diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..f0821349b Binary files /dev/null and b/.DS_Store differ diff --git a/back/.DS_Store b/back/.DS_Store new file mode 100644 index 000000000..a15d86adb Binary files /dev/null and b/back/.DS_Store differ diff --git a/back/methods/.DS_Store b/back/methods/.DS_Store new file mode 100644 index 000000000..810045cc9 Binary files /dev/null and b/back/methods/.DS_Store differ diff --git a/back/methods/collection/collectionGet.js b/back/methods/collection/collectionGet.js new file mode 100644 index 000000000..ff98c55d5 --- /dev/null +++ b/back/methods/collection/collectionGet.js @@ -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; + }; +}; diff --git a/back/methods/collection/collectionNew.js b/back/methods/collection/collectionNew.js new file mode 100644 index 000000000..59830a08b --- /dev/null +++ b/back/methods/collection/collectionNew.js @@ -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; + } +}; diff --git a/back/methods/collection/getSectors.js b/back/methods/collection/getSectors.js new file mode 100644 index 000000000..c5da7ec13 --- /dev/null +++ b/back/methods/collection/getSectors.js @@ -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; + }; +}; diff --git a/back/model-config.json b/back/model-config.json index 50603be3f..872f2239e 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -14,6 +14,9 @@ "Container": { "dataSource": "storage" }, + "Collection": { + "dataSource": "vn" + }, "Chat": { "dataSource": "vn" }, diff --git a/back/models/collection.js b/back/models/collection.js new file mode 100644 index 000000000..2802425a5 --- /dev/null +++ b/back/models/collection.js @@ -0,0 +1,5 @@ +module.exports = Self => { + require('../methods/collection/collectionGet')(Self); + require('../methods/collection/collectionNew')(Self); + require('../methods/collection/getSectors')(Self); +}; diff --git a/back/models/collection.json b/back/models/collection.json new file mode 100644 index 000000000..3e428ef60 --- /dev/null +++ b/back/models/collection.json @@ -0,0 +1,12 @@ +{ + "name": "Collection", + "base": "VnModel", + "acls": [{ + "property": "validations", + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }] +} + \ No newline at end of file diff --git a/loopback/.DS_Store b/loopback/.DS_Store new file mode 100644 index 000000000..5eff1eaf0 Binary files /dev/null and b/loopback/.DS_Store differ