I'm trying to write a report based on AP Invoice info, and I'm struggling to get a BAQ or SQL query to get all the records.
The problem arises from the fact the the APInv records are in unrelatable tables. There's the APInvHed, APInvDtl, and APInvMisc. I'll ignore the APInvTax. records for now (as I could have the AP entry folks do them as Misc lines).
Every APInvDtl belongs to an APInvHed. That's a simple inner join.
Every APInvMisc belongs to an APInvHed, but some also belong to an APInvDtl. Misc charges that apply to the whole invoice have an InvoiceLine = 0. Misc charges that are specific to a invoice line have the APInvMisc.InvoiceLine = APInvDtl.InvoiceLine.
An Example Invoice 54321
Line 1, Part xyx, $123, no misc charges
Line 2, Part pdq, $234, with 1 misc charge (Expdite, $100)
Line 3, Part abc, $345, with 2 misc charges(Expedite $100, Setup $75)
Line 4, Part lmn, $456, no misc charges
Invoice misc charge. (Fuel Surcharge $66)
The above would make (1) APInvHed record,
(4) APInvDtl records, (APInvDtl.InvoicesLine: 1, 2, 3, 4)
(4) APInvMisc records, (APInvMisc.InvoiceLine: 0,2,3,3)
Here's another look inside the Misc table
InvLine MiscNum Item ...
0 1 Fuel Surcharge
2 1 Expedite
3 1 Expedite
3 2 Setup
(note no entries for InvDtl lines 1 or 4, and there is no APInvDtl with line 0)
I'd like to get
Line MiscNum Item DtlAmt Misc Amt
0 1 Fuel Surcharge $66
1 XYZ $123
2 PDQ $234
2 1 Expedite $100
3 ABC $345
3 1 Expedite $100
3 2 Setup $75
4 LMN $456
I'm actually doing this in CR, so I've got even more options for table joins.
I thought a Left outer join Hed->Dtl and another left outer join of Hed->MIsc would work, but it doesn't.
Any help would be appreciated.
Calvin