Ejemplo n.º 1
0
        public long SaveRemittanceDocument(Guid txID, long remittanceID)
        {
            FnRemittanceDataset remittanceDS = (FnRemittanceDataset)TransactionService.GetDS(txID);

            FnRemittanceDataset.FnRemittanceRow remittanceRow = remittanceDS.FnRemittance.FindByRemittanceID(remittanceID);
            long documentID = remittanceRow.DocumentID;

            documentID = SCGDocumentService.SaveSCGDocument(txID, documentID);

            remittanceID = ScgeAccountingDaoProvider.FnRemittanceDao.Persist(remittanceDS.FnRemittance);

            ScgeAccountingDaoProvider.FnRemittanceDao.DeleteAllRemittanceItemAndRemittanceAdvance(remittanceRow.RemittanceID);

            FnRemittanceItemService.SaveRemittanceItem(txID, remittanceID);

            FnRemittanceAdvanceService.SaveRemittanceAdvance(txID, remittanceID);

            // Add code for update clearing advance by Anuwat S on 19/04/2009

            AvAdvanceDocumentService.UpdateRemittanceAdvance(remittanceID, double.Parse("0" + remittanceDS.FnRemittance.Rows[0]["TotalAmount"].ToString()), false);

            if (!remittanceRow.IsIsRepOfficeNull() && remittanceRow.IsRepOffice)
            {
                AvAdvanceDocumentService.UpdateRemittanceAdvanceForRepOffice(remittanceID, double.Parse("0" + remittanceDS.FnRemittance.Rows[0]["MainCurrencyAmount"].ToString()), false);
            }
            return(remittanceID);
        }
Ejemplo n.º 2
0
        public void SendEmailToOverDueDate()
        {
            IList <VOAdvanceOverDueReport> voList = ScgeAccountingQueryProvider.SCGDocumentQuery.GetAdvanceOverdueList();

            foreach (VOAdvanceOverDueReport item in voList)
            {
                SCGDocument document = SCGDocumentService.FindByIdentity(item.DocumentID);
                SCGEmailService.SendEmailEM10(item.AdvanceID, document.RequesterID.Userid, document.ApproverID.Email, "This is e-mail for autoreminder advancedocument system.", true);
            }
        }
        public long SaveFixedAdvance(Guid txid, long fixedadvanceId)
        {
            FixedAdvanceDataSet fixedadvanceDataset = (FixedAdvanceDataSet)TransactionService.GetDS(txid);

            FixedAdvanceDataSet.FixedAdvanceDocumentRow row = fixedadvanceDataset.FixedAdvanceDocument.FindByFixedAdvanceID(fixedadvanceId);
            long documentID = row.DocumentID;

            documentID     = SCGDocumentService.SaveSCGDocument(txid, documentID);
            fixedadvanceId = ScgeAccountingDaoProvider.FixedAdvanceDocumentDao.Persist(fixedadvanceDataset.FixedAdvanceDocument);
            return(fixedadvanceId);
        }
Ejemplo n.º 4
0
        public long SaveAvAdvance(Guid txid, long advanceId)
        {
            AdvanceDataSet advanceDataset = (AdvanceDataSet)TransactionService.GetDS(txid);

            AdvanceDataSet.AvAdvanceDocumentRow row = advanceDataset.AvAdvanceDocument.FindByAdvanceID(advanceId);
            long documentID = row.DocumentID;

            documentID = SCGDocumentService.SaveSCGDocument(txid, documentID);
            //insert update or delete AvAdvanveDocument
            advanceId = ScgeAccountingDaoProvider.AvAdvanceDocumentDao.Persist(advanceDataset.AvAdvanceDocument);

            //inset update or delete AvAdvanceItem
            AvAdvanceItemService.saveAdvanceItem(txid, advanceId);

            return(advanceId);
        }
        public long SaveMPADocument(Guid txID, long mpaDocumentID)
        {
            MPADocumentDataSet mpaDocumentDS = (MPADocumentDataSet)TransactionService.GetDS(txID);

            MPADocumentDataSet.MPADocumentRow mpaDocumentRow = mpaDocumentDS.MPADocument.FindByMPADocumentID(mpaDocumentID);
            long documentID = mpaDocumentRow.DocumentID;

            // Insert, Update SCGDocument.
            // Insert, Update, Delete DocumentInitiator.
            // Insert, Delete DocumentAttachment.
            documentID = SCGDocumentService.SaveSCGDocument(txID, documentID);

            // Insert, Update, Delete MPADocument.
            mpaDocumentID = ScgeAccountingDaoProvider.MPADocumentDao.Persist(mpaDocumentDS.MPADocument);

            // Insert, Update, Delete MPAItem.
            MPAItemService.SaveMPAItem(txID, documentID);

            return(mpaDocumentID);
        }
