Пример #1
0
    private void showReport()
    {
        Microsoft.Reporting.WebForms.ReportParameter[] ps = new Microsoft.Reporting.WebForms.ReportParameter[1];
        string reportName = Request["ReportName"];
        if(string.IsNullOrEmpty(reportName)){
            return;
        }
        string formID = this.Request["FormID"].ToString();
        //��ȡ����������Ա������ʱ��
        APFlowBLL ap = new APFlowBLL();
        //string approverName = ap.GetApprovalInfoByFormID(Int16.Parse(formID));
        ps[0] = new Microsoft.Reporting.WebForms.ReportParameter("FormID", formID);
        //ps[1] = new Microsoft.Reporting.WebForms.ReportParameter("ApproverName", approverName);

        //load report
        this.ReportViewer.LoadReport(reportName, ps);
    }
Пример #2
0
        public void UpdateRDPayment(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, int InvoiceStatusID, int PaymentTypeID, string PaymentFileName, string PaymentRealFileName, string Remark, int? VATTypeID, int FormPOID)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormRDPayment, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormRDPaymentDetail, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormInvoice, transaction);

                FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0];
                FormDS.FormRDPaymentRow formPaymentRow = this.TAFormRDPayment.GetDataByID(FormID)[0];

                //处理单据的内容
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                    formRow.InTurnUserIds = "P";//待改动
                    formRow.InTurnPositionIds = "P";//待改动
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;

                this.TAForm.Update(formRow);

                //处理Payment的内容
                if (PaymentFileName != null && PaymentFileName != string.Empty) {
                    formPaymentRow.PaymentFileName = PaymentFileName;
                }
                if (PaymentRealFileName != null && PaymentRealFileName != string.Empty) {
                    formPaymentRow.PaymentRealFileName = PaymentRealFileName;
                }
                if (Remark != null && Remark != string.Empty) {
                    formPaymentRow.Remark = Remark;
                }
                formPaymentRow.InvoiceStatusID = InvoiceStatusID;
                formPaymentRow.PaymentTypeID = PaymentTypeID;
                if (VATTypeID != null) {
                    formPaymentRow.VATTypeID = VATTypeID.GetValueOrDefault();
                }
                if (FormPOID > 0) {
                    formPaymentRow.FormPOID = FormPOID;
                }
                this.TAFormRDPayment.Update(formPaymentRow);

                //发票
                foreach (FormDS.FormInvoiceRow invoiceRow in this.FormDataSet.FormInvoice) {
                    // 与父表绑定
                    if (invoiceRow.RowState != DataRowState.Deleted) {
                        invoiceRow.FormID = formPaymentRow.FormRDPaymentID;
                    }
                }
                this.TAFormInvoice.Update(this.FormDataSet.FormInvoice);

                //处理明细
                decimal totalAmountRMB = 0;
                decimal totalAmountBeforeTaxtRMB = 0;
                foreach (FormDS.FormRDPaymentDetailRow detailRow in this.FormDataSet.FormRDPaymentDetail) {
                    if (detailRow.RowState != DataRowState.Deleted) {
                        totalAmountRMB += detailRow.AmountRMB;
                        totalAmountBeforeTaxtRMB += detailRow.IsAmountBeforeTaxNull() ? 0 : detailRow.AmountBeforeTax;
                        detailRow.FormRDPaymentID = formPaymentRow.FormRDPaymentID;
                    }
                }
                this.TAFormRDPaymentDetail.Update(this.FormDataSet.FormRDPaymentDetail);

                formPaymentRow.AmountRMB = totalAmountRMB;
                formPaymentRow.AmountBeforeTaxRMB = totalAmountBeforeTaxtRMB;

                this.TAFormRDPayment.Update(formPaymentRow);
                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    dic["PaymentTypeID"] = PaymentTypeID;
                    dic["InvoiceStatus"] = formPaymentRow.InvoiceStatusID;
                    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 = formPaymentRow.Remark;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();

            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #3
0
        public void AddRDPayment(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        SystemEnums.PageType PageType, int FormRDApplyID, int InvoiceStatusID, int PaymentTypeID, string PaymentFileName, string PaymentRealFileName, string Remark, int CostCenterID, int? VATTypeID, int FormPOID)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormRDPayment, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormRDPaymentDetail, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormInvoice, transaction);

                //处理Form的内容
                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)PageType;
                formRow.CostCenterID = CostCenterID;
                formRow.IsCreateVoucher = false;
                formRow.IsExportLock = false;
                formRow.IsCompletePayment = false;
                formRow.IsInvoiceReturned = false;
                this.FormDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理Payment的内容
                FormDS.FormRDPaymentRow formPaymentRow = this.FormDataSet.FormRDPayment.NewFormRDPaymentRow();
                formPaymentRow.FormRDPaymentID = formRow.FormID;
                formPaymentRow.FormRDApplyID = FormRDApplyID;
                formPaymentRow.InvoiceStatusID = InvoiceStatusID;
                formPaymentRow.PaymentTypeID = PaymentTypeID;
                if (PaymentFileName != null && PaymentFileName != string.Empty) {
                    formPaymentRow.PaymentFileName = PaymentFileName;
                }
                if (PaymentRealFileName != null && PaymentRealFileName != string.Empty) {
                    formPaymentRow.PaymentRealFileName = PaymentRealFileName;
                }
                if (Remark != null && Remark != string.Empty) {
                    formPaymentRow.Remark = Remark;
                }
                formPaymentRow.AmountRMB = 0;
                if (VATTypeID != null) {
                    formPaymentRow.VATTypeID = VATTypeID.GetValueOrDefault();
                }
                if (FormPOID > 0) {
                    formPaymentRow.FormPOID = FormPOID;
                }

                this.FormDataSet.FormRDPayment.AddFormRDPaymentRow(formPaymentRow);
                this.TAFormRDPayment.Update(formPaymentRow);

                //发票
                if (RejectedFormID != null) {
                    FormDS.FormInvoiceDataTable newInvoiceTable = new FormDS.FormInvoiceDataTable();
                    foreach (FormDS.FormInvoiceRow invoiceRow in this.FormDataSet.FormInvoice) {
                        if (invoiceRow.RowState != DataRowState.Deleted) {
                            FormDS.FormInvoiceRow newInvoiceRow = newInvoiceTable.NewFormInvoiceRow();
                            newInvoiceRow.FormID = formPaymentRow.FormRDPaymentID;
                            newInvoiceRow.InvoiceNo = invoiceRow.InvoiceNo;
                            newInvoiceRow.InvoiceDate = invoiceRow.InvoiceDate;
                            newInvoiceRow.InvoiceAmount = invoiceRow.InvoiceAmount;
                            newInvoiceRow.Remark = invoiceRow.IsRemarkNull() ? "" : invoiceRow.Remark;
                            newInvoiceRow.SystemInfo = invoiceRow.IsSystemInfoNull() ? "" : invoiceRow.SystemInfo;
                            newInvoiceTable.AddFormInvoiceRow(newInvoiceRow);
                        }
                        this.TAFormInvoice.Update(newInvoiceTable);
                    }
                } else {
                    foreach (FormDS.FormInvoiceRow invoiceRow in this.FormDataSet.FormInvoice) {
                        // 与父表绑定
                        if (invoiceRow.RowState != DataRowState.Deleted) {
                            invoiceRow.FormID = formPaymentRow.FormRDPaymentID;
                        }
                    }
                }
                this.TAFormInvoice.Update(this.FormDataSet.FormInvoice);

                //处理明细
                //先取得方案申请单
                FormDS.FormRDApplyRow rowRDApply = this.TAFormRDApply.GetDataByID(FormRDApplyID)[0];
                FormDS.FormRow rowApplyForm = this.TAForm.GetDataByID(FormRDApplyID)[0];
                decimal totalAmountRMB = 0;
                decimal totalAmountBeforeTaxtRMB = 0;
                FormDS.FormRDPaymentDetailDataTable newDetailTable = new FormDS.FormRDPaymentDetailDataTable();
                foreach (FormDS.FormRDPaymentDetailRow detailRow in this.FormDataSet.FormRDPaymentDetail) {
                    // 与父表绑定
                    if (detailRow.RowState != DataRowState.Deleted) {
                        totalAmountRMB += detailRow.AmountRMB;
                        totalAmountBeforeTaxtRMB += detailRow.IsAmountBeforeTaxNull() ? 0 : detailRow.AmountBeforeTax;
                        FormDS.FormRDPaymentDetailRow newDetailRow = newDetailTable.NewFormRDPaymentDetailRow();
                        newDetailRow.FormRDPaymentID = formPaymentRow.FormRDPaymentID;
                        newDetailRow.FormRDApplyDetailID = detailRow.FormRDApplyDetailID;
                        newDetailRow.VendorID = detailRow.VendorID;
                        newDetailRow.ExpenseItemID = detailRow.ExpenseItemID;
                        newDetailRow.SKUID = detailRow.SKUID;
                        newDetailRow.PaiedAmount = detailRow.PaiedAmount;
                        newDetailRow.ApplyAmount = detailRow.ApplyAmount;
                        newDetailRow.ApplyAmountRMB = detailRow.ApplyAmountRMB;
                        newDetailRow.RemainAmount = detailRow.RemainAmount;
                        newDetailRow.AmountBeforeTax = detailRow.AmountBeforeTax;
                        newDetailRow.TaxAmount = detailRow.TaxAmount;
                        newDetailRow.AmountRMB = detailRow.AmountRMB;

                        newDetailTable.AddFormRDPaymentDetailRow(newDetailRow);
                    }
                }
                this.TAFormRDPaymentDetail.Update(newDetailTable);

                formPaymentRow.AmountRMB = totalAmountRMB;
                formPaymentRow.AmountBeforeTaxRMB = totalAmountBeforeTaxtRMB;
                this.TAFormRDPayment.Update(formPaymentRow);

                //作废之前的单据
                if (RejectedFormID != null) {
                    FormDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0];
                    if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) {
                        oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap;
                        this.TAForm.Update(oldRow);
                    }
                }

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    dic["PaymentTypeID"] = PaymentTypeID;
                    dic["InvoiceStatus"] = formPaymentRow.InvoiceStatusID;
                    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 = formPaymentRow.Remark;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #4
