• Resolved dineshkumar382

    (@dineshkumar382)


    I using the Vik Rent Car plugin on WordPress, and right now they have to manually pull the revenue/booking reports from the backend. What they want is a way to have those reports automatically emailed to them every month. Basically, instead of logging in and downloading the report, they want it to hit their inbox at the beginning of each month. I have tried th code but that show wrong data

    add_action( ‘vikrentcar_send_scheduled_report’, ‘send_vikrentcar_scheduled_report_email’ );

    function send_vikrentcar_scheduled_report_email() {
    global $wpdb;

    $table_name = $wpdb->prefix . 'vikrentcar_orders';

    // Date range (last month)
    $date_from = date( "Y-m-01", strtotime( "first day of last month" ) );
    $date_to = date( "Y-m-t", strtotime( "last day of last month" ) );

    // Build email
    $to = "[email protected]"; // change to client email
    $subject = "PMS Report (Monthly)";
    $headers = array( 'Content-Type: text/html; charset=UTF-8' );

    $message = "<h2> PMS Report (Monthly)</h2>";
    $message .= "<table border='1' cellpadding='6' cellspacing='0' style='border-collapse: collapse;'>";
    $message .= "<tr style='background-color:#f2f2f2;'>
    <th>Date</th>
    <th>Cars Sold</th>
    <th>Total Orders</th>
    <th>% Occupancy</th>
    <th>ADR</th>
    <th>RevPAC</th>
    <th>Taxes/Fees</th>
    <th>Revenue</th>
    </tr>";

    // Loop through each day in the month
    $period = new DatePeriod(
    new DateTime($date_from),
    new DateInterval('P1D'),
    (new DateTime($date_to))->modify('+1 day')
    );

    foreach ($period as $date) {
    $day_str = $date->format('Y-m-d');

    // Use DATE(FROM_UNIXTIME(ts)) to match backend exactly
    $results = $wpdb->get_results(
    $wpdb->prepare(
    "SELECT
    COUNT(*) as total_orders,
    SUM(days) as total_days,
    SUM(order_total) as total_revenue,
    SUM(tot_taxes) as total_taxes
    FROM $table_name
    WHERE status = 'confirmed'
    AND DATE(FROM_UNIXTIME(ts)) = %s",
    $day_str
    )
    );

    $orders = floatval($results[0]->total_orders ?? 0);
    $days = floatval($results[0]->total_days ?? 0);
    $revenue = floatval($results[0]->total_revenue ?? 0);
    $taxes = floatval($results[0]->total_taxes ?? 0);

    // Calculations
    $cars_sold = $orders;
    $occupancy = ($days > 0) ? round(($cars_sold / $days) * 100, 2) : 0;
    $adr = ($days > 0) ? round($revenue / $days, 2) : 0;
    $revpac = ($orders > 0) ? round($revenue / $orders, 2) : 0;

    $message .= "<tr>
    <td>" . $date->format("D, m/d/Y") . "</td>
    <td>$cars_sold</td>
    <td>$orders</td>
    <td>{$occupancy}%</td>
    <td>$" . number_format($adr, 2) . "</td>
    <td>$" . number_format($revpac, 2) . "</td>
    <td>$" . number_format($taxes, 2) . "</td>
    <td>$" . number_format($revenue, 2) . "</td>
    </tr>";
    }

    $message .= "</table>";

    // Send email
    wp_mail($to, $subject, $message, $headers);

    }

Viewing 1 replies (of 1 total)
  • Plugin Author e4jvikwp

    (@e4jvikwp)

    Hello,

    Thanks for your message. We understand what you’re looking for, and the ideal solution would be to implement a scheduled action within WP-Cron that periodically invokes, executes and obtains the “resource” file generated by a specific Report.

    This function is already available in VikBooking, our PMS plugin for Hotels and Vacation Rentals. Our development team is planning to introduce similar functionalities into the VikRentCar framework, which will require a major core update for the Reports and Cron Jobs sections. This is something we will go through with the next official plugin updates. At the moment, the version 1.4.x does not support automatic report executions and export functions for delivering contents via email.

    The approach you described is probably the best solution right now. However, we recommend debugging the query to the database by sending it to output to see what data you’re trying to fetch. It is probably not selecting any records due the invalid WHERE clauses related to the rental order creation timestamp. Unless you want to fetch the rental orders of a specific and single date, it is probably better to use intervals of date and time expresses as Unix timestamps.

    We invite you to reach out to our technical support team through our website in case you wanted to get some additional information. Also, these functionalities are related to the Pro/commercial version of the plugin, and so we don’t want to go off-topic on this forum. We look forward to implementing such features natively in the plugin, so that by coding custom reports through WordPress plugins or hooks, you can extend the default functionalities and have the data exported and emailed automatically.

    Thank you,
    The VikWP Team

Viewing 1 replies (of 1 total)

The topic ‘Monthly Pms Report’ is closed to new replies.