fix: сортировка строк по категории в pricing CSV и вкладке Ценообразование (no-BOM)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -450,7 +450,16 @@ func (s *ExportService) buildPricingExportBlock(cfg *models.Configuration, opts
|
|||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catOrder := defaultCategoryOrder()
|
||||||
|
lotNames := make([]string, 0, len(cfg.Items))
|
||||||
for _, item := range cfg.Items {
|
for _, item := range cfg.Items {
|
||||||
|
if item.LotName != "" {
|
||||||
|
lotNames = append(lotNames, item.LotName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemCategories := s.resolveCategories(cfg.PricelistID, lotNames)
|
||||||
|
sortedItems := sortConfigItemsByCategoryMap(cfg.Items, catOrder, itemCategories)
|
||||||
|
for _, item := range sortedItems {
|
||||||
if item.LotName == "" {
|
if item.LotName == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -476,6 +485,22 @@ func (s *ExportService) buildPricingExportBlock(cfg *models.Configuration, opts
|
|||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sortConfigItemsByCategoryMap returns a copy of items sorted by category display order.
|
||||||
|
// categories maps lot_name → category code; catOrder maps category code → display order.
|
||||||
|
func sortConfigItemsByCategoryMap(items models.ConfigItems, catOrder map[string]int, categories map[string]string) models.ConfigItems {
|
||||||
|
sorted := make(models.ConfigItems, len(items))
|
||||||
|
copy(sorted, items)
|
||||||
|
sort.SliceStable(sorted, func(i, j int) bool {
|
||||||
|
orderI, hasI := categoryDisplayOrder(catOrder, categories[sorted[i].LotName])
|
||||||
|
orderJ, hasJ := categoryDisplayOrder(catOrder, categories[sorted[j].LotName])
|
||||||
|
if hasI && hasJ {
|
||||||
|
return orderI < orderJ
|
||||||
|
}
|
||||||
|
return hasI && !hasJ
|
||||||
|
})
|
||||||
|
return sorted
|
||||||
|
}
|
||||||
|
|
||||||
func applyDDPMarkup(rows []ProjectPricingExportRow, factor float64) {
|
func applyDDPMarkup(rows []ProjectPricingExportRow, factor float64) {
|
||||||
for i := range rows {
|
for i := range rows {
|
||||||
rows[i].Estimate = scaleFloatPtr(rows[i].Estimate, factor)
|
rows[i].Estimate = scaleFloatPtr(rows[i].Estimate, factor)
|
||||||
|
|||||||
@@ -4048,7 +4048,12 @@ async function renderPricingTab() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!bomRows.length) {
|
if (!bomRows.length) {
|
||||||
cart.forEach(item => { _pushCartRow(item, false); coveredLots.add(item.lot_name); });
|
const sortedByCategory = [...cart].sort((a, b) => {
|
||||||
|
const catA = (a.category || getCategoryFromLotName(a.lot_name)).toUpperCase();
|
||||||
|
const catB = (b.category || getCategoryFromLotName(b.lot_name)).toUpperCase();
|
||||||
|
return (categoryOrderMap[catA] || 9999) - (categoryOrderMap[catB] || 9999);
|
||||||
|
});
|
||||||
|
sortedByCategory.forEach(item => { _pushCartRow(item, false); coveredLots.add(item.lot_name); });
|
||||||
return { result, coveredLots };
|
return { result, coveredLots };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user