Beispiel #1
0
 /**
  * Dynamically access route parameters.
  *
  * @param  string  $key
  * @return mixed
  */
 public function __get($key)
 {
     // total property
     if ($key === 'price' || $key === 'price_111') {
         if (config('market.taxProductDisplayPrices') == TaxRuleLibrary::PRICE_WITHOUT_TAX) {
             return $this->subtotal_111;
         } elseif (config('market.taxProductDisplayPrices') == TaxRuleLibrary::PRICE_WITH_TAX) {
             return $this->total_111;
         }
     }
     // total property
     if ($key === 'total' || $key === 'total_111') {
         if ($this->total !== null) {
             return $this->total;
         }
         if ($this->taxAmount !== null) {
             $this->total = $this->subtotal_111 + $this->taxAmount;
             return $this->total;
         }
         if ($this->taxRules === null) {
             $this->taxRules = TaxRule::builder()->where('country_id_103', config('market.taxCountry'))->where('customer_class_tax_id_106', config('market.taxCustomerClass'))->where('product_class_tax_id_107', $this->product_class_tax_id_111)->orderBy('priority_104', 'asc')->get();
         }
         $taxes = TaxRuleLibrary::taxCalculateOverSubtotal($this->subtotal_111, $this->taxRules->where('product_class_tax_id_107', $this->product_class_tax_id_111));
         $this->taxAmount = $taxes->sum('taxAmount');
         $this->total = $this->subtotal_111 + $this->taxAmount;
         return $this->total;
     }
     // taxAmount property
     if ($key === 'taxAmount' || $key === 'tax_amount' || $key === 'tax_amount_111') {
         if ($this->taxAmount !== null) {
             return $this->taxAmount;
         } else {
             if ($this->taxRules === null) {
                 $this->taxRules = TaxRule::builder()->where('country_id_103', config('market.taxCountry'))->where('customer_class_tax_id_106', config('market.taxCustomerClass'))->where('product_class_tax_id_107', $this->product_class_tax_id_111)->orderBy('priority_104', 'asc')->get();
             }
             $taxes = TaxRuleLibrary::taxCalculateOverSubtotal($this->subtotal_111, $this->taxRules->where('product_class_tax_id_107', $this->product_class_tax_id_111));
             $this->taxAmount = $taxes->sum('taxAmount');
             return $this->taxAmount;
         }
     }
     if ($key === 'taxRules' || $key === 'tax_rules' || $key === 'tax_rules_111') {
         return $this->taxRules;
     }
     // check if property is mapped
     if (isset($this->maps[$key])) {
         return $this->{$this->maps[$key]};
     }
     // call parent method in model
     return parent::getAttribute($key);
 }
Beispiel #2
0
 public function apiGetProductTaxes($price, $productClassTax)
 {
     $taxRules = TaxRule::builder()->where('country_id_103', config('market.taxCountry'))->where('customer_class_tax_id_106', config('market.taxCustomerClass'))->where('product_class_tax_id_107', $productClassTax)->orderBy('priority_104', 'asc')->get();
     if ((int) config('market.taxProductPrices') == TaxRuleLibrary::PRICE_WITHOUT_TAX) {
         $taxes = TaxRuleLibrary::taxCalculateOverSubtotal($price, $taxRules);
         $taxAmount = $taxes->sum('taxAmount');
         $subtotal = $price;
         $total = $subtotal + $taxAmount;
     } elseif ((int) config('market.taxProductPrices') == TaxRuleLibrary::PRICE_WITH_TAX) {
         $taxes = TaxRuleLibrary::taxCalculateOverTotal($price, $taxRules);
         $taxAmount = $taxes->sum('taxAmount');
         $total = $price;
         $subtotal = $total - $taxAmount;
     }
     $response = ['success' => true, 'taxes' => $taxes, 'subtotal' => $subtotal, 'taxAmount' => $taxAmount, 'total' => $total, 'subtotalFormat' => number_format($subtotal, 2, ',', '.'), 'taxAmountFormat' => number_format($taxAmount, 2, ',', '.'), 'totalFormat' => number_format($total, 2, ',', '.')];
     return response()->json($response);
 }
Beispiel #3
0
 public function editCustomRecord($parameters)
 {
     $parameters['categories'] = Category::where('lang_id_110', $parameters['lang']->id_001)->get();
     $parameters['productTypes'] = array_map(function ($object) {
         $object->name = trans($object->name);
         return $object;
     }, config('market.productTypes'));
     $parameters['priceTypes'] = array_map(function ($object) {
         $object->name = trans($object->name);
         return $object;
     }, config('market.priceTypes'));
     $parameters['productClassTaxes'] = ProductClassTax::builder()->get();
     $parameters['parentsProducts'] = Product::builder()->where('lang_id_112', base_lang()->id_001)->where('id_111', '<>', $parameters['id'])->whereNull('parent_product_id_111')->get();
     $taxRules = TaxRule::builder()->where('country_id_103', config('market.taxCountry'))->where('customer_class_tax_id_106', config('market.taxCustomerClass'))->where('product_class_tax_id_107', $parameters['object']->product_class_tax_id_111)->orderBy('priority_104', 'asc')->get();
     $taxes = TaxRuleLibrary::taxCalculateOverSubtotal($parameters['object']->subtotal_111, $taxRules);
     // ATTENTION! we create custom properties tax_amount_111 and total_111
     $parameters['object']->tax_amount_111 = $taxes->sum('taxAmount');
     $parameters['object']->total_111 = $parameters['object']->subtotal_111 + $parameters['object']->tax_amount_111;
     $attachments = AttachmentLibrary::getRecords($this->package, 'market-product', $parameters['object']->id_111, $parameters['lang']->id_001);
     $parameters['customFieldGroups'] = CustomFieldGroup::builder()->where('resource_id_025', 'market-product')->get();
     $parameters['attachmentFamilies'] = AttachmentFamily::getAttachmentFamilies(['resource_id_015' => 'market-product']);
     $parameters = array_merge($parameters, $attachments);
     return $parameters;
 }