-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from hametuha/feature/payment-history
Add payment history screen.
- Loading branch information
Showing
18 changed files
with
362 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Hametuha\Sharee\Screen; | ||
|
||
|
||
use Hametuha\Pattern\TableScreen; | ||
use Hametuha\Sharee\Models\RevenueModel; | ||
use Hametuha\Sharee\Table\PaymentListTable; | ||
use Hametuha\Sharee\Table\RewardListTable; | ||
|
||
class PaymentList extends TableScreen { | ||
|
||
protected $slug = 'payment-history'; | ||
|
||
protected $parent = 'users.php'; | ||
|
||
protected $table_class = PaymentListTable::class; | ||
|
||
protected $has_search = true; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function get_title() { | ||
return __( 'Payment History', 'sharee' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
|
||
namespace Hametuha\Sharee\Table; | ||
|
||
use Hametuha\Sharee\Models\RevenueModel; | ||
use Hametuha\Sharee\Utilities\TableHelper; | ||
|
||
/** | ||
* Display payment history. | ||
* | ||
* @package sharee | ||
*/ | ||
class PaymentListTable extends \WP_List_Table { | ||
|
||
use TableHelper; | ||
|
||
/** | ||
* Get table summary. | ||
* | ||
* @var null | ||
*/ | ||
public $summary = null; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct() { | ||
parent::__construct( | ||
array( | ||
'singular' => 'payment', | ||
'plural' => 'payments', | ||
'ajax' => false, | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Get columns. | ||
* | ||
* @return array | ||
*/ | ||
public function get_columns() { | ||
return [ | ||
'user' => __( 'User', 'sharee' ), | ||
'total' => __( 'Subtotal', 'sharee' ), | ||
'deducting' => __( 'Deducting', 'sharee' ), | ||
'tax' => __( 'VAT', 'sharee' ), | ||
'paid_at' => __( 'Payed At', 'sharee' ), | ||
]; | ||
} | ||
|
||
/** | ||
* Get items. | ||
*/ | ||
public function prepare_items() { | ||
// Set column header. | ||
$this->_column_headers = [ | ||
$this->get_columns(), | ||
[], | ||
$this->get_sortable_columns(), | ||
]; | ||
// Search revenues. | ||
list( $status, $year, $monthnum, $type, $page_num, $user_id ) = $this->get_current_properties(); | ||
$model = RevenueModel::get_instance(); | ||
$this->items = $model->get_payment_list( $year, $user_id ); | ||
$this->set_pagination_args( | ||
[ | ||
'total_items' => count( $this->items ), | ||
'per_page' => count( $this->items ), | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Get column | ||
* | ||
* @param \stdClass $item | ||
* @param string $column_name | ||
*/ | ||
public function column_default( $item, $column_name ) { | ||
$model = RevenueModel::get_instance(); | ||
switch ( $column_name ) { | ||
case 'user': | ||
$url = add_query_arg( [ | ||
'page' => 'payment-history', | ||
'user_id' => $item->user_id, | ||
'year' => filter_input( INPUT_GET, 'year' ) ?: date_i18n( 'Y' ), | ||
], admin_url( 'users.php' ) ); | ||
printf( '<a href="%s">%s</a>', esc_url( $url ), esc_html( $item->display_name ) ); | ||
break; | ||
case 'total': | ||
case 'tax': | ||
case 'deducting': | ||
echo $model->format( $item->{$column_name} ); | ||
break; | ||
case 'paid_at': | ||
echo mysql2date( get_option( 'date_format' ), $item->fixed ); | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function get_table_classes() { | ||
return array_filter( | ||
parent::get_table_classes(), | ||
function( $c ) { | ||
return 'fixed' !== $c; | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function extra_tablenav( $which ) { | ||
if ( 'top' !== $which ) { | ||
return; | ||
} | ||
?> | ||
<label> | ||
<?php esc_html_e( 'User ID', 'sharee' ); ?> | ||
<input style="width: 3em;" type="number" value="<?php echo esc_attr( filter_input( INPUT_GET, 'user_id' ) ); ?>" name="user_id" /> | ||
</label> | ||
<?php | ||
$this->filter_inputs( false ); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function total_record() { | ||
return (int) $this->_pagination_args['total_items']; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.