From: <dai...@us...> - 2012-02-05 03:40:02
|
Revision: 4870 http://web-erp.svn.sourceforge.net/web-erp/?rev=4870&view=rev Author: daintree Date: 2012-02-05 03:39:56 +0000 (Sun, 05 Feb 2012) Log Message: ----------- not sure Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_salesorders.php trunk/doc/Manual/ManualAPITutorial.html Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-02-05 03:21:26 UTC (rev 4869) +++ trunk/api/api_debtortransactions.php 2012-02-05 03:39:56 UTC (rev 4870) @@ -935,6 +935,63 @@ $Result = api_DB_query($SQL,$db,'','',true); } + #Now figure out if there was an invoice in the same POS transaction to allocate against? + + $SQL = "SELECT id, + ovamount+ovgst AS total, + alloc + FROM debtortrans + WHERE customerref='" . $Header['customerref'] . "' + AND type=10 + AND settled=0"; + $Result = api_DB_query($SQL,$db,'','',true); + + $TotalCreditFX = $TotalFXNetCredit + $TotalFXTax; #Should be negative number + $Allocated = 0; + if (DB_num_rows($Result)>0){ + while ($InvoiceRow = DB_fetch_array($Result) AND $Allocated > $TotalCreditFX){ + if ($InvoiceRow['total'] - $InvoiceRow['alloc'] + $TotalCreditFX - $Allocated>0) { + /*Then we can allocate all of the (remaining) credit against this invoice */ + $AllocateAmount = $InvoiceRow['total'] - $InvoiceRow['alloc'] + $TotalCreditFX - $Allocated; + } elseif ($InvoiceRow['total'] - $InvoiceRow['alloc'] - $Allocated > 0){ + $AllocateAmount = $InvoiceRow['total'] - $InvoiceRow['alloc'] - $Allocated; + } else { + $AllocateAmount = 0; + } + if ($AllocateAmount > 0) { + $SQL = "INSERT INTO custallocns (datealloc, + amt, + transid_allocfrom, + transid_allocto) + VALUES ('" . date('Y-m-d') . "', + '" . $AllocateAmount . "', + '" . $DebtorTransID . "', + '" . $InvoiceRow['id'] . "')"; + $InsertAllocResult = api_DB_query($SQL,$db,'','',true); + } + if (abs($InvoiceRow['total'] - $InvoiceRow['alloc'] - $AllocateAmount)<0.005){ + $Settled = 1; + } else { + $Settled =0; + } + $SQL = "UPDATE debtortrans SET alloc = alloc + " . $AllocateAmount . ", + settled = '" . $Settled . "' + WHERE id = '" . $InvoiceRow['id'] ."'"; + $UpdateAllocResult = api_DB_query($SQL,$db,'','',true); + + $Allocated -= $AllocateAmount; + } + if (abs($TotalCreditFX - $Allocated)<0.005){ + $Settled = 1; + } else { + $Settled =0; + } + $SQL = "UPDATE debtortrans SET alloc = alloc + " . $Allocated . ", + settled = '" . $Settled . "' + WHERE id = '" . $DebtorTransID ."'"; + $UpdateAllocResult = api_DB_query($SQL,$db,'','',true); + } + if (sizeof($Errors)==0) { $Result = DB_Txn_Commit($db); $Errors[0]=0; @@ -943,7 +1000,6 @@ $Result = DB_Txn_Rollback($db); } return $Errors; - } /*End of CreateCreditNote method */ /* Create a customer invoice in webERP. This function will bypass the Modified: trunk/api/api_salesorders.php =================================================================== --- trunk/api/api_salesorders.php 2012-02-05 03:21:26 UTC (rev 4869) +++ trunk/api/api_salesorders.php 2012-02-05 03:39:56 UTC (rev 4870) @@ -1255,7 +1255,7 @@ '" . date('Y-m-d H-i-s') . "', '" . $PeriodNo . "', '" . $OrderHeader['customerref'] . "', - '" . $OrderHeader['sales_type'] . "', + '" . $OrderHeader['ordertype'] . "', '" . $OrderNo . "', '" . $TotalFXNetInvoice . "', '" . $TotalFXTax . "', @@ -1292,7 +1292,7 @@ function GetCurrentPeriod (&$db) { - $TransDate = mktime(); //The current date to find the period for + $TransDate = time(); //The current date to find the period for /* Find the unix timestamp of the last period end date in periods table */ $sql = "SELECT MAX(lastdate_in_period), MAX(periodno) from periods"; $result = DB_query($sql, $db); Modified: trunk/doc/Manual/ManualAPITutorial.html =================================================================== --- trunk/doc/Manual/ManualAPITutorial.html 2012-02-05 03:21:26 UTC (rev 4869) +++ trunk/doc/Manual/ManualAPITutorial.html 2012-02-05 03:39:56 UTC (rev 4870) @@ -37,7 +37,9 @@ include ("xmlrpc/lib/xmlrpc.inc"); <br /><br /> //if your webERP install is on a server at http://www.yourdomain.com/webERP +<br /><br /> $ServerURL = "http://www.yourdomain.com/webERP/api/api_xml-rpc.php"; +<br /><br /> $DebugLevel = 0; //Set to 0,1, or 2 with 2 being the highest level of debug info <br /><br /> $Parameters = array(); @@ -46,26 +48,39 @@ if one of the parameters required is an array then it needs to be processing into xml for the rpc call through php_xmlrpc_encode()*/ <br /><br /> $Parameters['StockID'] = xmlrpcval('DVD-TOPGUN'); //the stockid of the item we wish to know the balance for +<br /><br /> //assuming the demo username and password will work ! +<br /><br /> $Parameters['Username'] = xmlrpcval('admin'); +<br /><br /> $Parameters['Password'] = xmlrpcval('weberp'); <br /><br /> $msg = new xmlrpcmsg("weberp.xmlrpc_GetStockBalance", $Parameters); <br /><br /> $client = new xmlrpc_client($ServerURL); +<br /><br /> $client->setDebug($DebugLevel); +<br /><br /> $response = $client->send($msg); +<br /><br /> $answer = php_xmlrpc_decode($response->value()); +<br /><br /> if ($answer[0]!=0){ //then the API returned some errors need to figure out what went wrong <br /><br /> //need to figure out how to return all the error descriptions associated with the codes <br /><br /> } else { //all went well the returned data is in $answer[1] +<br /><br /> //answer will be an array of the locations and quantity on hand for DVD_TOPGUN so we need to run through the array to print out +<br /><br /> for ($i=0; $i < sizeof($answer[1]);$i++) { +<br /><br /> echo '<br>' . $answer[1][$i]['loccode'] . ' has ' . $answer[1][$i]['quantity'] . ' on hand'; + <br /><br /> } +<br /><br /> echo "</body></html>"; +<br /><br /> </i> <hr /> <br /><br /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |