diff --git a/app/Http/Controllers/Modals/Items.php b/app/Http/Controllers/Modals/Items.php new file mode 100644 index 000000000..bafe7d259 --- /dev/null +++ b/app/Http/Controllers/Modals/Items.php @@ -0,0 +1,77 @@ +middleware('permission:create-common-items')->only(['create', 'store', 'duplicate', 'import']); + $this->middleware('permission:read-common-items')->only(['index', 'show', 'edit', 'export']); + $this->middleware('permission:update-common-items')->only(['update', 'enable', 'disable']); + $this->middleware('permission:delete-common-items')->only('destroy'); + } + + /** + * Show the form for creating a new resource. + * + * @return Response + */ + public function create(Request $request) + { + $categories = Category::type('item')->enabled()->orderBy('name')->pluck('name', 'id'); + + $taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id'); + + $currency = Currency::where('code', setting('default.currency', 'USD'))->first(); + + $html = view('modals.items.create', compact('categories', 'taxes', 'currency'))->render(); + + return response()->json([ + 'success' => true, + 'error' => false, + 'message' => 'null', + 'html' => $html, + ]); + } + + /** + * Store a newly created resource in storage. + * + * @param $request + * @return Response + */ + public function store(Request $request) + { + if ($request->get('type', false) == 'inline') { + $data = [ + 'company_id' => session('company_id'), + 'name' => '', + 'sale_price' => 0, + 'purchase_price' => 0, + 'enabled' => 1 + ]; + + $data[$request->get('field')] = $request->get('value'); + + $request = $data; + } + + $response = $this->ajaxDispatch(new CreateItem($request)); + + return response()->json($response); + } +} diff --git a/resources/assets/js/components/AkauntingSelectRemote.vue b/resources/assets/js/components/AkauntingSelectRemote.vue index a0d50d63f..c3a93d76f 100644 --- a/resources/assets/js/components/AkauntingSelectRemote.vue +++ b/resources/assets/js/components/AkauntingSelectRemote.vue @@ -487,9 +487,21 @@ export default { description: "Selectbox search option not found item message" }, - remoteAction: null, - remoteType: 'invoice', - currecnyCode: 'USD', + remoteAction: { + type: String, + default: null, + description: "Selectbox remote action path" + }, + remoteType: { + type: String, + default: 'invoice', + description: "Ger remote item type." + }, + currencyCode: { + type: String, + default: 'USD', + description: "Get remote item price currecy code" + }, }, data() { @@ -572,7 +584,11 @@ export default { onAddItem() { // Get Select Input value - var value = this.$children[0].$children[0].$children[0].$refs.input.value; + if (this.title) { + var value = this.$children[0].$children[0].$children[0].$refs.input.value; + } else { + var value = this.$children[0].$children[0].$refs.input.value; + } if (this.add_new.type == 'inline') { this.addInline(value); @@ -582,7 +598,31 @@ export default { }, addInline(value) { + axios.post(this.add_new.path, { + '_token': window.Laravel.csrfToken, + 'type': 'inline', + field: this.add_new.field, + value: value, + }) + .then(response => { + if (response.data.success) { + this.selectOptions = []; + this.selectOptions.push(response.data.data); + this.real_model = response.data.data.id; + + this.change(); + + if (this.title) { + this.$children[0].$children[0].visible = false; + } else { + this.$children[0].visible = false; + } + //this.add_new.status = false; + } + }) + .catch(error => { + }); }, onModal(value) { @@ -593,7 +633,11 @@ export default { add_new.status = true; add_new.html = response.data.html; - this.$children[0].$children[0].visible = false; + if (this.title) { + this.$children[0].$children[0].visible = false; + } else { + this.$children[0].visible = false; + } this.add_new_html = Vue.component('add-new-component', function (resolve, reject) { resolve({ @@ -644,7 +688,7 @@ export default { this.change(); - this.add_new.status = false; + //this.add_new.status = false; } }) .catch(error => { diff --git a/resources/assets/js/views/sales/invoices.js b/resources/assets/js/views/sales/invoices.js index 950b0f321..63e5ed0c2 100644 --- a/resources/assets/js/views/sales/invoices.js +++ b/resources/assets/js/views/sales/invoices.js @@ -16,8 +16,10 @@ import Form from './../../plugins/form'; import Error from './../../plugins/error'; import BulkAction from './../../plugins/bulk-action'; +import { Link } from 'element-ui'; + // plugin setup -Vue.use(DashboardPlugin); +Vue.use(DashboardPlugin, Link); const app = new Vue({ el: '#app', diff --git a/resources/views/modals/items/create.blade.php b/resources/views/modals/items/create.blade.php new file mode 100644 index 000000000..deb855afd --- /dev/null +++ b/resources/views/modals/items/create.blade.php @@ -0,0 +1,25 @@ +{!! Form::open([ + 'route' => 'items.store', + 'id' => 'item', + '@submit.prevent' => 'onSubmit', + '@keydown' => 'form.errors.clear($event.target.name)', + 'role' => 'form', + 'class' => 'form-loading-button', + 'novalidate' => true +]) !!} +