Esempio n. 1
0
 /**
  * Reads the vat datasets from database.
  * 
  * @access	public 
  * @return	ilShopVatsList
  *  
  */
 public function read()
 {
     $this->vat_list = array();
     $query = "SELECT * FROM payment_vats ";
     $query .= "WHERE 1 = 1 ";
     if (!in_array($this->getOrderColumn(), array('vat_title', 'vat_rate'))) {
         $this->setOrderColumn('vat_rate');
         $this->setOrderDirection('ASC');
     }
     $order_limit = " ORDER BY " . $this->getOrderColumn() . " " . strtoupper($this->getOrderDirection()) . " ";
     if ((int) $this->getListMax()) {
         $order_limit .= "LIMIT " . $this->getListStart() . ", " . $this->getListMax();
     }
     $res = $this->db->query($query . $order_limit);
     while ($row = $this->db->fetchObject($res)) {
         $oVAT = new ilShopVats();
         $oVAT->setId($row->vat_id);
         $oVAT->setTitle($row->vat_title);
         $oVAT->setRate($row->vat_rate);
         $this->vat_list[$oVAT->getId()] = $oVAT;
     }
     $res = $this->db->query(str_replace('*', 'COUNT(vat_id) AS num_vat_list', $query));
     while ($row = $this->db->fetchObject($res)) {
         $this->num_vat_list = $row->num_vat_list;
         break;
     }
     return $this;
 }
 public function saveVatObject()
 {
     $this->initVatForm('create');
     if (!$this->form->checkInput()) {
         $this->form->setValuesByPost();
         $this->tpl->setContent($this->form->getHtml());
         return true;
     }
     if (!ilShopUtils::_checkVATRate($this->form->getInput('vat_rate'))) {
         $this->form->getItemByPostVar('vat_rate')->setAlert($this->lng->txt('payment_vat_input_invalid'));
         $this->form->setValuesByPost();
         $this->tpl->setContent($this->form->getHtml());
         return true;
     }
     try {
         $oVAT = new ilShopVats();
         $oVAT->setTitle($this->form->getInput('vat_title'));
         $oVAT->setRate((double) str_replace(',', '.', $this->form->getInput('vat_rate')));
         $oVAT->save();
     } catch (ilShopException $e) {
         ilUtil::sendInfo($e->getMessage());
         $this->form->setValuesByPost();
         $this->tpl->setContent($this->form->getHtml());
         return true;
     }
     ilUtil::sendInfo($this->lng->txt('saved'));
     $this->vatsObject();
     return true;
 }