diff --git a/client/client/src/credit-insurance/create/index.html b/client/client/src/credit-insurance/create/index.html index b37ed2c9a..38c598601 100644 --- a/client/client/src/credit-insurance/create/index.html +++ b/client/client/src/credit-insurance/create/index.html @@ -6,7 +6,7 @@ vn-one label="Credit" model="$ctrl.creditClassification.credit", - rule="CreditInsurance.credit" + rule="creditInsurance.credit" step="1" vn-focus> @@ -20,7 +20,7 @@ vn-one label="Since" model="$ctrl.creditClassification.started" - ini-options="{dateFormat: 'd-m-Y'}"> + ini-options="{enableTime: true, dateFormat: 'd-m-Y', time_24hr: true}"> diff --git a/client/client/src/credit-insurance/create/index.js b/client/client/src/credit-insurance/create/index.js index 81ab7c67d..221580b27 100644 --- a/client/client/src/credit-insurance/create/index.js +++ b/client/client/src/credit-insurance/create/index.js @@ -14,7 +14,7 @@ class Controller { submit() { if (this.$scope.form.$invalid) - return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); + return this.vnApp.showError(this.$translate.instant('Some fields are invalid')); let query = `/client/api/creditClassifications/createWithInsurance`; let data = this.creditClassification; diff --git a/client/client/src/credit-insurance/index/credit-insurance-index.spec.js b/client/client/src/credit-insurance/index/credit-insurance-index.spec.js index 74cf9f789..19128c821 100644 --- a/client/client/src/credit-insurance/index/credit-insurance-index.spec.js +++ b/client/client/src/credit-insurance/index/credit-insurance-index.spec.js @@ -20,7 +20,7 @@ describe('Client', () => { describe('_getClassifications()', () => { it('should perform a GET query to define the classifications property in the controller', () => { let res = ['some classifications']; - let query = '/client/api/CreditClassifications?filter=%7B%22order%22%3A%22finished%20ASC%2C%20started%20DESC%22%2C%22include%22%3A%5B%7B%22relation%22%3A%22creditInsurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D'; + let query = '/client/api/CreditClassifications?filter=%7B%22order%22%3A%22finished%20ASC%2C%20started%20DESC%22%2C%22include%22%3A%5B%7B%22relation%22%3A%22insurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D'; $httpBackend.whenGET(query).respond(res); $httpBackend.expectGET(query); diff --git a/client/client/src/credit-insurance/index/index.html b/client/client/src/credit-insurance/index/index.html index 69ee6cb74..b8c2480c5 100644 --- a/client/client/src/credit-insurance/index/index.html +++ b/client/client/src/credit-insurance/index/index.html @@ -15,7 +15,7 @@
To {{classification.finished | date:'dd/MM/yyyy'}}
- + diff --git a/client/client/src/credit-insurance/index/index.js b/client/client/src/credit-insurance/index/index.js index cee5a20b2..6d6994a9a 100644 --- a/client/client/src/credit-insurance/index/index.js +++ b/client/client/src/credit-insurance/index/index.js @@ -17,7 +17,7 @@ class Controller { order: 'finished ASC, started DESC', include: [ { - relation: 'creditInsurances', + relation: 'insurances', scope: { fields: ['id', 'credit', 'created', 'grade'], order: 'created DESC', diff --git a/client/client/src/credit-insurance/insurance/create/index.html b/client/client/src/credit-insurance/insurance/create/index.html index 77465eb91..f2f9efef3 100644 --- a/client/client/src/credit-insurance/insurance/create/index.html +++ b/client/client/src/credit-insurance/insurance/create/index.html @@ -1,4 +1,4 @@ - + + ini-options="{enableTime: true, dateFormat: 'd-m-Y', time_24hr: true}"> diff --git a/client/client/src/credit-insurance/insurance/create/index.js b/client/client/src/credit-insurance/insurance/create/index.js index 51feab0f5..5f615bdb2 100644 --- a/client/client/src/credit-insurance/insurance/create/index.js +++ b/client/client/src/credit-insurance/insurance/create/index.js @@ -3,7 +3,7 @@ import ngModule from '../../../module'; class Controller { constructor($filter) { this.insurance = { - created: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm') + created: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss') }; } } diff --git a/client/client/src/credit-insurance/insurance/index/index.html b/client/client/src/credit-insurance/insurance/index/index.html index b5c42326a..0190e9eec 100644 --- a/client/client/src/credit-insurance/insurance/index/index.html +++ b/client/client/src/credit-insurance/insurance/index/index.html @@ -1,4 +1,4 @@ - + diff --git a/client/client/src/summary/index.html b/client/client/src/summary/index.html index 5767f48c7..fda4ebe04 100644 --- a/client/client/src/summary/index.html +++ b/client/client/src/summary/index.html @@ -199,9 +199,16 @@ - - + + + + + + + {{$ctrl.grade ? ' / ' + $ctrl.grade : ' / - '}} + + diff --git a/client/client/src/summary/index.js b/client/client/src/summary/index.js index a8a54b55a..8c1986bd6 100644 --- a/client/client/src/summary/index.js +++ b/client/client/src/summary/index.js @@ -11,8 +11,12 @@ class Controller { return; this.$http.get(`/client/api/Clients/${this.client.id}/summary`).then(res => { - if (res && res.data) + if (res && res.data) { this.summary = res.data; + + if (res.data.classifications.length) + this.grade = res.data.classifications[0].insurances[0].grade; + } }); } } diff --git a/client/core/src/components/popover/popover.js b/client/core/src/components/popover/popover.js index 197f7773a..2a8760e6a 100644 --- a/client/core/src/components/popover/popover.js +++ b/client/core/src/components/popover/popover.js @@ -75,15 +75,6 @@ export default class Popover extends Component { this.document.addEventListener('keydown', this.docKeyDownHandler); this.document.addEventListener('focusin', this.docFocusInHandler); - let firstFocusable = this.element.querySelector('input, textarea'); - if (firstFocusable) { - firstFocusable.addEventListener('focus', () => { - firstFocusable.select(); - }); - setTimeout(() => { - firstFocusable.focus(); - }, 200); - } this.deregisterCallback = this.$transitions.onStart({}, () => this.hide()); this.relocate(); diff --git a/client/item/src/barcode/barcode.spec.js b/client/item/src/barcode/barcode.spec.js index 585af2d71..06adc75da 100644 --- a/client/item/src/barcode/barcode.spec.js +++ b/client/item/src/barcode/barcode.spec.js @@ -88,7 +88,7 @@ describe('Item', () => { describe('submit()', () => { it("should return an error message 'The barcode must be unique' when the code isnt unique", () => { - spyOn(controller.vnApp, 'showMessage').and.callThrough(); + spyOn(controller.vnApp, 'showError').and.callThrough(); controller.barcodes = [ {code: 123454, itemFk: 1, id: 1}, {code: 123454, itemFk: 1} @@ -96,7 +96,7 @@ describe('Item', () => { controller.oldBarcodes = {1: {id: 1, code: 123454, itemFk: 1}}; controller.submit(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The barcode must be unique'); + expect(controller.vnApp.showError).toHaveBeenCalledWith('The barcode must be unique'); }); it("should perfom a query to delete barcodes", () => { @@ -131,7 +131,7 @@ describe('Item', () => { }); it("should return a message 'No changes to save' when there are no changes to apply", () => { - spyOn(controller.vnApp, 'showMessage').and.callThrough(); + spyOn(controller.vnApp, 'showError').and.callThrough(); controller.oldBarcodes = [ {code: 1, itemFk: 1, id: 1}, {code: 2, itemFk: 1, id: 2} @@ -139,7 +139,7 @@ describe('Item', () => { controller.barcodes = []; controller.submit(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save'); + expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save'); }); }); }); diff --git a/client/item/src/barcode/index.js b/client/item/src/barcode/index.js index 3e31cab81..b1bbab3f4 100644 --- a/client/item/src/barcode/index.js +++ b/client/item/src/barcode/index.js @@ -86,7 +86,7 @@ export default class Controller { } if (repeatedBarcodes) { - return this.vnApp.showMessage(this.$translate.instant('The barcode must be unique')); + return this.vnApp.showError(this.$translate.instant('The barcode must be unique')); } canSubmit = barcodesObj.update.length > 0 || barcodesObj.create.length > 0 || barcodesObj.delete.length > 0; @@ -98,7 +98,7 @@ export default class Controller { this.$scope.watcher.notifySaved(); }); } - this.vnApp.showMessage(this.$translate.instant('No changes to save')); + this.vnApp.showError(this.$translate.instant('No changes to save')); } setOldBarcodes(response) { diff --git a/client/item/src/diary/index.html b/client/item/src/diary/index.html index 09e9339e0..ecc4170ac 100644 --- a/client/item/src/diary/index.html +++ b/client/item/src/diary/index.html @@ -24,10 +24,10 @@ Date - State - Origin - Reference - Worker + Id + State + Reference + Worker In Out Balance @@ -37,9 +37,9 @@ {{::sale.date | date:'dd/MM/yyyy HH:mm' }} - {{::sale.alertLevel | dashIfEmpty}} {{::sale.origin | dashIfEmpty}} - {{::sale.reference | dashIfEmpty}} + {{::sale.stateName | dashIfEmpty}} + {{::sale.reference | dashIfEmpty}} {{sale.name | dashIfEmpty}} {{::sale.in | dashIfEmpty}} {{::sale.out | dashIfEmpty}} diff --git a/client/item/src/niche/index.js b/client/item/src/niche/index.js index 9fec4ba91..f483fb1f9 100644 --- a/client/item/src/niche/index.js +++ b/client/item/src/niche/index.js @@ -122,11 +122,11 @@ export default class Controller { }); if (this.$scope.form.$invalid) { - return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); + return this.vnApp.showError(this.$translate.instant('Some fields are invalid')); } if (repeatedWarehouse) { - return this.vnApp.showMessage(this.$translate.instant('The niche must be unique')); + return this.vnApp.showError(this.$translate.instant('The niche must be unique')); } canSubmit = nichesObj.update.length > 0 || nichesObj.create.length > 0 || nichesObj.delete.length > 0; @@ -138,7 +138,7 @@ export default class Controller { this.$scope.watcher.notifySaved(); }); } - this.vnApp.showMessage(this.$translate.instant('No changes to save')); + this.vnApp.showError(this.$translate.instant('No changes to save')); } } diff --git a/client/item/src/niche/niche.spec.js b/client/item/src/niche/niche.spec.js index d3b91be9e..0309d2535 100644 --- a/client/item/src/niche/niche.spec.js +++ b/client/item/src/niche/niche.spec.js @@ -98,7 +98,7 @@ describe('Item', () => { describe('submit()', () => { it("should return an error message 'The niche must be unique' when the niche warehouse isnt unique", () => { controller.$scope.form = {}; - spyOn(controller.vnApp, 'showMessage').and.callThrough(); + spyOn(controller.vnApp, 'showError').and.callThrough(); controller.niches = [ {warehouseFk: 1, code: 123454, itemFk: 1, id: 1}, {warehouseFk: 1, code: 123454, itemFk: 1} @@ -106,7 +106,7 @@ describe('Item', () => { controller.oldNiches = {1: {warehouseFk: 1, id: 1, code: 123454, itemFk: 1}}; controller.submit(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The niche must be unique'); + expect(controller.vnApp.showError).toHaveBeenCalledWith('The niche must be unique'); }); it("should perfom a query to delete niches", () => { @@ -144,7 +144,7 @@ describe('Item', () => { it("should return a message 'No changes to save' when there are no changes to apply", () => { controller.$scope.form = {$setPristine: () => {}}; - spyOn(controller.vnApp, 'showMessage').and.callThrough(); + spyOn(controller.vnApp, 'showError').and.callThrough(); controller.oldNiches = [ {warehouseFk: 1, code: 1, itemFk: 1, id: 1}, {warehouseFk: 2, code: 2, itemFk: 1, id: 2} @@ -152,7 +152,7 @@ describe('Item', () => { controller.niches = []; controller.submit(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save'); + expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save'); }); }); }); diff --git a/client/item/src/tags/tags.spec.js b/client/item/src/tags/tags.spec.js index 41e2380a6..5b3049809 100644 --- a/client/item/src/tags/tags.spec.js +++ b/client/item/src/tags/tags.spec.js @@ -132,7 +132,7 @@ describe('Item', () => { // TODO: Server validation should be implemented xit("should return an error message 'The tag must be unique' when the tag value isnt unique", () => { controller.$.form = []; - spyOn(controller.vnApp, 'showMessage').and.callThrough(); + spyOn(controller.vnApp, 'showError').and.callThrough(); controller.tags = [ {typeFk: 1, value: 123454, itemFk: 1, id: 1}, {typeFk: 1, value: 123454, itemFk: 1} @@ -140,7 +140,7 @@ describe('Item', () => { controller.orgTags = {1: {typeFk: 1, id: 1, value: 123454, itemFk: 1}}; controller.submit(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The tag must be unique'); + expect(controller.vnApp.showError).toHaveBeenCalledWith('The tag must be unique'); }); it("should perfom a query to delete tags", () => { diff --git a/client/item/src/tax/index.js b/client/item/src/tax/index.js index 9ad2ad592..5e5e108f1 100644 --- a/client/item/src/tax/index.js +++ b/client/item/src/tax/index.js @@ -29,7 +29,7 @@ export default class Controller { let url = `/item/api/Items/${this.$stateParams.id}/updateTaxes`; this.$http.post(url, data).then( - () => this.vnApp.showMessage(this._.instant('Data saved!')) + () => this.vnApp.showSuccess(this._.instant('Data saved!')) ); } } diff --git a/client/ticket/src/create/card.html b/client/ticket/src/create/card.html new file mode 100644 index 000000000..e1b7a611d --- /dev/null +++ b/client/ticket/src/create/card.html @@ -0,0 +1,34 @@ +New order + + {{id}}: {{name}} + + + {{nickname}}: {{street}}, {{city}} + + + + + diff --git a/client/ticket/src/create/card.js b/client/ticket/src/create/card.js new file mode 100644 index 000000000..36fee36b3 --- /dev/null +++ b/client/ticket/src/create/card.js @@ -0,0 +1,93 @@ +import ngModule from '../module'; + +class Controller { + constructor($scope, $http, vnApp, $translate) { + this.$scope = $scope; + this.$http = $http; + this.translate = $translate; + this.vnApp = vnApp; + this.ticket = {}; + } + + set ticket(value) { + if (value) { + this._ticket = value; + } + } + + get ticket() { + return this._ticket; + } + + set clientFk(value) { + this.ticket.clientFk = value; + this.addressFk = null; + } + + get clientFk() { + return this.ticket.clientFk; + } + + set addressFk(value) { + this.ticket.addressFk = value; + this.getAvaibleAgencies(); + } + + get addressFk() { + return this.ticket.addressFk; + } + + set landed(value) { + this.ticket.landed = value; + this.getAvaibleAgencies(); + } + + get landed() { + return this.ticket.landed; + } + + get warehouseFk() { + return this.ticket.warehouseFk; + } + + getAvaibleAgencies() { + this.ticket.agencyModeFk = null; + if (this.ticket.landed && this.ticket.addressFk) { + let filter = {addressFk: this.ticket.addressFk, landed: this.ticket.landed}; + filter = encodeURIComponent(JSON.stringify(filter)); + let query = `/api/Agencies/landsThatDay?filter=${filter}`; + this.$http.get(query).then(res => { + this._avaibleAgencies = res.data[0]; + }); + } + } + + onSubmit() { + this.createOrder(); + } + + createOrder() { + let params = { + landed: this.ticket.landed, + addressFk: this.ticket.addressFk, + agencyModeFk: this.ticket.agencyModeFk + }; + + this.$http.post(`order/api/Orders/new`, params).then(res => { + this.vnApp.showSuccess(this.translate.instant('Data saved!')); + return res.data.id; + }).catch(e => { + this.vnApp.showError(this.translate.instant(e.data.error.message)); + }); + } +} + +Controller.$inject = ['$scope', '$http', 'vnApp', '$translate']; + +ngModule.component('vnTicketCreateCard', { + template: require('./card.html'), + controller: Controller, + bindings: { + ticket: ' { +describe('Ticket', () => { describe('Component vnTicketCreateCard', () => { let $componentController; let $scope; @@ -19,7 +19,7 @@ xdescribe('Ticket', () => { controller.item = {id: 3}; })); - describe('set clientFk()', () => { + describe('set clientFk', () => { it(`should set addressFk to null and clientFk to a value`, () => { controller.clientFk = 2; @@ -28,7 +28,7 @@ xdescribe('Ticket', () => { }); }); - describe('set addressFk()', () => { + describe('set addressFk', () => { it(`should set agencyModeFk property to null and addressFk to a value`, () => { controller.addressFk = 101; @@ -37,25 +37,39 @@ xdescribe('Ticket', () => { }); }); - describe('set onSubmit()', () => { - it(`should call createTicket()`, () => { - spyOn(controller, 'createTicket'); - controller.onSubmit(); + describe('getAvaibleAgencies()', () => { + it(`should make a query if landed and addressFk exists`, () => { + controller.ticket.addressFk = 101; + controller.ticket.landed = 101; - expect(controller.createTicket).toHaveBeenCalledWith(); + let filter = {addressFk: controller.ticket.addressFk, landed: controller.ticket.landed}; + filter = encodeURIComponent(JSON.stringify(filter)); + $httpBackend.whenGET(`/api/Agencies/landsThatDay?filter=${filter}`).respond({data: 1}); + $httpBackend.expectGET(`/api/Agencies/landsThatDay?filter=${filter}`); + + controller.getAvaibleAgencies(); + $httpBackend.flush(); }); }); - describe('createTicket()', () => { + describe('onSubmit()', () => { + it(`should call createOrder()`, () => { + spyOn(controller, 'createOrder'); + controller.onSubmit(); + + expect(controller.createOrder).toHaveBeenCalledWith(); + }); + }); + + describe('createOrder()', () => { it(`should make a query`, () => { - controller.ticket.clientFk = 101; controller.ticket.addressFk = 101; controller.ticket.agencyModeFk = 101; - controller.ticket.shipped = 101; + controller.ticket.landed = 101; - $httpBackend.whenPOST('order/api/Orders/new').respond({data: 'item'}); + $httpBackend.whenPOST('order/api/Orders/new').respond({data: 1}); $httpBackend.expectPOST('order/api/Orders/new'); - controller.createTicket(); + controller.createOrder(); $httpBackend.flush(); }); }); diff --git a/client/ticket/src/create/index.html b/client/ticket/src/create/index.html index 1542ffbc4..5e7e469c8 100644 --- a/client/ticket/src/create/index.html +++ b/client/ticket/src/create/index.html @@ -1,18 +1,11 @@ - - - -
-
+
+
- New ticket - + - + +
- +
\ No newline at end of file diff --git a/client/ticket/src/create/index.js b/client/ticket/src/create/index.js index d7a59d800..2c50c1e44 100644 --- a/client/ticket/src/create/index.js +++ b/client/ticket/src/create/index.js @@ -1,20 +1,18 @@ import ngModule from '../module'; class Controller { - constructor($scope, $state) { + constructor($scope, $http, $state) { this.$ = $scope; + this.$http = $http; this.$state = $state; - this.Ticket = {}; } - onSubmit() { - this.$.watcher.submit().then( - json => this.$state.go('ticket.card.data', {id: json.data.id}) - ); + async onSubmit() { + let newOrderID = await this.$.card.createOrder(); + this.$state.go("ticket.card.summary", {id: newOrderID}); } } - -Controller.$inject = ['$scope', '$state']; +Controller.$inject = ['$scope', '$http', '$state']; ngModule.component('vnTicketCreate', { template: require('./index.html'), diff --git a/client/ticket/src/create/index.spec.js b/client/ticket/src/create/index.spec.js index 468e648eb..89a59ca39 100644 --- a/client/ticket/src/create/index.spec.js +++ b/client/ticket/src/create/index.spec.js @@ -15,18 +15,17 @@ describe('Ticket', () => { $componentController = _$componentController_; $scope = $rootScope.$new(); - $scope.card = {createTicket: () => {}}; + $scope.card = {createOrder: () => {}}; $state = _$state_; - $state.go = () => {}; controller = $componentController('vnTicketCreate', {$scope: $scope, $state: $state}); })); describe('onSubmit()', () => { - it(`should call createTicket()`, () => { - spyOn(controller.$.card, 'createTicket'); + it(`should call createOrder()`, () => { + spyOn(controller.$.card, 'createOrder'); controller.onSubmit(); - expect(controller.$.card.createTicket).toHaveBeenCalledWith(); + expect(controller.$.card.createOrder).toHaveBeenCalledWith(); }); xit(`should call go()`, () => { diff --git a/client/ticket/src/create/locale/es.yml b/client/ticket/src/create/locale/es.yml new file mode 100644 index 000000000..df21d09f4 --- /dev/null +++ b/client/ticket/src/create/locale/es.yml @@ -0,0 +1,6 @@ +You can't create an order for a frozen client: No puedes crear una orden a un cliente congelado +You can't create an order for a inactive client: No puedes crear una orden a un cliente inactivo +You can't create an order for a client that doesn't has tax data verified: + No puedes crear una orden a un cliente cuyos datos fiscales no han sido verificados +You can't create an order for a client that has a debt: No puedes crear una orden a un cliente que tiene deuda +New order: Nueva orden \ No newline at end of file diff --git a/client/ticket/src/data/step-one/index.js b/client/ticket/src/data/step-one/index.js index d7d81747b..ff986b426 100644 --- a/client/ticket/src/data/step-one/index.js +++ b/client/ticket/src/data/step-one/index.js @@ -1,5 +1,4 @@ import ngModule from '../../module'; -import {toJsonDate} from 'core/src/lib/date'; class Controller { constructor($scope, $http, $translate, vnApp) { @@ -36,7 +35,7 @@ class Controller { let query = `/ticket/api/sales/${this.ticket.id}/priceDifference`; let data = { - landed: toJsonDate(this.ticket.landed), + landed: this.ticket.landed, addressFk: this.ticket.addressFk, agencyModeFk: this.ticket.agencyModeFk, warehouseFk: this.ticket.warehouseFk diff --git a/client/ticket/src/fetched-tags/index.html b/client/ticket/src/fetched-tags/index.html index a40073577..7b6515d7c 100644 --- a/client/ticket/src/fetched-tags/index.html +++ b/client/ticket/src/fetched-tags/index.html @@ -1,6 +1,6 @@ {{::$ctrl.sale.concept}} - +
{{::ticket.id}} {{::ticket.client.salesPerson.name | dashIfEmpty}} {{::ticket.shipped | date:'dd/MM/yyyy'}} - {{::ticket.shipped | date:'HH:MM'}} + {{::ticket.shipped | date:'HH:mm'}} {{::ticket.nickname}} {{::ticket.address.province.name}} {{::ticket.tracking.state.name}} diff --git a/client/ticket/src/note/index.js b/client/ticket/src/note/index.js index 8c2c602c9..ff9eef7b3 100644 --- a/client/ticket/src/note/index.js +++ b/client/ticket/src/note/index.js @@ -106,11 +106,11 @@ class Controller { }); if (this.$scope.form.$invalid) { - return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); + return this.vnApp.showError(this.$translate.instant('Some fields are invalid')); } if (repeatedType) { - return this.vnApp.showMessage(this.$translate.instant('The observation type must be unique')); + return this.vnApp.showError(this.$translate.instant('The observation type must be unique')); } canSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0; @@ -122,7 +122,7 @@ class Controller { this.$scope.watcher.notifySaved(); }); } - this.vnApp.showMessage(this.$translate.instant('No changes to save')); + this.vnApp.showError(this.$translate.instant('No changes to save')); } $onInit() { diff --git a/client/ticket/src/note/ticket-observation.spec.js b/client/ticket/src/note/ticket-observation.spec.js index f1bbbdd0b..fc2681375 100644 --- a/client/ticket/src/note/ticket-observation.spec.js +++ b/client/ticket/src/note/ticket-observation.spec.js @@ -90,7 +90,7 @@ describe('ticket', () => { it("should return an error message 'Some fields are invalid'", () => { controller.$scope.form = {}; controller.$scope.form.$invalid = true; - spyOn(controller.vnApp, 'showMessage').and.callThrough(); + spyOn(controller.vnApp, 'showError').and.callThrough(); controller.ticketObservations = [ {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}, {observationTypeFk: 1, description: 'one', itemFk: 1} @@ -98,12 +98,12 @@ describe('ticket', () => { controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}}; controller.submit(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Some fields are invalid'); + expect(controller.vnApp.showError).toHaveBeenCalledWith('Some fields are invalid'); }); it("should return an error message 'The observation type must be unique'", () => { controller.$scope.form = {}; - spyOn(controller.vnApp, 'showMessage').and.callThrough(); + spyOn(controller.vnApp, 'showError').and.callThrough(); controller.ticketObservations = [ {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}, {observationTypeFk: 1, description: 'one', itemFk: 1} @@ -111,7 +111,7 @@ describe('ticket', () => { controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}}; controller.submit(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The observation type must be unique'); + expect(controller.vnApp.showError).toHaveBeenCalledWith('The observation type must be unique'); }); it("should perfom a query to delete observations", () => { @@ -149,7 +149,7 @@ describe('ticket', () => { it("should return a message 'No changes to save' when there are no changes to apply", () => { controller.$scope.form = {$setPristine: () => {}}; - spyOn(controller.vnApp, 'showMessage').and.callThrough(); + spyOn(controller.vnApp, 'showError').and.callThrough(); controller.oldObservations = [ {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false}, {id: 2, observationTypeFk: 2, description: 'two', showAddIcon: true} @@ -157,7 +157,7 @@ describe('ticket', () => { controller.ticketObservations = []; controller.submit(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save'); + expect(controller.vnApp.showError).toHaveBeenCalledWith('No changes to save'); }); }); }); diff --git a/client/ticket/src/package/index.js b/client/ticket/src/package/index.js index a3f1119f9..c26be3d21 100644 --- a/client/ticket/src/package/index.js +++ b/client/ticket/src/package/index.js @@ -26,10 +26,10 @@ class Controller { }); if (this.$.form.$invalid) - return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); + return this.vnApp.showError(this.$translate.instant('Some fields are invalid')); if (!this.hasChanges(packagesObj)) - return this.vnApp.showMessage(this.$translate.instant('No changes to save')); + return this.vnApp.showError(this.$translate.instant('No changes to save')); this.$http.post(query, packagesObj).then(res => { this.$.index.accept(); diff --git a/client/ticket/src/sale/index.html b/client/ticket/src/sale/index.html index d1b69c763..5803b9742 100644 --- a/client/ticket/src/sale/index.html +++ b/client/ticket/src/sale/index.html @@ -107,7 +107,7 @@ {{(sale.quantity * sale.price) - ((sale.discount * (sale.quantity * sale.price))/100) | currency:' €':2}} - + No results @@ -197,7 +197,7 @@

New price

-

{{($ctrl.sale.quantity * $ctrl.sale.price) +

{{($ctrl.sale.quantity * $ctrl.editedPrice) - (($ctrl.sale.discount * ($ctrl.sale.quantity * $ctrl.editedPrice))/100) | currency:' €':2}}

- - + + + + + +
diff --git a/client/ticket/src/sale/index.js b/client/ticket/src/sale/index.js index 804211bf9..e18abd4a2 100644 --- a/client/ticket/src/sale/index.js +++ b/client/ticket/src/sale/index.js @@ -51,10 +51,8 @@ class Controller { getVAT() { this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/getVAT`).then(res => { - if (res.data) { - this.VAT = res.data; - this.total = this.subTotal + this.VAT; - } + this.VAT = res.data || 0; + this.total = this.subTotal + this.VAT; }); } @@ -117,6 +115,7 @@ class Controller { let params = {ticketFk: this.$state.params.id, weekDay: day}; this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => { this.$.addTurn.hide(); + this.vnApp.showSuccess(this.translate.instant('Data saved!')); }); } @@ -204,6 +203,19 @@ class Controller { this.$state.go("ticket.card.sale", {id: ticketID}); } + // Focus First Input + focusFirstInput(e) { + let firstFocusable = e.querySelector('input, textarea'); + if (firstFocusable) { + firstFocusable.addEventListener('focus', () => { + firstFocusable.select(); + }); + setTimeout(() => { + firstFocusable.focus(); + }, 200); + } + } + // Slesperson Mana getManaSalespersonMana() { this.$http.get(`/api/Tickets/${this.$state.params.id}/getSalesPersonMana`).then(res => { @@ -232,6 +244,7 @@ class Controller { }; this.$.editPricePopover.parent = event.target; this.$.editPricePopover.show(); + this.focusFirstInput(this.$.editPricePopover.$element[0]); } updatePrice() { @@ -255,11 +268,13 @@ class Controller { }]; this.$.editPopover.parent = event.target; this.$.editPopover.show(); + this.focusFirstInput(this.$.editPopover.$element[0]); } - async showEditDialog() { + showEditDialog() { this.edit = this.getCheckedLines(); this.$.editDialog.show(); + this.focusFirstInput(this.$.editDialog.$element[0]); } hideEditDialog() { @@ -281,27 +296,6 @@ class Controller { }); } - /* updateLine() { - if (this.edit.quantity != this.sale.quantity) { - this.$http.post(`/ticket/api/Sales/updateQuantity`, {id: this.edit.id, quantity: this.edit.quantity}).then(() => { - this.sale.quantity = this.edit.quantity; - }); - } - - if (this.edit.price != this.sale.price) { - this.$http.post(`/ticket/api/Sales/updatePrice`, {id: this.edit.id, price: this.edit.price}).then(() => { - this.sale.price = this.edit.price; - }); - } - - if (this.edit.discount != this.sale.discount) { - this.$http.post(`/ticket/api/Sales/updateDiscount`, {id: this.edit.id, discount: this.edit.discount}).then(() => { - this.sale.discount = this.edit.discount; - }); - } - this.$.edit.hide(); - }*/ - /** * Unmark sale as reserved */ diff --git a/client/ticket/src/sale/locale/es.yml b/client/ticket/src/sale/locale/es.yml index bfeb9cd37..f834f4c23 100644 --- a/client/ticket/src/sale/locale/es.yml +++ b/client/ticket/src/sale/locale/es.yml @@ -11,4 +11,6 @@ New ticket: Nuevo ticket Edit price: Editar precio You are going to delete lines of the ticket: Vas a borrar lineas del ticket Continue anyway?: ¿Estás seguro? -The new quantity should be smaller than the old one: La nueva cantidad debe de ser menor que la anterior \ No newline at end of file +The new quantity should be smaller than the old one: La nueva cantidad debe de ser menor que la anterior +You have to allow pop-ups in your web browser to use this functionality: + Debes permitir los pop-pups en tu navegador para que esta herramienta funcione correctamente \ No newline at end of file diff --git a/client/ticket/src/sale/style.scss b/client/ticket/src/sale/style.scss index abff21c8c..c8d06babc 100644 --- a/client/ticket/src/sale/style.scss +++ b/client/ticket/src/sale/style.scss @@ -52,13 +52,13 @@ vn-ticket-sale { } vn-popover.transfer{ - & table { + table { min-width: 650px; margin-bottom: 10px; } - & i { + vn-icon:nth-child(1) { padding-top: 0.2em; - font-size: 1.8em; + font-size: 1.7em; } } diff --git a/client/ticket/src/summary/index.html b/client/ticket/src/summary/index.html index 3e33e01d8..77d66820d 100644 --- a/client/ticket/src/summary/index.html +++ b/client/ticket/src/summary/index.html @@ -83,6 +83,9 @@ {{::sale.discount}} % {{::sale.quantity * sale.price | currency:'€':2}} + + No results + diff --git a/client/ticket/src/ticket.js b/client/ticket/src/ticket.js index 2632740d6..4212b486a 100644 --- a/client/ticket/src/ticket.js +++ b/client/ticket/src/ticket.js @@ -3,6 +3,7 @@ export * from './module'; import './search-panel'; import './index'; import './create'; +import './create/card'; import './card'; import './descriptor'; import './summary'; diff --git a/e2e/paths/ticket-module/03_list_sale.spec.js b/e2e/paths/ticket-module/03_list_sale.spec.js index f62ac21e6..2f6ec4ab6 100644 --- a/e2e/paths/ticket-module/03_list_sale.spec.js +++ b/e2e/paths/ticket-module/03_list_sale.spec.js @@ -64,11 +64,10 @@ describe('Ticket', () => { .wait(selectors.ticketSales.secondSaleText) .getInnerText(selectors.ticketSales.secondSaleText) .then(value => { - expect(value).toContain('Yellow'); - expect(value).toContain('2'); - expect(value).toContain('€23.50'); + expect(value).toContain('Red'); + expect(value).toContain('€4.50'); expect(value).toContain('0 %'); - expect(value).toContain('€47.00'); + expect(value).toContain('€45.00'); }); }); }); diff --git a/services/client/common/models/credit-classification.json b/services/client/common/models/credit-classification.json index 51bda330a..2e636af63 100644 --- a/services/client/common/models/credit-classification.json +++ b/services/client/common/models/credit-classification.json @@ -33,7 +33,7 @@ "model": "Client", "foreignKey": "client" }, - "creditInsurances": { + "insurances": { "type": "hasMany", "model": "CreditInsurance", "foreignKey": "creditClassification" diff --git a/services/db/install/changes/1.0.8/alertLevel.sql b/services/db/install/changes/1.0.8/alertLevel.sql new file mode 100644 index 000000000..c338d681b --- /dev/null +++ b/services/db/install/changes/1.0.8/alertLevel.sql @@ -0,0 +1,18 @@ +USE `vn`; + +CREATE TABLE `vn`.`alertLevel` ( + `code` VARCHAR(45) CHARACTER SET 'utf8' NOT NULL, + `alertLevel` INT(11) NOT NULL, + PRIMARY KEY (`code`)); + +ALTER TABLE `vn`.`alertLevel` +ADD CONSTRAINT `fk_code_1` + FOREIGN KEY (`code`) + REFERENCES `vn2008`.`state` (`code`) + ON DELETE CASCADE + ON UPDATE CASCADE; + +INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('FREE', '0'); +INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('ON_PREPARATION', '1'); +INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('PACKED', '2'); +INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('DELIVERED', '3'); diff --git a/services/db/install/changes/1.0.8/itemDiary.sql b/services/db/install/changes/1.0.8/itemDiary.sql new file mode 100644 index 000000000..ca853c5af --- /dev/null +++ b/services/db/install/changes/1.0.8/itemDiary.sql @@ -0,0 +1,105 @@ +USE `vn`; +DROP procedure IF EXISTS `itemDiary`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `itemDiary`(IN vItemId INT, IN vWarehouse INT) +BEGIN + DECLARE vDateInventory DATETIME; + DECLARE vCurdate DATE DEFAULT CURDATE(); + -- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance + SELECT Fechainventario INTO vDateInventory FROM vn2008.tblContadores; + SET @a = 0; + SELECT DATE(date) AS date, + alertLevel, + stateName, + origin, + reference, + name, + `in`, + `out`, + @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance + FROM + ( SELECT tr.landed as date, + b.quantity as `in`, + NULL as `out`, + IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, + st.name AS stateName, + s.name as name, + e.ref as reference, + e.id as origin + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.supplier s ON s.id = e.supplierFk + JOIN vn.alertLevel al ON al.alertLevel = + CASE + WHEN tr.isReceived != FALSE THEN 3 + WHEN tr.isDelivered THEN 1 + ELSE 0 + END + JOIN vn.state st ON st.code = al.code + WHERE tr.landed >= vDateInventory + AND vWarehouse = tr.warehouseInFk + AND b.itemFk = vItemId + AND e.isInventory = 0 + + UNION ALL + + SELECT tr.shipped as date, + NULL as `in`, + b.quantity as `out`, + IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, + st.name AS stateName, + s.name as name, + e.ref as reference, + e.id as origin + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.warehouse w ON w.id = tr.warehouseOutFk + JOIN vn.supplier s ON s.id = e.supplierFk + JOIN vn.alertLevel al ON al.alertLevel = + CASE + WHEN tr.isReceived != FALSE THEN 3 + WHEN tr.isDelivered THEN 1 + ELSE 0 + END + JOIN vn.state st ON st.code = al.code + WHERE tr.shipped >= vDateInventory + AND vWarehouse =tr.warehouseOutFk + AND s.id <> 4 + AND b.itemFk = vItemId + AND e.isInventory = 0 + AND w.isFeedStock = 0 + + UNION ALL + + SELECT t.shipped as date, + NULL as `in`, + s.quantity as `out`, + IF(t.shipped < vCurdate,3,IF(t.shipped > vCurdate, 0, IFNULL(ts.alertLevel,0))) as alertLevel, + st.name AS stateName, + t.nickname as name, + t.refFk as reference, + t.id as origin + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + LEFT JOIN vn.ticketState ts ON ts.ticket = t.id + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.alertLevel al ON al.alertLevel = + CASE + WHEN t.shipped < vCurdate THEN 3 + WHEN t.shipped > vCurdate THEN 0 + ELSE IFNULL(ts.alertLevel, 0) + END + JOIN vn.state st ON st.code = al.code + WHERE t.shipped >= vDateInventory + AND s.itemFk = vItemId + AND vWarehouse =t.warehouseFk + ) AS itemDiary + ORDER BY date, alertLevel, `in` DESC; +END$$ + +DELIMITER ; + diff --git a/services/loopback/common/methods/agency/landsThatDay.js b/services/loopback/common/methods/agency/landsThatDay.js new file mode 100644 index 000000000..00184f32f --- /dev/null +++ b/services/loopback/common/methods/agency/landsThatDay.js @@ -0,0 +1,27 @@ +module.exports = Self => { + Self.remoteMethod('landsThatDay', { + description: 'Returns a list of agencies that can land a shipment on a day for an address', + accessType: '', + accepts: [{ + arg: 'filter', + type: 'object', + required: true, + description: 'addressFk' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/landsThatDay`, + verb: 'get' + } + }); + + Self.landsThatDay = async filter => { + let query = `CALL vn.agencyHourGetAgency(?, ?)`; + let result = await Self.rawSql(query, [filter.addressFk, filter.landed]); + + return result; + }; +}; diff --git a/services/loopback/common/methods/client/summary.js b/services/loopback/common/methods/client/summary.js index 95cecbc9d..ab0732032 100644 --- a/services/loopback/common/methods/client/summary.js +++ b/services/loopback/common/methods/client/summary.js @@ -47,6 +47,19 @@ module.exports = Self => { where: {isDefaultAddress: true}, fields: ['nickname', 'street', 'city', 'postalCode'] } + }, + { + relation: 'classifications', + scope: { + include: { + relation: 'insurances', + scope: { + fields: ['id', 'grade', 'created'], + order: 'created DESC' + } + }, + where: {finished: null} + } } ], where: {id: clientId} diff --git a/services/loopback/common/models/agency.js b/services/loopback/common/models/agency.js index 251ba183a..9994624df 100644 --- a/services/loopback/common/models/agency.js +++ b/services/loopback/common/models/agency.js @@ -1,5 +1,5 @@ module.exports = Self => { Self.defineScope({where: {isManaged: {neq: 0}}}); - //require('../methods/agency/sendsThatDay')(Self); + require('../methods/agency/landsThatDay')(Self); require('../methods/agency/getFirstShipped')(Self); }; diff --git a/services/loopback/common/models/client.json b/services/loopback/common/models/client.json index 4c7d4d31b..d80e31d9e 100644 --- a/services/loopback/common/models/client.json +++ b/services/loopback/common/models/client.json @@ -160,7 +160,7 @@ "model": "Greuge", "foreignKey": "clientFk" }, - "creditClassifications": { + "classifications": { "type": "hasMany", "model": "CreditClassification", "foreignKey": "client" diff --git a/services/loopback/server/connectors/vn-mysql.js b/services/loopback/server/connectors/vn-mysql.js new file mode 100644 index 000000000..27f200975 --- /dev/null +++ b/services/loopback/server/connectors/vn-mysql.js @@ -0,0 +1,55 @@ + +var mysql = require('mysql'); +var SqlConnector = require('loopback-connector').SqlConnector; +var MySQL = require('loopback-connector-mysql').MySQL; +var EnumFactory = require('loopback-connector-mysql').EnumFactory; + +exports.initialize = function(dataSource, callback) { + dataSource.driver = mysql; + dataSource.connector = new VnMySQL(dataSource.settings); + dataSource.connector.dataSource = dataSource; + + var modelBuilder = dataSource.modelBuilder; + var defineType = modelBuilder.defineValueType ? + modelBuilder.defineValueType.bind(modelBuilder) : + modelBuilder.constructor.registerType.bind(modelBuilder.constructor); + + defineType(function Point() {}); + + dataSource.EnumFactory = EnumFactory; + + if (callback) { + if (dataSource.settings.lazyConnect) { + process.nextTick(function() { + callback(); + }); + } else { + dataSource.connector.connect(callback); + } + } +}; + +exports.VnMySQL = VnMySQL; + +function VnMySQL(settings) { + SqlConnector.call(this, 'mysql', settings); +} + +VnMySQL.prototype = Object.create(MySQL.prototype); +VnMySQL.constructor = VnMySQL; + +VnMySQL.prototype.toColumnValue = function(prop, val) { + if (val == null || !prop || prop.type !== Date) + return MySQL.prototype.toColumnValue.call(this, prop, val); + + return val.getFullYear() + '-' + + fillZeros(val.getMonth() + 1) + '-' + + fillZeros(val.getDate()) + ' ' + + fillZeros(val.getHours()) + ':' + + fillZeros(val.getMinutes()) + ':' + + fillZeros(val.getSeconds()); + + function fillZeros(v) { + return v < 10 ? '0' + v : v; + } +}; diff --git a/services/loopback/server/datasources.json b/services/loopback/server/datasources.json index e1e46bf4f..25d7d0739 100644 --- a/services/loopback/server/datasources.json +++ b/services/loopback/server/datasources.json @@ -3,7 +3,8 @@ "connector": "memory" }, "vn": { - "connector": "mysql", + "connector": "vn-mysql", + "timezone": "CET", "database": "vn", "debug": false, "host": "${salixHost}", @@ -14,7 +15,7 @@ "acquireTimeout": 20000 }, "salix": { - "connector": "mysql", + "connector": "vn-mysql", "database": "salix", "debug": false, "host": "${salixHost}", @@ -25,7 +26,7 @@ "acquireTimeout": 20000 }, "account": { - "connector": "mysql", + "connector": "vn-mysql", "database": "account", "debug": false, "host": "${salixHost}", @@ -36,7 +37,7 @@ "acquireTimeout": 20000 }, "edi": { - "connector": "mysql", + "connector": "vn-mysql", "database": "edi", "debug": false, "host": "${salixHost}", @@ -47,7 +48,7 @@ "acquireTimeout": 20000 }, "bs": { - "connector": "mysql", + "connector": "vn-mysql", "database": "bs", "debug": false, "host": "${salixHost}", @@ -58,7 +59,7 @@ "acquireTimeout": 20000 }, "hedera": { - "connector": "mysql", + "connector": "vn-mysql", "database": "hedera", "debug": false, "host": "${salixHost}", diff --git a/services/loopback/server/server.js b/services/loopback/server/server.js index 012dd21b7..f8678de06 100644 --- a/services/loopback/server/server.js +++ b/services/loopback/server/server.js @@ -1,9 +1,24 @@ let loopback = require('loopback'); let boot = require('loopback-boot'); +let DataSource = require('loopback-datasource-juggler').DataSource; let fs = require('fs-extra'); let i18n = require('i18n'); let path = require('path'); +let _resolveConnector = DataSource._resolveConnector; + +DataSource._resolveConnector = function(name) { + let testPath = `${__dirname}/connectors/${name}.js`; + + if (fs.existsSync(testPath)) + return { + connector: require(testPath), + error: null + }; + + return _resolveConnector.apply(this, arguments); +}; + module.exports = { loopback: loopback, boot: vnBoot diff --git a/services/mailer/application/config/datasources.json b/services/mailer/application/config/datasources.json index 6d489ec36..5bcaf6dae 100644 --- a/services/mailer/application/config/datasources.json +++ b/services/mailer/application/config/datasources.json @@ -3,8 +3,8 @@ "port": 3000, "debug": false, "defaultLanguage": "es", - "senderMail": "noreply@localhost", - "senderName": "MySender" + "senderMail": "joan@verdnatura.es", + "senderName": "VerdNatura" }, "mysql": { "host": "localhost", @@ -14,12 +14,12 @@ "password": "root" }, "smtp": { - "host": "localhost", + "host": "smtp.verdnatura.es", "port": 465, "secure": true, "auth": { - "user": "noreply", - "pass": "" + "user": "joan", + "pass": "CLed3ejl$" }, "tls": { "rejectUnauthorized": false diff --git a/services/order/common/methods/new.js b/services/order/common/methods/new.js new file mode 100644 index 000000000..02154e337 --- /dev/null +++ b/services/order/common/methods/new.js @@ -0,0 +1,51 @@ +module.exports = Self => { + Self.remoteMethod('new', { + description: 'Create a new order and returns the new ID', + accessType: 'WRITE', + accepts: [{ + arg: 'params', + type: 'object', + http: {source: 'body'} + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/new`, + verb: 'post' + } + }); + + Self.new = async params => { + let cli = await Self.app.models.Address.findOne({where: {id: params.addressFk}, fields: 'clientFk'}); + + let client = await Self.app.models.Client.findOne({ + where: {id: cli.clientFk}, + fields: ['isTaxDataChecked', 'isFreezed', 'isActive'] + }); + + if (client.isFreezed) + throw new Error(`You can't create an order for a frozen client`); + + if (!client.isActive) + throw new Error(`You can't create an order for a inactive client`); + + if (!client.isTaxDataChecked) + throw new Error(`You can't create an order for a client that doesn't has tax data verified`); + + let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`; + let clientDebt = await Self.rawSql(query, [cli.clientFk]); + if (clientDebt[0].debt > 0) + throw new Error(`You can't create an order for a client that has a debt`); + + query = `CALL vn.orderListCreate(?, ?, ?, ?);`; + result = await Self.rawSql(query, [ + params.landed, + params.agencyModeFk, + params.addressFk, + "SALIX" + ]); + return result[0].vOrderId; + }; +}; diff --git a/services/order/common/models/order.js b/services/order/common/models/order.js new file mode 100644 index 000000000..966d2750f --- /dev/null +++ b/services/order/common/models/order.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/new')(Self); +};