public int runTest() { try { // Send the Property File (FTP) Wakefield wake = new Wakefield(); var getLastCollection = db.collections.OrderByDescending(c => c.CollectionsID).Select(a => a.CollectionsID).First(); string ftpPath = wake.ftp + wake.ftpFolder + "Collection" + getLastCollection.ToString() + ".csv"; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpPath); request.Method = WebRequestMethods.Ftp.UploadFile; WebClient client = new WebClient(); Byte[] fileBytes = client.DownloadData("http://myirent.com/beta/collection.csv"); //byte[] fileBytes = Encoding.Default.GetBytes(sb.ToString()); //Enter FTP Server credentials request.Credentials = new NetworkCredential(wake.UserName, wake.Password); request.ContentLength = fileBytes.Length; request.UsePassive = true; request.UseBinary = true; request.ServicePoint.ConnectionLimit = fileBytes.Length; request.EnableSsl = true; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(fileBytes, 0, fileBytes.Length); requestStream.Close(); } FtpWebResponse response = (FtpWebResponse)request.GetResponse(); // Send Email SendUsEmail message = new SendUsEmail(); message.sendAlert(response.StatusCode + ": " + response.StatusDescription, "Test FTP Send to Collection"); response.Close(); } catch (Exception any) { Console.Write(any.ToString()); SendUsEmail error = new SendUsEmail(); error.sendError(any.ToString(), "Test FTP Send to Collections Error"); } return(0); }
public UpdatePayoutsData() { try { // Get active Stripe keys var getStripeKeys = db.stripes.GroupBy(s => s.SecretKey).Select(x => x.FirstOrDefault()).ToList(); foreach (var stripe in getStripeKeys) { StripeConfiguration.SetApiKey(stripe.SecretKey); // Get Payouts var payoutService = new StripePayoutService(); StripeList <StripePayout> payoutItems = payoutService.List( new StripePayoutListOptions() { Limit = 100 } ); foreach (var payout in payoutItems) { if (payout.Status == "paid") { var checkPayout = db.stripepayouts.Where(p => p.StripePayoutID == payout.Id).ToList(); if (checkPayout.Count == 0) { // Insert Payout stripepayout insertPayout = new stripepayout(); insertPayout.StripePayoutID = payout.Id; insertPayout.PaidDate = payout.ArrivalDate; insertPayout.PropertyID = stripe.PropertyID; db.stripepayouts.Add(insertPayout); db.SaveChanges(); // Get Payouts Payments var balanceService = new StripeBalanceService(); StripeList <StripeBalanceTransaction> balanceTransactions = balanceService.List( new StripeBalanceTransactionListOptions() { Limit = 100, PayoutId = payout.Id } ); foreach (var transaction in balanceTransactions) { if (transaction.Description != "STRIPE PAYOUT") { stripepayoutdetail payoutDetails = new stripepayoutdetail(); payoutDetails.AmountGross = (transaction.Amount / 100.0M); payoutDetails.Fee = (transaction.Fee / 100.0M); payoutDetails.AmountNet = (transaction.Net / 100.0M); payoutDetails.Description = transaction.Description; payoutDetails.StripePayoutID = insertPayout.ID; db.stripepayoutdetails.Add(payoutDetails); db.SaveChanges(); } } } } } } } catch (Exception e) { SendUsEmail error = new SendUsEmail(); error.sendError(e.ToString(), "Error getting iRent Payouts"); } }
public ScheduleSendToCollection() { try { // Get all active companies that have signed to send to collection var getCompanies = db.companies.Where(c => c.Active == 1 && c.SendToCollection == 1).ToList(); foreach (var company in getCompanies) { var getProperties = db.properties.Where(p => p.CompanyID == company.CompanyID && p.Active == 0 && p.PropertyID != 9).ToList(); foreach (var property in getProperties) { DataTable dt = new DataTable(); dt = createCollectionTable(); Decimal TotalBalance = 0; int count = 0; // Get Former Tenants need to send to collection var getFormerTenants = (from t in db.tenants join b in db.backgrounds on t.TenantID equals b.TenantID join c in db.collections on t.TenantID equals c.TenantID where t.Prospect == 3 && t.Collections == 1 && c.SentToCollections != 4 && t.PropertyID == property.PropertyID select new { t, b }).ToList(); foreach (var formerTenant in getFormerTenants) { var getUnit = db.units.Where(u => u.UnitID == formerTenant.t.UnitID).FirstOrDefault(); var getForwarding = db.whitelists.Where(w => w.TenantID == formerTenant.t.TenantID).FirstOrDefault(); TenantBalance tBalance = new TenantBalance(formerTenant.t.TenantID); if (tBalance.TotalTenantBalance > 0) { TotalBalance += tBalance.TotalTenantBalance; count++; // Tenant info into csv dt.Rows.Add( formerTenant.t.TenantID, formerTenant.t.TenantFName + " " + formerTenant.t.TenantMName + " " + formerTenant.t.TenantLName, formerTenant.b.DOB, formerTenant.t.SSN, property.PropertyName, "Unit: " + getUnit.UnitID + " " + property.PropertyAddress1 + " " + property.PropertyCity + " " + property.PropertyState + " " + property.PropertyZip, "NA", "NA", "NA", getForwarding.FAddress + " " + getForwarding.FCity + " " + getForwarding.FState + " " + getForwarding.FZip, formerTenant.t.TenantPhone, formerTenant.t.TenantEmail, formerTenant.t.LeaseStartDate.Value.ToString("MM/dd/yyyy") + " to " + formerTenant.t.LeaseEndDate.Value.ToString("MM/dd/yyyy"), tBalance.TotalTenantBalance, "Balance Overdue as of: " + formerTenant.t.LeaseEndDate.Value.ToString("MM/dd/yyyy"), "Rental Fees" ); var getCollection = db.collections.Where(c => c.TenantID == formerTenant.t.TenantID).ToList(); getCollection.ForEach(x => { x.SentToCollections = 4; }); db.SaveChanges(); } } if (count > 0) { // Convert the file to .CSV StringBuilder sb = new StringBuilder(); foreach (DataRow row in dt.Rows) { IEnumerable <string> fields = row.ItemArray.Select(field => field.ToString()); sb.AppendLine(string.Join(",", fields)); } // Send the Property File (FTP) Wakefield wake = new Wakefield(); var getLastCollection = db.collections.OrderByDescending(c => c.CollectionsID).Select(a => a.CollectionsID).First(); string ftpPath = wake.ftp + wake.ftpFolder + "Collection" + getLastCollection.ToString() + ".csv"; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpPath); request.Method = WebRequestMethods.Ftp.UploadFile; byte[] fileBytes = Encoding.Default.GetBytes(sb.ToString()); //Enter FTP Server credentials request.Credentials = new NetworkCredential(wake.UserName, wake.Password); request.ContentLength = fileBytes.Length; request.UsePassive = true; request.UseBinary = true; request.ServicePoint.ConnectionLimit = fileBytes.Length; request.EnableSsl = true; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(fileBytes, 0, fileBytes.Length); requestStream.Close(); } FtpWebResponse response = (FtpWebResponse)request.GetResponse(); response.Close(); // Send an email to property manager/admin string emailTo = ""; var getPMEmail = (from upm in db.users join propMap in db.userpropertymaps on upm.UserID equals propMap.UserID where upm.SecurityLevelID == 2 && upm.Active == 1 && propMap.PropertyID == property.PropertyID select upm).FirstOrDefault(); if (getPMEmail == null) { var getAdminEmail = (from upm in db.users join propMap in db.userpropertymaps on upm.UserID equals propMap.UserID where upm.SecurityLevelID == 1 && upm.Active == 1 && propMap.PropertyID == property.PropertyID select upm).FirstOrDefault(); if (getAdminEmail != null) { emailTo = getAdminEmail.UserEmail.ToString(); } } else { emailTo = getPMEmail.UserEmail.ToString(); } if (emailTo != "") { MailMessage mailMessage = new MailMessage(); string sendTo = emailTo; sendTo += ",[email protected]"; mailMessage.To.Add(sendTo); if (company.LeadSourceCompanyID == 1) { mailMessage.From = new MailAddress("*****@*****.**"); } else { mailMessage.From = new MailAddress("*****@*****.**"); } string subject = "Attached is your Collections list which has " + count.ToString() + " individuals totaling " + TotalBalance.ToString("C", CultureInfo.CurrentCulture); mailMessage.Subject = subject; mailMessage.Body = "These are being sent to collections."; byte[] contentAsBytes = Encoding.Default.GetBytes(sb.ToString()); MemoryStream memoryStream = new MemoryStream(); memoryStream.Write(contentAsBytes, 0, contentAsBytes.Length); memoryStream.Seek(0, SeekOrigin.Begin); ContentType contentType = new ContentType("text/csv"); contentType.Name = "collection.csv"; Attachment attachment = new Attachment(memoryStream, contentType); mailMessage.Attachments.Add(attachment); SmtpClient smtp = new SmtpClient(); iRentEmailConf emailConf = new iRentEmailConf(); smtp.Host = emailConf.Host; smtp.Port = emailConf.Port; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential (emailConf.User, emailConf.Password); smtp.Send(mailMessage); } } } } // Alert us that the file run fine //SendUsEmail message = new SendUsEmail(); //message.sendAlert("Just run send to collection", "Send to Collection Alert"); } catch (Exception any) { SendUsEmail error = new SendUsEmail(); error.sendError(any.ToString(), "Send to Collections Error"); } }
public PostRecurringBills() { try { var GetRecurringBillsUpdate = (from rb in db.recurringbills join pm in db.postmethods on rb.PostMethodID equals pm.PostMethodID join f in db.frequencies on rb.FrequencyID equals f.FrequencyID join p in db.properties on rb.PropertyID equals p.PropertyID join et in db.expensetypes on rb.ExpenseTypeID equals et.ExpenseTypeID join v in db.vendors on rb.VendorID equals v.VendorID select rb).ToList(); // If first pay date is in the past, update to today foreach (var rBills in GetRecurringBillsUpdate) { if (rBills.FirstPayDate < DateTime.Now) { rBills.FirstPayDate = DateTime.Now; db.SaveChanges(); } } var GetRecurringBills = (from rb in db.recurringbills join pm in db.postmethods on rb.PostMethodID equals pm.PostMethodID join f in db.frequencies on rb.FrequencyID equals f.FrequencyID join p in db.properties on rb.PropertyID equals p.PropertyID join et in db.expensetypes on rb.ExpenseTypeID equals et.ExpenseTypeID join v in db.vendors on rb.VendorID equals v.VendorID where rb.FirstPayDate == DateTime.Now && rb.PostMethodID == 1 select rb).ToList(); foreach (var rBills in GetRecurringBills) { // Add Bill checkregister cr = new checkregister(); cr.PropertyID = rBills.PropertyID; cr.VendorID = rBills.VendorID; cr.Amount = rBills.Amount; cr.Memo = rBills.Memo; cr.ExpenseTypeID = rBills.ExpenseTypeID; cr.CheckDate = DateTime.Now; cr.TransactionType = 1; cr.Paid = rBills.Paid; cr.Reconciled = 0; cr.Escrow = rBills.Escrow; cr.InvoiceDate = DateTime.Now; cr.PaidDate = DateTime.Now; cr.InvoiceNumber = rBills.InvoiceNumber; cr.SubmittedBy = 16; // Will User's id db.checkregisters.Add(cr); db.SaveChanges(); DateTime nextPayDate = DateTime.Now; if (rBills.FrequencyID == 1) { nextPayDate.AddDays(7); } if (rBills.FrequencyID == 2) { nextPayDate.AddDays(14); } if (rBills.FrequencyID == 3) { int days = DateTime.DaysInMonth(nextPayDate.Year, nextPayDate.Month); days = days / 2; nextPayDate.AddDays(days); } if (rBills.FrequencyID == 4) { nextPayDate.AddMonths(1); } if (rBills.FrequencyID == 5) { nextPayDate.AddMonths(3); } if (rBills.FrequencyID == 6) { nextPayDate.AddMonths(6); } if (rBills.FrequencyID == 7) { nextPayDate.AddYears(1); } if (rBills.Unlimited != 1) { int numPayments = rBills.NumberofPayments - 1; if (numPayments == 0) { db.recurringbills.Remove(rBills); } else { rBills.NumberofPayments = numPayments; rBills.FirstPayDate = nextPayDate; db.SaveChanges(); } } else { rBills.FirstPayDate = nextPayDate; db.SaveChanges(); } } string msg = "There were " + GetRecurringBills.Count.ToString() + " bills posted."; SendUsEmail message = new SendUsEmail(); message.sendAlert(msg, "We just posted Recurring Bills."); } catch (Exception any) { SendUsEmail message = new SendUsEmail(); message.sendAlert(any.ToString(), "Error - We just posted Recurring Bills."); } }