diff --git a/client/order/src/card/index.js b/client/order/src/card/index.js index 9a08a9ddb..71119ad9a 100644 --- a/client/order/src/card/index.js +++ b/client/order/src/card/index.js @@ -47,7 +47,7 @@ class Controller { let query = `/order/api/Orders/${this.$state.params.id}/getTotal`; this.$http.get(query).then(res => { if (res.data) { - this.order.total = res.data.total; + this.order.total = res.data; } }); } diff --git a/client/order/src/card/index.spec.js b/client/order/src/card/index.spec.js index 46bfec136..3d843852a 100644 --- a/client/order/src/card/index.spec.js +++ b/client/order/src/card/index.spec.js @@ -48,7 +48,7 @@ describe('Order', () => { describe('getTotal()', () => { it(`should make a query and save the data in order.total`, () => { - $httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond({total: '20M'}); + $httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}/getTotal`).respond('20M'); controller.getTotal(); $httpBackend.flush(); diff --git a/client/order/src/summary/index.html b/client/order/src/summary/index.html index c5fdbff8b..511c49454 100644 --- a/client/order/src/summary/index.html +++ b/client/order/src/summary/index.html @@ -1,9 +1,94 @@ - - - - -
Order
-
-
-
-
\ No newline at end of file + + + +
{{$ctrl.summary.id}} - {{$ctrl.summary.client.name}} - {{$ctrl.summary.client.salesPerson.id}}
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Subtotal {{::$ctrl.summary.subTotal | currency:' €':2}}

+

VAT {{::$ctrl.summary.VAT | currency:' €':2}}

+

Total {{::$ctrl.summary.total | currency:' €':2}}

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
ItemDescriptionQuantityPriceAmount
+ + + + + + {{("000000"+row.itemFk).slice(-6)}} + + {{::row.quantity}}{{::row.price | currency:'€':2}}{{::row.quantity * row.price | currency:'€':2}}
No results
+
+
+
+ + diff --git a/client/order/src/summary/index.js b/client/order/src/summary/index.js index 8ce557321..ac77972d8 100644 --- a/client/order/src/summary/index.js +++ b/client/order/src/summary/index.js @@ -1,12 +1,55 @@ import ngModule from '../module'; +import './style.scss'; class Controller { - constructor($http) { + constructor($scope, $http, $state) { + this.$scope = $scope; this.$http = $http; + this.$state = $state; + this.setSummary(); } + + setSummary() { + this.$http.get(`/order/api/Orders/${this.$state.params.id}/summary`).then(res => { + if (res && res.data) { + this.summary = res.data; + console.log(res.data); + } + }); + } + + get formattedAddress() { + if (!this.summary) return; + + let address = this.summary.address; + let province = address.province ? `(${address.province.name})` : ''; + + return `${address.street} - ${address.city} ${province}`; + } + +/* showDescriptor(event, itemFk) { + this.quicklinks = { + btnThree: { + icon: 'icon-transaction', + state: `item.card.diary({ + id: ${itemFk}, + warehouseFk: ${this.ticket.warehouseFk}, + ticketFk: ${this.ticket.id} + })`, + tooltip: 'Item diary' + } + }; + this.$scope.descriptor.itemFk = itemFk; + this.$scope.descriptor.parent = event.target; + this.$scope.descriptor.show(); + } + + onDescriptorLoad() { + this.$scope.popover.relocate(); + } */ } -Controller.$inject = ['$http']; +Controller.$inject = ['$scope', '$http', '$state']; ngModule.component('vnOrderSummary', { template: require('./index.html'), diff --git a/client/order/src/summary/index.spec.js b/client/order/src/summary/index.spec.js new file mode 100644 index 000000000..74a351927 --- /dev/null +++ b/client/order/src/summary/index.spec.js @@ -0,0 +1,50 @@ +import './index'; + +describe('Ticket', () => { + describe('Component vnTicketSummary', () => { + let $componentController; + let controller; + let $httpBackend; + + beforeEach(() => { + angular.mock.module('ticket'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { + $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + controller = $componentController('vnTicketSummary'); + controller.ticket = {id: 1}; + })); + + describe('ticket()', () => { + it('should perform a GET query and define summary property', () => { + let res = {id: 1, nickname: 'Batman'}; + $httpBackend.when('GET', `/ticket/api/Tickets/1/summary`).respond(200, res); + $httpBackend.expect('GET', `/ticket/api/Tickets/1/summary`); + controller.ticket = {id: 1}; + $httpBackend.flush(); + + expect(controller.summary).toBeDefined(); + expect(controller.summary.nickname).toEqual('Batman'); + }); + }); + + describe('formattedAddress()', () => { + it('should return a full fromatted address with city and province', () => { + controller.summary = { + address: { + province: { + name: 'Gotham' + }, + street: '1007 Mountain Drive', + city: 'Gotham' + } + }; + + expect(controller.formattedAddress).toEqual('1007 Mountain Drive - Gotham (Gotham)'); + }); + }); + }); +}); diff --git a/client/order/src/summary/style.scss b/client/order/src/summary/style.scss new file mode 100644 index 000000000..ca61ee97c --- /dev/null +++ b/client/order/src/summary/style.scss @@ -0,0 +1,25 @@ +.ticketSummary { + .ticketSummary__data { + vn-one { + padding-right: 20px + } + + vn-one:last-child { + padding-right: 0 + } + } + + .ticketSummary__notes { + max-width: 18em + } + + .ticketSummary__taxes { + max-width: 15em; + + & section { + border: 1px solid #CCC; + text-align: right; + padding: 10px + } + } +} \ No newline at end of file diff --git a/services/order/common/methods/order/getTotal.js b/services/order/common/methods/order/getTotal.js index bc2cf1471..d4808054d 100644 --- a/services/order/common/methods/order/getTotal.js +++ b/services/order/common/methods/order/getTotal.js @@ -23,6 +23,6 @@ module.exports = Self => { let query = `SELECT hedera.orderGetTotal(?) total;`; let [total] = await Self.rawSql(query, [orderFk]); - return total; + return total.total; }; }; diff --git a/services/order/common/methods/order/specs/getTaxes.spec.js b/services/order/common/methods/order/specs/getTaxes.spec.js index 1728cdc0c..9aaacdc99 100644 --- a/services/order/common/methods/order/specs/getTaxes.spec.js +++ b/services/order/common/methods/order/specs/getTaxes.spec.js @@ -16,7 +16,7 @@ describe('order getTaxes()', () => { it('should call the getTaxes method and return the taxes if its called with a known id', async() => { let result = await app.models.Order.getTaxes(1); - expect(result[0].tax).toEqual(0.95); + expect(result[0].tax).toEqual(9.49); expect(result.length).toEqual(1); }); }); diff --git a/services/order/common/methods/order/summary.js b/services/order/common/methods/order/summary.js new file mode 100644 index 000000000..6a1cfeacb --- /dev/null +++ b/services/order/common/methods/order/summary.js @@ -0,0 +1,87 @@ +module.exports = Self => { + Self.remoteMethod('summary', { + description: 'Returns a summary for a given order id', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'order id', + http: {source: 'path'} + }], + returns: { + type: [this.modelName], + root: true + }, + http: { + path: `/:id/summary`, + verb: 'GET' + } + }); + + Self.summary = async orderId => { + let models = Self.app.models; + let summary = await getOrderData(Self, orderId); + summary.subTotal = getSubTotal(summary.rows); + summary.VAT = await models.Order.getVAT(orderId); + summary.total = await models.Order.getTotal(orderId); + + return summary; + }; + + async function getOrderData(Self, orderId) { + let filter = { + include: [ + {relation: 'agencyMode', scope: {fields: ['name']}}, + { + relation: 'client', + scope: { + fields: ['salesPersonFk', 'name'], + include: { + relation: 'salesPerson', + fields: ['firstName', 'name'] + } + } + }, + { + relation: 'address', + scope: { + fields: ['street', 'city', 'provinceFk', 'phone', 'nickname'], + include: { + relation: 'province', + scope: { + fields: ['name'] + } + } + } + }, + { + relation: 'rows', + scope: { + include: { + relation: 'item', + scope: { + include: { + relation: 'tags' + } + } + } + } + } + ], + where: {id: orderId} + }; + + return await Self.findOne(filter); + } + + function getSubTotal(rows) { + let subTotal = 0.00; + + rows().forEach(row => { + subTotal += row.quantity * row.price; + }); + + return subTotal; + } +};