Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fdbaf0285 | |||
| 8a049efe49 | |||
| a62b2214c4 |
@@ -23,12 +23,14 @@ class CostUnitRepository {
|
||||
|
||||
|
||||
|
||||
public function getCurrentEvents() : array {
|
||||
public function getCurrentEvents(bool $disableAccessCheck = false) : array {
|
||||
return $this->getCostUnitsByCriteria([
|
||||
'allow_new' => true,
|
||||
'type' => CostUnitType::COST_UNIT_TYPE_EVENT,
|
||||
'archived' => false
|
||||
]);
|
||||
],
|
||||
true,
|
||||
$disableAccessCheck);
|
||||
}
|
||||
|
||||
public function getRunningJobs() : array {
|
||||
|
||||
@@ -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']);
|
||||
foreach ($costUnitRepository->getCurrentEvents(true) as $costUnit) {
|
||||
$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