Skip to content

Commit

Permalink
Creating Entities By Action
Browse files Browse the repository at this point in the history
  • Loading branch information
emreeren committed Jul 3, 2013
1 parent 8c5f257 commit 8e21d72
Show file tree
Hide file tree
Showing 28 changed files with 206 additions and 65 deletions.
Binary file added Lib/Gma.QrCodeNet.Encoding.Net35.dll
Binary file not shown.
6 changes: 2 additions & 4 deletions Samba.Domain/Models/Tickets/Ticket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,8 @@ public decimal GetSum(int taxTempleteAccountTransactionTypeId)

public decimal GetTaxExcludedSum(Order order)
{
var plainSum = order.GetTotal();
var services = CalculateServices(Calculations.Where(x => !x.IncludeTax), plainSum);
var tax = TaxIncluded ? order.GetTotalTaxAmount(TaxIncluded, plainSum, services) : 0;
return plainSum - tax;
var tax = TaxIncluded ? order.GetTotalTaxAmount(TaxIncluded, GetPlainSum(), GetPreTaxServicesTotal()) : 0;
return order.GetTotal() - tax;
}

public decimal GetPreTaxServicesTotal()
Expand Down
2 changes: 1 addition & 1 deletion Samba.Infrastructure/Settings/LocalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static double WindowScale
public static string CurrencySymbol { get { return CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol; } }

private static int DefaultDbVersion { get { return 8; } }
private static string DefaultAppVersion { get { return "3.0.11 BETA"; } }
private static string DefaultAppVersion { get { return "3.0.12 BETA"; } }

public static int DbVersion { get { return CanReadVersionFromFile() ? Convert.ToInt32(GetVersionDat("DbVersion")) : DefaultDbVersion; } }
public static string AppVersion { get { return CanReadVersionFromFile() ? GetVersionDat("AppVersion") : DefaultAppVersion; } }
Expand Down
19 changes: 18 additions & 1 deletion Samba.Modules.AccountModule/AccountModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public AccountModule(IRegionManager regionManager,

SetNavigationCommand(Resources.Accounts, Resources.Common, "Images/Xls.png", 30);

automationService.RegisterActionType(ActionNames.CreateAccountTransactionDocument, string.Format(Resources.Create_f, Resources.AccountTransactionDocument), new { AccountTransactionDocumentName = "" });
automationService.RegisterActionType(ActionNames.CreateAccountTransactionDocument, string.Format(Resources.Create_f, Resources.AccountTransactionDocument), new { AccountTransactionDocumentName = "", AccountName = "", Description = "", Amount = 0m });
automationService.RegisterActionType(ActionNames.CreateBatchAccountTransactionDocument, Resources.BatchCreateDocuments, new { AccountTransactionDocumentName = "" });
automationService.RegisterActionType(ActionNames.CreateAccountTransaction, string.Format(Resources.Create_f, Resources.AccountTransaction), new { AccountTransactionTypeName = "", Amount = 0m });
automationService.RegisterActionType(ActionNames.PrintAccountTransactionDocument, Resources.PrintAccountTransactionDocument, new { DocumentId = 0, PrinterName = "", PrinterTemplateName = "" });
}
Expand Down Expand Up @@ -118,10 +119,26 @@ private void OnActionData(EventParameters<ActionData> ep)
}

if (ep.Value.Action.ActionType == ActionNames.CreateAccountTransactionDocument)
{
var documentName = ep.Value.GetAsString("AccountTransactionDocumentName");
var documentType = _cacheService.GetAccountTransactionDocumentTypeByName(documentName);
var accountName = ep.Value.GetAsString("AccountName");
var description = ep.Value.GetAsString("Description");
var amount = ep.Value.GetAsDecimal("Amount");
if (amount > 0)
{
var account = _accountService.GetAccountByName(accountName);
var document = _accountService.CreateTransactionDocument(account, documentType, description, amount, null);
ep.Value.DataObject.DocumentId = document.Id;
}
}

if (ep.Value.Action.ActionType == ActionNames.CreateBatchAccountTransactionDocument)
{
var documentName = ep.Value.GetAsString("AccountTransactionDocumentName");
_accountService.CreateBatchAccountTransactionDocument(documentName);
}

if (ep.Value.Action.ActionType == ActionNames.CreateAccountTransaction)
{
var ticket = ep.Value.GetDataValue<Ticket>("Ticket");
Expand Down
8 changes: 4 additions & 4 deletions Samba.Modules.EntityModule/EntityEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using Samba.Domain.Models.Entities;
using Samba.Localization.Properties;
using Samba.Persistance.Data;
using Samba.Presentation.Common;
using Samba.Presentation.Common.Commands;
using Samba.Presentation.Services;
Expand All @@ -20,19 +19,21 @@ public class EntityEditorViewModel : ObservableObject
private readonly IUserService _userService;
private readonly ITicketServiceBase _ticketServiceBase;
private readonly IApplicationState _applicationState;
private readonly IEntityService _entityService;
public ICaptionCommand SaveEntityCommand { get; set; }
public ICaptionCommand SelectEntityCommand { get; set; }
public ICaptionCommand CreateAccountCommand { get; set; }

[ImportingConstructor]
public EntityEditorViewModel(ICacheService cacheService, IAccountService accountService, IUserService userService,
ITicketServiceBase ticketServiceBase, IApplicationState applicationState)
ITicketServiceBase ticketServiceBase, IApplicationState applicationState, IEntityService entityService)
{
_cacheService = cacheService;
_accountService = accountService;
_userService = userService;
_ticketServiceBase = ticketServiceBase;
_applicationState = applicationState;
_entityService = entityService;
SaveEntityCommand = new CaptionCommand<string>(Resources.Save, OnSaveEntity, CanSelectEntity);
SelectEntityCommand = new CaptionCommand<string>(string.Format(Resources.Select_f, Resources.Entity).Replace(" ", "\r"), OnSelectEntity, CanSelectEntity);
CreateAccountCommand = new CaptionCommand<string>(string.Format(Resources.Create_f, Resources.Account).Replace(" ", "\r"), OnCreateAccount, CanCreateAccount);
Expand Down Expand Up @@ -91,7 +92,7 @@ private void OnSaveEntity(string obj)
private void SaveSelectedEntity()
{
CustomDataViewModel.Update();
Dao.Save(SelectedEntity.Model);
_entityService.SaveEntity(SelectedEntity.Model);
}

private EntityOperationRequest<Entity> _operationRequest;
Expand All @@ -104,7 +105,6 @@ private void OnEditEntity(EventParameters<EntityOperationRequest<Entity>> obj)
var entityType = _cacheService.GetEntityTypeById(obj.Value.SelectedEntity.EntityTypeId);
SelectedEntity = new EntitySearchResultViewModel(obj.Value.SelectedEntity, entityType);
CustomDataViewModel = new EntityCustomDataViewModel(obj.Value.SelectedEntity, entityType);
//SelectedEntity.UpdateDetailedInfo();
RaisePropertyChanged(() => CustomDataViewModel);
RaisePropertyChanged(() => IsEntitySelectorVisible);
}
Expand Down
82 changes: 79 additions & 3 deletions Samba.Modules.EntityModule/EntityModule.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.Practices.Prism.MefExtensions.Modularity;
using Microsoft.Practices.Prism.Regions;
using Samba.Domain.Models;
using Samba.Domain.Models.Entities;
using Samba.Domain.Models.Tickets;
using Samba.Localization.Properties;
using Samba.Presentation.Common;
using Samba.Presentation.Common.ModelBase;
using Samba.Presentation.Controls.Interaction;
using Samba.Presentation.Services;
using Samba.Presentation.Services.Common;
using Samba.Services;
using Samba.Services.Common;

