198 lines
6.8 KiB
PHP
198 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\ManageFreeUInvestments;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Category;
|
|
use App\Models\Product;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Models\InvoiceDiscounting;
|
|
use App\Imports\InvoiceDiscountingImport;
|
|
use Illuminate\Support\Str;
|
|
use App\Models\Admin\FAQ;
|
|
use App\Models\Admin\Tag;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class InvoiceDiscountingController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$category = Category::find(Category::InvoiceDiscountingId);
|
|
$text = $category->category_name;
|
|
$category_id = $category->id;
|
|
$excelFileName = 'InvoiceDiscountingTemplate.xlsx';
|
|
return view('Admin.Pages.manage_freeu_investment.upload-product.invoice-discounting', compact('text', 'category_id','excelFileName'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
request()->validate([
|
|
'productFile' => 'required|mimes:xlx,xls,xlsx|max:2048'
|
|
]);
|
|
$category_type = $request->category_id;
|
|
$category = Category::find($request->category_id);
|
|
Excel::import(new InvoiceDiscountingImport($category_type), $request->file('productFile'));
|
|
return back()->with('success', "$category->category_name Imported Successfully.");
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$invoiceDiscounting = Product::with('category', 'invoiceDiscounting')->invoiceDiscounting()->find($id);
|
|
// dd($invoiceDiscounting);
|
|
return view('Admin.Pages.manage_freeu_investment.view-product.invoice-discounting', compact('invoiceDiscounting'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$invoiceDiscounting = Product::with('category', 'invoiceDiscounting')->invoiceDiscounting()->find($id);
|
|
return view('Admin.Pages.manage_freeu_investment.edit-product.invoice-discounting', compact('invoiceDiscounting','id'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
// $request->validate([
|
|
// 'company_name' => 'required'
|
|
// ]);
|
|
$validate = Validator::make($request->all(),[
|
|
'company_name' => 'required',
|
|
'presentation'=>"required|mimes:pdf,zip",
|
|
'fact_sheet'=>"required|mimes:pdf,zip",
|
|
],[
|
|
'required' => "This :attribute field is required",
|
|
'mimes' => "This :attribute field extension must be pdf or zip",
|
|
]);
|
|
$validationMessage = validationErrorMessage($validate);
|
|
if ($validationMessage) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'status' => 400,
|
|
|
|
'message' => $validationMessage
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
$invoiceDiscounting = InvoiceDiscounting::where('id', $id)->update([
|
|
'slug' => Str::slug($request->company_name),
|
|
'company_name' => $request->company_name,
|
|
'sector' => $request->sector,
|
|
'about_company' => $request->about_company,
|
|
'key_performance_metrics' => $request->key_performance_metrics,
|
|
'minimum_investment' => $request->minimum_investment,
|
|
'total_deal_size' => $request->total_deal_size,
|
|
'tenure' => $request->tenure,
|
|
'pre_tax_irr' => $request->pre_tax_irr,
|
|
'coupon_rate' => $request->coupon_rate,
|
|
'vendor' => $request->vendor,
|
|
'recourse_on' => $request->recourse_on,
|
|
'settlement_date' => $request->settlement_date,
|
|
'payout_frequency' => $request->payout_frequency,
|
|
'payment_obligor' => $request->payment_obligor,
|
|
'security_structure' => $request->security_structure,
|
|
'minimum_investment_in_int' => $request->minimum_investment_in_int
|
|
]);
|
|
$product = Product::where('id', $request->invoice_id)->first();
|
|
// dd($product);
|
|
if($request->has('presentation')){
|
|
if(\File::exists(public_path('/uploads/product/presentation/'.$product->presentation))){
|
|
\File::delete(public_path('/uploads/product/presentation/'.$product->presentation));
|
|
}
|
|
$productpresentation = time().'_presentation'.'.'.$request->presentation->extension();
|
|
$request->presentation->move(public_path('/uploads/product/presentation'),$productpresentation);
|
|
$updatepresentation = Product::where('id', $request->invoice_id)->update([
|
|
'presentation'=> $productpresentation,
|
|
]);
|
|
}
|
|
|
|
if($request->has('fact_sheet')){
|
|
if(\File::exists(public_path('/uploads/product/fact_sheet/'.$product->fact_sheet))){
|
|
\File::delete(public_path('/uploads/product/fact_sheet'.$product->fact_sheet));
|
|
}
|
|
$productfactsheet = time().'_factsheet'.'.'.$request->fact_sheet->extension();
|
|
$request->fact_sheet->move(public_path('uploads/product/fact_sheet'),$productfactsheet);
|
|
$updatefactsheet = Product::where('id', $request->invoice_id)->update([
|
|
'fact_sheet'=>$productfactsheet,]);
|
|
}
|
|
|
|
return response()->json(['status' => 200, 'message' => 'Invoice Discounting Details Updated Successfully']);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function invoiceDiscountingQuestionAndAnswer()
|
|
{
|
|
$InvoiceDiscounting = FAQ::where('tag_id',Tag::InvoiceDiscountingId)->select('faq_question','faq_answer')->get();
|
|
|
|
if(count($InvoiceDiscounting) > 0)
|
|
{
|
|
return response()->json([
|
|
"status" => "success",
|
|
"code" => 200,
|
|
"data" => $InvoiceDiscounting
|
|
]);
|
|
}
|
|
else
|
|
{
|
|
return response()->json([
|
|
"status" => "failed",
|
|
"code" => 400,
|
|
]);
|
|
}
|
|
}
|
|
}
|