<?php 
//****************MODIFY BY AMIT SINGH ************D&D************************23-11-2012*********************************
// include('Class_PickListEditor.php');
include('Class_PickListEditor.php');
include("Class_Branch.php");
include("ClassRole.php");
include('includes/stockcalculation.php');

$max_size='2000';
$flag=0;
function extension($filename)
{
$name_brk=explode('.',$filename);
return  $name_brk[1];
}  
?>

<script language="javascript" type="text/javascript">
function open_items()
{
window.open("assignzone_to_client.php?leadid=<?php echo $_REQUEST['leadid']?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=350,width=500,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function CalculateTotalLeadAmt(i)
{
// var stock_perunit = document.getElementById("stock_perunit_+"+i).value;
var stock_price = document.getElementById("stock_price_"+i).value;
var stock_qty = document.getElementById("stock_qty_"+i).value;
document.getElementById("stock_value_"+i).value=stock_price*stock_qty ;
document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;;
}
</script>
<?php  $catid= $s->GetFieldValue('crm_picklist',"picklist_title='Leads' and status=1",'picklist_id');
if($_REQUEST['action']=='Edit' || $_REQUEST['action']=='View')
{
//echo "select * from crm_leads where leadid='".$_REQUEST['leadid']."'";
$getlead=DB_query( "select * from crm_leads where leadid='".$_REQUEST['leadid']."'",$db);
$row_lead=DB_fetch_array($getlead);
extract($row_lead);
$function_filter[]=$mst_branchid;
	$function_filter[]=$store;
	$function_filter[]=ConvertSQLDate($leads_date);
	$function_filter[]=ConvertSQLDate($leads_date); 
}
?>
<!-- Table 1 --><?php  include('crm_top_menu.php'); ?><!-- close table 1 -->
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Leads Management</h1>
<form action=""	 method="post" enctype="multipart/form-data">
<h3>General Information</h3>	
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="13%" align="right"><strong>Branch :</strong></td>
    <td width="20%"> <?php echo $s->getField('locations','loccode',$mst_branchid,'locationname'); ?></td>
    <td width="13%" align="right"><strong>Lead No. :</strong></td>
    <td width="20%"> <?php echo $leadcode?></td>
    <td width="13%" align="right"><strong>Lead Date :</strong></td>
    <td> <?php echo ConvertSQLDate($leads_date);?></td>
  </tr>
 
  <tr class="row1">
    <td align="right"><strong>Subject :</strong></td>
    <td> <?php echo $lead_subject;?></td>
    <td align="right"><strong>Lead Category :</strong></td>
    <td> <?php echo $s->getField('type_master','id',$lead_Category,'name'); ?></td>
    <td align="right"><strong>Lead Status :</strong></td>
    <td> <?php echo $lead_status; ?></td>
  </tr>
  <tr class="row1">
    <td align="right"><strong>Priority :</strong></td>
    <td> <?php echo  $lead_Priority;?></td>
    <td align="right"><strong>Sale Executive :</strong></td>
    <td> <?php echo $s->getField('www_users','id',$sale_executive,'realname');?></td>
    <td align="right"><strong>Lead source :</strong></td>
    <td><?php if($s->getField('lead_source','id',$lead_source,'name')=='oth') { echo 'other'; } else {
	echo $s->getField('lead_source','id',$lead_source,'name'); } ?></td>
  </tr>
  <?php if($s->getField('lead_source','id',$lead_source,'name')=='oth') { ?>
  <tr class="row1">
    <td align="right"><strong>Reference Name</strong></td>
    <td><input type="text" name="ref_name" style="width:98%;" value="<?php echo $s->getField('crm_lead_reference','parent_id',$lead_source,'name'); ?>" id="ref_name" /></td>	
	  <td align="right"><strong>Address</strong></td>
    <td><input type="text" name="ref_addres" style="width:98%;" id="ref_addres" /></td>	
	  <td align="right"><strong>Mobile No.</strong></td>
    <td><input type="text" name="ref_phone" style="width:98%;" id="ref_phone" /></td>	
  </tr>
  <tr class="row1">
	  <td align="right"><strong>Email ID</strong></td>
    <td><input type="text" name="ref_email" style="width:98%;" id="ref_email" /></td>
    <td colspan="4"></td>
</tr>
   <?php } ?> 
</table>
<br>
<h3>Client &amp; Communication Information</h3> 
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="13%" align="right"><strong>Client Name :</strong></td>
    <td width="20%"> <?php $ZoneValue=$s->getField('clientmaster','id',$company_name,'Zone'); 
		if($ZoneValue!='')
		{
		echo $s->getField('clientmaster','id',$company_name,'c_name'); 
		}		
	?>
	<?php if($ZoneValue=='') {?>
	<?php  echo $company_name;?> 
	<?php } ?>
	</td>
    <td width="13%" align="right"><strong>Group Name :</strong></td>
    <td width="20%"> <?php echo $groupname;?></td>
    <td width="13%" align="right"><strong>Company Type :</strong></td>
    <td> <?php echo $lead_function;?></td>
  </tr>
  <tr class="row1">
    <td align="right"><strong>Address I :</strong></td>
    <td> <?php echo $address1;?></td>
    <td align="right"><strong>Address II  :</strong></td>
    <td> <?php echo $address2;?></td>
    <td align="right"><strong>Address III :</strong></td>
    <td> <?php echo $address3;?></td>
  </tr>
  <tr class="row1">
    <td align="right"><strong>City  :</strong></td>
    <td> <?php echo $s->getField('city_master','id',$city,'city'); ?></td> 
	  <td align="right"><strong>State :</strong></td>
    <td> <?php echo $s->getField('state_master','id',$state,'state'); ?></td>
    <td align="right"><strong>Country :</strong></td>
    <td> <?php echo $s->getField('country_master','id',$country,'country'); ?></td> 
	</tr>	
  <tr class="row1">
    <td align="right"><strong>Email Id :</strong></td>
    <td> <?php echo $email;?></td>
    <td align="right"><strong>Phone No. :</strong></td>
    <td> <?php echo $phone;?></td>
    <td align="right"><strong>Mobile No. :</strong></td>
    <td> <?php echo $mobile;?></td>
  </tr>
  <tr class="row1">
    <td align="right"><strong>Fax No. :</strong></td>
    <td> <?php echo $fax?></td>
    <td align="right"><strong>Zip Code :</strong></td>
    <td> <?php echo $zipcode?></td> 
    <td colspan="2">&nbsp;</td>
	</tr>
</table>
<br>
<h3>Contact Person Information </h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="13%" align="right"><strong>Contact Person I :</strong></td>
    <td width="20%" id="ContactPerson"> <?php  echo $contact_name?></td>
    <td width="13%" align="right"><strong>Dept. :</strong></td>
    <td width="20%"> <?php echo $s->getField('deptmaster','id',$department,'deptname'); ?>  </td>
    <td width="13%" align="right"><strong>Designation :</strong></td>
    <td> <?php echo $s->getField('desigmaster','id',$designation,'designame'); ?> </td>
  </tr>
  <tr class="row1">
    <td align="right"><strong>Contact Person II :</strong></td>
    <td id="firstname"> <?php  echo $fname;?></td>
    <td align="right"><strong>Dept. :</strong></td>
    <td> <?php echo $s->getField('deptmaster','id',$department1,'deptname'); ?></td>
    <td align="right"><strong>Designation :</strong></td>
    <td> <?php echo $s->getField('desigmaster','id',$designation1,'designame'); ?></td>
  </tr>
</table>
<br>
<h3>Product Information</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#808080 solid 1px;">  
  <tr>
    <th width="3%">S. No.</th>
    <th width="10%">Item Code</th>
    <th>Item Name</th>
	  <th width="13%">Size</th>
    <th colspan="4" style="text-align:center;">Quantity</th>
    <th width="8%">Price</th>
    <th width="8%">Per Unit</th>
    <th width="8%">Value</th>
    <th width="8%">Total Stock Qty</th>
  </tr>

<?php $i=1; 
$getitem=DB_query("select * from crm_lead_items where mst_leadid='".$_REQUEST['leadid']."' ",$db);
$n= DB_num_rows($getitem);
while($row=DB_fetch_array($getitem)){
$ItemCode=$s->GetFieldValue('item_master',"id='".$row['item_code']."'",'StockID');
$ItemName=$s->GetFieldValue('item_master',"id='".$row['item_code']."'",'item_name');
$ItemName=$s->GetFieldValue('item_master',"id='".$row['item_code']."'",'item_name');
$conv1=$s->GetFieldValue('item_master',"id='".$row['item_code']."'",'conv_factor');

if($row['size']==0)
{
$conv=$s->GetFieldValue('item_master',"id='".$row['item_code']."'",'conv_factor');
}
else
{
$catid=$s->GetFieldValue('item_master',"id='".$row['item_code']."'",'SubCategoryID');
				$door=$s->GetFieldValue('size_master',"type_product='".$catid."' 
				and id='".$row['size']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",'area');

				$frame=$s->GetFieldValue('size_master',"frame_category='".$catid."'
				 and id='".$row['size']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",'frame');

				$shutter=$s->GetFieldValue('size_master',"shutter_category='".$catid."'
				 and id='".$row['size']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",'sutter');
				
					if(!empty($door)) { $conv=$door; }
					else if(!empty($frame)) {$conv=$frame;	}
					else { 	$conv=$shutter;	}
							$op=openingBalance($function_filter,$row['item_code']);
							$in_1=receivedMRN($function_filter,$row['item_code']);
							$out_1=issueSlip($function_filter,$row['item_code']);
							$out_2=issueSiteToSite($function_filter,$row['item_code']);		
							$in_2=receivedSiteToSite($function_filter,$row['item_code']);
							$out_3=issueMatarialReturn($function_filter,$row['item_code']);
							$in_3=receivedReturn($function_filter,$myrow['id']);		 
							$invalue=($op+$in_1[0]+$in_2+$in_3);							
							$outvalue=($out_1+$out_2+$out_3);
							$tot=trim($invalue)-trim($outvalue);							
							$total_current=$tot;
}
?>
<tr bgcolor="#fff">
  <td ><?php echo $i; ?></td>
  <td ><?php echo $ItemCode; ?></td>
  <td ><?php echo $ItemName; ?></td>
  <td ><?php echo $s->getField('size_master','id',$row['size'],'size'); ?> </td>
  <td width="5%"><?php echo $row['stock_qty'];?></td>
  <td width="5%"><?php echo $s->getField('unitsofmeasure','unitid',$row['primary_unit'],'unitname'); ?></td>
  <td width="5%"><?php echo $row['stock_qty2']; ?></td>
  <td width="5%"><?php echo $s->getField('unitsofmeasure','unitid',$row['secondary_unit'],'unitname'); ?></td>
  <td ><?php echo $row['stock_price'];?></td>
  <td ><?php echo $row['stock_perunit'];?></td>
  <td ><?php echo $row['stock_value'];?></td>
  <td ><?php echo $total_current;?></td>
</tr>
<?php $i++;} ?> 
</table>
<br>

<h3>Groups &amp; Users Assignment</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
    <?php
  if($created_by==$_SESSION['UserID'])
  {
        $groupArray=explode(',', $groupid);
  ?>
<tr class="row1">
  	<td width="13%" align="right"><strong>Groups Name :</strong></td>
    <td width="35%"><?php 
    foreach($groupArray as $groupidInd)
    {
    echo $s->getField('securityroles','secroleid',$groupidInd,'role_name').'<br/>';
    }
    ?>	</td>
    <td width="13%" align="right"><strong>Users Name :</strong></td>
    <td>
	<div id='hid-Roleid'>
	<?php
	$userArray=explode(',',$userid);
        foreach($userArray as $user)
            {
            echo $s->getField('www_users','id',$user,'realname').'<br/>';
            }
            ?>
 </div>	
 </td>
 </tr>
 <?php
 }
	
	else {
 	?>
 	<tr class="row1">
 	<td width="13%" align="right"><strong>Groups Name :</strong></td>
    <td width="35%">
    <?php $groupSql= "SELECT secrolename FROM  securityroles where secroleid='".$groupid."' and  rolestatus ='Y' ";
    $groupRes=DB_query($groupSql,$db);
	$groupRow=DB_fetch_array($groupRes);
    ?>
    </td>
    <td width="13%" align="right"><strong>Users Name :</strong></td>
     <td><?php $usqrSql= "SELECT id , realname FROM  www_users where rolepid ='".$groupid."' ";
     	$userRes=DB_query($usqrSql,$db);
		$userRow=DB_fetch_array($userRes);
         ?>
         <?php echo $userRow['realname'];?></td>
 	</tr>
 	<?php		
	}	
	?>
  </table>
<br>
	<h3>Remarks</h3>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td>
      <textarea style="width:99%; height:80px;" name="description" readonly="readonly"><?php  echo $description;?></textarea>    
    </td>
  </tr>
</table>
<!-- form 5 close -->
	</form>	
	</div> <!-- form1 div close -->
</div>
