Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Fifo / ProcessOldLanded.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_ProcessOldLanded extends Pman_Xtuple_Fifo_ProcessBase
11 {
12      static $cli_desc = "Move old landed costs to new system.";
13    
14     static $permitError = false;
15     
16    
17     function get()
18     {
19         // set up the failure code..
20         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
21         
22         // old landed costs where stored in
23         // a) JE in Cost of freight
24         // NE-JE-IR-LANDEDCOST-XXXX-XXXX-IR11216
25         
26         //
27        //DB_DataObject::DebugLevel(1);
28         
29         $curr = DB_DataObject::Factory('curr_symbol')->base();
30         
31         //
32           $accnt = DB_DataObject::Factory('accnt');
33             // ??? 
34         $accnt->whereAdd("accnt_descrip like '%Cost of Freight%'");
35         $ids = $accnt->fetchAll('accnt_id');
36         $gl = DB_DataObject::Factory('gltrans');
37         $gl->whereAdd("gltrans_docnumber LIKE 'NS-JE-IR-LANDCOST%'");
38         $all = $gl->fetchAll();
39         $bad = array();
40         foreach($all as $gl) {
41             // try and find the item reciept.
42             //print_R($gl);
43             $m = array();
44             //var_dump($gl->gltrans_notes);
45             preg_match('/Landed cost for (.*)$/', $gl->gltrans_notes, $m);
46             //print_R($m);exit;
47             $ir = $m[1];
48             if (empty($ir)) {
49                 echo("NOT FOUND");
50                 print_R($gl);exit;
51             }
52             echo "$ir\n";
53             $rg = DB_DataObject::Factory('recvgrp');
54             if (!$rg->get('recvgrp_number', $ir)) {
55                 $bad[] = $ir;
56                 //print_R($gl);
57                 //die("recgrp not found");;
58                 continue;
59             }
60             // do we have a record of it..
61             $rgl = DB_DataObject::Factory('recvgrpland');
62             if ($rgl->get('recvgrpland_glseries' , $gl->gltrans_sequence)) {
63                 continue;
64             }
65             
66             
67             
68             $rgl = DB_DataObject::Factory('recvgrpland');
69             $rgl->setFrom(array(
70                 'recvgrpland_glseries' => $gl->gltrans_sequence,
71                 
72                 //'recvgrpland_vohead_id' => null
73                 'recvgrpland_recvgrp_id' => $rg->pid(),
74                 'recvgrpland_date' => $gl->gltrans_date,
75                 'recvgrpland_cost' => abs($gl->gltrans_amount),
76                 'recvgrpland_curr_id' => $curr->pid(),
77
78                 
79             ));
80             $rgl->insert();
81             
82             
83             
84             
85         }
86         print_R($bad);
87         die("DONE");
88         
89          
90    
91     }
92      
93 }