售后金额
This commit is contained in:
@@ -14,7 +14,7 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
/**
|
||||
* 门店账单合并导出:勾选账单跨账单按商品合并明细(可按一级分类过滤),
|
||||
* 表尾汇总商品金额/配送费/附加金额/总金额
|
||||
* 表尾汇总商品金额/配送费/附加金额/售后金额/总金额
|
||||
*/
|
||||
class BillExport implements FromCollection, WithStyles
|
||||
{
|
||||
@@ -113,18 +113,20 @@ class BillExport implements FromCollection, WithStyles
|
||||
$rows[] = ['', '合计', '', '', '', $totalQuantity, (float) $totalWeight, (float) $totalAmount];
|
||||
$this->specialRows[++$rowIndex] = 'summary';
|
||||
|
||||
// 配送费/附加金额/总金额(账单级费用全额汇总,不受分类过滤影响)
|
||||
// 配送费/附加金额/售后金额/总金额(账单级费用全额汇总,不受分类过滤影响)
|
||||
$deliveryTotal = '0';
|
||||
$addedTotal = '0';
|
||||
$afterSaleTotal = '0';
|
||||
$boxNum = 0;
|
||||
$trayNum = 0;
|
||||
foreach ($this->bills as $bill) {
|
||||
$deliveryTotal = bcadd($deliveryTotal, (string) $bill->delivery_fee, 2);
|
||||
$addedTotal = bcadd($addedTotal, (string) $bill->added_amount, 2);
|
||||
$afterSaleTotal = bcadd($afterSaleTotal, (string) $bill->after_sale, 2);
|
||||
$boxNum += (int) $bill->box_num;
|
||||
$trayNum += (int) $bill->tray_num;
|
||||
}
|
||||
$grandTotal = bcadd(bcadd($totalAmount, $deliveryTotal, 2), $addedTotal, 2);
|
||||
$grandTotal = bcadd(bcadd(bcadd($totalAmount, $deliveryTotal, 2), $addedTotal, 2), $afterSaleTotal, 2);
|
||||
|
||||
$rows[] = ['配送费合计', '', '', '', '', '', '', (float) $deliveryTotal];
|
||||
$this->specialRows[++$rowIndex] = 'summary';
|
||||
@@ -134,7 +136,11 @@ class BillExport implements FromCollection, WithStyles
|
||||
$this->specialRows[++$rowIndex] = 'summary';
|
||||
$this->mergeRows[] = $rowIndex;
|
||||
|
||||
$rows[] = ['总金额(商品金额+配送费+附加金额)', '', '', '', '', '', '', (float) $grandTotal];
|
||||
$rows[] = ['售后金额合计(可正负)', '', '', '', '', '', '', (float) $afterSaleTotal];
|
||||
$this->specialRows[++$rowIndex] = 'summary';
|
||||
$this->mergeRows[] = $rowIndex;
|
||||
|
||||
$rows[] = ['总金额(商品金额+配送费+附加金额+售后金额)', '', '', '', '', '', '', (float) $grandTotal];
|
||||
$this->specialRows[++$rowIndex] = 'grand';
|
||||
$this->mergeRows[] = $rowIndex;
|
||||
|
||||
|
||||
@@ -174,6 +174,7 @@ class BillController extends BaseMiniController
|
||||
'box_price' => $bill->box_price,
|
||||
'tray_price' => $bill->tray_price,
|
||||
'added_amount' => $bill->added_amount,
|
||||
'after_sale' => $bill->after_sale,
|
||||
'total_amount' => $bill->total_amount,
|
||||
'status' => $bill->status,
|
||||
'status_name' => BillModel::STATUS_NAMES[$bill->status] ?? '',
|
||||
|
||||
@@ -145,6 +145,7 @@ class CartController extends BaseMiniController
|
||||
'name' => $product->name ?? '',
|
||||
'spec' => $product->spec ?? '',
|
||||
'unit' => $product->unit ?? '',
|
||||
'price_unit' => $product->price_unit ?? '',
|
||||
'image' => $firstFile?->file_url ?? '',
|
||||
'price' => $price,
|
||||
'quantity' => $quantity,
|
||||
|
||||
@@ -97,6 +97,7 @@ class OrderController extends BaseMiniController
|
||||
'product_spec' => $product->spec,
|
||||
'unit' => (string) $product->unit,
|
||||
'price' => $price,
|
||||
'price_unit' => $product->price_unit,
|
||||
'image_ids' => implode(',', (array) $product->image_ids),
|
||||
'content' => (string) $product->content,
|
||||
'shelf_life' => (int) $product->shelf_life,
|
||||
|
||||
@@ -152,7 +152,7 @@ class PaymentController extends BaseMiniController
|
||||
|
||||
$bills = $payment->bills()
|
||||
->orderBy('id')
|
||||
->get(['id', 'bill_no', 'bill_date', 'product_amount', 'delivery_fee', 'added_amount', 'total_amount', 'status'])
|
||||
->get(['id', 'bill_no', 'bill_date', 'product_amount', 'delivery_fee', 'added_amount', 'after_sale', 'total_amount', 'status'])
|
||||
->toArray();
|
||||
|
||||
$data = $payment->toArray();
|
||||
|
||||
@@ -56,7 +56,7 @@ class PaymentController extends BaseController
|
||||
|
||||
$bills = $payment->bills()
|
||||
->orderBy('id')
|
||||
->get(['id', 'bill_no', 'bill_date', 'product_amount', 'delivery_fee', 'added_amount', 'total_amount', 'status'])
|
||||
->get(['id', 'bill_no', 'bill_date', 'product_amount', 'delivery_fee', 'added_amount', 'after_sale', 'total_amount', 'status'])
|
||||
->toArray();
|
||||
|
||||
$data = $payment->toArray();
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace App\Http\Requests\Purchase;
|
||||
use Modules\Common\Http\Requests\BaseFormRequest;
|
||||
|
||||
/**
|
||||
* 采购单生成账单 验证(按门店提交配送费/周转筐/托盘数量与售后/备注,金额由系统汇总不可修改;
|
||||
* 筐/托盘数量正数=压筐附加金额,负数=回筐抵扣金额)
|
||||
* 采购单生成账单 验证(按门店提交配送费/周转筐/托盘数量与售后金额/备注,金额由系统汇总不可修改;
|
||||
* 筐/托盘数量正数=压筐附加金额,负数=回筐抵扣金额;售后金额可正负,计入总金额)
|
||||
*/
|
||||
class PurchaseBillGenerateRequest extends BaseFormRequest
|
||||
{
|
||||
@@ -20,7 +20,7 @@ class PurchaseBillGenerateRequest extends BaseFormRequest
|
||||
'stores.*.delivery_fee' => 'required|numeric|min:0',
|
||||
'stores.*.box_num' => 'required|integer',
|
||||
'stores.*.tray_num' => 'required|integer',
|
||||
'stores.*.after_sale' => 'nullable|string|max:255',
|
||||
'stores.*.after_sale' => 'nullable|numeric',
|
||||
'stores.*.remark' => 'nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
@@ -41,7 +41,7 @@ class PurchaseBillGenerateRequest extends BaseFormRequest
|
||||
'stores.*.box_num.integer' => '周转筐数量必须为整数(正数=压筐,负数=回筐)',
|
||||
'stores.*.tray_num.required' => '周转托盘数量不能为空',
|
||||
'stores.*.tray_num.integer' => '周转托盘数量必须为整数(正数=压筐,负数=回筐)',
|
||||
'stores.*.after_sale.max' => '售后说明最长 255 个字符',
|
||||
'stores.*.after_sale.numeric' => '售后金额格式错误(可正负)',
|
||||
'stores.*.remark.max' => '备注最长 255 个字符',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ class BillModel extends Model
|
||||
'tray_price' => 'decimal:2',
|
||||
'added_amount' => 'decimal:2',
|
||||
'total_amount' => 'decimal:2',
|
||||
'after_sale' => 'decimal:2',
|
||||
'status' => 'integer',
|
||||
'payment_id' => 'integer',
|
||||
'paid_at' => 'datetime:Y-m-d H:i:s',
|
||||
|
||||
@@ -30,6 +30,7 @@ class StoreOrderItemModel extends Model
|
||||
'product_spec',
|
||||
'unit',
|
||||
'price',
|
||||
'price_unit',
|
||||
'image_ids',
|
||||
'content',
|
||||
'shelf_life',
|
||||
|
||||
@@ -20,8 +20,9 @@ use Throwable;
|
||||
* 2. 商品金额 = 门店订单商品金额汇总(快照,生成后不可修改)
|
||||
* 3. 附加金额 = 周转筐数量×筐单价 + 托盘数量×托盘单价(单价取站点配置快照;
|
||||
* 数量正数=压筐附加金额,负数=回筐抵扣金额)
|
||||
* 4. 总金额 = 商品金额 + 配送费 + 附加金额;回写门店订单 bill_id 完成关联,订单状态置为已完成
|
||||
* 5. 压回筐记录:筐/托盘数量非 0 时写入完整快照(数量/单价/金额均可为负)
|
||||
* 4. 售后金额 = 按门店填写的调整金额(可正负:正数=加收,负数=售后减免)
|
||||
* 5. 总金额 = 商品金额 + 配送费 + 附加金额 + 售后金额;回写门店订单 bill_id 完成关联,订单状态置为已完成
|
||||
* 6. 压回筐记录:筐/托盘数量非 0 时写入完整快照(数量/单价/金额均可为负)
|
||||
*/
|
||||
readonly class BillGenerateService
|
||||
{
|
||||
@@ -31,7 +32,7 @@ readonly class BillGenerateService
|
||||
|
||||
/**
|
||||
* @param PurchaseOrderModel $purchase 已完成采购单
|
||||
* @param array<int, array{store_id: int, delivery_fee: string, box_num: int, tray_num: int, after_sale?: string, remark?: string}> $stores 按门店提交的配送费/周转筐/托盘数量与售后/备注
|
||||
* @param array<int, array{store_id: int, delivery_fee: string, box_num: int, tray_num: int, after_sale?: string|int|float, remark?: string}> $stores 按门店提交的配送费/周转筐/托盘数量与售后金额/备注
|
||||
* @param int $operatorId 生成人(后台系统用户ID)
|
||||
* @return BillModel[] 生成的账单列表
|
||||
* @throws Throwable
|
||||
@@ -95,7 +96,8 @@ readonly class BillGenerateService
|
||||
bcmul((string) (int) $row['tray_num'], $trayPrice, 2),
|
||||
2
|
||||
);
|
||||
$totalAmount = bcadd(bcadd($productAmount, $deliveryFee, 2), $addedAmount, 2);
|
||||
$afterSale = bcadd((string) ($row['after_sale'] ?? '0'), '0', 2);
|
||||
$totalAmount = bcadd(bcadd(bcadd($productAmount, $deliveryFee, 2), $addedAmount, 2), $afterSale, 2);
|
||||
|
||||
$bill = BillModel::create([
|
||||
'bill_no' => $this->billNumberService->make('ZD'),
|
||||
@@ -111,7 +113,7 @@ readonly class BillGenerateService
|
||||
'added_amount' => $addedAmount,
|
||||
'total_amount' => $totalAmount,
|
||||
'operator_id' => $operatorId,
|
||||
'after_sale' => (string) ($row['after_sale'] ?? ''),
|
||||
'after_sale' => $afterSale,
|
||||
'remark' => (string) ($row['remark'] ?? ''),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user