Example #1
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->form = new IngresoInventarioForm();
     if ($request->isMethod('POST')) {
         $this->form->bind($request->getParameter('ingreso_inventario'));
         if ($this->form->isValid()) {
             $valores = $this->form->getValues();
             $BitacoraCambios = new BitacoraCambios();
             $BitacoraCambios->setModelo('Inventario');
             $Producto = ProductoQuery::create()->findOneById($valores['Producto']);
             $BitacoraCambios->setDescripcion('Ingreso de Inventario de Producto: ' . $Producto->getDescripcion() . ' con cantidad ' . $valores['Cantidad']);
             $BitacoraCambios->setIp($request->getRemoteAddress());
             $Usuario = UsuarioQuery::create()->findOneById(sfContext::getInstance()->getUser()->getAttribute('usuario', null, 'seguridad'));
             if ($Usuario) {
                 $BitacoraCambios->setCreatedBy($Usuario->getUsuario());
             }
             $Movimiento = new Movimiento();
             $Movimiento->setTipoMovimiento('+');
             $Movimiento->setProveedorId($valores['Proveedor']);
             $Movimiento->setProductoId($Producto->getId());
             $Movimiento->setCantidad($valores['Cantidad']);
             $Movimiento->setPrecio($valores['Precio']);
             $Movimiento->save();
             $BitacoraCambios->save();
             $Comprobacion = InventarioQuery::create()->filterByProductoId($valores['Producto'])->filterByProveedorId($valores['Proveedor'])->findOne();
             if ($Comprobacion) {
                 $Comprobacion->setCantidad($Comprobacion->getCantidad() + $valores['Cantidad']);
                 $anterior = $Comprobacion->getCantidad() * $Comprobacion->getPrecioCompra();
                 $actual = $valores['Cantidad'] * $valores['Precio'];
                 $suma = ($anterior + $actual) / ($valores['Cantidad'] + $Comprobacion->getCantidad());
                 $Comprobacion->setPrecioCompra($suma);
                 $Comprobacion->save();
             } else {
                 $Inventario = new Inventario();
                 $Inventario->setPrecioCompra($valores['Precio']);
                 $Inventario->setProductoId($valores['Producto']);
                 $Inventario->setProveedorId($valores['Proveedor']);
                 $Inventario->setCantidad($valores['Cantidad']);
                 $Inventario->save();
             }
             $this->redirect('inventario/index');
         }
     }
     $this->cinco = InventarioQuery::create()->orderById('DESC')->limit(5)->find();
 }
