Completed
Push — main ( caaa0e...fdd9d0 )
by Emmanuel
01:19
created

Stats::completed_orders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
use Epmnzava\BillMe\Models\Order;
14
use Epmnzava\BillMe\Models\Invoice;
15
use Epmnzava\BillMe\Models\OrderItem;
16
use Epmnzava\BillMe\Mail\Client\Invoices\InvoiceCreated;
17
use Epmnzava\BillMe\Mail\Client\OrderReceived;
18
use Epmnzava\BillMe\Mail\Merchant\NewOrder;
19
use Epmnzava\BillMe\Models\BillingPayment;
20
use Carbon\Carbon;
21
22
use Mail;
23
24
class Stats
25
{
26
27
    /**
28
     * Gets total count of orders 
29
     */
30
    public function total_orders()
31
    {
32
33
        return Order::count();
34
    }
35
36
    /**
37
     * Gets total count of cancelled orders 
38
     */
39
    public function total_cancelled_orders()
40
    {
41
        return Order::where('status', 'cancelled')->count();
42
    }
43
44
    /**
45
     * Gets total count of pending orders 
46
     */
47
    public function total_pending_orders()
48
    {
49
        return Order::where('status', 'pending')->count();
50
    }
51
52
    /**
53
     * Gets total sum of pending orders 
54
     */
55
    public function sum_of_pending_amount()
56
    {
57
58
        return Invoice::where('status', 'pending')->sum('amount');
59
    }
60
61
    public function total_completed_orders()
62
    {
63
        return Order::where('status', 'completed')->count();
64
    }
65
66
67
    public function paid_payments(){
68
69
        return BillingPayment::where('status', 'paid')->get();
70
71
    }
72
73
    /**
74
     * Gets total count of orders today
75
     */
76
77
    public function total_orders_today()
78
    {
79
        return Order::where('date', date('Y-m-d'))->count();
80
    }
81
82
83
    /**
84
     * Gets total count of orders on a particular day
85
     */
86
    public function total_orders_on_date($date)
87
    {
88
        return Order::where('date', $date)->count();
89
    }
90
91
    /**
92
     * Gets total count of orders on this month
93
     */
94
95
    public function total_orders_this_month()
96
    {
97
        return Order::whereMonth('date', '=', date('m'))->whereYear('date', '=', date('Y'))->count();
98
    }
99
100
101
    /**
102
     * Gets total count of orders on a particular month and year
103
     */
104
    public function total_orders_on_month($month, $year)
105
    {
106
        return Order::whereMonth('date', '=', $month)->whereYear('date', '=', $year)->count();
107
    }
108
109
110
    /**
111
     * Gets total count of orders on given year
112
     */
113
    public function total_orders_on_year($year)
114
    {
115
        return Order::whereYear('date', '=', $year)->count();
116
    }
117
118
119
    /**
120
     * Gets total count of invoices
121
     */
122
    public function total_invoices()
123
    {
124
        return Invoice::count();
125
    }
126
127
128
    /**
129
     * Gets total count of invoices today
130
     */
131
132
    public function total_invoices_today()
133
    {
134
        return Invoice::where('date', date('Y-m-d'))->count();
135
    }
136
137
138
    /**
139
     * Gets total count of pending orders 
140
     */
141
    public function total_pending_invoices()
142
    {
143
        return Invoice::where('status', 'pending')->count();
144
    }
145
146
    /**
147
     * Gets total sum of pending orders 
148
     */
149
    public function sum_of_pending_invoice_amount()
150
    {
151
152
        return Invoice::where('status', 'pending')->sum('amount');
153
    }
154
155
156
157
158
    /**
159
     * Gets total count of pending invoices by status 
160
     */
161
    public function total_invoice_count_by_status($status)
162
    {
163
        return Invoice::where('status', $status)->count();
164
    }
165
166
167
168
169
    /**
170
     * Gets total sum of pending invoices by status 
171
     */
172
    public function sum_of_given_invoice_status_amount($status)
173
    {
174
175
        return Invoice::where('status', $status)->sum('amount');
176
    }
177
178
179
180
    /**
181
     * Gets total count of completed invoices 
182
     */
183
    public function total_completed_invoices()
184
    {
185
        return Invoice::where('status', 'paid')->count();
186
    }
187
188
    /**
189
     * Gets total sum of completed invoices 
190
     */
191
    public function sum_of_completed_invoice_amount()
192
    {
193
194
        return Invoice::where('status', 'paid')->sum('amount');
195
    }
196
}
197