<?
session_start();
include('includes/config.php');
include('defs.php');

if(strlen($_SESSION['aid'])==0)
  { header('location:index.php');
}

$usr=$_SESSION['uname'];






?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <title>GLAKB  | Customer Details</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">
  <!--Function Email Availabilty---->

</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
<?php include_once("includes/navbar.php");?>
  <!-- /.navbar -->

  <!-- Main Sidebar Container -->
 <?php include_once("includes/sidebar.php");?>

 
  <div class="content-wrapper">
<?
$usr=$_SESSION['uname'];
$idd=$_GET['tid'];


echo "                <form name='sub_head' action='' method=POST onSubmit='return  validateForm();'>";




?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
 
  

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- DataTables -->
  <link rel="stylesheet" href="../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.css">
</head>


              <div class="card-body">
 
 
    
<style>

 

       
        .input-box {
            width: 100%;
            padding: 4px;
            margin-top: 2px;
            margin-bottom: 2px;
            border: 2px solid gainsboro;
            border-radius: 4px;
            font-size: 16px;

        }



#customers {
  font-family: Times-Roman;
  border-collapse: collapse;
  width: 98%;
}

#customers td, #customers th {
  border: 1px solid #4444;
  padding: 3px;
}

#customers tr:nth-child(even){background-color:gainsboro ;}


#customers th {
  padding-top: 8px;
  padding-bottom: 8px;
  text-align: center;
  background-color:dodgerblue;
  color: white;
}
</style>   


<script language="javascript">

 function formconfirm() {
return confirm("Do you want to Save the Record?<? echo "$coursename";?>"); 
}

function processkey(e)
                {
                       var kc = (window.Event ? e.which : e.keyCode);

    // Allow digits (48–57), backspace (8), dot (46), and minus (-) (45)
    if ((kc >= 48 && kc <= 57) || kc == 8 || kc == 46 || kc == 45)
        return true;
    else
        return false;

     
           }
function validateForm()
{
if((document.sub_head.item33.value) == '')
{
alert("Please Select Accounts Cost Center!");
document.sub_head.item33.focus();
return false;
}


if((document.sub_head.strcode.value) == '')
{
alert("Please Enter Accounts Code!");
document.sub_head.strcode.focus();
return false;
}

if((document.sub_head.strname.value) == '')
{
alert("Please Enter Accounts Head Name!");
document.sub_head.strname.focus();
return false;
}

return true;
}






                
</script>
<form name="voucher" method="POST" action="" >



<body>
<div id="content">
<div id="left">



   <link rel="stylesheet" href="css/style.css">


<?
$result = mysqli_query($link, "select * from acc_heads where Id='$idd'");
while($row  = mysqli_fetch_object($result))
{
$name=$row->Name;
$mhead=$row->M_Head;
$code=$row->A_Id;
$strn=$row->STRN;
$ntn=$row->NTN1;
$addr=$row->Adress;
$cname=$row->C_Person;
$cont=$row->Contact_No;
$ctype=$row->Ctype;
$city=$row->City;
$dued=$row->Dued;
$prov=$row->Province;
$sman=$row->Salesman;
$waree=$row->Warehouse;
$clmt=$row->C_Limit;
$m_tar=$row->M_Target;

}                                
?>


<table align="center" id="customers">
       
<tr>
    <th colspan="6"><font size="5">EDIT CUSTOMER DETAILS</th>

  </tr>


<td><b><font size=3 color="black">Customer Code:</b></td>
<td colspan="2">
<input type="text" name="strcode" id="strcode" value="<?php echo $code ?>" class="input-box" style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:20px;' readonly  /></td>
<td colspan="3">
</tr>
  

  
<tr align="left">
<td><b><font size=3 color="black">Customer Title:</b></td>
<td colspan="4">
<input type="text" name="strname" id="strname" value="<?php echo $name ?>" class="input-box" /></td>
</tr>
    

  
<tr align="left">
<td><b><font size=3 color="black">Contact Person:</b></td>
<td colspan="2">
<input type="text" name="cper" id="cper" value="<?php echo $cname ?>" class="input-box" /></td>

