/// <summary>
        /// This method will post the selected timesheet entries for accounting
        /// </summary>
        /// <param name="displayWarnings">if set to <c>true</c> display warnings.</param>
        private void PostTime(bool displayWarnings)
        {
            TimeServiceClient timeService = null;
            EarnerServiceClient earnerService = null;
            try
            {
                UnPostedTimeSearchCriteria searchCriteria = new UnPostedTimeSearchCriteria();
                searchCriteria.UserId = _logonSettings.DbUid;
                searchCriteria.TimeDate = DateTime.Now.Date;

                earnerService = new EarnerServiceClient();
                EarnerReturnValue earnerReturnVal = earnerService.GetFeeEarnerReference(_logonSettings.LogonId,
                                                                                        _logonSettings.MemberId);
                if (earnerReturnVal.Success)
                {
                    searchCriteria.FeeEarnerRef = earnerReturnVal.EarnerRef;
                }
                else
                {
                    throw new Exception(earnerReturnVal.Message);
                }

                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.StartRow = _grdTodaysTimesheet.PageIndex * _grdTodaysTimesheet.PageSize;
                collectionRequest.RowCount = _grdTodaysTimesheet.PageSize;

                //Get unposted time entries
                timeService = new TimeServiceClient();
                UnPostedTimeSearchReturnValue returnValue = timeService.UnPostedTimeSheetSearch(_logonSettings.LogonId,
                                                                                            collectionRequest,
                                                                                            searchCriteria);

                if (returnValue.UnPostedTimeSheet.Rows != null && returnValue.UnPostedTimeSheet.Rows.Length > 0)
                {
                    foreach (GridViewRow row in _grdTodaysTimesheet.Rows)
                    {
                        CheckBox timeSheetSelected = (CheckBox)row.FindControl("_chkSelect");
                        int timeId = (int)_grdTodaysTimesheet.DataKeys[row.RowIndex].Values["TimeId"];

                        //Find the item in the collection
                        UnPostedTimeSearchItem timeSheetItem = returnValue.UnPostedTimeSheet.Rows.First(time => time.TimeId == timeId);

                        //Check if the item is selected
                        if (timeSheetSelected.Checked)
                        {

                            //Validate the posting period
                            PeriodCriteria criteria = new PeriodCriteria();
                            criteria.Date = timeSheetItem.TimeDate;//returnValue.UnPostedTimeSheet.Rows[0].TimeDate;
                            criteria.IsTime = true;
                            criteria.IsPostingVATable = false;
                            criteria.IsAllowedPostBack2ClosedYear = false;

                            PeriodDetailsReturnValue periodDetailsReturnValue = new PeriodDetailsReturnValue();
                            periodDetailsReturnValue = timeService.ValidatePeriod(_logonSettings.LogonId, criteria);

                            if (periodDetailsReturnValue.Success)
                            {
                                //Display warning mesg(if any)
                                if (periodDetailsReturnValue.PeriodStatus == 3 && displayWarnings)
                                {
                                    _mdlPopUpCofirmationBox.Show();
                                    return;
                                }

                                if (periodDetailsReturnValue.PeriodStatus == 2)
                                {
                                    throw new Exception(periodDetailsReturnValue.ErrorMessage);
                                }

                                if (timeSheetItem != null)
                                {
                                    bool canBePosted = true;

                                    if (timeSheetItem.BillingTypeActive &&
                                        timeSheetItem.BillingTypeArchived == false &&
                                        timeSheetItem.TimeLAAsked == false)
                                    {
                                        canBePosted = false;
                                    }

                                    if (canBePosted)
                                    {
                                        TimeSheet timeSheet = new TimeSheet();
                                        timeSheet.TimeId = timeSheetItem.TimeId;
                                        timeSheet.PeriodId = periodDetailsReturnValue.PeriodId;
                                        timeSheet.MemberId = timeSheetItem.MemberId.ToString();
                                        timeSheet.CurrencyId = timeSheetItem.CurrencyId;
                                        timeSheet.PeriodMinutes = timeSheetItem.TimeElapsed;
                                        timeSheet.MasterPostedCost = timeSheetItem.TimeCost;
                                        timeSheet.MasterPostedCharge = timeSheetItem.TimeCharge;
                                        timeSheet.WorkingPostedCost = timeSheetItem.TimeCost;
                                        timeSheet.WorkingPostedCharge = timeSheetItem.TimeCharge;
                                        timeSheet.OrganisationId = timeSheetItem.OrganisationId;
                                        timeSheet.DepartmentId = timeSheetItem.DepartmentId;
                                        timeSheet.ProjectId = timeSheetItem.ProjectId;
                                        timeSheet.TimeTypeId = timeSheetItem.TimeTypeId;
                                        timeSheet.TimeDate = timeSheetItem.TimeDate;

                                        ReturnValue returnVal = timeService.PostTime(_logonSettings.LogonId, timeSheet);
                                        if (!returnVal.Success)
                                        {
                                            throw new Exception(returnVal.Message);
                                        }
                                    }
                                }

                            }
                            else
                            {
                                throw new Exception(periodDetailsReturnValue.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (timeService != null)
                {
                    if (timeService.State != System.ServiceModel.CommunicationState.Faulted)
                        timeService.Close();
                }
                if (earnerService != null)
                {
                    if (earnerService.State != System.ServiceModel.CommunicationState.Faulted)
                        earnerService.Close();
                }
            }
        }
        /// <summary>
        /// Validates the period.
        /// </summary>
        /// <param name="oHostSecurityToken">User token</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public PeriodDetailsReturnValue ValidatePeriod(HostSecurityToken oHostSecurityToken, PeriodCriteria criteria)
        {
            PeriodDetailsReturnValue returnValue = null;

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oTimeService = new TimeService();
                returnValue  = oTimeService.ValidatePeriod(Functions.GetLogonIdFromToken(oHostSecurityToken), criteria);
            }
            else
            {
                returnValue         = new PeriodDetailsReturnValue();
                returnValue.Success = false;
                returnValue.Message = "Invalid Token";
            }
            return(returnValue);
        }
        /// <summary>
        /// Validates posting period on page load and gets client banks
        /// </summary>
        /// <param name="bankType"></param>
        /// Previous - private PeriodDetailsReturnValue ValidatePostingPeriod(Guid projectId, IRIS.Law.PmsCommonData.DataConstantsBankSearchTypes bankType)
        private PeriodDetailsReturnValue ValidatePostingPeriod(Guid projectId)
        {
            TimeServiceClient        timeService = null;
            PeriodDetailsReturnValue returnValue = null;

            try
            {
                PeriodCriteria criteria = new PeriodCriteria();
                criteria.Date             = Convert.ToDateTime(_ccPostDate.DateText);
                criteria.IsPostingVATable = false;
                criteria.IsTime           = false;
                criteria.ProjectId        = projectId;
                // This parameter has been passed as "false" in accounts
                criteria.IsAllowedPostBack2ClosedYear = false;

                timeService = new TimeServiceClient();
                returnValue = timeService.ValidatePeriod(_logonSettings.LogonId, criteria);
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                _lblMessage.Text     = DataConstants.WSEndPointErrorMessage;
                _lblMessage.CssClass = "errorMessage";
            }
            catch (Exception ex)
            {
                _lblMessage.CssClass = "errorMessage";
                _lblMessage.Text     = ex.Message;
            }
            finally
            {
                if (timeService != null)
                {
                    if (timeService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        timeService.Close();
                    }
                }
            }

            return(returnValue);
        }
        /// <summary>
        /// Validates the posting period
        /// </summary>
        private bool SetPostingPeriod()
        {
            try
            {
                PeriodDetailsReturnValue returnValue = ValidatePostingPeriod(DataConstants.DummyGuid);//, IRIS.Law.PmsCommonData.DataConstantsBankSearchTypes.Client);

                if (returnValue.Success)
                {
                    // for warning message modal popup with "OK" button will be shown.
                    if (!string.IsNullOrEmpty(returnValue.WarningMessage))
                    {
                        _lblMessage.CssClass = "successMessage";
                        _lblMessage.Text     = returnValue.WarningMessage;
                    }

                    // Sets valid posting period else "Invalid"
                    _lblPostingPeriod.Text = returnValue.PostingPeriodNumber;
                }
                else
                {
                    // Sets posting error message only if posting period is invalid
                    _lblMessage.CssClass = "errorMessage";
                    _lblMessage.Text     = returnValue.ErrorMessage;
                }

                return(returnValue.Success);
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                _lblMessage.Text     = DataConstants.WSEndPointErrorMessage;
                _lblMessage.CssClass = "errorMessage";
                return(false);
            }
            catch (Exception ex)
            {
                _lblMessage.CssClass = "errorMessage";
                _lblMessage.Text     = ex.Message;
                return(false);
            }
        }
 /// <summary>
 /// Validates the period.
 /// </summary>
 /// <param name="oHostSecurityToken">User token</param>
 /// <param name="criteria">The criteria.</param>
 /// <returns></returns>
 public PeriodDetailsReturnValue ValidatePeriod(HostSecurityToken oHostSecurityToken, PeriodCriteria criteria)
 {
     PeriodDetailsReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oTimeService = new TimeService();
         returnValue = oTimeService.ValidatePeriod(Functions.GetLogonIdFromToken(oHostSecurityToken), criteria);
     }
     else
     {
         returnValue = new PeriodDetailsReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
Esempio n. 6
0
        /// <summary>
        /// This method will post the selected timesheet entries for accounting
        /// </summary>
        /// <param name="displayWarnings">if set to <c>true</c> display warnings.</param>
        private void PostTime(bool displayWarnings)
        {
            TimeServiceClient   timeService   = null;
            EarnerServiceClient earnerService = null;

            try
            {
                UnPostedTimeSearchCriteria searchCriteria = new UnPostedTimeSearchCriteria();
                searchCriteria.UserId   = _logonSettings.DbUid;
                searchCriteria.TimeDate = DateTime.Now.Date;

                earnerService = new EarnerServiceClient();
                EarnerReturnValue earnerReturnVal = earnerService.GetFeeEarnerReference(_logonSettings.LogonId,
                                                                                        _logonSettings.MemberId);
                if (earnerReturnVal.Success)
                {
                    searchCriteria.FeeEarnerRef = earnerReturnVal.EarnerRef;
                }
                else
                {
                    throw new Exception(earnerReturnVal.Message);
                }


                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.StartRow = _grdTodaysTimesheet.PageIndex * _grdTodaysTimesheet.PageSize;
                collectionRequest.RowCount = _grdTodaysTimesheet.PageSize;

                //Get unposted time entries
                timeService = new TimeServiceClient();
                UnPostedTimeSearchReturnValue returnValue = timeService.UnPostedTimeSheetSearch(_logonSettings.LogonId,
                                                                                                collectionRequest,
                                                                                                searchCriteria);

                if (returnValue.UnPostedTimeSheet.Rows != null && returnValue.UnPostedTimeSheet.Rows.Length > 0)
                {
                    foreach (GridViewRow row in _grdTodaysTimesheet.Rows)
                    {
                        CheckBox timeSheetSelected = (CheckBox)row.FindControl("_chkSelect");
                        int      timeId            = (int)_grdTodaysTimesheet.DataKeys[row.RowIndex].Values["TimeId"];

                        //Find the item in the collection
                        UnPostedTimeSearchItem timeSheetItem = returnValue.UnPostedTimeSheet.Rows.First(time => time.TimeId == timeId);


                        //Check if the item is selected
                        if (timeSheetSelected.Checked)
                        {
                            //Validate the posting period
                            PeriodCriteria criteria = new PeriodCriteria();
                            criteria.Date                         = timeSheetItem.TimeDate;//returnValue.UnPostedTimeSheet.Rows[0].TimeDate;
                            criteria.IsTime                       = true;
                            criteria.IsPostingVATable             = false;
                            criteria.IsAllowedPostBack2ClosedYear = false;

                            PeriodDetailsReturnValue periodDetailsReturnValue = new PeriodDetailsReturnValue();
                            periodDetailsReturnValue = timeService.ValidatePeriod(_logonSettings.LogonId, criteria);

                            if (periodDetailsReturnValue.Success)
                            {
                                //Display warning mesg(if any)
                                if (periodDetailsReturnValue.PeriodStatus == 3 && displayWarnings)
                                {
                                    _mdlPopUpCofirmationBox.Show();
                                    return;
                                }

                                if (periodDetailsReturnValue.PeriodStatus == 2)
                                {
                                    throw new Exception(periodDetailsReturnValue.ErrorMessage);
                                }

                                if (timeSheetItem != null)
                                {
                                    bool canBePosted = true;

                                    if (timeSheetItem.BillingTypeActive &&
                                        timeSheetItem.BillingTypeArchived == false &&
                                        timeSheetItem.TimeLAAsked == false)
                                    {
                                        canBePosted = false;
                                    }

                                    if (canBePosted)
                                    {
                                        TimeSheet timeSheet = new TimeSheet();
                                        timeSheet.TimeId              = timeSheetItem.TimeId;
                                        timeSheet.PeriodId            = periodDetailsReturnValue.PeriodId;
                                        timeSheet.MemberId            = timeSheetItem.MemberId.ToString();
                                        timeSheet.CurrencyId          = timeSheetItem.CurrencyId;
                                        timeSheet.PeriodMinutes       = timeSheetItem.TimeElapsed;
                                        timeSheet.MasterPostedCost    = timeSheetItem.TimeCost;
                                        timeSheet.MasterPostedCharge  = timeSheetItem.TimeCharge;
                                        timeSheet.WorkingPostedCost   = timeSheetItem.TimeCost;
                                        timeSheet.WorkingPostedCharge = timeSheetItem.TimeCharge;
                                        timeSheet.OrganisationId      = timeSheetItem.OrganisationId;
                                        timeSheet.DepartmentId        = timeSheetItem.DepartmentId;
                                        timeSheet.ProjectId           = timeSheetItem.ProjectId;
                                        timeSheet.TimeTypeId          = timeSheetItem.TimeTypeId;
                                        timeSheet.TimeDate            = timeSheetItem.TimeDate;

                                        ReturnValue returnVal = timeService.PostTime(_logonSettings.LogonId, timeSheet);
                                        if (!returnVal.Success)
                                        {
                                            throw new Exception(returnVal.Message);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                throw new Exception(periodDetailsReturnValue.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (timeService != null)
                {
                    if (timeService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        timeService.Close();
                    }
                }
                if (earnerService != null)
                {
                    if (earnerService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        earnerService.Close();
                    }
                }
            }
        }