ceil((float)$model->total) !== ceil($total) ||
json_encode($model->details, JSON_UNESCAPED_UNICODE) !== json_encode($details, JSON_UNESCAPED_UNICODE)
);
-
+ $isArchive = self::isEditable($year, $month);
if ($model->isNewRecord || $needsUpdate) {
$model->setAttributes([
'month' => $month,
'week' => $week,
'product_id' => $productId,
'store_id' => $storeId,
- 'is_archive' => false,
+ 'is_archive' => $isArchive,
'capacity_type' => 1,
'details' => json_encode($details, JSON_UNESCAPED_UNICODE),
'calculate' => $quantity,
return ExitCode::OK;
}
+ public static function isEditable($year, $month): bool
+ {
+ $target = DateTime::createFromFormat('Y-n-j', "$year-$month-1");
+ $target->modify('-2 month')->setDate($target->format('Y'), $target->format('n'), 27);
+
+ $today = new DateTime();
+
+ return $today < $target;
+ }
}