cli) { return true; } return parent::getAuth(); } function post() { $this->transObj = DB_DataObject::Factory('gltrans'); $this->transObj->query('BEGIN'); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError')); $img = DB_DataObject::Factory('images'); $img->setFrom(array( 'onid' => 0, 'ontable' => 'ipshead' )); $img->onUpload(false); require_once 'File/Convert.php'; $fc = new File_Convert($img->getStoreName(), $img->mimetype ); $csv = $fc->convert('text/csv'); $this->adjustBalances($csv); } function adjustBalances($csv) { ini_set("auto_detect_line_endings", true); $reference = $_REQUEST['reference']; $apply_date = $_REQUEST['apply_date']; $fh = fopen($csv, 'r'); if (!$fh) { $this->jerr("invalid file"); } $cols = false; $rows = array(); while(false !== ($n = fgetcsv($fh,10000, ',', '"'))) { if (!$cols) { $cols = array(); foreach($n as $k) { $cols[] = strtoupper(trim($k)); } if (!in_array('ADJUST',$cols)) { $this->jerr('Missing ADJUST value : ' . implode(' , ' , $cols)); } continue; } foreach($cols as $i=>$k) { $row[$k] = $n[$i]; } // ignore the accnt if the adjust is 0 if (empty($row['ADJUST']) || $row['ADJUST'] == 0) { continue; } $rows[] = $row; } fclose($fh); $gl = DB_DataObject::factory('gltrans'); $gl->query(" SELECT fetchGLSequence() AS glsequence "); $gl->fetch(); $seq = $gl->glsequence; // v_glsequence foreach ($rows as $i => $row){ if(empty($row['NAME'])){ continue; } $accnt = DB_DataObject::factory('accnt'); if(!$accnt->get('accnt_name', $row['NAME'])){ continue; } $gl = DB_DataObject::factory('gltrans'); $gl->query(" SELECT insertIntoGLSeries( $seq, 'G/L', 'JE', '{$gl->escape($reference)}', {$accnt->pid()}, {$row['ADJUST']}, '$apply_date'::date ) AS result "); $gl->fetch(); if ($gl->result < 1) { $this->jerr("insertIntoGLSeries INV ASS failed"); } } $gl = DB_DataObject::Factory('gltrans'); $gl->query("SELECT sum(glseries_amount) as result FROM glseries WHERE glseries_sequence = $seq "); $gl->fetch(); $sum = $gl->result; // the type here is string if(abs($sum) > 1.0){ $this->jerr('glseries amount is greater than 1.0'); } if($sum != 0){ $rounding = $sum * -1; $gl = DB_DataObject::factory('gltrans'); $gl->query(" SELECT insertIntoGLSeries( $seq, 'G/L', 'JE', '{$gl->escape($reference)}', fetchMetricValue('CurrencyGainLossAccount')::integer, {$rounding}, '$apply_date'::date ) AS result "); $gl->fetch(); if ($gl->result < 1) { $this->jerr("rounding insertIntoGLSeries failed"); } } $gl = DB_DataObject::Factory('gltrans'); $gl->query(" UPDATE glseries SET glseries_notes = '{$gl->escape($reference)}' WHERE glseries_sequence = $seq "); $gl = DB_DataObject::Factory('gltrans'); $gl->query(" SELECT postGLSeriesNoSumm( $seq, COALESCE(NULL,fetchJournalNumber('G/L')) ) AS result "); $gl->fetch(); if ($gl->result < 1) { $this->jerr("post GL seriese failed"); } $this->jok("DONE"); exit; } }