From 39e6fd56424cb43ff4e0163bf04e85005f835b1c Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Wed, 22 Jul 2026 15:11:06 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B2=D0=BA=D0=BB=D0=B0=D0=B4=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=90=D1=80=D0=B5=D0=BD=D0=B4=D0=B0=20=E2=80=94=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=BE=D0=BD=D0=BA=D0=B8=20Estimate/=D0=A6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B0=D0=B6=D0=B8?= =?UTF-8?q?;=20lot=5Fdescription=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B9=D1=81=D0=BB=D0=B8=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Вкладка «Аренда»: добавлены колонки Estimate и Цена продажи (+ итоги), чекбокс «БУ» перенесён первым слева, таблица переведена на тот же разметку/классы, что и таблицы вкладки «Ценообразование». Прайслисты: local_pricelist_items получает lot_description (синхронизируется из qt_pricelist_items.lot_description) вместо устаревших available_qty/ partnumbers, которые нигде не заполнялись. Co-Authored-By: Claude Sonnet 5 --- bible-local/03-database.md | 17 ++-- internal/handlers/pricelist.go | 20 ++-- internal/localdb/components.go | 20 ++-- internal/localdb/converters.go | 39 ++++---- internal/localdb/migrations.go | 92 +++++++++++++++++++ internal/localdb/models.go | 29 +++--- internal/models/lot.go | 11 --- internal/models/pricelist.go | 22 ++--- internal/repository/pricelist.go | 9 -- internal/repository/pricelist_test.go | 2 +- ...ervice_pricelist_category_backfill_test.go | 13 +-- .../sync/service_projects_push_test.go | 1 - ...add_lot_description_to_pricelist_items.sql | 17 ++++ web/templates/index.html | 66 ++++++++----- web/templates/pricelist_detail.html | 8 -- 15 files changed, 236 insertions(+), 130 deletions(-) create mode 100644 migrations/032_add_lot_description_to_pricelist_items.sql diff --git a/bible-local/03-database.md b/bible-local/03-database.md index f7adbd7..bc20d33 100644 --- a/bible-local/03-database.md +++ b/bible-local/03-database.md @@ -26,6 +26,7 @@ Rules: - user-authored tables must not be dropped as a recovery shortcut; - `local_pricelist_items` is the only valid runtime source of prices and component catalog; do not add a separate component cache table; - `local_pricelist_items.lot_category` is the single source of a LOT's category at runtime (populated by sync from `qt_pricelist_items.lot_category`); do not derive category from a lot_name prefix or from `qt_categories`/`qt_lot_metadata`; +- `local_pricelist_items.lot_description` is the single source of a LOT's description at runtime (populated by sync from `qt_pricelist_items.lot_description`); do not join the legacy `lot` table for it; - configuration `items` and `vendor_spec` are stored as JSON payloads inside configuration rows; - `local_components` table has been removed; any reference to it is dead code. @@ -80,7 +81,7 @@ These tables are retained for historical data. QuoteForge does not read or write Rules: - QuoteForge runtime must not depend on any legacy RFQ tables; -- QuoteForge sync reads prices and categories from `qt_pricelists` / `qt_pricelist_items` only; +- QuoteForge sync reads prices, categories and descriptions from `qt_pricelists` / `qt_pricelist_items` only; - QuoteForge does not enrich local pricelist rows from `parts_log` or any other raw supplier log table; - normal UI requests must not query MariaDB tables directly; - `qt_client_local_migrations` exists in the 2026-04-15 schema dump, but runtime sync does not depend on it. @@ -256,12 +257,16 @@ PK: lot_name | pricelist_id | bigint UNSIGNED NOT NULL | FK → qt_pricelists.id | | lot_name | varchar(255) NOT NULL | INDEX with pricelist_id | | lot_category | varchar(50) | | +| lot_description | varchar(10000) | added by migration 032; backfilled once from `lot.lot_description`. QF syncs this column directly — do not join `lot` per-row to get a description | | price | decimal(12,2) NOT NULL | | -| price_method | varchar(20) | | -| price_period_days | bigint DEFAULT 90 | | -| price_coefficient | decimal(5,2) DEFAULT 0 | | -| manual_price | decimal(12,2) | | -| meta_prices | varchar(1000) | | +| price_method | varchar(20) | synced to local and shown in the pricelist detail "Настройки" column | +| price_period_days | bigint DEFAULT 90 | synced to local, same as above | +| price_coefficient | decimal(5,2) DEFAULT 0 | synced to local, same as above | +| manual_price | decimal(12,2) | synced to local, same as above | +| meta_prices | varchar(1000) | synced to local, same as above | +| lead_time_weeks | int | exists in the real table; not read by QF — no corresponding field in `models.PricelistItem` | + +Fields QF never populates and does not model: `AvailableQty`/`Partnumbers` (removed from `models.PricelistItem` and `LocalPricelistItem` — no writer ever set them; always empty). ### qt_pricelist_sync_status PK: username diff --git a/internal/handlers/pricelist.go b/internal/handlers/pricelist.go index 0cfbf81..ad4548e 100644 --- a/internal/handlers/pricelist.go +++ b/internal/handlers/pricelist.go @@ -180,16 +180,16 @@ func (h *PricelistHandler) GetItems(c *gin.Context) { resultItems := make([]gin.H, 0, len(items)) for _, item := range items { resultItems = append(resultItems, gin.H{ - "id": item.ID, - "lot_name": item.LotName, - "lot_description": "", - "price": item.Price, - "category": item.LotCategory, - "available_qty": item.AvailableQty, - "partnumbers": []string(item.Partnumbers), - "partnumber_qtys": map[string]interface{}{}, - "competitor_names": []string{}, - "price_spread_pct": nil, + "id": item.ID, + "lot_name": item.LotName, + "lot_description": item.LotDescription, + "price": item.Price, + "category": item.LotCategory, + "price_method": item.PriceMethod, + "price_period_days": item.PricePeriodDays, + "price_coefficient": item.PriceCoefficient, + "manual_price": item.ManualPrice, + "meta_prices": item.MetaPrices, }) } diff --git a/internal/localdb/components.go b/internal/localdb/components.go index dcb190e..2889163 100644 --- a/internal/localdb/components.go +++ b/internal/localdb/components.go @@ -42,18 +42,19 @@ func (l *LocalDB) latestActivePricelistID(source string) (uint, error) { // pricelistItemRow is used for scanning rows from local_pricelist_items. type pricelistItemRow struct { - LotName string `gorm:"column:lot_name"` - Category string `gorm:"column:lot_category"` + LotName string `gorm:"column:lot_name"` + Category string `gorm:"column:lot_category"` + Description string `gorm:"column:lot_description"` } func (r pricelistItemRow) toLocalComponent() LocalComponent { return LocalComponent{ - LotName: r.LotName, - Category: r.Category, + LotName: r.LotName, + Category: r.Category, + LotDescription: r.Description, } } - // SearchLocalComponents searches components in the latest active estimate // pricelist by lot_name. func (l *LocalDB) SearchLocalComponents(query string, limit int) ([]LocalComponent, error) { @@ -72,7 +73,7 @@ func (l *LocalDB) SearchLocalComponents(query string, limit int) ([]LocalCompone } var rows []pricelistItemRow - if err := db.Select("lot_name, lot_category").Order("lot_name").Limit(limit).Scan(&rows).Error; err != nil { + if err := db.Select("lot_name, lot_category, lot_description").Order("lot_name").Limit(limit).Scan(&rows).Error; err != nil { return nil, err } components := make([]LocalComponent, len(rows)) @@ -100,7 +101,7 @@ func (l *LocalDB) SearchLocalComponentsByCategory(category, query string, limit } var rows []pricelistItemRow - if err := db.Select("lot_name, lot_category").Order("lot_name").Limit(limit).Scan(&rows).Error; err != nil { + if err := db.Select("lot_name, lot_category, lot_description").Order("lot_name").Limit(limit).Scan(&rows).Error; err != nil { return nil, err } components := make([]LocalComponent, len(rows)) @@ -134,7 +135,7 @@ func (l *LocalDB) ListComponents(filter ComponentFilter, offset, limit int) ([]L } var rows []pricelistItemRow - if err := db.Select("lot_name, lot_category").Order("lot_name").Offset(offset).Limit(limit).Scan(&rows).Error; err != nil { + if err := db.Select("lot_name, lot_category, lot_description").Order("lot_name").Offset(offset).Limit(limit).Scan(&rows).Error; err != nil { return nil, 0, err } components := make([]LocalComponent, len(rows)) @@ -154,7 +155,7 @@ func (l *LocalDB) GetLocalComponent(lotName string) (*LocalComponent, error) { var row pricelistItemRow if err := l.db.Table("local_pricelist_items"). - Select("lot_name, lot_category"). + Select("lot_name, lot_category, lot_description"). Where("pricelist_id = ? AND UPPER(lot_name) = ?", pricelistID, strings.ToUpper(lotName)). First(&row).Error; err != nil { return nil, err @@ -230,4 +231,3 @@ func (l *LocalDB) CountComponents() int64 { l.db.Table("local_pricelist_items").Where("pricelist_id = ?", pricelistID).Count(&count) return count } - diff --git a/internal/localdb/converters.go b/internal/localdb/converters.go index 8fdfd90..238b77e 100644 --- a/internal/localdb/converters.go +++ b/internal/localdb/converters.go @@ -331,30 +331,33 @@ func LocalToPricelist(local *LocalPricelist) *models.Pricelist { // PricelistItemToLocal converts models.PricelistItem to LocalPricelistItem func PricelistItemToLocal(item *models.PricelistItem, localPricelistID uint) *LocalPricelistItem { - partnumbers := make(LocalStringList, 0, len(item.Partnumbers)) - partnumbers = append(partnumbers, item.Partnumbers...) return &LocalPricelistItem{ - PricelistID: localPricelistID, - LotName: models.NormalizeLotName(item.LotName), - LotCategory: item.LotCategory, - Price: item.Price, - AvailableQty: item.AvailableQty, - Partnumbers: partnumbers, + PricelistID: localPricelistID, + LotName: models.NormalizeLotName(item.LotName), + LotCategory: item.LotCategory, + LotDescription: item.LotDescription, + Price: item.Price, + PriceMethod: item.PriceMethod, + PricePeriodDays: item.PricePeriodDays, + PriceCoefficient: item.PriceCoefficient, + ManualPrice: item.ManualPrice, + MetaPrices: item.MetaPrices, } } // LocalToPricelistItem converts LocalPricelistItem to models.PricelistItem func LocalToPricelistItem(local *LocalPricelistItem, serverPricelistID uint) *models.PricelistItem { - partnumbers := make([]string, 0, len(local.Partnumbers)) - partnumbers = append(partnumbers, local.Partnumbers...) return &models.PricelistItem{ - ID: local.ID, - PricelistID: serverPricelistID, - LotName: local.LotName, - LotCategory: local.LotCategory, - Price: local.Price, - AvailableQty: local.AvailableQty, - Partnumbers: partnumbers, + ID: local.ID, + PricelistID: serverPricelistID, + LotName: local.LotName, + LotCategory: local.LotCategory, + LotDescription: local.LotDescription, + Price: local.Price, + PriceMethod: local.PriceMethod, + PricePeriodDays: local.PricePeriodDays, + PriceCoefficient: local.PriceCoefficient, + ManualPrice: local.ManualPrice, + MetaPrices: local.MetaPrices, } } - diff --git a/internal/localdb/migrations.go b/internal/localdb/migrations.go index 3d8d809..3773079 100644 --- a/internal/localdb/migrations.go +++ b/internal/localdb/migrations.go @@ -129,6 +129,98 @@ var localMigrations = []localMigration{ name: "Add rental_enabled to local_projects", run: addLocalProjectRentalEnabled, }, + { + id: "2026_07_22_pricelist_items_price_settings", + name: "Add lot_description and price settings columns to local_pricelist_items, drop unused available_qty/partnumbers", + run: addPricelistItemDescriptionAndPriceSettings, + }, +} + +func addPricelistItemDescriptionAndPriceSettings(tx *gorm.DB) error { + type columnInfo struct { + Name string `gorm:"column:name"` + } + + var columns []columnInfo + if err := tx.Raw(` + SELECT name FROM pragma_table_info('local_pricelist_items') + WHERE name IN ('lot_description', 'price_method', 'price_period_days', 'price_coefficient', 'manual_price', 'meta_prices', 'available_qty', 'partnumbers') + `).Scan(&columns).Error; err != nil { + return fmt.Errorf("check local_pricelist_items columns: %w", err) + } + + have := make(map[string]bool, len(columns)) + for _, c := range columns { + have[c.Name] = true + } + + if have["lot_description"] && have["price_method"] && have["price_period_days"] && + have["price_coefficient"] && have["manual_price"] && have["meta_prices"] && + !have["available_qty"] && !have["partnumbers"] { + slog.Info("local_pricelist_items already migrated to description/price-settings schema") + return nil + } + + // SQLite: recreate table without the never-populated available_qty/partnumbers + // columns, adding lot_description and the price settings columns synced from + // qt_pricelist_items (needed to render the pricelist detail UI correctly). + if err := tx.Exec(` + CREATE TABLE local_pricelist_items_new ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + pricelist_id INTEGER NOT NULL, + lot_name TEXT NOT NULL, + lot_category TEXT, + lot_description TEXT, + price REAL NOT NULL, + price_method TEXT, + price_period_days INTEGER DEFAULT 90, + price_coefficient REAL DEFAULT 0, + manual_price REAL, + meta_prices TEXT + ) + `).Error; err != nil { + return fmt.Errorf("create new local_pricelist_items table: %w", err) + } + + if err := tx.Exec(` + INSERT INTO local_pricelist_items_new (id, pricelist_id, lot_name, lot_category, price) + SELECT id, pricelist_id, lot_name, lot_category, price + FROM local_pricelist_items + `).Error; err != nil { + return fmt.Errorf("copy data to new local_pricelist_items table: %w", err) + } + + if err := tx.Exec(`DROP TABLE local_pricelist_items`).Error; err != nil { + return fmt.Errorf("drop old local_pricelist_items table: %w", err) + } + + if err := tx.Exec(`ALTER TABLE local_pricelist_items_new RENAME TO local_pricelist_items`).Error; err != nil { + return fmt.Errorf("rename new local_pricelist_items table: %w", err) + } + + if err := tx.Exec(` + CREATE INDEX IF NOT EXISTS idx_local_pricelist_items_pricelist_lot + ON local_pricelist_items(pricelist_id, lot_name) + `).Error; err != nil { + return fmt.Errorf("recreate idx_local_pricelist_items_pricelist_lot: %w", err) + } + + if err := tx.Exec(` + CREATE UNIQUE INDEX IF NOT EXISTS idx_local_pricelist_items_pricelist_lot_unique + ON local_pricelist_items(pricelist_id, lot_name) + `).Error; err != nil { + return fmt.Errorf("recreate unique index on local_pricelist_items: %w", err) + } + + if err := tx.Exec(` + CREATE INDEX IF NOT EXISTS idx_local_pricelist_items_lot_category + ON local_pricelist_items(lot_category) + `).Error; err != nil { + return fmt.Errorf("recreate idx_local_pricelist_items_lot_category: %w", err) + } + + slog.Info("added lot_description/price settings columns to local_pricelist_items and dropped available_qty/partnumbers") + return nil } func addLocalProjectRentalEnabled(tx *gorm.DB) error { diff --git a/internal/localdb/models.go b/internal/localdb/models.go index 8735d5d..bf82519 100644 --- a/internal/localdb/models.go +++ b/internal/localdb/models.go @@ -120,7 +120,7 @@ type LocalConfiguration struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` SyncedAt *time.Time `json:"synced_at"` - ConfigType string `gorm:"default:server" json:"config_type"` // "server" | "storage" + ConfigType string `gorm:"default:server" json:"config_type"` // "server" | "storage" SyncStatus string `gorm:"default:'local'" json:"sync_status"` // 'local', 'synced', 'modified' OriginalUserID uint `json:"original_user_id"` // UserID from MariaDB for reference OriginalUsername string `gorm:"not null;default:'';index" json:"original_username"` @@ -180,7 +180,7 @@ type LocalPricelist struct { Name string `json:"name"` CreatedAt time.Time `gorm:"index:idx_local_pricelists_source_created_at,priority:2,sort:desc" json:"created_at"` SyncedAt time.Time `json:"synced_at"` - IsUsed bool `gorm:"default:false" json:"is_used"` // Used by any local configuration + IsUsed bool `gorm:"default:false" json:"is_used"` // Used by any local configuration IsActive bool `gorm:"not null;default:true;index" json:"is_active"` // Mirrors qt_pricelists.is_active } @@ -190,13 +190,20 @@ func (LocalPricelist) TableName() string { // LocalPricelistItem stores pricelist items type LocalPricelistItem struct { - ID uint `gorm:"primaryKey;autoIncrement" json:"id"` - PricelistID uint `gorm:"not null;index" json:"pricelist_id"` - LotName string `gorm:"not null" json:"lot_name"` - LotCategory string `gorm:"column:lot_category" json:"lot_category,omitempty"` - Price float64 `gorm:"not null" json:"price"` - AvailableQty *float64 `json:"available_qty,omitempty"` - Partnumbers LocalStringList `gorm:"type:text" json:"partnumbers,omitempty"` + ID uint `gorm:"primaryKey;autoIncrement" json:"id"` + PricelistID uint `gorm:"not null;index" json:"pricelist_id"` + LotName string `gorm:"not null" json:"lot_name"` + LotCategory string `gorm:"column:lot_category" json:"lot_category,omitempty"` + LotDescription string `gorm:"column:lot_description" json:"lot_description,omitempty"` + Price float64 `gorm:"not null" json:"price"` + + // Price calculation settings, mirrored from qt_pricelist_items for display + // in the pricelist detail UI (formatPriceSettings in pricelist_detail.html). + PriceMethod string `gorm:"column:price_method" json:"price_method,omitempty"` + PricePeriodDays int `gorm:"column:price_period_days;default:90" json:"price_period_days"` + PriceCoefficient float64 `gorm:"column:price_coefficient;default:0" json:"price_coefficient"` + ManualPrice *float64 `gorm:"column:manual_price" json:"manual_price,omitempty"` + MetaPrices string `gorm:"column:meta_prices" json:"meta_prices,omitempty"` } func (LocalPricelistItem) TableName() string { @@ -365,8 +372,8 @@ type VendorSpecLotMapping struct { // SyncLogEntry records the outcome of a single sync operation for diagnostics. type SyncLogEntry struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` - SyncType string `gorm:"not null;index;size:32" json:"sync_type"` // components | pricelists | push | full - Status string `gorm:"not null;size:16" json:"status"` // ok | error | skipped + SyncType string `gorm:"not null;index;size:32" json:"sync_type"` // components | pricelists | push | full + Status string `gorm:"not null;size:16" json:"status"` // ok | error | skipped ErrorText string `gorm:"size:1000" json:"error_text,omitempty"` SyncedCount int `gorm:"default:0" json:"synced_count"` StartedAt time.Time `gorm:"not null;index" json:"started_at"` diff --git a/internal/models/lot.go b/internal/models/lot.go index c31d8c2..89f2954 100644 --- a/internal/models/lot.go +++ b/internal/models/lot.go @@ -7,14 +7,3 @@ import "strings" func NormalizeLotName(s string) string { return strings.ToUpper(strings.TrimSpace(s)) } - -// Lot represents existing lot table -type Lot struct { - LotName string `gorm:"column:lot_name;primaryKey;size:255" json:"lot_name"` - LotDescription string `gorm:"column:lot_description;size:10000" json:"lot_description"` - LotCategory *string `gorm:"column:lot_category;size:50" json:"lot_category"` -} - -func (Lot) TableName() string { - return "lot" -} diff --git a/internal/models/pricelist.go b/internal/models/pricelist.go index 7a5ed1d..cd4c63d 100644 --- a/internal/models/pricelist.go +++ b/internal/models/pricelist.go @@ -55,24 +55,20 @@ func (Pricelist) TableName() string { // PricelistItem represents a single item in a pricelist type PricelistItem struct { - ID uint `gorm:"primaryKey" json:"id"` - PricelistID uint `gorm:"not null;index:idx_pricelist_lot" json:"pricelist_id"` - LotName string `gorm:"size:255;not null;index:idx_pricelist_lot" json:"lot_name"` - LotCategory string `gorm:"column:lot_category;size:50" json:"lot_category,omitempty"` - Price float64 `gorm:"type:decimal(12,2);not null" json:"price"` - PriceMethod string `gorm:"size:20" json:"price_method"` + ID uint `gorm:"primaryKey" json:"id"` + PricelistID uint `gorm:"not null;index:idx_pricelist_lot" json:"pricelist_id"` + LotName string `gorm:"size:255;not null;index:idx_pricelist_lot" json:"lot_name"` + LotCategory string `gorm:"column:lot_category;size:50" json:"lot_category,omitempty"` + LotDescription string `gorm:"column:lot_description;size:10000" json:"lot_description,omitempty"` + Price float64 `gorm:"type:decimal(12,2);not null" json:"price"` + PriceMethod string `gorm:"size:20" json:"price_method,omitempty"` - // Price calculation settings (snapshot from qt_lot_metadata) + // Price calculation settings (snapshot from qt_lot_metadata), shown in the + // pricelist detail UI as a compact "settings" summary next to each item. PricePeriodDays int `gorm:"default:90" json:"price_period_days"` PriceCoefficient float64 `gorm:"type:decimal(5,2);default:0" json:"price_coefficient"` ManualPrice *float64 `gorm:"type:decimal(12,2)" json:"manual_price,omitempty"` MetaPrices string `gorm:"size:1000" json:"meta_prices,omitempty"` - - // Virtual fields for display - LotDescription string `gorm:"-" json:"lot_description,omitempty"` - Category string `gorm:"-" json:"category,omitempty"` - AvailableQty *float64 `gorm:"-" json:"available_qty,omitempty"` - Partnumbers []string `gorm:"-" json:"partnumbers,omitempty"` } func (PricelistItem) TableName() string { diff --git a/internal/repository/pricelist.go b/internal/repository/pricelist.go index a100629..c3c68f7 100644 --- a/internal/repository/pricelist.go +++ b/internal/repository/pricelist.go @@ -234,15 +234,6 @@ func (r *PricelistRepository) GetItems(pricelistID uint, offset, limit int, sear return nil, 0, fmt.Errorf("listing pricelist items: %w", err) } - // Enrich with lot descriptions - for i := range items { - var lot models.Lot - if err := r.db.Where("lot_name = ?", items[i].LotName).First(&lot).Error; err == nil { - items[i].LotDescription = lot.LotDescription - } - items[i].Category = strings.TrimSpace(items[i].LotCategory) - } - return items, total, nil } diff --git a/internal/repository/pricelist_test.go b/internal/repository/pricelist_test.go index 7dac05e..ce79edd 100644 --- a/internal/repository/pricelist_test.go +++ b/internal/repository/pricelist_test.go @@ -177,7 +177,7 @@ func newTestPricelistRepository(t *testing.T) *PricelistRepository { if err != nil { t.Fatalf("open sqlite: %v", err) } - if err := db.AutoMigrate(&models.Pricelist{}, &models.PricelistItem{}, &models.Lot{}); err != nil { + if err := db.AutoMigrate(&models.Pricelist{}, &models.PricelistItem{}); err != nil { t.Fatalf("migrate: %v", err) } return NewPricelistRepository(db) diff --git a/internal/services/sync/service_pricelist_category_backfill_test.go b/internal/services/sync/service_pricelist_category_backfill_test.go index ff2291f..d9bdfac 100644 --- a/internal/services/sync/service_pricelist_category_backfill_test.go +++ b/internal/services/sync/service_pricelist_category_backfill_test.go @@ -16,7 +16,6 @@ func TestSyncPricelists_BackfillsLotCategoryForUsedPricelistItems(t *testing.T) if err := serverDB.AutoMigrate( &models.Pricelist{}, &models.PricelistItem{}, - &models.Lot{}, ); err != nil { t.Fatalf("migrate server tables: %v", err) } @@ -33,14 +32,10 @@ func TestSyncPricelists_BackfillsLotCategoryForUsedPricelistItems(t *testing.T) t.Fatalf("create server pricelist: %v", err) } if err := serverDB.Create(&models.PricelistItem{ - PricelistID: serverPL.ID, - LotName: "CPU_A", - LotCategory: "CPU", - Price: 10, - PriceMethod: "", - MetaPrices: "", - ManualPrice: nil, - AvailableQty: nil, + PricelistID: serverPL.ID, + LotName: "CPU_A", + LotCategory: "CPU", + Price: 10, }).Error; err != nil { t.Fatalf("create server pricelist item: %v", err) } diff --git a/internal/services/sync/service_projects_push_test.go b/internal/services/sync/service_projects_push_test.go index 1f8a62a..c48586b 100644 --- a/internal/services/sync/service_projects_push_test.go +++ b/internal/services/sync/service_projects_push_test.go @@ -439,7 +439,6 @@ func newServerDBForSyncTest(t *testing.T) *gorm.DB { &models.Configuration{}, &models.Pricelist{}, &models.PricelistItem{}, - &models.Lot{}, ); err != nil { t.Fatalf("migrate server test schema: %v", err) } diff --git a/migrations/032_add_lot_description_to_pricelist_items.sql b/migrations/032_add_lot_description_to_pricelist_items.sql new file mode 100644 index 0000000..c07f680 --- /dev/null +++ b/migrations/032_add_lot_description_to_pricelist_items.sql @@ -0,0 +1,17 @@ +-- Tables affected: qt_pricelist_items +-- recovery.not-started: safe to re-run; ADD COLUMN IF NOT EXISTS +-- recovery.partial: ALTER TABLE qt_pricelist_items DROP COLUMN lot_description; +-- recovery.completed: no action needed +-- verify: lot_description column missing | SELECT 1 FROM information_schema.COLUMNS WHERE table_schema=DATABASE() AND table_name='qt_pricelist_items' AND column_name='lot_description' HAVING COUNT(*)=0 + +-- QuoteForge previously read a LOT's description via a per-row live join into +-- `lot` (internal/repository/pricelist.go GetItems), which never made it into +-- the local sync cache. Storing the description directly on the pricelist row +-- lets QF sync it like any other pricelist field and removes the join. +ALTER TABLE qt_pricelist_items + ADD COLUMN IF NOT EXISTS lot_description VARCHAR(10000) NULL; + +UPDATE qt_pricelist_items i + JOIN lot l ON l.lot_name = i.lot_name + SET i.lot_description = l.lot_description + WHERE i.lot_description IS NULL OR i.lot_description = ''; diff --git a/web/templates/index.html b/web/templates/index.html index a66f29f..0b6436b 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -315,7 +315,7 @@

