<?php

namespace App\Helper;

use EF;
use File;
use DateTime;
use Spatie\Permission\Models\Role;
use Toastr;
use Storage;

class EstatechHelper

{
    public static $S3DIR = "skylite/";

    public static function getS3Directory() {
        return self::$S3DIR;
    }

  /**

     * Get the registered name of the component.

     *

     * @return string

     */

   public  function getFacadeAccessor()

    {
        return 'ef';
    }

    public function appSetting()
    {
        return [
            'app_name'              => 'Skylite Builders',
            'first_logo'            => 'logo.jpg',
            'second_logo'           => 'logo.jpg',
            'dashboard_text_color'  => '#E1832C'  

        ];
    }

    public function getVendorPaymentType()
    {
        return ['Pay Later','Pay Now'];
    }

   public  function getAccountInfo()
    {
        return [
            'vendor' => 9,
            'inventory from supplies' => 7,
            'control account' => 8,
            'cash'  => 1,

        ];
    }

    // JSON USER RIGHT STATIC FUNCTION

   public function getUserRightByNavigation($attribute,$value)
    {
        $right_list = [];

        if(isset(Auth::user()->id))
        {
            foreach (json_decode(Auth::user()->user_rights,true) as $rows)
            {
                if($rows[$attribute] == $value)
                {
                    $right_list[] = $rows;
                }
            }
        }

        return json_decode(json_encode($right_list));
    }

   public function dateHtml($value)
    {


        return str_replace('1970-01-01',' ',date('Y-m-d',strtotime($value)));

    }

   public function getCityList()
    {
        return [

            "Abbottabad",
            "Adezai",
            "Ali Bandar",
            "Amir Chah",
            "Attock",
            "Ayubia",
            "Bahawalpur",
            "Baden",
            "Bagh",
            "Bahawalnagar",
            "Burewala",
            "Banda Daud Shah",
            "Bannu",
            "Batagram",
            "Bazdar",
            "Bela",
            "Bellpat",
            "Bhag",
            "Bhakkar",
            "Bhalwal",
            "Bhimber",
            "Birote",
            "Buner",
            "Burj",
            "Chiniot",
            "Chachro",
            "Chagai",
            "Chah Sandan",
            "Chailianwala",
            "Chakdara",
            "Chakku",
            "Chakwal",
            "Chaman",
            "Charsadda",
            "Chhatr",
            "Chichawatni",
            "Chitral",
            "Dadu",
            "Dera Ghazi Khan",
            "Dera Ismail Khan",
             "Dalbandin",
            "Dargai",
            "Darya Khan",
            "Daska",
            "Dera Bugti",
            "Dhana Sar",
            "Digri",
            "Dina City|Dina",
            "Dinga",
            ", Pakistan|Diplo",
            "Diwana",
            "Dokri",
            "Drosh",
            "Duki",
            "Dushi",
            "Duzab",
            "Faisalabad",
            "Fateh Jang",
            "Ghotki",
            "Gwadar",
            "Gujranwala",
            "Gujrat",
            "Gadra",
            "Gajar",
            "Gandava",
            "Garhi Khairo",
            "Garruck",
            "Ghakhar Mandi",
            "Ghanian",
            "Ghauspur",
            "Ghazluna",
            "Girdan",
            "Gulistan",
            "Gwash",
            "Hyderabad",
            "Hala",
            "Haripur",
            "Hab Chauki",
            "Hafizabad",
            "Hameedabad",
            "Hangu",
            "Harnai",
            "Hasilpur",
            "Haveli Lakha",
            "Hinglaj",
            "Hoshab",
            "Islamabad",
            "Islamkot",
            "Ispikan",
            "Jacobabad",
            "Jamshoro",
            "Jhang",
            "Jhelum",
            "Jamesabad",
            "Jampur",
            "Janghar",
            "Jati(Mughalbhin)",
            "Jauharabad",
            "Jhal",
            "Jhal Jhao",
            "Jhatpat",
            "Jhudo",
            "Jiwani",
            "Jungshahi",
            "Karachi",
            "Kotri",
            "Kalam",
            "Kalandi",
            "Kalat",
            "Kamalia",
            "Kamararod",
            "Kamber",
            "Kamokey",
            "Kanak",
            "Kandi",
            "Kandiaro",
            "Kanpur",
            "Kapip",
            "Kappar",
            "Karak City",
            "Karodi",
            "Kashmor",
            "Kasur",
            "Katuri",
            "Keti Bandar",
            "Khairpur",
            "Khanaspur",
            "Khanewal",
            "Kharan",
            "kharian",
            "Khokhropur",
            "Khora",
            "Khushab",
            "Khuzdar",
            "Kikki",
            "Klupro",
            "Kohan",
            "Kohat",
            "Kohistan",
            "Kohlu",
            "Korak",
            "Korangi",
            "Kot Sarae",
            "Kotli",
            "Lahore",
            "Larkana",
            "Lahri",
            "Lakki Marwat",
            "Lasbela",
            "Latamber",
            "Layyah",
            "Leiah",
            "Liari",
            "Lodhran",
            "Loralai",
            "Lower Dir",
            "Shadan Lund",
            "Multan",
            "Mandi Bahauddin",
            "Mansehra",
            "Mian Chanu",
            "Mirpur",
            ", Pakistan|Moro",
            "Mardan",
            "Mach",
            "Madyan",
            "Malakand",
            "Mand",
            "Manguchar",
            "Mashki Chah",
            "Maslti",
            "Mastuj",
            "Mastung",
            "Mathi",
            "Matiari",
            "Mehar",
            "Mekhtar",
            "Merui",
            "Mianwali",
            "Mianez",
            "Mirpur Batoro",
            "Mirpur Khas",
            "Mirpur Sakro",
            "Mithi",
            "Mongora",
            "Murgha Kibzai",
            "Muridke",
            "Musa Khel Bazar",
            "Muzaffar Garh",
            "Muzaffarabad",
            "Nawabshah",
            "Nazimabad",
            "Nowshera",
            "Nagar Parkar",
            "Nagha Kalat",
            "Nal",
            "Naokot",
            "Nasirabad",
            "Nauroz Kalat",
            "Naushara",
            "Nur Gamma",
            "Nushki",
            "Nuttal",
            "Okara",
            "Ormara",
            "Peshawar",
            "Panjgur",
            "Pasni City",
            "Paharpur",
            "Palantuk",
            "Pendoo",
            "Piharak",
            "Pirmahal",
            "Pishin",
            "Plandri",
            "Pokran",
            "Pounch",
            "Quetta",
            "Qambar",
            "Qamruddin Karez",
            "Qazi Ahmad",
            "Qila Abdullah",
            "Qila Ladgasht",
            "Qila Safed",
            "Qila Saifullah",
            "Rawalpindi",
            "Rabwah",
            "Rahim Yar Khan",
            "Rajan Pur",
            "Rakhni",
            "Ranipur",
            "Ratodero",
            "Rawalakot",
            "Renala Khurd",
            "Robat Thana",
            "Rodkhan",
            "Rohri",
            "Sialkot",
            "Sadiqabad",
            "Safdar Abad- (Dhaban Singh)",
            "Sahiwal",
            "Saidu Sharif",
            "Saindak",
            "Sakrand",
            "Sanjawi",
            "Sargodha",
            "Saruna",
            "Shabaz Kalat",
            "Shadadkhot",
            "Shahbandar",
            "Shahpur",
            "Shahpur Chakar",
            "Shakargarh",
            "Shangla",
            "Sharam Jogizai",
            "Sheikhupura",
            "Shikarpur",
            "Shingar",
            "Shorap",
            "Sibi",
            "Sohawa",
            "Sonmiani",
            "Sooianwala",
            "Spezand",
            "Spintangi",
            "Sui",
            "Sujawal",
            "Sukkur",
            "Suntsar",
            "Surab",
            "Swabi",
            "Swat",
            "Tando Adam",
            "Tando Bago",
            "Tangi",
            "Tank City",
            "Tar Ahamd Rind",
            "Thalo",
            "Thatta",
            "Toba Tek Singh",
            "Tordher",
            "Tujal",
            "Tump",
            "Turbat",
            "Umarao",
            "Umarkot",
            "Upper Dir",
            "Uthal",
            "Vehari",
            "Veirwaro",
            "Vitakri",
            "Wadh",
            "Wah Cantt",
            "Warah",
            "Washap",
            "Wasjuk",
            "Wazirabad",
            "Yakmach",
            "Zhob"

        ];
    }

   public function createLogs($message, $type = 'activity')
    {

        $current_month = date('m-Y');
        $file_name = $type.'_logs/'.$current_month.'.json';

        try {

           // my data storage location is project_root/storage/app/data.json file.
            $old_logs = \Storage::disk('local')->exists($file_name) ? json_decode(\Storage::disk('local')->get($file_name)) : [];

           $user = \Auth::user();

           if(isset($user->id))
           {

               date_default_timezone_set("Asia/karachi");


               $inputData = array(
                       'user_id'   => $user->id,
                       'name'      => $user->name,
                       'branch'    => $user->branch->name,
                       'type'      => $type,
                       'log_date'  => date('d-M-Y'),
                       'log_time'  => date('H:i:s'),
                       'message'   => str_replace('.','', $message.' by '.$user->name).'.',
                   );



               array_push($old_logs,$inputData);

               \Storage::disk('local')->put($file_name, json_encode($old_logs),'public');

                // Session::put('logs_key',$primary_key);
           }

       } catch(Exception $e) {

           return ['error' => true, 'message' => $e->getMessage()];

       }
    }

    // S3 STORAGE FUNCTION
   public function uploadFile($file)
    {
        // ENABLED WHEN YOU ARE USING LOCAL STORAGE
        return EF::uploadLocalFile($file);
        // END 

        if(strlen(trim($file)))
        {
            $name = uniqid().'.'.$file->getClientOriginalExtension();


            \Storage::disk('s3')->put('skylite/'.$name,file_get_contents($file));

            return $name; 
        }
        else
        {
            return '/graphics/logo/user.png';
        }
        

    }


   public function showStatusColor($status)
    {
        $color = 'bg-primary';

        if($status === "Active")
        {
            $color = 'bg-success';
        }
        else if($status === "Deactive")
        {
            $color = 'bg-danger';
        }

        return $color;
    }


   public function getLettersList()
    {
        // $letters_list = ['Thanks Letter','Possession Letter','Intimation of Possession Letter','Transfer Rights Letter','Allotment Rights Letter','Payment Reminder Letter','Confirmation of Allotment'];

         $letters_list = ['Thanks Letter','Possession Letter','Intimation of Possession Letter','Transfer Rights Letter','Allotment Rights Letter','Payment Reminder Letter','Confirmation of Allotment'];


        return $letters_list;
    }

   public function getFile($file_name)
    {
        // ENABLED WHEN YOU ARE USING LOCAL STORAGE
        return EF::getLocalFile($file_name);
        // END  

        if($file_name != '/graphics/logo/user.png')
        {
            $disk = \Storage::disk('s3');
            $adapter = Storage::disk('s3')->getDriver()->getAdapter();
            
            $command = $adapter->getClient()->getCommand('GetObject', [
                'Bucket' => $adapter->getBucket(),
                'Key'    => $adapter->getPathPrefix().'skylite/'.$file_name
            ]);
            
            $request = $adapter->getClient()->createPresignedRequest($command, '+1 minute');

            return $request->getUri();
        }
        else
        {
            return url('/graphics/logo/user.png');
        }

    }

   public function getUserRightById($id)
    {
        if(isset(Auth::user()->id))
        {
            foreach (json_decode(Auth::user()->user_rights) as $rows)
            {
                if($rows->id === $id)
                {
                    return $rows;
                }
            }
        }
        // RECORD NOT FOUND.
        return false;
    }

   public function isUserRightFound($id)
    {
        if(isset(Auth::user()->id))
        {
            foreach (json_decode(Auth::user()->user_rights) as $rows)
            {
                if($rows->id === $id)
                {
                    return true;
                }
            }
        }
        // RECORD NOT FOUND.
        return false;
    }


    // END JSON USER RIGHT STATIC FUNCTION

    public function getUrl()
    {
        return explode('/',\URL::current())[3];
    }




   public function numberFormat($value)

    {

        return number_format($value,2);

    }

       public function showCustomDate($value,$format)
    {

        return str_replace('01-Jan-1970',' ',date($format,strtotime($value)));

    }

   public function getdateByFormat($format,$value)

    {


        return date($format,strtotime($value));

    }



   public function dateFormat($value)

    {

    	return str_replace('01-Jan-1970',' ',date('d-M-Y',strtotime($value)));

    }



   public function numberToWords($number)

    {
        

    	return strtoupper(EF::convertToWords(abs($number)));

    }



   public function getNatureList()
    {
        // Fixed Assets
        // Variable Assets
        // Capital / Equity
        // Expense
        // Expense - Cost of Sales
        // Revenue
        // Long term liability
        // Short term liability
        // return ['Asset','Revenue','Capital','Expense','Liability'];
        // return [
        //     'Fixed Assets','Current Assets','Capital / Equity','Expense','Expense - Cost of Sales','Revenue','Long-term Liability','Short-term Liability'
        // ];

        return [

            'Fixed Assets',             // 0
            'Current Assets',           // 1
            'Capital / Equity',         // 2
            'Long-term Liability',      // 3
            'Short-term Liability',     // 4
            'Revenue',                  // 5
            'Cost of Sales',            // 6
            'Expense',                  // 7

        ];


    }
   public function getNatureValue($nature)
    {

        $data = [

                'Fixed Assets'              => '001',
                'Current Assets'            => '002',
                'Capital / Equity'          => '003',
                'Expense'                   => '008',
                'Cost of Sales'             => '007',
                'Revenue'                   => '006',
                'Long-term Liability'       => '004',
                'Short-term Liability'      => '005',
        ];


        if(isset($data[trim($nature)]))
        {
            return $data[$nature];
        }
        else
        {
            return 0;
        }


    }
   public function getPlanType()

    {

        return ['Token','Down Payment','Booking','Confirmation','Allotment','Allocation','Possession','One Time','Installment','Quarter'];

    }

   public function getEmployeeType()
    {
        return ['Permanent','Intern','Temporary'];
    }

  public function getLogType()
    {
        return ['document','activity'];
    }
   public function getAccountsTypeList()
    {
        return ['General','Cash','Bank','Expense','Liability'];
    }

   public function getProjectLogo($project)
    {
        if($project == "Crown Business Center")
        {


            return "graphics/logo/Crown Business Center.png";
        }
        elseif($project == "Capital Square")
        {
             return "graphics/logo/Capital Square.png";
        }
        elseif($project == "Capital Villas")
        {
             return "graphics/logo/Capital Villas.png";
        }
        elseif($project == "Capital Homes")
        {
             return "graphics/logo/Capital Homes.png";
        }
        elseif($project == "The Galleria")
        {
             return "graphics/logo/The Galleria.png";
        }
        elseif($project == "AROOJ ARCADE")
        {
             return "graphics/logo/Arooj Arcade.png";
        }
        elseif($project == "Capital Business Center")
        {
            return "graphics/logo/logo Capital Business Center.png";
        }
        elseif($project == "Paradise Mansions")
        {
            return "graphics/logo/Paradise Mansions.png";
        }
         elseif($project == "Meher Apartments")
        {
            return "graphics/logo/Meher Apartments.png";
        }
         elseif($project == "Paradise Villas")
        {
            return "graphics/logo/Paradise Villas.png";
        }
           elseif($project == "Royal Apartments")
        {
            return "graphics/logo/Royal Apartments.png";
        }
        else
        {
            return "graphics/logo/logo.jpg";
        }



    }


   public function getSalaryMode()
    {
        return ['Cash','Cheque','Online'];
    }


   public function getPaymentMode()
    {
        return ['Cash','Cheque','Pay Order','Online','Adjustment'];
    }

  public function getVoucherType()
   {
       return ['General','Multiple Debit','Multiple Credit'];
   }
  public function getVoucherList()
   {
       return ['BRV','CRV','BPV','CPV','JV'];
   }

  public function getFullVoucherList()
   {
       return ['BRV' => 'Bank Receipt Voucher','CRV' => 'Cash Receipt Voucher','BPV' => 'Bank Payment Voucher','CPV' => 'Cash Payment Voucher','JV' => 'Journal Voucher'];
   }

  public function getPaymentType()
   {
       return ['Installment','Commission','Refund','Deduction','Transfer'];
   }
   public function getNomineeType()
    {
        return ['Nominee','Co-Owner'];
    }

   public function getUserType()
    {
        $roles = Role::all()->pluck('name');

        $index = $roles->search('Super Admin');

        $roles->pull($index);
        // return ['Dealer','Sub Dealer','Employee','Customer'];
        return $roles->toArray();
    }

   public function getUserTypeWithRole()
    {
        $roles = Role::all();

        // $index = $roles->search('Super Admin');

        // $roles->pull($index);
        // return ['Dealer','Sub Dealer','Employee','Customer'];
        return $roles->whereNotIn('name', ['Super Admin']);
    }

   public function getVoucherStatus()
    {
        return ['Approve','Reject','Reverse'];
    }

   public function calculatePercentage($parameter1,$parameter2,$percent)
    {
        if($parameter2 > 0)
        {
            $percentage = (($parameter1/$parameter2)*$percent);
        }
        else
        {
            $percentage = 0;

        }
        return $percentage;

    }

   public function getPriorityList()
    {
        return ['High','Medium','Low'];
    }

   public function getStatusList()
    {
        return ['Active','Deactive'];
    }

   public function getModuleList()
    {

        return ['Dashboard','Branch','User','Booking','Plot','Finance','Report','Document','Call Center','Installment Plan','Side Payments','Chart of Accounts','Log','Letter','SMS','HR','Inventory'];
    }

   public function getNavigationTypeList()
    {
        return ['Navigation','Feature'];
    }



       public function getCancelFormWhiteLabel()
    {
        return [
            'deduction_amount'   =>  'deduction_amount',
            'refund_amount'      =>  'refund_amount'


        ];
    }


   public function getStatus($status)
    {

        if($status == 'Approve')
        {
            return 'Approved';

        }
        elseif ($status == 'Unapprove')
        {
             return 'Unapproved';
        }
        elseif($status == 'Reversal')
        {
             return 'Reversed';
        }
        else
        {
            return $status;
        }
    }


   public function convertToWords($number)

    {



        $hyphen      = '-';

        $conjunction = ' and ';

        $separator   = ', ';

        $negative    = 'negative ';

        $decimal     = ' point ';

        $dictionary  = array(

            0                   => 'zero',

            1                   => 'one',

            2                   => 'two',

            3                   => 'three',

            4                   => 'four',

            5                   => 'five',

            6                   => 'six',

            7                   => 'seven',

            8                   => 'eight',

            9                   => 'nine',

            10                  => 'ten',

            11                  => 'eleven',

            12                  => 'twelve',

            13                  => 'thirteen',

            14                  => 'fourteen',

            15                  => 'fifteen',

            16                  => 'sixteen',

            17                  => 'seventeen',

            18                  => 'eighteen',

            19                  => 'nineteen',

            20                  => 'twenty',

            30                  => 'thirty',

            40                  => 'fourty',

            50                  => 'fifty',

            60                  => 'sixty',

            70                  => 'seventy',

            80                  => 'eighty',

            90                  => 'ninety',

            100                 => 'hundred',

            1000                => 'thousand',

            1000000             => 'million',

            1000000000          => 'billion',

            1000000000000       => 'trillion',

            1000000000000000    => 'quadrillion',

            1000000000000000000 => 'quintillion'

        );



        if (!is_numeric($number)) {

            return false;

        }



        if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {

            // overflow

            trigger_error(

                'convertToWords only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,

                E_USER_WARNING

            );

            return false;

        }

        if ($number < 0) {

            return $negative . convertToWords(abs($number));

        }



        $string = $fraction = null;



        if (strpos($number, '.') !== false) {

            list($number, $fraction) = explode('.', $number);

        }



        switch (true) {

            case $number < 21:

                $string = $dictionary[$number];

                break;

            case $number < 100:

                $tens   = ((int) ($number / 10)) * 10;

                $units  = $number % 10;

                $string = $dictionary[$tens];

                if ($units) {

                    $string .= $hyphen . $dictionary[$units];

                }

                break;

            case $number < 1000:

                $hundreds  = $number / 100;

                $remainder = $number % 100;

                $string = $dictionary[$hundreds] . ' ' . $dictionary[100];

                if ($remainder) {

                    $string .= $conjunction . EF::convertToWords($remainder);

                }

                break;

            default:

                $baseUnit = pow(1000, floor(log($number, 1000)));

                $numBaseUnits = (int) ($number / $baseUnit);

                $remainder = $number % $baseUnit;

                $string = EF::convertToWords($numBaseUnits) . ' ' . $dictionary[$baseUnit];

                if ($remainder) {

                    $string .= $remainder < 100 ? $conjunction : $separator;

                    $string .= EF::convertToWords($remainder);

                }

                break;

        }



        if (null !== $fraction && is_numeric($fraction)) {

            $string .= $decimal;

            $words = array();

            foreach (str_split((string) $fraction) as $number) {

                $words[] = $dictionary[$number];

            }

            $string .= implode(' ', $words);

        }



        return $string;

    }



   public function getCategoryList()
    {
        return ['Executive','Luxury','Standard','Regal','Pent House','Classic','Platinum','Gold','Silver','Nobel','Diamond','Villas','Shop','Office'];
    }

   public function getFeatureList()
    {
        return ['Corner','Parking','Face','Special'];
    }

