<?php
  include "include/dbcon.php";
  include "include/CPRODUCT.php";
  include "include/CORDER.php";
?>
<?php
  for($i=0;$i<10;$i++){
    $tid = ($i+1);
    $arrProId[$i] = $tid;
	$myPro[$tid] = new PRODUCT();
	$myPro[$tid]->setProduct("id",$tid);
  }
?>
<?php
  $qorder = "SELECT MAX(billno) as bilno FROM tb_order";
  $rorder = mysqli_query($conn,$qorder);
  while($myrow = mysqli_fetch_array($rorder)){
    $bilno = $myrow["bilno"];
  }
?>
<?php
  $tdate = "2021-08-08";
  $tsdate = strtotime($tdate);
  $numCus = rand(1,5);
  $bilno++;
  
  for($icus=0;$icus<$numCus;$icus++){
    $tnumPro = rand(1,5);
	echo "<br><br>Customer $icus<br>";
	$ordertotal = 0;
	for($ipro=0;$ipro<$tnumPro;$ipro++){
	  $tproid = rand(1,10);
	  $tpname = $myPro[$tproid]->name;
	  $tprice = $myPro[$tproid]->price;
	  $tqtty = rand(1,3);
      $ttotal = $tprice * $tqtty;
	  $ordertotal = $ordertotal+$ttotal;
	  $queryi = "INSERT INTO tb_orderitem VALUES(null,'$bilno','$tproid','$tqtty','$tprice')";
	  echo $queryi . "<br>";
	}
	
	$queryo = "INSERT INTO tb_order VALUES (null,'$tsdate','$tdate','$bilno','$ordertotal')";
	echo $queryo . "<br>";
	$bilno++;
  }
?>