128 lines
3.5 KiB
JavaScript
128 lines
3.5 KiB
JavaScript
import ngModule from '../../module';
|
|
import Section from 'salix/components/section';
|
|
import './style.scss';
|
|
|
|
class Controller extends Section {
|
|
constructor($element, $) {
|
|
super($element, $);
|
|
|
|
this.smartTableOptions = {
|
|
activeButtons: {
|
|
search: true
|
|
},
|
|
columns: [
|
|
{
|
|
field: 'agencyFk',
|
|
autocomplete: {
|
|
url: 'AgencyModes',
|
|
showField: 'name',
|
|
valueField: 'name'
|
|
}
|
|
},
|
|
{
|
|
field: 'agencyAgreement',
|
|
autocomplete: {
|
|
url: 'Agencies',
|
|
showField: 'name',
|
|
valueField: 'name'
|
|
}
|
|
},
|
|
{
|
|
field: 'supplierFk',
|
|
autocomplete: {
|
|
url: 'Suppliers',
|
|
showField: 'name',
|
|
valueField: 'name',
|
|
}
|
|
}
|
|
]
|
|
};
|
|
}
|
|
|
|
exprBuilder(param, value) {
|
|
switch (param) {
|
|
case 'routeFk':
|
|
return {'a.routeFk': value};
|
|
case 'created':
|
|
return {'a.created': value};
|
|
case 'agencyFk':
|
|
return {'a.agencyModeName': value};
|
|
case 'agencyAgreement':
|
|
return {'a.agencyAgreement': value};
|
|
case 'packages':
|
|
return {'a.packages': value};
|
|
case 'm3':
|
|
return {'a.m3': value};
|
|
case 'kmTotal':
|
|
return {'a.kmTotal': value};
|
|
case 'price':
|
|
return {'a.price': value};
|
|
case 'invoiceInFk':
|
|
return {'a.invoiceInFk': value};
|
|
case 'supplierFk':
|
|
return {'a.supplierName': value};
|
|
}
|
|
}
|
|
|
|
get checked() {
|
|
const agencyTerms = this.$.model.data || [];
|
|
const checkedAgencyTerms = [];
|
|
for (let agencyTerm of agencyTerms) {
|
|
if (agencyTerm.checked)
|
|
checkedAgencyTerms.push(agencyTerm);
|
|
}
|
|
|
|
return checkedAgencyTerms;
|
|
}
|
|
|
|
get totalChecked() {
|
|
return this.checked.length;
|
|
}
|
|
|
|
get totalPrice() {
|
|
let totalPrice = 0;
|
|
|
|
if (this.checked.length > 0) {
|
|
for (let agencyTerm of this.checked)
|
|
totalPrice += agencyTerm.price;
|
|
|
|
return totalPrice;
|
|
}
|
|
|
|
return totalPrice;
|
|
}
|
|
|
|
preview(route) {
|
|
this.routeSelected = route;
|
|
this.$.summary.show();
|
|
}
|
|
|
|
createInvoiceIn() {
|
|
const rowsToCreateInvoiceIn = [];
|
|
const supplier = this.checked[0].supplierFk;
|
|
|
|
for (let agencyTerm of this.checked) {
|
|
if (supplier == agencyTerm.supplierFk) {
|
|
rowsToCreateInvoiceIn.push({
|
|
routeFk: agencyTerm.routeFk,
|
|
supplierFk: agencyTerm.supplierFk,
|
|
created: agencyTerm.created,
|
|
totalPrice: this.totalPrice});
|
|
} else {
|
|
this.vnApp.showError(this.$t('Two autonomous cannot be counted at the same time'));
|
|
return false;
|
|
}
|
|
}
|
|
const params = JSON.stringify({
|
|
supplierName: this.checked[0].supplierName,
|
|
rows: rowsToCreateInvoiceIn
|
|
});
|
|
this.$state.go('route.agencyTerm.createInvoiceIn', {q: params});
|
|
}
|
|
}
|
|
|
|
ngModule.vnComponent('vnAgencyTermIndex', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|