0
        public void UpdateRDApply(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        decimal ExchangeRate, string ProjectName, string ProjectDesc,
                        string ApplyFileName, string ApplyRealFileName, DateTime? ActivityBeginDate, DateTime? ActivityEndDate, int? CostCenterID,
                        decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount, decimal ReimbursedAmount, decimal RemainBudget)
        {
            SqlTransaction transaction = null;

            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormRDApply, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormRDApplyDetail, transaction);

                FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0];
                FormDS.FormRDApplyRow formApplyRow = this.TAFormRDApply.GetDataByID(FormID)[0];

                //处理单据的内容
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                    formRow.InTurnUserIds = "P";//待改动
                    formRow.InTurnPositionIds = "P";//待改动
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;
                if (CostCenterID != null) {
                    formRow.CostCenterID = CostCenterID.GetValueOrDefault();
                }

                this.TAForm.Update(formRow);

                //处理申请表的内容
                formApplyRow.ExchangeRate = ExchangeRate;
                if (ProjectName != null) {
                    formApplyRow.ProjectName = ProjectName;
                }
                if (ProjectDesc != null) {
                    formApplyRow.ProjectDesc = ProjectDesc;
                }
                if (ApplyFileName != null && ApplyFileName != string.Empty) {
                    formApplyRow.ApplyFileName = ApplyFileName;
                }
                if (ApplyRealFileName != null && ApplyRealFileName != string.Empty) {
                    formApplyRow.ApplyRealFileName = ApplyRealFileName;
                }
                if (ActivityBeginDate != null)
                    formApplyRow.ActivityBeginDate = ActivityBeginDate.GetValueOrDefault();
                if (ActivityEndDate != null)
                    formApplyRow.ActivityEndDate = ActivityEndDate.GetValueOrDefault();

                formApplyRow.TotalBudget = TotalBudget;
                formApplyRow.ApprovedAmount = ApprovedAmount;
                formApplyRow.ApprovingAmount = ApprovingAmount;
                formApplyRow.ReimbursedAmount = ReimbursedAmount;
                formApplyRow.RemainBudget = RemainBudget;

                this.TAFormRDApply.Update(formApplyRow);

                //处理明细
                decimal totalAmountRMB = 0;
                foreach (FormDS.FormRDApplyDetailRow detailRow in this.FormDataSet.FormRDApplyDetail) {
                    if (detailRow.RowState != DataRowState.Deleted) {
                        detailRow.FormRDApplyID = formApplyRow.FormRDApplyID;
                        detailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                        totalAmountRMB = totalAmountRMB + detailRow.AmountRMB;
                    }
                }
                this.TAFormRDApplyDetail.Update(this.FormDataSet.FormRDApplyDetail);
                formApplyRow.AmountRMB = totalAmountRMB;
                TAFormRDApply.Update(formApplyRow);

                // 正式提交
                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;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #5
0
        public void AddPVSpecialApply(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        DateTime FPeriod, int VendorID, int ItemCategoryID, int CurrencyID, decimal ExchangeRate, int PurchaseBudgetTypeID, int PurchaseTypeID, string Remark,
                        string AttachedFileName, string RealAttachedFileName, int MethodPaymentID, DateTime? ExpectPaymentDate, decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount,
                        decimal ReimbursedAmount, decimal NonReimbursedAmount, decimal RemainBudget, bool IsUrgent, bool IsPublic, int InvoiceStatusID, int PVType, int? VATRateID, decimal AMTTax, string PaymentTerms, bool IsPTChanged)
        {
            SqlTransaction transaction = null;

            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormPV, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormInvoice, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormPVDetail, transaction);

                //处理单据的内容
                PurchaseDS.FormRow formRow = this.PurchaseDataSet.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.SpecialPV;
                formRow.CostCenterID = new StuffUserBLL().GetCostCenterIDByPositionID(PositionID);
                formRow.IsCreateVoucher = false;
                formRow.IsExportLock = false;
                formRow.IsCompletePayment = false;
                this.PurchaseDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理申请表的内容
                PurchaseDS.FormPVRow formPVRow = this.PurchaseDataSet.FormPV.NewFormPVRow();
                formPVRow.FormPVID = formRow.FormID;
                formPVRow.FPeriod = FPeriod;
                formPVRow.VendorID = VendorID;
                formPVRow.ItemCategoryID = ItemCategoryID;
                formPVRow.CurrencyID = CurrencyID;
                formPVRow.ExchangeRate = ExchangeRate;
                formPVRow.PurchaseBudgetTypeID = PurchaseBudgetTypeID;
                formPVRow.PurchaseTypeID = PurchaseTypeID;
                formPVRow.Remark = Remark;
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formPVRow.AttachedFileName = AttachedFileName;
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formPVRow.RealAttachedFileName = RealAttachedFileName;
                }
                formPVRow.MethodPaymentID = MethodPaymentID;
                if (ExpectPaymentDate != null) {
                    formPVRow.ExpectPaymentDate = ExpectPaymentDate.GetValueOrDefault();
                }
                formPVRow.ApplyAmount = 0;
                formPVRow.PayedAmount = 0;
                formPVRow.Amount = 0;
                formPVRow.AmountRMB = 0;
                formPVRow.AMTBeforeTax = 0;
                formPVRow.AMTTax = AMTTax;
                formPVRow.TotalBudget = TotalBudget;
                formPVRow.ApprovedAmount = ApprovedAmount;
                formPVRow.ApprovingAmount = ApprovingAmount;
                formPVRow.ReimbursedAmount = ReimbursedAmount;
                formPVRow.NonReimbursedAmount = NonReimbursedAmount;
                formPVRow.RemainBudget = RemainBudget;
                formPVRow.IsUrgent = IsUrgent;
                formPVRow.IsPublic = IsPublic;
                formPVRow.InvoiceStatusID = InvoiceStatusID;
                formPVRow.PVType = PVType;
                if (VATRateID != null) {
                    formPVRow.VatRateID = VATRateID.GetValueOrDefault();
                }
                formPVRow.PaymentTerms = PaymentTerms;
                formPVRow.IsPTChanged = IsPTChanged;
                formPVRow.FinalItemCategoryID = ItemCategoryID;
                this.PurchaseDataSet.FormPV.AddFormPVRow(formPVRow);
                this.TAFormPV.Update(formPVRow);

                //发票
                if (RejectedFormID != null) {
                    PurchaseDS.FormInvoiceDataTable newInvoiceTable = new PurchaseDS.FormInvoiceDataTable();
                    foreach (PurchaseDS.FormInvoiceRow invoiceRow in this.PurchaseDataSet.FormInvoice) {
                        if (invoiceRow.RowState != DataRowState.Deleted) {
                            PurchaseDS.FormInvoiceRow newInvoiceRow = newInvoiceTable.NewFormInvoiceRow();
                            newInvoiceRow.FormID = formRow.FormID;
                            newInvoiceRow.InvoiceNo = invoiceRow.InvoiceNo;
                            newInvoiceRow.InvoiceDate = invoiceRow.InvoiceDate;
                            newInvoiceRow.InvoiceAmount = invoiceRow.InvoiceAmount;
                            newInvoiceRow.Remark = invoiceRow.IsRemarkNull() ? "" : invoiceRow.Remark;
                            newInvoiceRow.SystemInfo = invoiceRow.IsSystemInfoNull() ? "" : invoiceRow.SystemInfo;
                            newInvoiceTable.AddFormInvoiceRow(newInvoiceRow);
                        }
                        this.TAFormInvoice.Update(newInvoiceTable);
                    }
                } else {
                    foreach (PurchaseDS.FormInvoiceRow invoiceRow in this.PurchaseDataSet.FormInvoice) {
                        // 与父表绑定
                        if (invoiceRow.RowState != DataRowState.Deleted) {
                            invoiceRow.FormID = formRow.FormID;
                        }
                    }
                }
                this.TAFormInvoice.Update(this.PurchaseDataSet.FormInvoice);

                //处理明细
                decimal totalAmount = 0;
                decimal totalAmountRMB = 0;
                if (RejectedFormID != null) {
                    PurchaseDS.FormPVDetailDataTable newPVDetailTable = new PurchaseDS.FormPVDetailDataTable();
                    foreach (PurchaseDS.FormPVDetailRow detailRow in this.PurchaseDataSet.FormPVDetail) {
                        if (detailRow.RowState != DataRowState.Deleted) {
                            PurchaseDS.FormPVDetailRow newPVDetailRow = newPVDetailTable.NewFormPVDetailRow();
                            newPVDetailRow.FormPVID = formRow.FormID;
                            newPVDetailRow.ItemID = detailRow.ItemID;
                            newPVDetailRow.ItemCode = detailRow.ItemCode;
                            newPVDetailRow.ItemName = detailRow.ItemName;
                            if (!detailRow.IsItemDescriptionNull()) {
                                newPVDetailRow.ItemDescription = detailRow.ItemDescription;
                            }
                            if (!detailRow.IsPackageNull()) {
                                newPVDetailRow.Package = detailRow.Package;
                            }
                            newPVDetailRow.UnitPrice = detailRow.UnitPrice;
                            newPVDetailRow.FinalPrice = detailRow.FinalPrice;
                            newPVDetailRow.Quantity = detailRow.Quantity;
                            newPVDetailRow.Amount = detailRow.Amount;
                            newPVDetailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                            newPVDetailRow.DeliveryDate = detailRow.DeliveryDate;

                            newPVDetailTable.AddFormPVDetailRow(newPVDetailRow);
                            totalAmount = totalAmountRMB + newPVDetailRow.Amount;
                            totalAmountRMB = totalAmountRMB + newPVDetailRow.AmountRMB;
                        }
                    }
                    this.TAFormPVDetail.Update(newPVDetailTable);

                } else {
                    foreach (PurchaseDS.FormPVDetailRow detailRow in this.PurchaseDataSet.FormPVDetail) {
                        if (detailRow.RowState != DataRowState.Deleted) {
                            detailRow.FormPVID = formRow.FormID;
                            detailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                            totalAmountRMB = totalAmountRMB + detailRow.AmountRMB;
                            totalAmount = totalAmount + detailRow.Amount;
                        }
                    }
                    this.TAFormPVDetail.Update(this.PurchaseDataSet.FormPVDetail);
                }

                formPVRow.AmountRMB = totalAmountRMB;
                formPVRow.Amount = totalAmount;
                formPVRow.AMTBeforeTax = totalAmount - AMTTax;
                this.TAFormPV.Update(formPVRow);

                //作废之前的单据
                if (RejectedFormID != null) {
                    PurchaseDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0];
                    if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) {
                        oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap;
                        this.TAForm.Update(oldRow);
                    }
                }

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    dic["InvoiceStatus"] = formPVRow.InvoiceStatusID;
                    dic["IsUrgent"] = formPVRow.IsUrgent;
                    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 = formPVRow.Remark;
                        this.TAForm.Update(formRow);
                    }
                }

                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #6
