/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $extra = Extra::findOrFail($id); $extra->update($request->all()); return redirect()->route('product-size.show', $request->product_size_id); }
/** * Formats a messy form and presents the user with a confirmation page (form) before * proceeding to payment. */ public function confirmEntry(Request $request) { // returns a confirm view which then sends the user to the store function above. $data = $request->all(); $user = Auth::user(); $event = Event::findOrFail($data['event_id']); $compSubTotal = 0; $extraSubTotal = 0; //Format the competitions for display in the confirmation form $entries = array(); //$competitions[$id] = array('detail' => $detail, 'competition' => $competition) foreach ($data['competitions'] as $competition_id => $detail_id) { if ($detail_id != "noEntry") { $competition = Competition::findOrFail($competition_id); $detail = Detail::findOrFail($detail_id); $entries[$competition_id] = array('competition' => $competition, 'detail' => $detail); $compSubTotal += $competition->fee; } } //if for some reason the competitor has forgotten to select a competition, bump them back. if (empty($entries)) { \Flash::error('You need to select a competition to enter before you can proceed.'); return redirect(action('EventsController@show', $event->slug)); } //Format the extras for display in the confirmation form $extras = array(); if (key_exists('extras', $data)) { foreach ($data['extras'] as $extra_id => $extraOrder) { $multiple = 1; $infoRequired = NULL; if (is_string($extraOrder) == False) { //This is an extra order with an array of info if (array_key_exists('multiple', $extraOrder)) { $multiple = $extraOrder['multiple']; } if (array_key_exists('infoRequired', $extraOrder)) { $infoRequired = $extraOrder['infoRequired']; } } $extra = Extra::findOrFail($extra_id); $thisExtraTotal = $extra->cost * $multiple; $extraSubTotal += $thisExtraTotal; $extras[$extra_id] = array('id' => $extra_id, 'multiple' => $multiple, 'infoRequired' => $infoRequired, 'extra' => $extra, 'thisExtraCost' => $thisExtraTotal); } } //Format the discounts so that the fixed and percentage discounts //can be applied separately, fixed first. $discounts = array(); $fixedDiscounts = array(); $percentageDiscounts = array(); $discounts_applied = ""; if (key_exists('discounts', $data)) { foreach ($data['discounts'] as $discount_id => $discountApply) { if ($discountApply == 1) { $discount = Discount::findOrFail($discount_id); $discounts[] = $discount; $discounts_applied = $discounts_applied . $discount_id . "-"; } } $discounts = collect($discounts); $fixedDiscounts = $discounts->where('type', 'fixed'); $percentageDiscounts = $discounts->where('type', 'percentage'); } //total (just competitions and extras) $compExtraSubtotal = $compSubTotal + $extraSubTotal; //Apply any discounts to the compextrasubtotal & registration fee //fixed fees first, then %. $discountedSubtotal = $compExtraSubtotal; $discountedRegistrationFee = $event->registrationFee; $percentageDiscountValues = array(); foreach ($fixedDiscounts as $fd) { $discountedSubtotal = $discountedSubtotal - $fd->value; } foreach ($percentageDiscounts as $pd) { $percentage = $pd->value / 100; $discount = $discountedSubtotal * $percentage; $percentageDiscountValues[$pd->id] = $discount; $discountedSubtotal = $discount; $discountedRegistrationFee = $discountedRegistrationFee * $percentage; } //Charge a late entry fee? //if it's past the closing date $lateEntryFee = 0; if (Carbon::now()->gt($event->closingDate)) { $lateEntryFee = $event->lateEntriesFee; } //FORESIGHT FEE $foresightFee = 2.99; $finalsubtotal = $discountedSubtotal + $discountedRegistrationFee + $lateEntryFee + $foresightFee; //paypal fees (3.4% + 20p) $paypalFees = $finalsubtotal * 0.034 + 0.2; $feesTotal = $discountedRegistrationFee + $lateEntryFee + $foresightFee + $paypalFees; $grandTotal = $finalsubtotal + $paypalFees; $format = "%4.2f"; $variables = array('entrydata' => $data, 'event' => $event, 'user' => $user, 'entries' => $entries, 'extras' => $extras, 'fixedDiscounts' => $fixedDiscounts, 'percentageDiscounts' => $percentageDiscounts, 'percentageDiscountValues' => $percentageDiscountValues, 'compSubTotal' => sprintf($format, $compSubTotal), 'extraSubTotal' => sprintf($format, $extraSubTotal), 'compExtraSubtotal' => sprintf($format, $compExtraSubtotal), 'discountedSubtotal' => sprintf($format, $discountedSubtotal), 'discountedRegistrationFee' => sprintf($format, $discountedRegistrationFee), 'lateEntryFee' => sprintf($format, $lateEntryFee), 'paypalFees' => sprintf($format, $paypalFees), 'feesTotal' => sprintf($format, $feesTotal), 'grandTotal' => sprintf($format, $grandTotal), 'discounts_applied' => $discounts_applied, 'foresightFee' => sprintf($format, $foresightFee)); //dd($variables); return view('events.entryconfirm')->with($variables); }