function get_graph_data($product_id, $select, $from, $group_by, $where, $parts) { global $wpdb, $cat_rev, $months, $order_arr; $encoded = get_last_few_order_details($product_id, $select, $from, $group_by, $where); $select .= " ,FROM_UNIXTIME(wtpl.`date`, '{$parts['abbr']}') AS period"; if (isset($parts['day']) && $parts['day'] == 'today') { if ($product_id > 0) { $select .= ",FROM_UNIXTIME(wtpl.`date`, '%H:%i:%s') AS time "; } else { $select .= ",FROM_UNIXTIME(max(wtpl.`date`), '%H:%i:%s') AS time "; } for ($i = 0; $i < 24; $i++) { $cat_rev1[$i] = 1; } } $group_by = " GROUP BY period"; if (isset($product_id) && $product_id != 0) { $where .= " AND prodid = {$product_id} "; } $query = "{$select} {$from} {$where} {$group_by} "; $results = $wpdb->get_results($query, 'ARRAY_A'); $num_rows = $wpdb->num_rows; $no_records = $num_rows != 0 ? count($cat_rev) : 0; if ($no_records != 0) { foreach ($results as $result) { // put within condition $cat_rev[$result['period']] = $result['sales']; if (isset($parts['day']) && $parts['day'] == 'today') { $cat_rev1[$result['period']] = $result['time']; } } $i = 0; foreach ($cat_rev as $mon => $rev) { $record['period'] = $mon; $record['sales'] = $rev; if (isset($parts['day']) && $parts['day'] == 'today') { $record['time'] = $cat_rev1[$i]; } $i++; $records[] = $record; } } if ($no_records == 0) { $encoded['graph']['items'] = ''; $encoded['graph']['totalCount'] = 0; } else { $encoded['graph']['items'] = $records; $encoded['graph']['totalCount'] = count($cat_rev); } return $encoded; }
function get_graph_data($product_id, $where_date, $parts) { global $wpdb, $cat_rev, $months, $order_arr; $cat_rev1 = array(); $encoded = get_last_few_order_details($product_id, $where_date); $time = ''; if (isset($parts['day']) && $parts['day'] == 'today') { $time = ",DATE_FORMAT(max(posts.`post_date`), '%H:%i:%s') AS time"; for ($i = 0; $i < 24; $i++) { $cat_rev1[$i] = 1; } } $select = "SELECT SUM( order_item.sales ) AS sales,\n\t\t\t\t\t\tDATE_FORMAT(posts.`post_date`, '{$parts['abbr']}') AS period\n\t {$time} \n\t\t\t\t\t "; $from = " FROM {$wpdb->prefix}sr_woo_order_items AS order_item\n\t\t\t\t \t LEFT JOIN {$wpdb->prefix}posts AS posts ON ( posts.ID = order_item.order_id )\n\t\t\t\t\t"; $where = ' WHERE 1 '; $group_by = " GROUP BY period"; if (isset($product_id) && $product_id != 0) { $where .= " AND order_item.product_id = {$product_id} "; } $query = "{$select} {$from} {$where} {$where_date} {$group_by} "; $results = $wpdb->get_results($query, 'ARRAY_A'); $num_rows = $wpdb->num_rows; $no_records = $num_rows != 0 ? count($cat_rev) : 0; if ($no_records != 0) { foreach ($results as $result) { // put within condition $cat_rev[$result['period']] = $result['sales']; if (isset($parts['day']) && $parts['day'] == 'today') { $cat_rev1[$result['period']] = $result['time']; } } $i = 0; foreach ($cat_rev as $mon => $rev) { $record['period'] = $mon; $record['sales'] = $rev; if (isset($parts['day']) && $parts['day'] == 'today') { $record['time'] = $cat_rev1[$i]; } $records[] = $record; $i++; } } if ($no_records == 0) { $encoded['graph']['items'] = ''; $encoded['graph']['totalCount'] = 0; } else { $encoded['graph']['items'] = $records; $encoded['graph']['totalCount'] = count($cat_rev); } return $encoded; }