0
        public void AddPaymentFreeGoods(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        SystemEnums.PageType PageType, int FormSaleSettlementID, int InvoiceStatusID, int PaymentTypeID, string Remark, string AttachedFileName, string RealAttachedFileName, int CostCenterID, int? VendorID)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormSalePayment, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSalePaymentDetail, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSalePaymentFreeGoods, transaction);

                //处理Form的内容
                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)PageType;
                formRow.CostCenterID = CostCenterID;
                formRow.IsCreateVoucher = false;
                formRow.IsExportLock = false;
                formRow.IsCompletePayment = false;
                formRow.IsInvoiceReturned = false;
                this.FormDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理Payment的内容
                FormDS.FormSalePaymentRow formPaymentRow = this.FormDataSet.FormSalePayment.NewFormSalePaymentRow();
                formPaymentRow.FormSalePaymentID = formRow.FormID;
                formPaymentRow.FormSaleSettlementID = FormSaleSettlementID;
                formPaymentRow.InvoiceStatusID = InvoiceStatusID;
                formPaymentRow.PaymentTypeID = PaymentTypeID;
                if (Remark != null && Remark != string.Empty) {
                    formPaymentRow.Remark = Remark;
                }
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formPaymentRow.AttachedFileName = AttachedFileName;
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formPaymentRow.RealAttachedFileName = RealAttachedFileName;
                }
                formPaymentRow.AmountRMB = 0;
                formPaymentRow.IsAdvanced = false;
                if (VendorID != null) {
                    formPaymentRow.VendorID = VendorID.GetValueOrDefault();
                }

                this.FormDataSet.FormSalePayment.AddFormSalePaymentRow(formPaymentRow);
                this.TAFormSalePayment.Update(formPaymentRow);

                //处理报销明细
                decimal totalAmountRMB = 0;
                FormDS.FormSalePaymentDetailDataTable newDetailTable = new FormDS.FormSalePaymentDetailDataTable();
                foreach (FormDS.FormSalePaymentDetailRow detailRow in this.FormDataSet.FormSalePaymentDetail) {
                    // 与父表绑定
                    if (detailRow.RowState != DataRowState.Deleted) {
                        totalAmountRMB += detailRow.AmountRMB;
                        FormDS.FormSalePaymentDetailRow newDetailRow = newDetailTable.NewFormSalePaymentDetailRow();
                        newDetailRow.FormSalePaymentID = formPaymentRow.FormSalePaymentID;
                        newDetailRow.FormSaleApplyID = detailRow.FormSaleApplyID;
                        newDetailRow.FormSaleExpenseDetailID = detailRow.FormSaleExpenseDetailID;
                        newDetailRow.ApplyFormNo = detailRow.ApplyFormNo;
                        newDetailRow.ApplyPeriod = detailRow.ApplyPeriod;
                        if (!detailRow.IsApplyProjectNameNull()) {
                            newDetailRow.ApplyProjectName = detailRow.ApplyProjectName;
                        }
                        newDetailRow.ExpenseItemID = detailRow.ExpenseItemID;
                        if (!detailRow.IsShopNameNull()) {
                            newDetailRow.ShopName = detailRow.ShopName;
                        }
                        if (!detailRow.IsSKUIDNull()) {
                            newDetailRow.SKUID = detailRow.SKUID;
                        }
                        newDetailRow.ApplyAmount = detailRow.ApplyAmount;
                        newDetailRow.ApplyAmountRMB = detailRow.ApplyAmountRMB;
                        if (!detailRow.IsSettlementAmountNull()) {
                            newDetailRow.SettlementAmount = detailRow.SettlementAmount;
                        }
                        if (!detailRow.IsPayedAmountNull()) {
                            newDetailRow.PayedAmount = detailRow.PayedAmount;
                        }
                        if (!detailRow.IsRemainAmountNull()) {
                            newDetailRow.RemainAmount = detailRow.RemainAmount;
                        }
                        newDetailRow.AmountRMB = detailRow.AmountRMB;

                        newDetailTable.AddFormSalePaymentDetailRow(newDetailRow);
                    }
                }
                this.TAFormSalePaymentDetail.Update(newDetailTable);

                formPaymentRow.AmountRMB = totalAmountRMB;
                this.TAFormSalePayment.Update(formPaymentRow);

                //处理free goods明细
                if (RejectedFormID != null) {
                    FormDS.FormSaleSettlementRow settlement = this.GetFormSaleSettlementByID(formPaymentRow.FormSaleSettlementID);
                    MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(settlement.CustomerID)[0];
                    FormDS.FormSalePaymentFreeGoodsDataTable newFGTable = new FormDS.FormSalePaymentFreeGoodsDataTable();
                    foreach (FormDS.FormSalePaymentFreeGoodsRow detailFGRow in this.FormDataSet.FormSalePaymentFreeGoods) {
                        // 与父表绑定
                        if (detailFGRow.RowState != DataRowState.Deleted) {
                            FormDS.FormSalePaymentFreeGoodsRow newDetailFGRow = newFGTable.NewFormSalePaymentFreeGoodsRow();
                            newDetailFGRow.FormSalePaymentID = formPaymentRow.FormSalePaymentID;
                            newDetailFGRow.SKUID = detailFGRow.SKUID;
                            newDetailFGRow.PackPerCase = detailFGRow.PackPerCase;
                            decimal deliveryPrice = new MasterDataBLL().GetSKUPriceByParameter(detailFGRow.SKUID, customer.CustomerTypeID, customer.CustomerChannelID);
                            newDetailFGRow.DeliveryPrice = deliveryPrice;
                            newDetailFGRow.Quantity = detailFGRow.Quantity;
                            newDetailFGRow.AmountRMB = decimal.Round(newDetailFGRow.Quantity * newDetailFGRow.DeliveryPrice, 2);
                            if (!detailFGRow.IsRemarkNull()) {
                                newDetailFGRow.Remark = detailFGRow.Remark;
                            }
                            newFGTable.AddFormSalePaymentFreeGoodsRow(newDetailFGRow);
                        }
                    }
                    this.TAFormSalePaymentFreeGoods.Update(newFGTable);
                } else {
                    foreach (FormDS.FormSalePaymentFreeGoodsRow detailFGRow in this.FormDataSet.FormSalePaymentFreeGoods) {
                        // 与父表绑定
                        if (detailFGRow.RowState != DataRowState.Deleted) {
                            detailFGRow.FormSalePaymentID = formPaymentRow.FormSalePaymentID;
                        }
                    }
                    this.TAFormSalePaymentFreeGoods.Update(this.FormDataSet.FormSalePaymentFreeGoods);
                }

                //作废之前的单据
                if (RejectedFormID != null) {
                    FormDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0];
                    if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) {
                        oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap;
                        this.TAForm.Update(oldRow);
                    }
                }

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(this.TAFormSaleSettlement.GetDataByID(FormSaleSettlementID)[0].CustomerID)[0];
                    dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode;
                    dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType;
                    dic["PaymentTypeID"] = PaymentTypeID;
                    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 = formPaymentRow.Remark;
                        this.TAForm.Update(formRow);
                    }
                }

                transaction.Commit();

            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #7
0
        public void AddFormInvitationApply(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID,
                SystemEnums.FormStatus StatusID, DateTime? Period, string Remark, String CustomerName, String AttenderNames, int AttenderCount, String BusinessRelation, String Place, DateTime? OccuredDate, String Purpose, String InvitationType, int CurrencyID, decimal? ExchangeRate, decimal? Amount,
            decimal? TotalBudget, decimal? ApprovingAmount, decimal? ApprovedAmount, decimal? RemainBudget)
        {
            SqlTransaction transaction = null;
            try {
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormInvitationApply, transaction);

                FormDS.FormDataTable tbForm = new FormDS.FormDataTable();
                FormDS.FormRow formRow = tbForm.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.FormInvitationApply;
                formRow.CostCenterID = new StuffUserBLL().GetCostCenterIDByPositionID(PositionID);
                tbForm.AddFormRow(formRow);
                this.TAForm.Update(tbForm);

                //处理申请表的内容
                FormDS.FormInvitationApplyDataTable tbFormInvitation = new FormDS.FormInvitationApplyDataTable();
                FormDS.FormInvitationApplyRow FormInvitationApplyRow = tbFormInvitation.NewFormInvitationApplyRow();
                FormInvitationApplyRow.FormInvitationApplyID = formRow.FormID;
                if (Period != null) {
                    FormInvitationApplyRow.Period = Period.GetValueOrDefault();
                }
                FormInvitationApplyRow.CustomerName = CustomerName;
                FormInvitationApplyRow.Remark = Remark;
                FormInvitationApplyRow.AttenderNames = AttenderNames;
                FormInvitationApplyRow.AttenderCount = AttenderCount;
                FormInvitationApplyRow.BusinessRelation = BusinessRelation;
                FormInvitationApplyRow.Place = Place;
                if (OccuredDate != null) {
                    FormInvitationApplyRow.OccuredDate = OccuredDate.GetValueOrDefault();
                }
                FormInvitationApplyRow.Purpose = Purpose;
                FormInvitationApplyRow.InvitationType = InvitationType;
                FormInvitationApplyRow.CurrencyID = CurrencyID;
                FormInvitationApplyRow.ExchangeRate = ExchangeRate.GetValueOrDefault();
                FormInvitationApplyRow.Amount = Amount.GetValueOrDefault();

                FormInvitationApplyRow.TotalBudget = TotalBudget.GetValueOrDefault();
                FormInvitationApplyRow.ApprovingAmount = ApprovingAmount.GetValueOrDefault();
                FormInvitationApplyRow.ApprovedAmount = ApprovedAmount.GetValueOrDefault();
                FormInvitationApplyRow.RemainBudget = RemainBudget.GetValueOrDefault();

                tbFormInvitation.AddFormInvitationApplyRow(FormInvitationApplyRow);
                this.TAFormInvitationApply.Update(tbFormInvitation);

                //作废之前的单据
                if (RejectedFormID != null) {
                    FormDS.FormRow oldRow = TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0];
                    if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) {
                        new APFlowBLL().ScrapForm(oldRow.FormID);
                    }
                }

                // 正式提交或草稿
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = FormInvitationApplyRow.AmountRMB;
                    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;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException(ex.Message);
            } finally {
                transaction.Dispose();
            }
        }
Пример #8
0
        public void AddPRApply(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        DateTime FPeriod, int VendorID, int ItemCategoryID, int CurrencyID, decimal ExchangeRate, int PurchaseBudgetTypeID, int PurchaseTypeID, int? CompanyID, int ShippingTermID,
                        string PaymentTerms, string Remark, string AttachedFileName, string RealAttachedFileName, decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount, decimal ReimbursedAmount,
                        decimal NonReimbursedAmount, decimal RemainBudget, string ItemCategoryName, string RealDeliveryAddress)
        {
            SqlTransaction transaction = null;

            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormPR, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormPRDetail, transaction);

                //处理单据的内容
                PurchaseDS.FormRow formRow = this.PurchaseDataSet.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.PRApply;
                formRow.CostCenterID = new StuffUserBLL().GetCostCenterIDByPositionID(PositionID);
                this.PurchaseDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理申请表的内容
                PurchaseDS.FormPRRow formPRRow = this.PurchaseDataSet.FormPR.NewFormPRRow();
                formPRRow.FormPRID = formRow.FormID;
                formPRRow.FPeriod = DateTime.Parse(FPeriod.Year.ToString() + "-" + FPeriod.Month.ToString() + "-01");
                formPRRow.VendorID = VendorID;
                formPRRow.ItemCategoryID = ItemCategoryID;
                formPRRow.CurrencyID = CurrencyID;
                formPRRow.ExchangeRate = ExchangeRate;
                formPRRow.PurchaseBudgetTypeID = PurchaseBudgetTypeID;
                formPRRow.PurchaseTypeID = PurchaseTypeID;
                if (CompanyID != null) {
                    formPRRow.CompanyID = CompanyID.GetValueOrDefault();
                    formPRRow.DeliveryAddress = new MasterDataBLL().GetCompanyById(CompanyID.GetValueOrDefault()).CompanyAddress;
                }
                formPRRow.ShippingTermID = ShippingTermID;
                if (PaymentTerms != null) {
                    formPRRow.PaymentTerms = PaymentTerms;
                }
                if (Remark != null) {
                    formPRRow.Remark = Remark;
                }
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formPRRow.AttachedFileName = AttachedFileName;
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formPRRow.RealAttachedFileName = RealAttachedFileName;
                }

                formPRRow.TotalBudget = TotalBudget;
                formPRRow.ApprovedAmount = ApprovedAmount;
                formPRRow.ApprovingAmount = ApprovingAmount;
                formPRRow.ReimbursedAmount = ReimbursedAmount;
                formPRRow.NonReimbursedAmount = NonReimbursedAmount;
                formPRRow.RemainBudget = RemainBudget;
                formPRRow.IsClose = false;
                formPRRow.AmountRMB = 0;
                formPRRow.RealDeliveryAddress = RealDeliveryAddress;

                this.PurchaseDataSet.FormPR.AddFormPRRow(formPRRow);
                this.TAFormPR.Update(formPRRow);

                //处理明细
                decimal totalAmountRMB = 0;
                if (RejectedFormID != null) {
                    PurchaseDS.FormPRDetailDataTable newPRDetailTable = new PurchaseDS.FormPRDetailDataTable();
                    foreach (PurchaseDS.FormPRDetailRow detailRow in this.PurchaseDataSet.FormPRDetail) {
                        if (detailRow.RowState != DataRowState.Deleted) {
                            PurchaseDS.FormPRDetailRow newPRDetailRow = newPRDetailTable.NewFormPRDetailRow();
                            newPRDetailRow.FormPRID = formRow.FormID;
                            newPRDetailRow.ItemID = detailRow.ItemID;
                            newPRDetailRow.ItemCode = detailRow.ItemCode;
                            newPRDetailRow.ItemName = detailRow.ItemName;
                            if (!detailRow.IsItemDescriptionNull()) {
                                newPRDetailRow.ItemDescription = detailRow.ItemDescription;
                            }
                            if (!detailRow.IsPackageNull()) {
                                newPRDetailRow.Package = detailRow.Package;
                            }
                            newPRDetailRow.UnitPrice = detailRow.UnitPrice;
                            newPRDetailRow.FinalPrice = detailRow.FinalPrice;
                            newPRDetailRow.Quantity = detailRow.Quantity;
                            newPRDetailRow.Amount = detailRow.Amount;
                            newPRDetailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                            newPRDetailRow.DeliveryDate = detailRow.DeliveryDate;
                            if (!detailRow.IsDeliveryAddressNull()) {
                                newPRDetailRow.DeliveryAddress = detailRow.DeliveryAddress;
                            }

                            newPRDetailTable.AddFormPRDetailRow(newPRDetailRow);
                            totalAmountRMB = totalAmountRMB + newPRDetailRow.AmountRMB;
                        }
                    }
                    this.TAFormPRDetail.Update(newPRDetailTable);

                } else {
                    foreach (PurchaseDS.FormPRDetailRow detailRow in this.PurchaseDataSet.FormPRDetail) {
                        if (detailRow.RowState != DataRowState.Deleted) {
                            detailRow.FormPRID = formRow.FormID;
                            detailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                            totalAmountRMB = totalAmountRMB + detailRow.AmountRMB;
                        }
                    }
                    this.TAFormPRDetail.Update(this.PurchaseDataSet.FormPRDetail);
                }

                formPRRow.AmountRMB = totalAmountRMB;
                this.TAFormPR.Update(formPRRow);

                //作废之前的单据
                if (RejectedFormID != null) {
                    PurchaseDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0];
                    if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) {
                        oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap;
                        this.TAForm.Update(oldRow);
                    }
                }

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TTLCost"] = totalAmountRMB;
                    dic["ItemCategory"] = ItemCategoryName;
                    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;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #9
0
        public void AddNoActivitySettlement(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        int CustomerID, int BrandID, int ExpenseSubCategoryID, int CurrencyID, string AttachedFileName, string RealAttachedFileName, string Remark, string FormApplyIds, string FormApplyNos, int CostCenterID, int PaymentTypeID)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormSaleSettlement, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSettlementExpenseDetail, transaction);

                //处理Form的内容
                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.NoActivitySettlementApply;
                formRow.CostCenterID = CostCenterID;
                this.FormDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理settlement的内容
                FormDS.FormSaleSettlementRow formSettleRow = this.FormDataSet.FormSaleSettlement.NewFormSaleSettlementRow();
                formSettleRow.FormSaleSettlementID = formRow.FormID;
                formSettleRow.CustomerID = CustomerID;
                formSettleRow.BrandID = BrandID;
                formSettleRow.ExpenseSubCategoryID = ExpenseSubCategoryID;
                formSettleRow.CurrencyID = CurrencyID;
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formSettleRow.AttachedFileName = AttachedFileName;
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formSettleRow.RealAttachedFileName = RealAttachedFileName;
                }
                if (Remark != null && Remark != string.Empty) {
                    formSettleRow.Remark = Remark;
                }
                formSettleRow.AmountRMB = 0;
                formSettleRow.FormApplyIds = FormApplyIds;
                formSettleRow.FormApplyNos = FormApplyNos;
                formSettleRow.IsClose = false;
                formSettleRow.PaymentTypeID = PaymentTypeID;
                this.FormDataSet.FormSaleSettlement.AddFormSaleSettlementRow(formSettleRow);
                this.TAFormSaleSettlement.Update(formSettleRow);

                //费用项
                decimal totalAmountRMB = 0;
                decimal totalApplyAmountRMB = 0;
                FormDS.FormSettlementExpenseDetailDataTable newExpenseDetailTable = new FormDS.FormSettlementExpenseDetailDataTable();
                foreach (FormDS.FormSettlementExpenseDetailRow expenseRow in this.FormDataSet.FormSettlementExpenseDetail) {
                    if (expenseRow.RowState != DataRowState.Deleted) {
                        FormDS.FormSettlementExpenseDetailRow newExpenseRow = newExpenseDetailTable.NewFormSettlementExpenseDetailRow();
                        newExpenseRow.FormSaleSettlementID = formSettleRow.FormSaleSettlementID;
                        newExpenseRow.FormSaleExpenseDetailID = expenseRow.FormSaleExpenseDetailID;
                        newExpenseRow.FormSaleApplyID = expenseRow.FormSaleApplyID;
                        newExpenseRow.ApplyFormNo = expenseRow.ApplyFormNo;
                        newExpenseRow.ApplyPeriod = expenseRow.ApplyPeriod;
                        newExpenseRow.ApplyProjectName = expenseRow.ApplyProjectName;
                        newExpenseRow.ExpenseItemID = expenseRow.ExpenseItemID;
                        if (!expenseRow.IsShopNameNull()) {
                            newExpenseRow.ShopName = expenseRow.ShopName;
                        }
                        if (!expenseRow.IsSKUIDNull()) {
                            newExpenseRow.SKUID = expenseRow.SKUID;
                        }
                        newExpenseRow.ApplyAmount = expenseRow.ApplyAmount;
                        newExpenseRow.ApplyAmountRMB = expenseRow.ApplyAmountRMB;
                        if (!expenseRow.IsApplyRemarkNull()) {
                            newExpenseRow.ApplyRemark = expenseRow.ApplyRemark;
                        }
                        if (!expenseRow.IsAdvancedAmountNull()) {
                            newExpenseRow.AdvancedAmount = expenseRow.AdvancedAmount;
                        }
                        newExpenseRow.AmountRMB = expenseRow.AmountRMB;
                        if (!expenseRow.IsRemarkNull()) {
                            newExpenseRow.Remark = expenseRow.Remark;
                        }

                        newExpenseDetailTable.AddFormSettlementExpenseDetailRow(newExpenseRow);
                        totalAmountRMB = totalAmountRMB + newExpenseRow.AmountRMB;
                        totalApplyAmountRMB = totalApplyAmountRMB + newExpenseRow.ApplyAmountRMB;
                    }
                }
                this.TAFormSettlementExpenseDetail.Update(newExpenseDetailTable);

                formSettleRow.ApplyAmountRMB = totalApplyAmountRMB;
                formSettleRow.AmountRMB = totalAmountRMB;

                this.TAFormSaleSettlement.Update(formSettleRow);

                //作废之前的单据
                if (RejectedFormID != null) {
                    FormDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0];
                    if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) {
                        oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap;
                        this.TAForm.Update(oldRow);
                    }
                }

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(CustomerID)[0];
                    dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode;
                    dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType;
                    dic["PaymentTypeID"] = PaymentTypeID;
                    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;
                        this.TAForm.Update(formRow);
                    }
                }

                transaction.Commit();

            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #10
0
        public void UpdateFormTravelReimburse(int FormID, SystemEnums.FormStatus StatusID, SystemEnums.FormType FormTypeID, 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.TAForm.GetDataByID(FormID)[0];
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;
                this.TAForm.Update(formRow);

                //处理申请表的内容
                FormDS.FormTravelReimburseRow formTravelReimburseRow = this.TAFormTravelReimburse.GetDataByFormTravelReimburseID(FormID)[0];

                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;
                } else {
                    formTravelReimburseRow.SetAttachedFileNameNull();
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formTravelReimburseRow.RealAttachedFileName = RealAttachedFileName;
                } else {
                    formTravelReimburseRow.SetRealAttachedFileNameNull();
                }

                this.TAFormTravelReimburse.Update(formTravelReimburseRow);

                //明细表
                decimal totalAmount = 0;//计算总申请金额
                foreach (FormDS.FormTravelReimburseDetailRow detailRow in this.FormDataSet.FormTravelReimburseDetail) {
                    // 与父表绑定
                    if (detailRow.RowState != DataRowState.Deleted) {
                        detailRow.FormTravelReimburseID = formTravelReimburseRow.FormTravelReimburseID;
                        totalAmount += detailRow.Cost;
                    }
                }
                this.TAFormTravelReimburseDetail.Update(this.FormDataSet.FormTravelReimburseDetail);

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

                // 正式提交或草稿
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmount;
                    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);
                    }
                }
                transaction.Commit();
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException(ex.Message);
            } finally {
                transaction.Dispose();
            }
        }
