public void UpdateBill(BillMaster bill) { #region 检查状态 if (bill.Status != CodeMaster.BillStatus.Create) { throw new BusinessException("Bill.Error.StatusErrorWhenUpdate", bill.Status, bill.BillNo); } #endregion #region 更新明细 if (bill.BillDetails != null && bill.BillDetails.Count > 0) { foreach (BillDetail billDetail in bill.BillDetails) { //反向更新ActingBill,会重新计算开票金额 if (billDetail.CurrentBillQty != billDetail.Qty) { this.ReverseActingBill(billDetail); } billDetail.Qty = billDetail.CurrentBillQty; billDetail.Amount = billDetail.CurrentBillAmount; billDetail.Discount = billDetail.CurrentDiscount; this.genericMgr.Update(billDetail); } } #endregion bill.Amount = bill.BillDetails.Sum(p => p.Amount); this.genericMgr.Update(bill); }
public string GetBillNo(BillMaster billMaster) { if (billMaster.Type == CodeMaster.BillType.Procurement) { string numberSuffix = GetNextSequence(BusinessConstants.NUMBERCONTROL_PROCUREMENTBILL); numberSuffix = numberSuffix.PadLeft(9, '0'); return ("B1" + numberSuffix); } else if (billMaster.Type == CodeMaster.BillType.Distribution) { string numberSuffix = GetNextSequence(BusinessConstants.NUMBERCONTROL_DISTRIBUTIONBILL); numberSuffix = numberSuffix.PadLeft(9, '0'); return ("B2" + numberSuffix); } else { throw new Exception("没有定义此账单类型"); } }
public IList<BillMaster> CreateBill(IList<ActingBill> actingBillList) { if (actingBillList == null || actingBillList.Count == 0) { throw new BusinessException("Bill.Error.EmptyBillDetails"); } DateTime dateTimeNow = DateTime.Now; IList<BillMaster> billList = new List<BillMaster>(); foreach (ActingBill actingBill in actingBillList) { BillMaster bill = null; #region 查找和待开明细的transactionType、billAddress、currency一致的BillMstr foreach (BillMaster thisBill in billList) { if (thisBill.Type == actingBill.Type && thisBill.BillAddress == actingBill.BillAddress && thisBill.Currency == actingBill.Currency) { bill = thisBill; break; } } #endregion #region 没有找到匹配的Bill,新建 if (bill == null) { #region 创建Bill bill = new BillMaster(); bill.BillDetails = new List<BillDetail>(); bill.BillAddress = actingBill.BillAddress; bill.BillAddressDescription = actingBill.BillAddressDescription; bill.BillNo = numberControlMgr.GetBillNo(bill); bill.Currency = actingBill.Currency; bill.Status = CodeMaster.BillStatus.Create; bill.Type = actingBill.Type; bill.SubType = CodeMaster.BillSubType.Normal; bill.Party = actingBill.Party; bill.PartyName = actingBill.PartyName; this.genericMgr.Create(bill); billList.Add(bill); #endregion } #endregion var q1_billDetails = bill.BillDetails.Where(b => b.Item == actingBill.Item && b.UnitCount == actingBill.UnitCount && b.Uom == actingBill.Uom && b.UnitPrice == actingBill.UnitPrice && b.ReceiptNo == actingBill.ReceiptNo && b.ActingBillId == actingBill.Id); if (q1_billDetails != null && q1_billDetails.Count() > 0) { BillDetail billDetail = q1_billDetails.First(); billDetail.Qty += actingBill.CurrentBillQty; billDetail.Amount += actingBill.CurrentBillAmount; this.genericMgr.Update(billDetail); //扣减ActingBill数量和金额 this.UpdateActingBill(billDetail); } else { BillDetail billDetail = this.ActingBill2BillDetail(actingBill); billDetail.BillNo = bill.BillNo; bill.AddBillDetail(billDetail); this.genericMgr.Create(billDetail); //扣减ActingBill数量和金额 this.UpdateActingBill(billDetail); } } foreach (var bill in billList) { foreach (var billDetail in bill.BillDetails) { bill.Amount += billDetail.Amount; } } return billList; }