สมอง BCอัปเดตล่าสุด 23 พฤศจิกายน 2569 เวลา 08:32 น.

คลังความรู้ / สเปก API และ MCP

นักพัฒนา#api#reports#menukey#pdf#drilldown

Central Report & PDF Engine ใช้ร่วมกันทั้งหน้าเว็บ POST /process/report/run, PDF POST /process/report/pdf (%PDF-1.4 + erp_report_template) และ MCP Tool bc_run_report โดยจำแนกตามรหัส menuKey ในแผนที่ menuReports (report_menu.go:30-42)


1. สัญญา Input/Output & กฎสำคัญของ Report Engine (report.go, report_options.go)

  • Input (RunReportInput): menuKey (case-insensitive), mode ("summary" / "detail" หรือ viewDetail: true), dateFrom, dateTo (YYYY-MM-DD), fromCode, toCode, orderBy, keyword, options (map[string]string สำหรับตัวกรองเฉพาะรายงาน).
  • Aliases อัตโนมัติ (reportCodeAliases ใน report.go:218-236):
    • rp_so_quotation -> menu_so_report_quotation
    • rp_so_sale_order -> menu_so_report_sale_order
    • report_vat_sale -> menu_report_vat_sale
    • report_vat_buy -> menu_report_vat_buy
    • ic_stock_balance / menu_ic_report_stock_balance / menu_ic_report_stk_balance -> menu_ic_info_stk_balance
    • menu_ic_report_stock_movement -> menu_ic_info_stk_card
    • menu_ic_report_stock_minimum -> menu_report_ic_stock_balance_warehouse_min
    • menu_ic_item_detail / menu_ic_report_item_detail -> menu_ic_detail
    • menu_ar_detail -> menu_ar_report_detail_ar
    • menu_ap_detail -> menu_ap_report_detail_ap
    • menu_po_report_purchase_item -> menu_po_recive_by_item
    • menu_so_report_sale_item -> menu_so_sale_service_by_item
    • menu_cb_report_bank_movement -> _menu_bank_statement
    • menu_fa_report_asset_list -> menu_asset_report_list
  • สิทธิ์ดูต้นทุนสินค้า (show_item_cost): หากผู้ใช้ไม่มีสิทธิ์ต้นทุน Engine จะบล็อกรายงานกำไรขั้นต้น/ต้นทุนบางตัว (ไม่มีสิทธิ์ดูต้นทุนสินค้า) หรือถอดคอลัมน์ต้นทุนออกอัตโนมัติ (dropCostColumns ใน report.go:491)
  • Strict Pro Menu Keys (edition_guard.go:11-15): รายงาน VAT ต่างประเทศ menu_gl_vat_report_sale_inter, menu_gl_vat_report_buy_inter, menu_gl_vat_report_inter_sum สงวนไว้เฉพาะ Pro Edition
  • ปี พ.ศ./ค.ศ. (applyReportYearType, readErpYearType ใน report.go:194-206): แปลงวันที่ในแถวและหัวข้อเงื่อนไขตาม erp_option.year_type (1 = พ.ศ., ค่าอื่น = ค.ศ.; หากอ่านค่าจาก erp_option ไม่ได้จะใช้ พ.ศ. 1 เป็นค่าเริ่มต้น)
  • Option Validation & ConditionText (normalizeReportOptions, appendActiveOptionsToConditionText ใน report.go:693-746): ยอมรับเฉพาะคีย์ตัวเลือกที่รายงานนั้นประกาศไว้ (checkbox, number, date, select, ranges, multi, text โดย ranges/text สามารถระบุ lookupTable เช่น ap_supplier, ar_customer, erp_branch_list สำหรับหน้าต่างค้นหารหัส) เพื่อกัน SQL smuggling และเติมเงื่อนไขที่เลือก รวมถึง ranges ลงใน ConditionText โดยอัตโนมัติ (ข้าม party_ranges ของ aparRun หากจัดรูปแบบไว้ใน rangeText แล้ว)

2. รายการ menuKey แยกตามโมดูล (Verified จากซอร์สโค้ดจริง)

