/** * Process form request to create report * * This will generate report for distribution * realization. * * @param Request $request * @return Response */ public function postDistRealization(Request $request) { $this->validate($request, ['edition_id' => 'required|numeric']); /** // Prepare data for report $DistPlan = DistPlan::with('details.agent') ->where('edition_id', '=', $request->edition_id) ->first(); $DistReal = DistRealization::with('details.agent') ->where('edition_id', '=', $request->edition_id) ->first(); */ $DistPlan = DistPlan::where('edition_id', '=', $request->edition_id)->first(); $DistReal = DistRealization::with('edition.magazine')->where('edition_id', '=', $request->edition_id)->first(); // if empty, don't render any result if (!$DistPlan or !$DistReal) { $msg = "Tidak ditemukan perencanaan atau realisasi"; return redirect('report/create-dist-realization')->with('errMsg', $msg); } $DistPlanDet = DistPlanDet::with('agent.agent_category')->where('distribution_plan_id', '=', $DistPlan->id)->get(); $DistRealDet = DistRealDet::with('agent.agent_category')->where('distribution_realization_id', '=', $DistReal->id)->get(); // Change structure so that $DistPlanDet // and $DistRealDet are keyed by agent_id $agent_DistPlanDet = $DistPlanDet->keyBy('agent_id'); $agent_DistRealDet = $DistRealDet->keyBy('agent_id'); // Get agent details $keys = $agent_DistPlanDet->keys(); $agents = Agent::with('agent_category')->whereIn('id', $keys->all())->orderBy('agent_category_id', 'asc')->get(); // Now, return agents aggregat return view('report/preview-dist-realization', ['distReal' => $DistReal, 'distPlanDet' => $agent_DistPlanDet, 'distRealDet' => $agent_DistRealDet, 'agents' => $agents]); }
/** * Show the form for creating a new resource. * * @return Response */ public function create($distPlanID) { //To remove duplicate, get agent NOT listed in $distPlanID $addedAgents = DistPlanDet::with('agent')->where('distribution_plan_id', '=', $distPlanID)->get(); //Convert to array $agents = []; foreach ($addedAgents as $detail) { $agents[] = $detail->agent->id; } $unAssignedAgent = Agent::select('id', 'name')->whereNotIn('id', $agents)->get(); return view('circulation/distribution-plan-details-form', ['agents' => $unAssignedAgent, 'distPlanID' => $distPlanID, 'form_action' => action("DistributionPlanDetController@store", [$distPlanID])]); }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $agents = Agent::all(); $editions = Edition::with('magazine')->get(); return view('invoice/invoice-form', ['invType' => 'Quota', 'agents' => $agents, 'eds' => $editions]); }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $agents = Agent::all(); $editions = Edition::with('magazine')->get(); return view('circulation/return-form', ['agents' => $agents, 'editions' => $editions, 'edition_detail_action' => action('ReturnController@postAddEditionDetail'), 'form_action' => action('ReturnController@store'), 'return_item_count' => 1]); }
/** * Process request to create new relationship * * @param Request request * @return Response */ public function postCreateRelationship(Request $request) { $this->validate($request, ['magazine_id' => 'required|numeric', 'agent_id' => 'required|numeric']); $agent_id = $request->agent_id; $magazine_id = $request->magazine_id; // Get current agent try { $agent = Agent::findOrFail($agent_id); $magazine = Magazine::findOrFail($magazine_id); } catch (ModelNotFoundException $e) { $errMsg = "Cannot find agent/magazine! Error on `CreateRelationship` with agent ID={$agent_id} and magazine ID={$magazine_id}"; return redirect('masterdata/agent')->with('errMsg', $errMsg); } $agent = $agent->magazine()->save($magazine); // Add new entry return redirect("masterdata/agent/relationship/{$agent_id}")->with('message', 'Added new relationship!'); }