Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6321_negative_tickets
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-05-13 13:25:52 +02:00
commit cfea648103
33 changed files with 299 additions and 232 deletions

24
db/dbWatcher.js Normal file
View File

@ -0,0 +1,24 @@
const fs = require('fs');
const {spawn} = require('child_process');
function watchDatabaseChanges() {
console.log('Watching for changes in db/routines and db/versions');
fs.watch('db', {recursive: true}, (eventType, filename) => {
if (filename.endsWith('.sql')) {
let command;
if (filename.startsWith('routines')) command = 'push';
else if (filename.startsWith('versions')) command = 'run';
if (command) {
const process = spawn('myt', [command]);
process.stdout.on('data', data => console.log(data.toString()));
process.stderr.on('data', data => console.error(`stderr: ${data}`));
process.on('error', error => console.error(`error: ${error.message}`));
process.on('close', () => console.log('Watching for changes in db/routines and db/versions'));
}
}
});
}
if (require.main === module) watchDatabaseChanges();
module.exports = watchDatabaseChanges;

View File

@ -2562,7 +2562,7 @@ REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issu
(9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 0, 442, 1), (9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 0, 442, 1),
(10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 0, 442, 1); (10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 0, 442, 1);
INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageWithholdingFk`, `daysAgo`) INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageFarmerWithholdingFk`, `daysAgo`)
VALUES VALUES
(1, -2, '2% retention', 2, 45); (1, -2, '2% retention', 2, 45);

View File

@ -53,7 +53,7 @@ BEGIN
IFNULL(c.street, ''), IFNULL(c.street, ''),
c.accountingAccount, c.accountingAccount,
@fi := IF(cu.code = LEFT(TRIM(c.fi), 2) AND c.isVies, MID(TRIM(c.fi), 3, LENGTH(TRIM(c.fi))-1), TRIM(c.fi)), @fi := IF(cu.code = LEFT(TRIM(c.fi), 2) AND c.isVies, MID(TRIM(c.fi), 3, LENGTH(TRIM(c.fi))-1), TRIM(c.fi)),
IF(c.isVies, CONCAT(cu.code, @fi ), TRIM(c.fi)), IF(c.isVies, CONCAT(IFNULL(cu.viesCode,cu.code), @fi ), TRIM(c.fi)),
IFNULL(c.postcode, ''), IFNULL(c.postcode, ''),
IFNULL(c.city, ''), IFNULL(c.city, ''),
IFNULL(pr.CodigoProvincia, ''), IFNULL(pr.CodigoProvincia, ''),
@ -91,7 +91,7 @@ BEGIN
IFNULL(s.street, ''), IFNULL(s.street, ''),
s.account, s.account,
@nif := IF(co.code = LEFT(TRIM(s.nif), 2), MID(TRIM(s.nif), 3, LENGTH(TRIM(s.nif))-1), TRIM(s.nif)), @nif := IF(co.code = LEFT(TRIM(s.nif), 2), MID(TRIM(s.nif), 3, LENGTH(TRIM(s.nif))-1), TRIM(s.nif)),
IF(s.isVies, CONCAT(co.code, @nif), TRIM(s.nif)), IF(s.isVies, CONCAT(IFNULL(co.viesCode,co.code), @nif), TRIM(s.nif)),
IFNULL(s.postCode,''), IFNULL(s.postCode,''),
IFNULL(s.city, ''), IFNULL(s.city, ''),
IFNULL(pr.CodigoProvincia, ''), IFNULL(pr.CodigoProvincia, ''),

View File

@ -1,10 +1,11 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balance_create`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balance_create`(
IN vStartingMonth INT, vStartingMonth INT,
IN vEndingMonth INT, vEndingMonth INT,
IN vCompany INT, vCompany INT,
IN vIsConsolidated BOOLEAN, vIsConsolidated BOOLEAN,
IN vInterGroupSalesIncluded BOOLEAN) vInterGroupSalesIncluded BOOLEAN
)
BEGIN BEGIN
/** /**
* Crea un balance financiero para una empresa durante * Crea un balance financiero para una empresa durante

View File

@ -1,5 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPricesByBuy`(IN vBuyFk INT(11)) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPricesByBuy`(
vBuyFk INT(11)
)
BEGIN BEGIN
/** /**
* Recalcula los precios de una compra * Recalcula los precios de una compra

View File

@ -1,5 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPricesByEntry`(IN vEntryFk INT(11)) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPricesByEntry`(
vEntryFk INT(11)
)
BEGIN BEGIN
/** /**
* Recalcula los precios de una entrada * Recalcula los precios de una entrada

View File

@ -192,7 +192,8 @@ BEGIN
AND cr.companyFk = vp.companyFk AND cr.companyFk = vp.companyFk
LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id
LEFT JOIN bankEntity be ON be.id = sa.bankEntityFk LEFT JOIN bankEntity be ON be.id = sa.bankEntityFk
LEFT JOIN country co ON co.id = be.countryFk; LEFT JOIN country co ON co.id = be.countryFk
GROUP BY vp.id;
DROP TEMPORARY TABLE tOpeningBalances; DROP TEMPORARY TABLE tOpeningBalances;
DROP TEMPORARY TABLE tPendingDuedates; DROP TEMPORARY TABLE tPendingDuedates;

View File

@ -1,56 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemTrash`(
vItemFk INT,
vWarehouseFk INT,
vQuantity INT,
vIsTrash BOOLEAN)
BEGIN
DECLARE vTicketFk INT;
DECLARE vClientFk INT;
DECLARE vCompanyVnlFk INT DEFAULT 442;
DECLARE vCalc INT;
SELECT barcodeToItem(vItemFk) INTO vItemFk;
SELECT IF(vIsTrash, 200, 400) INTO vClientFk;
SELECT t.id INTO vTicketFk
FROM ticket t
JOIN address a ON a.id=t.addressFk
WHERE t.warehouseFk = vWarehouseFk
AND t.clientFk = vClientFk
AND DATE(t.shipped) = util.VN_CURDATE()
AND a.isDefaultAddress
LIMIT 1;
CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
IF vTicketFk IS NULL THEN
CALL ticket_add(
vClientFk,
util.VN_CURDATE(),
vWarehouseFk,
vCompanyVnlFk,
NULL,
NULL,
NULL,
util.VN_CURDATE(),
account.myUser_getId(),
FALSE,
vTicketFk);
END IF;
INSERT INTO sale(ticketFk, itemFk, concept, quantity)
SELECT vTicketFk,
vItemFk,
CONCAT(longName,' ',worker_getCode(), ' ', LEFT(CAST(util.VN_NOW() AS TIME),5)),
vQuantity
FROM item
WHERE id = vItemFk;
UPDATE cache.visible
SET visible = visible - vQuantity
WHERE calc_id = vCalc
AND item_id = vItemFk;
END$$
DELIMITER ;

View File

@ -9,7 +9,7 @@ BEGIN
* @vItemFk item a buscar * @vItemFk item a buscar
* @vWarehouseFk almacen donde buscar * @vWarehouseFk almacen donde buscar
* @vDate Si la fecha es null, muestra el histórico desde el inventario. * @vDate Si la fecha es null, muestra el histórico desde el inventario.
* Si la fecha no es null, muestra histórico desde la fecha pasada. * Si la fecha no es null, muestra histórico desde la fecha de vDate.
*/ */
DECLARE vDateInventory DATETIME; DECLARE vDateInventory DATETIME;
@ -41,6 +41,7 @@ BEGIN
); );
INSERT INTO tItemDiary INSERT INTO tItemDiary
WITH entriesIn AS (
SELECT tr.landed shipped, SELECT tr.landed shipped,
b.quantity `in`, b.quantity `in`,
NULL `out`, NULL `out`,
@ -57,89 +58,125 @@ BEGIN
NULL clientType, NULL clientType,
NULL claimFk, NULL claimFk,
ec.inventorySupplierFk ec.inventorySupplierFk
FROM buy b FROM vn.buy b
JOIN entry e ON e.id = b.entryFk JOIN vn.entry e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk JOIN vn.travel tr ON tr.id = e.travelFk
JOIN supplier s ON s.id = e.supplierFk JOIN vn.supplier s ON s.id = e.supplierFk
JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() JOIN vn.state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
OR (util.VN_CURDATE() AND tr.isReceived), OR (util.VN_CURDATE() AND tr.isReceived),
'DELIVERED', 'DELIVERED',
'FREE') 'FREE')
JOIN entryConfig ec JOIN vn.entryConfig ec
WHERE tr.landed >= vDateInventory WHERE tr.landed >= vDateInventory
AND vWarehouseFk = tr.warehouseInFk AND vWarehouseFk = tr.warehouseInFk
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
AND b.itemFk = vItemFk AND b.itemFk = vItemFk
AND e.isExcludedFromAvailable = FALSE AND NOT e.isExcludedFromAvailable
AND e.isRaid = FALSE AND NOT e.isRaid
UNION ALL ), entriesOut AS (
SELECT tr.shipped, SELECT tr.shipped,
NULL, NULL,
b.quantity, b.quantity,
st.alertLevel, st.alertLevel,
st.name, st.name stateName,
s.name, s.name ,
e.invoiceNumber, e.invoiceNumber,
e.id, e.id entryFk,
s.id, s.id supplierFk,
IF(st.`code` = 'DELIVERED' , TRUE, FALSE), IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
FALSE, FALSE isTicket,
b.id, b.id,
NULL, NULL `order`,
NULL, NULL clientType,
NULL, NULL claimFk,
ec.inventorySupplierFk ec.inventorySupplierFk
FROM buy b FROM vn.buy b
JOIN entry e ON e.id = b.entryFk JOIN vn.entry e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk JOIN vn.travel tr ON tr.id = e.travelFk
JOIN warehouse w ON w.id = tr.warehouseOutFk JOIN vn.warehouse w ON w.id = tr.warehouseOutFk
JOIN supplier s ON s.id = e.supplierFk JOIN vn.supplier s ON s.id = e.supplierFk
JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE() JOIN vn.state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE()
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived), OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
'DELIVERED', 'DELIVERED',
'FREE') 'FREE')
JOIN entryConfig ec JOIN vn.entryConfig ec
WHERE tr.shipped >= vDateInventory WHERE tr.shipped >= vDateInventory
AND vWarehouseFk = tr.warehouseOutFk AND vWarehouseFk = tr.warehouseOutFk
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
AND b.itemFk = vItemFk AND b.itemFk = vItemFk
AND e.isExcludedFromAvailable = FALSE AND NOT e.isExcludedFromAvailable
AND w.isFeedStock = FALSE AND NOT w.isFeedStock
AND e.isRaid = FALSE AND NOT e.isRaid
UNION ALL ), sales AS (
SELECT DATE(t.shipped), SELECT DATE(t.shipped) shipped,
NULL,
s.quantity, s.quantity,
st2.alertLevel, st2.alertLevel,
st2.name, st2.name,
t.nickname, t.nickname,
t.refFk, t.refFk,
t.id, t.id ticketFk,
t.clientFk, t.clientFk,
stk.id, s.id saleFk,
TRUE,
s.id,
st.`order`, st.`order`,
c.typeFk, c.typeFk,
cb.claimFk, cb.claimFk
NULL FROM vn.sale s
FROM sale s JOIN vn.ticket t ON t.id = s.ticketFk
JOIN ticket t ON t.id = s.ticketFk LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
LEFT JOIN ticketState ts ON ts.ticketFk = t.id LEFT JOIN vn.state st ON st.`code` = ts.`code`
LEFT JOIN state st ON st.`code` = ts.`code` JOIN vn.client c ON c.id = t.clientFk
JOIN client c ON c.id = t.clientFk JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
'DELIVERED', 'DELIVERED',
IF (t.shipped > util.dayEnd(util.VN_CURDATE()), IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
'FREE', 'FREE',
IFNULL(ts.code, 'FREE'))) IFNULL(ts.code, 'FREE')))
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk
LEFT JOIN saleTracking stk ON stk.saleFk = s.id
AND stk.stateFk = stPrep.id
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
WHERE t.shipped >= vDateInventory WHERE t.shipped >= vDateInventory
AND s.itemFk = vItemFk AND s.itemFk = vItemFk
AND vWarehouseFk =t.warehouseFk AND vWarehouseFk = t.warehouseFk
),sale AS (
SELECT s.shipped,
NULL `in`,
s.quantity,
s.alertLevel,
s.name,
s.nickname,
s.refFk,
s.ticketFk,
s.clientFk,
IF(stk.saleFk, TRUE, NULL),
TRUE,
s.saleFk,
s.`order`,
s.typeFk,
s.claimFk,
NULL
FROM sales s
LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED'
LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk
AND stk.stateFk = stPrep.id
GROUP BY s.saleFk
) SELECT shipped,
`in`,
`out`,
alertLevel,
stateName,
`name`,
reference,
origin,
clientFk,
isPicked,
isTicket,
lineFk,
`order`,
clientType,
claimFk,
inventorySupplierFk
FROM entriesIn
UNION ALL
SELECT * FROM entriesOut
UNION ALL
SELECT * FROM sale
ORDER BY shipped, ORDER BY shipped,
(inventorySupplierFk = clientFk) DESC, (inventorySupplierFk = clientFk) DESC,
alertLevel DESC, alertLevel DESC,

View File

@ -21,9 +21,6 @@ BEGIN
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated); CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated);
-- Añadido temporalmente para ver si ya no sucede el cuelgue de db
SET vShowType = TRUE;
WITH itemTags AS ( WITH itemTags AS (
SELECT i.id, SELECT i.id,
typeFk, typeFk,
@ -82,7 +79,7 @@ BEGIN
AND iss.warehouseFk = vWarehouseFk AND iss.warehouseFk = vWarehouseFk
JOIN itemTags its JOIN itemTags its
WHERE a.available > 0 WHERE a.available > 0
AND IF(vShowType, i.typeFk = its.typeFk, TRUE) AND (i.typeFk = its.typeFk OR NOT vShowType)
AND i.id <> vSelf AND i.id <> vSelf
ORDER BY `counter` DESC, ORDER BY `counter` DESC,
(t.name = its.name) DESC, (t.name = its.name) DESC,

View File

@ -34,7 +34,7 @@ BEGIN
ticketFk INT(11), ticketFk INT(11),
saleFk INT(11), saleFk INT(11),
isFreezed INTEGER(1) DEFAULT 0, isFreezed INTEGER(1) DEFAULT 0,
risk DECIMAL(10,2) DEFAULT 0, risk DECIMAL(10,1) DEFAULT 0,
hasHighRisk TINYINT(1) DEFAULT 0, hasHighRisk TINYINT(1) DEFAULT 0,
hasTicketRequest INTEGER(1) DEFAULT 0, hasTicketRequest INTEGER(1) DEFAULT 0,
itemShortage VARCHAR(255), itemShortage VARCHAR(255),

View File

@ -7,7 +7,7 @@ BEGIN
* *
* @param vSelf El id del ticket * @param vSelf El id del ticket
*/ */
DECLARE vCmrFk, vPreviousCmrFk, vCurrentCmrFk INT; DECLARE vCmrFk INT;
SELECT cmrFk INTO vCmrFk SELECT cmrFk INTO vCmrFk
FROM ticket FROM ticket
WHERE id = vSelf; WHERE id = vSelf;
@ -44,8 +44,6 @@ BEGIN
AND t.id = vSelf AND t.id = vSelf
GROUP BY t.id; GROUP BY t.id;
START TRANSACTION;
IF vCmrFk THEN IF vCmrFk THEN
UPDATE cmr c UPDATE cmr c
JOIN tTicket t JOIN tTicket t
@ -58,8 +56,6 @@ BEGIN
c.ead = t.landed c.ead = t.landed
WHERE id = vCmrFk; WHERE id = vCmrFk;
ELSE ELSE
SELECT MAX(id) INTO vPreviousCmrFk FROM cmr;
INSERT INTO cmr ( INSERT INTO cmr (
senderInstruccions, senderInstruccions,
truckPlate, truckPlate,
@ -71,16 +67,13 @@ BEGIN
) )
SELECT * FROM tTicket; SELECT * FROM tTicket;
SELECT MAX(id) INTO vCurrentCmrFk FROM cmr; IF (SELECT EXISTS(SELECT * FROM tTicket)) THEN
IF vPreviousCmrFk <> vCurrentCmrFk THEN
UPDATE ticket UPDATE ticket
SET cmrFk = vCurrentCmrFk SET cmrFk = LAST_INSERT_ID()
WHERE id = vSelf; WHERE id = vSelf;
END IF; END IF;
END IF; END IF;
COMMIT;
DROP TEMPORARY TABLE tTicket; DROP TEMPORARY TABLE tTicket;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -7,6 +7,8 @@ BEGIN
UPDATE expedition UPDATE expedition
SET hasNewRoute = TRUE SET hasNewRoute = TRUE
WHERE ticketFk = NEW.id; WHERE ticketFk = NEW.id;
CALL ticket_doCmr(NEW.id);
END IF; END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -6,7 +6,6 @@ AS SELECT `s`.`id` AS `Id_Proveedor`,
`s`.`account` AS `cuenta`, `s`.`account` AS `cuenta`,
`s`.`countryFk` AS `pais_id`, `s`.`countryFk` AS `pais_id`,
`s`.`nif` AS `NIF`, `s`.`nif` AS `NIF`,
`s`.`isFarmer` AS `Agricola`,
`s`.`phone` AS `Telefono`, `s`.`phone` AS `Telefono`,
`s`.`retAccount` AS `cuentaret`, `s`.`retAccount` AS `cuentaret`,
`s`.`commission` AS `ComisionProveedor`, `s`.`commission` AS `ComisionProveedor`,

View File

@ -1,6 +1,4 @@
CREATE OR REPLACE PROCEDURE `vn`.`balance_create`() BEGIN END; CREATE OR REPLACE PROCEDURE `vn`.`balance_create`() BEGIN END;
CREATE OR REPLACE PROCEDURE `vn`.`buy_recalcPricesByEntry`() BEGIN END;
CREATE OR REPLACE PROCEDURE `vn`.`buy_recalcPricesByBuy`() BEGIN END;
GRANT EXECUTE ON PROCEDURE vn.balance_create TO `financialBoss`, `hrBoss`; GRANT EXECUTE ON PROCEDURE vn.balance_create TO `financialBoss`, `hrBoss`;
GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByEntry TO `buyer`, `claimManager`, `employee`; GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByEntry TO `buyer`, `claimManager`, `employee`;

View File

@ -0,0 +1,6 @@
ALTER TABLE vn.country
ADD IF NOT EXISTS viesCode varchar(2) DEFAULT NULL NULL AFTER code;
UPDATE IGNORE vn.country
SET viesCode = 'FR'
WHERE code = 'MC'; -- Mónaco

View File

@ -1,2 +0,0 @@
-- Place your SQL code here
ALTER TABLE vn.productionConfig ADD defaultSectorFk INT UNSIGNED DEFAULT 37 NOT NULL COMMENT 'Default sector';

View File

@ -0,0 +1,5 @@
-- Place your SQL code here
ALTER TABLE vn.packaging
MODIFY COLUMN height decimal(10,2) DEFAULT NULL NULL,
MODIFY COLUMN `depth` decimal(10,2) DEFAULT NULL NULL,
MODIFY COLUMN width decimal(10,2) DEFAULT NULL NULL;

View File

@ -0,0 +1 @@
REVOKE UPDATE (`size`, longName, name) ON vn.item FROM buyer;

View File

@ -0,0 +1,3 @@
ALTER TABLE vn.invoiceInConfig CHANGE sageWithholdingFk sageFarmerWithholdingFk smallint(6) NOT NULL;
ALTER TABLE vn.supplier CHANGE isFarmer isFarmer__ tinyint(1) DEFAULT 0 NOT NULL COMMENT 'refs #7345 @deprecated 2024-05-10 - Utilizar withholdingSageFk';
ALTER TABLE vn.supplier MODIFY COLUMN isFarmer__ tinyint(1) DEFAULT 0 NOT NULL COMMENT 'refs #7345 @deprecated 2024-05-10 - Utilizar withholdingSageFk';

View File

@ -0,0 +1,3 @@
ALTER TABLE vn.item
MODIFY nonRecycledPlastic DECIMAL(10,2) DEFAULT NULL NULL,
MODIFY recycledPlastic DECIMAL(10,2) DEFAULT NULL NULL;

View File

@ -6,6 +6,7 @@ const log = require('fancy-log');
const Myt = require('@verdnatura/myt/myt'); const Myt = require('@verdnatura/myt/myt');
const Run = require('@verdnatura/myt/myt-run'); const Run = require('@verdnatura/myt/myt-run');
const Start = require('@verdnatura/myt/myt-start'); const Start = require('@verdnatura/myt/myt-start');
const watchDatabaseChanges = require('./db/dbWatcher');
// Configuration // Configuration
@ -245,6 +246,7 @@ routes.description = 'Merges all module routes file into one file';
function watch(done) { function watch(done) {
gulp.watch(routeFiles, gulp.series(routes)); gulp.watch(routeFiles, gulp.series(routes));
gulp.watch(localeFiles, gulp.series(locales)); gulp.watch(localeFiles, gulp.series(locales));
watchDatabaseChanges();
done(); done();
} }
watch.description = `Watches for changes in routes and locale files`; watch.description = `Watches for changes in routes and locale files`;

View File

@ -26,7 +26,7 @@
"sageWithholding": { "sageWithholding": {
"type": "belongsTo", "type": "belongsTo",
"model": "SageWithholding", "model": "SageWithholding",
"foreignKey": "sageWithholdingFk" "foreignKey": "sageFarmerWithholdingFk"
} }
}, },
"acls": [{ "acls": [{

View File

@ -1,7 +1,7 @@
<vn-crud-model <vn-crud-model
url="InvoiceInConfigs" url="InvoiceInConfigs"
data="$ctrl.config" data="$ctrl.config"
filter="{fields: ['sageWithholdingFk']}" filter="{fields: ['sageFarmerWithholdingFk']}"
id-value="1" id-value="1"
auto-load="true"> auto-load="true">
</vn-crud-model> </vn-crud-model>

View File

@ -112,7 +112,7 @@ class Controller extends Descriptor {
} }
isAgricultural() { isAgricultural() {
return this.invoiceIn.supplier.sageWithholdingFk == this.config[0].sageWithholdingFk; return this.invoiceIn.supplier.sageWithholdingFk == this.config[0].sageFarmerWithholdingFk;
} }
} }

View File

@ -33,7 +33,6 @@ module.exports = Self => {
try { try {
await Self.makePdf(id, options); await Self.makePdf(id, options);
} catch (err) { } catch (err) {
console.error(err);
throw new UserError('Error while generating PDF', 'pdfError'); throw new UserError('Error while generating PDF', 'pdfError');
} }

View File

@ -36,6 +36,11 @@ module.exports = Self => {
type: 'number', type: 'number',
required: true required: true
}, },
{
arg: 'checked',
type: 'boolean',
required: true
},
], ],
returns: { returns: {
type: 'boolean', type: 'boolean',
@ -51,6 +56,7 @@ module.exports = Self => {
const models = Self.app.models; const models = Self.app.models;
const myOptions = {userId: ctx.req.accessToken.userId}; const myOptions = {userId: ctx.req.accessToken.userId};
const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args; const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args;
const checked = ctx.args.checked;
let tx; let tx;
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -96,9 +102,10 @@ module.exports = Self => {
await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions); await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions);
if (!checked) {
const [invoiceId] = await models.Ticket.invoiceTicketsAndPdf(ctx, clonedTicketIds, null, myOptions); const [invoiceId] = await models.Ticket.invoiceTicketsAndPdf(ctx, clonedTicketIds, null, myOptions);
return invoiceId; return invoiceId;
}
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;

View File

@ -1,15 +1,3 @@
<vn-crud-model
auto-load="true"
url="CplusRectificationTypes"
data="cplusRectificationTypes"
order="description">
</vn-crud-model>
<vn-crud-model
auto-load="true"
url="SiiTypeInvoiceOuts"
data="siiTypeInvoiceOuts"
where="{code: {like: 'R%'}}">
</vn-crud-model>
<vn-crud-model <vn-crud-model
auto-load="true" auto-load="true"
url="InvoiceCorrectionTypes" url="InvoiceCorrectionTypes"
@ -211,14 +199,14 @@
vn-one vn-one
vn-id="cplusRectificationType" vn-id="cplusRectificationType"
required="true" required="true"
data="cplusRectificationTypes" data="$ctrl.cplusRectificationTypes"
show-field="description" show-field="description"
value-field="id" value-field="id"
ng-model="$ctrl.cplusRectificationType" ng-model="$ctrl.cplusRectificationType"
search-function="{or: [{id: $search}, {description: {like: '%'+ $search +'%'}}]}" search-function="{or: [{id: $search}, {description: {like: '%'+ $search +'%'}}]}"
label="Rectificative type"> label="Rectificative type">
<tpl-item> <tpl-item>
{{::description}} {{ ::description}}
</tpl-item> </tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
@ -226,7 +214,7 @@
<vn-autocomplete <vn-autocomplete
vn-one vn-one
vn-id="siiTypeInvoiceOut" vn-id="siiTypeInvoiceOut"
data="siiTypeInvoiceOuts" data="$ctrl.siiTypeInvoiceOuts"
show-field="description" show-field="description"
value-field="id" value-field="id"
fields="['id','code','description']" fields="['id','code','description']"
@ -248,6 +236,14 @@
label="Type"> label="Type">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal>
<vn-check
ng-model="$ctrl.isChecked"
label="destinationClient"
info="transferInvoiceInfo"
/>
</vn-check>
</vn-horizontal>
</section> </section>
</tpl-body> </tpl-body>
<tpl-buttons> <tpl-buttons>

View File

@ -7,6 +7,7 @@ class Controller extends Section {
super($element, $); super($element, $);
this.vnReport = vnReport; this.vnReport = vnReport;
this.vnEmail = vnEmail; this.vnEmail = vnEmail;
this.checked = true;
} }
get invoiceOut() { get invoiceOut() {
@ -23,6 +24,26 @@ class Controller extends Section {
return this.aclService.hasAny(['invoicing']); return this.aclService.hasAny(['invoicing']);
} }
get isChecked() {
return this.checked;
}
set isChecked(value) {
this.checked = value;
}
$onInit() {
this.$http.get(`CplusRectificationTypes`, {filter: {order: 'description'}})
.then(res => {
this.cplusRectificationTypes = res.data;
this.cplusRectificationType = res.data.filter(type => type.description == 'I Por diferencias')[0].id;
});
this.$http.get(`SiiTypeInvoiceOuts`, {filter: {where: {code: {like: 'R%'}}}})
.then(res => {
this.siiTypeInvoiceOuts = res.data;
this.siiTypeInvoiceOut = res.data.filter(type => type.code == 'R4')[0].id;
});
}
loadData() { loadData() {
const filter = { const filter = {
include: [ include: [
@ -34,7 +55,7 @@ class Controller extends Section {
}, { }, {
relation: 'client', relation: 'client',
scope: { scope: {
fields: ['id', 'name', 'email'] fields: ['id', 'name', 'email', 'hasToInvoiceByAddress']
} }
} }
] ]
@ -136,13 +157,25 @@ class Controller extends Section {
newClientFk: this.clientId, newClientFk: this.clientId,
cplusRectificationTypeFk: this.cplusRectificationType, cplusRectificationTypeFk: this.cplusRectificationType,
siiTypeInvoiceOutFk: this.siiTypeInvoiceOut, siiTypeInvoiceOutFk: this.siiTypeInvoiceOut,
invoiceCorrectionTypeFk: this.invoiceCorrectionType invoiceCorrectionTypeFk: this.invoiceCorrectionType,
checked: this.checked
}; };
this.$http.get(`Clients/${this.clientId}`).then(response => {
const clientData = response.data;
const hasToInvoiceByAddress = clientData.hasToInvoiceByAddress;
if (this.checked && hasToInvoiceByAddress) {
if (!window.confirm(this.$t('confirmTransferInvoice')))
return;
}
this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => {
const invoiceId = res.data; const invoiceId = res.data;
this.vnApp.showSuccess(this.$t('Transferred invoice')); this.vnApp.showSuccess(this.$t('Transferred invoice'));
this.$state.go('invoiceOut.card.summary', {id: invoiceId}); this.$state.go('invoiceOut.card.summary', {id: invoiceId});
}); });
});
} }
} }

