diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql index 2e5982c82..9946b0b73 100644 --- a/db/routines/vn/procedures/zone_getAddresses.sql +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -1,26 +1,27 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( vSelf INT, - vShipped DATE, + vLanded DATE, vDepartmentFk INT ) BEGIN /** * Devuelve un listado de todos los clientes activos * con consignatarios a los que se les puede - * vender producto para esa zona. + * entregar producto para esa zona. * * @param vSelf Id de zona - * @param vShipped Fecha de envio - * @param vDepartmentFk Id de departamento + * @param vLanded Fecha de entrega + * @param vDepartmentFk Id de departamento | NULL para mostrar todos * @return Un select */ CALL zone_getPostalCode(vSelf); WITH clientWithTicket AS ( - SELECT clientFk + SELECT DISTINCT clientFk FROM vn.ticket - WHERE shipped BETWEEN vShipped AND util.dayEnd(vShipped) + WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded) + AND NOT isDeleted ) SELECT c.id, c.name, @@ -30,7 +31,7 @@ BEGIN u.name username, aai.invoiced, cnb.lastShipped, - cwt.clientFk + IF(cwt.clientFk, TRUE, FALSE) hasTicket FROM vn.client c JOIN vn.worker w ON w.id = c.salesPersonFk JOIN vn.workerDepartment wd ON wd.workerFk = w.id @@ -50,7 +51,7 @@ BEGIN AND c.isActive AND ct.code = 'normal' AND bt.code <> 'worker' - AND (d.id = vDepartmentFk OR NOT vDepartmentFk) + AND (d.id = vDepartmentFk OR vDepartmentFk IS NULL) GROUP BY c.id; DROP TEMPORARY TABLE tmp.zoneNodes; diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index 5359ce4a7..cf8bd855a 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -94,7 +94,7 @@ module.exports = Self => { AND r1.started = r2.maxStarted ) r ON r.clientFk = c.id LEFT JOIN workerDepartment wd ON wd.workerFk = u.id - JOIN department dp ON dp.id = wd.departmentFk + LEFT JOIN department dp ON dp.id = wd.departmentFk WHERE d.created = ? AND d.amount > 0 diff --git a/modules/client/back/models/client-credit.json b/modules/client/back/models/client-credit.json index b92639b80..b57374dc3 100644 --- a/modules/client/back/models/client-credit.json +++ b/modules/client/back/models/client-credit.json @@ -19,6 +19,9 @@ }, "created": { "type": "date" + }, + "workerFk": { + "type": "number" } }, "relations": { @@ -33,4 +36,4 @@ "foreignKey": "workerFk" } } -} \ No newline at end of file +} diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js index f66221409..78fce348e 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js @@ -74,7 +74,8 @@ module.exports = Self => { AND t.companyFk = ? AND NOT t.isDeleted GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id) - HAVING SUM(t.totalWithVat) > 0;`; + HAVING SUM(t.totalWithVat) > 0 + ORDER BY c.id`; const addresses = await Self.rawSql(query, [ minShipped, diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index 30c1a45fa..837e30b30 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/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; @@ -91,6 +90,11 @@ module.exports = Self => { arg: 'landed', type: 'date', description: 'The landed date' + }, + { + arg: 'awbFk', + type: 'number', + description: 'The awbFk id' } ], returns: { @@ -168,14 +172,17 @@ module.exports = Self => { t.totalEntries, t.isRaid, t.daysInForward, + t.awbFk, am.name agencyModeName, + a.code awbCode, win.name warehouseInName, wout.name warehouseOutName, cnt.code continent - FROM vn.travel t - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - JOIN vn.warehouse win ON win.id = t.warehouseInFk - JOIN vn.warehouse wout ON wout.id = t.warehouseOutFk + FROM travel t + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN warehouse win ON win.id = t.warehouseInFk + JOIN warehouse wout ON wout.id = t.warehouseOutFk + LEFT JOIN awb a ON a.id = t.awbFk JOIN warehouse wo ON wo.id = t.warehouseOutFk JOIN country c ON c.id = wo.countryFk LEFT JOIN continent cnt ON cnt.id = c.continentFk) AS t`