Guest User

Untitled

a guest
Jan 7th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.69 KB | None | 0 0
  1. function promote_invoice1() {
  2. $loggedIn=$this->Auth->user();
  3. $userBranch=$loggedIn['User']['branch_id'];
  4. $userRole=$loggedIn['User']['role_id'];
  5. $this->loadModel('Role');
  6. $roleName=$this->Role->field('Role.name',array('Role.id'=>$userRole));
  7.  
  8. $tot_net_fare=0;
  9. $tot_publish_fare=0;
  10. $arr_id=$_POST['rec_ids'];
  11. $i=0;
  12. $inv_no=$this-> _get_invoice_number();
  13.  
  14. foreach ($arr_id as $id) {
  15.  
  16.  
  17. $hotel=$this->HotelReservation->read(null,$id);
  18. /*---------------Get Customer Invo------------------------'*/
  19. $rsv_date=$hotel['HotelReservation']['issued_date'];
  20. $cust_id=$hotel['HotelReservation']['customer_id'];
  21. $currency=$hotel['Customer']['currency_id'];
  22. $payterm=$hotel['Customer']['pay_term_id'];
  23. $user=$hotel['HotelReservation']['user_id'];
  24. $point=$this->HotelReservation->field('point',array('HotelReservation.id'=>$id));
  25. $real_amount= (int)$hotel['HotelReservation']['basic_price']; //Net to Agent
  26. $amount=(int)$hotel['HotelReservation']['gross_price']; //publish fare
  27. $voucher_no = $hotel['HotelReservation']['voucher_no'];
  28. $reservation_no=$hotel['HotelReservation']['res_no'];
  29. $checkIn=$hotel['HotelReservation']['check_in_date'];
  30. $checkOut=$hotel['HotelReservation']['check_out_date'];
  31. $tot_basic_price=$tot_basic_price+(int)$real_amount;
  32. $tot_gross_price=$tot_gross_price+(int)$amount;
  33. $tot_profit=$tot_gross_price-$tot_basic_price;
  34. $current_rate=$this->HotelReservation->Currency->field('current_rate',array('id'=>$currency));
  35.  
  36. if ($payterm!=1) {
  37.  
  38. $termDay=$this->HotelReservation->PayTerm->field('due_day',array('PayTerm.id'=>$payterm));
  39. $addDate ="+".$termDay."'";
  40. $newDate = strtotime ( '+30 day' , strtotime ( $rsv_date ) ) ;
  41. $dueDate = date ( 'Y-m-j' , $newDate );
  42. }else{
  43. $dueDate=$rsv_date;
  44. }
  45.  
  46.  
  47.  
  48. };
  49.  
  50.  
  51. $data= $this->Auth->user();
  52. $user_id=$data['User']['id'];
  53. $branch_id=$data['User']['branch_id'];
  54.  
  55.  
  56. $this->loadModel('Product');
  57. $this->loadModel('Invoice');
  58.  
  59. $this->data['Invoice']['inv_no']= $inv_no;
  60. $this->data['Invoice']['inv_date']= $rsv_date;
  61. $this->data['Invoice']['due_date']= $dueDate;
  62. $this->data['Invoice']['customer_id']=$cust_id;
  63. $this->data['Invoice']['currency_id']=$currency;
  64. $this->data['Invoice']['pay_term_id']=$payterm;
  65. $this->data['Invoice']['amount']=$tot_publish_fare;//Total di invoice nanti (subtotal+tax+disc)
  66. $this->data['Invoice']['subtotal']=$tot_publish_fare;//sub Total
  67. $this->data['Invoice']['balance_due']=$tot_publish_fare;
  68. $this->data['Invoice']['outstanding']=$tot_publish_fare;
  69. $this->data['Invoice']['real_amount']=$tot_net_fare; //net
  70. $this->data['Invoice']['profit']= $tot_profit;
  71. $this->data['Invoice']['user_id']= $user_id;
  72. $this->data['Invoice']['current_rate']= $current_rate;
  73. $this->data['Invoice']['branch_id']= $branch_id;
  74. $this->data['Invoice']['reservation_no']= $reservation_no;
  75. $this->Invoice->save($this->data);
  76.  
  77. $arr_id=$_POST['rec_ids'];
  78. foreach ($arr_id as $id) {
  79.  
  80. $hotel=$this->HotelReservation->read(null,$id);
  81. $book_no=$hotel['HotelReservation']['res_no'];
  82. //$class_type=$ticket['HotelReservation']['class'];
  83. //$f_route=$ticket['HotelReservation']['flight_route'];
  84. $provider_alias=$hotel['Provider']['alias'];
  85. $provider_name=$hotel['Provider']['name'];
  86. //debug($airline);
  87.  
  88. $profit=$amount-$real_amount;
  89. if ($ticket)
  90. $product_id=$ticket['HotelReservation']['product_id'];
  91. $filters=array('HotelReservationDetail.hotel_reservation_id'=>$id);
  92. $hotelDetails=$this->HotelReservation->HotelReservationDetail->find('all',array(
  93. 'fields'=>array(
  94. 'HotelReservationDetail.guest_name',
  95. 'HotelReservationDetail.room_number',
  96. 'HotelReservationDetail.time_limit',
  97. 'HotelReservationDetail.gross_price',
  98. 'HotelReservationDetail.basic_fare',
  99. 'HotelReservationDetail.profit',
  100. ),
  101. 'conditions'=>$filters
  102.  
  103. ));
  104.  
  105.  
  106.  
  107. //-------------inv detail-----------------//
  108. $pass="";
  109. $real_prices=0;
  110. $prices=0;
  111.  
  112.  
  113. $inv_id=$this->Invoice->id;
  114. //debug($ticketDetails);
  115. foreach ($hotelDetails as $hotelDetail) {
  116.  
  117. $hotel_number=$hotelDetail['HotelReservationDetail']['room_number'];
  118. $guest=$hotelDetail['HotelReservationDetail']['guest_title']. ",".
  119. $hotelDetail['HotelReservationDetail']['guest_name'];
  120.  
  121. $i++;
  122. $real_prices= $hotelDetail['HotelReservationDetail']['basic_fare'];
  123. $prices=$hotelDetail['HotelReservationDetail']['gross_fare'];
  124. $profit=$hotelDetail['HotelReservationDetail']['profit'];
  125.  
  126. $description=$book_no." ".$voucher_no." ".$hotel_number . " ".$guest;
  127.  
  128.  
  129. $providerName=$this->Product->field('name',array('id'=>$product_id));
  130. $product_ref='Hotel '. $providerName . " ". $hotel_number;
  131. $data=array('item_no'=>$i,'invoice_id'=>$inv_id,'product_id'=>$product_id);
  132.  
  133. $tr_type=$this->Product->field('transaction_type_id',array('id'=>$product_id));
  134.  
  135. $this->loadModel('InvoiceDetail');
  136. $this->InvoiceDetail->create();
  137. $this->data['InvoiceDetail']['item_no']= $i;
  138. $this->data['InvoiceDetail']['invoice_id']=$inv_id;
  139. $this->data['InvoiceDetail']['product_id']=$product_id;
  140. $this->data['InvoiceDetail']['description']=$description;
  141. $this->data['InvoiceDetail']['price']=$prices;
  142. $this->data['InvoiceDetail']['real_price']=$real_prices;
  143. $this->data['InvoiceDetail']['profit']= $profit;
  144. $this->data['InvoiceDetail']['transaction_type_id']= $tr_type;
  145. $this->data['InvoiceDetail']['product_ref']= $product_ref;
  146. $this->data['InvoiceDetail']['refundable']= $refundable;
  147. $this->InvoiceDetail->save($this->data);
  148.  
  149.  
  150. }
  151.  
  152. //create letter of guarantee-----------
  153.  
  154. $guarantees=$this->HotelReservation->find('all',array(
  155. 'conditions'=>array('AND'=>array(
  156. array('HotelReservation.id'=>$id),
  157. array('HotelReservation.product_id'=>$product_id)
  158.  
  159. ))
  160.  
  161. ));
  162.  
  163. //$lg_description=$flight_no." ".$ticket_class." ".$f_route . " ".strtotime ($departure_date);
  164.  
  165. $lg_description=$hotel_number." ".$voucher_no." ";
  166.  
  167. $provider_id=$this->HotelReservation->Product->field('provider_id',array('id'=>$product_id));
  168.  
  169. $this->loadModel('GuaranteeLetter');
  170. $amount=0;
  171. $balance_amount=0;
  172. $lg_curr=null;
  173.  
  174.  
  175. foreach ($guarantees as $guarantee) {
  176.  
  177. $lg_no=$this-> _get_lg_number();
  178. $balance_amount=$guarantee['HotelReservation']['net_fare'];
  179. $amount=$guarantee['HotelReservation']['net_fare'];
  180. $lg_curr=$guarantee['HotelReservation']['currency_id'];
  181. $lg_rate=$guarantee['HotelReservation']['rate'];
  182.  
  183. $lg_checkin_date=date("d M Y", strtotime($guarantee['HotelReservation']['check_in_date']));
  184. $lg_checkout_date=date("d M Y", strtotime($guarantee['HotelReservation']['check_out_date']));
  185. $lg_dep_time=date("H:i", strtotime($guarantee['HotelReservation']['check_in_date']));
  186. $lg_arr_time=date("H:i", strtotime($guarantee['HotelReservation']['check_out_date']));
  187. $lg_desc=$providerName." ". $product_ref." ".$lg_dep_date." ".$lg_dep_time."-".$lg_arr_time;
  188.  
  189. $tr_type=$this->Product->field('transaction_type_id',array('id'=>$product_id));
  190. $this->GuaranteeLetter->create();
  191. $this->data['GuaranteeLetter']['lg_no']= $lg_no;
  192. $this->data['GuaranteeLetter']['lg_date']=$rsv_date;
  193. $this->data['GuaranteeLetter']['invoice_id']=$inv_id;
  194. $this->data['GuaranteeLetter']['product_id']= $product_id;
  195. $this->data['GuaranteeLetter']['description']=$lg_desc ; //$description;
  196. $this->data['GuaranteeLetter']['currency_id']=$lg_curr;
  197. $this->data['GuaranteeLetter']['current_rate']=$lg_rate;
  198. $this->data['GuaranteeLetter']['amount']=$amount;
  199. $this->data['GuaranteeLetter']['balance_amount']=$balance_amount;
  200. $this->data['GuaranteeLetter']['user_id']=$user_id;
  201. $this->data['GuaranteeLetter']['branch_id']=$branch_id;
  202. $this->data['GuaranteeLetter']['transaction_type_id']=$tr_type;
  203. $this->data['GuaranteeLetter']['currency']=$currency;
  204. $this->data['GuaranteeLetter']['provider_id']=$provider_id;
  205. $this->data['GuaranteeLetter']['status_guarantee_id']=1;
  206. $this->data['GuaranteeLetter']['refundable']=$refundable;
  207. $this->data['GuaranteeLetter']['ticket_reservation_id']=$id;
  208. $this->GuaranteeLetter->save($this->data);
  209.  
  210. $description=null;
  211. $lg_id=$this->GuaranteeLetter->id;
  212. $filters=array('HotelReservationDetail.ticket_reservation_id'=>$id);
  213. $ticketDetails=$this->HotelReservation->HotelReservationDetail->find('all',array(
  214. 'fields'=>array(
  215. 'HotelReservationDetail.guest_title',
  216. 'HotelReservationDetail.guest_name',
  217. 'HotelReservationDetail.net_fare',
  218. 'HotelReservationDetail.room_number',
  219.  
  220.  
  221. ),
  222. 'conditions'=>$filters
  223.  
  224. ));
  225.  
  226.  
  227. foreach ($hotelDetails as $hotelDetail) {
  228.  
  229.  
  230. $guest_name=$guestDetail['HotelReservationDetail']['guest_title']. " ".$ticketDetail['TicketReservationDetail']['passanger_name'];
  231. $ref_no=$ticketDetail['HotelReservationDetail']['ticket_number'];
  232. $i++;
  233. //$pass .=$passanger;
  234. $prices=$ticketDetail['HotelReservationDetail']['net_fare'];
  235.  
  236. $this->loadModel('GuaranteeLetterDetail');
  237. $this->GuaranteeLetterDetail->create();
  238. // $this->data['GuaranteeLetterDetail']['description']=$lg_description . " " .$passanger_name;
  239. $this->data['GuaranteeLetterDetail']['description']=$lg_desc." - ".$ref_no;
  240.  
  241. $this->data['GuaranteeLetterDetail']['price']=$prices;
  242. $this->data['GuaranteeLetterDetail']['invoice_price']=$prices;
  243. //$this->data['GuaranteeLetterDetail']['invoice_currency']=$prices;
  244. $this->data['GuaranteeLetterDetail']['guarantee_letter_id']=$lg_id;
  245. $this->data['GuaranteeLetterDetail']['product_id']=$product_id;
  246. $this->data['GuaranteeLetterDetail']['person_name']=$guest_name;
  247. $this->data['GuaranteeLetterDetail']['ref_no']=$ref_no;
  248. $this->GuaranteeLetterDetail->save($this->data);
  249.  
  250. }
  251.  
  252.  
  253. }
  254.  
  255.  
  256.  
  257.  
  258. $this->loadModel('Setting');
  259. $lg_lastnumber=Configure::read('__lg_last_number');
  260. $saveNumber=$lg_lastnumber+1;
  261.  
  262. $id = $this->Setting->field('id',array('key'=>'lg_last_number'));
  263. $this->Setting->id=$id;
  264. $this->Setting->updateAll(array('Setting.value'=>$saveNumber),array('key'=>'lg_last_number'));
  265.  
  266.  
  267.  
  268. //update_ticket_status
  269. $this->HotelReservation->id;
  270. $this->HotelReservation->saveField('status_reservation_id',4);
  271. }
  272.  
  273.  
  274. $this->set('hotelReservations', $this->paginate());
  275. $customers = $this->HotelReservation->Customer->find('list');
  276. $airlines = $this->HotelReservation->Provider->find('list');
  277. $date_issues = $this->HotelReservation->find('list',
  278. array('fields'=>array('res_date'),$filters));
  279. $statusReservations = $this->HotelReservation->StatusReservation->find('list');
  280.  
  281.  
  282.  
  283. $this->set(compact('customers','hotel','statusReservations','date_issues','userBranch','roleName','tr_type'));
  284.  
  285.  
  286.  
  287. if($this->RequestHandler->isAjax()) {
  288. $this->layout='ajax';
  289. $this->autoRender=false;
  290. $this->viewPath = 'elements'.DS.'ticket_reservations';
  291. $this->render('index_data');
  292. }
  293.  
  294. }
Add Comment
Please, Sign In to add comment