Пример #11
0
        public void UpdateSaleActivityApply(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, decimal ExchangeRate, string ShopName, int? ShopCount, string ProjectName, string ProjectDesc,
                        string ApplyFileName, string ApplyRealFileName, int? DisplayTypeID, decimal? DisplayArea, bool IsDM, int? DiscountTypeID, DateTime? ActivityBeginDate, DateTime? ActivityEndDate,
                        DateTime? DeliveryBeginDate, DateTime? DeliveryEndDate, int? CostCenterID, decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount, decimal CompletedAmount, decimal ReimbursedAmount, decimal RemainBudget)
        {
            SqlTransaction transaction = null;

            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormSaleApply, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSaleSKUDetail, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSaleExpenseDetail, transaction);

                FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0];
                FormDS.FormSaleApplyRow formApplyRow = this.TAFormSaleApply.GetDataByID(FormID)[0];

                //处理单据的内容
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                    formRow.InTurnUserIds = "P";//待改动
                    formRow.InTurnPositionIds = "P";//待改动
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;
                if (CostCenterID != null) {
                    formRow.CostCenterID = CostCenterID.GetValueOrDefault();
                }
                this.TAForm.Update(formRow);

                //处理申请表的内容
                formApplyRow.ExchangeRate = ExchangeRate;
                if (ShopName != null)
                    formApplyRow.ShopName = ShopName;
                if (ShopCount != null)
                    formApplyRow.ShopCount = ShopCount.GetValueOrDefault();
                if (ProjectName != null)
                    formApplyRow.ProjectName = ProjectName;
                if (ProjectDesc != null)
                    formApplyRow.ProjectDesc = ProjectDesc;
                if (ApplyFileName != null && ApplyFileName != string.Empty) {
                    formApplyRow.ApplyFileName = ApplyFileName;
                } else {
                    formApplyRow.SetApplyFileNameNull();
                }
                if (ApplyRealFileName != null && ApplyRealFileName != string.Empty) {
                    formApplyRow.ApplyRealFileName = ApplyRealFileName;
                } else {
                    formApplyRow.SetApplyRealFileNameNull();
                }
                if (DisplayTypeID != null)
                    formApplyRow.DisplayTypeID = DisplayTypeID.GetValueOrDefault();
                if (DisplayArea != null)
                    formApplyRow.DisplayArea = DisplayArea.GetValueOrDefault();
                formApplyRow.IsDM = IsDM;
                if (DiscountTypeID != null)
                    formApplyRow.DiscountTypeID = DiscountTypeID.GetValueOrDefault();
                if (ActivityBeginDate != null)
                    formApplyRow.ActivityBeginDate = ActivityBeginDate.GetValueOrDefault();
                if (ActivityEndDate != null)
                    formApplyRow.ActivityEndDate = ActivityEndDate.GetValueOrDefault();
                if (DeliveryBeginDate != null)
                    formApplyRow.DeliveryBeginDate = DeliveryBeginDate.GetValueOrDefault();
                if (DeliveryEndDate != null)
                    formApplyRow.DeliveryEndDate = DeliveryEndDate.GetValueOrDefault();

                formApplyRow.TotalBudget = TotalBudget;
                formApplyRow.ApprovedAmount = ApprovedAmount;
                formApplyRow.ApprovingAmount = ApprovingAmount;
                formApplyRow.CompletedAmount = CompletedAmount;
                formApplyRow.ReimbursedAmount = ReimbursedAmount;
                formApplyRow.RemainBudget = RemainBudget;

                this.TAFormSaleApply.Update(formApplyRow);

                //处理明细,先产品表
                decimal totalPriceDiscountAmountRMB = 0;//
                decimal totalForecastOrderAmount = 0;
                decimal maxDiscount = 0;
                foreach (FormDS.FormSaleSKUDetailRow skuRow in this.FormDataSet.FormSaleSKUDetail) {
                    if (skuRow.RowState != DataRowState.Deleted) {
                        skuRow.FormSaleApplyID = formApplyRow.FormSaleApplyID;
                        skuRow.PriceDiscountAmountRMB = decimal.Round(skuRow.PriceDiscountAmount * ExchangeRate, 2);
                        totalPriceDiscountAmountRMB = totalPriceDiscountAmountRMB + skuRow.PriceDiscountAmountRMB;
                        totalForecastOrderAmount = totalForecastOrderAmount + skuRow.ForecastOrderAmount;
                        if (skuRow.Discount > maxDiscount) {
                            maxDiscount = skuRow.Discount;
                        }
                        //如果有折扣的话,要生成费用项
                        if (!skuRow.IsPriceDiscountAmountRMBNull()) {
                            if (StatusID == SystemEnums.FormStatus.Awaiting && new ExpenseItemTableAdapter().GetPriceDiscountExpenseItem().Count != 0) {
                                FormDS.FormSaleExpenseDetailRow newExpenseDetail = this.FormDataSet.FormSaleExpenseDetail.NewFormSaleExpenseDetailRow();
                                newExpenseDetail.FormSaleApplyID = formApplyRow.FormSaleApplyID;
                                newExpenseDetail.ExpenseItemID = new ExpenseItemTableAdapter().GetPriceDiscountExpenseItem()[0].ExpenseItemID;
                                newExpenseDetail.SKUID = skuRow.SKUID;
                                newExpenseDetail.Amount = skuRow.PriceDiscountAmount;
                                newExpenseDetail.AmountRMB = decimal.Round(skuRow.PriceDiscountAmount * ExchangeRate, 2);
                                if (!skuRow.IsRemarkNull()) {
                                    newExpenseDetail.Remark = skuRow.Remark;
                                }
                                this.FormDataSet.FormSaleExpenseDetail.AddFormSaleExpenseDetailRow(newExpenseDetail);
                            }
                        }
                    }
                }
                this.TAFormSaleSKUDetail.Update(this.FormDataSet.FormSaleSKUDetail);
                //费用项
                decimal totalAmountRMB = 0;
                foreach (FormDS.FormSaleExpenseDetailRow expenseRow in this.FormDataSet.FormSaleExpenseDetail) {
                    if (expenseRow.RowState != DataRowState.Deleted) {
                        expenseRow.FormSaleApplyID = formApplyRow.FormSaleApplyID;
                        expenseRow.AmountRMB = decimal.Round(expenseRow.Amount * ExchangeRate, 2);
                        totalAmountRMB = totalAmountRMB + expenseRow.AmountRMB;
                    }
                }
                this.TAFormSaleExpenseDetail.Update(this.FormDataSet.FormSaleExpenseDetail);

                formApplyRow.PriceDiscountAmountRMB = totalPriceDiscountAmountRMB;
                formApplyRow.AmountRMB = totalAmountRMB;
                formApplyRow.OtherAmountRMB = totalAmountRMB - totalPriceDiscountAmountRMB;
                formApplyRow.ForecastOrderAmount = totalForecastOrderAmount;
                if (totalForecastOrderAmount != 0) {
                    formApplyRow.CostBenefitRate = totalAmountRMB / totalForecastOrderAmount * 100;
                } else {
                    formApplyRow.CostBenefitRate = 0;
                }
                TAFormSaleApply.Update(formApplyRow);

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(formApplyRow.CustomerID)[0];
                    dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode;
                    dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType;
                    dic["MaxDiscount"] = maxDiscount;
                    dic["DiscountType"] = DiscountTypeID;
                    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;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #12
0
        public void UpdatePaymentFreeGoods(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, int InvoiceStatusID, int PaymentTypeID,
                string Remark, string AttachedFileName, string RealAttachedFileName, int? VendorID)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormSalePayment, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSalePaymentDetail, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSalePaymentFreeGoods, transaction);

                FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0];
                FormDS.FormSalePaymentRow formPaymentRow = this.TAFormSalePayment.GetDataByID(FormID)[0];

                //处理单据的内容
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                    formRow.InTurnUserIds = "P";//待改动
                    formRow.InTurnPositionIds = "P";//待改动
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;

                this.TAForm.Update(formRow);

                //处理Payment的内容
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formPaymentRow.AttachedFileName = AttachedFileName;
                } else {
                    formPaymentRow.SetAttachedFileNameNull();
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formPaymentRow.RealAttachedFileName = RealAttachedFileName;
                } else {
                    formPaymentRow.SetRealAttachedFileNameNull();
                }
                if (Remark != null && Remark != string.Empty) {
                    formPaymentRow.Remark = Remark;
                }
                formPaymentRow.InvoiceStatusID = InvoiceStatusID;
                formPaymentRow.PaymentTypeID = PaymentTypeID;
                if (VendorID != null) {
                    formPaymentRow.VendorID = VendorID.GetValueOrDefault();
                }
                this.TAFormSalePayment.Update(formPaymentRow);

                //处理明细
                decimal totalAmountRMB = 0;
                foreach (FormDS.FormSalePaymentDetailRow detailRow in this.FormDataSet.FormSalePaymentDetail) {
                    if (detailRow.RowState != DataRowState.Deleted) {
                        totalAmountRMB += detailRow.AmountRMB;
                        detailRow.FormSalePaymentID = formPaymentRow.FormSalePaymentID;
                    }
                }
                this.TAFormSalePaymentDetail.Update(this.FormDataSet.FormSalePaymentDetail);

                formPaymentRow.AmountRMB = totalAmountRMB;
                this.TAFormSalePayment.Update(formPaymentRow);

                foreach (FormDS.FormSalePaymentFreeGoodsRow detailFGRow in this.FormDataSet.FormSalePaymentFreeGoods) {
                    // 与父表绑定
                    if (detailFGRow.RowState != DataRowState.Deleted) {
                        detailFGRow.FormSalePaymentID = formPaymentRow.FormSalePaymentID;
                    }
                }
                this.TAFormSalePaymentFreeGoods.Update(this.FormDataSet.FormSalePaymentFreeGoods);

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(this.TAFormSaleSettlement.GetDataByID(formPaymentRow.FormSaleSettlementID)[0].CustomerID)[0];
                    dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode;
                    dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType;
                    dic["PaymentTypeID"] = PaymentTypeID;
                    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 = formPaymentRow.Remark;
                        this.TAForm.Update(formRow);
                    }
                }

                transaction.Commit();

            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #13
