/**
  * Output the vendor coupon shortcode.
  *
  * @access public
  * @param array $atts
  * @return void
  */
 public static function output($attr)
 {
     global $WCMp;
     $WCMp->nocache();
     $coupon_arr = array();
     if (!defined('MNDASHBAOARD')) {
         define('MNDASHBAOARD', true);
     }
     if (is_user_logged_in()) {
         $user = wp_get_current_user();
         if (is_user_wcmp_vendor($user->ID)) {
             $vendor = get_wcmp_vendor($user->ID);
             if ($vendor) {
                 $args = array('posts_per_page' => -1, 'post_type' => 'shop_coupon', 'author' => $user->ID, 'post_status' => 'any');
                 $coupons = get_posts($args);
                 if (!empty($coupons)) {
                     foreach ($coupons as $coupon) {
                         $coupon_arr[] += $coupon->ID;
                     }
                 }
             }
             $WCMp->template->get_template('shortcode/vendor_coupon.php', array('coupons' => $coupon_arr));
         }
     }
 }
    /**
     * Output the vendor transaction details shortcode.
     *
     * @access public
     * @param array $atts
     * @return void
     */
    public static function output($attr)
    {
        global $WCMp;
        $WCMp->nocache();
        $transaction_ids = array();
        if (!defined('MNDASHBAOARD')) {
            define('MNDASHBAOARD', true);
        }
        $suffix = defined('WCMP_SCRIPT_DEBUG') && WCMP_SCRIPT_DEBUG ? '' : '.min';
        wp_enqueue_script('jquery-ui-datepicker');
        wp_enqueue_style('jquery_ui_css', $WCMp->plugin_url . 'assets/frontend/css/jquery-ui' . $suffix . '.css', array(), $WCMp->version);
        $frontend_script_path = $WCMp->plugin_url . 'assets/frontend/js/';
        $frontend_script_path = str_replace(array('http:', 'https:'), '', $frontend_script_path);
        $pluginURL = str_replace(array('http:', 'https:'), '', $WCMp->plugin_url);
        wp_enqueue_script('trans_dtl_js', $frontend_script_path . 'transaction_detail' . $suffix . '.js', array('jquery'), $WCMp->version, true);
        $user_id = get_current_user_id();
        if (is_user_wcmp_vendor($user_id)) {
            $vendor = get_wcmp_vendor($user_id);
            $start_date = date('01-m-Y');
            $end_date = date('t-m-Y');
            if ($_SERVER['REQUEST_METHOD'] == 'GET') {
                if (!empty($_GET['from_date']) && !empty($_GET['to_date'])) {
                    $transaction_details = $WCMp->transaction->get_transactions($vendor->term_id, $_GET['from_date'], $_GET['to_date'], false);
                } else {
                    if (!empty($_GET['from_date'])) {
                        $transaction_details = $WCMp->transaction->get_transactions($vendor->term_id, $_GET['from_date'], date('j-n-Y'), false);
                    } else {
                        $transaction_details = $WCMp->transaction->get_transactions($vendor->term_id, $start_date, $end_date, false);
                    }
                }
            } else {
                $transaction_details = $WCMp->transaction->get_transactions($vendor->term_id, $start_date, $end_date, false);
            }
            if (!empty($transaction_details)) {
                foreach ($transaction_details as $transaction_id => $detail) {
                    $transaction_ids[] = $transaction_id;
                }
            }
            ?>
			<div class="wcmp_remove_div">
				<div class="wcmp_main_page"> 
					<?php 
            $WCMp->template->get_template('vendor_dashboard_menu.php', array('selected_item' => 'history'));
            $WCMp->template->get_template('shortcode/vendor_transactions.php', array('transactions' => $transaction_ids));
            wp_localize_script('trans_dtl_js', 'wcmp_vendor_transactions_array', $transaction_ids);
            ?>
				</div>
			</div>
		<?php 
        }
    }
    /**
     * Output the shop settings shortcode.
     *
     * @access public
     * @param array $atts
     * @return void
     */
    public static function output($attr)
    {
        global $WCMp;
        $WCMp->nocache();
        if (!defined('MNDASHBAOARD')) {
            define('MNDASHBAOARD', true);
        }
        $frontend_script_path = $WCMp->plugin_url . 'assets/frontend/js/';
        $frontend_script_path = str_replace(array('http:', 'https:'), '', $frontend_script_path);
        $pluginURL = str_replace(array('http:', 'https:'), '', $WCMp->plugin_url);
        $suffix = defined('WCMP_SCRIPT_DEBUG') && WCMP_SCRIPT_DEBUG ? '' : '.min';
        wp_enqueue_script('wcmp_profile_edit_js', $frontend_script_path . '/profile_edit' . $suffix . '.js', array('jquery'), $WCMp->version, true);
        $user_id = get_current_user_id();
        $vendor = get_wcmp_vendor($user_id);
        $is_saved = 0;
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            if (isset($_POST['store_save'])) {
                $WCMp->vendor_dashboard->save_store_settings($vendor->id, $_POST);
                $is_saved = 1;
            }
        }
        $user_array = $WCMp->user->get_vendor_fields($vendor->id);
        $user_array['is_shop_settings_saved'] = $is_saved;
        ?>
		<?php 
        if ($user_array['is_shop_settings_saved'] == 1) {
            ?>
						<div style="margin-bottom:10px; width:98%;" class="green_massenger"><i class="fa fa-check"></i> &nbsp; <?php 
            _e('All Options Saved', $WCMp->text_domain);
            ?>
</div>
						
					<?php 
        }
        ?>
		<div class="wcmp_remove_div">
		
			<div class="wcmp_main_page">  <?php 
        $WCMp->template->get_template('vendor_dashboard_menu.php', array('selected_item' => 'shop_front'));
        $WCMp->template->get_template('shortcode/shop_settings.php', $user_array);
        ?>
			</div>
		</div>
		<?php 
    }
    /**
     * Output the vendor dashboard shortcode.
     *
     * @access public
     * @param array $atts
     * @return void
     */
    public static function output($attr)
    {
        global $WCMp;
        $WCMp->nocache();
        if (!defined('MNDASHBAOARD')) {
            define('MNDASHBAOARD', true);
        }
        $suffix = defined('WCMP_SCRIPT_DEBUG') && WCMP_SCRIPT_DEBUG ? '' : '.min';
        $frontend_script_path = $WCMp->plugin_url . 'assets/frontend/js/';
        $frontend_script_path = str_replace(array('http:', 'https:'), '', $frontend_script_path);
        $pluginURL = str_replace(array('http:', 'https:'), '', $WCMp->plugin_url);
        wp_enqueue_script('wcmp_frontend_vdashboard_js', $frontend_script_path . 'wcmp_vendor_dashboard' . $suffix . '.js', array('jquery'), $WCMp->version, true);
        $user = wp_get_current_user();
        if (is_user_logged_in()) {
            if (is_user_wcmp_vendor($user->ID)) {
                $vendor = get_wcmp_vendor($user->ID);
                $vendor_all_orders = $vendor->get_orders();
                if ($vendor_all_orders) {
                    $count_orders = count($vendor_all_orders);
                } else {
                    $count_orders = 0;
                }
                $customer_orders = array();
                $customer_orders = $vendor->get_orders(5, 0);
                ?>
				<div class="wcmp_remove_div">
					<div class="wcmp_main_page"> 
						<?php 
                $WCMp->template->get_template('vendor_dashboard_menu.php', array('selected_item' => 'dashboard'));
                $WCMp->template->get_template('shortcode/vendor_dashboard.php', array('vendor' => $vendor, 'customer_orders' => $customer_orders));
                ?>
 
					</div>
				</div>
				<?php 
            } else {
                $WCMp->template->get_template('shortcode/non_vendor_dashboard.php');
            }
        }
    }
    /**
     * Output the vendor report shortcode.
     *
     * @access public
     * @param array $atts
     * @return void
     */
    public static function output($attr)
    {
        global $WCMp;
        $WCMp->nocache();
        if (!defined('MNDASHBAOARD')) {
            define('MNDASHBAOARD', true);
        }
        $user = wp_get_current_user();
        if (is_user_logged_in()) {
            if (is_user_wcmp_vendor($user->ID)) {
                if (isset($_GET['wcmp_stat_start_dt'])) {
                    $start_date = $_GET['wcmp_stat_start_dt'];
                } else {
                    $start_date = date('01-m-Y');
                }
                // hard-coded '01' for first day
                if (isset($_GET['wcmp_stat_end_dt'])) {
                    $end_date = $_GET['wcmp_stat_end_dt'];
                } else {
                    $end_date = date('t-m-Y');
                }
                // hard-coded '01' for first day
                $vendor = get_wcmp_vendor($user->ID);
                $WCMp_Plugin_Post_Reports = new WCMp_Report();
                $array_report = $WCMp_Plugin_Post_Reports->vendor_sales_stat_overview($vendor, $start_date, $end_date);
                ?>
				<div class="wcmp_remove_div">
					<div class="wcmp_main_page"> 
						<?php 
                $WCMp->template->get_template('vendor_dashboard_menu.php', array('selected_item' => 'vendor_report'));
                $WCMp->template->get_template('shortcode/vendor_report.php', $array_report);
                ?>
 
					</div>
				</div>
				<?php 
            }
        }
    }
    /**
     * Output the vendor dashboard shortcode.
     *
     * @access public
     * @param array $atts
     * @return void
     */
    public static function output($attr)
    {
        global $WCMp;
        $WCMp->nocache();
        if (!defined('MNDASHBAOARD')) {
            define('MNDASHBAOARD', true);
        }
        $user = wp_get_current_user();
        $vendor = get_wcmp_vendor($user->ID);
        if ($vendor) {
            $frontend_script_path = $WCMp->plugin_url . 'assets/frontend/js/';
            $frontend_script_path = str_replace(array('http:', 'https:'), '', $frontend_script_path);
            $pluginURL = str_replace(array('http:', 'https:'), '', $WCMp->plugin_url);
            $suffix = defined('WCMP_SCRIPT_DEBUG') && WCMP_SCRIPT_DEBUG ? '' : '.min';
            wp_enqueue_script('vendor_withdrawal_js', $frontend_script_path . 'vendor_withdrawal' . $suffix . '.js', array('jquery'), $WCMp->version, true);
            $meta_query['meta_query'] = array(array('key' => '_paid_status', 'value' => 'unpaid', 'compare' => '='), array('key' => '_commission_vendor', 'value' => absint($vendor->term_id), 'compare' => '='));
            $vendor_all_orders = $vendor->get_orders(false, false, $meta_query);
            if ($vendor_all_orders) {
                $count_orders = count($vendor_all_orders);
            } else {
                $count_orders = 0;
            }
            $customer_orders = array();
            $customer_orders = $vendor->get_orders(6, 0, $meta_query);
            ?>
			<div class="wcmp_remove_div">
				<div class="wcmp_main_page"> 
					<?php 
            $WCMp->template->get_template('vendor_dashboard_menu.php', array('selected_item' => 'widthdrawal'));
            $WCMp->template->get_template('shortcode/vendor_withdrawal.php', array('vendor' => $vendor, 'commissions' => $customer_orders, 'total_orders' => $count_orders));
            ?>
				</div>
			</div>
			<?php 
        }
    }
