function wps_deals_sales_summary_widget()
{
    global $wps_deals_model, $wps_deals_currency, $wps_deals_render;
    //Model class
    $model = $wps_deals_model;
    //Currency Class
    $currency = $wps_deals_currency;
    //Render Class
    $render = $wps_deals_render;
    //total sales and earnings
    $totalsales = $model->wps_deals_get_dashboard_sale_count_earning();
    //current month sales and earnings
    $currentmonth = $model->wps_deals_get_sale_count_earning_by_date('', wps_deals_current_date('n'), wps_deals_current_date('Y'));
    $previous_month = wps_deals_current_date('n') == 1 ? 12 : wps_deals_current_date('n') - 1;
    $previous_year = $previous_month == 12 ? wps_deals_current_date('Y') - 1 : wps_deals_current_date('Y');
    //last month sales and earnings
    $lastmonth = $model->wps_deals_get_sale_count_earning_by_date('', $previous_month, $previous_year);
    //recent purchases
    $recentpurchases = $model->wps_deals_get_recent_purchases();
    wp_enqueue_script('wps-deals-popup-scripts');
    wp_enqueue_style('wps-deals-sales-styles');
    ?>
	
	<div class="wps-deals-dashboard-widget-wrap">
	
		<div class="wps-deals-dashboard-full">
		
			<div class="wps-deals-dashboard-left-first">
				<p class="widget-title">
					<?php 
    _e('Current Month', 'wpsdeals');
    ?>
				</p>
					<table>
						<tbody>
							<tr>
								<td class="widget-value"><?php 
    echo $currency->wps_deals_formatted_value($currentmonth['earnings']);
    ?>
</td>
								<td class="widget-label"><?php 
    _e('Earnings', 'wpsdeals');
    ?>
</td>
							</tr>
							<tr>
								<td class="widget-value"><?php 
    echo $currentmonth['salescount'];
    ?>
</td>
								<td class="widget-label"><?php 
    echo _n('Sale', 'Sales', $currentmonth['salescount'], 'wpsdeals');
    ?>
</td>
							</tr>
						</tbody>
					</table>
			</div><!--.wps-deals-dashboard-left-->
			
			<div class="wps-deals-dashboard-right">
				<p class="widget-title">
					<?php 
    _e('Totals', 'wpsdeals');
    ?>
				</p>
					<table>
						<tbody>
							<tr>
								<td class="widget-value"><?php 
    echo $currency->wps_deals_formatted_value($totalsales['earnings']);
    ?>
</td>
								<td class="widget-label"><?php 
    _e('Total Earnings', 'wpsdeals');
    ?>
</td>
							</tr>
							
							<tr>
								
								<td class="widget-value"><?php 
    echo $totalsales['salescount'];
    ?>
</td>
								<td class="widget-label"><?php 
    _e('Total Sales', 'wpsdeals');
    ?>
</td>
							</tr>
						</tbody>
					</table>
			</div><!--.wps-deals-dashboard-right-->
			
		</div><!--.wps-deals-dashboard-full-->
		
		<div class="wps-deals-dashboard-middle">
			<p class="widget-title">
				<?php 
    _e('Last Month', 'wpsdeals');
    ?>
			</p>
				<table>
					<tbody>
						<tr>
							<td class="widget-label"><?php 
    _e('Earnings', 'wpsdeals');
    ?>
</td>
							<td class="widget-value"><?php 
    echo $currency->wps_deals_formatted_value($lastmonth['earnings']);
    ?>
</td>
						</tr>
						<tr>
							<td class="widget-label"><?php 
    echo _n('Sale', 'Sales', $lastmonth['salescount'], 'wpsdeals');
    ?>
</td>
							<td class="widget-value"><?php 
    echo $lastmonth['salescount'];
    ?>
</td>
						</tr>
					</tbody>
				</table>
		</div><!--.wps-deals-dashboard-middle-->
		<?php 
    if (!empty($recentpurchases)) {
        //check recent purchases not empty
        ?>
		<div class="wps-deals-dashboard-middle dashboard-last">
			<p class="widget-title">
				<?php 
        _e('Recent Purchases', 'wpsdeals');
        ?>
			</p>
				<table>
					<tbody>
						<?php 
        foreach ($recentpurchases as $key => $recent) {
            $popup = $render->wps_deals_get_order_popup_details($recent);
            ?>
							<tr>
								<td>
									<?php 
            echo $recent['userdetails']['first_name'] . ' ' . $recent['userdetails']['last_name'];
            echo !empty($recent['userdetails']['user_email']) ? ' - (' . $recent['userdetails']['user_email'] . ') - ' : ' - ';
            ?>
									</td>
								<td class="widget-value"><?php 
            echo $recent['display_order_total'];
            ?>
</td>
								<td><?php 
            echo ' - ' . $popup;
            ?>
<a href="#wps_deal_ordered_<?php 
            echo $key;
            ?>
" rel="wps_deal_sale_view"><?php 
            _e('View Details', 'wpsdeals');
            ?>
</a></td>
							</tr>
						<?php 
        }
        ?>
					</tbody>
				</table>
		</div><!--.wps-deals-dashboard-middle-->
		<?php 
    }
    ?>
	</div><!--.wps-deals-dashboard-widget-wrap-->
	
<?php 
}
 /**
  * Enqueue Scripts for frontside
  * 
  * @package Social Deals Engine
  * @since 1.0.0
  */
 public function wps_deals_front_scripts()
 {
     global $post, $wps_deals_options;
     $prefix = WPS_DEALS_META_PREFIX;
     //check site is running on SSL or not
     $urlsuffix = is_ssl() ? 'https://' : 'http://';
     $disableguest = !empty($wps_deals_options['disable_guest_checkout']) ? '1' : '0';
     $enableterms = !empty($wps_deals_options['enable_terms']) ? '1' : '0';
     //register credit card validator script
     wp_register_script('wps-deals-credit-card-validator-scripts', WPS_DEALS_URL . 'includes/js/wps-deals-credit-card-validator.js', array('jquery'), WPS_DEALS_VERSION, true);
     //countdown timer script
     wp_register_script('wps-deals-countdown-timer-scripts', WPS_DEALS_URL . 'includes/js/wps-deals-countdown.js', array('jquery'), WPS_DEALS_VERSION, true);
     //timer localization variables for timer labels
     wp_localize_script('wps-deals-countdown-timer-scripts', 'Wps_Deals_Timer', array('days' => __('days', 'wpsdeals'), 'hours' => __('hrs', 'wpsdeals'), 'minutes' => __('mins', 'wpsdeals'), 'seconds' => __('secs', 'wpsdeals'), 'today' => wps_deals_current_date('F d, Y H:i:s')));
     //do not include this script in footer otherwise timer countdown will disabled
     wp_register_script('wps-deals-front-scripts', WPS_DEALS_URL . 'includes/js/wps-deals-front.js', array('jquery'), WPS_DEALS_VERSION, true);
     wp_enqueue_script('wps-deals-front-scripts');
     wp_register_script('twitter-bootstrap', WPS_DEALS_URL . 'includes/js/bootstrap.js', array('jquery'), '2.3.1', true);
     if (empty($wps_deals_options['disable_twitter_bootstrap'])) {
         wp_enqueue_script('twitter-bootstrap');
     }
     if (isset($wps_deals_options['enable_lightbox'])) {
         //deals gallery images js
         wp_register_script('wps-deals-gallery-image-scripts', WPS_DEALS_URL . 'includes/js/wps-deals-gallery-prettyPhoto.js', array('jquery'), WPS_DEALS_VERSION, true);
         wp_enqueue_script('wps-deals-gallery-image-scripts');
     }
     //get caching is on site or not
     $caching = isset($wps_deals_options['caching']) && !empty($wps_deals_options['caching']) ? '1' : '';
     //generic localize script
     wp_localize_script('wps-deals-front-scripts', 'Wps_Deals', array('ajaxurl' => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'disableguest' => $disableguest, 'cart_email_blank' => __('<span><strong>ERROR : </strong>Please enter valid email.</span>', 'wpsdeals'), 'cart_email_invalid' => __('<span><strong>ERROR : </strong>Invalid email entered.</span>', 'wpsdeals'), 'cart_login_user_pass_blank' => __('<span><strong>ERROR : </strong>Please enter username and password.</span>', 'wpsdeals'), 'cart_login_user_blank' => __('<span><strong>ERROR : </strong>Please enter valid username.</span>', 'wpsdeals'), 'cart_login_pass_blank' => __('<span><strong>ERROR : </strong>Please enter correct password.</span>', 'wpsdeals'), 'cart_must_reg' => __('<span><strong>ERROR : </strong>You must register or login to complete your purchase.</span>', 'wpsdeals'), 'cart_reg_pass_blank' => __('<span><strong>ERROR : </strong>Please enter password.</span>', 'wpsdeals'), 'cart_reg_conf_pass_blank' => __('<span><strong>ERROR : </strong>Please enter confirm password.</span>', 'wpsdeals'), 'cart_reg_same_pass' => __('<span><strong>ERROR : </strong>Password and confirm password must be same.</span>', 'wpsdeals'), 'cart_reg_user_blank' => __('<span><strong>ERROR : </strong>Please enter user name.</span>', 'wpsdeals'), 'cart_firstname_blank' => __('<span><strong>ERROR : </strong>Please enter first name.</span>', 'wpsdeals'), 'cart_lastname_blank' => __('<span><strong>ERROR : </strong>Please enter last name.</span>', 'wpsdeals'), 'agree_terms' => __('<span><strong>ERROR : </strong>You must agree to the terms of purchase.</span>', 'wpsdeals'), 'enableterms' => $enableterms, 'no_payment_selected' => __('<span><strong>ERROR : </strong>No payment gateway selected.</span>', 'wpsdeals'), 'caching' => $caching));
     //get billing is enable or not
     $enablebilling = isset($wps_deals_options['enable_billing']) && !empty($wps_deals_options['enable_billing']) ? '1' : '0';
     //billing details locatize script
     wp_localize_script('wps-deals-front-scripts', 'Wps_Deals_Billing', array('enable' => $enablebilling, 'country' => __('<span><strong>ERROR : </strong>Please select billing country.</span>', 'wpsdeals'), 'address' => __('<span><strong>ERROR : </strong>Please enter billing address.</span>', 'wpsdeals'), 'city' => __('<span><strong>ERROR : </strong>Please enter billing town / city.</span>', 'wpsdeals'), 'state' => __('<span><strong>ERROR : </strong>Please enter billing state / county.</span>', 'wpsdeals'), 'postcode' => __('<span><strong>ERROR : </strong>Please enter billing postcode.</span>', 'wpsdeals'), 'firstname' => __('<span><strong>ERROR : </strong>Please enter first name.</span>', 'wpsdeals'), 'lastname' => __('<span><strong>ERROR : </strong>Please enter last name.</span>', 'wpsdeals'), 'email' => __('<span><strong>ERROR : </strong>Please enter valid email address.</span>', 'wpsdeals'), 'currentpassword' => __('<span><strong>ERROR : </strong>Please enter current password.</span>', 'wpsdeals'), 'password1' => __('<span><strong>ERROR : </strong>Please enter new password.</span>', 'wpsdeals'), 'password2' => __('<span><strong>ERROR : </strong>Please enter re-enter new password.</span>', 'wpsdeals'), 'comparepassword' => __('<span><strong>ERROR : </strong>Passwords do not match.</span>', 'wpsdeals'), 'usernameemail' => __('<span><strong>ERROR : </strong>Please enter username or e-mail address.</span>', 'wpsdeals'), 'loginusername' => __('<span><strong>ERROR : </strong>Please enter your username.</span>', 'wpsdeals'), 'loginpassword' => __('<span><strong>ERROR : </strong>Please enter your password.</span>', 'wpsdeals')));
     if (is_singular()) {
         //check current page is not home page
         // register google Map Js files
         wp_register_script('wps-deals-google-map', $urlsuffix . 'maps.google.com/maps/api/js?sensor=false', array(), WPS_DEALS_VERSION, true);
         wp_register_script('wps-deals-map-script', WPS_DEALS_URL . 'includes/js/wps-deals-map.js', array(), WPS_DEALS_VERSION, true);
         //do action to add localize script for individual post data
         do_action('wps_deals_localize_map_script');
     }
     //control the facebook buttons to set cookie for ajax call
     //facebook button
     if (!empty($wps_deals_options['social_buttons'])) {
         //check facebook like button is emable or facebook social login enable or not
         if (in_array('facebook', $wps_deals_options['social_buttons']) || !empty($wps_deals_options['enable_facebook']) && WPS_DEALS_FB_APP_ID != '' && WPS_DEALS_FB_APP_SECRET != '') {
             wp_deregister_script('facebook');
             wp_register_script('facebook', $urlsuffix . 'connect.facebook.net/' . $wps_deals_options['fb_language'] . '/all.js#xfbml=1&appId=' . WPS_DEALS_FB_APP_ID, false, WPS_DEALS_VERSION, true);
         }
         //twitter button
         if (in_array('twitter', $wps_deals_options['social_buttons'])) {
             wp_deregister_script('twitter');
             wp_register_script('twitter', $urlsuffix . 'platform.twitter.com/widgets.js', array('jquery'), WPS_DEALS_VERSION, true);
         }
         //google plus button
         if (in_array('google', $wps_deals_options['social_buttons'])) {
             wp_deregister_script('google');
             wp_register_script('google', $urlsuffix . 'apis.google.com/js/plusone.js', array('jquery'), WPS_DEALS_VERSION, true);
         }
     }
     //Social Media Scripts
     //register social media script
     //if there is no authentication data entered in settings page then so error
     $fberror = $twerror = $gperror = $lierror = $yherror = $wlerror = '';
     if (WPS_DEALS_FB_APP_ID == '' || WPS_DEALS_FB_APP_SECRET == '') {
         $fberror = '1';
     }
     if (WPS_DEALS_TW_CONSUMER_KEY == '' || WPS_DEALS_TW_CONSUMER_SECRET == '') {
         $twerror = '1';
     }
     if (WPS_DEALS_GP_CLIENT_ID == '' || WPS_DEALS_GP_CLIENT_SECRET == '') {
         $gperror = '1';
     }
     if (WPS_DEALS_LI_APP_ID == '' || WPS_DEALS_LI_APP_SECRET == '') {
         $lierror = '1';
     }
     if (WPS_DEALS_YH_CONSUMER_KEY == '' || WPS_DEALS_YH_CONSUMER_SECRET == '' || WPS_DEALS_YH_APP_ID == '') {
         $yherror = '1';
     }
     if (WPS_DEALS_WL_CLIENT_ID == '' || WPS_DEALS_WL_CLIENT_SECRET == '') {
         $wlerror = '1';
     }
     //get login url
     $twitterloginurl = wp_login_url();
     //site_url('wp-login.php');
     $twitterloginurl = add_query_arg(array('wps_deals_social_login' => 1, 'dealsnetwork' => 'twitter'), $twitterloginurl);
     wp_register_script('wps-deals-social-front-scripts', WPS_DEALS_SOCIAL_URL . '/js/wps-deals-social-front.js', array('jquery'), WPS_DEALS_VERSION, true);
     wp_localize_script('wps-deals-social-front-scripts', 'WpsDealsSocial', array('ajaxurl' => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'fberror' => $fberror, 'gperror' => $gperror, 'twerror' => $twerror, 'lierror' => $lierror, 'yherror' => $yherror, 'wlerror' => $wlerror, 'urlerror' => __('Improper CallBack URL.', 'wpsdeals'), 'fberrormsg' => __('Please enter Facebook API Key & Secret in settings page.', 'wpsdeals'), 'twerrormsg' => __('Please enter Twitter Consumer Key & Secret in settings page.', 'wpsdeals'), 'gperrormsg' => __('Please enter Google+ Client ID & Secret in settings page.', 'wpsdeals'), 'lierrormsg' => __('Please enter LinkedIn API Key & Secret in settings page.', 'wpsdeals'), 'yherrormsg' => __('Please enter Yahoo API Consumer Key, Secret & App Id in settings page.', 'wpsdeals'), 'wlerrormsg' => __('Please enter Windows Live Client ID & Client Secret in settings page.', 'wpsdeals'), 'socialtwitterloginredirect' => $twitterloginurl));
     //if facebook application id & application secret are not empty
     if (!empty($wps_deals_options['enable_facebook']) && WPS_DEALS_FB_APP_ID != '' && WPS_DEALS_FB_APP_SECRET != '') {
         wp_register_script('wps-deals-social-fbinit', WPS_DEALS_SOCIAL_URL . '/js/wps-deals-social-fbinit.js', array('jquery'), WPS_DEALS_VERSION, true);
         wp_localize_script('wps-deals-social-fbinit', 'WpsDealsFbInit', array('app_id' => WPS_DEALS_FB_APP_ID));
     }
 }
