From 5e09df1c9dd046dddfc60a1a1893928da237ce3a Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 17 Apr 2018 14:49:55 +0200 Subject: [PATCH] Ticket summary. #213 --- .../src/components/label-value/label-value.js | 1 + .../src/components/label-value/style.scss | 9 +++++ client/item/src/summary/summary.html | 22 ++++++----- client/salix/src/styles/misc.scss | 5 --- client/ticket/src/locale/es.yml | 2 + client/ticket/src/summary/ticket-summary.html | 2 +- .../common/methods/ticket/get-taxes.js | 28 ++++++++++++++ .../common/methods/ticket/get-total.js | 28 ++++++++++++++ .../methods/ticket/specs/get-taxes.spec.js | 18 +++++++++ .../methods/ticket/specs/get-total.spec.js | 26 +++++++++++++ .../methods/ticket/specs/summary.spec.js | 22 +++++++++++ .../loopback/common/methods/ticket/summary.js | 38 +++++++++++-------- services/loopback/common/models/ticket.js | 2 + 13 files changed, 171 insertions(+), 32 deletions(-) create mode 100644 client/core/src/components/label-value/style.scss create mode 100644 services/loopback/common/methods/ticket/get-taxes.js create mode 100644 services/loopback/common/methods/ticket/get-total.js create mode 100644 services/loopback/common/methods/ticket/specs/get-taxes.spec.js create mode 100644 services/loopback/common/methods/ticket/specs/get-total.spec.js create mode 100644 services/loopback/common/methods/ticket/specs/summary.spec.js diff --git a/client/core/src/components/label-value/label-value.js b/client/core/src/components/label-value/label-value.js index b81786157..6b203c18a 100644 --- a/client/core/src/components/label-value/label-value.js +++ b/client/core/src/components/label-value/label-value.js @@ -1,5 +1,6 @@ import ngModule from '../../module'; import Component from '../../lib/component'; +import './style.scss'; ngModule.component('vnLabelValue', { template: require('../label-value/label-value.html'), diff --git a/client/core/src/components/label-value/style.scss b/client/core/src/components/label-value/style.scss new file mode 100644 index 000000000..cbd90f52c --- /dev/null +++ b/client/core/src/components/label-value/style.scss @@ -0,0 +1,9 @@ +vn-label-value { + & vn-label { + color: #9b9b9b + } + + & span { + color: #222222 + } +} \ No newline at end of file diff --git a/client/item/src/summary/summary.html b/client/item/src/summary/summary.html index 1abacd9d6..82f04abf2 100644 --- a/client/item/src/summary/summary.html +++ b/client/item/src/summary/summary.html @@ -14,7 +14,7 @@ - +
Basic data
@@ -40,7 +40,7 @@
- +
Tax
@@ -50,21 +50,23 @@ -
Tags
- - + +
Tags
+ + +
- -
Nicho
+ +
Niche
- +
Botanical
@@ -78,7 +80,7 @@
- +
Barcode

