Example #1
0
        public ResultModel Update(UserModel user, Operate.Model.Invoice invoice, FinanceInvoice fundsInvoice,string bids)
        {
            ResultModel result = new ResultModel();

            try
            {
                FinanceInvoiceDAL fundsInvoiceDAL = new FinanceInvoiceDAL();
                InvoiceDAL invoiceDAL = new InvoiceDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {

                    //获取财务发票
                    result = fundsInvoiceDAL.Get(user, fundsInvoice.FinanceInvoiceId);
                    if (result.ResultStatus != 0)
                        return result;

                    FinanceInvoice resultFundsInvoice = result.ReturnValue as FinanceInvoice;
                    if (resultFundsInvoice == null || resultFundsInvoice.FinanceInvoiceId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "财务发票获取失败";
                        return result;
                    }

                    //更新财务发票
                    resultFundsInvoice.AssetId = fundsInvoice.AssetId;
                    resultFundsInvoice.IntegerAmount = fundsInvoice.IntegerAmount;
                    resultFundsInvoice.NetAmount = fundsInvoice.NetAmount;
                    resultFundsInvoice.MUId = fundsInvoice.MUId;
                    resultFundsInvoice.VATRatio = fundsInvoice.VATRatio;
                    resultFundsInvoice.VATBala = fundsInvoice.VATBala;

                    result = fundsInvoiceDAL.Update(user, resultFundsInvoice);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取发票
                    result = invoiceDAL.Get(user, resultFundsInvoice.InvoiceId);
                    if (result.ResultStatus != 0)
                        return result;
                    Operate.Model.Invoice resultInvoice = result.ReturnValue as Operate.Model.Invoice;
                    if (resultInvoice == null || resultInvoice.InvoiceId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "发票信息获取失败";
                        return result;
                    }

                    resultInvoice.InvoiceDate = invoice.InvoiceDate;
                    resultInvoice.InvoiceName = invoice.InvoiceName;
                    resultInvoice.InvoiceBala = invoice.InvoiceBala;
                    resultInvoice.CurrencyId = invoice.CurrencyId;
                    resultInvoice.OutCorpId = invoice.OutCorpId;

                    Corporation outCorp = UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == invoice.OutCorpId);
                    if (outCorp == null || outCorp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "开票公司信息错误";
                        return result;
                    }
                    resultInvoice.OutCorpName = outCorp.CorpName;

                    resultInvoice.InCorpId = invoice.InCorpId;
                    Corporation inCorp = UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == invoice.InCorpId);
                    if (inCorp == null || inCorp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收票公司信息错误";
                        return result;
                    }
                    resultInvoice.InCorpName = inCorp.CorpName;
                    resultInvoice.Memo = invoice.Memo;

                    result = invoiceDAL.Update(user, resultInvoice);
                    if (result.ResultStatus != 0)
                        return result;

                    if (!string.IsNullOrEmpty(bids))
                    {
                        FinBusInvAllotDAL finBusInvAllotDAL = new FinBusInvAllotDAL();
                        FinBusInvAllotDetailDAL finBusInvAllotDetailDAL = new FinBusInvAllotDetailDAL();
                        result = finBusInvAllotDetailDAL.GetAllotIdByFid(user, fundsInvoice.FinanceInvoiceId);
                        if (result.ResultStatus != 0)
                            return result;

                        int allotId = (int)result.ReturnValue;

                        result = finBusInvAllotDAL.Get(user, allotId);
                        if (result.ResultStatus != 0)
                            return result;

                        FinBusInvAllot finBusInvAllot = result.ReturnValue as FinBusInvAllot;
                        finBusInvAllot.AllotBala = invoice.InvoiceBala;

                        result = finBusInvAllotDAL.Update(user, finBusInvAllot);
                        if (result.ResultStatus != 0)
                            return result;

                        result = finBusInvAllotDetailDAL.InvalidAll(user, allotId);
                        if (result.ResultStatus != 0)
                            return result;

                        foreach (string businessInvoiceId in bids.Split(','))
                        {
                            result = invoiceDAL.GetByBussinessInvoiceId(user, Convert.ToInt32(businessInvoiceId));
                            if (result.ResultStatus != 0)
                                return result;

                            Operate.Model.Invoice busInvoice = result.ReturnValue as Operate.Model.Invoice;

                            result = finBusInvAllotDetailDAL.Insert(user, new FinBusInvAllotDetail()
                            {
                                AllotId = allotId,
                                BusinessInvoiceId = Convert.ToInt32(businessInvoiceId),
                                FinanceInvoiceId = fundsInvoice.FinanceInvoiceId,
                                AllotBala = busInvoice.InvoiceBala,
                                DetailStatus = StatusEnum.已生效
                            });
                            if (result.ResultStatus != 0)
                                return result;
                        }

                    }

                    if (result.ResultStatus == 0)
                        result.ReturnValue = invoice.InvoiceId;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Example #2
0
        public ResultModel CreateByInvApply(UserModel user, Operate.Model.Invoice invoice, FinanceInvoice fundsInvoice, string bids, int invoiceApplyId)
        {
            ResultModel result = new ResultModel();

            try
            {
                FinanceInvoiceDAL fundsInvoiceDAL = new FinanceInvoiceDAL();
                InvoiceDAL invoiceDAL = new InvoiceDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //新增发票主表
                    int invoiceId = 0;

                    invoice.InvoiceType = (int)InvoiceTypeEnum.财务发票;

                    invoice.InvoiceStatus = StatusEnum.已录入;
                    Corporation outCorp = UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == invoice.OutCorpId);
                    if (outCorp == null || outCorp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "开票公司信息错误";
                        return result;
                    }
                    invoice.OutCorpName = outCorp.CorpName;
                    //invoice.OutBlocId = outCorp.b

                    Corporation inCorp = UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == invoice.InCorpId);
                    if (inCorp == null || inCorp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收票公司信息错误";
                        return result;
                    }
                    invoice.InCorpName = inCorp.CorpName;

                    result = invoiceDAL.Insert(user, invoice);
                    if (result.ResultStatus != 0)
                        return result;

                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out invoiceId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "发票添加失败";
                        return result;
                    }

                    //新增财务发票表
                    fundsInvoice.InvoiceId = invoiceId;
                    fundsInvoice.VATRatio = fundsInvoice.VATRatio;
                    result = fundsInvoiceDAL.Insert(user, fundsInvoice);
                    if (result.ResultStatus != 0)
                        return result;

                    int financeInvoiceId = (int)result.ReturnValue;

                    //财务发票业务发票分配
                    if (!string.IsNullOrEmpty(bids))
                    {
                        FinBusInvAllotDAL finBusInvAllotDAL = new FinBusInvAllotDAL();
                        result = finBusInvAllotDAL.Insert(user, new FinBusInvAllot()
                        {
                            AllotBala = invoice.InvoiceBala,
                            CurrencyId = invoice.CurrencyId,
                            Alloter = user.EmpId,
                            AllotDate = DateTime.Now,
                            AllotStatus = StatusEnum.已生效
                        });

                        if (result.ResultStatus != 0)
                            return result;

                        int allotId = (int)result.ReturnValue;

                        FinBusInvAllotDetailDAL finBusInvAllotDetailDAL = new FinBusInvAllotDetailDAL();
                        foreach (string businessInvoiceId in bids.Split(','))
                        {
                            result = invoiceDAL.GetByBussinessInvoiceId(user, Convert.ToInt32(businessInvoiceId));
                            if (result.ResultStatus != 0)
                                return result;

                            Operate.Model.Invoice busInvoice = result.ReturnValue as Operate.Model.Invoice;

                            result = finBusInvAllotDetailDAL.Insert(user, new FinBusInvAllotDetail()
                            {
                                AllotId = allotId,
                                BusinessInvoiceId = Convert.ToInt32(businessInvoiceId),
                                FinanceInvoiceId = financeInvoiceId,
                                AllotBala = busInvoice.InvoiceBala,
                                DetailStatus = StatusEnum.已生效
                            });
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    //添加开票申请与财务票关联
                    InvoiceApplyFinanceDAL invoiceApplyFinanceDAL = new InvoiceApplyFinanceDAL();
                    result = invoiceApplyFinanceDAL.Insert(user, new InvoiceApplyFinance()
                    {
                        InvoiceId = invoiceId,
                        FinanceInvoiceId = financeInvoiceId,
                        InvoiceApplyId = invoiceApplyId
                    });
                    if (result.ResultStatus != 0)
                        return result;

                    invoice.InvoiceId = invoiceId;
                    if (result.ResultStatus == 0) result.ReturnValue = invoice;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }