Jump to content

FIFO method for stock valuation


funbinod

Recommended Posts

ups sorry! it was my mistake.

 

i used require_once('classStockReport.php'), thats why it was selecting $sid only once.

i changed it to require('classStockReport.php') and it worked for all $sid.

 

thank u for ur company.

 

now will u please guide me how can i sum all $totamt of all $sid ?????

Link to comment
Share on other sites

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

I don't know why require_once() would be an issue. Is the Php file being called multiple times?

 

If you have a loop that generates all the sid and cqty values (in post #46 above) then you have everything you need. You can structure the code in several different ways. Also I would think you might want to generate output files so that the inventory processing data is preserved. To accumulate all of the $totamt you would simply keep a running total as the loops are processing the individual values.

Link to comment
Share on other sites

i dont know exactly but i think i had to loop that each time it finds $sid so using require_once made limit only to $sid=1 and using require made it open for all $sid that were found with while loop...

Link to comment
Share on other sites

and by running sum

 

did u mean the process like this---?

$total = array();$runSum = 0;foreach($totamt as $clamt) {	$runSum += $clamt;	$total[] = $runningSum;}print_r($total);

but how can i put the all values of $totamt to an array? like

$totamt = (0, 0, 73000, 4750, 4000, 10600)

or there is mistake or u suggest something else...???

Link to comment
Share on other sites

Maybe I don't understand the question? From post #46 above you have a loop that produces the cqty for each sid. You can put these into an array. I'm not real familiar with the limitations of Php arrays but I'm sure you can create a simple associative array with sid as the index and cqty as the value. Likewise you can create an array of totamt and sum it later or keep a running sum as you are creating it.

while ($row = mysqli_fetch_array($sql)) {	$inqty = $row['pqty']+$row['cnqty'];	$outqty = $row['sqty']+$row['dqty'];	$cqty = $row['oqty']+$inqty-$outqty;        $sid = $row['sid'];        $cqtyarr[ $sid ] = $cqty;...}

http://us1.php.net/manual/en/language.types.array.php

Link to comment
Share on other sites

perhaps u didn't understand my question.

 

i didn't mean to put all $cqty in an array. i meant to put all $totamt for all $sid.

 

in spite of this, i think we are on the way to the solution. i changed

$cqtyarr[ $sid ] = $cqty

to

$totamtarr[ $sid ] = $totamt

now the code looks like this ---

$totamtarr[ $sid ] = $totamt;$runSum = 0;foreach($totamtarr as $clamt) {$runSum += $clamt;$total[] = $runSum;}print_r($total);

it gave the result but it produced a long result array like this.

 

 

Array ( [0] => 0 ) Array ( [0] => 0 [1] => 0 [2] => 0 ) Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 )

..............................................................................

.........................................................................

Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 [9] => 73000 [10] => 0 [11] => 0 [12] => 0 [13] => 73000 [14] => 77750 [15] => 0 [16] => 0 [17] => 0 [18] => 73000 [19] => 77750 [20] => 81750 [21] => 0 [22] => 0 [23] => 0 [24] => 73000 [25] => 77750 [26] => 81750 [27] => 92350 [28] => 0 [29] => 0 [30] => 0 [31] => 73000 [32] => 77750 [33] => 81750 [34] => 92350 [35] => 106350 [36] => 0 [37] => 0 [38] => 0 [39] => 73000 [40] => 77750 [41] => 81750 [42] => 92350 [43] => 106350 [44] => 107050 [45] => 0 [46] => 0 [47] => 0 [48] => 73000 [49] => 77750 [50] => 81750 [51] => 92350 [52] => 106350 [53] => 107050 [54] => 112400 [55] => 0 [56] => 0 [57] => 0 [58] => 73000 [59] => 77750 [60] => 81750 [61] => 92350 [62] => 106350 [63] => 107050 ...............................................................[226] => 135250 [227] => 135250 [228] => 135900 [229] => 153500 [230] => 203900 )

 

can't i just get the last element(or result) from the array. (in the above quote, i want to get 203900 only, not that huge array..)?

Link to comment
Share on other sites

ok! now i got the solution. i used

end($total)

to find the last element of the array. and now my complete problem regarding stock(inventory) valuation is now solved. now i can use LIFO method either to calculate stock value along with FIFO.

 

thank u for ur precious time and support to help me solve this.

 

moreover i'll seek ur precious feedback and suggestions after i complete this project.

 

thank u again and again and again....

Link to comment
Share on other sites

  • 6 years later...
On 6/24/2014 at 8:45 AM, funbinod said:

and one thing more--

i removed all conditions relating 'remain' (columns, where clause) and i got the same result. i think i dont need this extra remain column. here is the code i changed--


<?phprequire_once('functions.php');if (!$connect){    $error = mysqli_connect_error();    $errno = mysqli_connect_errno();    echo "$errno: $errorn";    exit();}$sid = 1;  // this is the stock identifier$cqty = 5; // this is the qty sold$totqty = 0;$totamt = 0;$sql = "select qty, amt from fifo where sid=? order by date desc";$stmt = mysqli_prepare($connect, $sql);if (mysqli_stmt_bind_param($stmt, 'i', $sid)){	mysqli_stmt_execute($stmt) or die("Error: " . mysqli_error($connect));	$result = mysqli_stmt_get_result($stmt);	while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {		if ( !is_null($row['qty']) ){			if ($row['qty']>0 && $row['qty']+$totqty > $cqty){				$diff = $cqty - $totqty;				$totqty = $cqty;				$totamt += $diff*$row['amt']/$row['qty'];			// now you must record the remain count = $row->remain-$diff			} else {				$totqty += $row['qty'];				$totamt += $row['qty']*$row['amt']/$row['qty'];			// now you must record the remain=0			}		} else if ($row['qty']+$totqty > $cqty){			$diff = $cqty-$totqty;			$totqty = $cqty;			$totamt += $diff*$row['amt']/$row['qty'];		// now you must record the remain count = $row->qty-$diff		} else {			$totqty += $row['qty'];			$totamt += $row['amt'];		// now you must record the remain=0		}	    echo "qty={$row['qty']} amt={$row['amt']} cqty={$cqty} totqty={$totqty} totamt={$totamt} <br/>";	}	if ($cqty != $totqty) {		echo "error: recorded totqty={$totqty} purchased is insufficient to match cqty={$cqty}";	} else { echo $totamt; }} else {	echo 'error: could not bind';}mysqli_stmt_close($stmt);mysqli_close($connect);?>

it returned the same

 

and after this i'll need another guidance about summing all the $totamt for all the $sid from one category

I am no understanding where this functions.php came from what it actually doing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...