public async Task <int> RemoveReporteBancoAsync(ReporteBancos newReporteBanco)
 {
     try
     {
         var reporte = _context.ReporteBancos.Remove(newReporteBanco);
         return(await _context.SaveChangesAsync());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <int> AddReporteBancoAsync(ReporteBancos newReporteBanco)
        {
            try
            {
                var reporte = _context.ReporteBancos.Add(newReporteBanco);
                int result  = await _context.SaveChangesAsync();

                return(reporte.idReporteBancos);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #3
0
        public async Task <IHttpActionResult> RegistrarReporte(ReporteBancosModel reporteBancoModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                ReporteBancos newReporte = new ReporteBancos()
                {
                    factura       = reporteBancoModel.factura,
                    fechaFactura  = DateTime.ParseExact(reporteBancoModel.fechaFactura, "dd/MM/yyyy", new CultureInfo("es-MX")),
                    noCheque      = reporteBancoModel.noCheque,
                    fechaPago     = DateTime.ParseExact(reporteBancoModel.fechaPago, "dd/MM/yyyy", new CultureInfo("es-MX")),
                    proveedor     = reporteBancoModel.proveedor,
                    t0            = reporteBancoModel.t0,
                    excentos      = reporteBancoModel.excentos,
                    compras       = reporteBancoModel.compras,
                    gastos        = reporteBancoModel.gastos,
                    ivaCompras    = reporteBancoModel.ivaCompras,
                    ivaGastos     = reporteBancoModel.ivaGastos,
                    retensionISR  = reporteBancoModel.retensionISR,
                    retensionIVA  = reporteBancoModel.retensionIVA,
                    total         = reporteBancoModel.t0 + reporteBancoModel.excentos + reporteBancoModel.compras + reporteBancoModel.ivaCompras + reporteBancoModel.ivaGastos + reporteBancoModel.retensionISR + reporteBancoModel.retensionIVA,
                    fechaAlta     = reporteBancoModel.fechaAlta,
                    idUsuarioAlta = reporteBancoModel.idUsuarioAlta,
                    estatus       = reporteBancoModel.estatus,
                    uuid          = reporteBancoModel.uuid
                };

                using (ReventonERPRepository _repo = new ReventonERPRepository())
                {
                    int result = await _repo.AddReporteBancoAsync(newReporte);

                    if (result == 0)
                    {
                        return(InternalServerError(new Exception("No se pudo registrar el Reporte de Bancos. Intente más tarde")));
                    }

                    Bancos newBanco = new Bancos()
                    {
                        tipo                = 1,
                        numeroCheque        = newReporte.noCheque,
                        fechaPago           = newReporte.fechaPago,
                        proveedor           = newReporte.proveedor,
                        numeroFactura       = newReporte.factura,
                        fechaFactura        = newReporte.fechaFactura,
                        referenciaDepositos = string.Empty,
                        depositos           = 0.00m,
                        cargos              = 0.00m - newReporte.total,
                        fechaAlta           = newReporte.fechaAlta,
                        idUsuarioAlta       = newReporte.idUsuarioAlta,
                        estatus             = 1,
                        uuid                = newReporte.uuid
                    };

                    result = await _repo.AddBancoAsync(newBanco);

                    if (result == 0)
                    {
                        result = await _repo.RemoveReporteBancoAsync(newReporte);

                        return(InternalServerError(new Exception("No se pudo registrar el proceso de Bancos. Intente más tarde")));
                    }

                    return(Ok("success"));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }