Full Source Code
โค้ดทั้งหมดพร้อมคำอธิบาย
COA.4gl — 802 บรรทัด • แบ่งเป็น 18 ส่วน
ส่วนหัวโปรแกรม (Program Header)
ข้อมูลพื้นฐานของโปรแกรม เช่น Session ID, ชื่อผู้พัฒนา, วันที่สร้าง — ใช้เครื่องหมาย | เป็น Comment
| 1 | |****************************************************************************** |
| 2 | |* sccoa0603p100 0 VRC B61U a ptvo |
| 3 | |* Certificate of Analysis Printing |
| 4 | |* Jarat |
| 5 | |* 2009-06-02 |
| 6 | |****************************************************************************** |
| 7 | |* Main table sccoa003 COA Header, Form Type 4 |
| 8 | |****************************************************************************** |
ประวัติการแก้ไข (Change Log)
บันทึกการเปลี่ยนแปลงโปรแกรมตั้งแต่ปี 2009–2026 พร้อมหมายเลข Change Request
| 9 | | Program Narrative |
| 10 | | |
| 11 | | Date Ref No. Description |
| 12 | | --------- ---------- ------------------------------------------------------ |
| 13 | | 2009Dec21 SAL2009004 Get item description from item code system |
| 14 | | 2009Dec23 QMS2009017 Format date for char EXPIRE_D to DD/MM/YY |
| 15 | | 2010Jul02 QMS2010001 Modified Form COA |
| 16 | | 2011Jun07 QMS2011001 Get specification for characteristic type Option Set |
| 17 | | from text note in Quality-Id line |
| 18 | | 2012Sep25 QMS2012001 Modify for req no# QMS-2012-001 |
| 19 | | |
| 20 | | 10.6***** |
| 21 | | 2018Sep13 LN10600000 Modify for LN 10.6 |
| 22 | | 2026Jan06 QAD2026001 Modify for req no# QAD-2026-01-001 |
| 23 | | Extend decimal for RE_DEN25 |
| 24 | | 2026Feb02 QAD2026002 Modify for req no# QAD-2026-02-001 |
| 25 | | Extend decimal for RI_25C |
| 26 | | |
ส่วนประกาศ (Declaration)
ประกาศตารางฐานข้อมูลทั้งหมดที่ใช้ (17 ตาราง) ด้วยคำสั่ง table — เป็นการบอกให้ 4GL รู้จักตาราง
| 27 | |****************************** declaration section *************************** |
| 28 | declaration: |
| 29 | #include<bic_text> |
| 30 | |
| 31 | table tsccoa003 | COA Header |
| 32 | table tsccoa004 | COA Details |
| 33 | table tqmptc001 | Characteristic |
| 34 | table tqmptc002 | Aspect |
| 35 | table ttccom100 | Business Partner |
| 36 | table ttccom130 | Address |
| 37 | table ttcibd001 | Item Genteral |
| 38 | table ttcmcs007 | Unit by Language |
| 39 | table tqmptc014 | Options |
| 40 | table tqmptc015 | Quality ID - Characteristic |
| 41 | table tqmptc100 | Inspection Order |
| 42 | table tsccoa007 | Source of Origin |
| 43 | table ttcmcs001 | Unit |
| 44 | table ttcibd004 | Item Code system |
| 45 | |** QMS2010001 - 2010/07/02 -- START |
| 46 | table tsccoa008 | Specification by Business Partner and Item |
| 47 | table tsccoa009 | Remark by Item/Business Partner |
| 48 | table ttdsls400 |
| 49 | |** QMS2010001 - 2010/07/02 -- END |
| 50 | table ttccom001 | Employee |
| 51 |
ประกาศตัวแปร (Variables)
extern domain = ตัวแปรผูกกับ UI/Report, fixed = แสดงบนหน้าจอเท่านั้น, long = จำนวนเต็ม, boolean = true/false
| 52 | extern domain tcmcs.str9 coan.f fixed |
| 53 | extern domain tcmcs.str9 coan.t fixed |
| 54 | extern domain tccom.bpid bpid.f fixed |
| 55 | extern domain tccom.bpid bpid.t fixed |
| 56 | |
| 57 | extern domain tcdsca rpt.result |
| 58 | extern domain tcmcs.str100m bp.name |
| 59 | extern domain tcmcs.str100m item.dsca |
| 60 | extern domain tcmcs.str100m item.dsca2 |
| 61 | extern domain tcmcs.long rpt.seq |
| 62 | extern domain tcmcs.str10 rpt.mfg.date |
| 63 | extern domain tcmcs.str10 rpt.exp.date |
| 64 | extern domain tcmcs.str10 rpt.deli.date |
| 65 | extern domain tcdsca rpt.storage |
| 66 | extern domain tcmcs.str50 rpt.source |
| 67 | extern domain tcdsca rpt.lbl.01 |
| 68 | extern domain tcdsca rpt.lbl.02 |
| 69 | extern domain tcdsca rpt.lbl.03 |
| 70 | extern domain tcdsca rpt.lbl.04 |
| 71 | extern domain tcdsca rpt.lbl.05 |
| 72 | extern domain tcdsca rpt.lbl.06 |
| 73 | extern domain tcdsca rpt.lbl.07 |
| 74 | extern domain tcdsca rpt.lbl.08 |
| 75 | extern domain tcdsca rpt.lbl.09 |
| 76 | extern domain tcdsca rpt.lbl.10 |
| 77 | extern domain tcdsca rpt.lbl.11 |
| 78 | extern domain tcdsca rpt.lbl.12 |
| 79 | extern domain tcdsca rpt.lbl.13 |
| 80 | extern domain tcdsca rpt.lbl.14 |
| 81 | extern domain tcdsca rpt.lbl.15 |
| 82 | extern domain tcdsca rpt.lbl.16 |
| 83 | extern domain tcdsca rpt.lbl.17 |
| 84 | extern domain tcdsca rpt.lbl.18 |
| 85 | extern domain tcmcs.str132 rpt.lbl.19 |
| 86 | extern domain tcdsca rpt.lbl.20 |
| 87 | extern domain tcdsca rpt.lbl.21 |
| 88 | |
| 89 | extern domain tcdsca rpt.lbl.22 |
| 90 | extern domain tcdsca rpt.lbl.23 |
| 91 | extern domain tcdsca rpt.lbl.24 |
| 92 | |
| 93 | extern domain tcdsca rpt.unit |
| 94 | extern domain tcmcs.long rpt.show.dt |
| 95 | extern domain tcdsca rpt.spec |
| 96 | |** QMS2010001 - 2010/07/02 -- START |
| 97 | |extern domain aostr150 text.description(3) |
| 98 | extern domain aostr150 text.description(5) |
| 99 | |** QMS2010001 - 2010/07/02 -- END |
| 100 | extern domain tcdsca rpt.char.unit |
| 101 | extern domain tcmcs.str60m rpt.char.desc |
| 102 | extern domain tcdsca rpt.packaging |
| 103 | extern domain tcmcs.str132 rpt.iso |
| 104 | |** QMS2010001 - 2010/07/02 -- START |
| 105 | extern domain aostr150 remark.text1(2) |
| 106 | extern domain aostr150 remark.text2(3) |
| 107 | |** QMS2010001 - 2010/07/02 -- END |
| 108 | extern domain tcdsca Vender_No |
| 109 | extern domain tcdsca Vender_Manu |
| 110 | extern domain tcdsca PO |
| 111 | extern domain tcmcs.long out.off.spec |
| 112 | |
| 113 | extern domain tcclot rpt.lot.number |
| 114 | extern domain tcdate rpt.sample.date |
| 115 | extern domain tcmcs.str30 rpt.inv.no |
| 116 | |
| 117 | long row.count |
| 118 | long ix |
| 119 | long ret |
| 120 | |
| 121 | long rec, rpt, rpt2 |
| 122 | boolean first.time |
| 123 | boolean first.time.2 |
| 124 | long coa.type |
เริ่มต้นโปรแกรม (before.program)
ทำงานก่อนโปรแกรมเริ่ม — นำเข้าค่า COA Number และ Business Partner จากหน้าจอก่อนหน้า ด้วย import()
| 125 | |****************************** program section ******************************** |
| 126 | before.program: |
| 127 | if sel.parent.num.selected() > 0 then |
| 128 | import("sccoa003.ofbp", bpid.f) |
| 129 | import("sccoa003.ofbp", bpid.t) |
| 130 | import("sccoa003.coan", coan.f) |
| 131 | import("sccoa003.coan", coan.t) |
| 132 | else |
| 133 | bpid.t = "ZZZZZZZZZ" |
| 134 | endif |
| 135 | |
| 136 | if isspace(bpid.t) then |
| 137 | bpid.t = "ZZZZZZZZZ" |
| 138 | endif |
| 139 | |
| 140 | |coan.t = "ZZZZZZZZZ" |
ปุ่มคำสั่ง (Choice Section)
choice.cont.process = ปุ่ม Continue, choice.print.data = ปุ่ม Print — เปิดรายงานด้วย rprt_open() แล้วเรียก read.main.table()
| 141 | |****************************** group section ********************************** |
| 142 | |
| 143 | group.1: |
| 144 | init.group: |
| 145 | get.screen.defaults() |
| 146 | |
| 147 | |****************************** choice section ******************************** |
| 148 | |
| 149 | choice.cont.process: |
| 150 | on.choice: |
| 151 | execute(print.data) |
| 152 | |
| 153 | choice.print.data: |
| 154 | on.choice: |
| 155 | if rprt_open() then |
| 156 | read.main.table() |
| 157 | rprt_close() |
| 158 | else |
| 159 | choice.again() |
| 160 | endif |
| 161 |
Event เมื่อเปลี่ยนค่า (Field Section)
เมื่อกรอก COA Number (From) ค่า To จะถูกตั้งเป็นค่าเดียวกันอัตโนมัติ — เพื่อ UX ที่ดีกว่า
| 162 | |
| 163 | |****************************** field section ********************************* |
| 164 | |
| 165 | field.coan.f: |
| 166 | when.field.changes: |
| 167 | coan.t = coan.f |
| 168 | |
| 169 | field.bpid.f: |
| 170 | when.field.changes: |
| 171 | bpid.t = bpid.f |
| 172 | |
| 173 |
ฟังก์ชันหลัก read.main.table() — เริ่มต้น
detail.per.page=20 กำหนดบรรทัดต่อหน้า, เรียก initial.label(), SELECT จาก sccoa003 ตามช่วงที่กำหนด
| 174 | |****************************** function section ****************************** |
| 175 | |
| 176 | functions: |
| 177 | |
| 178 | function extern read.main.table() |
| 179 | { |
| 180 | domain tcmcs.str9 temp.coa |
| 181 | domain tcyesno first |
| 182 | long i |
| 183 | long detail.per.page |
| 184 | |** QMS2009017 - 2009/12/21 -- START |
| 185 | domain tcmcs.str10 expire.date |
| 186 | |** QMS2009017 - 2009/12/21 -- END |
| 187 | |
| 188 | |** QMS2010001 - 2010/07/02 -- START |
| 189 | |Change detail per page from 25 to 23 |
| 190 | |detail.per.page = 25 | Detail line per page |
| 191 | |detail.per.page = 23 | Detail line per page |
| 192 | detail.per.page = 20 | Detail line per page |Jarat 2019-03-04 |
| 193 | |** QMS2010001 - 2010/07/02 -- END |
| 194 | |
| 195 | initial.label() |
| 196 | |
| 197 | rpt.seq = 0 |
| 198 | row.count = 0 |
| 199 | first = tcyesno.yes |
| 200 | rpt.show.dt = 1 |
| 201 | out.off.spec = 0 |
| 202 | first.time = true |
| 203 | first.time.2 = true |
| 204 | |
| 205 | select sccoa003.* |
| 206 | from sccoa003 |
| 207 | where sccoa003.coan >= {:coan.f} and sccoa003.coan <= {:coan.t} |
| 208 | and sccoa003.ofbp >= {:bpid.f} and sccoa003.ofbp <= {:bpid.t} |
| 209 | order by sccoa003.coan |
| 210 | selectdo |
แยกรายงาน Local / Export
ตรวจประเทศลูกค้า (ccty="THA" = Local, อื่น = Export) เเล้วเปิดรายงาน BRP ที่ต่างกัน ด้วย brp.open()
| 211 | |
| 212 | |Check out of specification |
| 213 | if sccoa003.tbvr = tcyesno.no then |
| 214 | |
| 215 | select tccom100.* |
| 216 | from tccom100 |
| 217 | where tccom100.bpid = {:sccoa003.stbp} |
| 218 | selectdo |
| 219 | endselect |
| 220 | |
| 221 | select tccom130.* |
| 222 | from tccom130 |
| 223 | where tccom130.cadr = {:tccom100.cadr} |
| 224 | selectdo |
| 225 | endselect |
| 226 | |
| 227 | if tccom130.ccty = "THA" then |
| 228 | coa.type = 1 |Local |
| 229 | |
| 230 | if first.time = true then |
| 231 | rpt = brp.open("rsccoa060301000", "S", 0) |
| 232 | first.time = false |
| 233 | endif |
| 234 | else |
| 235 | coa.type = 2 |Export |
| 236 | |
| 237 | if first.time.2 = true then |
| 238 | rpt2 = brp.open("rsccoa060401000", "S", 0) |
| 239 | first.time.2 = false |
| 240 | endif |
| 241 | endif |
ดึงข้อมูลสินค้าและคู่ค้า
ดึงข้อมูล Item จาก tcibd001, ดึง Remark, ดึง PO Number จาก tdsls400, ดึงชื่อ QA Manager จาก tccom001
| 242 | |
| 243 | select tcibd001.* |
| 244 | from tcibd001 |
| 245 | where tcibd001.item = {:sccoa003.item} |
| 246 | selectdo |
| 247 | endselect |
| 248 | |
| 249 | | if first = tcyesno.yes then |
| 250 | | temp.coa = sccoa003.coan |
| 251 | | first = tcyesno.no |
| 252 | |
| 253 | | Get Text from Text Edit |
| 254 | |** QMS2010001 - 2010/07/02 -- START |
| 255 | |ret = text.to.buf("sccoa003.txta", language$, 3, text.description) |
| 256 | get.remark() |
| 257 | |** QMS2010001 - 2010/07/02 -- END |
| 258 | | endif |
| 259 | |
| 260 | PO = "" |
| 261 | select tdsls400.refb from tdsls400 |
| 262 | where tdsls400.orno = {:sccoa003.orno} |
| 263 | selectdo |
| 264 | PO = "PO : " & trim$(tdsls400.refb) |
| 265 | endselect |
PO Number และ QA Manager
ดึง PO จาก Sales Order (tdsls400), ดึงชื่อ QA Manager จาก Employee Table (tccom001)
| 266 | |
| 267 | |Get QM Manager |
| 268 | rpt.lbl.22 = "" |
| 269 | select tccom001.nama, tccom001.namb |
| 270 | from tccom001 |
| 271 | where tccom001.emno = {:sccoa003.qamn} |
| 272 | selectdo |
| 273 | rpt.lbl.22 = tccom001.namb |QA Manager |
| 274 | endselect |
| 275 | |
| 276 | rpt.seq = 0 |
| 277 | row.count = 0 |
| 278 | first = tcyesno.yes |
| 279 | rpt.show.dt = 1 |
| 280 | |
| 281 | rpt.inv.no = sccoa003.invo |
| 282 | rpt.sample.date = 0 |
วนอ่าน COA Detail — จัดรูปแบบผลทดสอบ
JOIN sccoa004 กับ qmptc001, จัดรูปแบบวันที่/ชื่อ/ผล ตามประเภท (Option/Fraction/Integer) ด้วย edit$()
| 283 | |
| 284 | select sccoa004.*, qmptc001.* |
| 285 | from sccoa004 JOIN qmptc001 ON qmptc001.char = sccoa004.char |
| 286 | where sccoa004.coan = {:sccoa003.coan} |
| 287 | order by sccoa004.prts |
| 288 | selectdo |
| 289 | |
| 290 | | rpt.lbl.22 = sccoa003.qamn |QA Manager |*** move to above |
| 291 | |
| 292 | | if sccoa003.coan = temp.coa then |
| 293 | | rpt.show.dt = 1 |
| 294 | | else |
| 295 | | | Print form |
| 296 | | rpt.show.dt = 2 |
| 297 | | if row.count < detail.per.page then |
| 298 | | for i = row.count to detail.per.page |
| 299 | | rprt_send() |
| 300 | | endfor |
| 301 | | endif |
| 302 | | rpt.seq = 0 |
| 303 | | row.count = 0 |
| 304 | | |
| 305 | | | Clear array |
| 306 | | |** QMS2010001 - 2010/07/02 -- START |
| 307 | | | for ix=1 to 3 |
| 308 | | | text.description(1,ix) = "" |
| 309 | | | endfor |
| 310 | | |** QMS2010001 - 2010/07/02 -- END |
| 311 | | |
| 312 | | | Get Text from Text Edit |
| 313 | | |** QMS2010001 - 2010/07/02 -- START |
| 314 | | |ret = text.to.buf("sccoa003.txta", language$, 3, text.description) |
| 315 | | get.remark() |
| 316 | | |** QMS2010001 - 2010/07/02 -- END |
| 317 | | endif |
| 318 | |
| 319 | rpt.seq = rpt.seq + 1 |
| 320 | row.count = row.count + 1 |
| 321 | rpt.storage = trim$(sccoa003.cwar) & "/" & trim$(sccoa003.loca) |
| 322 | rpt.mfg.date = sprintf$("%D(%02d/%02m/%04Y)", convert.utc.to.date(sccoa003.mfgd)) |
| 323 | |If no expiry date, Do not show on COA |
| 324 | if sccoa003.expd > 0 then |
| 325 | rpt.exp.date = sprintf$("%D(%02d/%02m/%04Y)", convert.utc.to.date(sccoa003.expd)) |
| 326 | else |
| 327 | rpt.exp.date = "" |
| 328 | endif |
| 329 | rpt.deli.date = sprintf$("%D(%02d/%02m/%04Y)", convert.utc.to.date(sccoa003.ddte)) |
| 330 | bp.name = trim$(sccoa003.stbp) & " " & strip$(tccom130.ln01) & " " & strip$(tccom130.ln02) |
| 331 | item.dsca = trim$(sccoa003.item) & " " & strip$(tcibd001.dsca) |
| 332 | rpt.char.desc = qmptc001.dsca |
| 333 | |
| 334 | |** SAL2009004 - 2009/12/21 -- START |
| 335 | | select tcibd004.aitc |
| 336 | | from tcibd004 |
| 337 | | where tcibd004.bpid = {:sccoa003.stbp} and tcibd004.item = {:sccoa003.item} |
| 338 | | and tcibd004.citt = "UNI" |
| 339 | | selectdo |
| 340 | | if sccoa003.stbp(1;6) <> "110217" then |
| 341 | | item.dsca = trim$(sccoa003.item) & " " & strip$(tcibd001.dsca) |
| 342 | | item.dsca2 = strip$(tcibd004.aitc) |
| 343 | | else |
| 344 | | item.dsca = strip$(tcibd001.dsca) |
| 345 | | endif |
| 346 | | endselect |
| 347 | |
| 348 | select tcibd004.aitc |
| 349 | from tcibd004 |
| 350 | where tcibd004.citt = "UN1" |
| 351 | and tcibd004.bpid = {:sccoa003.stbp} and tcibd004.item = {:sccoa003.item} |
| 352 | selectdo |
| 353 | item.dsca = trim$(sccoa003.item) & " " & strip$(tcibd004.aitc) |
| 354 | |item.dsca2 = strip$(tcibd004.aitc) |
| 355 | |
| 356 | endselect |
| 357 | |
| 358 | |========= Thanakorn Vender Code Nestle =============== |
| 359 | if sccoa003.stbp(1;6) = "110472" then |
| 360 | Vender_No = "VenderSiteNo: 100786789" |
| 361 | Vender_Manu = "VenderSiteCity:SamutPrakan TH" |
| 362 | endif |
| 363 | |
| 364 | |
| 365 | |
| 366 | |** SAL2009004 - 2009/12/21 -- END |
| 367 | |
| 368 | if qmptc001.ctyp = qmptc.ctyp.option then |
| 369 | select qmptc014.* |
| 370 | from qmptc014 |
| 371 | where qmptc014.oset = {:sccoa004.oset} and qmptc014.optn = {:sccoa004.mopt} |
| 372 | selectdo |
| 373 | |rpt.result = sccoa004.mopt |
| 374 | rpt.result = qmptc014.dsca |
| 375 | endselect |
| 376 | else |
| 377 | if qmptc001.ctyp = qmptc.ctyp.fraction then |
| 378 | if trim$(sccoa004.char) = "SP_GRAV2" or trim$(sccoa004.char) = "COLOR_C1" |
| 379 | or trim$(sccoa004.char) = "REL_DENS" |
| 380 | or trim$(sccoa004.char) = "RI_25C" |2026-02-02 - QAD2026002 |
| 381 | or trim$(sccoa004.char) = "RE_DEN25" then |2026-01-06 - QAD2026001 |
| 382 | rpt.result = edit$(sccoa004.mval, "ZZZZZZ9VD9999") |
| 383 | else |
| 384 | rpt.result = edit$(sccoa004.mval, "ZZZZZZZZ9VD99") |
| 385 | endif |
| 386 | else |
| 387 | if qmptc001.ctyp = qmptc.ctyp.integer then |
| 388 | rpt.result = edit$(sccoa004.mval, "ZZZZZZZZZZZ9") |
| 389 | |
| 390 | |** QMS2009017 - 2009/12/21 -- START |
| 391 | if trim$(sccoa004.char) = "EXPIRE_D" then |
| 392 | expire.date = trim$(str$(sccoa004.mval)) |
| 393 | if len(trim$(expire.date)) = 8 then |
| 394 | rpt.result = expire.date(7;2) & "/" & expire.date(5;2) & "/" & expire.date(1;4) |
| 395 | else |
| 396 | if len(trim$(expire.date)) = 6 then |
| 397 | rpt.result = expire.date(1;2) & "/" & expire.date(3;2) & "/" & expire.date(5;2) |
| 398 | else |
| 399 | if len(trim$(expire.date)) = 5 then |
| 400 | rpt.result = "0" & expire.date(1;1) & "/" & expire.date(2;2) & "/" & expire.date(4;2) |
| 401 | endif |
| 402 | endif |
| 403 | endif |
| 404 | endif |
| 405 | |** QMS2009017 - 2009/12/21 -- END |
| 406 | endif |
| 407 | endif |
| 408 | endif |
คำนวณ Specification (Min/Max/Range/Fixed)
คำนวณค่า Spec ตามประเภท: Min (llmt), Max (ulmt), Range (llmt-ulmt), MinVal, MaxVal, Fixed (fxsp)
| 409 | |
| 410 | | Unit |
| 411 | select tcmcs001.* |
| 412 | from tcmcs001 |
| 413 | where tcmcs001.cuni = {:sccoa004.chun} |
| 414 | selectdo |
| 415 | endselect |
| 416 | |
| 417 | if (trim$(sccoa004.chun) = "-") or isspace(sccoa004.chun) then |
| 418 | rpt.char.unit = "" |
| 419 | else |
| 420 | rpt.char.unit = tcmcs001.dsca |
| 421 | endif |
| 422 | |
| 423 | | Get Unit by Language |
| 424 | select tcmcs007.* |
| 425 | from tcmcs007 |
| 426 | where tcmcs007.cuni = {:sccoa003.cuqs} and tcmcs007.clan = "ENG" |
| 427 | selectdo |
| 428 | rpt.unit = tcmcs007.dsca |
| 429 | rpt.packaging = tcmcs007.dsca |
| 430 | selectempty |
| 431 | rpt.unit = sccoa003.cuqs |
| 432 | rpt.packaging = sccoa003.cuqs |
| 433 | endselect |
| 434 | |
| 435 | | Packaging |
| 436 | if (trim$(tcibd001.cpcl) = "FG00") or |
| 437 | (trim$(tcibd001.cpcl) = "FG01") or |
| 438 | (trim$(tcibd001.cpcl) = "FG02") then |
| 439 | rpt.packaging = trim$(tcibd001.dscd) |
| 440 | endif |
| 441 | |
| 442 | if trim$(tcibd001.item) = "03020" then |
| 443 | rpt.packaging = "IBC" |
| 444 | endif |
| 445 | |
| 446 | | Source of Origin |
| 447 | select sccoa007.* |
| 448 | from sccoa007 |
| 449 | where sccoa007.sorg = {:sccoa003.orgn} |
| 450 | selectdo |
| 451 | rpt.source = sccoa007.dsca |
| 452 | selectempty |
| 453 | rpt.source = "" |
| 454 | endselect |
| 455 | |
| 456 | | Get Characteristic Standard |
| 457 | select qmptc100.* |
| 458 | from qmptc100 |
| 459 | where qmptc100.iorn = {:sccoa004.iorn} |
| 460 | selectdo |
| 461 | select qmptc015.* |
| 462 | from qmptc015 |
| 463 | where qmptc015.quid = {:qmptc100.quid} and qmptc015.char = {:sccoa004.char} |
| 464 | selectdo |
| 465 | endselect |
| 466 | endselect |
| 467 | |
| 468 | |if trim$(qmptc015.cstd) = "MIN" then |
| 469 | if sccoa004.prto = scspec.prt.opt.min then |
| 470 | if qmptc001.ctyp = qmptc.ctyp.fraction then |
| 471 | if trim$(sccoa004.char) = "SP_GRAV2" or trim$(sccoa004.char) = "COLOR_C1" |
| 472 | or trim$(sccoa004.char) = "REL_DENS" |
| 473 | or trim$(sccoa004.char) = "RI_25C" |2026-02-02 - QAD2026002 |
| 474 | or trim$(sccoa004.char) = "RE_DEN25" then |2026-01-06 - QAD2026001 |
| 475 | rpt.spec = edit$(sccoa004.mval, "ZZZ9VD9999") |
| 476 | else |
| 477 | rpt.spec = "Min. " & edit$(sccoa004.llmt, "ZZZZZ9VD99") |
| 478 | endif |
| 479 | |
| 480 | else |
| 481 | if qmptc001.ctyp = qmptc.ctyp.integer then |
| 482 | rpt.spec = "Min. " & edit$(sccoa004.llmt, "ZZZZZZZZZ9") |
| 483 | else |
| 484 | rpt.spec = "Min. " & edit$(sccoa004.llmt, "ZZZZZ9VD99") |
| 485 | endif |
| 486 | endif |
| 487 | |
| 488 | |
| 489 | else |
| 490 | |if trim$(qmptc015.cstd) = "MAX" then |
| 491 | if sccoa004.prto = scspec.prt.opt.max then |
| 492 | if qmptc001.ctyp = qmptc.ctyp.fraction then |
| 493 | if trim$(sccoa004.char) = "SP_GRAV2" or trim$(sccoa004.char) = "COLOR_C1" |
| 494 | or trim$(sccoa004.char) = "REL_DENS" |
| 495 | or trim$(sccoa004.char) = "RI_25C" |2026-02-02 - QAD2026002 |
| 496 | or trim$(sccoa004.char) = "RE_DEN25" then |2026-01-06 - QAD2026001 |
| 497 | rpt.spec = "Max. " & edit$(sccoa004.ulmt, "ZZZ9VD9999") |
| 498 | else |
| 499 | rpt.spec = "Max. " & edit$(sccoa004.ulmt, "ZZZZZ9VD99") |
| 500 | endif |
| 501 | else |
| 502 | if qmptc001.ctyp = qmptc.ctyp.integer then |
| 503 | rpt.spec = "Max. " & edit$(sccoa004.ulmt, "ZZZZZZZZZ9") |
| 504 | else |
| 505 | rpt.spec = "Max. " & edit$(sccoa004.ulmt, "ZZZZZ9VD99") |
| 506 | endif |
| 507 | endif |
| 508 | |
| 509 | |
| 510 | else |
| 511 | |if trim$(qmptc015.cstd) = "RANGE" then |
| 512 | if sccoa004.prto = scspec.prt.opt.range then |
| 513 | if qmptc001.ctyp = qmptc.ctyp.fraction then |
| 514 | if trim$(sccoa004.char) = "SP_GRAV2" or trim$(sccoa004.char) = "COLOR_C1" |
| 515 | or trim$(sccoa004.char) = "REL_DENS" |
| 516 | or trim$(sccoa004.char) = "RI_25C" |2026-02-02 - QAD2026002 |
| 517 | or trim$(sccoa004.char) = "RE_DEN25" then |2026-01-06 - QAD2026001 |
| 518 | rpt.spec = edit$(sccoa004.llmt, "ZZZ9VD9999") & " - " & trim$(edit$(sccoa004.ulmt, "ZZZ9VD9999")) |
| 519 | else |
| 520 | rpt.spec = edit$(sccoa004.llmt, "ZZZZZ9VD99") & " - " & trim$(edit$(sccoa004.ulmt, "ZZZZZ9VD99")) |
| 521 | endif |
| 522 | else |
| 523 | if qmptc001.ctyp = qmptc.ctyp.integer then |
| 524 | rpt.spec = edit$(sccoa004.llmt, "ZZZZZZZZZ9") & " - " & trim$(edit$(sccoa004.ulmt, "ZZZZZZZZZZ")) |
| 525 | else |
| 526 | rpt.spec = edit$(sccoa004.llmt, "ZZZZZ9VD99") & " - " & trim$(edit$(sccoa004.ulmt, "ZZZZZ9VD99")) |
| 527 | endif |
| 528 | endif |
| 529 | |
| 530 | |
| 531 | else |
| 532 | if sccoa004.prto = scspec.prt.opt.minval then |
| 533 | if qmptc001.ctyp = qmptc.ctyp.fraction then |
| 534 | rpt.spec = edit$(sccoa004.llmt, "ZZZZZ9VD99") |
| 535 | else |
| 536 | if qmptc001.ctyp = qmptc.ctyp.integer then |
| 537 | rpt.spec = edit$(sccoa004.llmt, "ZZZZZZZZZ9") |
| 538 | else |
| 539 | rpt.spec = edit$(sccoa004.llmt, "ZZZZZ9VD99") |
| 540 | endif |
| 541 | endif |
| 542 | else |
| 543 | |if trim$(qmptc015.cstd) = "FIX" then |
| 544 | if sccoa004.prto = scspec.prt.opt.maxval then |
| 545 | if qmptc001.ctyp = qmptc.ctyp.fraction then |
| 546 | if trim$(sccoa004.char) = "SP_GRAV2" or trim$(sccoa004.char) = "COLOR_C1" |
| 547 | or trim$(sccoa004.char) = "REL_DENS" |
| 548 | or trim$(sccoa004.char) = "RI_25C" |2026-02-02 - QAD2026002 |
| 549 | or trim$(sccoa004.char) = "RE_DEN25" then |2026-01-06 - QAD2026001 |
| 550 | rpt.spec = edit$(sccoa004.ulmt, "ZZZ9VD9999") |
| 551 | else |
| 552 | rpt.spec = edit$(sccoa004.ulmt, "ZZZZZ9VD99") |
| 553 | endif |
| 554 | else |
| 555 | if qmptc001.ctyp = qmptc.ctyp.integer then |
| 556 | rpt.spec = edit$(sccoa004.ulmt, "ZZZZZZZZZ9") |
| 557 | else |
| 558 | rpt.spec = edit$(sccoa004.ulmt, "ZZZZZ9VD99") |
| 559 | endif |
| 560 | endif |
| 561 | |
| 562 | else |
| 563 | if sccoa004.prto = scspec.prt.opt.fixed then |
| 564 | rpt.spec = sccoa004.fxsp |Fixed Specification |
| 565 | else |
| 566 | rpt.spec = "" |
| 567 | endif |
| 568 | endif |
| 569 | endif |
| 570 | endif |
| 571 | endif |
| 572 | endif |
ส่งข้อมูลไปรายงาน และปิด
brp.ready() ส่งทุก record, เติมบรรทัดว่างให้ครบหน้า, selecteos → brp.close() ปิดรายงาน
| 573 | |
| 574 | |** QMS2011001 - 2011/06/07 -- START |
| 575 | | Get Specification for Option Set from Quality-ID line |
| 576 | if qmptc001.ctyp = qmptc.ctyp.option then |
| 577 | get.specification() |
| 578 | endif |
| 579 | |** QMS2011001 - 2011/06/07 -- END |
| 580 | |
| 581 | |LN10600000 - START |
| 582 | |** QMS2012001 - 2012/09/25 -- START |
| 583 | | Get Specification for Item 01024, use business partner 000 (TVOP) |
| 584 | | Default value from TVOP |
| 585 | | select sccoa008.spec |
| 586 | | from sccoa008 |
| 587 | | where sccoa008.bpid = "000" and sccoa008.item = {:sccoa003.item} |
| 588 | | and sccoa008.char = {:sccoa004.char} |
| 589 | | selectdo |
| 590 | | rpt.spec = sccoa008.spec |
| 591 | | endselect |
| 592 | |** QMS2012001 - 2012/09/25 -- END |
| 593 | |LN10600000 - END |
| 594 | |
| 595 | |LN10600000 - START |
| 596 | |** QMS2010001 - 2010/07/02 -- START |
| 597 | | Replace Specification with Specification by BP and Item |
| 598 | | select sccoa008.* |
| 599 | | from sccoa008 |
| 600 | | where sccoa008.bpid = {:sccoa003.stbp} and sccoa008.item = {:sccoa003.item} |
| 601 | | and sccoa008.char = {:sccoa004.char} |
| 602 | | selectdo |
| 603 | | rpt.spec = sccoa008.spec |
| 604 | | endselect |
| 605 | |** QMS2010001 - 2010/07/02 -- END |
| 606 | |LN10600000 - END |
| 607 | |
| 608 | if rpt.sample.date = 0 then |
| 609 | rpt.sample.date = sccoa004.smdt |
| 610 | endif |
| 611 | |
| 612 | if coa.type = 1 then |
| 613 | brp.ready(rpt) |
| 614 | else |
| 615 | brp.ready(rpt2) |
| 616 | endif |
| 617 | |
| 618 | endselect |
| 619 | |
| 620 | | Print form |
| 621 | rpt.show.dt = 2 |
| 622 | if row.count < detail.per.page then |
| 623 | for i = row.count to detail.per.page |
| 624 | if coa.type = 1 then |
| 625 | brp.ready(rpt) |
| 626 | else |
| 627 | brp.ready(rpt2) |
| 628 | endif |
| 629 | endfor |
| 630 | endif |
| 631 | else |
| 632 | message("COA ouf of specificaion, please contact QA.") |
| 633 | endif |
| 634 | selecteos |
| 635 | if rpt > 0 then |
| 636 | brp.close(rpt) |
| 637 | endif |
| 638 | |
| 639 | if rpt2 > 0 then |
| 640 | brp.close(rpt2) |
| 641 | endif |
| 642 | endselect |
| 643 |
ฟังก์ชัน initial.label()
ตั้งค่า Label คงที่บนรายงาน เช่น Customer, Product Name, COA No., Remark, ชื่อผู้อนุมัติ, ISO Form No.
| 644 | } |
| 645 | |
| 646 | function void initial.label() |
| 647 | { |
| 648 | rpt.lbl.01 = "Customer :" |
| 649 | rpt.lbl.02 = "Product Name :" |
| 650 | rpt.lbl.03 = "COA No." |
| 651 | rpt.lbl.04 = "Storage Area/Tank" |
| 652 | rpt.lbl.05 = "Source of Origin" |
| 653 | rpt.lbl.06 = "Mfg.Date" |
| 654 | rpt.lbl.07 = "Delivery Date" |
| 655 | rpt.lbl.08 = "Truck No." |
| 656 | rpt.lbl.09 = "Packaging" |
| 657 | rpt.lbl.10 = "Quantity" |
| 658 | rpt.lbl.11 = "Unit" |
| 659 | rpt.lbl.12 = "Item" |
| 660 | rpt.lbl.13 = "Analysis" |
| 661 | rpt.lbl.14 = "Unit" |
| 662 | rpt.lbl.15 = "Specification" |
| 663 | rpt.lbl.16 = "Result" |
| 664 | rpt.lbl.17 = "Analysis Method" |
| 665 | rpt.lbl.18 = "Remark :" |
| 666 | rpt.lbl.19 = "This certificate is generated from computerized system by authorized person (Lab Chemist) not required authorized signature." |
| 667 | rpt.lbl.20 = " Approved Report" |
| 668 | rpt.lbl.21 = "Certificate of Analysis" |
| 669 | rpt.lbl.22 = " Suttichai Chaisupitanarak" |
| 670 | rpt.lbl.23 = " QA Manager" |
| 671 | rpt.lbl.24 = "Expiry Date" |
| 672 | |
| 673 | rpt.iso = "FR-QAS-001 (Revision: 0; Last modified form Aug. 10, 2009)" |
| 674 | } |
ฟังก์ชันแปลงวันที่
convert.utc.to.date() แปลง UTC → Date Number, convert.date.to.utc() แปลงกลับ — ใช้ utc.to.date() + date.to.num()
| 675 | |
| 676 | function domain tcgld.date convert.utc.to.date(domain tcdate utc.date) |
| 677 | { |
| 678 | domain tcgld.date result |
| 679 | long date.yy |
| 680 | long date.mm |
| 681 | long date.dd |
| 682 | long date.hh |
| 683 | long date.mth |
| 684 | long date.ss |
| 685 | long ret |
| 686 | |
| 687 | ret = utc.to.date(utc.date, date.yy, date.mm, date.dd, date.hh, date.mth, date.ss) |
| 688 | result = date.to.num(date.yy, date.mm, date.dd) |
| 689 | return(result) |
| 690 | } |
| 691 | |
| 692 | function domain tcdate convert.date.to.utc(domain tcgld.date num.date) |
| 693 | { |
| 694 | domain tcdate result |
| 695 | long date.yy |
| 696 | long date.mm |
| 697 | long date.dd |
| 698 | long ret |
| 699 | |
| 700 | ret = num.to.date(num.date, date.yy, date.mm, date.dd) |
| 701 | result = date.to.utc(date.yy, date.mm, date.dd, 0, 0, 0) |
| 702 | return(result) |
| 703 | } |
ฟังก์ชัน get.remark()
ดึง Remark จาก 2 แหล่ง: (1) COA Header โดยตรง (2) ตาราง sccoa009 ตาม Item/BP — มี fallback ถ้าไม่พบ
| 704 | |
| 705 | |** QMS2010001 - 2010/07/02 -- START |
| 706 | function void get.remark() { |
| 707 | boolean remark.found |
| 708 | domain tcgld.date tmp.mfg.date |
| 709 | |
| 710 | remark.found = false |
| 711 | |
| 712 | | Clear array |
| 713 | for ix=1 to 5 |
| 714 | text.description(1,ix) = "" |
| 715 | endfor |
| 716 | |
| 717 | ix = 0 |
| 718 | |
| 719 | ret = text.to.buf("sccoa003.txta", language$, 2, remark.text1) |
| 720 | if ret > 0 then |
| 721 | if not isspace(remark.text1(1,1)) then |
| 722 | ix = ix + 1 |
| 723 | text.description(1, ix) = remark.text1(1, 1) |COA Remark line 1 |
| 724 | endif |
| 725 | if not isspace(remark.text1(1,2)) then |
| 726 | ix = ix + 1 |
| 727 | text.description(1, ix) = remark.text1(1, 2) |COA Remark line 2 |
| 728 | endif |
| 729 | endif |
| 730 | |
| 731 | tmp.mfg.date = convert.utc.to.date(sccoa003.mfgd) |
| 732 | |
| 733 | | Get Remark by Item/BP |
| 734 | select sccoa009.* |
| 735 | from sccoa009 |
| 736 | where sccoa009.item = {:sccoa003.item} and sccoa009.bpid = {:sccoa003.stbp} |
| 737 | and sccoa009.datf <= {:tmp.mfg.date} and sccoa009.datt >= {:tmp.mfg.date} |
| 738 | selectdo |
| 739 | remark.found = true |
| 740 | selectempty |
| 741 | | Get Remark by Item |
| 742 | select sccoa009.* |
| 743 | from sccoa009 |
| 744 | where sccoa009.item = {:sccoa003.item} and sccoa009.bpid = " " |
| 745 | and sccoa009.datf <= {:tmp.mfg.date} and sccoa009.datt >= {:tmp.mfg.date} |
| 746 | selectdo |
| 747 | remark.found = true |
| 748 | endselect |
| 749 | endselect |
| 750 | |
| 751 | if remark.found then |
| 752 | ret = text.to.buf("sccoa009.txtn", language$, 3, remark.text2) |
| 753 | if ret > 0 then |
| 754 | if not isspace(remark.text2(1,1)) then |
| 755 | ix = ix + 1 |
| 756 | text.description(1, ix) = remark.text2(1, 1) |Remark line 1 |
| 757 | endif |
| 758 | if not isspace(remark.text2(1,2)) then |
| 759 | ix = ix + 1 |
| 760 | text.description(1, ix) = remark.text2(1, 2) |Remark line 2 |
| 761 | endif |
| 762 | if not isspace(remark.text2(1,3)) then |
| 763 | ix = ix + 1 |
| 764 | text.description(1, ix) = remark.text2(1, 3) |Remark line 3 |
| 765 | endif |
| 766 | endif |
| 767 | endif |
| 768 | } |
ฟังก์ชัน get.specification()
ดึง Specification สำหรับ Option Set จาก Text Note ของ Quality-ID line — บรรทัด 1 = Spec, บรรทัด 2 = Unit
| 769 | |** QMS2010001 - 2010/07/02 -- END |
| 770 | |
| 771 | |** QMS2011001 - 2011/06/07 -- START |
| 772 | | Get Specification for Option Set from Quality-ID line |
| 773 | | Text Note line 1 for Specification |
| 774 | | Text Note line 2 for Unit |
| 775 | function void get.specification() { |
| 776 | |
| 777 | extern domain tcmcs.str80 spec.for.option(2) |
| 778 | |
| 779 | if qmptc015.txta > 0 then |
| 780 | |
| 781 | | Clear array |
| 782 | ix = 0 |
| 783 | for ix=1 to 2 |
| 784 | spec.for.option(1,ix) = "" |
| 785 | endfor |
| 786 | |
| 787 | ret = text.to.buf("qmptc015.txta", language$, 2, spec.for.option) |
| 788 | |
| 789 | if ret > 0 then |
| 790 | | First line for Specification Option Set |
| 791 | if not isspace(spec.for.option(1,1)) then |
| 792 | rpt.spec = spec.for.option(1,1) |
| 793 | endif |
| 794 | |
| 795 | | Second line for Unit of Option Set |
| 796 | if not isspace(spec.for.option(1,2)) then |
| 797 | rpt.char.unit = spec.for.option(1,2) |
| 798 | endif |
| 799 | endif |
| 800 | endif |
| 801 | } |
| 802 | |** QMS2011001 - 2011/06/07 -- END |