<?php

namespace App\Utility;


use Cake\ORM\TableRegistry;

class Common {



    public static function daysBetweenDate($from_date, $to_date)
    {

        $str_to_time_from = strtotime($from_date);
        $str_to_time_to = strtotime($to_date);

        $difference = 0;

        if ($str_to_time_from > $str_to_time_to) {
            $difference = date_diff(
                date_create($to_date),
                date_create($from_date)
            )->format('%a');
            $difference = (-1) * $difference;
        } else if ($str_to_time_from < $str_to_time_to) {
            $difference = date_diff(
                date_create($to_date),
                date_create($from_date)
            )->format('%a');
        }

        return $difference;
    }
    
    public static function generateRandomString($length = 5,$id = null){
        
        $str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
        $randomString = substr(str_shuffle($str_result), 0, $length);
        
        if($id > 0){
            $randomString =  substr($randomString, 0, -strlen($id)) . $id;
        }

        return $randomString;
    }


    public function tz_list() {
        $zones_array = array();
        $zones_array[] = ['key' => 'America/Belize', 'label' => "GMT -6:00 (Mountain Daylight Time)"];
        $zones_array[] = ['key' => 'Pacific/Honolulu', 'label' => "GMT -10:00 (Hawaii Standard Time)"];
        $zones_array[] = ['key' => 'America/Anchorage', 'label' => "GMT -8:00 (Alaska Daylight Time)"];
        $zones_array[] = ['key' => 'America/Los_Angeles', 'label' => "GMT -7:00 (Pacific Daylight Time)"];
        $zones_array[] = ['key' => 'America/Phoenix', 'label' => "GMT -7:00 (Mountain Standard Time)"];
        $zones_array[] = ['key' => 'America/Chicago', 'label' => "GMT -5:00 (Central Daylight Time)"];
        $zones_array[] = ['key' => 'America/New_York', 'label' => "GMT -4:00 (Eastern Daylight Time)"];
        $zones_array[] = ['key' => 'Europe/London', 'label' => "GMT +0:00 (Europe/London Time)"];
        return $zones_array;
    }

     public function tz_key_value_list() {
         $time_zone = $this->tz_list();
         $result = [];
         foreach ($time_zone as $t){
             $result[$t['key']] = $t['label'];
         }
         
         return $result;
     }
    public function organizeBulkActionIds($selectedCompanies) {
        $idList = [];
        if(!empty($selectedCompanies)){
            $invoicesToDelete = explode(',', $selectedCompanies);
            if(!empty($invoicesToDelete)){
                foreach ($invoicesToDelete as $value){
                    $value = str_replace("content_", "", $value);
                    $idList[] = $value;
                }
            }
        }

        return $idList;
    }

    public function getColorByDate($date,$is_disable){
        $color = "";
        if($is_disable == 1){
            $color = 'blue';
        }else{
            if(!empty($date) && $is_disable == 0) {
                $modified_on = strtotime(date('Y-m-d'));
                $next_section_date = strtotime(date_format($date,"Y-m-d"));
                $dateDiff = $next_section_date - $modified_on;
                $dateDiff = round($dateDiff / (60 * 60 * 24));
                if (($dateDiff <= NEXT_SELECTION_NEAREST_DAY && $dateDiff > 0) || $dateDiff == 0) {
                    $color = 'yellow'; 
                } else if ($is_disable == 0) {
                    if ($modified_on > $next_section_date) {
                         $color = 'red';
                    } else if ($modified_on < $next_section_date) {
                        $color = 'green';

                    }

                }
            }
        }

       
            

        return $color;
    }

