[freeside-commits] branch master updated. c14b35ce12141287e201bba8489b202a1b34b38f

Ivan ivan at 420.am
Sun Aug 25 16:23:18 PDT 2013


The branch, master has been updated
       via  c14b35ce12141287e201bba8489b202a1b34b38f (commit)
      from  d29b455cf176358089f98e2970beaab88195bc62 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c14b35ce12141287e201bba8489b202a1b34b38f
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sun Aug 25 16:23:17 2013 -0700

    continue sales person work: customer and package selection, commissions, reporting.  RT#23402

diff --git a/httemplate/edit/cust_main/top_misc.html b/httemplate/edit/cust_main/top_misc.html
index d8141b5..ebd9b92 100644
--- a/httemplate/edit/cust_main/top_misc.html
+++ b/httemplate/edit/cust_main/top_misc.html
@@ -20,7 +20,9 @@
        <% $cust_main->residential_commercial eq 'Commercial' ? 'CHECKED' : '' %>
   ></TD>
 </TR>
+
 <SCRIPT TYPE="text/javascript">
+
   function rescom_changed(what) {
     if ( what.checked == (what.value == 'Commercial' ) ) {
       document.getElementById('company_row').style.display = '';
@@ -33,11 +35,16 @@
     }
   }
 
+
   var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>;
   var ship_fields = ['address1', 'city', 'state', 'zip', 'country', 
     'latitude', 'longitude', 'district'];
+
   function agent_changed(what) {
     var agentnum = what.value;
+
+%   # unlock/lock service location
+
     var f = what.form;
     if ( ship_locked_agents[agentnum] ) {
 %     # For this agent, the service location (except address2)
@@ -65,7 +72,12 @@
       f['same'].disabled = false;
     }
     samechanged(f['same']);
+
+%   # update sales dropdown
+    salesnum_agentnum_changed(what);
+
   }
+
   <&| /elements/onload.js &>
   agent_changed(document.getElementById('agentnum'))
   </&>
diff --git a/httemplate/elements/tr-select-sales.html b/httemplate/elements/tr-select-sales.html
index 2a2edf0..b69b3d8 100644
--- a/httemplate/elements/tr-select-sales.html
+++ b/httemplate/elements/tr-select-sales.html
@@ -13,7 +13,8 @@ Example:
 
     'label'         => 'Sales Person',
     'empty_label'   => 'Select sales person', #override default 
-    #on already# 'disable_empty' => 1,
+    'disable_empty' => 0, #on byd efault, pass 0 to disable
+    'field'         => 'salesnum', #HTML element name and ID
 
   &>
 
@@ -21,8 +22,8 @@ Example:
 % if ( scalar(@sales) == 0 || $opt{'fixed'} ) { 
 
   <INPUT TYPE  = "hidden"
-         NAME  = "<% $opt{'field'} || 'salesnum' %>"
-         ID    = "<% $opt{'field'} || 'salesnum' %>"
+         NAME  = "<% $field %>"
+         ID    = "<% $id %>"
          VALUE = "<% $salesnum %>"
   >
 
@@ -63,19 +64,99 @@ Example:
 
 % } 
 
+<& /elements/xmlhttp.html,
+              'url'  => $p.'misc/sales.cgi',
+              'subs' => [ 'get_sales' ],
+&>
+<SCRIPT TYPE="text/javascript">
+
+% # false laziness w/ elements/tr-select-cust-part_pkg.html
+
+  function <% $field %>_opt(what, value, text) {
+    var optionName = new Option(text, value, false, false);
+    var length = what.length;
+    what.options[length] = optionName;
+  }
+
+  function <% $field %>_agentnum_changed(what) {
+    what.form.<% $field %>.disabled = 'disabled'; //disable sales dropdown
+
+    agentnum = what.options[what.selectedIndex].value;
+
+    function update_<% $field %>(sales) {
+
+      if ( what.form.<% $field %>.type == 'hidden' ) {
+        what.form.<% $field %>.disabled = ''; //re-enable sales dropdown
+        return;
+      }
+
+      // save the current salesnum
+      var salesnum = what.form.<% $field %>.value;
+
+      // blank the current sales people
+      for ( var i = what.form.<% $field %>.length; i>= 0; i-- )
+        what.form.<% $field %>.options[i] = null;
+
+      // add the new sales people
+
+%     my @pre_options  = $opt{pre_options}  ? @{ $opt{pre_options} } : ();
+%     while ( @pre_options ) { 
+%       my $pre_opt   = shift(@pre_options);
+%       my $pre_label = shift(@pre_options);
+%       #my $selected =  ( $salesnum eq $pre_opt );
+        <% $field %>_opt( what.form.<% $field %>,
+                          <% $pre_opt   |js_string %>,
+                          <% $pre_label |js_string %>
+                        );
+%     }
+
+%     unless ( $opt{'disable_empty'} ) {
+        <% $field %>_opt( what.form.<% $field %>,
+                          '',
+                          <% $opt{'empty_label'} || '(none)' |js_string %>
+                        );
+%     }
+
+      var salesArray = eval('(' + sales + ')' );
+      for ( var s = 0; s < salesArray.length; s=s+2 ) {
+        //surely this should be some kind of JSON structure
+        var salesLabel  = salesArray[s+1];
+        <% $field %>_opt( what.form.<% $field %>, salesArray[s], salesLabel );
+      }
+
+      what.form.<% $field %>.disabled = ''; //re-enable sales dropdown
+
+      //restore salesnum if possible
+      what.form.<% $field %>.value = salesnum;
+
+    }
+
+    get_sales( agentnum,
+               update_<% $field %>
+             );
+  }
+
+  <&| /elements/onload.js &>
+    <% $field %>_agentnum_changed(document.getElementById('agentnum'));
+  </&>
+
+</SCRIPT>
+
 <%init>
 
 my $curuser = $FS::CurrentUser::CurrentUser;
 
 my %opt = @_;
 my $salesnum = $opt{'curr_value'} || $opt{'value'};