{{barcode.code}} diff --git a/client/salix/src/styles/misc.scss b/client/salix/src/styles/misc.scss index aef35f9c4..bf7b8ab23 100644 --- a/client/salix/src/styles/misc.scss +++ b/client/salix/src/styles/misc.scss @@ -132,11 +132,6 @@ button { @extend .vn-clickable; } -vn-label { - font-size: .9em; - color: #c4c4c4 -} - vn-button-bar { display: block; margin-top: $margin-small; diff --git a/client/ticket/src/locale/es.yml b/client/ticket/src/locale/es.yml index 4710e2647..7e0e01be4 100644 --- a/client/ticket/src/locale/es.yml +++ b/client/ticket/src/locale/es.yml @@ -48,3 +48,5 @@ Tracking: Revisión Volume: Volumen Warehouse: Almacén Worker: Trabajador +Package size: Bultos +VAT: IVA \ No newline at end of file diff --git a/client/ticket/src/summary/ticket-summary.html b/client/ticket/src/summary/ticket-summary.html index e9444aabb..e59b8a73a 100644 --- a/client/ticket/src/summary/ticket-summary.html +++ b/client/ticket/src/summary/ticket-summary.html @@ -46,7 +46,7 @@

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

-

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

+

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

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

diff --git a/services/loopback/common/methods/ticket/get-taxes.js b/services/loopback/common/methods/ticket/get-taxes.js new file mode 100644 index 000000000..4ca66f72d --- /dev/null +++ b/services/loopback/common/methods/ticket/get-taxes.js @@ -0,0 +1,28 @@ +module.exports = Self => { + Self.remoteMethod('getTaxes', { + description: 'Returns ticket taxes', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'ticket id', + http: {source: 'path'} + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/:id/getTaxes`, + verb: 'GET' + } + }); + + Self.getTaxes = async ticketFk => { + let query = `CALL vn.ticketGetTaxAdd(?)`; + let [taxes] = await Self.rawSql(query, [ticketFk]); + + return taxes; + }; +}; \ No newline at end of file diff --git a/services/loopback/common/methods/ticket/get-total.js b/services/loopback/common/methods/ticket/get-total.js new file mode 100644 index 000000000..b743de090 --- /dev/null +++ b/services/loopback/common/methods/ticket/get-total.js @@ -0,0 +1,28 @@ +module.exports = Self => { + Self.remoteMethod('getTotal', { + description: 'Returns the total of a ticket', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'ticket id', + http: {source: 'path'} + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/:id/getTotal`, + verb: 'GET' + } + }); + + Self.getTotal = async ticketFk => { + let query = `SELECT vn.ticketGetTotal(?) AS amount`; + let [total] = await Self.rawSql(query, [ticketFk]); + + return total.amount ? total.amount : 0.00; + }; +}; \ No newline at end of file diff --git a/services/loopback/common/methods/ticket/specs/get-taxes.spec.js b/services/loopback/common/methods/ticket/specs/get-taxes.spec.js new file mode 100644 index 000000000..f7a4fbb70 --- /dev/null +++ b/services/loopback/common/methods/ticket/specs/get-taxes.spec.js @@ -0,0 +1,18 @@ +const getTaxes = require('../get-taxes'); +const {rawSql} = require('../../../test-helpers/rawSql'); +const model = { + remoteMethod: () => {} +}; + +rawSql(model); +getTaxes(model); + +describe('ticket getTaxes()', () => { + it('should call the getTaxes method', done => { + model.getTaxes(1) + .then(response => { + expect(response[0].tax).toEqual(1.05); + done(); + }); + }); +}); diff --git a/services/loopback/common/methods/ticket/specs/get-total.spec.js b/services/loopback/common/methods/ticket/specs/get-total.spec.js new file mode 100644 index 000000000..73adcb87e --- /dev/null +++ b/services/loopback/common/methods/ticket/specs/get-total.spec.js @@ -0,0 +1,26 @@ +const getTotal = require('../get-total'); +const {rawSql} = require('../../../test-helpers/rawSql'); +const model = { + remoteMethod: () => {} +}; + +rawSql(model); +getTotal(model); + +describe('ticket getTotal()', () => { + it('should call the getTotal method and return the response', done => { + model.getTotal(1) + .then(response => { + expect(response).toEqual(11.55); + done(); + }); + }); + + it(`should call the getTotal method and return zero if doesn't have lines`, done => { + model.getTotal(13) + .then(response => { + expect(response).toEqual(0); + done(); + }); + }); +}); diff --git a/services/loopback/common/methods/ticket/specs/summary.spec.js b/services/loopback/common/methods/ticket/specs/summary.spec.js new file mode 100644 index 000000000..5b1c3f398 --- /dev/null +++ b/services/loopback/common/methods/ticket/specs/summary.spec.js @@ -0,0 +1,22 @@ +/* let Jasmine = require('jasmine'); +const {getTicketData} = require('../summary'); + +const summary = require('../summary'); +const model = { + remoteMethod: () => {} +}; + +summary(model); + +fdescribe('ticket summary()', () => { + describe('getTicketData()', () => { + it('should sum all sales price', done => { + let result = getTicketData(model, 1); + + expect(result).toEqual("pepinillos"); + done(); + }); + }); +}); + + */ \ No newline at end of file diff --git a/services/loopback/common/methods/ticket/summary.js b/services/loopback/common/methods/ticket/summary.js index 9e937a8a5..8e59d22d4 100644 --- a/services/loopback/common/methods/ticket/summary.js +++ b/services/loopback/common/methods/ticket/summary.js @@ -22,8 +22,10 @@ module.exports = Self => { Self.summary = async ticketFk => { let models = Self.app.models; let summaryObj = await getTicketData(Self, ticketFk); - summaryObj.sales = await getSales(models.Sale, ticketFk); + summaryObj.subTotal = getSubTotal(summaryObj.sales); + summaryObj.totalTax = await getTotalTax(models.Ticket, ticketFk); + summaryObj.total = await models.Ticket.getTotal(ticketFk); return summaryObj; }; @@ -95,26 +97,30 @@ module.exports = Self => { }, fields: ['itemFk', 'name'] } - }, - { - relation: 'isChecked', - scope: { - fields: ['isChecked'] - } }] }; return await Sale.find(filter); } - /* async function getRecoveries(recovery, clientId) { - let filter = { - where: { - and: [{clientFk: clientId}, {or: [{finished: null}, {finished: {gt: Date.now()}}]}] - }, - limit: 1 - }; + function getSubTotal(sales) { + let subTotal = 0.00; - return await recovery.findOne(filter); - } */ + sales.forEach(sale => { + subTotal+= sale.quantity * sale.price; + }); + + return subTotal; + } + + async function getTotalTax(ticket, ticketFk) { + let totalTax = 0.00; + let taxes = await ticket.getTaxes(ticketFk); + + taxes.forEach(tax => { + totalTax += tax.tax; + }); + + return totalTax; + } }; diff --git a/services/loopback/common/models/ticket.js b/services/loopback/common/models/ticket.js index 39b6624c9..967018e13 100644 --- a/services/loopback/common/models/ticket.js +++ b/services/loopback/common/models/ticket.js @@ -4,4 +4,6 @@ module.exports = function(Self) { require('../methods/ticket/filter')(Self); require('../methods/ticket/get-volume')(Self); require('../methods/ticket/summary')(Self); + require('../methods/ticket/get-total')(Self); + require('../methods/ticket/get-taxes')(Self); };