หมวดสินค้าและคลัง (report_menu_ic.go — 80 menuKeys)

  • เอกสารสินค้า & ยกเลิก (14): menu_ic_report_goods_balance, menu_ic_report_item_withdraw, menu_ic_report_item_return, menu_import_item_ready_by_date, menu_ic_report_item_adjust_increase, menu_ic_report_item_adjust_decrease, menu_ic_report_item_transfer, menu_ic_report_item_count, menu_ic_report_cancel_raw_material, menu_ic_report_cancel_goods_raw_meterial, menu_ic_report_cancel_goods_pack, menu_ic_report_stk_cancel_over, menu_ic_report_stk_cancel_lost, menu_ic_report_stk_cancel
  • ยอดคงเหลือ & จุดต่ำสุด-สูงสุด (13): menu_ic_info_stk_balance, menu_ic_info_stk_balance_warehouse, menu_ic_info_stk_balance_shelf, menu_item_balance, menu_stock_balance_all_show_current_value, menu_ic_info_stk_balance_lot, menu_item_balance_lot, menu_ic_info_stk_reorder, menu_ic_report_info_stk_reorder, menu_report_ic_stock_balance_warehouse_max, menu_report_ic_stock_balance_warehouse_min, menu_report_ic_stock_balance_location_max, menu_report_ic_stock_balance_location_min
  • ความเคลื่อนไหว & สินค้าไม่เคลื่อนไหว (14): menu_ic_info_stk_movement_sum, menu_ic_info_stk_movement_sum_by_amount, menu_result_transfer_item, menu_report_ic_info_stk_movement_sum_show_amount, menu_ic_info_stk_move, menu_ic_info_stk_movement, menu_ic_info_stk_movement_hidden, menu_item_transfer, menu_account_special_item, menu_ic_info_product_no_movement, menu_item_non_transfer, menu_item_status, menu_report_ic_product_and_material, menu_item_transfer_standard
  • กำไรขั้นต้น (17): menu_ic_info_stk_profit, menu_ic_info_stk_profit_hidden, menu_ic_info_stk_profit_by_doc, menu_ic_info_stk_profit_by_ar, menu_ic_report_info_stk_profit, menu_ic_report_info_stk_profit_ic_doc, menu_ic_report_info_stk_profit_ic_cust, menu_ic_report_info_stk_profit_ic_cust_doc, menu_ic_report_info_stk_profit_doc, menu_ic_report_info_stk_profit_doc_ic, menu_ic_report_info_stk_profit_cust, menu_ic_report_info_stk_profit_cust_ic, menu_ic_report_info_stk_profit_cust_ic_doc, menu_ic_report_info_stk_profit_cust_doc, menu_ic_report_info_stk_profit_cust_doc_ic, menu_ic_report_info_stk_profit_by_doc_and_discount
  • ประวัติซื้อ-ขาย, Lot, Serial, Count & อื่นๆ (22): menu_ic_info_purchase_history, menu_ic_info_sale_history, menu_ic_detail, menu_ic_report_item_barcode, menu_ic_report_item_set_formula, menu_ic_report_item_sale_price, menu_ic_report_item_sale_price_normal, menu_ic_report_item_purchase_price, menu_diff_from_count, menu_stock_no_balance_from_count, menu_ic_by_license, menu_ic_serial_number, menu_item_balance_now_only_serial, menu_report_serial_check, menu_ic_report_item_giveaway, menu_report_lot_inventory, menu_report_inventory_adjust, menu_ic_report_sale_remain, menu_report_accrued_in_qty, menu_fastreport_other_ic

