示例#1
0
 public function updatePromotion(Request $request, Promotion $promotion)
 {
     $this->validate($request, ['name' => 'required|max:50', 'discount' => 'required|numeric|min:1|max:100', 'type' => 'required|numeric|min:1|max:100', 'image' => 'image', 'promo_date' => 'max:23']);
     $name = $request->name;
     $discount = $request->discount;
     $type = $request->type;
     $description = $request->description;
     if (!empty($request->promo_date)) {
         $dates = explode(" - ", $request->promo_date);
         $promotion->start_date = DateTime::createFromFormat('m/d/Y', $dates[0])->format('Y-m-d');
         $promotion->end_date = DateTime::createFromFormat('m/d/Y', $dates[1])->format('Y-m-d');
         //check if promotion is activated on create
         if ($dates[0] <= new DateTime("now") && $dates[1] > new DateTime("now")) {
             $promotion_status = 1;
         } else {
             $promotion_status = 0;
         }
     }
     if (Input::hasFile('image')) {
         if (File::exists('uploads/' . $cruise->image)) {
             File::delete('uploads/' . $cruise->image);
         }
         $file = Input::file('image');
         $imagename = 'promotion_' . $promotion->id . '.' . Input::file('image')->getClientOriginalExtension();
         $file->move('uploads', $imagename);
         $promotion->image = $imagename;
     }
     switch ($request->type) {
         case 1:
             DB::table('cruises')->where('promotion_id', '=', $promotion->id)->update(['promotion_id' => NULL]);
             $selcruises = Input::get('cruises');
             foreach ($selcruises as $key => $val) {
                 $cruise = Cruise::find($val);
                 $cruise->promotion_id = $promotion->id;
                 $cruise->save();
             }
             break;
         case 2:
             DB::table('cabins')->where('promotion_id', '=', $promotion->id)->update(['promotion_id' => NULL]);
             $cabins = Input::get('cabins');
             foreach ($cabins as $key => $val) {
                 $cabin = Cabin::find($val);
                 $cabin->promotion_id = $promotion->id;
                 $cabin->save();
             }
             break;
         case 3:
             DB::table('amenitites')->where('promotion_id', '=', $promotion->id)->update(['promotion_id' => NULL]);
             $amenities = Input::get('amenities');
             foreach ($amenities as $key => $val) {
                 $amenity = Amenity::find($val);
                 $amenity->promotion_id = $promotion->id;
                 $amenity->save();
             }
     }
     $promotion->save();
     return redirect('/admin/promotion/' . $promotion->id)->with('status', 'Promotion updated!');
 }
示例#2
0
 public static function createPromotionTable($session, $term_id)
 {
     try {
         //create new record for this table in the termly records table
         $promotion = new Promotion();
         $promotion->table_name = 'promotions_' . $session . '_' . $term_id;
         $promotion->session = $session;
         $promotion->term = $term_id;
         $promotion->save();
         \Schema::create('promotions_' . $session . '_' . $term_id, function (Blueprint $table) {
             $table->increments('id');
             $table->integer('student_id');
             $table->integer('class_id');
             $table->integer('average_score');
             $table->softDeletes();
             $table->timestamps();
         });
     } catch (\Illuminate\Database\QueryException $e) {
         $errorCode = $e->errorInfo[1];
         if ($errorCode == 1050) {
             $error_msg[] = 'Promotion table for chosen session and term already exists.';
             // session()->flash('flash_message', 'Invoices table for chosen session and term already exists.');
             // return \Redirect::back()->withInput();
         }
     }
 }