checkpoint tax editors and correct a blunder
authorjeff <jeff>
Wed, 2 Apr 2008 20:42:44 +0000 (20:42 +0000)
committerjeff <jeff>
Wed, 2 Apr 2008 20:42:44 +0000 (20:42 +0000)
FS/FS/Schema.pm
FS/FS/part_pkg_taxoverride.pm
httemplate/browse/tax_class.html [new file with mode: 0755]
httemplate/edit/part_pkg.cgi
httemplate/edit/part_pkg_taxoverride.html
httemplate/edit/process/part_pkg.cgi
httemplate/search/elements/search.html

index e431b07..d4a51a6 100644 (file)
@@ -1055,11 +1055,11 @@ sub tables_hashref {
       'columns' => [
         'taxoverridenum', 'serial', '', '', '', '',
         'pkgpart',        'serial', '', '', '', '',
       'columns' => [
         'taxoverridenum', 'serial', '', '', '', '',
         'pkgpart',        'serial', '', '', '', '',
-        'taxnum',         'serial', '', '', '', '',
+        'taxclassnum',    'serial', '', '', '', '',
       ],
       'primary_key' => 'taxoverridenum',
       'unique' => [],
       ],
       'primary_key' => 'taxoverridenum',
       'unique' => [],
-      'index' => [ [ 'pkgpart' ], [ 'taxnum' ] ],
+      'index' => [ [ 'pkgpart' ], [ 'taxclassnum' ] ],
     },
 
 #    'part_title' => {
     },
 
 #    'part_title' => {
index 656fe53..0fdfa50 100644 (file)
@@ -41,9 +41,9 @@ Primary key
 
 The package definition id
 
 
 The package definition id
 
-=item taxnum
+=item taxclassnum
 
 
-The tax rate definition id
+The tax class id
 
 =back
 
 
 =back
 
