/** * Get Docs current user is authorised to manage + Process datatables ajax request. */ public function getToolbox(Request $request) { $company_list = [Auth::user()->company->id, Auth::user()->company->reportsToCompany()->id]; //$company_list = [3, 27]; $records = SafetyDoc::select(['id', 'type', 'site_id', 'reportfile', 'name'])->where('type', 'TOOL')->whereIn('company_id', $company_list)->where('status', '1'); $dt = Datatables::of($records)->editColumn('id', '<div class="text-center"><a href="/filebank/whs/toolbox/{{$reportfile}}"><i class="fa fa-file-text-o"></i></a></div>')->make(true); return $dt; }
/** * Get Docs current user is authorised to manage + Process datatables ajax request. */ public function getSDS(Request $request) { if ($request->get('category_id') && $request->get('category_id') != ' ') { $category_list = [$request->get('category_id')]; } else { $category_list = SafetyDocCategory::lists('id')->toArray(); } $company_list = [Auth::user()->company->id, Auth::user()->company->reportsToCompany()->id]; $records = SafetyDoc::select(['id', 'type', 'site_id', 'reportfile', 'name'])->where('type', 'SDS')->whereIn('category_id', $category_list)->whereIn('company_id', $company_list)->where('status', '1'); $dt = Datatables::of($records)->editColumn('id', '<div class="text-center"><a href="/filebank/whs/sds/{{$reportfile}}"><i class="fa fa-file-text-o"></i></a></div>')->make(true); return $dt; }
/** * Migrate Reports */ public function reports() { echo "<h1>Migrating Report Categorys</h1>"; DB::table('safety_docs_categories')->truncate(); DB::table('site_docs_categories')->truncate(); $genCat = SafetyDocCategory::create(array('type' => 'SDS', 'name' => 'General', 'parent' => '0', 'status' => '1', 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); $genCat = SiteDocCategory::create(array('type' => 'RISK', 'name' => 'General', 'parent' => '0', 'status' => '1', 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); set_time_limit(60); $cats = zReportsCats::all(); $cats->each(function ($cat) { echo "<b>" . $cat->type . "</b> - {$cat->name}<br>"; $status = '0'; if ($cat->active == "y") { $status = '1'; } $type = $cat->type; if ($type == 'MSDS') { $type = 'SDS'; } if ($type == 'CWMS') { $type = 'WMS'; } if ($type == 'AAAA') { $type = 'AAA'; } if ($type == 'PLAN') { /*$newCat = SiteDocCategory::create(array( 'type' => $type, 'name' => reformatOldStr($cat->name), 'parent' => $cat->parent, 'status' => $status, 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1', ));*/ } else { if ($type == 'SDS') { $newCat = SiteDocCategory::create(array('type' => 'RISK', 'name' => reformatOldStr($cat->name), 'parent' => $cat->parent, 'status' => $status, 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); } if ($cat->id != 41) { $newCat = SafetyDocCategory::create(array('type' => $type, 'name' => reformatOldStr($cat->name), 'parent' => $cat->parent, 'status' => $status, 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); } } }); $hazCat = SafetyDocCategory::create(array('type' => 'HAZ', 'name' => 'Hazardous Materiels', 'parent' => '0', 'status' => '1', 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); /*$wmsCat = SafetyDocCategory::create(array( 'type' => 'WMS', 'name' => 'Work Method Statement', 'parent' => '0', 'status' => '1', 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1', ));*/ echo "<h1>Completed</h1>"; echo "<h1>Migrating Reports</h1>"; DB::table('site_docs')->truncate(); DB::table('safety_docs')->truncate(); DB::table('wms_docs')->truncate(); $reports = zReports::all(); $reports->each(function ($report) { echo "<b>" . $report->type . "</b> - {$report->reportfile}<br>"; $status = '0'; if ($report->active == "y") { $status = '1'; } $site_id = null; $site = Site::where('code', $report->jobnum)->first(); if ($site) { $site_id = $site->id; } $hazCat = SafetyDocCategory::where('type', 'HAZ')->first(); //$wmsCat = SafetyDocCategory::where('type', 'WMS')->first(); $type = $report->type; $cat = $report->cat; $cid = null; $newdir = 'filebank/'; if ($report->reportfile) { list($dir, $filename) = explode('/', $report->reportfile); switch ($dir) { case 'msds': $type = 'SDS'; $filename = substr($filename, 1); $newdir .= 'whs/sds/'; break; case 'hazard': $type = 'HAZ'; $cat = $hazCat->id; $newdir .= 'site/' . $site->id . '/hazard/'; break; case 'risk': $newdir .= 'site/' . $site->id . '/risk/'; break; case 'plans': /*$cid = $cat; $lookup = DB::table('z_lookup_company')->where('old', $cid)->get(); if ($lookup) $company = Company::find($lookup[0]->new); else $lookup = ['0' => (object) array('new' => '1')]; $cid = $lookup[0]->new;*/ $cat = '0'; $newdir .= 'site/' . $site->id . '/plan/'; break; case 'toolbox': $newdir .= 'whs/toolbox/'; break; case 'workmethod': $cid = $cat; $lookup = DB::table('z_lookup_company')->where('old', $cid)->get(); if ($lookup) { $company = Company::find($lookup[0]->new); } else { $lookup = ['0' => (object) array('new' => '1')]; } $cid = $lookup[0]->new; $newdir .= 'company/' . $cid . '/wms/'; break; } if ($report->updated_by == 'Guest') { $report->updated_by = 'latham'; } $user = User::where('username', $report->updated_by)->first(); if ($type == 'CWMS') { $newWMS = WmsDoc::create(array('name' => reformatOldStr($report->title), 'reportfile' => $filename, 'version' => '1.0', 'status' => '2', 'builder' => '0', 'master' => '0', 'principle' => 'Cape Cod', 'principle_id' => '3', 'principle_signed_id' => $user->id, 'principle_signed_date' => $report->updated, 'for_company_id' => $cid, 'company_id' => '3', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $report->updated, 'updated_at' => $report->updated)); } else { if ($type == 'PLAN' || $type == 'RISK' || $type == 'HAZ') { // readjust category id's to new tables (asuming they added in table order if ($cat == '35') { $cat = 1; } elseif ($cat == '36') { $cat = 1; } elseif ($cat == '37') { $cat = 1; } elseif ($cat == '38') { $cat = 1; } elseif ($cat == '39') { $cat = 1; } elseif ($cat == '40') { $cat = 1; } elseif ($cat == '41') { $cat = 1; } elseif ($cat == '42') { $cat = 36; } elseif ($cat == '43') { $cat = 37; } else { $cat++; } $newReport = SiteDoc::create(array('type' => $type, 'category_id' => $cat, 'site_id' => $site_id, 'reportfile' => $filename, 'name' => reformatOldStr($report->title), 'status' => $status, 'for_company_id' => null, 'company_id' => '3', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $report->updated, 'updated_at' => $report->updated)); } else { // readjust category id's to new tables (asuing they added in table order if ($cat == '41') { $cat = 1; } elseif ($cat == '42') { $cat = 36; } elseif ($cat == '43') { $cat = 37; } else { $cat++; } $newReport = SafetyDoc::create(array('type' => $type, 'category_id' => $cat, 'site_id' => $site_id, 'reportfile' => $filename, 'name' => reformatOldStr($report->title), 'status' => $status, 'for_company_id' => $cid, 'company_id' => '3', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $report->updated, 'updated_at' => $report->updated)); } } // Copy file to new location if (file_exists('filebankOrig/' . $report->reportfile)) { $newfile = $newdir . $filename; if (!file_exists($newdir)) { mkdir($newdir, 0777, true); echo "created directory {$newdir} <br>"; } if (!file_exists($newfile)) { echo "copying to {$newfile}<br>"; if (!copy('filebankOrig/' . $report->reportfile, $newfile)) { echo "*** FAILED to copy {$report->reportfile}...\n"; } } } } }); echo "<h1>Completed</h1>"; }