2022-12-30 20:54:06 +00:00
< ? php
/**
2022-12-31 01:42:49 +00:00
* ZGo Payment Gateway for WooCommerce Plugin
*
* This class creates the statistics page for the plugin .
2022-12-30 20:54:06 +00:00
*
**/
2022-12-31 02:57:58 +00:00
class zpmt_stats_page {
2022-12-30 20:54:06 +00:00
public $_limit ;
public $_offset ;
public $_npages ;
public $_page ;
public $_nrows ;
public $_path ;
2022-12-30 23:22:20 +00:00
public function __construct ( $path ) {
2022-12-30 20:54:06 +00:00
global $wpdb ;
$this -> _path = $path ;
2022-12-31 01:42:49 +00:00
2022-12-30 23:22:20 +00:00
$this -> _nrows = $this -> getPmtsCount ();
//
// Create zgo_pmtlst if does not exist
//
$sql = 'create table if not exists zgo_pmtlst (' .
2022-12-30 20:54:06 +00:00
'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) );' ;
2022-12-30 23:22:20 +00:00
$wpdb -> query ( $sql );
2022-12-30 20:54:06 +00:00
2022-12-30 23:22:20 +00:00
if ( ! $this -> pmtLstRdy () ) {
2023-06-23 14:29:08 +00:00
//
// Calculate first time pagination paramters
//
$this -> _limit = 10 ;
2022-12-30 20:54:06 +00:00
$this -> _page = 1 ;
$this -> _offset = 0 ;
$this -> _npages = intdiv ( $this -> _nrows , $this -> _limit );
if ( $this -> _nrows > ( $this -> _npages * $this -> _limit ) ) {
2023-06-23 14:29:08 +00:00
$this -> _npages ++ ;
}
2022-12-30 20:54:06 +00:00
2023-06-23 14:29:08 +00:00
$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 . ')' ;
$wpdb -> query ( $sql );
2022-12-30 23:22:20 +00:00
} else {
2022-12-30 20:54:06 +00:00
// 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 -> _nrows , $this -> _limit );
if ( $this -> _nrows > ( $this -> _npages * $this -> _limit ) ) {
$this -> _npages ++ ;
}
$sql = 'update zgo_pmtlst set pg_npages=' . $this -> _npages . ' where pg_ix=1' ;
$wpdb -> query ( $sql );
}
}
}
public function getPmtsCount () {
global $wpdb ;
$sql = " select count(*) as npmts from zgo_payments " ;
$result = $wpdb -> get_var ( $sql );
2023-01-01 02:31:41 +00:00
return $result ;
2022-12-30 20:54:06 +00:00
}
public function pmtLstRdy () {
global $wpdb ;
$sql = 'select count(*) as nrecs from zgo_pmtlst;' ;
$result = $wpdb -> get_var ( $sql );
return $result ;
}
public function pmtLstParams () {
global $wpdb ;
$sql = 'select * from zgo_pmtlst where pg_ix=1;' ;
$result = $wpdb -> get_row ( $sql , OBJECT );
return $result ;
}
public function console_log ( $data ) {
2022-12-30 23:22:20 +00:00
$file = $this -> _path . 'assets/log/console.log' ;
2022-12-30 20:54:06 +00:00
file_put_contents ( $file , 'LST::' . $data . chr ( 0x0D ) . chr ( 0x0A ), FILE_TEXT | FILE_APPEND | LOCK_EX );
}
public function render () {
global $wpdb ;
2022-12-30 23:22:20 +00:00
$currentDate = date ( 'Y-m-d H:i:s' );
2022-12-30 20:54:06 +00:00
if ( $_SERVER [ 'REQUEST_METHOD' ] === 'POST' ) {
//
// Navigation button pressed
//
2023-01-01 02:31:41 +00:00
$sql = 'select * from zgo_pmtlst where pg_ix=1;' ;
$result = $wpdb -> get_row ( $sql , OBJECT );
2022-12-30 20:54:06 +00:00
$this -> _page = $result -> pg_page ;
$this -> _limit = $result -> pg_limit ;
$this -> _npages = $result -> pg_npages ;
$this -> _nrows = $this -> getPmtsCount ();
if ( $this -> _nrows > ( $this -> _npages * $this -> _limit ) ) {
$this -> _npages = intdiv ( $this -> _nrows , $this -> _limit );
if ( $this -> _nrows > ( $this -> _npages * $this -> _limit ) ) {
$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;' ;
$wpdb -> query ( $sql );
}
?>
< div style = " margin-top: 20px;
font - family : Noto Sans ;
font - size : 30 px ;
font - weight : 900 ;
text - align : center ;
color : navy ; " >
2023-01-06 03:12:13 +00:00
< table >
< tr >
< td >
< img src = < ? php echo '"' . get_site_url () . '/wp-content/plugins/zgopmtgwy/assets/img/zgowoo-icon.png"' ;
?>
style = " width:50px;height:50px; " >
</ td >
< td >
ZGo Payment Gateway - Received Payments
</ td >
</ tr >
</ table >
2022-12-30 20:54:06 +00:00
</ div >
<!-- now output table header -->
< div width = " 100% "
style = " padding-right: 20px; " >
2022-12-30 23:22:20 +00:00
< table width = " 100% " >
< tr style = " font-family: Noto Sans;
2022-12-31 02:57:58 +00:00
font - weight : 600 ;
font - size : 15 px ;
vertical - align : center ;
height : 20 px ;
2022-12-31 02:01:35 +00:00
color : navy ; " >
2022-12-30 23:22:20 +00:00
< td width = " 50% " style = " padding-left: 5px; " >
< ? php
echo 'Page ' . $this -> _page . '/' . $this -> _npages ;
?>
</ td >
2022-12-31 02:01:35 +00:00
< td width = " 50% " style = " text-align: right; " >< ? php echo $currentDate ; ?>
2022-12-30 23:22:20 +00:00
</ td >
2022-12-31 02:01:35 +00:00
</ tr >
2022-12-30 23:22:20 +00:00
</ table >
< table >
< tr style = " font-family: Noto Sans;
font - weight : 600 ;
font - size : 15 px ;
text - align : center ;
vertical - align : center ;
height : 20 px ;
2022-12-31 02:57:58 +00:00
background - color : #ff5722;
color : white ; " >
2022-12-30 23:22:20 +00:00
< 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 >
2022-12-30 20:54:06 +00:00
< ? 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 ++ ;
2023-06-23 14:29:08 +00:00
print '<td><a href="https://dev.zgo.cash/invoice/' . htmlentities ( $row -> pmt_orderid , ENT_QUOTES ) . '" target="_blank">' . htmlentities ( $row -> pmt_orderid , ENT_QUOTES ) . " </a></td> " ;
2022-12-30 20:54:06 +00:00
print " <td> " . $row -> pmt_wc_order . " </td> " ;
2023-06-23 14:29:08 +00:00
print " <td> " . htmlentities ( $row -> pmt_wc_custname , ENT_QUOTES ) . " </td> " ;
2022-12-30 20:54:06 +00:00
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> " ;
}
?>
2022-12-30 23:22:20 +00:00
</ 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 : 8 px ;
padding - left : 10 px ;
padding - right : 10 px ;
padding - top : 5 px ;
padding - bottom : 5 px ;
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 : 8 px ;
padding - left : 10 px ;
padding - right : 10 px ;
padding - top : 5 px ;
padding - bottom : 5 px ;
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 : 8 px ;
padding - left : 10 px ;
padding - right : 10 px ;
padding - top : 5 px ;
padding - bottom : 5 px ;
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 : 8 px ;
padding - left : 10 px ;
padding - right : 10 px ;
padding - top : 5 px ;
padding - bottom : 5 px ;
font - weight : 700 ;
background - color : #ff5722;
color : #ffffff;">Last Page</button>
</ td >
< td width = " 10% " ></ td >
</ tr >
</ table >
</ form >
2022-12-30 20:54:06 +00:00
< ? php
$this -> render_stats ();
$this -> render_totals ();
}
}
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 );
?>
2022-12-31 02:57:58 +00:00
< div style = " margin-top: 10px;
2022-12-31 00:22:01 +00:00
margin - bottom : 10 px ;
padding - right : 20 px ;
2022-12-30 20:54:06 +00:00
font - family : 'Noto Sans' ;
font - size : 20 px ;
font - weight : 900 ;
text - align : center ;
color : navy ; " >
ZGo Confirmed Payments Statistics
</ div >
<!-- now output table header -->
2022-12-30 23:22:20 +00:00
< table width = " 100% "
2022-12-30 20:54:06 +00:00
style = " padding-right: 20px; " >
2022-12-30 23:22:20 +00:00
< tr >
< td width = " 10% " ></ td >
< td width = " 80% " >
2022-12-30 20:54:06 +00:00
< table width = " 100% " >
< tr style = " font-family: Noto Sans;
2022-12-31 00:22:01 +00:00
font - weight : 600 ;
font - size : 15 px ;
margin : auto ;
text - align : center ;
vertical - align : center ;
height : 20 px ;
background - color : #ff5722;
color : white ; " >
2022-12-30 20:54:06 +00:00
< td width = " 35% " > Payments received </ td >
< td width = " 35% " > Description </ td >
< td width = " 30% " > Value </ td >
</ tr >
</ table >
</ td >
2022-12-30 23:22:20 +00:00
< td width = " 10% " ></ td >
</ tr >
< 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 : 1 px solid navy ;
border - bottom : 1 px solid navy ; " >Received Today</td>
< td width = " 35% " >
< table width = " 100% "
style = " border-top: 1px solid navy;
border - bottom : 1 px 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 : 10 px ; " >Average Rate</td>
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >Total Zec</td>
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >Number of payments</td>
</ tr >
</ table >
</ td >
< td width = " 30% " >
< table width = " 100% "
style = " border-top: 1px solid navy;
border - bottom : 1 px 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 : 10 px ; " >
< ? 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 : 10 px ; " >
< ? php
echo number_format ( $result -> dTotalZec , 8 );
?>
</ td >
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >
< ? 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 : 1 px solid navy ;
border - bottom : 1 px solid navy ; " >Last 7 days</td>
< td width = " 35% " >
< table width = " 100% "
style = " border-top: 1px solid navy;
border - bottom : 1 px 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 : 10 px ; " >Average Rate</td>
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >Total Zec</td>
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >Number of payments</td>
</ tr >
</ table >
</ td >
< td width = " 30% " >
< table width = " 100% "
style = " border-top: 1px solid navy;
border - bottom : 1 px 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 : 10 px ; " >
< ? 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 : 10 px ; " >
< ? php
echo number_format ( $result -> wTotalZec , 8 );
?>
</ td >
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >
< ? 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 : 1 px solid navy ;
border - bottom : 1 px solid navy ; " >Last 30 days
</ td >
< td width = " 35% " >
< table width = " 100% "
style = " border-top: 1px solid navy;
border - bottom : 1 px 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 : 10 px ; " >Average Rate</td>
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >Total Zec</td>
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >Number of payments</td>
</ tr >
</ table >
</ td >
< td width = " 30% " >
< table width = " 100% "
style = " border-top: 1px solid navy;
border - bottom : 1 px 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 : 10 px ; " >
< ? 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 : 10 px ; " >
< ? php
echo number_format ( $result -> mTotalZec , 8 );
?>
</ td >
</ tr >
< tr >
< td style = " border-top: 1px solid navy;
padding - left : 10 px ; " >
< ? php
echo $result -> mTotalPmts ;
?>
</ td >
</ tr >
</ table >
</ td >
</ tr >
</ table >
2022-12-30 20:54:06 +00:00
</ td >
2022-12-30 23:22:20 +00:00
< td width = " 10% " ></ td >
</ tr >
2022-12-30 20:54:06 +00:00
</ table >
< ? 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 ) {
2022-12-31 01:42:49 +00:00
?>
2022-12-30 20:54:06 +00:00
< div style = " padding-right: 20px;
font - family : 'Noto Sans' ;
font - size : 15 px ;
font - weight : 900 ;
text - align : center ;
color : navy ; " >
Global Totals
</ div >
2022-12-31 01:42:49 +00:00
< table width = " 100% "
style = " padding-right: 20px; " >
< tr >
< td width = " 10% " ></ td >
< td width = " 80% " >
< table width = " 100% " >
2022-12-30 20:54:06 +00:00
< tr style = " font-family: Noto Sans;
2022-12-31 01:42:49 +00:00
font - weight : 600 ;
font - size : 15 px ;
text - align : center ;
vertical - align : center ;
height : 20 px ;
background - color : #ff5722;
color : white ! important ; " >
2022-12-30 20:54:06 +00:00
< 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 >
2022-12-31 01:42:49 +00:00
</ td >
< td width = " 10% " ></ td >
2022-12-30 20:54:06 +00:00
</ tr >
2022-12-31 01:42:49 +00:00
</ table >
< ? php
2022-12-30 20:54:06 +00:00
}
}
}
}