search recurly invoice by time periods - invoice

Does Recurly allow to search invoices by time priod? say, last month, or last three months invoices? I did not find any on the documentation.

On Recurly.com you can export invoices by time period https://app.recurly.com/go/exports/new
If you want search with PHP, You can use this example:
$invoices = Recurly_InvoiceList::get();
foreach ($invoices as $invoice) {
$date = $invoice->created_at;
$result = $date->format('Y-m-d');
if($result > '2014-06-00'){
print_R($invoice);
print "\n";
}
}

Related

Using JIRA Query Language from Klipfolio To Query JIRA API For Number of Rejected Issues

I am trying to query the JIRA API from Klipfolio, to return all issues whos status = "rejected" in a given month, and the number of times each issue's status = "rejected".
Example queries I have run:
Give me the issue history for a given issue which contains rejected issues. But I don't know how to return the number of times the issue's status = "rejected" from this query:
https://upvate.atlassian.net/rest/api/2/project/UC?expand=changelog.
Give me the the number of issues whos status = "rejected" for a given project and sprint:
https://upvate.atlassian.net/rest/api/2/search?jql=project="UC" and sprint="21" and status="rejected"
But I need all issues whos status = "rejected" in a given month, and the number of times each issue's status = "rejected".
To determine which issues have been rejected, you will need to construct a JQL statement and insert that into the query. If you want to see the changelog for any issue that has been rejected, the query will look like this:
https://upvate.atlassian.net/rest/api/2/search?jql=project='UC' and status = 'rejected'&expand=changelog&maxResults=100
The expand=changelog will add a JSON array to each issue object with a revision history of each change made to that issue. In case you have more than the default 50 issues per call, you can use the maxResults parameter (maxResults=100) which will bring the number of issues up to the max per call set by JIRA of 100. If you have more than that you will need to use the startAt parameter to paginate through the pages of issues.
Like the above, you will need to create a JQL statement and insert it into the query url.
https://upvate.atlassian.net/rest/api/2/search?jql=project = 'UC' and sprint = '21' and status = 'rejected' and createdDate >= 2017-12-01 AND createdDate <= 2017-12-31&maxResults=100
This will successfully return data from project UC for sprint 21 that has been rejected and created within the month of December 2017. If you want to filter the data by a relative date range; for example, the previous month, you can utilize Klipfolio's date parameters. To have the above query always return data for the previous month's with the same conditions, the query will look like so:
https://upvate.atlassian.net/rest/api/2/search?jql=project = 'UC' and sprint = '21' and status = 'rejected' and createdDate >= {date.addMonths(-1).startOfMonth.format()} AND createdDate <= {date.addMonths(-1).endOfMonth.format()}&maxResults=100

Rails counting Sql during rendering

How can I display the query count in rendering the view.
I would like to show the text message like
Processed with 8 queries.
For PHP version is
function query($query)
{
//We increase the queries counter by 1
global $nb_queries,$timer_queries;
$nb_queries++;
//Execute the query and time the execution time
$beginning = timer();
//Execute the query and save the result in a variable
$req_return = mysql_query($query);
//We add the query duration to the total
$timer_queries += round(timer()-$beginning,6);
return $req_return;
}
How can I do similar in rails
Just found a gem resolve my question.
Query Diet https://github.com/makandra/query_diet

How to show items (articles, post, whatever) grouped by day? Example: like Poduct Hunt does with products on its daily leaderboard

I have a lits of items in my models that I would like to list grouped daily in home. How to show items (articles, post, whatever) grouped by day? Example: like Poduct Hunt does with products on its daily leaderboard
Just iterate over your result, creating a hash keyed by the created_at converted to a date:
hash = Article.all.each_with_object({}) {|e,h| ( h[e.created_at.strftime '%F'] ||= [] ) << e }
Smathy's answer is correct.
And if you prefer a higher-order, easier solution, you can try this gem: https://github.com/radar/by_star

Using the Quickbooks ruby gem how do I return invoices by customer_ref?

I need to query invoices by customer_ref. I have tried:
invoices = service.query("Select * From Invoice Where customer_ref = 75")
But that just returns:
Quickbooks::IntuitRequestException: Error parsing query:
QueryParserError: Encountered " <INTEGER> "75 "" at line 1, column 44.
Was expecting one of:
"false" ...
"true" ...
How can I return invoices by customer_ref?
Ok.. I am going to answer my own question with a link to help others if they stumble across similar problems. Check out the Advanced SQL Query page provided by Intuit:
https://developer.intuit.com/blog/2014/03/20/advanced-sql-queries
invoices = service.query("Select * From Invoice Where CustomerRef = '75'")

Gorm count elements group by day without time

I wish to retrieve a list of UserProfile registrations per day.
The domain object UserProfile stores a Date creationDate property.
I've tried
def results = UserProfile.executeQuery('select u.creationDate, count(u) from UserProfile as u group by u.creationDate')
println results
which obviously is not what I need because data is (already) stored with complete time in it.
Any resource savvy solution will fit: projections, hql, ...
Thnks
I use HQL cast function:
def results = UserProfile.executeQuery("""
select cast(u.creationDate as date), count(u)
from UserProfile as u
group by cast(u.creationDate as date)
""")
Underlying database must support ANSI cast(... as ...) syntax for this to work, which is the case for PostgreSQL, MySQL, Oracle, SQL Server and many other DBMSs
Break down the date to day, month and year then ignore the timestamp.
This should give you what you need.
def query =
"""
select new map(day(u.creationDate) as day,
month(u.creationDate) as month,
year(u.creationDate) as year,
count(u) as count)
from UserProfile as u
group by day(u.creationDate),
month(u.creationDate),
year(u.creationDate)
"""
//If you do not worry about dates any more then this should be enough
def results = UserProfile.executeQuery( query )
//Or create date string which can be parsed later
def refinedresults =
results.collect { [ "$it.year-$it.month-$it.day" : it.count ] }
//Or parse it right here
def refinedresults =
results.collect {
[ Date.parse( 'yyyy-MM-dd', "$it.year-$it.month-$it.day" ) : it.count ]
}
You could define a "derived" property mapped as a formula to extract the date part of the date-and-time. The exact formula will differ depending what DB you're using, for MySQL you could use something like
Date creationDay // not sure exactly what type this needs to be, it may need
// to be java.sql.Date instead of java.util.Date
static mapping = {
creationDay formula: 'DATE(creation_date)'
}
(the formula uses DB column names rather than GORM property names). Now you can group by creationDay instead of by creationDate and it should do what you need.
Or instead of a "date" you could use separate fields for year, month and day as suggested in the other answer, and I think those functions are valid in H2 as well as MySQL.

Resources