/** * getOrderSum function * this funciton is to get total sum or the total quantities of all the orders and also by differenciating by user or confirmed orders. * * @todo by providing order id, get the total sums. * @param int id, product id not implemented, always null * @param sting qty, get the toal quantities of orders by providing qty = 'qty' string. * @param bool confirmed, TRUE or FALSE * @return int * @author Ankit Balyan - sf.ankit@gmail.com **/ function getOrderSum($id = NULL, $qty = NULL, $confirmed = FALSE, $user_id = NULL) { $confirmed = $confirmed ? " and orders.order_confirm_ind = {$confirmed} " : ' '; global $wpdb; if (isBrandUser()) { $user_id = isLogin(); if ($qty != 'qty') { $sql = "SELECT SUM(orders.total_price) as dist_total_price \n\t\t\t\tFROM \n\t\t\t\t\trw_orders AS orders \n\t\t\t\tLEFT OUTER JOIN \n\t\t\t\t\trw_products AS product on orders.product_id = product.product_id\n\t\t\t\tLEFT OUTER JOIN\n \trw_brand_user_map AS user_brand ON user_brand.user_id = {$user_id}\n LEFT OUTER JOIN\n \trw_brands AS brand ON brand.brand_id = user_brand.brand_id\n OR brand.brand_parent_id = user_brand.brand_id\n\t where\n\t product.brand_id = brand.brand_id\n\t or\n\t product.brand_id = brand.brand_parent_id\n\t\t\t\t\t\t{$confirmed}"; } elseif ($qty == 'qty') { $sql = "SELECT SUM(orders.total_qty) as dist_total_qty \n\t\t\t\t\tFROM \n\t\t\t\t\t\trw_orders AS orders \n\t\t\t\t\tLEFT OUTER JOIN \n\t\t\t\t\t\trw_products AS product on orders.product_id = product.product_id\n\t\t\t\t LEFT OUTER JOIN\n \trw_brand_user_map AS user_brand ON user_brand.user_id = {$user_id}\n\t LEFT OUTER JOIN\n\t \trw_brands AS brand ON brand.brand_id = user_brand.brand_id\n\t OR brand.brand_parent_id = user_brand.brand_id\n\t\t where\n\t\t product.brand_id = brand.brand_id\n\t\t or\n\t\t product.brand_id = brand.brand_parent_id {$confirmed}"; } $wpdb->get_var($sql); $wpdb->last_query; return $wpdb->get_var($sql); } elseif (isArvindUser()) { if ($qty != 'qty') { $sql = "SELECT SUM(orders.total_price) as dist_total_price \n\t\t\t\tFROM \n\t\t\t\t\trw_orders AS orders \n\t\t\t \twhere 1 {$confirmed}"; } elseif ($qty == 'qty') { $sql = "SELECT SUM(orders.total_qty) as dist_total_qty \n\t\t\t\t\tFROM \n\t\t\t\t\t\trw_orders AS orders \n\t\t\t\t \twhere 1 {$confirmed}"; } if ($user_id) { $sql .= " and orders.created_by = " . $user_id; } $wpdb->get_var($sql); $wpdb->last_query; return $wpdb->get_var($sql); } elseif (count(isDistributor($user_id)) && $user_id && $qty != 'qty') { $sql = "SELECT SUM(orders.total_price) as dist_total_price \n\t\t\t\tFROM \n\t\t\t\t\trw_orders AS orders \n\t\t\t\t\tLEFT OUTER JOIN rw_users as users\n\t\t\t \ton users.user_parent_id = {$user_id} \n\t\t\t \tor users.user_id = {$user_id}\n\t\t\t \twhere orders.created_by = users.user_id {$confirmed}"; } elseif (count(isDistributor($user_id)) && $user_id && $qty == 'qty') { $sql = "SELECT SUM(orders.total_qty) as dist_total_qty \n\t\t\t\tFROM \n\t\t\t\t\trw_orders AS orders \n\t\t\t\t\tLEFT OUTER JOIN rw_users as users\n\t\t\t \ton users.user_parent_id = {$user_id} \n\t\t\t \tor users.user_id = {$user_id}\n\t\t\t \twhere orders.created_by = users.user_id {$confirmed}"; } elseif ($id && $qty != 'qty') { $sql = "SELECT \n\t\t\t\t SUM(orders.total_price) AS user_total_price\n\t\t\t\tFROM\n\t\t\t\t rw_orders AS orders\n\t\t\t\t where orders.created_by = {$id} {$confirmed}"; } elseif ($id && $qty == 'qty') { $sql = "SELECT \n\t\t\t\t SUM(orders.total_qty) AS user_total_qty\n\t\t\t\tFROM\n\t\t\t\t rw_orders AS orders\n\t\t\t\t where orders.created_by = {$id} {$confirmed}"; } elseif (!$id && $qty == 'qty') { $sql = "SELECT \n\t\t\t\t SUM(orders.total_qty) AS user_total_qty\n\t\t\t\tFROM\n\t\t\t\t rw_orders AS orders\n\t\t\t\t where orders.created_by = " . isLogin() . " {$confirmed}"; } else { $sql = "SELECT \n\t\t\t\t SUM(orders.total_price) AS user_total_price\n\t\t\t\tFROM\n\t\t\t\t rw_orders AS orders\n\t\t\t\t where orders.created_by = " . isLogin() . " {$confirmed}"; } $wpdb->get_var($sql); // /echo $wpdb->last_query; return $wpdb->get_var($sql); }
?> <div class="col-xs-12 col-sm-7 col-md-5"> <div class="shop-menu pull-right"> <ul class="nav navbar-nav navbar-fixed"> <li><a href=""><i class="fa fa-user"></i> <?php echo "Hi! " . getRwUsers(isLogin())->user_fullname; ?> </a></li> <li><a href="<?php echo site_url('my-orders'); ?> "><i class="fa fa-shopping-cart"></i> My Orders</a></li> <!-- <li><a href="#"><i class="fa fa-star"></i> Wishlist</a></li> <li><a href="checkout.html"><i class="fa fa-crosshairs"></i> Checkout</a></li> --> <?php if (!isArvindUser() && !isBrandUser()) { ?> <li><a href="<?php echo site_url('review'); ?> "><i class="fa fa-eye"></i> Review </a></li> <?php } ?> <li><a href="javascript:void(0)" class="logout" onclick="logout();"><i class="fa fa-lock"></i> Logout</a></li> </ul> </div> </div> <?php } ?>
$allpieces = getOrderSum(null, 'qty', TRUE, isLogin()); ?> <div class="finalTotal">All Total: <span class ="pull-right"> Rs <?php echo $alltotal ? $alltotal : '0'; ?> </span><span class ="pull-right"> <?php echo $allpieces ? $allpieces . " pcs, " : '0' . " pcs, "; ?> </span></div> <?php } ?> </div> <?php } elseif ($user = isBrandUser() || isArvindUser()) { ?> <div id="review_order_tab3"> <?php $count = 0; ?> <?php $ordered_ids = getOrederedIdByBrand(null, null, TRUE); ?> <?php if (count($ordered_ids)) { ?> <?php $count++; ?> <?php