<html>
<head>

<style>
body{font-family: arial;
    font-size: 15px;}
    .tb_around{border:1px solid #000;}
    .tb_bottom td{border-bottom:1px solid #000;}
    .tb_pad {padding:10px 5px 10px 20px;line-height: 22px;}
    .tb_pad2{padding:10px 5px 10px 5px}
    .tb_pad3{padding:50px 5px 10px 5px}
</style>
</head>
<body>

<!--mpdf
<htmlpageheader name=myheader>

</htmlpageheader>

<htmlpagefooter name=myfooter>Dd Dfdf
<div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; >
E. & O.E. / Page {PAGENO} of {nb}
</div>
</htmlpagefooter>

<sethtmlpageheader name=myheader value=off show-this-page=1 />
<sethtmlpagefooter name=myfooter value=off />
mpdf-->
<?php 
$datas = DB::select("select * from lead_client where id = '".$leadclient->id."'");
//print_r($leadclient);
?>
<table width=100% cellpadding=2 cellspacing=0>

<tr>
    <td>
    <table width=100% cellpadding=2 cellspacing=0 >
        <tr>
            <td  style="text-align:left;width:70%;">            
                <strong>Mail Payment to:</strong>
                <?php if(!empty($company)){?>
                <BR>
                {{ $company->mgmt_name }} <BR>
                {{ $company->mgmt_mailing_add }} <br/>{{ $company->mgmt_mailing_city }} {{ $company->mgmt_mailing_state}} {{ $company->mgmt_mailing_zip}}<BR>
                {{ serformatephone($company->mgmt_phone) }}
            <?php } ?>
            </td>
            <td style="text-align:left;vertical-align:top;">
                
                                <?php 
                                    //echo "ttype "; print_r($leadclient->transaction_type_id); exit;
                                ?>
                            
                Invoice: {{ $leadclient->id }} <Br>
                Invoice Date: {{ showdateformatepdf($leadclient->inv_date) }}
            </td>
        </tr>
    </table>
    </td>
</tr>
<tr>
<br>

<td style="font-size: 22px;font-weight: bold;text-align: center;">
       Invoice<br> <br><br>
    </td>
</tr>
<tr>
    <td style="line-height:22px">
            <table width=100% cellpadding=2 cellspacing=0 >
                <tr>
                    <td  style="font-size:12px;text-align:left;width:55%">
                    
                        <strong>Bill to:</strong> 
                        <?php //if($leadclient->transaction_type_id==2 || $leadclient->transaction_type_id==1){ echo (!empty($leadclient->title)?ucfirst($leadclient->title):''); } ?><BR>
                            
                        <?php if($leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==2 || $leadclient->transaction_type_id==5){ ?>
                        
                        <?php if($leadclient->transaction_type_id==5){ ?>
                                {{ ucfirst($leadclient->title) }}<BR>
                             <?php echo (!empty($leadclient->title_add)?ucfirst($leadclient->title_add):'N/A')?> <BR>
                             {{ ucfirst($leadclient->title_city) }}, {{ $leadclient->title_state }} , {{ $leadclient->title_zip }}<BR>
                          
                            Phone: {{ serformatephone($leadclient->title_phone) }}, <br/> Fax: {{ serformatephone($leadclient->broker_fax) }}
                              
                        <?php  } ?>
                        <?php if($leadclient->transaction_type_id==1){ 
                        
                            //echo "<pre>"; print_r($property); exit;
                        ?>
                              {{ $property->prop_name }}<BR>
                            {{ $vendor_id }}<br>
                            {{ ucfirst($property->prop_add) }}<BR>
                            {{ ucfirst($property->prop_city) }}, {{ $property->prop_state }} {{ $property->prop_zip }}<BR>
                            Phone: {{ serformatephone($property->prop_phone) }}, <br/> Fax: {{ serformatephone($property->prop_fax) }}
                            
                        <?php  } ?>
                        
                        <?php if($leadclient->transaction_type_id==2){ ?>
                            
                             <?php echo (!empty($leadclient->title)?ucfirst($leadclient->title):'N/A')?> <BR>
                            <?php echo (!empty($leadclient->title_add)?ucfirst($leadclient->title_add):'N/A')?> <BR>
                            {{ ucfirst($leadclient->title_city) }}, {{ $leadclient->title_state }} , {{ $leadclient->title_zip }}<BR>
                           
                            
                            Phone : <?php echo (!empty($leadclient->title_phone)?$leadclient->title_phone:'N/A'); ?> <br>
                            Fax : <?php echo (!empty($leadclient->title_fax)?$leadclient->title_fax:'N/A'); ?> <br>
                            
                        <?php  } }else{ ?> 
                            
                            <?php echo (!empty($leadclient->title_add)?ucfirst($leadclient->title_add):'N/A')?> <BR>
                            {{ $leadclient->title_city }}, {{ $leadclient->title_state }} , {{ $leadclient->title_zip }}<BR>
                            
                            
                            Phone : <?php echo (!empty($leadclient->title_phone)?$leadclient->title_phone:'N/A'); ?> <br>
                            Fax : <?php echo (!empty($leadclient->title_fax)?$leadclient->title_fax:'N/A'); ?> <br>
                        
                        <?php  } ?>
                       
                    </td>
                    <td style="font-size:12px;text-align:left;vertical-align:top;">
                         Agent Name: {{ $agentdetail->name }} {{ $agentdetail->last_name }}<br />
                         Client Name: {{ ucfirst($leadclient->fname) }} {{ ucfirst($leadclient->lname) }}<br />
                         <?php if($leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==5){ 
                            
                            ?>
                         
                                Unit #: <?php echo (!empty($leadclient->apt_unit)?$leadclient->apt_unit:$datas[0]->commision_unit); ?><br>
                           <?php 
                           
                           } ?>
                           
                           
                          <?php if($leadclient->transaction_type_id==1){ ?>
                         
                                 Move In Date: <?php echo showdateformatepdf(!empty($leadclient->start_date)?$leadclient->start_date:''); ?><br>
                           <?php 
                           
                           }else{ ?>
                           
                                Move In Date: <?php echo showdateformatepdf(!empty($leadclient->close_date)?$leadclient->close_date:$leadclient->ar_contact_date_next); ?><br>
                           
                           <?php  } ?>
                         
                        <?php if(!empty($leadclient->reg_po)){ ?>
                            Registration #/PO #: {{ $leadclient->reg_po }}
                        <?php  } ?>
                        
                    </td>
                </tr>
           </table>
           <BR>&nbsp;<BR>
    </td>
</tr>
<br><br>

<tr>
    <td>
        <table width=100% cellpadding=2 cellspacing=0 class=tb_around style="font-size:13px">
        <tr>
            <td   style="width:50%;border-right-width:1px;border-right: solid #000 ;border-bottom-width:1px;border-bottom: solid #000 ;line-height:22px;">
            <strong>Description :   <?php echo  (!empty($leadclient->house_add)?$leadclient->house_add:'');  ?> </strong>
            </td>
            
            <td  style="width:50%;line-height:22px;border-bottom-width:1px;border-bottom: solid #000 ;text-align:right;">
            <strong>Amount</strong>
            </td>
         </tr>
        
        <tr>
            <td  style="width:50%;border-right-width:1px;border-right: solid #000 ;line-height:22px;">
                
            Rent Amount: $
            
            <?php 
            $agent_pad =0;
          // echo "<pre>"; print_r($agentdetail->broker_cost); exit;
           $broker_commission = (!empty($agentdetail->broker_cost)?(float)$agentdetail->broker_cost:'');
            if($leadclient->transaction_type_id==5){
                
                echo $leadclient->rent_amount;
       
            
            }else if($leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==0){
                
                    $commission_unit    = $leadclient->commision_unit;
                    $commission         = (float) $leadclient->commision;
                    $bonus              = (float) $leadclient->bonus;
                    $rent_amount        = (float) $leadclient->rent_amount;
                    
                    
                    if ($rent_amount == ''){
                        $rent_amount = 0;
                    }
        
                    if ($bonus == ''){
                        $bonus = 0;
                    }
        
                    if ($commission == ''){
                        $commission = 0;
                    }
                   
                    
                    if ($commission_unit == '%'){

                    if ($commission > 0){
    
                        $commission     = (float) $commission;
                        $tot_com        = (float) $rent_amount * ((float) $commission / 100);
                        $invoiced_total = (float) $tot_com + (float) $bonus;
                    }else{
                            $invoiced_total = (float) $bonus;
                        }
                         
                    }else{
                        $invoiced_total = (float) $commission + (float) $bonus;
                    }
                
                echo $rent_amount;
                
                 
            }else{
                echo $leadclient->sold_amt;
            } 
            
            ?> 
            <br> 
            
            
            
            <?php 
            //echo "<pre>";print_r($leadclient); exit;
            $invoice_cost =0;
            if($leadclient->transaction_type_id==0 || $leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==2 || $leadclient->transaction_type_id==3 || $leadclient->transaction_type_id==5 || $leadclient->transaction_type_id==6){
                 
                 
                if($leadclient->transaction_type_id==2 || $leadclient->transaction_type_id==3 ||$leadclient->transaction_type_id==6){
                    $tot_trans_amt = (float) $leadclient->sold_amt;
                }else{
                    $tot_trans_amt = (float) $leadclient->rent_amount;
                }
                
                
                
                if($tot_trans_amt < 100000){
                    
                   $invoice_cost = $agentdetail->commercial_tier1;
                    
                }else if($tot_trans_amt >= 100000 && $tot_trans_amt < 1000000){
                    
                   $invoice_cost = $agentdetail->commercial_tier2;
                    
                }else{
                    
                    $invoice_cost = $agentdetail->commercial_tier3;
                    
                }
                
                 if($leadclient->transaction_type_id==1){
                   $commision = $leadclient->commision;
                 }else{
                     $commision=$leadclient->house_comm;
                 }
                //echo $leadclient->sold_amt; exit;
                
                
                
                   //echo "agent paid ".$commission_unit; exit;
                if($leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==0){
                     if($commission_unit == '%')
                    {
                        $received_amount = ($tot_trans_amt*$commision/100);
                        $tier=$invoice_cost;
                        if(!empty($broker_commission)){
                            $broker_cost =(($tot_trans_amt*$commision/100)-$invoice_cost)*$broker_commission/100;
                        }else{
                            $broker_cost =00;
                        }
                        
                        
                        $agent_pad = $received_amount;
                    } else{
                        //echo "agent paid ".$commision; exit;
                       //$commision=   (explode('$',$commision)[1]);
                      // $commision=1;
                       //echo"<pre>";print_r($commision); exit;
                        $agent_pad = $commision;  
                    }
                     
                }else{
                    
                        $received_amount = ($tot_trans_amt*$commision/100);
                       
                        $tier=$invoice_cost;
                        
                          if(!empty($broker_commission)){
                                $broker_cost =(($tot_trans_amt*$commision/100)-$invoice_cost)*$broker_commission/100;
                          }else{
                             $broker_cost =0;
                          }
                        $agent_pad = $received_amount;
                        
                }
                
            //     $received_amount = ($tot_trans_amt*$commision/100);
            //     $tier=$invoice_cost;
            //     $broker_cost =(($tot_trans_amt*$commision/100)-$invoice_cost)*10/100;
                
                
            // //echo "Received amount ".($received_amount)." tier ".$tier. " broker_cost ".$broker_cost;exit;
            //     $agent_pad = $received_amount-$tier-$broker_cost;
                
            //$invoice_amount = ($leadclient->rent_amount*$leadclient->house_comm/100);
            
            
            //echo $broker_cost =   $invoice_cost-$invoice_amount*10/100;  
            ?>
                Commission: <?php 
                
            //print_r($leadclient); exit;
                if($leadclient->transaction_type_id==1){
                    // if($leadclient->$commission_unit==0){
                        
                    // }
                    echo $leadclient->commision." ".$leadclient->commision_unit."";
                }else if($leadclient->transaction_type_id==5 || $leadclient->transaction_type_id==6){
                    
                    echo (float) $leadclient->house_comm." %";
                    
                }else if($leadclient->transaction_type_id==2 || $leadclient->transaction_type_id==3){ 
                    echo (!empty($leadclient->house_comm))? (float) $leadclient->house_comm.'%':'';  
                } else{
                    echo (!empty($leadclient->house_comm))? (float) $leadclient->house_comm:(int) $commission."%";  
                }
               
                
                ?> <br>
           <?php   
            } ?>
            Bonus:<br> 
            </td>
            <td  style="width:50%;vertical-align: top;line-height:22px;text-align:right;">                
               <br>
               
                <?php 
               if($leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==5 || $leadclient->transaction_type_id==6)
                 {
                  //echo " $ ";  
                 }
                
                 if($leadclient->transaction_type_id==5 || $leadclient->transaction_type_id==6){
                        echo $agent_pad;
                    }else if($leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==0){
                        echo $agent_pad;
                        
                        }else{
                            echo $agent_pad;
                        //echo ($leadclient->sold_amt*$leadclient->house_comm/100)-$invoice_cost;
                    }
    
                ?>
                
                <BR>
                <?php
                if($leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==5 || $leadclient->transaction_type_id==6)
                 {
                  echo " $ ";  
                 }
                      $total_bonus =0;
                    if($leadclient->transaction_type_id==1){
                        echo  ''.$bonus;
                        $total_bonus=$bonus;
                    }else{
                        echo ''.(!empty($leadclient->house_bonus)?' '.$leadclient->house_bonus:' 0');
                        $total_bonus=(!empty($leadclient->house_bonus)?$leadclient->house_bonus:'0');
                    }    
                ?>
            </td>
        </tr>
        <tr>
            <td  style="width:50%;border-top-width:1px;border-top: solid #000 ;border-right-width:1px;border-right: solid #000 ;line-height:22px;text-align:right;">
              <strong>Total:&nbsp;&nbsp;</strong>
            </td>
            <td  style="width:50%;border-top-width:1px;border-top: solid #000 ;vertical-align: top;line-height:22px;text-align:right;">  
               <strong>
               <?php 
          if($leadclient->transaction_type_id==1 || $leadclient->transaction_type_id==5 || $leadclient->transaction_type_id==6)
                 {
                  //echo " $ ";  
                 }
           
               if($leadclient->transaction_type_id==5 || $leadclient->transaction_type_id==6){
                  echo  $agent_pad+$total_bonus;
                   
               }else if($leadclient->transaction_type_id==1){
                  
                   if(!empty($total_bonus)){
                    // echo "agent_pad";
                    // print_r("$".number_format(preg_replace('/[\$,]/','',$agent_pad) + $total_bonus,2)); die;
                    echo "$".number_format(preg_replace('/[\$,]/','',$agent_pad) + $total_bonus,2);
                      // echo $agent_pad+$total_bonus;  
                   }else{
                        echo $agent_pad;
                   }
                  
               } else{
                   echo $agent_pad+$total_bonus;
                   //echo (($leadclient->sold_amt*$leadclient->house_comm/100)+$leadclient->house_bonus)-$invoice_cost;
               }
               
               
                    
                ?>
               </strong>
            </td>
        </tr>
        </table>
    </td>
</tr>
<tr>

    <td style="font-size:12px">
    <br />  
    <?php if(!empty($company)){?>  
    {{ $property->prop_manager }}<br /><br />
    Please remit payment within 30 days to {{ $company->mgmt_mailing_add }}  {{ $company->mgmt_mailing_city }} {{ $company->mgmt_mailing_state}} {{ $company->mgmt_mailing_zip}}<br /><br />

Thank you for your diligence,<br>
{{ $clientdetail->name }} {{ $clientdetail->last_name }}<br>    
{{ serformatephone($clientdetail->phone) }}
<?php } ?>
    </td>
</tr>


</table>





</body>
</html>