function generateWorkTickets($pID) { $ticks = ProjectPart::where('in_project', 1)->where('project_id', $pID)->get(); foreach ($ticks as $tick) { Workticket::create(['project_id' => $pID, 'part_id' => $tick->part_listing_id, 'scopestatus_id' => 1]); } // end foreach return $pID; }
public function listByUser($id) { $user = Auth::user(); if ($user->all_companies) { $projects = Project::with($this->related)->get(); } else { $projects = Project::with($this->related)->where('company_id', $user->company_id)->all(); } foreach ($projects as $pro) { $cntParts = ProjectPart::where('project_id', $pro->id)->where('in_project', true)->count(); $cntMarket = ProjectPart::where('project_id', $pro->id)->where('in_project', true)->where('can_sell', true)->count(); $pro->in_market = $cntMarket; $pro->total_parts = $cntParts; if ($cntParts == 0) { $pro->percentage = 0; } else { $pro->percentage = $cntMarket / $cntParts; } } return $projects; }