Fix #7123 - getting abra ready to test
[Pman.Xtuple] / VoidSalesAndPurchaseOrders.php
index 0e58309..244ca1f 100644 (file)
@@ -3,63 +3,76 @@ require_once 'Pman/Roo.php';
 
 class Pman_Xtuple_VoidSalesAndPurchaseOrders extends Pman_Roo
 {   
+    static $cli_desc = "Void ALL the Sales Orders / Vouchers / Purchase Orders - Make Sure you know what is going to do!!!";
+    
+    static $cli_opts = array(
+        'confirm' => array(
+            'desc' => 'Confirm',
+            'default' => '',
+            'short' => 'f',
+            'min' => 0,
+            'max' => 1,
+        )
+    );
+    
     function getAuth()
     {
         if (HTML_FlexyFramework::get()->cli) {
-            return false;
+            return true;
         }
-        return parent::getAuth();
+        
+        return false;
     }
    
-    function get()
+    function get($v = '', $opts)
     {
+        if(empty($opts['confirm']) || $opts['confirm'] !== 'I am sure to void all things'){
+            $this->jerr("If you know what is going to do, try -f 'I am sure to void all things'");
+        }
+        
+        $this->transObj = DB_DataObject::Factory('cohead');
+        
+        $this->transObj->query('BEGIN');
+        
+        PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
+        
+        DB_DataObject::factory('cohead')->lockTables();
+        
         $cohead = DB_DataObject::factory('cohead');
         $cohead->whereAdd("
             cohead_status != 'X'
         ");
-        $cohead->orderBy('cohead_id DESC');
         $cohead->find();
         
         while ($cohead->fetch()){
             $co = clone ($cohead);
             
-            $cobmiscs = $co->cobmiscs();
+            $this->log("Voiding Sales Order : {$co->cohead_number}");
             
-            foreach ($cobmiscs as $cobmisc){
-                $cobapply = DB_DataObject::factory('cobapply');
-                $cobapply->cobapply_cobmisc_id = $cobmisc->pid();
-                print_r($cobapply->count());exit;
-                if($cobapply->count()){
-                    foreach($cobapply->fetchAll() as $coba){
-                        
-                        $coba->delete();
-                        $coba->void($this);
-                        
-                        $checkitem = DB_DataObject::factory('checkitem');
-                        $checkitem->autoJoin();
-                        $checkitem->checkitem_aropen_id = $coba->cobapply_aropen_id;
-                        $checkitem->whereAdd("
-                            join_checkitem_checkhead_id_checkhead_id.checkhead_posted = TRUE
-                            AND
-                            join_checkitem_checkhead_id_checkhead_id.checkhead_void = FALSE
-                            AND
-                            join_checkitem_checkhead_id_checkhead_id.checkhead_deleted = FALSE
-
-                        ");
-                        
-                        foreach ($checkitem->fetchAll() as $checki){
-                            $checkhead = $checki->checkhead();
-                            $checkhead->voidPostedCheck($this);
-                        }
-                    }
-                }
-                
-                
-            }
+            $co->clear($this);
+        }
+        
+        
+        $pohead = DB_DataObject::factory('pohead');
+        $pohead->find();
+        
+        while ($pohead->fetch()){
+            $po = clone ($pohead);
             
+            $this->log("Voiding Purchase Order : {$po->pohead_number}");
             
+            $po->clear($this);
         }
+        
+        
+        $this->jok('DONE');
+        
+        exit;
     }
     
+    function log($str)
+    {
+        echo "$str \n";
+    }
         
 }
\ No newline at end of file