Esempio n. 1
0
 public BankAccountDetails(BankAccount bankAccount)
 {
     BankAccountId = bankAccount.BankAccountId;
     Title = bankAccount.Title;
     Owner = bankAccount.Owner;
     CurrencyType = bankAccount.CurrencyType;
     BankAccountTypeLocalizedText = bankAccount.BankAccountTypeLocalizedText;
     BankAccountTypeLocalizedAcronym = bankAccount.BankAccountTypeLocalizedAcronym;
     AccountId = bankAccount.AccountId;
     Token = bankAccount.Token;
     ValidTo = bankAccount.ValidTo;
     IBAN = bankAccount.IBAN;
     SWIFT = bankAccount.SWIFT;
 }
Esempio n. 2
0
        public static DeleteResult Delete(DefaultContext db, int id, out BankAccount bankAccount)
        {
            bankAccount = GetDetail(db, id);
            if (bankAccount == null)
                return DeleteResult.AuthorizationFailed;

            // Pokud je bankovní účet součástí stále platných akcí, nesmí se smazat!
            if (db.Meetings.Any(m => m.BankAccountId == id && m.Finished > DateTime.Now))
                return DeleteResult.UnlinkFailed;

            try
            {
                var parameter = new SqlParameter(BankAccountIdSqlParameter, bankAccount.BankAccountId);
                db.Database.ExecuteSqlCommand(CascadeRemoveBankAccountProcedureTemplate, parameter);
                return DeleteResult.Ok;
            }
            catch (Exception e)
            {
                Logger.SetLog(e);
                return DeleteResult.DbFailed;
            }
        }
Esempio n. 3
0
        public static string GetInvoice(DefaultContext db, UserProfile userProfile, BankAccount bankAccountForClaAccess, DateTime currentDate, out string invoiceNumber)
        {
            invoiceNumber = PropertiesBagCache.GetClaAccessInvoiceNumber(db);

            var vocabulary = new Dictionary<string, string>
                                 {
                                     {"InvoiceNumber", invoiceNumber},
                                     {"VS", BankAccountHistory.GetVs(userProfile.LyonessId).ToString(CultureInfo.InvariantCulture)},
                                     {"ICO", userProfile.ICO},
                                     {"DIC", userProfile.DIC},
                                     {"Address", String.Format("{0} {1}\n{2}\n{3} {4}", userProfile.FirstName, userProfile.LastName, userProfile.Address, userProfile.PSC, userProfile.City)},
                                     {"AccountId", bankAccountForClaAccess.AccountId},
                                     {"IBAN", bankAccountForClaAccess.IBAN},
                                     {"SWIFT", bankAccountForClaAccess.SWIFT},
                                     {"Date", currentDate.ToString("dd.MM.yyyy")},
                                     {"Currency", userProfile.ClaAccessCurrency.ToString()},
                                     {"Price", userProfile.ClaAccessYearlyAccess.ToString(CultureInfo.InvariantCulture)}
                                 };

            string invoice = ProcessVocabulary(Properties.Resources.Invoice, vocabulary);
            return invoice;
        }
