public void Update(ICacheService cacheService, Account selectedAccount, WorkPeriod currentWorkPeriod)
        {
            var accountType = cacheService.GetAccountTypeById(selectedAccount.AccountTypeId);
            var transactions = Dao.Query(GetCurrentRange(accountType.DefaultFilterType, x => x.AccountId == selectedAccount.Id, currentWorkPeriod)).OrderBy(x => x.Date);
            Transactions = transactions.Select(x => new AccountDetailData(x, selectedAccount)).ToList();
            if (accountType.DefaultFilterType > 0)
            {
                var pastDebit = Dao.Sum(x => x.Debit, GetPastRange(accountType.DefaultFilterType, x => x.AccountId == selectedAccount.Id, currentWorkPeriod));
                var pastCredit = Dao.Sum(x => x.Credit, GetPastRange(accountType.DefaultFilterType, x => x.AccountId == selectedAccount.Id, currentWorkPeriod));
                var pastExchange = Dao.Sum(x => x.Exchange, GetPastRange(accountType.DefaultFilterType, x => x.AccountId == selectedAccount.Id, currentWorkPeriod));
                if (pastCredit > 0 || pastDebit > 0)
                {
                    Summaries.Add(new AccountSummaryData(Resources.Total, Transactions.Sum(x => x.Debit), Transactions.Sum(x => x.Credit)));
                    var detailValue =
                        new AccountDetailData(
                        new AccountTransactionValue
                        {
                            Name = Resources.PastTransactions,
                            Credit = pastCredit,
                            Debit = pastDebit,
                            Exchange = pastExchange
                        }, selectedAccount) { IsBold = true };
                    Transactions.Insert(0, detailValue);
                }
            }

            Summaries.Add(new AccountSummaryData(Resources.GrandTotal, Transactions.Sum(x => x.Debit), Transactions.Sum(x => x.Credit)));

            for (var i = 0; i < Transactions.Count; i++)
            {
                Transactions[i].Balance = (Transactions[i].Debit - Transactions[i].Credit);
                if (i > 0) (Transactions[i].Balance) += (Transactions[i - 1].Balance);
            }
        }
Пример #2
0
 public static void CalculateCost(PeriodicConsumption pc, WorkPeriod workPeriod)
 {
     var sales = GetSales(workPeriod);
     foreach (var sale in sales)
     {
         var lSale = sale;
         var recipe = Dao.Single<Recipe>(x => x.Portion.Name == lSale.PortionName && x.Portion.MenuItemId == lSale.MenuItemId, x => x.Portion, x => x.RecipeItems, x => x.RecipeItems.Select(y => y.InventoryItem));
         if (recipe != null)
         {
             var totalcost = recipe.FixedCost;
             foreach (var recipeItem in recipe.RecipeItems.Where(x => x.InventoryItem != null && x.Quantity > 0))
             {
                 var item = recipeItem;
                 var pci = pc.PeriodicConsumptionItems.SingleOrDefault(x => x.InventoryItem.Id == item.InventoryItem.Id);
                 if (pci != null && pci.GetPredictedConsumption() > 0)
                 {
                     var cost = recipeItem.Quantity * (pci.Cost / pci.UnitMultiplier);
                     cost = (pci.GetConsumption() * cost) / pci.GetPredictedConsumption();
                     totalcost += cost;
                 }
             }
             var ci = pc.CostItems.SingleOrDefault(x => x.Portion.Id == recipe.Portion.Id);
             if (ci != null) ci.Cost = decimal.Round(totalcost, 2);
         }
     }
 }
Пример #3
0
        private static IEnumerable<SalesData> GetSales(WorkPeriod workPeriod)
        {
            var ticketItems = GetTicketItemsFromRecipes(workPeriod);
            var salesData = ticketItems.GroupBy(x => new { x.MenuItemName, x.MenuItemId, x.PortionName })
                    .Select(x => new SalesData { MenuItemName = x.Key.MenuItemName, MenuItemId = x.Key.MenuItemId, PortionName = x.Key.PortionName, Total = x.Sum(y => y.Quantity) }).ToList();

            var properties = ticketItems.SelectMany(x => x.Properties, (ti, pr) => new { Properties = pr, ti.Quantity })
                    .Where(x => x.Properties.MenuItemId > 0)
                    .GroupBy(x => new { x.Properties.MenuItemId, x.Properties.PortionName });

            foreach (var ticketItemProperty in properties)
            {
                var tip = ticketItemProperty;
                var mi = AppServices.DataAccessService.GetMenuItem(tip.Key.MenuItemId);
                var port = mi.Portions.FirstOrDefault(x => x.Name == tip.Key.PortionName) ?? mi.Portions[0];
                var sd = salesData.SingleOrDefault(x => x.MenuItemId == mi.Id && x.MenuItemName == mi.Name && x.PortionName == port.Name) ?? new SalesData();
                sd.MenuItemId = mi.Id;
                sd.MenuItemName = mi.Name;
                sd.PortionName = port.Name;
                sd.Total += tip.Sum(x => x.Properties.Quantity * x.Quantity);
                if (!salesData.Contains(sd))
                    salesData.Add(sd);
            }

            return salesData;
        }
Пример #4
0
        public void StartWorkPeriod(string description, decimal cashAmount, decimal creditCardAmount, decimal ticketAmount)
        {
            using (var workspace = WorkspaceFactory.Create())
            {
                _applicationStateSetter.ResetWorkPeriods();

                var latestWorkPeriod = workspace.Last<WorkPeriod>();
                if (latestWorkPeriod != null && latestWorkPeriod.StartDate == latestWorkPeriod.EndDate)
                {
                    return;
                }

                var now = DateTime.Now;
                var newPeriod = new WorkPeriod
                {
                    StartDate = now,
                    EndDate = now,
                    StartDescription = description,
                    CashAmount = cashAmount,
                    CreditCardAmount = creditCardAmount,
                    TicketAmount = ticketAmount
                };

                workspace.Add(newPeriod);
                workspace.CommitChanges();
                _applicationStateSetter.ResetWorkPeriods();
            }
        }
Пример #5
0
        public void PrintAccountTransactions(Account account, WorkPeriod workPeriod, Printer printer, string filter)
        {
            var range = _accountService.GetDateRange(filter, workPeriod);
            var summary = _accountService.GetAccountTransactionSummary(account, workPeriod, range.Start, range.End);

            var totalBalance = summary.Transactions.Sum(x => x.Debit - x.Credit).ToString(LocalSettings.ReportCurrencyFormat);

            var report = new SimpleReport("");
            report.AddParagraph("Header");
            report.AddParagraphLine("Header", _settingService.ProgramSettings.UserInfo);
            report.AddParagraphLine("Header", Resources.AccountTransaction, true);
            report.AddParagraphLine("Header", "");
            report.AddParagraphLine("Header", string.Format("{0}: {1}", string.Format(Resources.Name_f, Resources.Account), account.Name));
            report.AddParagraphLine("Header", string.Format("{0}: {1}", Resources.Balance, totalBalance));
            report.AddParagraphLine("Header", "");

            report.AddColumnLength("Transactions", "15*", "35*", "15*", "15*", "20*");
            report.AddColumTextAlignment("Transactions", TextAlignment.Left, TextAlignment.Left, TextAlignment.Right, TextAlignment.Right, TextAlignment.Right);
            report.AddTable("Transactions", Resources.Date, Resources.Description, Resources.Debit, Resources.Credit, Resources.Balance);

            foreach (var ad in summary.Transactions)
            {
                report.AddRow("Transactions", ad.Date.ToShortDateString(), ad.Name, ad.DebitStr, ad.CreditStr, ad.BalanceStr);
            }

            foreach (var sum in summary.Summaries)
            {
                report.AddBoldRow("Transactions", "", sum.Caption, sum.Debit, sum.Credit, sum.Balance);
            }

            _printerService.PrintReport(report.Document, printer);
        }
