adjustments for 3.x, #33852
authorMark Wells <mark@freeside.biz>
Mon, 27 Apr 2015 06:58:08 +0000 (23:58 -0700)
committerMark Wells <mark@freeside.biz>
Mon, 27 Apr 2015 06:58:08 +0000 (23:58 -0700)
FS/FS/ClientAPI/MyAccount/quotation.pm
ng_selfservice/quotation.php

index 90c2ace..f3067f1 100644 (file)
@@ -5,7 +5,7 @@ use FS::Record qw(qsearch qsearchs);
 use FS::quotation;
 use FS::quotation_pkg;
 
-our $DEBUG = 1;
+our $DEBUG = 0;
 
 sub _custoragent_session_custnum {
   FS::ClientAPI::MyAccount::_custoragent_session_custnum(@_);
@@ -58,6 +58,7 @@ Returns a hashref describing the current quotation, containing:
 
 =cut
 
+use Data::Dumper;
 sub quotation_info {
   my $p = shift;
 
@@ -69,13 +70,22 @@ sub quotation_info {
   warn "quotation_info #".$quotation->quotationnum
     if $DEBUG;
 
-  # code reuse ftw
   my $null_escape = sub { @_ };
-  my ($sections) = $quotation->_items_sections(escape => $null_escape);
-  foreach my $section (@$sections) {
-    $section->{'detail_items'} =
-      [ $quotation->_items_pkg('section' => $section, escape_function => $null_escape) ]; 
-  }
+  # 3.x only; 4.x quotation redesign uses actual sections for this
+  # and isn't a weird hack
+  my @items =
+    map { $_->{'pkgnum'} = $_->{'preref_html'}; $_ }
+    $quotation->_items_pkg(escape_function => $null_escape,
+                           preref_callback => sub { shift->quotationpkgnum });
+  push @items, $quotation->_items_total();
+
+  my $sections = [
+    { 'description' => 'Estimated Charges',
+      'detail_items' => \@items
+    }
+  ];
+  warn Dumper $sections;
+
   return { 'error' => '', 'sections' => $sections }
 }
 
index cf45543..acccf9c 100644 (file)
@@ -58,34 +58,46 @@ if ( isset($quotation['sections']) and count($quotation['sections']) > 0 ) {
     );
     $row = 0;
     foreach ( $section['detail_items'] as $detail ) {
-      print(
-        '<TR CLASS="row' . $row . '">'.
-        '<TD>'
-      );
-      if ( $detail['pkgnum'] ) {
+      if (isset($detail['description'])) {
+        print(
+          '<TR CLASS="row' . $row . '">'.
+          '<TD>'
+        );
+        if ( $detail['pkgnum'] ) {
+          print(
+            '<A HREF="quotation_remove_pkg.php?pkgnum=' .
+            $detail['pkgnum'] . '">'.
+            '<IMG SRC="images/cross.png" /></A>'
+          );
+        }
+        print(
+          '</TD>'.
+          '<TD>'. htmlspecialchars($detail['description']). '</TD>'.
+          '<TD CLASS="amount">'. $detail['amount']. '</TD>'.
+          '</TR>'. "\n"
+        );
+        $row = 1 - $row;
+      } else {
+        # total rows; a 3.x-ism
         print(
-          '<A HREF="quotation_remove_pkg.php?pkgnum=' .
-          $detail['pkgnum'] . '">'.
-          '<IMG SRC="images/cross.png" /></A>'
+          '<TR CLASS="total">'.
+          '<TD></TD>'.
+          '<TD>'. htmlspecialchars($detail['total_item']). '</TD>'.
+          '<TD CLASS="amount">'. $detail['total_amount']. '</TD>'.
+          '</TR>'."\n"
         );
       }
+    }
+    if (isset($section['subtotal'])) {
       print(
-        '</TD>'.
-        '<TD>'. htmlspecialchars($detail['description']). '</TD>'.
-        '<TD CLASS="amount">'. $detail['amount']. '</TD>'.
-        '</TR>'. "\n"
+        '<TR CLASS="total">'.
+        '<TD></TD>'.
+        '<TD>Total</TD>'.
+        '<TD CLASS="amount">'. $section['subtotal']. '</TD>'.
+        '</TR>'
       );
-      $row = 1 - $row;
     }
-    print(
-      '<TR CLASS="total">'.
-      '<TD></TD>'.
-      '<TD>Total</TD>'.
-      '<TD CLASS="amount">'. $section['subtotal']. '</TD>'.
-      '</TR>'.
-      '</TABLE>'.
-      "\n"
-    );
+    print "</TABLE>\n";
   } # foreach $section
 }