Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class HotelReservationsController extends AppController {
- var $name = 'HotelReservations';
- var $paginate = array('HotelReservation' => array('order' => array('HotelReservation.id' => 'asc')));
- function index() {
- $this->HotelReservation->recursive = 0;
- $filter = $this->Filter->process($this);
- $hotels= $this->paginate(null, $filter);
- //debug($hotels);
- //die;
- $this->set('hotelReservations', $this->paginate(null, $filter));
- $customers = $this->HotelReservation->Customer->find('list');
- $product = $this->HotelReservation->Product->find('list');
- $statusReservations = $this->HotelReservation->StatusReservation->find('list');
- $request = $this->HotelReservation->ServiceRequest->find('list');
- $this->set(compact('customers','product','statusReservations','request'));
- if($this->RequestHandler->isAjax()) {
- $this->layout='ajax';
- $this->autoRender=false;
- $this->viewPath = 'elements'.DS.'hotel_reservations';
- $this->render('index_data');
- }
- }
- function view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid hotel reservation', true));
- $this->redirect(array('action' => 'index'));
- }
- $this->set('hotelReservation', $this->HotelReservation->read(null, $id));
- }
- function add() {
- if (!empty($this->data)) {
- $data= $this->Auth->user();
- $user_id=$data['User']['id'];
- $payterm=$this->HotelReservation->Customer->field('pay_term_id',array('Customer.id'=>$this->data['HotelReservation']['customer_id']));
- $currency=$this->HotelReservation->Customer->field('currency_id',array('Customer.id'=>$this->data['HotelReservation']['customer_id']));
- $branchName=$this->HotelReservation->User->Branch->field('name',array('id'=>$user_id));
- $this->data['HotelReservation']['pay_term_id']=$payterm;
- $this->data['HotelReservation']['currency_id']=$currency;
- $basic_price=0; $gross_price=0;
- foreach ($this->data['HotelReservationDetail'] as $index) {
- $gross_price=$gross_price+(float)str_replace(".","",$index['gross_price']);
- $basic_price=$basic_price+(float)str_replace(".","",$index['basic_price']);
- }
- $profit=$gross_price-$basic_price;
- $this->data['HotelReservation']['profit']=$profit;
- $this->data['HotelReservation']['gross_price']=$gross_price;
- $this->data['HotelReservation']['basic_price']=$basic_price;
- $rst_no=$this-> _set_room_number();
- $this->data['HotelReservation']['res_no']=$rst_no;
- $this->data['HotelReservation']['user_id']=$user_id;
- $this->data['HotelReservation']['branch_name']=$branchName;
- $this->HotelReservation->create();
- if ($this->HotelReservation->save($this->data)) {
- $hotel_id = $this->HotelReservation->id;
- foreach($this->data['HotelReservationDetail'] as $index => $hotelReservationDetail) {
- $hotelReservationDetail = array('HotelReservationDetail' =>$hotelReservationDetail);
- $hotelReservationDetail['HotelReservationDetail']['hotel_reservation_id'] = $hotel_id;
- $gross=(float)str_replace(".","",$hotelReservationDetail['HotelReservationDetail']['gross_price']);
- $basic=(float)str_replace(".","",$hotelReservationDetail['HotelReservationDetail']['basic_price']);
- $profitdetail=$gross-$basic;
- $hotelReservationDetail['HotelReservationDetail']['profit']=$profitdetail;
- $hotelReservationDetail['HotelReservationDetail']['gross_price']=$gross;
- $hotelReservationDetail['HotelReservationDetail']['basic_price']=$basic;
- $this->HotelReservation->HotelReservationDetail->create();
- //debug($hotelReservationDetail);
- //die;
- $this->HotelReservation->HotelReservationDetail->set($hotelReservationDetail);
- $this->HotelReservation->HotelReservationDetail->save();
- }
- $this->loadModel('Setting');
- $rst_lastnumber=Configure::read('__rst_last_number');
- $saveNumber=$rst_lastnumber+1;
- $id = $this->Setting->field('id',array('key'=>'rst_last_number'));
- $this->Setting->id=$id;
- $this->Setting->updateAll(array('Setting.value'=>$saveNumber),array('key'=>'rst_last_number'));
- $this->Session->setFlash(__('The hotel reservation has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The hotel reservation could not be saved. Please, try again.', true));
- }
- }
- $statusReservations = $this->HotelReservation->StatusReservation->find('list');
- $providers = $this->HotelReservation->Provider->find('list',
- array('conditions'=>array(
- 'Provider.service_type_id'=>5
- )));
- $products = $this->HotelReservation->Product->find('list',array('conditions'=>array('Product.')));
- $currencies = $this->HotelReservation->Currency->find('list');
- $customers = $this->HotelReservation->Customer->find('list');
- $serviceRequests = $this->HotelReservation->ServiceRequest->find('list');
- $currency = null;
- $payterm = null;
- $payterm_id = null;
- $credit_balance = null;
- $curr_rate = null;
- $credit_limit = null;
- $this->set(compact('statusReservations','providers', 'products', 'currencies','customers','serviceRequests','currency','payterm','payterm_id','credit_balance','curr_rate','credit_limit'));
- }
- function edit($id = null) {
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid hotel reservation', true));
- $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->data)) {
- $gross_price=0;
- $basic_price=0;
- foreach ($this->data['HotelReservationDetail'] as $index) {
- $gross_price=$gross_price+(float)str_replace(".","",$index['gross_price']);
- $basic_price=$basic_price+(float)str_replace(".","",$index['basic_price']);
- }
- $profit=$gross_price-$basic_price;
- $payterm=$this->HotelReservation->Customer->field('pay_term_id',array('Customer.id'=>$this->data['HotelReservation']['customer_id']));
- $this->data['HotelReservation']['pay_term_id']=$payterm;
- if ($this->HotelReservation->save($this->data)) {
- $this->HotelReservation->HotelReservationDetail->deleteAll(array('HotelReservationDetail.hotel_reservation_id' => $id));
- $hotel_id=$this->HotelReservation->id;
- foreach($this->data['HotelReservationDetail'] as $index => $hotelReservationDetail){
- $hotelReservationDetail = array('HotelReservationDetail' =>$hotelReservationDetail);
- $hotelReservationDetail['HotelReservationDetail']['hotel_reservation_id'] = $hotel_id;
- $gross=(float)str_replace(".","",$hotelReservationDetail['HotelReservationDetail']['gross_price']);
- $basic=(float)str_replace(".","",$hotelReservationDetail['HotelReservationDetail']['basic_price']);
- $profit=$gross-$basic;
- $hotelReservationDetail['HotelReservationDetail']['profit'] = $profit;
- $hotelReservationDetail['HotelReservationDetail']['gross_price']=$gross;
- $hotelReservationDetail['HotelReservationDetail']['basic_price']=$basic;
- $this->HotelReservation->HotelReservationDetail->create();
- $this->HotelReservation->HotelReservationDetail->set($hotelReservationDetail);
- $this->HotelReservation->HotelReservationDetail->save();
- }
- $this->Session->setFlash(__('The hotel reservation has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The hotel reservation could not be saved. Please, try again.', true));
- }
- }
- if (empty($this->data)) {
- $this->data = $this->HotelReservation->read(null, $id);
- $statusReservations = $this->HotelReservation->StatusReservation->find('list');
- $products = $this->HotelReservation->Product->find('list');
- $customers = $this->HotelReservation->Customer->find('list');
- $customer_id = $this->data['HotelReservation']['customer_id'];
- $currency_id = $this->data['HotelReservation']['currency_id'];
- $payterm_id = $this->data['HotelReservation']['pay_term_id'];
- $curr_rate=$this->data['HotelReservation']['rate'];
- $credit_balance = $this->HotelReservation->Customer->field('balance',array('Customer.id'=>$customer_id));
- //$hotelReservationDetails = $this->HotelReservation->HotelReservationDetail->find('list');
- $providers = $this->HotelReservation->Provider->find('list',
- array('conditions'=>array(
- 'Provider.service_type_id'=>1,
- 'Provider.service_type_id'=>2,
- )));
- $currency=$this->HotelReservation->Currency->field('code',array('Currency.id'=>$currency_id));
- $payterm=$this->HotelReservation->Customer->PayTerm->field('name',array('PayTerm.id'=>$payterm_id));
- $serviceRequests = $this->HotelReservation->ServiceRequest->find('list');
- $currency_name = $this->HotelReservation->Currency->field('code',array('Currency.id'=>$currency_id));
- $payterm_name = $this->HotelReservation->PayTerm->field('name',array('PayTerm.id'=>$payterm_id));
- $credit_limit = $this->HotelReservation->Customer->field('credit_limit',array('id'=>$customer_id));
- $this->set(compact('statusReservations', 'products', 'customers','
- serviceRequests','currency','currency_name','payterm_name','credit_limit','payterm','payterm_id','curr_rate','credit_balance','providers'));
- }
- }
- function insert_hoteldetail() {
- //debug($this->data);
- if (!empty($this->data)) {
- $this->loadModel('HotelReservationDetail');
- $this->data['HotelReservationDetail']['id']= $this->data['HotelReservation']['id'];
- $this->data['HotelReservationDetail']['hotel_reservation_id']= $this->data['HotelReservation']['hotel_reservation_id'];
- $this->data['HotelReservationDetail']['guest_name']= $this->data['HotelReservation']['guest_name'];
- $this->data['HotelReservationDetail']['room_number']= $this->data['HotelReservation']['room_number'];
- $this->data['HotelReservationDetail']['room_type']= $this->data['HotelReservation']['room_type'];
- $this->data['HotelReservationDetail']['check_in_date']= $this->data['HotelReservation']['check_in_date'];
- $this->data['HotelReservationDetail']['check_out_date']= $this->data['HotelReservation']['check_out_date'];
- $this->data['HotelReservationDetail']['gross_price']= $this->data['HotelReservation']['publish_fare'];
- $this->data['HotelReservationDetail']['basic_price']= $this->data['HotelReservation']['net_fare'];
- $this->HotelReservationDetail->save($this->data);
- }
- if($this->RequestHandler->isAjax()) {
- $this->autoRender=false;
- $this->layout='ajax';
- $this->render('edit');
- }
- }
- function delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for hotel reservation', true));
- $this->redirect(array('action'=>'index'));
- }
- if ($this->HotelReservation->delete($id)) {
- $this->Session->setFlash(__('Hotel reservation deleted', true));
- $this->redirect(array('action'=>'index'));
- }
- $this->Session->setFlash(__('Hotel reservation was not deleted', true));
- $this->redirect(array('action' => 'index'));
- }
- function _set_room_number() {
- $imonthNow=(idate("m"));
- $iyearNow = (idate("Y"));
- $appMonth=Configure::read('__month_period');
- $appYear=Configure::read('__year_period');
- $rst_prefix=Configure::read('__rst_prefix');
- if (strlen($appMonth) == 1) {
- $month_number = "0" . $appMonth ;
- }else{
- $month_number = $appMonth ;
- }
- $year_number=substr(Configure::read('__year_period'),2,2);
- $rst_lastnumber=Configure::read('__rst_last_number');
- if ($imonthNow == $appMonth) {
- $rst_number = $rst_lastnumber + 1 ;
- }else{
- $rst_number=1;
- }
- if (strlen($rst_number) == 1)
- $str_number=$rst_prefix."-".$year_number. $month_number ."-000" . $rst_number;
- elseif (strlen($rst_number) == 2)
- $str_number=$rst_prefix."-".$year_number. $month_number ."-00" . $rst_number;
- elseif (strlen($rst_number) == 3)
- $str_number=$rst_prefix."-".$year_number. $month_number ."-0" . $rst_number;
- else
- $str_number=$rst_prefix."-".$year_number. $month_number ."-" . $rst_number;
- return $str_number;
- }
- function promote_invoice() {
- $tot_basic_price=0;
- $tot_gross_price=0;
- $arr_id=$_POST['rec_ids'];
- $i=0;
- $inv_no=$this-> _get_invoice_number();
- foreach ($arr_id as $id) {
- $hotel=$this->HotelReservation->read(null,$id);
- /*---------------Get Customer Invo------------------------'*/
- $rsv_date=$hotel['HotelReservation']['issued_date'];
- $cust_id=$hotel['HotelReservation']['customer_id'];
- $currency=$hotel['HotelReservation']['currency_id'];
- $payterm=$hotel['Customer']['pay_term_id'];
- //$branch=$hotel['HotelReservation']['branch_name'];
- $user=$hotel['HotelReservation']['user_id'];
- $point=$this->HotelReservation->field('point',array('HotelReservation.id'=>$id));
- $real_amount= (int)$hotel['HotelReservation']['basic_price']; //Net to Agent
- $amount=(int)$hotel['HotelReservation']['gross_price']; //publish fare
- $reservation_no=$hotel['HotelReservation']['res_no'];
- $tot_basic_price=$tot_basic_price+(int)$real_amount;
- $tot_gross_price=$tot_gross_price+(int)$amount;
- $tot_profit=$tot_gross_price-$tot_basic_price;
- $current_rate=$this->HotelReservation->Currency->field('current_rate',array('id'=>$currency));
- }
- //debug($amount);
- // debug($real_amount);
- // debug($tot_net_fare);
- // debug($tot_publish_fare);
- // debug($tot_profit);
- // die;
- $data= $this->Auth->user();
- $user_id=$data['User']['id'];
- $branchName=$this->HotelReservation->User->Branch->field('name',array('id'=>$user_id));
- $this->loadModel('Product');
- $this->loadModel('Invoice');
- $this->data['Invoice']['inv_no']= $inv_no;
- $this->data['Invoice']['inv_date']= $rsv_date;
- $this->data['Invoice']['customer_id']=$cust_id;
- $this->data['Invoice']['currency_id']=$currency;
- $this->data['Invoice']['pay_term_id']=$payterm;
- //$this->data['Invoice']['branch_name']=$branch;
- $this->data['Invoice']['amount']=$tot_gross_price;
- $this->data['Invoice']['balance_due']=$tot_gross_price;
- $this->data['Invoice']['real_amount']=$tot_basic_price;
- $this->data['Invoice']['profit']= $tot_profit;
- $this->data['Invoice']['user_id']=$user;
- $this->data['Invoice']['current_rate']= $current_rate;
- $this->data['Invoice']['branch_name']= $branchName;
- $this->data['Invoice']['reservation_no']= $reservation_no;
- $this->data['Invoice']['point']=$point;
- $this->Invoice->save($this->data);
- $arr_id=$_POST['rec_ids'];
- foreach ($arr_id as $id) {
- $hotel=$this->HotelReservation->read(null,$id);
- $book_no=$hotel['HotelReservation']['book_no'];
- $profit=$amount-$real_amount;
- if ($hotel)
- $product_id=$hotel['HotelReservation']['product_id'];
- $filters=array('HotelReservationDetail.hotel_reservation_id'=>$id);
- $hotelDetails=$this->HotelReservation->HotelReservationDetail->find('all',array(
- 'fields'=>array(
- 'HotelReservationDetail.guest_name',
- 'HotelReservationDetail.room_number',
- 'HotelReservationDetail.room_type',
- 'HotelReservationDetail.check_in_date',
- 'HotelReservationDetail.check_out_date',
- 'HotelReservationDetail.time_limit',
- 'HotelReservationDetail.gross_price',
- 'HotelReservationDetail.basic_price',
- 'HotelReservationDetail.profit',
- ),
- 'conditions'=>$filters
- ));
- //-------------inv detail-----------------//
- $pass="";
- $real_prices=0;
- $prices=0;
- $inv_id=$this->Invoice->id;
- //debug($ticketDetails);
- foreach ($hotelDetails as $hotelDetail) {
- $room_number=$hotelDetail['HotelReservationDetail']['room_number'];
- $guest=$hotelDetail['HotelReservationDetail']['guest_name'];
- $i++;
- //$pass .=$passanger;
- $real_prices= $hotelDetail['HotelReservationDetail']['basic_price'];
- $prices=$hotelDetail['HotelReservationDetail']['gross_price'];
- $profit=$hotelDetail['HotelReservationDetail']['profit'];
- $room_type=$hotelDetail['HotelReservationDetail']['room_type'];
- $description=' Room#:'.$room_number."/".$book_no . " ".$product_id .$room_type."/".$guest;
- $data=array('item_no'=>$i,'invoice_id'=>$inv_id,'product_id'=>$product_id);
- $isdeposite=$this->Product->field('isdeposite',array('id'=>$product_id));
- // debug($product_id);
- // debug($data);
- $this->loadModel('InvoiceDetail');
- $this->InvoiceDetail->create();
- $this->data['InvoiceDetail']['item_no']= $i;
- $this->data['InvoiceDetail']['invoice_id']= $inv_id;
- $this->data['InvoiceDetail']['product_id']=$product_id;
- $this->data['InvoiceDetail']['description']=$description;
- $this->data['InvoiceDetail']['price']=$prices;
- $this->data['InvoiceDetail']['real_price']=$real_prices;
- $this->data['InvoiceDetail']['profit']= $profit;
- $this->data['InvoiceDetail']['deposite']= $isdeposite;
- $this->InvoiceDetail->save($this->data);
- }
- $this->HotelReservation->updateAll(
- array('status_reservation_id'=>3),
- array('HotelReservation.id' => $id)
- );
- }
- $this->set('hotelReservations', $this->paginate());
- $customers = $this->HotelReservation->Customer->find('list');
- $filters=array('conditions'=>array('HotelReservation.status_reservation_id'=>3));
- $date_issues = $this->HotelReservation->find('list',
- array('fields'=>array('res_date'),$filters));
- $statusReservations = $this->HotelReservation->StatusReservation->find('list');
- $this->set(compact('customers','statusReservations','date_issues'));
- $this->Session->delete('customer_id');
- $this->Session->delete('status_reservation_id');
- if($this->RequestHandler->isAjax()) {
- $this->layout='ajax';
- $this->autoRender=false;
- $this->viewPath = 'elements'.DS.'hotel_reservations';
- $this->render('index_data');
- }
- }
- function _get_invoice_number() {
- $imonthNow=(idate("m"));
- $iyearNow = (idate("Y"));
- $appMonth=Configure::read('__month_period');
- $appYear=Configure::read('__year_period');
- $inv_prefix=Configure::read('__inv_prefix');
- if (strlen($appMonth) == 1) {
- $month_number = "0" . $appMonth ;
- }else{
- $month_number = $appMonth ;
- }
- $year_number=substr(Configure::read('__year_period'),2,2);
- $inv_lastnumber=Configure::read('__inv_last_number');
- if ($imonthNow == $appMonth) {
- $inv_number = $inv_lastnumber + 1 ;
- }else{
- $inv_number=1;
- }
- if (strlen($inv_number) == 1)
- $str_number=$inv_prefix."-".$year_number. $month_number ."-000" . $inv_number;
- elseif (strlen($inv_number) == 2)
- $str_number=$inv_prefix."-".$year_number. $month_number ."-00" . $inv_number;
- elseif (strlen($inv_number) == 3)
- $str_number=$inv_prefix."-".$year_number. $month_number ."-0" . $inv_number;
- else
- $str_number=$inv_prefix."-".$year_number. $month_number ."-" . $inv_number;
- $saveNumber= $inv_number;
- $criteria="Update ota_settings set value=" . $saveNumber . " Where key='inv_last_number'" ;
- $this->loadModel('Setting');
- $this->Setting->query($criteria);
- return $str_number;
- }
- function _set_reservation_number() {
- $imonthNow=(idate("m"));
- $iyearNow = (idate("Y"));
- $appMonth=Configure::read('__month_period');
- $appYear=Configure::read('__year_period');
- $rst_prefix=Configure::read('__rst_prefix');
- if (strlen($appMonth) == 1) {
- $month_number = "0" . $appMonth ;
- }else{
- $month_number = $appMonth ;
- }
- $year_number=substr(Configure::read('__year_period'),2,2);
- $rst_lastnumber=Configure::read('__rst_last_number');
- if ($imonthNow == $appMonth) {
- $rst_number = $rst_lastnumber + 1 ;
- }else{
- $rst_number=1;
- }
- if (strlen($rst_number) == 1)
- $str_number=$rst_prefix."-".$year_number. $month_number ."-000" . $rst_number;
- elseif (strlen($rst_number) == 2)
- $str_number=$rst_prefix."-".$year_number. $month_number ."-00" . $rst_number;
- elseif (strlen($rst_number) == 3)
- $str_number=$rst_prefix."-".$year_number. $month_number ."-0" . $rst_number;
- else
- $str_number=$rst_prefix."-".$year_number. $month_number ."-" . $rst_number;
- return $str_number;
- }
- function update_product() {
- if($this->RequestHandler->isAjax()) {
- $this->layout='ajax';
- $this->autoRender=false;
- $this->viewPath = 'elements'.DS.'ticket_reservations';
- $this->render('index_data');
- }
- }
- function get_customer_info() {
- $this->layout='ajax';
- $this->autoRender=false;
- $custID=$this->data['HotelReservation']['customer_id'];
- $this->loadModel('Customer');
- $customers=$this->Customer->find('all',
- array('conditions'=>array('Customer.id'=>$custID)));
- foreach ($customers as $customer) {
- $currency=$customer['Currency']['code'];
- $payterm=$customer['PayTerm']['name'];
- $curr_rate=$customer['Currency']['current_rate'];
- $payterm_id=$customer['Customer']['pay_term_id'];
- $credit_limit=$customer['Customer']['credit_limit'];
- $credit_balance=$customer['Customer']['balance'];
- }
- $this->set(compact('currency','payterm','curr_rate','credit_limit','credit_balance','payterm_id'));
- if($this->RequestHandler->isAjax()) {
- $this->layout='ajax';
- $this->autoRender=false;
- $this->viewPath = 'elements'.DS.'hotel_reservations';
- $this->render('customer_info');
- }
- }
- function get_product() {
- $providerID=$this->data['HotelReservation']['provider_id'];
- $products = $this->HotelReservation->Product->find('list',array('conditions'=>array('provider_id'=>$providerID)));
- $this->set('products',$products);
- //debug($products);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement