<?php

namespace App\Http\Controllers;

use App\Models\Packages;
use App\Models\PermissionActions;
use PDF;

use Illuminate\Http\Request;

class PricingController extends Controller
{
    function viewpricing()
    {
        $silver = PermissionActions::select("Pack_Name", "tbl_packages.id as packid", "act_desc", "act_status" ,"act_slug")
            ->join('tbl_packages', 'tbl_permissionActions.act_package', '=', 'tbl_packages.id')
            ->where('tbl_packages.Pack_Slug', '=', 'silver')
            ->get();

        $gold = PermissionActions::select("Pack_Name", "tbl_packages.id as packid", "act_desc", "act_status","act_slug")
            ->join('tbl_packages', 'tbl_permissionActions.act_package', '=', 'tbl_packages.id')
            ->where('tbl_packages.Pack_Slug', '=', 'gold')
            ->get();

        $platinum = PermissionActions::select("Pack_Name", "tbl_packages.id as packid", "act_desc", "act_status","act_slug")
            ->join('tbl_packages', 'tbl_permissionActions.act_package', '=', 'tbl_packages.id')
            ->where('tbl_packages.Pack_Slug', '=', 'platinum')
            ->get();

            $silverprice = Packages::where('Pack_Slug','=','silver')->pluck('Pack_payment')->first();
            $silveradvance = Packages::where('Pack_Slug','=','silver')->pluck('advance')->first();
            $silveremi = Packages::where('Pack_Slug','=','silver')->pluck('emi')->first();

            $goldprice = Packages::where('Pack_Slug','=','gold')->pluck('Pack_payment')->first();
            $goldpadvance = Packages::where('Pack_Slug','=','gold')->pluck('advance')->first();
            $goldemi = Packages::where('Pack_Slug','=','gold')->pluck('emi')->first();

            $platinumprice = Packages::where('Pack_Slug','=','platinum')->pluck('Pack_payment')->first();
            $platinumadvance = Packages::where('Pack_Slug','=','platinum')->pluck('advance')->first();
            $platinumemi = Packages::where('Pack_Slug','=','platinum')->pluck('emi')->first();

        $load = '';

        for($i = 0; $i < count($silver) ; $i++) 
        {
            $load .= "<tr>
                      <td>
                      ";
                      
                      
                      if($silver[$i]['act_slug'] != 'trial')
                      {
                        if($silver[$i]['act_status'] == 0 )
                      {
                        $load .= " <img width='15px' height='15px' src='https://api.digitronicsindia.com/aswas/public/uploads/ic_close.png'> ";
                      }
                      else
                      {
                        $load .= " <img width='15px' height='15px' src='https://api.digitronicsindia.com/aswas/public/uploads/ic_tick.png'> ";
                      }
                      
                        $load .= "
                      ".$silver[$i]['act_desc']."
                      </td>";
                      }

            // $load .= "<td> ".$gold[$i]['act_desc']." </td>";

            // $load .= " <td> ".$platinum[$i]['act_desc']." </td> </tr>";

            $load .= "
            <td>
            ";
           
            
            if($gold[$i]['act_slug'] != 'trial')
            {

              if($gold[$i]['act_status'] == 0)
              {
                $load .= " <img width='15px' height='15px' src='https://api.digitronicsindia.com/aswas/public/uploads/ic_close.png'> ";
              }
              else
              {
                $load .= " <img width='15px' height='15px' src='https://api.digitronicsindia.com/aswas/public/uploads/ic_tick.png'> ";
              }


              $load .= "
            ".$gold[$i]['act_desc']."
            </td>";
            }



            $load .= "
            <td>
            ";
           
            
            if($platinum[$i]['act_slug'] != 'trial')
            {

              if($platinum[$i]['act_status'] == 0)
              {
                $load .= " <img width='15px' height='15px' src='https://api.digitronicsindia.com/aswas/public/uploads/ic_close.png'> ";
              }
              else
              {
                $load .= " <img width='15px' height='15px' src='https://api.digitronicsindia.com/aswas/public/uploads/ic_tick.png'> ";
              }

              
              $load .= "
            ".$platinum[$i]['act_desc']."
            </td></tr>";
            }
            
        }

        $data = [
            'silver' => $silver,
            'gold' => $gold,
            'platinum' => $platinum,
            'items' => $load,

            'silverprice' => $silverprice ,
            'goldprice' => $goldprice ,
            'platinumprice' => $platinumprice ,
            
            'silveradvance' => $silveradvance ,
            'silveremi' => $silveremi ,

            'goldpadvance' => $goldpadvance ,
            'goldemi' => $goldemi ,
            
            'platinumadvance' => $platinumadvance ,
            'platinumemi' => $platinumemi ,
        ];

        // return $load;

        // return view('Admin.pricing', $data);
        // return $packages;
        $pdf = PDF::loadView('Admin.pricing',$data)->set_option("isPhpEnabled", true)->setPaper('a4','portrait');

        return $pdf->set_option("isPhpEnabled", true)->download('pricing.pdf');
    }
}
