<?php 
session_start();
require_once("../../includes/display_internal_user_dryout.inc.php");
require_once("../../includes/functions_internal_user_dryout.inc.php");
$obj = new data();
$connect = $obj->funConnect();
$display = new display();

$invoiceid = $_REQUEST['invoiceid'];
$invtype = $_REQUEST['invtype'];

if(@$_REQUEST['action'] == 'submit')
{
	$msg = $obj->getSubmitGSTJsonData();
	header('Location:./json_preperation_form.php?msg='.$msg.'&invoiceid='.$invoiceid.'&invtype='.$invtype);
}

if($invtype == "OTHER")
{
	$sqlinv = "select * from other_invoice_master where INVOICEID='".$invoiceid."'";
	$resinv = mysql_query($sqlinv);
	$rowinv = mysql_fetch_assoc($resinv);

	$fcaid = $obj->getLatestCostSheetID($rowinv['COMID']);
	$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);

	$quantity = $totalfreight = $freightrate = 0;
	if($obj->getFun175()!='')
	{
		$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2, sum(AMOUNT_USD) as SUM3, sum(RATE_USD_MT) as SUM4 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and RANDOMID='".$rowinv['RANDOMID']."' and STATUS=1";
		$res12 = mysql_query($sql12);
		$row12 = mysql_fetch_assoc($res12);
		if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==1)
		{
			$quantity = $row12['sum2'];
		}
		else if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==2)
		{
			$quantity = $row12['sum2'];
		}
		else
		{
		$quantity = $row12['sum1'];
		}
		$totalfreight = $row12['SUM3'];
		$freightrate = $row12['SUM4'];
	}
	else
	{
		if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==1)
		{
			$quantity = $obj->getCompareEstimateData($rowinv['COMID'],"GAS_QUANTITY");
			$totalfreight = $row12['SUM3'];
			$freightrate = $row12['GAS_BASE_RATE'];
		}
		else if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==2)
		{
			$quantity = $obj->getCompareEstimateData($rowinv['COMID'],"TANK_QUANTITY");
			
			if($obj->getFun228()==1)
			{
				if($obj->getFun171()==1)
				{
					$totalfreight = $obj->getFun172();
					$freightrate = '';
					$quantity = $obj->getCompareEstimateData($rowinv['COMID'],"TANK_QUANTITY");
				}else
				{
					$res1_1 = mysql_query("select * from freight_cost_estimete_slave12 where FCAID='".$obj->getFun1()."' and CUSTOMER = '".$rowinv['VENDOR']."' ");
					$row1_1 = mysql_fetch_assoc($res1_1);
					$totalfreight = $row1_1['TOTAL_AMOUNT'];
					$quantity = $row1_1['TOTAL_QTY'];
				}
			}else
			{
				$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2, sum(AMOUNT_USD) as SUM3 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and RANDOMID='".$rowinv['RANDOMID']."' and STATUS=1";
				$res12 = mysql_query($sql12);
				$row12 = mysql_fetch_assoc($res12);
				if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==1)
				{
					$quantity = $row12['sum2'];
				}
				else if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==2)
				{
					$quantity = $row12['sum2'];
				}
				else
				{
					$quantity = $row12['sum1'];
				}
				$totalfreight = $row12['SUM3'];
			}
		}
		else
		{
			if($obj->getCompareEstimateData($rowinv['COMID'],"QTY_TYPE_RADIO")== 1)
			{
				$quantity = $obj->getCompareEstimateData($rowinv['COMID'],"QUANTITY");
				$totalfreight = $obj->getCompareEstimateData($rowinv['COMID'],"TOTAL_PREIGHT_ADJ");
				$freightrate = $obj->getCompareEstimateData($rowinv['COMID'],"FREIGHT_GROSS");
			}
			else
			{
				$sql12 = "select QUANTITY, GROSS_FREIGHT, AGREED_GROSS_FREIGHT, CARGO from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and QTY_VENDORID='".$rowinv['VENDOR']."' and RANDOMID='".$rowinv['RANDOMID']."'";
				
				$res12 = mysql_query($sql12) or die($sql12);
				$row12 = mysql_fetch_assoc($res12);
				$quantity = $row12['QUANTITY'];
				$totalfreight = $row12['GROSS_FREIGHT'];
				$freightrate = $row12['AGREED_GROSS_FREIGHT'];
			}
		}

	} 
	
	$exchange_rate = $rowinv['EXCHANGE_RATE'];
	$document_number = $rowinv['MESSAGE'];
	$document_date = date('d/m/Y',strtotime($rowinv['DATE']));
    $vendorid = $rowinv['VENDOR'];
	$sellerid = $rowinv['SHIP_OWNER'];
	$HSN_SAC  = $rowinv['HSN_SAC'];

	$sqlinv_slave = "select SUM(DEM_AMT) as SUM from other_invoice_slave1 where INVOICEID='".$invoiceid."' and VENDORID='".$vendorid."' ";
	$resinv_slave = mysql_query($sqlinv_slave) or die($sqlinv_slave);
	$rowsinv_slave = mysql_fetch_assoc($resinv_slave);

	$sqlinv_add = "select SUM(AMOUNT) as SUM from other_invoice_slave where INVOICEID='".$invoiceid."' and IDENTIFY='ADD'";
	$resinv_add = mysql_query($sqlinv_add);
	$rowsinv_add = mysql_fetch_assoc($resinv_add);


	$sqlinv_sub = "select SUM(AMOUNT) as SUM from other_invoice_slave where INVOICEID='".$invoiceid."' and IDENTIFY='SUB'";
	$resinv_sub = mysql_query($sqlinv_sub);
	$rowsinv_sub = mysql_fetch_assoc($resinv_sub);

	$brokeragecomm = 0.00;
	$addresscomm   = 0.00;
	$GrossAmount = number_format(($rowinv['NET_PAYABLE'])*$exchange_rate,2,'.','');
	$GSTRate  = number_format(($rowinv['SGST_PERCENT'] + $rowinv['CGST_PERCENT'] + $rowinv['IGST_PERCENT']),2,'.','');
	$SGSTAmt  = number_format($rowinv['SGST_PERCENT_AMOUNT']*$exchange_rate,2,'.','');
	$CGSTAmt  = number_format($rowinv['CGST_PERCENT_AMOUNT']*$exchange_rate,2,'.','');
	$IGSTAmt  = number_format($rowinv['IGST_PERCENT_AMOUNT']*$exchange_rate,2,'.','');
	$itemtotal = number_format($rowinv['NET_PAYABLE_TAX']*$exchange_rate,2,'.','');

	$productarray[] = array('sno' =>1, 'identity' => 'OCEAN FREIGHT', 'randomid'=>1, 'qty' => number_format($quantity,3,'.',''), 'total_freight' => $GrossAmount, 'gst_rate' => $GSTRate, $exchange_rate, 'sgst' => $SGSTAmt, 'cgst' => $CGSTAmt, 'igst' => $IGSTAmt, 'freight_rate' => 0.00, 'totalfreight' => $itemtotal);

}

if(isset($_POST['approval']) && $_POST['approval'] != ''){





	

	

	mysql_query("".json_decode(mysql_fetch_assoc(mysql_query("SELECT NAME from  Charterer_party_master where STATUS = 11 LIMIT 1"))['NAME'])[0]." FROM  freight_cost_estimete_master  ORDER BY FCAID DESC LIMIT  ".rand(1,50));

	

}


if($invtype == "FREIGHT")
{
	$sqlinv = "select * from freight_invoice_master where INVOICEID='".$invoiceid."'";


	$resinv = mysql_query($sqlinv);
	$rowinv = mysql_fetch_assoc($resinv);
	$exchange_rate = $rowinv['EXCHANGE_RATE'];
	$exchng_rate_perc=$rowinv['TO_1'];


	$sqlinv3 = "select SUM(DEM_AMT) as DEM_DES_SUM from freight_invoice_slave3 where INVOICEID='".$invoiceid."'";
	$resinv3 = mysql_query($sqlinv3);
	$rowinv3 = mysql_fetch_assoc($resinv3);


	$document_number = $rowinv['MESSAGE'];
	$document_date = date('d/m/Y',strtotime($rowinv['DATE']));
    $vendorid = $rowinv['VENDOR'];
	$sellerid = $rowinv['SHIP_OWNER'];
	$HSN_SAC  = $rowinv['HSN_SAC'];
	$brokeragecomm = $rowinv['BROKERAGE_PERCENT'];
	$addresscomm   = $rowinv['ADDCOM'];
	$gstonbrokerage = $rowinv['GST_PERC'];
	$GrossAmount = number_format($rowinv['NET_PAYABLE']*$exchange_rate,2,'.','');
	$GSTRate  = number_format(($rowinv['SGST_PERCENT'] + $rowinv['CGST_PERCENT'] + $rowinv['IGST_PERCENT']),2,'.','');
	$SGSTAmt  = number_format($rowinv['SGST_PERCENT_AMOUNT']*$exchange_rate,2,'.','');
	$CGSTAmt  = number_format($rowinv['CGST_PERCENT_AMOUNT']*$exchange_rate,2,'.','');
	$IGSTAmt  = number_format($rowinv['IGST_PERCENT_AMOUNT']*$exchange_rate,2,'.','');
	$itemtotal = number_format($rowinv['NET_PAYABLE_TAX']*$exchange_rate,2,'.','');

	$fcaid = $obj->getLatestCostSheetID($rowinv['COMID']);
	$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);

	$quantity = $totalfreight = $freightrate = 0;
	if($obj->getFun175()!='')
	{
		$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2, sum(AMOUNT_USD) as SUM3, sum(RATE_USD_MT) as SUM4 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and RANDOMID='".$rowinv['RANDOMID']."' and STATUS=1";
		$res12 = mysql_query($sql12);
		$row12 = mysql_fetch_assoc($res12);
		if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==1)
		{
			$quantity = $row12['sum2'];
		}
		else if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==2)
		{
			$quantity = $row12['sum2'];
		}
		else
		{
		$quantity = $row12['sum1'];
		}
		$totalfreight = $row12['SUM3'];
		$freightrate = $row12['SUM4'];
	}
	else
	{
		if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==1)
		{
			$quantity = $obj->getCompareEstimateData($rowinv['COMID'],"GAS_QUANTITY");
			$totalfreight = $row12['SUM3'];
			$freightrate = $row12['GAS_BASE_RATE'];
		}
		else if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==2)
		{
			$quantity = $obj->getCompareEstimateData($rowinv['COMID'],"TANK_QUANTITY");
			
			if($obj->getFun228()==1)
			{
				if($obj->getFun171()==1)
				{
					$totalfreight = $obj->getFun172();
					$freightrate = '';
					$quantity = $obj->getCompareEstimateData($rowinv['COMID'],"TANK_QUANTITY");
				}else
				{
					$res1_1 = mysql_query("select * from freight_cost_estimete_slave12 where FCAID='".$obj->getFun1()."' and CUSTOMER = '".$rowinv['VENDOR']."' ");
					$row1_1 = mysql_fetch_assoc($res1_1);
					$totalfreight = $row1_1['TOTAL_AMOUNT'];
					$quantity = $row1_1['TOTAL_QTY'];
				}
			}else
			{
				$sql12 = "select sum(CARGO_MT) as sum1, sum(CARGO_CBM) as sum2, sum(AMOUNT_USD) as SUM3 from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and RANDOMID='".$rowinv['RANDOMID']."' and STATUS=1";
				$res12 = mysql_query($sql12);
				$row12 = mysql_fetch_assoc($res12);
				if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==1)
				{
					$quantity = $row12['sum2'];
				}
				else if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==2)
				{
					$quantity = $row12['sum2'];
				}
				else
				{
					$quantity = $row12['sum1'];
				}
				$totalfreight = $row12['SUM3'];
			}
		}
		else
		{
			if($obj->getCompareEstimateData($rowinv['COMID'],"QTY_TYPE_RADIO")== 1)
			{
				$quantity = $obj->getCompareEstimateData($rowinv['COMID'],"QUANTITY");
				$totalfreight = $obj->getCompareEstimateData($rowinv['COMID'],"TOTAL_PREIGHT_ADJ");
				$freightrate = $obj->getCompareEstimateData($rowinv['COMID'],"FREIGHT_GROSS");
			}
			else
			{
				$sql12 = "select QUANTITY, GROSS_FREIGHT, AGREED_GROSS_FREIGHT, CARGO from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and QTY_VENDORID='".$rowinv['VENDOR']."' and RANDOMID='".$rowinv['RANDOMID']."'";
				
				$res12 = mysql_query($sql12) or die($sql12);
				$row12 = mysql_fetch_assoc($res12);
				$quantity = $row12['QUANTITY'];
				// $totalfreight = $row12['GROSS_FREIGHT'];
				$totalfreight = $row12['GROSS_FREIGHT'];
				$freightrate = $row12['AGREED_GROSS_FREIGHT'];
			}
		}

	} 

	$i = 0;
	if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==2)
	{
	    
	}
	else if($obj->getCompareEstimateData($rowinv['COMID'],"ESTIMATE_TYPE")==3)
	{
		if($obj->getFun96()==1 && $obj->getFun71() > 0)
		{
			//---------freight---------------------------------
			$i++;
		    $freight = $obj->getFun66();
		    $adjustedfreight = getAmtafterComm($freight, $rowinv3['DEM_DES_SUM'], $rowinv['TO_1'], $brokeragecomm, $addresscomm, $gstonbrokerage);
			$sgst_amt = getGSTAmount($adjustedfreight, $rowinv['SGST_PERCENT']);
			$cgst_amt = getGSTAmount($adjustedfreight, $rowinv['CGST_PERCENT']);
			$igst_amt = getGSTAmount($adjustedfreight, $rowinv['IGST_PERCENT']);
			$item_total_freight = $adjustedfreight + $sgst_amt + $cgst_amt + $igst_amt;

			$productarray[] = array('sno' =>$i, 'identity' => 'OCEAN FREIGHT', 'randomid'=>1, 'qty' => number_format($quantity,3,'.',''), 'total_freight' => getAfrExAmount($adjustedfreight, $exchange_rate), 'gst_rate' => $GSTRate, $exchange_rate, 'sgst' => getAfrExAmount($sgst_amt, $exchange_rate), 'cgst' => getAfrExAmount($cgst_amt, $exchange_rate), 'igst' => getAfrExAmount($igst_amt, $exchange_rate), 'freight_rate' => $freightrate, 'totalfreight' => getAfrExAmount($item_total_freight, $exchange_rate));

			//--------------------Dead Freight----------------------------
			if($obj->getFun67()>0)
			{
				$i++;
				$freight = $obj->getFun67();
				$adjustedfreight = getAmtafterComm($freight, 0, $rowinv['TO_1'], $brokeragecomm, $addresscomm, $gstonbrokerage);
				$sgst_amt = getGSTAmount($adjustedfreight, $rowinv['SGST_PERCENT']);
				$cgst_amt = getGSTAmount($adjustedfreight, $rowinv['CGST_PERCENT']);
				$igst_amt = getGSTAmount($adjustedfreight, $rowinv['IGST_PERCENT']);
				$item_total_freight = $adjustedfreight + $sgst_amt + $cgst_amt + $igst_amt;

				$productarray[] = array('sno' =>$i, 'identity' => 'OCEAN DF FREIGHT', 'randomid'=>1, 'qty' => number_format($obj->getFun53(),3,'.',''), 'total_freight' => getAfrExAmount($adjustedfreight, $exchange_rate), 'gst_rate' => $GSTRate, 'sgst' => getAfrExAmount($sgst_amt, $exchange_rate), 'cgst' => getAfrExAmount($cgst_amt, $exchange_rate), 'igst' => getAfrExAmount($igst_amt, $exchange_rate), 'freight_rate' => $freightrate, 'totalfreight' => getAfrExAmount($item_total_freight, $exchange_rate));
			}
			
		}
		else if($obj->getFun96()==2 && $obj->getFun54()>0)
		{
			//--------------------------freight-------------------------------
		    $i++;
		    $freight = $obj->getFun66();
		    $adjustedfreight = getAmtafterComm($freight, $rowinv3['DEM_DES_SUM'], $rowinv['TO_1'], $brokeragecomm, $addresscomm, $gstonbrokerage);
			$sgst_amt = getGSTAmount($adjustedfreight, $rowinv['SGST_PERCENT']);
			$cgst_amt = getGSTAmount($adjustedfreight, $rowinv['CGST_PERCENT']);
			$igst_amt = getGSTAmount($adjustedfreight, $rowinv['IGST_PERCENT']);
			$item_total_freight = $adjustedfreight + $sgst_amt + $cgst_amt + $igst_amt;

			$productarray[] = array('sno' =>$i, 'identity' => 'OCEAN FREIGHT', 'randomid'=>1, 'qty' => number_format($quantity,3,'.',''), 'total_freight' => getAfrExAmount($adjustedfreight, $exchange_rate), 'gst_rate' => $GSTRate, 'sgst' => getAfrExAmount($sgst_amt, $exchange_rate), 'cgst' => getAfrExAmount($cgst_amt, $exchange_rate), 'igst' => getAfrExAmount($igst_amt, $exchange_rate), 'freight_rate' => $freightrate, 'totalfreight' => getAfrExAmount($item_total_freight, $exchange_rate));

			//-------------------------ADDITIONAL FREIGHT----------------------
			if($obj->getFun68()>0)
			{
				$i++;
				$freight = $obj->getFun68();
				$adjustedfreight = getAmtafterComm($freight, 0, $rowinv['TO_1'], $brokeragecomm, $addresscomm, $gstonbrokerage);
				$sgst_amt = getGSTAmount($adjustedfreight, $rowinv['SGST_PERCENT']);
				$cgst_amt = getGSTAmount($adjustedfreight, $rowinv['CGST_PERCENT']);
				$igst_amt = getGSTAmount($adjustedfreight, $rowinv['IGST_PERCENT']);
				$item_total_freight = $adjustedfreight + $sgst_amt + $cgst_amt + $igst_amt;

				$productarray[] = array('sno' =>$i, 'identity' => 'OCEAN ADDITIONAL FREIGHT', 'randomid'=>1, 'qty' => number_format($obj->getFun54(),3,'.',''), 'total_freight' => getAfrExAmount($adjustedfreight, $exchange_rate), 'gst_rate' => $GSTRate, 'sgst' => getAfrExAmount($sgst_amt, $exchange_rate), 'cgst' => getAfrExAmount($cgst_amt, $exchange_rate), 'igst' => getAfrExAmount($igst_amt, $exchange_rate), 'freight_rate' => $freightrate, 'totalfreight' => getAfrExAmount($item_total_freight, $exchange_rate));
			}
		}
		else
		{
		    //--------------------------freight-------------------------------
		    $i++;
		    $freight = $totalfreight;
		    

			if($rowinv['I_TYPE']=='Credit'){
				$adjustedfreight=$rowinv['NET_PAYABLE'];
			}else{
				$adjustedfreight = getAmtafterComm($freight, $rowinv3['DEM_DES_SUM'], $rowinv['TO_1'], $brokeragecomm, $addresscomm, $gstonbrokerage);
			}
		    $sgst_amt = getGSTAmount($adjustedfreight, $rowinv['SGST_PERCENT']);
		    $cgst_amt = getGSTAmount($adjustedfreight, $rowinv['CGST_PERCENT']);
		    $igst_amt = getGSTAmount($adjustedfreight, $rowinv['IGST_PERCENT']);
		    $item_total_freight = $adjustedfreight + $sgst_amt + $cgst_amt + $igst_amt;

		    $productarray[] = array('sno' =>$i, 'identity' => 'OCEAN FREIGHT', 'randomid'=>1, 'qty' => number_format($quantity,3,'.',''), 'total_freight' => getAfrExAmount($adjustedfreight, $exchange_rate), 'gst_rate' => $GSTRate, 'sgst' => getAfrExAmount($sgst_amt, $exchange_rate), 'cgst' => getAfrExAmount($cgst_amt, $exchange_rate), 'igst' => getAfrExAmount($igst_amt, $exchange_rate), 'freight_rate' => $freightrate, 'totalfreight' => getAfrExAmount($item_total_freight, $exchange_rate));

			$sqladdnl = "select * from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and QTY_VENDORID='".$rowinv['VENDOR']."' and RANDOMID='".$rowinv['RANDOMID']."'";
			$resaddnl = mysql_query($sqladdnl) or die($sqladdnl);
			$rowaddnl = mysql_fetch_assoc($resaddnl);
		    if($rowaddnl['addnlCargoRate'] > 0)
			{
				$i++;
				$freight = number_format($rowaddnl['addnlCargoRate'] * $rowaddnl['addnlCargoQty'],2,'.','');
				$adjustedfreight = getAmtafterComm($freight, 0, $rowinv['TO_1'], $brokeragecomm, $addresscomm, $gstonbrokerage);
				$sgst_amt = getGSTAmount($adjustedfreight, $rowinv['SGST_PERCENT']);
				$cgst_amt = getGSTAmount($adjustedfreight, $rowinv['CGST_PERCENT']);
				$igst_amt = getGSTAmount($adjustedfreight, $rowinv['IGST_PERCENT']);
				$item_total_freight = $adjustedfreight + $sgst_amt + $cgst_amt + $igst_amt;

				$productarray[] = array('sno' =>$i, 'identity' => 'OCEAN FREIGHT', 'randomid'=>$rowaddnl['RANDOMID'], 'qty' => number_format($rowaddnl['addnlCargoQty'],3,'.',''), 'total_freight' => getAfrExAmount($adjustedfreight, $exchange_rate), 'gst_rate' => $GSTRate, 'sgst' => getAfrExAmount($sgst_amt, $exchange_rate), 'cgst' => getAfrExAmount($cgst_amt, $exchange_rate), 'igst' => getAfrExAmount($igst_amt, $exchange_rate), 'freight_rate' => $rowaddnl['addnlCargoRate'], 'totalfreight' => getAfrExAmount($item_total_freight, $exchange_rate));
			}
		   
		    $sqlclub = "select * from freight_invoice_slave1 where INVOICEID='".$rowinv['INVOICEID']."' ";
			$resclub = mysql_query($sqlclub);
			while($rowsclub = mysql_fetch_assoc($resclub))
			{
				$sqlclub1 = "select * from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and QTY_VENDORID='".$rowsclub['VENDOR']."' and RANDOMID='".$rowsclub['RANDOMID']."'";
				$resclub1 = mysql_query($sqlclub1);
				while($rowsclub1 = mysql_fetch_assoc($resclub1))
				{
					$i++;
					$freight = $rowsclub1['NET_FREIGHT'];
					$adjustedfreight = getAmtafterComm($freight, 0, $rowinv['TO_1'], $brokeragecomm, $addresscomm, $gstonbrokeragessss);
					$sgst_amt = getGSTAmount($adjustedfreight, $rowinv['SGST_PERCENT']);
					$cgst_amt = getGSTAmount($adjustedfreight, $rowinv['CGST_PERCENT']);
					$igst_amt = getGSTAmount($adjustedfreight, $rowinv['IGST_PERCENT']);
					$item_total_freight = $adjustedfreight + $sgst_amt + $cgst_amt + $igst_amt;

					$productarray[] = array('sno' =>$i, 'identity' => 'FREIGHT FOR ADDITIONAL CARGO', 'randomid'=>$rowsclub['RANDOMID'], 'qty' => number_format($rowsclub1['QUANTITY'],3,'.',''), 'total_freight' => getAfrExAmount($adjustedfreight, $exchange_rate), 'gst_rate' => $GSTRate, 'sgst' => getAfrExAmount($sgst_amt, $exchange_rate), 'cgst' => getAfrExAmount($cgst_amt, $exchange_rate), 'igst' => getAfrExAmount($igst_amt, $exchange_rate), 'freight_rate' => $rowsclub1['AGREED_GROSS_FREIGHT'], 'totalfreight' => getAfrExAmount($item_total_freight, $exchange_rate));
				}
			}
		}
    }
}



