<?php 
include("../config.php");
if(!empty($_POST)){
	$bill_no            = mysqli_real_escape_string($conn, $_POST['invoice_no']);
	$bill_submited_by       		= mysqli_real_escape_string($conn, $_POST['bill_submited_by']);
	$bill_submited_date       	= mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_POST['bill_submited_date'])));
	$updated_datetime   = date('Y-m-d H:i:s');
	$updated_id         = $_SESSION['user_detail']['id'];

	if($_POST["id"] != ''){
  	 	$type      = 'bill_conformation';
		$user_id   = $_SESSION['user_detail']['id'];
		$data      = serialize($_POST);
  	 	
  	 	$insert = "UPDATE billing SET bill_submited_by = '$bill_submited_by',bill_submited_date='$bill_submited_date',updated_id='$updated_id',updated_datetime='$updated_datetime' WHERE invoice_no = '".$bill_no."'";
  	 	
  	 	$result = mysqli_query($conn,$insert) or die( mysqli_error($conn) );
  	 	
		$activiti = "INSERT INTO `activities`(`type`, `user_id`, `data`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$type."','".$user_id."','".$data."','".$created_id."','".$created_datetime."','".$updated_id."','".$updated_datetime."')";
    	$acttivity_res = mysqli_query($conn,$activiti);

    }
  echo json_encode( array('response' => 1, 'msg' => 'DATA SAVED SUCCESSFULLY....!!!', 'alert' => 1, 'redirect' => 'index.php?page=bill/list.php') );die();
}else{
  echo json_encode( array('response' => 2, 'msg' => 'Opps', 'alert' => 1, 'redirect' => 'index.php?page=bill/add.php') );die();
} 