コード例 #1
0
ファイル: WmsController.php プロジェクト: unclefudge/whs
 /**
  * Get Steps for specific WMS doc
  */
 private function copyTemplate($master_id, $doc_id)
 {
     // Doc
     $master = WmsDoc::find($master_id);
     $doc = WmsDoc::find($doc_id);
     // Increment major version if copying from previous Wms Doc
     if (!$master->master) {
         list($major, $minor) = explode('.', $master->version);
         $major++;
         $doc->version = $major . '.0';
     } else {
         $doc->version = $master->version;
     }
     $doc->save();
     // Steps
     $steps = WmsStep::where('doc_id', $master_id)->get();
     foreach ($steps as $step) {
         $newStep = WmsStep::create(array('doc_id' => $doc_id, 'name' => $step->name, 'order' => $step->order, 'master' => '0', 'master_id' => $step->id));
         // Hazards
         $hazards = WmsHazard::where('step_id', $step->id)->get();
         foreach ($hazards as $hazard) {
             $newHazard = WmsHazard::create(array('step_id' => $newStep->id, 'name' => $hazard->name, 'order' => $hazard->order, 'master' => '0', 'master_id' => $hazard->id));
         }
         // Controls
         $controls = WmsControl::where('step_id', $step->id)->get();
         foreach ($controls as $control) {
             $newControl = WmsControl::create(array('step_id' => $newStep->id, 'name' => $control->name, 'res_principle' => $control->res_principle, 'res_company' => $control->res_company, 'res_worker' => $control->res_worker, 'order' => $control->order, 'master' => '0', 'master_id' => $control->id));
         }
     }
 }
コード例 #2
0
 /**
  * Migrate WMS
  */
 public function wms()
 {
     echo "<h1>Migrating WMS Templates</h1>";
     //DB::table('wms_docs')->truncate();
     DB::table('wms_steps')->truncate();
     DB::table('wms_hazards')->truncate();
     DB::table('wms_controls')->truncate();
     DB::table('z_lookup_template')->truncate();
     set_time_limit(60);
     $reports = zWmsTemplates::all();
     $reports->each(function ($report) {
         echo "<b>Report</b> - {$report->name}<br>";
         $status = '0';
         if ($report->active == "y") {
             $status = '1';
         }
         $user = User::where('username', $report->updated_by)->first();
         $newDoc = WmsDoc::create(array('name' => reformatOldStr($report->name), 'version' => '1.0', 'status' => $status, 'builder' => '1', 'master' => '1', 'company_id' => '3', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $report->updated, 'updated_at' => $report->updated));
         zLookupTemplate::create(array('type' => 'doc', 'old' => $report->id, 'new' => $newDoc->id));
         // Create each Step for the Doc
         $steps = zWmsTemplatesSteps::where('wms_id', $report->id)->get();
         foreach ($steps as $step) {
             echo "<b>Step</b> - {$step->name}<br>";
             if ($report->updated_by == 'Guest') {
                 $user = User::find(1);
             } else {
                 $user = User::where('username', $report->updated_by)->first();
             }
             $newStep = WmsStep::create(array('doc_id' => $newDoc->id, 'name' => reformatOldStr($step->name), 'order' => $step->item_order, 'master' => '1', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $step->updated, 'updated_at' => $step->updated));
             zLookupTemplate::create(array('type' => 'step', 'old' => $step->id, 'new' => $newStep->id));
             // Create each Hazard for the Step
             $hazards = zWmsTemplatesHazards::where('step_id', $step->id)->get();
             $order = 1;
             foreach ($hazards as $hazard) {
                 echo "<b>Hazard</b> - {$hazard->name}<br>";
                 $user = User::where('username', $hazard->updated_by)->first();
                 $newHazard = WmsHazard::create(array('step_id' => $newStep->id, 'name' => reformatOldStr($hazard->name), 'order' => $order++, 'master' => '1', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $hazard->updated, 'updated_at' => $hazard->updated));
                 zLookupTemplate::create(array('type' => 'haz', 'old' => $hazard->id, 'new' => $newHazard->id));
             }
             // Create each Control for the Step
             $controls = zWmsTemplatesControls::where('step_id', $step->id)->get();
             $order = 1;
             foreach ($controls as $control) {
                 echo "<b>Control</b> - {$control->name}<br>";
                 if ($control->updated_by == 'Guest') {
                     $user = User::find(1);
                 } else {
                     $user = User::where('username', $control->updated_by)->first();
                 }
                 $res_p = 0;
                 $res_c = 0;
                 if ($control->responsible == 'x') {
                     $res_c = 1;
                 }
                 if ($control->responsible == '12') {
                     $res_p = 1;
                 }
                 if ($control->responsible == 'cs') {
                     $res_c = 1;
                     $res_p = 1;
                 }
                 $newControl = WmsControl::create(array('step_id' => $newStep->id, 'name' => reformatOldStr($control->name), 'res_principle' => $res_p, 'res_company' => $res_c, 'order' => $order++, 'master' => '1', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $control->updated, 'updated_at' => $control->updated));
                 zLookupTemplate::create(array('type' => 'con', 'old' => $control->id, 'new' => $newControl->id));
             }
         }
     });
     echo "<h1>Completed</h1>";
     echo "<h1>Migrating WMS Docs</h1>";
     $reports = zWmsReports::all();
     $reports->each(function ($report) {
         echo "<b>Report</b> - {$report->name}<br>";
         $status = '0';
         if ($report->active == "y") {
             $status = '1';
         }
         if ($report->active == "p") {
             $status = '2';
         }
         $updated_by = User::where('username', $report->updated_by)->first();
         $cod_signed = User::where('username', $report->cod_signed)->first();
         $sub_signed = User::where('username', $report->sub_signed)->first();
         $cod_signed ? $cod_id = $cod_signed->id : ($cod_id = null);
         $sub_signed ? $sub_id = $sub_signed->id : ($sub_id = null);
         $lookup = DB::table('z_lookup_company')->where('old', $report->company_id)->get();
         if ($lookup) {
             $company = Company::find($lookup[0]->new);
             // Move CC Supers into Cape Cod
             if (substr($company->name, 0, 3) == "CC-") {
                 $lookup[0]->new = '3';
             }
         } else {
             $lookup = ['0' => (object) array('new' => '1')];
         }
         $cid = $lookup[0]->new;
         $master_id = null;
         if ($report->template_id) {
             $lookup = DB::table('z_lookup_template')->where('type', 'doc')->where('old', $report->template_id)->get();
             $master_id = $lookup[0]->new;
         }
         $newDoc = WmsDoc::create(array('name' => reformatOldStr($report->name), 'project' => $report->project, 'version' => '1.0', 'status' => $status, 'builder' => '1', 'master' => '0', 'master_id' => $master_id, 'principle' => 'Cape Cod', 'principle_id' => '3', 'principle_signed_id' => $cod_id, 'principle_signed_date' => $report->cod_date, 'user_signed_id' => $sub_id, 'user_signed_date' => $report->sub_date, 'for_company_id' => $cid, 'company_id' => '3', 'created_by' => $updated_by->id, 'updated_by' => $updated_by->id, 'created_at' => $report->updated, 'updated_at' => $report->updated));
         // Create each Step for the Doc
         $steps = zWmsSteps::where('wms_id', $report->id)->get();
         foreach ($steps as $step) {
             echo "<b>Step</b> - {$step->name}<br>";
             $user = User::where('username', $step->updated_by)->first();
             $master_id = null;
             if ($report->template_id) {
                 $lookup = DB::table('z_lookup_template')->where('type', 'step')->where('old', $step->template_id)->get();
                 $master_id = $lookup[0]->new;
             }
             $newStep = WmsStep::create(array('doc_id' => $newDoc->id, 'name' => reformatOldStr($step->name), 'order' => $step->item_order, 'master' => '0', 'master_id' => $master_id, 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $step->updated, 'updated_at' => $step->updated));
             // Create each Hazard for the Step
             $hazards = zWmsHazards::where('step_id', $step->id)->get();
             $order = 1;
             foreach ($hazards as $hazard) {
                 echo "<b>Hazard</b> - {$hazard->name}<br>";
                 $user = User::where('username', $hazard->updated_by)->first();
                 $master_id = null;
                 if ($report->template_id) {
                     $lookup = DB::table('z_lookup_template')->where('type', 'haz')->where('old', $hazard->template_id)->get();
                     $master_id = $lookup[0]->new;
                 }
                 $newHazard = WmsHazard::create(array('step_id' => $newStep->id, 'name' => reformatOldStr($hazard->name), 'order' => $order++, 'master' => '0', 'master_id' => $master_id, 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $hazard->updated, 'updated_at' => $hazard->updated));
             }
             // Create each Control for the Step
             $controls = zWmsControls::where('step_id', $step->id)->get();
             $order = 1;
             foreach ($controls as $control) {
                 echo "<b>Control</b> - {$control->name}<br>";
                 $user = User::where('username', $control->updated_by)->first();
                 $master_id = null;
                 if ($report->template_id) {
                     $lookup = DB::table('z_lookup_template')->where('type', 'con')->where('old', $control->template_id)->get();
                     $master_id = $lookup[0]->new;
                 }
                 $res_p = 0;
                 $res_c = 0;
                 if (substr($control->responsible, 0, 1) == 'c') {
                     $res_p = 1;
                     $res_c = 1;
                 } else {
                     if ($control->responsible == '12') {
                         $res_p = 1;
                     } else {
                         $res_c = 1;
                     }
                 }
                 $newControl = WmsControl::create(array('step_id' => $newStep->id, 'name' => reformatOldStr($control->name), 'res_principle' => $res_p, 'res_company' => $res_c, 'order' => $order++, 'master' => '0', 'master_id' => $master_id, 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $control->updated, 'updated_at' => $control->updated));
             }
         }
     });
     echo "<h1>Completed</h1>";
 }