<?php

    namespace App\Http\Controllers;
    use App\Models\OldPendingFollowUp;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\DB;
class OldPendingFollowUpController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        function amount2Rs($amount)
{
    $amount = explode("-", $amount);
    $l = COUNT($amount);
    if ($l > 1) {
        $minus = '-';
        $amount = $amount[1];
    } else {
        $amount = $amount[0];
    }
    $amount = explode(".", $amount);
    $l = COUNT($amount);
    if ($l > 1) {
        $after_point = $amount[1];
    }
    $amount = $amount[0];
    $len = strlen($amount);
    switch ($len) {
        case 1:
        case 2:
        case 3:
            $str = $amount;
            break;
        case 4:
        case 5:
            $j = $amount / 1000;
            settype($j, "int");
            $sub = substr($amount, strlen($j), $len);
            $amount = $j . ',' . $sub;
            $str = $amount;
            break;
        case 6:
        case 7:
            $j = $amount / 100000;
            settype($j, "int");
            //echo $amount."->$j";
            $sub = substr($amount, (strlen($j) + 2), $len);
            $amount = $j . ',' . substr($amount, strlen($j), 2) . ',' . $sub;
            $str = $amount;
            break;
        case 8:
        case 9:
        case 10:
            $j = $amount / 10000000;
            settype($j, "int");
            $sub = substr($amount, (strlen($j) + 4), $len);
            $amount = $j . ',' . substr($amount, strlen($j), 2) . ',' . substr($amount, (strlen($j) + 2), 2) . ',' . $sub;
            $str = $amount;

            break;
    }
    if (empty($str)) {
        $str = '0';
    }
    if (empty($after_point)) {
        $after_point = '00';
    }

    $str .= "." . $after_point;

    if (!empty($minus)) {
        $str = $minus . $str;
    }
    return $str;
}   
        
        $data["GoogleAdsLeads"] = DB::table('digitaladsleads')
        
        ->select('digitaladsleads.id as id','digitaladsleads.start_date','digitaladsleads.nextFollowupDate','CustomerName','OrganizationName','industry_type','apply_loanAmt','BankName','name','promoCode','ChannelSource','digitaladsleads.status','home_Location')
        ->join('loanproduct','digitaladsleads.LoanProduct','=','loanproduct.id')
        
        ->where('type', 'manual')
        
        ->where ("digitaladsleads.status","OLD PENDING FOLLOW-UP")
        
        ->orderBy('digitaladsleads.id', 'DESC')
        
        ->get();
        
        $data4 = $data["GoogleAdsLeads"];
        $array = json_decode(json_encode($data4), true);
        
        $apply_loanAmt = ($array[0]['apply_loanAmt']);
        $amount2Rs     = amount2Rs($apply_loanAmt);
        return view("layouts.OldPendingFollowUp",["OldPendingFollowUp"=>$array,"amount2Rs"=>$amount2Rs]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\OldPendingFollowUp  $oldPendingFollowUp
     * @return \Illuminate\Http\Response
     */
    public function show(OldPendingFollowUp $oldPendingFollowUp)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\OldPendingFollowUp  $oldPendingFollowUp
     * @return \Illuminate\Http\Response
     */
    public function edit(OldPendingFollowUp $oldPendingFollowUp)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\OldPendingFollowUp  $oldPendingFollowUp
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, OldPendingFollowUp $oldPendingFollowUp)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\OldPendingFollowUp  $oldPendingFollowUp
     * @return \Illuminate\Http\Response
     */
    public function destroy(OldPendingFollowUp $oldPendingFollowUp)
    {
        //
    }
}