0
        public void UpdateActivitySettlement(int FormID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, string AttachedFileName, string RealAttachedFileName, string Remark, int PaymentTypeID)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormSaleSettlement, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSettlementExpenseDetail, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormSettlementSKUDetail, transaction);

                FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0];
                FormDS.FormSaleSettlementRow formSettleRow = this.TAFormSaleSettlement.GetDataByID(FormID)[0];

                //处理单据的内容
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                    formRow.InTurnUserIds = "P";//待改动
                    formRow.InTurnPositionIds = "P";//待改动
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;

                this.TAForm.Update(formRow);

                //处理settlement的内容
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formSettleRow.AttachedFileName = AttachedFileName;
                } else {
                    formSettleRow.SetAttachedFileNameNull();
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formSettleRow.RealAttachedFileName = RealAttachedFileName;
                } else {
                    formSettleRow.SetRealAttachedFileNameNull();
                }
                if (Remark != null && Remark != string.Empty) {
                    formSettleRow.Remark = Remark;
                }
                formSettleRow.PaymentTypeID = PaymentTypeID;
                this.TAFormSaleSettlement.Update(formSettleRow);

                //处理明细,先产品表
                decimal totalForecastOrderAmount = 0;
                decimal totalActualOrderAmount = 0;
                foreach (FormDS.FormSettlementSKUDetailRow skuRow in this.FormDataSet.FormSettlementSKUDetail) {
                    if (skuRow.RowState != DataRowState.Deleted) {
                        skuRow.FormSaleSettlementID = formSettleRow.FormSaleSettlementID;
                        totalForecastOrderAmount = totalForecastOrderAmount + skuRow.ForecastOrderAmount;
                        totalActualOrderAmount = totalActualOrderAmount + skuRow.ActualOrderAmount;
                    }
                }
                this.TAFormSettlementSKUDetail.Update(this.FormDataSet.FormSettlementSKUDetail);
                //费用项
                decimal totalAmountRMB = 0;
                decimal totalApplyAmountRMB = 0;
                foreach (FormDS.FormSettlementExpenseDetailRow expenseRow in this.FormDataSet.FormSettlementExpenseDetail) {
                    if (expenseRow.RowState != DataRowState.Deleted) {
                        expenseRow.FormSaleSettlementID = formSettleRow.FormSaleSettlementID;
                        totalAmountRMB = totalAmountRMB + expenseRow.AmountRMB;
                        totalApplyAmountRMB = totalApplyAmountRMB + expenseRow.ApplyAmountRMB;
                    }
                }
                this.TAFormSettlementExpenseDetail.Update(this.FormDataSet.FormSettlementExpenseDetail);

                formSettleRow.ForecastOrderAmount = totalForecastOrderAmount;
                formSettleRow.ApplyAmountRMB = totalApplyAmountRMB;
                if (totalForecastOrderAmount != 0) {
                    formSettleRow.CostBenefitRate = totalApplyAmountRMB / totalForecastOrderAmount * 100;
                } else {
                    formSettleRow.CostBenefitRate = 0;
                }
                formSettleRow.ActualOrderAmount = totalActualOrderAmount;
                formSettleRow.AmountRMB = totalAmountRMB;
                if (totalActualOrderAmount != 0) {
                    formSettleRow.ActualCostBenefitRate = totalAmountRMB / totalActualOrderAmount * 100;
                } else {
                    formSettleRow.ActualCostBenefitRate = 0;
                }

                this.TAFormSaleSettlement.Update(formSettleRow);

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    MasterData.CustomerRow customer = new MasterDataBLL().GetCustomerById(formSettleRow.CustomerID)[0];
                    dic["CustomerChannel"] = new MasterDataBLL().GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelCode;
                    dic["KAType"] = customer.IsKaTypeNull() ? "" : customer.KaType;
                    dic["PaymentTypeID"] = PaymentTypeID;

                    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;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #14
0
        public void UpdatePRApply(int FormID, SystemEnums.FormStatus StatusID, decimal ExchangeRate, int PurchaseTypeID, int? CompanyID, int ShippingTermID,
                        string PaymentTerms, string Remark, string AttachedFileName, string RealAttachedFileName, decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount,
                        decimal ReimbursedAmount, decimal NonReimbursedAmount, decimal RemainBudget, string ItemCategoryName, string RealDeliveryAddress)
        {
            SqlTransaction transaction = null;

            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormPR, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormPRDetail, transaction);

                PurchaseDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0];
                PurchaseDS.FormPRRow formPRRow = this.TAFormPR.GetDataByID(FormID)[0];

                //处理单据的内容
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString(formRow.FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                    formRow.InTurnUserIds = "P";//待改动
                    formRow.InTurnPositionIds = "P";//待改动
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;

                this.TAForm.Update(formRow);

                //处理申请表的内容
                formPRRow.ExchangeRate = ExchangeRate;
                formPRRow.PurchaseTypeID = PurchaseTypeID;
                if (CompanyID != null) {
                    formPRRow.CompanyID = CompanyID.GetValueOrDefault();
                    formPRRow.DeliveryAddress = new MasterDataBLL().GetCompanyById(CompanyID.GetValueOrDefault()).CompanyAddress;
                }
                formPRRow.ShippingTermID = ShippingTermID;
                if (PaymentTerms != null) {
                    formPRRow.PaymentTerms = PaymentTerms;
                }
                if (Remark != null) {
                    formPRRow.Remark = Remark;
                }
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formPRRow.AttachedFileName = AttachedFileName;
                } else {
                    formPRRow.SetAttachedFileNameNull();
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formPRRow.RealAttachedFileName = RealAttachedFileName;
                } else {
                    formPRRow.SetRealAttachedFileNameNull();
                }

                formPRRow.TotalBudget = TotalBudget;
                formPRRow.ApprovedAmount = ApprovedAmount;
                formPRRow.ApprovingAmount = ApprovingAmount;
                formPRRow.ReimbursedAmount = ReimbursedAmount;
                formPRRow.NonReimbursedAmount = NonReimbursedAmount;
                formPRRow.RemainBudget = RemainBudget;
                formPRRow.AmountRMB = 0;
                formPRRow.RealDeliveryAddress = RealDeliveryAddress;

                this.TAFormPR.Update(formPRRow);

                //处理明细
                decimal totalAmountRMB = 0;
                foreach (PurchaseDS.FormPRDetailRow detailRow in this.PurchaseDataSet.FormPRDetail) {
                    if (detailRow.RowState != DataRowState.Deleted) {
                        detailRow.FormPRID = formRow.FormID;
                        detailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                        totalAmountRMB = totalAmountRMB + detailRow.AmountRMB;
                    }
                }
                this.TAFormPRDetail.Update(this.PurchaseDataSet.FormPRDetail);

                formPRRow.AmountRMB = totalAmountRMB;
                this.TAFormPR.Update(formPRRow);

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TTLCost"] = totalAmountRMB;
                    dic["ItemCategory"] = ItemCategoryName;
                    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;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #15
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();
            }
        }
Пример #16
0
        public void UpdatePVSpecialApply(int FormID, SystemEnums.FormStatus StatusID, decimal ExchangeRate, int PurchaseTypeID, string Remark, string AttachedFileName,
                        string RealAttachedFileName, int MethodPaymentID, DateTime? ExpectPaymentDate, decimal TotalBudget, decimal ApprovedAmount,
                        decimal ApprovingAmount, decimal ReimbursedAmount, decimal NonReimbursedAmount, decimal RemainBudget, bool IsUrgent, bool IsPublic, int InvoiceStatusID, int? VATRateID, decimal AMTTax, string PaymentTerms, bool IsPTChanged)
        {
            SqlTransaction transaction = null;

            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormPV, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormInvoice, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormPVDetail, transaction);

                PurchaseDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0];
                PurchaseDS.FormPVRow formPVRow = this.TAFormPV.GetDataByID(FormID)[0];

                //处理单据的内容
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString(formRow.FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                    formRow.InTurnUserIds = "P";//待改动
                    formRow.InTurnPositionIds = "P";//待改动
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;

                this.TAForm.Update(formRow);

                //处理申请表的内容
                formPVRow.ExchangeRate = ExchangeRate;
                formPVRow.PurchaseTypeID = PurchaseTypeID;
                if (Remark != null) {
                    formPVRow.Remark = Remark;
                }
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formPVRow.AttachedFileName = AttachedFileName;
                } else {
                    formPVRow.SetAttachedFileNameNull();
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formPVRow.RealAttachedFileName = RealAttachedFileName;
                } else {
                    formPVRow.SetRealAttachedFileNameNull();
                }
                formPVRow.MethodPaymentID = MethodPaymentID;
                if (ExpectPaymentDate != null) {
                    formPVRow.ExpectPaymentDate = ExpectPaymentDate.GetValueOrDefault();
                }
                formPVRow.TotalBudget = TotalBudget;
                formPVRow.ApprovedAmount = ApprovedAmount;
                formPVRow.ApprovingAmount = ApprovingAmount;
                formPVRow.ReimbursedAmount = ReimbursedAmount;
                formPVRow.NonReimbursedAmount = NonReimbursedAmount;
                formPVRow.RemainBudget = RemainBudget;
                formPVRow.IsUrgent = IsUrgent;
                formPVRow.IsPublic = IsPublic;
                formPVRow.InvoiceStatusID = InvoiceStatusID;
                formPVRow.IsUrgent = IsUrgent;
                formPVRow.IsPublic = IsPublic;
                formPVRow.InvoiceStatusID = InvoiceStatusID;
                formPVRow.AMTTax = AMTTax;
                if (VATRateID != null) {
                    formPVRow.VatRateID = VATRateID.GetValueOrDefault();
                }
                formPVRow.PaymentTerms = PaymentTerms;
                formPVRow.IsPTChanged = IsPTChanged;

                this.TAFormPV.Update(formPVRow);

                //发票
                foreach (PurchaseDS.FormInvoiceRow invoiceRow in this.PurchaseDataSet.FormInvoice) {
                    // 与父表绑定
                    if (invoiceRow.RowState != DataRowState.Deleted) {
                        invoiceRow.FormID = formRow.FormID;
                    }
                }
                this.TAFormInvoice.Update(this.PurchaseDataSet.FormInvoice);

                //处理明细
                decimal totalAmount = 0;
                decimal totalAmountRMB = 0;
                foreach (PurchaseDS.FormPVDetailRow detailRow in this.PurchaseDataSet.FormPVDetail) {
                    if (detailRow.RowState != DataRowState.Deleted) {
                        detailRow.FormPVID = formRow.FormID;
                        detailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                        totalAmountRMB = totalAmountRMB + detailRow.AmountRMB;
                        totalAmount = totalAmount + detailRow.Amount;
                    }
                }
                this.TAFormPVDetail.Update(this.PurchaseDataSet.FormPVDetail);

                formPVRow.AmountRMB = totalAmountRMB;
                formPVRow.Amount = totalAmount;
                formPVRow.AMTBeforeTax = totalAmount - AMTTax;
                this.TAFormPV.Update(formPVRow);

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = totalAmountRMB;
                    dic["InvoiceStatus"] = formPVRow.InvoiceStatusID;
                    dic["IsUrgent"] = formPVRow.IsUrgent;
                    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 = formPVRow.Remark;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #17
