Esempio n. 1
0
 public void SetEntityToDelete(object param)
 {
     if (param is UserCashBook)
     {
         entityToDelete = param as UserCashBook;
         this.Message = "Sunteti sigur ca doriti sa stergeti " + entityToDelete.Name + " ?".Replace(Environment.NewLine, "");
     }
 }
        public void Create(UserCashBook item)
        {
            using (var context = GetContext())
            {
                ICompanyRepository companyRepository = new CompanyRepository();

                var existingCompany = companyRepository.GetCompany();

                item.Id = DbIdHelper.GetNextID();
                item.RegistruCasaZis = new System.Data.Objects.DataClasses.EntityCollection<DailyCashBook>();
                item.SocietateId = existingCompany.Id;
                item.InitialBalanceDate = Utils.DateTimeToDay(item.InitialBalanceDate);
                context.UserCashBooks.AddObject(item);
                Commit(context);
            }
        }
 public void Edit(long id, UserCashBook item)
 {
     using (var context = GetContext())
     {
         var existingEntity = GetCashBook(id, context);
         if (existingEntity != null)
         {
             existingEntity.Name = item.Name;
             existingEntity.Account = item.Account;
             existingEntity.CashierName = item.CashierName;
             existingEntity.CoinDecimals = item.CoinDecimals;
             existingEntity.CoinType = item.CoinType;
             existingEntity.InitialBalance = item.InitialBalance;
             existingEntity.Location = item.Location;
             existingEntity.InitialBalanceDate = Utils.DateTimeToDay(item.InitialBalanceDate);
         }
         Commit(context);
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the UserCashBooks EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUserCashBooks(UserCashBook userCashBook)
 {
     base.AddObject("UserCashBooks", userCashBook);
 }
 /// <summary>
 /// Create a new UserCashBook object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="societateId">Initial value of the SocietateId property.</param>
 /// <param name="coinType">Initial value of the CoinType property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="coinDecimals">Initial value of the CoinDecimals property.</param>
 /// <param name="initialBalance">Initial value of the InitialBalance property.</param>
 /// <param name="location">Initial value of the Location property.</param>
 /// <param name="account">Initial value of the Account property.</param>
 /// <param name="cashierName">Initial value of the CashierName property.</param>
 public static UserCashBook CreateUserCashBook(global::System.Int64 id, global::System.Int64 societateId, global::System.String coinType, global::System.String name, global::System.Byte coinDecimals, global::System.Decimal initialBalance, global::System.String location, global::System.String account, global::System.String cashierName)
 {
     UserCashBook userCashBook = new UserCashBook();
     userCashBook.Id = id;
     userCashBook.SocietateId = societateId;
     userCashBook.CoinType = coinType;
     userCashBook.Name = name;
     userCashBook.CoinDecimals = coinDecimals;
     userCashBook.InitialBalance = initialBalance;
     userCashBook.Location = location;
     userCashBook.Account = account;
     userCashBook.CashierName = cashierName;
     return userCashBook;
 }
        public List<ReportPageVM> GetPages(Company company, UserCashBook cashBook, DateTime dateTime, ICashBookRepository cashBookRepository, ICashBookEntryRepository cashBookEntryRepository, int maxEntriesPerPage)
        {
            //maxEntriesPerPage = 13;
            List<ReportPageVM> resultPages = new List<ReportPageVM>();
            try
            {

                this.MaxEntriesPerPage = maxEntriesPerPage;

                var MoneyExchangeRate = cashBookEntryRepository.GetExchangeRateForDay(cashBook.Id, dateTime);

                CashBookEntries = new ObservableCollection<CashBookEntryUI>();
                var tempCashBookEntries = new ObservableCollection<CashBookEntryUI>();

                var existingCashBookEntries = cashBookEntryRepository.GetEntriesForDay(cashBook.Id, dateTime);
                if (existingCashBookEntries != null)
                {
                    foreach (var item in existingCashBookEntries)
                    {
                        tempCashBookEntries.Add((CashBookEntryUI)item);
                    }
                }
                if (tempCashBookEntries.Count == 0)
                {
                    //no report to print for this day, return empty;
                    return resultPages;
                }

                //add incasari
                foreach (var item in tempCashBookEntries)
                {
                    if (item.Incasari != 0)
                    {
                        CashBookEntries.Add((CashBookEntryUI)item);
                    }
                }

                //add payments
                foreach (var item in tempCashBookEntries)
                {
                    if (item.Plati != 0)
                    {
                        CashBookEntries.Add((CashBookEntryUI)item);
                    }
                }
                var ReportTitle = cashBook.IsLei ? "REGISTRU DE CASA in LEI" : "REGISTRU DE CASA in VALUTA";
                var MoneyExchangeRateVisibility = cashBook.IsLei ? Visibility.Collapsed : Visibility.Visible;

                if (!cashBook.IsLei && MoneyExchangeRate.HasValue)
                {
                    foreach (var item in CashBookEntries)
                    {
                        if (item.Incasari != 0)
                        {
                            item.LeiValue = item.Incasari * MoneyExchangeRate.Value;
                        }
                        else
                        {
                            item.LeiValue = item.Plati * MoneyExchangeRate.Value;
                        }
                    }
                }

                var InitialBalanceForDayDecimal = cashBookRepository.GetInitialBalanceForDay(cashBook.Id, dateTime);

                AddExtraDetailsRows(InitialBalanceForDayDecimal, cashBook, MoneyExchangeRate);
                currentPage = 0;
                nrCrt = 1;
                while (HasNextPage())
                {
                    currentPage++;
                    LoadDataForCurrentPage();

                    ReportPageVM newPage = new ReportPageVM()
                    {
                        Company = company,
                        CurrentPageCashBookEntries = CurrentPageCashBookEntries,
                        InitialBalanceForDayDecimal = InitialBalanceForDayDecimal,
                        MoneyExchangeRate = MoneyExchangeRate,
                        MoneyExchangeRateVisibility = MoneyExchangeRateVisibility,
                        PageNumber = PageNumber,
                        ReportTitle = ReportTitle,
                        SelectedCashBook = cashBook,
                        SelectedDate = dateTime,
                    };
                    resultPages.Add(newPage);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Log.Error(ex);
            }
            return resultPages;
        }
        private void AddExtraDetailsRows(decimal InitialBalanceForDayDecimal, UserCashBook cashBook, decimal? MoneyExchangeRate)
        {
            //calculate the current and final balance
            decimal currentBalanceIn = 0;
            decimal currentBalanceOut = 0;
            CashBookEntries.ToList().ForEach(p => currentBalanceIn += p.Incasari);
            CashBookEntries.ToList().ForEach(p => currentBalanceOut += p.Plati);
            var currentBalanceDecimal = currentBalanceIn - currentBalanceOut;
            var totalBalanceDecimal = currentBalanceDecimal + InitialBalanceForDayDecimal;

            CashBookEntryUI currentBalance = new CashBookEntryUI()
            {
                Plati = currentBalanceOut,
                Incasari = currentBalanceIn,
                Explicatii = "Rulaj curent",
                IsExtraDetail = true
            };

            CashBookEntryUI finalBalance = new CashBookEntryUI()
            {
                Incasari = totalBalanceDecimal,
                Plati = 0,
                PlatiString = "",
                Explicatii = "Sold final",
                IsExtraDetail = true
            };
            if (cashBook.IsLei)
            {
                finalBalance.LeiValue = finalBalance.Incasari * MoneyExchangeRate.Value;
            }

            CashBookEntries.Add(currentBalance);
            CashBookEntries.Add(finalBalance);
        }
        private void LoadDataForCashBook(UserCashBook cashBook, DateTime date)
        {
            SelectedCashBook = cashBook;
            this.Title = "Editare Registru de casa (" + SelectedCashBook.Name + ")";
            DecimalConvertor.Instance.SetNumberOfDecimals(SelectedCashBook.CoinDecimals);

            SelectedDate = date;
            UpdateBalance(null);

            MoneyExchangeRateVisibility = SelectedCashBook.IsLei ? Visibility.Collapsed : Visibility.Visible;
            if (SelectedCashBook.IsLei)
            {
                MoneyExchangeRate = 0;
            }
            Company = companyRepository.GetCompany();
            EndDate = DateTime.Now;
            if (SelectedCashBook.InitialBalanceDate.HasValue)
            {
                StartDate = SelectedCashBook.InitialBalanceDate.Value;
            }
            //do not let the user enter values in a day before the registry start date
            if (SelectedDate < StartDate)
            {
                SelectedDate = StartDate;
            }
        }