Completed
Push — development ( 877883...280d38 )
by Ashutosh
10:04
created

AdminOrderInvoiceController::getPaymentDetail()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 40
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 40
rs 9.472
c 0
b 0
f 0
cc 3
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\User;
4
5
use Illuminate\Http\Request;
6
use App\Model\Order\Invoice;
7
use App\Http\Controllers\Controller;
8
9
class AdminOrderInvoiceController extends Controller
10
{
11
    public function getClientInvoice($id)
12
    {
13
        $invoice = new Invoice();
14
        $client = $this->user->where('id', $id)->first();
15
        $invoices = $invoice->where('user_id', $id)->orderBy('created_at', 'desc')->get();
16
      
17
        return\ DataTables::of($invoices)
18
                        ->addColumn('checkbox', function ($model) {
19
                            return "<input type='checkbox' class='invoice_checkbox' 
20
                            value=".$model->id.' name=select[] id=check>';
21
                        })
22
                        ->addColumn('date', function ($model) use ($client) {
23
                            $date1 = new \DateTime($model->date);
24
                            $tz = $client->timezone()->first()->name;
25
                            $date1->setTimezone(new \DateTimeZone($tz));
26
                            $date = $date1->format('M j, Y, g:i a ');
27
                            return $date;
28
                        })
29
                        ->addColumn('invoice_no', function ($model) {
30
                            return  	'<a href='.url('invoices/show?invoiceid='.$model->id).'>'.$model->number.'</a>';
31
                        })
32
                        ->addColumn('total', function ($model) use ($client) {
33
                            return currency_format($model->grand_total, $code =$client->currency);
34
                        })
35
                         ->addColumn('paid', function ($model) use ($client) {
36
                             $payment = \App\Model\Order\Payment::where('invoice_id', $model->id)->select('amount')->get();
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
37
                             $c=count($payment);
38
                             $sum = 0;
39
                             for ($i=0 ;  $i <= $c-1 ; $i++) {
40
                                 $sum = $sum + $payment[$i]->amount;
41
                             }
42
                             return currency_format($sum, $code =$client->currency);
43
                         })
44
                         ->addColumn('balance', function ($model) use ($client) {
45
                             $payment = \App\Model\Order\Payment::where('invoice_id', $model->id)->select('amount')->get();
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
46
                             $c=count($payment);
47
                             $sum = 0;
48
                             for ($i=0 ;  $i <= $c-1 ; $i++) {
49
                                 $sum = $sum + $payment[$i]->amount;
50
                             }
51
                             $pendingAmount = ($model->grand_total)-($sum);
52
                             return currency_format($pendingAmount, $code =$client->currency);
53
                         })
54
                          ->addColumn('status', function ($model) {
55
                              return $model->status;
56
                          })
57
                        ->addColumn('action', function ($model) {
58
                            $action = '';
59
                            $cont = new \App\Http\Controllers\Order\TaxRatesAndCodeExpiryController();
60
                            $check = $cont->checkExecution($model->id);
61
                            if ($check == false) {
62
                                $action = '<a href='.url('order/execute?invoiceid='.$model->id)
63
                                ." class='btn btn-sm btn-primary btn-xs'>
64
                                <i class='fa fa-tasks' style='color:white;'>
65
                                 </i>&nbsp;&nbsp; Execute Order</a>";
66
                            }
67
                            $editAction = '<a href='.url('invoices/edit/'.$model->id)
68
                                ." class='btn btn-sm btn-primary btn-xs'>
69
                                <i class='fa fa-edit' style='color:white;'>
70
                                 </i>&nbsp;&nbsp; Edit</a>";
71
72
                            return '<a href='.url('invoices/show?invoiceid='.$model->id)
73
                            ." class='btn btn-sm btn-primary btn-xs'><i class='fa fa-eye' 
74
                            style='color:white;'> </i>&nbsp;&nbsp;View</a>"
75
                                    ."   $editAction $action";
76
                        })
77
                         ->rawColumns(['checkbox', 'date', 'invoice_no', 'total', 'paid', 'balance', 'status','action'])
78
                        ->make(true);
79
    }
80
81
82
    public function getOrderDetail($id)
83
    {
84
        $client = $this->user->where('id', $id)->first();
85
        $order = $client->order()->orderBy('created_at', 'desc')->get();
86
87
        return\ DataTables::of($order)
88
                        ->addColumn('checkbox', function ($model) {
89
                            return "<input type='checkbox' class='order_checkbox' 
90
                            value=".$model->id.' name=select[] id=checkorder>';
91
                        })
92
                        ->addColumn('date', function ($model) {
93
                            return ucfirst($model->created_at);
94
                        })
95
                        ->addColumn('product', function ($model) {
96
                            $productName = $model->product()->first() && $model->product()->first()->name ?
97
                            $model->product()->first()->name : 'Unknown';
98
99
                            return $productName;
100
                        })
101
                        ->addColumn('number', function ($model) {
102
                            $number= $model->number;
103
104
                            return ($number);
105
                        })
106
                         ->addColumn('total', function ($model) use ($client) {
107
                             $price = currency_format($model->price_override, $code = $client->currency);
108
                             return $price;
109
                         })
110
                         ->addColumn('status', function ($model) {
111
                             $status = $model->order_status;
112
                             return $status;
113
                         })
114
                        ->addColumn('action', function ($model) {
115
                            return '<a href='.url('orders/'.$model->id)." 
116
                            class='btn btn-sm btn-primary btn-xs'><i class='fa fa-eye' 
117
                            style='color:white;'> </i>&nbsp;&nbsp;View</a>";
118
                        })
119
                        ->rawColumns(['checkbox', 'date', 'product', 'number', 'total', 'status', 'action'])
120
                        ->make(true);
121
    }
122
123
    //Get Payment Details on Invoice Page
124
    public function getPaymentDetail($id)
125
    {
126
        $client = $this->user->where('id', $id)->first();
127
        $payments = $client->payment()->orderBy('created_at', 'desc')->get();
128
        $extraAmt = $this->getExtraAmtPaid($id);
129
130
        return\ DataTables::of($payments)
131
                        ->addColumn('checkbox', function ($model) {
132
                            return "<input type='checkbox' class='payment_checkbox' 
133
                            value=".$model->id.' name=select[] id=checkpayment>';
134
                        })
135
                        ->addColumn('invoice_no', function ($model) {
136
                            return $model->invoice()->first() ? $model->invoice()->first()->number : '--';
137
                        })
138
                        ->addColumn('date', function ($model) {
139
                            $date = $model->created_at;
140
                            $date1 = new \DateTime($date);
141
                            $tz = \Auth::user()->timezone()->first()->name;
142
                            $date1->setTimezone(new \DateTimeZone($tz));
143
                            $date = $date1->format('M j, Y, g:i a ');
144
                            return $date;
145
                        })
146
                        ->addColumn('payment_method', function ($model) {
147
                            return $model->payment_method;
148
                            ;
149
                        })
150
                         ->addColumn('total', function ($model) use ($client,$extraAmt) {
151
                             if ($model->invoice_id == 0) {
152
                                 $amount = currency_format($extraAmt, $code = $client->currency);
153
                             } else {
154
                                 $amount = currency_format($model->amount, $code = $client->currency);
155
                             }
156
                             return $amount;
157
                         })
158
                         ->addColumn('status', function ($model) {
159
                             return ucfirst($model->payment_status);
160
                         })
161
                      
162
                        ->rawColumns(['checkbox', 'invoice_no', 'date', 'payment_method', 'total', 'status'])
163
                        ->make(true);
164
    }
165
}
166