You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
62 lines
1.8 KiB
<?php
|
|
|
|
namespace App\Entities\Reports;
|
|
|
|
use App\Entities\BaseRepository;
|
|
use App\Entities\Payments\Payment;
|
|
use App\Entities\Projects\Project;
|
|
use DB;
|
|
|
|
/**
|
|
* Reports Repository Class
|
|
*/
|
|
class ReportsRepository extends BaseRepository
|
|
{
|
|
protected $model;
|
|
|
|
public function __construct(Payment $model)
|
|
{
|
|
parent::__construct($model);
|
|
}
|
|
|
|
public function getDailyReports($date, $q)
|
|
{
|
|
return Payment::orderBy('date','desc')
|
|
->where('date', $date)
|
|
->with('customer','project')
|
|
->where('owner_id',auth()->id())
|
|
->get();
|
|
}
|
|
|
|
public function getMonthlyReports($year, $month)
|
|
{
|
|
return Payment::select(DB::raw("date, count(`id`) as count, sum(if(in_out = 1, amount, 0)) AS cashin, sum(if(in_out = 0, amount, 0)) AS cashout, in_out"))
|
|
->where(DB::raw('YEAR(date)'), $year)
|
|
->where(DB::raw('MONTH(date)'), $month)
|
|
->groupBy('date')
|
|
->orderBy('date','asc')
|
|
->where('owner_id',auth()->id())
|
|
->get();
|
|
}
|
|
|
|
public function getYearlyReports($year)
|
|
{
|
|
return Payment::select(DB::raw("MONTH(date) as month, count(`id`) as count, sum(if(in_out = 1, amount, 0)) AS cashin, sum(if(in_out = 0, amount, 0)) AS cashout, in_out"))
|
|
->where(DB::raw('YEAR(date)'), $year)
|
|
->groupBy(DB::raw('YEAR(date)'))
|
|
->groupBy(DB::raw('MONTH(date)'))
|
|
->orderBy('date','asc')
|
|
->where('owner_id',auth()->id())
|
|
->get();
|
|
}
|
|
|
|
public function getCurrentCredits()
|
|
{
|
|
// On Progress, Done, On Hold
|
|
$projects = Project::whereIn('status_id',[2,3,6])->with('payments','customer')->get();
|
|
return $projects->filter(function($project) {
|
|
return $project->cashInTotal() < $project->project_value;
|
|
})->values();
|
|
}
|
|
|
|
}
|