cli) { die("run form cli only"); } $this->cli = true; } function get() { // set up the failure code.. die("not needed any more -- done on HK?? - needs testing on SG??"); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError')); //DB_DataObject::debugLevel(1); $id = DB_DataObject::Factory('invdetail'); $id->autoJoin(); $id->selectAdd(); $id->selectAdd( 'distinct(invhist_ordnumber) as ordernum'); $id->whereAdd(" invhist_transtype ='RS' AND invdetail_qty < 0 and invfifo_void =0 "); $ons = $id->fetchAll('ordernum'); print_R($ons); $tot = count($ons); foreach($ons as $n => $oid) { // find the last insue and reverse it.. $id = DB_DataObject::Factory('invdetail'); $id->autoJoin(); $id->whereAdd("invhist_ordnumber = '$oid'"); $id->whereAdd("invhist_transtype = 'SH' AND invdetail_qty < 0"); $id->orderBy('invdetail_id DESC'); $id->limit(1); if (!$id->find(true)) { die("not found"); } $id->reverse($this,array( '_force' => true )); // now find the one I've just create it and reverse it.. $id = DB_DataObject::Factory('invdetail'); $id->autoJoin(); $id->whereAdd("invhist_ordnumber = '$oid'"); $id->whereAdd("invhist_transtype = 'RS' AND invdetail_qty > 0"); $id->orderBy('invdetail_id DESC'); $id->limit(1); if (!$id->find(true)) { die("not found"); } $id->reverse($this,array( '_force' => true )); echo "$n / $tot\n"; //print_R($id);exit; //die("done"); } die("done"); } }