first commit
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
249c6b1bec
commit
d72f241946
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,22 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('collectionGet', {
|
||||
description: 'Get pending collections from a worker',
|
||||
accessType: 'WRITE',
|
||||
returns: {
|
||||
type: 'Object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/collectionGet`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.collectionGet = async ctx => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const query = `CALL vn.collection_get(?)`;
|
||||
const [result] = await Self.rawSql(query, [userId]);
|
||||
|
||||
return result;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,120 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('collectionNew', {
|
||||
description: 'Make a new collection of tickets',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'collectionFk',
|
||||
type: 'Number',
|
||||
required: false,
|
||||
description: 'The collection id'
|
||||
}, {
|
||||
arg: 'sectorFk',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The sector of worker'
|
||||
}],
|
||||
returns: {
|
||||
type: 'Object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/collectionNew`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.collectionNew = async(ctx, collectionFk, sectorFk) => {
|
||||
let query = '';
|
||||
|
||||
if (!collectionFk) {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
query = `CALL vn.collection_newBeta(?,?)`;
|
||||
const [result] = await Self.rawSql(query, [sectorFk, userId]);
|
||||
if (result.length == 0)
|
||||
throw new Error(`No collections for today`);
|
||||
|
||||
collectionFk = result[0].vCollectionFk;
|
||||
}
|
||||
|
||||
query = `CALL vn.collectionTicket_get(?)`;
|
||||
const [tickets] = await Self.rawSql(query, [collectionFk]);
|
||||
|
||||
query = `CALL vn.collectionSale_get(?)`;
|
||||
const [sales] = await Self.rawSql(query, [collectionFk]);
|
||||
|
||||
query = `CALL vn.collectionPlacement_get(?)`;
|
||||
const [placements] = await Self.rawSql(query, [collectionFk]);
|
||||
|
||||
return makeCollection(tickets, sales, placements);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a collection json
|
||||
* @param {*} tickets - Request tickets
|
||||
* @param {*} sales - Request sales
|
||||
* @param {*} placements - Request placements
|
||||
* @return {Object} Collection JSON
|
||||
*/
|
||||
async function makeCollection(tickets, sales, placements) {
|
||||
let collection = [];
|
||||
|
||||
for (let i = 0; i < tickets.length; i++) {
|
||||
let ticket = {};
|
||||
ticket['ticketFk'] = tickets[i]['ticketFk'];
|
||||
ticket['level'] = tickets[i]['level'];
|
||||
ticket['agencyName'] = tickets[i]['agencyName'];
|
||||
ticket['warehouseFk'] = tickets[i]['warehouseFk'];
|
||||
ticket['salesPersonFk'] = tickets[i]['salesPersonFk'];
|
||||
|
||||
let ticketSales = [];
|
||||
|
||||
for (let x = 0; x < sales.length; x++) {
|
||||
if (sales[x]['ticketFk'] == ticket['ticketFk']) {
|
||||
let sale = {};
|
||||
|
||||
sale['ticketFk'] = sales[x]['ticketFk'];
|
||||
sale['saleFk'] = sales[x]['saleFk'];
|
||||
sale['itemFk'] = sales[x]['itemFk'];
|
||||
sale['quantity'] = sales[x]['quantity'];
|
||||
sale['longName'] = sales[x]['longName'];
|
||||
sale['size'] = sales[x]['size'];
|
||||
sale['color'] = sales[x]['color'];
|
||||
sale['discount'] = sales[x]['discount'];
|
||||
sale['price'] = sales[x]['price'];
|
||||
sale['stems'] = sales[x]['stems'];
|
||||
sale['category'] = sales[x]['category'];
|
||||
sale['origin'] = sales[x]['origin'];
|
||||
sale['clientFk'] = sales[x]['clientFk'];
|
||||
sale['productor'] = sales[x]['productor'];
|
||||
sale['reserved'] = sales[x]['reserved'];
|
||||
sale['isPreviousPrepared'] = sales[x]['isPreviousPrepared'];
|
||||
sale['isPrepared'] = sales[x]['isPrepared'];
|
||||
sale['isControlled'] = sales[x]['isControlled'];
|
||||
|
||||
let salePlacements = [];
|
||||
|
||||
for (let z = 0; z < placements.length; z++) {
|
||||
if (placements[z]['saleFk'] == sale['saleFk']) {
|
||||
let placement = {};
|
||||
placement['saleFk'] = placements[z]['saleFk'];
|
||||
placement['itemFk'] = placements[z]['itemFk'];
|
||||
placement['placement'] = placements[z]['placement'];
|
||||
placement['shelving'] = placements[z]['shelving'];
|
||||
placement['created'] = placements[z]['created'];
|
||||
placement['visible'] = placements[z]['visible'];
|
||||
placement['order'] = placements[z]['order'];
|
||||
placement['grouping'] = placements[z]['grouping'];
|
||||
salePlacements.push(placement);
|
||||
}
|
||||
}
|
||||
sale['placements'] = salePlacements;
|
||||
ticketSales.push(sale);
|
||||
}
|
||||
}
|
||||
ticket['sales'] = ticketSales;
|
||||
collection.push(ticket);
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getSectors', {
|
||||
description: 'Get all sectors',
|
||||
accessType: 'WRITE',
|
||||
returns: {
|
||||
type: 'Object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getSectors`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getSectors = async ctx => {
|
||||
const query = `CALL vn.sector_get()`;
|
||||
const [result] = await Self.rawSql(query, []);
|
||||
return result;
|
||||
};
|
||||
};
|
|
@ -14,6 +14,9 @@
|
|||
"Container": {
|
||||
"dataSource": "storage"
|
||||
},
|
||||
"Collection": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"Chat": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/collection/collectionGet')(Self);
|
||||
require('../methods/collection/collectionNew')(Self);
|
||||
require('../methods/collection/getSectors')(Self);
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "Collection",
|
||||
"base": "VnModel",
|
||||
"acls": [{
|
||||
"property": "validations",
|
||||
"accessType": "EXECUTE",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}]
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue