salix/modules/route/front/agency-term/index/index.js

122 lines
3.3 KiB
JavaScript
Raw Normal View History

2022-03-02 13:59:30 +00:00
import ngModule from '../../module';
import Section from 'salix/components/section';
class Controller extends Section {
constructor($element, $) {
super($element, $);
this.smartTableOptions = {
activeButtons: {
search: true
},
columns: [
{
2022-03-16 13:42:19 +00:00
field: 'agencyModeFk',
2022-03-02 13:59:30 +00:00
autocomplete: {
url: 'AgencyModes',
showField: 'name',
2022-03-16 13:42:19 +00:00
valueField: 'id'
2022-03-02 13:59:30 +00:00
}
},
{
2022-03-16 13:42:19 +00:00
field: 'agencyFk',
2022-03-02 13:59:30 +00:00
autocomplete: {
url: 'Agencies',
showField: 'name',
2022-03-16 13:42:19 +00:00
valueField: 'id'
2022-03-02 13:59:30 +00:00
}
},
{
field: 'supplierFk',
autocomplete: {
url: 'Suppliers',
showField: 'name',
valueField: 'name',
}
}
]
};
}
exprBuilder(param, value) {
switch (param) {
2022-03-16 13:42:19 +00:00
case 'agencyModeFk':
return {'a.agencyModeFk': value};
2022-03-08 12:42:44 +00:00
case 'supplierFk':
return {'a.supplierName': value};
2022-03-02 13:59:30 +00:00
case 'routeFk':
return {'a.routeFk': value};
case 'created':
2022-03-16 13:42:19 +00:00
case 'agencyFk':
2022-03-02 13:59:30 +00:00
case 'packages':
case 'm3':
case 'kmTotal':
case 'price':
case 'invoiceInFk':
2022-03-08 12:42:44 +00:00
return {[`a.${param}`]: value};
2022-03-02 13:59:30 +00:00
}
}
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 = [];
2022-03-03 13:42:12 +00:00
const supplierFk = this.checked[0].supplierFk;
2022-03-02 13:59:30 +00:00
for (let agencyTerm of this.checked) {
2022-03-03 13:42:12 +00:00
let hasSameSupplier = supplierFk == agencyTerm.supplierFk;
if (hasSameSupplier) {
2022-03-02 13:59:30 +00:00
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
});