Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -136,6 +136,7 @@ func loadHasCostDetailGroups(ctx context.Context, uretimDB *sql.DB, nOnMLNo int)
|
||||
nOnMLNoStr string
|
||||
nOnMLDetNoStr string
|
||||
hNoStr string
|
||||
mtBolumStr string
|
||||
fiyatGirilen sql.NullFloat64
|
||||
fiyatDoviz sql.NullString
|
||||
maliyeteDahil sql.NullBool
|
||||
@@ -150,6 +151,7 @@ func loadHasCostDetailGroups(ctx context.Context, uretimDB *sql.DB, nOnMLNo int)
|
||||
&nOnMLNoStr,
|
||||
&nOnMLDetNoStr,
|
||||
&hNoStr,
|
||||
&mtBolumStr,
|
||||
&item.SKodu,
|
||||
&item.SAciklama,
|
||||
&item.SRenk,
|
||||
@@ -179,6 +181,7 @@ func loadHasCostDetailGroups(ctx context.Context, uretimDB *sql.DB, nOnMLNo int)
|
||||
item.NOnMLNo = strings.TrimSpace(nOnMLNoStr)
|
||||
item.NOnMLDetNo = strings.TrimSpace(nOnMLDetNoStr)
|
||||
item.NHammaddeTuruNo = strings.TrimSpace(hNoStr)
|
||||
item.NUrtMTBolumID = strings.TrimSpace(mtBolumStr)
|
||||
if fiyatGirilen.Valid {
|
||||
item.FiyatGirilen = new(float64)
|
||||
*item.FiyatGirilen = fiyatGirilen.Float64
|
||||
@@ -248,7 +251,11 @@ func (c *costingPDF) drawHeaderFull() {
|
||||
line2 := fmt.Sprintf("Urun: %s - %s", strings.TrimSpace(c.header.UrunKodu), strings.TrimSpace(c.header.UrunAdi))
|
||||
pdf.CellFormat(0, 5, line2, "", 1, "L", false, 0, "")
|
||||
|
||||
line3 := fmt.Sprintf("Firma: %s | Kaydeden: %s | Guncelleme: %s (%s)", strings.TrimSpace(c.header.FirmaKodu), strings.TrimSpace(c.header.SKullaniciAdi), strings.TrimSpace(c.header.DteGuncellemeTarihi), strings.TrimSpace(c.header.SGuncellemeKullaniciAdi))
|
||||
firmaLabel := strings.TrimSpace(c.header.FirmaKodu)
|
||||
if strings.TrimSpace(c.header.UretimiYapanFirma) != "" {
|
||||
firmaLabel = fmt.Sprintf("%s - %s", firmaLabel, strings.TrimSpace(c.header.UretimiYapanFirma))
|
||||
}
|
||||
line3 := fmt.Sprintf("Firma: %s | Kaydeden: %s | Guncelleme: %s (%s)", firmaLabel, strings.TrimSpace(c.header.SKullaniciAdi), strings.TrimSpace(c.header.DteGuncellemeTarihi), strings.TrimSpace(c.header.SGuncellemeKullaniciAdi))
|
||||
pdf.CellFormat(0, 5, line3, "", 1, "L", false, 0, "")
|
||||
|
||||
pdf.SetTextColor(0, 0, 0)
|
||||
@@ -258,7 +265,11 @@ func (c *costingPDF) drawHeaderFull() {
|
||||
func (c *costingPDF) drawHeaderCompact() {
|
||||
pdf := c.pdf
|
||||
pdf.SetFont("dejavu", "B", 10.5)
|
||||
title := fmt.Sprintf("OnML %s | %s - %s | %s", c.header.NOnMLNo, strings.TrimSpace(c.header.UrunKodu), strings.TrimSpace(c.header.UrunAdi), c.header.DteKayitTarihi)
|
||||
firmaLabel := strings.TrimSpace(c.header.FirmaKodu)
|
||||
if strings.TrimSpace(c.header.UretimiYapanFirma) != "" {
|
||||
firmaLabel = fmt.Sprintf("%s - %s", firmaLabel, strings.TrimSpace(c.header.UretimiYapanFirma))
|
||||
}
|
||||
title := fmt.Sprintf("OnML %s | %s - %s | %s | %s", c.header.NOnMLNo, strings.TrimSpace(c.header.UrunKodu), strings.TrimSpace(c.header.UrunAdi), c.header.DteKayitTarihi, firmaLabel)
|
||||
pdf.CellFormat(0, 6, title, "", 1, "L", false, 0, "")
|
||||
pdf.Ln(1)
|
||||
}
|
||||
@@ -270,8 +281,23 @@ func (c *costingPDF) drawGroup(g models.ProductionHasCostDetailGroup, firstGroup
|
||||
c.drawGroupBar(g, false)
|
||||
|
||||
// Columns
|
||||
cols := []string{"No", "Parca", "Hammadde", "Kod", "Aciklama", "Renk", "Miktar", "Br", "Fiyat", "Pr.Br", "Tutar(TRY)"}
|
||||
wn := []float64{10, 24, 24, 40, 90, 18, 18, 12, 20, 14, 24} // sum ~294 (A4 landscape width minus margins)
|
||||
// Keep total width <= A4 landscape printable width (297 - left/right margins).
|
||||
// Also force USD/TRY unit+total columns to always be visible.
|
||||
cols := []string{
|
||||
"No",
|
||||
"Parca",
|
||||
"Hammadde",
|
||||
"Kod",
|
||||
"Aciklama",
|
||||
"Renk",
|
||||
"Miktar",
|
||||
"Br",
|
||||
"USD\nFiyat",
|
||||
"USD\nTutar",
|
||||
"TRY\nFiyat",
|
||||
"TRY\nTutar",
|
||||
}
|
||||
wn := []float64{8, 20, 22, 32, 70, 14, 14, 10, 16, 16, 16, 16} // sum = 250
|
||||
|
||||
c.drawTableHeader(cols, wn)
|
||||
for _, it := range g.Items {
|
||||
@@ -297,10 +323,29 @@ func (c *costingPDF) drawTableHeader(cols []string, wn []float64) {
|
||||
pdf.SetFont("dejavu", "B", 8)
|
||||
pdf.SetFillColor(30, 30, 30)
|
||||
pdf.SetTextColor(255, 255, 255)
|
||||
|
||||
// Compute a stable header height based on wrapped labels.
|
||||
maxLines := 1
|
||||
for i, col := range cols {
|
||||
pdf.CellFormat(wn[i], 5.5, col, "1", 0, "C", true, 0, "")
|
||||
lines := pdf.SplitLines([]byte(col), wn[i]-1.6)
|
||||
if len(lines) > maxLines {
|
||||
maxLines = len(lines)
|
||||
}
|
||||
}
|
||||
pdf.Ln(5.5)
|
||||
lineH := 3.5
|
||||
headerH := float64(maxLines)*lineH + 1.2
|
||||
if headerH < 7.0 {
|
||||
headerH = 7.0
|
||||
}
|
||||
|
||||
x0 := pdf.GetX()
|
||||
y0 := pdf.GetY()
|
||||
x := x0
|
||||
for i, col := range cols {
|
||||
c.drawHeaderCellWrap(x, y0, wn[i], headerH, col)
|
||||
x += wn[i]
|
||||
}
|
||||
pdf.SetXY(x0, y0+headerH)
|
||||
pdf.SetTextColor(0, 0, 0)
|
||||
}
|
||||
|
||||
@@ -319,9 +364,28 @@ func (c *costingPDF) drawRowWithGroup(it models.ProductionHasCostDetailGroupItem
|
||||
pdf := c.pdf
|
||||
pdf.SetFont("dejavu", "", 7.2)
|
||||
|
||||
// Compute row height based on description wrapping.
|
||||
// Compute row height based on key wrapped cells.
|
||||
parcaLines := pdf.SplitLines([]byte(strings.TrimSpace(it.SParcaAdi)), wn[1]-2)
|
||||
hLabel := strings.TrimSpace(it.NHammaddeTuruNo)
|
||||
if strings.TrimSpace(it.SHammaddeTuruAdi) != "" {
|
||||
hLabel = hLabel + " " + strings.TrimSpace(it.SHammaddeTuruAdi)
|
||||
}
|
||||
hLines := pdf.SplitLines([]byte(hLabel), wn[2]-2)
|
||||
kodLines := pdf.SplitLines([]byte(strings.TrimSpace(it.SKodu)), wn[3]-2)
|
||||
descLines := pdf.SplitLines([]byte(strings.TrimSpace(it.SAciklama)), wn[4]-2)
|
||||
rowH := float64(len(descLines)) * 3.5
|
||||
|
||||
maxLines := len(descLines)
|
||||
if len(parcaLines) > maxLines {
|
||||
maxLines = len(parcaLines)
|
||||
}
|
||||
if len(hLines) > maxLines {
|
||||
maxLines = len(hLines)
|
||||
}
|
||||
if len(kodLines) > maxLines {
|
||||
maxLines = len(kodLines)
|
||||
}
|
||||
|
||||
rowH := float64(maxLines) * 3.5
|
||||
if rowH < 5.0 {
|
||||
rowH = 5.0
|
||||
}
|
||||
@@ -336,15 +400,11 @@ func (c *costingPDF) drawRowWithGroup(it models.ProductionHasCostDetailGroupItem
|
||||
|
||||
c.drawCell(x0, y0, wn[0], rowH, it.NOnMLDetNo, "R")
|
||||
x := x0 + wn[0]
|
||||
c.drawCell(x, y0, wn[1], rowH, strings.TrimSpace(it.SParcaAdi), "L")
|
||||
c.drawCellWrap(x, y0, wn[1], rowH, strings.TrimSpace(it.SParcaAdi), "L")
|
||||
x += wn[1]
|
||||
hLabel := strings.TrimSpace(it.NHammaddeTuruNo)
|
||||
if strings.TrimSpace(it.SHammaddeTuruAdi) != "" {
|
||||
hLabel = hLabel + " " + strings.TrimSpace(it.SHammaddeTuruAdi)
|
||||
}
|
||||
c.drawCell(x, y0, wn[2], rowH, hLabel, "L")
|
||||
c.drawCellWrap(x, y0, wn[2], rowH, hLabel, "L")
|
||||
x += wn[2]
|
||||
c.drawCell(x, y0, wn[3], rowH, strings.TrimSpace(it.SKodu), "L")
|
||||
c.drawCellWrap(x, y0, wn[3], rowH, strings.TrimSpace(it.SKodu), "L")
|
||||
x += wn[3]
|
||||
c.drawCellWrap(x, y0, wn[4], rowH, strings.TrimSpace(it.SAciklama), "L")
|
||||
x += wn[4]
|
||||
@@ -355,24 +415,38 @@ func (c *costingPDF) drawRowWithGroup(it models.ProductionHasCostDetailGroupItem
|
||||
c.drawCell(x, y0, wn[7], rowH, strings.TrimSpace(it.SBirim), "C")
|
||||
x += wn[7]
|
||||
|
||||
// Prefer input price if present; otherwise lFiyat.
|
||||
price := it.LFiyat
|
||||
cur := strings.TrimSpace(it.SDovizCinsi)
|
||||
if it.FiyatGirilen != nil && *it.FiyatGirilen > 0 {
|
||||
price = *it.FiyatGirilen
|
||||
if strings.TrimSpace(it.FiyatDoviz) != "" {
|
||||
cur = strings.TrimSpace(it.FiyatDoviz)
|
||||
}
|
||||
}
|
||||
c.drawCell(x, y0, wn[8], rowH, pdfMoney(price), "R")
|
||||
// Always show USD/TRY unit+total.
|
||||
// In URETIM schema: lFiyat/lTutar are in TRY, lDovizFiyati/usdTutar are in USD.
|
||||
c.drawCell(x, y0, wn[8], rowH, pdfMoney(it.LDovizFiyati), "R")
|
||||
x += wn[8]
|
||||
c.drawCell(x, y0, wn[9], rowH, cur, "C")
|
||||
usdTotal := it.USDTutar
|
||||
if usdTotal == 0 && it.LMiktar != 0 && it.LDovizFiyati != 0 {
|
||||
usdTotal = it.LMiktar * it.LDovizFiyati
|
||||
}
|
||||
c.drawCell(x, y0, wn[9], rowH, pdfMoney(usdTotal), "R")
|
||||
x += wn[9]
|
||||
c.drawCell(x, y0, wn[10], rowH, pdfMoney(it.LTutar), "R")
|
||||
|
||||
// Prefer input price if present; otherwise lFiyat.
|
||||
unitTRY := it.LFiyat
|
||||
if it.FiyatGirilen != nil && *it.FiyatGirilen > 0 && strings.EqualFold(strings.TrimSpace(it.FiyatDoviz), "TRY") {
|
||||
unitTRY = *it.FiyatGirilen
|
||||
}
|
||||
c.drawCell(x, y0, wn[10], rowH, pdfMoney(unitTRY), "R")
|
||||
x += wn[10]
|
||||
c.drawCell(x, y0, wn[11], rowH, pdfMoney(it.LTutar), "R")
|
||||
|
||||
pdf.SetXY(x0, y0+rowH)
|
||||
}
|
||||
|
||||
func (c *costingPDF) drawHeaderCellWrap(x, y, w, h float64, txt string) {
|
||||
pdf := c.pdf
|
||||
pdf.Rect(x, y, w, h, "DF")
|
||||
pdf.SetXY(x+0.8, y+0.6)
|
||||
pdf.MultiCell(w-1.6, 3.5, txt, "", "C", true)
|
||||
// restore cursor (MultiCell moves Y)
|
||||
pdf.SetXY(x+w, y)
|
||||
}
|
||||
|
||||
func (c *costingPDF) drawCell(x, y, w, h float64, txt, align string) {
|
||||
pdf := c.pdf
|
||||
pdf.Rect(x, y, w, h, "")
|
||||
|
||||
Reference in New Issue
Block a user