/**
  * Remove the specified resource from storage.
  *
  * Deletion will also remove all of its relationships
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     try {
         $distPlan = DistPlan::with('details')->findOrFail($id);
         //Ok? Destroy with relationships
         $this->delete_record($distPlan);
         $execMsg = "Delete successful!";
     } catch (ModelNotFoundException $e) {
         //In case of failure on deletion/finding data, set errMsg
         $execMsg = "Cannot delete record. Data not found.";
         return redirect('circulation/distribution-plan')->with('errMsg', $execMsg);
     }
     return redirect('circulation/distribution-plan')->with('message', $execMsg);
 }
 /**
  * Show comparisons between plan and realization
  *
  * @param int $distRealizationID
  * @param int $distPlanID
  * @return Response
  */
 public function compare($distRealizationID, $distPlanID)
 {
     $dist_real = DistRealize::with('details.agent')->find($distRealizationID);
     // Check if distPlanID match with $distRealizationID
     if ($dist_real->distribution_plan_id != $distPlanID) {
         return redirect()->back()->with('errMsg', 'Mismatched IDs!');
     }
     $dist_plan = DistPlan::with('details.agent')->find($distPlanID);
     // Try to combine both of them based on agent_id
     $agent_plan = $dist_plan->details->keyBy('agent_id');
     $agent_real = $dist_real->details->keyBy('agent_id');
     return view('circulation/distribution-realization-compare', ['agent_plan' => $agent_plan, 'agent_real' => $agent_real]);
 }