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 StockAdjustment($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); $balances = GetStockBalance($StockID, $user, $password); $balance = 0; for ($i = 0; $i < sizeof($balances); $i++) { $balance = $balance + $balances[$i]['quantity']; } $newqoh = $Quantity + $balance; $itemdetails = GetStockItem($StockID, $user, $password); $adjglact = GetCategoryGLCode($itemdetails[1]['categoryid'], 'adjglact', $db); $stockact = GetCategoryGLCode($itemdetails[1]['categoryid'], 'stockact', $db); $stockmovesql = "INSERT INTO stockmoves (stockid,\n type,\n transno,\n loccode,\n trandate,\n prd,\n reference,\n qty,\n newqoh)\n VALUES ('" . $StockID . "',\n '17',\n '" . GetNextTransactionNo(17, $db) . "',\n '" . $Location . "',\n '" . $TranDate . "',\n '" . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . "',\n 'api adjustment',\n '" . $Quantity . "',\n '" . $newqoh . "')"; $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 VALUES ('17',\n '" . GetNextTransactionNo(17, $db) . "',\n '" . $TranDate . "',\n '" . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . "',\n '" . $adjglact . "',\n '" . $itemdetails['materialcost'] * -$Quantity . "',\n '" . $StockID . ' x ' . $Quantity . ' @ ' . $itemdetails['materialcost'] . "')"; $glupdatesql2 = "INSERT INTO gltrans (type,\n typeno,\n trandate,\n periodno,\n account,\n amount,\n narrative)\n\t\t\t\t\t\tVALUES ('17',\n '" . GetNextTransactionNo(17, $db) . "',\n '" . $TranDate . "',\n '" . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . "',\n '" . $stockact . "',\n '" . $itemdetails['materialcost'] * $Quantity . "',\n '" . $StockID . ' x ' . $Quantity . ' @ ' . $itemdetails['materialcost'] . "')"; $systypessql = "UPDATE systypes set typeno='" . GetNextTransactionNo(17, $db) . "' where typeid='17'"; 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; return $Errors; } else { return 0; } }
function StockAdjustment($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); $balances = GetStockBalance($StockID, $user, $password); $balance = 0; for ($i = 0; $i < sizeof($balances); $i++) { $balance = $balance + $balances[$i]['quantity']; } $newqoh = $Quantity + $balance; $itemdetails = GetStockItem($StockID, $user, $password); $adjglact = GetCategoryGLCode($itemdetails['categoryid'], 'adjglact', $db); $stockact = GetCategoryGLCode($itemdetails['categoryid'], 'stockact', $db); $stockmovesql = 'INSERT INTO stockmoves (stockid, type, transno, loccode, trandate, prd, reference, qty, newqoh) VALUES ("' . $StockID . '", 17,' . GetNextTransactionNo(17, $db) . ',"' . $Location . '","' . $TranDate . '",' . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . ',"api adjustment",' . $Quantity . ',' . $newqoh . ')'; $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 (17,' . GetNextTransactionNo(17, $db) . ',"' . $TranDate . '",' . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . ',' . $adjglact . ',' . $itemdetails['materialcost'] * -$Quantity . ',"' . $StockID . ' x ' . $Quantity . ' @ ' . $itemdetails['materialcost'] . '")'; $glupdatesql2 = 'INSERT INTO gltrans (type, typeno, trandate, periodno, account, amount, narrative) VALUES (17,' . GetNextTransactionNo(17, $db) . ',"' . $TranDate . '",' . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . ',' . $stockact . ',' . $itemdetails['materialcost'] * $Quantity . ',"' . $StockID . ' x ' . $Quantity . ' @ ' . $itemdetails['materialcost'] . '")'; $systypessql = 'UPDATE systypes set typeno=' . GetNextTransactionNo(17, $db) . ' where typeid=17'; 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; return $Errors; } else { return 0; } }
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; }