public void AddFormPersonalReimburse(int?RejectedFormID, int UserID, int?ProxyUserID, int?ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, DateTime?Period, string Remark, string AttachedFileName, string RealAttachedFileName, string FlowTemplate) { SqlTransaction transaction = null; try { transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormPersonalReimburse, transaction); TableAdapterHelper.SetTransaction(this.TAFormPersonalReimburseDetail, transaction); FormDS.FormRow formRow = this.FormDataSet.Form.NewFormRow(); if (RejectedFormID != null) { formRow.RejectedFormID = RejectedFormID.GetValueOrDefault(); } formRow.UserID = UserID; UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); } else { formRow.SetFormNoNull(); } if (ProxyUserID != null) { formRow.ProxyUserID = ProxyUserID.GetValueOrDefault(); } if (ProxyPositionID != null) { formRow.ProxyPositionID = ProxyPositionID.GetValueOrDefault(); } formRow.OrganizationUnitID = OrganizationUnitID; formRow.PositionID = PositionID; formRow.FormTypeID = (int)FormTypeID; formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; formRow.InTurnUserIds = "P"; //待改动 formRow.InTurnPositionIds = "P"; //待改动 formRow.PageType = (int)SystemEnums.PageType.PersonalReimburseApply; this.FormDataSet.Form.AddFormRow(formRow); this.TAForm.Update(formRow); //处理申请表的内容 FormDS.FormPersonalReimburseRow formPersonalReimburseRow = this.FormDataSet.FormPersonalReimburse.NewFormPersonalReimburseRow(); formPersonalReimburseRow.FormPersonalReimburseID = formRow.FormID; formPersonalReimburseRow.Period = Period.GetValueOrDefault(); formPersonalReimburseRow.Amount = decimal.Zero; formPersonalReimburseRow.Remark = Remark; decimal[] calculateAssistant = this.GetPersonalBudgetByParameter(PositionID, Period); formPersonalReimburseRow.TotalBudget = calculateAssistant[0]; formPersonalReimburseRow.ApprovedAmount = calculateAssistant[1]; formPersonalReimburseRow.ApprovingAmount = calculateAssistant[2]; formPersonalReimburseRow.RemainAmount = calculateAssistant[3]; if (AttachedFileName != null) { formPersonalReimburseRow.AttachedFileName = AttachedFileName; } if (RealAttachedFileName != null) { formPersonalReimburseRow.RealAttachedFileName = RealAttachedFileName; } this.FormDataSet.FormPersonalReimburse.AddFormPersonalReimburseRow(formPersonalReimburseRow); this.TAFormPersonalReimburse.Update(formPersonalReimburseRow); //明细表 decimal totalAmount = 0;//计算总申请金额 if (RejectedFormID != null) { FormDS.FormPersonalReimburseDetailDataTable newDetailTable = new FormDS.FormPersonalReimburseDetailDataTable(); foreach (FormDS.FormPersonalReimburseDetailRow detailRow in this.FormDataSet.FormPersonalReimburseDetail) { if (detailRow.RowState != System.Data.DataRowState.Deleted) { FormDS.FormPersonalReimburseDetailRow newDetailRow = newDetailTable.NewFormPersonalReimburseDetailRow(); newDetailRow.FormPersonalReimburseID = formPersonalReimburseRow.FormPersonalReimburseID; newDetailRow.OccurDate = detailRow.OccurDate; newDetailRow.ExpenseManageTypeID = detailRow.ExpenseManageTypeID; newDetailRow.Amount = detailRow.Amount; newDetailRow.RealAmount = detailRow.RealAmount; if (!detailRow.IsRemarkNull()) { newDetailRow.Remark = detailRow.Remark; } totalAmount += newDetailRow.Amount; newDetailTable.AddFormPersonalReimburseDetailRow(newDetailRow); } } this.TAFormPersonalReimburseDetail.Update(newDetailTable); } else { foreach (FormDS.FormPersonalReimburseDetailRow detailRow in this.FormDataSet.FormPersonalReimburseDetail) { // 与父表绑定 if (detailRow.RowState != DataRowState.Deleted) { detailRow.FormPersonalReimburseID = formPersonalReimburseRow.FormPersonalReimburseID; totalAmount += detailRow.Amount; } } this.TAFormPersonalReimburseDetail.Update(this.FormDataSet.FormPersonalReimburseDetail); } formPersonalReimburseRow.Amount = totalAmount; this.TAFormPersonalReimburse.Update(formPersonalReimburseRow); // 正式提交或草稿 Dictionary <string, object> dic = new Dictionary <string, object>(); if (StatusID == SystemEnums.FormStatus.Awaiting) { //如果申请总额大于可用余额,不能提交 if (formPersonalReimburseRow.Amount > calculateAssistant[3]) //如果是减少预算,要做检查 { throw new ApplicationException("申请报销总额超出部门可用余额,不能提交!"); } dic["Apply_Amount"] = totalAmount;//金额 AuthorizationDS.OrganizationUnitDataTable OUTable = new AuthorizationDSTableAdapters.OrganizationUnitTableAdapter().GetOrganizationUnitCodeByOrganizationUnitID(formRow.OrganizationUnitID); if (OUTable.Count == 0) { throw new ApplicationException("没有找到您所在部门的流程,请联系管理员"); } dic["Department"] = OUTable[0].OrganizationUnitCode; APHelper AP = new APHelper(); new APFlowBLL().ApplyForm(AP, TAForm, RejectedFormID, formRow, OrganizationUnitID, FlowTemplate, StatusID, dic); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException(ex.Message); } finally { transaction.Dispose(); } }
public void AddFormPersonalReimburse(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, DateTime? Period, string Remark, decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount, decimal RemainAmount, string AttachedFileName, string RealAttachedFileName) { SqlTransaction transaction = null; try { transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormPersonalReimburse, transaction); TableAdapterHelper.SetTransaction(this.TAFormPersonalReimburseDetail, transaction); FormDS.FormRow formRow = this.FormDataSet.Form.NewFormRow(); if (RejectedFormID != null) { formRow.RejectedFormID = RejectedFormID.GetValueOrDefault(); } formRow.UserID = UserID; UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); } else { formRow.SetFormNoNull(); } if (ProxyUserID != null) { formRow.ProxyUserID = ProxyUserID.GetValueOrDefault(); } if (ProxyPositionID != null) { formRow.ProxyPositionID = ProxyPositionID.GetValueOrDefault(); } formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 formRow.OrganizationUnitID = OrganizationUnitID; formRow.PositionID = PositionID; formRow.FormTypeID = (int)FormTypeID; formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; formRow.PageType = (int)SystemEnums.PageType.FormPersonalReimburse; formRow.CostCenterID = new StuffUserBLL().GetCostCenterIDByPositionID(PositionID); formRow.IsCreateVoucher = false; formRow.IsExportLock = false; formRow.IsCompletePayment = false; this.FormDataSet.Form.AddFormRow(formRow); this.TAForm.Update(formRow); //处理申请表的内容 FormDS.FormPersonalReimburseRow formPersonalReimburseRow = this.FormDataSet.FormPersonalReimburse.NewFormPersonalReimburseRow(); formPersonalReimburseRow.FormPersonalReimburseID = formRow.FormID; if (Period != null) { formPersonalReimburseRow.Period = Period.GetValueOrDefault(); } formPersonalReimburseRow.Amount = decimal.Zero; formPersonalReimburseRow.Remark = Remark; formPersonalReimburseRow.TotalBudget = TotalBudget; formPersonalReimburseRow.ApprovedAmount = ApprovedAmount; formPersonalReimburseRow.ApprovingAmount = ApprovingAmount; formPersonalReimburseRow.RemainAmount = RemainAmount; if (AttachedFileName != null && AttachedFileName != string.Empty) { formPersonalReimburseRow.AttachedFileName = AttachedFileName; } if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) { formPersonalReimburseRow.RealAttachedFileName = RealAttachedFileName; } this.FormDataSet.FormPersonalReimburse.AddFormPersonalReimburseRow(formPersonalReimburseRow); this.TAFormPersonalReimburse.Update(formPersonalReimburseRow); //明细表 decimal totalAmountRMB = 0;//计算总申请金额 if (RejectedFormID != null) { FormDS.FormPersonalReimburseDetailDataTable newDetailTable = new FormDS.FormPersonalReimburseDetailDataTable(); foreach (FormDS.FormPersonalReimburseDetailRow detailRow in this.FormDataSet.FormPersonalReimburseDetail) { if (detailRow.RowState != System.Data.DataRowState.Deleted) { FormDS.FormPersonalReimburseDetailRow newDetailRow = newDetailTable.NewFormPersonalReimburseDetailRow(); newDetailRow.FormPersonalReimburseID = formPersonalReimburseRow.FormPersonalReimburseID; newDetailRow.OccurDate = detailRow.OccurDate; newDetailRow.ManageExpenseItemID = detailRow.ManageExpenseItemID; newDetailRow.ApplyAmount = detailRow.ApplyAmount; newDetailRow.RMB = detailRow.RMB; newDetailRow.CurrencyID = detailRow.CurrencyID; newDetailRow.ExchangeRate = detailRow.ExchangeRate; if (!detailRow.IsRemarkNull()) { newDetailRow.Remark = detailRow.Remark; } totalAmountRMB += newDetailRow.RMB; newDetailTable.AddFormPersonalReimburseDetailRow(newDetailRow); } } this.TAFormPersonalReimburseDetail.Update(newDetailTable); } else { foreach (FormDS.FormPersonalReimburseDetailRow detailRow in this.FormDataSet.FormPersonalReimburseDetail) { // 与父表绑定 if (detailRow.RowState != DataRowState.Deleted) { detailRow.FormPersonalReimburseID = formPersonalReimburseRow.FormPersonalReimburseID; totalAmountRMB += detailRow.RMB; } } this.TAFormPersonalReimburseDetail.Update(this.FormDataSet.FormPersonalReimburseDetail); } formPersonalReimburseRow.Amount = totalAmountRMB; this.TAFormPersonalReimburse.Update(formPersonalReimburseRow); // 正式提交或草稿 if (StatusID == SystemEnums.FormStatus.Awaiting) { Dictionary<string, object> dic = new Dictionary<string, object>(); dic["TotalAmount"] = totalAmountRMB; APResult result = new APFlowBLL().CreateProcess(new APParameter(formRow.FormID, formRow.FormNo, formRow.OrganizationUnitID, formRow.UserID, (int)StatusID, formRow.FormTypeID, formRow.PositionID, dic)); if (result != null) { formRow.InTurnPositionIds = result.InTurnPositionIds; formRow.InTurnUserIds = result.InTurnUserIds; formRow.SubmitDate = result.ApprovedDate.GetValueOrDefault(); formRow.StatusID = result.StatusID; formRow.ProcID = result.ProcID; formRow.FinanceRemark = formPersonalReimburseRow.Remark; this.TAForm.Update(formRow); } } //作废之前的单据 if (RejectedFormID != null) { FormDS.FormRow oldRow = TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0]; if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) { new APFlowBLL().ScrapForm(oldRow.FormID); } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException(ex.Message); } finally { transaction.Dispose(); } }
/// <summary> /// 个人费用报销 /// </summary> /// <param name="FormID"></param> /// <returns></returns> private bool ExportPersonalReimburseDataByFormID(int FormID, int logId) { ExportDataDS.ExportDataDataTable l_dtExportData = new ExportDataDS.ExportDataDataTable(); FormDS.FormPersonalReimburseDetailDataTable l_dtPersonalReimburseDetail = new FormDS.FormPersonalReimburseDetailDataTable(); FormMarketingBLL formmarkbll = new FormMarketingBLL(); FormTEBLL formtebll = new FormTEBLL(); StuffUserBLL stuffuserdll = new StuffUserBLL(); MasterDataBLL masterdatabll = new MasterDataBLL(); FormDS.FormDataTable l_dtform = formmarkbll.GetFormByID(FormID); FormDS.FormRow l_drform = l_dtform.NewFormRow(); try { if (l_dtform.Rows.Count > 0) { l_drform = l_dtform[0]; if (l_drform.IsFinanceRemarkNull()) { logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:财务摘要为空,导出失败!"); return false; } l_dtPersonalReimburseDetail = formtebll.GetFormPersonalReimburseDetailByFormPersonalReimburseID(l_drform.FormID); int i = 0; FormDS.FormPersonalReimburseDataTable l_dtPersonalReimburse = formtebll.GetFormPersonalReimburseByID(l_drform.FormID); foreach (FormDS.FormPersonalReimburseDetailRow l_drtemp in l_dtPersonalReimburseDetail) { ExportDataDS.ExportDataRow l_drExportData = l_dtExportData.NewExportDataRow(); l_drExportData.FormID = FormID; l_drExportData.VendorCode = stuffuserdll.GetStuffUserById(l_drform.UserID)[0].VendorCode; l_drExportData.CompanyCode = masterdatabll.GetCompanyById(masterdatabll.GetCostCenterById(l_drform.CostCenterID).CompanyID).CompanyCode; if (l_drExportData.IsVendorCodeNull() || string.IsNullOrEmpty(l_drExportData.VendorCode)) { logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:Vendor Code为空,无法导出!"); return false; } //如果Vendor Code的公司和成本中心的公司不一致,则报错 MasterData.VendorDataTable tbVendor = new BusinessObjects.MasterDataTableAdapters.VendorTableAdapter().GetDataByVendorCode(l_drExportData.VendorCode); if (tbVendor.Rows.Count > 0) { string vendorCompanyCode = masterdatabll.GetCompanyById(tbVendor[0].CompanyID).CompanyCode; if (l_drExportData.CompanyCode != vendorCompanyCode) { logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:Company Code不符,请检查!"); return false; } } l_drExportData.Reference = ""; l_drExportData.Invoice = l_drform.FormNo; l_drExportData.Invoicedate = l_drform.SubmitDate.ToString("yyyyMMdd"); l_drExportData.TotalMoney = l_dtPersonalReimburse[0].Amount; //l_drExportData.Currency = masterdatabll.GetCurrencyByID(l_drtemp.CurrencyID).CurrencyShortName; //l_drExportData.ExchangeRate = l_drtemp.ExchangeRate; l_drExportData.ManageExpenseItem = masterdatabll.GetManageExpenseItemById(l_drtemp.ManageExpenseItemID).ManageExpenseItemName; l_drExportData.CostCenter = masterdatabll.GetCostCenterById(l_drform.CostCenterID).CostCenterCode; l_drExportData.AccountCode = masterdatabll.GetAccountingCodeByExpenseItemAndCostCenter(l_drtemp.ManageExpenseItemID, l_drform.CostCenterID); l_drExportData.DetailMoney = l_drtemp.RMB; l_drExportData.PONumber = 0; l_drExportData.POLineNumber = "0"; l_drExportData.FinanceRemark = l_drform.FinanceRemark; l_drExportData.FormNo = l_drform.FormNo; l_drExportData.TaxRateCode = masterdatabll.GetVatTypeById(1)[0].VatTypeName; l_drExportData.TaxAmt = 0; l_dtExportData.AddExportDataRow(l_drExportData); i++; } if (l_dtExportData.Rows.Count == 0) { logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:无明细数据,无法导出!"); return false; } if (l_dtExportData.Rows.Count == l_dtPersonalReimburseDetail.Rows.Count) { ExportByFormView(l_dtExportData); } else { logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:导出数据与明细数据数量不一致!"); return false; } } } catch (Exception e) { logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:" + e.Message); return false; } return true; }
public void AddFormPersonalReimburse(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, DateTime? Period, string Remark, string AttachedFileName, string RealAttachedFileName, string FlowTemplate) { SqlTransaction transaction = null; try { transaction = TableAdapterHelper.BeginTransaction(this.TAForm); TableAdapterHelper.SetTransaction(this.TAFormPersonalReimburse, transaction); TableAdapterHelper.SetTransaction(this.TAFormPersonalReimburseDetail, transaction); FormDS.FormRow formRow = this.FormDataSet.Form.NewFormRow(); if (RejectedFormID != null) { formRow.RejectedFormID = RejectedFormID.GetValueOrDefault(); } formRow.UserID = UserID; UtilityBLL utility = new UtilityBLL(); if (StatusID == SystemEnums.FormStatus.Awaiting) { string formTypeString = utility.GetFormTypeString((int)FormTypeID); formRow.FormNo = utility.GetFormNo(formTypeString); } else { formRow.SetFormNoNull(); } if (ProxyUserID != null) { formRow.ProxyUserID = ProxyUserID.GetValueOrDefault(); } if (ProxyPositionID != null) { formRow.ProxyPositionID = ProxyPositionID.GetValueOrDefault(); } formRow.OrganizationUnitID = OrganizationUnitID; formRow.PositionID = PositionID; formRow.FormTypeID = (int)FormTypeID; formRow.StatusID = (int)StatusID; formRow.SubmitDate = DateTime.Now; formRow.LastModified = DateTime.Now; formRow.InTurnUserIds = "P";//待改动 formRow.InTurnPositionIds = "P";//待改动 formRow.PageType = (int)SystemEnums.PageType.PersonalReimburseApply; this.FormDataSet.Form.AddFormRow(formRow); this.TAForm.Update(formRow); //处理申请表的内容 FormDS.FormPersonalReimburseRow formPersonalReimburseRow = this.FormDataSet.FormPersonalReimburse.NewFormPersonalReimburseRow(); formPersonalReimburseRow.FormPersonalReimburseID = formRow.FormID; formPersonalReimburseRow.Period = Period.GetValueOrDefault(); formPersonalReimburseRow.Amount = decimal.Zero; formPersonalReimburseRow.Remark = Remark; decimal[] calculateAssistant = this.GetPersonalBudgetByParameter(PositionID, Period); formPersonalReimburseRow.TotalBudget = calculateAssistant[0]; formPersonalReimburseRow.ApprovedAmount = calculateAssistant[1]; formPersonalReimburseRow.ApprovingAmount = calculateAssistant[2]; formPersonalReimburseRow.RemainAmount = calculateAssistant[3]; if (AttachedFileName != null) { formPersonalReimburseRow.AttachedFileName = AttachedFileName; } if (RealAttachedFileName != null) { formPersonalReimburseRow.RealAttachedFileName = RealAttachedFileName; } this.FormDataSet.FormPersonalReimburse.AddFormPersonalReimburseRow(formPersonalReimburseRow); this.TAFormPersonalReimburse.Update(formPersonalReimburseRow); //明细表 decimal totalAmount = 0;//计算总申请金额 if (RejectedFormID != null) { FormDS.FormPersonalReimburseDetailDataTable newDetailTable = new FormDS.FormPersonalReimburseDetailDataTable(); foreach (FormDS.FormPersonalReimburseDetailRow detailRow in this.FormDataSet.FormPersonalReimburseDetail) { if (detailRow.RowState != System.Data.DataRowState.Deleted) { FormDS.FormPersonalReimburseDetailRow newDetailRow = newDetailTable.NewFormPersonalReimburseDetailRow(); newDetailRow.FormPersonalReimburseID = formPersonalReimburseRow.FormPersonalReimburseID; newDetailRow.OccurDate = detailRow.OccurDate; newDetailRow.ExpenseManageTypeID = detailRow.ExpenseManageTypeID; newDetailRow.Amount = detailRow.Amount; newDetailRow.RealAmount = detailRow.RealAmount; if (!detailRow.IsRemarkNull()) { newDetailRow.Remark = detailRow.Remark; } totalAmount += newDetailRow.Amount; newDetailTable.AddFormPersonalReimburseDetailRow(newDetailRow); } } this.TAFormPersonalReimburseDetail.Update(newDetailTable); } else { foreach (FormDS.FormPersonalReimburseDetailRow detailRow in this.FormDataSet.FormPersonalReimburseDetail) { // 与父表绑定 if (detailRow.RowState != DataRowState.Deleted) { detailRow.FormPersonalReimburseID = formPersonalReimburseRow.FormPersonalReimburseID; totalAmount += detailRow.Amount; } } this.TAFormPersonalReimburseDetail.Update(this.FormDataSet.FormPersonalReimburseDetail); } formPersonalReimburseRow.Amount = totalAmount; this.TAFormPersonalReimburse.Update(formPersonalReimburseRow); // 正式提交或草稿 Dictionary<string, object> dic = new Dictionary<string, object>(); if (StatusID == SystemEnums.FormStatus.Awaiting) { //如果申请总额大于可用余额,不能提交 if (formPersonalReimburseRow.Amount > calculateAssistant[3]) {//如果是减少预算,要做检查 throw new ApplicationException("申请报销总额超出部门可用余额,不能提交!"); } dic["Apply_Amount"] = totalAmount;//金额 AuthorizationDS.OrganizationUnitDataTable OUTable = new AuthorizationDSTableAdapters.OrganizationUnitTableAdapter().GetOrganizationUnitCodeByOrganizationUnitID(formRow.OrganizationUnitID); if (OUTable.Count == 0) { throw new ApplicationException("没有找到您所在部门的流程,请联系管理员"); } dic["Department"] = OUTable[0].OrganizationUnitCode; APHelper AP = new APHelper(); new APFlowBLL().ApplyForm(AP, TAForm, RejectedFormID, formRow, OrganizationUnitID, FlowTemplate, StatusID, dic); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new ApplicationException(ex.Message); } finally { transaction.Dispose(); } }