Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2470-account_e2e
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-05-25 07:35:59 +02:00
commit 316bd56acc
79 changed files with 1217 additions and 345 deletions

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethodCtx('setSaleQuantity', {
Self.remoteMethod('setSaleQuantity', {
description: 'Update sale quantity',
accessType: 'WRITE',
accepts: [{
@ -24,11 +24,13 @@ module.exports = Self => {
}
});
Self.setSaleQuantity = async ctx => {
const args = ctx.args;
Self.setSaleQuantity = async(saleId, quantity) => {
const models = Self.app.models;
const sale = await models.Sale.findById(args.saleId);
return await sale.updateAttribute('quantity', args.quantity);
const sale = await models.Sale.findById(saleId);
return await sale.updateAttributes({
originalQuantity: sale.quantity,
quantity: quantity
});
};
};

View File

@ -5,19 +5,12 @@ describe('setSaleQuantity()', () => {
const saleId = 30;
const newQuantity = 10;
const ctx = {
args: {
saleId: saleId,
quantity: newQuantity
}
};
const originalSale = await models.Sale.findById(saleId);
await models.Collection.setSaleQuantity(ctx);
await models.Collection.setSaleQuantity(saleId, newQuantity);
const updateSale = await models.Sale.findById(saleId);
expect(updateSale.quantity).toBeLessThan(originalSale.quantity);
expect(updateSale.originalQuantity).toEqual(originalSale.quantity);
expect(updateSale.quantity).toEqual(newQuantity);
});
});

View File

@ -68,6 +68,12 @@
"Language": {
"dataSource": "vn"
},
"MachineWorker": {
"dataSource": "vn"
},
"MobileAppVersionControl": {
"dataSource": "vn"
},
"Module": {
"dataSource": "vn"
},

View File

@ -28,6 +28,9 @@
},
"maxAmount": {
"type": "number"
},
"daysInFuture": {
"type": "number"
}
},
"acls": [{

View File

@ -0,0 +1,24 @@
{
"name": "MobileAppVersionControl",
"base": "VnModel",
"options": {
"mysql": {
"table": "vn.mobileAppVersionControl"
}
},
"properties": {
"id": {
"type": "number",
"id": true
},
"appName": {
"type": "string"
},
"version": {
"type": "string"
},
"isVersionCritical": {
"type": "boolean"
}
}
}

View File

@ -0,0 +1,33 @@
{
"name": "MachineWorker",
"base": "VnModel",
"options": {
"mysql": {
"table": "vn.machineWorker"
}
},
"properties": {
"id": {
"type": "number",
"id": true
},
"workerFk": {
"type": "number"
},
"machineFk": {
"type": "number"
},
"inTime": {
"type": "date",
"mysql": {
"columnName": "inTimed"
}
},
"outTime": {
"type": "date",
"mysql": {
"columnName": "outTimed"
}
}
}
}

View File

@ -1,14 +0,0 @@
create table `vn`.`invoiceOut_queue`
(
invoiceFk int(10) unsigned not null,
queued datetime default now() not null,
printed datetime null,
`status` VARCHAR(50) default '' null,
constraint invoiceOut_queue_pk
primary key (invoiceFk),
constraint invoiceOut_queue_invoiceOut_id_fk
foreign key (invoiceFk) references invoiceOut (id)
on update cascade on delete cascade
)
comment 'Queue for PDF invoicing';

View File

@ -2,49 +2,64 @@ DROP PROCEDURE IF EXISTS vn.ticket_doRefund;
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
/**
* Crea un ticket de abono a partir de tmp.sale y/o tmp.ticketService
*
* @return vNewTicket
*/
DECLARE vDone BIT DEFAULT 0;
DECLARE vCustomer MEDIUMINT;
DECLARE vClientFk MEDIUMINT;
DECLARE vWarehouse TINYINT;
DECLARE vCompany MEDIUMINT;
DECLARE vAddress MEDIUMINT;
DECLARE vRefundAgencyMode INT;
DECLARE vItemFk INT;
DECLARE vQuantity DECIMAL (10,2);
DECLARE vConcept VARCHAR(50);
DECLARE vPrice DECIMAL (10,2);
DECLARE vDiscount TINYINT;
DECLARE vRefundAgencyMode INT;
DECLARE vItemFk INT;
DECLARE vQuantity DECIMAL (10,2);
DECLARE vConcept VARCHAR(50);
DECLARE vPrice DECIMAL (10,2);
DECLARE vDiscount TINYINT;
DECLARE vSaleNew INT;
DECLARE vSaleMain INT;
DECLARE vZoneFk INT;
DECLARE vDescription VARCHAR(50);
DECLARE vTaxClassFk INT;
DECLARE vTicketServiceTypeFk INT;
DECLARE cSales CURSOR FOR
SELECT *
FROM tmp.sale;
DECLARE vSaleMain INT;
DECLARE vZoneFk INT;
DECLARE vDescription VARCHAR(50);
DECLARE vTaxClassFk INT;
DECLARE vTicketServiceTypeFk INT;
DECLARE vOriginTicket INT;
DECLARE cSales CURSOR FOR
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
FROM tmp.sale s;
DECLARE cTicketServices CURSOR FOR
SELECT *
FROM tmp.ticketService;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1;
SELECT id INTO vRefundAgencyMode
SELECT ts.description, - ts.quantity, ts.price, ts.taxClassFk, ts.ticketServiceTypeFk
FROM tmp.ticketService ts;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
SELECT sub.ticketFk INTO vOriginTicket
FROM (
SELECT s.ticketFk
FROM tmp.sale s
UNION ALL
SELECT ts.ticketFk
FROM tmp.ticketService ts
) sub
LIMIT 1;
SELECT id INTO vRefundAgencyMode
FROM agencyMode WHERE `name` = 'ABONO';
SELECT clientFk, warehouseFk, companyFk, addressFk
INTO vCustomer, vWarehouse, vCompany, vAddress
FROM ticket
WHERE id = vOriginTicket;
SELECT id INTO vZoneFk
INTO vClientFk, vWarehouse, vCompany, vAddress
FROM ticket
WHERE id = vOriginTicket;
SELECT id INTO vZoneFk
FROM zone WHERE agencyModeFk = vRefundAgencyMode
LIMIT 1;
LIMIT 1;
INSERT INTO vn.ticket (
clientFk,
shipped,
@ -54,10 +69,10 @@ BEGIN
warehouseFk,
companyFk,
landed,
zoneFk
zoneFk
)
SELECT
vCustomer,
vClientFk,
CURDATE(),
vAddress,
vRefundAgencyMode,
@ -65,49 +80,48 @@ BEGIN
vWarehouse,
vCompany,
CURDATE(),
vZoneFk
vZoneFk
FROM address a
WHERE a.id = vAddress;
SET vNewTicket = LAST_INSERT_ID();
SET vDone := 0;
SET vDone := FALSE;
OPEN cSales;
FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
WHILE NOT vDone DO
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount)
VALUES( vNewTicket, vItemFk, vQuantity, vConcept, vPrice, vDiscount );
SET vSaleNew = LAST_INSERT_ID();
INSERT INTO vn.saleComponent(saleFk,componentFk,`value`)
SELECT vSaleNew,componentFk,`value`
FROM vn.saleComponent
WHERE saleFk = vSaleMain;
SET vSaleNew = LAST_INSERT_ID();
INSERT INTO vn.saleComponent(saleFk,componentFk,`value`)
SELECT vSaleNew,componentFk,`value`
FROM vn.saleComponent
WHERE saleFk = vSaleMain;
FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
END WHILE;
CLOSE cSales;
SET vDone := 0;
SET vDone := FALSE;
OPEN cTicketServices;
FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk;
FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk;
WHILE NOT vDone DO
INSERT INTO vn.ticketService(description, quantity, price, taxClassFk, ticketFk, ticketServiceTypeFk)
VALUES(vDescription, vQuantity, vPrice, vTaxClassFk, vNewTicket, vTicketServiceTypeFk);
FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk;
END WHILE;
CLOSE cTicketServices;
INSERT INTO vn.ticketRefund(refundTicketFk, originalTicketFk)
VALUES(vNewTicket, vOriginTicket);
END$$
DELIMITER ;

View File

@ -0,0 +1,4 @@
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('ItemType', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
('ItemType', '*', 'WRITE', 'ALLOW', 'ROLE', 'buyer');

View File

@ -3,8 +3,8 @@ CREATE TABLE `vn`.`clientUnpaid` (
`dated` date NOT NULL,
`amount` double DEFAULT 0,
PRIMARY KEY (`clientFk`),
CONSTRAINT `clientUnpaid_clientFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE
CONSTRAINT `clientUnpaid_clientFk` FOREIGN KEY (`clientFk`) REFERENCES `vn`.`client` (`id`) ON UPDATE CASCADE
);
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES('ClientUnpaid', '*', '*', 'ALLOW', 'ROLE', 'administrative');
VALUES('ClientUnpaid', '*', '*', 'ALLOW', 'ROLE', 'administrative');

View File

@ -0,0 +1,8 @@
CREATE TABLE `vn`.`invoiceOut_queue` (
`invoiceFk` int(10) unsigned not null,
`queued` datetime default now() not null,
`printed` datetime null,
`status` VARCHAR(50) DEFAULT '' NULL,
CONSTRAINT `invoiceOut_queue_pk` PRIMARY KEY (`invoiceFk`),
CONSTRAINT `invoiceOut_queue_invoiceOut_id_fk` FOREIGN KEY (`invoiceFk`) REFERENCES `vn`.`invoiceOut` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
) comment 'Queue for PDF invoicing';

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn`.`accountingType` ADD daysInFuture INT NULL;
ALTER TABLE `vn`.`accountingType` MODIFY COLUMN daysInFuture int(11) DEFAULT 0 NULL;

View File

@ -99,13 +99,19 @@ INSERT INTO `account`.`mailForward`(`account`, `forwardTo`)
VALUES
(1, 'employee@domain.local');
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`, `phone`)
INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`)
VALUES
(1106, 'LGN', 'David Charles', 'Haller', 1106, 19, 432978106),
(1107, 'ANT', 'Hank' , 'Pym' , 1107, 19, 432978107),
(1108, 'DCX', 'Charles' , 'Xavier', 1108, 19, 432978108),
(1109, 'HLK', 'Bruce' , 'Banner', 1109, 19, 432978109),
(1110, 'JJJ', 'Jessica' , 'Jones' , 1110, 19, 432978110);
(1, 'printer1', 'path1', 0),
(2, 'printer2', 'path2', 1);
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`, `phone`, `sectorFk`, `labelerFk`)
VALUES
(1106, 'LGN', 'David Charles', 'Haller', 1106, 19, 432978106, NULL, NULL),
(1107, 'ANT', 'Hank' , 'Pym' , 1107, 19, 432978107, NULL, 1),
(1108, 'DCX', 'Charles' , 'Xavier', 1108, 19, 432978108, 1, NULL),
(1109, 'HLK', 'Bruce' , 'Banner', 1109, 19, 432978109, 1, 2),
(1110, 'JJJ', 'Jessica' , 'Jones' , 1110, 19, 432978110, 2, 1);
INSERT INTO `vn`.`currency`(`id`, `code`, `name`, `ratio`)
VALUES
@ -113,7 +119,7 @@ INSERT INTO `vn`.`currency`(`id`, `code`, `name`, `ratio`)
(2, 'USD', 'Dollar USA', 1.4),
(3, 'GBP', 'Libra', 1),
(4, 'JPY', 'Yen Japones', 1);
INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`, `continentFk`, `hasDailyInvoice`, `CEE`)
VALUES
(1, 'España', 1, 'ES', 1, 24, 4, 0, 1),
@ -156,22 +162,23 @@ INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `park
('HEJ', 2, 0, 1, 0, 1106),
('UXN', 1, 0, 1, 0, 1106);
INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`, `maxAmount`)
INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`, `maxAmount`, `daysInFuture`)
VALUES
(1, 'CC y Polizas de crédito', NULL, NULL, NULL),
(2, 'Cash', 'Cash', 'cash', 1000),
(3, 'Credit card', 'Credit Card', 'creditCard', NULL),
(4, 'Finalcial lines', NULL, NULL, NULL),
(5, 'Other products', NULL, NULL, NULL),
(6, 'Loans', NULL, NULL, NULL),
(7, 'Leasing', NULL, NULL, NULL),
(8, 'Compensations', 'Compensations', 'compensation', NULL);
(1, 'CC and credit policies', 'Transfers', 'wireTransfer', NULL, 1),
(2, 'Cash', 'Cash', 'cash', 1000, 0),
(3, 'Credit card', 'Credit Card', 'creditCard', NULL, 0),
(4, 'Finalcial lines', NULL, NULL, NULL, 0),
(5, 'Other products', NULL, NULL, NULL, 0),
(6, 'Loans', NULL, NULL, NULL, 0),
(7, 'Leasing', NULL, NULL, NULL, 0),
(8, 'Compensations', 'Compensations', 'compensation', NULL, 0);
INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`, `currencyFk`)
VALUES
(1, 'Pay on receipt', '5720000001', 3, 0, 1, 1),
(2, 'Cash', '5700000001', 2, 0, 1, 1),
(3, 'Compensation', '4000000000', 8, 0, 1, 1),
(4, 'Transfers', '4000000001', 1, 0, 1, 1),
(3117, 'Caixa Rural d''Algemesi', '5720000000', 8, 3117, 1, 1);
@ -744,14 +751,19 @@ INSERT INTO `vn`.`itemCategory`(`id`, `name`, `display`, `color`, `icon`, `code`
(7, 'Accessories', 1, NULL, 'icon-accessory', 'accessory'),
(8, 'Fruit', 1, NULL, 'icon-fruit', 'fruit');
INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `warehouseFk`, `life`,`workerFk`, `isPackaging`)
INSERT INTO `vn`.`temperature`(`code`, `name`, `description`)
VALUES
(1, 'CRI', 'Crisantemo', 2, 1, 31, 35, 0),
(2, 'ITG', 'Anthurium', 1, 1, 31, 35, 0),
(3, 'WPN', 'Paniculata', 2, 1, 31, 35, 0),
(4, 'PRT', 'Delivery ports', 3, 1, NULL, 35, 1),
(5, 'CON', 'Container', 3, 1, NULL, 35, 1),
(6, 'ALS', 'Alstroemeria', 1, 1, 31, 16, 0);
('warm', 'Warm', 'Warm'),
('cool', 'Cool', 'Cool');
INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `warehouseFk`, `life`,`workerFk`, `isPackaging`, `temperatureFk`)
VALUES
(1, 'CRI', 'Crisantemo', 2, 1, 31, 35, 0, 'cool'),
(2, 'ITG', 'Anthurium', 1, 1, 31, 35, 0, 'cool'),
(3, 'WPN', 'Paniculata', 2, 1, 31, 35, 0, 'cool'),
(4, 'PRT', 'Delivery ports', 3, 1, NULL, 35, 1, 'warm'),
(5, 'CON', 'Container', 3, 1, NULL, 35, 1, 'warm'),
(6, 'ALS', 'Alstroemeria', 1, 1, 31, 16, 0, 'warm');
INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`)
VALUES
@ -809,25 +821,25 @@ INSERT INTO `vn`.`itemFamily`(`code`, `description`)
('VT', 'Sales');
INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `expenceFk`,
`comment`, `relevancy`, `image`, `subName`, `minPrice`, `stars`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`)
`comment`, `relevancy`, `image`, `subName`, `minPrice`, `stars`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`, `packingShelve`)
VALUES
(1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 1, 'VT', 0, NULL, 'V', 0),
(2, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 2, 'VT', 0, NULL, 'H', 0),
(3, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 5, 'VT', 0, NULL, NULL, 0),
(4, 1, 60, 'YEL', 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 3, 'VT', 0, NULL, NULL, 0),
(5, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 3, 'VT', 0, NULL, NULL, 0),
(6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 4, 'VT', 0, NULL, NULL, 0),
(7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 4, 'VT', 0, NULL, NULL, 0),
(8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 5, 'VT', 0, NULL, NULL, 0),
(9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 4, 'VT', 1, NULL, NULL, 0),
(10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 4, 'VT', 0, NULL, NULL, 0),
(11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 4, 'VT', 0, NULL, NULL, 0),
(12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 3, 'VT', 0, NULL, NULL, 0),
(13, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 2, 'VT', 1, NULL, NULL, 1),
(14, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 4, 'VT', 1, NULL, NULL, 0),
(15, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0),
(16, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0),
(71, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'VT', 0, NULL, NULL, 0);
(1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 1, 'VT', 0, NULL, 'V', 0, 15),
(2, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 2, 'VT', 0, NULL, 'H', 0, 10),
(3, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, 5),
(4, 1, 60, 'YEL', 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL),
(5, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL),
(6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL),
(7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL),
(8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, NULL),
(9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL),
(10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL),
(11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL),
(12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL),
(13, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 2, 'VT', 1, NULL, NULL, 1, NULL),
(14, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL),
(15, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL),
(16, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL),
(71, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'VT', 0, NULL, NULL, 0, NULL);
-- Update the taxClass after insert of the items
UPDATE `vn`.`itemTaxCountry` SET `taxClassFk` = 2
@ -1621,51 +1633,59 @@ INSERT INTO `hedera`.`orderRowComponent`(`rowFk`, `componentFk`, `price`)
INSERT INTO `hedera`.`visit`(`id`, `firstAgentFk`)
VALUES
(1, NULL),
(2, NULL),
(3, NULL),
(4, NULL),
(5, NULL),
(6, NULL),
(7, NULL),
(8, NULL),
(9, NULL);
(1, NULL),
(2, NULL),
(3, NULL),
(4, NULL),
(5, NULL),
(6, NULL),
(7, NULL),
(8, NULL),
(9, NULL),
(10, NULL),
(11, NULL);
INSERT INTO `hedera`.`visitAgent`(`id`, `visitFk`)
VALUES
(1, 1),
(2, 2),
(3, 3),
(4, 4),
(5, 5),
(6, 6),
(7, 7),
(8, 8),
(9, 9);
(1, 1),
(2, 2),
(3, 3),
(4, 4),
(5, 5),
(6, 6),
(7, 7),
(8, 8),
(9, 9),
(10, 10),
(11, 11);
INSERT INTO `hedera`.`visitAccess`(`id`, `agentFk`, `stamp`)
VALUES
(1, 1, CURDATE()),
(2, 2, CURDATE()),
(3, 3, CURDATE()),
(4, 4, CURDATE()),
(5, 5, CURDATE()),
(6, 6, CURDATE()),
(7, 7, CURDATE()),
(8, 8, CURDATE()),
(9, 9, CURDATE());
(1, 1, CURDATE()),
(2, 2, CURDATE()),
(3, 3, CURDATE()),
(4, 4, CURDATE()),
(5, 5, CURDATE()),
(6, 6, CURDATE()),
(7, 7, CURDATE()),
(8, 8, CURDATE()),
(9, 9, CURDATE()),
(10, 10, CURDATE()),
(11, 11, CURDATE());
INSERT INTO `hedera`.`visitUser`(`id`, `accessFk`, `userFk`, `stamp`)
VALUES
(1, 1, 1101, CURDATE()),
(2, 2, 1101, CURDATE()),
(3, 3, 1101, CURDATE()),
(4, 4, 1102, CURDATE()),
(5, 5, 1102, CURDATE()),
(6, 6, 1102, CURDATE()),
(7, 7, 1103, CURDATE()),
(8, 8, 1103, CURDATE()),
(9, 9, 1103, CURDATE());
(1, 1, 1101, CURDATE()),
(2, 2, 1101, CURDATE()),
(3, 3, 1101, CURDATE()),
(4, 4, 1102, CURDATE()),
(5, 5, 1102, CURDATE()),
(6, 6, 1102, CURDATE()),
(7, 7, 1103, CURDATE()),
(8, 8, 1103, CURDATE()),
(9, 9, 1103, CURDATE()),
(10, 10, 1102, DATE_SUB(CURDATE(), INTERVAL 1 DAY)),
(11, 11, 1103, DATE_SUB(CURDATE(), INTERVAL 1 DAY));
INSERT INTO `hedera`.`userSession`(`created`, `lastUpdate`, `ssid`, `data`, `userVisitFk`)
VALUES
@ -2290,11 +2310,6 @@ INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `week
(1, 43200, 129600, 734400, 43200, 50400, 259200, 1296000, 36000);
INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11');
INSERT INTO `vn`.`temperature`(`code`, `name`, `description`)
VALUES
('warm', 'Warm', 'Warm'),
('cool', 'Cool', 'Cool');
INSERT INTO `vn`.`thermograph`(`id`, `model`)
VALUES
@ -2545,6 +2560,20 @@ INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackage
(4, 2, 0, 20.00, 0.00, NULL, 0, 0.00, 0),
(5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0);
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
INSERT INTO `vn`.`mobileAppVersionControl` (`appName`, `version`, `isVersionCritical`)
VALUES
('UserAccount', '*', '*', 'ALLOW', 'ROLE', 'sysadmin');
('delivery', '9.2', 0),
('warehouse', '8.1', 0);
INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmentFk`, `type`, `use`, `productionYear`, `workerFk`, `companyFk`)
VALUES
('RE-001', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442),
('RE-002', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442);
INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed`)
VALUES
(1106, 1, CURDATE(), CURDATE()),
(1106, 1, DATE_ADD(CURDATE(), INTERVAL + 1 DAY), DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
(1106, 2, CURDATE(), NULL),
(1106, 2, DATE_ADD(CURDATE(), INTERVAL + 1 DAY), DATE_ADD(CURDATE(), INTERVAL +1 DAY));

View File

@ -37460,6 +37460,31 @@ SET character_set_client = utf8;
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
--
-- Temporary table structure for view `printer`
--
DROP TABLE IF EXISTS `printer`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `printer` (
`id` tinyint(3) unsigned NOT NULL,
`name` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`path` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`modelFk` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`macWifi` varchar(20) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`ipAddress` varchar(15) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`reference` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`isLabeler` tinyint(1) DEFAULT 0 COMMENT 'Indica si es impresora de etiquetas',
PRIMARY KEY (`id`),
UNIQUE KEY `printer_UN` (`reference`),
UNIQUE KEY `printer_UN1` (`macWifi`),
UNIQUE KEY `printer_UN2` (`name`),
KEY `printer_FK` (`modelFk`),
CONSTRAINT `printer_FK` FOREIGN KEY (`modelFk`) REFERENCES `printerModel` (`code`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `printingQueueCheck`
--

View File

@ -60,7 +60,6 @@ IGNORETABLES=(
--ignore-table=vn.plantpassportAuthority__
--ignore-table=vn.preparationException
--ignore-table=vn.priceFixed__
--ignore-table=vn.printer
--ignore-table=vn.printingQueue
--ignore-table=vn.printServerQueue__
--ignore-table=vn.promissoryNote

View File

@ -146,16 +146,17 @@ export default class MultiCheck extends FormInput {
if (!this.model || !this.model.data) return;
const data = this.model.data;
const modelParams = this.model.userParams;
const params = {
filter: {
modelParams: modelParams,
limit: null
}
};
if (this.model.userFilter)
Object.assign(params.filter, this.model.userFilter);
if (this.model.userParams)
Object.assign(params, this.model.userParams);
this.rows = data.length;
this.$http.get(this.model.url, {params})
.then(res => {
this.allRowsCount = res.data.length;

View File

@ -46,11 +46,13 @@
</div>
</vn-horizontal>
<div id="table"></div>
<vn-pagination
ng-if="$ctrl.model"
model="$ctrl.model"
class="vn-pt-md">
</vn-pagination>
<div ng-transclude="pagination">
<vn-pagination
ng-if="$ctrl.model"
model="$ctrl.model"
class="vn-pt-md">
</vn-pagination>
</div>
</div>
<vn-confirm

View File

@ -497,7 +497,8 @@ ngModule.vnComponent('smartTable', {
controller: SmartTable,
transclude: {
table: '?slotTable',
actions: '?slotActions'
actions: '?slotActions',
pagination: '?slotPagination'
},
bindings: {
model: '<?',

View File

@ -6,7 +6,6 @@ class Controller extends Component {
this._role = value;
this.$.summary = null;
if (!value) return;
this.$http.get(`Roles/${value.id}`)
.then(res => this.$.summary = res.data);
}

View File

@ -39,7 +39,7 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId;
const sms = await models.Sms.send(ctx, id, destination, message);
const sms = await models.Sms.send(ctx, destination, message);
const logRecord = {
originFk: id,
userFk: userId,

View File

@ -6,10 +6,6 @@ module.exports = Self => {
description: 'Sends SMS to a destination phone',
accessType: 'WRITE',
accepts: [
{
arg: 'destinationFk',
type: 'integer'
},
{
arg: 'destination',
type: 'string',
@ -31,7 +27,7 @@ module.exports = Self => {
}
});
Self.send = async(ctx, destinationFk, destination, message) => {
Self.send = async(ctx, destination, message) => {
const userId = ctx.req.accessToken.userId;
const smsConfig = await Self.app.models.SmsConfig.findOne();
@ -68,7 +64,6 @@ module.exports = Self => {
const newSms = {
senderFk: userId,
destinationFk: destinationFk || null,
destination: destination,
message: message,
status: error

View File

@ -3,7 +3,7 @@ const app = require('vn-loopback/server/server');
describe('sms send()', () => {
it('should not return status error', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const result = await app.models.Sms.send(ctx, 1105, '123456789', 'My SMS Body');
const result = await app.models.Sms.send(ctx, '123456789', 'My SMS Body');
expect(result.status).toBeUndefined();
});

View File

@ -6,12 +6,7 @@ class Controller extends Dialog {
super($element, $, $transclude);
this.vnReport = vnReport;
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
this.receipt = {
payed: tomorrow
};
this.receipt = {};
}
set payed(value) {
@ -72,6 +67,10 @@ class Controller extends Dialog {
`${accountingType && accountingType.receiptDescription}`;
}
this.maxAmount = accountingType && accountingType.maxAmount;
this.receipt.payed = new Date();
if (accountingType.daysInFuture)
this.receipt.payed.setDate(this.receipt.payed.getDate() + accountingType.daysInFuture);
}
}

View File

@ -98,9 +98,6 @@ module.exports = Self => {
Self.latestBuysFilter = async(ctx, filter, options) => {
const myOptions = {};
if (filter && filter.modelParams)
ctx.args = filter.modelParams;
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -148,12 +148,12 @@
</td>
<td number>
<vn-chip class="transparent" translate-attr="buy.groupingMode == 2 ? {title: 'Minimun amount'} : {title: 'Packing'}" ng-class="{'message': buy.groupingMode == 2}">
<span translate>{{::buy.packing | dashIfEmpty}}</span>
<span>{{::buy.packing | dashIfEmpty}}</span>
</vn-chip>
</td>
<td number>
<vn-chip class="transparent" translate-attr="buy.groupingMode == 1 ? {title: 'Minimun amount'} : {title: 'Grouping'}" ng-class="{'message': buy.groupingMode == 1}">
<span translate>{{::buy.grouping | dashIfEmpty}}</span>
<span>{{::buy.grouping | dashIfEmpty}}</span>
</vn-chip>
</td>
<td number>{{::buy.quantity}}</td>

View File

@ -159,8 +159,22 @@ export default class Controller extends Section {
lines: rowsToEdit
};
if (this.checkedDummyCount && this.checkedDummyCount > 0)
data.filter = this.$.model.userParams;
if (this.checkedDummyCount && this.checkedDummyCount > 0) {
const params = {};
if (this.$.model.userParams) {
const userParams = this.$.model.userParams;
for (let param in userParams) {
let newParam = this.exprBuilder(param, userParams[param]);
if (!newParam)
newParam = {[param]: userParams[param]};
Object.assign(params, newParam);
}
}
if (this.$.model.userFilter)
Object.assign(params, this.$.model.userFilter.where);
data.filter = params;
}
return this.$http.post('Buys/editLatestBuys', data)
.then(() => {

View File

@ -76,6 +76,13 @@
translate>
Show CITES letter
</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-menu>
<vn-confirm
@ -88,6 +95,11 @@
on-accept="$ctrl.bookInvoiceOut()"
question="Are you sure you want to book this invoice?">
</vn-confirm>
<vn-confirm
vn-id="refundConfirmation"
on-accept="$ctrl.refundInvoiceOut()"
question="Are you sure you want to refund this invoice?">
</vn-confirm>
<vn-client-descriptor-popover
vn-id="clientDescriptor">
</vn-client-descriptor-popover>

View File

@ -116,6 +116,35 @@ class Controller extends Section {
invoiceId: this.id
});
}
async refundInvoiceOut() {
let filter = {
where: {refFk: this.invoiceOut.ref}
};
const tickets = await this.$http.get('Tickets', {filter});
this.tickets = tickets.data;
this.ticketsIds = [];
for (let ticket of this.tickets)
this.ticketsIds.push(ticket.id);
filter = {
where: {ticketFk: {inq: this.ticketsIds}}
};
const sales = await this.$http.get('Sales', {filter});
this.sales = sales.data;
const ticketServices = await this.$http.get('TicketServices', {filter});
this.services = ticketServices.data;
const params = {
sales: this.sales,
services: this.services
};
const query = `Sales/refund`;
return this.$http.post(query, params).then(res => {
this.$state.go('ticket.card.sale', {id: res.data});
});
}
}
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];

View File

@ -122,4 +122,34 @@ describe('vnInvoiceOutDescriptorMenu', () => {
expect(controller.vnApp.showMessage).toHaveBeenCalled();
});
});
// #4084 review with Juan
xdescribe('refundInvoiceOut()', () => {
it('should make a query and go to ticket.card.sale', () => {
controller.$state.go = jest.fn();
const invoiceOut = {
id: 1,
ref: 'T1111111'
};
controller.invoiceOut = invoiceOut;
const tickets = [{id: 1}];
const sales = [{id: 1}];
const services = [{id: 2}];
$httpBackend.expectGET(`Tickets`).respond(tickets);
$httpBackend.expectGET(`Sales`).respond(sales);
$httpBackend.expectGET(`TicketServices`).respond(services);
const expectedParams = {
sales: sales,
services: services
};
$httpBackend.expectPOST(`Sales/refund`, expectedParams).respond();
controller.refundInvoiceOut();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: undefined});
});
});
});

View File

@ -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?
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 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
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

View File

@ -21,8 +21,11 @@
"life": {
"type": "number"
},
"isPackaging": {
"type": "boolean"
"promo": {
"type": "number"
},
"isUnconventionalSize": {
"type": "number"
}
},
"relations": {
@ -40,6 +43,16 @@
"type": "belongsTo",
"model": "ItemCategory",
"foreignKey": "categoryFk"
},
"itemPackingType": {
"type": "belongsTo",
"model": "ItemPackingType",
"foreignKey": "itemPackingTypeFk"
},
"temperature": {
"type": "belongsTo",
"model": "Temperature",
"foreignKey": "temperatureFk"
}
},
"acls": [

View File

@ -140,6 +140,9 @@
},
"isFloramondo": {
"type": "boolean"
},
"packingShelve": {
"type": "number"
}
},
"relations": {

View File

@ -23,4 +23,4 @@ import './waste/index/';
import './waste/detail';
import './fixed-price';
import './fixed-price-search-panel';
import './item-type';

View File

@ -0,0 +1,62 @@
<vn-watcher
vn-id="watcher"
url="ItemTypes"
data="$ctrl.itemType"
form="form">
</vn-watcher>
<form
name="form"
ng-submit="watcher.submit()"
class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-vertical>
<vn-textfield
label="Code"
ng-model="$ctrl.itemType.code"
rule
vn-focus>
</vn-textfield>
<vn-textfield
label="Name"
ng-model="$ctrl.itemType.name"
rule>
</vn-textfield>
<vn-autocomplete
label="Worker"
ng-model="$ctrl.itemType.workerFk"
url="Workers"
show-field="firstName"
value-field="id"
rule>
</vn-autocomplete>
<vn-autocomplete
label="Category"
ng-model="$ctrl.itemType.categoryFk"
url="ItemCategories"
show-field="name"
value-field="id"
rule>
</vn-autocomplete>
<vn-autocomplete
label="Temperature"
ng-model="$ctrl.itemType.temperatureFk"
url="Temperatures"
show-field="name"
value-field="code"
rule>
</vn-autocomplete>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit
disabled="!watcher.dataChanged()"
label="Save">
</vn-submit>
<vn-button
class="cancel"
label="Undo changes"
disabled="!watcher.dataChanged()"
ng-click="watcher.loadOriginalData()">
</vn-button>
</vn-button-bar>
</form>

View File

@ -0,0 +1,12 @@
import ngModule from '../../module';
import Section from 'salix/components/section';
export default class Controller extends Section {}
ngModule.component('vnItemTypeBasicData', {
template: require('./index.html'),
controller: Controller,
bindings: {
itemType: '<'
}
});

View File

@ -0,0 +1,5 @@
<vn-portal slot="menu">
<vn-item-type-descriptor item-type="$ctrl.itemType"></vn-item-type-descriptor>
<vn-left-menu source="itemType"></vn-left-menu>
</vn-portal>
<ui-view></ui-view>

View File

@ -0,0 +1,23 @@
import ngModule from '../../module';
import ModuleCard from 'salix/components/module-card';
class Controller extends ModuleCard {
reload() {
const filter = {
include: [
{relation: 'worker'},
{relation: 'category'},
{relation: 'itemPackingType'},
{relation: 'temperature'}
]
};
this.$http.get(`ItemTypes/${this.$params.id}`, {filter})
.then(res => this.itemType = res.data);
}
}
ngModule.vnComponent('vnItemTypeCard', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,27 @@
import './index';
describe('component vnItemTypeCard', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('item'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnItemTypeCard', {$element: null});
}));
describe('reload()', () => {
it('should reload the controller data', () => {
controller.$params.id = 1;
const itemType = {id: 1};
$httpBackend.expectGET('ItemTypes/1').respond(itemType);
controller.reload();
$httpBackend.flush();
expect(controller.itemType).toEqual(itemType);
});
});
});

View File

@ -0,0 +1,62 @@
<vn-watcher
vn-id="watcher"
url="ItemTypes"
data="$ctrl.itemType"
insert-mode="true"
form="form">
</vn-watcher>
<form
name="form"
vn-http-submit="$ctrl.onSubmit()"
class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-vertical>
<vn-textfield
label="Code"
ng-model="$ctrl.itemType.code"
rule
vn-focus>
</vn-textfield>
<vn-textfield
label="Name"
ng-model="$ctrl.itemType.name"
rule>
</vn-textfield>
<vn-autocomplete
label="Worker"
ng-model="$ctrl.itemType.workerFk"
url="Workers"
show-field="firstName"
value-field="id"
rule>
</vn-autocomplete>
<vn-autocomplete
label="Category"
ng-model="$ctrl.itemType.categoryFk"
url="ItemCategories"
show-field="name"
value-field="id"
rule>
</vn-autocomplete>
<vn-autocomplete
label="Temperature"
ng-model="$ctrl.itemType.temperatureFk"
url="Temperatures"
show-field="name"
value-field="code"
rule>
</vn-autocomplete>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit
disabled="!watcher.dataChanged()"
label="Create">
</vn-submit>
<vn-button
class="cancel"
label="Cancel"
ui-sref="item.itemType">
</vn-button>
</vn-button-bar>
</form>

View File

@ -0,0 +1,15 @@
import ngModule from '../../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
onSubmit() {
return this.$.watcher.submit().then(res =>
this.$state.go('item.itemType.card.basicData', {id: res.data.id})
);
}
}
ngModule.component('vnItemTypeCreate', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,34 @@
import './index';
describe('component vnItemTypeCreate', () => {
let $scope;
let $state;
let controller;
beforeEach(ngModule('item'));
beforeEach(inject(($componentController, $rootScope, _$state_) => {
$scope = $rootScope.$new();
$state = _$state_;
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback({data: {id: '1234'}});
}
};
}
};
const $element = angular.element('<vn-item-type-create></vn-item-type-create>');
controller = $componentController('vnItemTypeCreate', {$element, $scope});
}));
describe('onSubmit()', () => {
it(`should call submit() on the watcher then expect a callback`, () => {
jest.spyOn($state, 'go');
controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith('item.itemType.card.basicData', {id: '1234'});
});
});
});

View File

@ -0,0 +1,25 @@
<vn-descriptor-content
module="item"
base-state="item.itemType"
description="$ctrl.itemType.code">
<slot-body>
<div class="attributes">
<vn-label-value
label="Code"
value="{{$ctrl.itemType.code}}">
</vn-label-value>
<vn-label-value
label="Name"
value="{{$ctrl.itemType.name}}">
</vn-label-value>
<vn-label-value
label="Worker"
value="{{$ctrl.itemType.worker.firstName}} {{$ctrl.itemType.worker.lastName}}">
</vn-label-value>
<vn-label-value
label="Category"
value="{{$ctrl.itemType.category.name}}">
</vn-label-value>
</div>
</slot-body>
</vn-descriptor-content>

View File

@ -0,0 +1,20 @@
import ngModule from '../../module';
import Descriptor from 'salix/components/descriptor';
class Controller extends Descriptor {
get itemType() {
return this.entity;
}
set itemType(value) {
this.entity = value;
}
}
ngModule.component('vnItemTypeDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
itemType: '<'
}
});

View File

@ -0,0 +1,8 @@
import './main';
import './index/';
import './summary';
import './card';
import './descriptor';
import './create';
import './basic-data';
import './search-panel';

View File

@ -0,0 +1,43 @@
<vn-crud-model
vn-id="model"
auto-load="true"
url="ItemTypes"
data="itemTypes"
order="name">
</vn-crud-model>
<vn-data-viewer
model="model"
class="vn-w-sm">
<vn-card>
<div class="vn-list separated">
<a
ng-repeat="itemType in itemTypes track by itemType.id"
ui-sref="item.itemType.card.summary(::{id: itemType.id})"
ui-sref-opts="{inherit: false}"
translate-attr="{title: 'View itemType'}"
class="vn-item search-result">
<vn-item-section>
<h6>{{::itemType.code}}</h6>
<div>{{::itemType.name}}</div>
</vn-item-section>
<vn-item-section side>
<vn-icon-button
vn-click-stop="$ctrl.preview(itemType)"
vn-tooltip="Preview"
icon="preview">
</vn-icon-button>
</vn-item-section>
</a>
</div>
</vn-card>
</vn-data-viewer>
<vn-popup vn-id="summary">
<vn-item-type-summary item-type="$ctrl.selectedItemType"></vn-item-type-summary>
</vn-popup>
<a ui-sref="item.itemType.create"
vn-tooltip="New itemType"
vn-bind="+"
fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>

View File

@ -0,0 +1,14 @@
import ngModule from '../../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
preview(itemType) {
this.selectedItemType = itemType;
this.$.summary.show();
}
}
ngModule.component('vnItemTypeIndex', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,34 @@
import './index';
describe('Item', () => {
describe('Component vnItemTypeIndex', () => {
let controller;
let $window;
beforeEach(ngModule('item'));
beforeEach(inject(($componentController, _$window_) => {
$window = _$window_;
const $element = angular.element('<vn-item-type-summary></vn-item-type-summary>');
controller = $componentController('vnItemTypeIndex', {$element});
}));
describe('preview()', () => {
it('should show the dialog summary', () => {
controller.$.summary = {show: () => {}};
jest.spyOn(controller.$.summary, 'show');
const itemType = {id: 1};
const event = new MouseEvent('click', {
view: $window,
bubbles: true,
cancelable: true
});
controller.preview(event, itemType);
expect(controller.$.summary.show).toHaveBeenCalledWith();
});
});
});
});

View File

@ -0,0 +1,2 @@
Item Type: Familia
New itemType: Nueva familia

View File

@ -0,0 +1,18 @@
<vn-crud-model
vn-id="model"
url="ItemTypes"
filter="::$ctrl.filter"
limit="20">
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
info="Search itemType by id, name or code"
panel="vn-item-type-search-panel"
model="model"
expr-builder="$ctrl.exprBuilder(param, value)"
base-state="item.itemType">
</vn-searchbar>
</vn-portal>
<ui-view>
<vn-item-type-index></vn-item-type-index>
</ui-view>

View File

@ -0,0 +1,24 @@
import ngModule from '../../module';
import ModuleMain from 'salix/components/module-main';
export default class ItemType extends ModuleMain {
exprBuilder(param, value) {
switch (param) {
case 'search':
return /^\d+$/.test(value)
? {id: value}
: {or: [
{name: {like: `%${value}%`}},
{code: {like: `%${value}%`}}
]};
case 'name':
case 'code':
return {[param]: {like: `%${value}%`}};
}
}
}
ngModule.vnComponent('vnItemType', {
controller: ItemType,
template: require('./index.html')
});

View File

@ -0,0 +1,31 @@
import './index';
describe('Item', () => {
describe('Component vnItemType', () => {
let controller;
beforeEach(ngModule('item'));
beforeEach(inject($componentController => {
const $element = angular.element('<vn-item-type></vn-item-type>');
controller = $componentController('vnItemType', {$element});
}));
describe('exprBuilder()', () => {
it('should return a filter based on a search by id', () => {
const filter = controller.exprBuilder('search', '123');
expect(filter).toEqual({id: '123'});
});
it('should return a filter based on a search by name or code', () => {
const filter = controller.exprBuilder('search', 'Alstroemeria');
expect(filter).toEqual({or: [
{name: {like: '%Alstroemeria%'}},
{code: {like: '%Alstroemeria%'}},
]});
});
});
});
});

View File

@ -0,0 +1 @@
Search itemType by id, name or code: Buscar familia por id, nombre o código

View File

@ -0,0 +1,22 @@
<div class="search-panel">
<form ng-submit="$ctrl.onSearch()">
<vn-horizontal>
<vn-textfield
vn-one
label="Name"
ng-model="filter.name"
vn-focus>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="Code"
ng-model="filter.code">
</vn-textfield>
</vn-horizontal>
<vn-horizontal class="vn-mt-lg">
<vn-submit label="Search"></vn-submit>
</vn-horizontal>
</form>
</div>

View File

@ -0,0 +1,7 @@
import ngModule from '../../module';
import SearchPanel from 'core/components/searchbar/search-panel';
ngModule.component('vnItemTypeSearchPanel', {
template: require('./index.html'),
controller: SearchPanel
});

View File

@ -0,0 +1,50 @@
<vn-card class="summary">
<h5>
<span>{{summary.id}} - {{summary.name}} - {{summary.worker.firstName}} {{summary.worker.lastName}}</span>
</h5>
<vn-horizontal class="vn-pa-md">
<vn-one>
<h4 translate>Basic data</h4>
<vn-label-value
label="Id"
value="{{summary.id}}">
</vn-label-value>
<vn-label-value
label="Code"
value="{{summary.code}}">
</vn-label-value>
<vn-label-value
label="Name"
value="{{summary.name}}">
</vn-label-value>
<vn-label-value
label="Worker"
value="{{summary.worker.firstName}} {{summary.worker.lastName}}">
</vn-label-value>
<vn-label-value
label="Category"
value="{{summary.category.name}}">
</vn-label-value>
<vn-label-value
label="Temperature"
value="{{summary.temperature.name}}">
</vn-label-value>
<vn-label-value
label="Life"
value="{{summary.life}}">
</vn-label-value>
<vn-label-value
label="Promo"
value="{{summary.promo}}">
</vn-label-value>
<vn-label-value
label="Item packing type"
value="{{summary.itemPackingType.description}}">
</vn-label-value>
<vn-label-value
label="Is unconventional size"
value="{{summary.isUnconventionalSize}}">
</vn-label-value>
</vn-one>
</vn-horizontal>
</vn-card>

View File

@ -0,0 +1,33 @@
import ngModule from '../../module';
import Component from 'core/lib/component';
class Controller extends Component {
set itemType(value) {
this._itemType = value;
this.$.summary = null;
if (!value) return;
const filter = {
include: [
{relation: 'worker'},
{relation: 'category'},
{relation: 'itemPackingType'},
{relation: 'temperature'}
]
};
this.$http.get(`ItemTypes/${value.id}`, {filter})
.then(res => this.$.summary = res.data);
}
get itemType() {
return this._itemType;
}
}
ngModule.component('vnItemTypeSummary', {
template: require('./index.html'),
controller: Controller,
bindings: {
itemType: '<'
}
});

View File

@ -0,0 +1,4 @@
Life: Vida
Promo: Promoción
Item packing type: Tipo de embalaje
Is unconventional size: Es de tamaño poco convencional

View File

@ -9,7 +9,8 @@
{"state": "item.index", "icon": "icon-item"},
{"state": "item.request", "icon": "icon-buyrequest"},
{"state": "item.waste.index", "icon": "icon-claims"},
{"state": "item.fixedPrice", "icon": "icon-fixedPrice"}
{"state": "item.fixedPrice", "icon": "icon-fixedPrice"},
{"state": "item.itemType", "icon": "contact_support"}
],
"card": [
{"state": "item.card.basicData", "icon": "settings"},
@ -20,6 +21,9 @@
{"state": "item.card.diary", "icon": "icon-transaction"},
{"state": "item.card.last-entries", "icon": "icon-regentry"},
{"state": "item.card.log", "icon": "history"}
],
"itemType": [
{"state": "item.itemType.card.basicData", "icon": "settings"}
]
},
"keybindings": [
@ -169,6 +173,47 @@
"component": "vn-fixed-price",
"description": "Fixed prices",
"acl": ["buyer"]
},
{
"url" : "/item-type?q",
"state": "item.itemType",
"component": "vn-item-type",
"description": "Item Type",
"acl": ["buyer"]
},
{
"url": "/create",
"state": "item.itemType.create",
"component": "vn-item-type-create",
"description": "New itemType",
"acl": ["buyer"]
},
{
"url": "/:id",
"state": "item.itemType.card",
"component": "vn-item-type-card",
"abstract": true,
"description": "Detail"
},
{
"url": "/summary",
"state": "item.itemType.card.summary",
"component": "vn-item-type-summary",
"description": "Summary",
"params": {
"item-type": "$ctrl.itemType"
},
"acl": ["buyer"]
},
{
"url": "/basic-data",
"state": "item.itemType.card.basicData",
"component": "vn-item-type-basic-data",
"description": "Basic data",
"params": {
"item-type": "$ctrl.itemType"
},
"acl": ["buyer"]
}
]
}

