1<?php 2// PcReportTab.php 3// . 4 5include ('includes/session.php'); 6$ViewTopic = 'PettyCash'; 7$BookMark = 'PcReportTab'; 8$Title = _('Petty Cash Management Report'); 9 10include ('includes/SQL_CommonFunctions.inc'); 11 12if (isset($_POST['SelectedTabs'])){ 13 $SelectedTabs = mb_strtoupper($_POST['SelectedTabs']); 14} elseif (isset($_GET['SelectedTabs'])){ 15 $SelectedTabs = mb_strtoupper($_GET['SelectedTabs']); 16} 17 18if ((! isset($_POST['FromDate']) AND ! isset($_POST['ToDate'])) OR isset($_POST['SelectDifferentDate'])) { 19 20 include ('includes/header.php'); 21 22 echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/money_add.png" title="' . _('Payment Entry') 23 . '" alt="" />' . ' ' . $Title . '</p>'; 24 25 echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '"> 26 <div> 27 <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; 28 29 if (!isset($_POST['FromDate'])){ 30 $_POST['FromDate'] = Date($_SESSION['DefaultDateFormat'], mktime(0,0,0,Date('m'),1,Date('Y'))); 31 } 32 33 if (!isset($_POST['ToDate'])){ 34 $_POST['ToDate'] = Date($_SESSION['DefaultDateFormat']); 35 } 36 37 /*Show a form to allow input of criteria for Tabs to show */ 38 echo '<table class="selection"> 39 <tr> 40 <td>' . _('Petty Cash Tab') . ':</td> 41 <td><select name="SelectedTabs">'; 42 43 $SQL = "SELECT tabcode 44 FROM pctabs 45 WHERE ( authorizer = '" . $_SESSION['UserID'] . 46 "' OR usercode = '" . $_SESSION['UserID']. 47 "' OR assigner = '" . $_SESSION['UserID'] . "' ) 48 ORDER BY tabcode"; 49 $Result = DB_query($SQL); 50 51 while ($MyRow = DB_fetch_array($Result)) { 52 if (isset($_POST['SelectedTabs']) and $MyRow['tabcode'] == $_POST['SelectedTabs']) { 53 echo '<option selected="selected" value="', $MyRow['tabcode'], '">', $MyRow['tabcode'], '</option>'; 54 } else { 55 echo '<option value="', $MyRow['tabcode'], '">', $MyRow['tabcode'], '</option>'; 56 } 57 } //end while loop get type of tab 58 59 DB_free_result($Result); 60 61 62 echo '</select></td> 63 </tr> 64 <tr> 65 <td>', _('From Date'), ':</td> 66 <td><input tabindex="2" class="date" type="text" name="FromDate" maxlength="10" size="11" value="' . $_POST['FromDate'] . '" /></td> 67 </tr> 68 <tr> 69 <td>', _('To Date'), ':</td> 70 <td><input tabindex="3" class="date" type="text" name="ToDate" maxlength="10" size="11" value="' . $_POST['ToDate'] . '" /></td> 71 </tr> 72 </table> 73 <br /> 74 <div class="centre"> 75 <input type="submit" name="ShowTB" value="' . _('Show HTML') . '" /> 76 <input type="submit" name="PrintPDF" value="' . _('Print PDF') . '" /> 77 </div> 78 </div> 79 </form>'; 80 81} elseif (isset($_POST['PrintPDF'])) { 82 83 include('includes/PDFStarter.php'); 84 $PageNumber = 0; 85 $FontSize = 10; 86 $pdf->addInfo('Title', _('Petty Cash Report Of Tab') ); 87 $pdf->addInfo('Subject', _('Petty Cash Report Of Tab') ); 88 $line_height = 12; 89 90 $SQLFromDate = FormatDateForSQL($_POST['FromDate']); 91 $SQLToDate = FormatDateForSQL($_POST['ToDate']); 92 93 $SQL = "SELECT counterindex, 94 tabcode, 95 tag, 96 date, 97 codeexpense, 98 amount, 99 authorized, 100 posted, 101 purpose, 102 notes 103 FROM pcashdetails 104 WHERE tabcode = '" . $SelectedTabs . "' 105 AND date >= '" . $SQLFromDate . "' AND date <= '" . $SQLToDate . "' 106 ORDER BY date, counterindex ASC"; 107 108 $TabDetail = DB_query($SQL); 109 110 $SQLDecimalPlaces = "SELECT decimalplaces 111 FROM currencies,pctabs 112 WHERE currencies.currabrev = pctabs.currency 113 AND tabcode='" . $SelectedTabs . "'"; 114 $Result = DB_query($SQLDecimalPlaces); 115 $MyRow = DB_fetch_array($Result); 116 $CurrDecimalPlaces = $MyRow['decimalplaces']; 117 118 if (DB_error_no() != 0){ 119 include('includes/header.php'); 120 prnMsg(_('An error occurred getting the orders details'),'',_('Database Error')); 121 if ($debug == 1){ 122 prnMsg( _('The SQL used to get the orders that failed was') . '<br />' . $SQL, '',_('Database Error')); 123 } 124 include ('includes/footer.php'); 125 exit; 126 } elseif (DB_num_rows($TabDetail) == 0){ 127 include('includes/header.php'); 128 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'); 129 if ($debug == 1) { 130 prnMsg(_('The SQL that returned no rows was') . '<br />' . $SQL,'',_('Database Error')); 131 } 132 include('includes/footer.php'); 133 exit; 134 } 135 136 include('includes/PDFTabReportHeader.inc'); 137 138 $SQLTabs = "SELECT tabcode, 139 usercode, 140 typetabcode, 141 currency, 142 tablimit, 143 assigner, 144 authorizer, 145 authorizerexpenses, 146 glaccountassignment, 147 glaccountpcash, 148 defaulttag, 149 taxgroupid 150 FROM pctabs 151 WHERE tabcode='" . $SelectedTabs . "'"; 152 153 $TabResult = DB_query($SQLTabs, _('No Petty Cash tabs were returned by the SQL because'), _('The SQL that failed was:')); 154 155 $Tabs = DB_fetch_array($TabResult); 156 157 $SQLBalance = "SELECT SUM(amount) FROM pcashdetails 158 WHERE tabcode = '" . $SelectedTabs . "' 159 AND date < '" . $SQLFromDate . "'"; 160 161 $TabBalance = DB_query($SQLBalance); 162 163 $Balance = DB_fetch_array($TabBalance); 164 165 if( !isset($Balance['0'])){ 166 $Balance['0'] = 0; 167 } 168 169 $YPos -= (2 * $line_height); 170 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('Tab Code :')); 171 $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,20,$FontSize,': '); 172 $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,$SelectedTabs); 173 $LeftOvers = $pdf->addTextWrap($Left_Margin+290,$YPos,70,$FontSize,_('From') . ' '); 174 $LeftOvers = $pdf->addTextWrap($Left_Margin+320,$YPos,20,$FontSize,': '); 175 $LeftOvers = $pdf->addTextWrap($Left_Margin+340,$YPos,70,$FontSize,$_POST['FromDate']); 176 177 $YPos -= $line_height; 178 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('User ')); 179 $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,20,$FontSize,': '); 180 $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,$Tabs['usercode']); 181 $LeftOvers = $pdf->addTextWrap($Left_Margin+290,$YPos,70,$FontSize,_('To') . ' '); 182 $LeftOvers = $pdf->addTextWrap($Left_Margin+320,$YPos,20,$FontSize,': '); 183 $LeftOvers = $pdf->addTextWrap($Left_Margin+340,$YPos,70,$FontSize,$_POST['ToDate']); 184 185 $YPos -= $line_height; 186 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('Currency') . ' '); 187 $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,20,$FontSize,': '); 188 $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,$Tabs['currency']); 189 190 $YPos -= $line_height; 191 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('Cash Assigner')); 192 $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,20,$FontSize,': '); 193 $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,$Tabs['assigner']); 194 195 $YPos -= $line_height; 196 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('Authoriser - Cash')); 197 $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,20,$FontSize,': '); 198 $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,$Tabs['authorizer']); 199 200 $YPos -= $line_height; 201 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,80,$FontSize,_('Authoriser - Expenses')); 202 $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,20,$FontSize,': '); 203 $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,$Tabs['authorizer']); 204 205 $YPos -= $line_height; 206 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,50,$FontSize,_('Balance before ')); 207 $LeftOvers = $pdf->addTextWrap($Left_Margin+55,$YPos,70,$FontSize,$_POST['FromDate']); 208 $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,20,$FontSize,': '); 209 $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,locale_number_format($Balance['0'], $CurrDecimalPlaces)); 210 $LeftOvers = $pdf->addTextWrap($Left_Margin+150,$YPos,70,$FontSize,$Tabs['currency']); 211 212 $YPos -= (2 * $line_height); 213 $pdf->line($Page_Width-$Right_Margin, $YPos+$line_height,$Left_Margin, $YPos+$line_height); 214 215 $YPos -= (2 * $line_height); 216 $FontSize = 8; 217 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,70,$FontSize,_('Date of Expense')); 218 $LeftOvers = $pdf->addTextWrap($Left_Margin+60,$YPos,100,$FontSize,_('Expense Code')); 219 $LeftOvers = $pdf->addTextWrap($Left_Margin+160,$YPos,100,$FontSize,_('Gross Amount')); 220 $LeftOvers = $pdf->addTextWrap($Left_Margin+210,$YPos,100,$FontSize,_('Tax')); 221 $LeftOvers = $pdf->addTextWrap($Left_Margin+255,$YPos,100,$FontSize,_('Tax Group')); 222 $LeftOvers = $pdf->addTextWrap($Left_Margin+320,$YPos,100,$FontSize,_('Tag')); 223 $LeftOvers = $pdf->addTextWrap($Left_Margin+380,$YPos,100,$FontSize,_('Notes')); 224 $LeftOvers = $pdf->addTextWrap($Left_Margin+465,$YPos,100,$FontSize,_('Date Authorised')); 225 $YPos -= (2 * $line_height); 226 227 while ($MyRow = DB_fetch_array($TabDetail)) { 228 229 $SQLDes = "SELECT description 230 FROM pcexpenses 231 WHERE codeexpense = '" . $MyRow[codeexpense] . "'"; 232 233 $ResultDes = DB_query($SQLDes); 234 $Description = DB_fetch_array($ResultDes); 235 if (!isset($Description['0'])){ 236 $Description['0']='ASSIGNCASH'; 237 } 238 239 $TagSQL = "SELECT tagdescription FROM tags WHERE tagref='" . $MyRow['tag'] . "'"; 240 $TagResult = DB_query($TagSQL); 241 $TagRow = DB_fetch_array($TagResult); 242 if ($MyRow['tag'] == 0) { 243 $TagRow['tagdescription'] = _('None'); 244 } 245 $TagTo = $MyRow['tag']; 246 $TagDescription = $TagTo . ' - ' . $TagRow['tagdescription']; 247 248 $TaxesDescription = ''; 249 $TaxesTaxAmount = ''; 250 $TaxSQL = "SELECT counterindex, 251 pccashdetail, 252 calculationorder, 253 description, 254 taxauthid, 255 purchtaxglaccount, 256 taxontax, 257 taxrate, 258 amount 259 FROM pcashdetailtaxes 260 WHERE pccashdetail='" . $MyRow['counterindex'] . "'"; 261 $TaxResult = DB_query($TaxSQL); 262 263 while ($MyTaxRow = DB_fetch_array($TaxResult)) { 264 $TaxesDescription .= $MyTaxRow['description'] . "\n"; //Line breaks not working !? 265 $TaxesTaxAmount .= locale_number_format($MyTaxRow['amount'], $CurrDecimalPlaces) . "\n"; //Line breaks not working !? 266 } 267 268 if ($MyRow['authorized'] == '0000-00-00') { 269 $AuthorisedDate = _('Unauthorised'); 270 } else { 271 $AuthorisedDate = ConvertSQLDate($MyRow['authorized']); 272 } 273 274 // Print total for each account 275 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,70,$FontSize,ConvertSQLDate($MyRow['date'])); 276 $LeftOvers = $pdf->addTextWrap($Left_Margin+60,$YPos,130,$FontSize,$Description[0]); 277 $LeftOvers = $pdf->addTextWrap($Left_Margin+160,$YPos,50,$FontSize,locale_number_format($MyRow['amount'], $CurrDecimalPlaces),'right'); 278 $LeftOvers = $pdf->addTextWrap($Left_Margin+210,$YPos,50,$FontSize,$TaxesTaxAmount); 279 $LeftOvers = $pdf->addTextWrap($Left_Margin+255,$YPos,50,$FontSize,$TaxesDescription); 280 $LeftOvers = $pdf->addTextWrap($Left_Margin+320,$YPos,50,$FontSize,$TagDescription); 281 $LeftOvers = $pdf->addTextWrap($Left_Margin+380,$YPos,60,$FontSize,$MyRow['notes']); 282 $LeftOvers = $pdf->addTextWrap($Left_Margin+465,$YPos,70,$FontSize,$AuthorisedDate); 283 $YPos -= $line_height; 284 285 } //end of while loop 286 287 $SQLAmount="SELECT sum(amount) 288 FROM pcashdetails 289 WHERE tabcode = '" . $SelectedTabs . "' 290 AND date <= '" . $SQLToDate . "'"; 291 292 $ResultAmount = DB_query($SQLAmount); 293 $Amount = DB_fetch_array($ResultAmount); 294 295 if (!isset($Amount[0])) { 296 $Amount[0] = 0; 297 } 298 299 $YPos -= (2 * $line_height); 300 $pdf->line($Left_Margin+250, $YPos+$line_height,$Left_Margin+500, $YPos+$line_height); 301 $LeftOvers = $pdf->addTextWrap($Left_Margin+70,$YPos,100,$FontSize,_('Balance at')); 302 $LeftOvers = $pdf->addTextWrap($Left_Margin+110,$YPos,70,$FontSize,$_POST['ToDate']); 303 $LeftOvers = $pdf->addTextWrap($Left_Margin+160,$YPos,20,$FontSize,': '); 304 $LeftOvers = $pdf->addTextWrap($Left_Margin+160,$YPos,70,$FontSize,locale_number_format($Amount[0], $CurrDecimalPlaces),'right'); 305 $LeftOvers = $pdf->addTextWrap($Left_Margin+240,$YPos,70,$FontSize,$Tabs['currency']); 306 $pdf->line($Page_Width-$Right_Margin, $YPos+$line_height,$Left_Margin, $YPos+$line_height); 307 308 $pdf->OutputD($_SESSION['DatabaseName'] . '_PettyCash_Tab_Report_' . date('Y-m-d') . '.pdf'); 309 $pdf->__destruct(); 310 exit; 311} else { 312 313 include('includes/header.php'); 314 315 echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/money_add.png" title="' . _('Payment Entry') 316 . '" alt="" />' . ' ' . $Title . '</p>'; 317 318 $SQLFromDate = FormatDateForSQL($_POST['FromDate']); 319 $SQLToDate = FormatDateForSQL($_POST['ToDate']); 320 321 echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; 322 echo '<div>'; 323 echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; 324 echo '<input type="hidden" name="FromDate" value="' . $_POST['FromDate'] . '" /> 325 <input type="hidden" name="ToDate" value="' . $_POST['ToDate'] . '" />'; 326 327 $SQLTabs = "SELECT tabcode, 328 usercode, 329 typetabcode, 330 currency, 331 tablimit, 332 assigner, 333 authorizer, 334 authorizerexpenses, 335 glaccountassignment, 336 glaccountpcash, 337 defaulttag, 338 taxgroupid 339 FROM pctabs 340 WHERE tabcode = '" . $SelectedTabs . "'"; 341 342 $TabResult = DB_query($SQLTabs, 343 _('No Petty Cash Tabs were returned by the SQL because'), 344 _('The SQL that failed was:')); 345 346 $Tabs = DB_fetch_array($TabResult); 347 348 $SQLDecimalPlaces = "SELECT decimalplaces 349 FROM currencies,pctabs 350 WHERE currencies.currabrev = pctabs.currency 351 AND tabcode='" . $SelectedTabs . "'"; 352 $Result = DB_query($SQLDecimalPlaces); 353 $MyRow = DB_fetch_array($Result); 354 $CurrDecimalPlaces = $MyRow['decimalplaces']; 355 356 echo '<br /><table class="selection">'; 357 358 echo '<tr> 359 <td>' . _('Tab Code') . ':</td> 360 <td></td> 361 <td>' . '' . $SelectedTabs . '</td> 362 </tr>'; 363 364 echo '<tr> 365 <td>' . _('From') . ':</td> 366 <td></td> 367 <td>' . '' . $_POST['FromDate'] . '</td> 368 </tr>'; 369 370 echo '<tr> 371 <td>' . _('User') . ':</td> 372 <td></td> 373 <td>' . '' . $Tabs['usercode'] . '</td> 374 </tr>'; 375 376 echo '<tr> 377 <td>' . _('To') . ':</td> 378 <td></td> 379 <td>' . '' . $_POST['ToDate'] . '</td> 380 </tr>'; 381 382 echo '<tr> 383 <td>' . _('Authoriser') . ':</td> 384 <td></td> 385 <td>' . '' . $Tabs['authorizer'] . '</td> 386 </tr>'; 387 echo '<tr> 388 <td>' . _('Currency') . ':</td> 389 <td></td> 390 <td>' . '' . $Tabs['currency'] . '</td> 391 </tr>'; 392 393 $SQLBalance = "SELECT SUM(amount) 394 FROM pcashdetails 395 WHERE tabcode = '" . $SelectedTabs . "' 396 AND date < '" . $SQLFromDate . "'"; 397 398 $TabBalance = DB_query($SQLBalance); 399 400 $Balance = DB_fetch_array($TabBalance); 401 402 if( !isset($Balance['0'])){ 403 $Balance['0'] = 0; 404 } 405 406 echo '<tr><td>' . _('Balance before ') . '' . $_POST['FromDate'] . ':</td> 407 <td></td> 408 <td>' . locale_number_format($Balance['0'],$_SESSION['CompanyRecord']['decimalplaces']) . ' ' . $Tabs['currency'] . '</td> 409 </tr>'; 410 411 $SQLBalanceNotAut = "SELECT SUM(amount) 412 FROM pcashdetails 413 WHERE tabcode = '" . $SelectedTabs . "' 414 AND authorized = '0000-00-00' 415 AND date < '" . $SQLFromDate . "'"; 416 417 $TabBalanceNotAut = DB_query($SQLBalanceNotAut); 418 419 $BalanceNotAut = DB_fetch_array($TabBalanceNotAut); 420 421 if( !isset($BalanceNotAut['0'])){ 422 $BalanceNotAut['0'] = 0; 423 } 424 425 echo '<tr><td>' . _('Total not authorised before ') . '' . $_POST['FromDate'] . ':</td> 426 <td></td> 427 <td>' . '' . locale_number_format($BalanceNotAut['0'],$_SESSION['CompanyRecord']['decimalplaces']) . ' ' . $Tabs['currency'] . '</td> 428 </tr>'; 429 430 431 echo '</table>'; 432 433 /*show a table of the accounts info returned by the SQL 434 Account Code , Account Name , Month Actual, Month Budget, Period Actual, Period Budget */ 435 436 $SQL = "SELECT counterindex, 437 tabcode, 438 tag, 439 date, 440 codeexpense, 441 amount, 442 authorized, 443 posted, 444 purpose, 445 notes 446 FROM pcashdetails 447 WHERE tabcode = '" . $SelectedTabs . "' 448 AND date >= '" . $SQLFromDate . "' 449 AND date <= '" . $SQLToDate . "' 450 ORDER BY date, counterindex Asc"; 451 452 $TabDetail = DB_query($SQL, 453 _('No Petty Cash movements for this tab were returned by the SQL because'), 454 _('The SQL that failed was:')); 455 456 echo '<br /> 457 <table class="selection"> 458 <thead> 459 <tr> 460 <th class="ascending">' . _('Date of Expense') . '</th> 461 <th class="ascending">' . _('Expense Code') . '</th> 462 <th class="ascending">' . _('Gross Amount') . '</th> 463 <th>' . _('Tax') . '</th> 464 <th>' . _('Tax Group') . '</th> 465 <th>' . _('Tag') . '</th> 466 <th>' . _('Business Purpose') . '</th> 467 <th>' . _('Notes') . '</th> 468 <th>' . _('Receipt Attachment') . '</th> 469 <th class="ascending">' . _('Date Authorised') . '</th> 470 </tr> 471 </thead> 472 </tbody>'; 473 474 while ($MyRow = DB_fetch_array($TabDetail)) { 475 476 $TagSQL = "SELECT tagdescription FROM tags WHERE tagref='" . $MyRow['tag'] . "'"; 477 $TagResult = DB_query($TagSQL); 478 $TagRow = DB_fetch_array($TagResult); 479 if ($MyRow['tag'] == 0) { 480 $TagRow['tagdescription'] = _('None'); 481 } 482 $TagTo = $MyRow['tag']; 483 $TagDescription = $TagTo . ' - ' . $TagRow['tagdescription']; 484 485 $TaxesDescription = ''; 486 $TaxesTaxAmount = ''; 487 $TaxSQL = "SELECT counterindex, 488 pccashdetail, 489 calculationorder, 490 description, 491 taxauthid, 492 purchtaxglaccount, 493 taxontax, 494 taxrate, 495 amount 496 FROM pcashdetailtaxes 497 WHERE pccashdetail='" . $MyRow['counterindex'] . "'"; 498 $TaxResult = DB_query($TaxSQL); 499 500 while ($MyTaxRow = DB_fetch_array($TaxResult)) { 501 $TaxesDescription .= $MyTaxRow['description'] . '<br />'; 502 $TaxesTaxAmount .= locale_number_format($MyTaxRow['amount'], $CurrDecimalPlaces) . '<br />'; 503 } 504 505 //Generate download link for expense receipt, or show text if no receipt file is found. 506 $ReceiptSupportedExt = array('png','jpg','jpeg','pdf','doc','docx','xls','xlsx'); //Supported file extensions 507 $ReceiptDir = $PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/expenses_receipts/'; //Receipts upload directory 508 $ReceiptSQL = "SELECT hashfile, 509 extension 510 FROM pcreceipts 511 WHERE pccashdetail='" . $MyRow['counterindex'] . "'"; 512 $ReceiptResult = DB_query($ReceiptSQL); 513 $ReceiptRow = DB_fetch_array($ReceiptResult); 514 if (DB_num_rows($ReceiptResult) > 0) { //If receipt exists in database 515 $ReceiptHash = $ReceiptRow['hashfile']; 516 $ReceiptExt = $ReceiptRow['extension']; 517 $ReceiptFileName = $ReceiptHash . '.' . $ReceiptExt; 518 $ReceiptPath = $ReceiptDir . $ReceiptFileName; 519 $ReceiptText = '<a href="' . $ReceiptPath . '" download="ExpenseReceipt-' . mb_strtolower($SelectedTabs) . '-[' . $MyRow['date'] . ']-[' . $MyRow['counterindex'] . ']">' . _('Download attachment') . '</a>'; 520 } else { 521 $ReceiptText = _('No attachment'); 522 } 523 524 if ($MyRow['authorized'] == '0000-00-00') { 525 $AuthorisedDate = _('Unauthorised'); 526 } else { 527 $AuthorisedDate = ConvertSQLDate($MyRow['authorized']); 528 } 529 530 $SQLDes = "SELECT description 531 FROM pcexpenses 532 WHERE codeexpense = '" . $MyRow['codeexpense'] . "'"; 533 534 $ResultDes = DB_query($SQLDes); 535 $Description=DB_fetch_array($ResultDes); 536 if (!isset($Description[0])) { 537 $ExpenseCodeDes = 'ASSIGNCASH'; 538 } else { 539 $ExpenseCodeDes = $MyRow['codeexpense'] . ' - ' . $Description[0]; 540 } 541 542 echo '<tr class="striped_row"> 543 <td>', ConvertSQLDate($MyRow['date']), '</td> 544 <td>', $ExpenseCodeDes, '</td> 545 <td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td> 546 <td class="number">', $TaxesTaxAmount, '</td> 547 <td>', $TaxesDescription, '</td> 548 <td>', $TagDescription, '</td> 549 <td>', $MyRow['purpose'], '</td> 550 <td>', $MyRow['notes'], '</td> 551 <td>', $ReceiptText, '</td> 552 <td>', $AuthorisedDate, '</td> 553 </tr>'; 554 } 555 556 $SQLAmount="SELECT sum(amount) 557 FROM pcashdetails 558 WHERE tabcode = '" . $SelectedTabs . "' 559 AND date <= '" . $SQLToDate . "'"; 560 561 $ResultAmount = DB_query($SQLAmount); 562 $Amount = DB_fetch_array($ResultAmount); 563 564 if (!isset($Amount[0])) { 565 $Amount[0] = 0; 566 } 567 568 echo '</tbody> 569 <tfoot> 570 <tr> 571 <td colspan="2" class="number">' . _('Balance at') . ' ' .$_POST['ToDate'] . ':</td> 572 <td>' . locale_number_format($Amount[0],$_SESSION['CompanyRecord']['decimalplaces']) . ' </td> 573 <td>' . $Tabs['currency'] . '</td> 574 </tr> 575 </tfoot>'; 576 577 echo '</table>'; 578 echo '<br /><div class="centre"><input type="submit" name="SelectDifferentDate" value="' . _('Select A Different Date') . '" /></div>'; 579 echo '</div> 580 </form>'; 581} 582include('includes/footer.php'); 583 584?>