- 基础环境:Docker 部署配置,源码挂载实时同步 - 修复:super_admin 权限补全、登录重定向循环 - 开发:店铺营销账户账单 - 抖音账户(15字段汇总账单) - 开发:店铺营销账户账单 - 淘系支付宝账户(8字段流水账单) - 开发:店铺营销账户账单 - 拼多多账户(7字段流水账单) - 业务页面导航集成:config/business_navigation.php + Business\Pages 控制器 - 各平台独立表结构和视图,互不影响
52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Utilities;
|
|
|
|
use App\Models\Document\Document;
|
|
use App\Traits\DateTime;
|
|
use App\Utilities\Date;
|
|
|
|
class Recurring
|
|
{
|
|
public static function reflect(&$items, $issued_date_field)
|
|
{
|
|
$financial_year = (new class { use DateTime; })->getFinancialYear();
|
|
|
|
foreach ($items as $key => $item) {
|
|
// @todo cache recurrings
|
|
if (! $item->recurring || !empty($item->parent_id)) {
|
|
continue;
|
|
}
|
|
|
|
foreach ($item->recurring->getRecurringSchedule() as $schedule) {
|
|
$issued = Date::parse($item->$issued_date_field);
|
|
$start = $schedule->getStart();
|
|
$start_date = Date::parse($start->format('Y-m-d'));
|
|
|
|
if (($issued->format('Y-m') == $start->format('Y-m')) && ($issued->format('d') >= $start->format('d'))) {
|
|
continue;
|
|
}
|
|
|
|
if ($start_date->lessThan($financial_year->getStartDate()) || $start_date->greaterThan($financial_year->getEndDate())) {
|
|
continue;
|
|
}
|
|
|
|
$clone = clone $item;
|
|
|
|
if ($clone instanceof Document) {
|
|
// Days between invoiced/billed and due date
|
|
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->$issued_date_field));
|
|
|
|
$clone->due_at = $start_date->copy()->addDays($diff_days)->format('Y-m-d');
|
|
}
|
|
|
|
$clone->parent_id = $item->id;
|
|
$clone->created_at = $start_date->format('Y-m-d');
|
|
$clone->$issued_date_field = $start_date->format('Y-m-d');
|
|
|
|
$items->push($clone);
|
|
}
|
|
}
|
|
}
|
|
}
|