예제 #1
0
function WorkOrderIssue($WONumber, $StockID, $Location, $Quantity, $TranDate, $Batch, $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 = VerifyIssuedQuantity($Quantity, sizeof($Errors), $Errors);
    //		$Errors = VerifyTransactionDate($TranDate, sizeof($Errors), $Errors, $db);
    if ($Batch != '') {
        VerifyBatch($Batch, $StockID, $Location, sizeof($Errors), $Errors, $db);
    }
    if (sizeof($Errors) != 0) {
        return $Errors;
    } else {
        $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);
        $wipglact = GetCategoryGLCode($itemdetails[1]['categoryid'], 'wipact', $db);
        $stockact = GetCategoryGLCode($itemdetails[1]['categoryid'], 'stockact', $db);
        $cost = $itemdetails[1]['materialcost'] + $itemdetails[1]['labourcost'] + $itemdetails[1]['overheadcost'];
        $TransactionNo = GetNextTransactionNo(28, $db);
        $stockmovesql = 'INSERT INTO stockmoves (stockid, type, transno, loccode, trandate, prd, reference, qty, newqoh,
				price, standardcost)
				VALUES ("' . $StockID . '", 28,' . $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 (28,' . $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 (28,' . $TransactionNo . ',"' . $TranDate . '",' . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . ',' . $stockact . ',' . $cost * $Quantity . ',"' . $StockID . ' x ' . $Quantity . ' @ ' . $cost . '")';
        $systypessql = 'UPDATE systypes set typeno=' . $TransactionNo . ' where typeid=28';
        $batchsql = 'UPDATE stockserialitems SET quantity=quantity-' . $Quantity . ' WHERE stockid="' . $StockID . '" AND loccode="' . $Location . '" AND serialno="' . $Batch . '"';
        $costsql = 'UPDATE workorders SET costissued=costissued+' . $cost . ' WHERE wo=' . $WONumber;
        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_query($costsql, $db);
        if ($Batch != '') {
            DB_Query($batchsql, $db);
        }
        DB_Txn_Commit($db);
        if (DB_error_no($db) != 0) {
            $Errors[0] = DatabaseUpdateFailed;
            return $Errors;
        } else {
            return 0;
        }
    }
}
예제 #2
0
function WorkOrderIssue($WONumber, $StockID, $Location, $Quantity, $TranDate, $Batch, $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 = VerifyIssuedQuantity($Quantity, sizeof($Errors), $Errors);
    //		$Errors = VerifyTransactionDate($TranDate, sizeof($Errors), $Errors, $db);
    if ($Batch != '') {
        VerifyBatch($Batch, $StockID, $Location, sizeof($Errors), $Errors, $db);
    }
    if (sizeof($Errors) != 0) {
        return $Errors;
    } else {
        $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);
        $wipglact = GetCategoryGLCode($itemdetails[1]['categoryid'], 'wipact', $db);
        $stockact = GetCategoryGLCode($itemdetails[1]['categoryid'], 'stockact', $db);
        $cost = $itemdetails[1]['materialcost'] + $itemdetails[1]['labourcost'] + $itemdetails[1]['overheadcost'];
        $TransactionNo = GetNextTransactionNo(28, $db);
        $stockmovesql = "INSERT INTO stockmoves (stockid,\n                                                   type,\n                                                   transno,\n                                                   loccode,\n                                                   trandate,\n                                                   prd,\n                                                   reference,\n                                                   qty,\n                                                   newqoh,\n\t\t\t\t                                   price,\n                                                   standardcost)\n                                   \t\tVALUES ('" . $StockID . "',\n                                                28,\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\t\t\t                           WHERE loccode='" . $Location . "'\n\t\t\t                           AND stockid='" . $StockID . "'";
        $glupdatesql1 = "INSERT INTO gltrans (type,\n\t\t\t\t\t\t                                               typeno,\n\t\t\t\t\t\t                                               trandate,\n\t\t\t\t\t\t                                               periodno,\n\t\t\t\t\t\t                                               account,\n\t\t\t\t\t\t                                               amount,\n\t\t\t\t\t\t                                               narrative)\n\t\t\t\t\t\t\t\t\t      VALUES (28,\n\t\t\t\t\t\t                                              '" . $TransactionNo . "',\n\t\t\t\t\t\t                                              '" . $TranDate . "',\n\t\t\t\t\t\t                                              '" . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . "',\n\t\t\t\t\t\t                                              '" . $wipglact . "',\n\t\t\t\t\t\t                                              '" . $cost * -$Quantity . "',\n\t\t\t\t\t\t                                              '" . $StockID . ' x ' . $Quantity . ' @ ' . $cost . "')";
        $glupdatesql2 = "INSERT INTO gltrans (type,\n\t\t\t\t\t\t                                                typeno,\n\t\t\t\t\t\t                                                trandate,\n\t\t\t\t\t\t                                                periodno,\n\t\t\t\t\t\t                                                account,\n\t\t\t\t\t\t                                                amount,\n\t\t\t\t\t\t                                                narrative)\n\t\t\t\t\t\t                          VALUES (28,\n\t\t\t\t\t\t                                        '" . $TransactionNo . "',\n\t\t\t\t\t\t                                        '" . $TranDate . "',\n\t\t\t\t\t\t                                        '" . GetPeriodFromTransactionDate($TranDate, sizeof($Errors), $Errors, $db) . "',\n\t\t\t\t\t\t                                        '" . $stockact . "',\n\t\t\t\t\t\t                                        '" . $cost * $Quantity . "',\n\t\t\t\t\t\t                                        '" . $StockID . ' x ' . $Quantity . ' @ ' . $cost . "')";
        $systypessql = "UPDATE systypes set typeno='" . $TransactionNo . "' where typeid=28";
        $batchsql = "UPDATE stockserialitems SET quantity=quantity-" . $Quantity . " WHERE stockid='" . $StockID . "'\n                              AND loccode='" . $Location . "' AND serialno='" . $Batch . "'";
        $costsql = "UPDATE workorders SET costissued=costissued+" . $cost . " WHERE wo='" . $WONumber . "'";
        DB_Txn_Begin();
        DB_query($stockmovesql);
        DB_query($locstocksql);
        DB_query($glupdatesql1);
        DB_query($glupdatesql2);
        DB_query($systypessql);
        DB_query($costsql);
        if ($Batch != '') {
            DB_Query($batchsql, $db);
        }
        DB_Txn_Commit();
        if (DB_error_no() != 0) {
            $Errors[0] = DatabaseUpdateFailed;
            return $Errors;
        } else {
            return 0;
        }
    }
}