示例#1
0
        /// <summary>
        /// 开票
        /// </summary>
        public void Submit()
        {
            var user           = Formula.FormulaHelper.GetUserInfo();
            var marketEntities = this.GetMarketContext();

            var receipt = marketEntities.Set <S_C_Receipt>().Find(this.ReceiptID);

            if (receipt == null)
            {
                throw new Formula.Exceptions.BusinessException("未找到ID为【" + this.ReceiptID + "】的收款项,无法完成补开流程");
            }
            if (this.State != InvoiceApplyState.Wait.ToString())
            {
                throw new Formula.Exceptions.BusinessException("只能对流程通过且未进行开票动作的发票进行开票操作");
            }
            var invoice = new S_C_Invoice();

            marketEntities.S_C_Invoice.Add(invoice);
            invoice.PayerUnitIDName = this.PayerUnitName;
            invoice.PayerUnit       = this.PayerUnitName;
            invoice.PayerUnitID     = this.PayerUnit;
            invoice.Amount          = Convert.ToDecimal(this.Amount);
            var customerInfo = marketEntities.S_F_Customer.FirstOrDefault(c => c.ID == this.PayerUnit);

            if (customerInfo == null)
            {
                throw new Formula.Exceptions.BusinessValidationException("没有找到指定的客户信息,无法开票");
            }
            invoice.CustomerFullID     = customerInfo.FullID;
            invoice.ContractInfoID     = this.Contract;
            invoice.InvoiceType        = this.InvoiceType;
            invoice.InvoiceDate        = DateTime.Now;
            invoice.CreateDate         = DateTime.Now;
            invoice.CreateUser         = user.UserName;
            invoice.CreateUserID       = user.UserID;
            invoice.InvoiceMaker       = user.UserName;
            invoice.InvoiceCode        = this.InvoiceCode;
            invoice.InvoiceMakerID     = user.UserID;
            invoice.InvoiceMakerIDName = user.UserName;
            invoice.BankName           = this.BankName;
            invoice.BankAccount        = this.BankAccount;
            invoice.TaxAccount         = this.TaxAccount;
            invoice.InvoiceName        = this.InvoiceName;
            invoice.TaxRate            = this.TaxRate;
            invoice.ClearAmount        = this.ClearValue;
            invoice.TaxesAmount        = this.TaxValue;
            invoice.TaxName            = this.TaxName;
            invoice.State = InvoiceState.Normal.ToString();
            invoice.Save();
            foreach (var item in this.T_C_InvoiceMakeUpApply_Detail.ToList())
            {
                var relationValue = item.ApplyInvoiceAmount.HasValue ? item.ApplyInvoiceAmount.Value : 0;
                invoice.RelateToReceiptObject(item.PlanReceiptID, relationValue);
            }

            this.State = InvoiceApplyState.Complete.ToString();
            receipt.RelateToInvoice(invoice);
        }
示例#2
0
        /// <summary>
        /// 开票
        /// </summary>
        public void Submit()
        {
            var user           = Formula.FormulaHelper.GetUserInfo();
            var marketEntities = this.GetMarketContext();

            if (this.State != InvoiceApplyState.Wait.ToString())
            {
                throw new Formula.Exceptions.BusinessException("只能对流程通过且未进行开票动作的发票进行开票操作");
            }
            var invoice = new S_C_Invoice();

            marketEntities.S_C_Invoice.Add(invoice);
            invoice.ID = this.ID;
            invoice.PayerUnitIDName = this.PayerUnitName;
            invoice.PayerUnit       = this.PayerUnitName;
            invoice.PayerUnitID     = this.PayerUnit;
            invoice.Amount          = -Convert.ToDecimal(this.Amount);//红冲票对应收款为相反数
            var customerInfo = marketEntities.S_F_Customer.FirstOrDefault(c => c.ID == this.PayerUnit);

            if (customerInfo == null)
            {
                throw new Formula.Exceptions.BusinessValidationException("没有找到指定的客户信息,无法开票");
            }
            invoice.CustomerFullID     = customerInfo.FullID;
            invoice.ContractInfoID     = this.Contract;
            invoice.InvoiceDate        = DateTime.Now;
            invoice.CreateDate         = DateTime.Now;
            invoice.CreateUser         = user.UserName;
            invoice.CreateUserID       = user.UserID;
            invoice.InvoiceMaker       = user.UserName;
            invoice.InvoiceCode        = this.InvoiceCode;
            invoice.InvoiceType        = Market.Logic.InvoiceType.CreditNote.ToString();
            invoice.InvoiceMakerID     = user.UserID;
            invoice.InvoiceMakerIDName = user.UserName;
            invoice.TaxRate            = this.TaxRate;
            invoice.BankName           = this.BankName;
            invoice.BankAccount        = this.BankAccount;
            invoice.TaxAccount         = this.TaxAccount;
            invoice.InvoiceName        = this.InvoiceName;
            invoice.State = InvoiceState.Normal.ToString();
            invoice.Save();//  invoice.Amount = -Convert.ToDecimal(this.Amount);//红冲票对应收款为相反数 save没问题!


            foreach (var item in this.T_C_CreditNoteApply_Detail.ToList())
            {
                var relationValue = item.CreditValue.HasValue ? item.CreditValue.Value : 0;
                var entities      = this.GetMarketContext();
                var plan          = entities.S_C_ManageContract_ReceiptObj.SingleOrDefault(d => d.ID == item.PlanReceiptID);
                if (plan == null)
                {
                    throw new Formula.Exceptions.BusinessException("未能找到ID为【" + item.PlanReceiptID + "】的计划收款对象,无法进行关联操作");
                }

                RelateToReceiptObject(invoice, plan, relationValue);
            }
            this.State = InvoiceApplyState.Complete.ToString();
        }