/**
 * Export Deals Report Data
 *
 * Handles to generate deals report data to pdf
 * 
 * @package Social Deals Engine
 * @since 1.0.0
 */
function wps_deals_report_to_pdf()
{
    global $wps_deals_model;
    //model class
    $model = $wps_deals_model;
    if (isset($_POST['wps-deals-sales-report-pdf']) && !empty($_POST['wps-deals-sales-report-pdf'])) {
        //check post is set or not
        $prefix = WPS_DEALS_META_PREFIX;
        require_once 'PDF/class-wps-deals-fpdf.php';
        require_once 'PDF/class-wps-deals-pdf.php';
        //if search is call then pass searching value to function for displaying searching values
        $args = array();
        //sorting as per payment status
        if (isset($_GET['payment_status'])) {
            $args['meta_query'] = array(array('key' => $prefix . 'payment_status', 'value' => $_GET['payment_status']));
        }
        if (isset($_GET['userid'])) {
            $args['author'] = $_GET['userid'];
        }
        //get deals sale data from database
        $data = $model->wps_deals_get_sales($args);
        $columns = apply_filters('wps_deals_sales_pdf_column', array(array('name' => __('NO.', 'wpsdeals'), 'width' => 13), array('name' => __('Order ID', 'wpsdeals'), 'width' => 18), array('name' => __('User Name', 'wpsdeals'), 'width' => 30), array('name' => __('User Email', 'wpsdeals'), 'width' => 75), array('name' => __('Amount', 'wpsdeals'), 'width' => 25), array('name' => __('User', 'wpsdeals'), 'width' => 30), array('name' => __('Status', 'wpsdeals'), 'width' => 30), array('name' => __('Date/Time', 'wpsdeals'), 'width' => 60)));
        $pdf = new Wps_Deals_Pdf();
        $pdf->AddPage('L', 'A4');
        // Auther name and Creater name
        $pdf->SetTitle(utf8_decode(__('WPSocial Deals Pdf Generate', 'wpsdeals')));
        $pdf->SetAuthor(utf8_decode(__('Social Deals Engine', 'wpsdeals')));
        $pdf->SetCreator(utf8_decode(__('Social Deals Engine', 'wpsdeals')));
        $pdf->Image(WPS_DEALS_URL . 'includes/images/wps-logo.png', 256, 10);
        // Set margine of pdf (float left, float top , float right)
        $pdf->SetMargins(8, 8, 8);
        $pdf->SetX(8);
        // Font size set
        $pdf->SetFont('Helvetica', '', 18);
        $pdf->SetTextColor(50, 50, 50);
        $pdf->Ln(3);
        $pdf->Cell(270, 5, utf8_decode(__('Deal Sales', 'wpsdeals')), 0, 2, 'C', false);
        $pdf->SetFont('Helvetica', '', 12);
        $pdf->SetFillColor(238, 238, 238);
        $pdf->Ln(4);
        if (!empty($data)) {
            //set width of columns
            $pdf->SetWidths(apply_filters('wps_deals_sales_pdf_columns_width', array(13, 18, 30, 75, 25, 30, 30, 60)));
            // Table head Code
            foreach ($columns as $column) {
                // parameter : (height, width, string, border[0 - no border, 1 - frame], )
                $pdf->Cell($column['width'], 8, utf8_decode($column['name']), 1, 0, 'C', true);
            }
            $pdf->Ln();
            $no = 1;
            foreach ($data as $key => $value) {
                //this line should be on start of loop
                $data[$key] = apply_filters('wps_deals_sales_pdf_column_data', $value, $value['ID']);
                // get the value for the user details from the post meta box
                $userdetails = $model->wps_deals_get_ordered_user_details($value['ID']);
                // get the value for the order details from the post meta box
                $order_details = $model->wps_deals_get_post_meta_ordered($value['ID']);
                // get the value for the payment status from the post meta box
                $payment_status = $model->wps_deals_get_ordered_payment_status($value['ID']);
                $user_id = isset($userdetails['user_id']) && !empty($userdetails['user_id']) ? $userdetails['user_id'] : '0';
                if (is_numeric($user_id)) {
                    //check user id is numeric or not
                    $userdata = get_userdata($user_id);
                    $username = is_object($userdata) ? $userdetails['first_name'] : __('guest', 'wpsdeals');
                } else {
                    //else user is guest
                    $username = __('guest', 'wpsdeals');
                }
                $displayusername = isset($userdetails['first_name']) && !empty($userdetails['first_name']) ? $userdetails['first_name'] . ' ' . $userdetails['last_name'] : $userdetails['user_name'];
                $data[$key]['user_details'] = !empty($userdetails) ? $userdetails : array();
                $data[$key]['useremail'] = isset($userdetails['user_email']) ? $userdetails['user_email'] : '';
                $data[$key]['payment_status'] = isset($payment_status) ? $payment_status : '';
                $data[$key]['amount'] = $order_details['display_order_total'];
                $data[$key]['date_time'] = $model->wps_deals_get_date_format($value['post_date'], true);
                $data[$key]['payment_method'] = isset($order_details['admin_label']) ? $order_details['admin_label'] : $order_details['payment_method'];
                $data[$key]['user_id'] = $userdetails['user_id'];
                $data[$key]['user_name'] = $username;
                $generatedrow = apply_filters('wps_deals_sales_pdf_generate_row_data', array($no, $data[$key]['ID'], $displayusername, $data[$key]['useremail'], html_entity_decode($data[$key]['amount']), $data[$key]['user_name'], $data[$key]['payment_status'], $data[$key]['date_time']));
                //generate row
                $pdf->Row($generatedrow);
                $no++;
            }
        } else {
            $pdf->SetWidths(array(280));
            $pdf->SetAligns('C');
            $title = utf8_decode(__('No Sales Data found.', 'wpsdeals'));
            $pdf->Row(array($title));
        }
        $pdf->Output('wps-deals-sales-reports-' . wps_deals_current_date('d-m-Y') . '.pdf', 'D');
    }
}
 /**
  * Loads Single Deal Expired Template
  * 
  * Handles to load single deal expired
  * template
  *  
  * @package Social Deals Engine
  * @since 1.0.0
  */
 function wps_deals_single_deal_expired()
 {
     global $post;
     $prefix = WPS_DEALS_META_PREFIX;
     //today's date time
     $today = wps_deals_current_date();
     //get the value for available deals from the post meta box
     $available = get_post_meta($post->ID, $prefix . 'avail_total', true);
     //get the value for start date & time of deals from the post meta box
     $startdate = get_post_meta($post->ID, $prefix . 'start_date', true);
     //get the value for end date & time of deals from the post meta box
     $enddate = get_post_meta($post->ID, $prefix . 'end_date', true);
     //when deal expired
     $dealexpired = false;
     //expired label
     $expiredtext = __('Deal expired', 'wpsdeals');
     if ($available == '') {
         //$availdeals =  __('Unlimited','wpsdeals');
     } elseif (intval($available) == 0 && $enddate >= $today) {
         // deal out of stock
         $expiredtext = __('Deal Sold Out', 'wpsdeals');
         $dealexpired = true;
     } else {
         //nothing to do
     }
     if ($enddate <= $today || $dealexpired == true) {
         //deal expired template
         wps_deals_get_template('single-deal/add-to-cart/expired.php', array('expiredtext' => $expiredtext));
     }
 }
 * The template for displaying product content in the single-deal.php template
 *
 * Override this template by copying it to yourtheme/deals-engine/content-single-deal.php
 *
 * @author 		Social Deals Engine
 * @package 	Deals-Engine/Includes/Templates
 * @version     2.0.0
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $wps_deals_options, $post;
$prefix = WPS_DEALS_META_PREFIX;
//today's date time
$today = wps_deals_current_date();
// get the end date & time
$enddate = get_post_meta($post->ID, $prefix . 'end_date', true);
// get the value for the amount of available deals
$available = get_post_meta($post->ID, $prefix . 'avail_total', true);
$expired = '';
if (!empty($enddate) && $enddate <= $today || $available == '0') {
    $expired = ' deal-expired';
}
// get the size
$deal_size = isset($wps_deals_options['deals_size_single']) ? $wps_deals_options['deals_size_single'] : '';
?>

<?php 
/**
 * wps_deals_before_single_deal hook
    /**
     * Get Single Deal Data
     * 
     * Handles to getting single deal data on the viewing page
     * whereever user put shortcode
     * 
     * @package Social Deals Engine
     * @since 1.0.0 
     */
    public function wps_deals_single($atts, $content)
    {
        global $post, $wps_deals_options;
        // get the size for the design from the settings page
        $size = $wps_deals_options['deals_size'];
        extract(shortcode_atts(array('id' => ''), $atts));
        if (!empty($id)) {
            // Check deal id is not empty from shortcode
            ob_start();
            // get the size
            $deal_size = isset($wps_deals_options['deals_size_single']) ? $wps_deals_options['deals_size_single'] : '';
            // Add query for display single deal wherever user put single deal id in shortcode
            $args = array('post_type' => WPS_DEALS_POST_TYPE, 'post__in' => array($id), 'posts_per_page' => '1');
            // The Query
            $the_query = new WP_Query($args);
            // The Loop
            if ($the_query->have_posts()) {
                while ($the_query->have_posts()) {
                    $the_query->the_post();
                    $prefix = WPS_DEALS_META_PREFIX;
                    //today's date time
                    $today = wps_deals_current_date();
                    // get the end date & time
                    $enddate = get_post_meta($post->ID, $prefix . 'end_date', true);
                    // get the value for the amount of available deals
                    $available = get_post_meta($post->ID, $prefix . 'avail_total', true);
                    $expired = '';
                    if (!empty($enddate) && $enddate <= $today || $available == '0') {
                        $expired = ' deal-expired';
                    }
                    //do action to add localize script for individual post data
                    do_action('wps_deals_localize_map_script');
                    //do action to add in top of single page
                    do_action('wps_deals_single_top');
                    /**
                     * wps_deals_before_single_deal_content hook
                     */
                    do_action('wps_deals_before_single_deal_content');
                    ?>
					<div class=" <?php 
                    echo $deal_size;
                    ?>
">
						
						<div class="deals-container deals-clearfix">
					
							<div id="sde" class="deals-single deals-row<?php 
                    echo $expired;
                    ?>
">
											
								<?php 
                    /**
                     * wps_deals_single_header_content hook
                     *
                     * @hooked wps_deals_breadcrumbs - 5
                     * @hooked wps_deals_single_header_message - 10
                     * @hooked wps_deals_single_header_title - 20
                     * @hooked wps_deals_single_header_left - 30
                     * @hooked wps_deals_single_header_right - 35
                     */
                    do_action('wps_deals_single_header_content');
                    ?>
																
							</div>
							
							<?php 
                    /**
                     * wps_deals_single_content hook
                     *
                     * @hooked wps_deals_single_description - 10
                     * @hooked wps_deals_single_business_info - 20
                     * @hooked wps_deals_single_terms_conditions - 30
                     */
                    do_action('wps_deals_single_content');
                    /**
                     * wps_deals_single_content hook
                     *
                     * @hooked wps_deals_single_description - 10
                     * @hooked wps_deals_single_business_info - 20
                     * @hooked wps_deals_single_terms_conditions - 30
                     */
                    do_action('wps_deals_single_footer_content');
                    ?>
						</div>

					</div><!-- .deal size -->											
						<?php 
                    /**
                     * wps_deals_after_single_deal_content hook
                     */
                    do_action('wps_deals_after_single_deal_content');
                    ?>

						<meta itemprop="url" content="<?php 
                    the_permalink();
                    ?>
" />								
						
					<?php 
                }
                wp_reset_query();
            }
            $content .= ob_get_clean();
        }
        return $content;
    }
 /**
  * Display Multiple Deals from shortcode
  * 
  * Handles to display multiple deals from shortcode
  * 
  * @package Social Deals Engine
  * @since 1.0.0
  */
 public function wps_deals_multiple_deals($atts)
 {
     global $post, $wps_deals_options;
     extract(shortcode_atts(array('ids' => '', 'disable_price' => '', 'disable_timer' => ''), $atts));
     $html = '';
     if (!empty($ids)) {
         // Check ids are not empty
         $ids = explode(',', $ids);
         $prefix = WPS_DEALS_META_PREFIX;
         //current date and time
         $today = wps_deals_current_date('Y-m-d H:i:s');
         /* all active deals listing start */
         $dealsmetaquery = array(array('key' => $prefix . 'start_date', 'value' => $today, 'compare' => '<=', 'type' => 'STRING'), array('key' => $prefix . 'end_date', 'value' => $today, 'compare' => '>=', 'type' => 'STRING'));
         $argssrcd = array('post_type' => WPS_DEALS_POST_TYPE, 'post__in' => $ids, 'meta_query' => $dealsmetaquery, 'posts_per_page' => '-1');
         ob_start();
         //active deals template
         wps_deals_get_template('home-deals/more-deals/more-deals.php', array('args' => $argssrcd, 'tab' => '', 'options' => array('disable_price' => $disable_price, 'disable_timer' => $disable_timer)));
         $html .= ob_get_clean();
     }
     echo $html;
 }