0
        public void UpdateFormInvitationReimburseApply(int RejectedFormID, int FormID, int FormTypeID, SystemEnums.FormStatus StatusID, DateTime? Period, string Remark, String CustomerName, String AttenderNames,
            int AttenderCount, String BusinessRelation, String Place, DateTime? OccuredDate, String Purpose, String InvitationType, int CurrencyID, decimal? ExchangeRate, decimal? Amount,
            decimal? TotalBudget, decimal? ApprovingAmount, decimal? ApprovedAmount, decimal? RemainBudget, int ManageExpenseItemID)
        {
            SqlTransaction transaction = null;
            try {
                //开始事务
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormInvitationApply, transaction);

                FormDS.FormRow formRow = this.TAForm.GetDataByID(FormID)[0];
                FormDS.FormInvitationReimburseRow FormInvitationReimburseRow = this.TAFormInvitationReimburse.GetDataByID(FormID)[0];

                //处理表单内容
                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                    formRow.InTurnUserIds = "P";//待改动
                    formRow.InTurnPositionIds = "P";//待改动
                } else {
                    formRow.SetFormNoNull();
                }
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;
                this.TAForm.Update(formRow);

                //处理申请表的内容
                if (Period != null) {
                    FormInvitationReimburseRow.Period = Period.GetValueOrDefault();
                }
                FormInvitationReimburseRow.CustomerName = CustomerName;
                FormInvitationReimburseRow.Remark = Remark;
                FormInvitationReimburseRow.AttenderNames = AttenderNames;
                FormInvitationReimburseRow.AttenderCount = AttenderCount;
                FormInvitationReimburseRow.BusinessRelation = BusinessRelation;
                FormInvitationReimburseRow.Place = Place;
                if (OccuredDate != null) {
                    FormInvitationReimburseRow.OccuredDate = OccuredDate.GetValueOrDefault();
                }
                FormInvitationReimburseRow.Purpose = Purpose;
                FormInvitationReimburseRow.InvitationType = InvitationType;
                FormInvitationReimburseRow.CurrencyID = CurrencyID;
                FormInvitationReimburseRow.ExchangeRate = ExchangeRate.GetValueOrDefault();
                FormInvitationReimburseRow.Amount = Amount.GetValueOrDefault();
                FormInvitationReimburseRow.ManageExpenseItemID = ManageExpenseItemID;

                FormInvitationReimburseRow.TotalBudget = TotalBudget.GetValueOrDefault();
                FormInvitationReimburseRow.ApprovingAmount = ApprovingAmount.GetValueOrDefault();
                FormInvitationReimburseRow.ApprovedAmount = ApprovedAmount.GetValueOrDefault();
                FormInvitationReimburseRow.RemainBudget = RemainBudget.GetValueOrDefault();

                this.TAFormInvitationReimburse.Update(FormInvitationReimburseRow);

                // 正式提交或草稿
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TotalAmount"] = FormInvitationReimburseRow.AmountRMB;
                    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;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException(ex.Message);
            } finally {
                transaction.Dispose();
            }
        }
Пример #18
0
        public void AddPVApply(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        int? FormPRID, int? FormPOID, string ParentFormNo, DateTime FPeriod, int VendorID, int ItemCategoryID, int CurrencyID, decimal ExchangeRate, int PurchaseBudgetTypeID, int PurchaseTypeID,
                        int? CompanyID, int ShippingTermID, string PaymentTerms, string Remark, string AttachedFileName, string RealAttachedFileName, int MethodPaymentID, DateTime? ExpectPaymentDate,
                        decimal ApplyAmount, decimal PayedAmount, decimal AMTBeforeTax, decimal AMTTax, bool IsUrgent, bool IsPublic, int InvoiceStatusID, int PVType, int? VATRateID, string ItemCategoryName, string RealDeliveryAddress)
        {
            SqlTransaction transaction = null;

            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormPV, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormInvoice, transaction);

                //处理单据的内容
                PurchaseDS.FormRow formRow = this.PurchaseDataSet.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.NormalPV;
                formRow.CostCenterID = new StuffUserBLL().GetCostCenterIDByPositionID(PositionID);
                formRow.IsCreateVoucher = false;
                formRow.IsExportLock = false;
                formRow.IsCompletePayment = false;

                this.PurchaseDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理申请表的内容
                PurchaseDS.FormPVRow formPVRow = this.PurchaseDataSet.FormPV.NewFormPVRow();
                formPVRow.FormPVID = formRow.FormID;
                if (FormPRID != null) {
                    formPVRow.FormPRID = FormPRID.GetValueOrDefault();
                }
                if (FormPOID != null) {
                    formPVRow.FormPOID = FormPOID.GetValueOrDefault();
                }
                formPVRow.ParentFormNo = ParentFormNo;
                formPVRow.FPeriod = FPeriod;
                formPVRow.VendorID = VendorID;
                formPVRow.ItemCategoryID = ItemCategoryID;
                formPVRow.CurrencyID = CurrencyID;
                formPVRow.ExchangeRate = ExchangeRate;
                formPVRow.PurchaseBudgetTypeID = PurchaseBudgetTypeID;
                formPVRow.PurchaseTypeID = PurchaseTypeID;
                if (CompanyID != null) {
                    formPVRow.CompanyID = CompanyID.GetValueOrDefault();
                    formPVRow.DeliveryAddress = new MasterDataBLL().GetCompanyById(CompanyID.GetValueOrDefault()).CompanyAddress;
                }
                formPVRow.ShippingTermID = ShippingTermID;
                formPVRow.PaymentTerms = PaymentTerms;
                formPVRow.Remark = Remark;
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formPVRow.AttachedFileName = AttachedFileName;
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formPVRow.RealAttachedFileName = RealAttachedFileName;
                }
                formPVRow.MethodPaymentID = MethodPaymentID;
                if (ExpectPaymentDate != null) {
                    formPVRow.ExpectPaymentDate = ExpectPaymentDate.GetValueOrDefault();
                }
                formPVRow.ApplyAmount = ApplyAmount;
                formPVRow.PayedAmount = PayedAmount;
                formPVRow.AMTBeforeTax = AMTBeforeTax;
                formPVRow.AMTTax = AMTTax;
                formPVRow.Amount = AMTBeforeTax + AMTTax;
                formPVRow.AmountRMB = decimal.Round(formPVRow.Amount * ExchangeRate, 2);
                formPVRow.IsUrgent = IsUrgent;
                formPVRow.IsPublic = IsPublic;
                formPVRow.InvoiceStatusID = InvoiceStatusID;
                formPVRow.PVType = PVType;
                if (VATRateID != null) {
                    formPVRow.VatRateID = VATRateID.GetValueOrDefault();
                }
                formPVRow.RealDeliveryAddress = RealDeliveryAddress;
                formPVRow.FinalItemCategoryID = ItemCategoryID;
                //payment term是否改变,只要在此判断即可,是从PO或者PR带入的
                string defaultPT = new MasterDataBLL().GetPaymentTermById(new VendorTableAdapter().GetDataByID(VendorID)[0].PaymentTermID)[0].PaymentTermName;
                if (defaultPT != PaymentTerms) {
                    formPVRow.IsPTChanged = true;
                } else {
                    formPVRow.IsPTChanged = false;
                }
                this.PurchaseDataSet.FormPV.AddFormPVRow(formPVRow);
                this.TAFormPV.Update(formPVRow);

                //发票
                if (RejectedFormID != null) {

                    PurchaseDS.FormInvoiceDataTable newInvoiceTable = new PurchaseDS.FormInvoiceDataTable();
                    foreach (PurchaseDS.FormInvoiceRow invoiceRow in this.PurchaseDataSet.FormInvoice) {
                        if (invoiceRow.RowState != DataRowState.Deleted) {
                            PurchaseDS.FormInvoiceRow newInvoiceRow = newInvoiceTable.NewFormInvoiceRow();
                            newInvoiceRow.FormID = formRow.FormID;
                            newInvoiceRow.InvoiceNo = invoiceRow.InvoiceNo;
                            newInvoiceRow.InvoiceDate = invoiceRow.InvoiceDate;
                            newInvoiceRow.InvoiceAmount = invoiceRow.InvoiceAmount;
                            newInvoiceRow.Remark = invoiceRow.IsRemarkNull() ? "" : invoiceRow.Remark;
                            newInvoiceRow.SystemInfo = invoiceRow.IsSystemInfoNull() ? "" : invoiceRow.SystemInfo;
                            newInvoiceTable.AddFormInvoiceRow(newInvoiceRow);
                        }
                        this.TAFormInvoice.Update(newInvoiceTable);
                    }
                } else {
                    foreach (PurchaseDS.FormInvoiceRow invoiceRow in this.PurchaseDataSet.FormInvoice) {
                        // 与父表绑定
                        if (invoiceRow.RowState != DataRowState.Deleted) {
                            invoiceRow.FormID = formRow.FormID;
                        }
                    }
                }
                this.TAFormInvoice.Update(this.PurchaseDataSet.FormInvoice);

                //作废之前的单据
                if (RejectedFormID != null) {
                    PurchaseDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0];
                    if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) {
                        oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap;
                        this.TAForm.Update(oldRow);
                    }
                }

                // 正式提交
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["TTLCost"] = formPVRow.AmountRMB;
                    dic["ItemCategory"] = ItemCategoryName;
                    dic["InvoiceStatus"] = formPVRow.InvoiceStatusID;
                    dic["IsUrgent"] = formPVRow.IsUrgent;
                    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 = formPVRow.Remark;
                        this.TAForm.Update(formRow);
                    }
                }
                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #19
