From 977e96dbc30ffa4fa5c0667dc538f2579fd0b8f6 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 2 Jan 2017 22:23:29 +0200 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98More=20Actions=E2=80=99=20to=20p?= =?UTF-8?q?ayments=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/PaymentController.php | 16 ++++++++++++++-- resources/views/payments/edit.blade.php | 22 +++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 2b38ba25d76b..d59604040940 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -122,9 +122,16 @@ class PaymentController extends BaseController public function edit(PaymentRequest $request) { $payment = $request->entity(); - $payment->payment_date = Utils::fromSqlDate($payment->payment_date); + $actions = []; + if ( ! $payment->trashed()) { + $actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans('texts.archive_payment')]; + $actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans('texts.delete_payment')]; + } else { + $actions[] = ['url' => 'javascript:submitAction("restore")', 'label' => trans('texts.restore_expense')]; + } + $data = [ 'client' => null, 'invoice' => null, @@ -138,6 +145,7 @@ class PaymentController extends BaseController 'method' => 'PUT', 'url' => 'payments/'.$payment->public_id, 'title' => trans('texts.edit_payment'), + 'actions' => $actions, 'paymentTypes' => Cache::get('paymentTypes'), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ]; @@ -173,6 +181,10 @@ class PaymentController extends BaseController */ public function update(UpdatePaymentRequest $request) { + if (in_array($request->action, ['archive', 'delete', 'restore'])) { + return self::bulk(); + } + $payment = $this->paymentRepo->save($request->input(), $request->entity()); Session::flash('message', trans('texts.updated_payment')); @@ -191,7 +203,7 @@ class PaymentController extends BaseController $count = $this->paymentService->bulk($ids, $action, ['amount'=>$amount]); if ($count > 0) { - $message = Utils::pluralize($action=='refund'?'refunded_payment':$action.'d_payment', $count); + $message = Utils::pluralize($action=='refund' ? 'refunded_payment':$action.'d_payment', $count); Session::flash('message', $message); } diff --git a/resources/views/payments/edit.blade.php b/resources/views/payments/edit.blade.php index d476bab5279c..01e0cb924b6d 100644 --- a/resources/views/payments/edit.blade.php +++ b/resources/views/payments/edit.blade.php @@ -15,7 +15,7 @@ @section('content') {!! Former::open($url) - ->addClass('col-md-10 col-md-offset-1 warn-on-exit') + ->addClass('col-md-10 col-md-offset-1 warn-on-exit main-form') ->onsubmit('onFormSubmit(event)') ->method($method) ->rules(array( @@ -30,6 +30,7 @@ {!! Former::text('public_id') !!} + {!! Former::text('action') !!}
@@ -81,6 +82,14 @@ @if (!$payment || !$payment->is_deleted) {!! Button::success(trans('texts.save'))->withAttributes(['id' => 'saveButton'])->appendIcon(Icon::create('floppy-disk'))->submit()->large() !!} @endif + + @if ($payment) + {!! DropdownButton::normal(trans('texts.more_actions')) + ->withContents($actions) + ->large() + ->dropup() !!} + @endif + {!! Former::close() !!} @@ -121,6 +130,17 @@ $('#saveButton').attr('disabled', true); } + function submitAction(action) { + $('#action').val(action); + $('.main-form').submit(); + } + + function onDeleteClick() { + sweetConfirm(function() { + submitAction('delete'); + }); + } + @stop