/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $data = $request->all(); // Salva o lote $lote = Lote::create(['descricao' => $data['descricao'], 'obra' => $data['obra_id'], 'fkestagio' => null, 'fketapa' => $data['etapa_id'], 'producao' => null]); if ($lote) { $sys_notifications[] = array('type' => 'success', 'message' => 'Lote criado com sucesso!'); } else { $sys_notifications[] = array('type' => 'danger', 'message' => 'Não foi possível criar o lote'); $request->session()->flash('sys_notifications', $sys_notifications); return back()->withInput($request->all()); } // Salva o Cronograma do Conjunto $data['fkobra'] = $data['obra_id']; $data['fketapa'] = $data['etapa_id']; $handles_ids = array(); foreach (@$data['handles_ids'] as $handle_id) { if ($request->has('grouped')) { $handles_conjunto = Handle::find($handle_id)->group(); foreach ($handles_conjunto as $handle) { // Atualiza HANDLE [lote] $handle->fklote = $lote->id; $handle->save(); $handles_ids[] = $handle->id; } } else { $handl = Handle::find($handle_id); // Atualiza HANDLE [lote] $handl->fklote = $lote->id; $handl->save(); $handles_ids[] = $handl->id; } } foreach ($data as $key => $value) { if (empty($value)) { unset($data[$key]); } } $cronosaved = 0; foreach ($handles_ids as $handle_id) { $data['fkpeca'] = $handle_id; $data['fklote'] = $lote->id; $cjtcrono = CjtCrono::create($data); if ($cjtcrono) { $cronosaved++; } } if ($cronosaved > 0) { $sys_notifications[] = array('type' => 'success', 'message' => 'Novo Conograma criado com ' . $cronosaved . ' itens!'); } else { $sys_notifications[] = array('type' => 'danger', 'message' => 'Não foi possível criar o CRONOGRAMA!'); $request->session()->flash('sys_notifications', $sys_notifications); return back()->withInput($request->all()); } $request->session()->flash('sys_notifications', $sys_notifications); return back()->withInput($request->all()); }