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. |