Modularize Go files, extract JS to static, implement competitor pricelists

Go refactoring:
- Split handlers/pricing.go (2446→291 lines) into 5 focused files
- Split services/stock_import.go (1334→~400 lines) into stock_mappings.go + stock_parse.go
- Split services/sync/service.go (1290→~250 lines) into 3 files

JS extraction:
- Move all inline <script> blocks to web/static/js/ (6 files)
- Templates reduced: admin_pricing 2873→521, lot 1531→304, vendor_mappings 1063→169, etc.

Competitor pricelists (migrations 033-039):
- qt_competitors + partnumber_log_competitors tables
- Excel import with column mapping, dedup, bulk insert
- p/n→lot resolution via weighted_median, discount applied
- Unmapped p/ns written to qt_vendor_partnumber_seen
- Quote counts (unique/total) shown on /admin/competitors
- price_method="weighted_median", price_period_days=0 stored explicitly

Fix price_method/price_period_days for warehouse items:
- warehouse: weighted_avg, period=0
- competitor: weighted_median, period=0
- Removes misleading DB defaults (was: median/90)

Update bible: architecture.md, pricelist.md, history.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-03-13 07:44:10 +03:00
parent c0fecde34e
commit f48615e8a9
41 changed files with 11822 additions and 9008 deletions

View File

@@ -0,0 +1,27 @@
CREATE TABLE IF NOT EXISTS qt_competitors (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
code VARCHAR(100) NOT NULL UNIQUE,
delivery_basis VARCHAR(50) NOT NULL DEFAULT 'DDP',
expected_discount_pct DECIMAL(5,2) NOT NULL DEFAULT 0.00,
column_mapping JSON NULL,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS partnumber_log_competitors (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
competitor_id BIGINT UNSIGNED NOT NULL,
lot_name VARCHAR(255) NOT NULL,
raw_partnumber VARCHAR(255) NULL,
price DECIMAL(12,2) NOT NULL,
quote_date DATE NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_plc_competitor_id (competitor_id),
INDEX idx_plc_lot_name (lot_name),
INDEX idx_plc_competitor_lot_date (competitor_id, lot_name, quote_date),
CONSTRAINT fk_plc_competitor
FOREIGN KEY (competitor_id) REFERENCES qt_competitors(id)
ON DELETE RESTRICT ON UPDATE CASCADE
);

View File

@@ -0,0 +1,2 @@
ALTER TABLE partnumber_log_competitors
ADD COLUMN qty DECIMAL(12,4) NOT NULL DEFAULT 1 AFTER price;

View File

@@ -0,0 +1 @@
ALTER TABLE partnumber_log_competitors MODIFY COLUMN lot_name VARCHAR(255) NULL;

View File

@@ -0,0 +1,4 @@
ALTER TABLE partnumber_log_competitors
DROP COLUMN lot_name,
CHANGE COLUMN raw_partnumber partnumber VARCHAR(255) NOT NULL,
CHANGE COLUMN quote_date date DATE NOT NULL;

View File

@@ -0,0 +1,2 @@
ALTER TABLE qt_competitors
ADD COLUMN currency VARCHAR(10) NOT NULL DEFAULT 'USD' AFTER delivery_basis;

View File

@@ -0,0 +1,3 @@
ALTER TABLE partnumber_log_competitors
ADD COLUMN description VARCHAR(500) NULL AFTER partnumber,
ADD COLUMN vendor VARCHAR(255) NULL AFTER description;

View File

@@ -0,0 +1,3 @@
ALTER TABLE partnumber_log_competitors
ADD COLUMN price_loccur DECIMAL(12,2) NULL AFTER price,
ADD COLUMN currency VARCHAR(10) NULL AFTER price_loccur;