Fix is here.
Change the lines of the function get_sql_for_sales_order_view() as follows
function get_sql_for_sales_orders_view($trans_type, $trans_no, $filter,
$stock_item='', $from='', $to='', $ref='', $location=ALL_TEXT, $customer_id=ALL_TEXT)
{
if ($filter=='OutstandingOnly')
$order_value = 'Sum(line.unit_price*(line.quantity-line.qty_sent)*(1-line.discount_percent))+freight_cost AS OrderValue,';
else
$order_value = 'Sum(line.unit_price*line.quantity*(1-line.discount_percent))+freight_cost AS OrderValue,';
$sql = "SELECT
sorder.order_no,
sorder.reference,
debtor.name,
branch.br_name,"
.($filter=='InvoiceTemplates'
|| $filter=='DeliveryTemplates' ?
"sorder.comments, " : "sorder.customer_ref, ")
."sorder.ord_date,
sorder.delivery_date,
sorder.deliver_to,
$order_value
sorder.type,
debtor.curr_code,
Sum(line.qty_sent) AS TotDelivered,
Sum(line.quantity) AS TotQuantity,
Sum(line.invoiced) AS TotInvoiced,
alloc,
prep_amount,
allocs.ord_payments,
inv.inv_payments,
sorder.total,
sorder.trans_type