From: <vv...@us...> - 2012-04-03 21:57:58
|
Revision: 5217 http://web-erp.svn.sourceforge.net/web-erp/?rev=5217&view=rev Author: vvs2012 Date: 2012-04-03 21:57:50 +0000 (Tue, 03 Apr 2012) Log Message: ----------- Cleaned up Petty Cash module. Fixed several errors in SQL INSERT statements. Modified Paths: -------------- trunk/PcAssignCashToTab.php trunk/PcAuthorizeExpenses.php trunk/PcClaimExpensesFromTab.php trunk/PcExpenses.php trunk/PcExpensesTypeTab.php trunk/PcReportTab.php trunk/PcTabs.php trunk/PcTypeTabs.php trunk/doc/Change.log Modified: trunk/PcAssignCashToTab.php =================================================================== --- trunk/PcAssignCashToTab.php 2012-04-03 20:28:39 UTC (rev 5216) +++ trunk/PcAssignCashToTab.php 2012-04-03 21:57:50 UTC (rev 5217) @@ -99,12 +99,12 @@ posted, notes, receipt) - VALUES ('', + VALUES (NULL, '" . $_POST['SelectedTabs'] . "', '".FormatDateForSQL($_POST['Date'])."', 'ASSIGNCASH', '" . filter_number_format($_POST['Amount']) . "', - authorized = '0000-00-00', + '0000-00-00', '0', '" . $_POST['Notes'] . "', '" . $_POST['Receipt'] . "' @@ -127,7 +127,7 @@ } elseif ( isset($_GET['delete']) ) { echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/money_add.png" title="' . - _('Search') . '" alt="">' . ' ' . $title. '</p>'; + _('Search') . '" alt="" />' . ' ' . $title. '</p>'; $sql="DELETE FROM pcashdetails WHERE counterindex='" . $SelectedIndex . "'"; $ErrMsg = _('The assignment of cash record could not be deleted because'); @@ -146,13 +146,9 @@ _('Search') . '" alt="" />' . ' ' . $title. '</p>'; echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; + echo '<div>'; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; - echo '<p><table class="selection">'; //Main table - echo '<tr><td>' . _('Petty Cash Tab To Assign Cash') . ':</td> - <td><select name="SelectedTabs">'; - - DB_free_result($result); $SQL = "SELECT tabcode FROM pctabs WHERE assigner='" . $_SESSION['UserID'] . "' @@ -160,6 +156,10 @@ $result = DB_query($SQL,$db); + echo '<br /><table class="selection">'; //Main table + + echo '<tr><td>' . _('Petty Cash Tab To Assign Cash') . ':</td> + <td><select name="SelectedTabs">'; while ($myrow = DB_fetch_array($result)) { if (isset($_POST['SelectTabs']) and $myrow['tabcode']==$_POST['SelectTabs']) { echo '<option selected="selected" value="'; @@ -170,13 +170,16 @@ } echo '</select></td></tr>'; - echo '</td></tr></table>'; // close main table - echo '<p> + echo '</table>'; // close main table + DB_free_result($result); + + echo '<br /> <div class="centre"> <input type="submit" name="process" value="' . _('Accept') . '" /> <input type="submit" name="Cancel" value="' . _('Cancel') . '" /> </div>'; - echo '</form>'; + echo '</div> + </form>'; } //end of ifs and buts! @@ -186,7 +189,7 @@ echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/money_add.png" title="' . _('Search') . '" alt="" />' . ' ' . $title. '</p>'; } - echo '<p><div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Select another tab') . '<a/></div></p>'; + echo '<br /><div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Select another tab') . '</a></div>'; @@ -218,14 +221,15 @@ ORDER BY date, counterindex ASC"; $result = DB_query($sql,$db); - echo '<table class="selection">'; echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; + echo '<div>'; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + echo '<table class="selection">'; echo '<tr><th colspan="8">' . _('Detail Of PC Tab Movements For Last') .': '; echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; echo '<input type="text" class="number" name="Days" value="' . $Days . '" maxlength="3" size="4" /> ' . _('Days'); echo '<input type="submit" name="Go" value="' . _('Go') . '" />'; - echo '</th></tr></form>'; + echo '</th></tr>'; echo '<tr> <th>' . _('Date') . '</th> <th>' . _('Expense Code') . '</th> @@ -265,12 +269,12 @@ <td>' . ConvertSQLDate($myrow['authorized']) . '</td> <td>' . $myrow['notes'] . '</td> <td>' . $myrow['receipt'] . '</td> - <td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?SelectedIndex=' . $myrow['counterindex'] . '&SelectedTabs=' . - $SelectedTabs . '&Days=' . $Days . '&edit=yes">' . _('Edit') . '</td> - <td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?SelectedIndex=' . $myrow['counterindex'] . '&SelectedTabs=' . - $SelectedTabs . '&Days=' . $Days . '&delete=yes" onclick="return confirm("' . - _('Are you sure you wish to delete this code and the expense it may have set up?') . '");">' . - _('Delete') . '</td> + <td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?SelectedIndex=' . $myrow['counterindex'] . '&SelectedTabs=' . + $SelectedTabs . '&Days=' . $Days . '&edit=yes">' . _('Edit') . '</a></td> + <td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?SelectedIndex=' . $myrow['counterindex'] . '&SelectedTabs=' . + $SelectedTabs . '&Days=' . $Days . '&delete=yes" onclick="return confirm(\'' . + _('Are you sure you wish to delete this code and the expense it may have set up?') . '\');">' . + _('Delete') . '</a></td> </tr>'; }else{ echo '<td>' . ConvertSQLDate($myrow['date']) . '</td> @@ -300,7 +304,8 @@ <td>' . locale_number_format($Amount['0'],$CurrDecimalPlaces) . '</td></tr>'; echo '</table>'; - + echo '</div> + </form>'; } if (! isset($_GET['delete'])) { @@ -310,13 +315,8 @@ } echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') .'">'; + echo '<div>'; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; - echo '<p><table class="selection">'; //Main table - if (isset($_GET['SelectedIndex'])) { - echo '<tr><th colspan="2"><font color=blue size="3">'._('Update Cash Assignment').'</font></th></tr>'; - } else { - echo '<tr><th colspan="2"><font color=blue size="3">'._('New Cash Assignment').'</font></th></tr>'; - } if ( isset($_GET['edit'])) { $sql = "SELECT * FROM pcashdetails @@ -342,6 +342,12 @@ $_POST['Date']=Date('d/m/Y'); } + echo '<br /><table class="selection">'; //Main table + if (isset($_GET['SelectedIndex'])) { + echo '<tr><th colspan="2"><h3>'._('Update Cash Assignment').'</h3></th></tr>'; + } else { + echo '<tr><th colspan="2"><h3>'._('New Cash Assignment').'</h3></th></tr>'; + } echo '<tr><td>' . _('Cash Assignation Date') . ':</td>'; echo '<td><input type="text" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" name="Date" size="10" maxlength="10" value="' . $_POST['Date'] . '" /></td></tr>'; @@ -372,17 +378,18 @@ <td><input type="text" name="Receipt" size="50" maxlength="49" value="' . $_POST['Receipt'] . '" /></td> </tr>'; - echo '<input type="hidden" name="CurrentAmount" value="' . $Amount['0']. '" />'; - echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; - echo '<input type="hidden" name="Days" value="' .$Days. '" />'; + echo '</table>'; // close main table - echo '</td></tr></table>'; // close main table + echo '<input type="hidden" name="CurrentAmount" value="' . $Amount['0']. '" />'; + echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; + echo '<input type="hidden" name="Days" value="' .$Days. '" />'; - echo '<p><div class="centre"> + echo '<br /><div class="centre"> <input type="submit" name="submit" value="' . _('Accept') . '" /> <input type="submit" name="Cancel" value="' . _('Cancel') . '" /></div>'; - echo '</form>'; + echo '</div> + </form>'; } // end if user wish to delete } Modified: trunk/PcAuthorizeExpenses.php =================================================================== --- trunk/PcAuthorizeExpenses.php 2012-04-03 20:28:39 UTC (rev 5216) +++ trunk/PcAuthorizeExpenses.php 2012-04-03 21:57:50 UTC (rev 5217) @@ -48,6 +48,7 @@ if (isset($_POST['Submit']) or isset($_POST['update']) OR isset($SelectedTabs) OR isset ($_POST['GO'])) { echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; + echo '<div>'; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; if(!isset ($Days)){ @@ -57,8 +58,7 @@ echo '<br /><table class="selection">'; echo '<tr><th colspan="7">' . _('Detail Of Movement For Last ') .': '; echo '<input type="text" class="number" name="Days" value="' . $Days . '" maxlength="3" size="4" />' . _('Days'); - echo '<input type="submit" name="Go" value="' . _('Go') . '" /></tr></th>'; - echo '</form>'; + echo '<input type="submit" name="Go" value="' . _('Go') . '" /></th></tr>'; $sql = "SELECT pcashdetails.counterindex, pcashdetails.tabcode, @@ -95,8 +95,6 @@ </tr>'; $k=0; //row colour counter - echo'<form action="PcAuthorizeExpenses.php" method="post" name="'._('update').'">'; - echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; while ($myrow=DB_fetch_array($result)) { $CurrDecimalPlaces = $myrow['decimalplaces']; @@ -117,6 +115,7 @@ $type = 2; $AccountFrom = $myrow['glaccountassignment']; $AccountTo = $myrow['glaccountpcash']; + $TagTo = 0; }else{ $type = 1; $Amount = -$Amount; @@ -251,20 +250,20 @@ <td>' . $myrow['receipt'] . '</td>'; if (isset($_POST[$myrow['counterindex']])){ - echo'<td>'.ConvertSQLDate(Date('Y-m-d')).'</td>'; + echo'<td>'.ConvertSQLDate(Date('Y-m-d')); }else{ //compare against raw SQL format date, then convert for display. if(($myrow['authorized']!='0000-00-00')){ - echo'<td>'.ConvertSQLDate($myrow['authorized']).'</td>'; + echo'<td>'.ConvertSQLDate($myrow['authorized']); }else{ - echo '<td align=right><input type="checkbox" name="'.$myrow['counterindex'].'" /></td>'; + echo '<td align="right"><input type="checkbox" name="'.$myrow['counterindex'].'" />'; } } echo '<input type="hidden" name="SelectedIndex" value="' . $myrow['counterindex']. '" />'; echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; echo '<input type="hidden" name="Days" value="' .$Days. '" />'; - echo'</tr>'; + echo '</td></tr>'; } //end of looping @@ -285,26 +284,28 @@ // Do the postings include ('includes/GLPostings.inc'); - echo'</table><br /><div class="centre"><input type="submit" name="Submit" value="' . _('Update') . '" /></div></form>'; + echo '</table><br /><div class="centre"><input type="submit" name="Submit" value="' . _('Update') . '" /></div> + </div> + </form>'; } else { /*The option to submit was not hit so display form */ echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') .'">'; +echo '<div>'; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; -echo '<p><table class="selection">'; //Main table +echo '<br /><table class="selection">'; //Main table -echo '<tr><td>' . _('Authorise expenses to Petty Cash Tab') . ':</td> - <td><select name="SelectedTabs">'; - - DB_free_result($result); $SQL = "SELECT tabcode FROM pctabs WHERE authorizer='" . $_SESSION['UserID'] . "'"; $result = DB_query($SQL,$db); +echo '<tr><td>' . _('Authorise expenses to Petty Cash Tab') . ':</td> + <td><select name="SelectedTabs">'; + while ($myrow = DB_fetch_array($result)) { if (isset($_POST['SelectTabs']) and $myrow['tabcode']==$_POST['SelectTabs']) { echo '<option selected="selected" value="'; @@ -316,12 +317,12 @@ } //end while loop get type of tab echo '</select></td></tr>'; + echo '</table>'; // close main table + DB_free_result($result); - echo '</td></tr></table>'; // close main table - - echo '<p><div class="centre"><input type="submit" name="Process" value="' . _('Accept') . '" /> + echo '<br /><div class="centre"><input type="submit" name="Process" value="' . _('Accept') . '" /> <input type="submit" name="Cancel" value="' . _('Cancel') . '" /></div>'; - + echo '</div>'; echo '</form>'; } /*end of else not submit */ include('includes/footer.inc'); Modified: trunk/PcClaimExpensesFromTab.php =================================================================== --- trunk/PcClaimExpensesFromTab.php 2012-04-03 20:28:39 UTC (rev 5216) +++ trunk/PcClaimExpensesFromTab.php 2012-04-03 21:57:50 UTC (rev 5217) @@ -1,403 +1,409 @@ -<?php - -/* $Id$*/ - -include('includes/session.inc'); -$title = _('Claim Petty Cash Expenses From Tab'); -include('includes/header.inc'); - - -if (isset($_POST['SelectedTabs'])){ - $SelectedTabs = mb_strtoupper($_POST['SelectedTabs']); -} elseif (isset($_GET['SelectedTabs'])){ - $SelectedTabs = mb_strtoupper($_GET['SelectedTabs']); -} - -if (isset($_POST['SelectedIndex'])){ - $SelectedIndex = $_POST['SelectedIndex']; -} elseif (isset($_GET['SelectedIndex'])){ - $SelectedIndex = $_GET['SelectedIndex']; -} - -if (isset($_POST['Days'])){ - $Days = filter_number_format($_POST['Days']); -} elseif (isset($_GET['Days'])){ - $Days = filter_number_format($_GET['Days']); -} - -if (isset($_POST['Cancel'])) { - unset($SelectedTabs); - unset($SelectedIndex); - unset($Days); - unset($_POST['Amount']); - unset($_POST['Notes']); - unset($_POST['Receipt']); -} - - -if (isset($_POST['Process'])) { - - if ($_POST['SelectedTabs']=='') { - echo prnMsg(_('You have not selected a tab to claim the expenses on'),'error'); - unset($SelectedTabs); - } -} - -if (isset($_POST['Go'])) { - if ($Days<=0) { - prnMsg(_('The number of days must be a positive number'),'error'); - $Days=30; - } -} - -if (isset($_POST['submit'])) { -//initialise no input errors assumed initially before we test - $InputError = 0; - - /* actions to take once the user has clicked the submit button - ie the page has called itself with some user input */ - - //first off validate inputs sensible - - if ($_POST['SelectedExpense']=='') { - $InputError=1; - prnMsg(_('You have not selected an expense to claim on this tab'),'error'); - } elseif ($_POST['amount']==0) { - $InputError = 1; - prnMsg( _('The Amount must be greater than 0'),'error'); - } - - if (isset($SelectedIndex) AND $InputError !=1) { - $sql = "UPDATE pcashdetails - SET date = '".FormatDateForSQL($_POST['Date'])."', - codeexpense = '" . $_POST['SelectedExpense'] . "', - amount = '" .-filter_number_format($_POST['amount']) . "', - notes = '" . $_POST['Notes'] . "', - receipt = '" . $_POST['Receipt'] . "' - WHERE counterindex = '".$SelectedIndex."'"; - - $msg = _('The Expense Claim on Tab') . ' ' . $SelectedTabs . ' ' . _('has been updated'); - - } elseif ($InputError !=1 ) { - - // First check the type is not being duplicated - // Add new record on submit - - $sql = "INSERT INTO pcashdetails (counterindex, - tabcode, - date, - codeexpense, - amount, - authorized, - posted, - notes, - receipt) - VALUES ('','" . $_POST['SelectedTabs'] . "', - '".FormatDateForSQL($_POST['Date'])."', - '" . $_POST['SelectedExpense'] . "', - '" . -filter_number_format($_POST['amount']) . "', - '', - '', - '" . $_POST['Notes'] . "', - '" . $_POST['Receipt'] . "' - )"; - - $msg = _('The Expense Claim on Tab') . ' ' . $_POST['SelectedTabs'] . ' ' . _('has been created'); - } - - if ( $InputError !=1) { - //run the SQL from either of the above possibilites - $result = DB_query($sql,$db); - prnMsg($msg,'success'); - - unset($_POST['SelectedExpense']); - unset($_POST['amount']); - unset($_POST['Date']); - unset($_POST['Notes']); - unset($_POST['Receipt']); - } - -} elseif ( isset($_GET['delete']) ) { - - $sql="DELETE FROM pcashdetails - WHERE counterindex='".$SelectedIndex."'"; - $ErrMsg = _('Petty Cash Expense record could not be deleted because'); - $result = DB_query($sql,$db,$ErrMsg); - prnMsg(_('Petty cash Expense record') . ' ' . $SelectedTabs . ' ' . _('has been deleted') ,'success'); - - unset($_GET['delete']); - -}//end of get delete - -if (!isset($SelectedTabs)){ - - /* It could still be the first time the page has been run and a record has been selected for modification - SelectedTabs will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters - then none of the above are true and the list of sales types will be displayed with - links to delete or edit each. These will call the same page again and allow update/input - or deletion of the records*/ - echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/money_add.png" title="' . _('Payment Entry') . '" alt="" />' . ' ' . $title . '</p>'; - - echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; - echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; - echo '<br /><table class="selection">'; //Main table - - echo '<tr><td>' . _('Petty Cash Tabs for User ') . $_SESSION['UserID'] . ':</td> - <td><select name="SelectedTabs">'; - - DB_free_result($result); - $SQL = "SELECT tabcode - FROM pctabs - WHERE usercode='" . $_SESSION['UserID'] . "'"; - - $result = DB_query($SQL,$db); - echo '<option value="">' . _('Not Yet Selected') . '</option>'; - while ($myrow = DB_fetch_array($result)) { - if (isset($_POST['SelectTabs']) and $myrow['tabcode']==$_POST['SelectTabs']) { - echo '<option selected="selected" value="'; - } else { - echo '<option value="'; - } - echo $myrow['tabcode'] . '">' . $myrow['tabcode'] . '</option>'; - - } //end while loop - - echo '</select></td></tr>'; - echo '</td></tr></table>'; // close main table - - echo '<p><div class="centre"><input type="submit" name="Process" value="' . _('Accept') . '" /><input type="submit" name="Cancel" value="' . _('Cancel') . '" /></div>'; - - echo '</form>'; - -} else { // isset($SelectedTabs) - - echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/money_add.png" title="' . _('Petty Cash Claim Entry') . '" alt="" /> - ' . ' ' . $title . '</p>'; - - echo '<p><div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Select another tab') . '</a></div></p>'; - - if (! isset($_GET['edit']) OR isset ($_POST['GO'])){ - echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; - echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; - echo '<br /><table class="selection">'; - echo '<tr><th colspan="8"><font color="navy" size="3">' . _('Petty Cash Tab') . ' ' .$SelectedTabs. '</font></th></tr>'; - echo '<tr><th colspan="8">' . _('Detail Of Movements For Last ') .': '; - - - if(!isset ($Days)){ - $Days=30; - } - - /* Retrieve decimal places to display */ - $SqlDecimalPlaces="SELECT decimalplaces - FROM currencies,pctabs - WHERE currencies.currabrev = pctabs.currency - AND tabcode='" . $SelectedTabs . "'"; - $result = DB_query($SqlDecimalPlaces,$db); - $myrow=DB_fetch_array($result); - $CurrDecimalPlaces = $myrow['decimalplaces']; - - echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; - echo '<input type="text" class="number" name="Days" value="' . $Days . '" maxlength="3" size="4" /> ' ._('Days'); - echo '<input type="submit" name="Go" value="' . _('Go') . '" />'; - echo '</th></div></form>'; - - if (isset($_POST['Cancel'])) { - unset($_POST['SelectedExpense']); - unset($_POST['amount']); - unset($_POST['Date']); - unset($_POST['Notes']); - unset($_POST['Receipt']); - } - - $sql = "SELECT * FROM pcashdetails - WHERE tabcode='".$SelectedTabs."' - AND date >=DATE_SUB(CURDATE(), INTERVAL ".$Days." DAY) - ORDER BY date, counterindex ASC"; - - $result = DB_query($sql,$db); - - echo '<tr> - <th>' . _('Date Of Expense') . '</th> - <th>' . _('Expense Description') . '</th> - <th>' . _('Amount') . '</th> - <th>' . _('Authorized') . '</th> - <th>' . _('Notes') . '</th> - <th>' . _('Receipt') . '</th> - </tr>'; - - $k=0; //row colour counter - - while ($myrow = DB_fetch_row($result)) { - if ($k==1){ - echo '<tr class="EvenTableRows">'; - $k=0; - } else { - echo '<tr class="OddTableRows">'; - $k=1; - } - - $sqldes="SELECT description - FROM pcexpenses - WHERE codeexpense='". $myrow['3'] . "'"; - - $ResultDes = DB_query($sqldes,$db); - $Description=DB_fetch_array($ResultDes); - - if (!isset($Description['0'])){ - $Description['0']='ASSIGNCASH'; - } - if ($myrow['5']=='0000-00-00') { - $AuthorisedDate=_('Unauthorised'); - } else { - $AuthorisedDate=ConvertSQLDate($myrow['5']); - } - if (($myrow['5'] == '0000-00-00') and ($Description['0'] != 'ASSIGNCASH')){ - // only movements NOT authorized can be modified or deleted - printf('<td>%s</td> - <td>%s</td> - <td class="number">%s</td> - <td>%s</td> - <td>%s</td> - <td>%s</td> - <td><a href="%sSelectedIndex=%s&SelectedTabs=' . $SelectedTabs . '&Days=' . $Days . '&edit=yes">' . _('Edit') . '</td> - <td><a href="%sSelectedIndex=%s&SelectedTabs=' . $SelectedTabs . '&Days=' . $Days . '&delete=yes" onclick=\'return confirm("' . _('Are you sure you wish to delete this code and the expenses it may have set up?') . '");\'>' . _('Delete') . '</td> - </tr>', - ConvertSQLDate($myrow['2']), - $Description['0'], - locale_number_format($myrow['4'],$CurrDecimalPlaces), - $AuthorisedDate, - $myrow['7'], - $myrow['8'], - htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', $myrow['0'], - htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', $myrow['0']); - } else { - printf('<td>%s</td> - <td>%s</td> - <td class="number">%s</td> - <td>%s</td> - <td>%s</td> - <td>%s</td> - </tr>', - ConvertSQLDate($myrow['2']), - $Description['0'], - locale_number_format($myrow['4'],$CurrDecimalPlaces), - $AuthorisedDate, - $myrow['7'], - $myrow['8']); - - } - - } - //END WHILE LIST LOOP - - $sqlamount="SELECT sum(amount) - FROM pcashdetails - WHERE tabcode='".$SelectedTabs."'"; - - $ResultAmount = DB_query($sqlamount,$db); - $Amount=DB_fetch_array($ResultAmount); - - if (!isset($Amount['0'])) { - $Amount['0']=0; - } - - echo '<tr><td colspan="2" style="text-align:right" >' . _('Current balance') . ':</td> - <td class="number">'.locale_number_format($Amount['0'],$CurrDecimalPlaces) . '</td></tr>'; - - - echo '</table>'; - } - - if (! isset($_GET['delete'])) { - - echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; - echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; - - echo '<br /><table class="selection">'; //Main table - - - if ( isset($_GET['edit'])) { - $sql = "SELECT * - FROM pcashdetails - WHERE counterindex='".$SelectedIndex."'"; - - $result = DB_query($sql, $db); - $myrow = DB_fetch_array($result); - - $_POST['Date'] = ConvertSQLDate($myrow['date']); - $_POST['SelectedExpense'] = $myrow['codeexpense']; - $_POST['Amount'] = -$myrow['amount']; - $_POST['Notes'] = $myrow['notes']; - $_POST['Receipt'] = $myrow['receipt']; - - echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; - echo '<input type="hidden" name="SelectedIndex" value="' . $SelectedIndex. '" />'; - echo '<input type="hidden" name="Days" value="' .$Days. '" />'; - - }//end of Get Edit - - if (!isset($_POST['Date'])) { - $_POST['Date']=Date($_SESSION['DefaultDateFormat']); - } - - echo '<tr><td>' . _('Date Of Expense') . ':</td> - <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="Date" size="10" maxlength="10" value="' . $_POST['Date']. '" /></td></tr>'; - echo '<tr><td>' . _('Code Of Expense') . ':</td><td><select name="SelectedExpense">'; - - DB_free_result($result); - - $SQL = "SELECT pcexpenses.codeexpense, - pcexpenses.description - FROM pctabexpenses, pcexpenses, pctabs - WHERE pctabexpenses.codeexpense = pcexpenses.codeexpense - AND pctabexpenses.typetabcode = pctabs.typetabcode - AND pctabs.tabcode = '".$SelectedTabs."' - ORDER BY pcexpenses.codeexpense ASC"; - - $result = DB_query($SQL,$db); - echo '<option value="">' . _('Not Yet Selected') . '</option>'; - while ($myrow = DB_fetch_array($result)) { - if (isset($_POST['SelectedExpense']) and $myrow['codeexpense']==$_POST['SelectedExpense']) { - echo '<option selected="selected" value="'; - } else { - echo '<option value="'; - } - echo $myrow['codeexpense'] . '">' . $myrow['codeexpense'] . ' - ' . $myrow['description'] . '</option>'; - - } //end while loop - - echo '</select></td></tr>'; - - if (!isset($_POST['Amount'])) { - $_POST['Amount']=0; - } - - echo '<tr><td>' . _('Amount') . ':</td> - <td><input type="text" class="number" name="amount" size="12" maxlength="11" value="' . $_POST['Amount'] . '" /></td></tr>'; - - if (!isset($_POST['Notes'])) { - $_POST['Notes']=''; - } - - echo '<tr><td>' . _('Notes') . ':</td> - <td><input type="text" name="Notes" size="50" maxlength="49" value="' . $_POST['Notes'] . '" /></td></tr>'; - - if (!isset($_POST['Receipt'])) { - $_POST['Receipt']=''; - } - - echo '<tr><td>' . _('Receipt') . ':</td> - <td><input type="text" name="Receipt" size="50" maxlength="49" value="' . $_POST['Receipt'] . '" /></td></tr>'; - echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; - echo '<input type="hidden" name="Days" value="' .$Days. '" />'; - - echo '</td></tr></table>'; // close main table - echo '<p><div class="centre"><input type="submit" name="submit" value="' . _('Accept') . '" /><input type="submit" name="Cancel" value="' . _('Cancel') . '" /></div>'; - echo '</form>'; - - } // end if user wish to delete - -} - -include('includes/footer.inc'); +<?php + +/* $Id$*/ + +include('includes/session.inc'); +$title = _('Claim Petty Cash Expenses From Tab'); +include('includes/header.inc'); + + +if (isset($_POST['SelectedTabs'])){ + $SelectedTabs = mb_strtoupper($_POST['SelectedTabs']); +} elseif (isset($_GET['SelectedTabs'])){ + $SelectedTabs = mb_strtoupper($_GET['SelectedTabs']); +} + +if (isset($_POST['SelectedIndex'])){ + $SelectedIndex = $_POST['SelectedIndex']; +} elseif (isset($_GET['SelectedIndex'])){ + $SelectedIndex = $_GET['SelectedIndex']; +} + +if (isset($_POST['Days'])){ + $Days = filter_number_format($_POST['Days']); +} elseif (isset($_GET['Days'])){ + $Days = filter_number_format($_GET['Days']); +} + +if (isset($_POST['Cancel'])) { + unset($SelectedTabs); + unset($SelectedIndex); + unset($Days); + unset($_POST['Amount']); + unset($_POST['Notes']); + unset($_POST['Receipt']); +} + + +if (isset($_POST['Process'])) { + + if ($_POST['SelectedTabs']=='') { + echo prnMsg(_('You have not selected a tab to claim the expenses on'),'error'); + unset($SelectedTabs); + } +} + +if (isset($_POST['Go'])) { + if ($Days<=0) { + prnMsg(_('The number of days must be a positive number'),'error'); + $Days=30; + } +} + +if (isset($_POST['submit'])) { +//initialise no input errors assumed initially before we test + $InputError = 0; + + /* actions to take once the user has clicked the submit button + ie the page has called itself with some user input */ + + //first off validate inputs sensible + + if ($_POST['SelectedExpense']=='') { + $InputError=1; + prnMsg(_('You have not selected an expense to claim on this tab'),'error'); + } elseif ($_POST['amount']==0) { + $InputError = 1; + prnMsg( _('The Amount must be greater than 0'),'error'); + } + + if (isset($SelectedIndex) AND $InputError !=1) { + $sql = "UPDATE pcashdetails + SET date = '".FormatDateForSQL($_POST['Date'])."', + codeexpense = '" . $_POST['SelectedExpense'] . "', + amount = '" .-filter_number_format($_POST['amount']) . "', + notes = '" . $_POST['Notes'] . "', + receipt = '" . $_POST['Receipt'] . "' + WHERE counterindex = '".$SelectedIndex."'"; + + $msg = _('The Expense Claim on Tab') . ' ' . $SelectedTabs . ' ' . _('has been updated'); + + } elseif ($InputError !=1 ) { + + // First check the type is not being duplicated + // Add new record on submit + + $sql = "INSERT INTO pcashdetails (counterindex, + tabcode, + date, + codeexpense, + amount, + authorized, + posted, + notes, + receipt) + VALUES (NULL, + '" . $_POST['SelectedTabs'] . "', + '".FormatDateForSQL($_POST['Date'])."', + '" . $_POST['SelectedExpense'] . "', + '" . -filter_number_format($_POST['amount']) . "', + 0, + 0, + '" . $_POST['Notes'] . "', + '" . $_POST['Receipt'] . "' + )"; + + $msg = _('The Expense Claim on Tab') . ' ' . $_POST['SelectedTabs'] . ' ' . _('has been created'); + } + + if ( $InputError !=1) { + //run the SQL from either of the above possibilites + $result = DB_query($sql,$db); + prnMsg($msg,'success'); + + unset($_POST['SelectedExpense']); + unset($_POST['amount']); + unset($_POST['Date']); + unset($_POST['Notes']); + unset($_POST['Receipt']); + } + +} elseif ( isset($_GET['delete']) ) { + + $sql="DELETE FROM pcashdetails + WHERE counterindex='".$SelectedIndex."'"; + $ErrMsg = _('Petty Cash Expense record could not be deleted because'); + $result = DB_query($sql,$db,$ErrMsg); + prnMsg(_('Petty cash Expense record') . ' ' . $SelectedTabs . ' ' . _('has been deleted') ,'success'); + + unset($_GET['delete']); + +}//end of get delete + +if (!isset($SelectedTabs)){ + + /* It could still be the first time the page has been run and a record has been selected for modification - SelectedTabs will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters + then none of the above are true and the list of sales types will be displayed with + links to delete or edit each. These will call the same page again and allow update/input + or deletion of the records*/ + echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/money_add.png" title="' . _('Payment Entry') . '" alt="" />' . ' ' . $title . '</p>'; + + echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; + echo '<div>'; + echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + echo '<br /><table class="selection">'; //Main table + + echo '<tr><td>' . _('Petty Cash Tabs for User ') . $_SESSION['UserID'] . ':</td> + <td><select name="SelectedTabs">'; + + $SQL = "SELECT tabcode + FROM pctabs + WHERE usercode='" . $_SESSION['UserID'] . "'"; + + $result = DB_query($SQL,$db); + echo '<option value="">' . _('Not Yet Selected') . '</option>'; + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectTabs']) and $myrow['tabcode']==$_POST['SelectTabs']) { + echo '<option selected="selected" value="'; + } else { + echo '<option value="'; + } + echo $myrow['tabcode'] . '">' . $myrow['tabcode'] . '</option>'; + + } //end while loop + + echo '</select></td></tr>'; + echo '</table>'; // close main table + DB_free_result($result); + + echo '<br /><div class="centre"><input type="submit" name="Process" value="' . _('Accept') . '" /><input type="submit" name="Cancel" value="' . _('Cancel') . '" /></div>'; + echo '</div>'; + echo '</form>'; + +} else { // isset($SelectedTabs) + + echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/money_add.png" title="' . _('Petty Cash Claim Entry') . '" alt="" /> + ' . ' ' . $title . '</p>'; + + echo '<br /><div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Select another tab') . '</a></div>'; + + if (! isset($_GET['edit']) OR isset ($_POST['GO'])){ + echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; + echo '<div>'; + echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + echo '<br /><table class="selection">'; + echo '<tr><th colspan="8"><h3>' . _('Petty Cash Tab') . ' ' .$SelectedTabs. '</h3></th></tr>'; + echo '<tr><th colspan="8">' . _('Detail Of Movements For Last ') .': '; + + + if(!isset ($Days)){ + $Days=30; + } + + /* Retrieve decimal places to display */ + $SqlDecimalPlaces="SELECT decimalplaces + FROM currencies,pctabs + WHERE currencies.currabrev = pctabs.currency + AND tabcode='" . $SelectedTabs . "'"; + $result = DB_query($SqlDecimalPlaces,$db); + $myrow=DB_fetch_array($result); + $CurrDecimalPlaces = $myrow['decimalplaces']; + + echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; + echo '<input type="text" class="number" name="Days" value="' . $Days . '" maxlength="3" size="4" /> ' ._('Days'); + echo '<input type="submit" name="Go" value="' . _('Go') . '" />'; + echo '</th></tr>'; + + if (isset($_POST['Cancel'])) { + unset($_POST['SelectedExpense']); + unset($_POST['amount']); + unset($_POST['Date']); + unset($_POST['Notes']); + unset($_POST['Receipt']); + } + + $sql = "SELECT * FROM pcashdetails + WHERE tabcode='".$SelectedTabs."' + AND date >=DATE_SUB(CURDATE(), INTERVAL ".$Days." DAY) + ORDER BY date, counterindex ASC"; + + $result = DB_query($sql,$db); + + echo '<tr> + <th>' . _('Date Of Expense') . '</th> + <th>' . _('Expense Description') . '</th> + <th>' . _('Amount') . '</th> + <th>' . _('Authorized') . '</th> + <th>' . _('Notes') . '</th> + <th>' . _('Receipt') . '</th> + </tr>'; + + $k=0; //row colour counter + + while ($myrow = DB_fetch_row($result)) { + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k=1; + } + + $sqldes="SELECT description + FROM pcexpenses + WHERE codeexpense='". $myrow['3'] . "'"; + + $ResultDes = DB_query($sqldes,$db); + $Description=DB_fetch_array($ResultDes); + + if (!isset($Description['0'])){ + $Description['0']='ASSIGNCASH'; + } + if ($myrow['5']=='0000-00-00') { + $AuthorisedDate=_('Unauthorised'); + } else { + $AuthorisedDate=ConvertSQLDate($myrow['5']); + } + if (($myrow['5'] == '0000-00-00') and ($Description['0'] != 'ASSIGNCASH')){ + // only movements NOT authorized can be modified or deleted + printf('<td>%s</td> + <td>%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + <td><a href="%sSelectedIndex=%s&SelectedTabs=' . $SelectedTabs . '&Days=' . $Days . '&edit=yes">' . _('Edit') . '</a></td> + <td><a href="%sSelectedIndex=%s&SelectedTabs=' . $SelectedTabs . '&Days=' . $Days . '&delete=yes" onclick=\'return confirm("' . _('Are you sure you wish to delete this code and the expenses it may have set up?') . '");\'>' . _('Delete') . '</a></td> + </tr>', + ConvertSQLDate($myrow['2']), + $Description['0'], + locale_number_format($myrow['4'],$CurrDecimalPlaces), + $AuthorisedDate, + $myrow['7'], + $myrow['8'], + htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', $myrow['0'], + htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', $myrow['0']); + } else { + printf('<td>%s</td> + <td>%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + </tr>', + ConvertSQLDate($myrow['2']), + $Description['0'], + locale_number_format($myrow['4'],$CurrDecimalPlaces), + $AuthorisedDate, + $myrow['7'], + $myrow['8']); + + } + + } + //END WHILE LIST LOOP + + $sqlamount="SELECT sum(amount) + FROM pcashdetails + WHERE tabcode='".$SelectedTabs."'"; + + $ResultAmount = DB_query($sqlamount,$db); + $Amount=DB_fetch_array($ResultAmount); + + if (!isset($Amount['0'])) { + $Amount['0']=0; + } + + echo '<tr><td colspan="2" style="text-align:right" >' . _('Current balance') . ':</td> + <td class="number">'.locale_number_format($Amount['0'],$CurrDecimalPlaces) . '</td></tr>'; + + + echo '</table>'; + echo '</div> + </form>'; + } + + if (! isset($_GET['delete'])) { + + echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; + echo '<div>'; + echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + + if ( isset($_GET['edit'])) { + $sql = "SELECT * + FROM pcashdetails + WHERE counterindex='".$SelectedIndex."'"; + + $result = DB_query($sql, $db); + $myrow = DB_fetch_array($result); + + $_POST['Date'] = ConvertSQLDate($myrow['date']); + $_POST['SelectedExpense'] = $myrow['codeexpense']; + $_POST['Amount'] = -$myrow['amount']; + $_POST['Notes'] = $myrow['notes']; + $_POST['Receipt'] = $myrow['receipt']; + + echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; + echo '<input type="hidden" name="SelectedIndex" value="' . $SelectedIndex. '" />'; + echo '<input type="hidden" name="Days" value="' .$Days. '" />'; + + }//end of Get Edit + + if (!isset($_POST['Date'])) { + $_POST['Date']=Date($_SESSION['DefaultDateFormat']); + } + + echo '<br /><table class="selection">'; //Main table + echo '<tr><td>' . _('Date Of Expense') . ':</td> + <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="Date" size="10" maxlength="10" value="' . $_POST['Date']. '" /></td></tr>'; + echo '<tr><td>' . _('Code Of Expense') . ':</td><td><select name="SelectedExpense">'; + + DB_free_result($result); + + $SQL = "SELECT pcexpenses.codeexpense, + pcexpenses.description + FROM pctabexpenses, pcexpenses, pctabs + WHERE pctabexpenses.codeexpense = pcexpenses.codeexpense + AND pctabexpenses.typetabcode = pctabs.typetabcode + AND pctabs.tabcode = '".$SelectedTabs."' + ORDER BY pcexpenses.codeexpense ASC"; + + $result = DB_query($SQL,$db); + echo '<option value="">' . _('Not Yet Selected') . '</option>'; + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectedExpense']) and $myrow['codeexpense']==$_POST['SelectedExpense']) { + echo '<option selected="selected" value="'; + } else { + echo '<option value="'; + } + echo $myrow['codeexpense'] . '">' . $myrow['codeexpense'] . ' - ' . $myrow['description'] . '</option>'; + + } //end while loop + + echo '</select></td></tr>'; + + if (!isset($_POST['Amount'])) { + $_POST['Amount']=0; + } + + echo '<tr><td>' . _('Amount') . ':</td> + <td><input type="text" class="number" name="amount" size="12" maxlength="11" value="' . $_POST['Amount'] . '" /></td></tr>'; + + if (!isset($_POST['Notes'])) { + $_POST['Notes']=''; + } + + echo '<tr><td>' . _('Notes') . ':</td> + <td><input type="text" name="Notes" size="50" maxlength="49" value="' . $_POST['Notes'] . '" /></td></tr>'; + + if (!isset($_POST['Receipt'])) { + $_POST['Receipt']=''; + } + + echo '<tr><td>' . _('Receipt') . ':</td> + <td><input type="text" name="Receipt" size="50" maxlength="49" value="' . $_POST['Receipt'] . '" /></td></tr>'; + echo '</table>'; // close main table + + echo '<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />'; + echo '<input type="hidden" name="Days" value="' .$Days. '" />'; + + echo '<br /><div class="centre"><input type="submit" name="submit" value="' . _('Accept') . '" /><input type="submit" name="Cancel" value="' . _('Cancel') . '" /></div>'; + echo '</div> + </form>'; + + } // end if user wish to delete + +} + +include('includes/footer.inc'); ?> \ No newline at end of file Modified: trunk/PcExpenses.php =================================================================== --- trunk/PcExpenses.php 2012-04-03 20:28:39 UTC (rev 5216) +++ trunk/PcExpenses.php 2012-04-03 21:57:50 UTC (rev 5217) @@ -1,356 +1,358 @@ -<?php - -/* $Id$*/ - -include('includes/session.inc'); -$title = _('Maintenance Of Petty Cash Of Expenses'); -include('includes/header.inc'); - -echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/money_add.png" title="' . _('Payment Entry') - . '" alt="" />' . ' ' . $title . '</p>'; - -if (isset($_POST['SelectedExpense'])){ - $SelectedExpense = mb_strtoupper($_POST['SelectedExpense']); -} elseif (isset($_GET['SelectedExpense'])){ - $SelectedExpense = mb_strtoupper($_GET['SelectedExpense']); -} - -if (isset($_POST['Cancel'])) { - unset($SelectedExpense); - unset($_POST['CodeExpense']); - unset($_POST['Description']); - unset($_POST['GLAccount']); - unset($_POST['Tag']); -} - - -if (isset($Errors)) { - unset($Errors); -} - -$Errors = array(); - -if (isset($_POST['submit'])) { - - //initialise no input errors assumed initially before we test - $InputError = 0; - - /* actions to take once the user has clicked the submit button - ie the page has called itself with some user input */ - - //first off validate inputs sensible - $i=1; - - if ($_POST['CodeExpense']=='' OR $_POST['CodeExpense']==' ' OR $_POST['CodeExpense']==' ') { - $InputError = 1; - prnMsg(_('The Expense type code cannot be an empty string or spaces'),'error'); - echo '<br />'; - $Errors[$i] = 'CodeExpense'; - $i++; - } elseif (mb_strlen($_POST['CodeExpense']) >20) { - $InputError = 1; - prnMsg(_('The Expense code must be twenty characters or less long'),'error'); - echo '<br />'; - $Errors[$i] = 'CodeExpense'; - $i++; - }elseif (ContainsIllegalCharacters($_POST['CodeExpense'])){ - $InputError = 1; - prnMsg(_('The Expense code cannot contain any of the following characters " \' - &'),'error'); - echo '<br />'; - $Errors[$i] = 'CodeExpense'; - $i++; - } elseif (ContainsIllegalCharacters($_POST['Description'])){ - $InputError = 1; - prnMsg(_('The Expense description cannot contain any of the following characters " \' - &'),'error'); - echo '<br />'; - $Errors[$i] = 'Description'; - $i++; - } elseif (mb_strlen($_POST['Description']) >50) { - $InputError = 1; - prnMsg(_('The tab code must be Fifty characters or less long'),'error'); - echo '<br />'; - echo '<br />'; - $Errors[$i] = 'Description'; - $i++; - } elseif (mb_strlen($_POST['Description'])==0) { - $InputError = 1; - echo prnMsg(_('The tab code description must be entered'),'error'); - echo '<br />'; - $Errors[$i] = 'Description'; - $i++; - } elseif ($_POST['GLAccount']=='') { - $InputError = 1; - echo prnMsg(_('A general ledger code must be selected for this expense'),'error'); - echo '<br />'; - } - - if (isset($SelectedExpense) AND $InputError !=1) { - - $sql = "UPDATE pcexpenses - SET description = '" . $_POST['Description'] . "', - glaccount = '" . $_POST['GLAccount'] . "', - tag = '" . $_POST['Tag'] . "' - WHERE codeexpense = '" . $SelectedExpense . "'"; - - $msg = _('The Expenses type') . ' ' . $SelectedExpense . ' ' . _('has been updated'); - } elseif ( $InputError !=1 ) { - - // First check the type is not being duplicated - - $checkSql = "SELECT count(*) - FROM pcexpenses - WHERE codeexpense = '" . $_POST['CodeExpense'] . "'"; - - $checkresult = DB_query($checkSql,$db); - $checkrow = DB_fetch_row($checkresult); - - if ( $checkrow[0] > 0 ) { - $InputError = 1; - prnMsg( _('The Expense type ') . $_POST['CodeExpense'] . _(' already exists.'),'error'); - } else { - - // Add new record on submit - - $sql = "INSERT INTO pcexpenses - (codeexpense, - description, - glaccount, - tag) - VALUES ('" . $_POST['CodeExpense'] . "', - '" . $_POST['Description'] . "', - '" . $_POST['GLAccount'] . "', - '" . $_POST['Tag'] . "')"; - - $msg = _('Expense ') . ' ' . $_POST['CodeExpense'] . ' ' . _('has been created'); - $checkSql = "SELECT count(codeexpense) - FROM pcexpenses"; - $result = DB_query($checkSql, $db); - $row = DB_fetch_row($result); - - } - } - - if ( $InputError !=1) { - //run the SQL from either of the above possibilites - $result = DB_query($sql,$db); - prnMsg($msg,'success'); - echo '<br />'; - unset($SelectedExpense); - unset($_POST['CodeExpense']); - unset($_POST['Description']); - unset($_POST['GLAccount']); - unset($_POST['Tag']); - } - -} elseif ( isset($_GET['delete']) ) { - - // PREVENT DELETES IF DEPENDENT RECORDS IN 'PcTabExpenses' - - $sql= "SELECT COUNT(*) - FROM pctabexpenses - WHERE codeexpense='" . $SelectedExpense . "'"; - - $ErrMsg = _('The number of type of tabs using this expense code could not be retrieved'); - $result = DB_query($sql,$db,$ErrMsg); - - $myrow = DB_fetch_row($result); - if ($myrow[0]>0) { - prnMsg(_('Cannot delete this petty cash expense because it is used in some tab types') . '<br />' . _('There are') . ' ' . $myrow[0] . ' ' . _('tab types using this expense code'),'error'); - - } else { - - $sql="DELETE FROM pcexpenses - WHERE codeexpense='" . $SelectedExpense . "'"; - $ErrMsg = _('The expense type record could not be deleted because'); - $result = DB_query($sql,$db,$ErrMsg); - prnMsg(_('Expense type') . ' ' . $SelectedExpense . ' ' . _('has been deleted') ,'success'); - echo '<br />'; - unset ($SelectedExpense); - unset($_GET['delete']); - } //end if tab type used in transactions -} - -if (!isset($SelectedExpense)){ - -/* It could still be the second time the page has been run and a record has been selected for modification - SelectedExpense will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters -then none of the above are true and the list of sales types will be displayed with -links to delete or edit each. These will call the same page again and allow update/input -or deletion of the records*/ - - $sql = "SELECT * - FROM pcexpenses"; - $result = DB_query($sql,$db); - - echo '<table class="selection">'; - echo '<tr> - <th>' . _('Code Of Expense') . '</th> - <th>' . _('Description') . '</th> - <th>' . _('Account Code') . '</th> - <th>' . _('Account Description') . '</th> - <th>' . _('Tag') . '</th> - </tr>'; - - $k=0; //row colour counter - - while ($myrow = DB_fetch_row($result)) { - if ($k==1){ - echo '<tr class="EvenTableRows">'; - $k=0; - } else { - echo '<tr class="OddTableRows">'; - $k=1; - } - - $sqldesc="SELECT accountname - FROM chartmaster - WHERE accountcode='". $myrow[2] . "'"; - - $ResultDes = DB_query($sqldesc,$db); - $Description=DB_fetch_array($ResultDes); - - $SqlDescTag="SELECT tagdescription - FROM tags - WHERE tagref='". $myrow[3] . "'"; - - $ResultDesTag = DB_query($SqlDescTag,$db); - $DescriptionTag=DB_fetch_array($ResultDesTag); - - printf('<td>%s</td> - <td>%s</td> - <td class="number">%s</td> - <td>%s</td> - <td>%s</td> - <td><a href="%sSelectedExpense=%s">' . _('Edit') . '</td> - <td><a href="%sSelectedExpense=%s&delete=yes" onclick="return confirm(\'' . _('Are you sure you wish to delete this expense code and all the details it may have set up?') . '\');">' . _('Delete') . '</td> - </tr>', - $myrow[0], - $myrow[1], - $myrow[2], - $Description['accountname'], - $DescriptionTag['tagdescription'], - htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', $myrow[0], - htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', $myrow[0]); - } - //END WHILE LIST LOOP - echo '</table>'; -} - -//end of ifs and buts! -if (isset($SelectedExpense)) { - - echo '<p><div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Show All Petty Cash Expenses Defined') . '</a></div><p>'; -} -if (! isset($_GET['delete'])) { - - echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; - echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; - echo '<p><table class="selection">'; //Main table - - // The user wish to EDIT an existing type - if ( isset($SelectedExpense) AND $SelectedExpense!='' ){ - - $sql = "SELECT codeexpense, - description, - glaccount, - tag - FROM pcexpenses - WHERE codeexpense='" . $SelectedExpense . "'"; - - $result = DB_query($sql, $db); - $myrow = DB_fetch_array($result); - - $_POST['CodeExpense'] = $myrow['codeexpense']; - $_POST['Description'] = $myrow['description']; - $_POST['GLAccount'] = $myrow['glaccount']; - $_POST['Tag'] = $myrow['tag']; - - echo '<input type="hidden" name="SelectedExpense" value="' . $SelectedExpense . '" />'; - echo '<input type="hidden" name="CodeExpense" value="' . $_POST['CodeExpense']. '" />'; - // We dont allow the user to change an existing type code - echo '<table class="selection"> - <tr> - <td>' . _('Code Of Expense') . ':</td> - <td>' . $_POST['CodeExpense'] . '</td> - </tr>'; - - } else { - - // This is a new type so the user may volunteer a type code - - echo '<table class="selection"> - <tr> - <td>' . _('Code Of Expense') . ':</td> - <td><input type="text"' . (in_array('CodeExpense',$Errors) ? 'class="inputerror"' : '' ) .' name="CodeExpense" /></td> - </tr>'; - - } - - if (!isset($_POST['Description'])) { - $_POST['Description']=''; - } - echo '<tr> - <td>' . _('Description') . ':</td> - <td><input type="text" ' . (in_array('Description',$Errors) ? 'class="inputerror"' : '' ) . ' name="Description" size="50" maxlength="49" value="' . $_POST['Description'] . '" /></td> - </tr>'; - - echo '<tr> - <td>' . _('Account Code') . ':</td> - <td><select name="GLAccount">'; - - DB_free_result($result); - $SQL = "SELECT accountcode, - accountname - FROM chartmaster - ORDER BY accountcode"; - $result = DB_query($SQL,$db); - echo '<option value="">' . _('Not Yet Selected') . '</option>'; - while ($myrow = DB_fetch_array($result)) { - if (isset($_POST['GLAccount']) and $myrow['accountcode']==$_POST['GLAccount']) { - echo '<option selected="selected" value="'; - } else { - echo '<option value="'; - } - echo $myrow['accountcode'] . '">' . $myrow['accountcode'] . ' - ' . $myrow['accountname'] . '</option>'; - - } //end while loop - - echo '</select></td></tr>'; - - //Select the tag - DB_free_result($result); - echo '<tr> - <td>' . _('Tag') . ':</td> - <td><select name="Tag">'; - - $SQL = "SELECT tagref, - tagdescription - FROM tags - ORDER BY tagref"; - - $result=DB_query($SQL,$db); - echo '<option value="0">0 - ' . _('None') . '</option>'; - while ($myrow=DB_fetch_array($result)){ - if (isset($_POST['Tag']) and $_POST['Tag']==$myrow['tagref']){ - echo '<option selected="selected" value="' . $myrow['tagref'] . '">' . $myrow['tagref'].' - ' .$myrow['tagdescription'].'</option>'; - } else { - echo '<option value="' . $myrow['tagref'] . '">' . $myrow['tagref'].' - ' .$myrow['tagdescription'] . '</option>'; - } - } - echo '</select></td>'; - // End select tag - - echo '</td></tr></table>'; // close main table - - echo '<br /> - <div class="centre"> - <input type="submit" name="submit" value="' . _('Accept') . '" /> - <input type="submit" name="Cancel" value="' . _('Cancel') . '" /> - </div>'; - - echo '</form>'; - -} // end if user wish to delete - - -include('includes/footer.inc'); +<?php + +/* $Id$*/ + +include('includes/session.inc'); +$title = _('Maintenance Of Petty Cash Of Expenses'); +include('includes/header.inc'); + +echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/money_add.png" title="' . _('Payment Entry') + . '" alt="" />' . ' ' . $title . '</p>'; + +if (isset($_POST['SelectedExpense'])){ + $SelectedExpense = mb_strtoupper($_POST['SelectedExpense']); +} elseif (isset($_GET['SelectedExpense'])){ + $SelectedExpense = mb_strtoupper($_GET['SelectedExpense']); +} + +if (isset($_POST['Cancel'])) { + unset($SelectedExpense); + unset($_POST['CodeExpense']); + unset($_POST['Description']); + unset($_POST['GLAccount']); + unset($_POST['Tag']); +} + + +if (isset($Errors)) { + unset($Errors); +} + +$Errors = array(); + +if (isset($_POST['submit'])) { + + //initialise no input errors assumed initially before we test + $InputError = 0; + + /* actions to take once the user has clicked the submit button + ie the page has called itself with some user input */ + + //first off validate inputs sensible + $i=1; + + if ($_POST['CodeExpense']=='' OR $_POST['CodeExpense']==' ' OR $_POST['CodeExpense']==' ') { + $InputError = 1; + prnMsg(_('The Expense type code cannot be an empty string or spaces'),'error'); + echo '<br />'; + $Errors[$i] = 'CodeExpense'; + $i++; + } elseif (mb_strlen($_POST['CodeExpense']) >20) { + $InputError = 1; + prnMsg(_('The Expense code must be twenty characters or less long'),'error'); + echo '<br />'; + $Errors[$i] = 'CodeExpense'; + $i++; + }elseif (ContainsIllegalCharacters($_POST['CodeExpense'])){ + $InputError = 1; + prnMsg(_('The Expense code cannot contain any of the following characters " \' - &'),'error'); + echo '<br />'; + $Errors[$i] = 'CodeExpense'; + $i++; + } elseif (ContainsIllegalCharacters($_POST['Description'])){ + $InputError = 1; + prnMsg(_('The Expense description cannot contain any of the following characters " \' - &'),'error'); + echo '<br />'; + $Errors[$i] = 'Description'; + $i++; + } elseif (mb_strlen($_POST['Description']) >50) { + $InputError = 1; + prnMsg(_('The tab code must be Fifty characters or less long'),'error'); + echo '<br />'; + echo '<br />'; + $Errors[$i] = 'Description'; + $i++; + } elseif (mb_strlen($_POST['Description'])==0) { + $InputError = 1; + echo prnMsg(_('The tab code description must be entered'),'error'); + echo '<br />'; + $Errors[$i] = 'Description'; + $i++; + } elseif ($_POST['GLAccount']=='') { + $InputError = 1; + echo prnMsg(_('A general ledger code must be selected for this expense'),'error'); + echo '<br />'; + } + + if (isset($SelectedExpense) AND $InputError !=1) { + + $sql = "UPDATE pcexpenses + SET description = '" . $_POST['Description'] . "', + glaccount = '" . $_POST['GLAccount'] . "', + tag = '" . $_POST['Tag'] . "' + WHERE codeexpense = '" . $SelectedExpense . "'"; + + $msg = _('The Expenses type') . ' ' . $SelectedExpense . ' ' . _('has been updated'); + } elseif ( $InputError !=1 ) { + + // First check the type is not being duplicated + + $checkSql = "SELECT count(*) + FROM pcexpenses + WHERE codeexpense = '" . $_POST['CodeExpense'] . "'"; + + $checkresult = DB_query($checkSql,$db); + $checkrow = DB_fetch_row($checkresult); + + if ( $checkrow[0] > 0 ) { + $InputError = 1; + prnMsg( _('The Expense type ') . $_POST['CodeExpense'] . _(' already exists.'),'error'); + } else { + + // Add new record on submit + + $sql = "INSERT INTO pcexpenses + (codeexpense, + description, + glaccount, + tag) + VALUES ('" . $_POST['CodeExpense'] . "', + '" . $_POST['Description'] . "', + '" . $_POST['GLAccount'] . "', + '" . $_POST['Tag'] . "')"; + + $msg = _('Expense ') . ' ' . $_POST['CodeExpense'] . ' ' . _('has been created'); + $checkSql = "SELECT count(codeexpense) + FROM pcexpenses"; + $result = DB_query($checkSql, $db); + $row = DB_fetch_row($result); + + } + } + + if ( $InputError !=1) { + //run the SQL from either of the above possibilites + $result = DB_query($sql,$db); + prnMsg($msg,'success'); + echo '<br />'; + unset($SelectedExpense); + unset($_POST['CodeExpense']); + unset($_POST['Description']); + unset($_POST['GLAccount']); + unset($_POST['Tag']); + } + +} elseif ( isset($_GET['delete']) ) { + + // PREVENT DELETES IF DEPENDENT RECORDS IN 'PcTabExpenses' + + $sql= "SELECT COUNT(*) + FROM pctabexpenses + WHERE codeexpense='" . $SelectedExpense . "'"; + + $ErrMsg = _('The number of type of tabs using this expense code could not be retrieved'); + $result = DB_query($sql,$db,$ErrMsg); + + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + prnMsg(_('Cannot delete this petty cash expense because it is used in some tab types') . '<br />' . _('There are') . ' ' . $myrow[0] . ' ' . _('tab types using this expense code'),'error'); + + } else { + + $sql="DELETE FROM pcexpenses + WHERE codeexpense='" . $SelectedExpense . "'"; + $ErrMsg = _('The expense type record could not be deleted because'); + $result = DB_query($sql,$db,$ErrMsg); + prnMsg(_('Expense type') . ' ' . $SelectedExpense . ' ' . _('has been deleted') ,'success'); + echo '<br />'; + unset ($SelectedExpense); + unset($_GET['delete']); + } //end if tab type used in transactions +} + +if (!isset($SelectedExpense)){ + +/* It could still be the second time the page has been run and a record has been selected for modification - SelectedExpense will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters +then none of the above are true and the list of sales types will be displayed with +links to delete or edit each. These will call the same page again and allow update/input +or deletion of the records*/ + + $sql = "SELECT * + FROM pcexpenses"; + $result = DB_query($sql,$db); + + echo '<table class="selection">'; + echo '<tr> + <th>' . _('Code Of Expense') . '</th> + <th>' . _('Description') . '</th> + <th>' . _('Account Code') . '</th> + <th>' . _('Account Description') . '</th> + <th>' . _('Tag') . '</th> + </tr>'; + + $k=0; //row colour counter + + while ($myrow = DB_fetch_row($result)) { + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k=1; + } + + $sqldesc="SELECT accountname + FROM chartmaster + WHERE accountcode='". $myrow[2] . "'"; + + $ResultDes = DB_query($sqldesc,$db); + $Description=DB_fetch_array($ResultDes); + + $SqlDescTag="SELECT tagdescription + FROM tags + WHERE tagref='". $myrow[3] . "'"; + + $ResultDesTag = DB_query($SqlDescTag,$db); + $DescriptionTag=DB_fetch_array($ResultDesTag); + + printf('<td>%s</td> + <td>%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td><a href="%sSelectedExpense=%s">' . _('Edit') . '</a></td> + <td><a href="%sSelectedExpense=%s&delete=yes" onclick="return confirm(\'' . _('Are you sure you wish to delete this expense code and all the details it may have set up?') . '\');">' . _('Delete') . '</a></td> + </tr>', + $myrow[0], + $myrow[1], + $myrow[2], + $Description['accountname'], + $DescriptionTag['tagdescription'], + htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', $myrow[0], + htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?', $myrow[0]); + } + //END WHILE LIST LOOP + echo '</table>'; +} + +//end of ifs and buts! +if (isset($SelectedExpense)) { + + echo '<br /><div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Show All Petty Cash Expenses Defined') . '</a></div>'; +} +if (! isset($_GET['delete'])) { + + echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; + echo '<div>'; + echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + echo '<br />'; //Main table + + // The user wish to EDIT an existing type + if ( isset($SelectedExpense) AND $SelectedExpense!='' ){ + + $sql = "SELECT codeexpense, + description, + glaccount, + tag + FROM pcexpenses + WHERE codeexpense='" . $SelectedExpense . "'"; + + $result = DB_query($sql, $db); + $myrow = DB_fetch_array($result); + + $_POST['CodeExpense'] = $myrow['codeexpense']; + $... [truncated message content] |