|
From: <dai...@us...> - 2012-12-08 01:41:40
|
Revision: 5753
http://sourceforge.net/p/web-erp/reponame/5753
Author: daintree
Date: 2012-12-08 01:41:35 +0000 (Sat, 08 Dec 2012)
Log Message:
-----------
Check users authoirty before allowing auto receiving
Modified Paths:
--------------
trunk/PO_Items.php
trunk/Payments.php
trunk/SuppPaymentRun.php
trunk/SupplierInvoice.php
trunk/doc/Change.log
trunk/includes/session.inc
Modified: trunk/PO_Items.php
===================================================================
--- trunk/PO_Items.php 2012-12-05 08:39:15 UTC (rev 5752)
+++ trunk/PO_Items.php 2012-12-08 01:41:35 UTC (rev 5753)
@@ -383,7 +383,8 @@
$Result = DB_Txn_Commit($db);
- if ($_SESSION['PO'.$identifier]->Status == 'Authorised'){;
+ /* Only show the link to auto receive the order if the user has permission to receive goods and permission to authorise and has authorised the order */
+ if ($_SESSION['PO'.$identifier]->Status == 'Authorised' AND in_array($_SESSION['PageSecurityArray']['GoodsReceived.php'], $_SESSION['AllowedPageSecurityTokens'])){
echo '<a href="SupplierInvoice.php?SupplierID=' . $_SESSION['PO'.$identifier]->SupplierID . '&ReceivePO=' . $_SESSION['PO'.$identifier]->OrderNo . '&DeliveryDate=' . $_SESSION['PO'.$identifier]->DeliveryDate . '">' . _('Receive and Enter Purchase Invoice') . '</a>';
}
Modified: trunk/Payments.php
===================================================================
--- trunk/Payments.php 2012-12-05 08:39:15 UTC (rev 5752)
+++ trunk/Payments.php 2012-12-08 01:41:35 UTC (rev 5753)
@@ -115,6 +115,9 @@
$_SESSION['PaymentDetail' . $identifier]->Currency = $myrow['currcode'];
$_POST['Currency'] = $_SESSION['PaymentDetail' . $identifier]->Currency;
}
+ if (isset($_GET['Amount']) AND is_numeric($_GET['Amount'])){
+ $_SESSION['PaymentDetail' . $identifier]->Amount = filter_number_format($_GET['Amount']);
+ }
}
}
Modified: trunk/SuppPaymentRun.php
===================================================================
--- trunk/SuppPaymentRun.php 2012-12-05 08:39:15 UTC (rev 5752)
+++ trunk/SuppPaymentRun.php 2012-12-08 01:41:35 UTC (rev 5753)
@@ -75,18 +75,18 @@
$CurrDecimalPlaces = $SuppliersToPay['currdecimalplaces'];
$sql = "SELECT suppliers.supplierid,
- suppliers.suppname,
- systypes.typename,
- paymentterms.terms,
- supptrans.suppreference,
- supptrans.trandate,
- supptrans.rate,
- supptrans.transno,
- supptrans.type,
- (supptrans.ovamount + supptrans.ovgst - supptrans.alloc) AS balance,
- (supptrans.ovamount + supptrans.ovgst ) AS trantotal,
- supptrans.diffonexch,
- supptrans.id
+ suppliers.suppname,
+ systypes.typename,
+ paymentterms.terms,
+ supptrans.suppreference,
+ supptrans.trandate,
+ supptrans.rate,
+ supptrans.transno,
+ supptrans.type,
+ (supptrans.ovamount + supptrans.ovgst - supptrans.alloc) AS balance,
+ (supptrans.ovamount + supptrans.ovgst ) AS trantotal,
+ supptrans.diffonexch,
+ supptrans.id
FROM suppliers INNER JOIN paymentterms
ON suppliers.paymentterms = paymentterms.termsindicator
INNER JOIN supptrans
@@ -96,7 +96,7 @@
WHERE supptrans.supplierno = '" . $SuppliersToPay['supplierid'] . "'
AND supptrans.ovamount + supptrans.ovgst - supptrans.alloc !=0
AND supptrans.duedate <='" . FormatDateForSQL($_POST['AmountsDueBy']) . "'
- AND supptrans.hold=0
+ AND supptrans.hold = 0
AND suppliers.currcode = '" . $_POST['Currency'] . "'
AND supptrans.supplierno >= '" . $_POST['FromCriteria'] . "'
AND supptrans.supplierno <= '" . $_POST['ToCriteria'] . "'
@@ -251,12 +251,12 @@
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection">';
- if (!isset($_POST['FromCriteria']) or mb_strlen($_POST['FromCriteria'])<1){
+ if (!isset($_POST['FromCriteria']) OR mb_strlen($_POST['FromCriteria'])<1){
$DefaultFromCriteria = '1';
} else {
$DefaultFromCriteria = $_POST['FromCriteria'];
}
- if (!isset($_POST['ToCriteria']) or mb_strlen($_POST['ToCriteria'])<1){
+ if (!isset($_POST['ToCriteria']) OR mb_strlen($_POST['ToCriteria'])<1){
$DefaultToCriteria = 'zzzzzzz';
} else {
$DefaultToCriteria = $_POST['ToCriteria'];
@@ -365,7 +365,7 @@
echo '</select></td>
</tr>';
- if (!isset($_POST['Ref']) or !is_numeric($_POST['Ref'])){
+ if (!isset($_POST['Ref']) OR !is_numeric($_POST['Ref'])){
$DefaultRef = '1';
} else {
$DefaultRef = $_POST['Ref'];
Modified: trunk/SupplierInvoice.php
===================================================================
--- trunk/SupplierInvoice.php 2012-12-05 08:39:15 UTC (rev 5752)
+++ trunk/SupplierInvoice.php 2012-12-08 01:41:35 UTC (rev 5753)
@@ -138,384 +138,362 @@
* on the details entered in the purchase order screen.
*/
if (isset($_GET['ReceivePO']) AND $_GET['ReceivePO']!=''){
+
+ /*Need to check that the user has permission to receive goods */
- $_GET['ModifyOrderNumber'] = intval($_GET['ReceivePO']);
- include('includes/PO_ReadInOrder.inc');
-
- if ($_SESSION['PO'.$identifier]->Status == 'Authorised'){
- $Result = DB_Txn_Begin($db);
- /*Now Get the next GRN - function in SQL_CommonFunctions*/
- $GRN = GetNextTransNo(25, $db);
- if (!isset($_GET['DeliveryDate'])){
- $DeliveryDate = date($_SESSION['DefaultDateFormat']);
- } else {
- $DeliveryDate = $_GET['DeliveryDate'];
- }
- $_POST['ExRate'] = $_SESSION['SuppTrans']->ExRate;
- $_POST['TranDate'] = $DeliveryDate;
+ if (! in_array($_SESSION['PageSecurityArray']['GoodsReceived.php'], $_SESSION['AllowedPageSecurityTokens'])){
+ prnMsg(_('Your permissions do not allow receiving of goods. Automatic receiving of purchase orders is restricted to those only users who are authorised to receive goods/services'),'error');
+ } else {
+ /* The user has permission to receive goods then lets go */
+
+ $_GET['ModifyOrderNumber'] = intval($_GET['ReceivePO']);
+ include('includes/PO_ReadInOrder.inc');
- $PeriodNo = GetPeriod($DeliveryDate, $db);
-
- $OrderHasControlledItems = false; //assume the best
- foreach ($_SESSION['PO'.$identifier]->LineItems as $OrderLine) {
- //Set the quantity to receive with this auto delivery assuming all is well
- $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->ReceiveQty = $OrderLine->Quantity - $OrderLine->QtyReceived;
-
- if ($OrderLine->Controlled ==1) { // it's a controlled item - we can't deal with auto receiving controlled items!!!
- prnMsg(_('Auto receiving of controlled stock items that require serial number or batch number entry is not currently catered for. Only orders with normal non-serial numbered items can be received automatically'),'error');
- $OrderHasControlledItems = true;
+ if ($_SESSION['PO'.$identifier]->Status == 'Authorised'){
+ $Result = DB_Txn_Begin($db);
+ /*Now Get the next GRN - function in SQL_CommonFunctions*/
+ $GRN = GetNextTransNo(25, $db);
+ if (!isset($_GET['DeliveryDate'])){
+ $DeliveryDate = date($_SESSION['DefaultDateFormat']);
+ } else {
+ $DeliveryDate = $_GET['DeliveryDate'];
}
- }
- if ($OrderHasControlledItems == false){
+ $_POST['ExRate'] = $_SESSION['SuppTrans']->ExRate;
+ $_POST['TranDate'] = $DeliveryDate;
+
+ $PeriodNo = GetPeriod($DeliveryDate, $db);
+
+ $OrderHasControlledItems = false; //assume the best
foreach ($_SESSION['PO'.$identifier]->LineItems as $OrderLine) {
- $LocalCurrencyPrice = ($OrderLine->Price / $_SESSION['SuppTrans']->ExRate);
-
- if ($OrderLine->StockID!='') { //Its a stock item line
- /*Need to get the current standard cost as it is now so we can process GL jorunals later*/
- $SQL = "SELECT materialcost + labourcost + overheadcost as stdcost
- FROM stockmaster
- WHERE stockid='" . $OrderLine->StockID . "'";
- $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The standard cost of the item being received cannot be retrieved because');
- $DbgMsg = _('The following SQL to retrieve the standard cost was used');
- $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
-
- $myrow = DB_fetch_row($Result);
- $CurrentStandardCost = $myrow[0];
+ //Set the quantity to receive with this auto delivery assuming all is well
+ $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->ReceiveQty = $OrderLine->Quantity - $OrderLine->QtyReceived;
- if ($OrderLine->QtyReceived==0){ //its the first receipt against this line
- $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = $CurrentStandardCost;
- }
-
- /*Set the purchase order line stdcostunit = weighted average / standard cost used for all receipts of this line
- This assures that the quantity received against the purchase order line multiplied by the weighted average of standard
- costs received = the total of standard cost posted to GRN suspense*/
- $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = (($CurrentStandardCost * $OrderLine->ReceiveQty) + ($_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost *$OrderLine->QtyReceived)) / ($OrderLine->ReceiveQty + $OrderLine->QtyReceived);
-
- } elseif ($OrderLine->QtyReceived==0 AND $OrderLine->StockID=='') {
- /*Its a nominal item being received */
- /*Need to record the value of the order per unit in the standard cost field to ensure GRN account entries clear */
- $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = $LocalCurrencyPrice;
+ if ($OrderLine->Controlled ==1) { // it's a controlled item - we can't deal with auto receiving controlled items!!!
+ prnMsg(_('Auto receiving of controlled stock items that require serial number or batch number entry is not currently catered for. Only orders with normal non-serial numbered items can be received automatically'),'error');
+ $OrderHasControlledItems = true;
}
-
- if ($OrderLine->StockID=='') { /*Its a NOMINAL item line */
- $CurrentStandardCost = $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost;
- }
-
- /*Now the SQL to do the update to the PurchOrderDetails */
-
- $SQL = "UPDATE purchorderdetails SET quantityrecd = quantityrecd + '" . $OrderLine->ReceiveQty . "',
- stdcostunit='" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost . "',
- completed='" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->Completed . "'
- WHERE podetailitem = '" . $OrderLine->PODetailRec . "'";
-
- $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The purchase order detail record could not be updated with the quantity received because');
- $DbgMsg = _('The following SQL to update the purchase order detail record was used');
- $Result = DB_query($SQL,$db, $ErrMsg, $DbgMsg, true);
-
-
- if ($OrderLine->StockID !=''){ /*Its a stock item so use the standard cost for the journals */
- $UnitCost = $CurrentStandardCost;
- } else { /*otherwise its a nominal PO item so use the purchase cost converted to local currency */
- $UnitCost = $OrderLine->Price / $_SESSION['SuppTrans']->ExRate;
- }
-
- /*Need to insert a GRN item */
-
- $SQL = "INSERT INTO grns (grnbatch,
- podetailitem,
- itemcode,
- itemdescription,
- deliverydate,
- qtyrecd,
- supplierid,
- stdcostunit)
- VALUES ('" . $GRN . "',
- '" . $OrderLine->PODetailRec . "',
- '" . $OrderLine->StockID . "',
- '" . DB_escape_string($OrderLine->ItemDescription) . "',
- '" . FormatDateForSQL($DeliveryDate) . "',
- '" . $OrderLine->ReceiveQty . "',
- '" . $_SESSION['PO'.$identifier]->SupplierID . "',
- '" . $CurrentStandardCost . "')";
-
- $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('A GRN record could not be inserted') . '. ' . _('This receipt of goods has not been processed because');
- $DbgMsg = _('The following SQL to insert the GRN record was used');
- $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
-
- if ($OrderLine->StockID!=''){ /* if the order line is in fact a stock item */
-
- /* Update location stock records - NB a PO cannot be entered for a dummy/assembly/kit parts */
-
- /* Need to get the current location quantity will need it later for the stock movement */
- $SQL="SELECT locstock.quantity
- FROM locstock
- WHERE locstock.stockid='" . $OrderLine->StockID . "'
- AND loccode= '" . $_SESSION['PO'.$identifier]->Location . "'";
-
- $Result = DB_query($SQL, $db);
- if (DB_num_rows($Result)==1){
- $LocQtyRow = DB_fetch_row($Result);
- $QtyOnHandPrior = $LocQtyRow[0];
- } else {
- /*There must actually be some error this should never happen */
- $QtyOnHandPrior = 0;
+ }
+ if ($OrderHasControlledItems == false){
+ foreach ($_SESSION['PO'.$identifier]->LineItems as $OrderLine) {
+ $LocalCurrencyPrice = ($OrderLine->Price / $_SESSION['SuppTrans']->ExRate);
+
+ if ($OrderLine->StockID!='') { //Its a stock item line
+ /*Need to get the current standard cost as it is now so we can process GL jorunals later*/
+ $SQL = "SELECT materialcost + labourcost + overheadcost as stdcost
+ FROM stockmaster
+ WHERE stockid='" . $OrderLine->StockID . "'";
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The standard cost of the item being received cannot be retrieved because');
+ $DbgMsg = _('The following SQL to retrieve the standard cost was used');
+ $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true);
+
+ $myrow = DB_fetch_row($Result);
+ $CurrentStandardCost = $myrow[0];
+
+ if ($OrderLine->QtyReceived==0){ //its the first receipt against this line
+ $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = $CurrentStandardCost;
+ }
+
+ /*Set the purchase order line stdcostunit = weighted average / standard cost used for all receipts of this line
+ This assures that the quantity received against the purchase order line multiplied by the weighted average of standard
+ costs received = the total of standard cost posted to GRN suspense*/
+ $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = (($CurrentStandardCost * $OrderLine->ReceiveQty) + ($_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost *$OrderLine->QtyReceived)) / ($OrderLine->ReceiveQty + $OrderLine->QtyReceived);
+
+ } elseif ($OrderLine->QtyReceived==0 AND $OrderLine->StockID=='') {
+ /*Its a nominal item being received */
+ /*Need to record the value of the order per unit in the standard cost field to ensure GRN account entries clear */
+ $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost = $LocalCurrencyPrice;
}
-
- $SQL = "UPDATE locstock
- SET quantity = locstock.quantity + '" . $OrderLine->ReceiveQty . "'
- WHERE locstock.stockid = '" . $OrderLine->StockID . "'
- AND loccode = '" . $_SESSION['PO'.$identifier]->Location . "'";
-
- $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated because');
- $DbgMsg = _('The following SQL to update the location stock record was used');
+
+ if ($OrderLine->StockID=='') { /*Its a NOMINAL item line */
+ $CurrentStandardCost = $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost;
+ }
+
+ /*Now the SQL to do the update to the PurchOrderDetails */
+
+ $SQL = "UPDATE purchorderdetails SET quantityrecd = quantityrecd + '" . $OrderLine->ReceiveQty . "',
+ stdcostunit='" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost . "',
+ completed='" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->Completed . "'
+ WHERE podetailitem = '" . $OrderLine->PODetailRec . "'";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The purchase order detail record could not be updated with the quantity received because');
+ $DbgMsg = _('The following SQL to update the purchase order detail record was used');
+ $Result = DB_query($SQL,$db, $ErrMsg, $DbgMsg, true);
+
+
+ if ($OrderLine->StockID !=''){ /*Its a stock item so use the standard cost for the journals */
+ $UnitCost = $CurrentStandardCost;
+ } else { /*otherwise its a nominal PO item so use the purchase cost converted to local currency */
+ $UnitCost = $OrderLine->Price / $_SESSION['SuppTrans']->ExRate;
+ }
+
+ /*Need to insert a GRN item */
+
+ $SQL = "INSERT INTO grns (grnbatch,
+ podetailitem,
+ itemcode,
+ itemdescription,
+ deliverydate,
+ qtyrecd,
+ supplierid,
+ stdcostunit)
+ VALUES ('" . $GRN . "',
+ '" . $OrderLine->PODetailRec . "',
+ '" . $OrderLine->StockID . "',
+ '" . DB_escape_string($OrderLine->ItemDescription) . "',
+ '" . FormatDateForSQL($DeliveryDate) . "',
+ '" . $OrderLine->ReceiveQty . "',
+ '" . $_SESSION['PO'.$identifier]->SupplierID . "',
+ '" . $CurrentStandardCost . "')";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('A GRN record could not be inserted') . '. ' . _('This receipt of goods has not been processed because');
+ $DbgMsg = _('The following SQL to insert the GRN record was used');
$Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
+
+ if ($OrderLine->StockID!=''){ /* if the order line is in fact a stock item */
+
+ /* Update location stock records - NB a PO cannot be entered for a dummy/assembly/kit parts */
+
+ /* Need to get the current location quantity will need it later for the stock movement */
+ $SQL="SELECT locstock.quantity
+ FROM locstock
+ WHERE locstock.stockid='" . $OrderLine->StockID . "'
+ AND loccode= '" . $_SESSION['PO'.$identifier]->Location . "'";
+
+ $Result = DB_query($SQL, $db);
+ if (DB_num_rows($Result)==1){
+ $LocQtyRow = DB_fetch_row($Result);
+ $QtyOnHandPrior = $LocQtyRow[0];
+ } else {
+ /*There must actually be some error this should never happen */
+ $QtyOnHandPrior = 0;
+ }
+
+ $SQL = "UPDATE locstock
+ SET quantity = locstock.quantity + '" . $OrderLine->ReceiveQty . "'
+ WHERE locstock.stockid = '" . $OrderLine->StockID . "'
+ AND loccode = '" . $_SESSION['PO'.$identifier]->Location . "'";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated because');
+ $DbgMsg = _('The following SQL to update the location stock record was used');
+ $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
+
+ /* Insert stock movements - with unit cost */
+
+ $SQL = "INSERT INTO stockmoves (stockid,
+ type,
+ transno,
+ loccode,
+ trandate,
+ price,
+ prd,
+ reference,
+ qty,
+ standardcost,
+ newqoh)
+ VALUES (
+ '" . $OrderLine->StockID . "',
+ 25,
+ '" . $GRN . "',
+ '" . $_SESSION['PO'.$identifier]->Location . "',
+ '" . FormatDateForSQL($DeliveryDate) . "',
+ '" . $LocalCurrencyPrice . "',
+ '" . $PeriodNo . "',
+ '" . $_SESSION['PO'.$identifier]->SupplierID . " (" . DB_escape_string($_SESSION['PO'.$identifier]->SupplierName) . ") - " .$_SESSION['PO'.$identifier]->OrderNo . "',
+ '" . $OrderLine->ReceiveQty . "',
+ '" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost . "',
+ '" . ($QtyOnHandPrior + $OrderLine->ReceiveQty) . "'
+ )";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('stock movement records could not be inserted because');
+ $DbgMsg = _('The following SQL to insert the stock movement records was used');
+ $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
- /* Insert stock movements - with unit cost */
-
- $SQL = "INSERT INTO stockmoves (stockid,
- type,
- transno,
- loccode,
+ } /*end of its a stock item - updates to locations and insert movements*/
+
+ /* Check to see if the line item was flagged as the purchase of an asset */
+ if ($OrderLine->AssetID !='' AND $OrderLine->AssetID !='0'){ //then it is an asset
+
+ /*first validate the AssetID and if it doesn't exist treat it like a normal nominal item */
+ $CheckAssetExistsResult = DB_query("SELECT assetid,
+ datepurchased,
+ costact
+ FROM fixedassets
+ INNER JOIN fixedassetcategories
+ ON fixedassets.assetcategoryid=fixedassetcategories.categoryid
+ WHERE assetid='" . $OrderLine->AssetID . "'",$db);
+ if (DB_num_rows($CheckAssetExistsResult)==1){ //then work with the assetid provided
+
+ /*Need to add a fixedassettrans for the cost of the asset being received */
+ $SQL = "INSERT INTO fixedassettrans (assetid,
+ transtype,
+ transno,
+ transdate,
+ periodno,
+ inputdate,
+ fixedassettranstype,
+ amount)
+ VALUES ('" . $OrderLine->AssetID . "',
+ 25,
+ '" . $GRN . "',
+ '" . FormatDateForSQL($DeliveryDate) . "',
+ '" . $PeriodNo . "',
+ '" . Date('Y-m-d') . "',
+ '" . _('cost') . "',
+ '" . $CurrentStandardCost * $OrderLine->ReceiveQty . "')";
+ $ErrMsg = _('CRITICAL ERROR! NOTE DOWN THIS ERROR AND SEEK ASSISTANCE The fixed asset transaction could not be inserted because');
+ $DbgMsg = _('The following SQL to insert the fixed asset transaction record was used');
+ $Result = DB_query($SQL,$db,$ErrMsg, $DbgMsg, true);
+
+ /*Now get the correct cost GL account from the asset category */
+ $AssetRow = DB_fetch_array($CheckAssetExistsResult);
+ /*Over-ride any GL account specified in the order with the asset category cost account */
+ $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->GLCode = $AssetRow['costact'];
+ /*Now if there are no previous additions to this asset update the date purchased */
+ if ($AssetRow['datepurchased']=='0000-00-00'){
+ /* it is a new addition as the date is set to 0000-00-00 when the asset record is created
+ * before any cost is added to the asset
+ */
+ $SQL = "UPDATE fixedassets
+ SET datepurchased='" . FormatDateForSQL($DeliveryDate) . "',
+ cost = cost + " . ($CurrentStandardCost * $OrderLine->ReceiveQty) . "
+ WHERE assetid = '" . $OrderLine->AssetID . "'";
+ } else {
+ $SQL = "UPDATE fixedassets SET cost = cost + " . ($CurrentStandardCost * $OrderLine->ReceiveQty) . "
+ WHERE assetid = '" . $OrderLine->AssetID . "'";
+ }
+ $ErrMsg = _('CRITICAL ERROR! NOTE DOWN THIS ERROR AND SEEK ASSISTANCE. The fixed asset cost and date purchased was not able to be updated because:');
+ $DbgMsg = _('The following SQL was used to attempt the update of the cost and the date the asset was purchased');
+ $Result = DB_query($SQL,$db,$ErrMsg, $DbgMsg, true);
+
+ } //assetid provided doesn't exist so ignore it and treat as a normal nominal item
+ } //assetid is set so the nominal item is an asset
+
+ /* If GLLink_Stock then insert GLTrans to debit the GL Code and credit GRN Suspense account at standard cost*/
+ if ($_SESSION['PO'.$identifier]->GLLink==1 AND $OrderLine->GLCode !=0){
+ /*GLCode is set to 0 when the GLLink is not activated this covers a situation where the GLLink is now active but it wasn't when this PO was entered */
+
+ /*first the debit using the GLCode in the PO detail record entry*/
+ $SQL = "INSERT INTO gltrans (type,
+ typeno,
trandate,
- price,
- prd,
- reference,
- qty,
- standardcost,
- newqoh)
- VALUES (
- '" . $OrderLine->StockID . "',
- 25,
- '" . $GRN . "',
- '" . $_SESSION['PO'.$identifier]->Location . "',
- '" . FormatDateForSQL($DeliveryDate) . "',
- '" . $LocalCurrencyPrice . "',
- '" . $PeriodNo . "',
- '" . $_SESSION['PO'.$identifier]->SupplierID . " (" . DB_escape_string($_SESSION['PO'.$identifier]->SupplierName) . ") - " .$_SESSION['PO'.$identifier]->OrderNo . "',
- '" . $OrderLine->ReceiveQty . "',
- '" . $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->StandardCost . "',
- '" . ($QtyOnHandPrior + $OrderLine->ReceiveQty) . "'
- )";
-
- $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('stock movement records could not be inserted because');
- $DbgMsg = _('The following SQL to insert the stock movement records was used');
- $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
-
- } /*end of its a stock item - updates to locations and insert movements*/
-
- /* Check to see if the line item was flagged as the purchase of an asset */
- if ($OrderLine->AssetID !='' AND $OrderLine->AssetID !='0'){ //then it is an asset
-
- /*first validate the AssetID and if it doesn't exist treat it like a normal nominal item */
- $CheckAssetExistsResult = DB_query("SELECT assetid,
- datepurchased,
- costact
- FROM fixedassets
- INNER JOIN fixedassetcategories
- ON fixedassets.assetcategoryid=fixedassetcategories.categoryid
- WHERE assetid='" . $OrderLine->AssetID . "'",$db);
- if (DB_num_rows($CheckAssetExistsResult)==1){ //then work with the assetid provided
-
- /*Need to add a fixedassettrans for the cost of the asset being received */
- $SQL = "INSERT INTO fixedassettrans (assetid,
- transtype,
- transno,
- transdate,
- periodno,
- inputdate,
- fixedassettranstype,
- amount)
- VALUES ('" . $OrderLine->AssetID . "',
+ periodno,
+ account,
+ narrative,
+ amount)
+ VALUES (
25,
'" . $GRN . "',
'" . FormatDateForSQL($DeliveryDate) . "',
'" . $PeriodNo . "',
- '" . Date('Y-m-d') . "',
- '" . _('cost') . "',
- '" . $CurrentStandardCost * $OrderLine->ReceiveQty . "')";
- $ErrMsg = _('CRITICAL ERROR! NOTE DOWN THIS ERROR AND SEEK ASSISTANCE The fixed asset transaction could not be inserted because');
- $DbgMsg = _('The following SQL to insert the fixed asset transaction record was used');
+ '" . $OrderLine->GLCode . "',
+ 'PO: " . $_SESSION['PO'.$identifier]->OrderNo . " " . $_SESSION['PO'.$identifier]->SupplierID . " - " . $OrderLine->StockID
+ . " - " . DB_escape_string($OrderLine->ItemDescription) . " x " . $OrderLine->ReceiveQty . " @ " .
+ locale_number_format($CurrentStandardCost,$_SESSION['CompanyRecord']['decimalplaces']) . "',
+ '" . $CurrentStandardCost * $OrderLine->ReceiveQty . "'
+ )";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The purchase GL posting could not be inserted because');
+ $DbgMsg = _('The following SQL to insert the purchase GLTrans record was used');
$Result = DB_query($SQL,$db,$ErrMsg, $DbgMsg, true);
-
- /*Now get the correct cost GL account from the asset category */
- $AssetRow = DB_fetch_array($CheckAssetExistsResult);
- /*Over-ride any GL account specified in the order with the asset category cost account */
- $_SESSION['PO'.$identifier]->LineItems[$OrderLine->LineNo]->GLCode = $AssetRow['costact'];
- /*Now if there are no previous additions to this asset update the date purchased */
- if ($AssetRow['datepurchased']=='0000-00-00'){
- /* it is a new addition as the date is set to 0000-00-00 when the asset record is created
- * before any cost is added to the asset
- */
- $SQL = "UPDATE fixedassets
- SET datepurchased='" . FormatDateForSQL($DeliveryDate) . "',
- cost = cost + " . ($CurrentStandardCost * $OrderLine->ReceiveQty) . "
- WHERE assetid = '" . $OrderLine->AssetID . "'";
- } else {
- $SQL = "UPDATE fixedassets SET cost = cost + " . ($CurrentStandardCost * $OrderLine->ReceiveQty) . "
- WHERE assetid = '" . $OrderLine->AssetID . "'";
- }
- $ErrMsg = _('CRITICAL ERROR! NOTE DOWN THIS ERROR AND SEEK ASSISTANCE. The fixed asset cost and date purchased was not able to be updated because:');
- $DbgMsg = _('The following SQL was used to attempt the update of the cost and the date the asset was purchased');
- $Result = DB_query($SQL,$db,$ErrMsg, $DbgMsg, true);
-
- } //assetid provided doesn't exist so ignore it and treat as a normal nominal item
- } //assetid is set so the nominal item is an asset
+
+ /* If the CurrentStandardCost != UnitCost (the standard at the time the first delivery was booked in, and its a stock item, then the difference needs to be booked in against the purchase price variance account */
+
+ /*now the GRN suspense entry*/
+ $SQL = "INSERT INTO gltrans (type,
+ typeno,
+ trandate,
+ periodno,
+ account,
+ narrative,
+ amount)
+ VALUES (25,
+ '" . $GRN . "',
+ '" . FormatDateForSQL($DeliveryDate) . "',
+ '" . $PeriodNo . "',
+ '" . $_SESSION['CompanyRecord']['grnact'] . "',
+ '" . _('PO'.$identifier) . ': ' . $_SESSION['PO'.$identifier]->OrderNo . ' ' . $_SESSION['PO'.$identifier]->SupplierID . ' - ' . $OrderLine->StockID . ' - ' . DB_escape_string($OrderLine->ItemDescription) . ' x ' . $OrderLine->ReceiveQty . ' @ ' . locale_number_format($UnitCost,$_SESSION['CompanyRecord']['decimalplaces']) . "',
+ '" . -$UnitCost * $OrderLine->ReceiveQty . "'
+ )";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GRN suspense side of the GL posting could not be inserted because');
+ $DbgMsg = _('The following SQL to insert the GRN Suspense GLTrans record was used');
+ $Result = DB_query($SQL,$db, $ErrMsg, $DbgMsg,true);
+
+ } /* end of if GL and stock integrated and standard cost !=0 */
+ } /*end of OrderLine loop */
- /* If GLLink_Stock then insert GLTrans to debit the GL Code and credit GRN Suspense account at standard cost*/
- if ($_SESSION['PO'.$identifier]->GLLink==1 AND $OrderLine->GLCode !=0){
- /*GLCode is set to 0 when the GLLink is not activated this covers a situation where the GLLink is now active but it wasn't when this PO was entered */
-
- /*first the debit using the GLCode in the PO detail record entry*/
- $SQL = "INSERT INTO gltrans (type,
- typeno,
- trandate,
- periodno,
- account,
- narrative,
- amount)
- VALUES (
- 25,
- '" . $GRN . "',
- '" . FormatDateForSQL($DeliveryDate) . "',
- '" . $PeriodNo . "',
- '" . $OrderLine->GLCode . "',
- 'PO: " . $_SESSION['PO'.$identifier]->OrderNo . " " . $_SESSION['PO'.$identifier]->SupplierID . " - " . $OrderLine->StockID
- . " - " . DB_escape_string($OrderLine->ItemDescription) . " x " . $OrderLine->ReceiveQty . " @ " .
- locale_number_format($CurrentStandardCost,$_SESSION['CompanyRecord']['decimalplaces']) . "',
- '" . $CurrentStandardCost * $OrderLine->ReceiveQty . "'
- )";
-
- $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The purchase GL posting could not be inserted because');
- $DbgMsg = _('The following SQL to insert the purchase GLTrans record was used');
- $Result = DB_query($SQL,$db,$ErrMsg, $DbgMsg, true);
-
- /* If the CurrentStandardCost != UnitCost (the standard at the time the first delivery was booked in, and its a stock item, then the difference needs to be booked in against the purchase price variance account */
-
- /*now the GRN suspense entry*/
- $SQL = "INSERT INTO gltrans (type,
- typeno,
- trandate,
- periodno,
- account,
- narrative,
- amount)
- VALUES (25,
- '" . $GRN . "',
- '" . FormatDateForSQL($DeliveryDate) . "',
- '" . $PeriodNo . "',
- '" . $_SESSION['CompanyRecord']['grnact'] . "',
- '" . _('PO'.$identifier) . ': ' . $_SESSION['PO'.$identifier]->OrderNo . ' ' . $_SESSION['PO'.$identifier]->SupplierID . ' - ' . $OrderLine->StockID . ' - ' . DB_escape_string($OrderLine->ItemDescription) . ' x ' . $OrderLine->ReceiveQty . ' @ ' . locale_number_format($UnitCost,$_SESSION['CompanyRecord']['decimalplaces']) . "',
- '" . -$UnitCost * $OrderLine->ReceiveQty . "'
- )";
-
- $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GRN suspense side of the GL posting could not be inserted because');
- $DbgMsg = _('The following SQL to insert the GRN Suspense GLTrans record was used');
- $Result = DB_query($SQL,$db, $ErrMsg, $DbgMsg,true);
-
- } /* end of if GL and stock integrated and standard cost !=0 */
- } /*end of OrderLine loop */
+ $StatusComment=date($_SESSION['DefaultDateFormat']) .' - ' . _('Order Completed on entry of GRN') .'<br />' . $_SESSION['PO'.$identifier]->StatusComments;
+ $sql="UPDATE purchorders
+ SET status='Completed',
+ stat_comment='" . $StatusComment . "'
+ WHERE orderno='" . $_SESSION['PO'.$identifier]->OrderNo . "'";
+ $result=DB_query($sql,$db);
+
+ if ($_SESSION['PO'.$identifier]->GLLink==1) {
+ EnsureGLEntriesBalance(25, $GRN,$db);
+ }
- $StatusComment=date($_SESSION['DefaultDateFormat']) .' - ' . _('Order Completed on entry of GRN') .'<br />' . $_SESSION['PO'.$identifier]->StatusComments;
- $sql="UPDATE purchorders
- SET status='Completed',
- stat_comment='" . $StatusComment . "'
- WHERE orderno='" . $_SESSION['PO'.$identifier]->OrderNo . "'";
- $result=DB_query($sql,$db);
-
- if ($_SESSION['PO'.$identifier]->GLLink==1) {
- EnsureGLEntriesBalance(25, $GRN,$db);
- }
-
- $Result = DB_Txn_Commit($db);
-
- //Now add all these deliveries to this purchase invoice
-
-
- $SQL = "SELECT grnbatch,
- grnno,
- purchorderdetails.orderno,
- purchorderdetails.unitprice,
- grns.itemcode,
- grns.deliverydate,
- grns.itemdescription,
- grns.qtyrecd,
- grns.quantityinv,
- grns.stdcostunit,
- purchorderdetails.glcode,
- purchorderdetails.shiptref,
- purchorderdetails.jobref,
- purchorderdetails.podetailitem,
- purchorderdetails.assetid,
- stockmaster.decimalplaces
- FROM grns INNER JOIN purchorderdetails
- ON grns.podetailitem=purchorderdetails.podetailitem
- LEFT JOIN stockmaster ON grns.itemcode=stockmaster.stockid
- WHERE grns.supplierid ='" . $_SESSION['SuppTrans']->SupplierID . "'
- AND purchorderdetails.orderno = '" . intval($_GET['ReceivePO']) . "'
- AND grns.qtyrecd - grns.quantityinv > 0
- ORDER BY grns.grnno";
- $GRNResults = DB_query($SQL,$db);
-
- while ($myrow=DB_fetch_array($GRNResults)){
+ $Result = DB_Txn_Commit($db);
- if ($myrow['decimalplaces']==''){
- $myrow['decimalplaces']=2;
+ //Now add all these deliveries to this purchase invoice
+
+
+ $SQL = "SELECT grnbatch,
+ grnno,
+ purchorderdetails.orderno,
+ purchorderdetails.unitprice,
+ grns.itemcode,
+ grns.deliverydate,
+ grns.itemdescription,
+ grns.qtyrecd,
+ grns.quantityinv,
+ grns.stdcostunit,
+ purchorderdetails.glcode,
+ purchorderdetails.shiptref,
+ purchorderdetails.jobref,
+ purchorderdetails.podetailitem,
+ purchorderdetails.assetid,
+ stockmaster.decimalplaces
+ FROM grns INNER JOIN purchorderdetails
+ ON grns.podetailitem=purchorderdetails.podetailitem
+ LEFT JOIN stockmaster ON grns.itemcode=stockmaster.stockid
+ WHERE grns.supplierid ='" . $_SESSION['SuppTrans']->SupplierID . "'
+ AND purchorderdetails.orderno = '" . intval($_GET['ReceivePO']) . "'
+ AND grns.qtyrecd - grns.quantityinv > 0
+ ORDER BY grns.grnno";
+ $GRNResults = DB_query($SQL,$db);
+
+ while ($myrow=DB_fetch_array($GRNResults)){
+
+ if ($myrow['decimalplaces']==''){
+ $myrow['decimalplaces']=2;
+ }
+ $_SESSION['SuppTrans']->Add_GRN_To_Trans($myrow['grnno'],
+ $myrow['podetailitem'],
+ $myrow['itemcode'],
+ $myrow['itemdescription'],
+ $myrow['qtyrecd'],
+ $myrow['quantityinv'],
+ $myrow['qtyrecd'] - $myrow['quantityinv'],
+ $myrow['unitprice'],
+ $myrow['unitprice'],
+ true,
+ $myrow['stdcostunit'],
+ $myrow['shiptref'],
+ $myrow['jobref'],
+ $myrow['glcode'],
+ $myrow['orderno'],
+ $myrow['assetid'],
+ 0,
+ $myrow['decimalplaces'],
+ $myrow['grnbatch']);
}
- $_SESSION['SuppTrans']->Add_GRN_To_Trans($myrow['grnno'],
- $myrow['podetailitem'],
- $myrow['itemcode'],
- $myrow['itemdescription'],
- $myrow['qtyrecd'],
- $myrow['quantityinv'],
- $myrow['qtyrecd'] - $myrow['quantityinv'],
- $myrow['unitprice'],
- $myrow['unitprice'],
- true,
- $myrow['stdcostunit'],
- $myrow['shiptref'],
- $myrow['jobref'],
- $myrow['glcode'],
- $myrow['orderno'],
- $myrow['assetid'],
- 0,
- $myrow['decimalplaces'],
- $myrow['grnbatch']);
- }
- } //end if the order has no controlled items on it
- } //only allow auto receiving of all lines if the PO is authorised
+ } //end if the order has no controlled items on it
+ } //only allow auto receiving of all lines if the PO is authorised
+ } //only allow auto receiving if the user has permission to receive goods
} // Page called with link to receive all the items on a PO
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/* Set the session variables to the posted data from the form if the page has called itself */
if (isset($_POST['ExRate'])){
$_SESSION['SuppTrans']->ExRate = filter_number_format($_POST['ExRate']);
@@ -1902,6 +1880,8 @@
echo '<br />
<div class="centre">
<a href="' . $rootpath . '/SupplierInvoice.php?&SupplierID=' .$_SESSION['SuppTrans']->SupplierID . '">' . _('Enter another Invoice for this Supplier') . '</a>
+ <br />
+ <a href="' . $rootpath . '/Payments.php?&SupplierID=' .$_SESSION['SuppTrans']->SupplierID . '&Amount=' . ($_SESSION['SuppTrans']->OvAmount+$TaxTotal) . '">' . _('Enter payment') . '</a>
</div>';
unset( $_SESSION['SuppTrans']->GRNs);
unset( $_SESSION['SuppTrans']->Shipts);
Modified: trunk/doc/Change.log
===================================================================
--- trunk/doc/Change.log 2012-12-05 08:39:15 UTC (rev 5752)
+++ trunk/doc/Change.log 2012-12-08 01:41:35 UTC (rev 5753)
@@ -1,5 +1,7 @@
webERP Change Log
+8/12/12 Phil: Check user has authority to receive goods before allowing auto receiving
+7/12/12 Phil: SupplierInvoice.php add link to pay invoice after invoice input
5/12/12 Phil: Allow auto receiving of purchase orders and populating of purchase invoice when purchase order is authorised.
5/12/12 Tim: PO_PDFPurchOrder.php fix printing of initiator to show the full name also style changes
4/12/12 Tim: PO_Header.php style mods also initiator reinstated as the userid not the user's realname - realname displayed but not stored in db.
Modified: trunk/includes/session.inc
===================================================================
--- trunk/includes/session.inc 2012-12-05 08:39:15 UTC (rev 5752)
+++ trunk/includes/session.inc 2012-12-08 01:41:35 UTC (rev 5753)
@@ -124,13 +124,6 @@
/*User is logged in so get configuration parameters - save in session*/
include($PathPrefix . 'includes/GetConfig.php');
-/*The page security variable is now retrieved from the database in GetConfig.php and stored in the $SESSION['PageSecurityArray'] array
- * the key for the array is the script name - the script name is retrieved from the basename ($_SERVER['SCRIPT_NAME'])
- */
-if (!isset($PageSecurity)){
-//only hardcoded in the UpgradeDatabase script - so old versions that don't have the scripts.pagesecurity field do not choke
- $PageSecurity = $_SESSION['PageSecurityArray'][basename($_SERVER['SCRIPT_NAME'])];
-}
/*If the Code $Version - held in ConnectDB.inc is > than the Database VersionNumber held in config table then do upgrades */
if (strcmp($Version,$_SESSION['VersionNumber'])>0 AND (basename($_SERVER['SCRIPT_NAME'])!='UpgradeDatabase.php')) {
@@ -265,8 +258,7 @@
-// Now check that the user as logged in has access to the page being called. The $PageSecurity
-// value must be set in the script before header.inc is included. $SecurityGroups is an array of
+// Now check that the user as logged in has access to the page being called. $SecurityGroups is an array of
// arrays defining access for each group of users. These definitions can be modified by a system admin under setup
@@ -279,6 +271,15 @@
exit;
}
+/*The page security variable is now retrieved from the database in GetConfig.php and stored in the $SESSION['PageSecurityArray'] array
+ * the key for the array is the script name - the script name is retrieved from the basename ($_SERVER['SCRIPT_NAME'])
+ */
+if (!isset($PageSecurity)){
+//only hardcoded in the UpgradeDatabase script - so old versions that don't have the scripts.pagesecurity field do not choke
+ $PageSecurity = $_SESSION['PageSecurityArray'][basename($_SERVER['SCRIPT_NAME'])];
+}
+
+
if (!isset($AllowAnyone)){
if ((!in_array($PageSecurity, $_SESSION['AllowedPageSecurityTokens']) OR !isset($PageSecurity))) {
$title = _('Security Permissions Problem');
|