6 * Idea is to test the walking through of a sequence
7 * to see if we can work out a method of ordering the calculations.
13 require_once 'ProcessBase.php';
15 class Pman_Xtuple_Fifo_ProcessValuesWalk extends Pman_Xtuple_Fifo_ProcessBase
19 static $cli_desc = "Fill in Fifo dollar values.";
21 static $permitError = false;
23 var $loc_only = false;//187; //false;
28 $ff = HTML_FlexyFramework::get();
30 die("run form cli only");
39 // set up the failure code..
40 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
42 // we have to have a pointer to work out where we left off..
43 // this process can go by invdetail_id ASC..
57 function runSingle($itemsite )
59 // DB_DataObject::debugLevel(1);
61 $itemsite = (int)$itemsite;
65 $id = DB_DataObject::Factory('invdetail');
72 count(invdetail_id) as nres
77 invhist_itemsite_id = $itemsite
87 $id = DB_DataObject::Factory('invdetail');
94 invhist_itemsite_id = {$itemsite}
99 invhist_transtype = 'RP'
101 invhist_transtype = 'AD'
103 invhist_transtype = 'RS'
109 invhist_transdate ASC,
114 while ($id->fetch()) {
118 foreach($all as $id) {
119 $idr = DB_DataObject::Factory('invdetail');
120 $idr->query("SELECT invfifo_update_from_invdetail({$id->invdetail_id},true)");
122 $done[] = $id->invdetail_id;
123 // fill in all outgoing based on these reciepts..
126 $done = array_unique(array_merge($done, $this->processOut($id, $done)));
130 echo "DONE : ". count($done) . " out of $total \n";
137 // pass 1 - incomming stock only..
143 $id = array_shift($all);
144 switch($id->invhist_transtype) {
145 case 'AD': // adjustment
165 function processOut($idr, $done= array())
171 $id = DB_DataObject::Factory('invdetail');
183 invhist_itemsite_id = {$idr->invhist_itemsite_id}
189 invfifo_qty_before >= {$idr->invfifo_qty_before}
191 invfifo_qty_before <= {$idr->invfifo_qty_after}
193 invdetail_location_id = {$idr->invdetail_location_id}
197 invdetail_id NOT IN (". implode(',', $done) . ")
200 invhist_transdate ASC,
205 while($id->fetch()) {
207 $ret[] = $id->invdetail_id;
210 foreach($all as $id) {
211 $idr = DB_DataObject::Factory('invdetail');
212 $idr->query("SELECT invfifo_update_from_invdetail({$id->invdetail_id},true)");
213 $done[] = $id->invdetail_id;
215 // if it's a transfer, then flag the reverse as done as well..
216 if ($id->invhist_transtype == 'RL') {
217 $idr = DB_DataObject::Factory('invdetail');
218 $idr->query("SELECT *
219 FROM invdetailview WHERE invdetail_invhist_id = {$id->invhist_id} AND invdetail_id != {$id->invdetail_id}
222 $done[] = $idr->invdetail_id ;
223 $done = array_unique(array_merge($this->processOut($idr , $done)));