<td><b><font size=3 color="black">Contact Number:</b></td>
<td colspan="2">
<input type="text" name="cont" id="cont" value="<?php echo $cont ?>" class="input-box" /></td>


<tr>
    <td><b><font size=3 color="black">City / Town:</b></td>
                        <td colspan="4">
    <select class="form-control" name="city" id="city" style=font-size="16" >
                                <option value="<?php echo $city ?>"><?php echo $city ?></option>
                                <?php 
                                if(isset($_GET['City']))
                                        {
                                                $City = $_GET['City'];
                                                
                                                
                
                                        }
                                else                        
                                        $City = "";
                                        
                                        //include('config.php');
$result = mysqli_query($link, "select Distinct Name from city where Name!='$city' order by Name");
                                        while($row  = mysqli_fetch_object($result))
                                        {
                                                        if($City == $row->Name)
                                                        {
                                                                echo "<option value=\"$row->Name\" selected=\"selected\">$row->Name</option>";
                                                        }        
                                                        else
                                                        {
                                                                echo "<option value=\"$row->Name\">$row->Name</option>";
                                                        }
                                        }
                                ?>
                                </select>
  
<tr>
<td><b><font size=3 color="black">Target Warehouse:</font></b></td>
<td colspan="2">
<select class="form-control" name=waree>
<option value="<?php echo $waree ?>"><?php echo $waree ?></option>
<option value='QUETTA'>QUETTA</option>
<option value='LAHORE'>LAHORE</option>
<option value='KARACHI'>KARACHI</option>
</select>


<td><b><font size=3 color="black">Province:</font></b></td>
<td>
<select class="form-control" name=province>
<option value="<?php echo $prov ?>"><?php echo $prov ?></option>
<option value='Balochistan'>Balochistan</option>
<option value='Punjab'>Punjab</option>
<option value='Sindh'>Sindh</option>
<option value='KPK'>KPK</option>
</select>
  

<tr>
<td><b><font size=3 color="black">Customer Type (If any):</b></td>
                        <td colspan="2">
    <select class="form-control" name="cust" id="cust" style=font-size="16" >
                                <option value="<?php echo $ctype ?>"><?php echo $ctype ?></option>
                                <?php 
                                if(isset($_GET['Cust']))
                                        {
                                                $Cust = $_GET['Cust'];
                                                
                                                
                
                                        }
                                else                        
                                        $Cust = "";
                                        
                                        //include('config.php');
$result = mysqli_query($link, "select Distinct Title from customer_type where Title!='$ctype' order by Title");
                                        while($row  = mysqli_fetch_object($result))
                                        {
                                                        if($Cust == $row->Title)
                                                        {
                                                                echo "<option value=\"$row->Title\" selected=\"selected\">$row->Title</option>";
                                                        }        
                                                        else
                                                        {
                                                                echo "<option value=\"$row->Title\">$row->Title</option>";
                                                        }
                                        }
                                ?>
                                </select>



<td><b><font size=3 color="black">Address:</b></td>
<td colspan="1">
<input type="text" name="adr" id="adr" value="<?php echo $addr ?>" class="input-box" /></td>
</tr>

<tr align="left">
<td><b><font size=3 color="black">NTN:</b></td>
<td colspan="2">
<input type="text" name="ntn1" id="ntn1" value="<?php echo $ntn ?>" class="input-box" style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:18px;'/></td>

<td><b><font size=3 color="black">STRN:</b></td>
<td colspan="2">
<input type="text" name="strn1" id="strn1" value="<?php echo $strn ?>" class="input-box" style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:18px;'/></td>
</tr>

  

<tr align="left">
<td><b><font size=3 color="black">Due Days:</b></td>
<td colspan="2">
<input type="text" name="due" id="due" value="<?php echo $dued ?>" class="input-box" style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:18px;' onkeypress='return processkey(event)' /></td>

<td><b><font size=3 color="black">Salesman:</b></td>
                        <td colspan="2">
    <select class="form-control" name="sman" id="sman" style=font-size="16" >
                                <option value="<?php echo $sman ?>"><?php echo $sman ?></option>
                                <?php 
                                if(isset($_GET['Sman']))
                                        {
                                                $Sman = $_GET['Sman'];
                                                
                                                
                
                                        }
                                else                        
                                        $Sman = "";
                                        
                                        //include('config.php');
