<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
if(!isset($_SESSION['is_login']) ){
header("location: login.php");
?>
<script>
window.location="login.php";
</script>
<?php
}

// $permission  = explode(',',$_SESSION['permission_id']);
// if(!in_array(19,$permission) && !in_array(1,$permission)  ){

// $op['is_success'] = false;
// $op['data'] 	  = "عذرا انت غير مخول للوصل الى هذه الصفحة";
// echo json_encode($op);
// exit;

// }

date_default_timezone_set($_SESSION['SYSTimezone']);


if (isset($_POST['type']) || isset($_GET['type'])){
		require("db_connect.php");

		


		if ($_POST['type']=="get_sell_date") {

			//$user_id = $_POST['cusid'];

			$res = $db->query("SELECT *
				FROM sell_item WHERE is_deleted = 0 ORDER BY created_at ASC LIMIT 1");
			if ($res) {				
				$op  = array();
				while ($row = $res->fetch_assoc()) {				   
						$result[0]  = $row['created_at'];						
						//array_push($op,$result);
						$dStart = new DateTime($row['created_at']);
				}

				$res = $db->query("SELECT *
				FROM sell_item WHERE is_deleted = 0 ORDER BY created_at DESC LIMIT 1");
				while ($row = $res->fetch_assoc()) {				   
						//$result[1]  = $row['created_at'];	
						$dEnd 			= new DateTime($row['created_at']);			
						//array_push($op,$result);
				}

				$dDiff = $dStart->diff($dEnd);
   			//echo $dDiff->format('%R'); // use for point out relation: smaller/greater
				$months = $dDiff->m;
				$day = $dDiff->d;
   			if($months == 0){
   					$op[0] = date('Y-m-d',strtotime($result[0]));
   			}else{
   				for($i=0;$i<$months;$i++){
   					$op[$i] = date('Y-m-d', strtotime("+".$i." months", strtotime($result[0])));
   				}
   			}
   			

				echo json_encode($op);
				exit;
			}else{
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_plans") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(P.plan_start_date)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(P.plan_start_date) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(P.plan_start_date) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(plan_id) AS total_price
					
					 			FROM plan P
								WHERE P.is_deleted = 0  $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}


		if ($_POST['type']=="get_total_visit") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_date)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.report_date) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.report_date) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(report_id) AS total_price
					
					 			FROM report R
								WHERE R.is_deleted = 0  $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_doctor_visit") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_date)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.report_date) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.report_date) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(report_id) AS total_price
					
					 			FROM report R
								WHERE R.is_deleted = 0 AND R.visit_type=0  $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_pharmacy_visit") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_date)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.report_date) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.report_date) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(report_id) AS total_price
					
					 			FROM report R
								WHERE R.is_deleted = 0 AND R.visit_type=1  $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_doctor") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.created_at)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.created_at) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.created_at) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(doctor_id) AS total_price
					
					 			FROM doctor R
								WHERE R.is_deleted = 0   $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_pharmacy") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.created_at)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.created_at) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.created_at) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(*) AS total_price
					
					 			FROM pharmacy R
								WHERE R.is_deleted = 0   $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_product") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.created_at)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.created_at) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.created_at) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(*) AS total_price
					
					 			FROM product R
								WHERE R.is_deleted = 0   $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_ordered_product") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_product_date)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.report_product_date) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.report_product_date) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	SUM(ordered_quantity) AS total_price
					
					 			FROM report_product_pharmacy R
								WHERE R.is_deleted = 0   $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_delivery") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_product_date)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.report_product_date) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.report_product_date) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(ordered_quantity) AS total_price
					
					 			FROM report_product_pharmacy R
								WHERE R.is_deleted = 0 AND R.is_delivered=2  $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_not_delivery") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_product_date)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.report_product_date) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.report_product_date) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(ordered_quantity) AS total_price
					
					 			FROM report_product_pharmacy R
								WHERE R.is_deleted = 0 AND R.is_delivered=0  $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_in_way") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_product_date)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.report_product_date) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.report_product_date) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(ordered_quantity) AS total_price
					
					 			FROM report_product_pharmacy R
								WHERE R.is_deleted = 0 AND R.is_delivered=1  $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}

		if ($_POST['type']=="get_total_saleman") {

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.created_at)  ='.$_POST['yy']:'';
			$cond_m = (isset($_POST['mm']) && $_POST['mm'] !='not')? ' AND MONTH(R.created_at) ='.$_POST['mm']:'';
			$cond_d = (isset($_POST['dd']) && $_POST['dd'] !='not')? ' AND DAY(R.created_at) ='.$_POST['dd']:'';

			$cond   = $cond_y . ' ' . $cond_m . ' ' . $cond_d;


			$res = $db->query("SELECT	COUNT(*) AS total_price
					
					 			FROM staff R
								WHERE R.is_deleted = 0 AND R.profile_type=1  $cond "); // all type
			
			if ($res) {				
				$op  = array();
				$row = $res->fetch_assoc();

				$result['total_price']  			= $row['total_price'];
					
				array_push($op,$result);

				echo json_encode($op);
				exit;
			}else{
				
				echo 0;
				exit;
			}
		}


		








		if ($_POST['type']=="get_pie_visit") {
			
			$reg_date = date("Y", time());
			

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_date)  	='.$_POST['yy']:'';
			

			$cond   = $cond_y ;

			if(strlen($cond) < 15){

				$cond = ' AND YEAR(R.report_date)  ='.$reg_date;
			
				$yyr 	= 	$reg_date;

			}else{
				$yyr 	= 	$_POST['yy'];

			}

			$city_id 	= 	$_POST['city_id'];
			

			if ($city_id > 0) {
				$cond .= ' AND R.city_id_fk  ='.$city_id;
				
			}

			
			$res = $db->query("SELECT

									count(*) AS no_of_orders,
									MONTH(R.report_date) AS montn_no,
									MONTHNAME(R.report_date) AS month_name
											
						
								FROM
								 report R
								
								 
							WHERE
								(R.is_deleted = 0  $cond )  GROUP BY MONTH(R.report_date)

					 "); // all type

			
			if ($res) {				
				$op  = array();
	
				while ($row = $res->fetch_assoc()) {				   
					$result['no_of_orders'] 			= $row['no_of_orders'];
					$result['montn_no']  				= $row['montn_no'];
					$result['month_name']  				= $row['month_name'];
					$result['year']  					= $yyr;								
					array_push($op,$result);
				}

				echo json_encode($op);
				exit;
			}else{
				
				echo $db->error;
				exit;
			}
		}



		if ($_POST['type']=="get_pie_ordered") {
			
			$reg_date = date("Y", time());
			
			$city_id 	= 	$_POST['city_id'];


			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(R.report_product_date)  	='.$_POST['yy']:'';
			

			$cond   = $cond_y ;

			if(strlen($cond) < 15){

				$cond = ' AND YEAR(R.report_product_date)  ='.$reg_date;
			
				$yyr 	= 	$reg_date;

			}else{
				$yyr 	= 	$_POST['yy'];

			}

			if ($city_id > 0) {
				$cond .= ' AND RP.city_id_fk  ='.$city_id;
				
			}

			
			$res = $db->query("SELECT

									count(*) AS no_of_orders,
									MONTH(R.report_product_date) AS montn_no,
									MONTHNAME(R.report_product_date) AS month_name,

									sum(ordered_quantity) AS final_price
											
						
								FROM
								 report_product_pharmacy R

								 LEFT JOIN report RP ON (RP.report_id = R.report_id_fk)
								
								 
							WHERE
								(R.is_deleted = 0   $cond )  GROUP BY MONTH(R.report_product_date)

					 "); // all type

			// echo $cond;
			if ($res) {				
				$op  = array();
	
				while ($row = $res->fetch_assoc()) {				   
					$result['no_of_orders'] 			= $row['no_of_orders'];
					$result['montn_no']  				= $row['montn_no'];
					$result['month_name']  				= $row['month_name'];
					$result['final_price']  			= round($row['final_price'],2);
					$result['year']  					= $yyr;								
					array_push($op,$result);
				}

				echo json_encode($op);
				exit;
			}else{
				
				echo $db->error;
				exit;
			}
		}




		if ($_POST['type']=="get_pie_expenses") {
			
			$reg_date = date("Y", time());
			

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(E.expenses_date)  	='.$_POST['yy']:'';
			

			$cond   = $cond_y ;

			if(strlen($cond) < 15){

				$cond = ' AND YEAR(E.expenses_date)  ='.$reg_date;
			
				$yyr 	= 	$reg_date;

			}else{
				$yyr 	= 	$_POST['yy'];

			}

			
			$res = $db->query("SELECT

									count(*) AS no_of_orders,
									MONTH(E.expenses_date) AS montn_no,
									MONTHNAME(E.expenses_date) AS month_name,

									sum(expenses_unit_price ) AS final_price
											
						
								FROM
								 expenses E
								
								 
							WHERE
								(E.is_deleted = 0  $cond )  GROUP BY MONTH(E.expenses_date)

					 "); // all type

			// echo $cond;
			if ($res) {				
				$op  = array();
	
				while ($row = $res->fetch_assoc()) {				   
					$result['no_of_orders'] 			= $row['no_of_orders'];
					$result['montn_no']  				= $row['montn_no'];
					$result['month_name']  				= $row['month_name'];
					$result['final_price']  			= round($row['final_price'],2);
					$result['year']  					= $yyr;								
					array_push($op,$result);
				}

				echo json_encode($op);
				exit;
			}else{
				
				echo $db->error;
				exit;
			}
		}



		if ($_POST['type']=="get_pie_purchase") {
			
			$reg_date = date("Y", time());
			

			$cond_y = (isset($_POST['yy']) && $_POST['yy'] !='not')? ' AND YEAR(P.purchase_date)  	='.$_POST['yy']:'';
			

			$cond   = $cond_y ;

			if(strlen($cond) < 15){

				$cond = ' AND YEAR(P.purchase_date)  ='.$reg_date;
			
				$yyr 	= 	$reg_date;

			}else{
				$yyr 	= 	$_POST['yy'];

			}

			
			$res = $db->query("SELECT

									count(*) AS no_of_orders,
									MONTH(P.purchase_date) AS montn_no,
									MONTHNAME(P.purchase_date) AS month_name,

									sum(cost_expenses * purchase_quantity) AS final_price
											
						
								FROM
								 purchase P , purchase_item PP
								
								 
							WHERE
								(PP.purchase_id_fk = P.purchase_id AND P.is_deleted = 0 AND PP.is_deleted = 0  $cond )  GROUP BY MONTH(P.purchase_date)

					 "); // all type

			// echo $cond;
			if ($res) {				
				$op  = array();
	
				while ($row = $res->fetch_assoc()) {				   
					$result['no_of_orders'] 			= $row['no_of_orders'];
					$result['montn_no']  				= $row['montn_no'];
					$result['month_name']  				= $row['month_name'];
					$result['final_price']  			= round($row['final_price'],2);
					$result['year']  					= $yyr;								
					array_push($op,$result);
				}

				echo json_encode($op);
				exit;
			}else{
				
				echo $db->error;
				exit;
			}
		}





		if ($_POST['type']=="get_user_sells") {
			$reg_date  =  date("Y-m-d", time());
			$yesterday = date('Y-m-d',strtotime("-1 days"));

			$res = $db->query("Select *   from  (SELECT sum(sell_item_quantity) as qty , sum(sell_item_quantity * item_sell_price_per_unit) AS total_price,sell_item.created_by,sell_date, staff.username, staff.full_name,profile_img  FROM sell_item LEFT JOIN staff ON (staff.staff_id = sell_item.created_by) where sell_item.is_deleted = 0 AND sell_date >= '$reg_date' GROUP By sell_item.created_by)  AS tmp ORDER By qty DESC
			 "); // all type

			$res1 = $db->query("Select *   from  (SELECT sum(sell_item_quantity) as qty , sum(sell_item_quantity * item_sell_price_per_unit) AS total_price,sell_item.created_by,sell_date, staff.username, staff.full_name,profile_img  FROM sell_item LEFT JOIN staff ON (staff.staff_id = sell_item.created_by) where sell_item.is_deleted = 0 AND sell_date >= '$yesterday' AND sell_date < '$reg_date' GROUP By sell_item.created_by)  AS tmp ORDER By qty DESC
			 "); // all type
			if ($res) {				
				$op  = array();


				while ($row = $res->fetch_assoc()) {				   
						$result[0]  = $row['qty'];
						$result[1]  = $row['total_price'];
						$result[2]  = $row['full_name'];
						$result[3]  = $row['username'];
						$result[4]  = $row['profile_img'];
						$result[5]  = '0';					
						array_push($op,$result);
				}

				while ($row = $res1->fetch_assoc()) {				   
						$result[0]  = $row['qty'];
						$result[1]  = $row['total_price'];
						$result[2]  = $row['full_name'];
						$result[3]  = $row['username'];
						$result[4]  = $row['profile_img'];
						$result[5]  = '1';					
						array_push($op,$result);
				}

				echo json_encode($op);
				exit;
			}else{
				
				echo $db->error;
				exit;
			}
		}










		if ($_POST['type']=="get_sell_date") {

			//$user_id = $_POST['cusid'];

			$res = $db->query("SELECT P.*,C.category,C.category_type,
				(SELECT sum(purchase_quantity) from purchase where purchase.product_id_fk = P.product_id AND purchase.is_deleted=0) as total_quantity,
				(SELECT sum(sell_quantity) from sell_item where sell_item.product_id_fk = P.product_id AND sell_item.is_deleted=0) as sold_quantity,
				(COALESCE((SELECT sum(COALESCE(purchase_quantity, 0)) from purchase where purchase.product_id_fk = P.product_id AND purchase.is_deleted=0),0)  -
					COALESCE((SELECT sum(COALESCE(sell_quantity, 0)) from sell_item where sell_item.product_id_fk = P.product_id AND sell_item.is_deleted=0),0) )  AS Remianed_quantity
				FROM product P, category C WHERE P.category_id_fk=C.category_id AND P.is_deleted = 0 AND C.category_type=0");
			if ($res) {
				//$row = $res->fetch_all();
				$op  = array();
				while ($row = $res->fetch_assoc()) {
				   
						$result[0]  = $row['product_id'];
						$result[1]  = $row['product'];
						$result[2]  = $row['part_number'];
						$result[3]  = $row['made_in'];
						$result[4]  = $row['sell_price'];
						$result[5]  = $row['sell_price_percentage'];
						$result[6]  = $row['average_price'];
						$result[7]  = $row['category_id_fk'];
						$result[8]  = $row['is_deleted'];
						$result[9]  = $row['created_at'];
						$result[10] = $row['updated_at'];
						$result[11] = $row['deleted_at'];
						$result[12] = $row['created_by'];
						$result[13] = $row['last_action'];
						$result[14] = $row['last_action_by'];
						$result[15] = $row['category'];
						$result[16] = $row['category_type'];
						$result[17] = $row['total_quantity'];
						$result[18] = $row['sold_quantity'];
						$result[19] = $row['Remianed_quantity'];
						array_push($op,$result);
				}
				echo json_encode($op);
				exit;
			}else{
				echo 0;
				exit;
			}
		}



	}
	else{
		header("Location:../");
		exit;
	}
?>
