- Add tab-based configurator (Base, Storage, PCI, Power, Accessories, Other) - Base tab: single-select with autocomplete for MB, CPU, MEM - Other tabs: multi-select with autocomplete and quantity input - Table view with LOT, Description, Price, Quantity, Total columns - Add configuration list page with create modal (opportunity number) - Remove Excel export functionality and excelize dependency - Increase component list limit from 100 to 5000 - Add web templates (base, index, configs, login, admin_pricing) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
95 lines
2.0 KiB
Go
95 lines
2.0 KiB
Go
package services
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/csv"
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.mchus.pro/mchus/quoteforge/internal/config"
|
|
"git.mchus.pro/mchus/quoteforge/internal/models"
|
|
)
|
|
|
|
type ExportService struct {
|
|
config config.ExportConfig
|
|
}
|
|
|
|
func NewExportService(cfg config.ExportConfig) *ExportService {
|
|
return &ExportService{config: cfg}
|
|
}
|
|
|
|
type ExportData struct {
|
|
Name string
|
|
Items []ExportItem
|
|
Total float64
|
|
Notes string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
type ExportItem struct {
|
|
LotName string
|
|
Description string
|
|
Category string
|
|
Quantity int
|
|
UnitPrice float64
|
|
TotalPrice float64
|
|
}
|
|
|
|
func (s *ExportService) ToCSV(data *ExportData) ([]byte, error) {
|
|
var buf bytes.Buffer
|
|
w := csv.NewWriter(&buf)
|
|
|
|
// Header
|
|
headers := []string{"Артикул", "Описание", "Категория", "Количество", "Цена за единицу", "Сумма"}
|
|
if err := w.Write(headers); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Items
|
|
for _, item := range data.Items {
|
|
row := []string{
|
|
item.LotName,
|
|
item.Description,
|
|
item.Category,
|
|
fmt.Sprintf("%d", item.Quantity),
|
|
fmt.Sprintf("%.2f", item.UnitPrice),
|
|
fmt.Sprintf("%.2f", item.TotalPrice),
|
|
}
|
|
if err := w.Write(row); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// Total row
|
|
if err := w.Write([]string{"", "", "", "", "ИТОГО:", fmt.Sprintf("%.2f", data.Total)}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
w.Flush()
|
|
return buf.Bytes(), w.Error()
|
|
}
|
|
|
|
func (s *ExportService) ConfigToExportData(config *models.Configuration) *ExportData {
|
|
items := make([]ExportItem, len(config.Items))
|
|
var total float64
|
|
|
|
for i, item := range config.Items {
|
|
itemTotal := item.UnitPrice * float64(item.Quantity)
|
|
items[i] = ExportItem{
|
|
LotName: item.LotName,
|
|
Quantity: item.Quantity,
|
|
UnitPrice: item.UnitPrice,
|
|
TotalPrice: itemTotal,
|
|
}
|
|
total += itemTotal
|
|
}
|
|
|
|
return &ExportData{
|
|
Name: config.Name,
|
|
Items: items,
|
|
Total: total,
|
|
Notes: config.Notes,
|
|
CreatedAt: config.CreatedAt,
|
|
}
|
|
}
|