/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new ProductoCompras();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['ProductoCompras'])) {
         //Buscar Proveedor
         $elProveedor = ProductoProveedor::model()->findByPk($_POST['ProductoCompras']['producto_proveedor_id']);
         $model->attributes = $_POST['ProductoCompras'];
         $model->nit = $elProveedor->doc_nit;
         $model->fecha = date("Y-m-d H:i:s");
         $model->fecha_sola = date("Y-m-d");
         $model->estado = "Activo";
         if ($_POST['ProductoCompras']['forma_pago'] == "Crédito") {
             $model->saldo = $_POST['ProductoCompras']['total_compra'];
         }
         $model->personal_id = Yii::app()->user->usuarioId;
         if ($model->save()) {
             //Los detalles de la Compra
             for ($i = 0; $i <= $_POST['variable']; $i++) {
                 if (isset($_POST['producto_' . $i])) {
                     $detalleC = new ProductoCompraDetalle();
                     $detalleC->producto_compra_id = $model->id;
                     $detalleC->producto_id = $_POST['producto_' . $i];
                     $detalleC->cantidad = $_POST['cantidad_' . $i];
                     $detalleC->lote = $_POST['lote_' . $i];
                     if ($_POST['vence_' . $i] == "") {
                         $detalleC->fecha_vencimiento = "0000-00-00";
                     } else {
                         $detalleC->fecha_vencimiento = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['vence_' . $i]);
                     }
                     $detalleC->valor = $_POST['valor_' . $i];
                     $detalleC->iva = $_POST['iva_' . $i];
                     $detalleC->total = $_POST['total_' . $i];
                     $detalleC->save();
                     //Aumentar inventario
                     $elProducto = ProductoInventario::model()->findByPk($_POST['producto_' . $i]);
                     $elProducto->cantidad = $elProducto->cantidad + $_POST['cantidad_' . $i];
                     $elProducto->costo_iva = $_POST['valor_' . $i];
                     if ($elProducto->save()) {
                         //Guardar detalle del inventario //Lotes **Quitar***
                         $elProductoD = new ProductoInventarioDetalle();
                         $elProductoD->producto_inventario_id = $_POST['producto_' . $i];
                         $elProductoD->lote = $_POST['lote_' . $i];
                         $elProductoD->cantidad_compra = $_POST['cantidad_' . $i];
                         $elProductoD->existencia = $_POST['cantidad_' . $i];
                         $elProductoD->compra_id = $model->id;
                         $elProductoD->save();
                     }
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->layout = 'main';
     $this->render('create', array('model' => $model));
 }
 public function actionCreate()
 {
     $model = new Egresos();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Egresos'])) {
         //Buscar Proveedores
         $datosProveedor = ProductoProveedor::model()->findByPk($_POST['id_proveedor']);
         $model->attributes = $_POST['Egresos'];
         $model->observaciones = $_POST['Egresos']['observaciones'];
         $model->proveedor_id = $_POST['id_proveedor'];
         $model->n_identificacion = $datosProveedor->doc_nit;
         $model->aplica_factura = $_POST['Egresos']['aplica_factura'];
         $model->fecha = date("Y-m-d H:i:s");
         $model->fecha_sola = date("Y-m-d");
         $model->personal_id = Yii::app()->user->usuarioId;
         $model->estado = "Activo";
         if ($model->save()) {
             if ($model->forma_pago == "Efectivo") {
                 //Para envio de correos
                 $this->actionEnvioCorreoEgresos($model->id);
                 //Afectar Caja
                 $datosCaja = CajaEfectivo::model()->findByPk(Yii::app()->user->usuarioId);
                 $datosCaja->total = $datosCaja->total - $model->valor_egreso;
                 $datosCaja->update();
                 //Registrar Ingreso en el detalle de caja
                 $nuevaCajaDetalle = new CajaEfectivoDetalle();
                 $nuevaCajaDetalle->caja_efectivo_id = $datosCaja->personal_id;
                 $nuevaCajaDetalle->monto = $model->valor_egreso * -1;
                 $nuevaCajaDetalle->tipo = "Egreso";
                 $nuevaCajaDetalle->egreso_id = $model->id;
                 $nuevaCajaDetalle->fecha = date("Y-m-d H:i:s");
                 $nuevaCajaDetalle->save();
                 if ($model->aplica_factura == "Si") {
                     $laCompra = ProductoCompras::model()->findByPk($model->factura_id);
                     $laCompra->saldo = $laCompra->saldo - $model->valor_egreso;
                     $laCompra->save();
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #3
0
			<?php 
echo $form->textField($model, 'stock_minimo', array('class' => 'input-mini'));
?>
			<?php 
echo $form->error($model, 'stock_minimo');
?>
		</div>
	</div>

	<div class="row">
		<div class="span4">
			<?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'"), 'id', 'nombre'), array('class' => 'input-xlarge'));
?>
			<?php 
echo $form->error($model, 'producto_proveedor_id');
?>
		</div>

		<div class="span4">
			<?php 
echo $form->labelEx($model, 'tipo_inventario');
?>
			<?php 
echo $form->dropDownList($model, 'tipo_inventario', array('Productos' => 'Productos', 'Insumos' => 'Insumos', 'Consumibles' => 'Consumibles'));
?>
	
			<?php 
 /**
  * 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 ProductoProveedor the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = ProductoProveedor::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #5
0
/* @var $this ProductoComprasController */
/* @var $model ProductoCompras */
$this->menu = array(array('label' => 'Crear Compra', 'url' => array('create')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$('#producto-compras-grid').yiiGridView('update', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<h1>Buscar Compras 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>

<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-compras-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('header' => 'ID.', 'name' => 'id', 'value' => '$data->id', 'htmlOptions' => array('width' => '30')), array('header' => 'Proveedor', 'name' => 'producto_proveedor_id', 'filter' => CHtml::listData(ProductoProveedor::model()->findAll(array('order' => 'nombre ASC')), 'id', 'nombre'), 'value' => '$data[\'productoProveedor\'][\'nombre\']', 'htmlOptions' => array('width' => '220')), array('name' => 'nit', 'value' => '$data->nit', 'htmlOptions' => array('width' => '100')), 'factura_n', 'forma_pago', array('name' => 'total_compra', 'value' => 'number_format($data->total_compra,2)', 'footer' => "<h6>\$ " . number_format($model->getTotal($model->search()), 2) . '</h6>'), 'fecha', array('header' => 'Realizado por:', 'name' => 'personal_id', 'filter' => CHtml::listData(Personal::model()->findAll(array('order' => 'nombres ASC', 'condition' => "activo = 'SI'")), 'id', 'nombreCompleto'), 'value' => '$data->personal->nombreCompleto', 'htmlOptions' => array('width' => '180')), array('name' => 'estado', 'filter' => array('Activo' => 'Activo', 'Anulada' => 'Anulada'), 'value' => '$data->estado'), array('class' => 'CButtonColumn', 'template' => '{view}'))));
?>

<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=productoCompras/exportar&tipo=<?php 
$elTipo;
?>
" method = "post">
  		<div class="span5">
			<label>Filtro:</label>
Example #6
0
/* @var $this ProductoComprasController */
/* @var $model ProductoCompras */
$this->menu = array();
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$('#producto-compras-grid').yiiGridView('update', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<h1>Cuentas por Pagar - <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' => 'cxp-grid', 'dataProvider' => $model->search(), 'afterAjaxUpdate' => 'reinstallDatePickerCxp', 'filter' => $model, 'columns' => array(array('header' => 'ID.', 'name' => 'id', 'value' => '$data->id', 'htmlOptions' => array('width' => '30')), array('header' => 'Proveedor', 'name' => 'producto_proveedor_id', 'filter' => CHtml::listData(ProductoProveedor::model()->findAll(array('order' => 'nombre ASC')), 'id', 'nombre'), 'value' => '$data[\'productoProveedor\'][\'nombre\']', 'htmlOptions' => array('width' => '220')), 'factura_n', array('header' => 'Total de Compra', 'name' => 'total_compra', 'value' => 'number_format($data->total_compra,2)', 'htmlOptions' => array('width' => '120'), 'footer' => $model->search()->itemCount === 0 ? '' : "<h5>\$ " . number_format($model->getTotal($model->search()), 2) . '</h5>'), 'forma_pago', array('header' => 'Término (días)', 'name' => 'credito_dias', 'value' => '$data->credito_dias', 'htmlOptions' => array('width' => '60')), array('header' => 'Saldo', 'name' => 'saldo', 'value' => 'number_format($data->saldo,2)', 'htmlOptions' => array('width' => '120'), 'footer' => $model->search()->itemCount === 0 ? '' : "<h5>\$ " . number_format($model->getTotal2($model->search()), 2) . '</h5>'), array('header' => 'Fecha', 'name' => 'fecha_sola', 'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array('language' => 'es', 'model' => $model, 'attribute' => 'fecha_sola', '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_sola\']);', 'htmlOptions' => array('width' => '80')), 'credito_fecha', array('header' => 'Estado', 'name' => 'estado', 'filter' => array('Activo' => 'Activo', 'Cancelada' => 'Cancelada', 'Pagada' => 'Pagada'), 'value' => '$data->estado', 'htmlOptions' => array('width' => '60')), array('class' => 'CButtonColumn', 'template' => '{view}{update}'))));
Yii::app()->clientScript->registerScript('re-install-date-picker', "\nfunction reinstallDatePickerCxp(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");
?>


<!-- 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=productoCompras/exportarCxp&idCompra=<?php 
echo $model->id;
?>
Example #7
0
/* @var $this ProductoComprasController */
/* @var $model ProductoCompras */
$this->menu = array();
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$('#producto-compras-grid').yiiGridView('update', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<h1>Cuentas por Pagar Pagadas - <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' => 'cxp-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('header' => 'ID.', 'name' => 'id', 'value' => '$data->id', 'htmlOptions' => array('width' => '30')), array('header' => 'Proveedor', 'name' => 'producto_proveedor_id', 'filter' => CHtml::listData(ProductoProveedor::model()->findAll(array('order' => 'nombre ASC')), 'id', 'nombre'), 'value' => '$data[\'productoProveedor\'][\'nombre\']', 'htmlOptions' => array('width' => '220')), 'factura_n', array('header' => 'Total de Compra', 'name' => 'total_compra', 'value' => 'number_format($data->total_compra,2)', 'htmlOptions' => array('width' => '120'), 'footer' => $model->search()->itemCount === 0 ? '' : "<h5>\$ " . number_format($model->getTotal($model->search()), 2) . '</h5>'), 'forma_pago', array('header' => 'Término (días)', 'name' => 'credito_dias', 'value' => '$data->credito_dias', 'htmlOptions' => array('width' => '60')), array('header' => 'Saldo', 'name' => 'saldo', 'value' => 'number_format($data->saldo,2)', 'htmlOptions' => array('width' => '120'), 'footer' => $model->search()->itemCount === 0 ? '' : "<h5>\$ " . number_format($model->getTotal2($model->search()), 2) . '</h5>'), 'fecha', 'credito_fecha', array('header' => 'Estado', 'name' => 'estado', 'filter' => array('Activo' => 'Activo', 'Pagada' => 'Pagada', 'Cancelada' => 'Cancelada'), 'value' => '$data->estado', 'htmlOptions' => array('width' => '60')), array('class' => 'CButtonColumn', 'template' => '{view}{update}'))));
?>


<!-- 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=productoCompras/exportarCxp&idCompra=<?php 
echo $model->id;
?>
" method = "post">