private MoneyAction IncomeTrasactionForClient(InnerTransactionInsertDto dto, int mainCompayId, DateTime date, IncomeTransactionCollection incomeTransactionCollection) { int branchId = BranchHelper.Id; int treasuryId = _appSession.GetCurrentTreasuryId(); var transaction = new Transaction(); transaction.Reason = ""; transaction.SenderClient = GetClient(dto.Sender); transaction.SenderBranchId = branchId; transaction.ReceiverBranchId = branchId; transaction.TreaseryId = treasuryId; transaction.IncomeTransactionCollection = incomeTransactionCollection; switch (dto.TypeOfPay) { case TypeOfPay.Cash: { transaction.ReciverClient = GetClient(dto.ReciverClinet); transaction.TypeOfPay = TypeOfPay.Cash; transaction.Deliverd = false; } break; case TypeOfPay.ClientsReceivables: { transaction.ReciverClientId = dto.AgentId; transaction.ReciverClientCommission = dto.AgentCommission; transaction.TypeOfPay = TypeOfPay.ClientsReceivables; transaction.Deliverd = true; } break; case TypeOfPay.CompaniesReceivables: { transaction.SenderCompanyId = dto.ReciverCompany.CompanyId; transaction.SenderCompanyComission = dto.ReciverCompany.CompanyCommission; transaction.ReciverClient = GetClient(dto.ReciverCompany.ReciverClinet); transaction.TypeOfPay = TypeOfPay.CompaniesReceivables; transaction.Deliverd = true; } break; } transaction.CoinId = dto.CoinId; transaction.ReceiverCompanyId = mainCompayId; transaction.Amount = dto.Amount; transaction.TransactionType = TransactionType.ImportTransaction; //transaction.Note = note; transaction.OurComission = dto.OurComission; transaction.TransactionsStatus = TransactionStatus.NotNotified; transaction.CreatedBy = _appSession.GetUserName(); _unitOfWork.GenericRepository <Transaction>().Insert(transaction); var moneyAction = new MoneyAction(); moneyAction.Transaction = transaction; moneyAction.Date = date; moneyAction.CreatedBy = _appSession.GetUserName(); _unitOfWork.GenericRepository <MoneyAction>().Insert(moneyAction); return(moneyAction); }
public static string GetNote(this MoneyAction moneyAction, Requester requester, int?objectId) { if (moneyAction.TransactionId != null) { return(moneyAction.Transaction.Note); } //if (moneyAction.PublicMoney != null&&moneyAction.BoxAction!=null) // return ""; //return "none"; if (moneyAction.BoxAction != null) { if (moneyAction.PubLicMoneyId == null) { return(moneyAction.BoxAction.Note); } else { return(moneyAction.BoxAction.Note + "/" + moneyAction.PublicMoney.GetActionName()); } } if (moneyAction.ClearingId != null) { return(moneyAction.Clearing.GetNote(requester, (int)objectId)); } return("GetNoteMoenyAction"); }
public string GetActionName(MoneyAction moneyAction) { try { if (moneyAction.Transaction != null && moneyAction.BoxAction == null) { return(moneyAction.Transaction.GetActionName()); } if (moneyAction.PublicMoney != null) { return(moneyAction.PublicMoney.GetActionName()); } if (moneyAction.BoxAction != null) { if (moneyAction.ClientCashFlows != null && moneyAction.ClientCashFlows.Count > 0) { return(new List <ClientCashFlow>(moneyAction.ClientCashFlows)[0].Client.FullName); } return(new List <CompanyCashFlow>(moneyAction.CompanyCashFlows)[0].CompanyName()); } if (moneyAction.Exchange != null) { return(_unitOfWork.GenericRepository <Coin>().GetById(moneyAction.Exchange.SecoundCoinId).Name); } } catch (Exception ex) { Tracing.SaveException(ex); } return("GetActionName"); }
public static string CreateBy(this MoneyAction moneyAction) { if (moneyAction.Transaction != null) { return(moneyAction.Transaction.CreateBy()); } return(moneyAction.CreatedBy); }
public static decimal SecounCompanyCommission(this MoneyAction moneyAction, int companyId) { if (moneyAction.Transaction != null) { return(moneyAction.Transaction.SecounCompanyCommission(companyId)); } return(0); }
public static string CountryName(this MoneyAction moneyAction) { if (moneyAction.Transaction != null) { if (moneyAction.Transaction.Country != null) { return(moneyAction.Transaction.Country.Name); } } return(""); }
public static decimal?OurCommission(this MoneyAction moneyAction) { if (moneyAction.BoxActionsId != null) { return(null); } if (moneyAction.Transaction != null) { return(moneyAction.Transaction.OurComission); } return(null); }
public static decimal ClientComission(this MoneyAction moneyAction, int clientId) { if (moneyAction.BoxActionsId != null) { return(0); } if (moneyAction.Transaction != null) { return(moneyAction.Transaction.ClientCommission(clientId: clientId)); } return(0); }
public static string ReciverName(this MoneyAction moneyAction, Requester requester, int requeserId) { if (moneyAction.TransactionId != null) { return(moneyAction.Transaction.ReceiverName()); } if (moneyAction.Clearing != null) { return(moneyAction.Clearing.ReciverName(requester, requeserId)); } return(""); }
public static string GetTypeName(this MoneyAction moneyAction, Requester requester, int?objectId) { if (moneyAction.BoxAction != null) { if (requester == Requester.Branch && moneyAction.PubLicMoneyId != null) { if (moneyAction.BoxAction.IsIncmoe) { return("قبض"); } return("صرف"); } if (moneyAction.Clearing == null && moneyAction.PubLicMoneyId == null && requester != Requester.Branch) { if (moneyAction.BoxAction.IsIncmoe) { return("قبض"); } return("صرف"); } else if (moneyAction.ClearingId != null) { return(moneyAction.Clearing.GetTypeName(requester, (int)objectId)); } else if (moneyAction.PubLicMoneyId != null) { return(moneyAction.BoxAction.IsIncmoe ? "صرف له" : "قبض منه"); } return(moneyAction.BoxAction.IsIncmoe ? "قبض" : "صرف"); } if (moneyAction.TransactionId != null) { return(moneyAction.Transaction.GetTypeName(requester, objectId)); } if (moneyAction.PublicMoney != null) { return(moneyAction.PublicMoney.GetTypeName()); } //get Company or ClientName if (moneyAction.ExchangeId != null) { var unitOfWork = new UnitOfWork <MainContext>(); var repository = new GenericRepository <Coin>(unitOfWork); return(repository.GetById(moneyAction.Exchange.FirstCoinId).Name); } if (moneyAction.ClearingId != null) { return(moneyAction.Clearing.GetTypeName(requester, (int)objectId)); } return("GetTypeName"); }
private void AddClientCashFlow(InnerTransactionUpdateDto dto, MoneyAction moneyAction) { var clientCashFlow = new ClientCashFlow() { ClientId = dto.AgentId, CoinId = dto.CoinId, Amount = dto.Amount, Matched = false, MoenyAction = moneyAction }; _unitOfWork.GenericRepository <ClientCashFlow>().Insert(clientCashFlow); }
private void AddCompanyCashFlow(InnerTransactionUpdateDto dto, MoneyAction moneyAction) { var companyCahsFlow = new CompanyCashFlow() { MoenyAction = moneyAction, Amount = dto.Amount + dto.SenderCompany.CompanyCommission, Matched = false, CompanyId = dto.SenderCompany.CompanyId, CoinId = dto.CoinId, CreatedBy = _appSession.GetUserName() }; _unitOfWork.GenericRepository <CompanyCashFlow>().Insert(companyCahsFlow); }
public static string GetDate(this MoneyAction moneyAction) { if (moneyAction.Transaction != null) { if (moneyAction.Transaction.Deliverd != null) { if ((bool)moneyAction.Transaction.Deliverd) { return(((DateTime)moneyAction.Transaction.DeliverdDate).ToString("dd/MM/yyyy", new CultureInfo("ar-AE"))); } } } return(moneyAction.Created.Value.ToString("dd/MM/yyyy", new CultureInfo("ar-AE"))); }
public static string SenderName(this MoneyAction moneyAction, Requester requester, int requeserId) { if (moneyAction.TransactionId != null) { return(moneyAction.Transaction.SenderName()); } if (moneyAction.Clearing != null) { return(moneyAction.Clearing.GetSenderName(requester, (int)requeserId)); } if (moneyAction.PubLicMoneyId != null) { return(moneyAction.PublicMoney.GetActionName()); } return(""); }
private void EditMaiCompanyBalanceArbitrage(InnerTransactionUpdateDto dto, MoneyAction moneyAction) { var oldCompanyCashFlow = _unitOfWork.GenericRepository <CompanyCashFlow>() .FindBy(x => x.CoinId == dto.CoinId && x.MoneyActionId == moneyAction.Id).FirstOrDefault(); if (oldCompanyCashFlow != null) { _unitOfWork.GenericRepository <CompanyCashFlow>().Delete(oldCompanyCashFlow); } var companyCashFlow = new CompanyCashFlow() { CoinId = dto.CoinId, CompanyId = dto.MainCompanyId, Amount = -dto.Amount, Matched = false, MoenyAction = moneyAction }; _unitOfWork.GenericRepository <CompanyCashFlow>().Insert(companyCashFlow); }
private void DeleteOldCashFlow(MoneyAction moneyAction) { //Old Company Cash Flows var oldCompanyCashFlows = moneyAction.CompanyCashFlows.ToList(); foreach (var oldCompanyCashFlow in oldCompanyCashFlows) { _unitOfWork.GenericRepository <CompanyCashFlow>().Delete(oldCompanyCashFlow); } //Old Client Cash Flows var oldClientCashFlows = moneyAction.ClientCashFlows.ToList(); foreach (var oldClientCashFlow in oldClientCashFlows) { _unitOfWork.GenericRepository <ClientCashFlow>().Delete(oldClientCashFlow); } //Old Branch Cash Flows var oldBranchCashFlows = moneyAction.BranchCashFlows.ToList(); var oldBranchCashFlowsIds = oldBranchCashFlows.Select(b => b.Id).ToList(); if (oldBranchCashFlows.Any()) { var oldTreasuryMoneyActions = _unitOfWork.GenericRepository <TreasuryMoneyAction>() .FindBy(x => oldBranchCashFlowsIds.Contains((int)x.BranchCashFlowId)).ToList(); foreach (var oldTreasuryMoneyAction in oldTreasuryMoneyActions) { _unitOfWork.GenericRepository <TreasuryMoneyAction>().Delete(oldTreasuryMoneyAction); } foreach (var oldBranchCashFlow in oldBranchCashFlows) { _unitOfWork.GenericRepository <BranchCashFlow>().Delete(oldBranchCashFlow); } } _unitOfWork.GenericRepository <MoneyAction>().Update(moneyAction); }
private void AgentBalnaceArbitrage(InnerTransactionInsertDto dto, MoneyAction moneyAction) { var clientCash = _unitOfWork.GenericRepository <ClientCash>() .FindBy(c => c.CoinId == dto.CoinId && c.ClientId == dto.AgentId) .FirstOrDefault(); clientCash.Total += dto.Amount; clientCash.Total += dto.AgentCommission; clientCash.ModifiedBy = _appSession.GetUserName(); _unitOfWork.GenericRepository <ClientCash>().Update(clientCash); var clientCashFlow = new ClientCashFlow() { ClientId = dto.AgentId, CoinId = dto.CoinId, Total = clientCash.Total, Amount = dto.Amount, Matched = false, MoenyAction = moneyAction }; _unitOfWork.GenericRepository <ClientCashFlow>().Insert(clientCashFlow); }
public static int?GetActionId(this MoneyAction moneyAction) { if (moneyAction.TransactionId != null) { return((int)moneyAction.TransactionId); } //if (moneyAction.PublicMoney != null) // return null; //return -1; if (moneyAction.BoxAction != null) { return(moneyAction.BoxAction.Id); } if (moneyAction.Exchange != null) { return(moneyAction.Exchange.Id); } if (moneyAction.ClearingId != null) { return(moneyAction.ClearingId); } return(-1); }
private void CompanyBlanceArbitrage(InnerTransactionInsertDto dto, MoneyAction moneyAction) { var companyCah = _unitOfWork.GenericRepository <CompanyCash>() .FindBy(c => c.CoinId == dto.CoinId && c.CompanyId == dto.ReciverCompany.CompanyId) .FirstOrDefault(); companyCah.Total += dto.Amount; companyCah.Total += dto.ReciverCompany.CompanyCommission; companyCah.ModifiedBy = _appSession.GetUserName(); _unitOfWork.GenericRepository <CompanyCash>().Update(companyCah); var companyCahsFlow = new CompanyCashFlow() { MoenyAction = moneyAction, Total = companyCah.Total, Amount = dto.Amount + dto.ReciverCompany.CompanyCommission, Matched = false, CompanyId = dto.ReciverCompany.CompanyId, CoinId = dto.CoinId, CreatedBy = _appSession.GetUserName() }; _unitOfWork.GenericRepository <CompanyCashFlow>().Insert(companyCahsFlow); }
/// <summary> /// Tworzy obiekt Akcji na podstawie informacji zawartych w ActionStringu(Nazwa klasy + lista zmiennych) /// </summary> /// <param name="form">Obiekt przechowujący informacje o ActionCardzie</param> /// <returns></returns> public static ActionCard Create(ActionString form) { ActionCard card = null; switch (form.actionType) { case ActionType.Money: { MoneyAction.MoneyActor payer = (MoneyAction.MoneyActor)Enum.Parse(typeof(MoneyAction.MoneyActor), form.variables[0]); MoneyAction.MoneyActor receiver = (MoneyAction.MoneyActor)Enum.Parse(typeof(MoneyAction.MoneyActor), form.variables[1]); float value = float.Parse(form.variables[2]); card = new MoneyAction(payer, receiver, value); } break; case ActionType.Wait: { WaitAction.WaitActor target = (WaitAction.WaitActor)Enum.Parse(typeof(WaitAction.WaitActor), form.variables[0]); int rounds = int.Parse(form.variables[1]); card = new WaitAction(target, rounds); } break; case ActionType.Move: { MoveAction.Mode mode = (MoveAction.Mode)Enum.Parse(typeof(MoveAction.Mode), form.variables[0]); int byAmount = int.Parse(form.variables[1]); MoveAction.ToTarget toTarget = (MoveAction.ToTarget)Enum.Parse(typeof(MoveAction.ToTarget), form.variables[2]); int targetId = int.Parse(form.variables[3]); MoveAction.PlaceTypeTarget targetType = (MoveAction.PlaceTypeTarget)Enum.Parse(typeof(MoveAction.PlaceTypeTarget), form.variables[4]); MoveAction.MovementType movementType = (MoveAction.MovementType)Enum.Parse(typeof(MoveAction.MovementType), form.variables[5]); card = new MoveAction(mode, byAmount, toTarget, targetId, targetType, movementType); } break; case ActionType.WithUser: { ActionType insideType = (ActionType)Enum.Parse(typeof(ActionType), form.variables[0]); if (insideType != ActionType.WithUser) { ActionString insideActionString = ActionString.FromString(form.variables[(int)insideType + 1]); ActionCard insideAction = Create(insideActionString); card = new WithUserAction(insideAction); } else { Debug.LogError("Nie można zagnieżdzać typu WithUser w akcji typu WithUser"); } } break; case ActionType.Imprison: { card = new ImprisonAction(); } break; } return(card); }
private void MaiCompanyBalanceArbitrage(CompanyCash companyCash, InnerTransactionInsertDto dto, int mainCompanyId, MoneyAction moneyAction) { companyCash.Total -= (dto.Amount + dto.OurComission); companyCash.ModifiedBy = _appSession.GetUserName(); _unitOfWork.GenericRepository <CompanyCash>().Update(companyCash); var companyCahsFlow = new CompanyCashFlow() { CoinId = dto.CoinId, CompanyId = mainCompanyId, Total = companyCash.Total, Amount = -dto.Amount, Matched = false, MoenyAction = moneyAction }; _unitOfWork.GenericRepository <CompanyCashFlow>().Insert(companyCahsFlow); }
public bool ExchangeForBranch(int sellingCoinId, int purchasingCoinId, decimal firstAmount) { try { int treasuryId = _appSession.GetCurrentTreasuryId(); var secondCoinAmount = CalcForFirstCoin(sellingCoinId, purchasingCoinId, firstAmount); var mainCoin = _unitOfWork.GenericRepository <BranchCash>().FindBy(c => c.IsMainCoin == true).FirstOrDefault(); var firstCoinExchange = _unitOfWork.GenericRepository <BranchCash>().FindBy(c => c.CoinId == sellingCoinId).FirstOrDefault(); var secoundCoinExchange = _unitOfWork.GenericRepository <BranchCash>().FindBy(c => c.CoinId == purchasingCoinId).FirstOrDefault(); _unitOfWork.CreateTransaction(); var exchange = new Exchange() { BranchId = BranchHelper.Id, FirstCoinId = sellingCoinId, SecoundCoinId = purchasingCoinId, AmountOfFirstCoin = firstAmount, AmoutOfSecoundCoin = secondCoinAmount, MainCoinId = mainCoin.CoinId, FirstCoinExchangePriceWithMainCoin = firstCoinExchange.ExchangePrice, FirstCoinSellingPriceWithMainCoin = firstCoinExchange.SellingPrice, FirstCoinPurchasingPriceWithMainCoin = firstCoinExchange.PurchasingPrice, SecoundCoinExchangePriceWithMainCoin = secoundCoinExchange.ExchangePrice, SecoundCoinSellingPricWithMainCoin = secoundCoinExchange.SellingPrice, SecoundCoinPurchasingPriceWithMainCoin = secoundCoinExchange.PurchasingPrice }; _unitOfWork.GenericRepository <Exchange>().Insert(exchange); var branchCaches = _unitOfWork.GenericRepository <BranchCash>(); var branchCashSellingCoin = branchCaches.FindBy(c => c.CoinId == sellingCoinId).FirstOrDefault(); branchCashSellingCoin.Total -= firstAmount; _unitOfWork.GenericRepository <BranchCash>().Update(branchCashSellingCoin); var branchCashpurhesCoin = branchCaches.FindBy(c => c.CoinId == purchasingCoinId).FirstOrDefault(); branchCashpurhesCoin.Total += secondCoinAmount; _unitOfWork.GenericRepository <BranchCash>().Update(branchCashpurhesCoin); var moneyAction = new MoneyAction() { ExchangeId = exchange.Id }; _unitOfWork.GenericRepository <MoneyAction>().Insert(moneyAction); var branchCashFlowForFirstCoin = new BranchCashFlow() { BranchId = BranchHelper.Id, MoenyAction = moneyAction, CoinId = sellingCoinId, Total = branchCashSellingCoin.Total, Amount = -firstAmount, TreasuryId = treasuryId, }; _unitOfWork.GenericRepository <BranchCashFlow>().Insert(branchCashFlowForFirstCoin); var sellingCoinTreasuryCash = _unitOfWork.GenericRepository <TreasuryCash>().FindBy(C => C.TreasuryId == treasuryId && C.CoinId == sellingCoinId).FirstOrDefault(); sellingCoinTreasuryCash.Total -= firstAmount; _unitOfWork.GenericRepository <TreasuryCash>().Update(sellingCoinTreasuryCash); TreasuryMoneyAction sellingCoinTreasuryMoeyAction = new TreasuryMoneyAction() { Amount = -firstAmount, CoinId = sellingCoinId, TreasuryId = treasuryId, Total = sellingCoinTreasuryCash.Total, BranchCashFlow = branchCashFlowForFirstCoin, }; _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(sellingCoinTreasuryMoeyAction); var mainTreasuryId = _appSession.GetMainTreasury(); if (mainTreasuryId != treasuryId) { var mainTruseryMoneyAction = new TreasuryMoneyAction() { TreasuryId = mainTreasuryId, Amount = -firstAmount, CoinId = sellingCoinId, BranchCashFlow = branchCashFlowForFirstCoin, CreatedBy = _appSession.GetUserName() }; _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(mainTruseryMoneyAction); } var branChCashFlowForSecoundCoin = new BranchCashFlow() { BranchId = BranchHelper.Id, CoinId = purchasingCoinId, MonyActionId = moneyAction.Id, Total = branchCashpurhesCoin.Total, Amount = secondCoinAmount, TreasuryId = treasuryId, }; _unitOfWork.GenericRepository <BranchCashFlow>().Insert(branChCashFlowForSecoundCoin); var secoundCoinTreasuryCash = _unitOfWork.GenericRepository <TreasuryCash>().FindBy(C => C.TreasuryId == treasuryId && C.CoinId == sellingCoinId).FirstOrDefault(); secoundCoinTreasuryCash.Total += secondCoinAmount; _unitOfWork.GenericRepository <TreasuryCash>().Update(secoundCoinTreasuryCash); TreasuryMoneyAction secoundCoinTreasuryMoeyAction = new TreasuryMoneyAction() { Amount = +secondCoinAmount, CoinId = purchasingCoinId, TreasuryId = treasuryId, Total = secoundCoinTreasuryCash.Total, BranchCashFlow = branChCashFlowForSecoundCoin, }; _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(secoundCoinTreasuryMoeyAction); if (mainTreasuryId != treasuryId) { var mainTruseryMoneyActionSecoundCoin = new TreasuryMoneyAction() { TreasuryId = mainTreasuryId, Amount = +secondCoinAmount, BranchCashFlow = branChCashFlowForSecoundCoin, CoinId = purchasingCoinId, CreatedBy = _appSession.GetUserName() }; _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(mainTruseryMoneyActionSecoundCoin); } _unitOfWork.Save(); _unitOfWork.Commit(); return(true); } catch (Exception ex) { _unitOfWork.Rollback(); return(false); } }
public bool ExchangeForCompany(int companyId, int sellingCoinId, int purchasingCoinId, decimal firstAmount) { try { int treasuryId = _appSession.GetCurrentTreasuryId(); var secondCoinAmount = CalcForFirstCoin(sellingCoinId, purchasingCoinId, firstAmount); var mainCoin = _unitOfWork.GenericRepository <BranchCash>().FindBy(c => c.IsMainCoin == true).FirstOrDefault(); var firstCoinExchange = _unitOfWork.GenericRepository <CompanyCash>().FindBy(c => c.CoinId == sellingCoinId && c.CompanyId == companyId).FirstOrDefault(); var secoundCoinExchange = _unitOfWork.GenericRepository <CompanyCash>().FindBy(c => c.CoinId == purchasingCoinId && c.CompanyId == companyId).FirstOrDefault(); _unitOfWork.CreateTransaction(); var exchange = new Exchange() { BranchId = BranchHelper.Id, FirstCoinId = sellingCoinId, SecoundCoinId = purchasingCoinId, AmountOfFirstCoin = firstAmount, AmoutOfSecoundCoin = secondCoinAmount, MainCoinId = mainCoin.CoinId, }; _unitOfWork.GenericRepository <Exchange>().Insert(exchange); var companyCaches = _unitOfWork.GenericRepository <CompanyCash>().FindBy(c => c.CompanyId == companyId); var branchCashSellingCoin = companyCaches.Where(c => c.CoinId == sellingCoinId).FirstOrDefault(); branchCashSellingCoin.Total -= firstAmount; _unitOfWork.GenericRepository <CompanyCash>().Update(branchCashSellingCoin); var branchCashpurhesCoin = companyCaches.Where(c => c.CoinId == purchasingCoinId).FirstOrDefault(); branchCashpurhesCoin.Total += secondCoinAmount; _unitOfWork.GenericRepository <CompanyCash>().Update(branchCashpurhesCoin); var moneyAction = new MoneyAction() { ExchangeId = exchange.Id }; _unitOfWork.GenericRepository <MoneyAction>().Insert(moneyAction); var companyCashFlowForFirstCoin = new CompanyCashFlow() { CompanyId = companyId, MoenyAction = moneyAction, CoinId = sellingCoinId, Total = branchCashSellingCoin.Total, Amount = -firstAmount }; _unitOfWork.GenericRepository <CompanyCashFlow>().Insert(companyCashFlowForFirstCoin); var companyCashFlowForSecondCoin = new CompanyCashFlow() { CompanyId = companyId, CoinId = purchasingCoinId, MoenyAction = moneyAction, Total = branchCashpurhesCoin.Total, Amount = secondCoinAmount }; _unitOfWork.GenericRepository <CompanyCashFlow>().Insert(companyCashFlowForSecondCoin); _unitOfWork.Save(); _unitOfWork.Commit(); return(true); } catch (Exception ex) { _unitOfWork.Rollback(); return(false); } }