Passed
Push — master ( 55010d...cba042 )
by Matthijs
06:10
created

InvoiceController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * InvoiceController
5
 *
6
 * This is the controller of the invoices of the shop
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 0.1
9
 */
10
11
use App\Http\Controllers\Controller;
12
use Hideyo\Ecommerce\Framework\Services\Invoice\InvoiceFacade as InvoiceService;
13
use Hideyo\Ecommerce\Framework\Services\TaxRate\TaxRateFacade as TaxRateService;
14
use Hideyo\Ecommerce\Framework\Services\PaymentMethod\PaymentMethodFacade as PaymentMethodService;
15
16
use \Request;
17
use \Notification;
18
use \Redirect;
19
20
class InvoiceController extends Controller
21
{
22
    public function index()
23
    {
24
        if (Request::wantsJson()) {
25
26
            $invoice = InvoiceService::getModel()->select(
27
                [
28
                'id', 'generated_custom_invoice_id', 'order_id',
29
                'price_with_tax']
30
            )->with(array('Order'))->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id);
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
31
            
32
            
33
            $datatables = \DataTables::of($invoice)
34
            ->addColumn('price_with_tax', function ($order) {
35
                $money = '&euro; '.$order->price_with_tax;
36
                return $money;
37
            })
38
            ->addColumn('action', function ($invoice) {
39
                $deleteLink = \Form::deleteajax('/invoice/'. $invoice->id, 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
0 ignored issues
show
Unused Code introduced by
The assignment to $deleteLink is dead and can be removed.
Loading history...
40
                $download = '<a href="/invoice/'.$invoice->id.'/download" class="btn btn-default btn-sm btn-info"><i class="entypo-pencil"></i>Download</a>  ';
41
                $links = '<a href="/invoice/'.$invoice->id.'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Show</a>  '.$download;
42
            
43
                return $links;
44
            });
45
46
            return $datatables->make(true);
47
        }
48
        
49
        return view('backend.invoice.index')->with('invoice', InvoiceService::selectAll());
50
    }
51
52
    public function show($invoiceId)
53
    {
54
        return view('backend.invoice.show')->with('invoice', InvoiceService::find($invoiceId));
55
    }
56
57
    public function download($invoiceId)
58
    {
59
        $invoice = InvoiceService::find($invoiceId);
60
        $pdf = \PDF::loadView('invoice.pdf', array('invoice' => $invoice));
0 ignored issues
show
Bug introduced by
The type PDF was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
        return $pdf->download('invoice-'.$invoice->generated_custom_invoice_id.'.pdf');
62
    }
63
64
    public function create()
65
    {
66
        return view('backend.invoice.create')->with(array(
67
            'taxRates' => TaxRateService::selectAll()->pluck('title', 'id'),
68
            'paymentMethods' => PaymentMethodService::selectAll()->pluck('title', 'id')
69
        ));
70
    }
71
72
    public function store()
73
    {
74
        $result  = InvoiceService::create(Request::all());
75
76
        if (isset($result->id)) {
77
            \Notification::success('The invoice was inserted.');
78
            return \Redirect::route('sending-method.index');
79
        }
80
        
81
        \Notification::error($result->errors()->all());
82
        return \Redirect::back()->withInput();
83
    }
84
85
    public function edit($invoiceId)
86
    {
87
        return view('backend.invoice.edit')->with(array(
88
            'taxRates' => TaxRateService::selectAll()->pluck('title', 'id'),
89
            'invoice' => InvoiceService::find($invoiceId),
90
            'paymentMethods' => PaymentMethodService::selectAll()->pluck('title', 'id'),
91
        ));
92
    }
93
94
    public function update($invoiceId)
95
    {
96
        $result  = InvoiceService::updateById(Request::all(), $invoiceId);
97
98
        if (isset($result->id)) {
99
            \Notification::success('The invoice was updated.');
100
            return \Redirect::route('sending-method.index');
101
        }
102
        
103
        \Notification::error($result->errors()->all());
104
        return \Redirect::back()->withInput();
105
    }
106
107
    public function destroy($invoiceId)
108
    {
109
        $result  = InvoiceService::destroy($invoiceId);
110
111
        if ($result) {
112
            Notification::success('The invoice was deleted.');
113
            return Redirect::route('sending-method.index');
114
        }
115
    }
116
}
117