Freight Voucher Usecase AP125 and AP1012 Programs¶
The AP125.rpg and AP1012.rpg programs together implement a single primary use case, as they form a cohesive process for creating accounts payable (A/P) voucher transactions from freight invoices. The use case is described below:
- Create A/P Voucher Transactions from Freight Invoices:
- Description: This use case processes freight invoices from the
FRCINHorFRCFBHfiles to generate A/P voucher transactions in theAPTRANfile, including header and detail records. It calculates due dates, applies discounts, prorates freight amounts across sales detail or miscellaneous records, and validates general ledger (G/L) accounts and vendor information. The process ensures accurate allocation of freight charges and compliance with payment terms and hold statuses. - Inputs: Company code (
CO), carrier ID (CAID), invoice number (CAIN), record type (RCD), reference number (RDNO), and sales-related data (order number, shipping reference number, freight total, etc.). - Outputs: A/P transaction header and detail records in
APTRAN, updated freight invoice records inFRCINHorFRCFBH, marked as processed. - Components:
AP125.rpg: Handles header creation, vendor validation, due date calculation, and G/L validation, and callsAP1012.rpgfor detail line creation.AP1012.rpg: Prorates freight amounts across sales detail (SA5FIUD,SA5MOUD) or miscellaneous (SA5FIUM,SA5MOUM) records and creates detail lines inAPTRAN.
Function Requirement Document¶
Function Requirement: Create A/P Voucher Transactions from Freight Invoices¶
Purpose¶
Automate the creation of accounts payable (A/P) voucher transactions from freight invoices, including header and detail records, by processing invoice data, validating vendor and G/L information, calculating due dates, applying discounts, and prorating freight amounts across sales detail or miscellaneous records.
Inputs¶
- Company Code (
CO): 2-digit code identifying the company. - Carrier ID (
CAID): 6-character identifier for the carrier. - Invoice Number (
CAIN): 25-character freight invoice number. - Record Type (
RCD): Indicates invoice source (FRCFBHP4for freight billed balance header, elseFRCINHP4). - Reference Number (
RDNO): Numeric reference number forFRCFBHinvoices. - Sales Data (via
SALESdata structure): - Order Number (
SAORD): 6-digit sales order number. - Shipping Reference Number (
SASRN#): 3-digit shipping reference number. - Freight Total (
FRTTOT): Total freight amount to allocate (7.2 digits). - Vendor Number (
VEND): 5-digit vendor number. - Entry Number (
ENTNUM): 5-digit A/P entry number. - Discount Percentage (
DSPC): 4.3-digit discount percentage. - Comparison Date (
CMPDT8): Invoice date minus one year (8 digits). - File Indicator (
S@FIMO):F(SA5FI files) orM(SA5MO files). - Detail/Misc Indicator (
S@DM):D(detail) orM(miscellaneous).
Outputs¶
- A/P Transaction Records: Header and detail records in
APTRANwith validated vendor, G/L, and prorated freight amounts. - Updated Freight Invoice Records:
FRCINHorFRCFBHrecords marked as processed (FRAPST = 'Y').
Process Steps¶
- Retrieve Invoice Data:
- Access
FRCINH(ifRCD ≠ 'FRCFBHP4') orFRCFBH(ifRCD = 'FRCFBHP4') usingCO,CAID,CAIN, andRDNO. -
Extract invoice number (
FRCAIN), type (FRINTY), date (FRIYMD), amount (FRINAM - FRFBOA), sales order (FRRDNO), and shipping reference (FRSRN). -
Validate Company and Generate Entry Number:
- Retrieve company details (
ACAPGL,ACCAGL,ACRTGL,ACNXTE) fromAPCONTusingCO. -
Assign a new entry number (
ENT#) fromACNXTEfor new transactions, incrementing and updatingACNXTE. -
Retrieve Vendor Information:
- Get vendor number (
VYVEND) fromAPVENYusingCOandCAID. - Retrieve vendor details (
VNVNAM,VNAD1-4,VNHOLD,VNSNGL,VNTERM,VNEXGL) fromAPVENDusingCOandVEND. -
Set hold description (
HLDD) based on hold code (VNHOLD):H: "VENDOR ON HOLD"A: "ON HOLD FOR ACH"W: "ON HOLD FOR WIRE TRANSFER"U: "ON HOLD FOR UTILITY AUTO-PAYMENT"
-
Calculate Due Date:
- If
VNTERMis non-zero, retrieve terms (TBNETD,TBPRXD,TBDISC) fromGSTABL(tableAPTERM). - Calculate due date:
- For net days (
TBNETD): AddTBNETDto invoice date (FRIYMD) using Julian date conversion. - For prox days (
TBPRXD): Set toTBPRXDday of the next month. - Default to invoice date if no terms.
- For net days (
-
Adjust due date to a non-holiday/non-weekend date using
APDATE(ADNED8). -
Validate G/L Accounts:
-
Validate A/P (
APGL), bank (BKGL), and retention (RTGL) accounts againstGLMAST, retrieving descriptions. -
Create A/P Header:
-
Write/update header in
APTRANwith invoice, vendor, G/L, due date, hold status, and discount (DSPC) data. -
Prorate Freight and Create Detail Lines:
- Call
AP1012withSALESdata structure to prorateFRTTOTacross sales records. - For Detail Records (
SA5FIUDorSA5MOUD):- Calculate total gallons (
TTLQTY) for records withS5SHD8 >= CMPDT8. - Prorate freight:
AMT = (S5NGAL / TTLQTY) * FRTTOT. - Adjust the last record to ensure the sum equals
FRTTOT. - Retrieve freight G/L (
FEGL): - If product code (
S5PROD) has alpha characters, useCUFEGLfromGSCTUM. - Else, use
TBFEG4fromGSTABL(tableCNTRPF) withS5PRODappended. - Default to
BCFRGLfromBICONT. - Write detail line to
APTRANwithFEGL,AMT,DSPC, and description "XXXXXXXXX XXXX XXX FRTCHG".
- Calculate total gallons (
-
For Miscellaneous Records (
SA5FIUMorSA5MOUM):- If no detail records, calculate total miscellaneous freight (
TTLMFT) for records withSMMSTY = 'F',SMGLNO ≠ 0, andSMSHD8 >= CMPDT8. - Prorate freight:
FRTAMT = (SMMAMT * SMMQTY / TTLMFT) * FRTTOT. - Adjust the last record to match
FRTTOT. - Use
SMGLNOasFEGL. - Write detail line to
APTRANwithFRTAMT,DSPC, and description "MISC CHARGE".
- If no detail records, calculate total miscellaneous freight (
-
Update Freight Invoice:
- Mark
FRCINHorFRCFBHas processed (FRAPST = 'Y').
Business Rules¶
- Invoice Source: Process
FRCINHorFRCFBHbased onRCD(FRCFBHP4for freight billed balance). - Freight Adjustment: Subtract
FRFBOAfromFRINAMfor invoice amount. - Hold Status: Support
H(hold),A(ACH),W(wire transfer),U(utility auto-payment) with corresponding descriptions. - Due Date: Calculate based on
VNTERM(net or prox days) or default to invoice date; adjust for non-holiday/weekend. - Discounts: Apply
TBDISCfromGSTABLto detail lines. - Date Restriction: Process sales records with ship date within one year of invoice date (
S5SHD8orSMSHD8 >= CMPDT8). - Freight Proration:
- Detail records: Prorate based on net gallons (
S5NGAL). - Miscellaneous records: Prorate based on
SMMAMT * SMMQTYfor freight-type records (SMMSTY = 'F'). - Ensure total prorated amounts equal
FRTTOT. - G/L Validation: Validate all G/L accounts against
GLMAST; useGSCTUM,GSTABL, orBICONTfor freight G/L. - Record Selection: Use
S@FIMO(ForM) andS@DM(DorM) to select appropriate sales files; determine dynamically if blank.
Calculations¶
- Due Date (Net Days):
DUDT = INDT + TBNETD(converted via Julian date). - Due Date (Prox Days):
DUDT = TBPRXDday of the next month fromINDT. - Freight Proration (Detail):
AMT = (S5NGAL / TTLQTY) * FRTTOT; adjust last record to matchFRTTOT. - Freight Proration (Misc):
FRTAMT = ((SMMAMT * SMMQTY) / TTLMFT) * FRTTOT; adjust last record to matchFRTTOT.
Dependencies¶
- Files:
- Update:
APTRAN,APCONT,FRCINH,FRCFBH. - Input:
APVEND,APVENY,GLMAST,GSTABL,APDATE,SA5FIUD,SA5FIUM,SA5MOUD,SA5MOUM,BICONT,GSCTUM. - External Program:
AP1012(called byAP125).
Assumptions¶
- Input data is valid and exists in the respective files.
APTRANcan accommodate new or updated records without conflicts.- Sales records are available within the one-year date range.
Error Handling¶
- Invalid company, vendor, or G/L accounts: Skip record creation and log errors (via indicators).
- No matching sales records: Skip detail line creation.
- Invalid dates: Reject and log errors.