From cc35998f62ec78f535124e5a4415327c25e965df Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 15 Oct 2020 08:15:04 +0200 Subject: [PATCH] new module supplier, created section index and searchpanel --- db/dump/fixtures.sql | 8 +- front/core/styles/icons/salixfont.css | 3 + front/core/styles/icons/salixfont.svg | 4 +- front/core/styles/icons/salixfont.ttf | Bin 33496 -> 32980 bytes front/core/styles/icons/salixfont.woff | Bin 33572 -> 33056 bytes front/module-import.js | 1 + front/salix/locale/es.yml | 1 + modules/item/back/model-config.json | 3 - .../supplier/back/methods/supplier/filter.js | 106 ++++++++++++++++++ .../methods/supplier/specs/filter.spec.js | 28 +++++ modules/supplier/back/model-config.json | 5 + modules/supplier/back/models/supplier.js | 3 + .../back/models/supplier.json | 0 modules/supplier/front/index.js | 5 + modules/supplier/front/index/index.html | 61 ++++++++++ modules/supplier/front/index/index.js | 9 ++ modules/supplier/front/index/locale/es.yml | 5 + modules/supplier/front/main/index.html | 18 +++ modules/supplier/front/main/index.js | 9 ++ modules/supplier/front/module.js | 3 + modules/supplier/front/routes.json | 27 +++++ .../supplier/front/search-panel/index.html | 46 ++++++++ modules/supplier/front/search-panel/index.js | 7 ++ .../supplier/front/search-panel/locale/es.yml | 3 + 24 files changed, 346 insertions(+), 9 deletions(-) create mode 100644 modules/supplier/back/methods/supplier/filter.js create mode 100644 modules/supplier/back/methods/supplier/specs/filter.spec.js create mode 100644 modules/supplier/back/model-config.json create mode 100644 modules/supplier/back/models/supplier.js rename modules/{item => supplier}/back/models/supplier.json (100%) create mode 100644 modules/supplier/front/index.js create mode 100644 modules/supplier/front/index/index.html create mode 100644 modules/supplier/front/index/index.js create mode 100644 modules/supplier/front/index/locale/es.yml create mode 100644 modules/supplier/front/main/index.html create mode 100644 modules/supplier/front/main/index.js create mode 100644 modules/supplier/front/module.js create mode 100644 modules/supplier/front/routes.json create mode 100644 modules/supplier/front/search-panel/index.html create mode 100644 modules/supplier/front/search-panel/index.js create mode 100644 modules/supplier/front/search-panel/locale/es.yml diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 62a5b7ca2..ae7fbe67e 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1208,11 +1208,11 @@ INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`) (104, 500), (105, 5000); -INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`) +INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `phone`, `payDay`) VALUES - (1, 'Plants SL', 'Plants nick', 4000000001, 1, 'A11111111', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1), - (2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2), - (442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2); + (1, 'Plants SL', 'Plants nick', 4000000001, 1, 'A11111111', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 123456789, 15), + (2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2, 987654321, 10), + (442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 987123654, 15); INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`) VALUES diff --git a/front/core/styles/icons/salixfont.css b/front/core/styles/icons/salixfont.css index 52a2308b4..aafc549a1 100644 --- a/front/core/styles/icons/salixfont.css +++ b/front/core/styles/icons/salixfont.css @@ -22,6 +22,9 @@ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } +.icon-supplier:before { + content: "\e936"; +} .icon-latestBuys:before { content: "\e95f"; } diff --git a/front/core/styles/icons/salixfont.svg b/front/core/styles/icons/salixfont.svg index 7e8695d63..ee14609a4 100644 --- a/front/core/styles/icons/salixfont.svg +++ b/front/core/styles/icons/salixfont.svg @@ -61,7 +61,7 @@ - + @@ -102,7 +102,7 @@ - + diff --git a/front/core/styles/icons/salixfont.ttf b/front/core/styles/icons/salixfont.ttf index 608dd7c80c653928df2a89af6a5851ad8237c19d..6958c0e3dd4cfaa662de976ebb1ce9e38a78daec 100644 GIT binary patch delta 611 zcmXw#O=uHA7>2*u-DEXQb|*GJ^e1VW?aVgYX459=Zn~yT5UrS_lqyoxV5^}tZNVTx zBx#GSJ$R_-MbLuiNjxa=Ce~^}JV^u(isC^%dJwD!16C)3a~YoZeVFfK-mP$Nm$>z8 zb?5jK8vt4ZxOlHHou6tihu#2O>IVR$zyfhw=wUp?xTjDom9JfCxyqRN=+^A~nY{69 zLI$KV3ygOdhvxFd>66Fa9|ov;n7^?wf4&4fYhdwlvj?7k^la0rvIYKZ z^9_CrIv@@iI0AX5dqfF|b|tLpNTowba}=3IBJK|&zmE@7mc|e@OdToqe_{Z2o1!W< zdsCH>U(Fy!&BP|M7kC}9&}@~E*W*jX4c2m}F*XR%su4m=8DrTbB%%>wV4M>r(J6B- zPT1oi?tz1cD*aJztdYQ$;_h_ZjnWaEOQtEs8a|<-;V*kbo=M*89CJm+BiV?5~}qPlEUny2-!{9Y@*+3NNrAD;3X-Uq-t_qb7k==zfX!hblJ067rtpX z9ER`qswI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KBN++YM^>S^_QBQnwMIO+68qk z^?Mp>8YeXCv_5DnXlLjg&~?&1rYEO&NB^9mnqiD#g^_@1mRXp2odt^}i`6`93)>)Y Qx=Lp%VUXPH*LaN)06sa4djJ3c delta 1155 zcmah}T}TvB6uxKgxKpknmZKIVaEird!h(W|Eh^|iY9Azs!iOk==;tvgNTP?ft#fxPA_`~j`OdlLeCNC8KFo|C zbzC~`s64QG*)jqIpJ6v~aewrAsxp>{Um+xZ~6CVoh-oAlB%snRrE^teYxGwJM--5iM0pvX8W_bEG_4N$yA>>FD_YDO*=Gecx zr*9kP@Ek~Ui@7$uSiYx!FE$PfH*=3W6Lm!TK1p-*DiA1vQkV}*pbf&HLj&3j%Ww^Dz-_n>lPDa9He7lEi}9=&kQL-4imu33ST}?!X6^hZ z;ZL0+p;300{~Rpf6fqa5l>S0VPRz=wsI1Z&B@Tfgzhoe&74?hAN2VB-Lx@QpO;SQ2 z24oeOwm?+=?D*ZsG?DW>$PYuJ&4*r8LRuXtp%RRJVu+PH6sF-`lf+Eqy*}U43DKVK!K(NS^_jbC^+dW zpom!z%1R;TDuq!jWT|tm-!O8!ZQC)e0yVvMO+`uo0cd1Y`}WbY-~?k@%)+3?5DcSV ztw}}B=4UJ`OGQ+7(6jd~>kif}ORcSA{Rwr{pT8dW4*8?W$Y|7*>my0kw(p*9MTsP1 zh5=ttpU!cD2||+3$WJqYj&aZ5{DD%}`nhE$6-78TrJK5$#NM~E{O$cb&6~9(Q#DVd z{pl|2u4S#kaz;<OFQ2&(R{*5U { + Self.remoteMethodCtx('filter', { + description: 'Find all instances of the model matched by filter from the data source.', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'Object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, { + arg: 'search', + type: 'String', + description: 'Searchs the supplier by id', + http: {source: 'query'} + }, { + arg: 'id', + type: 'Integer', + description: 'The supplier id', + http: {source: 'query'} + }, { + arg: 'nickname', + type: 'String', + description: 'The supplier name to filter', + http: {source: 'query'} + }, { + arg: 'provinceFk', + type: 'Number', + description: 'The province id to filter', + http: {source: 'query'} + }, { + arg: 'countryFk', + type: 'Number', + description: 'The country id to filter', + http: {source: 'query'} + }, { + arg: 'nif', + type: 'String', + description: 'The supplier nif to filter', + http: {source: 'query'} + } + ], + returns: { + type: ['Object'], + root: true + }, + http: { + path: `/filter`, + verb: 'GET' + } + }); + + Self.filter = async(ctx, filter) => { + let conn = Self.dataSource.connector; + let where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'search': + return {'s.id': value}; + case 'nickname': + param = `s.${param}`; + return {[param]: {like: `%${value}%`}}; + case 'id': + case 'provinceFk': + case 'countryFk': + case 'nif': + param = `s.${param}`; + return {[param]: value}; + } + }); + filter = mergeFilters(ctx.args.filter, {where}); + + let stmts = []; + let stmt; + stmt = new ParameterizedSQL( + `SELECT + s.id, + s.name AS socialName, + s.nickname AS alias, + s.account, + s.provinceFk, + s.nif, + s.payDemFk, + s.payDay, + s.phone, + s.city, + pm.name AS payMethod, + pd.payDem AS payDem + FROM vn.supplier s + JOIN vn.payMethod pm ON pm.id = s.payMethodFk + JOIN vn.payDem pd ON pd.id = s.payDemFk` + ); + + stmt.merge(conn.makeSuffix(filter)); + let itemsIndex = stmts.push(stmt) - 1; + + let sql = ParameterizedSQL.join(stmts, ';'); + let result = await conn.executeStmt(sql); + return itemsIndex === 0 ? result : result[itemsIndex]; + }; +}; + diff --git a/modules/supplier/back/methods/supplier/specs/filter.spec.js b/modules/supplier/back/methods/supplier/specs/filter.spec.js new file mode 100644 index 000000000..1f74b10ff --- /dev/null +++ b/modules/supplier/back/methods/supplier/specs/filter.spec.js @@ -0,0 +1,28 @@ +const app = require('vn-loopback/server/server'); + +describe('Supplier filter()', () => { + it('should return the supplier matching "search"', async() => { + let ctx = { + args: { + search: 1 + } + }; + + let result = await app.models.Supplier.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].id).toEqual(1); + }); + + it('should return the supplier matching the province', async() => { + let ctx = { + args: { + provinceFk: 1 + } + }; + + let result = await app.models.Supplier.filter(ctx); + + expect(result.length).toEqual(2); + }); +}); diff --git a/modules/supplier/back/model-config.json b/modules/supplier/back/model-config.json new file mode 100644 index 000000000..899e3c38a --- /dev/null +++ b/modules/supplier/back/model-config.json @@ -0,0 +1,5 @@ +{ + "Supplier": { + "dataSource": "vn" + } +} diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js new file mode 100644 index 000000000..953df5106 --- /dev/null +++ b/modules/supplier/back/models/supplier.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/supplier/filter')(Self); +}; diff --git a/modules/item/back/models/supplier.json b/modules/supplier/back/models/supplier.json similarity index 100% rename from modules/item/back/models/supplier.json rename to modules/supplier/back/models/supplier.json diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js new file mode 100644 index 000000000..cb25b3b8c --- /dev/null +++ b/modules/supplier/front/index.js @@ -0,0 +1,5 @@ +export * from './module'; + +import './main'; +import './index/'; +import './search-panel'; diff --git a/modules/supplier/front/index/index.html b/modules/supplier/front/index/index.html new file mode 100644 index 000000000..9c4dd21d2 --- /dev/null +++ b/modules/supplier/front/index/index.html @@ -0,0 +1,61 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/supplier/front/index/index.js b/modules/supplier/front/index/index.js new file mode 100644 index 000000000..f4a3d7c6d --- /dev/null +++ b/modules/supplier/front/index/index.js @@ -0,0 +1,9 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section {} + +ngModule.vnComponent('vnSupplierIndex', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/supplier/front/index/locale/es.yml b/modules/supplier/front/index/locale/es.yml new file mode 100644 index 000000000..ad8a4f0bb --- /dev/null +++ b/modules/supplier/front/index/locale/es.yml @@ -0,0 +1,5 @@ +Payment deadline: Plazo de pago +Pay day: Dia de pago +Account: Cuenta +Pay method: Metodo de pago +Tax number: Nif \ No newline at end of file diff --git a/modules/supplier/front/main/index.html b/modules/supplier/front/main/index.html new file mode 100644 index 000000000..2278087c2 --- /dev/null +++ b/modules/supplier/front/main/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/modules/supplier/front/main/index.js b/modules/supplier/front/main/index.js new file mode 100644 index 000000000..2fd870573 --- /dev/null +++ b/modules/supplier/front/main/index.js @@ -0,0 +1,9 @@ +import ngModule from '../module'; +import ModuleMain from 'salix/components/module-main'; + +export default class Supplier extends ModuleMain {} + +ngModule.vnComponent('vnSupplier', { + controller: Supplier, + template: require('./index.html') +}); diff --git a/modules/supplier/front/module.js b/modules/supplier/front/module.js new file mode 100644 index 000000000..d7f78389a --- /dev/null +++ b/modules/supplier/front/module.js @@ -0,0 +1,3 @@ +import {ng} from 'core/vendor'; + +export default ng.module('supplier', ['salix']); diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json new file mode 100644 index 000000000..21f1ceb26 --- /dev/null +++ b/modules/supplier/front/routes.json @@ -0,0 +1,27 @@ +{ + "module": "supplier", + "name": "Suppliers", + "icon" : "icon-supplier", + "validations" : true, + "menus": { + "main": [ + {"state": "supplier.index", "icon": "icon-supplier"} + ], + "card": [ + ] + }, + "routes": [ + { + "url": "/supplier", + "state": "supplier", + "abstract": true, + "component": "vn-supplier", + "description": "Suppliers" + }, { + "url": "/index?q", + "state": "supplier.index", + "component": "vn-supplier-index", + "description": "Suppliers" + } + ] +} \ No newline at end of file diff --git a/modules/supplier/front/search-panel/index.html b/modules/supplier/front/search-panel/index.html new file mode 100644 index 000000000..5ad5e6e3a --- /dev/null +++ b/modules/supplier/front/search-panel/index.html @@ -0,0 +1,46 @@ +
+
+ + + + + + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/modules/supplier/front/search-panel/index.js b/modules/supplier/front/search-panel/index.js new file mode 100644 index 000000000..6223b5670 --- /dev/null +++ b/modules/supplier/front/search-panel/index.js @@ -0,0 +1,7 @@ +import ngModule from '../module'; +import SearchPanel from 'core/components/searchbar/search-panel'; + +ngModule.vnComponent('vnSupplierSearchPanel', { + template: require('./index.html'), + controller: SearchPanel +}); diff --git a/modules/supplier/front/search-panel/locale/es.yml b/modules/supplier/front/search-panel/locale/es.yml new file mode 100644 index 000000000..6df042998 --- /dev/null +++ b/modules/supplier/front/search-panel/locale/es.yml @@ -0,0 +1,3 @@ +Province: Provincia +Country: Pais +Tax number: Nif \ No newline at end of file