<?php 
// require_once("../../includes/functions_internal_user_dryout.inc.php");

// include_once("../../includes/functions_internal_user_dryout.inc.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->funConnectMysqli();

// print_r($connect);
//$comid      = mysqli_real_escape_string($connect, $_REQUEST['comid']);
$auth_token = mysqli_real_escape_string($connect, $_REQUEST['auth_token']);

//  print_r($auth_token);die;

if($auth_token != "6obDl3xsdutQ2FreightInv")
{
    echo "Invalid Auth Token";die;
}
$arraydata = array();
// $sql_main = "select COMID from freight_cost_estimate_compare where STATUS > 0";
// $main_res = mysqli_query($connect, $sql_main);
// $i = 0;
// while($main_rows = mysqli_fetch_assoc($main_res))
// {
//     $comid = $main_rows['COMID'];
//     $arraydata[$i]['Voyage ID']                  = $obj->getCompareEstimateData($comid,"VOYAGE_NO");
//     $arraydata[$i]['Vessel Name']                = $obj->getVesselIMOData( $obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");
//     $arraydata[$i]['IMO No']                     = $obj->getVesselIMOData( $obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"IMO_NO");
    
//     $sql    = "select SHEET_NAME from cost_sheet_name_master where COST_SHEETID='".$obj->getCompareEstimateData($comid,"SHEET_NO")."'";
//     $result = mysqli_query($connect, $sql);
//     $rows   = mysqli_fetch_assoc($result);
    
//     $arraydata[$i]['Voyage Financial Name']      = $rows['SHEET_NAME'];
    
//     $cpdate = $obj->getCompareEstimateData($comid,"TRANS_DATE");
//     if($cpdate!="0000-00-00" && $cpdate!=""){$cpdate = date('Y-m-d',strtotime($cpdate));}else{$cpdate = "";}
    
//     $arraydata[$i]['CP Date']                    = $cpdate;
//     $arraydata[$i]['Business Type']              = "XXX";
    
//     $laycanstartdate = $obj->getCompareEstimateData($comid,"LAYCAN_START_DATE");
//     if($laycanstartdate!="0000-00-00" && $laycanstartdate!=""){$laycanstartdate = date('Y-m-d',strtotime($laycanstartdate));}else{$laycanstartdate = "";}
    
//     $arraydata[$i]['Start of Employement']       = $laycanstartdate;
    
//     $laycanenddate = $obj->getCompareEstimateData($comid,"LAYCAN_FINISH_DATE");
//     if($laycanenddate!="0000-00-00" && $laycanenddate!=""){$laycanenddate = date('Y-m-d',strtotime($laycanenddate));}else{$laycanenddate = "";}
    
//     $arraydata[$i]['End of Employment']          = $laycanenddate;
    
//     $charterers = '';
//     if($obj->getCompareEstimateData($comid,"ESTIMATE_TYPE")==2 && $rows['TANKER_RADIO_SINGLE_DIS']==2)
//     {
//         $vendor_arr = array();
//         $sql12 = "select SHIPPER_CHARTER, STATUS from freight_cost_estimete_slave10 where FCAID='".$obj->getCompareEstimateData($comid,"FCAID")."' group by SHIPPER_CHARTER";
//         $res12 = mysqli_query($connect, $sql12);
//         while($row12 = mysqli_fetch_assoc($res12))
//         {
//             if($row12['STATUS']==1 || $row12['STATUS']==2)
//             {
//                 $vendor_arr[]  = $row12['SHIPPER_CHARTER'];
//             }
//         }
//         $charterers = implode(',', $vendor_arr);
//     }
//     else
//     {
//         $charterers = $obj->getCompareEstimateData($comid,"LUMP_VENDOR");
//     }
//     $arraydata[$i]["Charterer's Name"]           = $charterers;
//     $arraydata[$i]['Currency']                   = $obj->getCompareEstimateData($comid,"VOYAGE_CURRENCY");
//     $arraydata[$i]['Status']                     = $obj->getCompareEstimateData($comid,"CREATED_UPDATED");
    
