/** * Function that searches for past trips. * * @return Response */ public function searchVehicleTrips() { // Validate Input. $validator = Validator::make(Input::all(), array('vehicle' => 'required', 'start' => 'required', 'end' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'Informacion incompleta!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(array()); } // Get trips. $start = date('Y-m-d', strtotime(Input::get('start'))); $end = date('Y-m-d', strtotime(Input::get('end'))); $trips = Transport::where('VehicleId', '=', Input::get('vehicle'))->where('Date', '>=', $start)->where('Date', '<=', $end)->where('State', '=', 1)->groupBy('Date')->orderBy('Order')->get(); $tripData = array(); foreach ($trips as $trip) { $driver = Worker::find($trip->DriverId); $reason = ''; switch ($trip->Type) { case 1: // Get sale breakdown. $breakdown = SaleBreakdown::find($trip->ReasonId); // Get product or service. $product = Stock::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $driver->BranchId)->first(); if ($product) { $reason = 'Venta de ' . $product->Description; } else { $service = Service::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $driver->BranchId)->first(); $reason = 'Venta de ' . $service->Description; } break; case 2: // Get sale. $sale = Sale::find($trip->ReasonId); // Get client or institution. if ($sale->CreditorType == 1) { if ($sale->CreditorId == 0) { $reason = 'Venta a cliente no definido'; } else { $client = Client::find($sale->CreditorId); $reason = 'Venta a ' . $client->Name; } } else { $institution = Institution::find($sale->CreditorId); $reason = 'Venta a ' . $institution->Name; } break; case 3: // Get order breakdown. $breakdown = OrderBreakdown::find('OrderId', '=', $trip->ReasonId); // Get product or service. $product = Stock::where('Code', '=', $breakdown->Code)->where('BranchId', '=', $driver->BranchId)->first(); $reason = 'Produccion de ' . $product->Description; break; case 4: // Get order. $order = Order::find($trip->ReasonId); // Get client or institution. $client = Client::find($order->ClientId); if ($client->InstitutionId == 0) { $reason = 'Orden de Produccion de ' . $client->Name; } else { $institution = Institution::find($client->InstitutionId); $reason = 'Orden de Produccion de ' . $institution->Name; } break; case 5: // Get storage request. $request = StorageRequest::find($trip->ReasonId); $reason = $request->Reason; break; case 6: // Get visit. $visit = Visit::find($trip->ReasonId); $reason = 'Visita ' . $visit->Result; break; case 7: // Get credit bill. $creditBill = Sale::find($trip->ReasonId); $reason = 'Cobro de Facturo: ' . $creditBill->Id; break; case 8: // Contract Payment. $contract = Contract::find($trip->ReasonId); $reason = 'Cobro de Contrato: ' . $contract->Code; break; case 9: // Provider purchase. $aiOrder = AIOrder::find($trip->ReasonId); $reason = 'Compra automatica ' . $aiOrder->Id; break; case 10: $reason = 'Generado por usuario.'; break; } array_push($tripData, array('Id' => $trip->Id, 'Date' => $trip->Date, 'Driver' => $driver->Name, 'Reason' => $reason, 'Distance' => $trip->Distance, 'Journey' => json_decode($trip->Journey, true), 'StartLat' => $trip->StartLatitude, 'StartLon' => $trip->StartLongitude, 'EndLat' => $trip->EndLatitude, 'EndLon' => $trip->EndLongitude)); } $response['state'] = 'Success'; $response['trips'] = $tripData; return response()->json($response); }
use App\User; use App\Worker; use App\Branch; use App\UserLevel; use App\Notification; use App\AIOrder; use App\AIOrderBreakdown; use App\Stock; use App\Service; use App\Provider; $currentNotification = Notification::find($notification); $currentNotification->Seen = true; $currentNotification->save(); $permissions = json_decode(UserLevel::find(Auth::user()->UserLevel)->Permissions); $order = AIOrder::find($id); $orderBreakdown = AIOrderBreakdown::where('AIOrderId', '=', $order->Id)->get(); $worker = Worker::find(Auth::user()->TypeId); $branch = Branch::find($worker->BranchId); $provider = Provider::find($order->ProviderId); ?> <!DOCTYPE html> <html lang="es"> <head> <title>Eirene Systema Administrativo</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta charset="UTF-8"> <meta name="csrf-token" content="{{{ Session::token() }}}"> <link href="{{ URL::to('/') }}/css/bootstrap.min.css" rel="stylesheet"> <link href="{{ URL::to('/') }}/css/bootstrap-responsive.min.css" rel="stylesheet">