Completed
Push — development ( 50bb76...10afda )
by Ashutosh
08:23
created

ExtendedOrderController::getFromDate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace App\Http\Controllers\Order;
4
5
use Illuminate\Http\Request;
6
use App\Http\Controllers\Controller;
7
use App\Model\Order\Order;
8
use Bugsnag;
9
use Crypt;
10
11
class ExtendedOrderController extends Controller
12
{
13
        public function advanceSearch($order_no = '', $product_id = '', $expiry = '', $from = '', $till = '', $domain = '')
14
    {
15
        $join = Order::leftJoin('subscriptions', 'orders.id', '=', 'subscriptions.order_id');
16
        if ($order_no) {
17
            $join = $join->where('number', $order_no);
18
        }
19
        if ($product_id) {
20
            $join = $join->where('product', $product_id);
21
        }
22
        if ($expiry) {
23
            $join = $join->where('ends_at', 'LIKE', '%'.$expiry.'%');
24
        }
25
        if ($from) {
26
           
27
            $fromdate = date_create($from);
28
            $from = date_format($fromdate, 'Y-m-d H:m:i');
29
            $tills = date('Y-m-d H:m:i');
30
             $tillDate = $this->getTillDate($from,$till,$tills);
31
            $join = $join->whereBetween('orders.created_at', [$from, $tillDate]);
32
        }
33
        if ($till) {
34
            $tilldate = date_create($till);
35
            $till = date_format($tilldate, 'Y-m-d H:m:i');
36
            $froms = Order::first()->created_at;
37
            $fromDate = $this->getFromDate($from,$froms);
38
            $join = $join->whereBetween('orders.created_at', [$fromDate, $till]);
39
        }
40
        if ($domain) {
41
            if (str_finish($domain, '/')) {
42
                $domain = substr_replace($domain, '', -1, 0);
43
            }
44
            $join = $join->where('domain', 'LIKE', '%'.$domain.'%');
45
        }
46
47
        $join = $join->select('orders.id', 'orders.created_at', 'client', 'price_override', 'order_status', 'number', 'serial_key');
48
49
        return $join;
50
    }
51
52
    public function getTillDate($from,$till,$tills)
53
    {
54
         if ($till) 
55
         {
56
            $todate = date_create($till);
57
            $tills = date_format($todate, 'Y-m-d H:m:i');
58
         }
59
         return $tills;
60
    }
61
62
    public function getFromDate($from,$froms)
63
    {
64
     if ($from) {
65
            $fromdate = date_create($from);
66
            $froms = date_format($fromdate, 'Y-m-d H:m:i');
67
        }
68
        return $froms;
69
    }
70
71
        /**
72
     * Create orders.
73
     *
74
     * @param Request $request
75
     *
76
     * @return type
77
     */
78
    public function orderExecute(Request $request)
79
    {
80
        try {
81
            $invoiceid = $request->input('invoiceid');
82
            $execute = $this->executeOrder($invoiceid);
83
            if ($execute == 'success') {
84
                return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
85
            } else {
86
                return redirect()->back()->with('fails', \Lang::get('message.not-saved-successfully'));
87
            }
88
        } catch (\Exception $ex) {
89
            Bugsnag::notifyException($ex);
90
91
            return redirect()->back()->with('fails', $ex->getMessage());
92
        }
93
    }
94
95
     /**
96
     * generating serial key if product type is downloadable.
97
     *
98
     * @param type $product_type
99
     *
100
     * @throws \Exception
101
     *
102
     * @return type
103
     */
104
    public function generateSerialKey($product_type)
105
    {
106
        try {
107
            if ($product_type == 2) {
108
                $str = str_random(16);
109
                $str = strtoupper($str);
110
                $str = Crypt::encrypt($str);
111
                 return $str;
112
            }
113
        } catch (\Exception $ex) {
114
            Bugsnag::notifyException($ex);
115
116
            throw new \Exception($ex->getMessage());
117
        }
118
    }
119
120
    public function generateNumber()
121
    {
122
        try {
123
            return rand('10000000', '99999999');
124
        } catch (\Exception $ex) {
125
            throw new \Exception($ex->getMessage());
126
        }
127
    }
128
129
    public function domainChange(Request $request)
130
    {
131
        $domain = $request->input('domain');
132
        $id = $request->input('id');
133
        $order = Order::find($id);
134
        $order->domain = $domain;
135
        $order->save();
136
    }
137
138
139
140
}
141