fixed item button create new item feature fixed..

This commit is contained in:
Cüneyt Şentürk 2020-12-26 12:48:55 +03:00
parent 2ba5e53b3e
commit 8dbe178a70
3 changed files with 88 additions and 39 deletions

View File

@ -3,9 +3,10 @@
namespace App\Jobs\Document; namespace App\Jobs\Document;
use App\Abstracts\Job; use App\Abstracts\Job;
use App\Models\Document\DocumentTotal;
use App\Traits\Currencies;
use App\Traits\DateTime; use App\Traits\DateTime;
use App\Traits\Currencies;
use App\Jobs\Common\CreateItem;
use App\Models\Document\DocumentTotal;
class CreateDocumentItemsAndTotals extends Job class CreateDocumentItemsAndTotals extends Job
{ {
@ -166,6 +167,20 @@ class CreateDocumentItemsAndTotals extends Job
$item['global_discount'] = $this->request['discount']; $item['global_discount'] = $this->request['discount'];
} }
if (empty($item['item_id'])) {
$new_item = $this->dispatch(new CreateItem([
'company_id' => $this->request['company_id'],
'name' => $item['name'],
'description' => $item['description'],
'sale_price' => $item['price'],
'purchase_price' => $item['price'],
'tax_ids' => $item['tax_ids'],
'enabled' => '1'
]));
$item['item_id'] = $new_item->id;
}
$document_item = $this->dispatch(new CreateDocumentItem($this->document, $item)); $document_item = $this->dispatch(new CreateDocumentItem($this->document, $item));
$item_amount = (double) $item['price'] * (double) $item['quantity']; $item_amount = (double) $item['price'] * (double) $item['quantity'];

View File

@ -178,11 +178,52 @@ export default {
}, },
methods: { methods: {
setItemList(items) {
// Option set sort_option data
if (!Array.isArray(items)) {
let index = 0;
for (const [key, value] of Object.entries(items)) {
this.item_list.push({
index: index,
key: key,
value: value,
type: 'item',
id: key,
name: value,
description: '',
price: 0,
tax_ids: [],
});
index++;
}
} else {
items.forEach(function (item, index) {
this.item_list.push({
index: index,
key: item.id,
value: (item.title) ? item.title : (item.display_name) ? item.display_name : item.name,
type: this.type,
id: item.id,
name: (item.title) ? item.title : (item.display_name) ? item.display_name : item.name,
description: (item.description) ? item.description : '',
price: (item.price) ? item.price : (this.type == 'sale') ? item.sale_price : item.purchase_price,
tax_ids: (item.tax_ids) ? item.tax_ids : [],
});
}, this);
}
},
onItemList() { onItemList() {
this.show.item_list = true; this.show.item_list = true;
}, },
onInput() { onInput() {
if (!this.search) {
return;
}
window.axios.get(url + '/common/items?search="' + this.search + '" limit:10') window.axios.get(url + '/common/items?search="' + this.search + '" limit:10')
.then(response => { .then(response => {
this.item_list = []; this.item_list = [];
@ -224,9 +265,33 @@ export default {
}, },
onItemCreate() { onItemCreate() {
let index = Object.keys(this.item_list).length;
index++;
let item = {
index: index,
key: 0,
value: this.search,
type: this.type,
id: 0,
name: this.search,
description: '',
price: 0,
tax_ids: [],
};
this.selected_items.push(item);
this.$emit('item', item);
this.$emit('items', this.selected_items);
this.setItemList(this.items);
this.show.item_selected = false; this.show.item_selected = false;
this.show.item_list = false; this.show.item_list = false;
this.search = '';
/*
let add_new = this.add_new; let add_new = this.add_new;
window.axios.get(this.createRoute) window.axios.get(this.createRoute)
@ -275,6 +340,7 @@ export default {
.finally(function () { .finally(function () {
// always executed // always executed
}); });
*/
}, },
onSubmit(event) { onSubmit(event) {
@ -338,7 +404,7 @@ export default {
this.add_new.html = ''; this.add_new.html = '';
this.add_new_html = null; this.add_new_html = null;
this.$emit('new', contact); this.$emit('new', item);
let documentClasses = document.body.classList; let documentClasses = document.body.classList;
@ -376,40 +442,7 @@ export default {
}, },
created() { created() {
// Option set sort_option data this.setItemList(this.items);
if (!Array.isArray(this.items)) {
let index = 0;
for (const [key, value] of Object.entries(this.items)) {
this.item_list.push({
index: index,
key: key,
value: value,
type: 'item',
id: key,
name: value,
description: '',
price: 0,
tax_ids: [],
});
index++;
}
} else {
this.items.forEach(function (item, index) {
this.item_list.push({
index: index,
key: item.id,
value: (item.title) ? item.title : (item.display_name) ? item.display_name : item.name,
type: this.type,
id: item.id,
name: (item.title) ? item.title : (item.display_name) ? item.display_name : item.name,
description: (item.description) ? item.description : '',
price: (item.price) ? item.price : (this.type == 'sale') ? item.sale_price : item.purchase_price,
tax_ids: (item.tax_ids) ? item.tax_ids : [],
});
}, this);
}
}, },
computed: { computed: {

View File

@ -718,6 +718,7 @@ const app = new Vue({
if (typeof document_items !== 'undefined' && document_items) { if (typeof document_items !== 'undefined' && document_items) {
this.edit.status = true; this.edit.status = true;
document_items.forEach(function(item) { document_items.forEach(function(item) {
// form set item // form set item
this.form.items.push({ this.form.items.push({
@ -761,7 +762,7 @@ const app = new Vue({
description: item.description, description: item.description,
quantity: item.quantity, quantity: item.quantity,
price: (item.price).toFixed(2), price: (item.price).toFixed(2),
add_tax: (item_taxes.length) ? true : false, add_tax: true,
tax_ids: item_taxes, tax_ids: item_taxes,
add_discount: (item_taxes.length) ? true : false, add_discount: (item_taxes.length) ? true : false,
discount: item.discount_rate, discount: item.discount_rate,