namespace Samba.Modules.EntityModule
{
Expand All @@ -17,23 +20,34 @@ class EntityModule : ModuleBase
{
private readonly IRegionManager _regionManager;
private readonly IApplicationStateSetter _applicationStateSetter;
private readonly ICacheService _cacheService;
private readonly IAccountService _accountService;
private readonly EntityEditorView _entityEditorView;
private readonly EntitySwitcherView _entitySwitcherView;
private readonly IEntityService _entityService;
private readonly IEntityServiceClient _entityServiceClient;

[ImportingConstructor]
public EntityModule(IRegionManager regionManager,
IUserService userService, IApplicationStateSetter applicationStateSetter,
EntitySwitcherView entitySwitcherView,
IUserService userService, IApplicationStateSetter applicationStateSetter, ICacheService cacheService, IAccountService accountService,
EntitySwitcherView entitySwitcherView, IAutomationService automationService, IEntityService entityService, IEntityServiceClient entityServiceClient,
EntityEditorView entityEditorView)
{
_entitySwitcherView = entitySwitcherView;
_entityService = entityService;
_entityServiceClient = entityServiceClient;
_entityEditorView = entityEditorView;
_regionManager = regionManager;
_applicationStateSetter = applicationStateSetter;
_cacheService = cacheService;
_accountService = accountService;

AddDashboardCommand<EntityCollectionViewModelBase<EntityTypeViewModel, EntityType>>(Resources.EntityType.ToPlural(), Resources.Entities, 40);
AddDashboardCommand<EntityCollectionViewModelBase<EntityViewModel, Entity>>(Resources.Entity.ToPlural(), Resources.Entities, 40);
AddDashboardCommand<EntityCollectionViewModelBase<EntityScreenViewModel, EntityScreen>>(Resources.EntityScreen.ToPlural(), Resources.Entities, 41);

automationService.RegisterActionType(ActionNames.CreateEntity, string.Format(Resources.Create_f, Resources.Entity), new { EntityTypeName = "", EntityName = "", CreateAccount = false });
automationService.RegisterActionType(ActionNames.UpdateEntityState, Resources.UpdateEntityState, new { EntityTypeName = "", EntityStateName = "", CurrentState = "", EntityState = "", QuantityExp = "" });
}

protected override void OnInitialization()
Expand All @@ -54,6 +68,68 @@ protected override void OnInitialization()
{
if (x.Topic == EventTopicNames.SelectEntity) ActivateEntitySwitcher();
});

EventServiceFactory.EventService.GetEvent<GenericEvent<ActionData>>().Subscribe(OnActionData);
}

private void OnActionData(EventParameters<ActionData> actionData)
{
if (actionData.Value.Action.ActionType == ActionNames.CreateEntity)
{
var entityTypeName = actionData.Value.GetAsString("EntityTypeName");
var entityName = actionData.Value.GetAsString("EntityName");
var createAccount = actionData.Value.GetAsBoolean("CreateAccount");
var customData = actionData.Value.GetAsString("CustomData");
if (!string.IsNullOrEmpty(entityTypeName) && !string.IsNullOrEmpty(entityName))
{
var entityType = _cacheService.GetEntityTypeByName(entityTypeName);
var entity = _entityService.CreateEntity(entityType.Id, entityName);
if (customData.Contains(":"))
{
foreach (var parts in customData.Split('#').Select(data => data.Split('=')))
entity.SetCustomData(parts[0], parts[1]);
}
if (createAccount)
{
var accountName = entityType.GenerateAccountName(entity);
var accountId = _accountService.CreateAccount(entityType.AccountTypeId, accountName);
entity.AccountId = accountId;
actionData.Value.DataObject.AccountName = accountName;
}
_entityService.SaveEntity(entity);
actionData.Value.DataObject.EntityName = entity.Name;
}
}

if (actionData.Value.Action.ActionType == ActionNames.UpdateEntityState)
{
var entityId = actionData.Value.GetDataValueAsInt("EntityId");
var entityTypeId = actionData.Value.GetDataValueAsInt("EntityTypeId");
var stateName = actionData.Value.GetAsString("EntityStateName");
var state = actionData.Value.GetAsString("EntityState");
var quantityExp = actionData.Value.GetAsString("QuantityExp");
if (state != null)
{
if (entityId > 0 && entityTypeId > 0)
{
_entityServiceClient.UpdateEntityState(entityId, entityTypeId, stateName, state, quantityExp);
}
else
{
var ticket = actionData.Value.GetDataValue<Ticket>("Ticket");
if (ticket != null)
{
var entityTypeName = actionData.Value.GetAsString("EntityTypeName");
foreach (var ticketEntity in ticket.TicketEntities)
{
var entityType = _cacheService.GetEntityTypeById(ticketEntity.EntityTypeId);
if (string.IsNullOrEmpty(entityTypeName.Trim()) || entityType.Name == entityTypeName)
_entityServiceClient.UpdateEntityState(ticketEntity.EntityId, ticketEntity.EntityTypeId, stateName, state, quantityExp);
}
}
}
}
}
}

private void ActivateEntityEditor()
Expand Down
2 changes: 1 addition & 1 deletion Samba.Modules.PosModule/PosViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private void CloseTicket()