Example #2
0
 public function executeEntregado(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     $BitacoraCambios = new BitacoraCambios();
     $BitacoraCambios->setModelo('Pedido Proveedores');
     $Usuario = UsuarioQuery::create()->findOneById(sfContext::getInstance()->getUser()->getAttribute('usuario', null, 'seguridad'));
     $BitacoraCambios->setDescripcion('Cambio de estado de Pedido a Proveedor  a Entregado con id : ' . $id . ' el usuario ' . $Usuario->getNombre());
     $BitacoraCambios->setIp($request->getRemoteAddress());
     $pedido = PedidoProveedorQuery::create()->findOneById($id);
     $pedido->setEstado('Entregado');
     $pedido->save();
     $detalle_pedido = DetallePedidoProveedorQuery::create()->filterByPedidoProveedor($pedido)->find();
     foreach ($detalle_pedido as $det) {
         $Comprobacion = InventarioQuery::create()->filterByProductoId($det->getProductoId())->filterByProveedorId($pedido->getProveedorId())->findOne();
         if ($Comprobacion) {
             $Comprobacion->setCantidad($Comprobacion->getCantidad() + $det->getCantidad());
             $anterior = $det->getCantidad() * $Comprobacion->getPrecioCompra();
             $actual = $det->getCantidad() * $det->getPrecio();
             $suma = ($anterior + $actual) / ($det->getCantidad() + $Comprobacion->getCantidad());
             $Comprobacion->setPrecioCompra($suma);
             $Comprobacion->save();
         } else {
             $Inventario = new Inventario();
             $Inventario->setPrecioCompra($det->getPrecio());
             $Inventario->setProductoId($det->getProductoId());
             $Inventario->setProveedorId($pedido->getProveedorId());
             $Inventario->setCantidad($det->getCantidad());
             $Inventario->save();
         }
         $Movimiento = new Movimiento();
         $Movimiento->setTipoMovimiento('+');
         $Movimiento->setProveedorId($pedido->getProveedorId());
         $Movimiento->setProductoId($det->getProductoId());
         $Movimiento->setCantidad($det->getCantidad());
         $Movimiento->setPrecio($det->getPrecio());
         $Movimiento->save();
     }
     $this->redirect('pedido_proveedor/index');
 }
 public function actionCreate()
 {
     $cuenta_id = $_POST['cuenta'];
     $fecha = $_POST['fecha'];
     $monto = $_POST['monto'];
     $detalle = $_POST['detalle'];
     $tipo = $_POST['tipo'];
     $forma_pago_id = -1;
     if (isset($_POST['formaPago'])) {
         $forma_pago_id = $_POST['formaPago'];
     }
     $model = new Movimiento();
     $model->fecha = $fecha;
     $model->monto = $monto;
     $model->detalle = $detalle;
     $model->tipo = $tipo;
     if ($model->tipo == Tools::MOVIMIENTO_TIPO_CARGO) {
         $model->validado = 1;
     } else {
         $model->validado = 0;
         $model->forma_pago_id = $forma_pago_id;
     }
     $model->cuenta_corriente_id = $cuenta_id;
     $cuenta = CuentaCorriente::model()->findByPk($cuenta_id);
     if ($cuenta == null) {
         echo -1;
         die;
     } else {
         if ($cuenta->estaAsociadoPropietario(Yii::app()->user->id)) {
             $anterior = $model->findAllByAttributes(array('fecha' => $model->fecha, 'tipo' => $model->tipo, 'monto' => $model->monto, 'detalle' => $model->detalle, 'cuenta_corriente_id' => $model->cuenta_corriente_id));
             if (count($anterior) == 0) {
                 $model->saldo_cuenta = $model->cuentaCorriente->saldoAFecha($model->fecha);
                 if ($model->save()) {
                     if ($model->validado) {
                         if ($model->tipo == Tools::MOVIMIENTO_TIPO_ABONO) {
                             $model->actualizaSaldosPosteriores($model->monto);
                         } else {
                             $model->actualizaSaldosPosteriores(-$model->monto);
                         }
                     } else {
                         $model->actualizaSaldosPosteriores(0);
                     }
                     echo $model->id;
                 } else {
                     echo CHtml::errorSummary($model);
                 }
             } else {
                 echo -1;
             }
             die;
         } else {
             echo -1;
             die;
         }
     }
 }