Esempio n. 4
0
        private static void ProcessPayableMeeting(DefaultContext db, BankAccount bankAccount, Currency[] currencies, DateTime currentDateTime, ref StringBuilder conversionExclamationMessages)
        {
            // Seskupit bankovní historii podle ID akce (Specifický symbol)
            var groupedBySsBankAccountHistories = bankAccount.BankAccountHistories
                .Where(bah => bah.Ss.HasValue)
                .GroupBy(bah => bah.Ss, bah => bah,
                         (key, g) => new
                         {
                             MeetingId = key,
                             BankAccountHistories = g.ToArray()
                         }).ToArray();
            foreach (var groupedBySsBankAccountHistory in groupedBySsBankAccountHistories)
            {
                int meetingId;
                try
                {
                    meetingId = Convert.ToInt32(groupedBySsBankAccountHistory.MeetingId.GetValueOrDefault());
                }
                catch (Exception e)
                {
                    Logger.SetLog(e);
                    continue;
                }

                Meeting meeting = MeetingCache.GetDetail(db, meetingId);
                if (meeting == null || meeting.Started < currentDateTime || (meeting.BankAccountId != bankAccount.BankAccountId && meeting.SecondBankAccountId != bankAccount.BankAccountId))
                    continue;

                MeetingAttendee[] meetingAttendees = meeting.MeetingAttendees.ToArray();
                int freeCapacity = meeting.Capacity - meetingAttendees.Length;

                // Seskupit bankovní historii podle ID akce a Lyoness Id (Specifický symbol a Variabilní symbol)
                var groupedBySsAndVsBankAccountHistories = groupedBySsBankAccountHistory.BankAccountHistories
                    .Where(bah => bah.Vs.HasValue)
                    .GroupBy(bah => bah.LyonessId, bah => bah,
                    (key, g) => new
                    {
                        LyonessId = key,
                        BankAccountHistories = g.ToArray()
                    }).ToArray();
                var conversionExclamationMessagesForOrganizer = new StringBuilder();
                foreach (var groupedBySsAndVsBankAccountHistory in groupedBySsAndVsBankAccountHistories)
                {
                    int amount = 0;
                    var notes = new StringBuilder();
                    foreach (BankAccountHistory bankAccountHistory in groupedBySsAndVsBankAccountHistory.BankAccountHistories)
                    {
                        notes.AppendLine(bankAccountHistory.Note);

                        if (bankAccountHistory.CurrencyType == bankAccount.CurrencyType)
                        {
                            amount += (int)bankAccountHistory.Ammount;
                            continue;
                        }

                        decimal convertedAmount;
                        CurrencyHelper.TryConvertTo(bankAccountHistory.Ammount, bankAccountHistory.CurrencyType, bankAccount.CurrencyType, currencies, out convertedAmount);
                        amount += (int)Math.Round(convertedAmount);

                        string conversionExclamationMessage =
                            String.Format(ViewResource.BankAccountHistory_MeetingPaymentWasConverted_Text,
                                          bankAccount.Title,
                                          bankAccount.CurrencyType, bankAccountHistory.CurrencyType,
                                          bankAccountHistory.Vs.GetValueOrDefault(), bankAccountHistory.Note);
                        conversionExclamationMessages.AppendLine(conversionExclamationMessage);
                        conversionExclamationMessagesForOrganizer.AppendLine(conversionExclamationMessage);
                    }

                    bool isSecondBankAccount = meeting.BankAccountId != bankAccount.BankAccountId;
                    bool success = RegisterAttendee(db, meetingAttendees, groupedBySsAndVsBankAccountHistory.LyonessId, notes.ToString(), meeting, amount, currentDateTime, isSecondBankAccount, ref freeCapacity);
                    if (!success)
                        continue;

                    foreach (BankAccountHistory bankAccountHistory in groupedBySsAndVsBankAccountHistory.BankAccountHistories)
                    {
                        db.BankAccountHistories.Remove(bankAccountHistory);
                    }
                }

                if (conversionExclamationMessages.Length == 0)
                    continue;

                string textBody = String.Format(MailResource.TaskSchedulerController_FoundConvertedAmountForMeeting_TextBody, conversionExclamationMessagesForOrganizer);
                Mail.SendEmail(meeting.Organizer.Email1, MailResource.TaskSchedulerController_FoundConvertedAmountForMeeting_Subject, textBody, meeting.Organizer.UseMail, true);
            }
        }
Esempio n. 5
0
        private static void ProcessChangingApplicationAccessAmount(DefaultContext db, BankAccount bankAccount, Currency[] currencies, ref StringBuilder conversionExclamationMessages)
        {
            // Seskupit bankovní historii podle ID uživatele (Variabilní symbol)
            var groupedByVsBankAccountHistories = bankAccount.BankAccountHistories
                .Where(bah => bah.Vs.HasValue)
                .GroupBy(bah => bah.LyonessId, bah => bah,
                         (key, g) => new
                         {
                             LyonessId = key,
                             BankAccountHistories = g.ToArray()
                         }).ToArray();

            foreach (var groupedByVsBankAccountHistory in groupedByVsBankAccountHistories)
            {
                UserProfile userProfile = UserProfileCache.GetDetail(db, lyonessId: groupedByVsBankAccountHistory.LyonessId);
                if (userProfile == null)
                    continue;

                decimal amount = 0;
                foreach (BankAccountHistory bankAccountHistory in groupedByVsBankAccountHistory.BankAccountHistories)
                {
                    if (bankAccountHistory.CurrencyType == userProfile.ClaAccessCurrency)
                    {
                        amount += bankAccountHistory.Ammount;
                        continue;
                    }

                    decimal convertedAmount;
                    CurrencyHelper.TryConvertTo(bankAccountHistory.Ammount, bankAccountHistory.CurrencyType, userProfile.ClaAccessCurrency, currencies, out convertedAmount);
                    amount += convertedAmount;

                    conversionExclamationMessages.AppendLine(
                            String.Format(ViewResource.BankAccountHistory_MeetingPaymentWasConverted_Text,
                                          bankAccount.Title,
                                          bankAccount.CurrencyType, bankAccountHistory.CurrencyType,
                                          bankAccountHistory.Vs.GetValueOrDefault(), bankAccountHistory.Note));
                }

                userProfile.ClaAccessAmount += amount;

                string textBody = String.Format(MailResource.TaskSchedulerController_AccessPaymentAccepted_TextBody, amount, userProfile.ClaAccessCurrency, userProfile.ClaAccessAmount);
                Mail.SendEmail(userProfile.Email1, MailResource.TaskSchedulerController_AccessPaymentAccepted_Subject, textBody, userProfile.UseMail, true);

                foreach (BankAccountHistory bankAccountHistory in groupedByVsBankAccountHistory.BankAccountHistories)
                {
                    db.BankAccountHistories.Remove(bankAccountHistory);
                }
            }
        }
Esempio n. 6
0
        public static bool Update(DefaultContext db, int[] userIds, bool saveOnlyUsersOrToken, ref BankAccount bankAccount)
        {
            int bankAccountId = bankAccount.BankAccountId;
            BankAccount dbBankAccount = GetDetail(db, bankAccountId);
            if (dbBankAccount == null)
                return false;

            if (!saveOnlyUsersOrToken)
            {
                if (bankAccount.NeedResetLastDownloadId(dbBankAccount))
                {
                    bankAccount.LastDownloadId = null;
                }

                dbBankAccount.CopyFrom(bankAccount);
            }
            else
            {
                dbBankAccount.Token = bankAccount.Token;
                dbBankAccount.ValidTo = bankAccount.ValidTo;
            }

            int[] dbUserIds = dbBankAccount.BankAccountUsers.Select(bau => bau.UserId).ToArray();
            int[] deletedUserIds = dbUserIds.Except(userIds).ToArray();
            int[] newUserIds = userIds.Except(dbUserIds).ToArray();

            BankAccountUser[] deletedBankAccountUsers =
                deletedUserIds.Select(dui => db.BankAccountUsers.Where(bau => bau.BankAccountId == bankAccountId && bau.UserId == dui))
                .SelectMany(bau => bau).ToArray();
            foreach (BankAccountUser bankAccountUser in deletedBankAccountUsers)
            {
                db.BankAccountUsers.Remove(bankAccountUser);
            }

            List<BankAccountUser> newBankAccountUsers = newUserIds.Select(nui => new BankAccountUser
                                                                                     {
                                                                                         BankAccountId = bankAccountId,
                                                                                         UserId = nui
                                                                                     }).ToList();
            foreach (BankAccountUser bankAccountUser in newBankAccountUsers)
            {
                db.BankAccountUsers.Add(bankAccountUser);
            }

            bool success = TrySaveChanges(db);
            if (!success)
                return false;

            bankAccount = dbBankAccount;
            return true;
        }
