2022-03-02 13:59:30 +00:00
|
|
|
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) {
|
2022-03-08 12:42:44 +00:00
|
|
|
case 'agencyFk':
|
|
|
|
return {'a.agencyModeName': value};
|
|
|
|
case 'supplierFk':
|
|
|
|
return {'a.supplierName': value};
|
2022-03-02 13:59:30 +00:00
|
|
|
case 'routeFk':
|
|
|
|
return {'a.routeFk': value};
|
|
|
|
case 'created':
|
|
|
|
case 'agencyAgreement':
|
|
|
|
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
|
|
|
|
});
|