From: <dai...@us...> - 2012-01-09 05:11:19
|
Revision: 4793 http://web-erp.svn.sourceforge.net/web-erp/?rev=4793&view=rev Author: daintree Date: 2012-01-09 05:11:13 +0000 (Mon, 09 Jan 2012) Log Message: ----------- additional API functions Modified Paths: -------------- trunk/api/api_paymentterms.php trunk/api/api_taxgroups.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_paymentterms.php =================================================================== --- trunk/api/api_paymentterms.php 2012-01-07 01:04:29 UTC (rev 4792) +++ trunk/api/api_paymentterms.php 2012-01-09 05:11:13 UTC (rev 4793) @@ -40,5 +40,43 @@ $result = DB_query($sql, $db); return DB_fetch_array($result); } +/* This function returns a list of the payment methods + * currently setup on webERP + */ + function GetPaymentMethodsList($User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = 'SELECT paymentid FROM paymentmethods'; + $result = DB_query($sql, $db); + $i=0; + while ($myrow=DB_fetch_array($result)) { + $PaymentMethodsList[$i]=$myrow[0]; + $i++; + } + return $PaymentMethodsList; + } +/* This function takes as a parameter a payment method code + * and returns an array containing the details of the selected + * payment method. + */ + + function GetPaymentMethodDetails($PaymentMethod, $User, $Password) { + $Errors = array(); + if (!isset($db)) { + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + } + $sql = "SELECT * FROM paymentmethods WHERE paymentid='".$PaymentMethod."'"; + $result = DB_query($sql, $db); + return DB_fetch_array($result); + } + ?> \ No newline at end of file Modified: trunk/api/api_taxgroups.php =================================================================== --- trunk/api/api_taxgroups.php 2012-01-07 01:04:29 UTC (rev 4792) +++ trunk/api/api_taxgroups.php 2012-01-09 05:11:13 UTC (rev 4793) @@ -38,4 +38,77 @@ $result = DB_query($sql, $db); return DB_fetch_array($result); } + + /* This function takes as a parameter a tax group id + * and returns an array containing the taxes in the selected + * tax group. + */ + + function GetTaxGroupTaxes($TaxGroup, $User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = "SELECT * FROM taxgrouptaxes WHERE taxgroupid='".$TaxGroup."'"; + $result = DB_query($sql, $db); + return DB_fetch_array($result); + } + +/* This function returns a list of the tax authority ids + * currently setup on webERP + */ + function GetTaxAuthorityList($User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = 'SELECT taxid FROM taxauthorities'; + $result = DB_query($sql, $db); + $i=0; + while ($myrow=DB_fetch_array($result)) { + $TaxAuthList[$i]=$myrow[0]; + $i++; + } + return $TaxAuthList; + } + +/* This function takes as a parameter a tax authority id + * and returns an array containing the details of the selected + * tax authority. + */ + + function GetTaxAuthorityDetails($TaxAuthority, $User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = "SELECT * FROM taxauthorities WHERE taxid='".$TaxAuthority."'"; + $result = DB_query($sql, $db); + return DB_fetch_array($result); + } + +/* This function takes as a parameter a tax authority id + * and returns an array containing the rate of tax fpr the selected + * tax authority. + */ + + function GetTaxAuthorityRates($TaxAuthority, $User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = "SELECT * FROM taxauthrates WHERE taxauthority='".$TaxAuthority."'"; + $result = DB_query($sql, $db); + return DB_fetch_array($result); + } + + ?> \ No newline at end of file Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-01-07 01:04:29 UTC (rev 4792) +++ trunk/api/api_xml-rpc.php 2012-01-09 05:11:13 UTC (rev 4793) @@ -4,7 +4,7 @@ * Must be a better way of doing this, but at * least it works */ } - + /* Note api_php.php includes api */ include 'api_php.php'; include '../xmlrpc/lib/xmlrpc.inc'; @@ -619,10 +619,68 @@ return $rtn; } + unset($Description); + unset($Parameter); + unset($ReturnValue); + + $Description = _('This function returns a list of payment method codes.'); + $Parameter[0]['name'] = _('User name'); + $Parameter[0]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[1]['name'] = _('User password'); + $Parameter[1]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of payment method codes.'); + +/*E*/$GetPaymentMethodsList_sig = array(array($xmlrpcStruct), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString)); + $GetPaymentmethodsList_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetPaymentMethodsList($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 2) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetPaymentMethodsList($xmlrpcmsg->getParam( 0 )->scalarval( ), $xmlrpcmsg->getParam( 1 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetPaymentMethodsList( '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + unset($Description); unset($Parameter); unset($ReturnValue); + $Description = _('This function takes a payment method code and returns details of that payment method.'); + $Parameter[0]['name'] = _('Payment method code'); + $Parameter[0]['description'] = _('A payment method code as returned by the GetPaymentMethodsList function.'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of payment terms details.'); + +/*E*/$GetPaymentMethodDetails_sig = array(array($xmlrpcStruct,$xmlrpcString), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); + $GetPaymentMethodDetails_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetPaymentMethodDetails($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetPaymentMethodDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetPaymentMethodDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + + unset($Description); + unset($Parameter); + unset($ReturnValue); + $Description = _('This function inserts a new stock item into webERP, including updating the locstock table.'); $Parameter[0]['name'] = _('Stock Item Details'); $Parameter[0]['description'] = _('Key/value pairs of data to insert. The key must be identical with the database field name.'); @@ -1721,10 +1779,127 @@ return $rtn; } + $Description = _('This function returns a list of tax authority IDs.'); + $Parameter[0]['name'] = _('User name'); + $Parameter[0]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[1]['name'] = _('User password'); + $Parameter[1]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of tax group IDs.'); + +/*E*/ $GetTaxAuthorityList_sig = array(array($xmlrpcStruct), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString)); + $GetTaxAuthorityList_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetTaxAuthorityList($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 2) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityList($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityList( '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + unset($Description); unset($Parameter); unset($ReturnValue); + $Description = _('This function takes a tax authority ID and returns details of that tax authority.'); + $Parameter[0]['name'] = _('Tax Authority ID'); + $Parameter[0]['description'] = _('A tax Authority ID as returned by the GetTaxAuthorityList function.'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of tax authority details.'); + +/*E*/$GetTaxAuthorityDetails_sig = array(array($xmlrpcStruct,$xmlrpcString), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); + $GetTaxAuthorityDetails_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetTaxAuthorityDetails($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + + $Description = _('This function takes a tax authority ID and returns the rates of tax for the authority.'); + $Parameter[0]['name'] = _('Tax Authority ID'); + $Parameter[0]['description'] = _('A tax Authority ID as returned by the GetTaxAuthorityList function.'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of tax authority tax rates.'); + +/*E*/ $GetTaxAuthorityRates_sig = array(array($xmlrpcStruct,$xmlrpcString), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); + $GetTaxAuthorityRates_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetTaxAuthorityRates($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityRates($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityRates($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + + $Description = _('This function takes a tax group ID and returns the taxes that belong to that tax group.'); + $Parameter[0]['name'] = _('Tax Group ID'); + $Parameter[0]['description'] = _('A tax group ID as returned by the GetTaxgroupList function.'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of tax group details.'); + +/*E*/$GetTaxGroupTaxes_sig = array(array($xmlrpcStruct,$xmlrpcString), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); + $GetTaxGroupTaxes_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetTaxgroupDetails($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxGroupTaxes($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxGroupTaxes($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + $Description = _('This function returns a list of customer types.'); $Parameter[0]['name'] = _('User name'); $Parameter[0]['description'] = _('A valid weberp username. This user should have security access to this data.'); @@ -2766,6 +2941,14 @@ "function" => "xmlrpc_GetPaymentTermsDetails", "signature" => $GetPaymentTermsDetails_sig, "docstring" => $GetPaymentTermsDetails_doc), + "weberp.xmlrpc_GetPaymentMethodsList" => array( + "function" => "xmlrpc_GetPaymentMethodsList", + "signature" => $GetPaymentMethodsList_sig, + "docstring" => $GetPaymentMethodsList_doc), + "weberp.xmlrpc_GetPaymentMethodsDetails" => array( + "function" => "xmlrpc_GetPaymentMethodsDetails", + "signature" => $GetPaymentMethodsDetails_sig, + "docstring" => $GetPaymentMrthodsDetails_doc), "weberp.xmlrpc_InsertStockItem" => array( "function" => "xmlrpc_InsertStockItem", "signature" => $InsertStockItem_sig, @@ -2918,6 +3101,22 @@ "function" => "xmlrpc_GetTaxgroupDetails", "signature" => $GetTaxgroupDetails_sig, "docstring" => $GetTaxgroupDetails_doc), + "weberp.xmlrpc_GetTaxGroupTaxes" => array( + "function" => "xmlrpc_GetTaxGroupTaxes", + "signature" => $GetTaxGroupTaxes_sig, + "docstring" => $GetTaxGroupTaxes_doc), + "weberp.xmlrpc_GetTaxAuthorityList" => array( + "function" => "xmlrpc_GetTaxAuthorityList", + "signature" => $GetTaxAuthorityList_sig, + "docstring" => $GetTaxAuthorityList_doc), + "weberp.xmlrpc_GetTaxAuthorityDetails" => array( + "function" => "xmlrpc_GetTaxAuthorityDetails", + "signature" => $GetTaxAuthorityDetails_sig, + "docstring" => $GetTaxAuthorityDetails_doc), + "weberp.xmlrpc_GetTaxAuthorityRates" => array( + "function" => "xmlrpc_GetTaxAuthorityRates", + "signature" => $GetTaxAuthorityRates_sig, + "docstring" => $GetTaxAuthorityRates_doc), "weberp.xmlrpc_GetCustomerTypeList" => array( "function" => "xmlrpc_GetCustomerTypeList", "signature" => $GetCustomerTypeList_sig, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-01-09 05:11:20
|
Revision: 4793 http://web-erp.svn.sourceforge.net/web-erp/?rev=4793&view=rev Author: daintree Date: 2012-01-09 05:11:13 +0000 (Mon, 09 Jan 2012) Log Message: ----------- additional API functions Modified Paths: -------------- trunk/api/api_paymentterms.php trunk/api/api_taxgroups.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_paymentterms.php =================================================================== --- trunk/api/api_paymentterms.php 2012-01-07 01:04:29 UTC (rev 4792) +++ trunk/api/api_paymentterms.php 2012-01-09 05:11:13 UTC (rev 4793) @@ -40,5 +40,43 @@ $result = DB_query($sql, $db); return DB_fetch_array($result); } +/* This function returns a list of the payment methods + * currently setup on webERP + */ + function GetPaymentMethodsList($User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = 'SELECT paymentid FROM paymentmethods'; + $result = DB_query($sql, $db); + $i=0; + while ($myrow=DB_fetch_array($result)) { + $PaymentMethodsList[$i]=$myrow[0]; + $i++; + } + return $PaymentMethodsList; + } +/* This function takes as a parameter a payment method code + * and returns an array containing the details of the selected + * payment method. + */ + + function GetPaymentMethodDetails($PaymentMethod, $User, $Password) { + $Errors = array(); + if (!isset($db)) { + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + } + $sql = "SELECT * FROM paymentmethods WHERE paymentid='".$PaymentMethod."'"; + $result = DB_query($sql, $db); + return DB_fetch_array($result); + } + ?> \ No newline at end of file Modified: trunk/api/api_taxgroups.php =================================================================== --- trunk/api/api_taxgroups.php 2012-01-07 01:04:29 UTC (rev 4792) +++ trunk/api/api_taxgroups.php 2012-01-09 05:11:13 UTC (rev 4793) @@ -38,4 +38,77 @@ $result = DB_query($sql, $db); return DB_fetch_array($result); } + + /* This function takes as a parameter a tax group id + * and returns an array containing the taxes in the selected + * tax group. + */ + + function GetTaxGroupTaxes($TaxGroup, $User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = "SELECT * FROM taxgrouptaxes WHERE taxgroupid='".$TaxGroup."'"; + $result = DB_query($sql, $db); + return DB_fetch_array($result); + } + +/* This function returns a list of the tax authority ids + * currently setup on webERP + */ + function GetTaxAuthorityList($User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = 'SELECT taxid FROM taxauthorities'; + $result = DB_query($sql, $db); + $i=0; + while ($myrow=DB_fetch_array($result)) { + $TaxAuthList[$i]=$myrow[0]; + $i++; + } + return $TaxAuthList; + } + +/* This function takes as a parameter a tax authority id + * and returns an array containing the details of the selected + * tax authority. + */ + + function GetTaxAuthorityDetails($TaxAuthority, $User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = "SELECT * FROM taxauthorities WHERE taxid='".$TaxAuthority."'"; + $result = DB_query($sql, $db); + return DB_fetch_array($result); + } + +/* This function takes as a parameter a tax authority id + * and returns an array containing the rate of tax fpr the selected + * tax authority. + */ + + function GetTaxAuthorityRates($TaxAuthority, $User, $Password) { + $Errors = array(); + $db = db($User, $Password); + if (gettype($db)=='integer') { + $Errors[0]=NoAuthorisation; + return $Errors; + } + $sql = "SELECT * FROM taxauthrates WHERE taxauthority='".$TaxAuthority."'"; + $result = DB_query($sql, $db); + return DB_fetch_array($result); + } + + ?> \ No newline at end of file Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-01-07 01:04:29 UTC (rev 4792) +++ trunk/api/api_xml-rpc.php 2012-01-09 05:11:13 UTC (rev 4793) @@ -4,7 +4,7 @@ * Must be a better way of doing this, but at * least it works */ } - + /* Note api_php.php includes api */ include 'api_php.php'; include '../xmlrpc/lib/xmlrpc.inc'; @@ -619,10 +619,68 @@ return $rtn; } + unset($Description); + unset($Parameter); + unset($ReturnValue); + + $Description = _('This function returns a list of payment method codes.'); + $Parameter[0]['name'] = _('User name'); + $Parameter[0]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[1]['name'] = _('User password'); + $Parameter[1]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of payment method codes.'); + +/*E*/$GetPaymentMethodsList_sig = array(array($xmlrpcStruct), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString)); + $GetPaymentmethodsList_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetPaymentMethodsList($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 2) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetPaymentMethodsList($xmlrpcmsg->getParam( 0 )->scalarval( ), $xmlrpcmsg->getParam( 1 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetPaymentMethodsList( '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + unset($Description); unset($Parameter); unset($ReturnValue); + $Description = _('This function takes a payment method code and returns details of that payment method.'); + $Parameter[0]['name'] = _('Payment method code'); + $Parameter[0]['description'] = _('A payment method code as returned by the GetPaymentMethodsList function.'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of payment terms details.'); + +/*E*/$GetPaymentMethodDetails_sig = array(array($xmlrpcStruct,$xmlrpcString), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); + $GetPaymentMethodDetails_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetPaymentMethodDetails($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetPaymentMethodDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetPaymentMethodDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + + unset($Description); + unset($Parameter); + unset($ReturnValue); + $Description = _('This function inserts a new stock item into webERP, including updating the locstock table.'); $Parameter[0]['name'] = _('Stock Item Details'); $Parameter[0]['description'] = _('Key/value pairs of data to insert. The key must be identical with the database field name.'); @@ -1721,10 +1779,127 @@ return $rtn; } + $Description = _('This function returns a list of tax authority IDs.'); + $Parameter[0]['name'] = _('User name'); + $Parameter[0]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[1]['name'] = _('User password'); + $Parameter[1]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of tax group IDs.'); + +/*E*/ $GetTaxAuthorityList_sig = array(array($xmlrpcStruct), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString)); + $GetTaxAuthorityList_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetTaxAuthorityList($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 2) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityList($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityList( '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + unset($Description); unset($Parameter); unset($ReturnValue); + $Description = _('This function takes a tax authority ID and returns details of that tax authority.'); + $Parameter[0]['name'] = _('Tax Authority ID'); + $Parameter[0]['description'] = _('A tax Authority ID as returned by the GetTaxAuthorityList function.'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of tax authority details.'); + +/*E*/$GetTaxAuthorityDetails_sig = array(array($xmlrpcStruct,$xmlrpcString), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); + $GetTaxAuthorityDetails_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetTaxAuthorityDetails($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + + $Description = _('This function takes a tax authority ID and returns the rates of tax for the authority.'); + $Parameter[0]['name'] = _('Tax Authority ID'); + $Parameter[0]['description'] = _('A tax Authority ID as returned by the GetTaxAuthorityList function.'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of tax authority tax rates.'); + +/*E*/ $GetTaxAuthorityRates_sig = array(array($xmlrpcStruct,$xmlrpcString), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); + $GetTaxAuthorityRates_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetTaxAuthorityRates($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityRates($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityRates($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + + $Description = _('This function takes a tax group ID and returns the taxes that belong to that tax group.'); + $Parameter[0]['name'] = _('Tax Group ID'); + $Parameter[0]['description'] = _('A tax group ID as returned by the GetTaxgroupList function.'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of tax group details.'); + +/*E*/$GetTaxGroupTaxes_sig = array(array($xmlrpcStruct,$xmlrpcString), +/*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); + $GetTaxGroupTaxes_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_GetTaxgroupDetails($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) +/*x*/ { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxGroupTaxes($xmlrpcmsg->getParam( 0 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxGroupTaxes($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + $Description = _('This function returns a list of customer types.'); $Parameter[0]['name'] = _('User name'); $Parameter[0]['description'] = _('A valid weberp username. This user should have security access to this data.'); @@ -2766,6 +2941,14 @@ "function" => "xmlrpc_GetPaymentTermsDetails", "signature" => $GetPaymentTermsDetails_sig, "docstring" => $GetPaymentTermsDetails_doc), + "weberp.xmlrpc_GetPaymentMethodsList" => array( + "function" => "xmlrpc_GetPaymentMethodsList", + "signature" => $GetPaymentMethodsList_sig, + "docstring" => $GetPaymentMethodsList_doc), + "weberp.xmlrpc_GetPaymentMethodsDetails" => array( + "function" => "xmlrpc_GetPaymentMethodsDetails", + "signature" => $GetPaymentMethodsDetails_sig, + "docstring" => $GetPaymentMrthodsDetails_doc), "weberp.xmlrpc_InsertStockItem" => array( "function" => "xmlrpc_InsertStockItem", "signature" => $InsertStockItem_sig, @@ -2918,6 +3101,22 @@ "function" => "xmlrpc_GetTaxgroupDetails", "signature" => $GetTaxgroupDetails_sig, "docstring" => $GetTaxgroupDetails_doc), + "weberp.xmlrpc_GetTaxGroupTaxes" => array( + "function" => "xmlrpc_GetTaxGroupTaxes", + "signature" => $GetTaxGroupTaxes_sig, + "docstring" => $GetTaxGroupTaxes_doc), + "weberp.xmlrpc_GetTaxAuthorityList" => array( + "function" => "xmlrpc_GetTaxAuthorityList", + "signature" => $GetTaxAuthorityList_sig, + "docstring" => $GetTaxAuthorityList_doc), + "weberp.xmlrpc_GetTaxAuthorityDetails" => array( + "function" => "xmlrpc_GetTaxAuthorityDetails", + "signature" => $GetTaxAuthorityDetails_sig, + "docstring" => $GetTaxAuthorityDetails_doc), + "weberp.xmlrpc_GetTaxAuthorityRates" => array( + "function" => "xmlrpc_GetTaxAuthorityRates", + "signature" => $GetTaxAuthorityRates_sig, + "docstring" => $GetTaxAuthorityRates_doc), "weberp.xmlrpc_GetCustomerTypeList" => array( "function" => "xmlrpc_GetCustomerTypeList", "signature" => $GetCustomerTypeList_sig, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-01-29 09:42:51
|
Revision: 4850 http://web-erp.svn.sourceforge.net/web-erp/?rev=4850&view=rev Author: daintree Date: 2012-01-29 09:42:44 +0000 (Sun, 29 Jan 2012) Log Message: ----------- extended API to create invoices from salesorders Modified Paths: -------------- trunk/api/api_errorcodes.php trunk/api/api_php.php trunk/api/api_salesorders.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_errorcodes.php =================================================================== --- trunk/api/api_errorcodes.php 2012-01-29 09:03:14 UTC (rev 4849) +++ trunk/api/api_errorcodes.php 2012-01-29 09:42:44 UTC (rev 4850) @@ -160,6 +160,12 @@ Define('BatchIsEmpty', 1155); Define('NoSuchArea', 1156); Define('NoSuchSalesMan', 1157); + Define('NoCompanyRecord',1158); + Define('NoReadOrder',1159); + Define('NoReadOrderLines',1160); + Define('NoTaxProvince',1161); + Define('TaxRatesFailed',1162); + /* Array of Descriptions of errors */ $ErrorDescription['1'] = _('No Authorisation'); @@ -320,5 +326,10 @@ $ErrorDescription['1155'] = _('Batch is empty'); $ErrorDescription['1156'] = _('No such area'); $ErrorDescription['1157'] = _('No such salesman'); + $ErrorDescription['1158'] = _('Unable to read company record'); + $ErrorDescription['1159'] = _('Unable to read sales order'); + $ErrorDescription['1160'] = _('Unable to read sales order lines'); + $ErrorDescription['1161'] = _('Unable to get tax province of location'); + $ErrorDescription['1162'] = _('Unable to read tax rates for this item and tax group'); ?> \ No newline at end of file Modified: trunk/api/api_php.php =================================================================== --- trunk/api/api_php.php 2012-01-29 09:03:14 UTC (rev 4849) +++ trunk/api/api_php.php 2012-01-29 09:42:44 UTC (rev 4850) @@ -14,7 +14,7 @@ /* Include SQL_CommonFunctions.inc, to use GetNextTransNo().*/ include($PathPrefix . 'includes/SQL_CommonFunctions.inc'); /* Required for creating invoices/credits */ - include($PathPrefix . 'includes/GetSalesTransGLCode.inc'); + include($PathPrefix . 'includes/GetSalesTransGLCodes.inc'); /* Get weberp authentication, and return a valid database connection */ @@ -22,7 +22,7 @@ if (!isset($_SESSION['AccessLevel']) OR $_SESSION['AccessLevel'] == '') { // Login to default database = old clients. - if ($user != '' && $password != '') { + if ($user != '' AND $password != '') { global $api_DatabaseName; $rc = LoginAPI ($api_DatabaseName, $user, $password); if ($rc[0] == UL_OK ) { Modified: trunk/api/api_salesorders.php =================================================================== --- trunk/api/api_salesorders.php 2012-01-29 09:03:14 UTC (rev 4849) +++ trunk/api/api_salesorders.php 2012-01-29 09:42:44 UTC (rev 4850) @@ -116,15 +116,15 @@ /* Check that the delivery date is a valid date. The date * must be in the same format as the date format specified in the * target webERP company */ - function VerifyDeliveryDate($deliverydate, $i, $Errors, $db) { + function VerifyDeliveryDate($DeliveryDate, $i, $Errors, $db) { $sql="SELECT confvalue FROM config WHERE confname='DefaultDateFormat'"; $result=api_DB_query($sql, $db); $myrow=DB_fetch_array($result); $DateFormat=$myrow[0]; - if (mb_strstr($deliverydate,'/')) { - $DateArray = explode('/',$deliverydate); + if (mb_strstr($DeliveryDate,'/')) { + $DateArray = explode('/',$DeliveryDate); } elseif (mb_strstr($PeriodEnd,'.')) { - $DateArray = explode('.',$deliverydate); + $DateArray = explode('.',$DeliveryDate); } if ($DateFormat=='d/m/Y') { $Day=$DateArray[0]; @@ -349,10 +349,6 @@ VALUES (" . mb_substr($FieldValues,0,-2). ")"; if (sizeof($Errors)==0) { - /*debug info to file - $fp = fopen( '/root/Web-Server/apidebug/api-sql.sql', "w"); - fputs($fp, $sql); - */ $result = api_DB_Query($sql, $db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; @@ -464,6 +460,7 @@ * already exist in webERP. */ function InsertSalesOrderLine($OrderLine, $user, $password) { + $Errors = array(); $db = db($user, $password); if (gettype($db)=='integer') { @@ -610,6 +607,7 @@ then it returns an $Errors array. */ function GetSalesOrderLine($OrderNo, $user, $password) { + $Errors = array(); $db = db($user, $password); if (gettype($db)=='integer') { @@ -631,8 +629,12 @@ function InvoiceSalesOrder($OrderNo, $User, $Password) { + /*debug info to file */ + $fp = fopen( '/root/Web-Server/apidebug/debuginfo.txt', "w"); + fputs($fp, 'starting to invoice order ' . $OrderNo); + $Errors = array(); - $db = db($user, $password); + $db = db($User, $Password); if (gettype($db)=='integer') { $Errors[0]=NoAuthorisation; return $Errors; @@ -648,68 +650,92 @@ gllink_debtors, gllink_stock FROM companies - WHERE coycode=1";,$db); + WHERE coycode=1",$db); $CompanyRecord = DB_fetch_array($ReadCoyResult); - + if (DB_error_no($db) != 0) { + $Errors[] = NoCompanyRecord; + } + + fputs($fp, 'Got company info' . "\n"); + $OrderHeaderSQL = "SELECT salesorders.debtorno, - debtorsmaster.name, - salesorders.branchcode, - salesorders.customerref, - salesorders.orddate, - salesorders.ordertype, - salesorders.shipvia, - custbranch.area, - custbranch.taxgroupid, - debtorsmaster.currcode, - currencies.rate, - salesorders.fromstkloc, - custbranch.salesman - FROM salesorders - INNER JOIN debtorsmaster - ON salesorders.debtorno = debtorsmaster.debtorno - INNER JOIN custbranch - ON salesorders.debtorno = custbranch.debtorno - AND salesorders.branchcode = custbranch.branchcode - INNER JOIN locations - ON locations.loccode=salesorders.fromstkloc - INNER JOIN currencies - ON debtorsmaster.currcode=currencies.currabrev - WHERE salesorders.orderno = '" . $OrderNumber . "'"; + debtorsmaster.name, + salesorders.branchcode, + salesorders.customerref, + salesorders.orddate, + salesorders.ordertype, + salesorders.shipvia, + custbranch.area, + custbranch.taxgroupid, + debtorsmaster.currcode, + currencies.rate, + salesorders.fromstkloc, + custbranch.salesman + FROM salesorders + INNER JOIN debtorsmaster + ON salesorders.debtorno = debtorsmaster.debtorno + INNER JOIN custbranch + ON salesorders.debtorno = custbranch.debtorno + AND salesorders.branchcode = custbranch.branchcode + INNER JOIN locations + ON locations.loccode=salesorders.fromstkloc + INNER JOIN currencies + ON debtorsmaster.currcode=currencies.currabrev + WHERE salesorders.orderno = '" . $OrderNumber . "'"; $OrderHeaderResult = api_DB_query($OrderHeaderSQL,$db); + if (DB_error_no($db) != 0) { + $Errors[] = NoReadOrder; + } + + fputs($fp, 'Got order header' . "\n"); + $OrderHeader = DB_fetch_array($OrderHeaderResult); $TaxProvResult = api_DB_query("SELECT taxprovinceid FROM locations WHERE loccode='" . $OrderHeader['fromstkloc'] ."'",$db); $Result = api_DB_query($SQL,$db); + if (DB_error_no($db) != 0) { + $Errors[] = NoTaxProvince; + } $myrow = DB_fetch_row($Result); $DispTaxProvinceID = $myrow[0]; - - $LineItemsSQL = "SELECT stkcode, unitprice, quantity, discountpercent, - taxcatid + taxcatid, + mbflag, + materialcost+labourcost+overheadcost AS standardcost FROM salesorderdetails INNER JOIN stockmaster ON salesorderdetails.stkcode = stockmaster.stockid - WHERE orderno ='" . $OrderNo . "'"; + WHERE orderno ='" . $OrderNo . "' + AND completed=0"; $LineItemsResult = api_DB_query($LineItemsSQL,$db); - + if (DB_error_no($db) != 0 OR DB_num_rows($LineItemsResult)==0) { + $Errors[] = NoReadOrderLines; + return $Errors; + } + fputs($fp, 'Got order line items' . "\n"); + /*Start an SQL transaction */ $result = DB_Txn_Begin($db); /*Now Get the next invoice number - function in SQL_CommonFunctions*/ $InvoiceNo = GetNextTransNo(10, $db); $PeriodNo = GetCurrentPeriod($db); + fputs($fp, 'Got invoice number ' . $InvoiceNo . "\n and into PeriodNo " . $PeriodNo . "\n"); + $TotalFXNetInvoice = 0; $TotalFXTax = 0; $LineCounter =0; while ($OrderLineRow = DB_fetch_array($LineItemsResult)) { - + + $StandardCost = $OrderLineRow['standardcost']; + $LineNetAmount = $OrderLineRow['unitprice'] * $OrderLineRow['quantity'] *(1- floatval($OrderLineRow['discountpercent'])); /*Gets the Taxes and rates applicable to this line from the TaxGroup of the branch and TaxCategory of the item @@ -731,7 +757,9 @@ ORDER BY taxgrouptaxes.calculationorder"; $GetTaxRatesResult = api_DB_query($SQL,$db,'','',true); - + if (DB_error_no($db) != 0) { + $Errors[] = TaxRatesFailed; + } $LineTaxAmount = 0; $TaxTotals =array(); @@ -762,7 +790,7 @@ 'TaxAuthAmount'=>$TaxAuthAmount); $LineTaxAmount += $TaxAuthAmount; - } + }//end loop around Taxes $LineNetAmount = $OrderLineRow['unitprice'] * $OrderLineRow['quantity'] *(1- floatval($OrderLineRow['discountpercent'])); @@ -774,54 +802,178 @@ SET qtyinvoiced = qtyinvoiced + " . $OrderLineRow['quantity'] . ", actualdispatchdate = '" . $OrderHeader['orddate']. "', completed='1' - WHERE orderno = '" . $OrderNo . "' - AND stkcode = '" . $OrderLineRow['stkcode'] . "'"; + WHERE orderno = '" . $OrderNo . "' + AND stkcode = '" . $OrderLineRow['stkcode'] . "'"; - $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The sales order detail record could not be updated because'); - $DbgMsg = _('The following SQL to update the sales order detail record was used'); - $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); + $Result = api_DB_query($SQL,$db,'','',true); - // Insert stock movements - with unit cost - $LocalCurrencyPrice= ($OrderLineRow['unitprice'] *(1- floatval($OrderLineRow['discountpercent'])))/ $OrderHeader['rate']; + if ($OrderHeader['mbflag']=='B' OR $OrderHeader['mbflag']=='M') { + $Assembly = False; + /* Need to get the current location quantity + will need it later for the stock movement */ + $SQL="SELECT locstock.quantity + FROM locstock + WHERE locstock.stockid='" . $OrderLineRow['stkcode'] . "' + AND loccode= '" . $OrderHeader['fromstkloc'] . "'"; + $Result = api_DB_query($SQL, $db); + if (DB_num_rows($Result)==1){ + $LocQtyRow = DB_fetch_row($Result); + $QtyOnHandPrior = $LocQtyRow[0]; + } else { + /* There must be some error this should never happen */ + $QtyOnHandPrior = 0; + } -/*Can't assume dummy/service items need the cogs stuff here too */ + $SQL = "UPDATE locstock + SET quantity = locstock.quantity - " . $OrderLineRow['quantity'] . " + WHERE locstock.stockid = '" . $OrderLineRow['stkcode'] . "' + AND loccode = '" . $OrderHeader['fromstkloc'] . "'"; + $Result = api_DB_query($SQL,$db,'','',true); + + $SQL = "INSERT INTO stockmoves (stockid, + type, + transno, + loccode, + trandate, + debtorno, + branchcode, + price, + prd, + reference, + qty, + discountpercent, + standardcost, + newqoh) + VALUES ('" . $OrderLineRow['stkcode'] . "', + '10', + '" . $InvoiceNo . "', + '" . $OrderHeader['fromstkloc'] . "', + '" . $OrderHeader['orddate'] . "', + '" . $OrderHeader['debtorno'] . "', + '" . $OrderHeader['branchcode'] . "', + '" . $LocalCurrencyPrice . "', + '" . $PeriodNo . "', + '" . $OrderNo . "', + '" . -$OrderLineRow['quantity'] . "', + '" . $OrderLineRow['discountpercent'] . "', + '" . $StandardCost . "', + '" . ($QtyOnHandPrior - $OrderLineRow['quantity']) . "' )"; + + $Result = api_DB_query($SQL,$db,'','',true); + } else if ($OrderHeader['mbflag']=='A'){ /* its an assembly */ + /*Need to get the BOM for this part and make + stock moves for the components then update the Location stock balances */ + $Assembly=True; + $StandardCost =0; /*To start with - accumulate the cost of the comoponents for use in journals later on */ + $SQL = "SELECT bom.component, + bom.quantity, + stockmaster.materialcost+stockmaster.labourcost+stockmaster.overheadcost AS standard + FROM bom INNER JOIN stockmaster + ON bom.component=stockmaster.stockid + WHERE bom.parent='" . $OrderLineRow['stkcode'] . "' + AND bom.effectiveto >= '" . Date('Y-m-d') . "' + AND bom.effectiveafter < '" . Date('Y-m-d') . "'"; + $AssResult = api_DB_query($SQL,$db); - // its a dummy item dummies always have nil stock (by definition so new qty on hand will be nil - $SQL = "INSERT INTO stockmoves ( - stockid, - type, - transno, - loccode, - trandate, - debtorno, - branchcode, - price, - prd, - reference, - qty, - discountpercent, - standardcost) - VALUES ( - '" . $OrderLineRow['stkcode'] . "', - '10', - '" . $InvoiceNo . "', - '" . $OrderHeader['fromstkloc'] . "', - '" . $OrderHeader['orddate'] . "', - '" . $OrderHeader['debtorno'] . "', - '" . $OrderHeader['branchcode'] . "', - '" . $LocalCurrencyPrice . "', - '" . $PeriodNo . "', - '" . $OrderNo . "', - '" . -$OrderLineRow['quantity'] . "', - '" . $OrderLineRow['discountpercent'] . "', - '0')"; + while ($AssParts = DB_fetch_array($AssResult,$db)){ - $Result = api_DB_query($SQL,$db,'','',true); + $StandardCost += ($AssParts['standard'] * $AssParts['quantity']) ; + /* Need to get the current location quantity + will need it later for the stock movement */ + $SQL="SELECT locstock.quantity + FROM locstock + WHERE locstock.stockid='" . $AssParts['component'] . "' + AND loccode= '" . $OrderHeader['fromstkloc'] . "'"; + $Result = api_DB_query($SQL,$db); + if (DB_num_rows($Result)==1){ + $LocQtyRow = DB_fetch_row($Result); + $QtyOnHandPrior = $LocQtyRow[0]; + } else { + /*There must be some error this should never happen */ + $QtyOnHandPrior = 0; + } + if (empty($AssParts['standard'])) { + $AssParts['standard']=0; + } + $SQL = "INSERT INTO stockmoves (stockid, + type, + transno, + loccode, + trandate, + debtorno, + branchcode, + prd, + reference, + qty, + standardcost, + show_on_inv_crds, + newqoh) + VALUES ('" . $AssParts['component'] . "', + 10, + '" . $InvoiceNo . "', + '" . $OrderHeader['fromstkloc'] . "', + '" . $DefaultDispatchDate . "', + '" . $OrderHeader['debtorno'] . "', + '" . $OrderHeader['branchcode'] . "', + '" . $PeriodNo . "', + '" . _('Assembly') . ': ' . $OrderLineRow['stkcode'] . ' ' . _('Order') . ': ' . $OrderNo . "', + '" . -$AssParts['quantity'] * $OrderLineRow['quantity'] . "', + '" . $AssParts['standard'] . "', + 0, + '" . ($QtyOnHandPrior - $AssParts['quantity'] * $OrderLineRow['quantity']) . "' )"; + + $Result = DB_query($SQL,$db,'','',true); + + $SQL = "UPDATE locstock + SET quantity = locstock.quantity - " . ($AssParts['quantity'] * $OrderLineRow['quantity']) . " + WHERE locstock.stockid = '" . $AssParts['component'] . "' + AND loccode = '" . $OrderHeader['fromlocstk'] . "'"; + + $Result = DB_query($SQL,$db,'','',true); + } /* end of assembly explosion and updates */ + } /* end of its an assembly */ + + // Insert stock movements - with unit cost + $LocalCurrencyPrice= ($OrderLineRow['unitprice'] *(1- floatval($OrderLineRow['discountpercent'])))/ $OrderHeader['rate']; + if ($OrderHeader['mbflag']=='A' OR $OrderHeader['mbflag']=='D'){ + /*it's a Dummy/Service item or an Assembly item - still need stock movement record + * but quantites on hand are always nil */ + $SQL = "INSERT INTO stockmoves (stockid, + type, + transno, + loccode, + trandate, + debtorno, + branchcode, + price, + prd, + reference, + qty, + discountpercent, + standardcost, + newqoh) + VALUES ('" . $OrderLineRow['stkcode'] . "', + '10', + '" . $InvoiceNo . "', + '" . $OrderHeader['fromstkloc'] . "', + '" . $OrderHeader['orddate'] . "', + '" . $OrderHeader['debtorno'] . "', + '" . $OrderHeader['branchcode'] . "', + '" . $LocalCurrencyPrice . "', + '" . $PeriodNo . "', + '" . $OrderNo . "', + '" . -$OrderLineRow['quantity'] . "', + '" . $OrderLineRow['discountpercent'] . "', + '" . $StandardCost . "', + '0' )"; + + $Result = api_DB_query($SQL,$db,'','',true); + } /*Get the ID of the StockMove... */ $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); @@ -839,9 +991,7 @@ '" . $Tax['TaxCalculationOrder'] . "', '" . $Tax['TaxOnTax'] . "')"; - $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Taxes and rates applicable to this invoice line item could not be inserted because'); - $DbgMsg = _('The following SQL to insert the stock movement tax detail records was used'); - $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); + $Result = DB_query($SQL,$db,'','',true); } /*Insert Sales Analysis records */ @@ -936,10 +1086,52 @@ $Result = api_DB_query($SQL,$db,'','',true); + if ($CompanyRecord['gllink_stock']==1 AND $StandardCost !=0){ + +/*first the cost of sales entry - GL accounts are retrieved using the function GetCOGSGLAccount from includes/GetSalesTransGLCodes.inc */ + + $SQL = "INSERT INTO gltrans (type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (10, + '" . $InvoiceNo . "', + '" . $OrderHeader['orddate'] . "', + '" . $PeriodNo . "', + '" . GetCOGSGLAccount($OrderHeader['area'], $OrderLineRow['stkcode'], $OrderHeader['ordertype'], $db) . "', + '" . $OrderHeader['debtorno'] . " - " . $OrderLineRow['stkcode'] . " x " . $OrderLineRow['quantity'] . " @ " . $StandardCost . "', + '" . ($StandardCost * $OrderLineRow['quantity']) . "')"; + + $Result = api_DB_query($SQL,$db,'','',true); + +/*now the stock entry - this is set to the cost act in the case of a fixed asset disposal */ + $StockGLCode = GetStockGLCode($OrderLineRow['stkcode'],$db); + + $SQL = "INSERT INTO gltrans (type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (10, + '" . $InvoiceNo . "', + '" . $OrderHeader['orddate'] . "', + '" . $PeriodNo . "', + '" . $StockGLCode['stockact'] . "', + '" . $OrderHeader['debtorno'] . " - " . $OrderLineRow['stkcode'] . " x " . $OrderLineRow['quantity'] . " @ " . $StandardCost . "', + '" . (-$StandardCost * $OrderLineRow['quantity']) . "')"; + + $Result = api_DB_query($SQL,$db,'','',true); + } /* end of if GL and stock integrated and standard cost !=0 and not an asset */ + if ($CompanyRecord['gllink_debtors']==1 AND $OrderLineRow['unitprice'] !=0){ //Post sales transaction to GL credit sales - $SalesGLAccounts = GetSalesGLAccount($Area, $OrderLineRow['stkcode'], $OrderHeader['ordertype'], $db); + $SalesGLAccounts = GetSalesGLAccount($OrderHeader['area'], $OrderLineRow['stkcode'], $OrderHeader['ordertype'], $db); $SQL = "INSERT INTO gltrans (type, typeno, @@ -958,28 +1150,6 @@ )"; $Result = api_DB_query($SQL,$db,'','',true); - /* We also need the COGS stuff in here */ - - - - - - - - - - - - - - - - - - - - - if ($OrderLineRow['discountpercent'] !=0){ $SQL = "INSERT INTO gltrans (type, @@ -989,21 +1159,20 @@ account, narrative, amount) - VALUES ('10', - '" . $InvoiceNo . "', - '" . $OrderHeader['orddate'] . "', - '" . $PeriodNo . "', - '" . $SalesGLAccounts['discountglcode'] . "', - '" . $OrderHeader['debtorno'] . " - " . $OrderLineRow['stkcode'] . ' @ ' . ($OrderLineRow['discountpercent'] * 100) . "%', - '" . $OrderLineRow['unitprice'] * $OrderLineRow['quantity'] * $OrderLineRow['discountpercent']/$OrderHeader['rate'] . "' )"; + VALUES (10, + '" . $InvoiceNo . "', + '" . $OrderHeader['orddate'] . "', + '" . $PeriodNo . "', + '" . $SalesGLAccounts['discountglcode'] . "', + '" . $OrderHeader['debtorno'] . " - " . $OrderLineRow['stkcode'] . " @ " . ($OrderLineRow['discountpercent'] * 100) . "%', + '" . ($OrderLineRow['unitprice'] * $OrderLineRow['quantity'] * $OrderLineRow['discountpercent']/$OrderHeader['rate']) . "')"; - $Result = api_DB_query($SQL,$db,'','',true); - + $Result = DB_query($SQL,$db,'','',true); } /*end of if discount !=0 */ } /*end of if sales integrated with gl */ - $LineCounter++; + $LineCounter++; //needed for the array of taxes by line } /*end of OrderLine loop */ $TotalInvLocalCurr = ($TotalFXNetInvoice + $TotalFXTax)/$OrderHeader['rate']; @@ -1054,8 +1223,7 @@ $Result = api_DB_query($SQL,$db,'','',true); } - - + EnsureGLEntriesBalance(10,$InvoiceNo,$db); } /*end of if Sales and GL integrated */ /*Update order header for invoice charged on */ @@ -1099,29 +1267,26 @@ $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); /*for each Tax - need to insert into debtortranstaxes */ - - - - $SQL = "INSERT INTO debtortranstaxes (debtortransid, - taxauthid, - taxamount) - VALUES ('" . $DebtorTransID . "', - '" . $TaxAuthID . "', - '" . $Tax['FXAmount']/$OrderHeader['rate'] . "')"; + foreach ($TaxTotals AS $TaxAuthID => $TaxAmount) { - $Result = api_DB_query($SQL,$db,'','',true); - - $Result = DB_Txn_Commit($db); + $SQL = "INSERT INTO debtortranstaxes (debtortransid, + taxauthid, + taxamount) + VALUES ('" . $DebtorTransID . "', + '" . $TaxAuthID . "', + '" . $TaxAmount/$OrderHeader['rate'] . "')"; + $Result = api_DB_query($SQL,$db,'','',true); + } if (sizeof($Errors)==0) { + $Result = DB_Txn_Commit($db); $Errors[0]=0; $Errors[1]=$InvoiceNo; - } + } else { + $Result = DB_Txn_Rollback($db); + } return $Errors; - - - - } + } //end InvoiceSalesOrder function function GetCurrentPeriod (&$db) { @@ -1206,31 +1371,4 @@ return $myrow[0]; } - function PeriodExists($TransDate, &$db) { - - /* Find the date a month on */ - $MonthAfterTransDate = Mktime(0,0,0,Date('m',$TransDate)+1,Date('d',$TransDate),Date('Y',$TransDate)); - - $GetPrdSQL = "SELECT periodno FROM periods WHERE lastdate_in_period < '" . Date('Y/m/d', $MonthAfterTransDate) . "' AND lastdate_in_period >= '" . Date('Y/m/d', $TransDate) . "'"; - - $GetPrdResult = api_DB_query($GetPrdSQL,$db,$ErrMsg); - - if (DB_num_rows($GetPrdResult)==0) { - return false; - } else { - return true; - } - - } - - function CreatePeriod($PeriodNo, $PeriodEnd, &$db) { - $InsertPrdSQL = "INSERT INTO periods (periodno, - lastdate_in_period) - VALUES ('" . $PeriodNo . "', - '" . Date('Y-m-d', $PeriodEnd) . "')"; - - $InsertPrdResult = api_DB_query($InsertPrdSQL, $db); - } - - ?> \ No newline at end of file Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-01-29 09:03:14 UTC (rev 4849) +++ trunk/api/api_xml-rpc.php 2012-01-29 09:42:44 UTC (rev 4850) @@ -518,12 +518,10 @@ function xmlrpc_GetHoldReasonList($xmlrpcmsg){ ob_start('ob_file_callback'); -/*x*/ if ($xmlrpcmsg->getNumParams() == 2) -/*x*/ { -/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonList($xmlrpcmsg->getParam( 0 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ))) ); +/*x*/ if ($xmlrpcmsg->getNumParams() == 2) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonList($xmlrpcmsg->getParam( 0 )->scalarval( ), $xmlrpcmsg->getParam( 1 )->scalarval( ))) ); /*x*/ } else { -/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonList( '', ''))); + $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonList( '', ''))); /*x*/ } ob_end_flush(); return $rtn; @@ -548,11 +546,8 @@ function xmlrpc_GetHoldReasonDetails($xmlrpcmsg){ ob_start('ob_file_callback'); -/*x*/ if ($xmlrpcmsg->getNumParams() == 3) -/*x*/ { -/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), $xmlrpcmsg->getParam( 1 )->scalarval( ),$xmlrpcmsg->getParam( 2 )->scalarval( ))) ); /*x*/ } else { /*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); /*x*/ } @@ -1149,8 +1144,7 @@ function xmlrpc_InsertSalesOrderHeader($xmlrpcmsg){ ob_start('ob_file_callback'); -/*x*/ if ($xmlrpcmsg->getNumParams() == 3) -/*x*/ { +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) { /*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(InsertSalesOrderHeader(php_xmlrpc_decode($xmlrpcmsg->getParam( 0 )), /*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), /*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); @@ -1165,6 +1159,36 @@ unset($Parameter); unset($ReturnValue); + $Description = 'This function is used to invoice a sales order for the full quantity on the order assuming it is all dispatched. NB It does not deal with serialised/controlled items.'; + $Parameter[0]['name'] = _('Sales Order to invoice'); + $Parameter[0]['description'] = _('An integer representing the webERP sales order number'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('If successful this function returns a two element array; the first element is 0 for success or an error code, while the second element is the invoice number.'); + +/*E*/$InvoiceSalesOrder_sig = array(array($xmlrpcStruct,$xmlrpcStruct), +/*x*/ array($xmlrpcStruct,$xmlrpcStruct,$xmlrpcString,$xmlrpcString)); + $InvoiceSalesOrder_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_InvoiceSalesOrder($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(InvoiceSalesOrder($xmlrpcmsg->getParam( 0 )->scalarval( ), $xmlrpcmsg->getParam( 1 )->scalarval( ), $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); + } else { //do it with the current login +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(InvoiceSalesOrder($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + + + $Description = 'This function is used to modify the header details of a sales order'; $Parameter[0]['name'] = _('Modify Sales Order Header Details'); $Parameter[0]['description'] = _('A set of key/value pairs where the key must be identical to the name of the field to be updated. ') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-01-29 09:42:51
|
Revision: 4850 http://web-erp.svn.sourceforge.net/web-erp/?rev=4850&view=rev Author: daintree Date: 2012-01-29 09:42:44 +0000 (Sun, 29 Jan 2012) Log Message: ----------- extended API to create invoices from salesorders Modified Paths: -------------- trunk/api/api_errorcodes.php trunk/api/api_php.php trunk/api/api_salesorders.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_errorcodes.php =================================================================== --- trunk/api/api_errorcodes.php 2012-01-29 09:03:14 UTC (rev 4849) +++ trunk/api/api_errorcodes.php 2012-01-29 09:42:44 UTC (rev 4850) @@ -160,6 +160,12 @@ Define('BatchIsEmpty', 1155); Define('NoSuchArea', 1156); Define('NoSuchSalesMan', 1157); + Define('NoCompanyRecord',1158); + Define('NoReadOrder',1159); + Define('NoReadOrderLines',1160); + Define('NoTaxProvince',1161); + Define('TaxRatesFailed',1162); + /* Array of Descriptions of errors */ $ErrorDescription['1'] = _('No Authorisation'); @@ -320,5 +326,10 @@ $ErrorDescription['1155'] = _('Batch is empty'); $ErrorDescription['1156'] = _('No such area'); $ErrorDescription['1157'] = _('No such salesman'); + $ErrorDescription['1158'] = _('Unable to read company record'); + $ErrorDescription['1159'] = _('Unable to read sales order'); + $ErrorDescription['1160'] = _('Unable to read sales order lines'); + $ErrorDescription['1161'] = _('Unable to get tax province of location'); + $ErrorDescription['1162'] = _('Unable to read tax rates for this item and tax group'); ?> \ No newline at end of file Modified: trunk/api/api_php.php =================================================================== --- trunk/api/api_php.php 2012-01-29 09:03:14 UTC (rev 4849) +++ trunk/api/api_php.php 2012-01-29 09:42:44 UTC (rev 4850) @@ -14,7 +14,7 @@ /* Include SQL_CommonFunctions.inc, to use GetNextTransNo().*/ include($PathPrefix . 'includes/SQL_CommonFunctions.inc'); /* Required for creating invoices/credits */ - include($PathPrefix . 'includes/GetSalesTransGLCode.inc'); + include($PathPrefix . 'includes/GetSalesTransGLCodes.inc'); /* Get weberp authentication, and return a valid database connection */ @@ -22,7 +22,7 @@ if (!isset($_SESSION['AccessLevel']) OR $_SESSION['AccessLevel'] == '') { // Login to default database = old clients. - if ($user != '' && $password != '') { + if ($user != '' AND $password != '') { global $api_DatabaseName; $rc = LoginAPI ($api_DatabaseName, $user, $password); if ($rc[0] == UL_OK ) { Modified: trunk/api/api_salesorders.php =================================================================== --- trunk/api/api_salesorders.php 2012-01-29 09:03:14 UTC (rev 4849) +++ trunk/api/api_salesorders.php 2012-01-29 09:42:44 UTC (rev 4850) @@ -116,15 +116,15 @@ /* Check that the delivery date is a valid date. The date * must be in the same format as the date format specified in the * target webERP company */ - function VerifyDeliveryDate($deliverydate, $i, $Errors, $db) { + function VerifyDeliveryDate($DeliveryDate, $i, $Errors, $db) { $sql="SELECT confvalue FROM config WHERE confname='DefaultDateFormat'"; $result=api_DB_query($sql, $db); $myrow=DB_fetch_array($result); $DateFormat=$myrow[0]; - if (mb_strstr($deliverydate,'/')) { - $DateArray = explode('/',$deliverydate); + if (mb_strstr($DeliveryDate,'/')) { + $DateArray = explode('/',$DeliveryDate); } elseif (mb_strstr($PeriodEnd,'.')) { - $DateArray = explode('.',$deliverydate); + $DateArray = explode('.',$DeliveryDate); } if ($DateFormat=='d/m/Y') { $Day=$DateArray[0]; @@ -349,10 +349,6 @@ VALUES (" . mb_substr($FieldValues,0,-2). ")"; if (sizeof($Errors)==0) { - /*debug info to file - $fp = fopen( '/root/Web-Server/apidebug/api-sql.sql', "w"); - fputs($fp, $sql); - */ $result = api_DB_Query($sql, $db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; @@ -464,6 +460,7 @@ * already exist in webERP. */ function InsertSalesOrderLine($OrderLine, $user, $password) { + $Errors = array(); $db = db($user, $password); if (gettype($db)=='integer') { @@ -610,6 +607,7 @@ then it returns an $Errors array. */ function GetSalesOrderLine($OrderNo, $user, $password) { + $Errors = array(); $db = db($user, $password); if (gettype($db)=='integer') { @@ -631,8 +629,12 @@ function InvoiceSalesOrder($OrderNo, $User, $Password) { + /*debug info to file */ + $fp = fopen( '/root/Web-Server/apidebug/debuginfo.txt', "w"); + fputs($fp, 'starting to invoice order ' . $OrderNo); + $Errors = array(); - $db = db($user, $password); + $db = db($User, $Password); if (gettype($db)=='integer') { $Errors[0]=NoAuthorisation; return $Errors; @@ -648,68 +650,92 @@ gllink_debtors, gllink_stock FROM companies - WHERE coycode=1";,$db); + WHERE coycode=1",$db); $CompanyRecord = DB_fetch_array($ReadCoyResult); - + if (DB_error_no($db) != 0) { + $Errors[] = NoCompanyRecord; + } + + fputs($fp, 'Got company info' . "\n"); + $OrderHeaderSQL = "SELECT salesorders.debtorno, - debtorsmaster.name, - salesorders.branchcode, - salesorders.customerref, - salesorders.orddate, - salesorders.ordertype, - salesorders.shipvia, - custbranch.area, - custbranch.taxgroupid, - debtorsmaster.currcode, - currencies.rate, - salesorders.fromstkloc, - custbranch.salesman - FROM salesorders - INNER JOIN debtorsmaster - ON salesorders.debtorno = debtorsmaster.debtorno - INNER JOIN custbranch - ON salesorders.debtorno = custbranch.debtorno - AND salesorders.branchcode = custbranch.branchcode - INNER JOIN locations - ON locations.loccode=salesorders.fromstkloc - INNER JOIN currencies - ON debtorsmaster.currcode=currencies.currabrev - WHERE salesorders.orderno = '" . $OrderNumber . "'"; + debtorsmaster.name, + salesorders.branchcode, + salesorders.customerref, + salesorders.orddate, + salesorders.ordertype, + salesorders.shipvia, + custbranch.area, + custbranch.taxgroupid, + debtorsmaster.currcode, + currencies.rate, + salesorders.fromstkloc, + custbranch.salesman + FROM salesorders + INNER JOIN debtorsmaster + ON salesorders.debtorno = debtorsmaster.debtorno + INNER JOIN custbranch + ON salesorders.debtorno = custbranch.debtorno + AND salesorders.branchcode = custbranch.branchcode + INNER JOIN locations + ON locations.loccode=salesorders.fromstkloc + INNER JOIN currencies + ON debtorsmaster.currcode=currencies.currabrev + WHERE salesorders.orderno = '" . $OrderNumber . "'"; $OrderHeaderResult = api_DB_query($OrderHeaderSQL,$db); + if (DB_error_no($db) != 0) { + $Errors[] = NoReadOrder; + } + + fputs($fp, 'Got order header' . "\n"); + $OrderHeader = DB_fetch_array($OrderHeaderResult); $TaxProvResult = api_DB_query("SELECT taxprovinceid FROM locations WHERE loccode='" . $OrderHeader['fromstkloc'] ."'",$db); $Result = api_DB_query($SQL,$db); + if (DB_error_no($db) != 0) { + $Errors[] = NoTaxProvince; + } $myrow = DB_fetch_row($Result); $DispTaxProvinceID = $myrow[0]; - - $LineItemsSQL = "SELECT stkcode, unitprice, quantity, discountpercent, - taxcatid + taxcatid, + mbflag, + materialcost+labourcost+overheadcost AS standardcost FROM salesorderdetails INNER JOIN stockmaster ON salesorderdetails.stkcode = stockmaster.stockid - WHERE orderno ='" . $OrderNo . "'"; + WHERE orderno ='" . $OrderNo . "' + AND completed=0"; $LineItemsResult = api_DB_query($LineItemsSQL,$db); - + if (DB_error_no($db) != 0 OR DB_num_rows($LineItemsResult)==0) { + $Errors[] = NoReadOrderLines; + return $Errors; + } + fputs($fp, 'Got order line items' . "\n"); + /*Start an SQL transaction */ $result = DB_Txn_Begin($db); /*Now Get the next invoice number - function in SQL_CommonFunctions*/ $InvoiceNo = GetNextTransNo(10, $db); $PeriodNo = GetCurrentPeriod($db); + fputs($fp, 'Got invoice number ' . $InvoiceNo . "\n and into PeriodNo " . $PeriodNo . "\n"); + $TotalFXNetInvoice = 0; $TotalFXTax = 0; $LineCounter =0; while ($OrderLineRow = DB_fetch_array($LineItemsResult)) { - + + $StandardCost = $OrderLineRow['standardcost']; + $LineNetAmount = $OrderLineRow['unitprice'] * $OrderLineRow['quantity'] *(1- floatval($OrderLineRow['discountpercent'])); /*Gets the Taxes and rates applicable to this line from the TaxGroup of the branch and TaxCategory of the item @@ -731,7 +757,9 @@ ORDER BY taxgrouptaxes.calculationorder"; $GetTaxRatesResult = api_DB_query($SQL,$db,'','',true); - + if (DB_error_no($db) != 0) { + $Errors[] = TaxRatesFailed; + } $LineTaxAmount = 0; $TaxTotals =array(); @@ -762,7 +790,7 @@ 'TaxAuthAmount'=>$TaxAuthAmount); $LineTaxAmount += $TaxAuthAmount; - } + }//end loop around Taxes $LineNetAmount = $OrderLineRow['unitprice'] * $OrderLineRow['quantity'] *(1- floatval($OrderLineRow['discountpercent'])); @@ -774,54 +802,178 @@ SET qtyinvoiced = qtyinvoiced + " . $OrderLineRow['quantity'] . ", actualdispatchdate = '" . $OrderHeader['orddate']. "', completed='1' - WHERE orderno = '" . $OrderNo . "' - AND stkcode = '" . $OrderLineRow['stkcode'] . "'"; + WHERE orderno = '" . $OrderNo . "' + AND stkcode = '" . $OrderLineRow['stkcode'] . "'"; - $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The sales order detail record could not be updated because'); - $DbgMsg = _('The following SQL to update the sales order detail record was used'); - $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); + $Result = api_DB_query($SQL,$db,'','',true); - // Insert stock movements - with unit cost - $LocalCurrencyPrice= ($OrderLineRow['unitprice'] *(1- floatval($OrderLineRow['discountpercent'])))/ $OrderHeader['rate']; + if ($OrderHeader['mbflag']=='B' OR $OrderHeader['mbflag']=='M') { + $Assembly = False; + /* Need to get the current location quantity + will need it later for the stock movement */ + $SQL="SELECT locstock.quantity + FROM locstock + WHERE locstock.stockid='" . $OrderLineRow['stkcode'] . "' + AND loccode= '" . $OrderHeader['fromstkloc'] . "'"; + $Result = api_DB_query($SQL, $db); + if (DB_num_rows($Result)==1){ + $LocQtyRow = DB_fetch_row($Result); + $QtyOnHandPrior = $LocQtyRow[0]; + } else { + /* There must be some error this should never happen */ + $QtyOnHandPrior = 0; + } -/*Can't assume dummy/service items need the cogs stuff here too */ + $SQL = "UPDATE locstock + SET quantity = locstock.quantity - " . $OrderLineRow['quantity'] . " + WHERE locstock.stockid = '" . $OrderLineRow['stkcode'] . "' + AND loccode = '" . $OrderHeader['fromstkloc'] . "'"; + $Result = api_DB_query($SQL,$db,'','',true); + + $SQL = "INSERT INTO stockmoves (stockid, + type, + transno, + loccode, + trandate, + debtorno, + branchcode, + price, + prd, + reference, + qty, + discountpercent, + standardcost, + newqoh) + VALUES ('" . $OrderLineRow['stkcode'] . "', + '10', + '" . $InvoiceNo . "', + '" . $OrderHeader['fromstkloc'] . "', + '" . $OrderHeader['orddate'] . "', + '" . $OrderHeader['debtorno'] . "', + '" . $OrderHeader['branchcode'] . "', + '" . $LocalCurrencyPrice . "', + '" . $PeriodNo . "', + '" . $OrderNo . "', + '" . -$OrderLineRow['quantity'] . "', + '" . $OrderLineRow['discountpercent'] . "', + '" . $StandardCost . "', + '" . ($QtyOnHandPrior - $OrderLineRow['quantity']) . "' )"; + + $Result = api_DB_query($SQL,$db,'','',true); + } else if ($OrderHeader['mbflag']=='A'){ /* its an assembly */ + /*Need to get the BOM for this part and make + stock moves for the components then update the Location stock balances */ + $Assembly=True; + $StandardCost =0; /*To start with - accumulate the cost of the comoponents for use in journals later on */ + $SQL = "SELECT bom.component, + bom.quantity, + stockmaster.materialcost+stockmaster.labourcost+stockmaster.overheadcost AS standard + FROM bom INNER JOIN stockmaster + ON bom.component=stockmaster.stockid + WHERE bom.parent='" . $OrderLineRow['stkcode'] . "' + AND bom.effectiveto >= '" . Date('Y-m-d') . "' + AND bom.effectiveafter < '" . Date('Y-m-d') . "'"; + $AssResult = api_DB_query($SQL,$db); - // its a dummy item dummies always have nil stock (by definition so new qty on hand will be nil - $SQL = "INSERT INTO stockmoves ( - stockid, - type, - transno, - loccode, - trandate, - debtorno, - branchcode, - price, - prd, - reference, - qty, - discountpercent, - standardcost) - VALUES ( - '" . $OrderLineRow['stkcode'] . "', - '10', - '" . $InvoiceNo . "', - '" . $OrderHeader['fromstkloc'] . "', - '" . $OrderHeader['orddate'] . "', - '" . $OrderHeader['debtorno'] . "', - '" . $OrderHeader['branchcode'] . "', - '" . $LocalCurrencyPrice . "', - '" . $PeriodNo . "', - '" . $OrderNo . "', - '" . -$OrderLineRow['quantity'] . "', - '" . $OrderLineRow['discountpercent'] . "', - '0')"; + while ($AssParts = DB_fetch_array($AssResult,$db)){ - $Result = api_DB_query($SQL,$db,'','',true); + $StandardCost += ($AssParts['standard'] * $AssParts['quantity']) ; + /* Need to get the current location quantity + will need it later for the stock movement */ + $SQL="SELECT locstock.quantity + FROM locstock + WHERE locstock.stockid='" . $AssParts['component'] . "' + AND loccode= '" . $OrderHeader['fromstkloc'] . "'"; + $Result = api_DB_query($SQL,$db); + if (DB_num_rows($Result)==1){ + $LocQtyRow = DB_fetch_row($Result); + $QtyOnHandPrior = $LocQtyRow[0]; + } else { + /*There must be some error this should never happen */ + $QtyOnHandPrior = 0; + } + if (empty($AssParts['standard'])) { + $AssParts['standard']=0; + } + $SQL = "INSERT INTO stockmoves (stockid, + type, + transno, + loccode, + trandate, + debtorno, + branchcode, + prd, + reference, + qty, + standardcost, + show_on_inv_crds, + newqoh) + VALUES ('" . $AssParts['component'] . "', + 10, + '" . $InvoiceNo . "', + '" . $OrderHeader['fromstkloc'] . "', + '" . $DefaultDispatchDate . "', + '" . $OrderHeader['debtorno'] . "', + '" . $OrderHeader['branchcode'] . "', + '" . $PeriodNo . "', + '" . _('Assembly') . ': ' . $OrderLineRow['stkcode'] . ' ' . _('Order') . ': ' . $OrderNo . "', + '" . -$AssParts['quantity'] * $OrderLineRow['quantity'] . "', + '" . $AssParts['standard'] . "', + 0, + '" . ($QtyOnHandPrior - $AssParts['quantity'] * $OrderLineRow['quantity']) . "' )"; + + $Result = DB_query($SQL,$db,'','',true); + + $SQL = "UPDATE locstock + SET quantity = locstock.quantity - " . ($AssParts['quantity'] * $OrderLineRow['quantity']) . " + WHERE locstock.stockid = '" . $AssParts['component'] . "' + AND loccode = '" . $OrderHeader['fromlocstk'] . "'"; + + $Result = DB_query($SQL,$db,'','',true); + } /* end of assembly explosion and updates */ + } /* end of its an assembly */ + + // Insert stock movements - with unit cost + $LocalCurrencyPrice= ($OrderLineRow['unitprice'] *(1- floatval($OrderLineRow['discountpercent'])))/ $OrderHeader['rate']; + if ($OrderHeader['mbflag']=='A' OR $OrderHeader['mbflag']=='D'){ + /*it's a Dummy/Service item or an Assembly item - still need stock movement record + * but quantites on hand are always nil */ + $SQL = "INSERT INTO stockmoves (stockid, + type, + transno, + loccode, + trandate, + debtorno, + branchcode, + price, + prd, + reference, + qty, + discountpercent, + standardcost, + newqoh) + VALUES ('" . $OrderLineRow['stkcode'] . "', + '10', + '" . $InvoiceNo . "', + '" . $OrderHeader['fromstkloc'] . "', + '" . $OrderHeader['orddate'] . "', + '" . $OrderHeader['debtorno'] . "', + '" . $OrderHeader['branchcode'] . "', + '" . $LocalCurrencyPrice . "', + '" . $PeriodNo . "', + '" . $OrderNo . "', + '" . -$OrderLineRow['quantity'] . "', + '" . $OrderLineRow['discountpercent'] . "', + '" . $StandardCost . "', + '0' )"; + + $Result = api_DB_query($SQL,$db,'','',true); + } /*Get the ID of the StockMove... */ $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno'); @@ -839,9 +991,7 @@ '" . $Tax['TaxCalculationOrder'] . "', '" . $Tax['TaxOnTax'] . "')"; - $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Taxes and rates applicable to this invoice line item could not be inserted because'); - $DbgMsg = _('The following SQL to insert the stock movement tax detail records was used'); - $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); + $Result = DB_query($SQL,$db,'','',true); } /*Insert Sales Analysis records */ @@ -936,10 +1086,52 @@ $Result = api_DB_query($SQL,$db,'','',true); + if ($CompanyRecord['gllink_stock']==1 AND $StandardCost !=0){ + +/*first the cost of sales entry - GL accounts are retrieved using the function GetCOGSGLAccount from includes/GetSalesTransGLCodes.inc */ + + $SQL = "INSERT INTO gltrans (type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (10, + '" . $InvoiceNo . "', + '" . $OrderHeader['orddate'] . "', + '" . $PeriodNo . "', + '" . GetCOGSGLAccount($OrderHeader['area'], $OrderLineRow['stkcode'], $OrderHeader['ordertype'], $db) . "', + '" . $OrderHeader['debtorno'] . " - " . $OrderLineRow['stkcode'] . " x " . $OrderLineRow['quantity'] . " @ " . $StandardCost . "', + '" . ($StandardCost * $OrderLineRow['quantity']) . "')"; + + $Result = api_DB_query($SQL,$db,'','',true); + +/*now the stock entry - this is set to the cost act in the case of a fixed asset disposal */ + $StockGLCode = GetStockGLCode($OrderLineRow['stkcode'],$db); + + $SQL = "INSERT INTO gltrans (type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (10, + '" . $InvoiceNo . "', + '" . $OrderHeader['orddate'] . "', + '" . $PeriodNo . "', + '" . $StockGLCode['stockact'] . "', + '" . $OrderHeader['debtorno'] . " - " . $OrderLineRow['stkcode'] . " x " . $OrderLineRow['quantity'] . " @ " . $StandardCost . "', + '" . (-$StandardCost * $OrderLineRow['quantity']) . "')"; + + $Result = api_DB_query($SQL,$db,'','',true); + } /* end of if GL and stock integrated and standard cost !=0 and not an asset */ + if ($CompanyRecord['gllink_debtors']==1 AND $OrderLineRow['unitprice'] !=0){ //Post sales transaction to GL credit sales - $SalesGLAccounts = GetSalesGLAccount($Area, $OrderLineRow['stkcode'], $OrderHeader['ordertype'], $db); + $SalesGLAccounts = GetSalesGLAccount($OrderHeader['area'], $OrderLineRow['stkcode'], $OrderHeader['ordertype'], $db); $SQL = "INSERT INTO gltrans (type, typeno, @@ -958,28 +1150,6 @@ )"; $Result = api_DB_query($SQL,$db,'','',true); - /* We also need the COGS stuff in here */ - - - - - - - - - - - - - - - - - - - - - if ($OrderLineRow['discountpercent'] !=0){ $SQL = "INSERT INTO gltrans (type, @@ -989,21 +1159,20 @@ account, narrative, amount) - VALUES ('10', - '" . $InvoiceNo . "', - '" . $OrderHeader['orddate'] . "', - '" . $PeriodNo . "', - '" . $SalesGLAccounts['discountglcode'] . "', - '" . $OrderHeader['debtorno'] . " - " . $OrderLineRow['stkcode'] . ' @ ' . ($OrderLineRow['discountpercent'] * 100) . "%', - '" . $OrderLineRow['unitprice'] * $OrderLineRow['quantity'] * $OrderLineRow['discountpercent']/$OrderHeader['rate'] . "' )"; + VALUES (10, + '" . $InvoiceNo . "', + '" . $OrderHeader['orddate'] . "', + '" . $PeriodNo . "', + '" . $SalesGLAccounts['discountglcode'] . "', + '" . $OrderHeader['debtorno'] . " - " . $OrderLineRow['stkcode'] . " @ " . ($OrderLineRow['discountpercent'] * 100) . "%', + '" . ($OrderLineRow['unitprice'] * $OrderLineRow['quantity'] * $OrderLineRow['discountpercent']/$OrderHeader['rate']) . "')"; - $Result = api_DB_query($SQL,$db,'','',true); - + $Result = DB_query($SQL,$db,'','',true); } /*end of if discount !=0 */ } /*end of if sales integrated with gl */ - $LineCounter++; + $LineCounter++; //needed for the array of taxes by line } /*end of OrderLine loop */ $TotalInvLocalCurr = ($TotalFXNetInvoice + $TotalFXTax)/$OrderHeader['rate']; @@ -1054,8 +1223,7 @@ $Result = api_DB_query($SQL,$db,'','',true); } - - + EnsureGLEntriesBalance(10,$InvoiceNo,$db); } /*end of if Sales and GL integrated */ /*Update order header for invoice charged on */ @@ -1099,29 +1267,26 @@ $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); /*for each Tax - need to insert into debtortranstaxes */ - - - - $SQL = "INSERT INTO debtortranstaxes (debtortransid, - taxauthid, - taxamount) - VALUES ('" . $DebtorTransID . "', - '" . $TaxAuthID . "', - '" . $Tax['FXAmount']/$OrderHeader['rate'] . "')"; + foreach ($TaxTotals AS $TaxAuthID => $TaxAmount) { - $Result = api_DB_query($SQL,$db,'','',true); - - $Result = DB_Txn_Commit($db); + $SQL = "INSERT INTO debtortranstaxes (debtortransid, + taxauthid, + taxamount) + VALUES ('" . $DebtorTransID . "', + '" . $TaxAuthID . "', + '" . $TaxAmount/$OrderHeader['rate'] . "')"; + $Result = api_DB_query($SQL,$db,'','',true); + } if (sizeof($Errors)==0) { + $Result = DB_Txn_Commit($db); $Errors[0]=0; $Errors[1]=$InvoiceNo; - } + } else { + $Result = DB_Txn_Rollback($db); + } return $Errors; - - - - } + } //end InvoiceSalesOrder function function GetCurrentPeriod (&$db) { @@ -1206,31 +1371,4 @@ return $myrow[0]; } - function PeriodExists($TransDate, &$db) { - - /* Find the date a month on */ - $MonthAfterTransDate = Mktime(0,0,0,Date('m',$TransDate)+1,Date('d',$TransDate),Date('Y',$TransDate)); - - $GetPrdSQL = "SELECT periodno FROM periods WHERE lastdate_in_period < '" . Date('Y/m/d', $MonthAfterTransDate) . "' AND lastdate_in_period >= '" . Date('Y/m/d', $TransDate) . "'"; - - $GetPrdResult = api_DB_query($GetPrdSQL,$db,$ErrMsg); - - if (DB_num_rows($GetPrdResult)==0) { - return false; - } else { - return true; - } - - } - - function CreatePeriod($PeriodNo, $PeriodEnd, &$db) { - $InsertPrdSQL = "INSERT INTO periods (periodno, - lastdate_in_period) - VALUES ('" . $PeriodNo . "', - '" . Date('Y-m-d', $PeriodEnd) . "')"; - - $InsertPrdResult = api_DB_query($InsertPrdSQL, $db); - } - - ?> \ No newline at end of file Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-01-29 09:03:14 UTC (rev 4849) +++ trunk/api/api_xml-rpc.php 2012-01-29 09:42:44 UTC (rev 4850) @@ -518,12 +518,10 @@ function xmlrpc_GetHoldReasonList($xmlrpcmsg){ ob_start('ob_file_callback'); -/*x*/ if ($xmlrpcmsg->getNumParams() == 2) -/*x*/ { -/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonList($xmlrpcmsg->getParam( 0 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ))) ); +/*x*/ if ($xmlrpcmsg->getNumParams() == 2) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonList($xmlrpcmsg->getParam( 0 )->scalarval( ), $xmlrpcmsg->getParam( 1 )->scalarval( ))) ); /*x*/ } else { -/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonList( '', ''))); + $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonList( '', ''))); /*x*/ } ob_end_flush(); return $rtn; @@ -548,11 +546,8 @@ function xmlrpc_GetHoldReasonDetails($xmlrpcmsg){ ob_start('ob_file_callback'); -/*x*/ if ($xmlrpcmsg->getNumParams() == 3) -/*x*/ { -/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), $xmlrpcmsg->getParam( 1 )->scalarval( ),$xmlrpcmsg->getParam( 2 )->scalarval( ))) ); /*x*/ } else { /*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetHoldReasonDetails($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); /*x*/ } @@ -1149,8 +1144,7 @@ function xmlrpc_InsertSalesOrderHeader($xmlrpcmsg){ ob_start('ob_file_callback'); -/*x*/ if ($xmlrpcmsg->getNumParams() == 3) -/*x*/ { +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) { /*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(InsertSalesOrderHeader(php_xmlrpc_decode($xmlrpcmsg->getParam( 0 )), /*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), /*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); @@ -1165,6 +1159,36 @@ unset($Parameter); unset($ReturnValue); + $Description = 'This function is used to invoice a sales order for the full quantity on the order assuming it is all dispatched. NB It does not deal with serialised/controlled items.'; + $Parameter[0]['name'] = _('Sales Order to invoice'); + $Parameter[0]['description'] = _('An integer representing the webERP sales order number'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('If successful this function returns a two element array; the first element is 0 for success or an error code, while the second element is the invoice number.'); + +/*E*/$InvoiceSalesOrder_sig = array(array($xmlrpcStruct,$xmlrpcStruct), +/*x*/ array($xmlrpcStruct,$xmlrpcStruct,$xmlrpcString,$xmlrpcString)); + $InvoiceSalesOrder_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_InvoiceSalesOrder($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(InvoiceSalesOrder($xmlrpcmsg->getParam( 0 )->scalarval( ), $xmlrpcmsg->getParam( 1 )->scalarval( ), $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); + } else { //do it with the current login +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(InvoiceSalesOrder($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + + + $Description = 'This function is used to modify the header details of a sales order'; $Parameter[0]['name'] = _('Modify Sales Order Header Details'); $Parameter[0]['description'] = _('A set of key/value pairs where the key must be identical to the name of the field to be updated. ') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-02-07 09:12:20
|
Revision: 4884 http://web-erp.svn.sourceforge.net/web-erp/?rev=4884&view=rev Author: daintree Date: 2012-02-07 09:12:13 +0000 (Tue, 07 Feb 2012) Log Message: ----------- added discount to the InsertDebtorReceipt function Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-02-07 07:27:32 UTC (rev 4883) +++ trunk/api/api_debtortransactions.php 2012-02-07 09:12:13 UTC (rev 4884) @@ -276,6 +276,7 @@ * $Receipt['paymentmethod'] - the payment method of the receipt e.g. cash/EFTPOS/credit card * $Receipt['bankaccount'] - the webERP bank account * $Receipt['reference'] + * $Receipt['discountfx'] */ $Errors = array(); @@ -288,7 +289,8 @@ /*Get Company Defaults */ $ReadCoyResult = api_DB_query("SELECT debtorsact, - gllink_debtors + pytdiscountact, + gllink_debtors FROM companies WHERE coycode=1",$db); @@ -391,12 +393,30 @@ '" . $PeriodNo . "', '". $CompanyRecord['debtorsact'] . "', '" . $Receipt['reference'] . "', - '" . round(-$Receipt['amountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; + '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) * $FunctionalExRate / $ReceiptExRate,4) . "')"; $result = api_DB_query($SQL,$db,'','',true); fputs($fp, "Entered the debtor GL journal with the following SQL: \n" . $SQL . "\n"); - + + if($Receipt['discountfx']!=0){ + $SQL="INSERT INTO gltrans ( type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (12, + '" . $ReceiptNo . "', + '" . $Receipt['trandate'] . "', + '" . $PeriodNo . "', + '". $CompanyRecord['pytdiscountact'] . "', + '" . $Receipt['reference'] . "', + '" . round($Receipt['discountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; + + $result = api_DB_query($SQL,$db,'','',true); + } /*and debit bank account with the receipt */ $SQL="INSERT INTO gltrans ( type, typeno, @@ -410,7 +430,7 @@ '" . $ReceiptNo . "', '" . $Receipt['trandate'] . "', '" . $PeriodNo . "', - '". $Receipt['bankaccount'] . "', + '" . $Receipt['bankaccount'] . "', '" . $Receipt['reference'] . "', '" . round($Receipt['amountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; @@ -438,10 +458,11 @@ '" . $PeriodNo . "', '" . $Receipt['reference'] . "', '" . ($ReceiptExRate/$FunctionalExRate) . "', - '" . -$Receipt['amountfx'] . "', + '" . (-$Receipt['amountfx']-$Receipt['discountfx']) . "', '" . $Receipt['paymentmethod'] . "')"; $result = api_DB_query($SQL,$db,'','',true); + fputs($fp, "Entered the debtortrans with the following SQL: \n" . $SQL . "\n"); $SQL = "UPDATE debtorsmaster SET lastpaiddate = '" . $Receipt['trandate'] . "', Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-02-07 07:27:32 UTC (rev 4883) +++ trunk/api/api_xml-rpc.php 2012-02-07 09:12:13 UTC (rev 4884) @@ -1086,7 +1086,7 @@ unset($Parameter); unset($ReturnValue); - $Description = _('Creates a credit note from header details associative array and line items'); + $Description = _('Creates a credit note from header details associative array and line items. This function implements most of a webERP credit note with the exception that it cannot handle serialised or lot/batch controlled items. All the necessary updates and inserts are handled for stock quantities returned, taxes, sales analysis, stock movements, sales and cost of sales journals'); $Parameter[0]['name'] = _('Credit Note Header Details'); $Parameter[0]['description'] = _('An associative array describing the credit note header with the fields debtorno, branchcode, trandate, tpe, fromstkloc, customerref, shipvia'); $Parameter[1]['name'] = _('Credit note line items'); @@ -1118,7 +1118,7 @@ unset($Parameter); unset($ReturnValue); - $Description = _('Inserts a sales invoice into the debtortrans table and does the relevant GL entries'); + $Description = _('Inserts a sales invoice into the debtortrans table and does the relevant GL entries. Note that this function does not do the tax entries, insert stock movements, update the stock quanties, sales analysis data or do any cost of sales gl journals. Caution is advised in using this function. To create a full webERP invoice with all tables updated use the InvoiceSalesOrder function.'); $Parameter[0]['name'] = _('Invoice Details'); $Parameter[0]['description'] = _('An array of index/value items describing the invoice.') ._('The field names can be found ').'<a href="../../Z_DescribeTable.php?table=debtortrans">'._('here ').'</a>' @@ -1157,7 +1157,7 @@ unset($Parameter); unset($ReturnValue); $ReturnValue = _('Return Value Descriptions go here'); - $Description = _('This function is used to insert a new Sales Credit to the webERP database.'); + $Description = _('This function is used to insert a new Sales Credit to the webERP database. Note that this function does not implement a webERP credit note in full and caution is advised in using this function. It does not handle tax at all, it does not add stockmovements, it does not update stock for any quantity returned or update sales analysis. To create a credit note using webERP logic use the CreateCreditNote function'); $Parameter[0]['name'] = _('Credit Details'); $Parameter[0]['description'] = _('An array of index/value items describing the credit. All values must be negative.'); $Parameter[1]['name'] = _('User name'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-02-07 09:12:24
|
Revision: 4884 http://web-erp.svn.sourceforge.net/web-erp/?rev=4884&view=rev Author: daintree Date: 2012-02-07 09:12:13 +0000 (Tue, 07 Feb 2012) Log Message: ----------- added discount to the InsertDebtorReceipt function Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-02-07 07:27:32 UTC (rev 4883) +++ trunk/api/api_debtortransactions.php 2012-02-07 09:12:13 UTC (rev 4884) @@ -276,6 +276,7 @@ * $Receipt['paymentmethod'] - the payment method of the receipt e.g. cash/EFTPOS/credit card * $Receipt['bankaccount'] - the webERP bank account * $Receipt['reference'] + * $Receipt['discountfx'] */ $Errors = array(); @@ -288,7 +289,8 @@ /*Get Company Defaults */ $ReadCoyResult = api_DB_query("SELECT debtorsact, - gllink_debtors + pytdiscountact, + gllink_debtors FROM companies WHERE coycode=1",$db); @@ -391,12 +393,30 @@ '" . $PeriodNo . "', '". $CompanyRecord['debtorsact'] . "', '" . $Receipt['reference'] . "', - '" . round(-$Receipt['amountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; + '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) * $FunctionalExRate / $ReceiptExRate,4) . "')"; $result = api_DB_query($SQL,$db,'','',true); fputs($fp, "Entered the debtor GL journal with the following SQL: \n" . $SQL . "\n"); - + + if($Receipt['discountfx']!=0){ + $SQL="INSERT INTO gltrans ( type, + typeno, + trandate, + periodno, + account, + narrative, + amount) + VALUES (12, + '" . $ReceiptNo . "', + '" . $Receipt['trandate'] . "', + '" . $PeriodNo . "', + '". $CompanyRecord['pytdiscountact'] . "', + '" . $Receipt['reference'] . "', + '" . round($Receipt['discountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; + + $result = api_DB_query($SQL,$db,'','',true); + } /*and debit bank account with the receipt */ $SQL="INSERT INTO gltrans ( type, typeno, @@ -410,7 +430,7 @@ '" . $ReceiptNo . "', '" . $Receipt['trandate'] . "', '" . $PeriodNo . "', - '". $Receipt['bankaccount'] . "', + '" . $Receipt['bankaccount'] . "', '" . $Receipt['reference'] . "', '" . round($Receipt['amountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; @@ -438,10 +458,11 @@ '" . $PeriodNo . "', '" . $Receipt['reference'] . "', '" . ($ReceiptExRate/$FunctionalExRate) . "', - '" . -$Receipt['amountfx'] . "', + '" . (-$Receipt['amountfx']-$Receipt['discountfx']) . "', '" . $Receipt['paymentmethod'] . "')"; $result = api_DB_query($SQL,$db,'','',true); + fputs($fp, "Entered the debtortrans with the following SQL: \n" . $SQL . "\n"); $SQL = "UPDATE debtorsmaster SET lastpaiddate = '" . $Receipt['trandate'] . "', Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-02-07 07:27:32 UTC (rev 4883) +++ trunk/api/api_xml-rpc.php 2012-02-07 09:12:13 UTC (rev 4884) @@ -1086,7 +1086,7 @@ unset($Parameter); unset($ReturnValue); - $Description = _('Creates a credit note from header details associative array and line items'); + $Description = _('Creates a credit note from header details associative array and line items. This function implements most of a webERP credit note with the exception that it cannot handle serialised or lot/batch controlled items. All the necessary updates and inserts are handled for stock quantities returned, taxes, sales analysis, stock movements, sales and cost of sales journals'); $Parameter[0]['name'] = _('Credit Note Header Details'); $Parameter[0]['description'] = _('An associative array describing the credit note header with the fields debtorno, branchcode, trandate, tpe, fromstkloc, customerref, shipvia'); $Parameter[1]['name'] = _('Credit note line items'); @@ -1118,7 +1118,7 @@ unset($Parameter); unset($ReturnValue); - $Description = _('Inserts a sales invoice into the debtortrans table and does the relevant GL entries'); + $Description = _('Inserts a sales invoice into the debtortrans table and does the relevant GL entries. Note that this function does not do the tax entries, insert stock movements, update the stock quanties, sales analysis data or do any cost of sales gl journals. Caution is advised in using this function. To create a full webERP invoice with all tables updated use the InvoiceSalesOrder function.'); $Parameter[0]['name'] = _('Invoice Details'); $Parameter[0]['description'] = _('An array of index/value items describing the invoice.') ._('The field names can be found ').'<a href="../../Z_DescribeTable.php?table=debtortrans">'._('here ').'</a>' @@ -1157,7 +1157,7 @@ unset($Parameter); unset($ReturnValue); $ReturnValue = _('Return Value Descriptions go here'); - $Description = _('This function is used to insert a new Sales Credit to the webERP database.'); + $Description = _('This function is used to insert a new Sales Credit to the webERP database. Note that this function does not implement a webERP credit note in full and caution is advised in using this function. It does not handle tax at all, it does not add stockmovements, it does not update stock for any quantity returned or update sales analysis. To create a credit note using webERP logic use the CreateCreditNote function'); $Parameter[0]['name'] = _('Credit Details'); $Parameter[0]['description'] = _('An array of index/value items describing the credit. All values must be negative.'); $Parameter[1]['name'] = _('User name'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-02-09 09:30:27
|
Revision: 4887 http://web-erp.svn.sourceforge.net/web-erp/?rev=4887&view=rev Author: daintree Date: 2012-02-09 09:30:20 +0000 (Thu, 09 Feb 2012) Log Message: ----------- new function for allocating debtor receipts from POS Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-02-08 20:10:33 UTC (rev 4886) +++ trunk/api/api_debtortransactions.php 2012-02-09 09:30:20 UTC (rev 4887) @@ -285,8 +285,7 @@ $Errors[0]=NoAuthorisation; return $Errors; } - $fp = fopen( "/root/Web-Server/apidebug/DebugInfo.txt", "w"); - + /*Get Company Defaults */ $ReadCoyResult = api_DB_query("SELECT debtorsact, pytdiscountact, @@ -341,18 +340,12 @@ $ReceiptExRate = $CustCurrRow['rate']/$BankActRow['rate']; $FunctionalExRate = $BankActRow['rate']; -fputs($fp, 'Receipt ex rate = ' . $ReceiptExRate . "\n"); -fputs($fp, 'Functional ex rate = ' . $FunctionalExRate . "\n"); - DB_Txn_Begin($db); $ReceiptNo = GetNextTransNo(12,$db); $PeriodNo = GetCurrentPeriod($db); /*now enter the BankTrans entry */ -fputs($fp, 'Receipt No = ' . $ReceiptNo . "\n"); -fputs($fp, 'Period No = ' . $PeriodNo . "\n"); - $SQL="INSERT INTO banktrans (type, transno, bankact, @@ -376,7 +369,6 @@ $result = api_DB_query($SQL,$db,'','',true); -fputs($fp, "Entered the bank trans with the following SQL: \n" . $SQL . "\n"); if ($CompanyRecord['gllink_debtors']==1) { /* Now Credit Debtors account with receipts */ @@ -396,8 +388,6 @@ '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) * $FunctionalExRate / $ReceiptExRate,4) . "')"; $result = api_DB_query($SQL,$db,'','',true); - -fputs($fp, "Entered the debtor GL journal with the following SQL: \n" . $SQL . "\n"); if($Receipt['discountfx']!=0){ $SQL="INSERT INTO gltrans ( type, @@ -436,8 +426,6 @@ $result = api_DB_query($SQL,$db,'','',true); -fputs($fp, "Entered the bank deposit GL trans with the following SQL: \n" . $SQL . "\n"); - } /* end if GL linked to debtors */ $SQL = "INSERT INTO debtortrans (transno, @@ -463,8 +451,6 @@ $result = api_DB_query($SQL,$db,'','',true); -fputs($fp, "Entered the debtortrans with the following SQL: \n" . $SQL . "\n"); - $SQL = "UPDATE debtorsmaster SET lastpaiddate = '" . $Receipt['trandate'] . "', lastpaid='" . $Receipt['amountfx'] ."' WHERE debtorsmaster.debtorno='" . $Receipt['debtorno'] . "'"; @@ -1311,7 +1297,10 @@ function AllocateTrans($AllocDetails, $User, $Password) { - /* AllocDetails is an associative array containing: + /* This function is quite specific and probably not generally useful + * It only attempts to allocate a receipt or credit note sent to invoices that have a customerref equal to the value sent + * + * The first parameter AllocDetails is an associative array containing: * AllocDetails['debtorno'] * AllocDetails['type'] * AllocDetails['transno'] @@ -1338,7 +1327,7 @@ AND transno='" . $AllocDetails['transno'] . "'"; $Result = api_DB_query($SQL,$db); $LeftToAllocRow = DB_fetch_array($Result); - if (DB_num_row($Result)==0){ + if (DB_num_rows($Result)==0){ $Errors[] = NoTransactionToAllocate; } Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-02-08 20:10:33 UTC (rev 4886) +++ trunk/api/api_xml-rpc.php 2012-02-09 09:30:20 UTC (rev 4887) @@ -1057,8 +1057,8 @@ unset($ReturnValue); $Description = _('Creates a customer receipt from the details passed to the method as an associative array'); - $Parameter[0]['name'] = _('Create Customer Receipt'); - $Parameter[0]['description'] = _('An associative array describing the customer receipt with the following fields: debtorno - the customer code, trandate - the date of the receipt in Y-m-d format, amountfx - the amount in FX, paymentmethod - the payment method of the receipt e.g. cash/EFTPOS/credit card, bankaccount - the webERP bank account to use for the transaction, reference - the reference to record against the webERP receipt transaction'); + $Parameter[0]['name'] = _('Receipt Details'); + $Parameter[0]['description'] = _('An associative array describing the customer receipt with the following fields: debtorno - the customer code; trandate - the date of the receipt in Y-m-d format; amountfx - the amount in FX; paymentmethod - the payment method of the receipt e.g. cash/EFTPOS/credit card; bankaccount - the webERP bank account to use for the transaction, reference - the reference to record against the webERP receipt transaction'); $Parameter[1]['name'] = _('User name'); $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); $Parameter[2]['name'] = _('User password'); @@ -1086,6 +1086,36 @@ unset($Parameter); unset($ReturnValue); + $Description = _('Allocates a debtor receipt or credit to a debtor invoice. Using the customerref field to match up which invoice to allocate to'); + $Parameter[0]['name'] = _('Allocation Details'); + $Parameter[0]['description'] = _('An associative array describing the customer, the transaction being allocated from, it\'s transaction type 12 for a receipt or 11 for a credit note, the webERP transaction number, the customer ref that is to be searched for in invoices to match to. The fields are: debtorno, type, transno, customerref'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of integers. ') + ._('If the first element is zero then the function was successful.') + ._('Otherwise an array of error codes is returned and no insertion takes place. '); + +/*E*/$AllocateTrans_sig = array(array($xmlrpcStruct,$xmlrpcStruct), +/*x*/ array($xmlrpcStruct,$xmlrpcStruct,$xmlrpcString,$xmlrpcString)); + $AllocateTrans_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_AllocateTrans($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(AllocateTrans(php_xmlrpc_decode($xmlrpcmsg->getParam( 0 )), $xmlrpcmsg->getParam( 1 )->scalarval( ),$xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(AllocateTrans(php_xmlrpc_decode($xmlrpcmsg->getParam( 0 )), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + $Description = _('Creates a credit note from header details associative array and line items. This function implements most of a webERP credit note with the exception that it cannot handle serialised or lot/batch controlled items. All the necessary updates and inserts are handled for stock quantities returned, taxes, sales analysis, stock movements, sales and cost of sales journals'); $Parameter[0]['name'] = _('Credit Note Header Details'); $Parameter[0]['description'] = _('An associative array describing the credit note header with the fields debtorno, branchcode, trandate, tpe, fromstkloc, customerref, shipvia'); @@ -3100,6 +3130,10 @@ "function" => "xmlrpc_InsertSalesInvoice", "signature" => $InsertSalesInvoice_sig, "docstring" => $InsertSalesInvoice_doc), + "weberp.xmlrpc_AllocateTrans" => array( + "function" => "xmlrpc_AllocateTrans", + "signature" => $AllocateTrans_sig, + "docstring" => $AllocateTrans_doc), "weberp.xmlrpc_InsertDebtorReceipt" => array( "function" => "xmlrpc_InsertDebtorReceipt", "signature" => $InsertDebtorReceipt_sig, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-02-09 09:30:30
|
Revision: 4887 http://web-erp.svn.sourceforge.net/web-erp/?rev=4887&view=rev Author: daintree Date: 2012-02-09 09:30:20 +0000 (Thu, 09 Feb 2012) Log Message: ----------- new function for allocating debtor receipts from POS Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-02-08 20:10:33 UTC (rev 4886) +++ trunk/api/api_debtortransactions.php 2012-02-09 09:30:20 UTC (rev 4887) @@ -285,8 +285,7 @@ $Errors[0]=NoAuthorisation; return $Errors; } - $fp = fopen( "/root/Web-Server/apidebug/DebugInfo.txt", "w"); - + /*Get Company Defaults */ $ReadCoyResult = api_DB_query("SELECT debtorsact, pytdiscountact, @@ -341,18 +340,12 @@ $ReceiptExRate = $CustCurrRow['rate']/$BankActRow['rate']; $FunctionalExRate = $BankActRow['rate']; -fputs($fp, 'Receipt ex rate = ' . $ReceiptExRate . "\n"); -fputs($fp, 'Functional ex rate = ' . $FunctionalExRate . "\n"); - DB_Txn_Begin($db); $ReceiptNo = GetNextTransNo(12,$db); $PeriodNo = GetCurrentPeriod($db); /*now enter the BankTrans entry */ -fputs($fp, 'Receipt No = ' . $ReceiptNo . "\n"); -fputs($fp, 'Period No = ' . $PeriodNo . "\n"); - $SQL="INSERT INTO banktrans (type, transno, bankact, @@ -376,7 +369,6 @@ $result = api_DB_query($SQL,$db,'','',true); -fputs($fp, "Entered the bank trans with the following SQL: \n" . $SQL . "\n"); if ($CompanyRecord['gllink_debtors']==1) { /* Now Credit Debtors account with receipts */ @@ -396,8 +388,6 @@ '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) * $FunctionalExRate / $ReceiptExRate,4) . "')"; $result = api_DB_query($SQL,$db,'','',true); - -fputs($fp, "Entered the debtor GL journal with the following SQL: \n" . $SQL . "\n"); if($Receipt['discountfx']!=0){ $SQL="INSERT INTO gltrans ( type, @@ -436,8 +426,6 @@ $result = api_DB_query($SQL,$db,'','',true); -fputs($fp, "Entered the bank deposit GL trans with the following SQL: \n" . $SQL . "\n"); - } /* end if GL linked to debtors */ $SQL = "INSERT INTO debtortrans (transno, @@ -463,8 +451,6 @@ $result = api_DB_query($SQL,$db,'','',true); -fputs($fp, "Entered the debtortrans with the following SQL: \n" . $SQL . "\n"); - $SQL = "UPDATE debtorsmaster SET lastpaiddate = '" . $Receipt['trandate'] . "', lastpaid='" . $Receipt['amountfx'] ."' WHERE debtorsmaster.debtorno='" . $Receipt['debtorno'] . "'"; @@ -1311,7 +1297,10 @@ function AllocateTrans($AllocDetails, $User, $Password) { - /* AllocDetails is an associative array containing: + /* This function is quite specific and probably not generally useful + * It only attempts to allocate a receipt or credit note sent to invoices that have a customerref equal to the value sent + * + * The first parameter AllocDetails is an associative array containing: * AllocDetails['debtorno'] * AllocDetails['type'] * AllocDetails['transno'] @@ -1338,7 +1327,7 @@ AND transno='" . $AllocDetails['transno'] . "'"; $Result = api_DB_query($SQL,$db); $LeftToAllocRow = DB_fetch_array($Result); - if (DB_num_row($Result)==0){ + if (DB_num_rows($Result)==0){ $Errors[] = NoTransactionToAllocate; } Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-02-08 20:10:33 UTC (rev 4886) +++ trunk/api/api_xml-rpc.php 2012-02-09 09:30:20 UTC (rev 4887) @@ -1057,8 +1057,8 @@ unset($ReturnValue); $Description = _('Creates a customer receipt from the details passed to the method as an associative array'); - $Parameter[0]['name'] = _('Create Customer Receipt'); - $Parameter[0]['description'] = _('An associative array describing the customer receipt with the following fields: debtorno - the customer code, trandate - the date of the receipt in Y-m-d format, amountfx - the amount in FX, paymentmethod - the payment method of the receipt e.g. cash/EFTPOS/credit card, bankaccount - the webERP bank account to use for the transaction, reference - the reference to record against the webERP receipt transaction'); + $Parameter[0]['name'] = _('Receipt Details'); + $Parameter[0]['description'] = _('An associative array describing the customer receipt with the following fields: debtorno - the customer code; trandate - the date of the receipt in Y-m-d format; amountfx - the amount in FX; paymentmethod - the payment method of the receipt e.g. cash/EFTPOS/credit card; bankaccount - the webERP bank account to use for the transaction, reference - the reference to record against the webERP receipt transaction'); $Parameter[1]['name'] = _('User name'); $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); $Parameter[2]['name'] = _('User password'); @@ -1086,6 +1086,36 @@ unset($Parameter); unset($ReturnValue); + $Description = _('Allocates a debtor receipt or credit to a debtor invoice. Using the customerref field to match up which invoice to allocate to'); + $Parameter[0]['name'] = _('Allocation Details'); + $Parameter[0]['description'] = _('An associative array describing the customer, the transaction being allocated from, it\'s transaction type 12 for a receipt or 11 for a credit note, the webERP transaction number, the customer ref that is to be searched for in invoices to match to. The fields are: debtorno, type, transno, customerref'); + $Parameter[1]['name'] = _('User name'); + $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); + $Parameter[2]['name'] = _('User password'); + $Parameter[2]['description'] = _('The weberp password associated with this user name. '); + $ReturnValue[0] = _('This function returns an array of integers. ') + ._('If the first element is zero then the function was successful.') + ._('Otherwise an array of error codes is returned and no insertion takes place. '); + +/*E*/$AllocateTrans_sig = array(array($xmlrpcStruct,$xmlrpcStruct), +/*x*/ array($xmlrpcStruct,$xmlrpcStruct,$xmlrpcString,$xmlrpcString)); + $AllocateTrans_doc = apiBuildDocHTML( $Description,$Parameter,$ReturnValue ); + + function xmlrpc_AllocateTrans($xmlrpcmsg){ + ob_start('ob_file_callback'); +/*x*/ if ($xmlrpcmsg->getNumParams() == 3) { +/*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(AllocateTrans(php_xmlrpc_decode($xmlrpcmsg->getParam( 0 )), $xmlrpcmsg->getParam( 1 )->scalarval( ),$xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ } else { +/*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(AllocateTrans(php_xmlrpc_decode($xmlrpcmsg->getParam( 0 )), '', ''))); +/*x*/ } + ob_end_flush(); + return $rtn; + } + + unset($Description); + unset($Parameter); + unset($ReturnValue); + $Description = _('Creates a credit note from header details associative array and line items. This function implements most of a webERP credit note with the exception that it cannot handle serialised or lot/batch controlled items. All the necessary updates and inserts are handled for stock quantities returned, taxes, sales analysis, stock movements, sales and cost of sales journals'); $Parameter[0]['name'] = _('Credit Note Header Details'); $Parameter[0]['description'] = _('An associative array describing the credit note header with the fields debtorno, branchcode, trandate, tpe, fromstkloc, customerref, shipvia'); @@ -3100,6 +3130,10 @@ "function" => "xmlrpc_InsertSalesInvoice", "signature" => $InsertSalesInvoice_sig, "docstring" => $InsertSalesInvoice_doc), + "weberp.xmlrpc_AllocateTrans" => array( + "function" => "xmlrpc_AllocateTrans", + "signature" => $AllocateTrans_sig, + "docstring" => $AllocateTrans_doc), "weberp.xmlrpc_InsertDebtorReceipt" => array( "function" => "xmlrpc_InsertDebtorReceipt", "signature" => $InsertDebtorReceipt_sig, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-06-04 04:10:12
|
Revision: 5426 http://web-erp.svn.sourceforge.net/web-erp/?rev=5426&view=rev Author: daintree Date: 2012-06-04 04:10:05 +0000 (Mon, 04 Jun 2012) Log Message: ----------- tax api fixes for POS Modified Paths: -------------- trunk/api/api_stock.php trunk/api/api_taxgroups.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_stock.php =================================================================== --- trunk/api/api_stock.php 2012-06-04 03:49:24 UTC (rev 5425) +++ trunk/api/api_stock.php 2012-06-04 04:10:05 UTC (rev 5426) @@ -530,8 +530,7 @@ $Errors[0]=NoAuthorisation; return $Errors; } - $sql="SELECT stockid, - description + $sql="SELECT stockid FROM stockmaster WHERE " . $Field ." LIKE '%".$Criteria."%'"; $result = DB_Query($sql, $db); Modified: trunk/api/api_taxgroups.php =================================================================== --- trunk/api/api_taxgroups.php 2012-06-04 03:49:24 UTC (rev 5425) +++ trunk/api/api_taxgroups.php 2012-06-04 04:10:05 UTC (rev 5426) @@ -90,12 +90,23 @@ } $sql = "SELECT * FROM taxauthorities WHERE taxid='".$TaxAuthority."'"; $result = DB_query($sql, $db); - return DB_fetch_array($result); + $i=0; + while ($myrow=DB_fetch_array($result)){ + $Answer[$i]['taxcatid'] = $myrow['taxcatid']; + $Answer[$i]['dispatchtaxprovince'] = $myrow['dispatchtaxprovince']; + $Answer[$i]['taxrate'] = $myrow['taxrate']; + } + $Errors[0]=0; + $Errors[1]=$Answer; + return $Errors; } -/* This function takes as a parameter a tax authority id - * and returns an array containing the rate of tax fpr the selected - * tax authority. + +/ + +/* This function takes as a parameter a tax authority id and a tax category id + * and returns an array containing the rate of tax for the selected + * tax authority and tax category */ function GetTaxAuthorityRates($TaxAuthority, $User, $Password) { @@ -105,9 +116,10 @@ $Errors[0]=NoAuthorisation; return $Errors; } - $sql = "SELECT * FROM taxauthrates WHERE taxauthority='".$TaxAuthority."'"; + $sql = "SELECT taxcatid, dispatchtaxprovince, taxrate FROM taxauthrates WHERE taxauthority='".$TaxAuthority."' AND taxcatid='" . $TaxCatID . "'"; $result = DB_query($sql, $db); - return DB_fetch_array($result); + $TaxRateRow = DB_fetch_row($result); + return $TaxRateRow[0]; } Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-06-04 03:49:24 UTC (rev 5425) +++ trunk/api/api_xml-rpc.php 2012-06-04 04:10:05 UTC (rev 5426) @@ -1862,6 +1862,7 @@ return $rtn; } + unset($Description); unset($Parameter); unset($ReturnValue); @@ -1953,7 +1954,7 @@ $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); $Parameter[2]['name'] = _('User password'); $Parameter[2]['description'] = _('The weberp password associated with this user name. '); - $ReturnValue[0] = _('This function returns an array of tax authority tax rates.'); + $ReturnValue[0] = _('This function returns the tax rates for the authority.'); /*E*/$GetTaxAuthorityRates_sig = array(array($xmlrpcStruct,$xmlrpcString), /*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); @@ -1963,8 +1964,8 @@ ob_start('ob_file_callback'); /*x*/ if ($xmlrpcmsg->getNumParams() == 3) { /*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityRates($xmlrpcmsg->getParam( 0 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ) )) ); /*x*/ } else { /*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityRates($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); /*x*/ } @@ -2009,7 +2010,7 @@ $Parameter[0]['description'] = _('A valid weberp username. This user should have security access to this data.'); $Parameter[1]['name'] = _('User password'); $Parameter[1]['description'] = _('The weberp password associated with this user name. '); - $ReturnValue[0] = _('This function returns an array of customer types.'); + $ReturnValue[0] = _('This function returns an array of customer types'); /*E*/ $GetCustomerTypeList_sig = array(array($xmlrpcStruct), /*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString)); @@ -3246,6 +3247,10 @@ "function" => "xmlrpc_GetTaxgroupList", "signature" => $GetTaxgroupList_sig, "docstring" => $GetTaxgroupList_doc), + "weberp.xmlrpc_GetTaxCategoryList" => array( + "function" => "xmlrpc_GetTaxCategoryList", + "signature" => $GetTaxCategoryList_sig, + "docstring" => $GetTaxCategoryList_doc), "weberp.xmlrpc_GetTaxgroupDetails" => array( "function" => "xmlrpc_GetTaxgroupDetails", "signature" => $GetTaxgroupDetails_sig, @@ -3262,10 +3267,10 @@ "function" => "xmlrpc_GetTaxAuthorityDetails", "signature" => $GetTaxAuthorityDetails_sig, "docstring" => $GetTaxAuthorityDetails_doc), - "weberp.xmlrpc_GetTaxAuthorityRates" => array( - "function" => "xmlrpc_GetTaxAuthorityRates", - "signature" => $GetTaxAuthorityRates_sig, - "docstring" => $GetTaxAuthorityRates_doc), + "weberp.xmlrpc_GetTaxAuthorityRate" => array( + "function" => "xmlrpc_GetTaxAuthorityRate", + "signature" => $GetTaxAuthorityRate_sig, + "docstring" => $GetTaxAuthorityRate_doc), "weberp.xmlrpc_GetCustomerTypeList" => array( "function" => "xmlrpc_GetCustomerTypeList", "signature" => $GetCustomerTypeList_sig, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-06-04 04:10:12
|
Revision: 5426 http://web-erp.svn.sourceforge.net/web-erp/?rev=5426&view=rev Author: daintree Date: 2012-06-04 04:10:05 +0000 (Mon, 04 Jun 2012) Log Message: ----------- tax api fixes for POS Modified Paths: -------------- trunk/api/api_stock.php trunk/api/api_taxgroups.php trunk/api/api_xml-rpc.php Modified: trunk/api/api_stock.php =================================================================== --- trunk/api/api_stock.php 2012-06-04 03:49:24 UTC (rev 5425) +++ trunk/api/api_stock.php 2012-06-04 04:10:05 UTC (rev 5426) @@ -530,8 +530,7 @@ $Errors[0]=NoAuthorisation; return $Errors; } - $sql="SELECT stockid, - description + $sql="SELECT stockid FROM stockmaster WHERE " . $Field ." LIKE '%".$Criteria."%'"; $result = DB_Query($sql, $db); Modified: trunk/api/api_taxgroups.php =================================================================== --- trunk/api/api_taxgroups.php 2012-06-04 03:49:24 UTC (rev 5425) +++ trunk/api/api_taxgroups.php 2012-06-04 04:10:05 UTC (rev 5426) @@ -90,12 +90,23 @@ } $sql = "SELECT * FROM taxauthorities WHERE taxid='".$TaxAuthority."'"; $result = DB_query($sql, $db); - return DB_fetch_array($result); + $i=0; + while ($myrow=DB_fetch_array($result)){ + $Answer[$i]['taxcatid'] = $myrow['taxcatid']; + $Answer[$i]['dispatchtaxprovince'] = $myrow['dispatchtaxprovince']; + $Answer[$i]['taxrate'] = $myrow['taxrate']; + } + $Errors[0]=0; + $Errors[1]=$Answer; + return $Errors; } -/* This function takes as a parameter a tax authority id - * and returns an array containing the rate of tax fpr the selected - * tax authority. + +/ + +/* This function takes as a parameter a tax authority id and a tax category id + * and returns an array containing the rate of tax for the selected + * tax authority and tax category */ function GetTaxAuthorityRates($TaxAuthority, $User, $Password) { @@ -105,9 +116,10 @@ $Errors[0]=NoAuthorisation; return $Errors; } - $sql = "SELECT * FROM taxauthrates WHERE taxauthority='".$TaxAuthority."'"; + $sql = "SELECT taxcatid, dispatchtaxprovince, taxrate FROM taxauthrates WHERE taxauthority='".$TaxAuthority."' AND taxcatid='" . $TaxCatID . "'"; $result = DB_query($sql, $db); - return DB_fetch_array($result); + $TaxRateRow = DB_fetch_row($result); + return $TaxRateRow[0]; } Modified: trunk/api/api_xml-rpc.php =================================================================== --- trunk/api/api_xml-rpc.php 2012-06-04 03:49:24 UTC (rev 5425) +++ trunk/api/api_xml-rpc.php 2012-06-04 04:10:05 UTC (rev 5426) @@ -1862,6 +1862,7 @@ return $rtn; } + unset($Description); unset($Parameter); unset($ReturnValue); @@ -1953,7 +1954,7 @@ $Parameter[1]['description'] = _('A valid weberp username. This user should have security access to this data.'); $Parameter[2]['name'] = _('User password'); $Parameter[2]['description'] = _('The weberp password associated with this user name. '); - $ReturnValue[0] = _('This function returns an array of tax authority tax rates.'); + $ReturnValue[0] = _('This function returns the tax rates for the authority.'); /*E*/$GetTaxAuthorityRates_sig = array(array($xmlrpcStruct,$xmlrpcString), /*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString)); @@ -1963,8 +1964,8 @@ ob_start('ob_file_callback'); /*x*/ if ($xmlrpcmsg->getNumParams() == 3) { /*x*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityRates($xmlrpcmsg->getParam( 0 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), -/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ))) ); +/*x*/ $xmlrpcmsg->getParam( 1 )->scalarval( ), +/*x*/ $xmlrpcmsg->getParam( 2 )->scalarval( ) )) ); /*x*/ } else { /*e*/ $rtn = new xmlrpcresp( php_xmlrpc_encode(GetTaxAuthorityRates($xmlrpcmsg->getParam( 0 )->scalarval( ), '', ''))); /*x*/ } @@ -2009,7 +2010,7 @@ $Parameter[0]['description'] = _('A valid weberp username. This user should have security access to this data.'); $Parameter[1]['name'] = _('User password'); $Parameter[1]['description'] = _('The weberp password associated with this user name. '); - $ReturnValue[0] = _('This function returns an array of customer types.'); + $ReturnValue[0] = _('This function returns an array of customer types'); /*E*/ $GetCustomerTypeList_sig = array(array($xmlrpcStruct), /*x*/ array($xmlrpcStruct,$xmlrpcString,$xmlrpcString)); @@ -3246,6 +3247,10 @@ "function" => "xmlrpc_GetTaxgroupList", "signature" => $GetTaxgroupList_sig, "docstring" => $GetTaxgroupList_doc), + "weberp.xmlrpc_GetTaxCategoryList" => array( + "function" => "xmlrpc_GetTaxCategoryList", + "signature" => $GetTaxCategoryList_sig, + "docstring" => $GetTaxCategoryList_doc), "weberp.xmlrpc_GetTaxgroupDetails" => array( "function" => "xmlrpc_GetTaxgroupDetails", "signature" => $GetTaxgroupDetails_sig, @@ -3262,10 +3267,10 @@ "function" => "xmlrpc_GetTaxAuthorityDetails", "signature" => $GetTaxAuthorityDetails_sig, "docstring" => $GetTaxAuthorityDetails_doc), - "weberp.xmlrpc_GetTaxAuthorityRates" => array( - "function" => "xmlrpc_GetTaxAuthorityRates", - "signature" => $GetTaxAuthorityRates_sig, - "docstring" => $GetTaxAuthorityRates_doc), + "weberp.xmlrpc_GetTaxAuthorityRate" => array( + "function" => "xmlrpc_GetTaxAuthorityRate", + "signature" => $GetTaxAuthorityRate_sig, + "docstring" => $GetTaxAuthorityRate_doc), "weberp.xmlrpc_GetCustomerTypeList" => array( "function" => "xmlrpc_GetCustomerTypeList", "signature" => $GetCustomerTypeList_sig, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-07-22 03:30:00
|
Revision: 5526 http://web-erp.svn.sourceforge.net/web-erp/?rev=5526&view=rev Author: daintree Date: 2012-07-22 03:29:54 +0000 (Sun, 22 Jul 2012) Log Message: ----------- Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_salesorders.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-07-21 23:37:38 UTC (rev 5525) +++ trunk/api/api_debtortransactions.php 2012-07-22 03:29:54 UTC (rev 5526) @@ -82,7 +82,7 @@ } /* Find the period number from the transaction date */ -/* Why use this function over GetPeriod we already have this function included in DateFunctions.inc +/* Why use this function over GetPeriod we already have this function included in DateFunctions.inc * This function doesn't create periods if required so there is the danger of not being able to insert transactions*/ function GetPeriodFromTransactionDate($TranDate, $i, $Errors, $db) { $sql="SELECT confvalue FROM config WHERE confname='DefaultDateFormat'"; @@ -243,11 +243,11 @@ return $Errors; } -/* Retrieves the default sales GL code for a given part code and sales area - * +/* Retrieves the default sales GL code for a given part code and sales area + * * This function also in SQL_CommonFunctions...better to use it from there as it covers all cases * and not limited to stk='any'!! - * + * function GetSalesGLCode($salesarea, $partnumber, $db) { $sql="SELECT salesglcode FROM salesglpostings WHERE stkcat='any'"; @@ -267,8 +267,8 @@ function InsertDebtorReceipt($Receipt, $User, $Password) { - - /* + + /* This function inserts a debtors receipt into a bank account/GL Postings and does the allocation and journals for difference on exchange $Receipt contains an associative array in the format: @@ -287,7 +287,7 @@ $Errors[0]=NoAuthorisation; return $Errors; } - + /*Get Company Defaults */ $ReadCoyResult = api_DB_query("SELECT debtorsact, pytdiscountact, @@ -299,7 +299,7 @@ if (DB_error_no($db) != 0) { $Errors[] = NoCompanyRecord; } - + $CustCurrencySQL = "SELECT currcode, rate FROM debtorsmaster @@ -313,9 +313,9 @@ } $CustCurrRow = DB_fetch_array($CurrResult); - + /*Get the currency and rate of the bank account transferring to*/ - $SQL = "SELECT currcode, + $SQL = "SELECT currcode, rate FROM bankaccounts INNER JOIN currencies ON bankaccounts.currcode = currencies.currabrev @@ -324,9 +324,9 @@ if (DB_error_no($db) != 0) { $Errors[] = InvalidBankAccount; } - + $BankActRow = DB_fetch_array($BankActResult); - + /*To illustrate the rates required * The money received is assumed to be in the currency of the customer account. * but it may be banked into a bank account that is denominated in a different currency - so we need to work out the amount of money that this would turn into when sold to the bank to deposit into this bank account - we call this the receipt ex rate. Normally this would be figured out at the time of entry so the actual currency banked agrees. However, we must use the system rates to automate this and the amounts may not agree to actual deposits. @@ -336,12 +336,12 @@ The FunctionalExRate = 0.90 - the rate between the functional currency and the bank account currency The receipt ex rate is the rate at which one can sell the received currency and purchase the bank account currency in this case the AUD/USD cross rate or 0.8/0.9 = 0.88889 - So the receipt ex rate will always be 1 if the currency of the bank account is the same as the customer currency. - + So the receipt ex rate will always be 1 if the currency of the bank account is the same as the customer currency. + */ $ReceiptExRate = $CustCurrRow['rate']/$BankActRow['rate']; $FunctionalExRate = $BankActRow['rate']; - + DB_Txn_Begin($db); $ReceiptNo = GetNextTransNo(12,$db); @@ -368,10 +368,10 @@ '" . $Receipt['paymentmethod'] . "', '" . round($Receipt['amountfx'] / $ReceiptExRate,4) . "', '" . $CustCurrRow['currcode'] . "')"; - + $result = api_DB_query($SQL,$db,'','',true); - + if ($CompanyRecord['gllink_debtors']==1) { /* Now Credit Debtors account with receipts */ $SQL="INSERT INTO gltrans ( type, @@ -388,9 +388,9 @@ '". $CompanyRecord['debtorsact'] . "', '" . $Receipt['reference'] . "', '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) * $FunctionalExRate / $ReceiptExRate,4) . "')"; - + $result = api_DB_query($SQL,$db,'','',true); - + if($Receipt['discountfx']!=0){ $SQL="INSERT INTO gltrans ( type, typeno, @@ -406,7 +406,7 @@ '". $CompanyRecord['pytdiscountact'] . "', '" . $Receipt['reference'] . "', '" . round($Receipt['discountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; - + $result = api_DB_query($SQL,$db,'','',true); } /*and debit bank account with the receipt */ @@ -425,11 +425,11 @@ '" . $Receipt['bankaccount'] . "', '" . $Receipt['reference'] . "', '" . round($Receipt['amountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; - + $result = api_DB_query($SQL,$db,'','',true); } /* end if GL linked to debtors */ - + $SQL = "INSERT INTO debtortrans (transno, type, debtorno, @@ -448,20 +448,20 @@ '" . date('Y-m-d H-i-s') . "', '" . $PeriodNo . "', '" . $Receipt['reference'] . "', - '" . ($ReceiptExRate/$FunctionalExRate) . "', - '" . -$Receipt['amountfx'] . "', - '" . -$Receipt['discountfx'] . "', - '" . $Receipt['paymentmethod'] . "')"; - + '" . ($ReceiptExRate/$FunctionalExRate) . "', + '" . -$Receipt['amountfx'] . "', + '" . -$Receipt['discountfx'] . "', + '" . $Receipt['paymentmethod'] . "')"; + $result = api_DB_query($SQL,$db,'','',true); - + $SQL = "UPDATE debtorsmaster SET lastpaiddate = '" . $Receipt['trandate'] . "', lastpaid='" . $Receipt['amountfx'] ."' WHERE debtorsmaster.debtorno='" . $Receipt['debtorno'] . "'"; - + $result = api_DB_query($SQL,$db,'','',true); - - + + if (sizeof($Errors)==0) { $Result = DB_Txn_Commit($db); $Errors[0]=0; @@ -474,7 +474,7 @@ function CreateCreditNote($Header,$LineDetails, $User, $Password) { - + /* Create a customer credit note in webERP. * Needs an associative array for the $Header * and an array of assocative arrays for the $LineDetails @@ -501,8 +501,8 @@ $Errors[0]=NoAuthorisation; return $Errors; } - - + + $Errors=VerifyDebtorExists($Header['debtorno'], sizeof($Errors), $Errors, $db); $Errors=VerifyBranchNoExists($Header['debtorno'],$Header['branchcode'], sizeof($Errors), $Errors, $db); /*Does not deal with serialised/lot track items - for use by POS */ @@ -518,7 +518,7 @@ if (DB_error_no($db) != 0) { $Errors[] = NoCompanyRecord; } - + $HeaderSQL = "SELECT custbranch.area, custbranch.taxgroupid, debtorsmaster.currcode, @@ -602,7 +602,7 @@ } $LineTaxAmount = 0; - + while ($myrow = DB_fetch_array($GetTaxRatesResult)){ if (!isset($TaxTotals[$myrow['taxauthid']]['FXAmount'])) { $TaxTotals[$myrow['taxauthid']]['FXAmount']=0; @@ -618,7 +618,7 @@ $TaxAuthAmount = $LineNetAmount * $myrow['taxrate']; } $TaxTotals[$myrow['taxauthid']]['FXAmount'] += $TaxAuthAmount; - + /*Make an array of the taxes and amounts including GLcodes for later posting - need debtortransid so can only post once the debtor trans is posted - can only post debtor trans when all tax is calculated */ $LineTaxes[$LineCounter][$myrow['calculationorder']] = array('TaxCalculationOrder' =>$myrow['calculationorder'], @@ -634,7 +634,7 @@ $TotalFXNetCredit += $LineNetAmount; $TotalFXTax += $LineTaxAmount; - + if ($LineRow['mbflag']=='B' OR $LineRow['mbflag']=='M') { $Assembly = False; @@ -645,7 +645,7 @@ WHERE locstock.stockid='" . $CN_Line['stockid'] . "' AND loccode= '" . $Header['fromstkloc'] . "'"; $Result = api_DB_query($SQL, $db); - + if (DB_num_rows($Result)==1){ $LocQtyRow = DB_fetch_row($Result); $QtyOnHandPrior = $LocQtyRow[0]; @@ -1101,16 +1101,16 @@ } #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'] . "' + + $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){ @@ -1123,11 +1123,11 @@ } else { $AllocateAmount = 0; } - if ($AllocateAmount > 0) { + if ($AllocateAmount > 0) { $SQL = "INSERT INTO custallocns (datealloc, amt, transid_allocfrom, - transid_allocto) + transid_allocto) VALUES ('" . date('Y-m-d') . "', '" . $AllocateAmount . "', '" . $DebtorTransID . "', @@ -1143,7 +1143,7 @@ settled = '" . $Settled . "' WHERE id = '" . $InvoiceRow['id'] ."'"; $UpdateAllocResult = api_DB_query($SQL,$db,'','',true); - + $Allocated -= $AllocateAmount; } if (abs($TotalCreditFX - $Allocated)<0.005){ @@ -1156,7 +1156,7 @@ WHERE id = '" . $DebtorTransID ."'"; $UpdateAllocResult = api_DB_query($SQL,$db,'','',true); } - + if (sizeof($Errors)==0) { $Result = DB_Txn_Commit($db); $Errors[0]=0; @@ -1252,35 +1252,35 @@ } if (sizeof($Errors)==0) { $result = DB_Txn_Begin($db); - $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames,0,-2) .") + $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames,0,-2) .") VALUES ('" . mb_substr($FieldValues,0,-2) ."') "; $result = DB_Query($sql, $db); $sql = "UPDATE systypes SET typeno='" . GetNextTransactionNo(10, $db) . "' WHERE typeid=10"; $result = DB_Query($sql, $db); $SalesGLCode=GetSalesGLCode($SalesArea, $PartCode, $db); $DebtorsGLCode=GetDebtorsGLCode($db); - $sql="INSERT INTO gltrans VALUES(null, + $sql="INSERT INTO gltrans VALUES(null, 10, '" . GetNextTransactionNo(10, $db) . "', 0, '" . $InvoiceDetails['trandate'] ."', - '" . $InvoiceDetails['prd'] . "', + '" . $InvoiceDetails['prd'] . "', '" . $DebtorsGLCode. "', - '". _('Invoice for') .' -' . $InvoiceDetails['debtorno'] .' ' . _('Total') . ' - '. $InvoiceDetails['ovamount'] . "', - '" . $InvoiceDetails['ovamount'] . "', + '". _('Invoice for') .' -' . $InvoiceDetails['debtorno'] .' ' . _('Total') . ' - '. $InvoiceDetails['ovamount'] . "', + '" . $InvoiceDetails['ovamount'] . "', 0, '" . $InvoiceDetails['jobref'] . "', 1)"; $result = api_DB_Query($sql, $db); - $sql="INSERT INTO gltrans VALUES(null, + $sql="INSERT INTO gltrans VALUES(null, 10, '" . GetNextTransactionNo(10, $db) . "', 0, '" . $InvoiceDetails['trandate'] ."', - '" . $InvoiceDetails['prd'] . "', + '" . $InvoiceDetails['prd'] . "', '" . $SalesGLCode . "', - '" . _('Invoice for') . ' -' . $InvoiceDetails['debtorno'] . ' ' . _('Total') .' - '. $InvoiceDetails['ovamount'] ."', - '" . (-intval($InvoiceDetails['ovamount'])) ."', + '" . _('Invoice for') . ' -' . $InvoiceDetails['debtorno'] . ' ' . _('Total') .' - '. $InvoiceDetails['ovamount'] ."', + '" . (-intval($InvoiceDetails['ovamount'])) ."', 0, '" . $InvoiceDetails['jobref'] . "', 1)"; @@ -1300,10 +1300,10 @@ } function AllocateTrans($AllocDetails, $User, $Password) { - + /* This function is quite specific and probably not generally useful * It only attempts to allocate a receipt or credit note sent to invoices that have a customerref equal to the value sent - * + * * The first parameter AllocDetails is an associative array containing: * AllocDetails['debtorno'] * AllocDetails['type'] @@ -1319,7 +1319,7 @@ } $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; } @@ -1335,7 +1335,7 @@ if (DB_num_rows($Result)==0){ $Errors[] = NoTransactionToAllocate; } - + if ($LeftToAllocRow['lefttoalloc'] <= 0){ /* negative if there is owt to allocate */ /*Now look for invoices with the same customerref to allocate to */ $SQL = "SELECT id, @@ -1347,7 +1347,7 @@ AND reference='" . $AllocDetails['customerref'] . "'"; $Result = api_DB_query($SQL,$db); $OSInvRow = DB_fetch_array($Result); - + if ($OSInvRow['rate']==$LeftToAllocRow['rate'] AND $OSInvRow['outstanding']>0){ @@ -1358,12 +1358,12 @@ /*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, + $SQL = "INSERT INTO custallocs (amt, + datealloc, + transid_allocfrom, transid_allocto) VALUE('" . $AllocateAmount . "', '" . Date('Y-m-d') . "', @@ -1386,8 +1386,8 @@ } else { $Result = DB_Txn_Rollback($db); } - return $Errors; - + return $Errors; + } /* Create a customer credit note in webERP. This function will bypass the @@ -1476,22 +1476,22 @@ } if (sizeof($Errors)==0) { $result = DB_Txn_Begin($db); - $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames,0,-2) . ") + $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames,0,-2) . ") VALUES ('".mb_substr($FieldValues,0,-2) ."') "; $result = DB_Query($sql, $db); $sql = "UPDATE systypes SET typeno='" . GetNextTransactionNo(11, $db) ."' WHERE typeid=10"; $result = DB_Query($sql, $db); $SalesGLCode=GetSalesGLCode($SalesArea, $PartCode, $db); $DebtorsGLCode=GetDebtorsGLCode($db); - $sql="INSERT INTO gltrans VALUES(null, + $sql="INSERT INTO gltrans VALUES(null, 10, '" . GetNextTransactionNo(11, $db). "', 0, '" . $CreditDetails['trandate'] . "', - '" . $CreditDetails['prd'] . "', + '" . $CreditDetails['prd'] . "', '" .$DebtorsGLCode . "', - '". _('Invoice for') . ' - '.$CreditDetails['debtorno'].' ' . -('Total') .' - '.$CreditDetails['ovamount']. "', - '" . $CreditDetails['ovamount'] . "', + '". _('Invoice for') . ' - '.$CreditDetails['debtorno'].' ' . -('Total') .' - '.$CreditDetails['ovamount']. "', + '" . $CreditDetails['ovamount'] . "', 0, '" . $CreditDetails['jobref'] ."')"; $result = DB_Query($sql, $db); @@ -1500,10 +1500,10 @@ '" . GetNextTransactionNo(11, $db) . "', 0, '" . $CreditDetails['trandate'] ."', - '" . $CreditDetails['prd'] . "', + '" . $CreditDetails['prd'] . "', '" . $SalesGLCode ."', - '". _('Invoice for') . ' - ' . $CreditDetails['debtorno'] .' ' . _('Total') . ' - '. $CreditDetails['ovamount'] ."', - '" .(-intval($CreditDetails['ovamount'])) . "', + '". _('Invoice for') . ' - ' . $CreditDetails['debtorno'] .' ' . _('Total') . ' - '. $CreditDetails['ovamount'] ."', + '" .(-intval($CreditDetails['ovamount'])) . "', 0, '" . $CreditDetails['jobref'] ."')"; $result = DB_Query($sql, $db); Modified: trunk/api/api_salesorders.php =================================================================== --- trunk/api/api_salesorders.php 2012-07-21 23:37:38 UTC (rev 5525) +++ trunk/api/api_salesorders.php 2012-07-22 03:29:54 UTC (rev 5526) @@ -5,10 +5,10 @@ // InsertSalesOrderHeader and ModifySalesOrderHeader have date fields // which need to be converted to the appropriate format. This is // a list of such fields used to detect date values and format appropriately. -$SOH_DateFields = array ('orddate', +$SOH_DateFields = array ('orddate', 'deliverydate', 'datepackingslipprinted', - 'quotedate', + 'quotedate', 'confirmeddate' ); /* Check that the custmerref field is 50 characters or less long */ @@ -345,10 +345,10 @@ } $FieldValues.="'".$value."', "; } - $sql = 'INSERT INTO salesorders ('.mb_substr($FieldNames,0,-2).") + $sql = 'INSERT INTO salesorders ('.mb_substr($FieldNames,0,-2).") VALUES (" . mb_substr($FieldValues,0,-2). ")"; if (sizeof($Errors)==0) { - + $result = api_DB_Query($sql, $db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; @@ -460,7 +460,7 @@ * already exist in webERP. */ function InsertSalesOrderLine($OrderLine, $user, $password) { - + $Errors = array(); $db = db($user, $password); if (gettype($db)=='integer') { @@ -488,7 +488,7 @@ $Errors=VerifyNarrative($OrderLine['narrative'], sizeof($Errors), $Errors); } /* - * Not sure why the verification of itemdue doesn't work + * Not sure why the verification of itemdue doesn't work if (isset($OrderLine['itemdue'])){ $Errors=VerifyItemDueDate($OrderLine['itemdue'], sizeof($Errors), $Errors); } @@ -507,8 +507,8 @@ } $FieldValues.= "'" . $value . "', "; } - - $sql = "INSERT INTO salesorderdetails (" . mb_substr($FieldNames,0,-2) . ") + + $sql = "INSERT INTO salesorderdetails (" . mb_substr($FieldNames,0,-2) . ") VALUES (" . mb_substr($FieldValues,0,-2) . ")"; if (sizeof($Errors)==0) { @@ -582,7 +582,7 @@ } return $Errors; } - + /* This function takes a Order Header ID and returns an associative array containing the database record for that Order. If the Order Header ID doesn't exist then it returns an $Errors array. @@ -606,13 +606,13 @@ return $Errors; } } - + /* This function takes a Order Header ID and returns an associative array containing the database record for that Order. If the Order Header ID doesn't exist then it returns an $Errors array. */ function GetSalesOrderLine($OrderNo, $user, $password) { - + $Errors = array(); $db = db($user, $password); if (gettype($db)=='integer') { @@ -631,15 +631,10 @@ return $Errors; } } - - - function InvoiceSalesOrder($OrderNo, $User, $Password) { -$fp = fopen( "/root/Web-Server/apidebug/DebugInfo.txt", "w"); + function InvoiceSalesOrder($OrderNo, $User, $Password) { - - $Errors = array(); $db = db($User, $Password); if (gettype($db)=='integer') { @@ -662,8 +657,8 @@ $CompanyRecord = DB_fetch_array($ReadCoyResult); if (DB_error_no($db) != 0) { $Errors[] = NoCompanyRecord; - } - + } + $OrderHeaderSQL = "SELECT salesorders.debtorno, debtorsmaster.name, salesorders.branchcode, @@ -692,10 +687,10 @@ $OrderHeaderResult = api_DB_query($OrderHeaderSQL,$db); if (DB_error_no($db) != 0) { $Errors[] = NoReadOrder; - } - + } + $OrderHeader = DB_fetch_array($OrderHeaderResult); - + $TaxProvResult = api_DB_query("SELECT taxprovinceid FROM locations WHERE loccode='" . $OrderHeader['fromstkloc'] ."'",$db); if (DB_error_no($db) != 0) { $Errors[] = NoTaxProvince; @@ -720,21 +715,21 @@ $Errors[] = NoReadOrderLines; return $Errors; } - + /*Start an SQL transaction */ $result = DB_Txn_Begin($db); /*Now Get the next invoice number - function in SQL_CommonFunctions*/ $InvoiceNo = GetNextTransNo(10, $db); $PeriodNo = GetCurrentPeriod($db); - + $TaxTotals =array(); - + $TotalFXNetInvoice = 0; $TotalFXTax = 0; $LineCounter =0; while ($OrderLineRow = DB_fetch_array($LineItemsResult)) { - + $StandardCost = $OrderLineRow['standardcost']; $LocalCurrencyPrice= ($OrderLineRow['unitprice'] *(1- floatval($OrderLineRow['discountpercent'])))/ $OrderHeader['rate']; $LineNetAmount = $OrderLineRow['unitprice'] * $OrderLineRow['quantity'] *(1- floatval($OrderLineRow['discountpercent'])); @@ -758,10 +753,10 @@ ORDER BY taxgrouptaxes.calculationorder"; $GetTaxRatesResult = api_DB_query($SQL,$db); - + if (DB_error_no($db) != 0) { $Errors[] = TaxRatesFailed; - } + } $LineTaxAmount = 0; while ($myrow = DB_fetch_array($GetTaxRatesResult)){ @@ -779,7 +774,7 @@ $TaxAuthAmount = $LineNetAmount * $myrow['taxrate']; } $TaxTotals[$myrow['taxauthid']]['FXAmount'] += $TaxAuthAmount; - + /*Make an array of the taxes and amounts including GLcodes for later posting - need debtortransid so can only post once the debtor trans is posted - can only post debtor trans when all tax is calculated */ $LineTaxes[$LineCounter][$myrow['calculationorder']] = array('TaxCalculationOrder' =>$myrow['calculationorder'], @@ -804,8 +799,8 @@ AND stkcode = '" . $OrderLineRow['stkcode'] . "'"; $Result = api_DB_query($SQL,$db,'','',true); - - + + if ($OrderLineRow['mbflag']=='B' OR $OrderLineRow['mbflag']=='M') { $Assembly = False; @@ -816,7 +811,7 @@ WHERE locstock.stockid='" . $OrderLineRow['stkcode'] . "' AND loccode= '" . $OrderHeader['fromstkloc'] . "'"; $Result = api_DB_query($SQL, $db); - + if (DB_num_rows($Result)==1){ $LocQtyRow = DB_fetch_row($Result); $QtyOnHandPrior = $LocQtyRow[0]; @@ -830,7 +825,7 @@ WHERE locstock.stockid = '" . $OrderLineRow['stkcode'] . "' AND loccode = '" . $OrderHeader['fromstkloc'] . "'"; $Result = api_DB_query($SQL,$db,'','',true); - + $SQL = "INSERT INTO stockmoves (stockid, type, transno, @@ -859,9 +854,9 @@ '" . $OrderLineRow['discountpercent'] . "', '" . $StandardCost . "', '" . ($QtyOnHandPrior - $OrderLineRow['quantity']) . "' )"; - + $Result = api_DB_query($SQL,$db,'','',true); - + } else if ($OrderLineRow['mbflag']=='A'){ /* its an assembly */ /*Need to get the BOM for this part and make stock moves for the components then update the Location stock balances */ @@ -937,9 +932,9 @@ } /* end of assembly explosion and updates */ } /* end of its an assembly */ - + if ($OrderLineRow['mbflag']=='A' OR $OrderLineRow['mbflag']=='D'){ - /*it's a Dummy/Service item or an Assembly item - still need stock movement record + /*it's a Dummy/Service item or an Assembly item - still need stock movement record * but quantites on hand are always nil */ $SQL = "INSERT INTO stockmoves (stockid, type, @@ -969,7 +964,7 @@ '" . $OrderLineRow['discountpercent'] . "', '" . $StandardCost . "', '0' )"; - + $Result = api_DB_query($SQL,$db,'','',true); } /*Get the ID of the StockMove... */ @@ -990,7 +985,7 @@ $Result = DB_query($SQL,$db,'','',true); } - + /*Insert Sales Analysis records */ $SQL="SELECT COUNT(*), @@ -1031,7 +1026,7 @@ $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); $myrow = DB_fetch_row($Result); - + if ($myrow[0]>0){ /*Update the existing record that already exists */ $SQL = "UPDATE salesanalysis @@ -1047,7 +1042,7 @@ AND stockid " . LIKE . " '" . $OrderLineRow['stkcode'] . "' AND salesanalysis.stkcategory ='" . $myrow[1] . "' AND budgetoractual='1'"; - + } else { /* insert a new sales analysis record */ $SQL = "INSERT INTO salesanalysis ( typeabbrev, @@ -1080,9 +1075,9 @@ WHERE stockmaster.stockid = '" . $OrderLineRow['stkcode'] . "' AND custbranch.debtorno = '" . $OrderHeader['debtorno'] . "' AND custbranch.branchcode='" . $OrderHeader['branchcode'] . "'"; - + } - + $Result = api_DB_query($SQL,$db,'','',true); if ($CompanyRecord['gllink_stock']==1 AND $StandardCost !=0){ @@ -1105,7 +1100,7 @@ '" . ($StandardCost * $OrderLineRow['quantity']) . "')"; $Result = api_DB_query($SQL,$db,'','',true); - + /*now the stock entry - this is set to the cost act in the case of a fixed asset disposal */ $StockGLCode = GetStockGLCode($OrderLineRow['stkcode'],$db); @@ -1125,7 +1120,7 @@ '" . (-$StandardCost * $OrderLineRow['quantity']) . "')"; $Result = api_DB_query($SQL,$db,'','',true); - + } /* end of if GL and stock integrated and standard cost !=0 and not an asset */ if ($CompanyRecord['gllink_debtors']==1 AND $OrderLineRow['unitprice'] !=0){ @@ -1149,7 +1144,7 @@ '" . -$OrderLineRow['unitprice'] * $OrderLineRow['quantity']/$OrderHeader['rate'] . "' )"; $Result = api_DB_query($SQL,$db,'','',true); - + if ($OrderLineRow['discountpercent'] !=0){ $SQL = "INSERT INTO gltrans (type, @@ -1223,7 +1218,7 @@ $Result = api_DB_query($SQL,$db,'','',true); } EnsureGLEntriesBalance(10,$InvoiceNo,$db); - + } /*end of if Sales and GL integrated */ /*Update order header for invoice charged on */ @@ -1261,14 +1256,14 @@ '" . $TotalFXTax . "', '" . $OrderHeader['rate'] . "', '" . $OrderHeader['shipvia'] . "')"; - + $Result = api_DB_query($SQL,$db,'','',true); - + $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); - + /*for each Tax - need to insert into debtortranstaxes */ foreach ($TaxTotals AS $TaxAuthID => $Tax) { - + $SQL = "INSERT INTO debtortranstaxes (debtortransid, taxauthid, taxamount) @@ -1277,27 +1272,27 @@ '" . $Tax['FXAmount']/$OrderHeader['rate'] . "')"; $Result = api_DB_query($SQL,$db,'','',true); } - + if (sizeof($Errors)==0) { - + $Result = DB_Txn_Commit($db); $Errors[0]=0; $Errors[1]=$InvoiceNo; } else { $Result = DB_Txn_Rollback($db); - } + } return $Errors; } //end InvoiceSalesOrder function - - + + function GetCurrentPeriod (&$db) { - + $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); $myrow=DB_fetch_row($result); - + if (is_null($myrow[0])){ $InsertFirstPeriodResult = api_DB_query("INSERT INTO periods VALUES (0,'" . Date('Y-m-d',mktime(0,0,0,Date('m')+1,0,Date('Y'))) . "')",$db); $InsertFirstPeriodResult = api_DB_query("INSERT INTO periods VALUES (1,'" . Date('Y-m-d',mktime(0,0,0,Date('m')+2,0,Date('Y'))) . "')",$db); @@ -1315,14 +1310,14 @@ $Date_Array = explode('-', $myrow[0]); $FirstPeriodEnd = mktime(0,0,0,$Date_Array[1],0,(int)$Date_Array[0]); $FirstPeriod = $myrow[1]; - + /* If the period number doesn't exist */ if (!PeriodExists($TransDate, $db)) { /* if the transaction is after the last period */ if ($TransDate > $LastPeriodEnd) { - + $PeriodEnd = mktime(0,0,0,Date('m', $TransDate)+1, 0, Date('Y', $TransDate)); - + while ($PeriodEnd >= $LastPeriodEnd) { if (Date('m', $LastPeriodEnd)<=13) { $LastPeriodEnd = mktime(0,0,0,Date('m', $LastPeriodEnd)+2, 0, Date('Y', $LastPeriodEnd)); @@ -1356,19 +1351,19 @@ $LastPeriod = $myrow[1]; CreatePeriod($LastPeriod+1, $LastPeriodEnd, $db); } - + /* Now return the period number of the transaction */ - + $MonthAfterTransDate = Mktime(0,0,0,Date('m',$TransDate)+1,Date('d',$TransDate),Date('Y',$TransDate)); - $GetPrdSQL = "SELECT periodno - FROM periods - WHERE lastdate_in_period < '" . Date('Y-m-d', $MonthAfterTransDate) . "' + $GetPrdSQL = "SELECT periodno + FROM periods + WHERE lastdate_in_period < '" . Date('Y-m-d', $MonthAfterTransDate) . "' AND lastdate_in_period >= '" . Date('Y-m-d', $TransDate) . "'"; - + $ErrMsg = _('An error occurred in retrieving the period number'); $GetPrdResult = DB_query($GetPrdSQL,$db,$ErrMsg); $myrow = DB_fetch_row($GetPrdResult); - + return $myrow[0]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-07-22 03:30:01
|
Revision: 5526 http://web-erp.svn.sourceforge.net/web-erp/?rev=5526&view=rev Author: daintree Date: 2012-07-22 03:29:54 +0000 (Sun, 22 Jul 2012) Log Message: ----------- Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_salesorders.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-07-21 23:37:38 UTC (rev 5525) +++ trunk/api/api_debtortransactions.php 2012-07-22 03:29:54 UTC (rev 5526) @@ -82,7 +82,7 @@ } /* Find the period number from the transaction date */ -/* Why use this function over GetPeriod we already have this function included in DateFunctions.inc +/* Why use this function over GetPeriod we already have this function included in DateFunctions.inc * This function doesn't create periods if required so there is the danger of not being able to insert transactions*/ function GetPeriodFromTransactionDate($TranDate, $i, $Errors, $db) { $sql="SELECT confvalue FROM config WHERE confname='DefaultDateFormat'"; @@ -243,11 +243,11 @@ return $Errors; } -/* Retrieves the default sales GL code for a given part code and sales area - * +/* Retrieves the default sales GL code for a given part code and sales area + * * This function also in SQL_CommonFunctions...better to use it from there as it covers all cases * and not limited to stk='any'!! - * + * function GetSalesGLCode($salesarea, $partnumber, $db) { $sql="SELECT salesglcode FROM salesglpostings WHERE stkcat='any'"; @@ -267,8 +267,8 @@ function InsertDebtorReceipt($Receipt, $User, $Password) { - - /* + + /* This function inserts a debtors receipt into a bank account/GL Postings and does the allocation and journals for difference on exchange $Receipt contains an associative array in the format: @@ -287,7 +287,7 @@ $Errors[0]=NoAuthorisation; return $Errors; } - + /*Get Company Defaults */ $ReadCoyResult = api_DB_query("SELECT debtorsact, pytdiscountact, @@ -299,7 +299,7 @@ if (DB_error_no($db) != 0) { $Errors[] = NoCompanyRecord; } - + $CustCurrencySQL = "SELECT currcode, rate FROM debtorsmaster @@ -313,9 +313,9 @@ } $CustCurrRow = DB_fetch_array($CurrResult); - + /*Get the currency and rate of the bank account transferring to*/ - $SQL = "SELECT currcode, + $SQL = "SELECT currcode, rate FROM bankaccounts INNER JOIN currencies ON bankaccounts.currcode = currencies.currabrev @@ -324,9 +324,9 @@ if (DB_error_no($db) != 0) { $Errors[] = InvalidBankAccount; } - + $BankActRow = DB_fetch_array($BankActResult); - + /*To illustrate the rates required * The money received is assumed to be in the currency of the customer account. * but it may be banked into a bank account that is denominated in a different currency - so we need to work out the amount of money that this would turn into when sold to the bank to deposit into this bank account - we call this the receipt ex rate. Normally this would be figured out at the time of entry so the actual currency banked agrees. However, we must use the system rates to automate this and the amounts may not agree to actual deposits. @@ -336,12 +336,12 @@ The FunctionalExRate = 0.90 - the rate between the functional currency and the bank account currency The receipt ex rate is the rate at which one can sell the received currency and purchase the bank account currency in this case the AUD/USD cross rate or 0.8/0.9 = 0.88889 - So the receipt ex rate will always be 1 if the currency of the bank account is the same as the customer currency. - + So the receipt ex rate will always be 1 if the currency of the bank account is the same as the customer currency. + */ $ReceiptExRate = $CustCurrRow['rate']/$BankActRow['rate']; $FunctionalExRate = $BankActRow['rate']; - + DB_Txn_Begin($db); $ReceiptNo = GetNextTransNo(12,$db); @@ -368,10 +368,10 @@ '" . $Receipt['paymentmethod'] . "', '" . round($Receipt['amountfx'] / $ReceiptExRate,4) . "', '" . $CustCurrRow['currcode'] . "')"; - + $result = api_DB_query($SQL,$db,'','',true); - + if ($CompanyRecord['gllink_debtors']==1) { /* Now Credit Debtors account with receipts */ $SQL="INSERT INTO gltrans ( type, @@ -388,9 +388,9 @@ '". $CompanyRecord['debtorsact'] . "', '" . $Receipt['reference'] . "', '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) * $FunctionalExRate / $ReceiptExRate,4) . "')"; - + $result = api_DB_query($SQL,$db,'','',true); - + if($Receipt['discountfx']!=0){ $SQL="INSERT INTO gltrans ( type, typeno, @@ -406,7 +406,7 @@ '". $CompanyRecord['pytdiscountact'] . "', '" . $Receipt['reference'] . "', '" . round($Receipt['discountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; - + $result = api_DB_query($SQL,$db,'','',true); } /*and debit bank account with the receipt */ @@ -425,11 +425,11 @@ '" . $Receipt['bankaccount'] . "', '" . $Receipt['reference'] . "', '" . round($Receipt['amountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; - + $result = api_DB_query($SQL,$db,'','',true); } /* end if GL linked to debtors */ - + $SQL = "INSERT INTO debtortrans (transno, type, debtorno, @@ -448,20 +448,20 @@ '" . date('Y-m-d H-i-s') . "', '" . $PeriodNo . "', '" . $Receipt['reference'] . "', - '" . ($ReceiptExRate/$FunctionalExRate) . "', - '" . -$Receipt['amountfx'] . "', - '" . -$Receipt['discountfx'] . "', - '" . $Receipt['paymentmethod'] . "')"; - + '" . ($ReceiptExRate/$FunctionalExRate) . "', + '" . -$Receipt['amountfx'] . "', + '" . -$Receipt['discountfx'] . "', + '" . $Receipt['paymentmethod'] . "')"; + $result = api_DB_query($SQL,$db,'','',true); - + $SQL = "UPDATE debtorsmaster SET lastpaiddate = '" . $Receipt['trandate'] . "', lastpaid='" . $Receipt['amountfx'] ."' WHERE debtorsmaster.debtorno='" . $Receipt['debtorno'] . "'"; - + $result = api_DB_query($SQL,$db,'','',true); - - + + if (sizeof($Errors)==0) { $Result = DB_Txn_Commit($db); $Errors[0]=0; @@ -474,7 +474,7 @@ function CreateCreditNote($Header,$LineDetails, $User, $Password) { - + /* Create a customer credit note in webERP. * Needs an associative array for the $Header * and an array of assocative arrays for the $LineDetails @@ -501,8 +501,8 @@ $Errors[0]=NoAuthorisation; return $Errors; } - - + + $Errors=VerifyDebtorExists($Header['debtorno'], sizeof($Errors), $Errors, $db); $Errors=VerifyBranchNoExists($Header['debtorno'],$Header['branchcode'], sizeof($Errors), $Errors, $db); /*Does not deal with serialised/lot track items - for use by POS */ @@ -518,7 +518,7 @@ if (DB_error_no($db) != 0) { $Errors[] = NoCompanyRecord; } - + $HeaderSQL = "SELECT custbranch.area, custbranch.taxgroupid, debtorsmaster.currcode, @@ -602,7 +602,7 @@ } $LineTaxAmount = 0; - + while ($myrow = DB_fetch_array($GetTaxRatesResult)){ if (!isset($TaxTotals[$myrow['taxauthid']]['FXAmount'])) { $TaxTotals[$myrow['taxauthid']]['FXAmount']=0; @@ -618,7 +618,7 @@ $TaxAuthAmount = $LineNetAmount * $myrow['taxrate']; } $TaxTotals[$myrow['taxauthid']]['FXAmount'] += $TaxAuthAmount; - + /*Make an array of the taxes and amounts including GLcodes for later posting - need debtortransid so can only post once the debtor trans is posted - can only post debtor trans when all tax is calculated */ $LineTaxes[$LineCounter][$myrow['calculationorder']] = array('TaxCalculationOrder' =>$myrow['calculationorder'], @@ -634,7 +634,7 @@ $TotalFXNetCredit += $LineNetAmount; $TotalFXTax += $LineTaxAmount; - + if ($LineRow['mbflag']=='B' OR $LineRow['mbflag']=='M') { $Assembly = False; @@ -645,7 +645,7 @@ WHERE locstock.stockid='" . $CN_Line['stockid'] . "' AND loccode= '" . $Header['fromstkloc'] . "'"; $Result = api_DB_query($SQL, $db); - + if (DB_num_rows($Result)==1){ $LocQtyRow = DB_fetch_row($Result); $QtyOnHandPrior = $LocQtyRow[0]; @@ -1101,16 +1101,16 @@ } #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'] . "' + + $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){ @@ -1123,11 +1123,11 @@ } else { $AllocateAmount = 0; } - if ($AllocateAmount > 0) { + if ($AllocateAmount > 0) { $SQL = "INSERT INTO custallocns (datealloc, amt, transid_allocfrom, - transid_allocto) + transid_allocto) VALUES ('" . date('Y-m-d') . "', '" . $AllocateAmount . "', '" . $DebtorTransID . "', @@ -1143,7 +1143,7 @@ settled = '" . $Settled . "' WHERE id = '" . $InvoiceRow['id'] ."'"; $UpdateAllocResult = api_DB_query($SQL,$db,'','',true); - + $Allocated -= $AllocateAmount; } if (abs($TotalCreditFX - $Allocated)<0.005){ @@ -1156,7 +1156,7 @@ WHERE id = '" . $DebtorTransID ."'"; $UpdateAllocResult = api_DB_query($SQL,$db,'','',true); } - + if (sizeof($Errors)==0) { $Result = DB_Txn_Commit($db); $Errors[0]=0; @@ -1252,35 +1252,35 @@ } if (sizeof($Errors)==0) { $result = DB_Txn_Begin($db); - $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames,0,-2) .") + $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames,0,-2) .") VALUES ('" . mb_substr($FieldValues,0,-2) ."') "; $result = DB_Query($sql, $db); $sql = "UPDATE systypes SET typeno='" . GetNextTransactionNo(10, $db) . "' WHERE typeid=10"; $result = DB_Query($sql, $db); $SalesGLCode=GetSalesGLCode($SalesArea, $PartCode, $db); $DebtorsGLCode=GetDebtorsGLCode($db); - $sql="INSERT INTO gltrans VALUES(null, + $sql="INSERT INTO gltrans VALUES(null, 10, '" . GetNextTransactionNo(10, $db) . "', 0, '" . $InvoiceDetails['trandate'] ."', - '" . $InvoiceDetails['prd'] . "', + '" . $InvoiceDetails['prd'] . "', '" . $DebtorsGLCode. "', - '". _('Invoice for') .' -' . $InvoiceDetails['debtorno'] .' ' . _('Total') . ' - '. $InvoiceDetails['ovamount'] . "', - '" . $InvoiceDetails['ovamount'] . "', + '". _('Invoice for') .' -' . $InvoiceDetails['debtorno'] .' ' . _('Total') . ' - '. $InvoiceDetails['ovamount'] . "', + '" . $InvoiceDetails['ovamount'] . "', 0, '" . $InvoiceDetails['jobref'] . "', 1)"; $result = api_DB_Query($sql, $db); - $sql="INSERT INTO gltrans VALUES(null, + $sql="INSERT INTO gltrans VALUES(null, 10, '" . GetNextTransactionNo(10, $db) . "', 0, '" . $InvoiceDetails['trandate'] ."', - '" . $InvoiceDetails['prd'] . "', + '" . $InvoiceDetails['prd'] . "', '" . $SalesGLCode . "', - '" . _('Invoice for') . ' -' . $InvoiceDetails['debtorno'] . ' ' . _('Total') .' - '. $InvoiceDetails['ovamount'] ."', - '" . (-intval($InvoiceDetails['ovamount'])) ."', + '" . _('Invoice for') . ' -' . $InvoiceDetails['debtorno'] . ' ' . _('Total') .' - '. $InvoiceDetails['ovamount'] ."', + '" . (-intval($InvoiceDetails['ovamount'])) ."', 0, '" . $InvoiceDetails['jobref'] . "', 1)"; @@ -1300,10 +1300,10 @@ } function AllocateTrans($AllocDetails, $User, $Password) { - + /* This function is quite specific and probably not generally useful * It only attempts to allocate a receipt or credit note sent to invoices that have a customerref equal to the value sent - * + * * The first parameter AllocDetails is an associative array containing: * AllocDetails['debtorno'] * AllocDetails['type'] @@ -1319,7 +1319,7 @@ } $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; } @@ -1335,7 +1335,7 @@ if (DB_num_rows($Result)==0){ $Errors[] = NoTransactionToAllocate; } - + if ($LeftToAllocRow['lefttoalloc'] <= 0){ /* negative if there is owt to allocate */ /*Now look for invoices with the same customerref to allocate to */ $SQL = "SELECT id, @@ -1347,7 +1347,7 @@ AND reference='" . $AllocDetails['customerref'] . "'"; $Result = api_DB_query($SQL,$db); $OSInvRow = DB_fetch_array($Result); - + if ($OSInvRow['rate']==$LeftToAllocRow['rate'] AND $OSInvRow['outstanding']>0){ @@ -1358,12 +1358,12 @@ /*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, + $SQL = "INSERT INTO custallocs (amt, + datealloc, + transid_allocfrom, transid_allocto) VALUE('" . $AllocateAmount . "', '" . Date('Y-m-d') . "', @@ -1386,8 +1386,8 @@ } else { $Result = DB_Txn_Rollback($db); } - return $Errors; - + return $Errors; + } /* Create a customer credit note in webERP. This function will bypass the @@ -1476,22 +1476,22 @@ } if (sizeof($Errors)==0) { $result = DB_Txn_Begin($db); - $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames,0,-2) . ") + $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames,0,-2) . ") VALUES ('".mb_substr($FieldValues,0,-2) ."') "; $result = DB_Query($sql, $db); $sql = "UPDATE systypes SET typeno='" . GetNextTransactionNo(11, $db) ."' WHERE typeid=10"; $result = DB_Query($sql, $db); $SalesGLCode=GetSalesGLCode($SalesArea, $PartCode, $db); $DebtorsGLCode=GetDebtorsGLCode($db); - $sql="INSERT INTO gltrans VALUES(null, + $sql="INSERT INTO gltrans VALUES(null, 10, '" . GetNextTransactionNo(11, $db). "', 0, '" . $CreditDetails['trandate'] . "', - '" . $CreditDetails['prd'] . "', + '" . $CreditDetails['prd'] . "', '" .$DebtorsGLCode . "', - '". _('Invoice for') . ' - '.$CreditDetails['debtorno'].' ' . -('Total') .' - '.$CreditDetails['ovamount']. "', - '" . $CreditDetails['ovamount'] . "', + '". _('Invoice for') . ' - '.$CreditDetails['debtorno'].' ' . -('Total') .' - '.$CreditDetails['ovamount']. "', + '" . $CreditDetails['ovamount'] . "', 0, '" . $CreditDetails['jobref'] ."')"; $result = DB_Query($sql, $db); @@ -1500,10 +1500,10 @@ '" . GetNextTransactionNo(11, $db) . "', 0, '" . $CreditDetails['trandate'] ."', - '" . $CreditDetails['prd'] . "', + '" . $CreditDetails['prd'] . "', '" . $SalesGLCode ."', - '". _('Invoice for') . ' - ' . $CreditDetails['debtorno'] .' ' . _('Total') . ' - '. $CreditDetails['ovamount'] ."', - '" .(-intval($CreditDetails['ovamount'])) . "', + '". _('Invoice for') . ' - ' . $CreditDetails['debtorno'] .' ' . _('Total') . ' - '. $CreditDetails['ovamount'] ."', + '" .(-intval($CreditDetails['ovamount'])) . "', 0, '" . $CreditDetails['jobref'] ."')"; $result = DB_Query($sql, $db); Modified: trunk/api/api_salesorders.php =================================================================== --- trunk/api/api_salesorders.php 2012-07-21 23:37:38 UTC (rev 5525) +++ trunk/api/api_salesorders.php 2012-07-22 03:29:54 UTC (rev 5526) @@ -5,10 +5,10 @@ // InsertSalesOrderHeader and ModifySalesOrderHeader have date fields // which need to be converted to the appropriate format. This is // a list of such fields used to detect date values and format appropriately. -$SOH_DateFields = array ('orddate', +$SOH_DateFields = array ('orddate', 'deliverydate', 'datepackingslipprinted', - 'quotedate', + 'quotedate', 'confirmeddate' ); /* Check that the custmerref field is 50 characters or less long */ @@ -345,10 +345,10 @@ } $FieldValues.="'".$value."', "; } - $sql = 'INSERT INTO salesorders ('.mb_substr($FieldNames,0,-2).") + $sql = 'INSERT INTO salesorders ('.mb_substr($FieldNames,0,-2).") VALUES (" . mb_substr($FieldValues,0,-2). ")"; if (sizeof($Errors)==0) { - + $result = api_DB_Query($sql, $db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; @@ -460,7 +460,7 @@ * already exist in webERP. */ function InsertSalesOrderLine($OrderLine, $user, $password) { - + $Errors = array(); $db = db($user, $password); if (gettype($db)=='integer') { @@ -488,7 +488,7 @@ $Errors=VerifyNarrative($OrderLine['narrative'], sizeof($Errors), $Errors); } /* - * Not sure why the verification of itemdue doesn't work + * Not sure why the verification of itemdue doesn't work if (isset($OrderLine['itemdue'])){ $Errors=VerifyItemDueDate($OrderLine['itemdue'], sizeof($Errors), $Errors); } @@ -507,8 +507,8 @@ } $FieldValues.= "'" . $value . "', "; } - - $sql = "INSERT INTO salesorderdetails (" . mb_substr($FieldNames,0,-2) . ") + + $sql = "INSERT INTO salesorderdetails (" . mb_substr($FieldNames,0,-2) . ") VALUES (" . mb_substr($FieldValues,0,-2) . ")"; if (sizeof($Errors)==0) { @@ -582,7 +582,7 @@ } return $Errors; } - + /* This function takes a Order Header ID and returns an associative array containing the database record for that Order. If the Order Header ID doesn't exist then it returns an $Errors array. @@ -606,13 +606,13 @@ return $Errors; } } - + /* This function takes a Order Header ID and returns an associative array containing the database record for that Order. If the Order Header ID doesn't exist then it returns an $Errors array. */ function GetSalesOrderLine($OrderNo, $user, $password) { - + $Errors = array(); $db = db($user, $password); if (gettype($db)=='integer') { @@ -631,15 +631,10 @@ return $Errors; } } - - - function InvoiceSalesOrder($OrderNo, $User, $Password) { -$fp = fopen( "/root/Web-Server/apidebug/DebugInfo.txt", "w"); + function InvoiceSalesOrder($OrderNo, $User, $Password) { - - $Errors = array(); $db = db($User, $Password); if (gettype($db)=='integer') { @@ -662,8 +657,8 @@ $CompanyRecord = DB_fetch_array($ReadCoyResult); if (DB_error_no($db) != 0) { $Errors[] = NoCompanyRecord; - } - + } + $OrderHeaderSQL = "SELECT salesorders.debtorno, debtorsmaster.name, salesorders.branchcode, @@ -692,10 +687,10 @@ $OrderHeaderResult = api_DB_query($OrderHeaderSQL,$db); if (DB_error_no($db) != 0) { $Errors[] = NoReadOrder; - } - + } + $OrderHeader = DB_fetch_array($OrderHeaderResult); - + $TaxProvResult = api_DB_query("SELECT taxprovinceid FROM locations WHERE loccode='" . $OrderHeader['fromstkloc'] ."'",$db); if (DB_error_no($db) != 0) { $Errors[] = NoTaxProvince; @@ -720,21 +715,21 @@ $Errors[] = NoReadOrderLines; return $Errors; } - + /*Start an SQL transaction */ $result = DB_Txn_Begin($db); /*Now Get the next invoice number - function in SQL_CommonFunctions*/ $InvoiceNo = GetNextTransNo(10, $db); $PeriodNo = GetCurrentPeriod($db); - + $TaxTotals =array(); - + $TotalFXNetInvoice = 0; $TotalFXTax = 0; $LineCounter =0; while ($OrderLineRow = DB_fetch_array($LineItemsResult)) { - + $StandardCost = $OrderLineRow['standardcost']; $LocalCurrencyPrice= ($OrderLineRow['unitprice'] *(1- floatval($OrderLineRow['discountpercent'])))/ $OrderHeader['rate']; $LineNetAmount = $OrderLineRow['unitprice'] * $OrderLineRow['quantity'] *(1- floatval($OrderLineRow['discountpercent'])); @@ -758,10 +753,10 @@ ORDER BY taxgrouptaxes.calculationorder"; $GetTaxRatesResult = api_DB_query($SQL,$db); - + if (DB_error_no($db) != 0) { $Errors[] = TaxRatesFailed; - } + } $LineTaxAmount = 0; while ($myrow = DB_fetch_array($GetTaxRatesResult)){ @@ -779,7 +774,7 @@ $TaxAuthAmount = $LineNetAmount * $myrow['taxrate']; } $TaxTotals[$myrow['taxauthid']]['FXAmount'] += $TaxAuthAmount; - + /*Make an array of the taxes and amounts including GLcodes for later posting - need debtortransid so can only post once the debtor trans is posted - can only post debtor trans when all tax is calculated */ $LineTaxes[$LineCounter][$myrow['calculationorder']] = array('TaxCalculationOrder' =>$myrow['calculationorder'], @@ -804,8 +799,8 @@ AND stkcode = '" . $OrderLineRow['stkcode'] . "'"; $Result = api_DB_query($SQL,$db,'','',true); - - + + if ($OrderLineRow['mbflag']=='B' OR $OrderLineRow['mbflag']=='M') { $Assembly = False; @@ -816,7 +811,7 @@ WHERE locstock.stockid='" . $OrderLineRow['stkcode'] . "' AND loccode= '" . $OrderHeader['fromstkloc'] . "'"; $Result = api_DB_query($SQL, $db); - + if (DB_num_rows($Result)==1){ $LocQtyRow = DB_fetch_row($Result); $QtyOnHandPrior = $LocQtyRow[0]; @@ -830,7 +825,7 @@ WHERE locstock.stockid = '" . $OrderLineRow['stkcode'] . "' AND loccode = '" . $OrderHeader['fromstkloc'] . "'"; $Result = api_DB_query($SQL,$db,'','',true); - + $SQL = "INSERT INTO stockmoves (stockid, type, transno, @@ -859,9 +854,9 @@ '" . $OrderLineRow['discountpercent'] . "', '" . $StandardCost . "', '" . ($QtyOnHandPrior - $OrderLineRow['quantity']) . "' )"; - + $Result = api_DB_query($SQL,$db,'','',true); - + } else if ($OrderLineRow['mbflag']=='A'){ /* its an assembly */ /*Need to get the BOM for this part and make stock moves for the components then update the Location stock balances */ @@ -937,9 +932,9 @@ } /* end of assembly explosion and updates */ } /* end of its an assembly */ - + if ($OrderLineRow['mbflag']=='A' OR $OrderLineRow['mbflag']=='D'){ - /*it's a Dummy/Service item or an Assembly item - still need stock movement record + /*it's a Dummy/Service item or an Assembly item - still need stock movement record * but quantites on hand are always nil */ $SQL = "INSERT INTO stockmoves (stockid, type, @@ -969,7 +964,7 @@ '" . $OrderLineRow['discountpercent'] . "', '" . $StandardCost . "', '0' )"; - + $Result = api_DB_query($SQL,$db,'','',true); } /*Get the ID of the StockMove... */ @@ -990,7 +985,7 @@ $Result = DB_query($SQL,$db,'','',true); } - + /*Insert Sales Analysis records */ $SQL="SELECT COUNT(*), @@ -1031,7 +1026,7 @@ $Result = DB_query($SQL,$db,$ErrMsg,$DbgMsg,true); $myrow = DB_fetch_row($Result); - + if ($myrow[0]>0){ /*Update the existing record that already exists */ $SQL = "UPDATE salesanalysis @@ -1047,7 +1042,7 @@ AND stockid " . LIKE . " '" . $OrderLineRow['stkcode'] . "' AND salesanalysis.stkcategory ='" . $myrow[1] . "' AND budgetoractual='1'"; - + } else { /* insert a new sales analysis record */ $SQL = "INSERT INTO salesanalysis ( typeabbrev, @@ -1080,9 +1075,9 @@ WHERE stockmaster.stockid = '" . $OrderLineRow['stkcode'] . "' AND custbranch.debtorno = '" . $OrderHeader['debtorno'] . "' AND custbranch.branchcode='" . $OrderHeader['branchcode'] . "'"; - + } - + $Result = api_DB_query($SQL,$db,'','',true); if ($CompanyRecord['gllink_stock']==1 AND $StandardCost !=0){ @@ -1105,7 +1100,7 @@ '" . ($StandardCost * $OrderLineRow['quantity']) . "')"; $Result = api_DB_query($SQL,$db,'','',true); - + /*now the stock entry - this is set to the cost act in the case of a fixed asset disposal */ $StockGLCode = GetStockGLCode($OrderLineRow['stkcode'],$db); @@ -1125,7 +1120,7 @@ '" . (-$StandardCost * $OrderLineRow['quantity']) . "')"; $Result = api_DB_query($SQL,$db,'','',true); - + } /* end of if GL and stock integrated and standard cost !=0 and not an asset */ if ($CompanyRecord['gllink_debtors']==1 AND $OrderLineRow['unitprice'] !=0){ @@ -1149,7 +1144,7 @@ '" . -$OrderLineRow['unitprice'] * $OrderLineRow['quantity']/$OrderHeader['rate'] . "' )"; $Result = api_DB_query($SQL,$db,'','',true); - + if ($OrderLineRow['discountpercent'] !=0){ $SQL = "INSERT INTO gltrans (type, @@ -1223,7 +1218,7 @@ $Result = api_DB_query($SQL,$db,'','',true); } EnsureGLEntriesBalance(10,$InvoiceNo,$db); - + } /*end of if Sales and GL integrated */ /*Update order header for invoice charged on */ @@ -1261,14 +1256,14 @@ '" . $TotalFXTax . "', '" . $OrderHeader['rate'] . "', '" . $OrderHeader['shipvia'] . "')"; - + $Result = api_DB_query($SQL,$db,'','',true); - + $DebtorTransID = DB_Last_Insert_ID($db,'debtortrans','id'); - + /*for each Tax - need to insert into debtortranstaxes */ foreach ($TaxTotals AS $TaxAuthID => $Tax) { - + $SQL = "INSERT INTO debtortranstaxes (debtortransid, taxauthid, taxamount) @@ -1277,27 +1272,27 @@ '" . $Tax['FXAmount']/$OrderHeader['rate'] . "')"; $Result = api_DB_query($SQL,$db,'','',true); } - + if (sizeof($Errors)==0) { - + $Result = DB_Txn_Commit($db); $Errors[0]=0; $Errors[1]=$InvoiceNo; } else { $Result = DB_Txn_Rollback($db); - } + } return $Errors; } //end InvoiceSalesOrder function - - + + function GetCurrentPeriod (&$db) { - + $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); $myrow=DB_fetch_row($result); - + if (is_null($myrow[0])){ $InsertFirstPeriodResult = api_DB_query("INSERT INTO periods VALUES (0,'" . Date('Y-m-d',mktime(0,0,0,Date('m')+1,0,Date('Y'))) . "')",$db); $InsertFirstPeriodResult = api_DB_query("INSERT INTO periods VALUES (1,'" . Date('Y-m-d',mktime(0,0,0,Date('m')+2,0,Date('Y'))) . "')",$db); @@ -1315,14 +1310,14 @@ $Date_Array = explode('-', $myrow[0]); $FirstPeriodEnd = mktime(0,0,0,$Date_Array[1],0,(int)$Date_Array[0]); $FirstPeriod = $myrow[1]; - + /* If the period number doesn't exist */ if (!PeriodExists($TransDate, $db)) { /* if the transaction is after the last period */ if ($TransDate > $LastPeriodEnd) { - + $PeriodEnd = mktime(0,0,0,Date('m', $TransDate)+1, 0, Date('Y', $TransDate)); - + while ($PeriodEnd >= $LastPeriodEnd) { if (Date('m', $LastPeriodEnd)<=13) { $LastPeriodEnd = mktime(0,0,0,Date('m', $LastPeriodEnd)+2, 0, Date('Y', $LastPeriodEnd)); @@ -1356,19 +1351,19 @@ $LastPeriod = $myrow[1]; CreatePeriod($LastPeriod+1, $LastPeriodEnd, $db); } - + /* Now return the period number of the transaction */ - + $MonthAfterTransDate = Mktime(0,0,0,Date('m',$TransDate)+1,Date('d',$TransDate),Date('Y',$TransDate)); - $GetPrdSQL = "SELECT periodno - FROM periods - WHERE lastdate_in_period < '" . Date('Y-m-d', $MonthAfterTransDate) . "' + $GetPrdSQL = "SELECT periodno + FROM periods + WHERE lastdate_in_period < '" . Date('Y-m-d', $MonthAfterTransDate) . "' AND lastdate_in_period >= '" . Date('Y-m-d', $TransDate) . "'"; - + $ErrMsg = _('An error occurred in retrieving the period number'); $GetPrdResult = DB_query($GetPrdSQL,$db,$ErrMsg); $myrow = DB_fetch_row($GetPrdResult); - + return $myrow[0]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-07-31 20:08:25
|
Revision: 5582 http://web-erp.svn.sourceforge.net/web-erp/?rev=5582&view=rev Author: daintree Date: 2012-07-31 20:08:18 +0000 (Tue, 31 Jul 2012) Log Message: ----------- correct ex rates for receipts Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_salesorders.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-07-31 13:29:43 UTC (rev 5581) +++ trunk/api/api_debtortransactions.php 2012-07-31 20:08:18 UTC (rev 5582) @@ -269,7 +269,7 @@ function InsertDebtorReceipt($Receipt, $User, $Password) { /* - This function inserts a debtors receipt into a bank account/GL Postings and does the allocation and journals for difference on exchange + This function inserts a debtors receipt into a bank account/GL Postings $Receipt contains an associative array in the format: * $Receipt['debtorno'] - the customer code @@ -387,7 +387,7 @@ '" . $PeriodNo . "', '". $CompanyRecord['debtorsact'] . "', '" . $Receipt['reference'] . "', - '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) * $FunctionalExRate / $ReceiptExRate,4) . "')"; + '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) / $CustCurrRow['rate'],4) . "')"; $result = api_DB_query($SQL,$db,'','',true); @@ -405,7 +405,7 @@ '" . $PeriodNo . "', '". $CompanyRecord['pytdiscountact'] . "', '" . $Receipt['reference'] . "', - '" . round($Receipt['discountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; + '" . round($Receipt['discountfx'] / $CustCurrRow['rate'],4) . "')"; $result = api_DB_query($SQL,$db,'','',true); } @@ -424,7 +424,7 @@ '" . $PeriodNo . "', '" . $Receipt['bankaccount'] . "', '" . $Receipt['reference'] . "', - '" . round($Receipt['amountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; + '" . round($Receipt['amountfx'] / $CustCurrRow['rate'],4) . "')"; $result = api_DB_query($SQL,$db,'','',true); @@ -448,7 +448,7 @@ '" . date('Y-m-d H-i-s') . "', '" . $PeriodNo . "', '" . $Receipt['reference'] . "', - '" . ($ReceiptExRate/$FunctionalExRate) . "', + '" . $CustCurrRow['rate'] . "', '" . -$Receipt['amountfx'] . "', '" . -$Receipt['discountfx'] . "', '" . $Receipt['paymentmethod'] . "')"; Modified: trunk/api/api_salesorders.php =================================================================== --- trunk/api/api_salesorders.php 2012-07-31 13:29:43 UTC (rev 5581) +++ trunk/api/api_salesorders.php 2012-07-31 20:08:18 UTC (rev 5582) @@ -350,8 +350,10 @@ if (sizeof($Errors)==0) { $result = api_DB_Query($sql, $db); + if (DB_error_no($db) != 0) { - $Errors[0] = DatabaseUpdateFailed; + //$Errors[0] = DatabaseUpdateFailed; + $Errors[0] = $sql; } else { $Errors[0]=0; $Errors[1]=$OrderHeader['orderno']; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dai...@us...> - 2012-07-31 20:08:28
|
Revision: 5582 http://web-erp.svn.sourceforge.net/web-erp/?rev=5582&view=rev Author: daintree Date: 2012-07-31 20:08:18 +0000 (Tue, 31 Jul 2012) Log Message: ----------- correct ex rates for receipts Modified Paths: -------------- trunk/api/api_debtortransactions.php trunk/api/api_salesorders.php Modified: trunk/api/api_debtortransactions.php =================================================================== --- trunk/api/api_debtortransactions.php 2012-07-31 13:29:43 UTC (rev 5581) +++ trunk/api/api_debtortransactions.php 2012-07-31 20:08:18 UTC (rev 5582) @@ -269,7 +269,7 @@ function InsertDebtorReceipt($Receipt, $User, $Password) { /* - This function inserts a debtors receipt into a bank account/GL Postings and does the allocation and journals for difference on exchange + This function inserts a debtors receipt into a bank account/GL Postings $Receipt contains an associative array in the format: * $Receipt['debtorno'] - the customer code @@ -387,7 +387,7 @@ '" . $PeriodNo . "', '". $CompanyRecord['debtorsact'] . "', '" . $Receipt['reference'] . "', - '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) * $FunctionalExRate / $ReceiptExRate,4) . "')"; + '" . round((-$Receipt['amountfx']-$Receipt['discountfx']) / $CustCurrRow['rate'],4) . "')"; $result = api_DB_query($SQL,$db,'','',true); @@ -405,7 +405,7 @@ '" . $PeriodNo . "', '". $CompanyRecord['pytdiscountact'] . "', '" . $Receipt['reference'] . "', - '" . round($Receipt['discountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; + '" . round($Receipt['discountfx'] / $CustCurrRow['rate'],4) . "')"; $result = api_DB_query($SQL,$db,'','',true); } @@ -424,7 +424,7 @@ '" . $PeriodNo . "', '" . $Receipt['bankaccount'] . "', '" . $Receipt['reference'] . "', - '" . round($Receipt['amountfx'] * $FunctionalExRate / $ReceiptExRate,4) . "')"; + '" . round($Receipt['amountfx'] / $CustCurrRow['rate'],4) . "')"; $result = api_DB_query($SQL,$db,'','',true); @@ -448,7 +448,7 @@ '" . date('Y-m-d H-i-s') . "', '" . $PeriodNo . "', '" . $Receipt['reference'] . "', - '" . ($ReceiptExRate/$FunctionalExRate) . "', + '" . $CustCurrRow['rate'] . "', '" . -$Receipt['amountfx'] . "', '" . -$Receipt['discountfx'] . "', '" . $Receipt['paymentmethod'] . "')"; Modified: trunk/api/api_salesorders.php =================================================================== --- trunk/api/api_salesorders.php 2012-07-31 13:29:43 UTC (rev 5581) +++ trunk/api/api_salesorders.php 2012-07-31 20:08:18 UTC (rev 5582) @@ -350,8 +350,10 @@ if (sizeof($Errors)==0) { $result = api_DB_Query($sql, $db); + if (DB_error_no($db) != 0) { - $Errors[0] = DatabaseUpdateFailed; + //$Errors[0] = DatabaseUpdateFailed; + $Errors[0] = $sql; } else { $Errors[0]=0; $Errors[1]=$OrderHeader['orderno']; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |