1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Author: Emmanuel Paul Mnzava |
5
|
|
|
* Twitter: @epmnzava |
6
|
|
|
* Github: https://github.com/dbrax/bill-me |
7
|
|
|
* Email: [email protected] |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Epmnzava\BillMe; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use Epmnzava\BillMe\Models\BillingPayment; |
15
|
|
|
use Epmnzava\BillMe\Models\Order; |
16
|
|
|
use Epmnzava\BillMe\Models\Invoice; |
17
|
|
|
use Epmnzava\BillMe\Models\OrderItem; |
18
|
|
|
use Epmnzava\BillMe\Mail\Client\Invoices\InvoiceCreated; |
19
|
|
|
use Epmnzava\BillMe\Mail\Client\OrderReceived; |
20
|
|
|
use Epmnzava\BillMe\Mail\Merchant\NewOrder; |
21
|
|
|
|
22
|
|
|
use Mail; |
23
|
|
|
|
24
|
|
|
class Queries extends Stats |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
public function orders() |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
return Order::all(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function orders_orderby($orderby) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function orders_today() |
41
|
|
|
{ |
42
|
|
|
return Order::where('date', date('Y-m-d'))->get(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function get_orders_with_status($status) |
47
|
|
|
{ |
48
|
|
|
return Order::where('status', $status)->get(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function pending_orders() |
52
|
|
|
{ |
53
|
|
|
return Order::where('status', "pending")->get(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function cancelled_orders() |
57
|
|
|
{ |
58
|
|
|
return Order::where('status', "cancelled")->get(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function completed_orders() |
62
|
|
|
{ |
63
|
|
|
return Order::where('status', "complete")->get(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getOrderById($orderid) |
67
|
|
|
{ |
68
|
|
|
return Order::find($orderid); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getOrdersOnDate($date) |
72
|
|
|
{ |
73
|
|
|
return Order::where('date', $date)->get(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function getOrdersOnDateRange($startdate, $enddate) |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** Function to get an invoice */ |
83
|
|
|
public function getInvoiceById($invoiceid) |
84
|
|
|
{ |
85
|
|
|
return Invoice::find($invoiceid); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* |
91
|
|
|
* User Queries |
92
|
|
|
*/ |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** Function to get given user orders */ |
96
|
|
|
public function getUserOrders($userid) |
97
|
|
|
{ |
98
|
|
|
return Order::where('userid', $userid)->get(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** Function to get given user orders by status */ |
103
|
|
|
public function getUserOrdersByStatus($userid, $status) |
104
|
|
|
{ |
105
|
|
|
return Order::where('userid', $userid)->where('status', $status)->get(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** Function to get given user invoices */ |
110
|
|
|
public function getUserInvoices($userid) |
111
|
|
|
{ |
112
|
|
|
return Invoice::where('userid', $userid)->get(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** Function that returns total number of user invoices */ |
117
|
|
|
public function totalUserInvoices($userid) : int |
118
|
|
|
{ |
119
|
|
|
return Invoice::where('userid', $userid)->count(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
|
124
|
|
|
|
125
|
|
|
/** Function to get given user invoices by status */ |
126
|
|
|
public function getUserInvoiceByStatus($userid, $status) |
127
|
|
|
{ |
128
|
|
|
return Invoice::where('userid', $userid)->where('status', $status)->get(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
|
133
|
|
|
|
134
|
|
|
/** Function to get given user invoices by status */ |
135
|
|
|
public function sumUserInvoiceByStatus($userid, $status) |
136
|
|
|
{ |
137
|
|
|
return Invoice::where('userid', $userid)->where('status', $status)->sum('amount'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
|
142
|
|
|
|
143
|
|
|
/** Function to get given user invoices by status */ |
144
|
|
|
public function totalUserInvoiceByStatus($userid, $status) |
145
|
|
|
{ |
146
|
|
|
return Invoice::where('userid', $userid)->where('status', $status)->count(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** Function that gets full billing history */ |
150
|
|
|
|
151
|
|
|
public function getAllBillingHistory() |
152
|
|
|
{ |
153
|
|
|
|
154
|
|
|
return BillingPayment::all(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
/** Function that gets full user billing history*/ |
159
|
|
|
|
160
|
|
|
public function getUserBillingHistory($userid) |
161
|
|
|
{ |
162
|
|
|
|
163
|
|
|
return BillingPayment::where('userid', $userid)->get(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
|
167
|
|
|
|
168
|
|
|
|
169
|
|
|
public function getUserBillingHistoryByStartDate($userid,$start_date) |
170
|
|
|
{ |
171
|
|
|
|
172
|
|
|
return BillingPayment::where('userid', $userid)->where('date',$start_date)->get(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
/** Function to get payment history of a given user for a given period */ |
177
|
|
|
|
178
|
|
|
public function getUserBillingHistoryBetweenDates($userid,$start_date,$enddate) |
179
|
|
|
{ |
180
|
|
|
|
181
|
|
|
return BillingPayment::where('userid', $userid)->whereBetween('date',[$start_date,$enddate])->get(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Returns the model instance to be updated |
187
|
|
|
*/ |
188
|
|
|
public function updateBillingHistory($invoiceid) : BillingPayment |
189
|
|
|
{ |
190
|
|
|
return BillingPayment::find(BillingPayment::where('invoiceid',$invoiceid)->first()->id); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function getUserBillingHistoryByStatus($userid, $status) |
194
|
|
|
{ |
195
|
|
|
|
196
|
|
|
return BillingPayment::where('userid', $userid)->where('status', $status)->get(); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.