|
|
@@ -51,22 +51,25 @@ class CreateOwnerBillReport extends Command
|
|
|
$sql = "SELECT owner_id,SUM(IFNULL(work_fee,0)) AS work_fee,SUM(IFNULL(logistic_fee,0)) AS logistic_fee FROM owner_fee_details WHERE worked_at LIKE ? AND ((type = '发货' AND logistic_fee IS NOT NULL AND work_fee IS NOT NULL) OR (type <> '发货' AND work_fee IS NOT NULL)) GROUP BY owner_id";
|
|
|
$billDetails = DB::select(DB::raw($sql),[$year."-".$lastMonth."%"]);
|
|
|
|
|
|
- $areas = OwnerAreaReport::query()->with("ownerStoragePriceModel")->where("counting_month","like",$year."-".$lastMonth."%")->get();
|
|
|
+ $areas = OwnerAreaReport::query()->with(["ownerStoragePriceModel.timeUnit","ownerStoragePriceModel.taxRate"])->where("counting_month","like",$year."-".$lastMonth."%")->get();
|
|
|
$map = [];
|
|
|
+ $mapTax = [];
|
|
|
foreach($areas as $area){
|
|
|
- if (isset($map[$area->owner_id."_".$area->counting_month])){
|
|
|
+ $key = $area->owner_id."_".$area->counting_month;
|
|
|
+ if (isset($map[$key])){
|
|
|
if (!$area->ownerStoragePriceModel)continue;
|
|
|
- $map[$area->owner_id."_".$area->counting_month] += app('OwnerStoragePriceModelService')
|
|
|
+ list($money,$taxFee) = app('OwnerStoragePriceModelService')
|
|
|
->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
|
|
|
+ $map[$key] += $money;
|
|
|
+ $mapTax[$key] += $taxFee;
|
|
|
}else{
|
|
|
if (!$area->ownerStoragePriceModel)continue;
|
|
|
- $map[$area->owner_id."_".$area->counting_month] = app('OwnerStoragePriceModelService')
|
|
|
+ list($map[$key],$mapTax[$key]) = app('OwnerStoragePriceModelService')
|
|
|
->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
|
|
|
}
|
|
|
}
|
|
|
foreach (OwnerPriceSystem::query()->with(["timeUnit","taxRate"])->select("owner_id","usage_fee")->whereNull("operation")->orWhere("operation","")->get() as $system){
|
|
|
- if (!$system->timeUnit)$systemFee[$system->owner_id] = $system->usage_fee;
|
|
|
- else $systemFee[$system->owner_id] = $this->systemFee($system,$year."-".$lastMonth);
|
|
|
+ list($systemFee[$system->owner_id],$systemTaxFee[$system->owner_id]) = $this->systemFee($system,$year."-".$lastMonth);
|
|
|
}
|
|
|
$chunks = array_chunk($billDetails,50);
|
|
|
foreach ($chunks as $bills){
|
|
|
@@ -74,14 +77,15 @@ class CreateOwnerBillReport extends Command
|
|
|
$createOwnerBillReport = [];
|
|
|
foreach ($bills as $bill){
|
|
|
$key = $bill->owner_id."_".$year."-".$lastMonth;
|
|
|
- $otherFee = $systemFee[$bill->owner_id] ?? null;
|
|
|
$createOwnerBillReport[] = [
|
|
|
"owner_id" => $bill->owner_id, //项目ID
|
|
|
"counting_month" => $year."-".$lastMonth."-01", //结算月
|
|
|
"work_fee" => $bill->work_fee,
|
|
|
"logistic_fee" => $bill->logistic_fee,
|
|
|
"storage_fee" => $map[$key] ?? 0,
|
|
|
- "other_fee" => $otherFee,
|
|
|
+ "storage_tax_fee" => $mapTax[$key] ?? 0,
|
|
|
+ "other_fee" => $systemFee[$bill->owner_id] ?? null,
|
|
|
+ "other_tax_fee" => $systemTaxFee[$bill->owner_id] ?? null,
|
|
|
"created_at" => $date,
|
|
|
];
|
|
|
}
|
|
|
@@ -96,23 +100,25 @@ class CreateOwnerBillReport extends Command
|
|
|
* @param OwnerPriceSystem|\stdClass $system
|
|
|
* @param string $month
|
|
|
*
|
|
|
- * @return double
|
|
|
+ * @return array
|
|
|
*/
|
|
|
private function systemFee(OwnerPriceSystem $system,$month)
|
|
|
{
|
|
|
- $money = null;
|
|
|
- switch ($system->timeUnit->name){
|
|
|
- case "日":
|
|
|
- $money = $system->usage_fee*(Carbon::parse($month)->lastOfMonth()->format("d"));
|
|
|
- break;
|
|
|
- case "单":
|
|
|
- $money = $system->usage_fee * (app("OrderService")->getOrderQuantity($system->owner_id));
|
|
|
- break;
|
|
|
- case "年":
|
|
|
- $money = $system->usage_fee/12;
|
|
|
- break;
|
|
|
- default:
|
|
|
- $money = $system->usage_fee;
|
|
|
+ if (!$system->timeUnit)$money = $system->usage_fee;
|
|
|
+ else{
|
|
|
+ switch ($system->timeUnit->name){
|
|
|
+ case "日":
|
|
|
+ $money = $system->usage_fee*(Carbon::parse($month)->lastOfMonth()->format("d"));
|
|
|
+ break;
|
|
|
+ case "单":
|
|
|
+ $money = $system->usage_fee * (app("OrderService")->getOrderQuantity($system->owner_id));
|
|
|
+ break;
|
|
|
+ case "年":
|
|
|
+ $money = $system->usage_fee/12;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $money = $system->usage_fee;
|
|
|
+ }
|
|
|
}
|
|
|
if ($system->taxRate)$taxFee = $money * ($system->taxRate->value/100);
|
|
|
else{
|
|
|
@@ -120,6 +126,6 @@ class CreateOwnerBillReport extends Command
|
|
|
if ($system->owner && $system->owner->taxRate)$taxFee = $money * ($system->owner->taxRate->value/100);
|
|
|
else $taxFee = null;
|
|
|
}
|
|
|
- return $money;
|
|
|
+ return array($money,$taxFee);
|
|
|
}
|
|
|
}
|