Plugin Directory

Changeset 3138223


Ignore:
Timestamp:
08/20/2024 02:01:00 PM (18 months ago)
Author:
anzia
Message:

updated tags

Location:
ni-woocommerce-dashboard-report
Files:
19 added
5 edited

Legend:

Unmodified
Added
Removed
  • ni-woocommerce-dashboard-report/tags/2.2.9/ni-woocommerce-dashboard-report.php

    r3138221 r3138223  
    33Plugin Name: Ni WooCommerce Dashboard Sales Report
    44Plugin URI: http://naziinfotech.com/
    5 Description: Enhance your WooCommerce store's performance with the "Ni WooCommerce Dashboard Report" plugin. Gain valuable insights, track sales, and optimize your online business for success.
     5Description: Enhance your WooCommerce store with the "Ni WooCommerce Dashboard Report" plugin. Gain insights, track sales, and optimize your business.
    66Version: 2.2.9
    77Author: anzia
  • ni-woocommerce-dashboard-report/tags/2.2.9/readme.txt

    r3138221 r3138223  
    11=== Ni WooCommerce Dashboard Sales Report ===
    22Contributors: anzia
    3 Tags: report, sales, order,customer, sales report, order report, woocommerce reports, new customer
     3Tags: dashboard report, order status report, sales report, customer report 
    44Stable tag:  2.2.9
    55License: GPLv3 or later
     
    1515
    1616
    17 Enhance your WooCommerce store's performance with the "Ni WooCommerce Dashboard Report" plugin. Gain valuable insights, track sales, and optimize your online business for success. Download now!
     17Enhance your WooCommerce store with the "Ni WooCommerce Dashboard Report" plugin. Gain insights, track sales, and optimize your business.
    1818 
    1919== Description ==
  • ni-woocommerce-dashboard-report/trunk/include/ni-dashboard-report.php

    r2518049 r3138223  
    33if( !class_exists( 'ni_dashboard_report' ) ) {
    44    class ni_dashboard_report{
     5        var $is_hpos_enable = false;
     6        private $months;
    57         public function __construct(){
    68             add_action('admin_init', array( &$this, 'admin_init'));
    79             add_action( 'admin_enqueue_scripts',  array(&$this,'ni_admin_enqueue_scripts' ));
    810             //add_filter( 'gettext', array($this, 'get_text'),20,3);
     11             $this->is_hpos_enable = $this->is_hpos_enabled();
     12   
    913         }
    1014         function get_text($translated_text, $text, $domain){
     
    1418         return $translated_text;
    1519         }
     20         function is_hpos_enabled() {
     21            if ( ! class_exists( 'Automattic\\WooCommerce\\Utilities\\OrderUtil' ) ) {
     22                return false; // OrderUtil class doesn't exist, HPOS is likely not enabled
     23            }
     24       
     25            return Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled();
     26        }
    1627         function admin_init(){
    1728            add_action( 'wp_dashboard_setup', array( &$this, 'ni_add_dashboard_widgets' ));
     
    7586         }
    7687         function ni_woocommerce_top_sold_product_widget(){
    77              global $wpdb;
     88
     89
     90              global $wpdb;
    7891              $query = " SELECT ";
    7992              $query .= "  SUM(qty.meta_value) as qty ";
    8093              $query .= " ,ROUND(SUM(line_total.meta_value),2) as line_total ";
    8194              $query .= " ,line_item.order_item_name as order_item_name ";
    82               $query .= " FROM {$wpdb->prefix}posts as posts ";
     95                if ( $this->is_hpos_enable){
     96                    $query .= " FROM {$wpdb->prefix}wc_orders as posts ";
     97                }else{
     98                    $query .= " FROM {$wpdb->prefix}posts as posts ";
     99                }
     100           
    83101              $query .= " LEFT JOIN  {$wpdb->prefix}woocommerce_order_items as line_item ON line_item.order_id=posts.ID  " ;
    84102             
     
    91109             
    92110              $query .= " WHERE 1=1 ";
    93               $query .= " AND posts.post_type ='shop_order' ";
     111              if ( $this->is_hpos_enable){
     112                $query .= " AND posts.type ='shop_order' ";
     113              }else{
     114                $query .= " AND posts.post_type ='shop_order' ";
     115              }
     116             
    94117              $query .= " AND qty.meta_key ='_qty' ";
    95118              $query .= " AND product_id.meta_key ='_product_id' ";
     
    98121              $query .= " AND line_item.order_item_type ='line_item' ";
    99122              $query .= " AND line_total.meta_key ='_line_total' ";
    100               $query .= " AND posts.post_status IN ('wc-processing','wc-on-hold', 'wc-completed')";
    101            
    102               $query .= " AND  posts.post_status NOT IN ('trash')";
     123              if ( $this->is_hpos_enable){
     124                $query .= " AND posts.status IN ('wc-processing','wc-on-hold', 'wc-completed')";
     125                $query .= " AND  posts.status NOT IN ('trash')";
     126              }else{
     127                $query .= " AND posts.post_status IN ('wc-processing','wc-on-hold', 'wc-completed')";
     128                $query .= " AND  posts.post_status NOT IN ('trash')";
     129              }
     130             
     131           
     132             
    103133              $query .= " GROUP BY product_id.meta_value, variation_id.meta_value  ";
    104134              $query .= " ORDER BY SUM(qty.meta_value) + 0 DESC ";
     
    147177           
    148178            $query = "";
    149             $query = " SELECT ";
    150             $query .= " SUM(order_total.meta_value) as order_total";
    151             $query .= ",  date_format( posts.post_date, '%Y-%m')   as month";
    152             $query .= "  FROM  {$wpdb->prefix}posts as posts ";
     179            $query .= " SELECT ";
     180       
     181           
     182            //$query .= "  FROM  {$wpdb->prefix}posts as posts ";
     183
     184            if ( $this->is_hpos_enable){
     185                $query .= " SUM(total_amount) as order_total";
     186                $query .= ",  date_format( posts.date_created_gmt, '%Y-%m')   as month";
     187                $query .= " FROM {$wpdb->prefix}wc_orders as posts ";
     188            }else{
     189                $query .= " SUM(order_total.meta_value) as order_total";
     190                $query .= ",  date_format( posts.post_date, '%Y-%m')   as month";
     191                $query .= " FROM {$wpdb->prefix}posts as posts ";
    153192                $query  .= " LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID ";
     193            }
     194
     195           
    154196            $query .= " WHERE 1=1 ";
    155             $query .= " AND posts.post_type = 'shop_order'";
    156             $query .= " AND order_total.meta_key = '_order_total'";
    157            
    158             $query .= " AND   date_format( posts.post_date, '%Y-%m-%d') BETWEEN '{$start_date}' AND '{$end_date}'";
    159            
    160               $query .= " AND posts.post_status IN ('{$order_status}')  ";
    161            
    162            
    163             $query .= " GROUP BY YEAR(posts.post_date), MONTH(posts.post_date) ";
     197            //$query .= " AND posts.post_type = 'shop_order'";
     198
     199            if ( $this->is_hpos_enable){
     200                $query .= " AND posts.type ='shop_order' ";
     201              }else{
     202                $query .= " AND posts.post_type ='shop_order' ";
     203              }
     204
     205              if ( $this->is_hpos_enable){
     206                //$query .= " AND order_total.meta_key = '_order_total'";
     207                $query .= " AND   date_format( posts.date_created_gmt, '%Y-%m-%d') BETWEEN '{$start_date}' AND '{$end_date}'";
     208                $query .= " AND posts.status IN ('{$order_status}') ";
     209                $query .= " GROUP BY YEAR(posts.date_created_gmt), MONTH(posts.date_created_gmt) ";
     210              } else{
     211                $query .= " AND order_total.meta_key = '_order_total'";
     212                $query .= " AND   date_format( posts.post_date, '%Y-%m-%d') BETWEEN '{$start_date}' AND '{$end_date}'";
     213                $query .= " AND posts.post_status IN ('{$order_status}')    ";
     214                $query .= " GROUP BY YEAR(posts.post_date), MONTH(posts.post_date) ";
     215            }
     216
     217
     218
    164219            $row = $wpdb->get_results($query);
    165220            $_net_amount = array();
     
    173228            $query = "";
    174229            $query = " SELECT ";
     230           
    175231            $query .= " SUM(order_itemmeta.meta_value) as order_total";
    176             $query .= ", date_format( posts.post_date, '%Y-%m')   as month";
    177             $query .= "  FROM  {$wpdb->prefix}posts as posts ";
     232            if ( $this->is_hpos_enable){
     233                $query .= ", date_format( posts.date_created_gmt, '%Y-%m')   as month";
     234            }else{
     235                $query .= ", date_format( posts.post_date, '%Y-%m')   as month";
     236            }
     237       
     238            if ( $this->is_hpos_enable){
     239                $query .= "  FROM  {$wpdb->prefix}wc_orders as posts ";
     240            }else{
     241                $query .= "  FROM  {$wpdb->prefix}posts as posts ";
     242            }
     243           
    178244           
    179245            $query  .= " LEFT JOIN  {$wpdb->prefix}woocommerce_order_items as order_items ON order_items.order_id=posts.ID ";
     
    182248           
    183249            $query .= " WHERE 1=1 ";
    184             $query .= " AND posts.post_type = 'shop_order'";
     250       
     251            if ( $this->is_hpos_enable){
     252                $query .= " AND posts.type ='shop_order' ";
     253              }else{
     254                $query .= " AND posts.post_type ='shop_order' ";
     255            }
     256
     257
    185258            $query .= " AND order_itemmeta.meta_key = '_line_total'";
    186             $query .= " AND   date_format( posts.post_date, '%Y-%m-%d') BETWEEN '{$start_date}' AND '{$end_date}'";
    187              $query .= " AND posts.post_status IN ('{$order_status}')   ";
    188             $query .= " GROUP BY YEAR(posts.post_date), MONTH(posts.post_date) ";
     259           
     260            if ( $this->is_hpos_enable){
     261                $query .= " AND   date_format( posts.date_created_gmt, '%Y-%m-%d') BETWEEN '{$start_date}' AND '{$end_date}'";
     262                $query .= " AND posts.status IN ('{$order_status}') ";
     263                $query .= " GROUP BY YEAR(posts.date_created_gmt), MONTH(posts.date_created_gmt) ";
     264            }else{
     265                $query .= " AND   date_format( posts.post_date, '%Y-%m-%d') BETWEEN '{$start_date}' AND '{$end_date}'";
     266                $query .= " AND posts.post_status IN ('{$order_status}')    ";
     267                $query .= " GROUP BY YEAR(posts.post_date), MONTH(posts.post_date) ";
     268            }
     269           
     270       
    189271            $row = $wpdb->get_results($query);
    190272            $_gross_amount = array();
     
    271353         }
    272354         function ni_woocommerce_sales_analysis_widget(){
    273              $order_data = $this->get_sales_analysis();
    274              //$this->print_array($order_data);
     355            $order_data  = array();
     356       
     357           
     358
     359             if ( $this->is_hpos_enable){
     360                $order_data = $this->get_sales_analysis_hpos();
     361             }else{
     362                $order_data = $this->get_sales_analysis();
     363             }
     364             
    275365             ?>
    276366            <div style="overflow-x:auto;"> 
     
    338428        function get_recent_orders(){
    339429            global $wpdb;
    340            
    341             $query = " SELECT
    342                     posts.ID as order_id
    343                     ,posts.post_status as order_status
    344                     , date_format( posts.post_date, '%Y-%m-%d') as order_date
    345                    
    346                     FROM {$wpdb->prefix}posts as posts  ";
     430
     431            $query = "";
     432           
     433            $query .= " SELECT ";
     434           
     435       
     436            if ( $this->is_hpos_enable){
     437                $query .= "     posts.ID as order_id";
     438                $query .= "     ,posts.status as order_status";
     439                $query .= "     , date_format( posts.date_created_gmt, '%Y-%m-%d') as order_date    ";
     440                $query .= "     FROM {$wpdb->prefix}wc_orders as posts  ";
     441            }else{
     442                $query .= "     posts.ID as order_id";
     443                $query .= "     ,posts.post_status as order_status";
     444                $query .= "     , date_format( posts.post_date, '%Y-%m-%d') as order_date   ";
     445                $query .= "     FROM {$wpdb->prefix}posts as posts  ";
     446            }
     447       
    347448                   
    348449                    $query .= " WHERE 1=1  ";
    349                     $query .= " AND  posts.post_type = 'shop_order'";
    350                     $query .= " AND  posts.post_status NOT IN ('auto-draft')";
    351                    
    352                     $query .= "order by posts.post_date DESC"; 
     450                    if ( $this->is_hpos_enable){
     451                        $query .= " AND  posts.type = 'shop_order'";
     452                        $query .= " AND  posts.status NOT IN ('auto-draft')";
     453                        $query .= "order by posts.date_created_gmt DESC";   
     454                    }else{
     455                        $query .= " AND  posts.post_type = 'shop_order'";
     456                        $query .= " AND  posts.post_status NOT IN ('auto-draft')";
     457                        $query .= "order by posts.post_date DESC"; 
     458                    }
     459                   
     460                   
     461               
    353462                    $query .= " LIMIT 5";   
    354463                    $order_data = $wpdb->get_results( $query); 
     
    389498            $today = date_i18n("Y-m-d");
    390499            global $wpdb;   
    391                 $query = "SELECT
    392                         SUM(order_total.meta_value)as 'total_sales'
    393                         ,count(*) as order_count
    394                         ,'Today' as 'order_day'
    395                         ,'#AD1457' as 'color'
    396                         FROM {$wpdb->prefix}posts as posts         
    397                         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID
     500            $query = "";
     501            $query .= " SELECT ";
     502            $query .= "         SUM(order_total.meta_value)as 'total_sales'";
     503            $query .= "         ,count(*) as order_count";
     504            $query .= "         ,'Today' as 'order_day'";
     505            $query .= "         ,'#AD1457' as 'color'";
     506            $query .= "         FROM {$wpdb->prefix}posts as posts";           
     507            $query .= "         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID ";
    398508                       
    399                         WHERE 1=1
    400                         AND posts.post_type ='shop_order'
    401                         AND order_total.meta_key='_order_total' ";
    402                
    403                  $query .= " AND   date_format( posts.post_date, '%Y-%m-%d') = date_format('{$today}', '%Y-%m-%d')";
    404                   $query .= " AND posts.post_status IN ('{$order_status}')  ";
    405                
    406                 $query .= " UNION ALL ";
     509            $query .= "         WHERE 1=1";
     510            $query .= "         AND posts.post_type ='shop_order' ";
     511            $query .= "         AND order_total.meta_key='_order_total' ";
     512               
     513            $query .= " AND   date_format( posts.post_date, '%Y-%m-%d') = date_format('{$today}', '%Y-%m-%d')";
     514            $query .= " AND posts.post_status IN ('{$order_status}')    ";
     515               
     516            $query .= " UNION ALL ";
    407517               
    408518                /*Yesterday*/
    409                 $query .= "SELECT
    410                         SUM(order_total.meta_value)as 'total_sales'
    411                         ,count(*) as order_count
    412                         ,'Yesterday' as 'order_day'
    413                         ,'#6A1B9A' as 'color'
    414                         FROM {$wpdb->prefix}posts as posts         
    415                         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID
     519            $query .= "SELECT ";
     520            $query .= "         SUM(order_total.meta_value)as 'total_sales' ";
     521            $query .= "         ,count(*) as order_count ";
     522            $query .= "         ,'Yesterday' as 'order_day' ";
     523            $query .= "         ,'#6A1B9A' as 'color' ";
     524            $query .= " FROM {$wpdb->prefix}posts as posts   ";     
     525            $query .= "         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID  ";
    416526                       
    417                         WHERE 1=1
    418                         AND posts.post_type ='shop_order'
    419                         AND order_total.meta_key='_order_total' ";
    420                
    421                 //$query .= " AND   date_format( posts.post_date, '%Y-%m-%d') > DATE_SUB(date_format(NOW(), '%Y-%m-%d'), INTERVAL 1 WEEK) ";
    422                
    423                 //$query .= " AND   date_format( posts.post_date, '%Y-%m-%d') =  SUBDATE(date_format('{$today}' , '%Y-%m-%d'),1) ";
    424                
    425                 $query .= " AND   date_format( posts.post_date, '%Y-%m-%d') = DATE_SUB(date_format('{$today}' , '%Y-%m-%d'), INTERVAL 1 DAY) ";
    426                
    427                     $query .= " AND posts.post_status IN ('{$order_status}')    ";
    428                
    429                 $query .= " UNION ALL ";
     527            $query .= "         WHERE 1=1 ";
     528            $query .= "         AND posts.post_type ='shop_order'  ";
     529            $query .= "         AND order_total.meta_key='_order_total' ";
     530            $query .= " AND   date_format( posts.post_date, '%Y-%m-%d') = DATE_SUB(date_format('{$today}' , '%Y-%m-%d'), INTERVAL 1 DAY) ";
     531            $query .= " AND posts.post_status IN ('{$order_status}')    ";
     532               
     533            $query .= " UNION ALL ";
    430534               
    431535                /*Week*/
    432                 $query .= "SELECT
    433                         SUM(order_total.meta_value)as 'total_sales'
    434                         ,count(*) as order_count
    435                         ,'This Week' as 'order_day'
    436                         ,'#6A1B9A' as 'color'
    437                         FROM {$wpdb->prefix}posts as posts         
    438                         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID
     536            $query .= "SELECT ";
     537            $query .= "         SUM(order_total.meta_value)as 'total_sales'";
     538            $query .= "         ,count(*) as order_count";
     539            $query .= "         ,'This Week' as 'order_day'";
     540            $query .= "         ,'#6A1B9A' as 'color'";
     541            $query .= "         FROM {$wpdb->prefix}posts as posts      "; 
     542            $query .= "         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID ";
    439543                       
    440                         WHERE 1=1
    441                         AND posts.post_type ='shop_order'
    442                         AND order_total.meta_key='_order_total' ";
    443                
    444                 //$query .= " AND   date_format( posts.post_date, '%Y-%m-%d') > DATE_SUB(date_format(NOW(), '%Y-%m-%d'), INTERVAL 1 WEEK) ";
    445                
    446                 $query .= "  AND  YEAR(date_format( posts.post_date, '%Y-%m-%d')) = YEAR(CURRENT_DATE()) AND
    447           WEEK(date_format( posts.post_date, '%Y-%m-%d')) = WEEK(CURRENT_DATE()) ";
    448                   $query .= " AND posts.post_status IN ('{$order_status}')  ";
    449                 $query .= " UNION ALL ";
     544            $query .= "         WHERE 1=1";
     545            $query .= "         AND posts.post_type ='shop_order' ";
     546            $query .= "         AND order_total.meta_key='_order_total' ";
     547            $query .= "  AND  YEAR(date_format( posts.post_date, '%Y-%m-%d')) = YEAR(CURRENT_DATE()) AND ";
     548            $query .= " WEEK(date_format( posts.post_date, '%Y-%m-%d')) = WEEK(CURRENT_DATE()) ";
     549            $query .= " AND posts.post_status IN ('{$order_status}')    ";
     550            $query .= " UNION ALL ";
    450551                /*Month*/
    451                 $query .= "SELECT
    452                         SUM(order_total.meta_value)as 'total_sales'
    453                         ,count(*) as order_count
    454                         ,'This Month' as 'order_day'
    455                         ,'#1565C0' as 'color'
    456                         FROM {$wpdb->prefix}posts as posts         
    457                         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID
     552            $query .= " SELECT ";
     553            $query .= "         SUM(order_total.meta_value)as 'total_sales' ";
     554            $query .= "         ,count(*) as order_count ";
     555            $query .= "         ,'This Month' as 'order_day' ";
     556            $query .= "         ,'#1565C0' as 'color' ";
     557            $query .= "         FROM {$wpdb->prefix}posts as posts   ";     
     558            $query .= "         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID  ";
    458559                       
    459                         WHERE 1=1
    460                         AND posts.post_type ='shop_order'
    461                         AND order_total.meta_key='_order_total' ";
    462                
    463                 //$query .= " AND   date_format( posts.post_date, '%Y-%m-%d') > DATE_SUB(date_format(NOW(), '%Y-%m-%d'), INTERVAL 1 MONTH) ";
    464                
    465                 $query .= "  AND  YEAR(date_format( posts.post_date, '%Y-%m-%d')) = YEAR(CURRENT_DATE()) AND
    466           MONTH(date_format( posts.post_date, '%Y-%m-%d')) = MONTH(CURRENT_DATE()) ";
    467                   $query .= " AND posts.post_status IN ('{$order_status}')  ";
    468                 $query .= " UNION ALL ";
     560            $query .= "         WHERE 1=1 ";
     561            $query .= "         AND posts.post_type ='shop_order'  ";
     562            $query .= "         AND order_total.meta_key='_order_total' ";
     563            $query .= "  AND  YEAR(date_format( posts.post_date, '%Y-%m-%d')) = YEAR(CURRENT_DATE()) AND  ";
     564            $query .= " MONTH(date_format( posts.post_date, '%Y-%m-%d')) = MONTH(CURRENT_DATE()) ";
     565            $query .= " AND posts.post_status IN ('{$order_status}')    ";
     566
     567            $query .= " UNION ALL ";
    469568                /*Year*/
    470                 $query .= "SELECT
    471                         SUM(order_total.meta_value)as 'total_sales'
    472                         ,count(*) as order_count
    473                         ,'This Year' as 'order_day'
    474                         ,'#FF5722' as 'color'
    475                         FROM {$wpdb->prefix}posts as posts         
    476                         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID
     569            $query .= " SELECT ";
     570            $query .= "         SUM(order_total.meta_value)as 'total_sales'";
     571            $query .= "         ,count(*) as order_count";
     572            $query .= "         ,'This Year' as 'order_day'";
     573            $query .= "         ,'#FF5722' as 'color'";
     574            $query .= "         FROM {$wpdb->prefix}posts as posts      "; 
     575            $query .= "         LEFT JOIN  {$wpdb->prefix}postmeta as order_total ON order_total.post_id=posts.ID ";
    477576                       
    478                         WHERE 1=1
    479                         AND posts.post_type ='shop_order'
    480                         AND order_total.meta_key='_order_total' ";
    481                
    482                 $query .= " AND YEAR(date_format( posts.post_date, '%Y-%m-%d')) = YEAR(date_format(NOW(), '%Y-%m-%d')) ";
    483                
    484                   $query .= " AND posts.post_status IN ('{$order_status}')  ";
     577            $query .= "         WHERE 1=1";
     578            $query .= "         AND posts.post_type ='shop_order' ";
     579            $query .= "         AND order_total.meta_key='_order_total' ";
     580               
     581            $query .= " AND YEAR(date_format( posts.post_date, '%Y-%m-%d')) = YEAR(date_format(NOW(), '%Y-%m-%d')) ";
     582               
     583            $query .= " AND posts.post_status IN ('{$order_status}')    ";
     584           
     585            $order_data = $wpdb->get_results( $query); 
     586           
     587            return $order_data;
     588        }
     589        function get_sales_analysis_hpos(){
     590            $query = "";
     591            $order_status =  $this->get_woo_order_status();
     592           
     593            $today = date_i18n("Y-m-d");
     594            global $wpdb;   
     595            $query = "";
     596            $query .= " SELECT ";
     597            $query .= "         SUM(total_amount)as 'total_sales'";
     598            $query .= "         ,count(*) as order_count";
     599            $query .= "         ,'Today' as 'order_day'";
     600            $query .= "         ,'#AD1457' as 'color'";
     601            $query .= "         FROM {$wpdb->prefix}wc_orders as posts";           
     602                   
     603            $query .= "         WHERE 1=1";
     604            $query .= "         AND posts.type ='shop_order' ";
     605       
     606            $query .= " AND   date_format( posts.date_created_gmt, '%Y-%m-%d') = date_format('{$today}', '%Y-%m-%d')";
     607            $query .= " AND posts.status IN ('{$order_status}') ";
     608               
     609            $query .= " UNION ALL ";
     610               
     611                /*Yesterday*/
     612            $query .= "SELECT ";
     613            $query .= "         SUM(total_amount)as 'total_sales'";
     614            $query .= "         ,count(*) as order_count";
     615            $query .= "         ,'Yesterday' as 'order_day' ";
     616            $query .= "         ,'#AD1457' as 'color'";
     617            $query .= "         FROM {$wpdb->prefix}wc_orders as posts";
     618           
     619                       
     620            $query .= "         WHERE 1=1 ";
     621            $query .= "         AND posts.type ='shop_order' ";
     622       
     623            $query .= " AND   date_format( posts.date_created_gmt, '%Y-%m-%d') = DATE_SUB(date_format('{$today}' , '%Y-%m-%d'), INTERVAL 1 DAY) ";
     624            $query .= " AND posts.status IN ('{$order_status}') ";
     625               
     626            $query .= " UNION ALL ";
     627               
     628                /*Week*/
     629            $query .= "SELECT ";
     630            $query .= "         SUM(total_amount)as 'total_sales'";
     631            $query .= "         ,count(*) as order_count";
     632            $query .= "         ,'This Week' as 'order_day'";
     633            $query .= "         ,'#AD1457' as 'color'";
     634            $query .= "         FROM {$wpdb->prefix}wc_orders as posts";
     635           
     636            $query .= "         WHERE 1=1";
     637            $query .= "         AND posts.type ='shop_order' ";
     638       
     639            $query .= "  AND  YEAR(date_format( posts.date_created_gmt, '%Y-%m-%d')) = YEAR(CURRENT_DATE()) AND ";
     640            $query .= " WEEK(date_format( posts.date_created_gmt, '%Y-%m-%d')) = WEEK(CURRENT_DATE()) ";
     641            $query .= " AND posts.status IN ('{$order_status}') ";
     642            $query .= " UNION ALL ";
     643                /*Month*/
     644            $query .= " SELECT ";
     645            $query .= "         SUM(total_amount)as 'total_sales'";
     646            $query .= "         ,count(*) as order_count";
     647            $query .= "         ,'This Month' as 'order_day' ";
     648            $query .= "         ,'#AD1457' as 'color'";
     649            $query .= "         FROM {$wpdb->prefix}wc_orders as posts";
     650       
     651            $query .= "         WHERE 1=1 ";
     652            $query .= "         AND posts.type ='shop_order'  ";
     653            $query .= "  AND  YEAR(date_format( posts.date_created_gmt, '%Y-%m-%d')) = YEAR(CURRENT_DATE()) AND  ";
     654            $query .= " MONTH(date_format( posts.date_created_gmt, '%Y-%m-%d')) = MONTH(CURRENT_DATE()) ";
     655            $query .= " AND posts.status IN ('{$order_status}') ";
     656
     657            $query .= " UNION ALL ";
     658                /*Year*/
     659            $query .= " SELECT ";
     660            $query .= "         SUM(total_amount)as 'total_sales'";
     661            $query .= "         ,count(*) as order_count";
     662            $query .= "         ,'This Year' as 'order_day'";
     663            $query .= "         ,'#AD1457' as 'color'";
     664            $query .= "         FROM {$wpdb->prefix}wc_orders as posts";
     665                       
     666            $query .= "         WHERE 1=1";
     667            $query .= "         AND posts.type ='shop_order' ";
     668           
     669               
     670            $query .= " AND YEAR(date_format( posts.date_created_gmt, '%Y-%m-%d')) = YEAR(date_format(NOW(), '%Y-%m-%d')) ";
     671               
     672            $query .= " AND posts.status IN ('{$order_status}') ";
    485673           
    486674            $order_data = $wpdb->get_results( $query); 
     
    491679            global $wpdb;
    492680            $query = "SELECT ";
    493             $query .= "  post.post_status as order_status";
    494             $query .= " , SUM(postmeta.meta_value) as order_total";
    495             $query .= " , COUNT(*) as order_count";
    496             $query .= " FROM {$wpdb->prefix}posts as post  ";
    497            
    498             $query .= "LEFT JOIN  {$wpdb->prefix}postmeta as postmeta ON postmeta.post_id=post.ID ";
    499            
    500             $query .= " WHERE 1=1  ";
    501             //$query .= " AND  post.post_status = 'publish'";
    502             $query .= " AND  post.post_type = 'shop_order'";
    503            
    504             $query .= " AND  postmeta.meta_key = '_order_total'";
    505            
    506            $query .= " GROUP BY post.post_status ";
    507              $query .= " ORDER  BY order_total DESC";
     681            if ($this->is_hpos_enable){
     682                $query .= "  post.status as order_status";
     683                $query .= " , SUM(total_amount) as order_total";
     684                $query .= " , COUNT(*) as order_count";
     685                $query .= " FROM {$wpdb->prefix}wc_orders as post  ";
     686               
     687           
     688               
     689                $query .= " WHERE 1=1  ";
     690                $query .= " AND  post.type = 'shop_order'";
     691               
     692               
     693                $query .= " GROUP BY post.status ";
     694                $query .= " ORDER  BY SUM(total_amount) DESC";
     695            }else{
     696                $query .= "  post.post_status as order_status";
     697                $query .= " , SUM(postmeta.meta_value) as order_total";
     698                $query .= " , COUNT(*) as order_count";
     699                $query .= " FROM {$wpdb->prefix}posts as post  ";
     700               
     701                $query .= "LEFT JOIN  {$wpdb->prefix}postmeta as postmeta ON postmeta.post_id=post.ID ";
     702               
     703                $query .= " WHERE 1=1  ";
     704                $query .= " AND  post.post_type = 'shop_order'";
     705                $query .= " AND  postmeta.meta_key = '_order_total'";
     706               
     707                $query .= " GROUP BY post.post_status ";
     708                $query .= " ORDER  BY  SUM(postmeta.meta_value) DESC";
     709            }
     710           
    508711           
    509712            $results = $wpdb->get_results( $query);
    510             //$this->print_array($results);
     713           
    511714        ?>
    512715        <style>
     
    589792        function ni_woocommerce_sales_statistics_widget(){
    590793            global $wpdb;   
    591             $query = " SELECT
    592             max(posts.post_date) as order_date
    593 
    594             FROM {$wpdb->prefix}posts as posts  ";
    595 
    596             $query .= " WHERE 1=1  ";
    597             $query .= " AND  posts.post_type = 'shop_order'";
    598             $query .= " AND  posts.post_status NOT IN ('auto-draft')";
    599 
    600             $query .= "order by posts.post_date DESC"; 
     794            $query = "";
     795            $query .= " SELECT ";
     796            if ( $this->is_hpos_enable){
     797                $query .= "max(posts.date_created_gmt) as order_date ";
     798
     799                $query .= "FROM {$wpdb->prefix}wc_orders as posts   ";
     800   
     801                $query .= " WHERE 1=1  ";
     802                $query .= " AND  posts.type = 'shop_order'";
     803                $query .= " AND  posts.status NOT IN ('auto-draft')";
     804   
     805                $query .= "order by posts.date_created_gmt DESC";   
     806
     807            }else{
     808                $query .= "max(posts.post_date) as order_date ";
     809
     810                $query .= "FROM {$wpdb->prefix}posts as posts   ";
     811   
     812                $query .= " WHERE 1=1  ";
     813                $query .= " AND  posts.post_type = 'shop_order'";
     814                $query .= " AND  posts.post_status NOT IN ('auto-draft')";
     815   
     816                $query .= "order by posts.post_date DESC"; 
     817            }
     818       
    601819       
    602820            $results = $wpdb->get_var( $query);
     
    615833        }
    616834        function time_elapsed_string($datetime, $full = false) {
    617             $now = new DateTime;
     835            $now = new DateTime();
    618836            $ago = new DateTime($datetime);
    619837            $diff = $now->diff($ago);
    620 
    621             $diff->w = floor($diff->d / 7);
    622             $diff->d -= $diff->w * 7;
    623 
     838       
     839            // Calculate the number of weeks and adjust days
     840            $weeks = floor($diff->days / 7);
     841            $days = $diff->days % 7;
     842       
    624843            $string = array(
    625844                'y' => 'year',
     
    631850                's' => 'second',
    632851            );
    633             foreach ($string as $k => &$v) {
    634                 if ($diff->$k) {
    635                     $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
    636                 } else {
    637                     unset($string[$k]);
     852       
     853            // Create an associative array to hold the time components
     854            $result = array(
     855                'y' => $diff->y,
     856                'm' => $diff->m,
     857                'w' => $weeks,
     858                'd' => $days,
     859                'h' => $diff->h,
     860                'i' => $diff->i,
     861                's' => $diff->s,
     862            );
     863       
     864            // Build the result string
     865            $parts = array();
     866            foreach ($string as $k => $v) {
     867                if ($result[$k]) {
     868                    $parts[] = $result[$k] . ' ' . $v . ($result[$k] > 1 ? 's' : '');
    638869                }
    639870            }
    640 
    641             if (!$full) $string = array_slice($string, 0, 1);
    642             return $string ? implode(', ', $string) . ' ago' : 'just now';
    643         }
     871       
     872            if (!$full) $parts = array_slice($parts, 0, 1);
     873            return $parts ? implode(', ', $parts) . ' ago' : 'just now';
     874        }
     875       
    644876        function ni_woocommerce_new_customer_widget(){
    645877            $lists['today']['count']        =  $daily_count = $this->new_customer('today');
  • ni-woocommerce-dashboard-report/trunk/ni-woocommerce-dashboard-report.php

    r3010873 r3138223  
    33Plugin Name: Ni WooCommerce Dashboard Sales Report
    44Plugin URI: http://naziinfotech.com/
    5 Description: Enhance your WooCommerce store's performance with the "Ni WooCommerce Dashboard Report" plugin. Gain valuable insights, track sales, and optimize your online business for success.
    6 Version: 2.2.8
     5Description: Enhance your WooCommerce store with the "Ni WooCommerce Dashboard Report" plugin. Gain insights, track sales, and optimize your business.
     6Version: 2.2.9
    77Author: anzia
    88Author URI: http://naziinfotech.com/
     
    1313Domain Path: /languages/
    1414Requires at least: 4.7
    15 Tested up to: 6.4.2
     15Tested up to: 6.6.1
    1616WC requires at least: 3.0.0
    17 WC tested up to: 8.4.0
    18 Last Updated Date: 17-December-2023
     17WC tested up to: 9.1.4
     18Last Updated Date: 20-August-2024
    1919Requires PHP: 7.0
     20*/
     21if ( ! defined( 'ABSPATH' ) ) { exit;}
     22if(!class_exists('NiWooDR_Dashbaord_Report')){
     23    class NiWooDR_Dashbaord_Report{
     24        public function __construct(){
     25            add_action('plugins_loaded', array($this, 'plugins_loaded'));
     26            add_action( 'before_woocommerce_init',  array(&$this,'before_woocommerce_init') );
     27        }
     28        function before_woocommerce_init(){
     29            if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     30                \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     31            }   
     32        }
     33        function plugins_loaded(){
     34           
     35            load_plugin_textdomain('nidashboardreport', WP_PLUGIN_DIR.'/ni-woocommerce-dashboard-report/languages','ni-woocommerce-dashboard-report/languages');
     36            include_once('include/ni-dashboard-report.php');
     37            $obj = new ni_dashboard_report();
     38        }
    2039
    21 */
    22 include_once('include/ni-dashboard-report.php');
    23 $obj = new ni_dashboard_report();
    24 function plugins_loaded(){
    25             load_plugin_textdomain('nidashboardreport', WP_PLUGIN_DIR.'/ni-woocommerce-dashboard-report/languages','ni-woocommerce-dashboard-report/languages');
    26             //load_plugin_textdomain('nipepro', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     40    }
     41
    2742}
    28 add_action( 'plugins_loaded',  'plugins_loaded' );
     43$obj = new NiWooDR_Dashbaord_Report();
  • ni-woocommerce-dashboard-report/trunk/readme.txt

    r3010873 r3138223  
    11=== Ni WooCommerce Dashboard Sales Report ===
    22Contributors: anzia
    3 Tags: report, sales, order,customer, sales report, order report, woocommerce reports, new customer
    4 Stable tag:  2.2.8
     3Tags: dashboard report, order status report, sales report, customer report 
     4Stable tag:  2.2.9
    55License: GPLv3 or later
    66License URI: http://www.gnu.org/licenses/agpl-3.0.html
     
    88Plugin URI: https://wordpress.org/plugins/ni-woocommerce-dashboard-report/
    99Requires at least: 4.7
    10 Tested up to: 6.4.2
     10Tested up to: 6.6.1
    1111WC requires at least: 3.0.0
    12 WC tested up to: 8.4.0
    13 Last Updated Date: 17-December-2023
     12WC tested up to: 9.1.4
     13Last Updated Date:20-August-2024
    1414Requires PHP: 7.0
    1515
    1616
    17 Enhance your WooCommerce store's performance with the "Ni WooCommerce Dashboard Report" plugin. Gain valuable insights, track sales, and optimize your online business for success. Download now!
     17Enhance your WooCommerce store with the "Ni WooCommerce Dashboard Report" plugin. Gain insights, track sales, and optimize your business.
    1818 
    1919== Description ==
     
    8383</blockquote>
    8484
    85 
     85<p>
     86<strong>Note</strong>: This plugin is fully compatible with both WooCommerce's new High-Performance Order Storage (HPOS) and the legacy WordPress posts storage. Whether you are utilizing HPOS or the traditional storage method, you can rely on this plugin to work seamlessly with your current setup.
     87</p>
    8688
    8789<blockquote>
     
    9496</blockquote>
    9597
     98
    9699Feedback   
    97100* We are open to your suggestions and feedback - Thank you for using or trying out one of our plugins.
     
    129132== Changelog ==
    130133
     134= version 2.2.9 -20-August-2024 =
     135* Tested: Compatible With WooCommerce 9.1.4
     136* Tested: Compatible With WordPress 6.6.1
     137* Tested: High-Performance Order Storage (HPOS)
     138
    131139= version 2.2.8 -17-December-2023 =
    132140* Tested: Compatible With WooCommerce 8.4.0
Note: See TracChangeset for help on using the changeset viewer.