199 lines
6.7 KiB
PHP
199 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\ManageFreeUInvestments;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Admin\FAQ;
|
|
use App\Models\Admin\Tag;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Category;
|
|
use App\Models\Product;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Models\HighYieldFinance;
|
|
use App\Imports\HighYieldFinanceImport;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class HighYieldFinanceController 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::HighYieldFinanceId);
|
|
$text = $category->category_name;
|
|
$category_id = $category->id;
|
|
$excelFileName = 'HighYieldFinanceTemplate.xlsx';
|
|
return view('Admin.Pages.manage_freeu_investment.upload-product.high-yield-finance', 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 HighYieldFinanceImport($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)
|
|
{
|
|
$highYieldFinance = Product::with('category', 'highYieldFinances')->highYieldFinances()->find($id);
|
|
// dd($highYieldFinance);
|
|
return view('Admin.Pages.manage_freeu_investment.view-product.high-yield-finance', compact('highYieldFinance'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$highYieldFinance = Product::with('category', 'highYieldFinances')->highYieldFinances()->find($id);
|
|
return view('Admin.Pages.manage_freeu_investment.edit-product.high-yield-finance', compact('highYieldFinance','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([
|
|
// 'security_name' => 'required'
|
|
// ]);
|
|
|
|
$validate = Validator::make($request->all(),[
|
|
'security_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
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$highYieldFinance = HighYieldFinance::where('id', $id)->update([
|
|
'security_name' => $request->security_name,
|
|
'security_type' => $request->security_type,
|
|
'isin' => $request->isin,
|
|
'issuer_company' => $request->issuer_company,
|
|
'issue_size' => $request->issue_size,
|
|
'issue_type' => $request->issue_type,
|
|
'listing_details' => $request->listing_details,
|
|
'rating_category' => $request->rating_category,
|
|
'minimum_investment' => $request->minimum_investment,
|
|
'coupon_rate' => $request->coupon_rate,
|
|
'yield_to_maturity' => $request->yield_to_maturity,
|
|
'interest_payment_frequency' => $request->interest_payment_frequency,
|
|
'allotment_date' => $request->allotment_date,
|
|
'maturity_date' => $request->maturity_date,
|
|
'minimum_investment_in_int' => $request->minimum_investment_in_int
|
|
]);
|
|
|
|
$product = Product::where('id', $request->product_high_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->product_high_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->product_high_id)->update([
|
|
'fact_sheet'=>$productfactsheet,]);
|
|
}
|
|
|
|
return response()->json(['status' => 200, 'message' => 'High Yield Finance Details Updated Successfully']);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function highYieldFinanceQuestionAndAnswer()
|
|
{
|
|
$highYieldFinance = FAQ::where('tag_id',Tag::HighYieldFinanceId)->get();
|
|
|
|
if(count($highYieldFinance) > 0)
|
|
{
|
|
return response()->json([
|
|
"status" => "success",
|
|
"code" => 200,
|
|
"data" => $highYieldFinance
|
|
]);
|
|
}
|
|
else
|
|
{
|
|
return response()->json([
|
|
"status" => "failed",
|
|
"code" => 400,
|
|
]);
|
|
}
|
|
}
|
|
}
|