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
FRCINH
orFRCFBH
files to generate A/P voucher transactions in theAPTRAN
file, 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 inFRCINH
orFRCFBH
, marked as processed. - Components:
AP125.rpg
: Handles header creation, vendor validation, due date calculation, and G/L validation, and callsAP1012.rpg
for 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 (FRCFBHP4
for freight billed balance header, elseFRCINHP4
). - Reference Number (
RDNO
): Numeric reference number forFRCFBH
invoices. - Sales Data (via
SALES
data 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
APTRAN
with validated vendor, G/L, and prorated freight amounts. - Updated Freight Invoice Records:
FRCINH
orFRCFBH
records 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
) fromAPCONT
usingCO
. -
Assign a new entry number (
ENT#
) fromACNXTE
for new transactions, incrementing and updatingACNXTE
. -
Retrieve Vendor Information:
- Get vendor number (
VYVEND
) fromAPVENY
usingCO
andCAID
. - Retrieve vendor details (
VNVNAM
,VNAD1-4
,VNHOLD
,VNSNGL
,VNTERM
,VNEXGL
) fromAPVEND
usingCO
andVEND
. -
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
VNTERM
is non-zero, retrieve terms (TBNETD
,TBPRXD
,TBDISC
) fromGSTABL
(tableAPTERM
). - Calculate due date:
- For net days (
TBNETD
): AddTBNETD
to invoice date (FRIYMD
) using Julian date conversion. - For prox days (
TBPRXD
): Set toTBPRXD
day 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
APTRAN
with invoice, vendor, G/L, due date, hold status, and discount (DSPC
) data. -
Prorate Freight and Create Detail Lines:
- Call
AP1012
withSALES
data structure to prorateFRTTOT
across sales records. - For Detail Records (
SA5FIUD
orSA5MOUD
):- 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, useCUFEGL
fromGSCTUM
. - Else, use
TBFEG4
fromGSTABL
(tableCNTRPF
) withS5PROD
appended. - Default to
BCFRGL
fromBICONT
. - Write detail line to
APTRAN
withFEGL
,AMT
,DSPC
, and description "XXXXXXXXX XXXX XXX FRTCHG".
- Calculate total gallons (
-
For Miscellaneous Records (
SA5FIUM
orSA5MOUM
):- 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
SMGLNO
asFEGL
. - Write detail line to
APTRAN
withFRTAMT
,DSPC
, and description "MISC CHARGE".
- If no detail records, calculate total miscellaneous freight (
-
Update Freight Invoice:
- Mark
FRCINH
orFRCFBH
as processed (FRAPST = 'Y'
).
Business Rules¶
- Invoice Source: Process
FRCINH
orFRCFBH
based onRCD
(FRCFBHP4
for freight billed balance). - Freight Adjustment: Subtract
FRFBOA
fromFRINAM
for 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
TBDISC
fromGSTABL
to detail lines. - Date Restriction: Process sales records with ship date within one year of invoice date (
S5SHD8
orSMSHD8 >= CMPDT8
). - Freight Proration:
- Detail records: Prorate based on net gallons (
S5NGAL
). - Miscellaneous records: Prorate based on
SMMAMT * SMMQTY
for freight-type records (SMMSTY = 'F'
). - Ensure total prorated amounts equal
FRTTOT
. - G/L Validation: Validate all G/L accounts against
GLMAST
; useGSCTUM
,GSTABL
, orBICONT
for freight G/L. - Record Selection: Use
S@FIMO
(F
orM
) andS@DM
(D
orM
) 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 = TBPRXD
day 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.
APTRAN
can 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.