Расчёт стоимости платного тестирования / аренды

-

Черновая методика — параметры и коэффициенты могут измениться. Цена всегда за 1 неделю: разовый платёж (один раз) + еженедельный платёж (за каждую неделю теста/аренды). Цена берётся из Estimate, увеличенного на аплифт ниже. Поддержка сюда не входит.

+

Черновая методика — параметры и коэффициенты могут измениться. Цена всегда за 1 неделю: разовый платёж (один раз) + еженедельный платёж (за каждую неделю теста/аренды), с НДС. Цена продажи = Estimate, увеличенный на аплифт ниже. Поддержка сюда не входит.

@@ -333,21 +333,25 @@ + - + + - + - + + + @@ -3358,7 +3362,7 @@ async function renderRentalTab() { const foot = document.getElementById('rental-foot'); const warningsEl = document.getElementById('rental-warnings'); if (!configUUID || cart.length === 0) { - body.innerHTML = ''; + body.innerHTML = ''; foot.classList.add('hidden'); return; } @@ -3378,13 +3382,13 @@ async function renderRentalTab() { body: JSON.stringify(payload) }); if (!resp.ok) { - body.innerHTML = ''; + body.innerHTML = ''; foot.classList.add('hidden'); return; } result = await resp.json(); } catch (e) { - body.innerHTML = ''; + body.innerHTML = ''; foot.classList.add('hidden'); return; } @@ -3399,26 +3403,42 @@ async function renderRentalTab() { const descByLot = {}; cart.forEach(c => { descByLot[(c.lot_name || '').toUpperCase()] = c.description || ''; }); - const rows = (result.items || []).map(item => { + const items = result.items || []; + if (!items.length) { + body.innerHTML = ''; + foot.classList.add('hidden'); + return; + } + + let totEst = 0, totSale = 0; + body.innerHTML = items.map(item => { const isUsed = item.condition === 'used'; const desc = descByLot[(item.lot_name || '').toUpperCase()] || ''; - return '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - ''; + const estTotal = item.buy_price * item.quantity; + const saleTotal = item.price * item.quantity; + totEst += estTotal; + totSale += saleTotal; + return ` + + + + + + + + + + `; }).join(''); - body.innerHTML = rows || ''; - document.getElementById('rental-total-onetime').textContent = formatMoney(result.one_time_total); - document.getElementById('rental-total-weekly').textContent = formatMoney(result.weekly_total); + document.getElementById('rental-total-estimate').textContent = formatCurrency(totEst); + document.getElementById('rental-total-sale').textContent = formatCurrency(totSale); + document.getElementById('rental-total-onetime').textContent = formatCurrency(result.one_time_total); + document.getElementById('rental-total-weekly').textContent = formatCurrency(result.weekly_total); foot.classList.remove('hidden'); } diff --git a/web/templates/pricelist_detail.html b/web/templates/pricelist_detail.html index 6a98e10..82eb6e8 100644 --- a/web/templates/pricelist_detail.html +++ b/web/templates/pricelist_detail.html @@ -58,7 +58,6 @@ - @@ -164,16 +163,9 @@ function toggleWarehouseColumns() { const stock = isStockSource(); - document.getElementById('th-qty').classList.toggle('hidden', true); document.getElementById('th-settings').classList.toggle('hidden', stock); } - function formatQty(qty) { - if (typeof qty !== 'number') return '—'; - if (Number.isInteger(qty)) return qty.toString(); - return qty.toLocaleString('ru-RU', { minimumFractionDigits: 0, maximumFractionDigits: 3 }); - } - function escapeHtml(text) { if (text === null || text === undefined) return ''; return String(text)
БУ LOT Описание Категория Кол-воБУEstimateЦена продажи Разовый платёж Еженедельный платёж
Загрузите компоненты во вкладке «Estimate»
Загрузите компоненты во вкладке «Estimate»