salix/db/routines/vn/functions/till_new.sql

74 lines
1.2 KiB
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`till_new`(
vClient INT,
vBank INT,
vAmount DOUBLE,
vConcept VARCHAR(25),
vDated DATE,
vSerie CHAR(1),
vBatch TINYINT,
vNumber INT,
vCompany SMALLINT,
vWorker INT
)
BEGIN
DECLARE vAccount VARCHAR(12);
DECLARE vSubaccount VARCHAR(12);
DECLARE vAsiento INT DEFAULT NULL;
-- Inserta el registro en cajas
INSERT INTO till
SET
workerFk = vWorker,
bankFk = vBank,
`in` = vAmount,
concept = vConcept,
dated = vDated,
serie = vSerie,
isAccountable = vBatch,
`number` = vNumber,
companyFk = vCompany;
-- Inserta los asientos contables
SELECT account INTO vAccount
FROM accounting WHERE id = vBank;
SELECT accountingAccount INTO vSubaccount
FROM `client` WHERE id = vClient;
CALL xdiario_new(
vAsiento,
vDated,
vAccount,
vSubaccount,
vConcept,
vAmount,
0,
0,
NULL, -- Serie
NULL, -- Factura
NULL, -- IVA
NULL, -- Recargo
FALSE, -- Auxiliar
vCompany,
vAsiento);
CALL xdiario_new(
vAsiento,
vDated,
vSubaccount,
vAccount,
vConcept,
0,
vAmount,
0,
NULL, -- Serie
NULL, -- Factura
NULL, -- IVA
NULL, -- Recargo
FALSE, -- Auxiliar
vCompany,
vAsiento);
END$$
DELIMITER ;