Пример #6
0
 public IEnumerable<CashTransaction> GetTransactions(WorkPeriod workPeriod)
 {
     Debug.Assert(workPeriod != null);
     if (workPeriod.StartDate == workPeriod.EndDate)
         return Dao.Query<CashTransaction>(x => x.Date >= workPeriod.StartDate);
     return Dao.Query<CashTransaction>(x => x.Date >= workPeriod.StartDate && x.Date < workPeriod.EndDate);
 }
Пример #7
0
 public void CalculateCost(PeriodicConsumption pc, WorkPeriod workPeriod)
 {
     foreach (var warehouseConsumption in pc.WarehouseConsumptions)
     {
         var recipes = GetSales(workPeriod, warehouseConsumption.WarehouseId).Select(sale => _inventoryDao.GetRecipe(sale.PortionName, sale.MenuItemId));
         pc.UpdateFinalCost(recipes.ToList(), warehouseConsumption.WarehouseId);
     }
 }
Пример #8
0
 public DateRange GetDateRange(string rangeName, WorkPeriod workPeriod)
 {
     if (rangeName == Resources.ThisMonth) return new DateRange(DateTime.Now.MonthStart(), null);
     if (rangeName == Resources.PastMonth) return new DateRange(DateTime.Now.AddMonths(-1).MonthStart(), DateTime.Now.AddMonths(-1).MonthEnd());
     if (rangeName == Resources.ThisWeek) return new DateRange(DateTime.Now.StartOfWeek(), null);
     if (rangeName == Resources.PastWeek) return new DateRange(DateTime.Now.StartOfPastWeek(), DateTime.Now.StartOfWeek().AddDays(7));
     if (rangeName == Resources.WorkPeriod) return new DateRange(workPeriod.StartDate, null);
     return new DateRange(null, null);
 }
Пример #9
0
 private static IEnumerable<TicketItem> GetTicketItemsFromRecipes(WorkPeriod workPeriod)
 {
     var recipeItemIds = Dao.Select<Recipe, int>(x => x.Portion.MenuItemId, x => x.Portion != null).Distinct();
     var tickets = Dao.Query<Ticket>(x => x.Date > workPeriod.StartDate,
                                     x => x.TicketItems,
                                     x => x.TicketItems.Select(y => y.Properties));
     return tickets.SelectMany(x => x.TicketItems)
             .Where(x => !x.Voided && recipeItemIds.Contains(x.MenuItemId));
 }
Пример #10
0
        private Expression<Func<AccountTransactionValue, bool>> GetCurrentRange(int filterType, Expression<Func<AccountTransactionValue, bool>> activeSpecification, WorkPeriod workPeriod)
        {
            //Resources.All, Resources.Month, Resources.Week, Resources.WorkPeriod
            DateTime? date = null;

            if (filterType == 1) date = DateTime.Now.MonthStart();
            if (filterType == 2) date = DateTime.Now.StartOfWeek();
            if (filterType == 3) date = workPeriod.StartDate;

            return date.HasValue ? activeSpecification.And(x => x.Date >= date) : activeSpecification;
        }
Пример #11
0
 public static PeriodicConsumption Create(WorkPeriod currentWorkPeriod, IEnumerable<int> warehouseIds)
 {
     var result = new PeriodicConsumption
     {
         WorkPeriodId = currentWorkPeriod.Id,
         Name = currentWorkPeriod.StartDate + " - " +
                currentWorkPeriod.EndDate,
         StartDate = currentWorkPeriod.StartDate,
         EndDate = currentWorkPeriod.EndDate
     };
     result.CreateWarehouseConsumptions(warehouseIds);
     return result;
 }
