<?php
/*--------------------------------------------------------------*/
/* Get Company Address
/*--------------------------------------------------------------*/
function get_cominfo($id,$cfild='',$brid=''){
global $con;
$output='';

if($cfild!=''){
$sql="SELECT *,".$cfild." AS cdata FROM tbl_company WHERE id='$id' LIMIT 1";	
}else{
$sql="SELECT * FROM tbl_company WHERE id='$id' LIMIT 1";	
}

$query=mysqli_query($con,$sql) or die(mysqli_error($con));
$row=mysqli_fetch_array($query);

if($brid!=''){
if($brid!=0){    
$bsql="SELECT * FROM tbl_branch WHERE id='$brid' LIMIT 1";    
$binfo=mysqli_query($con,$bsql) or die(mysqli_error($con));    
$bri=mysqli_fetch_array($binfo);    
}
}
    
$output='<p>';
if($brid!=''){
if($brid!=0){
if(get_fild_data('tbl_setting','1','sval')==0){    
$output.='<strong>Branch:</strong>'.get_fild_data('tbl_branch',$brid,'name');     
$output.='<br><strong>Address:</strong> '.$bri['address'];
}else{
$output.='<strong>শাখাঃ</strong>'.get_fild_data('tbl_branch',$brid,'bname');     
$output.='<br><strong>ঠিকানাঃ</strong> '.$bri['baddress'];    
}
}else{
if(get_fild_data('tbl_setting','1','sval')==0){    
$output.=$row['address'];
}else{
$output.=$row['baddress'];    
}
}
}else{
if(get_fild_data('tbl_setting','1','sval')==0){    
$output.=$row['address'];
}else{
$output.=$row['baddress'];    
}    
}
    
if($brid!=''){
if($brid!=0){ 
if($bri['phone']!=''){
if(get_fild_data('tbl_setting','1','sval')==0){     
$output.='<br><strong>Phone:</strong> '.$bri['phone'];
}else{
$output.='<br><strong>ফোনঃ</strong> '.engToBn($bri['phone']);    
}
}
}else{    
if($row['phone']!=''){
    if(get_fild_data('tbl_setting','1','sval')==0){      
        $output.='<br><strong>Phone:</strong> '.$row['phone'];
    }else{
        $output.='<br><strong>ফোনঃ</strong> '.engToBn($row['phone']);
    }
}
}
}else{
if($row['phone']!=''){
if(get_fild_data('tbl_setting','1','sval')==0){     
    $output.='<br><strong>Phone:</strong> '.$row['phone'];
}else{
    $output.='<br><strong>ফোনঃ</strong> '.engToBn($row['phone']);    
}
}    
}





if($brid!=''){
if($brid!=0){ 

}else{
if($row['mobile']!=''){
if(get_fild_data('tbl_setting','1','sval')==0){    
$output.='<br><strong>Mobile:</strong> '.$row['mobile'];
}else{
$output.='<br><strong>মোবাইলঃ</strong> '.engToBn($row['mobile']);    
}
}    
}    
}else{
if($row['mobile']!=''){
if(get_fild_data('tbl_setting','1','sval')==0){    
$output.='<br><strong>Mobile:</strong> '.$row['mobile'];
}else{
$output.='<br><strong>মোবাইলঃ</strong> '.engToBn($row['mobile']);     
}
}    
}    


if($brid!=''){
if($brid!=0){ 
if($bri['email']!=''){
if(get_fild_data('tbl_setting','1','sval')==0){     
$output.='<br><strong>Email:</strong> '.$bri['email'];
}else{
$output.='<br><strong>ই-মেইলঃ</strong> '.$bri['email'];    
}
}
}else{    
if($row['email']!=''){
if(get_fild_data('tbl_setting','1','sval')==0){     
$output.='<br><strong>Email:</strong> '.$row['email'];
}else{
$output.='<br><strong>ই-মেইলঃ</strong> '.$row['email'];    
}
}
}
}else{
if($row['email']!=''){
if(get_fild_data('tbl_setting','1','sval')==0){     
$output.='<br><strong>Email:</strong> '.$row['email'];
}else{
$output.='<br><strong>ই-মেইলঃ</strong> '.$row['email'];    
}	
}    
} 

$output.='<br><strong>BIN:</strong> 0054366650102';    
    
// if($row['web']!=''){
// if(get_fild_data('tbl_setting','1','sval')==0){     
//     $output.='<br><strong>Web:</strong> '.$row['web'];
// }else{
//     $output.='<br><strong>ওয়েবঃ</strong> '.$row['web'];    
// }
// }
$output.='</p>';
if($cfild!=''){
return $row['cdata'];	
}else{
return $output; 	
}	
}

/*--------------------------------------------------------------*/
/* Get Customer OR supplier info
/*--------------------------------------------------------------*/
function get_csinfo($id,$table,$cfild=''){
global $con;
$output='';

if($cfild!=''){
$sql="SELECT *,".$cfild." AS cdata FROM ".$table." WHERE id='$id' LIMIT 1";	
}else{
$sql="SELECT * FROM ".$table." WHERE id='$id' LIMIT 1";	
}

$query=mysqli_query($con,$sql) or die(mysqli_error($con));
$row=mysqli_fetch_array($query);

$output='<p><span style="font-size: 15px;font-weight: bold;">'.$row['name'].'</span>';
if($row['address']!=''){
$output.='<br><strong>Address:</strong> '.$row['address'];	
}
if($row['cnumber']!=''){
$output.='<br><strong>Contact:</strong> '.$row['cnumber'];	
}
if($row['cemail']!=''){
$output.='<br><strong>Email:</strong> '.$row['cemail'];	
}
if($row['code']!=''){
$output.='<br><strong>Client ID:</strong> '.$row['code'];	
}
$output.='</p>';
if($cfild!=''){
return $row['cdata'];	
}else{
return $output; 	
}	
}

function get_csinfogen($id,$table,$cfild=''){
global $con;
$output='';

if($cfild!=''){
$sql="SELECT *,".$cfild." AS cdata FROM ".$table." WHERE id='$id' LIMIT 1";	
}else{
$sql="SELECT * FROM ".$table." WHERE id='$id' LIMIT 1";	
}

$query=mysqli_query($con,$sql) or die(mysqli_error($con));
$row=mysqli_fetch_array($query);

$output='<p><span style="font-size: 15px;font-weight: bold;">'.$row['name'].'</span>';
if($row['cnumber']!=''){
$output.='<br><strong>Contact:</strong> '.$row['cnumber'];	
}
if($row['cemail']!=''){
$output.='<br><strong>Email:</strong> '.$row['cemail'];	
}
if($row['code']!=''){
$output.='<br><strong>Client ID:</strong> '.$row['code'];	
}
$output.='</p>';
if($cfild!=''){
return $row['cdata'];	
}else{
return $output; 	
}	
}




function get_csinfogen80($id,$table,$cfild=''){
    global $con;
    $output='';
    
    if($cfild!=''){
    $sql="SELECT *,".$cfild." AS cdata FROM ".$table." WHERE id='$id' LIMIT 1";	
    }else{
    $sql="SELECT * FROM ".$table." WHERE id='$id' LIMIT 1";	
    }
    
    $query=mysqli_query($con,$sql) or die(mysqli_error($con));
    $row=mysqli_fetch_array($query);
    
    $output='<p><span style="font-size: 8px;font-weight: bold;">'.$row['name'].'</span>';
    if($row['cnumber']!=''){
    $output.='<br><strong>Contact:</strong> '.$row['cnumber'];	
    }
    if($row['cemail']!=''){
    $output.='<br><strong>Email:</strong> '.$row['cemail'];	
    }
    if($row['code']!=''){
    $output.='<br><strong>Client ID:</strong> '.$row['code'];	
    }
    $output.='</p>';
    if($cfild!=''){
    return $row['cdata'];	
    }else{
    return $output; 	
    }	
    }


    function get_walkcus80($id,$table,$key=''){
        global $con;
        $output='';
        $sql="SELECT * FROM ".$table." WHERE id='$id' LIMIT 1";
        $query=mysqli_query($con,$sql) or die(mysqli_error($con));
        $row=mysqli_fetch_array($query);    
        if($key!=''){
            
        if($row['waddress']!=''){
        $output.='<strong>'.$row['waddress'].'</strong>';
        }
            
        }else{    
        $output='<p><span style="font-size: 8px;font-weight: bold;">'.$row['name'].'</span>';
        if($row['mobile']!=''){
        $output.='<br><strong>Mobile:</strong> '.$row['mobile'];
        }
        
        }
        $output.='</p>';
        return $output;    
        }



