VoidSalesAndPurchaseOrders.php
[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             $this->log("Voiding Sales Order : {$cohead->cohead_number}");
49             
50             $cohead->clear($this);
51         }
52         
53         
54         $pohead = DB_DataObject::factory('pohead');
55         $pohead->find();
56         
57         while ($pohead->fetch()){
58             $po = clone ($pohead);
59             $po->clear($this);
60         }
61         
62         
63         $this->jerr('DONE');
64         exit;
65     }
66     
67     function log($str)
68     {
69         echo "$str \n";
70     }
71         
72 }