Пример #12
0
 public AccountTransactionSummary GetAccountTransactionSummary(Account selectedAccount, WorkPeriod currentWorkPeriod, DateTime? start = null, DateTime? end = null)
 {
     if (!start.HasValue)
     {
         var accountType = _cacheService.GetAccountTypeById(selectedAccount.AccountTypeId);
         if (accountType != null)
         {
             if (accountType.DefaultFilterType == 1) start = DateTime.Now.MonthStart();
             if (accountType.DefaultFilterType == 2) start = DateTime.Now.StartOfWeek();
             if (accountType.DefaultFilterType == 3) start = currentWorkPeriod.StartDate;
         }
     }
     return
             AccountTransactionSummaryBuilder.Create()
                                             .ForAccount(selectedAccount)
                                             .WithStartDate(start)
                                             .WithEndDate(end)
                                             .Build();
 }
Пример #13
0
        public IEnumerable<AccountScreenRow> GetAccountScreenRows(AccountScreen accountScreen, WorkPeriod currentWorkPeriod)
        {
            var rows = new List<AccountScreenRow>();
            var detailedTemplateNames = accountScreen.AccountScreenValues.Where(x => x.DisplayDetails).Select(x => x.AccountTypeId);
            _accountDao.GetAccountBalances(detailedTemplateNames.ToList(), GetFilter(accountScreen, currentWorkPeriod)).ToList().ForEach(x => rows.Add(AccountScreenRow.Create(x, _cacheService.GetCurrencySymbol(x.Key.ForeignCurrencyId), GetGroupKey(accountScreen, x.Key.AccountTypeId))));

            var templateTotals = accountScreen.AccountScreenValues.Where(x => !x.DisplayDetails).Select(x => x.AccountTypeId);
            _accountDao.GetAccountTypeBalances(templateTotals.ToList(), GetFilter(accountScreen, currentWorkPeriod)).ToList().ForEach(x => rows.Add(AccountScreenRow.Create(x, GetGroupKey(accountScreen, x.Key.Id))));

            var hideIfZeroBalanceTypeIds =
                accountScreen.AccountScreenValues.Where(x => x.HideZeroBalanceAccounts).Select(x => x.AccountTypeId).ToList();

            var accounts = rows.Where(x => ShouldKeepAccount(x, hideIfZeroBalanceTypeIds))
                               .OrderBy(x => GetSortOrder(accountScreen.AccountScreenValues, x.AccountTypeId))
                               .ThenBy(x => x.Name)
                               .ToList();

            return accounts;
        }
Пример #14
0
        public void StartWorkPeriod(string description, IWorkspace workspace)
        {
            var latestWorkPeriod = workspace.Last<WorkPeriod>();
            if (latestWorkPeriod != null && latestWorkPeriod.StartDate == latestWorkPeriod.EndDate)
            {
                return;
            }

            var now = DateTime.Now;
            var newPeriod = new WorkPeriod
            {
                StartDate = now,
                EndDate = now,
                StartDescription = description,
            };

            workspace.Add(newPeriod);
            workspace.CommitChanges();
        }
Пример #15
0
        public void PrintAccountScreen(AccountScreen accountScreen, WorkPeriod workperiod, Printer printer)
        {
            var accounts = _accountService.GetAccountScreenRows(accountScreen, workperiod);
            var report = new SimpleReport("");
            report.AddParagraph("Header");
            report.AddParagraphLine("Header", _settingService.ProgramSettings.UserInfo);
            report.AddParagraphLine("Header", string.Format(accountScreen.Name), true);
            report.AddParagraphLine("Header", "");

            report.AddColumnLength("Transactions", "60*", "40*");
            report.AddColumTextAlignment("Transactions", TextAlignment.Left, TextAlignment.Right);
            report.AddTable("Transactions", string.Format(Resources.Name_f, Resources.Account), Resources.Balance);

            foreach (var ad in accounts)
            {
                report.AddRow("Transactions", ad.Name, ad.BalanceStr);
            }

            _printerService.PrintReport(report.Document, printer);
        }
Пример #16
0
 private Expression<Func<AccountTransactionValue, bool>> GetFilter(AccountScreen selectedAccountScreen, WorkPeriod currentWorkPeriod)
 {
     if (selectedAccountScreen == null || selectedAccountScreen.Filter == 0) return null;
     //Resources.All, Resources.Month, Resources.Week, Resources.WorkPeriod
     if (selectedAccountScreen.Filter == 1)
     {
         var date = DateTime.Now.MonthStart();
         return x => x.Date >= date;
     }
     if (selectedAccountScreen.Filter == 2)
     {
         var date = DateTime.Now.StartOfWeek();
         return x => x.Date >= date;
     }
     if (selectedAccountScreen.Filter == 3)
     {
         var date = currentWorkPeriod.StartDate;
         return x => x.Date >= date;
     }
     return null;
 }
Пример #17
0
        public IEnumerable<CashTransactionData> GetTransactionsWithCustomerData(WorkPeriod workPeriod)
        {
            var wp = new WorkPeriod() { StartDate = workPeriod.StartDate, EndDate = workPeriod.EndDate };
            if (wp.StartDate == wp.EndDate) wp.EndDate = DateTime.Now;
            using (var workspace = WorkspaceFactory.CreateReadOnly())
            {
                var lines = from ct in workspace.Queryable<CashTransaction>()
                            join customer in workspace.Queryable<Customer>() on ct.CustomerId equals customer.Id into ctC
                            from customer in ctC.DefaultIfEmpty()
                            where ct.Date >= wp.StartDate && ct.Date < wp.EndDate
                            select new { CashTransaction = ct, Customer = customer };

                return lines.ToList().Select(x => new CashTransactionData
                                       {
                                           Amount = x.CashTransaction.Amount,
                                           CustomerName = x.Customer != null ? x.Customer.Name : "",
                                           Date = x.CashTransaction.Date,
                                           Name = x.CashTransaction.Name,
                                           PaymentType = x.CashTransaction.PaymentType,
                                           TransactionType = x.CashTransaction.TransactionType
                                       });
            }
        }
Пример #18
0
 private IEnumerable<Order> GetOrdersFromRecipes(WorkPeriod workPeriod, int inventoryItemId, int warehouseId)
 {
     return _inventoryDao.GetOrdersFromRecipes(workPeriod.StartDate, inventoryItemId, warehouseId);
 }
Пример #19
0
 public AccountTransactionSummary(ICacheService cacheService, Account selectedAccount, WorkPeriod currentWorkPeriod)
 {
     Summaries = new List<AccountSummaryData>();
     Update(cacheService, selectedAccount, currentWorkPeriod);
 }
Пример #20
0
 private IEnumerable<SalesData> GetSales(WorkPeriod workPeriod, int warehouseId)
 {
     var orders = GetOrdersFromRecipes(workPeriod, warehouseId).ToList();
     return GetSaleTransactions(orders);
 }
Пример #21
0
 public void AddDefaultReportHeader(SimpleReport report, WorkPeriod workPeriod, string caption)
 {
     report.AddHeader("Samba POS");
     report.AddHeader(caption);
     if (workPeriod.EndDate > workPeriod.StartDate)
         report.AddHeader(workPeriod.StartDate.ToString("dd MMMM yyyy HH:mm") +
             " - " + workPeriod.EndDate.ToString("dd MMMM yyyy HH:mm"));
     else
     {
         report.AddHeader(workPeriod.StartDate.ToString("dd MMMM yyyy HH:mm") +
         " - " + DateTime.Now.ToString("dd MMMM yyyy HH:mm"));
     }
 }
Пример #22
0
 public static void ResetCache()
 {
     _tickets = null;
     _transactions = null;
     _periodicConsumptions = null;
     _currentWorkPeriod = null;
     _cashTransactions = null;
     _thisMonthWorkPeriod = null;
     _lastMonthWorkPeriod = null;
     _thisWeekWorkPeriod = null;
     _lastWeekWorkPeriod = null;
     _yesterdayWorkPeriod = null;
     _todayWorkPeriod = null;
     _workPeriods = null;
     _taxServiceTemplates = null;
     _workspace = null;
 }
