Document add payment modal fixed..
This commit is contained in:
@ -1,110 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Modals;
|
||||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Utilities\Modules;
|
||||
use App\Traits\Uploads;
|
||||
|
||||
class BillTransactions extends Controller
|
||||
{
|
||||
use Uploads;
|
||||
|
||||
/**
|
||||
* Instantiate a new controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Add CRUD permission check
|
||||
$this->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);
|
||||
}
|
||||
}
|
@ -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)]);
|
||||
|
Reference in New Issue
Block a user