InvoiceController   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 44
c 2
b 0
f 1
dl 0
loc 94
rs 10
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A download() 0 5 1
A index() 0 28 2
A show() 0 3 1
A destroy() 0 7 2
A edit() 0 6 1
A store() 0 11 2
A create() 0 5 1
A update() 0 11 2
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 Illuminate\Http\Request;
17
18
class InvoiceController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $invoice = InvoiceService::getModel()->select(
25
                [
26
                'id', 'generated_custom_invoice_id', 'order_id',
27
                'price_with_tax']
28
            )->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...
29
            
30
            
31
            $datatables = \DataTables::of($invoice)
32
            ->addColumn('price_with_tax', function ($order) {
33
                $money = '&euro; '.$order->price_with_tax;
34
                return $money;
35
            })
36
            ->addColumn('action', function ($invoice) {
37
                $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...
38
                $download = '<a href="/invoice/'.$invoice->id.'/download" class="btn btn-default btn-sm btn-info"><i class="entypo-pencil"></i>Download</a>  ';
39
                $links = '<a href="/invoice/'.$invoice->id.'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Show</a>  '.$download;
40
            
41
                return $links;
42
            });
43
44
            return $datatables->make(true);
45
        }
46
        
47
        return view('backend.invoice.index')->with('invoice', InvoiceService::selectAll());
48
    }
49
50
    public function show($invoiceId)
51
    {
52
        return view('backend.invoice.show')->with('invoice', InvoiceService::find($invoiceId));
53
    }
54
55
    public function download($invoiceId)
56
    {
57
        $invoice = InvoiceService::find($invoiceId);
58
        $pdf = \PDF::loadView('invoice.pdf', array('invoice' => $invoice));
59
        return $pdf->download('invoice-'.$invoice->generated_custom_invoice_id.'.pdf');
60
    }
61
62
    public function create()
63
    {
64
        return view('backend.invoice.create')->with(array(
65
            'taxRates' => TaxRateService::selectAll()->pluck('title', 'id'),
66
            'paymentMethods' => PaymentMethodService::selectAll()->pluck('title', 'id')
67
        ));
68
    }
69
70
    public function store(Request $request)
71
    {
72
        $result  = InvoiceService::create($request->all());
73
74
        if (isset($result->id)) {
75
            flash('The invoice was inserted.');
76
            return redirect()->route('sending-method.index');
77
        }
78
        
79
        flash($result->errors()->all());
80
        return redirect()->back()->withInput();
81
    }
82
83
    public function edit($invoiceId)
84
    {
85
        return view('backend.invoice.edit')->with(array(
86
            'taxRates' => TaxRateService::selectAll()->pluck('title', 'id'),
87
            'invoice' => InvoiceService::find($invoiceId),
88
            'paymentMethods' => PaymentMethodService::selectAll()->pluck('title', 'id'),
89
        ));
90
    }
91
92
    public function update(Request $request, $invoiceId)
93
    {
94
        $result  = InvoiceService::updateById($request->all(), $invoiceId);
95
96
        if (isset($result->id)) {
97
            flash('The invoice was updated.');
98
            return redirect()->route('sending-method.index');
99
        }
100
        
101
        flash($result->errors()->all());
102
        return redirect()->back()->withInput();
103
    }
104
105
    public function destroy($invoiceId)
106
    {
107
        $result  = InvoiceService::destroy($invoiceId);
108
109
        if ($result) {
110
            flash('The invoice was deleted.');
111
            return Redirect::route('sending-method.index');
112
        }
113
    }
114
}
115