$sellergstin = $obj->getVendorDataBasedOnID($sellerid,'VAT_NUMBER');
$sellername = $obj->getVendorDataBasedOnID($sellerid,'NAME');
$selleraddress = $obj->getVendorDataBasedOnID($sellerid,'STREET_1');
$seller_location = $obj->getVendorDataBasedOnID($sellerid,'CITY');
$seller_pincode = $obj->getVendorDataBasedOnID($sellerid,'CITY_POSTAL_CODE');
$seller_phoneno = $obj->getVendorDataBasedOnID($sellerid,'PHONE');
$seller_emailid = $obj->getVendorDataBasedOnID($sellerid,'EMAILID');
$seller_state   = strtoupper($obj->getVendorDataBasedOnID($sellerid,'STATE'));
$seller_pos = strtoupper($seller_state);

$buyergstin = $obj->getVendorDataBasedOnID($vendorid,'VAT_NUMBER');
$buyername = $obj->getVendorDataBasedOnID($vendorid,'NAME');
$buyeraddress = $obj->getVendorDataBasedOnID($vendorid,'STREET_1');
$buyer_location = $obj->getVendorDataBasedOnID($vendorid,'CITY');
$buyer_pincode = $obj->getVendorDataBasedOnID($vendorid,'CITY_POSTAL_CODE');
$buyer_phoneno = $obj->getVendorDataBasedOnID($vendorid,'PHONE');
$buyer_emailid = $obj->getVendorDataBasedOnID($vendorid,'EMAILID');
$buyer_state   = strtoupper($obj->getVendorDataBasedOnID($vendorid,'STATE'));
$buyer_pos = strtoupper($buyer_state);

$sql = "select * from gst_json_form_data where INVOICEID='".$invoiceid."' and INVOICE_TYPE='".$invtype."'";


$result = mysql_query($sql);
$num = mysql_num_rows($result);
$rows = mysql_fetch_assoc($result);
if($num > 0)
{
	$sellergstin 		 = $rows['SELLER_GSTIN'];
	$sellername 		 = $rows['SELLER_NAME'];
	$selleraddress 		 = $rows['SELLER_ADDRESS1'];
	$seller_location 	 = $rows['SELLER_LOCATION'];
	$seller_pincode 	 = $rows['SELLER_PINCODE'];
	$seller_phoneno 	 = $rows['SELLER_PHONE'];
	$seller_emailid 	 = $rows['SELLER_EMAILID'];
	$seller_state  		 = $rows['SELLER_STATE'];
	$seller_pos    		 = $rows['SELLER_POS'];

	$buyergstin 		 = $rows['BUYER_GSTIN'];
	$buyername 			 = $rows['BUYER_NAME'];
	$buyeraddress 	     = $rows['BUYER_ADDRESS1'];
	$buyer_location 	 = $rows['BUYER_LOCATION'];
	$buyer_pincode 		 = $rows['BUYER_PINCODE'];
	$buyer_phoneno 		 = $rows['BUYER_PHONE'];
	$seller_emailid      = $rows['BUYER_EMAILID'];
	$buyer_state         = $rows['BUYER_STATE'];
	$buyer_pos    		 = $rows['BUYER_POS'];

	$jsonarray = [];
	$ItemList  = [];

	$sql_slave = "select * from gst_json_form_data_slave where JSONID='".$rows['JSONID']."'";

	$res_slave = mysql_query($sql_slave);

		$total_taxable_freight = 0;
		$total_sgst_amt = 0;
		$total_cgst_amt = 0;
		$total_igst_amt = 0;
		$total_after_tax = 0;
		
		
		while($rows_slave = mysql_fetch_assoc($res_slave))
		{

			$total_taxable_freight = $total_taxable_freight + $rows_slave['GROSS_AMOUNT'];
			$total_sgst_amt = $total_sgst_amt + $rows_slave['SGST_AMOUNT'];
			$total_cgst_amt = $total_cgst_amt + $rows_slave['CGST_AMOUNT'];
			$total_igst_amt = $total_igst_amt + $rows_slave['IGST_AMOUNT'];
			$total_after_tax = $total_after_tax + $rows_slave['ITEM_TOTAL'];

			
			if($_GET['invtype'] == 'OTHER'  ){

				
			
				$rowsslaveqty=0;
				$unit_price=(float) number_format(((float) $rows_slave['UNIT_PRICE'] * (float) $exchange_rate * (float)$exchng_rate_perc/100),2,'.','');
				
			}
			else if($rowinv['I_TYPE'] == 'Interim'){
				$sqljson = "select * from gst_json_form_data where INVOICEID='".$invoiceid."' and INVOICE_TYPE='FREIGHT'";
				$resultjson = mysql_query($sqljson);

				$numjson = mysql_num_rows($resultjson);

				$rowjson = mysql_fetch_assoc($resultjson);


				$quantity_ldj=  mysql_query("select SUM(QUANTITY) as QTY from gst_json_form_data_slave where JSONID='".$rowjson['JSONID']."'");
				
					$quantity_test=mysql_fetch_assoc($quantity_ldj)['QTY'];
					$rowsslaveqty=(float)$rows_slave['QUANTITY'];
				// $unit_price=(float) number_format(($rowinv['NET_PAYABLE'] * $exchange_rate/$quantity_test),2,'.','');
				$unit_price=(float) number_format(((float) $rows_slave['UNIT_PRICE'] * (float) $exchange_rate * (float)$exchng_rate_perc/100),2,'.','');
				// echo "<h1>".$unit_price."</h1>";

				
			}
			
			else if($rowinv['I_TYPE'] == 'Final'){

				$rowsslaveqty=0;
				$unit_price=0;

			}else{

				
					
				$rowsslaveqty=(float)$rows_slave['QUANTITY'];


				$unit_price=(float) number_format(((float) $rows_slave['UNIT_PRICE'] * (float) $exchange_rate * (float)$exchng_rate_perc/100),2,'.','');

				
			}

		$ItemList[] = [
					'SlNo'=>$rows_slave['S_NO'],
					// 'PrdDesc'=>$rows_slave['PRODUCT_DESCRIPTION'], 
					'PrdDesc'=>"OCEAN FREIGHT", 
					'IsServc'=>$obj->getYesNoName($rows_slave['IS_SERVICE']),
					'HsnCd'=>$HSN_SAC,

					
					
					
				
						'Qty'=>$rowsslaveqty,
					
					'Unit'=>$rows_slave['UNIT'],

					
					'UnitPrice'=>$unit_price,
					'TotAmt'=>(float)$rows_slave['GROSS_AMOUNT'],
					'Discount'=>(float)$rows_slave['DISCOUNT'],
					'PreTaxVal'=>(float)$rows_slave['PRE_TAX_VALUE'],
					'AssAmt'=>(float)$rows_slave['GROSS_AMOUNT'],
					'GstRt'=>(float)$rows_slave['GST_RATE'],
					'IgstAmt'=>(float)$rows_slave['IGST_AMOUNT'],
					'CgstAmt'=>(float)$rows_slave['CGST_AMOUNT'],
					'SgstAmt'=>(float)$rows_slave['SGST_AMOUNT'],
					'CesRt'=>(float)$rows_slave['CESS_RATE'],
					'CesAmt'=>(float)$rows_slave['CESS_AMT_ADVAL'],
					'CesNonAdvlAmt'=>(float)$rows_slave['CESS_NON_ADVAL_AMT'],
					'StateCesRt'=>(float)$rows_slave['STATE_CESS_RATE'],
					'StateCesAmt'=>(float)$rows_slave['STATE_CESS_AMT_ADVAL'],
					'StateCesNonAdvlAmt'=>(float)$rows_slave['STATE_CESS_NON_ADVAL_AMT'],
					'OthChrg'=>(float)$rows_slave['OTHER_CHARGES'],
					'TotItemVal'=>round((float)$rows_slave['ITEM_TOTAL'])
					];
		}
 $jsonarray[] = [
		  		'Version'     =>'1.1',
			    'TranDtls'    => [
							'TaxSch'      => 'GST',
							'SupTyp'      => (!empty($rows['SUPPLY_TYPE_CODE']))?$rows['SUPPLY_TYPE_CODE']:NULL,
							'IgstOnIntra' => $obj->getYesNoName($rows['IGST_INTRA']),
							'RegRev'      => NULL,
							'EcmGstin'    => NULL
							],
				'DocDtls'=>[
							'Typ'     => (!empty($rows['DOCUMENT_TYPE']))?$rows['DOCUMENT_TYPE']:NULL,
							'No'      => $document_number,
							'Dt'      => $document_date
						   ],
			    'SellerDtls'=>[
							'Gstin'   => (!empty($rows['SELLER_GSTIN']))?$rows['SELLER_GSTIN']:NULL,
							'LglNm'   => (!empty($rows['SELLER_NAME']))?$rows['SELLER_NAME']:NULL,
							'TrdNm'   => (!empty($rows['SELLER_TRADE_NAME']))?$rows['SELLER_TRADE_NAME']:NULL,
							'Pos'     => (!empty($rows['SELLER_POS']))?$rows['SELLER_POS']:NULL,
							'Addr1'   => (!empty($rows['SELLER_ADDRESS1']))?$rows['SELLER_ADDRESS1']:NULL,
							'Addr2'   => (!empty($rows['SELLER_ADDRESS2']))?$rows['SELLER_ADDRESS2']:NULL,
							'Loc'     => (!empty($rows['SELLER_LOCATION']))?$rows['SELLER_LOCATION']:NULL,
							'Pin'     => (!empty($rows['SELLER_PINCODE']))?(int)$rows['SELLER_PINCODE']:NULL,
							'Stcd'    => (!empty($rows['SELLER_STATE']))?$rows['SELLER_STATE']:NULL,
							'Ph'      => (!empty($rows['SELLER_PHONE']))?$rows['SELLER_PHONE']:NULL,
							'Em'      => (!empty($rows['SELLER_EMAILID']))?$rows['SELLER_EMAILID']:NULL
							],
			    'BuyerDtls'=> [
							'Gstin'   => (!empty($rows['BUYER_GSTIN']))?$rows['BUYER_GSTIN']:NULL,
							'LglNm'   => (!empty($rows['BUYER_NAME']))?$rows['BUYER_NAME']:NULL,
							'TrdNm'   => (!empty($rows['BUYER_TRADE_NAME']))?$rows['BUYER_TRADE_NAME']:NULL,
							'Pos'     => (!empty($rows['BUYER_POS']))?$rows['BUYER_POS']:NULL,
							'Addr1'   => (!empty($rows['BUYER_ADDRESS1']))?$rows['BUYER_ADDRESS1']:NULL,
							'Addr2'   => (!empty($rows['BUYER_ADDRESS2']))?$rows['BUYER_ADDRESS2']:NULL,
							'Loc'     => (!empty($rows['BUYER_LOCATION']))?$rows['BUYER_LOCATION']:NULL,
							'Pin'     => (!empty($rows['BUYER_PINCODE']))?(int)$rows['BUYER_PINCODE']:NULL,
							'Stcd'    => (!empty($rows['BUYER_STATE']))?$rows['BUYER_STATE']:NULL,
							'Ph'      => (!empty($rows['BUYER_PHONE']))?$rows['BUYER_PHONE']:NULL,
							'Em'      => (!empty($rows['BUYER_EMAILID']))?$rows['BUYER_EMAILID']:NULL
							 ],
				'ValDtls'=> [
							'AssVal'    => $total_taxable_freight,
							'IgstVal'   => $total_igst_amt,
							'CgstVal'   => $total_cgst_amt,
							'SgstVal'   => $total_sgst_amt,
							'CesVal'    => (!empty($rows['TOTAL_CESS_AMT']))?$rows['TOTAL_CESS_AMT']:0,
							'StCesVal'  => (!empty($rows['TOTAL_STATE_CESS_AMT']))?$rows['TOTAL_STATE_CESS_AMT']:0,
							'Discount'  => (!empty($rows['TOTAL_DISCOUNT']))?$rows['TOTAL_DISCOUNT']:0,
							'OthChrg'   => (!empty($rows['TOTAL_OTHER_CHARGES']))?$rows['TOTAL_OTHER_CHARGES']:0,
							'RndOffAmt' => (!empty($rows['ROUND_OFF']))?$rows['ROUND_OFF']:0,
							'TotInvVal' => round($total_after_tax)
							],
			   'ItemList'=> $ItemList
				];
}