หมวดซื้อ-ขาย (SO / PO — report_menu_so_po.go 90 keys + report_menu_sopo.go 1 key)

  • ระบบซื้อ (PO & Receive — 38): menu_po_report_record_requisition_purchase, menu_po_report_requisition_purchase1, menu_po_report_requisition_cancel, menu_po_report_requisition_purchase, menu_po_report_purchase_order, menu_po_report_purchase_order_approve, menu_po_report_purchase_order_cancel, menu_po_report_purchase_order_status, menu_po_hold_receive_by_doc, menu_po_report_deposit_payment, menu_po_report_deposit_payment_return, menu_po_report_deposit_payment_cancel, menu_po_report_deposit_payment_return_cancel, menu_po_report_deposit_payment_remain, menu_po_report_cut_deposit_payment, menu_po_report_advance_payment, menu_po_report_advance_payment_return, menu_po_report_advance_payment_cancel, menu_po_report_advance_payment_return_cancel, menu_po_report_deposit_payment_2_remain, menu_po_report_cut_deposit_payment_2, menu_po_report_purchase_partial, menu_po_report_purchase_partial_debit, menu_po_report_purchase_partial_1, menu_po_report_purchase_partial_2, menu_po_report_purchase_partial_3, menu_po_report_purchase, menu_po_report_credit_note, menu_po_report_add_goods, menu_po_report_purchase_cancel, menu_po_credit_note_cancel_report, menu_po_report_add_goods_cancel, menu_report_purchase_by_date, menu_report_purchase_credit_by_date, menu_report_purchse_on_due, menu_report_sum_purchase_by_vat, menu_report_purchase_order_by_date, menu_report_purchase_add_by_date, menu_report_purchase_credit_note_by_item, menu_report_purchase_rank_item_group, menu_po_report_purchase_analyze, menu_po_recive_by_item, menu_po_report_compare_purchase_monthly, menu_fastreport_other_purchase
  • ระบบขาย (SO & Billing — 47): menu_so_report_quotation, menu_so_report_quotation_approve, menu_so_report_quotation_cancel, menu_so_report_quotation_stat, menu_so_report_inquiry, menu_so_report_inquiry_approve, menu_so_report_inquiry_cancel, menu_so_report_inquiry_stat, menu_so_report_sale_order, menu_so_report_sale_order_approve, menu_so_report_sale_order_cancel, menu_so_report_sale_order_stat, menu_so_report_deposit_receive, menu_so_report_deposit_return, menu_so_report_deposit_payment_cancel, menu_so_report_deposit_payment_return_cancel, menu_so_report_deposit_payment_remain, menu_so_report_cut_deposit_payment, menu_so_report_deposit_receive_2, menu_so_report_deposit_return_2, menu_so_report_deposit_payment_cancel_2, menu_so_report_deposit_payment_return_cancel_2, menu_so_report_deposit_payment_remain_2, menu_so_report_cut_deposit_payment_2, menu_so_report_invoice, menu_so_report_credit_note, menu_so_report_add_goods, menu_so_report_invoice_cancel, menu_so_report_credit_note_cancel, menu_so_report_add_goods_cancel, menu_so_sale_service_by_item, menu_sell_by_sale, menu_fast_report_summary_sell_by_sale, menu_shipments_by_date, menu_sale_history_product, menu_fast_report_analysis_sell_ex_by_product, menu_fast_report_analysis_sell_sum_by_docno, menu_fast_report_margin_reacceptance, menu_fast_report_product_rank, menu_compare_sale_with_price, menu_product_sale_loss, menu_fast_report_shipments_compare_month, menu_so_report_sale_drug_by_lot, menu_so_report_sale_drug_by_lot_5, menu_so_report_sale_drug_13, menu_so_report_sale_recall, menu_fastreport_other_sale

หมวดลูกหนี้ / เจ้าหนี้ (report_menu_ap_ar.go — 60 menuKeys)

  • เจ้าหนี้ยกมา & หนี้อื่น: menu_ap_report_early_year_balance_setup, menu_ap_report_early_year_balance_increase, menu_ap_report_early_year_balance_decrease, menu_documents_early_year_other, menu_increase_debt_other, menu_reduction_dept_other, menu_cancel_documents_early_year_other, menu_cancel_increase_debt_other, menu_cancel_reduction_dept_other
  • ลูกหนี้ยกมา & หนี้อื่น: menu_ar_report_early_year_balance_setup, menu_ar_report_early_year_balance_increase, menu_ar_report_early_year_balance_decrease, menu_ar_documents_early_year_other, menu_report_ar_increase_debt_other, menu_ar_reduction_dept_other, menu_ar_cancel_documents_early_year_other, menu_report_ar_cancel_increase_debt_other, menu_ar_cancel_reduction_dept_other
  • วางบิล รับชำระ จ่ายชำระ สถานะ และอายุหนี้: menu_ap_report_billing, menu_ap_report_payment, menu_ap_report_cancel_pay_bill, menu_ap_report_cancel_debt_billing, menu_ar_report_billing, menu_ar_report_receipt, menu_ar_report_cancel_pay_billing, menu_ar_report_cancel_invoice, menu_ar_report_pay_debt_trans, menu_report_ar_payment_pay_detail, menu_report_receive_money_summary, menu_ap_report_payable_status, menu_ar_report_status_ar, menu_ap_report_payable_movement, menu_ar_report_movement, menu_ap_report_payable_aging, menu_ar_report_period_ar_debt_remain, menu_ap_report_payable_aging_by_doc, menu_ar_report_period_ar_debt_remain_by_doc, menu_ap_report_detail_ap, menu_ar_report_detail_ar, menu_invoice_arrears_by_date, menu_invoice_due_by_date, menu_invoice_arrears_due, menu_invoice_overdue_by_date, menu_ar_report_invoice_remain_pay, menu_billing_value_by_invoice, menu_billing_outstanding, menu_payment_detail, menu_payment_by_invoice, menu_payment_by_date, menu_payment_by_department, menu_ap_detail_debt_by_ap, menu_ap_report_payable_not_movement, menu_ar_report_check_balance, menu_report_point_balance
  • ป้ายส่งของ & FastReport: menu_ap_transport_label_print, menu_ar_transport_label_print, menu_import_ap_transport_label, menu_import_ar_transport_label, menu_fastreport_other_supplier, menu_fastreport_other_customer

