From: <tim...@us...> - 2010-02-17 22:11:53
|
Revision: 3350 http://web-erp.svn.sourceforge.net/web-erp/?rev=3350&view=rev Author: tim_schofield Date: 2010-02-17 22:11:45 +0000 (Wed, 17 Feb 2010) Log Message: ----------- Pak Ricard: New Petty cash module Modified Paths: -------------- trunk/WWW_Users.php trunk/doc/Change.log.html trunk/index.php trunk/sql/mysql/upgrade3.11.1-3.12.sql Added 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 Added: trunk/PcAssignCashToTab.php =================================================================== --- trunk/PcAssignCashToTab.php (rev 0) +++ trunk/PcAssignCashToTab.php 2010-02-17 22:11:45 UTC (rev 3350) @@ -0,0 +1,356 @@ +<?php +/* $Revision: 1.0 $ */ + +$PageSecurity = 6; + +include('includes/session.inc'); +$title = _('Assignation of Cash to Petty Cash Tab'); +include('includes/header.inc'); + +if (isset($_POST['SelectedTabs'])){ + $SelectedTabs = strtoupper($_POST['SelectedTabs']); +} elseif (isset($_GET['SelectedTabs'])){ + $SelectedTabs = strtoupper($_GET['SelectedTabs']); +} + +if (isset($_POST['SelectedIndex'])){ + $SelectedIndex = $_POST['SelectedIndex']; +} elseif (isset($_GET['SelectedIndex'])){ + $SelectedIndex = $_GET['SelectedIndex']; +} + +if (isset($_POST['Days'])){ + $Days = $_POST['Days']; +} elseif (isset($_GET['Days'])){ + $Days = $_GET['Days']; +} + +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 */ + + $i=1; + + if ($_POST['Amount']==0) { + $InputError = 1; + prnMsg('<br>' . _('The Amount must be inputed'),'error'); + $Errors[$i] = 'TabCode'; + $i++; + } + + $sqlLimit = "SELECT tablimit + FROM pctabs + WHERE tabcode='$SelectedTabs'"; + + $ResultLimit = DB_query($sqlLimit,$db); + $Limit=DB_fetch_array($ResultLimit); + + if (($_POST['CurrentAmount']+$_POST['amount'])>$Limit['tablimit']){ + prnMsg('<br>' . _('The balance after this assignation would be greater than the specified limit for this PC tab'),'warning'); + } + + if ($InputError !=1 AND isset($SelectedIndex) ) { + + $sql = "UPDATE pcashdetails + SET date = '".FormatDateForSQL($_POST['Date'])."', + amount = '" . $_POST['Amount'] . "', + authorized = '0000-00-00', + notes = '" . $_POST['Notes'] . "', + receipt = '" . $_POST['Receipt'] . "' + WHERE counterindex = '$SelectedIndex'"; + $msg = _('Assignation of cash to PC Tab ') . ' ' . $SelectedTabs . ' ' . _('has been updated'); + + } elseif ($InputError !=1 ) { + // Add new record on submit + $sql = "INSERT INTO pcashdetails + (counterindex, + tabcode, + date, + codeexpense, + amount, + authorized, + posted, + notes, + receipt) + VALUES ('', + '" . $_POST['SelectedTabs'] . "', + '".FormatDateForSQL($_POST['Date'])."', + 'ASSIGNCASH', + '" .$_POST['Amount'] . "', + '0000-00-00', + '0', + '" . $_POST['Notes'] . "', + '" . $_POST['Receipt'] . "' + )"; + $msg = _('Assignation of cash to PC 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['Notes']); + unset($_POST['Receipt']); + } + +} elseif ( isset($_GET['delete']) ) { + $sql="DELETE FROM pcashdetails + WHERE counterindex='$SelectedIndex'"; + $ErrMsg = _('The assignation of cash record could not be deleted because'); + $result = DB_query($sql,$db,$ErrMsg); + prnMsg(_('Assignation of cash to PC Tab ') . ' ' . $SelectedTabs . ' ' . _('has been deleted') ,'success'); + unset($_GET['delete']); +} + +if (!isset($SelectedTabs)){ + + /* It could still be the second 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 "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table border=1>'; //Main table + echo '<td><table>'; // First column + + echo '<tr><td>' . _('Petty Cash Tab To Assign Cash') . ":</td><td><select name='SelectedTabs'>"; + + DB_free_result($result); + $SQL = "SELECT tabcode + FROM pctabs + WHERE authorizer='" . $_SESSION['UserID'] . "' + ORDER BY tabcode"; + + $result = DB_query($SQL,$db); + + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectTabs']) and $myrow['tabcode']==$_POST['SelectTabs']) { + echo "<option selected VALUE='"; + } else { + echo "<option VALUE='"; + } + echo $myrow['tabcode'] . "'>" . $myrow['tabcode']; + } + + echo '</select></td></tr>'; + echo '</table>'; // close table in first column + 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>'; +} + +//end of ifs and buts! +if (isset($_POST['process'])OR isset($SelectedTabs)) { + + echo '<p><div class="centre"><a href="' . $_SERVER['PHP_SELF'] . '?' . SID . '">' . _('Details Of Petty Cash Tab ') . '' .$SelectedTabs. '<a/></div><p>'; + + if (! isset($_GET['edit']) OR isset ($_POST['GO'])){ + + echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo "<div class='centre'><p>" . _('Detail Of PC Tab Movements For Last ') .': '; + if(!isset ($Days)){ + $Days=30; + } + 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 '<p></div></form>'; + + if (isset($_POST['Cancel'])) { + unset($_POST['Amount']); + unset($_POST['Date']); + unset($_POST['Notes']); + unset($_POST['Receipt']); + } + +/* $sql = "SELECT pcashdetails.date, + pcashdetails.codeexpense, + pcexpenses.description + pcashdetails.amount, + pcashdetails.authorized, + pcashdetails.posted, + pcashdetails.notes, + pcashdetails.receipt + FROM pcashdetails, pcexpenses + WHERE pcashdetails.tabcode='$SelectedTabs' + AND pcashdetails.codeexpense = pcexpenses.codeexpense + AND pcashdetails.date >=DATE_SUB(CURDATE(), INTERVAL ".$Days." DAY) + ORDER BY pcashdetails.counterindex Asc"; +*/ + $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 '<br><table BORDER=1>'; + echo "<tr> + <th>" . _('Date') . "</th> + <th>" . _('Expense Code') . "</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") and ($Description['0'] == 'ASSIGNCASH')){ + // only cash assignations 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 expense it may have set up?') . "');\">" . _('Delete') . "</td> + </tr>", + ConvertSQLDate($myrow['2']), + $Description['0'], + number_format($myrow['4'],2), + ConvertSQLDate($myrow['5']), + $myrow['7'], + $myrow['8'], + $_SERVER['PHP_SELF'] . '?' . SID, $myrow['0'], + $_SERVER['PHP_SELF'] . '?' . SID, $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'], + number_format($myrow['4'],2), + ConvertSQLDate($myrow['5']), + $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=4 style=text-align:right >" . _('Current balance') . ":</td> + <td colspan=2>".number_format($Amount['0'],2)."</td></tr>"; + + echo '</table>'; + + } + + if (! isset($_GET['delete'])) { + + echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table border=1>'; //Main table + echo '<td><table>'; // First column + + 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='CurrentAmount' VALUE=" . $Amount['0']. ">"; + echo "<input type=hidden name='Days' VALUE=" .$Days. ">"; + } + +/* Ricard: needs revision of this date initialization */ + if (!isset($_POST['Date'])) { + $_POST['Date']=Date("d/m/Y"); + } + + 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>'; + + + 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='CurrentAmount' VALUE=" . $Amount['0']. ">"; + echo "<input type=hidden name='SelectedTabs' VALUE=" . $SelectedTabs . ">"; + echo "<input type=hidden name='Days' VALUE=" .$Days. ">"; + + echo '</table>'; // close table in first column + 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'); +?> \ No newline at end of file Property changes on: trunk/PcAssignCashToTab.php ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/PcAuthorizeExpenses.php =================================================================== --- trunk/PcAuthorizeExpenses.php (rev 0) +++ trunk/PcAuthorizeExpenses.php 2010-02-17 22:11:45 UTC (rev 3350) @@ -0,0 +1,293 @@ + +<?php +/* $Revision: 1.0 $ */ + +$PageSecurity = 6; + +include('includes/session.inc'); +$title = _('Authorization of Petty Cash Expenses'); +include('includes/header.inc'); +include('includes/SQL_CommonFunctions.inc'); + +if (isset($_POST['SelectedTabs'])){ + $SelectedTabs = strtoupper($_POST['SelectedTabs']); +} elseif (isset($_GET['SelectedTabs'])){ + $SelectedTabs = strtoupper($_GET['SelectedTabs']); +} + +if (isset($_POST['SelectedIndex'])){ + $SelectedIndex = $_POST['SelectedIndex']; +} elseif (isset($_GET['SelectedIndex'])){ + $SelectedIndex = $_GET['SelectedIndex']; +} + +if (isset($_POST['Days'])){ + $Days = $_POST['Days']; +} elseif (isset($_GET['Days'])){ + $Days = $_GET['Days']; +} + +if (isset($Errors)) { + unset($Errors); +} + +$Errors = array(); + + +echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/magnifier.png" title="' . _('Petty Cash') . '" alt="">' . ' <a href="' . $_SERVER['PHP_SELF'] . '?' . SID . '">' . _('Authorization Of Petty Cash Expenses ') . ''.$SelectedTabs.'<a/>'; + +if (isset($_POST['submit']) or isset($_POST['update']) OR isset($SelectedTabs) OR isset ($_POST['GO'])) { + + echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo "<div class='centre'><p>" . _('Detail Of Movement For Last ') .': '; + + if(!isset ($Days)){ + $Days=30; + } + 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 '<p></div></form>'; + + $sql = "SELECT pcashdetails.counterindex, + pcashdetails.tabcode, + pcashdetails.date, + pcashdetails.codeexpense, + pcashdetails.amount, + pcashdetails.authorized, + pcashdetails.posted, + pcashdetails.notes, + pcashdetails.receipt, + pctabs.glaccountassignment, + pctabs.glaccountpcash, + pctabs.usercode, + pctabs.currency, + currencies.rate + FROM pcashdetails, pctabs, currencies + WHERE pcashdetails.tabcode = pctabs.tabcode + AND pctabs.currency = currencies.currabrev + AND pcashdetails.tabcode = '$SelectedTabs' + AND pcashdetails.date >= DATE_SUB(CURDATE(), INTERVAL ".$Days." DAY) + ORDER BY pcashdetails.date, pcashdetails.counterindex ASC"; + + $result = DB_query($sql,$db); + + echo '<br><table BORDER=1>'; + echo "<tr> + <th>" . _('Date') . "</th> + <th>" . _('Expense Code') . "</th> + <th>" . _('Amount') . "</th> + <th>" . _('Posted') . "</th> + <th>" . _('Notes') . "</th> + <th>" . _('Receipt') . "</th> + <th>" . _('Authorized') . "</th> + </tr>"; + + $k=0; //row colour counter + echo'<form action="PcAuthorizeExpenses.php" method="POST" name="'._('update').'">'; + + while ($myrow=DB_fetch_array($result)) { + + //update database if update pressed + if (($_POST['submit']=='Update') AND isset($_POST[$myrow['counterindex']])){ + + $PeriodNo = GetPeriod(ConvertSQLDate($myrow['date']), $db); + + if ($myrow['rate'] == 1){ // functional currency + $Amount = $myrow['amount']; + }else{ // other currencies + $Amount = $myrow['amount']/$myrow['rate']; + } + + if ($myrow['codeexpense'] == 'ASSIGNCASH'){ + $type = 2; + $AccountFrom = $myrow['glaccountassignment']; + $AccountTo = $myrow['glaccountpcash']; + }else{ + $type = 1; + $Amount = -$Amount; + $AccountFrom = $myrow['glaccountpcash']; + $SQLAccExp = "SELECT glaccount + FROM pcexpenses + WHERE codeexpense = '".$myrow['codeexpense']."'"; + $ResultAccExp = DB_query($SQLAccExp,$db); + $myrowAccExp = DB_fetch_array($ResultAccExp); + $AccountTo = $myrowAccExp['glaccount']; + } + + //get typeno + $typeno = GetNextTransNo($type,$db); + + //build narrative + $narrative= "PettyCash - ".$myrow['tabcode']." - ".$myrow['codeexpense']." - ".$myrow['notes']." - ".$myrow['receipt'].""; + //insert to gltrans + + $sqlFrom="INSERT INTO `gltrans` + (`counterindex`, + `type`, + `typeno`, + `chequeno`, + `trandate`, + `periodno`, + `account`, + `narrative`, + `amount`, + `posted`, + `jobref`, + `tag`) + VALUES (NULL, + '".$type."', + '".$typeno."', + 0, + '".$myrow['date']."', + '".$PeriodNo."', + '".$AccountFrom."', + '".$narrative."', + '".-$Amount."', + 0, + '', + 0)"; + + $ResultFrom = DB_Query($sqlFrom, $db); + + $sqlTo="INSERT INTO `gltrans` + (`counterindex`, + `type`, + `typeno`, + `chequeno`, + `trandate`, + `periodno`, + `account`, + `narrative`, + `amount`, + `posted`, + `jobref`, + `tag`) + VALUES (NULL, + '".$type."', + '".$typeno."', + 0, + '".$myrow['date']."', + '".$PeriodNo."', + '".$AccountTo."', + '".$narrative."', + '".$Amount."', + 0, + '', + 0)"; + + $ResultTo = DB_Query($sqlTo, $db); + + if ($myrow['codeexpense'] == 'ASSIGNCASH'){ + // if it's a cash assignation we need to updated banktrans table as well. + $ReceiptTransNo = GetNextTransNo( 2, $db); + $SQLBank= 'INSERT INTO banktrans (transno, + type, + bankact, + ref, + exrate, + functionalexrate, + transdate, + banktranstype, + amount, + currcode) + VALUES (' . $ReceiptTransNo . ', + 1, + ' . $AccountFrom . ", '" + . $narrative . " ', + 1, + " . $myrow['rate'] . ", + '" . $myrow['date'] . "', + 'Cash', + " . -$myrow['amount'] . ", + '" . $myrow['currency'] . "' + )"; + $ErrMsg = _('Cannot insert a bank transaction because'); + $DbgMsg = _('Cannot insert a bank transaction with the SQL'); + $resultBank = DB_query($SQLBank,$db,$ErrMsg,$DbgMsg,true); + + } + + $sql = "UPDATE pcashdetails + SET authorized = '".Date('Y-m-d')."', + posted = 1 + WHERE counterindex = '".$myrow['counterindex']."'"; + $resultupdate = DB_query($sql,$db); + } + + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k=1; + } + + echo' <td>'.ConvertSQLDate($myrow['date']).'</td> + <td>'.$myrow['codeexpense'].'</td> + <td class="number">'.number_format($myrow['amount'],2).'</td> + <td>'.$myrow['posted'].'</td> + <td>'.$myrow['notes'].'</td> + <td>'.$myrow['receipt'].'</td>'; + + if (isset($_POST[$myrow['counterindex']])){ + echo'<td>'.ConvertSQLDate(Date('Y-m-d')).'</td>'; + }else{ + $Authorizer=ConvertSQLDate($myrow['authorized']); + if(($Authorizer!='00/00/0000')){ + echo'<td>'.ConvertSQLDate($myrow['authorized']).'</td>'; + }else{ + 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> '; + + + } //end of looping + + // Do the postings + include ('includes/GLPostings.inc'); + + echo'<tr><td style="text-align:right" colspan=4><input type=submit name=submit value=' . _("Update") . '></td></tr></form>'; + +} else { /*The option to submit was not hit so display form */ + + +echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table border=1>'; //Main table + echo '<td><table>'; // First column + +echo '<tr><td>' . _('Authorize 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); + + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectTabs']) and $myrow['tabcode']==$_POST['SelectTabs']) { + echo "<option selected VALUE='"; + } else { + echo "<option VALUE='"; + } + echo $myrow['tabcode'] . "'>" . $myrow['tabcode']; + + } //end while loop get type of tab + + echo '</select></td></tr>'; + + echo '</table>'; // close table in first column + 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>'; +} /*end of else not submit */ +include('includes/footer.inc'); +?> Property changes on: trunk/PcAuthorizeExpenses.php ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/PcClaimExpensesFromTab.php =================================================================== --- trunk/PcClaimExpensesFromTab.php (rev 0) +++ trunk/PcClaimExpensesFromTab.php 2010-02-17 22:11:45 UTC (rev 3350) @@ -0,0 +1,364 @@ +<?php +/* $Revision: 1.0 $ */ + +$PageSecurity = 6; + +include('includes/session.inc'); +$title = _('Claim Petty Cash Expenses From Tab'); +include('includes/header.inc'); + + +if (isset($_POST['SelectedTabs'])){ + $SelectedTabs = strtoupper($_POST['SelectedTabs']); +} elseif (isset($_GET['SelectedTabs'])){ + $SelectedTabs = strtoupper($_GET['SelectedTabs']); +} + +if (isset($_POST['SelectedIndex'])){ + $SelectedIndex = $_POST['SelectedIndex']; +} elseif (isset($_GET['SelectedIndex'])){ + $SelectedIndex = $_GET['SelectedIndex']; +} + +if (isset($_POST['Days'])){ + $Days = $_POST['Days']; +} elseif (isset($_GET['Days'])){ + $Days = $_GET['Days']; +} + +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['amount']==0) { + $InputError = 1; + prnMsg('<br>' . _('The Amount must be greater than 0'),'error'); + $Errors[$i] = 'TabCode'; + $i++; + } + + if (isset($SelectedIndex) AND $InputError !=1) { + $sql = "UPDATE pcashdetails + SET date = '".FormatDateForSQL($_POST['Date'])."', + codeexpense = '" . $_POST['SelectedExpense'] . "', + amount = '" .- $_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'] . "', + '" .- $_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 "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table border=1>'; //Main table + echo '<td><table>'; // First column + + 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); + + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectTabs']) and $myrow['tabcode']==$_POST['SelectTabs']) { + echo "<option selected VALUE='"; + } else { + echo "<option VALUE='"; + } + echo $myrow['tabcode'] . "'>" . $myrow['tabcode']; + + } //end while loop + + echo '</select></td></tr>'; + echo '</table>'; // close table in first column + 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>'; + +} + +//end of ifs and buts! +if (isset($_POST['process'])OR isset($SelectedTabs)) { + + echo '<p><div class="centre"><a href="' . $_SERVER['PHP_SELF'] . '?' . SID . '">' . _('Petty Cash Tab ') . '' .$SelectedTabs. '<a/></div><p>'; +/* RICARD */ + if (! isset($_GET['edit']) OR isset ($_POST['GO'])){ + echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo "<div class='centre'><p>" . _('Detail Of Movements For Last ') .': '; + + if(!isset ($Days)){ + $Days=30; + } + 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 '<p></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 '<br><table BORDER=1>'; + 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") 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 expense it may have set up?') . "');\">" . _('Delete') . "</td> + </tr>", + ConvertSQLDate($myrow['2']), + $Description['0'], + number_format($myrow['4'],2), + ConvertSQLDate($myrow['5']), + $myrow['7'], + $myrow['8'], + $_SERVER['PHP_SELF'] . '?' . SID, $myrow['0'], + $_SERVER['PHP_SELF'] . '?' . SID, $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'], + number_format($myrow['4'],2), + ConvertSQLDate($myrow['5']), + $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=4 style=text-align:right >" . _('Current balance') . ":</td> + <td colspan=2>".number_format($Amount['0'],2)."</td></tr>"; + + + echo '</table>'; + } + + if (! isset($_GET['delete'])) { + + echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table border=1>'; //Main table + echo '<td><table>'; // First column + + + 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("d/m/Y"); + } + + echo '<tr><td>' . _('Date Of Expense') . ":</td>"; + echo '<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); + + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectedExpense']) and $myrow['codeexpense']==$_POST['SelectedExpense']) { + echo "<option selected VALUE='"; + } else { + echo "<option VALUE='"; + } + echo $myrow['codeexpense'] . "'>" . $myrow['codeexpense'] . ' - ' . $myrow['description']; + + } //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 '</table>'; // close table in first column + 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'); +?> \ No newline at end of file Property changes on: trunk/PcClaimExpensesFromTab.php ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/PcExpenses.php =================================================================== --- trunk/PcExpenses.php (rev 0) +++ trunk/PcExpenses.php 2010-02-17 22:11:45 UTC (rev 3350) @@ -0,0 +1,270 @@ +<?php +/* $Revision: 1.0$ */ + +$PageSecurity = 15; + +include('includes/session.inc'); +$title = _('Maintenance Of Petty Cash Of Expenses'); +include('includes/header.inc'); + +if (isset($_POST['SelectedExpense'])){ + $SelectedExpense = strtoupper($_POST['SelectedExpense']); +} elseif (isset($_GET['SelectedExpense'])){ + $SelectedExpense = strtoupper($_GET['SelectedExpense']); +} + +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('<br>' . _('The Expense type code cannot be an empty string or spaces'),'error'); + $Errors[$i] = 'PcExpenses'; + $i++; + } elseif (strlen($_POST['codeexpense']) >20) { + $InputError = 1; + echo prnMsg(_('The Expense code must be twenty characters or less long'),'error'); + $Errors[$i] = 'PcExpenses'; + $i++; + }elseif (strlen($_POST['description']) >50) { + $InputError = 1; + echo prnMsg(_('The tab code must be Fifty characters or less long'),'error'); + $Errors[$i] = 'TypeTabCode'; + $i++; + } + + if (isset($SelectedExpense) AND $InputError !=1) { + + $sql = "UPDATE pcexpenses + SET description = '" . $_POST['description'] . "', + glaccount = '" . $_POST['glaccount'] . "' + 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 exist.'),'error'); + } else { + + // Add new record on submit + + $sql = "INSERT INTO pcexpenses + (codeexpense, + description,glaccount) + VALUES ('" . $_POST['codeexpense'] . "', + '" . $_POST['description'] . "', + '" . $_POST['glaccount'] . "')"; + + $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'); + + unset($SelectedExpense); + unset($_POST['codeexpense']); + unset($_POST['description']); + unset($_POST['glaccount']); + } + +} 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'); + 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 '<br><table BORDER=1>'; + echo "<tr> + <th>" . _('Code Of Expense') . "</th> + <th>" . _('Description') . "</th> + <th>" . _('Account Code') . "</th> + <th>" . _('Account Description') . "</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); + + printf("<td>%s</td> + <td>%s</td> + <td class=number>%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[0], + $_SERVER['PHP_SELF'] . '?' . SID, $myrow[0], + $_SERVER['PHP_SELF'] . '?' . SID, $myrow[0]); + } + //END WHILE LIST LOOP + echo '</table>'; +} + +//end of ifs and buts! +if (isset($SelectedExpense)) { + + echo '<p><div class="centre"><a href="' . $_SERVER['PHP_SELF'] . '?' . SID . '">' . _('Show All Petty Cash Expenses Defined') . '</a></div><p>'; +} +if (! isset($_GET['delete'])) { + + echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table border=1>'; //Main table + echo '<td><table>'; // First column + + + // The user wish to EDIT an existing type + if ( isset($SelectedExpense) AND $SelectedExpense!='' ) + { + + $sql = "SELECT codeexpense, + description, + glaccount + 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']; + + echo "<input type=hidden name='SelectedExpense' VALUE=" . $SelectedExpense . ">"; + echo "<input type=hidden name='codeexpense' VALUE=" . $_POST['codeexpense']. ">"; + echo "<table> <tr><td>" . _('Code Of Expense') . ":</td><td>"; + + // We dont allow the user to change an existing type code + + echo $_POST['codeexpense'] . '</td></tr>'; + + } else { + + // This is a new type so the user may volunteer a type code + + echo "<table><tr><td>" . _('Code Of Expense') . ":</td><td><input type='Text' + " . (in_array('SalesType',$Errors) ? 'class="inputerror"' : '' ) ." name='codeexpense'></td></tr>"; + + } + + if (!isset($_POST['description'])) { + $_POST['description']=''; + } + echo "<tr><td>" . _('Description') . ":</td><td><input type='Text' 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); + + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['glaccount']) and $myrow['accountcode']==$_POST['glaccount']) { + echo "<option selected VALUE='"; + } else { + echo "<option VALUE='"; + } + echo $myrow['accountcode'] . "'>" . $myrow['accountcode'] . ' - ' . $myrow['accountname']; + + } //end while loop + + echo '</select></td></tr>'; + + echo '</table>'; // close table in first column + 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'); +?> \ No newline at end of file Property changes on: trunk/PcExpenses.php ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/PcExpensesTypeTab.php =================================================================== --- trunk/PcExpensesTypeTab.php (rev 0) +++ trunk/PcExpensesTypeTab.php 2010-02-17 22:11:45 UTC (rev 3350) @@ -0,0 +1,217 @@ +<?php +/* $Revision: 1.0 $ */ + +$PageSecurity = 15; + +include('includes/session.inc'); +$title = _('Maintenance Of Petty Cash Expenses For a Type Tab'); +include('includes/header.inc'); + +if (isset($_POST['SelectedType'])){ + $SelectedType = strtoupper($_POST['SelectedType']); +} elseif (isset($_GET['SelectedType'])){ + $SelectedType = strtoupper($_GET['SelectedType']); +} + +if (isset($_POST['SelectedTabs'])){ + $SelectedTabs = strtoupper($_POST['SelectedTabs']); +} elseif (isset($_GET['SelectedTabs'])){ + $SelectedTabs = strtoupper($_GET['SelectedTabs']); +} + +if (isset($Errors)) { + unset($Errors); +} + +$Errors = array(); + +if (isset($_POST['submit'])) { + + if ( $InputError !=1 ) { + + // First check the type is not being duplicated + + $checkSql = "SELECT count(*) + FROM pctabexpenses + WHERE typetabcode= '" . $_POST['SelectedTabs'] . "' + AND codeexpense = '" . $_POST['SelectedExpense'] . "'"; + + $checkresult = DB_query($checkSql,$db); + $checkrow = DB_fetch_row($checkresult); + + if ( $checkrow[0] >0) { + $InputError = 1; + prnMsg( _('The Expense ') . $_POST['codeexpense'] . _(' already exist in this Type of Tab.'),'error'); + } else { + + // Add new record on submit + + $sql = "INSERT INTO pctabexpenses + (typetabcode, + codeexpense) + VALUES ('" . $_POST['SelectedTabs'] . "', + '" . $_POST['SelectedExpense'] . "')"; + + $msg = _('Expense code:') . ' ' . $_POST["SelectedExpense"].' for Type of Tab:' . $_POST["SelectedTabs"] . ' ' . _('has been created'); + $checkSql = "SELECT count(typetabcode) + FROM pctypetabs"; + $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'); + + unset($_POST['SelectedExpense']); + } + +} elseif ( isset($_GET['delete']) ) { + + + $sql="DELETE FROM pctabexpenses + WHERE typetabcode='$SelectedTabs' + AND codeexpense='$SelectedType'"; + $ErrMsg = _('The Tab Type record could not be deleted because'); + $result = DB_query($sql,$db,$ErrMsg); + prnMsg(_('Expense code').' '. $SelectedTabs . _('for type of tab').' '. $SelectedType .' '. _('has been deleted') ,'success'); + unset ($SelectedType); + unset($_GET['delete']); + + +} + +if (!isset($SelectedTabs)){ + +/* It could still be the second time the page has been run and a record has been selected for modification - SelectedType 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 "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table border=1>'; //Main table + echo '<td><table>'; // First column + +echo '<tr><td>' . _('Select Type of Tab') . ":</td><td><select name='SelectedTabs'>"; + + DB_free_result($result); + $SQL = "SELECT typetabcode,typetabdescription + FROM pctypetabs"; + + $result = DB_query($SQL,$db); + + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectedTabs']) and $myrow['typetabcode']==$_POST['SelectedTabs']) { + echo "<option selected VALUE='"; + } else { + echo "<option VALUE='"; + } + echo $myrow['typetabcode'] . "'>" . $myrow['typetabcode'] . ' - ' . $myrow['typetabdescription']; + + } //end while loop + + echo '</select></td></tr>'; + + echo '</table>'; // close table in first column + 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>'; + +} + +//end of ifs and buts! +if (isset($_POST['process'])OR isset($SelectedTabs)) { + + echo '<p><div class="centre"><a href="' . $_SERVER['PHP_SELF'] . '?' . SID . '">' . _('Expense Codes for Type of Tab ') . '' .$SelectedTabs. '<a/></div><p>'; + + $sql = "SELECT pctabexpenses.codeexpense, pcexpenses.description + FROM pctabexpenses,pcexpenses + WHERE pctabexpenses.codeexpense=pcexpenses.codeexpense + AND pctabexpenses.typetabcode='$SelectedTabs' + ORDER BY pctabexpenses.codeexpense ASC"; + + $result = DB_query($sql,$db); + + echo '<br><table BORDER=1>'; + echo "<tr> + <th>" . _('Expense Code') . "</th> + <th>" . _('Description') . "</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; + } + + printf("<td>%s</td> + <td>%s</td> + <td><a href='%sSelectedType=%s&delete=yes&SelectedTabs=$_POST[SelectedTabs]' onclick=\"return confirm('" . _('Are you sure you wish to delete this code and the expense it may have set up?') . "');\">" . _('Delete') . "</td> + </tr>", + $myrow[0], + $myrow[1], + $_SERVER['PHP_SELF'] . '?' . SID, $myrow[0], + $_SERVER['PHP_SELF'] . '?' . SID, $myrow[0]); + } + //END WHILE LIST LOOP + echo '</table>'; + + + + + if (! isset($_GET['delete'])) { + + echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table border=1>'; //Main table + echo '<td><table>'; // First column + + + + echo '<tr><td>' . _('Select Expense Code') . ":</td><td><select name='SelectedExpense'>"; + + DB_free_result($result); + $SQL = "SELECT codeexpense,description + FROM pcexpenses"; + + $result = DB_query($SQL,$db); + + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectedExpense']) and $myrow['codeexpense']==$_POST['SelectedExpense']) { + echo "<option selected VALUE='"; + } else { + echo "<option VALUE='"; + } + echo $myrow['codeexpense'] . "'>" . $myrow['codeexpense'] . ' - ' . $myrow['description']; + + } //end while loop + + echo '</select></td></tr>'; + + + echo "<input type=hidden name='SelectedTabs' VALUE=" . $SelectedTabs . ">"; + + echo '</table>'; // close table in first column + 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'); +?> \ No newline at end of file Property changes on: trunk/PcExpensesTypeTab.php ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/PcReportTab.php =================================================================== --- trunk/PcReportTab.php (rev 0) +++ trunk/PcReportTab.php 2010-02-17 22:11:45 UTC (rev 3350) @@ -0,0 +1,420 @@ +<?php + +/* $Revision: 1.0 $ */ + +$PageSecurity = 6; + +include ('includes/session.inc'); +include ('includes/SQL_CommonFunctions.inc'); + +$title = _('Petty Cash Management Report'); + +if (isset($_POST['SelectedTabs'])){ + $SelectedTabs = strtoupper($_POST['SelectedTabs']); +} elseif (isset($_GET['SelectedTabs'])){ + $SelectedTabs = strtoupper($_GET['SelectedTabs']); +} + +if ((! isset($_POST['FromDate']) AND ! isset($_POST['ToDate'])) OR isset($_POST['SelectDifferentDate'])){ + + include ('includes/header.inc'); + echo '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?' . SID . '">'; + + if (!isset($_POST['FromDate'])){ + $_POST['FromDate']=Date($_SESSION['DefaultDateFormat'], mktime(0,0,0,Date('m'),1,Date('Y'))); + } + + if (!isset($_POST['ToDate'])){ + $_POST['ToDate'] = Date($_SESSION['DefaultDateFormat']); + } + + /*Show a form to allow input of criteria for Tabs to show */ + echo '<table>'; + echo '<tr><td>' . _('Code Of Petty Cash Tab') . ":</td><td><select name='SelectedTabs'>"; + + DB_free_result($result); + + if ($_SESSION['AccessLevel'] >= 8){ // GL user (to supervise the supervisor) + $SQL = "SELECT tabcode + FROM pctabs"; + }else{ + $SQL = "SELECT tabcode + FROM pctabs + WHERE authorizer='" . $_SESSION['UserID'] . "'"; + } + $result = DB_query($SQL,$db); + + while ($myrow = DB_fetch_array($result)) { + if (isset($_POST['SelectTabs']) and $myrow['tabcode']==$_POST['SelectTabs']) { + echo "<option selected VALUE='"; + } else { + echo "<option VALUE='"; + } + echo $myrow['tabcode'] . "'>" . $myrow['tabcode']; + + } //end while loop get type of tab + + + echo '</select></td></tr>'; + echo'<tr><td>' . _('From Date :') . '</td><td>'; + echo '<input tabindex="2" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" type="TEXT" name="FromDate" maxlength="10" size="11" VALUE="' . $_POST['FromDate'] . '">'; + echo '</td></tr>'; + echo '<tr><td>' . _('To Date:') .'</td><td>'; + echo '<input tabindex="3" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" type="TEXT" name="ToDate" maxlength="10" size="11" VALUE="' . $_POST['ToDate'] . '">'; + echo '</td></tr></table><br>'; + echo '<div class="centre"><input type=submit Name="ShowTB" Value="' . _('Show HTML') .'">'; + echo "<input type=submit Name='PrintPDF' Value='"._('PrintPDF')."'></div>"; + +} else if (isset($_POST['PrintPDF'])) { + + + include('includes/PDFStarter.php'); + $PageNumber = 0; + $FontSize = 10; + $pdf->addinfo('Title', _('Petty Cash Report Of Tab') ); + $pdf->addinfo('Subject', _('Petty Cash Report Of Tab') ); + $line_height = 12; + + $SQL_FromDate = FormatDateForSQL($_POST['FromDate']); + $SQL_ToDate = FormatDateForSQL($_POST['ToDate']); + + $SQL = "SELECT * FROM pcashdetails + WHERE tabcode='$SelectedTabs' + AND date >='" . $SQL_FromDate . "' AND date <= '" . $SQL_ToDate . "' + ORDER BY date, counterindex ASC"; + + $TabDetail = DB_query($SQL,$db); + +if (DB_error_no($db)!=0){ + include('includes/header.inc'); + prnMsg(_('An error occurred getting the orders details'),'',_('Database Error')); + if ($debug==1){ + prnMsg( _('The SQL used to get the orders that failed was') . '<br>' . $SQL, '',_('Database Error')); + } + include ('includes/footer.inc'); + exit; +} elseif (DB_num_rows($TabDetail)==0){ + include('includes/header.inc'); + prnMsg(_('There were no expenses found in the database within the period from') . ' ' . $_POST['FromDate'] . ' ' . _('to') . ' '. $_POST['ToDate'] . '. ' . _('Please try again selecting a different date range'),'warn'); + if ($debug==1) { + prnMsg(_('The SQL that returned no rows was') . '<br>' . $SQL,'',_('Database Error')); + } + include('includes/footer.inc'); + exit; +} + + include('includes/PDFTabReportHeader.inc'); + + $SqlTabs = "SELECT * FROM pctabs + WHERE tabcode='$SelectedTabs'"; + + $TabResult = DB_query($SqlTabs, $db, _('No Petty Cash tabs were returned by the SQL because'), _('The SQL that failed was:')); + + $Tabs=DB_fetch_array($TabResult); + + $SqlBalance = "SELECT SUM(amount) FROM pcashdetails + WHERE tabcode='$SelectedTabs' + AND date<'".$SQL_FromDate."'"; + + $TabBalance = DB_query($SqlBalance, + $db); + + $Balance=DB_fetch_array($TabBalance); + + if( !isset($Balance['0'])){ + $Balance['0']=0; + } + + $YPos -= (2 * $line_height); + $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('Tab Code :')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+90,$YPos,20,$FontSize,_(': ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,70,$FontSize,$SelectedTabs); + $LeftOvers = $pdf->addTextWrap($Left_Margin+290,$YPos,70,$FontSize,_('From ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+320,$YPos,20,$FontSize,_(': ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+340,$YPos,70,$FontSize,$_POST['FromDate']); + + $YPos -= $line_height; + $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('User ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+90,$YPos,20,$FontSize,_(': ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,70,$FontSize,$Tabs['usercode']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+290,$YPos,70,$FontSize,_('To ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+320,$YPos,20,$FontSize,_(': ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+340,$YPos,70,$FontSize,$_POST['ToDate']); + + $YPos -= $line_height; + $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('Authorizer ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+90,$YPos,20,$FontSize,_(': ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,70,$FontSize,$Tabs['authorizer']); + + $YPos -= $line_height; + $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('Currency ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+90,$YPos,20,$FontSize,_(': ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,70,$FontSize,$Tabs['currency']); + + $YPos -= $line_height; + $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,40,$FontSize,_('Balance before ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+40,$YPos,70,$FontSize,$_POST['FromDate']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+90,$YPos,20,$FontSize,_(': ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,70,$FontSize,number_format($Balance['0'],2)); + $LeftOvers = $pdf->addTextWrap($Left_Margin+140,$YPos,70,$FontSize,$Tabs['currency']); + + $YPos -= (2 * $line_height); + $pdf->line($Page_Width-$Right_Margin, $YPos+$line_height,$Left_Margin, $YPos+$line_height); + + $YPos -= (2 * $line_height); + $FontSize = 8; + $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,70,$FontSize,_('Date Of Expense')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+70,$YPos,100,$FontSize,_('Description')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+200,$YPos,100,$FontSize,_('Amount')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+250,$YPos,100,$FontSize,_('Note')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+350,$YPos,100,$FontSize,_('Receipt')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+420,$YPos,100,$FontSize,_('Date Authorizer')); + $pdf->selectFont('./fonts/Helvetica.afm'); + $YPos -= (2 * $line_height); + + while ($myrow=DB_fetch_array($TabDetail)) { + + $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'; + } + + // Print total for each account + $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,70,$FontSize,ConvertSQLDate($myrow['date'])); + $LeftOvers = $pdf->addTextWrap($Left_Margin+70,$YPos,130,$FontSize,$Description[0]); + $LeftOvers = $pdf->addTextWrap($Left_Margin+180,$YPos,50,$FontSize,number_format($myrow['amount'],2),'right'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+250,$YPos,100,$FontSize,$myrow['notes']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+350,$YPos,70,$FontSize,$myrow['receipt']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+430,$YPos,70,$FontSize,ConvertSQLDate($myrow['authorized'])); + $YPos -= $line_height; + + } //end of while loop + + $sqlamount="SELECT sum(amount) + FROM pcashdetails + WHERE tabcode='$SelectedTabs' + AND date<='".$SQL_ToDate."'"; + + $ResultAmount = DB_query($sqlamount,$db); + $Amount=DB_fetch_array($ResultAmount); + + if (!isset($Amount[0])) { + $Amount[0]=0; + } + + + + $YPos -= (2 * $line_height); + $pdf->line($Left_Margin+250, $YPos+$line_height,$Left_Margin+500, $YPos+$line_height); + $LeftOvers = $pdf->addTextWrap($Left_Margin+70,$YPos,100,$FontSize,_('Balance at')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,$_POST['ToDate']); + $LeftOvers = $pdf->addTextWrap($Left_Margin+160,$YPos,20,$FontSize,_(': ')); + $LeftOvers = $pdf->addTextWrap($Left_Margin+160,$YPos,70,$FontSize,number_format($Amount[0],2),'right'); + $LeftOvers = $pdf->addTextWrap($Left_Margin+240,$YPos,70,$FontSize,$Tabs['currency']); + $pdf->line($Page_Width-$Right_Margin, $YPos+$line_height,$Left_Margin, $YPos+$line_height); + + $pdfcode = $pdf->output(); + $len = strlen($pdfcode); + + if ($len<=20){ + $title = _('Print Report Tab Error'); + include('includes/header.inc'); + echo '<p>'; + prnMsg( _('There were no entries to print out for the selections specified') ); + echo '<br><a href="'. $rootpath.'/index.php?' . SID . '">'. _('Back to the menu'). '</a>'; + include('includes/footer.inc'); + exit; + } else { + header('Content-type: application/pdf'); + header('Content-Length: ' . $len); + header('Content-Disposition: inline; filename=TabReports.pdf'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + + $pdf->Output('PcReportTabs.pdf','I'); + + } + exit; +} else { + + include('includes/header.inc'); + + + $SQL_FromDate = FormatDateForSQL($_POST['FromDate']); + $SQL_ToDate = FormatDateForSQL($_POST['ToDate']); + + echo '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?' . SID . '">'; + echo '<input type=hidden name="FromDate" VALUE="' . $_POST['FromDate'] . '"><input type=hidden name="ToDate" VALUE="' . $_POST['ToDate'] . '">'; + + $SqlTabs = "SELECT * FROM pctabs + WHERE tabcode='$SelectedTabs'"; + + $TabResult = DB_query($SqlTabs, + $db, + _('No Petty Cash Tabs were returned by the SQL because'), + _('The SQL that failed was:')); + + $Tabs=DB_fetch_array($TabResult); + + echo "<br><table >"; + + echo '<tr><td>' . _('Tab Code') . '</td> + <td>:</td> + <td width=200>' . ''.$SelectedTabs.'</td>' . + '<td>' . _('From') . '</td><td>:</td><td>' . + ''.$_POST['FromDate'].'</td></tr>'; + + echo '<tr><td>' . _('User') . '</td> + <td>:</td> + <td>' . ''.$Tabs['usercode'].'</td>'. + '<td>' . _('To') . '</td><td>:</td><td>' . + ''.$_POST['ToDate'].'</td></tr>'; + + echo '<tr><td>' . _('Authorizer') . '</td><td>:</td><td>' . ''.$Tabs['authorizer'].'</td> + </tr>'; + echo '<tr><td>' . _('Currency') . '</td><td>:</td><td>' . ''.$Tabs['currency'].'</td> + </tr>'; + + $SqlBalance = "SELECT SUM(amount) + FROM pcashdetails + WHERE tabcode='$SelectedTabs' + AND date<'".$SQL_FromDate."'"; + + $TabBalance = DB_query($SqlBalance, $db); + + $Balance=DB_fetch_array($TabBalance); + + if( !isset($Balance['0'])){ + $Balance['0']=0; + } + + echo '<tr><td>' . _('Balance before ') . ''.$_POST['FromDate'].'</td><td>:</td><td>' . ''.$Balance['0'].' '.$Tabs['currency'].'</td></tr>'; + + $SqlBalanceNotAut = "S... [truncated message content] |