diff --git a/app/Http/Controllers/Modals/BillTransactions.php b/app/Http/Controllers/Modals/BillTransactions.php
deleted file mode 100644
index 86b586208..000000000
--- a/app/Http/Controllers/Modals/BillTransactions.php
+++ /dev/null
@@ -1,110 +0,0 @@
-middleware('permission:create-purchases-bills')->only('create', 'store', 'duplicate', 'import');
- $this->middleware('permission:read-purchases-bills')->only('index', 'show', 'edit', 'export');
- $this->middleware('permission:update-purchases-bills')->only('update', 'enable', 'disable');
- $this->middleware('permission:delete-purchases-bills')->only('destroy');
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @param Document $bill
- *
- * @return Response
- */
- public function create(Document $bill)
- {
- $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
-
- $currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray();
-
- $currency = Currency::where('code', $bill->currency_code)->first();
-
- $payment_methods = Modules::getPaymentMethods();
-
- $paid = $bill->paid;
-
- // Get Bill Totals
- foreach ($bill->totals as $bill_total) {
- $bill->{$bill_total->code} = $bill_total->amount;
- }
-
- $total = money($bill->total, $currency->code, true)->format();
-
- $bill->grand_total = money($total, $currency->code)->getAmount();
-
- if (!empty($paid)) {
- $bill->grand_total = round($bill->total - $paid, $currency->precision);
- }
-
- $html = view('modals.bills.payment', compact('bill', 'accounts', 'currencies', 'currency', 'payment_methods'))->render();
-
- return response()->json([
- 'success' => true,
- 'error' => false,
- 'message' => 'null',
- 'html' => $html,
- 'data' => [
- 'title' => trans('general.title.new', ['type' => trans_choice('general.payments', 1)]),
- 'buttons' => [
- 'cancel' => [
- 'text' => trans('general.cancel'),
- 'class' => 'btn-outline-secondary'
- ],
- 'confirm' => [
- 'text' => trans('general.save'),
- 'class' => 'btn-success'
- ]
- ]
- ]
- ]);
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param Document $bill
- * @param Request $request
- *
- * @return Response
- */
- public function store(Document $bill, Request $request)
- {
- $response = $this->ajaxDispatch(new CreateBankingDocumentTransaction($bill, $request));
-
- if ($response['success']) {
- $response['redirect'] = route('bills.show', $bill->id);
-
- $message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]);
-
- flash($message)->success();
- } else {
- $response['redirect'] = null;
- }
-
- return response()->json($response);
- }
-}
diff --git a/app/Http/Controllers/Modals/InvoiceTransactions.php b/app/Http/Controllers/Modals/DocumentTransactions.php
similarity index 60%
rename from app/Http/Controllers/Modals/InvoiceTransactions.php
rename to app/Http/Controllers/Modals/DocumentTransactions.php
index 95ea68153..fde3332c1 100644
--- a/app/Http/Controllers/Modals/InvoiceTransactions.php
+++ b/app/Http/Controllers/Modals/DocumentTransactions.php
@@ -12,7 +12,7 @@ use App\Models\Setting\Currency;
use App\Utilities\Modules;
use App\Traits\Uploads;
-class InvoiceTransactions extends Controller
+class DocumentTransactions extends Controller
{
use Uploads;
@@ -22,45 +22,45 @@ class InvoiceTransactions extends Controller
public function __construct()
{
// Add CRUD permission check
- $this->middleware('permission:create-sales-invoices')->only('create', 'store', 'duplicate', 'import');
- $this->middleware('permission:read-sales-invoices')->only('index', 'show', 'edit', 'export');
- $this->middleware('permission:update-sales-invoices')->only('update', 'enable', 'disable');
- $this->middleware('permission:delete-sales-invoices')->only('destroy');
+ //$this->middleware('permission:create-sales-invoices')->only('create', 'store', 'duplicate', 'import');
+ //$this->middleware('permission:read-sales-invoices')->only('index', 'show', 'edit', 'export');
+ //$this->middleware('permission:update-sales-invoices')->only('update', 'enable', 'disable');
+ //$this->middleware('permission:delete-sales-invoices')->only('destroy');
}
/**
* Show the form for creating a new resource.
*
- * @param Document $invoice
+ * @param Document $document
*
* @return Response
*/
- public function create(Document $invoice)
+ public function create(Document $document)
{
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');
$currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray();
- $currency = Currency::where('code', $invoice->currency_code)->first();
+ $currency = Currency::where('code', $document->currency_code)->first();
$payment_methods = Modules::getPaymentMethods();
- $paid = $invoice->paid;
+ $paid = $document->paid;
- // Get Invoice Totals
- foreach ($invoice->totals as $invoice_total) {
- $invoice->{$invoice_total->code} = $invoice_total->amount;
+ // Get document Totals
+ foreach ($document->totals as $document_total) {
+ $document->{$document_total->code} = $document_total->amount;
}
- $total = money($invoice->total, $currency->code, true)->format();
+ $total = money($document->total, $currency->code, true)->format();
- $invoice->grand_total = money($total, $currency->code)->getAmount();
+ $document->grand_total = money($total, $currency->code)->getAmount();
if (!empty($paid)) {
- $invoice->grand_total = round($invoice->total - $paid, $currency->precision);
+ $document->grand_total = round($document->total - $paid, $currency->precision);
}
- $html = view('modals.invoices.payment', compact('invoice', 'accounts', 'currencies', 'currency', 'payment_methods'))->render();
+ $html = view('modals.documents.payment', compact('document', 'accounts', 'currencies', 'currency', 'payment_methods'))->render();
return response()->json([
'success' => true,
@@ -91,17 +91,23 @@ class InvoiceTransactions extends Controller
/**
* Store a newly created resource in storage.
*
- * @param Document $invoice
+ * @param Document $document
* @param Request $request
*
* @return Response
*/
- public function store(Document $invoice, Request $request)
+ public function store(Document $document, Request $request)
{
- $response = $this->ajaxDispatch(new CreateBankingDocumentTransaction($invoice, $request));
+ $response = $this->ajaxDispatch(new CreateBankingDocumentTransaction($document, $request));
if ($response['success']) {
- $response['redirect'] = route('invoices.show', $invoice->id);
+ $route = config('type.' . $document->type . '.route.prefix');
+
+ if ($alias = config('type.' . $document->type . '.alias')) {
+ $route = $alias . '.' . $route;
+ }
+
+ $response['redirect'] = route($route . '.show', $document->id);
$message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]);
diff --git a/resources/views/modals/bills/payment.blade.php b/resources/views/modals/documents/payment.blade.php
similarity index 61%
rename from resources/views/modals/bills/payment.blade.php
rename to resources/views/modals/documents/payment.blade.php
index cf01f2f96..56c0023a2 100644
--- a/resources/views/modals/bills/payment.blade.php
+++ b/resources/views/modals/documents/payment.blade.php
@@ -4,7 +4,7 @@
'@keydown' => 'form.errors.clear($event.target.name)',
'role' => 'form',
'class' => 'form-loading-button',
- 'route' => ['modals.bills.bill.transactions.store', $bill->id],
+ 'route' => ['modals.documents.document.transactions.store', $document->id],
'novalidate' => true
]) !!}