ZGoPmtList first develompent commit

This commit is contained in:
Rene V. Vergara A. 2022-12-23 15:02:43 -05:00
commit 46e578da7d
4 changed files with 666 additions and 0 deletions

29
README.md Normal file
View file

@ -0,0 +1,29 @@
# ZGo Payment Gateway - Payments Monitoring plugin.
## Description
## Installation
This plugin is installed
### Linux
Red Hat:
This procedure should also work for servers using Fedora, Centos, Rocky Linux, Alma Linux, and other Red Hat derivatives.
Debian:
This procedure should also work for servers using Debian, Ubuntu and its derivatives
### Windows
Although this plugin should work in an Windows based WordPress installation, we do not support it.

View file

@ -0,0 +1,541 @@
<?php
/**
* Creates the submenu page for the plugin.
*
* Provides the functionality necessary for rendering the page corresponding
* to the submenu with which this page is associated.
*
* @package ZGo-Payments
*/
class Submenu_Page {
/**
* 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
* Submenu class.
*/
public $_limit;
public $_offset;
public $_npages;
public $_page;
public $_nrows;
public $_path;
function __construct( $path ) {
$this->_path = $path;
$this->console_log('$_path -> '. $this->_path);
$this->_nrows = $this->getPmtsCount();
//
// Create zgo_pmtlst if does not exist
//
$sql = 'create table if not exists zgo_pmtlst (' .
'pg_ix integer ,' .
'pg_page integer not null default 0,' .
'pg_npages integer not null default 0,' .
'pg_offset integer not null default 0,' .
'pg_limit integer not null default 0,' .
'pg_dt datetime default current_timestamp, '.
'unique lstix (pg_ix) );';
$GLOBALS['wpdb']->query($sql);
if ( ! $this->pmtLstRdy() ) {
//
// Calculate first time pagination paramters
//
$this->_limit = 10;
$this->_page = 1;
$this->_offset = 0;
$this->_npages = intdiv($this->_nrows,$this->_limit);
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
$this->_npages++;
}
$sql = 'insert into zgo_pmtlst (pg_ix,pg_page,pg_npages,pg_offset,pg_limit) values (1,' .
$this->_page . ',' .
$this->_npages . ',' .
$this->_offset . ',' .
$this->_limit .')';
$GLOBALS['wpdb']->query($sql);
} else {
// Load last state
$params = $this->pmtLstParams();
$this->_page = $params->pg_page;
$this->_offset = $params->pg_offset;
$this->_limit = $params->pg_limit;
$this->_npages = $params->pg_npages;
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
//
// Calc new number of pages
//
$this->_npages = intdiv($this->_npages,$this->_limit);
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
$this->_npages++;
}
$sql = 'update zgo_pmtlst set pg_npages=' . $this->_npages . ' where pg_ix=1';
$GLOBALS['wpdb']->query($sql);
}
}
}
public function getPmtsCount() {
global $wpdb;
$sql = "select count(*) as npmts from zgo_payments";
$result = $wpdb->get_var($sql);
$this->console_log('getPmtsCount() -> ' . $result);
return $result;
}
public function pmtLstRdy() {
global $wpdb;
$sql = 'select count(*) as nrecs from zgo_pmtlst;';
$result = $wpdb->get_var($sql);
$this->console_log("pmtLstRdy() -> " . $result);
return $result;
}
public function pmtLstParams() {
global $wpdb;
$sql = 'select * from zgo_pmtlst where pg_ix=1;';
$result = $wpdb->get_row($sql,OBJECT);
$this->console_log('Params -> ' . json_encode($result) );
$this->console_log('pg_ix -> ' . $result->pg_ix );
$this->console_log('pg_page -> ' . $result->pg_page );
$this->console_log('pg_offset -> ' . $result->pg_offset );
return $result;
}
public function console_log($data) {
$file = $this->_path . 'zgopmtgwy/assets/console.log';
file_put_contents($file, 'LST::' . $data . chr(0x0D) . chr(0x0A), FILE_TEXT | FILE_APPEND | LOCK_EX );
}
public function render() {
global $wpdb;
$currentDate = date('Y-m-d H:i:s');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
//
// Navigation button pressed
//
$sql = 'select * from zgo_pmtlst where pg_ix=1;';
$result = $wpdb->get_row($sql,OBJECT);
$this->_page = $result->pg_page;
$this->console_log("_page -> " . $this->_page);
$this->_limit = $result->pg_limit;
$this->console_log("_limit -> " . $this->_limit);
$this->_npages = $result->pg_npages;
$this->console_log("_npages -> " . $this->_npages);
$this->_nrows = $this->getPmtsCount();
$this->console_log("_nrows -> " . $this->_nrows);
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
$this->console_log('_nrows > ' . ($this->_npages*$this->_limit));
$this->_npages = intdiv($this->_nrows,$this->_limit);
$this->console_log('_npages > ' . $this->_npages );
if ( $this->_nrows > ($this->_npages*$this->_limit) ) {
$this->_npages++;
$this->console_log('Page number increased to ' . $this->_npages);
}
}
if ( isset($_POST['First'])) {
$this->_page = 1;
$this->_offset = 0;
}
if ( isset($_POST['Previous'])) {
if ($this->_page > 1) {
$this->_page--;
}
$this->_offset = $this->_limit*($this->_page-1);
}
if ( isset($_POST['Next'])) {
if ($this->_page < $this->_npages ) {
$this->_page++;
}
$this->_offset = $this->_limit*($this->_page-1);
}
if ( isset($_POST['Last'])) {
$this->_page = $this->_npages;
$this->_offset = $this->_limit*($this->_page-1);
}
//
// Save new list state
//
$sql = 'update zgo_pmtlst set pg_page=' . $this->_page .
', pg_npages=' . $this->_npages .
', pg_offset=' . $this->_offset . ' where pg_ix=1;';
$this->console_log( $sql );
$wpdb->query($sql);
}
?>
<div style="margin-top: 20px;
margin-bottom: 20px;
font-family: Noto Sans;
font-size: 30px;
font-weight: 900;
text-align: center;
color: navy;">
ZGo Payment Gateway - Received Payments
</div>
<!-- now output table header -->
<div width="100%"
style="padding-right: 20px;">
<table width="100%">
<tr style="font-family: Noto Sans;
font-weight: 600;
font-size: 15px;
vertical-align: center;
height: 20px;
color: navy;">
<td width="50%" style="padding-left: 5px;">
<?php
echo 'Page ' . $this->_page . '/' . $this->_npages;
?>
</td>
<td width="50%" style="text-align: right;">
<?php echo $currentDate; ?>
</td>
</tr>
</table>
<table>
<tr style="font-family: Noto Sans;
font-weight: 600;
font-size: 15px;
text-align: center;
vertical-align: center;
height: 20px;
background-color: #ff5722;
color: white;">
<td width="10%">ZGo Order Id</td>
<td width="10%">Shop Order Id</td>
<td width="15%">Customer</td>
<td width="10%">Accepted</td>
<td width="10%">Confirmed</td>
<td width="8%">Order Total</td>
<td width="8%">Rate</td>
<td width="8%">Total ZEC</td>
<td width="5%">Paid?</td>
</tr>
<?php
$sql = "select * from zgo_payments order by pmt_accepted desc LIMIT " . $this->_offset . "," . $this->_limit;
$result = $wpdb->get_results($sql,OBJECT);
$npmts = count($result);
if ( $npmts > 0 ) {
$line = 0;
while ( $line < $npmts ) {
$row = $result[$line];
if ( fmod($line,2) ) {
print '<tr style="background-color: #ffffff;
font-weight: 600;">';
} else {
print '<tr style="background-color: #ebecf0;
font-weight: 600;">';
}
$line++;
print '<td><a href="https://dev.zgo.cash/invoice/' . $row->pmt_orderid . '" target="_blank">' . $row->pmt_orderid . "</a></td>";
print "<td>" . $row->pmt_wc_order . "</td>";
print "<td>" . $row->pmt_wc_custname . "</td>";
print '<td style="text-align:center;">'. $row->pmt_accepted . "</td>";
print '<td style="text-align:center;">'.$row->pmt_confirmed ."</td>";
print '<td style="text-align:right;">'. number_format($row->pmt_amount,2) . "</td>";
print '<td style="text-align:right;">'. number_format($row->pmt_rate,2) . "</td>";
print '<td style="text-align:right;">'. number_format($row->pmt_zec,8) . "</td>";
print '<td style="text-align:center;">'.$row->pmt_wc_paid ."</td></tr>";
}
?>
</table>
</div>
<br>
<form class="" action="" method="POST">
<table width="100%">
<tr>
<td width="10%"></td>
<td width="20%" align="center">
<button type="submit" name="First"
style="border: 2px solid #ff2b00;
border-radius: 8px;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
font-weight: 700;
background-color: #ff5722;
color: #ffffff;">First Page</button>
</td>
<td width="20%" align="center">
<button type="submit" name="Previous"
style="border: 2px solid #ff2b00;
border-radius: 8px;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
font-weight: 700;
background-color: #ff5722;
color: #ffffff;">Prev Page</button>
</td>
<td width="20%" align="center">
<button type="submit" name="Next"
style="border: 2px solid #ff2b00;
border-radius: 8px;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
font-weight: 700;
background-color: #ff5722;
color: #ffffff;">Next Page</button>
</td>
<td width="20%" align="center">
<button type="submit" name="Last"
style="border: 2px solid #ff2b00;
border-radius: 8px;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
font-weight: 700;
background-color: #ff5722;
color: #ffffff;">Last Page</button>
</td>
<td width="10%"></td>
</tr>
</table>
</form>
<?php
$this->render_stats();
}
}
public function render_stats() {
global $wpdb;
$sql = "select ifnull(a.dTotalAmount,0) as dTotalAmount, ifnull(a.dTotalZec,0) as dTotalZec, ifnull(a.dTotalPmts,0) as dTotalPmts, ifnull(b.wTotalAmount,0) as wTotalAmount, ifnull(b.wTotalZec,0) as wTotalZec, ifnull(b.wTotalPmts,0) as wTotalPmts, ifnull(c.mTotalAmount,0) as mTotalAmount, ifnull(c.mTotalZec,0) as mTotalZec, ifnull(c.mTotalPmts,0) as mTotalPmts from (select sum(a0.pmt_amount) as dTotalAmount, sum(a0.pmt_zec) as dTotalZec, count(*) as dTotalPmts from zgo_payments a0 where STR_TO_DATE(left(a0.pmt_confirmed,10), '%Y-%m-%d') = CURRENT_DATE ) a join (select sum(aa.pmt_amount) as wTotalAmount, sum(aa.pmt_zec) as wTotalZec, count(*) as wTotalPmts from zgo_payments aa where STR_TO_DATE(aa.pmt_confirmed, '%Y-%m-%d %H:%i:%s') >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) b join (select sum(bb.pmt_amount) as mTotalAmount, sum(bb.pmt_zec) as mTotalZec, count(*) as mTotalPmts from zgo_payments bb where STR_TO_DATE(bb.pmt_confirmed, '%Y-%m-%d %H:%i:%s') >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY)) c where 1;";
$result = $wpdb->get_row($sql,OBJECT);
?>
<div style="margin-top: 25px;
margin-bottom: 20px;
padding-right: 20px;
font-family: 'Noto Sans';
font-size: 20px;
font-weight: 900;
text-align: center;
color: navy;">
ZGo Confirmed Payments Statistics
</div>
<!-- now output table header -->
<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="35%">Payments received</td>
<td width="35%">Description</td>
<td width="30%">Value</td>
</tr>
</table>
</td>
<td width="10%"></td>
</tr>
<td width="10%"></td>
<td width="80%" >
<table width="100%">
<tr style="font-family: Noto Sans;
font-weight: 700;
background-color: white;">
<td width="35%" style="padding-left: 10px;
border-top: 1px solid navy;
border-bottom: 1px solid navy;">Received Today</td>
<td width="35%">
<table width="100%"
style="border-top: 1px solid navy;
border-bottom: 1px solid navy;
border-collapse: collapse;">
<tr>
<td style="padding-left: 10px;">Total Amount</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Average Rate</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Total Zec</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Number of payments</td>
</tr>
</table>
</td>
<td width="30%">
<table width="100%"
style="border-top: 1px solid navy;
border-bottom: 1px solid navy;
border-collapse: collapse;">
<tr>
<td style="padding-left: 10px;"> <?php echo number_format($result->dTotalAmount,2);?></td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;"> <?php if ($result->dTotalZec > 0.0) {
echo number_format($result->dTotalZec/$result->dTotalAmount,2);
} else { echo '0.00'; } ?></td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;"><?php echo number_format($result->dTotalZec,8);?></td>
</tr>
<tr >
<td style="border-top: 1px solid navy;
padding-left: 10px;"><?php echo $result->dTotalPmts;?></td>
</tr>
</table>
</td>
</tr>
<tr style="font-family: Noto Sans;
font-weight: 600;">
<td width="35%" style="padding-left: 10px;
border-top: 1px solid navy;
border-bottom: 1px solid navy;">Last 7 days</td>
<td width="35%">
<table width="100%"
style="border-top: 1px solid navy;
border-bottom: 1px solid navy;
border-collapse: collapse;">
<tr>
<td style="padding-left: 10px;">Total Amount</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Average Rate</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Total Zec</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Number of payments</td>
</tr>
</table>
</td>
<td width="30%">
<table width="100%"
style="border-top: 1px solid navy;
border-bottom: 1px solid navy;
border-collapse: collapse;">
<tr>
<td style="padding-left: 10px;"> <?php echo number_format($result->wTotalAmount,2);?></td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;"> <?php if ($result->wTotalZec > 0.0) {
echo number_format($result->wTotalAmount/$result->wTotalZec,2);
} else { echo '0.00'; } ?></td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;"><?php echo number_format($result->wTotalZec,8);?></td>
</tr>
<tr >
<td style="border-top: 1px solid navy;
padding-left: 10px;"><?php echo $result->wTotalPmts;?></td>
</tr>
</table>
</td>
</tr>
<tr style="font-family: Noto Sans;
font-weight: 600;
background-color: white;">
<td width="35%" style="padding-left: 10px;
border-top: 1px solid navy;
border-bottom: 1px solid navy;">Last 30 days</td>
<td width="35%">
<table width="100%"
style="border-top: 1px solid navy;
border-bottom: 1px solid navy;
border-collapse: collapse;">
<tr>
<td style="padding-left: 10px;">Total Amount</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Average Rate</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Total Zec</td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;">Number of payments</td>
</tr>
</table>
</td>
<td width="30%">
<table width="100%"
style="border-top: 1px solid navy;
border-bottom: 1px solid navy;
border-collapse: collapse;">
<tr>
<td style="padding-left: 10px;"> <?php echo number_format($result->mTotalAmount,2);?></td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;"> <?php if ($result->mTotalZec> 0.0) {
echo number_format($result->mTotalAmount/$result->mTotalZec,2);
} else { echo '0.00'; } ?></td>
</tr>
<tr>
<td style="border-top: 1px solid navy;
padding-left: 10px;"><?php echo number_format($result->mTotalZec,8);?></td>
</tr>
<tr >
<td style="border-top: 1px solid navy;
padding-left: 10px;"><?php echo $result->mTotalPmts;?></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="10%"></td>
<tr>
</tr>
</table>
<?php
}
}

52
admin/class-submenu.php Normal file
View file

@ -0,0 +1,52 @@
<?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' )
);
}
}

44
zgopmtlist.php Normal file
View file

@ -0,0 +1,44 @@
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the
* plugin admin area. This file also defines a function that starts the plugin.
*
* @package ZGo-Payments
*
* @wordpress-plugin
* Plugin Name: ZGo Payment Database
* Plugin URI: http://vergara.tech
* 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 ( ! defined( 'WPINC' ) ) {
die;
}
// Include the dependencies needed to instantiate the plugin.
foreach ( glob( plugin_dir_path( __FILE__ ) . 'admin/*.php' ) as $file ) {
include_once $file;
}
add_action( 'plugins_loaded', 'zgopmtlist_plugin' );
/**
* Starts the plugin.
*
* @since 1.0.0
*/
function zgopmtlist_plugin() {
$path = str_replace('zgopmtlist/','',plugin_dir_path( __FILE__ ));
$plugin = new Submenu( new Submenu_Page($path) );
$plugin->init();
}