@@ -96,7 +96,7 @@ sub check {
   my $error = 
     $self->ut_numbern('taxoverridenum')
     || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart')
   my $error = 
     $self->ut_numbern('taxoverridenum')
     || $self->ut_foreign_key('pkgpart', 'part_pkg', 'pkgpart')
-    || $self->ut_foreign_key('taxnum', 'tax_rate', 'taxnum')
+    || $self->ut_foreign_key('taxclassnum', 'tax_class', 'taxclassnum')
   ;
   return $error if $error;
 
   ;
   return $error if $error;
 
diff --git a/httemplate/browse/tax_class.html b/httemplate/browse/tax_class.html
new file mode 100755 (executable)
index 0000000..76d266b
--- /dev/null
@@ -0,0 +1,92 @@
+<% include( 'elements/browse.html',
+     'title'             => "Tax classes $title",
+     'name_singular'     => 'tax class',
+     'menubar'           => \@menubar,
+     'html_init'         => $html_init,
+     'query'             => {
+                              'table'     => 'tax_class',
+                              'hashref'   => $hashref,
+                              'extra_sql' => $where,
+                              'order_by'  => 'ORDER BY taxclass',
+                            },
+     'count_query'       => $count_query,
+     'header'            => \@header,
+     'fields'            => \@fields,
+     'align'             => $align,
+     'links'             => \@links,
+     'link_onclicks'     => \@link_onclicks,
+     'disable_maxselect' => 1,
+     'disable_total'     => 1,
+  )
+%>
+<%once>
+
+my $conf = new FS::Conf;
+
+</%once>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $title = '';
+my @menubar = ();
+my $html_init = '';
+my $hashref = {};
+my @where = ();
+my $onclick = 'return true;';
+
+my $omit = '';
+if ( $cgi->param('magic') eq 'omit' ) {
+  $cgi->param('omit') =~ /^([,\d]+)$/;
+  $omit = $1;
+  $title .= " unselected";
+  push @where, map { "taxclassnum != $_" } grep {$_} split( /,/, $omit );
+  $onclick = sub{ 'parent.doSelect('. shift->taxclassnum. '); return false;' } 
+}
+$cgi->delete('omit');
+
+my $data_vendor = '';
+if ( $cgi->param('datavendor') =~ /^([\w]+)$/ ) {
+  $data_vendor = $1;
+  $title .= " for data vendor $1";
+  push @where, 'data_vendor = '. dbh->quote($data_vendor);
+}
+$cgi->delete('data_vendor');
+
+my $selected = '';
+if (    $cgi->param('magic') eq 'select')
+{
+  $cgi->param('selected') =~ /^([,\d]*)$/;
+  $selected = $1;
+  $title = " selected";
+  my @clauses =  map { "taxclassnum = $_" } grep {$_} split( /,/, $selected );
+  @where =  scalar(@clauses) ? '( '. join(' OR ', @clauses) .')' : '1=0';
+  $onclick = sub{ 'parent.doUnselect('. shift->taxclassnum. '); return false;' } ;
+}
+$cgi->delete('selected');
+
+
+if ( $data_vendor ) {
+  push @menubar, 'View all tax classes' => $p.'browse/tax_class.html';
+}
+
+$cgi->param('dummy', 1);
+
+#restore this so pagination works
+$cgi->param('omit', $omit ) if $omit;
+$cgi->param('selected', $selected ) if $selected;
+$cgi->param('data_vendor', $data_vendor ) if $data_vendor;
+
+my $where = scalar(@where) ? 'WHERE '. join( ' AND ', @where ) : '';
+my $count_query = 'SELECT COUNT(*) FROM tax_class '. $where;
+
+my $link = [ 'javascript:void(0);', sub{ ''; } ];
+
+my @header        = ( '', '', '' );
+my @links         = ( $link, $link, $link );
+my @link_onclicks = ( $onclick, $onclick, $onclick );
+my $align = 'lll';
+my @fields = ( 'data_vendor', 'taxclass', 'description' );
+
+</%init>
index 84f7498..2e7c732 100755 (executable)
@@ -94,13 +94,13 @@ Tax information
         <TD align="right">Tax product</TD>
         <TD>
           <INPUT name="part_pkg_taxproduct_taxproductnum" id="taxproductnum" type="hidden" value="<% $hashref->{'taxproductnum'}%>">
         <TD align="right">Tax product</TD>
         <TD>
           <INPUT name="part_pkg_taxproduct_taxproductnum" id="taxproductnum" type="hidden" value="<% $hashref->{'taxproductnum'}%>">
-          <INPUT name="part_pkg_taxproduct_description" id="taxproduct_description" type="text" value="<% $taxproduct_description %>" size="12" onclick="overlib( OLiframeContent('part_pkg_taxproduct.html?'+document.getElementById('taxproductnum').value, 800, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
+          <INPUT name="part_pkg_taxproduct_description" id="taxproduct_description" type="text" value="<% $taxproduct_description %>" size="12" onclick="overlib( OLiframeContent('part_pkg_taxproduct.html?'+document.getElementById('taxproductnum').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
         </TD>
       </TR>
       <TR>
         <TD colspan="2" align="right">
           <INPUT name="tax_override" id="tax_override" type="hidden" value="<% $tax_override %>">
         </TD>
       </TR>
       <TR>
         <TD colspan="2" align="right">
           <INPUT name="tax_override" id="tax_override" type="hidden" value="<% $tax_override %>">
-          <A href="javascript:void(0)" onclick="overlib( OLiframeContent('part_pkg_taxoverride.html?'+document.getElementById('tax_override').value, 800, 400, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
+          <A href="javascript:void(0)" onclick="overlib( OLiframeContent('part_pkg_taxoverride.html?selected='+document.getElementById('tax_override').value, 1100, 600, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
             <% $tax_override ? 'Edit tax overrides' : 'Override taxes' %>
           </A>
         </TD>
             <% $tax_override ? 'Edit tax overrides' : 'Override taxes' %>
           </A>
         </TD>
@@ -467,7 +467,8 @@ if ( $cgi->param('clone') ) {
   (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
     unless $part_pkg;
   $tax_override =
   (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
     unless $part_pkg;
   $tax_override =
-    join (",", map {$_->taxnum} qsearch('part_pkg_taxoverride',{'pkgpart'=>$1}))
+    join (",", map {$_->taxclassnum}
+               qsearch('part_pkg_taxoverride',{'pkgpart'=>$1}))
     unless $part_pkg;
   $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
   $pkgpart = $part_pkg->pkgpart;
     unless $part_pkg;
   $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
   $pkgpart = $part_pkg->pkgpart;
index 61cca1f..ba709ce 100644 (file)
-<%doc>
+<% include('/elements/header-popup.html', 'Override taxes', '', 'onload="resizeFrames()"') %>
 
 
-  The crappy version
-  
-</%doc>
-<% include('/elements/header-popup.html', 'Select tax product') %>
+<TABLE WIDTH="100%" HEIGHT="100%">
+  <TR><TD>
+    <iframe name="selected" src="<% $p %>browse/tax_class.html?_type=select;magic=select;maxrecords=15;offset=<% $selected_offset %>;selected=<% $selected %>;" width="100%" frameborder="0" border="0" id="selectorSelected" scrolling="no">
+</iframe>
+    <BR>
+  </TD></TR>
+
+  <TR><TD>
+<FORM="dummy">
+  <CENTER>
+    <INPUT type="submit" value="Finish" onclick="s=fetchSelected(); s.shift(); parent.document.getElementById('tax_override').value=s.toString(); parent.cClick();">
+    <INPUT type="reset" value="Cancel" onclick="parent.cClick();">
+  </CENTER>
+</FORM>
+  </TD></TR>
+
+  <TR><TD>
+    <iframe name="unselected" src="<% $p %>browse/tax_class.html?_type=select;magic=omit;maxrecords=15;offset=<% $unselected_offset %>;omit=<% $selected %>;" width="100%" frameborder="0" border="0" id="selectorUnselected" scrolling="no">
+</iframe>
+    <BR>
+  </TD></TR>
+
+</TABLE>
 <SCRIPT>
 <SCRIPT>
-  function saveit2() {
-    var num = parent.document.getElementById('tax_override');
-    var sel = document.getElementById('taxoverride_popup_select');
-    var value = '';
-    for (i=0; i< sel.length; i++) {
-      if (sel.options[i].selected) {
-        value = value + sel.options[i].value + ",";
+
+    function resizeFrames() {
+      //frames['selected'].style.height =
+      //  frames['selected'].contentWindow.document.body.scrollHeight + "px";
+      //frames['unselected'].style.height =
+      //  frames['unselected'].contentWindow.document.body.scrollHeight + "px";
+      var f = document.getElementById('selectorSelected');
+      f.style.height = f.contentWindow.document.body.scrollHeight + "px";
+      var f = document.getElementById('selectorUnselected');
+      f.style.height = f.contentWindow.document.body.scrollHeight + "px";
+    }
+
+    function fetchOffset(search) {
+      var value = 0;
+      if (search.length > 1) {
+        var params = search.split(';');
+        for (i=0; i<params.length; i++) {
+          if (params[i].substr(0,7) == 'offset=') {
+            value = params[i].substr(7);
+          }
+        }
+      }
+      return value;
+    }
+
+    function fetchOffsetStrings() {
+      return 'selected_offset=' +
+             fetchOffset(frames['selected'].location.search) + ';' +
+             'unselected_offset=' +
+             fetchOffset(frames['unselected'].location.search) + ';';
+    }
+
+    function fetchSelected() {
+      var i;
+      var selected = new Array;
+      var replace = '?';
+      if (window.location.search.length > 1) {
+        var search = window.location.search.substr(1).split(';');
+        for (i=0; i<search.length; i++) {
+          if (search[i].substr(0,9) == 'selected=') {
+            selected = search[i].substr(9).split(',')
+          }else if (search[i].substr(0,16) ==   'selected_offset=') {
+          }else if (search[i].substr(0,18) == 'unselected_offset=') {
+          }else if (search[i].length) {
+            replace += search[i] + ';';
+          }
+        }
+      }
+      selected.unshift(replace);
+      return selected;
+    }
+    function doUnselect(classnum) {
+      var selected = fetchSelected();
+      var search = selected.shift();
+      //alert("discovered: "+selected.toString());
+      var i=-1, j=-1, k=selected.length;
+      while(++j < k) {
+        if (!(selected[j]==classnum)) {
+          selected[++i]=selected[j];
+        }
       }
       }
+      selected.length = ++i;
+      //alert("finished: "+selected.toString());
+
+      search += "selected=" + selected.toString() + ';';
+      window.location.search = search + fetchOffsetStrings();
     }
     }
-    if (value.length > 0) {
-      value = value.substr(0, value.length-1);
+    function doSelect(classnum) {
+      var selected = fetchSelected();
+      var search = selected.shift();
+      selected.push(classnum);
+      search += "selected=" + selected.toString() + ';';
+      window.location.search = search + fetchOffsetStrings();
     }
     }
-      
-    num.value = value;
-    parent.cClick();
-  }
 </SCRIPT>
 </SCRIPT>
-<FORM="dummy" METHOD="POST" onsubmit="saveit2();return false;" >
-
-<% ntable("#cccccc", 2) %>
-<TR>
-  <TD align="left">Tax override</TD>
-  <TD>
-    <% include( '/elements/select-table.html',
-                'table'       => 'tax_rate',
-                'name_col'    => 'taxname',
-                'curr_value'  => \@curr_value,
-                'element_etc' => "id='taxoverride_popup_select'",
-                'multiple'    => '1',
-              )
-    %>
-  </TD>
-</TR>
-</TABLE>
-<BR><BR>
-<CENTER><INPUT type="submit" value="Select"></CENTER>
-</FORM>
+
 <% include('/elements/footer.html') %>
 <% include('/elements/footer.html') %>
+<%once>
+
+my $conf = new FS::Conf;
 
 
+</%once>
 <%init>
 
 <%init>
 
-my $conf = new FS::Conf;
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+
+my $selected_offset = $1
+  if $cgi->param('selected_offset') =~/^(\d+)$/;
 
 
-my @curr_value;
-my ( $query ) = $cgi->keywords;
-$query =~ /^([\d,]+)$/;
-push @curr_value, split ',', $1
-  if $1;
+my $unselected_offset = $1
+  if $cgi->param('unselected_offset') =~/^(\d+)$/;
 
 
-unless (scalar(@curr_value)) {
-  #push @curr_value, map {$_=>taxnum} $part_pkg->tax_rate;
-}
+my $selected = $1
+  if $cgi->param('selected') =~/^([,\d]+)$/;
 
 </%init>
 
 </%init>
index eac20af..94bff0f 100755 (executable)
@@ -116,7 +116,7 @@ unless ( $error || $conf->exists('agent_defaultpkg') ) {
 unless ( $error  ) {
   $error = $new->process_m2m(
     'link_table'   => 'part_pkg_taxoverride',
 unless ( $error  ) {
   $error = $new->process_m2m(
     'link_table'   => 'part_pkg_taxoverride',
-    'target_table' => 'tax_rate',
+    'target_table' => 'tax_class',
     'params'       => \@tax_overrides,
   );
 }
     'params'       => \@tax_overrides,
   );
 }
index e1bc024..40c71d8 100644 (file)
@@ -93,6 +93,8 @@ Example:
     
     #disabling things
     'disable_download' => '', # set true to hide the CSV/Excel download links
     
     #disabling things
     'disable_download' => '', # set true to hide the CSV/Excel download links
+    'disable_total'    => '', # set true to hide the total"
+    'disable_maxselect' => '', # set true to disable record/page selection
     'disable_nonefound' => '', # set true to disable the "No matching Xs found"
                                # message
    
     'disable_nonefound' => '', # set true to disable the "No matching Xs found"
                                # message
    
@@ -291,6 +293,17 @@ Example:
 
         <% include( '/elements/header-popup.html', $opt{'title'} ) %>
 
 
         <% include( '/elements/header-popup.html', $opt{'title'} ) %>
 
+%     } elsif ( $type eq 'select' ) {
+
+        <% include( '/elements/header-popup.html', $opt{'title'} ) %>
+        <% defined($opt{'html_init'}) 
+              ? ( ref($opt{'html_init'})
+                    ? &{$opt{'html_init'}}()
+                    : $opt{'html_init'}
+                )
+              : ''
+        %>
+
 %     } else {
 %
 %       my @menubar = ();
 %     } else {
 %
 %       my @menubar = ();
@@ -330,14 +343,18 @@ Example:
 
               <FORM>
 
 
               <FORM>
 
-                <% $total %> total <% $opt{'name'} %>
+%               if (! $opt{'disable_total'}) {
+                  <% $total %> total <% $opt{'name'} %>
+%               }
 
 
-%               if ( $confmax && $total > $confmax && $type ne 'html-print' ) {
+%               if ( $confmax && $total > $confmax
+%                    && ! $opt{'disable_maxselect'}
+%                    && $type ne 'html-print' )
+%               {
 %                 $cgi->delete('maxrecords');
 %                 $cgi->param('_dummy', 1);
 
 %#                 ( show <SELECT NAME="maxrecords" onChange="this.form.submit();">
 %                 $cgi->delete('maxrecords');
 %                 $cgi->param('_dummy', 1);
 
 %#                 ( show <SELECT NAME="maxrecords" onChange="this.form.submit();">
-                  ( show <SELECT NAME="maxrecords" onChange="window.location = '<% $cgi->self_url %>;maxrecords=' + this.options[this.selectedIndex].value;">
 
 %                   foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
                   <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
 
 %                   foreach my $max ( map { $_ * $confmax } qw( 1 5 10 25 ) ) {
                   <OPTION VALUE="<% $max %>" <% ( $maxrecords == $max ) ? 'SELECTED' : '' %>><% $max %></OPTION>
@@ -770,7 +787,7 @@ if ( $opt{'disableable'} ) {
 
 }
 
 
 }
 
-my $type = $cgi->param('_type') =~ /^(csv|\w*\.xls|html(-print)?)$/
+my $type = $cgi->param('_type') =~ /^(csv|\w*\.xls|select|html(-print)?)$/
            ? $1 : 'html';
 
 my $limit = '';
            ? $1 : 'html';
 
 my $limit = '';