fix(运费对账): 按最终结算值计算运费差和重量差 #1786
@ -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'));
|
||||
|
||||
@ -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'));
|
||||
|
||||
39
app/Support/CourierBills/SettlementComparison.php
Normal file
39
app/Support/CourierBills/SettlementComparison.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\CourierBills;
|
||||
|
||||
/** 对账展示和导出统一使用最终结算口径,保留原核算字段。 */
|
||||
final class SettlementComparison
|
||||
{
|
||||
public static function difference(mixed $billed, mixed $settled, int $precision = 2): ?float
|
||||
{
|
||||
return $billed === null || $settled === null ? null : round((float) $billed - (float) $settled, $precision);
|
||||
}
|
||||
|
||||
public static function weight(mixed $billFreight, mixed $calcFreight, mixed $billWeight, mixed $chargeWeight, mixed $settled): ?float
|
||||
{
|
||||
if ($settled === null) return null;
|
||||
if ($billFreight !== null && $calcFreight !== null && (float) $billFreight < (float) $calcFreight
|
||||
&& round((float) $settled, 2) === round((float) $billFreight, 2)) {
|
||||
return $billWeight === null ? null : (float) $billWeight;
|
||||
}
|
||||
|
||||
return $chargeWeight === null ? null : (float) $chargeWeight;
|
||||
}
|
||||
|
||||
/** @return array{settlement_weight:?float,weight_diff:?float,freight_diff:?float} */
|
||||
public static function courier(object $line): array
|
||||
{
|
||||
$weight = match ($line->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)];
|
||||
}
|
||||
}
|
||||
@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
@ -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,
|
||||
// 运费差 = 厂家运费 − 最终结算运费
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -29,23 +29,29 @@
|
||||
<thead><tr>
|
||||
<th scope="col"><input type="checkbox" data-cbr-check-all aria-label="全选本页"></th>
|
||||
<th scope="col">账单月份</th><th scope="col">对账分组</th><th scope="col">负责人</th><th scope="col">快递单号</th><th scope="col">分类</th>
|
||||
<th scope="col" class="num">快递运费</th><th scope="col" class="num">核算运费</th><th scope="col" class="num">结算运费</th><th scope="col" class="num">差异</th>
|
||||
<th scope="col" class="num">快递运费</th><th scope="col" class="num">核算运费</th><th scope="col" class="num">结算运费</th><th scope="col" class="num">运费差</th>
|
||||
<th scope="col" class="num">快递重量</th><th scope="col" class="num">计费重量</th><th scope="col" class="num">结算重量</th><th scope="col" class="num">重量差</th>
|
||||
<th scope="col">发货时间</th><th scope="col">发货数据快递名称1</th><th scope="col">处理结果</th><th scope="col"></th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
@forelse ($cbLines as $line)
|
||||
@php($comparison = \App\Support\CourierBills\SettlementComparison::courier($line))
|
||||
<tr>
|
||||
<td>@if ($line->statement_status !== 'confirmed')<input type="checkbox" name="lines[]" value="{{ $line->id }}" aria-label="选择 {{ $line->waybill_no }}">@endif</td>
|
||||
<td>{{ $line->bill_month }}</td><td>{{ $line->group_name }}</td><td>{{ $line->owner }}</td><td>{{ $line->waybill_no }}</td>
|
||||
<td>{{ \App\Support\CourierBills\Category::label((string) $line->category, $line->category_month) }}</td>
|
||||
<td class="num">{{ $money($line->bill_amount) }}</td><td class="num">{{ $money($line->calc_freight) }}</td>
|
||||
<td class="num">{{ $money($line->self_amount) }}</td><td class="num cbr-diff">{{ $money((float) $line->bill_amount - (float) $line->self_amount) }}</td>
|
||||
<td class="num">{{ $money($line->self_amount) }}</td><td class="num cbr-diff">{{ $money($comparison['freight_diff']) }}</td>
|
||||
<td class="num">{{ $line->bill_weight === null ? '' : round((float) $line->bill_weight, 4) }}</td>
|
||||
<td class="num">{{ $line->charge_weight === null ? '' : round((float) $line->charge_weight, 4) }}</td>
|
||||
<td class="num">{{ $comparison['settlement_weight'] === null ? '' : round($comparison['settlement_weight'], 4) }}</td>
|
||||
<td class="num">{{ $comparison['weight_diff'] ?? '' }}</td>
|
||||
<td>{{ $line->ship_time ? substr((string) $line->ship_time, 0, 16) : '' }}</td><td>{{ $line->express_name }}</td>
|
||||
<td>{{ \App\Support\CourierBills\Category::RESOLUTIONS[$line->resolution] ?? '' }}{{ $line->statement_status === 'confirmed' ? '(已确认结算)' : '' }}</td>
|
||||
<td><a data-cbr-tab href="{{ $pageUrl(['cb_view' => 'statement', 'statement' => $line->statement_id, 'month' => $line->bill_month]) }}">对账单</a></td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="14" class="cbr-empty">当前条件下没有明细。</td></tr>
|
||||
<tr><td colspan="18" class="cbr-empty">当前条件下没有明细。</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
@ -63,4 +69,4 @@
|
||||
<span class="cbr-pager">共 {{ number_format($cbLines->total()) }} 条,每页 50 条 {{ $cbLines->links('business.partials.previous-next-pagination') }}</span>
|
||||
</div>
|
||||
</form>
|
||||
<p class="cbr-muted">正常应付运费取快递提供与我方核算的较低金额;中铁物流、武进安能按我方实际核算运费结算。处理结果:同意付款 = 自算金额取快递金额;已与快递确认剔除 / 转下月 = 本月自算金额为 0。武进韵达重量多报超过1公斤的正向运费差额,合计后补50%,在小汇总单列。改完对应对账单的小汇总和快递应付汇总自动重算。</p>
|
||||
<p class="cbr-muted">正常应付运费取快递提供与我方核算的较低金额;按快递较低运费结算时,结算重量也取快递重量,缺失则留空。运费差 = 快递运费 − 结算运费;重量差 = 快递重量 − 结算重量。中铁物流、武进安能按我方实际核算运费结算。处理结果:同意付款 = 结算金额和重量取快递提供值;已与快递确认剔除 / 转下月 = 本月结算金额和重量为 0。武进韵达重量多报超过1公斤的正向运费差额,合计后补50%,在小汇总单列。改完对应对账单的小汇总和快递应付汇总自动重算。</p>
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
<div class="fc-workspace"><div>
|
||||
<section class="cbr-panel" aria-label="小汇总">
|
||||
<h3>小汇总</h3>
|
||||
<p class="cbr-muted cbr-panel-body">正常应付运费与已核价附加费取快递提供和我方核算的较低金额;中铁物流、武进安能的运费按我方实际核算值结算,已有手工处理优先。武进韵达:快递重量超过我方计费重量1公斤的单据,快递多报的运费差额合计的50%单列补给快递。</p>
|
||||
<p class="cbr-muted cbr-panel-body">正常应付运费与已核价附加费取快递提供和我方核算的较低金额;按快递较低运费结算时,结算重量也取快递重量,缺失则留空。运费差 = 快递运费 − 结算运费;重量差 = 快递重量 − 结算重量。中铁物流、武进安能的运费按我方实际核算值结算,已有手工处理优先。武进韵达:快递重量超过我方计费重量1公斤的单据,快递多报的运费差额合计的50%单列补给快递。</p>
|
||||
<div class="cbr-scroll">
|
||||
<table>
|
||||
<thead><tr><th scope="col">项目</th><th scope="col" class="num">快递提供金额</th><th scope="col" class="num">自算金额</th><th scope="col" class="num">差异</th><th scope="col">归到汇总列</th><th scope="col"></th></tr></thead>
|
||||
@ -111,7 +111,7 @@
|
||||
@else
|
||||
@if ($open)<th scope="col"><input type="checkbox" data-cbr-check-all aria-label="全选本页"></th>@endif
|
||||
<th scope="col">快递单号</th><th scope="col" class="num">快递运费</th><th scope="col" class="num">快递重量</th>
|
||||
<th scope="col">发货时间</th><th scope="col">发货数据快递名称1</th><th scope="col" class="num">核算运费</th><th scope="col" class="num">结算运费</th><th scope="col" class="num">计费重量</th>
|
||||
<th scope="col">发货时间</th><th scope="col">发货数据快递名称1</th><th scope="col" class="num">核算运费</th><th scope="col" class="num">结算运费</th><th scope="col" class="num">计费重量</th><th scope="col" class="num">结算重量</th>
|
||||
<th scope="col" class="num">运费差</th><th scope="col" class="num">重量差</th><th scope="col">未发出来源</th><th scope="col">处理结果</th>
|
||||
@endif
|
||||
</tr></thead>
|
||||
@ -120,6 +120,7 @@
|
||||
@if ($isUnprovided)
|
||||
<tr><td>{{ $line->waybill_no }}</td><td>{{ $line->ship_time }}</td><td>{{ $line->express_name }}</td><td class="num">{{ $money($line->calc_freight) }}</td></tr>
|
||||
@else
|
||||
@php($comparison = \App\Support\CourierBills\SettlementComparison::courier($line))
|
||||
<tr>
|
||||
@if ($open)<td><input type="checkbox" name="lines[]" value="{{ $line->id }}" aria-label="选择 {{ $line->waybill_no }}"></td>@endif
|
||||
<td>{{ $line->waybill_no }}</td>
|
||||
@ -130,14 +131,15 @@
|
||||
<td class="num">{{ $money($line->calc_freight) }}</td>
|
||||
<td class="num">{{ $money($line->self_amount) }}</td>
|
||||
<td class="num">{{ $line->charge_weight === null ? '' : rtrim(rtrim(number_format((float) $line->charge_weight, 3), '0'), '.') }}</td>
|
||||
<td class="num cbr-diff">{{ $line->bill_amount !== null && $line->calc_freight !== null ? $money((float) $line->bill_amount - (float) $line->calc_freight) : '' }}</td>
|
||||
<td class="num">{{ $line->bill_weight !== null && $line->charge_weight !== null ? round((float) $line->bill_weight - (float) $line->charge_weight, 3) : '' }}</td>
|
||||
<td class="num">{{ $comparison['settlement_weight'] === null ? '' : round($comparison['settlement_weight'], 4) }}</td>
|
||||
<td class="num cbr-diff">{{ $money($comparison['freight_diff']) }}</td>
|
||||
<td class="num">{{ $comparison['weight_diff'] ?? '' }}</td>
|
||||
<td>{{ $line->unshipped_sources }}</td>
|
||||
<td>{{ \App\Support\CourierBills\Category::RESOLUTIONS[$line->resolution] ?? '' }}{{ $line->resolved_by ? ' · ' . $line->resolved_by : '' }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
@empty
|
||||
<tr><td colspan="13" class="cbr-empty">这一类没有明细。</td></tr>
|
||||
<tr><td colspan="14" class="cbr-empty">这一类没有明细。</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@ -68,10 +68,10 @@ $feedbackPageFor = function (string $waybill) use ($dfCurrentDisputes): int {
|
||||
<nav class="cbr-tabs" aria-label="按状态查看"><a data-cbr-tab href="{{ $pageUrl($base) }}" class="{{ $dfStatus===''?'is-active':'' }}">全部 {{ array_sum($s['counts']) }}</a><a data-cbr-tab href="{{ $pageUrl($base+['status'=>'attention']) }}" class="{{ $dfStatus==='attention'?'is-active':'' }}">要看的 {{ $s['attention'] }}</a><a data-cbr-tab href="{{ $pageUrl($base+['status'=>'disputed']) }}" class="{{ $dfStatus==='disputed'?'is-active':'' }}">厂家异议 {{ count($dfCurrentDisputes) }}</a>
|
||||
@foreach(\App\Support\DropshipFreight\DropshipReconciler::LABELS as $key=>$label)@if($s['counts'][$key])<a data-cbr-tab href="{{ $pageUrl($base+['status'=>$key]) }}" class="{{ $dfStatus===$key?'is-active':'' }}">{{ $label }} {{ $s['counts'][$key] }}</a>@endif@endforeach</nav>
|
||||
<nav class="cbr-tabs" aria-label="运费差异原因">@foreach(['weight_diff'=>'重量差','price_diff'=>'价格差','missing_weight'=>'重量待补充'] as $key=>$label)<a data-cbr-tab href="{{ $pageUrl($base+['status'=>$key]) }}" class="{{ $dfStatus===$key?'is-active':'' }}">{{ $label }} {{ $s['diff_counts'][$key] }}</a>@endforeach</nav>
|
||||
<p class="cbr-muted">重量差 = 厂家账单重量 − 我方计费重量(公斤)。运费有差时,重量相同归价格差;任一重量缺失归重量待补充。差异分类不改变结算金额。</p>
|
||||
<p class="cbr-muted">运费差 = 厂家运费 − 最终结算运费;重量差 = 厂家重量 − 结算重量(公斤)。按厂家较低运费结算时,结算重量也取厂家重量;厂家未提供重量则留空。上方差异原因仍按原核算值识别。</p>
|
||||
<section class="cbr-panel"><h3>逐单核算明细</h3><form method="GET" action="{{ $pageUrl() }}" class="cbr-form cbr-panel-body" data-cbr-filter><input type="hidden" name="df_view" value="factory"><input type="hidden" name="factory" value="{{ $dfFactory->id }}"><input type="hidden" name="month" value="{{ $month }}"><input type="hidden" name="status" value="{{ $dfStatus }}"><input name="q" value="{{ $dfSearch }}" placeholder="搜索快递单号" aria-label="搜索快递单号"><button>搜索</button></form>
|
||||
<div class="cbr-scroll"><table><thead><tr><th>快递单号</th><th>发货 / 快递</th><th class="num">厂家重量(kg)</th><th class="num">我方计费重量(kg)</th><th class="num">重量差(kg)</th><th class="num">厂家运费</th><th class="num">我方核算</th><th class="num">最终结算</th><th class="num">差额</th><th>分类 / 说明</th><th>厂家反馈</th></tr></thead><tbody>
|
||||
@forelse($dfLines as $r)<tr><td>{{ $r['waybill'] }}</td><td>{{ $r['ship_time'] }}<div class="cbr-muted">{{ $r['express'] }}</div></td>@foreach(['bill_weight','charge_weight','weight_diff'] as $weightKey)<td class="num">{{ $r[$weightKey]===null?'—':rtrim(rtrim(number_format($r[$weightKey],4,'.',''),'0'),'.') }}</td>@endforeach<td class="num">{{ $money($r['bill']) }}</td><td class="num">{{ $money($r['calc']) }}</td><td class="num">{{ $money($r['final']??$r['settle']) }}</td><td class="num cbr-diff">{{ $r['bill']===null?'':$money($r['bill']-(float)($r['final']??$r['settle'])) }}</td><td class="wrap">{{ $r['label'] }}@if($r['diff_kind'])<div class="cbr-muted">{{ ['weight_diff'=>'重量差','price_diff'=>'价格差','missing_weight'=>'重量待补充'][$r['diff_kind']] }}</div>@endif<div class="cbr-muted">{{ $r['note'] }}</div></td><td>@if(isset($dfDisputeMap[$r['waybill']]))<a data-cbr-tab href="{{ $pageUrl(array_merge($base, request()->query(), ['feedback_page' => $feedbackPageFor((string)$r['waybill'])])) }}#feedback-{{ md5($r['waybill']) }}">{{ isset($dfDisputeMap[$r['waybill']]['decision'])?'查看处理':'待处理异议' }}</a>@else<span class="cbr-muted">—</span>@endif</td></tr>@empty<tr><td colspan="11">当前筛选没有明细。</td></tr>@endforelse
|
||||
<div class="cbr-scroll"><table><thead><tr><th>快递单号</th><th>发货 / 快递</th><th class="num">厂家重量(kg)</th><th class="num">我方计费重量(kg)</th><th class="num">结算重量(kg)</th><th class="num">重量差(kg)</th><th class="num">厂家运费</th><th class="num">我方核算</th><th class="num">最终结算</th><th class="num">运费差</th><th>分类 / 说明</th><th>厂家反馈</th></tr></thead><tbody>
|
||||
@forelse($dfLines as $r)<tr><td>{{ $r['waybill'] }}</td><td>{{ $r['ship_time'] }}<div class="cbr-muted">{{ $r['express'] }}</div></td>@foreach(['bill_weight','charge_weight','settlement_weight','weight_diff'] as $weightKey)<td class="num">{{ $r[$weightKey]===null?'—':rtrim(rtrim(number_format($r[$weightKey],4,'.',''),'0'),'.') }}</td>@endforeach<td class="num">{{ $money($r['bill']) }}</td><td class="num">{{ $money($r['calc']) }}</td><td class="num">{{ $money($r['final']??$r['settle']) }}</td><td class="num cbr-diff">{{ $money($r['freight_diff']) }}</td><td class="wrap">{{ $r['label'] }}@if($r['diff_kind'])<div class="cbr-muted">{{ ['weight_diff'=>'重量差','price_diff'=>'价格差','missing_weight'=>'重量待补充'][$r['diff_kind']] }}</div>@endif<div class="cbr-muted">{{ $r['note'] }}</div></td><td>@if(isset($dfDisputeMap[$r['waybill']]))<a data-cbr-tab href="{{ $pageUrl(array_merge($base, request()->query(), ['feedback_page' => $feedbackPageFor((string)$r['waybill'])])) }}#feedback-{{ md5($r['waybill']) }}">{{ isset($dfDisputeMap[$r['waybill']]['decision'])?'查看处理':'待处理异议' }}</a>@else<span class="cbr-muted">—</span>@endif</td></tr>@empty<tr><td colspan="12">当前筛选没有明细。</td></tr>@endforelse
|
||||
</tbody></table></div><div class="cbr-pager">{{ $dfLines->links() }}</div></section>
|
||||
@if(($dfSurchargeSummary??collect())->isNotEmpty())<section class="cbr-panel"><h3>附加费核对</h3><div class="cbr-scroll"><table><thead><tr><th>项目</th><th>厂家金额</th><th>自算金额</th></tr></thead><tbody>@foreach($dfSurchargeSummary as $fee)<tr><td>{{ $fee->item }}</td><td>{{ $money($fee->bill) }}</td><td>{{ $money($fee->self) }}</td></tr>@endforeach</tbody></table></div></section>@endif
|
||||
@include('business.pages.courier-payables.partials.surcharge-matches',['surchargeRows'=>$dfSurchargeRows??null])
|
||||
|
||||
@ -317,7 +317,8 @@ final class CourierBillReconciliationTest extends FeatureTestCase
|
||||
$this->assertSame('13800000000', (string) $recon->getCell('C2')->getValue());
|
||||
$this->assertNotSame(DataType::TYPE_NUMERIC, $recon->getCell('C2')->getDataType());
|
||||
$this->assertSame('ZT001', (string) $recon->getCell('G2')->getValue()); // 快递单号(25 列里的第 4 列)
|
||||
$this->assertEquals(0, $recon->getCell('R2')->getValue()); // 运费差 = 10 − 核算 10,核算后新增结算列
|
||||
$freightDiffColumn = array_search('运费差', $header, true) + 1;
|
||||
$this->assertEquals(0, $recon->getCell([$freightDiffColumn, 2])->getValue()); // 运费差 = 快递金额 − 结算金额
|
||||
$book->disconnectWorksheets();
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,77 @@ use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class CourierSettlementRulesTest extends FeatureTestCase
|
||||
{
|
||||
public function test_final_settlement_weight_and_differences_are_used_by_pages_and_exports(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
$this->user->attachPermission(\App\Models\Auth\Permission::where('name', 'read-admin-panel')->firstOrFail());
|
||||
$this->loginAs()->withExceptionHandling();
|
||||
$db = CourierBillMatcher::db();
|
||||
$store = app(CourierBillStore::class);
|
||||
$group = $store->saveGroup(null, ['name' => '武进极兔', 'express_names' => ['武进极兔']]);
|
||||
$shipping = app(\App\Support\CourierBills\ShippingLookup::class)->connection();
|
||||
$cases = [['WTLOW0001', 8, 2, 10, 5, 2, 0, 0], ['WTHIGH0001', 12, 7, 10, 5, 5, 2, 2],
|
||||
['WTEQUAL0001', 10, 4, 10, 5, 5, -1, 0], ['WTMISSING0001', 8, null, 10, 5, null, null, 0],
|
||||
['WTZERO0001', 0, 0, 10, 5, 0, 0, 0]];
|
||||
$csv = "单号,运费,重量\n";
|
||||
foreach ($cases as $i => [$waybill, $bill, $weight, $calc, $charge]) {
|
||||
$shipping->table('jst_oms_shipping')->insert(['source_id' => $i + 1, 'express_no' => $waybill,
|
||||
'express_name1' => '武进极兔', 'ship_time' => '2026-11-03 09:00:00']);
|
||||
$shipping->table('jst_oms_shipping_freight')->insert(['source_id' => $i + 1, 'status' => 'OK', 'freight' => $calc, 'charge_weight' => $charge]);
|
||||
$csv .= "$waybill,$bill,$weight\n";
|
||||
}
|
||||
$file = $store->upload([\Illuminate\Http\UploadedFile::fake()->createWithContent('武进极兔.csv', $csv)], '2026-11', [], '测试')[0];
|
||||
$id = (int) $db->table('courier_bill_files')->where('id', $file)->value('statement_id');
|
||||
$before = $db->table('courier_bill_lines')->where('statement_id', $id)->orderBy('id')->get()->toJson();
|
||||
$path = tempnam(sys_get_temp_dir(), 'settlement-weight');
|
||||
$out = fopen($path, 'wb');
|
||||
try { app(StatementExporter::class)->export($id, $out); } finally { fclose($out); }
|
||||
try {
|
||||
$book = IOFactory::load($path);
|
||||
$grid = $book->getSheetByName('对账')->toArray(null, false, false);
|
||||
$headers = array_shift($grid);
|
||||
$rows = collect($grid)->keyBy(fn ($row) => $row[array_search('快递单号', $headers, true)]);
|
||||
foreach ($cases as [$waybill, $bill, $weight, $calc, $charge, $expectedWeight, $expectedWeightDiff, $expectedFreightDiff]) {
|
||||
$row = $rows[$waybill];
|
||||
$expectedWeight === null ? $this->assertNull($row[array_search('结算重量', $headers, true)])
|
||||
: $this->assertEquals($expectedWeight, $row[array_search('结算重量', $headers, true)]);
|
||||
$expectedWeightDiff === null ? $this->assertNull($row[array_search('重量差', $headers, true)])
|
||||
: $this->assertEquals($expectedWeightDiff, $row[array_search('重量差', $headers, true)]);
|
||||
$this->assertEquals($expectedFreightDiff, $row[array_search('运费差', $headers, true)]);
|
||||
$this->assertEquals($charge, $row[array_search('计费重量', $headers, true)]);
|
||||
$this->assertEquals($calc, $row[array_search('核算运费', $headers, true)]);
|
||||
}
|
||||
$book->disconnectWorksheets();
|
||||
} finally { @unlink($path); }
|
||||
foreach (['courier-payables', 'courier-payables-final'] as $section) {
|
||||
$this->get(route('business.pages.show', ['section' => $section, 'page' => 'courier-bill-reconciliation',
|
||||
'cb_view' => 'statement', 'statement' => $id, 'month' => '2026-11']))->assertOk()->assertSeeText('结算重量');
|
||||
$query = ['cb_view' => 'details', 'month' => '2026-11', 'group_id' => $group, 'resolution' => 'all'];
|
||||
$this->get(route('business.pages.show', ['section' => $section, 'page' => 'courier-bill-reconciliation', ...$query]))
|
||||
->assertOk()->assertSeeText('结算重量')->assertSeeText('重量差');
|
||||
$response = $this->get(route("business.$section.courier-bills.export-details", $query))->assertOk();
|
||||
file_put_contents($path, $response->streamedContent());
|
||||
try {
|
||||
$book = IOFactory::load($path);$grid = $book->getActiveSheet()->toArray(null, false, false);$headers = array_shift($grid);
|
||||
$low = collect($grid)->first(fn ($row) => $row[array_search('快递单号', $headers, true)] === 'WTLOW0001');
|
||||
$this->assertEquals(2, $low[array_search('结算重量', $headers, true)]);
|
||||
$this->assertEquals(0, $low[array_search('重量差', $headers, true)]);
|
||||
$this->assertEquals(0, $low[array_search('运费差', $headers, true)]);
|
||||
$book->disconnectWorksheets();
|
||||
} finally { @unlink($path); }
|
||||
}
|
||||
$this->assertSame($before, $db->table('courier_bill_lines')->where('statement_id', $id)->orderBy('id')->get()->toJson());
|
||||
foreach (['中铁物流', '武进安能'] as $name) {
|
||||
$line = (object) ['bill_amount'=>8, 'bill_weight'=>2, 'calc_freight'=>10, 'charge_weight'=>5,
|
||||
'self_amount'=>CourierBillMatcher::selfAmount(Category::DIFF,10,8,null,$name), 'category'=>Category::DIFF, 'resolution'=>null, 'express_name'=>$name];
|
||||
$this->assertSame(['settlement_weight'=>5.0,'weight_diff'=>-3.0,'freight_diff'=>-2.0], \App\Support\CourierBills\SettlementComparison::courier($line));
|
||||
}
|
||||
$line->resolution = 'agree'; $line->self_amount = 8;
|
||||
$this->assertSame(['settlement_weight'=>2.0,'weight_diff'=>0.0,'freight_diff'=>0.0], \App\Support\CourierBills\SettlementComparison::courier($line));
|
||||
$line->resolution = 'exclude'; $line->self_amount = 0;
|
||||
$this->assertSame(['settlement_weight'=>0.0,'weight_diff'=>2.0,'freight_diff'=>8.0], \App\Support\CourierBills\SettlementComparison::courier($line));
|
||||
}
|
||||
|
||||
public function test_freight_settlement_caps_at_billed_amount_but_keeps_missing_values_and_manual_decisions(): void
|
||||
{
|
||||
foreach ([Category::MATCH, Category::DIFF, Category::UNCALCULATED, Category::PRIOR] as $category) {
|
||||
|
||||
@ -12,6 +12,37 @@ use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class DropshipWeightTest extends FeatureTestCase
|
||||
{
|
||||
public function test_lower_freight_also_uses_billed_weight_without_overwriting_original_calculation(): void
|
||||
{
|
||||
Storage::fake('local');$store=app(DropshipFreightStore::class);$shipping=app(ShippingLookup::class)->connection();
|
||||
$id=$store->saveFactory(null,['name'=>'重量测试','warehouse'=>'测试代发仓','keywords'=>'测试']);
|
||||
$file=$store->upload([UploadedFile::fake()->createWithContent('重量测试.csv',"单号,运费,重量\nWTLOW0001,8,2\nWTMISSING0001,8,\nWTHIGH0001,12,7\n")], '2026-11', '测试')[0];
|
||||
foreach(['WTLOW0001','WTMISSING0001','WTHIGH0001'] as $i=>$no){
|
||||
$shipping->table('jst_oms_shipping')->insert(['source_id'=>$i+1,'express_no'=>$no,'express_name1'=>'测试快递','warehouse_name'=>'测试代发仓','ship_time'=>'2026-11-03 09:00:00']);
|
||||
$shipping->table('jst_oms_shipping_freight')->insert(['source_id'=>$i+1,'status'=>'OK','freight'=>10,'charge_weight'=>5]);
|
||||
}
|
||||
$factory=collect($store->factories())->firstWhere('id',$id);$result=app(DropshipReconciler::class)->factoryMonth($factory,'2026-11');
|
||||
$rows=collect($result['rows'])->keyBy('waybill');
|
||||
$this->assertEquals([10,5,8,2,0,0],array_map(fn($key)=>$rows['WTLOW0001'][$key],['calc','charge_weight','final','settlement_weight','weight_diff','freight_diff']));
|
||||
$this->assertNull($rows['WTMISSING0001']['settlement_weight']);$this->assertNull($rows['WTMISSING0001']['weight_diff']);
|
||||
$this->assertEquals([10,5,2,2],array_map(fn($key)=>$rows['WTHIGH0001'][$key],['final','settlement_weight','weight_diff','freight_diff']));
|
||||
$this->assertEquals(26,$result['summary']['settle']);
|
||||
$path=tempnam(sys_get_temp_dir(),'drop-weight');$out=fopen($path,'wb');
|
||||
try{app(DropshipExporter::class)->export($factory,'2026-11',$out);}finally{fclose($out);}
|
||||
try{
|
||||
$book=IOFactory::load($path);$grid=$book->getSheetByName('对账')->toArray(null,false,false);$headers=array_shift($grid);
|
||||
$low=collect($grid)->first(fn($row)=>$row[array_search('快递单号',$headers,true)]==='WTLOW0001');
|
||||
$this->assertEquals(2,$low[array_search('结算重量',$headers,true)]);
|
||||
$this->assertEquals(0,$low[array_search('重量差',$headers,true)]);
|
||||
$this->assertEquals(0,$low[array_search('运费差',$headers,true)]);
|
||||
$book->disconnectWorksheets();
|
||||
}finally{@unlink($path);}
|
||||
$this->user->attachPermission(\App\Models\Auth\Permission::where('name','read-admin-panel')->firstOrFail());$this->loginAs();
|
||||
$this->get(route('business.pages.show',['section'=>'courier-payables','page'=>DropshipFreightController::PAGE,'df_view'=>'factory','factory'=>$id,'month'=>'2026-11']))
|
||||
->assertOk()->assertSeeText('结算重量(kg)')->assertSeeText('运费差');
|
||||
$this->assertEquals(28,$store->db()->table('dropship_bill_lines')->where('file_id',$file)->sum('amount'));
|
||||
}
|
||||
|
||||
public function test_parser_sums_weight_without_treating_partial_missing_as_zero_or_reading_system_weight(): void
|
||||
{
|
||||
$path = tempnam(sys_get_temp_dir(), 'weight') . '.csv';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user