The said function that does the job is in sales/includes/db/cust_trans_db.inc
function get_customer_trans_version($type, $trans_no) {
if (!is_array($trans_no))
$trans_no = array( $trans_no );
$sql= 'SELECT trans_no, version FROM '.TB_PREF. 'debtor_trans
WHERE type='.db_escape($type).' AND (';
foreach ($trans_no as $key=>$trans)
$trans_no[$key] = 'trans_no='.db_escape($trans_no[$key]);
$sql .= implode(' OR ', $trans_no) . ')';
$res = db_query($sql, 'document version retreival');
$vers = array();
while($mysql=db_fetch($res)) {
$vers[$mysql['trans_no']] = $mysql['version'];
}
return $vers;
}
If there are no transaction or just one transaction only then what would happen to the orphaned OR?
Also, there may be a typo in the field name 'type' being 'tpe' since both exist. The table definition is:
CREATE TABLE IF NOT EXISTS `0_debtor_trans` (
`trans_no` int(11) unsigned NOT NULL default '0',
`type` smallint(6) unsigned NOT NULL default '0',
`version` tinyint(1) unsigned NOT NULL default '0',
`debtor_no` int(11) unsigned default NULL,
`branch_code` int(11) NOT NULL default '-1',
`tran_date` date NOT NULL default '0000-00-00',
`due_date` date NOT NULL default '0000-00-00',
`reference` varchar(60) NOT NULL default '',
`tpe` int(11) NOT NULL default '0',
`order_` int(11) NOT NULL default '0',
`ov_amount` double NOT NULL default '0',
`ov_gst` double NOT NULL default '0',
`ov_freight` double NOT NULL default '0',
`ov_freight_tax` double NOT NULL default '0',
`ov_discount` double NOT NULL default '0',
`alloc` double NOT NULL default '0',
`rate` double NOT NULL default '1',
`ship_via` int(11) default NULL,
`dimension_id` int(11) NOT NULL default '0',
`dimension2_id` int(11) NOT NULL default '0',
`payment_terms` int(11) default NULL,
PRIMARY KEY (`type`,`trans_no`),
KEY `debtor_no` (`debtor_no`,`branch_code`),
KEY `tran_date` (`tran_date`)
) ENGINE=InnoDB;
Should the line:
$trans_no[$key] = 'trans_no='.db_escape($trans_no[$key]);
be
$trans_no[$key] = 'trans_no='.db_escape($value);
?