function ModifySalesOrderLine($OrderLine, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } foreach ($OrderLine as $key => $value) { $OrderLine[$key] = DB_escape_string($value); } $Errors = VerifyOrderHeaderExists($OrderLine['orderno'], sizeof($Errors), $Errors, $db); $Errors = VerifyStockCodeExists($OrderLine['stkcode'], sizeof($Errors), $Errors, $db); if (isset($OrderLine['unitprice'])) { $Errors = VerifyUnitPrice($OrderLine['unitprice'], sizeof($Errors), $Errors); } if (isset($OrderLine['quantity'])) { $Errors = VerifyQuantity($OrderLine['quantity'], sizeof($Errors), $Errors); } if (isset($OrderLine['discountpercent'])) { //$OrderLine['discountpercent'] = $OrderLine['discountpercent'] * 100; $Errors = VerifyDiscountPercent($OrderLine['discountpercent'], sizeof($Errors), $Errors); $OrderLine['discountpercent'] = $OrderLine['discountpercent'] / 100; } if (isset($OrderLine['narrative'])) { $Errors = VerifyNarrative($OrderLine['narrative'], sizeof($Errors), $Errors); } if (isset($OrderLine['itemdue'])) { $Errors = VerifyItemDueDate($OrderLine['itemdue'], sizeof($Errors), $Errors); } if (isset($OrderLine['poline'])) { $Errors = VerifyPOLine($OrderLine['poline'], sizeof($Errors), $Errors); } $sql = 'UPDATE salesorderdetails SET '; foreach ($OrderLine as $key => $value) { if ($key == 'actualdispatchdate') { $value = FormatDateWithTimeForSQL($value); } elseif ($key == 'itemdue') { $value = FormatDateForSQL($value); } $sql .= $key . '="' . $value . '", '; } //$sql = substr($sql,0,-2).' WHERE orderno="'.$OrderLine['orderno'].'" and // " orderlineno='.$OrderLine['orderlineno']; $sql = substr($sql, 0, -2) . ' WHERE orderno="' . $OrderLine['orderno'] . '" and stkcode="' . $OrderLine['stkcode'] . '"'; //echo $sql; //exit; if (sizeof($Errors) == 0) { $result = api_DB_Query($sql, $db); echo DB_error_no($db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; } else { $Errors[0] = 0; } } return $Errors; }
function ModifyPurchData($PurchDataDetails, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } foreach ($PurchDataDetails as $key => $value) { $PurchDataDetails[$key] = DB_escape_string($value); } $Errors = VerifyPurchDataLineExists($PurchDataDetails['supplierno'], $PurchDataDetails['stockid'], sizeof($Errors), $Errors, $db); $Errors = VerifyStockCodeExists($PurchDataDetails['stockid'], sizeof($Errors), $Errors, $db); $Errors = VerifySupplierNoExists($PurchDataDetails['supplierno'], sizeof($Errors), $Errors, $db); if (isset($StockItemDetails['price'])) { $Errors = VerifyUnitPrice($PurchDataDetails['price'], sizeof($Errors), $Errors); } if (isset($StockItemDetails['suppliersuom'])) { $Errors = VerifySuppliersUOM($PurchDataDetails['suppliersuom'], sizeof($Errors), $Errors); } if (isset($StockItemDetails['conversionfactor'])) { $Errors = VerifyConversionFactor($PurchDataDetails['conversionfactor'], sizeof($Errors), $Errors); } if (isset($StockItemDetails['supplierdescription'])) { $Errors = VerifySupplierDescription($PurchDataDetails['supplierdescription'], sizeof($Errors), $Errors); } if (isset($StockItemDetails['leadtime'])) { $Errors = VerifyLeadTime($PurchDataDetails['leadtime'], sizeof($Errors), $Errors); } if (isset($StockItemDetails['preferred'])) { $Errors = VerifyPreferredFlag($PurchDataDetails['preferred'], sizeof($Errors), $Errors); } $sql = "UPDATE purchdata SET "; foreach ($PurchDataDetails as $key => $value) { $sql .= $key . "='" . $value . "', "; } $sql = mb_substr($sql, 0, -2) . " WHERE stockid='" . $PurchDataDetails['stockid'] . "'\n\t\t\t\t\t\t\t\tAND supplierno='" . $PurchDataDetails['supplierno'] . "'"; if (sizeof($Errors) == 0) { $result = DB_Query($sql, $db); echo DB_error_no($db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; } else { $Errors[0] = 0; } } return $Errors; }
function InsertSalesCredit($CreditDetails, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } foreach ($CreditDetails as $key => $value) { $CreditDetails[$key] = DB_escape_string($value); } $PartCode = $CreditDetails['partcode']; $Errors = VerifyStockCodeExists($PartCode, sizeof($Errors), $Errors, $db); unset($CreditDetails['partcode']); $SalesArea = $CreditDetails['salesarea']; unset($CreditDetails['salesarea']); $CreditDetails['transno'] = GetNextTransactionNo(11, $db); $CreditDetails['type'] = 10; $Errors = VerifyDebtorExists($CreditDetails['debtorno'], sizeof($Errors), $Errors, $db); $Errors = VerifyBranchNoExists($CreditDetails['debtorno'], $CreditDetails['branchcode'], sizeof($Errors), $Errors, $db); $Errors = VerifyTransNO($CreditDetails['transno'], 10, sizeof($Errors), $Errors, $db); $Errors = VerifyTransactionDate($CreditDetails['trandate'], sizeof($Errors), $Errors, $db); if (isset($CreditDetails['settled'])) { $Errors = VerifySettled($CreditDetails['settled'], sizeof($Errors), $Errors); } if (isset($CreditDetails['reference'])) { $Errors = VerifyReference($CreditDetails['reference'], sizeof($Errors), $Errors); } if (isset($CreditDetails['tpe'])) { $Errors = VerifyTpe($CreditDetails['tpe'], sizeof($Errors), $Errors); } if (isset($CreditDetails['order_'])) { $Errors = VerifyOrderNumber($CreditDetails['order_'], sizeof($Errors), $Errors); } if (isset($CreditDetails['rate'])) { $Errors = VerifyExchangeRate($CreditDetails['rate'], sizeof($Errors), $Errors); } if (isset($CreditDetails['ovamount'])) { $Errors = VerifyOVAmount($CreditDetails['ovamount'], sizeof($Errors), $Errors); } if (isset($CreditDetails['ovgst'])) { $Errors = VerifyOVGst($CreditDetails['ovgst'], sizeof($Errors), $Errors); } if (isset($CreditDetails['ovfreight'])) { $Errors = VerifyOVFreight($CreditDetails['ovfreight'], sizeof($Errors), $Errors); } if (isset($CreditDetails['ovdiscount'])) { $Errors = VerifyOVDiscount($CreditDetails['ovdiscount'], sizeof($Errors), $Errors); } if (isset($CreditDetails['diffonexch'])) { $Errors = VerifyDiffOnExchange($CreditDetails['diffonexch'], sizeof($Errors), $Errors); } if (isset($CreditDetails['alloc'])) { $Errors = VerifyAllocated($CreditDetails['alloc'], sizeof($Errors), $Errors); } if (isset($CreditDetails['invtext'])) { $Errors = VerifyInvoiceText($CreditDetails['invtext'], sizeof($Errors), $Errors); } if (isset($CreditDetails['shipvia'])) { $Errors = VerifyShipVia($CreditDetails['shipvia'], sizeof($Errors), $Errors); } if (isset($CreditDetails['edisent'])) { $Errors = VerifyEdiSent($CreditDetails['edisent'], sizeof($Errors), $Errors); } if (isset($CreditDetails['consignment'])) { $Errors = VerifyConsignment($CreditDetails['consignment'], sizeof($Errors), $Errors); } $FieldNames = ''; $FieldValues = ''; $CreditDetails['trandate'] = ConvertToSQLDate($CreditDetails['trandate']); $CreditDetails['prd'] = GetPeriodFromTransactionDate($CreditDetails['trandate'], sizeof($Errors), $Errors, $db); foreach ($CreditDetails as $key => $value) { $FieldNames .= $key . ', '; $FieldValues .= '"' . $value . '", '; } if (sizeof($Errors) == 0) { $result = DB_Txn_Begin($db); $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames, 0, -2) . ")\n\t\t\t\t\t\tVALUES ('" . 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,\n\t\t\t\t\t\t\t\t\t\t\t10,\n\t\t\t\t\t\t\t\t\t\t\t'" . GetNextTransactionNo(11, $db) . "',\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['trandate'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['prd'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $DebtorsGLCode . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . _('Invoice for') . ' - ' . $CreditDetails['debtorno'] . ' ' . -'Total' . ' - ' . $CreditDetails['ovamount'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['ovamount'] . "',\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['jobref'] . "')"; $result = DB_Query($sql, $db); $sql = "INSERT INTO gltrans VALUES(null,\n\t\t\t\t\t\t\t\t\t\t\t10,\n\t\t\t\t\t\t\t\t\t\t\t'" . GetNextTransactionNo(11, $db) . "',\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['trandate'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['prd'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $SalesGLCode . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . _('Invoice for') . ' - ' . $CreditDetails['debtorno'] . ' ' . _('Total') . ' - ' . $CreditDetails['ovamount'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . -intval($CreditDetails['ovamount']) . "',\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['jobref'] . "')"; $result = DB_Query($sql, $db); $result = DB_Txn_Commit($db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; } else { $Errors[0] = 0; } return $Errors; } else { return $Errors; } }
function GetBatches($StockID, $Location, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } $Errors = VerifyStockCodeExists($StockID, sizeof($Errors), $Errors, $db); $Errors = VerifyStockLocation($Location, sizeof($Errors), $Errors, $db); if (sizeof($Errors) != 0) { return $Errors; } $sql = "SELECT stockserialitems.stockid,\n\t\t\t\tloccode,\n\t\t\t\tstockserialitems.serialno as batchno,\n\t\t\t\tquantity,\n\t\t\t\tt.price as itemcost\n\t\t\tFROM stockserialitems JOIN (SELECT stockmoves.stockid,\n\t\t\t\t\t\t\t\t\t\tstockmoves.price,\n\t\t\t\t\t\t\t\t\t\tstockserialmoves.serialno\n\t\t\t\t\t\t\t\t\t\tFROM stockmoves JOIN stockserialmoves\n\t\t\t\t\t\t\t\t\t\tON stockmoves.stkmoveno=stockserialmoves.stockmoveno\n\t\t\t\t\t\t\t\t\t\tWHERE stockmoves.type=25) as t\n\t\t\t\tON stockserialitems.stockid=t.stockid and stockserialitems.serialno=t.serialno\n\t\t\tWHERE stockid='" . $StockID . "' AND loccode='" . $Location . "'"; $result = DB_Query($sql, $db); if (sizeof($Errors) == 0) { $i = 0; while ($myrow = DB_fetch_array($result)) { $answer[$i] = $myrow; $i++; } return $answer; } else { return $Errors; } }
function WorkOrderReceive($WONumber, $StockID, $Location, $Quantity, $TranDate, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } $Errors = VerifyStockCodeExists($StockID, sizeof($Errors), $Errors, $db); $Errors = VerifyWorkOrderExists($WONumber, sizeof($Errors), $Errors, $db); $Errors = VerifyStockLocation($Location, sizeof($Errors), $Errors, $db); $Errors = VerifyReceivedQuantity($Quantity, sizeof($Errors), $Errors); // $Errors = VerifyTransactionDate($TranDate, sizeof($Errors), $Errors); if (sizeof($Errors) != 0) { return $Errors; } $itemdetails = GetStockItem($StockID, $user, $password); $balances = GetStockBalance($StockID, $user, $password); $balance = 0; for ($i = 0; $i < sizeof($balances); $i++) { $balance = $balance + $balances[$i]['quantity']; } $newqoh = $Quantity + $balance; $wipglact = GetCategoryGLCode($itemdetails['categoryid'], 'wipact', $db); $stockact = GetCategoryGLCode($itemdetails['categoryid'], 'stockact', $db); $costsql = 'SELECT costissued FROM workorders WHERE wo=' . $WONumber; $costresult = DB_query($costsql); $myrow = DB_fetch_row($costresult); $cost = $myrow[0]; $TransactionNo = GetNextTransactionNo(26, $db); $stockmovesql = 'INSERT INTO stockmoves (stockid, type, transno, loccode, trandate, prd, reference, qty, newqoh, price, standardcost) VALUES ("' . $StockID . '", 26,' . $TransactionNo . ',"' . $Location . '","' . $TranDate . '",' . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . ',"' . $WONumber . '",' . $Quantity . ',' . $newqoh . ',' . $cost . ',' . $cost . ')'; $locstocksql = 'UPDATE locstock SET quantity = quantity + ' . $Quantity . ' WHERE loccode="' . $Location . '" AND stockid="' . $StockID . '"'; $glupdatesql1 = 'INSERT INTO gltrans (type, typeno, trandate, periodno, account, amount, narrative) VALUES (26,' . $TransactionNo . ',"' . $TranDate . '",' . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . ',' . $wipglact . ',' . $cost * $Quantity . ',"' . $StockID . ' x ' . $Quantity . ' @ ' . $cost . '")'; $glupdatesql2 = 'INSERT INTO gltrans (type, typeno, trandate, periodno, account, amount, narrative) VALUES (26,' . $TransactionNo . ',"' . $TranDate . '",' . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . ',' . $stockact . ',' . $cost * -$Quantity . ',"' . $StockID . ' x ' . $Quantity . ' @ ' . $cost . '")'; $systypessql = 'UPDATE systypes set typeno=' . $TransactionNo . ' where typeid=26'; DB_Txn_Begin($db); DB_query($stockmovesql, $db); DB_query($locstocksql, $db); DB_query($glupdatesql1, $db); DB_query($glupdatesql2, $db); DB_query($systypessql, $db); DB_Txn_Commit($db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; } else { $Errors[0] = 0; } return $Errors; }
function WorkOrderReceive($WONumber, $StockID, $Location, $Quantity, $TranDate, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } $Errors = VerifyStockCodeExists($StockID, sizeof($Errors), $Errors, $db); $Errors = VerifyWorkOrderExists($WONumber, sizeof($Errors), $Errors, $db); $Errors = VerifyStockLocation($Location, sizeof($Errors), $Errors, $db); $Errors = VerifyReceivedQuantity($Quantity, sizeof($Errors), $Errors); // $Errors = VerifyTransactionDate($TranDate, sizeof($Errors), $Errors); if (sizeof($Errors) != 0) { return $Errors; } $itemdetails = GetStockItem($StockID, $user, $password); $balances = GetStockBalance($StockID, $user, $password); $balance = 0; for ($i = 0; $i < sizeof($balances); $i++) { $balance = $balance + $balances[$i]['quantity']; } $newqoh = $Quantity + $balance; $wipglact = GetCategoryGLCode($itemdetails['categoryid'], 'wipact', $db); $stockact = GetCategoryGLCode($itemdetails['categoryid'], 'stockact', $db); $costsql = "SELECT costissued FROM workorders WHERE wo='" . $WONumber . "'"; $costresult = DB_query($costsql); $myrow = DB_fetch_row($costresult); $cost = $myrow[0]; $TransactionNo = GetNextTransactionNo(26, $db); $stockmovesql = "INSERT INTO stockmoves (stockid,\n type,\n transno,\n loccode,\n trandate,\n prd,\n reference,\n qty,\n newqoh,\n price,\n standardcost)\n \tVALUES ('" . $StockID . "',\n '26',\n '" . $TransactionNo . "',\n '" . $Location . "',\n '" . $TranDate . "',\n '" . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . "',\n '" . $WONumber . "',\n '" . $Quantity . "',\n '" . $newqoh . "',\n '" . $cost . "',\n '" . $cost . "')"; $locstocksql = "UPDATE locstock SET quantity = quantity + " . $Quantity . "\n WHERE loccode='" . $Location . "'\n AND stockid='" . $StockID . "'"; $glupdatesql1 = "INSERT INTO gltrans (type,\n typeno,\n trandate,\n periodno,\n account,\n amount,\n narrative)\n \t\tVALUES (26,\n '" . $TransactionNo . "',\n '" . $TranDate . "',\n '" . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . "',\n '" . $wipglact . "',\n '" . $cost * $Quantity . "',\n '" . $StockID . ' x ' . $Quantity . ' @ ' . $cost . "')"; $glupdatesql2 = "INSERT INTO gltrans (type,\n typeno,\n trandate,\n periodno,\n account,\n amount,\n narrative)\n \tVALUES (26,\n '" . $TransactionNo . "',\n '" . $TranDate . "',\n '" . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . "',\n '" . $stockact . ',' . $cost * -$Quantity . "',\n '" . $StockID . ' x ' . $Quantity . ' @ ' . $cost . "')"; $systypessql = "UPDATE systypes set typeno='" . $TransactionNo . "' where typeid=26"; DB_Txn_Begin(); DB_query($stockmovesql); DB_query($locstocksql); DB_query($glupdatesql1); DB_query($glupdatesql2); DB_query($systypessql); DB_Txn_Commit(); if (DB_error_no() != 0) { $Errors[0] = DatabaseUpdateFailed; } else { $Errors[0] = 0; } return $Errors; }