3 require_once 'Pman/Roo.php';
5 class Pman_Xtuple_Import_AUPostAccounts extends Pman_Roo
9 if (HTML_FlexyFramework::get()->cli) {
12 return parent::getAuth();
17 $this->transObj = DB_DataObject::Factory('custinfo');
19 $this->transObj->query('BEGIN');
21 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
23 $img = DB_DataObject::Factory('images');
26 'ontable' => 'ipshead'
28 $img->onUpload(false);
30 require_once 'File/Convert.php';
31 $fc = new File_Convert($img->getStoreName(), $img->mimetype );
32 $csv = $fc->convert('text/csv');
33 $this->importCsv($csv);
36 function importCsv($csv)
38 ini_set("auto_detect_line_endings", true);
40 $fh = fopen($csv, 'r');
42 $this->jerr("invalid file");
45 $req = array('CUSTOMER', 'ACCOUNT NO.');
50 while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) {
55 $cols[] = strtoupper(trim($k));
62 if (!in_array($r,$cols)) {
69 foreach($cols as $i=>$k) {
76 $this->jerr("could not find a row with " . implode(' / ', $req));
82 foreach ($rows as $row){
83 if(empty($row['CUSTOMER']) || empty($row['ACCOUNT NO.'])){
86 $custinfo = DB_DataObject::factory('custinfo');
87 if(!$custinfo->get('cust_name',$row['CUSTOMER'])){
88 $missing[] = $row['CUSTOMER'];
92 $ca = DB_DAtaObject::factory('charass');
95 'C',{$custinfo->pid()},
96 'AU-POST-ACCNO', '{$row['ACCOUNT NO.']}'
101 $this->jok('data imported successfully! <br/> Missing : <br/>' . implode("<br/>", $missing));