Vue.component('v_create_expense', {
template: `
<div :data-component="$options.name" class="xd-content-t xd-section">
<div v-if="system.loading" class="xd-loading"></div>
<div v-else-if="system.finished" class="xd-center xd-padding">
<h5 class="xd-xlarge">Operacja wykonana</h5>
</div>
<template v-else>
<form @submit.prevent="submitData()" class="xd-form xd-section">
<label></label>
<h3>Przygotowanie umów</h3>
<label style="white-space:normal">
Typ umowy
</label>
<div>
AUTO
</div>
<label style="white-space:normal">
Ilość umów
</label>
<div>
{{clipboard_items.length}}
</div>
<label></label>
<div class="xd-container">
<button type="submit" :disabled="system.loadingLastMailParts" tabindex="-1" class="xd-button xd-success">
<span v-if="!system.loadingLastMailParts"><i class="fa fa-fw fa-paper-plane-o" aria-hidden="true"></i> Przygotuj umowy<span> - {{clipboard_items.length}} </span></span>
<span v-else class="xd-center xd-loading">
</span>
</button>
</div>
</form>
</template>
</div>`,
props: {
clipboard_items: { type: Array }, //object
api: { type: Object },
table: { type: Object },
},
data: function () {
return {
system: {
remoteID: '',
remoteSource: '',
loading: false,
finished: false
},
model: {},
datasets: {
},
}
},
methods: {
async submitData() {
for (let i = 0; i < this.clipboard_items.length; i++) {
//1.wygenerowanie i upload umowy
//1.1. prepare printout url
let item = this.clipboard_items[i];
if (item.expense_code) {
app.$root.notifications.push({ color: 'xd-warning', text: `Umowa ${item.expense_code} była już wygenerowana`, visible: true });
continue;
}
let dataToSend = {
file_url: `/api/srs/111/zlecenie.hbs.pdf?uuid=${item.uuid}&uuid2=${item.uuid2}`,
expense_file_name: '',
documentType: 'zlecenie',
expense_status: 10 //wprowadzony
};
item = Object.assign({}, item, dataToSend); //merge objects
debugger;
//2.2 wygenerowanie i upload
await this.axpost(`/api/core/files/uploadv2?file_url={file_url}`, item).then((response) => {
if (response.data.data && response.data.data.files && response.data.data.files.length) {
item.expense_file_name = "".concat(response.data.data.files[0].file_hash, response.data.data.files[0].file_extension);
}
else {
app.$root.notifications.push({ color: 'xd-warning', text: "Bład podczas generowania dokumentu", visible: true });
}
}).catch(() => {
app.$root.notifications.push({ color: 'xd-warning', text: "Bład podczas generowania dokumentu", visible: true });
})
//3.zapis umowy do rozliczenia
await this.axpost('/api/srs/426/api', item);
//4.wysłanie umowy autenti
}
this.$parent.clipboard_items_clear(); //clipboard clear
this.system.finished = true; //will lock form optionaly reload this.$parent.$emit('reload-event');
},
async fetchData() {
this.system.loading = false;
},
mounted() {
this.fetchData();
//sometimes table.type can contain mssql, oracle or other database name
if (this.table.type.startsWith('v_') && this.table.type != 'v_srs_table') {
//switch to srs table view
this.table.type = 'v_srs_table';
}
},
}
});