diff --git a/db/routines/vn/procedures/stockBuyedByWorker.sql b/db/routines/vn/procedures/stockBuyedByWorker.sql new file mode 100644 index 000000000..536638770 --- /dev/null +++ b/db/routines/vn/procedures/stockBuyedByWorker.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockBuyedByWorker`( + vDated DATE, + vWorker INT +) +BEGIN +/** + * Inserta el volumen de compra de un comprador + * en stockBuyed de acuerdo con la fecha. + * + * @param vDated Fecha de compra + * @param vWorker Id de trabajador + */ + CREATE OR REPLACE TEMPORARY TABLE tStockBuyed + (INDEX (userFk)) + ENGINE = MEMORY + SELECT requested, reserved, userFk + FROM stockBuyed + WHERE dated = vDated + AND userFk = vWorker; + + DELETE FROM stockBuyed + WHERE dated = vDated + AND userFk = vWorker; + + CALL item_calculateStock(vDated); + + INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description) + SELECT it.workerFk, + SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000, + vDated, + sb.reserved, + sb.requested, + u.name + 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 + JOIN account.`user` u ON u.id = it.workerFk + LEFT JOIN tStockBuyed sb ON sb.userFk = it.workerFk + WHERE ic.display + AND it.workerFk = vWorker; + + SELECT b.entryFk Id_Entrada, + i.id Id_Article, + i.name Article, + ti.quantity Cantidad, + (ac.conversionCoefficient * (ti.quantity / b.packing) * buy_getVolume(b.id)) + / (vc.trolleyM3 * 1000000) buyed, + b.packagingFk id_cubo, + 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 = vWorker; + + DROP TEMPORARY TABLE tmp.buyUltimate, + tmp.item, + tStockBuyed; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/stockBuyed_add.sql b/db/routines/vn/procedures/stockBuyed_add.sql new file mode 100644 index 000000000..0491c2424 --- /dev/null +++ b/db/routines/vn/procedures/stockBuyed_add.sql @@ -0,0 +1,70 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockBuyed_add`( + vDated DATE +) +BEGIN +/** + * Inserta el volumen de compra por comprador + * en stockBuyed de acuerdo con la fecha. + * + * @param vDated Fecha de compra + */ + CREATE OR REPLACE TEMPORARY TABLE tStockBuyed + (INDEX (userFk)) + ENGINE = MEMORY + SELECT requested, reserved, userFk + FROM stockBuyed + WHERE dated = vDated; + + DELETE FROM stockBuyed WHERE dated = vDated; + + CALL item_calculateStock(vDated); + + INSERT INTO stockBuyed(userFk, buyed, `dated`, description) + SELECT it.workerFk, + SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000, + vDated, + u.name + 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 + JOIN account.`user` u ON u.id = it.workerFk + JOIN workerDepartment wd ON wd.workerFk = u.id + JOIN department d ON d.id = wd.departmentFk + WHERE ic.display + AND d.code IN ('shopping', 'logistic', 'franceTeam') + GROUP BY it.workerFk; + + INSERT INTO stockBuyed(buyed, dated, description) + SELECT SUM(ic.cm3 * ito.quantity / vc.palletM3 / 1000000), + vDated, + IF(c.code = 'ES', p.name, c.name) destiny + FROM itemTicketOut ito + JOIN ticket t ON t.id = ito.ticketFk + JOIN `address` a ON a.id = t.addressFk + JOIN province p ON p.id = a.provinceFk + JOIN country c ON c.id = p.countryFk + JOIN warehouse wh ON wh.id = t.warehouseFk + JOIN itemCost ic ON ic.itemFk = ito.itemFk + AND ic.warehouseFk = t.warehouseFk + JOIN volumeConfig vc + WHERE ito.shipped BETWEEN vDated AND util.dayend(vDated) + AND wh.code = 'VNH' + GROUP BY destiny; + + UPDATE stockBuyed s + JOIN tStockBuyed ts ON ts.userFk = s.userFk + SET s.requested = ts.requested, + s.reserved = ts.reserved + WHERE s.dated = vDated; + + DROP TEMPORARY TABLE tmp.buyUltimate, + tmp.item, + tStockBuyed; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11338-brownMonstera/00-firstScript.sql b/db/versions/11338-brownMonstera/00-firstScript.sql new file mode 100644 index 000000000..9752bb90d --- /dev/null +++ b/db/versions/11338-brownMonstera/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +RENAME TABLE vn.stockBuyed__ TO vn.stockBuyed; diff --git a/front/core/services/app.js b/front/core/services/app.js index dba6e70bf..816167835 100644 --- a/front/core/services/app.js +++ b/front/core/services/app.js @@ -70,10 +70,18 @@ export default class App { if (this.logger.$params.q) { let tableValue = this.logger.$params.q; - const q = JSON.parse(tableValue); - if (typeof q === 'number') - tableValue = JSON.stringify({id: tableValue}); - newRoute = newRoute.concat(`?table=${tableValue}`); + if (Array.isArray(tableValue)) { + const [key, param1, param2] = tableValue; + const payload = key === 'createForm' + ? {[param1]: param2} + : {[key]: param1}; + newRoute += `?${key}=${JSON.stringify(payload)}`; + } else { + const q = JSON.parse(tableValue); + if (typeof q === 'number') + tableValue = JSON.stringify({id: tableValue}); + newRoute = newRoute.concat(`?table=${tableValue}`); + } } else if (!hasId && this.logger.$params.id && newRoute.indexOf(this.logger.$params.id) < 0) newRoute = newRoute.concat(`${this.logger.$params.id}`); diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index f805c4be9..7df973f19 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -1,4 +1,3 @@ - const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index f2dbd64b6..cecd7ee62 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -99,7 +99,7 @@
diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index 758e8065c..f8df6e10e 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -76,6 +76,7 @@ module.exports = Self => { }); Self.filter = async(ctx, filter, options) => { + const models = Self.app.models; const conn = Self.dataSource.connector; const myOptions = {}; diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index 30910fa46..ad3fb1e2c 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -117,7 +117,6 @@ module.exports = Self => { case 'landedTo': return {'t.landed': {lte: value}}; case 'daysOnward': - today.setHours(0, 0, 0, 0); future.setDate(today.getDate() + value); future.setHours(23, 59, 59, 999);