fix(商品月加权平均单价): 排除指定商品编码 (#1342)
This commit is contained in:
parent
4041e7351d
commit
5bdee2bd8f
@ -119,6 +119,12 @@ class Pages extends Controller
|
||||
|
||||
private const RAW_BOARD_SOURCE = 'jiansun';
|
||||
|
||||
/** 商品月加权平均单价中固定排除的完整商品编码。 */
|
||||
private const MONTHLY_WEIGHTED_EXCLUDED_PRODUCT_CODES = [
|
||||
'TY-ZPLS',
|
||||
'XF001-JX',
|
||||
];
|
||||
|
||||
/**
|
||||
* 「终版」目录只提供空的表结构,数据由各自按表导入,不解析其他目录的既有页面内容。
|
||||
*/
|
||||
@ -1521,6 +1527,14 @@ class Pages extends Controller
|
||||
/**
|
||||
* 商品月加权平均单价:读取已计算的月份数据,默认最新月份。
|
||||
*/
|
||||
private function applyMonthlyWeightedAverageVisibilityFilters($query): void
|
||||
{
|
||||
$query->where('warehouse_short_name', 'not like', '配件-%')
|
||||
// 商品编码以「-数字」结尾时整行不展示。
|
||||
->whereRaw('product_code NOT REGEXP ?', ['-[0-9]+$'])
|
||||
->whereNotIn('product_code', self::MONTHLY_WEIGHTED_EXCLUDED_PRODUCT_CODES);
|
||||
}
|
||||
|
||||
protected function monthlyWeightedAveragePriceRows(): LengthAwarePaginator
|
||||
{
|
||||
$connection = (string) config('upstream_mirrors.connection', 'business_mirror');
|
||||
@ -1550,9 +1564,8 @@ class Pages extends Controller
|
||||
}
|
||||
|
||||
$query = DB::connection($connection)->table('product_monthly_weighted_average_rows')
|
||||
->where('report_month', $month)
|
||||
// 配件仓不纳入商品月加权平均单价展示。
|
||||
->where('warehouse_short_name', 'not like', '配件-%');
|
||||
->where('report_month', $month);
|
||||
$this->applyMonthlyWeightedAverageVisibilityFilters($query);
|
||||
$productCode = trim((string) request('product_code', ''));
|
||||
if ($productCode !== '') {
|
||||
// 与进销存总表一致:商品编码按精确查询。
|
||||
@ -4064,9 +4077,8 @@ class Pages extends Controller
|
||||
}
|
||||
$month = $requested !== '' ? $requested : ($months[0] ?? null);
|
||||
|
||||
$query = DB::connection($connection)->table('product_monthly_weighted_average_rows')
|
||||
// 与页面一致,配件仓不纳入商品月加权平均单价导出。
|
||||
->where('warehouse_short_name', 'not like', '配件-%');
|
||||
$query = DB::connection($connection)->table('product_monthly_weighted_average_rows');
|
||||
$this->applyMonthlyWeightedAverageVisibilityFilters($query);
|
||||
if ($month !== null) {
|
||||
$query->where('report_month', $month);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\Feature\FeatureTestCase;
|
||||
|
||||
class MonthlyWeightedAveragePriceWarehouseFilterTest extends FeatureTestCase
|
||||
class MonthlyWeightedAveragePriceVisibilityFilterTest extends FeatureTestCase
|
||||
{
|
||||
private string $connection = 'monthly_weighted_average_fixture';
|
||||
|
||||
@ -25,6 +25,11 @@ class MonthlyWeightedAveragePriceWarehouseFilterTest extends FeatureTestCase
|
||||
'upstream_mirrors.connection' => $this->connection,
|
||||
]);
|
||||
DB::purge($this->connection);
|
||||
DB::connection($this->connection)->getPdo()->sqliteCreateFunction(
|
||||
'regexp',
|
||||
static fn (string $pattern, string $value): int => preg_match('~' . $pattern . '~u', $value),
|
||||
2,
|
||||
);
|
||||
|
||||
Schema::connection($this->connection)->create(
|
||||
'product_monthly_weighted_average_states',
|
||||
@ -67,10 +72,15 @@ class MonthlyWeightedAveragePriceWarehouseFilterTest extends FeatureTestCase
|
||||
->insert([
|
||||
$this->row('normal', '销售主仓', 'SKU-NORMAL'),
|
||||
$this->row('accessory', '配件-山东沂海配件单仓', 'SKU-ACCESSORY'),
|
||||
$this->row('suffix-single', '销售主仓', 'SKU-TAIL-4'),
|
||||
$this->row('suffix-multi', '销售主仓', 'SKU-TAIL-12'),
|
||||
$this->row('ty', '销售主仓', 'TY-ZPLS'),
|
||||
$this->row('xf', '销售主仓', 'XF001-JX'),
|
||||
$this->row('hyphen-inside', '销售主仓', 'SKU-12-KEEP'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_page_excludes_accessory_warehouses(): void
|
||||
public function test_page_excludes_hidden_warehouses_and_product_codes(): void
|
||||
{
|
||||
$this->loginAs()
|
||||
->get(route('business.pages.show', [
|
||||
@ -81,11 +91,16 @@ class MonthlyWeightedAveragePriceWarehouseFilterTest extends FeatureTestCase
|
||||
->assertOk()
|
||||
->assertSeeText('销售主仓')
|
||||
->assertSeeText('SKU-NORMAL')
|
||||
->assertSeeText('SKU-12-KEEP')
|
||||
->assertDontSeeText('配件-山东沂海配件单仓')
|
||||
->assertDontSeeText('SKU-ACCESSORY');
|
||||
->assertDontSeeText('SKU-ACCESSORY')
|
||||
->assertDontSeeText('SKU-TAIL-4')
|
||||
->assertDontSeeText('SKU-TAIL-12')
|
||||
->assertDontSeeText('TY-ZPLS')
|
||||
->assertDontSeeText('XF001-JX');
|
||||
}
|
||||
|
||||
public function test_export_excludes_accessory_warehouses(): void
|
||||
public function test_export_excludes_hidden_warehouses_and_product_codes(): void
|
||||
{
|
||||
$response = $this->loginAs()
|
||||
->get(route('business.product-inventory.monthly-weighted-average-price.export', [
|
||||
@ -97,8 +112,13 @@ class MonthlyWeightedAveragePriceWarehouseFilterTest extends FeatureTestCase
|
||||
$content = $response->streamedContent();
|
||||
$this->assertStringContainsString('销售主仓', $content);
|
||||
$this->assertStringContainsString('SKU-NORMAL', $content);
|
||||
$this->assertStringContainsString('SKU-12-KEEP', $content);
|
||||
$this->assertStringNotContainsString('配件-山东沂海配件单仓', $content);
|
||||
$this->assertStringNotContainsString('SKU-ACCESSORY', $content);
|
||||
$this->assertStringNotContainsString('SKU-TAIL-4', $content);
|
||||
$this->assertStringNotContainsString('SKU-TAIL-12', $content);
|
||||
$this->assertStringNotContainsString('TY-ZPLS', $content);
|
||||
$this->assertStringNotContainsString('XF001-JX', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
Loading…
x
Reference in New Issue
Block a user