View File

@ -43,11 +43,9 @@ module.exports = Self => {
TIME(v.stamp) AS hour,
DATE(v.stamp) AS dated,
wtc.workerFk
FROM hedera.userSession s
JOIN hedera.visitUser v ON v.id = s.userVisitFk
FROM hedera.visitUser v
JOIN client c ON c.id = v.userFk
LEFT JOIN account.user u ON c.salesPersonFk = u.id
LEFT JOIN worker w ON c.salesPersonFk = w.id
JOIN account.user u ON c.salesPersonFk = u.id
LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk
AND CURDATE() BETWEEN sc.started AND sc.ended
LEFT JOIN workerTeamCollegues wtc
@ -58,7 +56,9 @@ module.exports = Self => {
const where = filter.where;
where['wtc.workerFk'] = userId;
stmt.merge(conn.makeSuffix(filter));
stmt.merge(conn.makeWhere(filter.where));
stmt.merge(`GROUP BY clientFk, v.stamp`);
stmt.merge(conn.makePagination(filter));
return conn.executeStmt(stmt, myOptions);
};

View File

@ -6,12 +6,49 @@ describe('SalesMonitor clientsFilter()', () => {
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 18}}, args: {}};
const filter = {order: 'dated DESC'};
const from = new Date();
const to = new Date();
from.setHours(0, 0, 0, 0);
to.setHours(23, 59, 59, 59);
const filter = {
where: {
'v.stamp': {between: [from, to]}
}
};
const result = await models.SalesMonitor.clientsFilter(ctx, filter, options);
expect(result.length).toEqual(9);
expect(result.length).toEqual(3);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return the clients web activity filtered', async() => {
const tx = await models.SalesMonitor.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 18}}, args: {}};
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
const today = new Date();
yesterday.setHours(0, 0, 0, 0);
today.setHours(23, 59, 59, 59);
const filter = {
where: {
'v.stamp': {between: [yesterday, today]}
}
};
const result = await models.SalesMonitor.clientsFilter(ctx, filter, options);
expect(result.length).toEqual(5);
await tx.rollback();
} catch (e) {

View File

@ -88,8 +88,16 @@
</td>
</tr>
</tbody>
<table>
<slot-table>
</table>
</slot-table>
<slot-pagination>
<vn-pagination
model="model"
class="vn-pt-xs"
scroll-selector="vn-monitor-sales-clients smart-table"
scroll-offset="100">
</vn-pagination>
</slot-pagination>
</smart-table>
</vn-card>
<vn-worker-descriptor-popover

View File

@ -2,19 +2,19 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('refund', {
description: 'Create ticket with the selected lines changing the sign to the quantites',
description: 'Create ticket refund with lines and services changing the sign to the quantites',
accessType: 'WRITE',
accepts: [{
arg: 'sales',
description: 'The sales',
type: ['object'],
required: true
required: false
},
{
arg: 'ticketId',
type: 'number',
required: true,
description: 'The ticket id'
arg: 'services',
type: ['object'],
required: false,
description: 'The services'
}],
returns: {
type: 'number',
@ -26,7 +26,7 @@ module.exports = Self => {
}
});
Self.refund = async(ctx, sales, ticketId, options) => {
Self.refund = async(ctx, sales, services, options) => {
const myOptions = {};
let tx;
@ -39,7 +39,6 @@ module.exports = Self => {
}
try {
const salesIds = [];
const userId = ctx.req.accessToken.userId;
const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager');
@ -49,39 +48,47 @@ module.exports = Self => {
if (!hasValidRole)
throw new UserError(`You don't have privileges to create refund`);
for (let sale of sales)
salesIds.push(sale.id);
const salesIds = [];
if (sales) {
for (let sale of sales)
salesIds.push(sale.id);
} else
salesIds.push(null);
const servicesIds = [];
if (services) {
for (let service of services)
servicesIds.push(service.id);
} else
servicesIds.push(null);
const query = `
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketService;
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, s.ticketFk
FROM sale s
WHERE s.id IN (?);
CREATE TEMPORARY TABLE tmp.ticketService(
description VARCHAR(50),
quantity DECIMAL (10,2),
price DECIMAL (10,2),
taxClassFk INT,
ticketServiceTypeFk INT
);
CALL vn.ticket_doRefund(?, @newTicket);
CREATE TEMPORARY TABLE tmp.ticketService
SELECT ts.description, ts.quantity, ts.price, ts.taxClassFk, ts.ticketServiceTypeFk, ts.ticketFk
FROM ticketService ts
WHERE ts.id IN (?);
CALL vn.ticket_doRefund(@newTicket);
DROP TEMPORARY TABLE tmp.sale;
DROP TEMPORARY TABLE tmp.ticketService;`;
await Self.rawSql(query, [salesIds, ticketId], myOptions);
await Self.rawSql(query, [salesIds, servicesIds], myOptions);
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
ticketId = newTicket.id;
const newTicketId = newTicket.id;
if (tx) await tx.commit();
return ticketId;
return newTicketId;
} catch (e) {
if (tx) await tx.rollback();
throw e;

View File

@ -1,78 +0,0 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('refundAll', {
description: 'Create ticket with all lines and services changing the sign to the quantites',
accessType: 'WRITE',
accepts: [{
arg: 'ticketId',
type: 'number',
required: true,
description: 'The ticket id'
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/refundAll`,
verb: 'post'
}
});
Self.refundAll = async(ctx, ticketId, options) => {
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const userId = ctx.req.accessToken.userId;
const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager');
const isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant');
const hasValidRole = isClaimManager || isSalesAssistant;
if (!hasValidRole)
throw new UserError(`You don't have privileges to create refund`);
const query = `
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketService;
CREATE TEMPORARY TABLE tmp.sale
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
WHERE t.id IN (?);
CREATE TEMPORARY TABLE tmp.ticketService
SELECT ts.description, - ts.quantity, ts.price, ts.taxClassFk, ts.ticketServiceTypeFk
FROM ticketService ts
WHERE ts.ticketFk IN (?);
CALL vn.ticket_doRefund(?, @newTicket);
DROP TEMPORARY TABLE tmp.sale;
DROP TEMPORARY TABLE tmp.ticketService;`;
await Self.rawSql(query, [ticketId, ticketId, ticketId], myOptions);
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
ticketId = newTicket.id;
if (tx) await tx.commit();
return ticketId;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -1,20 +1,20 @@
const models = require('vn-loopback/server/server').models;
describe('sale refund()', () => {
const sales = [
{id: 7, ticketFk: 11},
{id: 8, ticketFk: 11}
];
const services = [{id: 1}];
it('should create ticket with the selected lines changing the sign to the quantites', async() => {
const tx = await models.Sale.beginTransaction({});
const ctx = {req: {accessToken: {userId: 9}}};
const ticketId = 11;
const sales = [
{id: 7, ticketFk: 11},
{id: 8, ticketFk: 11}
];
try {
const options = {transaction: tx};
const response = await models.Sale.refund(ctx, sales, ticketId, options);
const response = await models.Sale.refund(ctx, sales, services, options);
const [newTicketId] = await models.Sale.rawSql('SELECT MAX(t.id) id FROM vn.ticket t;', null, options);
expect(response).toEqual(newTicketId.id);
@ -30,17 +30,12 @@ describe('sale refund()', () => {
const tx = await models.Sale.beginTransaction({});
const ctx = {req: {accessToken: {userId: 1}}};
const ticketId = 11;
const sales = [
{id: 7, ticketFk: 11}
];
let error;
try {
const options = {transaction: tx};
await models.Sale.refund(ctx, sales, ticketId, options);
await models.Sale.refund(ctx, sales, services, options);
await tx.rollback();
} catch (e) {

View File

@ -45,7 +45,7 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId;
try {
const sms = await Self.app.models.Sms.send(ctx, id, destination, message);
const sms = await Self.app.models.Sms.send(ctx, destination, message);
const logRecord = {
originFk: id,
userFk: userId,

View File

@ -7,7 +7,6 @@ module.exports = Self => {
require('../methods/sale/updateConcept')(Self);
require('../methods/sale/recalculatePrice')(Self);
require('../methods/sale/refund')(Self);
require('../methods/sale/refundAll')(Self);
require('../methods/sale/canEdit')(Self);
Self.validatesPresenceOf('concept', {

View File

@ -38,6 +38,9 @@
},
"created": {
"type": "date"
},
"originalQuantity":{
"type": "number"
}
},
"relations": {

View File

@ -302,7 +302,7 @@
<!-- Refund all confirmation dialog -->
<vn-confirm
vn-id="refundAllConfirmation"
on-accept="$ctrl.refundAll()"
on-accept="$ctrl.refund()"
question="Are you sure you want to refund all?"
message="Refund all">
</vn-confirm>

View File

@ -273,9 +273,21 @@ class Controller extends Section {
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
}
refundAll() {
const params = {ticketId: this.id};
const query = `Sales/refundAll`;
async refund() {
const filter = {
where: {ticketFk: this.id}
};
const sales = await this.$http.get('Sales', {filter});
this.sales = sales.data;
const ticketServices = await this.$http.get('TicketServices', {filter});
this.services = ticketServices.data;
const params = {
sales: this.sales,
services: this.services
};
const query = `Sales/refund`;
return this.$http.post(query, params).then(res => {
this.$state.go('ticket.card.sale', {id: res.data});
});

View File

@ -262,16 +262,27 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
});
});
describe('refundAll()', () => {
// #4084 review with Juan
xdescribe('refund()', () => {
it('should make a query and go to ticket.card.sale', () => {
jest.spyOn(controller.$state, 'go').mockReturnValue();
const expectedParams = {ticketId: ticket.id};
controller.$state.go = jest.fn();
$httpBackend.expect('POST', `Sales/refundAll`, expectedParams).respond({ticketId: 16});
controller.refundAll();
controller._id = ticket.id;
const sales = [{id: 1}];
const services = [{id: 2}];
$httpBackend.expectGET(`Sales`).respond(sales);
$httpBackend.expectGET(`TicketServices`).respond(services);
const expectedParams = {
sales: sales,
services: services
};
$httpBackend.expectPOST(`Sales/refund`, expectedParams).respond();
controller.refund();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: {ticketId: ticket.id}});
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: undefined});
});
});

View File

@ -483,7 +483,7 @@ class Controller extends Section {
const sales = this.selectedValidSales();
if (!sales) return;
const params = {sales: sales, ticketId: this.ticket.id};
const params = {sales: sales};
const query = `Sales/refund`;
this.resetChanges();
this.$http.post(query, params).then(res => {

View File

@ -42,7 +42,7 @@
</append>
</vn-autocomplete>
<vn-input-number
vn-one min="0"
vn-one
step="1"
label="Quantity"
ng-model="service.quantity"

View File

@ -135,7 +135,8 @@ module.exports = Self => {
function formatDate(date) {
let day = date.getDate();
if (day < 10) day = `0${day}`;
let month = date.getMonth();
let month = date.getMonth() + 1;
if (month < 10) month = `0${month}`;
let year = date.getFullYear();

View File

@ -87,7 +87,7 @@ module.exports = Self => {
function formatDate(date) {
let day = date.getDate();
if (day < 10) day = `0${day}`;
let month = date.getMonth();
let month = date.getMonth() + 1;
if (month < 10) month = `0${month}`;
let year = date.getFullYear();

View File

@ -20,6 +20,9 @@
"EducationLevel": {
"dataSource": "vn"
},
"Sector": {
"dataSource": "vn"
},
"WorkCenter": {
"dataSource": "vn"
},

View File

@ -0,0 +1,20 @@
{
"name": "Sector",
"base": "VnModel",
"options": {
"mysql": {
"table": "sector"
}
},
"properties": {
"id": {
"type": "number",
"id": true,
"description": "Identifier"
},
"description": {
"type": "string",
"required": true
}
}
}

View File

@ -46,6 +46,9 @@
},
"SSN": {
"type" : "string"
},
"labelerFk": {
"type" : "number"
}
},
"relations": {
@ -78,6 +81,11 @@
"type": "hasMany",
"model": "WorkerTeamCollegues",
"foreignKey": "workerFk"
},
"sector": {
"type": "belongsTo",
"model": "Sector",
"foreignKey": "sectorFk"
}
}
}

View File

@ -67,7 +67,6 @@
<vn-input-number
label="Bonus"
ng-model="$ctrl.zone.bonus"
min="0"
step="0.01"
vn-acl="deliveryBoss"
rule>

View File

@ -14,5 +14,6 @@ FROM route r
LEFT JOIN account.user u ON u.id = w.userFk
LEFT JOIN agencyMode am ON am.id = r.agencyModeFk
LEFT JOIN agency a ON a.id = am.agencyFk
LEFT JOIN supplier s ON s.id = a.supplierFk
LEFT JOIN supplierAgencyTerm sa ON sa.agencyFk = a.id
LEFT JOIN supplier s ON s.id = sa.supplierFk
WHERE r.id IN(?)