first test step

This commit is contained in:
Bernat Exposito Domenech 2020-10-22 09:35:11 +02:00
parent 0f6e1eae24
commit fe2f12cd8f
15 changed files with 174 additions and 30 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn`.`supplier`
ADD COLUMN `email` VARCHAR(45) NULL AFTER `isTrucker`;

View File

@ -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`, `phone`, `payDay`)
INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `phone`, `payDay`, `email`)
VALUES
(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);
(1, 'Plants SL', 'Plants nick', 4000000001, 1, '06089160W', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 123456789, 15, 'supplier_one@gmail.es'),
(2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2, 987654321, 10, 'supplier_two@gmail.es'),
(442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 987123654, 15, 'supplier_three@gmail.es');
INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`)
VALUES

View File

@ -35,7 +35,7 @@ export default class Controller extends Section {
const $t = this.$translate.instant;
const filter = encodeURIComponent(JSON.stringify(filterObj));
const query = `Clients/findOne?filter=${filter}`;
const query = `Clients/find?filter=${filter}`;
this.$http.get(query).then(res => {
const params = {clientId: res.data.id};
const question = $t('Found a client with this phone or email', params, null, null, 'sanitizeParameters');

View File

@ -60,7 +60,12 @@ module.exports = Self => {
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'search':
return {'s.id': value};
return {or: [
{'s.id': value},
{'s.name': {like: `%${value}%`}},
{'s.nickname': {like: `%${value}%`}}
]};
// return {'s.id': value};
case 'nickname':
param = `s.${param}`;
return {[param]: {like: `%${value}%`}};

View File

@ -50,7 +50,7 @@ module.exports = Self => {
{
relation: 'country',
scope: {
fields: ['id', 'name', 'code']
fields: ['id', 'country', 'code']
}
},
{

View File

@ -0,0 +1,26 @@
module.exports = Self => {
Self.remoteMethod('isAClient', {
description: 'Returns the supplier summary',
accessType: 'READ',
accepts: {
arg: 'nif',
type: 'string',
required: true,
description: 'The supplier nif',
http: {source: 'path'}
},
returns: {
type: 'object',
root: true
},
http: {
path: `/:nif/isAClient`,
verb: 'GET'
}
});
Self.isAClient = async nif => {
const client = await Self.app.models.Client.findOne({where: {fi: nif}});
console.log('client', client);
return client;
};
};

View File

@ -0,0 +1,28 @@
const app = require('vn-loopback/server/server');
describe('Supplier getSummary()', () => {
// 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);
// });
});

View File

@ -1,4 +1,5 @@
module.exports = Self => {
require('../methods/supplier/filter')(Self);
require('../methods/supplier/getSummary')(Self);
require('../methods/supplier/isAClient')(Self);
};

View File

@ -8,7 +8,50 @@
</vn-label-value>
<vn-label-value label="Alias"
value="{{$ctrl.supplier.nickname}}">
</vn-label-value>
</vn-label-value>
<vn-label-value label="Pay method"
value="{{$ctrl.supplier.payMethod.name}}">
</vn-label-value>
<vn-label-value label="Payment deadline"
value="{{$ctrl.supplier.payDem.payDem}}">
</vn-label-value>
<vn-label-value label="Pay day"
value="{{$ctrl.supplier.payDay}}">
</vn-label-value>
<vn-label-value label="Account"
value="{{$ctrl.supplier.account}}">
</vn-label-value>
</div>
<div class="icons">
<vn-icon
vn-tooltip="Supplier inactive"
icon="icon-disabled"
ng-class="{bright: $ctrl.supplier.isActive == false}">
</vn-icon>
<vn-icon
vn-tooltip="Supplier inactive"
icon="icon-net"
ng-class="{bright: $ctrl.supplier.isOfficial == false}">
</vn-icon>
</div>
<div class="quicklinks">
<div ng-transclude="btnOne">
<vn-quick-link
tooltip="All entries with current supplier"
state="['entry.index', {q: $ctrl.entryFilter}]"
icon="icon-entry">
</vn-quick-link>
</div>
<div ng-transclude="btnTwo">
<vn-quick-link
ng-if="$ctrl.isAClient"
tooltip="Go to client"
state="['client.card.summary', {id: $ctrl.isAClient.id}]"
icon="person">
</vn-quick-link>
</div>
<div ng-transclude="btnThree">
</div>
</div>
</slot-body>
</vn-descriptor-content>

View File

@ -8,14 +8,71 @@ class Controller extends Descriptor {
set supplier(value) {
this.entity = value;
this.iSupplierAClient();
}
get entryFilter() {
if (!this.supplier) return null;
const date = new Date();
date.setHours(0, 0, 0, 0);
const from = new Date(date.getTime());
from.setDate(from.getDate() - 10);
const to = new Date(date.getTime());
to.setDate(to.getDate() + 10);
return JSON.stringify({
supplierFk: this.supplier.id,
from,
to
});
}
iSupplierAClient() {
if (!this.supplier) return;
const filter = {
where: {fi: this.supplier.nif}
};
this.$http.get('Clients/findOne', {filter}).then(res => {
if (res.data)
this.isAClient = res.data;
}).catch(error => {
return this.isAClient = false;
});
// this.$http.get(`Suppliers/${this.supplier.nif}/isAClient`).then(res => {
// this.isAClient = res.data;
// });
}
loadData() {
const filter = {
fields: [
'id',
'name',
'nickname',
'nif'
'nif',
'payMethodFk',
'payDemFk',
'payDay',
'isActive',
'isOfficial',
'account'
],
include: [
{
relation: 'payMethod',
scope: {
fields: ['id', 'name']
}
},
{
relation: 'payDem',
scope: {
fields: ['id', 'payDem']
}
}
]
};

View File

@ -8,7 +8,7 @@
<vn-searchbar
vn-focus
panel="vn-supplier-search-panel"
info="Search suppliers by id"
info="Search suppliers by id name or alias"
model="model">
</vn-searchbar>
</vn-portal>

View File

@ -5,7 +5,7 @@
vn-one
label="General search"
ng-model="filter.search"
info="Search suppliers by id"
info="Search suppliers by id name or alias"
vn-focus>
</vn-textfield>
</vn-horizontal>

View File

@ -38,7 +38,7 @@
value="{{$ctrl.summary.city}}">
</vn-label-value>
<vn-label-value label="Postcode"
value="{{$ctrl.summary.postcode}}">
value="{{$ctrl.summary.postCode}}">
</vn-label-value>
<vn-label-value label="Province"
value="{{$ctrl.summary.province.name}}">

View File

@ -15,24 +15,6 @@ class Controller extends Section {
this.summary = response.data;
});
}
// sumRisk() {
// let total = 0;
// this.summary.clientRisks.forEach(risk => {
// total += risk.amount;
// });
// return total;
// }
// claimRate(priceIncreasing) {
// if (priceIncreasing)
// return priceIncreasing * 100;
// }
// claimingRate(rate) {
// if (rate)
// return rate * 100;
// }
}
ngModule.vnComponent('vnSupplierSummary', {