Exemplo n.º 1
0
        /// <summary>
        /// Loads write off bills only while page index changed.
        /// </summary>
        /// <param name="startRow"></param>
        /// <param name="pageSize"></param>
        /// <param name="forceRefresh"></param>
        /// <returns></returns>
        public BillsLedgerSearchItem[] LoadWriteOffBills(int startRow, int pageSize, bool forceRefresh)
        {
            AccountsServiceClient accountsService = null;

            BillsLedgerSearchItem[] writeOffBills = null;

            try
            {
                if (Session[SessionName.ProjectId] != null)
                {
                    accountsService = new AccountsServiceClient();
                    CollectionRequest collectionRequest = new CollectionRequest();
                    collectionRequest.ForceRefresh = forceRefresh;
                    collectionRequest.StartRow     = startRow;
                    collectionRequest.RowCount     = pageSize;

                    Guid projectId = (Guid)Session[SessionName.ProjectId];
                    Guid logonId   = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId;
                    BillsLedgerReturnValue returnValue = accountsService.LoadWriteOffBills(logonId, collectionRequest, projectId);

                    if (returnValue.Success)
                    {
                        _writeOffBillsRowCount = returnValue.Bills.TotalRowCount;
                        writeOffBills          = returnValue.Bills.Rows;
                    }
                    else
                    {
                        _lblMessage.CssClass = "errorMessage";
                        _lblMessage.Text     = returnValue.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (accountsService != null)
                {
                    if (accountsService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        accountsService.Close();
                    }
                }
            }

            return(writeOffBills);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads uncleared bills by project id
        /// </summary>
        /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
        /// <param name="projectId">To load uncleared bills</param>
        /// <returns>Loads uncleared bills by project id</returns>
        public BillsLedgerReturnValue LoadUnclearedBills(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest, Guid projectId)
        {
            BillsLedgerReturnValue returnValue = null;

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oAccountService = new AccountsService();
                returnValue     = oAccountService.LoadUnclearedBills(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, projectId);
            }
            else
            {
                returnValue         = new BillsLedgerReturnValue();
                returnValue.Success = false;
                returnValue.Message = "Invalid Token";
            }
            return(returnValue);
        }
        /// <summary>
        /// Loads write off bills by project id
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service</param>
        /// <param name="projectId">To load write off bills</param>
        /// <returns>Loads write off bills by project id</returns>
        public BillsLedgerReturnValue LoadWriteOffBills(Guid logonId, CollectionRequest collectionRequest, Guid projectId)
        {
            BillsLedgerReturnValue returnValue = new BillsLedgerReturnValue();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                        // Can do everything
                            break;
                        case DataConstants.UserType.Client:
                            // Can view own bills
                            if (!SrvMatterCommon.WebAllowedToAccessMatter(projectId))
                                throw new Exception("Access denied");
                            break;
                        case DataConstants.UserType.ThirdParty:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }

                    // Create a data list creator for a list of bills
                    DataListCreator<BillsLedgerSearchItem> dataListCreator = new DataListCreator<BillsLedgerSearchItem>();

                    // Declare an inline event (annonymous delegate) to read the
                    // dataset if it is required
                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        DsBillWoTransactions dsBillWoTransactions = SrvBillWoLedgerLookup.GetBillWoLedgerTransactions(projectId);

                        DataSet dsWriteOffBills = new DataSet();
                        dsWriteOffBills.Tables.Add("WriteOffBills");
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("PostingId", typeof(int));
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("PostingDate", typeof(DateTime));
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("PostingReference", typeof(string));
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("PostingType", typeof(string));
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("Debit", typeof(decimal));
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("Credit", typeof(decimal));
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("Paid", typeof(decimal));
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("OutStanding", typeof(decimal));
                        dsWriteOffBills.Tables["WriteOffBills"].Columns.Add("Balance", typeof(decimal));

                        DataView dvWriteOffBills = new DataView(dsBillWoTransactions.uvw_BillWoTransactions);
                        if (dvWriteOffBills.Count != 0)
                        {
                            string columnOrderByPostingDate = Convert.ToString(dsBillWoTransactions.uvw_BillWoTransactions.Columns["PostingDetailsDate"]);
                            dvWriteOffBills.Sort = columnOrderByPostingDate + " " + "asc";

                            int factor = 1;
                            string postingBank = string.Empty;
                            string postingType = string.Empty;
                            decimal debit = decimal.Zero;
                            decimal credit = decimal.Zero;
                            decimal balance = decimal.Zero;
                            decimal outStanding = decimal.Zero;
                            decimal paid = decimal.Zero;

                            foreach (DataRowView writeOfBillsRowView in dvWriteOffBills)
                            {
                                int postingId = Convert.ToInt32(writeOfBillsRowView.Row["PostingId"].ToString());
                                DateTime postingDate = (DateTime)writeOfBillsRowView.Row["PostingDetailsDate"];
                                string postingReference = (string)writeOfBillsRowView.Row["PostingDetailsRef"].ToString();
                                postingType = "Write Off";

                                if ((decimal)writeOfBillsRowView.Row["BillWoLedgerWorkingAmount"] < Decimal.Zero)
                                {
                                    // Credit note.
                                    credit = Math.Abs((decimal)writeOfBillsRowView.Row["BillWoLedgerWorkingAmount"]);
                                    debit = decimal.Zero;
                                    factor = -1;
                                }
                                else
                                {
                                    // Bill.
                                    debit = Math.Abs((decimal)writeOfBillsRowView.Row["BillWoLedgerWorkingAmount"]);
                                    credit = decimal.Zero;
                                    factor = 1;
                                }

                                paid = factor * Math.Abs((decimal)writeOfBillsRowView.Row["BillWoAmount"]);
                                outStanding = factor * (debit + credit - Math.Abs(paid));

                                balance = balance + outStanding;
                                outStanding = Decimal.Round(outStanding, 2);
                                debit = Decimal.Round(debit, 2);
                                credit = Decimal.Round(credit, 2);
                                balance = Decimal.Round(balance, 2);

                                // Adds deposit details to dataset after calculations
                                dsWriteOffBills.Tables["WriteOffBills"].Rows.Add(postingId,
                                                                             postingDate,
                                                                             postingReference,
                                                                             postingType,
                                                                             debit.ToString("0.00"),
                                                                             credit.ToString("0.00"),
                                                                             paid.ToString("0.00"),
                                                                             outStanding.ToString("0.00"),
                                                                             balance.ToString("0.00"));
                            }
                        }

                        e.DataSet = dsWriteOffBills;
                    };

                    // Create the data list
                    returnValue.Bills = dataListCreator.Create(logonId,
                        // Give the query a name so it can be cached
                        "LoadWriteOffBills",
                        // Tell it the query criteria used so if the cache is accessed
                        // again it knows if it is the same query
                        projectId.ToString(),
                        collectionRequest,
                        // Import mappings to map the dataset row fields to the data
                        // list entity properties
                        new ImportMapping[] {
                                            new ImportMapping("PostingId", "PostingId"),
                                            new ImportMapping("BillDate", "PostingDate"),
                                            new ImportMapping("BillReference", "PostingReference"),
                                            new ImportMapping("BillType", "PostingType"),
                                            new ImportMapping("Debit","Debit"),
                                            new ImportMapping("Credit","Credit"),
                                            new ImportMapping("Paid","Paid"),
                                            new ImportMapping("OutStanding","OutStanding"),
                                            new ImportMapping("Balance","Balance")
                            }
                        );
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception Ex)
            {
                returnValue.Success = false;
                returnValue.Message = Ex.Message;
            }

            return returnValue;
        }
 /// <summary>
 /// Loads write off bills by project id
 /// </summary>
 /// <param name="oHostSecurityToken">HostSecurityToken obtained when security provider of IWS is called</param>
 /// <param name="projectId">To load write off bills</param>
 /// <returns>Loads write off bills by project id</returns>
 public BillsLedgerReturnValue LoadWriteOffBills(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest, Guid projectId)
 {
     BillsLedgerReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oAccountService = new AccountsService();
         returnValue = oAccountService.LoadWriteOffBills(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, projectId);
     }
     else
     {
         returnValue = new BillsLedgerReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }