From: <dai...@us...> - 2014-12-01 07:08:58
|
Revision: 7011 http://sourceforge.net/p/web-erp/reponame/7011 Author: daintree Date: 2014-12-01 07:08:55 +0000 (Mon, 01 Dec 2014) Log Message: ----------- bug fixes Modified Paths: -------------- trunk/CustomerBalancesMovement.php trunk/config.distrib.php trunk/includes/Login.php Modified: trunk/CustomerBalancesMovement.php =================================================================== --- trunk/CustomerBalancesMovement.php 2014-11-29 17:45:46 UTC (rev 7010) +++ trunk/CustomerBalancesMovement.php 2014-12-01 07:08:55 UTC (rev 7011) @@ -3,11 +3,14 @@ $PageSecurity = 1; include('includes/session.inc'); $Title=_('Customer Balances Movements'); -include('includes/header.inc'); -echo '<p class="page_title_text"> +if (!isset($_POST['CreateCSV'])){ + include('includes/header.inc'); + + echo '<p class="page_title_text"> <img src="'.$RootPath.'/css/'.$Theme.'/images/transactions.png" title="' . _('Customer Balances Movements') . '" alt="" />' . ' ' . _('Customer Balances Movements') . ' </p>'; +} if (!isset($_POST['RunReport'])){ @@ -48,6 +51,10 @@ <td>' . _('Date To') . ':</td> <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="ToDate" maxlength="10" size="11" value="' . Date($_SESSION['DefaultDateFormat']) . '" /></td> </tr> + <tr> + <td>' . _('Create CSV') . ':</td> + <td><input type="checkbox" name="CreateCSV" value=""></td> + </tr> </table> <br /> @@ -90,15 +97,19 @@ $LocalTotal =0; -echo '<table> - <tr> - <th class="ascending">' . _('Customer') . ' </th> - <th class="ascending">' . _('Opening Balance') . '</th> - <th class="ascending">' . _('Debits') . '</th> - <th class="ascending">' . _('Credits') . '</th> - <th class="ascending">' . _('Balance') . '</th> - </tr>'; +if (!isset($_POST['CreateCSV'])){ + echo '<table> + <tr> + <th class="ascending">' . _('Customer') . ' </th> + <th class="ascending">' . _('Opening Balance') . '</th> + <th class="ascending">' . _('Debits') . '</th> + <th class="ascending">' . _('Credits') . '</th> + <th class="ascending">' . _('Balance') . '</th> + </tr>'; +} else { + $CSVFile = '"' . _('Customer') . '","' . _('Opening Balance') . '","' . _('Debits') . '", "' . _('Credits') . '","' . _('Balance') . '"' . "\n"; +} $OpeningBalances =0; $Debits =0; @@ -127,8 +138,8 @@ $sql = "SELECT SUM(CASE WHEN debtortrans.type=10 THEN ovamount+ovgst+ovdiscount+ovfreight ELSE 0 END) AS currencydebits, SUM(CASE WHEN debtortrans.type<>10 THEN ovamount+ovgst+ovdiscount+ovfreight ELSE 0 END) AS currencycredits, debtorsmaster.debtorno, - SUM(CASE WHEN debtortrans.type=10 THEN (ovamount+ovgst+ovdiscount+ovfreight-alloc)/debtortrans.rate ELSE 0 END) AS localdebits, - SUM(CASE WHEN debtortrans.type<>10 THEN (ovamount+ovgst+ovdiscount+ovfreight-alloc)/debtortrans.rate ELSE 0 END) AS localcredits + SUM(CASE WHEN debtortrans.type=10 THEN (ovamount+ovgst+ovdiscount+ovfreight)/debtortrans.rate ELSE 0 END) AS localdebits, + SUM(CASE WHEN debtortrans.type<>10 THEN (ovamount+ovgst+ovdiscount+ovfreight)/debtortrans.rate ELSE 0 END) AS localcredits FROM debtortrans INNER JOIN debtorsmaster ON debtortrans.debtorno=debtorsmaster.debtorno WHERE trandate>='" . FormatDateForSQL($_POST['FromDate']) . "' AND trandate <= '" . FormatDateForSQL($_POST['ToDate']) . "' @@ -138,42 +149,71 @@ $TransResult = DB_query($sql); $TransRow = DB_fetch_array($TransResult); - $OpeningBal = $myrow['localbalance']-$TransPostRow['localtotalpost']-$TransRow['localdebits']+$TransRow['localcredits']; + $OpeningBal = $myrow['localbalance']-$TransPostRow['localtotalpost']-$TransRow['localdebits']-$TransRow['localcredits']; $ClosingBal = $myrow['localbalance']-$TransPostRow['localtotalpost']; + if($OpeningBal !=0 OR $ClosingBal!=0 OR $TransRow['localdebits']!=0 OR $TransRow['localcredits']!=0) { - echo '<tr> - <td>' . $myrow['name'] . ' </td> - <td class="number">' . locale_number_format($OpeningBal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> - <td class="number">' . locale_number_format($TransRow['localdebits'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td> - <td class="number">' . locale_number_format($TransRow['localcredits'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td> - <td class="number">' . locale_number_format($ClosingBal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> - </tr>'; + if (!isset($_POST['CreateCSV'])){ + echo '<tr> + <td>' . $myrow['name'] . ' </td> + <td class="number">' . locale_number_format($OpeningBal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($TransRow['localdebits'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($TransRow['localcredits'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($ClosingBal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + </tr>'; + } else { //send the line to CSV file + $CSVFile .= '"' . stripcomma($myrow['name']) . '","' . stripcomma($OpeningBal) . '","' . stripcomma($TransRow['localdebits']) . '","' . stripcomma($TransRow['localcredits']) . '","' . stripcomma($ClosingBal) . '"' . "\n"; + + } + } + $OpeningBalances += $OpeningBal; $Debits += $TransRow['localdebits']; $Credits += $TransRow['localcredits']; $ClosingBalances += $ClosingBal; } -echo '</table>'; - +if (!isset($_POST['CreateCSV'])){ + echo '</table>'; +} if ($_POST['Customer']==''){ //if there could be several customers being reported - echo '<table> - <tr> - <th></th> - <th>' . _('Opening Balance') . '</th> - <th>' . _('Debits') . '</th> - <th>' . _('Credits') . '</th> - <th>' . _('Balance') . '</th> - </tr> - <tr> - <td>' . _('TOTALS') . '</td> - <td class="number">' . locale_number_format($OpeningBalances,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> - <td class="number">' . locale_number_format($Debits,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> - <td class="number">' . locale_number_format($Credits,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> - <td class="number">' . locale_number_format($ClosingBalances,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> - </tr> - </table>'; + if (!isset($_POST['CreateCSV'])){ + echo '<table> + <tr> + <th></th> + <th>' . _('Opening Balance') . '</th> + <th>' . _('Debits') . '</th> + <th>' . _('Credits') . '</th> + <th>' . _('Balance') . '</th> + </tr> + <tr> + <td>' . _('TOTALS') . '</td> + <td class="number">' . locale_number_format($OpeningBalances,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($Debits,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($Credits,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($ClosingBalances,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + </tr> + </table>'; + } else { + $CSVFile .= '"' . _('TOTALS') . '","' . stripcomma($OpeningBalances) . '","' . stripcomma($Debits) . '","' . stripcomma($Credits) . '","' . stripcomma($ClosingBalances) . '"' . "\n"; + } } +if (isset($_POST['CreateCSV'])){ + + header('Content-Encoding: UTF-8'); + header('Content-type: text/csv; charset=UTF-8'); + header("Content-disposition: attachment; filename=CustomerBalancesMovement_" . FormatDateForSQL($_POST['FromDate']) . '-' . FormatDateForSQL($_POST['ToDate']) .'.csv'); + header("Pragma: public"); + header("Expires: 0"); + echo "\xEF\xBB\xBF"; // UTF-8 BOM + echo $CSVFile; + exit; +} + include('includes/footer.inc'); + +function stripcomma($str) { //because we're using comma as a delimiter + return str_replace(',', '', $str); +} ?> \ No newline at end of file Modified: trunk/config.distrib.php =================================================================== --- trunk/config.distrib.php 2014-11-29 17:45:46 UTC (rev 7010) +++ trunk/config.distrib.php 2014-12-01 07:08:55 UTC (rev 7011) @@ -51,7 +51,7 @@ // 'ShowInputBox' // 'Hide' - +//$AllowCompanySelectionBox = 'Hide'; //$AllowCompanySelectionBox = 'ShowInputBox'; $AllowCompanySelectionBox = 'ShowSelectionBox'; Modified: trunk/includes/Login.php =================================================================== --- trunk/includes/Login.php 2014-11-29 17:45:46 UTC (rev 7010) +++ trunk/includes/Login.php 2014-12-01 07:08:55 UTC (rev 7011) @@ -37,7 +37,7 @@ <input type="hidden" name="FormID" value="<?php echo $_SESSION['FormID']; ?>" /> <span> <?php - if (isset($CompanyList) && is_array($CompanyList)) { + if (isset($CompanyList) AND is_array($CompanyList)) { foreach ($CompanyList as $key => $CompanyEntry){ if ($DefaultDatabase == $CompanyEntry['database']) { $CompanyNameField = "$key"; |