HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1014-azure #14~24.04.1-Ubuntu SMP Fri Oct 3 20:52:11 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/dreamsrent-wp-demo/wp-content/plugins/dreamsrent-booking/templates/account/payments.php
<?php
if (!defined('ABSPATH')) {
    exit;
}
?>
 <script src="<?php echo plugin_dir_url(dirname(__DIR__)); ?>js/pdf/jspdf.min.js"></script>
<script src="<?php echo plugin_dir_url(dirname(__DIR__)); ?>js/pdf/html2canvas.min.js"></script>


<?php
global $post_id;
$main_logo = dreamsrent_fl_framework_getoptions('frontend_logo');
    $main_logo_url = isset($main_logo) && $main_logo != '' ? $main_logo['url'] : '';

if (in_array('redux-framework/redux-framework.php', apply_filters('active_plugins', get_option('active_plugins')))) {

    $main_logo = dreamsrent_fl_framework_getoptions('frontend_logo');
    $main_logo_url = isset($main_logo) && $main_logo != '' ? $main_logo['url'] : '';

    $mobile_logo = dreamsrent_fl_framework_getoptions('small_logo');
    $mobile_logo_url = isset($mobile_logo) && $mobile_logo != '' ? $mobile_logo['url'] : '';
} else {
    $main_logo_url = get_template_directory_uri() . '/assets/images/logo.svg';
    $mobile_logo_url = get_template_directory_uri() . '/assets/images/logo-small.png';
} ?>

<div class="content">
 
				<!-- Content Header -->
				<div class="content-header">
					<h4><?php echo esc_html__('Payments', 'bookingcore'); ?></h4>
				</div>

                


                <!-- Payments Table -->
				<div class="row">
					<div class="col-lg-12 d-flex">
						<div class="card book-card flex-fill mb-0">
							<div class="card-header">	
								<div class="row align-items-center">
									<div class="col-md-5">
										<h4><?php echo esc_html__('All Payments', 'bookingcore'); ?></h4>	
									</div>
									<div class="col-md-7 text-md-end">
										<div class="table-search">
											<div id="tablefilter" class="me-0"></div>										
										</div>
									</div>
								</div>
							</div>
							<div class="card-body">	
								<div class="table-responsive dashboard-table">
									<table class="table datatable">
										<thead class="thead-light">
											<tr>
												 
												<th><?php echo esc_html__('Booking ID', 'bookingcore'); ?></th>
												<th><?php echo esc_html__('Car Name', 'bookingcore'); ?></th>
												<th><?php echo esc_html__('Paid on', 'bookingcore'); ?></th>
												<th><?php echo esc_html__('Total', 'bookingcore'); ?></th>
												<th><?php echo esc_html__('Mode', 'bookingcore'); ?></th>
												<th><?php echo esc_html__('Status', 'bookingcore'); ?></th>
												<th class="text-end"><?php echo esc_html__('Action', 'bookingcore'); ?></th>
											</tr>
										</thead>
										<tbody>


                                     
                
                                       
                <?php 

