PostgreSQL - problemas con ma matrix en postgres

 
Vista:
sin imagen de perfil
Val: 1
Ha disminuido su posición en 14 puestos en PostgreSQL (en relación al último mes)
Gráfica de PostgreSQL

problemas con ma matrix en postgres

Publicado por Raymond (1 intervención) el 21/02/2020 12:35:30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
DROP FUNCTION insertarfacturaventamulti(text[], text, integer, integer, integer, text, text, text, text, text, text, text, text, text, text, text);
CREATE OR REPLACE FUNCTION insertarfacturaventamulti(matrixx text[][], numfa text, fil integer, colum integer, inic integer, usuari text, fech text, hor text, codcl text, subtota text, ig text, tota text, fec text, bod text, vendedo text, prefij text)
  RETURNS text AS
$BODY$
	DECLARE
	filas int :=fil;--tamaño de la matrix
	columnas int :=colum;--columnas
	inicia int :=0;--pocicion de inicio
	matrix  text[][] := matrixx;--asignacion ppor referencia de la matrix
	Arreglo text[]   := ARRAY( SELECT inicia FROM generate_series(filas, columnas) ) ; -- Arreglo de N elementos (columnas), inizializadas con el valor de "value"
	matri  text[][] := ARRAY[ Arreglo ] ; -- Inicializamos la primera fila, con el Arreglo de N columnas.
 
	numfac text :=numfa;--numero de la factura
	tam int :=fil;--tamaño de la matrix
	capcod text;--codigo del producto
	capcan int;--cantidad vendida
	despro text;--descripcion
	preunit int;--precio unitario
	importe text;--total del importe
	detalles text;--detalle del producto
	prc text;--precio de compra
	iv text;--iva
	pess text;--pesado
	desfinal int;--diferencia
	bodegas text;--bodega
	usuario text:=usuari;--usuario
	fechav text:=fech;--fecha
	hora text:=hor;--hora
	iva text;--iva
	pc text;--preciocompra
	pv text;--precioventa
	cantibodega int;--canridad en bodega
	--datos de la factura
	codcli text:=codcl;--codigo del cliente
	subtotal text:=subtota;--subtotal
	igv text:=ig;--iva de la factura
	total text:=tota;--toal de la factura
	fechaf text:=fec;--fecha de facturacion
	bode text:=bod;--bodega que realiza la venta
	vendedor text:=vendedo;--vendedor
	prefijo text:=prefij;--prefijo de facturacion
 
	BEGIN
 
	--------GUARDAMOS LOS DATOS DE FACTURACION
		INSERT INTO factura VALUES (numfac,codcli,codcli,subtotal,igv,total,fechaf,bode);
		INSERT INTO facturahistorial VALUES (numfac,codcli,codcli,subtotal,igv,total,fechaf,bode,vendedor,fechav,hora);
		INSERT INTO facturadiaria VALUES (numfac,codcli,codcli,subtotal,igv,total,fechaf,bode,vendedor,fechav,hora);
		INSERT INTO consecutivohistorial VALUES (numfac,usuario,fechav,hora);
		INSERT INTO facturacomprafecha VALUES (numfac,prefijo,fechaf);
	--------LLENAMOS LA MATRIX LOCAL CON LA INFORMACION QUE VIENE DESDE EL EXTERIOR
		FOR i IN 1..filas LOOP  -- Se iniziliza el resto de las  filas de la matriz
			matri := array_cat( matrix, Arreglo ) ; -- Concatenamos el arreglo a la matriz (añade una fila a la matriz).
		END LOOP ;
	-------RRECORREMOS LA MATRIX LOCAL CON EL FIN DE EMPEZAR A LLENAR LA TABLA
		FOR i IN 1..filas LOOP
			capcod=matri[i][0];
			capcan=cast(matri[i][3] as int);
			despro=matri[i][1];
			preunit=cast(matri[i][2] as int);
			importe=matri[i][4];
 
			detalles= (select detalle from producto where cod_pro=capcod limit 1);
			bodegas=(select bodega from producto where cod_pro=capcod limit 1);
			prc=(select grupo from puc where clase=capcod limit 1);
			pess= (select pesado from producto where cod_pro=capcod limit 1);
			cantibodega=(select stock from producto where cod_pro=capcod limit 1);
			desfinal=cantibodega-capcan;
			iv=(select nombrecuenta from puc where clase=capcod limit 1);
			iva=(select nombrecuenta from puc where clase=capcod limit 1);
			pc=(select grupo from puc where clase=capcod limit 1);
			pv=(select subcuenta from puc where clase=capcod limit 1);
 
			INSERT INTO productohistorialventa VALUES (capcod,despro,preunit,desfinal,detalles,pess,bodegas,usuario,fechav,hora);
			INSERT INTO productohistorialventadiaria VALUES (capcod,despro,preunit,desfinal,detalles,pess,bodegas,usuario,fechav,hora);
			update producto set stock=desfinal where cod_pro=capcod and bodega=bodegas;
			INSERT INTO detallefactura VALUES (numfac,capcod,despro,capcan,preunit,importe,detalles);
			INSERT INTO detallefacturahistorial VALUES (numfac,capcod,despro,capcan,preunit,importe,detalles,usuario,fechav,hora);
			INSERT INTO productomovimiento VALUES (numfac,capcod,despro,pc,preunit,capcan,detalles,iva,pess,bodegas,'FACTURA DE VENTA',usuario,fechav,hora);
		END LOOP;
	RETURN 'ingreso exitoso';
	END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION insertarfacturaventamulti(text[], text, integer, integer, integer, text, text, text, text, text, text, text, text, text, text, text)
  OWNER TO postgres;

no esta entrando el loop que estare haciendo mal
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Francisco
Val: 256
Oro
Ha mantenido su posición en PostgreSQL (en relación al último mes)
Gráfica de PostgreSQL

problemas con ma matrix en postgres

Publicado por Francisco (110 intervenciones) el 21/02/2020 18:32:13
Hola

Prueba agregando

1
2
3
4
------RRECORREMOS LA MATRIX LOCAL CON EL FIN DE EMPEZAR A LLENAR LA TABLA
i = 0;
FOR i IN 1..filas LOOP
...

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar