Merge branch 'master' of git.freeside.biz:/home/git/freeside
authorIvan Kohler <ivan@freeside.biz>
Sun, 11 Aug 2013 23:18:24 +0000 (16:18 -0700)
committerIvan Kohler <ivan@freeside.biz>
Sun, 11 Aug 2013 23:18:24 +0000 (16:18 -0700)
16 files changed:
FS/FS/cust_bill_pkg.pm
FS/FS/cust_pkg.pm
httemplate/edit/process/change-cust_pkg.html
httemplate/elements/location.html
httemplate/elements/tr-input-pkg-quantity.html [new file with mode: 0644]
httemplate/misc/change_pkg.cgi
httemplate/misc/order_pkg.html
httemplate/misc/suspend_cust.html
httemplate/search/pay_batch.cgi
httemplate/search/unearned_detail.html
httemplate/view/cust_main/packages/location.html
httemplate/view/cust_main/packages/package.html
httemplate/view/cust_main/packages/status.html
rt/lib/RT/Interface/Web.pm
rt/lib/RT/Interface/Web_Vendor.pm
rt/share/html/Ticket/Elements/EditBasics

index 572fe79..f94bf9b 100644 (file)
@@ -955,8 +955,8 @@ Returns an SQL expression for the sum of payments applied to this item.
 
 sub paid_sql {
   my ($class, $start, $end, %opt) = @_;
-  my $s = $start ? "AND cust_bill_pay._date <= $start" : '';
-  my $e = $end   ? "AND cust_bill_pay._date >  $end"   : '';
+  my $s = $start ? "AND cust_pay._date <= $start" : '';
+  my $e = $end   ? "AND cust_pay._date >  $end"   : '';
   my $setuprecur = 
     $opt{setuprecur} =~ /^s/ ? 'setup' :
     $opt{setuprecur} =~ /^r/ ? 'recur' :
@@ -965,6 +965,7 @@ sub paid_sql {
 
   my $paid = "( SELECT COALESCE(SUM(cust_bill_pay_pkg.amount),0)
      FROM cust_bill_pay_pkg JOIN cust_bill_pay USING (billpaynum)
+                            JOIN cust_pay      USING (paynum)
      WHERE cust_bill_pay_pkg.billpkgnum = cust_bill_pkg.billpkgnum
            $s $e $setuprecur )";
 
@@ -983,8 +984,8 @@ sub paid_sql {
 
 sub credited_sql {
   my ($class, $start, $end, %opt) = @_;
-  my $s = $start ? "AND cust_credit_bill._date <= $start" : '';
-  my $e = $end   ? "AND cust_credit_bill._date >  $end"   : '';
+  my $s = $start ? "AND cust_credit._date <= $start" : '';
+  my $e = $end   ? "AND cust_credit._date >  $end"   : '';
   my $setuprecur = 
     $opt{setuprecur} =~ /^s/ ? 'setup' :
     $opt{setuprecur} =~ /^r/ ? 'recur' :
@@ -993,6 +994,7 @@ sub credited_sql {
 
   my $credited = "( SELECT COALESCE(SUM(cust_credit_bill_pkg.amount),0)
      FROM cust_credit_bill_pkg JOIN cust_credit_bill USING (creditbillnum)
+                               JOIN cust_credit      USING (crednum)
      WHERE cust_credit_bill_pkg.billpkgnum = cust_bill_pkg.billpkgnum
            $s $e $setuprecur )";
 
index d885abf..89c683e 100644 (file)
@@ -1732,6 +1732,11 @@ New pkgpart (see L<FS::part_pkg>).
 
 New refnum (see L<FS::part_referral>).
 
+=item quantity
+
+New quantity; if unspecified, the new package will have the same quantity
+as the old.
+
 =item cust_pkg
 
 "New" (existing) FS::cust_pkg object.  The package's services and other 
@@ -1767,9 +1772,6 @@ sub change {
   my $self = shift;
   my $opt = ref($_[0]) ? shift : { @_ };
 
-#  my ($custnum, $pkgparts, $remove_pkgnum, $return_cust_pkg, $refnum) = @_;
-#    
-
   my $conf = new FS::Conf;
 
   # Transactionize this whole mess
@@ -1790,10 +1792,6 @@ sub change {
 
   my $time = time;
 
-  #$hash{$_} = $self->$_() foreach qw( last_bill bill );
-    
-  #$hash{$_} = $self->$_() foreach qw( setup );
-
   $hash{'setup'} = $time if $self->setup;
 
   $hash{'change_date'} = $time;
@@ -1865,6 +1863,7 @@ sub change {
   }
 
   $hash{'contactnum'} = $opt->{'contactnum'} if $opt->{'contactnum'};
+  $hash{'quantity'} = $opt->{'quantity'} || $self->quantity;
 
   my $cust_pkg;
   if ( $opt->{'cust_pkg'} ) {
@@ -2098,7 +2097,9 @@ The date for the package change.  Required, and must be in the future.
 
 =item locationnum
 
-The pkgpart and locationnum of the new package, with the same 
+=item quantity
+
+The pkgpart. locationnum, and quantity of the new package, with the same 
 meaning as in C<change>.
 
 =back
@@ -2130,7 +2131,9 @@ sub change_later {
         if $opt->{'pkgpart'} and $opt->{'pkgpart'} != $change_to->pkgpart;
     my $new_locationnum = $opt->{'locationnum'}
         if $opt->{'locationnum'} and $opt->{'locationnum'} != $change_to->locationnum;
-    if ( $new_pkgpart or $new_locationnum ) {
+    my $new_quantity = $opt->{'quantity'}
+        if $opt->{'quantity'} and $opt->{'quantity'} != $change_to->quantity;
+    if ( $new_pkgpart or $new_locationnum or $new_quantity ) {
       # it hasn't been billed yet, so in principle we could just edit
       # it in place (w/o a package change), but that's bad form.
       # So change the package according to the new options...
@@ -2168,12 +2171,16 @@ sub change_later {
       if $opt->{'pkgpart'} and $opt->{'pkgpart'} != $self->pkgpart;
   my $new_locationnum = $opt->{'locationnum'}
       if $opt->{'locationnum'} and $opt->{'locationnum'} != $self->locationnum;
-  return '' unless $new_pkgpart or $new_locationnum; # wouldn't do anything
+  my $new_quantity = $opt->{'quantity'}
+      if $opt->{'quantity'} and $opt->{'quantity'} != $self->quantity;
+
+  return '' unless $new_pkgpart or $new_locationnum or $new_quantity; # wouldn't do anything
 
   my %hash = (
     'custnum'     => $self->custnum,
     'pkgpart'     => ($opt->{'pkgpart'}     || $self->pkgpart),
     'locationnum' => ($opt->{'locationnum'} || $self->locationnum),
+    'quantity'    => ($opt->{'quantity'}    || $self->quantity),
     'start_date'  => $date,
   );
   my $new = FS::cust_pkg->new(\%hash);
index 9d06d8e..0d571de 100644 (file)
@@ -27,7 +27,7 @@ my $cust_pkg = qsearchs({
 die 'unknown pkgnum' unless $cust_pkg;
 
 my %change = map { $_ => scalar($cgi->param($_)) }
-                 qw( locationnum pkgpart );
+                 qw( locationnum pkgpart quantity );
 
 $change{'keep_dates'} = 1;
 
index 41a67a0..df5106c 100644 (file)
@@ -244,6 +244,42 @@ Example:
 %# Placeholders
 <INPUT TYPE="hidden" NAME="<%$pre%>cachenum" VALUE="">
 <INPUT TYPE="hidden" NAME="<%$pre%>addr_clean" VALUE="">
+
+<SCRIPT TYPE="text/javascript">
+// the strictly correct way to append something to window.onload
+window.addEventListener('load', function() {
+  var clear_coords_ids = [
+    '<%$pre%>latitude',
+    '<%$pre%>longitude',
+    'enter_censustract',
+    '<%$pre%>district'
+  ];
+  function clear_coords() {
+    for (var i=0; i < clear_coords_ids.length; i++) {
+      var el = document.getElementById(clear_coords_ids[i]);
+      if ( el ) {
+        el.value = '';
+      }
+    }
+  }
+  var clear_coords_on_change = [
+    '<%$pre%>address1',
+    '<%$pre%>address2',
+    '<%$pre%>city',
+    '<%$pre%>state',
+    '<%$pre%>zip',
+    '<%$pre%>country',
+  ];
+  for (var i=0; i < clear_coords_on_change.length; i++) {
+    var el = document.getElementById(clear_coords_on_change[i]);
+    if ( el ) {
+      // because some of these already have onchange triggers
+      el.addEventListener('change', clear_coords);
+    }
+  }
+});
+</SCRIPT>
+
 <%init>
 
 my %opt = @_;
diff --git a/httemplate/elements/tr-input-pkg-quantity.html b/httemplate/elements/tr-input-pkg-quantity.html
new file mode 100644 (file)
index 0000000..7ade573
--- /dev/null
@@ -0,0 +1,15 @@
+% if ( FS::Conf->new->exists('invoice-unitprice') or $curr_value > 1 ) {
+  <TR>
+    <TH ALIGN="right"><% mt('Quantity') |h %>
+    </TH>
+    <TD>
+      <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $curr_value |h %>">
+    </TD>
+  </TR>
+% } else {
+  <INPUT TYPE="hidden" NAME="quantity" VALUE="1">
+% }
+<%init>
+my %opt = @_;
+my $curr_value = $cgi->param('quantity') || $opt{'curr_value'} || 1;
+</%init>
index 7425fbf..923be71 100755 (executable)
                'cust_main'  => $cust_main,
   &>
 
+  <& /elements/tr-input-pkg-quantity.html,
+               'curr_value' => $cust_pkg->quantity
+  &>
+
   <& /elements/tr-select-cust_location.html,
                'cgi'       => $cgi,
                'cust_main' => $cust_main,
@@ -94,7 +98,7 @@ my $title = "Change Package";
 if ( $cust_pkg->change_to_pkgnum ) {
   my $change_to = FS::cust_pkg->by_key($cust_pkg->change_to_pkgnum);
   $cgi->param('delay', 1);
-  foreach(qw( start_date pkgpart locationnum )) {
+  foreach(qw( start_date pkgpart locationnum quantity )) {
     $cgi->param($_, $change_to->get($_));
   }
   $title = "Edit Scheduled Package Change";
index a257e53..66c405a 100644 (file)
     &>
 % }
 
-% if ( $conf->exists('invoice-unitprice') ) {
-    <TR>
-      <TH ALIGN="right"><% mt('Quantity') |h %> </TD>
-      <TD>
-        <INPUT TYPE="text" NAME="quantity" SIZE=4 VALUE="<% $quantity %>">
-      </TD>
-    </TR>
-% } else {
-    <INPUT TYPE="hidden" NAME="quantity" VALUE="1">
-% }
+<& /elements/tr-input-pkg-quantity.html, curr_value => $quantity &>
 
 <TR>
   <TH ALIGN="right"><% mt('Start date') |h %> </TD>
index b41f36f..e0d17f3 100644 (file)
@@ -40,7 +40,7 @@ toggle(false);
 STYLE="margin-left:auto; margin-right:auto">
 <& /elements/tr-select-reason.html,
              'field'          => 'reasonnum',
-             'reason_class'   => 'C',
+             'reason_class'   => 'S',
              'cgi'            => $cgi,
              'control_button' => "document.getElementById('confirm_suspend_cust_button')",
 &>
index 620996a..40df5aa 100755 (executable)
                                      'Type',
                                      'First Download',
                                      'Last Upload',
-                                      '', # requests
-                                      '', # req amt
-                                      '', # payments
-                                      '', # pay amt
+                                      { label => 'Requested', colspan => 2 },
+                                      '',
+                                      { label => 'Paid', colspan => 2 },
+                                      '',
                                      'Status',
                                     ],
+                 'header2'       => [ '',
+                                      '',
+                                      '',
+                                      '',
+                                      '',
+                                      'Items',
+                                      'Amount',
+                                      'Items',
+                                      'Amount',
+                                      '',
+                                    ],
                 'align'         => 'rcllrrrrc',
                 'fields'        => [ 'batchnum',
                                      sub { 
@@ -49,7 +60,7 @@
                                      },
                                      sub {
                                         my $c = FS::cust_pay_batch->count('batchnum = '.$_[0]->batchnum);
-                                        $c ? "$c requested" : ''
+                                        $c || ''
                                       },
                                       sub {
                                         my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
@@ -62,7 +73,7 @@
                                       },
                                       sub {
                                         my $c = FS::cust_pay->count('batchnum = '.$_[0]->batchnum);
-                                        $c ? "$c paid" : ''
+                                        $c || '';
                                       },
                                       sub {
                                         my $st = "SELECT SUM(paid) from cust_pay WHERE batchnum=" . shift->batchnum;
index 285fb50..b87a747 100644 (file)
@@ -105,6 +105,10 @@ my $agentnums_sql =
 
 my @where = ( $agentnums_sql );
 
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+  push @where, "cust_main.agentnum = $1";
+}
+
 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
 
 if ( $cgi->param('status') =~ /^([a-z]+)$/ ) {
@@ -191,12 +195,16 @@ push @select, "$unearned_sql AS unearned_revenue";
 # last payment/credit date
 my %t = (pay => 'cust_bill_pay', credit => 'cust_credit_bill');
 foreach my $x (qw(pay credit)) {
-  my $table = $t{$x};
-  my $link = $table.'_pkg';
-  my $pkey = dbdef->table($table)->primary_key;
-  my $last_date_sql = "SELECT MAX(_date) 
-  FROM $table JOIN $link USING ($pkey)
-  WHERE $link.billpkgnum = cust_bill_pkg.billpkgnum 
+  my $table     = "cust_$x";
+  my $link_bill = $t{$x};
+  my $link_pkg  = $link_bill.'_pkg';
+  my %pkey = map { $_ => dbdef->table($_)->primary_key }
+    ( $table, $link_bill );
+
+  my $last_date_sql = "SELECT MAX($table._date) 
+  FROM $table JOIN $link_bill USING ($pkey{$table})
+              JOIN $link_pkg  USING ($pkey{$link_bill})
+  WHERE $link_pkg.billpkgnum = cust_bill_pkg.billpkgnum 
   AND $table._date <= $unearned";
   push @select, "($last_date_sql) AS last_$x";
 }
index 01cbc0f..5ff2b1e 100644 (file)
@@ -70,8 +70,8 @@ sub pkg_change_location_link {
     'label'       => emt('Change location'),
     'actionlabel' => emt('Change'),
     'cust_pkg'    => $cust_pkg,
-    'width'       => 763,
-    'height'      => 380,
+    'width'       => 960,
+    'height'      => 490,
   );
 }
 
index 596a473..7df0869 100644 (file)
@@ -280,8 +280,8 @@ sub pkg_change_link {
     'label'       => emt('Change package'),
     'actionlabel' => emt('Change'),
     'cust_pkg'    => $cust_pkg,
-    'width'       => 763,
-    'height'      => 480,
+    'width'       => 960,
+    'height'      => 490,
   );
 }
 
@@ -295,8 +295,8 @@ sub pkg_change_location_link {
     'label'       => emt('Change location'),
     'actionlabel' => emt('Change'),
     'cust_pkg'    => $cust_pkg,
-    'width'       => 763,
-    'height'      => 380,
+    'width'       => 960,
+    'height'      => 490,
   );
 }
 
index 6894a4e..70b623c 100644 (file)
@@ -645,8 +645,8 @@ sub pkg_change_later_link {
     'label'       => emt('Reschedule'),
     'actionlabel' => emt('Edit scheduled change for'),
     'cust_pkg'    => $cust_pkg,
-    'width'       => 763,
-    'height'      => 480,
+    'width'       => 960,
+    'height'      => 490,
   )
 }
 
index bdad213..4a6bfda 100644 (file)
@@ -2983,6 +2983,7 @@ sub ProcessTicketDates {
         Starts
         Started
         Due
+        WillResolve
     );
 
     #Run through each field in this list. update the value if apropriate
index fb2b807..a5f5b88 100644 (file)
@@ -254,8 +254,20 @@ sub ProcessTicketBasics {
         TimeLeft
         Type
         Queue
+        WillResolve
     );
 
+    # the UI for editing WillResolve through Ticket Basics should allow 
+    # setting it to null
+    my $to_date = delete($ARGSRef->{'WillResolve_Date'});
+    my $DateObj = RT::Date->new($session{'CurrentUser'});
+    if ( $to_date ) {
+        $DateObj->Set(Format => 'unknown', Value => $to_date);
+    } else {
+        $DateObj->Set(Value => 0);
+    }
+    $ARGSRef->{'WillResolve'} = $DateObj->ISO;
+
     if ( $ARGSRef->{'Queue'} and ( $ARGSRef->{'Queue'} !~ /^(\d+)$/ ) ) {
         my $tempqueue = RT::Queue->new($RT::SystemUser);
         $tempqueue->Load( $ARGSRef->{'Queue'} );
index ae70bd8..e7a1662 100755 (executable)
@@ -52,6 +52,7 @@ $InTable => 0
 %defaults => ()
 </%ARGS>
 <%INIT>
+my $WillResolveObj = $TicketObj->WillResolveObj if defined $TicketObj;
 unless ( @fields ) {
     @fields = (
         {   name => 'Subject',
@@ -72,7 +73,10 @@ unless ( @fields ) {
             comp => '/Elements/SelectDate',
             args => {
                 menu_prefix => 'WillResolve',
-                Default => $ARGS{'WillResolve'} || $TicketObj->WillResolveObj->Date,
+                Default => $ARGS{'WillResolve'} || 
+                           (defined($WillResolveObj) 
+                            and $WillResolveObj->Unix > 0 ?
+                              $WillResolveObj->Date : ''),
                 current => 0,
                 ShowTime => 0,
             },