Beispiel #1
0
        private BillDetail ActingBill2BillDetail(ActingBill actingBill)
        {
            BillDetail billDetail = Mapper.Map<ActingBill, BillDetail>(actingBill);

            billDetail.Amount = actingBill.CurrentBillAmount;
            billDetail.Qty = actingBill.CurrentBillQty;
            billDetail.PriceList = actingBill.PriceList;

            //本次开票数量大于剩余数量
            if (actingBill.CurrentBillQty > (actingBill.BillQty - actingBill.BillingQty))
            {
                throw new BusinessException("ActingBill.Error.CurrentBillQtyGeRemainQty");
            }

            //本次开票金额大于剩余金额
            if (actingBill.CurrentBillAmount > (actingBill.BillAmount - actingBill.BillingAmount))
            {
                throw new BusinessException("ActingBill.Error.CurrentBillAmountGeRemainAmount");
            }

            return billDetail;
        }
Beispiel #2
0
        private SettleBillTransaction RecordSettleBillTransaction(PlanBill planBill, ActingBill actingBill, DateTime effectiveDate, bool isVoid)
        {
            #region 记BillTransaction
            SettleBillTransaction billTransaction = new SettleBillTransaction();

            billTransaction.OrderNo = planBill.OrderNo;
            billTransaction.IpNo = planBill.IpNo;
            billTransaction.ExternalIpNo = planBill.ExternalIpNo;
            billTransaction.ReceiptNo = planBill.ReceiptNo;
            billTransaction.ExternalReceiptNo = planBill.ExternalReceiptNo;
            billTransaction.IsIncludeTax = planBill.IsIncludeTax;
            billTransaction.Item = planBill.Item;
            billTransaction.ItemDescription = planBill.ItemDescription;
            billTransaction.Uom = planBill.Uom;
            billTransaction.UnitCount = planBill.UnitCount;
            billTransaction.HuId = planBill.HuId;
            //billTransaction.TransactionType =
            //    planBill.Type == com.Sconit.CodeMaster.BillType.Procurement ?
            //    (isVoid ? com.Sconit.CodeMaster.BillTransactionType.POSettleVoid : com.Sconit.CodeMaster.BillTransactionType.POSettle) :
            //    (isVoid ? com.Sconit.CodeMaster.BillTransactionType.SOSettleVoid : com.Sconit.CodeMaster.BillTransactionType.SOSettle);
            //billTransaction.BillAddress = planBill.BillAddress;
            //billTransaction.BillAddressDescription = planBill.BillAddressDescription;
            billTransaction.Party = planBill.Party;
            billTransaction.PartyName = planBill.PartyName;
            billTransaction.PriceList = planBill.PriceList;
            billTransaction.Currency = planBill.Currency;
            billTransaction.UnitPrice = planBill.UnitPrice;
            billTransaction.IsProvisionalEstimate = planBill.IsProvisionalEstimate;
            billTransaction.Tax = planBill.Tax;

            #region 记录数量
            decimal qty = isVoid ? planBill.CurrentVoidQty : planBill.CurrentActingQty;
            //billTransaction.BillQty = (isVoid ? -1 : 1)      //冲销为负数
            //        * (planBill.Type == com.Sconit.CodeMaster.BillType.Procurement ? -1 * qty : qty);  //采购付款为负数
            if (planBill.Type == CodeMaster.BillType.Procurement)
            {
                if (isVoid)
                {
                    //采购结算冲销负数
                    billTransaction.TransactionType = CodeMaster.BillTransactionType.POSettleVoid;
                    billTransaction.BillQty = -qty;
                    billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice;
                }
                else
                {
                    //采购结算正数
                    billTransaction.TransactionType = CodeMaster.BillTransactionType.POSettle;
                    billTransaction.BillQty = qty;
                    billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice;
                }
            }
            else
            {
                if (isVoid)
                {
                    //销售开票冲销负数
                    billTransaction.TransactionType = CodeMaster.BillTransactionType.SOSettleVoid;
                    billTransaction.BillQty = -qty;
                    billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice;
                }
                else
                {
                    //销售开票正数
                    billTransaction.TransactionType = CodeMaster.BillTransactionType.SOSettle;
                    billTransaction.BillQty = qty;
                    billTransaction.BillAmount = billTransaction.BillQty * billTransaction.UnitPrice;
                }
            }

            #endregion

            billTransaction.UnitQty = planBill.UnitQty;
            //
            billTransaction.LocationFrom = planBill.LocationFrom;
            billTransaction.SettleLocation = planBill.CurrentLocation;

            billTransaction.EffectiveDate = effectiveDate;
            billTransaction.PlanBill = planBill.Id;
            billTransaction.ActingBill = actingBill.Id;

            billTransaction.BillTerm = actingBill.BillTerm;

            User user = SecurityContextHolder.Get();
            billTransaction.CreateUserId = user.Id;
            billTransaction.CreateUserName = user.FullName;
            billTransaction.CreateDate = DateTime.Now;

            this.genericMgr.Create(billTransaction);

            return billTransaction;
            #endregion
        }