//     $arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid, $obj->getCompareEstimateData($comid,"FCAID"));
    
//     $lp_port = $dp_port = array();
//     for($ln=0;$ln<count($arr);$ln++){
//         $arr_explode = explode('@@',$arr[$ln]);
    
//         if($arr_explode[0] == 'LP'){
//             $lp_port[] = $obj->getPortUNLCODEBasedOnID($arr_explode[1]);
//         }
//         if($arr_explode[0] == 'DP'){
//             $dp_port[] = $obj->getPortUNLCODEBasedOnID($arr_explode[1]);
//         }
//     }
//     $arraydata[$i]['LP'] = implode(',',  $lp_port);
//     $arraydata[$i]['DP'] = implode(',',  $dp_port);
//     $i++;
// }













$sql = 'select * from freight_invoice_master where STATUS=5';
	$res = mysqli_query($connect,$sql);
	    $i=0;
	while($rows = mysqli_fetch_assoc($res)){


     

        // $i=1;



 

    // $sql_main = "select COMID from freight_cost_estimate_compare where STATUS > 0";
// $main_res = mysqli_query($connect, $sql_main);
// $i = 0;
// while($main_rows = mysqli_fetch_assoc($main_res))



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


	$arr       = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($rows['COMID'],$fcaid);

	$lp_name = array(); 
	$dp_name = array();
	$discharge_port = "";

	for($j=0;$j<count($arr);$j++)
	{   
		$arr_explode = explode('@@',$arr[$j]);
		if($arr_explode[0] == "LP" && $arr_explode[8]==''){$lp_name[]= $obj->shortPortNameWithCountry($obj->getPortNameBasedOnID($arr_explode[1]));}
		if($arr_explode[0] == "DP" && $arr_explode[8]==''){$dp_name[]= $obj->shortPortNameWithCountry($obj->getPortNameBasedOnID($arr_explode[1]));}
	}



	$lp_name  = implode(', ',$lp_name);
	$dp_name  = implode(', ',$dp_name);

	$sqlForQtyNRate = 'select BL_QTY_FREIGHT,FREIGHT_GROSS,COAID from
	freight_cost_estimete_master where FCAID="'.$fcaid.'" and COMID="'.$rows['COMID'].'" and MCOMPANYID="'.$_SESSION['company'].'" and MODULEID="'.$_SESSION['moduleid'].'"';


	$resForQtyNRate = mysqli_query($connect,$sqlForQtyNRate) or die($sqlForQtyNRate);

	$rowForQtyNRate = mysqli_fetch_assoc($resForQtyNRate);	

	if(!empty($rowForQtyNRate['COAID']) || $rowForQtyNRate['COAID']!=NULL){
			// echo '<h1>hi';
		$sql1 = "select * from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and STATUS=1";

		$res1 = mysqli_query($connect,$sql1) or die($sql1);

		$row1 = mysqli_fetch_assoc($res1);	

	}

	if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
	{
		
		$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
		$totalfreight = $row12['SUM3'];
		$freightrate = $row12['GAS_BASE_RATE'];
	}
	else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
	{
		
		$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
		$freightrate = $obj->getFun250();
		$maincargoid = $obj->getFun52();
		if($obj->getFun228()==1)
		 {
			 if($obj->getFun171()==1)
			 {
				 $totalfreight = $obj->getFun172();
				 $quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
			 }else
			 {
				 $res1_1 = mysqli_query($connect,"select * from freight_cost_estimete_slave12 where FCAID='".$obj->getFun1()."' and CUSTOMER = '".$rows['VENDOR']."' ");
				 $row1_1 = mysqli_fetch_assoc($res1_1);
				 $totalfreight = $row1_1['TOTAL_AMOUNT'];
				 $quantity = $row1_1['TOTAL_QTY'];
			 }
		 }else
		 {
			
			 $sql12 = "select CARGO_MT, AMOUNT_USD, CARGOID from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and RANDOMID='".$rows['RANDOMID']."' and STATUS=1";
			 $res12 = mysqli_query($connect,$sql12);
			 $row12 = mysqli_fetch_assoc($res12);
			 $quantity = $row12['CARGO_MT'];
			 
			 $totalfreight = $row12['AMOUNT_USD'];
			 $maincargoid = $row12['CARGOID'];
		 }
	}
	else
	{
		if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
		{
			
			// die($rows['COMID']);
			// echo 'dpk';
			$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
			$totalfreight = $obj->getCompareEstimateData($rows['COMID'],"TOTAL_PREIGHT_ADJ");
			// $freightrate = $obj->getCompareEstimateData($rows['COMID'],"FREIGHT_GROSS");

			if($rows['FREIGHT_RATE']!=NULL || $rows['FREIGHT_RATE']!=0.00){
					 $freightrate = $rows['FREIGHT_RATE'];

					// echo 'lp';
			}else{
				$freightrate = $obj->getCompareEstimateData($rows['COMID'],"FREIGHT_GROSS");

				// echo 'cp';
			}

			$maincargoid = $obj->getCompareEstimateData($rows['COMID'],"CARGO_ID");
		}
		else
		{

			$sql12 = "select QUANTITY, GROSS_FREIGHT, AGREED_GROSS_FREIGHT, CARGO from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and RANDOMID='".$rows['RANDOMID']."'";


			// echo $sql12;



			$res12 = mysqli_query($connect,$sql12) or die($sql12);
			$row12 = mysqli_fetch_assoc($res12);
			$quantity = $row12['QUANTITY'];
			$totalfreight = $row12['GROSS_FREIGHT'];
			$freightrate = $row12['AGREED_GROSS_FREIGHT'];
			$maincargoid = $row12['CARGO'];
		}
	}

	if($obj->getFun155()==2){ $f_rate =  $id[7].' USD/MT' ;}else if(!empty($rowForQtyNRate['COAID']) || $rowForQtyNRate['COAID']!=NULL){ $f_rate = $rowForQtyNRate['FREIGHT_GROSS'].' USD/MT'; }else{ $f_rate = $rowForQtyNRate['FREIGHT_GROSS'].' USD/MT';}

	$LPDem = $DPDesp = 0;

	for($jj=0;$jj<count($arr);$jj++)
	{
	    $arr_explode = explode('@@',$arr[$jj]);
		$psql = "select * from laytime_master where COMID='".$rows['COMID']."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$arr_explode[0]."' and PORTID='".$arr_explode[1]."' and RANDOMID='".$arr_explode[2]."'";
		$pres = mysqli_query($connect,$psql);
		while($prows = mysqli_fetch_assoc($pres))
		{
			
			$sql2 = "select * from freight_invoice_slave3 where INVOICEID='".$rows['INVOICEID']."' and PORT='".$arr_explode[0]."' and PORTID='".$arr_explode[1]."' and RANDOMID='".$arr_explode[2]."'";					
			$res21 = mysqli_query($connect,$sql2);
			while($rows21 = mysqli_fetch_assoc($res21))
			{

				$DebitDeMLedger = $rows21['VENDORID'];
				
			    if($rows21['DEM_AMT']>0)
				{

					$LPDem += $rows21['DEM_AMT'];
				}else{
			
					$DPDesp += $rows21['DEM_AMT'];

				}  
			
			}
			
		}
	}


	$sql_brok = "select * from freight_cost_estimete_slave4 where FCAID='".$fcaid."'";
									
	$res_brok = mysqli_query($connect,$sql_brok);
	$num_brok = mysqli_num_rows($res_brok);
	if($num_brok==0)
	{
		$BrokerageVendor='';

	}else{

		while($rows_brok = mysqli_fetch_assoc($res_brok))
		{

			$BrokerageVendor[]=explode(",",$rows_brok['VENDORID']);

		}
	}
	
	$sql_brok = "select * from freight_cost_estimete_slave4 where FCAID='".$fcaid."'";
									
	$res_brok = mysqli_query($connect,$sql_brok);
	$num_brok = mysqli_num_rows($res_brok);
	if($num_brok==0)
	{
		$BrokerageVendor='';

	}else{

		while($rows_brok = mysqli_fetch_assoc($res_brok))
		{
			
			
			
			$dynamicArray[$dynamicKey] = $dynamicValue;

		}
	}



	$sql_addadj = "select * from freight_invoice_adj_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD' and AMOUNT>0" ;
									
	
	// echo $sql_add;
	$res_addadj = mysqli_query($connect,$sql_addadj);
	$num_addadj = mysqli_num_rows($res_addadj);
	if($num_addadj==0)
	{
		// $resForSubAdd='';

	}else{
		$i=1;
		$k=1;

		$otherAddAdj[[]];

		while($resForAddadj = mysqli_fetch_assoc($res_addadj))
		{
			
			$otherAddAdj[]=array(

				"COST TYPE" => $resForAddadj['ORC_ID'],
				"FIXTURE NO"=> $resForAddadj['FIXTURE_NO'],
				"VESSEL"=>	$obj->getVesselIMOData($resForAddadj['VESSEL'],'VESSEL_NAME'),
				"DESCRIPTION"=> $resForAddadj['DESCRIPTION'],
				"AMOUNT"=> $resForAddadj['AMOUNT'],
	
			);

			$i++;

			$k++;

		}
	}




	$sql_lessadj = "select * from freight_invoice_adj_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0" ;
									
	
	// echo $sql_add;
	$res_lessadj = mysqli_query($connect,$sql_lessadj);
	$num_lessadj = mysqli_num_rows($res_lessadj);
	if($num_lessadj==0)
	{
		// $resForSubAdd='';

	}else{
		$i=1;
		$k=1;

		$otherLessAdj[[]];

		while($resForLessadj = mysqli_fetch_assoc($res_lessadj))
		{
			
			$otherLessAdj[]=array(
				"COST TYPE" => $resForLessadj['ORC_ID'],
				"FIXTURE NO"=> $resForLessadj['FIXTURE_NO'],
				"VESSEL"=>	 $obj->getVesselIMOData($resForLessadj['VESSEL'],'VESSEL_NAME'),
				"DESCRIPTION"=> $resForLessadj['DESCRIPTION'],
				"AMOUNT"=> $resForLessadj['AMOUNT'],
			);

			$i++;

			$k++;

		}
	}




	$sql111 = 'select sum(NET_AMOUNT) as netA from freight_invoice_master where COMID="'.$rows['COMID'].'" and I_TYPE="Interim"';
	$res111 = mysqli_query($connect,$sql111);
	$rows111 = mysqli_fetch_assoc($res111);

	// echo $sql111;

	// die();

	if($rows['I_TYPE']=='Final'){

		$balance = $rows['NET_AMOUNT']-$rows111['netA'];


	}else{

		$balance = 0;

	}


	$sql_add = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD' and AMOUNT>0" ;
									
	
	// echo $sql_add;
	$res_add = mysqli_query($connect,$sql_add);
	$num_add = mysqli_num_rows($res_add);
	if($num_add==0)
	{
		// $resForSubAdd='';

	}else{
		$i=1;
		$k=1;

		$otherAdd[[]];

		while($resForAdd = mysqli_fetch_assoc($res_add))
		{
			
			$otherAdd[]=array(



				"Cr_Code" => $resForAdd['ORC_ID'],
				"Cr_Amt"=> $resForAdd['AMOUNT'],

			);

			$i++;

			$k++;

		}
	}




	$sql_sub = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0" ;
									
	
	// echo $sql_add;
	$res_sub = mysqli_query($connect,$sql_sub);
	$num_sub = mysqli_num_rows($res_sub);
	if($num_sub==0)
	{
		// $num_sub='';

	}else{
		$i=1;
		$k=1;

		// $otherLess[[]];

		while($resForLess = mysqli_fetch_assoc($res_sub))
		{
			
			$otherLess[]=array(



				"Dr_Code" => $resForLess['ORC_ID'],
				"Dr_Amt" => $resForLess['AMOUNT'],

			);

			$i++;

			$k++;

		}
	}




	// print_r($otherAdd);

	// die();






	
	$totalDisDUm = $LPDem - $DPDesp;

	$array_json = [[

		"InvoiceId" => $rows['INVOICEID'],
		"voucherType" => "FREIGHT INVOICE RECEIPT",
		"InvoiceDate" => date('d-M-Y H:i:s', strtotime($rows['DATE'])),
		"InvoiceNo"=> $rows['MESSAGE'],
		"CreditLedger"=> "DI0006",

		"DebitLedger"=> $obj->getVendorListNewData($rows['VENDOR'],"CODE"),
		"VendorName"=> $obj->getVendorListNewData($rows['VENDOR'],"NAME"),
		"Fixtureno"=> $obj->getVoyageNoByComid($rows['COMID']),
		"VesselName"=>  $obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME"),
		"CPDate"=> date("d-m-Y",strtotime($obj->getFun3())),
		"LP"=> $lp_name,
		"DP"=> $dp_name,
		
		"FreightRate"=> $freightrate,
		"BLQTY"=> $quantity,
		"BLDate"=> date("d-m-Y",strtotime($rows['BL_DATE'])),
		"BLNo"=>  $rows['BL_NO'],
		"Unit"=>	"USD/MT",
		"Currency"=> "USD",
		"ExchCurrency"=> $rows['EXCHANGE_CURRENCY'],
        "ExchRate"=>  $rows['EXCHANGE_RATE'],
	
        "ExchDate"=> date("d-m-Y",strtotime($rows['EXCHANGE_DATE'])),
		"InvoiceType"=> $rows['I_TYPE'],
        "Attn"=>  $rows['ATTEN'],
        "PymtTerms"=> $rows['PAYMENT_TERMS'],
        "Description"=> $rows['REMARKS'],
		"GrossFreight"=> $freightrate*$quantity,
        "Percent"=> $rows['TO_1'],
        "LPDem"=> $LPDem,
        "DPDesp"=> $DPDesp,
        "CreditDemcode"=> "DI0003",
        "DebitDeMLedger"=>$DebitDeMLedger, 
        "DemNetAmt" => $totalDisDUm,
        "Brokerage"=> $rows['BROKERAGE'],
        "BrokerageVendor"=> implode(", ",$BrokerageVendor),  
        "BrokerDebitCode"=> "DE0006" ,


		"Gst_brokerage" => "GSTBR1",

		"GST_brk_Amount" => $rows['GST_ON_BROK'],

		"Addcomm"  => "DE0001",

		"Addcomm_amt" => $rows['ADDCOM_AMOUNT'],


		"AddAdj"   => $otherAddAdj,
		"otherAdd" => $otherAdd,
		"LessAdj"   => $otherLessAdj,
		
		"otherLess" => $otherLess,
		"balance"=>$balance,

		"totalAmt"=> $rows['NET_PAYABLE_TAX'],

		"objParticulars" => [[
			"accountErpID" => $rows2['BD_ID'],
			"accountName" => $rows2['NAME'],
			"accountAlias" => "",
			"accountAliasID" => "",
			"accountGroup" => "Bank Accounts",
			"accountDivision" => $rows2['BANK'],
			"accountAddLine1" => $rows2['ADDRESS'],
			"accountAddLine2" => "",
			"accountLandmark" => "",
			"accountCity" => "",
			"accountState" => "",
			"accountCountry" => "",
			"accountPincode" => "",
			"accountGstNo" => "",
			"accountPanNo" => "",
			"accountCinNo" => "",
			"accountContactName" => "",
			"accountMobile" => "91-6000000",
			"accountEmail" => "",
			"totalAmt" => $rows['P_AMT'],
			"billType" => 0
		]],

		"hasErrors" => false, 
		"errors" => null, 
		"errorCode" => null

	]];
    // "AddAdj"   => $otherAddAdj,


    // echo '<pre>';
	// $arraydata[$i]['Voyage ID']                  = $obj->getCompareEstimateData($comid,"VOYAGE_NO");
    // print_r($rows);

    // die();

    // [[

	// 	"InvoiceId" => $rows['INVOICEID'],
	// 	"voucherType" => "Receipt",
	// 	"InvoiceDate" => date('d-M-Y H:i:s', strtotime($rows['DATE'])),
	// 	"InvoiceNo"=> $rows['MESSAGE'],
	// 	"CreditLedger"=> "DI0006",

	// 	"DebitLedger"=> $obj->getVendorListNewData($rows['VENDOR'],"CODE"),
	// 	"VendorName"=> $obj->getVendorListNewData($rows['VENDOR'],"NAME"),
	// 	"Fixtureno"=> $obj->getVoyageNoByComid($rows['COMID']),
	// 	"VesselName"=>  $obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME"),
	// 	"CPDate"=> date("d-m-Y",strtotime($obj->getFun3())),
	// 	"LP"=> $lp_name,
	// 	"DP"=> $dp_name,
		
	// 	"FreightRate"=> $freightrate,
	// 	"BLQTY"=> $quantity,
	// 	"BLDate"=> date("d-m-Y",strtotime($rows['BL_DATE'])),
	// 	"BLNo"=>  $rows['BL_NO'],
	// 	"Unit"=>	"USD/MT",
	// 	"Currency"=> "USD",
	// 	"ExchCurrency"=> $rows['EXCHANGE_CURRENCY'],
    //     "ExchRate"=>  $rows['EXCHANGE_RATE'],
	
    //     "ExchDate"=> date("d-m-Y",strtotime($rows['EXCHANGE_DATE'])),
	// 	"InvoiceType"=> $rows['I_TYPE'],
    //     "Attn"=>  $rows['ATTEN'],
    //     "PymtTerms"=> $rows['PAYMENT_TERMS'],
    //     "Description"=> $rows['REMARKS'],
	// 	"GrossFreight"=> $freightrate*$quantity,
    //     "Percent"=> $rows['TO_1'],
    //     "LPDem"=> $LPDem,
    //     "DPDesp"=> $DPDesp,
    //     "CreditDemcode"=> "DI0003",
    //     "DebitDeMLedger"=>$DebitDeMLedger, 
    //     "DemNetAmt" => $totalDisDUm,
    //     "Brokerage"=> $rows['BROKERAGE'],
    //     "BrokerageVendor"=> implode(", ",$BrokerageVendor),  
    //     "BrokerDebitCode"=> "DE0006" ,


	// 	"Gst_brokerage" => "GSTBR1",

	// 	"GST_brk_Amount" => $rows['GST_ON_BROK'],

	// 	"Addcomm"  => "DE0001",

	// 	"Addcomm_amt" => $rows['ADDCOM_AMOUNT'],


	// 	"AddAdj"   => $otherAddAdj,
	// 	"otherAdd" => $otherAdd,
	// 	"LessAdj"   => $otherLessAdj,
		
	// 	"otherLess" => $otherLess,
	// 	"balance"=>$balance,

	// 	"totalAmt"=> $rows['NET_PAYABLE_TAX'],

	// 	"objParticulars" => [[
	// 		"accountErpID" => $rows2['BD_ID'],
	// 		"accountName" => $rows2['NAME'],
	// 		"accountAlias" => "",
	// 		"accountAliasID" => "",
	// 		"accountGroup" => "Bank Accounts",
	// 		"accountDivision" => $rows2['BANK'],
	// 		"accountAddLine1" => $rows2['ADDRESS'],
	// 		"accountAddLine2" => "",
	// 		"accountLandmark" => "",
	// 		"accountCity" => "",
	// 		"accountState" => "",
	// 		"accountCountry" => "",
	// 		"accountPincode" => "",
	// 		"accountGstNo" => "",
	// 		"accountPanNo" => "",
	// 		"accountCinNo" => "",
	// 		"accountContactName" => "",
	// 		"accountMobile" => "91-6000000",
	// 		"accountEmail" => "",
	// 		"totalAmt" => $rows['P_AMT'],
	// 		"billType" => 0
	// 	]],

	// 	"hasErrors" => false, 
	// 	"errors" => null, 
	// 	"errorCode" => null

	// ]];

    // $i++;
    echo json_encode($array_json);

}


// die();


?>