2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`clientDebtSpray`(vClientFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
/* Reparte el saldo de un cliente en greuge en la cartera que corresponde, y desasigna el comercial
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
DECLARE vClientDebt DOUBLE;
|
|
|
|
|
|
|
|
SELECT vn.client_getDebt(vClientFk, util.VN_CURDATE()) INTO vClientDebt;
|
|
|
|
|
|
|
|
INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk)
|
|
|
|
VALUES (vClientFk, 'Saldo pendiente', vClientDebt, util.VN_CURDATE(), 5);
|
|
|
|
|
|
|
|
CALL vn.clientGreugeSpray(vClientFk, TRUE, '', TRUE);
|
|
|
|
|
|
|
|
INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk)
|
|
|
|
SELECT vClientFk, 'Liquidación cliente', sum(amount), util.VN_CURDATE(), 5
|
|
|
|
FROM vn.greuge
|
|
|
|
WHERE clientFk = vClientFk;
|
|
|
|
|
|
|
|
UPDATE vn.client
|
|
|
|
SET salesPersonFk = NULL
|
|
|
|
WHERE id = vClientFk;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|