    public function getOrganizeCreditReportSummary($data){
        $item = [];
        $publicrecords = [];
        $accountType[1] = "Being Challenged";
        $accountType[2] = "Positive Account";
        $accountType[3] = "N/A";
        $accountType[4] = "Updated/Removed";
        $accountType[5] = "Late Pays / 2 Or Less";
        $accountType[6] = "Repaired Accounts/Now Positive";
         if(!empty($data)){
             foreach ($data as $dd){
                 
                 if(!empty($dd->data_basic_key_values)){
                    foreach($dd->data_basic_key_values as $dik){
                       // pr($dik);exit;
                        
                        $accType = "";
                        
                        $item[] = [
                            'table_type'=>'PI',
                            'item_id'=>$dik->id,
                            'exp_type'=>$dik->status1,
                            'equif_type'=>$dik->status2,
                            'trans_type'=>$dik->status3,
                            //'name'=>$this->processDatakeyString($dik->data_key).$account_no,
                            'name'=>$dik->data_key,
                            'exp'=>$accountType[$dik->status1],
                            'equif'=>$accountType[$dik->status2],
                            'trans'=>$accountType[$dik->status3],
                            'item_type'=>$accType,
                            'dropdown'=>$this->createDropDownForItem("",$accType,$dik->id,'PI',NEGATIVE_DROPDOWN_INFO)
                        ];
                       
                    }


                 }
                 
                 
                 if(!empty($dd->data_item_key_values)){
                    foreach($dd->data_item_key_values as $dik){
                       // pr($dik);exit;
                        $account_no =  $dik->value1;
                        $accType = $dik->value4;
                        if($dik->isJson == 1){
                             $dik->value1 = json_decode($dik->value1,true);
                             if(isset($dik->value1['accType']) && !empty($dik->value1['accType'])){
                                 $accType = $dik->value1['accType'];
                             }
                             $account_no = "";
                             if(isset($dik->value1['account']) && !empty($dik->value1['account'])){
                                 $account_no = $dik->value1['account'];
                             }
                             
                             
                        }
                        
                        if(!empty($account_no)){
                                 $account_no = " - ".$account_no;
                             }
                        $item[] = [
                            'table_type'=>'ACC',
                            'item_id'=>$dik->id,
                            'exp_type'=>$dik->type2,
                            'equif_type'=>$dik->type3,
                            'trans_type'=>$dik->type,
                            //'name'=>$this->processDatakeyString($dik->data_key).$account_no,
                            'name'=>$dik->data_key.$account_no,
                            'exp'=>$accountType[$dik->type2],
                            'equif'=>$accountType[$dik->type3],
                            'trans'=>$accountType[$dik->type],
                            'item_type'=>$accType,
                            'dropdown'=>$this->createDropDownForItem("",$accType,$dik->id,'ACC',NEGATIVE_DROPDOWN_INFO)
                        ];
                       
                    }


                 }
                 
                if(!empty($dd->data_public_records)){
                    $first_occurence = true;
                    $pb_first_row_id = 0;
                     foreach ($dd->data_public_records as $pb){
                         $pk_key_name = $this->processDatakeyString($pb->data_key);
                         if(!empty($pk_key_name) && $first_occurence){
                                $pb_first_row_id = $pb->id;
                                $pb_account_type_value = "";
                                $type_values[] = $pb->value1;
                                $type_values[] = $pb->value2;
                                $type_values[] = $pb->value3;
                                $type_values = array_unique($type_values);
                                
                                if(!empty($type_values[0])){
                                    $pb_account_type_value = str_replace($pb->title_name, "", $type_values[0]);
                                }
                                $item['publicrecord'][] = [
                                                            'table_type'=>'PB',
                                                            'item_id'=>$pb->id,
                                                            'exp_type'=>$pb->status1,
                                                            'equif_type'=>$pb->status2,
                                                            'trans_type'=>$pb->status3,
                                                            'name'=> $pb->title_name,
                                                            'exp'=>$accountType[$pb->status1],
                                                            'equif'=>$accountType[$pb->status2],
                                                            'trans'=>$accountType[$pb->status3],
                                                            'item_type'=>"Public Record"//$pb->title_name." ".$pb_account_type_value
                                                           ];
                                $first_occurence = false;
                         }
                         
                         if(strtolower($pk_key_name) == strtolower("Reference#")){
                             $temp_array = [$pb->value1,$pb->value2,$pb->value3];
                             $temp_array = array_unique($temp_array);
                             $new_name = "";
                             
                             if(!empty($temp_array)){
                                 $item['publicrecord'][0]['name'] .= " - ".$temp_array[0]."<br/>";
                                 unset($temp_array[0]);
                                 foreach ($temp_array as $arr){
                                     if(!empty($arr)){
                                        if(!empty($new_name)){
                                            $new_name .= " , ".$arr;
                                        }else{
                                             $new_name = $arr;
                                        }
                                     }
                                 }
                             }
                             $item['publicrecord'][0]['name'] .= $new_name;
                             $item['publicrecord'][0]['dropdown'] = $this->createDropDownForItem($pb->title_name,$pb_account_type_value,$pb_first_row_id,'PB',PUBLIC_RECORD_DROPDOWN_INFO);
                         }
                         
                     }
                }

                if(!empty($dd->data_inquiries)){
                     foreach ($dd->data_inquiries as $inq){
                         $temp_inq['table_type'] = 'INQ';
                         $temp_inq['item_id'] = $inq->id;
                         $temp_inq['name'] = explode("_", $inq->data_key)[0];
                         $temp_inq['name'] = $this->processDatakeyString($temp_inq['name']);

                         if($inq->item_category_id == APP_TRANSUNION){
                             $temp_inq['trans'] = $accountType[$inq->type];
                             $temp_inq['trans_type'] = $inq->type;
                             $temp_inq['exp'] = "N/A";
                             $temp_inq['exp_type'] = 3;
                             $temp_inq['equif'] = "N/A";
                             $temp_inq['equif_type'] = 3;
                         }

                         if($inq->item_category_id == APP_EXPERIAN){
                             $temp_inq['exp'] = $accountType[$inq->type];
                            $temp_inq['exp_type'] = $inq->type;
                             $temp_inq['trans'] = "N/A";
                             $temp_inq['trans_type'] = 3;
                             $temp_inq['equif'] = "N/A";
                             $temp_inq['equif_type'] = 3;
                         }

                         if($inq->item_category_id == APP_EQUIFAX){
                             $temp_inq['equif'] = $accountType[$inq->type];
                             $temp_inq['equif_type'] = $inq->type;
                             $temp_inq['trans'] = "N/A";
                             $temp_inq['trans_type'] = 3;
                             $temp_inq['exp'] = "N/A";
                             $temp_inq['exp_type'] = 3;
                         }
                         
                         $temp_inq['item_type'] = "Inquiry";
                         
                         if(empty($temp_inq['exp'])){
                             $temp_inq['exp'] = "N/A";
                             $temp_inq['exp_type'] = 3;
                         }
                         
                         if(empty($temp_inq['equif'])){
                             $temp_inq['equif'] = "N/A";
                             $temp_inq['equif_type'] = 3;
                         }
                         
                         if(empty($temp_inq['trans'])){
                             $temp_inq['trans'] = "N/A";
                             $temp_inq['trans_type'] = 3;
                         }
                         
                         $item[] = $temp_inq;

                     }
                }


             }
         }
        
         return $item;
    }

