<?php
ini_set('memory_limit', '-1');
	require_once("../include/config.php");	
	require_once("../include/startup.php");
	require_once("../include/tax_related_functions.php");
	require_once("../include/classes/alltables.class.php");

	$obj  = new Product();
	
	$data = array();
	$quantity 			= $_POST['totalquantity'];

	$fromcompanyid 	= $_POST['fromcompanyid'];
	$tocompanyid 	= $_POST['tocompanyid'];

	$itemno  = $_POST['values'];
	
	$sqltext_company_statecode = "Select * from user_company  where isdeleted = 0 and membercompanyid = $fromcompanyid ";
	$statecode = $obj-> getProduct('',$sqltext_company_statecode);
	
	$statecode		= $statecode[0]['head_Stateid1'];
	
	
	
	$sqltext = "Select * from mstproducts  where isdeleted = 0 and  itemno = '".strtoupper($itemno)."' and membercompanyid = $fromcompanyid order by Product_ID desc";
	//echo $sqltext;
	//echo json_encode($sqltext);
	//exit;
	$row = $obj-> getProduct('',$sqltext);
	if(is_array($row))
	{
		$rowcount =count($row);
	}
	$total1 = 0;
	if($tocompanyid > 0)
	{
		$taxtype = CheckTypeOfGST($tocompanyid,$statecode);
	}
	else 
	{
		$taxtype = 'IGST';
	}
//	echo json_encode($taxtype);
	for($i=0;$i<$rowcount;$i++)
	{
		$total = $row[$i]['price'] ;
		$productid = $row[$i]['Product_ID'];
		$totalamt = $total * $quantity;   
		$taxcal  = TaxCalculation($totalamt,$productid,$taxtype);
		$total1	=  $taxcal['total_amount_with_tax']; 
		$cgst		=  $taxcal['cgstamt']; 
		$sgst		=  $taxcal['sgstamt']; 
		$igst		=  $taxcal['igstamt']; 
		$name = $total1.'|'.$quantity.'|'.$cgst.'|'.$sgst.'|'.$igst;
		array_push($data, $name);
	}	
	echo json_encode($data);
?>