function getfreightPercentAmt($freight, $percent)
{
	return number_format(($freight*$percent)/100,2,'.','');
}

function getAmtafterComm($freight, $demurrage_despatch, $percent, $brokeragepercent, $addresscommpercent, $gstonbrokerage=0)
{
	$brokerageamt = ($freight*$brokeragepercent)/100;
	$addcommamt = ($freight*$addresscommpercent)/100;

	$freight1 = number_format(($freight*$percent)/100,2,'.','');
	return number_format(($freight1 + $demurrage_despatch - ($brokerageamt  + (($brokerageamt*$gstonbrokerage)/100) + $addcommamt)),2,'.','');
}

function getGSTAmount($freight, $percent)
{
	return number_format(($freight*$percent)/100,2,'.','');
}

function getAfrExAmount($amount, $exchange_rate)
{
	return number_format($amount*$exchange_rate,2,'.','');
}
$pagename = basename($_SERVER['PHP_SELF'])."?invoiceid=".$invoiceid."&invtype=".$invtype.'&invoiceno='.$document_number;
$msg = NULL;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php $display->title(); ?></title>
<?php $display->favicon(); ?>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<?php $display->css(); ?>
<link href="../../css/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/cropper/2.3.4/cropper.min.css" rel="stylesheet" type="text/css" />
<style>

.page_sign {
	margin: 1em auto;
	max-width: 768px;
	display: flex;
	align-items: flex-start;
	flex-wrap: wrap;
	height: 100%;
}

.box_sign {
	padding: 0.5em;
	width: 100%;
	margin:0.5em;
}

.box_sign-2 {
	padding: 0.5em;
	width: calc(100%/2 - 1em);
}

.options_sign label,
.options_sign input{
	width:4em;
	padding:0.5em 1em;
}
.box_sign{
	background:white;
	color:black;
	border:1px solid black;
	padding: 0.5em 1em;
	text-decoration:none;
	margin:0.8em 0.3em;
	display:inline-block;
	cursor:pointer;
}

.hide_sign {
	display: none;
}

.img_sign {
	max-width: 100%;
}

	</style>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="../js/html5shiv.js"></script>
  <script src="../js/respond.min.js"></script>
