Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Fifo / FixVoids.php
1 <?php
2
3 /**
4  * fill in any fifo basic entries that have not been processed..
5  * -- does not fill in values.. - just qty's
6  *
7  */
8 require_once 'ProcessBase.php';
9  
10 class Pman_Xtuple_Fifo_FixVoids extends  Pman_Xtuple_Fifo_ProcessBase
11
12 {
13     static $cli_desc = "Fill some void records - do not normmally run...";
14    
15     static $permitError = false;
16     
17     function getAuth()
18     {
19         $ff = HTML_FlexyFramework::get();
20         if (!$ff->cli) {
21             die("run form cli only");
22         }
23         $this->cli = true;
24          
25     }
26     
27     function get()
28     {
29         // set up the failure code..
30         
31         die("not needed any more -- done on HK?? - needs testing on SG??");
32         
33         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
34         //DB_DataObject::debugLevel(1);
35         $id = DB_DataObject::Factory('invdetail');
36         $id->autoJoin();
37         $id->selectAdd();
38         $id->selectAdd( 'distinct(invhist_ordnumber) as ordernum');
39         $id->whereAdd(" invhist_transtype ='RS' AND invdetail_qty < 0 and invfifo_void =0 ");
40         $ons = $id->fetchAll('ordernum');
41         print_R($ons);
42         $tot = count($ons);
43         foreach($ons as $n => $oid) {
44             
45             
46             // find the last insue and reverse it..
47             $id = DB_DataObject::Factory('invdetail');
48             $id->autoJoin();
49
50             $id->whereAdd("invhist_ordnumber = '$oid'");
51             $id->whereAdd("invhist_transtype = 'SH' AND invdetail_qty < 0");
52             $id->orderBy('invdetail_id DESC');
53             $id->limit(1);
54             if (!$id->find(true)) {
55                 die("not found");
56             }
57             $id->reverse($this,array(
58                 '_force' => true
59             ));
60             // now find the one I've just create it and reverse it..
61             $id = DB_DataObject::Factory('invdetail');
62             $id->autoJoin();
63             
64             $id->whereAdd("invhist_ordnumber = '$oid'");
65             $id->whereAdd("invhist_transtype = 'RS' AND invdetail_qty > 0");
66             $id->orderBy('invdetail_id DESC');
67             $id->limit(1);
68             if (!$id->find(true)) {
69                 die("not found");
70             }
71             $id->reverse($this,array(
72                 '_force' => true
73             ));
74             echo "$n / $tot\n";
75             //print_R($id);exit;
76             //die("done");
77             
78             
79             
80         }
81         
82         die("done");
83         
84         
85          
86    
87     }
88      
89  
90 }