Example #4
0
 public function crearDeudaMes($fechaHoy)
 {
     //para saber cuánto tiene que pagar, tengo que consultar su debe pagar actual
     $debePagars = DebePagar::model()->findAllByAttributes(array('contrato_id' => $this->id), array('order' => 'id DESC'));
     $debePagar = null;
     $cta_id = $this->cuentaCorriente->id;
     if (count($debePagars) > 0) {
         $debePagar = $debePagars[0];
         //si ya se ha pagado otros meses, o sea no es un contrato nuevo
         //se debe crear un movimiento de cargo por cada pago que se deba efectuar al contrato
         //este arreglo sirve por si se cae algún grabar borrar todos los que habían sido guardados
         $idGuardados = array();
         //deuda de renta
         if ($this->monto_renta > 0) {
             $movimiento = new Movimiento();
             $movimiento->fecha = $fechaHoy;
             $movimiento->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
             $movimiento->monto = $debePagar->monto_renta;
             $movimiento->detalle = "Monto de Renta";
             $movimiento->validado = 1;
             $movimiento->cuenta_corriente_id = $cta_id;
             if ($movimiento->save()) {
                 $movimiento->actualizaSaldosPosteriores(-$movimiento->monto);
                 $idGuardados[] = $movimiento->id;
             } else {
                 foreach ($idGuardados as $idGuardado) {
                     $movGuardado = Movimiento::model()->findByPk($idGuardado);
                     $movGuardado->delete();
                 }
                 var_dump(CHtml::errorSummary($movimiento));
                 return;
             }
         }
         //deuda de gasto común
         if ($this->monto_gastocomun > 0) {
             $movimiento = new Movimiento();
             $movimiento->fecha = $fechaHoy;
             $movimiento->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
             $movimiento->monto = $debePagar->monto_gastocomun;
             $movimiento->detalle = "Monto de Gasto Común";
             $movimiento->validado = 1;
             $movimiento->cuenta_corriente_id = $cta_id;
             if ($movimiento->save()) {
                 $movimiento->actualizaSaldosPosteriores(-$movimiento->monto);
                 $idGuardados[] = $movimiento->id;
             } else {
                 foreach ($idGuardados as $idGuardado) {
                     $movGuardado = Movimiento::model()->findByPk($idGuardado);
                     $movGuardado->delete();
                 }
                 var_dump(CHtml::errorSummary($movimiento));
                 return;
             }
         }
         //deuda de mueble
         if ($this->monto_mueble > 0) {
             $movimiento = new Movimiento();
             $movimiento->fecha = $fechaHoy;
             $movimiento->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
             $movimiento->monto = $debePagar->monto_mueble;
             $movimiento->detalle = "Monto por Muebles";
             $movimiento->validado = 1;
             $movimiento->cuenta_corriente_id = $cta_id;
             if ($movimiento->save()) {
                 $movimiento->actualizaSaldosPosteriores(-$movimiento->monto);
                 $idGuardados[] = $movimiento->id;
             } else {
                 foreach ($idGuardados as $idGuardado) {
                     $movGuardado = Movimiento::model()->findByPk($idGuardado);
                     $movGuardado->delete();
                 }
                 var_dump(CHtml::errorSummary($movimiento));
                 return;
             }
         }
         //deuda de gasto variable
         if ($this->monto_gastovariable > 0) {
             $movimiento = new Movimiento();
             $movimiento->fecha = $fechaHoy;
             $movimiento->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
             $movimiento->monto = $debePagar->monto_gastovariable;
             $movimiento->detalle = "Monto de Gasto Variable";
             $movimiento->validado = 1;
             $movimiento->cuenta_corriente_id = $cta_id;
             if ($movimiento->save()) {
                 $movimiento->actualizaSaldosPosteriores(-$movimiento->monto);
                 $idGuardados[] = $movimiento->id;
             } else {
                 foreach ($idGuardados as $idGuardado) {
                     $movGuardado = Movimiento::model()->findByPk($idGuardado);
                     $movGuardado->delete();
                 }
                 var_dump(CHtml::errorSummary($movimiento));
                 return;
             }
         }
     } else {
         $debeNuevo = new DebePagar();
         $debeNuevo->agno = date("Y");
         $debeNuevo->mes = date("m");
         $debeNuevo->dia = $this->dia_pago;
         $debeNuevo->contrato_id = $this->id;
         //ahora hay que reajustar los montos del contrato dependiendo del ipc_acumulado
         //el precio base debe ser el valor anterior en debe pagar
         $debeNuevo->monto_gastocomun = $this->monto_gastocomun;
         $debeNuevo->monto_gastovariable = $this->monto_gastovariable;
         $debeNuevo->monto_mueble = $this->monto_mueble;
         $debeNuevo->monto_renta = $this->monto_renta;
         $debeNuevo->save();
         $movimiento = new Movimiento();
         $movimiento->fecha = $fechaHoy;
         $movimiento->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
         $movimiento->monto = $this->monto_primer_mes;
         $movimiento->detalle = Tools::DETALLE_PRIMER_CARGO;
         $movimiento->validado = 1;
         $movimiento->cuenta_corriente_id = $cta_id;
         $movimiento->saldo_cuenta = $movimiento->cuentaCorriente->saldo_inicial - $movimiento->monto;
         $movimiento->save();
     }
 }
