<?php 
$conn = mysqli_connect("localhost","root","admin@2411","shree_shyam");
require 'function.php';
$select = mysqli_query($conn, "SELECT * FROM `temp_truck`");
$detail = array();
while ($row = mysqli_fetch_assoc($select)) {
	$detail[] = $row;
}

foreach ($detail as $key => $details) {
	$code     = turckCode($conn);
	$act_code = accountCode($conn);
	echo "<pre>";
	print_r("INSERT INTO `truck_mst`(`truck_code`, `truck_no`, `o_name`, `o_address`, `o_city`, `o_contact`, `o_pan`, `t_name`, `t_address`, `t_city`, `t_contact`, `t_pan`, `d_name`, `d_address`, `d_city`, `d_contact`, `lic_no`, `rto`, `tr_name`, `tr_address`, `tr_city`, `tr_contact`, `reference`, `remark`, `lorry_type`, `chasis_no`, `eng_no`, `per_no`, `from`, `up_to`, `insurance`, `branch`, `policy`, `height`, `weight`, `up_too`, `rc_no`, `rc_img`, `rc_img_back`, `pan_no`, `pan_img`, `dec_img`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$code."','".$details['truck']."','".$details['owner']."','".$details['address']."','".$details['city']."','','','".$details['transport']."','".$details['t_address']."','".$details['t_city']."','','','','','','','','','','','','','','','','".$details['chasis']."','".$details['engin']."','','','','','','','','','','','','','".$details['pan']."','','','1','1','1','','1','')");
	echo "</pre>";

	$insert = mysqli_query($conn, "INSERT INTO `truck_mst`(`truck_code`, `truck_no`, `o_name`, `o_address`, `o_city`, `o_contact`, `o_pan`, `t_name`, `t_address`, `t_city`, `t_contact`, `t_pan`, `d_name`, `d_address`, `d_city`, `d_contact`, `lic_no`, `rto`, `tr_name`, `tr_address`, `tr_city`, `tr_contact`, `reference`, `remark`, `lorry_type`, `chasis_no`, `eng_no`, `per_no`, `from`, `up_to`, `insurance`, `branch`, `policy`, `height`, `weight`, `up_too`, `rc_no`, `rc_img`, `rc_img_back`, `pan_no`, `pan_img`, `dec_img`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$code."','".$details['truck']."','".$details['owner']."','".$details['address']."','".$details['city']."','','','".$details['transport']."','".$details['t_address']."','".$details['t_city']."','','','','','','','','','','','','','','','','".$details['chasis']."','".$details['engin']."','','','','','','','','','','','','','".$details['pan']."','','','1','1','1','','1','')");

	$check_act = "SELECT * FROM `act_master` WHERE `ac_name` = '".$details['owner']."'";
    $check_res = mysqli_query($conn,$check_act);
    $check_num = mysqli_num_rows($check_res);

    if($check_num == 0 ){
        $act_mst = "INSERT INTO `act_master`(`act_code`, `ac_name`, `dr_open_bal`, `cr_open_bal`, `account_group`, `party_code`, `branch_id`, `company_id`, `created_id`, `created_datetime`, `updated_id`, `updated_datetime`) VALUES ('".$act_code."','".$details['owner']."','0.00','0.00','SUNDRY CREDITORS','".$code."','1','1','1','','1','')";

        $act_res = mysqli_query($conn,$act_mst) or die( mysqli_error($conn) );    
    }
}
?>