Beispiel #3
0
        private ActingBill RetriveActingBill(PlanBill planBill, DateTime effectiveDate)
        {
            DetachedCriteria criteria = DetachedCriteria.For<ActingBill>();
            criteria.Add(Expression.Eq("ReceiptNo", planBill.ReceiptNo));

            IList<ActingBill> actingBillList = this.genericMgr.FindAll<ActingBill>(criteria);

            ActingBill actingBill = new ActingBill();
            if (actingBillList == null || actingBillList.Count == 0)
            {
                actingBill = Mapper.Map<PlanBill, ActingBill>(planBill);
            }
            else
            {
                var actingBills = actingBillList.Where(p => p.OrderNo == planBill.OrderNo &&
                    p.ExternalReceiptNo == planBill.ExternalReceiptNo &&
                    p.Type == planBill.Type &&
                    p.Item == planBill.Item &&
                    p.BillAddress == planBill.BillAddress &&
                    p.Uom == planBill.Uom &&
                    p.UnitCount == planBill.UnitCount &&
                    p.PriceList == planBill.PriceList &&
                    p.RecPrice == planBill.UnitPrice &&
                    p.Currency == planBill.Currency &&
                    p.IsIncludeTax == planBill.IsIncludeTax &&
                    p.Tax == planBill.Tax &&
                    p.LocationFrom == planBill.LocationFrom &&
                    p.IsProvisionalEstimate == planBill.IsProvisionalEstimate &&
                    p.EffectiveDate == effectiveDate);
                if (actingBills == null || actingBills.Count() == 0)
                {
                    actingBill = Mapper.Map<PlanBill, ActingBill>(planBill);
                }
                else if (actingBills.Count() == 1)
                {
                    actingBill = actingBills.First();
                }
                else
                {
                    throw new TechnicalException("Acting bill record consolidate error, find target acting bill number great than 1.");
                }
            }

            actingBill.BillQty += planBill.CurrentActingQty;
            actingBill.EffectiveDate = effectiveDate;
            actingBill.IsClose = (actingBill.BillQty == (actingBill.BillingQty + actingBill.VoidQty));
            actingBill.BillAmount += planBill.UnitPrice * planBill.CurrentActingQty;
            actingBill.RecPrice = planBill.UnitPrice;

            return actingBill;
        }
