/// <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>
        /// Get all the unposted time sheet for the current date for the logged in fee earner
        /// </summary>
        /// <param name="oHostSecurityToken"></param>
        /// <param name="collectionRequest"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public UnPostedTimeSearchReturnValue UnPostedTimeSheetSearch(HostSecurityToken oHostSecurityToken,
                                                                     CollectionRequest collectionRequest, UnPostedTimeSearchCriteria criteria)
        {
            UnPostedTimeSearchReturnValue returnValue = null;

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oTimeService = new TimeService();
                returnValue  = oTimeService.UnPostedTimeSheetSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
            }
            else
            {
                returnValue         = new UnPostedTimeSearchReturnValue();
                returnValue.Success = false;
                returnValue.Message = "Invalid Token";
            }
            return(returnValue);
        }
 /// <summary>
 /// Get all the unposted time sheet for the current date for the logged in fee earner
 /// </summary>
 /// <param name="oHostSecurityToken"></param>
 /// <param name="collectionRequest"></param>
 /// <param name="criteria"></param>
 /// <returns></returns>
 public UnPostedTimeSearchReturnValue UnPostedTimeSheetSearch(HostSecurityToken oHostSecurityToken,
                                                     CollectionRequest collectionRequest, UnPostedTimeSearchCriteria criteria)
 {
     UnPostedTimeSearchReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oTimeService = new TimeService();
         returnValue = oTimeService.UnPostedTimeSheetSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
     }
     else
     {
         returnValue = new UnPostedTimeSearchReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
Ejemplo n.º 4
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();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The list of time entries for today
        /// </summary>
        public UnPostedTimeSearchItem[] BindTodaysTimesheet(int startRow, int pageSize, string sortBy, bool forceRefresh)
        {
            UnPostedTimeSearchItem[] timesheet = null;

            TimeServiceClient   timeService   = null;
            EarnerServiceClient earnerService = null;

            try
            {
                if (HttpContext.Current.Session[SessionName.LogonSettings] != null)
                {
                    LogonReturnValue logonSettings = (LogonReturnValue)Session[SessionName.LogonSettings];

                    earnerService = new EarnerServiceClient();

                    EarnerReturnValue earnerReturnValue = earnerService.GetFeeEarnerReference(logonSettings.LogonId, logonSettings.MemberId);

                    if (earnerReturnValue.Success)
                    {
                        timeService = new TimeServiceClient();
                        CollectionRequest collectionRequest = new CollectionRequest();
                        collectionRequest.ForceRefresh = forceRefresh;
                        collectionRequest.StartRow     = startRow;
                        collectionRequest.RowCount     = pageSize;

                        UnPostedTimeSearchCriteria searchCriteria = new UnPostedTimeSearchCriteria();
                        searchCriteria.FeeEarnerRef = earnerReturnValue.EarnerRef;
                        searchCriteria.UserId       = logonSettings.DbUid;
                        searchCriteria.TimeDate     = DateTime.Now.Date;
                        searchCriteria.OrderBy      = sortBy;

                        UnPostedTimeSearchReturnValue returnValue = timeService.UnPostedTimeSheetSearch(logonSettings.LogonId,
                                                                                                        collectionRequest, searchCriteria);

                        if (returnValue.Success)
                        {
                            _rowCount = returnValue.UnPostedTimeSheet.TotalRowCount;
                            timesheet = returnValue.UnPostedTimeSheet.Rows;
                        }
                        else
                        {
                            throw new Exception(returnValue.Message);
                        }
                    }
                    else
                    {
                        //Error retrieveing earner ref. wont be able to get the time sheet
                        throw new Exception("Error retrieving timesheet");
                    }
                }
                return(timesheet);
            }
            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>
        /// The list of time entries for today
        /// </summary>
        public UnPostedTimeSearchItem[] BindTodaysTimesheet(int startRow, int pageSize, string sortBy, bool forceRefresh)
        {
            UnPostedTimeSearchItem[] timesheet = null;

            TimeServiceClient timeService = null;
            EarnerServiceClient earnerService = null;
            try
            {

                if (HttpContext.Current.Session[SessionName.LogonSettings] != null)
                {
                    LogonReturnValue logonSettings = (LogonReturnValue)Session[SessionName.LogonSettings];

                    earnerService = new EarnerServiceClient();

                    EarnerReturnValue earnerReturnValue = earnerService.GetFeeEarnerReference(logonSettings.LogonId, logonSettings.MemberId);

                    if (earnerReturnValue.Success)
                    {
                        timeService = new TimeServiceClient();
                        CollectionRequest collectionRequest = new CollectionRequest();
                        collectionRequest.ForceRefresh = forceRefresh;
                        collectionRequest.StartRow = startRow;
                        collectionRequest.RowCount = pageSize;

                        UnPostedTimeSearchCriteria searchCriteria = new UnPostedTimeSearchCriteria();
                        searchCriteria.FeeEarnerRef = earnerReturnValue.EarnerRef;
                        searchCriteria.UserId = logonSettings.DbUid;
                        searchCriteria.TimeDate = DateTime.Now.Date;
                        searchCriteria.OrderBy = sortBy;

                        UnPostedTimeSearchReturnValue returnValue = timeService.UnPostedTimeSheetSearch(logonSettings.LogonId,
                                                        collectionRequest, searchCriteria);

                        if (returnValue.Success)
                        {
                            _rowCount = returnValue.UnPostedTimeSheet.TotalRowCount;
                            timesheet = returnValue.UnPostedTimeSheet.Rows;
                        }
                        else
                        {
                            throw new Exception(returnValue.Message);
                        }
                    }
                    else
                    {
                        //Error retrieveing earner ref. wont be able to get the time sheet
                        throw new Exception("Error retrieving timesheet");
                    }
                }
                return timesheet;
            }
            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();
                }
            }
        }