1<?php
2/* This script is an utility to show debtors balances in total by currency. */
3
4include ('includes/session.php');
5$Title = _('Currency Debtor Balances');// Screen identificator.
6$ViewTopic = 'SpecialUtilities';// Filename's id in ManualContents.php's TOC.
7$BookMark = 'Z_CurrencyDebtorsBalances';// Anchor's id in the manual's html document.
8include('includes/header.php');
9echo '<p class="page_title_text"><img alt="" src="'.$RootPath.'/css/'.$Theme.
10	'/images/ar.png" title="' .
11	_('Show Local Currency Total Debtors Balances') . '" /> ' .// Icon title.
12	_('Debtors Balances By Currency Totals') . '</p>';// Page title.
13
14$sql = "SELECT SUM(ovamount+ovgst+ovdiscount+ovfreight-alloc) AS currencybalance,
15		currcode,
16		decimalplaces AS currdecimalplaces,
17		SUM((ovamount+ovgst+ovdiscount+ovfreight-alloc)/debtortrans.rate) AS localbalance
18	FROM debtortrans INNER JOIN debtorsmaster
19		ON debtortrans.debtorno=debtorsmaster.debtorno
20	INNER JOIN currencies
21	ON debtorsmaster.currcode=currencies.currabrev
22	WHERE (ovamount+ovgst+ovdiscount+ovfreight-alloc)<>0 GROUP BY currcode";
23
24$result = DB_query($sql);
25
26
27$LocalTotal =0;
28
29echo '<table>';
30
31while ($myrow=DB_fetch_array($result)){
32
33	echo '<tr>
34			<td>' . _('Total Debtor Balances in') . ' </td>
35			<td>' . $myrow['currcode'] . '</td>
36			<td class="number">' . locale_number_format($myrow['currencybalance'],$myrow['currdecimalplaces']) . '</td>
37			<td>' . _('in') . ' ' . $_SESSION['CompanyRecord']['currencydefault'] . '</td>
38			<td class="number">' . locale_number_format($myrow['localbalance'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
39		</tr>';
40	$LocalTotal += $myrow['localbalance'];
41}
42
43echo '<tr>
44		<td colspan="4">' . _('Total Balances in local currency') . ':</td>
45		<td class="number">' . locale_number_format($LocalTotal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td></tr>';
46
47echo '</table>';
48
49include('includes/footer.php');
50?>
51