Ticket summary. #213

This commit is contained in:
Joan Sanchez 2018-04-17 14:49:55 +02:00
parent f95a2f646b
commit 5e09df1c9d
13 changed files with 171 additions and 32 deletions

View File

@ -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'),

View File

@ -0,0 +1,9 @@
vn-label-value {
& vn-label {
color: #9b9b9b
}
& span {
color: #222222
}
}

View File

@ -14,7 +14,7 @@
</vn-vertical>
</vn-auto>
<vn-one margin-medium>
<vn-vertical>
<vn-vertical name="basicData">
<h5 translate>Basic data</h5>
<vn-label-value label="Name"
value="{{$ctrl.item.name}}">
@ -40,7 +40,7 @@
</vn-vertical>
</vn-one>
<vn-one margin-medium>
<vn-vertical>
<vn-vertical name="tax">
<h5 translate>Tax</h5>
<vn-label-value label="{{tax.country.country}}" ng-repeat="tax in $ctrl.taxes track by $index"
value="{{tax.taxClass.description}}">
@ -50,21 +50,23 @@
</vn-horizontal>
<vn-horizontal>
<vn-one margin-medium>
<vn-vertical name="tags">
<h5 translate>Tags</h5>
<vn-label-value label="{{tag.tag.name}}" ng-repeat="tag in $ctrl.tags track by tag.id"
value="{{tag.value}}">
</vn-label-value>
</vn-vertical>
</vn-one>
<vn-one margin-medium>
<vn-vertical>
<h5 translate>Nicho</h5>
<vn-vertical name="niche">
<h5 translate>Niche</h5>
<vn-label-value label="{{niche.warehouse.name}}" ng-repeat="niche in $ctrl.niches track by $index"
value="{{niche.code}}">
</vn-label-value>
</vn-vertical>
</vn-one>
<vn-one margin-medium>
<vn-vertical>
<vn-vertical name="botanical">
<h5 translate>Botanical</h5>
<vn-label-value label="Botanical"
value="{{$ctrl.item.botanical.botanical}}">
@ -78,7 +80,7 @@
</vn-vertical>
</vn-one>
<vn-one margin-medium>
<vn-vertical>
<vn-vertical name="barcode">
<h5 translate>Barcode</h5>
<p ng-repeat="barcode in $ctrl.barcodes track by $index">
<b>{{barcode.code}}</b>

View File

@ -132,11 +132,6 @@ button {
@extend .vn-clickable;
}
vn-label {
font-size: .9em;
color: #c4c4c4
}
vn-button-bar {
display: block;
margin-top: $margin-small;

View File

@ -48,3 +48,5 @@ Tracking: Revisión
Volume: Volumen
Warehouse: Almacén
Worker: Trabajador
Package size: Bultos
VAT: IVA

View File

@ -46,7 +46,7 @@
<vn-one class="ticketSummary__taxes">
<section>
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.summary.subTotal | currency:' €':2}}</p>
<p><vn-label translate>BAT</vn-label> {{$ctrl.summary.totalTax | currency:' €':2}}</p>
<p><vn-label translate>VAT</vn-label> {{$ctrl.summary.totalTax | currency:' €':2}}</p>
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.summary.total | currency:' €':2}}</strong></p>
</section>

View File

@ -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;
};
};

View File

@ -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;
};
};

View File

@ -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();
});
});
});

View File

@ -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();
});
});
});

View File

@ -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();
});
});
});
*/

View File

@ -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;
}
};

View File

@ -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);
};