Working on the calendar

This commit is contained in:
Hillel Coren 2017-09-13 16:34:16 +03:00
parent e0bcd698ac
commit 647c44ee57
4 changed files with 40 additions and 0 deletions

View File

@ -30,6 +30,12 @@ class GenerateCalendarEvents extends Job
foreach ($data as $type => $source) { foreach ($data as $type => $source) {
if (! count($filter) || in_array($type, $filter)) { if (! count($filter) || in_array($type, $filter)) {
$source->where(function($query) use ($type) {
$start = date_create(request()->start);
$end = date_create(request()->end);
return $query->dateRange($start, $end);
});
foreach ($source->with(['account', 'client.contacts'])->get() as $entity) { foreach ($source->with(['account', 'client.contacts'])->get() as $entity) {
if ($entity->client && $entity->client->trashed()) { if ($entity->client && $entity->client->trashed()) {
continue; continue;

View File

@ -227,6 +227,16 @@ class Expense extends EntityModel
return $array; return $array;
} }
/**
* @param $query
*
* @return mixed
*/
public function scopeDateRange($query, $startDate, $endDate)
{
return $query->whereBetween('expense_date', [$startDate, $endDate]);
}
/** /**
* @param $query * @param $query
* @param null $bankdId * @param null $bankdId

View File

@ -423,6 +423,20 @@ class Invoice extends EntityModel implements BalanceAffecting
->where('is_recurring', '=', true); ->where('is_recurring', '=', true);
} }
/**
* @param $query
*
* @return mixed
*/
public function scopeDateRange($query, $startDate, $endDate)
{
return $query->where(function ($query) use ($startDate, $endDate) {
$query->whereBetween('invoice_date', [$startDate, $endDate]);
})->orWhere(function ($query) use ($startDate, $endDate) {
$query->whereBetween('due_date', [$startDate, $endDate]);
});
}
/** /**
* @param $query * @param $query
* *

View File

@ -146,6 +146,16 @@ class Payment extends EntityModel
return $query; return $query;
} }
/**
* @param $query
*
* @return mixed
*/
public function scopeDateRange($query, $startDate, $endDate)
{
return $query->whereBetween('payment_date', [$startDate, $endDate]);
}
/** /**
* @return mixed * @return mixed
*/ */