Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Import / Transfer.php
1 <?php
2
3 require_once 'Pman/Core/ExcelToJson.php';
4
5 class Pman_Xtuple_Import_Transfer extends Pman_Core_ExcelToJson
6 {
7     function getAuth()
8     {
9         if (HTML_FlexyFramework::get()->cli) {
10             return true;
11         }
12         return parent::getAuth();
13     }
14     
15     function post()
16     {
17         parent::post();
18     }
19     
20     function importCsv($csv)
21     {
22         $ret = parent::importCsv($csv);
23        
24         $data = $ret['data'];
25         
26         $ret['data'] =$ret['extra'];
27         
28         // can not handle extra data.. .as image calls back with result.data...
29         
30         
31         $lc = DB_DataObject::factory('location');
32         if(!empty($ret['extra']['From']) && $lc->get('location_name', $ret['extra']['From'])){
33             $ret['data']['invhist_transfer_from'] = $lc->pid();
34             $ret['data']['invhist_transfer_from_location_name'] = $lc->location_name;
35         }
36         
37         
38         $lt = DB_DataObject::factory('location');
39         if(!empty($ret['extra']['To']) && $lt->get('location_name', $ret['extra']['To'])){
40             $ret['data']['invhist_transfer_to'] = $lt->pid();
41             $ret['data']['invhist_transfer_to_location_name'] = $lt->location_name;
42         }
43         
44         $ourdb = substr($lt->database(), -2);
45         
46         $ltc = ($lt->location_id  && $lt->location_cust_id ) ? $lt->customer()->char('INTERNALCOMPANY') : '';
47         
48         $ret['data']['isInter'] = 0;
49         if(strlen($ltc) && $ourdb != $ltc){
50             $ret['data']['isInter'] = 1;
51         }
52         
53         $errmsg = array();
54         
55         foreach ($data as $r){
56             $itemsite = DB_DataObject::factory('itemsite');
57             $itemsite->autoJoin();
58             $itemsite->whereAdd("UPPER(join_itemsite_item_id_item_id.item_number) = UPPER('{$itemsite->escape(trim($r['ITEM CODE']))}')");
59             if(!$itemsite->find(true)){
60                 $errmsg[] = $r['ITEM CODE'];
61                 continue;
62             }
63             $r['UNIT PRICE']  = isset($r['UNIT PRICE'] ) ? $r['UNIT PRICE']  : '';
64             $ret['data']['items'][] = array(
65                 'itemsite_item_id' => $itemsite->itemsite_item_id,
66                 'itemsite_id' => $itemsite->pid(),
67                 'itemsite_item_id_item_number' => trim($r['ITEM CODE']),
68                 'itemsite_item_id_item_descrip1' => !empty($r['DESCRIPTION']) ? $r['DESCRIPTION'] : $itemsite->itemsite_item_id_item_descrip1,
69                 'itemsite_qty' => $r['QUANTITY'],
70                 'unit_price' => (strlen($ltc) && $ourdb != $ltc) ? $r['UNIT PRICE'] : ''
71             );
72         }
73         
74         if(count($errmsg)){
75             $this->jerr("MISSING \n" . implode("\n", $errmsg));
76         }
77         
78         return $ret;
79         
80     }
81     
82 }