Пример #1
0
 public frmPagar(int id, double valor = 0)
 {
     InitializeComponent();
     empeño   = _context.Empenos.Find(id);
     empeñoId = id;
     if (valor > 0)
     {
         valorInteres = valor;
     }
 }
Пример #2
0
        public async Task PrintAbono(Empeno empeno, Pago pago)
        {
            try
            {
                var configuracion = await _context.Configuraciones.FirstOrDefaultAsync();

                Microsoft.Office.Interop.Excel.Application cexcel = new Microsoft.Office.Interop.Excel.Application();
                string pathch = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
                pathch = $"{pathch}\\Empeños\\Comprobantes\\ComprobanteAbono.xlsx";
                cexcel.Workbooks.Open(pathch, true, true);

                cexcel.Visible = false;
                var usuario = await _context.Empleados.FindAsync(Program.EmpleadoId);

                cexcel.Visible           = false;
                cexcel.Cells[3, 1].value = configuracion.Compañia;
                cexcel.Cells[4, 1].value = configuracion.Direccion;
                cexcel.Cells[5, 1].value = "Tel. " + configuracion.Telefono;
                cexcel.Cells[6, 1].value = configuracion.Nombre;
                cexcel.Cells[7, 1].value = "Cédula: " + configuracion.Identificacion;

                cexcel.Cells[8, 2].value  = pago.Consecutivo;
                cexcel.Cells[9, 2].value  = usuario.Nombre;
                cexcel.Cells[10, 2].value = usuario.Usuario;
                cexcel.Cells[14, 2].value = empeno.Cliente.Identificacion;
                cexcel.Cells[15, 1].value = empeno.Cliente.Nombre;
                cexcel.Cells[16, 2].value = pago.Fecha.ToString("dd/MM/yyyy");
                cexcel.Cells[17, 2].value = empeno.EmpenoId.ToString();

                if (empeno.EsOro)
                {
                    cexcel.Cells[19, 1].value = "ORO : " + empeno.Descripcion;
                }
                else
                {
                    cexcel.Cells[19, 1].value = empeno.Descripcion;
                }
                cexcel.Cells[23, 3].value = txtMontoAPagar.Text;
                cexcel.Cells[24, 3].value = txtPagaMonto.Text;
                cexcel.Cells[25, 3].value = txtAdeudaMonto.Text;
                cexcel.Cells[27, 3].value = txtPagaMonto.Text;
                cexcel.Cells[29, 3].value = empeno.FechaVencimiento.ToString("dd/MM/yyyy");
                cexcel.Cells[31, 3].value = empeno.Estado.ToString();
                cexcel.ActiveWindow.SelectedSheets.PrintOut();
                System.Threading.Thread.Sleep(300);
                cexcel.ActiveWorkbook.Close(false);
                cexcel.Quit();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error al imprimir la factura, es probable que el Microsoft Excel Office esta desactivado, por favor contacte con Soporte Técnico", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        public async Task SendMail(string to, string subject, string body, Empeno empeño)
        {
            var cliente       = _context.Clientes.Find(empeño.ClienteId);
            var empleado      = _context.Empleados.Find(empeño.EmpleadoId);
            var interes       = _context.Interes.Find(empeño.InteresId);
            var configuracion = _context.Configuraciones.FirstOrDefault();

            var str = "Estimado " + cliente.Nombre + ", <br /><br />"
                      + body
                      + "<b>Fecha</b> : " + empeño.Fecha.ToString("dd/MM/yyyy") + "<br />"
                      + "<b>Realizado por</b>  : " + empleado.Nombre + "<br />"
                      + "<b>Monto del Empeño</b> : " + empeño.Monto.ToString("N2") + "<br />"
                      + "<b>Interes Mensual</b> : " + (empeño.Monto * ((double)interes.Porcentaje / 100)).ToString("N2") + "<br />"
                      + "<b>Estado</b> : " + empeño.Estado.ToString() + "<br />"
                      + "<b>Fecha de Vencimiento</b> : " + empeño.FechaVencimiento.ToString("dd/MM/yyyy")
                      + "<br /><br />Saludos.";

            await SendMail(to, subject, str);
        }
Пример #4
0
        public async Task PrintVencido(Empeno objempeño, Vencimientos vencimientos)
        {
            var configuracion = await _context.Configuraciones.FirstOrDefaultAsync();

            Microsoft.Office.Interop.Excel.Application cexcel = new Microsoft.Office.Interop.Excel.Application();
            string pathch = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            pathch = $"{pathch}\\Empeños\\Comprobantes\\ComprobanteVencimiento.xlsx";
            cexcel.Workbooks.Open(pathch, true, true);

            var empleado = await _context.Empleados.FindAsync(Program.EmpleadoId);

            cexcel.Visible           = false;
            cexcel.Visible           = false;
            cexcel.Cells[2, 1].value = configuracion.Compañia;
            cexcel.Cells[3, 1].value = configuracion.Direccion;
            cexcel.Cells[4, 1].value = "Tel. " + configuracion.Telefono;
            cexcel.Cells[5, 1].value = configuracion.Nombre;
            cexcel.Cells[6, 1].value = "Cédula: " + configuracion.Identificacion;

            cexcel.Cells[7, 2].value  = vencimientos.Consecutivo;
            cexcel.Cells[8, 2].value  = empleado.Nombre;
            cexcel.Cells[9, 2].value  = empleado.Usuario;
            cexcel.Cells[13, 2].value = objempeño.Cliente.Identificacion;
            cexcel.Cells[14, 1].value = objempeño.Cliente.Nombre;

            cexcel.Cells[15, 2].value = vencimientos.Fecha.ToString("dd/MM/yyyy");
            cexcel.Cells[16, 2].value = objempeño.EmpenoId;

            cexcel.Cells[18, 1].value = objempeño.Descripcion;


            cexcel.Cells[23, 3].value = objempeño.MontoPendiente;

            cexcel.Cells[25, 3].value = "Vencido";
            cexcel.ActiveWindow.SelectedSheets.PrintOut();
            System.Threading.Thread.Sleep(300);
            cexcel.ActiveWorkbook.Close(false);
            cexcel.Quit();
        }
Пример #5
0
        public async Task PrintInteres(Empeno empeno, List <Intereses> intereses, Pago pago)
        {
            try
            {
                var configuracion = await _context.Configuraciones.FirstOrDefaultAsync();

                Microsoft.Office.Interop.Excel.Application cexcel = new Microsoft.Office.Interop.Excel.Application();
                string pathch = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
                pathch = $"{pathch}\\Empeños\\Comprobantes\\ComprobanteInteres.xlsx";
                cexcel.Workbooks.Open(pathch, true, true);

                cexcel.Visible           = false;
                cexcel.Cells[3, 1].value = configuracion.Compañia;
                cexcel.Cells[4, 1].value = configuracion.Direccion;
                cexcel.Cells[5, 1].value = "Tel. " + configuracion.Telefono;
                cexcel.Cells[6, 1].value = configuracion.Nombre;
                cexcel.Cells[7, 1].value = "Cédula: " + configuracion.Identificacion;

                var empleado = await _context.Empleados.FindAsync(Program.EmpleadoId);

                cexcel.Cells[8, 2].value  = pago.Consecutivo;
                cexcel.Cells[9, 2].value  = empleado.Nombre;
                cexcel.Cells[10, 2].value = empleado.Usuario;
                cexcel.Cells[14, 2].value = empeno.Cliente.Identificacion;
                cexcel.Cells[15, 1].value = empeno.Cliente.Nombre;
                cexcel.Cells[16, 2].value = pago.Fecha.ToString("dd/MM/yyyy");
                cexcel.Cells[17, 2].value = empeno.EmpenoId.ToString();

                if (empeno.EsOro)
                {
                    cexcel.Cells[19, 1].value = "ORO : " + empeno.Descripcion;
                }
                else
                {
                    cexcel.Cells[19, 1].value = empeno.Descripcion;
                }
                cexcel.Cells[22, 4].value = empeno.MontoPendiente;
                var index = 0;
                foreach (var item in intereses)
                {
                    if (item.Pagado >= 1)
                    {
                        var pagado = item.Pagado;

                        if (pagado > item.MontoBodega)
                        {
                            cexcel.Cells[26 + index, 1].value = "Bodega " + Program.Meses(item.FechaVencimiento.Month);
                            cexcel.Cells[26 + index, 3].value = item.MontoBodega.ToString("N2");

                            Microsoft.Office.Interop.Excel.Worksheet ws = cexcel.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;

                            Range line = (Range)cexcel.Rows[27 + index];
                            line.Insert();
                            ++index;
                            ws.get_Range("A" + (26 + index), "B" + (26 + index)).Merge();
                            ws.get_Range("C" + (26 + index), "D" + (26 + index)).Merge();
                            pagado -= item.MontoBodega;
                        }

                        if (pagado > 1)
                        {
                            cexcel.Cells[26 + index, 1].value = Program.Meses(item.FechaVencimiento.Month);
                            cexcel.Cells[26 + index, 3].value = pagado.ToString("N2");

                            Microsoft.Office.Interop.Excel.Worksheet ws = cexcel.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;

                            Range line = (Range)cexcel.Rows[27 + index];
                            line.Insert();
                            ++index;
                            ws.get_Range("A" + (26 + index), "B" + (26 + index)).Merge();
                            ws.get_Range("C" + (26 + index), "D" + (26 + index)).Merge();
                        }
                    }
                }

                cexcel.Cells[28 + index, 3].value = txtPagaInteres.Text;
                cexcel.Cells[30 + index, 3].value = empeno.FechaVencimiento.ToString("dd/MM/yyyy");
                cexcel.Cells[32 + index, 3].value = empeno.Estado.ToString();

                cexcel.ActiveWindow.SelectedSheets.PrintOut();
                System.Threading.Thread.Sleep(300);
                cexcel.ActiveWorkbook.Close(false);
                cexcel.Quit();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error al imprimir la factura, es probable que el Microsoft Excel Office esta desactivado, por favor contacte con Soporte Técnico", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #6
0
        public async Task <ResposeCancelar> SetPagaInteres(double pagoIntereses, bool print = true)
        {
            empeño = await _context.Empenos.FindAsync(empeñoId);

            if (pagoIntereses > 0)
            {
                var pago = new Pago
                {
                    EmpenoId    = empeño.EmpenoId,
                    Consecutivo = GetConsecutivo(),
                    Comentario  = txtComentario.Text,
                    EmpleadoId  = Program.EmpleadoId,
                    Fecha       = DateTime.Now,
                    Monto       = pagoIntereses,
                    TipoPago    = TipoPago.Interes,
                };

                _context.Pago.Add(pago);
                await _context.SaveChangesAsync();

                await funciones.SaveBitacora(new ValorBitacora
                {
                    Valor  = JsonConvert.SerializeObject(pago),
                    Modulo = "Pagos",
                    Accion = "Crear"
                });

                List <Intereses> intereses = new List <Intereses>();
                var sobrante    = pago.Monto;
                var listInteres = await _context.Intereses.Where(i => i.EmpenoId == pago.EmpenoId && i.Pagado < i.Monto).ToListAsync();

                foreach (var item in listInteres)
                {
                    if ((item.Monto - item.Pagado) > sobrante && sobrante > 0)
                    {
                        item.Pagado += sobrante;
                        if (item.Pagado == item.Monto)
                        {
                            empeño.FechaVencimiento = empeño.FechaVencimiento.AddMonths(1);
                            item.FechaPago          = DateTime.Now;
                        }

                        intereses.Add(item);
                        _context.Entry(item).State = EntityState.Modified;
                        break;
                    }
                    else if (sobrante > 0)
                    {
                        double paga = (item.Monto - item.Pagado);
                        item.Pagado += paga;
                        if (item.Pagado == item.Monto)
                        {
                            empeño.FechaVencimiento = empeño.FechaVencimiento.AddMonths(1);
                            item.FechaPago          = DateTime.Now;
                        }
                        item.PagoId = pago.PagoId;
                        sobrante   -= paga;
                        intereses.Add(item);
                        _context.Entry(item).State = EntityState.Modified;
                    }
                }

                await _context.SaveChangesAsync();

                await funciones.SaveBitacora(new ValorBitacora
                {
                    Valor  = JsonConvert.SerializeObject(intereses),
                    Modulo = "Intereses",
                    Accion = "Crear"
                });

                var id = empeño.EmpenoId;
                await funciones.ReviewEmpeño(id);

                empeño = null;
                using (DataContext contextTemp = new DataContext())
                {
                    empeño = await contextTemp.Empenos.FindAsync(id);

                    if (print)
                    {
                        await PrintInteres(empeño, intereses, pago);
                    }
                }

                return(new ResposeCancelar()
                {
                    Pago = pago,
                    Intereses = intereses
                });
            }

            return(null);
        }
Пример #7
0
        public async Task Guardar()
        {
            if (!funciones.ValidatePIN("Empeño"))
            {
                return;
            }

            double pagoIntereses  = double.Parse(txtPagaInteres.Text);
            double pagoMonto      = double.Parse(txtPagaMonto.Text);
            double montoPendiente = double.Parse(txtMontoAPagar.Text);

            if (pagoMonto < montoPendiente)
            {
                if ((pagoMonto > 0) && (empeño.Intereses.Sum(i => i.Monto) > (empeño.Intereses.Sum(i => i.Pagado) + pagoIntereses)))
                {
                    MessageBox.Show("Para abonar a la prenda debe pagar todos los intereses pendientes de " + montoMinimo.ToString("N2"), "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            var empleadoId = await funciones.GetEmpleadoIdByUser(Program.Usuario.Usuario);

            double montoIntereses = double.Parse(txtInteresAPagar.Text);



            if (pagoMonto > montoPendiente)
            {
                txtPagaMonto.Text = txtMontoAPagar.Text;
                pagoMonto         = double.Parse(txtPagaMonto.Text);
            }
            if (pagoIntereses > montoIntereses)
            {
                txtPagaInteres.Text = txtInteresAPagar.Text;
                pagoIntereses       = double.Parse(txtPagaInteres.Text);
            }

            empeño = null;
            var empeñoTemp = _context.Empenos.Find(empeñoId);

            if ((pagoMonto > 0 && pagoMonto < montoPendiente) && (pagoIntereses < montoMinimo - 1))
            {
                MessageBox.Show("Para abonar a la prenda debe pagar todos los intereses pendientes de " + montoMinimo.ToString("N2"), "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (pagoMonto > 0)
            {
                var pago = new Pago
                {
                    EmpenoId    = empeñoTemp.EmpenoId,
                    Consecutivo = GetConsecutivo(),
                    Comentario  = txtComentario.Text == "Comentario" ? string.Empty : txtComentario.Text,
                    EmpleadoId  = Program.EmpleadoId,
                    Fecha       = DateTime.Now,
                    Monto       = pagoMonto,
                    TipoPago    = TipoPago.Principal,
                };

                _context.Pago.Add(pago);
                await _context.SaveChangesAsync();

                await funciones.SaveBitacora(new ValorBitacora
                {
                    Valor  = JsonConvert.SerializeObject(pago),
                    Modulo = "Pagos",
                    Accion = "Crear"
                });

                empeñoTemp.MontoPendiente -= pago.Monto;

                if (empeñoTemp.MontoPendiente < 1)
                {
                    var pagoInteres = await SetPagaInteres(pagoIntereses, false);

                    empeñoTemp.Estado      = Estado.Cancelado;
                    empeñoTemp.Retirado    = true;
                    empeñoTemp.FechaRetiro = DateTime.Today;
                    _context.Intereses.RemoveRange(_context.Intereses.Where(i => i.EmpenoId == empleadoId && i.Pagado == 0));
                    _context.Entry(empeñoTemp).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    if (pagoInteres == null)
                    {
                        await PrintRetiro(empeñoTemp, pago);
                    }
                    else
                    {
                        await PrintRetiro(empeñoTemp, pago, pagoInteres);
                    }
                }
                else
                {
                    empeñoTemp.Estado = Estado.Vigente;
                    _context.Entry(empeñoTemp).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                    await PagaInteres(pagoIntereses, true);
                    await PrintAbono(empeñoTemp, pago);
                }
            }
            else
            {
                await PagaInteres(pagoIntereses, true);
            }

            await _context.SaveChangesAsync();

            this.Close();
        }