บทที่ 7 / 8

ฟังก์ชันสนับสนุน (Helper Functions)

Label, Date, Remark, Specification

7 / 8
1

initial.label() — กำหนดป้ายกำกับ

ตั้งค่า Label ทั้งหมดที่จะแสดงบนรายงาน COA

ฟังก์ชัน initial.label()
function void initial.label()
{
    rpt.lbl.01 = "Customer :"
    rpt.lbl.02 = "Product Name :"
    rpt.lbl.03 = "COA No."
    rpt.lbl.04 = "Storage Area/Tank"
    rpt.lbl.05 = "Source of Origin"
    rpt.lbl.06 = "Mfg.Date"
    rpt.lbl.07 = "Delivery Date"
    rpt.lbl.08 = "Truck No."
    rpt.lbl.09 = "Packaging"
    rpt.lbl.10 = "Quantity"
    rpt.lbl.11 = "Unit"
    rpt.lbl.12 = "Item"
    rpt.lbl.13 = "Analysis"
    rpt.lbl.14 = "Unit"
    rpt.lbl.15 = "Specification"
    rpt.lbl.16 = "Result"
    rpt.lbl.17 = "Analysis Method"
    rpt.lbl.18 = "Remark :"
    rpt.lbl.19 = "This certificate is generated from computerized 
                   system by authorized person (Lab Chemist) 
                   not required authorized signature."
    rpt.lbl.20 = "   Approved Report"
    rpt.lbl.21 = "Certificate of Analysis"  
    rpt.lbl.22 = "   Suttichai Chaisupitanarak"    
    rpt.lbl.23 = "   QA Manager"
    rpt.lbl.24 = "Expiry Date"
    
    rpt.iso = "FR-QAS-001 (Revision: 0; Last modified form Aug. 10, 2009)"
}
คำอธิบาย

Label เหล่านี้กำหนดข้อความคงที่บนรายงาน เช่น:

  • ชื่อหัวข้อต่างๆ (Customer, Product Name, COA No.)
  • ข้อความ Disclaimer (rpt.lbl.19)
  • ชื่อผู้อนุมัติ (rpt.lbl.22) — QA Manager
  • หมายเลข ISO Form (rpt.iso)
2

convert.utc.to.date() — แปลงวันที่

ฟังก์ชันแปลงวันที่จากรูปแบบ UTC ของ LN เป็นรูปแบบ Date Number

ฟังก์ชันแปลงวันที่
function domain tcgld.date convert.utc.to.date(
    domain tcdate utc.date)
{
    domain  tcgld.date  result
    long    date.yy
    long    date.mm
    long    date.dd
    long    date.hh
    long    date.mth
    long    date.ss
    long    ret
    
    ret = utc.to.date(utc.date, date.yy, date.mm, date.dd, 
                      date.hh, date.mth, date.ss)
    result = date.to.num(date.yy, date.mm, date.dd)
    return(result)
}
คำอธิบาย

ใน LN วันที่จะถูกเก็บเป็น UTC (จำนวนวินาที) ฟังก์ชันนี้แปลงเป็นวันที่:

  1. utc.to.date() — แยก UTC ออกเป็น ปี, เดือน, วัน, ชั่วโมง, นาที, วินาที
  2. date.to.num() — รวมกลับเป็นตัวเลขวันที่ (เช่น 20260101)
  3. ค่าที่ได้นำไปใช้กับ sprintf$() เพื่อแสดงเป็น DD/MM/YYYY
3

get.remark() — ดึงหมายเหตุ

ดึงข้อความ Remark จากหลายแหล่ง ทั้งจาก COA โดยตรง และจากข้อมูลที่ตั้งไว้ตาม Item/Business Partner

ฟังก์ชัน get.remark()
function void get.remark() {
    boolean     remark.found
    
    remark.found = false
    
    | Clear array
    for ix=1 to 5
        text.description(1,ix) = ""
    endfor
    
    | ดึง Remark จาก COA Header
    ret = text.to.buf("sccoa003.txta", language$, 2, remark.text1)
    if ret > 0 then
        if not isspace(remark.text1(1,1)) then
            ix = ix + 1
            text.description(1, ix) = remark.text1(1, 1)
        endif
    endif
    
    | ดึง Remark จาก Item/BP
    select  sccoa009.*
    from    sccoa009
    where   sccoa009.item = {:sccoa003.item} 
            and sccoa009.bpid = {:sccoa003.stbp}
            and sccoa009.datf <= {:tmp.mfg.date} 
            and sccoa009.datt >= {:tmp.mfg.date}
    selectdo
        remark.found = true
    selectempty
        | ลองหาแบบ Item อย่างเดียว (ไม่ระบุ BP)
        select  sccoa009.*
        from    sccoa009
        where   sccoa009.item = {:sccoa003.item} 
                and sccoa009.bpid = " "
        selectdo
            remark.found = true
        endselect
    endselect
}
คำอธิบาย

กระบวนการดึง Remark:

  1. ล้างข้อมูลเก่า — Clear array text.description
  2. ดึงจาก COA Header — ข้อความที่ผู้ใช้กรอกบน COA โดยตรง (สูงสุด 2 บรรทัด)
  3. ดึงจาก Item/BP — ตาราง sccoa009 ที่ตั้งค่า Remark ไว้ล่วงหน้า
    • ค้นหาแบบเฉพาะเจาะจง (ระบุทั้ง Item + BP + ช่วงวันที่)
    • ถ้าไม่พบ ใช้ fallback ค้นหาแค่ Item อย่างเดียว

text.to.buf() คือฟังก์ชันมาตรฐาน LN ที่อ่าน Text Note (ข้อความอิสระที่แนบกับ record) มาเก็บใน array