#7202 added new field in InvoiceOut module #3034
|
@ -639,13 +639,13 @@ INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaF
|
||||||
('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL),
|
('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL),
|
||||||
('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick');
|
('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick');
|
||||||
|
|
||||||
INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`, `customsAgentFk`)
|
INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`, `customsAgentFk`, `incotermsFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'T', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, 1),
|
(1, 'E', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, 1, 'FAS'),
|
||||||
(2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL),
|
(2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL, NULL),
|
||||||
(3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL),
|
(3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL, NULL),
|
||||||
(4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL),
|
(4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0, NULL, NULL),
|
||||||
(5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0, NULL);
|
(5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0, NULL, NULL);
|
||||||
|
|
||||||
UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1;
|
UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1;
|
||||||
UPDATE `vn`.`invoiceOut` SET ref = 'T2222222' WHERE id = 2;
|
UPDATE `vn`.`invoiceOut` SET ref = 'T2222222' WHERE id = 2;
|
||||||
|
|
|
@ -34,6 +34,7 @@ BEGIN
|
||||||
DECLARE vMaxShipped DATE;
|
DECLARE vMaxShipped DATE;
|
||||||
DECLARE vDone BOOL;
|
DECLARE vDone BOOL;
|
||||||
DECLARE vTicketFk INT;
|
DECLARE vTicketFk INT;
|
||||||
|
DECLARE vAddressFk INT;
|
||||||
DECLARE vCursor CURSOR FOR
|
DECLARE vCursor CURSOR FOR
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM tmp.ticketToInvoice;
|
FROM tmp.ticketToInvoice;
|
||||||
|
@ -48,11 +49,13 @@ BEGIN
|
||||||
DATE(vInvoiceDate) >= invoiceOut_getMaxIssued(
|
DATE(vInvoiceDate) >= invoiceOut_getMaxIssued(
|
||||||
vSerial,
|
vSerial,
|
||||||
t.companyFk,
|
t.companyFk,
|
||||||
YEAR(vInvoiceDate))
|
YEAR(vInvoiceDate)),
|
||||||
|
t.addressFk
|
||||||
INTO vClientFk,
|
INTO vClientFk,
|
||||||
vCompanyFk,
|
vCompanyFk,
|
||||||
vMaxShipped,
|
vMaxShipped,
|
||||||
vIsCorrectInvoiceDate
|
vIsCorrectInvoiceDate,
|
||||||
|
vAddressFk
|
||||||
FROM tmp.ticketToInvoice tt
|
FROM tmp.ticketToInvoice tt
|
||||||
JOIN ticket t ON t.id = tt.id;
|
JOIN ticket t ON t.id = tt.id;
|
||||||
|
|
||||||
|
@ -106,7 +109,8 @@ BEGIN
|
||||||
dued,
|
dued,
|
||||||
companyFk,
|
companyFk,
|
||||||
siiTypeInvoiceOutFk,
|
siiTypeInvoiceOutFk,
|
||||||
customsAgentFk
|
customsAgentFk,
|
||||||
|
incotermsFk
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
1,
|
1,
|
||||||
|
@ -120,9 +124,10 @@ BEGIN
|
||||||
IF(vSerial = vSimplifiedSerial,
|
IF(vSerial = vSimplifiedSerial,
|
||||||
|
|||||||
vCplusSimplifiedInvoiceTypeFk,
|
vCplusSimplifiedInvoiceTypeFk,
|
||||||
vCplusStandardInvoiceTypeFk)),
|
vCplusStandardInvoiceTypeFk)),
|
||||||
a.customsAgentFk
|
a.customsAgentFk,
|
||||||
|
a.incotermsFk
|
||||||
FROM client c
|
FROM client c
|
||||||
carlosap
commented
Si se va a guardar el customsAgentFk en la factura se deben de cambiar las consultas de los informes(report) de facturas Si se va a guardar el customsAgentFk en la factura se deben de cambiar las consultas de los informes(report) de facturas
|
|||||||
JOIN address a ON a.id = c.defaultAddressFk
|
JOIN address a ON a.id = vAddressFk
|
||||||
WHERE c.id = vClientFk;
|
WHERE c.id = vClientFk;
|
||||||
|
|
||||||
SET vNewInvoiceId = LAST_INSERT_ID();
|
SET vNewInvoiceId = LAST_INSERT_ID();
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
ALTER TABLE vn.invoiceOut ADD COLUMN IF NOT EXISTS customsAgentFk INT(11) DEFAULT NULL AFTER siiTrascendencyInvoiceOutFk;
|
ALTER TABLE vn.invoiceOut ADD COLUMN IF NOT EXISTS customsAgentFk INT(11) DEFAULT NULL AFTER siiTrascendencyInvoiceOutFk;
|
||||||
|
ALTER TABLE vn.invoiceOut ADD COLUMN IF NOT EXISTS incotermsFk varchar(3) DEFAULT NULL AFTER customsAgentFk;
|
||||||
|
|
||||||
ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_customsAgentFk FOREIGN KEY (customsAgentFk)
|
ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_customsAgentFk FOREIGN KEY (customsAgentFk)
|
||||||
REFERENCES vn.customsAgent (id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
REFERENCES vn.customsAgent (id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE vn.invoiceOut ADD CONSTRAINT invoiceOut_incotermsFk FOREIGN KEY (incotermsFk)
|
||||||
|
REFERENCES vn.incoterms (`code`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
UPDATE vn.invoiceOut io
|
UPDATE vn.invoiceOut io
|
||||||
JOIN vn.client c ON c.id = io.clientFk
|
JOIN vn.client c ON c.id = io.clientFk
|
||||||
JOIN vn.address a ON a.id = c.defaultAddressFk
|
JOIN vn.ticket t ON t.clientFk = c.id
|
||||||
SET io.customsAgentFk = a.customsAgentFk;
|
JOIN vn.address a ON a.id = t.addressFk
|
||||||
|
SET io.customsAgentFk = a.customsAgentFk,
|
||||||
|
io.incotermsFk = a.incotermsFk;
|
|
@ -1,9 +1,9 @@
|
||||||
WITH tickets AS(
|
WITH tickets AS(
|
||||||
SELECT id, packages, addressFk, weight
|
SELECT id, addressFk, packages, refFk
|
||||||
FROM ticket
|
FROM vn.ticket
|
||||||
WHERE refFk= ?
|
WHERE refFk = ?
|
||||||
), volume AS(
|
), volume AS(
|
||||||
SELECT SUM(volume) volume
|
SELECT SUM(volume) volume, MAX(weight)weight
|
||||||
FROM tickets t
|
FROM tickets t
|
||||||
JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
||||||
), intrastat AS(
|
), intrastat AS(
|
||||||
|
@ -12,10 +12,14 @@ SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '
|
||||||
JOIN vn.sale s ON t.id = s.ticketFk
|
JOIN vn.sale s ON t.id = s.ticketFk
|
||||||
JOIN vn.item i ON i.id = s.itemFk
|
JOIN vn.item i ON i.id = s.itemFk
|
||||||
JOIN vn.intrastat ir ON ir.id = i.intrastatFk
|
JOIN vn.intrastat ir ON ir.id = i.intrastatFk
|
||||||
)SELECT SUM(t.packages) packages,
|
), totalPackages AS(
|
||||||
a.incotermsFk,
|
SELECT SUM(packages)packages
|
||||||
|
FROM tickets s
|
||||||
|
)
|
||||||
|
SELECT tp.packages,
|
||||||
|
io.incotermsFk,
|
||||||
ic.name incotermsName,
|
ic.name incotermsName,
|
||||||
MAX(t.weight) weight,
|
v.weight weight,
|
||||||
ca.fiscalName customsAgentName,
|
ca.fiscalName customsAgentName,
|
||||||
ca.street customsAgentStreet,
|
ca.street customsAgentStreet,
|
||||||
ca.nif customsAgentNif,
|
ca.nif customsAgentNif,
|
||||||
|
@ -23,9 +27,10 @@ SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '
|
||||||
ca.email customsAgentEmail,
|
ca.email customsAgentEmail,
|
||||||
CAST(v.volume AS DECIMAL (10,2)) volume,
|
CAST(v.volume AS DECIMAL (10,2)) volume,
|
||||||
i.intrastat
|
i.intrastat
|
||||||
FROM tickets t
|
FROM vn.invoiceOut io
|
||||||
JOIN vn.address a ON a.id = t.addressFk
|
JOIN vn.incoterms ic ON ic.code = io.incotermsFk
|
||||||
JOIN vn.incoterms ic ON ic.code = a.incotermsFk
|
LEFT JOIN vn.customsAgent ca ON ca.id = io.customsAgentFk
|
||||||
LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk
|
|
||||||
JOIN volume v
|
JOIN volume v
|
||||||
JOIN intrastat i
|
JOIN intrastat i
|
||||||
|
JOIN totalPackages tp
|
||||||
|
WHERE `ref` = (SELECT DISTINCT refFk FROM tickets)
|
Loading…
Reference in New Issue
no de debe de coger del defaultAddressFk del cliente, se debería de coger del addres de los tickets a facturar