proper use of date_format config for international date formats, RT#7009
[freeside.git] / httemplate / edit / elements / ApplicationCommon.html
index 181430c..7b1050a 100644 (file)
@@ -54,7 +54,7 @@ Examples:
 
 <TR>
   <TD ALIGN="right">Date: </TD>
-  <TD><B><% time2str("%D", $src->_date) %></B></TD>
+  <TD><B><% time2str($date_format, $src->_date) %></B></TD>
 </TR>
 
 <TR>
@@ -86,20 +86,36 @@ Examples:
 <BR>
 
 <SCRIPT TYPE="text/javascript">
+function clear_amounts() {
+  var rownum=0
+  var table = document.getElementById('ApplicationTable');
+  for (var row = 2; table.rows[row]; row++)
+  {
+    var inputs = table.rows[row].getElementsByTagName('input');
+    if ( !inputs.length ) {
+      break;
+    }
+    inputs.item(0).value = ''; // amount
+  }
+
+}
+
 function changed(what) {
   dst = what.options[what.selectedIndex].value;
 
   if ( dst == '' ) {
     what.form.submit.disabled=true;
-%if ($src_pkey eq 'crednum') {
+%if ($use_sub_dst_thing && $src_pkey eq 'crednum') {
     what.form.tax_button.disabled=true;
+    what.form.clear_button.disabled=true;
 %}
     return true;
   }
 
   what.form.submit.disabled=false;
-%if ($src_pkey eq 'crednum') {
+%if ($use_sub_dst_thing && $src_pkey eq 'crednum') {
   what.form.tax_button.disabled=false;
+  what.form.clear_button.disabled=false;
 %}
 
 % foreach my $dst ( @dst ) {
@@ -184,7 +200,18 @@ function set_amount_color(what) {
 Apply to:
 
 % if ($use_sub_dst_thing && $src_pkey eq 'crednum') {
-<CENTER><BUTTON TYPE="button" NAME="tax_button" ID="tax_button" onClick="do_calculate_tax(this);" DISABLED>Calculate Tax</BUTTON></CENTER>
+<CENTER>
+  <TABLE>
+    <TR>
+      <TD>
+        <BUTTON TYPE="button" NAME="tax_button" ID="tax_button" onClick="do_calculate_tax(this);" DISABLED>Calculate Tax</BUTTON>
+      </TD>
+      <TD>
+        <BUTTON TYPE="button" NAME="clear_button" ID="clear_button" onClick="clear_amounts(this);" DISABLED>Clear Amounts</BUTTON>
+      </TD>
+    </TR>
+  </TABLE>
+</CENTER>
 <% include( '/elements/xmlhttp.html',
             'url' =>  $p.'misc/xmlhttp-calculate_taxes.html',
             'subs' => [ 'calculate_taxes' ],
@@ -198,6 +225,8 @@ function show_taxes(arg) {
   var button = document.getElementById('tax_button');
   button.disabled = false;
   button.innerHTML = 'Calculate Tax';
+  button = document.getElementById('clear_button');
+  button.disabled = false;
 
   var error = argsHash['error'];
 
@@ -256,6 +285,8 @@ function show_taxes(arg) {
 function do_calculate_tax (what) {
   what.innerHTML = 'Calculating....';
   what.disabled = true;
+  var button = document.getElementById('clear_button');
+  button.disabled = true;
   var taxed_items = new Array();
   var table = document.getElementById('ApplicationTable');
   for (var row = 2; table.rows[row]; row++)
@@ -267,7 +298,7 @@ function do_calculate_tax (what) {
     var taxed_item = new Array(
       inputs.item(1).value, // billpkgnum
       inputs.item(3).value, // s_or_r
-      inputs.item(0).value  // amount
+      inputs.item(0).value || 0  // amount
     );
     taxed_items.push(taxed_item);
   }
@@ -283,6 +314,7 @@ function do_change_amount (what) {
   var amount_cell = document.getElementById('original_amount');
   var inputs = amount_cell.getElementsByTagName('input');
   if (inputs.length) {
+    src_amount_changed();
     amount_cell.innerHTML = '<B><% $money_char %></B>' + inputs.item(0).value;
   } else {
     amount_cell.innerHTML = '<% $money_char %>';
@@ -298,11 +330,16 @@ function do_change_amount (what) {
   }
 }
 
-function src_amount_changed (what) {
-  what.form.src_amount.value = what.value;
-  var unapplied_cell = document.getElementById('unapplied_amount');
-  unapplied_cell.innerHTML = '<B><% $money_char %>' + what.value + '</B>';
-  set_amount_color(what);
+function src_amount_changed () {
+  //alert('src_amount_changed called');
+  var entered_amount = document.getElementById('entered_amount');
+  if ( entered_amount ) {
+    entered_amount.form.src_amount.value = entered_amount.value;
+    var unapplied_cell = document.getElementById('unapplied_amount');
+    unapplied_cell.innerHTML = '<B><% $money_char %>' + entered_amount.value + '</B>';
+    set_amount_color(entered_amount);
+  }
+  return true;
 }
 
 </SCRIPT>
@@ -317,7 +354,7 @@ function src_amount_changed (what) {
 <OPTION VALUE="">Select <% $dst_thing %>
 
 % foreach my $dst ( @dst ) { 
-  <OPTION<% $dst->$dst_pkey eq $dst_pkeyvalue ? ' SELECTED' : '' %> VALUE="<% $dst->$dst_pkey %>">#<% $dst->$dst_pkey %> - <% time2str("%D", $dst->_date) %> - $<% $dst->$dst_unapplied %>
+  <OPTION<% $dst->$dst_pkey eq $dst_pkeyvalue ? ' SELECTED' : '' %> VALUE="<% $dst->$dst_pkey %>">#<% $dst->$dst_pkey %> - <% time2str($date_format, $dst->_date) %> - $<% $dst->$dst_unapplied %>
 % } 
 
 </SELECT>
@@ -335,7 +372,15 @@ function src_amount_changed (what) {
 </TABLE>
 
 <BR>
-<CENTER><INPUT TYPE="submit" VALUE="Apply" NAME="submit" ID="submit" DISABLED></CENTER>
+<CENTER><INPUT TYPE="submit"
+               VALUE="Apply"
+               NAME="submit"
+               ID="submit"
+% if ($use_sub_dst_thing && $can_change_credit) {
+               onClick="src_amount_changed()"
+% }
+               DISABLED
+></CENTER>
 
 </FORM>
 
@@ -354,7 +399,8 @@ function myOnLoadFunction () {
 my %opt = @_;
 
 my $conf = new FS::Conf;
-my $money_char = $conf->config('money_char') || '$';
+my $money_char  = $conf->config('money_char')  || '$';
+my $date_format = $conf->config('date_format') || '%m/%d/%Y';
 
 my $src_thing = ucfirst($opt{'src_thing'});
 my $src_table = $opt{'src_table'};