/// <summary> /// 用于创建运单 /// </summary> /// <param name="user"></param> public EditModel(IUser user) : this() { Bill = new BillEditModel(); IsReadOnly = false; IsSenderAndReceiverReadOnly = false; IsAllowSetAgent = user.Role >= UserRoles.Admin; IsAllowUpdateState = user.Role >= UserRoles.Agent; IsAllowSetCreateDate = user.Role >= UserRoles.Agent; }
public EditModel(BillAuthority authority, IBill service) : this() { Bill = new BillEditModel(service); IsAllowUpdateState = authority.AllowUpdateState; IsReadOnly = !authority.AllowUpdateMinorInfo; IsSenderAndReceiverReadOnly = !authority.AllowUpdateSenderOrReceiver; IsAllowSetAgent = authority.AllowSetAgent; IsAllowSetCreateDate = authority.AllowSetCreateDate; }
public async Task <IActionResult> Edit([FromBody] BillEditModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorList())); } if (!EnumerableExtensions.Any(model.Items)) { return(BadRequest("Please select item to continue")); } try { await _manager.Editsync(model); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public static void Edit(Bill bill, BillEditModel model, string userId) { bill.VendorId = model.VendorId; bill.BillNumber = model.BillNumber; bill.Tax = model.Tax; bill.Discount = model.Discount; bill.TotalAmount = model.TotalAmount; bill.Remark = model.Remark; bill.DueDate = model.DueDate; bill.UpdatedBy = userId ?? "0"; bill.UpdatedOn = Utility.GetDateTime(); bill.BillDate = model.BillDate; bill.StrBillDate = model.BillDate.ToString("dd/MM/yyyy"); bill.StrDueDate = model.DueDate.Value.ToString("dd/MM/yyyy"); bill.PoSoNumber = model.PoSoNumber; bill.Notes = model.Notes; bill.SubTotal = model.SubTotal; bill.LineAmountSubTotal = model.LineAmountSubTotal; bill.RefrenceNumber = model.RefrenceNumber; ArrayList tempArr = new ArrayList(); foreach (var item in model.Items) { tempArr.Add(item.ItemId); var alreadyExistServices = bill.Items.Where(x => item.ItemId == x.ItemId).FirstOrDefault(); if (alreadyExistServices != null) { alreadyExistServices.Price = item.Price; alreadyExistServices.TaxId = item.TaxId; alreadyExistServices.TaxPercentage = item.TaxPercentage; alreadyExistServices.Rate = item.Rate; alreadyExistServices.Quantity = item.Quantity; alreadyExistServices.TaxPrice = item.TaxPrice; alreadyExistServices.LineAmount = item.LineAmount; bill.Items.Add(alreadyExistServices); } } var deletedServices = bill.Items.Where(x => !tempArr.Contains(x.ItemId)).ToList(); //var alreadyExistServices = entity.Services.Where(x => tempArr.Contains(x.ServiceId)).ToList(); //var resultAll = items.Where(i => filter.All(x => i.Features.Any(f => x == f.Id))); foreach (var deletedService in deletedServices) { bill.Items.Remove(deletedService); } var addedServices = model.Items .Where(x => !bill.Items.Select(y => y.ItemId).Contains(x.ItemId)) .ToList(); foreach (var service in addedServices) { bill.Items.Add(new BillItem { Id = Guid.NewGuid(), ItemId = service.ItemId, Rate = service.Rate, TaxId = service.TaxId, Price = service.Price, Quantity = service.Quantity, TaxPercentage = service.TaxPercentage, TaxPrice = service.TaxPrice, LineAmount = service.LineAmount }); } if (model.Attachments == null || !model.Attachments.Any()) { return; } var deletedAttachemntFiles = bill.Attachments.Select(x => x.FileName) .Except(model.Attachments.Select(y => y.FileName)).ToList(); foreach (var deletedAttachemntFile in deletedAttachemntFiles) { var attachemnt = bill.Attachments.Single(x => x.FileName.Equals(deletedAttachemntFile)); bill.Attachments.Remove(attachemnt); } foreach (var attachment in model.Attachments) { var billAttachment = bill.Attachments.SingleOrDefault(x => x.FileName.Equals(attachment.FileName)); if (billAttachment == null) { billAttachment = new BillAttachment { Title = attachment.Title, FileName = attachment.FileName, OriginalFileName = attachment.OriginalFileName, CreatedBy = userId ?? "0", CreatedOn = Utility.GetDateTime() }; } else { billAttachment.Title = attachment.Title; billAttachment.FileName = attachment.FileName; billAttachment.OriginalFileName = attachment.OriginalFileName; } bill.Attachments.Add(billAttachment); } }
public async Task Editsync(BillEditModel model) { //var items = (await _itemRepository.GetAsync(model.Items)).ToList(); //model.TotalAmount = items.Sum(x => x.Rate); //model.Tax = items.Where(x => x.IsTaxable).Sum(x => x.Rate * x.SalesTax.TaxPercentage / 100); //var vendor = await _vendorRepository.GetAsync(model.VendorId); //if (vendor.Discount != null) //{ // model.Discount = model.TotalAmount * vendor.Discount / 100; // model.TotalAmount = model.TotalAmount - (model.Discount ?? 0); //} //if (model.Tax != null) //{ // model.TotalAmount = model.TotalAmount + (model.Tax ?? 0); //} await _transactionRepository.DeleteTransaction(model.Id); var bill = await _repository.GetAsync(model.Id); BillFactory.Edit(bill, model, _userId); _repository.Edit(bill); await _unitOfWork.SaveChangesAsync(); var transaction = TransactionFactory.CreateByBill(bill); await _transactionRepository.AddAsync(transaction); await _unitOfWork.SaveChangesAsync(); var itemsList = (model.Items.GroupBy(l => l.BankAccountId, l => new { l.BankAccountId, l.LineAmount }) .Select(g => new { GroupId = g.Key, Values = g.ToList() })).ToList(); foreach (var item in itemsList) { var id = item.GroupId; var amount = item.Values.Sum(x => x.LineAmount); var itemsData = TransactionFactory.CreateByBillItemsAndTax(bill, id, amount); await _transactionRepository.AddAsync(itemsData); await _unitOfWork.SaveChangesAsync(); } var taxlistList = (model.Items.GroupBy(l => l.TaxBankAccountId, l => new { l.TaxBankAccountId, l.TaxPrice }) .Select(g => new { GroupId = g.Key, Values = g.ToList() })).ToList(); foreach (var tax in taxlistList) { if (tax.GroupId > 0) { var id = tax.GroupId; var amount = tax.Values.Sum(x => x.TaxPrice); var taxData = TransactionFactory.CreateByBillItemsAndTax(bill, id, amount); await _transactionRepository.AddAsync(taxData); await _unitOfWork.SaveChangesAsync(); } } }