| Server IP : 13.126.101.145 / Your IP : 216.73.217.47 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/woocommerce-rfq/ |
Upload File : |
<?php
// Ensure the file is not accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Add admin menu
add_action('admin_menu', 'quotation_admin_menu');
function quotation_admin_menu()
{
add_menu_page(
'Quotation', // Page title
'Quotation', // Menu title
'manage_options', // Capability
'quotation-dashboard', // Menu slug
'quotation_display_quotes',// Callback function
'dashicons-list-view', // Icon URL
7 // Position
);
add_submenu_page(
null, //parent slug
'Edit Quotation Quotes', //page title
'Edit', //menu title
'manage_options', //capability
'edit-quotation', //menu slug
'quotation_edit'
);
}
// content data
function quotation_get_quotes($filter_status = '') {
global $wpdb;
$current_user = wp_get_current_user();
$user_roles = $current_user->roles;
$user_id = get_current_user_id();
$user_region = get_user_meta($user_id, 'ba_region_location', true);
// Base query
$where = "WHERE 1=1";
if (in_array('rue_manager', $user_roles) && !empty($user_region)) {
$where .= $wpdb->prepare(" AND region = %s", $user_region);
}
if (!empty($filter_status)) {
$where = $wpdb->prepare("WHERE qt_status = %s", $filter_status);
}
// Retrieve data with optional filter
$results = $wpdb->get_results("SELECT * FROM wp_quotation $where ORDER BY created_at DESC", ARRAY_A);
return $results;
}
function quotation_display_quotes()
{
global $wpdb;
// Get the current user's visible columns from their preferences
$user_id = get_current_user_id();
$visible_columns = get_user_meta($user_id, 'quotation_visible_columns', true);
$visible_columns = $visible_columns ? explode(',', $visible_columns) : ['machine_sr_no', 'actions'];
$filter_status = isset($_GET['qt_status']) ? sanitize_text_field($_GET['qt_status']) : '';
$quotes = quotation_get_quotes($filter_status);
?>
<div class="wrap quotation-wrap">
<h1 class="wp-heading-inline mb-2 font-weight-bold">Quotation</h1>
<!-- button and filter added -->
<div style="display:flex; margin-bottom:20px;">
<div class="quotation-export-btn" style="display:flex;">
<button id="quoteexport" class="btn custom-btn" style="padding: 2px 21px 4px 21px; margin-right:10px;" >Export</button>
</div>
<!-- show more columns -->
<button id="toggle-dropdown" style="padding: 0px 6px 0px 6px;background-color: #000;color:#FFBD2B; border-radius:5px;margin-right:10px;">Show More Columns</button>
<!-- Filter by Status -->
<form method="GET" action="" >
<input type="hidden" name="page" value="quotation-dashboard"> <!-- Preserve the page parameter -->
<select name="qt_status" id="qt_status_filter" style="padding: 0px 25px 0px 8px;">
<option value="">Filter by Status</option>
<?php
global $wpdb;
$statuses = $wpdb->get_col("SELECT DISTINCT qt_status FROM wp_quotation WHERE qt_status IS NOT NULL");
foreach ($statuses as $status) {
$selected = isset($_GET['qt_status']) && $_GET['qt_status'] === $status ? 'selected' : '';
echo "<option value='" . esc_attr($status) . "' $selected>" . esc_html(ucfirst($status)) . "</option>";
}
?>
</select>
<button type="submit" class="button button-primary" style="margin-left: 10px;">Filter</button>
</form>
</div>
<!-- select more column dropdown -->
<div id="dropdown" style="display: none; border: 1px solid #ccc; padding: 10px; width: 100%; background-color: white; position: relative;margin-bottom:30px;">
<h6>Select Columns to Display:</h6>
<form method="POST" action="">
<div style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 20px;">
<label>
<input type="checkbox" name="columns[]" value="end_date" <?php checked(in_array('end_date', $visible_columns)); ?>> End Date
</label>
<label>
<input type="checkbox" name="columns[]" value="shifts" <?php checked(in_array('shifts', $visible_columns)); ?>> Shifts
</label>
<label>
<input type="checkbox" name="columns[]" value="final_price" <?php checked(in_array('final_price', $visible_columns)); ?>> Final Price
</label>
<label>
<input type="checkbox" name="columns[]" value="status" <?php checked(in_array('status', $visible_columns)); ?>> Status
</label>
<label>
<input type="checkbox" name="columns[]" value="discount_status" <?php checked(in_array('discount_status', $visible_columns)); ?>> Discount Status
</label>
<label>
<input type="checkbox" name="columns[]" value="discount_requested" <?php checked(in_array('discount_requested', $visible_columns)); ?>> Discount Requested
</label>
<label>
<input type="checkbox" name="columns[]" value="approver_comments" <?php checked(in_array('approver_comments', $visible_columns)); ?>> approver_comments
</label>
<label>
<input type="checkbox" name="columns[]" value="created_on" <?php checked(in_array('created_on', $visible_columns)); ?>> created_on
</label>
</div>
<input type="submit" name="save_columns" value="Save Columns" style="margin-top: 10px;" class="button button-primary">
</form>
</div>
<!-- /end button and filter added -->
<div class="table-responsive">
<table id="quotation-table" class="table display pb-30 dataTable table-data">
<thead style="background-color:#FFBD2B;">
<tr>
<th scope="row" class="manage-column sticky-col">Sr. No</th>
<th scope="col" class="manage-column">Quotation ID</th>
<th scope="col" class="manage-column">Customer Name</th>
<th scope="col" class="manage-column">Customer Email</th>
<th scope="col" class="manage-column">Product Name</th>
<th scope="col" class="manage-column">Start Date</th>
<th class="manage-column"
<?php
if (in_array('end_date', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"';
}
?>
>End Date</th>
<!-- <th class="manage-column"
<?php
if (in_array('shifts', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"';
}
?>
>Shifts</th> -->
<th class="manage-column"
<?php
if (in_array('final_price', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"';
}
?>
>Final Price</th>
<th class="manage-column"
<?php
if (in_array('status', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"';
}
?>
>Status</th>
<th class="manage-column"
<?php
if (in_array('discount_status', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"';
}
?>
>Discount Status</th>
<th class="manage-column"
<?php
if (in_array('discount_requested', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"';
}
?>
>Discount Requested</th>
<th class="manage-column"
<?php
if (in_array('approver_comments', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"';
}
?>
>approver_comments</th>
<th class="manage-column"
<?php
if (in_array('created_on', $visible_columns)) {
echo 'style="font-weight:700; width:75.5px;"' ;
} else {
echo 'style="display:none"';
}
?>
>Created On</th>
<th scope="col" class="manage-column sticky-col-action" style="background-color:#FFBD2B;">Actions
</th>
</tr>
</thead>
<tbody>
<?php if ($quotes): ?>
<?php $count = 1; ?>
<?php foreach ($quotes as $quote): ?>
<?php
$metaData = get_user_meta($quote['user_id'], 'sap_customer_id', $single = false);
if (!empty($metaData[0])) {
$actionSts = '<a href="" title="Generate Quote"><i class="fas fa-paper-plane" alt="Generate Quote"></i></a>';
$customerStatus = 'Exisiting Customer';
} else {
$actionSts = '<a href="https://gmmco.connecticons.app/customer/registration/portal" title="Register Customer
" target="_blank"><i class="fa fa-link" aria-hidden="true" alt="Register Customer"></i></a>';
$customerStatus = 'New Customer';
}
?>
<tr>
<td class="sticky-col"><?php echo $count++; ?></td>
<td><?php echo esc_html($quote['id']); ?></td>
<td><?php echo esc_html($quote['user_name']); ?></td>
<td><?php echo esc_html($quote['user_email']); ?></td>
<!-- <td><?php echo esc_html($quote['product_id']); ?></td> -->
<td><?php echo esc_html($quote['product_name']); ?></td>
<td><?php echo esc_html(date('d-m-Y', strtotime($quote['start_date']))); ?></td>
<td <?php echo in_array('end_date', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html(date('d-m-Y', strtotime($quote['end_date']))); ?></td>
<!-- <td <?php echo in_array('shifts', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($quote['shift']); ?></td> -->
<td <?php echo in_array('final_price', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($quote['final_price']); ?></td>
<td <?php echo in_array('status', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($quote['qt_status']); ?></td>
<td <?php echo in_array('discount_status', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($quote['discount_status']); ?></td>
<td <?php echo in_array('discount_requested', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($quote['discount_requested']); ?></td>
<td <?php echo in_array('approver_comments', $visible_columns) ? '' : 'style="display:none"'; ?>><?php echo esc_html($quote['ap_comments']); ?></td>
<td <?php echo in_array('created_on', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php echo esc_html(date("d-m-Y", strtotime($quote['created_at']))); ?>
</td>
<td class="sticky-col-action">
<?php
// Check if an agreement exists for the current quote
$agreement_exists = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM wp_agreement WHERE qt_id = %d",
$quote['id']
));
// Show edit button as read-only if an agreement exists
if ($agreement_exists) {
// Show as read-only with reduced opacity and disabled pointer events
echo '<a href="#" class="readonly-edit-btn" title="Edit (Read Only)" style="pointer-events: none; opacity: 0.5;">
<i class="fas fa-edit"></i>
</a>';
} else {
// Normal edit button
echo '<a href="' . admin_url('admin.php?page=edit-quotation&id=' . $quote['id']) . '" title="Edit">
<i class="fas fa-edit"></i>
</a>';
}
?>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="11" class="no-quotes">No quotes found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
<!-- added -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- Include DataTables CSS and JS -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
<!-- Include Bootstrap CSS and JS for Multiselect -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js"></script>
<!-- Include Bootstrap Multiselect CSS and JS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-multiselect@0.9.15/dist/css/bootstrap-multiselect.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap-multiselect@0.9.15/dist/js/bootstrap-multiselect.min.js"></script>
<!--end added -->
<script>
// Initialize DataTable
jQuery(document).ready(function ($) {
// jQuery('#quotation-table').DataTable();
var dataTable = jQuery('#quotation-table').DataTable({
"scrollX": true,
});
$('#toggle-dropdown').on('click', function() {
$('#dropdown').toggle();
});
function exportTableToCSV(filename) {
var csv = [];
var rows = document.querySelectorAll("#quotation-table tbody tr");
// Get table headers (column names)
var headers = [];
var headerCols = document.querySelectorAll("#quotation-table thead th");
for (var k = 0; k < headerCols.length - 1; k++) { // exclude last header
headers.push(headerCols[k].innerText);
}
csv.push(headers.join(",")); // Push headers to CSV
// Get table rows data
for (var i = 0; i < rows.length; i++) {
var row = [];
var cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length - 1; j++) { // exclude last column
row.push(cols[j].innerText);
}
csv.push(row.join(","));
}
// Download CSV file
downloadCSV(csv.join("\n"), filename);
}
function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;
// CSV file
csvFile = new Blob([csv], { type: "text/csv" });
// Download link
downloadLink = document.createElement("a");
// File name
downloadLink.download = filename;
// Create a link to the file
downloadLink.href = window.URL.createObjectURL(csvFile);
// Hide download link
downloadLink.style.display = "none";
// Add the link to DOM
document.body.appendChild(downloadLink);
// Click download link
downloadLink.click();
}
// Attach event listener to export button
document.getElementById("quoteexport").addEventListener("click", function () {
exportTableToCSV("Quotation-Data.csv");
});
});
</script>
<style>
.manage-column {
font-size:13px;
white-space: wrap;
}
.table-responsive .table-data th {
white-space: nowrap;
}
.table-responsive {
overflow-x: auto;
}
.table-data tbody tr:nth-child(even) {
background-color: #ffbd2b30 !important;
}
.sticky-col {
position: sticky !important;
left: 0px;
z-index: 2 !important;
background-color: #FFBD2B;
width:20px !important;
}
.sticky-col-action {
position: sticky !important;
right: 0px;
background-color: #fff;
z-index: 2;
}
.table-responsive .table-data.display tbody tr.odd>.sorting_1 {
background-color: #FFF;
}
.table-responsive .table-data th, table.dataTable td{
white-space: nowrap !important;
}
.table-responsive .table-data tr {
padding: 50px !important;
}
table.dataTable.stripe tbody tr.odd, table.dataTable.display tbody tr.odd {
height:50px;
}
.quotation-export-btn .custom-btn {
background-color: #000;
color: #FFBD2B;
font-weight: 600;
font-size:15px;
border-radius:5px;
cursor: pointer;
}
.quotation-export-btn .custom-btn:hover {
color: #fff;
}
.table-responsive .dataTables_wrapper .dataTables_length select {
padding: 0px 17px 1px 8px;
}
.dataTables_filter {
margin-bottom:10px;
}
.btn-group button {
background-color: #fff !important;
border: 1px solid #0000002b !important;
}
.quotation-wrap {
background-color: #f9f9f9;
padding: 20px;
border-radius: 8px;
}
</style>
<?php
if (isset($_POST['save_columns'])) {
$selected_columns = isset($_POST['columns']) ? $_POST['columns'] : [];
update_user_meta($user_id, 'quotation_visible_columns', implode(',', $selected_columns));
echo '<script>location.reload();</script>';
}
}
function create_order(){
global $wpdb;
$id = intval($_GET['id']);
$getQuoteDet = $wpdb->get_row($wpdb->prepare(
"SELECT * FROM wp_quotation WHERE id = %d",
$id
));
$user_id = $getQuoteDet->user_id;
$userDetails = get_userdata($user_id);
$first_name = get_user_meta($user_id, 'billing_first_name', true);
$last_name = get_user_meta($user_id, 'billing_last_name', true);
$user_phone = get_user_meta($user_id, 'user_phone', true);
$billing_address_1 = get_user_meta($user_id, 'billing_address_1', true);
$billing_address_2 = get_user_meta($user_id, 'billing_address_2', true);
$billing_city = get_user_meta($user_id, 'billing_city', true);
$billing_state = get_user_meta($user_id, 'billing_state', true);
$billing_postcode = get_user_meta($user_id, 'billing_postcode', true);
$billing_country = get_user_meta($user_id, 'billing_country', true);
$customer_id = $getQuoteDet->user_id; // Replace with a valid customer ID
$product_id = $getQuoteDet->product_id; // Replace with a valid product ID
$quantity = 1;
$order = wc_create_order();
$custom_price = $getQuoteDet->final_price;
// Add product to the order
$product = wc_get_product($product_id);
$order->add_product($product, $quantity, [
'subtotal' => $custom_price * $quantity,
'total' => $custom_price * $quantity,
]); // Specify the quantity
// Set customer details
$order->set_customer_id($customer_id);
$order->set_billing_email($userDetails->user_email);
// Set address details
$address = array(
'first_name' => $first_name,
'last_name' => $last_name,
'company' => $first_name,
'email' => $userDetails->user_email,
'phone' => $user_phone,
'address_1' => $billing_address_1,
'address_2' => $billing_address_2,
'city' => $billing_city,
'state' => $billing_state,
'postcode' => $billing_postcode,
'country' => $billing_country
);
// Set billing and shipping address
$order->set_address($address, 'billing');
$order->set_address($address, 'shipping');
// Calculate totals
// Set order total
$order->set_total($custom_price * $quantity);
// Save the order
$order->save();
$order_id = $order->get_id();
// Add custom meta data
update_post_meta($order_id, 'rental_amount', $getQuoteDet->final_price);
update_post_meta($order_id, 'deposit_amount', '');
update_post_meta($order_id, '_number_shifts_required', $getQuoteDet->shift);
update_post_meta($order_id, 'start_date', $getQuoteDet->start_date);
update_post_meta($order_id, 'end_date', $getQuoteDet->end_date);
update_post_meta($order_id, '_quotation_id', $getQuoteDet->id);
$qt_tbl = $wpdb->prefix."quotation";
$wpdb->query( $wpdb->prepare("UPDATE $qt_tbl
SET qt_status = %s
WHERE id = %s",'Order Generated', $getQuoteDet->id)
);
// Send the email notification
WC()->mailer()->get_emails()['WC_Email_Customer_Processing_Order']->trigger($order->get_id());
echo '<div id="message" class="notice notice-success is-dismissible updated"><p>Order ID'.$order_id.' created successfully.</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>';
}
function hide_screen_options_for_quotation() {
?>
<style>
<?php if (isset($_GET['page']) && ($_GET['page'] === 'quotation-dashboard' || $_GET['page'] === 'edit-quotation')) : ?>
#screen-meta-links {
display: none !important;
}
<?php endif; ?>
</style>
<?php
}
add_action('admin_head', 'hide_screen_options_for_quotation');