Add invoice product to datatable

This commit is contained in:
Hillel Coren 2017-11-03 11:25:14 +02:00
parent c6dd901203
commit c39f57fcb5
5 changed files with 68 additions and 9 deletions

View File

@ -149,6 +149,10 @@ class ProductController extends BaseController
$message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product');
Session::flash('message', $message);
if (in_array(request('action'), ['archive', 'delete', 'restore', 'invoice'])) {
return self::bulk();
}
return Redirect::to("products/{$product->public_id}/edit");
}
@ -162,6 +166,7 @@ class ProductController extends BaseController
if ($action == 'invoice') {
$products = Product::scope($ids)->get();
$data = [];
foreach ($products as $product) {
$data[] = $product->product_key;
}

View File

@ -52,6 +52,15 @@ class ProductDatatable extends EntityDatatable
return URL::to("products/{$model->public_id}/edit");
},
],
[
trans('texts.invoice_product'),
function ($model) {
return "javascript:submitForm_product('invoice', {$model->public_id})";
},
function ($model) {
return (! $model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('create', ENTITY_INVOICE);
},
],
];
}
}

View File

@ -2,6 +2,7 @@
namespace App\Ninja\Presenters;
use DropdownButton;
use App\Libraries\Skype\HeroCard;
class ProductPresenter extends EntityPresenter
@ -22,4 +23,25 @@ class ProductPresenter extends EntityPresenter
return $card;
}
public function moreActions()
{
$product = $this->entity;
if (! $product->trashed()) {
if (auth()->user()->can('create', ENTITY_INVOICE)) {
$actions[] = ['url' => 'javascript:submitAction("invoice")', 'label' => trans('texts.invoice_product')];
$actions[] = DropdownButton::DIVIDER;
}
$actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans("texts.archive_product")];
} else {
$actions[] = ['url' => 'javascript:submitAction("restore")', 'label' => trans("texts.restore_product")];
}
if (! $product->is_deleted) {
$actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans("texts.delete_product")];
}
return $actions;
}
}

View File

@ -2518,6 +2518,7 @@ $LANG = array(
'enabled_two_factor' => 'Successfully enabled Two-Factor Authentication',
'add_product' => 'Add Product',
'email_will_be_sent_on' => 'Note: the email will be sent on :date.',
'invoice_product' => 'Invoice Product',
);

View File

@ -6,7 +6,17 @@
{!! Former::open($url)
->method($method)
->rules(['product_key' => 'required|max:255'])
->addClass('col-md-10 col-md-offset-1 warn-on-exit') !!}
->addClass('col-md-10 col-md-offset-1 main-form warn-on-exit') !!}
@if ($product)
{{ Former::populate($product) }}
{{ Former::populateField('cost', Utils::roundSignificant($product->cost)) }}
@endif
<span style="display:none">
{!! Former::text('public_id') !!}
{!! Former::text('action') !!}
</span>
<div class="panel panel-default">
<div class="panel-heading">
@ -14,11 +24,6 @@
</div>
<div class="panel-body form-padding-right">
@if ($product)
{{ Former::populate($product) }}
{{ Former::populateField('cost', Utils::roundSignificant($product->cost)) }}
@endif
{!! Former::text('product_key')->label('texts.product') !!}
{!! Former::textarea('notes')->rows(6) !!}
@ -43,6 +48,12 @@
<center class="buttons">
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(HTMLUtils::previousUrl('/products'))->appendIcon(Icon::create('remove-circle')) !!}
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
@if ($product)
{!! DropdownButton::normal(trans('texts.more_actions'))
->withContents($product->present()->moreActions())
->large()
->dropup() !!}
@endif
</center>
{!! Former::close() !!}
@ -53,6 +64,17 @@
$('#product_key').focus();
});
function submitAction(action) {
$('#action').val(action);
$('.main-form').submit();
}
function onDeleteClick() {
sweetConfirm(function() {
submitAction('delete');
});
}
</script>
@stop