Пример #23
0
 public WorkPeriodViewModel(WorkPeriod model)
 {
     Model = model;
 }
Пример #24
0
 public static void ResetCache()
 {
     _tickets = null;
     _transactions = null;
     _accountTransactionValues = null;
     _periodicConsumptions = null;
     _currentWorkPeriod = null;
     _thisMonthWorkPeriod = null;
     _lastMonthWorkPeriod = null;
     _thisWeekWorkPeriod = null;
     _lastWeekWorkPeriod = null;
     _yesterdayWorkPeriod = null;
     _todayWorkPeriod = null;
     _workPeriods = null;
     _calculationTypes = null;
     _paymentTypes = null;
     _taxTemplates = null;
 }
Пример #25
0
 public AccountTransactionSummary GetAccountTransactionSummary(Account selectedAccount, WorkPeriod currentWorkPeriod)
 {
     return new AccountTransactionSummary(_cacheService, selectedAccount, currentWorkPeriod);
 }
Пример #26
0
 public IEnumerable<AccountScreenRow> GetAccountScreenRows(AccountScreen accountScreen, WorkPeriod currentWorkPeriod)
 {
     return _accountRowBuilder.GetAccountScreenRows(accountScreen, currentWorkPeriod);
 }
Пример #27
0
 public static WorkPeriod CreateCustomWorkPeriod(string name, DateTime startDate, DateTime endDate)
 {
     var periods = GetWorkPeriods(startDate, endDate).ToList();
     var startPeriod = periods.FirstOrDefault();
     var endPeriod = periods.LastOrDefault();
     var start = startPeriod != null ? startPeriod.StartDate : startDate;
     var end = endPeriod != null ? endPeriod.EndDate : endDate;
     if (endPeriod != null && end == endPeriod.StartDate)
         end = DateTime.Now;
     var result = new WorkPeriod { Name = name, StartDate = start, EndDate = end };
     return result;
 }
Пример #28
0
        public void AddDefaultReportHeader(SimpleReport report, WorkPeriod workPeriod, string caption)
        {
            report.AddHeader("Vero");
            report.AddHeader(caption);
            if (workPeriod.EndDate > workPeriod.StartDate)
                report.AddHeader(workPeriod.StartDate.ToString("dd MMMM yyyy HH:mm") +
                    " - " + workPeriod.EndDate.ToString("dd MMMM yyyy HH:mm"));
            else
            {
                report.AddHeader(workPeriod.StartDate.ToString("dd MMMM yyyy HH:mm") +
                " - " + DateTime.Now.ToString("dd MMMM yyyy HH:mm"));
            }

            if (!string.IsNullOrEmpty(workPeriod.Description))
                report.AddHeader(workPeriod.Description);
        }
Пример #29
0
 public void AddDefaultReportHeader(SimpleReport report, WorkPeriod workPeriod, string caption)
 {
     var userInfo = _settingService.ProgramSettings.UserInfo;
     report.AddHeader(!string.IsNullOrEmpty(userInfo) ? userInfo : "SambaPOS");
     report.AddHeader(caption);
     if (workPeriod.EndDate > workPeriod.StartDate)
         report.AddHeader(workPeriod.StartDate.ToString("dd MMMM yyyy HH:mm") +
             " - " + workPeriod.EndDate.ToString("dd MMMM yyyy HH:mm"));
     else
     {
         report.AddHeader(workPeriod.StartDate.ToString("dd MMMM yyyy HH:mm") +
         " - " + DateTime.Now.ToString("dd MMMM yyyy HH:mm"));
     }
 }
Пример #30
0
 public void ProcessWorkPeriodEnd(WorkPeriod workPeriod)
 {
     _inventoryService.DoWorkPeriodEnd();
 }