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

This commit is contained in:
Vicent Llopis 2022-07-29 13:38:23 +02:00
commit 537c383cd2
73 changed files with 717 additions and 326 deletions

View File

@ -10,7 +10,7 @@ module.exports = Self => {
}, },
http: { http: {
path: `/sendQueued`, path: `/sendQueued`,
verb: 'POST' verb: 'GET'
} }
}); });

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
@ -11,11 +12,11 @@ module.exports = Self => {
}, },
http: { http: {
path: `/deleteTrashFiles`, path: `/deleteTrashFiles`,
verb: 'POST' verb: 'GET'
} }
}); });
Self.deleteTrashFiles = async(options) => { Self.deleteTrashFiles = async options => {
const tx = await Self.beginTransaction({}); const tx = await Self.beginTransaction({});
const myOptions = {}; const myOptions = {};
@ -26,6 +27,9 @@ module.exports = Self => {
myOptions.transaction = tx; myOptions.transaction = tx;
try { try {
if (process.env.NODE_ENV == 'test')
throw new UserError(`Action not allowed on the test environment`);
const models = Self.app.models; const models = Self.app.models;
const DmsContainer = models.DmsContainer; const DmsContainer = models.DmsContainer;
@ -33,9 +37,15 @@ module.exports = Self => {
where: {code: 'trash'} where: {code: 'trash'}
}, myOptions); }, myOptions);
const date = new Date();
date.setMonth(date.getMonth() - 4);
const dmsToDelete = await models.Dms.find({ const dmsToDelete = await models.Dms.find({
where: { where: {
dmsTypeFk: trashDmsType.id and: [
{dmsTypeFk: trashDmsType.id},
{created: {lt: date}}
]
} }
}, myOptions); }, myOptions);
@ -43,14 +53,19 @@ module.exports = Self => {
const pathHash = DmsContainer.getHash(dms.id); const pathHash = DmsContainer.getHash(dms.id);
const dmsContainer = await DmsContainer.container(pathHash); const dmsContainer = await DmsContainer.container(pathHash);
const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file); const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file);
const dstFolder = path.join(dmsContainer.client.root, pathHash);
await fs.unlink(dstFile); await fs.unlink(dstFile);
await dms.destroy(myOptions); try {
await fs.rmdir(dstFolder);
await dms.destroy(myOptions);
} catch (err) {
await dms.destroy(myOptions);
}
} }
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;
} }
}; };

View File

@ -1,2 +1,3 @@
ALTER TABLE `vn`.`accountingType` ADD daysInFuture INT NULL; ALTER TABLE `vn`.`accountingType` ADD daysInFuture INT NULL;
ALTER TABLE `vn`.`accountingType` MODIFY COLUMN daysInFuture int(11) DEFAULT 0 NULL; ALTER TABLE `vn`.`accountingType` MODIFY COLUMN daysInFuture int(11) DEFAULT 0 NULL;
UPDATE `vn`.`accountingType` SET daysInFuture=1 WHERE id=8;

View File

@ -0,0 +1,3 @@
ALTER TABLE `vn`.`chat` MODIFY COLUMN message TEXT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL;
ALTER TABLE `vn`.`chat` MODIFY COLUMN dated DATETIME DEFAULT NULL NULL;
ALTER TABLE `vn`.`chat` ADD error TEXT NULL;

View File

@ -0,0 +1,3 @@
ALTER TABLE `vn`.`creditInsurance`
ADD CONSTRAINT `creditInsurance_creditClassificationFk` FOREIGN KEY (`creditClassificationFk`)
REFERENCES `vn`.`creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -1,6 +1,21 @@
INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
VALUES VALUES
('InvoiceOut','refund','WRITE','ALLOW','ROLE','invoicing'),
('InvoiceOut','refund','WRITE','ALLOW','ROLE','salesAssistant'),
('InvoiceOut','refund','WRITE','ALLOW','ROLE','claimManager'),
('Ticket','refund','WRITE','ALLOW','ROLE','invoicing'),
('Ticket','refund','WRITE','ALLOW','ROLE','salesAssistant'),
('Ticket','refund','WRITE','ALLOW','ROLE','claimManager'),
('Sale','refund','WRITE','ALLOW','ROLE','salesAssistant'),
('Sale','refund','WRITE','ALLOW','ROLE','claimManager'),
('TicketRefund','*','WRITE','ALLOW','ROLE','invoicing'),
('ClaimObservation','*','WRITE','ALLOW','ROLE','salesPerson'), ('ClaimObservation','*','WRITE','ALLOW','ROLE','salesPerson'),
('ClaimObservation','*','READ','ALLOW','ROLE','salesPerson'), ('ClaimObservation','*','READ','ALLOW','ROLE','salesPerson'),
('Client','setPassword','WRITE','ALLOW','ROLE','salesPerson'), ('Client','setPassword','WRITE','ALLOW','ROLE','salesPerson'),
('Client','updateUser','WRITE','ALLOW','ROLE','salesPerson'); ('Client','updateUser','WRITE','ALLOW','ROLE','salesPerson');
DELETE FROM `salix`.`ACL` WHERE id=313;
UPDATE `salix`.`ACL`
SET principalId='invoicing'
WHERE id=297;

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn2008`.`albaran_gestdoc` DROP FOREIGN KEY fk_albaran_gestdoc_gestdoc1;
ALTER TABLE `vn2008`.`albaran_gestdoc` ADD CONSTRAINT albaran_gestdoc_FK FOREIGN KEY (gestdoc_id) REFERENCES `vn`.`dms`(id) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,21 @@
DROP PROCEDURE IF EXISTS `vn`.`ticketRefund_beforeUpsert`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketRefund_beforeUpsert`(vRefundTicketFk INT, vOriginalTicketFk INT)
BEGIN
DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE;
IF vRefundTicketFk = vOriginalTicketFk THEN
CALL util.throw('Original ticket and refund ticket has same id');
END IF;
SELECT COUNT(*) INTO vAlreadyExists
FROM ticketRefund
WHERE originalTicketFk = vOriginalTicketFk;
IF vAlreadyExists > 0 THEN
CALL util.throw('This ticket is already a refund');
END IF;
END$$
DELIMITER ;

View File

@ -1353,7 +1353,7 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO
(7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1), (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1),
(8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2); (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2);
INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `ref`,`isInventory`, `isRaid`, `notes`, `evaNotes`) INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `ref`,`isExcludedFromAvailable`, `isRaid`, `notes`, `evaNotes`)
VALUES VALUES
(1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'Movement 1', 0, 0, '', ''), (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'Movement 1', 0, 0, '', ''),
(2, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'Movement 2', 0, 0, 'this is the note two', 'observation two'), (2, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'Movement 2', 0, 0, 'this is the note two', 'observation two'),
@ -2232,6 +2232,10 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`)
(8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'), (8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'),
(10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'); (10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun');
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`)
VALUES
(9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR));
INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`) INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`)
VALUES VALUES
(1106, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in'), (1106, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in'),

View File

@ -23,6 +23,7 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `account` /*!40100 DEFAULT CHARACTER SE
USE `account`; USE `account`;
-- --
-- Table structure for table `account` -- Table structure for table `account`
-- --
@ -7388,7 +7389,7 @@ proc: BEGIN
JOIN vn.warehouse w ON w.id = t.warehouseInFk JOIN vn.warehouse w ON w.id = t.warehouseInFk
WHERE t.landed BETWEEN vInventoryDate AND vStartDate WHERE t.landed BETWEEN vInventoryDate AND vStartDate
AND t.warehouseInFk = vWarehouse AND t.warehouseInFk = vWarehouse
AND NOT e.isInventory AND NOT e.isExcludedFromAvailable
GROUP BY b.itemFk GROUP BY b.itemFk
) c ) c
JOIN vn.item i ON i.id = c.item_id JOIN vn.item i ON i.id = c.item_id
@ -27101,7 +27102,7 @@ CREATE TABLE `entry` (
`dated` datetime NOT NULL, `dated` datetime NOT NULL,
`ref` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `ref` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`isBooked` tinyint(1) NOT NULL DEFAULT '0', `isBooked` tinyint(1) NOT NULL DEFAULT '0',
`isInventory` tinyint(1) NOT NULL DEFAULT '0', `isExcludedFromAvailable` tinyint(1) NOT NULL DEFAULT 0,
`notes` longtext COLLATE utf8_unicode_ci, `notes` longtext COLLATE utf8_unicode_ci,
`isConfirmed` tinyint(1) NOT NULL DEFAULT '0', `isConfirmed` tinyint(1) NOT NULL DEFAULT '0',
`isOrdered` tinyint(1) NOT NULL DEFAULT '0', `isOrdered` tinyint(1) NOT NULL DEFAULT '0',
@ -37102,6 +37103,7 @@ CREATE TABLE `ticket` (
`zoneBonus` decimal(10,2) DEFAULT NULL, `zoneBonus` decimal(10,2) DEFAULT NULL,
`totalWithVat` decimal(10,2) DEFAULT NULL COMMENT 'cache calculada del total con iva', `totalWithVat` decimal(10,2) DEFAULT NULL COMMENT 'cache calculada del total con iva',
`totalWithoutVat` decimal(10,2) DEFAULT NULL COMMENT 'cache calculada del total sin iva', `totalWithoutVat` decimal(10,2) DEFAULT NULL COMMENT 'cache calculada del total sin iva',
`weight` decimal(10,2) DEFAULT NULL COMMENT 'En caso de informar, se utilizará su valor para calcular el peso de la factura',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `Id_Cliente` (`clientFk`), KEY `Id_Cliente` (`clientFk`),
KEY `Id_Consigna` (`addressFk`), KEY `Id_Consigna` (`addressFk`),
@ -37124,7 +37126,7 @@ CREATE TABLE `ticket` (
CONSTRAINT `ticket_ibfk_9` FOREIGN KEY (`routeFk`) REFERENCES `route` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `ticket_ibfk_9` FOREIGN KEY (`routeFk`) REFERENCES `route` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `tickets_fk11` FOREIGN KEY (`collectionFk__`) REFERENCES `collection` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `tickets_fk11` FOREIGN KEY (`collectionFk__`) REFERENCES `collection` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `tickets_zone_fk` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON UPDATE CASCADE CONSTRAINT `tickets_zone_fk` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=InnoDB AUTO_INCREMENT=3750016 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ;
@ -43256,6 +43258,40 @@ BEGIN
) t1; ) t1;
RETURN totalAmount; RETURN totalAmount;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
/*!50003 DROP FUNCTION IF EXISTS `invoiceOutAmount` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceOut_getWeight`(vInvoice VARCHAR(15)) RETURNS decimal(10,2)
READS SQL DATA
BEGIN
DECLARE vTotalWeight DECIMAL(10,2);
SELECT SUM(CAST(IFNULL(i.stems, 1) * s.quantity *
IF(ic.grams, ic.grams, i.density * ic.cm3delivery / 1000)
/ 1000 AS DECIMAL(10,2)))
INTO vTotalWeight
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN item i ON i.id = s.itemFk
JOIN itemCost ic ON ic.itemFk = i.id
AND ic.warehouseFk = t.warehouseFk
WHERE t.refFk = vInvoice
AND i.intrastatFk ;
RETURN vTotalWeight;
END ;; END ;;
DELIMITER ; DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET sql_mode = @saved_sql_mode */ ;
@ -59568,7 +59604,7 @@ BEGIN
WHERE tr.landed >= vDateInventory WHERE tr.landed >= vDateInventory
AND vWarehouse = tr.warehouseInFk AND vWarehouse = tr.warehouseInFk
AND b.itemFk = vItemId AND b.itemFk = vItemId
AND e.isInventory = FALSE AND e.isExcludedFromAvailable = FALSE
AND e.isRaid = FALSE AND e.isRaid = FALSE
UNION ALL UNION ALL
@ -59603,7 +59639,7 @@ BEGIN
AND vWarehouse =tr.warehouseOutFk AND vWarehouse =tr.warehouseOutFk
AND s.id <> 4 AND s.id <> 4
AND b.itemFk = vItemId AND b.itemFk = vItemId
AND e.isInventory = FALSE AND e.isExcludedFromAvailable = FALSE
AND w.isFeedStock = FALSE AND w.isFeedStock = FALSE
AND e.isRaid = FALSE AND e.isRaid = FALSE
UNION ALL UNION ALL
@ -59857,7 +59893,7 @@ BEGIN
LEFT JOIN travel t ON t.id = e.travelFk LEFT JOIN travel t ON t.id = e.travelFk
WHERE t.landed BETWEEN vDatedFrom AND vDatedTo WHERE t.landed BETWEEN vDatedFrom AND vDatedTo
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
AND !e.isInventory AND !e.isExcludedFromAvailable
AND b.quantity != 0 AND b.quantity != 0
AND (vItemFk IS NULL OR b.itemFk = vItemFk) AND (vItemFk IS NULL OR b.itemFk = vItemFk)
UNION ALL UNION ALL
@ -59870,7 +59906,7 @@ BEGIN
LEFT JOIN travel t ON t.id = e.travelFk LEFT JOIN travel t ON t.id = e.travelFk
WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo
AND (vWarehouseFk IS NULL OR t.warehouseOutFk = vWarehouseFk) AND (vWarehouseFk IS NULL OR t.warehouseOutFk = vWarehouseFk)
AND !e.isInventory AND !e.isExcludedFromAvailable
AND b.quantity != 0 AND b.quantity != 0
AND (vItemFk IS NULL OR b.itemFk = vItemFk) AND (vItemFk IS NULL OR b.itemFk = vItemFk)
AND !e.isRaid AND !e.isRaid
@ -68688,7 +68724,7 @@ BEGIN
* Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar.
* *
* @param vDated Fecha de los tickets que se quieren adelantar. * @param vDated Fecha de los tickets que se quieren adelantar.
* @param vWarehouseFk Almacén * @param vWarehouseFk AlmacénitemEntryIn
*/ */
DECLARE vDateInventory DATE; DECLARE vDateInventory DATE;
DECLARE vDateToAdvance DATE; DECLARE vDateToAdvance DATE;
@ -79953,7 +79989,7 @@ USE `vn`;
/*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 SET collation_connection = utf8mb4_unicode_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `itemEntryIn` AS select `t`.`warehouseInFk` AS `warehouseInFk`,`t`.`landed` AS `landed`,`b`.`itemFk` AS `itemFk`,`b`.`quantity` AS `quantity`,`t`.`isReceived` AS `isReceived`,`e`.`isRaid` AS `isVirtualStock`,`e`.`id` AS `entryFk` from ((`buy` `b` join `entry` `e` on((`b`.`entryFk` = `e`.`id`))) join `travel` `t` on((`e`.`travelFk` = `t`.`id`))) where ((`e`.`isInventory` = 0) and (`b`.`quantity` <> 0)) */; /*!50001 VIEW `itemEntryIn` AS select `t`.`warehouseInFk` AS `warehouseInFk`,`t`.`landed` AS `landed`,`b`.`itemFk` AS `itemFk`,`b`.`quantity` AS `quantity`,`t`.`isReceived` AS `isReceived`,`e`.`isRaid` AS `isVirtualStock`,`e`.`id` AS `entryFk` from ((`buy` `b` join `entry` `e` on((`b`.`entryFk` = `e`.`id`))) join `travel` `t` on((`e`.`travelFk` = `t`.`id`))) where ((`e`.`isExcludedFromAvailable` = 0) and (`b`.`quantity` <> 0)) */;
/*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */; /*!50001 SET collation_connection = @saved_col_connection */;
@ -79972,7 +80008,7 @@ USE `vn`;
/*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 SET collation_connection = utf8mb4_unicode_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `itemEntryOut` AS select `t`.`warehouseOutFk` AS `warehouseOutFk`,`t`.`shipped` AS `shipped`,`b`.`itemFk` AS `itemFk`,-(`b`.`quantity`) AS `quantity`,`t`.`isDelivered` AS `isDelivered`,`e`.`id` AS `entryFk` from ((`buy` `b` join `entry` `e` on((`b`.`entryFk` = `e`.`id`))) join `travel` `t` on((`e`.`travelFk` = `t`.`id`))) where ((`e`.`isInventory` = 0) and (`e`.`isRaid` = 0) and (`b`.`quantity` <> 0)) */; /*!50001 VIEW `itemEntryOut` AS select `t`.`warehouseOutFk` AS `warehouseOutFk`,`t`.`shipped` AS `shipped`,`b`.`itemFk` AS `itemFk`,-(`b`.`quantity`) AS `quantity`,`t`.`isDelivered` AS `isDelivered`,`e`.`id` AS `entryFk` from ((`buy` `b` join `entry` `e` on((`b`.`entryFk` = `e`.`id`))) join `travel` `t` on((`e`.`travelFk` = `t`.`id`))) where ((`e`.`isExcludedFromAvailable` = 0) and (`e`.`isRaid` = 0) and (`b`.`quantity` <> 0)) */;
/*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */; /*!50001 SET collation_connection = @saved_col_connection */;

