예제 #1
0
function guardarReporteACPM($fechaAccion, $idModulo, $tipoAccion, $descripcionAccion)
{
    $reporteACPM = DB::select("Select MAX(idReporteACPM) as idReporteACPM\n      From reporteacpm \n      where Compania_idCompania = " . \Session::get("idCompania"));
    $reporte = get_object_vars($reporteACPM[0])["idReporteACPM"];
    if ($reporte != "") {
        $indice = array('ReporteACPM_idReporteACPM' => $reporte, 'Modulo_idModulo' => $idModulo, 'tipoReporteACPMDetalle' => $tipoAccion, 'descripcionReporteACPMDetalle' => $descripcionAccion);
        $data = array('ReporteACPM_idReporteACPM' => $reporte, 'ordenReporteACPMDetalle' => 0, 'fechaReporteACPMDetalle' => $fechaAccion, 'Proceso_idProceso' => NULL, 'Modulo_idModulo' => $idModulo, 'tipoReporteACPMDetalle' => $tipoAccion, 'descripcionReporteACPMDetalle' => $descripcionAccion, 'analisisReporteACPMDetalle' => '', 'correccionReporteACPMDetalle' => '', 'Tercero_idResponsableCorrecion' => NULL, 'planAccionReporteACPMDetalle' => '', 'Tercero_idResponsablePlanAccion' => NULL, 'fechaEstimadaCierreReporteACPMDetalle' => '0000-00-00', 'estadoActualReporteACPMDetalle' => '', 'fechaCierreReporteACPMDetalle' => '0000-00-00', 'eficazReporteACPMDetalle' => 0);
    } else {
        DB::statement('INSERT into reporteacpm (idReporteACPM, numeroReporteACPM, fechaElaboracionReporteACPM, descripcionReporteACPM, Compania_idCompania) values (0, 1, "0000-00-00", "Acciones correctivas, preventivas y de mejora", ' . \Session::get("idCompania") . ')');
        $reporteACPM = DB::select("Select MAX(idReporteACPM) as idReporteACPM\n          From reporteacpm \n          where Compania_idCompania = " . \Session::get("idCompania"));
        $reporte = get_object_vars($reporteACPM[0])["idReporteACPM"];
        $indice = array('ReporteACPM_idReporteACPM' => $reporte, 'Modulo_idModulo' => $idModulo, 'tipoReporteACPMDetalle' => $tipoAccion, 'descripcionReporteACPMDetalle' => $descripcionAccion);
        $data = array('ReporteACPM_idReporteACPM' => $reporte, 'ordenReporteACPMDetalle' => 0, 'Proceso_idProceso' => NULL, 'Modulo_idModulo' => $idModulo, 'tipoReporteACPMDetalle' => $tipoAccion, 'descripcionReporteACPMDetalle' => $descripcionAccion, 'analisisReporteACPMDetalle' => '', 'correccionReporteACPMDetalle' => '', 'Tercero_idResponsableCorrecion' => NULL, 'planAccionReporteACPMDetalle' => '', 'Tercero_idResponsablePlanAccion' => NULL, 'fechaEstimadaCierreReporteACPMDetalle' => '0000-00-00', 'estadoActualReporteACPMDetalle' => '', 'fechaCierreReporteACPMDetalle' => '0000-00-00', 'eficazReporteACPMDetalle' => 0);
    }
    $respuesta = \App\ReporteACPMDetalle::updateOrCreate($indice, $data);
}
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(ReporteACPMRequest $request, $id)
 {
     if ($request['respuesta'] != 'falso') {
         $reporteACPM = \App\ReporteACPM::find($id);
         $reporteACPM->fill($request->all());
         $reporteACPM->save();
         $idsEliminar = explode(',', $request['eliminarReporteACPMDetalle']);
         \App\ReporteACPMDetalle::whereIn('idReporteACPMDetalle', $idsEliminar)->delete();
         $contadorDetalle = count($request['ordenReporteACPMDetalle']);
         for ($i = 0; $i < $contadorDetalle; $i++) {
             $indice = array('idReporteACPMDetalle' => $request['idReporteACPMDetalle'][$i]);
             $datos = array('ReporteACPM_idReporteACPM' => $id, 'ordenReporteACPMDetalle' => $request['ordenReporteACPMDetalle'][$i], 'fechaReporteACPMDetalle' => $request['fechaReporteACPMDetalle'][$i], 'Proceso_idProceso' => $request['Proceso_idProceso'][$i] == '' ? NULL : $request['Proceso_idProceso'][$i], 'Modulo_idModulo' => $request['Modulo_idModulo'][$i], 'tipoReporteACPMDetalle' => $request['tipoReporteACPMDetalle'][$i], 'descripcionReporteACPMDetalle' => $request['descripcionReporteACPMDetalle'][$i], 'analisisReporteACPMDetalle' => $request['analisisReporteACPMDetalle'][$i], 'correccionReporteACPMDetalle' => $request['correccionReporteACPMDetalle'][$i], 'Tercero_idResponsableCorrecion' => $request['Tercero_idResponsableCorrecion'][$i] == '' ? NULL : $request['Tercero_idResponsableCorrecion'][$i], 'planAccionReporteACPMDetalle' => $request['planAccionReporteACPMDetalle'][$i], 'Tercero_idResponsablePlanAccion' => $request['Tercero_idResponsablePlanAccion'][$i] == '' ? NULL : $request['Tercero_idResponsablePlanAccion'][$i], 'fechaEstimadaCierreReporteACPMDetalle' => $request['fechaEstimadaCierreReporteACPMDetalle'][$i], 'estadoActualReporteACPMDetalle' => $request['estadoActualReporteACPMDetalle'][$i], 'fechaCierreReporteACPMDetalle' => $request['fechaCierreReporteACPMDetalle'][$i], 'eficazReporteACPMDetalle' => $request['eficazReporteACPMDetalle'][$i]);
             $guardar = \App\ReporteACPMDetalle::updateOrCreate($indice, $datos);
         }
         return redirect('/reporteacpm');
     }
 }