+ mv => 'LEFT JOIN vendor AS mv ON mv.id = mm.make',
+ );
+ my @join_order = qw(partsgroup makemodel mv invoice_oi apoe cv pfac);
+
+ my %table_prefix = (
+ deliverydate => 'apoe.', serialnumber => 'ioi.',
+ transdate => 'apoe.', trans_id => 'ioi.',
+ module => 'apoe.', name => 'cv.',
+ ordnumber => 'apoe.', make => 'mm.',
+ quonumber => 'apoe.', model => 'mm.',
+ invnumber => 'apoe.', partsgroup => 'pg.',
+ lastcost => 'p.', , soldtotal => ' ',
+ factor => 'pfac.',
+ 'SUM(ioi.qty)' => ' ',
+ description => 'p.',
+ qty => 'ioi.',
+ serialnumber => 'ioi.',
+ quotation => 'apoe.',
+ cv => 'cv.',
+ "ioi.id" => ' ',
+ "ioi.ioi" => ' ',
+ );
+
+ # if the join condition in these blocks are met, the column
+ # of the scecified table will gently override (coalesce actually) the original value
+ # use it to conditionally coalesce values from subtables
+ my @column_override = (
+ # column name, prefix, joins_needed
+ [ 'description', 'ioi.', 'invoice_oi' ],
+ [ 'deliverydate', 'ioi.', 'invoice_oi' ],
+ [ 'transdate', 'apoe.', 'apoe' ],
+ [ 'unit', 'ioi.', 'invoice_oi' ],
+ [ 'sellprice', 'ioi.', 'invoice_oi' ],
+ );
+
+ # careful with renames. these are HARD, and any filters done on the original column will break
+ my %renamed_columns = (
+ 'factor' => 'price_factor',
+ 'SUM(ioi.qty)' => 'soldtotal',
+ 'ioi.id' => 'ioi_id',
+ 'ioi.ioi' => 'ioi',