if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {

    $user_id = get_current_user_id();

    $query_args = array(
        'customer_id' => $user_id,
        'orderby' => 'date',
        'order' => 'DESC',
        'numberposts' => -1,
    );

    $orders = wc_get_orders($query_args);
    $store_address     = get_option( 'woocommerce_store_address' );
    $store_address_2   = get_option( 'woocommerce_store_address_2' );
    $store_city        = get_option( 'woocommerce_store_city' );
    $store_postcode    = get_option( 'woocommerce_store_postcode' );
    $store_raw_country = get_option( 'woocommerce_default_country' );
    $split_country = explode( ":", $store_raw_country );
	
	if(!empty($split_country[1])) {
    $store_country = $split_country[0];
    $store_state   = $split_country[1];
	} else {
		$store_country = $split_country[0];	
		$store_state   = '';
	}

    foreach ($orders as $order) {
        $order_id = $order->get_id();
        $invoice_number = $order->get_order_number();
        $billing_address = $order->get_formatted_billing_address();
        foreach ($order->get_items() as $item_id => $item) {
            $combined_amount = 0;
            $product_id = $item->get_product_id();
            $product = wc_get_product($product_id);
			
			$args = array(
				'post_type' => 'rental', // Change 'post' to the appropriate post type
				'meta_query' => array(
					array(
						'key' => '_booking_product_id', // Change 'product_id' to the meta key where product ID is stored
						'value' => $product_id,
						'compare' => '=',
					),
				),
				'fields' => 'ids', // Retrieve only post IDs
			);
			
			$posts_with_product_id = new WP_Query($args);
 
			if ($posts_with_product_id->have_posts()) {
			 while ($posts_with_product_id->have_posts()) {
				 $posts_with_product_id->the_post();
				 
				 $post_id_post = get_the_ID();
                $product_post = wc_get_product($product_id);
                $product_image_post = wp_get_attachment_image_url(get_post_thumbnail_id($post_id_post), 'thumbnail');
                 $dsrent_price_type = get_post_meta($post_id_post, 'dreams_booking_meta_rental_type', true);
              $deposit_amount = wc_get_order_item_meta($item_id, 'dsrent_product_subtotal', true);
            $remaining_amount = wc_get_order_item_meta($item_id, 'dsrent_remain_balance', true);
          if($remaining_amount) { 
            $combined_amount = $deposit_amount + $remaining_amount;
          } else {
            $combined_amount = $deposit_amount;
          }
 
            $rent_days = wc_get_order_item_meta($item_id, 'dsrent_date_difference', true);
            ?>
            <tr>
												 
												<td><?php echo esc_html('#' . $order_id); ?></td>
												<td>
												<div class="table-avatar">
														<a href="#" class="avatar avatar-lg flex-shrink-0">
 
                                                            <img class="avatar-img" src="<?php echo esc_html($product_image_post); ?>" alt="<?php echo esc_html($product->get_title(), 'bookingcore'); ?>">

														</a>
														<div class="table-head-name flex-grow-1">
															<a href="<?php echo esc_url(get_permalink($post_id_post)); ?>
"><?php echo esc_html($product->get_name(), 'bookingcore'); ?></a>
 														</div>
													</div>
												</td>
												<td><?php echo esc_html($order->get_date_created()->format('Y-m-d H:i:s')); ?></td>
												<td><p class="text-darker"><?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($combined_amount); ?></p></td>
												<td>
													<span class="badge badge-light-secondary"><?php echo esc_html($order->get_payment_method_title()); ?></span>
												</td>
												<td>
													<span class="badge badge-light-success"><?php echo esc_html($order->get_status()); ?></span>
												</td>
												<td class="">
													<div class="dropdown dropdown-action">
														<a href="javascript:void(0);" class="dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
															<i class="fas fa-ellipsis-vertical"></i>
														</a>
														<div class="dropdown-menu dropdown-menu-end">
															<!-- <a class="dropdown-item" href="javascript:void(0);" data-bs-toggle="modal" data-bs-target="#viewModal<?php echo esc_html($order_id); ?>">
																<i class="feather-file-plus"></i> <?php echo  esc_html__('View Invoice', 'bookingcore'); ?>
															</a> -->

															
															<a class="dropdown-item" href="javascript:void(0);" onclick="prepareInvoiceContent(<?php echo esc_html($order_id); ?>)">
    <i class="feather-file-text"></i> <?php echo esc_html__('Download Invoice', 'bookingcore'); ?>
</a>
                                                            
															 
														</div>
													</div>

                                                    
<!-- View Invoice Modal -->
<div class="modal new-modal fade" id="viewModal<?php echo esc_html($order_id); ?>" data-keyboard="false" data-backdrop="static">
		<div class="modal-dialog modal-dialog-centered modal-xl">
			<div class="modal-content">
				<div class="modal-header border-0 m-0 p-0">
					<div class="invoice-btns">
						<a href="" class="btn me-2" onclick="printModalContent(<?php echo $order_id; ?>)">
							<i class="feather-printer"></i><?php echo esc_html__('Print', 'bookingcore'); ?> 
						</a>
						 
					</div>
				</div>
				<div class="modal-body">
					<div class="invoice-details">
						<div class="invoice-items">
							<div class="row align-items-center">
								<div class="col-md-6">
									<div class="invoice-logo">
                                    <img src="<?php echo esc_url($main_logo_url); ?>" class="img-fluid" alt="Logo">
									</div>
								</div>
								<div class="col-md-6">
									<div class="invoice-info-text">
										<h4><?php echo esc_html__('Invoice', 'bookingcore'); ?></h4>
										<p><?php echo esc_html__('Invoice Number', 'bookingcore'); ?> : <span><?php echo esc_html($invoice_number); ?></span></p>
									</div>
								</div>
							</div>
						</div>
						<div class="invoice-item-bills">
							<div class="row align-items-center">
								<div class="col-lg-4 col-md-12">
									<div class="invoice-bill-info">
										<h6><?php echo  esc_html__('Billed to', 'bookingcore'); ?></h6>
										<p><?php echo print_r($billing_address); ?> </p>
									</div>
								</div>
								<div class="col-lg-4 col-md-12">
									<div class="invoice-bill-info">
										<h6><?php echo esc_html__('Invoice From', 'bookingcore'); ?></h6>
										<p>
                                        <?php if ($store_address) {  ?> 
                                        <?php echo esc_html($store_address); ?>, <br />
                                        <?php } ?> 
                                        <?php if ($store_address_2) {  ?>
                                         <?php echo esc_html($store_address_2); ?><br />
                                         <?php } ?> 
                                         <?php if ($store_city) {  ?>
                                         <?php echo esc_html($store_city); ?>,<br />
                                         <?php } ?> 
                                         <?php if ($store_state) {  ?>
                                         <?php echo esc_html($store_state); ?>,<br />
                                         <?php } ?> 
                                         <?php if ($store_postcode) {  ?>
                                         <?php echo esc_html($store_postcode); ?>,<br />
                                         <?php } ?> 
                                         <?php if ($store_country) {  ?>
                                         <?php echo esc_html($store_country); ?>.
                                         <?php } ?> 

                                        
										</p>
									</div>
								</div>
								<div class="col-lg-4 col-md-12">
									<div class="invoice-bill-info border-0">
										<p><?php echo esc_html__('Issue Date', 'bookingcore'); ?> : <?php echo esc_html($order->get_date_created()->format('Y-m-d')); ?> </p>
										<p><?php echo esc_html__('Due Amount', 'bookingcore'); ?> : <?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($combined_amount); ?></p>
										<p class="mb-0"><?php echo esc_html__('PO Number ', 'bookingcore'); ?> : <?php echo esc_html($order_id); ?></p>
									</div>
								</div>
							</div>
						</div>

 

						<div class="invoice-table-wrap">
							<div class="row">
								<div class="col-md-12">
									<div class="table-responsive">
										<table class="invoice-table table table-center mb-0">
											<thead>
												<tr>
													<th><?php echo esc_html__('Rented Car', 'bookingcore'); ?></th>
													<th><?php echo esc_html__('No of days', 'bookingcore'); ?></th>
													<th><?php echo esc_html__('Rental Amount', 'bookingcore'); ?></th>
													<th class="text-end"><?php echo esc_html__('Amount', 'bookingcore'); ?></th>
												</tr>
											</thead>
											<tbody>
												<tr>
													<td>
														<h6><?php echo esc_html( $product->get_name()); ?></h6>
													</td>
													<td><?php echo esc_html($rent_days); ?></td>
													<td><?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($combined_amount); ?></td>
													<td class="text-end"><?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($combined_amount); ?></td>
												</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
						<div class="payment-details-info">
							<div class="row">
								<div class="col-lg-6 col-md-12">
									<div class="invoice-terms">											
										<h6><?php echo esc_html__('Payment Details', 'bookingcore'); ?></h6>
										<div class="invocie-note">
											<p><?php echo esc_html($order->get_payment_method_title()); ?> </p>
										</div>
									</div>
								</div>
							 
							</div>
						</div>
						<div class="invoice-total">
							<h4><?php echo esc_html__('Total', 'bookingcore'); ?> <span><?php echo get_woocommerce_currency_symbol(); ?><?php echo esc_html($combined_amount); ?></span></h4>
						</div>
						 
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- /View Invoice Modal -->

	

 </td>

 
 </tr>
 <?php
}
			 // Restore original post data
			 wp_reset_postdata();
		 }
		 ?>
 <div id="dynamicContentContainer" style="display: none;" data-order-id="<?php echo esc_html($order_id); ?>"></div>

<?php
        
        } 
    } wp_reset_query();
}
?>



</tbody>

</table>
 
</div>

<div class="table-footer">
									<div class="row">
										<div class="col-md-6">
											<div id="tablelength"></div>
										</div>
										<div class="col-md-6 text-md-end">
											<div id="tablepage"></div>
										</div>
									</div>
								</div>
</div></div></div></div> 



</div>
                </div>
                

 
            </div></div>
<script>

function printModalContent(orderId) {
    var themeDirectoryUrl = '<?php echo esc_url( get_template_directory_uri() ); ?>';

    var bootstrapCssLink = document.createElement('link');
    bootstrapCssLink.rel = 'stylesheet';
    bootstrapCssLink.href = themeDirectoryUrl + '/assets/css/bootstrap.min.css';
    document.head.appendChild(bootstrapCssLink);

    var customCssLink = document.createElement('link');
    customCssLink.rel = 'stylesheet';
    customCssLink.href = themeDirectoryUrl + '/assets/css/pdf-style.css';
    document.head.appendChild(customCssLink);

    var modalBodyClone = document.getElementById('viewModal' + orderId).getElementsByClassName('modal-body')[0].cloneNode(true);

    var printWindow = window.open('', '_blank');

    printWindow.document.head.innerHTML = '';
    printWindow.document.head.appendChild(bootstrapCssLink.cloneNode(true));
    printWindow.document.head.appendChild(customCssLink.cloneNode(true));

    printWindow.document.body.innerHTML = '';
    printWindow.document.body.appendChild(modalBodyClone);

    var images = printWindow.document.body.getElementsByTagName('img');
    var imagesLoaded = 0;

    function imageLoaded() {
        imagesLoaded++;
        if (imagesLoaded === images.length) {
            printWindow.print();
            printWindow.close();
        }
    }

    for (var i = 0; i < images.length; i++) {
        images[i].addEventListener('load', imageLoaded);
    }

    if (images.length === 0) {
        printWindow.print();
        printWindow.close();
    }
}


// function prepareInvoiceContent(orderId) {
//     var modalBodyClone = document.getElementById('viewModal' + orderId)
//         .getElementsByClassName('modal-body')[0].cloneNode(true);
//     var modalWrapper = document.createElement('div');
//     modalWrapper.appendChild(modalBodyClone);

//     var dynamicContentContainer = document.getElementById('dynamicContentContainer');
//     dynamicContentContainer.innerHTML = '';
//     dynamicContentContainer.appendChild(modalWrapper);
//     convertDynamicContentToPDF(orderId);
// }

function prepareInvoiceContent(orderId) {
    var themeDirectoryUrl = '<?php echo esc_url( get_template_directory_uri() ); ?>';

    var bootstrapCssLink = document.createElement('link');
    bootstrapCssLink.rel = 'stylesheet';
    bootstrapCssLink.href = themeDirectoryUrl + '/assets/css/bootstrap.min.css';
    document.head.appendChild(bootstrapCssLink);

    var customCssLink = document.createElement('link');
    customCssLink.rel = 'stylesheet';
    customCssLink.href = themeDirectoryUrl + '/assets/css/pdf-style.css';
    document.head.appendChild(customCssLink);

    var modalBodyClone = document.getElementById('viewModal' + orderId).getElementsByClassName('modal-body')[0].cloneNode(true);

    // Add the border class to the cloned content
    modalBodyClone.classList.add('pdf-border');

    var dynamicContentContainer = document.getElementById('dynamicContentContainer');
    dynamicContentContainer.innerHTML = '';
    dynamicContentContainer.appendChild(modalBodyClone);

    // Ensure styles are fully applied before generating the PDF
    setTimeout(function() {
        convertDynamicContentToPDF(orderId);
    }, 500);  // Add a slight delay to allow styles to load
}

function convertDynamicContentToPDF(orderId) {
    var dynamicContentContainer = document.getElementById('dynamicContentContainer');
    var pdfFileName = 'invoice_' + orderId + '.pdf';

    dynamicContentContainer.style.display = 'block'; // Show the content temporarily

    setTimeout(function () {
        html2canvas(dynamicContentContainer, { imageType: 'png' })
            .then(function (canvas) {
                var imgData = canvas.toDataURL('image/png');
                var pdf = new jsPDF('p', 'pt', 'a4'); // Set orientation to portrait and size to A4

                // A4 dimensions in points
                var imgWidth = 595 - 40; // A4 width minus margins (20 points on each side)
                var pageHeight = 842 - 40; // A4 height minus margins (20 points on each side)
                var imgHeight = (canvas.height * imgWidth) / canvas.width;
                var heightLeft = imgHeight;

                let position = 20; // Starting position with top margin

                // Add the image to the PDF
                pdf.addImage(imgData, 'PNG', 20, position, imgWidth, imgHeight); // 20 points left margin
                heightLeft -= pageHeight;

                while (heightLeft >= 0) {
                    position = heightLeft - imgHeight + 20; // Adjust for top margin
                    pdf.addPage();
                    pdf.addImage(imgData, 'PNG', 20, position, imgWidth, imgHeight); // 20 points left margin
                    heightLeft -= pageHeight;
                }

                pdf.save(pdfFileName);
				window.location.reload();
                 dynamicContentContainer.style.display = 'none'; // Hide the content again
            })
            .catch(function (error) {
                console.error('Error capturing dynamic content:', error);
                dynamicContentContainer.style.display = 'none'; // Hide on error
            });
    }, 1000); // Delay to ensure the content is fully rendered
}

</script>