+my $field = $opt{'element_name'} || $opt{'field'} || 'salesnum';
+my $id = $opt{'id'} || $opt{'field'} || 'salesnum';
 
 my @sales = qsearch({ 'table'   => 'sales',
                       'hashref' => { 'disabled' => '' },
                       'extra_sql' => ' AND '. $curuser->agentnums_sql,
+                      'order_by'  => 'ORDER BY salesperson',
                    });
 
 my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';
 
-
 </%init>
diff --git a/httemplate/elements/xmlhttp.html b/httemplate/elements/xmlhttp.html
index a9e65c7..2f4f0d5 100644
--- a/httemplate/elements/xmlhttp.html
+++ b/httemplate/elements/xmlhttp.html
@@ -14,17 +14,19 @@ Example:
   );
 
 </%doc>
+<%shared>
+my %initialized = ();#won't work if component is "preloaded"... so don't do that
+</%shared>
 <& /elements/rs_init_object.html &>
 <& /elements/init_overlib.html &>
 <SCRIPT TYPE="text/javascript">
 
 % foreach my $func ( @{$opt{'subs'}} ) { 
 %
-%       my $furl = $url;
-%       $furl =~ s/\"/\\\\\"/; #javascript escape
-%#"
-%  
-
+%   next if $initialized{$key.$func}++;
+%
+%   my $furl = $url;
+%   $furl =~ s/\"/\\\\\"/; #javascript escape (fix gvim syntax: ")
 
     function <%$key%><%$func%>() {
         // count args; build URL
diff --git a/httemplate/misc/sales.cgi b/httemplate/misc/sales.cgi
new file mode 100644
index 0000000..1e56371
--- /dev/null
+++ b/httemplate/misc/sales.cgi
@@ -0,0 +1,27 @@
+<% encode_json( \@return ) %>\
+<%init>
+
+my( $agentnum ) = $cgi->param('arg');
+
+my %hash = ( 'disabled' => '' );
+if ( $agentnum > 0 ) {
+  $hash{'agentnum'} = $agentnum;
+}
+my @sales = qsearch({
+  'table'     => 'sales',
+  'hashref'   => \%hash,
+  'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+  'order_by'  => 'ORDER BY salesperson',
+});
+
+warn scalar(@sales);
+
+my @return = map  {
+                    ( $_->salesnum,
+                      $_->salesperson,
+                    )
+                  }
+                  #sort { $a->salesperson cmp $b->salesperson }
+                  @sales;
+
+</%init>
diff --git a/httemplate/search/report_cust_pkg.html b/httemplate/search/report_cust_pkg.html
index 6cf297c..0a17344 100755
--- a/httemplate/search/report_cust_pkg.html
+++ b/httemplate/search/report_cust_pkg.html
@@ -16,9 +16,24 @@
     <% include( '/elements/tr-select-agent.html',
                    'curr_value'    => scalar( $cgi->param('agentnum') ),
                    'disable_empty' => 0,
+                   'onchange'      => 'agent_changed(this)',
                )
     %>
 
+    <SCRIPT TYPE="text/javascript">
+
+      function agent_changed(what) {
+%       # update sales dropdowns
+        salesnum_agentnum_changed(what);
+        cust_main_salesnum_agentnum_changed(what);
+      }
+
+      <&| /elements/onload.js &>
+      agent_changed(document.getElementById('agentnum'))
+      </&>
+ 
+    </SCRIPT>
+
     <& /elements/tr-select-sales.html,
                   'label'         => 'Customer sales person',
                   'element_name'  => 'cust_main_salesnum',

-----------------------------------------------------------------------

Summary of changes:
 httemplate/edit/cust_main/top_misc.html  |   12 ++++
 httemplate/elements/tr-select-sales.html |   89 ++++++++++++++++++++++++++++-
 httemplate/elements/xmlhttp.html         |   12 ++--
 httemplate/misc/sales.cgi                |   27 +++++++++
 httemplate/search/report_cust_pkg.html   |   15 +++++
 5 files changed, 146 insertions(+), 9 deletions(-)
 create mode 100644 httemplate/misc/sales.cgi




More information about the freeside-commits mailing list