修改计å¤备货单金额计算&&采购单编写â€

This commit is contained in:
mzl
2025-09-22 01:55:34 +00:00
parent 20e3ce3b27
commit e12d5951e4
14 changed files with 745 additions and 34 deletions
+238 -4
View File
@@ -160,7 +160,7 @@ class StockOrdersService
$config['with'][] = 'moneyValues';
$config['with'][] = 'salesperson';
$item = $this->logicShow($config);
$pdfData = $this->pdfData($item);
$pdfData = $this->formatData($item);
// 渲染模板为最终HTML
$tplPath = app_path('common/utils/pdf/template/stockOrder.stub');
@@ -200,7 +200,7 @@ class StockOrdersService
return $res;
}
public function pdfData($item)
public function pdfData2($item)
{
$vehList = [];
$index = 0;
@@ -375,8 +375,8 @@ class StockOrdersService
{
$config = $this->buildQueryConfig($request, 'detail');
$item = $this->logicShow($config);
$pdfData = $this->pdfData($item);
return $this->postProcess('Detail', $pdfData);
$detail = $this->formatData($item);
return $this->postProcess('Detail', $detail);
}
/**
@@ -739,4 +739,238 @@ class StockOrdersService
StockOrderAccounts::create($account);
}
}
// ====== ======= ====== ======= ====== 信息处理 ======= ====== ======= ====== =======
// PDF数据
public function formatData($item)
{
// 提取车辆列表信息
$vehListData = $this->prepareVehicleListData($item);
// 提取订单金额信息
$moneyValues = $this->prepareOrderMoneyValues($item);
// 提取账户列表信息
$accountList = $this->prepareAccountList($item);
// 构建返回数据
$veh = [
// 基本信息
'order_no' => $item->order_no,
'salesperson_snapshot' => $item->salesperson_snapshot,
'sign_img_url' => $this->getSignatureImageUrl($item->salesperson->sign_img ?? null),
'created_at' => date('Y-m-d', strtotime($item->created_at)),
'pi_no' => $item->pi_no,
'biz_date' => date('Y-m-d', $item->biz_date),
'clearance_country_snapshot' => $item->clearance_country_snapshot,
'customer_source_snapshot' => $item->customer_source_snapshot,
'customer_snapshot' => $item->customer_snapshot,
'customer_country_snapshot' => $item->customer_country_snapshot,
// 订单项
'veh_list' => array_values($vehListData['list']),
'contract_exchange_rate' => $item->contract_exchange_rate,
'cif_total_amount' => $moneyValues['cif_total_amount'] ?? [],
'profit_total' => $moneyValues['profit_total'] ?? [],
// 运输和交付信息
'declarant_name' => $item->declarant_name,
'eta_ship_date' => date('Y-m-d', $item->eta_ship_date),
'shipping_method_snapshot' => $item->shipping_method_snapshot,
'domestic_port_snapshot' => $item->domestic_port_snapshot,
'trade_term_snapshot' => $item->trade_term_snapshot,
'clearance_port_snapshot' => $item->clearance_port_snapshot,
'latest_arrival_date' => date('Y-m-d', $item->latest_arrival_date),
'pick_up_date' => date('Y-m-d', $item->pick_up_date),
'collect_all_date' => date('Y-m-d', $item->collect_all_date),
'is_final' => $item->is_final,
// 账户信息
'account_list' => $accountList,
'acc_index' => count($accountList) + 1,
'currency_symbol' => $item->settlement_currency,
'sign_imgs' => $this->queryAppro($item->id),
'contract_url' => $this->getContractUrl($item->contract ?? null)
];
return $veh;
}
/**
* 准备车辆列表数据
*/
private function prepareVehicleListData($item): array
{
$vehList = [];
$index = 0;
$currencyInfo = $this->getCurrencyInfo($item->settlement_currency);
foreach ($item->items as $v) {
// 如果已存在相同车辆,增加数量
if (isset($vehList[$v->unique_id])) {
$this->incrementVehicleCount($vehList[$v->unique_id], $currencyInfo);
continue;
}
$index++;
// 处理金额信息
$moneyValues = $this->processItemMoneyValues($v);
// 处理改装信息
$modificationText = $this->getModificationText($v->options);
// 计算单项利润
$itemProfit = $this->calculateProfit($moneyValues, $item);
// 构建车辆信息
$vehList[$v->unique_id] = [
'index' => $index,
'model_snapshot' => $v->model_snapshot,
'color_interior_snapshot' => $v->color_interior_snapshot,
'color_exterior_snapshot' => $v->color_exterior_snapshot,
'num' => 1,
'modify' => $modificationText,
'mileage' => $v->mileage
] + $moneyValues;
// 添加利润信息
$vehList[$v->unique_id]['profit'] = [
'currency' => $item->settlement_currency,
'amount' => $itemProfit,
'currency_info' => $currencyInfo['currency_symbol'] . number_format($itemProfit, 2, '.', ',')
];
}
return ['list' => $vehList];
}
/**
* 处理单项金额值
*/
private function processItemMoneyValues($item): array
{
$moneyValues = [];
foreach ($item->moneyValues as $money) {
$moneyValues[$money->field] = [
'currency' => $money->currency,
'amount' => $money->amount,
'rate' => $money->exchange_rate,
'currency_info' => $this->formatCurrency($money->amount, $money->currency)
];
}
return $moneyValues;
}
/**
* 获取改装文本
*/
private function getModificationText($options): string
{
$modificationText = '';
foreach ($options as $option) {
$modificationText .= $option->option_name_snapshot . ' ';
}
return trim($modificationText);
}
/**
* 增加车辆数量并更新相关金额显示
*/
private function incrementVehicleCount(array &$vehicleData, array $currencyInfo): void
{
$vehicleData['num'] += 1;
// 更新总价显示
if (isset($vehicleData['total_price']['amount'])) {
$totalAmount = $vehicleData['total_price']['amount'] * $vehicleData['num'];
$vehicleData['total_price']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($totalAmount, 2, '.', ',');
}
// 更新利润显示
if (isset($vehicleData['profit']['amount'])) {
$profitAmount = $vehicleData['profit']['amount'] * $vehicleData['num'];
$vehicleData['profit']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($profitAmount, 2, '.', ',');
}
}
/**
* 准备订单金额值
*/
private function prepareOrderMoneyValues($item): array
{
$moneyValues = [];
foreach ($item->moneyValues as $money) {
$moneyValues[$money->field] = [
'currency' => $money->currency,
'amount' => $money->amount,
'rate' => $money->exchange_rate,
'currency_info' => $this->formatCurrency($money->amount, $money->currency)
];
}
return $moneyValues;
}
/**
* 准备账户列表
*/
private function prepareAccountList($item): array
{
$accountList = [];
foreach ($item->accounts as $k => $account) {
$accountList[] = [
'index' => '收款' . ($k + 1),
'remit_country_name_snapshot' => $account->remit_country_name_snapshot,
'remit_date' => date('Y-m-d', $account->remit_date),
'currency_name_snapshot' => $account->currency_name_snapshot,
'account_name_snapshot' => $account->account_name_snapshot,
'remitter_name' => $account->remitter_name,
'amount' => $account->amount,
];
}
return $accountList;
}
/**
* 获取货币信息
*/
private function getCurrencyInfo(string $currencyCode): array
{
return SysCurrency::where('currency_code', $currencyCode)
->first(['currency_symbol', 'currency_name'])
->toArray();
}
/**
* 格式化货币显示
*/
private function formatCurrency(float $amount, string $currencyCode): string
{
$currencySymbol = SysCurrency::where('currency_code', $currencyCode)->value('currency_symbol');
return $currencySymbol . number_format($amount, 2, '.', ',');
}
/**
* 获取签名图片URL
*/
private function getSignatureImageUrl(?string $signImg): string
{
if (empty($signImg)) {
return '';
}
return (new \app\common\service\OssService)->generatePrivateUrl($signImg);
}
/**
* 获取合同URL
*/
private function getContractUrl(?string $contract): string
{
if (empty($contract)) {
return '';
}
return (new \app\common\service\OssService)->generatePrivateUrl($contract);
}
}