diff --git a/app/Http/Controllers/Business/CourierBillController.php b/app/Http/Controllers/Business/CourierBillController.php
index 93e4f4932..fcff3393a 100644
--- a/app/Http/Controllers/Business/CourierBillController.php
+++ b/app/Http/Controllers/Business/CourierBillController.php
@@ -562,13 +562,15 @@ final class CourierBillController extends Controller
return response()->streamDownload(function () use ($query): void {
$book = new StreamingWorkbook();
$book->row('对账明细', ['账单月份', '对账分组', '负责人', '快递单号', '快递提供运费', '快递提供重量', '分类', '发货时间', '发货数据快递名称1',
- '核算运费', '计费重量', '自算金额', '差异', '未发出来源', '处理结果', '处理人'], true);
+ '核算运费', '结算运费', '运费差', '计费重量', '结算重量', '重量差', '未发出来源', '处理结果', '处理人'], true);
foreach ($query->orderBy('l.id')->select(['l.*', 's.bill_month', 'g.name as group_name', 'g.owner'])->lazyById(1000, 'l.id', 'id') as $line) {
+ $comparison = \App\Support\CourierBills\SettlementComparison::courier($line);
$book->row('对账明细', [$line->bill_month, $line->group_name, $line->owner, (string) $line->waybill_no,
$line->bill_amount === null ? null : (float) $line->bill_amount, $line->bill_weight === null ? null : (float) $line->bill_weight,
Category::label((string) $line->category, $line->category_month), $line->ship_time, $line->express_name,
- $line->calc_freight === null ? null : (float) $line->calc_freight, $line->charge_weight === null ? null : (float) $line->charge_weight,
- $line->self_amount === null ? null : (float) $line->self_amount, round((float) $line->bill_amount - (float) $line->self_amount, 2),
+ $line->calc_freight === null ? null : (float) $line->calc_freight,
+ $line->self_amount === null ? null : (float) $line->self_amount, $comparison['freight_diff'],
+ $line->charge_weight === null ? null : (float) $line->charge_weight, $comparison['settlement_weight'], $comparison['weight_diff'],
$line->unshipped_sources, Category::RESOLUTIONS[$line->resolution] ?? null, $line->resolved_by]);
}
$book->writeTo(fopen('php://output', 'wb'));
diff --git a/app/Http/Controllers/Business/DropshipFreightController.php b/app/Http/Controllers/Business/DropshipFreightController.php
index 44ca4b7fd..32a388a9e 100644
--- a/app/Http/Controllers/Business/DropshipFreightController.php
+++ b/app/Http/Controllers/Business/DropshipFreightController.php
@@ -428,10 +428,10 @@ final class DropshipFreightController extends Controller
}
foreach ($details as [$factory, $rows]) {
$sheet = $factories->count() === 1 ? '明细' : mb_substr((string) $factory->name, 0, 28);
- $book->row($sheet, ['快递单号', '发货时间', '快递名称1', '仓库', '厂家运费', '我方核算运费', '结算运费', '最终结算运费', '差额(厂家−我方)', '状态', '说明', '核算公式'], true);
+ $book->row($sheet, ['快递单号', '发货时间', '快递名称1', '仓库', '厂家运费', '我方核算运费', '结算运费', '最终结算运费', '运费差', '厂家重量', '我方计费重量', '结算重量', '重量差', '状态', '说明', '核算公式'], true);
foreach ($rows as $r) {
$book->row($sheet, [$r['waybill'], $r['ship_time'], $r['express'], $r['warehouse'], $r['bill'], $r['calc'], $r['settle'],
- $r['final'] ?? $r['settle'], $r['diff'], $r['label'], $r['note'], $r['formula']]);
+ $r['final'] ?? $r['settle'], $r['freight_diff'], $r['bill_weight'], $r['charge_weight'], $r['settlement_weight'], $r['weight_diff'], $r['label'], $r['note'], $r['formula']]);
}
}
$book->writeTo(fopen('php://output', 'wb'));
diff --git a/app/Support/CourierBills/SettlementComparison.php b/app/Support/CourierBills/SettlementComparison.php
new file mode 100644
index 000000000..fe174eb00
--- /dev/null
+++ b/app/Support/CourierBills/SettlementComparison.php
@@ -0,0 +1,39 @@
+resolution) {
+ 'agree' => $line->bill_weight === null ? null : (float) $line->bill_weight,
+ 'exclude', 'defer' => 0.0,
+ default => in_array($line->category, [...Category::PAYABLE, Category::PRIOR], true)
+ ? (in_array(trim((string) ($line->express_name ?? '')), CourierBillMatcher::ACTUAL_FREIGHT_EXPRESSES, true)
+ ? ($line->self_amount === null || $line->charge_weight === null ? null : (float) $line->charge_weight)
+ : self::weight($line->bill_amount, $line->calc_freight, $line->bill_weight, $line->charge_weight, $line->self_amount)) : null,
+ };
+
+ return ['settlement_weight' => $weight, 'weight_diff' => self::difference($line->bill_weight, $weight, 4),
+ 'freight_diff' => self::difference($line->bill_amount, $line->self_amount)];
+ }
+}
diff --git a/app/Support/CourierBills/StatementExporter.php b/app/Support/CourierBills/StatementExporter.php
index b32dcbb8f..4324af84f 100644
--- a/app/Support/CourierBills/StatementExporter.php
+++ b/app/Support/CourierBills/StatementExporter.php
@@ -11,15 +11,15 @@ use Modules\EcommerceFinance\Services\CourierBookkeepingRegistry;
* 导出文件以快递发来的原始账单为底:原文件的每张表一个字节不改,后面追加汇总、对账、前月补提供-X月、跨月订单-X月、快递不符、重复、
* 匹配不到、未发出、未提供、说明;没有数据的工作表不生成。
*
- * 对账类子表的列顺序:快递原始列 → 财务指定的 25 列 → 发货数据其余字段 → 处理结果。
+ * 对账类子表的列顺序:快递原始列 → 核算及结算对比列 → 发货数据其余字段 → 处理结果。
*/
final class StatementExporter
{
- /** 财务指定的 25 列 => 取值来源(发货数据字段,或 _ 开头的计算项)。 */
+ /** 对账列 => 取值来源(发货数据字段,或 _ 开头的计算项)。 */
public const FRONT = [
'称重重量' => '_measured', '首重' => 'qc_first_price', '面单' => 'qc_miandan', '快递单号' => 'express_no',
'交易单号' => 'trade_no', '商品ID' => 'item_id', '条形码' => 'barcode', '商品名称' => 'product_name', '数量' => 'qty',
- '计费重量' => 'qc_charge_weight', '续重/费率' => 'qc_rate', '核算运费' => 'qc_freight', '重量差' => '_weight_diff',
+ '计费重量' => 'qc_charge_weight', '结算重量' => '_settlement_weight', '续重/费率' => 'qc_rate', '核算运费' => 'qc_freight', '重量差' => '_weight_diff',
'运费差' => '_freight_diff', '省' => 'receiver_state', '买家昵称' => 'buyer_nick', '收货姓名' => 'receiver_name',
'店铺名称' => 'shop_name', '快递名称1' => 'express_name1', '仓库' => 'warehouse_name', '发货时间' => 'ship_time',
'未发出' => '_unshipped', '运费' => 'freight', '线上重量' => 'online_weight', '实称重量' => 'actual_weight',
@@ -398,7 +398,7 @@ final class StatementExporter
}
$rows = [
...$rows,
- [$book->nameOf('对账'), '本月发货、发货数据里找得到、属于这家快递的单号(运费一致或有差)。前面是快递原始列,后面接我方核算的 25 列(称重重量、首重、面单、计费重量、续重/费率、核算运费、重量差、运费差……)和发货数据其余字段。', $count(Category::PAYABLE)],
+ [$book->nameOf('对账'), '本月发货、发货数据里找得到、属于这家快递的单号(运费一致或有差)。前面是快递原始列,后面接核算与结算对比列;运费差为快递运费减结算运费,重量差为快递重量减结算重量。', $count(Category::PAYABLE)],
['前月补提供-X月', '发货时间在账单月之前、结算台账里没结算过的单号:快递之前漏报、这次补上的。', $count([Category::PRIOR])],
['跨月订单-X月', '发货时间在账单月之后的单号,本月不结算。', $count([Category::LATER])],
[$book->nameOf('快递不符'), '发货数据里有这个单号,但快递名称1 不是这家(也不在同一张合并账单里)。', $count([Category::MISMATCH])],
@@ -488,10 +488,9 @@ final class StatementExporter
return match ($field) {
'_measured' => $ship['qc_measured_weight'] ?? null,
'_unshipped' => $line->unshipped_sources,
- '_weight_diff' => $line->bill_weight !== null && ($ship['qc_charge_weight'] ?? null) !== null
- ? round((float) $line->bill_weight - (float) $ship['qc_charge_weight'], 4) : null,
- '_freight_diff' => $line->bill_amount !== null && ($ship['qc_freight'] ?? null) !== null
- ? round((float) $line->bill_amount - (float) $ship['qc_freight'], 2) : null,
+ '_settlement_weight' => SettlementComparison::courier($line)['settlement_weight'],
+ '_weight_diff' => SettlementComparison::courier($line)['weight_diff'],
+ '_freight_diff' => SettlementComparison::courier($line)['freight_diff'],
default => self::value($field, $ship[$field] ?? null),
};
}
diff --git a/app/Support/DropshipFreight/DropshipExporter.php b/app/Support/DropshipFreight/DropshipExporter.php
index 0f43acf02..5fbec5c5c 100644
--- a/app/Support/DropshipFreight/DropshipExporter.php
+++ b/app/Support/DropshipFreight/DropshipExporter.php
@@ -17,7 +17,7 @@ use RuntimeException;
* 代发运费对账单导出(内部版),和快递账单对账的导出一个样子:
* 和手工版一样:第一张是「汇总」(照这家上月手工汇总的样子),然后是厂家发来的原始账单(表名改叫「厂家账单」,内容原样不动),后面接 对账、前月补提供-X月、跨月订单-X月、快递不符、重复、匹配不到、未发出、
* 厂家未提供、说明;没有数据的表不生成。
- * 对账类子表的列顺序:厂家账单原始列(一单多行取第一行)→ 财务指定的 25 列 → 发货数据其余字段 → 厂家运费合计、结算运费、分类、说明。
+ * 对账类子表的列顺序:厂家账单原始列(一单多行取第一行)→ 核算及结算对比列 → 发货数据其余字段 → 厂家运费合计、结算运费、分类、说明。
*/
final class DropshipExporter
{
@@ -258,7 +258,7 @@ final class DropshipExporter
. ';' . ($read ? '读了这张表的运费。' : '这张表没读运费(货款、记账、退货等)。'), $lines]);
}
foreach ([
- ['对账', '本月发货、是这家代发单的单号(一致、运费有差、系统未核算),按我方核算运费结算。前面是厂家账单原始列,后面接我方核算的 25 列和发货数据其余字段。', [Category::MATCH, Category::DIFF, Category::UNCALCULATED]],
+ ['对账', '本月发货、是这家代发单的单号(一致、运费有差、系统未核算)。运费差为厂家运费减最终结算运费,重量差为厂家重量减结算重量。前面是厂家账单原始列,后面接核算及结算对比列和发货数据其余字段。', [Category::MATCH, Category::DIFF, Category::UNCALCULATED]],
['前月补提供-X月', '上月及以前发货、厂家这次才开的单,按我方核算运费结算。', [Category::PRIOR]],
['跨月订单-X月', '下个月才发货的单,本月不付,留到发货那个月。', [Category::LATER]],
['快递不符', '发货数据查得到,但不是这家代发单(不是这家代发仓发的、快递名称1 不含关键字,或是自有快递),不付。', [Category::MISMATCH]],
@@ -337,6 +337,7 @@ final class DropshipExporter
'_unshipped' => null,
'_bill_weight' => $r['bill_weight'],
'qc_charge_weight' => $r['charge_weight'],
+ '_settlement_weight' => $r['settlement_weight'],
'_weight_diff' => $r['weight_diff'],
'_final' => $r['final'] ?? $r['settle'] ?? null,
// 运费差 = 厂家运费 − 最终结算运费
diff --git a/app/Support/DropshipFreight/DropshipReconciler.php b/app/Support/DropshipFreight/DropshipReconciler.php
index b949138b4..3d45e1374 100644
--- a/app/Support/DropshipFreight/DropshipReconciler.php
+++ b/app/Support/DropshipFreight/DropshipReconciler.php
@@ -5,6 +5,7 @@ namespace App\Support\DropshipFreight;
use App\Support\CourierBills\Category;
use App\Support\CourierBills\CourierBillMatcher;
use App\Support\CourierBills\ShippingLookup;
+use App\Support\CourierBills\SettlementComparison;
use App\Support\UnshippedWaybills;
/**
@@ -141,12 +142,15 @@ final class DropshipReconciler
$settle = in_array($status, self::PAYABLE, true) ? $calc : null;
$chargeWeight = $i['charge_weight'] ?? null;
$weightDiff = $billWeight !== null && $chargeWeight !== null ? round($billWeight - $chargeWeight, 4) : null;
+ $final = self::final($billed, $settle);
+ $settlementWeight = SettlementComparison::weight($billed, $calc, $billWeight, $chargeWeight, $final);
return ['waybill' => $waybill, 'ship_time' => $i['ship_time'] ?? null, 'express' => $i['express'] ?? null,
'warehouse' => $i['warehouse'] ?? null, 'bill' => $billed, 'calc' => $calc,
- 'bill_weight' => $billWeight, 'charge_weight' => $chargeWeight, 'weight_diff' => $weightDiff,
+ 'bill_weight' => $billWeight, 'charge_weight' => $chargeWeight, 'settlement_weight' => $settlementWeight,
+ 'weight_diff' => SettlementComparison::difference($billWeight, $settlementWeight, 4),
'diff_kind' => $status !== Category::DIFF ? null : ($weightDiff === null ? 'missing_weight' : (abs($weightDiff) > 0.005 ? 'weight_diff' : 'price_diff')),
- 'settle' => $settle, 'final' => self::final($billed, $settle),
+ 'settle' => $settle, 'final' => $final, 'freight_diff' => SettlementComparison::difference($billed, $final),
'diff' => $billed !== null && $calc !== null ? round($billed - $calc, 2) : null,
'status' => $status, 'status_month' => $statusMonth, 'label' => self::label($status, $statusMonth),
'note' => $note, 'formula' => $i['formula'] ?? null];
diff --git a/resources/views/business/pages/courier-payables/courier-bills/details.blade.php b/resources/views/business/pages/courier-payables/courier-bills/details.blade.php
index 47b78121b..c6b94309b 100644
--- a/resources/views/business/pages/courier-payables/courier-bills/details.blade.php
+++ b/resources/views/business/pages/courier-payables/courier-bills/details.blade.php
@@ -29,23 +29,29 @@
账单月份 对账分组 负责人 快递单号 分类
- 快递运费 核算运费 结算运费 差异
+ 快递运费 核算运费 结算运费 运费差
+ 快递重量 计费重量 结算重量 重量差
发货时间 发货数据快递名称1 处理结果
正常应付运费取快递提供与我方核算的较低金额;中铁物流、武进安能按我方实际核算运费结算。处理结果:同意付款 = 自算金额取快递金额;已与快递确认剔除 / 转下月 = 本月自算金额为 0。武进韵达重量多报超过1公斤的正向运费差额,合计后补50%,在小汇总单列。改完对应对账单的小汇总和快递应付汇总自动重算。
+正常应付运费取快递提供与我方核算的较低金额;按快递较低运费结算时,结算重量也取快递重量,缺失则留空。运费差 = 快递运费 − 结算运费;重量差 = 快递重量 − 结算重量。中铁物流、武进安能按我方实际核算运费结算。处理结果:同意付款 = 结算金额和重量取快递提供值;已与快递确认剔除 / 转下月 = 本月结算金额和重量为 0。武进韵达重量多报超过1公斤的正向运费差额,合计后补50%,在小汇总单列。改完对应对账单的小汇总和快递应付汇总自动重算。
diff --git a/resources/views/business/pages/courier-payables/courier-bills/statement.blade.php b/resources/views/business/pages/courier-payables/courier-bills/statement.blade.php index d906614f2..7fa993818 100644 --- a/resources/views/business/pages/courier-payables/courier-bills/statement.blade.php +++ b/resources/views/business/pages/courier-payables/courier-bills/statement.blade.php @@ -47,7 +47,7 @@正常应付运费与已核价附加费取快递提供和我方核算的较低金额;中铁物流、武进安能的运费按我方实际核算值结算,已有手工处理优先。武进韵达:快递重量超过我方计费重量1公斤的单据,快递多报的运费差额合计的50%单列补给快递。
+正常应付运费与已核价附加费取快递提供和我方核算的较低金额;按快递较低运费结算时,结算重量也取快递重量,缺失则留空。运费差 = 快递运费 − 结算运费;重量差 = 快递重量 − 结算重量。中铁物流、武进安能的运费按我方实际核算值结算,已有手工处理优先。武进韵达:快递重量超过我方计费重量1公斤的单据,快递多报的运费差额合计的50%单列补给快递。
| 项目 | 快递提供金额 | 自算金额 | 差异 | 归到汇总列 | @endif | 快递单号 | 快递运费 | 快递重量 | -发货时间 | 发货数据快递名称1 | 核算运费 | 结算运费 | 计费重量 | +发货时间 | 发货数据快递名称1 | 核算运费 | 结算运费 | 计费重量 | 结算重量 | 运费差 | 重量差 | 未发出来源 | 处理结果 | @endif @@ -120,6 +120,7 @@ @if ($isUnprovided)
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{ $line->waybill_no }} | {{ $line->ship_time }} | {{ $line->express_name }} | {{ $money($line->calc_freight) }} | ||||||||||
| @endif | {{ $line->waybill_no }} | @@ -130,14 +131,15 @@{{ $money($line->calc_freight) }} | {{ $money($line->self_amount) }} | {{ $line->charge_weight === null ? '' : rtrim(rtrim(number_format((float) $line->charge_weight, 3), '0'), '.') }} | -{{ $line->bill_amount !== null && $line->calc_freight !== null ? $money((float) $line->bill_amount - (float) $line->calc_freight) : '' }} | -{{ $line->bill_weight !== null && $line->charge_weight !== null ? round((float) $line->bill_weight - (float) $line->charge_weight, 3) : '' }} | +{{ $comparison['settlement_weight'] === null ? '' : round($comparison['settlement_weight'], 4) }} | +{{ $money($comparison['freight_diff']) }} | +{{ $comparison['weight_diff'] ?? '' }} | {{ $line->unshipped_sources }} | {{ \App\Support\CourierBills\Category::RESOLUTIONS[$line->resolution] ?? '' }}{{ $line->resolved_by ? ' · ' . $line->resolved_by : '' }} | ||
| 这一类没有明细。 | |||||||||||||
| 这一类没有明细。 | |||||||||||||
重量差 = 厂家账单重量 − 我方计费重量(公斤)。运费有差时,重量相同归价格差;任一重量缺失归重量待补充。差异分类不改变结算金额。
+运费差 = 厂家运费 − 最终结算运费;重量差 = 厂家重量 − 结算重量(公斤)。按厂家较低运费结算时,结算重量也取厂家重量;厂家未提供重量则留空。上方差异原因仍按原核算值识别。
| 快递单号 | 发货 / 快递 | 厂家重量(kg) | 我方计费重量(kg) | 重量差(kg) | 厂家运费 | 我方核算 | 最终结算 | 差额 | 分类 / 说明 | 厂家反馈 | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| {{ $r['waybill'] }} | {{ $r['ship_time'] }} {{ $r['express'] }} | @foreach(['bill_weight','charge_weight','weight_diff'] as $weightKey){{ $r[$weightKey]===null?'—':rtrim(rtrim(number_format($r[$weightKey],4,'.',''),'0'),'.') }} | @endforeach{{ $money($r['bill']) }} | {{ $money($r['calc']) }} | {{ $money($r['final']??$r['settle']) }} | {{ $r['bill']===null?'':$money($r['bill']-(float)($r['final']??$r['settle'])) }} | {{ $r['label'] }}@if($r['diff_kind']) {{ ['weight_diff'=>'重量差','price_diff'=>'价格差','missing_weight'=>'重量待补充'][$r['diff_kind']] }} @endif{{ $r['note'] }} | @if(isset($dfDisputeMap[$r['waybill']])){{ isset($dfDisputeMap[$r['waybill']]['decision'])?'查看处理':'待处理异议' }}@else—@endif | |||
| 当前筛选没有明细。 | |||||||||||
| 快递单号 | 发货 / 快递 | 厂家重量(kg) | 我方计费重量(kg) | 结算重量(kg) | 重量差(kg) | 厂家运费 | 我方核算 | 最终结算 | 运费差 | 分类 / 说明 | 厂家反馈 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| {{ $r['waybill'] }} | {{ $r['ship_time'] }} {{ $r['express'] }} | @foreach(['bill_weight','charge_weight','settlement_weight','weight_diff'] as $weightKey){{ $r[$weightKey]===null?'—':rtrim(rtrim(number_format($r[$weightKey],4,'.',''),'0'),'.') }} | @endforeach{{ $money($r['bill']) }} | {{ $money($r['calc']) }} | {{ $money($r['final']??$r['settle']) }} | {{ $money($r['freight_diff']) }} | {{ $r['label'] }}@if($r['diff_kind']) {{ ['weight_diff'=>'重量差','price_diff'=>'价格差','missing_weight'=>'重量待补充'][$r['diff_kind']] }} @endif{{ $r['note'] }} | @if(isset($dfDisputeMap[$r['waybill']])){{ isset($dfDisputeMap[$r['waybill']]['decision'])?'查看处理':'待处理异议' }}@else—@endif | |||
| 当前筛选没有明细。 | |||||||||||
| 项目 | 厂家金额 | 自算金额 |
|---|---|---|
| {{ $fee->item }} | {{ $money($fee->bill) }} | {{ $money($fee->self) }} |