Sale tracking get state from saleTracking instead of ticket. #695

This commit is contained in:
Joan Sanchez 2018-10-01 08:17:36 +02:00
parent 12824b1564
commit 1e604d92b4
3 changed files with 25 additions and 36 deletions

View File

@ -15,9 +15,9 @@
<vn-thead>
<vn-tr>
<vn-th></vn-th>
<vn-th field="id" default-order="DESC">Id</vn-th>
<vn-th field="id">Id</vn-th>
<vn-th field="amount" number>Amount</vn-th>
<vn-th field="created">Payed</vn-th>
<vn-th field="created" default-order="DESC">Payed</vn-th>
<vn-th></vn-th>
</vn-tr>
</vn-thead>

View File

@ -4,8 +4,7 @@
filter="{}"
link="{ticketFk: $ctrl.$stateParams.id}"
limit="20"
data="sales"
on-data-change="$ctrl.getTags()">
data="sales">
</vn-crud-model>
<vn-vertical>
<vn-card pad-large>

View File

@ -1,3 +1,6 @@
const ParameterizedSQL = require('vn-loopback/node_modules/loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('listSaleTracking', {
description: 'Returns all ticket sale trackings',
@ -20,40 +23,27 @@ module.exports = Self => {
});
Self.listSaleTracking = async filter => {
let where = '';
let limit = '';
let order = '';
let params;
let stmt = new ParameterizedSQL(`
SELECT
st.id,
s.ticketFk,
s.quantity,
s.concept,
s.itemFk,
st.originalQuantity,
st.created,
st.workerFk,
w.firstName,
w.name,
ste.name AS state
FROM saleTracking st
JOIN sale s ON s.id = st.saleFk
JOIN worker w ON w.id = st.workerFk
JOIN state ste ON ste.id = st.stateFk`);
if (filter) {
let connector = Self.dataSource.connector;
if (filter.where) {
where = 'WHERE s.ticketFk = ?';
params = [filter.where.ticketFk];
}
stmt.merge(Self.buildSuffix(filter));
limit = connector._buildLimit(null, filter.limit, filter.skip);
order = connector.buildOrderBy('Item', filter.order);
}
let query = `SELECT
st.id,
s.quantity,
s.concept,
s.itemFk,
st.originalQuantity,
st.created,
st.workerFk,
w.firstName,
w.name,
ste.name AS state
FROM saleTracking st
JOIN sale s ON s.id = st.saleFK
JOIN worker w ON w.id = st.workerFk
JOIN ticketState ts ON ts.ticketFk = s.ticketFk
JOIN state ste ON ste.id = ts.stateFK ${where} ${order} ${limit}`;
let trackings = await Self.rawSql(query, params);
let trackings = await Self.rawStmt(stmt);
let salesFilter = {
include: [