Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function promote_invoice1() {
- $loggedIn=$this->Auth->user();
- $userBranch=$loggedIn['User']['branch_id'];
- $userRole=$loggedIn['User']['role_id'];
- $this->loadModel('Role');
- $roleName=$this->Role->field('Role.name',array('Role.id'=>$userRole));
- $tot_net_fare=0;
- $tot_publish_fare=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['Customer']['currency_id'];
- $payterm=$hotel['Customer']['pay_term_id'];
- $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
- $voucher_no = $hotel['HotelReservation']['voucher_no'];
- $reservation_no=$hotel['HotelReservation']['res_no'];
- $checkIn=$hotel['HotelReservation']['check_in_date'];
- $checkOut=$hotel['HotelReservation']['check_out_date'];
- $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));
- if ($payterm!=1) {
- $termDay=$this->HotelReservation->PayTerm->field('due_day',array('PayTerm.id'=>$payterm));
- $addDate ="+".$termDay."'";
- $newDate = strtotime ( '+30 day' , strtotime ( $rsv_date ) ) ;
- $dueDate = date ( 'Y-m-j' , $newDate );
- }else{
- $dueDate=$rsv_date;
- }
- };
- $data= $this->Auth->user();
- $user_id=$data['User']['id'];
- $branch_id=$data['User']['branch_id'];
- $this->loadModel('Product');
- $this->loadModel('Invoice');
- $this->data['Invoice']['inv_no']= $inv_no;
- $this->data['Invoice']['inv_date']= $rsv_date;
- $this->data['Invoice']['due_date']= $dueDate;
- $this->data['Invoice']['customer_id']=$cust_id;
- $this->data['Invoice']['currency_id']=$currency;
- $this->data['Invoice']['pay_term_id']=$payterm;
- $this->data['Invoice']['amount']=$tot_publish_fare;//Total di invoice nanti (subtotal+tax+disc)
- $this->data['Invoice']['subtotal']=$tot_publish_fare;//sub Total
- $this->data['Invoice']['balance_due']=$tot_publish_fare;
- $this->data['Invoice']['outstanding']=$tot_publish_fare;
- $this->data['Invoice']['real_amount']=$tot_net_fare; //net
- $this->data['Invoice']['profit']= $tot_profit;
- $this->data['Invoice']['user_id']= $user_id;
- $this->data['Invoice']['current_rate']= $current_rate;
- $this->data['Invoice']['branch_id']= $branch_id;
- $this->data['Invoice']['reservation_no']= $reservation_no;
- $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']['res_no'];
- //$class_type=$ticket['HotelReservation']['class'];
- //$f_route=$ticket['HotelReservation']['flight_route'];
- $provider_alias=$hotel['Provider']['alias'];
- $provider_name=$hotel['Provider']['name'];
- //debug($airline);
- $profit=$amount-$real_amount;
- if ($ticket)
- $product_id=$ticket['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.time_limit',
- 'HotelReservationDetail.gross_price',
- 'HotelReservationDetail.basic_fare',
- 'HotelReservationDetail.profit',
- ),
- 'conditions'=>$filters
- ));
- //-------------inv detail-----------------//
- $pass="";
- $real_prices=0;
- $prices=0;
- $inv_id=$this->Invoice->id;
- //debug($ticketDetails);
- foreach ($hotelDetails as $hotelDetail) {
- $hotel_number=$hotelDetail['HotelReservationDetail']['room_number'];
- $guest=$hotelDetail['HotelReservationDetail']['guest_title']. ",".
- $hotelDetail['HotelReservationDetail']['guest_name'];
- $i++;
- $real_prices= $hotelDetail['HotelReservationDetail']['basic_fare'];
- $prices=$hotelDetail['HotelReservationDetail']['gross_fare'];
- $profit=$hotelDetail['HotelReservationDetail']['profit'];
- $description=$book_no." ".$voucher_no." ".$hotel_number . " ".$guest;
- $providerName=$this->Product->field('name',array('id'=>$product_id));
- $product_ref='Hotel '. $providerName . " ". $hotel_number;
- $data=array('item_no'=>$i,'invoice_id'=>$inv_id,'product_id'=>$product_id);
- $tr_type=$this->Product->field('transaction_type_id',array('id'=>$product_id));
- $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']['transaction_type_id']= $tr_type;
- $this->data['InvoiceDetail']['product_ref']= $product_ref;
- $this->data['InvoiceDetail']['refundable']= $refundable;
- $this->InvoiceDetail->save($this->data);
- }
- //create letter of guarantee-----------
- $guarantees=$this->HotelReservation->find('all',array(
- 'conditions'=>array('AND'=>array(
- array('HotelReservation.id'=>$id),
- array('HotelReservation.product_id'=>$product_id)
- ))
- ));
- //$lg_description=$flight_no." ".$ticket_class." ".$f_route . " ".strtotime ($departure_date);
- $lg_description=$hotel_number." ".$voucher_no." ";
- $provider_id=$this->HotelReservation->Product->field('provider_id',array('id'=>$product_id));
- $this->loadModel('GuaranteeLetter');
- $amount=0;
- $balance_amount=0;
- $lg_curr=null;
- foreach ($guarantees as $guarantee) {
- $lg_no=$this-> _get_lg_number();
- $balance_amount=$guarantee['HotelReservation']['net_fare'];
- $amount=$guarantee['HotelReservation']['net_fare'];
- $lg_curr=$guarantee['HotelReservation']['currency_id'];
- $lg_rate=$guarantee['HotelReservation']['rate'];
- $lg_checkin_date=date("d M Y", strtotime($guarantee['HotelReservation']['check_in_date']));
- $lg_checkout_date=date("d M Y", strtotime($guarantee['HotelReservation']['check_out_date']));
- $lg_dep_time=date("H:i", strtotime($guarantee['HotelReservation']['check_in_date']));
- $lg_arr_time=date("H:i", strtotime($guarantee['HotelReservation']['check_out_date']));
- $lg_desc=$providerName." ". $product_ref." ".$lg_dep_date." ".$lg_dep_time."-".$lg_arr_time;
- $tr_type=$this->Product->field('transaction_type_id',array('id'=>$product_id));
- $this->GuaranteeLetter->create();
- $this->data['GuaranteeLetter']['lg_no']= $lg_no;
- $this->data['GuaranteeLetter']['lg_date']=$rsv_date;
- $this->data['GuaranteeLetter']['invoice_id']=$inv_id;
- $this->data['GuaranteeLetter']['product_id']= $product_id;
- $this->data['GuaranteeLetter']['description']=$lg_desc ; //$description;
- $this->data['GuaranteeLetter']['currency_id']=$lg_curr;
- $this->data['GuaranteeLetter']['current_rate']=$lg_rate;
- $this->data['GuaranteeLetter']['amount']=$amount;
- $this->data['GuaranteeLetter']['balance_amount']=$balance_amount;
- $this->data['GuaranteeLetter']['user_id']=$user_id;
- $this->data['GuaranteeLetter']['branch_id']=$branch_id;
- $this->data['GuaranteeLetter']['transaction_type_id']=$tr_type;
- $this->data['GuaranteeLetter']['currency']=$currency;
- $this->data['GuaranteeLetter']['provider_id']=$provider_id;
- $this->data['GuaranteeLetter']['status_guarantee_id']=1;
- $this->data['GuaranteeLetter']['refundable']=$refundable;
- $this->data['GuaranteeLetter']['ticket_reservation_id']=$id;
- $this->GuaranteeLetter->save($this->data);
- $description=null;
- $lg_id=$this->GuaranteeLetter->id;
- $filters=array('HotelReservationDetail.ticket_reservation_id'=>$id);
- $ticketDetails=$this->HotelReservation->HotelReservationDetail->find('all',array(
- 'fields'=>array(
- 'HotelReservationDetail.guest_title',
- 'HotelReservationDetail.guest_name',
- 'HotelReservationDetail.net_fare',
- 'HotelReservationDetail.room_number',
- ),
- 'conditions'=>$filters
- ));
- foreach ($hotelDetails as $hotelDetail) {
- $guest_name=$guestDetail['HotelReservationDetail']['guest_title']. " ".$ticketDetail['TicketReservationDetail']['passanger_name'];
- $ref_no=$ticketDetail['HotelReservationDetail']['ticket_number'];
- $i++;
- //$pass .=$passanger;
- $prices=$ticketDetail['HotelReservationDetail']['net_fare'];
- $this->loadModel('GuaranteeLetterDetail');
- $this->GuaranteeLetterDetail->create();
- // $this->data['GuaranteeLetterDetail']['description']=$lg_description . " " .$passanger_name;
- $this->data['GuaranteeLetterDetail']['description']=$lg_desc." - ".$ref_no;
- $this->data['GuaranteeLetterDetail']['price']=$prices;
- $this->data['GuaranteeLetterDetail']['invoice_price']=$prices;
- //$this->data['GuaranteeLetterDetail']['invoice_currency']=$prices;
- $this->data['GuaranteeLetterDetail']['guarantee_letter_id']=$lg_id;
- $this->data['GuaranteeLetterDetail']['product_id']=$product_id;
- $this->data['GuaranteeLetterDetail']['person_name']=$guest_name;
- $this->data['GuaranteeLetterDetail']['ref_no']=$ref_no;
- $this->GuaranteeLetterDetail->save($this->data);
- }
- }
- $this->loadModel('Setting');
- $lg_lastnumber=Configure::read('__lg_last_number');
- $saveNumber=$lg_lastnumber+1;
- $id = $this->Setting->field('id',array('key'=>'lg_last_number'));
- $this->Setting->id=$id;
- $this->Setting->updateAll(array('Setting.value'=>$saveNumber),array('key'=>'lg_last_number'));
- //update_ticket_status
- $this->HotelReservation->id;
- $this->HotelReservation->saveField('status_reservation_id',4);
- }
- $this->set('hotelReservations', $this->paginate());
- $customers = $this->HotelReservation->Customer->find('list');
- $airlines = $this->HotelReservation->Provider->find('list');
- $date_issues = $this->HotelReservation->find('list',
- array('fields'=>array('res_date'),$filters));
- $statusReservations = $this->HotelReservation->StatusReservation->find('list');
- $this->set(compact('customers','hotel','statusReservations','date_issues','userBranch','roleName','tr_type'));
- if($this->RequestHandler->isAjax()) {
- $this->layout='ajax';
- $this->autoRender=false;
- $this->viewPath = 'elements'.DS.'ticket_reservations';
- $this->render('index_data');
- }
- }
Add Comment
Please, Sign In to add comment