Example #1
0
        /// <summary>
        /// 导出凭证清单
        /// </summary>
        /// <param name="searchValue"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public FileResult ExportTripReimbursementByCondition(string searchValue, DateTime?startTime, DateTime?endTime, string status)
        {
            List <ApiExpenseReimbursementEntity> list = new List <ApiExpenseReimbursementEntity>();
            int total    = 0;
            var dataList = GetSearchTripReimbursementList(inn, Userinfo.Roles, out total, null, startTime, endTime, searchValue, status, Userinfo.UserName);

            if (dataList != null)
            {
                foreach (var item in dataList)
                {
                    if (string.IsNullOrEmpty(item.status))
                    {
                        item.status = "End";
                    }

                    if (item.status == "Expense Accountant Creation" || item.status == "End")
                    {
                        List <ApiExpenseReimbursementEntity> datas = TripReimbursementBll.SendTripReimbursementCreation(inn, item.id);
                        if (datas != null)
                        {
                            List <ApiExpenseReimbursementEntity> newApiEntity = new List <ApiExpenseReimbursementEntity>();
                            foreach (var data in datas)
                            {
                                if (data.b_TaxRate > 0)
                                {
                                    int             rateInt         = int.Parse((data.b_TaxRate.Value * double.Parse("100")).ToString());
                                    TaxCodeTypeList?obj             = EnumDescription.GetEnumByValue <TaxCodeTypeList>(rateInt);
                                    string          textDescription = EnumDescription.GetFieldText(obj);
                                    //根据描述获取对应的科目
                                    string subject = TaxCodeConfigureBll.GeTaxCodeConfigureByText(textDescription);

                                    data.DMBTR = data.b_TaxFreeAmount;
                                    ApiExpenseReimbursementEntity entity = new ApiExpenseReimbursementEntity();
                                    entity.BUKRS  = data.BUKRS;
                                    entity.XBLNR  = data.XBLNR;
                                    entity.BLDAT  = data.BLDAT;
                                    entity.BUDAT  = data.BUDAT;
                                    entity.BKTXT  = data.BKTXT;
                                    entity.NUMPG  = data.NUMPG;
                                    entity.PROTYP = data.PROTYP;
                                    entity.POSID  = data.POSID;
                                    entity.HKONT  = subject;
                                    entity.DMBTR  = data.b_Tax;
                                    entity.KOSTL  = "";
                                    entity.SGTXT  = data.SGTXT;
                                    entity.AUFNR  = data.AUFNR;
                                    newApiEntity.Add(data);
                                    newApiEntity.Add(entity);
                                }
                                else
                                {
                                    newApiEntity.Add(data);
                                }
                            }

                            //计算合计金额
                            ApiExpenseReimbursementEntity totalEntity = new ApiExpenseReimbursementEntity();
                            totalEntity.BUKRS = newApiEntity.First().BUKRS;
                            totalEntity.XBLNR = newApiEntity.First().XBLNR;
                            totalEntity.BLDAT = newApiEntity.First().BLDAT;
                            totalEntity.BUDAT = newApiEntity.First().BUDAT;
                            totalEntity.BKTXT = newApiEntity.First().b_StaffNo;
                            totalEntity.HKONT = "2241999999";
                            totalEntity.DMBTR = newApiEntity.Select(x => x.DMBTR).Sum();
                            newApiEntity.Add(totalEntity);
                            list.AddRange(newApiEntity);
                        }
                    }
                }
            }

            Stream ms = ExportTripReimbursementByData(list);

            return(File(ms, "application/vnd.ms-excel", "凭证清单" + ".xls"));
        }