public string GetPrintError()
{
if (SelectedTicket.Orders.Count(x => x.Price == 0 && x.CalculatePrice) > 0)
if (SelectedTicket.Orders.Any(x => x.GetValue() == 0 && x.CalculatePrice))
return Resources.CantCompleteOperationWhenThereIsZeroPricedProduct;
if (!SelectedTicket.IsClosed && SelectedTicket.Orders.Count > 0)
{
Expand Down
1 change: 1 addition & 0 deletions Samba.Persistance/IAccountDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface IAccountDao
string GetEntityCustomDataByAccountId(int accountId);
AccountTransactionDocument CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, decimal exchangeRate, IEnumerable<Account> accounts);
Account GetAccountById(int accountId);
Account GetAccountByName(string accountName);
bool GetIsAccountNameExists(string accountName);
int CreateAccount(int accountTypeId, string accountName);
string GetAccountNameById(int accountId);
Expand Down
1 change: 1 addition & 0 deletions Samba.Persistance/IEntityDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public interface IEntityDao
List<Entity> FindEntities(EntityType entityType, string fieldName, string searchValue, string stateFilter);
EntityStateValue UpdateEntityState(int entityId, string stateName, string state, string quantityExp);
Entity GetEntityById(int id);
void SaveEntity(Entity entity);
}
}
5 changes: 5 additions & 0 deletions Samba.Persistance/Implementations/AccountDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public Account GetAccountById(int accountId)
return Dao.Single<Account>(x => x.Id == accountId);
}

public Account GetAccountByName(string accountName)
{
return Dao.Single<Account>(x => x.Name == accountName);
}

public bool GetIsAccountNameExists(string accountName)
{
return Dao.Exists<Account>(x => x.Name == accountName);
Expand Down
5 changes: 5 additions & 0 deletions Samba.Persistance/Implementations/EntityDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,10 @@ public Entity GetEntityById(int id)
{
return Dao.Single<Entity>(x => x.Id == id);
}

public void SaveEntity(Entity entity)
{
Dao.Save(entity);
}
}
}
4 changes: 3 additions & 1 deletion Samba.Presentation.Services/Common/EventTopicNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class ActionNames
public const string DisplayTicket = "DisplayTicket";
public const string DisplayPaymentScreen = "DisplayPaymentScreen";
public const string CreateAccountTransactionDocument = "CreateAccountTransactionDocument";
public const string CreateBatchAccountTransactionDocument = "CreateBatchAccountTransactionDocument";
public const string AddOrder = "AddOrder";
public const string SendEmail = "SendEmail";
public const string ExecutePowershellScript = "ExecutePowershellScript";
Expand All @@ -37,7 +38,8 @@ public static class ActionNames
public const string MarkTicketAsClosed = "MarkTicketAsClosed";
public const string LoadTicket = "LoadTicket";
public const string LoopValues = "LoopValues";
public static string PrintAccountTransactionDocument = "PrintAccountTransactionDocument";
public const string PrintAccountTransactionDocument = "PrintAccountTransactionDocument";
public const string CreateEntity = "CreateEntity";
}

public static class RuleEventNames
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.Composition;
using Samba.Domain.Models.Entities;
using Samba.Persistance;
using Samba.Presentation.Services.Common;
using Samba.Services;
Expand Down Expand Up @@ -33,5 +34,6 @@ public void UpdateEntityState(int entityId, int entityTypeId, string stateName,
Quantity = sv.GetStateQuantity(stateName)
});
}

}
}
17 changes: 7 additions & 10 deletions Samba.Presentation.ViewModels/AccountBalances.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@ public AccountBalances(IApplicationState applicationState,ICacheService cacheSer
Balances = new Dictionary<int, decimal>();
}

private Ticket _selectedTicket;
public Ticket SelectedTicket
{
get { return _selectedTicket; }
set
{
_selectedTicket = value;
UpdateBalances();
}
}
public Ticket SelectedTicket { get; set; }

private void UpdateBalances()
{
Expand All @@ -46,6 +37,12 @@ private void UpdateBalances()
if (_applicationState.GetPaymentScreenPaymentTypes().Any(x => x.AccountTransactionType.TargetAccountTypeId == entityType.AccountTypeId))
{
var balance = _accountService.GetAccountBalance(ticketEntity.AccountId);
balance +=
SelectedTicket.Payments.Where(
x =>
x.Id == 0 &&
x.AccountTransaction.AccountTransactionValues.Any(
y => y.AccountId == ticketEntity.AccountId)).Sum(x=>x.Amount);
Balances.Add(ticketEntity.AccountId, balance);
}
}
Expand Down
Loading

0 comments on commit 8e21d72

Please sign in to comment.