function buscar($b) { $elProducto = ProductoInventario::model()->find("id={$b}"); //$ar = array("referencia"=>"Hola", "presentacion"=>"laaaa") $ar = array("referencia" => $elProducto->producto_referencia, "presentacion" => $elProducto->productoPresentacion->presentacion, "valor" => $elProducto->precio_publico, "stock" => $elProducto->cantidad, "iva" => $elProducto->iva); $arr = json_encode($ar); echo $arr; }
function buscar($b) { $elProducto = ProductoInventario::model()->find("producto_referencia='" . $b . "'"); //$ar = array("referencia"=>"Hola", "presentacion"=>"laaaa") $ar = array("id" => $elProducto->id, "referencia" => $elProducto->producto_referencia, "presentacion" => $elProducto->productoPresentacion->presentacion, "unidad" => $elProducto->productoUnidadMedida->medida, "valor" => $elProducto->costo_iva, "iva" => $elProducto->iva); $arr = json_encode($ar); echo $arr; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new HojaGastos(); $superTotal = 0; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['HojaGastos'])) { $datosCita = Citas::model()->findByPk($_GET['idCita']); $model->attributes = $_POST['HojaGastos']; $model->cita_id = $datosCita->id; $model->paciente_id = $datosCita->paciente_id; $model->observaciones = $_POST['HojaGastos']['observaciones']; $model->fecha = date("Y-m-d H:i:s"); $model->personal_id = Yii::app()->user->usuarioId; if ($model->save()) { //Los detalles de la Hoja de Gastos for ($i = 0; $i <= $_POST['variable']; $i++) { if (isset($_POST['producto_' . $i])) { $detalleC = new HojaGastosDetalle(); $detalleC->hoja_gastos_id = $model->id; $detalleC->producto_id = $_POST['elid_' . $i]; $detalleC->cantidad = $_POST['cantidad_' . $i]; $detalleC->save(); //Agregar a relación de Hoja de gstos $elCosto = ProductoInventario::model()->findByPk($_POST['producto_' . $i]); //Reducir inventario e inventario detalle $elProducto = InventarioPersonalDetalle::model()->find('id =' . $_POST['producto_' . $i] . " and inventario_personal_id =" . Yii::app()->user->usuarioId); $elProducto->cantidad = $elProducto->cantidad - $_POST['cantidad_' . $i]; $elProducto->save(); $elProductoDetalle = ProductoInventarioDetalle::model()->find('producto_inventario_id = ' . $elProducto->producto_id . ' and lote = "' . $_POST['lote_' . $i] . '"'); $elProductoDetalle->existencia = $elProductoDetalle->existencia - $_POST['cantidad_' . $i]; if ($elProductoDetalle->save()) { $elProducto = ProductoInventario::model()->findByPk($elProductoDetalle->producto_inventario_id); $elProducto->cantidad = $elProducto->cantidad - $_POST['cantidad_' . $i]; $elProducto->save(); } $superTotal = $superTotal + $elProducto->costo_iva; } } } $relacion = new RelacionHojaGastos(); $relacion->hoja_gastos_id = $model->id; $relacion->paciente_id = $model->paciente_id; $relacion->n_identificacion = $datosCita->n_identificacion; $relacion->hoja = "Hoja de Gastos"; $relacion->asistencial_id = $datosCita->personal_id; $relacion->cita_id = $datosCita->id; $relacion->linea_servicio_id = $datosCita->linea_servicio_id; $relacion->fecha = date("Y-m-d"); $relacion->fecha_hora = date("Y-m-d H:i:s"); $relacion->costo = $superTotal; $relacion->personal_id = Yii::app()->user->usuarioId; $relacion->save(); $this->redirect(array('view', 'id' => $model->id)); } $this->render('create', array('model' => $model)); }
public function actionAnular() { $id = $_GET['idCompra']; if ($_POST['clave'] == "super") { $laCompra = ProductoCompras::model()->findByPk($id); $laCompra->comentario_anulado = $_POST['observaciones']; $laCompra->total_compra = $laCompra->total_compra * -1; $laCompra->estado = "Anulada"; if ($laCompra->update()) { $compraDetalle = ProductoCompraDetalle::model()->findAll("producto_compra_id = " . $laCompra->id); foreach ($compraDetalle as $compra_detalle) { $InventarioProducto = ProductoInventario::model()->findByPk($compra_detalle->producto_id); $InventarioProducto->cantidad = $InventarioProducto->cantidad - $compra_detalle->cantidad; $InventarioProducto->update(); } Yii::app()->user->setFlash('success', "Se ha realizado con éxito la anulación"); $this->redirect(array('view', 'id' => $id)); } } else { Yii::app()->user->setFlash('error', "Usted no esta autorizado para realizar esta anulación"); $this->redirect(array('view', 'id' => $id)); } }
$form = $this->beginWidget('CActiveForm', array('id' => 'producto-compras-form', 'action' => 'index.php?r=productoCompras/create', 'htmlOptions' => array('onsubmit' => "return validar();"), 'enableAjaxValidation' => true)); ?> <?php echo $form->errorSummary($model); ?> <div class="row"> <div class="span12"> <!-- <form id="Formulacion" name="Formulacion" action="index.php?r=productosCompras/guardarFormulacion" method = "post" onsubmit="onEnviar()"> --> <!-- </form> --> </div> </div> <?php $losProductos = ProductoInventario::model()->findAll("estado = 'Activo' ORDER BY `nombre_producto` ASC"); ?> <div class="row"> <div class="span6"> <?php echo $form->labelEx($model, 'producto_proveedor_id'); ?> <?php echo $form->dropDownList($model, 'producto_proveedor_id', CHtml::listData(ProductoProveedor::model()->findAll("id > 0 order by nombre ASC"), 'id', 'nombre'), array('class' => 'input-xxlarge')); ?> <?php echo $form->error($model, 'producto_proveedor_id'); ?> </div>
?> <h1>Relación de Productos - <a href="#exportar" class="btn btn-warning" role="button" data-toggle="modal"><i class="icon-share-alt icon-white"></i> Exportar</a></h1> <?php //echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search', array('model' => $model)); $lasVentas = Ventas::model()->findAll(); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'ventas-detalle-grid', 'dataProvider' => $model->search(), 'afterAjaxUpdate' => 'reinstallDatePickerVentas', 'filter' => $model, 'columns' => array(array('header' => 'ID.', 'name' => 'id', 'value' => '$data->id', 'htmlOptions' => array('width' => '30')), array('name' => 'nombre_paciente', 'value' => '$data->paciente->nombre', 'htmlOptions' => array('width' => '100'), 'headerHtmlOptions' => array('style' => 'width:150px;text-align:center;')), array('name' => 'apellido_paciente', 'value' => '$data->paciente->apellido', 'htmlOptions' => array('width' => '100'), 'headerHtmlOptions' => array('style' => 'width:150px;text-align:center;')), array('header' => 'Producto', 'name' => 'producto_id', 'filter' => CHtml::listData(ProductoInventario::model()->findAll(array('order' => 'nombre_producto ASC')), 'id', 'nombre_producto'), 'value' => '$data[\'producto\'][\'nombre_producto\']', 'htmlOptions' => array('width' => '250')), array('header' => 'Vendedor', 'name' => 'vendedor_id', 'value' => '$data->venta->vendedor->nombreCompleto', 'filter' => CHtml::listData(Personal::model()->findAll(array('order' => 'nombres ASC')), 'id', 'nombreCompleto'), 'htmlOptions' => array('width' => '200'), 'headerHtmlOptions' => array('style' => 'width:150px;text-align:center;')), array('name' => 'cantidad', 'value' => '$data->cantidad', 'htmlOptions' => array('width' => '50'), 'footer' => "<h5>" . number_format($model->getTotal4($model->searchSuma())) . '</h5>'), array('name' => 'valor', 'value' => 'number_format($data->valor,2)', 'footer' => "<h5>\$ " . number_format($model->getTotal($model->searchSuma()), 2) . '</h5>'), array('name' => 'iva', 'value' => 'number_format($data->iva,2)', 'footer' => "<h5>\$ " . number_format($model->getTotal2($model->searchSuma()), 2) . '</h5>'), array('name' => 'total', 'value' => 'number_format($data->total,2)', 'footer' => "<h5>\$ " . number_format($model->getTotal3($model->searchSuma()), 2) . '</h5>'), array('header' => 'Fecha', 'name' => 'fecha', 'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array('language' => 'es', 'model' => $model, 'attribute' => 'fecha', 'options' => array('showAnim' => 'fold', 'language' => 'es', 'dateFormat' => 'dd-mm-yy', 'changeMonth' => true, 'changeYear' => true, 'yearRange' => '2014:2025'), 'htmlOptions' => array('id' => 'datepicker_for_fecha', 'style' => 'height:20px;width:80px;'), 'defaultOptions' => array('showOn' => 'focus', 'showOtherMonths' => true, 'selectOtherMonths' => true, 'changeMonth' => true, 'changeYear' => true, 'showButtonPanel' => true)), true), 'value' => 'Yii::app()->dateformatter->format("dd-MM-yyyy",$data[\'fecha\']);', 'htmlOptions' => array('width' => '80')), array('class' => 'CButtonColumn', 'template' => '{view}')))); Yii::app()->clientScript->registerScript('re-install-date-picker', "\nfunction reinstallDatePickerVentas(id, data) {\n //use the same parameters that you had set in your widget else the datepicker will be refreshed by default\n \$('#datepicker_for_fecha').datepicker(jQuery.extend({showMonthAfterYear:false},jQuery.datepicker.regional['es'],{'dateFormat':'dd-mm-yy'}));\n //\$('#datepicker_for_fecha').datepicker(\$.datepicker.regional[ 'es' ]);\n //\$('#datepicker_for_fecha').datepicker({dateFormat: 'dd-mm-yy'});\n}\n"); ?> <div id="exportar" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="myModalLabel">Exportar a un archivo de Excel </h3> </div> <div class="modal-body"> <p>Seleccione las opciones de Exportar</p> <form id="frmExportar" name="frmExportar" action="index.php?r=VentasDetalle/exportar&tipo=<?php $elTipo; ?> " method = "post"> <div class="span5">
public function actionActualizarInventario() { $model = InventarioPersonal::model()->findByPk($_GET['id']); //Los detalles de la Compra for ($i = 0; $i <= $_POST['variable']; $i++) { if (isset($_POST['producto_' . $i])) { $idProducto = $_POST['id_producto_' . $i]; $loteProducto = $_POST['lote_' . $i]; $existencias = InventarioPersonalDetalle::model()->find("inventario_personal_id = {$model->personal_id} and producto_id = {$idProducto} and lote = '" . $loteProducto . "'"); if ($existencias) { $existencias->cantidad = $existencias->cantidad + $_POST['cantidad_' . $i]; $existencias->update(); } else { $detalleC = new InventarioPersonalDetalle(); $detalleC->inventario_personal_id = $model->personal_id; $detalleC->producto_id = $_POST['id_producto_' . $i]; $detalleC->cantidad = $_POST['cantidad_' . $i]; $detalleC->lote = $_POST['lote_' . $i]; $detalleC->save(); } //Reducir inventario general $elProducto = ProductoInventario::model()->findByPk($_POST['id_producto_' . $i]); $elProducto->cantidad = $elProducto->cantidad - $_POST['cantidad_' . $i]; $elProducto->save(); //Reducir inventario por lote $elProducto = ProductoInventarioDetalle::model()->findByPk($_POST['producto_' . $i]); $elProducto->existencia = $elProducto->existencia - $_POST['cantidad_' . $i]; $elProducto->save(); } } $elComentario = date("d-m-Y H:m:s") . "<br>-------------------------<br>" . $_POST['InventarioPersonal']['comentario'] . "<br><br>"; $model->comentario = $elComentario . $model->comentario; $model->save(); $this->redirect(array('view', 'id' => $model->personal_id)); }
<?php /* @var $this VentasController */ /* @var $model Ventas */ /* @var $form CActiveForm */ ?> <div class="form"> <?php $form = $this->beginWidget('CActiveForm', array('id' => 'ventas-form', 'htmlOptions' => array('onsubmit' => "return validar();"), 'enableAjaxValidation' => false)); ?> <?php $losProductos = ProductoInventario::model()->findAll("cantidad > 0 and estado = 'Activo' and tipo_inventario = 'Productos' ORDER BY nombre_producto ASC"); ?> <?php echo $form->errorSummary($model); ?> <div class="row"> <div class="span6"> <div clas="row"> <div class="span6"> <?php echo $form->labelEx($model, 'paciente_id'); ?> <?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array('id' => 'paciente_id', 'name' => 'paciente_id', 'source' => $this->createUrl('pacienteBuscar/buscarPaciente'), 'options' => array('delay' => 300, 'minLength' => 2, 'showAnim' => 'fold', 'select' => "js:function(event, ui) {\n\t\t\t\t\t \$('#nombre_proveedor').val(ui.item.nombre);\n\t\t\t\t\t \$('#direccion_proveedor').val(ui.item.direccion);\n\t\t\t\t\t \$('#ciudad_proveedor').val(ui.item.ciudad);\n\t\t\t\t\t \$('#telefono_proveedor').val(ui.item.telefono);\n\t\t\t\t\t \$('#elpaciente_id').val(ui.item.paciente_id);\n\t\t\t\t\t }"), 'htmlOptions' => array('size' => '40'))); ?> </div>
<?php /* @var $this OrdenPedidoController */ /* @var $model OrdenPedido */ /* @var $form CActiveForm */ ?> <?php $losTipos = TipoOrdenPedido::model()->findAll(); $losProductos = ProductoInventario::model()->findAll("tipo_inventario='Consumibles'"); $elPersonal = Personal::model()->findAll("activo = 'SI'"); ?> <div class="form"> <div class="row"> <div class="span1"></div> <div class="span11"> <form id="Formulacion" name="Formulacion" action="index.php?r=OrdenPedido/guardarOrden" method = "post" onsubmit="onEnviar()"> <label for="">Personal que Recibe:</label> <select name='personalRecibe' id='personalRecibe' class='input-xxlarge'> <?php foreach ($elPersonal as $el_personal) { ?> <option value='<?php echo $el_personal->id; ?> '><?php echo $el_personal->nombreCompleto;
public function actionCreate() { $model = new Ventas(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Ventas'])) { //Datos de Paciente $elPaciente = Paciente::model()->findByPk($_POST['elpaciente_id']); if ($_POST['Ventas']['credito_fecha'] == "") { $fechaCredito = "0000-00-00"; } else { $fechaCredito = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['Ventas']['credito_fecha']); } if ($_POST['Ventas']['credito_fecha2'] == "") { $fechaCredito2 = "0000-00-00"; } else { $fechaCredito2 = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['Ventas']['credito_fecha2']); } $model->attributes = $_POST['Ventas']; $model->forma_pago = $_POST['Ventas']['forma_pago']; $model->descripcion = $_POST['Ventas']['descripcion']; $model->paciente_id = $_POST['elpaciente_id']; $model->n_identificacion = $elPaciente->n_identificacion; $model->credito_fecha = $fechaCredito; $model->fecha = date("Y-m-d"); $model->fecha_hora = date("Y-m-d H:i:s"); $model->estado = "Activo"; $model->personal = Yii::app()->user->usuarioId; $model->vendedor_id = $_POST['Ventas']['vendedor_id']; //Mas de una forma de pago $model->forma_pago2 = $_POST['Ventas']['forma_pago2']; $model->credito_fecha2 = $fechaCredito2; $model->total1 = $_POST['Ventas']['total1']; $model->total2 = $_POST['Ventas']['total2']; $model->credito_dias2 = $_POST['Ventas']['credito_dias2']; $model->tarjeta_tipo2 = $_POST['Ventas']['tarjeta_tipo2']; $model->tarjeta_aprobacion2 = $_POST['Ventas']['tarjeta_aprobacion2']; $model->tarjeta_entidad2 = $_POST['Ventas']['tarjeta_entidad2']; $model->tarjeta_cuenta_banco2 = $_POST['Ventas']['tarjeta_cuenta_banco2']; $model->consignacion_cuenta_banco2 = $_POST['Ventas']['consignacion_cuenta_banco2']; $model->consignacion_banco2 = $_POST['Ventas']['consignacion_banco2']; $model->consignacion_cuenta2 = $_POST['Ventas']['consignacion_cuenta2']; if ($model->save()) { //Los detalles de la Compra for ($i = 0; $i <= $_POST['variable']; $i++) { if (isset($_POST['producto_' . $i])) { $detalleC = new VentasDetalle(); $detalleC->venta_id = $model->id; $detalleC->producto_id = $_POST['producto_' . $i]; $detalleC->cantidad = $_POST['cantidad_' . $i]; $detalleC->valor = $_POST['valor_' . $i]; $detalleC->iva = $_POST['iva_' . $i]; $detalleC->total = $_POST['total_' . $i]; $detalleC->paciente_id = $model->paciente_id; $detalleC->fecha = $model->fecha; $detalleC->save(); //Aumentar inventario $elProducto = ProductoInventario::model()->findByPk($_POST['producto_' . $i]); $elProducto->cantidad = $elProducto->cantidad - $_POST['cantidad_' . $i]; $elProducto->save(); } } if ($model->forma_pago == "Cheque") { //Los detalles de la Compra for ($i = 0; $i <= $_POST['variablec']; $i++) { if (isset($_POST['numero_' . $i])) { $detalleC = new VentasCheques(); $detalleC->ingresos_id = $model->id; $detalleC->numero = $_POST['numero_' . $i]; $detalleC->entidad = $_POST['entidad_' . $i]; $detalleC->valor = $_POST['valor_' . $i]; $detalleC->f_cobro = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_cobro_' . $i]); $detalleC->save(); } } } if ($model->forma_pago == "Efectivo") { //$this->actionEnvioCorreoVenta($model->id); $laCaja = CajaEfectivo::model()->findByPk($model->personal); if ($laCaja === null) { //Nueva Caja $nuevaCaja = new CajaEfectivo(); $nuevaCaja->personal_id = $model->personal; if ($model->total2 > 0) { $nuevaCaja->total = $model->total1; } else { $nuevaCaja->total = $model->total_venta; } $nuevaCaja->save(); //Registrar Ingreso en el detalle de caja $nuevaCajaDetalle = new CajaEfectivoDetalle(); $nuevaCajaDetalle->caja_efectivo_id = $nuevaCaja->personal_id; if ($model->total2 > 0) { $nuevaCajaDetalle->monto = $model->total1; } else { $nuevaCajaDetalle->monto = $model->total_venta; } $nuevaCajaDetalle->tipo = "Venta"; $nuevaCajaDetalle->venta_id = $model->id; $nuevaCajaDetalle->fecha = date("Y-m-d H:i:s"); $nuevaCajaDetalle->save(); } else { //Actualizar Caja if ($model->total2 > 0) { $laCaja->total = $laCaja->total + $model->total1; } else { $laCaja->total = $laCaja->total + $model->total_venta; } $laCaja->save(); //Registrar Ingreso en el detalle de caja $nuevaCajaDetalle = new CajaEfectivoDetalle(); $nuevaCajaDetalle->caja_efectivo_id = $model->personal; if ($model->total2 > 0) { $nuevaCajaDetalle->monto = $model->total1; } else { $nuevaCajaDetalle->monto = $model->total_venta; } $nuevaCajaDetalle->tipo = "Venta"; $nuevaCajaDetalle->venta_id = $model->id; $nuevaCajaDetalle->fecha = date("Y-m-d H:i:s"); $nuevaCajaDetalle->save(); } } //Render de Vista $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
} ?> <h1>Buscar Productos <?php echo $subtitulo; ?> - <a href="#exportar" class="btn btn-warning" role="button" data-toggle="modal"><i class="icon-share-alt icon-white"></i> Exportar</a></h1> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'producto-inventario-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('header' => 'ID.', 'name' => 'id', 'value' => '$data->id', 'htmlOptions' => array('width' => '20')), array('header' => 'Producto', 'name' => 'id', 'filter' => CHtml::listData(ProductoInventario::model()->findAll(array('order' => 'nombre_producto ASC')), 'id', 'nombre_producto'), 'value' => '$data->nombre_producto', 'htmlOptions' => array('width' => '220')), 'producto_referencia', 'lote', 'cantidad', array('name' => 'costo_iva', 'value' => 'number_format($data->costo_iva,2)', 'htmlOptions' => array('width' => '120'), 'footer' => "<h6>\$ " . number_format($model->getTotal($model->search()), 2) . '</h6>'), array('name' => 'precio_publico', 'value' => 'number_format($data->precio_publico,2)', 'htmlOptions' => array('width' => '120'), 'footer' => "<h6>\$ " . number_format($model->getTotal2($model->search()), 2) . '</h6>'), 'iva', array('name' => 'tipo_inventario', 'filter' => array('Consumibles' => 'Consumibles', 'Insumos' => 'Insumos', 'Productos' => 'Productos'), 'value' => '$data->tipo_inventario'), array('name' => 'estado', 'filter' => array('Activo' => 'Activo', 'Inactivo' => 'Inactivo'), 'value' => '$data->estado'), array('class' => 'CButtonColumn', 'template' => '{view}{update}', 'buttons' => array('view' => array('url' => 'Yii::app()->createUrl("productoInventario/view", array("id"=>$data->id,"asDialog"=>1))', 'options' => array('ajax' => array('type' => 'POST', 'url' => "js:\$(this).attr('href')", 'update' => '#id_view')))))))); ?> <div id="id_view"></div> <!-- Ventanas Modales --> <div id="exportar" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="myModalLabel">Exportar a un archivo de Excel </h3> </div> <div class="modal-body"> <p>Seleccione las opciones de Exportar</p> <form id="frmExportar" name="frmExportar" action="index.php?r=ProductoInventario/exportar&tipo=<?php echo $elTipo; ?>
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return ProductoInventario the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ProductoInventario::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }