public function guardarMedicina() { $response = self::SUCCESS; try { $data = Input::all(); Log::error($data); $detalle = new Medicina(); $detalle->nombre = $data["nombre"]; $detalle->descripcion = $data["descripcion"]; $detalle->proveedor_id = $data["proveedor_id"]; $detalle->cantidad = $data["cantidad"]; $detalle->precio = $data["precio"]; $detalle->save(); } catch (\Exception $ex) { Log::error($ex); $response = self::FAIL; } return array("responseCode" => $response); }
public function loadModel() { if ($this->_model === null) { if (isset($_GET['id'])) { $this->_model = Medicina::model()->findbyPk($_GET['id']); } if ($this->_model === null) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } } return $this->_model; }
echo $form->labelEx($model, 'fecha'); ?> <?php echo $form->textField($model, 'fecha'); ?> <?php echo $form->error($model, 'fecha'); ?> </div>--> <div class="row"> <?php echo $form->labelEx($model, 'recipeMedicinas'); ?> <?php echo $form->dropDownList($model, 'recipeMedicinas', Medicina::GET_LISTA_NOMBRE(), array('multiple' => true)); ?> <?php echo $form->error($model, 'recipeMedicinas'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'paciente_id'); ?> <?php echo $form->dropDownList($model, 'paciente_id', Paciente::GET_LISTA_NOMBRE_COMPLETO(), array('empty' => 'Seleccione paciente')); ?> <?php echo $form->error($model, 'paciente_id');
public function guardarDetallePedido() { $response = self::SUCCESS; try { $data = Input::all(); $medicina = Medicina::find($data["medicina"]); $cantidadRestante = $medicina->cantidad - $data["cantidad"]; if ($data["cantidad"] == 0) { throw new \Exception("Se tiene que agregar por lo menos un medicamento"); } if ($cantidadRestante < 0) { throw new \Exception("No hay disponbilidad suficiente de medicina"); } //Guardar detalle $subtotal = $medicina->precio * (int) $data["cantidad"]; $detallePedido = new DetallePedido(); $detallePedido->pedido_id = $data["pedido_id"]; $detallePedido->medicina = $data["medicina"]; $detallePedido->cantidad = $data["cantidad"]; $detallePedido->subtotal = $subtotal; $detallePedido->save(); //Actualizar total $pedido = Pedido::find($data["pedido_id"]); $pedido->total = $pedido->total + $subtotal; $pedido->save(); //Restar de el catalogo $medicina->cantidad = $cantidadRestante; $medicina->save(); } catch (\Exception $ex) { Log::error($ex); $response = self::FAIL; } return array("responseCode" => $response); }
public static function GET_LISTA_NOMBRE() { return CHtml::listData(Medicina::model()->findAll(), 'id', 'nombre'); }