หมวดเงินสด ธนาคาร & เช็ค (report_menu_cb.go — 61 menuKeys)

  • รายได้/รายจ่ายอื่น & เงินสดย่อย: menu_cash_income_other_report, menu_cash_income_other_credit_report, menu_cash_income_other_debit_report, menu_cash_income_other_cancel_report, menu_cash_income_other_credit_cancel_report, menu_cash_income_other_debit_cancel_report, menu_cash_expense_other_report, menu_cash_expense_other_credit_report, menu_cash_expense_other_debit_report, menu_cash_expense_other_cancel_report, menu_cash_expense_other_credit_cancel_report, menu_cash_expense_other_debit_cancel_report, menu_report_cb_petty_cash_request, menu_report_cb_petty_cash_return, menu_report_cb_cancel_pettycash_request, menu_report_cb_cancel_pettycash_return, menu_peety_cash_status
  • ฝาก-ถอน-โอนธนาคาร & Statement: menu_report_cash_payin, menu_report_cash_withdraw, menu_cb_report_transfer_bank, menu_report_cancel_withdraw, menu_report_cancel_payin, menu_report_transfer_bank_cancel, _menu_cash_movements, menu_sub_cash_movements, menu_book_bank_balance, _menu_bank_statement, menu_statement_advance, menu_summary_payment, menu_summary_received
  • เช็ครับ เช็คจ่าย บัตรเครดิต & ยกเลิก: menu_cb_report_chq_in_receive_balance, menu_cb_report_chq_out_payment_balance, menu_bank_report_chq_in_deposit, menu_bank_report_chq_in_pass, menu_bank_report_chq_in_return, menu_bank_report_chq_in_pass_cancel, menu_bank_report_chq_out_pass, menu_bank_report_chq_out_pass_cancel, menu_bank_report_chq_out_return, menu_bank_report_chq_in_change, menu_bank_report_chq_out_change, menu_cb_report_chq_in_receive, menu_cb_report_chq_out_payment, menu_cb_report_credit_card_receive, menu_cb_report_credit_card_pass, menu_cb_report_chq_in_receive_by_date, menu_cb_report_chq_out_payment_by_date, menu_report_chq_receive_due_date, menu_report_chq_pay_due_date, menu_report_chq_card_enddate_card, menu_report_cb_chq_in_payin_cancel, menu_report_cb_chq_in_honor_cancle, menu_report_cb_chq_in_return_cancle, menu_report_cb_chq_cancel, menu_report_cb_chq_in_change_cancle, menu_report_cb_chq_out_honor_cancel, menu_report_cb_chq_out_cancel_hornor_cancel, menu_report_chq_out_return_cancel, menu_report_cb_chq_out_change_cancle, menu_report_cb_credit_card_cancel, menu_fastreport_other_cashbank

