Completed
Push — main ( f8f0ae...cd74f0 )
by Emmanuel
01:19
created

AccountingData::sumOfExpenseByCategory()   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 1
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
19
class AccountingData
20
{
21
22
     /**
23
      * Get sum of total income
24
      */
25
    public function totalIncome() : int
26
    {
27
        return Income::sum('amount');
28
    }
29
30
31
    /**
32
     * @param int $category
33
     * @return int
34
     * function gets sum of an income by a given category ..
35
     */
36
    public function sumOfIncomeByCategory(int $category) : int
37
    {
38
        return Income::where('incomecategory',$category)->sum('amount');
39
    }
40
41
42
    /**
43
     * @param int $category
44
     * @return int
45
     * function gets sum of an expense by a given category ..
46
     */
47
    public function sumOfExpenseByCategory(int $category) : int
48
    {
49
        return Expense::where('expense_category',$category)->sum('amount');
50
    }
51
52
    /**
53
     * @return int
54
     *
55
     * function gets the total income for  the current month
56
     */
57
    public function totalIncomeThisMonth() : int
58
    {
59
        return Income::whereMonth('date', date('m'))->whereYear('date', date('Y'))->sum('amount');
60
    }
61
62
    public function totalExpense()
63
    {
64
        return Expense::sum('amount');
65
    }
66
67
    public function totalExpenseThisMonth()
68
    {
69
        return Expense::whereMonth('date', date('m'))->whereYear('date', date('Y'))->sum('amount');
70
    }
71
72
    public function totalIncomeThisYear()
73
    {
74
        return Income::whereYear('date', date('Y'))->sum('amount');
75
    }
76
    public function totalExpenseThisYear()
77
    {
78
        return Expense::whereYear('date', date('Y'))->sum('amount');
79
    }
80
}
81