Esempio n. 8
0
 * Override this template by copying it to 
 * yourtheme/deals-engine/single-deal/single-content.php
 * 
 * @package Social Deals Engine
 * @since 1.0.0
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $post;
$prefix = WPS_DEALS_META_PREFIX;
//get disable button value
$disable_button = get_post_meta($post->ID, $prefix . 'disable_button_bottom', true);
//today's date time
$today = wps_deals_current_date('Y-m-d H:i:s');
//get the value for start date & time of deals from the post meta box
$startdate = get_post_meta($post->ID, $prefix . 'start_date', true);
?>
<div class="row-fluid">
	<div class="wps-deals-product-content">
	
		<?php 
//do action to load middle content top
do_action('wps_deals_single_middle_content_top');
if ($disable_button != 'on' && $startdate <= $today) {
    //button is enable && deal start date should be less or equal to today
    ?>
					<div class="row-fluid">
						<div class="span3 hidden-phone"></div>
							<div class="wps-deals-product-btn span6">
                    //order id
                    $args['email'] = $_POST['wps-deals-edit-order-email'];
                    //order user email id
                    if (isset($_POST['wps-deals-order-edit-append-comment']) && !empty($_POST['wps-deals-order-edit-append-comment'])) {
                        $args['comments'] = $comments;
                        $args['appendcomment'] = '1';
                    }
                    //end if to check append comment is set or not
                    //send notification to customer
                    $args['status'] = $model->wps_deals_paypal_value_to_status($newstatus);
                    $model->wps_deals_send_order_status_email($args);
                }
                //check notify customer checkbox is checked or not
                //update order track to database
                $notify = isset($_POST['wps-deals-order-edit-notify']) && !empty($_POST['wps-deals-order-edit-notify']) ? '1' : '0';
                $track = array('date' => wps_deals_current_date('Y-m-d H:i:s'), 'notify' => $notify, 'payment_status' => $newstatus, 'comments' => $comments, 'orderid' => $orderid);
                //update order tracking data
                wps_deals_update_order_track($track);
            }
            //check payment status is changed or not & payment note is not empty
            //call some action to update data to database
            do_action('wps_deals_edit_order_update', $_POST, $orderid);
        }
        //end if to check update order button is clicked or not
        ?>