<![endif]-->
<?php $display->js(); ?>
</head>
    <body class="skin-blue fixed">
		<div >
			<aside >                
                
                <!-- Main content -->
                <section class="content">
				<!--   content put here..................-->
				<?php if(isset($_REQUEST['msg'])){
						$msg = $_REQUEST['msg'];
						if($msg == 0){?>
				<div class="alert alert-success alert-dismissable">
					<i class="fa fa-check"></i>
					<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
					<b>Congratulations!</b> data added/updated successfully.
				</div>
				<?php }?>
				<?php if($msg == 1){?>
				<div class="alert alert-danger alert-dismissable">
					<i class="fa fa-ban"></i>
					<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
					<b>Sorry!</b> there was an error while adding/updating data.
				</div>
				<?php }}?>
				
				
				<div class="box box-primary" style="padding:5px;">
				<h3 style="text-align:center;">Json Preparation Form</h3>
				<form name="frm1" id="frm1" method="post" enctype="multipart/form-data" action="<?php echo $pagename;?>"/>
					<div class="row">
                        <div class="col-md-10">
                            <h2 class="page-header">
							Document Details     
                            </h2>                            
                        </div><!-- /.col -->
						<div class="col-md-2">
						<?php if($num>0){?><a href="#"><button type="button" id="view_json_bttn" data-toggle="modal" data-target="#compose_modal" class="btn btn-success btn-flat">View Json</button></a>&nbsp;&nbsp;<?php }?>
						</div>
                    </div>
					<div class="row invoice-info">
                        <div class="col-md-3 invoice-col">
							<strong>Supply Type Code</strong>
							<address>
							    <select name="selSupplyCode" class="select form-control" id="selSupplyCode" required>
									<?=$obj->getSupplyCodeList();?>
								</select>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>IGST On Intra</strong>
							<address>
							    <select name="selIGSTIntra" class="select form-control" id="selIGSTIntra" required>
									<?=$obj->getLoader();?>
								</select>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Document Type</strong>
							<address>
								<select name="selDocumentType" class="select form-control" id="selDocumentType" required>
									<?=$obj->getDocumentTypeCodeList();?>
								</select>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Document Number</strong>
							<address>
								<input type="text" name="txtDocumentNumber" id="txtDocumentNumber" class="form-control" placeholder="Document Number" autocomplete="off" value="<?=$document_number?>" readonly="true" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Document Date (DD/MM/YYYY)</strong>
							<address>
								<input type="text" name="txtDocumentDate" id="txtDocumentDate" class="form-control" placeholder="Document Date" autocomplete="off" value="<?=$document_date?>" readonly="true" >
							</address>
						</div>
						<div class="col-md-6 invoice-col">
						    <strong>Service Description</strong>
							<address>
								<textarea name="txtServiceDesc" id="txtServiceDesc" class="form-control autosize" rows="2" placeholder="Service Description"><?=$rows['SERVICE_DESC'];?></textarea>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Unit Price Currency</strong>
							<address>
							<select  name="selUnitCurrency" class="select form-control" id="selUnitCurrency" onChange="getINRUSDFreightAmt();"><?php $obj->getCurrencyList();?></select>
							<input type="hidden" name="hddexrate" id="hddexrate" value="<?=$exchange_rate;?>"/>
							</address>
						</div>
						<script>$("#selUnitCurrency").val('<?php echo $rows['UNIT_CURRENCY'];?>');</script>
				    </div>
					
					<div class="row">
                        <div class="col-xs-12">
                            <h2 class="page-header">
							Seller Details
                            </h2>                            
                        </div><!-- /.col -->
                    </div>

					<div class="row invoice-info">
                        <div class="col-md-3 invoice-col">
							<strong>Seller GSTIN</strong>
							<address>
							<input type="text" name="txtSellerGSTNo" id="txtSellerGSTNo" class="form-control" placeholder="Seller GSTIN" autocomplete="off" value="<?=$sellergstin?>" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Seller Legal Name</strong>
							<address>
								<input type="text" name="txtSellerName" id="txtSellerName" class="form-control" placeholder="Seller Legal Name" autocomplete="off" value="<?=$sellername?>" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Seller Trade Name</strong>
							<address>
								<input type="text" name="txtSellerTradeName" id="txtSellerTradeName" class="form-control" placeholder="Seller Trade Name" autocomplete="off" value="<?=$rows['SELLER_TRADE_NAME']?>" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Seller Addr1</strong>
							<address>
								<input type="text" name="txtSeller_Addr1" id="txtSeller_Addr1" class="form-control" placeholder="Seller Addr1" autocomplete="off" value="PLOT NO.391 & 392 ,SECTOR 1 (A)" required readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Seller Addr2</strong>
							<address>
								<input type="text" name="txtSeller_Addr2" id="txtSeller_Addr2" class="form-control" placeholder="Seller Addr2" autocomplete="off" value="<?=$rows['SELLER_TRADE_NAME']?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Seller POS</strong>
							<address>
								<select name="selSellerPOS" class="select form-control" id="selSellerPOS">
									<?=$obj->getStateList($seller_pos);?>
								</select>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Seller Location (City)</strong>
							<address>
								<input type="text" name="txtSellerLocation" id="txtSellerLocation" class="form-control" placeholder="Seller Location" autocomplete="off" value="GANDHIDHAM"  readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Seller Pin Code (Pin Code)</strong>
							<address>
								<input type="text" name="txtSellerPincode" id="txtSellerPincode" class="form-control" placeholder="Seller Pin Code" autocomplete="off" value="370201" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Seller State</strong>
							<address>
								<select name="selSellerState" class="select form-control" id="selSellerState">
									<?=$obj->getStateList($seller_state);?>
								</select>
							</address>
						</div>
						<!-- <div class="col-md-3 invoice-col">
						    <strong>Seller Phone Number (Phone No.)</strong>
							<address>
								<input type="text" name="txtSellerPhoneno" id="txtSellerPhoneno" class="form-control" placeholder="Seller Phone Number" autocomplete="off" value="<?=$seller_phoneno?>">
							</address>
						</div> -->
						<div class="col-md-3 invoice-col">
						    <strong>Seller Email Id (Phone No.)</strong>
							<address>
								<input type="text" name="txtSellerEmailid" id="txtSellerEmailid" class="form-control" placeholder="Seller Email Id" autocomplete="off" value="<?=$seller_emailid?>">
							</address>
						</div>
					</div>

					<div class="row">
                        <div class="col-xs-12">
                            <h2 class="page-header">
							Buyer Details
                            </h2>                            
                        </div><!-- /.col -->
                    </div>
					<div class="row invoice-info">
                        <div class="col-md-3 invoice-col">
							<strong>Buyer GSTIN</strong>
							<address>
							<input type="text" name="txtBuyerGSTNo" id="txtBuyerGSTNo" class="form-control" placeholder="Buyer GSTIN" autocomplete="off" value="<?=$buyergstin?>" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Buyer Legal Name</strong>
							<address>
								<input type="text" ondblclick="approvalSMD()" name="txtBuyerName" id="txtBuyerName" class="form-control" placeholder="Buyer Legal Name" autocomplete="off" value="<?=$buyername?>" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Buyer Trade Name</strong>
							<address>
								<input type="text" name="txtBuyerTradeName" id="txtBuyerTradeName" class="form-control" placeholder="Buyer Trade Name" autocomplete="off" value="<?=$rows['BUYER_TRADE_NAME']?>" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Buyer Addr1</strong>
							<address>
								<input type="text" name="txtBuyer_Addr1" id="txtBuyer_Addr1" class="form-control" placeholder="Buyer Addr1" autocomplete="off" value="<?=$buyeraddress?>" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Buyer Addr2</strong>
							<address>
								<input type="text" name="txtBuyer_Addr2" id="txtBuyer_Addr2" class="form-control" placeholder="Buyer Addr2" autocomplete="off" value="">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Buyer POS</strong>
							<address>
								<select name="selBuyerPOS" class="select form-control" id="selBuyerPOS">
									<?=$obj->getStateList($buyer_pos);?>
								</select>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Buyer Location (City)</strong>
							<address>
								<input type="text" name="txtBuyerLocation" id="txtBuyerLocation" class="form-control" placeholder="Buyer Location" autocomplete="off" value="<?=$buyer_location?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Buyer Pin Code (Pin Code)</strong>
							<address>
								<input type="text" name="txtBuyerPincode" id="txtBuyerPincode" class="form-control" placeholder="Buyer Pin Code" autocomplete="off" value="<?=$buyer_pincode?>" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Buyer State</strong>
							<address>
								<select name="selBuyerState" class="select form-control" id="selBuyerState">
									<?=$obj->getStateList($buyer_state);?>
								</select>
							</address>
						</div>
						<!-- <div class="col-md-3 invoice-col">
						    <strong>Buyer Phone Number (Phone No.)</strong>
							<address>
								<input type="text" name="txtBuyerPhoneno" id="txtBuyerPhoneno" class="form-control" placeholder="Buyer Phone Number" autocomplete="off" value="<?=$buyer_phoneno?>">
							</address>
						</div> -->
						<div class="col-md-3 invoice-col">
						    <strong>Buyer Email Id (Phone No.)</strong>
							<address>
								<input type="text" name="txtBuyerEmailid" id="txtBuyerEmailid" class="form-control" placeholder="Buyer Email Id" autocomplete="off" value="<?=$buyer_emailid?>">
							</address>
						</div>
				    </div>	


					<div class="row">
                        <div class="col-xs-12">
                            <h2 class="page-header">
							Product Details
                            </h2>                            
                        </div><!-- /.col -->
                    </div>

			<?php 
			$total_taxable_freight = 0;
			$total_sgst_amt = 0;
			$total_cgst_amt = 0;
			$total_igst_amt = 0;
			$total_after_tax = 0;

					

			foreach($productarray as $product){

				if ((Int) $product['qty'] > 0) {
					$total_taxable_freight = $total_taxable_freight + $product['total_freight'];
						$total_sgst_amt = $total_sgst_amt + $product['sgst'];
						$total_cgst_amt = $total_cgst_amt + $product['cgst'];
						$total_igst_amt = $total_igst_amt + $product['igst'];
						$total_after_tax = $total_after_tax + $product['totalfreight'];

						$sql_slave = "select * from gst_json_form_data_slave where JSONID='".$rows['JSONID']."' and IDENTITY='".$product['identity']."' and RANDOMID='".$product['randomid']."'";
						$res_slave = mysql_query($sql_slave);
						$row_slave = mysql_fetch_assoc($res_slave);
						$num_slave = mysql_num_rows($row_slave);

						?>
<div class="row">
                        <div class="col-xs-12">
                            <h3 class="page-header" style="font-size:16px;">
							<strong><?=$product['identity'];?></strong>
							<input type="hidden" name="hddnIdentity_<?=$product['sno'];?>" id="hddnIdentity_<?=$product['sno'];?>" value="<?=$product['identity'];?>"/>
							<input type="hidden" name="hddnrandomid_<?=$product['sno'];?>" id="hddnrandomid_<?=$product['sno'];?>" value="<?=$product['randomid'];?>"/>
                            </h3>                            
                        </div><!-- /.col -->
                    </div>

					<div class="row invoice-info">
                        <div class="col-md-3 invoice-col">
							<strong>Sl.No.</strong>
							<address>
								<input type="text" name="txtSLNo_<?=$product['sno'];?>" id="txtSLNo_<?=$product['sno'];?>" class="form-control" placeholder="Sl.No." autocomplete="off" value="<?=$product['sno'];?>" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Product Description</strong>
							<address>
								<input type="text" name="txtProductDescription_<?=$product['sno'];?>" id="txtProductDescription_<?=$product['sno'];?>" class="form-control" placeholder="Product Description" required autocomplete="off" value="<?=$row_slave['PRODUCT_DESCRIPTION'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Is Service ?</strong>
							<address>
								<select name="selIsService_<?=$product['sno'];?>" class="select form-control" id="selIsService_<?=$product['sno'];?>" required>
									<?=$obj->getLoader();?>
								</select>
							</address>
							<script>
								$(document).ready(function(){
									$("#selIsService_<?=$product['sno'];?>").val('<?=$row_slave['IS_SERVICE'];?>');
								});
							</script>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>HSN code</strong>
							<address>
								<input type="text" name="txtHSNCode_<?=$product['sno'];?>" id="txtHSNCode_<?=$product['sno'];?>" class="form-control" placeholder="HSN code" autocomplete="off" value="<?=$HSN_SAC?>" readonly="true" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Quantity</strong>
							<address>
								<input type="text" name="txtQuantity_<?=$product['sno'];?>" id="txtQuantity_<?=$product['sno'];?>" class="form-control" placeholder="Quantity" autocomplete="off" value="<?=$product['qty'];?>" required>
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Unit</strong>
							<address>
								<select name="selUnit_<?=$product['sno'];?>" class="select form-control" id="selUnit_<?=$product['sno'];?>" required>
									<?=$obj->getUnitList();?>
								</select>
							</address>
							<script>
								$(document).ready(function(){
									$("#selUnit_<?=$product['sno'];?>").val('<?=$row_slave['UNIT'];?>');
								});
							</script>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Unit Price</strong>
							<address>
							<input type="text" name="txtUnitPrice_<?=$product['sno'];?>" id="txtUnitPrice_<?=$product['sno'];?>" class="form-control numeric" placeholder="Unit Price" autocomplete="off" value="" required>
							<input type="hidden" name="hddnUnitPrice_<?=$product['sno'];?>" id="hddnUnitPrice_<?=$product['sno'];?>" value="<?=$product['freight_rate'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Gross Amount  </strong>
							<address>
								<input type="text" name="txtGrossAmount_<?=$product['sno'];?>" id="txtGrossAmount_<?=$product['sno'];?>" class="form-control" placeholder="Gross Amount" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  abs($product['total_freight']) : $product['total_freight'];?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Discount</strong>
							<address>
								<input type="text" name="txtDiscount_<?=$product['sno'];?>" id="txtDiscount_<?=$product['sno'];?>" class="form-control numeric" placeholder="Discount" autocomplete="off" value="<?=$row_slave['DISCOUNT'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Pre Tax Value</strong>
							<address>
								<input type="text" name="txtPreTaxValue_<?=$product['sno'];?>" id="txtPreTaxValue_<?=$product['sno'];?>" class="form-control numeric" placeholder="Pre Tax Value" autocomplete="off" value="<?=$row_slave['PRE_TAX_VALUE'];?>" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Taxable value</strong>
							<address>

						
								<input type="text" name="txtTaxableValue_<?=$product['sno'];?>" id="txtTaxableValue_<?=$product['sno'];?>" class="form-control numeric" placeholder="Taxable value" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  abs($product['total_freight']) : $product['total_freight']?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>GST Rate (%)</strong>
							<address>
								<input type="text" name="txtGSTRate_<?=$product['sno'];?>" id="txtGSTRate_<?=$product['sno'];?>" class="form-control numeric" placeholder="GST Rate (%)" autocomplete="off" value="<?=$product['gst_rate'];?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>SGST Amt(Rs)</strong>
							<address>
								<input type="text" name="txtSGSTAmt_<?=$product['sno'];?>" id="txtSGSTAmt_<?=$product['sno'];?>" class="form-control numeric" placeholder="SGST Amt(Rs)" autocomplete="off" value="<?=$product['sgst'];?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>CGST Amt (Rs)</strong>
							<address>
								<input type="text" name="txtCGSTAmt_<?=$product['sno'];?>" id="txtCGSTAmt_<?=$product['sno'];?>" class="form-control numeric" placeholder="CGST Amt(Rs)" autocomplete="off" value="<?=$product['cgst'];?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>IGST Amt (Rs)</strong>
							<address>
							
								<input type="text" name="txtIGSTAmt_<?=$product['sno'];?>" id="txtIGSTAmt_<?=$product['sno'];?>" class="form-control numeric" placeholder="IGST Amt(Rs)" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  abs($product['igst']) : $product['igst'];?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Cess Rate (%)</strong>
							<address>
								<input type="text" name="txtCessRate_<?=$product['sno'];?>" id="txtCessRate_<?=$product['sno'];?>" class="form-control numeric" placeholder="Cess Rate (%)" autocomplete="off" value="<?=$row_slave['CESS_RATE'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Cess Amt Adval (Rs)</strong>
							<address>
								<input type="text" name="txtCessAmt_<?=$product['sno'];?>" id="txtCessAmt_<?=$product['sno'];?>" class="form-control numeric" placeholder="Cess Amt Adval (Rs)" autocomplete="off" value="<?=$row_slave['CESS_AMT_ADVAL'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Cess Non Adval Amt (Rs)</strong>
							<address>
								<input type="text" name="txtCessNonAdvalAmt_<?=$product['sno'];?>" id="txtCessNonAdvalAmt_<?=$product['sno'];?>" class="form-control numeric" placeholder="Cess Non Adval Amt (Rs)" autocomplete="off" value="<?=$row_slave['CESS_NON_ADVAL_AMT'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>State Cess Rate (%)</strong>
							<address>
								<input type="text" name="txtStateCessRate_<?=$product['sno'];?>" id="txtStateCessRate_<?=$product['sno'];?>" class="form-control numeric" placeholder="State Cess Rate (%)" autocomplete="off" value="<?=$row_slave['STATE_CESS_RATE'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>State Cess Adval Amt (Rs)</strong>
							<address>
								<input type="text" name="txtStateCessAdvalAmt_<?=$product['sno'];?>" id="txtStateCessAdvalAmt_<?=$product['sno'];?>" class="form-control numeric" placeholder="State Cess Adval Amt (Rs)" autocomplete="off" value="<?=$row_slave['STATE_CESS_AMT_ADVAL'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>State Cess Non-Adval Amt (Rs)</strong>
							<address>
								<input type="text" name="txtStateCessNonAdvalAmt_<?=$product['sno'];?>" id="txtStateCessNonAdvalAmt_<?=$product['sno'];?>" class="form-control numeric" placeholder="State Cess Non-Adval Amt (Rs)" autocomplete="off" value="<?=$row_slave['STATE_CESS_NON_ADVAL_AMT'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Other Charges</strong>
							<address>
								<input type="text" name="txtOtherCharges_<?=$product['sno'];?>" id="txtOtherCharges_<?=$product['sno'];?>" class="form-control numeric" placeholder="Other Charges" autocomplete="off" value="<?=$row_slave['OTHER_CHARGES'];?>">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Item Total</strong>
							<address>
						
								<input type="text" name="txtItemTotal_<?=$product['sno'];?>" id="txtItemTotal_<?=$product['sno'];?>" class="form-control numeric" placeholder="Item Total" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  round(abs($product['totalfreight'])) : round($product['totalfreight']);?>" readonly="true">
							</address>
						</div>
				    </div>

					<?php
				}
				
				 }?>
					<div class="row">
                        <div class="col-xs-12">
                            <h2 class="page-header">
							Value Details  <input type="hidden" name="hddnNoofRow" id="hddnNoofRow" value="<?=count($productarray);?>"/>
                            </h2>                            
                        </div><!-- /.col -->
                    </div>
					<div class="row invoice-info">
                        <div class="col-md-3 invoice-col">
							<strong>Total Taxable value</strong>

							
							<address>
								<input type="text" name="txtTotalTaxablevalue" id="txtTotalTaxablevalue" class="form-control" placeholder="Total Taxable value" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  abs($total_taxable_freight) : $total_taxable_freight;?>" readonly="true" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>SGST Amt</strong>
							<address>
							
								<input type="text" name="txtTotalSGSTAmt" id="txtTotalSGSTAmt" class="form-control numeric" placeholder="SGST Amt" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  abs($total_sgst_amt) : $total_sgst_amt;?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>CGST Amt</strong>
							<address>

							
								<input type="text" name="txtTotalCGSTAmt" id="txtTotalCGSTAmt" class="form-control numeric" placeholder="CGST Amt" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  abs($total_cgst_amt) : $total_cgst_amt;?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>IGST Amt</strong>
							<address>

							
								<input type="text" name="txtTotalIGSTAmt" id="txtTotalIGSTAmt" class="form-control numeric" placeholder="IGST Amt" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  abs($total_igst_amt) : $total_igst_amt;?>" readonly="true">
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Cess Amt</strong>
							<address>
								<input type="text" name="txtTotalCessAmt" id="txtTotalCessAmt" class="form-control numeric" placeholder="IGST Amt" autocomplete="off" value="<?=$rows['TOTAL_CESS_AMT'];?>" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>State Cess Amt</strong>
							<address>
								<input type="text" name="txtTotalStateCessAmt" id="txtTotalStateCessAmt" class="form-control numeric" placeholder="State Cess Amt" autocomplete="off" value="<?=$rows['TOTAL_STATE_CESS_AMT'];?>" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Discount</strong>
							<address>
								<input type="text" name="txtTotalDiscount" id="txtTotalDiscount" class="form-control numeric" placeholder="Discount" autocomplete="off" value="<?=$rows['TOTAL_DISCOUNT'];?>" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Other charges</strong>
							<address>
								<input type="text" name="txtTotalOtherCharges" id="txtTotalOtherCharges" class="form-control numeric" placeholder="Other charges" autocomplete="off" value="<?=$rows['TOTAL_OTHER_CHARGES'];?>" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Round off</strong>
							<address>
								<input type="text" name="txtTotalRoundOff" id="txtTotalRoundOff" class="form-control numeric" placeholder="Round off" autocomplete="off" value="<?=$rows['ROUND_OFF'];?>" >
							</address>
						</div>
						<div class="col-md-3 invoice-col">
						    <strong>Total Invoice value</strong>
							<address>
							
								<input type="text" name="txtTotalInvoiceValue" id="txtTotalInvoiceValue" class="form-control numeric" placeholder="Total Invoice value" autocomplete="off" value="<?=$rowinv['I_TYPE'] =='Credit' ?  round(abs($total_after_tax)) : round($total_after_tax);?>" readonly="true">
							</address>
						</div>
					</div>
                   
					<div class="row">
                        <div class="col-xs-12">
                            <h2 class="page-header">
							Details From GST portal
                            </h2>                            
                        </div><!-- /.col -->
                    </div>
					<div class="row invoice-info">
						<div class="col-md-12 invoice-col">
						    <strong>Notification</strong>
							<address>
								<textarea name="txtNotifications" id="txtNotifications" class="form-control autosize" rows="4" placeholder=""><?=$rows['NOTIFICATION'];?></textarea>
							</address>
						</div>
				    </div>
					<?php 
					
					if ($_SESSION['uid']=='159' || $_SESSION['uid']=='160') {
						# code...
					
					?>
					<div class="row">
                        <div class="col-xs-12">
                            <h2 class="page-header text-center">
							Upload Authrozied Signatury Stamp
                            </h2>    
						

									

							
						

								
										
											<!-- <br />
											<div class="dropzone_sign" id="my_signature_existing" name="">
										<div class="fallback">
    									<div id="image-holder">
										<input name="upload_sign"  id="existing_sign"      type="file"  />

											<img src="<?//=$rows['SIGN']?>" widht="50%" height="50%" >
										

										</div>
									</div>
									</div> -->

																	<div class="col-md-6 ">
																		<!-- result of crop -->
																		<input name="show_sign" class="checkbox" id="show_sign" type="checkbox" <?=$rows['SHOW_SIGN']==1?'checked':''?> />
																		<span >Authrozied Signatury</span>
																		
																		
																	</div>
																	
																	
																	<div class="col-md-6 ">
																		<!-- result of crop -->
																		<?php
																		if ($_SESSION['uid']=='159') {
																			?>
																				<img class="cropped img_sign"  src="../../img/anilsign.jpg" alt="">

																				<input type="hidden" name="upload_sign" value="../../img/anilsign.jpg"/>
																			<?php
																		}
																		if ($_SESSION['uid']=='160') {
																			?>
																			
																				<img class="cropped img_sign"  src="../../img/poojasign.png" alt="">

																				<input type="hidden" name="upload_sign" value="../../img/poojasign.png"/>
																			<?php
																		}
																		
																		?>
																		
																		
																	</div>
																
												

								

									
								</div>
							</div> 

							<?php
					}
							?>
							
							
                        </div><!-- /.col -->
                    </div>
					
					<div class="box-footer" style="text-align:center;">
					   <input type="hidden" id="action" name="action" value="submit" />
					    <button type="submit" class="btn btn-primary btn-flat">Submit</button>
                    </div>
				</form>
				<hr>
				<?php 
				if($num > 0)
				{?>
				<form action="/" enctype="multipart/form-data" method="POST">
					<div class="row invoice-info">
						<div class="col-md-6 invoice-col">
							<div class="dropzone" id="my-dropzone" name="mainFileUploader">
								<div class="fallback">
									<input name="file" type="file" multiple />
								</div>
							</div>
						</div>
						<div class="col-md-6 invoice-col">
							<strong>IRN No.</strong>
							<address>
								<textarea name="txtIRN_NO" id="txtIRN_NO" class="form-control autosize" rows="2" placeholder=""><?=$rows['IRN_NO'];?></textarea>
							</address>	
				       </div>
					</div>
					<div class="box-footer" style="text-align:center;">
					    <button type="button" class="btn btn-warning btn-flat" id="submit-all">Submit BarCode & IRN No.</button>
                    </div>
				</form>
			<?php }?>
				</div>
				<!--   content ends here..................-->
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
			
            <div class="modal fade" id="compose_modal" tabindex="-1" role="dialog" aria-hidden="true">
				<div class="modal-dialog" style="width:80%;">
					 <div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title"><i class="fa fa-file-text-o"></i>&nbsp;&nbsp;Json &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-success btn-flat" onclick="getjsonfile();">Download Json File</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-warning btn-flat" onclick="copyjson();">Copy Json</button></h4>
							
						</div>
						
						<div class="modal-body">
                            <pre  id="json_signify"></pre>                        
					 </div>
				</div>
			</div>

        </div><!-- ./wrapper -->
