|
From: <afc...@us...> - 2017-11-23 22:45:07
|
Revision: 7866
http://sourceforge.net/p/web-erp/reponame/7866
Author: afcouling
Date: 2017-11-23 22:45:05 +0000 (Thu, 23 Nov 2017)
Log Message:
-----------
Added Petty Cash receipt file upload to directory functionality.
Modified Paths:
--------------
trunk/PcAssignCashTabToTab.php
trunk/PcAssignCashToTab.php
trunk/PcAuthorizeCash.php
trunk/PcAuthorizeExpenses.php
trunk/PcClaimExpensesFromTab.php
trunk/PcExpenses.php
trunk/PcReportExpense.php
trunk/PcReportTab.php
trunk/PcTabExpensesList.php
trunk/doc/Change.log
trunk/doc/Manual/ManualPettyCash.html
Modified: trunk/PcAssignCashTabToTab.php
===================================================================
--- trunk/PcAssignCashTabToTab.php 2017-11-07 01:57:00 UTC (rev 7865)
+++ trunk/PcAssignCashTabToTab.php 2017-11-23 22:45:05 UTC (rev 7866)
@@ -29,7 +29,6 @@
unset($Days);
unset($_POST['Amount']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
}
if (isset($_POST['Process'])) {
@@ -117,8 +116,7 @@
amount,
authorized,
posted,
- notes,
- receipt)
+ notes)
VALUES (NULL,
'" . $_POST['SelectedTabs'] . "',
'" . FormatDateForSQL($_POST['Date']) . "',
@@ -127,9 +125,8 @@
'0000-00-00',
'0',
'" . $_POST['Notes'] . "',
- '" . $_POST['Receipt'] . "'
- ),
- (NULL,
+ ),
+ (NULL,
'" . $SelectedTabsTo . "',
'" . FormatDateForSQL($_POST['Date']) . "',
'ASSIGNCASH',
@@ -137,7 +134,7 @@
'0000-00-00',
'0',
'" . $_POST['Notes'] . "',
- '" . $_POST['Receipt'] . "')";
+ )";
$msg = _('Assignment of cash from PC Tab ') . ' ' . $SelectedTabs . ' ' . _('to ') . $SelectedTabsTo . ' ' . _('has been created');
}
@@ -148,7 +145,6 @@
unset($_POST['SelectedExpense']);
unset($_POST['Amount']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
unset($_POST['SelectedTabs']);
unset($_POST['Date']);
}
@@ -235,7 +231,6 @@
unset($_POST['Amount']);
unset($_POST['Date']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
}
if(!isset ($Days)){
@@ -259,8 +254,7 @@
amount,
authorized,
posted,
- notes,
- receipt
+ notes
FROM pcashdetails
WHERE tabcode='" . $SelectedTabs . "'
AND date >= DATE_SUB(CURDATE(), INTERVAL " . $Days . " DAY)
@@ -269,22 +263,28 @@
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">
<div>
- <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
- <table class="selection">
+ <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+
+ //Limit expenses history to X days
+ echo '<table class="selection">
<tr>
- <th colspan="8">' . _('Detail of Tab Movements For Last') .':
+ <td>' . _('Detail of Tab Movements For Last') .':
<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />
<input type="text" class="number" name="Days" value="' . $Days . '" maxlength="3" size="4" /> ' . _('Days') . '
- <input type="submit" name="Go" value="' . _('Go') . '" /></th>
+ <input type="submit" name="Go" value="' . _('Go') . '" />
+ </td>
</tr>
- <tr>
- <th>' . _('Date') . '</th>
- <th>' . _('Expense Code') . '</th>
- <th>' . _('Amount') . '</th>
- <th>' . _('Notes') . '</th>
- <th>' . _('Receipt') . '</th>
- <th>' . _('Date Authorised') . '</th>
- </tr>';
+ </table>';
+
+ echo '<table class="selection">
+ <tr>
+ <th>' . _('Date') . '</th>
+ <th>' . _('Expense Code') . '</th>
+ <th>' . _('Amount') . '</th>
+ <th>' . _('Notes') . '</th>
+ <th>' . _('Receipt Attachment') . '</th>
+ <th>' . _('Date Authorised') . '</th>
+ </tr>';
$k = 0; //row colour counter
@@ -309,6 +309,18 @@
$ExpenseCodeDes = $MyRow['codeexpense'] . ' - ' . $Description[0];
}
+ //Generate download link for expense receipt, or show text if no receipt file is found.
+ $ReceiptSupportedExt = array('png','jpg','jpeg','pdf','doc','docx','xls','xlsx'); //Supported file extensions
+ $ReceiptFileDir = $PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/expenses_receipts/' . mb_strtolower($SelectedTabs); //Receipts upload directory
+ $ReceiptFilePathMatched = reset(glob($ReceiptFileDir . '/' . $MyRow['counterindex'] . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE)); //Find the relevant receipt file for the expense. There should only be one (file type), but limit to one result just in case.
+ if (!empty($ReceiptFilePathMatched)) { //If no receipt file for the expenses is found
+ $ReceiptText = '<a href="' . $ReceiptFilePathMatched . '" download="ExpenseReceipt-' . mb_strtolower($SelectedTabs) . '-[' . $MyRow['date'] . ']-[' . $MyRow['counterindex'] . ']">' . _('Download attachment') . '</a>';
+ } elseif ($ExpenseCodeDes == 'ASSIGNCASH') {
+ $ReceiptText = '';
+ } else {
+ $ReceiptText = _('No attachment');
+ }
+
if ($MyRow['authorized'] == '0000-00-00') {
$AuthorisedDate = _('Unauthorised');
} else {
@@ -321,7 +333,7 @@
<td>', $ExpenseCodeDes, '</td>
<td class="number">' . locale_number_format($MyRow['amount'],$CurrDecimalPlaces) . '</td>
<td>' . $MyRow['notes'] . '</td>
- <td>' . $MyRow['receipt'] . '</td>
+ <td>' . $ReceiptText . '</td>
<td>' . $AuthorisedDate . '</td>
</tr>';
}else{
@@ -329,7 +341,7 @@
<td>', $ExpenseCodeDes, '</td>
<td class="number">' . locale_number_format($MyRow['amount'],$CurrDecimalPlaces) . '</td>
<td>' . $MyRow['notes'] . '</td>
- <td>' . $MyRow['receipt'] . '</td>
+ <td>' . $ReceiptText . '</td>
<td>' . $AuthorisedDate . '</td>
</tr>';
}
@@ -416,16 +428,8 @@
<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>
- </table>
- <input type="hidden" name="CurrentAmount" value="' . $SelectedTab['0']. '" />
+ echo '</table>'; // close main table
+ echo '<input type="hidden" name="CurrentAmount" value="' . $SelectedTab['0']. '" />
<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />
<input type="hidden" name="Days" value="' . $Days . '" />
<input type="hidden" name="SelectedTabsTo" value="' . $SelectedTabsTo[1] . '" />
Modified: trunk/PcAssignCashToTab.php
===================================================================
--- trunk/PcAssignCashToTab.php 2017-11-07 01:57:00 UTC (rev 7865)
+++ trunk/PcAssignCashToTab.php 2017-11-23 22:45:05 UTC (rev 7866)
@@ -28,7 +28,6 @@
unset($Days);
unset($_POST['Amount']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
}
if (isset($_POST['Process'])) {
if ($SelectedTabs == '') {
@@ -80,7 +79,6 @@
amount = '" . filter_number_format($_POST['Amount']) . "',
authorized = '0000-00-00',
notes = '" . $_POST['Notes'] . "',
- receipt = '" . $_POST['Receipt'] . "'
WHERE counterindex = '" . $SelectedIndex . "'";
$Msg = _('Assignment of cash to PC Tab ') . ' ' . $SelectedTabs . ' ' . _('has been updated');
} elseif ($InputError != 1) {
@@ -93,8 +91,7 @@
amount,
authorized,
posted,
- notes,
- receipt)
+ notes)
VALUES (NULL,
'" . $_POST['SelectedTabs'] . "',
'" . FormatDateForSQL($_POST['Date']) . "',
@@ -103,7 +100,6 @@
'0000-00-00',
'0',
'" . $_POST['Notes'] . "',
- '" . $_POST['Receipt'] . "'
)";
$Msg = _('Assignment of cash to PC Tab ') . ' ' . $_POST['SelectedTabs'] . ' ' . _('has been created');
}
@@ -114,7 +110,6 @@
unset($_POST['SelectedExpense']);
unset($_POST['Amount']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
unset($_POST['SelectedTabs']);
unset($_POST['Date']);
}
@@ -188,7 +183,6 @@
unset($_POST['Amount']);
unset($_POST['Date']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
}
if (!isset($Days)) {
$Days = 30;
@@ -209,8 +203,7 @@
amount,
authorized,
posted,
- notes,
- receipt
+ notes
FROM pcashdetails
WHERE tabcode='" . $SelectedTabs . "'
AND date >=DATE_SUB(CURDATE(), INTERVAL " . $Days . " DAY)
@@ -219,20 +212,25 @@
$Result = DB_query($SQL);
echo '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
+
+ //Limit expenses history to X days
echo '<table class="selection">
<tr>
- <th colspan="8">', _('Detail of Tab Movements For Last'), ':
+ <td>', _('Detail of Tab Movements For Last'), ':
<input type="hidden" name="SelectedTabs" value="', $SelectedTabs, '" />
<input type="text" class="number" name="Days" value="', $Days, '" required="required" maxlength="3" size="4" />' . _('Days') . '
<input type="submit" name="Go" value="' . _('Go') . '" /></th>
- </th>
+ </td>
</tr>
+ </table>';
+
+ echo '<table class="selection">
<tr>
<th>', _('Date'), '</th>
<th>', _('Expense Code'), '</th>
<th>', _('Amount'), '</th>
<th>', _('Notes'), '</th>
- <th>', _('Receipt'), '</th>
+ <th>', _('Receipt Attachment'), '</th>
<th>', _('Date Authorised'), '</th>
</tr>';
$k = 0; //row colour counter
@@ -262,6 +260,18 @@
$AuthorisedDate = ConvertSQLDate($MyRow['authorized']);
}
+ //Generate download link for expense receipt, or show text if no receipt file is found.
+ $ReceiptSupportedExt = array('png','jpg','jpeg','pdf','doc','docx','xls','xlsx'); //Supported file extensions
+ $ReceiptFileDir = $PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/expenses_receipts/' . mb_strtolower($SelectedTabs); //Receipts upload directory
+ $ReceiptFilePathMatched = reset(glob($ReceiptFileDir . '/' . $MyRow['counterindex'] . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE)); //Find the relevant receipt file for the expense. There should only be one (file type), but limit to one result just in case.
+ if (!empty($ReceiptFilePathMatched)) { //If no receipt file for the expenses is found
+ $ReceiptText = '<a href="' . $ReceiptFilePathMatched . '" download="ExpenseReceipt-' . mb_strtolower($SelectedTabs) . '-[' . $MyRow['date'] . ']-[' . $MyRow['counterindex'] . ']">' . _('Download attachment') . '</a>';
+ } elseif ($ExpenseCodeDes == 'ASSIGNCASH') {
+ $ReceiptText = '';
+ } else {
+ $ReceiptText = _('No attachment');
+ }
+
if (($MyRow['authorized'] == '0000-00-00') and ($ExpenseCodeDes == 'ASSIGNCASH')) {
// only cash assignations NOT authorized can be modified or deleted
echo '<td>', ConvertSQLDate($MyRow['date']), '</td>
@@ -268,7 +278,7 @@
<td>', $ExpenseCodeDes, '</td>
<td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td>
<td>', $MyRow['notes'], '</td>
- <td>', $MyRow['receipt'], '</td>
+ <td>', $ReceiptText, '</td>
<td>', $AuthorisedDate, '</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 assigned cash?') . '");\'>' . _('Delete') . '</a></td>
@@ -278,7 +288,7 @@
<td>', $ExpenseCodeDes, '</td>
<td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td>
<td>', $MyRow['notes'], '</td>
- <td>', $MyRow['receipt'], '</td>
+ <td>', $ReceiptText, '</td>
<td>', $AuthorisedDate, '</td>
</tr>';
}
@@ -323,9 +333,8 @@
authorized,
posted,
notes,
- receipt
- FROM pcashdetails
- WHERE counterindex='" . $SelectedIndex . "'";
+ FROM pcashdetails
+ WHERE counterindex='" . $SelectedIndex . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$_POST['Date'] = ConvertSQLDate($MyRow['date']);
@@ -332,7 +341,6 @@
$_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], '" />';
@@ -372,13 +380,6 @@
<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="CurrentAmount" value="', $Amount['0'], '" />';
echo '<input type="hidden" name="SelectedTabs" value="', $SelectedTabs, '" />';
Modified: trunk/PcAuthorizeCash.php
===================================================================
--- trunk/PcAuthorizeCash.php 2017-11-07 01:57:00 UTC (rev 7865)
+++ trunk/PcAuthorizeCash.php 2017-11-23 22:45:05 UTC (rev 7866)
@@ -55,14 +55,17 @@
if (!isset($Days)) {
$Days = 30;
}
- echo '<input type="hidden" name="SelectedTabs" value="', $SelectedTabs, '" />';
+
+ //Limit expenses history to X days
echo '<table class="selection">
<tr>
- <th colspan="6">', _('Detail of Tab Movements For Last '), ':
+ <td>', _('Detail of Tab Movements For Last '), ':
+ <input type="hidden" name="SelectedTabs" value="', $SelectedTabs, '" />
<input type="text" class="number" name="Days" value="', $Days, '" maxlength="3" size="4" />', _('Days'), '
<input type="submit" name="Go" value="', _('Go'), '" />
- </th>
- </tr>';
+ </td>
+ </tr>
+ </table>';
$SQL = "SELECT pcashdetails.counterindex,
pcashdetails.tabcode,
pcashdetails.date,
@@ -71,7 +74,6 @@
pcashdetails.authorized,
pcashdetails.posted,
pcashdetails.notes,
- pcashdetails.receipt,
pctabs.glaccountassignment,
pctabs.glaccountpcash,
pctabs.usercode,
@@ -86,14 +88,14 @@
AND pcashdetails.codeexpense='ASSIGNCASH'
ORDER BY pcashdetails.date, pcashdetails.counterindex ASC";
$Result = DB_query($SQL);
- echo '<tr>
- <th>', _('Date'), '</th>
- <th>', _('Expense Code'), '</th>
- <th>', _('Amount'), '</th>
- <th>', _('Notes'), '</th>
- <th>', _('Receipt'), '</th>
- <th>', _('Date Authorised'), '</th>
- </tr>';
+ echo '<table class="selection">
+ <tr>
+ <th>', _('Date'), '</th>
+ <th>', _('Expense Code'), '</th>
+ <th>', _('Amount'), '</th>
+ <th>', _('Notes'), '</th>
+ <th>', _('Date Authorised'), '</th>
+ </tr>';
$k = 0; //row colour counter
$CurrDecimalPlaces = 2;
while ($MyRow = DB_fetch_array($Result)) {
@@ -127,7 +129,7 @@
//get typeno
$typeno = GetNextTransNo($type,$db);
//build narrative
- $Narrative = _('PettyCash') . ' - ' . $MyRow['tabcode'] . ' - ' . $MyRow['codeexpense'] . ' - ' . DB_escape_string($MyRow['notes']) . ' - ' . $MyRow['receipt'];
+ $Narrative = _('PettyCash') . ' - ' . $MyRow['tabcode'] . ' - ' . $MyRow['codeexpense'] . ' - ' . DB_escape_string($MyRow['notes']);
//insert to gltrans
DB_Txn_Begin();
$SQLFrom = "INSERT INTO `gltrans` (`counterindex`,
@@ -229,19 +231,10 @@
$k = 1;
}
- /*
- if ($MyRow['posted'] == 0) {
- $Posted = _('No');
- } else {
- $Posted = _('Yes');
- }
- */
-
echo '<td>', ConvertSQLDate($MyRow['date']), '</td>
<td>', $MyRow['codeexpense'], '</td>
<td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td>
- <td>', $MyRow['notes'], '</td>
- <td>', $MyRow['receipt'], '</td>';
+ <td>', $MyRow['notes'], '</td>';
if (isset($_POST[$MyRow['counterindex']])) {
echo '<td>' . ConvertSQLDate(Date('Y-m-d'));
} else {
Modified: trunk/PcAuthorizeExpenses.php
===================================================================
--- trunk/PcAuthorizeExpenses.php 2017-11-07 01:57:00 UTC (rev 7865)
+++ trunk/PcAuthorizeExpenses.php 2017-11-23 22:45:05 UTC (rev 7866)
@@ -55,14 +55,17 @@
if (!isset($Days)) {
$Days = 30;
}
- echo '<input type="hidden" name="SelectedTabs" value="', $SelectedTabs, '" />';
+
+ //Limit expenses history to X days
echo '<table class="selection">
<tr>
- <th colspan="9">', _('Detail of Tab Movements For Last '), ':
+ <td>', _('Detail of Tab Movements For Last '), ':
+ <input type="hidden" name="SelectedTabs" value="', $SelectedTabs, '" />
<input type="text" class="number" name="Days" value="', $Days, '" maxlength="3" size="4" />', _('Days'), '
<input type="submit" name="Go" value="', _('Go'), '" />
- </th>
- </tr>';
+ </td>
+ </tr>
+ </table>';
$SQL = "SELECT pcashdetails.counterindex,
pcashdetails.tabcode,
pcashdetails.tag,
@@ -72,7 +75,6 @@
pcashdetails.authorized,
pcashdetails.posted,
pcashdetails.notes,
- pcashdetails.receipt,
pctabs.glaccountassignment,
pctabs.glaccountpcash,
pctabs.usercode,
@@ -87,17 +89,18 @@
AND pcashdetails.codeexpense<>'ASSIGNCASH'
ORDER BY pcashdetails.date, pcashdetails.counterindex ASC";
$Result = DB_query($SQL);
- echo '<tr>
- <th>', _('Date of Expense'), '</th>
- <th>', _('Expense Code'), '</th>
- <th>', _('Gross Amount'), '</th>
- <th>', _('Tax'), '</th>
- <th>', _('Tax Group'), '</th>
- <th>', _('Tag'), '</th>
- <th>', _('Notes'), '</th>
- <th>', _('Receipt'), '</th>
- <th>', _('Date Authorised'), '</th>
- </tr>';
+ echo '<table class="selection">
+ <tr>
+ <th>', _('Date of Expense'), '</th>
+ <th>', _('Expense Code'), '</th>
+ <th>', _('Gross Amount'), '</th>
+ <th>', _('Tax'), '</th>
+ <th>', _('Tax Group'), '</th>
+ <th>', _('Tag'), '</th>
+ <th>', _('Notes'), '</th>
+ <th>', _('Receipt Attachment'), '</th>
+ <th>', _('Date Authorised'), '</th>
+ </tr>';
$k = 0; //row colour counter
while ($MyRow = DB_fetch_array($Result)) {
$CurrDecimalPlaces = $MyRow['decimalplaces'];
@@ -120,13 +123,13 @@
$NetAmount = ($MyRow['amount'] - $TaxTotalRow['totaltax']) / $MyRow['rate'];
}
if ($MyRow['codeexpense'] == 'ASSIGNCASH') {
- $type = 2;
+ $Type = 2;
$AccountFrom = $MyRow['glaccountassignment'];
$AccountTo = $MyRow['glaccountpcash'];
$TagTo = 0;
$TagDescription = '0 - ' . _('None');
} else {
- $type = 1;
+ $Type = 1;
$NetAmount = -$NetAmount;
$AccountFrom = $MyRow['glaccountpcash'];
$SQLAccExp = "SELECT glaccount,
@@ -141,9 +144,9 @@
}
if (isset($_POST['Submit']) and $_POST['Submit'] == _('Update') and isset($_POST[$MyRow['counterindex']])) {
//get typeno
- $typeno = GetNextTransNo($type,$db);
+ $TypeNo = GetNextTransNo($Type,$db);
//build narrative
- $Narrative = _('PettyCash') . ' - ' . $MyRow['tabcode'] . ' - ' . $MyRow['codeexpense'] . ' - ' . DB_escape_string($MyRow['notes']) . ' - ' . $MyRow['receipt'];
+ $Narrative = _('PettyCash') . ' - ' . $MyRow['tabcode'] . ' - ' . $MyRow['codeexpense'] . ' - ' . DB_escape_string($MyRow['notes']);
//insert to gltrans
DB_Txn_Begin();
$SQLFrom = "INSERT INTO `gltrans` (`counterindex`,
@@ -159,8 +162,8 @@
`jobref`,
`tag`)
VALUES (NULL,
- '" . $type . "',
- '" . $typeno . "',
+ '" . $Type . "',
+ '" . $TypeNo . "',
0,
'" . $MyRow['date'] . "',
'" . $PeriodNo . "',
@@ -184,8 +187,8 @@
`jobref`,
`tag`)
VALUES (NULL,
- '" . $type . "',
- '" . $typeno . "',
+ '" . $Type . "',
+ '" . $TypeNo . "',
0,
'" . $MyRow['date'] . "',
'" . $PeriodNo . "',
@@ -222,8 +225,8 @@
`jobref`,
`tag`)
VALUES (NULL,
- '" . $type . "',
- '" . $typeno . "',
+ '" . $Type . "',
+ '" . $TypeNo . "',
0,
'" . $MyRow['date'] . "',
'" . $PeriodNo . "',
@@ -283,14 +286,6 @@
$k = 1;
}
- /*
- if ($MyRow['posted'] == 0) {
- $Posted = _('No');
- } else {
- $Posted = _('Yes');
- }
- */
-
$SQLDes = "SELECT description
FROM pcexpenses
WHERE codeexpense='" . $MyRow['codeexpense'] . "'";
@@ -320,7 +315,19 @@
$TaxesDescription .= $MyTaxRow['description'] . '<br />';
$TaxesTaxAmount .= locale_number_format($MyTaxRow['amount'], $CurrDecimalPlaces) . '<br />';
}
-
+
+ //Generate download link for expense receipt, or show text if no receipt file is found.
+ $ReceiptSupportedExt = array('png','jpg','jpeg','pdf','doc','docx','xls','xlsx'); //Supported file extensions
+ $ReceiptFileDir = $PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/expenses_receipts/' . mb_strtolower($SelectedTabs); //Receipts upload directory
+ $ReceiptFilePathMatched = reset(glob($ReceiptFileDir . '/' . $MyRow['counterindex'] . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE)); //Find the relevant receipt file for the expense. There should only be one (file type), but limit to one result just in case.
+ if (!empty($ReceiptFilePathMatched)) { //If no receipt file for the expenses is found
+ $ReceiptText = '<a href="' . $ReceiptFilePathMatched . '" download="ExpenseReceipt-' . mb_strtolower($SelectedTabs) . '-[' . $MyRow['date'] . ']-[' . $MyRow['counterindex'] . ']">' . _('Download attachment') . '</a>';
+ } elseif ($ExpenseCodeDes == 'ASSIGNCASH') {
+ $ReceiptText = '';
+ } else {
+ $ReceiptText = _('No attachment');
+ }
+
echo '<td>', ConvertSQLDate($MyRow['date']), '</td>
<td>', $ExpenseCodeDes, '</td>
<td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td>
@@ -328,7 +335,7 @@
<td>', $TaxesDescription, '</td>
<td>', $TagDescription, '</td>
<td>', $MyRow['notes'], '</td>
- <td>', $MyRow['receipt'], '</td>';
+ <td>', $ReceiptText, '</td>';
if (isset($_POST[$MyRow['counterindex']])) {
echo '<td>' . ConvertSQLDate(Date('Y-m-d'));
} else {
Modified: trunk/PcClaimExpensesFromTab.php
===================================================================
--- trunk/PcClaimExpensesFromTab.php 2017-11-07 01:57:00 UTC (rev 7865)
+++ trunk/PcClaimExpensesFromTab.php 2017-11-23 22:45:05 UTC (rev 7866)
@@ -28,7 +28,7 @@
unset($Days);
unset($_POST['Amount']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
+ unset($_FILES['Receipt']);
}
if (isset($_POST['Process'])) {
if ($_POST['SelectedTabs'] == '') {
@@ -42,6 +42,9 @@
$Days = 30;
}
}
+//Define receipt attachment upload functions and variables which are used in various places within script
+$ReceiptSupportedExt = array('png','jpg','jpeg','pdf','doc','docx','xls','xlsx'); //Supported file extensions
+$ReceiptFileDir = $PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/expenses_receipts/' . mb_strtolower($SelectedTabs); //Receipts upload directory
if (isset($_POST['submit'])) {
//initialise no input errors assumed initially before we test
$InputError = 0;
@@ -59,14 +62,13 @@
$InputError = 1;
prnMsg(_('The date input is not in the correct format'), 'error');
}
- if (isset($SelectedIndex) and $InputError != 1) {
+ if (isset($SelectedIndex) and $InputError != 1) { //Edit
$SQL = "UPDATE pcashdetails
SET date = '" . FormatDateForSQL($_POST['Date']) . "',
tag = '" . $_POST['Tag'] . "',
codeexpense = '" . $_POST['SelectedExpense'] . "',
amount = '" . -filter_number_format($_POST['Amount']) . "',
- notes = '" . $_POST['Notes'] . "',
- receipt = '" . $_POST['Receipt'] . "'
+ notes = '" . $_POST['Notes'] . "'
WHERE counterindex = '" . $SelectedIndex . "'";
$Msg = _('The expense claim on tab') . ' ' . $SelectedTabs . ' ' . _('has been updated');
$Result = DB_query($SQL);
@@ -85,6 +87,59 @@
$Result = DB_query($SQL);
}
}
+ if (isset($_FILES['Receipt']) and $_FILES['Receipt']['name'] != '') {
+ $UploadOriginalName = $_FILES['Receipt']['name'];
+ $UploadTempName = $_FILES['Receipt']['tmp_name'];
+ $UploadSize = $_FILES['Receipt']['size'];
+ $UploadType = $_FILES['Receipt']['type'];
+ $UploadError = $_FILES['Receipt']['error'];
+ $UploadTheFile = 'Yes'; //Assume all is well to start off with, but check for the worst
+ $ReceiptSupportedMime = array('image/png','image/jpeg','application/pdf','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //list of support mime types, corresponding to the list of support file extensions in $ReceiptSupportedExt
+ if ($UploadSize > ($_SESSION['MaxImageSize'] * 1024)) { //Server-side file size check. This will usually be caught by $UploadError == 2 (MAX_FILE_SIZE), but we must not trust the user.
+ prnMsg(_('The uploaded file exceeds the maximum file size of') . ' ' . $_SESSION['MaxImageSize'] . 'KB', 'warn');
+ $UploadTheFile = 'No';
+ } elseif (!in_array($UploadType, $ReceiptSupportedMime) and $UploadError != 2) { //File type check. If $UploadError == 2, then $UploadType will be empty.
+ prnMsg(_('File type not accepted. Only the following file types can be attached') . ': ' . implode(', ', $ReceiptSupportedExt), 'warn');
+ $UploadTheFile = 'No';
+ } elseif ($UploadError == 1 ) { //upload_max_filesize error check
+ prnMsg(_('The uploaded file exceeds the upload_max_filesize directive in php.ini. Please contact your system administrator.'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 2 ) { //Client-side file size error check (MAX_FILE_SIZE)
+ prnMsg(_('The uploaded file exceeds the maximum file size of') . ' ' . $_SESSION['MaxImageSize'] . 'KB', 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 3 ) { //Partial upload error check
+ prnMsg( _('The uploaded file was only partially uploaded. Please try again.'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 4 ) { //No file uploaded error check
+ prnMsg( _('No file was uploaded'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 5 ) { //Undefined error check
+ prnMsg( _('Undefined error'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 6 ) { //Temp directory error check
+ prnMsg( _('A necessary temporary folder is missing. Please contact your system administrator.'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 7 ) { //Disk write failure error check
+ prnMsg( _('Cannot write file to disk. Please contact your system administrator.'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 8 ) { //Upload stopped by PHP extension error check
+ prnMsg( _('The file upload was stopped by a PHP extension. Please contact your system administrator.'), 'warn');
+ $UploadTheFile ='No';
+ }
+ if ($UploadTheFile == 'Yes') { //Passed all the above validation
+ if (!file_exists($ReceiptFileDir)) { //Create the receipts directory if it doesn't already exist
+ mkdir($ReceiptFileDir, 0775, true);
+ }
+ $ReceiptFileExt = pathinfo($UploadOriginalName, PATHINFO_EXTENSION); //Grab the file extension of the uploaded file
+ $ReceiptFileName = $SelectedIndex . '.' . $ReceiptFileExt; //Rename the uploaded file with the expenses index number
+ $ReceiptFilePath = $ReceiptFileDir . '/' . $ReceiptFileName;
+ $ReceiptExistingFiles = glob($ReceiptFileDir . '/' . $SelectedIndex . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE); //Find all existing receipt files for the expense, in case more than 1 file type is currently in the receipts directory
+ foreach($ReceiptExistingFiles as $ReceiptExistingFile) { // Overwrite existing files, and delete all other file types.
+ unlink($ReceiptExistingFile);
+ };
+ move_uploaded_file($UploadTempName, $ReceiptFilePath); //Move the uploaded file from the temp directory to the receipts directory.
+ }
+ }
prnMsg($Msg, 'success');
} elseif ($InputError != 1) {
// First check the type is not being duplicated
@@ -97,8 +152,7 @@
amount,
authorized,
posted,
- notes,
- receipt)
+ notes)
VALUES (NULL,
'" . $_POST['SelectedTabs'] . "',
'" . $_POST['Tag'] . "',
@@ -107,12 +161,11 @@
'" . -filter_number_format($_POST['Amount']) . "',
0,
0,
- '" . $_POST['Notes'] . "',
- '" . $_POST['Receipt'] . "'
+ '" . $_POST['Notes'] . "'
)";
$Msg = _('The expense claim on tab') . ' ' . $_POST['SelectedTabs'] . ' ' . _('has been created');
$Result = DB_query($SQL);
- $PcCashDetail = DB_Last_Insert_ID($db, 'pcashdetails', 'counterindex');
+ $SelectedIndex = DB_Last_Insert_ID($db, 'pcashdetails', 'counterindex');
foreach ($_POST as $Index => $Value) {
if (substr($Index, 0, 5) == 'index') {
$Index = $Value;
@@ -127,7 +180,7 @@
amount
) VALUES (
NULL,
- '" . $PcCashDetail . "',
+ '" . $SelectedIndex . "',
'" . $_POST['CalculationOrder' . $Index] . "',
'" . $_POST['Description' . $Index] . "',
'" . $_POST['TaxAuthority' . $Index] . "',
@@ -139,6 +192,59 @@
$Result = DB_query($SQL);
}
}
+ if (isset($_FILES['Receipt']) and $_FILES['Receipt']['name'] != '') {
+ $UploadOriginalName = $_FILES['Receipt']['name'];
+ $UploadTempName = $_FILES['Receipt']['tmp_name'];
+ $UploadSize = $_FILES['Receipt']['size'];
+ $UploadType = $_FILES['Receipt']['type'];
+ $UploadError = $_FILES['Receipt']['error'];
+ $UploadTheFile = 'Yes'; //Assume all is well to start off with, but check for the worst
+ $ReceiptSupportedMime = array('image/png','image/jpeg','application/pdf','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //list of support mime types, corresponding to the list of support file extensions in $ReceiptSupportedExt
+ if ($UploadSize > ($_SESSION['MaxImageSize'] * 1024)) { //Server-side file size check. This will usually be caught by $UploadError == 2 (MAX_FILE_SIZE), but we must not trust the user.
+ prnMsg(_('The uploaded file exceeds the maximum file size of') . ' ' . $_SESSION['MaxImageSize'] . 'KB', 'warn');
+ $UploadTheFile = 'No';
+ } elseif (!in_array($UploadType, $ReceiptSupportedMime) and $UploadError != 2) { //File type check. If $UploadError == 2, then $UploadType will be empty.
+ prnMsg(_('File type not accepted. Only the following file types can be attached') . ': ' . implode(', ', $ReceiptSupportedExt), 'warn');
+ $UploadTheFile = 'No';
+ } elseif ($UploadError == 1 ) { //upload_max_filesize error check
+ prnMsg(_('The uploaded file exceeds the upload_max_filesize directive in php.ini. Please contact your system administrator.'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 2 ) { //Client-side file size error check (MAX_FILE_SIZE)
+ prnMsg(_('The uploaded file exceeds the maximum file size of') . ' ' . $_SESSION['MaxImageSize'] . 'KB', 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 3 ) { //Partial upload error check
+ prnMsg( _('The uploaded file was only partially uploaded. Please try again.'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 4 ) { //No file uploaded error check
+ prnMsg( _('No file was uploaded'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 5 ) { //Undefined error check
+ prnMsg( _('Undefined error'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 6 ) { //Temp directory error check
+ prnMsg( _('A necessary temporary folder is missing. Please contact your system administrator.'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 7 ) { //Disk write failure error check
+ prnMsg( _('Cannot write file to disk. Please contact your system administrator.'), 'warn');
+ $UploadTheFile ='No';
+ } elseif ($UploadError == 8 ) { //Upload stopped by PHP extension error check
+ prnMsg( _('The file upload was stopped by a PHP extension. Please contact your system administrator.'), 'warn');
+ $UploadTheFile ='No';
+ }
+ if ($UploadTheFile == 'Yes') { //Passed all the above validation
+ if (!file_exists($ReceiptFileDir)) { //Create the receipts directory if it doesn't already exist
+ mkdir($ReceiptFileDir, 0775, true);
+ }
+ $ReceiptFileExt = pathinfo($UploadOriginalName, PATHINFO_EXTENSION); //Grab the file extension of the uploaded file
+ $ReceiptFileName = $SelectedIndex . '.' . $ReceiptFileExt; //Rename the uploaded file with the expenses index number
+ $ReceiptFilePath = $ReceiptFileDir . '/' . $ReceiptFileName;
+ $ReceiptExistingFiles = glob($ReceiptFileDir . '/' . $SelectedIndex . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE); //Find all existing receipt files for the expense, in case more than 1 file type is currently in the receipts directory
+ foreach($ReceiptExistingFiles as $ReceiptExistingFile) { // Overwrite existing files, and delete all other file types.
+ unlink($ReceiptExistingFile);
+ };
+ move_uploaded_file($UploadTempName, $ReceiptFilePath); //Move the uploaded file from the temp directory to the receipts directory.
+ }
+ }
prnMsg($Msg, 'success');
}
if ($InputError != 1) {
@@ -147,9 +253,9 @@
unset($_POST['Tag']);
unset($_POST['Date']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
+ unset($_FILES['Receipt']);
}
-} elseif (isset($_GET['Delete'])) {
+} elseif (isset($_GET['delete'])) {
$SQL = "DELETE FROM pcashdetails, pcashdetailtaxes
USING pcashdetails
INNER JOIN pcashdetailtaxes
@@ -158,7 +264,12 @@
$ErrMsg = _('Petty Cash Expense record could not be deleted because');
$Result = DB_query($SQL, $ErrMsg);
prnMsg(_('Petty Cash expense record') . ' ' . $SelectedTabs . ' ' . _('has been deleted'), 'success');
- unset($_GET['Delete']);
+ //Delete receipt attachments. There should be only one per expenses, but check for all possible file extensions anyway.
+ $ReceiptExistingFiles = glob($ReceiptFileDir . '/' . $SelectedIndex . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE); //Find all existing receipt files for the expense, in case more than 1 file type is currently in the receipts directory
+ foreach($ReceiptExistingFiles as $ReceiptExistingFile) {
+ unlink($ReceiptExistingFile);
+ };
+ 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
@@ -168,7 +279,7 @@
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['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 '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" enctype="multipart/form-data">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
echo '<table class="selection">
<tr>
@@ -214,7 +325,7 @@
$Result = DB_query($SQLDecimalPlaces);
$MyRow = DB_fetch_array($Result);
$CurrDecimalPlaces = $MyRow['decimalplaces'];
- echo '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '">';
+ echo '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" enctype="multipart/form-data">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
echo '<br /><table class="selection">';
echo '<tr>
@@ -222,20 +333,23 @@
<td>' . $SelectedTabs . '</td>
</tr>';
echo '</table>';
+
+ //Limit expenses history to X days
echo '<table class="selection">
<tr>
- <th colspan="9">', _('Detail of Tab Movements For Last '), ':
+ <td>', _('Detail of Tab Movements For Last '), ':
<input type="hidden" name="SelectedTabs" value="' . $SelectedTabs . '" />
<input type="text" class="number" name="Days" value="', $Days, '" required="required" maxlength="3" size="4" /> ', _('Days'), '
<input type="submit" name="Go" value="', _('Go'), '" />
- </th>
- </tr>';
+ </td>
+ </tr>
+ </table>';
if (isset($_POST['Cancel'])) {
unset($_POST['SelectedExpense']);
unset($_POST['Amount']);
unset($_POST['Date']);
unset($_POST['Notes']);
- unset($_POST['Receipt']);
+ unset($_FILES['Receipt']);
}
$SQL = "SELECT counterindex,
tabcode,
@@ -245,8 +359,7 @@
amount,
authorized,
posted,
- notes,
- receipt
+ notes
FROM pcashdetails
WHERE tabcode='" . $SelectedTabs . "'
AND date >=DATE_SUB(CURDATE(), INTERVAL " . $Days . " DAY)
@@ -253,17 +366,18 @@
ORDER BY date,
counterindex ASC";
$Result = DB_query($SQL);
- echo '<tr>
- <th>', _('Date of Expense'), '</th>
- <th>', _('Expense Code'), '</th>
- <th>', _('Gross Amount'), '</th>
- <th>', _('Tax'), '</th>
- <th>', _('Tax Group'), '</th>
- <th>', _('Tag'), '</th>
- <th>', _('Notes'), '</th>
- <th>', _('Receipt'), '</th>
- <th>', _('Date Authorised'), '</th>
- </tr>';
+ echo '<table class="selection">
+ <tr>
+ <th>', _('Date of Expense'), '</th>
+ <th>', _('Expense Code'), '</th>
+ <th>', _('Gross Amount'), '</th>
+ <th>', _('Tax'), '</th>
+ <th>', _('Tax Group'), '</th>
+ <th>', _('Tag'), '</th>
+ <th>', _('Notes'), '</th>
+ <th>', _('Receipt Attachment'), '</th>
+ <th>', _('Date Authorised'), '</th>
+ </tr>';
$k = 0; //row colour counter
while ($MyRow = DB_fetch_array($Result)) {
if ($k == 1) {
@@ -291,6 +405,16 @@
$AuthorisedDate = ConvertSQLDate($MyRow['authorized']);
}
+ //Generate download link for expense receipt, or show text if no receipt file is found.
+ $ReceiptFilePathMatched = reset(glob($ReceiptFileDir . '/' . $MyRow['counterindex'] . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE)); //Find the relevant receipt file for the expense. There should only be one (file type), but limit to one result just in case.
+ if (!empty($ReceiptFilePathMatched)) { //If no receipt file for the expenses is found
+ $ReceiptText = '<a href="' . $ReceiptFilePathMatched . '" download="ExpenseReceipt-' . mb_strtolower($SelectedTabs) . '-[' . $MyRow['date'] . ']-[' . $MyRow['counterindex'] . ']">' . _('Download attachment') . '</a>';
+ } elseif ($ExpenseCodeDes == 'ASSIGNCASH') {
+ $ReceiptText = '';
+ } else {
+ $ReceiptText = _('No attachment');
+ }
+
$TagSQL = "SELECT tagdescription FROM tags WHERE tagref='" . $MyRow['tag'] . "'";
$TagResult = DB_query($TagSQL);
$TagRow = DB_fetch_array($TagResult);
@@ -298,8 +422,12 @@
$TagRow['tagdescription'] = _('None');
}
$TagTo = $MyRow['tag'];
- $TagDescription = $TagTo . ' - ' . $TagRow['tagdescription'];
-
+ if ($ExpenseCodeDes == 'ASSIGNCASH') {
+ $TagDescription = '';
+ } else {
+ $TagDescription = $TagTo . ' - ' . $TagRow['tagdescription'];
+ }
+
$TaxesDescription = '';
$TaxesTaxAmount = '';
$TaxSQL = "SELECT counterindex,
@@ -318,32 +446,32 @@
$TaxesDescription .= $MyTaxRow['description'] . '<br />';
$TaxesTaxAmount .= locale_number_format($MyTaxRow['amount'], $CurrDecimalPlaces) . '<br />';
}
- if (($MyRow['authorized'] == '0000-00-00') and ($ExpenseCodeDes != 'ASSIGNCASH')) {
- // only movements NOT authorised can be modified or deleted
- echo '<td>', ConvertSQLDate($MyRow['date']), '</td>
- <td>', $ExpenseCodeDes, '</td>
- <td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td>
- <td class="number">', $TaxesTaxAmount, '</td>
- <td>', $TaxesDescription, '</td>
- <td>', $TagDescription, '</td>
- <td>', $MyRow['notes'], '</td>
- <td>', $MyRow['receipt'], '</td>
- <td>', $AuthorisedDate, '</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 expense?') . '");\'>' . _('Delete') . '</a></td>
- </tr>';
- } else {
- echo '<td>', ConvertSQLDate($MyRow['date']), '</td>
- <td>', $ExpenseCodeDes, '</td>
- <td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td>
- <td class="number">', $TaxesTaxAmount, '</td>
- <td>', $TaxesDescription, '</td>
- <td>', $MyRow['tag'], ' - ', $TagRow['tagdescription'], '</td>
- <td>', $MyRow['notes'], '</td>
- <td>', $MyRow['receipt'], '</td>
- <td>', $AuthorisedDate, '</td>
- </tr>';
- }
+ if (($MyRow['authorized'] == '0000-00-00') and ($ExpenseCodeDes != 'ASSIGNCASH')) {
+ // only movements NOT authorised can be modified or deleted
+ echo '<td>', ConvertSQLDate($MyRow['date']), '</td>
+ <td>', $ExpenseCodeDes, '</td>
+ <td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td>
+ <td class="number">', $TaxesTaxAmount, '</td>
+ <td>', $TaxesDescription, '</td>
+ <td>', $TagDescription, '</td>
+ <td>', $MyRow['notes'], '</td>
+ <td>', $ReceiptText, '</td>
+ <td>', $AuthorisedDate, '</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 expense?') . '");\'>' . _('Delete') . '</a></td>
+ </tr>';
+ } else {
+ echo '<td>', ConvertSQLDate($MyRow['date']), '</td>
+ <td>', $ExpenseCodeDes, '</td>
+ <td class="number">', locale_number_format($MyRow['amount'], $CurrDecimalPlaces), '</td>
+ <td class="number">', $TaxesTaxAmount, '</td>
+ <td>', $TaxesDescription, '</td>
+ <td>', $TagDescription, '</td>
+ <td>', $MyRow['notes'], '</td>
+ <td>', $ReceiptText, '</td>
+ <td>', $AuthorisedDate, '</td>
+ </tr>';
+ }
}
//END WHILE LIST LOOP
$SQLAmount = "SELECT sum(amount)
@@ -361,8 +489,8 @@
echo '</table>';
echo '</form>';
}
- if (!isset($_GET['Delete'])) {
- echo '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '">';
+ if (!isset($_GET['delete'])) {
+ echo '<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" enctype="multipart/form-data">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
if (isset($_GET['edit'])) {
$SQL = "SELECT counterindex,
@@ -373,10 +501,9 @@
amount,
authorized,
posted,
- notes,
- receipt
- FROM pcashdetails
- WHERE counterindex='" . $SelectedIndex . "'";
+ notes
+ FROM pcashdetails
+ WHERE counterindex='" . $SelectedIndex . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$_POST['Date'] = ConvertSQLDate($MyRow['date']);
@@ -384,7 +511,6 @@
$_POST['Amount'] = -$MyRow['amount'];
$_POST['Notes'] = $MyRow['notes'];
$_POST['Tag'] = $MyRow['tag'];
- $_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, '" />';
@@ -409,7 +535,7 @@
</td>
</tr>
<tr>
- <td>', _('Code of Expense'), ':</td>
+ <td>', _('Expense Code'), ':</td>
<td>
<select required="required" name="SelectedExpense">';
DB_free_result($Result);
@@ -434,30 +560,6 @@
echo '</select>
</td>
</tr>';
- //Select the tag
- echo '<tr>
- <td>', _('Tag'), ':</td>
- <td><select name="Tag">';
- $SQL = "SELECT tagref,
- tagdescription
- FROM tags
- ORDER BY tagref";
- $Result = DB_query($SQL);
- if (!isset($_POST['Tag'])) {
- $_POST['Tag'] = $DefaultTag;
- }
- echo '<option value="0">0 - ', _('None'), '</option>';
- while ($MyRow = DB_fetch_array($Result)) {
- if ($_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>
- </tr>';
- // End select tag
if (!isset($_POST['Amount'])) {
$_POST['Amount'] = 0;
}
@@ -522,12 +624,50 @@
echo '<input type="hidden" name="TaxOnTax', $i, '" value="', $MyTaxRow['taxontax'], '" />';
echo '<input type="hidden" name="TaxRate', $i, '" value="', $MyTaxRow['taxrate'], '" />';
echo '<tr>
- <td>', $MyTaxRow['description'], ' - ', ($MyTaxRow['taxrate'] * 100), '%</td>
+ <td>', $MyTaxRow['description'], ' - ', ($MyTaxRow['taxrate'] * 100), '%:</td>
<td><input type="text" class="number" size="12" name="TaxAmount', $i, '" value="0" /></td>
</tr>';
++$i;
}
}
+
+ //Select the tag
+ echo '<tr>
+ <td>', _('Tag'), ':</td>
+ <td><select name="Tag">';
+ $SQL = "SELECT tagref,
+ tagdescription
+ FROM tags
+ ORDER BY tagref";
+ $Result = DB_query($SQL);
+ if (!isset($_POST['Tag'])) {
+ $_POST['Tag'] = $DefaultTag;
+ }
+ echo '<option value="0">0 - ', _('None'), '</option>';
+ while ($MyRow = DB_fetch_array($Result)) {
+ if ($_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>
+ </tr>';
+ // End select tag
+
+ //For the accept attribute of the file element, prefix dots to the front of each supported file extension.
+ $ReceiptSupportedExtDotPrefix = array_map(function($ReceiptSupportedExt) {
+ return '.' . $ReceiptSupportedExt;
+ }, $ReceiptSupportedExt);
+ echo '<tr>
+ <td>', _('Attach Receipt'), ':</td>
+ <td>
+ <input type="hidden" name="MAX_FILE_SIZE" value="' . $_SESSION['MaxImageSize'] * 1024 . '" />
+ <input type="file" name="Receipt" id="Receipt" accept="' . implode(',', $ReceiptSupportedExtDotPrefix) . '" title="', _('Accepted file types'), ': ', implode(', ', $ReceiptSupportedExt), '" />
+ </td>
+ </tr>';
+
if (!isset($_POST['Notes'])) {
$_POST['Notes'] = '';
}
@@ -537,13 +677,7 @@
<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, '" />';
Modified: trunk/PcExpenses.php
===================================================================
--- trunk/PcExpenses.php 2017-11-07 01:57:00 UTC (rev 7865)
+++ trunk/PcExpenses.php 2017-11-23 22:45:05 UTC (rev 7866)
@@ -36,16 +36,16 @@
prnMsg(_('The Expense type code cannot be an empty string or spaces'), 'error');
} elseif (mb_strlen($_POST['CodeExpense']) > 20) {
$InputError = 1;
- prnMsg(_('The Expense code must be twenty characters or less long'), 'error');
+ prnMsg(_('The expense code must be twenty characters or less long'), 'error');
} elseif (ContainsIllegalCharacters($_POST['CodeExpense'])) {
$InputError = 1;
- prnMsg(_('The Expense code cannot contain any of the following characters " \' - &'), 'error');
+ prnMsg(_('The expense code cannot contain any of the following characters ') . '" \' - &', 'error');
} elseif (ContainsIllegalCharacters($_POST['Description'])) {
$InputError = 1;
- prnMsg(_('The Expense description cannot contain any of the following characters " \' - &'), 'error');
+ prnMsg(_('The expense description cannot contain any of the following characters ') . '" \' - &', 'error');
} elseif (mb_strlen($_POST['Description']) > 50) {
$InputError = 1;
- prnMsg(_('The tab code must be Fifty characters or less long'), 'error');
+ prnMsg(_('The tab code must be fifty characters or less long'), 'error');
} elseif (mb_strlen($_POST['Description']) == 0) {
$InputError = 1;
echo prnMsg(_('The tab code description must be entered'), 'error');
@@ -139,7 +139,7 @@
$Result = DB_query($SQL);
echo '<table class="selection">
<tr>
- <th>', _('Code Of Expense'), '</th>
+ <th>', _('Expense Code'), '</th>
<th>', _('Description'), '</th>
<th>', _('Account Code'), '</th>
<th>', _('Account Description'), '</th>
@@ -213,7 +213,7 @@
// We dont allow the user to change an existing type code
echo '<table class="selection">
<tr>
- <td>', _('Code Of Expense'), ':</td>
+ <td>', _('Expense Code'), ':</td>
<td>', $_POST['CodeExpense'], '</td>
</tr>';
} else {
@@ -220,7 +220,7 @@
// This is a new type so the user may volunteer a type code
echo '<table class="selection">
<tr>
- <td>', _('Code Of Expense'), ':</td>
+ <td>', _('Expense Code'), ':</td>
<td><input type="text" name="CodeExpense" autofocus="autofocus" required="required" maxlength="20" /></td>
</tr>';
}
Modified: trunk/PcReportExpense.php
===================================================================
--- trunk/PcReportExpense.php 2017-11-07 01:57:00 UTC (rev 7865)
+++ trunk/PcReportExpense.php 2017-11-23 22:45:05 UTC (rev 7866)
@@ -3,6 +3,7 @@
include ('includes/session.php');
$Title = _('Petty Cash Expense Management Report');
+/* webERP manual links before header.php */
$ViewTopic = 'PettyCash';
$BookMark = 'PcReportExpense';
@@ -115,7 +116,6 @@
pcashdetails.authorized,
pcashdetails.posted,
pcashdetails.notes,
- pcashdetails.receipt,
pctabs.currency,
currencies.decimalplaces
FROM pcashdetails, pctabs, currencies
@@ -139,11 +139,10 @@
<th>' . _('Tab') . '</th>
<th>' . _('Currency') . '</th>
<th>' . _('Gross Amount') . '</th>
- <th>', _('Total Tax'), '</th>
+ <th>', _('Tax'), '</th>
<th>', _('Tax Group'), '</th>
<th>', _('Tag'), '</th>
<th>' . _('Notes') . '</th>
- <th>' . _('Receipt') . '</th>
<th>' . _('Date Authorised') . '</th>
</tr>';
@@ -186,7 +185,7 @@
$TagDescription = $TagTo . ' - ' . $TagRow['tagdescription'];
if ($MyRow['authorized'] == '0000-00-00') {
- $AuthorisedDate = _('Unauthorised');
+ $AuthorisedDate = _('Unauthorised');
} else {
$AuthorisedDate = ConvertSQLDate($MyRow['authorized']);
}
@@ -207,7 +206,6 @@
<td>', $TaxesDescription, '</td>
<td>', $TagDescription, '</td>
<td>', $MyRow['notes'], '</td>
- <td>', $MyRow['receipt'], '</td>
<td>', $AuthorisedDate, '</td>
</tr>';
} //end of looping
Modified: trunk/PcReportTab.php
===================================================================
--- trunk/PcReportTab.php 2017-11-07 01:57:00 UTC (rev 7865)
+++ trunk/PcReportTab.php 2017-11-23 22:45:05 UTC (rev 7866)
@@ -3,12 +3,12 @@
include ('includes/session.php');
$Title = _('Petty Cash Management Report');
+/* webERP manual links before header.php */
$ViewTopic = 'PettyCash';
$BookMark = 'PcReportTab';
include ('includes/SQL_CommonFunctions.inc');
-
if (isset($_POST['SelectedTabs'])){
$SelectedTabs = mb_strtoupper($_POST['SelectedTabs']);
} elseif (isset($_GET['SelectedTabs'])){
@@ -41,21 +41,19 @@
<td><select name="SelectedTabs">';
$SQL = "SELECT tabcode
- FROM pctabs
- WHERE ( authorizer = '" . $_SESSION['UserID'] .
- "' OR usercode = '" . $_SESSION['UserID'].
- "' OR assigner = '" . $_SESSION['UserID'] . "' )
- ORDER BY tabcode";
+ FROM pctabs
+ WHERE ( authorizer = '" . $_SESSION['UserID'] .
+ "' OR usercode = '" . $_SESSION['UserID'].
+ "' OR assigner = '" . $_SESSION['UserID'] . "' )
+ ORDER BY tabcode";
$Result = DB_query($SQL);
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['SelectedTabs']) and $MyRow['tabcode'] == $_POST['SelectedTabs']) {
- echo '<option selected="selected" value="';
+ echo '<option selected="selected" value="', $MyRow['tabcode'], '">', $MyRow['tabcode'], '</option>';
} else {
- echo '<option value="';
+ echo '<option value="', $MyRow['tabcode'], '">', $MyRow['tabcode'], '</option>';
}
- echo $MyRow['tabcode'] . '">' . $MyRow['tabcode'] . '</option>';
-
} //end while loop get type of tab
DB_free_result($Result);
@@ -100,8 +98,7 @@
amount,
authorized,
posted,
- notes,
- receipt
+ notes
FROM pcashdetails
WHERE tabcode = '" . $SelectedTabs . "'
AND date >= '" . $SQLFromDate . "' AND date <= '" . $SQLToDate . "'
@@ -219,11 +216,10 @@
$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,70,$FontSize,_('Date of Expense'));
$LeftOvers = $pdf->addTextWrap($Left_Margin+60,$YPos,100,$FontSize,_('Expense Code'));
$LeftOvers = $pdf->addTextWrap($Left_Margin+160,$YPos,100,$FontSize,_('Gross Amount'));
- $LeftOvers = $pdf->addTextWrap($Left_Margin+210,$YPos,100,$FontSize,_('Total Tax'));
- $LeftOvers = $pdf->addTextWrap($Left_Margin+245,$YPos,100,$FontSize,_('Tax Group'));
- $LeftOvers = $pdf->addTextWrap($Left_Margin+285,$YPos,100,$FontSize,_('Tag'));
- $LeftOvers = $pdf->addTextWrap($Left_Margin+330,$YPos,100,$FontSize,_('Note'));
- $LeftOvers = $pdf->addTextWrap($Left_Margin+395,$YPos,100,$FontSize,_('Receipt'));
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+210,$YPos,100,$FontSize,_('Tax'));
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+255,$YPos,100,$FontSize,_('Tax Group'));
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+320,$YPos,100,$FontSize,_('Tag'));
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+380,$YPos,100,$FontSize,_('Notes'));
$LeftOvers = $pdf->addTextWrap($Left_Margin+465,$YPos,100,$FontSize,_('Date Authorised'));
$YPos -= (2 * $line_height);
@@ -264,10 +260,20 @@
$TaxResult = DB_query($TaxSQL);
while ($MyTaxRow = DB_fetch_array($TaxResult)) {
- $TaxesDescription .= $MyTaxRow['description'];
- $TaxesTaxAmount .= locale_number_format($MyTaxRow['amount'], $CurrDecimalPlaces);
+ $TaxesDescription .= $MyTaxRow['description'] . "\n"; //Line breaks not working !?
+ $TaxesTaxAmount .= locale_number_format($MyTaxRow['amount'], $CurrDecimalPlaces) . "\n"; //Line breaks not working !?
}
+ //Generate download link for expense receipt, or show text if no receipt file is found.
+ $ReceiptSupportedExt = array('png','jpg','jpeg','pdf','doc','docx','xls','xlsx'); //Supported file extensions
+ $ReceiptFileDir = $PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/expenses_receipts/' . mb_strtolower($SelectedTabs); //Receipts upload directory
+ $ReceiptFilePath = reset(glob($ReceiptFileDir . '/' . $MyRow['counterindex'] . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE)); //Find the relevant receipt file for the expense. There should only be one (file type), but limit to one result just in case.
+ if (empty($ReceiptFilePath)) { //If no receipt file for the expenses is found
+ $ReceiptText = _('No attachment');
+ } else {
+ $ReceiptText = '<a href="' . $ReceiptFilePath . '" download="ExpenseReceipt-' . mb_strtolower($SelectedTabs) . '-[' . $MyRow['date'] . ']-[' . $MyRow['counterindex'] . ']">' . _('Download attachment') . '</a>';
+ }
+
if ($MyRow['authorized'] == '0000-00-00') {
$AuthorisedDate = _('Unauthorised');
} else {
@@ -279,10 +285,9 @@
$LeftOvers = $pdf->addTextWrap($Left_Margin+60,$YPos,130,$FontSize,$Description[0]);
$LeftOvers = $pdf->addTextWrap($Left_Margin+160,$YPos,50,$FontSize,locale_number_format($MyRow['amount'], $CurrDecimalPlaces),'right');
$LeftOvers = $pdf->addTextWrap($Left_Margin+210,$YPos,50,$FontSize,$TaxesTaxAmount);
- $LeftOvers = $pdf->addTextWrap($Left_Margin+245,$YPos,50,$FontSize,$TaxesDescription);
- $LeftOvers = $pdf->addTextWrap($Left_Margin+285,$YPos,50,$FontSize,$TagDescription);
- $LeftOvers = $pdf->addTextWrap($Left_Margin+330,$YPos,60,$FontSize,$MyRow['notes']);
- $LeftOvers = $pdf->addTextWrap($Left_Margin+395,$YPos,65,$FontSize,$MyRow['receipt']);
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+255,$YPos,50,$FontSize,$TaxesDescription);
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+320,$YPos,50,$FontSize,$TagDescription);
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+380,$YPos,60,$FontSize,$MyRow['notes']);
$LeftOvers = $pdf->addTextWrap($Left_Margin+465,$YPos,70,$FontSize,$AuthorisedDate);
$YPos -= $line_height;
@@ -445,8 +450,7 @@
amount,
authorized,
posted,
- notes,
- receipt
+ notes
FROM pcashdetails
WHERE tabcode = '" . $SelectedTabs . "'
AND date >= '" . $SQLFromDate . "'
@@ -462,11 +466,11 @@
<th>' . _('Date of Expense') . '</th>
<th>' . _('Expense Code') . '</th>
<th>' . _('Gross Amount') . '</th>
- <th>' . _('Total Tax') . '</th>
+ <th>' . _('Tax') . '</th>
<th>' . _('Tax Group') . '</th>
<th>' . _('Tag') . '</th>
<th>' . _('Notes') . '</th>
- <th>' . _('Receipt') . '</th>
+ <th>' . _('Receipt Attachment') . '</th>
<th>' . _('Date Authorised') . '</th>
</tr>';
@@ -510,6 +514,16 @@
$TaxesTaxAmount .= locale_number_format($MyTaxRow['amount'], $CurrDecimalPlaces) . '<br />';
}
+ //Generate download link for expense receipt, or show text if no receipt file is found.
+ $ReceiptSupportedExt = array('png','jpg','jpeg','pdf','doc','docx','xls','xlsx'); //Supported file extensions
+ $ReceiptFileDir = $PathPrefix . 'companies/' . $_SESSION['DatabaseName'] . '/expenses_receipts/' . mb_strtolower($SelectedTabs); //Receipts upload directory
+ $ReceiptFilePath = reset(glob($ReceiptFileDir . '/' . $MyRow['counterindex'] . '.{' . implode(',', $ReceiptSupportedExt) . '}', GLOB_BRACE)); //Find the relevant receipt file for the expense. There should only be one (file type), but limit to one result just in case.
+ if (empty($ReceiptFilePath)) { //If no receipt file for the expenses is found
+ $ReceiptText = _('No attachment');
+ } else {
+ $ReceiptText = '<a href="' . $ReceiptFilePath . '" download="ExpenseReceipt-' . mb_strtolower($SelectedTabs) . '-[' . $MyRow['date'] . ']-[' . $MyRow['counterindex'] . ']">' . _('Download attachment') . '</a>';
+ }
+
if ($MyRow['authorized'] == '0000-00-00') {
$AuthorisedDate =...
[truncated message content] |