public Tuple <int, string, Bill> Create(UserClaim creator, BillCreatedModel model) { if (isExisted(model.RepairedRequestId)) { return(new Tuple <int, string, Bill>(400, "Bill is already existed", null)); } double total = 0; var details = _rrService.GetQuotationDetails(model.RepairedRequestId); if (details != null) { foreach (var detail in details) { total += detail.Quantity * detail.UnitPrice + detail.LaborCost; } if (model.Discount != 0) { total = total * (1 - model.Discount); } } var customer = _customerService.Get(model.CustomerId); if (customer == null) { return(new Tuple <int, string, Bill>(400, "Customer Not Found", null)); } Bill bill = new Bill() { TotalAmount = total, CreatedDate = System.DateTime.Now, Creator = creator, Id = model.RepairedRequestId, Details = details, Customer = customer, Discount = model.Discount, VAT = model.VAT }; try { _bill.InsertOne(bill); return(new Tuple <int, string, Bill>(200, "", bill)); } catch { return(new Tuple <int, string, Bill>(500, "", null)); } }
public List <IssueDetailModel> GetIssueDetails(string id) { List <IssueDetailModel> result = new List <IssueDetailModel>(); var rrId = _accessoryIssue.Find(acc => acc.Id == id).Project(acc => acc.RepairedRequestId).FirstOrDefault(); if (rrId == null) { throw new Exception("Không tìm thấy phiếu xuất phụ tùng"); } var details = _rrService.GetQuotationDetails(rrId); foreach (var detail in details) { var acc = _accessoryService.Get(detail.AccessoryId); result.Add(new IssueDetailModel() { Name = acc.Name, Quantity = detail.Quantity, Unit = acc.Unit, }); } return(result); }