Exemplo n.º 1
0
 public function report_description_content()
 {
     try {
         $dept = new VendorDepartmentsModel($this->connection);
         $dept->vendorID($this->form->id);
         $dept->deptID($this->form->category);
         if ($dept->load()) {
             return array('Category: ' . $dept->name(), 'Margin Target: ' . sprintf('%.2f%%', $dept->margin() * 100));
         } else {
             return array();
         }
     } catch (Exception $ex) {
         return array();
     }
 }
Exemplo n.º 2
0
 function ajax_callbacks($action)
 {
     global $FANNIE_OP_DB;
     $json = array('error' => 0);
     switch ($action) {
         case 'createCat':
             $json = $this->createVendorDepartment(FormLib::get_form_value('vid'), FormLib::get_form_value('deptID'), FormLib::get_form_value('name'));
             echo json_encode($json);
             break;
         case 'deleteCat':
             $dbc = FannieDB::get($FANNIE_OP_DB);
             $q = $dbc->prepare_statement("DELETE FROM vendorDepartments\n                WHERE vendorID=? AND deptID=?");
             $gone = $dbc->exec_statement($q, array(FormLib::get_form_value('vid'), FormLib::get_form_value('deptID')));
             if (!$gone) {
                 $json['error'] = 'Error deleting #' + FormLib::get('deptID');
             }
             echo json_encode($json);
             break;
         case 'updateCat':
             $dbc = FannieDB::get($FANNIE_OP_DB);
             $dept = new VendorDepartmentsModel($dbc);
             $dept->vendorID(FormLib::get('vid'));
             $dept->deptID(FormLib::get('deptID'));
             $dept->name(FormLib::get('name'));
             $dept->margin(trim(FormLib::get('margin', 0), '%') / 100.0);
             $dept->posDeptID(FormLib::get('pos'));
             $saved = $dept->save();
             if ($saved === false) {
                 $json['error'] = 'Error saving #' . FormLib::get('deptID');
             }
             echo json_encode($json);
             break;
         default:
             echo 'bad request';
             break;
     }
 }
Exemplo n.º 3
0
 function process_file($linedata)
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     if (!isset($_SESSION['vid'])) {
         $this->error_details = 'Missing vendor setting';
         return False;
     }
     $VENDOR_ID = $_SESSION['vid'];
     $p = $dbc->prepare_statement("SELECT vendorID,vendorName FROM vendors WHERE vendorID=?");
     $idR = $dbc->exec_statement($p, array($VENDOR_ID));
     if ($dbc->num_rows($idR) == 0) {
         $this->error_details = 'Cannot find vendor';
         return False;
     }
     $idW = $dbc->fetch_row($idR);
     $vendorName = $idW['vendorName'];
     $num = $this->get_column_index('deptID');
     $name = $this->get_column_index('name');
     $margin = $this->get_column_index('margin');
     $model = new VendorDepartmentsModel($dbc);
     foreach ($linedata as $data) {
         if (!is_array($data)) {
             continue;
         }
         if (!isset($data[$num])) {
             continue;
         }
         if (!is_numeric($data[$num])) {
             continue;
         }
         // grab data from appropriate columns
         $model->vendorID($VENDOR_ID);
         $model->deptID($data[$num]);
         $model->name($name === false ? '' : $data[$name]);
         $model->margin($margin === false ? 0 : $data[$margin]);
         $model->save();
     }
     return true;
 }