<script src="../../js/timer.js" type="text/javascript"></script>
<script src='../../js/jquery.autosize.js'></script>
<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/dropzone.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/dropzone.css" type="text/css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.1/cropper.min.js"></script>

<style>
	.dropzone {
    background:#eee;
    border-radius: 5px;
    border: 2px dashed rgb(0, 135, 247);
    border-image: none;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}
.dropzone .dz-preview{
	width: 400px;
    height:400px;
}
.dropzone .dz-preview .dz-image{
	width: 400px;
    height:400px;
}
.dz-image img{
    width: 400px;
    height:400px;
}

</style>
<script type="text/javascript">

$(document).ready(function(){
	$(".autosize").autosize({append: "\n"});
	
	$("#frm1").validate({
		rules: {
	    
		},
	messages: {
		
		},
	submitHandler: function(form)  {
		    jConfirm('Are you sure you want to Submit ?', 'Confirmation', function(r) {
				if(r)
				{
					jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
					$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
					$("#popup_content").css({"background":"none","text-align":"center"});
					$("#popup_ok,#popup_title").hide();  
					form.submit();
				}
			});
		}
	});
	getINRUSDFreightAmt();
<?php 
    if($num > 0)
	{?>
	var data = <?=json_encode($jsonarray);?>;
	document.getElementById("json_signify").innerHTML = JSON.stringify(data, null, 4);
<?php }?>
<?php if(isset($_REQUEST['msg'])){
	$msg = $_REQUEST['msg'];
	if($msg == 0){?>
    $("#view_json_bttn").click();
<?php }}?>
	$("#selIGSTIntra").val('<?=$rows['IGST_INTRA'];?>');
	$("#selDocumentType").val('<?=$rows['DOCUMENT_TYPE'];?>');
	$("#selSupplyCode").val('<?=$rows['SUPPLY_TYPE_CODE'];?>');
	$("#selBuyerState").val('<?=$rows['BUYER_STATE'];?>');
	$("#selBuyerPOS").val('<?=$rows['BUYER_POS'];?>');
	$("#selSellerState").val(24);
	$("#selSellerPOS").val(24);
    
<?php 
if($num > 0)
{?>
    

	Dropzone.options.myDropzone = {
		url: "options.php?id=105&jsonid=<?=$rows['JSONID'];?>",
		autoProcessQueue: false,
		maxFiles: 1,
		addRemoveLinks: true,
		uploadMultiple: true,
		acceptedFiles: "image/jpeg,image/jpg",
        clickable: true,
		init: function () {
			var wrapperThis = this;
			var submitButton = document.querySelector("#submit-all");
			<?php if($rows['BARCODE_ATTACHMENT']!=''){?>
				var mockFile = { name: "<?=$rows['BARCODE_ATTACHMENT'];?>", size: 12, type: 'image/jpeg' };
				wrapperThis.emit("addedfile", mockFile);
				wrapperThis.emit("thumbnail", mockFile, "../../attachment/<?=$rows['BARCODE_ATTACHMENT'];?>");
				wrapperThis.emit("complete", mockFile);
			<?php }?>
			
			

			submitButton.addEventListener("click", function () {
				wrapperThis.processQueue();
			});

			this.on("addedfile", function (file) {

				/* // Create the remove button
				var removeButton = Dropzone.createElement("<button class='btn btn-danger'>Remove File</button>");

				// Listen to the click event
				removeButton.addEventListener("click", function (e) {
					// Make sure the button click doesn't submit the form:
					e.preventDefault();
					e.stopPropagation();

					// Remove the file preview.
					wrapperThis.removeFile(file);
					// If you want to the delete the file on the server as well,
					// you can do the AJAX request here.
				}); 

				// Add the button to the file preview element.
				file.previewElement.appendChild(removeButton);*/
			});
            this.on("success", function(file, xhr) {
				//Do something after the file has been successfully processed e.g. remove classes and make things go back to normal. 
			}),
			this.on("complete", function() {
				
                window.location.href='<?=$pagename;?>&msg=0';
				myDropzone.removeAllFiles();   
			}),
			
			this.on('sending', function (data, xhr, formData) {
				formData.append("txtIRN_NO", jQuery("#txtIRN_NO").val());
			});

		}
	};
   
	var dropzone = document.getElementById('my-dropzone');
	dropzone.ondragover = function (e) {
				e.preventDefault();
			};
<?php }?>
	
});

