Ejemplo n.º 1
0
        /// <summary>
        /// 收款关联收款项
        /// </summary>
        /// <param name="receiptObj">收款项对象</param>
        /// <param name="relateValue">关联金额</param>
        /// <param name="offSet">是否对账冲销</param>
        public void RelateToReceiptObject(S_C_ManageContract_ReceiptObj receiptObj, decimal relateValue = 0, bool offSet = false)
        {
            var plan = receiptObj.S_C_PlanReceipt.FirstOrDefault(d => d.State == PlanReceiptState.UnReceipt.ToString());

            if (plan == null)
            {
                throw new Formula.Exceptions.BusinessException("收款项【" + receiptObj.Name + "】不存在未到款的计划,无法关联到款");
            }
            this.RelateToPlanReceipt(plan, relateValue, offSet);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 将发票对象关联到计划收款对象
        /// </summary>
        /// <param name="receiptObj">计划收款对象</param>
        /// <param name="relateValue">关联金额(默认为0,当为0时,且offset为false,关联金额自动等于计划收款金额。当默认为0,且offset为true,关联金额则取发票和计划收款的金额小的金额)</param>
        /// <param name="offSet">是否冲销关联</param>
        public void RelateToReceiptObject(S_C_ManageContract_ReceiptObj receiptObj, decimal relateValue = 0, bool offSet = false)
        {
            var marketEntites = this.GetMarketContext();

            marketEntites.S_C_Invoice_ReceiptObject.Delete(d => d.ReceiptObjectID == receiptObj.ID && d.S_C_InvoiceID == this.ID);
            var relation = marketEntites.S_C_Invoice_ReceiptObject.Create();

            relation.ID              = FormulaHelper.CreateGuid();
            relation.S_C_InvoiceID   = this.ID;
            relation.ReceiptObjectID = receiptObj.ID;
            relation.ContractInfoID  = this.ContractInfoID;
            relation.ModifyDate      = DateTime.Now;
            var userInfo = FormulaHelper.GetUserInfo();

            relation.ModifyUserName = userInfo.UserName;
            relation.ModifyUserID   = userInfo.UserID;
            relation.S_C_Invoice    = this;
            if (relateValue == 0)
            {
                relateValue = Convert.ToDecimal(receiptObj.ReceiptValue);
            }
            if (!offSet)
            {
                if (relateValue > this.Amount)
                {
                    throw new Formula.Exceptions.BusinessException("收款对应到发票的金额,不能高于发票金额");
                }

                if (relateValue > receiptObj.ReceiptValue)
                {
                    throw new Formula.Exceptions.BusinessException("【" + receiptObj.Name + "】对应到发票的金额,不能高于计划收款金额");
                }
                var relationValue      = receiptObj.S_C_Invoice_ReceiptObject.Where(d => d.S_C_InvoiceID != this.ID).Sum(d => d.RelationValue);
                var remainInvoiceValue = receiptObj.ReceiptValue - relationValue;
                if (relateValue > remainInvoiceValue)
                {
                    throw new Formula.Exceptions.BusinessException("【" + receiptObj.Name + "】对应到发票的金额,不能高于剩余可开票金额【" + remainInvoiceValue + "】");
                }
            }
            else
            {
                if (relateValue > receiptObj.ReceiptValue)
                {
                    relateValue = Convert.ToDecimal(receiptObj.ReceiptValue);
                }
                if (relateValue > this.Amount)
                {
                    relateValue = Convert.ToDecimal(this.Amount);
                }
            }
            relation.RelationValue = relateValue;
            marketEntites.S_C_Invoice_ReceiptObject.Add(relation);
            receiptObj.SummaryInvoiceValue();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 将发票对象关联到计划收款对象
        /// </summary>
        /// <param name="receiptObj">计划收款对象</param>
        /// <param name="relateValue">关联金额(默认为0,当为0时,且offset为false,关联金额自动等于计划收款金额。当默认为0,且offset为true,关联金额则取发票和计划收款的金额小的金额)</param>
        /// <param name="offSet">是否冲销关联</param>
        public void RelateToReceiptObject(S_C_Invoice invoice, S_C_ManageContract_ReceiptObj receiptObj, decimal relateValue = 0, bool offSet = false)
        {
            var marketEntites = invoice.GetMarketContext();

            marketEntites.S_C_Invoice_ReceiptObject.Delete(d => d.ReceiptObjectID == receiptObj.ID && d.S_C_InvoiceID == invoice.ID);
            var relation = marketEntites.S_C_Invoice_ReceiptObject.Create();

            relation.ID              = FormulaHelper.CreateGuid();
            relation.S_C_InvoiceID   = invoice.ID;
            relation.ReceiptObjectID = receiptObj.ID;
            relation.ContractInfoID  = invoice.ContractInfoID;
            relation.ModifyDate      = DateTime.Now;
            var userInfo = FormulaHelper.GetUserInfo();

            relation.ModifyUserName = userInfo.UserName;
            relation.ModifyUserID   = userInfo.UserID;
            relation.S_C_Invoice    = invoice;
            if (relateValue == 0)
            {
                relateValue = Convert.ToDecimal(receiptObj.ReceiptValue);
            }

            //if (!offSet)
            {
                if (relateValue > this.Amount)//不用invoice.Amount因为invoice.Amount已经是负数
                {
                    throw new Formula.Exceptions.BusinessException("收款对应到发票的金额,不能高于发票金额");
                }

                if (relateValue > receiptObj.FactInvoiceValue)
                {
                    throw new Formula.Exceptions.BusinessException("【" + receiptObj.Name + "】对应到发票的金额,不能高于已开票金额");
                }
            }
            //else
            //{
            //    if (relateValue > receiptObj.ReceiptValue)
            //        relateValue = Convert.ToDecimal(receiptObj.ReceiptValue);
            //    if (relateValue > this.Amount)
            //        relateValue = Convert.ToDecimal(this.Amount);
            //}

            relation.RelationValue = -relateValue;
            marketEntites.S_C_Invoice_ReceiptObject.Add(relation);
            receiptObj.SummaryInvoiceValue();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 保存收款项信息
        /// </summary>
        /// <param name="receiptObject">收款项对象</param>
        public void SaveReceiptObject(S_C_ManageContract_ReceiptObj receiptObject)
        {
            var marketEntities = this.GetMarketContext();
            var receiptObj     = this.S_C_ManageContract_ReceiptObj.SingleOrDefault(d => d.ID == receiptObject.ID);
            var receiptValue   = this.S_C_ManageContract_ReceiptObj.Where(d => d.ID != receiptObject.ID).Sum(d => d.ReceiptValue);

            if (receiptValue > this.ContractRMBAmount)
            {
                throw new Formula.Exceptions.BusinessException("收款项金额合计不能大于合同金额");
            }
            if (receiptObj == null)
            {
                receiptObj       = new S_C_ManageContract_ReceiptObj();
                receiptObject.ID = FormulaHelper.CreateGuid();
                FormulaHelper.UpdateModel(receiptObj, receiptObject);
                receiptObj.MileStoneState = false.ToString();
                this.S_C_ManageContract_ReceiptObj.Add(receiptObj);
                var plan = new S_C_PlanReceipt();
                receiptObj.S_C_ManageContract = this;
                //新增合同收款项的同时,新建计划收款项
                plan.Name             = receiptObj.Name;
                plan.PlanReceiptDate  = receiptObj.PlanFinishDate;
                plan.PlanReceiptValue = Convert.ToDecimal(receiptObj.ReceiptValue);
                receiptObj.AddReceiptPlan(plan);
            }
            else
            {
                if (receiptObj.FactInvoiceValue > 0 || receiptObj.FactReceiptValue > 0 || receiptObj.FactBadValue > 0)
                {
                    receiptObj.SummaryReceiptObjectData();
                    receiptObj.ProjectInfo     = receiptObject.ProjectInfo;
                    receiptObj.ProjectInfoName = receiptObject.ProjectInfoName;
                }
                else
                {
                    FormulaHelper.UpdateModel(receiptObj, receiptObject);
                    receiptObj.ResetPlan();
                }
            }
            receiptObj.SummaryReceiptObjectData();
            if (receiptObj.ReceiptValue < receiptObj.FactInvoiceValue)
            {
                throw new Formula.Exceptions.BusinessException("【" + receiptObj.Name + "】收款项金额不能小于该收款项的已开票金额:【" + receiptObj.FactInvoiceValue + "】");
            }
            if (receiptObj.ReceiptValue < receiptObj.FactReceiptValue)
            {
                throw new Formula.Exceptions.BusinessException("【" + receiptObj.Name + "】收款项金额不能小于该收款项的已到款金额:【" + receiptObj.FactReceiptValue + "】");
            }
            if (receiptObj.ReceiptValue < receiptObj.FactReceiptValue)
            {
                throw new Formula.Exceptions.BusinessException("【" + receiptObj.Name + "】收款项金额不能小于该收款项的坏账金额:【" + receiptObj.FactBadValue + "】");
            }
            receiptObj.SetPlanFinishDate();
            if (!receiptObj.OriginalPlanFinishDate.HasValue)
            {
                receiptObj.OriginalPlanFinishDate = receiptObj.PlanFinishDate;
            }
            if (this.S_C_ManageContract_ProjectRelation.Count == 1)
            {
                var projectRelation = this.S_C_ManageContract_ProjectRelation.FirstOrDefault();
                if (String.IsNullOrEmpty(receiptObj.ProjectInfo))
                {
                    receiptObj.ProjectInfo     = projectRelation.ProjectID;
                    receiptObj.ProjectInfoName = projectRelation.ProjectName;
                }
            }

            if (!String.IsNullOrEmpty(receiptObj.ProjectInfo))
            {
                if (this.S_C_ManageContract_ProjectRelation.Count(d => d.ProjectID == receiptObj.ProjectInfo) == 0 &&
                    !String.IsNullOrEmpty(receiptObj.MileStoneID))
                {
                    throw new Formula.Exceptions.BusinessException("已经绑定里程碑的收款项不能绑定其它项目,请重新添加项目【" + receiptObj.ProjectInfoName + "】");
                }
                else if (receiptObj.FactReceiptValue > 0 && this.S_C_ManageContract_ProjectRelation.Count(d => d.ProjectID == receiptObj.ProjectInfo) == 0)
                {
                    throw new Formula.Exceptions.BusinessException("已经有过到款的收款项不能绑定其它项目,请重新添加项目【" + receiptObj.ProjectInfoName + "】");
                }
            }
            else
            {
            }
            receiptObj.SchyorPlanRecipet();
        }