modify("$days days"); return $date->format($format); } $html = ""; $db = new db(); $farm_res = $db->exec_query('farms', ['*'], '', '', '', '', 'record_id = 5', "ORDER BY record_id ASC"); while ($farm = $farm_res->fetch_assoc()) { $html = $html . "

FARM : {$farm['farm_name']}


"; $asset_type_res = $db->exec_query('asset_types', ['*'], '', '', '', '', "record_id = 9 OR record_id = 10 OR record_id = 11 OR record_id = 19"); while ($asset_type = $asset_type_res->fetch_assoc()) { $html = $html . "

{$asset_type['asset_type_name']}

"; $assets_res = $db->exec_query('assets', ['*'], '', '', '', '', " asset_type_id = {$asset_type['record_id']} AND farm_id = {$farm['record_id']}"); while ($asset = $assets_res->fetch_assoc()) { $html = $html . "

{$asset['fleet_no']} {$asset['description']} "; $odo_res2 = $db->exec_query('asset_odo', ['*'], '', '', '', '', "asset_record_id = {$asset['record_id']}", 'ORDER BY record_id DESC'); $odo2 = $odo_res2->fetch_assoc(); $last_known_service_res = $db->exec_query('job_cards', ['*'], '', '', '', '', "asset_id = {$asset['record_id']} AND job_card_type = 'SERVICE'", "ORDER BY record_id DESC"); if ($last_known_service_res->num_rows > 0) { $last_known_service = $last_known_service_res->fetch_assoc(); $odo_res = $db->exec_query('asset_odo', ['*'], '', '', '', '', "asset_record_id = {$asset['record_id']} AND `date` BETWEEN '" . addDays(substr($last_known_service['date_time_opened'], 0, 10), "-5") . " 00:00' AND '" . addDays(substr($last_known_service['date_time_opened'], 0, 10), "+5") . " 23:59'", 'ORDER BY record_id DESC'); if ($odo_res->num_rows < 1) { $odo_res = $db->exec_query('asset_odo', ['*'], '', '', '', '', "asset_record_id = {$asset['record_id']} AND `date` < '" . addDays(substr($last_known_service['date_time_opened'], 0, 10), "+0") . " 23:59'", 'ORDER BY record_id DESC'); } $odo = $odo_res->fetch_assoc(); // $html = $html . "
LAST KNOWN SERVICE :
JC. No. : {$last_known_service['record_id']}
DATE OPENED : {$last_known_service['date_time_opened']}
JC. STATUS : {$last_known_service['job_card_status']}
ODO for that day : {$odo['odo']}"; $html = $html . "
CURRENT ODO @ {$odo2['odo']} Km "; $service_type_res = $db->exec_query('service_types', ['*'], '', '', '', '', "record_id = '{$asset_type['service_type_id']}'"); $service_type = $service_type_res->fetch_assoc(); // $html = $html . "
SERVICE INTERVAL : {$service_type['service_interval']}"; $html = $html . "
NEXT SERVICE @ " . ($odo['odo'] + $service_type['service_interval']) . ' Km'; $amlost_due[] = "{$asset['fleet_no']} {$asset['description']} DUE IN " . (($odo['odo'] + $service_type['service_interval']) - $odo2['odo']) . " {$service_type['odo_type']}"; } else { $html = $html . "
CURRENT ODO @ {$odo2['odo']} Km "; $html = $html . "
NO SERIVICE HISTORY FOUND ON THE SYSTEM

"; } } } // var_dump($amlost_due); echo $html; // $header = ""; // foreach ($amlost_due as $due) { // $header = $header . ""; // } // $header = $header . "
$due
"; $body = "

FULL ASSET SERVICE REPORT


$html"; echo "SEND YES"; $email_send = new email(); // $emails_res = $db->exec_query('emails', ['*'], '', '', '', '', "farm_id = {$farm['record_id']} OR farm_id = 0"); $em = ['chris@elegantwork.co.za', 'management@muellestates.co.za1']; $names = ['CP', 'Johann Wasserman']; // while ($email = $emails_res->fetch_assoc()) { // $em[] = $email['email']; // $names[] = $email['name']; // } $email_send->send_mail($em, $names, $body, "{$farm['farm_name']} SERVICE REPORT"); $amlost_due = []; $html = ''; $header = ''; $body = ''; }