test #3056

Merged
robert merged 18 commits from test into dev 2024-10-02 09:22:28 +00:00
25 changed files with 307 additions and 39 deletions
Showing only changes of commit d31340ff25 - Show all commits

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`travel_setDelivered` CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`travel_setDelivered`
ON SCHEDULE EVERY 1 DAY ON SCHEDULE EVERY 1 DAY
STARTS '2024-07-12 00:10:00.000' STARTS '2024-07-12 00:10:00.000'
ON COMPLETION PRESERVE ON COMPLETION PRESERVE

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimate`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`buy_getUltimate`(
vItemFk INT, vItemFk INT,
vWarehouseFk SMALLINT, vWarehouseFk SMALLINT,
vDated DATE vDated DATE

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimateFromInterval`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`buy_getUltimateFromInterval`(
vItemFk INT, vItemFk INT,
vWarehouseFk SMALLINT, vWarehouseFk SMALLINT,
vStarted DATE, vStarted DATE,

View File

@ -55,24 +55,20 @@ BEGIN
SELECT ts.saleFk, SELECT ts.saleFk,
ts.itemFk, ts.itemFk,
CAST(0 AS DECIMAL(10,0)) saleOrder, CAST(0 AS DECIMAL(10,0)) saleOrder,
IF(ish.visible > 0 OR iss.id, 1, 100000) * (IF(ish.visible > 0 OR iss.id, 1, 100000) *
IFNULL(p2.pickingOrder, p.pickingOrder) `order`, COALESCE(p2.pickingOrder, p.pickingOrder)) `order`,
TO_SECONDS(IF(iss.id, TO_SECONDS(COALESCE(iss.created, ish.created)) - TO_SECONDS(MAKEDATE(IFNULL(YEAR(iss.created), YEAR(ish.created)), 1)) priority,
iss.created - INTERVAL vCurrentYear YEAR,
ish.created - INTERVAL YEAR(ish.created) YEAR)) priority,
CONCAT( CONCAT(
IF(iss.id, IF(iss.id, CONCAT('< ', COALESCE(wk.`code`, '---'),' > '), ''),
CONCAT('< ', IFNULL(wk.`code`, '---'),' > '), p.`code`
''), ) COLLATE utf8_general_ci placement,
p.`code`) COLLATE utf8_general_ci placement,
sh.priority shelvingPriority, sh.priority shelvingPriority,
sh.code COLLATE utf8_general_ci shelving, sh.code COLLATE utf8_general_ci shelving,
ish.created, ish.created,
ish.visible, ish.visible,
IFNULL( COALESCE(
IF(st.code = 'previousByPacking', ish.packing, g.`grouping`), IF(st.code = 'previousByPacking', ish.packing, g.`grouping`),1) `grouping`,
1) `grouping`, (st.code = 'previousPrepared') isPreviousPrepared,
st.code = 'previousPrepared' isPreviousPrepared,
iss.id itemShelvingSaleFk, iss.id itemShelvingSaleFk,
ts.ticketFk, ts.ticketFk,
iss.id, iss.id,
@ -80,11 +76,12 @@ BEGIN
iss.userFk, iss.userFk,
ts.quantity ts.quantity
FROM tSale ts FROM tSale ts
LEFT JOIN (SELECT DISTINCT saleFk LEFT JOIN (SELECT st.saleFk
FROM saleTracking st FROM saleTracking st
JOIN state s ON s.id = st.stateFk JOIN state s ON s.id = st.stateFk
WHERE st.isChecked WHERE st.isChecked
AND s.semaphore = 1) st ON st.saleFk = ts.saleFk AND s.semaphore = 1
GROUP BY st.saleFk) st ON st.saleFk = ts.saleFk
JOIN itemShelving ish ON ish.itemFk = ts.itemFk JOIN itemShelving ish ON ish.itemFk = ts.itemFk
JOIN shelving sh ON sh.code = ish.shelvingFk JOIN shelving sh ON sh.code = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk JOIN parking p ON p.id = sh.parkingFk
@ -93,14 +90,14 @@ BEGIN
JOIN warehouse w ON w.id = sc.warehouseFk JOIN warehouse w ON w.id = sc.warehouseFk
LEFT JOIN tGrouping g ON g.itemFk = ts.itemFk LEFT JOIN tGrouping g ON g.itemFk = ts.itemFk
LEFT JOIN itemShelvingSale iss ON iss.saleFk = ts.saleFk LEFT JOIN itemShelvingSale iss ON iss.saleFk = ts.saleFk
AND iss.itemShelvingFk = ish.id AND iss.itemShelvingFk = ish.id
LEFT JOIN worker wk ON wk.id = iss.userFk LEFT JOIN worker wk ON wk.id = iss.userFk
LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = ts.saleFk LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = ts.saleFk
LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
LEFT JOIN parking p2 ON p2.id = sg.parkingFk LEFT JOIN parking p2 ON p2.id = sg.parkingFk
WHERE w.id = vWarehouseFk WHERE w.id = vWarehouseFk
AND NOT sc.isHideForPickers AND NOT sc.isHideForPickers
HAVING (iss.id AND st.saleFk) OR salePreviousPrepared IS NULL; AND ((iss.id AND st.saleFk) OR st.saleFk IS NULL);
CREATE OR REPLACE TEMPORARY TABLE tSalePlacementList2 CREATE OR REPLACE TEMPORARY TABLE tSalePlacementList2
(INDEX(saleFk), INDEX(olderPriority)) (INDEX(saleFk), INDEX(olderPriority))

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_mergeSales`(vCollectionFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`collection_mergeSales`(vCollectionFk INT)
BEGIN BEGIN
DECLARE vDone BOOL; DECLARE vDone BOOL;
DECLARE vTicketFk INT; DECLARE vTicketFk INT;

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemMinimumQuantity_check`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemMinimumQuantity_check`(
vSelf INT, vSelf INT,
vItemFk INT, vItemFk INT,
vStarted DATE, vStarted DATE,

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySaleGroup`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySaleGroup`(
vSaleGroupFk INT(11) vSaleGroupFk INT(11)
) )
BEGIN BEGIN

View File

@ -0,0 +1,62 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockBought_calculate`(
vDated DATE
)
proc: BEGIN
/**
* Calculate the stock of the auction warehouse from the inventory date to vDated
* without taking into account the outputs of the same day vDated
*
* @param vDated Date to calculate the stock.
*/
IF vDated < util.VN_CURDATE() THEN
LEAVE proc;
END IF;
CREATE OR REPLACE TEMPORARY TABLE tStockBought
SELECT workerFk, reserve
FROM stockBought
WHERE dated = vDated
AND reserve;
DELETE FROM stockBought WHERE dated = vDated;
CALL item_calculateStock(vDated);
INSERT INTO stockBought(workerFk, bought, dated)
SELECT it.workerFk,
ROUND(SUM(
(ti.quantity / b.packing) *
buy_getVolume(b.id)
) / vc.palletM3 / 1000000, 1) bought,
vDated
FROM itemType it
JOIN item i ON i.typeFk = it.id
LEFT JOIN tmp.item ti ON ti.itemFk = i.id
JOIN itemCategory ic ON ic.id = it.categoryFk
JOIN warehouse wh ON wh.code = 'VNH'
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
AND bu.warehouseFk = wh.id
JOIN buy b ON b.id = bu.buyFk
JOIN volumeConfig vc
WHERE ic.display
GROUP BY it.workerFk
HAVING bought;
UPDATE stockBought s
JOIN tStockBought ts ON ts.workerFk = s.workerFk
SET s.reserve = ts.reserve
WHERE s.dated = vDated;
INSERT INTO stockBought (workerFk, reserve, dated)
SELECT ts.workerFk, ts.reserve, vDated
FROM tStockBought ts
WHERE ts.workerFk NOT IN (
SELECT workerFk
FROM stockBought
WHERE dated = vDated
);
DROP TEMPORARY TABLE tStockBought, tmp.item, tmp.buyUltimate;
END$$
DELIMITER ;

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE vn.supplier_statementWithEntries( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE vn.supplier_statementWithEntries(
vSupplierFk INT, vSupplierFk INT,
vCurrencyFk INT, vCurrencyFk INT,
vCompanyFk INT, vCompanyFk INT,

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_mergeSales`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_mergeSales`(
vSelf INT vSelf INT
) )
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRiskByClient`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setProblemRiskByClient`(
vClientFk INT vClientFk INT
) )
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolume`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setVolume`(
vSelf INT vSelf INT
) )
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`(
vItemFk INT vItemFk INT
) )
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`host_beforeInsert` CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`host_beforeInsert`
BEFORE INSERT ON `host` BEFORE INSERT ON `host`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`roadmap_beforeInsert` CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeInsert`
BEFORE INSERT ON `roadmap` BEFORE INSERT ON `roadmap`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`roadmap_beforeUpdate` CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeUpdate`
BEFORE UPDATE ON `roadmap` BEFORE UPDATE ON `roadmap`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroupDetail_beforeInsert` CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`saleGroupDetail_beforeInsert`
BEFORE INSERT ON `saleGroupDetail` BEFORE INSERT ON `saleGroupDetail`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroupDetail_afterDelete` CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`saleGroupDetail_afterDelete`
AFTER DELETE ON `saleGroupDetail` AFTER DELETE ON `saleGroupDetail`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroupDetail_beforeUpdate` CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`saleGroupDetail_beforeUpdate`
BEFORE UPDATE ON `saleGroupDetail` BEFORE UPDATE ON `saleGroupDetail`
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN

View File

@ -0,0 +1,30 @@
-- Place your SQL code here
-- vn.stockBought definition
CREATE TABLE IF NOT EXISTS vn.stockBought (
id INT UNSIGNED auto_increment NOT NULL,
workerFk int(10) unsigned NOT NULL,
bought decimal(10,2) NOT NULL COMMENT 'purchase volume in m3 for the day',
reserve decimal(10,2) NULL COMMENT 'reserved volume in m3 for the day',
dated DATE NOT NULL DEFAULT current_timestamp(),
CONSTRAINT stockBought_pk PRIMARY KEY (id),
CONSTRAINT stockBought_unique UNIQUE KEY (workerFk,dated),
CONSTRAINT stockBought_worker_FK FOREIGN KEY (workerFk) REFERENCES vn.worker(id)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;
INSERT IGNORE vn.stockBought (workerFk, bought, reserve, dated)
SELECT userFk, SUM(buyed), SUM(IFNULL(reserved,0)), dated
FROM vn.stockBuyed
WHERE userFk IS NOT NULL
AND buyed IS NOT NULL
GROUP BY userFk, dated;
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('StockBought','*','READ','ALLOW','ROLE','buyer'),
('StockBought','*','WRITE','ALLOW','ROLE','buyer'),
('Buyer','*','READ','ALLOW','ROLE','buyer');

View File

@ -0,0 +1,58 @@
module.exports = Self => {
Self.remoteMethod('getStockBought', {
description: 'Returns the stock bought for a given date',
accessType: 'READ',
accepts: [{
arg: 'workerFk',
type: 'number',
description: 'The id for a buyer',
},
{
arg: 'dated',
type: 'date',
description: 'The date to filter',
}
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/getStockBought`,
verb: 'GET'
}
});
Self.getStockBought = async(workerFk, dated = Date.vnNew()) => {
const models = Self.app.models;
const today = Date.vnNew();
dated.setHours(0, 0, 0, 0);
today.setHours(0, 0, 0, 0);
await models.StockBought.rawSql(`CALL vn.stockBought_calculate(?)`, [dated]);
const filter = {
where: {dated},
include: [
{
fields: ['workerFk', 'reserve', 'bought'],
relation: 'worker',
scope: {
include: [
{
relation: 'user',
scope: {
fields: ['id', 'name']
}
}
]
}
}
]
};
if (workerFk) filter.where.workerFk = workerFk;
return models.StockBought.find(filter);
};
};

View File

@ -0,0 +1,74 @@
module.exports = Self => {
Self.remoteMethod('getStockBoughtDetail', {
description: 'Returns the detail of stock bought for a given date and a worker',
accessType: 'READ',
accepts: [{
arg: 'workerFk',
type: 'number',
description: 'The worker to filter',
required: true,
}, {
arg: 'dated',
type: 'string',
description: 'The date to filter',
required: true,
}
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/getStockBoughtDetail`,
verb: 'GET'
}
});
Self.getStockBoughtDetail = async(workerFk, dated) => {
const models = Self.app.models;
const myOptions = {};
let tx;
let result;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated], myOptions);
result = await Self.rawSql(
`SELECT b.entryFk entryFk,
i.id itemFk,
i.name itemName,
ti.quantity,
(ac.conversionCoefficient * (ti.quantity / b.packing) * buy_getVolume(b.id))
/ (vc.trolleyM3 * 1000000) volume,
b.packagingFk packagingFk,
b.packing
FROM tmp.item ti
JOIN item i ON i.id = ti.itemFk
JOIN itemType it ON i.typeFk = it.id
JOIN itemCategory ic ON ic.id = it.categoryFk
JOIN worker w ON w.id = it.workerFk
JOIN auctionConfig ac
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
AND bu.warehouseFk = ac.warehouseFk
JOIN buy b ON b.id = bu.buyFk
JOIN volumeConfig vc
WHERE ic.display
AND w.id = ?`,
[workerFk], myOptions
);
await Self.rawSql(`DROP TEMPORARY TABLE tmp.item, tmp.buyUltimate;`, [], myOptions);
if (tx) await tx.commit();
return result;
} catch (e) {
await tx.rollback();
throw e;
}
};
};

View File

@ -25,5 +25,8 @@
}, },
"EntryType": { "EntryType": {
"dataSource": "vn" "dataSource": "vn"
},
"StockBought": {
"dataSource": "vn"
} }
} }

View File

@ -0,0 +1,10 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
require('../methods/stock-bought/getStockBought')(Self);
require('../methods/stock-bought/getStockBoughtDetail')(Self);
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')
return new UserError(`This buyer has already made a reservation for this date`);
return err;
});
};

View File

@ -0,0 +1,34 @@
{
"name": "StockBought",
"base": "VnModel",
"options": {
"mysql": {
"table": "stockBought"
}
},
"properties": {
"id": {
"type": "number",
"id": true
},
"workerFk": {
"type": "number"
},
"bought": {
"type": "number"
},
"reserve": {
"type": "number"
},
"dated": {
"type": "date"
}
},
"relations": {
"worker": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": "workerFk"
}
}
}