function display()
 {
     global $sugar_config;
     $focus = new AirlinesTickets();
     $db = DBManagerFactory::getInstance();
     $record = isset($_GET["record"]) ? htmlspecialchars($_GET["record"]) : '';
     $sql = "select atk.name as name, air.name as airline,\r\n            atk.messenger as messenger,atk.airlines_representative as representative,\r\n            atk.ticket_agency as ticket_agency, atk.itinerary as itinerary,\r\n            atk.booking_class as booking_class, atk.booking_code as booking_code,\r\n            atk.fare as fare ,atk.commisson as commisson,atk.tax_fee_change as tax_fee_change,\r\n            atk.nett as nett, atk.roe as roe,atk.equivalent_in_vn as equivalent_in_vn\r\n            from airlinestickets atk , airlines air  ,airlines_ailinestickets_c aac \r\n            where atk.id = '" . $record . "' \r\n            and air.id = aac.airlines_a476cirlines_ida \r\n            and atk.id = aac.airlines_a1d09tickets_idb \r\n            and atk.deleted = 0 and aac.deleted = 0 and air.deleted = 0";
     // This query to get airline name and airlineticket info.
     $result = $db->query($sql);
     $template = file_get_contents('modules/AirlinesTickets/tpls/Export_exchangeorder.tpl');
     $row = $db->fetchByAssoc($result);
     $template = str_replace("{SITE_URL}", $sugar_config['site_url'], $template);
     $template = str_replace("{AIRLINE}", $row['airline'], $template);
     $template = str_replace("{MESSENGER}", $row['messenger'], $template);
     $template = str_replace("{REPRESENTATIVE}", $row['representative'], $template);
     $template = str_replace("{TICKET_AGENCY}", $row['ticket_agency'], $template);
     $template = str_replace("{FARE}", $row['fare'], $template);
     $template = str_replace("{COMMISSION}", $row['commisson'], $template);
     $template = str_replace("{TAXFEECHANGE}", $row['tax_fee_change'], $template);
     $template = str_replace("{NETT}", $row['nett'], $template);
     $template = str_replace("{ROE}", $row['roe'], $template);
     $template = str_replace("{EQUIVALENT}", $row['equivalent_in_vn'], $template);
     $template = str_replace("{RECORDS}", $focus->get_ticket_exchange_order_record($record, $row['itinerary'], $row['booking_class'], $row['booking_code']), $template);
     $size = strlen($template);
     $filename = "Ticket Exchange Order " . $row['name'] . ".doc";
     ob_end_clean();
     header("Cache-Control: private");
     header("Content-Type: application/force-download;");
     header("Content-Disposition:attachment; filename=\"{$filename}\"");
     header("Content-length:{$size}");
     echo $template;
     ob_flush();
 }
 function display()
 {
     global $sugar_config;
     $focus = new AirlinesTickets();
     $db = DBManagerFactory::getInstance();
     // ONLY LOAD A RECORD IF A RECORD ID IS GIVEN;
     // A RECORD ID IS NOT GIVEN WHEN VIEWING IN LAYOUT EDITOR
     $record = isset($_GET["record"]) ? htmlspecialchars($_GET["record"]) : '';
     $sql = "SELECT\r\n            f.last_name,\r\n            f.first_name,\r\n            f.phone_mobile,\r\n            airt.itinerary,\r\n            acc.name       AS accname,\r\n            air.name       AS airname\r\n            FROM airlines air \r\n            INNER JOIN airlines_ailinestickets_c airair\r\n            ON air.id = airair.airlines_a476cirlines_ida\r\n            INNER JOIN airlinestickets airt\r\n            ON airair.airlines_a1d09tickets_idb = airt.id\r\n            INNER JOIN airlinesticets_accounts_c airacc\r\n            ON airt.id = airacc.airlinestiec2atickets_ida\r\n            INNER JOIN accounts acc\r\n            ON acc.id = airacc.airlinesti3969ccounts_idb\r\n            INNER JOIN accounts_fits_c afc\r\n            ON acc.id = afc.accounts_fd483ccounts_ida\r\n            INNER JOIN fits f\r\n            ON f.id = afc.accounts_f7035itsfits_idb\r\n            WHERE air.deleted = 0\r\n            AND acc.deleted = 0\r\n            AND airair.deleted = 0\r\n            AND airacc.deleted = 0\r\n            AND afc.deleted = 0\r\n            AND airt.deleted = 0\r\n            AND f.deleted =0\r\n            AND airt.id = '" . $record . "'";
     $result = $db->query($sql);
     $countGIT = $db->getRowCount($result);
     $sql1 = "SELECT\r\n            f.last_name ,f.first_name,f.phone_mobile,airt.itinerary, air.name\r\n            FROM\r\n            airlines air INNER JOIN airlines_ailinestickets_c airair ON air.id = airair.airlines_a476cirlines_ida\r\n            INNER JOIN airlinestickets airt ON airt.id = airair.airlines_a1d09tickets_idb INNER JOIN\r\n            airlinestickets_fits_c airf ON airt.id = airf.airlinestia31ctickets_ida INNER JOIN fits f ON\r\n            f.id = airf.airlinestib0dfitsfits_idb \r\n            WHERE f.deleted =0 AND air.deleted =0 AND airair.deleted =0 AND airf.deleted =0 AND airt.deleted =0 AND airt.id ='" . $record . "'";
     $result1 = $db->query($sql1);
     $countFIT = $db->getRowCount($result1);
     $sql2 = "\r\n            SELECT \r\n            airt.tax_fee_change, \r\n            airt.nett, \r\n            airt.roe, \r\n            airt.equivalent_in_vn, \r\n            airt.messenger, \r\n            airt.airlines_representative, \r\n            airt.ticket_agency,\r\n            airt.name as name,\r\n            air.name as airline\r\n            FROM \r\n            airlinestickets airt  LEFT JOIN airlines_ailinestickets_c airairt ON airt.id = airairt.airlines_a1d09tickets_idb AND airairt.deleted =0\r\n            LEFT JOIN airlines air ON air.id = airairt.airlines_a476cirlines_ida AND air.deleted =0 WHERE airt.deleted =0  AND airt.id='" . $record . "'";
     $result2 = $db->query($sql2);
     $row = $db->fetchByAssoc($result2);
     $template = '';
     if ($countGIT != 0 && $countFIT == 0) {
         $template = file_get_contents('modules/AirlinesTickets/tpls/ExportGIT.tpl');
     } else {
         if ($countFIT != 0 && $countGIT == 0) {
             $template = file_get_contents('modules/AirlinesTickets/tpls/ExportFIT.tpl');
         } else {
             $template = file_get_contents('modules/AirlinesTickets/tpls/Export.tpl');
         }
     }
     $template = str_replace("{SITE_URL}", $sugar_config['site_url'], $template);
     $template = str_replace("{NAME}", $row['name'], $template);
     $template = str_replace("{AIRLINE}", $row['airline'], $template);
     $template = str_replace("{MESSENGER}", $row['messenger'], $template);
     $template = str_replace("{AIRLINESREPRESENTATIVE}", $row['airlines_representative'], $template);
     $template = str_replace("{TICKETAGENCY}", $row['ticket_agency'], $template);
     $template = str_replace("{FARE}", $row['fare'], $template);
     $template = str_replace("{COMMISSON}", $row['commison'], $template);
     $template = str_replace("{TAXFEECHANGE}", $row['tax_fee_change'], $template);
     $template = str_replace("{NETT}", $row['nett'], $template);
     $template = str_replace("{ROE}", $row['roe'], $template);
     $template = str_replace("{EQUIVALENT}", $row['equivalent_in_vn'], $template);
     $template = str_replace("{GIT_LIST}", $focus->get_gits_list($record), $template);
     $template = str_replace("{FIT_LIST}", $focus->get_fits_list($record), $template);
     $size = strlen($template);
     $filename = "Danh Sach Ve May Bay " . $row['name'] . ".doc";
     ob_end_clean();
     header("Cache-Control: private");
     header("Content-Type: application/force-download;");
     header("Content-Disposition:attachment; filename=\"{$filename}\"");
     header("Content-length:{$size}");
     echo $template;
     ob_flush();
 }
 function createAirTrainBooking($bean, $chuyenbay = '')
 {
     global $db;
     $sql = "\r\n            SELECT \r\n              a.id \r\n            FROM\r\n              `airlinestickets` a \r\n              JOIN `airlines_ailinestickets_c` b \r\n                ON a.`id` = b.`airlines_a1d09tickets_idb` \r\n                AND b.`deleted` = 0 \r\n                AND b.`airlines_a476cirlines_ida` = '{$chuyenbay->vemaybay}' \r\n              JOIN `groupprogralinestickets_c` c \r\n                ON a.`id` = c.`groupprogr8400tickets_idb` \r\n                AND c.`deleted` = 0 \r\n                AND c.`groupprogr0fd9rograms_ida` = '{$bean->id}' \r\n            WHERE a.`deleted` = 0 \r\n            ";
     $airTrainBooking = new AirlinesTickets();
     $result = $db->query($sql);
     while ($row = $db->fetchByAssoc($result)) {
         $airTrainBooking->id = $row['id'];
     }
     $airTrainBooking->groupprograestickets_name = $bean->name;
     $airTrainBooking->groupprogr0fd9rograms_ida = $bean->id;
     $airTrainBooking->airlines_a476cirlines_ida = $chuyenbay->vemaybay;
     $airline = new Airline();
     $getname_input = array('name' => 'id', 'value' => $chuyenbay->vemaybay);
     $airTrainBooking->airlines_aiestickets_name = getName($airline->table_name, $getname_input);
     $airTrainBooking->name = $airTrainBooking->groupprograestickets_name . ' - ' . $airTrainBooking->airlines_aiestickets_name;
     $airTrainBooking->assigned_user_name = $bean->assigned_user_name;
     $airTrainBooking->assigned_user_id = $bean->assigned_user_id;
     $return = $airTrainBooking->save();
     return $return;
 }