Beispiel #1
0
        public void SaveExpenseAdvance(Guid txID, long expDocumentID)
        {
            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txID);

            ScgeAccountingDaoProvider.FnExpenseAdvanceDao.Persist(ds.FnExpenseAdvance);
        }
Beispiel #2
0
        public void AddExpensePerdiemItemTransaction(FnExpensePerdiemItem item, Guid txId)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            string PerdiemType = GetPerdiemType(item, txId);

            if (!item.FromDate.HasValue)
            {
                errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("RequiredFromDate"));
            }
            if (!item.FromTime.HasValue)
            {
                errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("RequiredFromTime"));
            }
            if (!item.ToDate.HasValue)
            {
                errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("RequiredToDate"));
            }
            if (!item.ToTime.HasValue)
            {
                errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("RequiredToTime"));
            }
            if (item.FromDate.HasValue && item.FromTime.HasValue && item.ToDate.HasValue && item.ToTime.HasValue)
            {
                DateTime FromDateTime = ConvertDateTime(item.FromDate, item.FromTime);
                DateTime ToDateTime   = ConvertDateTime(item.ToDate, item.ToTime);

                if (DateTime.Compare(ToDateTime, DateTime.Now.Date) > 0)
                {
                    errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("PleaseSelectDateIsNotToday"));
                }
                if (ToDateTime < FromDateTime)
                {
                    errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("RequiredToDateIncorrect"));
                }
                else
                {
                    if (CalculateNetDay(CalculateTotalDay(FromDateTime, ToDateTime, PerdiemType), item.AdjustedDay) < 0)
                    {
                        errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("Invalid Date Information"));
                    }
                    if (PerdiemType == ZoneType.Foreign)
                    {
                        if (item.HalfDay < 0)
                        {
                            errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("Invalid Date Information"));
                        }
                        else
                        {
                            if (CalculateFullDay(CalculateNetDay(CalculateTotalDay(FromDateTime, ToDateTime, PerdiemType), item.AdjustedDay), item.HalfDay) < 0)
                            {
                                errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("Invalid Date Information"));
                            }
                        }
                    }
                }
            }
            if (PerdiemType == ZoneType.Foreign)
            {
                if (!item.CountryID.HasValue && string.IsNullOrEmpty(item.Remark))
                {
                    errors.AddError("PerdiemItem.Error", new Spring.Validation.ErrorMessage("Remark is required"));
                }
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.FnExpensePerdiemItemRow row = ds.FnExpensePerdiemItem.NewFnExpensePerdiemItemRow();

            row.ExpensePerdiemID = item.ExpensePerdiem.ExpensePerdiemID;
            row.FromDate         = item.FromDate.Value;
            row.FromTime         = ConvertDateTime(item.FromDate.Value, item.FromTime.Value);
            row.ToDate           = item.ToDate.Value;
            row.ToTime           = ConvertDateTime(item.ToDate, item.ToTime);
            row.AdjustedDay      = (decimal)item.AdjustedDay;
            row.NetDay           = (decimal)CalculateNetDay(CalculateTotalDay(row.FromTime, row.ToTime, PerdiemType), item.AdjustedDay);

            //** for Domestic and Foreign
            row.Remark = item.Remark;

            if (PerdiemType == ZoneType.Foreign)
            {
                row.HalfDay = (decimal)item.HalfDay;
                row.FullDay = (decimal)CalculateFullDay((double)row.NetDay, (double)row.HalfDay);

                if (item.CountryID.HasValue)
                {
                    row.CountryID = item.CountryID.Value;
                }
                if (item.CountryZoneID.HasValue)
                {
                    row.CountryZoneID = item.CountryZoneID.Value;
                }
            }
            row.CreBy   = row.UpdBy = UserAccount.UserID;
            row.CreDate = row.UpdDate = DateTime.Now.Date;
            row.UpdPgm  = item.UpdPgm;
            row.Active  = true;

            ds.FnExpensePerdiemItem.AddFnExpensePerdiemItemRow(row);
            FnExpensePerdiemService.UpdateExpensePerdiemCalculateTransaction(item.ExpensePerdiem.ExpensePerdiemID, txId);
        }
        public void UpdateTransactionDocument(Guid TxID, SCGDocument document, bool haveReceiver, bool haveApprover)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            try
            {
                this.ValidateSCGDocument(document, haveReceiver, haveApprover);
            }
            catch (ServiceValidationException ex)
            {
                errors.MergeErrors(ex.ValidationErrors);
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            DataSet   ds            = TransactionService.GetDS(TxID);
            DataTable documentTable = ds.Tables["Document"];

            if (documentTable.Rows.Count > 0)
            {
                DataRow documentRow = documentTable.Rows[0];
                documentRow.BeginEdit();

                if (document.CompanyID != null)
                {
                    documentRow["CompanyID"] = document.CompanyID.CompanyID;
                }
                if (document.CreatorID != null)
                {
                    documentRow["CreatorID"] = document.CreatorID.Userid;
                }
                if (document.RequesterID != null)
                {
                    documentRow["RequesterID"] = document.RequesterID.Userid;
                }
                if (document.ApproverID != null)
                {
                    documentRow["ApproverID"] = document.ApproverID.Userid;
                }
                if (document.ReceiverID != null)
                {
                    documentRow["ReceiverID"] = document.ReceiverID.Userid;
                }
                //documentRow["DocumentNo"] = document.DocumentNo;
                if (document.DocumentType != null)
                {
                    documentRow["DocumentTypeID"] = document.DocumentType.DocumentTypeID;
                }
                IList <object> advanceEditableField      = AvAdvanceDocumentService.GetEditableFields(document.DocumentID, null);
                IList <object> expenseEditableField      = FnExpenseDocumentService.GetEditableFields(document.DocumentID);
                IList <object> remittanceEditableField   = FnRemittanceService.GetEditableFields(document.DocumentID);
                IList <object> fixedAdvanceEditableField = FixedAdvanceDocumentService.GetEditableFields(document.DocumentID);
                if (advanceEditableField.Contains(AdvanceFieldGroup.VerifyDetail) || expenseEditableField.Contains(ExpenseFieldGroup.VerifyDetail) || remittanceEditableField.Contains(RemittanceFieldGroup.VerifyDetail) || fixedAdvanceEditableField.Contains(FixedAdvanceFieldGroup.VerifyDetail))
                {
                    //add new field
                    if (!string.IsNullOrEmpty(document.BranchCode))
                    {
                        documentRow["BranchCode"] = document.BranchCode;
                    }
                    if (!string.IsNullOrEmpty(document.BusinessArea))
                    {
                        documentRow["BusinessArea"] = document.BusinessArea;
                    }
                    else
                    {
                        documentRow["BusinessArea"] = string.Empty;
                    }

                    if (!string.IsNullOrEmpty(document.Supplementary))
                    {
                        documentRow["Supplementary"] = document.Supplementary;
                    }
                    else
                    {
                        documentRow["Supplementary"] = string.Empty;
                    }

                    if (document.PaymentMethodID.HasValue && document.PaymentMethodID > 0)
                    {
                        documentRow["PaymentMethodID"] = document.PaymentMethodID.Value;
                    }
                    if (document.PostingDate.HasValue && document.PostingDate.Value != DateTime.MinValue)
                    {
                        documentRow["PostingDate"] = document.PostingDate;
                    }
                    if (document.BaseLineDate.HasValue && document.BaseLineDate.Value != DateTime.MinValue)
                    {
                        documentRow["BaseLineDate"] = document.BaseLineDate;
                    }
                    if (!string.IsNullOrEmpty(document.BankAccount))
                    {
                        documentRow["BankAccount"] = document.BankAccount;
                    }
                }
                if (!string.IsNullOrEmpty(document.ReferenceNo))
                {
                    documentRow["ReferenceNo"] = document.ReferenceNo;
                }
                else
                {
                    if (!documentRow["DocumentNo"].ToString().StartsWith("EHR"))
                    {
                        documentRow["ReferenceNo"] = document.ReferenceNo;
                    }
                }

                documentRow["IsVerifyImage"] = document.IsVerifyImage;
                documentRow["Subject"]       = document.Subject;
                documentRow["Memo"]          = document.Memo;
                documentRow["Active"]        = document.Active;
                documentRow["CreBy"]         = UserAccount.UserID;
                documentRow["CreDate"]       = DateTime.Now;
                documentRow["UpdBy"]         = UserAccount.UserID;
                documentRow["UpdDate"]       = DateTime.Now;
                documentRow["UpdPgm"]        = UserAccount.CurrentProgramCode;

                documentRow.EndEdit();
            }
        }
        public void UpdateCADocumentTransaction(Guid txID, CADocument caDocument)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            CADocumentDataSet caDocumentDS = (CADocumentDataSet)TransactionService.GetDS(txID);

            CADocumentDataSet.CADocumentRow caDocumentRow = caDocumentDS.CADocument.FindByCADocumentID(caDocument.CADocumentID);

            caDocumentRow.BeginEdit();

            caDocumentRow.DocumentID = caDocument.DocumentID.DocumentID;

            //if (mpaDocument.StartDate < DateTime.Today)
            //{
            //    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("StartDateMoreOrEqualToDay"));
            //}

            if (caDocument.StartDate > caDocument.EndDate)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("StartDateLessOrEqualEndDate"));
            }

            if (caDocument.StartDate.Equals(DateTime.MinValue))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("StartDateIsRequired"));
            }
            else
            {
                caDocumentRow.StartDate = caDocument.StartDate;
            }

            if (caDocument.EndDate.Equals(DateTime.MinValue))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EndDateIsRequired"));
            }
            else
            {
                caDocumentRow.EndDate = caDocument.EndDate;
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            caDocumentRow.IsTemporary  = caDocument.IsTemporary;
            caDocumentRow.CarLicenseNo = caDocument.CarLicenseNo;
            caDocumentRow.Brand        = caDocument.Brand;
            caDocumentRow.Model        = caDocument.Model;
            if (caDocument.IsWorkArea.HasValue)
            {
                caDocumentRow.IsWorkArea = caDocument.IsWorkArea.Value;
            }
            caDocumentRow.Remark    = caDocument.Remark;
            caDocumentRow.CarType   = caDocument.CarType;
            caDocumentRow.OwnerType = caDocument.OwnerType;
            caDocumentRow.Active    = caDocument.Active;
            caDocumentRow.CreBy     = UserAccount.UserID;
            caDocumentRow.CreDate   = DateTime.Now;
            caDocumentRow.UpdBy     = UserAccount.UserID;
            caDocumentRow.UpdDate   = DateTime.Now;
            caDocumentRow.UpdPgm    = UserAccount.CurrentProgramCode;

            caDocumentRow.EndEdit();
        }
