<?php
require_once("../dbconfig.php");
include "../dbfunction.php";
//print_r($_POST);
//$company_data=$_POST;
//$new_company =insert($con,"customers",$company_data);
$name="";
$phone="";
$mobile="";
$email="";
$address1="";
$address2="";
$city="";
$post_code="";
$payment_terms="";
if(isset($_POST['name']))
{
$name=$_POST['name'];
}
if(isset($_POST['phone']))
{
$phone=$_POST['phone'];
}
if(isset($_POST['mobile']))
{
$mobile=$_POST['mobile'];
}
if(isset($_POST['email']))
{
$email=$_POST['email'];
}
if(isset($_POST['address1']))
{
$address1=$_POST['address1'];
}
if(isset($_POST['address2']))
{
$address2=$_POST['address2'];
}
if(isset($_POST['city']))
{
$city=$_POST['city'];
}
if(isset($_POST['post_code']))
{
$post_code=$_POST['post_code'];
}
if(isset($_POST['payment_terms']))
{
$payment_terms=$_POST['payment_terms'];
}

mysqli_query($con,"INSERT INTO customers (name,phone,mobile,email,address1,address2,city,post_code,payment_terms) 
VALUES ('$name','$phone','$mobile','$email','$address1','$address2','$city','$post_code','$payment_terms')");

$source_id=mysqli_insert_id($con);
$balance=0;
if(isset($_POST['balance']))
{
$balance=$_POST['balance'];
}
else
{
$balance=0;
}
$details="opening balance";
date_default_timezone_set ("Europe/London");
 $date = date('Y-m-d');
  $created = date('Y-m-d H:i:s');
  $sql = "INSERT INTO `creditors` (date, source_id,balance,details,created,name) VALUES('$date','$source_id','$balance','$details','$created','$name')";
		 
				//	  echo $sql;

		  if (!mysqli_query($con,$sql)) {
			  echo $sql;
			  die('Create Transaction 3 INTO ORDER_Details -Error: ' . mysqli_error($con));
		  }
		  else
		  {
		  echo 'success';
		  }
//if($new_company){echo 'success';}
?>