Esempio n. 7
0
        public static void Insert(DefaultContext db, BankAccount bankAccount, int[] userIds)
        {
            db.BankAccounts.Add(bankAccount);

            IEnumerable<BankAccountUser> bankAccountUsers = userIds == null
                                                                ? new BankAccountUser[0]
                                                                : userIds.Select(ui => new BankAccountUser
                                                                                           {
                                                                                               BankAccountId = bankAccount.BankAccountId,
                                                                                               UserId = ui
                                                                                           });
            foreach (BankAccountUser bankAccountUser in bankAccountUsers)
            {
                db.BankAccountUsers.Add(bankAccountUser);
            }

            db.SaveChanges();
        }
Esempio n. 8
0
 private bool IsAccess(BankAccount bankAccount)
 {
     return bankAccount != null;
 }
Esempio n. 9
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        /// <param name="other">An object to compare with this object.</param>
        public bool NeedResetLastDownloadId(BankAccount other)
        {
            bool needResetLastDownloadId = false;
            needResetLastDownloadId |= Token != other.Token;
            needResetLastDownloadId |= TransactionStartDate != other.TransactionStartDate;

            return needResetLastDownloadId;
        }
Esempio n. 10
0
 public void CopyFrom(BankAccount bankAccount)
 {
     Title = bankAccount.Title;
     Owner = bankAccount.Owner;
     BankAccountType = bankAccount.BankAccountType;
     CurrencyType = bankAccount.CurrencyType;
     AccountId = bankAccount.AccountId;
     Token = bankAccount.Token;
     ValidTo = bankAccount.ValidTo;
     TransactionStartDate = bankAccount.TransactionStartDate;
     LastDownloadId = bankAccount.LastDownloadId;
     IBAN = bankAccount.IBAN;
     SWIFT = bankAccount.SWIFT;
 }
Esempio n. 11
0
 public BankAccountIndex(BankAccount bankAccount)
 {
     BankAccountId = bankAccount.BankAccountId;
     Title = bankAccount.Title;
     BankAccountTypeLocalizedAcronym = bankAccount.BankAccountTypeLocalizedAcronym;
     CurrencyType = bankAccount.CurrencyType;
     ValidTo = bankAccount.ValidTo;
 }
Esempio n. 12
0
        public BankAccount GetModel(out int[] userIds, out bool saveOnlyUsersOrToken)
        {
            userIds = UserIds ?? new int[0];
            saveOnlyUsersOrToken = SaveOnlyUsersOrToken;

            var bankAccount = new BankAccount
            {
                BankAccountId = BankAccountId,
                Title = Title,
                Owner = Owner,
                BankAccountType = BankAccountType,
                AccountId = AccountId,
                CurrencyType = CurrencyType,
                Token = Token,
                TransactionStartDate = TransactionStartDate,
                ValidTo = ValidTo,
                IBAN = IBAN,
                SWIFT = SWIFT
            };
            return bankAccount;
        }
Esempio n. 13
0
        public static BankAccountEdit GetModelView(BankAccount bankAccount)
        {
            if (bankAccount == null)
                return null;

            var bankAccountEdit = new BankAccountEdit(bankAccount);
            return bankAccountEdit;
        }
Esempio n. 14
0
 public BankAccountEdit(BankAccount bankAccount)
 {
     BankAccountId = bankAccount.BankAccountId;
     Title = bankAccount.Title;
     Owner = bankAccount.Owner;
     BankAccountType = bankAccount.BankAccountType;
     AccountId = bankAccount.AccountId;
     CurrencyType = bankAccount.CurrencyType;
     Token = bankAccount.Token;
     ValidTo = bankAccount.ValidTo;
     TransactionStartDate = bankAccount.TransactionStartDate;
     UserIds = bankAccount.BankAccountUsers.Select(bau => bau.UserId).ToArray();
     IBAN = bankAccount.IBAN;
     SWIFT = bankAccount.SWIFT;
 }
Esempio n. 15
0
        public static BankAccountDetails GetModelView(BankAccount bankAccount)
        {
            if (bankAccount == null)
                return null;

            var bankAccountDetails = new BankAccountDetails(bankAccount);
            return bankAccountDetails;
        }