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_FillValuesWalk2 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);
63 $itemsite = (int)$itemsite;
67 $id = DB_DataObject::Factory('invdetail');
72 count(invdetail_id) as nres
77 invhist_itemsite_id = $itemsite
90 $id = DB_DataObject::Factory('invdetail');
97 invhist_itemsite_id = {$itemsite}
102 invhist_transtype = 'RP'
104 invhist_transtype = 'AD'
106 invhist_transtype = 'RS'
112 invhist_transdate ASC,
117 while ($id->fetch()) {
123 foreach($all as $id) {
124 $idr = DB_DataObject::Factory('invdetail');
125 $idr->query("SELECT invfifo_update_from_invdetail({$id->invdetail_id},true)");
128 // fill in all outgoing based on these reciepts..
130 $this->regBuy( $id->invdetail_id, $id->invdetail_location_id, $id->invfifo_qty_before, $id->invfifo_qty_after, 'S');
135 $before = count($this->done);
136 foreach($this->locs as $loc=>$ar) {
138 $this->processOut($loc, $itemsite);
141 if (count($this->done) == $before) {
144 // process remaining locs...
146 echo "DONE : ". count($this->done) . " out of $total \n";
155 function processOut($loc, $itemsite)
158 if (!isset($this->locs[$loc]) || $this->locs[$loc][0] > 0) {
159 return; // no record or can not start..
163 $end = $this->locs[$loc][1];
165 $id = DB_DataObject::Factory('invdetail');
168 for($i = 0; $i < count($this->locs[$loc]); $i+=2) {
172 (invfifo_qty_before >= {$this->locs[$loc][$i]} AND invfifo_qty_after <= {$this->locs[$loc][$i+1]})
184 invhist_itemsite_id = {$itemsite}
190 (". implode(' OR ', $q) . ")
192 invdetail_location_id = $loc
194 invdetail_id NOT IN (". implode(',', $this->done) . ")
197 invhist_transdate ASC,
202 while($id->fetch()) {
205 $ret[] = $id->invdetail_id;
209 foreach($all as $id) {
210 //var_dump($id->invdetail_id);
211 if (in_array($id->invdetail_id, $this->done)) {
216 $idr = DB_DataObject::Factory('invdetail');
217 $idr->query("SELECT invfifo_update_from_invdetail({$id->invdetail_id},true)");
220 // if it's a transfer, then flag the reverse as done as well..
221 if ($id->invhist_transtype == 'RL') {
222 $idr = DB_DataObject::Factory('invdetail');
223 $idr->query("SELECT *
224 FROM invdetailview WHERE invdetail_invhist_id = {$id->invhist_id} AND invdetail_id != {$id->invdetail_id}
227 $this->regBuy( $idr->invdetail_id, $idr->invdetail_location_id, $idr->invfifo_qty_before, $idr->invfifo_qty_after, 'R');
230 $invdetail_id = $idr->invdetail_id;
231 $out_loc = $idr->invdetail_location_id;
233 $idr = DB_DataObject::Factory('invdetail');
234 $idr->query("SELECT invfifo_update_from_invdetail({$invdetail_id},true)");
249 var $done = array( 0 );
251 function regBuy($invdetail_id, $loc, $start, $end, $type) {
253 if (in_array($invdetail_id, $this->done)) {
256 $this->done[] = $invdetail_id;
258 echo "$loc S:$start, $end : $type\n";
259 if (!isset($this->locs[$loc])) {
260 $this->locs[$loc] = array($start, $end);
264 // replace the last line..
265 if (count($this->locs[$loc]) == 2 && $this->locs[$loc][1] == $start) {
266 $this->locs[$loc][1] = $end;
267 print_r($this->locs);
270 // got an array, work out how to maniupulate it..
272 for ($i = 0; $i < count($this->locs[$loc]); $i +=2) {
273 $ss = $this->locs[$loc][$i];
274 $ee = $this->locs[$loc][$i+1];
275 echo "CHECK $ee == $start?";
279 $this->locs[$loc][$i+1] = $end;
286 $this->locs[$loc][] = $start;
287 $this->locs[$loc][] = $end;
290 sort($this->locs[$loc]);
293 for ($i = 0; $i < count($this->locs[$loc]); $i+=2) {
294 $ss = $this->locs[$loc][$i];
295 $ee = $this->locs[$loc][$i+1];
301 if ($ss == $nl[count($nl)-1]) {
302 $nl[count($nl)-1] = $ee;
310 // normalize the list..
311 $this->locs[$loc] = $nl;
313 print_r($this->locs);