[freeside-commits] freeside/FS/FS/Report/Table Monthly.pm, 1.22, 1.22.4.1

Erik Levinson levinse at wavetail.420.am
Thu Dec 30 15:03:53 PST 2010


Update of /home/cvs/cvsroot/freeside/FS/FS/Report/Table
In directory wavetail.420.am:/tmp/cvs-serv24398/FS/FS/Report/Table

Modified Files:
      Tag: FREESIDE_2_1_BRANCH
	Monthly.pm 
Log Message:
add customer accounting summary report, RT10911

Index: Monthly.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Report/Table/Monthly.pm,v
retrieving revision 1.22
retrieving revision 1.22.4.1
diff -u -w -d -r1.22 -r1.22.4.1
--- Monthly.pm	22 May 2010 18:52:46 -0000	1.22
+++ Monthly.pm	30 Dec 2010 23:03:51 -0000	1.22.4.1
@@ -59,7 +59,14 @@
 
   while ( $syear < $eyear || ( $syear == $eyear && $smonth < $emonth+1 ) ) {
 
+    if ( $self->{'doublemonths'} ) {
+	my($firstLabel,$secondLabel) = @{$self->{'doublemonths'}};
+	push @{$data{label}}, "$smonth/$syear $firstLabel";
+	push @{$data{label}}, "$smonth/$syear $secondLabel";
+    }
+    else {
     push @{$data{label}}, "$smonth/$syear";
+    }
 
     my $speriod = timelocal(0,0,0,1,$smonth-1,$syear);
     push @{$data{speriod}}, $speriod;
@@ -68,13 +75,26 @@
     push @{$data{eperiod}}, $eperiod;
   
     my $col = 0;
-    my @row = ();
-    foreach my $item ( @{$self->{'items'}} ) {
+    my @items = @{$self->{'items'}};
+    my $i;
+    for ( $i = 0; $i < scalar(@items); $i++ ) {
+      if ( $self->{'doublemonths'} ) {
+	  my $item = $items[$i]; 
+	  my @param = $self->{'params'} ? @{ $self->{'params'}[$i] }: ();
+	  my $value = $self->$item($speriod, $eperiod, $agentnum, @param);
+	  push @{$data{data}->[$col]}, $value;
+	  $item = $items[$i+1]; 
+	  @param = $self->{'params'} ? @{ $self->{'params'}[++$i] }: ();
+	  $value = $self->$item($speriod, $eperiod, $agentnum, @param);
+	  push @{$data{data}->[$col++]}, $value;
+      }
+      else {
+	  my $item = $items[$i];
       my @param = $self->{'params'} ? @{ $self->{'params'}[$col] }: ();
       my $value = $self->$item($speriod, $eperiod, $agentnum, @param);
-      #push @{$data{$item}}, $value;
       push @{$data{data}->[$col++]}, $value;
     }
+    }
 
   }
 
@@ -127,31 +147,32 @@
 }
 
 sub invoiced { #invoiced
-  my( $self, $speriod, $eperiod, $agentnum ) = @_;
+  my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
 
   $self->scalar_sql("
     SELECT SUM(charged)
       FROM cust_bill
         LEFT JOIN cust_main USING ( custnum )
       WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
+      . (%opt ? $self->for_custnum(%opt) : '')
   );
   
 }
 
 sub netsales { #net sales
-  my( $self, $speriod, $eperiod, $agentnum ) = @_;
+  my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
 
-    $self->invoiced($speriod,$eperiod,$agentnum)
-  - $self->netcredits($speriod,$eperiod,$agentnum);
+    $self->invoiced($speriod,$eperiod,$agentnum,%opt)
+  - $self->netcredits($speriod,$eperiod,$agentnum,%opt);
 }
 
 #deferred revenue
 
 sub cashflow {
-  my( $self, $speriod, $eperiod, $agentnum ) = @_;
+  my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
 
-    $self->payments($speriod, $eperiod, $agentnum)
-  - $self->refunds( $speriod, $eperiod, $agentnum);
+    $self->payments($speriod, $eperiod, $agentnum, %opt)
+  - $self->refunds( $speriod, $eperiod, $agentnum, %opt);
 }
 
 sub netcashflow {
@@ -162,12 +183,13 @@
 }
 
 sub payments {
-  my( $self, $speriod, $eperiod, $agentnum ) = @_;
+  my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
   $self->scalar_sql("
     SELECT SUM(paid)
       FROM cust_pay
         LEFT JOIN cust_main USING ( custnum )
       WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
+      . (%opt ? $self->for_custnum(%opt) : '')
   );
 }
 
@@ -182,17 +204,18 @@
 }
 
 sub refunds {
-  my( $self, $speriod, $eperiod, $agentnum ) = @_;
+  my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
   $self->scalar_sql("
     SELECT SUM(refund)
       FROM cust_refund
         LEFT JOIN cust_main USING ( custnum )
       WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum)
+      . (%opt ? $self->for_custnum(%opt) : '')
   );
 }
 
 sub netcredits {
-  my( $self, $speriod, $eperiod, $agentnum ) = @_;
+  my( $self, $speriod, $eperiod, $agentnum, %opt ) = @_;
   $self->scalar_sql("
     SELECT SUM(cust_credit_bill.amount)
       FROM cust_credit_bill
@@ -203,6 +226,7 @@
                                                 $agentnum,
                                                 'cust_bill._date'
                                               )
+      . (%opt ? $self->for_custnum(%opt) : '')
   );
 }
 
@@ -567,6 +591,12 @@
   $sql;
 }
 
+sub for_custnum {
+    my ( $self, %opt ) = @_;
+    return '' unless $opt{'custnum'};
+    $opt{'custnum'} =~ /^\d+$/ ? " and custnum = $opt{custnum} " : '';
+}
+
 sub scalar_sql {
   my( $self, $sql ) = ( shift, shift );
   my $sth = dbh->prepare($sql) or die dbh->errstr;



More information about the freeside-commits mailing list