Ejemplo n.º 1
0
        public IList<TransportBillMaster> CreateBill(IList<TransportActingBill> actingBillList)
        {
            if (actingBillList == null || actingBillList.Count == 0)
            {
                throw new BusinessException("Bill.Error.EmptyBillDetails");
            }

            DateTime dateTimeNow = DateTime.Now;
            IList<TransportBillMaster> billList = new List<TransportBillMaster>();

            foreach (TransportActingBill actingBill in actingBillList)
            {
                TransportBillMaster bill = null;

                #region 查找和待开明细的transactionType、billAddress、currency一致的BillMstr
                foreach (TransportBillMaster 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 TransportBillMaster();
                    bill.BillDetails = new List<TransportBillDetail>();
                    bill.BillAddress = actingBill.BillAddress;
                    bill.BillAddressDescription = actingBill.BillAddressDescription;
                    bill.BillNo = numberControlMgr.GetTransportBillNo(bill);
                    bill.Currency = actingBill.Currency;
                    bill.Status = CodeMaster.BillStatus.Create;
                    bill.Type = actingBill.Type;
                    bill.SubType = CodeMaster.BillSubType.Normal;
                    bill.Carrier = actingBill.Carrier;
                    bill.CarrierDescription = actingBill.CarrierDescription;

                    this.genericMgr.Create(bill);
                    billList.Add(bill);
                    #endregion
                }
                #endregion

                var q1_billDetails = bill.BillDetails.Where(b => b.ActBill == actingBill.Id);
                if (q1_billDetails != null && q1_billDetails.Count() > 0)
                {
                    TransportBillDetail billDetail = q1_billDetails.First();
                    billDetail.BillQty += actingBill.CurrentBillQty;
                    billDetail.BillAmount += actingBill.CurrentBillAmount;
                    this.genericMgr.Update(billDetail);
                    //扣减TransportActingBill数量和金额
                    this.UpdateTransportActingBill(billDetail);
                }
                else
                {
                    TransportBillDetail billDetail = this.TransportActingBill2TransportBillDetail(actingBill);
                    billDetail.BillNo = bill.BillNo;
                    bill.AddBillDetail(billDetail);
                    this.genericMgr.Create(billDetail);
                    //扣减TransportActingBill数量和金额
                    this.UpdateTransportActingBill(billDetail);
                }
            }
            foreach (var bill in billList)
            {
                foreach (var billDetail in bill.BillDetails)
                {
                    bill.BillAmount += billDetail.BillAmount;
                }
            }
            return billList;
        }
Ejemplo n.º 2
0
 public string GetTransportBillNo(TransportBillMaster billMaster)
 {
     string numberSuffix = GetNextSequence(BusinessConstants.NUMBERCONTROL_PROCUREMENTBILL);
     numberSuffix = numberSuffix.PadLeft(9, '0');
     return ("B3" + numberSuffix);
 }
Ejemplo n.º 3
0
        public void UpdateBill(TransportBillMaster 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 (TransportBillDetail billDetail in bill.BillDetails)
                {
                    //反向更新TransportActingBill,会重新计算开票金额
                    if (billDetail.CurrentBillQty != billDetail.BillQty)
                    {
                        this.ReverseTransportActingBill(billDetail);
                    }

                    billDetail.BillQty = billDetail.CurrentBillQty;
                    billDetail.BillAmount = billDetail.CurrentBillAmount;
                    billDetail.Discount = billDetail.CurrentDiscount;
                    this.genericMgr.Update(billDetail);
                }
            }
            #endregion
            bill.BillAmount = bill.BillDetails.Sum(p => p.BillAmount);
            this.genericMgr.Update(bill);
        }