Completed
Push — main ( e0ab63...caaa0e )
by Emmanuel
01:08
created

Stats::paid_payments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
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
  public function completed_orders()
67
    {
68
        return Order::where('status', 'completed')->get();
69
    }
70
71
    public function paid_payments(){
72
73
        return BillingPayment::where('status', 'paid')->get();
74
75
    }
76
77
    /**
78
     * Gets total count of orders today
79
     */
80
81
    public function total_orders_today()
82
    {
83
        return Order::where('date', date('Y-m-d'))->count();
84
    }
85
86
87
    /**
88
     * Gets total count of orders on a particular day
89
     */
90
    public function total_orders_on_date($date)
91
    {
92
        return Order::where('date', $date)->count();
93
    }
94
95
    /**
96
     * Gets total count of orders on this month
97
     */
98
99
    public function total_orders_this_month()
100
    {
101
        return Order::whereMonth('date', '=', date('m'))->whereYear('date', '=', date('Y'))->count();
102
    }
103
104
105
    /**
106
     * Gets total count of orders on a particular month and year
107
     */
108
    public function total_orders_on_month($month, $year)
109
    {
110
        return Order::whereMonth('date', '=', $month)->whereYear('date', '=', $year)->count();
111
    }
112
113
114
    /**
115
     * Gets total count of orders on given year
116
     */
117
    public function total_orders_on_year($year)
118
    {
119
        return Order::whereYear('date', '=', $year)->count();
120
    }
121
122
123
    /**
124
     * Gets total count of invoices
125
     */
126
    public function total_invoices()
127
    {
128
        return Invoice::count();
129
    }
130
131
132
    /**
133
     * Gets total count of invoices today
134
     */
135
136
    public function total_invoices_today()
137
    {
138
        return Invoice::where('date', date('Y-m-d'))->count();
139
    }
140
141
142
    /**
143
     * Gets total count of pending orders 
144
     */
145
    public function total_pending_invoices()
146
    {
147
        return Invoice::where('status', 'pending')->count();
148
    }
149
150
    /**
151
     * Gets total sum of pending orders 
152
     */
153
    public function sum_of_pending_invoice_amount()
154
    {
155
156
        return Invoice::where('status', 'pending')->sum('amount');
157
    }
158
159
160
161
162
    /**
163
     * Gets total count of pending invoices by status 
164
     */
165
    public function total_invoice_count_by_status($status)
166
    {
167
        return Invoice::where('status', $status)->count();
168
    }
169
170
171
172
173
    /**
174
     * Gets total sum of pending invoices by status 
175
     */
176
    public function sum_of_given_invoice_status_amount($status)
177
    {
178
179
        return Invoice::where('status', $status)->sum('amount');
180
    }
181
182
183
184
    /**
185
     * Gets total count of completed invoices 
186
     */
187
    public function total_completed_invoices()
188
    {
189
        return Invoice::where('status', 'paid')->count();
190
    }
191
192
    /**
193
     * Gets total sum of completed invoices 
194
     */
195
    public function sum_of_completed_invoice_amount()
196
    {
197
198
        return Invoice::where('status', 'paid')->sum('amount');
199
    }
200
}
201