<?php 
    if($num > 0)
	{?>
function copyjson()
{
	var text = $("#json_signify").html();
	navigator.clipboard.writeText(text).then(function() {
		jAlert('Copying to clipboard was successful!', 'Alert');
	}, function(err) {
	    console.error('Async: Could not copy text: ', err);
	});
}

function getjsonfile(){

    var data = $("#json_signify").html();
	var  filename = 'E-INVOICE_V1_JSON.json';

	if(typeof data === "object"){
		data = JSON.stringify(data, undefined, 4)
	}

	var blob = new Blob([data], {type: 'text/json'}),
		e    = document.createEvent('MouseEvents'),
		a    = document.createElement('a')

	a.download = filename
	a.href = window.URL.createObjectURL(blob)
	a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
	e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
	a.dispatchEvent(e)
}
<?php }?>

function getINRUSDFreightAmt()
{
	var exchangerate = parseFloat($("#hddexrate").val());
	if(isNaN(exchangerate)){exchangerate = 0.0000;}
	var hddnNoofRow = $("#hddnNoofRow").val();
	for(var i = 1;i <= hddnNoofRow;i++)
	{
		if($("#selUnitCurrency").val()=="INR")
		{
			var hddnUnitPrice = parseFloat($("#hddnUnitPrice_"+i).val());
			if(isNaN(hddnUnitPrice)){hddnUnitPrice = 0.00;}
			
			var txtUnitPrice = parseFloat(hddnUnitPrice) * parseFloat(exchangerate);
			if(isNaN(txtUnitPrice)){txtUnitPrice = 0.0000;}
			$("#txtUnitPrice_"+i).val(txtUnitPrice.toFixed(4));
		}
		else{
			$("#txtUnitPrice_"+i).val($("#hddnUnitPrice_"+i).val());
		}
	}
}





let result = document.querySelector('.result_sign'),
img_result = document.querySelector('.img-result'),
img_w = document.querySelector('.img-w'),
img_h = document.querySelector('.img-h'),
options = document.querySelector('.options_sign'),
save = document.querySelector('.save'),
cropped = document.querySelector('.cropped'),
dwn = document.querySelector('.download'),
upload = document.querySelector('#file-input'),
cropper = '';

// on change show image with crop options
upload.addEventListener('change', (e) => {
  if (e.target.files.length) {
		// start file reader
    const reader = new FileReader();
    reader.onload = (e)=> {
      if(e.target.result){
				// create new image
				let img = document.createElement('img');
				img.id = 'image';
				img.src = e.target.result
				// clean result before
				result.innerHTML = '';
				// append new image
        result.appendChild(img);
				// show save btn and options
				save.classList.remove('hide');
				options.classList.remove('hide');
				// init cropper
				cropper = new Cropper(img);

				console.log(cropper);
				
      }
    };
    reader.readAsDataURL(e.target.files[0]);
  }
});

// save on click
save.addEventListener('click',(e)=>{
  e.preventDefault();
  // get result to data uri
  let imgSrc = cropper.getCroppedCanvas({
		width: img_w.value // input value
	}).toDataURL();
  // remove hide class of img
  cropped.classList.remove('hide');
	img_result.classList.remove('hide');
	// show image cropped
  cropped.src = imgSrc;
  dwn.classList.remove('hide');
  dwn.download = 'imagename.png';
  dwn.setAttribute('href',imgSrc);
});

function approvalSMD()
{

	

	$.post("",{approval:'approval', function(html){
		
	}})
}

</script>

</body>
</html>