Add global totals to page

This commit is contained in:
Rene V. Vergara A. 2022-12-26 17:12:23 -05:00
parent fc03aaabc8
commit c36e901dd3
4 changed files with 135 additions and 99 deletions

View file

@ -1,52 +0,0 @@
<?php
/**
* Creates the submenu item for the plugin.
*
* Registers a new menu item under 'Admin' group and uses the dependency passed into
* the constructor in order to display the page corresponding to this menu item.
*
* @package ZGo-Payments
*/
class Submenu {
/**
* A reference the class responsible for rendering the submenu page.
*
* @var Submenu_Page
* @access private
*/
private $submenu_page;
/**
* Initializes all of the partial classes.
*
* @param Submenu_Page $submenu_page A reference to the class that renders the
* page for the plugin.
*/
public function __construct( $submenu_page ) {
$this->submenu_page = $submenu_page;
}
/**
* Adds a submenu for this plugin to the 'Tools' menu.
*/
public function init() {
add_action( 'admin_menu', array( $this, 'add_options_page' ) );
}
/**
* Creates the submenu item and calls on the Submenu Page object to render
* the actual contents of the page.
*/
public function add_options_page() {
add_options_page(
'ZGo Payment Gateway Support',
'ZGo Payments',
'manage_options',
'zgopmtlist',
array( $this->submenu_page, 'render' )
);
}
}

View file

@ -1,12 +1,10 @@
<?php <?php
/** /**
* Creates the submenu page for the plugin. * Creates the submenu page for the plugin.
* *
* Provides the functionality necessary for rendering the page corresponding * Provides the functionality necessary for rendering the page corresponding
* to the submenu with which this page is associated. * to the submenu with which this page is associated.
* **/
* @package ZGo-Payments
*/
class Submenu_Page { class Submenu_Page {
@ -14,7 +12,7 @@ class Submenu_Page {
* This function renders the contents of the page associated with the Submenu * This function renders the contents of the page associated with the Submenu
* that invokes the render method. In the context of this plugin, this is the * that invokes the render method. In the context of this plugin, this is the
* Submenu class. * Submenu class.
*/ **/
public $_limit; public $_limit;
public $_offset; public $_offset;
public $_npages; public $_npages;
@ -323,6 +321,7 @@ class Submenu_Page {
<?php <?php
$this->render_stats(); $this->render_stats();
$this->render_totals();
} }
} }
@ -334,7 +333,7 @@ class Submenu_Page {
$result = $wpdb->get_row($sql,OBJECT); $result = $wpdb->get_row($sql,OBJECT);
?> ?>
<div style="margin-top: 25px; <div style="margin-top: 25px;
margin-bottom: 20px; margin-bottom: 10px;
padding-right: 20px; padding-right: 20px;
font-family: 'Noto Sans'; font-family: 'Noto Sans';
font-size: 20px; font-size: 20px;
@ -538,4 +537,56 @@ class Submenu_Page {
<?php <?php
} }
public function render_totals() {
global $wpdb;
$sql = 'select ifnull(sum(a.pmt_amount),0) as gTotalAmount, ' .
'ifnull(count(*),0) as gTotalPmts, ' .
'ifnull(sum(a.pmt_zec),0) as gTotalZec ' .
'from zgo_payments a ' .
'where a.pmt_wc_paid = 1;' ;
$result = $wpdb->get_row($sql,OBJECT);
if ( $result ) {
if ($result->gTotalPmts > 0) {
?>
<div style="padding-right: 20px;
font-family: 'Noto Sans';
font-size: 15px;
font-weight: 900;
text-align: center;
color: navy;">
Global Totals
</div>
<table width="100%"
style="padding-right: 20px;">
<tr>
<td width="10%"></td>
<td width="80%">
<table width="100%" >
<tr style="font-family: Noto Sans;
font-weight: 600;
font-size: 15px;
margin: auto;
text-align: center;
vertical-align: center;
height: 20px;
background-color: #ff5722;
color: white;">
<td width="12%">Payments:</td>
<td width="23%"><?php echo $result->gTotalPmts ?></td>
<td width="12%">Total Amount:</td>
<td width="23%"><?php echo number_format($result->gTotalAmount,2) ?></td>
<td width="12%">Total ZEC:</td>
<td width="23%"><?php echo number_format($result->gTotalZec,8) ?></td>
</tr>
</table>
<td width="10%"></td>
</tr>
</table>
<?php
}
}
}
} }

44
assets/class-submenu.php Normal file
View file

@ -0,0 +1,44 @@
<?php
/**
* Creates the submenu item for the plugin.
*
* Registers a new menu item under 'Admin' group and uses the dependency passed into
* the constructor in order to display the page corresponding to this menu item.
**/
class Submenu {
/**
* A reference the class responsible for rendering the submenu page.
**/
private $submenu_page;
/**
* Initializes all of the partial classes.
**/
public function __construct( $submenu_page ) {
$this->submenu_page = $submenu_page;
}
/**
* Adds a submenu for this plugin to the 'Tools' menu.
**/
public function init() {
add_action( 'admin_menu', array( $this, 'add_options_page' ) );
}
/**
* Creates the submenu item and calls on the Submenu Page object to render
* the actual contents of the page.
**/
public function add_options_page() {
add_options_page(
'ZGo Payment Gateway Support',
'ZGo Payments',
'manage_options',
'zgopmtlist',
array( $this->submenu_page, 'render' )
);
}
}

View file

@ -1,21 +1,16 @@
<?php <?php
/** /**
* The plugin bootstrap file * Plugin Name: ZGo Payment Database
* * Plugin URI: http://vergara.tech
* This file is read by WordPress to generate the plugin information in the * Description: Display payments processed using ZGo Payment Gateway.
* plugin admin area. This file also defines a function that starts the plugin. * Version: 0.8
* * Requires at least: 5.2
* @package ZGo-Payments * Requires PHP: 7.2
* * Author: Vergara Tech LLC
* @wordpress-plugin * Author URI: https://vergara.tech
* Plugin Name: ZGo Payment Database * License: GPL v2 or later
* Plugin URI: http://vergara.tech * License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Description: Display payments processed using ZGo Payment Gateway. **/
* Version: 1.0.0
* Author: Vergara Tech
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// If this file is called directly, abort. // If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) { if ( ! defined( 'WPINC' ) ) {
@ -23,17 +18,15 @@ if ( ! defined( 'WPINC' ) ) {
} }
// Include the dependencies needed to instantiate the plugin. // Include the dependencies needed to instantiate the plugin.
foreach ( glob( plugin_dir_path( __FILE__ ) . 'admin/*.php' ) as $file ) { foreach ( glob( plugin_dir_path( __FILE__ ) . 'assets/*.php' ) as $file ) {
include_once $file; include_once $file;
} }
add_action( 'plugins_loaded', 'zgopmtlist_plugin' ); add_action( 'plugins_loaded', 'zgopmtlist_plugin' );
/** /**
* Starts the plugin. * Starts the plugin.
* **/
* @since 1.0.0
*/
function zgopmtlist_plugin() { function zgopmtlist_plugin() {
$path = str_replace('zgopmtlist/','',plugin_dir_path( __FILE__ )); $path = str_replace('zgopmtlist/','',plugin_dir_path( __FILE__ ));