![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/medad.corals.io/Corals/modules/Medad/Http/Controllers/ |
<?php namespace Corals\Modules\Medad\Http\Controllers; use Corals\Foundation\Http\Controllers\BaseController; use Corals\Modules\Medad\DataTables\QuotationsDataTable; use Corals\Modules\Medad\DataTables\Scopes\BranchItemsScope; use Corals\Modules\Medad\DataTables\Scopes\ProjectDatatableScope; use Corals\Modules\Medad\Facades\Medad; use Corals\Modules\Medad\Http\Requests\QuotationsRequest; use Corals\Modules\Medad\Models\Branch; use Corals\Modules\Medad\Models\Company; use Corals\Modules\Medad\Models\Project; use Corals\Modules\Medad\Models\Quotation; use Corals\Modules\Medad\Models\QuotationRequest; use Corals\Modules\Medad\Services\QuotationService; use Illuminate\Http\Request; class QuotationsController extends BaseController { protected $quotationService; public function __construct(QuotationService $quotationService) { $this->quotationService = $quotationService; $this->resource_url = config('medad.models.quotation.resource_url'); $this->title = trans('Medad::module.quotation.title'); $this->title_singular = trans('Medad::module.quotation.title_singular'); parent::__construct(); } /** * @param QuotationsRequest $request * @param QuotationsDataTable $dataTable * @return mixed */ public function index(QuotationsRequest $request, QuotationsDataTable $dataTable) { $this->setViewSharedData(['hideCreate' => true]); return $dataTable->render('Medad::quotations.index'); } /** * @param QuotationsRequest $request * @return \Illuminate\Http\JsonResponse */ public function store(QuotationsRequest $request) { try { $quotationRequest = $this->quotationService->store($request, Quotation::class); $message = [ 'level' => 'success', 'message' => trans('Corals::messages.success.created', ['item' => $this->title_singular]) ]; } catch (\Exception $exception) { $message = ['level' => 'error', 'message' => $exception->getMessage()]; log_exception($exception, Quotation::class, 'update'); } return response()->json($message); } /** * @param QuotationsRequest $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show(QuotationsRequest $request, Quotation $quotation) { $this->setViewSharedData([ 'title_singular' => trans('Corals::labels.show_title', ['title' => $quotation->getIdentifier()]), 'showModel' => $quotation, ]); $customerBranch = $quotation->customerBranch; $supplierBranch = $quotation->supplierBranch; return view('Medad::quotations.show')->with(compact( 'quotation', 'customerBranch', 'supplierBranch')); } /** * @param Quotation $quotation * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function edit(QuotationsRequest $request, Quotation $quotation) { $this->setViewSharedData([ 'title_singular' => trans('Corals::labels.update_title', ['title' => $quotation->code]) ]); $customerBranch = $quotation->customerBranch; $supplierBranch = $quotation->supplierBranch; $customerCompany = $quotation->customerCompany; $supplierCompany = $quotation->supplierCompany; return view('Medad::quotations.create_edit')->with(compact('quotation', 'customerCompany', 'supplierCompany', 'customerBranch', 'supplierBranch')); } /** * @param QuotationsRequest $request * @param Quotation $quotation * @return \Illuminate\Http\JsonResponse */ public function update(QuotationsRequest $request, Quotation $quotation) { try { $this->quotationService->update($request, $quotation); $message = [ 'level' => 'success', 'message' => trans('Corals::messages.success.updated', ['item' => $this->title_singular]) ]; } catch (\Exception $exception) { $message = ['level' => 'error', 'message' => $exception->getMessage()]; log_exception($exception, Quotation::class, 'update'); } return response()->json($message); } /** * @param QuotationsRequest $request * @param Quotation $quotation * @return \Illuminate\Http\JsonResponse */ public function destroy(QuotationsRequest $request, Quotation $quotation) { try { $this->quotationService->destroy($request, $quotation); $message = [ 'level' => 'success', 'message' => trans('Corals::messages.success.deleted', ['item' => $this->title_singular]) ]; } catch (\Exception $exception) { log_exception($exception, Quotation::class, 'destroy'); $message = ['level' => 'error', 'message' => $exception->getMessage()]; } return response()->json($message); } public function companyQuotations( QuotationsRequest $request, Company $company, Branch $branch, QuotationsDataTable $dataTable ) { if ($request->has('tab_html')) { $modelDataTable = new QuotationsDataTable(); $modelDataTable->setResourceUrl($request->url()); return view('Medad::sub_show')->with(compact('modelDataTable')); } $dataTable->addScope(new BranchItemsScope($branch)); return $dataTable->renderAjaxAndActions(); } public function projectQuotations( QuotationsRequest $request, Company $company, Branch $branch, Project $project, QuotationsDataTable $dataTable ) { if ($request->has('tab_html')) { $modelDataTable = new QuotationsDataTable(); $modelDataTable->setResourceUrl($request->url()); return view('Medad::sub_show')->with(compact('modelDataTable')); } $dataTable->addScope(new ProjectDatatableScope($project)); return $dataTable->renderAjaxAndActions(); } public function create(QuotationsRequest $request, Company $company, Branch $branch) { $this->setViewSharedData([ 'title_singular' => trans('Corals::labels.create_title', ['title' => $this->title_singular]) ]); $quotation = new Quotation(); if ($projectHashedId = $request->get('project')) { $quotation->project_id = optional(Project::findByHash($projectHashedId))->id; } $customerBranch = new Branch(); $supplierBranch = $branch; $customerCompany = new Company(); $supplierCompany = $branch->company; return view('Medad::quotations.create_edit')->with(compact('quotation', 'customerCompany', 'customerBranch', 'supplierBranch', 'supplierCompany')); } public function generateQuotation(Request $request, QuotationRequest $quotationRequest) { $quotation = new Quotation(); return view('Medad::quotation_requests.partials.generate_quotation_modal') ->with(compact('quotation', 'quotationRequest')); } /** * @return \Illuminate\Http\JsonResponse */ public function submitGenerateQuotation(Request $request, QuotationRequest $quotationRequest) { $this->authorize('addQuotation', $quotationRequest); $request->validate([ 'owner_id' => 'required', 'types_count' => 'required', 'total_quantity' => 'required', 'amount' => 'required', 'supplier_branch_id' => 'required', ]); try { $quotation = $this->quotationService->store($request, Quotation::class, [ 'quotation_request_id' => $quotationRequest->id, 'project_id' => $quotationRequest->project_id, 'customer_company_id' => $quotationRequest->customer_company_id, 'supplier_company_id' => Medad::getUserCompany()->id, 'customer_branch_id' => $quotationRequest->customer_branch_id, ]); $message = [ 'level' => 'success', 'message' => trans('Corals::messages.success.created', ['item' => $this->title_singular]) ]; } catch (\Exception $exception) { log_exception($exception, Quotation::class, 'destroy'); $message = ['level' => 'error', 'message' => $exception->getMessage()]; } return response()->json($message); } public function getQuotationRequestValues(Request $request) { $quotationRequest = QuotationRequest::select('types_count', 'total_quantity') ->where('id', $request->id) ->first(); $this->authorize('view', $quotationRequest); return response()->json($quotationRequest); } public function addNote(Request $request, Quotation $quotation) { $model = $quotation; return view('Medad::add_note_modal')->with(compact('model')); } public function notesList(Request $request, Quotation $quotation) { $this->authorize('notesList', $quotation); $comments = $quotation->comments; return view('Medad::comments')->with(compact('comments')); } }