model binding

This commit is contained in:
denisdulici 2017-11-08 17:22:04 +03:00
parent 7cd0a1b1ed
commit b2aab4f66c
3 changed files with 27 additions and 38 deletions

View File

@ -459,36 +459,33 @@ class Bills extends Controller
} }
/** /**
* Mark the invoice as sent. * Mark the bill as received.
* *
* @param int $invoice_id * @param Bill $bill
* *
* @return Response * @return Response
*/ */
public function markReceived($bill_id) public function markReceived(Bill $bill)
{ {
$bill = Bill::find($bill_id);
$bill->bill_status_code = 'received'; $bill->bill_status_code = 'received';
$bill->save(); $bill->save();
flash(trans('bills.marked_received'))->success(); flash(trans('bills.messages.received'))->success();
return redirect()->back(); return redirect()->back();
} }
/** /**
* Show the form for viewing the specified resource. * Print the bill.
* *
* @param int $bill_id * @param Bill $bill
* *
* @return Response * @return Response
*/ */
public function printBill($bill_id) public function printBill(Bill $bill)
{ {
$paid = 0; $paid = 0;
$bill = Bill::where('id', $bill_id)->first();
foreach ($bill->payments as $item) { foreach ($bill->payments as $item) {
$item->default_currency_code = $bill->currency_code; $item->default_currency_code = $bill->currency_code;
@ -501,18 +498,16 @@ class Bills extends Controller
} }
/** /**
* Show the form for viewing the specified resource. * Download the PDF file of bill.
* *
* @param int $bill_id * @param Bill $bill
* *
* @return Response * @return Response
*/ */
public function pdfBill($bill_id) public function pdfBill(Bill $bill)
{ {
$paid = 0; $paid = 0;
$bill = Bill::where('id', $bill_id)->first();
foreach ($bill->payments as $item) { foreach ($bill->payments as $item) {
$item->default_currency_code = $bill->currency_code; $item->default_currency_code = $bill->currency_code;
@ -532,7 +527,7 @@ class Bills extends Controller
} }
/** /**
* Show the form for viewing the specified resource. * Add payment to the bill.
* *
* @param PaymentRequest $request * @param PaymentRequest $request
* *

View File

@ -393,13 +393,12 @@ class Invoices extends Controller
/** /**
* Mark the invoice as sent. * Mark the invoice as sent.
* *
* @param int $invoice_id * @param Invoice $invoice
* *
* @return Response * @return Response
*/ */
public function markSent($invoice_id) public function markSent(Invoice $invoice)
{ {
$invoice = Invoice::find($invoice_id);
$invoice->invoice_status_code = 'sent'; $invoice->invoice_status_code = 'sent';
$invoice->save(); $invoice->save();
@ -411,15 +410,14 @@ class Invoices extends Controller
/** /**
* Mark the invoice as paid. * Mark the invoice as paid.
* *
* @param int $invoice_id * @param Invoice $invoice
* *
* @return Response * @return Response
*/ */
public function payInvoice($invoice_id) public function payInvoice(Invoice $invoice)
{ {
$invoice = Invoice::find($invoice_id);
$paid = 0; $paid = 0;
foreach ($invoice->payments as $item) { foreach ($invoice->payments as $item) {
$item->default_currency_code = $invoice->currency_code; $item->default_currency_code = $invoice->currency_code;
@ -447,16 +445,14 @@ class Invoices extends Controller
/** /**
* Print the invoice. * Print the invoice.
* *
* @param int $invoice_id * @param Invoice $invoice
* *
* @return Response * @return Response
*/ */
public function printInvoice($invoice_id) public function printInvoice(Invoice $invoice)
{ {
$paid = 0; $paid = 0;
$invoice = Invoice::find($invoice_id);
foreach ($invoice->payments as $item) { foreach ($invoice->payments as $item) {
$item->default_currency_code = $invoice->currency_code; $item->default_currency_code = $invoice->currency_code;
@ -475,16 +471,14 @@ class Invoices extends Controller
/** /**
* Download the PDF file of invoice. * Download the PDF file of invoice.
* *
* @param int $invoice_id * @param Invoice $invoice
* *
* @return Response * @return Response
*/ */
public function pdfInvoice($invoice_id) public function pdfInvoice(Invoice $invoice)
{ {
$paid = 0; $paid = 0;
$invoice = Invoice::find($invoice_id);
foreach ($invoice->payments as $item) { foreach ($invoice->payments as $item) {
$item->default_currency_code = $invoice->currency_code; $item->default_currency_code = $invoice->currency_code;

View File

@ -44,10 +44,10 @@ Route::group(['middleware' => 'language'], function () {
Route::group(['prefix' => 'incomes'], function () { Route::group(['prefix' => 'incomes'], function () {
Route::get('customers/currency', 'Incomes\Customers@currency'); Route::get('customers/currency', 'Incomes\Customers@currency');
Route::resource('customers', 'Incomes\Customers'); Route::resource('customers', 'Incomes\Customers');
Route::get('invoices/{id}/sent', 'Incomes\Invoices@markSent'); Route::get('invoices/{invoice}/sent', 'Incomes\Invoices@markSent');
Route::get('invoices/{id}/pay', 'Incomes\Invoices@payInvoice'); Route::get('invoices/{invoice}/pay', 'Incomes\Invoices@payInvoice');
Route::get('invoices/{id}/print', 'Incomes\Invoices@printInvoice'); Route::get('invoices/{invoice}/print', 'Incomes\Invoices@printInvoice');
Route::get('invoices/{id}/pdf', 'Incomes\Invoices@pdfInvoice'); Route::get('invoices/{invoice}/pdf', 'Incomes\Invoices@pdfInvoice');
Route::post('invoices/payment', 'Incomes\Invoices@payment'); Route::post('invoices/payment', 'Incomes\Invoices@payment');
Route::delete('invoices/payment/{payment}', 'Incomes\Invoices@paymentDestroy'); Route::delete('invoices/payment/{payment}', 'Incomes\Invoices@paymentDestroy');
Route::resource('invoices', 'Incomes\Invoices'); Route::resource('invoices', 'Incomes\Invoices');
@ -56,9 +56,9 @@ Route::group(['middleware' => 'language'], function () {
Route::group(['prefix' => 'expenses'], function () { Route::group(['prefix' => 'expenses'], function () {
Route::resource('payments', 'Expenses\Payments'); Route::resource('payments', 'Expenses\Payments');
Route::get('bills/{id}/received', 'Expenses\Bills@markReceived'); Route::get('bills/{bill}/received', 'Expenses\Bills@markReceived');
Route::get('bills/{id}/print', 'Expenses\Bills@printBill'); Route::get('bills/{bill}/print', 'Expenses\Bills@printBill');
Route::get('bills/{id}/pdf', 'Expenses\Bills@pdfBill'); Route::get('bills/{bill}/pdf', 'Expenses\Bills@pdfBill');
Route::post('bills/payment', 'Expenses\Bills@payment'); Route::post('bills/payment', 'Expenses\Bills@payment');
Route::delete('bills/payment/{payment}', 'Expenses\Bills@paymentDestroy'); Route::delete('bills/payment/{payment}', 'Expenses\Bills@paymentDestroy');
Route::resource('bills', 'Expenses\Bills'); Route::resource('bills', 'Expenses\Bills');