Beispiel #5
0
        public long AddFnRemittanceItemTransaction(Guid txID, FnRemittanceItem fnRemittanceItem, bool isFromAddvance, double totalAdvance)
        {
            Spring.Validation.ValidationErrors errors  = new Spring.Validation.ValidationErrors();
            FnRemittanceDataset fnRemittanceDocumentDS = (FnRemittanceDataset)TransactionService.GetDS(txID);

            DataRow[] dr;
            //FnRemittanceDataset.FnRemittanceRow remittanceRow = fnRemittanceDocumentDS.FnRemittance.FindByRemittanceID(fnRemittanceItem.Remittance.RemittanceID);
            if (fnRemittanceItem.Remittance.PB.Pbid != 0)
            {
                Dbpb dbPb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(Convert.ToInt64(fnRemittanceItem.Remittance.PB.Pbid));
                IsRepOffice = dbPb.RepOffice;
            }
            if (isFromAddvance)
            {
                string strSQL = " PaymentType = '{0}' AND CurrencyID = {1} ";
                dr = fnRemittanceDocumentDS.FnRemittanceItem.Select(string.Format(strSQL, fnRemittanceItem.PaymentType, fnRemittanceItem.Currency.CurrencyID));
            }
            else
            {
                if (fnRemittanceItem.Currency == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CurrencyIsRequire"));
                }
                if (fnRemittanceItem.ExchangeRate == 0 || fnRemittanceItem.ForeignCurrencyRemitted == 0)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ExchangerateAndForeignCurrencyRemittedMustMoreThanZero"));
                }
                double totalRemittanceItemAmount = 0;
                foreach (FnRemittanceDataset.FnRemittanceItemRow remittanceItemRow in fnRemittanceDocumentDS.FnRemittanceItem.Select())
                {
                    if (!IsRepOffice)
                    {
                        totalRemittanceItemAmount += (double)Math.Round((decimal)remittanceItemRow.AmountTHB, 2, MidpointRounding.AwayFromZero);
                    }
                    else
                    {
                        totalRemittanceItemAmount += (double)Math.Round((decimal)remittanceItemRow.MainCurrencyAmount, 2, MidpointRounding.AwayFromZero);
                    }
                }
                if (!IsRepOffice)
                {
                    if (totalRemittanceItemAmount + fnRemittanceItem.AmountTHB > totalAdvance)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TotalRemittanceItemNotMoreThanTotalAdvance"));
                    }
                }
                else
                {
                    if (totalRemittanceItemAmount + fnRemittanceItem.MainCurrencyAmount > totalAdvance)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TotalRemittanceItemNotMoreThanTotalAdvance"));
                    }
                }
                if (!errors.IsEmpty)
                {
                    throw new ServiceValidationException(errors);
                }
                dr = fnRemittanceDocumentDS.FnRemittanceItem.Select(string.Format("CurrencyID = {0}", fnRemittanceItem.Currency.CurrencyID.ToString()));
            }
            if (dr.Length > 0)
            {
                if (isFromAddvance)
                {
                    dr[0]["ForeignAmountTHBAdvanced"] = Convert.ToDouble(dr[0]["ForeignAmountTHBAdvanced"]) + fnRemittanceItem.ForeignAmountTHBAdvanced;
                    dr[0]["ForeignCurrencyAdvanced"]  = Convert.ToDouble(dr[0]["ForeignCurrencyAdvanced"]) + fnRemittanceItem.ForeignCurrencyAdvanced;

                    if (Convert.ToDouble(dr[0]["ExchangeRate"]).Equals(0))
                    {
                        dr[0]["ExchangeRate"] = fnRemittanceItem.ExchangeRate;
                    }
                    else
                    {
                        dr[0]["ExchangeRate"] = (Convert.ToDouble(dr[0]["ExchangeRate"]) + fnRemittanceItem.ExchangeRate) / 2;
                    }
                }
                else
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("DuplicateCurrency"));
                }
                if (!errors.IsEmpty)
                {
                    throw new ServiceValidationException(errors);
                }
                return(Convert.ToInt64(dr[0]["RemittanceItemID"]));
            }
            else
            {
                FnRemittanceDataset.FnRemittanceItemRow fnRemittanceItemRow = fnRemittanceDocumentDS.FnRemittanceItem.NewFnRemittanceItemRow();

                if (fnRemittanceItem.Remittance != null)
                {
                    fnRemittanceItemRow.RemittanceID = fnRemittanceItem.Remittance.RemittanceID;
                }
                fnRemittanceItemRow.PaymentType                       = fnRemittanceItem.PaymentType;
                fnRemittanceItemRow.CurrencyID                        = fnRemittanceItem.Currency.CurrencyID;
                fnRemittanceItemRow.ForeignCurrencyAdvanced           = (double)Math.Round((decimal)fnRemittanceItem.ForeignCurrencyAdvanced, 2, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ExchangeRate                      = (double)Math.Round((decimal)fnRemittanceItem.ExchangeRate, 5, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ForeignCurrencyRemitted           = (double)Math.Round((decimal)fnRemittanceItem.ForeignCurrencyRemitted, 2, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ForeignAmountTHBAdvanced          = (double)Math.Round((decimal)fnRemittanceItem.ForeignAmountTHBAdvanced, 2, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ExchangeRateTHB                   = (double)Math.Round((decimal)fnRemittanceItem.ExchangeRateTHB, 5, MidpointRounding.AwayFromZero);
                fnRemittanceItemRow.ForeignAmountMainCurrencyAdvanced = (double)Math.Round((decimal)fnRemittanceItem.ForeignAmountMainCurrencyAdvanced, 2, MidpointRounding.AwayFromZero);

                if (isFromAddvance)
                {
                    fnRemittanceItemRow.AmountTHB          = 0.00;
                    fnRemittanceItemRow.MainCurrencyAmount = 0.00;
                }
                else
                {
                    fnRemittanceItemRow.AmountTHB          = (double)Math.Round((decimal)fnRemittanceItem.AmountTHB, 2, MidpointRounding.AwayFromZero);
                    fnRemittanceItemRow.MainCurrencyAmount = (double)Math.Round((decimal)fnRemittanceItem.MainCurrencyAmount, 2, MidpointRounding.AwayFromZero);
                }
                fnRemittanceItemRow.IsImportFromAdvance = isFromAddvance;
                fnRemittanceItemRow.Active  = fnRemittanceItem.Active;
                fnRemittanceItemRow.CreBy   = UserAccount.UserID;
                fnRemittanceItemRow.CreDate = DateTime.Now;
                fnRemittanceItemRow.UpdBy   = UserAccount.UserID;
                fnRemittanceItemRow.UpdDate = DateTime.Now;
                fnRemittanceItemRow.UpdPgm  = UserAccount.CurrentProgramCode;
                fnRemittanceDocumentDS.FnRemittanceItem.AddFnRemittanceItemRow(fnRemittanceItemRow);

                FnRemittanceService.UpdateTotalRemittanceAmount(txID, fnRemittanceItemRow.RemittanceID);

                return(fnRemittanceItemRow.RemittanceItemID);
            }
        }
        public void ValidateInvoiceItem(Guid txId, long expenseId)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            ExpenseDataSet expDs = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.FnExpenseDocumentRow      expRow   = expDs.FnExpenseDocument.FindByExpenseID(expenseId);
            ExpenseDataSet.DocumentRow               docRow   = expDs.Document.FindByDocumentID(expRow.DocumentID);
            ExpenseDataSet.FnExpenseInvoiceItemRow[] itemRows = (ExpenseDataSet.FnExpenseInvoiceItemRow[])expDs.FnExpenseInvoiceItem.Select();

            foreach (ExpenseDataSet.FnExpenseInvoiceItemRow row in itemRows)
            {
                string accountCode = string.Empty;
                if (!row.IsIOIDNull())
                {
                    DbInternalOrder io = ScgDbQueryProvider.DbIOQuery.FindByIdentity(row.IOID);
                    if (io == null || !io.CompanyID.HasValue || io.CompanyID.Value != docRow.CompanyID)
                    {
                        if (io == null)
                        {
                            io = new DbInternalOrder()
                            {
                                IONumber = "Unknown"
                            };
                        }
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("InternalOrder_Is_Invalid", new object[] { io.IONumber }));
                    }
                }
                if (!row.IsAccountIDNull())
                {
                    DbAccount account = ScgDbQueryProvider.DbAccountQuery.FindByIdentity(row.AccountID);


                    IList <VOAccountCompany> accountList = ScgDbQueryProvider.DbAccountCompanyQuery.FindAccountCompany(docRow.CompanyID, row.AccountID);
                    if (account == null || accountList.Count == 0)
                    {
                        if (account == null)
                        {
                            account = new DbAccount()
                            {
                                AccountCode = "Unknown"
                            };
                        }
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ExpenseCode_Is_Invalid", new object[] { account.AccountCode }));
                    }
                    accountCode = account.AccountCode;
                }
                if (!row.IsCostCenterIDNull())
                {
                    DbCostCenter cost = ScgDbQueryProvider.DbCostCenterQuery.FindByIdentity(row.CostCenterID);

                    if (cost == null || cost.CompanyID == null || cost.CompanyID.CompanyID != docRow.CompanyID)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CostCenter_Is_Invalid", new object[] { cost.CostCenterCode }));
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(accountCode))
                        {
                            DbAccount ac = ScgDbQueryProvider.DbAccountQuery.FindAccountByAccountCodeExpenseGroup(accountCode, null);
                            if (ac == null)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ExpenseCode_Is_Invalid_With_Costcenter", new object[] { accountCode, cost.CostCenterCode }));
                            }
                        }
                    }
                }
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
        }
        public void UpdateTADocumentTransaction(Guid txID, TADocument taDocument)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            TADocumentDataSet taDocumentDS = (TADocumentDataSet)TransactionService.GetDS(txID);

            TADocumentDataSet.TADocumentRow taDocumentRow = taDocumentDS.TADocument.FindByTADocumentID(taDocument.TADocumentID);

            taDocumentRow.BeginEdit();

            taDocumentRow.DocumentID = taDocument.DocumentID.DocumentID;

            if (taDocument.FromDate < DateTime.Today)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("FromDateMoreOrEqualToDay"));
            }

            if (taDocument.FromDate > taDocument.ToDate)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("FromDateLessOrEqualToDate"));
            }

            if (taDocument.FromDate.Equals(DateTime.MinValue))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("FromDateIsRequired"));
            }
            else
            {
                taDocumentRow.FromDate = taDocument.FromDate;
            }

            if (taDocument.ToDate.Equals(DateTime.MinValue))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ToDateIsRequired"));
            }
            else
            {
                taDocumentRow.ToDate = taDocument.ToDate;
            }

            if (((!taDocument.IsBusinessPurpose) && (!taDocument.IsTrainningPurpose) && (!taDocument.IsOtherPurpose)))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("PurposeIsRequired"));
            }
            else
            {
                taDocumentRow.IsBusinessPurpose  = taDocument.IsBusinessPurpose;
                taDocumentRow.IsTrainningPurpose = taDocument.IsTrainningPurpose;
                taDocumentRow.IsOtherPurpose     = taDocument.IsOtherPurpose;
            }

            if (taDocument.IsOtherPurpose && string.IsNullOrEmpty(taDocument.OtherPurposeDescription))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("OtherIsRequired"));
            }
            else
            {
                taDocumentRow.OtherPurposeDescription = taDocument.OtherPurposeDescription;
            }

            if ((!string.IsNullOrEmpty(taDocument.TravelBy)) && taDocument.TravelBy.Trim().ToUpper().Equals("D") && string.IsNullOrEmpty(taDocument.Province))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TravelByProvinceIsRequired"));
            }
            else
            {
                taDocumentRow.Province = taDocument.Province;
            }

            if ((!string.IsNullOrEmpty(taDocument.TravelBy)) && taDocument.TravelBy.Trim().ToUpper().Equals("F") && string.IsNullOrEmpty(taDocument.Country))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TravelByCountryIsRequired"));
            }
            else
            {
                taDocumentRow.Country = taDocument.Country;
            }

            if (string.IsNullOrEmpty(taDocument.TravelBy))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TravelByIsRequired"));
            }
            else
            {
                taDocumentRow.TravelBy = taDocument.TravelBy;
            }

            if (string.IsNullOrEmpty(taDocument.Ticketing))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("TicketingIsRequired"));
            }
            else
            {
                taDocumentRow.Ticketing = taDocument.Ticketing;
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            taDocumentRow.Active  = taDocument.Active;
            taDocumentRow.CreBy   = UserAccount.UserID;
            taDocumentRow.CreDate = DateTime.Now;
            taDocumentRow.UpdBy   = UserAccount.UserID;
            taDocumentRow.UpdDate = DateTime.Now;
            taDocumentRow.UpdPgm  = UserAccount.CurrentProgramCode;

            taDocumentRow.EndEdit();
        }
        public void UpdateInvoiceItemByInvoiceID(Guid txID, long invoiceId, FnExpenseDocument expenseDocument)
        {
            ExpenseDataSet expDS = (ExpenseDataSet)TransactionService.GetDS(txID);

            ExpenseDataSet.FnExpenseInvoiceRow       invoiceRow = expDS.FnExpenseInvoice.FindByInvoiceID(invoiceId);
            ExpenseDataSet.FnExpenseInvoiceItemRow[] itemRows   = (ExpenseDataSet.FnExpenseInvoiceItemRow[])expDS.FnExpenseInvoiceItem.Select();
            DbAccount account = new DbAccount();

            foreach (ExpenseDataSet.FnExpenseInvoiceItemRow row in itemRows)
            {
                account = ScgDbQueryProvider.DbAccountQuery.FindByIdentity(row.AccountID);
            }
            string filter = String.Format("InvoiceID = {0}", invoiceId);

            DataRow[] rows = expDS.FnExpenseInvoiceItem.Select(filter);
            Dbpb      pb   = null;
            double    totalLocalCurrencyAmount = 0;
            double    totalMainCurrencyAmount  = 0;
            double    totalAmountTHB           = 0;
            bool      isRepOffice = expenseDocument.IsRepOffice.HasValue ? expenseDocument.IsRepOffice.Value : false;

            if (expenseDocument.PB != null)
            {
                pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(expenseDocument.PB.Pbid);
            }

            foreach (DataRow row in rows)
            {
                FnExpenseInvoiceItem item = new FnExpenseInvoiceItem();
                item.LoadFromDataRow(row);
                item.Invoice.Expense = expenseDocument;
                if (account.SaveAsVendor)
                {
                    if (invoiceRow.isVAT)
                    {
                        if (!invoiceRow.IsVendorIDNull())
                        {
                            item.VendorCodeAP = invoiceRow.VendorCode;
                        }
                    }
                }
                if (isRepOffice)
                {
                    if (expenseDocument.MainCurrencyID.HasValue)
                    {
                        item.MainCurrencyID = expenseDocument.MainCurrencyID.Value;
                    }

                    if (expenseDocument.ExchangeRateForLocalCurrency.HasValue && expenseDocument.ExchangeRateForLocalCurrency.Value != 0)
                    {
                        if (item.LocalCurrencyAmount.HasValue)
                        {
                            if (expenseDocument.MainCurrencyID == expenseDocument.LocalCurrencyID)
                            {
                                item.MainCurrencyAmount = item.LocalCurrencyAmount;
                            }
                            else
                            {
                                item.MainCurrencyAmount = (double)Math.Round((decimal)(item.LocalCurrencyAmount.Value / expenseDocument.ExchangeRateForLocalCurrency.Value), 2, MidpointRounding.AwayFromZero);
                            }
                            totalMainCurrencyAmount  += item.MainCurrencyAmount.Value;
                            totalLocalCurrencyAmount += item.LocalCurrencyAmount.Value;
                        }
                    }

                    if (expenseDocument.ExchangeRateMainToTHBCurrency.HasValue)
                    {
                        if (item.MainCurrencyAmount.HasValue)
                        {
                            item.Amount     = (double)Math.Round((decimal)(item.MainCurrencyAmount * expenseDocument.ExchangeRateMainToTHBCurrency), 2, MidpointRounding.AwayFromZero);
                            totalAmountTHB += item.Amount.Value;
                        }
                    }
                }
                else
                {
                    if (expenseDocument.ExpenseType == ZoneType.Foreign)
                    {
                        //item.ExchangeRate = (double)Math.Round(Convert.ToDecimal(expenseDocument.ExchangeRateForUSDAdvance), 4, MidpointRounding.AwayFromZero);
                        item.Amount = (double)Math.Round(Convert.ToDecimal(item.CurrencyAmount * item.ExchangeRate), 2, MidpointRounding.AwayFromZero);
                    }

                    totalAmountTHB += item.Amount.Value;
                }
                UpdateInvoiceItemOnTransaction(item, txID, expenseDocument.ExpenseType);
            }
            invoiceRow.BeginEdit();
            if (isRepOffice)
            {
                invoiceRow.TotalAmountLocalCurrency = invoiceRow.TotalBaseAmountLocalCurrency = invoiceRow.NetAmountLocalCurrency = (decimal)totalLocalCurrencyAmount;
            }
            invoiceRow.TotalAmount = (decimal)totalAmountTHB;
            invoiceRow.EndEdit();
        }
        public void AddRecommendInvoiceItemOnTransaction(long invoiceId, string expenseType, IList <FnExpenseInvoiceItem> recommendList, Guid txId)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            ExpenseDataSet ds              = (ExpenseDataSet)TransactionService.GetDS(txId);
            short?         mainCurrencyID  = null;
            short?         localCurrencyID = null;

            if (ds.FnExpenseDocument.Rows.Count > 0)
            {
                if (!string.IsNullOrEmpty(ds.FnExpenseDocument.Rows[0]["MainCurrencyID"].ToString()) && Convert.ToInt16(ds.FnExpenseDocument.Rows[0]["MainCurrencyID"].ToString()) > 0)
                {
                    mainCurrencyID = Convert.ToInt16(ds.FnExpenseDocument.Rows[0]["MainCurrencyID"].ToString());
                }

                if (!string.IsNullOrEmpty(ds.FnExpenseDocument.Rows[0]["LocalCurrencyID"].ToString()) && Convert.ToInt16(ds.FnExpenseDocument.Rows[0]["MainCurrencyID"].ToString()) > 0)
                {
                    localCurrencyID = Convert.ToInt16(ds.FnExpenseDocument.Rows[0]["LocalCurrencyID"].ToString());
                }
            }

            foreach (FnExpenseInvoiceItem item in recommendList)
            {
                ExpenseDataSet.FnExpenseInvoiceItemRow row = ds.FnExpenseInvoiceItem.NewFnExpenseInvoiceItemRow();
                row.InvoiceID = invoiceId;

                if (item.CostCenter == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequiredCostCenter"));
                }
                if (item.Account == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequiredAccountID"));
                }

                if (!errors.IsEmpty)
                {
                    FnExpenseInvoiceService.DeleteInvoiceOnTransaction(invoiceId, txId);
                    throw new ServiceValidationException(errors);
                }

                if (item.CostCenter != null)
                {
                    row.CostCenterID = item.CostCenter.CostCenterID;
                }

                if (item.Account != null)
                {
                    row.AccountID = item.Account.AccountID;
                }

                if (item.IO != null)
                {
                    row.IOID = item.IO.IOID;
                }

                if (item.CurrencyID.HasValue)
                {
                    row.CurrencyID = item.CurrencyID.Value;
                }

                row.Description = item.Description;

                if (item.CurrencyAmount.HasValue)
                {
                    row.CurrencyAmount = item.CurrencyAmount.Value;
                }

                if (item.Amount.HasValue)
                {
                    row.Amount = item.Amount.Value;
                }

                if (item.ExchangeRate.HasValue)
                {
                    row.ExchangeRate = item.ExchangeRate.Value;
                }

                if (mainCurrencyID.HasValue)
                {
                    row.MainCurrencyID = mainCurrencyID.Value;
                }

                if (item.LocalCurrencyAmount.HasValue)
                {
                    row.LocalCurrencyAmount = (decimal)item.LocalCurrencyAmount.Value;
                }

                if (mainCurrencyID == localCurrencyID)
                {
                    row.MainCurrencyAmount = (double)row.LocalCurrencyAmount;
                }

                row.ReferenceNo = item.ReferenceNo;

                row.Active  = true;
                row.CreBy   = UserAccount.UserID;
                row.CreDate = DateTime.Now;
                row.UpdBy   = UserAccount.UserID;
                row.UpdDate = DateTime.Now;
                row.UpdPgm  = UserAccount.CurrentProgramCode;

                ds.FnExpenseInvoiceItem.AddFnExpenseInvoiceItemRow(row);
            }
        }
        public void AddInvoiceItemOnTransaction(FnExpenseInvoiceItem item, Guid txId, string expenseType)
        {
            bool isRepOffice = false;

            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            ExpenseDataSet ds = (ExpenseDataSet)TransactionService.GetDS(txId);

            ExpenseDataSet.FnExpenseDocumentRow expRow = null;
            long documentId = 0;

            if (item.Invoice != null && item.Invoice.Expense != null)
            {
                expRow     = ds.FnExpenseDocument.FindByExpenseID(item.Invoice.Expense.ExpenseID);
                documentId = expRow == null ? 0 : expRow.DocumentID;
                if (!expRow.IsIsRepOfficeNull())
                {
                    isRepOffice = expRow.IsRepOffice;
                }
            }

            // Validate CostCenter.
            if (item.CostCenter == null)
            {
                errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredCostCenter"));
            }
            else
            {
                if (ScgDbQueryProvider.DbCostCenterQuery.FindByIdentity(item.CostCenter.CostCenterID) == null)
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredCostCenter"));
                }
            }

            // Validate Account.
            if (item.Account == null)
            {
                errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAccountID"));
            }
            else
            {
                if (ScgDbQueryProvider.DbAccountQuery.FindByIdentity(item.Account.AccountID) == null)
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAccountID"));
                }
            }

            if (!string.IsNullOrEmpty(item.SaleOrder) && item.SaleOrder.Length < 10)
            {
                errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("SaleOrder_Has_10_Digit"));
            }

            if (expenseType.Equals(ZoneType.Domestic))
            {
                // Validate Amount.
                if (!isRepOffice)
                {
                    if (!item.Amount.HasValue || (item.Amount.HasValue && item.Amount.Value == 0))
                    {
                        errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAmount"));
                    }
                }
                else
                {
                    if (!item.LocalCurrencyAmount.HasValue || (item.LocalCurrencyAmount.HasValue && item.LocalCurrencyAmount.Value == 0))
                    {
                        errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAmount"));
                    }
                }
            }
            else if (expenseType.Equals(ZoneType.Foreign))
            {
                // Validate Currency.
                if (!item.CurrencyID.HasValue || (item.CurrencyID.HasValue && item.CurrencyID.Value == 0))
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredCurrency"));
                }
                // Validate Currency Amount.
                if (!item.CurrencyAmount.HasValue || (item.CurrencyAmount.HasValue && item.CurrencyAmount.Value == 0))
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredAmount"));
                }

                // Validate ExchangeRate.
                if (!item.ExchangeRate.HasValue)
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredExchangeRate"));
                }
                else if ((item.ExchangeRate.HasValue) && (item.ExchangeRate.Value == 0))
                {
                    errors.AddError("InvoiceItem.Error", new Spring.Validation.ErrorMessage("RequiredExchangeRate"));
                }
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            ExpenseDataSet.FnExpenseInvoiceItemRow row = ds.FnExpenseInvoiceItem.NewFnExpenseInvoiceItemRow();

            if (item.Invoice != null)
            {
                row.InvoiceID = item.Invoice.InvoiceID;
            }

            if (item.CostCenter != null)
            {
                row.CostCenterID = item.CostCenter.CostCenterID;
            }
            else
            {
                row.SetCostCenterIDNull();
            }

            row.AccountID = item.Account.AccountID;

            if (item.IO != null)
            {
                row.IOID = item.IO.IOID;
            }

            if (item.CurrencyID.HasValue)
            {
                row.CurrencyID = item.CurrencyID.Value;
            }

            if (item.ExchangeRate.HasValue)
            {
                row.ExchangeRate = item.ExchangeRate.Value;
            }

            if (item.CurrencyAmount.HasValue)
            {
                row.CurrencyAmount = item.CurrencyAmount.Value;
            }

            if (item.LocalCurrencyAmount.HasValue)
            {
                row.LocalCurrencyAmount = (decimal)item.LocalCurrencyAmount.Value;
            }

            if (item.MainCurrencyAmount.HasValue)
            {
                row.MainCurrencyAmount = item.MainCurrencyAmount.Value;
            }

            if (expenseType.Equals(ZoneType.Foreign) && !isRepOffice)
            {
                row.Amount = (double)Math.Round((decimal)(item.CurrencyAmount.Value * item.ExchangeRate.Value), 2, MidpointRounding.AwayFromZero);
            }
            else
            {
                if (item.Amount.HasValue)
                {
                    row.Amount = item.Amount.Value;
                }
            }

            row.SaleOrder   = item.SaleOrder;
            row.SaleItem    = item.SaleItem;
            row.Description = item.Description;
            row.ReferenceNo = item.ReferenceNo;

            row.Active  = true;
            row.CreBy   = UserAccount.UserID;
            row.CreDate = DateTime.Now;
            row.UpdBy   = UserAccount.UserID;
            row.UpdDate = DateTime.Now;
            row.UpdPgm  = UserAccount.CurrentProgramCode;

            ds.FnExpenseInvoiceItem.AddFnExpenseInvoiceItemRow(row);
        }
