public function postUpdatepackage()
 {
     $input = Input::all();
     $input['updated_by'] = Auth::user()->id;
     $check = PackageAssumption::where('id', '!=', Input::get('id'))->where('name', '=', Input::get('name'))->where('description', '=', Input::get('description'))->where('active', '=', 1)->where('project_id', '=', Session::get('project_id'))->get();
     if ($check->isEmpty()) {
         $category = PackageAssumption::find(Input::get('id'));
         $category->update($input);
         return Redirect::to('package-assumption');
     } else {
         return Redirect::to('package-assumption')->withErrors('Package Assumption duplicate!');
     }
 }
 public function getExportproject()
 {
     $project_arr = array();
     $project_arr = explode(' ', Input::get('projectname'));
     $project_name = implode('_', $project_arr);
     $datefile = date('dmY');
     $ranfile = rand(11111, 99999);
     $foldername = $project_name . '_' . $ranfile . '_' . $datefile;
     $basic_equipment = array();
     $basic_equipment = BasicEquipment::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'category_id', 'type_id', 'part_id'));
     if (!$basic_equipment->isEmpty()) {
         $filename = '001_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($basic_equipment) {
             $excel->sheet('basic_equipment', function ($sheet) use($basic_equipment) {
                 $sheet->fromArray($basic_equipment);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $basic_failure = array();
     $basic_failure = BasicFailure::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'mode_id', 'cause_id'));
     if (!$basic_failure->isEmpty()) {
         $filename = '002_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($basic_failure) {
             $excel->sheet('basic_failure', function ($sheet) use($basic_failure) {
                 $sheet->fromArray($basic_failure);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $basic_task = array();
     $basic_task = BasicTask::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'cause_id', 'type_id', 'list_id'));
     if (!$basic_task->isEmpty()) {
         $filename = '003_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($basic_task) {
             $excel->sheet('basic_task', function ($sheet) use($basic_task) {
                 $sheet->fromArray($basic_task);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_category = array();
     $ref_category = RefCategory::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'description'));
     if (!$ref_category->isEmpty()) {
         $filename = '004_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_category) {
             $excel->sheet('ref_category', function ($sheet) use($ref_category) {
                 $sheet->fromArray($ref_category);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_fail_cause = array();
     $ref_fail_cause = RefFailureCause::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'description'));
     if (!$ref_fail_cause->isEmpty()) {
         $filename = '005_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_fail_cause) {
             $excel->sheet('ref_fail_cause', function ($sheet) use($ref_fail_cause) {
                 $sheet->fromArray($ref_fail_cause);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_fail_mode = array();
     $ref_fail_mode = RefFailureMode::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'description'));
     if (!$ref_fail_mode->isEmpty()) {
         $filename = '006_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_fail_mode) {
             $excel->sheet('ref_fail_mode', function ($sheet) use($ref_fail_mode) {
                 $sheet->fromArray($ref_fail_mode);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_non = array();
     $ref_non = RefNonCriticalQuestion::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'questions'));
     if (!$ref_non->isEmpty()) {
         $filename = '007_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_non) {
             $excel->sheet('ref_non', function ($sheet) use($ref_non) {
                 $sheet->fromArray($ref_non);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_order_type = array();
     $ref_order_type = RefOrderType::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'name', 'description'));
     if (!$ref_order_type->isEmpty()) {
         $filename = '008_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_order_type) {
             $excel->sheet('ref_order_type', function ($sheet) use($ref_order_type) {
                 $sheet->fromArray($ref_order_type);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_part = array();
     $ref_part = RefPart::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'description'));
     if (!$ref_part->isEmpty()) {
         $filename = '009_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_part) {
             $excel->sheet('ref_part', function ($sheet) use($ref_part) {
                 $sheet->fromArray($ref_part);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_task_interval = array();
     $ref_task_interval = RefTaskInterval::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'interval', 'description'));
     if (!$ref_task_interval->isEmpty()) {
         $filename = '010_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_task_interval) {
             $excel->sheet('ref_task_interval', function ($sheet) use($ref_task_interval) {
                 $sheet->fromArray($ref_task_interval);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_task_list = array();
     $ref_task_list = RefTaskList::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'description'));
     if (!$ref_task_list->isEmpty()) {
         $filename = '011_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_task_list) {
             $excel->sheet('ref_task_list', function ($sheet) use($ref_task_list) {
                 $sheet->fromArray($ref_task_list);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_task_type = array();
     $ref_task_type = RefTaskType::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'description'));
     if (!$ref_task_type->isEmpty()) {
         $filename = '012_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($ref_task_type) {
             $excel->sheet('ref_task_type', function ($sheet) use($ref_task_type) {
                 $sheet->fromArray($ref_task_type);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $ref_type = array();
     $ref_type = RefType::where('project_id', Input::get('project_id'))->where('type_use', 2)->where('active', 1)->get(array('id', 'description'));
     if (!$ref_type->isEmpty()) {
         $filename = '013_' . $ranfile . '_' . $datefile;
         Excel::resetValueBinder();
         $file = Excel::create($filename, function ($excel) use($ref_type) {
             $excel->sheet('ref_type', function ($sheet) use($ref_type) {
                 $sheet->fromArray($ref_type);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $asset_registers = array();
     $asset_registers = AssetRegister::where('active', 1)->where('project_id', Input::get('project_id'))->get();
     if (!$asset_registers->isEmpty()) {
         $filename = '014_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($asset_registers) {
             $excel->sheet('asset_registers', function ($sheet) use($asset_registers) {
                 $sheet->fromModel($asset_registers);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $asset_complex_detail = array();
     $asset_complex_detail = AssetComplexDetail::where('active', 1)->where('project_id', Input::get('project_id'))->get();
     if (!$asset_complex_detail->isEmpty()) {
         $filename = '015_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($asset_complex_detail) {
             $excel->sheet('asset_complex_detail', function ($sheet) use($asset_complex_detail) {
                 $sheet->fromArray($asset_complex_detail);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $asset_basic_failure = array();
     $asset_basic_failure = AssetBasicFailure::where('active', 1)->where('project_id', Input::get('project_id'))->get();
     if (!$asset_basic_failure->isEmpty()) {
         $filename = '016_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($asset_basic_failure) {
             $excel->sheet('asset_basic_failure', function ($sheet) use($asset_basic_failure) {
                 $sheet->fromArray($asset_basic_failure);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $asset_questions = array();
     $asset_questions = AssetQuestion::where('active', 1)->where('project_id', Input::get('project_id'))->get();
     if (!$asset_questions->isEmpty()) {
         $filename = '017_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($asset_questions) {
             $excel->sheet('asset_questions', function ($sheet) use($asset_questions) {
                 $sheet->fromArray($asset_questions);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $task_selection = array();
     $task_selection = TaskSelection::where('active', 1)->where('project_id', Input::get('project_id'))->get();
     if (!$task_selection->isEmpty()) {
         $filename = '018_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($task_selection) {
             $excel->sheet('task_selection', function ($sheet) use($task_selection) {
                 $sheet->fromArray($task_selection);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     $package_assumptions = array();
     $package_assumptions = PackageAssumption::where('active', 1)->where('project_id', Input::get('project_id'))->get();
     if (!$package_assumptions->isEmpty()) {
         $filename = '019_' . $ranfile . '_' . $datefile;
         $file = Excel::create($filename, function ($excel) use($package_assumptions) {
             $excel->sheet('package_assumptions', function ($sheet) use($package_assumptions) {
                 $sheet->fromArray($package_assumptions);
             });
         })->store('csv', 'public/backup/export/' . $foldername);
         $filenamezip = "public/backup/export/" . $foldername . ".zip";
         $files = glob($file->storagePath . "/*");
         Zipper::make($filenamezip)->add($files);
     }
     Zipper::close();
     return Response::download($filenamezip);
 }