X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fbrowse%2Fpart_referral.cgi;h=581e01bb6c6f082b4b11f67a132bc8bc507cfeaa;hp=82f42924f3ec3c3db0231a7cf291625b3c30c5b9;hb=31f55d8223d14807ce7648657502552f69dc9ad4;hpb=1fd6d8cf5d7854860ef4fd10ed89828e0c04ec39 diff --git a/httemplate/browse/part_referral.cgi b/httemplate/browse/part_referral.cgi index 82f42924f..581e01bb6 100755 --- a/httemplate/browse/part_referral.cgi +++ b/httemplate/browse/part_referral.cgi @@ -1,38 +1,97 @@ - -<% - -print header("Referral Listing", menubar( + +<%= header("Advertising source Listing", menubar( 'Main Menu' => $p, # 'Add new referral' => "../edit/part_referral.cgi", -)), "Where a customer heard about your service. Tracked for informational purposes.

", &table(), < - Referral - -END +)) %> +Where a customer heard about your service. Tracked for informational purposes. +

+Add a new advertising source +

+ +<% + my $today = timelocal(0, 0, 0, (localtime(time))[3..5] ); + my %after; + tie %after, 'Tie::IxHash', + 'Today' => 0, + 'Yesterday' => 86400, # 60sec * 60min * 24hrs + 'Past week' => 518400, # 60sec * 60min * 24hrs * 6days + 'Past 30 days' => 2505600, # 60sec * 60min * 24hrs * 29days + 'Past 60 days' => 5097600, # 60sec * 60min * 24hrs * 59days + 'Past 90 days' => 7689600, # 60sec * 60min * 24hrs * 89days + 'Past 6 months' => 15724800, # 60sec * 60min * 24hrs * 182days + 'Past year' => 31486000, # 60sec * 60min * 24hrs * 364days + 'Total' => $today, + ; + my %before = ( + 'Today' => 86400, # 60sec * 60min * 24hrs + 'Yesterday' => 0, + 'Past week' => 86400, # 60sec * 60min * 24hrs + 'Past 30 days' => 86400, # 60sec * 60min * 24hrs + 'Past 60 days' => 86400, # 60sec * 60min * 24hrs + 'Past 90 days' => 86400, # 60sec * 60min * 24hrs + 'Past 6 months' => 86400, # 60sec * 60min * 24hrs + 'Past year' => 86400, # 60sec * 60min * 24hrs + 'Total' => 86400, # 60sec * 60min * 24hrs + ); + + my $statement = "SELECT COUNT(*) FROM h_cust_main + WHERE history_action = 'insert' + AND refnum = ? + AND history_date >= ? + AND history_date < ? + "; + my $sth = dbh->prepare($statement) + or die dbh->errstr; +%> +<%= table() %> + + Advertising source + >Customers + +<% for my $period ( keys %after ) { %> + <%= $period %> +<% } %> + + +<% foreach my $part_referral ( sort { $a->getfield('refnum') <=> $b->getfield('refnum') } qsearch('part_referral',{}) ) { - my($hashref)=$part_referral->hashref; - print < - - $hashref->{refnum} - - $hashref->{referral} + + <%= $part_referral->refnum %> + + <%= $part_referral->referral %> + <% for my $period ( keys %after ) { + $sth->execute( $part_referral->refnum, + $today-$after{$period}, + $today+$before{$period}, + ) or die $sth->errstr; + my $number = $sth->fetchrow_arrayref->[0]; + %> + <%= $number %> + <% } %> -END - -} +<% } %> -print <prepare($statement) + or die dbh->errstr; +%> - Add a new referral + Total + <% for my $period ( keys %after ) { + $sth->execute( $today-$after{$period}, + $today+$before{$period}, + ) or die $sth->errstr; + my $number = $sth->fetchrow_arrayref->[0]; + %> + <%= $number %> + <% } %> - -END - -%>