Example #1
0
 public static function getCloudDefault()
 {
     $objStatus = TaxStatus::model()->findByAttributes(array('status' => 'Default', 'tax1_status' => '0', 'tax2_status' => '1', 'tax3_status' => '1', 'tax4_status' => '1', 'tax5_status' => '1'));
     if (is_null($objStatus)) {
         return false;
     } else {
         return $objStatus;
     }
 }
Example #2
0
 public function calc_percentage($rate_id, $status_id, $amount)
 {
     $rate = new TaxRate();
     $rate->load($rate_id);
     // If no rate supplied then return zero
     if (!$rate->isLoaded()) {
         return 0;
     }
     $rate_percentage = $rate->percentage;
     $status = new TaxStatus();
     $status->load($status_id);
     // If no status supplied then by default apply tax
     if (!$status->isLoaded()) {
         $status->apply_tax = 't';
     }
     if ($status->apply_tax === 't') {
         $percentage = $rate_percentage;
     } else {
         $percentage = 0;
     }
     return bcdiv($percentage, 100, 4);
 }
Example #3
0
 /**
  * For a product, returns tax rate for all defined destinations
  * Useful for RSS exports
  * @return TaxGrid[]
  */
 public function GetTaxRateGrid()
 {
     $arrGrid = array();
     $intTaxStatus = $this->tax_status_id;
     $objStatus = TaxStatus::LoadByLS($intTaxStatus);
     $objDestinations = Destination::model()->findAll();
     foreach ($objDestinations as $objDestination) {
         //Because of differences in how Google defines zip code ranges, we can't convert our ranges
         //to theirs. At this time we won't be able to support zip code ranges
         if (!is_null($objDestination->country) && $objDestination->Zipcode1 == '') {
             $objTaxCode = TaxCode::LoadByLS($objDestination->taxcode);
             //print_r($objTaxCode);
             $fltRate = 0.0;
             for ($x = 1; $x <= 5; $x++) {
                 $statusstring = "tax" . $x . "_status";
                 $codestring = "tax" . $x . "_rate";
                 if ($objStatus->{$statusstring} == 0) {
                     $fltRate += $objTaxCode->{$codestring};
                 }
             }
             //Our four elements
             $strCountry = Country::CodeById($objDestination->country);
             if (!is_null($objDestination->state)) {
                 $strState = State::CodeById($objDestination->state);
             } else {
                 $strState = '';
             }
             //$fltRate -- built above
             $strTaxShip = Yii::app()->params['SHIPPING_TAXABLE'] == '1' ? "y" : "n";
             $arrGrid[] = array($strCountry, $strState, $fltRate, $strTaxShip);
         }
     }
     return $arrGrid;
 }
 /**
  * Adds tax status
  *
  * @param string $passkey
  * @param int $intRowid
  * @param string $strStatus
  * @param int $blnTax1Exempt
  * @param int $blnTax2Exempt
  * @param int $blnTax3Exempt
  * @param int $blnTax4Exempt
  * @param int $blnTax5Exempt
  * @return string
  */
 function add_tax_status($passkey, $intRowid, $strStatus, $blnTax1Exempt, $blnTax2Exempt, $blnTax3Exempt, $blnTax4Exempt, $blnTax5Exempt)
 {
     if (!$this->check_passkey($passkey)) {
         return self::FAIL_AUTH;
     }
     if ($strStatus == "") {
         //ignore blank tax statuses
         return self::OK;
     }
     // Loads tax
     $tax = TaxStatus::LoadByLS($intRowid);
     if (!$tax) {
         $tax = new TaxStatus();
     }
     $tax->lsid = $intRowid;
     $tax->status = $strStatus;
     $tax->tax1_status = $blnTax1Exempt;
     $tax->tax2_status = $blnTax2Exempt;
     $tax->tax3_status = $blnTax3Exempt;
     $tax->tax4_status = $blnTax4Exempt;
     $tax->tax5_status = $blnTax5Exempt;
     if (!$tax->save()) {
         Yii::log("SOAP ERROR : Error saving category {$strStatus} " . print_r($tax->getErrors()), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::UNKNOWN_ERROR . " Error saving category {$strStatus} " . print_r($tax->getErrors(), true);
     }
     return self::OK;
 }
Example #5
0
 /**
  * Removes the tax from a tax inclusive price. Since our TaxIn prices are generated from our
  * default tax code, we can use this to undo the tax
  * @param $fltPrice
  * @return float
  */
 public static function StripTaxesFromPrice($fltSellTotal, $intTaxStatusId)
 {
     static $objTaxes;
     // Cached for better performance
     $fltSellTotalTaxed = $fltSellTotal;
     $arrTaxAmount = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0);
     $intTaxCodeId = 0;
     $objTaxCodes = TaxCode::model()->findAll(array('order' => 'list_order'));
     //Default tax code is first in list
     $objTaxCode = $objTaxCodes[0];
     if (!$objTaxCode) {
         if (!is_null($intTaxCodeId)) {
             //Ignore null at this stage
             Yii::log("Unknown tax code passed: {$intTaxCodeId}", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         }
         return array($fltSellTotalTaxed, $arrTaxAmount);
     }
     if ($intTaxStatusId instanceof TaxStatus) {
         $objTaxStatus = $intTaxStatusId;
     } elseif ($intTaxStatusId >= 0) {
         $objTaxStatus = TaxStatus::model()->findByAttributes(array('lsid' => $intTaxStatusId));
     } else {
         $objTaxStatus = false;
     }
     if (!$objTaxes) {
         $objTaxes = Tax::model()->findAll();
     }
     $taxtypes = 5;
     // Number of taxes in LS
     // for each exempt, reset the code to 0
     if ($objTaxStatus) {
         if ($objTaxStatus->tax1_status) {
             $objTaxCode->tax1_rate = 0;
         }
         if ($objTaxStatus->tax2_status) {
             $objTaxCode->tax2_rate = 0;
         }
         if ($objTaxStatus->tax3_status) {
             $objTaxCode->tax3_rate = 0;
         }
         if ($objTaxStatus->tax4_status) {
             $objTaxCode->tax4_rate = 0;
         }
         if ($objTaxStatus->tax5_status) {
             $objTaxCode->tax5_rate = 0;
         }
     }
     $i = 0;
     foreach ($objTaxes as $objTax) {
         $strRate = "tax" . ($i + 1) . "_rate";
         if ($objTaxCode->{$strRate} > 0) {
             if ($objTax->compounded) {
                 $fltTaxAmount = $fltSellTotalTaxed / ($objTaxCode->{$strRate} / 100);
             } else {
                 $fltOrig = $fltSellTotal / (1 + $objTaxCode->{$strRate} / 100);
                 $fltTaxAmount = round($fltSellTotal - $fltOrig, 2);
             }
         } else {
             $fltTaxAmount = 0;
         }
         if ($objTax->max_tax > 0 && $fltTaxAmount >= $objTax->max_tax) {
             $fltTaxAmount = $objTax->max_tax;
         }
         $arrTaxAmount[$i + 1] = $fltTaxAmount;
         $fltSellTotalTaxed = $fltSellTotalTaxed - $fltTaxAmount;
         $i++;
         if ($i >= $taxtypes) {
             $i = $taxtypes;
         }
     }
     return $fltSellTotalTaxed;
 }
 /**
  * Tax Status List
  *
  * @param string $passkey
  * @return string
  * @throws SoapFault
  * @soap
  */
 public function list_tax_statuses($passkey)
 {
     self::check_passkey($passkey);
     $obj = TaxStatus::model()->findAll();
     return CJSON::encode($obj);
 }