예제 #1
0
 public function batchPost(BatchPostRequest $request)
 {
     $input = $request->all();
     $token = strtok($input['folio_num'], " ");
     while ($token !== false) {
         $baseCost = DB::table('services')->select('base_cost')->where('service_id', '=', $input['service_id'])->first();
         //getting the tax percentages
         $tax_code = DB::table('services')->select('tax_code')->where('service_id', '=', $input['service_id'])->first();
         $tax_rate = DB::table('tax_rates')->select('percentage')->where('tax_code', '=', $tax_code->tax_code)->first();
         //getting the customer_payable status of the selected service IMPLEMENT THIS!!!-------------(A)
         /*$payStatus = DB::table('services')->select('guest_payable')->where('service_id', '=', $input['service_id'])->first();*/
         //creating a model and saving to folio_services table
         try {
             folio_services::create(['service_id' => $input['service_id'], 'folio_num' => $token, 'date' => Carbon::now(), 'price' => ($baseCost->base_cost + $baseCost->base_cost * $tax_rate->percentage) * floatval($input['service_qty']), 'service_count' => $input['service_qty']]);
             //updating the folio table
             $credit_balance = DB::table('folio')->select('credit_total')->where('folio_num', '=', $token)->first();
             $total_balance = DB::table('folio')->select('prog_balance')->where('folio_num', '=', $token)->first();
             $credit_balance->credit_total = $credit_balance->credit_total + ($baseCost->base_cost + $baseCost->base_cost * $tax_rate->percentage) * floatval($input['service_qty']);
             $total_balance->prog_balance = $total_balance->prog_balance + ($baseCost->base_cost + $baseCost->base_cost * $tax_rate->percentage) * floatval($input['service_qty']) * 1.11;
             DB::table('folio')->where('folio_num', $token)->update(['credit_total' => $credit_balance->credit_total, 'prog_balance' => $total_balance->prog_balance]);
         } catch (QueryException $e) {
             $folios = folio::all();
             $services = DB::table('services')->select('service_id')->get();
             $exception_msg = 1;
             //return $folios;
             return view("Cashiering/FolioManagement", compact('folios', 'services', 'exception_msg'));
         }
         $token = strtok(" ");
         //increment the tokenizer's pointer
     }
     return redirect('/payments/');
 }
 function checkin()
 {
     try {
         $input = Request::all();
         $res_id = $input['res_id'];
         DB::table('reservation')->where('res_id', '=', $res_id)->update(['status' => 'Checked_In']);
         //changing guest status in the folio
         DB::table('folio')->where('res_id', '=', $res_id)->update(['guest_status' => 'Checked_In']);
         //adding Room Charges
         $no_of_nights = DB::table('reservation')->where('res_id', '=', $res_id)->value('nights');
         $variable = DB::table('room_reservation_rate')->where('res_id', '=', $res_id)->select('room_id')->get();
         foreach ($variable as $var) {
             $type = DB::table('room')->where('room_id', '=', $var->room_id)->value('type_id');
             $rate = DB::table('reservation_room_type_count')->where('type_id', '=', $type)->where('res_id', '=', $res_id)->value('rate_code');
             $rate_value = DB::table('rate')->where('rate_code', '=', $rate)->value('rate');
             $total = $rate_value * $no_of_nights;
             $folio_num = DB::table('folio')->where('res_id', '=', $res_id)->where('room_id', '=', $var->room_id)->value('folio_num');
             //start
             try {
                 folio_services::create(['service_id' => "RMCHRG", 'folio_num' => $folio_num, 'date' => Carbon::now(), 'price' => $total, 'service_count' => "1"]);
                 //updating the folio table
                 $credit_balance = DB::table('folio')->select('credit_total')->where('folio_num', '=', $folio_num)->first();
                 $total_balance = DB::table('folio')->select('prog_balance')->where('folio_num', '=', $folio_num)->first();
                 $credit_balance->credit_total = $credit_balance->credit_total + $total;
                 $total_balance->prog_balance = $total_balance->prog_balance + $total;
                 DB::table('folio')->where('folio_num', $folio_num)->update(['credit_total' => $credit_balance->credit_total, 'prog_balance' => $total_balance->prog_balance, 'Rate_code' => $rate]);
             } catch (QueryException $e) {
                 /*$folios = folio::all();
                   $services = DB::table('services')->select('service_id')->get();
                   $exception_msg = 1;
                   return view("Cashiering/FolioManagement", compact('folios', 'services', 'exception_msg'));*/
                 return redirect('/FO_mainpage')->with(['exception' => 'You have errors in your last request.Try again!']);
                 //redirect the user to the corresponding folio to view the new record.
                 /*return redirect('/payments/view/'.$input['folio_num']);*/
                 //end
             }
         }
         return redirect('/checkin')->with(['succ_status' => 'Successfully Checked-In']);
     } catch (Exception $e) {
         return redirect('/FO_mainpage')->with(['exception' => 'You have errors in your last request.Try again!']);
     }
 }