refs #1147 invoice item create inline..

This commit is contained in:
Cüneyt Şentürk 2020-01-21 17:05:37 +03:00
parent 0876197e35
commit a8522812b2
7 changed files with 164 additions and 23 deletions

View File

@ -0,0 +1,77 @@
<?php
namespace App\Http\Controllers\Modals;
use App\Abstracts\Http\Controller;
use Illuminate\Http\Request as Request;
use App\Jobs\Common\CreateItem;
use App\Models\Setting\Category;
use App\Models\Setting\Currency;
use App\Models\Setting\Tax;
class Items extends Controller
{
/**
* Instantiate a new controller instance.
*/
public function __construct()
{
// Add CRUD permission check
$this->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);
}
}

View File

@ -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 => {

View File

@ -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',

View File

@ -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
]) !!}
<div class="row">
{{ Form::textGroup('name', trans('general.name'), 'tag') }}
{{ Form::selectAddNewGroup('tax_id', trans_choice('general.taxes', 1), 'percentage', $taxes, setting('default.tax'), ['path' => route('modals.taxes.create')]) }}
{{ Form::textareaGroup('description', trans('general.description')) }}
{{ Form::textGroup('sale_price', trans('items.sales_price'), 'money-bill-wave') }}
{{ Form::textGroup('purchase_price', trans('items.purchase_price'), 'money-bill-wave-alt') }}
{{ Form::selectAddNewGroup('category_id', trans_choice('general.categories', 1), 'folder', $categories, null, ['required' => 'required', 'path' => route('modals.categories.create') . '?type=item']) }}
{!! Form::hidden('enabled', '1', []) !!}
</div>
{!! Form::close() !!}

View File

@ -38,6 +38,10 @@
:form-error="form.errors.get('{{ $name }}')"
@endif
:remote-action="'{{ $attributes['remote_action'] }}'"
:remote-type="'{{ $attributes['remote_type'] }}'"
:currency-code="{{ $attributes['currecny_code'] }}"
:loading-text="'{{ trans('general.loading') }}'"
:no-data-text="'{{ trans('general.no_data') }}'"
:no-matching-data-text="'{{ trans('general.no_matching_data') }}'"

View File

@ -24,22 +24,10 @@
:value="'{{ old('item_id', '') }}'"
:add-new="{{ json_encode([
'status' => true,
'text' => trans('general.form.add_new', ['field' => trans_choice('general.items', 1)]),
'path' => isset($attributes['path']) ? $attributes['path']: false,
'type' => isset($attributes['type']) ? $attributes['type'] : 'modal',
'field' => isset($attributes['field']) ? $attributes['field'] : 'name',
'buttons' => [
'cancel' => [
'text' => trans('general.cancel'),
'icon' => 'fas fa-times',
'class' => 'btn-outline-secondary'
],
'confirm' => [
'text' => trans('general.save'),
'icon' => 'fas fa-save',
'class' => 'btn-success'
]
]
'text' => trans('general.form.add_new', ['field' => '']),
'path' => route('modals.items.store'),
'type' => 'inline',
'field' => 'name',
])}}"
@interface="row.item_id = $event"
@label="row.name = $event"

View File

@ -207,6 +207,7 @@ Route::group(['as' => 'modals.', 'prefix' => 'modals'], function () {
Route::resource('categories', 'Modals\Categories');
Route::resource('customers', 'Modals\Customers');
Route::resource('vendors', 'Modals\Vendors');
Route::resource('items', 'Modals\Items');
Route::patch('invoice-templates', 'Modals\InvoiceTemplates@update')->name('invoice-templates.update');
Route::resource('invoices/{invoice}/transactions', 'Modals\InvoiceTransactions', ['middleware' => ['date.format', 'money']]);
Route::resource('bills/{bill}/transactions', 'Modals\BillTransactions', ['middleware' => ['date.format', 'money']]);