/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Alreserva(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Alreserva'])) { $model->attributes = $_POST['Alreserva']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
private function insertareserva($documento, $cantidad) { if (isset($modelo)) { unset($modelo); } $modelo = new Alreserva(); $modelo->hidesolpe = $this->id; $modelo->cant = $cantidad; $modelo->flag = '1'; $modelo->estadoreserva = self::ESTADO_RESERVA_CREADO; $modelo->codocu = $documento; $modelo->fechares = date("Y-m-d H:i:s"); //PRINT_R($modelo->attributes); return $modelo->save(); }
public function actionReservaitem($id) { $model = Desolpe::Model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'No se encontro ningun documento para estos datos'); } if ($model->tipsolpe == 'S') { throw new CHttpException(500, 'No se puede reservar un servicio'); } $modelocabecera = Solpe::model()->findByPk($model->hidsolpe); if ($modelocabecera->escompra == '1') { throw new CHttpException(500, 'No se puede reservar items de solicitudes hechas para compras '); } // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); $model->setscenario('reservar'); if (isset($_POST['Desolpe'])) { $model->attributes = $_POST['Desolpe']; if ($model->save()) { $transaccion = $model->dbConnection->beginTransaction(); $idsolpe = $model->id; $cantcompra = $model->cantidad_compras; $cantreservada = $model->cantidad_reservada; if ($cantreservada > 0) { $modelo = new Alreserva(); $modelo->hidesolpe = $idsolpe; $modelo->cant = $cantreservada; $modelo->flag = '1'; // $model->est='06'; //estado 'RESERVADO' //$modelo->codocu='045'; } if ($cantcompra > 0) { $modelin = new Alreserva(); $modelin->hidesolpe = $idsolpe; $modelin->cant = $cantcompra; $modelin->flag = '0'; // $model->est='08'; //'SOLICITADO PARA COMPRA' //$modelin->codocu='008'; } $modeloinventario = Alinventario::model()->findByPk($model->desolpe_alinventario->id); if (!is_null($modeloinventario)) { $modeloinventario->setscenario('modificacantidad'); $modeloinventario->cantlibre = $modeloinventario->cantlibre - $cantreservada * Alconversiones::model()->convierte($modeloinventario->codart, $model->um); ///; $modeloinventario->cantres = $modeloinventario->cantres + $cantreservada * Alconversiones::model()->convierte($modeloinventario->codart, $model->um); } $model->est = ($cantcompra > 0 and $cantreservada == 0) ? '80' : '60'; ///si es una solicitud exclusiva apra compras el estado es '08' if ($model->save() and $cantreservada > 0 ? $modelo->save() : true and $modeloinventario->save() and $cantcompra > 0 ? $modelin->save() : true) { $transaccion->commit(); } else { $transaccion->rollback(); ///regresar todo a como estaba throw new CHttpException(404, 'carayyyyyy'); } if (!empty($_GET['asDialog'])) { //Close the dialog, reset the iframe and update the grid echo CHtml::script("window.parent.\$('#cru-dialogdetalle').dialog('close');\n\t\t\t\t\t\t\t\t\t\t\t\t\t window.parent.\$('#cru-detalle').attr('src','');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twindow.parent.\$.fn.yiiGridView.update('detalle-grid');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"); Yii::app()->end(); } } } if (!empty($_GET['asDialog'])) { $this->layout = '//layouts/iframe'; } //ECHO $model->id; //Yii::app()->end(); $this->render('_form_detalle_reservar', array('model' => $model, 'idcabeza' => $model->hidsolpe)); }