Exemple #1
0
        /// <summary>
        /// 差旅费报销
        /// </summary>
        /// <param name="FormID"></param>
        /// <returns></returns>
        private bool ExportTravelReimburseDataByFormID(int FormID, int logId)
        {
            ExportDataDS.ExportDataDataTable l_dtExportData = new ExportDataDS.ExportDataDataTable();
            FormDS.FormTravelReimburseDetailDataTable l_dtTravelReimburseDetail = new FormDS.FormTravelReimburseDetailDataTable();
            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_dtTravelReimburseDetail = formtebll.GetFormTravelReimburseDetailByFormTravelReimburseID(l_drform.FormID);
                    int i = 0;
                    FormDS.FormTravelReimburseDataTable l_dtTravelReimburse = formtebll.GetFormTravelReimburseByID(l_drform.FormID);
                    decimal TotalMoney = l_dtTravelReimburse[0].Amount;
                    foreach (FormDS.FormTravelReimburseDetailRow l_drtemp in l_dtTravelReimburseDetail) {
                        if (l_drtemp.PayMan == 1) {
                            TotalMoney = TotalMoney - l_drtemp.Cost;
                        }
                    }
                    foreach (FormDS.FormTravelReimburseDetailRow l_drtemp in l_dtTravelReimburseDetail) {
                        if (l_drtemp.PayMan != 1) {
                            ExportDataDS.ExportDataRow l_drExportData = l_dtExportData.NewExportDataRow();
                            l_drExportData.FormID = FormID;
                            l_drExportData.CompanyCode = masterdatabll.GetCompanyById(masterdatabll.GetCostCenterById(l_drform.CostCenterID).CompanyID).CompanyCode;
                            l_drExportData.VendorCode = stuffuserdll.GetStuffUserById(l_drform.UserID)[0].VendorCode;
                            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 = TotalMoney;
                            //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);
                            //公司支付的金额为0
                            l_drExportData.DetailMoney = l_drtemp.Cost;
                            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 == i) {
                        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;
        }
Exemple #2
0
        public void AddFormTravelReimburse(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.TAFormTravelReimburse, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormTravelReimburseDetail, 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.TravelReimburseApply;
                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.FormTravelReimburseRow formTravelReimburseRow = this.FormDataSet.FormTravelReimburse.NewFormTravelReimburseRow();
                formTravelReimburseRow.FormTravelReimburseID = formRow.FormID;
                if (Period != null) {
                    formTravelReimburseRow.Period = Period.GetValueOrDefault();
                }

                formTravelReimburseRow.Amount = decimal.Zero;
                formTravelReimburseRow.Remark = Remark;
                formTravelReimburseRow.TotalBudget = TotalBudget;
                formTravelReimburseRow.ApprovedAmount = ApprovedAmount;
                formTravelReimburseRow.ApprovingAmount = ApprovingAmount;
                formTravelReimburseRow.RemainAmount = RemainAmount;
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formTravelReimburseRow.AttachedFileName = AttachedFileName;
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formTravelReimburseRow.RealAttachedFileName = RealAttachedFileName;
                }
                this.FormDataSet.FormTravelReimburse.AddFormTravelReimburseRow(formTravelReimburseRow);
                this.TAFormTravelReimburse.Update(formTravelReimburseRow);

                //明细表
                decimal totalAmountRMB = 0;//计算总申请金额

                if (RejectedFormID != null) {
                    FormDS.FormTravelReimburseDetailDataTable newDetailTable = new FormDS.FormTravelReimburseDetailDataTable();
                    foreach (FormDS.FormTravelReimburseDetailRow detailRow in this.FormDataSet.FormTravelReimburseDetail) {
                        if (detailRow.RowState != System.Data.DataRowState.Deleted) {
                            FormDS.FormTravelReimburseDetailRow newDetailRow = newDetailTable.NewFormTravelReimburseDetailRow();
                            newDetailRow.FormTravelReimburseID = formTravelReimburseRow.FormTravelReimburseID;
                            newDetailRow.OccurDate = detailRow.OccurDate;
                            newDetailRow.ManageExpenseItemID = detailRow.ManageExpenseItemID;
                            newDetailRow.Cost = detailRow.Cost;
                            newDetailRow.CityID = detailRow.CityID;
                            newDetailRow.CurrencyID = detailRow.CurrencyID;
                            newDetailRow.Destination = detailRow.Destination;
                            newDetailRow.Frequency = detailRow.Frequency;
                            newDetailRow.UnitPrice = detailRow.UnitPrice;
                            newDetailRow.ExchangeRate = detailRow.ExchangeRate;
                            newDetailRow.PayMan = detailRow.PayMan;

                            if (!detailRow.IsRemarkNull()) {
                                newDetailRow.Remark = detailRow.Remark;
                            }
                            totalAmountRMB += newDetailRow.Cost;
                            newDetailTable.AddFormTravelReimburseDetailRow(newDetailRow);
                        }
                    }
                    this.TAFormTravelReimburseDetail.Update(newDetailTable);
                } else {
                    foreach (FormDS.FormTravelReimburseDetailRow detailRow in this.FormDataSet.FormTravelReimburseDetail) {
                        // 与父表绑定
                        if (detailRow.RowState != DataRowState.Deleted) {
                            detailRow.FormTravelReimburseID = formTravelReimburseRow.FormTravelReimburseID;
                            totalAmountRMB += detailRow.Cost;
                        }
                    }
                    this.TAFormTravelReimburseDetail.Update(this.FormDataSet.FormTravelReimburseDetail);
                }

                formTravelReimburseRow.Amount = totalAmountRMB;
                this.TAFormTravelReimburse.Update(formTravelReimburseRow);

                // 正式提交或草稿
                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 = formTravelReimburseRow.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();
            }
        }