Ejemplo n.º 1
0
        public long CheckExistAndAddNew(SS.Standard.WorkFlow.DTO.WorkFlow domain)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            if (domain.Document == null)
            {
                errors.AddError("WorkFlow.Error", new Spring.Validation.ErrorMessage("DocumentRequired"));
            }
            if (domain.WorkFlowType == null)
            {
                errors.AddError("WorkFlow.Error", new Spring.Validation.ErrorMessage("WorkFlowTypeRequired"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            WorkFlow.DTO.WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(domain.Document.DocumentID);
            if (workFlow == null)
            {
                domain.Active  = true;
                domain.CreBy   = UserAccount.UserID;
                domain.CreDate = DateTime.Now;
                domain.UpdBy   = UserAccount.UserID;
                domain.UpdDate = DateTime.Now;
                domain.UpdPgm  = UserAccount.CurrentProgramCode;
                long workFlowID = WorkFlowDaoProvider.WorkFlowDao.Save(domain);

                return(workFlowID);
            }
            else
            {
                return(workFlow.WorkFlowID);
            }
        }
Ejemplo n.º 2
0
        private bool CanApprove(long DocID, string DocKind)
        {
            SS.Standard.WorkFlow.DTO.WorkFlow workflow = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(DocID);
            bool boolReturn = false;

            if (workflow == null)
            {
                //this.Alert("Don't Found WorkflowID of this DocumentID !!!");
            }
            else if (DocKind == DocumentKind.Advance.ToString())
            {
                AvAdvanceDocument avDoc = ScgeAccountingQueryProvider.AvAdvanceDocumentQuery.GetAvAdvanceByDocumentID(DocID);
                if (workflow.CurrentState.Name.ToString() != SCG.eAccounting.SAP.BAPI.Service.Const.WorkFlowStatEventNameConst.WaitApproveVerify)
                {
                    boolReturn = false;
                }
                else if (avDoc.AdvanceType == "DM")
                {
                    boolReturn = AdvanceWorkFlowService.CanApproveWaitApproveVerify(workflow.WorkFlowID);
                }
                else
                {
                    boolReturn = AdvanceForeignWorkFlowService.CanApproveWaitApproveVerify(workflow.WorkFlowID);
                }
            }
            else if (DocKind == DocumentKind.Remittance.ToString())
            {
                if (workflow.CurrentState.Name.ToString() != SCG.eAccounting.SAP.BAPI.Service.Const.WorkFlowStatEventNameConst.WaitApproveRemittance)
                {
                    boolReturn = false;
                }
                else
                {
                    boolReturn = RemittanceWorkFlowService.CanApproveWaitApproveRemittance(workflow.WorkFlowID);
                }
            }
            else if (DocKind == DocumentKind.Expense.ToString())
            {
                if (workflow.CurrentState.Name.ToString() != SCG.eAccounting.SAP.BAPI.Service.Const.WorkFlowStatEventNameConst.WaitApproveVerify)
                {
                    boolReturn = false;
                }
                else
                {
                    boolReturn = ExpenseWorkFlowService.CanApproveWaitApproveVerify(workflow.WorkFlowID);
                }
            }
            else if (DocKind == DocumentKind.ExpenseRemittance.ToString())
            {
                if (workflow.CurrentState.Name.ToString() != SCG.eAccounting.SAP.BAPI.Service.Const.WorkFlowStatEventNameConst.WaitRemittance)
                {
                    boolReturn = false;
                }
                else
                {
                    boolReturn = ExpenseWorkFlowService.CanPayWaitRemittance(workflow.WorkFlowID);
                }
            }
            return(boolReturn);
        }
        public void Initialize(long wfId)
        {
            SS.Standard.WorkFlow.DTO.WorkFlow workFlow = SS.Standard.WorkFlow.Query.WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(wfId);
            switch (workFlow.CurrentState.Name)
            {
            case "Draft":
            case "WaitAR":
                workflowState.Cells[0].BgColor = Color.LightYellow.Name;
                break;

            case "WaitPayment":
            case "WaitPaymentFromSAP":
            case "WaitRemittance":
            case "WaitApproveRemittance":
                workflowState.Cells[1].BgColor = Color.LightYellow.Name;
                workflowState.Cells[0].BgColor = Color.LightGreen.Name;
                break;

            case "Complete":
            case "Outstanding":
                workflowState.Cells[2].BgColor = Color.LightGreen.Name;
                workflowState.Cells[1].BgColor = Color.LightGreen.Name;
                workflowState.Cells[0].BgColor = Color.LightGreen.Name;
                break;
            }
        }
Ejemplo n.º 4
0
        public IList <object> GetVisibleFields(long?documentID)
        {
            IList <object> visibleFields = new List <object>();

            if (!documentID.HasValue) // Check whether new flag then return the default editableFields.
            {
                visibleFields.Add(AdvanceFieldGroup.Subject);
                visibleFields.Add(AdvanceFieldGroup.PaymentType);
                visibleFields.Add(AdvanceFieldGroup.RequestDateOfAdvance);
                visibleFields.Add(AdvanceFieldGroup.RequestDateOfRemittance);
                visibleFields.Add(AdvanceFieldGroup.Reason);
                visibleFields.Add(AdvanceFieldGroup.Initiator);
                visibleFields.Add(AdvanceFieldGroup.Attachment);
                visibleFields.Add(AdvanceFieldGroup.Memo);
                //visibleFields.Add(AdvanceFieldGroup.ExchangeRateForPerDiemCalculation);
                visibleFields.Add(AdvanceFieldGroup.Other);
                visibleFields.Add(AdvanceFieldGroup.AdvanceReferTA);
                visibleFields.Add(AdvanceFieldGroup.Company);
                visibleFields.Add(AdvanceFieldGroup.ServiceTeam);
                visibleFields.Add(AdvanceFieldGroup.BuActor);
                visibleFields.Add(AdvanceFieldGroup.CounterCashier);
                visibleFields.Add(AdvanceFieldGroup.DomesticAmountTHB);
                visibleFields.Add(AdvanceFieldGroup.ArrivalDate);
                visibleFields.Add(AdvanceFieldGroup.CurrencyAmount);
                visibleFields.Add(AdvanceFieldGroup.PaymentTypeFR);
                visibleFields.Add(AdvanceFieldGroup.CurrencyRepOffice);
            }
            else // Check whether view or edit flag then return editableFields from workflow state.
            {
                SS.Standard.WorkFlow.DTO.WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(documentID.Value);
                visibleFields = WorkFlowService.GetVisibleFields(workFlow.WorkFlowID);
            }

            return(visibleFields);
        }
        public IList <object> GetEditableFields(long?documentID)
        {
            IList <object> editableFields = new List <object>();

            if (documentID.HasValue) // Check whether new flag then return the default editableFields.
            {
                SS.Standard.WorkFlow.DTO.WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(documentID.Value);
                if (workFlow != null)
                {
                    return(WorkFlowService.GetEditableFields(workFlow.WorkFlowID));
                }
            }
            editableFields.Add(FixedAdvanceFieldGroup.PaymentType);
            editableFields.Add(FixedAdvanceFieldGroup.Initiator);
            editableFields.Add(FixedAdvanceFieldGroup.Attachment);
            editableFields.Add(FixedAdvanceFieldGroup.Memo);
            editableFields.Add(FixedAdvanceFieldGroup.Other);
            editableFields.Add(FixedAdvanceFieldGroup.RequestDate);
            editableFields.Add(FixedAdvanceFieldGroup.ServiceTeam);
            editableFields.Add(FixedAdvanceFieldGroup.BuActor);
            editableFields.Add(FixedAdvanceFieldGroup.CounterCashier);
            editableFields.Add(FixedAdvanceFieldGroup.Subject);
            editableFields.Add(FixedAdvanceFieldGroup.Company);
            return(editableFields);
        }
        public IList <object> GetVisibleFields(long?documentID)
        {
            IList <object> visibleFields = new List <object>();

            if (!documentID.HasValue) // Check whether new flag then return the default editableFields.
            {
                visibleFields.Add(FixedAdvanceFieldGroup.PaymentType);
                visibleFields.Add(FixedAdvanceFieldGroup.Initiator);
                visibleFields.Add(FixedAdvanceFieldGroup.Attachment);
                visibleFields.Add(FixedAdvanceFieldGroup.Memo);
                visibleFields.Add(FixedAdvanceFieldGroup.Other);
                visibleFields.Add(FixedAdvanceFieldGroup.RequestDate);
                visibleFields.Add(FixedAdvanceFieldGroup.Company);
                visibleFields.Add(FixedAdvanceFieldGroup.ServiceTeam);
                visibleFields.Add(FixedAdvanceFieldGroup.BuActor);
                visibleFields.Add(FixedAdvanceFieldGroup.CounterCashier);
                visibleFields.Add(FixedAdvanceFieldGroup.Subject);
            }
            else // Check whether view or edit flag then return editableFields from workflow state.
            {
                SS.Standard.WorkFlow.DTO.WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(documentID.Value);
                visibleFields = WorkFlowService.GetVisibleFields(workFlow.WorkFlowID);
            }

            return(visibleFields);
        }
Ejemplo n.º 7
0
        public void Initialize(long workFlowID)
        {
            Document document = WorkFlowQueryProvider.WorkFlowQuery.GetDocumentByWorkFlowID(workFlowID);

            SS.Standard.WorkFlow.DTO.WorkFlow wf = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(workFlowID);
            if (document != null && document.DocumentType != null) //Advance DocumentType when 1 is Domestic when 5 is Foreign
            {
                this.DocumentTypeID  = document.DocumentType.DocumentTypeID;
                this.WorkflowStateID = wf.CurrentState.WorkFlowStateID;
                this.BindReasonDropdown();
            }
        }
 public void ValidateRemittanceRecievedMethod(long wfid)
 {
     Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
     SS.Standard.WorkFlow.DTO.WorkFlow  wf     = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(wfid);
     if (wf != null && wf.CurrentState != null && wf.CurrentState.Name != null)
     {
         if (wf.CurrentState.Name.Equals(WorkFlowStateFlag.WaitRemittance))
         {
             FnExpenseDocument expDoc = ScgeAccountingQueryProvider.FnExpenseDocumentQuery.GetExpenseDocumentByDocumentID(wf.Document.DocumentID);
             if (string.IsNullOrEmpty(expDoc.ReceivedMethod))
             {
                 errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("ReceiveIsRequired"));
             }
         }
     }
     if (!errors.IsEmpty)
     {
         throw new ServiceValidationException(errors);
     }
 }
Ejemplo n.º 9
0
        public IList <object> GetEditableFields(long?documentID)
        {
            IList <object> editableFields = new List <object>();

            if (!documentID.HasValue) // Check whether new flag then return the default editableFields.
            {
                editableFields.Add(TAFieldGroup.All);
                editableFields.Add(TAFieldGroup.Company);
                editableFields.Add(TAFieldGroup.Initiator);
            }
            else // Check whether view or edit flag then return editableFields from workflow state.
            {
                SS.Standard.WorkFlow.DTO.WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(documentID.Value);
                editableFields = WorkFlowService.GetEditableFields(workFlow.WorkFlowID);

                //Because TA does not has special visible or editable field
                //Then return all
                //editableFields.Add(TAFieldGroup.All);
            }

            return(editableFields);
        }
        public void MultipleApproveVerify()
        {
            IList <long>               workflowList            = GetWorkflowIDForMultipleApprove();
            ApproveVerifyStatus        approveVerifyStatus     = null;
            List <ApproveVerifyStatus> approveVerifyStatusList = new List <ApproveVerifyStatus>();

            foreach (long workflowId in workflowList)
            {
                try
                {
                    SS.Standard.WorkFlow.DTO.WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(workflowId);
                    SCGDocument document = ScgeAccountingQueryProvider.SCGDocumentQuery.GetSCGDocumentByDocumentID(workFlow.Document.DocumentID);
                    approveVerifyStatus            = new ApproveVerifyStatus();
                    approveVerifyStatus.DocumentNo = document.DocumentNo;
                    approveVerifyStatus.Subject    = document.Subject;

                    int workFlowStateEventID = ScgeAccountingQueryProvider.SCGDocumentQuery.GetWorkStateEvent(workFlow.CurrentState.WorkFlowStateID, WorkFlowEventNameConst.Approve);
                    if (workFlow.WorkFlowType.WorkFlowTypeID == WorkFlowTypeID.AdvanceWorkFlowType)
                    {
                        AvAdvanceDocument advDocument = ScgeAccountingQueryProvider.AvAdvanceDocumentQuery.GetAvAdvanceByDocumentID(workFlow.Document.DocumentID);
                        approveVerifyStatus.Amount = advDocument.Amount;
                        IList <WorkFlowStateEvent> workFlowState = WorkFlowQueryProvider.WorkFlowStateEventQuery.FindWorkFlowStateEvent(WorkFlowEventNameConst.Approve, WorkFlowStatEventNameConst.WaitApproveVerify, WorkFlowTypeName.Advance);
                        object eventData = new SubmitResponse(workFlowState[0].WorkFlowStateEventID);
                        WorkFlowService.NotifyEvent(workflowId, WorkFlowEventNameConst.Approve, eventData);
                    }
                    else if (workFlow.WorkFlowType.WorkFlowTypeID == WorkFlowTypeID.ExpenseWorkFlow)
                    {
                        FnExpenseDocument expDocument = ScgeAccountingQueryProvider.FnExpenseDocumentQuery.GetExpenseDocumentByDocumentID(workFlow.Document.DocumentID);
                        approveVerifyStatus.Amount = expDocument.DifferenceAmount;

                        IList <WorkFlowStateEvent> workFlowState = WorkFlowQueryProvider.WorkFlowStateEventQuery.FindWorkFlowStateEvent(WorkFlowEventNameConst.Approve, WorkFlowStatEventNameConst.WaitApproveVerify, WorkFlowTypeName.Expense);
                        object eventData = new SubmitResponse(workFlowState[0].WorkFlowStateEventID);
                        WorkFlowService.NotifyEvent(workflowId, WorkFlowEventNameConst.Approve, eventData);
                    }
                    else if (workFlow.WorkFlowType.WorkFlowTypeID == WorkFlowTypeID.RemittanceWorkFlow)
                    {
                        FnRemittance rmtDocument = ScgeAccountingQueryProvider.FnRemittanceQuery.GetFnRemittanceByDocumentID(workFlow.Document.DocumentID);
                        approveVerifyStatus.Amount = rmtDocument.TotalAmount;

                        IList <WorkFlowStateEvent> workFlowState = WorkFlowQueryProvider.WorkFlowStateEventQuery.FindWorkFlowStateEvent(WorkFlowEventNameConst.Approve, WorkFlowStatEventNameConst.WaitApproveRemittance, WorkFlowTypeName.Remittance);
                        object eventData = new SubmitResponse(workFlowState[0].WorkFlowStateEventID);
                        WorkFlowService.NotifyEvent(workflowId, WorkFlowEventNameConst.Approve, eventData);
                    }

                    approveVerifyStatus.Status = "Success";
                }
                catch (ServiceValidationException ex)
                {
                    approveVerifyStatus.Status = "Error";
                    approveVerifyStatus.Reason = new List <string>();
                    foreach (Spring.Validation.ErrorMessage errorMsg in ex.ValidationErrors.GetErrors("WorkFlow.Error"))
                    {
                        approveVerifyStatus.Reason.Add(errorMsg.Id);
                    }
                    //ctlApproveStatusSummary.ValidationErrors.MergeErrors(ex.ValidationErrors);
                }
                approveVerifyStatusList.Add(approveVerifyStatus);
            }

            if (approveVerifyStatusList.Count > 0)
            {
                ctlApproveStatusSummary.DataList = approveVerifyStatusList.OrderBy(x => x.Status).ThenBy(x => x.DocumentNo).ToList();
                ctlApproveStatusSummary.BindGridView();
                ctlApproveResultSummaryModalPopupExtender.Show();
            }
        }
Ejemplo n.º 11
0
        protected void ctlTADocumentGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            bool isValid = true;

            if (!isMultiple)
            {
                if (e.CommandName.Equals("Select"))
                {
                    int  rowIndex   = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
                    long documentId = UIHelper.ParseLong(ctlTADocumentGridView.DataKeys[rowIndex].Value.ToString());
                    IList <TADocumentObj> taDocument = ScgeAccountingQueryProvider.SCGDocumentQuery.FindByDocumentIdentity(Convert.ToInt64(documentId));
                    long taDocID = Convert.ToInt64(taDocument[0].TADocumentID);
                    Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
                    IList <Advance> advanceList = ScgeAccountingQueryProvider.AvAdvanceDocumentQuery.FindAdvanceDocumentForRequesterByTADocumentID(UIHelper.ParseLong(ctlRequesterID.Value), taDocID);
                    if (advanceList.Count > 0)
                    {
                        foreach (Advance ad in advanceList)
                        {
                            workflow.WorkFlow wf = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(ad.DocumentID);
                            if (wf != null && wf.CurrentState.Name == "Outstanding")
                            {
                                IList <FnExpenseDocument> expenseList    = ScgeAccountingQueryProvider.FnExpenseDocumentQuery.FindExpenseReferenceTAForRequesterByTADocumentID(UIHelper.ParseLong(ctlRequesterID.Value), taDocID);
                                IList <FnRemittance>      remittanceList = ScgeAccountingQueryProvider.FnRemittanceQuery.FindRemittanceReferenceTAForRequesterByTADocumentID(UIHelper.ParseLong(ctlRequesterID.Value), taDocID);

                                //check expense
                                if (expenseList.Count > 0)
                                {
                                    foreach (FnExpenseDocument exp in expenseList)
                                    {
                                        workflow.WorkFlow expenseWF = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(exp.Document.DocumentID);

                                        if (!(expenseWF.CurrentState.Name == "Cancel" || expenseWF.CurrentState.Name == "Complete"))
                                        {
                                            isValid = false;
                                            break;
                                        }
                                    }
                                }

                                //check remittance
                                if (isValid && remittanceList.Count > 0)
                                {
                                    foreach (FnRemittance rmt in remittanceList)
                                    {
                                        workflow.WorkFlow remittanceWF = WorkFlowQueryProvider.WorkFlowQuery.GetWorkFlowByDocumentID(rmt.Document.DocumentID);
                                        if (!(remittanceWF.CurrentState.Name == "Cancel" || remittanceWF.CurrentState.Name == "Complete"))
                                        {
                                            isValid = false;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (!isValid)
                            {
                                break;
                            }
                        }
                    }


                    if (!isValid)
                    {
                        errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("CannotReferenceTADocument"));
                        this.ValidationErrors.MergeErrors(errors);
                        ctlUpdatePanelValidate.Update();
                    }
                    else
                    {
                        CallOnObjectLookUpReturn(documentId.ToString());
                        Hide();
                    }
                }
            }
        }
Ejemplo n.º 12
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();
        }