simple A/P
authorIvan Kohler <ivan@freeside.biz>
Wed, 31 Jul 2013 12:24:27 +0000 (05:24 -0700)
committerIvan Kohler <ivan@freeside.biz>
Wed, 31 Jul 2013 12:24:27 +0000 (05:24 -0700)
FS/FS/vend_bill.pm
httemplate/elements/select-vend_class.html [new file with mode: 0644]
httemplate/elements/tr-select-vend_class.html [new file with mode: 0644]
httemplate/search/report_vend_bill.html
httemplate/search/vend_bill.html

index 81de694..c8fcdd7 100644 (file)
@@ -193,6 +193,7 @@ sub search {
   my ($class, $param) = @_;
 
   my @where = ();
+  my $addl_from = '';
 
   #_date
   if ( $param->{_date} ) {
@@ -202,7 +203,7 @@ sub search {
                  "vend_bill._date <  $ending";
   }
 
-  #_date
+  #payment_date
   if ( $param->{payment_date} ) {
     my($beginning, $ending) = @{$param->{payment_date}};
 
@@ -210,11 +211,17 @@ sub search {
                  "vend_pay._date <  $ending";
   }
 
+  if ( $param->{'classnum'} =~ /^(\d+)$/ ) {
+    #also simplistic, but good for now
+    $addl_from .= ' LEFT JOIN vend_main USING (vendnum) ';
+    push @where, "vend_main.classnum = $1";
+  }
+
   my $extra_sql = scalar(@where) ? ' WHERE '. join(' AND ', @where) : '';
 
   #simplistic, but how we are for now
-  my $addl_from = ' LEFT JOIN vend_bill_pay USING (vendbillnum) '.
-                  ' LEFT JOIN vend_pay      USING (vendpaynum)  ';
+  $addl_from .= ' LEFT JOIN vend_bill_pay USING (vendbillnum) '.
+                ' LEFT JOIN vend_pay      USING (vendpaynum)  ';
 
   my $count_query = "SELECT COUNT(*), SUM(charged) FROM vend_bill $addl_from $extra_sql";
 
diff --git a/httemplate/elements/select-vend_class.html b/httemplate/elements/select-vend_class.html
new file mode 100644 (file)
index 0000000..e323988
--- /dev/null
@@ -0,0 +1,18 @@
+<% include( '/elements/select-table.html',
+                 'table'       => 'vend_class',
+                 'name_col'    => 'classname',
+                 'value'       => $classnum,
+                 'empty_label' => '(none)',
+                 'hashref'     => { 'disabled' => '' },
+                 %opt,
+             )
+%>
+<%init>
+
+my %opt = @_;
+my $classnum = $opt{'curr_value'} || $opt{'value'};
+
+$opt{'records'} = delete $opt{'vend_class'}
+  if $opt{'vend_class'};
+
+</%init>
diff --git a/httemplate/elements/tr-select-vend_class.html b/httemplate/elements/tr-select-vend_class.html
new file mode 100644 (file)
index 0000000..b17191b
--- /dev/null
@@ -0,0 +1,27 @@
+% if ( 0 ) { # scalar(@{ $opt{'vend_class'} }) == 0 ) { 
+
+  <INPUT TYPE="hidden" NAME="<% $opt{'element_name'} || $opt{'field'} || 'classnum' %>" VALUE="">
+
+% } else { 
+
+  <TR>
+    <TD ALIGN="right"><% $opt{'label'} || 'Vendor class' %></TD>
+    <TD>
+      <% include( '/elements/select-vend_class.html',
+                    'curr_value' => $classnum,
+                    %opt
+                )
+      %>
+    </TD>
+  </TR>
+
+% } 
+
+<%init>
+
+my %opt = @_;
+my $classnum = $opt{'curr_value'} || $opt{'value'};
+
+$opt{'vend_class'} ||= [ qsearch( 'vend_class', { disabled=>'' } ) ];
+
+</%init>
index defda70..4f391fd 100644 (file)
@@ -4,7 +4,7 @@
 
   <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
 
-   <TR>
+    <TR>
         <TD ALIGN="right" VALIGN="center"><% mt('Date') |h %></TD>
         <TD>
           <TABLE>
@@ -16,7 +16,7 @@
         </TD>
     </TR>
 
-  <TR>
+    <TR>
         <TD ALIGN="right" VALIGN="center"><% mt('Payment date') |h %></TD>
         <TD>
           <TABLE>
@@ -28,6 +28,9 @@
         </TD>
     </TR>
 
+    <& /elements/tr-select-vend_class.html,
+    &>
+
   </TABLE>
 
 <BR>
index 33eb224..9bc74cf 100644 (file)
@@ -40,6 +40,8 @@ $search{'_date'} = [ $beginning, $ending ];
 ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, 'payment_date');
 $search{'payment_date'} = [ $beginning, $ending ];
 
+$search{'classnum'} = $cgi->param('classnum');
+
 my $query = FS::vend_bill->search( \%search );
 my $count_query = delete( $query->{'count_query'} );