Exemplo n.º 1
0
        public static int[] GetAccountIdsWithFreshDocuments(IDalSession session, DocumentSubtypes documentSubtype, 
                                                            int managementCompanyId, int accountId)
        {
            Hashtable parameters = new Hashtable();

            string hql = string.Format(@"SELECT CA.Key FROM CustomerAccount CA
                                          WHERE CA.Key IN (SELECT DISTINCT A.Key {0})", hqlDocumentsWithJoins(documentSubtype, false));

            if (managementCompanyId != 0)
            {
                parameters.Add("ManagementCompanyId", managementCompanyId);
                hql += " AND CA.AccountOwner.Key = :ManagementCompanyId";
            }

            if (accountId != 0)
            {
                parameters.Add("AccountId", accountId);
                hql += " AND CA.Key = :AccountId";
            }

            hql += " ORDER BY CA.Number";

            return session.GetTypedListByHQL<int>(hql, parameters).ToArray();
        }
Exemplo n.º 2
0
        private static void sendEmailNotificationsToContacts(BatchExecutionResults results, List<IContact> contacts, List<IDocument> documents,
                                                             DocumentSubtypes documentSubtype)
        {
            if (contacts.Count > 0)
            {
                ICustomerAccount account = documents[0].Account;

                string body = documentsCreatedEmailTemplate;
                body = Utility.ShowOptionalTag(body, "option-notas", documentSubtype == DocumentSubtypes.Notas);
                body = Utility.ShowOptionalTag(body, "option-reports", documentSubtype == DocumentSubtypes.QuarterlyReports ||
                                                                       documentSubtype == DocumentSubtypes.YearlyReports);

                string clientWebsiteUrl = (account.AccountOwner.StichtingDetails.ClientWebsiteUrl ?? "").TrimEnd('/');
                if (string.IsNullOrEmpty(clientWebsiteUrl))
                    throw new ApplicationException("Client Website URL not known.");

                body = body.Replace("<%AccountNumber%>", account.Number)
                           .Replace("<%ClientWebsiteUrl%>", clientWebsiteUrl);

                MailMessage message = new MailMessage();
                message.Subject = string.Format("Nieuwe {0} portefeuille {1}",
                                                documentSubtype == DocumentSubtypes.Notas ? "transactienota’s" : "rapportage",
                                                account.Number);
                message.IsBodyHtml = true;

                SmtpClient client = new SmtpClient();

                foreach (IContact contact in contacts)
                {
                    message.To.Clear();
                    message.To.Add(testEmailRecipients != "" ? testEmailRecipients : contact.Email);
                    message.Body = body.Replace("<%DearSirForm%>", contact.CurrentNAW.Formatter.DearSirForm);

                    client.Send(message);
                    results.MarkSuccess();
                }
            }
        }
Exemplo n.º 3
0
        private static void sendEmailNotificationsForAccount(BatchExecutionResults results, DocumentSubtypes documentSubtype, int accountId)
        {
            IDalSession session = NHSessionFactory.CreateSession();

            try
            {
                List<IDocument> documents = DocumentMapper.GetFreshDocuments(session, documentSubtype, accountId);
                if (documents.Count > 0)
                {
                    ICustomerAccount account = documents[0].Account;

                    if (account.Status == AccountStati.Active)
                    {
                        List<IContact> contacts = (from ah in account.AccountHolders
                                                   where ah.IsPrimaryAccountHolder || account.AccountHolders.Count == 1
                                                   select ah.Contact into c
                                                   where c.IsActive && c.Email != "" &&
                                                         c.ContactSendingOptions.GetValueOrDefault(
                                                                SendableDocumentCategories.NotasAndQuarterlyReports, SendingOptions.ByEmail)
                                                   select c).ToList();

                        sendEmailNotificationsToContacts(results, contacts, documents, documentSubtype);
                    }

                    foreach (IDocument document in documents)
                        document.EmailNotificationHandled = true;
                    session.Update(documents);
                }
            }
            catch (Exception ex)
            {
                results.MarkError(new ApplicationException(
                    string.Format("Error sending email notifications for account {0}.", accountId), ex));
            }
            finally
            {
                session.Close();
            }
        }
Exemplo n.º 4
0
        private static int[] getAccountIdsWithFreshDocuments(BatchExecutionResults results, DocumentSubtypes documentSubtype, int managementCompanyId, int accountId)
        {
            IDalSession session = NHSessionFactory.CreateSession();

            try
            {
                return DocumentMapper.GetAccountIdsWithFreshDocuments(session, documentSubtype, managementCompanyId, accountId);
            }
            catch (Exception ex)
            {
                results.MarkError(new ApplicationException(
                        string.Format("Error retrieving list of accounts needing email notifications ({0}).",
                                      Util.SplitCamelCase(documentSubtype.ToString())), ex));
                return new int[] { };
            }
            finally
            {
                session.Close();
            }
        }
Exemplo n.º 5
0
        public static void SendEmailNotifications(BatchExecutionResults results, DocumentSubtypes documentSubtype, int managementCompanyId, int accountId)
        {
            managementCompanyId = checkCompany(managementCompanyId);
            int[] freshAccountIds = getAccountIdsWithFreshDocuments(results, documentSubtype, managementCompanyId, accountId);

            foreach (int freshAccountId in freshAccountIds)
                sendEmailNotificationsForAccount(results, documentSubtype, freshAccountId);
        }
Exemplo n.º 6
0
 public static void SendEmailNotifications(BatchExecutionResults results, DocumentSubtypes documentSubtype, int managementCompanyId)
 {
     SendEmailNotifications(results, documentSubtype, managementCompanyId, 0);
 }
Exemplo n.º 7
0
 public static void SendEmailNotifications(BatchExecutionResults results, DocumentSubtypes documentSubtype)
 {
     SendEmailNotifications(results, documentSubtype, 0, 0);
 }
Exemplo n.º 8
0
        public static List<IDocument> GetFreshDocuments(IDalSession session, DocumentSubtypes documentSubtype, int accountId)
        {
            Hashtable parameters = new Hashtable();
            parameters.Add("AccountId", accountId);

            string hql = string.Format(@"FROM Document DD
                                         WHERE DD.Key IN (SELECT DISTINCT D.Key {0} AND A.Key = :AccountId)
                                         ORDER BY DD.CreationDate",
                                       hqlDocumentsWithJoins(documentSubtype, false));

            return session.GetTypedListByHQL<IDocument>(hql, parameters);
        }
Exemplo n.º 9
0
        private static string hqlDocumentsWithJoins(DocumentSubtypes documentSubtype, bool? emailNotificationHandled)
        {
            string hql;

            if (documentSubtype == DocumentSubtypes.Notas)
                hql = @"FROM NotaDocument D
                        INNER JOIN D.bagOfNotas N
                        INNER JOIN N.NotaAccount.Account A
                        WHERE N.PrintCount != 0";
            else
            {
                Type reportSubclass = (documentSubtype == DocumentSubtypes.QuarterlyReports ?
                                                                typeof(ReportQuarter) :
                                                                typeof(ReportEOY));
                hql = string.Format(@"FROM FinancialReportDocument D
                                      INNER JOIN D.Report R
                                      INNER JOIN R.Account A
                                      WHERE R.ReportStatusId = {0}
                                      AND R.Key IN (SELECT RR.Key FROM {1} RR)", (int)ReportStatuses.PrintSuccess, reportSubclass.Name);
            }

            if (emailNotificationHandled != null)
                hql += " AND D.EmailNotificationHandled = " + emailNotificationHandled.ToString().ToLower();

            return hql;
        }