Пример #1
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();
            }
        }
Пример #2
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();
            }
        }