$result = mysqli_query($link, "select Distinct Name from acc_heads where M_Head='Salesman' and Name!='$sman' order by Name");
                                        while($row  = mysqli_fetch_object($result))
                                        {
                                                        if($Sman == $row->Name)
                                                        {
                                                                echo "<option value=\"$row->Name\" selected=\"selected\">$row->Name</option>";
                                                        }        
                                                        else
                                                        {
                                                                echo "<option value=\"$row->Name\">$row->Name</option>";
                                                        }
                                        }
                                ?>
                                </select>

<tr align="left">
<td><b><font size=3 color="black">Credit Limit:</b></td>
<td colspan="2">
<input type="text" name="climit" id="climit" value="<?php echo $clmt ?>" class="input-box" style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:18px;' onkeypress='return processkey(event)' /></td>

<?
$resut = mysqli_query($link, "select Debit-Credit as bals from ledgers where Code='$name' and M_Head='Customer' and Details ='Opening Balance of the Customer..' ");
while($rowr  = mysqli_fetch_object($resut))
{
$deb=$rowr->bals;
}
?>


<td><b><font size=3 color="black">Opening Balance:</b></td>
<td colspan="2">
<input type="text" name="opdeb" id="opdeb" value="<?php echo $deb ?>" class="input-box" style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:18px;' onkeypress='return processkey(event)' /></td>

<tr>
<td><b><font size=3 color="black">Monthly Sales Target:</b></td>
<td colspan="2">
<input type="text" name="mtar" id="mtar" value="<?php echo $m_tar ?>" class="input-box" style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:18px;' onkeypress='return processkey(event)' /></td>


<tr>
<td colspan="5" align="center">
<input type="submit" name="save" value="Update Details" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">


<input type="submit" name="hme" value="Main Search Page" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">

  </td>

</table>



         
<?php


if(isset($_POST['hme']))
{
$link1 = "<script>window.open('editview.php','_self')</script>";
echo $link1;
}


if(isset($_POST['save']))
{
date_default_timezone_set ("Asia/Karachi");
$date = date('d-m-Y (h:i:s a)', time());
$expdate = strtotime($_POST['strDate']);
$expdate = date("Y-m-d",$expdate);


$name=$_POST['strname'];
$code=$_POST['strcode'];                
$ntn1=$_POST['ntn1'];
$strn2=$_POST['strn1'];
$addr=$_POST['adr'];
$due=$_POST['due'];
$ctpe=$_POST['cust'];
$prov1=$_POST['province'];
$city=$_POST['city'];
$cont=$_POST['cont'];
$cper=$_POST['cper'];
 
$smn=$_POST['sman'];
$ware=$_POST['waree'];
$clmt=$_POST['climit'];
$obals=$_POST['opdeb'];
$mtar=$_POST['mtar'];



$result = mysqli_query($link, "update acc_heads set C_Person='$cper', Contact_No='$cont', Adress='$addr', STRN='$strn2', NTN1='$ntn1', Dued='$due', Salesman='$smn', Warehouse='$ware', Ctype='$ctpe', Province='$prov1', City='$city', C_Limit='$clmt', M_Target='$mtar' where A_Id = '$code' ");

$result1 = mysqli_query($link, "update ledgers set Salesman='$smn' where Code = '$name' and M_Head='Customer' ");



if($obals>=0)
{
$result = mysqli_query($link, "update ledgers set Debit='$obals', Credit='0.00' where Details='Opening Balance of the Customer..' and Code = '$name' ");

}

if($obals<0)
{
            $nopbal = $obals * -1;
$result = mysqli_query($link, "update ledgers set Credit='$nopbal', Debit='0.00' where Details='Opening Balance of the Customer..' and Code = '$name' ");

}


donot1:
echo "<script language='javascript'>";
echo "alert('Successfully Updated!')";
echo "</script>";

$link1 = "<script>window.open('edit_cust.php?tid=$idd','_self')</script>";
echo $link1;

donot:

}



        echo "</form>";                
 a:       
        include "footer.php";
?>

</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="../plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
$(function () {
  bsCustomFileInput.init();
});
</script>
</body>
</html>
<?php  ?>