Completed
Push — development ( 1edf8d...636245 )
by Ashutosh
10:23
created

ProductController::create()   A

Complexity

Conditions 3
Paths 19

Size

Total Lines 35
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 35
rs 9.504
c 0
b 0
f 0
cc 3
nc 19
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Product;
4
5
// use Illuminate\Http\Request;
6
    use App\Http\Controllers\License\LicenseController;
7
    use App\Http\Controllers\AutoUpdate\AutoUpdateController;
8
    use App\Http\Controllers\License\LicensePermissionsController;
9
    use App\Model\Common\Setting;
10
    use App\Model\Common\StatusSetting;
11
    use App\Model\License\LicenseType;
12
    use App\Model\Order\Order;
13
    use App\Model\Payment\Currency;
14
    use App\Model\Payment\Period;
15
    use App\Model\Payment\Plan;
16
    use App\Model\Payment\Tax;
17
    use App\Model\Payment\TaxClass;
18
    use App\Model\Payment\TaxProductRelation;
19
    use App\Model\Product\Price;
20
    use App\Model\Product\Product;
21
    use App\Model\Product\ProductGroup;
22
    use App\Model\Product\ProductUpload;
23
    use App\Model\Product\Subscription;
24
    use App\Model\Product\Type;
25
    use App\Traits\Upload\ChunkUpload;
26
    use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
27
    use Illuminate\Http\Request;
28
    use Illuminate\Support\Facades\Input;
29
    use Spatie\Activitylog\Models\Activity;
30
31
    // use Input;
32
33
class ProductController extends BaseProductController
34
{
35
    use ChunkUpload;
36
37
    public $product;
38
    public $price;
39
    public $type;
40
    public $subscription;
41
    public $currency;
42
    public $group;
43
    public $plan;
44
    public $tax;
45
    public $tax_relation;
46
    public $tax_class;
47
    public $product_upload;
48
49
    public function __construct()
50
    {
51
        $this->middleware('auth');
52
        $this->middleware('admin', ['except' => ['adminDownload', 'userDownload']]);
53
54
        $product = new Product();
55
        $this->product = $product;
56
57
        $price = new Price();
58
        $this->price = $price;
59
60
        $type = new LicenseType();
61
        $this->type = $type;
62
63
        $subscription = new Subscription();
64
        $this->subscription = $subscription;
65
66
        $currency = new Currency();
67
        $this->currency = $currency;
68
69
        $group = new ProductGroup();
70
        $this->group = $group;
71
72
        $plan = new Plan();
73
        $this->plan = $plan;
74
75
        $tax = new Tax();
76
        $this->tax = $tax;
77
78
        $period = new Period();
79
        $this->period = $period;
80
81
        $tax_relation = new TaxProductRelation();
82
        $this->tax_relation = $tax_relation;
83
84
        $tax_class = new TaxClass();
85
        $this->tax_class = $tax_class;
86
87
        $product_upload = new ProductUpload();
88
        $this->product_upload = $product_upload;
89
90
        $license = new LicenseController();
91
        $this->licensing = $license;
92
    }
93
94
    /**
95
     * Display a listing of the resource.
96
     *
97
     * @return \Response
98
     */
99
    public function index()
100
    {
101
        try {
102
            return view('themes.default1.product.product.index');
103
        } catch (\Exception $e) {
104
            Bugsnag::notifyException($e);
105
106
            return redirect('/')->with('fails', $e->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('/')->wi...ils', $e->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
107
        }
108
    }
109
110
    /**
111
     * Display a listing of the resource.
112
     *
113
     * @return \Response
114
     */
115
    public function getProducts()
116
    {
117
        try {
118
            $new_product = Product::select('id', 'name', 'type', 'image', 'group', 'image')->get();
119
120
            return\ DataTables::of($new_product)
121
122
                            ->addColumn('checkbox', function ($model) {
123
                                return "<input type='checkbox' class='product_checkbox' 
124
                                value=".$model->id.' name=select[] id=check>';
125
                            })
126
                            ->addColumn('name', function ($model) {
127
                                return ucfirst($model->name);
128
                            })
129
                              ->addColumn('image', function ($model) {
130
                                  // return $model->image;
131
                                  return "<img src= '$model->image' + height=\"80\"/>";
132
                              })
133
                            ->addColumn('type', function ($model) {
134
                                if ($this->type->where('id', $model->type)->first()) {
135
                                    return $this->type->where('id', $model->type)->first()->name;
136
                                } else {
137
                                    return 'Not available';
138
                                }
139
                            })
140
                            ->addColumn('group', function ($model) {
141
                                if ($this->group->where('id', $model->group)->first()) {
142
                                    return $this->group->where('id', $model->group)->first()->name;
143
                                } else {
144
                                    return 'Not available';
145
                                }
146
                            })
147
148
                            ->addColumn('Action', function ($model) {
149
                                $permissions = LicensePermissionsController::getPermissionsForProduct($model->id);
150
                                $url = '';
151
                                if ($permissions['downloadPermission'] == 1) {
152
                                    $url = '<a href='.url('product/download/'.$model->id).
153
                                    " class='btn btn-sm btn-primary btn-xs'><i class='fa fa-download' 
154
                                    style='color:white;'> </i>&nbsp;&nbsp;Download</a>";
155
                                }
156
157
                                return '<p><a href='.url('products/'.$model->id.'/edit').
158
                                " class='btn btn-sm btn-primary btn-xs'><i class='fa fa-edit'
159
                                 style='color:white;'> </i>&nbsp;&nbsp;Edit</a>&nbsp;$url</p>";
160
                            })
161
162
                            ->rawColumns(['checkbox', 'name', 'image', 'type', 'group', 'Action'])
163
                            ->make(true);
164
        } catch (\Exception $e) {
165
            Bugsnag::notifyException($e);
166
167
            return redirect()->back()->with('fails', $e->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ils', $e->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
168
        }
169
    }
170
171
    // Save file Info in Modal popup
172
    public function save(Request $request)
173
    {
174
        $this->validate(
175
            $request,
176
            [
177
       'producttitle'  => 'required',
178
        'version'      => 'required',
179
       'filename'      => 'required',
180
       ],
181
       ['filename.required' => 'Please Uplaod A file',
182
        ]
183
        );
184
185
        try {
186
            $product_id = Product::where('name', $request->input('productname'))->select('id')->first();
187
188
            $this->product_upload->product_id = $product_id->id;
189
            $this->product_upload->title = $request->input('producttitle');
190
            $this->product_upload->description = $request->input('description');
191
            $this->product_upload->version = $request->input('version');
192
            $this->product_upload->file = $request->input('filename');
193
            $this->product_upload->save();
194
            $this->product->where('id', $product_id->id)->update(['version'=>$request->input('version')]);
195
            $autoUpdateStatus = StatusSetting::pluck('update_settings')->first();
196
            if ($autoUpdateStatus == 1) { //If License Setting Status is on,Add Product to the License Manager
197
                $updateClassObj = new \App\Http\Controllers\AutoUpdate\AutoUpdateController();
198
                $addProductToAutoUpdate = $updateClassObj->addNewVersion($product_id->id, $request->input('version'), $request->input('filename'), '1');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $addProductToAutoUpdate is correct as $updateClassObj->addNewV...input('filename'), '1') targeting App\Http\Controllers\Aut...roller::addNewVersion() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 152 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...
199
            }
200
            $response = ['success'=>'true', 'message'=>'Product Uploaded Successfully'];
201
202
            return $response;
203
        } catch (\Exception $e) {
204
            app('log')->error($e->getMessage());
205
            Bugsnag::notifyException($e);
206
            $message = [$e->getMessage()];
207
            $response = ['success'=>'false', 'message'=>$message];
208
209
            return response()->json(compact('response'), 500);
210
        }
211
    }
212
213
    /**
214
     * Show the form for creating a new resource.
215
     *
216
     * @return \Response
217
     */
218
    public function create()
219
    {
220
        try {
221
            /*
222
             * server url
223
             */
224
            $url = url('/');
225
            $id = $this->product->orderBy('id', 'desc')->first();
226
            $i = $id ? $id->id + 1 : 1;
227
            $cartUrl = $url.'/pricing?id='.$i;
228
            $type = $this->type->pluck('name', 'id')->toArray();
229
            $subscription = $this->plan->pluck('name', 'id')->toArray();
230
            $currency = $this->currency->where('status', 1)->pluck('name', 'code')->toArray();
231
            $group = $this->group->pluck('name', 'id')->toArray();
232
            $products = $this->product->pluck('name', 'id')->toArray();
233
            $periods = $this->period->pluck('name', 'days')->toArray();
234
            $taxes = $this->tax_class->pluck('name', 'id')->toArray();
235
236
            return view(
237
                'themes.default1.product.product.create',
238
                compact(
239
                    'subscription',
240
                    'type',
241
                    'periods',
242
                    'currency',
243
                    'group',
244
                    'cartUrl',
245
                    'products',
246
                    'taxes'
247
                )
248
            );
249
        } catch (\Exception $e) {
250
            Bugsnag::notifyException($e);
251
252
            return redirect()->back()->with('fails', $e->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ils', $e->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
253
        }
254
    }
255
256
    /**
257
     * Store a newly created resource in storage.
258
     *
259
     * @return \Response
260
     */
261
    public function store(Request $request)
262
    {
263
        $input = $request->all();
264
        $v = \Validator::make($input, [
265
                        'name'       => 'required|unique:products,name',
266
                        'type'       => 'required',
267
                        'description'=> 'required',
268
                        'category'   => 'required',
269
                        'image'      => 'sometimes | mimes:jpeg,jpg,png,gif | max:1000',
270
                        'product_sku'=> 'required|unique:products,product_sku',
271
                        'group'      => 'required',
272
                        'show_agent' => 'required',
273
                        // 'version' => 'required',
274
            ], [
275
            'show_agent.required' => 'Select you Cart Page Preference',
276
            ]);
277
278
        if ($v->fails()) {
279
            //     $currency = $input['currency'];
280
281
            return redirect()->back()
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back()->withErrors($v) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
282
                        ->withErrors($v);
283
        }
284
285
        try {
286
            $licenseStatus = StatusSetting::pluck('license_status')->first();
287
            if ($licenseStatus == 1) { //If License Setting Status is on,Add Product to the License Manager
288
                $addProductToLicensing = $this->licensing->addNewProduct($input['name'], $input['product_sku']);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $addProductToLicensing is correct as $this->licensing->addNew... $input['product_sku']) targeting App\Http\Controllers\Lic...roller::addNewProduct() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
289
            }
290
            $updateCont = new \App\Http\Controllers\AutoUpdate\AutoUpdateController();
291
            $addProductToLicensing = $updateCont->addNewProductToAUS($input['name'], $input['product_sku']);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $addProductToLicensing is correct as $updateCont->addNewProdu... $input['product_sku']) targeting App\Http\Controllers\Aut...r::addNewProductToAUS() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
292
            if ($request->hasFile('image')) {
293
                $image = $request->file('image')->getClientOriginalName();
294
                $imagedestinationPath = 'common/images';
295
                $request->file('image')->move($imagedestinationPath, $image);
296
                $this->product->image = $image;
297
            }
298
            $can_modify_agent = $request->input('can_modify_agent');
299
            $can_modify_quantity = $request->input('can_modify_quantity');
300
            $product = $this->product;
301
            $product->fill($request->except('image', 'file', 'cartquantity', 'can_modify_agent', 'can_modify_quantity'))->save();
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 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...
302
            $this->saveCartValues($input, $can_modify_agent, $can_modify_quantity);
303
            $product_id = $product->id;
304
            $subscription = $request->input('subscription');
305
            $taxes = $request->input('tax');
306
            if ($taxes) {
307
                foreach ($taxes as $key => $value) {
308
                    $newtax = new TaxProductRelation();
309
                    $newtax->product_id = $product_id;
310
                    $newtax->tax_class_id = $value;
311
                    $newtax->save();
312
                }
313
            }
314
315
            return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...e.saved-successfully')) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
316
        } catch (\Exception $e) {
317
            app('log')->error($e->getMessage());
318
            Bugsnag::notifyException($e);
319
320
            return redirect()->back()->with('fails', $e->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ils', $e->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
321
        }
322
    }
323
324
    /**
325
     * Show the form for editing the specified resource.
326
     *
327
     * @param int $id
328
     *
329
     * @return \Response
330
     */
331
    public function edit($id)
332
    {
333
        try {
334
            $type = $this->type->pluck('name', 'id')->toArray();
335
336
            $subscription = $this->plan->pluck('name', 'id')->toArray();
337
            $currency = $this->currency->pluck('name', 'code')->toArray();
338
            $group = $this->group->pluck('name', 'id')->toArray();
339
            $products = $this->product->pluck('name', 'id')->toArray();
340
            $checkowner = Product::where('id', $id)->value('github_owner');
341
            $periods = $this->period->pluck('name', 'days')->toArray();
342
            // $url = $this->GetMyUrl();
343
            $url = url('/');
344
            $cartUrl = $url.'/cart?id='.$id;
345
            $product = $this->product->where('id', $id)->first();
346
            $selectedGroup = ProductGroup:: where('id', $product->group)->pluck('name')->toArray();
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after double colon; 1 found

This check looks for references to static members where there are spaces between the name of the type and the actual member.

An example:

Certificate:: TRIPLEDES_CBC

will actually work, but is not very readable.

Loading history...
347
            $taxes = $this->tax_class->pluck('name', 'id')->toArray();
348
            $selectedCategory = \App\Model\Product\ProductCategory::
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after double colon; 1 found

This check looks for references to static members where there are spaces between the name of the type and the actual member.

An example:

Certificate:: TRIPLEDES_CBC

will actually work, but is not very readable.

Loading history...
349
                where('category_name', $product->category)->pluck('category_name')->toArray();
350
            $taxes = $this->tax_class->pluck('name', 'id')->toArray();
351
            // dd($taxes);
352
            $saved_taxes = $this->tax_relation->where('product_id', $id)->get();
353
            $savedTaxes = $this->tax_relation->where('product_id', $id)->pluck('tax_class_id')->toArray();
354
            $showagent = $product->show_agent;
355
            $showProductQuantity = $product->show_product_quantity;
356
            $canModifyAgent = $product->can_modify_agent;
357
            $canModifyQuantity = $product->can_modify_quantity;
358
            $githubStatus = StatusSetting::pluck('github_status')->first();
359
360
            return view(
361
                'themes.default1.product.product.edit',
362
                compact(
363
                    'product',
364
                    'periods',
365
                    'type',
366
                    'subscription',
367
                    'currency',
368
                    'group',
369
                    'price',
370
                    'cartUrl',
371
                    'products',
372
                    'regular',
373
                    'sales',
374
                    'taxes',
375
                    'saved_taxes',
376
                    'savedTaxes',
377
                    'selectedCategory',
378
                    'selectedGroup',
379
                    'showagent',
380
                    'showProductQuantity',
381
                    'canModifyAgent',
382
                    'canModifyQuantity',
383
                    'checkowner',
384
                    'githubStatus'
385
                )
386
            );
387
        } catch (\Exception $e) {
388
            Bugsnag::notifyException($e);
389
390
            return redirect()->back()->with('fails', $e->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ils', $e->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
391
        }
392
    }
393
394
    /**
395
     * Update the specified resource in storage.
396
     *
397
     * @param int $id
398
     *
399
     * @return \Response
400
     */
401
    public function update($id, Request $request)
402
    {
403
        $input = $request->all();
404
        $v = \Validator::make($input, [
405
                        'name'       => 'required',
406
                        'type'       => 'required',
407
                        'description'=> 'required',
408
                        'image'      => 'sometimes | mimes:jpeg,jpg,png,gif | max:1000',
409
                        'product_sku'=> 'required',
410
                        'group'      => 'required',
411
        ]);
412
413
        if ($v->fails()) {
414
            return redirect()->back()->with('errors', $v->errors());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...'errors', $v->errors()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
415
        }
416
417
        try {
418
            $licenseStatus = StatusSetting::pluck('license_status')->first();
419
            if ($licenseStatus == 1) {
420
                $addProductInLicensing = $this->licensing->editProduct($input['name'], $input['product_sku']);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $addProductInLicensing is correct as $this->licensing->editPr... $input['product_sku']) targeting App\Http\Controllers\Lic...ntroller::editProduct() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
421
            } 
422
            $product = $this->product->where('id', $id)->first();
423
            if ($request->hasFile('image')) {
424
                $image = $request->file('image')->getClientOriginalName();
425
                $imagedestinationPath = 'common/images';
426
                $request->file('image')->move($imagedestinationPath, $image);
427
                $product->image = $image;
428
            }
429
            if ($request->hasFile('file')) {
430
                $file = $request->file('file')->getClientOriginalName();
431
                $filedestinationPath = storage_path().'/products';
432
                $request->file('file')->move($filedestinationPath, $file);
433
                $product->file = $file;
434
            }
435
            $product->fill($request->except('image', 'file', 'cartquantity', 'product_multiple_qty', 'agent_multiple_qty'))->save();
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 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...
436
            $this->saveCartDetailsWhileUpdating($input, $request, $product);
437
438
            //$this->saveCartValues($input,$can_modify_agent,$can_modify_quantity);
439
            $this->updateVersionFromGithub($product->id);
440
441
            $product_id = $product->id;
442
            $subscription = $request->input('subscription');
443
            $cost = $request->input('price');
444
            $sales_price = $request->input('sales_price');
445
            $currencies = $request->input('currency');
446
447
            //add tax class to tax_product_relation table
448
            $taxes = $request->input('tax');
449
            $newTax = $this->saveTax($taxes, $product_id);
450
451
            return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...updated-successfully')) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
452
        } catch (\Exception $e) {
453
            Bugsnag::notifyException($e);
454
455
            return redirect()->back()->with('fails', $e->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ils', $e->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Response.
Loading history...
456
        }
457
    }
458
459
    /**
460
     * Remove the specified resource from storage.
461
     *
462
     * @param int $id
463
     *
464
     * @return \Response
465
     */
466
    public function destroy(Request $request)
467
    {
468
        try {
469
            $ids = $request->input('select');
470
            if (!empty($ids)) {
471
                foreach ($ids as $id) {
472
                    $product = $this->product->where('id', $id)->first();
473
                    if ($product) {
474
                        $licenseStatus = StatusSetting::pluck('license_status')->first();
475
                        if($licenseStatus ==1) {
476
                            $this->licensing->deleteProductFromAPL($product);
477
                        }
478
                        $product->delete();
479
                    } else {
480
                        echo "<div class='alert alert-danger alert-dismissable'>
481
                    <i class='fa fa-ban'></i>
482
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
483
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
484
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
485
                        './* @scrutinizer ignore-type */\Lang::get('message.no-record').'
486
                </div>';
487
                        //echo \Lang::get('message.no-record') . '  [id=>' . $id . ']';
488
                    }
489
                    echo "<div class='alert alert-success alert-dismissable'>
490
                    <i class='fa fa-ban'></i>
491
                    <b>"./* @scrutinizer ignore-type */
492
                        \Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */ \Lang::get('message.success').'
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...
493
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
494
                        './* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').'
495
                </div>';
496
                }
497
            } else {
498
                echo "<div class='alert alert-danger alert-dismissable'>
499
                    <i class='fa fa-ban'></i>
500
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
501
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
502
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
503
                        './* @scrutinizer ignore-type */\Lang::get('message.select-a-row').'
504
                </div>';
505
                //echo \Lang::get('message.select-a-row');
506
            }
507
            $lastActivity = Activity::all()->last();
508
        } catch (\Exception $e) {
509
            echo "<div class='alert alert-danger alert-dismissable'>
510
                    <i class='fa fa-ban'></i>
511
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
512
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
513
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
514
                        '.$e->getMessage().'
515
                </div>';
516
        }
517
    }
518
519
    /**
520
     * Remove the specified resource from storage.
521
     *
522
     * @param int $id
523
     *
524
     * @return \Response
525
     */
526
    public function fileDestroy(Request $request)
527
    {
528
        try {
529
            $ids = $request->input('select');
530
            $storagePath = Setting::find(1)->value('file_storage');
531
            if (!empty($ids)) {
532
                foreach ($ids as $id) {
533
                    $product = $this->product_upload->where('id', $id)->first();
534
                    if ($product) {
535
                        $file = $product->file;
536
                        unlink($storagePath.'/'.$file);
537
                        $product->delete();
538
                    } else {
539
                        echo "<div class='alert alert-danger alert-dismissable'>
540
                    <i class='fa fa-ban'></i>
541
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
542
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
543
                        '.\Lang::get('message.no-record').'
544
                </div>';
545
                        //echo \Lang::get('message.no-record') . '  [id=>' . $id . ']';
546
                    }
547
                    echo "<div class='alert alert-success alert-dismissable'>
548
                    <i class='fa fa-ban'></i>
549
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.success').'
550
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
551
                        '.\Lang::get('message.deleted-successfully').'
552
                </div>';
553
                }
554
            } else {
555
                echo "<div class='alert alert-danger alert-dismissable'>
556
                    <i class='fa fa-ban'></i>
557
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
558
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
559
                        '.\Lang::get('message.select-a-row').'
560
                </div>';
561
                //echo \Lang::get('message.select-a-row');
562
            }
563
        } catch (\Exception $e) {
564
            echo "<div class='alert alert-danger alert-dismissable'>
565
                    <i class='fa fa-ban'></i>
566
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
567
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
568
                        '.$e->getMessage().'
569
                </div>';
570
        }
571
    }
572
573
    /*
574
    *  Download Files from Filesystem/Github
575
    */
576
    public function downloadProduct($uploadid, $id, $invoice_id, $version_id = '')
577
    {
578
        try {
579
            $product = $this->product->findOrFail($uploadid);
580
            $type = $product->type;
581
            $owner = $product->github_owner;
582
            $repository = $product->github_repository;
583
            $file = $this->product_upload
584
                ->where('product_id', '=', $uploadid)
585
                ->where('id', $version_id)->select('file')->first();
586
            $order = Order::where('invoice_id', '=', $invoice_id)->first();
587
            $order_id = $order->id;
588
            $relese = $this->getRelease($owner, $repository, $order_id, $file);
589
590
            return $relese;
591
        } catch (\Exception $e) {
592
            Bugsnag::notifyException($e);
593
594
            return redirect()->back()->with('fails', $e->getMessage());
595
        }
596
    }
597
598
    public function getSubscriptionCheckScript()
599
    {
600
        $response = "<script>
601
        function getPrice(val) {
602
            var user = document.getElementsByName('user')[0].value;
603
            var plan = '';
604
            if ($('#plan').length > 0) {
605
                var plan = document.getElementsByName('plan')[0].value;
606
            }
607
            //var plan = document.getElementsByName('plan')[0].value;
608
            //alert(user);
609
610
            $.ajax({
611
                type: 'POST',
612
                url: ".url('get-price').",
613
                data: {'product': val, 'user': user,'plan':plan},
614
                //data: 'product=' + val+'user='+user,
615
                success: function (data) {
616
                    var price = data['price'];
617
                    var field = data['field'];
618
                    $('#price').val(price);
619
                    $('#fields').append(field);
620
                }
621
            });
622
        }
623
624
    </script>";
625
    }
626
}
627