salix/modules/supplier/front/descriptor/index.js

91 lines
2.2 KiB
JavaScript

import ngModule from '../module';
import Descriptor from 'salix/components/descriptor';
class Controller extends Descriptor {
get supplier() {
return this.entity;
}
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',
'payMethodFk',
'payDemFk',
'payDay',
'isActive',
'isOfficial',
'account'
],
include: [
{
relation: 'payMethod',
scope: {
fields: ['id', 'name']
}
},
{
relation: 'payDem',
scope: {
fields: ['id', 'payDem']
}
}
]
};
return this.getData(`Suppliers/${this.id}`, {filter})
.then(res => this.entity = res.data);
}
}
ngModule.vnComponent('vnSupplierDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
supplier: '<'
}
});