Beispiel #4
0
        public SettleBillTransaction VoidSettleBill(ActingBill actingBill, PlanBill planBill, bool voidPlanBill)
        {
            #region 更新ActingBill
            if (Math.Abs(actingBill.BillQty) < Math.Abs(actingBill.BillingQty + actingBill.VoidQty + actingBill.CurrentVoidQty))
            {
                //待开票数量不足,不能冲销结算
                throw new BusinessException(Resources.BIL.Bill.Errors_VoidActBillFailActQtyNotEnough, actingBill.Item);
            }

            actingBill.VoidQty += actingBill.CurrentVoidQty;
            actingBill.IsClose = (actingBill.BillQty == (actingBill.BillingQty + actingBill.VoidQty));
            this.genericMgr.Update(actingBill);
            #endregion

            #region 反向更新PlanBill
            if (planBill == null)
            {
                planBill = this.genericMgr.FindById<PlanBill>(actingBill.PlanBill);
            }

            planBill.ActingQty -= actingBill.CurrentVoidQty;

            if (Math.Abs(planBill.ActingQty + planBill.VoidQty) > Math.Abs(planBill.PlanQty))
            {
                //冲销的数量大于待开票数量
                throw new BusinessException(Resources.BIL.Bill.Errors_VoidActingQtyExceedPlanQty, planBill.Item);
            }

            if (voidPlanBill)
            {
                if (Math.Abs(planBill.ActingQty + planBill.VoidQty + actingBill.CurrentVoidQty) > Math.Abs(planBill.PlanQty))
                {
                    //已经结算,不能冲销寄售信息
                    throw new BusinessException(Resources.BIL.Bill.Errors_VoidPlanBillFailPlanQtyNotEnough, planBill.Item);
                }

                planBill.VoidQty += actingBill.CurrentVoidQty;
            }

            if (planBill.PlanQty == (planBill.ActingQty + planBill.VoidQty))
            {
                planBill.IsClose = true;
            }
            else
            {
                planBill.IsClose = false;
            }

            this.genericMgr.Update(planBill);
            #endregion

            #region 记录库存事务
            planBill.CurrentVoidQty = actingBill.CurrentVoidQty;
            return this.RecordSettleBillTransaction(planBill, actingBill, actingBill.EffectiveDate, true);
            #endregion
        }
Beispiel #5
0
        public BillTransaction VoidSettleBill(ActingBill actingBill, PlanBill planBill, bool voidPlanBill)
        {
            #region 更新ActingBill
            //if (Math.Abs(actingBill.BillQty) < Math.Abs(actingBill.BilledQty + actingBill.VoidQty + actingBill.CurrentVoidQty))
            //{
            //    //待开票数量不足,不能冲销结算
            //    throw new BusinessException(Resources.BIL.Bill.Errors_VoidActBillFailActQtyNotEnough, actingBill.Item);
            //}

            actingBill.VoidQty += actingBill.CurrentVoidQty;
            //actingBill.IsClose = (actingBill.BillQty == (actingBill.BilledQty + actingBill.VoidQty));
            this.genericMgr.Update(actingBill);
            #endregion

            #region 反向更新PlanBill
            if (planBill == null)
            {
                planBill = this.genericMgr.FindById<PlanBill>(actingBill.PlanBill);

                planBill.CurrentVoidQty = 0;
                planBill.CurrentCancelVoidQty = 0;
                planBill.CurrentActingQty = 0;
                planBill.CurrentLocation = null;
                planBill.CurrentHuId = null;
                planBill.CurrentActingBill = null;
                planBill.CurrentBillTransaction = null;
            }

            planBill.ActingQty -= actingBill.CurrentVoidQty;

            //if (Math.Abs(planBill.ActingQty + planBill.VoidQty) > Math.Abs(planBill.PlanQty))
            //{
            //    //冲销的数量大于待开票数量
            //    throw new BusinessException(Resources.BIL.Bill.Errors_VoidActingQtyExceedPlanQty, planBill.Item);
            //}

            if (voidPlanBill)
            {
                //if (Math.Abs(planBill.ActingQty + planBill.VoidQty + actingBill.CurrentVoidQty) > Math.Abs(planBill.PlanQty))
                //{
                //    //已经结算,不能冲销寄售信息
                //    throw new BusinessException(Resources.BIL.Bill.Errors_VoidPlanBillFailPlanQtyNotEnough, planBill.Item);
                //}

                planBill.VoidQty += actingBill.CurrentVoidQty;
            }

            //if (planBill.PlanQty == (planBill.ActingQty + planBill.VoidQty))
            //{
            //    planBill.IsClose = true;
            //}
            //else
            //{
            //    planBill.IsClose = false;
            //}

            this.genericMgr.Update(planBill);
            #endregion

            #region 记录账单事务
            planBill.CurrentVoidQty = actingBill.CurrentVoidQty;
            return this.RecordBillTransaction(planBill, actingBill, actingBill.EffectiveDate, true);
            #endregion
        }