Ejemplo n.º 6
0
        public long SaveCADocument(Guid txID, long caDocumentID)
        {
            CADocumentDataSet caDocumentDS = (CADocumentDataSet)TransactionService.GetDS(txID);

            CADocumentDataSet.CADocumentRow caDocumentRow = caDocumentDS.CADocument.FindByCADocumentID(caDocumentID);
            long documentID = caDocumentRow.DocumentID;

            // Insert, Update SCGDocument.
            // Insert, Update, Delete DocumentInitiator.
            // Insert, Delete DocumentAttachment.
            documentID = SCGDocumentService.SaveSCGDocument(txID, documentID);

            // Insert, Update, Delete MPADocument.
            caDocumentID = ScgeAccountingDaoProvider.CADocumentDao.Persist(caDocumentDS.CADocument);

            // Insert, Update, Delete MPAItem.
            //MPAItemService.SaveMPADocumentItem(txID, mpaDocumentID);

            return(caDocumentID);
        }
Ejemplo n.º 7
0
        public long SaveTADocument(Guid txID, long taDocumentID)
        {
            TADocumentDataSet taDocumentDS = (TADocumentDataSet)TransactionService.GetDS(txID);

            TADocumentDataSet.TADocumentRow taDocumentRow = taDocumentDS.TADocument.FindByTADocumentID(taDocumentID);
            long documentID = taDocumentRow.DocumentID;

            // Insert, Update SCGDocument.
            // Insert, Update, Delete DocumentInitiator.
            // Insert, Delete DocumentAttachment.
            documentID = SCGDocumentService.SaveSCGDocument(txID, documentID);

            // Insert, Update, Delete TADocument.
            taDocumentID = ScgeAccountingDaoProvider.TADocumentDao.Persist(taDocumentDS.TADocument);

            // Insert, Update, Delete TADocumentTraveller.
            TADocumentTravellerService.SaveTADocumentTraveller(txID, taDocumentID);

            // Insert, Update, Delete TADocumentSchedule.
            TADocumentScheduleService.SaveTADocumentSchedule(txID, taDocumentID);

            return(taDocumentID);
        }
        public System.Data.DataSet PrepareDataToDataset(long documentID, bool isCopy)
        {
            MPADocumentDataSet mpaDocumentDS = new MPADocumentDataSet();

            MPADocument mpaDocument = ScgeAccountingQueryProvider.MPADocumentQuery.GetMPADocumentByDocumentID(documentID);

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            if (mpaDocument == null)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("MPADocumentNotFound"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            // Prepare Data to Document datatable.
            if (!isCopy)
            {
                SCGDocumentService.PrepareDataToDataset(mpaDocumentDS, documentID);
            }
            else
            {
                SCGDocumentService.PrepareDataInternalToDataset(mpaDocumentDS, documentID, isCopy);
            }

            // Set data to Document row
            MPADocumentDataSet.MPADocumentRow mpaDocumentRow = mpaDocumentDS.MPADocument.NewMPADocumentRow();

            mpaDocumentRow.MPADocumentID = mpaDocument.MPADocumentID;

            if (!isCopy)
            {
                if (mpaDocument.DocumentID != null)
                {
                    mpaDocumentRow.DocumentID = mpaDocument.DocumentID.DocumentID;
                }
            }
            else
            {
                if (mpaDocumentDS.Document.Rows.Count > 0)
                {
                    MPADocumentDataSet.DocumentRow docRow = (MPADocumentDataSet.DocumentRow)mpaDocumentDS.Document.Rows[0];
                    mpaDocumentRow.DocumentID = docRow.DocumentID;
                }
            }

            mpaDocumentRow.StartDate = mpaDocument.StartDate;
            mpaDocumentRow.EndDate   = mpaDocument.EndDate;

            mpaDocumentRow.Active  = mpaDocument.Active;
            mpaDocumentRow.CreBy   = mpaDocument.CreBy;
            mpaDocumentRow.CreDate = mpaDocument.CreDate;
            mpaDocumentRow.UpdBy   = mpaDocument.UpdBy;
            mpaDocumentRow.UpdDate = mpaDocument.UpdDate;
            mpaDocumentRow.UpdPgm  = mpaDocument.UpdPgm;

            // Add ta document row to MPADocument.
            mpaDocumentDS.MPADocument.AddMPADocumentRow(mpaDocumentRow);

            // Prepare Data to MPAItemService Datatable.
            MPAItemService.PrepareDataToDataset(mpaDocumentDS, mpaDocument.MPADocumentID);


            return(mpaDocumentDS);
        }
Ejemplo n.º 9
0
        public System.Data.DataSet PrepareDataToDataset(long documentID, bool isCopy)
        {
            CADocumentDataSet caDocumentDS = new CADocumentDataSet();

            CADocument caDocument = ScgeAccountingQueryProvider.CADocumentQuery.GetCADocumentByDocumentID(documentID);

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            if (caDocument == null)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CADocumentNotFound"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            // Prepare Data to Document datatable.
            if (!isCopy)
            {
                SCGDocumentService.PrepareDataToDataset(caDocumentDS, documentID);
            }
            else
            {
                SCGDocumentService.PrepareDataInternalToDataset(caDocumentDS, documentID, isCopy);
            }

            // Set data to Document row
            CADocumentDataSet.CADocumentRow caDocumentRow = caDocumentDS.CADocument.NewCADocumentRow();

            caDocumentRow.CADocumentID = caDocument.CADocumentID;

            if (!isCopy)
            {
                if (caDocument.DocumentID != null)
                {
                    caDocumentRow.DocumentID = caDocument.DocumentID.DocumentID;
                }
            }
            else
            {
                if (caDocumentDS.Document.Rows.Count > 0)
                {
                    CADocumentDataSet.DocumentRow docRow = (CADocumentDataSet.DocumentRow)caDocumentDS.Document.Rows[0];
                    caDocumentRow.DocumentID = docRow.DocumentID;
                }
            }

            caDocumentRow.StartDate   = caDocument.StartDate;
            caDocumentRow.EndDate     = caDocument.EndDate;
            caDocumentRow.IsTemporary = caDocument.IsTemporary;
            if (caDocument.CarLicenseNo != null)
            {
                caDocumentRow.CarLicenseNo = caDocument.CarLicenseNo;
            }
            if (caDocument.CarLicenseNo != null)
            {
                caDocumentRow.Brand = caDocument.Brand;
            }
            if (caDocument.Model != null)
            {
                caDocumentRow.Model = caDocument.Model;
            }

            if (caDocument.IsWorkArea != null)
            {
                caDocumentRow.IsWorkArea = caDocument.IsWorkArea.Value;
            }
            if (caDocument.Remark != null)
            {
                caDocumentRow.Remark = caDocument.Remark;
            }
            caDocumentRow.CarType   = caDocument.CarType;
            caDocumentRow.OwnerType = caDocument.OwnerType;

            caDocumentRow.Active  = caDocument.Active;
            caDocumentRow.CreBy   = caDocument.CreBy;
            caDocumentRow.CreDate = caDocument.CreDate;
            caDocumentRow.UpdBy   = caDocument.UpdBy;
            caDocumentRow.UpdDate = caDocument.UpdDate;
            caDocumentRow.UpdPgm  = caDocument.UpdPgm;

            // Add ta document row to MPADocument.
            caDocumentDS.CADocument.AddCADocumentRow(caDocumentRow);

            // Prepare Data to MPAItemService Datatable.
            //MPAItemService.PrepareDataToDataset(mpaDocumentDS, mpaDocument.MPADocumentID);


            return(caDocumentDS);
        }
Ejemplo n.º 10
0
        public DataSet PrepareDataToDataset(long documentID, bool isCopy)
        {
            TADocumentDataSet taDocumentDS = new TADocumentDataSet();

            TADocument taDocument = ScgeAccountingQueryProvider.TADocumentQuery.GetTADocumentByDocumentID(documentID);

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            if (taDocument == null)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("NoTADocumentFound"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            // Prepare Data to Document datatable.
            if (!isCopy)
            {
                SCGDocumentService.PrepareDataToDataset(taDocumentDS, documentID);
            }
            else
            {
                SCGDocumentService.PrepareDataInternalToDataset(taDocumentDS, documentID, isCopy);
            }

            // Set data to Budget Document row in budgetDocumentDS.
            TADocumentDataSet.TADocumentRow taDocumentRow = taDocumentDS.TADocument.NewTADocumentRow();

            taDocumentRow.TADocumentID = taDocument.TADocumentID;

            if (!isCopy)
            {
                if (taDocument.DocumentID != null)
                {
                    taDocumentRow.DocumentID = taDocument.DocumentID.DocumentID;
                }
            }
            else
            {
                if (taDocumentDS.Document.Rows.Count > 0)
                {
                    TADocumentDataSet.DocumentRow docRow = (TADocumentDataSet.DocumentRow)taDocumentDS.Document.Rows[0];
                    taDocumentRow.DocumentID = docRow.DocumentID;
                }
            }

            taDocumentRow.FromDate           = taDocument.FromDate;
            taDocumentRow.ToDate             = taDocument.ToDate;
            taDocumentRow.IsBusinessPurpose  = taDocument.IsBusinessPurpose;
            taDocumentRow.IsTrainningPurpose = taDocument.IsTrainningPurpose;
            taDocumentRow.IsOtherPurpose     = taDocument.IsOtherPurpose;
            if (taDocument.OtherPurposeDescription != null)
            {
                taDocumentRow.OtherPurposeDescription = taDocument.OtherPurposeDescription;
            }
            taDocumentRow.TravelBy = taDocument.TravelBy;
            if (taDocument.Province != null)
            {
                taDocumentRow.Province = taDocument.Province;
            }
            if (taDocument.Country != null)
            {
                taDocumentRow.Country = taDocument.Country;
            }
            taDocumentRow.Ticketing = taDocument.Ticketing;

            //if (taDocument.CostCenterID != null)
            //{
            //    taDocumentRow.CostCenterID = taDocument.CostCenterID.CostCenterID;
            //}
            //if (taDocument.Account != null)
            //{
            //    taDocumentRow.AccountID = taDocument.Account.AccountID;
            //}
            //if (taDocument.IOID != null)
            //{
            //    taDocumentRow.IOID = taDocument.IOID.IOID;
            //}

            taDocumentRow.Active  = taDocument.Active;
            taDocumentRow.CreBy   = taDocument.CreBy;
            taDocumentRow.CreDate = taDocument.CreDate;
            taDocumentRow.UpdBy   = taDocument.UpdBy;
            taDocumentRow.UpdDate = taDocument.UpdDate;
            taDocumentRow.UpdPgm  = taDocument.UpdPgm;

            // Add ta document row to taDocument.
            taDocumentDS.TADocument.AddTADocumentRow(taDocumentRow);

            // Prepare Data to TADocumentTravellerService Datatable.
            TADocumentTravellerService.PrepareDataToDataset(taDocumentDS, taDocument.TADocumentID);

            // Prepare Data to TADocumentScheduleService Datatable.
            TADocumentScheduleService.PrepareDataToDataset(taDocumentDS, taDocument.TADocumentID);

            //Not Save to TADocumemtAdvance Table.
            // Prepare Data to TADocumentAdvanceService Datatable.
            ////TADocumentAdvanceService.PrepareDataToDataset(taDocumentDS, taDocument.TADocumentID);

            return(taDocumentDS);
        }
Ejemplo n.º 11
0
        public FnRemittanceDataset PrepareDataToDataset(long documentID, bool isCopy)
        {
            FnRemittanceDataset remittanceDS = new FnRemittanceDataset();
            FnRemittance        remittance   = ScgeAccountingQueryProvider.FnRemittanceQuery.GetFnRemittanceByDocumentID(documentID);

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            if (remittance == null)
            {
                errors.AddError("Remittance.Error", new Spring.Validation.ErrorMessage("NoRemittanceFound"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }


            // Prepare Data to Document datatable.
            if (!isCopy)
            {
                SCGDocumentService.PrepareDataToDataset(remittanceDS, documentID);
            }
            else
            {
                SCGDocumentService.PrepareDataInternalToDataset(remittanceDS, documentID, isCopy);
            }
            // Set data to Remittance Document row in FnremittanceDS.
            FnRemittanceDataset.FnRemittanceRow remittanceRow = remittanceDS.FnRemittance.NewFnRemittanceRow();
            remittanceRow.RemittanceID = remittance.RemittanceID;
            //remittanceRow.SAPIONo = remittance.SAPIONo;
            if (!isCopy)
            {
                if (remittance.Document != null)
                {
                    remittanceRow.DocumentID = remittance.Document.DocumentID;
                }
                //remittanceRow.PBID = remittance.PB.Pbid;
                remittanceRow.TotalAmount    = remittance.TotalAmount;
                remittanceRow.isFullClearing = remittance.IsFullClearing;
                remittanceRow.TADocumentID   = remittance.TADocumentID;
            }
            else
            {
                if (remittanceDS.Document.Rows.Count > 0)
                {
                    FnRemittanceDataset.DocumentRow docRow = (FnRemittanceDataset.DocumentRow)remittanceDS.Document.Rows[0];
                    remittanceRow.DocumentID = docRow.DocumentID;
                }
            }
            remittanceRow.PBID = remittance.PB.Pbid;
            remittanceRow.MainCurrencyAmount = remittance.MainCurrencyAmount;
            remittanceRow.IsRepOffice        = Convert.ToBoolean(remittance.IsRepOffice);
            remittanceRow.Active             = remittance.Active;
            remittanceRow.CreBy   = remittance.CreBy;
            remittanceRow.CreDate = remittance.CreDate;
            remittanceRow.UpdBy   = remittance.UpdBy;
            remittanceRow.UpdDate = remittance.UpdDate;
            remittanceRow.UpdPgm  = remittance.UpdPgm;
            // Add Remittance document row to FnremittanceDS.
            remittanceDS.FnRemittance.AddFnRemittanceRow(remittanceRow);

            // Prepare Data to RemittanceItem Datatable.
            FnRemittanceItemService.PrepareDataToDataset(remittanceDS, remittance.RemittanceID);

            // Prepare Data to RemittacneAdvance Datatable.
            FnRemittanceAdvanceService.PrepareDataToDataset(remittanceDS, remittance.RemittanceID);

            return(remittanceDS);
        }
Ejemplo n.º 12
0
 public void UpdateHeaderAndFooterToTransaction(Guid txid, SCGDocument document, FnRemittance remittance)
 {
     SCGDocumentService.UpdateTransactionDocument(txid, document, false, false);
     this.UpdateRemittanceDocumentTransaction(txid, remittance, true);
 }
Ejemplo n.º 13
0
        public AdvanceDataSet PrepareDataToDs(long documentId)
        {
            AdvanceDataSet advanceDs = new AdvanceDataSet();
            //ดึงจาก base มาใส่ใน DataSet
            AvAdvanceDocument avDb = ScgeAccountingQueryProvider.AvAdvanceDocumentQuery.GetAvAdvanceByDocumentID(documentId);

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            if (avDb == null)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("NoAvAdvanceFound"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
            // Prepare Data to Document datatable.
            SCGDocumentService.PrepareDataToDataset(advanceDs, documentId);

            // Set data to Advance Document row in advanceDs.
            AdvanceDataSet.AvAdvanceDocumentRow avRow = advanceDs.AvAdvanceDocument.NewAvAdvanceDocumentRow();
            avRow.AdvanceID  = avDb.AdvanceID;
            avRow.DocumentID = avDb.DocumentID.DocumentID;
            if (avDb.TADocumentID.HasValue)
            {
                avRow.TADocumentID = avDb.TADocumentID.Value;
            }
            else
            {
                avRow.SetTADocumentIDNull();
            }
            avRow.AdvanceType = avDb.AdvanceType;
            if (avDb.PBID != null && avDb.PBID.Pbid > 0)
            {
                avRow.PBID = avDb.PBID.Pbid;
            }
            else
            {
                avRow.SetPBIDNull();
            }
            if (avDb.ServiceTeamID != null && avDb.ServiceTeamID.ServiceTeamID > 0)
            {
                avRow.ServiceTeamID = avDb.ServiceTeamID.ServiceTeamID;
            }
            else
            {
                avRow.SetServiceTeamIDNull();
            }
            avRow.RequestDateOfAdvance    = avDb.RequestDateOfAdvance;
            avRow.DueDateOfRemittance     = avDb.DueDateOfRemittance;
            avRow.RequestDateOfRemittance = avDb.RequestDateOfRemittance;
            if (avDb.AdvanceType == ZoneType.Foreign)
            {
                avRow.ArrivalDate = avDb.ArrivalDate.Value;
            }
            avRow.Reason           = avDb.Reason;
            avRow.PerDiemExRateUSD = (decimal)avDb.PerDiemExRateUSD;
            avRow.Amount           = (decimal)avDb.Amount;
            avRow.RemittanceAmount = (decimal)avDb.RemittanceAmount;
            avRow.ExpenseAmount    = (decimal)avDb.ExpenseAmount;
            avRow.Active           = avDb.Active;
            avRow.CreBy            = UserAccount.UserID;
            avRow.CreDate          = DateTime.Now;
            avRow.UpdBy            = UserAccount.UserID;
            avRow.UpdDate          = DateTime.Now;
            avRow.UpdPgm           = UserAccount.CurrentProgramCode;

            if (avDb.MainCurrencyID.HasValue && avDb.MainCurrencyID.Value > 0)
            {
                avRow.MainCurrencyID = avDb.MainCurrencyID.Value;
            }
            else
            {
                avRow.SetMainCurrencyIDNull();
            }

            if (avDb.MainCurrencyAmount.HasValue)
            {
                avRow.MainCurrencyAmount = (decimal)avDb.MainCurrencyAmount.Value;
            }
            else
            {
                avRow.SetMainCurrencyAmountNull();
            }

            if (avDb.ExchangeRateForLocalCurrency.HasValue)
            {
                avRow.ExchangeRateForLocalCurrency = (decimal)avDb.ExchangeRateForLocalCurrency.Value;
            }
            else
            {
                avRow.SetExchangeRateForLocalCurrencyNull();
            }

            if (avDb.ExchangeRateMainToTHBCurrency.HasValue)
            {
                avRow.ExchangeRateMainToTHBCurrency = (decimal)avDb.ExchangeRateMainToTHBCurrency.Value;
            }
            else
            {
                avRow.SetExchangeRateMainToTHBCurrencyNull();
            }

            if (avDb.LocalCurrencyAmount.HasValue)
            {
                avRow.LocalCurrencyAmount = (decimal)avDb.LocalCurrencyAmount.Value;
            }
            else
            {
                avRow.SetLocalCurrencyAmountNull();
            }

            if (avDb.IsRepOffice.HasValue)
            {
                avRow.IsRepOffice = avDb.IsRepOffice.Value;
            }
            else
            {
                avRow.SetIsRepOfficeNull();
            }


            if (avDb.RequestDateOfAdvanceApproved.HasValue)
            {
                avRow.RequestDateOfAdvanceApproved = avDb.RequestDateOfAdvanceApproved.Value;
            }
            else
            {
                avRow.SetRequestDateOfAdvanceApprovedNull();
            }

            advanceDs.AvAdvanceDocument.AddAvAdvanceDocumentRow(avRow);

            // Prepare Data to AvAdvanceItem Datatable.
            AvAdvanceItemService.PrepareDataToDataset(advanceDs, avRow.AdvanceID, false);

            advanceDs.AcceptChanges();
            return(advanceDs);
        }
        public DataSet PrepareInternalDataToDataset(long documentId, bool isCopy)
        {
            FixedAdvanceDataSet fixedadvanceDs = new FixedAdvanceDataSet();
            //ดึงจาก base มาใส่ใน DataSet
            FixedAdvanceDocument favDb = ScgeAccountingQueryProvider.FixedAdvanceDocumentQuery.GetFixedAdvanceByDocumentID(documentId);

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            if (favDb == null)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("NoFixedAdvanceFound"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
            // Prepare Data to Document datatable.
            if (!isCopy)
            {
                SCGDocumentService.PrepareDataToDataset(fixedadvanceDs, documentId);
            }
            else
            {
                SCGDocumentService.PrepareDataInternalToDataset(fixedadvanceDs, documentId, isCopy);
            }

            // Set data to Advance Document row in advanceDs.
            FixedAdvanceDataSet.FixedAdvanceDocumentRow favRow = fixedadvanceDs.FixedAdvanceDocument.NewFixedAdvanceDocumentRow();
            if (!isCopy)
            {
                favRow.DocumentID        = favDb.DocumentID.DocumentID;
                favRow.FixedAdvanceID    = favDb.FixedAdvanceID;
                favRow.EffectiveFromDate = favDb.EffectiveFromDate;
                favRow.EffectiveToDate   = favDb.EffectiveToDate;
                favRow.RequestDate       = favDb.RequestDate;
                if (favDb.ReturnRequestDate != null)
                {
                    favRow.ReturnRequestDate = (DateTime)favDb.ReturnRequestDate;
                }
                /*Check RefFixedAdvanceID is null*/
                favRow.Objective = favDb.Objective;
                if (favDb.RefFixedAdvanceID != null)
                {
                    favRow.RefFixedAdvanceID = (long)favDb.RefFixedAdvanceID;
                }
                favRow.FixedAdvanceType = favDb.FixedAdvanceType;
                favRow.Amount           = (decimal)favDb.Amount;
                favRow.NetAmount        = (decimal)favDb.NetAmount;
            }
            else
            {
                if (fixedadvanceDs.Document.Rows.Count > 0)
                {
                    FixedAdvanceDataSet.DocumentRow docRow = (FixedAdvanceDataSet.DocumentRow)fixedadvanceDs.Document.Rows[0];
                    favRow.DocumentID = docRow.DocumentID;
                }
                favRow.EffectiveFromDate = favDb.EffectiveFromDate;
                favRow.EffectiveToDate   = favDb.EffectiveToDate;
                favRow.RequestDate       = favDb.RequestDate;
                if (favDb.ReturnRequestDate != null)
                {
                    favRow.ReturnRequestDate = (DateTime)favDb.ReturnRequestDate;
                }
                favRow.Objective = favDb.Objective;
                if (favDb.RefFixedAdvanceID != null)
                {
                    favRow.RefFixedAdvanceID = (long)favDb.RefFixedAdvanceID;
                }
                favRow.FixedAdvanceType = favDb.FixedAdvanceType;
                favRow.Amount           = (decimal)favDb.Amount;
                favRow.NetAmount        = (decimal)favDb.NetAmount;
            }

            favRow.PaymentType       = favDb.PaymentType;
            favRow.ReturnPaymentType = favDb.ReturnPaymentType;

            if (favDb.PBID != null && favDb.PBID.Pbid > 0)
            {
                favRow.PBID = favDb.PBID.Pbid;
            }
            else
            {
                favRow.SetPBIDNull();
            }

            if (favDb.ReturnPBID != null && favDb.ReturnPBID.Pbid > 0)
            {
                favRow.ReturnPBID = favDb.ReturnPBID.Pbid;
            }
            else
            {
                favRow.SetReturnPBIDNull();
            }

            if (favDb.ReturnServiceTeamID != null && favDb.ReturnServiceTeamID.ServiceTeamID > 0)
            {
                favRow.ReturnServiceTeamID = favDb.ReturnServiceTeamID.ServiceTeamID;
            }
            else
            {
                favRow.SetReturnServiceTeamIDNull();
            }

            favRow.PostingStatusReturn     = favDb.PostingStatusReturn;
            favRow.BranchCodeReturn        = favDb.BranchCodeReturn;
            favRow.FixedAdvanceBankAccount = favDb.FixedAdvanceBankAccount;
            if (favDb.PaymentMethodIDReturn != null)
            {
                favRow.PaymentMethodIDReturn = (long)favDb.PaymentMethodIDReturn;
            }

            if (favDb.PostingDateReturn != null)
            {
                favRow.PostingDateReturn = (DateTime)favDb.PostingDateReturn;
            }
            else
            {
                favRow.PostingDateReturn = DateTime.MinValue;
            }

            if (favDb.BaseLineDateReturn != null)
            {
                favRow.BaseLineDateReturn = (DateTime)favDb.BaseLineDateReturn;
            }
            else
            {
                favRow.BaseLineDateReturn = DateTime.MinValue;
            }

            favRow.Active  = favDb.Active;
            favRow.CreBy   = UserAccount.UserID;
            favRow.CreDate = DateTime.Now;
            favRow.UpdBy   = UserAccount.UserID;
            favRow.UpdDate = DateTime.Now;
            favRow.UpdPgm  = UserAccount.CurrentProgramCode;
            fixedadvanceDs.FixedAdvanceDocument.AddFixedAdvanceDocumentRow(favRow);
            return(fixedadvanceDs);
        }