| Server IP : 13.126.101.145 / Your IP : 216.73.216.159 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/agreement/ |
Upload File : |
<?php
/*
Plugin Name: Agreement Plugin
Description: Custom plugin to manage agreements and dynamic Create order.
Version: 1.3
Author: Itrosys
*/
// Include the user page
include plugin_dir_path(__FILE__) . "user-my-account.php";
// Function to enqueue styles
function enqueue_my_plugin_styles() {
// Enqueue the style.css file
wp_enqueue_style('my-plugin-styles', plugin_dir_url(__FILE__) . 'style.css', array(), '1.0', 'all');
}
// Use 'admin_enqueue_scripts' if both pages are in the WordPress admin
add_action('admin_enqueue_scripts', 'enqueue_my_plugin_styles');
// Hide specific elements on the WooCommerce order edit page
function custom_hide_wc_order_elements() {
// Check if we are on the WooCommerce order edit page
$screen = get_current_screen();
if ( $screen && $screen->id == 'shop_order' ) {
?>
<style>
th.item_cost.sortable {
display: none;
}
th.quantity.sortable {
display: none;
}
th.line_cost.sortable {
display: none;
}
td.item_cost {
display: none;
}
td.quantity {
display: none;
}
td.line_cost {
display: none;
}
table.wc-order-totals {
display: none;
}
button.button.button-primary.calculate-action {
display: none;
}
button.button.add-coupon {
display: none;
}
button.button.refund-items {
display: none;
}
a.edit-order-item.tips {
display: none !important;
}
button.button.add-order-fee {
display: none;
}
button.button.add-order-shipping {
display: none;
}
</style>
<?php
}
}
add_action('admin_head', 'custom_hide_wc_order_elements');
?>
<?php
global $wpdb;
define('AGREEMENT_TABLE', $wpdb->prefix . 'agreement');
// Plugin Activation: Create the agreement table
// Add menu page for the Agreement Plugin
function agreement_admin_menu() {
add_menu_page(
'Agreement Management',
'Agreements',
'manage_options',
'agreement',
'agreement_management_page',
'dashicons-media-document',
20
);
}
add_action('admin_menu', 'agreement_admin_menu');
// Create Agreement form and listing page
function agreement_management_page() {
global $wpdb;
// Check if the upload_success query parameter exists
// if (isset($_GET['upload_success']) && $_GET['upload_success'] == '1') {
// echo '<br><div class="notice notice-success is-dismissible"><p>PDF uploaded successfully.</p></div>';
// }
// Handle order creation
if (isset($_POST['create_order']) && !empty($_POST['create_order_agreement_id'])) {
$agreement_id = intval($_POST['create_order_agreement_id']);
// Fetch the agreement and related product and user details
$agreement = $wpdb->get_row($wpdb->prepare("
SELECT a.*, q.*
FROM " . AGREEMENT_TABLE . " a
LEFT JOIN " . $wpdb->prefix . "quotation q ON a.qt_id = q.id
WHERE a.agreement_id = %d", $agreement_id));
$table_name = $wpdb->prefix . 'agreement';
$qt_id = $wpdb->get_var($wpdb->prepare("SELECT qt_id FROM $table_name WHERE agreement_id = %d", $agreement_id));
$table_name = $wpdb->prefix . 'quotation';
$rfq_id = $wpdb->get_var($wpdb->prepare("SELECT rfq_id FROM $table_name WHERE id = %d", $qt_id));
// $table_name = $wpdb->prefix . 'request_quote';
// $rfq_order_id = $wpdb->get_var($wpdb->prepare("SELECT order_id FROM $table_name WHERE id = %d", $rfq_id));
// Directly get order_id from quotation table
$rfq_order_id = $wpdb->get_var($wpdb->prepare("SELECT order_id FROM $table_name WHERE id = %d", $qt_id));
if ($agreement) {
create_woocommerce_order($agreement, $rfq_order_id); // Create WooCommerce order and redirect
}
}
// Handle date filter submission
$start_date_filter = isset($_POST['start_date_filter']) ? sanitize_text_field($_POST['start_date_filter']) : '';
$end_date_filter = isset($_POST['end_date_filter']) ? sanitize_text_field($_POST['end_date_filter']) : '';
// Build the WHERE clause for filtering by start and end dates
$where_clauses = [];
if (!empty($start_date_filter)) {
$where_clauses[] = $wpdb->prepare("q.start_date >= %s", $start_date_filter);
}
if (!empty($end_date_filter)) {
$where_clauses[] = $wpdb->prepare("q.end_date <= %s", $end_date_filter);
}
$where_sql = !empty($where_clauses) ? "WHERE " . implode(' AND ', $where_clauses) : '';
// Fetch agreements with the date filter applied
$agreements = $wpdb->get_results("
SELECT
a.*,
q.*
FROM " . AGREEMENT_TABLE . " a
LEFT JOIN " . $wpdb->prefix . "quotation q ON a.qt_id = q.id
$where_sql
ORDER BY a.agreement_id DESC
");
// Get the current user's visible columns from their preferences
$user_id = get_current_user_id();
$visible_columns = get_user_meta($user_id, 'agreement_visible_columns', true);
$visible_columns = $visible_columns ? explode(',', $visible_columns) : ['machine_sr_no', 'actions'];
?>
<div style="overflow-x: auto; width:100%;">
<br>
<h1 style="font-weight:bold;">Agreements List</h1><br>
<div class="all-in-one-line" style="display: flex; align-items: center; gap: 10px; flex-wrap: nowrap;">
<button id="toggle-dropdown" style="margin-bottom: 10px;padding: 5px;background-color: #000;color:#FFBD2B; border-radius:5px;flex-shrink: 0;">Show More Columns</button>
<button id="exportbutton" style="margin-top: -11px; padding: 5px 20px; background-color: #000; color: #FFBD2B; border-radius: 5px;flex-shrink: 0;margin-bottom: unset;">Export</button><br><br>
<form method="POST" style="margin-bottom: 20px;">
<label for="start_date_filter">Start Date:</label>
<input type="date" id="start_date_filter" name="start_date_filter" value="<?php echo esc_attr($start_date_filter); ?>" />
<label for="end_date_filter">End Date:</label>
<input type="date" id="end_date_filter" name="end_date_filter" value="<?php echo esc_attr($end_date_filter); ?>" />
<button type="submit" class="button button-primary">Filter</button>
</form>
</div>
<div id="dropdown" style="display: none; border: 1px solid #ccc; padding: 10px; width: 100%; background-color: white; position: relative;margin-bottom:30px;">
<h3>Select Columns to Display:</h3>
<form method="POST" action="">
<div style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 20px;">
<label>
<input type="checkbox" name="columns[]" value="customer_email" <?php checked(in_array('customer_email', $visible_columns)); ?>> Customer Email
</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="start_date" <?php checked(in_array('start_date', $visible_columns)); ?>>Start Date
</label>
<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="view_agreement" <?php checked(in_array('view_agreement', $visible_columns)); ?>> View Agreement
</label>
<label>
<input type="checkbox" name="columns[]" value="view_customer_pdf" <?php checked(in_array('view_customer_pdf', $visible_columns)); ?>> View Customer PDF
</label>
</div>
<input type="submit" name="save_columns" value="Save Columns" style="margin-top: 10px;" class="button button-primary">
</form>
</div>
<table class="wp-list-table widefat striped table-view-list" id="agreement-table">
<thead>
<tr>
<th scope="col" class="set-width">SN</th>
<th scope="col" class="set-width">Customer Name</th>
<!-- <th>Customer Email</th> -->
<th scope="col" class="set-width"
<?php
if (!in_array('customer_email', $visible_columns)) {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Customer Email</th>
<th scope="col" class="set-width">Product Name</th>
<!-- <th>Start Date</th> -->
<th scope="col" class="set-width"
<?php
if (!in_array('start_date', $visible_columns)) {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Start Date</th>
<!-- <th>End Date</th> -->
<th scope="col" class="set-width"
<?php
if (!in_array('end_date', $visible_columns)) {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>End Date</th>
<!-- <th>Final Price</th> -->
<th scope="col" class="set-width"
<?php
if (!in_array('final_price', $visible_columns)) {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>Final Price</th>
<th scope="col" class="set-width">Download Agreement Word</th>
<th scope="col" class="set-width">Upload Agreement PDF</th>
<!-- <th>View Agreement PDF</th> -->
<th scope="col" class="set-width"
<?php
if (!in_array('view_agreement', $visible_columns)) {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>View Agreement PDF</th>
<!-- <th>View Customer Signed PDF</th> -->
<th scope="col" class="set-width"
<?php
if (!in_array('view_customer_pdf', $visible_columns)) {
echo 'style="display:none"'; // Hide column if not visible
}
?>
>View Customer Signed PDF</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
// Initialize serial number
$serial_number = 1;
foreach ($agreements as $agreement) {
// Get the rfq_order_id for this specific agreement
$current_qt_id = $wpdb->get_var($wpdb->prepare("SELECT qt_id FROM " . $wpdb->prefix . "agreement WHERE agreement_id = %d", $agreement->agreement_id));
$current_rfq_id = $wpdb->get_var($wpdb->prepare("SELECT rfq_id FROM " . $wpdb->prefix . "quotation WHERE id = %d", $current_qt_id));
// $rfq_order_id = $wpdb->get_var($wpdb->prepare("SELECT order_id FROM " . $wpdb->prefix . "request_quote WHERE id = %d", $current_rfq_id));
$rfq_order_id = $wpdb->get_var($wpdb->prepare("SELECT order_id FROM " . $wpdb->prefix . "quotation WHERE id = %d",$current_qt_id));
?>
<tr>
<td><?php echo $serial_number; ?></td>
<td><?php echo $agreement->user_name; ?></td>
<!-- <td><?php echo $agreement->user_email; ?></td> -->
<td class="manage-column" <?php echo in_array('customer_email', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php echo !empty($agreement->user_email) ? esc_html($agreement->user_email) : 'N/A'; ?>
</td>
<td><?php echo $agreement->product_name; ?></td>
<!-- <td><?php echo $agreement->start_date; ?></td> -->
<td class="manage-column" <?php echo in_array('start_date', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php echo !empty($agreement->start_date) ? esc_html($agreement->start_date) : 'N/A'; ?>
</td>
<!-- <td><?php echo $agreement->end_date; ?></td> -->
<td class="manage-column" <?php echo in_array('end_date', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php echo !empty($agreement->end_date) ? esc_html($agreement->end_date) : 'N/A'; ?>
</td>
<!-- <td><?php echo $agreement->final_price; ?></td> -->
<td class="manage-column" <?php echo in_array('final_price', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php echo !empty($agreement->final_price) ? esc_html($agreement->final_price) : 'N/A'; ?>
</td>
<td>
<form method="post">
<input type="hidden" name="download_agreement_id" value="<?php echo $agreement->agreement_id; ?>">
<input type="submit" name="download_word" class="button button-secondary download-word" value="Download">
</form>
</td>
<td>
<form method="post" enctype="multipart/form-data" id="upload-pdf-form-<?php echo $agreement->agreement_id; ?>">
<input type="hidden" name="upload_agreement_id" value="<?php echo $agreement->agreement_id; ?>">
<input id="file-upload-<?php echo $agreement->agreement_id; ?>" type="file" name="pdf_file" accept="application/pdf" required style="display: none;" onchange="this.form.submit();">
<!-- <span id="file-name-<?php echo $agreement->agreement_id; ?>">No file selected</span> -->
<input type="button" name="upload_pdf" class="button button-primary" value="Upload PDF" onclick="triggerFileUpload(<?php echo $agreement->agreement_id; ?>);">
</form>
</td>
<!-- <td>
<?php if (!empty($agreement->upload_pdf)) { ?>
<a href="<?php echo esc_url($agreement->upload_pdf); ?>" target="_blank" class="button button-secondary view-pdf">View Uploaded</a>
<?php } else { ?>
<span>No PDF Uploaded</span>
<?php } ?>
</td> -->
<td class="manage-column" <?php echo in_array('view_agreement', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php if (!empty($agreement->upload_pdf)) : ?>
<a href="<?php echo esc_url($agreement->upload_pdf); ?>" target="_blank" class="button button-secondary view-pdf">View Uploaded</a>
<?php else : ?>
<span>No PDF Uploaded</span>
<?php endif; ?>
</td>
<!-- <td>
<?php if (!empty($agreement->upload_pdf_cus)) { ?>
<a href="<?php echo esc_url($agreement->upload_pdf_cus); ?>" target="_blank" class="button button-secondary view-pdf">View Signed</a>
<?php } else { ?>
<span>Signed Doc Awaited</span>
<?php } ?>
</td> -->
<td class="manage-column" <?php echo in_array('view_customer_pdf', $visible_columns) ? '' : 'style="display:none"'; ?>>
<?php if (!empty($agreement->upload_pdf_cus)) : ?>
<a href="<?php echo esc_url($agreement->upload_pdf_cus); ?>" target="_blank" class="button button-secondary view-pdf">View Signed</a>
<?php else : ?>
<span>Signed Doc Awaited</span>
<?php endif; ?>
</td>
<td>
<?php if (isset($agreement->upload_pdf_cus) && !empty($agreement->upload_pdf_cus)) : ?>
<?php if ($agreement->status == 'Order Created') : ?>
<h4><b>Contract Created</b></h4>
<?php else : ?>
<form method="post">
<input type="hidden" name="create_order_agreement_id" value="<?php echo $agreement->agreement_id; ?>">
<?php if($rfq_order_id):?><input type="submit" name="create_order" value="Update Contract" class="button button-primary">
<?php else:?> <input type="submit" name="create_order" value="Create Contract" class="button button-primary">
<?php endif; ?>
</form>
<?php endif; ?>
<?php endif; ?>
</td>
<?php
// Increment serial number after each row
$serial_number++;
?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<style>
.set-width {
/* width:150px !important; */
white-space: nowrap;
}
</style>
<!-- Include DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
<!-- Include jQuery and DataTables JS -->
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script>
function triggerFileUpload(agreementId) {
document.getElementById('file-upload-' + agreementId).click();
}
jQuery('#toggle-dropdown').on('click', function() {
jQuery('#dropdown').toggle();
});
var table = $('#agreement-table').DataTable({
"scrollX": true,
// "searching": true, // Enable search functionality
"ordering": true, // Enable sorting functionality
"paging": true, // Enable pagination
"lengthChange": true, // Disable page length dropdown
"pageLength": 10, // Default number of rows per page
"columnDefs": [
{
"targets": [1], // Target the "Name" column (index 1)
// "searchable": true // Make only the "Name" column searchable
}
]
});
function exportTableToCSV(filename) {
var csv = [];
var rows = document.querySelectorAll("#agreement-table tbody tr");
// Get table headers (column names)
var headers = [];
var headerCols = document.querySelectorAll("#agreement-table thead th");
for (var k = 0; k < headerCols.length; k++) {
headers.push(`"${headerCols[k].innerText.replace(/"/g, '""')}"`); // Wrap headers in quotes and escape inner quotes
}
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");
for (var j = 0; j < cols.length; j++) {
row.push(`"${cols[j].innerText.replace(/"/g, '""')}"`); // Wrap cell content in quotes and escape inner quotes
}
csv.push(row.join(",")); // Join row values with a comma
}
// Create a timestamp for the filename
var date = new Date();
var timestamp = date.toISOString().slice(0, 19).replace("T", "_").replace(/:/g, "-"); // Format: YYYY-MM-DD_HH-MM-SS
// Add timestamp to filename if needed
var fullFilename = `Agreement__${timestamp}.csv`;
// Trigger CSV download
downloadCSV(csv.join("\n"), fullFilename);
}
// Function to download CSV file
function downloadCSV(csv, filename) {
var csvFile;
var downloadLink;
// Create a Blob from the CSV data
csvFile = new Blob([csv], { type: "text/csv" });
// Create a download link for the file
downloadLink = document.createElement("a");
// Set the file name for download
downloadLink.download = filename;
// Create a URL for the Blob and assign it to the download link
downloadLink.href = window.URL.createObjectURL(csvFile);
// Hide the download link from the page
downloadLink.style.display = "none";
// Append the download link to the document body
document.body.appendChild(downloadLink);
// Simulate a click on the download link to trigger the download
downloadLink.click();
// Remove the download link from the document body after download
document.body.removeChild(downloadLink);
}
// Attach event listener to the export button
document.getElementById("exportbutton").addEventListener("click", function() {
exportTableToCSV("agreement-table.csv");
});
</script>
<script>
// Wait until the page is fully loaded
window.onload = function() {
// Check if 'upload_success=1' is in the URL
if (window.location.search.includes('upload_success=1')) {
// Create a success message div
var successMessage = document.createElement('div');
successMessage.className = 'notice notice-success is-dismissible';
successMessage.innerHTML = '<p>PDF uploaded successfully.</p>';
// Add a top margin to the message
successMessage.style.marginTop = '40px';
successMessage.style.marginBottom = '-20px';
// Insert the success message at the top of the content
var wrapDiv = document.querySelector('.wrap');
wrapDiv.parentNode.insertBefore(successMessage, wrapDiv);
// Redirect to 'admin.php?page=agreement' after removing the query parameter
const newUrl = '<?php echo admin_url("admin.php?page=agreement"); ?>';
window.history.replaceState({}, document.title, newUrl);
}
};
</script>
<?php
if (isset($_POST['save_columns'])) {
$selected_columns = isset($_POST['columns']) ? $_POST['columns'] : [];
update_user_meta($user_id, 'agreement_visible_columns', implode(',', $selected_columns));
echo '<script>location.reload();</script>';
}
}
// File Upload Handler in Plugin
add_action('admin_init', 'handle_pdf_upload');
function handle_pdf_upload() {
if (isset($_FILES['pdf_file']) && !empty($_FILES['pdf_file']['name'])) {
global $wpdb;
// Get the agreement ID from the form
$agreement_id = intval($_POST['upload_agreement_id']);
// Handle file upload
$uploaded_file = $_FILES['pdf_file'];
$upload_dir = wp_upload_dir(); // Get WordPress upload directory
// Define upload directory inside 'uploads/pdfupload'
$pdf_upload_dir = $upload_dir['basedir'] . '/pdfupload';
// Create the directory if it doesn't exist
if (!file_exists($pdf_upload_dir)) {
wp_mkdir_p($pdf_upload_dir);
}
// Get file extension and validate
$file_ext = pathinfo($uploaded_file['name'], PATHINFO_EXTENSION);
if (strtolower($file_ext) !== 'pdf') {
echo '<div class="notice notice-error is-dismissible"><p>Only PDF files are allowed for upload.</p></div>';
return;
}
// Generate a unique file name
$file_name = 'agreement_' . $agreement_id . '_' . time() . '.' . $file_ext;
$file_path = $pdf_upload_dir . '/' . $file_name;
// Move the uploaded file to the pdfupload directory
if (move_uploaded_file($uploaded_file['tmp_name'], $file_path)) {
// File URL to store in the database
$file_url = $upload_dir['baseurl'] . '/pdfupload/' . $file_name;
// Update the wp_agreement table
$wpdb->update(
'wp_agreement', // Table name
array(
'upload_pdf' => $file_url, // Set the file URL in the column
'status' => 'PDF Uploaded' // Update the status
),
array('agreement_id' => $agreement_id) // Where condition
);
// Redirect to the same page with a success query parameter
wp_redirect(add_query_arg('upload_success', '1', $_SERVER['REQUEST_URI']));
exit;
} else {
echo '<div class="notice notice-error is-dismissible"><p>Failed to upload PDF. Please try again.</p></div>';
}
}
}
// function processHtmlForWord($html) {
// $dom = new DOMDocument();
// @$dom->loadHTML('<?xml encoding="UTF-8"><div>' . $html . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
// $result = '';
// $nodes = $dom->getElementsByTagName('div')->item(0)->childNodes;
// foreach ($nodes as $node) {
// if ($node->nodeType === XML_TEXT_NODE) {
// // Preserve text with spaces and add line breaks for new paragraphs
// $text = trim($node->textContent);
// if (!empty($text)) {
// $result .= htmlspecialchars($text, ENT_QUOTES | ENT_XML1, 'UTF-8') . '<w:br/>';
// }
// } elseif ($node->nodeType === XML_ELEMENT_NODE && $node->tagName === 'br') {
// $result .= '<w:br/>';
// }
// }
// // Remove the last <w:br/> if it exists to avoid extra line break at the end
// $result = rtrim($result, '<w:br/>');
// return $result ?: '';
// }
// Generate and download Word file manually
function agreement_download_word($agreement_id) {
global $wpdb;
// Fetch the agreement and corresponding quotation data
$agreement = $wpdb->get_row($wpdb->prepare("
SELECT
a.agreement_id, /* Include agreement_id */
a.sales_rep,
a.ag_created_at, /* Use the renamed ag_created_at */
q.*
FROM " . AGREEMENT_TABLE . " a
LEFT JOIN " . $wpdb->prefix . "quotation q ON a.qt_id = q.id
WHERE a.agreement_id = %d",
$agreement_id
));
// Dynamic Linking --- Bhaskara
$qt_id = $wpdb->get_var($wpdb->prepare(
"SELECT qt_id FROM {$wpdb->prefix}agreement WHERE agreement_id = %d",
$agreement_id
));
// Log the qt_id for debugging
error_log("Qt_id: " . var_export($qt_id, true));
$security_terms = '';
$shipping_terms = '';
$billing_terms = '';
$payment_terms = '';
$additional_terms = '';
$standard_terms = '';
if ($qt_id) {
$quotation = $wpdb->get_row($wpdb->prepare(
"SELECT dynamic_terms_1, dynamic_terms_2, standard_terms FROM {$wpdb->prefix}quotation WHERE id = %d",
$qt_id
));
error_log("Quotation: " . var_export($quotation, true));
if ($quotation) {
// Handle dynamic_terms_2 (clear text)
$additional_terms_raw = $quotation->dynamic_terms_2 ?? '';
$dom = new DOMDocument();
@$dom->loadHTML('<?xml encoding="UTF-8"><div>' . $additional_terms_raw . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$additional_terms = trim($dom->textContent);
// Handle standard_terms (single ID)
if (!empty($quotation->standard_terms)) {
$standard_terms_id = intval($quotation->standard_terms);
$standard_result = $wpdb->get_row($wpdb->prepare(
"SELECT termscondition FROM {$wpdb->prefix}termscondition WHERE id = %d",
$standard_terms_id
));
if ($standard_result) {
$standard_terms_raw = $standard_result->termscondition ?? '';
// $standard_terms = strip_tags($standard_terms_raw);
$dom = new DOMDocument();
@$dom->loadHTML('<?xml encoding="UTF-8"><div>' . $standard_terms_raw . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$standard_terms = trim($dom->textContent);
// $standard_terms = processHtmlForWord($standard_terms_raw);
}
}
// Handle dynamic_terms_1 (multiple IDs)
if (!empty($quotation->dynamic_terms_1)) {
$term_ids = array_map('intval', explode(',', $quotation->dynamic_terms_1));
$valid_ids = array_slice($term_ids, 0, 4);
$placeholders = implode(',', array_fill(0, count($valid_ids), '%d'));
$query = $wpdb->prepare(
"SELECT id, termscondition FROM {$wpdb->prefix}termscondition WHERE id IN ($placeholders)",
...$valid_ids
);
$results = $wpdb->get_results($query);
$terms_map = [];
foreach ($results as $row) {
$dom = new DOMDocument();
@$dom->loadHTML('<?xml encoding="UTF-8"><div>' . $row->termscondition . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$terms_map[$row->id] = trim($dom->textContent);
}
$security_terms = $terms_map[$valid_ids[0]] ?? '';
$shipping_terms = $terms_map[$valid_ids[1]] ?? '';
$billing_terms = $terms_map[$valid_ids[2]] ?? '';
$payment_terms = $terms_map[$valid_ids[3]] ?? '';
}
}
}
$dynamic_terms_content = '
<w:p>
<w:pPr><w:spacing w:before="200"/></w:pPr>
<w:r><w:rPr><w:b/></w:rPr><w:t>12.A. Security Terms</w:t></w:r>
</w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($security_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p><w:pPr><w:spacing w:before="200"/></w:pPr><w:r><w:rPr><w:b/></w:rPr><w:t>12.B. Shipping Terms</w:t></w:r></w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($shipping_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p><w:pPr><w:spacing w:before="200"/></w:pPr><w:r><w:rPr><w:b/></w:rPr><w:t>12.C. Billing Terms</w:t></w:r></w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($billing_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p><w:pPr><w:spacing w:before="200"/></w:pPr><w:r><w:rPr><w:b/></w:rPr><w:t>12.D. Payment Terms</w:t></w:r></w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($payment_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p><w:pPr><w:spacing w:before="200"/></w:pPr><w:r><w:rPr><w:b/></w:rPr><w:t>12.E. Additional Terms</w:t></w:r></w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($additional_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p><w:pPr><w:spacing w:before="200"/></w:pPr><w:r><w:rPr><w:b/></w:rPr><w:t>12.F. Standard Terms</w:t></w:r></w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($standard_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>';
//--- end ---
$user_first_name = $wpdb->get_var($wpdb->prepare("
SELECT meta_value
FROM " . $wpdb->prefix . "usermeta
WHERE user_id = %d AND meta_key = 'billing_first_name'",
$agreement->user_id
));
// Get GST Number
$gst_number = $wpdb->get_var(
$wpdb->prepare("
SELECT meta_value
FROM {$wpdb->prefix}usermeta
WHERE user_id = %d AND meta_key = 'gst_number'",
$agreement->user_id
)
);
// Get PAN
$reg_pan = $wpdb->get_var(
$wpdb->prepare("
SELECT meta_value
FROM {$wpdb->prefix}usermeta
WHERE user_id = %d AND meta_key = 'reg_pan'",
$agreement->user_id
)
);
// // Dynamic Linking --- Bhaskara
// $qt_id = $wpdb->get_var($wpdb->prepare(
// "SELECT qt_id FROM agreement WHERE agreement_id = %d", // Changed %s to %d for integer
// $agreement_id
// ));
// // Initialize variables
// $security_terms = '';
// $shipping_terms = '';
// $billing_terms = '';
// $payment_terms = '';
// $additional_terms = '';
// $standard_terms = '';
// if ($qt_id) {
// $quotation = $wpdb->get_row($wpdb->prepare(
// "SELECT dynamic_terms_1, dynamic_terms_2, standard_terms FROM {$wpdb->prefix}quotation WHERE id = %d",
// $qt_id
// ));
// if ($quotation) {
// // Handle dynamic_terms_2 (clear text)
// $additional_terms = htmlspecialchars(strip_tags($quotation->dynamic_terms_2 ?? ''), ENT_QUOTES | ENT_XML1, 'UTF-8');
// // Handle standard_terms (single ID)
// if (!empty($quotation->standard_terms)) {
// $standard_terms_id = intval($quotation->standard_terms); // Ensure it's a single integer
// $standard_result = $wpdb->get_row($wpdb->prepare(
// "SELECT termscondition FROM {$wpdb->prefix}termscondition WHERE id = %d",
// $standard_terms_id
// ));
// if ($standard_result) {
// $standard_terms = htmlspecialchars(strip_tags($standard_result->termscondition ?? ''), ENT_QUOTES | ENT_XML1, 'UTF-8');
// }
// }
// // Handle dynamic_terms_1 (multiple IDs)
// if (!empty($quotation->dynamic_terms_1)) {
// $term_ids = array_map('intval', explode(',', $quotation->dynamic_terms_1));
// $valid_ids = array_slice($term_ids, 0, 4);
// $placeholders = implode(',', array_fill(0, count($valid_ids), '%d'));
// $query = $wpdb->prepare(
// "SELECT id, termscondition FROM {$wpdb->prefix}termscondition WHERE id IN ($placeholders)",
// ...$valid_ids
// );
// $results = $wpdb->get_results($query);
// $terms_map = [];
// foreach ($results as $row) {
// $terms_map[$row->id] = strip_tags($row->termscondition); // Extract text content
// }
// $security_terms = htmlspecialchars($terms_map[$valid_ids[0]] ?? '', ENT_QUOTES | ENT_XML1, 'UTF-8');
// $shipping_terms = htmlspecialchars($terms_map[$valid_ids[1]] ?? '', ENT_QUOTES | ENT_XML1, 'UTF-8');
// $billing_terms = htmlspecialchars($terms_map[$valid_ids[2]] ?? '', ENT_QUOTES | ENT_XML1, 'UTF-8');
// $payment_terms = htmlspecialchars($terms_map[$valid_ids[3]] ?? '', ENT_QUOTES | ENT_XML1, 'UTF-8');
// }
// }
// }
// //--- end ---
// Fetch the user's last name (assuming it's stored in wp_usermeta)
$user_last_name = $wpdb->get_var($wpdb->prepare("
SELECT meta_value
FROM " . $wpdb->prefix . "usermeta
WHERE user_id = %d AND meta_key = 'billing_last_name'",
$agreement->user_id
));
// Combine first name and last name to create full username
$user_name = trim($user_first_name . ' ' . $user_last_name);
// Fetch the user's billing address
$user_billing_address = $wpdb->get_var($wpdb->prepare("
SELECT meta_value
FROM " . $wpdb->prefix . "usermeta
WHERE user_id = %d AND meta_key = 'billing_address_1'",
$agreement->user_id
));
// Fetch the user's Shipping address
$user_shipping_address = $wpdb->get_var($wpdb->prepare("
SELECT meta_value
FROM " . $wpdb->prefix . "usermeta
WHERE user_id = %d AND meta_key = 'shipping_address_1'",
$agreement->user_id
));
// If you need to format the billing address with new lines
$formatted_billing_address = $user_billing_address ? nl2br(esc_html($user_billing_address)) : null;
$formatted_shipping_address = $user_billing_address ? nl2br(esc_html($user_shipping_address)) : null;
$creation_date = date('d-m-Y', strtotime($agreement->ag_created_at));
// Get GST Number
$gst_number = $wpdb->get_var(
$wpdb->prepare("
SELECT meta_value
FROM {$wpdb->prefix}usermeta
WHERE user_id = %d AND meta_key = 'gst_number'",
$agreement->user_id
)
);
// Get PAN
$reg_pan = $wpdb->get_var(
$wpdb->prepare("
SELECT meta_value
FROM {$wpdb->prefix}usermeta
WHERE user_id = %d AND meta_key = 'reg_pan'",
$agreement->user_id
)
);
if ($agreement) {
// Set the headers to download the file as a .docx
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=agreement-{$agreement->user_name}.docx");
header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
header("Cache-Control: must-revalidate");
header("Pragma: public");
// Create simple Word (docx) content in XML format
$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:pPr>
<w:jc w:val="center"/> <!-- Aligns text to center -->
</w:pPr>
<w:r>
<w:rPr>
<w:b/> <!-- Bold -->
<w:u w:val="single"/> <!-- Underline -->
<w:sz w:val="28"/> <!-- Font size: 14pt (equivalent to 28px) -->
</w:rPr>
<w:t>AGREEMENT FOR HIRE</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>This Agreement is made at Chennai on this '.$creation_date.' </w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>BETWEEN</w:t>
</w:r>
</w:p>
<w:p><w:r><w:t>M/s GMMCO LTD. a Company registered under the Companies Act and having its registered office at 9/1 R N Mukherjee Road Kolkatta – 700 001 and its head office at No 6 GST Road ST Thomas Mount Chennai – 600 016 & branch office at No. 906 Murunkancheery Village Aranvayal Panchayath Tiruvallur Taluk Tiruvallur District 602025 hereinafter referred to as GMMCO which expression shall unless repugnant to context mean and include their assigns and successors in interest</w:t></w:r></w:p>
<w:p>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>AND</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t>'.$user_name.',</w:t>
<w:br />
<w:t>'.$formatted_billing_address.'</w:t>
</w:r>
</w:p>
<w:p><w:r><w:t>GSTIN: ' .$gst_number. '</w:t></w:r></w:p>
<w:p><w:r><w:t>PAN NO: ' .$reg_pan. '</w:t></w:r></w:p>
<w:p><w:r><w:t>hereinafter referred to as ‘ The Hirer, which expression shall unless repugnant to context mean and include their assigns and successors in interest. </w:t></w:r></w:p>
<w:p><w:r><w:t>WHEREAS GMMCO is inter alia engaged in the business of hiring out earth moving machineries Diesel Generator sets Allied equipments etc.</w:t></w:r></w:p>
<w:p><w:r><w:t>WHEREAS the Hirer is engaged in the business of construction /mining activities and has expressed its intention to take on hire the machine more fully described in Clause 1 hereunder and hereinafter referred to as “the Equipment” and GMMCO has agreed to give on hire the Equipment on the terms and conditions set out hereunder.</w:t></w:r></w:p>
<w:p><w:r><w:t>NOW THEREFORE THIS DEED WITNESSES AS HEREUNDER:</w:t></w:r></w:p>
<w:tbl>
<w:tblPr>
<w:tblW w:w="5000" w:type="pct"/> <!-- Adjusts table width to 50% -->
<w:tblBorders>
<w:top w:val="single" w:sz="4" w:space="0" w:color="000000"/>
<w:left w:val="single" w:sz="4" w:space="0" w:color="000000"/>
<w:bottom w:val="single" w:sz="4" w:space="0" w:color="000000"/>
<w:right w:val="single" w:sz="4" w:space="0" w:color="000000"/>
<w:insideH w:val="single" w:sz="4" w:space="0" w:color="000000"/>
<w:insideV w:val="single" w:sz="4" w:space="0" w:color="000000"/>
</w:tblBorders>
</w:tblPr>
<w:tr> <!-- Row 1 (Headers) -->
<w:tc>
<w:tcPr><w:tcW w:w="1000" w:type="dxa"/></w:tcPr>
<w:p>
<w:r>
<w:rPr><w:b/></w:rPr> <!-- Bold formatting -->
<w:t>Sl. no</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr><w:tcW w:w="2000" w:type="dxa"/></w:tcPr>
<w:p>
<w:r>
<w:rPr><w:b/></w:rPr> <!-- Bold formatting -->
<w:t>Equipment Model</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr><w:tcW w:w="2000" w:type="dxa"/></w:tcPr>
<w:p>
<w:r>
<w:rPr><w:b/></w:rPr> <!-- Bold formatting -->
<w:t>Equipment Serial No</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr><w:tcW w:w="2000" w:type="dxa"/></w:tcPr>
<w:p>
<w:r>
<w:rPr><w:b/></w:rPr> <!-- Bold formatting -->
<w:t>Period of Hire/Min hours</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr> <!-- Row 2 (Data) -->
<w:tc>
<w:tcPr><w:tcW w:w="1000" w:type="dxa"/></w:tcPr>
<w:p><w:r><w:t>01</w:t></w:r></w:p>
</w:tc>
<w:tc>
<w:tcPr><w:tcW w:w="2000" w:type="dxa"/></w:tcPr>
<w:p><w:r><w:t>'.$agreement->product_name.'</w:t></w:r></w:p>
</w:tc>
<w:tc>
<w:tcPr><w:tcW w:w="2000" w:type="dxa"/></w:tcPr>
<w:p><w:r><w:t></w:t></w:r></w:p>
</w:tc>
<w:tc>
<w:tcPr><w:tcW w:w="2000" w:type="dxa"/></w:tcPr>
<w:p><w:r><w:t></w:t></w:r></w:p>
</w:tc>
</w:tr>
</w:tbl>
<w:p>
<w:r>
<w:rPr>
<w:b />
</w:rPr>
<w:t>Requirement – 3 Nos.</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>2. Period</w:t>
</w:r>
</w:p>
<w:p><w:r><w:t>2.1 The period of hire as mentioned above from the date of commencing.</w:t></w:r></w:p>
<w:p><w:r><w:t>2.2 Agreement can be extended with written consent of GMMCO at mutually agreed terms & conditions.</w:t></w:r></w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>3. Hire Charges</w:t>
</w:r>
</w:p>
<w:p><w:r><w:t>3.1 The monthly fixed hire charges for the above mentioned machine will be Rs ----./- (Rupees -------) for a minimum billable period of --- hours (Minimum Billing Hours) of 26 working days in calendar month.</w:t></w:r></w:p>
<w:p><w:r><w:t>3.2 The Hirer will pay @ Pro-rata charges (Rs.---/-) for every additional hour used beyond the minimum billable period of --- hours per month.</w:t></w:r></w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>4. Taxes & Duties</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>4.1 PAN number of the Hirer is -----.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>4.2 GSTIN number of the Hirer is -------.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>4.3 The GSTIN No of GMMCO is 33AABCG0949C1Z4.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>4.4 GST @ 18% will be charged extra on invoice value.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>4.5 Compensation cess, if any applicable or imposed at a later date by the Government, will be charged separately on monthly invoice value and will be payable by the Hirer.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>4.6 Any other taxes, duties, or levies if applicable in addition to the above will be borne by the Hirer extra at actuals.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>4.7 If the Hirer is liable to deduct the TDS at the time of payment against the invoice, the Hirer will issue TDS Certificate at the end of each quarter and immediately in case of closure of the agreement.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>5. Security Deposit</w:t>
</w:r>
</w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($security_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>5.2 GMMCO will despatch and commission the equipment to the Hirer only on receipt of the Security Deposit as above.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>5.3 The Security Deposit shall not carry any interest and will be refunded only after all dues to GMMCO are fully settled by the Hirer.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>6. Transportation</w:t>
</w:r>
</w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($shipping_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>6.2 If GMMCO arranges for the transportation of the Equipment on behalf of the Hirer to and from the Customers site at the beginning or end of the contract period, the cost of transportation at actual will be paid by the Hirer to the Transporter directly.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>6.3 The transit insurance will be GMMCOs responsibility.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>7. Delivery & Commissioning</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>7.1 GMMCO will despatch the machine on receipt of the duly signed agreement along with the Security Deposit.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>7.2 GMMCO will arrange for commissioning of the Machines free of cost. The Hirer will provide the necessary semi skilled labour and the crane for loading and unloading the equipment at the site.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>8. Operators</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>8.1 Based on Hirers request, GMMCO will provide one skilled operator for single shift operation of the Equipment at the site. For an additional operator, the Hirer needs to pay Rs ---- extra per operator per month.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>8.2 The Hirer shall provide accommodation and food for the operators provided by GMMCO.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>8.3 The Hirer shall not make any payment to GMMCO operators without written consent of GMMCO other than food and travel expenses as per clause 8.2.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>9. Fuel</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>9.1 Uncontaminated High Speed Diesel required for the operation of the equipment shall be provided at the site by the Hirer at his costs.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>9.2 GMMCO shall not be responsible for pilferage of fuel if any.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>10. Maintenance & Repairs</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>10.1 </w:t></w:r>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t> Teeth Point, Adaptor and Bucket maintenance will be customer scope.</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>The routine maintenance and repairs of the equipment will be carried out by GMMCO personnel by providing the necessary parts and lubricating oil as may be required.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>10.2 Hirer shall not issue any spare parts lubricants consumables without written consent of GMMCO.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>10.3 The Hirer shall spare the equipment for carrying out routine maintenance without delay.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>10.4 GMMCO will arrange for the necessary spare parts as may be required for carrying out the repairs and maintenance subject to proper operation of the equipment.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>10.5 The Hirer agrees to provide unskilled labour as and when required for maintenance of the Equipment at their own costs.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>10.6 Any repairs on account of use of contaminated fuel or misuse abuse of the equipment will be borne by the Hirer. The decision of GMMCO on whether the repairs are on account of fuel contamination or misuse abuse will be final and binding on the Hirer.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>11. Invoicing</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>11.1 The hire charges is payable from the date of commissioning of the equipment at the Hirers site or three days from the date of delivery of the Machine at site whichever is earlier. The billing cycle will be calendar month.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>11.2 Final billable hours for invoicing during the month will be the minimum billable hours or actual working hours whichever is higher.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>11.3 In case the deployment is for partial month then invoicing will be done on pro rata basis of minimum billable hours or actual worked days whichever is higher.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>11.4 Both the parties will sign the log sheets on daily basis certifying the working hours of the equipment and breakdown hours if any. The mutually agreed breakdown hours for deductions will be reduced from the final billable hours.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>11.5 The Hirer shall be entitled to make deductions in log sheet on number of hours utilized for Machine breakdown beyond one hour at a stretch. However, the Hirer will cooperate to make up for the breakdown hours by working extra hours.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>11.6 The log sheet shall be reconciled and signed by both parties on fortnightly basis and shall be binding on both parties.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>11.7 The Hirer and GMMCO will nominate their respective authorised representatives to sign the log sheet which shall be binding on both the parties.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>11.8 If the total number of hours utilized during a month exceeds minimum billable hours then no deduction towards breakdown shall be made.</w:t></w:r>
</w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($billing_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($payment_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p><w:pPr><w:spacing w:before="200"/></w:pPr><w:r><w:rPr><w:b/></w:rPr><w:t>11.9. Additional Terms</w:t></w:r></w:p>
<w:p><w:r><w:t xml:space="preserve">' . htmlspecialchars($additional_terms, ENT_QUOTES | ENT_XML1, 'UTF-8') . '</w:t></w:r></w:p>
<w:p><w:pPr><w:spacing w:before="200"/></w:pPr><w:r><w:rPr><w:b/></w:rPr><w:t>12. Security Terms</w:t></w:r></w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>12.1 The hire charges shall be paid by the Hirer within 5 to 8 days from the date of invoice through RTGS through Virtual Bank Account details given by GMMCO.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>12.2 The Hirer shall be liable to pay interest at 24 percent per annum for any delay in payment of hire charges beyond the stipulated period.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>12.3 GMMCO has all rights to stop or withdraw the machine from Hirers site if the payment is delayed beyond 10 days from the date of invoice.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>13. Hirer’s Covenants</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>The Hirer covenants with GMMCO that</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>13.1 He will use the equipment only for the purpose it is hired and shall not misuse or abuse the equipment or use the Equipment for any unlawful or illegal purposes.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>13.2 He will not remove the equipment from the site without the written consent of GMMCO.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>13.3 He will ensure the safe custody of the equipment by providing necessary security, parking bay, etc, and will be liable for any loss or damage or destruction to the machine at prevailing prices, taxes, freight, etc.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>13.4 The Hirer shall not make any alterations, additions or improvements to the Equipment or allow any unauthorised person to operate the Equipment.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>13.5 The Hirer shall be solely responsible and liable to handle any dispute entered with any third party in relation to the use and operation of Equipment.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>13.6 The Hirer recognises GMMCOs right to inspect the Equipment at any time during the tenure of this agreement. The Hirer shall provide free access and facilities to the GMMCOs personnel to enable them to inspect the equipment at any time.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>14. Title & Ownership</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>The Hirer confirms and agrees that the Equipment is offered by GMMCO LIMITED only on "right to use" basis and acknowledges the title and ownership of GMMCO LIMITED of the equipment and he shall not at any time claim any proprietary rights, title or interest in the Equipment.</w:t></w:r>
</w:p>
<w:p>
<w:r><w:t>The Hirer shall not sell, assign, hypothecate, mortgage, create any charge, lien or any other encumbrance on the equipment. The ownership of the equipment will continue to remain unaffected during the pendency of the agreement and the Hirer shall be considered as the bailee thereof with all duties and obligations of a bailee in law.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>15. Damages</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>Any damage to the equipment occurring in the Hirers premises or site due to misuse or abuse by the Hirer, mishandling by the Hirers personnel, theft, acts of vandalism will be completely compensated by the Hirer and during such period of breakdown the equipment will be considered as working and will be charged accordingly.</w:t></w:r>
</w:p>
<w:p>
<w:r><w:t>GMMCO shall not be liable for any damage to any property of the Hirer during the course of normal operation of the equipment.</w:t></w:r>
</w:p>
<w:p>
<w:r><w:t>GMMCO is also not liable to any losses or damages or consequential damages or losses for any reasons during the pendency of contract.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>16. Termination</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>16.1 Either side can terminate the agreement by giving 30 days advance notice.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>16.2 This agreement can be terminated by GMMCO without any notice if the Hirer does not make full payment of the hire charges within 15 days from the date of invoice or if the Hirer otherwise breaches any of the terms of this agreement. This right of GMMCO will be without prejudice to its rights to claim penal interest and damages that may be reasonably suffered by it on account of the Hirers default in making the payments, including the costs and expenses of transporting the equipment machine back to GMMCOs yard as well as fees for enforcement of GMMCOs rights.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>16.3 The Hirer will be liable to pay one months hire charges in lieu of notice if he terminates the agreement without giving prior notice as required under clause 16.1 above.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>16.4 On termination of the agreement, GMMCO shall be entitled but without prejudice to any previously accrued rights or remedies GMMCO may have under this agreement or otherwise at law and to exercise all or any of the following rights or remedies, namely:</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>(a) To remove and retake the possession of the Equipment and for that purpose by itself, its servants or agents to enter upon any land or premises where the Equipment is or is reasonably believed by GMMCO to be for the time being situated and detach and dismantle the Equipment.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>(b) Recover from the Hirer the arrears of the monthly hire charges and monthly hire charges for the unexpired residue of the term of this agreement together with all other sums payable by the Hirer including other expenses incurred by GMMCO in connection with the termination.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>17. Arbitration & Jurisdiction</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>The parties shall endeavour to settle all disputes through negotiations, failing which the dispute will be referred to arbitration of a Sole Arbitrator to be nominated by GMMCO. The venue of arbitration shall be at </w:t></w:r>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>Chennai</w:t>
</w:r>
<w:r><w:t> and the arbitration shall be governed by the provisions of the Arbitration and Conciliation Act 1996.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>18. Anti- Corruption:</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>Further, the Hirer shall not (a) offer or agree to give any person working for or engaged by GMMCO any gift or other consideration, which could act as an inducement or a reward for any act or failure to act connected to this Agreement, including its award to the Hirer and any of the rights and obligations contained within it; nor (b) enter into this agreement if it has knowledge that, in connection with it, any money has been or will be paid to any person working for or engaged by GMMCO by or for the Hirer.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>If the Hirer (including any of its employees, sub-contractors, or agents) breaches (a) this clause or (b) any anti-corruption and bribery legislation, laws, or regulations in relation to this Agreement, GMMCO may terminate this Agreement without liability to the Hirer, by written notice with immediate effect. The Hirers liability under or in connection with this clause shall be unlimited.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>The Hirer shall provide a self certificate that they are duly complying with the provisions under anti-corruption laws in the following manner:</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>“I on behalf of the Hirer certify that to the best of my knowledge, upon adequate investigation and diligence, the Hirer is and has been in compliance with all applicable anti-bribery and anti-corruption laws, including but not limited to national, state and local laws, rules, regulations, directives or statutes regarding anti-bribery and anti-corruption. I further certify that I am a duly authorized representative of the Hirer and have the authority to act for the Hirer and bind the same.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>19. Waiver:</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>Failure of any of the parties to require performance of any provision of this agreement shall not affect such partys right to full performance thereof at any time thereafter, and any waiver by any of the parties of a breach of any provision hereof shall not constitute a waiver of a similar breach in the future or any other breach. No waiver shall be effective unless in writing and duly executed by an authorised representative of the concerned party.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>20. Merger and Integration:</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>This agreement contains the entire agreement of the parties with respect to the subject matter of the agreement. The agreement of hire supersedes any prior agreements, understandings, or negotiations, whether written or oral. This agreement can only be amended through a written document formally executed by all parties.</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>Site Address :</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>'.$user_name.',</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r> <w:t>'.$formatted_shipping_address.'</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>GSTIN: ' .$gst_number. '</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>PAN NO: ' .$reg_pan. '</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="200"/> <!-- Adds space before the heading -->
</w:pPr>
<w:r>
<w:rPr><w:b/></w:rPr>
<w:t>Billing Address :</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>'.$user_name.',</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r> <w:t>'.$formatted_billing_address.'</w:t></w:r>
</w:p>
<w:p>
<w:r><w:t>GSTIN: ' .$gst_number. '</w:t></w:r>
</w:p>
<w:p>
<w:pPr>
<w:spacing w:before="0" w:after="0"/>
</w:pPr>
<w:r><w:t>PAN NO: ' .$reg_pan. '</w:t></w:r>
</w:p>
<w:p>
<w:r><w:t>Our site team contact details:</w:t></w:r>
</w:p>
<w:p>
<w:r><w:t>For Site Engineers:</w:t></w:r>
</w:p>
<w:p><w:r><w:t>IN WITNESS WHEREOF the parties have signed these presents on the date month and year first above mentioned.</w:t></w:r></w:p>
<w:p><w:r><w:t>For GMMCO LIMITED. For '.$user_name.'</w:t></w:r></w:p>
<w:p><w:r><w:t>Signature: Signature:</w:t></w:r></w:p>
<w:p><w:r><w:t>Name: Name: </w:t></w:r></w:p>
<w:p><w:r><w:t>Designation: Designation: </w:t></w:r></w:p>
</w:body>
</w:document>';
// Create the ZIP structure for the DOCX file
$zip = new ZipArchive();
$tmp_file = tempnam(sys_get_temp_dir(), 'docx');
$zip->open($tmp_file, ZipArchive::CREATE);
// Add the Word content to the document
$zip->addFromString("word/document.xml", $content);
// Add the required DOCX files/folders (minimal set)
$zip->addFromString("[Content_Types].xml", '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="xml" ContentType="application/xml"/>
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="jpeg" ContentType="image/jpeg"/>
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
</Types>');
$zip->addFromString("_rels/.rels", '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
</Relationships>');
$zip->addEmptyDir("word/_rels");
$zip->addFromString("word/_rels/document.xml.rels", '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
</Relationships>');
// Close the ZIP file and output it
$zip->close();
readfile($tmp_file);
// Clean up
unlink($tmp_file);
exit;
}
}
// Handle the Word download action
if (isset($_POST['download_word']) && isset($_POST['download_agreement_id'])) {
agreement_download_word($_POST['download_agreement_id']);
}
// Create order
function create_woocommerce_order($agreement, $rfq_order_id) {
global $wpdb;
// Get user data
$user_id = $agreement->user_id;
$user = get_userdata($user_id);
if (!$user) {
echo "<script>alert('User not found.');</script>";
return;
}
// Fetch the billing and shipping information from the user meta
$billing_first_name = get_user_meta($user_id, 'billing_first_name', true);
$billing_last_name = get_user_meta($user_id, 'billing_last_name', 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_postcode = get_user_meta($user_id, 'billing_postcode', true);
$billing_country = get_user_meta($user_id, 'billing_country', true);
$billing_state = get_user_meta($user_id, 'billing_state', true);
$billing_email = get_user_meta($user_id, 'billing_email', true);
$billing_phone = get_user_meta($user_id, 'billing_phone', true);
$shipping_first_name = get_user_meta($user_id, 'shipping_first_name', true);
$shipping_last_name = get_user_meta($user_id, 'shipping_last_name', true);
$shipping_address_1 = get_user_meta($user_id, 'shipping_address_1', true);
$shipping_address_2 = get_user_meta($user_id, 'shipping_address_2', true);
$shipping_city = get_user_meta($user_id, 'shipping_city', true);
$shipping_postcode = get_user_meta($user_id, 'shipping_postcode', true);
$shipping_country = get_user_meta($user_id, 'shipping_country', true);
$shipping_state = get_user_meta($user_id, 'shipping_state', true);
if($rfq_order_id){
$order = wc_get_order($rfq_order_id);
// Set order total based on the agreement's final price
if ($agreement->final_price) {
$order->set_total($agreement->final_price);
}
// Set custom meta fields from agreement
$order->update_meta_data('assign_location_id', $agreement->assign_location_id);
$order->update_meta_data('model_name', $agreement->product_name);
$order->update_meta_data('agreement_id', $agreement->agreement_id);
$order->update_meta_data('start_date', $agreement->start_date);
$order->update_meta_data('end_date', $agreement->end_date);
$order->update_meta_data('_number_shifts_required', $agreement->shift); // Assuming 'shift' column corresponds to number of shifts
$order->update_meta_data('rental_amount', $agreement->final_price);
$order->update_meta_data('order_location', $agreement->location);
$order->update_meta_data('order_region', $agreement->region);
$order->set_status('pending', 'Order initially set to processing for email workflow.');
// Save the order
$order->save();
$order_id = $order->get_id();
// Update the ag_status in the wp_agreement table to "Order Created"
$wpdb->update(
'wp_agreement', // Table name
array('status' => 'Order Created'), // Data to update
array('agreement_id' => $agreement->agreement_id) // Where clause (agreement_id matches)
);
// Redirect to the WooCommerce order edit page
$redirect_url = admin_url('post.php?post=' . $order_id . '&action=edit');
// Output JavaScript to show an alert and redirect
echo "<script>
alert('Contract Updated Successfully.');
window.location.href = '{$redirect_url}';
</script>";
exit; // Stop further execution to ensure redirection
}
else {
// Create a new WooCommerce order without adding a product
$order = wc_create_order();
// Set billing details
$order->set_address(array(
'first_name' => $billing_first_name,
'last_name' => $billing_last_name,
'address_1' => $billing_address_1,
'address_2' => $billing_address_2,
'city' => $billing_city,
'postcode' => $billing_postcode,
'country' => $billing_country,
'state' => $billing_state,
'email' => $billing_email,
'phone' => $billing_phone,
), 'billing');
// Set shipping details
$order->set_address(array(
'first_name' => $shipping_first_name,
'last_name' => $shipping_last_name,
'address_1' => $shipping_address_1,
'address_2' => $shipping_address_2,
'city' => $shipping_city,
'postcode' => $shipping_postcode,
'country' => $shipping_country,
'state' => $shipping_state,
), 'shipping');
// Set customer ID if available
$order->set_customer_id($user_id);
// Set order total based on the agreement's final price
if ($agreement->final_price) {
$order->set_total($agreement->final_price);
}
// Set custom meta fields from agreement
$order->update_meta_data('assign_location_id', $agreement->assign_location_id);
$order->update_meta_data('model_name', $agreement->product_name);
$order->update_meta_data('agreement_id', $agreement->agreement_id);
$order->update_meta_data('start_date', $agreement->start_date);
$order->update_meta_data('end_date', $agreement->end_date);
$order->update_meta_data('_number_shifts_required', $agreement->shift); // Assuming 'shift' column corresponds to number of shifts
$order->update_meta_data('rental_amount', $agreement->final_price);
$order->update_meta_data('order_location', $agreement->location);
$order->update_meta_data('order_region', $agreement->region);
$order->set_status('pending', 'Order initially set to processing for email workflow.');
// Save the order
$order->save();
// add_action('shutdown', function () use ($order) {
// sleep(10); // Delay for 10 seconds
// $order->update_status('pending', 'Order status changed to pending programmatically.');
// });
// Get the newly created order ID and update the agreement status
$order_id = $order->get_id();
// Update the ag_status in the wp_agreement table to "Order Created"
$wpdb->update(
'wp_agreement', // Table name
array('status' => 'Order Created'), // Data to update
array('agreement_id' => $agreement->agreement_id) // Where clause (agreement_id matches)
);
// Redirect to the WooCommerce order edit page
$redirect_url = admin_url('post.php?post=' . $order_id . '&action=edit');
// Output JavaScript to show an alert and redirect
echo "<script>
alert('Contract Created Successfully.');
window.location.href = '{$redirect_url}';
</script>";
exit; // Stop further execution to ensure redirection
}
}
// 13-11-2024 Aseema
function hide_screen_options_for_agreement() {
?>
<style>
<?php if (isset($_GET['page']) && ($_GET['page'] === 'agreement')) : ?>
#screen-meta-links {
display: none !important;
}
<?php endif; ?>
</style>
<?php
}
add_action('admin_head', 'hide_screen_options_for_agreement');