   public function getTypeList()
    {
       return['Flat','Office','Shop','House','Villa','Entertainment'];
    }


    // WHITE LABEL

   public function moduleWhiteLabel()
    {

    }

   public function getWhiteLabel()
    {

        return [
            'file'               => 'file',
            'reference'          => 'reference',
            'booking_date'       => 'booking_date',
            'approve_date'       => 'approve_date',
            'block'              => 'block',
            'size'               => 'area',
            'plot'               =>  EF::plotWhiteLabel()['module'],
            'rate_per_marla'     => 'rate_per_marla',
            'total_amount'       => 'total_price',
            'feature_charges'    => 'feature_charges',
            'feature_description' => 'feature_description',
            'discount'           => 'discount',
            'agreed_amount'      => 'agreed_amount',
            'remarks'            => 'remarks',
            'receipt'            => 'receipt',
            'token_amount'       => 'token_amount',
            'payment_mode'       => 'payment_mode',
            'transfer_date'      => 'transfer_date',
            'transfer_fee'       => 'fee',
            'type'               => 'type',
            'category'           => 'category',
            'start_date'           => 'start_date',
            'end_date'           => 'end_date',
            'reserve_booking'           => 'reserve_booking',


            'branch'             =>  EF::branchWhiteLabel()['module']


        ];
    }



   public function plotWhiteLabel()
    {
        $module_name = 'article';

        return [

            'module'                =>  $module_name,
            'plot_name'             =>  $module_name.'_no',
            'block'                 => 'block',
            'size'                  => 'area',
            'category'              => 'category',
            'type'                  => 'type',
            'feature_description'   => 'feature_description',
            'dimension'             => 'dimension',
            'rate'                  => 'price',
            'marla'                 => 'size',
            'feature'               => 'feature',
            'feature_charges'       => 'feature_charges',
            'branch'                =>  EF::branchWhiteLabel()['module'],
            'inventory'             =>  'inventory',
            'location'              =>  $module_name.'_location',
            'feature_list'          =>  'select_features',
            'floor'                 =>  'floor',
            'dimension_x'           =>  'dimension_x',
            'dimension_y'           =>  'dimension_y',



        ];
}
   public function departmentWhiteLabel()
    {
         return [
            'department_name'              => 'name',
            'department_code'              => 'code',
            'department_description'       => 'description',
            'department_status'            => 'status'



        ];
    }


   public function branchWhiteLabel()
    {
        $module_name = 'project';

        return [

            'module'            =>  $module_name,
            'code'              =>  'code',
            'name'              =>  'name',
            'email'             =>  'email',
            'contact'           =>  'contact',
            'commission'        =>  'commission',
            'branch'            =>  'branch',
            'location'          =>  'location',
            'city'              =>  'city',
            'start_date'        =>  'start_date',
            'end_date'          =>  'end_date',






        ];
    }

     public function getLeavesTypeList()
    {
        return ['Short Leave','Full Leave','Sick Leave'];
    }


   public function getSettingsTypeList()
    {
        return ['Leave','Tax'];
    }

   public function getFloorList()
    {
        return ['2B','LG','G1','B','E','G','M','1F','2F','3F','4F','5F','6F','7F','8F','9F','10F','11F','12F','13F','14F','15F','16F','17F','18F','19F','20F'];
    }

   public function showPlotFormat($plot)
    {
        $view = '';

        if(isset($plot->id))
        {
            if(strlen(trim($plot->floor)) > 0)
            {
                $view = $plot->branch->code.'-'.$plot->floor.'-'.$plot->plot_id;
            }
            else
            {
                $view = $plot->branch->code.'-'.$plot->plot_id;
            }
        }

        return $view;
    }

       public function getBillExpenseType()
        {
          return ['Cost of Sales','Administrative'];
        }
       public function getBillLaibilityType()
        {
        return ['Short Term','Long Term'];
        }
       public function getBilPayableType()
        {
        return ['One Time','Reoccuring'];
        }


   public function getLocationList()
    {
         return ['Head Office','Blue Area Office','CBC & Royal Apartments E-11','Capital Square B-17','Capital Villas B-17','PVA & Tulip Apartments D-17','The Gate, Faisal Town','Capital Business Center, Faisal Town','The Arch, G-11','Meher Apartments H-13'];
    }


   public function getBloodGroupList()
    {
        return ['A+','B+','AB+','A-','B-','AB-','O+','O-'];
    }

   public function getGenderList()
    {
        return ['Male','Female'];
    }

   public function getGenericTableIndex()
    {
        return [
            'Installment'       => 1,
            'Commission'        => 2,
            'Booking'           => 3,
            'Loan'              => 4,
            'Payroll'           => 5,
            'HR Adjustment'     => 6,
            'Bills'             => 7,
            'Inventory'         => 8,
            'Inventory Payable' => 9,
            'Invoice'           => 10,
            'Vendor Payment'    => 11,
        ];
    }


    // END WHITE LABEL

    // COMMISSION ACCOUNT SETTING
   public function getCommissionAccount()
    {
        return [
            'commission_debit'  => 12, // EXPENSE / BOOKING COMMISSION
            'commission_credit' => 11, // SHOT TERM LIABILITY / ACCOUNT LIABILITY
        ];

    }
    // END

     // COMMISSION ACCOUNT SETTING
   public function getBankOpeningAccount()
    {
        return [
            'opening_credit' => 13, // CAPITAL / EQUITY => EQUITY INTRODUCE
        ];

    }
    // END

    // RECEIVABLE ACCOUNT WORKING ONLY ALOTMENT / MEMBERSHIP FEE SETTING
   public function getReceivableAccount()
    {
        return [
            'receivable_debit'  => 1, // BOOKING RECEIVABLE / ACCOUNT RECEIVABLE
            'receivable_credit' => 2, // RREVENUE / ACCOUNT REVENUE
        ];

    }

 public function getProductUnitList()
    {
        $unit_list = ['Kg','Ton','Gram'];

        return $unit_list;
    }

   public function getItemTypeList()
    {
        $type_list = ['Product','Service'];

        return $type_list;
    }

   public function getServiceUnitList()
    {
        $unit_list = ['per hour','per person','per item'];

        return $unit_list;
    }

   public function getProductCategoryList()
    {
        $category_list = ['Cement','Tiles','Other'];

        return $category_list;
    }

     public function getServiceCategoryList()
    {
        $category_list = ['S1','S2','Other'];

        return $category_list;
    }

    // Created By Yousaf
   public function dateDiffForHumans($from_this_date, $to_this_date){
        // $fromYear = date("Y", strtotime($fromThisDate));
        // $fromMonth = date("m", strtotime($fromThisDate));
        // $fromDay = date("d", strtotime($fromThisDate));

        // $toYear = date("Y", strtotime($toThisDate));
        // $toMonth = date("m", strtotime($toThisDate));
        // $toDay = date("d", strtotime($toThisDate));

        $from_this_date = new DateTime(date("Y-m-d",strtotime($from_this_date)));
        $to_this_date   = new DateTime(date("y-m-d",strtotime($to_this_date)));

        $difference_of_date = $from_this_date->diff($to_this_date);

        $date_string = "";
        if($difference_of_date->y > 0){
            if($difference_of_date->y > 1){
                $date_string .= $difference_of_date->y ." Years ";
            }
            else{
                $date_string .= $difference_of_date->y ." Year ";
            }

        }

        if($difference_of_date->m > 0){
            if($difference_of_date->m > 1){
                $date_string .= $difference_of_date->m ." Months ";
            }
            else{
                $date_string .= $difference_of_date->m ." Month ";
            }
        }

        if($difference_of_date->d > 0){
            if($difference_of_date->d > 1){
                $date_string .= $difference_of_date->d ." Days ";
            }
            else{
                $date_string .= $difference_of_date->d ." Day ";
            }
        }

        if(empty($date_string)){
            $date_string .= "First Day ";
        }

        return $date_string;

    }
    //End

    public static  function getRoleIdByName($name)
    {
        $role_id = 0;

        $role = new Role;

        $role = $role->findByName($name);

        if(isset($role->id))
        {
            $role_id = $role->id;
        }

        return $role_id;
    }

   public function getRoleNameById($id)
    {
        $name = "";

        $role = new Role;

        $role = $role->findById($id);

        if(isset($role->id))
        {
            $name = $role->name;
        }

        return $name;
    }

   public function getNumOfDays($number,$current_date,$flag)
    {
        if($flag == 1)
        {


            return date('Y-m-d',strtotime('+'.$number.' day',strtotime($current_date)));

        }

        elseif($flag == 2)
        {
            return date('Y-m-d',strtotime('+'.$number.' week',strtotime($current_date)));

        }
        else
        {
            return date('Y-m-d',strtotime('+'.$number.' month',strtotime($current_date)));
        }

    }

   public function getInvoiceStatus()
    {
        return ['Pending', 'Approve'];
    }

   public function textWrap($text,$size)
    {
        return wordwrap($text,$size,"<br>\n");
    }
   public function getLeadStatus()
    {
        return ['New Contact','Contacted','Interested','Under Review','Qualified','Unqualified'];
    }

   public function getTaskStatus()
    {
        return ['Completed','Pending','Incomplete'];
    }
   public function getVisitType()
    {
        return ['Walk in','Call','Chat','Social Media','Email','Cold Call','Negotiation'];

    }

   public function filterEmail($email)
    {
        if (strpos($email, 'estatech') !== false) {
            return '';
        }
        return $email;
    }

   public function getFirstBranch()
    {
        $first_branch = \App\Branch::orderBy('id','asc')->first();

        if(isset($first_branch->id))
        {
            return $first_branch->id;
        }
        else
        {
            return 0;
        }
    }

    public static function errorMessage($message,$status = 1)
    {
        EF::clearMessageLog($status);
        Toastr::error($message, 'Fail', ["positionClass" => "toast-bottom-right"]);
    }

    public static function clearMessageLog($status)
    {
        if($status == 1)
        {
            Toastr::clear();
        }
    }

    public static function downloadS3Data($data,$column)
    {
        \Artisan::call('storage:link');
        \File::makeDirectory(storage_path("app/public/".EF::getS3Directory()), 0777, true, true);
        // CHANGE DIRECTORY NAME APP TOP APP THIS IS MORE IMPORTANT STEP
        $file_path = EF::getS3Directory();
        // END CHANGE DIRECTORY NAME APP TOP APP THIS IS MORE IMPORTANT STEP

        $key = config('filesystems.disks.s3.key');
        $secret = config('filesystems.disks.s3.secret');
        $region = config('filesystems.disks.s3.region');
        $bucket = config('filesystems.disks.s3.bucket');
        $s3 = new \Aws\S3\S3Client([
            'version' => 'latest',
            'region' => $region,
            'credentials' => [
                'key'    => $key,
                'secret' => $secret,
            ],
        ]);

        $objects = $s3->listObjectsV2([
            'Bucket' => $bucket,
        ]);

        
        foreach ($data as $object) {
            $filePath = $file_path . $object->$column;
        
            try {
                
                // Check if the file exists in S3
                $s3->headObject([
                    'Bucket' => $bucket,
                    'Key' => $filePath,
                ]);
        
                // File exists, proceed with downloading
                $fileContent = $s3->getObject([
                    'Bucket' => $bucket,
                    'Key' => $filePath,
                ])['Body']->getContents();
        
                $localFilePath = storage_path("app/public/{$filePath}");

                if (File::exists($localFilePath)) {
                    // The file exists on the local storage
                    continue;
                }
        
                file_put_contents($localFilePath, $fileContent);
        
            } catch (\Aws\S3\Exception\S3Exception $e) {
               dd($e->getMessage());
            }
        }
    }

    public function getLocalFile($file_name)
    {
        if ($file_name != '/graphics/logo/user.png') {
            
            return url(Storage::url(EF::getS3Directory().$file_name));
        }
        else
        {
            return url('/graphics/logo/user.png');
        }
    }

    public function uploadLocalFile($file,$flag = true)
    {
        if($flag == true)
        {
            $name = uniqid() . '.' . $file->getClientOriginalExtension();
            \Storage::disk('public')->put('/'.EF::getS3Directory().$name, file_get_contents($file));
        }
        else // RUN TIME CREATE FILE USING CAMERA
        {
            $name = uniqid().".png";
            // file_put_contents("storage/".$name, $file );
            \Storage::disk('public')->put('/'.EF::getS3Directory().$name,$file);
            return $name;
        }
        return $name;
    }

    // public function getInstallmentGapLabels()
    // {
    //     return ['Monthly','Quarterly','Semi Annually','Annually'];
    // }

    // public function getInstallmentGapLabelValue($value)
    // {
    //     $label = '';
    //     if($value == 1){

    //      $label ='Monthly';

    //     }
    //     else if($value == 3){

    //         $label = 'Quarterly';
            
    //     }
    //     else if($value == 6){

    //         $label = 'Semi Annually';
    //     }
    //     else{

    //         $label = 'Annually';

    //     }
    //     return $label;
    // }
 

}
