Php-er,
I've been working on severals stock reporting and processing. And i've tried many ways to achieve one. And finally i've came with final. This is it check it out.
Source code:
require_once 'classCol/misc.php';
require_once 'classCol/classStockCalc.php';
/**
* Example: Lets say we have 5 stock entry.
* We arrange them in this format
* DATE---QTY---PRICE---VALUE---REFERENCE
* where: "---" is delimiter.
* Dont worry if one of the value is negative
* since the filter will only take --- exactly.
*
*/
$isDbg = _IS_DEBUG;
$CStockCalc = new stockCalc;
$egTx = array("STOCK_DATE" => array("01-06-2008",
"02-06-2008",
"03-06-2008",
"04-06-2008",
"05-06-2008"),
"QTY" => array("1000",
"2000",
"1000",
"2000",
"1000"),
"PRICE" => array("200",
"400",
"300",
"400",
"250"),
"VALUE" => array("200000",
"800000",
"300000",
"800000",
"250000"),
"REFERENCE" => array("000001/STKOUT/06-2008",
"000002/STKOUT/06-2008",
"000003/STKOUT/06-2008",
"000004/STKOUT/06-2008",
"000005/STKOUT/06-2008",
"000006/STKOUT/06-2008"));
$szEgTx = sizeof($egTx["REFERENCE"]) - 1; //downtop loop, subs by one
for($iTx = $szEgTx; $iTx >= 0; $iTx--){ //where $iTx >= 0
$dataTx = $egTx["STOCK_DATE"][$iTx] ."---".
$egTx["QTY"][$iTx] ."---".
$egTx["PRICE"][$iTx] ."---".
$egTx["VALUE"][$iTx] ."---".
$egTx["REFERENCE"][$iTx];
$CStockCalc->addDetails($dataTx);
}
$qtyOut = 2500;
//calculate the FIFO
$CStockCalc->calcFifo($qtyOut);
$resQtyOut = $CStockCalc->getQtyOutDetails();
$resQtyBal = $CStockCalc->getQtyBalDetails();
dbgInfo("resQtyOut",$resQtyOut["QTY"],$isDbg);
dbgInfo("resQtyOut",$resQtyOut["VALUE"],$isDbg);
dbgInfo("resQtyBal",$resQtyBal["QTY"],$isDbg);
dbgInfo("resQtyBal",$resQtyBal["VALUE"],$isDbg);
Yup, itu aja. Silahkan method nya dipilih sendiri utk fifo, lifo ato average.
Full source code bisa di download disini stockCalc. Artikel selanjutanya akan bahas mengupas classStockCalc ini.
Gbu.
Coding for life, coding with ethic.
Comments