Example #5
0
 public function executeConfirmar(sfWebRequest $request)
 {
     $Factura = FacturaQuery::create()->findOneById($request->getParameter('id'));
     $Detalles = FacturaDetalleQuery::create()->findByFacturaId($request->getParameter('id'));
     if (sizeof($Detalles) == 0) {
         $this->getUser()->setFlash('error', 'No existen productos ingresados en esta factura.');
         $this->redirect('venta/detalle?id=' . $request->getParameter('id'));
     }
     if ($Factura->getActivo()) {
         foreach ($Detalles as $detalle) {
             $fecha = date("d/m/Y");
             $Promocion = PromocionQuery::create()->filterByProductoId($detalle->getProductoId())->where("fecha_inicio <= '{$fecha}' and fecha_fin >= '{$fecha}'")->findOne();
             $descuento = 1;
             if ($Promocion) {
                 $descuento = 1 - $Promocion->getDescuento() / 100;
             }
             $Movimiento = new Movimiento();
             $Movimiento->setTipoMovimiento('-');
             $Movimiento->setClienteId($Factura->getClienteId());
             $Movimiento->setProductoId($detalle->getProductoId());
             $Movimiento->setCantidad($detalle->getCantidad());
             $Movimiento->setProveedorId($detalle->getProveedorId());
             $Movimiento->setPrecio($detalle->getPrecioUnitario() * $descuento);
             $Movimiento->setFecha(date('Y-m-d'));
             $Movimiento->save();
         }
         $BitacoraCambios = new BitacoraCambios();
         $BitacoraCambios->setModelo('Factura');
         $BitacoraCambios->setIp(sfContext::getInstance()->getRequest()->getRemoteAddress());
         $BitacoraCambios->setDescripcion('Creacion de Factura con id: ' . sprintf("%05d", $Factura->getId()));
         $Usuario = UsuarioQuery::create()->findOneById(sfContext::getInstance()->getUser()->getAttribute('usuario', null, 'seguridad'));
         if ($Usuario) {
             $Factura->setCreatedBy($Usuario->getUsuario());
             $BitacoraCambios->setCreatedBy($Usuario->getUsuario());
         }
         $BitacoraCambios->save();
         $Cliente = ClienteQuery::create()->findOneById($Factura->getClienteId());
         if (Factura::obtenerTotal($request->getParameter('id')) >= 200) {
             $Cliente->setPuntos($Cliente->getPuntos() + 10);
             $Cliente->save();
         }
     }
     $Factura->setActivo(false);
     $Factura->save();
     $pdf = new sfTCPDF("P", "mm", "Letter");
     $this->id = $request->getParameter("id");
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('SALUD_INTEGRAL');
     $pdf->SetTitle('Factura');
     $pdf->SetSubject('Factura');
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetHeaderMargin(0.1);
     $pdf->SetFooterMargin(0.1);
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     $pdf->SetFont('dejavusans', '', 7);
     $pdf->AddPage();
     $html = '';
     $detalles = FacturaDetalleQuery::create()->findByFacturaId($Factura->getId());
     $html = $this->getPartial('venta/soporteTabla', array("factura" => $Factura, "detalles" => $detalles));
     $pdf->writeHTML($html);
     $pdf->Output('Factura.pdf', 'D');
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $model->fecha = Tools::backFecha($model->fecha);
     $deptos = new Departamento('search');
     $deptos->unsetAttributes();
     if (isset($_GET['Departamento'])) {
         $deptos->attributes = $_GET['Departamento'];
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Prestacion'])) {
         $model->attributes = $_POST['Prestacion'];
         $model->fecha = Tools::fixFecha($model->fecha);
         if ($model->save()) {
             $movimientosPrestacion = PrestacionGeneraMovimiento::model()->findAllByAttributes(array('prestacion_id' => $model->id));
             foreach ($movimientosPrestacion as $mov) {
                 $movimiento = $mov->movimiento;
                 if ($movimiento->tipo == Tools::MOVIMIENTO_TIPO_CARGO) {
                     $movimiento->actualizaSaldosPosteriores($movimiento->monto);
                 }
                 $mov->delete();
                 $movimiento->delete();
             }
             PrestacionADepartamento::model()->deleteAllByAttributes(array('prestacion_id' => $model->id));
             if (isset($_POST['chbDepartamentoId']) && !$model->general_prop) {
                 $cant_deptos = count($_POST['chbDepartamentoId']);
                 if ($cant_deptos != 0) {
                     $monto = (int) $model->monto / $cant_deptos;
                 }
                 foreach ($_POST['chbDepartamentoId'] as $i => $departamento) {
                     $prest_depto = new PrestacionADepartamento();
                     $prest_depto->departamento_id = $departamento;
                     $prest_depto->prestacion_id = $model->id;
                     if ($prest_depto->validate()) {
                         $prest_depto->save();
                     }
                     if ($model->genera_cargos == "1") {
                         $cargo = new Movimiento();
                         $contrato = Contrato::model()->findByAttributes(array('departamento_id' => $departamento, 'vigente' => 1));
                         if ($contrato != null) {
                             if ($contrato->vigente) {
                                 $cargo->cuenta_corriente_id = $contrato->cuentaCorriente->id;
                             } else {
                                 continue;
                             }
                         } else {
                             continue;
                         }
                         $cargo->fecha = $model->fecha;
                         $cargo->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
                         $cargo->monto = $monto;
                         $cargo->detalle = "PRESTACIÓN REALIZADA: " . $model->descripcion;
                         $cargo->validado = 1;
                         $cargo->saldo_cuenta = $cargo->ultimoSaldo();
                         $cargo->save();
                         $cargo->actualizaSaldosPosteriores(-$monto);
                         $prestacionMovimiento = new PrestacionGeneraMovimiento();
                         $prestacionMovimiento->prestacion_id = $model->id;
                         $prestacionMovimiento->movimiento_id = $cargo->id;
                         $prestacionMovimiento->save();
                     }
                 }
             }
             if ($model->general_prop) {
                 if ($model->genera_cargos == "1") {
                     //se crean los cargos para los deptos
                     $departamentos = Departamento::model()->getVigentesDePropiedad($model->propiedad_id);
                     $cant_deptos = count($departamentos);
                     if ($cant_deptos != 0) {
                         $monto = (int) $model->monto / $cant_deptos;
                         foreach ($departamentos as $depto) {
                             $cargo = new Movimiento();
                             if ($depto->contrato != null) {
                                 if ($depto->contrato->vigente) {
                                     $cargo->cuenta_corriente_id = $depto->contrato->cuentaCorriente->id;
                                 } else {
                                     continue;
                                 }
                             } else {
                                 continue;
                             }
                             $cargo->fecha = $model->fecha;
                             $cargo->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
                             $cargo->monto = $monto;
                             $cargo->detalle = "PRESTACIÓN REALIZADA: " . $model->descripcion;
                             $cargo->validado = 1;
                             $cargo->saldo_cuenta = $cargo->ultimoSaldo();
                             $cargo->save();
                             $cargo->actualizaSaldosPosteriores(-$monto);
                             $prestacionMovimiento = new PrestacionGeneraMovimiento();
                             $prestacionMovimiento->prestacion_id = $model->id;
                             $prestacionMovimiento->movimiento_id = $cargo->id;
                             $prestacionMovimiento->save();
                         }
                     }
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model, 'departamentos' => $deptos));
 }