Esempio n. 7
0
 /**
  * get vendor commission by date
  *
  * @access public
  * @param mixed $vars
  * @return array
  */
 public function vendor_sales_stat_overview($vendor, $start_date = false, $end_date = false)
 {
     global $WCMp;
     $total_sales = 0;
     $total_vendor_earnings = 0;
     $total_order_count = 0;
     $total_purchased_products = 0;
     $total_coupon_used = 0;
     $total_coupon_discuont_value = 0;
     $total_earnings = 0;
     $total_customers = array();
     $vendor = get_wcmp_vendor(get_current_user_id());
     for ($date = strtotime($start_date); $date <= strtotime('+1 day', strtotime($end_date)); $date = strtotime('+1 day', $date)) {
         $year = date('Y', $date);
         $month = date('n', $date);
         $day = date('j', $date);
         $line_total = $sales = $comm_amount = $vendor_earnings = $earnings = 0;
         $args = array('post_type' => 'shop_order', 'posts_per_page' => -1, 'post_status' => array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed'), 'meta_query' => array(array('key' => '_commissions_processed', 'value' => 'yes', 'compare' => '=')), 'date_query' => array(array('year' => $year, 'month' => $month, 'day' => $day)));
         $qry = new WP_Query($args);
         $orders = apply_filters('wcmp_filter_orders_report_overview', $qry->get_posts(), $vendor->id);
         if (!empty($orders)) {
             foreach ($orders as $order_obj) {
                 $order = new WC_Order($order_obj->ID);
                 $items = $order->get_items('line_item');
                 $commission_array = array();
                 foreach ($items as $item_id => $item) {
                     $comm_pro_id = $product_id = $order->get_item_meta($item_id, '_product_id', true);
                     $line_total = $order->get_item_meta($item_id, '_line_total', true);
                     $variation_id = $order->get_item_meta($item_id, '_variation_id', true);
                     if ($variation_id) {
                         $comm_pro_id = $variation_id;
                     }
                     if ($product_id && $line_total) {
                         $product_vendors = get_wcmp_product_vendors($product_id);
                         if ($product_vendors) {
                             $sales += $line_total;
                             $total_sales += $line_total;
                             $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($product_vendors->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order_obj->ID), 'compare' => '='), array('key' => '_commission_product', 'value' => absint($comm_pro_id), 'compare' => 'LIKE')));
                             $commissions = get_posts($args);
                             $comm_amount = 0;
                             if (!empty($commissions)) {
                                 foreach ($commissions as $commission) {
                                     if (in_array($commission->ID, $commission_array)) {
                                         continue;
                                     }
                                     $comm_amount += (double) get_post_meta($commission->ID, '_commission_amount', true);
                                     $commission_array[] = $commission->ID;
                                 }
                             }
                             $vendor_earnings += $comm_amount;
                             $total_vendor_earnings += $comm_amount;
                             $earnings += $line_total - $comm_amount;
                             $total_earnings += $line_total - $comm_amount;
                             $total_purchased_products++;
                         }
                     }
                 }
                 //coupons count
                 $coupon_used = array();
                 $coupons = $order->get_items('coupon');
                 foreach ($coupons as $coupon_item_id => $item) {
                     $coupon = new WC_Coupon(trim($item['name']));
                     $coupon_post = get_post($coupon->id);
                     $author_id = $coupon_post->post_author;
                     if ($vendor->id == $author_id) {
                         $total_coupon_used++;
                         $total_coupon_discuont_value += (double) wc_add_order_item_meta($coupon_item_id, 'discount_amount', true);
                     }
                 }
                 ++$total_order_count;
                 //user count
                 if ($order->customer_user != 0 && $order->customer_user != 1) {
                     array_push($total_customers, $order->customer_user);
                 }
             }
         }
     }
     return array('total_order_count' => $total_order_count, 'total_vendor_sales' => $total_sales, 'total_vendor_earning' => $total_vendor_earnings, 'total_coupon_discuont_value' => $total_coupon_discuont_value, 'total_coupon_used' => $total_coupon_used, 'total_customers' => array_unique($total_customers), 'total_purchased_products' => $total_purchased_products);
 }
Esempio n. 8
0
 /**
  * Reject Pending Vendor via AJAX
  *
  * @return void
  */
 function reject_pending_vendor()
 {
     global $WCMp;
     $user_id = $_POST['user_id'];
     $user = new WP_User(absint($user_id));
     if (is_array($user->roles) && in_array('dc_pending_vendor', $user->roles)) {
         $user->remove_role('dc_pending_vendor');
     }
     $user->add_role('dc_rejected_vendor');
     $user_dtl = get_userdata(absint($user_id));
     $email = WC()->mailer()->emails['WC_Email_Rejected_New_Vendor_Account'];
     $email->trigger($user_id, $user_dtl->user_pass);
     if (in_array('dc_vendor', $old_role)) {
         $vendor = get_wcmp_vendor($user_id);
         if ($vendor) {
             wp_delete_term($vendor->term_id, 'dc_vendor_shop');
         }
     }
     wp_delete_user($user_id);
     die;
 }
 /**
  * Get assigned commission percentage
  *
  * @param  int $product_id ID of product
  * @param  int $vendor_id  ID of vendor
  * @return int             Relevent commission percentage
  */
 public function get_commission_amount($product_id = 0, $vendor_id = 0, $variation_id = 0, $item_id = '', $order = array())
 {
     global $WCMp;
     $data = array();
     if ($product_id > 0 && $vendor_id > 0) {
         $vendor_idd = $order->get_item_meta($item_id, '_vendor_id', true);
         if ($vendor_idd) {
             $vendor = get_wcmp_vendor($vendor_idd);
         } else {
             $vendor = get_wcmp_product_vendors($product_id);
         }
         if ($vendor->term_id == $vendor_id) {
             if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage') {
                 if ($variation_id > 0) {
                     $data['commission_val'] = get_post_meta($variation_id, '_product_vendors_commission_percentage', true);
                     $data['commission_fixed'] = get_post_meta($variation_id, '_product_vendors_commission_fixed_per_trans', true);
                     if (empty($data)) {
                         $data['commission_val'] = get_post_meta($product_id, '_commission_percentage_per_product', true);
                         $data['commission_fixed'] = get_post_meta($product_id, '_commission_fixed_with_percentage', true);
                     }
                 } else {
                     $data['commission_val'] = get_post_meta($product_id, '_commission_percentage_per_product', true);
                     $data['commission_fixed'] = get_post_meta($product_id, '_commission_fixed_with_percentage', true);
                 }
                 if (!empty($data['commission_val'])) {
                     return $data;
                     // Use product commission percentage first
                 } else {
                     $vendor_commission_percentage = 0;
                     $vendor_commission_percentage = get_user_meta($vendor->id, '_vendor_commission_percentage', true);
                     $vendor_commission_fixed_with_percentage = 0;
                     $vendor_commission_fixed_with_percentage = get_user_meta($vendor->id, '_vendor_commission_fixed_with_percentage', true);
                     if ($vendor_commission_percentage > 0) {
                         return array('commission_val' => $vendor_commission_percentage, 'commission_fixed' => $vendor_commission_fixed_with_percentage);
                         // Use vendor user commission percentage
                     } else {
                         if (isset($WCMp->vendor_caps->payment_cap['default_percentage'])) {
                             return array('commission_val' => $WCMp->vendor_caps->payment_cap['default_percentage'], 'commission_fixed' => $WCMp->vendor_caps->payment_cap['fixed_with_percentage']);
                         } else {
                             return false;
                         }
                     }
                 }
             } else {
                 if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage_qty') {
                     if ($variation_id > 0) {
                         $data['commission_val'] = get_post_meta($variation_id, '_product_vendors_commission_percentage', true);
                         $data['commission_fixed'] = get_post_meta($variation_id, '_product_vendors_commission_fixed_per_qty', true);
                         if (!$data) {
                             $data['commission_val'] = get_post_meta($product_id, '_commission_percentage_per_product', true);
                             $data['commission_fixed'] = get_post_meta($product_id, '_commission_fixed_with_percentage_qty', true);
                         }
                     } else {
                         $data['commission_val'] = get_post_meta($product_id, '_commission_percentage_per_product', true);
                         $data['commission_fixed'] = get_post_meta($product_id, '_commission_fixed_with_percentage_qty', true);
                     }
                     if (!empty($data['commission_val'])) {
                         return $data;
                         // Use product commission percentage first
                     } else {
                         $vendor_commission_percentage = 0;
                         $vendor_commission_fixed_with_percentage = 0;
                         $vendor_commission_percentage = get_user_meta($vendor->id, '_vendor_commission_percentage', true);
                         $vendor_commission_fixed_with_percentage = get_user_meta($vendor->id, '_vendor_commission_fixed_with_percentage_qty', true);
                         if ($vendor_commission_percentage > 0) {
                             return array('commission_val' => $vendor_commission_percentage, 'commission_fixed' => $vendor_commission_fixed_with_percentage);
                             // Use vendor user commission percentage
                         } else {
                             if (isset($WCMp->vendor_caps->payment_cap['default_percentage'])) {
                                 return array('commission_val' => $WCMp->vendor_caps->payment_cap['default_percentage'], 'commission_fixed' => $WCMp->vendor_caps->payment_cap['fixed_with_percentage_qty']);
                             } else {
                                 return false;
                             }
                         }
                     }
                 } else {
                     if ($variation_id > 0) {
                         $data['commission_val'] = get_post_meta($variation_id, '_product_vendors_commission', true);
                         if (!$data) {
                             $data['commission_val'] = get_post_meta($product_id, '_commission_per_product', true);
                         }
                     } else {
                         $data['commission_val'] = get_post_meta($product_id, '_commission_per_product', true);
                     }
                     if (!empty($data['commission_val'])) {
                         return $data;
                         // Use product commission percentage first
                     } else {
                         $vendor_commission = get_user_meta($vendor->id, '_vendor_commission', true);
                         if ($vendor_commission) {
                             return array('commission_val' => $vendor_commission);
                             // Use vendor user commission percentage
                         } else {
                             return isset($WCMp->vendor_caps->payment_cap['default_commission']) ? array('commission_val' => $WCMp->vendor_caps->payment_cap['default_commission']) : false;
                             // Use default commission
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
    /**
     * Output the report
     */
    public function output_report()
    {
        global $wpdb, $woocommerce, $WCMp;
        $ranges = array('year' => __('Year', $WCMp->text_domain), 'last_month' => __('Last Month', $WCMp->text_domain), 'month' => __('This Month', $WCMp->text_domain), '7day' => __('Last 7 Days', $WCMp->text_domain));
        $current_range = !empty($_GET['range']) ? sanitize_text_field($_GET['range']) : '7day';
        if (!in_array($current_range, array('custom', 'year', 'last_month', 'month', '7day'))) {
            $current_range = '7day';
        }
        $this->calculate_current_range($current_range);
        if (isset($_POST['search_product'])) {
            $is_variation = false;
            $product_id = $_POST['search_product'];
            $_product = get_product($product_id);
            if ($_product->is_type('variation')) {
                $title = $_product->get_formatted_name();
                $is_variation = true;
            } else {
                $title = $_product->get_title();
            }
        }
        if (isset($product_id)) {
            $option = '<option value="' . $product_id . '" selected="selected">' . $title . '</option>';
        } else {
            $option = '<option></option>';
        }
        $start_date = $this->start_date;
        $end_date = $this->end_date;
        $end_date = strtotime('+1 day', $end_date);
        $products = $product_ids = array();
        $vendor = false;
        $current_user_id = '';
        $current_user_id = get_current_user_id();
        $vendor = get_wcmp_vendor($current_user_id);
        if ($vendor) {
            $products = $vendor->get_products();
            foreach ($products as $product) {
                $product_ids[] = $product->ID;
            }
        } else {
            $args = array('posts_per_page' => -1, 'offset' => 0, 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'product', 'post_status' => 'publish');
            $products = get_posts($args);
            foreach ($products as $product) {
                $product_ids[] = $product->ID;
            }
        }
        $total_sales = $admin_earnings = array();
        $max_total_sales = $index = 0;
        $product_report = $report_bk = array();
        if (isset($product_ids) && !empty($product_ids)) {
            foreach ($product_ids as $product_id) {
                $is_variation = false;
                $_product = array();
                $vendor = false;
                $_product = get_product($product_id);
                if ($_product->is_type('variation')) {
                    $title = $_product->get_formatted_name();
                    $is_variation = true;
                } else {
                    $title = $_product->get_title();
                }
                if (isset($product_id) && !$is_variation) {
                    $vendor = get_wcmp_product_vendors($product_id);
                } else {
                    if (isset($product_id) && $is_variation) {
                        $variation_parent = wp_get_post_parent_id($product_id);
                        $vendor = get_wcmp_product_vendors($variation_parent);
                    }
                }
                if ($vendor) {
                    $orders = array();
                    if ($_product->is_type('variable')) {
                        $get_children = $_product->get_children();
                        if (!empty($get_children)) {
                            foreach ($get_children as $child) {
                                $orders = array_merge($orders, $vendor->get_vendor_orders_by_product($vendor->term_id, $child));
                            }
                            $orders = array_unique($orders);
                        }
                    } else {
                        $orders = array_unique($vendor->get_vendor_orders_by_product($vendor->term_id, $product_id));
                    }
                }
                $order_items = array();
                $i = 0;
                if (!empty($orders)) {
                    foreach ($orders as $order_id) {
                        $order = new WC_Order($order_id);
                        $order_line_items = $order->get_items('line_item');
                        if (!empty($order_line_items)) {
                            foreach ($order_line_items as $line_item) {
                                if ($line_item['product_id'] == $product_id) {
                                    if ($_product->is_type('variation')) {
                                        $order_items_product_id = $line_item['product_id'];
                                        $order_items_variation_id = $line_item['variation_id'];
                                    } else {
                                        $order_items_product_id = $line_item['product_id'];
                                        $order_items_variation_id = $line_item['variation_id'];
                                    }
                                    $order_date_str = strtotime($order->order_date);
                                    if ($order_date_str > $start_date && $order_date_str < $end_date) {
                                        $order_items[$i] = array('order_id' => $order_id, 'product_id' => $order_items_product_id, 'variation_id' => $order_items_variation_id, 'line_total' => $line_item['line_total'], 'item_quantity' => $line_item['qty'], 'post_date' => $order->order_date, 'multiple_product' => 0);
                                        if (count($order_line_items) > 1) {
                                            $order_items[$i]['multiple_product'] = 1;
                                        }
                                        $i++;
                                    }
                                }
                            }
                        }
                    }
                }
                if (isset($order_items) && !empty($order_items)) {
                    foreach ($order_items as $item_id => $order_item) {
                        if ($order_item['line_total'] == 0 && $order_item['item_quantity'] == 0) {
                            continue;
                        }
                        if ($order_item['variation_id'] != 0) {
                            $variation_id = $order_item['variation_id'];
                            $product_id_1 = $order_item['variation_id'];
                        } else {
                            $variation_id = 0;
                            $product_id_1 = $order_item['product_id'];
                        }
                        $vendor = get_wcmp_product_vendors($product_id);
                        if (!$vendor) {
                            break;
                        }
                        $commissions = false;
                        $vendor_earnings = 0;
                        if ($order_item['multiple_product'] == 0) {
                            $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($vendor->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order_item['order_id']), 'compare' => '='), array('key' => '_commission_product', 'value' => absint($product_id_1), 'compare' => 'LIKE')));
                            $commissions = get_posts($args);
                            if (!empty($commissions)) {
                                foreach ($commissions as $item_id => $commission) {
                                    $vendor_earnings = $vendor_earnings + get_post_meta($commission->ID, '_commission_amount', true);
                                }
                            }
                        } else {
                            if ($order_item['multiple_product'] == 1) {
                                $vendor_obj = new WCMp_Vendor();
                                $vendor_items = $vendor_obj->get_vendor_items_from_order($order_item['order_id'], $vendor->term_id);
                                foreach ($vendor_items as $vendor_item) {
                                    if ($variation_id == 0) {
                                        if ($vendor_item['product_id'] == $product_id) {
                                            $item = $vendor_item;
                                            break;
                                        }
                                    } else {
                                        if ($vendor_item['product_id'] == $product_id && $vendor_item['variation_id'] == $variation_id) {
                                            $item = $vendor_item;
                                            break;
                                        }
                                    }
                                }
                                $commission_obj = new WCMp_Calculate_Commission();
                                $vendor_earnings = $commission_obj->get_item_commission($product_id, $variation_id, $item, $order_item['order_id'], $item_id);
                            }
                        }
                        if ($vendor_earnings <= 0) {
                            continue;
                        }
                        $total_sales[$product_id] = isset($total_sales[$product_id]) ? $total_sales[$product_id] + $order_item['line_total'] : $order_item['line_total'];
                        $vendor = get_wcmp_vendor($current_user_id);
                        if (!$vendor) {
                            $admin_earnings[$product_id] = isset($admin_earnings[$product_id]) ? $admin_earnings[$product_id] + $order_item['line_total'] - $vendor_earnings : $order_item['line_total'] - $vendor_earnings;
                        } else {
                            $admin_earnings[$product_id] = isset($admin_earnings[$product_id]) ? $admin_earnings[$product_id] + $vendor_earnings : $vendor_earnings;
                        }
                        if ($total_sales[$product_id] > $max_total_sales) {
                            $max_total_sales = $total_sales[$product_id];
                        }
                    }
                }
                if (!empty($total_sales[$product_id]) && !empty($admin_earnings[$product_id])) {
                    $product_report[$index]['product_id'] = $product_id;
                    $product_report[$index]['total_sales'] = $total_sales[$product_id];
                    $product_report[$index++]['admin_earning'] = $admin_earnings[$product_id];
                    $report_bk[$product_id]['total_sales'] = $total_sales[$product_id];
                    $report_bk[$product_id]['admin_earning'] = $admin_earnings[$product_id];
                }
            }
            $i = 0;
            $max_value = 10;
            $report_sort_arr = array();
            $total_sales_sort = $admin_earning_sort = array();
            if (!empty($product_report) && !empty($report_bk)) {
                $total_sales_sort = wp_list_pluck($product_report, 'total_sales', 'product_id');
                $admin_earning_sort = wp_list_pluck($product_report, 'admin_earning', 'product_id');
                foreach ($total_sales_sort as $key => $value) {
                    $total_sales_sort_arr[$key]['total_sales'] = $report_bk[$key]['total_sales'];
                    $total_sales_sort_arr[$key]['admin_earning'] = $report_bk[$key]['admin_earning'];
                }
                arsort($total_sales_sort);
                foreach ($total_sales_sort as $product_id => $value) {
                    if ($i++ < $max_value) {
                        $report_sort_arr[$product_id]['total_sales'] = $report_bk[$product_id]['total_sales'];
                        $report_sort_arr[$product_id]['admin_earning'] = $report_bk[$product_id]['admin_earning'];
                    }
                }
            }
            wp_localize_script('wcmp_report_js', 'wcmp_report_product', array('product_report' => $product_report, 'report_bk' => $report_bk, 'total_sales_sort' => $total_sales_sort, 'admin_earning_sort' => $admin_earning_sort, 'max_total_sales' => $max_total_sales, 'start_date' => $start_date, 'end_date' => $end_date));
            $report_chart = $report_html = '';
            if (sizeof($report_sort_arr) > 0) {
                foreach ($report_sort_arr as $product_id => $sales_report) {
                    $width = $sales_report['total_sales'] > 0 ? round($sales_report['total_sales']) / round($max_total_sales) * 100 : 0;
                    $width2 = $sales_report['admin_earning'] > 0 ? round($sales_report['admin_earning']) / round($max_total_sales) * 100 : 0;
                    $product = new WC_Product($product_id);
                    $product_url = admin_url('post.php?post=' . $product_id . '&action=edit');
                    $report_chart .= '<tr><th><a href="' . $product_url . '">' . $product->get_title() . '</a></th>
						<td width="1%"><span>' . woocommerce_price($sales_report['total_sales']) . '</span><span class="alt">' . woocommerce_price($sales_report['admin_earning']) . '</span></td>
						<td class="bars">
							<span style="width:' . esc_attr($width) . '%">&nbsp;</span>
							<span class="alt" style="width:' . esc_attr($width2) . '%">&nbsp;</span>
						</td></tr>';
                }
                $report_html = '
					<h4>' . __("Sales and Earnings", $WCMp->text_domain) . '</h4>
					<div class="bar_indecator">
						<div class="bar1">&nbsp;</div>
						<span class="">' . __("Gross Sales", $WCMp->text_domain) . '</span>
						<div class="bar2">&nbsp;</div>
						<span class="">' . __("My Earnings", $WCMp->text_domain) . '</span>
					</div>
					<table class="bar_chart">
						<thead>
							<tr>
								<th>' . __("Month", $WCMp->text_domain) . '</th>
								<th colspan="2">' . __("Sales Report", $WCMp->text_domain) . '</th>
							</tr>
						</thead>
						<tbody>
							' . $report_chart . '
						</tbody>
					</table>
				';
            } else {
                $report_html = '<tr><td colspan="3">' . __('No product was sold in the given period.', $WCMp->text_domain) . '</td></tr>';
            }
        } else {
            $report_html = '<tr><td colspan="3">' . __('Your store has no products.', $WCMp->text_domain) . '</td></tr>';
        }
        include $WCMp->plugin_path . '/classes/reports/views/html-wcmp-report-by-product.php';
    }
Esempio n. 11
0
<?php

global $WCMp;
$pages = get_option('wcmp_pages_settings_name');
$vendor = get_wcmp_vendor(get_current_user_id());
$notice_data = get_option('wcmp_notices_settings_name');
$notice_to_be_display = '';
if (!isset($selected_item)) {
    $selected_item = '';
}
if (!$vendor->image) {
    $vendor->image = $WCMp->plugin_url . 'assets/images/WP-stdavatar.png';
}
$wcmp_payment_settings_name = get_option('wcmp_payment_settings_name');
$_vendor_give_shipping = get_user_meta(get_current_user_id(), '_vendor_give_shipping', true);
$wcmp_capabilities_settings_name = get_option('wcmp_capabilities_settings_name');
$_vendor_submit_coupon = get_user_meta(get_current_user_id(), '_vendor_submit_coupon', true);
$policies_settings = get_option('wcmp_general_policies_settings_name');
$customer_support_details_settings = get_option('wcmp_general_customer_support_details_settings_name');
$is_policy_show_in_menu = 0;
$is_university_show_in_menu = 0;
if (isset($policies_settings['is_policy_on']) && isset($wcmp_capabilities_settings_name['policies_can_override_by_vendor']) || isset($customer_support_details_settings['is_customer_support_details']) && isset($wcmp_capabilities_settings_name['can_vendor_add_customer_support_details'])) {
    $is_policy_show_in_menu = 1;
}
$general_settings = get_option('wcmp_general_settings_name');
if (isset($general_settings['is_university_on'])) {
    $is_university_show_in_menu = 1;
}
?>
<div class="wcmp_side_menu">
	<div class="wcmp_top_logo_div"> <img src="<?php 
 function save_store_settings($user_id, $post)
 {
     global $WCMp;
     $vendor = get_wcmp_vendor($user_id);
     $fields = $WCMp->user->get_vendor_fields($user_id);
     foreach ($fields as $fieldkey => $value) {
         if (isset($post[$fieldkey])) {
             if ($fieldkey == "vendor_page_slug" && !empty($post[$fieldkey])) {
                 if ($vendor && !$vendor->update_page_slug(wc_clean($_POST[$fieldkey]))) {
                     echo _e('Slug already exists', $WCMp->text_domain);
                 } else {
                     update_user_meta($user_id, '_' . $fieldkey, wc_clean($post[$fieldkey]));
                 }
                 continue;
             }
             if ($fieldkey == 'vendor_description') {
                 update_user_meta($user_id, '_' . $fieldkey, $post[$fieldkey]);
             } else {
                 update_user_meta($user_id, '_' . $fieldkey, wc_clean($post[$fieldkey]));
             }
             if ($fieldkey == 'vendor_page_title') {
                 if (!$vendor->update_page_title(wc_clean($post[$fieldkey]))) {
                     echo _e('Shop Title Update Error', $WCMp->text_domain);
                 } else {
                     wp_update_user(array('ID' => $user_id, 'display_name' => $post[$fieldkey]));
                 }
             }
         } else {
             if (!isset($post['vendor_hide_description']) && $fieldkey == 'vendor_hide_description') {
                 delete_user_meta($user_id, '_vendor_hide_description');
             } else {
                 if (!isset($post['vendor_hide_email']) && $fieldkey == 'vendor_hide_email') {
                     delete_user_meta($user_id, '_vendor_hide_email');
                 } else {
                     if (!isset($post['vendor_hide_address']) && $fieldkey == 'vendor_hide_address') {
                         delete_user_meta($user_id, '_vendor_hide_address');
                     } else {
                         if (!isset($post['vendor_hide_phone']) && $fieldkey == 'vendor_hide_phone') {
                             delete_user_meta($user_id, '_vendor_hide_phone');
                         } else {
                             if (!isset($post['vendor_hide_message_to_buyers']) && $fieldkey == 'vendor_hide_message_to_buyers') {
                                 delete_user_meta($user_id, '_vendor_hide_message_to_buyers');
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 13
0
 /**
  * Filter product search with vendor specific
  *
  * @access public
  * @return void
  */
 function json_filter_report_products($products)
 {
     $current_userid = get_current_user_id();
     $filtered_product = array();
     if (is_user_wcmp_vendor($current_userid)) {
         $vendor = get_wcmp_vendor($current_userid);
         $vendor_products = $vendor->get_products();
         if (!empty($vendor_products)) {
             foreach ($vendor_products as $vendor_product) {
                 if (isset($products[$vendor_product->ID])) {
                     $filtered_product[$vendor_product->ID] = $products[$vendor_product->ID];
                 }
             }
         }
         $products = $filtered_product;
     }
     return $products;
 }
Esempio n. 14
0
    /**
     * Set output capability css
     */
    function output_capability_css()
    {
        global $post;
        $screen = get_current_screen();
        $custom_css = '';
        if (in_array($screen->id, array('product'))) {
            if (is_user_wcmp_vendor(get_current_user_id())) {
                if (!$this->vendor_can('taxes')) {
                    $custom_css .= '
					._tax_status_field, ._tax_class_field {
						display: none !important;
					}
					';
                }
                if (!$this->vendor_can('add_comment')) {
                    $custom_css .= '
					.comments-box {
						display: none !important;
					}
					';
                }
                if (!$this->vendor_can('comment_box')) {
                    $custom_css .= '
					#add-new-comment {
						display: none !important;
					}
					';
                }
                if ($this->vendor_can('stylesheet')) {
                    $custom_css .= $this->capability['stylesheet'];
                }
                $vendor_id = get_current_user_id();
                $vendor = get_wcmp_vendor($vendor_id);
                if ($vendor && $post->post_author != $vendor_id) {
                    $custom_css .= '.options_group.pricing.show_if_simple.show_if_external {
														display: none !important;
													}';
                }
                wp_add_inline_style('woocommerce_admin_styles', $custom_css);
            }
        }
    }
    /**
     * Output the Vendor Orders shortcode.
     *
     * @access public
     * @param array $atts
     * @return void
     */
    public static function output($attr)
    {
        global $woocommerce, $WCMp, $wpdb;
        $WCMp->nocache();
        if (!defined('MNDASHBAOARD')) {
            define('MNDASHBAOARD', true);
        }
        $frontend_script_path = $WCMp->plugin_url . 'assets/frontend/js/';
        $frontend_script_path = str_replace(array('http:', 'https:'), '', $frontend_script_path);
        $pluginURL = str_replace(array('http:', 'https:'), '', $WCMp->plugin_url);
        $suffix = defined('WCMP_SCRIPT_DEBUG') && WCMP_SCRIPT_DEBUG ? '' : '.min';
        wp_enqueue_script('vendor_orders_js', $frontend_script_path . 'vendor_orders' . $suffix . '.js', array('jquery'), $WCMp->version, true);
        wp_localize_script('vendor_orders_js', 'wcmp_mark_shipped_text', array('text' => __('Order is marked as shipped.', $WCMp->text_domain), 'image' => $WCMp->plugin_url . 'assets/images/roket-green.png'));
        $user = wp_get_current_user();
        $vendor = get_wcmp_vendor($user->ID);
        if ($vendor) {
            if (!empty($_GET['wcmp_start_date_order'])) {
                $start_date = $_GET['wcmp_start_date_order'];
            } else {
                $start_date = date('01-m-Y');
            }
            // hard-coded '01' for first day
            if (!empty($_GET['wcmp_end_date_order'])) {
                $end_date = $_GET['wcmp_end_date_order'];
            } else {
                $end_date = date('t-m-Y');
            }
            // hard-coded '01' for first day
            $start_date = date('Y-m-d G:i:s', strtotime($start_date));
            $end_date = date('Y-m-d G:i:s', strtotime($end_date . ' +1 day'));
            $customer_orders = $wpdb->get_results("SELECT DISTINCT order_id from `{$wpdb->prefix}wcmp_vendor_orders` where commission_id > 0 AND vendor_id = '" . $vendor->id . "' AND (`created` >= '" . $start_date . "' AND `created` <= '" . $end_date . "') ORDER BY `created` ASC", ARRAY_A);
            $orders_array = array();
            if (!empty($customer_orders)) {
                foreach ($customer_orders as $order_obj) {
                    if (isset($order_obj['order_id'])) {
                        if (get_post_status($order_obj['order_id']) == 'wc-completed') {
                            $orders_array['completed'][] = $order_obj['order_id'];
                        } else {
                            if (get_post_status($order_obj['order_id']) == 'wc-processing') {
                                $orders_array['processing'][] = $order_obj['order_id'];
                            }
                        }
                        $orders_array['all'][] = $order_obj['order_id'];
                    }
                }
            }
            if (!isset($orders_array['all'])) {
                $orders_array['all'] = array();
            }
            if (!isset($orders_array['processing'])) {
                $orders_array['processing'] = array();
            }
            if (!isset($orders_array['completed'])) {
                $orders_array['completed'] = array();
            }
            ?>
			<div class="wcmp_remove_div">
				<div class="wcmp_main_page"> 
					<?php 
            $WCMp->template->get_template('vendor_dashboard_menu.php', array('selected_item' => 'orders'));
            $WCMp->template->get_template('shortcode/vendor_orders.php', array('vendor' => $vendor, 'customer_orders' => $orders_array));
            wp_localize_script('vendor_orders_js', 'wcmp_vendor_all_orders_array', $orders_array['all']);
            wp_localize_script('vendor_orders_js', 'wcmp_vendor_processing_orders_array', $orders_array['processing']);
            wp_localize_script('vendor_orders_js', 'wcmp_vendor_completed_orders_array', $orders_array['completed']);
            ?>
 
				</div>
			</div>
			<?php 
        }
    }
    /**
     * Output the report
     */
    public function output_report()
    {
        global $wpdb, $woocommerce, $WCMp;
        $vendor = $vendor_id = $order_items = false;
        $ranges = array('year' => __('Year', $WCMp->text_domain), 'last_month' => __('Last Month', $WCMp->text_domain), 'month' => __('This Month', $WCMp->text_domain), '7day' => __('Last 7 Days', $WCMp->text_domain));
        $current_range = !empty($_GET['range']) ? sanitize_text_field($_GET['range']) : '7day';
        if (!in_array($current_range, array('custom', 'year', 'last_month', 'month', '7day'))) {
            $current_range = '7day';
        }
        $this->calculate_current_range($current_range);
        if (isset($_POST['vendor'])) {
            $vendor_id = $_POST['vendor'];
            $vendor = get_wcmp_vendor_by_term($vendor_id);
            if ($vendor) {
                $products = $vendor->get_products();
            }
            if (!empty($products)) {
                foreach ($products as $product) {
                    $chosen_product_ids[] = $product->ID;
                }
            }
        }
        if ($vendor_id && $vendor) {
            $option = '<option value="' . $vendor_id . '" selected="selected">' . $vendor->user_data->display_name . '</option>';
        } else {
            $option = '<option></option>';
        }
        $all_vendors = get_wcmp_vendors();
        $start_date_str = $this->start_date;
        $end_date_str = $this->end_date;
        $end_date_str = strtotime('+1 day', $end_date_str);
        $start_date = date("Y-m-d H:i:s", $start_date_str);
        $end_date = date("Y-m-d H:i:s", $end_date_str);
        $total_sales = $admin_earning = $vendor_report = $report_bk = array();
        $max_total_sales = $i = 0;
        if (isset($all_vendors) && !empty($all_vendors)) {
            foreach ($all_vendors as $all_vendor) {
                $chosen_product_ids = array();
                $vendor_id = $all_vendor->id;
                $vendor = get_wcmp_vendor($vendor_id);
                if ($vendor) {
                    $products = $vendor->get_products();
                }
                if (!empty($products)) {
                    foreach ($products as $product) {
                        $chosen_product_ids[] = $product->ID;
                    }
                }
                if ($chosen_product_ids && is_array($chosen_product_ids)) {
                    // Get titles and ID's related to product
                    $chosen_product_titles = array();
                    $children_ids = array();
                    foreach ($chosen_product_ids as $product_id) {
                        $children = (array) get_posts('post_parent=' . $product_id . '&fields=ids&post_status=any&numberposts=-1');
                        $children_ids = $children_ids + $children;
                        $chosen_product_titles[] = get_the_title($product_id);
                    }
                    // Get order items
                    $order_items = apply_filters('woocommerce_reports_product_sales_order_items', $wpdb->get_results("\n\t\t\t\t\t\tSELECT posts.ID as order_id, order_item_meta_2.meta_value as product_id, order_item_meta_1.meta_value as variation_id, posts.post_date, SUM( order_item_meta.meta_value ) as item_quantity, SUM( order_item_meta_3.meta_value ) as line_total\n\t\t\t\t\t\tFROM {$wpdb->prefix}woocommerce_order_items as order_items\n\t\t\t\n\t\t\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_1 ON order_items.order_item_id = order_item_meta_1.order_item_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta_3 ON order_items.order_item_id = order_item_meta_3.order_item_id\n\t\t\t\t\t\tLEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID\n\t\t\t\n\t\t\t\t\t\tWHERE posts.post_type \t= 'shop_order'\n\t\t\t\t\t\tAND \torder_item_meta_2.meta_value IN ('" . implode("','", array_merge($chosen_product_ids, $children_ids)) . "')\n\t\t\t\t\t\tAND posts.post_status IN ('wc-pending','wc-processing','wc-on-hold','wc-completed','wc-cancelled','wc-refunded','wc-failed')\n\t\t\t\t\t\tAND \torder_items.order_item_type = 'line_item'\n\t\t\t\t\t\tAND \torder_item_meta.meta_key = '_qty'\n\t\t\t\t\t\tAND \torder_item_meta_2.meta_key = '_product_id'\n\t\t\t\t\t\tAND \torder_item_meta_1.meta_key = '_variation_id'\n\t\t\t\t\t\tAND \torder_item_meta_3.meta_key = '_line_total'\n\t\t\t\t\t\tAND   posts.post_date BETWEEN '" . $start_date . "' AND '" . $end_date . "'\n\t\t\t\t\t\tGROUP BY order_items.order_id\n\t\t\t\t\t\tORDER BY posts.post_date ASC\n\t\t\t\t\t"), array_merge($chosen_product_ids, $children_ids));
                    if ($order_items) {
                        foreach ($order_items as $order_item) {
                            if ($order_item->line_total == 0 && $order_item->item_quantity == 0) {
                                continue;
                            }
                            if ($order_item->variation_id != '0') {
                                $product_id = $order_item->variation_id;
                                $variation_id = $order_item->variation_id;
                            } else {
                                $product_id = $order_item->product_id;
                                $variation_id = 0;
                            }
                            $commissions = false;
                            $vendor_earnings = 0;
                            $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($vendor->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order_item->order_id), 'compare' => '='), array('key' => '_commission_product', 'value' => absint($product_id), 'compare' => 'LIKE')));
                            $commissions = get_posts($args);
                            if (!empty($commissions)) {
                                foreach ($commissions as $commission) {
                                    $vendor_earnings = $vendor_earnings + get_post_meta($commission->ID, '_commission_amount', true);
                                }
                            }
                            if ($vendor_earnings <= 0) {
                                continue;
                            }
                            $total_sales[$vendor_id] = isset($total_sales[$vendor_id]) ? $total_sales[$vendor_id] + $order_item->line_total : $order_item->line_total;
                            $admin_earning[$vendor_id] = isset($admin_earning[$vendor_id]) ? $admin_earning[$vendor_id] + $order_item->line_total - $vendor_earnings : $order_item->line_total - $vendor_earnings;
                            if ($total_sales[$vendor_id] > $max_total_sales) {
                                $max_total_sales = $total_sales[$vendor_id];
                            }
                        }
                    }
                }
                if (isset($total_sales[$vendor_id]) && isset($admin_earning[$vendor_id])) {
                    $vendor_report[$i]['vendor_id'] = $vendor_id;
                    $vendor_report[$i]['total_sales'] = $total_sales[$vendor_id];
                    $vendor_report[$i++]['admin_earning'] = $admin_earning[$vendor_id];
                    $report_bk[$vendor_id]['total_sales'] = $total_sales[$vendor_id];
                    $report_bk[$vendor_id]['admin_earning'] = $admin_earning[$vendor_id];
                }
            }
            $i = 0;
            $max_value = 10;
            $report_sort_arr = array();
            if (isset($vendor_report) && isset($report_bk)) {
                $total_sales_sort = wp_list_pluck($vendor_report, 'total_sales', 'vendor_id');
                $admin_earning_sort = wp_list_pluck($vendor_report, 'admin_earning', 'vendor_id');
                foreach ($total_sales_sort as $key => $value) {
                    $total_sales_sort_arr[$key]['total_sales'] = $report_bk[$key]['total_sales'];
                    $total_sales_sort_arr[$key]['admin_earning'] = $report_bk[$key]['admin_earning'];
                }
                arsort($total_sales_sort);
                foreach ($total_sales_sort as $key => $value) {
                    if ($i++ < $max_value) {
                        $report_sort_arr[$key]['total_sales'] = $report_bk[$key]['total_sales'];
                        $report_sort_arr[$key]['admin_earning'] = $report_bk[$key]['admin_earning'];
                    }
                }
            }
            wp_localize_script('wcmp_report_js', 'wcmp_report_vendor', array('vendor_report' => $vendor_report, 'report_bk' => $report_bk, 'total_sales_sort' => $total_sales_sort, 'admin_earning_sort' => $admin_earning_sort, 'max_total_sales' => $max_total_sales, 'start_date' => $start_date, 'end_date' => $end_date));
            $chart_arr = $html_chart = '';
            if (count($report_sort_arr) > 0) {
                foreach ($report_sort_arr as $vendor_id => $sales_report) {
                    $total_sales_width = $sales_report['total_sales'] > 0 ? $sales_report['total_sales'] / round($max_total_sales) * 100 : 0;
                    $admin_earning_width = $sales_report['admin_earning'] > 0 ? $sales_report['admin_earning'] / round($max_total_sales) * 100 : 0;
                    $user = get_userdata($vendor_id);
                    $user_name = $user->data->display_name;
                    $chart_arr .= '<tr><th><a href="user-edit.php?user_id=' . $vendor_id . '">' . $user_name . '</a></th>
					<td width="1%"><span>' . woocommerce_price($sales_report['total_sales']) . '</span><span class="alt">' . woocommerce_price($sales_report['admin_earning']) . '</span></td>
					<td class="bars">
						<span style="width:' . esc_attr($total_sales_width) . '%">&nbsp;</span>
						<span class="alt" style="width:' . esc_attr($admin_earning_width) . '%">&nbsp;</span>
					</td></tr>';
                }
                $html_chart = '
					<h4>' . __("Sales and Earnings", $WCMp->text_domain) . '</h4>
					<div class="bar_indecator">
						<div class="bar1">&nbsp;</div>
						<span class="">' . __('Gross Sales', $WCMp->text_domain) . '</span>
						<div class="bar2">&nbsp;</div>
						<span class="">' . __('My Earnings', $WCMp->text_domain) . '</span>
					</div>
					<table class="bar_chart">
						<thead>
							<tr>
								<th>' . __("Vendors", $WCMp->text_domain) . '</th>
								<th colspan="2">' . __("Sales Report", $WCMp->text_domain) . '</th>
							</tr>
						</thead>
						<tbody>
							' . $chart_arr . '
						</tbody>
					</table>
				';
            } else {
                $html_chart = '<tr><td colspan="3">' . __('Any vendor did not generate any sales in the given period.', $WCMp->text_domain) . '</td></tr>';
            }
        } else {
            $html_chart = '<tr><td colspan="3">' . __('Your store has no vendors.', $WCMp->text_domain) . '</td></tr>';
        }
        include $WCMp->plugin_path . '/classes/reports/views/html-wcmp-report-by-vendor.php';
    }
Esempio n. 17
0
/**
 * The template for displaying vendor dashboard
 *
 * Override this template by copying it to yourtheme/dc-product-vendor/shortcode/vendor_shipping.php
 *
 * @author 		dualcube
 * @package 	WCMp/Templates
 * @version   2.2.0
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $woocommerce, $WCMp;
$vendor_user_id = get_current_user_id();
$vendor_data = get_wcmp_vendor($vendor_user_id);
if ($vendor_data) {
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        if (isset($_POST['vendor_shipping_data'])) {
            $fee = 0;
            $vendor_shipping_data = get_user_meta($vendor_user_id, 'vendor_shipping_data', true);
            $cost = $_POST['vendor_shipping_data']['shipping_amount'];
            $international_cost = $_POST['vendor_shipping_data']['international_shipping_amount'];
            $fee = isset($_POST['vendor_shipping_data']['handling_amount']) ? $_POST['vendor_shipping_data']['handling_amount'] : '';
            if (isset($_POST['vendor_shipping_data']['shipping_amount'])) {
                $shipping_updt = true;
                $dc_flat_rates = array();
                $shipping_class_id = get_user_meta($vendor_user_id, 'shipping_class_id', true);
                if (!empty($shipping_class_id)) {
                    $term_shipping_obj = get_term_by('id', $shipping_class_id, 'product_shipping_class');
                }
 /**
  * Register new columns for commissions list table
  * @param  str $column_name Name of column
  * @param  int $id          ID of commission
  * @return void
  */
 public function wcmp_register_custom_columns($column_name, $id)
 {
     $data = get_post_meta($id, $column_name, true);
     switch ($column_name) {
         case '_commission_product':
             if (is_array($data)) {
                 foreach ($data as $dat) {
                     if (function_exists('get_product')) {
                         $product = get_product($dat);
                     } else {
                         $product = new WC_Product($dat);
                     }
                     if (is_object($product) && $product->get_formatted_name()) {
                         echo ' &nbsp;[&nbsp;<a href="' . esc_url(get_edit_post_link($product->id)) . '">' . $product->get_formatted_name() . '</a>&nbsp;]&nbsp;';
                     }
                 }
             } else {
                 // support for previous versions
                 if ($data && strlen($data) > 0) {
                     if (function_exists('get_product')) {
                         $product = get_product($data);
                     } else {
                         $product = new WC_Product($data);
                     }
                     if (is_object($product) && $product->get_formatted_name()) {
                         echo ' <a href="' . esc_url(get_edit_post_link($product->id)) . '">' . $product->get_formatted_name() . '</a>';
                     }
                 }
             }
             break;
         case '_commission_order_id':
             if ($data && strlen($data) > 0) {
                 $edit_url = 'post.php?post=' . $data . '&action=edit';
                 echo '<a href="' . esc_url($edit_url) . '">#' . $data . '</a>';
             }
             break;
         case '_commission_vendor':
             if ($data && strlen($data) > 0) {
                 $vendor_user_id = get_woocommerce_term_meta($data, '_vendor_user_id', true);
                 if ($vendor_user_id) {
                     $vendor = get_wcmp_vendor($vendor_user_id);
                     $edit_url = get_edit_user_link($vendor_user_id);
                     echo '<a href="' . esc_url($edit_url) . '">' . $vendor->user_data->user_login . '</a>';
                 }
             }
             break;
         case '_commission_amount':
             echo get_woocommerce_currency_symbol() . number_format($data, 2);
             break;
         case '_paid_status':
             echo ucfirst($data);
             break;
         default:
             break;
     }
 }
 /**
  *  Get current vendor orders
  *
  * @return array
  */
 function wcmp_get_vendor_orders()
 {
     global $WCMp;
     $user_id = get_current_user_id();
     $vendor = get_wcmp_vendor($user_id);
     $orders = array();
     $vendor_orders_array = $vendor->get_orders();
     if (!$vendor_orders_array) {
         $vendor_orders_array = array();
     }
     $_orders = array_unique($vendor_orders_array);
     if (!empty($_orders)) {
         foreach ($_orders as $order_id) {
             $order = new WC_Order($order_id);
             $valid_items = $vendor->get_vendor_items_from_order($order->id, $vendor->term_id);
             $products = '';
             foreach ($valid_items as $key => $item) {
                 $item_meta = new WC_Order_Item_Meta($item['item_meta']);
                 // $item_meta = $item_meta->display( false, true );
                 $item_meta = $item_meta->get_formatted();
                 $products .= '<strong>' . $item['qty'] . ' x ' . $item['name'] . '</strong><br />';
                 foreach ($item_meta as $key => $meta) {
                     // Remove the sold by meta key for display
                     if (strtolower($key) != 'sold by') {
                         if ($meta['label'] == 'flat_shipping_per_item') {
                             $products .= __('Flat Shipping Charges', $WCMp->text_domain) . ' : ' . $meta['value'] . '<br />';
                         } else {
                             $products .= $meta['label'] . ' : ' . $meta['value'] . '<br />';
                         }
                     }
                 }
             }
             $shippers = (array) get_post_meta($order->id, 'dc_pv_shipped', true);
             $shipped = in_array($user_id, $shippers) ? 'Yes' : 'No';
             if ($order->id && $vendor->term_id) {
                 $commission_total = 0;
                 $commissions = false;
                 $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($vendor->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order->id), 'compare' => '=')));
                 $commissions = get_posts($args);
                 if (!empty($commissions)) {
                     foreach ($commissions as $commission) {
                         $commission_total = $commission_total + (double) get_post_meta($commission->ID, '_commission_amount', true) + (double) get_post_meta($commission->ID, '_shipping', true) + (double) get_post_meta($commission->ID, '_tax', true);
                     }
                 }
             }
             $extra_checkout_fields_for_brazil_active_datas = '';
             if (WC_Dependencies_Product_Vendor::woocommerce_extra_checkout_fields_for_brazil_active_check()) {
                 $settings = get_option('wcbcf_settings');
                 if (0 != $settings['person_type']) {
                     // Person type information.
                     if (1 == $order->billing_persontype && 1 == $settings['person_type'] || 2 == $settings['person_type']) {
                         $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('CPF', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_cpf) . '<br />';
                         if (isset($settings['rg'])) {
                             $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('RG', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_rg) . '<br />';
                         }
                     }
                     if (2 == $order->billing_persontype && 1 == $settings['person_type'] || 3 == $settings['person_type']) {
                         $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Company Name', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_company) . '<br />';
                         $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('CNPJ', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_cnpj) . '<br />';
                         if (isset($settings['ie'])) {
                             $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('State Registration', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_ie) . '<br />';
                         }
                     }
                 } else {
                     $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Company', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_company) . '<br />';
                 }
                 if (isset($settings['birthdate_sex'])) {
                     // Birthdate information.
                     $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Birthdate', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_birthdate) . '<br />';
                     // Sex Information.
                     $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Sex', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_sex) . '<br />';
                 }
                 $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Phone', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_phone) . '<br />';
                 // Cell Phone Information.
                 if (!empty($order->billing_cellphone)) {
                     $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Cell Phone', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_cellphone) . '<br />';
                 }
             }
             $customer_user_name = get_post_meta($order->id, '_shipping_first_name', true) . ' ' . get_post_meta($order->id, '_shipping_last_name', true);
             $order_items = array();
             $order_items['order_id'] = $order->id;
             $order_items['customer'] = $customer_user_name . '<br>' . apply_filters('wcmp_dashboard_google_maps_link', '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode(esc_html(preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address()))) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address())) . '</a><br />' . $extra_checkout_fields_for_brazil_active_datas);
             $order_items['products'] = $products;
             $order_items['total'] = woocommerce_price($commission_total);
             $order_items['date'] = date_i18n(wc_date_format(), strtotime($order->order_date));
             $order_items['status'] = $shipped;
             $orders[] = (object) $order_items;
         }
     }
     return $orders;
 }
Esempio n. 20
0
 /**
  * Delete vendor data on user delete
  * function delete_vendor
  * @access private
  * @param int $user_id
  * @return void
  */
 function delete_vendor($user_id)
 {
     global $WCMp;
     if (is_user_wcmp_vendor($user_id)) {
         $vendor = get_wcmp_vendor($user_id);
         do_action('delete_dc_vendor', $vendor);
         if (isset($_POST['reassign_user']) && !empty($_POST['reassign_user']) && $_POST['delete_option'] == 'reassign') {
             if (is_user_wcmp_vendor(absint($_POST['reassign_user']))) {
                 if ($products = $vendor->get_products(array('fields' => 'ids'))) {
                     foreach ($products as $product_id) {
                         $new_vendor = get_wcmp_vendor(absint($_POST['reassign_user']));
                         wp_set_object_terms($product_id, absint($new_vendor->term_id), $WCMp->taxonomy->taxonomy_name);
                     }
                 }
             } else {
                 wp_die(__('Select a Vendor.', $WCMp->text_domain));
             }
         }
         wp_delete_term($vendor->term_id, $WCMp->taxonomy->taxonomy_name);
     }
 }
Esempio n. 21
0
 *
 * @author 		dualcube
 * @package 	WCMp/Templates
 * @version   2.2.0
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $woocommerce, $WCMp;
$pages = get_option('wcmp_pages_settings_name');
$vendor_detail_page = $pages['vendor_order_detail'];
if (!empty($orders)) {
    foreach ($orders as $order) {
        $order_obj = new WC_Order($order);
        $mark_ship = $WCMp->vendor_dashboard->is_order_shipped($order, get_wcmp_vendor(get_current_user_id()));
        $user_id = get_current_user_id();
        ?>
		<tr>
			<td align="center"  width="20" ><span class="input-group-addon beautiful">
				<input type="checkbox" class="select_<?php 
        echo $order_status;
        ?>
" name="select_<?php 
        echo $order_status;
        ?>
[<?php 
        echo $order;
        ?>
]" >
				</span></td>
Esempio n. 22
0
 /**
  * Get vendors for product
  * @param  int $product_id Product ID
  * @return arr             Array of product vendors
  */
 function get_wcmp_product_vendors($product_id = 0)
 {
     global $WCMp;
     $vendor_data = false;
     if ($product_id > 0) {
         $vendors_data = wp_get_post_terms($product_id, $WCMp->taxonomy->taxonomy_name);
         foreach ($vendors_data as $vendor) {
             $vendor_obj = get_wcmp_vendor_by_term($vendor->term_id);
             if ($vendor_obj) {
                 $vendor_data = $vendor_obj;
             }
         }
         if (!$vendor_data) {
             $product_obj = get_post($product_id);
             $author_id = $product_obj->post_author;
             if ($author_id) {
                 $vendor_data = get_wcmp_vendor($author_id);
             }
         }
     }
     return $vendor_data;
 }
 /**
  * Get all data needed for this report and store in the class
  */
 private function query_report_data()
 {
     $this->report_data = new stdClass();
     $start_date = $this->start_date;
     $end_date = $this->end_date;
     $chart_data_order_count = array();
     $total_order_count = 0;
     $total_earnings = 0;
     $total_sales = 0;
     $total_avg_sales = 0;
     $total_vendor_earnings = 0;
     for ($date = $start_date; $date <= strtotime('+1 day', $end_date); $date = strtotime('+1 day', $date)) {
         $year = date('Y', $date);
         $month = date('n', $date);
         $day = date('j', $date);
         $line_total = $sales = $comm_amount = $vendor_earnings = $earnings = $order_count = 0;
         $args = array('post_type' => 'shop_order', 'posts_per_page' => -1, 'post_status' => array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-cancelled', 'wc-refunded', 'wc-failed'), 'meta_query' => array(array('key' => '_commissions_processed', 'value' => 'yes', 'compare' => '=')), 'date_query' => array(array('year' => $year, 'month' => $month, 'day' => $day)));
         $qry = new WP_Query($args);
         $orders = apply_filters('wcmp_filter_orders_report_overview', $qry->get_posts());
         if (!empty($orders)) {
             foreach ($orders as $order_obj) {
                 $order = new WC_Order($order_obj->ID);
                 $items = $order->get_items('line_item');
                 $commission_array = array();
                 foreach ($items as $item_id => $item) {
                     $comm_pro_id = $product_id = $order->get_item_meta($item_id, '_product_id', true);
                     $line_total = $order->get_item_meta($item_id, '_line_total', true);
                     $variation_id = $order->get_item_meta($item_id, '_variation_id', true);
                     if ($variation_id) {
                         $comm_pro_id = $variation_id;
                     }
                     if ($product_id && $line_total) {
                         $vendor_id = $order->get_item_meta($item_id, '_vendor_id', true);
                         if ($vendor_id) {
                             $product_vendors = get_wcmp_vendor($vendor_id);
                         } else {
                             $product_vendors = get_wcmp_product_vendors($product_id);
                         }
                         if ($product_vendors) {
                             $sales += $line_total;
                             $total_sales += $line_total;
                             $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($product_vendors->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order_obj->ID), 'compare' => '='), array('key' => '_commission_product', 'value' => absint($comm_pro_id), 'compare' => 'LIKE')));
                             $commissions = get_posts($args);
                             $comm_amount = 0;
                             if (!empty($commissions)) {
                                 foreach ($commissions as $commission) {
                                     if (in_array($commission->ID, $commission_array)) {
                                         continue;
                                     }
                                     $comm_amount += (double) get_post_meta($commission->ID, '_commission_amount', true);
                                     $commission_array[] = $commission->ID;
                                 }
                             }
                             $vendor_earnings += $comm_amount;
                             $total_vendor_earnings += $comm_amount;
                             $earnings += $line_total - $comm_amount;
                             $total_earnings += $line_total - $comm_amount;
                         }
                     }
                 }
                 ++$order_count;
                 ++$total_order_count;
             }
         }
         if ($order_count > 0) {
             $avg_sales = $sales / $order_count;
         } else {
             $avg_sales = 0;
         }
         $chart_data_order_count[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'count' => $order_count));
         $chart_data_sales[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'sales' => $sales));
         $chart_data_vendor_earnings[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'vendor_earnings' => $vendor_earnings));
         $chart_data_earnings[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'earnings' => $earnings));
         $chart_data_avg_sales[] = wcmpArrayToObject(array('post_date' => date("Y-m-d H:i:s", $date), 'avg_sales' => $avg_sales));
     }
     $this->report_data->order_count = $chart_data_order_count;
     $this->report_data->sales = $chart_data_sales;
     $this->report_data->vendor_earnings = $chart_data_vendor_earnings;
     $this->report_data->earnings = $chart_data_earnings;
     $this->report_data->avg_sales = $chart_data_avg_sales;
     if ($total_order_count > 0) {
         $total_avg_sales = $total_sales / $total_order_count;
     } else {
         $total_avg_sales = 0;
     }
     // Total order_count
     $this->report_data->total_orders = $total_order_count;
     // Total the refunds and sales amounts. Sales subract refunds.
     $this->report_data->total_sales = wc_format_decimal($total_sales);
     // Calculate average based on net
     $this->report_data->average_sales = wc_format_decimal($total_avg_sales);
     $this->report_data->total_earned = wc_format_decimal($total_earnings);
     $this->report_data->vendor_total_earned = wc_format_decimal($total_vendor_earnings);
 }
Esempio n. 24
0
/**
 * The template for displaying vendor order detail and called from vendor_order_item.php template
 *
 * Override this template by copying it to yourtheme/dc-product-vendor/shortcode/vendor_order_detail.php
 *
 * @author 		dualcube
 * @package 	WCMp/Templates
 * @version   2.2.0
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
global $woocommerce, $WCMp;
$user = wp_get_current_user();
$vendor = get_wcmp_vendor($user->ID);
$order_id = $_GET['order_id'];
if ($vendor && $order_id) {
    $vendor_items = $vendor->get_vendor_items_from_order($order_id, $vendor->term_id);
    $order = new WC_Order($order_id);
    if ($order) {
        ?>
		<h2><?php 
        _e('Order Details', $WCMp->text_domain);
        ?>
</h2>
			<table class="customer_order_dtl"> 
				<tbody>
					<th><label for="product_name"><?php 
        _e('Product Title', $WCMp->text_domain);
        ?>
 /**
  * Send the quick info form mail
  *
  * @since 1.0
  * @return void
  * @author dualcube
  */
 function send_mail()
 {
     if ($this->check_form()) {
         /* === Sanitize Form Value === */
         $vendor = get_wcmp_vendor($_POST['quick_info']['vendor_id']);
         $to = sanitize_email($vendor->user_data->user_email);
         $subject = sanitize_text_field($_POST['quick_info']['subject']);
         $message = sanitize_text_field($_POST['quick_info']['message']);
         $from = sanitize_text_field($_POST['quick_info']['name']);
         $from_email = sanitize_email($_POST['quick_info']['email']);
         $admin_email = get_option('admin_email');
         $headers[] = "From: {$from} <{$from_email}>";
         $headers[] = "Cc: Admin <{$admin_email}>";
         /* === Send Mail === */
         $check = wp_mail($to, $subject, $message, $headers);
         /* === Prevent resubmit form === */
         unset($_POST);
         $redirect = esc_url(add_query_arg(array('message' => $check ? 1 : 0), $vendor->permalink));
         wp_redirect($redirect);
         exit;
     }
 }