Fix #7123 - getting abra ready to test
[Pman.Xtuple] / VoidSalesAndPurchaseOrders.php
1 <?php
2 require_once 'Pman/Roo.php';
3
4 class Pman_Xtuple_VoidSalesAndPurchaseOrders extends Pman_Roo
5 {   
6     static $cli_desc = "Void ALL the Sales Orders / Vouchers / Purchase Orders - Make Sure you know what is going to do!!!";
7     
8     static $cli_opts = array(
9         'confirm' => array(
10             'desc' => 'Confirm',
11             'default' => '',
12             'short' => 'f',
13             'min' => 0,
14             'max' => 1,
15         )
16     );
17     
18     function getAuth()
19     {
20         if (HTML_FlexyFramework::get()->cli) {
21             return true;
22         }
23         
24         return false;
25     }
26    
27     function get($v = '', $opts)
28     {
29         if(empty($opts['confirm']) || $opts['confirm'] !== 'I am sure to void all things'){
30             $this->jerr("If you know what is going to do, try -f 'I am sure to void all things'");
31         }
32         
33         $this->transObj = DB_DataObject::Factory('cohead');
34         
35         $this->transObj->query('BEGIN');
36         
37         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
38         
39         DB_DataObject::factory('cohead')->lockTables();
40         
41         $cohead = DB_DataObject::factory('cohead');
42         $cohead->whereAdd("
43             cohead_status != 'X'
44         ");
45         $cohead->find();
46         
47         while ($cohead->fetch()){
48             $co = clone ($cohead);
49             
50             $this->log("Voiding Sales Order : {$co->cohead_number}");
51             
52             $co->clear($this);
53         }
54         
55         
56         $pohead = DB_DataObject::factory('pohead');
57         $pohead->find();
58         
59         while ($pohead->fetch()){
60             $po = clone ($pohead);
61             
62             $this->log("Voiding Purchase Order : {$po->pohead_number}");
63             
64             $po->clear($this);
65         }
66         
67         
68         $this->jok('DONE');
69         
70         exit;
71     }
72     
73     function log($str)
74     {
75         echo "$str \n";
76     }
77         
78 }