<!DOCTYPE html>
<html>

<head>
    <title>Lead List</title>
</head>

<body>
    <div class="heading">
        <div class="logo col-6">
            <img src="~images/pdf/logo.png">
        </div>
        <div class="companay_name col-6 text-right">
           <?php
                
                $model_Company = MasCompany::model()->find();
                
                ?>
                
                <h3><?php echo $model_Company->company_name; ?></h3>
                <p><?php echo $model_Company->company_address; ?>
                <?php echo ', '.$model_Company->company_location; ?>
                <?php echo ', '.$model_Company->country->country_name; ?></p>
                <p><?php echo 'Phone : '. $model_Company->company_phone_no; ?></p>
                <p><?php echo 'Email : '.$model_Company->company_email_id; ?></p>
        </div>
    </div>
    <div class="clearfix"></div>
    <div class="title">
        <div class="col-6">
          <div style="height: 10px;"></div>
      </div>
      <div class="col-6 text-right">
        <h1>LEAD LIST</h1>
        <div class="details-box">
        </div>
    </div>
</div>
<div class="clearfix"></div>
<div class="table-body">
    <table id="tbl_enquiry_table" class="table table-fixed table-primary dataTable">
       <thead>
           <tr>
               <tr>
   		<th>No</th>
                <th>Enquiry</th>
                <th>Customer Name</th> 
                <th>Enquiry Date</th>
                <th>Closing Date</th>
                <th>Lead Reason</th>   		  		
                <th>Sales Group</th>
                <th>Source Type</th>
                <th>Currency</th>
                <th>Amount</th>
                <th>Probability</th>
                <th>Contact Name</th>
                <th>Mobile</th>
                <th>Email</th>                
                <th>Actions</th>
                </tr>

           </tr>
       </thead>
       <tbody>
         <?php 
        $condition = '1=1'; ;
            if($enq_from_date != ''){   
                $enq_from_date = str_replace('/', '-', $enq_from_date);
                $enq_from_date = date('Y-m-d',strtotime($enq_from_date));
                $condition .= ' AND t.enq_date >="'.$enq_from_date.'"';
            }
            if($enq_to_date != ''){   
                $enq_to_date = str_replace('/', '-', $enq_to_date);
                $enq_to_date = date('Y-m-d',strtotime($enq_to_date));
                $condition .= ' AND t.enq_date <="'.$enq_to_date.'"';
            }
            if($closing_from_date != ''){    
                $closing_from_date = str_replace('/', '-', $closing_from_date);
                $closing_from_date = date('Y-m-d',strtotime($closing_from_date));
                $condition .= ' AND t.closing_date >="' . $closing_from_date.'"';
            }
             if($closing_to_date != ''){    
                $closing_to_date = str_replace('/', '-', $closing_to_date);
                $closing_to_date = date('Y-m-d',strtotime($closing_to_date));
                $condition .= ' AND t.closing_date <="' . $closing_to_date.'"';
            }
            if($customer_id != ''){
                $condition .= ' AND t.customer_id ="' . $customer_id.'"';
            }
            if($sales_group_id != ''){
                $condition .= ' AND t.sales_group_id ="' . $sales_group_id.'"';
            }
            if($source_type_id != ''){
                $condition .= ' AND t.source_type_id ="' . $source_type_id.'"';
            }
            if($probability_id != ''){
                $condition .= ' AND t.probability_id ="' . $probability_id.'"';
            }
            if($leadowner_id != ''){
                $condition .= ' AND t.leadowner_id ="' . $leadowner_id.'"';
            }
             if($status != ''){
                $condition .= ' AND t.status ="' . $status.'"';
            }
            $model_lead = Lead::model()->findAll(array('condition'=>$condition));
        foreach ($model_lead as $i => $model) {
            ?>
       <input type="hidden" id="enq_from_date" name="enq_from_date" value="<?php echo $enq_from_date;?>">
        <input type="hidden" id="enq_to_date" name="enq_to_date" value="<?php echo $enq_to_date;?>">
        <input type="hidden" id="closing_from_date" name="closing_from_date" value="<?php echo $closing_from_date;?>">
        <input type="hidden" id="closing_to_date" name="closing_to_date" value="<?php echo $closing_to_date;?>">
        <input type="hidden" id="customer_id" name="customer_id" value="<?php echo $customer_id;?>">
        <input type="hidden" id="sales_group_id" name="sales_group_id" value="<?php echo $sales_group_id;?>">
        <input type="hidden" id="source_type_id" name="source_type_id" value="<?php echo $source_type_id;?>">
        <input type="hidden" id="probability_id" name="probability_id" value="<?php echo $probability_id;?>">
        <input type="hidden" id="leadowner_id" name="leadowner_id" value="<?php echo $leadowner_id;?>">
        <input type="hidden" id="status" name="status" value="<?php echo $status;?>">
  	 	<tr>
  	 	<td><?php echo $i+1;?></td>
                <td><?php echo $model->title; ?></td>
  	 	<td><?php echo $model->customer->customer_name;?></td>
                <?php if($model->enq_date!='0000-00-00'){ ?>
                <td><?php echo date("d/m/Y", strtotime($model->enq_date));?></td>
                <?php }else{ ?>
                <td>&nbsp;</td>
                <?php } ?>
                <?php if($model->closing_date!='0000-00-00'){ ?>
                <td><?php echo date("d/m/Y", strtotime($model->closing_date));?></td>
                <?php }else{ ?>
                <td>&nbsp;</td>
                <?php } ?>
                 <td><?php echo $model->file->leadowner->first_name." ".$model->file->leadowner->last_name;?></td>
                <td><?php echo $model->lead_reason;?></td>
                <td><?php echo $model->salesgroup->group_name;?></td>             
                           
                <?php if($model->source_type_id == 1)
                        $source = "Web";
                else if($model->source_type_id == 2)
                        $source = "Facebook"; 
                else if($model->source_type_id == 3)
                        $source = "Email"; 
                else if($model->source_type_id == 4)
                        $source = "Referral From Mouth"; 
                ?>
                <td><?php echo $source;?></td>       
                <td><?php echo $model->lead_currency->currency_code;?></td>    
                <td><?php echo $model->amount;?></td>    
                <td><?php echo $model->probability->probability;?></td>    
                <td><?php echo $model->customercontact->person_name;?></td>                
                <td><?php echo $model->mobile1;?></td> 
                <td><?php echo $model->email1;?></td> 
                <?php } ?>
       </tbody>
   </table>
</div>
<!--    mpdf
        <htmlpagefooter name="myfooter">
            <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; ">
                <div style="text-align:center;width:100%">This report is auto generated by Bluesky project on 
                    <?php
                  date_default_timezone_set("Asia/Dubai");
                 echo date('d/m/Y')." ".date("h:i:sa"); ?> </div>
                <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
            </div>
        </htmlpagefooter>
        <sethtmlpagefooter name="myfooter" page="all" value="on" />-->
    
</body>

</html>
