Ejemplo n.º 1
0
 /**     
  * @param   request data  tax rows information (if 'id'=0 this is a new row)
  * @see plugins/taxes/js/edit.js
  * @return 	json    json array information: success or failure
  */
 function updateJsonAction()
 {
     $dataJson = $this->_getParam('data', '[]');
     $data = Zend_Json::decode($dataJson);
     $iso = $this->_getParam('iso', RM_Environment::getInstance()->getLocale());
     $unitTaxesModel = new RM_UnitTaxes();
     $model = new RM_Taxes();
     foreach ($data as $row) {
         if (isset($row['name'])) {
             $row[$iso] = $row['name'];
             unset($row['name']);
         }
         $unitIDs = explode(',', $row['units']);
         unset($row['units']);
         if ($row['id'] == 0) {
             unset($row['id']);
             $taxID = $model->insert($row);
             $tax = $model->find($taxID)->current();
         } else {
             $tax = $model->find($row['id'])->current();
             if ($tax == null) {
                 continue;
             }
             foreach ($row as $key => $value) {
                 $tax->{$key} = $value;
             }
             $tax->save();
         }
         $unitTaxesModel->insertRows($tax, $unitIDs);
     }
     return array('data' => array('success' => true));
 }
Ejemplo n.º 2
0
 function copyInformation(RM_Unit_Row $original, RM_Unit_Row $copy)
 {
     $unitTaxesModel = new RM_UnitTaxes();
     $unitTaxes = $unitTaxesModel->getByUnit($original);
     foreach ($unitTaxes as $unitTax) {
         $copyUnitTaxData = $unitTax->toArray();
         unset($copyUnitTaxData['id']);
         $copyUnitTaxData['unit_id'] = $copy->id;
         $unitTaxesModel->insert($copyUnitTaxData);
     }
 }
Ejemplo n.º 3
0
 /**
  * Returns the column/value data as an array and parse all assigned units
  * in csv format in 'units' field.
  *
  * @return array
  */
 public function toArray()
 {
     $dataRow = parent::toArray();
     if ($this->global == 1) {
         $dataRow['units'] = array(0);
     } else {
         $unitTaxesModel = new RM_UnitTaxes();
         $unitIDs = array();
         $unitTaxes = $unitTaxesModel->getByTax($this);
         foreach ($unitTaxes as $unitTax) {
             $unitIDs[] = $unitTax->unit_id;
         }
         $dataRow['units'] = implode(',', $unitIDs);
     }
     return $dataRow;
 }