<?php
namespace App\Services;

use App\Expense;
use App\Income;
use Illuminate\Support\Facades\DB;

class SummaryService{
 

    public static function expenses($start_date=null,$end_date=null){
        if($start_date&&$end_date){
            return Expense::whereDate('expense_date','>=',$start_date)->whereDate('expense_date','<=',$end_date)->sum('amount');
        }
        return Expense::sum('amount');
    }

    public static function incomes($start_date=null,$end_date=null){
        if($start_date&&$end_date){
            return Income::whereDate('income_date','>=',$start_date)->whereDate('income_date','<=',$end_date)->sum('amount');
        }
        return Income::sum('amount');
    }

    public static function date_expense($date)
    {
        return Expense::where('expense_date', $date)->sum('amount');
    }

    public static function date_income($date)
    {
        return Income::where('income_date', $date)->sum('amount');
    }

}
