Changed display of attendee numbers in dashboard to make more sense.
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 27 Sep 2018 16:17:21 +0000 (12:17 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 27 Sep 2018 16:17:21 +0000 (12:17 -0400)
When displaying attendee numbers, now checking for errors and correcting.

classes/data/dataRegEvent.php
models/admin/registrations/events_eventDashboard.php [changed mode: 0644->0755]
setup/databaseScripts/create_database_V1.0.1.sql
views/admin/registrations/eventDashboard.html [changed mode: 0644->0755]

index d22ecaf..76448b7 100755 (executable)
@@ -465,12 +465,62 @@ class GlmDataRegistrationsRegEvent extends GlmDataAbstract
         // Get sum of all attendee counts
         $countsData = $this->wpdb->get_row($sql, ARRAY_A);
 
+        // Calculate Available numbers
+        $totalAvailCalc = $countsData['total'] - $countsData['registered'];
+        $curAvailCalc = $countsData['total'] - $countsData['registered'] - $countsData['cartHold'];
+
+        /*
+         * Note: we have seen a few errors in the total available numbers in the times entries.
+         * This could be due to other errors that have now been corrected. This will ensure that
+         * any such errors, new or lingering, are corrected.
+         */
+
+        // If calc error, verify and update incorrect attendees_available values in time entries
+        $curAvailError = false;
+        $availErrorCorrected = false;
+        if ($countsData['curAvail'] != $curAvailCalc) {
+
+            $curAvailError = true;
+
+            // Get reg times for this event
+            require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegTime.php';
+            $RegTime = new GlmDataRegistrationsRegTime($this->wpdb, $this->config);
+            $regEventTimes = $RegTime->getList("reg_event = ".$eventId);
+
+            // If we have times loop through all looking for calc errors
+            if (is_array($regEventTimes) && count($regEventTimes) > 0) {
+                foreach ($regEventTimes as $regTime) {
+
+                    // If this time entry isn't right
+                    $availCalc = $regTime['attendee_max'] - $regTime['attendee_count'] - $regTime['attendees_pending'];
+                    if ($availCalc != $regTime['attendees_available']) {
+
+                        // Set the correct attendees_available
+                        $sql = "
+                            UPDATE ".GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX."reg_time
+                               SET attendees_available = $availCalc
+                             WHERE id = ".$regTime['id'];
+                        $rows = $this->wpdb->query($sql);
+                        if ($rows = 1) {
+                            $availErrorCorrected = true;
+                        }
+                    }
+
+                }
+
+            }
+
+        }
+
         $counts = array(
             'total'         => $countsData['total'],
             'registered'    => $countsData['registered'],
             'cartHold'      => $countsData['cartHold'],
             'curAvail'      => $countsData['curAvail'],
-            'totalAvail'    => $countsData['cartHold'] + $countsData['curAvail']
+            'curAvailCalc'  => $curAvailCalc,
+            'totalAvail'    => $totalAvailCalc,
+            'curAvailError' => $curAvailError,
+            'errorCorrected' => $availErrorCorrected
         );
 
         return $counts;
index 54bc4d0..fe3819a 100755 (executable)
@@ -284,7 +284,7 @@ CREATE TABLE {prefix}reg_time (
     attendee_max MEDIUMINT NULL,                                -- Attendee count limit - 0 = unlimited - get from reg_event record
     attendee_count MEDIUMINT NULL,                              -- Current attendee count - calculated on the fly and stored here for reference
     attendees_pending MEDIUMINT NULL,                           -- Current number of attendees for this time in active pending carts (Not checked out and attendees slots held)
-    attendees_available MEDIUMINT NULL,                         -- Currently available attendee count (limit - current - pending)
+    attendees_available MEDIUMINT NULL,                         -- Currently available attendee count (limit - registered - pending)
     total_base_charge DOUBLE NULL,                              -- Total base charges
     total_per_attendee DOUBLE NULL,                             -- Total per-attendee charges
     total_other DOUBLE NULL,                                    -- Total other charges (meals, extras, fees, ...)
old mode 100644 (file)
new mode 100755 (executable)
index 2c729c4..fc86a82
@@ -11,7 +11,7 @@
                         <h3>{$terms.reg_term_event_cap} Code:</h3>
                     </div>
                     <div class="glm-small-6 glm-column">
-                        {$regEvent.event_code}
+                        {$regEvent.event_code} (ID {$regEvent.id})
                     </div>
                 </div>
                 <div class="glm-row">
   {if $haveRegEvent}
                 <div class="glm-row">
                     <div class="glm-small-12 glm-column">
-                        <h3>Cart Hold:</h3>
+                        <h3>{$terms.reg_term_attendee_plur_cap} Available:</h3>
                     </div>
                     <div class="glm-small-12 glm-column">
-                        {$regEvent.cartHold}
+                        {$regEvent.totalAvail}
                     </div>
                 </div>
                 <div class="glm-row">
                     <div class="glm-small-12 glm-column">
-                        <h3>Currently Available:</h3>
+                        <h3>On Hold in Pending Requests:</h3>
                     </div>
                     <div class="glm-small-12 glm-column">
-                        {$regEvent.curAvail}
+                        {$regEvent.cartHold}
                     </div>
                 </div>
                 <div class="glm-row">
                     <div class="glm-small-12 glm-column">
-                        <h3>Total Available:</h3>
+                        <h3>Available Less Currently Held:</h3>
                     </div>
                     <div class="glm-small-12 glm-column">
-                        {$regEvent.totalAvail}
+                        {$regEvent.curAvailCalc} 
+        {if $regEvent.curAvailError}<br>(discrepancy in stored quantity corrected) {/if}                        
                     </div>
                 </div>
   {/if}