private async Task openCloseBox(string status) { CashTransfer cashTransfer = new CashTransfer(); cashTransfer.processType = "box"; cashTransfer.transType = status; cashTransfer.cash = MainWindow.posLogIn.balance; cashTransfer.createUserId = MainWindow.userID.Value; cashTransfer.posId = (int)MainWindow.posID; if (status == "o") { cashTransfer.transNum = await cashTransfer.generateCashNumber("bc"); } else { cashTransfer.transNum = await cashTransfer.getLastOpenTransNum((int)MainWindow.posID); } int res = await posModel.updateBoxState((int)MainWindow.posID, status, Convert.ToInt32(isAdmin), MainWindow.userLogin.userId, cashTransfer); if (res > 0) { await MainWindow.refreshBalance(); Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopUpdate"), animation: ToasterAnimation.FadeIn); } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } }
private void Btn_save_Click(object sender, RoutedEventArgs e) { try { if (!isPurchase && (invoice.paid >= invoice.totalNet || (hasCredit == true && creditValue > invoice.totalNet - invoice.paid) || (hasCredit == true && creditValue == 0))) { if (invoice.totalNet - invoice.paid > 0) { cashTrasnfer = new CashTransfer(); /////////////////////////////////////////////////// cashTrasnfer.agentId = invoice.agentId; cashTrasnfer.invId = invoice.invoiceId; cashTrasnfer.processType = "balance"; cashTrasnfer.cash = invoice.totalNet - invoice.paid; listPayments.Add(cashTrasnfer); } isOk = true; this.Close(); } else if (isPurchase && hasCredit == true) { if (listPayments.Where(x => x.processType == "cash").Count() > 0 && listPayments.Where(x => x.processType == "cash").FirstOrDefault().cash > MainWindow.posLogIn.balance) { isOk = false; Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopNotEnoughBalance"), animation: ToasterAnimation.FadeIn); } else { if (invoice.totalNet - invoice.paid > 0) { cashTrasnfer = new CashTransfer(); /////////////////////////////////////////////////// cashTrasnfer.agentId = invoice.agentId; cashTrasnfer.invId = invoice.invoiceId; cashTrasnfer.processType = "balance"; cashTrasnfer.cash = invoice.totalNet - invoice.paid; listPayments.Add(cashTrasnfer); } //lst_payments.Items.Add(s); /////////////////////////////////////////////////// isOk = true; this.Close(); } } else // if (invoice.paid < invoice.totalNet && hasCredit == false &&) { isOk = false; Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trAmountPaidEqualInvoiceValue"), animation: ToasterAnimation.FadeIn); } } catch (Exception ex) { SectionData.ExceptionMessage(ex, this); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { CashTransfer s = value as CashTransfer; string name = ""; switch (s.side) { case "bnd": break; case "v": name = MainWindow.resourcemanager.GetString("trVendor"); break; case "c": name = MainWindow.resourcemanager.GetString("trCustomer"); break; case "u": name = MainWindow.resourcemanager.GetString("trUser"); break; case "s": name = MainWindow.resourcemanager.GetString("trSalary"); break; case "e": name = MainWindow.resourcemanager.GetString("trGeneralExpenses"); break; case "m": if (s.transType == "d") { name = MainWindow.resourcemanager.GetString("trAdministrativeDeposit"); } if (s.transType == "p") { name = MainWindow.resourcemanager.GetString("trAdministrativePull"); } break; case "sh": name = MainWindow.resourcemanager.GetString("trShippingCompany"); break; default: break; } if (!string.IsNullOrEmpty(s.agentName)) { name = name + " " + s.agentName; } else if (!string.IsNullOrEmpty(s.usersName) && !string.IsNullOrEmpty(s.usersLName)) { name = name + " " + s.usersName + " " + s.usersLName; } else if (!string.IsNullOrEmpty(s.shippingCompanyName)) { name = name + " " + s.shippingCompanyName; } else if ((s.side != "e") && (s.side != "m")) { name = name + " " + MainWindow.resourcemanager.GetString("trUnKnown"); } return(name); }
private string GetOperationType(CashTransfer cashTransfer) { var fiatCurrencies = new[] { "USD", "EUR", "CHF", "GBP" }; if (fiatCurrencies.Contains(cashTransfer.AssetId)) { return(cashTransfer.Fees != null && cashTransfer.Fees.Any() ? "CardCashIn" : "SwiftTransfer"); } return("CryptoCashIn"); }
private async Task confirmOpr(CashTransfer cashtrans) { cashtrans.isConfirm = 1; int s = await cashModel.Save(cashtrans); if (!s.Equals(0)) { await fillDataGrid(); Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopConfirm"), animation: ToasterAnimation.FadeIn); } }
private async Task recordCash(Invoice invoice) { User user = new User(); float newBalance = 0; user = await user.getUserById((int)cb_user.SelectedValue); CashTransfer cashTrasnfer = new CashTransfer(); cashTrasnfer.posId = MainWindow.posID; cashTrasnfer.userId = (int)cb_user.SelectedValue; cashTrasnfer.invId = invoice.invoiceId; cashTrasnfer.createUserId = invoice.createUserId; cashTrasnfer.processType = "balance"; cashTrasnfer.side = "u"; // user cashTrasnfer.transType = "d"; //deposit cashTrasnfer.transNum = await cashTrasnfer.generateCashNumber("du"); if (user.balanceType == 0) { if (invoice.totalNet <= (decimal)user.balance) { invoice.paid = invoice.totalNet; invoice.deserved = 0; newBalance = user.balance - (float)invoice.totalNet; user.balance = newBalance; } else { invoice.paid = (decimal)user.balance; invoice.deserved = invoice.totalNet - (decimal)user.balance; newBalance = (float)invoice.totalNet - user.balance; user.balance = newBalance; user.balanceType = 1; } cashTrasnfer.cash = invoice.paid; await invoice.saveInvoice(invoice); await cashTrasnfer.Save(cashTrasnfer); //add cash transfer await user.save(user); } else if (user.balanceType == 1) { newBalance = user.balance + (float)invoice.totalNet; user.balance = newBalance; await user.save(user); } }
public void Handle(ICommandContext context, CreateCashTransferCommand command) { var cashTransfer = new CashTransfer( command.AggregateRootId, command.WalletId, command.Number, new CashTransferInfo(command.Amount, command.Fee, command.Direction, command.Remark), command.Type, command.Status); context.Add(cashTransfer); }
/// <summary> /// 接受新的现金记录 更新统计信息 /// </summary> /// <param name="reply"></param> public void AcceptNewCashTransfer(CashTransfer cashTransfer) { var finallyValue = _cash; //业务逻辑判断 CashTransferInfo cashTransferInfo = cashTransfer.GetInfo(); //统计信息 var walletStatisticInfo = _walletStatisticInfo; if (cashTransferInfo.Direction == WalletDirection.Out) { if (_isFreeze) { throw new Exception("钱包冻结,无法出账"); } //如果是出账 判断账号余额是否够 if (_cash < cashTransferInfo.Amount) { throw new Exception("账户余额不足"); } finallyValue -= cashTransferInfo.Amount; } else { //进账 判断收益 if (cashTransfer.GetTransferType() == CashTransferType.Incentive) { //善心激励 if (_walletStatisticInfo.UpdatedOn.Date.Equals(DateTime.Now.Date)) { //非第一个 walletStatisticInfo.YesterdayEarnings += cashTransferInfo.Amount; } else { //今日第一个 walletStatisticInfo.YesterdayEarnings = cashTransferInfo.Amount; } walletStatisticInfo.Earnings += cashTransferInfo.Amount; walletStatisticInfo.UpdatedOn = DateTime.Now; } finallyValue += cashTransferInfo.Amount; } finallyValue = Math.Round(finallyValue, 2); //新的记录接受后,发出新记录接受的事件 ApplyEvent(new NewCashTransferAcceptedEvent(_userId, cashTransfer.Id, finallyValue, walletStatisticInfo)); }
private async Task transfer() { //add cash transfer CashTransfer cash1 = new CashTransfer(); cash1.transType = "p";//pull cash1.transNum = await cash1.generateCashNumber(cash1.transType + "p"); cash1.cash = MainWindow.posLogIn.balance; cash1.createUserId = MainWindow.userID.Value; cash1.posIdCreator = MainWindow.posID.Value; cash1.isConfirm = 1; cash1.side = "p";//pos cash1.posId = Convert.ToInt32(MainWindow.posID.Value); int s1 = await cash1.Save(cash1); if (!s1.Equals(0)) { //second operation CashTransfer cash2 = new CashTransfer(); cash2.transType = "d";//deposite cash2.transNum = await cash2.generateCashNumber(cash2.transType + "p"); cash2.cash = MainWindow.posLogIn.balance; cash2.createUserId = MainWindow.userID.Value; cash2.posIdCreator = MainWindow.posID.Value; cash2.isConfirm = 0; cash2.side = "p"; //pos cash2.posId = Convert.ToInt32(cb_pos.SelectedValue); cash2.cashTransIdSource = s1; //id from first operation int s2 = await cash2.Save(cash2); if (s2 > 0) { Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopAdd"), animation: ToasterAnimation.FadeIn); } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } } }
public async Task <int> updateBoxState(int posId, string state, int isAdminClose, int userId, CashTransfer cashTransfer) { Dictionary <string, string> parameters = new Dictionary <string, string>(); string method = "Pos/updateBoxState"; parameters.Add("posId", posId.ToString()); parameters.Add("state", state); parameters.Add("isAdminClose", isAdminClose.ToString()); parameters.Add("userId", userId.ToString()); var myContent = JsonConvert.SerializeObject(cashTransfer); parameters.Add("cashTransfer", myContent); return(await APIResult.post(method, parameters)); }
public async Task <IActionResult> Transfer(DepositCommand deposit) { _Logger.LogInformation("Starting Transfer"); Currency c = _TransactionDbContext.Currencies.SingleOrDefault(c => c.Symbol.ToUpper() == deposit.Currency.ToUpper()); if (c == null) { c = new Currency() { Symbol = deposit.Currency.ToUpper() }; _TransactionDbContext.Currencies.Add(c); } string token = this.Request.Headers["Authorization"].ToString().Substring("Bearer ".Length); _AccountsService.Authenticate(token); AccountInfo account = await _AccountsService.GetAsync(deposit.AccountId); _Logger.LogInformation($"Transfer money to {account.Name}"); if (deposit.Currency != account.Currency) { return(BadRequest("Deposit currency and account currency do not match")); } CashTransfer cashTransfer = new CashTransfer(); cashTransfer.Currency = c; cashTransfer.Date = deposit.Date; cashTransfer.Amount = deposit.Amount; cashTransfer.AccountId = account.Id; _TransactionDbContext.Add(cashTransfer); _TransactionDbContext.SaveChangesAsync(); if (deposit.Amount > 0) { _Bus.SendAsync(new CashDepositedEvent() { AccountId = deposit.AccountId, Amount = deposit.Amount, Currency = deposit.Currency, Date = deposit.Date, Id = Guid.NewGuid(), }); } else { _Bus.SendAsync(new CashWithdrawnEvent() { AccountId = deposit.AccountId, Amount = Math.Abs(deposit.Amount), Currency = deposit.Currency, Date = deposit.Date, Id = Guid.NewGuid(), }); } return(StatusCode(StatusCodes.Status201Created)); }
private void Btn_enter_Click(object sender, RoutedEventArgs e) { try { tb_cash.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#f8f8f8")); p_errorCash.Visibility = Visibility.Collapsed; //listPayments string s = ""; cashTrasnfer = new CashTransfer(); try { cashTrasnfer.cash = decimal.Parse(tb_cash.Text); } catch { cashTrasnfer.cash = 0; } if (cashTrasnfer.cash > 0) { if (cashTrasnfer.cash + invoice.paid <= invoice.totalNet) { cashTrasnfer.agentId = invoice.agentId; cashTrasnfer.invId = invoice.invoiceId; cashTrasnfer.processType = cb_paymentProcessType.SelectedValue.ToString(); if (cb_paymentProcessType.SelectedValue.ToString().Equals("cash")) { //s = cb_paymentProcessType.Text + " : " + cashTrasnfer.cash; s = validateDuplicate(cashTrasnfer.cash.Value); } else if (cb_paymentProcessType.SelectedValue.ToString().Equals("card")) { if (_SelectedCard == -1) { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trSelectCreditCard"), animation: ToasterAnimation.FadeIn); return; } else { cashTrasnfer.cardId = _SelectedCard; cashTrasnfer.docNum = tb_processNum.Text; s = txt_card.Text + " : " + cashTrasnfer.cash; } } lst_payments.Items.Add(s); listPayments.Add(cashTrasnfer); invoice.paid += cashTrasnfer.cash; txt_sum.Text = invoice.paid.ToString(); if (invoice.paid == invoice.totalNet) { txt_sum.Foreground = Application.Current.Resources["mediumGreen"] as SolidColorBrush; } else { txt_sum.Foreground = Application.Current.Resources["mediumRed"] as SolidColorBrush; } tb_cash.Text = (invoice.totalNet - invoice.paid).ToString(); } else { p_errorCash.Visibility = Visibility.Visible; tt_errorCash.Content = MainWindow.resourcemanager.GetString("trAmountGreaterInvoiceValue"); tb_cash.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#15FF0000")); } } else { p_errorCash.Visibility = Visibility.Visible; tt_errorCash.Content = MainWindow.resourcemanager.GetString("trZeroAmmount"); tb_cash.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#15FF0000")); } } catch (Exception ex) { SectionData.ExceptionMessage(ex, this); } }
async void cancelRowinDatagrid(object sender, RoutedEventArgs e) { try { if (sender != null) { SectionData.StartAwait(grid_main); } for (var vis = sender as Visual; vis != null; vis = VisualTreeHelper.GetParent(vis) as Visual) { if (vis is DataGridRow) { CashTransfer row = (CashTransfer)dg_transfers.SelectedItems[0]; #region get two pos cashes2 = await cashModel.GetbySourcId("p", row.cashTransId); //to insure that the pull operation is in cashtrans2 if (row.transType == "p") { cashtrans2 = cashes2.ToList()[0] as CashTransfer; cashtrans3 = cashes2.ToList()[1] as CashTransfer; } else if (row.transType == "d") { cashtrans2 = cashes2.ToList()[1] as CashTransfer; cashtrans3 = cashes2.ToList()[0] as CashTransfer; } #endregion #region cancel cashtrans2.isConfirm = 2; cashtrans3.isConfirm = 2; int s2 = await cashModel.Save(cashtrans2); int s3 = await cashModel.Save(cashtrans3); if ((!s2.Equals(0)) && (!s3.Equals(0))) { Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopCanceled"), animation: ToasterAnimation.FadeIn); await fillDataGrid(); } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } #endregion } } if (sender != null) { SectionData.EndAwait(grid_main); } } catch (Exception ex) { if (sender != null) { SectionData.EndAwait(grid_main); } SectionData.ExceptionMessage(ex, this); } }
async void confirmRowinDatagrid(object sender, RoutedEventArgs e) { try { if (sender != null) { SectionData.StartAwait(grid_main); } for (var vis = sender as Visual; vis != null; vis = VisualTreeHelper.GetParent(vis) as Visual) { if (vis is DataGridRow) { Pos posModel = new Pos(); CashTransfer row = (CashTransfer)dg_transfers.SelectedItems[0]; #region old //#region get two pos //cashes2 = await cashModel.GetbySourcId("p", row.cashTransId); ////to insure that the pull operation is in cashtrans2 //if (row.transType == "p") //{ // cashtrans2 = cashes2.ToList()[0] as CashTransfer; // cashtrans3 = cashes2.ToList()[1] as CashTransfer; //} //else if (row.transType == "d") //{ // cashtrans2 = cashes2.ToList()[1] as CashTransfer; // cashtrans3 = cashes2.ToList()[0] as CashTransfer; //} //#endregion //#region confirm ////if another operation not confirmed then just confirm this //////if another operation is confirmed then chk balance before confirm //bool confirm = false; //if (cashtrans2.cashTransId == row.cashTransId)//chk which record is selected //{ if (cashtrans3.isConfirm == 0) confirm = false; else confirm = true; } //else//chk which record is selected //{ if (cashtrans2.isConfirm == 0) confirm = false; else confirm = true; } //if (!confirm) await confirmOpr(row); //else //{ // Pos posModel = new Pos(); // Pos pos = await posModel.getById(cashtrans2.posId.Value); // //there is enough balance // if (pos.balance >= cashtrans2.cash) // { // cashtrans2.isConfirm = 1; // int s = await cashModel.Save(cashtrans2); // s = await cashModel.MovePosCash(cashtrans2.cashTransId, MainWindow.userID.Value); // // if (s.Equals("transdone"))//tras done so confirm // if (s.Equals(1))//tras done so confirm // await confirmOpr(row); // else//error then do not confirm // Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); // } // //there is not enough balance // else // Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopNotEnoughBalance"), animation: ToasterAnimation.FadeIn); //} //await MainWindow.refreshBalance(); //#endregion #endregion if (row.isConfirm2 == 0) { await confirmOpr(row); } else { Pos pos = await posModel.getById(row.posId.Value); Pos pos2 = await posModel.getById(row.pos2Id.Value); int s1 = 0; if (row.transType == "d") { //there is enough balance if (pos.balance >= row.cash) { pos.balance -= row.cash; int s = await posModel.save(pos); pos2.balance += row.cash; s1 = await posModel.save(pos2); if (!s1.Equals(0))//tras done so confirm { await confirmOpr(row); } else//error then do not confirm { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } } //there is not enough balance else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopNotEnoughBalance"), animation: ToasterAnimation.FadeIn); } } else { //there is enough balance if (pos2.balance >= row.cash) { pos2.balance -= row.cash; int s = await posModel.save(pos2); pos.balance += row.cash; s1 = await posModel.save(pos); if (!s1.Equals(0))//tras done so confirm { await confirmOpr(row); } else//error then do not confirm { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } } //there is not enough balance else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopNotEnoughBalance"), animation: ToasterAnimation.FadeIn); } } await MainWindow.refreshBalance(); } } } if (sender != null) { SectionData.EndAwait(grid_main); } } catch (Exception ex) { if (sender != null) { SectionData.EndAwait(grid_main); } SectionData.ExceptionMessage(ex, this); } }