costs for one-time charges, RT#31429
[freeside.git] / httemplate / edit / quick-charge.html
index 666ba82..ec1a580 100644 (file)
@@ -107,14 +107,29 @@ function bill_now_changed (what) {
 % if ( $cust_pkg ) {
 
 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $cust_pkg->pkgnum %>">
-<& /elements/tr-fixed.html,
-  label => 'Amount',
-  field => 'amount',
-  value => $money_char . sprintf('%.2f',$part_pkg->option('setup_fee')),
-&>
+% my $field = '/elements/tr-input-text.html';
+% # don't allow changing these after the fact
+% $field = '/elements/tr-fixed.html' if $billed;
+<& $field,
+  label  => mt('Amount to charge'),
+  field  => 'amount',
+  value  => sprintf('%.2f',$part_pkg->option('setup_fee')),
+  size   => 8,
+  prefix => $money_char,
+&> 
+
+% if ( $curuser->access_right('Edit package definition costs') ) {
+  <& $field,
+    label  => mt('Cost'),
+    field  => 'setup_cost',
+    value  => sprintf('%.2f',$part_pkg->setup_cost),
+    size   => 8,
+    prefix => $money_char,
+  &> 
+% }
 
 %   if ( $conf->exists('invoice-unitprice') ) {
-<& /elements/tr-fixed.html,
+<& $field,
   label => 'Quantity',
   field => 'quantity',
   value => $cust_pkg->quantity
@@ -137,28 +152,47 @@ function bill_now_changed (what) {
 % #display the future or past charge date, but don't allow changes
 % # XXX we probably _could_ let as-yet unbilled charges be rescheduled, but
 % # there's no compelling need yet
-%   if ( $cust_pkg->setup or $cust_pkg->start_date ) {
-%     my $label = $cust_pkg->setup ? emt('Billed on') : emt('Will be billed');
-%     my $field = $cust_pkg->setup ? 'setup' : 'start_date';
+%   if ( $billed ) {
       <& /elements/tr-fixed-date.html,
-        label => $label,
-        value => $cust_pkg->get($field)
+        label => emt('Billed on'),
+        value => $cust_pkg->get('setup')
       &>
-%   } # else we don't show anything here
+%   } else {
+      <& /elements/tr-input-date-field.html,
+        {
+          name    => 'start_date',
+          label   => emt('Will be billed'),
+          value   => $cust_pkg->get('start_date'),
+          format  => $date_format,
+          noinit  => 1,
+        }
+      &>
+%   }
+
 % } else { # new one-time charge
 
-<TR>
-  <TD ALIGN="right"><% mt('Amount') |h %> </TD>
-  <TD>
-    <% $money_char %><INPUT TYPE       = "text"
-                            NAME       = "amount"
-                            SIZE       = 6
-                            VALUE      = "<% $amount %>"
-                            onChange   = "return enable_quick_charge(event)"
-                            onKeyPress = "return enable_quick_charge(event)"
-                     >
-  </TD>
-</TR>
+    <TR>
+      <TD ALIGN="right"><% mt('Amount to charge') |h %> </TD>
+      <TD>
+        <% $money_char %><INPUT TYPE       = "text"
+                                NAME       = "amount"
+                                SIZE       = 8
+                                VALUE      = "<% $amount %>"
+                                onChange   = "return enable_quick_charge(event)"
+                                onKeyPress = "return enable_quick_charge(event)"
+                         >
+      </TD>
+    </TR>
+
+%   if ( $curuser->access_right('Edit package definition costs') ) {
+      <& /elements/tr-input-text.html,
+           label  => mt('Cost'),
+           field  => 'setup_cost',
+           value  => $setup_cost,
+           size   => 8,
+           prefix => $money_char,
+      &> 
+%   }
 
 %   if ( $conf->exists('invoice-unitprice') ) {
     <TR>
@@ -187,8 +221,9 @@ function bill_now_changed (what) {
     >
     <% mt('with terms') |h %> 
     <& /elements/select-terms.html,
-                 'curr_value'  => scalar($cgi->param('invoice_terms')),
-                 'disabled'    => ( $cgi->param('bill_now') ? 0 : 1 ),
+         'curr_value' => scalar($cgi->param('invoice_terms')),
+         'disabled'   => ( $cgi->param('bill_now') ? 0 : 1 ),
+         'agentnum'   => $cust_main->agentnum,
     &>
   </TD>
 </TR>
@@ -403,6 +438,11 @@ if ( $cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
   $amount = $1;
 }
 
+my $setup_cost = '';
+if ( $cgi->param('setup_cost') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ ) {
+  $setup_cost = $1;
+}
+
 my $quantity = 1;
 if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) {
   $quantity = $1;
@@ -416,9 +456,12 @@ my $default_terms;
 if ( $cust_main->invoice_terms ) {
   $default_terms = emt("Customer default ([_1])", $cust_main->invoice_terms);
 } else {
-  $default_terms = emt("Default ([_1])",
-            ($conf->config('invoice_default_terms') || emt('Payable upon receipt'))
-                      );
+  $default_terms =
+    emt( "Default ([_1])",
+         ( $conf->config('invoice_default_terms', $cust_main->agentnum)
+             || emt('Payable upon receipt')
+         )
+       );
 }
 
 my @description;
@@ -433,6 +476,7 @@ if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
 }
 
 my $part_pkg;
+my $billed = 0;
 
 if ( $cust_pkg ) { # set defaults
   $part_pkg = $cust_pkg->part_pkg;
@@ -444,6 +488,7 @@ if ( $cust_pkg ) { # set defaults
       push @description, $part_pkg->option("additional_info$i",1);
     }
   }
+  $billed = $cust_pkg->get('setup') ? 1 : 0;
 }
 
 </%init>