Exemplo n.º 1
0
 private static function get_next_delivery_info()
 {
     if (self::$next_query_complete === false) {
         global $connection;
         // Set up for pulling only order cycles appropriate to the current customer_type permissions
         // Allow "orderex" direct access to all order cycles
         $customer_type_query = CurrentMember::auth_type('orderex') ? '1' : '0';
         if (CurrentMember::auth_type('member')) {
             $customer_type_query .= '
           OR customer_type LIKE "%member%"';
         }
         if (CurrentMember::auth_type('institution')) {
             $customer_type_query .= '
           OR customer_type LIKE "%institution%"';
         }
         // Set the default "where condition" to be the cycle that opened most recently
         // Do not use MySQL NOW() because it does not know about the php timezone directive
         $now = date('Y-m-d H:i:s', time());
         $query = '
             (SELECT
               date_open,
               date_closed,
               delivery_date,
               delivery_id,
               producer_markdown / 100 AS producer_markdown,
               retail_markup / 100 AS retail_markup,
               wholesale_markup / 100 AS wholesale_markup,
               1 AS using_next
             FROM
               ' . TABLE_ORDER_CYCLES . '
             WHERE
               date_closed > "' . $now . '"
               AND (' . $customer_type_query . ')
             ORDER BY
               date_closed ASC
             LIMIT 0,1)
           UNION
             (SELECT
               date_open,
               date_closed,
               delivery_date,
               delivery_id,
               producer_markdown / 100 AS producer_markdown,
               retail_markup / 100 AS retail_markup,
               wholesale_markup / 100 AS wholesale_markup,
               0 AS using_next
             FROM
               ' . TABLE_ORDER_CYCLES . '
             WHERE
               date_open < "' . $now . '"
               AND (' . $customer_type_query . ')
             ORDER BY
               date_open DESC
             LIMIT 0,1)';
         $result = @mysql_query($query, $connection) or die(debug_print("ERROR: 863024 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
         if ($row = mysql_fetch_object($result)) {
             self::$date_open_next = $row->date_open;
             self::$date_closed_next = $row->date_closed;
             self::$delivery_date_next = $row->delivery_date;
             self::$delivery_id_next = $row->delivery_id;
             self::$producer_markdown_next = $row->producer_markdown;
             self::$retail_markup_next = $row->retail_markup;
             self::$wholesale_markup_next = $row->wholesale_markup;
             self::$using_next = $row->using_next;
             self::$next_query_complete = true;
         }
     }
 }