    private function hasValue($constant,$selected_value){
        $result = false;
        foreach ($constant as $key => $info){
            $selected_value = trim($selected_value);
            $info = trim($info);
            if($selected_value == $info){
               $result = true;
               break;
            }
        }
        
        return $result;
    }
    private function createDropDownForItem($title,$selected_value,$item_id,$type,$constant){
        $params = $item_id.",'".$title."','".$type."',this";
        $html = '<select onchange="accountTypeChangeById('.$params.')" class="item-dropdown" name="pb_dropdown">';
        $hasValue = $this->hasValue($constant,$selected_value);
        
        if(!$hasValue){
            $html .= '<option value="">Please select</option>';
        }
        $constant[$selected_value] = $selected_value;
        $constant = array_unique($constant);
        foreach ($constant as $key => $info){
            $selected = "";
            $selected_value = trim($selected_value);
            $info = trim($info);
            if($selected_value == $info){
                $selected = "selected";
            }
            $temp_title = $title;
            $html .= '<option value="'.$key.'" '.$selected.'>'.$temp_title." ".$info.'</option>';
        }
        $html .= '</select>';
        
        return $html;
    }

    public function processDatakeyString($string){
        $split_point = '-';
       // $string = 'one - two and three - four and five x-1.651';

        $stringpos = strrpos($string, $split_point, -1);
        $finalstr2 = substr($string,$stringpos+1,strlen($string));

        if(is_numeric($finalstr2)) {
            $finalstr = substr($string,0,$stringpos);
        } else {
            $finalstr = $string;
        }

        return $finalstr;
    }
    
    public function customPagination($page, $page_limit,$yourDataArray){
        //$page = $page_limit;
        //pr($yourDataArray);exit;
        
        
        $total = count($yourDataArray ); //total items in array
        $limit = $page_limit; //per page
        $totalPages = ceil( $total/ $limit ); //calculate total pages
        $page = max($page, 1); //get 1 page when $_GET['page'] <= 0
        $page = min($page, $totalPages); //get last page when $_GET['page'] > $totalPages
        $offset = ($page - 1) * $limit;
        if( $offset < 0 ){
            $offset = 0;
        }
        $from = $offset + 1;
        if($totalPages == 0){
            $from = 0;
        }
        $to = $page * $limit;
        $paginate['from'] = $from;
        $paginate['offset'] = $offset;
        $paginate['to'] = $to > $total ? $total:$to;
        $paginate['total'] = $totalPages;
        $paginate['page'] = $page;
        $paginate['entries'] = $total;
        $paginate['limit'] = $limit;
        
       // pr($paginate);exit;
        return $paginate;
    }
    

    public function htmlFilewrite($content, $file_path,$file_name = ""){
        $result  = "";
        if(!is_dir($file_path)){
            mkdir($file_path,0777,true);
        }
        
        $file_name = $file_path."/".$file_name;
        if(!is_file($file_name)){
            $file_name = $file_path."/".time().uniqid().".html";
        }
       // echo $file_name;exit;
       if(!empty($file_name) && !empty($content)){
           if(file_put_contents($file_name, utf8_encode($content))){
                $result  = basename($file_name);
            }
       }
       
       return $result;
    }
    
    
    public function itemDropdownHTML(){
        return '<select class="item-dropdown">
                                            <option value="3">Please select</option>
                                            <option value="1">negative</option>
                                            <option value="">positive</option>
                                        </select>';
    }
    
    
    public function twoDatesMonthDayYear($sdate,$edate){
        $result['year'] = 0;
        $result['month'] = 0;
        $result['day'] = 0;
        $result['hour'] = 0;
        $result['min'] = 0;
        $result['sec'] = 0;
        $date1 = strtotime($sdate);  
        $date2 = strtotime($edate);  

        // Formulate the Difference between two dates 
        $diff = abs($date2 - $date1);  


        // To get the year divide the resultant date into 
        // total seconds in a year (365*60*60*24) 
        $years = floor($diff / (365*60*60*24));  
        
        if($years > 0){
            if($years == 1){
                return $years." year";
            }else{
                 return $years." years";
            }
        }

        // To get the month, subtract it with years and 
        // divide the resultant date into 
        // total seconds in a month (30*60*60*24) 
        $months = floor(($diff - $years * 365*60*60*24) 
                                       / (30*60*60*24));  
        if($months > 0){
            if($months == 1){
                return $months." month";
            }else{
                 return $months." months";
            }
        }

        // To get the day, subtract it with years and  
        // months and divide the resultant date into 
        // total seconds in a days (60*60*24) 
        $days = floor(($diff - $years * 365*60*60*24 -  
                     $months*30*60*60*24)/ (60*60*24)); 

        if($days > 0){
            if($days == 1){
                return $days." day";
            }else{
                 return $days." days";
            }
        }
        // To get the hour, subtract it with years,  
        // months & seconds and divide the resultant 
        // date into total seconds in a hours (60*60) 
        $hours = floor(($diff - $years * 365*60*60*24  
               - $months*30*60*60*24 - $days*60*60*24) 
                                           / (60*60));  

        if($hours > 0){
            if($hours == 1){
                return $hours." hour";
            }else{
                 return $hours." hours";
            }
        }
        // To get the minutes, subtract it with years, 
        // months, seconds and hours and divide the  
        // resultant date into total seconds i.e. 60 
        $minutes = floor(($diff - $years * 365*60*60*24  
                 - $months*30*60*60*24 - $days*60*60*24  
                                  - $hours*60*60)/ 60);  

        if($minutes > 0){
            if($minutes == 1){
                return $minutes." minute";
            }else{
                 return $minutes." minutes";
            }
        }
        // To get the minutes, subtract it with years, 
        // months, seconds, hours and minutes  
        $seconds = floor(($diff - $years * 365*60*60*24  
                 - $months*30*60*60*24 - $days*60*60*24 
                        - $hours*60*60 - $minutes*60)); 
        
        if($seconds > 0){
            if($seconds == 1){
                return $seconds." second";
            }else{
                 return $seconds." seconds";
            }
        }
        
        
        return $result;
    }
    
