Release
This commit is contained in:
@@ -2,23 +2,41 @@
|
||||
|
||||
namespace App\Tasks;
|
||||
|
||||
use App\Domains\CostUnit\Actions\ChangeCostUnitDetails\ChangeCostUnitDetailsCommand;
|
||||
use App\Domains\CostUnit\Actions\ChangeCostUnitDetails\ChangeCostUnitDetailsRequest;
|
||||
use App\Domains\CostUnit\Actions\ChangeCostUnitState\ChangeCostUnitStateCommand;
|
||||
use App\Domains\CostUnit\Actions\ChangeCostUnitState\ChangeCostUnitStateRequest;
|
||||
use App\Models\CostUnit;
|
||||
use App\Repositories\CostUnitRepository;
|
||||
use App\ValueObjects\Amount;
|
||||
|
||||
class CloseCostUnit implements CronTask {
|
||||
public function handle(): void
|
||||
{
|
||||
$now = now();
|
||||
$costUnitRepository = new CostUnitRepository();
|
||||
$now = now();
|
||||
$billingResetEnd = clone $now;
|
||||
$billingResetEnd->add(new \DateInterval('P6W'));
|
||||
/** @var CostUnit $costUnit */
|
||||
foreach ($costUnitRepository->getCurrentEvents() as $costUnit) {
|
||||
$billingEndTime = \DateTime::createFromFormat('Y-m-d H:i:s', $costUnit['billing_deadline']);
|
||||
$billingEnd = $costUnit['billing_deadline'];
|
||||
|
||||
if ($billingEnd === null) {
|
||||
$billingEnd = \DateTime::createFromFormat('Y-m-d H:i:s', $billingResetEnd)->format('Y-m-d H:i:s');
|
||||
new ChangeCostUnitDetailsCommand(new ChangeCostUnitDetailsRequest(
|
||||
CostUnit::where('id', $costUnit['id'])->first(),
|
||||
Amount::fromString($costUnit['distance_allowance']),
|
||||
$costUnit['mail_on_new'],
|
||||
$billingResetEnd
|
||||
))->execute();
|
||||
}
|
||||
|
||||
$billingEndTime = \DateTime::createFromFormat('Y-m-d H:i:s', $billingEnd);
|
||||
$billingEndTime->setTime(0,0,0);
|
||||
$billingEndTime->add(new \DateInterval('P1D'));
|
||||
|
||||
$now = now();
|
||||
|
||||
|
||||
if ($billingEndTime < $now) {
|
||||
new ChangeCostUnitStateCommand(
|
||||
|
||||
Reference in New Issue
Block a user