diff --git a/db/changes/10210-summer/00-ticket_close.sql b/db/changes/10210-summer/00-ticket_close.sql new file mode 100644 index 000000000..96f9c5528 --- /dev/null +++ b/db/changes/10210-summer/00-ticket_close.sql @@ -0,0 +1,119 @@ +USE `vn`; +DROP procedure IF EXISTS `ticket_close`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_close`(vTicketFk INT) +BEGIN +/** + * Realiza el cierre de todos los + * tickets de la tabla ticketClosure. + * + * @param vTicketFk Id del ticket + */ + DECLARE vDone BOOL; + DECLARE vClientFk INT; + DECLARE vCurTicketFk INT; + DECLARE vIsTaxDataChecked BOOL; + DECLARE vCompanyFk INT; + DECLARE vShipped DATE; + DECLARE vNewInvoiceId INT; + DECLARE vHasDailyInvoice BOOL; + DECLARE vWithPackage BOOL; + DECLARE vHasToInvoice BOOL; + + DECLARE cur CURSOR FOR + SELECT ticketFk FROM tmp.ticketClosure; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + RESIGNAL; + END; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + CREATE TEMPORARY TABLE tmp.ticketClosure + SELECT vTicketFk AS ticketFk; + + INSERT INTO tmp.ticketClosure + SELECT id FROM stowaway s + WHERE s.shipFk = vTicketFk; + OPEN cur; + + proc: LOOP + SET vDone = FALSE; + + FETCH cur INTO vCurTicketFk; + + IF vDone THEN + LEAVE proc; + END IF; + + -- ticketClosure start + SELECT + c.id, + c.isTaxDataChecked, + t.companyFk, + t.shipped, + co.hasDailyInvoice, + w.isManaged, + c.hasToInvoice + INTO vClientFk, + vIsTaxDataChecked, + vCompanyFk, + vShipped, + vHasDailyInvoice, + vWithPackage, + vHasToInvoice + FROM ticket t + JOIN `client` c ON c.id = t.clientFk + JOIN province p ON p.id = c.provinceFk + JOIN country co ON co.id = p.countryFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.id = vCurTicketFk; + + INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) + (SELECT vCurTicketFk, p.id, COUNT(*) + FROM expedition e + JOIN packaging p ON p.itemFk = e.itemFk + WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable + AND vWithPackage + GROUP BY p.itemFk); + + -- No retornables o no catalogados + INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed) + (SELECT e.itemFk, vCurTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1 + FROM expedition e + JOIN item i ON i.id = e.itemFk + LEFT JOIN packaging p ON p.itemFk = i.id + WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 + AND getSpecialPrice(e.itemFk, vClientFk) > 0 + GROUP BY e.itemFk); + + CALL vn.zonePromo_Make(); + + IF(vHasDailyInvoice) AND vHasToInvoice THEN + + -- Facturacion rapida + CALL ticketTrackingAdd(vCurTicketFk, 'DELIVERED', NULL); + -- Facturar si está contabilizado + IF vIsTaxDataChecked THEN + CALL invoiceOut_newFromClient( + vClientFk, + (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), + vShipped, + vCompanyFk, + NULL, + vNewInvoiceId); + END IF; + ELSE + CALL ticketTrackingAdd(vCurTicketFk, (SELECT vn.getAlert3State(vCurTicketFk)), NULL); + END IF; + END LOOP; + + CLOSE cur; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; +END$$ + +DELIMITER ; + diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index fe93e8b41..33eecc627 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -199,7 +199,7 @@ export default { }, dms: { deleteFileButton: 'vn-client-dms-index vn-tr:nth-child(1) vn-icon-button[icon="delete"]', - firstDocWorker: 'vn-client-dms-index vn-td:nth-child(7) > span', + firstDocWorker: 'vn-client-dms-index vn-td:nth-child(8) > span', firstDocWorkerDescriptor: '.vn-popover.shown vn-worker-descriptor' }, clientContacts: { @@ -909,5 +909,12 @@ export default { newValueInput: 'vn-textfield[ng-model="$ctrl.editedColumn.newValue"]', latestBuysSectionButton: 'a[ui-sref="entry.latestBuys"]', acceptEditBuysDialog: 'button[response="accept"]' + }, + entryIndex: { + createEntryButton: 'vn-entry-index vn-button[icon="add"]', + newEntrySupplier: 'vn-entry-create vn-autocomplete[ng-model="$ctrl.entry.supplierFk"]', + newEntryTravel: 'vn-entry-create vn-autocomplete[ng-model="$ctrl.entry.travelFk"]', + newEntryCompany: 'vn-entry-create vn-autocomplete[ng-model="$ctrl.entry.companyFk"]', + saveNewEntry: 'vn-entry-create button[type="submit"]' } }; diff --git a/e2e/paths/12-entry/04_create.spec.js b/e2e/paths/12-entry/04_create.spec.js new file mode 100644 index 000000000..90dac618a --- /dev/null +++ b/e2e/paths/12-entry/04_create.spec.js @@ -0,0 +1,33 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Entry create path', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('buyer', 'entry'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should click the create entry button to open the form', async() => { + await page.waitToClick(selectors.entryIndex.createEntryButton); + await page.waitForState('entry.create'); + }); + + it('should fill the form to create a valid entry', async() => { + await page.autocompleteSearch(selectors.entryIndex.newEntrySupplier, '2'); + await page.autocompleteSearch(selectors.entryIndex.newEntryTravel, 'Warehouse Three'); + await page.autocompleteSearch(selectors.entryIndex.newEntryCompany, 'ORN'); + await page.waitToClick(selectors.entryIndex.saveNewEntry); + }); + + it('should be redirected to entry basic data', async() => { + await page.waitForState('entry.card.basicData'); + }); +}); diff --git a/modules/claim/back/methods/claim/filter.js b/modules/claim/back/methods/claim/filter.js index 1caa120be..7ba89089a 100644 --- a/modules/claim/back/methods/claim/filter.js +++ b/modules/claim/back/methods/claim/filter.js @@ -106,7 +106,7 @@ module.exports = Self => { let stmt; stmt = new ParameterizedSQL( - `SELECT cl.id, c.name, cl.clientFk, cl.workerFk, u.nickName, cs.description, cl.created + `SELECT cl.id, c.name, cl.clientFk, cl.workerFk, u.name AS userName, cs.description, cl.created FROM claim cl LEFT JOIN client c ON c.id = cl.clientFk LEFT JOIN worker w ON w.id = cl.workerFk diff --git a/modules/claim/front/card/index.js b/modules/claim/front/card/index.js index 361b0e74f..747eea9e7 100644 --- a/modules/claim/front/card/index.js +++ b/modules/claim/front/card/index.js @@ -12,7 +12,7 @@ class Controller extends ModuleCard { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/claim/front/descriptor/index.html b/modules/claim/front/descriptor/index.html index 627537348..d6fb75ac5 100644 --- a/modules/claim/front/descriptor/index.html +++ b/modules/claim/front/descriptor/index.html @@ -32,20 +32,32 @@ value="{{$ctrl.claim.created | date: 'dd/MM/yyyy HH:mm'}}"> + label="Salesperson"> + + {{$ctrl.claim.client.salesPersonUser.name}} + + label="Attended by"> + + {{$ctrl.claim.worker.user.name}} + + label="Ticket"> + + {{$ctrl.claim.ticketFk}} +
@@ -89,4 +93,7 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index 3402074cc..f38e91134 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -53,6 +53,12 @@ {{::document.dms.description}} + + + + @@ -62,7 +68,7 @@ - {{::document.dms.worker.user.nickname | dashIfEmpty}} + {{::document.dms.worker.user.name | dashIfEmpty}} {{::document.dms.created | date:'dd/MM/yyyy HH:mm'}} diff --git a/modules/client/front/dms/index/index.js b/modules/client/front/dms/index/index.js index c65de39e4..a18f195bb 100644 --- a/modules/client/front/dms/index/index.js +++ b/modules/client/front/dms/index/index.js @@ -32,7 +32,7 @@ class Controller extends Section { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } }, } diff --git a/modules/client/front/sample/index/index.html b/modules/client/front/sample/index/index.html index bd7fc6e4a..7bb503fa2 100644 --- a/modules/client/front/sample/index/index.html +++ b/modules/client/front/sample/index/index.html @@ -32,7 +32,7 @@ - {{::sample.worker.user.nickname}} + {{::sample.worker.user.name}} {{::sample.company.code}} diff --git a/modules/client/front/sample/index/index.js b/modules/client/front/sample/index/index.js index e93c2d2dc..132704de0 100644 --- a/modules/client/front/sample/index/index.js +++ b/modules/client/front/sample/index/index.js @@ -18,7 +18,7 @@ class Controller extends Section { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/client/front/summary/index.html b/modules/client/front/summary/index.html index 9e53d4988..ce69bf158 100644 --- a/modules/client/front/summary/index.html +++ b/modules/client/front/summary/index.html @@ -21,8 +21,12 @@ - + + + {{$ctrl.summary.salesPerson.user.name}} + @@ -197,4 +201,7 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/entry/back/models/entry.json b/modules/entry/back/models/entry.json index d3f149680..a67641b0c 100644 --- a/modules/entry/back/models/entry.json +++ b/modules/entry/back/models/entry.json @@ -1,6 +1,6 @@ { "name": "Entry", - "base": "VnModel", + "base": "Loggable", "log": { "model":"EntryLog" }, @@ -62,6 +62,18 @@ }, "loadPriority": { "type": "number" + }, + "supplierFk": { + "type": "number", + "required": true + }, + "travelFk": { + "type": "number", + "required": true + }, + "companyFk": { + "type": "number", + "required": true } }, "relations": { diff --git a/modules/entry/front/basic-data/index.html b/modules/entry/front/basic-data/index.html new file mode 100644 index 000000000..e69de29bb diff --git a/modules/entry/front/basic-data/index.js b/modules/entry/front/basic-data/index.js new file mode 100644 index 000000000..141a365fa --- /dev/null +++ b/modules/entry/front/basic-data/index.js @@ -0,0 +1,10 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +ngModule.vnComponent('vnEntryBasicData', { + template: require('./index.html'), + controller: Section, + bindings: { + entry: '<' + } +}); diff --git a/modules/entry/front/create/index.html b/modules/entry/front/create/index.html new file mode 100644 index 000000000..7b5dfc928 --- /dev/null +++ b/modules/entry/front/create/index.html @@ -0,0 +1,61 @@ + + + +
+ + + + + + + {{::id}} - {{::nickname}} + + + + + + + {{::agencyModeName}} - {{::warehouseInName}} ({{::shipped | date: 'dd/MM/yyyy'}}) → + {{::warehouseOutName}} ({{::landed | date: 'dd/MM/yyyy'}}) + + + + + + + + + + + + +
diff --git a/modules/entry/front/create/index.js b/modules/entry/front/create/index.js new file mode 100644 index 000000000..5c61730f9 --- /dev/null +++ b/modules/entry/front/create/index.js @@ -0,0 +1,43 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; +import './style.scss'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + + this.entry = { + companyFk: this.vnConfig.companyFk + }; + + if (this.$params && this.$params.supplierFk) + this.entry.supplierFk = parseInt(this.$params.supplierFk); + if (this.$params && this.$params.travelFk) + this.entry.travelFk = parseInt(this.$params.travelFk); + if (this.$params && this.$params.companyFk) + this.entry.companyFk = parseInt(this.$params.companyFk); + } + + onSubmit() { + this.$.watcher.submit().then( + res => this.$state.go('entry.card.basicData', {id: res.data.id}) + ); + } + + searchFunction($search) { + return {or: [ + {'agencyModeName': {like: `%${$search}%`}}, + {'warehouseInName': {like: `%${$search}%`}}, + {'warehouseOutName': {like: `%${$search}%`}}, + {'shipped': new Date($search)}, + {'landed': new Date($search)} + ]}; + } +} + +Controller.$inject = ['$element', '$scope']; + +ngModule.vnComponent('vnEntryCreate', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/entry/front/create/locale/es.yml b/modules/entry/front/create/locale/es.yml new file mode 100644 index 000000000..aa269ed15 --- /dev/null +++ b/modules/entry/front/create/locale/es.yml @@ -0,0 +1,2 @@ +New entry: Nueva entrada +Required fields (*): Campos requeridos (*) \ No newline at end of file diff --git a/modules/entry/front/create/style.scss b/modules/entry/front/create/style.scss new file mode 100644 index 000000000..2dc52b1ff --- /dev/null +++ b/modules/entry/front/create/style.scss @@ -0,0 +1,10 @@ +vn-entry-create { + vn-card { + position: relative + } + vn-icon[icon="info"] { + position: absolute; + top: 16px; + right: 16px + } +} \ No newline at end of file diff --git a/modules/entry/front/index.js b/modules/entry/front/index.js index fc24e3efb..484d8f718 100644 --- a/modules/entry/front/index.js +++ b/modules/entry/front/index.js @@ -2,6 +2,7 @@ export * from './module'; import './main'; import './index/'; +import './create'; import './latest-buys'; import './search-panel'; import './latest-buys-search-panel'; diff --git a/modules/entry/front/index/index.html b/modules/entry/front/index/index.html index e3d174cbf..8a28888b0 100644 --- a/modules/entry/front/index/index.html +++ b/modules/entry/front/index/index.html @@ -69,4 +69,16 @@ - \ No newline at end of file + + +
+ + + + + + +
\ No newline at end of file diff --git a/modules/entry/front/routes.json b/modules/entry/front/routes.json index cdaaebc7d..a430a95fa 100644 --- a/modules/entry/front/routes.json +++ b/modules/entry/front/routes.json @@ -10,6 +10,7 @@ {"state": "entry.latestBuys", "icon": "icon-latestBuys"} ], "card": [ + {"state": "entry.card.basicData", "icon": "settings"}, {"state": "entry.card.buy", "icon": "icon-lines"}, {"state": "entry.card.log", "icon": "history"} ] @@ -33,6 +34,12 @@ "component": "vn-entry-latest-buys", "description": "Latest buys", "acl": ["buyer"] + }, { + "url": "/create?supplierFk&travelFk&companyFk", + "state": "entry.create", + "component": "vn-entry-create", + "description": "New entry", + "acl": ["buyer"] }, { "url": "/:id", "state": "entry.card", @@ -46,6 +53,14 @@ "params": { "entry": "$ctrl.entry" } + }, { + "url": "/basic-data", + "state": "entry.card.basicData", + "component": "vn-entry-basic-data", + "description": "Basic data", + "params": { + "entry": "$ctrl.entry" + } }, { "url" : "/log", "state": "entry.card.log", diff --git a/modules/invoiceOut/front/descriptor/index.html b/modules/invoiceOut/front/descriptor/index.html index 093d9edf7..fe22e4dd8 100644 --- a/modules/invoiceOut/front/descriptor/index.html +++ b/modules/invoiceOut/front/descriptor/index.html @@ -37,8 +37,12 @@ value="{{$ctrl.invoiceOut.amount | currency: 'EUR': 2}}">
+ label="Client"> + + {{$ctrl.invoiceOut.client.name}} + - \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index 420b357a5..d953d1938 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -26,7 +26,9 @@ module.exports = Self => { await fs.mkdir(tempPath, {recursive: true}); const timer = setInterval(async() => { - const image = await Self.findOne({where: {error: null}}); + const image = await Self.findOne({ + where: {error: null, url: {neq: null}} + }); // Exit loop if (!image) return clearInterval(timer); diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index a38a06713..1fefab77e 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -113,7 +113,7 @@ module.exports = Self => { i.isActive, t.name type, t.workerFk buyerFk, - u.nickname userNickname, + u.name userName, intr.description AS intrastat, i.stems, ori.code AS origin, diff --git a/modules/item/back/methods/item/getCard.js b/modules/item/back/methods/item/getCard.js index 9780c5601..69b5c1116 100644 --- a/modules/item/back/methods/item/getCard.js +++ b/modules/item/back/methods/item/getCard.js @@ -37,7 +37,7 @@ module.exports = Self => { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/item/back/methods/item/getSummary.js b/modules/item/back/methods/item/getSummary.js index fd52951d7..698984572 100644 --- a/modules/item/back/methods/item/getSummary.js +++ b/modules/item/back/methods/item/getSummary.js @@ -38,7 +38,7 @@ module.exports = Self => { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/item/back/models/supplier.json b/modules/item/back/models/supplier.json index bc13e79b9..41fc9c45c 100644 --- a/modules/item/back/models/supplier.json +++ b/modules/item/back/models/supplier.json @@ -33,13 +33,13 @@ "retAccount": { "type": "Number" }, - "commision": { + "commission": { "type": "Boolean" }, "created": { "type": "Date" }, - "poscodeFk": { + "postcodeFk": { "type": "Number" }, "isActive": { diff --git a/modules/item/front/descriptor/index.html b/modules/item/front/descriptor/index.html index c872d2bf2..8363a652f 100644 --- a/modules/item/front/descriptor/index.html +++ b/modules/item/front/descriptor/index.html @@ -44,8 +44,12 @@
+ label="Buyer"> + + {{$ctrl.item.itemType.worker.user.name}} + + + \ No newline at end of file diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index eaef0f34f..01128ed74 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -70,11 +70,11 @@ {{::item.intrastat}} {{::item.origin}} - + - {{::item.userNickname}} + {{::item.userName}} {{::item.density}} diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index 938005828..bf9ab9445 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -36,8 +36,12 @@ - + + + {{$ctrl.summary.item.itemType.worker.user.name}} + @@ -105,4 +109,7 @@

- \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/order/front/card/index.js b/modules/order/front/card/index.js index d154b0b52..33012d0f6 100644 --- a/modules/order/front/card/index.js +++ b/modules/order/front/card/index.js @@ -37,7 +37,7 @@ class Controller extends ModuleCard { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index a13274484..ecce520a6 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -63,7 +63,7 @@ ng-model="$ctrl.orderField" selection="$ctrl.orderSelection" translate-fields="['name']" - order="name" + order="priority DESC" show-field="name" value-field="field" label="Order by" diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index ddfe69cc9..d5d944607 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -14,10 +14,10 @@ class Controller extends Section { {way: 'DESC', name: 'Descendant'}, ]; this.defaultOrderFields = [ - {field: 'relevancy DESC, name', name: 'Relevancy'}, - {field: 'showOrder, price', name: 'Color and price'}, - {field: 'name', name: 'Name'}, - {field: 'price', name: 'Price'} + {field: 'relevancy DESC, name', name: 'Relevancy', priority: 999}, + {field: 'showOrder, price', name: 'Color and price', priority: 999}, + {field: 'name', name: 'Name', priority: 999}, + {field: 'price', name: 'Price', priority: 999} ]; this.orderFields = [].concat(this.defaultOrderFields); this._orderWay = this.orderWays[0].way; @@ -312,9 +312,11 @@ class Controller extends Section { tags.push({ name: itemTag.name, field: itemTag.tagFk, - isTag: true + isTag: true, + priority: 1 }); - } + } else + tags[alreadyAdded].priority += 1; }); }); let newFilterList = [].concat(this.defaultOrderFields); diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index eceb3eb66..4ef9cbeb9 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -45,7 +45,7 @@ describe('Order', () => { jest.spyOn(controller, 'buildTagsFilter'); jest.spyOn(controller, 'buildOrderFilter'); - const expectedResult = [{field: 'showOrder, price', name: 'Color and price'}]; + const expectedResult = [{field: 'showOrder, price', name: 'Color and price', priority: 999}]; const items = [{id: 1, name: 'My Item', tags: [ {tagFk: 4, name: 'Length'}, {tagFk: 5, name: 'Color'} diff --git a/modules/order/front/descriptor/index.html b/modules/order/front/descriptor/index.html index b16470bf2..e9f1684e5 100644 --- a/modules/order/front/descriptor/index.html +++ b/modules/order/front/descriptor/index.html @@ -15,8 +15,12 @@ value="{{$ctrl.$t($ctrl.order.isConfirmed ? 'Confirmed' : 'Not confirmed')}}">
+ label="Sales person"> + + {{$ctrl.order.client.salesPerson.user.name}} + - \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/route/back/methods/route/filter.js b/modules/route/back/methods/route/filter.js index eeeef1dac..c96f856f0 100644 --- a/modules/route/back/methods/route/filter.js +++ b/modules/route/back/methods/route/filter.js @@ -119,7 +119,7 @@ module.exports = Self => { r.m3, r.description, am.name agencyName, - u.nickname AS workerNickname, + u.name AS workerUserName, v.numberPlate AS vehiclePlateNumber FROM route r LEFT JOIN agencyMode am ON am.id = r.agencyModeFk @@ -128,7 +128,6 @@ module.exports = Self => { LEFT JOIN account.user u ON u.id = w.userFk` ); - stmt.merge(conn.makeSuffix(filter)); let itemsIndex = stmts.push(stmt) - 1; diff --git a/modules/route/back/methods/route/specs/summary.spec.js b/modules/route/back/methods/route/specs/summary.spec.js index ba976ae94..a9516f7c5 100644 --- a/modules/route/back/methods/route/specs/summary.spec.js +++ b/modules/route/back/methods/route/specs/summary.spec.js @@ -25,7 +25,7 @@ describe('route summary()', () => { const result = await app.models.Route.summary(1); const worker = result.route.worker().user(); - expect(worker.nickname).toEqual('deliveryNick'); + expect(worker.name).toEqual('delivery'); }); it(`should return a summary object containing data from the tickets`, async() => { diff --git a/modules/route/back/methods/route/summary.js b/modules/route/back/methods/route/summary.js index 0a8710e88..52927d974 100644 --- a/modules/route/back/methods/route/summary.js +++ b/modules/route/back/methods/route/summary.js @@ -38,7 +38,7 @@ module.exports = Self => { { relation: 'user', scope: { - fields: ['id', 'nickname'] + fields: ['id', 'name'] } } ] diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html index 7258018f1..d095fed09 100644 --- a/modules/route/front/index/index.html +++ b/modules/route/front/index/index.html @@ -38,7 +38,7 @@ - {{::route.workerNickname}} + {{::route.workerUserName}}
{{::route.agencyName | dashIfEmpty}} @@ -79,10 +79,9 @@ tooltip-position="left"> - + diff --git a/modules/route/front/summary/index.html b/modules/route/front/summary/index.html index b2c9255e0..4c45d3985 100644 --- a/modules/route/front/summary/index.html +++ b/modules/route/front/summary/index.html @@ -14,8 +14,12 @@ - + + + {{$ctrl.summary.route.worker.user.name}} + @@ -106,3 +110,6 @@ + + diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 3a34be442..878b4278e 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -245,7 +245,7 @@ module.exports = Self => { SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped FROM tmp.filter f LEFT JOIN alertLevel al ON al.alertLevel = f.alertLevel - WHERE (f.alertLevelCode = 'FREE' OR f.alertLevel IS NULL) + WHERE (al.code = 'FREE' OR f.alertLevel IS NULL) AND f.shipped >= CURDATE()`); stmts.push('CALL ticketGetProblems()'); diff --git a/modules/ticket/back/methods/ticket/summary.js b/modules/ticket/back/methods/ticket/summary.js index 79a7c24d9..434cf5624 100644 --- a/modules/ticket/back/methods/ticket/summary.js +++ b/modules/ticket/back/methods/ticket/summary.js @@ -63,7 +63,7 @@ module.exports = Self => { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/ticket/front/card/index.js b/modules/ticket/front/card/index.js index 5b3c3c405..34ec2be98 100644 --- a/modules/ticket/front/card/index.js +++ b/modules/ticket/front/card/index.js @@ -44,7 +44,7 @@ class Controller extends ModuleCard { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html index 1ad27aac3..f5c4891c3 100644 --- a/modules/ticket/front/descriptor/index.html +++ b/modules/ticket/front/descriptor/index.html @@ -90,8 +90,12 @@ value="{{$ctrl.ticket.ticketState.state.name}}"> + label="Sales person"> + + {{$ctrl.ticket.client.salesPerson.user.name}} + - \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index fdcd50e3c..b67474427 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -210,7 +210,7 @@ class Controller extends Descriptor { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 80ddbf899..851276a6b 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -51,6 +51,12 @@ {{::document.dms.description}} + + + + @@ -60,8 +66,9 @@ - {{::document.dms.worker.user.nickname | dashIfEmpty}} - + {{::document.dms.worker.user.name | dashIfEmpty}} + + {{::document.dms.created | date:'dd/MM/yyyy HH:mm'}} diff --git a/modules/ticket/front/dms/index/index.js b/modules/ticket/front/dms/index/index.js index 2a67d6890..da6aa6b6f 100644 --- a/modules/ticket/front/dms/index/index.js +++ b/modules/ticket/front/dms/index/index.js @@ -33,7 +33,7 @@ class Controller extends Section { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } }, } diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index b0aff5b91..2c598ca03 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -143,10 +143,9 @@ vn-tooltip="Payment on account..." tooltip-position="left"> - + diff --git a/modules/ticket/front/summary/index.html b/modules/ticket/front/summary/index.html index 7b0e9d06d..ed269914c 100644 --- a/modules/ticket/front/summary/index.html +++ b/modules/ticket/front/summary/index.html @@ -18,8 +18,12 @@ - + + + {{$ctrl.summary.client.salesPerson.user.name}} + @@ -239,4 +243,7 @@ - \ No newline at end of file + + + diff --git a/modules/ticket/front/tracking/index/index.html b/modules/ticket/front/tracking/index/index.html index bf22bfb98..42d2197d0 100644 --- a/modules/ticket/front/tracking/index/index.html +++ b/modules/ticket/front/tracking/index/index.html @@ -25,7 +25,7 @@ - {{::tracking.worker.user.nickname | dashIfEmpty}} + {{::tracking.worker.user.name | dashIfEmpty}} {{::tracking.created | date:'dd/MM/yyyy HH:mm'}} diff --git a/modules/ticket/front/tracking/index/index.js b/modules/ticket/front/tracking/index/index.js index 5528fc1ad..38abcd8ab 100644 --- a/modules/ticket/front/tracking/index/index.js +++ b/modules/ticket/front/tracking/index/index.js @@ -13,7 +13,7 @@ class Controller extends Section { include: { relation: 'user', scope: { - fields: ['nickname'] + fields: ['name'] } } } diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index 0cfafd7ba..024448bfe 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -112,7 +112,8 @@ module.exports = Self => { let stmts = []; let stmt; stmt = new ParameterizedSQL( - `SELECT + `SELECT * FROM + (SELECT t.id, t.shipped, t.landed, @@ -132,7 +133,7 @@ module.exports = Self => { FROM vn.travel t JOIN vn.agencyMode am ON am.id = t.agencyFk JOIN vn.warehouse win ON win.id = t.warehouseInFk - JOIN vn.warehouse wout ON wout.id = t.warehouseOutFk` + JOIN vn.warehouse wout ON wout.id = t.warehouseOutFk) AS t` ); stmt.merge(conn.makeSuffix(filter)); diff --git a/modules/travel/front/descriptor/locale/es.yml b/modules/travel/front/descriptor/locale/es.yml index 1f51a0132..0ae18fdbf 100644 --- a/modules/travel/front/descriptor/locale/es.yml +++ b/modules/travel/front/descriptor/locale/es.yml @@ -1,6 +1,6 @@ Reference: Referencia -Wh. In: Warehouse entrada -Wh. Out: Warehouse salida +Wh. In: Almacén entrada +Wh. Out: Almacén salida Shipped: F. envío Landed: F. entrega Total entries: Entradas totales \ No newline at end of file diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 4564dba44..d74d65bfa 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -18,6 +18,7 @@ Reference Description Original + File Created @@ -36,7 +37,13 @@ {{::document.description}} - + + + + + diff --git a/print/methods/closure.js b/print/methods/closure.js index 3bcca9d4e..a1450f446 100644 --- a/print/methods/closure.js +++ b/print/methods/closure.js @@ -4,42 +4,179 @@ const smtp = require('../core/smtp'); const config = require('../core/config'); module.exports = app => { - app.get('/api/closure/by-ticket', async function(req, res) { + app.get('/api/closure/all', async function(req, res, next) { + try { + res.status(200).json({ + message: 'Task executed successfully' + }); + + await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`); + await db.rawSql(` + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND DATE(t.shipped) BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND CURDATE() + AND t.refFk IS NULL + GROUP BY e.ticketFk)`); + + await closeAll(req.args); + + await db.rawSql(` + UPDATE ticket t + JOIN ticketState ts ON t.id = ts.ticketFk + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN zone z ON z.id = t.zoneFk + SET t.routeFk = NULL + WHERE shipped BETWEEN CURDATE() AND util.dayEnd(CURDATE()) + AND al.code NOT IN('DELIVERED','PACKED') + AND t.routeFk + AND z.name LIKE '%MADRID%'`); + } catch (error) { + next(error); + } }); - app.get('/api/closure/all', async function(req, res) { - res.status(200).json({ - message: 'Task executed successfully' - }); + app.get('/api/closure/by-ticket', async function(req, res, next) { + try { + const reqArgs = req.args; + if (!reqArgs.ticketId) + throw new Error('The argument ticketId is required'); + res.status(200).json({ + message: 'Task executed successfully' + }); + + await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`); + await db.rawSql(` + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.id = :ticketId + AND t.refFk IS NULL + GROUP BY e.ticketFk)`, { + ticketId: reqArgs.ticketId + }); + + await closeAll(reqArgs); + } catch (error) { + next(error); + } + }); + + app.get('/api/closure/by-agency', async function(req, res) { + try { + const reqArgs = req.args; + if (!reqArgs.agencyModeId) + throw new Error('The argument agencyModeId is required'); + + if (!reqArgs.warehouseId) + throw new Error('The argument warehouseId is required'); + + if (!reqArgs.to) + throw new Error('The argument to is required'); + + res.status(200).json({ + message: 'Task executed successfully' + }); + + await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`); + await db.rawSql(` + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.agencyModeFk = :agencyModeId + AND t.warehouseFk = :warehouseId + AND DATE(t.shipped) BETWEEN DATE_ADD(:to, INTERVAL -2 DAY) AND :to + AND t.refFk IS NULL + GROUP BY e.ticketFk)`, { + agencyModeId: reqArgs.agencyModeId, + warehouseId: reqArgs.warehouseId, + to: reqArgs.to + }); + + await closeAll(reqArgs); + } catch (error) { + next(error); + } + }); + + app.get('/api/closure/by-route', async function(req, res) { + try { + const reqArgs = req.args; + if (!reqArgs.routeId) + throw new Error('The argument routeId is required'); + + res.status(200).json({ + message: 'Task executed successfully' + }); + + await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`); + await db.rawSql(` + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.routeFk = :routeId + AND t.refFk IS NULL + GROUP BY e.ticketFk)`, { + routeId: reqArgs.routeId + }); + + await closeAll(reqArgs); + } catch (error) { + next(error); + } + }); + + async function closeAll(reqArgs) { const failedtickets = []; const tickets = await db.rawSql(` SELECT t.id, t.clientFk, c.email recipient, - c.isToBeMailed, c.salesPersonFk, + c.isToBeMailed, + c.hasToInvoice, + co.hasDailyInvoice, eu.email salesPersonEmail - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk + FROM tmp.ticket_close tt + JOIN ticket t ON t.id = tt.ticketFk JOIN client c ON c.id = t.clientFk - JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk - WHERE al.code = 'PACKED' - AND DATE(t.shipped) BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND CURDATE() - AND t.refFk IS NULL - GROUP BY e.ticketFk`); + JOIN province p ON p.id = c.provinceFk + JOIN country co ON co.id = p.countryFk + LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk`); for (const ticket of tickets) { try { - await db.rawSql(`CALL vn.ticket_closeByTicket(:ticketId)`, { + await db.rawSql(`CALL vn.ticket_close(:ticketId)`, { ticketId: ticket.id }); - if (!ticket.salesPersonFk || !ticket.isToBeMailed) continue; + const hasToInvoice = ticket.hasToInvoice && ticket.hasDailyInvoice; + if (!ticket.salesPersonFk || !ticket.isToBeMailed || hasToInvoice) continue; if (!ticket.recipient) { const body = `No se ha podido enviar el albarán ${ticket.id} @@ -54,7 +191,6 @@ module.exports = app => { continue; } - const reqArgs = req.args; const args = Object.assign({ ticketId: ticket.id, recipientId: ticket.clientFk, @@ -88,5 +224,7 @@ module.exports = app => { html: body }); } - }); + + await db.rawSql(`DROP TEMPORARY TABLE tmp.ticket_close`); + } }; diff --git a/print/templates/email/delivery-note-link/locale/en.yml b/print/templates/email/delivery-note-link/locale/en.yml index 5f1526828..aaa545525 100644 --- a/print/templates/email/delivery-note-link/locale/en.yml +++ b/print/templates/email/delivery-note-link/locale/en.yml @@ -1,5 +1,5 @@ subject: Your delivery note -title: "Here is your delivery note!" +title: Your delivery note dear: Dear client description: The delivery note from the order {0} is now available.
You can download it by clicking
this link. diff --git a/print/templates/email/delivery-note-link/locale/es.yml b/print/templates/email/delivery-note-link/locale/es.yml index 47c7f11da..0bafd459a 100644 --- a/print/templates/email/delivery-note-link/locale/es.yml +++ b/print/templates/email/delivery-note-link/locale/es.yml @@ -1,5 +1,5 @@ -subject: Aquí tienes tu albarán -title: "Aquí tienes tu albarán" +subject: Tu albarán +title: Tu albarán dear: Estimado cliente description: Ya está disponible el albarán correspondiente al pedido {0}.
Puedes verlo haciendo clic en este enlace. diff --git a/print/templates/email/delivery-note-link/locale/fr.yml b/print/templates/email/delivery-note-link/locale/fr.yml index 3ecf357e1..bcb16c09f 100644 --- a/print/templates/email/delivery-note-link/locale/fr.yml +++ b/print/templates/email/delivery-note-link/locale/fr.yml @@ -1,5 +1,5 @@ -subject: Voici votre bon de livraison -title: "Voici votre bon de livraison" +subject: Votre bon de livraison +title: Votre bon de livraison dear: Cher client, description: Le bon de livraison correspondant à la commande {0} est maintenant disponible.
Vous pouvez le voir en cliquant sur ce lien. diff --git a/print/templates/email/delivery-note-link/locale/pt.yml b/print/templates/email/delivery-note-link/locale/pt.yml index c008ea2c7..cff3ea52b 100644 --- a/print/templates/email/delivery-note-link/locale/pt.yml +++ b/print/templates/email/delivery-note-link/locale/pt.yml @@ -1,5 +1,5 @@ -subject: Vossa Nota de Entrega -title: "Esta é vossa nota de entrega!" +subject: Vossa nota de entrega +title: Vossa nota de entrega dear: Estimado cliente description: Já está disponível sua nota de entrega correspondente a encomenda numero {0}.
Para ver-lo faça um clique neste link. diff --git a/print/templates/email/delivery-note/locale/en.yml b/print/templates/email/delivery-note/locale/en.yml index fcabe11ec..50d39e8cf 100644 --- a/print/templates/email/delivery-note/locale/en.yml +++ b/print/templates/email/delivery-note/locale/en.yml @@ -1,5 +1,5 @@ subject: Your delivery note -title: "Here is your delivery note!" +title: Your delivery note dear: Dear client description: The delivery note from the order {0} is now available.
You can download it by clicking on the attachment of this email. diff --git a/print/templates/email/delivery-note/locale/es.yml b/print/templates/email/delivery-note/locale/es.yml index 3294b2316..ffa99e12f 100644 --- a/print/templates/email/delivery-note/locale/es.yml +++ b/print/templates/email/delivery-note/locale/es.yml @@ -1,5 +1,5 @@ -subject: Aquí tienes tu albarán -title: "¡Este es tu albarán!" +subject: Tu albarán +title: Tu albarán dear: Estimado cliente description: Ya está disponible el albarán correspondiente al pedido {0}.
Puedes descargarlo haciendo clic en el adjunto de este correo. diff --git a/print/templates/email/delivery-note/locale/fr.yml b/print/templates/email/delivery-note/locale/fr.yml index fdaf6e320..f8fb5e7cd 100644 --- a/print/templates/email/delivery-note/locale/fr.yml +++ b/print/templates/email/delivery-note/locale/fr.yml @@ -1,5 +1,5 @@ -subject: Voici votre bon de livraison -title: "Voici votre bon de livraison!" +subject: Votre bon de livraison +title: Votre bon de livraison dear: Cher client, description: Le bon de livraison correspondant à la commande {0} est maintenant disponible.
Vous pouvez le télécharger en cliquant sur la pièce jointe dans cet email. diff --git a/print/templates/email/delivery-note/locale/pt.yml b/print/templates/email/delivery-note/locale/pt.yml index cbca170a3..818a4de4c 100644 --- a/print/templates/email/delivery-note/locale/pt.yml +++ b/print/templates/email/delivery-note/locale/pt.yml @@ -1,5 +1,5 @@ -subject: Vossa Nota de Entrega -title: "Esta é vossa nota de entrega!" +subject: Vossa nota de entrega +title: Vossa nota de entrega dear: Estimado cliente description: Já está disponível sua nota de entrega correspondente a encomenda {0}.
Podes descarregar-la fazendo um clique no arquivo anexado ao e-mail.