    public function dateCheckInRange($start_date, $end_date, $date_from_user) {
        // Convert to timestamp
        $start_ts = strtotime($start_date);
        $end_ts = strtotime($end_date);
        $user_ts = strtotime($date_from_user);

        // Check that user date is between start & end
        return (($user_ts >= $start_ts) && ($user_ts <= $end_ts));
    }
    
    
    public function makeRecurringDateRange($subData) {
        $interval_type = $subData['radInterval'];
        $start_date = $subData['txtStartDate'];
        $hasnoEndDate = false;
        $end_type = "";
        $end_value = $start_date;
        if($interval_type == "MM"){
            $interval_value = $subData['ddlInterval'];
        }else if($interval_type == "DD") {
            $interval_value = $subData['txtIntervalDay'];
        }
        
        if($subData['radDurationEnd'] == "NoEndDate"){
            $hasnoEndDate = true;
        }else{
          $end_type = $subData['radDurationEnd'];
          if($end_type == "EndDate"){
              $end_value = $subData['txtEndDate'];
              $end_value = date('Y-m-d H:i:s',strtotime($end_value));
          }else if($end_type == "EndDuration"){
              $end_value = $subData['txtNumRecur'];
          }
        }

        
        $end_date = $end_value;
        if (!$hasnoEndDate) {
            if ($end_type == "EndDuration") {  // EndDuration for day interval
                if ($interval_type == "MM") { // MM for Month
                    $months = ($interval_value * $end_value);
                    $end_date = date('Y-m-d H:i:s', strtotime("+" . $months . " months", strtotime($start_date)));
                } else if ($interval_type == "DD") { // DD for days
                    $days = ($interval_value * $end_value);
                    $end_date = date('Y-m-d H:i:s', strtotime($start_date . ' + ' . $days . ' days'));
                }
            }
        } 
       
        return $end_date;
    }
    
    public function invoicePDFforClient($cmsuserInfo, $invoiceInfo, $invoice_item, $isEmail = false) {
        $path = WWW_ROOT.CMSUSER_LOGO . $cmsuserInfo['cmsuser_logo'];

        $from_string = "";
        $to_string = "";
        
        if($isEmail){
            $from_string = "<p>From</p>";
            $to_string = "<p>To</p>";
        }
        
        $html = '
<!doctype html>
<html>
<head>
<style>
body{
	font-family:"open-sans", Helvetica, Arial, Verdana, sans-serif;
}
.receiver-info-section{
    line-height: normal;
}
.receiver-info-section p{
    margin:2px;
}
.invoice-date-section{
    line-height: normal;
}
.invoice-date-section h3,
.invoice-date-section p{
    margin:2px;
}
.payment_details h6{
	font-size:10px;
	color:#555;
	font-family:"open-sans", Helvetica, Arial, Verdana, sans-serif;
	margin-bottom:0px;
}
.payment_details h4{
	font-size:13px;
	color:#555;
	font-family:"open-sans", Helvetica, Arial, Verdana, sans-serif;
	margin-top:0px;
}
#item-table thead th,
#item-table tbody td{
	padding:10px auto;
}

#item-table tbody tr td{
	border-top:2px solid #eee;
	
}
#item-table tbody tr td:last-child {
	border-bottom:2px solid #eee;
	
}
.payment_details table tr td h6,
.payment_details table tr td h4{
    font-family:"open-sans", Helvetica, Arial, Verdana, sans-serif;
}
footer{
	width:100%;
	padding:10px auto;
	border-top:2px solid #eee;
	text-align:center;
}
.footer-text{
	font-size:10px;
	color:#777;
	font-family:"open-sans", Helvetica, Arial, Verdana, sans-serif;
}
</style>
</head>
<body>
<div style="width:100%;text-align:right;">
        <img src="' . $path . '" style="width:200px;height:100px;float:left;"/>
	' . $invoiceInfo['status'] . '
</div>
<div class="receiver-info-section" style="width:100%;margin:10px auto;">
	<div  style="width:50%;float:left;text-align:left;">
		'.$from_string.'
		<p>' . $cmsuserInfo['cmsuser_company_name'] . '</p>
		<p>' . $cmsuserInfo['cmsuser_contact_name'] . '</p>
		<p>' . $cmsuserInfo['cmsuser_address_one'] . $cmsuserInfo['comma_one'] . $cmsuserInfo['cmsuser_address_two'] . '</p>
		<p>' . $cmsuserInfo['cmsuser_city'] . $cmsuserInfo['comma_two'] . $cmsuserInfo['cmsuser_state'] . $cmsuserInfo['comma_three'] . $cmsuserInfo['cmsuser_zip_address'] . '</p>
	</div>
	<div  style="width:50%;float:right;text-align:right;">
                '.$to_string.'
		' . $invoiceInfo['client_name'] . '
		' . $invoiceInfo['address'] . '
		' . $invoiceInfo['state'] . '
		' . $invoiceInfo['zipcode'] . '
	</div>
</div>
<div class="invoice-date-section" style="width:100%;margin:10px auto;border-bottom: 3px solid #28a9f1;">
	<div  style="width:50%;float:left;text-align:left;">
		<h3>Invoice ' . $invoiceInfo['invoice_id'] . '</h3>
		<p>' . $invoiceInfo['issue_date'] . '</p>
	</div>
	<div  style="width:50%;float:right;text-align:right;">
		<p>Due date</p>
		<p>' . $invoiceInfo['due_date'] . '</p>
	</div>
</div>
<div style="margin:10px auto;width:100%;">
	<table id="item-table" width="100%">
		<thead>
			<tr>
				<th width="45%" style="text-align:left;">Payment ID</th>
				<th width="45%" style="text-align:left;">Description</th>
				<th width="15%" style="text-align:center;">QTY</th>
				<th width="20%" style="text-align:right;">UNIT PRICE</th>
				<th width="20%" style="text-align:right;">AMOUNT</th>
			</tr>
			
		</thead>
                <tbody>' . $invoice_item . '</tbody>
		
		
	</table>
	
</div>
<hr>
<div class="payment_details" style="margin:10px auto;width:100%;">
    <table width="100%">
        <tr>
           
            ' . $invoiceInfo['payment_received'] . '
            ' . $invoiceInfo['total'] . '
        </tr>
    </table>
</div>
<div style="clear:both;"></div>
<footer style="position:absolute;bottom:0;left:0;">
	<h6 class="footer-text">' . $cmsuserInfo['cmsuser_company_name'] . ' | ' . $cmsuserInfo['cmsuser_email'] . ' | ' . $cmsuserInfo['cmsuser_phone'] . '</h6>
