Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($idItemNaoCadastrado = null)
 {
     $model = new Servico();
     if (isset($_POST['Servico'])) {
         $model->attributes = $_POST['Servico'];
         if ($model->save()) {
             if (!empty(Yii::app()->user->getState('log_item_nao_cadastrado'))) {
                 $logItemNaoCadastrado = LogItemNaoCadastrado::model()->findByPk(Yii::app()->user->getState('log_item_nao_cadastrado'));
                 $logItemNaoCadastrado->scenario = 'alteracao';
                 $logItemNaoCadastrado->cadastrado = true;
                 $logItemNaoCadastrado->save();
                 $oOrdemServicoItem = OrdemServicoItem::model()->findByPk($logItemNaoCadastrado->ordem_servico_item_id);
                 $oOrdemServicoItem->scenario = 'alteracao';
                 $oOrdemServicoItem->item_id = $model->id;
                 $oOrdemServicoItem->save();
                 Yii::app()->user->setState('log_item_nao_cadastrado', NULL);
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     if (!empty($idItemNaoCadastrado)) {
         $logItemNaoCadastrado = LogItemNaoCadastrado::model()->findByPk($idItemNaoCadastrado);
         if (!empty($logItemNaoCadastrado)) {
             Yii::app()->user->setState('log_item_nao_cadastrado', $logItemNaoCadastrado->id);
             $model->titulo = $logItemNaoCadastrado->titulo;
             $model->preco = $logItemNaoCadastrado->preco;
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function postCadastro()
 {
     $id = Input::get('id');
     $dsServico = Input::get('dsServico');
     $destaque = Input::get('destaque');
     $servicos = Input::get('servico');
     $vlServico = str_replace(array("R\$", "."), "", Input::get('vlServico'));
     $vlServico = str_replace(",", ".", $vlServico);
     if (isset($id)) {
         $servico = Servico::find($id);
         $servico->dsServico = $dsServico;
         $servico->vlServico = $vlServico;
         $servico->servico = $servicos;
         $servico->destaque = $destaque;
         if (Input::hasFile('img')) {
             $img = Input::file('img');
             $img->move('upload/', $img->getClientOriginalName());
             $servico->img = 'upload/' . $img->getClientOriginalName();
         }
         $servico->save();
     } else {
         $servico = new Servico();
         $servico->dsServico = $dsServico;
         $servico->vlServico = $vlServico;
         $servico->servico = $servicos;
         $servico->destaque = $destaque;
         $servico->status = 'AT';
         if (Input::hasFile('img')) {
             $img = Input::file('img');
             $img->move('upload/', $img->getClientOriginalName());
             $servico->img = 'upload/' . $img->getClientOriginalName();
         }
         $servico->save();
     }
     return Redirect::to('/servico');
 }