46 lines
1.5 KiB
SQL
46 lines
1.5 KiB
SQL
drop procedure `vn`.`invoiceOut_newFromClient`;
|
|
|
|
DELIMITER $$
|
|
$$
|
|
create
|
|
definer = root@`%` procedure `vn`.`invoiceOut_newFromClient`(IN vClientFk int, IN vSerial char(2), IN vMaxShipped date,
|
|
IN vCompanyFk int, IN vTaxArea varchar(25),
|
|
IN vRef varchar(25), OUT vInvoiceId int)
|
|
BEGIN
|
|
/**
|
|
* Factura los tickets de un cliente hasta una fecha dada
|
|
* @param vClientFk Id del cliente a facturar
|
|
* @param vSerial Serie de factura
|
|
* @param vMaxShipped Fecha hasta la cual cogera tickets para facturar
|
|
* @param vCompanyFk Id de la empresa desde la que se factura
|
|
* @param vTaxArea Tipo de iva en relacion a la empresa y al cliente, NULL por defecto
|
|
* @param vRef Referencia de la factura en caso que se quiera forzar, NULL por defecto
|
|
* @return vInvoiceId factura
|
|
*/
|
|
|
|
DECLARE vIsRefEditable BOOLEAN;
|
|
|
|
IF vRef IS NOT NULL THEN
|
|
SELECT isRefEditable INTO vIsRefEditable
|
|
FROM invoiceOutSerial
|
|
WHERE code = vSerial;
|
|
|
|
IF NOT vIsRefEditable THEN
|
|
CALL util.throw('serial non editable');
|
|
END IF;
|
|
END IF;
|
|
|
|
CALL invoiceFromClient(vMaxShipped, vClientFk, vCompanyFk);
|
|
CALL invoiceOut_new(vSerial, CURDATE(), vTaxArea, vInvoiceId);
|
|
|
|
UPDATE invoiceOut
|
|
SET `ref` = vRef
|
|
WHERE id = vInvoiceId
|
|
AND vRef IS NOT NULL;
|
|
|
|
IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN
|
|
CALL invoiceOutBooking(vInvoiceId);
|
|
END IF;
|
|
END;;$$
|
|
DELIMITER ;
|