หมวดบัญชีแยกประเภท งบการเงิน ภาษี และสินทรัพย์ถาวร (report_menu_gl_fa.go — 61 menuKeys)

  • สินทรัพย์ถาวร (FA — 10): menu_asset_picture, menu_show_asset_byday, menu_show_asset_bymonth, menu_show_asset_byyear, menu_asset_transfers, menu_asset_report_list, menu_asset_report_depreciate, menu_asset_report_maintain, menu_asset_report_sale, menu_fastreport_other_asset
  • ผังบัญชี สมุดรายวัน & แยกประเภท (12): menu_chart_of_account_flow, menu_report_chart_of_account, menu_product_sale_cost_close, menu_journal_summary, menu_gl_show_sheet, menu_gl_show_sheet_sum, menu_gl_report_journal, menu_gl_report_journal_sum, menu_gl_report_sheet, menu_gl_report_sheet_sum, menu_gl_allocate_all, menu_gl_report_slip
  • ภาษีมูลค่าเพิ่ม VAT (14): menu_report_vat_sale, menu_report_except_vat_sale, menu_report_vat_sale_2557, menu_report_except_vat_sale_with_tax, menu_report_sum_vat_sale, menu_report_vat_buy, menu_report_except_vat_buy, menu_report_vat_buy_2557, menu_report_vat_sale_standard, menu_report_vat_buy_standard, menu_gl_vat_report_sum, menu_gl_vat_report_sale_inter 🔒, menu_gl_vat_report_buy_inter 🔒, menu_gl_vat_report_inter_sum 🔒
  • ภาษีหัก ณ ที่จ่าย WHT (4): menu_gl_wht_report_in_53, menu_gl_wht_report_in_3, menu_gl_wht_report_sum, menu_export_wht
  • งบทดลอง งบดุล งบกำไรขาดทุน & ปิดงวด (21): menu_gl_show_trial_balance, menu_gl_analysis_trial_balance, menu_gl_report_trial_balance, menu_gl_report_trial_balance_depart, menu_gl_report_trial_balance_branch, menu_display_balance_sheet, menu_gl_report_balance, menu_singha_report_balancesheet_asset, menu_gl_show_work_sheet, menu_gl_report_balance_sheet, menu_display_lost_and_profit_compare_dimension, menu_report_profit_and_lost_sum_year, menu_gl_report_profit_and_lost_branch_1, menu_gl_report_trial_balance_branch_depart, menu_report_profit_and_lost_sum_year_by_department, menu_singha_report_profit_and_lost, menu_gl_report_other_1, menu_financial_report, menu_gl_end_of_period, menu_close_account_process, menu_fastreport_other_gl

หมวด AutoCare, พนักงาน และ Singha/SaleTools

  • AutoCare (report_menu_autocare.go — 5 keys): ac_res_executive_queue, ac_res_posted_ledger, ac_res_dot_fefo_aging, ac_res_tech_wallet, ac_res_warranty_crm
  • พนักงาน (report_menu_employee.go — 1 key): menu_report_employee_group
  • Singha / BC SaleTools (report_menu_singha.go): ครอบคลุมรายงานเฉพาะธุรกิจจำหน่ายเครื่องดื่ม-คลังกระจาย (menu_singha_report_*, menu_singha_report_chequein_*) และกลุ่มเมทริกซ์ BC SaleTools Mobile Sales (คำนำหน้า menu_saletools_* ทั้งหมด 63 เมนูย่อย)

3. Column Drill-Down Specification (report_drilldown.go)

InferReportDrillEntity จำแนกคอลัมน์ในผลลัพธ์รายงานอัตโนมัติ (doc, ref, customer, supplier, party, item, account, passbook, employee, warehouse, shelf, unit, asset, department, project, branch, side, allocate, item_group) เพื่อส่งให้ Frontend และ API เปิดหน้าจอต้นทางได้ตรงบริบท:

  • ถ้าชื่อรายงานเกี่ยวกับซื้อ/เจ้าหนี้ (_po_, _ap_, purchase, supplier, vat_buy, wht_report_in) คอลัมน์คู่ค้ารวม (party) จะเปิดเจ้าหนี้ก่อน (party_ap_first)
  • ถ้าชื่อรายงานเกี่ยวกับขาย/ลูกหนี้ (_so_, _ar_, sale, customer, vat_sale) คอลัมน์คู่ค้ารวมจะเปิดลูกหนี้ก่อน (party_ar_first)
  • คอลัมน์คำว่า ประเภท ทุกชนิดจะถูกยกเว้นไม่ทำเป็น Drill-Down Master (report_drilldown.go:118-120)