Location: PHPKode > scripts > WP Marketplace > wpmarketplace/libs/scode_earnings.php
<?php
global $wpdb, $current_user;
$uid = $current_user->ID;
$sql = "select p.*,i.price,i.quantity, o.date from {$wpdb->prefix}mp_orders o,
                      {$wpdb->prefix}mp_order_items i,
                      {$wpdb->prefix}posts p 
                      where p.post_author=$uid and 
                            i.oid=o.order_id and 
                            i.pid=p.ID and 
                            o.payment_status='Completed' order by o.date desc";

$sales = $wpdb->get_results($sql);   
$sql = "select sum(i.price*i.quantity) from {$wpdb->prefix}mp_orders o,
                      {$wpdb->prefix}mp_order_items i,
                      {$wpdb->prefix}posts p 
                      where p.post_author=$uid and 
                            i.oid=o.order_id and 
                            i.pid=p.ID and 
                            o.payment_status='Completed'";

 $total_sales= $wpdb->get_var($sql); 
 
 $sql = "select sum(amount) from {$wpdb->prefix}mp_withdraws 
                      where uid=$uid";

$total_withdraws = $wpdb->get_var($sql); 

$balance=$total_sales-$total_withdraws;

//finding matured balance 
$payout_duration=get_option("wpmp_payout_duration");
$sqlm = "select sum(i.price*i.quantity) from {$wpdb->prefix}mp_orders o,
                      {$wpdb->prefix}mp_order_items i,
                      {$wpdb->prefix}posts p 
                      where p.post_author=$uid and 
                            i.oid=o.order_id and 
                            i.pid=p.ID and 
                            o.payment_status='Completed'
                            and (o.date+({$payout_duration}*24*60*60))<".time()."
                            ";

$tempbalance = $wpdb->get_var($sqlm); 
$matured_balance=$tempbalance-$total_withdraws;
/**********************************/

//finding pending balance
$pending_balance=$balance-$matured_balance;

                                                  
if(get_user_meta($uid,'w_req',true)==1) { delete_user_meta($uid,'w_req');


?>
<blockquote class="success"><b>Withdraw request</b><br/>Withdraw request submitted successfully.</blockquote>
<?php } ?>
<script type="text/javascript" charset="utf-8">
            /* Table initialisation */
            jQuery(document).ready(function() {
                
                jQuery.extend( jQuery.fn.dataTableExt.oStdClasses, {
                    "sSortAsc": "header headerSortDown",
                    "sSortDesc": "header headerSortUp",
                    "sSortable": "header"
                } );
                /* API method to get paging information */
                            jQuery.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
                            {
                                return {
                                    "iStart":         oSettings._iDisplayStart,
                                    "iEnd":           oSettings.fnDisplayEnd(),
                                    "iLength":        oSettings._iDisplayLength,
                                    "iTotal":         oSettings.fnRecordsTotal(),
                                    "iFilteredTotal": oSettings.fnRecordsDisplay(),
                                    "iPage":          Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
                                    "iTotalPages":    Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
                                };
                            }
/* Bootstrap style pagination control */
            jQuery.extend( jQuery.fn.dataTableExt.oPagination, {
                "bootstrap": {
                    "fnInit": function( oSettings, nPaging, fnDraw ) {
                        var oLang = oSettings.oLanguage.oPaginate;
                        var fnClickHandler = function ( e ) {
                            if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
                                fnDraw( oSettings );
                            }
                        };

                        jQuery(nPaging).addClass('pagination').append(
                            '<ul>'+
                                '<li class="prev disabled"><a href="#">&larr; '+oLang.sPrevious+'</a></li>'+
                                '<li class="next disabled"><a href="#">'+oLang.sNext+' &rarr; </a></li>'+
                            '</ul>'
                        );
                        var els = jQuery('a', nPaging);
                        jQuery(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
                        jQuery(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
                    },

                    "fnUpdate": function ( oSettings, fnDraw ) {
                        var oPaging = oSettings.oInstance.fnPagingInfo();
                        var an = oSettings.aanFeatures.p;
                        var i, sClass, iStart, iEnd, iHalf=Math.floor(oPaging.iTotalPages/2);

                        if ( oPaging.iTotalPages < 5) {
                            iStart = 1;
                            iEnd = oPaging.iTotalPages;
                        }
                        else if ( oPaging.iPage <= iHalf ) {
                            iStart = 1;
                            iEnd = 5;
                        } else if ( oPaging.iPage >= (5-iHalf) ) {
                            iStart = oPaging.iTotalPages - 5 + 1;
                            iEnd = oPaging.iTotalPages;
                        } else {
                            iStart = oPaging.iPage - Math.ceil(5/2) + 1;
                            iEnd = iStart + 5 - 1;
                        }

                        for ( i=0, iLen=an.length ; i<iLen ; i++ ) {
                            // Remove the middle elements
                            jQuery('li:gt(0)', an[i]).filter(':not(:last)').remove();

                            // Add the new list items and their event handlers
                            for ( i=iStart ; i<=iEnd ; i++ ) {
                                sClass = (i==oPaging.iPage+1) ? 'class="active"' : '';
                                jQuery('<li '+sClass+'><a href="#">'+i+'</a></li>')
                                    .insertBefore('li:last', an[i])
                                    .bind('click', function () {
                                        oSettings._iDisplayStart = (parseInt(jQuery('a', this).text(),10)-1) * oPaging.iLength;
                                        fnDraw( oSettings );
                                    } );
                            }

                            // Add / remove disabled classes from the static elements
                            if ( oPaging.iPage === 0 ) {
                                jQuery('li:first', an[i]).addClass('disabled');
                            } else {
                                jQuery('li:first', an[i]).removeClass('disabled');
                            }

                            if ( oPaging.iPage === oPaging.iTotalPages-1 ) {
                                jQuery('li:last', an[i]).addClass('disabled');
                            } else {
                                jQuery('li:last', an[i]).removeClass('disabled');
                            }
                        }

                    }
                }
            } );
            jQuery('#earnings').dataTable( {
                    "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
                    "sPaginationType": "bootstrap"
                } );
            } );
        </script>
<style type="text/css">
div.dataTables_length label {
   /* width: 460px;*/
    float: left;
    text-align: left;
}
 
div.dataTables_length select {
    width: 75px;
}
 
div.dataTables_filter label {
    float: right;
   /* width: 460px;*/
}
 
div.dataTables_info {
    padding-top: 8px;
}
 
div.dataTables_paginate {
    float: right;
    margin: 0;
}
 
table {
    margin: 1em 0;
    clear: both;
}
.center{
    text-align: center;
}
</style>
<div class="container-fluid">
<div class="well well-small">
<div class="row-fluid" style="height: 25px;">
<span class="span3 center"><b style="color: #336699;font-size:10pt"><?php echo __("Total Sales:","wpmarketplace");?> $<?php echo number_format($total_sales,2); ?></b></span><span class="span3 center"><b style="color: #366DDB;font-size:10pt"><?php echo __("Total Withdraws:","wpmarketplace");?> $<?php echo number_format($total_withdraws,2); ?></b></span><span class="span2 center"><b style="color: #008000;font-size:10pt"><?php echo __("Pending:","wpmarketplace");?> $<?php echo number_format($pending_balance,2);?></b></span><span class="span4 center"><b class="span5" style="color: #008000;font-size:10pt"><?php echo __("Balance:","wpmarketplace");?> $<?php echo number_format($matured_balance,2); ?> </b><form action="" method="post" class="span5"><input type="hidden" name="withdraw" value="1"><input type="hidden" name="withdraw_amount" value="<?php echo $matured_balance;?>"><button <?php if($matured_balance<=0){?>disabled="disabled" <?php } ?>  class="btn btn-success btn-small" type="submit"><?php echo __("Withdraw","wpmarketplace");?></button></form></span>
</div>
</div>
</div>
<table class="table table-bordered table-striped" id="earnings">
<thead>
<tr><th><?php echo __("Date","wpmarketplace");?></th><th><?php echo __("Item","wpmarketplace");?></th><th><?php echo __("Quantity","wpmarketplace");?></th><th><?php echo __("Price","wpmarketplace");?></th></tr>
</thead>
<tbody>
<?php foreach($sales as $sale){ ?>
<tr><td><?php echo date("Y-m-d H:i",$sale->date); ?></td><td><?php echo $sale->post_title; ?></td><td><?php echo $sale->quantity; ?></td><td><?php echo $sale->price; ?></td></tr>    
<?php } ?>
</tbody>
</table>
Return current item: WP Marketplace