Exemplo n.º 1
0
        public decimal GetDefaultAmount(AccountTransactionDocumentType documentType, Account account)
        {
            decimal result = 0;

            if (!string.IsNullOrEmpty(documentType.DefaultAmount))
            {
                var da = documentType.DefaultAmount;
                if (Regex.IsMatch(da, "\\[:([^\\]]+)\\]"))
                {
                    var match = Regex.Match(da, "\\[:([^\\]]+)\\]");
                    da = GetCustomData(account, match.Groups[1].Value);
                    decimal.TryParse(da, out result);
                }
                else if (da == string.Format("[{0}]", Resources.Balance))
                {
                    result = Math.Abs(GetAccountBalance(account.Id));
                }
                else if (da == string.Format("[{0}]", "BalanceEx"))
                {
                    var er = GetExchangeRate(account.ForeignCurrencyId, documentType.ExchangeTemplate);
                    result = er != 1
                        ? Math.Abs(GetAccountExchangeBalance(account.Id) * er)
                        : Math.Abs(GetAccountBalance(account.Id));
                }
                else
                {
                    decimal.TryParse(da, out result);
                }
            }
            return(result);
        }
 public AccountRowViewModel(Account account, AccountTransactionDocumentType documentType, IAccountService accountService, ICacheService cacheService)
 {
     _account       = account;
     Amount         = accountService.GetDefaultAmount(documentType, account);
     Description    = accountService.GetDescription(documentType, account);
     TargetAccounts = GetAccountSelectors(documentType, account, accountService, cacheService).ToList();
 }
        private IEnumerable <AccountSelectViewModel> GetAccountSelectors(AccountTransactionDocumentType documentType, Account selectedAccount, IAccountService accountService, ICacheService cacheService)
        {
            var accountMap = documentType.AccountTransactionDocumentAccountMaps.FirstOrDefault(x => x.AccountId == selectedAccount.Id);

            return(accountMap != null
                       ? documentType.GetNeededAccountTypes().Select(x => new AccountSelectViewModel(accountService, cacheService.GetAccountTypeById(x), accountMap.MappedAccountId, accountMap.MappedAccountName))
                       : documentType.GetNeededAccountTypes().Select(x => new AccountSelectViewModel(accountService, cacheService.GetAccountTypeById(x))));
        }
Exemplo n.º 4
0
        public IEnumerable <AccountTransactionDocumentType> BatchCreateTransactionTypeDocuments(string[] values, IWorkspace workspace)
        {
            IList <AccountTransactionDocumentType> result = new List <AccountTransactionDocumentType>();

            if (values.Length > 0)
            {
                foreach (var item in values)
                {
                    var parts = item.Split(';');
                    if (parts.Count() > 3)
                    {
                        var name = parts[0].Trim();
                        if (workspace.Single <AccountTransactionDocumentType>(x => x.Name.ToLower() == name.ToLower()) != null)
                        {
                            continue;
                        }

                        var atName = parts[1].Trim();
                        var header = parts[2].Trim();

                        var accTemplate = workspace.Single <AccountType>(x => x.Name.ToLower() == atName.ToLower());
                        if (accTemplate == null)
                        {
                            using (var w = WorkspaceFactory.Create())
                            {
                                accTemplate = new AccountType {
                                    Name = atName
                                };
                                w.Add(accTemplate);
                                w.CommitChanges();
                            }
                        }

                        var resultItem = new AccountTransactionDocumentType
                        {
                            Name = name,
                            MasterAccountTypeId = accTemplate.Id,
                            ButtonHeader        = header,
                            ButtonColor         = "Gainsboro"
                        };

                        for (var i = 3; i < parts.Length; i++)
                        {
                            var n  = parts[i].ToLower();
                            var tt = workspace.Single <AccountTransactionType>(x => x.Name.ToLower() == n);
                            if (tt != null)
                            {
                                resultItem.TransactionTypes.Add(tt);
                            }
                        }

                        result.Add(resultItem);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 5
0
 public void CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, decimal exchangeRate, IEnumerable <Account> accounts)
 {
     using (var w = WorkspaceFactory.Create())
     {
         var document = documentType.CreateDocument(selectedAccount, description, amount, exchangeRate, accounts != null ? accounts.ToList() : null);
         w.Add(document);
         w.CommitChanges();
     }
 }
Exemplo n.º 6
0
        public IEnumerable <Account> GetDocumentAccounts(AccountTransactionDocumentType documentType)
        {
            switch (documentType.Filter)
            {
            case 1: return(GetBalancedAccounts(documentType.MasterAccountTypeId));

            case 2: return(GetAccounts(documentType.AccountTransactionDocumentAccountMaps.Select(x => x.AccountId)));

            default: return(GetAccounts(documentType.MasterAccountTypeId));
            }
        }
        public void Update(AccountTransactionDocumentType value)
        {
            SelectedDocumentType = value;
            Accounts.Clear();
            var accounts = GetAccounts(value);

            Accounts.AddRange(accounts
                              .AsParallel()
                              .SetCulture()
                              .Select(x => new AccountRowViewModel(x, value, _accountService, _cacheService)));
            OnOnUpdate(EventArgs.Empty);
        }
        private AccountTransactionDocumentType CreateTransactionDocument(AccountType masterAccountType, params AccountTransactionType[] transactionTypes)
        {
            var result = new AccountTransactionDocumentType();

            foreach (var accountTransactionType in transactionTypes)
            {
                result.TransactionTypes.Add(accountTransactionType);
            }
            result.MasterAccountTypeId = masterAccountType.Id;
            Workspace.Add(result);
            Workspace.CommitChanges();
            return(result);
        }
Exemplo n.º 9
0
        public string GetDescription(AccountTransactionDocumentType documentType, Account account)
        {
            var result = documentType.DescriptionTemplate;

            if (string.IsNullOrEmpty(result))
            {
                return(result);
            }
            while (Regex.IsMatch(result, "\\[:([^\\]]+)\\]"))
            {
                var match = Regex.Match(result, "\\[:([^\\]]+)\\]");
                result = result.Replace(match.Groups[0].Value, GetCustomData(account, match.Groups[1].Value));
            }
            if (result.Contains("[MONTH]"))
            {
                result = result.Replace("[MONTH]", DateTime.Now.ToMonthName());
            }
            if (result.Contains("[NEXT MONTH]"))
            {
                result = result.Replace("[NEXT MONTH]", DateTime.Now.ToNextMonthName());
            }
            if (result.Contains("[WEEK]"))
            {
                result = result.Replace("[WEEK]", DateTime.Now.WeekOfYear().ToString(CultureInfo.CurrentCulture));
            }
            if (result.Contains("[NEXT WEEK]"))
            {
                result = result.Replace("[NEXT WEEK]", (DateTime.Now.NextWeekOfYear()).ToString(CultureInfo.CurrentCulture));
            }
            if (result.Contains("[YEAR]"))
            {
                result = result.Replace("[YEAR]", (DateTime.Now.Year).ToString(CultureInfo.CurrentCulture));
            }
            if (result.Contains("[ACCOUNT NAME]"))
            {
                result = result.Replace("[ACCOUNT NAME]", account.Name);
            }
            return(result);
        }
Exemplo n.º 10
0
 public DocumentCreationData(Account account, AccountTransactionDocumentType documentType)
 {
     Account      = account;
     DocumentType = documentType;
 }
Exemplo n.º 11
0
 public DocumentTypeButtonViewModel(AccountTransactionDocumentType model, Account account)
 {
     Model   = model;
     Account = account;
     SelectDocumentTypeCommand = new DelegateCommand <string>(OnSelectDocumentType);
 }
Exemplo n.º 12
0
 private void CreateTransaction(AccountTransactionDocumentType accountTransactionDocumentType, Account masterAccount, decimal amount, params Account[] accounts)
 {
     _accountService.CreateTransactionDocument(masterAccount, accountTransactionDocumentType, "", amount, accounts);
     Workspace.CommitChanges();
 }
Exemplo n.º 13
0
        public void CreateData()
        {
            CreateDefaultCurrenciesIfNeeded();

            if (!ShouldCreateData())
            {
                return;
            }

            var saleAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Sales)
            };
            var receivableAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Receiveable)
            };
            var paymentAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Payment)
            };
            var discountAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Discount)
            };
            var customerAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Customer)
            };

            _workspace.Add(receivableAccountType);
            _workspace.Add(saleAccountType);
            _workspace.Add(paymentAccountType);
            _workspace.Add(discountAccountType);
            _workspace.Add(customerAccountType);
            _workspace.CommitChanges();

            var customerEntityType = new EntityType {
                Name = Resources.Customers, EntityName = Resources.Customer, AccountTypeId = customerAccountType.Id, PrimaryFieldName = Resources.Name
            };

            customerEntityType.EntityCustomFields.Add(new EntityCustomField {
                EditingFormat = "(###) ### ####", FieldType = 0, Name = Resources.Phone
            });
            customerEntityType.AccountNameTemplate = "[Name]-[" + Resources.Phone + "]";
            var tableEntityType = new EntityType {
                Name = Resources.Tables, EntityName = Resources.Table, PrimaryFieldName = Resources.Name
            };

            _workspace.Add(customerEntityType);
            _workspace.Add(tableEntityType);

            _workspace.CommitChanges();

            var accountScreen = new AccountScreen {
                Name = Resources.General
            };

            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = saleAccountType.Name, AccountTypeId = saleAccountType.Id, DisplayDetails = true, SortOrder = 10
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = receivableAccountType.Name, AccountTypeId = receivableAccountType.Id, DisplayDetails = true, SortOrder = 20
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = discountAccountType.Name, AccountTypeId = discountAccountType.Id, DisplayDetails = true, SortOrder = 30
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = paymentAccountType.Name, AccountTypeId = paymentAccountType.Id, DisplayDetails = true, SortOrder = 40
            });
            _workspace.Add(accountScreen);

            var defaultSaleAccount = new Account {
                AccountTypeId = saleAccountType.Id, Name = Resources.Sales
            };
            var defaultReceivableAccount = new Account {
                AccountTypeId = receivableAccountType.Id, Name = Resources.Receivables
            };
            var cashAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.Cash
            };
            var creditCardAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.CreditCard
            };
            var voucherAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.Voucher
            };
            var defaultDiscountAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = Resources.Discount
            };
            var defaultRoundingAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = Resources.Rounding
            };

            _workspace.Add(defaultSaleAccount);
            _workspace.Add(defaultReceivableAccount);
            _workspace.Add(defaultDiscountAccount);
            _workspace.Add(defaultRoundingAccount);
            _workspace.Add(cashAccount);
            _workspace.Add(creditCardAccount);
            _workspace.Add(voucherAccount);

            _workspace.CommitChanges();

            var discountTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Discount),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = defaultDiscountAccount.Id
            };

            var roundingTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Rounding),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = defaultRoundingAccount.Id
            };

            var saleTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Sale),
                SourceAccountTypeId    = saleAccountType.Id,
                TargetAccountTypeId    = receivableAccountType.Id,
                DefaultSourceAccountId = defaultSaleAccount.Id,
                DefaultTargetAccountId = defaultReceivableAccount.Id
            };

            var paymentTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Payment),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = cashAccount.Id
            };

            var customerAccountTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Customer_f, Resources.AccountTransaction),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = customerAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id
            };

            var customerCashPaymentType = new AccountTransactionType
            {
                Name = string.Format(Resources.Customer_f, Resources.CashPayment),
                SourceAccountTypeId    = customerAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultTargetAccountId = cashAccount.Id
            };

            var customerCreditCardPaymentType = new AccountTransactionType
            {
                Name = string.Format(Resources.Customer_f, Resources.CreditCardPayment),
                SourceAccountTypeId    = customerAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultTargetAccountId = creditCardAccount.Id
            };

            _workspace.Add(saleTransactionType);
            _workspace.Add(paymentTransactionType);
            _workspace.Add(discountTransactionType);
            _workspace.Add(roundingTransactionType);
            _workspace.Add(customerAccountTransactionType);
            _workspace.Add(customerCashPaymentType);
            _workspace.Add(customerCreditCardPaymentType);

            var discountService = new CalculationType
            {
                AccountTransactionType = discountTransactionType,
                CalculationMethod      = 0,
                DecreaseAmount         = true,
                Name = Resources.Discount
            };

            var roundingService = new CalculationType
            {
                AccountTransactionType = roundingTransactionType,
                CalculationMethod      = 2,
                DecreaseAmount         = true,
                IncludeTax             = true,
                Name = Resources.Round
            };

            var discountSelector = new CalculationSelector {
                Name = Resources.Discount, ButtonHeader = Resources.DiscountPercentSign
            };

            discountSelector.CalculationTypes.Add(discountService);
            discountSelector.AddCalculationSelectorMap();

            var roundingSelector = new CalculationSelector {
                Name = Resources.Round, ButtonHeader = Resources.Round
            };

            roundingSelector.CalculationTypes.Add(roundingService);
            roundingSelector.AddCalculationSelectorMap();


            _workspace.Add(discountService);
            _workspace.Add(roundingService);
            _workspace.Add(discountSelector);
            _workspace.Add(roundingSelector);

            var screen = new ScreenMenu();

            _workspace.Add(screen);

            var ticketNumerator = new Numerator {
                Name = Resources.TicketNumerator
            };

            _workspace.Add(ticketNumerator);

            var orderNumerator = new Numerator {
                Name = Resources.OrderNumerator
            };

            _workspace.Add(orderNumerator);



            _workspace.CommitChanges();

            var ticketType = new TicketType
            {
                Name                = Resources.Ticket,
                TicketNumerator     = ticketNumerator,
                OrderNumerator      = orderNumerator,
                SaleTransactionType = saleTransactionType,
                ScreenMenuId        = screen.Id,
            };

            ticketType.EntityTypeAssignments.Add(new EntityTypeAssignment {
                EntityTypeId = tableEntityType.Id, EntityTypeName = tableEntityType.Name, SortOrder = 10
            });
            ticketType.EntityTypeAssignments.Add(new EntityTypeAssignment {
                EntityTypeId = customerEntityType.Id, EntityTypeName = customerEntityType.Name, SortOrder = 20
            });

            var cashPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = cashAccount,
                Name    = cashAccount.Name
            };

            cashPayment.PaymentTypeMaps.Add(new PaymentTypeMap());

            var creditCardPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = creditCardAccount,
                Name    = creditCardAccount.Name
            };

            creditCardPayment.PaymentTypeMaps.Add(new PaymentTypeMap());

            var voucherPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = voucherAccount,
                Name    = voucherAccount.Name
            };

            voucherPayment.PaymentTypeMaps.Add(new PaymentTypeMap());

            var accountPayment = new PaymentType
            {
                AccountTransactionType = customerAccountTransactionType,
                Name = Resources.CustomerAccount
            };

            accountPayment.PaymentTypeMaps.Add(new PaymentTypeMap());

            _workspace.Add(cashPayment);
            _workspace.Add(creditCardPayment);
            _workspace.Add(voucherPayment);
            _workspace.Add(accountPayment);
            _workspace.Add(ticketType);

            var warehouseType = new WarehouseType {
                Name = Resources.Warehouses
            };

            _workspace.Add(warehouseType);
            _workspace.CommitChanges();

            var localWarehouse = new Warehouse
            {
                Name            = Resources.LocalWarehouse,
                WarehouseTypeId = warehouseType.Id
            };

            _workspace.Add(localWarehouse);
            _workspace.CommitChanges();

            var department = new Department
            {
                Name         = Resources.Restaurant,
                TicketTypeId = ticketType.Id,
                WarehouseId  = localWarehouse.Id
            };

            _workspace.Add(department);

            var transactionType = new InventoryTransactionType
            {
                Name = Resources.PurchaseTransactionType,
                TargetWarehouseTypeId    = warehouseType.Id,
                DefaultTargetWarehouseId = localWarehouse.Id
            };

            _workspace.Add(transactionType);

            var transactionDocumentType = new InventoryTransactionDocumentType
            {
                Name = Resources.PurchaseTransaction,
                InventoryTransactionType = transactionType
            };

            _workspace.Add(transactionDocumentType);

            var role = new UserRole("Admin")
            {
                IsAdmin = true, DepartmentId = 1
            };

            _workspace.Add(role);

            var u = new User("Administrator", "1234")
            {
                UserRole = role
            };

            _workspace.Add(u);

            var ticketPrinterTemplate = new PrinterTemplate {
                Name = Resources.TicketTemplate, Template = GetDefaultTicketPrintTemplate()
            };
            var kitchenPrinterTemplate = new PrinterTemplate {
                Name = Resources.KitchenOrderTemplate, Template = GetDefaultKitchenPrintTemplate()
            };
            var customerReceiptTemplate = new PrinterTemplate {
                Name = Resources.CustomerReceiptTemplate, Template = GetDefaultCustomerReceiptTemplate()
            };

            _workspace.Add(ticketPrinterTemplate);
            _workspace.Add(kitchenPrinterTemplate);
            _workspace.Add(customerReceiptTemplate);

            var printer1 = new Printer {
                Name = Resources.TicketPrinter
            };
            var printer2 = new Printer {
                Name = Resources.KitchenPrinter
            };
            var printer3 = new Printer {
                Name = Resources.InvoicePrinter
            };

            _workspace.Add(printer1);
            _workspace.Add(printer2);
            _workspace.Add(printer3);

            _workspace.CommitChanges();

            var t = new Terminal
            {
                IsDefault            = true,
                Name                 = Resources.Server,
                ReportPrinterId      = printer1.Id,
                TransactionPrinterId = printer1.Id,
            };

            var pm1 = new PrinterMap {
                PrinterId = printer1.Id, PrinterTemplateId = ticketPrinterTemplate.Id
            };

            _workspace.Add(pm1);

            var pj1 = new PrintJob
            {
                Name        = Resources.PrintBill,
                WhatToPrint = (int)WhatToPrintTypes.Everything,
            };

            pj1.PrinterMaps.Add(pm1);


            _workspace.Add(pj1);

            var pm2 = new PrinterMap {
                PrinterId = printer2.Id, PrinterTemplateId = kitchenPrinterTemplate.Id
            };
            var pj2 = new PrintJob
            {
                Name        = Resources.PrintOrdersToKitchenPrinter,
                WhatToPrint = (int)WhatToPrintTypes.Everything,
            };

            pj2.PrinterMaps.Add(pm2);

            _workspace.Add(pj2);
            _workspace.Add(t);

            new RuleGenerator().GenerateSystemRules(_workspace);

            ImportMenus(screen);
            ImportTableResources(tableEntityType, ticketType);

            var customerScreen = new EntityScreen {
                Name = string.Format(Resources.Customer_f, Resources.Search), DisplayMode = 1, EntityTypeId = customerEntityType.Id, TicketTypeId = ticketType.Id
            };

            customerScreen.EntityScreenMaps.Add(new EntityScreenMap());
            _workspace.Add(customerScreen);

            var customerTicketScreen = new EntityScreen {
                Name = Resources.CustomerTickets, DisplayMode = 0, EntityTypeId = customerEntityType.Id, StateFilter = Resources.NewOrders, ColumnCount = 6, RowCount = 6, TicketTypeId = ticketType.Id
            };

            customerTicketScreen.EntityScreenMaps.Add(new EntityScreenMap());
            _workspace.Add(customerTicketScreen);

            var customerCashDocument = new AccountTransactionDocumentType
            {
                Name                = string.Format(Resources.Customer_f, Resources.Cash),
                ButtonHeader        = Resources.Cash,
                DefaultAmount       = string.Format("[{0}]", Resources.Balance),
                DescriptionTemplate = string.Format(Resources.Payment_f, Resources.Cash),
                MasterAccountTypeId = customerAccountType.Id,
                PrinterTemplateId   = customerReceiptTemplate.Id
            };

            customerCashDocument.AddAccountTransactionDocumentTypeMap();
            customerCashDocument.TransactionTypes.Add(customerCashPaymentType);

            var customerCreditCardDocument = new AccountTransactionDocumentType
            {
                Name                = string.Format(Resources.Customer_f, Resources.CreditCard),
                ButtonHeader        = Resources.CreditCard,
                DefaultAmount       = string.Format("[{0}]", Resources.Balance),
                DescriptionTemplate = string.Format(Resources.Payment_f, Resources.CreditCard),
                MasterAccountTypeId = customerAccountType.Id,
                PrinterTemplateId   = customerReceiptTemplate.Id
            };

            customerCreditCardDocument.AddAccountTransactionDocumentTypeMap();
            customerCreditCardDocument.TransactionTypes.Add(customerCreditCardPaymentType);

            _workspace.Add(customerCashDocument);
            _workspace.Add(customerCreditCardDocument);

            ImportItems(BatchCreateEntities);
            ImportItems(BatchCreateTransactionTypes);
            ImportItems(BatchCreateTransactionTypeDocuments);

            _workspace.CommitChanges();
            _workspace.Dispose();
        }
 private IEnumerable <Account> GetAccounts(AccountTransactionDocumentType documentType)
 {
     return(_accountService.GetDocumentAccounts(documentType).Where(documentType.CanMakeAccountTransaction));
 }
Exemplo n.º 15
0
 public AccountTransactionDocument CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, decimal exchangeRate, IEnumerable <AccountData> accounts, IEnumerable <ForeignCurrency> currencies)
 {
     using (var w = WorkspaceFactory.Create())
     {
         var document = documentType.CreateDocument(selectedAccount, description, amount, exchangeRate, accounts != null ? accounts.ToList() : null, currencies.ToList());
         w.Add(document);
         w.CommitChanges();
         return(document);
     }
 }
Exemplo n.º 16
0
        public void CreateData()
        {
            CreateDefaultCurrenciesIfNeeded();

            if (!ShouldCreateData())
            {
                return;
            }

            var saleAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Sales)
            };
            var receivableAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Receiveable)
            };
            var paymentAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Payment)
            };
            var discountAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Discount)
            };
            var customerAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Customer)
            };

            _workspace.Add(receivableAccountType);
            _workspace.Add(saleAccountType);
            _workspace.Add(paymentAccountType);
            _workspace.Add(discountAccountType);
            _workspace.Add(customerAccountType);
            _workspace.CommitChanges();

            var customerResourceType = new ResourceType {
                Name = Resources.Customers, EntityName = Resources.Customer, AccountTypeId = customerAccountType.Id
            };

            customerResourceType.ResoruceCustomFields.Add(new ResourceCustomField {
                EditingFormat = "(###) ### ####", FieldType = 0, Name = Resources.Phone
            });
            customerResourceType.AccountNameTemplate = "[Name]-[Phone]";
            var tableResourceType = new ResourceType {
                Name = Resources.Tables, EntityName = Resources.Table
            };

            _workspace.Add(customerResourceType);
            _workspace.Add(tableResourceType);

            _workspace.CommitChanges();

            var accountScreen = new AccountScreen {
                Name = Resources.General
            };

            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = saleAccountType.Name, AccountTypeId = saleAccountType.Id, DisplayDetails = true
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = receivableAccountType.Name, AccountTypeId = receivableAccountType.Id, DisplayDetails = true
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = discountAccountType.Name, AccountTypeId = discountAccountType.Id, DisplayDetails = true
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = paymentAccountType.Name, AccountTypeId = paymentAccountType.Id, DisplayDetails = true
            });
            _workspace.Add(accountScreen);

            var defaultSaleAccount = new Account {
                AccountTypeId = saleAccountType.Id, Name = Resources.Sales
            };
            var defaultReceivableAccount = new Account {
                AccountTypeId = receivableAccountType.Id, Name = Resources.Receivables
            };
            var cashAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.Cash
            };
            var creditCardAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.CreditCard
            };
            var voucherAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.Voucher
            };
            var defaultDiscountAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = Resources.Discount
            };
            var defaultRoundingAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = Resources.Rounding
            };

            _workspace.Add(defaultSaleAccount);
            _workspace.Add(defaultReceivableAccount);
            _workspace.Add(defaultDiscountAccount);
            _workspace.Add(defaultRoundingAccount);
            _workspace.Add(cashAccount);
            _workspace.Add(creditCardAccount);
            _workspace.Add(voucherAccount);

            _workspace.CommitChanges();

            var discountTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Discount),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = defaultDiscountAccount.Id
            };

            var roundingTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Rounding),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = defaultRoundingAccount.Id
            };

            var saleTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Sale),
                SourceAccountTypeId    = saleAccountType.Id,
                TargetAccountTypeId    = receivableAccountType.Id,
                DefaultSourceAccountId = defaultSaleAccount.Id,
                DefaultTargetAccountId = defaultReceivableAccount.Id
            };

            var paymentTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Payment),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = cashAccount.Id
            };

            var customerAccountTransactionType = new AccountTransactionType
            {
                Name = "Customer Account Transaction",
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = customerAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id
            };

            var customerCashPaymentType = new AccountTransactionType
            {
                Name = "Customer Cash Payment",
                SourceAccountTypeId    = customerAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultTargetAccountId = cashAccount.Id
            };

            var customerCreditCardPaymentType = new AccountTransactionType
            {
                Name = "Customer Credit Card Payment",
                SourceAccountTypeId    = customerAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultTargetAccountId = creditCardAccount.Id
            };

            _workspace.Add(saleTransactionType);
            _workspace.Add(paymentTransactionType);
            _workspace.Add(discountTransactionType);
            _workspace.Add(roundingTransactionType);
            _workspace.Add(customerAccountTransactionType);
            _workspace.Add(customerCashPaymentType);
            _workspace.Add(customerCreditCardPaymentType);

            var customerCashDocument = new AccountTransactionDocumentType
            {
                Name                = "Customer Cash",
                ButtonHeader        = Resources.Cash,
                DefaultAmount       = string.Format("[{0}]", Resources.Balance),
                DescriptionTemplate = string.Format(Resources.Payment_f, Resources.Cash),
                MasterAccountTypeId = customerAccountType.Id
            };

            customerCashDocument.AddAccountTransactionDocumentTypeMap();
            customerCashDocument.TransactionTypes.Add(customerCashPaymentType);

            var customerCreditCardDocument = new AccountTransactionDocumentType
            {
                Name                = "Customer Credit Card",
                ButtonHeader        = Resources.CreditCard,
                DefaultAmount       = string.Format("[{0}]", Resources.Balance),
                DescriptionTemplate = string.Format(Resources.Payment_f, Resources.CreditCard),
                MasterAccountTypeId = customerAccountType.Id
            };

            customerCreditCardDocument.AddAccountTransactionDocumentTypeMap();
            customerCreditCardDocument.TransactionTypes.Add(customerCreditCardPaymentType);

            _workspace.Add(customerCashDocument);
            _workspace.Add(customerCreditCardDocument);

            var discountService = new CalculationType
            {
                AccountTransactionType = discountTransactionType,
                CalculationMethod      = 0,
                DecreaseAmount         = true,
                Name = Resources.Discount
            };

            var roundingService = new CalculationType
            {
                AccountTransactionType = roundingTransactionType,
                CalculationMethod      = 2,
                DecreaseAmount         = true,
                IncludeTax             = true,
                Name = Resources.Round
            };

            var discountSelector = new CalculationSelector {
                Name = Resources.Discount, ButtonHeader = Resources.DiscountPercentSign
            };

            discountSelector.CalculationTypes.Add(discountService);
            discountSelector.AddCalculationSelectorMap();

            var roundingSelector = new CalculationSelector {
                Name = Resources.Round, ButtonHeader = Resources.Round
            };

            roundingSelector.CalculationTypes.Add(roundingService);
            roundingSelector.AddCalculationSelectorMap();


            _workspace.Add(discountService);
            _workspace.Add(roundingService);
            _workspace.Add(discountSelector);
            _workspace.Add(roundingSelector);

            var screen = new ScreenMenu();

            _workspace.Add(screen);

            var ticketNumerator = new Numerator {
                Name = Resources.TicketNumerator
            };

            _workspace.Add(ticketNumerator);

            var orderNumerator = new Numerator {
                Name = Resources.OrderNumerator
            };

            _workspace.Add(orderNumerator);

            var printBillAutomation = new AutomationCommand {
                Name = Resources.PrintBill, ButtonHeader = Resources.PrintBill
            };

            printBillAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                VisualBehaviour = 1
            });
            _workspace.Add(printBillAutomation);

            var unlockTicketAutomation = new AutomationCommand {
                Name = Resources.UnlockTicket, ButtonHeader = Resources.UnlockTicket
            };

            unlockTicketAutomation.AutomationCommandMaps.Add(new AutomationCommandMap {
                VisualBehaviour = 2
            });
            _workspace.Add(unlockTicketAutomation);

            var addTicketAutomation = new AutomationCommand {
                Name = string.Format(Resources.Add_f, Resources.Ticket), ButtonHeader = string.Format(Resources.Add_f, Resources.Ticket)
            };

            addTicketAutomation.AddAutomationCommandMap();
            _workspace.Add(addTicketAutomation);

            _workspace.CommitChanges();

            var ticketTemplate = new TicketTemplate
            {
                Name                = Resources.TicketTemplate,
                TicketNumerator     = ticketNumerator,
                OrderNumerator      = orderNumerator,
                SaleTransactionType = saleTransactionType,
            };

            var cashPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = cashAccount,
                Name    = cashAccount.Name
            };

            cashPayment.PaymentTypeMaps.Add(new PaymentTypeMap {
                DisplayAtPaymentScreen = true
            });

            var creditCardPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = creditCardAccount,
                Name    = creditCardAccount.Name
            };

            creditCardPayment.PaymentTypeMaps.Add(new PaymentTypeMap {
                DisplayAtPaymentScreen = true
            });

            var voucherPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = voucherAccount,
                Name    = voucherAccount.Name
            };

            voucherPayment.PaymentTypeMaps.Add(new PaymentTypeMap {
                DisplayAtPaymentScreen = true
            });

            var accountPayment = new PaymentType
            {
                AccountTransactionType = customerAccountTransactionType,
                Name = Resources.CustomerAccount
            };

            accountPayment.PaymentTypeMaps.Add(new PaymentTypeMap {
                DisplayAtPaymentScreen = true
            });

            _workspace.Add(cashPayment);
            _workspace.Add(creditCardPayment);
            _workspace.Add(voucherPayment);
            _workspace.Add(ticketTemplate);
            _workspace.Add(accountPayment);

            var department = new Department
            {
                Name           = Resources.Restaurant,
                TicketTemplate = ticketTemplate,
                ScreenMenuId   = screen.Id,
            };

            _workspace.Add(department);

            var role = new UserRole("Admin")
            {
                IsAdmin = true, DepartmentId = 1
            };

            _workspace.Add(role);

            var u = new User("Administrator", "1234")
            {
                UserRole = role
            };

            _workspace.Add(u);

            var ticketPrinterTemplate = new PrinterTemplate {
                Name = Resources.TicketTemplate, Template = Resources.TicketTemplateValue
            };
            var kitchenPrinterTemplate = new PrinterTemplate {
                Name = Resources.KitchenOrderTemplate, Template = Resources.KitchenTemplateValue
            };

            _workspace.Add(ticketPrinterTemplate);
            _workspace.Add(kitchenPrinterTemplate);

            var printer1 = new Printer {
                Name = Resources.TicketPrinter
            };
            var printer2 = new Printer {
                Name = Resources.KitchenPrinter
            };
            var printer3 = new Printer {
                Name = Resources.InvoicePrinter
            };

            _workspace.Add(printer1);
            _workspace.Add(printer2);
            _workspace.Add(printer3);

            _workspace.CommitChanges();

            var t = new Terminal
            {
                IsDefault     = true,
                Name          = Resources.Server,
                ReportPrinter = printer1,
            };

            var pm1 = new PrinterMap {
                PrinterId = printer1.Id, PrinterTemplateId = ticketPrinterTemplate.Id
            };

            _workspace.Add(pm1);

            var pj1 = new PrintJob
            {
                Name        = Resources.PrintBill,
                LocksTicket = true,
                WhatToPrint = (int)WhatToPrintTypes.Everything,
            };

            pj1.PrinterMaps.Add(pm1);


            _workspace.Add(pj1);

            var pm2 = new PrinterMap {
                PrinterId = printer2.Id, PrinterTemplateId = kitchenPrinterTemplate.Id
            };
            var pj2 = new PrintJob
            {
                Name        = Resources.PrintOrdersToKitchenPrinter,
                WhatToPrint = (int)WhatToPrintTypes.NewLines,
            };

            pj2.PrinterMaps.Add(pm2);

            _workspace.Add(pj2);
            _workspace.Add(t);

            var orderTag1 = new OrderStateGroup {
                Name = Resources.Gift, ButtonHeader = Resources.Gift, CalculateOrderPrice = false, DecreaseOrderInventory = true
            };

            orderTag1.OrderStates.Add(new OrderState {
                Name = Resources.Gift
            });
            orderTag1.AddOrderStateMap();
            _workspace.Add(orderTag1);

            var orderTag2 = new OrderStateGroup {
                Name = Resources.Void, ButtonHeader = Resources.Void, CalculateOrderPrice = false, DecreaseOrderInventory = false
            };

            orderTag2.OrderStates.Add(new OrderState {
                Name = Resources.Void
            });
            orderTag2.UnlocksOrder = true;
            orderTag2.AddOrderStateMap();
            _workspace.Add(orderTag2);

            const string parameterFormat = "[{{\"Key\":\"{0}\",\"Value\":\"{1}\"}}]";
            //const string doubleParameterFormat = "[{{\"Key\":\"{0}\",\"Value\":\"{1}\"}},{{\"Key\":\"{2}\",\"Value\":\"{3}\"}}]";

            var newOrderState = new ResourceState {
                Name = "New Orders", Color = "Orange"
            };

            _workspace.Add(newOrderState);

            var availableState = new ResourceState {
                Name = "Available", Color = "White"
            };

            _workspace.Add(availableState);

            var billRequestedState = new ResourceState {
                Name = "Bill Requested", Color = "Maroon"
            };

            _workspace.Add(billRequestedState);

            var newOrderAction = new AppAction {
                ActionType = "UpdateResourceState", Name = "Update New Order State", Parameter = string.Format(parameterFormat, "ResourceState", "New Orders")
            };

            _workspace.Add(newOrderAction);
            var availableAction = new AppAction {
                ActionType = "UpdateResourceState", Name = "Update Available State", Parameter = string.Format(parameterFormat, "ResourceState", "Available")
            };

            _workspace.Add(availableAction);
            var billRequestedAction = new AppAction {
                ActionType = "UpdateResourceState", Name = "Update Bill Requested State", Parameter = string.Format(parameterFormat, "ResourceState", "Bill Requested")
            };

            _workspace.Add(billRequestedAction);
            var createTicketAction = new AppAction {
                ActionType = "CreateTicket", Name = string.Format(Resources.Create_f, Resources.Ticket), Parameter = ""
            };

            _workspace.Add(createTicketAction);
            var closeTicketAction = new AppAction {
                ActionType = "CloseActiveTicket", Name = Resources.CloseTicket, Parameter = ""
            };

            _workspace.Add(closeTicketAction);
            var printBillAction = new AppAction {
                ActionType = "ExecutePrintJob", Name = "Execute Bill Print Job", Parameter = string.Format(parameterFormat, "PrintJobName", Resources.PrintBill)
            };

            _workspace.Add(printBillAction);
            var printKitchenOrdersAction = new AppAction {
                ActionType = "ExecutePrintJob", Name = "Execute Kitchen Orders Print Job", Parameter = string.Format(parameterFormat, "PrintJobName", Resources.PrintOrdersToKitchenPrinter)
            };

            _workspace.Add(printKitchenOrdersAction);
            var unlockTicketAction = new AppAction {
                ActionType = "UnlockTicket", Name = Resources.UnlockTicket, Parameter = ""
            };

            _workspace.Add(unlockTicketAction);
            _workspace.CommitChanges();

            var newOrderRule = new AppRule {
                Name = "Update New Order Resource Color", EventName = "TicketClosing", EventConstraints = "NewOrderCount;>;0"
            };

            newOrderRule.Actions.Add(new ActionContainer(printKitchenOrdersAction));
            newOrderRule.Actions.Add(new ActionContainer(newOrderAction));
            newOrderRule.AddRuleMap();
            _workspace.Add(newOrderRule);

            var availableRule = new AppRule {
                Name = "Update Available Resource Color", EventName = "ResourceUpdated", EventConstraints = "OpenTicketCount;=;0"
            };
            var ac2 = new ActionContainer(availableAction);

            availableRule.Actions.Add(ac2);
            availableRule.AddRuleMap();
            _workspace.Add(availableRule);

            var movingRule = new AppRule {
                Name = "Update Moved Resource Color", EventName = "TicketResourceChanged", EventConstraints = "OrderCount;>;0"
            };
            var ac3 = new ActionContainer(newOrderAction);

            movingRule.Actions.Add(ac3);
            movingRule.AddRuleMap();
            _workspace.Add(movingRule);

            var printBillRule = new AppRule {
                Name = "Print Bill Rule", EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;" + Resources.PrintBill
            };

            printBillRule.Actions.Add(new ActionContainer(printBillAction));
            printBillRule.Actions.Add(new ActionContainer(billRequestedAction));
            printBillRule.Actions.Add(new ActionContainer(closeTicketAction));
            printBillRule.AddRuleMap();
            _workspace.Add(printBillRule);

            var unlockTicketRule = new AppRule {
                Name = "Unlock Ticket Rule", EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;Unlock Ticket"
            };

            unlockTicketRule.Actions.Add(new ActionContainer(unlockTicketAction));
            unlockTicketRule.AddRuleMap();
            _workspace.Add(unlockTicketRule);

            var createTicketRule = new AppRule {
                Name = "Create Ticket Rule", EventName = RuleEventNames.AutomationCommandExecuted, EventConstraints = "AutomationCommandName;=;Add Ticket"
            };

            createTicketRule.Actions.Add(new ActionContainer(createTicketAction));
            createTicketRule.AddRuleMap();
            _workspace.Add(createTicketRule);

            var updateMergedTicket = new AppRule {
                Name = "Update Merged Tickets State", EventName = RuleEventNames.TicketsMerged
            };

            updateMergedTicket.Actions.Add(new ActionContainer(newOrderAction));
            updateMergedTicket.AddRuleMap();
            _workspace.Add(updateMergedTicket);

            ImportMenus(screen);
            ImportTableResources(tableResourceType, availableState.Id);

            var customerScreen = new ResourceScreen {
                Name = "Customer Search", DisplayMode = 2, ResourceTypeId = customerResourceType.Id
            };

            customerScreen.ResourceScreenMaps.Add(new ResourceScreenMap());
            _workspace.Add(customerScreen);

            var customerTicketScreen = new ResourceScreen {
                Name = "Customer Tickets", DisplayMode = 0, ResourceTypeId = customerResourceType.Id, StateFilterId = newOrderState.Id, ColumnCount = 6, RowCount = 6
            };

            customerTicketScreen.ResourceScreenMaps.Add(new ResourceScreenMap());
            _workspace.Add(customerTicketScreen);


            ImportItems(BatchCreateResources);
            ImportItems(BatchCreateTransactionTypes);
            ImportItems(BatchCreateTransactionTypeDocuments);

            _workspace.CommitChanges();
            _workspace.Dispose();
        }
Exemplo n.º 17
0
        public AccountTransactionDocument CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, IEnumerable <Account> accounts)
        {
            var exchangeRate = GetExchangeRate(selectedAccount.ForeignCurrencyId, documentType.ExchangeTemplate);
            var accountData  = accounts.Select(x => new AccountData(x)
            {
                ExchangeRate = GetExchangeRate(x.ForeignCurrencyId, documentType.ExchangeTemplate)
            });

            return(_accountDao.CreateTransactionDocument(selectedAccount, documentType, description, amount, exchangeRate, accountData, _cacheService.GetForeignCurrencies()));
        }
Exemplo n.º 18
0
        public void Create(DataCreationService dataCreationService, IWorkspace workspace)
        {
            this._workspace = workspace;
            var saleAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Sales)
            };
            var receivableAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Receiveable)
            };
            var paymentAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Payment)
            };
            var discountAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Discount)
            };
            var customerAccountType = new AccountType {
                Name = string.Format(Resources.Accounts_f, Resources.Customer)
            };

            _workspace.Add(receivableAccountType);
            _workspace.Add(saleAccountType);
            _workspace.Add(paymentAccountType);
            _workspace.Add(discountAccountType);
            _workspace.Add(customerAccountType);
            _workspace.CommitChanges();

            var customerEntityType = new EntityType {
                Name = Resources.Customers, EntityName = Resources.Customer, AccountTypeId = customerAccountType.Id, PrimaryFieldName = Resources.Name
            };

            customerEntityType.EntityCustomFields.Add(new EntityCustomField {
                EditingFormat = "(###) ### ####", FieldType = 0, Name = Resources.Phone
            });
            customerEntityType.AccountNameTemplate = "[Name]-[" + Resources.Phone + "]";
            //var tableEntityType = new EntityType { Name = Resources.Tables, EntityName = Resources.Table, PrimaryFieldName = Resources.Name };

            _workspace.Add(customerEntityType);
            //_workspace.Add(tableEntityType);

            _workspace.CommitChanges();

            var accountScreen = new AccountScreen {
                Name = Resources.General
            };

            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = saleAccountType.Name, AccountTypeId = saleAccountType.Id, DisplayDetails = true, SortOrder = 10
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = receivableAccountType.Name, AccountTypeId = receivableAccountType.Id, DisplayDetails = true, SortOrder = 20
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = discountAccountType.Name, AccountTypeId = discountAccountType.Id, DisplayDetails = true, SortOrder = 30
            });
            accountScreen.AccountScreenValues.Add(new AccountScreenValue {
                AccountTypeName = paymentAccountType.Name, AccountTypeId = paymentAccountType.Id, DisplayDetails = true, SortOrder = 40
            });
            _workspace.Add(accountScreen);

            var defaultSaleAccount = new Account {
                AccountTypeId = saleAccountType.Id, Name = Resources.Sales
            };
            var defaultReceivableAccount = new Account {
                AccountTypeId = receivableAccountType.Id, Name = Resources.Receivables
            };
            var cashAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.Cash
            };
            var creditCardAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.CreditCard
            };
            var voucherAccount = new Account {
                AccountTypeId = paymentAccountType.Id, Name = Resources.Voucher
            };
            var defaultDiscountAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = Resources.Discount
            };
            var defaultRoundingAccount = new Account {
                AccountTypeId = discountAccountType.Id, Name = Resources.Rounding
            };

            _workspace.Add(defaultSaleAccount);
            _workspace.Add(defaultReceivableAccount);
            _workspace.Add(defaultDiscountAccount);
            _workspace.Add(defaultRoundingAccount);
            _workspace.Add(cashAccount);
            _workspace.Add(creditCardAccount);
            _workspace.Add(voucherAccount);

            _workspace.CommitChanges();

            var discountTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Discount),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = defaultDiscountAccount.Id
            };

            var roundingTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Rounding),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = discountAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = defaultRoundingAccount.Id
            };

            var saleTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Sale),
                SourceAccountTypeId    = saleAccountType.Id,
                TargetAccountTypeId    = receivableAccountType.Id,
                DefaultSourceAccountId = defaultSaleAccount.Id,
                DefaultTargetAccountId = defaultReceivableAccount.Id
            };

            var paymentTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Transaction_f, Resources.Payment),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id,
                DefaultTargetAccountId = cashAccount.Id
            };

            var customerAccountTransactionType = new AccountTransactionType
            {
                Name = string.Format(Resources.Customer_f, Resources.AccountTransaction),
                SourceAccountTypeId    = receivableAccountType.Id,
                TargetAccountTypeId    = customerAccountType.Id,
                DefaultSourceAccountId = defaultReceivableAccount.Id
            };

            var customerCashPaymentType = new AccountTransactionType
            {
                Name = string.Format(Resources.Customer_f, Resources.CashPayment),
                SourceAccountTypeId    = customerAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultTargetAccountId = cashAccount.Id
            };

            var customerCreditCardPaymentType = new AccountTransactionType
            {
                Name = string.Format(Resources.Customer_f, Resources.CreditCardPayment),
                SourceAccountTypeId    = customerAccountType.Id,
                TargetAccountTypeId    = paymentAccountType.Id,
                DefaultTargetAccountId = creditCardAccount.Id
            };

            _workspace.Add(saleTransactionType);
            _workspace.Add(paymentTransactionType);
            _workspace.Add(discountTransactionType);
            _workspace.Add(roundingTransactionType);
            _workspace.Add(customerAccountTransactionType);
            _workspace.Add(customerCashPaymentType);
            _workspace.Add(customerCreditCardPaymentType);

            var discountService = new CalculationType
            {
                AccountTransactionType = discountTransactionType,
                CalculationMethod      = 0,
                DecreaseAmount         = true,
                Name = Resources.Discount
            };

            var roundingService = new CalculationType
            {
                AccountTransactionType = roundingTransactionType,
                CalculationMethod      = 2,
                DecreaseAmount         = true,
                IncludeTax             = true,
                Name = Resources.Round
            };

            var discountSelector = new CalculationSelector {
                Name = Resources.Discount, ButtonHeader = Resources.DiscountPercentSign
            };

            discountSelector.CalculationTypes.Add(discountService);
            discountSelector.AddCalculationSelectorMap();

            var roundingSelector = new CalculationSelector {
                Name = Resources.Round, ButtonHeader = Resources.Round
            };

            roundingSelector.CalculationTypes.Add(roundingService);
            roundingSelector.AddCalculationSelectorMap();


            _workspace.Add(discountService);
            _workspace.Add(roundingService);
            _workspace.Add(discountSelector);
            _workspace.Add(roundingSelector);

            var screen = new ScreenMenu();

            _workspace.Add(screen);

            var ticketNumerator = new Numerator {
                Name = Resources.TicketNumerator
            };

            _workspace.Add(ticketNumerator);

            var orderNumerator = new Numerator {
                Name = Resources.OrderNumerator
            };

            _workspace.Add(orderNumerator);



            _workspace.CommitChanges();

            var ticketType = new TicketType
            {
                Name                = Resources.Ticket,
                TicketNumerator     = ticketNumerator,
                OrderNumerator      = orderNumerator,
                SaleTransactionType = saleTransactionType,
                ScreenMenuId        = screen.Id,
            };

            ticketType.EntityTypeAssignments.Add(new EntityTypeAssignment {
                EntityTypeId = customerEntityType.Id, EntityTypeName = customerEntityType.Name, SortOrder = 20
            });

            var cashPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = cashAccount,
                Name    = cashAccount.Name
            };

            cashPayment.PaymentTypeMaps.Add(new PaymentTypeMap());

            var creditCardPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = creditCardAccount,
                Name    = creditCardAccount.Name
            };

            creditCardPayment.PaymentTypeMaps.Add(new PaymentTypeMap());

            var voucherPayment = new PaymentType
            {
                AccountTransactionType = paymentTransactionType,
                Account = voucherAccount,
                Name    = voucherAccount.Name
            };

            voucherPayment.PaymentTypeMaps.Add(new PaymentTypeMap());

            var accountPayment = new PaymentType
            {
                AccountTransactionType = customerAccountTransactionType,
                Name = Resources.CustomerAccount
            };

            accountPayment.PaymentTypeMaps.Add(new PaymentTypeMap());

            _workspace.Add(cashPayment);
            _workspace.Add(creditCardPayment);
            _workspace.Add(voucherPayment);
            _workspace.Add(accountPayment);
            _workspace.Add(ticketType);

            var warehouseType = new WarehouseType {
                Name = Resources.Warehouses
            };

            _workspace.Add(warehouseType);
            _workspace.CommitChanges();

            var localWarehouse = new Warehouse
            {
                Name            = Resources.LocalWarehouse,
                WarehouseTypeId = warehouseType.Id
            };

            _workspace.Add(localWarehouse);
            _workspace.CommitChanges();

            var department = new Department
            {
                Name         = Resources.Retail,
                TicketTypeId = ticketType.Id,
                WarehouseId  = localWarehouse.Id
            };

            _workspace.Add(department);

            var transactionType = new InventoryTransactionType
            {
                Name = Resources.PurchaseTransactionType,
                TargetWarehouseTypeId    = warehouseType.Id,
                DefaultTargetWarehouseId = localWarehouse.Id
            };

            _workspace.Add(transactionType);

            var transactionDocumentType = new InventoryTransactionDocumentType
            {
                Name = Resources.PurchaseTransaction,
                InventoryTransactionType = transactionType
            };

            _workspace.Add(transactionDocumentType);

            AddDefaultUsers();

            PrinterTemplate customerReceiptTemplate = AddDefaultPrintersAndTerminal();

            new RuleGenerator().GenerateSystemRules(_workspace);

            dataCreationService.ImportMenus(screen);
            //dataCreationService.ImportTableResources(tableEntityType, ticketType);
            //RL - import data and associate with an entity.
            //C:\Users\Roy Lawson\source\repos\sdselite\SambaPOS-3\Samba.Presentation\bin\Debug\Imports

            var customerScreen = new EntityScreen {
                Name = string.Format(Resources.Customer_f, Resources.Search), DisplayMode = 1, EntityTypeId = customerEntityType.Id, TicketTypeId = ticketType.Id
            };

            customerScreen.EntityScreenMaps.Add(new EntityScreenMap());
            _workspace.Add(customerScreen);

            var customerTicketScreen = new EntityScreen {
                Name = Resources.CustomerTickets, DisplayMode = 0, EntityTypeId = customerEntityType.Id, StateFilter = Resources.NewOrders, ColumnCount = 6, RowCount = 6, TicketTypeId = ticketType.Id
            };

            customerTicketScreen.EntityScreenMaps.Add(new EntityScreenMap());
            _workspace.Add(customerTicketScreen);

            var customerCashDocument = new AccountTransactionDocumentType
            {
                Name                = string.Format(Resources.Customer_f, Resources.Cash),
                ButtonHeader        = Resources.Cash,
                DefaultAmount       = string.Format("[{0}]", Resources.Balance),
                DescriptionTemplate = string.Format(Resources.Payment_f, Resources.Cash),
                MasterAccountTypeId = customerAccountType.Id,
                PrinterTemplateId   = customerReceiptTemplate.Id
            };

            customerCashDocument.AddAccountTransactionDocumentTypeMap();
            customerCashDocument.TransactionTypes.Add(customerCashPaymentType);

            var customerCreditCardDocument = new AccountTransactionDocumentType
            {
                Name                = string.Format(Resources.Customer_f, Resources.CreditCard),
                ButtonHeader        = Resources.CreditCard,
                DefaultAmount       = string.Format("[{0}]", Resources.Balance),
                DescriptionTemplate = string.Format(Resources.Payment_f, Resources.CreditCard),
                MasterAccountTypeId = customerAccountType.Id,
                PrinterTemplateId   = customerReceiptTemplate.Id
            };

            customerCreditCardDocument.AddAccountTransactionDocumentTypeMap();
            customerCreditCardDocument.TransactionTypes.Add(customerCreditCardPaymentType);

            _workspace.Add(customerCashDocument);
            _workspace.Add(customerCreditCardDocument);
        }
Exemplo n.º 19
0
        public AccountTransactionDocument CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, IEnumerable <Account> accounts)
        {
            var exchangeRate = GetExchangeRate(selectedAccount, documentType.ExchangeTemplate);

            return(_accountDao.CreateTransactionDocument(selectedAccount, documentType, description, amount, exchangeRate, accounts));
        }