Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 7202-AddCustomAgentFkColumn
This commit is contained in:
commit
698ef3dec3
|
@ -15,9 +15,6 @@
|
|||
"nickname": {
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
"display": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
|
|
|
@ -179,12 +179,12 @@ INSERT INTO `vn`.`country`(`id`, `name`, `isUeeMember`, `code`, `currencyFk`, `i
|
|||
(30,'Canarias', 1, 'IC', 1, 24, 4, 1, 2);
|
||||
|
||||
INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasDms`, `hasComission`, `countryFk`, `hasProduction`, `isOrigin`, `isDestiny`)
|
||||
VALUES (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
|
||||
VALUES
|
||||
(1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
|
||||
(2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 1, 13, 1, 1, 0),
|
||||
(3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0),
|
||||
(4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1),
|
||||
(5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0),
|
||||
(6, 'Warehouse six', 'VNH', 1, 1, 1, 1, 0, 0, 1, 1, 0, 0),
|
||||
(13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 1, 0, 0, 0),
|
||||
(60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0);
|
||||
|
||||
|
@ -1544,7 +1544,7 @@ INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `sal
|
|||
('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 6, 1, '186', '0', '51', '53.12', '56.20', '56.20', '56.20'),
|
||||
('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 7, 1, '277', '0', '53.12', '56.20', '56.20', '56.20', '56.20');
|
||||
|
||||
INSERT INTO vn.buy(id,entryFk,itemFk,buyingValue,quantity,packagingFk,stickers,freightValue,packageValue,comissionValue,packing,grouping,groupingMode,location,price1,price2,price3,printedStickers,isChecked,isIgnored,weight,created)
|
||||
INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packagingFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`, `printedStickers`,`isChecked`,`isIgnored`,`weight`, `created`)
|
||||
VALUES
|
||||
(1, 1, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH),
|
||||
(2, 2, 1, 50, 100, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 1 MONTH),
|
||||
|
@ -1560,8 +1560,7 @@ INSERT INTO vn.buy(id,entryFk,itemFk,buyingValue,quantity,packagingFk,stickers,f
|
|||
(12, 6, 4, 1.25, 0, 3, 1, 2.500, 2.500, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()),
|
||||
(13, 7, 1, 50, 0, 3, 1, 2.000, 2.000, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()),
|
||||
(14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()),
|
||||
(15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()),
|
||||
(16, 99,1,50.0000, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.60, 99.40, 0, 1, 0, 1.00, '2024-07-30 08:13:51.000');
|
||||
(15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE());
|
||||
|
||||
INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`)
|
||||
VALUES
|
||||
|
@ -3939,37 +3938,43 @@ INSERT INTO vn.medicalReview
|
|||
(id, workerFk, centerFk, `date`, `time`, isFit, amount, invoice, remark)
|
||||
VALUES(3, 9, 2, '2000-01-01', '8:00', 1, 150.0, NULL, NULL);
|
||||
|
||||
INSERT INTO vn.stockBought (workerFk, bought, reserve, dated)
|
||||
VALUES(35, 1.00, 1.00, '2001-01-01');
|
||||
|
||||
INSERT INTO vn.auctionConfig (id,conversionCoefficient,warehouseFk)
|
||||
VALUES (1,0.6,6);
|
||||
|
||||
INSERT INTO vn.payrollComponent (id, name, isSalaryAgreed, isVariable, isException)
|
||||
VALUES (1, 'Salario1', 1, 0, 0),
|
||||
INSERT INTO vn.payrollComponent
|
||||
(id, name, isSalaryAgreed, isVariable, isException)
|
||||
VALUES
|
||||
(1, 'Salario1', 1, 0, 0),
|
||||
(2, 'Salario2', 1, 1, 0),
|
||||
(3, 'Salario3', 1, 0, 1);
|
||||
|
||||
INSERT INTO vn.workerIncome (debit, credit, incomeTypeFk, paymentDate, workerFk, concept)
|
||||
VALUES (1000.00, 900.00, 2, '2000-01-01', 1106, NULL),
|
||||
|
||||
INSERT INTO vn.workerIncome
|
||||
(debit, credit, incomeTypeFk, paymentDate, workerFk, concept)
|
||||
VALUES
|
||||
(1000.00, 900.00, 2, '2000-01-01', 1106, NULL),
|
||||
(1001.00, 800.00, 2, '2000-01-01', 1106, NULL);
|
||||
|
||||
INSERT INTO dipole.printer (id, description) VALUES(1, '');
|
||||
|
||||
INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments)
|
||||
VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL);
|
||||
INSERT INTO dipole.printer (id, description)
|
||||
VALUES(1, '');
|
||||
|
||||
INSERT INTO vn.accountDetail (id, value, accountDetailTypeFk, supplierAccountFk)
|
||||
VALUES (21, 'ES12345B12345678', 3, 241),
|
||||
(35, 'ES12346B12345679', 3, 241);
|
||||
INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode,
|
||||
truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments)
|
||||
VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL);
|
||||
|
||||
INSERT INTO vn.accountDetailType (id, description, code)
|
||||
VALUES (1, 'IBAN', 'iban'),
|
||||
(2, 'SWIFT', 'swift'),
|
||||
(3, 'Referencia Remesas', 'remRef'),
|
||||
(4, 'Referencia Transferencias', 'trnRef'),
|
||||
(5, 'Referencia Nominas', 'payRef'),
|
||||
(6, 'ABA', 'aba');
|
||||
INSERT INTO vn.accountDetail
|
||||
(id, value, accountDetailTypeFk, supplierAccountFk)
|
||||
VALUES
|
||||
(21, 'ES12345B12345678', 3, 241),
|
||||
(35, 'ES12346B12345679', 3, 241);
|
||||
|
||||
INSERT INTO vn.accountDetailType
|
||||
(id, description, code)
|
||||
VALUES
|
||||
(1, 'IBAN', 'iban'),
|
||||
(2, 'SWIFT', 'swift'),
|
||||
(3, 'Referencia Remesas', 'remRef'),
|
||||
(4, 'Referencia Transferencias', 'trnRef'),
|
||||
(5, 'Referencia Nominas', 'payRef'),
|
||||
(6, 'ABA', 'aba');
|
||||
|
||||
INSERT IGNORE INTO ormConfig
|
||||
SET id =1,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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
|
||||
STARTS '2024-07-12 00:10:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimate`(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`buy_getUltimate`(
|
||||
vItemFk INT,
|
||||
vWarehouseFk SMALLINT,
|
||||
vDated DATE
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimateFromInterval`(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`buy_getUltimateFromInterval`(
|
||||
vItemFk INT,
|
||||
vWarehouseFk SMALLINT,
|
||||
vStarted DATE,
|
||||
|
|
|
@ -29,21 +29,24 @@ BEGIN
|
|||
(INDEX (itemFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT i.id itemFk,
|
||||
SUM(IFNULL(pd.absIncreasing,0)) absIncreasing,
|
||||
SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing,
|
||||
pd.warehouseFk
|
||||
FROM item i
|
||||
JOIN priceDelta pd
|
||||
ON pd.itemTypeFk = i.typeFk
|
||||
AND (pd.minSize IS NULL OR pd.minSize <= i.`size`)
|
||||
AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`)
|
||||
AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk)
|
||||
AND (pd.originFk IS NULL OR pd.originFk = i.originFk)
|
||||
AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk)
|
||||
AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk)
|
||||
WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped)
|
||||
AND (pd.toDated IS NULL OR pd.toDated >= vShipped)
|
||||
GROUP BY i.id;
|
||||
SUM(IFNULL(pd.absIncreasing,0)) absIncreasing,
|
||||
SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing,
|
||||
pd.warehouseFk
|
||||
FROM item i
|
||||
JOIN priceDelta pd
|
||||
ON pd.itemTypeFk = i.typeFk
|
||||
AND (pd.minSize IS NULL OR pd.minSize <= i.`size`)
|
||||
AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`)
|
||||
AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk)
|
||||
AND (pd.originFk IS NULL OR pd.originFk = i.originFk)
|
||||
AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk)
|
||||
AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk)
|
||||
LEFT JOIN zoneGeo zg ON zg.id = pd.zoneGeoFk
|
||||
LEFT JOIN zoneGeo zg2 ON zg2.id = address_getGeo(vAddressFk)
|
||||
WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped)
|
||||
AND (pd.toDated IS NULL OR pd.toDated >= vShipped)
|
||||
AND (pd.zoneGeoFk IS NULL OR zg2.lft BETWEEN zg.lft AND zg.rgt)
|
||||
GROUP BY itemFk;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice
|
||||
(INDEX (itemFk))
|
||||
|
@ -130,15 +133,15 @@ BEGIN
|
|||
|
||||
-- Bonus del comprador a un rango de productos
|
||||
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
|
||||
SELECT
|
||||
SELECT
|
||||
tcb.warehouseFk,
|
||||
tcb.itemFk,
|
||||
c.id,
|
||||
IFNULL(tcb.base * tpd.ratIncreasing / 100,0) + IFNULL(tpd.absIncreasing,0)
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN component c ON c.code = 'bonus'
|
||||
JOIN tPriceDelta tpd
|
||||
ON tpd.itemFk = tcb.itemFk
|
||||
JOIN tPriceDelta tpd
|
||||
ON tpd.itemFk = tcb.itemFk
|
||||
AND tpd.warehouseFk = tcb.warehouseFk;
|
||||
|
||||
-- RECOBRO
|
||||
|
|
|
@ -55,24 +55,20 @@ BEGIN
|
|||
SELECT ts.saleFk,
|
||||
ts.itemFk,
|
||||
CAST(0 AS DECIMAL(10,0)) saleOrder,
|
||||
IF(ish.visible > 0 OR iss.id, 1, 100000) *
|
||||
IFNULL(p2.pickingOrder, p.pickingOrder) `order`,
|
||||
TO_SECONDS(IF(iss.id,
|
||||
iss.created - INTERVAL vCurrentYear YEAR,
|
||||
ish.created - INTERVAL YEAR(ish.created) YEAR)) priority,
|
||||
(IF(ish.visible > 0 OR iss.id, 1, 100000) *
|
||||
COALESCE(p2.pickingOrder, p.pickingOrder)) `order`,
|
||||
TO_SECONDS(COALESCE(iss.created, ish.created)) - TO_SECONDS(MAKEDATE(IFNULL(YEAR(iss.created), YEAR(ish.created)), 1)) priority,
|
||||
CONCAT(
|
||||
IF(iss.id,
|
||||
CONCAT('< ', IFNULL(wk.`code`, '---'),' > '),
|
||||
''),
|
||||
p.`code`) COLLATE utf8_general_ci placement,
|
||||
IF(iss.id, CONCAT('< ', COALESCE(wk.`code`, '---'),' > '), ''),
|
||||
p.`code`
|
||||
) COLLATE utf8_general_ci placement,
|
||||
sh.priority shelvingPriority,
|
||||
sh.code COLLATE utf8_general_ci shelving,
|
||||
ish.created,
|
||||
ish.visible,
|
||||
IFNULL(
|
||||
IF(st.code = 'previousByPacking', ish.packing, g.`grouping`),
|
||||
1) `grouping`,
|
||||
st.code = 'previousPrepared' isPreviousPrepared,
|
||||
COALESCE(
|
||||
IF(st.code = 'previousByPacking', ish.packing, g.`grouping`),1) `grouping`,
|
||||
(st.code = 'previousPrepared') isPreviousPrepared,
|
||||
iss.id itemShelvingSaleFk,
|
||||
ts.ticketFk,
|
||||
iss.id,
|
||||
|
@ -80,11 +76,12 @@ BEGIN
|
|||
iss.userFk,
|
||||
ts.quantity
|
||||
FROM tSale ts
|
||||
LEFT JOIN (SELECT DISTINCT saleFk
|
||||
FROM saleTracking st
|
||||
JOIN state s ON s.id = st.stateFk
|
||||
WHERE st.isChecked
|
||||
AND s.semaphore = 1) st ON st.saleFk = ts.saleFk
|
||||
LEFT JOIN (SELECT st.saleFk
|
||||
FROM saleTracking st
|
||||
JOIN state s ON s.id = st.stateFk
|
||||
WHERE st.isChecked
|
||||
AND s.semaphore = 1
|
||||
GROUP BY st.saleFk) st ON st.saleFk = ts.saleFk
|
||||
JOIN itemShelving ish ON ish.itemFk = ts.itemFk
|
||||
JOIN shelving sh ON sh.code = ish.shelvingFk
|
||||
JOIN parking p ON p.id = sh.parkingFk
|
||||
|
@ -93,14 +90,14 @@ BEGIN
|
|||
JOIN warehouse w ON w.id = sc.warehouseFk
|
||||
LEFT JOIN tGrouping g ON g.itemFk = ts.itemFk
|
||||
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 saleGroupDetail sgd ON sgd.saleFk = ts.saleFk
|
||||
LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
|
||||
LEFT JOIN parking p2 ON p2.id = sg.parkingFk
|
||||
WHERE w.id = vWarehouseFk
|
||||
AND NOT sc.isHideForPickers
|
||||
HAVING (iss.id AND st.saleFk) OR salePreviousPrepared IS NULL;
|
||||
AND NOT sc.isHideForPickers
|
||||
AND ((iss.id AND st.saleFk) OR st.saleFk IS NULL);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tSalePlacementList2
|
||||
(INDEX(saleFk), INDEX(olderPriority))
|
||||
|
|
|
@ -23,7 +23,7 @@ BEGIN
|
|||
JOIN vn.ticketCollection tc ON tc.ticketFk = tob.ticketFk
|
||||
LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk
|
||||
WHERE ot.`code` = 'itemPicker'
|
||||
AND tc.collectionFk = vParamFk
|
||||
AND tc.collectionFk = vParamFk OR tc.ticketFk = vParamFk
|
||||
)
|
||||
SELECT t.id ticketFk,
|
||||
IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vTicketFk INT;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`collection_new`(vUserFk INT, OUT vCollectionFk INT)
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`collection_new`(
|
||||
vUserFk INT,
|
||||
OUT vCollectionFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Genera colecciones de tickets sin asignar trabajador.
|
||||
|
@ -12,30 +15,29 @@ BEGIN
|
|||
DECLARE vLinesLimit INT;
|
||||
DECLARE vTicketLines INT;
|
||||
DECLARE vVolumeLimit DECIMAL;
|
||||
DECLARE vTicketVolume DECIMAL;
|
||||
DECLARE vSizeLimit INT;
|
||||
DECLARE vTicketVolume DECIMAL;
|
||||
DECLARE vMaxTickets INT;
|
||||
DECLARE vStateFk VARCHAR(45);
|
||||
DECLARE vStateCode VARCHAR(45);
|
||||
DECLARE vFirstTicketFk INT;
|
||||
DECLARE vHour INT;
|
||||
DECLARE vMinute INT;
|
||||
DECLARE vWorkerCode VARCHAR(3);
|
||||
DECLARE vWagonCounter INT DEFAULT 0;
|
||||
DECLARE vWagonCounter INT DEFAULT 1;
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vItemPackingTypeFk VARCHAR(1);
|
||||
DECLARE vHasAssignedTickets BOOLEAN;
|
||||
DECLARE vHasAssignedTickets BOOL;
|
||||
DECLARE vHasUniqueCollectionTime BOOL;
|
||||
DECLARE vDone INT DEFAULT FALSE;
|
||||
DECLARE vLockName VARCHAR(215);
|
||||
DECLARE vLockTime INT DEFAULT 30;
|
||||
DECLARE vHeight INT;
|
||||
DECLARE vVolume INT;
|
||||
DECLARE vLiters INT;
|
||||
DECLARE vLines INT;
|
||||
DECLARE vTotalLines INT DEFAULT 0;
|
||||
DECLARE vTotalVolume INT DEFAULT 0;
|
||||
DECLARE vFreeWagonFk INT;
|
||||
DECLARE vErrorNumber INT;
|
||||
DECLARE vErrorMsg TEXT;
|
||||
DECLARE vDone INT DEFAULT FALSE;
|
||||
|
||||
DECLARE c1 CURSOR FOR
|
||||
DECLARE vTickets CURSOR FOR
|
||||
SELECT ticketFk, `lines`, m3
|
||||
FROM tmp.productionBuffer
|
||||
WHERE ticketFk <> vFirstTicketFk
|
||||
ORDER BY HH,
|
||||
mm,
|
||||
productionOrder DESC,
|
||||
|
@ -48,26 +50,6 @@ BEGIN
|
|||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
GET DIAGNOSTICS CONDITION 1
|
||||
vErrorNumber = MYSQL_ERRNO,
|
||||
vErrorMsg = MESSAGE_TEXT;
|
||||
|
||||
CALL util.debugAdd('collection_new', JSON_OBJECT(
|
||||
'errorNumber', vErrorNumber,
|
||||
'errorMsg', vErrorMsg,
|
||||
'lockName', vLockName,
|
||||
'userFk', vUserFk,
|
||||
'ticketFk', vTicketFk
|
||||
)); -- Tmp
|
||||
|
||||
IF vLockName IS NOT NULL THEN
|
||||
DO RELEASE_LOCK(vLockName);
|
||||
END IF;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
SELECT pc.ticketTrolleyMax * o.numberOfWagons,
|
||||
pc.hasUniqueCollectionTime,
|
||||
w.code,
|
||||
|
@ -78,36 +60,26 @@ BEGIN
|
|||
o.trainFk,
|
||||
o.linesLimit,
|
||||
o.volumeLimit,
|
||||
o.sizeLimit,
|
||||
pc.collection_new_lockname
|
||||
o.sizeLimit
|
||||
INTO vMaxTickets,
|
||||
vHasUniqueCollectionTime,
|
||||
vWorkerCode,
|
||||
vWarehouseFk,
|
||||
vItemPackingTypeFk,
|
||||
vStateFk,
|
||||
vWagons,
|
||||
vTrainFk,
|
||||
vLinesLimit,
|
||||
vVolumeLimit,
|
||||
vSizeLimit,
|
||||
vLockName
|
||||
FROM productionConfig pc
|
||||
JOIN worker w ON w.id = vUserFk
|
||||
vHasUniqueCollectionTime,
|
||||
vWorkerCode,
|
||||
vWarehouseFk,
|
||||
vItemPackingTypeFk,
|
||||
vStateCode,
|
||||
vWagons,
|
||||
vTrainFk,
|
||||
vLinesLimit,
|
||||
vVolumeLimit,
|
||||
vSizeLimit
|
||||
FROM worker w
|
||||
JOIN operator o ON o.workerFk = w.id
|
||||
JOIN state st ON st.`code` = 'ON_PREPARATION'
|
||||
JOIN operator o ON o.workerFk = vUserFk;
|
||||
|
||||
SET vLockName = CONCAT_WS('/',
|
||||
vLockName,
|
||||
vWarehouseFk,
|
||||
vItemPackingTypeFk
|
||||
);
|
||||
|
||||
IF NOT GET_LOCK(vLockName, vLockTime) THEN
|
||||
CALL util.throw(CONCAT('Cannot get lock: ', vLockName));
|
||||
END IF;
|
||||
JOIN productionConfig pc
|
||||
WHERE w.id = vUserFk;
|
||||
|
||||
-- Se prepara el tren, con tantos vagones como sea necesario.
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tTrain
|
||||
(wagon INT,
|
||||
shelve INT,
|
||||
|
@ -118,59 +90,60 @@ BEGIN
|
|||
PRIMARY KEY(wagon, shelve))
|
||||
ENGINE = MEMORY;
|
||||
|
||||
WHILE vWagons > vWagonCounter DO
|
||||
SET vWagonCounter = vWagonCounter + 1;
|
||||
|
||||
INSERT INTO tTrain(wagon, shelve, liters, `lines`, height)
|
||||
SELECT vWagonCounter, cv.`level` , cv.liters , cv.`lines` , cv.height
|
||||
FROM collectionVolumetry cv
|
||||
WHERE cv.trainFk = vTrainFk
|
||||
INSERT INTO tTrain (wagon, shelve, liters, `lines`, height)
|
||||
WITH RECURSIVE wagonSequence AS (
|
||||
SELECT vWagonCounter wagon
|
||||
UNION ALL
|
||||
SELECT wagon + 1 wagon
|
||||
FROM wagonSequence
|
||||
WHERE wagon < vWagonCounter + vWagons -1
|
||||
)
|
||||
SELECT ws.wagon, cv.`level`, cv.liters, cv.`lines`, cv.height
|
||||
FROM wagonSequence ws
|
||||
JOIN vn.collectionVolumetry cv ON cv.trainFk = vTrainFk
|
||||
AND cv.itemPackingTypeFk = vItemPackingTypeFk;
|
||||
END WHILE;
|
||||
|
||||
-- Esto desaparecerá cuando tengamos la table cache.ticket
|
||||
|
||||
CALL productionControl(vWarehouseFk, 0);
|
||||
|
||||
ALTER TABLE tmp.productionBuffer
|
||||
ADD COLUMN liters INT,
|
||||
ADD COLUMN height INT;
|
||||
|
||||
-- Se obtiene nº de colección.
|
||||
INSERT INTO collection
|
||||
SET itemPackingTypeFk = vItemPackingTypeFk,
|
||||
trainFk = vTrainFk,
|
||||
wagons = vWagons,
|
||||
warehouseFk = vWarehouseFk;
|
||||
|
||||
SELECT LAST_INSERT_ID() INTO vCollectionFk;
|
||||
|
||||
-- Los tickets de recogida en Algemesí sólo se sacan si están asignados.
|
||||
-- Los pedidos con riesgo no se sacan aunque se asignen.
|
||||
DELETE pb.*
|
||||
|
||||
DELETE pb
|
||||
FROM tmp.productionBuffer pb
|
||||
JOIN state s ON s.id = pb.state
|
||||
WHERE (pb.agency = 'REC_ALGEMESI'
|
||||
AND s.code <> 'PICKER_DESIGNED')
|
||||
OR pb.problem LIKE '%RIESGO%';
|
||||
|
||||
-- Comprobamos si hay tickets asignados. En ese caso, nos centramos
|
||||
-- exclusivamente en esos tickets y los sacamos independientemente
|
||||
-- de problemas o tamaños
|
||||
SELECT COUNT(*) INTO vHasAssignedTickets
|
||||
FROM tmp.productionBuffer pb
|
||||
JOIN state s ON s.id = pb.state
|
||||
WHERE s.code = 'PICKER_DESIGNED'
|
||||
AND pb.workerCode = vWorkerCode;
|
||||
-- Si hay tickets asignados, nos centramos exclusivamente en esos tickets
|
||||
-- y los sacamos independientemente de problemas o tamaños
|
||||
|
||||
-- Se dejan en la tabla tmp.productionBuffer sólo aquellos tickets adecuados
|
||||
IF vHasAssignedTickets THEN
|
||||
DELETE pb.*
|
||||
SELECT EXISTS (
|
||||
SELECT TRUE
|
||||
FROM tmp.productionBuffer pb
|
||||
JOIN state s ON s.id = pb.state
|
||||
WHERE s.code <> 'PICKER_DESIGNED'
|
||||
OR pb.workerCode <> vWorkerCode;
|
||||
WHERE (s.code = 'PICKER_DESIGNED'
|
||||
AND pb.workerCode = vWorkerCode)
|
||||
OR s.code = 'LAST_CALL'
|
||||
) INTO vHasAssignedTickets;
|
||||
|
||||
-- Se dejan en la tabla tmp.productionBuffer sólo aquellos tickets adecuados
|
||||
|
||||
IF vHasAssignedTickets THEN
|
||||
DELETE pb
|
||||
FROM tmp.productionBuffer pb
|
||||
JOIN state s ON s.id = pb.state
|
||||
WHERE (s.code <> 'PICKER_DESIGNED'
|
||||
OR pb.workerCode <> vWorkerCode)
|
||||
AND s.code <> 'LAST_CALL';
|
||||
ELSE
|
||||
DELETE pb.*
|
||||
DELETE pb
|
||||
FROM tmp.productionBuffer pb
|
||||
JOIN state s ON s.id = pb.state
|
||||
JOIN agencyMode am ON am.id = pb.agencyModeFk
|
||||
|
@ -193,26 +166,25 @@ BEGIN
|
|||
OR (NOT pb.H AND pb.V > 0 AND vItemPackingTypeFk = 'H')
|
||||
OR (NOT pb.V AND vItemPackingTypeFk = 'V')
|
||||
OR (pc.isPreviousPreparationRequired AND pb.previousWithoutParking)
|
||||
OR LENGTH(pb.problem) > 0
|
||||
OR LENGTH(pb.problem)
|
||||
OR pb.lines > vLinesLimit
|
||||
OR pb.m3 > vVolumeLimit
|
||||
OR sub.maxSize > vSizeLimit
|
||||
OR pb.hasPlantTray;
|
||||
END IF;
|
||||
|
||||
-- Es importante que el primer ticket se coja en todos los casos
|
||||
SELECT ticketFk,
|
||||
HH,
|
||||
mm,
|
||||
`lines`,
|
||||
m3
|
||||
INTO vFirstTicketFk,
|
||||
vHour,
|
||||
vMinute,
|
||||
vTicketLines,
|
||||
vTicketVolume
|
||||
-- Hay que excluir aquellos que no tengan la misma hora de preparacion, si procede
|
||||
|
||||
IF vHasUniqueCollectionTime THEN
|
||||
DELETE pb
|
||||
FROM tmp.productionBuffer pb
|
||||
JOIN tmp.productionBuffer pb2 ON pb2.ticketFk = vFirstTicketFk
|
||||
AND (pb.HH <> pb2.HH OR pb.mm <> pb2.mm);
|
||||
END IF;
|
||||
|
||||
SELECT ticketFk INTO vFirstTicketFk
|
||||
FROM tmp.productionBuffer
|
||||
ORDER BY HH,
|
||||
ORDER BY HH,
|
||||
mm,
|
||||
productionOrder DESC,
|
||||
m3 DESC,
|
||||
|
@ -222,44 +194,37 @@ BEGIN
|
|||
ticketFk
|
||||
LIMIT 1;
|
||||
|
||||
-- Hay que excluir aquellos que no tengan la misma hora de preparacion, si procede
|
||||
IF vHasUniqueCollectionTime THEN
|
||||
DELETE FROM tmp.productionBuffer
|
||||
WHERE HH <> vHour
|
||||
OR mm <> vMinute;
|
||||
END IF;
|
||||
|
||||
SET vTicketFk = vFirstTicketFk;
|
||||
SET @lines = 0;
|
||||
SET @volume = 0;
|
||||
|
||||
OPEN c1;
|
||||
read_loop: LOOP
|
||||
OPEN vTickets;
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vTickets INTO vTicketFk, vTicketLines, vTicketVolume;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
-- Buscamos un ticket que cumpla con los requisitos en el listado
|
||||
IF ((vTicketLines + @lines) <= vLinesLimit OR vLinesLimit IS NULL)
|
||||
AND ((vTicketVolume + @volume) <= vVolumeLimit OR vVolumeLimit IS NULL) THEN
|
||||
|
||||
IF (vLinesLimit IS NULL OR (vTotalLines + vTicketLines) <= vLinesLimit)
|
||||
AND (vVolumeLimit IS NULL OR (vTotalVolume + vTicketVolume) <= vVolumeLimit) THEN
|
||||
|
||||
CALL ticket_splitItemPackingType(vTicketFk, vItemPackingTypeFk);
|
||||
DROP TEMPORARY TABLE tmp.ticketIPT;
|
||||
|
||||
SELECT COUNT(*), SUM(litros), MAX(i.`size`), SUM(sv.volume)
|
||||
INTO vLines, vLiters, vHeight, vVolume
|
||||
FROM saleVolume sv
|
||||
JOIN sale s ON s.id = sv.saleFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
WHERE sv.ticketFk = vTicketFk;
|
||||
|
||||
SET vTotalVolume = vTotalVolume + vVolume,
|
||||
vTotalLines = vTotalLines + vLines;
|
||||
|
||||
UPDATE tmp.productionBuffer pb
|
||||
JOIN (
|
||||
SELECT SUM(litros) liters,
|
||||
@lines:= COUNT(*) + @lines,
|
||||
COUNT(*) `lines`,
|
||||
MAX(i.`size`) height,
|
||||
@volume := SUM(sv.volume) + @volume,
|
||||
SUM(sv.volume) volume
|
||||
FROM saleVolume sv
|
||||
JOIN sale s ON s.id = sv.saleFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
WHERE sv.ticketFk = vTicketFk
|
||||
) sub
|
||||
SET pb.liters = sub.liters,
|
||||
pb.`lines` = sub.`lines`,
|
||||
pb.height = sub.height
|
||||
SET pb.liters = vLiters,
|
||||
pb.`lines` = vLines,
|
||||
pb.height = vHeight
|
||||
WHERE pb.ticketFk = vTicketFk;
|
||||
|
||||
UPDATE tTrain tt
|
||||
|
@ -276,17 +241,13 @@ BEGIN
|
|||
tt.height
|
||||
LIMIT 1;
|
||||
|
||||
-- Si no le encuentra una balda adecuada, intentamos darle un carro entero si queda alguno libre
|
||||
-- Si no le encuentra una balda, intentamos darle un carro entero libre
|
||||
|
||||
IF NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN
|
||||
SELECT tt.wagon
|
||||
INTO vFreeWagonFk
|
||||
FROM tTrain tt
|
||||
LEFT JOIN (
|
||||
SELECT DISTINCT wagon
|
||||
FROM tTrain
|
||||
WHERE ticketFk IS NOT NULL
|
||||
) nn ON nn.wagon = tt.wagon
|
||||
WHERE nn.wagon IS NULL
|
||||
SELECT wagon INTO vFreeWagonFk
|
||||
FROM tTrain
|
||||
GROUP BY wagon
|
||||
HAVING COUNT(ticketFk) = 0
|
||||
ORDER BY wagon
|
||||
LIMIT 1;
|
||||
|
||||
|
@ -295,38 +256,35 @@ BEGIN
|
|||
SET ticketFk = vFirstTicketFk
|
||||
WHERE wagon = vFreeWagonFk;
|
||||
|
||||
-- Se anulan el resto de carros libres para que sólo uno lleve un pedido excesivo
|
||||
DELETE tt.*
|
||||
FROM tTrain tt
|
||||
LEFT JOIN (
|
||||
SELECT DISTINCT wagon
|
||||
FROM tTrain
|
||||
WHERE ticketFk IS NOT NULL
|
||||
) nn ON nn.wagon = tt.wagon
|
||||
WHERE nn.wagon IS NULL;
|
||||
END IF;
|
||||
END IF;
|
||||
-- Se anulan el resto de carros libres,
|
||||
-- máximo un carro con pedido excesivo
|
||||
|
||||
FETCH c1 INTO vTicketFk, vTicketLines, vTicketVolume;
|
||||
IF vDone OR NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk IS NULL) THEN
|
||||
LEAVE read_loop;
|
||||
END IF;
|
||||
ELSE
|
||||
FETCH c1 INTO vTicketFk, vTicketLines, vTicketVolume;
|
||||
IF vDone THEN
|
||||
LEAVE read_loop;
|
||||
END IF;
|
||||
DELETE tt
|
||||
FROM tTrain tt
|
||||
JOIN (SELECT wagon
|
||||
FROM tTrain
|
||||
GROUP BY wagon
|
||||
HAVING COUNT(ticketFk) = 0
|
||||
) sub ON sub.wagon = tt.wagon;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
END LOOP;
|
||||
CLOSE c1;
|
||||
CLOSE vTickets;
|
||||
|
||||
IF (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN
|
||||
UPDATE collection c
|
||||
JOIN state st ON st.code = 'ON_PREPARATION'
|
||||
SET c.stateFk = st.id
|
||||
WHERE c.id = vCollectionFk;
|
||||
-- Se obtiene nº de colección
|
||||
|
||||
INSERT INTO collection
|
||||
SET itemPackingTypeFk = vItemPackingTypeFk,
|
||||
trainFk = vTrainFk,
|
||||
wagons = vWagons,
|
||||
warehouseFk = vWarehouseFk;
|
||||
|
||||
SELECT LAST_INSERT_ID() INTO vCollectionFk;
|
||||
|
||||
-- Asigna las bandejas
|
||||
|
||||
INSERT IGNORE INTO ticketCollection(ticketFk, collectionFk, `level`, wagon, liters)
|
||||
SELECT tt.ticketFk, vCollectionFk, tt.shelve, tt.wagon, tt.liters
|
||||
FROM tTrain tt
|
||||
|
@ -334,39 +292,36 @@ BEGIN
|
|||
ORDER BY tt.wagon, tt.shelve;
|
||||
|
||||
-- Actualiza el estado de los tickets
|
||||
CALL collection_setState(vCollectionFk, vStateFk);
|
||||
|
||||
CALL collection_setState(vCollectionFk, vStateCode);
|
||||
|
||||
-- Aviso para la preparacion previa
|
||||
|
||||
INSERT INTO ticketDown(ticketFk, collectionFk)
|
||||
SELECT tc.ticketFk, tc.collectionFk
|
||||
FROM ticketCollection tc
|
||||
WHERE tc.collectionFk = vCollectionFk;
|
||||
|
||||
CALL sales_mergeByCollection(vCollectionFk);
|
||||
CALL collection_mergeSales(vCollectionFk);
|
||||
|
||||
UPDATE `collection` c
|
||||
JOIN (
|
||||
JOIN(
|
||||
SELECT COUNT(*) saleTotalCount,
|
||||
SUM(s.isPicked <> 0) salePickedCount
|
||||
FROM ticketCollection tc
|
||||
JOIN sale s ON s.ticketFk = tc.ticketFk
|
||||
WHERE tc.collectionFk = vCollectionFk
|
||||
AND s.quantity > 0
|
||||
) sub
|
||||
WHERE tc.collectionFk = vCollectionFk
|
||||
AND s.quantity > 0
|
||||
)sub
|
||||
SET c.saleTotalCount = sub.saleTotalCount,
|
||||
c.salePickedCount = sub.salePickedCount
|
||||
WHERE c.id = vCollectionFk;
|
||||
|
||||
ELSE
|
||||
DELETE FROM `collection`
|
||||
WHERE id = vCollectionFk;
|
||||
SET vCollectionFk = NULL;
|
||||
SET vCollectionFk = NULL;
|
||||
END IF;
|
||||
|
||||
DO RELEASE_LOCK(vLockName);
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tTrain,
|
||||
tmp.productionBuffer;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
DELIMITER ;
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemMinimumQuantity_check`(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemMinimumQuantity_check`(
|
||||
vSelf INT,
|
||||
vItemFk INT,
|
||||
vStarted DATE,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySaleGroup`(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySaleGroup`(
|
||||
vSaleGroupFk INT(11)
|
||||
)
|
||||
BEGIN
|
||||
|
|
|
@ -15,13 +15,11 @@ proc: BEGIN
|
|||
DECLARE vEndingDate DATETIME;
|
||||
DECLARE vIsTodayRelative BOOLEAN;
|
||||
|
||||
SELECT util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY
|
||||
INTO vEndingDate
|
||||
FROM productionConfig;
|
||||
|
||||
SELECT isTodayRelative INTO vIsTodayRelative
|
||||
FROM worker
|
||||
WHERE id = getUser(); -- Cambiar por account.myUser_getId(), falta dar permisos
|
||||
SELECT w.isTodayRelative, util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, pc.maxProductionScopeDays) DAY
|
||||
INTO vIsTodayRelative,vEndingDate
|
||||
FROM worker w
|
||||
JOIN productionConfig pc
|
||||
WHERE w.id = account.myUser_getId();
|
||||
|
||||
CALL prepareTicketList(util.yesterday(), vEndingDate);
|
||||
|
||||
|
@ -268,15 +266,14 @@ proc: BEGIN
|
|||
UPDATE tmp.productionBuffer pb
|
||||
JOIN sale s ON s.ticketFk = pb.ticketFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN cache.last_buy lb ON lb.warehouse_id = vWarehouseFk
|
||||
JOIN cache.last_buy lb ON lb.warehouse_id = vWarehouseFk
|
||||
AND lb.item_id = s.itemFk
|
||||
JOIN buy b ON b.id = lb.buy_id
|
||||
JOIN packaging p ON p.id = b.packagingFk
|
||||
JOIN productionConfig pc
|
||||
SET pb.hasPlantTray = TRUE
|
||||
WHERE p.isPlantTray
|
||||
AND s.quantity >= b.packing
|
||||
AND pb.isOwn;
|
||||
AND pb.isOwn;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.productionTicket,
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`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 ;
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE vn.supplier_statementWithEntries(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE vn.supplier_statementWithEntries(
|
||||
vSupplierFk INT,
|
||||
vCurrencyFk INT,
|
||||
vCompanyFk INT,
|
||||
|
|
|
@ -1,14 +1,27 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_mergeSales`(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_mergeSales`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Para un ticket se agrupa las diferentes líneas de venta de un mismo artículo en una sola
|
||||
* siempre y cuando tengan el mismo precio y dto.
|
||||
*
|
||||
* @param vSelf Id de ticket
|
||||
*/
|
||||
DECLARE vHasSalesToMerge BOOL;
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
SELECT id INTO vSelf
|
||||
FROM ticket
|
||||
WHERE id = vSelf FOR UPDATE;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve
|
||||
(PRIMARY KEY (id))
|
||||
ENGINE = MEMORY
|
||||
|
@ -18,26 +31,24 @@ BEGIN
|
|||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE s.ticketFk = vSelf
|
||||
AND it.isMergeable
|
||||
GROUP BY s.itemFk, s.price, s.discount;
|
||||
GROUP BY s.itemFk, s.price, s.discount
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
START TRANSACTION;
|
||||
SELECT COUNT(*) INTO vHasSalesToMerge FROM tSalesToPreserve;
|
||||
|
||||
UPDATE sale s
|
||||
JOIN tSalesToPreserve stp ON stp.id = s.id
|
||||
SET s.quantity = newQuantity
|
||||
WHERE s.ticketFk = vSelf;
|
||||
IF vHasSalesToMerge THEN
|
||||
UPDATE sale s
|
||||
JOIN tSalesToPreserve stp ON stp.id = s.id
|
||||
SET s.quantity = newQuantity;
|
||||
|
||||
DELETE s.*
|
||||
FROM sale s
|
||||
LEFT JOIN tSalesToPreserve stp ON stp.id = s.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE s.ticketFk = vSelf
|
||||
AND stp.id IS NULL
|
||||
AND it.isMergeable;
|
||||
DELETE s
|
||||
FROM sale s
|
||||
JOIN tSalesToPreserve stp ON stp.itemFk = s.itemFk
|
||||
WHERE s.ticketFk = vSelf
|
||||
AND s.id <> stp.id;
|
||||
END IF;
|
||||
|
||||
COMMIT;
|
||||
|
||||
DROP TEMPORARY TABLE tSalesToPreserve;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRiskByClient`(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setProblemRiskByClient`(
|
||||
vClientFk INT
|
||||
)
|
||||
BEGIN
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolume`(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setVolume`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`(
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`(
|
||||
vItemFk INT
|
||||
)
|
||||
BEGIN
|
||||
|
|
|
@ -3,124 +3,87 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_splitItemPacki
|
|||
vSelf INT,
|
||||
vOriginalItemPackingTypeFk VARCHAR(1)
|
||||
)
|
||||
BEGIN
|
||||
proc:BEGIN
|
||||
/**
|
||||
* Clona y reparte las ventas de un ticket en funcion del tipo de empaquetado.
|
||||
* Respeta el id inicial para el tipo propuesto.
|
||||
* Clona y reparte las líneas de ventas de un ticket en funcion del tipo de empaquetado.
|
||||
* Respeta el id de ticket original para el tipo de empaquetado propuesto.
|
||||
*
|
||||
* @param vSelf Id ticket
|
||||
* @param vOriginalItemPackingTypeFk Tipo para el que se reserva el número de ticket original
|
||||
* @param vOriginalItemPackingTypeFk Tipo empaquetado que se mantiene el ticket original
|
||||
* @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||
*/
|
||||
DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H';
|
||||
DECLARE vNewTicketFk INT;
|
||||
DECLARE vPackingTypesToSplit INT;
|
||||
DECLARE vDone INT DEFAULT FALSE;
|
||||
DECLARE vHasItemPackingType BOOL;
|
||||
DECLARE vItemPackingTypeFk INT;
|
||||
DECLARE vNewTicketFk INT;
|
||||
|
||||
DECLARE vSaleGroup CURSOR FOR
|
||||
SELECT itemPackingTypeFk
|
||||
FROM tSaleGroup
|
||||
WHERE itemPackingTypeFk IS NOT NULL
|
||||
ORDER BY (itemPackingTypeFk = vOriginalItemPackingTypeFk) DESC;
|
||||
DECLARE vItemPackingTypes CURSOR FOR
|
||||
SELECT DISTINCT itemPackingTypeFk
|
||||
FROM tSalesToMove;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
SELECT id
|
||||
FROM sale
|
||||
WHERE ticketFk = vSelf
|
||||
AND NOT quantity
|
||||
FOR UPDATE;
|
||||
|
||||
DELETE FROM sale
|
||||
WHERE NOT quantity
|
||||
AND ticketFk = vSelf;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tSale
|
||||
(PRIMARY KEY (id))
|
||||
ENGINE = MEMORY
|
||||
SELECT s.id, i.itemPackingTypeFk, IFNULL(sv.litros, 0) litros
|
||||
FROM sale s
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
LEFT JOIN saleVolume sv ON sv.saleFk = s.id
|
||||
WHERE s.ticketFk = vSelf;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tSaleGroup
|
||||
ENGINE = MEMORY
|
||||
SELECT itemPackingTypeFk, SUM(litros) totalLitros
|
||||
FROM tSale
|
||||
GROUP BY itemPackingTypeFk;
|
||||
|
||||
SELECT COUNT(*) INTO vPackingTypesToSplit
|
||||
FROM tSaleGroup
|
||||
WHERE itemPackingTypeFk IS NOT NULL;
|
||||
SELECT COUNT(*) INTO vHasItemPackingType
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
WHERE t.id = vSelf
|
||||
AND i.itemPackingTypeFk = vOriginalItemPackingTypeFk;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT(
|
||||
ticketFk INT,
|
||||
itemPackingTypeFk VARCHAR(1)
|
||||
) ENGINE = MEMORY;
|
||||
) ENGINE=MEMORY
|
||||
SELECT vSelf ticketFk, vOriginalItemPackingTypeFk itemPackingTypeFk;
|
||||
|
||||
CASE vPackingTypesToSplit
|
||||
WHEN 0 THEN
|
||||
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||
VALUES(vSelf, vItemPackingTypeFk);
|
||||
WHEN 1 THEN
|
||||
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||
SELECT vSelf, itemPackingTypeFk
|
||||
FROM tSaleGroup
|
||||
WHERE itemPackingTypeFk IS NOT NULL;
|
||||
ELSE
|
||||
OPEN vSaleGroup;
|
||||
FETCH vSaleGroup INTO vItemPackingTypeFk;
|
||||
IF NOT vHasItemPackingType THEN
|
||||
LEAVE proc;
|
||||
END IF;
|
||||
|
||||
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||
VALUES(vSelf, vItemPackingTypeFk);
|
||||
CREATE OR REPLACE TEMPORARY TABLE tSalesToMove (
|
||||
ticketFk INT,
|
||||
saleFk INT,
|
||||
itemPackingTypeFk INT
|
||||
) ENGINE=MEMORY;
|
||||
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vSaleGroup INTO vItemPackingTypeFk;
|
||||
INSERT INTO tSalesToMove (saleFk, itemPackingTypeFk)
|
||||
SELECT s.id, i.itemPackingTypeFk
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
WHERE t.id = vSelf
|
||||
AND i.itemPackingTypeFk <> vOriginalItemPackingTypeFk;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
OPEN vItemPackingTypes;
|
||||
|
||||
CALL ticket_Clone(vSelf, vNewTicketFk);
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vItemPackingTypes INTO vItemPackingTypeFk;
|
||||
|
||||
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||
VALUES(vNewTicketFk, vItemPackingTypeFk);
|
||||
END LOOP;
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
CLOSE vSaleGroup;
|
||||
CALL ticket_Clone(vSelf, vNewTicketFk);
|
||||
|
||||
SELECT s.id
|
||||
FROM sale s
|
||||
JOIN tSale ts ON ts.id = s.id
|
||||
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk
|
||||
FOR UPDATE;
|
||||
UPDATE tSalesToMove
|
||||
SET ticketFk = vNewTicketFk
|
||||
WHERE itemPackingTypeFk = vItemPackingTypeFk;
|
||||
|
||||
UPDATE sale s
|
||||
JOIN tSale ts ON ts.id = s.id
|
||||
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk
|
||||
SET s.ticketFk = t.ticketFk;
|
||||
END LOOP;
|
||||
|
||||
SELECT itemPackingTypeFk INTO vItemPackingTypeFk
|
||||
FROM tSaleGroup sg
|
||||
WHERE sg.itemPackingTypeFk IS NOT NULL
|
||||
ORDER BY sg.itemPackingTypeFk
|
||||
LIMIT 1;
|
||||
CLOSE vItemPackingTypes;
|
||||
|
||||
UPDATE sale s
|
||||
JOIN tSale ts ON ts.id = s.id
|
||||
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk
|
||||
SET s.ticketFk = t.ticketFk
|
||||
WHERE ts.itemPackingTypeFk IS NULL;
|
||||
END CASE;
|
||||
UPDATE sale s
|
||||
JOIN tSalesToMove stm ON stm.saleFk = s.id
|
||||
SET s.ticketFk = stm.ticketFk
|
||||
WHERE stm.ticketFk;
|
||||
|
||||
COMMIT;
|
||||
INSERT INTO tmp.ticketIPT (ticketFk, itemPackingTypeFk)
|
||||
SELECT ticketFk, itemPackingTypeFk
|
||||
FROM tSalesToMove
|
||||
GROUP BY ticketFk;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tSale,
|
||||
tSaleGroup;
|
||||
DROP TEMPORARY TABLE tSalesToMove;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert`
|
||||
AFTER INSERT ON `itemShelving`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO itemShelvingLog
|
||||
SET itemShelvingFk = NEW.id,
|
||||
workerFk = account.myUser_getId(),
|
||||
accion = 'CREA REGISTRO',
|
||||
itemFk = NEW.itemFk,
|
||||
shelvingFk = NEW.shelvingFk,
|
||||
visible = NEW.visible,
|
||||
`grouping` = NEW.`grouping`,
|
||||
packing = NEW.packing,
|
||||
available = NEW.available;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,5 +1,5 @@
|
|||
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`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
|
|
|
@ -2,12 +2,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
|||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`buyer`
|
||||
AS SELECT DISTINCT `u`.`id` AS `userFk`,
|
||||
`u`.`nickname` AS `nickname`,
|
||||
`ic`.`display` AS `display`
|
||||
`u`.`nickname` AS `nickname`
|
||||
FROM (
|
||||
`account`.`user` `u`
|
||||
JOIN `vn`.`itemType` `it` ON(`it`.`workerFk` = `u`.`id`)
|
||||
JOIN `vn`.`itemCategory` `ic` ON(`ic`.`id` = `it`.`categoryFk`)
|
||||
)
|
||||
WHERE `u`.`active` <> 0
|
||||
ORDER BY `u`.`nickname`
|
||||
|
|
|
@ -13,6 +13,5 @@ AS SELECT `am`.`id` AS `Id_Agencia`,
|
|||
`am`.`reportMail` AS `send_mail`,
|
||||
`am`.`isActive` AS `tpv`,
|
||||
`am`.`code` AS `code`,
|
||||
`am`.`showAgencyName` AS `show_AgencyName`,
|
||||
`am`.`isRiskFree` AS `isRiskFree`
|
||||
FROM `vn`.`agencyMode` `am`
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
-- 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');
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE vn.agencyMode
|
||||
CHANGE IF EXISTS showAgencyName showAgencyName__ tinyint(1) DEFAULT 1 COMMENT '@deprecated 2024-09-24';
|
|
@ -0,0 +1,31 @@
|
|||
-- vn.priceDelta definition
|
||||
|
||||
CREATE OR REPLACE TABLE vn.priceDelta (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`itemTypeFk` smallint(5) unsigned NOT NULL,
|
||||
`minSize` int(10) unsigned DEFAULT NULL COMMENT 'Minimum item.size',
|
||||
`maxSize` int(10) unsigned DEFAULT NULL COMMENT 'Maximum item.size',
|
||||
`inkFk` varchar(3) DEFAULT NULL,
|
||||
`originFk` tinyint(2) unsigned DEFAULT NULL,
|
||||
`producerFk` mediumint(3) unsigned DEFAULT NULL,
|
||||
`fromDated` date DEFAULT NULL,
|
||||
`toDated` date DEFAULT NULL,
|
||||
`absIncreasing` decimal(10,3) DEFAULT NULL COMMENT 'Absolute increasing of final price',
|
||||
`ratIncreasing` int(11) DEFAULT NULL COMMENT 'Increasing ratio for the cost price',
|
||||
`warehouseFk` smallint(6) unsigned NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`editorFk` int(10) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `priceDelta_itemType_FK` (`itemTypeFk`),
|
||||
KEY `priceDelta_ink_FK` (`inkFk`),
|
||||
KEY `priceDelta_producer_FK` (`producerFk`),
|
||||
KEY `priceDelta_warehouse_FK` (`warehouseFk`),
|
||||
KEY `priceDelta_worker_FK` (`editorFk`),
|
||||
CONSTRAINT `priceDelta_ink_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_itemType_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_producer_FK` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_warehouse_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_worker_FK` FOREIGN KEY (`editorFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Defines the increasing o decreasing for ranges of items';
|
||||
|
||||
GRANT INSERT, SELECT, UPDATE, DELETE ON TABLE vn.priceDelta TO buyer;
|
|
@ -0,0 +1,32 @@
|
|||
-- Place your SQL code here
|
||||
-- vn.priceDelta definition
|
||||
|
||||
CREATE OR REPLACE TABLE vn.priceDelta (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`itemTypeFk` smallint(5) unsigned NOT NULL,
|
||||
`minSize` int(10) unsigned DEFAULT NULL COMMENT 'Minimum item.size',
|
||||
`maxSize` int(10) unsigned DEFAULT NULL COMMENT 'Maximum item.size',
|
||||
`inkFk` varchar(3) DEFAULT NULL,
|
||||
`originFk` tinyint(2) unsigned DEFAULT NULL,
|
||||
`producerFk` mediumint(3) unsigned DEFAULT NULL,
|
||||
`fromDated` date DEFAULT NULL,
|
||||
`toDated` date DEFAULT NULL,
|
||||
`absIncreasing` decimal(10,3) DEFAULT NULL COMMENT 'Absolute increasing of final price',
|
||||
`ratIncreasing` int(11) DEFAULT NULL COMMENT 'Increasing ratio for the cost price',
|
||||
`warehouseFk` smallint(6) unsigned NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`editorFk` int(10) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `priceDelta_itemType_FK` (`itemTypeFk`),
|
||||
KEY `priceDelta_ink_FK` (`inkFk`),
|
||||
KEY `priceDelta_producer_FK` (`producerFk`),
|
||||
KEY `priceDelta_warehouse_FK` (`warehouseFk`),
|
||||
KEY `priceDelta_worker_FK` (`editorFk`),
|
||||
CONSTRAINT `priceDelta_ink_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_itemType_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_producer_FK` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_warehouse_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `priceDelta_worker_FK` FOREIGN KEY (`editorFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Defines the increasing o decreasing for ranges of items';
|
||||
|
||||
GRANT INSERT, SELECT, UPDATE, DELETE ON TABLE vn.priceDelta TO buyer;
|
|
@ -0,0 +1,3 @@
|
|||
-- Place your SQL code here
|
||||
ALTER TABLE vn.priceDelta ADD IF NOT EXISTS zoneGeoFk int(11) NULL COMMENT 'Application area for the bonus component';
|
||||
ALTER TABLE vn.priceDelta ADD CONSTRAINT priceDelta_zoneGeo_FK FOREIGN KEY IF NOT EXISTS (zoneGeoFk) REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -57,7 +57,7 @@ export default class App {
|
|||
|
||||
getUrl(route, appName = 'lilium') {
|
||||
const index = window.location.hash.indexOf(route.toLowerCase());
|
||||
const newRoute = index < 0 ? route : window.location.hash.substring(index);
|
||||
let newRoute = index < 0 ? route : window.location.hash.substring(index);
|
||||
const env = process.env.NODE_ENV;
|
||||
const filter = {
|
||||
where: {and: [
|
||||
|
@ -66,6 +66,11 @@ export default class App {
|
|||
]}
|
||||
};
|
||||
|
||||
|
||||
if (this.logger.$params.q)
|
||||
newRoute = newRoute.concat(`?table=${this.logger.$params.q}`);
|
||||
|
||||
|
||||
return this.logger.$http.get('Urls/findOne', {filter})
|
||||
.then(res => {
|
||||
if (res && res.data)
|
||||
|
|
|
@ -235,10 +235,10 @@
|
|||
"Cannot add holidays on this day": "Cannot add holidays on this day",
|
||||
"Cannot send mail": "Cannot send mail",
|
||||
"CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`",
|
||||
"This postcode already exists": "This postcode already exists",
|
||||
"Original invoice not found": "Original invoice not found",
|
||||
"There is already a tray with the same height": "There is already a tray with the same height",
|
||||
"The height must be greater than 50cm": "The height must be greater than 50cm",
|
||||
"The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm",
|
||||
"This postcode already exists": "This postcode already exists",
|
||||
"This buyer has already made a reservation for this date": "This buyer has already made a reservation for this date"
|
||||
}
|
||||
"The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line"
|
||||
}
|
||||
|
|
|
@ -366,9 +366,11 @@
|
|||
"The invoices have been created but the PDFs could not be generated": "Se ha facturado pero no se ha podido generar el PDF",
|
||||
"It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono",
|
||||
"Payment method is required": "El método de pago es obligatorio",
|
||||
"Cannot send mail": "No se ha podido enviar el correo",
|
||||
"Cannot send mail": "Não é possível enviar o email",
|
||||
"CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos",
|
||||
"The sale not exists in the item shelving": "La venta no existe en la estantería del artículo",
|
||||
"The entry not have stickers": "La entrada no tiene etiquetas",
|
||||
"Too many records": "Demasiados registros",
|
||||
"Original invoice not found": "Factura original no encontrada",
|
||||
"The entry has no lines or does not exist": "La entrada no tiene lineas o no existe",
|
||||
"Weight already set": "El peso ya está establecido",
|
||||
|
@ -377,7 +379,7 @@
|
|||
"The height must be greater than 50cm": "La altura debe ser superior a 50cm",
|
||||
"The maximum height of the wagon is 200cm": "La altura máxima es 200cm",
|
||||
"The entry does not have stickers": "La entrada no tiene etiquetas",
|
||||
"Too many records": "Demasiados registros",
|
||||
"This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha",
|
||||
"No valid travel thermograph found": "No se encontró un termógrafo válido"
|
||||
"No valid travel thermograph found": "No se encontró un termógrafo válido",
|
||||
"The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea"
|
||||
}
|
||||
|
|
|
@ -361,6 +361,6 @@
|
|||
"The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré",
|
||||
"It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré",
|
||||
"Cannot send mail": "Impossible d'envoyer le mail",
|
||||
"Original invoice not found": "Facture originale introuvable"
|
||||
|
||||
"Original invoice not found": "Facture originale introuvable",
|
||||
"The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne"
|
||||
}
|
||||
|
|
|
@ -361,5 +361,6 @@
|
|||
"The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado",
|
||||
"It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso",
|
||||
"Original invoice not found": "Fatura original não encontrada",
|
||||
"Cannot send mail": "Não é possível enviar o email"
|
||||
"Cannot send mail": "Não é possível enviar o email",
|
||||
"The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
const ForbiddenError = require('vn-loopback/util/forbiddenError');
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.rewriteDbError(function(err) {
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('ClaimBeginning model()', () => {
|
||||
const claimFk = 1;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 18},
|
||||
headers: {origin: 'localhost:5000'},
|
||||
__: () => {}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
});
|
||||
|
||||
it('should change quantity claimed', async() => {
|
||||
const tx = await models.ClaimBeginning.beginTransaction({});
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const claim = await models.ClaimBeginning.findOne({where: {claimFk}}, options);
|
||||
const sale = await models.Sale.findById(claim.saleFk, {}, options);
|
||||
await claim.updateAttribute('quantity', sale.quantity - 1, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should throw error when quantity claimed is greater than quantity of the sale', async() => {
|
||||
const tx = await models.ClaimBeginning.beginTransaction({});
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const claim = await models.ClaimBeginning.findOne({where: {claimFk}}, options);
|
||||
const sale = await models.Sale.findById(claim.saleFk, {}, options);
|
||||
await claim.updateAttribute('quantity', sale.quantity + 1, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.toString()).toContain('The quantity claimed cannot be greater than the quantity of the line');
|
||||
});
|
||||
});
|
|
@ -10,16 +10,21 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.observe('before save', async ctx => {
|
||||
const options = ctx.options;
|
||||
const models = Self.app.models;
|
||||
const saleFk = ctx?.currentInstance?.saleFk || ctx?.instance?.saleFk;
|
||||
const sale = await models.Sale.findById(saleFk, {fields: ['ticketFk', 'quantity']}, options);
|
||||
|
||||
if (ctx.isNewInstance) {
|
||||
const models = Self.app.models;
|
||||
const options = ctx.options;
|
||||
const instance = ctx.instance;
|
||||
const ticket = await models.Sale.findById(instance.saleFk, {fields: ['ticketFk']}, options);
|
||||
const claim = await models.Claim.findById(instance.claimFk, {fields: ['ticketFk']}, options);
|
||||
if (ticket.ticketFk != claim.ticketFk)
|
||||
const claim = await models.Claim.findById(ctx.instance.claimFk, {fields: ['ticketFk']}, options);
|
||||
if (sale.ticketFk != claim.ticketFk)
|
||||
throw new UserError(`Cannot create a new claimBeginning from a different ticket`);
|
||||
}
|
||||
|
||||
await claimIsEditable(ctx);
|
||||
|
||||
if (sale?.quantity && ctx.data?.quantity && ctx.data.quantity > sale?.quantity)
|
||||
throw new UserError('The quantity claimed cannot be greater than the quantity of the line');
|
||||
});
|
||||
|
||||
Self.observe('before delete', async ctx => {
|
||||
|
|
|
@ -52,7 +52,7 @@ module.exports = Self => {
|
|||
await merger.add(new Uint8Array(pdfBuffer[0]));
|
||||
}
|
||||
|
||||
if (!merger._doc) throw new UserError('The entry does not have stickers');
|
||||
if (!merger._doc) throw new UserError('The entry not have stickers');
|
||||
|
||||
await Self.rawSql(`
|
||||
UPDATE buy
|
||||
|
|
|
@ -39,7 +39,7 @@ describe('Entry filter()', () => {
|
|||
|
||||
const result = await models.Entry.filter(ctx, options);
|
||||
|
||||
expect(result.length).toEqual(12);
|
||||
expect(result.length).toEqual(11);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
@ -131,7 +131,7 @@ describe('Entry filter()', () => {
|
|||
|
||||
const result = await models.Entry.filter(ctx, options);
|
||||
|
||||
expect(result.length).toEqual(11);
|
||||
expect(result.length).toEqual(10);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
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);
|
||||
};
|
||||
};
|
|
@ -1,74 +0,0 @@
|
|||
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;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -25,8 +25,5 @@
|
|||
},
|
||||
"EntryType": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"StockBought": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
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;
|
||||
});
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,7 +64,7 @@ module.exports = Self => {
|
|||
try {
|
||||
const client = await models.Client.findById(args.clientId, {
|
||||
fields: ['id', 'hasToInvoiceByAddress']
|
||||
}, options);
|
||||
}, myOptions);
|
||||
|
||||
if (client.hasToInvoiceByAddress) {
|
||||
await Self.rawSql('CALL ticketToInvoiceByAddress(?, ?, ?, ?)', [
|
||||
|
@ -72,13 +72,13 @@ module.exports = Self => {
|
|||
args.maxShipped,
|
||||
args.addressId,
|
||||
args.companyFk
|
||||
], options);
|
||||
], myOptions);
|
||||
} else {
|
||||
await Self.rawSql('CALL invoiceFromClient(?, ?, ?)', [
|
||||
args.maxShipped,
|
||||
client.id,
|
||||
args.companyFk
|
||||
], options);
|
||||
], myOptions);
|
||||
}
|
||||
|
||||
const invoiceId = await models.Ticket.makeInvoice(
|
||||
|
@ -87,7 +87,7 @@ module.exports = Self => {
|
|||
args.companyFk,
|
||||
args.invoiceDate,
|
||||
null,
|
||||
options
|
||||
myOptions
|
||||
);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
|
|
@ -38,9 +38,13 @@ module.exports = Self => {
|
|||
|
||||
const itemShelving = itemShelvingSale.itemShelving();
|
||||
const quantity = itemShelving.visible + itemShelvingSale.quantity;
|
||||
const available = itemShelving.available + itemShelvingSale.quantity;
|
||||
|
||||
await itemShelving.updateAttributes(
|
||||
{visible: quantity},
|
||||
{
|
||||
visible: quantity,
|
||||
available: available
|
||||
},
|
||||
myOptions
|
||||
);
|
||||
if (tx) await tx.commit();
|
||||
|
|
|
@ -75,7 +75,11 @@ module.exports = Self => {
|
|||
|
||||
const itemShelving = await models.ItemShelving.findById(itemShelvingFk, null, myOptions);
|
||||
|
||||
await itemShelving.updateAttributes({visible: itemShelving.visible - quantity}, myOptions);
|
||||
await itemShelving.updateAttributes(
|
||||
{
|
||||
visible: itemShelving.visible - quantity,
|
||||
available: itemShelving.available - quantity
|
||||
}, myOptions);
|
||||
|
||||
await Self.updateAll(
|
||||
{saleFk},
|
||||
|
|
|
@ -82,7 +82,7 @@ module.exports = Self => {
|
|||
const getDataOperator = await models.Operator.findOne({
|
||||
where: {workerFk: user.id},
|
||||
fields: ['numberOfWagons', 'warehouseFk', 'itemPackingTypeFk', 'sectorFk', 'sector',
|
||||
'trainFk', 'train', 'labelerFk', 'printer'],
|
||||
'trainFk', 'train', 'labelerFk', 'printer', 'isOnReservationMode'],
|
||||
include: [
|
||||
{
|
||||
relation: 'sector',
|
||||
|
|
Loading…
Reference in New Issue