Beispiel #1
0
 public function postDelete()
 {
     $id = Input::get('id');
     $delsch = Payments::find($id);
     $delsch->delete();
     return 1;
 }
Beispiel #2
0
 public function getSave()
 {
     $id = Input::get('id');
     $year = date('Y');
     $month = date('m');
     $date = date('d');
     $now = date('Y-m-d');
     if ($id) {
         // print_r($_POST);
         $employee_id = Input::get('employee_id');
         if ($employee_id) {
             $employee_id = Input::get('employee_id');
         } else {
             $employee_id = NULL;
         }
         $bs = BookingServices::where('booking_id', $id);
         $bs->delete();
         $br = BookingRooms::where('booking_id', $id);
         $br->delete();
         $bookings = Bookings::find($id);
         $service_id = Input::get('service_id');
         $TOTAL = 0;
         for ($i = 0; $i < count($service_id); $i++) {
             $cek_bs = BookingServices::where('service_id', '=', $service_id[$i])->first();
             if (empty($cek_bs)) {
                 $booking_service = new BookingServices();
                 $d_service = Services::find($service_id[$i]);
                 $booking_service->booking_id = $id;
                 $booking_service->service_id = $service_id[$i];
                 $booking_service->price = $d_service->price;
                 $TOTAL += $d_service->price;
                 $booking_service->save();
             }
         }
         $room_id = Input::get('room_id');
         for ($j = 0; $j < count($room_id); $j++) {
             $cek_r = BookingRooms::where('room_id', '=', $room_id[$j])->first();
             if (empty($cek_r)) {
                 $booking_room = new BookingRooms();
                 $d_room = Room::find($room_id[$j]);
                 $d_room->booked = 1;
                 $booking_room->booking_id = $id;
                 $booking_room->room_id = $room_id[$j];
                 $booking_room->price = $d_room->type->price;
                 $booking_room->save();
                 $d_room->save();
                 $TOTAL += $d_room->type->price;
             }
         }
         $bookings->guest_id = Input::get('guest_id');
         $bookings->employee_id = $employee_id;
         $bookings->number_of_days = Input::get('number_of_days');
         $bookings->date_booking = Input::get('date_booking');
         $bookings->date_booking_from = Input::get('date_booking');
         $bookings->date_booking_to = Input::get('date_booking_to');
         $bookings->save();
         $holiday = date('D');
         if ($holiday == 'Sat' || $holiday == 'Sun') {
             $disc = 0.05;
         } else {
             $disc = 0;
         }
         $TOTAL = $TOTAL * $bookings->number_of_days;
         $discount = $TOTAL * $disc;
         $grand_total = $TOTAL - $discount;
         $py = Payments::where('booking_id', '=', $id)->first();
         $payment = Payments::find($py->id);
         $payment->subtotal = $TOTAL;
         $payment->disc = $disc;
         $payment->grand_total = $grand_total;
         $payment->cashed = 0;
         $payment->save();
         Session::flash('message', 'The records are updated successfully');
         return Redirect::to('bookings/show/' . $id);
     } else {
         $data = Bookings::orderBy('id', 'desc')->first();
         if (isset($data->id)) {
             $index = $data->id + 1;
         } else {
             $index = 1;
         }
         $x = strlen($index);
         $y = null;
         for ($i = 4; $i > $x; $i--) {
             $y .= '0';
         }
         $y .= $index;
         $booking_code = $year . '' . $month . '' . $date . '' . $y;
         $employee_id = Input::get('employee_id');
         if ($employee_id) {
             $employee_id = Input::get('employee_id');
         } else {
             $employee_id = NULL;
         }
         $bookings = new Bookings();
         $bookings->booking_code = $booking_code;
         $bookings->guest_id = Input::get('guest_id');
         $bookings->employee_id = $employee_id;
         $bookings->number_of_days = Input::get('number_of_days');
         $bookings->date_booking = Input::get('date_booking');
         $bookings->date_booking_from = Input::get('date_booking');
         $bookings->date_booking_to = Input::get('date_booking_to');
         $bookings->save();
         $last = Bookings::orderBy('id', 'desc')->first();
         $last_id = $last->id;
         $service_id = Input::get('service_id');
         $TOTAL = 0;
         for ($i = 0; $i < count($service_id); $i++) {
             $cek_bs = BookingServices::where('service_id', '=', $service_id[$i])->first();
             if (empty($cek_bs)) {
                 $booking_service = new BookingServices();
                 $d_service = Services::find($service_id[$i]);
                 $booking_service->booking_id = $last_id;
                 $booking_service->service_id = $service_id[$i];
                 $booking_service->price = $d_service->price;
                 $booking_service->save();
                 $TOTAL += $d_service->price;
             }
         }
         $room_id = Input::get('room_id');
         for ($j = 0; $j < count($room_id); $j++) {
             $cek_r = BookingRooms::where('room_id', '=', $room_id[$j])->first();
             if (empty($cek_r)) {
                 $booking_room = new BookingRooms();
                 $d_room = Room::find($room_id[$j]);
                 $d_room->booked = 1;
                 $booking_room->booking_id = $last_id;
                 $booking_room->room_id = $room_id[$j];
                 $booking_room->price = $d_room->type->price;
                 $booking_room->save();
                 $d_room->save();
                 $TOTAL += $d_room->type->price;
             }
         }
         $TOTAL = $TOTAL * $bookings->number_of_days;
         $holiday = date('D');
         if ($holiday == 'Sat' || $holiday == 'Sun') {
             $disc = 0.05;
         } else {
             $disc = 0;
         }
         $discount = $TOTAL * $disc;
         $grand_total = $TOTAL - $discount;
         $payment = new Payments();
         $payment->booking_id = $last_id;
         $payment->subtotal = $TOTAL;
         $payment->disc = $disc;
         $payment->grand_total = $grand_total;
         $payment->cashed = 0;
         $payment->save();
         Session::flash('message', 'The records are inserted successfully');
         return Redirect::to('bookings/show/' . $last_id);
     }
 }
Beispiel #3
0
    /**
     * Get Last Client Payments to session
     * @return array
     */
    public static function getLastClientsPayment()
    {
        $lastPayment = array();

        $payments = new Payments();
        $condition = new CDbCriteria();
        $condition->join = "LEFT JOIN documents ON documents.Document_ID=t.Document_ID";
        $condition->addCondition("documents.Client_ID='" . Yii::app()->user->clientID . "'");

        if (is_numeric(Yii::app()->user->projectID)) {
            $condition->addCondition("documents.Project_ID= '" . Yii::app()->user->projectID . "'");
        }

        $condition->order = "t.Payment_ID DESC";
        $payment = $payments->find($condition);

        if ($payment) {
            $lastPayment[1] = $payment->Document_ID;
        }

        return $lastPayment;
    }