1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Front; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use App\Http\Controllers\License\LicensePermissionsController; |
7
|
|
|
use App\Http\Requests\User\ProfileRequest; |
8
|
|
|
use App\Model\Order\Invoice; |
9
|
|
|
use App\Model\Order\Order; |
10
|
|
|
use App\Model\Product\Product; |
11
|
|
|
use App\Model\Product\Subscription; |
12
|
|
|
use Bugsnag; |
13
|
|
|
use DateTime; |
14
|
|
|
use DateTimeZone; |
15
|
|
|
use Exception; |
16
|
|
|
use Hash; |
17
|
|
|
|
18
|
|
|
class BaseClientController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Get the version list popup for the Product. |
22
|
|
|
* |
23
|
|
|
* @author Ashutosh Pathak <[email protected]> |
24
|
|
|
* |
25
|
|
|
* @date 2019-01-06 |
26
|
|
|
* |
27
|
|
|
* @param Order $orders Order For the Client |
28
|
|
|
* @param int $productid Product id for the Order |
29
|
|
|
* |
30
|
|
|
* @return array Show Modal Popup if Condition Satisfies |
31
|
|
|
*/ |
32
|
|
|
public function getPopup(Order $orders, int $productid) |
33
|
|
|
{ |
34
|
|
|
$listUrl = ''; |
35
|
|
|
$permissions = LicensePermissionsController::getPermissionsForProduct($productid); |
36
|
|
|
$productCheck = $orders->product() |
37
|
|
|
->select('github_owner', 'github_repository', 'type') |
38
|
|
|
->where('id', $orders->product)->first(); |
39
|
|
|
if ($permissions['downloadPermission'] == 1) { //If the Product has doownlaod permission |
40
|
|
|
if (!$productCheck->github_owner == '' && !$productCheck->github_repository == '') { |
41
|
|
|
$listUrl = $this->downloadGithubPopup($orders->client, $orders->invoice()->first()->id, $productid); |
42
|
|
|
} else { |
43
|
|
|
$listUrl = $this->downloadPopup($orders->client, $orders->invoice()->first()->number, $productid); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $listUrl; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get expiry Date for order. |
52
|
|
|
* |
53
|
|
|
* @param type $orders |
54
|
|
|
* |
55
|
|
|
* @return type |
56
|
|
|
*/ |
57
|
|
|
public function getExpiryDate($orders) |
58
|
|
|
{ |
59
|
|
|
$end = '--'; |
60
|
|
|
if ($orders->subscription()->first()) { |
61
|
|
|
if ($end != '0000-00-00 00:00:00' || $end != null) { |
62
|
|
|
$ends = new DateTime($orders->subscription()->first()->ends_at); |
63
|
|
|
$tz = \Auth::user()->timezone()->first()->name; |
64
|
|
|
$ends->setTimezone(new DateTimeZone($tz)); |
65
|
|
|
$date = $ends->format('M j, Y, g:i a '); |
66
|
|
|
$end = $date; |
67
|
|
|
// dd($end); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $end; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function downloadPopup($clientid, $invoiceid, $productid) |
75
|
|
|
{ |
76
|
|
|
return view('themes.default1.front.clients.download-list', |
77
|
|
|
compact('clientid', 'invoiceid', 'productid')); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function downloadGithubPopup($clientid, $invoiceid, $productid) |
81
|
|
|
{ |
82
|
|
|
return view('themes.default1.front.clients.download-github-list', |
83
|
|
|
compact('clientid', 'invoiceid', 'productid')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function renewPopup($id, $productid) |
87
|
|
|
{ |
88
|
|
|
return view('themes.default1.renew.popup', compact('id', 'productid')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getActionButton($countExpiry, $countVersions, $link, $orderEndDate, $productid) |
92
|
|
|
{ |
93
|
|
|
$downloadPermission = LicensePermissionsController::getPermissionsForProduct($productid); |
94
|
|
|
if ($downloadPermission['allowDownloadTillExpiry'] == 1) { |
95
|
|
|
if (strtotime($link['created_at']) < strtotime($orderEndDate->update_ends_at)) { |
96
|
|
|
$githubApi = new \App\Http\Controllers\Github\GithubApiController(); |
97
|
|
|
|
98
|
|
|
$link = $githubApi->getCurl1($link['zipball_url']); |
99
|
|
|
|
100
|
|
|
return '<p><a href='.$link['header']['Location']." |
101
|
|
|
class='btn btn-sm btn-primary'><i class='fa fa-download'> |
102
|
|
|
</i> Download</a>".' |
103
|
|
|
|
104
|
|
|
</p>'; |
105
|
|
|
} else { |
106
|
|
|
return '<button class="btn btn-primary btn-sm disabled tooltip"> |
107
|
|
|
Download <span class="tooltiptext">Please Renew!!</span></button>'; |
108
|
|
|
} |
109
|
|
|
} elseif ($downloadPermission['allowDownloadTillExpiry'] == 0) { |
110
|
|
|
if ($countExpiry == $countVersions) { |
111
|
|
|
$githubApi = new \App\Http\Controllers\Github\GithubApiController(); |
112
|
|
|
$link = $githubApi->getCurl1($link['zipball_url']); |
113
|
|
|
|
114
|
|
|
return '<p><a href='.$link['header']['Location']." |
115
|
|
|
class='btn btn-sm btn-primary'><i class='fa fa-download'> |
116
|
|
|
</i> Download</a>".' |
117
|
|
|
|
118
|
|
|
</p>'; |
119
|
|
|
} else { |
120
|
|
|
return '<button class="btn btn-primary btn-sm disabled tooltip"> |
121
|
|
|
Download <span class="tooltiptext">Please Renew!!</span></button>'; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Update Profile. |
128
|
|
|
*/ |
129
|
|
|
public function postProfile(ProfileRequest $request) |
130
|
|
|
{ |
131
|
|
|
try { |
132
|
|
|
$user = \Auth::user(); |
133
|
|
|
if ($request->hasFile('profile_pic')) { |
134
|
|
|
$name = \Input::file('profile_pic')->getClientOriginalName(); |
135
|
|
|
$destinationPath = 'dist/app/users'; |
136
|
|
|
$fileName = rand(0000, 9999).'.'.$name; |
137
|
|
|
\Input::file('profile_pic')->move($destinationPath, $fileName); |
138
|
|
|
$user->profile_pic = $fileName; |
139
|
|
|
} |
140
|
|
|
$user->first_name = strip_tags($request->input('first_name')); |
141
|
|
|
$user->last_name = strip_tags($request->input('last_name')); |
142
|
|
|
$user->email = strip_tags($request->input('email')); |
143
|
|
|
$user->company = strip_tags($request->input('company')); |
144
|
|
|
$user->mobile_code = strip_tags($request->input('mobile_code')); |
145
|
|
|
$user->mobile = strip_tags($request->input('mobile')); |
146
|
|
|
$user->address = strip_tags($request->input('address')); |
147
|
|
|
$user->town = strip_tags($request->input('town')); |
148
|
|
|
$user->timezone_id = strip_tags($request->input('timezone_id')); |
149
|
|
|
$user->country = ($request->input('country')); |
150
|
|
|
$user->state = ($request->input('state')); |
151
|
|
|
$user->zip = strip_tags($request->input('zip')); |
152
|
|
|
$user->save(); |
153
|
|
|
|
154
|
|
|
return redirect()->back()->with('success', \Lang::get('message.updated-successfully')); |
155
|
|
|
} catch (Exception $ex) { |
156
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Update Password. |
162
|
|
|
*/ |
163
|
|
|
public function postPassword(ProfileRequest $request) |
164
|
|
|
{ |
165
|
|
|
try { |
166
|
|
|
$user = \Auth::user(); |
167
|
|
|
$oldpassword = $request->input('old_password'); |
168
|
|
|
$currentpassword = $user->getAuthPassword(); |
169
|
|
|
$newpassword = $request->input('new_password'); |
170
|
|
|
if (\Hash::check($oldpassword, $currentpassword)) { |
171
|
|
|
$user->password = Hash::make($newpassword); |
172
|
|
|
$user->save(); |
173
|
|
|
$response = ['type'=>'success', 'message'=>'Password Updated Successfully']; |
174
|
|
|
|
175
|
|
|
return $response; |
176
|
|
|
} else { |
177
|
|
|
$response = ['type'=>'error', 'message'=>'Password Not Updated']; |
178
|
|
|
} |
179
|
|
|
} catch (\Exception $e) { |
180
|
|
|
$result = [$e->getMessage()]; |
181
|
|
|
Bugsnag::notifyException($e); |
182
|
|
|
|
183
|
|
|
return response()->json(compact('result'), 500); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function getInvoicesByOrderId($orderid, $userid) |
188
|
|
|
{ |
189
|
|
|
try { |
190
|
|
|
$order = Order::where('id', $orderid)->where('client', $userid)->first(); |
191
|
|
|
|
192
|
|
|
$relation = $order->invoiceRelation()->pluck('invoice_id')->toArray(); |
193
|
|
|
$invoice = new Invoice(); |
194
|
|
|
$invoices = $invoice |
195
|
|
|
->select('number', 'created_at', 'grand_total', 'id', 'status') |
196
|
|
|
->whereIn('id', $relation); |
197
|
|
|
if ($invoices->get()->count() == 0) { |
198
|
|
|
$invoices = $order->invoice() |
199
|
|
|
->select('number', 'created_at', 'grand_total', 'id', 'status'); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
return \DataTables::of($invoices->get()) |
203
|
|
|
->addColumn('number', function ($model) { |
204
|
|
|
return $model->number; |
205
|
|
|
}) |
206
|
|
|
->addColumn('products', function ($model) { |
207
|
|
|
$invoice = $this->invoice->find($model->id); |
208
|
|
|
$products = $invoice->invoiceItem()->pluck('product_name')->toArray(); |
209
|
|
|
|
210
|
|
|
return ucfirst(implode(',', $products)); |
211
|
|
|
}) |
212
|
|
|
->addColumn('date', function ($model) { |
213
|
|
|
$date = date_create($model->created_at); |
214
|
|
|
|
215
|
|
|
return date_format($date, 'M j, Y, g:i a'); |
216
|
|
|
}) |
217
|
|
|
->addColumn('total', function ($model) { |
218
|
|
|
return $model->grand_total; |
219
|
|
|
}) |
220
|
|
|
->addColumn('status', function ($model) { |
221
|
|
|
return ucfirst($model->status); |
222
|
|
|
}) |
223
|
|
|
->addColumn('action', function ($model) { |
224
|
|
|
if (\Auth::user()->role == 'admin') { |
225
|
|
|
$url = '/invoices/show?invoiceid='.$model->id; |
226
|
|
|
} else { |
227
|
|
|
$url = 'my-invoice'; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
return '<a href='.url($url.'/'.$model->id)." |
231
|
|
|
class='btn btn-sm btn-primary btn-xs'><i class='fa fa-eye' |
232
|
|
|
style='color:white;'> </i> View</a>"; |
233
|
|
|
}) |
234
|
|
|
->rawColumns(['number', 'products', 'date', 'total', 'status', 'action']) |
235
|
|
|
->make(true); |
236
|
|
|
} catch (Exception $ex) { |
237
|
|
|
Bugsnag::notifyException($ex); |
238
|
|
|
|
239
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function getInvoice($id) |
244
|
|
|
{ |
245
|
|
|
try { |
246
|
|
|
$invoice = $this->invoice->findOrFail($id); |
247
|
|
|
$items = $invoice->invoiceItem()->get(); |
248
|
|
|
$user = \Auth::user(); |
249
|
|
|
|
250
|
|
|
return view('themes.default1.front.clients.show-invoice', compact('invoice', 'items', 'user')); |
251
|
|
|
} catch (Exception $ex) { |
252
|
|
|
Bugsnag::notifyException($ex); |
253
|
|
|
|
254
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function subscriptions() |
259
|
|
|
{ |
260
|
|
|
try { |
261
|
|
|
return view('themes.default1.front.clients.subscription'); |
262
|
|
|
} catch (Exception $ex) { |
263
|
|
|
Bugsnag::notifyException($ex); |
264
|
|
|
|
265
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
public function s($updateEndDate, $productid, $versions, $clientid, $invoiceid) |
270
|
|
|
{ |
271
|
|
|
if ($versions->created_at->toDateTimeString() |
272
|
|
|
< $updateEndDate->update_ends_at) { |
273
|
|
|
return '<p><a href='.url('download/'.$productid.'/' |
274
|
|
|
.$clientid.'/'.$invoiceid.'/'.$versions->id). |
275
|
|
|
" class='btn btn-sm btn-primary'><i class='fa fa-download'> |
276
|
|
|
</i> Download</a>".' |
277
|
|
|
|
278
|
|
|
</p>'; |
279
|
|
|
} else { |
280
|
|
|
return '<button class="btn btn-danger |
281
|
|
|
btn-sm disabled">Please Renew </button>'; |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
public function whenDownloadExpiresAfterExpiry($countExpiry, $countVersions, $updatesEndDate, $productid, $versions, $clientid, $invoiceid) |
|
|
|
|
286
|
|
|
{ |
287
|
|
|
if ($countExpiry == $countVersions) { |
288
|
|
|
return '<p><a href='.url('download/'.$productid.'/' |
289
|
|
|
.$clientid.'/'.$invoiceid.'/'.$versions->id). |
290
|
|
|
" class='btn btn-sm btn-primary'><i class='fa fa-download'> |
291
|
|
|
</i> Download</a>".' |
292
|
|
|
|
293
|
|
|
</p>'; |
294
|
|
|
} else { |
295
|
|
|
return '<button class="btn btn-danger |
296
|
|
|
btn-sm disabled">Please Renew </button>'; |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function orders() |
301
|
|
|
{ |
302
|
|
|
try { |
303
|
|
|
return view('themes.default1.front.clients.order1'); |
304
|
|
|
} catch (Exception $ex) { |
305
|
|
|
Bugsnag::notifyException($ex); |
306
|
|
|
|
307
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|
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.