Exemplo n.º 1
0
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $dn_index = $this->get_column_index('dept_no');
     $desc_index = $this->get_column_index('desc');
     $margin_index = $this->get_column_index('margin');
     $tax_index = $this->get_column_index('tax');
     $fs_index = $this->get_column_index('fs');
     // prepare statements
     $marP = $dbc->prepare_statement("INSERT INTO deptMargin (dept_ID,margin) VALUES (?,?)");
     $scP = $dbc->prepare_statement("INSERT INTO deptSalesCodes (dept_ID,salesCode) VALUES (?,?)");
     $model = new DepartmentsModel($dbc);
     foreach ($linedata as $line) {
         // get info from file and member-type default settings
         // if applicable
         $dept_no = $line[$dn_index];
         $desc = $line[$desc_index];
         $margin = $margin_index !== False ? $line[$margin_index] : 0;
         if ($margin > 1) {
             $margin /= 100.0;
         }
         $tax = $tax_index !== False ? $line[$tax_index] : 0;
         $fs = $fs_index !== False ? $line[$fs_index] : 0;
         if (!is_numeric($dept_no)) {
             continue;
         }
         // skip header/blank rows
         if (strlen($desc) > 30) {
             $desc = substr($desc, 0, 30);
         }
         $model->reset();
         $model->dept_no($dept_no);
         $model->dept_name($desc);
         $model->dept_tax($tax);
         $model->dept_fs($fs);
         $model->dept_limit(50);
         $model->dept_minimum(0.01);
         $model->dept_discount(1);
         $model->dept_see_id(0);
         $model->modified(date('Y-m-d H:i:s'));
         $model->modifiedby(1);
         $model->margin($margin);
         $model->salesCode($dept_no);
         $imported = $model->save();
         if ($imported) {
             $this->stats['imported']++;
         } else {
             $this->stats['errors'][] = 'Error imported department #' . $dept_no;
         }
         if ($dbc->tableExists('deptMargin')) {
             $insR = $dbc->exec_statement($marP, array($dept_no, $margin));
         }
         if ($dbc->tableExists('deptSalesCodes')) {
             $insR = $dbc->exec_statement($scP, array($dept_no, $dept_no));
         }
     }
     return true;
 }
Exemplo n.º 2
0
 protected function hookAddColumnsalesCode()
 {
     if ($this->connection->table_exists('deptSalesCodes')) {
         $dataR = $this->connection->query('SELECT dept_ID, salesCode FROM deptSalesCodes');
         $tempModel = new DepartmentsModel($this->connection);
         while ($dataW = $this->connection->fetch_row($dataR)) {
             $tempModel->reset();
             $tempModel->dept_no($dataW['dept_ID']);
             if ($tempModel->load()) {
                 $tempModel->salesCode($dataW['salesCode']);
                 $tempModel->save();
             }
         }
     }
 }