/** * Update existing route * * @param void * @return null */ function edit() { if ($this->active_tax_rate->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_tax_rate->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $this->wireframe->addPageMessage(lang('Updating of this tax rate will also update all existing invoices. If that is not an option, consider creating a new tax rate'), 'warning'); $tax_rate_data = $this->request->post('tax_rate'); if (!is_array($tax_rate_data)) { $tax_rate_data = array('name' => $this->active_tax_rate->getName(), 'percentage' => $this->active_tax_rate->getPercentage()); } // if $this->smarty->assign('tax_rate_data', $tax_rate_data); if ($this->request->isSubmitted()) { $this->active_tax_rate->setAttributes($tax_rate_data); $save = $this->active_tax_rate->save(); if ($save && !is_error($save)) { flash_success('Tax rate ":name" has been updated', array('name' => $this->active_tax_rate->getName())); $this->redirectTo('admin_tax_rates'); } else { $this->smarty->assign('errors', $save); } // if } // if }
/** * Show the form for creating a new resource. * GET /tax_rates/create * * @return Response */ public function create() { $validator = Validator::make($data = Input::all(), TaxRate::$rules); $user = Auth::user(); if ($validator->passes()) { $this->tax_rate->name = Input::get('name'); $this->tax_rate->rate = Input::get('rate'); $this->tax_rate->user_id = Auth::user()->id; if ($this->tax_rate->save()) { if (Request::ajax()) { return Response::json(array('status' => 'success', 'message' => trans('tax_rates.success.create'), 'id' => $this->tax_rate->id, 'name' => $this->tax_rate->name, 'rate' => $this->tax_rate->rate)); } return Redirect::route('tax_rates.index'); } } if (Request::ajax()) { return Response::json(array('status' => 'error', 'errors' => $validator->errors()->toArray())); } return Redirect::back()->withErrors($validator)->withInput(); }
public function actionCreate() { $model = new TaxRate(); $description = new TaxRateDescription(); $this->performAjaxValidation(array($model, $description), 'tax-rate-form'); if (isset($_POST[$this->modelName])) { $model->setAttributes($_POST[$this->modelName]); $description->setAttributes($_POST[$this->modelName . 'Description']); $suc = Yii::t('info', 'TaxRate was successfully created'); $err = Yii::t('info', 'Could not update TaxRate'); $description->tax_rate_id = 0; $description->locale_code = Yii::app()->getLanguage(); if ($model->validate() && $description->validate()) { if ($model->save()) { $description->tax_rate_id = $model->id; $description->save(); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc); if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_view', array('model' => $model, 'description' => $description), false, true); Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->id)); } } else { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err); } } else { $description->validate(); } } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_form', array('model' => $model, 'description' => $description), false, true); Yii::app()->end(); } $this->render('create', array('model' => $model, 'description' => $description)); }
$type = new ProductType(); $type->name = $v; $type->list_order = $list_order; $type->save(); $producttype_id_arr[] = $type->id; $list_order++; } echo '.'; foreach ($sugar_demodata['taxrate_seed_data'] as $v) { $taxrate = new TaxRate(); $taxrate->name = $v['name']; $taxrate->value = $v['value']; $taxrate->status = "Active"; $taxrate->list_order = "1"; $taxrate->disable_num_format = TRUE; $taxrate->save(); $taxrate_id_arr[] = $taxrate->id; } echo '.'; foreach ($sugar_demodata['currency_seed_data'] as $v) { if ($v['name'] == $_SESSION["default_currency_name"]) { continue; } $currency = new Currency(); $currency->name = $v['name']; $currency->status = "Active"; $currency->conversion_rate = $v['conversion_rate']; $currency->iso4217 = $v['iso4217']; $currency->symbol = $v['symbol']; $currency->save(); }