View File

@ -1102,7 +1102,7 @@ export default {
company: 'vn-entry-basic-data vn-autocomplete[ng-model="$ctrl.entry.companyFk"]', company: 'vn-entry-basic-data vn-autocomplete[ng-model="$ctrl.entry.companyFk"]',
ordered: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isOrdered"]', ordered: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isOrdered"]',
confirmed: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isConfirmed"]', confirmed: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isConfirmed"]',
inventory: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isInventory"]', inventory: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isExcludedFromAvailable"]',
raid: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isRaid"]', raid: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isRaid"]',
booked: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isBooked"]', booked: 'vn-entry-basic-data vn-check[ng-model="$ctrl.entry.isBooked"]',
save: 'vn-entry-basic-data button[type=submit]', save: 'vn-entry-basic-data button[type=submit]',

View File

@ -23,9 +23,9 @@ describe('Ticket services path', () => {
await page.waitForClassPresent(selectors.ticketService.firstAddServiceTypeButton, 'disabled'); await page.waitForClassPresent(selectors.ticketService.firstAddServiceTypeButton, 'disabled');
await page.waitToClick(selectors.ticketService.addServiceButton); await page.waitToClick(selectors.ticketService.addServiceButton);
await page.waitForSelector(selectors.ticketService.firstAddServiceTypeButton); await page.waitForSelector(selectors.ticketService.firstAddServiceTypeButton);
const result = await page.isDisabled(selectors.ticketService.firstAddServiceTypeButton); const disabled = await page.isDisabled(selectors.ticketService.firstAddServiceTypeButton);
expect(result).toBe(true); expect(disabled).toBe(true);
}); });
it('should receive an error if you attempt to save a service without access rights', async() => { it('should receive an error if you attempt to save a service without access rights', async() => {

View File

@ -156,7 +156,7 @@ module.exports = Self => {
e.dated, e.dated,
e.ref, e.ref,
e.isBooked, e.isBooked,
e.isInventory, e.isExcludedFromAvailable,
e.notes, e.notes,
e.evaNotes AS observation, e.evaNotes AS observation,
e.isConfirmed, e.isConfirmed,

View File

@ -24,7 +24,7 @@
"isBooked": { "isBooked": {
"type": "boolean" "type": "boolean"
}, },
"isInventory": { "isExcludedFromAvailable": {
"type": "boolean" "type": "boolean"
}, },
"notes": { "notes": {

View File

@ -103,7 +103,7 @@
</vn-check> </vn-check>
<vn-check <vn-check
label="Inventory" label="Inventory"
ng-model="$ctrl.entry.isInventory"> ng-model="$ctrl.entry.isExcludedFromAvailable">
</vn-check> </vn-check>
<vn-check <vn-check
label="Raid" label="Raid"

View File

@ -25,7 +25,7 @@
<vn-icon <vn-icon
vn-tooltip="Is inventory entry" vn-tooltip="Is inventory entry"
icon="icon-inventory" icon="icon-inventory"
ng-if="$ctrl.entry.isInventory"> ng-if="$ctrl.entry.isExcludedFromAvailable">
</vn-icon> </vn-icon>
<vn-icon <vn-icon
vn-tooltip="Is virtual entry" vn-tooltip="Is virtual entry"

View File

@ -25,7 +25,7 @@
ui-sref="entry.card.summary({id: {{::entry.id}}})"> ui-sref="entry.card.summary({id: {{::entry.id}}})">
<vn-td shrink> <vn-td shrink>
<vn-icon <vn-icon
ng-show="entry.isInventory" ng-show="entry.isExcludedFromAvailable"
class="bright" class="bright"
vn-tooltip="Inventory entry" vn-tooltip="Inventory entry"
icon="icon-inventory"> icon="icon-inventory">

View File

@ -91,7 +91,7 @@
</vn-check> </vn-check>
<vn-check <vn-check
label="Inventory" label="Inventory"
ng-model="$ctrl.entryData.isInventory" ng-model="$ctrl.entryData.isExcludedFromAvailable"
disabled="true"> disabled="true">
</vn-check> </vn-check>
</vn-vertical> </vn-vertical>

View File

@ -1,7 +1,6 @@
import './index.js'; import './index.js';
import watcher from 'core/mocks/watcher'; import watcher from 'core/mocks/watcher';
import crudModel from 'core/mocks/crud-model'; import crudModel from 'core/mocks/crud-model';
const UserError = require('vn-loopback/util/user-error');
describe('InvoiceIn', () => { describe('InvoiceIn', () => {
describe('Component tax', () => { describe('Component tax', () => {

View File

@ -61,7 +61,7 @@ module.exports = Self => {
responseType: 'stream', responseType: 'stream',
params: { params: {
authorization: auth.id, authorization: auth.id,
invoiceId: id refFk: invoiceOut.ref
} }
}).then(async response => { }).then(async response => {
const issued = invoiceOut.issued; const issued = invoiceOut.issued;

View File

@ -9,7 +9,7 @@ module.exports = Self => {
accepts: [ accepts: [
{ {
arg: 'id', arg: 'id',
type: 'String', type: 'string',
description: 'The invoice id', description: 'The invoice id',
http: {source: 'path'} http: {source: 'path'}
} }
@ -21,16 +21,16 @@ module.exports = Self => {
root: true root: true
}, { }, {
arg: 'Content-Type', arg: 'Content-Type',
type: 'String', type: 'string',
http: {target: 'header'} http: {target: 'header'}
}, { }, {
arg: 'Content-Disposition', arg: 'Content-Disposition',
type: 'String', type: 'string',
http: {target: 'header'} http: {target: 'header'}
} }
], ],
http: { http: {
path: `/:id/download`, path: '/:id/download',
verb: 'GET' verb: 'GET'
} }
}); });

View File

@ -0,0 +1,49 @@
module.exports = Self => {
Self.remoteMethod('refund', {
description: 'Create refund tickets with sales and services if provided',
accessType: 'WRITE',
accepts: [{
arg: 'ref',
type: 'string',
description: 'The invoice reference'
}],
returns: {
type: ['number'],
root: true
},
http: {
path: '/refund',
verb: 'post'
}
});
Self.refund = async(ref, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const filter = {where: {refFk: ref}};
const tickets = await models.Ticket.find(filter, myOptions);
const ticketsIds = tickets.map(ticket => ticket.id);
const refundedTickets = await models.Ticket.refund(ticketsIds, myOptions);
if (tx) await tx.commit();
return refundedTickets;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -0,0 +1,28 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('InvoiceOut refund()', () => {
const userId = 5;
const activeCtx = {
accessToken: {userId: userId},
};
it('should return the ids for the created refund tickets', async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try {
const result = await models.InvoiceOut.refund('T1111111', options);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -8,4 +8,5 @@ module.exports = Self => {
require('../methods/invoiceOut/createPdf')(Self); require('../methods/invoiceOut/createPdf')(Self);
require('../methods/invoiceOut/createManualInvoice')(Self); require('../methods/invoiceOut/createManualInvoice')(Self);
require('../methods/invoiceOut/globalInvoicing')(Self); require('../methods/invoiceOut/globalInvoicing')(Self);
require('../methods/invoiceOut/refund')(Self);
}; };

View File

@ -80,6 +80,8 @@
ng-click="refundConfirmation.show()" ng-click="refundConfirmation.show()"
name="refundInvoice" name="refundInvoice"
vn-tooltip="Create a single ticket with all the content of the current invoice" vn-tooltip="Create a single ticket with all the content of the current invoice"
vn-acl="invoicing, claimManager, salesAssistant"
vn-acl-action="remove"
translate> translate>
Refund Refund
</vn-item> </vn-item>

View File

@ -84,7 +84,7 @@ class Controller extends Section {
showCsvInvoice() { showCsvInvoice() {
this.vnReport.showCsv('invoice', { this.vnReport.showCsv('invoice', {
recipientId: this.invoiceOut.client.id, recipientId: this.invoiceOut.client.id,
invoiceId: this.id refFk: this.invoiceOut.ref
}); });
} }
@ -95,7 +95,7 @@ class Controller extends Section {
return this.vnEmail.send('invoice', { return this.vnEmail.send('invoice', {
recipientId: this.invoiceOut.client.id, recipientId: this.invoiceOut.client.id,
recipient: $data.email, recipient: $data.email,
invoiceId: this.id refFk: this.invoiceOut.ref
}); });
} }
@ -106,43 +106,23 @@ class Controller extends Section {
return this.vnEmail.sendCsv('invoice', { return this.vnEmail.sendCsv('invoice', {
recipientId: this.invoiceOut.client.id, recipientId: this.invoiceOut.client.id,
recipient: $data.email, recipient: $data.email,
invoiceId: this.id refFk: this.invoiceOut.ref
}); });
} }
showExportationLetter() { showExportationLetter() {
this.vnReport.show('exportation', { this.vnReport.show('exportation', {
recipientId: this.invoiceOut.client.id, recipientId: this.invoiceOut.client.id,
invoiceId: this.id refFk: this.invoiceOut.ref
}); });
} }
async refundInvoiceOut() { refundInvoiceOut() {
let filter = { const query = 'InvoiceOuts/refund';
where: {refFk: this.invoiceOut.ref} const params = {ref: this.invoiceOut.ref};
}; this.$http.post(query, params).then(res => {
const tickets = await this.$http.get('Tickets', {filter}); const ticketIds = res.data.map(ticket => ticket.id).join(', ');
this.tickets = tickets.data; this.vnApp.showSuccess(this.$t('The following refund tickets have been created', {ticketIds}));
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});
}); });
} }
} }

View File

@ -6,7 +6,8 @@ describe('vnInvoiceOutDescriptorMenu', () => {
let $httpParamSerializer; let $httpParamSerializer;
const invoiceOut = { const invoiceOut = {
id: 1, id: 1,
client: {id: 1101} client: {id: 1101},
ref: 'T1111111'
}; };
beforeEach(ngModule('invoiceOut')); beforeEach(ngModule('invoiceOut'));
@ -15,14 +16,17 @@ describe('vnInvoiceOutDescriptorMenu', () => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_; $httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnInvoiceOutDescriptorMenu', {$element: null}); controller = $componentController('vnInvoiceOutDescriptorMenu', {$element: null});
controller.invoiceOut = {
id: 1,
ref: 'T1111111',
client: {id: 1101}
};
})); }));
describe('createPdfInvoice()', () => { describe('createPdfInvoice()', () => {
it('should make a query to the createPdf() endpoint and show a success snackbar', () => { it('should make a query to the createPdf() endpoint and show a success snackbar', () => {
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');
controller.invoiceOut = invoiceOut;
$httpBackend.whenGET(`InvoiceOuts/${invoiceOut.id}`).respond(); $httpBackend.whenGET(`InvoiceOuts/${invoiceOut.id}`).respond();
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/createPdf`).respond(); $httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/createPdf`).respond();
controller.createPdfInvoice(); controller.createPdfInvoice();
@ -36,11 +40,9 @@ describe('vnInvoiceOutDescriptorMenu', () => {
it('should make a query to the csv invoice download endpoint and show a message snackbar', () => { it('should make a query to the csv invoice download endpoint and show a message snackbar', () => {
jest.spyOn(window, 'open').mockReturnThis(); jest.spyOn(window, 'open').mockReturnThis();
controller.invoiceOut = invoiceOut;
const expectedParams = { const expectedParams = {
invoiceId: invoiceOut.id, recipientId: invoiceOut.client.id,
recipientId: invoiceOut.client.id refFk: invoiceOut.ref
}; };
const serializedParams = $httpParamSerializer(expectedParams); const serializedParams = $httpParamSerializer(expectedParams);
const expectedPath = `api/csv/invoice/download?${serializedParams}`; const expectedPath = `api/csv/invoice/download?${serializedParams}`;
@ -52,7 +54,6 @@ describe('vnInvoiceOutDescriptorMenu', () => {
describe('deleteInvoiceOut()', () => { describe('deleteInvoiceOut()', () => {
it(`should make a query and call showSuccess()`, () => { it(`should make a query and call showSuccess()`, () => {
controller.invoiceOut = invoiceOut;
controller.$state.reload = jest.fn(); controller.$state.reload = jest.fn();
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');
@ -65,7 +66,6 @@ describe('vnInvoiceOutDescriptorMenu', () => {
}); });
it(`should make a query and call showSuccess() after state.go if the state wasn't in invoiceOut module`, () => { it(`should make a query and call showSuccess() after state.go if the state wasn't in invoiceOut module`, () => {
controller.invoiceOut = invoiceOut;
jest.spyOn(controller.$state, 'go').mockReturnValue('ok'); jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');
controller.$state.current.name = 'invoiceOut.card.something'; controller.$state.current.name = 'invoiceOut.card.something';
@ -83,13 +83,11 @@ describe('vnInvoiceOutDescriptorMenu', () => {
it('should make a query to the email invoice endpoint and show a message snackbar', () => { it('should make a query to the email invoice endpoint and show a message snackbar', () => {
jest.spyOn(controller.vnApp, 'showMessage'); jest.spyOn(controller.vnApp, 'showMessage');
controller.invoiceOut = invoiceOut;
const $data = {email: 'brucebanner@gothamcity.com'}; const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = { const expectedParams = {
invoiceId: invoiceOut.id,
recipient: $data.email, recipient: $data.email,
recipientId: invoiceOut.client.id recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
}; };
const serializedParams = $httpParamSerializer(expectedParams); const serializedParams = $httpParamSerializer(expectedParams);
@ -105,13 +103,11 @@ describe('vnInvoiceOutDescriptorMenu', () => {
it('should make a query to the csv invoice send endpoint and show a message snackbar', () => { it('should make a query to the csv invoice send endpoint and show a message snackbar', () => {
jest.spyOn(controller.vnApp, 'showMessage'); jest.spyOn(controller.vnApp, 'showMessage');
controller.invoiceOut = invoiceOut;
const $data = {email: 'brucebanner@gothamcity.com'}; const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = { const expectedParams = {
invoiceId: invoiceOut.id,
recipient: $data.email, recipient: $data.email,
recipientId: invoiceOut.client.id recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
}; };
const serializedParams = $httpParamSerializer(expectedParams); const serializedParams = $httpParamSerializer(expectedParams);
@ -123,33 +119,16 @@ describe('vnInvoiceOutDescriptorMenu', () => {
}); });
}); });
// #4084 review with Juan describe('refundInvoiceOut()', () => {
xdescribe('refundInvoiceOut()', () => { it('should make a query and show a success message', () => {
it('should make a query and go to ticket.card.sale', () => { jest.spyOn(controller.vnApp, 'showSuccess');
controller.$state.go = jest.fn(); const params = {ref: controller.invoiceOut.ref};
const invoiceOut = { $httpBackend.expectPOST(`InvoiceOuts/refund`, params).respond([{id: 1}, {id: 2}]);
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(); controller.refundInvoiceOut();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: undefined}); expect(controller.vnApp.showSuccess).toHaveBeenCalled();
}); });
}); });
}); });

View File

@ -0,0 +1 @@
The following refund tickets have been created: "The following refund tickets have been created: {{ticketIds}}"

View File

@ -17,3 +17,4 @@ Create a single ticket with all the content of the current invoice: Crear un tic
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
The following refund tickets have been created: "Se han creado los siguientes tickets de abono: {{ticketIds}}"

View File

@ -12,7 +12,7 @@ module.exports = Self => {
}, },
http: { http: {
path: `/downloadImages`, path: `/downloadImages`,
verb: 'POST' verb: 'GET'
} }
}); });

View File

@ -1,23 +1,20 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('refund', { Self.remoteMethod('refund', {
description: 'Create ticket refund with lines and services changing the sign to the quantites', description: 'Create refund tickets with sales and services if provided',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [
arg: 'sales', {
description: 'The sales', arg: 'salesIds',
type: ['object'], type: ['number'],
required: false required: true
}, },
{ {
arg: 'services', arg: 'servicesIds',
type: ['object'], type: ['number']
required: false, },
description: 'The services' ],
}],
returns: { returns: {
type: 'number', type: ['number'],
root: true root: true
}, },
http: { http: {
@ -26,7 +23,8 @@ module.exports = Self => {
} }
}); });
Self.refund = async(ctx, sales, services, options) => { Self.refund = async(salesIds, servicesIds, options) => {
const models = Self.app.models;
const myOptions = {}; const myOptions = {};
let tx; let tx;
@ -39,56 +37,103 @@ module.exports = Self => {
} }
try { try {
const userId = ctx.req.accessToken.userId; const refundAgencyMode = await models.AgencyMode.findOne({
include: {
relation: 'zones',
scope: {
limit: 1,
field: ['id', 'name']
}
},
where: {code: 'refund'}
}, myOptions);
const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager'); const refoundZoneId = refundAgencyMode.zones()[0].id;
const isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant');
const hasValidRole = isClaimManager || isSalesAssistant;
if (!hasValidRole) const salesFilter = {
throw new UserError(`You don't have privileges to create refund`); where: {id: {inq: salesIds}},
include: {
relation: 'components',
scope: {
fields: ['saleFk', 'componentFk', 'value']
}
}
};
const sales = await models.Sale.find(salesFilter, myOptions);
const ticketsIds = [...new Set(sales.map(sale => sale.ticketFk))];
const salesIds = []; const refundTickets = [];
if (sales) {
for (let sale of sales)
salesIds.push(sale.id);
} else
salesIds.push(null);
const servicesIds = []; const now = new Date();
if (services && services.length) { const mappedTickets = new Map();
for (let service of services)
servicesIds.push(service.id);
} else
servicesIds.push(null);
const query = ` for (let ticketId of ticketsIds) {
DROP TEMPORARY TABLE IF EXISTS tmp.sale; const filter = {include: {relation: 'address'}};
DROP TEMPORARY TABLE IF EXISTS tmp.ticketService; const ticket = await models.Ticket.findById(ticketId, filter, myOptions);
CREATE TEMPORARY TABLE tmp.sale const refundTicket = await models.Ticket.create({
SELECT s.id, s.itemFk, s.quantity, s.concept, s.price, s.discount, s.ticketFk clientFk: ticket.clientFk,
FROM sale s shipped: now,
WHERE s.id IN (?); addressFk: ticket.address().id,
agencyModeFk: refundAgencyMode.id,
nickname: ticket.address().nickname,
warehouseFk: ticket.warehouseFk,
companyFk: ticket.companyFk,
landed: now,
zoneFk: refoundZoneId
}, myOptions);
CREATE TEMPORARY TABLE tmp.ticketService refundTickets.push(refundTicket);
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); mappedTickets.set(ticketId, refundTicket.id);
DROP TEMPORARY TABLE tmp.sale; await models.TicketRefund.create({
DROP TEMPORARY TABLE tmp.ticketService;`; refundTicketFk: refundTicket.id,
originalTicketFk: ticket.id,
}, myOptions);
}
await Self.rawSql(query, [salesIds, servicesIds], myOptions); for (const sale of sales) {
const refundTicketId = mappedTickets.get(sale.ticketFk);
const createdSale = await models.Sale.create({
ticketFk: refundTicketId,
itemFk: sale.itemFk,
quantity: sale.quantity,
concept: sale.concept,
price: sale.price,
discount: sale.discount,
}, myOptions);
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions); const components = sale.components();
const newTicketId = newTicket.id; for (const component of components)
component.saleFk = createdSale.id;
await models.SaleComponent.create(components, myOptions);
}
if (servicesIds && servicesIds.length > 0) {
const servicesFilter = {
where: {id: {inq: servicesIds}}
};
const services = await models.TicketService.find(servicesFilter, myOptions);
for (const service of services) {
const refundTicketId = mappedTickets.get(service.ticketFk);
await models.TicketService.create({
description: service.description,
quantity: service.quantity,
price: service.price,
taxClassFk: service.taxClassFk,
ticketFk: refundTicketId,
ticketServiceTypeFk: service.ticketServiceTypeFk,
}, myOptions);
}
}
if (tx) await tx.commit(); if (tx) await tx.commit();
return newTicketId; return refundTickets;
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;

View File

@ -1,23 +1,30 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('sale refund()', () => { describe('sale refund()', () => {
const sales = [ const userId = 5;
{id: 7, ticketFk: 11}, const activeCtx = {
{id: 8, ticketFk: 11} accessToken: {userId: userId},
]; };
const services = [{id: 1}];
it('should create ticket with the selected lines changing the sign to the quantites', async() => { const servicesIds = [3];
beforeEach(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
it('should create ticket with the selected lines', async() => {
const tx = await models.Sale.beginTransaction({}); const tx = await models.Sale.beginTransaction({});
const ctx = {req: {accessToken: {userId: 9}}}; const salesIds = [7, 8];
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const response = await models.Sale.refund(ctx, sales, services, options); const response = await models.Sale.refund(salesIds, servicesIds, options);
const [newTicketId] = await models.Sale.rawSql('SELECT MAX(t.id) id FROM vn.ticket t;', null, options);
expect(response).toEqual(newTicketId.id); expect(response.length).toBeGreaterThanOrEqual(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -26,24 +33,53 @@ describe('sale refund()', () => {
} }
}); });
it(`should throw an error if the user doesn't have privileges to create a refund`, async() => { it('should create a ticket for each unique ticketFk in the sales', async() => {
const tx = await models.Sale.beginTransaction({}); const tx = await models.Sale.beginTransaction({});
const ctx = {req: {accessToken: {userId: 1}}}; const salesIds = [6, 7];
let error;
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
await models.Sale.refund(ctx, sales, services, options); const tickets = await models.Sale.refund(salesIds, servicesIds, options);
const ticketsIds = tickets.map(ticket => ticket.id);
const refundedTickets = await models.Ticket.find({
where: {
id: {
inq: ticketsIds
}
},
include: [
{
relation: 'ticketSales',
scope: {
include: {
relation: 'components'
}
}
},
{
relation: 'ticketServices',
}
]
}, options);
const firstRefoundedTicket = refundedTickets[0];
const secondRefoundedTicket = refundedTickets[1];
const salesLength = firstRefoundedTicket.ticketSales().length;
const componentsLength = firstRefoundedTicket.ticketSales()[0].components().length;
const servicesLength = secondRefoundedTicket.ticketServices().length;
expect(refundedTickets.length).toEqual(2);
expect(salesLength).toEqual(1);
expect(componentsLength).toEqual(4);
expect(servicesLength).toBeGreaterThanOrEqual(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();
error = e; throw e;
} }
expect(error).toBeDefined();
expect(error.message).toEqual(`You don't have privileges to create refund`);
}); });
}); });

View File

@ -0,0 +1,54 @@
module.exports = Self => {
Self.remoteMethod('refund', {
description: 'Create refund tickets with all their sales and services',
accessType: 'WRITE',
accepts: [
{
arg: 'ticketsIds',
type: ['number'],
required: true
},
],
returns: {
type: ['number'],
root: true
},
http: {
path: `/refund`,
verb: 'post'
}
});
Self.refund = async(ticketsIds, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const filter = {where: {ticketFk: {inq: ticketsIds}}};
const sales = await models.Sale.find(filter, myOptions);
const salesIds = sales.map(sale => sale.id);
const services = await models.TicketService.find(filter, myOptions);
const servicesIds = services.map(service => service.id);
const refundedTickets = await models.Sale.refund(salesIds, servicesIds, myOptions);
if (tx) await tx.commit();
return refundedTickets;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -56,6 +56,9 @@
"TicketPackaging": { "TicketPackaging": {
"dataSource": "vn" "dataSource": "vn"
}, },
"TicketRefund": {
"dataSource": "vn"
},
"TicketRequest": { "TicketRequest": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -0,0 +1,40 @@
{
"name": "TicketRefund",
"base": "Loggable",
"options": {
"mysql": {
"table": "ticketRefund"
}
},
"log": {
"model": "TicketLog",
"relation": "originalTicket"
},
"properties": {
"id": {
"id": true,
"type": "number",
"description": "Identifier"
},
"refundTicketFk": {
"type": "number",
"required": true
},
"originalTicketFk": {
"type": "number",
"required": true
}
},
"relations": {
"refundTicket": {
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "refundTicketFk"
},
"originalTicket": {
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "originalTicketFk"
}
}
}

View File

@ -3,17 +3,18 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.observe('before save', async ctx => { Self.observe('before save', async ctx => {
const models = Self.app.models; const models = Self.app.models;
let changes = ctx.currentInstance || ctx.instance; const changes = ctx.currentInstance || ctx.instance;
if (changes) {
let ticketId = changes.ticketFk; if (changes && !ctx.isNewInstance) {
let isLocked = await models.Ticket.isLocked(ticketId); const ticketId = changes.ticketFk;
const isLocked = await models.Ticket.isLocked(ticketId);
if (isLocked) if (isLocked)
throw new UserError(`The current ticket can't be modified`); throw new UserError(`The current ticket can't be modified`);
}
if (changes.ticketServiceTypeFk) { if (changes && changes.ticketServiceTypeFk) {
const ticketServiceType = await models.TicketServiceType.findById(changes.ticketServiceTypeFk); const ticketServiceType = await models.TicketServiceType.findById(changes.ticketServiceTypeFk);
changes.description = ticketServiceType.name; changes.description = ticketServiceType.name;
}
} }
}); });

View File

@ -27,6 +27,7 @@ module.exports = Self => {
require('../methods/ticket/isLocked')(Self); require('../methods/ticket/isLocked')(Self);
require('../methods/ticket/freightCost')(Self); require('../methods/ticket/freightCost')(Self);
require('../methods/ticket/getComponentsSum')(Self); require('../methods/ticket/getComponentsSum')(Self);
require('../methods/ticket/refund')(Self);
Self.observe('before save', async function(ctx) { Self.observe('before save', async function(ctx) {
const loopBackContext = LoopBackContext.getCurrentContext(); const loopBackContext = LoopBackContext.getCurrentContext();

View File

@ -105,6 +105,16 @@
"model": "TicketPackaging", "model": "TicketPackaging",
"foreignKey": "ticketFk" "foreignKey": "ticketFk"
}, },
"ticketSales": {
"type": "hasMany",
"model": "Sale",
"foreignKey": "ticketFk"
},
"ticketServices": {
"type": "hasMany",
"model": "TicketService",
"foreignKey": "ticketFk"
},
"tracking": { "tracking": {
"type": "hasMany", "type": "hasMany",
"model": "TicketTracking", "model": "TicketTracking",

View File

@ -127,6 +127,8 @@
</vn-item> </vn-item>
<vn-item <vn-item
ng-click="refundAllConfirmation.show()" ng-click="refundAllConfirmation.show()"
vn-acl="invoicing, claimManager, salesAssistant"
vn-acl-action="remove"
translate> translate>
Refund all Refund all
</vn-item> </vn-item>

View File

@ -253,22 +253,14 @@ class Controller extends Section {
} }
async refund() { async refund() {
const filter = { const params = {ticketsIds: [this.id]};
where: {ticketFk: this.id} const query = 'Tickets/refund';
};
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 => { return this.$http.post(query, params).then(res => {
this.$state.go('ticket.card.sale', {id: res.data}); const [refundTicket] = res.data;
this.vnApp.showSuccess(this.$t('The following refund ticket have been created', {
ticketId: refundTicket.id
}));
this.$state.go('ticket.card.sale', {id: refundTicket.id});
}); });
} }
} }

View File

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

View File

@ -0,0 +1 @@
The following refund ticket have been created: "The following refund ticket have been created: {{ticketId}}"

View File

@ -8,4 +8,5 @@ Send CSV: Enviar CSV
Send CSV Delivery Note: Enviar albarán en CSV Send CSV Delivery Note: Enviar albarán en CSV
Send PDF Delivery Note: Enviar albarán en PDF Send PDF Delivery Note: Enviar albarán en PDF
Show Proforma: Ver proforma Show Proforma: Ver proforma
Refund all: Abonar todo Refund all: Abonar todo
The following refund ticket have been created: "Se ha creado siguiente ticket de abono: {{ticketId}}"

View File

@ -514,7 +514,7 @@
<vn-item translate <vn-item translate
name="refund" name="refund"
ng-click="$ctrl.createRefund()" ng-click="$ctrl.createRefund()"
vn-acl="claimManager, salesAssistant" vn-acl="invoicing, claimManager, salesAssistant"
vn-acl-action="remove"> vn-acl-action="remove">
Refund Refund
</vn-item> </vn-item>

View File

@ -483,11 +483,18 @@ class Controller extends Section {
const sales = this.selectedValidSales(); const sales = this.selectedValidSales();
if (!sales) return; if (!sales) return;
const params = {sales: sales}; const salesIds = sales.map(sale => sale.id);
const query = `Sales/refund`;
this.resetChanges(); const params = {salesIds: salesIds};
const query = 'Sales/refund';
this.$http.post(query, params).then(res => { this.$http.post(query, params).then(res => {
this.$state.go('ticket.card.sale', {id: res.data}); const [refundTicket] = res.data;
this.vnApp.showSuccess(this.$t('The following refund ticket have been created', {
ticketId: refundTicket.id
}));
this.$state.go('ticket.card.sale', {id: refundTicket.id});
this.resetChanges();
}); });
} }

View File

@ -704,18 +704,19 @@ describe('Ticket', () => {
}); });
describe('createRefund()', () => { describe('createRefund()', () => {
it('should make an HTTP POST query and then call to the $state go() method', () => { it('should make a query and then navigate to the created ticket sales section', () => {
jest.spyOn(controller, 'selectedValidSales').mockReturnValue(controller.sales); jest.spyOn(controller, 'selectedValidSales').mockReturnValue(controller.sales);
jest.spyOn(controller, 'resetChanges');
jest.spyOn(controller.$state, 'go'); jest.spyOn(controller.$state, 'go');
const params = {
const expectedId = 9999; salesIds: [1, 4],
$httpBackend.expect('POST', `Sales/refund`).respond(200, expectedId); };
const refundTicket = {id: 99};
const createdTickets = [refundTicket];
$httpBackend.expect('POST', 'Sales/refund', params).respond(200, createdTickets);
controller.createRefund(); controller.createRefund();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.resetChanges).toHaveBeenCalledWith(); expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', refundTicket);
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: expectedId});
}); });
}); });

View File

@ -44,12 +44,16 @@ module.exports = Self => {
OR (type = 'range' OR (type = 'range'
AND ( AND (
(started BETWEEN ? AND ?) (started BETWEEN ? AND ?)
OR (ended BETWEEN ? AND ?) OR
(ended BETWEEN ? AND ?)
OR
(started <= ? AND ended >= ?)
) )
) )
) )
ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`; ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`;
const events = await Self.rawSql(query, [zoneFk, started, ended, started, ended, started, ended], myOptions); const events = await Self.rawSql(query,
[zoneFk, started, ended, started, ended, started, ended, started, ended], myOptions);
query = ` query = `
SELECT * SELECT *

View File

@ -6,8 +6,9 @@ describe('zone getEventsFiltered()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const today = new Date();
let result = await models.Zone.getEventsFiltered(10, '2021-10-01', '2021-10-02', options); const result = await models.Zone.getEventsFiltered(10, today, today, options);
expect(result.events.length).toEqual(1); expect(result.events.length).toEqual(1);
expect(result.exclusions.length).toEqual(0); expect(result.exclusions.length).toEqual(0);
@ -18,4 +19,46 @@ describe('zone getEventsFiltered()', () => {
throw e; throw e;
} }
}); });
describe('event range type', () => {
it('should return events and exclusions for the zone 9 in a range of dates', async() => {
const tx = await models.Zone.beginTransaction({});
try {
const options = {transaction: tx};
const today = new Date();
const result = await models.Zone.getEventsFiltered(9, today, today, options);
expect(result.events.length).toEqual(1);
expect(result.exclusions.length).toEqual(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should not return events and exclusions for the zone 9 in a range of dates', async() => {
const tx = await models.Zone.beginTransaction({});
try {
const options = {transaction: tx};
const date = new Date();
date.setFullYear(date.getFullYear() - 2);
const dateTomorrow = new Date(date.setDate(date.getDate() + 1));
const result = await models.Zone.getEventsFiltered(9, date, dateTomorrow, options);
expect(result.events.length).toEqual(0);
expect(result.exclusions.length).toEqual(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});
}); });

View File

@ -55,6 +55,11 @@
"type": "belongsTo", "type": "belongsTo",
"model": "DeliveryMethod", "model": "DeliveryMethod",
"foreignKey": "deliveryMethodFk" "foreignKey": "deliveryMethodFk"
},
"zones": {
"type": "hasMany",
"model": "Zone",
"foreignKey": "agencyModeFk"
} }
}, },
"acls": [ "acls": [

View File

@ -1,6 +1,6 @@
{ {
"name": "salix-back", "name": "salix-back",
"version": "6.8.0", "version": "8.6.0",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "Salix backend", "description": "Salix backend",
"license": "GPL-3.0", "license": "GPL-3.0",

View File

@ -31,7 +31,7 @@ module.exports = {
if (invoiceOut) { if (invoiceOut) {
const args = Object.assign({ const args = Object.assign({
invoiceId: invoiceOut.id, refFk: invoiceOut.ref,
recipientId: ticket.clientFk, recipientId: ticket.clientFk,
recipient: ticket.recipient, recipient: ticket.recipient,
replyTo: ticket.salesPersonEmail replyTo: ticket.salesPersonEmail
@ -118,7 +118,7 @@ module.exports = {
await db.rawSql(` await db.rawSql(`
INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?) INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?)
`, [ticket.clientFk, sample.id, ticket.companyFk]) `, [ticket.clientFk, sample.id, ticket.companyFk]);
} }
} catch (error) { } catch (error) {
// Domain not found // Domain not found

View File

@ -7,13 +7,13 @@ const sqlPath = path.join(__dirname, 'sql');
module.exports = async function(request, response, next) { module.exports = async function(request, response, next) {
try { try {
const reqArgs = request.query; const reqArgs = request.query;
if (!reqArgs.invoiceId) if (!reqArgs.refFk)
throw new Error('The argument invoiceId is required'); throw new Error('The argument refFk is required');
const invoiceId = reqArgs.invoiceId; const refFk = reqArgs.refFk;
const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [invoiceId]); const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [refFk]);
const content = toCSV(sales); const content = toCSV(sales);
const fileName = `invoice_${invoiceId}.csv`; const fileName = `invoice_${refFk}.csv`;
response.setHeader('Content-type', 'text/csv'); response.setHeader('Content-type', 'text/csv');
response.setHeader('Content-Disposition', `inline; filename="${fileName}"`); response.setHeader('Content-Disposition', `inline; filename="${fileName}"`);

View File

@ -8,22 +8,22 @@ const sqlPath = path.join(__dirname, 'sql');
module.exports = async function(request, response, next) { module.exports = async function(request, response, next) {
try { try {
const reqArgs = request.query; const reqArgs = request.query;
if (!reqArgs.invoiceId) if (!reqArgs.refFk)
throw new Error('The argument invoiceId is required'); throw new Error('The argument refFk is required');
const invoiceId = reqArgs.invoiceId; const refFk = reqArgs.refFk;
const invoice = await db.findOneFromDef(`${sqlPath}/invoice`, [invoiceId]); const invoice = await db.findOneFromDef(`${sqlPath}/invoice`, [refFk]);
const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [invoiceId]); const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [refFk]);
const args = Object.assign({ const args = Object.assign({
invoiceId: (String(invoice.id)), refFk: invoice.refFk,
recipientId: invoice.clientFk, recipientId: invoice.clientFk,
recipient: invoice.recipient, recipient: invoice.recipient,
replyTo: invoice.salesPersonEmail replyTo: invoice.salesPersonEmail
}, response.locals); }, response.locals);
const content = toCSV(sales); const content = toCSV(sales);
const fileName = `invoice_${invoiceId}.csv`; const fileName = `invoice_${refFk}.csv`;
const email = new Email('invoice', args); const email = new Email('invoice', args);
await email.send({ await email.send({
overrideAttachments: true, overrideAttachments: true,

View File

@ -6,4 +6,5 @@ SELECT
FROM invoiceOut io FROM invoiceOut io
JOIN client c ON c.id = io.clientFk JOIN client c ON c.id = io.clientFk
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -31,5 +31,5 @@ FROM sale s
AND itc.countryFk = s2.countryFk AND itc.countryFk = s2.countryFk
JOIN taxClass tc ON tc.id = itc.taxClassFk JOIN taxClass tc ON tc.id = itc.taxClassFk
JOIN invoiceOut io ON io.ref = t.refFk JOIN invoiceOut io ON io.ref = t.refFk
WHERE io.id = ? WHERE t.refFk = ?
ORDER BY s.ticketFk, s.created ORDER BY s.ticketFk, s.created

View File

@ -38,7 +38,7 @@ module.exports = async function(request, response, next) {
connection.query('START TRANSACTION'); connection.query('START TRANSACTION');
const args = Object.assign({ const args = Object.assign({
invoiceId: invoiceOut.id, refFk: invoiceOut.ref,
recipientId: invoiceOut.clientFk, recipientId: invoiceOut.clientFk,
recipient: invoiceOut.recipient, recipient: invoiceOut.recipient,
replyTo: invoiceOut.salesPersonEmail replyTo: invoiceOut.salesPersonEmail

View File

@ -5,11 +5,11 @@ const emailFooter = new Component('email-footer');
module.exports = { module.exports = {
name: 'invoice', name: 'invoice',
async serverPrefetch() { async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId); this.invoice = await this.fetchInvoice(this.refFk);
}, },
methods: { methods: {
fetchInvoice(invoiceId) { fetchInvoice(refFk) {
return this.findOneFromDef('invoice', [invoiceId]); return this.findOneFromDef('invoice', [refFk]);
}, },
}, },
components: { components: {
@ -17,7 +17,7 @@ module.exports = {
'email-footer': emailFooter.build() 'email-footer': emailFooter.build()
}, },
props: { props: {
invoiceId: { refFk: {
type: [Number, String], type: [Number, String],
required: true required: true
} }

View File

@ -4,4 +4,4 @@ SELECT
FROM invoiceOut io FROM invoiceOut io
JOIN ticket t ON t.refFk = io.ref JOIN ticket t ON t.refFk = io.ref
JOIN client c ON c.id = io.clientFk JOIN client c ON c.id = io.clientFk
WHERE io.id = ? WHERE t.refFk = ?

View File

@ -5,14 +5,14 @@ const reportFooter = new Component('report-footer');
module.exports = { module.exports = {
name: 'exportation', name: 'exportation',
async serverPrefetch() { async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId); this.invoice = await this.fetchInvoice(this.refFk);
if (!this.invoice) if (!this.invoice)
throw new Error('Something went wrong'); throw new Error('Something went wrong');
}, },
methods: { methods: {
fetchInvoice(invoiceId) { fetchInvoice(refFk) {
return this.findOneFromDef('invoice', [invoiceId]); return this.findOneFromDef('invoice', [refFk]);
} }
}, },
computed: { computed: {
@ -27,7 +27,7 @@ module.exports = {
'report-footer': reportFooter.build() 'report-footer': reportFooter.build()
}, },
props: { props: {
invoiceId: { refFk: {
type: [Number, String], type: [Number, String],
required: true required: true
} }

View File

@ -3,4 +3,5 @@ SELECT
io.ref, io.ref,
io.issued io.issued
FROM invoiceOut io FROM invoiceOut io
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -5,9 +5,9 @@ const reportFooter = new Component('report-footer');
module.exports = { module.exports = {
name: 'invoice-incoterms', name: 'invoice-incoterms',
async serverPrefetch() { async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId); this.invoice = await this.fetchInvoice(this.refFk);
this.client = await this.fetchClient(this.invoiceId); this.client = await this.fetchClient(this.refFk);
this.incoterms = await this.fetchIncoterms(this.invoiceId); this.incoterms = await this.fetchIncoterms(this.refFk);
if (!this.invoice) if (!this.invoice)
throw new Error('Something went wrong'); throw new Error('Something went wrong');
@ -16,14 +16,14 @@ module.exports = {
}, },
methods: { methods: {
fetchInvoice(invoiceId) { fetchInvoice(refFk) {
return this.findOneFromDef('invoice', [invoiceId]); return this.findOneFromDef('invoice', [refFk]);
}, },
fetchClient(invoiceId) { fetchClient(refFk) {
return this.findOneFromDef('client', [invoiceId]); return this.findOneFromDef('client', [refFk]);
}, },
fetchIncoterms(invoiceId) { fetchIncoterms(refFk) {
return this.findOneFromDef('incoterms', [invoiceId, invoiceId, invoiceId]); return this.findOneFromDef('incoterms', [refFk, refFk, refFk]);
} }
}, },
components: { components: {
@ -31,7 +31,7 @@ module.exports = {
'report-footer': reportFooter.build() 'report-footer': reportFooter.build()
}, },
props: { props: {
invoiceId: { refFk: {
type: [Number, String], type: [Number, String],
required: true required: true
} }

View File

@ -9,4 +9,5 @@ FROM vn.invoiceOut io
JOIN vn.country cty ON cty.id = c.countryFk JOIN vn.country cty ON cty.id = c.countryFk
LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial
AND ios.taxAreaFk = 'CEE' AND ios.taxAreaFk = 'CEE'
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -51,7 +51,7 @@ SELECT io.issued,
FROM vn.invoiceOut io FROM vn.invoiceOut io
JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.ticket t ON t.refFk = io.ref
JOIN vn.saleVolume sv ON sv.ticketFk = t.id JOIN vn.saleVolume sv ON sv.ticketFk = t.id
WHERE io.id = ? WHERE t.refFk = ?
) sub2 ON TRUE ) sub2 ON TRUE
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk AND itc.itemFk = s.itemFk JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk AND itc.itemFk = s.itemFk
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
@ -66,6 +66,7 @@ SELECT io.issued,
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
WHERE io.id = ? WHERE t.refFk = ?
)sub3 ON TRUE )sub3 ON TRUE
WHERE io.id = ? WHERE t.refFk = ?

View File

@ -14,4 +14,5 @@ FROM invoiceOut io
JOIN company cny ON cny.id = io.companyFk JOIN company cny ON cny.id = io.companyFk
JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk
LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -7,15 +7,15 @@ const invoiceIncoterms = new Report('invoice-incoterms');
module.exports = { module.exports = {
name: 'invoice', name: 'invoice',
async serverPrefetch() { async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId); this.invoice = await this.fetchInvoice(this.refFk);
this.client = await this.fetchClient(this.invoiceId); this.client = await this.fetchClient(this.refFk);
this.taxes = await this.fetchTaxes(this.invoiceId); this.taxes = await this.fetchTaxes(this.refFk);
this.intrastat = await this.fetchIntrastat(this.invoiceId); this.intrastat = await this.fetchIntrastat(this.refFk);
this.rectified = await this.fetchRectified(this.invoiceId); this.rectified = await this.fetchRectified(this.refFk);
this.hasIncoterms = await this.fetchHasIncoterms(this.invoiceId); this.hasIncoterms = await this.fetchHasIncoterms(this.refFk);
const tickets = await this.fetchTickets(this.invoiceId); const tickets = await this.fetchTickets(this.refFk);
const sales = await this.fetchSales(this.invoiceId); const sales = await this.fetchSales(this.refFk);
const map = new Map(); const map = new Map();
@ -65,29 +65,29 @@ module.exports = {
} }
}, },
methods: { methods: {
fetchInvoice(invoiceId) { fetchInvoice(refFk) {
return this.findOneFromDef('invoice', [invoiceId]); return this.findOneFromDef('invoice', [refFk]);
}, },
fetchClient(invoiceId) { fetchClient(refFk) {
return this.findOneFromDef('client', [invoiceId]); return this.findOneFromDef('client', [refFk]);
}, },
fetchTickets(invoiceId) { fetchTickets(refFk) {
return this.rawSqlFromDef('tickets', [invoiceId]); return this.rawSqlFromDef('tickets', [refFk]);
}, },
fetchSales(invoiceId) { fetchSales(refFk) {
return this.rawSqlFromDef('sales', [invoiceId, invoiceId]); return this.rawSqlFromDef('sales', [refFk, refFk]);
}, },
fetchTaxes(invoiceId) { fetchTaxes(refFk) {
return this.rawSqlFromDef(`taxes`, [invoiceId]); return this.rawSqlFromDef(`taxes`, [refFk]);
}, },
fetchIntrastat(invoiceId) { fetchIntrastat(refFk) {
return this.rawSqlFromDef(`intrastat`, [invoiceId]); return this.rawSqlFromDef(`intrastat`, [refFk, refFk, refFk]);
}, },
fetchRectified(invoiceId) { fetchRectified(refFk) {
return this.rawSqlFromDef(`rectified`, [invoiceId]); return this.rawSqlFromDef(`rectified`, [refFk]);
}, },
fetchHasIncoterms(invoiceId) { fetchHasIncoterms(refFk) {
return this.findValueFromDef(`hasIncoterms`, [invoiceId]); return this.findValueFromDef(`hasIncoterms`, [refFk]);
}, },
saleImport(sale) { saleImport(sale) {
const price = sale.quantity * sale.price; const price = sale.quantity * sale.price;
@ -115,9 +115,8 @@ module.exports = {
'invoice-incoterms': invoiceIncoterms.build() 'invoice-incoterms': invoiceIncoterms.build()
}, },
props: { props: {
invoiceId: { refFk: {
type: [Number, String], type: String
required: true
} }
} }
}; };

View File

@ -9,4 +9,5 @@ FROM vn.invoiceOut io
JOIN vn.country cty ON cty.id = c.countryFk JOIN vn.country cty ON cty.id = c.countryFk
LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial
AND ios.taxAreaFk = 'CEE' AND ios.taxAreaFk = 'CEE'
WHERE io.id = ? LEFT JOIN vn.ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -3,6 +3,6 @@ SELECT IF(incotermsFk IS NULL, FALSE, TRUE) AS hasIncoterms
JOIN invoiceOut io ON io.ref = t.refFk JOIN invoiceOut io ON io.ref = t.refFk
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN address a ON a.id = t.addressFk JOIN address a ON a.id = t.addressFk
WHERE io.id = ? WHERE t.refFk = ?
AND IF(c.hasToinvoiceByAddress = FALSE, c.defaultAddressFk, TRUE) AND IF(c.hasToinvoiceByAddress = FALSE, c.defaultAddressFk, TRUE)
LIMIT 1 LIMIT 1

View File

@ -1,18 +1,22 @@
SELECT SELECT
ir.id AS code, ir.id code,
ir.description AS description, ir.description description,
CAST(SUM(IFNULL(i.stems,1) * s.quantity) AS DECIMAL(10,2)) as stems, CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL(10,2)) stems,
CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) netKg, CAST(SUM(CAST(IFNULL(i.stems, 1) * s.quantity * IF(ic.grams, ic.grams, i.density * ic.cm3delivery / 1000) / 1000 AS DECIMAL(10,2)) *
CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) AS subtotal IF(sub.weight, sub.weight / vn.invoiceOut_getWeight(?), 1)) AS DECIMAL(10,2)) netKg,
FROM vn.sale s CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) subtotal
LEFT JOIN (SELECT ic.itemFk, ic.cm3, ic.cm3delivery FROM vn.ticket t
FROM vn.itemCost ic JOIN vn.sale s ON s.ticketFk = t.id
WHERE ic.cm3 JOIN vn.item i ON i.id = s.itemFk
GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk
LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id JOIN vn.intrastat ir ON ir.id = i.intrastatFk
LEFT JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN (
LEFT JOIN vn.invoiceOut io ON io.ref = t.refFk SELECT t2.weight
LEFT JOIN vn.item i ON i.id = s.itemFk FROM vn.ticket t2
JOIN vn.intrastat ir ON ir.id = i.intrastatFk WHERE refFk = ? AND weight
WHERE io.id = ? LIMIT 1
GROUP BY i.intrastatFk; ) sub ON TRUE
WHERE t.refFk = ?
AND i.intrastatFk
GROUP BY i.intrastatFk
ORDER BY i.intrastatFk;

View File

@ -13,4 +13,5 @@ FROM invoiceOut io
JOIN company cny ON cny.id = io.companyFk JOIN company cny ON cny.id = io.companyFk
JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk
LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -6,4 +6,5 @@ SELECT
FROM vn.invoiceCorrection ic FROM vn.invoiceCorrection ic
JOIN vn.invoiceOut io ON io.id = ic.correctedFk JOIN vn.invoiceOut io ON io.id = ic.correctedFk
JOIN vn.invoiceCorrectionType ict ON ict.id = ic.invoiceCorrectionTypeFk JOIN vn.invoiceCorrectionType ict ON ict.id = ic.invoiceCorrectionTypeFk
where ic.correctingFk = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -37,7 +37,7 @@ SELECT
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk
AND itc.itemFk = s.itemFk AND itc.itemFk = s.itemFk
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
WHERE io.id = ? WHERE t.refFk = ?
UNION ALL UNION ALL
SELECT SELECT
io.ref, io.ref,
@ -69,4 +69,4 @@ SELECT
JOIN vn.company co ON co.id = io.companyFk JOIN vn.company co ON co.id = io.companyFk
JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk
JOIN vn.taxClass tc ON tc.id = ts.taxClassFk JOIN vn.taxClass tc ON tc.id = ts.taxClassFk
WHERE io.id = ? WHERE t.refFk = ?

View File

@ -6,6 +6,7 @@ SELECT
FROM invoiceOutTax iot FROM invoiceOutTax iot
JOIN pgc ON pgc.code = iot.pgcFk JOIN pgc ON pgc.code = iot.pgcFk
LEFT JOIN pgcEqu pe ON pe.equFk = pgc.code LEFT JOIN pgcEqu pe ON pe.equFk = pgc.code
JOIN invoiceOut io ON io.id = iot.invoiceOutFk JOIN invoiceOut io ON io.id = iot.invoiceOutFk
WHERE invoiceOutFk = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?
ORDER BY iot.id ORDER BY iot.id

View File

@ -4,5 +4,5 @@ SELECT
t.nickname t.nickname
FROM invoiceOut io FROM invoiceOut io
JOIN ticket t ON t.refFk = io.ref JOIN ticket t ON t.refFk = io.ref
WHERE io.id = ? WHERE t.refFk = ?
ORDER BY t.shipped ORDER BY t.shipped