From: <dai...@us...> - 2012-02-08 09:40:41
|
Revision: 4885 http://web-erp.svn.sourceforge.net/web-erp/?rev=4885&view=rev Author: daintree Date: 2012-02-08 09:40:30 +0000 (Wed, 08 Feb 2012) Log Message: ----------- manual session issues Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_errorcodes.php trunk/api/api_xml-rpc.php trunk/doc/Manual/ManualAPIFunctions.php trunk/doc/Manual/ManualContents.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-02-07 09:12:13 UTC (rev 4884) +++ trunk/api/api_debtortransactions.php 2012-02-08 09:40:30 UTC (rev 4885) @@ -1281,7 +1281,7 @@ 0, '" . $InvoiceDetails['jobref'] . "', 1)"; - $result = DB_Query($sql, $db); + $result = api_DB_Query($sql, $db); $sql="INSERT INTO gltrans VALUES(null, 10, '" . GetNextTransactionNo(10, $db) . "', @@ -1294,7 +1294,7 @@ 0, '" . $InvoiceDetails['jobref'] . "', 1)"; - $result = DB_Query($sql, $db); + $result = api_DB_Query($sql, $db); $result= DB_Txn_Commit($db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; @@ -1309,6 +1309,91 @@ } } + function AllocateTrans($AllocDetails, $User, $Password) { + + /* AllocDetails is an associative array containing: + * AllocDetails['debtorno'] + * AllocDetails['type'] + * AllocDetails['transno'] + * AllocDetails['customerref'] + */ + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $Errors=VerifyDebtorExists($AllocDetails['debtorno'], sizeof($Errors), $Errors, $db); + /*Get the outstanding amount to allocate (all amounts in FX) from the transaction*/ + + if ($AllocDetails['type'] !='11' AND $AllocDetails['type'] !=12){ + $Errors[] = MustBeReceiptOrCreditNote; + } + $SQL = "SELECT id, + rate, + ovamount+ovgst-alloc AS lefttoalloc + FROM debtortrans + WHERE debtorno='" . $AllocDetails['debtorno'] . "' + AND type='" . $AllocDetails['type'] . "' + AND transno='" . $AllocDetails['transno'] . "'"; + $Result = api_DB_query($SQL,$db); + $LeftToAllocRow = DB_fetch_array($Result); + if (DB_num_row($Result)==0){ + $Errors[] = NoTransactionToAllocate; + } + + if ($LeftToAllocRow['lefttoalloc'] >= 0){ + /*Now look for invoices with the same customerref to allocate to */ + $SQL = "SELECT id, + rate, + -ovamount-ovgst-alloc AS outstanding + FROM debtortrans + WHERE debtorno='" . $AllocDetails['debtorno'] . "' + AND type=10 + AND customerref='" . $AllocDetails['customerref'] . "'"; + $Result = api_DB_query($SQL,$db); + $OSInvRow = DB_fetch_array($Result); + if ($OSInvRow['rate']==$LeftToAllocRow['rate'] + AND $OSInvRow['outstanding']>0){ + + if ($OSInvRow['outstanding']>=$LeftToAllocRow['lefttoalloc']){ + /*We can allocate the whole amount of the credit/receipt */ + $AllocateAmount = $LeftToAllocRow['lefttoalloc']; + } else { + /*We can only allocate the rest of the invoice outstanding */ + $AllocateAmount = $OSInvRow['outstanding']; + } + DB_Txn_Begin($db); + /*Now insert the allocation records */ + $SQL = "INSERT INTO custallocs (amt, + datealloc, + transid_allocfrom, + transid_allocto) + VALUE('" . $AllocateAmount . "', + '" . Date('Y-m-d') . "', + '" . $LeftToAllocRow['id'] . "', + '" . $OSInvRow['id'] . "')"; + $Result = api_DB_query($SQL,$db,'','',true); + /*Now update the allocated amounts in the debtortrans for both transactions */ + $SQL = "UPDATE debtortrans SET alloc=alloc-" . $AllocateAmount . " + WHERE id = '" . $LeftToAllocRow['id'] . "'"; + $Result = api_DB_query($SQL,$db,'','',true); + $SQL = "UPDATE debtortrans SET alloc=alloc+" . $AllocateAmount . " + WHERE id = '" . $OSInvRow['id'] . "'"; + $Result = api_DB_query($SQL,$db,'','',true); + } /*end if the exchange rates are the same so no diff on exchange */ + + }/*end if there is owt to allocation*/ + if (sizeof($Errors)==0) { + $Result = DB_Txn_Commit($db); + $Errors[0]=0; + } else { + $Result = DB_Txn_Rollback($db); + } + return $Errors; + + } + /* Create a customer credit note in webERP. This function will bypass the * normal procedure in webERP for creating a sales order first, and then * delivering it. All values should be sent as negatives. Modified: trunk/api/api_errorcodes.php =================================================================== --- trunk/api/api_errorcodes.php 2012-02-07 09:12:13 UTC (rev 4884) +++ trunk/api/api_errorcodes.php 2012-02-08 09:40:30 UTC (rev 4885) @@ -167,6 +167,9 @@ Define('TaxRatesFailed',1162); Define('NoReadCustomerBranch',1163); Define('NoReadItem',1164); + Define('MustBeReceiptOrCreditNote',1165); + Define('NoTransactionToAllocate',1166); + /* Array of Descriptions of errors */ $ErrorDescription['1'] = _('No Authorisation'); @@ -334,5 +337,7 @@ $ErrorDescription['1162'] = _('Unable to read tax rates for this item and tax group'); $ErrorDescription['1163'] = _('Unable to read customer and branch details'); $ErrorDescription['1164'] = _('Unable to read credit note item details'); + $ErrorDescription['1165'] = _('Can only allocate receipts or a credit notes'); + $ErrorDescription['1166'] = _('No transaction found to allocate'); ?> \ No newline at end of file Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-02-07 09:12:13 UTC (rev 4884) +++ trunk/api/api_xml-rpc.php 2012-02-08 09:40:30 UTC (rev 4885) @@ -12,7 +12,7 @@ include '../xmlrpc/lib/xmlrpcs.inc'; $Description = _('This function is used to login into the API methods for the specified the database.') - .'<p><b>' . _('NOTE: using this function means that the User Name and Password fields in the following functions are no longer required. When calling those functions, leave the last two parameters off.') . '</b>'; + .'<p>' . _('NOTE: using this function means that the User Name and Password fields in the following functions are no longer required. When calling those functions, leave the last two parameters off.') . '</p>'; $Parameter[0]['name'] = _('Database Name'); $Parameter[0]['description'] = _('The name of the database to use for the transactions to come. '); $Parameter[1]['name'] = _('User name'); Modified: trunk/doc/Manual/ManualAPIFunctions.php =================================================================== --- trunk/doc/Manual/ManualAPIFunctions.php 2012-02-07 09:12:13 UTC (rev 4884) +++ trunk/doc/Manual/ManualAPIFunctions.php 2012-02-08 09:40:30 UTC (rev 4885) @@ -7,7 +7,7 @@ //$PathPrefix= $_SERVER['HTTP_HOST'].$rootpath.'/../../'; //$PathPrefix= '/../'; -include('../../includes/session.inc'); +//include('../../includes/session.inc'); include('../../xmlrpc/lib/xmlrpc.inc'); include('../../api/api_errorcodes.php'); @@ -45,7 +45,11 @@ $answer = php_xmlrpc_decode($response->value()); for ($i=0; $i<sizeof($answer); $i++) { - echo '<table border="1" width="80%"><tr><th colspan="3"><h4>'._('Method name')._(' - ').'<b>'.$answer[$i].'</b></h4></th></tr></table>'; + echo '<table border="1" width="80%"> + <tr> + <th colspan="3"><h4>'._('Method name')._(' - ').'<b>'.$answer[$i].'</b></h4></th> + </tr> + </table>'; $method = php_xmlrpc_encode($answer[$i]); $msg = new xmlrpcmsg("system.methodHelp", array($method)); Modified: trunk/doc/Manual/ManualContents.php =================================================================== --- trunk/doc/Manual/ManualContents.php 2012-02-07 09:12:13 UTC (rev 4884) +++ trunk/doc/Manual/ManualContents.php 2012-02-08 09:40:30 UTC (rev 4885) @@ -21,7 +21,7 @@ -->';*/ $PathPrefix='../../'; -//include($PathPrefix.'includes/session.inc'); +include($PathPrefix.'includes/session.inc'); include('ManualHeader.html'); ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |