public async Task <IActionResult> GetInvoiceTransReportById(Int64 Id) { InvoiceTransReport Items = new InvoiceTransReport(); try { Items = await _context.InvoiceTransReport.Where(q => q.IdInvoiceTransReport == Id).FirstOrDefaultAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(Items))); }
public async Task <IActionResult> GetInvoiceTransReportByDates(DateTime fechainicio, DateTime fechafinal) { InvoiceTransReport Items = new InvoiceTransReport(); try { Items = await _context.InvoiceTransReport.Where(q => q.InvoiceDate >= fechainicio && q.InvoiceDate <= fechafinal).FirstOrDefaultAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(Items))); }
public async Task <ActionResult <InvoiceTransReport> > Insert([FromBody] InvoiceTransReport _IdInvoiceTransReport) { InvoiceTransReport IdInvoiceTransReportq = new InvoiceTransReport(); try { IdInvoiceTransReportq = _IdInvoiceTransReport; _context.InvoiceTransReport.Add(IdInvoiceTransReportq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(IdInvoiceTransReportq))); }
public async Task <IActionResult> Delete([FromBody] InvoiceTransReport _IdInvoiceTransReport) { InvoiceTransReport _IdInvoiceTransReportq = new InvoiceTransReport(); try { _IdInvoiceTransReportq = _context.InvoiceTransReport .Where(x => x.IdInvoiceTransReport == (Int64)_IdInvoiceTransReport.IdInvoiceTransReport) .FirstOrDefault(); _context.InvoiceTransReport.Remove(_IdInvoiceTransReportq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_IdInvoiceTransReportq))); }
public async Task <ActionResult <InvoiceTransReport> > Update([FromBody] InvoiceTransReport _IdInvoiceTransReport) { InvoiceTransReport _IdInvoiceTransReportq = _IdInvoiceTransReport; try { _IdInvoiceTransReportq = await(from c in _context.InvoiceTransReport .Where(q => q.IdInvoiceTransReport == _IdInvoiceTransReport.IdInvoiceTransReport) select c ).FirstOrDefaultAsync(); _context.Entry(_IdInvoiceTransReportq).CurrentValues.SetValues((_IdInvoiceTransReport)); //_context.Bank.Update(_Bankq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_IdInvoiceTransReportq))); }
public async Task <ActionResult <Invoice> > InsertConAlarma([FromBody] Invoice _Invoice) { Invoice _Invoiceq = new Invoice(); ElementoConfiguracion _elemento = new ElementoConfiguracion(); bool GenerateAlert = false; try { using (var transaction = _context.Database.BeginTransaction()) { try { _Invoiceq = _Invoice; Invoice _invoice = await _context.Invoice.Where(q => q.BranchId == _Invoice.BranchId) .Where(q => q.IdPuntoEmision == _Invoice.IdPuntoEmision) .FirstOrDefaultAsync(); if (_invoice != null) { _Invoiceq.NumeroDEI = _context.Invoice.Where(q => q.BranchId == _Invoice.BranchId) .Where(q => q.IdPuntoEmision == _Invoice.IdPuntoEmision).Max(q => q.NumeroDEI); } _Invoiceq.NumeroDEI += 1; // Int64 puntoemision = _context.Users.Where(q=>q.Email==_Invoiceq.UsuarioCreacion).Select(q=>q.) Int64 IdCai = await _context.NumeracionSAR .Where(q => q.BranchId == _Invoiceq.BranchId) .Where(q => q.IdPuntoEmision == _Invoiceq.IdPuntoEmision) .Where(q => q.Estado == "Activo").Select(q => q.IdCAI).FirstOrDefaultAsync(); if (IdCai == 0) { return(BadRequest("No existe un CAI activo para el punto de emisión")); } //_Invoiceq.Sucursal = await _context.Branch.Where(q => q.BranchId == _Invoice.BranchId).Select(q => q.BranchCode).FirstOrDefaultAsync(); // _Invoiceq.Caja = await _context.PuntoEmision.Where(q=>q.IdPuntoEmision== _Invoice.IdPuntoEmision).Select(q => q.PuntoEmisionCod).FirstOrDefaultAsync(); _Invoiceq.CAI = await _context.CAI.Where(q => q.IdCAI == IdCai).Select(q => q._cai).FirstOrDefaultAsync(); Numalet let; let = new Numalet(); let.SeparadorDecimalSalida = "Lempiras"; let.MascaraSalidaDecimal = "00/100 "; let.ApocoparUnoParteEntera = true; _Invoiceq.TotalLetras = let.ToCustomCardinal((_Invoiceq.Total)).ToUpper(); _context.Invoice.Add(_Invoiceq); _elemento = await _context.ElementoConfiguracion.Where(q => q.Id == 76).FirstOrDefaultAsync(); if (_elemento != null) { if (_Invoiceq.CurrencyId == 1) { if (_Invoiceq.Total > _elemento.Valordecimal) { GenerateAlert = true; } } else { ExchangeRate rate = new ExchangeRate(); rate = await _context.ExchangeRate.Where(q => q.DayofRate == _Invoiceq.InvoiceDate && q.CurrencyId == _Invoiceq.CurrencyId).FirstOrDefaultAsync(); if (rate != null) { if (((double)rate.ExchangeRateValue * _Invoiceq.Total) > _elemento.Valordecimal) { GenerateAlert = true; } } } } if (GenerateAlert) { //se agrega la alerta Alert _alert = new Alert(); _alert.DocumentId = _invoice.InvoiceId; _alert.DocumentName = "FACTURA"; _alert.AlertName = "Sancionados"; _alert.Code = "PERSON004"; _alert.ActionTakenId = 0; _alert.ActionTakenName = ""; _alert.IdEstado = 0; _alert.SujetaARos = false; _alert.FalsoPositivo = false; _alert.CloseDate = DateTime.MinValue; _alert.DescriptionAlert = _invoice.InvoiceId.ToString() + " / " + _invoice.CustomerName + " / " + _invoice.Total.ToString(); _alert.FechaCreacion = DateTime.Now; _alert.FechaModificacion = DateTime.Now; _alert.UsuarioCreacion = _invoice.UsuarioCreacion; _alert.UsuarioModificacion = _invoice.UsuarioModificacion; _context.Alert.Add(_alert); //se agrega la informacion a la tabla InvoiceTransReport InvoiceTransReport _report = new InvoiceTransReport(); _report.Amount = _invoice.Total; _report.CustomerId = _invoice.CustomerId; _report.InvoiceDate = _invoice.InvoiceDate; _report.FechaCreacion = DateTime.Now; _report.FechaModificacion = DateTime.Now; _report.UsuarioCreacion = _invoice.UsuarioCreacion; _report.UsuarioModificacion = _invoice.UsuarioModificacion; _context.InvoiceTransReport.Add(_report); } //await _context.SaveChangesAsync(); foreach (var item in _Invoice.InvoiceLine) { item.InvoiceId = _Invoiceq.InvoiceId; _context.InvoiceLine.Add(item); } await _context.SaveChangesAsync(); JournalEntryConfiguration _journalentryconfiguration = await(_context.JournalEntryConfiguration .Where(q => q.TransactionId == 1) .Where(q => q.BranchId == _Invoiceq.BranchId) .Where(q => q.EstadoName == "Activo") .Include(q => q.JournalEntryConfigurationLine) ).FirstOrDefaultAsync(); BitacoraWrite _writejec = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Invoice.CustomerId, DocType = "JournalEntryConfiguration", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_journalentryconfiguration, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_journalentryconfiguration, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "InsertInvoice", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _Invoice.UsuarioCreacion, UsuarioModificacion = _Invoice.UsuarioModificacion, UsuarioEjecucion = _Invoice.UsuarioModificacion, }); // await _context.SaveChangesAsync(); double sumacreditos = 0, sumadebitos = 0; if (_journalentryconfiguration != null) { //Crear el asiento contable configurado //............................./////// JournalEntry _je = new JournalEntry { Date = _Invoiceq.InvoiceDate, Memo = "Factura de ventas", DatePosted = _Invoiceq.InvoiceDate, ModifiedDate = DateTime.Now, CreatedDate = DateTime.Now, ModifiedUser = _Invoiceq.UsuarioModificacion, CreatedUser = _Invoiceq.UsuarioCreacion, DocumentId = _Invoiceq.InvoiceId, TypeOfAdjustmentId = 65, VoucherType = 1, }; foreach (var item in _journalentryconfiguration.JournalEntryConfigurationLine) { InvoiceLine _iline = new InvoiceLine(); _iline = _Invoiceq.InvoiceLine.Where(q => q.SubProductId == item.SubProductId).FirstOrDefault(); if (_iline != null || item.SubProductName.ToUpper().Contains(("Impuesto").ToUpper())) { if (!item.AccountName.ToUpper().Contains(("Impuestos sobre ventas").ToUpper()) && !item.AccountName.ToUpper().Contains(("Sobre Servicios Diversos").ToUpper())) { _iline.AccountId = Convert.ToInt32(item.AccountId); _iline.AccountName = item.AccountName; _context.Entry(_iline).CurrentValues.SetValues((_iline)); _je.JournalEntryLines.Add(new JournalEntryLine { AccountId = Convert.ToInt32(item.AccountId), AccountName = item.AccountName, Description = item.AccountName, Credit = item.DebitCredit == "Credito" ? _iline.SubTotal : 0, Debit = item.DebitCredit == "Debito" ? _iline.SubTotal : 0, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, CreatedUser = _Invoiceq.UsuarioCreacion, ModifiedUser = _Invoiceq.UsuarioModificacion, Memo = "", }); sumacreditos += item.DebitCredit == "Credito" ? _iline.SubTotal : 0; sumadebitos += item.DebitCredit == "Debito" ? _iline.SubTotal : 0; } else { _je.JournalEntryLines.Add(new JournalEntryLine { AccountId = Convert.ToInt32(item.AccountId), AccountName = item.AccountName, Description = item.AccountName, Credit = item.DebitCredit == "Credito" ? _Invoiceq.Tax + _Invoiceq.Tax18 : 0, Debit = item.DebitCredit == "Debito" ? _Invoiceq.Tax + _Invoiceq.Tax18 : 0, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, CreatedUser = _Invoiceq.UsuarioCreacion, ModifiedUser = _Invoiceq.UsuarioModificacion, Memo = "", }); sumacreditos += item.DebitCredit == "Credito" ? _Invoiceq.Tax + _Invoiceq.Tax18 : 0; sumadebitos += item.DebitCredit == "Debito" ? _Invoiceq.Tax + _Invoiceq.Tax18 : 0; } } // _context.JournalEntryLine.Add(_je); } if (sumacreditos != sumadebitos) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: No coinciden debitos :{sumadebitos} y creditos{sumacreditos}"); return(BadRequest($"Ocurrio un error: No coinciden debitos :{sumadebitos} y creditos{sumacreditos}")); } _je.TotalCredit = sumacreditos; _je.TotalDebit = sumadebitos; _context.JournalEntry.Add(_je); await _context.SaveChangesAsync(); } BitacoraWrite _write = new BitacoraWrite(_context, new Bitacora { IdOperacion = _Invoice.CustomerId, DocType = "Invoice", ClaseInicial = Newtonsoft.Json.JsonConvert.SerializeObject(_Invoice, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), ResultadoSerializado = Newtonsoft.Json.JsonConvert.SerializeObject(_Invoice, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Accion = "Insert", FechaCreacion = DateTime.Now, FechaModificacion = DateTime.Now, UsuarioCreacion = _Invoice.UsuarioCreacion, UsuarioModificacion = _Invoice.UsuarioModificacion, UsuarioEjecucion = _Invoice.UsuarioModificacion, }); await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); _logger.LogError($"Ocurrio un error: { ex.ToString() }"); throw ex; } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(await Task.Run(() => Ok(_Invoiceq))); }