<?php
include('admin/config.php');
//include('code.php');


$officer=$_GET['admin'];
$bcode=$_GET['bcode'];

$date=date('Y-m-d');
$mon=date('m');
$yr=date('Y');

$sql =$link->query("select * from dailystockreport where BranchCode='$bcode' and date='$date'");
$num = mysqli_num_rows($sql);
		if($num<1){
		$result=$link->query("select * from items where BranchCode='$bcode'");
		$sq =$link->query("update login set status='YES' where usertype='Sales'");
				$prev=0;
				while($reply = mysqli_fetch_array($result)){
					$name=$reply['name'];
					$quan=$reply['quantity'];
					$retail=$reply['nprice'];
					$lar=$reply['lar'];
					$vsm=$reply['vsm'];
					$psn=$reply['psn'];
					$cost=$reply['cost'];
					
					$sql =$link->query("insert into dailystockreport values(0, '$bcode','$date','$name','$quan','0','0',$mon,$yr,'$officer')");
					$sql =$link->query("insert into summary values(0, '$bcode','$date','$name','0','$retail','0','$lar','0','$vsm','0','$psn',$mon,$yr,'$officer')");
					
				}
			OpenUnit1($link,$date,$bcode);
			//OpenUnit2($link,$date);	
			$sl =$link->query("update login set status='YES' where usertype='Sales'");
			echo "<script>alert('Stock Opened Succesfully')</script>";
			echo "<script>location='dashboard.php'</script>";
				
}else{
	
	echo "<script>alert('Stock Has Been Opened Today')</script>";
			echo "<script>location='dashboard.php'</script>";
}
//================================================================POINT 1==========================================================================================================



//================================================================POINT 1==========================================================================================================


?>