Completed
Push — main ( 2e4439...e4e587 )
by Emmanuel
01:20
created

AccountingData::sum_of_expense_this_year()   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
/**
5
 * Author: Emmanuel Paul Mnzava
6
 * Twitter: @epmnzava
7
 * Github:https://github.com/dbrax/income-expense
8
 * Email: [email protected]
9
 *
10
 */
11
12
namespace Epmnzava\IncomeExpense;
13
14
use Epmnzava\IncomeExpense\Models\Expense;
15
use Epmnzava\IncomeExpense\Models\ExpenseCategory;
16
use Epmnzava\IncomeExpense\Models\Income;
17
use Epmnzava\IncomeExpense\Models\IncomeCategory;
18
use Carbon\Carbon;
19
20
class AccountingData
21
{
22
23
24
25
    public function _construct(){
26
27
    }
28
29
     /**
30
      * Get sum of total income
31
      */
32
    public function total_sum_Income() : int
33
    {
34
        return Income::sum('amount');
35
    }
36
37
38
    /**
39
     * @param int $category
40
     * @return int
41
     * function gets sum of an income by a given category ..
42
     */
43
    public function sumOfIncomeByCategory(int $category) : int
44
    {
45
        return Income::where('incomecategory',$category)->sum('amount');
46
    }
47
48
49
    /**
50
     * @param int $category
51
     * @return int
52
     * function gets sum of an expense by a given category ..
53
     */
54
    public function sumOfExpenseByCategory(int $category) : int
55
    {
56
        return Expense::where('expense_category',$category)->sum('amount');
57
    }
58
59
    /**
60
     * @return int
61
     *
62
     * function gets the total income for  the current month
63
     */
64
    public function total_sum_of_income_this_month() : int
65
    {
66
        return Income::whereMonth('date', date('m'))->whereYear('date', date('Y'))->sum('amount');
67
    }
68
69
    /**
70
     * @return int
71
     * function that gets the total_sum_of_all_expense
72
     */
73
    public function total_sum_Expense() :int
74
    {
75
        return Expense::sum('amount');
76
    }
77
78
    /**
79
     * @return int
80
     * function that gets total expense for the current month
81
     */
82
    public function totalExpenseThisMonth() : int
83
    {
84
        return Expense::whereMonth('date', date('m'))->whereYear('date', date('Y'))->sum('amount');
85
    }
86
87
88
    /**
89
     * @return int
90
     * function that gets totalincome of the current year
91
     */
92
    public function totalIncomeThisYear() : int
93
    {
94
        return Income::whereYear('date', date('Y'))->sum('amount');
95
    }
96
97
    /**
98
     * @return int
99
     *
100
     *sum_of_total_income_last_year
101
     */
102
    public function sum_of_total_income_last_year() : int
103
    {
104
        $date = new Carbon();
105
106
107
        return Income::whereYear('date',$date->subYear()->format('Y'))->sum('amount');
108
    }
109
110
    /**
111
     * @return int
112
     *
113
     * sum_of_total_income_last_month
114
     */
115
116
    public function sum_of_total_income_last_month() : int
117
    {
118
        $date = new Carbon();
119
120
121
        return Income::whereYear('date',$date->subMonth()->format('m'))->sum('amount');
122
    }
123
124
125
    /**
126
     * @return int
127
     *
128
     * function that
129
     */
130
    public function sum_of_expense_this_year() : int
131
    {
132
        return Expense::whereYear('date', date('Y'))->sum('amount');
133
    }
134
}
135