|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Order; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Model\Order\Invoice; |
|
7
|
|
|
use App\Model\Order\Order; |
|
8
|
|
|
use App\Model\Order\Payment; |
|
9
|
|
|
use Exception; |
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
|
|
12
|
|
|
class ExtendedBaseInvoiceController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
public function __construct() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->middleware('auth'); |
|
17
|
|
|
$this->middleware('admin', ['except' => ['pdf']]); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function newPayment(Request $request) |
|
21
|
|
|
{ |
|
22
|
|
|
try { |
|
23
|
|
|
$clientid = $request->input('clientid'); |
|
24
|
|
|
$invoice = new Invoice(); |
|
25
|
|
|
$order = new Order(); |
|
26
|
|
|
$invoices = $invoice->where('user_id', $clientid)->where('status', '=', 'pending')->orderBy('created_at', 'desc')->get(); |
|
|
|
|
|
|
27
|
|
|
$cltCont = new \App\Http\Controllers\User\ClientController(); |
|
28
|
|
|
$invoiceSum = $cltCont->getTotalInvoice($invoices); |
|
29
|
|
|
$amountReceived = $cltCont->getAmountPaid($clientid); |
|
30
|
|
|
$pendingAmount = $invoiceSum - $amountReceived; |
|
31
|
|
|
$client = $this->user->where('id', $clientid)->first(); |
|
32
|
|
|
$currency = $client->currency; |
|
33
|
|
|
$orders = $order->where('client', $clientid)->get(); |
|
34
|
|
|
|
|
35
|
|
|
return view('themes.default1.invoice.newpayment', compact('clientid', 'client', 'invoices', 'orders', |
|
36
|
|
|
'invoiceSum', 'amountReceived', 'pendingAmount', 'currency')); |
|
37
|
|
|
} catch (Exception $ex) { |
|
38
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function postNewPayment($clientid, Request $request) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->validate($request, [ |
|
45
|
|
|
'payment_date' => 'required', |
|
46
|
|
|
'payment_method'=> 'required', |
|
47
|
|
|
'amount' => 'required', |
|
48
|
|
|
]); |
|
49
|
|
|
|
|
50
|
|
|
try { |
|
51
|
|
|
$payment = new Payment(); |
|
52
|
|
|
$payment->payment_status = 'success'; |
|
53
|
|
|
$payment->user_id = $clientid; |
|
54
|
|
|
$payment->invoice_id = '--'; |
|
55
|
|
|
$paymentReceived = $payment->fill($request->all())->save(); |
|
56
|
|
|
|
|
57
|
|
|
return redirect()->back()->with('success', \Lang::get('message.saved-successfully')); |
|
58
|
|
|
} catch (Exception $ex) { |
|
59
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function edit($invoiceid, Request $request) |
|
64
|
|
|
{ |
|
65
|
|
|
$invoice = Invoice::where('id',$invoiceid)->first(); |
|
66
|
|
|
// $payment = Payment::where() |
|
67
|
|
|
return view('themes.default1.invoice.editInvoice',compact('userid','invoiceid','invoice')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function postEdit($invoiceid, Request $request) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->validate($request,[ |
|
73
|
|
|
'total' => 'required', |
|
74
|
|
|
'status'=> 'required', |
|
75
|
|
|
]); |
|
76
|
|
|
try{ |
|
77
|
|
|
$total = $request->input('total'); |
|
78
|
|
|
$status = $request->input('status'); |
|
79
|
|
|
$invoice = Invoice::where('id',$invoiceid)->update(['grand_total'=>$total,'status'=>$status]); |
|
80
|
|
|
return redirect()->back()->with('success', \Lang::get('message.updated-successfully')); |
|
81
|
|
|
}catch (\Exception $ex) |
|
82
|
|
|
{ |
|
83
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
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.