public function getJust($idCarga) { $carga = Cargas::find($idCarga); if ($carga) { //obtener cargas $empresa = $carga->empresa()->orderBy('tipo_receptor')->get(); $sat = $carga->sat()->orderBy('tipo_receptor')->get(); $diff = new DiferenciasCFID($sat, $empresa, $carga->rfc); $just_emitidos = $diff->get_justificados_emitidos(); $just_recibidos = $diff->get_justificados_recibidos(); $array = ['rfc' => $carga->rfc, 'nombre' => $carga->contribuyente->nombre, 'justEm' => $just_emitidos, 'justRec' => $just_recibidos]; $namePdf = $carga->rfc . "_" . time() . ".pdf"; \PDF::loadView('descargas.reporte-justificados', $array)->save(storage_path('temp') . "/{$namePdf}"); $nameZip = "just_" . time() . ".zip"; $zipper = new Zipper(); $zipper->make(storage_path("temp/{$nameZip}"))->add(storage_path('temp') . "/{$namePdf}"); $anexos = $diff->getAnexos(); foreach ($anexos as $anexo) { $zipper->folder($anexo['uuid']); foreach ($anexo['anexos'] as $file) { $zipper->add($file->file); } } $zipper->close(); return response()->download(storage_path("temp/{$nameZip}"), $nameZip); } }
/** * Closes the zip file and frees all handles * * @static */ public static function close() { return \Chumper\Zipper\Zipper::close(); }
/** * Sweet baby jesus, I know I know! * * Used to upload a blueprint and do the necessary * checks to ensure that the upload is valid * * @param NbtParser $parser * @param ImageManipulate $manipulator * @param Zipper $zipper * @param PathBuilder $pathBuilder * @param PostUploadRequest $request * @param Blueprint $blueprint * @param BlueprintModsUsed $blueprintModsUsed * @param Filesystem $file * @param Guard $guard * @param Repository $repository * * @return \Illuminate\Http\RedirectResponse */ public function postUpload(NbtParser $parser, ImageManipulate $manipulator, Zipper $zipper, PathBuilder $pathBuilder, PostUploadRequest $request, Blueprint $blueprint, BlueprintModsUsed $blueprintModsUsed, Filesystem $file, Guard $guard, Repository $repository) { $input = $request->get('upload'); // Make sure that the blueprint is valid // ...well sort of, it can't be checked for sure $parser->loadFile($request->file('upload.blueprint')); if (!array_key_exists(0, $parser->root) || empty($parser->root) || !array_key_exists('type', $parser->root[0])) { return redirect()->back()->with('blueprintNotValid', true)->withInput(); } // Arrays to be inserted into the database // Blueprint things $blueprintInsert = []; // Process the blueprint foreach ($parser->root[0]['value'] as $key => $value) { $value['name'] != 'version' ?: ($blueprintInsert['bc_version'] = $value['value']); $value['name'] != 'sizeY' ?: ($blueprintInsert['sizeY'] = $value['value']); $value['name'] != 'sizeZ' ?: ($blueprintInsert['sizeZ'] = $value['value']); $value['name'] != 'sizeX' ?: ($blueprintInsert['sizeX'] = $value['value']); } // Set some fields that are easy to set, just to get it out of the way $blueprintInsert['name'] = trim($input['name']); $blueprintInsert['version'] = trim($input['version']); $blueprintInsert['author_name'] = trim($input['author_name']); $blueprintInsert['survival_creative'] = $input['play_mode']; $blueprintInsert['description'] = trim($input['description']); $blueprintInsert['user_id'] = $guard->user()->getAuthIdentifier(); $blueprintInsert['uploaded_at'] = Carbon::now()->toDateTimeString(); $blueprintInsert['archive_name'] = str_replace(' ', '', $input['name']) . '_' . getRandomId() . '.zip'; // Get the buildcraft image storage path $buildcraftImagesStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.images')); // Get the buildcraft archives storage path $buildcraftArchivesStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives')); // Get the buildcraft temp storage path $buildcraftTempStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.temp')); // Compress and move the required screenshot $manipulator->setFileInfo($request->file('upload.required_screenshot'))->compress()->move($buildcraftImagesStoragePath)->createThumb(500)->exitClean(); //Might as well add it to the insert array $blueprintInsert['screenshot'] = $manipulator->getFileName(); // Get a temporary name for the blueprint $temporary_name = getRandomId() . '.' . $request->file('upload.blueprint')->getClientOriginalExtension(); // Move the blueprint to a temporary folder in order to archive it. $request->file('upload.blueprint')->move($buildcraftTempStoragePath, $temporary_name); // Add blueprint to the archive $zipper->make($buildcraftArchivesStoragePath . $blueprintInsert['archive_name'])->add($buildcraftTempStoragePath . $temporary_name)->add($buildcraftImagesStoragePath . $blueprintInsert['screenshot']); // Compress and move the first optional screenshot // Get the file name, create a thumb // Also add the file to the archive if (null !== $request->file('upload.optional_screenshot_0')) { $manipulator->setFileInfo($request->file('upload.optional_screenshot_0'))->compress()->move($buildcraftImagesStoragePath)->createThumb(500)->exitClean(); $blueprintInsert['screenshot_optional_0'] = $manipulator->getFileName(); $zipper->add($buildcraftImagesStoragePath . $blueprintInsert['screenshot_optional_0']); } else { $blueprintInsert['screenshot_optional_0'] = null; } // Compress and move the second optional screenshot // Get the file name, create a thumb // Also add the file to the archive if (null !== $request->file('upload.optional_screenshot_1')) { $manipulator->setFileInfo($request->file('upload.optional_screenshot_1'))->compress()->move($buildcraftImagesStoragePath)->createThumb(500)->exitClean(); $blueprintInsert['screenshot_optional_1'] = $manipulator->getFileName(); $zipper->add($buildcraftImagesStoragePath . $blueprintInsert['screenshot_optional_1']); } else { $blueprintInsert['screenshot_optional_1'] = null; } //Clean up $zipper->close(); if ($file->exists($buildcraftTempStoragePath . $temporary_name)) { $file->delete($buildcraftTempStoragePath . $temporary_name); } // Insert the blueprint data $blueprint->insert($blueprintInsert); // Get the last inserted id $blueprint_id = $blueprint->id; $modsUsedInsert = []; // Get a list of the mods used $mods_used = $this->getModsUsed($parser->root[0]); if (null !== $mods_used) { // Make a valid array to insert foreach ($mods_used as $key => $value) { $modsUsedInsert[] = ['blueprint_id' => $blueprint_id, 'mod_name' => $value]; } // Insert into mods used too $blueprintModsUsed->insert($modsUsedInsert); } // Welp, that's that return redirect()->route('buildcraft::user::getUpload', ['user_id' => Auth::user()->id])->with('blueprintUploadSuccess', true); }
public function add(Zipper $zipper, PathBuilder $pathBuilder, Request $request, BlueprintCollection $blueprintCollection, Filesystem $file, Repository $repository, Collection $collection) { $input = $request->get('collection'); // Check if the blueprint already belongs to this collection $search = $blueprintCollection->where(['collection_id' => $input['id'], 'blueprint_id' => $input['blueprint_id']])->get()->toArray(); if (!empty($search)) { return redirect()->back()->with('blueprintAlreadyInCollection', true); } // Insert the blueprint in the collection $insert = $blueprintCollection->insert(['collection_id' => $input['id'], 'blueprint_id' => $input['blueprint_id']]); if ($insert) { // Create an archive to server to the user rather than creating it when it's downloaded // Get all the collection current archives first $collection = $collection->select('id', 'archive_name', 'name')->where(['id' => $input['id']])->with(['blueprints' => function ($query) { $query->select('archive_name'); }])->first(); $buildcraftArchiveStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives')); // Delete the previous archive(if any) if (null !== $collection->archive_name) { $file->delete($buildcraftArchiveStoragePath . $collection->archive_name); } // Create a random name for the collection archive $collectionArchiveName = str_replace(' ', '', $collection->name) . '_' . getRandomId() . '_collection' . '.zip'; // Start creating the archive $zipper->make($buildcraftArchiveStoragePath . $collectionArchiveName); foreach ($collection->blueprints as $key => $value) { // Add each archive to the the newly created archive $zipper->add($buildcraftArchiveStoragePath . $value->archive_name); } //Clean up $zipper->close(); // Update the archive name in the collections table $collection->archive_name = $collectionArchiveName; $collection->save(); // Welp, that's that return redirect()->back()->with('blueprintAddedToCollection', true); } // Or not return redirect()->back()->with('blueprintNotAddedToCollection', true); }
public function getJust(Request $request) { try { $contr = $request->cont; $desde = Carbon::createFromFormat('Y-m-d', $request->desde)->startOfDay(); $hasta = Carbon::createFromFormat('Y-m-d', $request->hasta)->endOfDay(); } catch (\Exception $e) { return view('vacio'); } $sat = ArchivoSat::whereBetween('fecha', array($desde, $hasta))->where(function ($q) use($contr) { $q->where('rfc_emisor', '=', $contr)->orWhere('rfc_receptor', '=', $contr); })->get(); $empresa = ArchivoEmpresa::whereBetween('fecha', array($desde, $hasta))->where(function ($q) use($contr) { $q->where('rfc_emisor', '=', $contr)->orWhere('rfc_receptor', '=', $contr); })->get(); $todos = $sat->count() + $empresa->count(); if ($todos == 0) { return view('vacio'); } $diff = new DiferenciasCFID($sat, $empresa, $contr); $just_emitidos = $diff->get_justificados_emitidos(); $just_recibidos = $diff->get_justificados_recibidos(); $contr = Contribuyente::where('rfc', '=', $contr)->first(); $array = ['nombre' => $contr->nombre, 'rfc' => $contr->rfc, 'justEm' => $just_emitidos, 'justRec' => $just_recibidos]; $namePdf = $contr->rfc . "_" . time() . ".pdf"; \PDF::loadView('descargas.reporte-justificados', $array)->save(storage_path('temp') . "/{$namePdf}"); $nameZip = "just_" . time() . ".zip"; $zipper = new Zipper(); $zipper->make(storage_path("temp/{$nameZip}"))->add(storage_path('temp') . "/{$namePdf}"); $anexos = $diff->getAnexos(); foreach ($anexos as $anexo) { $zipper->folder($anexo['uuid']); foreach ($anexo['anexos'] as $file) { $zipper->add($file->file); } } $zipper->close(); return response()->download(storage_path("temp/{$nameZip}"), $nameZip); }
public function postExportPdf(Request $request) { $ids = null; if ($request->exists("checkall")) { $filter = !is_null($request->input('search')) ? $this->buildSearch() : ''; $args["params"] = $filter; $rows = $this->model->getRows($args); foreach ($rows["rows"] as $row) { $ids[] = $row->id; } } if (!$ids) { $ids = $request->input('ids'); } if (count($ids) > 0) { $uid = uniqid(); $zip = new \Chumper\Zipper\Zipper(); $zip->make(storage_path() . "/app/tmp/{$uid}/facturas.zip"); foreach ($ids as $id) { $view = $this->getHtmlContent($id); $nombreFact = "factura-{$this->data['row']->serfac}-{$this->data['row']->ejefac}-{$this->data['row']->numfac}.pdf"; $pdfContents = \PDF::loadHTML($view)->setPaper('a4')->setOption('margin-right', 0)->setOption('margin-bottom', 0)->setOption('margin-left', 0)->setOption('margin-top', 0)->output(); $zip->addString($nombreFact, $pdfContents); $this->data['subgrid'] = isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'][0] : array(); } $zip->close(); $response = \Response::make(file_get_contents(storage_path() . "/app/tmp/{$uid}/facturas.zip")); $size = \Storage::drive("local")->size("tmp/{$uid}/facturas.zip"); \Storage::drive("local")->deleteDirectory("tmp/{$uid}"); $response->header('Content-Disposition', 'attachment; filename="facturas.zip"'); $response->header('Content-Length', '$size'); return $response; } }
public function download(Request $request) { $digits = 5; $build_string = 'milligram_custom_' . str_pad(rand(0, pow(10, $digits) - 1), $digits, '0', STR_PAD_LEFT); $temp_path = 'temp/' . $build_string . '.css'; $temp = fopen($temp_path, 'a'); $base = file_get_contents('milligram/Base.css'); $blockquote = file_get_contents('milligram/Blockquote.css'); $button = file_get_contents('milligram/Button.css'); $code = file_get_contents('milligram/Code.css'); $form = file_get_contents('milligram/Form.css'); $grid = file_get_contents('milligram/Grid.css'); $link = file_get_contents('milligram/Link.css'); $list = file_get_contents('milligram/List.css'); $misc = file_get_contents('milligram/Misc.css'); $spacing = file_get_contents('milligram/Spacing.css'); $table = file_get_contents('milligram/Table.css'); $typography = file_get_contents('milligram/Typography.css'); $utility = file_get_contents('milligram/Utility.css'); if ($request->has('base')) { file_put_contents($temp_path, $base, FILE_APPEND); } if ($request->has('blockquote')) { file_put_contents($temp_path, $blockquote, FILE_APPEND); } if ($request->has('button')) { file_put_contents($temp_path, $button, FILE_APPEND); } if ($request->has('code')) { file_put_contents($temp_path, $code, FILE_APPEND); } if ($request->has('form')) { file_put_contents($temp_path, $form, FILE_APPEND); } if ($request->has('grid')) { file_put_contents($temp_path, $grid, FILE_APPEND); } if ($request->has('link')) { file_put_contents($temp_path, $link, FILE_APPEND); } if ($request->has('list')) { file_put_contents($temp_path, $list, FILE_APPEND); } if ($request->has('misc')) { file_put_contents($temp_path, $misc, FILE_APPEND); } if ($request->has('spacing')) { file_put_contents($temp_path, $spacing, FILE_APPEND); } if ($request->has('table')) { file_put_contents($temp_path, $table, FILE_APPEND); } if ($request->has('typography')) { file_put_contents($temp_path, $typography, FILE_APPEND); } if ($request->has('utility')) { file_put_contents($temp_path, $utility, FILE_APPEND); } fclose($temp); $zipper = new Zipper(); $zipper->make('download/' . $build_string . '.zip')->add([$temp_path, 'temp/normalize.css']); $zipper->close(); $download_path = rtrim(app()->basePath('public/'), '/') . "/download/" . $build_string . '.zip'; return response()->download($download_path, $build_string . '.zip', ['Content-type' => 'application/zip']); }