</footer>
</body>
</html>';
          
        return ['html' => $html, 'path' => $file_name];
}

    public function getCurrentUserInfo(){
        $userTypeString = "";
        if($_SESSION['userType']== CRM_USER_INDICATOR && $_SESSION['Auth']['User']['type'] == 1){
            $userTypeString = "EMPLOYEE";
        }else if($_SESSION['userType']== CMS_USER_INDICATOR){
            $userTypeString = "MEMBER";
        }else if($_SESSION['userType'] == STAF_USER_INDICATOR){
            $userTypeString = "STAFF";
        }else if($_SESSION['userType']== CRM_USER_INDICATOR && $_SESSION['Auth']['User']['type'] == 2){
            $userTypeString = "AFFILIATE";
        }else if($_SESSION['userType']== CMS_USER_INDICATOR && ($_SESSION['Auth']['User']['id'] == 1 || $_SESSION['Auth']['User']['id'] == 1477)){
            $userTypeString = "ADMIN";
        }else if($_SESSION['userType']== CONTACT_USER_INDICATOR){
            $userTypeString = "CLIENT";
        }
        
        return $userTypeString;
    }


    public function replaceHtmlBody($html_body,$client_info,$company_info)
    {
        $final_html=$html_body;
        $final_html=$this->replaceClientInfo($final_html,$client_info);
        $final_html=$this->replaceCompanyInfo($final_html,$company_info);
        return $final_html;
    }
    private function replaceClientInfo($html_body,$client_info)
    {
        $final_html = $html_body;
        $ssn = "";
        $birthDay = "";
        if($client_info['client_id'] > 0){
           $creditreportsetupsTable = TableRegistry::get('Creditreportsetups');
           $creditreportDataObj = $creditreportsetupsTable->getCreditReportByClientId($client_info['client_id']);
            if(!empty($creditreportDataObj)){
                $ssn = $creditreportDataObj->social_secuirty_no;
                $birthDay = $creditreportDataObj->birth_date;
            }
        }

        $final_html = str_replace(AGREEMENT_PRIFIX, "", $final_html);

        $final_html = str_replace(AGREEMENT_FIRSTNAME, $client_info['first_name'], $final_html);
        $final_html = str_replace(AGREEMENT_CUSTOMERNAME, $client_info['first_name'].' '.$client_info['last_name'], $final_html);
        $final_html = str_replace(AGREEMENT_LASTNAME, $client_info['last_name'], $final_html);

        $final_html = str_replace(AGREEMENT_SUFFIX, "", $final_html);

        $final_html = str_replace(AGREEMENT_SSN, $ssn, $final_html);
        $final_html = str_replace(AGREEMENT_BIRTHDAY, $birthDay, $final_html);

        $final_html = str_replace(AGREEMENT_ADDRESS, $client_info['address'], $final_html);
        $final_html = str_replace(AGREEMENT_CITY_STATE_POSTCODE, $client_info['city'].', '.$client_info['street_name'].', '.$client_info['zip_code'], $final_html);
        $final_html = str_replace(AGREEMENT_PRICE_FOR_SERVICE, "", $final_html);

        return $final_html;
    }
    private function replaceCompanyInfo($html_body,$company_info)
    {
        $final_html=$html_body;
        $final_html = str_replace(AGREEMENT_COMPANYNAME, $company_info['company_name'], $final_html);
        $final_html = str_replace(AGREEMENT_COMPANYADDRESS, $company_info['address_one'].$company_info['address_two'], $final_html);
        $final_html = str_replace(AGREEMENT_COMPANY_CITY_STATE_ZIP, $company_info['city'].', '.$company_info['state'].', '.$company_info['address_zip'], $final_html);
        $final_html = str_replace(AGREEMENT_COMPANYPHONE, $company_info['phone'], $final_html);
        $final_html = str_replace(AGREEMENT_COMPANYFAX, "", $final_html);
        $final_html = str_replace(AGREEMENT_COMPANYWEBSITE, $company_info['website'], $final_html);
        $final_html = str_replace(AGREEMENT_ADMINEMAIL, $company_info['email'], $final_html);
        return $final_html;
    }

    public static function getStringToDateTime($stringDate,$format = 'Y-m-d H:i:s')
    {
        $date = strtotime($stringDate);
        return date($format, $date);
    }
    public static function accountNumberMasking($number, $maskingCharacter = '*')
    {
        return substr($number, 0, -4).str_repeat($maskingCharacter,4) ;
    }
    public static function amountFormatter($number,$currency='$')
    {
        return $currency.rtrim(rtrim(number_format($number, 2, '.', ','),'0'),'.');
    }
}
