/** * Store a newly created branch in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Tax::$rules, Tax::$messages); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $tax = new Tax(); $tax->name = Input::get('name'); $tax->rate = Input::get('rate'); $tax->save(); return Redirect::route('taxes.index')->withFlashMessage('Tax successfully created!'); }
public function actionCreate() { $model = new Tax(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Tax'])) { $model->attributes = $_POST['Tax']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionUpload() { parent::actionUpload(); $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/'; // folder for uploaded files $file = $folder . basename($_FILES['uploadfile']['name']); if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { $row = 0; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row > 0) { $model = Tax::model()->findByPk((int) $data[0]); if ($model === null) { $model = new Tax(); } $model->taxid = (int) $data[0]; $model->taxcode = $data[1]; $model->taxvalue = $data[2]; $model->description = $data[3]; $model->recordstatus = (int) $data[4]; try { if (!$model->save()) { $this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]); } } catch (Exception $e) { $this->messages = $this->messages . $e->getMessage(); } } $row++; } } else { $this->messages = $this->messages . ' memory or harddisk full'; } fclose($handle); } else { $this->messages = $this->messages . ' check your directory permission'; } if ($this->messages == '') { $this->messages = 'success'; } echo $this->messages; }
private function generateEuropeTaxRule() { $euro_vat_array = self::$europe_vat_array; $euro_tax_rule_grp_id = TaxRulesGroup::getIdByName((string) $this->european_vat_name); if (!$euro_tax_rule_grp_id) { // Create it $trg = new TaxRulesGroup(); $trg->name = (string) $this->european_vat_name; $trg->active = 1; if (!$trg->save()) { $this->_errors[] = Tools::displayError('Tax rule cannot be saved.'); return false; } $euro_tax_rule_grp_id = (int) $trg->id; } $tax_rules_euro_group = TaxRule::getTaxRulesByGroupId((int) Context::getContext()->language->id, (int) $euro_tax_rule_grp_id); $euro_group_taxes_rules = array(); foreach ($tax_rules_euro_group as $tax_rule) { $euro_group_taxes_rules[] = $tax_rule; } foreach ($euro_vat_array as $euro_vat_name => $euro_vat_details) { $posted_euro_vat = 'euro_vat_' . (string) $euro_vat_details['iso_country']; $posted_available_vat = 'available_vat_' . (string) $euro_vat_details['iso_country']; $country_id = Country::getByIso((string) $euro_vat_details['iso_country']); if (Tools::isSubmit($posted_euro_vat)) { if (!Tools::isSubmit($posted_available_vat)) { $id_tax_found = Tax::getTaxIdByName((string) $euro_vat_name); if ($id_tax_found !== false) { $tax = new Tax((int) $id_tax_found); } else { $tax = new Tax(); } $tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $euro_vat_name; $tax->rate = (double) $euro_vat_details['rate']; $tax->active = 1; if ($tax->validateFields(false, true) !== true || $tax->validateFieldsLang(false, true) !== true) { $this->_errors[] = Tools::displayError('Invalid tax properties.'); continue; } if (!$tax->save()) { $this->_errors[] = Tools::displayError('An error occurred while saving the tax: '); continue; } $id_tax_rule = $this->getTaxRuleIdFromUnique($euro_tax_rule_grp_id, $country_id, $id_tax_found); if ($id_tax_rule !== false) { $tr = new TaxRule((int) $id_tax_rule); } else { $tr = new TaxRule(); } $tr->id_tax_rules_group = (int) $euro_tax_rule_grp_id; $tr->id_country = (int) $country_id; $tr->id_state = 0; $tr->id_county = 0; $tr->zipcode_from = 0; $tr->zipcode_to = 0; $tr->behavior = 0; $tr->description = ''; $tr->id_tax = (int) $tax->id; $tr->save(); } else { $assoc_id_tax = (int) Tools::getValue($posted_available_vat); $id_tax_rule = $this->getTaxRuleIdFromUnique($euro_tax_rule_grp_id, $country_id, $assoc_id_tax); if ($id_tax_rule !== false) { $tr = new TaxRule((int) $id_tax_rule); } else { $tr = new TaxRule(); } $tr->id_tax_rules_group = (int) $euro_tax_rule_grp_id; $tr->id_country = (int) $country_id; $tr->id_state = 0; $tr->id_county = 0; $tr->zipcode_from = 0; $tr->zipcode_to = 0; $tr->behavior = 0; $tr->description = ''; $tr->id_tax = (int) $assoc_id_tax; $tr->save(); } } else { $this->_errors[] = Tools::displayError('Invalid parameters received'); } } }
/** * Adds tax to the system * * @param string $passkey * @param int $intNo * @param string $strTax * @param float $fltMax * @param int $blnCompounded * @return string */ public function add_tax($passkey, $intNo, $strTax, $fltMax, $blnCompounded) { if (!$this->check_passkey($passkey)) { return self::FAIL_AUTH; } if ($intNo > 5) { _xls_log(sprintf("SOAP ERROR : System can only handle %s number of taxes. Specified %s", 5, $intNo)); return self::UNKNOWN_ERROR; } // Loads tax $tax = Tax::LoadByLS($intNo); if (!$tax) { $tax = new Tax(); $tax->lsid = $intNo; } $tax->tax = $strTax; $tax->max_tax = $fltMax; $tax->compounded = $blnCompounded; if (!$tax->save()) { _xls_log("SOAP ERROR : Error adding tax {$strTax} " . print_r($tax->getErrors(), true)); return self::UNKNOWN_ERROR . " Error adding tax {$strTax} " . print_r($tax->getErrors(), true); } return self::OK; }
/** * Adds tax to the system * * @param string $passkey * @param int $intNo * @param int $intTaxRateId * @param string $strTax * @param float $fltMax * @param int $blnCompounded * @return string * @throws SoapFault * @soap */ public function add_tax($passkey, $intNo, $intTaxRateId, $strTax, $fltMax, $blnCompounded) { self::check_passkey($passkey); //Remove if we have this tax already, just readd Tax::model()->deleteAllByAttributes(array('id' => $intTaxRateId)); Tax::model()->deleteAllByAttributes(array('lsid' => $intNo)); // Loads tax $tax = Tax::LoadByLS($intNo); if (!$tax) { $tax = new Tax(); $tax->id = $intTaxRateId; $tax->lsid = $intNo; } $tax->tax = $strTax; $tax->max_tax = $fltMax; $tax->compounded = $blnCompounded; if (!$tax->save()) { $strMsg = "Error adding tax {$strTax}"; Yii::log("SOAP ERROR : {$strMsg} " . print_r($tax->getErrors(), true), CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__); throw new SoapFault($strMsg, WsSoapException::ERROR_UNKNOWN); } return self::OK; }