/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $record = DocumentoLinea::find($id)->delete();
     return new AjaxResponse('success', '');
 }
function crearDocumentoYSolicitud($arrayCabecera, $arrayLineas, $tmpString, $rideContent, $rideExtension, $fullXml)
{
    $handlerRequestCore = new RequestCore();
    $handlerAttachmentCore = new AttachmentCore();
    $handlerRequestMetadataCore = new RequestMetadataCore();
    // Verificar el usuario creador / al que se asignará
    $creator = Responsable::whereRuc($arrayCabecera['ruc'])->lists('responsable')->implode(',');
    if (empty($creator)) {
        $creator = FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_DEF_ASIGNACION");
    }
    if ($arrayCabecera["tipo_doc"] == "FAC") {
        $customStep = FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_STEP_FACTURAS");
    } else {
        $customStep = FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_STEP_OTROS");
        $creator = '';
    }
    // Crear solicitud por cada proveedor
    $request_flow = FLOW_RECEPCIONDOCUMENTOS;
    $request_id = $handlerRequestCore->getLastGeneralRequestId() + 1;
    $inner_request_id = $handlerRequestCore->getLastGeneralRequestId($request_flow) + 1;
    $request_name = $request_description = $arrayCabecera["tipo_doc"] . " - " . $arrayCabecera["razonSocial"];
    $request_createdby = "admin";
    $request_id = $handlerRequestCore->createNewRequest($request_id, $inner_request_id, $request_flow, $request_name, $request_description, $request_createdby, $creator, $customStep);
    // Crear documento
    $arrayCabecera['ef_id'] = $request_id;
    $documento = Documento::create($arrayCabecera);
    // Setear id_documento en líneas e insertar
    foreach ($arrayLineas as &$linea) {
        $linea['id_documento'] = $documento->id;
        DocumentoLinea::create($linea);
    }
    // Guardar archivos temporales en disco
    $xmlFile = dirname(__FILE__) . "/facturas/tmpAttachments/tmp.xml";
    $pdfFile = dirname(__FILE__) . "/facturas/tmpAttachments/tmp." . $rideExtension;
    $filetypeXml = FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_FILE_XML");
    $filetypePdf = FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_FILE_PDF");
    //file_put_contents($xmlFile, $tmpString);
    file_put_contents($xmlFile, $fullXml);
    $handlerAttachmentCore->addAttachmentToRequest($request_id, $filetypeXml, $xmlFile, $_SESSION["environment_path"], "admin", "Documento XML");
    if (!empty($rideExtension) && !empty($rideContent)) {
        file_put_contents($pdfFile, $rideContent);
        $handlerAttachmentCore->addAttachmentToRequest($request_id, $filetypePdf, $pdfFile, $_SESSION["environment_path"], "admin", "Documento PDF");
    }
    // Setear variables de solicitud
    $handlerRequestMetadataCore->setVariable($request_id, "RDE-TIPO-DOCUMENTO", $arrayCabecera["tipo_doc"]);
    $handlerRequestMetadataCore->setVariable($request_id, "RDE-NUM-DOCUMENTO", $arrayCabecera["estab"] . "-" . $arrayCabecera["ptoEmi"] . "-" . $arrayCabecera["secuencial"]);
    $handlerRequestMetadataCore->setVariable($request_id, "RDE-NOMBRE-PROVEEDOR", $arrayCabecera["razonSocial"]);
}
 public function deleteLineaDistribucionDetallada()
 {
     $input = Request::createFromGlobals();
     $linea = DocumentoLinea::with('documento')->find($input->id_documento_linea);
     Distribucion::find($input->id)->delete();
     return $this->getDocumento($linea->documento->id);
 }