It is imperative for the stock_id field to be indexed in the debtor_trans_details table for all FA databases used with the equivalent of:
ALTER TABLE `0_debtor_trans_details` ADD INDEX `stock_trans` (`stock_id`);
The function get_customer_trans_details() in the file sales/icludes/db/cust_trans_details_db.inc is used in reporting/rep107.php (and in 110, 113 reports as well) to acquire the transaction list filtered as appropriate. The non filtered SQL in it is:
SELECT trans.*,
trans.unit_price + trans.unit_tax AS FullUnitPrice,
trans.description AS StockDescription,
stock.units,
stock.mb_flag
FROM 0_debtor_trans_details trans
INNER JOIN 0_stock_master stock USING (stock_id)
ORDER BY id;
As the stock_master.stock_id and debtor_trans_details.id fields are primary keys, they stand already indexed. Hence the foreign key debtor_trans_details.stock_id is the one that is left to be indexed as it is the INNER JOIN field.
The said function can be modified to be:
function get_customer_trans_details($debtor_trans_type, $debtor_trans_no)
{
if (!is_array($debtor_trans_no))
$debtor_trans_no = array( 0=>$debtor_trans_no );
$sql = "SELECT trans.*,
trans.unit_price + trans.unit_tax AS FullUnitPrice,
trans.description As StockDescription,
stock.units, stock.mb_flag
FROM ".TB_PREF."debtor_trans_details trans
INNER JOIN ".TB_PREF."stock_master stock USING (stock_id)
WHERE (";
$tr=array();
foreach ($debtor_trans_no as $trans_no)
$tr[] = 'debtor_trans_no='.db_escape($trans_no);
$sql .= implode(' OR ', $tr);
$sql.= ") AND debtor_trans_type=".db_escape($debtor_trans_type)."
ORDER BY id";
return db_query($sql, "The debtor transaction detail could not be queried");
}
@joe: want to include it in the core? Committed in my FAMods.
I can confirm that even after this, when a range of invoices is attempted to be printed, the webserver hangs. Single invoice printing works. Multi Invoice (range) printing fails at second invoice call of function get_sales_parent_lines() in file sales/includes/sales_db.inc.
In the first invoice call in the Training Co (Demo Co) it succeeds:
SELECT parent.*
FROM 1_debtor_trans_details parent
LEFT JOIN 0_debtor_trans_details trans
ON trans.src_id=parent.id
WHERE trans.debtor_trans_type='10'
AND trans.debtor_trans_no='17'
GROUP BY parent.debtor_trans_no
ORDER BY parent.debtor_trans_no;
SQL SELECT debug Trail attached.
Web Server hangs when the statement $rep->NewPage() tries to get executed for the second page in rep107.php - tested in XAMPP v1.7.3 on WinXP SP3 / FireFox v37.0.
Post's attachmentssql_audit_trail_1.zip 1.7 kb, 2 downloads since 2016-08-15
You don't have the permssions to download the attachments of this post.