| Server IP : 13.126.101.145 / Your IP : 216.73.217.33 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ip-11-115-0-196 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.3.17 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/rentals_updated/wp-content/plugins/custom-dashboard/ |
Upload File : |
<?php
?>
<!-- Custom CSS -->
<link href="<?php echo plugins_url('/template/dist/css/style.css', __FILE__); ?>" rel="stylesheet" type="text/css">
<link href="<?php echo plugins_url('/template/vendors/bower_components/morris.js/morris.css', __FILE__); ?>" rel="stylesheet" type="text/css"/>
<!-- Data table CSS -->
<link href="<?php echo plugins_url('/template/vendors/bower_components/datatables/media/css/jquery.dataTables.min.css', __FILE__); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo plugins_url('/template/vendors/bower_components/jquery-toast-plugin/dist/jquery.toast.min.css', __FILE__); ?>" rel="stylesheet" type="text/css">
<!-- Custom CSS -->
<link href="<?php echo plugins_url('/template/dist/css/style.css', __FILE__); ?>" rel="stylesheet" type="text/css">
<!-- Preloader -->
<!-- <div class="preloader-it">
<div class="la-anim-1"></div>
</div> -->
<?php
global $wpdb;
$query = "
SELECT DATE_FORMAT(post_modified, '%d-%b-%Y %H:%i:%s') AS formatted_date
FROM $wpdb->posts
WHERE post_type = 'product'
ORDER BY post_date DESC
LIMIT 1
";
$updated_on = $wpdb->get_var($query);
// echo "Last added product modified at: $result";
?>
<!-- /Preloader -->
<div class="wrapper theme-4-active pimary-color-red">
<div class="title">
<h3 style="margin: 19px 0px -10px 5px;">Business Administrator Dashboard </h3>
</div>
<!-- Main Content -->
<div class="">
<div class="container-fluid pt-25">
<!-- Row -->
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
<div class="panel panel-default card-view pa-0">
<div class="panel-wrapper collapse in">
<div class="panel-body pa-0">
<div class="sm-data-box bg-red">
<div class="container-fluid">
<!-- Link to src downloads 05/07 -->
<a href="<?php echo get_site_url() ?>/wp-admin/admin.php?page=stdratecard-dashboard" target="_blank">
<div class="row">
<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-left">
<?php
global $wpdb;
$user = wp_get_current_user();
$user_roles = $user->roles;
$table_name = $wpdb->prefix . 'download_std_ratecard';
// Get the user's region location from user meta
$user_region = get_user_meta($user->ID, 'ba_region_location', true);
// Ensure that user_region is set and not empty
if ($user_region && (in_array('rue_manager', $user_roles) )) {
// Count download_std_ratecard where the region matches the user's region
$count_src = $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM $table_name WHERE region = %s",
$user_region
) );
} else {
// If the user does not have the required roles or region is not set, count all leads
$count_src = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" );
}
?>
<span class="txt-light block counter"><span class="counter-anim"><?php echo $count_src; ?></span></span>
<span class="weight-500 uppercase-font txt-light block font-13">Standard Quote</span>
</div>
<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-right">
<i class="fa fa-download txt-light data-right-rep-icon"></i>
</div>
</div>
</a>
<!-- end link to src downloads -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
<div class="panel panel-default card-view pa-0">
<div class="panel-wrapper collapse in">
<div class="panel-body pa-0">
<div class="sm-data-box bg-yellow">
<div class="container-fluid">
<!-- Link to RFQ 05/07 -->
<a href="<?php echo get_site_url() ?>/wp-admin/admin.php?page=rfq-dashboard" target="_blank">
<div class="row">
<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-left">
<?php
global $wpdb;
$user = wp_get_current_user();
$user_roles = $user->roles;
// Get the user's region location from user meta
$user_region = get_user_meta($user->ID, 'ba_region_location', true);
// Ensure that user_region is set and not empty
if ($user_region && (in_array('rue_manager', $user_roles) )) {
$table_name = $wpdb->prefix . 'request_quote';
// Count RFQs where the region matches the user's region
$count_rfq = $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM $table_name WHERE region = %s",
$user_region
) );
} else {
$table_name = $wpdb->prefix . 'request_quote'; // Ensure the table name is defined
// If the user does not have the required roles or region is not set, count all RFQs
$count_rfq = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" );
}
?>
<span class="txt-light block counter"><span class="counter-anim"><?php echo $count_rfq; ?></span></span>
<span class="weight-500 uppercase-font txt-light block">RFQ</span>
</div>
<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-right">
<i class="fa fa-file txt-light data-right-rep-icon"></i>
</div>
</div>
</a>
<!--/end of link to RFQ -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
<div class="panel panel-default card-view pa-0">
<div class="panel-wrapper collapse in">
<div class="panel-body pa-0">
<div class="sm-data-box bg-green">
<div class="container-fluid">
<!-- link to enquiry 05/07 -->
<a href="<?php echo get_site_url() ?>/wp-admin/admin.php?page=leads" target="_blank">
<div class="row">
<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-left">
<?php
global $wpdb;
$user = wp_get_current_user();
$user_roles = $user->roles;
// Get the user's region location from user meta
$user_region = get_user_meta($user->ID, 'ba_region_location', true);
// Ensure that user_region is set and not empty
if ($user_region && (in_array('rue_manager', $user_roles) )) {
$table_name = $wpdb->prefix . 'leads';
// Count leads where the region matches the user's region
$count_leads = $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM $table_name WHERE region = %s",
$user_region
) );
} else {
$table_name = $wpdb->prefix . 'leads'; // Ensure the table name is defined
// If the user does not have the required roles or region is not set, count all leads
$count_leads = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" );
}
?>
<span class="txt-light block counter"><span class="counter-anim"><?php echo $count_leads; ?></span></span>
<span class="weight-500 uppercase-font txt-light block">Enquiry Raised</span>
</div>
<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-right">
<i class="zmdi zmdi-male-female txt-light data-right-rep-icon"></i>
</div>
</div>
</a>
<!-- end of enquiry -->
</div>
</div>
</div>
</div>
</div>
</div>
<?php
global $wpdb;
$customer_count = "
SELECT COUNT(DISTINCT u.ID)
FROM {$wpdb->users} u
INNER JOIN {$wpdb->usermeta} um ON u.ID = um.user_id
INNER JOIN {$wpdb->postmeta} pm ON u.ID = pm.meta_value
INNER JOIN {$wpdb->posts} p ON pm.post_id = p.ID
WHERE um.meta_key = '{$wpdb->prefix}capabilities'
AND um.meta_value LIKE '%customer%'
AND pm.meta_key = '_customer_user'
AND p.post_type = 'shop_order'
$search_query
";
$active_customer_count = $wpdb->get_var($customer_count);
?>
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
<div class="panel panel-default card-view pa-0">
<div class="panel-wrapper collapse in">
<div class="panel-body pa-0">
<div class="sm-data-box bg-blue">
<div class="container-fluid">
<!-- link to users 05/07 -->
<a href="<?php echo get_site_url() ?>/wp-admin/users.php?page=active-users" target="_blank">
<div class="row">
<div class="col-xs-6 text-center pl-0 pr-0 data-wrap-left">
<span class="txt-light block counter">
<span class="counter-anim"><?php echo $active_customer_count; ?></span>
</span>
<span class="weight-500 uppercase-font txt-light block">Active Customers</span>
</div>
<div class="col-xs-6 text-center pl-0 pr-0 pt-25 data-wrap-right">
<i class="fa fa-users txt-light data-right-rep-icon"></i>
</div>
</div>
</a>
<!-- end link to users -->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /Row -->
<!-- Row -->
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
<div class="panel panel-default card-view">
<div class="panel-wrapper collapse in">
<div class="panel-body sm-data-box-1">
<!-- add query for FU and TU and fleet value within php tag -->
<?php
// for example
// global $wpdb;
// $contract_end_date = '2024-04-01';
// // Prepare the SQL query to count distinct customer_id
// $query = "
// SELECT COUNT(DISTINCT customer_id) AS distinct_customer_count
// FROM {$wpdb->prefix}archive_contract_data
// WHERE contract_end_date >= %s
// ";
// // Execute the query using wpdb's prepare method to prevent SQL injection
// $distinct_customer_count = $wpdb->get_var( $wpdb->prepare( $query, $contract_end_date ) );
$Tu = "TU%";
$Fu = "FU%";
$fiv = "Report";
?>
<span style="font-weight:500; font-size:28px; text-align:center" class=" block text-center txt-dark">Fleet Performance</span>
<div class="cus-sat-stat weight-500 txt-success text-center mt-5">
<!-- <span class="counter-anim">30</span><span>%</span> -->
<span style="font-weight:500; font-size:28px; text-align:center" class=" block text-center txt-dark"><?php echo $fiv ?></span>
</div>
<div class="progress-anim mt-20">
<div class="progress">
<div class="progress-bar progress-bar-success wow animated progress-animated" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<ul class="flex-stat mt-5" style="margin-left: -114px;">
<li>
<span class="block"></span>
<span class="block" style="font-size: 18px; font-weight: bold;"><?php echo $Tu?>
<a href="<?php echo admin_url('admin.php?page=rfm-time-utilization'); ?>" target="_blank"><span class="dashicons dashicons-arrow-right-alt" style="float:right;color:green;"></span></a></span>
</li>
<li>
<span class="block"></span>
<span class="block" style="font-size: 18px; font-weight: bold;"><?php echo $Fu?>
<a href="<?php echo admin_url('admin.php?page=rfm-financial-utilization'); ?>" target="_blank"><span class="dashicons dashicons-arrow-right-alt" style="float:right;color:green;"></span></a></span>
</li>
</ul>
</div>
</div>
</div>
<div class="panel panel-default card-view">
<div class="panel-heading">
<!-- <div class="pull-left"> -->
<span>
<h6 style="text-align:center; font-weight:500; font-size:28px;" class="panel-title txt-dark">Registered Operators</h6>
<a href="<?php echo admin_url('admin.php?page=operator-dashboard'); ?>" target="_blank"><span class="dashicons dashicons-arrow-right-alt" style="float:right;color:green;"></span></a>
</span>
<div class="clearfix"></div>
</div>
<div class="panel-wrapper collapse in">
<div class="panel-body">
<?php
global $wpdb;
$query = "SELECT COUNT(*) AS admin_count
FROM {$wpdb->users} u
JOIN {$wpdb->usermeta} um ON u.ID = um.user_id
WHERE um.meta_key = 'wp_capabilities'
AND um.meta_value LIKE %s";
// Prepare and execute the query
$registerd_count = $wpdb->get_var($wpdb->prepare($query, '%operator%'));
$assigned_query = "SELECT COUNT(*) FROM `wp_usermeta` WHERE meta_key = 'operator_status' AND meta_value = '2'";
$assigned_query_count = $wpdb->get_var($assigned_query);
$available_query = "SELECT COUNT(*) FROM `wp_usermeta` WHERE meta_key = 'operator_status' AND meta_value = '1'";
$available_query_count = $wpdb->get_var($available_query);
?>
<div>
<span class="pull-left inline-block capitalize-font txt-dark">
Registered
</span>
<span class="label label-warning pull-right" style="font-size:17px"><?php echo $registerd_count?></span>
<div class="clearfix"></div>
<hr class="light-grey-hr row mt-10 mb-10"/>
<span class="pull-left inline-block capitalize-font txt-dark">
Assigned
</span>
<span class="label label-danger pull-right" style="font-size:17px"><?php echo $assigned_query_count ?></span>
<div class="clearfix"></div>
<hr class="light-grey-hr row mt-10 mb-10"/>
<span class="pull-left inline-block capitalize-font txt-dark">
Available
</span>
<span class="label label-success pull-right" style="font-size:17px"><?php echo $available_query_count ?></span>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</div>
<!-- add here -->
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
<div class="panel panel-default card-view">
<div class="panel-heading">
<!-- <div class="pull-left"> -->
<h6 style="font-weight:500; font-size:28px; text-align:center;" class="panel-title txt-dark">Fleet Usage</h6> <br>
<h6 style="text-align:center; font-size:14px !important;">Average Hours Used For Month</h6>
<!-- </div> -->
<?php
// Function to get the last six months
function get_last_six_months() {
$months = [];
$current_date = new DateTime(); // Get the current date
// Loop to get the last six months
for ($i = 0; $i < 6; $i++) {
// Clone the current date and subtract months
$month = clone $current_date;
$month->modify("-$i month");
// Format the month and year
$months[] = $month->format('F Y');
}
// Reverse the array to have the oldest month first
return array_reverse($months);
}
// Fetch the last six months
$last_six_months = get_last_six_months();
$last_six_months_js = json_encode($last_six_months);
$first_month = $last_six_months[0]; // Get the first month
$second_month = $last_six_months[1];// Get the Second month
$third_month = $last_six_months[2];
$fourth_month = $last_six_months[3];
$fifth_month = $last_six_months[4];
$sixth_month = $last_six_months[5];
// for 1st month from last 6 months
global $wpdb;
// for excavator
$category_name = "excavator";
$query_count = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$first_month,
$category_name
);
$count = $wpdb->get_var($query_count);
$query_sum = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$first_month,
$category_name
);
$total_excavator_meta_value = $wpdb->get_var($query_sum);
// Calculate the average if count is greater than zero
$average_meta_value = 0; // Initialize average
if ($count > 0) {
$average_meta_value = round($total_excavator_meta_value / $count); // Calculate average
}
echo "<script>var averageExcavatorValue = " . intval($average_meta_value) . ";</script>";
// for excavator, 2nd month
$category_name = "excavator";
// Prepare the count query for the second month
$query_count_second = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$second_month,
$category_name
);
// Fetch the count result for the second month
$count_second = $wpdb->get_var($query_count_second);
// Prepare the sum query for the second month
$query_sum_second = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$second_month,
$category_name
);
// Fetch the sum result for the second month
$total_excavator_meta_value_second = $wpdb->get_var($query_sum_second);
// Calculate the average if count is greater than zero for the second month
$average_meta_value_second = 0; // Initialize average
if ($count_second > 0) {
$average_meta_value_second = round($total_excavator_meta_value_second / $count_second); // Calculate average
// echo $average_meta_value_second;
// echo "second Excavator '{$average_meta_value_second}': <br>";
}
// Output the JavaScript variable for the second month
echo "<script>var averageExcavatorValueSecond = " . intval($average_meta_value_second) . ";</script>";
// for 3rd month for excavator
$query_count_third = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$third_month, // Replace with your actual variable for the third month
$category_name
);
// Fetch the count result for the third month
$count_third = $wpdb->get_var($query_count_third);
// Prepare the sum query for the third month
$query_sum_third = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$third_month, // Replace with your actual variable for the third month
$category_name
);
// Fetch the sum result for the third month
$total_excavator_meta_value_third = $wpdb->get_var($query_sum_third);
// Calculate the average if count is greater than zero for the third month
$average_meta_value_third = 0; // Initialize average
if ($count_third > 0) {
$average_meta_value_third = round($total_excavator_meta_value_third / $count_third); // Calculate average
// echo "Third month Excavator '{$average_meta_value_third}': <br>";
}
// Output the JavaScript variable for the third month
echo "<script>var averageExcavatorValueThird = " . intval($average_meta_value_third) . ";</script>";
// For 4th month for excavator
$category_name = "excavator";
// Prepare the count query for the fourth month
$query_count_fourth = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fourth_month, // Replace with your actual variable for the fourth month
$category_name
);
// Fetch the count result for the fourth month
$count_fourth = $wpdb->get_var($query_count_fourth);
// Prepare the sum query for the fourth month
$query_sum_fourth = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fourth_month, // Replace with your actual variable for the fourth month
$category_name
);
// Fetch the sum result for the fourth month
$total_excavator_meta_value_fourth = $wpdb->get_var($query_sum_fourth);
// Calculate the average if count is greater than zero for the fourth month
$average_meta_value_fourth = 0; // Initialize average
if ($count_fourth > 0) {
$average_meta_value_fourth = round($total_excavator_meta_value_fourth / $count_fourth); // Calculate average
// echo "Fourth month Excavator '{$average_meta_value_fourth}': <br>";
}
// Output the JavaScript variable for the fourth month
echo "<script>var averageExcavatorValueFourth = " . intval($average_meta_value_fourth) . ";</script>";
// for fifth month for excavator
// Prepare the count query for the fifth month
$query_count_fifth = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fifth_month, // Replace with your actual variable for the fifth month
$category_name
);
// Fetch the count result for the fifth month
$count_fifth = $wpdb->get_var($query_count_fifth);
// Prepare the sum query for the fifth month
$query_sum_fifth = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fifth_month, // Replace with your actual variable for the fifth month
$category_name
);
// Fetch the sum result for the fifth month
$total_excavator_meta_value_fifth = $wpdb->get_var($query_sum_fifth);
// Calculate the average if count is greater than zero for the fifth month
$average_meta_value_fifth = 0; // Initialize average
if ($count_fifth > 0) {
$average_meta_value_fifth = round($total_excavator_meta_value_fifth / $count_fifth); // Calculate average
// echo "Fifth month Excavator '{$average_meta_value_fifth}': <br>";
}
// Output the JavaScript variable for the fifth month
echo "<script>var averageExcavatorValueFifth = " . intval($average_meta_value_fifth) . ";</script>";
// For 6th month for Excavator
$query_count_sixth = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$sixth_month, // Replace with your actual variable for the sixth month
$category_name
);
// Fetch the count result for the sixth month
$count_sixth = $wpdb->get_var($query_count_sixth);
// Prepare the sum query for the sixth month
$query_sum_sixth = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$sixth_month, // Replace with your actual variable for the sixth month
$category_name
);
// Fetch the sum result for the sixth month
$total_excavator_meta_value_sixth = $wpdb->get_var($query_sum_sixth);
// Calculate the average if count is greater than zero for the sixth month
$average_meta_value_sixth = 0; // Initialize average
if ($count_sixth > 0) {
$average_meta_value_sixth = round($total_excavator_meta_value_sixth / $count_sixth); // Calculate average
// echo "Sixth month Excavator '{$average_meta_value_sixth}': <br>";
}
// Output the JavaScript variable for the sixth month
echo "<script>var averageExcavatorValueSixth = " . intval($average_meta_value_sixth) . ";</script>";
// for power solution for 1st month
$category_name_power = "power solution";
$query_count_power = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$first_month,
$category_name_power
);
$count_power = $wpdb->get_var($query_count_power); // Use get_var() for a single value
// Prepare the sum query for power solution
$query_sum_power = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$first_month,
$category_name_power
);
$total_power_meta_value = $wpdb->get_var($query_sum_power);
$average_meta_value_power = 0; // Initialize average
if ($count_power > 0) {
$average_meta_value_power = round($total_power_meta_value / $count_power); // Calculate average
}
// echo "ASEEMA category_name '{$average_meta_value_power}': ";
echo "<script>var averagePowerSolutionValue = " . intval($average_meta_value_power) . ";</script>";
// for power solution, 2nd month
$query_count_second_power = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$second_month,
$category_name_power
);
// Fetch the count result for the second month
$count_second_power = $wpdb->get_var($query_count_second_power);
// Prepare the sum query for the second month
$query_sum_second_power = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$second_month,
$category_name_power
);
// Fetch the sum result for the second month
$total_power_meta_value_second = $wpdb->get_var($query_sum_second_power);
// Calculate the average if count is greater than zero for the second month
$average_meta_value_second_power = 0; // Initialize average
if ($count_second_power > 0) {
$average_meta_value_second_power = round($total_power_meta_value_second / $count_second_power); // Calculate average
// echo $average_meta_value_second_power;
// echo "second power solution '{$average_meta_value_second_power}': <br>";
}
// Output the JavaScript variable for the second month
echo "<script>var averagePowerSolutionValueSecond = " . intval($average_meta_value_second_power) . ";</script>";
// thord mnth for power solution
// Prepare the count query for the third month
$query_count_third_power = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$third_month, // Replace with your actual variable for the third month
$category_name_power
);
// Fetch the count result for the third month
$count_third_power = $wpdb->get_var($query_count_third_power);
// Prepare the sum query for the third month
$query_sum_third_power = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$third_month, // Replace with your actual variable for the third month
$category_name_power
);
// Fetch the sum result for the third month
$total_power_meta_value_third = $wpdb->get_var($query_sum_third_power);
// Calculate the average if count is greater than zero for the third month
$average_meta_value_third_power = 0; // Initialize average
if ($count_third_power > 0) {
$average_meta_value_third_power = round($total_power_meta_value_third / $count_third_power); // Calculate average
// echo $average_meta_value_third_power; // Uncomment to debug
// echo "Third power solution '{$average_meta_value_third_power}': <br>";
}
// Output the JavaScript variable for the third month
echo "<script>var averagePowerSolutionValueThird = " . intval($average_meta_value_third_power) . ";</script>";
// For 4th month for Power Solution
$query_count_fourth_power = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fourth_month, // Replace with your actual variable for the fourth month
$category_name_power
);
// Fetch the count result for the fourth month
$count_fourth_power = $wpdb->get_var($query_count_fourth_power);
// Prepare the sum query for the fourth month
$query_sum_fourth_power = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fourth_month, // Replace with your actual variable for the fourth month
$category_name_power
);
// Fetch the sum result for the fourth month
$total_power_meta_value_fourth = $wpdb->get_var($query_sum_fourth_power);
// Calculate the average if count is greater than zero for the fourth month
$average_meta_value_fourth_power = 0; // Initialize average
if ($count_fourth_power > 0) {
$average_meta_value_fourth_power = round($total_power_meta_value_fourth / $count_fourth_power); // Calculate average
// echo $average_meta_value_fourth_power; // Uncomment to debug
// echo "Fourth power solution '{$average_meta_value_fourth_power}': <br>";
}
// Output the JavaScript variable for the fourth month
echo "<script>var averagePowerSolutionValueFourth = " . intval($average_meta_value_fourth_power) . ";</script>";
// for fifth month for power solution
$query_count_fifth_power = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fifth_month, // Replace with your actual variable for the fifth month
$category_name_power
);
// Fetch the count result for the fifth month
$count_fifth_power = $wpdb->get_var($query_count_fifth_power);
// Prepare the sum query for the fifth month
$query_sum_fifth_power = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fifth_month, // Replace with your actual variable for the fifth month
$category_name_power
);
// Fetch the sum result for the fifth month
$total_power_meta_value_fifth = $wpdb->get_var($query_sum_fifth_power);
// Calculate the average if count is greater than zero for the fifth month
$average_meta_value_fifth_power = 0; // Initialize average
if ($count_fifth_power > 0) {
$average_meta_value_fifth_power = round($total_power_meta_value_fifth / $count_fifth_power); // Calculate average
// echo "Fifth power solution '{$average_meta_value_fifth_power}': <br>";
}
// Output the JavaScript variable for the fifth month
echo "<script>var averagePowerSolutionValueFifth = " . intval($average_meta_value_fifth_power) . ";</script>";
// For 6th month for Power Solution
$query_count_sixth_power = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$sixth_month, // Replace with your actual variable for the sixth month
$category_name_power
);
// Fetch the count result for the sixth month
$count_sixth_power = $wpdb->get_var($query_count_sixth_power);
// Prepare the sum query for the sixth month
$query_sum_sixth_power = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$sixth_month, // Replace with your actual variable for the sixth month
$category_name_power
);
// Fetch the sum result for the sixth month
$total_power_meta_value_sixth = $wpdb->get_var($query_sum_sixth_power);
// Calculate the average if count is greater than zero for the sixth month
$average_meta_value_sixth_power = 0; // Initialize average
if ($count_sixth_power > 0) {
$average_meta_value_sixth_power = round($total_power_meta_value_sixth / $count_sixth_power); // Calculate average
// echo "Sixth power solution '{$average_meta_value_sixth_power}': <br>";
}
// Output the JavaScript variable for the sixth month
echo "<script>var averagePowerSolutionValueSixth = " . intval($average_meta_value_sixth_power) . ";</script>";
// for loaders for 1st month
$category_name_loaders = "loaders"; // Set the category name for loaders
// Prepare the count query for loaders
$query_count_loaders = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$first_month,
$category_name_loaders
);
$count_loaders = $wpdb->get_var($query_count_loaders); // Use get_var() for a single value
// Prepare the sum query for loaders
$query_sum_loaders = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$first_month,
$category_name_loaders
);
// Fetch the sum result for loaders
$total_loaders_meta_value = $wpdb->get_var($query_sum_loaders);
// Calculate the average if count is greater than zero for loaders
$average_meta_value_loaders = 0;
if ($count_loaders > 0) {
$average_meta_value_loaders = round($total_loaders_meta_value / $count_loaders); // Calculate average
}
// Output the JavaScript variable for loaders
echo "<script>var averageLoadersValue = " . intval($average_meta_value_loaders) . ";</script>";
// for loaders, 2nd month
$category_name_loaders = "loaders";
// Prepare the count query for the second month
$query_count_second_loaders = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$second_month,
$category_name_loaders
);
// Fetch the count result for the second month
$count_second_loaders = $wpdb->get_var($query_count_second_loaders);
// Prepare the sum query for the second month
$query_sum_second_loaders = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$second_month,
$category_name_loaders
);
// Fetch the sum result for the second month
$total_loaders_meta_value_second = $wpdb->get_var($query_sum_second_loaders);
// Calculate the average if count is greater than zero for the second month
$average_meta_value_second_loaders = 0; // Initialize average
if ($count_second_loaders > 0) {
$average_meta_value_second_loaders = round($total_loaders_meta_value_second / $count_second_loaders); // Calculate average
// echo $average_meta_value_second_loaders;
// echo "second loaders '{$average_meta_value_second_loaders}':<br> ";
}
// Output the JavaScript variable for the second month
echo "<script>var averageLoadersValueSecond = " . intval($average_meta_value_second_loaders) . ";</script>";
// for 3rd month for loader
$query_count_third_loaders = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$third_month, // Replace with your actual variable for the third month
$category_name_loaders
);
// Fetch the count result for the third month
$count_third_loaders = $wpdb->get_var($query_count_third_loaders);
// Prepare the sum query for the third month
$query_sum_third_loaders = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$third_month, // Replace with your actual variable for the third month
$category_name_loaders
);
// Fetch the sum result for the third month
$total_loaders_meta_value_third = $wpdb->get_var($query_sum_third_loaders);
// Calculate the average if count is greater than zero for the third month
$average_meta_value_third_loaders = 0; // Initialize average
if ($count_third_loaders > 0) {
$average_meta_value_third_loaders = round($total_loaders_meta_value_third / $count_third_loaders); // Calculate average
// echo $average_meta_value_third_loaders; // Uncomment to debug
// echo "Third loaders '{$average_meta_value_third_loaders}':<br> ";
}
// Output the JavaScript variable for the third month
echo "<script>var averageLoadersValueThird = " . intval($average_meta_value_third_loaders) . ";</script>";
// For 4th month for Loaders
$query_count_fourth_loaders = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fourth_month, // Replace with your actual variable for the fourth month
$category_name_loaders
);
// Fetch the count result for the fourth month
$count_fourth_loaders = $wpdb->get_var($query_count_fourth_loaders);
// Prepare the sum query for the fourth month
$query_sum_fourth_loaders = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fourth_month, // Replace with your actual variable for the fourth month
$category_name_loaders
);
// Fetch the sum result for the fourth month
$total_loaders_meta_value_fourth = $wpdb->get_var($query_sum_fourth_loaders);
// Calculate the average if count is greater than zero for the fourth month
$average_meta_value_fourth_loaders = 0; // Initialize average
if ($count_fourth_loaders > 0) {
$average_meta_value_fourth_loaders = round($total_loaders_meta_value_fourth / $count_fourth_loaders); // Calculate average
// echo $average_meta_value_fourth_loaders; // Uncomment to debug
// echo "Fourth loaders '{$average_meta_value_fourth_loaders}': ";
}
// Output the JavaScript variable for the fourth month
echo "<script>var averageLoadersValueFourth = " . intval($average_meta_value_fourth_loaders) . ";</script>";
// For 5th month for Loaders
$query_count_fifth_loaders = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fifth_month, // Replace with your actual variable for the fifth month
$category_name_loaders
);
// Fetch the count result for the fifth month
$count_fifth_loaders = $wpdb->get_var($query_count_fifth_loaders);
// Prepare the sum query for the fifth month
$query_sum_fifth_loaders = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$fifth_month, // Replace with your actual variable for the fifth month
$category_name_loaders
);
// Fetch the sum result for the fifth month
$total_loaders_meta_value_fifth = $wpdb->get_var($query_sum_fifth_loaders);
// Calculate the average if count is greater than zero for the fifth month
$average_meta_value_fifth_loaders = 0; // Initialize average
if ($count_fifth_loaders > 0) {
$average_meta_value_fifth_loaders = round($total_loaders_meta_value_fifth / $count_fifth_loaders); // Calculate average
// echo "Fifth loaders '{$average_meta_value_fifth_loaders}': ";
}
// Output the JavaScript variable for the fifth month
echo "<script>var averageLoadersValueFifth = " . intval($average_meta_value_fifth_loaders) . ";</script>";
// For 6th month for Loaders
$query_count_sixth_loaders = $wpdb->prepare(
"SELECT COUNT(*) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$sixth_month, // Replace with your actual variable for the sixth month
$category_name_loaders
);
// Fetch the count result for the sixth month
$count_sixth_loaders = $wpdb->get_var($query_count_sixth_loaders);
// Prepare the sum query for the sixth month
$query_sum_sixth_loaders = $wpdb->prepare(
"SELECT SUM(meta_value) FROM `wp_fleet_usagemeta` WHERE meta_key = %s AND category_name = %s",
$sixth_month, // Replace with your actual variable for the sixth month
$category_name_loaders
);
// Fetch the sum result for the sixth month
$total_loaders_meta_value_sixth = $wpdb->get_var($query_sum_sixth_loaders);
// Calculate the average if count is greater than zero for the sixth month
$average_meta_value_sixth_loaders = 0; // Initialize average
if ($count_sixth_loaders > 0) {
$average_meta_value_sixth_loaders = round($total_loaders_meta_value_sixth / $count_sixth_loaders); // Calculate average
// echo "Sixth loaders '{$average_meta_value_sixth_loaders}': ";
}
// Output the JavaScript variable for the sixth month
echo "<script>var averageLoadersValueSixth = " . intval($average_meta_value_sixth_loaders) . ";</script>";
?>
<div id="last-six-months">
<ul>
<!-- <?php foreach ($last_six_months as $month) : ?>
<li><?php echo esc_html($month); ?></li>
<?php endforeach; ?> -->
</ul>
</div>
<div class="pull-right" style="display:none">
<span class="no-margin-switcher">
<input type="checkbox" id="morris_switch" class="js-switch" data-color="#ff2a00" data-secondary-color="#2879ff" data-size="small"/>
</span>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-wrapper collapse in">
<?php
global $wpdb;
$rental_fleet = "
SELECT COUNT(*)
FROM {$wpdb->postmeta} pm
JOIN {$wpdb->posts} p ON pm.post_id = p.ID
WHERE pm.meta_key = %s
AND pm.meta_value = %s
AND p.post_status = 'publish'
";
// Execute the query for "Rental Fleet" count
$rental_fleet_count = $wpdb->get_var($wpdb->prepare($rental_fleet, 'purpose_of_listing', 'renting'));
// Execute the query for used fleet
$used_fleet = "
SELECT COUNT( p.ID)
FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON p.ID = tr.object_id
JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN $wpdb->terms t ON tt.term_id = t.term_id
WHERE p.post_type = 'product'
AND p.post_status = 'publish' -- Only published products
AND tt.taxonomy = 'product_cat'
AND t.name = 'Sell'; -- Only products in the 'Sell' category
";
$used_fleet_count = $wpdb->get_var($used_fleet);
$used_fleet_count = $wpdb->get_var($used_fleet);
$rental_equp_fleet = "
WITH RECURSIVE category_tree AS (
-- Get Machine Rental category ID
SELECT term_id, parent
FROM wp_term_taxonomy
WHERE taxonomy = 'product_cat'
AND term_id = (SELECT term_id FROM wp_terms WHERE name = 'Machine Rental')
UNION ALL
-- Recursively get all child categories
SELECT tt.term_id, tt.parent
FROM wp_term_taxonomy tt
INNER JOIN category_tree ct ON tt.parent = ct.term_id
)
SELECT COUNT(DISTINCT p.ID) AS product_count
FROM wp_posts p
JOIN wp_term_relationships tr ON p.ID = tr.object_id
JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN wp_postmeta pm ON p.ID = pm.post_id
WHERE p.post_type = 'product'
AND p.post_status != 'trash' -- Exclude trashed products
AND tt.term_id IN (SELECT term_id FROM category_tree)
AND pm.meta_key = 'purpose_of_listing'
AND pm.meta_value = 'renting';
";
$rental_equp_fleet_count = $wpdb->get_var($rental_equp_fleet);
$dg_set_fleet = "
SELECT COUNT(DISTINCT p.ID) AS product_count
FROM wp_posts p
JOIN wp_term_relationships tr ON p.ID = tr.object_id
JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN wp_terms t ON tt.term_id = t.term_id
JOIN wp_postmeta pm ON p.ID = pm.post_id
WHERE p.post_type = 'product'
AND p.post_status != 'trash'
AND tt.taxonomy = 'product_cat'
AND t.name = 'DG Set'
AND pm.meta_key = 'purpose_of_listing'
AND pm.meta_value = 'renting';
";
$rental_dg_set_count = $wpdb->get_var($dg_set_fleet);
$total_rentals = $rental_dg_set_count + $rental_equp_fleet_count;
?>
<div class="panel-body">
<div id="morris_extra_line_chart" class="morris-chart" style="height:293px;"></div>
<ul class="flex-stat mt-40" style="display:flex">
<li>
<span class="block font-15 weight-500 mb-5">Total Rentals</span>
<span class="block txt-dark weight-500 font-18"><span class="counter-anim"><?php echo $total_rentals ?></span></span>
</li>
<li>
<span class="block font-15 weight-500 mb-5">Fleet Count</span>
<span class="block txt-dark weight-500 font-18"><span class="counter-anim"><?php echo $rental_equp_fleet_count ?></span></span>
</li>
<li>
<span class="block font-15 weight-500 mb-5">DG Count</span>
<span class="block txt-dark weight-500 font-18"><span class="counter-anim"><?php echo $rental_dg_set_count ?></span></span>
</li>
<li>
<span class="block font-15 weight-500 mb-5">Used Fleet</span>
<span class="block txt-dark weight-500 font-18"><span class="counter-anim"><?php echo $used_fleet_count ?></span></span>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
<div class="panel panel-default card-view panel-refresh">
<div class="refresh-container">
<div class="la-anim-1"></div>
</div>
<div class="panel-heading">
<?php
global $wpdb;
// Prepare the SQL query
$query_working = "
WITH RECURSIVE category_tree AS (
-- Get Machine Rental category ID
SELECT term_id, parent
FROM wp_term_taxonomy
WHERE taxonomy = 'product_cat'
AND term_id = (SELECT term_id FROM wp_terms WHERE name = 'Machine Rental')
UNION ALL
-- Recursively get all child categories
SELECT tt.term_id, tt.parent
FROM wp_term_taxonomy tt
INNER JOIN category_tree ct ON tt.parent = ct.term_id
)
SELECT COUNT(DISTINCT p.ID) AS product_count
FROM wp_posts p
JOIN wp_term_relationships tr ON p.ID = tr.object_id
JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN wp_postmeta pm1 ON p.ID = pm1.post_id
JOIN wp_postmeta pm2 ON p.ID = pm2.post_id
WHERE p.post_type = 'product'
AND p.post_status != 'trash' -- Exclude trashed products
AND tt.term_id IN (SELECT term_id FROM category_tree) -- Filter Machine Rental & children
AND pm1.meta_key = 'purpose_of_listing'
AND pm1.meta_value = 'renting'
AND pm2.meta_key = 'status'
AND pm2.meta_value = 'onrent';
";
$working_count = $wpdb->get_var( $query_working );
// Example: Fetching counts for "Idle" and "Breakdown" status as well
$query_idle = "
WITH RECURSIVE category_tree AS (
-- Get Machine Rental category ID
SELECT term_id, parent
FROM wp_term_taxonomy
WHERE taxonomy = 'product_cat'
AND term_id = (SELECT term_id FROM wp_terms WHERE name = 'Machine Rental')
UNION ALL
-- Recursively get all child categories
SELECT tt.term_id, tt.parent
FROM wp_term_taxonomy tt
INNER JOIN category_tree ct ON tt.parent = ct.term_id
)
SELECT COUNT(DISTINCT p.ID) AS product_count
FROM wp_posts p
JOIN wp_term_relationships tr ON p.ID = tr.object_id
JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN wp_postmeta pm1 ON p.ID = pm1.post_id
JOIN wp_postmeta pm2 ON p.ID = pm2.post_id
WHERE p.post_type = 'product'
AND p.post_status != 'trash' -- Exclude trashed products
AND tt.term_id IN (SELECT term_id FROM category_tree) -- Filter Machine Rental & children
AND pm1.meta_key = 'purpose_of_listing'
AND pm1.meta_value = 'renting'
AND pm2.meta_key = 'status'
AND pm2.meta_value = 'idle';
";
$idle_count = $wpdb->get_var( $query_idle );
$query_breakdown = "
WITH RECURSIVE category_tree AS (
-- Get Machine Rental category ID
SELECT term_id, parent
FROM wp_term_taxonomy
WHERE taxonomy = 'product_cat'
AND term_id = (SELECT term_id FROM wp_terms WHERE name = 'Machine Rental')
UNION ALL
-- Recursively get all child categories
SELECT tt.term_id, tt.parent
FROM wp_term_taxonomy tt
INNER JOIN category_tree ct ON tt.parent = ct.term_id
)
SELECT COUNT(DISTINCT p.ID) AS product_count
FROM wp_posts p
JOIN wp_term_relationships tr ON p.ID = tr.object_id
JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN wp_postmeta pm1 ON p.ID = pm1.post_id
JOIN wp_postmeta pm2 ON p.ID = pm2.post_id
WHERE p.post_type = 'product'
AND p.post_status != 'trash' -- Exclude trashed products
AND tt.term_id IN (SELECT term_id FROM category_tree) -- Filter Machine Rental & children
AND pm1.meta_key = 'purpose_of_listing'
AND pm1.meta_value = 'renting'
AND pm2.meta_key = 'status'
AND (pm2.meta_value like '%breakdown%')
";
$breakdown_count = $wpdb->get_var( $query_breakdown );
$total_rental_count = $breakdown_count + $idle_count +$working_count;
?>
<!-- <div class="pull-left"> -->
<h6 style="font-weight:500; font-size:28px; text-align:center;" class="panel-title txt-dark">Fleet Status</h6>
<!-- </div> -->
<div class="pull-right" style="display:none;">
<a href="#" class="pull-left inline-block refresh mr-15">
<i class="zmdi zmdi-replay"></i>
</a>
<div class="pull-left inline-block dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false" role="button" style="display:none;"><i class="zmdi zmdi-more-vert"></i></a>
<ul class="dropdown-menu bullet dropdown-menu-right" role="menu">
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-reply" aria-hidden="true"></i>Devices</a></li>
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-share" aria-hidden="true"></i>General</a></li>
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-trash" aria-hidden="true"></i>Referral</a></li>
</ul>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-wrapper collapse in">
<div class="panel-body">
<div>
<canvas id="chart_6" height="191"></canvas>
</div>
<hr class="light-grey-hr row mt-10 mb-15"/>
<div class="label-chatrs" style="display: flex; justify-content: center;">
<div class="">
<span class="clabels clabels-lg inline-block bg-blue mr-10 pull-right" style="margin-right:5px"></span>
<span class="clabels-text font-12 inline-block txt-dark capitalize-font pull-left"><span class="block font-15 weight-500 mb-5"><?php echo $working_count?> Rented</span></span>
<!-- <div id="sparkline_1" class="pull-right" style="width: 100px; overflow: hidden; margin: 0px auto;"></div> -->
<div class="clearfix"></div>
</div>
</div>
<hr class="light-grey-hr row mt-10 mb-15"/>
<div class="label-chatrs" style="display: flex; justify-content: center;">
<div class="">
<span class="clabels clabels-lg inline-block bg-green mr-10 pull-right" style="margin-right:5px"></span>
<span class="clabels-text font-12 inline-block txt-dark capitalize-font pull-left"><span class="block font-15 weight-500 mb-5"><?php echo $idle_count ?> Idle</span></span>
<!-- <div id="sparkline_2" class="pull-right" style="width: 100px; overflow: hidden; margin: 0px auto;"></div> -->
<div class="clearfix"></div>
</div>
</div>
<hr class="light-grey-hr row mt-10 mb-15"/>
<div class="label-chatrs" style="display: flex; justify-content: center;">
<div class="">
<span class="clabels clabels-lg inline-block bg-yellow mr-10 pull-right" style="margin-right:5px"></span>
<span class="clabels-text font-12 inline-block txt-dark capitalize-font pull-left"><span class="block font-15 weight-500 mb-5"><?php echo $breakdown_count?> Breakdown</span></span>
<!-- <div id="sparkline_3" class="pull-right" style="width: 100px; overflow: hidden; margin: 0px auto;"></div> -->
<div class="clearfix"></div>
</div>
</div>
</div>
<span class="block font-15 weight-500 mb-5 text-center txt-dark">
Rental Fleet Count: <span style="color:red;"><?php echo $total_rental_count?></span>
<a href="<?php echo admin_url('edit.php?post_type=product'); ?>" target="_blank"><span class="dashicons dashicons-arrow-right-alt" style="float:right;color:green;"></span></a>
</span>
</div>
</div>
</div>
</div>
<!-- /Row -->
<!-- Row -->
<div class="row">
<div class="col-lg-8 col-md-7 col-sm-12 col-xs-12">
<div class="panel panel-default card-view panel-refresh">
<div class="refresh-container">
<div class="la-anim-1"></div>
</div>
<div class="panel-heading">
<!-- <div class="pull-left"> -->
<h6 style="text-align:center; font-weight:500; font-size:28px;" class="panel-title txt-dark">Sale of Used Equipment
</h6>
<!-- </div> -->
<div class="pull-right" style="display:none">
<a href="#" class="pull-left inline-block refresh mr-15">
<i class="zmdi zmdi-replay"></i>
</a>
<a href="#" class="pull-left inline-block full-screen mr-15">
<i class="zmdi zmdi-fullscreen"></i>
</a>
<div class="pull-left inline-block dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false" role="button"><i class="zmdi zmdi-more-vert"></i></a>
<ul class="dropdown-menu bullet dropdown-menu-right" role="menu">
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-reply" aria-hidden="true"></i>Edit</a></li>
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-share" aria-hidden="true"></i>Delete</a></li>
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-trash" aria-hidden="true"></i>New</a></li>
</ul>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-wrapper collapse in">
<div class="panel-body row pa-0">
<div class="table-wrap">
<div class="table-responsive">
<?php
// Ensure that the WordPress environment is loaded
global $wpdb;
// Define the table name, using the correct prefix
$table_name = $wpdb->prefix . 'archive_sold_equipment_data'; // Replace with your actual table name
// Prepare the SQL query to fetch the latest 5 records
$query = "
SELECT bill_payer_name, bill_material_name, invoice_value, bill_created_on
FROM $table_name
ORDER BY bill_created_on DESC
LIMIT 5
";
// Execute the query and get the results
$results = $wpdb->get_results($query);
?>
<table class="table table-hover mb-0">
<thead>
<tr>
<th style="text-align:left">Customers</th>
<th style="text-align:left">Equipement</th>
<th style="text-align:left">Price</th>
<th style="text-align:left">Sold Date</th>
</tr>
</thead>
<tbody>
<?php
// Assuming you have fetched the required data into an array called $results
foreach ($results as $row) {
// Use the variables from the row, adjust as necessary
$bill_payer_name = esc_html($row->bill_payer_name); // Replace with actual logic to get orders, price, and status
$equipement = esc_html($row->bill_material_name);
$price = esc_html($row->invoice_value);
$Sold_date = date('d-m-Y', strtotime(esc_html($row->bill_created_on))) ;
$label_class = 'label-primary'; // Default label class
?>
<tr>
<td><span class="txt-dark weight-500"><?php echo $bill_payer_name; ?></span></td>
<td><span class="txt-dark weight-500"><?php echo $equipement; ?></span></td>
<td>
<span class="txt-dark weight-500">
<span><?php echo $price; ?></span>
</span>
</td>
<td>
<span class="txt-dark weight-500 "><?php echo $Sold_date; ?></span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-4 col-md-5 col-sm-12 col-xs-12">
<div class="panel panel-default card-view panel-refresh">
<div class="refresh-container">
<div class="la-anim-1"></div>
</div>
<div class="panel-heading">
<div class="">
<h2 style="text-align:center; font-weight:500; font-size:28px;" class="panel-title txt-dark">RFQ</h2>
</div>
<div class="pull-right" style="display:none;">
<a href="#" class="pull-left inline-block refresh mr-15">
<i class="zmdi zmdi-replay"></i>
</a>
<div class="pull-left inline-block dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false" role="button"><i class="zmdi zmdi-more-vert"></i></a>
<ul class="dropdown-menu bullet dropdown-menu-right" role="menu">
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-reply" aria-hidden="true"></i>option 1</a></li>
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-share" aria-hidden="true"></i>option 2</a></li>
<li role="presentation"><a href="javascript:void(0)" role="menuitem"><i class="icon wb-trash" aria-hidden="true"></i>option 3</a></li>
</ul>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-wrapper collapse in">
<div class="panel-body">
<div>
<?php
// Ensure WordPress environment is loaded
global $wpdb;
// Define the table name (assuming wp_quotation is the actual table name)
$table_name = $wpdb->prefix . 'quotation';
$table_name_rfq = $wpdb->prefix . 'request_quote';
// Prepare the SQL query
$query = "
SELECT COUNT(*)
FROM $table_name
WHERE qt_status = 'In Progress' OR qt_status = 'Revised'
";
// Execute the query and get the count
$in_progress_or_revised_count = $wpdb->get_var($query);
// echo 'Count of quotations in progress or revised: ' . $in_progress_or_revised_count;
// for accepted
// Prepare the SQL query to get the count of accepted quotations
$query_accepted = "
SELECT COUNT(*)
FROM $table_name
WHERE qt_status = 'Accepted'
";
// Execute the query and get the count
$accepted_count = $wpdb->get_var($query_accepted);
// echo 'Count of accepted quotations: ' . $accepted_count;
// for rfq count
// Automatically use the correct prefix for the table
// Prepare the SQL query to count the rows in wp_request_quote table
$query_request_quote = "
SELECT COUNT(*)
FROM $table_name_rfq
";
// Execute the query and get the count
$request_quote_count = $wpdb->get_var($query_request_quote);
// echo 'Count of request quotes: ' . $request_quote_count;
// Calculate the active count
$active_count = $request_quote_count - ($in_progress_or_revised_count + $accepted_count);
?>
<script>
var inProgressCount = <?php echo (int)$in_progress_or_revised_count; ?>;
var acceptedCount = <?php echo (int)$accepted_count; ?>;
var activeCount = <?php echo (int)$active_count; ?>;
</script>
<canvas id="chart_2" height="253"></canvas>
</div>
<div class="label-chatrs mt-30">
<div class="inline-block mr-15">
<span class="clabels inline-block bg-pink mr-5"></span>
<span class="clabels-text font-12 inline-block txt-dark capitalize-font">In progress</span>
</div>
<div class="inline-block mr-15">
<span class="clabels inline-block bg-green mr-5"></span>
<span class="clabels-text font-12 inline-block txt-dark capitalize-font">Accepted</span>
</div>
<div class="inline-block">
<span class="clabels inline-block bg-yellow mr-5"></span>
<span class="clabels-text font-12 inline-block txt-dark capitalize-font">Active</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Row -->
</div>
<!-- Footer -->
<footer class="footer container-fluid pl-30 pr-30">
<div class="row">
</div>
</footer>
<!-- /Footer -->
</div>
<!-- /Main Content -->
</div>
<!-- /#wrapper -->
<!-- JavaScript -->
<!-- jQuery -->
<script src="<?php echo plugins_url('template/vendors/bower_components/jquery/dist/jquery.min.js', __FILE__); ?>"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<?php echo plugins_url('template/vendors/bower_components/bootstrap/dist/js/bootstrap.min.js', __FILE__); ?>"></script>
<!-- Data table JavaScript -->
<script src="<?php echo plugins_url('template/vendors/bower_components/datatables/media/js/jquery.dataTables.min.js', __FILE__); ?>"></script>
<!-- Slimscroll JavaScript -->
<script src="<?php echo plugins_url('template/dist/js/jquery.slimscroll.js', __FILE__); ?>"></script>
<!-- simpleWeather JavaScript -->
<script src="<?php echo plugins_url('template/vendors/bower_components/moment/min/moment.min.js', __FILE__); ?>"></script>
<script src="<?php echo plugins_url('template/vendors/bower_components/simpleWeather/jquery.simpleWeather.min.js', __FILE__); ?>"></script>
<script src="<?php echo plugins_url('template/dist/js/simpleweather-data.js', __FILE__); ?>"></script>
<!-- Progressbar Animation JavaScript -->
<script src="<?php echo plugins_url('template/vendors/bower_components/waypoints/lib/jquery.waypoints.min.js', __FILE__); ?>"></script>
<script src="<?php echo plugins_url('template/vendors/bower_components/jquery.counterup/jquery.counterup.min.js', __FILE__); ?>"></script>
<!-- Fancy Dropdown JS -->
<script src="<?php echo plugins_url('template/dist/js/dropdown-bootstrap-extended.js', __FILE__); ?>"></script>
<!-- Sparkline JavaScript -->
<script src="<?php echo plugins_url('template/vendors/jquery.sparkline/dist/jquery.sparkline.min.js', __FILE__); ?>"></script>
<!-- Owl JavaScript -->
<script src="<?php echo plugins_url('template/vendors/bower_components/owl.carousel/dist/owl.carousel.min.js', __FILE__); ?>"></script>
<!-- ChartJS JavaScript -->
<script src="<?php echo plugins_url('template/vendors/chart.js/Chart.min.js', __FILE__); ?>"></script>
<!-- Morris Charts JavaScript -->
<script src="<?php echo plugins_url('template/vendors/bower_components/raphael/raphael.min.js', __FILE__); ?>"></script>
<script src="<?php echo plugins_url('template/vendors/bower_components/morris.js/morris.min.js', __FILE__); ?>"></script>
<!-- <script src="<?php echo plugins_url('template/vendors/bower_components/jquery-toast-plugin/dist/jquery.toast.min.js', __FILE__); ?>"></script> -->
<!-- Switchery JavaScript -->
<script src="<?php echo plugins_url('template/vendors/bower_components/switchery/dist/switchery.min.js', __FILE__); ?>"></script>
<!-- Init JavaScript -->
<script src="<?php echo plugins_url('template/dist/js/init.js', __FILE__); ?>"></script>
<script src="<?php echo plugins_url('template/dist/js/dashboard-data.js', __FILE__); ?>"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
if( document.getElementById('chart_6') ){
var ctx6 = document.getElementById("chart_6").getContext("2d");
var data6 = {
labels: [
"Rented",
"Idle",
"Breakdown"
],
datasets: [
{
data: [<?php echo $working_count; ?>, <?php echo $idle_count; ?>, <?php echo $breakdown_count; ?>],
backgroundColor: [
"#2879ff",
"#01c853",
"#fec107",
],
hoverBackgroundColor: [
"#2879ff",
"#01c853",
"#fec107",
]
}
]
};
var pieChart = new Chart(ctx6, {
type: 'pie',
data: data6,
options: {
animation: {
duration: 3000
},
responsive: true,
maintainAspectRatio: false,
legend: {
display: false
},
tooltip: {
backgroundColor: 'rgba(33,33,33,1)',
cornerRadius: 0,
footerFontFamily: "'Roboto'"
},
elements: {
arc: {
borderWidth: 0
}
}
}
});
}
// Fetch last six months from PHP
var lastSixMonths = <?php echo $last_six_months_js; ?>;
var testData = [
{ Excavator: 80, MotorGraders: 60, PowerSolutions: 70 },
{ Excavator: 70, MotorGraders: 200, PowerSolutions: 140 },
{ Excavator: 180, MotorGraders: 150, PowerSolutions: 140 }
];
function getRandomValue(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
if ($('#morris_extra_line_chart').length > 0) {
// Create a dynamic dataset by matching the periods with testData
var dataNew = lastSixMonths.map(function(month, index) {
// Find the corresponding testData entry for the current month
var monthData = testData.find(function(data) {
return data.period === month;
});
// If it's the second month, set random values
if (index === 1) { // Assuming second month is index 1
return {
period: month,
Excavator: monthData ? monthData.Excavator : averageExcavatorValueSecond,
MotorGraders: monthData ? monthData.MotorGraders : averageLoadersValueSecond,
PowerSolutions: monthData ? monthData.PowerSolutions : averagePowerSolutionValueSecond
};
}
// If it's the third month, set random values
if (index === 2) { // Assuming third month is index 2
return {
period: month,
Excavator: monthData ? monthData.Excavator : averageExcavatorValueThird,
MotorGraders: monthData ? monthData.MotorGraders : averageLoadersValueThird,
PowerSolutions: monthData ? monthData.PowerSolutions : averagePowerSolutionValueThird
};
}
if (index === 3) { // Assuming fourth month is index 3
return {
period: month,
Excavator: monthData ? monthData.Excavator : averageExcavatorValueFourth,
MotorGraders: monthData ? monthData.MotorGraders : averageLoadersValueFourth ,
PowerSolutions: monthData ? monthData.PowerSolutions : averagePowerSolutionValueFourth
};
}
if (index === 4) { // Assuming fifth month is index 4
return {
period: month,
Excavator: monthData ? monthData.Excavator : averageExcavatorValueFifth ,
MotorGraders: monthData ? monthData.MotorGraders : averageLoadersValueFifth ,
PowerSolutions: monthData ? monthData.PowerSolutions : averagePowerSolutionValueFifth
};
}
if (index === 5) { // Assuming sixth month is index 5
return {
period: month,
Excavator: monthData ? monthData.Excavator : averageExcavatorValueSixth ,
MotorGraders: monthData ? monthData.MotorGraders : averageLoadersValueSixth ,
PowerSolutions: monthData ? monthData.PowerSolutions : averagePowerSolutionValueSixth
};
}
// For other months, use actual test data or fallback to averages
return {
period: month,
Excavator: monthData ? monthData.Excavator : averageExcavatorValue,
MotorGraders: monthData ? monthData.MotorGraders : averageLoadersValue,
PowerSolutions: monthData ? monthData.PowerSolutions : averagePowerSolutionValue
};
});
// Debugging: Log the data for checking
console.log(dataNew);
// Initialize Morris chart with the new data
var lineChart = Morris.Line({
element: 'morris_extra_line_chart',
data: dataNew, // Use dynamic data with test data mapped
xkey: 'period',
ykeys: ['Excavator', 'MotorGraders', 'PowerSolutions'],
labels: ['Excavator', 'Loaders', 'Power Solutions'],
pointSize: 2,
fillOpacity: 0,
lineWidth: 2,
pointStrokeColors: ['#2879ff', '#e91e63', '#fec107'],
behaveLikeLine: true,
gridLineColor: '#878787',
hideHover: 'auto',
lineColors: ['#2879ff', '#e91e63', '#fec107'],
resize: true,
parseTime: false, // Keep this to treat 'period' as a string
xLabelAngle: 45 // Optional: Rotate x-axis labels if crowded
});
// Force chart to redraw
lineChart.redraw();
}
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
$('#morris_switch').each(function() {
new Switchery($(this)[0], $(this).data());
});
var swichMorris = function() {
if($("#morris_switch").is(":checked")) {
lineChart.setData(data);
lineChart.redraw();
} else {
lineChart.setData(dataNew);
lineChart.redraw();
}
}
swichMorris();
$(document).on('change', '#morris_switch', function () {
swichMorris();
});
// for RFQ bar graph
if( $('#chart_2').length > 0 ){
var ctx2 = document.getElementById("chart_2").getContext("2d");
var data2 = {
labels: lastSixMonths,
datasets: [
{
label: "In Progress",
backgroundColor: "rgba(233, 30, 99)",
borderColor: "rgba(233, 30, 99)",
data: [10, 10, 80, 61, 26, inProgressCount]
},
{
label: "Accepted",
backgroundColor: "rgba(1,200,83,1)",
borderColor: "rgba(1,200,83,1)",
data: [28, 28, 40, 19, 86, acceptedCount ]
},
{
label: "Active",
backgroundColor: "rgba(254,193,7,1)",
borderColor: "rgba(254,193,7,1)",
data: [8, 8, 50, 29, 76, activeCount ]
}
]
};
var hBar = new Chart(ctx2, {
type:"horizontalBar",
data:data2,
options: {
tooltips: {
mode:"label"
},
scales: {
yAxes: [{
stacked: true,
gridLines: {
color: "#878787",
},
ticks: {
fontFamily: "Roboto",
fontColor:"#878787"
}
}],
xAxes: [{
stacked: true,
gridLines: {
color: "#878787",
},
ticks: {
fontFamily: "Roboto",
fontColor:"#878787",
min: 0, // Set minimum value of x-axis
max: 40, // Set maximum value of x-axis
stepSize: 10 // Set step size for the x-axis labels
}
}],
},
elements:{
point: {
hitRadius:40
}
},
animation: {
duration: 3000
},
responsive: true,
maintainAspectRatio:false,
legend: {
display: false,
},
tooltip: {
backgroundColor:'rgba(33,33,33,1)',
cornerRadius:0,
footerFontFamily:"'Roboto'"
}
}
});
}
});
</script>
<style>
#morris_extra_line_chart svg {
height: 350px !important;
}
</style>