0
        public void AddRDApply(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        DateTime FPeriod, int BrandID, int CustomerChannelID, int CurrencyID, decimal ExchangeRate, string ProjectName, string ProjectDesc,
                        string ApplyFileName, string ApplyRealFileName, DateTime? ActivityBeginDate, DateTime? ActivityEndDate, int? CostCenterID, int ExpenseSubCategoryID,
                        decimal TotalBudget, decimal ApprovedAmount, decimal ApprovingAmount, decimal ReimbursedAmount, decimal RemainBudget)
        {
            SqlTransaction transaction = null;
            try {
                //事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormRDApply, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormRDApplyDetail, 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.RDApply;
                if (CostCenterID != null) {
                    formRow.CostCenterID = CostCenterID.GetValueOrDefault();
                }
                this.FormDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理申请表的内容
                FormDS.FormRDApplyRow formApplyRow = this.FormDataSet.FormRDApply.NewFormRDApplyRow();
                formApplyRow.FormRDApplyID = formRow.FormID;
                formApplyRow.FPeriod = DateTime.Parse(FPeriod.Year.ToString() + "-" + FPeriod.Month.ToString() + "-01");
                formApplyRow.BrandID = BrandID;
                formApplyRow.CustomerChannelID = CustomerChannelID;
                formApplyRow.CurrencyID = CurrencyID;
                formApplyRow.ExchangeRate = ExchangeRate;
                if (!string.IsNullOrEmpty(ProjectName)) {
                    formApplyRow.ProjectName = ProjectName;
                }
                if (ProjectDesc != null)
                    formApplyRow.ProjectDesc = ProjectDesc;
                if (ApplyFileName != null && ApplyFileName != string.Empty) {
                    formApplyRow.ApplyFileName = ApplyFileName;
                }
                if (ApplyRealFileName != null && ApplyRealFileName != string.Empty) {
                    formApplyRow.ApplyRealFileName = ApplyRealFileName;
                }
                if (ActivityBeginDate != null) {
                    formApplyRow.ActivityBeginDate = ActivityBeginDate.GetValueOrDefault();
                }
                if (ActivityEndDate != null) {
                    formApplyRow.ActivityEndDate = ActivityEndDate.GetValueOrDefault();
                }
                formApplyRow.ExpenseSubCategoryID = ExpenseSubCategoryID;
                formApplyRow.TotalBudget = TotalBudget;
                formApplyRow.ApprovedAmount = ApprovedAmount;
                formApplyRow.ApprovingAmount = ApprovingAmount;
                formApplyRow.ReimbursedAmount = ReimbursedAmount;
                formApplyRow.RemainBudget = RemainBudget;
                formApplyRow.AmountRMB = 0;
                formApplyRow.IsClose = false;

                this.FormDataSet.FormRDApply.AddFormRDApplyRow(formApplyRow);
                this.TAFormRDApply.Update(formApplyRow);

                //处理明细
                decimal totalAmountRMB = 0;

                if (RejectedFormID != null) {
                    FormDS.FormRDApplyDetailDataTable newDetailTable = new FormDS.FormRDApplyDetailDataTable();
                    foreach (FormDS.FormRDApplyDetailRow detailRow in this.FormDataSet.FormRDApplyDetail) {
                        if (detailRow.RowState != DataRowState.Deleted) {
                            FormDS.FormRDApplyDetailRow newDetailRow = newDetailTable.NewFormRDApplyDetailRow();
                            newDetailRow.FormRDApplyID = formApplyRow.FormRDApplyID;
                            newDetailRow.VendorID = detailRow.VendorID;
                            newDetailRow.ExpenseItemID = detailRow.ExpenseItemID;
                            newDetailRow.SKUID = detailRow.SKUID;
                            newDetailRow.Amount = detailRow.Amount;
                            newDetailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                            if (!detailRow.IsRemarkNull()) {
                                newDetailRow.Remark = detailRow.Remark;
                            }
                            newDetailTable.AddFormRDApplyDetailRow(newDetailRow);
                            totalAmountRMB = totalAmountRMB + newDetailRow.AmountRMB;
                        }
                        this.TAFormRDApplyDetail.Update(newDetailTable);
                    }
                } else {
                    foreach (FormDS.FormRDApplyDetailRow detailRow in this.FormDataSet.FormRDApplyDetail) {
                        if (detailRow.RowState != DataRowState.Deleted) {
                            detailRow.FormRDApplyID = formApplyRow.FormRDApplyID;
                            detailRow.AmountRMB = decimal.Round(detailRow.Amount * ExchangeRate, 2);
                            totalAmountRMB = totalAmountRMB + detailRow.AmountRMB;
                        }
                    }
                    this.TAFormRDApplyDetail.Update(this.FormDataSet.FormRDApplyDetail);
                }

                formApplyRow.AmountRMB = totalAmountRMB;
                TAFormRDApply.Update(formApplyRow);
                //作废之前的单据
                if (RejectedFormID != null) {
                    FormDS.FormRow oldRow = this.TAForm.GetDataByID(RejectedFormID.GetValueOrDefault())[0];
                    if (oldRow.StatusID == (int)SystemEnums.FormStatus.Rejected) {
                        oldRow.StatusID = (int)SystemEnums.FormStatus.Scrap;
                        this.TAForm.Update(oldRow);
                    }
                }

                // 正式提交
                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;
                        this.TAForm.Update(formRow);
                    }
                }

                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }
Пример #20
0
        public void AddFormVendorApply(int? RejectedFormID, int UserID, int? ProxyStuffUserId, int? ProxyStuffPositionID, int OrganizationUnitID, int PositionID,
                 SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID, int VendorID, string VendorName, string VendorAddress, string City, string Country, string ContactName, int? VendorTypeID,
             string PhoneNumber, int OneTimeVendor, int HoldVendor, string PurchasingPostalCode, string AlphaSearchKey, string PurchasingContact, string PurchasingAddress,
            string PurchasingCity, string PurchasingPhoneNumber, int? BankCodeID, int? MethodPaymentID, int? PaymentTermID,
                 int? TransTypeID, int? VatTypeID, string BankName, string AccountNo, string BankNo, int? ACTypeID, string AttachmentFileName, string RealAttachmentFileName, string Remark, string ModifyReason, int ActionType)
        {
            SqlTransaction transaction = null;
            try {
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormVendor, transaction);

                PurchaseDS.FormRow formRow = this.PurchaseDataSet.Form.NewFormRow();
                if (RejectedFormID != null) {
                    formRow.RejectedFormID = RejectedFormID.GetValueOrDefault();
                }
                formRow.UserID = UserID;
                UtilityBLL utility = new UtilityBLL();

                string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                formRow.FormNo = utility.GetFormNo(formTypeString);

                if (ProxyStuffUserId != null) {
                    formRow.ProxyUserID = ProxyStuffUserId.GetValueOrDefault();
                }
                if (ProxyStuffPositionID != null) {
                    formRow.ProxyPositionID = ProxyStuffPositionID.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.VendorApply;
                this.PurchaseDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理申请表的内容
                PurchaseDS.FormVendorDataTable tbFormVendor = new PurchaseDS.FormVendorDataTable();
                PurchaseDS.FormVendorRow FormVendorRow = tbFormVendor.NewFormVendorRow();

                FormVendorRow.FormVendorID = formRow.FormID;
                if (ActionType != 1 && VendorID > 0) {
                    FormVendorRow.VendorID = VendorID;
                    FormVendorRow.VendorCode = new MasterDataBLL().GetVendorByID(VendorID).VendorCode;
                }
                FormVendorRow.VendorName = VendorName;
                FormVendorRow.VendorAddress = VendorAddress;
                FormVendorRow.City = City;

                FormVendorRow.Postal = Country;
                FormVendorRow.ContactName = ContactName;
                if (VendorTypeID != null) {
                    FormVendorRow.VendorTypeID = VendorTypeID.GetValueOrDefault();
                }
                FormVendorRow.PhoneNumber = PhoneNumber;
                FormVendorRow.OneTimeVendor = OneTimeVendor == 1;
                FormVendorRow.HoldVendor = HoldVendor == 1;
                FormVendorRow.PurchaseingPostalCode = PurchasingPostalCode;
                FormVendorRow.AlphaSearchKey = AlphaSearchKey;
                FormVendorRow.PurchasingContact = PurchasingContact;
                FormVendorRow.PurchasingAddress = PurchasingAddress;
                FormVendorRow.PurchasingCity = PurchasingCity;
                FormVendorRow.PurchasePhoneNumber = PurchasingPhoneNumber;
                if (BankCodeID != null && BankCodeID != 0) {
                    FormVendorRow.BankCodeID = BankCodeID.GetValueOrDefault();
                    MasterData.BankCodeRow rowBankCode = new MasterDataBLL().GetBankCodeById(BankCodeID.GetValueOrDefault())[0];
                    FormVendorRow.BankCode = rowBankCode.BankCode + rowBankCode.Description;
                }
                if (MethodPaymentID != null) {
                    FormVendorRow.MethodPaymentID = MethodPaymentID.GetValueOrDefault();
                }
                if (PaymentTermID != null) {
                    FormVendorRow.PaymentTermID = PaymentTermID.GetValueOrDefault();
                }
                if (TransTypeID != null) {
                    FormVendorRow.TransTypeID = TransTypeID.GetValueOrDefault();
                }
                if (VatTypeID != null) {
                    FormVendorRow.VATTypeID = VatTypeID.GetValueOrDefault();
                }
                FormVendorRow.BankName = BankName;
                FormVendorRow.AccountNo = AccountNo;
                FormVendorRow.BankNo = BankNo;
                if (ACTypeID != null) {
                    FormVendorRow.ACTypeID = ACTypeID.GetValueOrDefault();
                }
                FormVendorRow.AttachmentFileName = AttachmentFileName;
                FormVendorRow.RealAttachmentFileName = RealAttachmentFileName;
                FormVendorRow.Remark = Remark;
                FormVendorRow.ModifyReason = ModifyReason;
                FormVendorRow.ActionType = ActionType;

                tbFormVendor.AddFormVendorRow(FormVendorRow);
                this.TAFormVendor.Update(tbFormVendor);

                // 正式提交或草稿
                if (StatusID == SystemEnums.FormStatus.Awaiting) {

                    Dictionary<string, object> dic = new Dictionary<string, object>();
                    dic["ActionType"] = FormVendorRow.ActionType;
                    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;
                        this.TAForm.Update(formRow);
                    }
                }

                //作废之前的单据
                if (RejectedFormID != null) {
                    PurchaseDS.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();
            }
        }
Пример #21
0
    protected void SubmitBtn_Click(object sender, EventArgs e)
    {
        try {
            AuthorizationDS.StuffUserRow currentStuff = (AuthorizationDS.StuffUserRow)Session["StuffUser"];
            APFlowBLL AB = new APFlowBLL();
            List<int> formIDs = this.GetCheckedFormIds();
            if (formIDs.Count > 0) {
                string test = string.Empty;
                for (int i = 0; i < formIDs.Count; i++) {
                    AB.ApproveForm(CommonUtility.GetAPHelper(Session), formIDs[i], currentStuff.StuffUserId, currentStuff.StuffName, true, "", "", 0);
                }

                if (this.Request["Source"] != null) {
                    this.Response.Redirect(this.Request["Source"].ToString());
                } else {
                    this.Response.Redirect("~/Home.aspx");
                }
            } else {
                PageUtility.ShowModelDlg(this, "请选择单据!");
                return;
            }

        } catch (Exception exception) {
            PageUtility.DealWithException(this, exception);
        }
    }