Merge branch 'dev' into 6964_itemOlder
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
e84805508a
|
@ -1980,10 +1980,10 @@ INSERT INTO `pbx`.`sip`(`user_id`, `extension`)
|
|||
(5, 1102),
|
||||
(9, 1201);
|
||||
|
||||
INSERT INTO `vn`.`professionalCategory` (`id`, `name`, `level`, `dayBreak`)
|
||||
INSERT INTO `vn`.`professionalCategory` (`id`, `description`)
|
||||
VALUES
|
||||
(1, 'employee', NULL, NULL),
|
||||
(2, 'florist', NULL, NULL);
|
||||
(1, 'employee'),
|
||||
(2, 'florist');
|
||||
|
||||
INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`)
|
||||
VALUES
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_checkBooked`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Comprueba si una entrada está contabilizada,
|
||||
* y si lo está retorna un throw.
|
||||
*
|
||||
* @param vSelf Id de entrada
|
||||
*/
|
||||
DECLARE vIsBooked BOOL;
|
||||
|
||||
SELECT isBooked INTO vIsBooked
|
||||
FROM `entry`
|
||||
WHERE id = vSelf;
|
||||
|
||||
IF vIsBooked THEN
|
||||
CALL util.throw('Entry is already booked');
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -2,54 +2,9 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketClon`(vTicketFk INT, vNewShipped DATE)
|
||||
BEGIN
|
||||
|
||||
DECLARE done INT DEFAULT FALSE;
|
||||
DECLARE vNewTicketFk INT;
|
||||
DECLARE vOldSaleFk INT;
|
||||
DECLARE vNewSaleFk INT;
|
||||
|
||||
DECLARE cur1 CURSOR FOR
|
||||
SELECT id
|
||||
FROM vn.sale
|
||||
WHERE ticketFk = vTicketFk;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
|
||||
|
||||
SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE());
|
||||
|
||||
CALL vn.ticket_Clone(vTicketFk, vNewTicketFk);
|
||||
|
||||
UPDATE vn.ticket
|
||||
SET landed = TIMESTAMPADD(DAY, DATEDIFF(vNewShipped, shipped), landed),
|
||||
shipped = vNewShipped
|
||||
WHERE id = vNewTicketFk;
|
||||
|
||||
OPEN cur1;
|
||||
|
||||
read_loop: LOOP
|
||||
|
||||
FETCH cur1 INTO vOldSaleFk;
|
||||
|
||||
IF done THEN
|
||||
LEAVE read_loop;
|
||||
END IF;
|
||||
|
||||
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed)
|
||||
SELECT vNewTicketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed
|
||||
FROM vn.sale
|
||||
WHERE id = vOldSaleFk;
|
||||
|
||||
SELECT max(id) INTO vNewSaleFk
|
||||
FROM vn.sale
|
||||
WHERE ticketFk = vNewTicketFk;
|
||||
|
||||
INSERT INTO vn.saleComponent(saleFk, componentFk, value, isGreuge)
|
||||
SELECT vNewSaleFk, componentFk, value, isGreuge
|
||||
FROM vn.saleComponent
|
||||
WHERE saleFk = vOldSaleFk;
|
||||
|
||||
END LOOP;
|
||||
|
||||
CLOSE cur1;
|
||||
CALL ticket_cloneAll(vTicketFk, vNewShipped, TRUE, vNewTicketFk);
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_cloneAll`(vTicketFk INT, vNewShipped DATE, vWithWarehouse BOOLEAN, OUT vNewTicketFk INT)
|
||||
BEGIN
|
||||
|
||||
DECLARE vDone BOOLEAN DEFAULT FALSE;
|
||||
DECLARE vOldSaleFk INT;
|
||||
DECLARE vNewSaleFk INT;
|
||||
|
||||
DECLARE cur1 CURSOR FOR
|
||||
SELECT id
|
||||
FROM sale
|
||||
WHERE ticketFk = vTicketFk;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE());
|
||||
|
||||
CALL ticket_Clone(vTicketFk, vNewTicketFk);
|
||||
|
||||
UPDATE ticket
|
||||
SET landed = TIMESTAMPADD(DAY, DATEDIFF(vNewShipped, shipped), landed),
|
||||
shipped = vNewShipped,
|
||||
warehouseFk = IF(vWithWarehouse, warehouseFk, NULL)
|
||||
WHERE id = vNewTicketFk;
|
||||
|
||||
OPEN cur1;
|
||||
|
||||
read_loop: LOOP
|
||||
|
||||
FETCH cur1 INTO vOldSaleFk;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE read_loop;
|
||||
END IF;
|
||||
|
||||
INSERT INTO sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed)
|
||||
SELECT vNewTicketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed
|
||||
FROM sale
|
||||
WHERE id = vOldSaleFk;
|
||||
|
||||
SELECT max(id) INTO vNewSaleFk
|
||||
FROM sale
|
||||
WHERE ticketFk = vNewTicketFk;
|
||||
|
||||
INSERT INTO saleComponent(saleFk, componentFk, value, isGreuge)
|
||||
SELECT vNewSaleFk, componentFk, value, isGreuge
|
||||
FROM saleComponent
|
||||
WHERE saleFk = vOldSaleFk;
|
||||
|
||||
END LOOP;
|
||||
|
||||
CLOSE cur1;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_beforeDelete`
|
|||
BEFORE DELETE ON `buy`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL entry_checkBooked(OLD.entryFk);
|
||||
IF OLD.printedStickers <> 0 THEN
|
||||
CALL util.throw("it is not possible to delete buys with printed labels ");
|
||||
END IF;
|
||||
|
|
|
@ -15,6 +15,7 @@ trig: BEGIN
|
|||
LEAVE trig;
|
||||
END IF;
|
||||
|
||||
CALL entry_checkBooked(NEW.entryFk);
|
||||
IF NEW.printedStickers <> 0 THEN
|
||||
CALL util.throw('it is not possible to create buy lines with printedstickers other than 0');
|
||||
END IF;
|
||||
|
|
|
@ -13,6 +13,7 @@ trig:BEGIN
|
|||
LEAVE trig;
|
||||
END IF;
|
||||
|
||||
CALL entry_checkBooked(OLD.entryFk);
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
|
||||
SELECT defaultEntry INTO vDefaultEntry
|
||||
|
|
|
@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_beforeDelete`
|
|||
BEFORE DELETE ON `entry`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL entry_checkBooked(OLD.id);
|
||||
DELETE FROM buy WHERE entryFk = OLD.id;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -7,6 +7,10 @@ BEGIN
|
|||
DECLARE vPrintedCount INT;
|
||||
DECLARE vHasDistinctWarehouses BOOL;
|
||||
|
||||
IF NEW.isBooked = OLD.isBooked THEN
|
||||
CALL entry_checkBooked(OLD.id);
|
||||
END IF;
|
||||
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
|
||||
IF NOT (NEW.travelFk <=> OLD.travelFk) THEN
|
||||
|
|
|
@ -12,5 +12,5 @@ FROM (
|
|||
`pc`.`id` = `b`.`workerBusinessProfessionalCategoryFk`
|
||||
)
|
||||
)
|
||||
WHERE `pc`.`name` = 'Aux ventas'
|
||||
WHERE `pc`.`description` = 'Aux ventas'
|
||||
GROUP BY `b`.`workerFk`
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||
VALUES('Ticket', 'clone', 'WRITE', 'ALLOW', 'ROLE', 'administrative');
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE vn.professionalCategory DROP COLUMN dayBreak, DROP COLUMN `level`;
|
||||
ALTER TABLE vn.professionalCategory
|
||||
CHANGE name description varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL;
|
|
@ -0,0 +1,54 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('clone', {
|
||||
description: 'clone a ticket and return the new ticket id',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The ticket id',
|
||||
http: {source: 'path'}
|
||||
}, {
|
||||
arg: 'shipped',
|
||||
type: 'date',
|
||||
}, {
|
||||
arg: 'withWarehouse',
|
||||
type: 'boolean',
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/clone`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.clone = async(ctx, id, shipped, withWarehouse, options) => {
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const [, [{clonedTicketId}]] = await Self.rawSql(`
|
||||
CALL vn.ticket_cloneAll(?, ?, ?, @clonedTicketId);
|
||||
SELECT @clonedTicketId clonedTicketId;`,
|
||||
[id, shipped, withWarehouse], myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return clonedTicketId;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,56 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('Ticket cloning - clone function', () => {
|
||||
let ctx;
|
||||
let options;
|
||||
let tx;
|
||||
const ticketId = 1;
|
||||
const shipped = Date.vnNew();
|
||||
|
||||
beforeEach(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 9},
|
||||
headers: {origin: 'http://localhost'}
|
||||
},
|
||||
args: {}
|
||||
};
|
||||
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: ctx.req
|
||||
});
|
||||
|
||||
options = {transaction: tx};
|
||||
tx = await models.Ticket.beginTransaction({});
|
||||
options.transaction = tx;
|
||||
});
|
||||
|
||||
afterEach(async() => {
|
||||
await tx.rollback();
|
||||
});
|
||||
|
||||
it('should clone a new ticket without warehouse', async() => {
|
||||
const originalTicket = await models.Ticket.findById(ticketId, null, options);
|
||||
|
||||
const newTicketId = await models.Ticket.clone(ctx, ticketId, shipped, false, options);
|
||||
const newTicket = await models.Ticket.findById(newTicketId, null, options);
|
||||
|
||||
expect(newTicket.clientFk).toEqual(originalTicket.clientFk);
|
||||
expect(newTicket.companyFk).toEqual(originalTicket.companyFk);
|
||||
expect(newTicket.addressFk).toEqual(originalTicket.addressFk);
|
||||
expect(newTicket.warehouseFk).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should clone a new ticket with warehouse', async() => {
|
||||
const originalTicket = await models.Ticket.findById(ticketId, null, options);
|
||||
|
||||
const newTicketId = await models.Ticket.clone(ctx, ticketId, shipped, true, options);
|
||||
const newTicket = await models.Ticket.findById(newTicketId, null, options);
|
||||
|
||||
expect(newTicket.clientFk).toEqual(originalTicket.clientFk);
|
||||
expect(newTicket.companyFk).toEqual(originalTicket.companyFk);
|
||||
expect(newTicket.addressFk).toEqual(originalTicket.addressFk);
|
||||
expect(newTicket.warehouseFk).toEqual(originalTicket.warehouseFk);
|
||||
});
|
||||
});
|
|
@ -46,4 +46,6 @@ module.exports = function(Self) {
|
|||
require('../methods/ticket/invoiceTicketsAndPdf')(Self);
|
||||
require('../methods/ticket/docuwareDownload')(Self);
|
||||
require('../methods/ticket/myLastModified')(Self);
|
||||
require('../methods/ticket/addSaleByCode')(Self);
|
||||
require('../methods/ticket/clone')(Self);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('./ticket-methods')(Self);
|
||||
require('../methods/ticket/state')(Self);
|
||||
require('../methods/ticket/addSaleByCode')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue