Beispiel #1
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;
        }
Beispiel #2
0
        public ResultModel Create(UserModel user, Operate.Model.Invoice invoice, FinanceInvoice fundsInvoice)
        {
            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;

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

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

            return result;
        }