refactor: refund
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
bd0164dd4e
commit
d1bd2f9c77
|
@ -2,49 +2,63 @@ DROP PROCEDURE IF EXISTS vn.ticket_doRefund;
|
||||||
|
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
$$
|
$$
|
||||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doRefund`(IN vOriginTicket INT, OUT vNewTicket INT)
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doRefund`(OUT vNewTicket INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Crea un ticket de abono a partir de tmp.sale y/o tmp.ticketService
|
||||||
|
*
|
||||||
|
* @return vNewTicket
|
||||||
|
*/
|
||||||
DECLARE vDone BIT DEFAULT 0;
|
DECLARE vDone BIT DEFAULT 0;
|
||||||
DECLARE vCustomer MEDIUMINT;
|
DECLARE vClientFk MEDIUMINT;
|
||||||
DECLARE vWarehouse TINYINT;
|
DECLARE vWarehouse TINYINT;
|
||||||
DECLARE vCompany MEDIUMINT;
|
DECLARE vCompany MEDIUMINT;
|
||||||
DECLARE vAddress MEDIUMINT;
|
DECLARE vAddress MEDIUMINT;
|
||||||
DECLARE vRefundAgencyMode INT;
|
DECLARE vRefundAgencyMode INT;
|
||||||
DECLARE vItemFk INT;
|
DECLARE vItemFk INT;
|
||||||
DECLARE vQuantity DECIMAL (10,2);
|
DECLARE vQuantity DECIMAL (10,2);
|
||||||
DECLARE vConcept VARCHAR(50);
|
DECLARE vConcept VARCHAR(50);
|
||||||
DECLARE vPrice DECIMAL (10,2);
|
DECLARE vPrice DECIMAL (10,2);
|
||||||
DECLARE vDiscount TINYINT;
|
DECLARE vDiscount TINYINT;
|
||||||
DECLARE vSaleNew INT;
|
DECLARE vSaleNew INT;
|
||||||
DECLARE vSaleMain INT;
|
DECLARE vSaleMain INT;
|
||||||
DECLARE vZoneFk INT;
|
DECLARE vZoneFk INT;
|
||||||
DECLARE vDescription VARCHAR(50);
|
DECLARE vDescription VARCHAR(50);
|
||||||
DECLARE vTaxClassFk INT;
|
DECLARE vTaxClassFk INT;
|
||||||
DECLARE vTicketServiceTypeFk INT;
|
DECLARE vTicketServiceTypeFk INT;
|
||||||
|
DECLARE vOriginTicket INT;
|
||||||
DECLARE cSales CURSOR FOR
|
|
||||||
SELECT *
|
DECLARE cSales CURSOR FOR
|
||||||
FROM tmp.sale;
|
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
||||||
|
FROM tmp.sale s;
|
||||||
|
|
||||||
DECLARE cTicketServices CURSOR FOR
|
DECLARE cTicketServices CURSOR FOR
|
||||||
SELECT *
|
SELECT ts.description, - ts.quantity, ts.price, ts.taxClassFk, ts.ticketServiceTypeFk
|
||||||
FROM tmp.ticketService;
|
FROM tmp.ticketService ts;
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
SELECT id INTO vRefundAgencyMode
|
SELECT sub.ticketFk INTO vOriginTicket
|
||||||
|
FROM (
|
||||||
|
SELECT s.ticketFk
|
||||||
|
FROM tmp.sale s
|
||||||
|
UNION ALL
|
||||||
|
SELECT ts.ticketFk
|
||||||
|
FROM tmp.ticketService ts
|
||||||
|
) sub;
|
||||||
|
|
||||||
|
SELECT id INTO vRefundAgencyMode
|
||||||
FROM agencyMode WHERE `name` = 'ABONO';
|
FROM agencyMode WHERE `name` = 'ABONO';
|
||||||
|
|
||||||
SELECT clientFk, warehouseFk, companyFk, addressFk
|
SELECT clientFk, warehouseFk, companyFk, addressFk
|
||||||
INTO vCustomer, vWarehouse, vCompany, vAddress
|
INTO vClientFk, vWarehouse, vCompany, vAddress
|
||||||
FROM ticket
|
FROM ticket
|
||||||
WHERE id = vOriginTicket;
|
WHERE id = vOriginTicket;
|
||||||
|
|
||||||
SELECT id INTO vZoneFk
|
SELECT id INTO vZoneFk
|
||||||
FROM zone WHERE agencyModeFk = vRefundAgencyMode
|
FROM zone WHERE agencyModeFk = vRefundAgencyMode
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
INSERT INTO vn.ticket (
|
INSERT INTO vn.ticket (
|
||||||
clientFk,
|
clientFk,
|
||||||
shipped,
|
shipped,
|
||||||
|
@ -54,10 +68,10 @@ BEGIN
|
||||||
warehouseFk,
|
warehouseFk,
|
||||||
companyFk,
|
companyFk,
|
||||||
landed,
|
landed,
|
||||||
zoneFk
|
zoneFk
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
vCustomer,
|
vClientFk,
|
||||||
CURDATE(),
|
CURDATE(),
|
||||||
vAddress,
|
vAddress,
|
||||||
vRefundAgencyMode,
|
vRefundAgencyMode,
|
||||||
|
@ -65,49 +79,48 @@ BEGIN
|
||||||
vWarehouse,
|
vWarehouse,
|
||||||
vCompany,
|
vCompany,
|
||||||
CURDATE(),
|
CURDATE(),
|
||||||
vZoneFk
|
vZoneFk
|
||||||
FROM address a
|
FROM address a
|
||||||
WHERE a.id = vAddress;
|
WHERE a.id = vAddress;
|
||||||
|
|
||||||
SET vNewTicket = LAST_INSERT_ID();
|
SET vNewTicket = LAST_INSERT_ID();
|
||||||
|
|
||||||
SET vDone := 0;
|
SET vDone := FALSE;
|
||||||
OPEN cSales;
|
OPEN cSales;
|
||||||
FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
|
FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
|
||||||
|
|
||||||
WHILE NOT vDone DO
|
WHILE NOT vDone DO
|
||||||
|
|
||||||
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount)
|
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount)
|
||||||
VALUES( vNewTicket, vItemFk, vQuantity, vConcept, vPrice, vDiscount );
|
VALUES( vNewTicket, vItemFk, vQuantity, vConcept, vPrice, vDiscount );
|
||||||
|
|
||||||
SET vSaleNew = LAST_INSERT_ID();
|
SET vSaleNew = LAST_INSERT_ID();
|
||||||
|
|
||||||
INSERT INTO vn.saleComponent(saleFk,componentFk,`value`)
|
INSERT INTO vn.saleComponent(saleFk,componentFk,`value`)
|
||||||
SELECT vSaleNew,componentFk,`value`
|
SELECT vSaleNew,componentFk,`value`
|
||||||
FROM vn.saleComponent
|
FROM vn.saleComponent
|
||||||
WHERE saleFk = vSaleMain;
|
WHERE saleFk = vSaleMain;
|
||||||
|
|
||||||
FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
|
FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
|
||||||
|
|
||||||
END WHILE;
|
END WHILE;
|
||||||
CLOSE cSales;
|
CLOSE cSales;
|
||||||
|
|
||||||
SET vDone := 0;
|
SET vDone := FALSE;
|
||||||
OPEN cTicketServices;
|
OPEN cTicketServices;
|
||||||
FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk;
|
FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk;
|
||||||
|
|
||||||
WHILE NOT vDone DO
|
WHILE NOT vDone DO
|
||||||
|
|
||||||
INSERT INTO vn.ticketService(description, quantity, price, taxClassFk, ticketFk, ticketServiceTypeFk)
|
INSERT INTO vn.ticketService(description, quantity, price, taxClassFk, ticketFk, ticketServiceTypeFk)
|
||||||
VALUES(vDescription, vQuantity, vPrice, vTaxClassFk, vNewTicket, vTicketServiceTypeFk);
|
VALUES(vDescription, vQuantity, vPrice, vTaxClassFk, vNewTicket, vTicketServiceTypeFk);
|
||||||
|
|
||||||
FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk;
|
FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk;
|
||||||
|
|
||||||
END WHILE;
|
END WHILE;
|
||||||
CLOSE cTicketServices;
|
CLOSE cTicketServices;
|
||||||
|
|
||||||
INSERT INTO vn.ticketRefund(refundTicketFk, originalTicketFk)
|
INSERT INTO vn.ticketRefund(refundTicketFk, originalTicketFk)
|
||||||
VALUES(vNewTicket, vOriginTicket);
|
VALUES(vNewTicket, vOriginTicket);
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -76,6 +76,13 @@
|
||||||
translate>
|
translate>
|
||||||
Show CITES letter
|
Show CITES letter
|
||||||
</vn-item>
|
</vn-item>
|
||||||
|
<vn-item
|
||||||
|
ng-click="refundConfirmation.show()"
|
||||||
|
name="refundInvoice"
|
||||||
|
vn-tooltip="Create a single ticket with all the content of the current invoice"
|
||||||
|
translate>
|
||||||
|
Refund
|
||||||
|
</vn-item>
|
||||||
</vn-list>
|
</vn-list>
|
||||||
</vn-menu>
|
</vn-menu>
|
||||||
<vn-confirm
|
<vn-confirm
|
||||||
|
@ -88,6 +95,11 @@
|
||||||
on-accept="$ctrl.bookInvoiceOut()"
|
on-accept="$ctrl.bookInvoiceOut()"
|
||||||
question="Are you sure you want to book this invoice?">
|
question="Are you sure you want to book this invoice?">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
|
<vn-confirm
|
||||||
|
vn-id="refundConfirmation"
|
||||||
|
on-accept="$ctrl.bookInvoiceOut()"
|
||||||
|
question="Are you sure you want to refund this invoice?">
|
||||||
|
</vn-confirm>
|
||||||
<vn-client-descriptor-popover
|
<vn-client-descriptor-popover
|
||||||
vn-id="clientDescriptor">
|
vn-id="clientDescriptor">
|
||||||
</vn-client-descriptor-popover>
|
</vn-client-descriptor-popover>
|
||||||
|
|
|
@ -12,6 +12,8 @@ Are you sure you want to delete this invoice?: Estas seguro de eliminar esta fac
|
||||||
Are you sure you want to clone this invoice?: Estas seguro de clonar esta factura?
|
Are you sure you want to clone this invoice?: Estas seguro de clonar esta factura?
|
||||||
InvoiceOut booked: Factura asentada
|
InvoiceOut booked: Factura asentada
|
||||||
Are you sure you want to book this invoice?: Estas seguro de querer asentar esta factura?
|
Are you sure you want to book this invoice?: Estas seguro de querer asentar esta factura?
|
||||||
|
Are you sure you want to refund this invoice?: Estas seguro de querer abonar esta factura?
|
||||||
|
Create a single ticket with all the content of the current invoice: Crear un ticket unico con todo el contenido de la factura actual
|
||||||
Regenerate PDF invoice: Regenerar PDF factura
|
Regenerate PDF invoice: Regenerar PDF factura
|
||||||
The invoice PDF document has been regenerated: El documento PDF de la factura ha sido regenerado
|
The invoice PDF document has been regenerated: El documento PDF de la factura ha sido regenerado
|
||||||
The email can't be empty: El correo no puede estar vacío
|
The email can't be empty: El correo no puede estar vacío
|
||||||
|
|
|
@ -2,13 +2,19 @@ const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('refundAll', {
|
Self.remoteMethodCtx('refundAll', {
|
||||||
description: 'Create ticket with all lines and services changing the sign to the quantites',
|
description: 'Create ticket refund with all lines and services changing the sign to the quantites',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'ticketId',
|
arg: 'sales',
|
||||||
type: 'number',
|
description: 'The sales',
|
||||||
|
type: ['object'],
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'services',
|
||||||
|
type: ['object'],
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The ticket id'
|
description: 'The services'
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -20,7 +26,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.refundAll = async(ctx, ticketId, options) => {
|
Self.refundAll = async(ctx, sales, services, options) => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
|
@ -49,27 +55,26 @@ module.exports = Self => {
|
||||||
CREATE TEMPORARY TABLE tmp.sale
|
CREATE TEMPORARY TABLE tmp.sale
|
||||||
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
||||||
FROM sale s
|
FROM sale s
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
WHERE s.id IN (?);
|
||||||
WHERE t.id IN (?);
|
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE tmp.ticketService
|
CREATE TEMPORARY TABLE tmp.ticketService
|
||||||
SELECT ts.description, - ts.quantity, ts.price, ts.taxClassFk, ts.ticketServiceTypeFk
|
SELECT ts.description, - ts.quantity, ts.price, ts.taxClassFk, ts.ticketServiceTypeFk
|
||||||
FROM ticketService ts
|
FROM ticketService ts
|
||||||
WHERE ts.ticketFk IN (?);
|
WHERE ts.id IN (?);
|
||||||
|
|
||||||
CALL vn.ticket_doRefund(?, @newTicket);
|
CALL vn.ticket_doRefund(@newTicket);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.sale;
|
DROP TEMPORARY TABLE tmp.sale;
|
||||||
DROP TEMPORARY TABLE tmp.ticketService;`;
|
DROP TEMPORARY TABLE tmp.ticketService;`;
|
||||||
|
|
||||||
await Self.rawSql(query, [ticketId, ticketId, ticketId], myOptions);
|
await Self.rawSql(query, [sales, services], myOptions);
|
||||||
|
|
||||||
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
||||||
ticketId = newTicket.id;
|
const newTicketId = newTicket.id;
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return ticketId;
|
return newTicketId;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in New Issue