function getPachetPretMinim($packID) { return PacheteCamere::where('PackID', $packID)->min('Price'); }
public function ajaxVerificarePretPachetPas1(Request $request) { $formData = []; foreach ($request->formData as $value) { $formData[$value['name']] = $value['value']; } $nrCamere = $formData['Camere']; $idPlecare = $formData['Plecare']; // DB::enableQueryLog(); $oferte = PacheteCamere::select('Name', DB::raw('sum(Price) as Price'), 'Currency', 'PackID')->where('EntryID', $idPlecare)->groupBy('EntryID')->where(function ($query) use($nrCamere, $formData) { for ($i = 1; $i <= $nrCamere; $i++) { $infanti = 0; if ($formData['Copii_Cam' . $i] != 0) { for ($j = 1; $j <= $formData['Copii_Cam' . $i]; $j++) { if ($formData['varstaCopil' . $j . '_Cam' . $i] <= 1) { $infanti = $infanti + 1; } } } else { $infanti = 0; } // dump($infanti); $array[$i] = ['Adults' => $formData['Adulti_Cam' . $i], 'Childs' => $formData['Copii_Cam' . $i], 'Infants' => $infanti]; $packs = $query->orWhere($array[$i], 'and'); } })->get(); // dd(DB::getQueryLog()); $intrare = PacheteIntrari::where('EntryID', $idPlecare)->first(); $pachet = Pachete::where('PackID', $intrare->PackID)->first(); // afisez camerele pentru packid si entryid $camere = []; for ($i = 1; $i <= $nrCamere; $i++) { $infanti = 0; $varste = []; if ($formData['Copii_Cam' . $i] != 0) { for ($j = 1; $j <= $formData['Copii_Cam' . $i]; $j++) { array_push($varste, $formData['varstaCopil' . $j . '_Cam' . $i]); if ($formData['varstaCopil' . $j . '_Cam' . $i] <= 1) { $infanti = $infanti + 1; } } } else { $infanti = 0; } $array = ['EntryID' => $intrare->EntryID, 'PackID' => $intrare->PackID, 'Adults' => $formData['Adulti_Cam' . $i], 'Childs' => $formData['Copii_Cam' . $i], 'Infants' => $infanti]; $sql = PacheteCamere::where($array, 'and')->first(); // dump($sql); array_push($camere, ['RoomID' => $sql->RoomID, 'EntryID' => $sql->EntryID, 'RoomName' => $sql->RoomName, 'RoomType' => $sql->RoomType, 'RoomFeature' => $sql->RoomFeature, 'Adults' => $sql->Adults, 'Childs' => $sql->Childs, 'Ages' => $varste, 'Price' => $sql->Price, 'Currency' => $sql->Currency]); } // dd($camere); // dump(DB::getQueryLog()); dump($camere); // dump($oferte); // dd($oferte); return (string) view('frontend.ajax.raspuns-pachete-disponibile')->with('intrare', $intrare)->with('pachet', $pachet)->with('oferte', $oferte)->with('camere', $camere); }