示例#1
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;
}