2021-01-26 06:21:05 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
|
|
|
this.import = {
|
|
|
|
file: '',
|
|
|
|
invoice: null,
|
|
|
|
buys: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onFileChange($event) {
|
|
|
|
const input = $event.target;
|
|
|
|
const file = input.files[0];
|
|
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = event =>
|
|
|
|
this.fillData(event.target.result);
|
|
|
|
reader.readAsText(file, 'UTF-8');
|
|
|
|
}
|
|
|
|
|
|
|
|
fillData(raw) {
|
|
|
|
this.import.file = raw;
|
|
|
|
|
|
|
|
const data = JSON.parse(raw);
|
|
|
|
const [invoice] = data.invoices;
|
|
|
|
|
|
|
|
this.$.$applyAsync(() => {
|
|
|
|
this.import.invoice = invoice.id_invoice;
|
2021-02-09 06:59:55 +00:00
|
|
|
this.import.observation = invoice.tx_awb;
|
2021-01-26 06:21:05 +00:00
|
|
|
|
|
|
|
const boxes = invoice.boxes;
|
|
|
|
const buys = [];
|
|
|
|
for (let box of boxes) {
|
2021-02-03 08:03:03 +00:00
|
|
|
const boxVolume = box.nu_length * box.nu_width * box.nu_height;
|
2021-01-26 06:21:05 +00:00
|
|
|
for (let product of box.products) {
|
|
|
|
const packing = product.nu_stems_bunch * product.nu_bunches;
|
|
|
|
buys.push({
|
|
|
|
description: product.nm_product,
|
|
|
|
size: product.nu_length,
|
|
|
|
packing: packing,
|
|
|
|
grouping: product.nu_stems_bunch,
|
2021-02-03 08:03:03 +00:00
|
|
|
buyingValue: parseFloat(product.mny_rate_stem),
|
|
|
|
volume: boxVolume
|
2021-01-26 06:21:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 06:59:55 +00:00
|
|
|
|
|
|
|
const params = {buys};
|
|
|
|
const query = `Entries/${this.entry.id}/importPreview`;
|
|
|
|
this.$http.get(query, {params}).then(res => {
|
|
|
|
this.import.buys = res.data;
|
|
|
|
});
|
|
|
|
// this.import.buys = buys;
|
2021-01-26 06:21:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
const params = {buys: this.import.buys};
|
|
|
|
const query = `Entries/${this.entry.id}/import`;
|
|
|
|
return this.$http.post(query, params).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
itemSearchFunc($search) {
|
|
|
|
return /^\d+$/.test($search)
|
|
|
|
? {id: $search}
|
|
|
|
: {name: {like: '%' + $search + '%'}};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope'];
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnEntryBuyImport', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
worker: '<'
|
|
|
|
}
|
|
|
|
});
|