diff --git a/app/Business/KukaPostingReconciliation/KukaReconciliationPageData.php b/app/Business/KukaPostingReconciliation/KukaReconciliationPageData.php index aea1ebdb..e5f4f392 100644 --- a/app/Business/KukaPostingReconciliation/KukaReconciliationPageData.php +++ b/app/Business/KukaPostingReconciliation/KukaReconciliationPageData.php @@ -35,6 +35,10 @@ class KukaReconciliationPageData private const INVOICE_MOBILE = '15061959991'; + private const INVENTORY_ELS_ACCOUNT = '435421'; + + private const INVENTORY_ELS_NAME = '常州欧伯娜家居有限公司'; + private const INVENTORY_SAP_CODE = 'OA01207289'; private const VIRTUAL_SUPPLIER_NAME = '欧伯娜'; @@ -141,7 +145,6 @@ class KukaReconciliationPageData $shippingLookup = $this->loadShippingLookup($sourceRows); $lineItems = []; $posting = []; - $inventory = []; $orders = []; $postingQuantityTotal = '0'; $postingSupplierAmountTotal = '0.00'; @@ -312,31 +315,11 @@ class KukaReconciliationPageData ); } - if (! isset($inventory[$materialNumber])) { - $inventory[$materialNumber] = [ - 'year' => $item['year'], - 'month' => $item['month'], - 'supplier_account' => $supplier['account'], - 'supplier_name' => $supplierName, - 'material_number' => $materialNumber, - 'description' => $description, - 'quantity' => '0', - 'material_name' => $productName, - 'model_spec' => $item['model_spec'], - 'item_number' => $item['item_number'], - 'salesperson' => $item['salesperson'], - ]; - } - $inventory[$materialNumber]['quantity'] = $this->addDecimal( - $inventory[$materialNumber]['quantity'], - $quantity, - ); $supplierAmountTotal = $this->addMoney($supplierAmountTotal, $supplierAmount); $salesAmountTotal = $this->addMoney($salesAmountTotal, $salesAmount); } ksort($posting, SORT_NATURAL); - ksort($inventory, SORT_NATURAL); $generatedAt = now()->format('Y-m-d H:i:s'); $postingSalesAmountTotal = $this->divideMoney( $postingSupplierAmountTotal, @@ -356,39 +339,10 @@ class KukaReconciliationPageData $row['unit_price'], $row['supplier_amount'], ], array_values($posting)); - $inventoryRows = array_map(fn (array $row): array => [ - $row['year'], - $row['month'], - $row['supplier_account'], - self::INVENTORY_SAP_CODE, - $row['supplier_name'], - $row['material_number'], - $row['description'], - $this->formatQuantity($row['quantity']), - $this->formatQuantity($row['quantity']), - '', - '', - '', - '', - '', - '', - '', - $row['material_name'], - $row['model_spec'], - $row['item_number'], - $row['material_name'], - '', - '', - $row['salesperson'], - '', - '', - $generatedAt, - $this->formatQuantity($row['quantity']), - $this->formatQuantity($row['quantity']), - ], array_values($inventory)); $virtualRows = $this->virtualRows($lineItems, $generatedAt); $erpRecipients = $this->loadErpRecipients($companyId); $erpRows = $this->erpRows($virtualRows, $generatedAt, $erpRecipients); + $inventoryRows = $this->inventoryRows($virtualRows, $generatedAt); $invoiceRows = $this->invoiceRows($virtualRows); $invoiceQuantityTotal = '0'; $invoiceAmountTotal = '0.00'; @@ -509,6 +463,44 @@ class KukaReconciliationPageData return $rows; } + /** + * @param list> $virtualRows + * @return list> + */ + private function inventoryRows(array $virtualRows, string $generatedAt): array + { + return array_map(fn (array $row): array => [ + $row[0], + $row[1], + self::INVENTORY_ELS_ACCOUNT, + self::INVENTORY_SAP_CODE, + self::INVENTORY_ELS_NAME, + $row[3], + $row[4], + $row[5], + $row[5], + '', + '', + '', + '', + '', + '', + '', + $row[4], + '', + '', + '', + '', + '', + '', + '', + '', + $generatedAt, + $row[5], + '', + ], array_values($virtualRows)); + } + /** * @param list> $virtualRows * @param list $recipients diff --git a/resources/views/business/pages/posting-data/kuka-reconciliation.blade.php b/resources/views/business/pages/posting-data/kuka-reconciliation.blade.php index f9050cc6..c718922e 100644 --- a/resources/views/business/pages/posting-data/kuka-reconciliation.blade.php +++ b/resources/views/business/pages/posting-data/kuka-reconciliation.blade.php @@ -105,7 +105,7 @@ 'slug' => 'inventory-management-template', 'title' => '库存管理模板', 'icon' => 'warehouse', - 'description' => '已按工作簿4“库存管理模版”子表的双行表头放入字段和接口编码。', + 'description' => '按灵珊虚拟过账生成库存管理模板,仅填写指定库存字段。', 'source_sheet' => '库存管理模版', 'numeric_columns' => [7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 26, 27], 'headers' => $pairedHeaders( diff --git a/tests/Unit/Business/KukaReconciliationPageDataTest.php b/tests/Unit/Business/KukaReconciliationPageDataTest.php index f4f4847c..acde871d 100644 --- a/tests/Unit/Business/KukaReconciliationPageDataTest.php +++ b/tests/Unit/Business/KukaReconciliationPageDataTest.php @@ -295,13 +295,40 @@ class KukaReconciliationPageDataTest extends TestCase $this->assertSame('yuechenna@dingtalk.com', $invoice[18]); $this->assertSame('15061959991', $invoice[19]); - $inventory = $data['views']['inventory-management-template']['rows'][0]; - $this->assertSame('435421', $inventory[2]); - $this->assertSame('OA01207289', $inventory[3]); - $this->assertSame('M-1', $inventory[5]); - $this->assertSame('3', $inventory[7]); - $this->assertSame('3', $inventory[8]); - $this->assertSame('3', $inventory[27]); + $this->assertSame( + $data['views']['lingshan-virtual-posting']['total'], + $data['views']['inventory-management-template']['total'], + ); + $this->assertSame([ + '2026', + '10', + '435421', + 'OA01207289', + '常州欧伯娜家居有限公司', + 'M-1', + '测试物料', + '2', + '2', + '', + '', + '', + '', + '', + '', + '', + '测试物料', + '', + '', + '', + '', + '', + '', + '', + '', + $data['generated_at'], + '2', + '', + ], $data['views']['inventory-management-template']['rows'][0]); } public function test_virtual_sales_summary_uses_total_supplier_amount(): void @@ -407,6 +434,41 @@ class KukaReconciliationPageDataTest extends TestCase } } + public function test_inventory_template_maps_every_virtual_row_without_aggregation(): void + { + $connection = DB::connection('business_mirror'); + $connection->table('kuka_posting_base_imports')->insert([ + 'company_id' => 1, + 'period' => '2026-10', + 'completed_at' => '2026-11-01 08:00:00', + ]); + $this->insertBaseRow(2, $this->payload('O-1', 'P-1', 'S-1', 'I-1', 'M-1', '1', '10.00')); + $this->insertBaseRow(3, $this->payload('O-2', 'P-1', 'S-1', 'I-1', 'M-1', '2', '10.00')); + + $data = app(KukaReconciliationPageData::class)->build( + Request::create('/', 'GET', ['period' => '2026-10']), + 1, + ); + + $virtualRows = $data['views']['lingshan-virtual-posting']['rows']; + $inventoryRows = $data['views']['inventory-management-template']['rows']; + $this->assertCount(2, $virtualRows); + $this->assertCount(2, $inventoryRows); + $this->assertSame(['M-1', 'M-1'], array_column($inventoryRows, 5)); + $this->assertSame(['1', '2'], array_column($inventoryRows, 7)); + $this->assertSame(['1', '2'], array_column($inventoryRows, 8)); + $this->assertSame(['1', '2'], array_column($inventoryRows, 26)); + $this->assertSame([$data['generated_at'], $data['generated_at']], array_column($inventoryRows, 25)); + foreach ($inventoryRows as $row) { + $this->assertSame('常州欧伯娜家居有限公司', $row[4]); + $this->assertSame('测试物料', $row[6]); + $this->assertSame('测试物料', $row[16]); + foreach ([9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 27] as $column) { + $this->assertSame('', $row[$column]); + } + } + } + public function test_posting_export_returns_every_material_row_without_pagination(): void { $connection = DB::connection('business_mirror');