I have a scenario where I would like to determine if a certain payment has been paid before a certain due date. The due date variable is just an integer from 1-30. Now this payment is supposed to be paid on a monthly basis so if the due date is 6th then every month on 6th I'm expecting the payment to be done. What I currently have is the following
DateTime.strptime(#payment.created.to_s,'%s') <= Date.new(Date.today.year, Date.today.month, #offer.due_date)
the offer model holds the due date and the payment comes in as a linux timestamp that's why the conversion. Now the problem with this simple logic is that it doesn' take into account the month at all. So DateTime.strptime(#payment.created.to_s,'%s') could be the payment for the last month and this would evaluate to true which would be not okay. How can I consider this logic, but on a monthly basis?
Related
The best approach to understand what i need is taking a look at the sample spreadsheet
https://docs.google.com/spreadsheets/d/1AyqCMvbjUt3nlqvE2ZLbmPfixwh_i1nIl9HMTn4pETY/edit?usp=sharing
What i need is unpivot the data:
1st date payment
xx months depending on the months entered in Col G (here i need to round the amount of the monthly payments, and in the last payment adjust the amount, so i don't get cents in the monthly payments divided)
last date payment
i believe the best way is generate a data base ordered correctly, from there know in which date every client has a due date for his payment
The way im entering the data is as the sample sheet shows from A:J
And my expected result is in range L:P
any help on this please will be very much appreciated
This is probably best handled by breaking the problem in 2 parts. Monthly payments and First/Last Payments. I've laid out one possible solution on your sheet in a tab called MK.Idea.
I used a SPLIT(FLATTEN( technique to generate both sets of cashflows and then a simple query to stack and order them.
This formula generated the monthly flows:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN('S1'!A2:A&"|"&'S1'!B2:B&"|"&MROUND(('S1'!D2:D-'S1'!E2:E-'S1'!I2:I)/'S1'!G2:G,100)&"|"&EDATE('S1'!H2:H,SEQUENCE(1,MAX('S1'!G2:G),0))&"|"&EDATE('S1'!H2:H,'S1'!G2:G)&"|"&"Monthly "&SEQUENCE(1,MAX('S1'!G2:G),1)),"|",0,0),"select Col4,Col1,Col2,Col6,Col3 where Col4<Col5"))
I'm using Google Sheets for tracking my mutual funds portfolio, and I'm supposed to call the function below to get the timestamp of the most recent change of the VASIX fund share price:
=GOOGLEFINANCE("VASIX", "date")
The problem is that the date, returned by this function, is typically two-three days late.
What might be wrong here?
GOOGLEFINANCE("VASIX", "date") returns The date at which the net asset value was reported. For mutual funds this is at market close on trading days. So, for example, Sat. would show the market close on Fri. The date won't change again until Tue. when Mondays NAV is reoported. Try =GOOGLEFINANCE("VASIX", "close","8/25/2017") requesting specific dates over a weekend through Tuesday to see what is happening.
I am writing what could be defined as an accountancy/invoicing app using Rails 5. I am in need of implementing a section that predicts the company's cashflow in the future. So far I've got the following:
Actual bank movements and balances (in the past), imported from the bank
Future invoices (income) which are expected to be paid on a certain date
Future one-time expenses which are expected to be paid on a certain date
Using these three sets of data, I can calculate, for any given date in the future, the sum of: the last known bank balance, plus all the future invoices values coming IN, minus all the future expenses going OUT, so I get, theoretically, the expected balance of the company for any given date.
My doubt arises when it comes to recurrent expenses (or potentially incomes). Given that all of the items I mentioned before (bank movements, invoices and expenses) are actual ActiveRecord records stored in my database, I'm not sure about how to treat the recurrent expenses, for example:
Let's imagine I want to enter a known future recurrent paycheck of a certain employee, which is $2000 every first day of the month.
1- Should I generate at some point the next X entries and treat them as normal future expenses (each with its own ID, date and amount)?
2- The other option I've thought of is having some kind of "declaration" on the nature of the recurrent expense, as in "it's $2000 every day 1 of month until -forever-", similarly to a cronjob. But, if I were to take this approach, I'd like to have an ActiveRecord - similar interface, so that I can do something like:
cashflow = []
last_movement = BankMovement.last
value = last_movement.balance
(last_movement.date..(last_movement.date + 12.months)).each do |day|
value += Invoice.pending.expected_on(day).sum(:gross_amount)
value -= Expense.pending.expected_on(day).sum(:gross_amount)
value -= RecurringExpense.expected_on(day).sum(:gross_amount)
cashflow.push( { date: day, balance: value } )
end
This feels almost right but, I'm not sure about how to link the actual expense when it comes with the recurrent/calculated one. How can I then change the date if the expense gets paid the day after it was supposed? I need to have an actual record of each one of those, at least whenever they are "consolidated".
I'm not really sure if I was clear enough with my trouble here, so, should anyone want and have some spare time to help me out, please feel free to ask for any extra relevant info, I'd really appreciate some help, especially if we can find a way of doing this "the Rails way"!
I need to schedule reports on monthly basis. The reports need to go out on 1st of each month with data from previous month. For reporting, I have selected the preset date option as 'Last Month' with monthly rolling date option. Right now, it says: Rolling date options: 04/01/2017 (rolling monthly) - 04/30/2017 (rolling monthly) which is how it should be. But I am concerned if it considers the varying number of days in a month (30, 31). Can someone confirm when the next set of reports go out on 6/1, whether the date range would be from 05/01/2017 to 05/30/2017 or 05/31/2017?
If it doesn't consider the number of days in a month, is there an alternative to this setup for achieving the same results?
"Rolling monthly" does just as the name implies. When the date shifts from 4/30 to 5/1, the report will update to April data. When the date shifts from 5/31 to 6/1, the report will update to May data. If on 6/15 you again open the report, it will still be populated with May data, because the month has not yet rolled.
I am creating a simple todo app where I have 2 types of tasks.
1) regular tasks - These have a due date
2) recurring tasks -These are poped up as reminders on specified date. They can be created either as weekly or monthly reminders. If created for a week, it will be poped up on each week (on a specified date on the week). Likewise for a month it need to be specified the week and the date.
What will be the best way to model this scenario?
I would have two columns for the reminder object - remind_at (date) and repeat_frequency (something to identify different re-occurrences by). That way, you could index the remind_at column and search by it quite quickly. Each time a reminder is shown to user, it would look at repeat_frequency - if it contains directions for repeating, set remind_at to next date, if not, delete/archive the reminder.
You could model a Task to have a due_date. But if a task is recurring, due_date will be null and you would use the recurrence field to compute the next_due_date. recurrence would be a string field holding a parsable string like "tuesday" (for weekly) or "17" (a day number for monthly).
def next_due_date
if due_date
due_date
else
# compute next due date using the 'recurrence' field and today's date
end
end
This may or may not be the "best way" for you, depending on your requirements, and the future needs of the model.