/**
  * Get the chart for this report.
  *
  * @since 1.0
  *
  * @param string $date_type
  * @param int    $product
  *
  * @return Base
  */
 public function get_chart($date_type = 'this_year', $product = 0)
 {
     $start = date('Y-m-d H:i:s', $this->convert_date($date_type));
     $end = date('Y-m-d H:i:s', $this->convert_date($date_type, true));
     $grouping = self::get_grouping_for_date_type($date_type);
     $sql = self::get_group_by($grouping, 'r.renewal_date');
     $group = $sql['group'];
     $per = $sql['per'];
     if ($per) {
         $per .= ' AS d, ';
     }
     if ($group) {
         $group = "GROUP BY {$group}";
     }
     /**
      * @var \wpdb $wpdb
      */
     global $wpdb;
     $rtn = Manager::get('itelic-renewals')->get_table_name($wpdb);
     $ktn = Manager::get('itelic-keys')->get_table_name($wpdb);
     if ($product) {
         $raw = "SELECT {$per}SUM(revenue) as c FROM {$rtn} r JOIN {$ktn} k ON(k.lkey = r.lkey AND k.product = %d) WHERE r.renewal_date BETWEEN %s AND %s";
         $raw .= $group;
         $revenue = $wpdb->get_results($wpdb->prepare($raw, $product, $start, $end));
     } else {
         $raw = "SELECT {$per}SUM(revenue) as c FROM {$rtn} r  WHERE r.renewal_date BETWEEN %s AND %s";
         $raw .= $group;
         $revenue = $wpdb->get_results($wpdb->prepare($raw, $start, $end));
     }
     $revenue = self::fill_gaps(self::translate_results($revenue), $start, $end, $grouping);
     $labels = self::get_labels($revenue, $date_type);
     $before = $after = '';
     $settings = it_exchange_get_option('settings_general');
     $currency = html_entity_decode(it_exchange_get_currency_symbol($settings['default-currency']));
     if ('after' === $settings['currency-symbol-position']) {
         $after = $currency;
     } else {
         $before = $currency;
     }
     $chart = new Line($labels, 600, 200, array('responsive' => true, 'tooltipTemplate' => "{$before}<%= value %>{$after}"));
     $chart->add_data_set(array_values($revenue), __("Revenue", Plugin::SLUG), array('fillColor' => "rgba(140,197,62,0.2)", 'strokeColor' => "rgba(140,197,62,1)", 'pointColor' => "rgba(140,197,62,1)", 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(140,197,62,1)"));
     return $chart;
 }
예제 #2
0
 /**
  * Get the chart for this report.
  *
  * @since 1.0
  *
  * @param string $date_type
  * @param int    $product
  *
  * @return Chart
  */
 public function get_chart($date_type = 'this_year', $product = 0)
 {
     $start = date('Y-m-d H:i:s', $this->convert_date($date_type));
     $end = date('Y-m-d H:i:s', $this->convert_date($date_type, true));
     $grouping = self::get_grouping_for_date_type($date_type);
     $sql = self::get_group_by($grouping, 'p.post_date');
     $group = $sql['group'];
     $per = $sql['per'];
     if ($per) {
         $per .= ' AS d, ';
     }
     if ($group) {
         $group = "GROUP BY {$group}";
     }
     /**
      * @var \wpdb $wpdb
      */
     global $wpdb;
     $ktn = Manager::get('itelic-keys')->get_table_name($wpdb);
     $ptn = $wpdb->posts;
     $raw = "SELECT {$per}COUNT(1) as c FROM {$ktn} k JOIN {$ptn} p ON (k.transaction_id = p.ID and p.post_date BETWEEN %s and %s) WHERE k.status = %s ";
     if ($product) {
         $product = absint($product);
         $raw .= "AND product = '{$product}' ";
     }
     $raw .= $group;
     $active = $wpdb->get_results($wpdb->prepare($raw, $start, $end, Key::ACTIVE));
     $expired = $wpdb->get_results($wpdb->prepare($raw, $start, $end, Key::EXPIRED));
     $disabled = $wpdb->get_results($wpdb->prepare($raw, $start, $end, Key::DISABLED));
     $active = self::fill_gaps(self::translate_results($active), $start, $end, $grouping);
     $expired = self::fill_gaps(self::translate_results($expired), $start, $end, $grouping);
     $disabled = self::fill_gaps(self::translate_results($disabled), $start, $end, $grouping);
     $labels = self::get_labels($active, $date_type);
     $chart = new Line($labels, 600, 200, array('ibdShowLegend' => '#legend-' . $this->get_slug(), 'responsive' => true));
     $statuses = Key::get_statuses();
     $chart->add_data_set(array_values($active), $statuses[Key::ACTIVE], array('fillColor' => "rgba(140,197,62,0.2)", 'strokeColor' => "rgba(140,197,62,1)", 'pointColor' => "rgba(140,197,62,1)", 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(140,197,62,1)"));
     $chart->add_data_set(array_values($expired), $statuses[Key::EXPIRED], array('fillColor' => "rgba(255,186,0,0.2)", 'strokeColor' => "rgba(255,186,0,1)", 'pointColor' => "rgba(255,186,0,1)", 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(255,186,0,1)"));
     $chart->add_data_set(array_values($disabled), $statuses[Key::DISABLED], array('fillColor' => "rgba(221,61,54,0.2)", 'strokeColor' => "rgba(221,61,54,1)", 'pointColor' => "rgba(221,61,54,1)", 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(221,61,54,1)"));
     return $chart;
 }
 /**
  * Get the chart for this report.
  *
  * @since 1.0
  *
  * @param string $date_type
  * @param int    $product
  *
  * @return Base
  */
 public function get_chart($date_type = 'this_year', $product = 0)
 {
     $start = date('Y-m-d H:i:s', $this->convert_date($date_type));
     $end = date('Y-m-d H:i:s', $this->convert_date($date_type, true));
     $grouping = self::get_grouping_for_date_type($date_type);
     $sql = self::get_group_by($grouping, 'r.renewal_date');
     $group = $sql['group'];
     $per = $sql['per'];
     if ($per) {
         $per .= ' AS d, ';
     }
     if ($group) {
         $group = "GROUP BY {$group}";
     }
     /**
      * @var \wpdb $wpdb
      */
     global $wpdb;
     $rtn = Manager::get('itelic-renewals')->get_table_name($wpdb);
     $ktn = Manager::get('itelic-keys')->get_table_name($wpdb);
     if ($product) {
         $raw = "SELECT {$per}COUNT(1) as c FROM {$rtn} r JOIN {$ktn} k ON(k.lkey = r.lkey AND k.product = %d) WHERE r.renewal_date BETWEEN %s AND %s";
         $raw .= $group;
         $renewals = $wpdb->get_results($wpdb->prepare($raw, $product, $start, $end));
     } else {
         $raw = "SELECT {$per}COUNT(1) as c FROM {$rtn} r  WHERE r.renewal_date BETWEEN %s AND %s";
         $raw .= $group;
         $renewals = $wpdb->get_results($wpdb->prepare($raw, $start, $end));
     }
     $renewals = self::fill_gaps(self::translate_results($renewals), $start, $end, $grouping);
     $labels = self::get_labels($renewals, $date_type);
     $chart = new Line($labels, 600, 200, array('responsive' => true));
     $chart->add_data_set(array_values($renewals), __("Renewals", Plugin::SLUG), array('fillColor' => "rgba(151,187,205,0.2)", 'strokeColor' => "rgba(151,187,205,1)", 'pointColor' => "rgba(151,187,205,1)", 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(151,187,205,1)"));
     return $chart;
 }
예제 #4
0
 /**
  * Get the progress line chart.
  *
  * @since 1.0
  *
  * @param Release $release
  *
  * @return Chart\Base
  */
 private function get_progress_chart(Release $release)
 {
     if ($release->get_status() == Release::STATUS_DRAFT) {
         return null;
     }
     $raw = $release->get_first_14_days_of_upgrades();
     $now = new \DateTime();
     $diff = $release->get_start_date()->diff($now);
     $days = min(14, max($diff->days + 1, 1));
     $data = array();
     $day = \ITELIC\convert_gmt_to_local(clone $release->get_start_date());
     $sql_df = 'Y-m-d';
     for ($i = 0; $i < $days; $i++) {
         $key = $day->format($sql_df);
         if (isset($raw[$key])) {
             $data[$key] = $raw[$key];
         } else {
             $data[$key] = 0;
         }
         $day = $day->add(new \DateInterval('P1D'));
     }
     $df = 'M j';
     $labels = array_map(function ($day) use($df) {
         $day = new \DateTime($day);
         return $day->format($df);
     }, array_keys($data));
     $chart = new Chart\Line($labels, 698, 200, array('scaleIntegersOnly' => true, 'scaleBeginAtZero' => true, 'ibdLoadOn' => 'loadProgressChart', 'responsive' => true));
     $chart->add_data_set(array_values($data), '', array('fillColor' => "rgba(151,187,205,0.2)", 'strokeColor' => "rgba(151,187,205,1)", 'pointColor' => "rgba(151,187,205,1)", 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(151,187,205,1)"));
     return $chart;
 }