/**
  * @role update
  */
 public function save()
 {
     $taxes = Tax::getAllTaxes();
     $classes = TaxClass::getAllClasses();
     if (($zoneID = (int) $this->request->get('id')) <= 0) {
         $taxRates = TaxRate::getRecordSetByDeliveryZone(null);
         $deliveryZone = DeliveryZone::getDefaultZoneInstance();
     } else {
         $deliveryZone = DeliveryZone::getInstanceByID($zoneID, true);
         $taxRates = $deliveryZone->getTaxRates();
     }
     ActiveRecord::beginTransaction();
     // delete all rates
     foreach ($taxRates as $rate) {
         $rate->delete();
     }
     foreach ($taxes as $tax) {
         $this->saveRate($deliveryZone, $tax, null);
         foreach ($classes as $class) {
             $this->saveRate($deliveryZone, $tax, $class);
         }
     }
     ActiveRecord::commit();
     return new JSONResponse(false, 'success', $this->translate('_tax_rates_have_been_successfully_saved'));
 }
Exemple #2
0
 /**
  * Get a list of existing taxes
  *
  * @param boolean $includeDisabled Include disabled taxes in this list
  * @param TaxRate $doNotBelongToRate Don not belong to specified rate
  * @param boolean $loadReferencedRecords Load referenced records
  *
  * @return ARSet
  */
 public static function getTaxes(DeliveryZone $notUsedInThisZone = null, $loadReferencedRecords = false)
 {
     $filter = new ARSelectFilter();
     $rates = TaxRate::getRecordSetByDeliveryZone($notUsedInThisZone);
     if ($rates->getTotalRecordCount() > 0) {
         $zoneRatesIDs = array();
         foreach ($rates as $rate) {
             $taxIDs[] = $rate->tax->get()->getID();
         }
         $notInCond = new NotINCond(new ARFieldHandle(__CLASS__, "ID"), $taxIDs);
         $filter->setCondition($notInCond);
     }
     return self::getRecordSet($filter, $loadReferencedRecords);
 }
Exemple #3
0
 private function appendTaxRates($response, $taxID = null)
 {
     $this->loadLanguageFile('backend/DeliveryZone');
     // 'default zone'
     $zones = array();
     //default
     $taxRates = TaxRate::getRecordSetByDeliveryZone(null);
     $zones[] = array('ID' => -1, 'name' => $this->translate('_default_zone'), 'taxRates' => $taxRates ? $taxRates->toArray() : null);
     // custom
     foreach (DeliveryZone::getTaxZones() as $deliveryZone) {
         $zone = $deliveryZone->toArray();
         $taxRates = $deliveryZone->getTaxRates();
         $zones[] = array('ID' => $zone['ID'], 'name' => $zone['name'], 'taxRates' => $taxRates ? $taxRates->toArray() : null);
     }
     // reorder tax rates in structure $zone['taxRates'][<delivery zone id>][<tax class id>] = ..
     //                                (for default delivery zone and tax class id use -1)
     foreach ($zones as &$zone) {
         $filtered = array();
         if (is_array($zone['taxRates'])) {
             foreach ($zone['taxRates'] as $taxRate) {
                 if ($taxRate['Tax']['ID'] == $taxID) {
                     $filtered[$zone['ID']][array_key_exists('taxClassID', $taxRate) ? $taxRate['taxClassID'] : -1] = $taxRate;
                 }
             }
         }
         $zone['taxRates'] = $filtered;
         //pp($zone['taxRates']);
     }
     $classes = TaxClass::getAllClasses()->toArray();
     $response->set('zones', $zones);
     $response->set('classes', $classes);
     return $response;
 }
Exemple #4
0
 /**
  *
  *	@return ARSet
  */
 public function getTaxRates($includeDisabled = true, $loadReferencedRecords = array('Tax'))
 {
     if (!$this->taxRates) {
         $this->taxRates = TaxRate::getRecordSetByDeliveryZone($this, $loadReferencedRecords);
     }
     return $this->taxRates;
 }