function get_walkcus($id,$table,$key=''){
global $con;
$output='';
$sql="SELECT * FROM ".$table." WHERE id='$id' LIMIT 1";
$query=mysqli_query($con,$sql) or die(mysqli_error($con));
$row=mysqli_fetch_array($query);    
if($key!=''){
    
if($row['waddress']!=''){
$output.='<strong>'.$row['waddress'].'</strong>';
}
    
}else{    
$output='<p><span style="font-size: 15px;font-weight: bold;">'.$row['name'].'</span>';
if($row['mobile']!=''){
$output.='<br><strong>Mobile:</strong> '.$row['mobile'];
}

}
$output.='</p>';
return $output;    
}

function get_brwhinfo($type,$table,$id){
global $con;
$output='';
if($type=='BR'){
$stype='Branch: ';    
}else{
$stype='Warehouse: ';    
}    
$sql="SELECT * FROM ".$table." WHERE id='$id' LIMIT 1";
$query=mysqli_query($con,$sql) or die(mysqli_error($con));
$row=mysqli_fetch_array($query);
if($id!=0){
$output='<span style="font-size: 15px;font-weight: bold;">'.$stype.'</span>'.$row['name'];
if($row['address']!=''){
$output.='<br><strong>Address: </strong> '.$row['address'];	
}
if($row['email']!=''){
$output.='<br><strong>Email: </strong> '.$row['email'];	
}
if($row['phone']!=''){
$output.='<br><strong>Phone: </strong> '.$row['phone'];	
}    
}else{
$output='<p><span style="font-size: 7px;font-weight: bold;">'.$stype.'</span> Main Branch';     
}
$output.='</p>';    
return $output;    
}

/*--------------------------------------------------------------*/
/* Function for Tender Address OR Thirdpaty Sales
/*--------------------------------------------------------------*/
function tender_address($table,$id){
global $con;
$output='';
$data='';    
$sql="SELECT * FROM ".$table." WHERE id='$id' LIMIT 1";
$query=mysqli_query($con,$sql) or die(mysqli_error($con));
$row=mysqli_fetch_array($query);
$data.=$row['pname'].$row['pdep'].$row['paddress'];
if(strlen($data)>5){    
$output.='<p>';
if($row['pname']!=''){
$output.='<strong>Name: </strong>'.$row['pname'];    
}
if($row['pdep']!=''){
if(strlen($output)>1){
$output.='<br><strong>Dept/Des: </strong>'.$row['pdep'];    
}else{
$output.='<strong>Department: </strong>'.$row['pdep'];    
}        
}
if($row['paddress']!=''){
if(strlen($output)>1){
$output.='<br><strong>Address: </strong> '.$row['paddress'];    
}else{
$output.='<strong>Address: </strong>'.$row['paddress'];    
}        
}
$output.='</p>';
}else{
$output='';    
}
return $output;    
}

/*--------------------------------------------------------------*/
/* Function for break print serial
/*--------------------------------------------------------------*/

function sl_break($string,$brp,$sep=', '){
$restring='';    
$serial=explode($brp,$string);
$max = count($serial);
$slrlen=strlen($serial[0]);
if($slrlen<=12){
$brp=4;    
}elseif($slrlen>=13 && $slrlen<=15){
$brp=3;    
}elseif($slrlen>15){
$brp=2;    
}
$count = 1;    
for($i=0;$i<$max;$i++){
if ($count%$brp == 0){
$restring.=$serial[$i].'<br>';
}else{
if($i==($max-1)){
$restring.=$serial[$i];    
}else{    
$restring.=$serial[$i].$sep;
}
}
$count++;    
}    
return $restring;    
}
?>