users()->latest()->get(); $investingUserCount = MonthlyUpdateMaster::distinct('users_id')->count('users_id'); return view('Admin.Pages.manage_investors.manage_investors', compact('users', 'investingUserCount')); } public function manage_investor_kyc() { $users = UserKyc::with('user')->get(); return view('Admin.Pages.manage_investors.manage_investor_kyc', compact('users')); } public function manageInvestorKYCIndividual($id) { $kycType = UserKyc::find($id)->kyc_type; $userId = UserKyc::find($id)->users_id; $user = UserKyc::query(); $user->where('user_kycs.id', $id); if ($kycType == 'Individual') { $user->leftJoin('user_individual_kyc', 'user_kycs.users_id', 'user_individual_kyc.user_id'); // $user = $user->select('*')->first(); } if ($kycType == 'HUF') { $user->leftJoin('huf', 'user_kycs.users_id', 'huf.user_id'); // $user = $user->select('*')->first(); } if ($kycType == 'NRI') { $user->leftJoin('nri_kyc', 'user_kycs.users_id', 'nri_kyc.user_id'); // $user = $user->select('*')->first(); } if ($kycType == 'Company') { $user->leftJoin('company', 'user_kycs.users_id', 'company.user_id'); // $user = $user->select('*')->first(); } if ($kycType == 'Partnership') { $user->leftJoin('partnership', 'user_kycs.users_id', 'partnership.user_id'); // $user = $user->select('*')->first(); } if ($kycType == 'Others') { $user->leftJoin('others', 'user_kycs.users_id', 'others.user_id'); // $user = $user->select('*')->first(); } $user = $user->select('*')->first(); // $user->select('*')->first(); // $user = $user->addSelect('*')->first(); // $user = UserKyc::query() // ->leftJoin('user_individual_kyc', 'user_kycs.users_id', 'user_individual_kyc.user_id') // ->leftJoin('nri_kyc', 'user_kycs.users_id', 'nri_kyc.user_id') // ->leftJoin('others', 'user_kycs.users_id', 'others.user_id') // ->leftJoin('partnership', 'user_kycs.users_id', 'partnership.user_id') // ->leftJoin('huf', 'user_kycs.users_id', 'huf.user_id') // ->leftJoin('company', 'user_kycs.users_id', 'company.user_id') // ->where('user_kycs.id', $id) // ->select('*', 'user_individual_kyc.pan_card as individual_pan_card', 'huf.pan_card as huf_pan_card','user_individual_kyc.copy_of_cml as individual_copy_of_cml','huf.copy_of_cml as huf_copy_of_cml','huf.cancelled_cheque as huf_cancelled_cheque') // ->first(); $user_docs = UserKycDocs::where('user_id', $userId)->get(); $userPan = UserKycDocs::where(['user_id' => $userId, 'doc_type' => 'Pan'])->get(); $userAadhar = UserKycDocs::where(['user_id' => $userId, 'doc_type' => 'Aadhar'])->get(); $userPassport = UserKycDocs::where(['user_id' => $userId, 'doc_type' => 'Passport'])->get(); // dd($user); return view('Admin.Pages.manage_investors.manage_investor_kyc_individual', compact('user', 'user_docs', 'userPan', 'userAadhar', 'userPassport')); } public function total_active_investors() { return view('Admin.Pages.manage_investors.total_active_investors'); } public function new_investors() { return view('Admin.Pages.manage_investors.new_investors'); } public function view_investors_details($id) { $currentInvestment = $this->getUserProducts('Holding', $id); $reedemedInvestment = $this->getUserProducts('Reedemed', $id); $totalInvestmentForHolding = array_sum(array_column($currentInvestment['productsDetails'], 'total_investment_amount')); $totalInvestmentForReedemed = array_sum(array_column($reedemedInvestment['productsDetails'], 'total_investment_amount')); $totalInvestment = $this->IND_money_format($totalInvestmentForHolding + $totalInvestmentForReedemed); // return $reedemedInvestment; // echo '
';
        // print_r($currentInvestment);
        // die;

        $user = User::findOrFail($id);

        return view('Admin.Pages.manage_investors.view_investors_detail', compact('user', 'currentInvestment', 'totalInvestment', 'reedemedInvestment'));
    }

    public function getUserProducts($type, $id)
    {
        $user = MonthlyUpdateMaster::where(['users_id' =>  $id, 'holding_status' => $type])->get();
        $productDetails = [];
        foreach ($user as $singleMUM) {
            $dataArr = [
                'id' => $singleMUM->id,
                'categories' => $singleMUM->categories,
                'product_category' => $singleMUM->product_category,
                'product_name' => $singleMUM->product_name,
                'platform' => Company::find($singleMUM->investment_platform)->value('company_name')
            ];
            if (MonthlyUpdateAlternativeInvestmentFund::where('custom_id', $singleMUM->custom_id)->exists()) {
                $data = MonthlyUpdateAlternativeInvestmentFund::where('custom_id', $singleMUM->custom_id)->latest()->first();
                $dataArr['total_investment_amount'] = $data->getRawOriginal('commitment_amount');
                $dataArr['total_investment_amount_in_rs'] = $this->IND_money_format($data->getRawOriginal('commitment_amount'));
                array_push($productDetails, $dataArr);
            } elseif (MonthlyUpdateFractionalRealEstate::where('custom_id', $singleMUM->custom_id)->first()) {
                $data = MonthlyUpdateFractionalRealEstate::where('custom_id', $singleMUM->custom_id)->latest()->first();
                $dataArr['total_investment_amount'] = $data->getRawOriginal('absolute_return_till_date');
                $dataArr['total_investment_amount_in_rs'] = $this->IND_money_format($data->getRawOriginal('absolute_return_till_date'));
                array_push($productDetails, $dataArr);
            } elseif (MonthlyUpdatePeerToPeerLending::where('custom_id', $singleMUM->custom_id)->first()) {
                $data = MonthlyUpdatePeerToPeerLending::where('custom_id', $singleMUM->custom_id)->latest()->first();
                if ($singleMUM->categories == 'Liquiloans') {
                    $dataArr['total_investment_amount'] = $data->getRawOriginal('total_investment');
                    $dataArr['total_investment_amount_in_rs'] = $this->IND_money_format($data->getRawOriginal('total_investment'));
                } elseif ($singleMUM->categories == 'Faircent') {
                    $dataArr['total_investment_amount'] = $data->getRawOriginal('all_time_amount_invested');
                    $dataArr['total_investment_amount_in_rs'] = $this->IND_money_format($data->getRawOriginal('all_time_amount_invested'));
                } elseif ($singleMUM->categories == 'Finance Peer') {
                    $dataArr['total_investment_amount'] = $data->getRawOriginal('all_time_investment_added');
                    $dataArr['total_investment_amount_in_rs'] = $this->IND_money_format($data->getRawOriginal('all_time_investment_added'));
                }
                array_push($productDetails, $dataArr);
            } elseif (MonthlyUpdateIndianFinancialAssets::where('custom_id', $singleMUM->custom_id)->first()) {
                $data = MonthlyUpdateIndianFinancialAssets::where('custom_id', $singleMUM->custom_id)->latest()->first();
                $dataArr['total_investment_amount'] = $data->getRawOriginal('amount_invested');
                $dataArr['total_investment_amount_in_rs'] = $this->IND_money_format($data->getRawOriginal('amount_invested'));
                array_push($productDetails, $dataArr);
            }
        }

        $totalInvestment  = array_sum(array_column($productDetails, 'total_investment_amount'));

        $totalInvestment = $this->IND_money_format(($totalInvestment));

        return [
            'productsDetails' => $productDetails,
            'totalInvestment' => $totalInvestment
        ];
    }

    public function investedProductDetails($id)
    {
        $monthlyUpdateMaster = MonthlyUpdateMaster::findOrFail($id);
        $peerToPeerLending = ['Finance Peer', 'Faircent', 'Liquiloans'];
        $indianfinacial = ['Invoice Discounting', 'Clean And Green Assets', 'Venture Debt', 'High Yield Finance', 'Securitized debt instrument', 'Lease Based Financing', 'Revenue Based Financing'];
        if (in_array($monthlyUpdateMaster->categories, $peerToPeerLending)) {
            $data = MonthlyUpdatePeerToPeerLending::where('custom_id', $monthlyUpdateMaster->custom_id)->latest()->first();
        } elseif ($monthlyUpdateMaster->categories == 'Fractional Real Estate') {
            $data = MonthlyUpdateFractionalRealEstate::where('custom_id', $monthlyUpdateMaster->custom_id)->latest()->first();
        } elseif (in_array($monthlyUpdateMaster->categories, $indianfinacial)) {
            $data = MonthlyUpdateIndianFinancialAssets::where('custom_id', $monthlyUpdateMaster->custom_id)->latest()->first();
        } elseif ($monthlyUpdateMaster->categories == "Alternative Investment Fund") {
            $data = MonthlyUpdateAlternativeInvestmentFund::where('custom_id', $monthlyUpdateMaster->custom_id)->latest()->first();
        }
        return view('Admin.Pages.manage_investors.invested_products.index', [
            'monthlyUpdateMaster' => $monthlyUpdateMaster,
            'data' => $data
        ]);
    }


    function IND_money_format($number)
    {
        $number = (float) $number;
        $decimal = (string)($number - floor($number));
        $money = floor($number);
        $length = strlen($money);
        $delimiter = '';
        $money = strrev($money);

        for ($i = 0; $i < $length; $i++) {
            if (($i == 3 || ($i > 3 && ($i - 1) % 2 == 0)) && $i != $length) {
                $delimiter .= ',';
            }
            $delimiter .= $money[$i];
        }

        $result = strrev($delimiter);
        $decimal = preg_replace("/0\./i", ".", $decimal);
        $decimal = substr($decimal, 0, 3);

        if ($decimal != '0') {
            $result = $result . $decimal;
        }

        return '₹ ' . $result;
    }

    public function downloadBankStatement($file_name)
    {
        return \Storage::download('user_cancelled_check_bank_statement/' . $file_name);
    }

    public function downloadPan($file_name)
    {
        return \Storage::download('user_pan_front/' . $file_name);
    }

    public function downloadAadhar($file_name)
    {
        return \Storage::download('user_aadhar_card/' . $file_name);
    }

    public function downloadDocumentFront($file_name)
    {
        return \Storage::download('user_document_front/' . $file_name);
    }

    public function downloadDocumentBack($file_name)
    {
        return \Storage::download('user_document_back/' . $file_name);
    }

    public function kycStatus(Request $request)
    {
        $status = UserKyc::where('id', $request->id)->update([
            'status' => $request->status
        ]);
        if ($status) {
            $userId = UserKyc::find($request->id);
            $user = User::find($userId->users_id);
            $notify['message'] = "Your KYC has been $request->status!";
            $user->notify(new UserAdmin($notify));
            return response()->json(['status' => 200, 'message' => "Kyc $request->status"]);
        }
        return response()->json(['status' => 400, 'message' => "Kyc could not be $request->status"]);
    }

    public function dataTableKYC(Request $request)
    {
        if ($request->ajax()) {
            $data = UserKyc::with('user');
            if ($request->dropdownValue == 'Approved' || $request->dropdownValue == 'Rejected' || $request->dropdownValue == 'New') {
                $data->where('status', $request->dropdownValue);
            };
            if ($request->dropdownValue == 'Individual' || $request->dropdownValue == 'HUF' || $request->dropdownValue == 'NRI' || $request->dropdownValue == 'Company' || $request->dropdownValue == 'Partnership' || $request->dropdownValue == 'Others') {
                $data->where('kyc_type', $request->dropdownValue);
            };
            $data->latest()->select('*');
            return Datatables::of($data)->addIndexColumn()
                // return Datatables::of($data)
                ->editColumn('created_at', function ($row) {
                    $formattedDate =  $row->created_at->format('d/m/Y');
                    return '
' . $formattedDate . '
'; }) ->editColumn('name', function ($row) { return '
' . $row->user->name . '
'; }) ->editColumn('email', function ($row) { return '
' . $row->email . '
'; }) ->editColumn('status', function ($row) { return '
' . $row->status . '
'; }) ->addColumn('action', function ($row) { if ($row->status == 'Approved') { $btn = 'id) . '" class="action_icon" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-inverse" data-bs-placement="top" title="View Detail"> users_id) . '" class="action_icon" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-inverse" data-bs-placement="top" title="View Invetsor Profile"> '; } elseif ($row->status == "Rejected") { $btn = 'id) . '" class="action_icon" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-inverse" data-bs-placement="top" title="View Detail"> users_id) . '" class="action_icon" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-inverse" data-bs-placement="top" title="View Invetsor Profile"> '; } else { $btn = 'id) . '" class="action_icon" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-inverse" data-bs-placement="top" title="View Detail"> users_id) . '" class="action_icon" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-inverse" data-bs-placement="top" title="View Invetsor Profile"> '; } return $btn; }) ->rawColumns(['name', 'email', 'created_at', 'status', 'action']) ->make(true); } return view('Admin.Pages.manage_investors.manage_investor_kyc'); } public function downloadFile(Request $request) { if (\Storage::exists($request->file)) { return Storage::download($request->file); } else { return "File not found"; } } public function manageInvestorDataTableKYC(Request $request) { if ($request->ajax()) { $data = User::query(); // print_r($request->dropdownValue); $data->users(); if ($request->dropdownValue == '1' || $request->dropdownValue == '0') { $data->where('status', $request->dropdownValue); }; if ($request->dropdownValue === 'Zero') { $data->doesntHave('investments'); } // if ($request->dropdownValue == 'Individual' || $request->dropdownValue == 'HUF' || $request->dropdownValue == 'NRI' || $request->dropdownValue == 'Company' || $request->dropdownValue == 'Partnership' || $request->dropdownValue == 'Others') { // $data->where('kyc_type', $request->dropdownValue); // }; $data->latest()->select('*'); $count = 1; return Datatables::of($data)->addIndexColumn() // return Datatables::of($data) ->editColumn('created_at', function ($row) { $formattedDate = $row->created_at->format('d/m/Y'); return '
' . $formattedDate . '
'; }) ->editColumn('name', function ($row) { return '
' . $row->name . '
'; }) ->editColumn('email', function ($row) { return '
' . $row->email . '
'; }) ->editColumn('contact_number', function ($row) { return '
' . $row->contact_number . '
'; }) ->editColumn('amount_invested', function ($row) { return '
' . $this->totalInvestment($row->id) . '
'; }) ->editColumn('active_investment', function ($row) { return '
' . $this->totalInvestmentCount($row->id) . ' Investment(s)
'; }) ->editColumn('status', function ($row) { return '
' . $row->status . '
'; }) ->addColumn('action', function ($row) { $checked = $row->status == 1 ? 'checked' : ''; $btn = '
id) . ' class="action_icon" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-inverse" data-bs-placement="top" title="View Detail">
'; return $btn; }) ->rawColumns(['name', 'email', 'contact_number', 'amount_invested', 'active_investment', 'created_at', 'status', 'action']) ->make(true); } return view('Admin.Pages.manage_investors.manage_investors'); } public function totalInvestmentCount($id) { return MonthlyUpdateMaster::where(['users_id' => $id, 'holding_status' => 'Holding'])->count(); } public function totalInvestment($id, $type = null) { // $user = MonthlyUpdateMaster::where('users_id', $id)->where('holding_status',$type)->get(); $user = MonthlyUpdateMaster::where('users_id', $id)->when($type !== null, function ($query) use ($type) { return $query->where('holding_status', $type); })->get(); $productDetails = []; foreach ($user as $singleMUM) { $dataArr = [ 'categories' => $singleMUM->categories, 'product_category' => $singleMUM->product_category, 'product_name' => $singleMUM->product_name, ]; if (MonthlyUpdateAlternativeInvestmentFund::where('custom_id', $singleMUM->custom_id)->exists()) { $data = MonthlyUpdateAlternativeInvestmentFund::where('custom_id', $singleMUM->custom_id)->latest()->first(); $dataArr['total_investment_amount'] = $data->getRawOriginal('commitment_amount'); array_push($productDetails, $dataArr); } elseif (MonthlyUpdateFractionalRealEstate::where('custom_id', $singleMUM->custom_id)->first()) { $data = MonthlyUpdateFractionalRealEstate::where('custom_id', $singleMUM->custom_id)->latest()->first(); $dataArr['total_investment_amount'] = $data->getRawOriginal('absolute_return_till_date'); array_push($productDetails, $dataArr); } elseif (MonthlyUpdatePeerToPeerLending::where('custom_id', $singleMUM->custom_id)->first()) { $data = MonthlyUpdatePeerToPeerLending::where('custom_id', $singleMUM->custom_id)->latest()->first(); if ($singleMUM->categories == 'Liquiloans') { $dataArr['total_investment_amount'] = $data->getRawOriginal('total_investment'); } elseif ($singleMUM->categories == 'Faircent') { $dataArr['total_investment_amount'] = $data->getRawOriginal('all_time_amount_invested'); } elseif ($singleMUM->categories == 'Finance Peer') { $dataArr['total_investment_amount'] = $data->getRawOriginal('all_time_investment_added'); } array_push($productDetails, $dataArr); } elseif (MonthlyUpdateIndianFinancialAssets::where('custom_id', $singleMUM->custom_id)->first()) { $data = MonthlyUpdateIndianFinancialAssets::where('custom_id', $singleMUM->custom_id)->latest()->first(); $dataArr['total_investment_amount'] = $data->amount_invested; array_push($productDetails, $dataArr); } } $totalInvestment = array_sum(array_column($productDetails, 'total_investment_amount')); $totalInvestment = IND_money_format($totalInvestment); return $totalInvestment; } }