Beispiel #11
0
        public void UpdateAvDocumentTransaction(AvAdvanceDocument avAdvanceDoc, Guid txid)
        {
            bool           isRepOffice          = false;
            IList <object> advanceEditableField = new List <object>();
            string         mode = string.Empty;

            if (UserAccount.CurrentProgramCode == "AdvanceForeignForm")
            {
                mode = "FR";
            }
            else if (UserAccount.CurrentProgramCode == "AdvanceDomesticForm")
            {
                mode = "DM";
            }
            if (avAdvanceDoc.DocumentID != null)
            {
                advanceEditableField = GetEditableFields(avAdvanceDoc.DocumentID.DocumentID, null);
            }
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            AdvanceDataSet ds = (AdvanceDataSet)TransactionService.GetDS(txid);

            AdvanceDataSet.AvAdvanceDocumentRow rowAdvance = (AdvanceDataSet.AvAdvanceDocumentRow)ds.AvAdvanceDocument.FindByAdvanceID(avAdvanceDoc.AdvanceID);
            SS.Standard.WorkFlow.DTO.WorkFlow   workFlow   = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(avAdvanceDoc.DocumentID.DocumentID);

            AdvanceDataSet.DocumentRow rowDocument = (AdvanceDataSet.DocumentRow)ds.Document.FindByDocumentID(rowAdvance.DocumentID);
            if (!rowAdvance.IsIsRepOfficeNull())
            {
                isRepOffice = rowAdvance.IsRepOffice;
            }
            //IList<AvAdvanceItem> advanceItem = ScgeAccountingQueryProvider.AvAdvanceItemQuery.FindByAvAdvanceItemAdvanceID(rowAdvance.AdvanceID);
            //ds.AvAdvanceItem.FindByAdvanceID(rowAdvance.AdvanceID);
            DataRow[] drItem = ds.AvAdvanceItem.Select(string.Format("AdvanceID={0}", rowAdvance.AdvanceID));
            rowAdvance.BeginEdit();
            // Validate Amount.
            if (avAdvanceDoc.AdvanceType == ZoneType.Domestic)
            {
                Dbpb pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(avAdvanceDoc.PBID == null ? 0 : avAdvanceDoc.PBID.Pbid);

                if (!isRepOffice)
                {
                    if (avAdvanceDoc.Amount == 0)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("AmountDomesticIsRequired"));
                    }
                    //เกินวงเงินของ counter cashier
                    if (avAdvanceDoc.PaymentType == PaymentType.CA)
                    {
                        if (pb != null && avAdvanceDoc.Amount > pb.PettyCashLimit && pb.PettyCashLimit != 0)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("AmountDomesticIsOverPettyCashLimit"));
                        }
                    }
                }
                else
                {
                    if (avAdvanceDoc.LocalCurrencyAmount == 0)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("AmountIsRequired"));
                    }

                    if (avAdvanceDoc.PaymentType == PaymentType.CA)
                    {
                        if (avAdvanceDoc.MainCurrencyAmount > pb.PettyCashLimit && pb.PettyCashLimit != 0)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("AmountDomesticIsOverPettyCashLimit"));
                        }
                    }
                }
                //ถ้าเป็นไม่เป้นเงินโอน ต้องใส่ค่า dbpb
                if (drItem.Length > 0)
                {
                    if (!drItem[0]["PaymentType"].ToString().Equals(PaymentType.TR))
                    {
                        if (avAdvanceDoc.PBID == null || avAdvanceDoc.PBID.Pbid == 0)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CounterCashierIsRequired"));
                        }
                    }
                }
                // Validate Service Team
                if (avAdvanceDoc.ServiceTeamID.ServiceTeamID == 0)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ServiceTeamIsRequired"));
                }
            }
            else
            {
                if (avAdvanceDoc.ArrivalDate == null)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ArrivalDateIsRequired"));
                }
                if (avAdvanceDoc.ArrivalDate.Equals(DateTime.MinValue))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ArrivalDateIsMoreThanRequestDateofAdvance"));
                }
                // Validate Counter Cashier
                if (avAdvanceDoc.PBID == null || avAdvanceDoc.PBID.Pbid == 0)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CounterCashierFNIsRequired"));
                }
                if ((workFlow != null && workFlow.CurrentState.Name == WorkFlowStateFlag.WaitVerify) && advanceEditableField.Contains(AdvanceFieldGroup.ExchangeRateForPerDiemCalculation) && avAdvanceDoc.PerDiemExRateUSD < 0)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ExchangeRateforPerDiemCalculationIsRequired"));
                }
            }

            // Validate Request date of advance
            if (avAdvanceDoc.RequestDateOfAdvance.Equals(DateTime.MinValue))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofAdvanceIsRequired"));
            }
            else if ((workFlow != null && workFlow.CurrentState.Name == WorkFlowStateFlag.WaitVerify) && (!string.IsNullOrEmpty(rowAdvance["RequestDateOfAdvanceApproved"].ToString()) && avAdvanceDoc.RequestDateOfAdvance < rowAdvance.RequestDateOfAdvanceApproved))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofAdvanceMustMoreOrEqualThanApproved"));
            }
            else if (!avAdvanceDoc.RequestDateOfAdvance.Equals(DateTime.MinValue) && !avAdvanceDoc.RequestDateOfAdvance.Equals(DateTime.MaxValue))
            {
                if (DbHolidayProfileService.CheckDay(avAdvanceDoc.RequestDateOfAdvance, mode))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("SystemNotAllowRequestDateOfAdvanceOnHoliday"));
                }
            }
            // Validate Request date of advance

            if (avAdvanceDoc.DocumentID.DocumentID == -1 || workFlow.CurrentState.Name.Equals(WorkFlowStateFlag.Draft))
            {
                if (avAdvanceDoc.RequestDateOfAdvance.Date.CompareTo(DateTime.Today) < 0)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofAdvanceMustBeLaterThanToday"));
                }
            }

            // Validate Request date of Remittance
            if (avAdvanceDoc.RequestDateOfRemittance.Equals(DateTime.MinValue))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofRemittanceIsRequired"));
            }
            // Validate Reason
            if (avAdvanceDoc.RequestDateOfRemittance.CompareTo(avAdvanceDoc.DueDateOfRemittance) > 0)
            {
                if (string.IsNullOrEmpty(avAdvanceDoc.Reason))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ReasonIsRequired"));
                }
            }
            // Validate request date of remittance ; check request date between advance date and advance date + x Day
            // use maxValue ในการ check ถ้าส่งมาเป้น max value แปลว่า วันที่เลือกมาอยู่นอกช่วงที่กำหนด
            if (avAdvanceDoc.RequestDateOfRemittance.Equals(DateTime.MaxValue))
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateofRemittanceIsNotIntime"));
            }
            else if (!avAdvanceDoc.RequestDateOfRemittance.Equals(DateTime.MaxValue) && !avAdvanceDoc.RequestDateOfRemittance.Equals(DateTime.MinValue))
            {
                if (DbHolidayProfileService.CheckDay(avAdvanceDoc.RequestDateOfRemittance, mode))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("SystemNotAllowRequestDateOfRemittanceOnHoliday"));
                }
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            rowAdvance.DocumentID = avAdvanceDoc.DocumentID.DocumentID;
            if (avAdvanceDoc.TADocumentID.HasValue)
            {
                rowAdvance.TADocumentID = avAdvanceDoc.TADocumentID.Value;
            }
            else
            {
                rowAdvance.SetTADocumentIDNull();
            }
            if (avAdvanceDoc.PBID != null)
            {
                rowAdvance.PBID = avAdvanceDoc.PBID.Pbid;
            }
            else
            {
                rowAdvance.SetPBIDNull();
            }
            rowAdvance.AdvanceType = avAdvanceDoc.AdvanceType;
            if (avAdvanceDoc.ServiceTeamID != null)
            {
                rowAdvance.ServiceTeamID = avAdvanceDoc.ServiceTeamID.ServiceTeamID;
            }
            else
            {
                rowAdvance.SetServiceTeamIDNull();
            }
            rowAdvance.RequestDateOfAdvance    = avAdvanceDoc.RequestDateOfAdvance;
            rowAdvance.DueDateOfRemittance     = avAdvanceDoc.DueDateOfRemittance;
            rowAdvance.RequestDateOfRemittance = avAdvanceDoc.RequestDateOfRemittance;
            if (avAdvanceDoc.ArrivalDate != null)
            {
                rowAdvance.ArrivalDate = avAdvanceDoc.ArrivalDate.Value;
            }
            else
            {
                rowAdvance.ArrivalDate = DateTime.MinValue;
            }
            rowAdvance.Reason = avAdvanceDoc.Reason;

            if (workFlow == null || workFlow.CurrentState.Name == WorkFlowStateFlag.Draft)
            {
                rowAdvance.PerDiemExRateUSD = 0;
            }
            else
            {
                rowAdvance.PerDiemExRateUSD = Math.Round((decimal)avAdvanceDoc.PerDiemExRateUSD, 5, MidpointRounding.AwayFromZero);
            }
            rowAdvance.Amount           = Math.Round((decimal)avAdvanceDoc.Amount, 2, MidpointRounding.AwayFromZero);
            rowAdvance.RemittanceAmount = Math.Round((decimal)avAdvanceDoc.RemittanceAmount, 2, MidpointRounding.AwayFromZero);
            rowAdvance.ExpenseAmount    = Math.Round((decimal)avAdvanceDoc.ExpenseAmount, 2, MidpointRounding.AwayFromZero);
            rowAdvance.Active           = avAdvanceDoc.Active;
            rowAdvance.CreBy            = UserAccount.UserID;
            rowAdvance.CreDate          = DateTime.Now;
            rowAdvance.UpdBy            = UserAccount.UserID;
            rowAdvance.UpdDate          = DateTime.Now;
            rowAdvance.UpdPgm           = UserAccount.CurrentProgramCode;

            if (avAdvanceDoc.IsRepOffice.HasValue)
            {
                rowAdvance.IsRepOffice = avAdvanceDoc.IsRepOffice.Value;
            }

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

            if (avAdvanceDoc.MainCurrencyAmount.HasValue)
            {
                rowAdvance.MainCurrencyAmount = (decimal)avAdvanceDoc.MainCurrencyAmount.Value;
            }
            else
            {
                rowAdvance.SetMainCurrencyAmountNull();
            }

            if (avAdvanceDoc.ExchangeRateForLocalCurrency.HasValue)
            {
                rowAdvance.ExchangeRateForLocalCurrency = (decimal)avAdvanceDoc.ExchangeRateForLocalCurrency.Value;
            }
            else
            {
                rowAdvance.SetExchangeRateForLocalCurrencyNull();
            }

            if (avAdvanceDoc.ExchangeRateMainToTHBCurrency.HasValue)
            {
                rowAdvance.ExchangeRateMainToTHBCurrency = (decimal)avAdvanceDoc.ExchangeRateMainToTHBCurrency.Value;
            }
            else
            {
                rowAdvance.SetExchangeRateMainToTHBCurrencyNull();
            }


            if (avAdvanceDoc.LocalCurrencyAmount.HasValue)
            {
                rowAdvance.LocalCurrencyAmount = (decimal)avAdvanceDoc.LocalCurrencyAmount.Value;
            }
            else
            {
                rowAdvance.SetLocalCurrencyAmountNull();
            }

            rowAdvance.EndEdit();
        }
        public void UpdateFixedDocumentTransaction(FixedAdvanceDocument fixedAvAdvanceDoc, Guid txid)
        {
            DateTime dateAndTime = DateTime.Now;
            DateTime CurDate     = dateAndTime.Date;

            IList <object> fixedadvanceEditableField = new List <object>();
            string         mode = string.Empty;

            mode = "DM";
            if (fixedAvAdvanceDoc.DocumentID != null)
            {
                fixedadvanceEditableField = GetEditableFields(fixedAvAdvanceDoc.DocumentID.DocumentID);
            }
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            FixedAdvanceDataSet ds = (FixedAdvanceDataSet)TransactionService.GetDS(txid);

            FixedAdvanceDataSet.FixedAdvanceDocumentRow rowFixedAdvance = (FixedAdvanceDataSet.FixedAdvanceDocumentRow)ds.FixedAdvanceDocument.FindByFixedAdvanceID(fixedAvAdvanceDoc.FixedAdvanceID);
            SS.Standard.WorkFlow.DTO.WorkFlow           workFlow        = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(fixedAvAdvanceDoc.DocumentID.DocumentID);
            FixedAdvanceDataSet.DocumentRow             rowDocument     = (FixedAdvanceDataSet.DocumentRow)ds.Document.FindByDocumentID(rowFixedAdvance.DocumentID);
            rowFixedAdvance.BeginEdit();
            // Validate Amount.
            Dbpb pb = ScgDbQueryProvider.DbPBQuery.FindByIdentity(fixedAvAdvanceDoc.PBID == null ? 0 : fixedAvAdvanceDoc.PBID.Pbid);

            #region Validate value

            if (workFlow == null)
            {
                if (fixedAvAdvanceDoc.NetAmount > 0)
                {
                    if (fixedAvAdvanceDoc.PaymentType == "CA")
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Can't receiv payment type cash."));
                    }
                }
                else
                {
                    if (fixedAvAdvanceDoc.PaymentType == "CQ")
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return payment can't receiv payment type cheque."));
                    }
                }

                if (String.IsNullOrEmpty(fixedAvAdvanceDoc.PaymentType))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                }

                if (fixedAvAdvanceDoc.Amount == 0)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("PleaseFillAmount"));
                }

                if (String.IsNullOrEmpty(fixedAvAdvanceDoc.Objective))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ObjectiveIsRequired"));
                }
                if (fixedAvAdvanceDoc.EffectiveFromDate > fixedAvAdvanceDoc.EffectiveToDate)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveFromdateOverEffectiveTodate"));
                }
                if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue)
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired"));
                }
                else
                {
                    if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom"));
                    }
                    if (fixedAvAdvanceDoc.RequestDate < CurDate)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday"));
                    }
                    if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate"));
                    }
                }
                if (fixedAvAdvanceDoc.PaymentType == "CQ" && (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                }
                if (fixedAvAdvanceDoc.PaymentType == "CA" && (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                }
                if (fixedAvAdvanceDoc.FixedAdvanceType == 1)
                {
                    if (fixedAvAdvanceDoc.EffectiveFromDate < CurDate)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveFromIsLessThanToday"));
                    }
                }
                else
                {
                    if (fixedAvAdvanceDoc.RefFixedAdvanceID == 0)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RefFixedAdvanceIsRequired"));
                    }
                }
            }
            else
            {
                if (workFlow.CurrentState.Name == "Outstanding")
                {
                    if (fixedAvAdvanceDoc.ReturnRequestDate == DateTime.MinValue)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ReturnDateIsRequired"));
                    }
                    else
                    {
                        if (fixedAvAdvanceDoc.ReturnRequestDate < fixedAvAdvanceDoc.EffectiveFromDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOverRequestDate"));
                        }
                        if (fixedAvAdvanceDoc.ReturnRequestDate < CurDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday"));
                        }
                        if (fixedAvAdvanceDoc.ReturnRequestDate > fixedAvAdvanceDoc.EffectiveToDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate"));
                        }
                    }
                    if (String.IsNullOrEmpty(fixedAvAdvanceDoc.ReturnPaymentType))
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                    }
                    else
                    {
                        if (fixedAvAdvanceDoc.ReturnPBID == null || fixedAvAdvanceDoc.ReturnPBID.Pbid == 0)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return Counter Cashier is Required."));
                        }
                    }
                    if (fixedAvAdvanceDoc.ReturnPaymentType == "CQ")
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return payment can't receiv payment type cheque."));
                    }
                }
                else if (workFlow.CurrentState.Name == "WaitReturnComplete")
                {
                    /*N-Addnew*/

                    if (fixedAvAdvanceDoc.ReturnPaymentType == "")
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return Payment Type is Required."));
                    }
                    else
                    {
                        if (fixedAvAdvanceDoc.ReturnPBID == null || fixedAvAdvanceDoc.ReturnPBID.Pbid == 0)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Return Counter Cashier is Required."));
                        }
                    }
                }
                else if (workFlow.CurrentState.Name == "WaitReturn")
                {
                    /*N-Addnew*/
                    if (fixedAvAdvanceDoc.FixedAdvanceType == 1)
                    {
                        /*New*/
                        if (fixedAvAdvanceDoc.PaymentType == "")
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                        }
                        else if (fixedAvAdvanceDoc.PaymentType == "CQ")
                        {
                            if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                            }
                        }
                        /*check change Requestdate*/
                        if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired"));
                        }
                        else
                        {
                            if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom"));
                            }
                            if (fixedAvAdvanceDoc.RequestDate < CurDate)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday"));
                            }
                            if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate"));
                            }
                        }
                    }
                    else
                    {
                        /*Adjust*/
                        if (fixedAvAdvanceDoc.NetAmount < 0)
                        {
                            /*PaybackCompany*/
                            if (fixedAvAdvanceDoc.PaymentType == "")
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                            }
                            else
                            {
                                if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                                }
                            }
                        }
                        else
                        {
                            if (fixedAvAdvanceDoc.PaymentType == "")
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                            }
                            else if (fixedAvAdvanceDoc.PaymentType == "CQ")
                            {
                                if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                                }
                            }
                        }
                    }
                    /*check change Requestdate*/
                    if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired"));
                    }
                    else
                    {
                        if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom"));
                        }
                        if (fixedAvAdvanceDoc.RequestDate < CurDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday"));
                        }
                        if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate"));
                        }
                    }
                }
                else if (workFlow.CurrentState.Name == "WaitVerify")
                {
                    /*N-Addnew*/
                    //check verifyer edit valueCounter Cashier is Required.
                    if (fixedAvAdvanceDoc.FixedAdvanceType == 1)
                    {
                        /*New*/
                        if (fixedAvAdvanceDoc.PaymentType == "")
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                        }
                        else if (fixedAvAdvanceDoc.PaymentType == "CQ")
                        {
                            if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                            }
                        }
                        /*check change Requestdate*/
                        if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired"));
                        }
                        else
                        {
                            if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom"));
                            }
                            //if (fixedAvAdvanceDoc.RequestDate < CurDate)
                            //{
                            //    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday"));
                            //}
                            if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate"));
                            }
                        }
                    }
                    else
                    {
                        /*Adjust*/
                        if (fixedAvAdvanceDoc.NetAmount < 0)
                        {
                            /*PaybackCompany*/
                            if (fixedAvAdvanceDoc.PaymentType == "")
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                            }
                            else
                            {
                                if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                                }
                            }
                        }
                        else
                        {
                            if (fixedAvAdvanceDoc.PaymentType == "")
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                            }
                            else if (fixedAvAdvanceDoc.PaymentType == "CQ")
                            {
                                if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)
                                {
                                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                                }
                            }
                        }
                        if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired"));
                        }
                        else
                        {
                            if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom"));
                            }
                            //if (fixedAvAdvanceDoc.RequestDate < CurDate)
                            //{
                            //    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday"));
                            //}
                            if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate"));
                            }
                        }
                    }
                }
                else
                {
                    if (fixedAvAdvanceDoc.EffectiveFromDate < CurDate && fixedAvAdvanceDoc.FixedAdvanceType == 1)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveFromIsLessThanToday"));
                    }
                    if (fixedAvAdvanceDoc.EffectiveFromDate > fixedAvAdvanceDoc.EffectiveToDate)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveFromdateOverEffectiveTodate"));
                    }

                    /*check change Requestdate*/
                    if (fixedAvAdvanceDoc.RequestDate == DateTime.MinValue)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsRequired"));
                    }
                    else
                    {
                        if (fixedAvAdvanceDoc.RequestDate < fixedAvAdvanceDoc.EffectiveFromDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateIsLessThanEffectDateFrom"));
                        }
                        if (fixedAvAdvanceDoc.RequestDate < CurDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectDateFromOrRequestDateLessToday"));
                        }
                        if (fixedAvAdvanceDoc.RequestDate > fixedAvAdvanceDoc.EffectiveToDate)
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequestDateOverEffectiveTodate"));
                        }
                    }

                    if (fixedAvAdvanceDoc.RefFixedAdvanceID == 0 && fixedAvAdvanceDoc.FixedAdvanceType == 2)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RefFixedAdvanceIsRequired"));
                    }

                    if (fixedAvAdvanceDoc.NetAmount < 0)
                    {
                        /*PaybackCompany*/
                        if (fixedAvAdvanceDoc.PaymentType == "")
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                        }
                        else
                        {
                            if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                            }
                        }
                    }
                    else
                    {
                        if (fixedAvAdvanceDoc.PaymentType == "")
                        {
                            errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Payment Type is Required."));
                        }
                        else if (fixedAvAdvanceDoc.PaymentType == "CQ")
                        {
                            if (fixedAvAdvanceDoc.PBID == null || fixedAvAdvanceDoc.PBID.Pbid == 0)
                            {
                                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Counter Cashier is Required."));
                            }
                        }
                    }
                }
            }

            var result = fixedAvAdvanceDoc.EffectiveToDate - fixedAvAdvanceDoc.EffectiveFromDate;
            //var a = Convert.ToString(result.Days);

            //DateTime datenow = DateTime.Now;
            //DateTime setyearnow = new DateTime(datenow.Year, 1, 1);
            /*N-edited*/
            DateTime setyearnow  = DateTime.Now;
            DateTime setaddmonth = setyearnow.AddMonths(int.Parse(ParameterServices.FixedAdvanceConfigEffectiveDate));
            var      result2     = setaddmonth - setyearnow;
            int      paramdate   = result2.Days;

            if (Convert.ToInt32(result.Days) > paramdate)
            {
                errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("EffectiveDateToIsOverMaximumRange"));
            }


            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
            #endregion

            rowFixedAdvance.DocumentID = fixedAvAdvanceDoc.DocumentID.DocumentID;

            if (fixedAvAdvanceDoc.PBID != null)
            {
                rowFixedAdvance.PBID = fixedAvAdvanceDoc.PBID.Pbid;
            }
            else
            {
                rowFixedAdvance.SetPBIDNull();
            }

            if (fixedAvAdvanceDoc.ReturnPBID != null)
            {
                rowFixedAdvance.ReturnPBID = fixedAvAdvanceDoc.ReturnPBID.Pbid;
            }
            else
            {
                rowFixedAdvance.SetReturnPBIDNull();
            }

            if (fixedAvAdvanceDoc.ServiceTeamID != null)
            {
                rowFixedAdvance.ServiceTeamID = fixedAvAdvanceDoc.ServiceTeamID.ServiceTeamID;
            }
            else
            {
                rowFixedAdvance.SetServiceTeamIDNull();
            }

            if (fixedAvAdvanceDoc.ReturnServiceTeamID != null)
            {
                rowFixedAdvance.ReturnServiceTeamID = fixedAvAdvanceDoc.ReturnServiceTeamID.ServiceTeamID;
            }
            else
            {
                rowFixedAdvance.SetReturnServiceTeamIDNull();
            }

            if (fixedAvAdvanceDoc.RefFixedAdvanceID != null)
            {
                rowFixedAdvance.RefFixedAdvanceID = (long)fixedAvAdvanceDoc.RefFixedAdvanceID;
            }
            else
            {
                rowFixedAdvance.SetRefFixedAdvanceIDNull();
            }

            rowFixedAdvance.FixedAdvanceType        = fixedAvAdvanceDoc.FixedAdvanceType;
            rowFixedAdvance.PaymentType             = fixedAvAdvanceDoc.PaymentType;
            rowFixedAdvance.ReturnPaymentType       = fixedAvAdvanceDoc.ReturnPaymentType;
            rowFixedAdvance.FixedAdvanceBankAccount = fixedAvAdvanceDoc.FixedAdvanceBankAccount;

            rowFixedAdvance.RequestDate = fixedAvAdvanceDoc.RequestDate;
            if (fixedAvAdvanceDoc.ReturnRequestDate != null)
            {
                rowFixedAdvance.ReturnRequestDate = (DateTime)fixedAvAdvanceDoc.ReturnRequestDate;
            }
            else
            {
                rowFixedAdvance.SetReturnRequestDateNull();
            }

            if (fixedAvAdvanceDoc.BaseLineDateReturn != null)
            {
                rowFixedAdvance.BaseLineDateReturn = (DateTime)fixedAvAdvanceDoc.BaseLineDateReturn;
            }
            else
            {
                rowFixedAdvance.SetBaseLineDateReturnNull();
            }

            if (fixedAvAdvanceDoc.PaymentMethodIDReturn != null)
            {
                rowFixedAdvance.PaymentMethodIDReturn = (long)fixedAvAdvanceDoc.PaymentMethodIDReturn;
            }
            else
            {
                rowFixedAdvance.SetPaymentMethodIDReturnNull();
            }

            if (fixedAvAdvanceDoc.PostingDateReturn != null)
            {
                rowFixedAdvance.PostingDateReturn = (DateTime)fixedAvAdvanceDoc.PostingDateReturn;
            }

            rowFixedAdvance.BranchCodeReturn = fixedAvAdvanceDoc.BranchCodeReturn;

            rowFixedAdvance.EffectiveFromDate = fixedAvAdvanceDoc.EffectiveFromDate;
            rowFixedAdvance.EffectiveToDate   = fixedAvAdvanceDoc.EffectiveToDate;
            rowFixedAdvance.Objective         = fixedAvAdvanceDoc.Objective;
            rowFixedAdvance.Amount            = Math.Round((decimal)fixedAvAdvanceDoc.Amount, 2, MidpointRounding.AwayFromZero);
            rowFixedAdvance.NetAmount         = Math.Round((decimal)fixedAvAdvanceDoc.NetAmount, 2, MidpointRounding.AwayFromZero);
            rowFixedAdvance.Active            = fixedAvAdvanceDoc.Active;
            rowFixedAdvance.CreBy             = UserAccount.UserID;
            rowFixedAdvance.CreDate           = DateTime.Now;
            rowFixedAdvance.UpdBy             = UserAccount.UserID;
            rowFixedAdvance.UpdDate           = DateTime.Now;
            rowFixedAdvance.UpdPgm            = UserAccount.CurrentProgramCode;
            rowFixedAdvance.EndEdit();
        }