View File

@ -1,3 +1,7 @@
The following refund tickets have been created: "The following refund tickets have been created: {{ticketIds}}" The following refund tickets have been created: "The following refund tickets have been created: {{ticketIds}}"
Transfer invoice to...: Transfer invoice to... Transfer invoice to...: Transfer invoice to...
Cplus Type: Cplus Type Cplus Type: Cplus Type
transferInvoice: Transfer Invoice
destinationClient: Bill destination client
transferInvoiceInfo: New tickets from the destination customer will be generated in the default consignee.
confirmTransferInvoice: Destination customer has marked to bill by consignee, do you want to continue?

View File

@ -24,3 +24,7 @@ Refund...: Abono...
Transfer invoice to...: Transferir factura a... Transfer invoice to...: Transferir factura a...
Rectificative type: Tipo rectificativa Rectificative type: Tipo rectificativa
Transferred invoice: Factura transferida Transferred invoice: Factura transferida
transferInvoice: Transferir factura
destinationClient: Facturar cliente destino
transferInvoiceInfo: Los nuevos tickets del cliente destino serán generados en el consignatario por defecto.
confirmTransferInvoice: El cliente destino tiene marcado facturar por consignatario, ¿desea continuar?

View File

@ -19,6 +19,9 @@ module.exports = Self => {
type: 'number', type: 'number',
required: true, required: true,
description: 'The requested item quantity', description: 'The requested item quantity',
}, {
arg: 'attenderFk',
type: 'number'
}], }],
returns: { returns: {
type: 'object', type: 'object',
@ -73,12 +76,14 @@ module.exports = Self => {
ticketFk: request.ticketFk, ticketFk: request.ticketFk,
itemFk: ctx.args.itemFk, itemFk: ctx.args.itemFk,
quantity: ctx.args.quantity, quantity: ctx.args.quantity,
attenderFk: ctx.args.attenderFk,
concept: item.name concept: item.name
}, myOptions); }, myOptions);
await request.updateAttributes({ await request.updateAttributes({
saleFk: sale.id, saleFk: sale.id,
itemFk: sale.itemFk, itemFk: sale.itemFk,
isOk: true isOk: true,
attenderFk: sale.attenderFk,
}, myOptions); }, myOptions);
const query = `CALL vn.sale_calculateComponent(?, NULL)`; const query = `CALL vn.sale_calculateComponent(?, NULL)`;

View File

@ -113,7 +113,8 @@
"test:e2e": "node e2e/tests.js", "test:e2e": "node e2e/tests.js",
"test:front": "jest --watch", "test:front": "jest --watch",
"back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back", "back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back",
"lint": "eslint ./ --cache --ignore-pattern .gitignore" "lint": "eslint ./ --cache --ignore-pattern .gitignore",
"watch:db": "node ./db/dbWatcher.js"
}, },
"jest": { "jest": {
"projects": [ "projects": [