public async Task <bool> MarkAsPaid(int CompanyID, int InvoiceID) { bool ret = true; Invoices invoice; FinancialMovements newMovement; try { invoice = await _dbContext.Invoices.FirstOrDefaultAsync(x => x.CompanyID == CompanyID && x.InvoiceID == InvoiceID); if (invoice != null) { invoice.Paid = true; ret = await _dbContext.SaveChangesAsync() > 0; newMovement = await _dbContext.FinancialMovements.Where(x => x.InvoiceID == invoice.InvoiceID).FirstOrDefaultAsync(); if (newMovement != null) { newMovement.TypeID = 1; _dbContext.Entry(newMovement).State = EntityState.Modified; } else { newMovement = new FinancialMovements { CompanyID = CompanyID, isCompleted = true, Ammount = invoice.Total, Date = DateTime.Now, Description = "Factura cobrada", TypeID = 1, InvoiceID = invoice.InvoiceID }; _dbContext.Entry(newMovement).State = EntityState.Added; } await _dbContext.SaveChangesAsync(); } return(ret); } catch (Exception e) { return(false); } }
public async Task <Pos> Create(Pos pos) { try { _dbContex.Entry(pos).State = EntityState.Added; await _dbContex.SaveChangesAsync(); return(pos); } catch (Exception e) { return(null); } }
public async Task <Account.ChangePassword> ChangePassword(ChangePasswordModel passwords) { try { string oldPassword = string.Empty; string newPassword = string.Empty; Users user = await _dbContex.Users .FirstOrDefaultAsync(u => u.UserName == passwords.UserName); if (user != null) { PasswordVerificationResult result = _passwordHasher.VerifyHashedPassword(user, user.Password, passwords.oldPassword); if (result == PasswordVerificationResult.Success) { if (passwords.newPassword == passwords.confirmNewPassword) { user.Password = _passwordHasher.HashPassword(user, passwords.newPassword); _dbContex.Entry(user).State = EntityState.Modified; if (await _dbContex.SaveChangesAsync() == 0) { return(Account.ChangePassword.Not_Changed); } } else { return(Account.ChangePassword.Password_Dont_Match); } } else { return(Account.ChangePassword.Password_Verification_Failure); } } else { return(Account.ChangePassword.Password_Not_Linked); } return(Account.ChangePassword.Changed); } catch (Exception) { return(Account.ChangePassword.Unknown_Error); } }
public async Task <bool> addSend(DocumentToSend document) { DocumentToSend newDocumentToSend; try { document.Date = DateTime.Now; document.Sent = false; document.TimesSent = 0; _dbContex.Entry(document).State = EntityState.Added; return(await _dbContex.SaveChangesAsync() > 0); } catch (Exception e) { throw; } }
public async Task <InvoiceResponseModel> Create(int CompanyID, Invoices invoice) { BIWSFEV1 wsfev1; List <InvoiceAuthorizationObs> _observations; int nroComprobante; InvoiceResponseModel response = new InvoiceResponseModel(); List <Taxes> taxes = null; Certificates cert = null; DocumentType documentType = new DocumentType(); List <(string, decimal)> AmountTaxes = new List <(string, decimal)>(); List <TaxesModel> lstTaxes = new List <TaxesModel>(); FinancialMovements movements; decimal CalculatedTaxes = 0; decimal BaseTaxable = 0; decimal CalculatedDiscount = 0; double NetAmount = 0; try { _observations = new List <InvoiceAuthorizationObs>(); cert = await _dbContex.Certificates.FirstOrDefaultAsync(x => x.CompanyID == CompanyID); wsfev1 = new BIWSFEV1(); taxes = await _dbContex.Taxes.ToListAsync(); documentType = await _dbContex.DocumentTypes.FirstOrDefaultAsync(x => x.DocumentTypeID == invoice.DocumentTypeID); response = new InvoiceResponseModel(); invoice.CompanyID = CompanyID; invoice.Letter = documentType.Letter; invoice.DocumentTypeCode = documentType.Code.ToString().PadLeft(3, '0'); invoice.DocumentTypeShortCode = documentType.ShortName; invoice.Created = DateTime.Now; await _dbContex.AddAsync(invoice); invoice.Status = Enums.InvoiceStatus.Created; movements = new FinancialMovements { Ammount = -(invoice.Total), CompanyID = invoice.CompanyID, Date = DateTime.Now, Description = "Factura creada", TypeID = 3, Invoice = invoice }; _dbContex.Entry(movements).State = EntityState.Added; #region Extraer impuestos y calcular descuentos var GroupedTaxes = invoice.Items.GroupBy(x => x.TaxId); foreach (var item in GroupedTaxes) { int TaxCode = int.Parse(item.Key.ToString()); Taxes Tax = taxes.FirstOrDefault(x => x.Code == TaxCode); //var TotalDiscount = item.Sum(x => x.dis); CalculatedTaxes = item.Sum(x => x.TaxCalculated); BaseTaxable = item.Sum(x => x.Price * x.Qtty); lstTaxes.Add(new TaxesModel { CalculatedTax = (double)CalculatedTaxes, TaxBase = (double)BaseTaxable, TaxID = TaxCode }); AmountTaxes.Add((Tax.Name, CalculatedTaxes)); CalculatedTaxes = 0; } NetAmount = double.Parse(lstTaxes.Sum(x => x.TaxBase).ToString("N2")); //neto gravado if (cert != null) { if (await wsfev1.login(cert.Path, cert.Password)) { var LastInvoice = await wsfev1.recuperaLastCMPAsync(invoice.PosCode, documentType.Code); nroComprobante = LastInvoice.Body.FECompUltimoAutorizadoResult.CbteNro; nroComprobante++; wsfev1.reset(); wsfev1.agregaFactura(int.Parse(invoice.ConceptCode), int.Parse(invoice.IdentityDocumentTypeCode), long.Parse(invoice.IdentityDocumentNumber), nroComprobante, nroComprobante, DateTime.Parse(DateTime.Now.ToShortDateString()), Helpers.Truncate((double)invoice.Total, 2), /*TotalNotTaxed*/ 0, Helpers.Truncate(NetAmount, 2), /*OptionalExemptAmount*/ 0, null, null, null, "PES", 1); if (lstTaxes != null) { if (lstTaxes.Count > 0) { foreach (var tax in lstTaxes) { wsfev1.agregaIVA(tax.TaxID, Handlers.Helpers.Truncate(tax.TaxBase, 2), Handlers.Helpers.Truncate(tax.CalculatedTax, 2)); } } } var Authorizar = await wsfev1.AutorizarAsync(invoice.PosCode, documentType.Code); //wsfev1.autorizarRespuesta(0, ref cae, ref vencimiento, ref resultado); var respuesta = wsfev1.autorizarRespuestaV2(0); if (respuesta.Resultado == "A") { Guid id = Guid.NewGuid(); invoice.CAE = respuesta.CAE; invoice.CAEExpiration = respuesta.VencimientoCae; response.Result = respuesta.Resultado; /*GENERACION DE CODIGO DE BARRA*/ string FileCodeBar = $"{id}" + $".bmp"; string PathCodeBar = System.IO.Path.Combine($"C:\\Invoices\\Barcode\\{FileCodeBar}"); FEAFIPLib.TBarcodeBitmap.generarCodigoBarras(long.Parse(invoice.IdentityDocumentNumber), (byte)int.Parse(invoice.DocumentTypeCode), (byte)invoice.PosCode, respuesta.CAE, respuesta.VencimientoCae, 3, 80, PathCodeBar); BarCode barCode = new BarCode { Created = DateTime.Today, Name = FileCodeBar }; invoice.Status = Enums.InvoiceStatus.Authorized; invoice.BarCode = barCode; invoice.InvoiceNumber = nroComprobante; } else { if (respuesta.Observaciones.Count > 0) { foreach (var obs in respuesta.Observaciones) { _observations.Add(new InvoiceAuthorizationObs { Code = obs.Codigo, Description = obs.Descripcion }); } response.Observations = _observations; } } } } #endregion string fileName = await CreatePDF(invoice, AmountTaxes); Download download = new Download { File = fileName, Created = DateTime.Now, Count = 0, }; invoice.Download = download; await _dbContex.SaveChangesAsync(); response.InvoiceID = invoice.InvoiceID; response.Created = DateTime.Now; response.CAE = invoice.CAE; response.DueDateCae = invoice.CAEExpiration?.ToShortDateString(); return(response); //let calculatedDiscount = 0; //let discountPercent = discount / 100; //let _subTotal = 0; //let _total = this.ToDecimal(0); //calculatedDiscount = (price * Qtty) * discountPercent; //_subTotal = this.ToDecimal((price * Qtty) - calculatedDiscount); //let tax = Tax.taxById(parseInt(taxId)); //let taxValue = tax.Value; //let TaxCalculated = (_subTotal * taxValue) / 100; //_total = this.ToDecimal(parseFloat(_subTotal) + parseFloat(TaxCalculated)); } catch (Exception e) { throw; } }