| Server IP : 103.234.187.230 / Your IP : 216.73.216.216 Web Server : Apache System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/b2bzend/application/models/ |
Upload File : |
<?php
class Travel_Model_TblBus
{
private $db = NULL;
public $intId = NULL;
public $searchArr = NULL;
public $baseUrl = Null;
/* * ************************************ */
public function __construct()
{
$request = Zend_Controller_Front::getInstance()->getRequest();
$this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();
$this->db = Zend_Db_Table::getDefaultAdapter();
}
public function __destruct()
{
$this->db->closeConnection();
}
public function checkDuplicate($data, $BusId = null)
{
$Title = $data['Title'];
$LayoutType = $data['LayoutType'];
$AgencySysId = (int) $data['AgencySysId'];
$select = $this->db->select();
$select->from("TB_Bus", array(new Zend_Db_Expr('count(*) as n')));
$select->where("Title =?", $Title);
$select->where("AgencySysId =?", $AgencySysId);
$select->where("LayoutType =?", $LayoutType);
if (!empty($BusId)) {
$select->where("BusId !=?", $BusId);
}
$result = $this->db->fetchRow($select);
if ($result['n'] > 0) {
return 1;
}
return 0;
}
public function checkDuplicateLayout($data, $BusLayoutsId = null)
{
$Title = $data['Title'];
// $BusId = $data['BusId'];
$TotalSeats = $data['TotalSeats'];
$AgencySysId = (int) $data['AgencySysId'];
$select = $this->db->select();
$select->from("TB_Bus_Layouts", array(new Zend_Db_Expr('count(*) as n')));
$select->where("Title =?", $Title);
$select->where("AgencySysId =?", $AgencySysId);
// $select->where("BusId =?", $BusId);
$select->where("TotalSeats =?", $TotalSeats);
if (!empty($BusLayoutsId)) {
$select->where("BusLayoutsId !=?", $BusLayoutsId);
}
$result = $this->db->fetchRow($select);
if ($result['n'] > 0) {
return 1;
}
return 0;
}
public function updateDataWhere($table, $data, $where)
{
try {
$this->db->update($table, $data, $where);
} catch (Exception $e) {
die($e->getMessage());
return 0;
}
}
public function updateData($update, $BusId)
{
$where = array('BusId = ? ' => $BusId);
$this->db->update('TB_Bus', $update, $where);
}
public function updateLayoutData($update, $BusLayoutsId)
{
$where = array('BusLayoutsId = ? ' => $BusLayoutsId);
$this->db->update('TB_Bus_Layouts', $update, $where);
}
public function insertData($data)
{
try {
$this->db->insert('TB_Bus', $data);
return $this->db->lastInsertId('TB_Bus');
} catch (Exception $e) {
die('There has been an error. ' . $e->getMessage());
}
return 0;
}
public function insertLayoutData($data)
{
try {
$this->db->insert('TB_Bus_Layouts', $data);
return $this->db->lastInsertId('TB_Bus_Layouts');
} catch (Exception $e) {
die('There has been an error. ' . $e->getMessage());
}
return 0;
}
public function insertBusSeats($data)
{
try {
$this->db->insert('Tb_Bus_Seats', $data);
return $this->db->lastInsertId('Tb_Bus_Seats');
} catch (Exception $e) {
die('There has been an error. ' . $e->getMessage());
}
return 0;
}
public function updateBusSeatData($update, $BusSeatsId)
{
$where = array('BusSeatsId = ? ' => $BusSeatsId);
$this->db->update('Tb_Bus_Seats', $update, $where);
}
public function updateBusSeatDataWhereIn($update, $where)
{
$this->db->update('Tb_Bus_Seats', $update, $where);
}
public function busList($AgencySysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_Bus"));
$select->joinLeft(array('t2' => 'TB_Bus_Layouts'), 't2.BusLayoutsId = tb1.LayoutType ', array("Title as LayoutName", "layout_type as layout_type"));
$select->where("tb1.AgencySysId = ?", $AgencySysId);
$select->where("tb1.IsMarkForDelete = ?", 0);
$select->where("t2.IsMarkForDelete = ?", 0);
$select->order("tb1.BusId DESC");
$result = $this->db->fetchAll($select);
return $result;
}
public function busLayoutList($AgencySysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_Bus_Layouts"));
// $select->joinLeft(array('t2' => 'TB_Bus'), 't2.BusId = tb1.BusId ', array("Title as Busname"));
$select->where("tb1.AgencySysId = ?", $AgencySysId);
$select->where("tb1.IsMarkForDelete = ?", 0);
$select->order("tb1.BusLayoutsId DESC");
$result = $this->db->fetchAll($select);
return $result;
}
public function busDetails($BusId, $AgencySysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_Bus"));
$select->joinLeft(array('t2' => 'TB_Bus_Layouts'), 't2.BusLayoutsId = tb1.LayoutType ', array("Title as LayoutName", "layout_type as layout_type"));
$select->where("tb1.BusId = ?", $BusId);
$select->where("tb1.AgencySysId = ?", $AgencySysId);
$select->where("tb1.IsMarkForDelete = ?", 0);
$select->where("t2.IsMarkForDelete = ?", 0);
$select->order("tb1.BusId DESC");
$result = $this->db->fetchRow($select);
return $result;
}
public function busLayoutDetails($BusLayoutsId, $AgencySysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_Bus_Layouts"));
// $select->joinLeft(array('t2' => 'TB_Bus'), 't2.BusId = tb1.BusId ', array("Title as Busname", "LayoutType"));
$select->where("tb1.BusLayoutsId = ?", $BusLayoutsId);
$select->where("tb1.AgencySysId = ?", $AgencySysId);
// $select->where("t2.IsMarkForDelete = ?", 0);
// $select->where("t2.IsActive = ?", 1);
$select->where("tb1.IsMarkForDelete = ?", 0);
$select->where("tb1.IsActive = ?", 1);
$select->order("tb1.BusLayoutsId DESC");
$result = $this->db->fetchRow($select);
return $result;
}
public function busLayoutDetailsEdit($BusLayoutsId, $AgencySysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_Bus_Layouts"));
// $select->joinLeft(array('t2' => 'TB_Bus'), 't2.BusId = tb1.BusId ', array("Title as Busname", "LayoutType"));
$select->where("tb1.BusLayoutsId = ?", $BusLayoutsId);
$select->where("tb1.AgencySysId = ?", $AgencySysId);
// $select->where("t2.IsMarkForDelete = ?", 0);
// $select->where("t2.IsActive = ?", 1);
$select->where("tb1.IsMarkForDelete = ?", 0);
$select->order("tb1.BusLayoutsId DESC");
$result = $this->db->fetchRow($select);
return $result;
}
public function BusSeatsDetails($BusLayoutsId, $AgencySysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "Tb_Bus_Seats"));
// $select->joinLeft(array('t2' => 'TB_Bus'), 't2.BusId = tb1.BusId ', array("Title as Busname", "LayoutType"));
$select->joinLeft(array('t3' => 'TB_Bus_Layouts'), 't3.BusLayoutsId = tb1.BusLayoutsId ', array("Title as Title", "TotalSeats"));
$select->where("tb1.BusLayoutsId = ?", $BusLayoutsId);
// $select->where("tb1.BusId = ?", $BusId);
$select->where("tb1.AgencySysId = ?", $AgencySysId);
// $select->where("t2.IsMarkForDelete = ?", 0);
// $select->where("t2.IsActive = ?", 1);
$select->where("tb1.IsMarkForDelete = ?", 0);
$select->where("tb1.IsActive = ?", 1);
// $select->order("tb1.BusLayoutsId DESC");
$result = $this->db->fetchAll($select);
$SeatData = [];
$BusSeatsId = [];
$BusSeatType = [];
$AllRows = [];
if ($result) {
foreach ($result as $key => $val) {
if ((isset($val['SeatType']) && !empty($val['SeatType']) && $val['SeatType'] == '1')) {
$SeatType = 'seater';
} elseif ((isset($val['SeatType']) && !empty($val['SeatType']) && $val['SeatType'] == '2')) {
$SeatType = 'sleeper';
} else {
$SeatType = 0;
}
$BusSeatsId[] = $val['BusSeatsId'];
if ($val['SeatNo'] != '0') {
//$BusSeatsId[] = $val['BusSeatsId'];
$BusSeatType[$val['SeatNo']] = $val['SeatType'];
}
if ($val['columns'] == 0) {
$SeatData[$val['rows']][$val['columns']] = [
'BusSeatsId' => $val['BusSeatsId'],
'position' => ['row' => $val['rows'], 'col' => $val['columns']],
];
} else {
$SeatData[$val['rows']][$val['columns']] = [
'BusSeatsId' => $val['BusSeatsId'],
'seatno' => $val['SeatNo'],
'type' => $SeatType,
'position' => ['row' => $val['rows'], 'col' => $val['columns']],
];
}
// $AllRows[$val['rows']][] = [
// 'BusSeatsId' => $val['BusSeatsId'],
// 'seatno' => $val['SeatNo'],
// 'type' => $SeatType,
// 'position' => ['row' => $val['rows'], 'col' => $val['columns']],
// ];
}
// echo '<pre>';
// print_r(json_encode($AllRows));
// die;
}
return ['SeatData' => $SeatData, 'BusSeatsId' => array_values($BusSeatsId), 'BusSeatType' => $BusSeatType];
}
public function busSeatMap($BusId, $AgencySysId)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_Bus"));
$select->joinLeft(array('t2' => 'TB_Bus_Layouts'), 't2.BusLayoutsId = tb1.LayoutType ', array("Title as LayoutName", "layout_type as layout_type", "TotalSeats"));
$select->where("tb1.BusId = ?", $BusId);
$select->where("tb1.AgencySysId = ?", $AgencySysId);
$select->where("tb1.IsMarkForDelete = ?", 0);
$select->where("t2.IsMarkForDelete = ?", 0);
$select->order("tb1.BusId DESC");
$result = $this->db->fetchRow($select);
$Data = [];
if ($result) {
$LayoutID = isset($result['LayoutType']) ? $result['LayoutType'] : 0;
$BusSeatsDetails = $this->BusSeatsDetails($LayoutID, $AgencySysId);
$Data = ['BusData' => $result, 'SeatMap' => $BusSeatsDetails];
}
return $Data;
}
public function busSeatHold($TPSysId, $InventoryDate, $AgencySysId, $ProposalSysId = 0)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_TravelPlan_Bus_Seats"));
$select->joinleft(array('tb2' => "Tb_Bus_Seats"), "tb1.SeatId = tb2.BusSeatsId", array("SeatNo", "SeatType"));
if ($ProposalSysId > 0) {
$select->where("tb1.ProposalSysId = ?", $ProposalSysId);
}
$select->where("tb1.TPSysId = ?", $TPSysId);
$select->where("tb1.AgencySysId = ?", $AgencySysId);
$select->where("tb1.InventoryDate = ?", $InventoryDate);
$select->where("tb1.IsMarkForDelete = ?", 0);
$select->order("tb1.BusSeatsId DESC");
$result = $this->db->fetchAll($select);
return $result;
}
public function CheckHoldUnholdSeatExist($whereArray)
{
$select = $this->db->select();
$select->from(array('tb1' => "TB_TravelPlan_Bus_Seats"));
// $select->where("tb1.SeatNo = ?", $whereArray['SeatNo']);
$select->where("tb1.TPSysId = ?", $whereArray['TPSysId']);
$select->where("tb1.InventoryDate = ?", $whereArray['InventoryDate']);
$select->where("tb1.AgencySysId = ?", $whereArray['AgencySysId']);
$select->where("tb1.SeatType = ?", $whereArray['SeatType']);
if (isset($whereArray['ProposalSysId']) && $whereArray['ProposalSysId'] > 0) {
$select->where("tb1.ProposalSysId = ?", $whereArray['ProposalSysId']);
}
$select->where("tb1.SeatId = ?", $whereArray['SeatId']);
$result = $this->db->fetchRow($select);
return $result;
}
public function setActiveDeactiveBus($BusId, $intLoggedinUserAgencySysId, $statusValue)
{
$where = array('BusId = ? ' => base64_decode($BusId), 'AgencySysId = ? ' => $intLoggedinUserAgencySysId);
$updateData = array('IsActive' => $statusValue);
return $this->db->update('TB_Bus', $updateData, $where);
}
public function setActiveDeactiveBusLayout($BusLayoutsId, $intLoggedinUserAgencySysId, $statusValue)
{
$where = array('BusLayoutsId = ? ' => base64_decode($BusLayoutsId), 'AgencySysId = ? ' => $intLoggedinUserAgencySysId);
$updateData = array('IsActive' => $statusValue);
return $this->db->update('TB_Bus_Layouts', $updateData, $where);
}
}