I have a script which prints extracts from a database to produce an HTML report by month, grouped by calendar year. The relevant part of the script is below. I now want to adapt the script to group by financial year eg 2007/08 March to April inclusive. Can anyone suggest how I could adapt the script, maybe be creating a new variable 'finyear'? - sub report_5 () {
-
my ($title) = @_;
-
output_title($title,5);
-
-
output_heading ('Month', '| Sales', ' | Sales value', ' | Renewals', ' | Renewals value', ' | Total', ' | Total value');
-
-
my $query = "select
-
SUM(IF(ord.order_prod_code = 'SUB1YR', 1, 0)) as sales_count,
-
SUM(IF(ord.order_prod_code = 'SUB1YR', amt, 0)) as sales_amt,
-
SUM(IF(ord.order_prod_code = 'SUB1YR', 0, 1)) as renewals_count,
-
SUM(IF(ord.order_prod_code = 'SUB1YR', 0, amt)) as renewals_amt,
-
DATE_FORMAT(pay.date, \"%M% %Y\") as month,
-
DATE_FORMAT(pay.date, \"%Y\") as year
-
from
-
$main::UsersTable as users,
-
$main::SubscriptionTable as subs,
-
$main::CustTable as cust,
-
$main::TxnTable as txn,
-
$main::OrderTable as ord,
-
$main::PaymentTable as pay
-
where users.user_id = subs.user_id
-
and pay.paymkey = subs.payment_id and pay.txn_id = txn.txnkey
-
and ord.order_txn_id = txn.txnkey
-
and cust.custkey = txn.txn_cust_id
-
and pay.status = 'AUTH' group by DATE_FORMAT(pay.date, \"%Y\"), DATE_FORMAT(pay.date, \"%M% %Y\")
-
order by pay.date desc
-
";
##etc
2 1355 eWish 971
Recognized Expert Contributor
From the looks of the code supplied the sub routine is only taking 1 argument which does not effect the query itself. Where is the code that determines the date you want to select between?
--Kevin
From the looks of the code supplied the sub routine is only taking 1 argument which does not effect the query itself. Where is the code that determines the date you want to select between?
--Kevin
As I really don't understand Perl code, perhaps it's easier if I copy the whole code: -
#!/usr/bin/perl
-
-
BEGIN {
-
require 'config.pl';
-
require 'akinit.pl';
-
}
-
require 'login_users.pl';
-
require 'logout.pl';
-
require 'dbconnect.pl';
-
require 'modem.pl';
-
require 'misc.pl';
-
use Audit;
-
-
-
$HtmlStart = read_html('login.htm');
-
-
use DBI;
-
use CGI;
-
use CGI::Carp qw(fatalsToBrowser);
-
-
-
use Login;
-
-
&DBconnect;
-
-
# Initialise a few variables
-
$query_CGI = new CGI;
-
@param_CGI=$query_CGI->param();
-
my $countDel;
-
$Nbr_Parms=$#param_CGI+1;
-
-
$html_format = $query_CGI->param('html_format');
-
$password = $query_CGI->param('password');
-
-
if ($html_format) {
-
print "content-Type: text/html\n\n";
-
print '<html><body><nobr>';
-
}
-
else {
-
print "content-Type: text/plain\n\n";
-
print "Use CTRL+F in your browser to find text, File->Save As to save a copy to import into Works\n";
-
print "e.g. save to a file called transactions.csv\n";
-
}
-
-
-
if ($html_format) {
-
}
-
report_5('Net monthly sales totals');
-
-
if ($html_format) {
-
print '</nobr></body></html>';
-
}
-
-
-
-
-
sub report_5 () {
-
my ($title) = @_;
-
output_title($title,5);
-
-
output_heading ('Month', '| Sales', ' | Sales value', ' | Renewals', ' | Renewals value', ' | Total', ' | Total value');
-
-
my $query = "select
-
SUM(IF(ord.order_prod_code = 'SUB1YR', 1, 0)) as sales_count,
-
SUM(IF(ord.order_prod_code = 'SUB1YR', amt, 0)) as sales_amt,
-
SUM(IF(ord.order_prod_code = 'SUB1YR', 0, 1)) as renewals_count,
-
SUM(IF(ord.order_prod_code = 'SUB1YR', 0, amt)) as renewals_amt,
-
DATE_FORMAT(pay.date, \"%M% %Y\") as month,
-
DATE_FORMAT(pay.date, \"%Y\") as year
-
from
-
$main::UsersTable as users,
-
$main::SubscriptionTable as subs,
-
$main::CustTable as cust,
-
$main::TxnTable as txn,
-
$main::OrderTable as ord,
-
$main::PaymentTable as pay
-
where users.user_id = subs.user_id
-
and pay.paymkey = subs.payment_id and pay.txn_id = txn.txnkey
-
and ord.order_txn_id = txn.txnkey
-
and cust.custkey = txn.txn_cust_id
-
and pay.status = 'AUTH' group by DATE_FORMAT(pay.date, \"%Y\"), DATE_FORMAT(pay.date, \"%M% %Y\")
-
order by pay.date desc
-
";
-
-
-
-
my $sth = $dbh->prepare($query);
-
$sth->execute();
-
-
$country_count = 0;
-
$country_sales = 0;
-
$country = '';
-
$year = '';
-
-
while (my $hash = $sth->fetchrow_hashref()) {
-
$month = $hash->{month};
-
$amt = $hash->{amt};
-
$count = $hash->{count};
-
-
-
if (($year ne $hash->{year}) and ($year ne '')) {
-
output_bold_record("Total for $year",$y_sales_count_total, $y_sales_amt_total,$y_renewals_count_total,$y_renewals_amt_total,$y_all_count_total,$y_all_amt_total);
-
if ($html_format) {
-
print '<tr height=10><td></td></tr>';
-
}
-
$y_sales_count_total = 0;
-
$y_sales_amt_total = 0;
-
$y_renewals_count_total = 0;
-
$y_renewals_amt_total = 0;
-
$y_all_count_total = 0;
-
$y_all_amt_total = 0;
-
}
-
-
$year = $hash->{year};
-
-
-
output_record(
-
$month,
-
$hash->{sales_count},
-
$hash->{sales_amt},
-
$hash->{renewals_count},
-
$hash->{renewals_amt},
-
$hash->{sales_count} + $hash->{renewals_count},
-
$hash->{sales_amt} + $hash->{renewals_amt}
-
);
-
$sales_count_total += $hash->{sales_count};
-
$sales_amt_total += $hash->{sales_amt};
-
$renewals_count_total += $hash->{renewals_count};
-
$renewals_amt_total += $hash->{renewals_amt};
-
$all_count_total += $hash->{sales_count} + $hash->{renewals_count};
-
$all_amt_total += $hash->{sales_amt} + $hash->{renewals_amt};
-
-
-
-
$y_sales_count_total += $hash->{sales_count};
-
$y_sales_amt_total += $hash->{sales_amt};
-
$y_renewals_count_total += $hash->{renewals_count};
-
$y_renewals_amt_total += $hash->{renewals_amt};
-
$y_all_count_total += $hash->{sales_count} + $hash->{renewals_count};
-
$y_all_amt_total += $hash->{sales_amt} + $hash->{renewals_amt};
-
}
-
-
output_bold_record("Total for $year",$y_sales_count_total, $y_sales_amt_total,$y_renewals_count_total,$y_renewals_amt_total,$y_all_count_total,$y_all_amt_total);
-
if ($html_format) {
-
print '<tr height=10><td></td></tr>';
-
}
-
output_bold_record('Total',$sales_count_total, $sales_amt_total,$renewals_count_total,$renewals_amt_total,$all_count_total,$all_amt_total);
-
-
output_footer();
-
}
-
-
-
-
sub get_current_status () {
-
my ($dbh, $user_id) = @_;
-
-
$Query="SELECT first_name, last_name FROM $UsersTable as u , $SubscriptionTable as s WHERE u.user_id =?
-
AND NOW() >= s.start_date
-
AND NOW() <= s.end_date
-
AND u.user_id = s.user_id";
-
-
$sth_user = $dbh->prepare($Query)
-
||print "AK572 could not select $Query $!\n $DBI::errstr";
-
$sth_user->execute($user_id)
-
||print "AK573 could not select $Query $!\n $DBI::errstr";
-
-
if ($sth_user->rows) {
-
return 'LIVE';
-
}
-
else {
-
return 'LAPSED';
-
}
-
}
-
-
-
sub superseded () {
-
-
#
-
# See if there are any subscriptions for the user that end after the date provided
-
#
-
-
my ($dbh, $user_id, $end_date) = @_;
-
-
$Query="SELECT * FROM $UsersTable as u , $SubscriptionTable as s WHERE u.user_id =?
-
AND s.end_date > ?
-
AND u.user_id = s.user_id";
-
-
$sth_user = $dbh->prepare($Query)
-
||print "AK574 could not select $Query $!\n $DBI::errstr";
-
$sth_user->execute($user_id, $end_date)
-
||print "AK575 could not select $Query $!\n $DBI::errstr";
-
-
if ($sth_user->rows) {
-
return 1;
-
}
-
else {
-
return 0;
-
}
-
}
-
-
-
sub output_title () {
-
my ($title, $name) = @_;
-
-
if ($html_format) {
-
print "<a name=$name>";
-
print "<p><H2>$title </H2>\n";
-
}
-
else {
-
print "\n$title \n";
-
}
-
}
-
-
-
sub output_sub_total () {
-
if ($html_format) {
-
print "<tr><td colspan=$no_fields><nobr><b>";
-
print join(' ', @_);
-
print '</b></nobr></td></tr>' . "\n";
-
}
-
else {
-
print join(' ', @_) . "\n";
-
}
-
}
-
-
sub output_record () {
-
if ($html_format) {
-
print '<tr><td><nobr>';
-
print join('</nobr></td><td align=right><nobr>', @_);
-
print '</nobr></td></tr>' . "\n";
-
}
-
else {
-
print join(',', @_) . "\n";
-
}
-
}
-
-
sub output_bold_record () {
-
if ($html_format) {
-
print '<tr><td><b><nobr>';
-
print join('</nobr></b></td><td align=right><b><nobr>', @_);
-
print '</nobr></b></td></tr>' . "\n";
-
}
-
else {
-
print join(',', @_) . "\n";
-
}
-
}
-
sub output_heading () {
-
$no_fields = scalar(@_);
-
if ($html_format) {
-
print '<table>';
-
print '<tr><td><nobr><b>';
-
print join('</b></nobr></td><td><nobr><b>', @_);
-
print '</b></nobr></td></tr>' . "\n";
-
}
-
else {
-
print join(',', @_) . "\n";
-
}
-
}
-
-
sub output_footer () {
-
if ($html_format) {
-
print '</table>';
-
}
-
else {
-
print "\n\n\n";
-
}
-
}
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jon via AccessMonster.com |
last post by:
Hi Guys,
My "Sorting and Grouping" in my report looks like this:
Field/Expression Sort Order
sID Ascending
((= Project Name Ascending
User *** Ascending
((= rID Ascending
|
by: RD |
last post by:
Say Company's financial year starts October First and say we are now March
17th. How do you determine which quarter of the Financial year - not the
actual year - March 17th is in.
Thanks for any help,
Bob
|
by: mpmason14 |
last post by:
i am trying to sort a report by the year from newest to oldest. however there is a catch...
the format of the records i want to sort by is YYMMDD - i am trying to figure out how to get it sorted from the most current (2006) to the oldest (in the 80s). any ideas without having to recreate a new column manually? there are over 500 records, need i say more?
|
by: paulquinlan100 |
last post by:
Hi
I have a table of investment history ranging over about 10 years, with
the structure:
Inv_Ref
Inv_Type
Inv_date
I need to produce a report where the data is grouped into columns by
Financial year eg
|
by: Jimmy |
last post by:
Is there a way to sort/group a report based on the second column of a combo
box, i.e. the text associated with the primary key number?
| |
by: Ryan |
last post by:
I have a SQL view that shows data by Category and Year - so the data may
look something like this.
Category - Year - Amount
Fruit - 2006 - $12,000
Fruit - 2007 - $16,000
Vegetables - 2006 - $15,000
Vegatables - 2007 - $25,000
Say I want to show that data in Tabular view with Category being the Y-Axis
and Year being the X-Axis, how would I go about doing this? I'm having a
|
by: sfjnet |
last post by:
Hi
I am relatively new to Access so I hope I am not embarrassing myself with this question.
I have created a database showing contract details (contract number, contractors, dates, other relavant info). Also on the data entry form there is a separate field for each month of the financial year and the user can enter a value in the relevant month(s) corresponding to the number of hours the contractor has worked that month.
The users...
|
by: p0lp0l |
last post by:
I'm too dummy. Pls help me...
The question:
Write a C program that accepts for staff of cOMPANY two data values: monthly salary
(ringgit amount) and a character value for performance evaluation. The performance
evaluation can have the values E (exceed expectation), M (meet expectation), and N
(need improvement). We want the program to compute and display the bonus for the
|
by: rajukotla |
last post by:
How to find out the number of days in a financial year.
suppose from date is sep1st,2006.and to date is aug24th,2009.
the entire range involves financial years.i.e.,
april1st,2006-march31st,2007
april1st,2007-march31st,2008
april1st,2008-march31st,2009
april1st,2009-march31st,2010.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |