Fix on invoices, add delivery reference, wip on dashboard concurrency requests designed on template
This commit is contained in:
@@ -12,6 +12,59 @@ use function League\Period\interval_after;
|
||||
|
||||
class DateRange
|
||||
{
|
||||
|
||||
public static function today()
|
||||
{
|
||||
return self::previousDay(0);
|
||||
}
|
||||
|
||||
public static function currentWeek()
|
||||
{
|
||||
return self::previousWeek(0);
|
||||
}
|
||||
|
||||
public static function currentMonth()
|
||||
{
|
||||
return self::previousMonth(0);
|
||||
}
|
||||
|
||||
public static function currentYear()
|
||||
{
|
||||
return self::previousYear(0);
|
||||
}
|
||||
|
||||
public static function previousDay($nb = 1)
|
||||
{
|
||||
return [
|
||||
'start' => Carbon::now()->subDay($nb)->startOfDay(),
|
||||
'end' => Carbon::now()->subDay($nb)->endOfDay(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function previousWeek($nb = 1)
|
||||
{
|
||||
return [
|
||||
'start' => Carbon::now()->subWeek($nb)->startOfWeek(),
|
||||
'end' => Carbon::now()->subWeek($nb)->endOfWeek(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function previousMonth($nb = 1)
|
||||
{
|
||||
return [
|
||||
'start' => Carbon::now()->subMonth($nb)->startOfMonth(),
|
||||
'end' => Carbon::now()->subMonth($nb)->endOfMonth(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function previousYear($nb = 1)
|
||||
{
|
||||
return [
|
||||
'start' => Carbon::now()->subYear($nb)->startOfYear(),
|
||||
'end' => Carbon::now()->subYear($nb)->endOfYear(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPeriodsLastMonthWithLabels($nb, $with_actual = true)
|
||||
{
|
||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $with_actual));
|
||||
@@ -30,7 +83,7 @@ class DateRange
|
||||
public static function getPeriodsLastMonth($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||
$begin = ($nb == 1) ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb-1);
|
||||
$begin = ($nb == 1) ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb - 1);
|
||||
$t = self::getPeriodsbyMonth($begin, $end);
|
||||
return self::getPeriodsbyMonth($begin, $end);
|
||||
}
|
||||
@@ -58,14 +111,14 @@ class DateRange
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||
$begin = $end->copy()->subWeek($nb);
|
||||
return static::getPeriodsbyWeek($begin, $end);
|
||||
return self::getPeriodsbyWeek($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastDay($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||
$begin = $end->copy()->subDay($nb);
|
||||
return static::getPeriodsbyDay($begin, $end);
|
||||
return self::getPeriodsbyDay($begin, $end);
|
||||
}
|
||||
|
||||
public static function byDay()
|
||||
@@ -92,16 +145,16 @@ class DateRange
|
||||
{
|
||||
$quarter = Carbon::now()->quarter;
|
||||
switch ($quarter) {
|
||||
case 1:
|
||||
case 2:
|
||||
$date = Carbon::now()->startOfYear();
|
||||
break;
|
||||
case 3:
|
||||
$date = Carbon::now()->startOfQuarter();
|
||||
break;
|
||||
case 4:
|
||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
$date = Carbon::now()->startOfYear();
|
||||
break;
|
||||
case 3:
|
||||
$date = Carbon::now()->startOfQuarter();
|
||||
break;
|
||||
case 4:
|
||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||
break;
|
||||
}
|
||||
return [$date, $date->addMonth(6)];
|
||||
}
|
||||
@@ -143,7 +196,7 @@ class DateRange
|
||||
|
||||
public static function getPeriods($begin, $end, $duration, $interval = 1)
|
||||
{
|
||||
$period = new Period($begin, $end);
|
||||
$period = new Period($begin, $end, $interval);
|
||||
foreach ($period->getDatePeriod($duration) as $day) {
|
||||
$daterange[] = interval_after($day, $duration);
|
||||
}
|
||||
|
||||
51
app/Repositories/Core/DateStats.php
Normal file
51
app/Repositories/Core/DateStats.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
Trait DateStats
|
||||
{
|
||||
public static function countByMonth($prev = 0)
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth($prev);
|
||||
$end = Carbon::now()->endOfMonth($prev);
|
||||
return self::countByPeriod($start, $end);
|
||||
}
|
||||
|
||||
public static function countByPeriod($start, $end, $field = 'created_at')
|
||||
{
|
||||
return self::getModel()->whereBetween($field, [$start, $end])->count();
|
||||
}
|
||||
|
||||
public static function avgByMonth($prev = 0, $field = false)
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth($prev);
|
||||
$end = Carbon::now()->endOfMonth($prev);
|
||||
return self::avgByPeriod($start, $end, $field);
|
||||
}
|
||||
|
||||
public static function avgByPeriod($start, $end, $field)
|
||||
{
|
||||
$c = self::countByPeriod($start, $end);
|
||||
return $c ? round(self::sumByPeriod($start, $end, $field) / $c, 2) : 0;
|
||||
}
|
||||
|
||||
public static function sumByMonth($prev = 0, $field = false)
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth($prev);
|
||||
$end = Carbon::now()->endOfMonth($prev);
|
||||
return self::sumByPeriod($start, $end, $field);
|
||||
}
|
||||
|
||||
public static function sumByPeriod($start, $end, $field = 'created_at')
|
||||
{
|
||||
return self::getModel()->whereBetween($field, [$start, $end])->sum($field);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return new Model;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user