4 require_once 'Pman/Roo.php';
6 class Pman_Xtuple_Pricing extends Pman_Roo
10 * get .. same as roo...
17 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
19 //DB_DataObject::DebugLevel(1);
20 require_once 'File/Convert.php';
21 $fc = new File_Convert('/tmp/pricelist2012-07-20.xls', 'application/vnd.ms-excel');
22 //var_Dump($img->getStoreName());
23 $csv = $fc->convert('text/csv');
24 $this->importCsv($csv);
31 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
34 $img = DB_DataObject::Factory('images');
37 'ontable' => 'ipshead'
39 $img->onUpload(false);
41 require_once 'File/Convert.php';
42 $fc = new File_Convert($img->getStoreName(), $img->mimetype );
43 //var_Dump($img->getStoreName());
44 $csv = $fc->convert('text/csv');
46 //var_dump($csv);exit;
47 $this->importCsv($csv);
49 function importCsv($csv)
51 ini_set("auto_detect_line_endings", true);
53 $fh = fopen($csv, 'r');
55 $bom = "\xEF\xBB\xBF";
56 for ($i = 0; $i< 3;$i++) {
57 if ($bom[$i] != fgetc($fh)) {
64 // we need to break this into cols..
66 $names = fgetcsv($fh);
72 foreach($names as $i=>$n) {
73 if (!strlen(trim($n))) { // skip the empty columsn
90 if (!strlen(trim($names[1])) && $curr[1] == 'item_number') {
96 while (false !== ($row = fgetcsv($fh))) {
97 $sku = $row[$skucol]; // if first column is brand..
101 for ($i = $skucol+1; $i < count($row); $i++) {
102 $plist[$i]['prices'][$sku] = $row[$i];
107 // grab all the sku's... nice and emmeor
109 //print_R($plist);exit;
111 $it = DB_DataObject::Factory('item');
112 $imap = $it->fetchAll('item_number','item_id');
114 foreach($allsku as $sku => $n) {
115 if (empty($imap[$sku])) {
116 $this->jerr("invalid sku in upload:" . $sku);
121 foreach($plist as $nn => $data) {
122 $ih = DB_DataObject::Factory('ipshead');
123 $ih->selectAdd('(SELECT curr_name FROM curr_symbol where curr_id = ipshead_curr_id LIMIT 1) AS ipshead_curr');
124 $ih->ipshead_name = $data['name'];
126 if (!$ih->find(true)) {
127 $this->jerr('unknown pricelist column('. $nn .')'. @$data['name'] );
130 if ($ih->ipshead_curr != $data['curr']) {
131 // var_Dump($data['curr']);
132 $this->jerr("currency on pricelist {$data['name']} can not be changed from {$ih->ipshead_curr} to {$data['curr']}");
134 $plist[$nn]['ipshead'] = $ih;
137 $ret = array('updated'=>0, 'inserted'=>0,'deleted'=>0);
138 foreach($plist as $nn => $data) {
139 $res = $data['ipshead']->updatePrices($data['prices'],$imap);
140 $ret['deleted'] += $res['deleted'];
141 $ret['inserted'] += $res['inserted'];
142 $ret['updated'] += $res['updated'];