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     function getAuth()
7     {
8         if (HTML_FlexyFramework::get()->cli) {
9             return false;
10         }
11         return parent::getAuth();
12     }
13    
14     function get()
15     {
16         $this->transObj = DB_DataObject::Factory('cohead');
17         
18         $this->transObj->query('BEGIN');
19         
20         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
21         
22         $cohead = DB_DataObject::factory('cohead');
23         $cohead->whereAdd("
24             cohead_status != 'X'
25             AND
26             cohead_id = 14462
27         ");
28         $cohead->orderBy('cohead_id DESC');
29         $cohead->find();
30         
31         while ($cohead->fetch()){
32             $co = clone ($cohead);
33             
34             $cobmiscs = $co->cobmiscs();
35             print_r($cobmiscs);exit;
36             foreach ($cobmiscs as $cobmisc){
37                 $invchead = $cobmisc->invchead();
38                 $aropen = $invchead->aropen();
39                 
40                 if(!empty($aropen->aropen_id)){
41                     $cashrcptitem = DB_DataObject::factory('cashrcptitem');
42                     $cashrcptitem->cashrcptitem_aropen_id = $aropen->pid();
43                     
44                     if($cashrcptitem->count()){
45                         $cashrcpt = DB_DataObject::factory('cashrcpt');
46                         $cashrcpt->whereAddIn('cashrcpt_id', $cashrcptitem->fetchAll('cashrcptitem_cashrcpt_id'), 'int');
47                         $cashrcpt->cashrcpt_posted = TRUE;
48                         $cashrcpt->cashrcpt_void = FALSE;
49                         foreach($cashrcpt->fetchAll() as $cashr){
50                             $cashr->void($this);
51                             $this->addEvent("VOIDED", $cashr);
52                         }
53                     }
54                 }
55                 
56                 
57                 
58             }
59             
60             
61         }
62         $this->jerr('ROLL BACK');
63         exit;
64     }
65     
66         
67 }