Fixing printing issue with coupons.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 9 Dec 2016 20:53:14 +0000 (15:53 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 9 Dec 2016 20:53:14 +0000 (15:53 -0500)
Put the print coupon id's into the sql so we only get the ones they
selected at first.

models/admin/ajax/pdfCoupons.php
views/front/coupons/memberDetail.html

index 71f1490..167c859 100644 (file)
@@ -67,7 +67,7 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons
      */
     public function modelAction( $actionData = false )
     {
-        $coupons = $categories = array();
+        $coupons = $categories = $printCoupons = array();
 
         $where   = "current_date BETWEEN T.start_date AND T.end_date AND T.status = 10";
 
@@ -75,6 +75,16 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons
             $where .= " AND T.ref_dest = " . $_REQUEST['member'];
         }
 
+        // check to see if Print selected is on
+        if (isset($_REQUEST['printSel']) && $_REQUEST['printSel']) {
+            $printAll = false;
+            foreach ($_REQUEST as $posted => $value) {
+                if (preg_match('%coupon-id-(\d+)%', $posted, $matches)) {
+                    $printCoupons[] = $matches[1];
+                }
+            }
+            $where .= " AND T.id in (" . implode( ',', $printCoupons)  . ")";
+        }
         $coupons = $this->getList( $where );
 
         if ( isset( $coupons ) && !empty( $coupons ) ) {
@@ -91,7 +101,7 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons
                     $address[] = $mInfo['city'];
                 }
                 if ( $mInfo['state'] ) {
-                    $address[] = $mInfo['state'];
+                    $address[] = $mInfo['state']['name'];
                 }
                 if ( $mInfo['zip'] ) {
                     $address[] = $mInfo['zip'];
@@ -100,9 +110,6 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons
             }
         }
 
-        //echo '<pre>$coupons: ' . print_r( $coupons, true ) . '</pre>';
-        //exit;
-
         $pdf = new glmCoupon('a4', 'portrait');
         $pdf->selectFont(GLM_MEMBERS_COUPONS_PLUGIN_PATH . "/fonts/Helvetica.afm");
         $pdf->ezSetMargins(90, 30, 30, 35);
@@ -116,41 +123,23 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons
         $pdf->closeObject();
         $pdf->addObject($all, 'all');
         $coupon_lft_opt = array(
-            'left' => 5,
-            'right' => 280,
-            'justification'=>'left'
+            'left'          => 5,
+            'right'         => 280,
+            'justification' =>'left'
         );
         $coupon_rgt_opt = array(
-            'left' => 290,
-            'justification'=>'left'
+            'left'          => 290,
+            'justification' =>'left'
         );
 
-        // check to see if Print selected is on
-        $printIds = array();
-        if (isset($_REQUEST['printSel']) && $_REQUEST['printSel']) {
-            $printAll = false;
-            foreach ($_REQUEST as $posted => $value) {
-                if (preg_match('%coupon-id-(\d+)%', $posted, $matches)) {
-                    //echo '<pre>' . print_r($matches, true) . '</pre>';
-                    $printIds[$matches[1]] = $matches[1];
-                }
-            }
-        } else {
-            $printAll = true;
-        }
-        $minY             = $y   // y is verticle position starting at lower left hand corner
+        $minY             = $y   // y is vertical position starting at lower left hand corner
                           = 800;
         $x                = 20;  // x is horizontal position starting at lover left hand corner
         $coupon_width     = 265; //
         $mycount = $count = 1;   //
 
         $options = $coupon_lft_opt;
-        foreach ( $coupons as $coupon ) {
-            if ( !$printAll && !in_array( $coupon['id'], $printIds ) ) {
-                continue;
-            } else if ( !$printAll && in_array( $coupon['id'], $printIds ) ) {
-                unset( $printIds[$coupon['id']] );
-            }
+        foreach ( $coupons as &$coupon ) {
             $reset              = $y;
             $val                = array();
             $val['header']      = iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon['name']);
@@ -212,13 +201,13 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons
                 }
                 if ($y < 180 || ($mycount % 8 == 0)) {
                     $pdf->ezNewPage();
-                    $y = 800;
+                    $y    = 800;
                     $minY = $y;
                 }
             } else {
                 $minY = $y;
-                $y = $reset;
-                $x = 300;
+                $y    = $reset;
+                $x    = 300;
             }
             $count++;
             $mycount++;
index 8ed9fba..b5ac829 100644 (file)
@@ -1,9 +1,11 @@
 <div id="glm-member-detail-coupons-toggle" class="glm-member-detail-content-toggle">Coupons</div>
 <div id="glm-member-detail-coupons-container">
-    <form id="glm-coupon-form" action="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=pdfCoupons&pdf=1&member={$member_id}" method="post">
+    <br clear="all">
+    <form id="glm-coupon-form" action="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=pdfCoupons&pdf=1&member={$member_id}" method="post"
+        style="margin-top: 20px;">
         <input type="hidden" id="form-option" name="option" value="">
-        <input type="submit" id="print-all-coupon" value="Print All" name="printAll" class="button success glm_coupon_print">
-        <input type="submit" id="print-selected-coupon" value="Print Selected" name="printSel" class="button success glm_coupon_print">
+        <input type="submit" id="print-all-coupon" value="Print All" name="printAll" class="button tiny success glm_coupon_print">
+        <input type="submit" id="print-selected-coupon" value="Print Selected" name="printSel" class="button tiny success glm_coupon_print">
         {if $categories}
             {foreach $categories as $catName => $coupons}
                 {if $catName != '1-category'}