From d72f2419468132cb955d8d9a3fa4fe933edac22b Mon Sep 17 00:00:00 2001 From: Ainki Date: Mon, 23 Mar 2020 08:24:57 +0100 Subject: [PATCH] first commit --- .DS_Store | Bin 0 -> 8196 bytes back/.DS_Store | Bin 0 -> 6148 bytes back/methods/.DS_Store | Bin 0 -> 6148 bytes back/methods/collection/collectionGet.js | 22 +++++ back/methods/collection/collectionNew.js | 120 +++++++++++++++++++++++ back/methods/collection/getSectors.js | 20 ++++ back/model-config.json | 3 + back/models/collection.js | 5 + back/models/collection.json | 12 +++ loopback/.DS_Store | Bin 0 -> 6148 bytes 10 files changed, 182 insertions(+) create mode 100644 .DS_Store create mode 100644 back/.DS_Store create mode 100644 back/methods/.DS_Store create mode 100644 back/methods/collection/collectionGet.js create mode 100644 back/methods/collection/collectionNew.js create mode 100644 back/methods/collection/getSectors.js create mode 100644 back/models/collection.js create mode 100644 back/models/collection.json create mode 100644 loopback/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f0821349b2196b034eb2201ebee8f9ea8fe4d886 GIT binary patch literal 8196 zcmeHM(M}UV6ukq*ZVLz)6L@o9OniU_F(Ss8)B+C}F~%BwPy=1Mmddi*bXzLcn!flC z>L2(ieu2N>yC0zE&Mb9yy9J+&kr^^`XLrw;nLTr7rgtGCQEFGO6D<&th0Jz#5=Bbl z=bVSqSajzKtN@?rfLv-)ooeI{q0J4WfKk9GU=%P47zO?X1#o6_vPPWy>ZvJ>0!D#z zsQ~W}HZt2{Wc$j>tpkM&0bnz@Efea910=_eY%#KZWhE7Ds^~#PR1t+3LecTuW;kpy zvVCP0orI#3hYG7IpJM(DCihyPV>%=+ z-lzDGU}k`;@mLeM9|>Ik1UGtAW0eFa3(gURQh{o!ZXY$>X2_umvWxdG=&IrBHHGo< z5o@QjGm?$jisPhGI&KUz<0LSwiH^z0*$Y!O(Q%hz9np5P$Y($ls<>nXglg5MMu^r#+m@DDLppn5l|_HoP^)BG1|tU zpS1SjM+w$_jL65TVjmArxbYcbm13-Ecz_FZi_o23V| zMeDRl52;L>@i9u}^qwqe5#X;e!V_7)Q}IqGY()FYSEu3C!`AZhH!(JznYfU(th|+< z&c7`02c2@O(rSmLO7l5iJ*u?!ov8jK2)seP;ykUpot@ds>w({@)P1)p$@QuW$ctxn zzZ!H(LEEo}vYoPeU|BgUw==uY?cQEnU9?wLS9^h9_x=->4w8s|fzXV)9+aO^8xrQI-1NP`uQ3rhi)|{vQetPqBqwBM2hwGmg4;0K zrJd7w(uH*1944lMC3=9e2KJJiF20s-i#Gju&%CjV@0u%3C0ZE8u9_p2rt>_j?ajyiZ3XE3reom{YnkfMC}cPeE5mWv!9NU9w*h5N dF|vJSaR=$Ie+b}T73TbppS9-vm%ezOieD3RXrcfB literal 0 HcmV?d00001 diff --git a/back/.DS_Store b/back/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a15d86adb3a8380cd195bb108ab8ed68193beb99 GIT binary patch literal 6148 zcmeHK%}(1u5S~raViT!yB@R^T!BP*sa0n_PJz9bEgw(1=pbKp%n^;oh0u4JxEPf=D$Z&3@zgTl=%M>jePO9Y(7F4ggrFgf$z7zX-)i zXQXC4ghKU@5J3@+ii0qn$!5o6WPsk?0(^rQN*KT&?@xvpxegD~q$pdhD^aUAo;+Q! z?8TLn~(>*@#Bv~X!T{+C6Lgkz0%Ki|P1MFkH^1?I4sBPJOXL&qs zciJoN+S}G-#T|D#EwtaPPbRiyy?FiZ#r>{A86pH#mh~XxyRX z(9g3}X8RbKR!y@RnE_^i8JI%`%u;4G=kVV7mYD%&;C>mP^}$6Y^bA%S)zX0j{XSB> zK}do&oh1legPy@kBSuh!E=AO(!W=P#E=Rv>@;rl;MqLg<&5V7_%)*>dgqj`wu1W{t zY2=X^UYk#_~#pYErZX-K6$X3on{wI>1 zw77l|o#lw#->~4-6Ie$Dr~nn90#tws3>C;WJ)I4cjHv(>paM|9z7Hj_Cia2;>A>P6 z0I)&Y4YAJ>z+wqtP3!}afoV{ILDd{FH0a2etgDHAV9-VVWIQKN)|^n(Pe;CZxo8dK zN(HFEqXLuI&aMBi;7{iNM-q2bfC~I81+-bNmkYd7_SVtMS+6bd4cuyOa5KbC!Q$;0 j=m!pwp3eI*>mDrVEV { + 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 0000000000000000000000000000000000000000..5eff1eaf067fb52e1e272e187642d76f154ecfcf GIT binary patch literal 6148 zcmeHK!EVz)5S>j;>I4uuAhkzdkT^tDT0|&9NNGq9Js=^B-~gz#W2-fFy;1Bmf)L~j z9|3>Br|<=Q2p<4%b{AA9z<~oo(M~k;c4udHz0cWQFA<6UB-$ow5s?dJbeb@~5N>B( zlA7^wqfmWF$_`RF3{x2{MO%kuz%uZ^F~DoLPD7G(hF^94@}_VPdh?qS_2_j<5jCU$ z7++ZH9Q$b@_6m&6Y8V~S~uUQxb0hS*rhYtUobr#%|bL*N#kE2@qp-Y;a-(Qiy+ zI%m5O`}I$;;WQta-Rg5VN|U_kbiRn%nsceX?z&C4dA0e{Kao?v2#QJG55~{A_9!S$ zLQ{SsW%{!mgin)rdf2-DKxRddWbs%fCsB-$7tfL`lGDDNWKpjA@pXgiHr&QxYjZZc zyW4GhJKgTQ?ag*~ZnwQVom=yH!`-;CegEL-?Dd=3+xfc>m=Hu@%T;pC;1BqSLWPiX zf1ITadRG>~3=87S7I{coA>lrLH>U0w3@*&K~!rV}V z8Xf(6Dx5@5qqUX+%RrTZHC=7-`M>}B`+qgb)+_^-ft6xFI0Jvs$CS+3x->aHYdz=@ ql!fC;jVcAk9LK7_NAV_93EDg^0DA^YjqpJ1hk&BN8q2^xW#Buj-=0PQ literal 0 HcmV?d00001