374 lines
15 KiB
Plaintext
374 lines
15 KiB
Plaintext
{
|
|
FUNCION : GeneraEntradaDiario
|
|
OBJETIVO : REcibir las informaciones desde otros modulos con la finalidad
|
|
de adicionar los registros necesarios en el mayor de contabilidad
|
|
relacionado al documento fuente
|
|
DESARROLLADO : JUAN SOTO
|
|
FECHA : 7, Noviembre 2025
|
|
|
|
}
|
|
|
|
FUNCTION GeneraEntradaDiario(
|
|
usuario,
|
|
tipoPrograma,
|
|
idEntrada,
|
|
cuenta_no_banco,
|
|
xfecha,
|
|
valor_bruto,
|
|
monto_desc,
|
|
impuesto,
|
|
tipoCliente,
|
|
secCliente,
|
|
moneda,
|
|
tasa,
|
|
xnumeroDoc,
|
|
comision)
|
|
DEFINE
|
|
tipoPrograma, usuario, xventas VARCHAR(50),
|
|
cuenta_no_banco,
|
|
xcuenta_no_ingreso,
|
|
xcuenta_no_prima_ingresos,
|
|
xcuenta_no_ventas,
|
|
xcuenta_no_prima,
|
|
xcuenta_comision,
|
|
xcuenta_no_itbis
|
|
VARCHAR(8),
|
|
idEntrada,
|
|
tipoCliente,
|
|
secCliente,
|
|
xdepartamento,
|
|
xnumeroDoc,
|
|
idrow,
|
|
deptoAct
|
|
INT,
|
|
xfecha DATE,
|
|
moneda SMALLINT,
|
|
valor_bruto, monto_desc, impuesto, tasa, debito, comision, dolares, diferencia DEC(18, 2),
|
|
tieneDepto_ing, tieneDepto_prima, tieneDepto_ventas, tieneDepto_comision
|
|
CHAR(1),
|
|
entra VARCHAR(25),
|
|
detalle1 VARCHAR(100)
|
|
|
|
DEFINE
|
|
registroEntrada DYNAMIC ARRAY OF RECORD
|
|
referenciaEntrada VARCHAR(25),
|
|
fecha DATE,
|
|
tipo CHAR(1),
|
|
cuenta_no VARCHAR(8),
|
|
departamento INT,
|
|
detalle VARCHAR(100),
|
|
debito, credito DEC(12, 2)
|
|
END RECORD,
|
|
qcuentas STRING
|
|
|
|
LET idrow = 1
|
|
LET deptoAct = NULL
|
|
DISPLAY "comision entr ", comision
|
|
CALL registroEntrada.clear()
|
|
#QUERYS GENERALES PARA TODOS LOS AUXILIARES
|
|
LET qcuentas =
|
|
"
|
|
SELECT DISTINCT a.cuenta_no_ventas,a.cuenta_no_ingresos,a.cuenta_no_prima,a.cuenta_no_prima_ingresos,a.cuenta_comision
|
|
,a.departamento,b.descripcion
|
|
FROM marmotech.dbo.vetb00060 a INNER JOIN marmotech.dbo.vetb00061 b ON b.ventas = a.ventas WHERE a.tipo_cliente = ?
|
|
"
|
|
PREPARE scuentas FROM qcuentas
|
|
EXECUTE scuentas
|
|
INTO xcuenta_no_ventas, xcuenta_no_ingreso, xcuenta_no_prima, xcuenta_no_prima_ingresos, xcuenta_comision, xdepartamento, xventas USING tipoCliente
|
|
|
|
LET qcuentas =
|
|
"
|
|
SELECT ISNULL(a.depto,'N') FROM marmotech.dbo.cgtb00001 a WHERE a.cuenta_no = ?"
|
|
|
|
PREPARE sdepto FROM qcuentas
|
|
EXECUTE sdepto INTO tieneDepto_ing USING xcuenta_no_ingreso
|
|
|
|
LET qcuentas =
|
|
"
|
|
SELECT ISNULL(a.depto,'N') FROM marmotech.dbo.cgtb00001 a WHERE a.cuenta_no = ?"
|
|
|
|
PREPARE cprima FROM qcuentas
|
|
EXECUTE cprima INTO tieneDepto_prima USING xcuenta_no_prima_ingresos
|
|
|
|
LET qcuentas =
|
|
"
|
|
SELECT ISNULL(a.depto,'N') FROM marmotech.dbo.cgtb00001 a WHERE a.cuenta_no = ?"
|
|
PREPARE sventas FROM qcuentas
|
|
EXECUTE sventas INTO tieneDepto_ventas USING xcuenta_no_ventas
|
|
|
|
LET qcuentas =
|
|
"
|
|
SELECT ISNULL(a.depto,'N') FROM marmotech.dbo.cgtb00001 a WHERE a.cuenta_no = ?"
|
|
PREPARE sventas FROM qcuentas
|
|
EXECUTE sventas INTO tieneDepto_comision USING xcuenta_comision
|
|
|
|
#------------------------------------------------------------------------
|
|
# RECIBOS INGRESOS
|
|
#------------------------------------------------------------------------
|
|
IF tipoPrograma = 'RECIBOS INGRESOS' THEN
|
|
|
|
LET qcuentas =
|
|
"SELECT a.tasa-1 FROM marmotech.dbo.cgtb00084 a WHERE a.ano = YEAR(?) AND a.mes = MONTH(?) AND
|
|
a.tipo_cliente = ?"
|
|
PREPARE stasa FROM qcuentas
|
|
EXECUTE stasa INTO tasa USING xfecha, xfecha, tipoCliente
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
RETURN FALSE, registroEntrada
|
|
END IF
|
|
|
|
LET deptoAct = xdepartamento
|
|
|
|
IF tieneDepto_ing = 'N' THEN
|
|
LET deptoAct = NULL
|
|
END IF
|
|
|
|
LET detalle1 =
|
|
'RECIBO INGRESO ', xventas CLIPPED, " ", xnumeroDoc USING "<<<<<<<<"
|
|
CALL controlNumericoED(idEntrada, xfecha, usuario) RETURNING entra
|
|
LET debito = (valor_bruto - monto_desc)
|
|
|
|
LET registroEntrada[1].cuenta_no = xcuenta_no_ingreso CLIPPED
|
|
LET registroEntrada[1].fecha = xfecha
|
|
LET registroEntrada[1].referenciaEntrada = entra
|
|
LET registroEntrada[1].tipo = '1'
|
|
LET registroEntrada[1].departamento = deptoAct
|
|
LET registroEntrada[1].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[1].debito = debito
|
|
LET registroEntrada[1].credito = 0
|
|
|
|
IF xcuenta_no_prima_ingresos IS NOT NULL THEN
|
|
LET deptoAct = xdepartamento
|
|
|
|
IF tieneDepto_prima = 'N' THEN
|
|
LET deptoAct = NULL
|
|
END IF
|
|
|
|
LET registroEntrada[2].cuenta_no = xcuenta_no_prima_ingresos CLIPPED
|
|
LET registroEntrada[2].referenciaEntrada = entra
|
|
LET registroEntrada[2].fecha = xfecha
|
|
LET registroEntrada[2].tipo = '1'
|
|
LET registroEntrada[2].departamento = deptoAct
|
|
LET registroEntrada[2].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[2].debito = debito * tasa
|
|
LET registroEntrada[2].credito = 0
|
|
|
|
END IF
|
|
|
|
LET deptoAct = xdepartamento
|
|
|
|
IF tieneDepto_ventas = 'N' THEN
|
|
LET deptoAct = NULL
|
|
END IF
|
|
LET registroEntrada[3].cuenta_no = xcuenta_no_ventas CLIPPED
|
|
LET registroEntrada[3].referenciaEntrada = entra
|
|
LET registroEntrada[3].fecha = xfecha
|
|
LET registroEntrada[3].tipo = '1'
|
|
LET registroEntrada[3].departamento = deptoAct
|
|
LET registroEntrada[3].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[3].debito = 0
|
|
LET registroEntrada[3].credito = debito
|
|
|
|
IF xcuenta_no_prima IS NOT NULL THEN
|
|
LET deptoAct = xdepartamento
|
|
|
|
IF tieneDepto_prima = 'N' THEN
|
|
LET deptoAct = NULL
|
|
END IF
|
|
LET registroEntrada[4].cuenta_no = xcuenta_no_prima CLIPPED
|
|
LET registroEntrada[4].referenciaEntrada = entra
|
|
LET registroEntrada[4].fecha = xfecha
|
|
LET registroEntrada[4].tipo = '1'
|
|
LET registroEntrada[4].departamento = deptoAct
|
|
LET registroEntrada[4].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[4].debito = 0
|
|
LET registroEntrada[4].credito = debito * tasa
|
|
|
|
END IF
|
|
|
|
RETURN TRUE, registroEntrada
|
|
END IF
|
|
|
|
#------------------------------------------------------------------------
|
|
# DEPOSITOS
|
|
#------------------------------------------------------------------------
|
|
|
|
IF tipoPrograma = 'DEPOSITOS' THEN
|
|
LET idrow = 1
|
|
LET qcuentas =
|
|
"SELECT avg(a.tasa) FROM marmotech.dbo.cgtb00084 a WHERE a.ano = YEAR(?) AND a.mes = MONTH(?) AND
|
|
a.ventas = ?"
|
|
PREPARE stasa1 FROM qcuentas
|
|
EXECUTE stasa1 INTO tasa USING xfecha, xfecha, moneda
|
|
|
|
IF STATUS = NOTFOUND THEN
|
|
RETURN FALSE, registroEntrada
|
|
END IF
|
|
|
|
LET qcuentas =
|
|
"
|
|
SELECT DISTINCT a.cuenta_no_ventas,a.cuenta_no_ingresos,a.cuenta_no_prima,a.cuenta_no_prima_ingresos,a.cuenta_comision
|
|
,a.departamento,b.descripcion,a.cuenta_no_itbis,a.cuenta_comision
|
|
FROM marmotech.dbo.vetb00060 a INNER JOIN marmotech.dbo.vetb00061 b ON b.ventas = a.ventas WHERE a.ventas = ?
|
|
"
|
|
PREPARE scuentasdp FROM qcuentas
|
|
EXECUTE scuentasdp
|
|
INTO xcuenta_no_ventas, xcuenta_no_ingreso, xcuenta_no_prima, xcuenta_no_prima_ingresos, xcuenta_comision, xdepartamento, xventas, xcuenta_no_itbis, xcuenta_comision USING moneda
|
|
|
|
LET deptoAct = NULL
|
|
|
|
LET detalle1 =
|
|
'DEPOSITOS ', xventas CLIPPED, " ", xnumeroDoc USING "<<<<<<<<"
|
|
|
|
LET usuario = NULL
|
|
CALL controlNumericoED(idEntrada, xfecha, usuario) RETURNING entra
|
|
LET debito = valor_bruto
|
|
IF comision > 0 THEN
|
|
LET impuesto = (valor_bruto / 1.18) * .02
|
|
LET debito = valor_bruto - comision - impuesto
|
|
END IF
|
|
DISPLAY "en DEPOSITO: ",
|
|
detalle1,
|
|
" debito ",
|
|
debito,
|
|
" comision ",
|
|
comision,
|
|
" valor Bruto :",
|
|
valor_bruto,
|
|
" tasa ",
|
|
tasa
|
|
IF tasa = 0 THEN
|
|
LET tasa = 1
|
|
END IF
|
|
LET registroEntrada[idrow].cuenta_no = cuenta_no_banco CLIPPED
|
|
LET registroEntrada[idrow].fecha = xfecha
|
|
LET registroEntrada[idrow].referenciaEntrada = entra
|
|
LET registroEntrada[idrow].tipo = '1'
|
|
LET registroEntrada[idrow].departamento = deptoAct
|
|
LET registroEntrada[idrow].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[idrow].debito = debito
|
|
LET registroEntrada[idrow].credito = 0
|
|
|
|
IF comision > 0 THEN
|
|
|
|
LET idrow = idrow + 1
|
|
LET registroEntrada[idrow].cuenta_no = xcuenta_no_itbis CLIPPED
|
|
LET registroEntrada[idrow].referenciaEntrada = entra
|
|
LET registroEntrada[idrow].fecha = xfecha
|
|
LET registroEntrada[idrow].tipo = '1'
|
|
LET registroEntrada[idrow].departamento = deptoAct
|
|
LET registroEntrada[idrow].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[idrow].debito = impuesto
|
|
LET registroEntrada[idrow].credito = 0
|
|
|
|
LET idrow = idrow + 1
|
|
LET registroEntrada[idrow].cuenta_no = xcuenta_comision CLIPPED
|
|
LET registroEntrada[idrow].referenciaEntrada = entra
|
|
LET registroEntrada[idrow].fecha = xfecha
|
|
LET registroEntrada[idrow].tipo = '1'
|
|
LET registroEntrada[idrow].departamento = deptoAct
|
|
LET registroEntrada[idrow].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[idrow].debito = comision
|
|
LET registroEntrada[idrow].credito = 0
|
|
LET deptoAct = xdepartamento
|
|
|
|
# El credito completo al ingreso solo aplica en depositos locales.
|
|
# En dolares (moneda > 1) el credito lo arma el bloque de mas abajo (Caja US$ + Prima).
|
|
IF moneda = 1 THEN
|
|
LET idrow = idrow + 1
|
|
LET registroEntrada[idrow].cuenta_no = xcuenta_no_ingreso CLIPPED
|
|
LET registroEntrada[idrow].referenciaEntrada = entra
|
|
LET registroEntrada[idrow].fecha = xfecha
|
|
LET registroEntrada[idrow].tipo = '1'
|
|
LET registroEntrada[idrow].departamento = deptoAct
|
|
LET registroEntrada[idrow].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[idrow].debito = 0
|
|
LET registroEntrada[idrow].credito = valor_bruto
|
|
END IF
|
|
|
|
END IF
|
|
|
|
IF moneda = 1 AND comision = 0 THEN
|
|
|
|
LET idrow = idrow + 1
|
|
LET registroEntrada[idrow].cuenta_no = xcuenta_no_ingreso CLIPPED
|
|
LET registroEntrada[idrow].referenciaEntrada = entra
|
|
LET registroEntrada[idrow].fecha = xfecha
|
|
LET registroEntrada[idrow].tipo = '1'
|
|
LET registroEntrada[idrow].departamento = deptoAct
|
|
LET registroEntrada[idrow].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[idrow].debito = 0
|
|
LET registroEntrada[idrow].credito = valor_bruto
|
|
|
|
END IF
|
|
|
|
IF moneda > 1 THEN
|
|
# DOLARES PAGADOS AL DEPOSITO (guardados en las columnas monto_* de tetb00001)
|
|
LET dolares = 0
|
|
LET qcuentas =
|
|
"SELECT ISNULL(a.monto_efectivo,0)+ISNULL(a.monto_ck,0)+ISNULL(a.monto_link,0)+ISNULL(a.monto_tarjeta,0)
|
|
FROM marmotech.dbo.tetb00001 a WHERE a.num_doc = ?"
|
|
PREPARE sdolares FROM qcuentas
|
|
EXECUTE sdolares INTO dolares USING xnumeroDoc
|
|
IF dolares IS NULL THEN
|
|
LET dolares = 0
|
|
END IF
|
|
|
|
LET diferencia = valor_bruto - dolares
|
|
|
|
# 1100-01 CAJA US$ = dolares pagados
|
|
LET idrow = idrow + 1
|
|
LET registroEntrada[idrow].cuenta_no = xcuenta_no_ingreso CLIPPED
|
|
LET registroEntrada[idrow].referenciaEntrada = entra
|
|
LET registroEntrada[idrow].fecha = xfecha
|
|
LET registroEntrada[idrow].tipo = '1'
|
|
LET registroEntrada[idrow].departamento = deptoAct
|
|
LET registroEntrada[idrow].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[idrow].debito = 0
|
|
LET registroEntrada[idrow].credito = dolares
|
|
|
|
# 1100-02 PRIMA = valor_bruto - dolares (solo si hubo conversion)
|
|
IF diferencia <> 0 THEN
|
|
LET idrow = idrow + 1
|
|
LET registroEntrada[idrow].cuenta_no = xcuenta_no_prima_ingresos CLIPPED
|
|
LET registroEntrada[idrow].referenciaEntrada = entra
|
|
LET registroEntrada[idrow].fecha = xfecha
|
|
LET registroEntrada[idrow].tipo = '1'
|
|
LET registroEntrada[idrow].departamento = deptoAct
|
|
LET registroEntrada[idrow].detalle = detalle1 CLIPPED
|
|
LET registroEntrada[idrow].debito = 0
|
|
LET registroEntrada[idrow].credito = diferencia
|
|
END IF
|
|
|
|
END IF
|
|
|
|
RETURN TRUE, registroEntrada
|
|
END IF
|
|
#------------------------------------------------------------------------
|
|
# VENTAS
|
|
#------------------------------------------------------------------------
|
|
IF tipoPrograma = 'VENTAS' THEN
|
|
END IF
|
|
#------------------------------------------------------------------------
|
|
# INVENTARIO PRODUCTOS TERMINADOS
|
|
#------------------------------------------------------------------------
|
|
IF tipoPrograma = 'INV PRODUCTOS' THEN
|
|
END IF
|
|
#------------------------------------------------------------------------
|
|
# INVENTARIO REPUESTOS
|
|
#------------------------------------------------------------------------
|
|
IF tipoPrograma = 'INV REPUESTOS' THEN
|
|
END IF
|
|
#------------------------------------------------------------------------
|
|
# INVENTARIOS MATERIA PRIMA
|
|
#------------------------------------------------------------------------
|
|
IF tipoPrograma = 'INV MAT PRIMA' THEN
|
|
END IF
|
|
#------------------------------------------------------------------------
|
|
# ACTIVOS FIJS
|
|
#------------------------------------------------------------------------
|
|
IF tipoPrograma = 'ACTIVOS' THEN
|
|
END IF
|
|
|
|
END FUNCTION
|