|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Interfaces\SettlementBillReportInterface;
|
|
|
use App\Owner;
|
|
|
use App\OwnerBillReport;
|
|
|
use App\OwnerBillReportArchive;
|
|
|
@@ -12,7 +13,7 @@ use Carbon\Carbon;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
-class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReportInterface
|
|
|
+class OwnerStoreFeeReportService implements SettlementBillReportInterface
|
|
|
{
|
|
|
const TYPE = '入库费-合计';
|
|
|
|
|
|
@@ -98,35 +99,9 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
|
|
|
OwnerStoreFeeReport::query()->insertOrIgnore($items);
|
|
|
}
|
|
|
|
|
|
- //没有数量的计费模型填充0数据
|
|
|
- //查询到全部的货主
|
|
|
- $owners = Owner::query()->with('ownerPriceOperations.items')->get();
|
|
|
- foreach ($owners as $owner) {
|
|
|
- $owner_id = $owner->id;
|
|
|
- foreach ($owner->ownerPriceOperations as $ownerPriceOperation) {
|
|
|
- $ownerPriceOperation_id = $ownerPriceOperation->id;
|
|
|
- $has_report = OwnerStoreFeeReport::query()
|
|
|
- ->where('owner_id', $owner_id)
|
|
|
- ->where('model_id', $ownerPriceOperation_id)
|
|
|
- ->where('counting_month', $counting_month)
|
|
|
- ->exists();
|
|
|
- if ($has_report) continue;
|
|
|
-
|
|
|
-// foreach ($ownerPriceOperation->items as $ownerPriceOperationItem) {
|
|
|
- OwnerStoreFeeReport::query()->insert([
|
|
|
- 'owner_bill_report_id' => 1,
|
|
|
- 'owner_id' => $owner_id,
|
|
|
- 'counting_month' => $counting_month, //统计月份
|
|
|
- 'unit_id' => 4, //件
|
|
|
- 'unit_price' => $ownerPriceOperation->items[0]->unit_price ?? 0, //单价
|
|
|
- 'amount' => 0, //数量
|
|
|
- 'fee' => 0,//费用
|
|
|
- 'work_name' => $ownerPriceOperation->name,//作业名称
|
|
|
- 'model_id' => $ownerPriceOperation_id,//计费模型
|
|
|
- 'tax_fee' => 0,//税费
|
|
|
- ]);
|
|
|
- }
|
|
|
- }
|
|
|
+ //货主的每个计费模型都要有数据,如果当月没有实际数据则需要
|
|
|
+ //写默认值
|
|
|
+ $this->insertDefaultData($counting_month);
|
|
|
}
|
|
|
|
|
|
public function get(array $kvPairs): array
|
|
|
@@ -207,5 +182,42 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
|
|
|
$this->confirmBillFeeTotal($counting_month, $owner_id);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 没有数量的计费模型填充0数据
|
|
|
+ * @param string|null $counting_month
|
|
|
+ */
|
|
|
+ private function insertDefaultData(?string $counting_month): void
|
|
|
+ {
|
|
|
+ //查询到全部的货主
|
|
|
+ $owners = Owner::query()->with('ownerPriceOperations.items')->get();
|
|
|
+ //遍历货主
|
|
|
+ foreach ($owners as $owner) {
|
|
|
+ $owner_id = $owner->id;
|
|
|
+ //遍历货主下的计费模型
|
|
|
+ foreach ($owner->ownerPriceOperations as $ownerPriceOperation) {
|
|
|
+ $ownerPriceOperation_id = $ownerPriceOperation->id;
|
|
|
+ //查询是否有报表数据
|
|
|
+ $has_report = OwnerStoreFeeReport::query()
|
|
|
+ ->where('owner_id', $owner_id)
|
|
|
+ ->where('model_id', $ownerPriceOperation_id)
|
|
|
+ ->where('counting_month', $counting_month)
|
|
|
+ ->exists();
|
|
|
+ //有报表直接略过
|
|
|
+ if ($has_report) continue;
|
|
|
+ //构建默认数据
|
|
|
+ OwnerStoreFeeReport::query()->insert([
|
|
|
+ 'owner_bill_report_id' => 1,
|
|
|
+ 'owner_id' => $owner_id,
|
|
|
+ 'counting_month' => $counting_month, //统计月份
|
|
|
+ 'unit_id' => 4, //件
|
|
|
+ 'unit_price' => $ownerPriceOperation->items[0]->unit_price ?? 0, //单价
|
|
|
+ 'amount' => 0, //数量
|
|
|
+ 'fee' => 0,//费用
|
|
|
+ 'work_name' => $ownerPriceOperation->name,//作业名称
|
|
|
+ 'model_id' => $ownerPriceOperation_id,//计费模型
|
|
|
+ 'tax_fee' => 0,//税费
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|