<div id="wps-deals-sales" class="post-box-container">
	<div class="metabox-holder">	
		<div class="meta-box-sortables ui-sortable">
			<div id="order" class="postbox">	
				<div class="handlediv" title="<?php 
        _e('Click to toggle', 'wpsdeals');
    /**
     * Outputs the content of the widget
     */
    function widget($args, $instance)
    {
        global $post, $wps_deals_options;
        extract($args);
        $prefix = WPS_DEALS_META_PREFIX;
        // deals main page
        $dealspage = $wps_deals_options['deals_main_page'];
        // current date and time
        $today = wps_deals_current_date('Y-m-d H:i:s');
        $title = apply_filters('widget_title', $instance['title']);
        $limit = $instance['limit'];
        $disable_timer = $instance['disable_timer'];
        $deal_size = isset($instance['deal_size']) ? esc_attr($instance['deal_size']) : 'medium';
        $deal_ids = isset($instance['deal_ids']) && !empty($instance['deal_ids']) ? explode(',', $instance['deal_ids']) : array();
        // get the color scheme from the settings
        $button_color = $wps_deals_options['deals_btn_color'];
        $btncolor = isset($button_color) && !empty($button_color) ? $button_color : 'blue';
        // all active deals
        $dealsmetaquery = array(array('key' => $prefix . 'start_date', 'value' => $today, 'compare' => '<=', 'type' => 'STRING'), array('key' => $prefix . 'end_date', 'value' => $today, 'compare' => '>=', 'type' => 'STRING'));
        //$this_post = $post->ID;
        $this_post = isset($post->ID) ? $post->ID : '';
        $argswidget = array('post_type' => WPS_DEALS_POST_TYPE, 'post_status' => '', 'posts_per_page' => $limit, 'meta_query' => $dealsmetaquery, 'orderby' => 'rand');
        if (!empty($deal_ids)) {
            $argswidget['post__in'] = $deal_ids;
        } else {
            $argswidget['post__not_in'] = array($this_post);
        }
        $loop = null;
        $loop = new WP_Query();
        $loop->query($argswidget);
        $html = '';
        if ($loop->have_posts()) {
            echo $before_widget;
            $html .= '<div class="deals-row deals-clearfix">';
            $html .= '<div class="deals-widget ' . $deal_size . ' deals-col-12">';
            if ($title) {
                $alldeals = '<div class="deals-after-title"><a href="' . get_permalink($dealspage) . '">' . __('See All', 'wpsdeals') . '</a></div>';
                echo $before_title . $title . $alldeals . $after_title;
            }
            while ($loop->have_posts()) {
                $loop->the_post();
                // get the value of image url from the post meta box
                //$imgurl = get_post_meta($post->ID,$prefix.'main_image',true);
                // get the deal main image
                $imgurl = get_post_meta($post->ID, $prefix . 'main_image', true);
                // add filter to change deal main image of deal by third party plugin
                $imgurl['src'] = apply_filters('wps_deals_main_image_src', $imgurl['src'], $post->ID);
                // no image
                $imgsrc = isset($imgurl['src']) && !empty($imgurl['src']) ? $imgurl['src'] : apply_filters('wps_deals_default_img_src', WPS_DEALS_URL . 'includes/images/deals-no-image-big.jpg');
                // get the normal price
                $normalprice = get_post_meta($post->ID, $prefix . 'normal_price', true);
                // get the sales price
                $saleprice = get_post_meta($post->ID, $prefix . 'sale_price', true);
                // get the start date & time
                $startdate = get_post_meta($post->ID, $prefix . 'start_date', true);
                // getthe end date and time
                $enddate = get_post_meta($post->ID, $prefix . 'end_date', true);
                // check that the start or end date ar not empty
                if (!empty($startdate) || !empty($enddate)) {
                    // check if the start date is in the future
                    if ($startdate >= $today) {
                        $counterdate = $startdate;
                    } else {
                        $counterdate = $enddate;
                    }
                }
                // calculate saving price
                $yousave = $this->price->wps_deals_get_savingprice($post->ID);
                // get the display price
                $price = $this->price->wps_deals_get_price($post->ID);
                // get the product price
                $productprice = $this->price->get_display_price($price, $post->ID);
                // get the discount
                $discount = $this->price->wps_deals_get_discount($post->ID);
                // beginning of the single widget content
                $html .= '<div class="deals-more-content">';
                if (!empty($discount) && $discount != '0%') {
                    // discount box
                    $html .= ' 	<div class="deals-more-discount-box">	
									<p class="deals-more-discount">
										<span>
											 -&nbsp;' . $discount . '
										</span>
									</p>									
								</div>';
                }
                // deal image
                $html .= '	<div class="deals-more-content-img">
								<a href="' . get_permalink($post->ID) . '" title="' . strip_tags(get_the_title($post->ID)) . '" >
									<img src="' . $imgsrc . '" width="100%" alt="' . strip_tags(get_the_title($post->ID)) . '" />
								</a>
							</div>';
                // deal timer
                if (empty($disable_timer)) {
                    // enqueue the timer
                    wp_enqueue_script('wps-deals-countdown-timer-scripts');
                    $endyear = date('Y', strtotime($counterdate));
                    $endmonth = date('m', strtotime($counterdate));
                    $endday = date('d', strtotime($counterdate));
                    $endhours = date('H', strtotime($counterdate));
                    $endminute = date('i', strtotime($counterdate));
                    $endseconds = date('s', strtotime($counterdate));
                    $html .= '		<div class="deals-timing deals-timer-home-list deals-end-timer" 
											timer-year="' . $endyear . '"
											timer-month="' . $endmonth . '"
											timer-day="' . $endday . '"
											timer-hours="' . $endhours . '"
											timer-minute="' . $endminute . '"
											timer-second="' . $endseconds . '">
											<span class="timer-icon"></span>
									</div>';
                }
                // deal title
                $html .= '	<h3 class="deals-more-title">
								' . get_the_title($post->ID) . '						
							</h3>';
                if ($normalprice !== '' || $price !== '') {
                    // deal price
                    $html .= '	<div class="deals-more-price-box">
									<p class="deals-more-price">
										<del>
											' . $this->price->get_display_price($normalprice, $post->ID) . '
										</del>	
									</p>
									<p class="deals-more-price-special">
										<span>
											' . $productprice . '
										</span>
									</p>									
								</div>';
                }
                // view deal button
                $html .= '	<div class="' . $btncolor . ' deals-button btn-small">
								<a href="' . get_permalink($post->ID) . '">	
									' . __('See Deal', 'wpsdeals') . '	
								</a>																		
							</div>';
                $html .= '</div>';
                // deals-more-content
            }
            $html .= '</div>';
            // deals-widget-content
            $html .= '</div>';
            // deals-row
            $cache = $html;
            echo $cache;
            echo $after_widget;
        }
        wp_reset_query();
    }
Esempio n. 11
0
/**
 * Update Order Track
 * 
 * Handles to update order track
 * data to database
 * 
 * @package Social Deals Engine 
 * @since 1.0.0
 **/
function wps_deals_update_order_track($args = array())
{
    $prefix = WPS_DEALS_META_PREFIX;
    //customer is notified or not
    $notifycustomer = isset($args['notify']) ? $args['notify'] : '0';
    //order id
    $orderid = $args['orderid'];
    //new payment status
    $paymentstatus = $args['payment_status'];
    //comments for trackin
    $comments = isset($args['comments']) ? $args['comments'] : '';
    //get saved order tracking data
    $track = get_post_meta($orderid, $prefix . 'order_track', true);
    //initialize tracking data with array
    $track = !empty($track) ? $track : array();
    $track[] = array('date' => wps_deals_current_date('Y-m-d H:i:s'), 'notify' => $notifycustomer, 'status' => $paymentstatus, 'comments' => $comments);
    //update order tracking data
    update_post_meta($orderid, $prefix . 'order_track', $track);
}
/**
 * Validate Order Details
 *
 * @return unknown
 */
function wps_deals_order_data_validate()
{
    global $wps_deals_cart, $wps_deals_message;
    $prefix = WPS_DEALS_META_PREFIX;
    $cart = $wps_deals_cart;
    $message = $wps_deals_message;
    //get cart products
    $cartproducts = $cart->getproduct();
    $error = false;
    $errormsg = '';
    //get today's date & time
    $today = wps_deals_current_date();
    //validation code
    //checking is there error occuered before proceed for storing data in data base
    if (!empty($cartproducts)) {
        foreach ($cartproducts as $dealid => $dealdata) {
            //get the data by deal id
            $getdeal = get_post($dealid);
            //get the value for available deals from post meta
            $available = get_post_meta($dealid, $prefix . 'avail_total', true);
            //get the value for start date
            $startdate = get_post_meta($dealid, $prefix . 'start_date', true);
            //get the value for end date
            $enddate = get_post_meta($dealid, $prefix . 'end_date', true);
            if ($startdate <= $today && $enddate >= $today) {
                //check deal start date and end date not greater then today
                if ($available < 1 && $available != '') {
                    $error = true;
                } else {
                    if ($dealdata['quantity'] > $available && $available != '') {
                        //check use entered copy is not more then stock
                        $error = true;
                    }
                }
            } else {
                if ($startdate > $today) {
                    //check deal is not started yet
                    $error = true;
                } else {
                    if ($enddate < $today) {
                        //check deal is ended or not \
                        $error = true;
                    }
                }
            }
        }
    } else {
        $error = true;
    }
    if ($error) {
        // if error set
        //if there is any error occured then show error
        $errormsg = __('<strong>ERROR : </strong>Please see errors below.</span>', 'wpsdeals');
        $message->add_session('error', $errormsg, 'error');
        return false;
    } else {
        return true;
    }
}
/**
 * Sets up the dates used to filter graph data
 *
 * Date sent via $_GET is read first and then modified (if needed) to match the selected date-range (if any)
 *
 * @access      public
 * @since       1.0.0
 * @return      void
*/
function wps_deals_get_report_dates()
{
    $dates = array();
    $dates['range'] = isset($_GET['range']) ? $_GET['range'] : 'this_month';
    $dates['day'] = isset($_GET['day']) ? $_GET['day'] : null;
    $dates['m_start'] = isset($_GET['m_start']) ? $_GET['m_start'] : 1;
    $dates['m_end'] = isset($_GET['m_end']) ? $_GET['m_end'] : 12;
    $dates['year'] = isset($_GET['year']) ? $_GET['year'] : wps_deals_current_date('Y');
    $dates['year_end'] = wps_deals_current_date('Y');
    // Modify dates based on predefined ranges
    switch ($dates['range']) {
        case 'this_month':
            $dates['m_start'] = wps_deals_current_date('n');
            $dates['m_end'] = wps_deals_current_date('n');
            $dates['year'] = wps_deals_current_date('Y');
            break;
        case 'last_month':
            if ($dates['m_start'] == 12) {
                $dates['m_start'] = 12;
                $dates['m_end'] = 12;
                $dates['year'] = wps_deals_current_date('Y') - 1;
                $dates['year_end'] = wps_deals_current_date('Y') - 1;
            } else {
                $dates['m_start'] = wps_deals_current_date('n') - 1;
                $dates['m_end'] = wps_deals_current_date('n') - 1;
                $dates['year'] = wps_deals_current_date('Y');
            }
            break;
        case 'today':
            $dates['day'] = wps_deals_current_date('d');
            $dates['m_start'] = wps_deals_current_date('n');
            $dates['m_end'] = wps_deals_current_date('n');
            $dates['year'] = wps_deals_current_date('Y');
            break;
        case 'this_week':
            $dates['day'] = date('d', wps_deals_current_time() - (wps_deals_current_date('w') - 1) * 60 * 60 * 24);
            $dates['day_end'] = $dates['day'] + 6;
            $dates['m_start'] = wps_deals_current_date('n');
            $dates['m_end'] = wps_deals_current_date('n');
            $dates['year'] = wps_deals_current_date('Y');
            break;
        case 'last_week':
            $dates['day'] = date('d', wps_deals_current_time() - (wps_deals_current_date('w') - 1) * 60 * 60 * 24) - 6;
            $dates['day_end'] = $dates['day'] + 6;
            $dates['m_start'] = wps_deals_current_date('n');
            $dates['m_end'] = wps_deals_current_date('n');
            $dates['year'] = wps_deals_current_date('Y');
            break;
        case 'this_quarter':
            $month_now = wps_deals_current_date('n');
            if ($month_now <= 3) {
                $dates['m_start'] = 1;
                $dates['m_end'] = 3;
                $dates['year'] = wps_deals_current_date('Y');
            } else {
                if ($month_now <= 6) {
                    $dates['m_start'] = 4;
                    $dates['m_end'] = 6;
                    $dates['year'] = wps_deals_current_date('Y');
                } else {
                    if ($month_now <= 9) {
                        $dates['m_start'] = 7;
                        $dates['m_end'] = 9;
                        $dates['year'] = wps_deals_current_date('Y');
                    } else {
                        $dates['m_start'] = 10;
                        $dates['m_end'] = 12;
                        $dates['year'] = wps_deals_current_date('Y');
                    }
                }
            }
            break;
        case 'last_quarter':
            $month_now = wps_deals_current_date('n');
            if ($month_now <= 3) {
                $dates['m_start'] = 10;
                $dates['m_end'] = 12;
                $dates['year'] = wps_deals_current_date('Y') - 1;
                // Previous year
            } else {
                if ($month_now <= 6) {
                    $dates['m_start'] = 1;
                    $dates['m_end'] = 3;
                    $dates['year'] = wps_deals_current_date('Y');
                } else {
                    if ($month_now <= 9) {
                        $dates['m_start'] = 4;
                        $dates['m_end'] = 6;
                        $dates['year'] = wps_deals_current_date('Y');
                    } else {
                        $dates['m_start'] = 7;
                        $dates['m_end'] = 9;
                        $dates['year'] = wps_deals_current_date('Y');
                    }
                }
            }
            break;
        case 'this_year':
            $dates['m_start'] = 1;
            $dates['m_end'] = 12;
            $dates['year'] = wps_deals_current_date('Y');
            break;
        case 'last_year':
            $dates['m_start'] = 1;
            $dates['m_end'] = 12;
            $dates['year'] = wps_deals_current_date('Y') - 1;
            break;
    }
    return apply_filters('wps_deals_report_dates', $dates);
}
Esempio n. 14
0
/**
 * Export Deals Report Data
 *
 * Handles to export deals report data to csv
 * 
 * @package Social Deals Engine
 * @since 1.0.0
 */
function wps_deals_report_to_csv()
{
    global $wps_deals_model, $wps_deals_currency;
    //model class
    $model = $wps_deals_model;
    //currency class
    $currency = $wps_deals_currency;
    //export deals report to CSV file
    if (isset($_POST['wps-deals-report-exports']) && !empty($_POST['wps-deals-report-exports'])) {
        //check post is set or not
        $exports = '';
        //get deals sale data from database
        $data = $model->wps_deals_get_data();
        $columns = apply_filters('wps_deals_exports_sales_report_columns', array(__('Deals', 'wpsdeals'), __('Sales', 'wpsdeals'), __('Earnings', 'wpsdeals'), __('Monthly Average Sales', 'wpsdeals'), __('Monthly Average Earnings', 'wpsdeals')));
        // Put the name of all fields
        foreach ($columns as $column) {
            $exports .= '"' . $column . '",';
        }
        $exports .= "\n";
        foreach ($data as $key => $value) {
            //this line should be on start of loop
            $data[$key] = apply_filters('wps_deals_export_sales_report_column_data', $value, $value['ID']);
            $sales_data = $model->wps_deals_get_post_sale_count_earning($value['ID']);
            $monthly_sales_data = $model->wps_deals_get_monthly_sales_earning($value['ID']);
            $exports .= '"' . $value['post_title'] . '",';
            $exports .= '"' . $sales_data['salescount'] . '",';
            $exports .= '"' . html_entity_decode($currency->wps_deals_formatted_value($sales_data['earnings'])) . '",';
            $exports .= '"' . number_format($monthly_sales_data['salescount'], 2) . '",';
            $exports .= '"' . html_entity_decode($currency->wps_deals_formatted_value($monthly_sales_data['earnings'])) . '",';
            $exports .= "\n";
        }
        // Output to browser with appropriate mime type, you choose ;)
        header("Content-type: text/x-csv");
        header("Content-Disposition: attachment; filename=wps-deals-sales-report-" . wps_deals_current_date('d-m-Y') . ".csv");
        echo $exports;
        exit;
    }
    //export customer report to CSV file
    if (isset($_POST['wps-deals-customer-report-exports']) && !empty($_POST['wps-deals-customer-report-exports'])) {
        //check post is set or not
        $exports = '';
        //get deals sale data from database
        $data = $model->wps_deals_get_customers();
        $columns = apply_filters('wps_deals_exports_customers_columns', array(__('Name', 'wpsdeals'), __('Email', 'wpsdeals'), __('Purchases', 'wpsdeals'), __('Total Spent', 'wpsdeals')));
        // Put the name of all fields
        foreach ($columns as $column) {
            $exports .= '"' . $column . '",';
        }
        $exports .= "\n";
        foreach ($data as $key => $value) {
            $value_id = isset($value['ID']) ? $value['ID'] : '';
            //this line should be on start of loop
            $data[$key] = apply_filters('wps_deals_exports_customers_report_column_data', $value, $value_id);
            $wp_user = get_user_by('email', $value);
            $item = array();
            if ($wp_user) {
                $user_id = $wp_user->ID;
                $item['user_id'] = $user_id;
                $item['user_name'] = $wp_user->display_name;
            } else {
                $user_id = 0;
                $item['useremail'] = $value;
            }
            $purchases_args = array('useremail' => $value, 'getcount' => '1');
            $purchases_amount_data = $model->wps_deals_purchase_total_of_user($value);
            $exports .= '"' . ($wp_user ? $wp_user->display_name : __('guest', 'wpsdeals')) . '",';
            $exports .= '"' . $value . '",';
            $exports .= '"' . html_entity_decode($purchases_amount_data['salescount']) . '",';
            $exports .= '"' . html_entity_decode($currency->wps_deals_formatted_value($purchases_amount_data['earnings'])) . '",';
            $exports .= "\n";
        }
        // Output to browser with appropriate mime type, you choose ;)
        header("Content-type: text/x-csv");
        header("Content-Disposition: attachment; filename=wps-deals-customers-report-" . wps_deals_current_date('d-m-Y') . ".csv");
        echo $exports;
        exit;
    }
}