Esempio 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;
 }
Esempio 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();
             }
         }
     }
 }
Esempio n. 3
0
 private function ajax_save_dept()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $id = FormLib::get_form_value('did', 0);
     $name = FormLib::get_form_value('name', '');
     $tax = FormLib::get_form_value('tax', 0);
     $fs = FormLib::get_form_value('fs', 0);
     $disc = FormLib::get_form_value('disc', 1);
     $min = FormLib::get_form_value('min', 0.01);
     $max = FormLib::get_form_value('max', 50.0);
     $margin = FormLib::get_form_value('margin', 0);
     $margin = (double) $margin / 100.0;
     $pcode = FormLib::get_form_value('pcode', $id);
     if (!is_numeric($pcode)) {
         $pcode = (int) $id;
     }
     $new = FormLib::get_form_value('new', 0);
     $model = new DepartmentsModel($dbc);
     $model->dept_no($id);
     $model->dept_name($name);
     $model->dept_tax($tax);
     $model->dept_fs($fs);
     $model->dept_discount($disc);
     $model->dept_minimum($min);
     $model->dept_limit($max);
     $model->modified(date('Y-m-d H:i:s'));
     $model->margin($margin);
     $model->salesCode($pcode);
     if ($new == 1) {
         $model->modifiedby(1);
         $model->dept_see_id(0);
     }
     $saved = $model->save();
     if ($new == 1) {
         if ($saved === False) {
             echo 'Error: could not create department';
             return;
         }
         $superP = $dbc->prepare_statement('INSERT INTO superdepts (superID,dept_ID) VALUES (0,?)');
         $superR = $dbc->exec_statement($superP, array($id));
     } else {
         if ($saved === False) {
             echo 'Error: could not save changes';
             return;
         }
     }
     if ($dbc->tableExists('deptMargin')) {
         $chkM = $dbc->prepare_statement('SELECT dept_ID FROM deptMargin WHERE dept_ID=?');
         $mR = $dbc->exec_statement($chkM, array($id));
         if ($dbc->num_rows($mR) > 0) {
             $up = $dbc->prepare_statement('UPDATE deptMargin SET margin=? WHERE dept_ID=?');
             $dbc->exec_statement($up, array($margin, $id));
         } else {
             $ins = $dbc->prepare_statement('INSERT INTO deptMargin (dept_ID,margin) VALUES (?,?)');
             $dbc->exec_statement($ins, array($id, $margin));
         }
     }
     if ($dbc->tableExists('deptSalesCodes')) {
         $chkS = $dbc->prepare_statement('SELECT dept_ID FROM deptSalesCodes WHERE dept_ID=?');
         $rS = $dbc->exec_statement($chkS, array($id));
         if ($dbc->num_rows($rS) > 0) {
             $up = $dbc->prepare_statement('UPDATE deptSalesCodes SET salesCode=? WHERE dept_ID=?');
             $dbc->exec_statement($up, array($pcode, $id));
         } else {
             $ins = $dbc->prepare_statement('INSERT INTO deptSalesCodes (dept_ID,salesCode) VALUES (?,?)');
             $dbc->exec_statement($ins, array($id, $pcode));
         }
     }
     $json = array();
     $json['did'] = $id;
     $json['msg'] = 'Department ' . $id . ' - ' . $name . ' Saved';
     echo json_encode($json);
 }