From: <dai...@us...> - 2010-11-21 00:25:59
|
Revision: 4161 http://web-erp.svn.sourceforge.net/web-erp/?rev=4161&view=rev Author: daintree Date: 2010-11-21 00:25:51 +0000 (Sun, 21 Nov 2010) Log Message: ----------- Fixed Asset Module - deprn journal Modified Paths: -------------- trunk/FixedAssetCategories.php trunk/FixedAssetItems.php trunk/FixedAssetJournal.php trunk/GoodsReceived.php trunk/sql/mysql/upgrade3.11.1-4.00.sql Modified: trunk/FixedAssetCategories.php =================================================================== --- trunk/FixedAssetCategories.php 2010-11-20 08:13:47 UTC (rev 4160) +++ trunk/FixedAssetCategories.php 2010-11-21 00:25:51 UTC (rev 4161) @@ -41,6 +41,37 @@ prnMsg(_('The Fixed Asset Category description must be twenty characters or less long'),'error'); } + if ($_POST['CostAct'] == $_SESSION['CompanyRecord']['debtorsact'] + OR $_POST['CostAct'] == $_SESSION['CompanyRecord']['creditorsact'] + OR $_POST['AccumDepnAct'] == $_SESSION['CompanyRecord']['debtorsact'] + OR $_POST['AccumDepnAct'] == $_SESSION['CompanyRecord']['creditorsact'] + OR $_POST['CostAct'] == $_SESSION['CompanyRecord']['grnact'] + OR $_POST['AccumDepnAct'] == $_SESSION['CompanyRecord']['grnact']){ + prnMsg(_('The accounts selected to post cost or accumulated depreciation to cannot be either of the debtors control account, creditors control account or GRN suspense accounts'),'error'); + $InputError =1; + } + /*Make an array of the defined bank accounts */ + $SQL = 'SELECT bankaccounts.accountcode + FROM bankaccounts, + chartmaster + WHERE bankaccounts.accountcode=chartmaster.accountcode'; + $result = DB_query($SQL,$db); + $BankAccounts = array(); + $i=0; + + while ($Act = DB_fetch_row($result)){ + $BankAccounts[$i]= $Act[0]; + $i++; + } + if (in_array($_POST['CostAct'], $BankAccounts)) { + prnMsg( _('The asset cost account selected is a bank account - bank accounts are protected from having any other postings made to them. Select another balance sheet account for the asset cost'),'error'); + $InputError =1; + } + if (in_array($_POST['AccumDepnAct'], $BankAccounts)) { + prnMsg( _('The accumulated depreciation account selected is a bank account - bank accounts are protected from having any other postings made to them. Select another balance sheet account for the asset accumulated depreciation'),'error'); + $InputError =1; + } + if (isset($SelectedCategory) AND $InputError !=1) { /*SelectedCategory could also exist if submit had not been clicked this code Modified: trunk/FixedAssetItems.php =================================================================== --- trunk/FixedAssetItems.php 2010-11-20 08:13:47 UTC (rev 4160) +++ trunk/FixedAssetItems.php 2010-11-21 00:25:51 UTC (rev 4161) @@ -219,7 +219,7 @@ description='" . $_POST['Description'] . "', assetcategoryid='" . $_POST['AssetCategoryID'] . "', assetlocation='" . $_POST['AssetLocation'] . "', - datepurchased='" . $_POST['DatePurchased'] . "', + datepurchased='" . FormatDateForSQL($_POST['DatePurchased']) . "', depntype='" . $_POST['DepnType'] . "', depnrate='" . $_POST['DepnRate'] . "', barcode='" . $_POST['BarCode'] . "', @@ -248,7 +248,7 @@ '" . $_POST['LongDescription'] . "', '" . $_POST['AssetCategoryID'] . "', '" . $_POST['AssetLocation'] . "', - '" . $_POST['DatePurchased'] . "', + '" . FormatDateForSQL($_POST['DatePurchased']) . "', '" . $_POST['DepnType'] . "', '" . $_POST['DepnRate']. "', '" . $_POST['BarCode'] . "', Modified: trunk/FixedAssetJournal.php =================================================================== --- trunk/FixedAssetJournal.php 2010-11-20 08:13:47 UTC (rev 4160) +++ trunk/FixedAssetJournal.php 2010-11-21 00:25:51 UTC (rev 4161) @@ -11,396 +11,220 @@ include('includes/header.inc'); include('includes/SQL_CommonFunctions.inc'); -if (isset($_GET['NewJournal']) and $_GET['NewJournal'] == 'Yes' AND isset($_SESSION['JournalDetail'])){ - unset($_SESSION['JournalDetail']->GLEntries); - unset($_SESSION['JournalDetail']); -} -if (!isset($_SESSION['JournalDetail']) or isset($_POST['update'])){ - $_SESSION['JournalDetail'] = new Journal; +/*Get the last period depreciation (depn is transtype =44) was posted for */ +$result = DB_query('SELECT periods.lastdate_in_period, max(fixedassettrans.periodno) FROM fixedassettrans INNER JOIN periods ON fixedassettrans.periodno=periods.periodno WHERE transtype=44 GROUP BY periods.lastdate_in_period',$db); - /* Make an array of the defined bank accounts - better to make it now than do it each time a line is added - Journals cannot be entered against bank accounts GL postings involving bank accounts must be done using - a receipt or a payment transaction to ensure a bank trans is available for matching off vs statements */ +$LastDepnRun = DB_fetch_row($result); - $SQL = 'SELECT accountcode FROM bankaccounts'; - $result = DB_query($SQL,$db); - $i=0; - while ($Act = DB_fetch_row($result)){ - $_SESSION['JournalDetail']->BankAccounts[$i]= $Act[0]; - $i++; - } +//echo '<BR>LastRun period = ' . $LastDepnRun[1] . ' Last date in period = ' . $LastDepnRun[0]; - /* Get list of assets for journal */ - $sql='SELECT assetmanager.*, - stockcategory.wipact as bsdepn, - stockcategory.adjglact as pldepn, - fixedassetlocations.locationdescription - FROM assetmanager - LEFT JOIN stockmaster - ON assetmanager.stockid=stockmaster.stockid - LEFT JOIN stockcategory - ON stockmaster.categoryid=stockcategory.categoryid - LEFT JOIN fixedassetlocations - ON fixedassetlocations.locationid=assetmanager.location'; - $result=DB_query($sql, $db); - $i=0; - while ($myrow=DB_fetch_array($result)) { - $assetarray[$i]=$myrow; - // Find depreciation type - $typesql='SELECT stockitemproperties.value - FROM stockitemproperties - LEFT JOIN stockcatproperties - ON stockcatproperties.stkcatpropid=stockitemproperties.stkcatpropid - WHERE stockitemproperties.stockid="'.$myrow['stockid'].'" - AND stockcatproperties.label="'._('Depreciation Type').'"'; - $typeresult=DB_query($typesql,$db); - $typerow=DB_fetch_array($typeresult); - $assetarray[$i]['DepreciationType']=$typerow['value']; +$AllowUserEnteredProcessDate = true; - // Find the depreciation rate - $ratesql='SELECT stockitemproperties.value - FROM stockitemproperties - LEFT JOIN stockcatproperties - ON stockcatproperties.stkcatpropid=stockitemproperties.stkcatpropid - WHERE stockitemproperties.stockid="'.$myrow['stockid'].'" - AND stockcatproperties.label="'._('Annual Depreciation Percentage').'"'; - $rateresult=DB_query($ratesql, $db); - $raterow=DB_fetch_array($rateresult); - $assetarray[$i]['DepreciationRate']=$raterow['value']; - - - $bsnamesql='SELECT accountname FROM chartmaster WHERE accountcode="'.$assetarray[$i]['bsdepn'].'"'; - $bsnameresult=DB_query($bsnamesql, $db); - $bsnamerow=DB_fetch_array($bsnameresult); - $assetarray[$i]['bsdepnaccount']=$bsnamerow['accountname']; - $plnamesql='SELECT accountname FROM chartmaster WHERE accountcode="'.$assetarray[$i]['pldepn'].'"'; - $plnameresult=DB_query($plnamesql, $db); - $plnamerow=DB_fetch_array($plnameresult); - $assetarray[$i]['pldepnaccount']=$plnamerow['accountname']; - - /* Need a method to correctly enter the journal date, - * and for it to be available to the depn calculation - Tim - */ - - if (isset($_POST['JournalProcessDate'])) { - $_SESSION['JournalDetail']->JnlDate=$_POST['JournalProcessDate']; - } - if (!Is_Date($_SESSION['JournalDetail']->JnlDate)){ - // Default the date to the last day of the previous month - $_SESSION['JournalDetail']->JnlDate = Date($_SESSION['DefaultDateFormat'],mktime(0,0,0,date('m'),0,date('Y'))); - } - - $NoOfMonths=DateDiff($_SESSION['JournalDetail']->JnlDate,ConvertSQLDate($assetarray[$i]['datepurchased']), 'm'); - if ($assetarray[$i]['DepreciationType']==_('Straight Line')) { - $TotalDepnAmount=round(($NoOfMonths/12)*($assetarray[$i]['DepreciationRate']/100)*$assetarray[$i]['cost'],2); - } else { - $TotalDepnAmount=round(($NoOfMonths/12)*($assetarray[$i]['DepreciationRate']/100)* - ($assetarray[$i]['cost']-$assetarray[$i]['depn']),2); - } - - if (($TotalDepnAmount+$assetarray[$i]['disposalvalue'])>$assetarray[$i]['cost']) { - $TotalDepnAmount=$assetarray[$i]['cost']-$assetarray[$i]['disposalvalue']; - } - $assetarray[$i]['narrative']='Depreciation Journal - '.$assetarray[$i]['stockid']. - ' - '.$assetarray[$i]['serialno'].' - '.$assetarray[$i]['locationdescription']; - - $_SESSION['JournalDetail']->Add_To_GLAnalysis( - -($TotalDepnAmount-$assetarray[$i]['depn']), - $assetarray[$i]['narrative'], - $assetarray[$i]['bsdepn'], - $assetarray[$i]['bsdepnaccount'], - 0, - $assetarray[$i]['id']); - - $_SESSION['JournalDetail']->Add_To_GLAnalysis( - $TotalDepnAmount-$assetarray[$i]['depn'], - $assetarray[$i]['narrative'], - $assetarray[$i]['pldepn'], - $assetarray[$i]['pldepnaccount'], - 0, - $assetarray[$i]['id']); - $i++; +if ($LastDepnRun[1]==0 AND $LastDepnRun[0]==NULL) { //then depn has never been run yet? + + /*in this case default depreciation calc to the last day of last month - and allow user to select a period */ + if (!isset($_POST['ProcessDate'])) { + $_POST['ProcessDate'] = Date($_SESSION['DefaultDateFormat'],mktime(0,0,0,date('m'),0,date('Y'))); } + +} else { //depn calc has been run previously + $AllowUserEnteredProcessDate = false; + $_POST['ProcessDate'] = DateAdd(ConvertSQLDate($LastDepnRun[0]),'m',1); } +$PeriodNo = GetPeriod($_POST['ProcessDate'],$db); -if (isset($_POST['JournalProcessDate'])){ - $_SESSION['JournalDetail']->JnlDate=$_POST['JournalProcessDate']; +/* Get list of assets for journal */ +$sql='SELECT fixedassets.assetid, + fixedassets.description, + fixedassets.cost, + fixedassets.accumdepn, + fixedassets.depntype, + fixedassets.depnrate, + fixedassetcategories.accumdepnact AS bsdepn, + fixedassetcategories.depnact AS pldepn, + fixedassetcategories.categorydescription + FROM fixedassets + INNER JOIN fixedassetcategories + ON fixedassets.assetcategoryid=fixedassetcategories.categoryid + ORDER BY assetcategoryid, assetid'; +$result=DB_query($sql, $db); - if (!Is_Date($_POST['JournalProcessDate'])){ - prnMsg(_('The date entered was not valid please enter the date to process the journal in the format'). $_SESSION['DefaultDateFormat'],'warn'); - $_POST['CommitBatch']='Do not do it the date is wrong'; - } +if (isset($_POST['CommitDepreciation'])){ + $result = DB_Txn_Begin($db); + $TransNo = GetNextTransNo(44, $db); + } -if (isset($_POST['JournalType'])){ - $_SESSION['JournalDetail']->JournalType = $_POST['JournalType']; -} -if (isset($_POST['CommitBatch']) and $_POST['CommitBatch']==_('Accept and Process Journal')){ +echo '<p></p><table>'; +$Heading = '<tr><th>' . _('Asset ID') . '</th> + <th>' . _('Description') . '</th> + <th>' . _('Cost') . '</th> + <th>' . _('Accum Depn') . '</th> + <th>' . _('B/fwd Book Value') . '</th> + <th>'. _('Depn Type') . '</th> + <th>'. _('Depn Rate') . '</th> + <th>' . _('New Depn') . '</th> + </tr>'; +echo $Heading; - /* once the GL analysis of the journal is entered - process all the data in the session cookie into the DB - A GL entry is created for each GL entry -*/ +$AssetCategoryDescription ='0'; - $PeriodNo = GetPeriod($_SESSION['JournalDetail']->JnlDate,$db); +$TotalCost =0; +$TotalAccumDepn=0; +$TotalDepn = 0; +$RowCounter = 0; +$k=0; - /*Start a transaction to do the whole lot inside */ - $result = DB_Txn_Begin($db); - - $TransNo = GetNextTransNo( 0, $db); - $BSorPL=1; // Balance sheet or P&L indicator - - foreach ($_SESSION['JournalDetail']->GLEntries as $JournalItem) { - $odd=$BSorPL%2; - if ($odd==0) { - $sql='UPDATE assetmanager SET depn=depn+"'.$JournalItem->Amount.'" WHERE id="'.$JournalItem->assetid.'"'; - $ErrMsg = _('Cannot update the asset manager for this amount because'); - $DbgMsg = _('The SQL that failed to update the asset manger record was'); - $result=DB_query($sql, $db,$ErrMsg,$DbgMsg,true); +while ($myrow=DB_fetch_array($result)) { + if ($AssetCategoryDescription != $myrow['categorydescription'] OR $AssetCategoryDescription =='0'){ + if ($AssetCategoryDescription !='0'){ //then print totals + echo '<tr><th colspan=2 align="right">' . _('Total for') . ' ' . $AssetCategoryDescription . ' </th> + <th class="number">' . number_format($TotalCategoryCost,2) . '</th> + <th class="number">' . number_format($TotalCategoryAccumDepn,2) . '</th> + <th class="number">' . number_format(($TotalCategoryCost-$TotalCategoryAccumDepn),2) . '</th> + <th colspan=2></th> + <th class="number">' . number_format($TotalCategoryDepn,2) . '</th> + </tr>'; } - $BSorPL++; + echo '<tr><th colspan=8 align="left">' . $myrow['categorydescription'] . '</th></tr>'; + $AssetCategoryDescription = $myrow['categorydescription']; + $TotalCategoryCost = 0; + $TotalCategoryAccumDepn =0; + $TotalCategoryDepn = 0; } - - foreach ($_SESSION['JournalDetail']->GLEntries as $JournalItem) { + $BookValueBfwd = $myrow['cost'] - $myrow['accumdepn']; + if ($myrow['depntype']==0){ //striaght line depreciation + $DepreciationType = _('SL'); + $NewDepreciation = $myrow['cost'] * $myrow['depnrate']/100/12; + if ($NewDepreciation > $BookValueBfwd){ + $NewDepreciation = $BookValueBfwd; + } + } else { //Diminishing value depreciation + $DepreciationType = _('DV'); + $NewDepreciation = $BookValueBfwd * $myrow['depnrate']/100/12; + } + $RowCounter++; + if ($RowCounter ==15){ + echo $Heading; + $RowCounter =0; + } + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k++; + } + echo '<td>' . $myrow['assetid'] . '</td> + <td>' . $myrow['description'] . '</td> + <td class="number">' . number_format($myrow['cost'],2) . '</td> + <td class="number">' . number_format($myrow['accumdepn'],2) . '</td> + <td class="number">' . number_format($myrow['cost']-$myrow['accumdepn'],2) . '</td> + <td align="center">' . $DepreciationType . '</td> + <td class="number">' . $myrow['depnrate'] . '</td> + <td class="number">' . $NewDepreciation . '</td> + </tr>'; + $TotalCategoryCost +=$myrow['cost']; + $TotalCategoryAccumDepn +=$myrow['accumdepn']; + $TotalCategoryDepn +=$NewDepreciation; + $TotalCost +=$myrow['cost']; + $TotalAccumDepn +=$myrow['accumdepn']; + $TotalDepn +=$NewDepreciation; + + if (isset($_POST['CommitDepreciation']) AND $NewDepreciation !=0){ + //debit depreciation expense $SQL = "INSERT INTO gltrans (type, - typeno, - trandate, - periodno, - account, - narrative, - amount, - tag) "; - $SQL= $SQL . "VALUES (0, - '" . $TransNo . "', - '" . FormatDateForSQL($_SESSION['JournalDetail']->JnlDate) . "', - '" . $PeriodNo . "', - '" . $JournalItem->GLCode . "', - '" . $JournalItem->Narrative . "', - '" . $JournalItem->Amount ."', - '" . $JournalItem->tag."' - )"; - $ErrMsg = _('Cannot insert a GL entry for the journal line because'); + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (44, + '" . $TransNo . "', + '" . FormatDateForSQL($_POST['ProcessDate']) . "', + '" . $PeriodNo . "', + '" . $myrow['depnact'] . "', + '" . $myrow['assetid'] . "', + '" . $NewDepreciation ."')"; + $ErrMsg = _('Cannot insert a depreciation GL entry for the depreciation because'); $DbgMsg = _('The SQL that failed to insert the GL Trans record was'); $result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); - } + $SQL = "INSERT INTO gltrans (type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (44, + '" . $TransNo . "', + '" . FormatDateForSQL($_POST['ProcessDate']) . "', + '" . $PeriodNo . "', + '" . $myrow['accumdepnact'] . "', + '" . $myrow['assetid'] . "', + '" . -$NewDepreciation ."')"; + $result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); + + //insert the fixedassettrans record + $SQL = "INSERT INTO fixedassettrans (assetid, + transtype, + transno, + transdate, + periodno, + inputdate, + cost, + depn) + VALUES ('" . $myrow['assetid'] . "', + '44', + '" . $TransNo . "', + '" . FormatDateForSQL($_POST['ProcessDate']) . "', + '" . $PeriodNo . "', + '" . Date('Y-m-d') . "', + '0', + '" . $NewDepreciation . "')"; + $ErrMsg = _('Cannot insert a fixed asset transaction entry for the depreciation because'); + $DbgMsg = _('The SQL that failed to insert the fixed asset transaction record was'); + $result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); + } //end if Committing the depreciation to DB +} //end loop around the assets to calculate depreciation for +echo '<tr><th colspan=2 align="right">' . _('Total for') . ' ' . $AssetCategoryDescription . ' </th> + <th class="number">' . number_format($TotalCategoryCost,2) . '</th> + <th class="number">' . number_format($TotalCategoryAccumDepn,2) . '</th> + <th class="number">' . number_format(($TotalCategoryCost-$TotalCategoryAccumDepn),2) . '</th> + <th colspan=2></th> + <th class="number">' . number_format($TotalCategoryDepn,2) . '</th> + </tr>'; +echo '<tr><th colspan=2 align="right">' . _('GRAND Total') . ' </th> + <th class="number">' . number_format($TotalCost,2) . '</th> + <th class="number">' . number_format($TotalAccumDepn,2) . '</th> + <th class="number">' . number_format(($TotalCost-$TotalAccumDepn),2) . '</th> + <th colspan=2></th> + <th class="number">' . number_format($TotalDepn,2) . '</th> + </tr>'; +echo '</table><hr><p></p>'; - $ErrMsg = _('Cannot commit the changes'); - $result= DB_Txn_Begin($db); - - prnMsg(_('Journal').' ' . $TransNo . ' '._('has been successfully entered'),'success'); - - unset($_POST['JournalProcessDate']); - unset($_POST['JournalType']); - unset($_SESSION['JournalDetail']->GLEntries); - unset($_SESSION['JournalDetail']); - - /*Set up a newy in case user wishes to enter another */ - echo "<br><a href='index.php" . '?' . SID . "'>"._('Return to main menu').'</a>'; +if (isset($_POST['CommitDepreciation'])){ + $result = DB_Txn_Commit($db); + prnMsg(_('Depreciation') . ' ' . $TransNo . ' ' . _('has been successfully entered'),'success'); + unset($_POST['ProcessDate']); + echo '<br><a href="index.php' . '?' . SID . '">' ._('Return to main menu').'</a>'; /*And post the journal too */ include ('includes/GLPostings.inc'); - include ('includes/footer.inc'); - exit; - -} elseif (isset($_GET['Delete'])){ - - /* User hit delete the line from the journal */ - $_SESSION['JournalDetail']->Remove_GLEntry($_GET['Delete']); - -} elseif (isset($_POST['Process']) and $_POST['Process']==_('Accept')){ //user hit submit a new GL Analysis line into the journal - if($_POST['GLCode']!='') - { - $extract = explode(' - ',$_POST['GLCode']); - $_POST['GLCode'] = $extract[0]; +} else { + echo '<form action=' . $_SERVER['PHP_SELF'] . '?' . SID . ' method=post name="form">'; + echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + echo '<p></p>'; + echo '<table class=selection width=30%><tr></tr><tr>'; + if (AllowUserEnteredProcessDate){ + echo '<td>'._('Date to Process Depreciation'). ':</td> + <td><input type="text" class="date" alt="' .$_SESSION['DefaultDateFormat']. '" name="ProcessDate" maxlength=10 size=11 value="' . $_POST['ProcessDate'] . '"></td>'; } - if($_POST['Debit']>0) - { - $_POST['GLAmount'] = $_POST['Debit']; - } - elseif($_POST['Credit']>0) - { - $_POST['GLAmount'] = '-' . $_POST['Credit']; - } - if ($_POST['GLManualCode'] != '' AND is_numeric($_POST['GLManualCode'])){ - // If a manual code was entered need to check it exists and isnt a bank account - $AllowThisPosting = true; //by default - if ($_SESSION['ProhibitJournalsToControlAccounts'] == 1){ - if ($_SESSION['CompanyRecord']['gllink_debtors'] == '1' AND $_POST['GLManualCode'] == $_SESSION['CompanyRecord']['debtorsact']){ - prnMsg(_('GL Journals involving the debtors control account cannot be entered. The general ledger debtors ledger (AR) integration is enabled so control accounts are automatically maintained by webERP. This setting can be disabled in System Configuration'),'warn'); - $AllowThisPosting = false; - } - if ($_SESSION['CompanyRecord']['gllink_creditors'] == '1' AND $_POST['GLManualCode'] == $_SESSION['CompanyRecord']['creditorsact']){ - prnMsg(_('GL Journals involving the creditors control account cannot be entered. The general ledger creditors ledger (AP) integration is enabled so control accounts are automatically maintained by webERP. This setting can be disabled in System Configuration'),'warn'); - $AllowThisPosting = false; - } - } - if (in_array($_POST['GLManualCode'], $_SESSION['JournalDetail']->BankAccounts)) { - prnMsg(_('GL Journals involving a bank account cannot be entered') . '. ' . _('Bank account general ledger entries must be entered by either a bank account receipt or a bank account payment'),'info'); - $AllowThisPosting = false; - } - - if ($AllowThisPosting) { - $SQL = 'SELECT accountname - FROM chartmaster - WHERE accountcode=' . $_POST['GLManualCode']; - $Result=DB_query($SQL,$db); - - if (DB_num_rows($Result)==0){ - prnMsg(_('The manual GL code entered does not exist in the database') . ' - ' . _('so this GL analysis item could not be added'),'warn'); - unset($_POST['GLManualCode']); - } else { - $myrow = DB_fetch_array($Result); - $_SESSION['JournalDetail']->add_to_glanalysis($_POST['GLAmount'], $_POST['GLNarrative'], $_POST['GLManualCode'], $myrow['accountname'], $_POST['tag']); - } - } - } else { - $AllowThisPosting =true; //by default - if ($_SESSION['ProhibitJournalsToControlAccounts'] == 1){ - if ($_SESSION['CompanyRecord']['gllink_debtors'] == '1' AND $_POST['GLCode'] == $_SESSION['CompanyRecord']['debtorsact']){ - prnMsg(_('GL Journals involving the debtors control account cannot be entered. The general ledger debtors ledger (AR) integration is enabled so control accounts are automatically maintained by webERP. This setting can be disabled in System Configuration'),'warn'); - $AllowThisPosting = false; - } - if ($_SESSION['CompanyRecord']['gllink_creditors'] == '1' AND $_POST['GLCode'] == $_SESSION['CompanyRecord']['creditorsact']){ - prnMsg(_('GL Journals involving the creditors control account cannot be entered. The general ledger creditors ledger (AP) integration is enabled so control accounts are automatically maintained by webERP. This setting can be disabled in System Configuration'),'warn'); - $AllowThisPosting = false; - } - } - - if (in_array($_POST['GLCode'], $_SESSION['JournalDetail']->BankAccounts)) { - prnMsg(_('GL Journals involving a bank account cannot be entered') . '. ' . _('Bank account general ledger entries must be entered by either a bank account receipt or a bank account payment'),'warn'); - $AllowThisPosting = false; - } - - if ($AllowThisPosting){ - if (!isset($_POST['GLAmount'])) { - $_POST['GLAmount']=0; - } - $SQL = 'SELECT accountname FROM chartmaster WHERE accountcode=' . $_POST['GLCode']; - $Result=DB_query($SQL,$db); - $myrow=DB_fetch_array($Result); - $_SESSION['JournalDetail']->add_to_glanalysis($_POST['GLAmount'], $_POST['GLNarrative'], $_POST['GLCode'], $myrow['accountname'], $_POST['tag']); - } - } - - /*Make sure the same receipt is not double processed by a page refresh */ - $Cancel = 1; - unset($_POST['Credit']); - unset($_POST['Debit']); - unset($_POST['tag']); - unset($_POST['GLManualCode']); - unset($_POST['GLNarrative']); + echo '<td><input type="submit" name="CommitDepreciation" value="'._('Commit Depreciation').'">'; + echo '</tr></table><br>'; + echo '</form>'; } - -if (isset($Cancel)){ - unset($_POST['Credit']); - unset($_POST['Debit']); - unset($_POST['GLAmount']); - unset($_POST['GLCode']); - unset($_POST['tag']); - unset($_POST['GLManualCode']); -} - -// set up the form whatever -/* -if (!isset($_SESSION['JournalDetail']->JnlDate)){ - $_POST['JournalProcessDate']= Date($_SESSION['DefaultDateFormat']); - $_SESSION['JournalDetail']->JnlDate = $_POST['JournalProcessDate']; -} -*/ - -echo '<form action=' . $_SERVER['PHP_SELF'] . '?' . SID . ' method=post name="form">'; -echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; - -echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Search') . '" alt="">' . ' ' . $title.'</p>'; - -// A new table in the first column of the main table - -echo '<table class=selection width=30%><tr><td>'._('Date to Process Journal').":</td> - <td><input type='text' class='date' alt='".$_SESSION['DefaultDateFormat']. - "' name='JournalProcessDate' maxlength=10 size=11 value='" . - $_SESSION['JournalDetail']->JnlDate . "'></td>"; -echo '<td><input type="submit" name="update" value="'._('Update Journal').'">'; -echo '<input type=hidden name=JournalType value=Normal>'; -echo '</tr> - </table><br>'; -/* close off the table in the first column */ - - -echo "<table class=selection width=85%> - <tr> - <th>"._('GL Tag')."</th> - <th>"._('GL Account')."</th> - <th>"._('Debit')."</th> - <th>"._('Credit')."</th> - <th>"._('Narrative').'</th></tr>'; - -$debittotal=0; -$credittotal=0; -$j=0; - -foreach ($_SESSION['JournalDetail']->GLEntries as $JournalItem) { - if ($j==1) { - echo '<tr class="OddTableRows">'; - $j=0; - } else { - echo '<tr class="EvenTableRows">'; - $j++; - } - $sql='SELECT tagdescription - FROM tags - WHERE tagref='.$JournalItem->tag; - $result=DB_query($sql, $db); - $myrow=DB_fetch_row($result); - if ($JournalItem->tag==0) { - $tagdescription='None'; - } else { - $tagdescription=$myrow[0]; - } - echo "<td>" . $JournalItem->tag . ' - ' . $tagdescription . "</td>"; - echo "<td>" . $JournalItem->GLCode . ' - ' . $JournalItem->GLActName . "</td>"; - if($JournalItem->Amount>0) { - echo "<td class='number'>" . number_format($JournalItem->Amount,2) . '</td><td></td>'; - $debittotal=$debittotal+$JournalItem->Amount; - } elseif($JournalItem->Amount<0) { - $credit=(-1 * $JournalItem->Amount); - echo "<td></td><td class='number'>" . number_format($credit,2) . '</td>'; - $credittotal=$credittotal+$credit; - } - - echo '<td>' . $JournalItem->Narrative . "</td> - <td><a href='" . $_SERVER['PHP_SELF'] . '?' . SID . '&Delete=' . $JournalItem->ID . "'>"._('Delete').'</a></td></tr>'; -} - -echo '<tr class="EvenTableRows"><td></td> - <td align=right><b> Total </b></td> - <td align=right class="number"><b>' . number_format($debittotal,2) . '</b></td> - <td align=right class="number"><b>' . number_format($credittotal,2) . '</b></td>'; -if ($debittotal!=$credittotal) { - echo '<td align=center style="background-color: #fddbdb"><b>Required to balance - ' . - number_format(abs($debittotal-$credittotal),2); -} -if ($debittotal>$credittotal) { - echo ' Credit'; -} else if ($debittotal<$credittotal) { - echo ' Debit'; -} - -echo '</b></td></tr></table>'; - -if (ABS($_SESSION['JournalDetail']->JournalTotal)<0.001 AND $_SESSION['JournalDetail']->GLItemCounter > 0){ - echo "<br><br><div class='centre'><input type=submit name='CommitBatch' value='"._('Accept and Process Journal')."'></div>"; -} elseif(count($_SESSION['JournalDetail']->GLEntries)>0) { - echo '<br><br>'; - prnMsg(_('The journal must balance ie debits equal to credits before it can be processed'),'warn'); -} - -if (!isset($_GET['NewJournal']) or $_GET['NewJournal']=='') { - echo "<script>defaultControl(document.form.GLManualCode);</script>"; -} else { - echo "<script>defaultControl(document.form.JournalProcessDate);</script>"; -} - -echo '</form>'; include('includes/footer.inc'); ?> \ No newline at end of file Modified: trunk/GoodsReceived.php =================================================================== --- trunk/GoodsReceived.php 2010-11-20 08:13:47 UTC (rev 4160) +++ trunk/GoodsReceived.php 2010-11-21 00:25:51 UTC (rev 4161) @@ -23,7 +23,7 @@ /* This page can only be called with a purchase order number for invoicing*/ echo '<div class="centre"><a href= "' . $rootpath . '/PO_SelectOSPurchOrder.php?' . SID . '">'. _('Select a purchase order to receive').'</a></div>'; - echo '<br>'. _('This page can only be opened if a purchase order has been selected') . '. ' . _('Please select a purchase order first'); + echo '<br>'. _('This page can only be opened if a purchase order has been selected. Please select a purchase order first'); include ('includes/footer.inc'); exit; } elseif (isset($_GET['PONumber']) AND !isset($_POST['Update'])) { @@ -45,10 +45,10 @@ } } -$statussql="SELECT status FROM purchorders WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; -$statusresult=DB_query($statussql, $db); -$mystatusrow=DB_fetch_array($statusresult); -$Status=$mystatusrow['status']; +$StatusSQL="SELECT status FROM purchorders WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; +$StatusResult=DB_query($StatusSQL, $db); +$StatusRow=DB_fetch_array($StatusResult); +$Status=$StatusRow['status']; if ($Status != PurchOrder::STATUS_PRINTED) { prnMsg( _('Purchase orders must have a status of Printed before they can be received').'.<br>'. @@ -79,11 +79,11 @@ echo '<table cellpadding=2 class=selection> <tr><th>' . _('Item Code') . '</th> - <th>' . _('Description') . '</th> - <th>' . _('Quantity') . '<br>' . _('Ordered') . '</th> - <th>' . _('Units') . '</th> - <th>' . _('Already Received') . '</th> - <th>' . _('This Delivery') . '<br>' . _('Quantity') . '</th>'; + <th>' . _('Description') . '</th> + <th>' . _('Quantity') . '<br>' . _('Ordered') . '</th> + <th>' . _('Units') . '</th> + <th>' . _('Already Received') . '</th> + <th>' . _('This Delivery') . '<br>' . _('Quantity') . '</th>'; if ($_SESSION['ShowValueOnGRN']==1) { echo '<th>' . _('Price') . '</th><th>' . _('Total Value') . '<br>' . _('Received') . '</th>'; @@ -126,29 +126,29 @@ $DisplayLineTotal = number_format($LineTotal,2); $DisplayPrice = number_format($LnItm->Price,2); - $uomsql="SELECT unitsofmeasure.unitname, - conversionfactor, - suppliersuom, - max(effectivefrom) - FROM purchdata - LEFT JOIN unitsofmeasure - ON purchdata.suppliersuom=unitsofmeasure.unitid - WHERE supplierno='".$_SESSION['PO']->SupplierID."' - AND stockid='".$LnItm->StockID."' - GROUP BY unitsofmeasure.unitname"; - - $uomresult=DB_query($uomsql, $db); - if (DB_num_rows($uomresult)>0) { - $uomrow=DB_fetch_array($uomresult); - if (strlen($uomrow['unitname'])>0) { - $uom=$uomrow['unitname']; + $UomSQL="SELECT unitsofmeasure.unitname, + conversionfactor, + suppliersuom, + max(effectivefrom) + FROM purchdata + LEFT JOIN unitsofmeasure + ON purchdata.suppliersuom=unitsofmeasure.unitid + WHERE supplierno='".$_SESSION['PO']->SupplierID."' + AND stockid='".$LnItm->StockID."' + GROUP BY unitsofmeasure.unitname"; + + $UomResult=DB_query($UomSQL, $db); + if (DB_num_rows($UomResult)>0) { + $UomRow=DB_fetch_array($UomResult); + if (strlen($UomRow['unitname'])>0) { + $Uom=$UomRow['unitname']; } else { - $uom=$LnItm->Units; + $Uom=$LnItm->Units; } - $conversionfactor=$uomrow['conversionfactor']; + $ConversionFactor=$UomRow['conversionfactor']; } else { - $uom=$LnItm->Units; - $conversionfactor=1; + $Uom=$LnItm->Units; + $ConversionFactor=1; } //Now Display LineItem @@ -188,14 +188,13 @@ $DisplayTotal = number_format($_SESSION['PO']->total,2); if ($_SESSION['ShowValueOnGRN']==1) { echo '<tr><td colspan=7 class=number><b>' . _('Total value of goods received'). '</b></td> - <td class=number><b>'. $DisplayTotal. '</b></td> - </tr></table>'; + <td class=number><b>'. $DisplayTotal. '</b></td> + </tr></table>'; } else { echo '</table>'; } }//If count(LineItems) > 0 - $SomethingReceived = 0; if (count($_SESSION['PO']->LineItems)>0){ foreach ($_SESSION['PO']->LineItems as $OrderLine) { @@ -225,19 +224,18 @@ if ($OrderLine->ReceiveQty < 0 AND $_SESSION['ProhibitNegativeStock']==1){ $SQL = "SELECT locstock.quantity FROM - locstock WHERE locstock.stockid='" . $OrderLine->StockID . "' - AND loccode= '" . $_SESSION['PO']->Location . "'"; + locstock WHERE locstock.stockid='" . $OrderLine->StockID . "' + AND loccode= '" . $_SESSION['PO']->Location . "'"; $CheckNegResult = DB_query($SQL,$db); $CheckNegRow = DB_fetch_row($CheckNegResult); if ($CheckNegRow[0]+$OrderLine->ReceiveQty<0){ $NegativesFound=true; prnMsg(_('Receiving a negative quantity that results in negative stock is prohibited by the parameter settings. This delivery of stock cannot be processed until the stock of the item is corrected.'),'error',$OrderLine->StockID . ' Cannot Go Negative'); } - } + } /*end if ReceiveQty negative and not allowed negative stock */ + } /* end loop around the items received */ +} /* end if there are lines received */ - } -} - if ($SomethingReceived==0 AND isset($_POST['ProcessGoodsReceived'])){ /*Then dont bother proceeding cos nothing to do ! */ prnMsg(_('There is nothing to process') . '. ' . _('Please enter valid quantities greater than zero'),'warn'); @@ -272,16 +270,16 @@ /*Now need to check that the order details are the same as they were when they were read into the Items array. If they've changed then someone else must have altered them */ // Otherwise if you try to fullfill item quantities separately will give error. $SQL = "SELECT itemcode, - glcode, - quantityord, - quantityrecd, - qtyinvoiced, - shiptref, - jobref - FROM purchorderdetails - WHERE orderno='" . (int) $_SESSION['PO']->OrderNo . "' - AND completed=0 - ORDER BY podetailitem"; + glcode, + quantityord, + quantityrecd, + qtyinvoiced, + shiptref, + jobref + FROM purchorderdetails + WHERE orderno='" . (int) $_SESSION['PO']->OrderNo . "' + AND completed=0 + ORDER BY podetailitem"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Could not check that the details of the purchase order had not been changed by another user because'). ':'; $DbgMsg = _('The following SQL to retrieve the purchase order details was used'); @@ -422,22 +420,22 @@ /*Need to insert a GRN item */ $SQL = "INSERT INTO grns (grnbatch, - podetailitem, - itemcode, - itemdescription, - deliverydate, - qtyrecd, - supplierid, - stdcostunit) - VALUES ('" . $GRN . "', - '" . $OrderLine->PODetailRec . "', - '" . $OrderLine->StockID . "', - '" . $OrderLine->ItemDescription . "', - '" . $_POST['DefaultReceivedDate'] . "', - '" . $OrderLine->ReceiveQty . "', - '" . $_SESSION['PO']->SupplierID . "', - '" . $CurrentStandardCost *$OrderLine->ConversionFactor. "')"; - + podetailitem, + itemcode, + itemdescription, + deliverydate, + qtyrecd, + supplierid, + stdcostunit) + VALUES ('" . $GRN . "', + '" . $OrderLine->PODetailRec . "', + '" . $OrderLine->StockID . "', + '" . $OrderLine->ItemDescription . "', + '" . $_POST['DefaultReceivedDate'] . "', + '" . $OrderLine->ReceiveQty . "', + '" . $_SESSION['PO']->SupplierID . "', + '" . $CurrentStandardCost *$OrderLine->ConversionFactor. "')"; + $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); @@ -448,10 +446,10 @@ /* 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']->Location . "'"; - + FROM locstock + WHERE locstock.stockid='" . $OrderLine->StockID . "' + AND loccode= '" . $_SESSION['PO']->Location . "'"; + $Result = DB_query($SQL, $db); if (DB_num_rows($Result)==1){ $LocQtyRow = DB_fetch_row($Result); @@ -462,23 +460,23 @@ } $sql="SELECT conversionfactor - FROM purchdata - WHERE supplierno='".$_SESSION['PO']->SupplierID."' - AND stockid='".$OrderLine->StockID."'"; + FROM purchdata + WHERE supplierno='".$_SESSION['PO']->SupplierID."' + AND stockid='".$OrderLine->StockID."'"; $result=DB_query($sql, $db); if (DB_num_rows($result)>0) { $myrow=DB_fetch_array($result); - $conversionfactor=$myrow['conversionfactor']; + $ConversionFactor=$myrow['conversionfactor']; } else { - $conversionfactor=1; + $ConversionFactor=1; } - $OrderLine->ReceiveQty=$OrderLine->ReceiveQty*$conversionfactor; + $OrderLine->ReceiveQty=$OrderLine->ReceiveQty*$ConversionFactor; $SQL = "UPDATE locstock - SET quantity = locstock.quantity + '" . $OrderLine->ReceiveQty . "' - WHERE locstock.stockid = '" . $OrderLine->StockID . "' - AND loccode = '" . $_SESSION['PO']->Location . "'"; - + SET quantity = locstock.quantity + '" . $OrderLine->ReceiveQty . "' + WHERE locstock.stockid = '" . $OrderLine->StockID . "' + AND loccode = '" . $_SESSION['PO']->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); @@ -487,30 +485,30 @@ /* If its a stock item still .... 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']->Location . "', - '" . $_POST['DefaultReceivedDate'] . "', - '" . $LocalCurrencyPrice / $conversionfactor . "', - '" . $PeriodNo . "', - '" . $_SESSION['PO']->SupplierID . " (" . $_SESSION['PO']->SupplierName . ") - " .$_SESSION['PO']->OrderNo . "', - '" . $OrderLine->ReceiveQty . "', - '" . $_SESSION['PO']->LineItems[$OrderLine->LineNo]->StandardCost . "', - '" . ($QtyOnHandPrior + $OrderLine->ReceiveQty) . "' - )"; - + type, + transno, + loccode, + trandate, + price, + prd, + reference, + qty, + standardcost, + newqoh) + VALUES ( + '" . $OrderLine->StockID . "', + 25, + '" . $GRN . "', + '" . $_SESSION['PO']->Location . "', + '" . $_POST['DefaultReceivedDate'] . "', + '" . $LocalCurrencyPrice / $ConversionFactor . "', + '" . $PeriodNo . "', + '" . $_SESSION['PO']->SupplierID . " (" . $_SESSION['PO']->SupplierName . ") - " .$_SESSION['PO']->OrderNo . "', + '" . $OrderLine->ReceiveQty . "', + '" . $_SESSION['PO']->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); @@ -526,9 +524,9 @@ The StockSerialMoves as well */ //need to test if the controlled item exists first already $SQL = "SELECT COUNT(*) FROM stockserialitems - WHERE stockid='" . $OrderLine->StockID . "' - AND loccode = '" . $_SESSION['PO']->Location . "' - AND serialno = '" . $Item->BundleRef . "'"; + WHERE stockid='" . $OrderLine->StockID . "' + AND loccode = '" . $_SESSION['PO']->Location . "' + AND serialno = '" . $Item->BundleRef . "'"; $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Could not check if a batch or lot stock item already exists because'); $DbgMsg = _('The following SQL to test for an already existing controlled but not serialised stock item was used'); $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true); @@ -545,47 +543,23 @@ AND serialno = '" . $Item->BundleRef . "'"; } else { $SQL = "INSERT INTO stockserialitems (stockid, - loccode, - serialno, - qualitytext, - quantity) - VALUES ('" . $OrderLine->StockID . "', - '" . $_SESSION['PO']->Location . "', - '" . $Item->BundleRef . "', - '', - '" . $Item->BundleQty . "')"; + loccode, + serialno, + qualitytext, + quantity) + VALUES ('" . $OrderLine->StockID . "', + '" . $_SESSION['PO']->Location . "', + '" . $Item->BundleRef . "', + '', + '" . $Item->BundleQty . "')"; } $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be inserted because'); $DbgMsg = _('The following SQL to insert the serial stock item records was used'); $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true); - /*Update fixed asset details */ - $sql="SELECT stocktype - FROM stockcategory - LEFT JOIN stockmaster - ON stockcategory.categoryid=stockmaster.categoryid - WHERE stockmaster.stockid='".$OrderLine->StockID."'"; - $result=DB_query($sql, $db); - $myrow=DB_fetch_array($result); - if ($myrow['stocktype']=='A') { - $SQL = "INSERT INTO assetmanager - VALUES ( - NULL, - '" . $OrderLine->StockID . "', - '" . $Item->BundleRef . "', - '', - '".$Item->BundleQty*$OrderLine->Price."', - 0, - '". $_POST['DefaultReceivedDate']."', - 0)"; - $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be inserted because'); - $DbgMsg = _('The following SQL to insert the serial stock item records was used'); - $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true); - } + /* end of handle stockserialitems records */ - /** end of handle stockserialitems records */ - /** now insert the serial stock movement **/ $SQL = "INSERT INTO stockserialmoves (stockmoveno, stockid, @@ -611,23 +585,23 @@ /*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 . "', - '" . $_POST['DefaultReceivedDate'] . "', - '" . $PeriodNo . "', - '" . $OrderLine->GLCode . "', - 'PO: " . $_SESSION['PO']->OrderNo . " " . $_SESSION['PO']->SupplierID . " - " . $OrderLine->StockID - . " - " . $OrderLine->ItemDescription . " x " . $OrderLine->ReceiveQty . " @ " . - number_format($CurrentStandardCost,2) . "', - '" . $CurrentStandardCost * $OrderLine->ReceiveQty . "' - )"; + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES ( + 25, + '" . $GRN . "', + '" . $_POST['DefaultReceivedDate'] . "', + '" . $PeriodNo . "', + '" . $OrderLine->GLCode . "', + 'PO: " . $_SESSION['PO']->OrderNo . " " . $_SESSION['PO']->SupplierID . " - " . $OrderLine->StockID + . " - " . $OrderLine->ItemDescription . " x " . $OrderLine->ReceiveQty . " @ " . + number_format($CurrentStandardCost,2) . "', + '" . $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'); @@ -635,25 +609,24 @@ /* 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 . "', - '" . $_POST['DefaultReceivedDate'] . "', - '" . $PeriodNo . "', - '" . $_SESSION['CompanyRecord']['grnact'] . "', - '" . _('PO') . ': ' . $_SESSION['PO']->OrderNo . ' ' . $_SESSION['PO']->SupplierID . ' - ' . - $OrderLine->StockID . ' - ' . $OrderLine->ItemDescription . ' x ' . - $OrderLine->ReceiveQty . ' @ ' . number_format($UnitCost,2) . "', - '" . -$UnitCost * $OrderLine->ReceiveQty . "' - )"; + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (25, + '" . $GRN . "', + '" . $_POST['DefaultReceivedDate'] . "', + '" . $PeriodNo . "', + '" . $_SESSION['CompanyRecord']['grnact'] . "', + '" . _('PO') . ': ' . $_SESSION['PO']->OrderNo . ' ' . $_SESSION['PO']->SupplierID . ' - ' . + $OrderLine->StockID . ' - ' . $OrderLine->ItemDescription . ' x ' . + $OrderLine->ReceiveQty . ' @ ' . number_format($UnitCost,2) . "', + '" . -$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'); @@ -662,27 +635,27 @@ } /* end of if GL and stock integrated and standard cost !=0 */ } /*Quantity received is != 0 */ } /*end of OrderLine loop */ - $completedsql="SELECT SUM(completed) as completedlines, - COUNT(podetailitem) as alllines - FROM purchorderdetails - WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; - $completedresult=DB_query($completedsql,$db); - $mycompletedrow=DB_fetch_array($completedresult); - $status=$mycompletedrow['alllines']-$mycompletedrow['completedlines']; + $CompletedSQL="SELECT SUM(completed) as completedlines, + COUNT(podetailitem) as alllines + FROM purchorderdetails + WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; + $CompletedResult=DB_query($CompletedSQL,$db); + $MyCompletedRow=DB_fetch_array($CompletedResult); + $Status=$MyCompletedRow['alllines']-$MyCompletedRow['completedlines']; - if ($status==0) { + if ($Status==0) { $sql="SELECT stat_comment - FROM purchorders - WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; + FROM purchorders + WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; $result=DB_query($sql,$db); $myrow=DB_fetch_array($result); $comment=$myrow['stat_comment']; $date = date($_SESSION['DefaultDateFormat']); $StatusComment=$date.' - Order Completed'.'<br>'.$comment; $sql="UPDATE purchorders - SET status='" . PurchOrder::STATUS_COMPLITED . "', - stat_comment='".$StatusComment."' - WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; + SET status='" . PurchOrder::STATUS_COMPLITED . "', + stat_comment='".$StatusComment."' + WHERE orderno='".$_SESSION['PO']->OrderNo . "'"; $result=DB_query($sql,$db); } @@ -695,7 +668,7 @@ echo '<br><div class=centre>'. _('GRN number'). ' '. $GRN .' '. _('has been processed').'<br>'; echo '<br><a href=PDFGrn.php?GRNNo='.$GRN .'&PONo='.$PONo.'>'. _('Print this Goods Received Note (GRN)').'</a><br><br>'; - echo "<a href='" . $rootpath . "/PO_SelectOSPurchOrder.php?" . SID . "'>" . + echo '<a href="' . $rootpath . '/PO_SelectOSPurchOrder.php?' . SID . '">' . _('Select a different purchase order for receiving goods against'). '</a></div>'; /*end of process goods received entry */ include('includes/footer.inc'); @@ -703,13 +676,12 @@ } else { /*Process Goods received not set so show a link to allow mod of line items on order and allow input of date goods received*/ - echo "<br><div class='centre'><a href='" . $rootpath . "/PO_Items.php?=" . SID . "'>" . _('Modify Order Items'). '</a></div>'; + echo '<br><div class='centre'><a href="' . $rootpath . '/PO_Items.php?=' . SID . '">' . _('Modify Order Items'). '</a></div>'; echo '<br><div class="centre"><input type=submit name=Update Value=' . _('Update') . '><p>'; echo '<input type=submit name="ProcessGoodsReceived" Value="' . _('Process Goods Received') . '"></div>'; } echo '</form>'; - include('includes/footer.inc'); ?> \ No newline at end of file Modified: trunk/sql/mysql/upgrade3.11.1-4.00.sql =================================================================== --- trunk/sql/mysql/upgrade3.11.1-4.00.sql 2010-11-20 08:13:47 UTC (rev 4160) +++ trunk/sql/mysql/upgrade3.11.1-4.00.sql 2010-11-21 00:25:51 UTC (rev 4161) @@ -473,14 +473,17 @@ DELETE FROM stockcategory WHERE stocktype='A'; ALTER TABLE `fixedassets` DROP `stockid`; +INSERT INTO `systypes` (`typeid`, `typename`, `typeno`) VALUES ('41', 'Asset Addition', '1'); INSERT INTO `systypes` (`typeid`, `typename`, `typeno`) VALUES ('42', 'Asset Category Change', '1'); INSERT INTO `systypes` (`typeid`, `typename`, `typeno`) VALUES ('43', 'Delete w/down asset', '1'); +INSERT INTO `systypes` (`typeid`, `typename`, `typeno`) VALUES ('44', 'Depreciation', '1'); CREATE TABLE `fixedassettrans` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `assetid` INT NOT NULL , `transtype` TINYINT NOT NULL , `transno` INT NOT NULL , +`periodno` SMALLINT( 4 ) NOT NULL, `inputdate` DATE NOT, `cost` DOUBLE NOT NULL , `depn` DOUBLE NOT NULL , This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |