<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/cartfunctions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
$_SESSION['cuPages']='ser_receivecreate.php';   
$cuPage='ser_receivecreate.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];     
}else{
header('Location:../index.php');
exit;    
}
$mhead='sevice';
$menuh='Service';
$phead='serrevcre';
$page='Service Received Create';
$dtnow = date("Y-m-d h:i:s", time());
$today = strftime("%Y-%m-%d", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>
<?php
   $dyna1='';
  $d = rand(1, 100000); 
  $invoice_no = "SR".date("Ymd-").$d;
?>
<?php 
if(isset($_POST['save_received'])){
	$cname = ucwords(remove_junk(escape($_POST['cname'])));
    $invoice_no =remove_junk(escape($_POST['invoice_no']));
    $cphone = remove_junk(escape($_POST['cphone']));
    $caddress = remove_junk(escape($_POST['caddress']));
    $pname = remove_junk(escape($_POST['pname']));
    $pmodel = remove_junk(escape($_POST['pmodel']));
    $pdescription = remove_junk(escape($_POST['pdescription']));
    $deli_date = $_POST['deli_date'];
    $status = 'Pending';
   
	
	if(isset($_POST['invoice_no'])){
	$ducode = mysqli_query($con,"SELECT * FROM tbl_serreceive WHERE invoice_no = '$invoice_no'");
	}
	
	if($ducode->num_rows > 0) {
		save_msg('i','Invoice number alrady exists! Plz try another');
		echo "<script>window.location='ser_receivecreate.php'</script>";
	}else{
    $sql="INSERT INTO tbl_serreceive(invoice_no,cname,cphone,caddress,pname,pmodel,pdescription,deli_date,status,brid,uid,date) VALUES ('$invoice_no','$cname','$cphone','$caddress','$pname','$pmodel','$pdescription','$deli_date','$status','$brid','$aid','$dtnow')";    
	$result = mysqli_query($con,$sql) or die(mysqli_error($con));
    $efid=mysqli_affected_rows($con);    
    if($efid>0){
        $act =remove_junk(escape('Service Receive invoice: '.$invoice_no));    
        write_activity($aid,'SER','Service Receive has been created',$act);        
        save_msg('s','Service Receive Successfully created!!!');
        }else{
        save_msg('s','Service Receive Fail to create!!!');    
        }
    echo "<script>window.location='ser_receivecreate.php'</script>";  
	}  
}
?>
<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">

<div class="row">
<div class="col-md-9">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Add New Received</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<form action="ser_receivecreate.php" onsubmit="return validate()" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="col-md-12 popup_details_div">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="col-md-12">

<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Customer Name</label>    
<input type="text" name="cname" maxlength="45" value="" id="cname" class="form-control" placeholder="e.g. Md.Sumon Rahman"/>
</div>    
</div>
  
<div class="col-md-3">
<div class="form-group">
<label>Invoice No</label>    
<input type="text" name="invoice_no" maxlength="15" value="<?php echo $invoice_no ?>" id="invoice_no" class="form-control" placeholder="e.g. ABA/CU/001" readonly/>
</div>    
</div>  

<div class="col-md-3">
<div class="form-group">
<label>Delivery Date</label>    
<input type="text" name="deli_date" maxlength="45"  id="deli_date" class="form-control datetimepicker"/>
</div>    
</div>  
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Phone</label>    
<input type="text" name="cphone" maxlength="45" value="" id="cphone" class="form-control" placeholder="e.g.017XXXXXXXXXX"/>
</div>    
</div>
<div class="col-md-4">
<div class="form-group">
<label>Product Name</label>    
<input type="text" name="pname" maxlength="45" value="" id="pname" class="form-control" placeholder="e.g. TV"/>
</div>    
</div>
<div class="col-md-4">
<div class="form-group">
<label>Product Model</label>    
<input type="text" name="pmodel" maxlength="45" value="" id="pmodel" class="form-control" placeholder="e.g. SN487"/>
</div>    
</div>
 
</div>    
   
<div class="row">
<div class="col-md-6"> 
<div class="form-group">    
<label>Address</label>
<textarea class="form-control" name="caddress" id="caddress" maxlength="200" rows="4" placeholder="Address"></textarea>    
</div>
</div>    
<div class="col-md-6">    
<div class="form-group">
<label>Product Description/Problem</label>
<textarea class="form-control" name="pdescription" id="pdescription" maxlength="200" rows="4" placeholder="Description"></textarea>   
</div>
</div>    
</div> 

    
</div>    
</div>    
<div class="col-md-1"></div>    
</div>
<div class="clearfix" ></div>
<div class="col-md-12 nopadding widgets_area"></div>    
<div class="row"style="margin-top: 15px" >
<div class="col-md-8 ">
</div>
<div class="col-md-4 text-right" >
<input type="submit" name="save_received" id="submit" class="btn btn-flat bg-purple btn-sm" value="Save"/> <a href="main_cutomerlist.php" class="btn btn-flat bg-gray  ">Close</a>
</div> 
</div>     
</form>    
</div>
</div>
</div>
<div class="col-md-3">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['access']=='1'){echo read_activity($aid,'SER','A');}else{echo read_activity($aid,'CUS','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>

<?php include('../layout/quick.php');?>    
</section>
<!-- /.main content -->
<?php include('../layout/rside.php'); ?> 
<?php include('../layout/checkout.php'); ?>
<div id="invdata" style="display: none;"></div>    
</div>
<?php
include('../layout/footer.php');
?>