<?php


session_start();
require_once("../../includes/Numbertowordconversion.php");
require_once("../../includes/Numbertowordconversion_inr.php");
require_once("../../includes/functions_internal_user_dryout.inc.php");
require_once('../../includes/fpdf_protection.php');



@$i = $_REQUEST['id'];
$ret = "";
switch ($i)
{
    case 1:

        $ret = getFreightPdf();
				break;
    case 2:

        $ret = create_TC_hire_pdf();
				break;
    case 3:

        $ret = getFreightPdf_old();
				break;

	case 4:
		$ret = otherInvoicePdf();
		break;
    case 5:
		$ret = getFreightINRPdf();
		break;

	case 6:
		$ret = getOtherINRPdf();
		break;



	default:

		    //$ret = funError();
				//echo $ret;
				break; 				
}


function otherInvoicePdf()
{




				$obj = new data();
				$amttoword = new Numbertowordconversion();
				$obj->funConnect();

		// changing
		// $im_id = $_GET['im_id'];
		// echo $im_id;

				// $im_id = $_REQUEST['im_id'];
				$pdfpassword = $_REQUEST['pdfpassword'];
				// // $comid = $_REQUEST['comid'];
				$_SESSION['invoiceid'] = $_REQUEST['im_id'];




	$sql = "select * from other_invoice_master where INVOICEID='".$_REQUEST['im_id']."'";
		// echo '<pre>';
		// echo $sql;


		$res = mysql_query($sql);
		$rows = mysql_fetch_assoc($res);
		$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
		$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
		$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);

		// print_r($rows);


		$_SESSION['companyname']        =  $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME");
		$_SESSION['companyaddress']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1");
		$_SESSION['companycity']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY");
		$_SESSION['companycountry']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY");
		$_SESSION['companycode']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE");
		$_SESSION['companyemail']       = $obj->getVendorListNewData($rows['SHIP_OWNER'],"EMAILID");
		$_SESSION['companytel']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PHONE");
		$_SESSION['companyvat']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
		$_SESSION['footeraddr']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
		$_SESSION['vendorlogo']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");
		$SESSION['TRN_NO']              = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");

		// print_r($_SESSION);
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			if($rows['RDOVATGST'] == 1)
			{
				$_SESSION['taxno2'] = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}else{
				$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}
		}else{
			$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) :';
		}
		
		$vlsImoId 						= $obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID");
		
		// exit;
	class PDF extends FPDF_Protection
	{
		function Header()
		{
			$image_path1 = '../../img/'.$_SESSION['vendorlogo'];
			
			$this->Image($image_path1,10,2,190,26);
			$this->AddFont("daxcondensedlight",'',"daxcondensedlight.php");
			
			$this->SetY(24);
			
		}
			
		function Footer()
		{
			$this->SetY(-20);
			$this->SetFillColor(255,255,255);
			$this->SetTextColor(177,175,175);
			// $this->SetFont('Arial','',10);     villian
			$this->SetX(0);
			
			$this->Ln(1);
			$this->AddFont("daxcondensedlight",'',"daxcondensedlight.php");
			$this->SetFont('daxcondensedlight','',12);
			$this->SetTextColor(027,119,166);
			$this->Ln(1);
			$this->Cell(0,5,$_SESSION['companyname'],0,1,'C');
			$this->Ln(1);
			$this->SetFont('daxcondensedlight','',9);
			$this->Cell(0,4,$_SESSION['footeraddr'],0,1,'C');
			$this->Cell(0,4,"Tel: ".$_SESSION['companytel']."  email: ".$_SESSION['companyemail'],0,1,'C');
		}
	}	
		

						$sql = "select * from other_invoice_master where INVOICEID='".$_REQUEST['im_id']."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
	$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
	$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);

	$lp_name = array(); 
	$dp_name = array();
	
	
	if($rows['I_TYPE']=='Credit'){
		$invtitle = 'Credit Note';
		$invtitleType = 'Credit Note';
		$inv_amt_title = 'to Credit';
	}else{
		$invtitle = 'Invoice';
		if($rows['I_TYPE']=='Interim'){$invtitleType = 'INITIAL INVOICE';}else{$invtitleType = 'FINAL INVOICE';}
		$inv_amt_title = 'Invoiced';
	}
	
	$discharge_port = "";
	
	for($j=0;$j<count($arr);$j++)
	{   
		$arr_explode = explode('@@',$arr[$j]);
		if($arr_explode[0] == "LP"){$lp_name[]= $obj->getPortNameBasedOnID($arr_explode[1]);}
		if($arr_explode[0] == "DP"){$dp_name[]= $obj->getPortNameBasedOnID($arr_explode[1]);}
	}
	
	$lp_name  = implode(', ',$lp_name);
	$dp_name  = implode(', ',$dp_name);
	
	if($obj->getFun175()!='')
	{
		$sqlcoa = "select * from coa_master where COAID='".$obj->getFun175()."'";
		$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
		$rowscoa   = mysql_fetch_assoc($resultcoa);
		$currency = $rowscoa['CURRENCY'];
	}else
	{
		$currency = 'USD';
	}
	
	$pdf = new PDF();

	$pdf->SetProtection(array('print'),$pdfpassword);
	$pdf->AddPage('P');
	$pdf->SetDisplayMode('real','single');
	$pdf->SetTitle('Generate Other '.$invtitle.' Pdf');
	$pdf->SetAuthor('Seven Oceans Holdings');
	$pdf->SetSubject('Generate Other '.$invtitle.' Pdf');
	$pdf->SetKeywords('Designed and Developed By Seven Oceans Holdings pvt. Ltd.');
	
	
	$pdf->Ln(10);
	
	$pdf->Ln(1);
	
	$pdf->SetFont('daxcondensedlight','',15);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C');
	$arr2=array(190);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	if(strpos($rows['P_TYPE'], "Demurrage/Dispatch") !== false) 
	{
	    $pdf->Row(array(strtoupper('Demurrage/Dispatch')));
	}
	elseif($invtitle=='Credit Note'){
		$pdf->Row(array($rows['PDFHEAD']));
	}
	
	else
	{
		$pdf->Row(array($rows['PDFHEAD']));
	}
	
	
	$initialY =  $pdf->GetY();
	
	$pdf->SetFont('daxcondensedlight','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L');
	$arr2=array(120,70);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$invdate = date('d-m-Y',strtotime($rows['DATE'])); if($invdate=='01-01-1970'){$invdate = '';}
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
	    if($rows['RDOVATGST'] == 1)
	    {
			$taxno1 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
			$taxno2 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}else{
			$taxno1 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
			$taxno2 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}
	}else{
	     $taxno1 = '';
		 $taxno2 = '';
	}
	
	if($obj->getVendorListNewBasedOnID($rows['VENDOR'])){
		$pdf->Row1(array("M/S. ".$obj->getVendorListNewBasedOnID($rows['VENDOR']),''));
		}
	
		if($obj->getVendorDataBasedOnID($rows['VENDOR'],'STREET_1') && $obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY') && $obj->getVendorDataBasedOnID($rows['VENDOR'],'COUNTRY')) {
			$pdf->Row1(array(stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'STREET_1')).",".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY')).", ".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'COUNTRY')).", ".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY_POSTAL_CODE'))."\n ".$taxno1,$invtitle.' No. :'.$rows['MESSAGE']."\n".$invtitle." Date : ".$invdate."\n"."REF NO : ".$rows['REF_NO']."\n".'TRN NO:'.$SESSION['TRN_NO']));
	
		}else{
			$pdf->Row1(array(stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'STREET_1'))."".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY'))."".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'COUNTRY'))."".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY_POSTAL_CODE'))."\n ".$taxno1,$invtitle.' No. :'.$rows['MESSAGE']."\n".$invtitle." Date : ".$invdate."\n"."REF NO : ".$rows['REF_NO']."\n".'TRN NO:'.$SESSION['TRN_NO']));
		}
	
	
	


	$initialY1 =  $pdf->GetY();
	
	$pdf->Ln(-($initialY1 - $initialY));
    $pdf->Cell(0,($initialY1 - $initialY),"",1,1,'L',0);
	
	
	$pdf->SetFont('daxcondensedlight','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L');
	$arr2=array(40,150);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$pdf->Row(array("VESSEL NAME : ",$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'                 VOYAGE NO : '.$obj->getFun8()));
	$pdf->Row(array("CHARTER PARTY DATED : ",date("d-m-Y",strtotime($obj->getFun3()))));
	
	
	$gety = $pdf->GetY();
	
	$pdf->SetFont('daxcondensedlight','',12);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','C');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("DESCRIPTION :","Amount in ".$currency.""));
	
	$pdf->SetFont('daxcondensedlight','',10);
	$arr1=array('L','L','R');
	$arr2=array(50,100,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("VOYAGE :",$rows['VOYAGE'],''));
	
	$pdf->Ln(1);
	$pdf->SetFont('daxcondensedlight','',10);
	$arr1=array('L','R');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$sql1 = "select SUM(DEM_AMT) as SUM from other_invoice_slave1 where INVOICEID='".$rows['INVOICEID']."'";
    $res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	$pdf->Row1(array($rows['REMARKS'],number_format(($rows['GROSS_AMT'] + $rows1['SUM']),2,'.',',')));
	
	
	

    $sql2 = "select * from other_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD'  and AMOUNT>0";
    $res2 = mysql_query($sql2);
	$num2 = mysql_num_rows($res2);

    if($num2>0)
	{
		$pdf->Ln(2);
		$pdf->SetFont('daxcondensedlight','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','R');
		$arr2=array(150,40);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("Additional:",""));
	}
	
	$pdf->SetFont('daxcondensedlight','',10);
	
    while($rows2 = mysql_fetch_assoc($res2))
	{
		$pdf->Row1(array("     ".$rows2['DESCRIPTION'],"(+) ".number_format($rows2['AMOUNT'],2,'.',',')));
	}
	
	$sql2 = "select * from other_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0";
    $res2 = mysql_query($sql2);
	$num2 = mysql_num_rows($res2);

    if($num2>0 || $rows['BROKERAGE'] > 0 || $rows['ADDCOM_AMOUNT'] > 0)
	{
		$pdf->Ln(2);
		$pdf->SetFont('daxcondensedlight','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','R');
		$arr2=array(150,40);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("Less:",""));
	}
	$pdf->SetFont('daxcondensedlight','',10);
	
    while($rows2 = mysql_fetch_assoc($res2))
	{
		$pdf->Row1(array("     ".$rows2['DESCRIPTION'],"(-) ".number_format($rows2['AMOUNT'],2,'.',',')));
	}
	
	
	$pdf->SetFont('daxcondensedlight','',11);
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
	    if($rows['RDOVATGST'] == 1)
	    {
			$pdf->Ln(2);
			if($rows['IGST_PERCENT']>0)
			{
				$pdf->Row1(array("     IGST Output(".$rows['IGST_PERCENT']."%)","(+) ".number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
			}else{
			    $pdf->Row1(array("     SGST Output(".$rows['SGST_PERCENT']."%)","(+) ".number_format($rows['SGST_PERCENT_AMOUNT'],2,'.',',')));
				$pdf->Row1(array("     CGST Output(".$rows['CGST_PERCENT']."%)","(+) ".number_format($rows['CGST_PERCENT_AMOUNT'],2,'.',',')));
			}
		}else{
			$pdf->Ln(2);
			$pdf->Row1(array("     VAT Output(".$rows['VAT_PERCENT']."%)","(+) ".number_format($rows['VAT_PERCENT_AMOUNT'],2,'.',',')));
		}
	}
	
	
	$pdf->Ln(3);
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','R');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("TOTAL PAYABLE DUE ",number_format($rows['NET_PAYABLE_TAX'],2,'.',',')));
	$pdf->SetX(160);
	$pdf->Cell(40,0,"",0,1,'C','1');
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $pdf->SetFont('daxcondensedlight','',11);
		$pdf->Row1(array("TOTAL PAYABLE DUE (".$rows['EXCHANGE_CURRENCY'].")",number_format(($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE']),2,'.',',')));
		$pdf->SetX(160);
	    $pdf->Cell(40,0,"",0,1,'C','1');
	}
	
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','R');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("(AMOUNT IN WORDS : ".strtoupper($amttoword->convert_number_to_words($rows['NET_PAYABLE_TAX'],$currency)).")", ''));
	if($rows['EXCHANGE_RATE']!=1)
	{$pdf->Ln(1);
	    $pdf->SetFont('daxcondensedlight','',10);
		$pdf->Row1(array("(AMOUNT IN WORDS : ".strtoupper($amttoword->convert_number_to_words(number_format($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE'],2,'.',''),$rows['EXCHANGE_CURRENCY'])).")", ''));
	}
	
	$pdf->Ln(2);
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->Row1(array("REMIT VIDE WIRE TRANSFER : ", ''));
	
	$pdf->SetFont('daxcondensedlight','',10);
	$pdf->Row1(array("PAYMENT DUE DATE  :     ".$rows['PAYMENT_TERMS'], ''));
	
	$pdf->Ln(1);
	$pdf->SetFont('daxcondensedlight','',12);
	$pdf->Row1(array("PAYMENT INSTRUCTIONS : ", ''));
	
	$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	$pdf->SetFont('daxcondensedlight','',10);
	$arr1=array('L', 'L', 'L', 'L', 'L');
	$arr2=array(30, 40, 5, 65,50);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	
	$pdf->Row1(array('', 'ACCOUNT NAME',' : ',$rows2['NAME'],''));
	
	$pdf->Row1(array('', 'ADDRESS',' : ',$rows2['ADDRESS'],''));
	$pdf->Row1(array('', 'ACCOUNT NO.',' : ',$rows2['AC_NO'],''));
	$pdf->Row1(array('', 'BANK NAME',' : ',$rows2['BANK'],''));
	$pdf->Row1(array('', 'SWIFT CODE',' : ',$rows2['BANK_SWIFT_CODE'],''));
	if($rows2['IFSC']!='')
	{
		$pdf->Row1(array('', 'IFSC',' : ',$rows2['IFSC'],''));
	}
	$pdf->Ln(1);
	

	$pdf->Ln(1);
	$pdf->SetFont('daxcondensedlight','',12);
	$pdf->Cell(190,6,"INTERMEDIARY BANK DETAILS : ",0,1,'L');
	
	$pdf->SetFont('daxcondensedlight','',10);
	$arr1=array('L', 'L', 'L', 'L', 'L');
	$arr2=array(30, 40, 5, 65,50);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	

	$pdf->Row1(array('', 'BANK NAME',' : ',$rows2['C_BANK_NAME'],''));
	
	$pdf->Row1(array('', 'ADDRESS',' : ',$rows2['CORRES_ADDRESS'],''));

	if($rows2['B_ACNO']!='')
	{
	$pdf->Row1(array('', 'ACCOUNT NO.',' : ',$rows2['B_ACNO'],''));
	}

	if($rows2['C_SWIFT_CODE']!='')
	{
	$pdf->Row1(array('', 'SWIFT CODE',' : ',$rows2['C_SWIFT_CODE'],''));
	}

	$pdf->Ln(1);


	
	$gety1 = $pdf->GetY();
	$pdf->Ln(-($gety1 - $gety));
    $pdf->Cell(150,($gety1 - $gety),"",1,1,'L',0);
	
	$gety1 = $pdf->GetY();
	$pdf->Ln(-($gety1 - $gety));
	$pdf->SetX(160);
    $pdf->Cell(40,($gety1 - $gety),"",1,1,'L',0);
	
	
	
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
		
	    if($rows['RDOVATGST'] == 1)
	    {
		    $pdf->SetFont('daxcondensedlight','',11);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('C','C','C','C');
			$arr2=array(100,30,30,30);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row(array("HSN/SAC","Taxable Value", "Rate", "Tax Amount"));
			
			$pdf->SetFont('daxcondensedlight','',10);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('L','R','R','R');
			$arr2=array(100,30,30,30);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			if($rows['IGST_PERCENT']>0)
			{
				$pdf->Row(array("996521", $rows['NET_PAYABLE'],"IGST ". $rows['IGST_PERCENT']."%",number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
				$pdf->SetFont('daxcondensedlight','',11);
				$pdf->Row(array("Total", $rows['NET_PAYABLE'],"",number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
			}else{
			    $pdf->Row(array("996521", $rows['NET_PAYABLE'],"SGST ". $rows['SGST_PERCENT']."%",number_format($rows['SGST_PERCENT_AMOUNT'],2,'.',',')));
				$pdf->Row(array("996521", $rows['NET_PAYABLE'],"CGST ". $rows['CGST_PERCENT']."%",number_format($rows['CGST_PERCENT_AMOUNT'],2,'.',',')));
				$pdf->SetFont('daxcondensedlight','',11);
				$pdf->Row(array("Total", $rows['NET_PAYABLE'],"",number_format(($rows['CGST_PERCENT_AMOUNT'] + $rows['SGST_PERCENT_AMOUNT']),2,'.',',')));
			}
		}else{
			
		}
	}
	
	$pdf->Ln(1);
	// $pdf->SetFont('Arial','I',9);
	$pdf->SetTextColor(10,10,10);
	$pdf->Cell(0,6,"* This is a system generated ".strtolower($invtitle)." and no signatures are required",0,1,'L',0);
	//-----------------------------------------------------------------------------------------------------------------------------
	
	
	
	
	
	/*
	
	
	
	$pdf->Ln(7);
	$pdf->SetFont('daxcondensedlight','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L','L','L');
	$arr2=array(48,47,48,47);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row(array($invtitle." No.",$rows['MESSAGE'],"Contract Ref.","CP Date ".date("d-m-Y",strtotime($obj->getFun3()))));
	$invdate = date('d-m-Y',strtotime($rows['DATE'])); if($invdate=='01-01-1970'){$invdate = '';}
	$duedate = date('d-m-Y',strtotime($rows['DUE_DATE'])); if($duedate=='01-01-1970'){$duedate = '';}
	$pdf->Row(array($invtitle." Date",$invdate,"Due Date",$duedate));
	$pdf->Row(array("Vessel",$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME"),$invtitle." Type","Other"));
	$pdf->Row(array("Port of Loading",$lp_name,"Port of Discharging",$dp_name));
	$pdf->Row(array("Voyage Number ",$obj->getFun8(),"",""));
	
	$pdf->Ln(5);
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L');
	$arr2=array(95,95);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row(array($invtitle." To:",$invtitle." From:"));
	$pdf->SetFont('daxcondensedlight','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L');
	$arr2=array(95,95);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
	    if($rows['RDOVATGST'] == 1)
	    {
			$taxno1 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
			$taxno2 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}else{
			$taxno1 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
			$taxno2 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}
	}else{
	     $taxno1 = '';
		 $taxno2 = '';
	}
	
	$pdf->Row(array($obj->getVendorListNewBasedOnID($rows['VENDOR'])."\n".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'STREET_1')).", ".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY')).", ".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'COUNTRY')).", ".stripslashes($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY_POSTAL_CODE')),$obj->getVendorListNewBasedOnID($rows['SHIP_OWNER'])."\n".stripslashes($obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STREET_1'))));
	
	$pdf->Row(array($taxno1,$taxno2));
		
	$pdf->Ln(5);
	$gety = $pdf->GetY();
    $pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L');
	$arr2=array(190);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("Payment Terms:"));
	$pdf->SetFont('daxcondensedlight','',10);
	$pdf->Row1(array($rows['PAYMENT_TERMS']));
	
	$pdf->Ln(2);
	$gety2 = $pdf->GetY();
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row(array("Description","Amount(".$currency.")"));
	
	$pdf->SetFont('daxcondensedlight','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','R');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array($rows['REMARKS'],$rows['GROSS_AMT']));

	$pdf->Ln(2);
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("Additional:",""));
	
	$pdf->SetFont('daxcondensedlight','',10);
	$sql2 = "select * from other_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD'";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $pdf->SetTextColor(0,0,0);
		$arr1=array('L','R');
		$arr2=array(150,40);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("     ".$rows2['DESCRIPTION'],$rows2['AMOUNT']));
	}
	
	
	
	$pdf->Ln(2);
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("Less:",""));
	$pdf->SetFont('daxcondensedlight','',10);
	$sql2 = "select * from other_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB'";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $pdf->SetTextColor(0,0,0);
		$arr1=array('L','R');
		$arr2=array(150,40);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("     ".$rows2['DESCRIPTION'],$rows2['AMOUNT']));
	}
	
	$pdf->SetFont('daxcondensedlight','',11);
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
	    if($rows['RDOVATGST'] == 1)
	    {
			$pdf->Ln(2);
			if($rows['IGST_PERCENT']>0)
			{
				$pdf->Row1(array("     IGST Output(".$rows['IGST_PERCENT']."%)","(+) ".number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
			}else{
			    $pdf->Row1(array("     SGST Output(".$rows['SGST_PERCENT']."%)","(+) ".number_format($rows['SGST_PERCENT_AMOUNT'],2,'.',',')));
				$pdf->Row1(array("     CGST Output(".$rows['CGST_PERCENT']."%)","(+) ".number_format($rows['CGST_PERCENT_AMOUNT'],2,'.',',')));
			}
		}else{
			$pdf->Ln(2);
			$pdf->Row1(array("     VAT Output(".$rows['VAT_PERCENT']."%)","(+) ".number_format($rows['VAT_PERCENT_AMOUNT'],2,'.',',')));
		}
	}
	
	$pdf->Ln(3);
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','R');
	$arr2=array(150,40);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row(array("Total Amount ".$inv_amt_title,$rows['NET_PAYABLE_TAX']));
	if($rows['EXCHANGE_RATE']!=1)
	{
		$pdf->Row(array("Total Amount ".$inv_amt_title." (".$rows['EXCHANGE_CURRENCY'].")",number_format(($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE']),2,'.','')));
	}
	
	$gety1 = $pdf->GetY();
	$pdf->Ln(-($gety1 - $gety));
    $pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
	
	$pdf->Ln(-($gety1 - $gety2));
	$pdf->SetX(160);
    $pdf->Cell(40,($gety1 - $gety2),"",1,1,'L',0);
	
	$pdf->Ln(5);
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L');
	$arr2=array(190);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row(array("Total amount in words:",""));
	$pdf->SetFont('daxcondensedlight','',10);
	$pdf->Row(array(strtoupper($amttoword->convert_number_to_words($rows['NET_PAYABLE_TAX'],$currency))));
	if($rows['EXCHANGE_RATE']!=1)
	{
		$pdf->Row(array(strtoupper($amttoword->convert_number_to_words(number_format($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE'],2,'.',''),$rows['EXCHANGE_CURRENCY'])),""));
	}
	
	$pdf->SetFont('daxcondensedlight','',11);
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
		
	    if($rows['RDOVATGST'] == 1)
	    {
		    $pdf->SetFont('daxcondensedlight','',11);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('C','C','C','C');
			$arr2=array(100,30,30,30);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row(array("HSN/SAC","Taxable Value", "Rate", "Tax Amount"));
			
			$pdf->SetFont('daxcondensedlight','',10);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('L','R','R','R');
			$arr2=array(100,30,30,30);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			if($rows['IGST_PERCENT']>0)
			{
				$pdf->Row(array("996521", $rows['NET_PAYABLE'],"IGST ". $rows['IGST_PERCENT']."%",number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
				$pdf->SetFont('daxcondensedlight','',11);
				$pdf->Row(array("Total", $rows['NET_PAYABLE'],"",number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
			}else{
			    $pdf->Row(array("996521", $rows['NET_PAYABLE'],"SGST ". $rows['SGST_PERCENT']."%",number_format($rows['SGST_PERCENT_AMOUNT'],2,'.',',')));
				$pdf->Row(array("996521", $rows['NET_PAYABLE'],"CGST ". $rows['CGST_PERCENT']."%",number_format($rows['CGST_PERCENT_AMOUNT'],2,'.',',')));
				$pdf->SetFont('daxcondensedlight','',11);
				$pdf->Row(array("Total", $rows['NET_PAYABLE'],"",number_format(($rows['CGST_PERCENT_AMOUNT'] + $rows['SGST_PERCENT_AMOUNT']),2,'.',',')));
			}
		}else{
			//$pdf->Ln(2);
			//$pdf->Row(array("     VAT Output(".$rows['VAT_PERCENT']."%)","(+) ".number_format($rows['VAT_PERCENT_AMOUNT'],2,'.',',')));
		}
	}
	
	$pdf->Ln(5);
	$pdf->SetFont('daxcondensedlight','',11);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L');
	$arr2=array(30,160);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row(array("Remit To:",""));
	$pdf->SetFont('daxcondensedlight','',10);
	$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	if($rows2['IFSC']!='')
	{
		$ifsc = '\nIBAN No.: .'.$rows2['IFSC'];
	}else{$ifsc = '';}
	$pdf->Row(array("Beneficiary",$_SESSION['companyname']."\nBENEFICIARY NAME: ".$rows2['NAME']."\nBENEFICIARY BANK: ".$rows2['BANK']."\nADDRESS: ".$rows2['ADDRESS']."\nACCOUNT NUMBER: ".$rows2['AC_NO']."\nSWIFT CODE: ".$rows2['BANK_SWIFT_CODE']."\nIBAN No.: ".$rows2['IBAN_NO'].$ifsc));
	
	$pdf->Ln(1);
	// $pdf->SetFont('Arial','I',9);
	$pdf->SetTextColor(10,10,10);
	$pdf->Cell(0,6,"* This is a system generated ".strtolower($invtitle)." and no signatures are required",0,1,'L',0);*/
	
$filename = $invtitle." Of ".$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME")."(".$rows['I_TYPE'].") ".$obj->getFun8()." ".date("d-M-Y",time()).".pdf";
						
			
						$pdf->Output($filename,'D');

}

function getOtherINRPdf()
{
		$obj = new data();
		$amttoword = new Numbertowordconversion_inr();

		$obj->funConnect();

		$im_id = $_REQUEST['im_id'];
		$pdfpassword = $_REQUEST['pdfpassword'];

		$sql = "select * from other_invoice_master where INVOICEID='".$im_id."'";	

     
		$res = mysql_query($sql);
		$rows = mysql_fetch_assoc($res);

		$sqljson = "select * from gst_json_form_data where INVOICEID='".$im_id."' and INVOICE_TYPE='OTHER'";
		$resultjson = mysql_query($sqljson);
		$numjson = mysql_num_rows($resultjson);
		$rowjson = mysql_fetch_assoc($resultjson);

		$commodity_arr = array();
		if($numjson > 0)
		{
			$sqljson_slave = "select * from gst_json_form_data_slave where JSONID='".$rowjson['JSONID']."'";
			

			$resjson_slave = mysql_query($sqljson_slave);
			while($rowsjson_slave = mysql_fetch_assoc($resjson_slave))
			{
				$commodity_arr[] = $rowsjson_slave['PRODUCT_DESCRIPTION'];
			}

		}

			$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'];

		
		$commodity_arr = array_unique($commodity_arr);
	

		$exchange_rate = $rows['EXCHANGE_RATE'];
		$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
		$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
		$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);
		
		$_SESSION['companyname']        =  $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME");
		$_SESSION['companyaddress']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1");
		$_SESSION['companycity']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY");
		$_SESSION['companycountry']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY");
		$_SESSION['companycode']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE");
		$_SESSION['companyemail']       = $obj->getVendorListNewData($rows['SHIP_OWNER'],"EMAILID");
		$_SESSION['companytel']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PHONE");
		$_SESSION['companyfax']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FAX");
		$_SESSION['companyvat']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
		$_SESSION['panno']              = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PANNO");
		$_SESSION['CINno']              = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CINNO");
		$_SESSION['footeraddr']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
		$_SESSION['vendorlogo']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");
		
		$vlsImoId 						= $obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID");

		$_SESSION['BARCODE_ATTACHMENT'] = $rowjson['BARCODE_ATTACHMENT'];
		$_SESSION['IRN_NO']             = $rowjson['IRN_NO'];
	
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			if($rows['RDOVATGST'] == 1)
			{
				$_SESSION['taxno2'] = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}else{
				$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}
		}else{
			$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) :';
		}
	
		if($rows['I_TYPE']=='Credit'){
			$invtitle = 'Credit Note';
			$invtitleType = 'CREDIT NOTE';
			$inv_amt_title = 'to Credit';
		}
		else if($rows['I_TYPE']=='Debit'){
			$invtitle = 'Debit Note';
			$invtitleType = 'DEBIT NOTE';
			$inv_amt_title = 'to Debit';
		}else{
			$invtitle = 'Invoice';
			if($rows['I_TYPE']=='Interim'){$invtitleType = 'TAX INVOICE';}else{$invtitleType = 'TAX INVOICE';}
			$inv_amt_title = 'Invoiced';
		}
	
			class PDF extends FPDF_Protection
			{
				function Header()
				{
					$this->AddFont("CalibriBold",'',"CalibriBold.php");
					$this->AddFont("Calibri",'',"Calibri.php");
                    $this->Ln(-3);
					$this->SetFillColor(255,255,255);
					$this->SetTextColor(45,45,45);
					$this->SetFont('Calibri','',8);
					$this->Cell(0,3,"E-MAIL        :        accounts.gim@actship.com",0,1,'L');
					$this->Cell(0,3,"                     :        chartaccounts@actship.com",0,1,'L');
					$this->SetFont('CalibriBold','',9);
					$this->Cell(0,4,$_SESSION['companyname'],0,1,'C');
					$this->SetFont('Calibri','',8);
					$this->Cell(0,3,"( Chartering Division )",0,1,'C');
					$this->Ln(1);
					$this->Cell(0,3,"PLOT NO.391 & 392 SECTOR 1 (A), GANDHIDHAM - 370 201",0,1,'C');
					$this->Cell(0,3,"REGD. OFFICE NO.14, SHIPPING HOUSE, GR.FLOOR,",0,1,'C');
					$this->Cell(0,3,"KUMPTA STREET, FORT, MUMBAI - 400 001",0,1,'C');
					$this->Cell(0,3,"TEL NO. (02836) 229967/239743/231734/FAX NO.(02836) 238864/270579",0,1,'C');
					$this->SetFont('CalibriBold','',8);
					$this->Cell(0,3,"GSTIN : ".$_SESSION['companyvat'],0,1,'C');
					$this->Cell(0,3,"PAN NO. : ".$_SESSION['panno'], 0,1,'C');
					$this->Cell(0,3,"CIN No. : ".$_SESSION['CINno'], 0,1,'C');
					$this->Cell(0,3,"IRN No. : ".$_SESSION['IRN_NO'], 0,1,'C');
					if($_SESSION['BARCODE_ATTACHMENT']!='')
					{
						
						$image_path1 = '../../attachment/'.$_SESSION['BARCODE_ATTACHMENT'];
						$this->Image($image_path1,158,10,38,38);
						
					}
					$this->SetY(38);
					
				}
				
				function Footer()
				{

					
					
					
				}
			}
	
			$quantity = $totalfreight = $freightrate = 0;$maincargoid = 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='".$rows['RANDOMID']."' and STATUS=1";
				$res12 = mysql_query($sql12);
				$row12 = mysql_fetch_assoc($res12);
				if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
				{
					$quantity = $row12['sum2'];
				}
				else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
				{
					$quantity = $row12['sum2'];
				}
				else
				{
				$quantity = $row12['sum1'];
				}
				$totalfreight = $row12['SUM3']*$exchange_rate;
				$freightrate = $row12['SUM4'];
				$maincargoid = $row12['CARGOID'];
			}
			else
			{
				
				if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
				{
					$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
					$totalfreight = $row12['SUM3']*$exchange_rate;
					$freightrate = $row12['GAS_BASE_RATE'];
				}
				else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
				{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
				
				if($obj->getFun228()==1)
				{
				 if($obj->getFun171()==1)
				 {
				     $totalfreight = $obj->getFun172()*$exchange_rate;
					 $freightrate = '';
					 $quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
				 }else
				 {
				     $res1_1 = mysql_query("select * from freight_cost_estimete_slave12 where FCAID='".$obj->getFun1()."' and CUSTOMER = '".$rows['VENDOR']."' ");
					 $row1_1 = mysql_fetch_assoc($res1_1);
					 $totalfreight = $row1_1['TOTAL_AMOUNT']*$exchange_rate;
					 $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='".$rows['RANDOMID']."' and STATUS=1";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
					{
						$quantity = $row12['sum2'];
					}
					else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
					{
						$quantity = $row12['sum2'];
					}
					else
					{
						$quantity = $row12['sum1'];
					}
					$totalfreight = $row12['SUM3']*$exchange_rate;
					$maincargoid = $row12['CARGOID'];
				 }
			}
			else
			{
				
					if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
					{
						$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
						$totalfreight = $obj->getCompareEstimateData($rows['COMID'],"TOTAL_PREIGHT_ADJ")*$exchange_rate;
						$freightrate = $obj->getCompareEstimateData($rows['COMID'],"FREIGHT_GROSS");
						$maincargoid = $obj->getCompareEstimateData($rows['COMID'],"CARGO_ID");
					}
					else
					{
						$sql12 = "select QUANTITY, GROSS_FREIGHT, AGREED_GROSS_FREIGHT, CARGO, addnlCargoQty from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and RANDOMID='".$rows['RANDOMID']."'";
						
						$res12 = mysql_query($sql12) or die($sql12);
						$row12 = mysql_fetch_assoc($res12);
						$quantity = $row12['QUANTITY'] + $row12['addnlCargoQty'];
						$totalfreight = $row12['GROSS_FREIGHT']*$exchange_rate;
						$freightrate = $row12['AGREED_GROSS_FREIGHT'];
						$maincargoid = $row12['CARGO'];
					}
			}
		
		}
							
		
		$lp_name = array(); 
		$dp_name = array();
		$discharge_port = "";
	
		for($j=0;$j<count($arrports);$j++)
		{   
			$arr_explode = explode('@@',$arrports[$j]);
			if($arr_explode[0] == "LP"){$lp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
			if($arr_explode[0] == "DP"){$dp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
		}
	
		$lp_name  = implode(', ',$lp_name);
		$dp_name  = implode(', ',$dp_name);
		if($rows['LOAD_PORT_NAME']!='')
		{
			$lp_name = $rows['LOAD_PORT_NAME'];
		}
		if($rows['DISCHARGE_PORT_NAME']!='')
		{
			$dp_name = $rows['DISCHARGE_PORT_NAME'];
		}
	
		if($obj->getFun175()!='')
		{
			$sqlcoa = "select * from coa_master where COAID='".$obj->getFun175()."'";
			$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
			$rowscoa   = mysql_fetch_assoc($resultcoa);
			$currency = $rowscoa['CURRENCY'];
		}else
		{
			$currency = 'USD';
		}
	
		
	$pdf = new PDF();
	$pdf->SetProtection(array('print'),$pdfpassword);
	$pdf->AddPage('P');
	
	$pdf->AddFont("CalibriBold",'',"CalibriBold.php");
	$pdf->AddFont("Calibri",'',"Calibri.php");

	$pdf->SetDisplayMode('real','single');
	$pdf->SetTitle('Generate Freight '.$invtitle.' Pdf');
	$pdf->SetAuthor('Seven Oceans Holdings');
	$pdf->SetSubject('Generate '.$invtitle.' Pdf');
	$pdf->SetKeywords('Designed and Developed By Seven Oceans Holdings pvt. Ltd.');

	$pdf->Ln(9);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C');
	$arr2=array(190);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array($invtitleType));
	
	$pdf->Ln(1);
	$initialY =  $pdf->GetY();
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','C','L','L','C','L');
	$arr2=array(22,7,65,25,7,65);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
	    if($rows['RDOVATGST'] == 1)
	    {
			$taxno1 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
			$taxno2 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}else{
			$taxno1 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
			$taxno2 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}
	}else{
	     $taxno1 = '';
		 $taxno2 = '';
	}
	
	$supplydate = date('d-m-Y',strtotime($rows['SUPPLY_DATE'])); if($supplydate=='01-01-1970'){$supplydate = '';}
	$invdate = date('d-m-Y',strtotime($rows['DATE'])); if($invdate=='01-01-1970'){$invdate = '';}
	
	$invmonth = date('m',strtotime($rows['DATE']));
	$invyear = date('Y',strtotime($rows['DATE']));
	
	if($invmonth > 3)
	{
	    $fyear = $invyear.' - '.($invyear + 1);
	}else{
	    $fyear = ($invyear - 1).' - '.$invyear;
	}
	
	$pdf->Row1(array("Reverse Charges",":",($rows['REVERSE_CHARGE']==1)?'Yes':'No',"Service Description",":",$rows['PDFHEAD']));
	$pdf->Ln(-1);

    if($rows['I_TYPE']=='Credit')
    {
	    $pdf->Row1(array("Financial Year",":",$fyear,"Against Invoice No.",":",$rows['VEHICLE_NO']));
    
    }else{
        $pdf->Row1(array("Financial Year",":",$fyear,"Vehicle No.",":",$rows['VEHICLE_NO']));

    }
	$pdf->Ln(-1);

    
    if($rows['I_TYPE']=='Credit')
    {
        $pdf->Row1(array("Credit Note No.",":",$rows['MESSAGE'],"Invoice Date",":",$supplydate));

    }else{

        $pdf->Row1(array("Invoice No.",":",$rows['MESSAGE'],"Date Of Supply",":",$supplydate));
    }
	$pdf->Ln(-1);

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

        $pdf->Row1(array("Date of Issue",":",$invdate,"Place Of Supply",":",$rows['SUPPLY_PLACE']));

    }else{
        $pdf->Row1(array("Invoice Date",":",$invdate,"Place Of Supply",":",$rows['SUPPLY_PLACE']));

    }
	$pdf->Ln(-1);
	$pdf->Row1(array("Voyage No.",":",$obj->getFun8(),"","",""));
	$pdf->Ln(-1);
	$pdf->Row1(array("State",":",$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STATE')."              State Code:".$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STATE_CODE'),"","",""));
	
	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(22,($initialY1 - $initialY),"",1,0,'L',0);
	$pdf->Cell(7,$ydifference,"",1,0,'L',0);
	$pdf->Cell(65,$ydifference,"",1,0,'L',0);
	$pdf->Cell(25,$ydifference,"",1,0,'L',0);
	$pdf->Cell(7,$ydifference,"",1,0,'L',0);
	$pdf->Cell(65,$ydifference,"",1,1,'L',0);
	
	$initialY =  $pdf->GetY();
	
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','C','L','L','L','L','C','L','L','L');
	$arr2=array(22,7,24,17,24,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	// dpkldj

	
	
	
	$pdf->Row(array("Vessel Name",":",$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME"),"Load Port :",$lp_name,"Commodity",":", implode(', ',$commodity_arr),"Quantity :",number_format($quantity_test,3,'.',',').' MT'));
	$cpdate = date('d-m-Y',strtotime($obj->getFun3())); if($cpdate=='01-01-1970'){$cpdate = '';}
	$exchangedate = date('d-m-Y',strtotime($rows['EXCHANGE_DATE'])); if($exchangedate=='01-01-1970'){$exchangedate = '';}
	
	$pdf->Row(array("CP Date",":",$cpdate,"Discharge Port :",$dp_name,"Ex Rate(USD)",":",$rows['EXCHANGE_RATE'],"Date : ",$exchangedate));
	
	
	
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','C');
	$arr2=array(94,97);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$pdf->Row(array("Details of Receiver / Billed To","Details of Consignee / Shipped To"));
	
	$initialY =  $pdf->GetY();
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','C','L','L','C','L');
	$arr2=array(22,7,65,25,7,64);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("Name",":","M/S ".$obj->getVendorListNewBasedOnID($rows['VENDOR']),"Name",":","M/S ".$obj->getVendorListNewBasedOnID($rows['SHIPPER_VENDOR'])));
	$pdf->Ln(-1);
	$pdf->Row1(array("Address",":",stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'STREET_1'))).' '.stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'COUNTRY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY_POSTAL_CODE'))),"Address",":",stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STREET_1'))).' '.stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'CITY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'COUNTRY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'CITY_POSTAL_CODE')))));
	$pdf->Ln(-1);
	$pdf->Row1(array("PAN",":",$obj->getVendorDataBasedOnID($rows['VENDOR'],'PANNO'),"PAN",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'PANNO')));
	$pdf->Ln(-1);
	
	
	$pdf->Row1(array("GSTIN",":",$rowjson['BUYER_GSTIN'],"GSTIN",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'VAT_NUMBER')));
	$pdf->Ln(-1);
	$pdf->Row1(array("State",":",$obj->getVendorDataBasedOnID($rows['VENDOR'],'STATE')."               State Code : ".$obj->getVendorDataBasedOnID($rows['VENDOR'],'STATE_CODE'),"State",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STATE')."               State Code : ".$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STATE_CODE')));
	
	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(94,($initialY1 - $initialY),"",1,0,'L',0);
	$pdf->Cell(97,$ydifference,"",1,1,'L',0);
	
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L');
	$arr2=array(191);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$bldate = date('d-m-Y',strtotime($rows['BL_DATE'])); if($bldate=='01-01-1970'){$bldate = '';}
	
	$pdf->Row(array("BL NO. : ".$rows['BL_NO'].", Dtd . : ".$bldate." , Ref No. : ".$rows['REF_NO']." "));

	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','C','C','C','C','C','C');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);

	if($rowjson['UNIT_CURRENCY']=='INR')
	{
		$freight_exchangerate = $exchange_rate;
		$currency_code = "";
	}else{
		$freight_exchangerate = 1;
		$currency_code = "$";
	}
	$pdf->Row(array("S.No.", "Particulars", ($rows['GST_PERCENT']>0)?"":"HSN/SAC", "UO", "QTY", "RATE", "Amount(".$rows['EXCHANGE_CURRENCY'].")"));
	
	$sqlinv_slave = "select SUM(DEM_AMT) as SUM from other_invoice_slave1 where INVOICEID='".$rows['INVOICEID']."'";
	$resinv_slave = mysql_query($sqlinv_slave) or die($sqlinv_slave);
	$rowsinv_slave = mysql_fetch_assoc($resinv_slave);
	
	$initialY =  $pdf->GetY();
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','L','C','C','C','C','R');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$i = 0;

	

	
	$pdf->Row1(array(1, $rows['REMARKS'], $rows['HSN_SAC'], "", '', '', number_format(($rows['I_TYPE'] == 'Credit' ? abs($rows['GROSS_AMT'] + $rowsinv_slave['SUM']):$rows['GROSS_AMT'] + $rowsinv_slave['SUM'])*$exchange_rate,2,'.',',')));
	
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','R','C','C','C','C','R');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	
	
	$amount = $rows['GROSS_AMT']*$exchange_rate;
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','L','C','C','C','C','R');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	
	/* $pdf->SetX(177);
	$pdf->Cell(24, 1, '', 'T', 1, 'L');
	$pdf->Ln(-1);
	$pdf->Row1(array("", "SUB TOTAL", '', '', '', '',number_format($amount,2,'.',','))); */
	
	
	$sql2 = "select * from other_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD' and AMOUNT>0";
    $res2 = mysql_query($sql2);
	$num2 = mysql_num_rows($res2);

	
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $pdf->Ln(-1);
		$pdf->Row1(array("", $rows2['DESCRIPTION'], '', '', '', '',number_format($rows2['AMOUNT']*$exchange_rate,2,'.',',')));
	}
	
	$sql2 = "select * from other_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0";
    $res2 = mysql_query($sql2);
	$num2 = mysql_num_rows($res2);
		
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $pdf->Ln(-1);
		$pdf->Row1(array("","Less ".$rows2['DESCRIPTION'], '', '', '', '',number_format($rows2['AMOUNT']*$exchange_rate,2,'.',',')));
	}
	
	
	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(22,($initialY1 - $initialY),"",1,0,'L',0);
	$pdf->Cell(72,$ydifference,"",1,0,'L',0);
	$pdf->Cell(25,$ydifference,"",1,0,'L',0);
	$pdf->Cell(7,$ydifference,"",1,0,'L',0);
	$pdf->Cell(24,$ydifference,"",1,0,'L',0);
	$pdf->Cell(17,$ydifference,"",1,0,'L',0);
	$pdf->Cell(24,$ydifference,"",1,1,'L',0);
	
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('R','R','R');
	$arr2=array(150,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$initialY =  $pdf->GetY();
	
	if($rowjson['NOTIFICATION']!='')
	{
		
		$arr1=array('L');
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			$arr2=array(119);
		}else{
            $arr2=array(190);
		}
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$initialY_n =  $pdf->GetY();
		$pdf->SetFont('Calibri','',8);
        $pdf->Row(array($rowjson['NOTIFICATION']));
		$initialY_n1 =  $pdf->GetY();
		$pdf->SetY($initialY_n);

		if($rows['RDOTAXAPPLICABLE'] == 1)
		{

			
			
			$pdf->SetX(129);
			$arr1=array('R','R','R');
			$arr2=array(30,17,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row1(array("Total value        ","",number_format($rows['NET_PAYABLE']*$exchange_rate,2,'.',',')));
			$pdf->SetFont('Calibri','',8);
			if($rows['RDOVATGST'] == 1)
			{
				if($rows['GST_PERCENT']>0)
				{
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total GST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['GST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['GST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['IGST_PERCENT']>0)
				{
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total IGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['IGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['IGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['SGST_PERCENT']>0)
				{   
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total SGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['SGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['SGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['CGST_PERCENT']>0)
				{
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total CGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['CGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['CGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
			}else{
				if($rows['VAT_PERCENT']>0)
				{
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total VAT          ",0,0,'R',0);$pdf->Cell(17,4,$rows['VAT_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['VAT_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
			}
		}
        
		$pdf->SetX(129);
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('R','R','R');
		$arr2=array(30,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$sqlprev = "select * from freight_invoice_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR = '".$rows['VENDOR']."' and P_TYPE='".$rows['P_TYPE']."' and CARGOID='".$rows['CARGOID']."' and RANDOMID='".$rows['RANDOMID']."' and STATUS=5 and INVOICEID<'".$rows['INVOICEID']."'";
		$resprev = mysql_query($sqlprev) or die($sqlprev);
		while($rowsprev = mysql_fetch_assoc($resprev))
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("INITIAL FREIGHT RECEIVED", "", "(-) ".number_format($rowsprev['P_AMT']*$exchange_rate,2,'.',',')));
		}
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetX(177);
		$pdf->Cell(24, 1, '', 'T', 1, 'L');

		$pdf->Ln(-1);
		$pdf->SetX(129);
		
		$total_ldj_amt=($rows['GST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['SGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['IGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['CGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['NET_PAYABLE']*$exchange_rate);
		
		$pdf->Row1(array("Grand Total (".$rows['EXCHANGE_CURRENCY'].")       ", "",round($total_ldj_amt,0).".00"));

		$initialY_n2 =  $pdf->GetY();
		if($initialY_n2 > $initialY_n1)
		{$lastY = $initialY_n2;}
		else{$lastY = $initialY_n1;}
	}
	else{
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			
			$pdf->Ln(-1);
			$arr1=array('R','R','R');
			$arr2=array(150,17,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);

		

			$pdf->Row1(array("Total value       ","",number_format($rows['I_TYPE'] == 'Credit'? abs($rows['NET_PAYABLE'])*$exchange_rate:$rows['NET_PAYABLE']*$exchange_rate,2,'.',',')));
			$pdf->SetFont('Calibri','',8);
			if($rows['RDOVATGST'] == 1)
			{
				if($rows['GST_PERCENT']>0)
				{

					$gst_ldj_val= $rows['I_TYPE'] == 'Credit' ? abs($rows['GST_PERCENT_AMOUNT']): $rows['GST_PERCENT_AMOUNT'];

					$pdf->Cell(150,4,"Total GST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['GST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($gst_ldj_val*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['IGST_PERCENT']>0)
				{

					$igst_ldj_val= $rows['I_TYPE'] == 'Credit' ? abs($rows['IGST_PERCENT_AMOUNT']): $rows['IGST_PERCENT_AMOUNT'];
					$pdf->Cell(150,4,"Total IGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['IGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($igst_ldj_val*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['SGST_PERCENT']>0)
				{ 
					
					$sgst_ldj_val= $rows['I_TYPE'] == 'Credit' ? abs($rows['SGST_PERCENT_AMOUNT']): $rows['SGST_PERCENT_AMOUNT'];
					$pdf->Cell(150,4,"Total SGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['SGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($sgst_ldj_val*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['CGST_PERCENT']>0)
				{
					$cgst_ldj_val= $rows['I_TYPE'] == 'Credit' ? abs($rows['CGST_PERCENT_AMOUNT']): $rows['CGST_PERCENT_AMOUNT'];
					$pdf->Cell(150,4,"Total CGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['CGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($cgst_ldj_val*$exchange_rate,2,'.',','),0,1,'R',0);
				}
			}else{
				if($rows['VAT_PERCENT']>0)
				{

					$vat_percent_val= $rows['I_TYPE'] == 'Credit' ? abs($rows['VAT_PERCENT_AMOUNT']): $rows['VAT_PERCENT_AMOUNT'];

					$pdf->Cell(150,4,"Total VAT          ",0,0,'R',0);$pdf->Cell(17,4,$rows['VAT_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($vat_percent_val*$exchange_rate,2,'.',','),0,1,'R',0);
				}
			}
		}
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('R','R','R');
		$arr2=array(150,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$sqlprev = "select * from freight_invoice_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR = '".$rows['VENDOR']."' and P_TYPE='".$rows['P_TYPE']."' and CARGOID='".$rows['CARGOID']."' and RANDOMID='".$rows['RANDOMID']."' and STATUS=5 and INVOICEID<'".$rows['INVOICEID']."'";
		$resprev = mysql_query($sqlprev) or die($sqlprev);
		while($rowsprev = mysql_fetch_assoc($resprev))
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("INITIAL FREIGHT RECEIVED          ", "", "(-) ".number_format($rowsprev['P_AMT']*$exchange_rate,2,'.',',')));
		}
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetX(177);
		$pdf->Cell(24, 1, '', 'T', 1, 'L');
		$pdf->Ln(-1);
		
		$total_ldj_amt=($rows['GST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['SGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['IGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['CGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['NET_PAYABLE']*$exchange_rate);
		

		$pdf->Row1(array("Grand Total (".$rows['EXCHANGE_CURRENCY'].")       ", "",round($rows['I_TYPE'] =='Credit' ? abs($total_ldj_amt):$total_ldj_amt,0).".00"));

		$lastY = $pdf->GetY();
	}
	
	$pdf->SetY($lastY);
	$pdf->SetX(177);
	$pdf->Cell(24, 1, '', 'T', 1, 'L');
	
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','R','R');
	$arr2=array(150,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Ln(-1);


	$total_ldj_amt= explode(".",(string ) round(($rows['IGST_PERCENT_AMOUNT']*$exchange_rate)+($rows['NET_PAYABLE']*$exchange_rate),0).".00");


	$total_ldj_amt[0]=$rows['I_TYPE'] == 'Credit' ? abs($total_ldj_amt[0]): $total_ldj_amt[0];
	$total_ldj_amt[1]=$rows['I_TYPE'] == 'Credit' ? abs($total_ldj_amt[1]): $total_ldj_amt[1];

	
	if($total_ldj_amt[1] != '00'){
		$pdf->Row1(array("AMOUNT IN WORDS : RUPEES ".strtoupper($amttoword->convert_number_to_words($total_ldj_amt[0])." AND ".$amttoword->convert_number_to_words($total_ldj_amt[1])." Paise Only"), '', ''));
	}
	else{
		$pdf->Row1(array("AMOUNT IN WORDS : RUPEES ".strtoupper($amttoword->convert_number_to_words($total_ldj_amt[0])." AND Zero Paise  Only"), '', ''));
	}
	

	
	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(150,($initialY1 - $initialY),"",1,0,'L',0);
	$pdf->Cell(17,$ydifference,"",1,0,'L',0);
	$pdf->Cell(24,$ydifference,"",1,1,'L',0);
	
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L');
	$arr2=array(191);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	
	$pdf->Cell(191,4,"E & OE",1,1,'L',0);
	$pdf->Cell(191,4,"BANKING DETAILS:",1,1,'L',0);
	
	$initialY =  $pdf->GetY();
	
	$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L',"C","L");
	$arr2=array(25,6, 165);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$pdf->Cell(25,4,"BENEFICIARY",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['NAME'],0,1,'L',0);
	$pdf->Cell(25,4,"ACCOUNT NO",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['AC_NO'],0,1,'L',0);

	if($rows2['ACCOUNT_TYPE']!=' ' || $rows2['ACCOUNT_TYPE']!=NULL){

		$pdf->Cell(25,4,"A/C TYPE",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['ACCOUNT_TYPE'],0,1,'L',0);
		
	}
	$pdf->Cell(25,4,"BANK NAME",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BANK'],0,1,'L',0);
	$pdf->Cell(25,4,"BRANCH",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BRANCH'],0,1,'L',0);
	$pdf->Cell(25,4,"BANK ADDRESS",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['B_ADDRESS'],0,1,'L',0);
	
	if($rows2['BANK_SWIFT_CODE']!='')
	{
	    $pdf->Cell(25,4,"SWIFT CODE",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BANK_SWIFT_CODE'],0,1,'L',0);
	}
	if($rows2['IFSC']!='')
	{
		$pdf->Cell(25,4,"IFSC/NEFT Code",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['IFSC'],0,1,'L',0);
	}
	if($rows2['IBAN_NO']!='')
	{
		$pdf->Cell(25,4,"IBAN NO.",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['IBAN_NO'],0,1,'L',0);
	}
	

	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(191,($initialY1 - $initialY),"",1,1,'L',0);
	
	$pdf->SetFont('CalibriBold','',9);
	$pdf->SetTextColor(10,10,10);
	$pdf->Cell(0,5,"FOR ".strtoupper($_SESSION['companyname']),0,1,'R',0);
	
	if($pdf->GetY()>245)
	{
	    $pdf->AddPage('P');
	}
	$pdf->Ln(12);
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(10,10,10);
	//$pdf->Cell("",1,1,'L',0);
	$pdf->SetX(10);

	if ($_SESSION['uid']=='159' || $_SESSION['uid']=='160') {
		if ($_SESSION['uid']=='159' && $rowjson['SHOW_SIGN'] == 1) {
			$image_path_ldj = '../../img/anilsign.jpg';
			
			$pdf->Image($image_path_ldj,175 ,($pdf->GetY()-10),23,0);

		}

		if ($_SESSION['uid']=='160' && $rowjson['SHOW_SIGN'] == 1) {
			$image_path_ldj = '../../img/poojasign.png';
			
			$pdf->Image($image_path_ldj,175 ,($pdf->GetY()-10),18,0);

		}	
	}	
	
	$pdf->MultiCell(191,4,addslashes("Note: Please make the payment specified to the bank account mentioned in the Freight Invoice.\nM/s ".$_SESSION['companyname'].' India will only use account holder as M/s '.$_SESSION['companyname'].' India & our banker is '.$rows2['BANK'].". We will never request payment to another bank or other company on behalf of us to collect the remittance, if you received any invoice or payment request not matching with this information, please inform us immediately at /chartaccounts@actship.com/accounts.gim@actship.com. We will not be liable for any losses arising from failure to adhere to the above instructions. We recommed you to kindly check with us telephonically, before processing the funds. If required we shall FAX the invoice to your office."),0,'L',false);
	$filename = $invtitle." Of ".$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME")."(".$rows['I_TYPE'].")".date("d-M-Y",time()).".pdf";
	
	$pdf->Output($filename,'D');
}

function create_TC_hire_pdf()
{

	$obj = new data();
	$amttoword = new Numbertowordconversion();
	$obj->funConnect();
	
	$invoiceid                      = $_REQUEST['invoiceid'];
	$comid 							= $_REQUEST['comid'];
	$pdfpassword                    = $_REQUEST['pdfpassword'];
	
	$tcoutid = $obj->getLatestCostSheetIDTC($comid);
    $obj->viewTCEstimationTempleteRecordsNew($tcoutid);
	$sql = "SELECT * from invoice_tchire_master where INVOICEID='".$invoiceid."' and COMID='".$comid."'";
	$res 	= mysql_query($sql);
	$rec 	= mysql_num_rows($res);
	$rows 	= mysql_fetch_assoc($res);
	
	$sqlprev = "SELECT SUM(CVE_AMOUNT) as CVE_TOTAL, SUM(CVE_OFFHIRE_AMOUNT) as CVE_OFFHIRE_TOTAL, SUM(FINAL_AMOUNT) as INVOICE_AMT_TOTAL, SUM(ADDRESS_COMMISSION_AMOUNT) as ADDRESS_COMM_TOTAL, SUM(BROKER_COMMISSION_AMOUNT) as BROKER_COMM_TOTAL from invoice_tchire_master where RANDOMID='".$rows['RANDOMID']."' and COMID='".$comid."'";
	$resprev 	= mysql_query($sqlprev);
	$recprev 	= mysql_num_rows($resprev);
	$rowsprev 	= mysql_fetch_assoc($resprev);
	
	$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$obj->getFun1()."' and RANDOMID='".$rows['RANDOMID']."'";
	$restc 	= mysql_query($sqltc) or die($sqltc);
	$rectc 	= mysql_num_rows($restc);
	$rowstc = mysql_fetch_assoc($restc);
	$vendorid = $rowstc['TTL_REV_VENDOR']; 
	if($rows['OLD_EXCHANGE_CURRENCY']!=''){$printcurrency = $rows['OLD_EXCHANGE_CURRENCY'];}else{$printcurrency = $rowstc['EXCHANGE_CURRENCY'];}
	if($printcurrency==''){$printcurrency = 'USD';}
	if($rows['OLD_DAILY_HIRE_RATE']!=''){$dailyhirey = $rows['OLD_DAILY_HIRE_RATE'];}else{$dailyhirey = $rowstc['DAILY_GROSS_HIRE_EST'];}

	$_SESSION['companyname']        =  $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME");
	$_SESSION['companyaddress']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1");
	$_SESSION['companycity']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY");
	$_SESSION['companycountry']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY");
	$_SESSION['companycode']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE");
	$_SESSION['companyemail']       = $obj->getVendorListNewData($rows['SHIP_OWNER'],"EMAILID");
	$_SESSION['companytel']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PHONE");
	$_SESSION['companyvat']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
	$_SESSION['companyfax']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FAX");
    $_SESSION['footeraddr']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
	$_SESSION['vendorlogo']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");
	
	$vlsImoId 						= $obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID");
	
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
		if($rows['RDOVATGST'] == 1)
		{
			$_SESSION['taxno2'] = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}else{
			$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}
	}else{
		 $_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) :';
	}

	class PDF extends FPDF_Protection
	{
	function Header()
	{
		$image_path1 = '../../img/'.$_SESSION['vendorlogo'];
		$this->Image($image_path1,10,2,190,23);
		$this->AddFont("CalibriBold",'',"CalibriBold.php");
		
		$this->SetY(29);
		$this->SetFont('CalibriBold','',17);
		$this->SetTextColor(0,0,0);
		$arr1=array('C');
		$arr2=array(190);
		$this->SetAligns($arr1);
		$this->SetWidths($arr2);
		$this->Row1(array("HIRE INVOICE"));	
			
	}
	
	function Footer()
	{
		$this->SetY(-25);
		$this->SetFillColor(255,255,255);
		$this->SetTextColor(177,175,175);
		$this->SetX(0);
		
		$this->Ln(1);
		$this->AddFont("CalibriBold",'',"CalibriBold.php");
		$this->AddFont("Calibri",'',"Calibri.php");
		$this->SetFont('CalibriBold','',11);
		$this->SetTextColor(027,119,166);
		$this->Ln(1);
		$this->Cell(0,5,$_SESSION['companyname'],0,1,'C');
		$this->Ln(1);
		$this->SetFont('Calibri','',11);
		$this->Cell(0,4,$_SESSION['footeraddr'],0,1,'C');
		$this->Cell(0,4,"Tel: ".$_SESSION['companytel']." | Fax: ".$_SESSION['companyfax'],0,1,'C');
		$this->Cell(0,4,"Email: ".$_SESSION['companyemail']." | Web: www.actship.com",0,1,'C');
		
	}
}	
	
	$pdf = new PDF();
	$pdf->SetProtection(array('print'),$pdfpassword);
	$pdf->AddPage('P');
	
	if($rows['INVOICE_TYPE']=='Credit'){
		$invtitle = 'Credit Note';
		$inv_amt_title = 'to Credit';
	}else{
		$invtitle = 'Invoice';
		$inv_amt_title = 'Invoiced';
	}
	
	$pdf->SetDisplayMode('real','single');
	$pdf->SetTitle('Generate TC Hire '.$invtitle.' Pdf');
	$pdf->SetAuthor('Seven Oceans Holdings');
	$pdf->SetSubject('Generate TC Hire '.$invtitle.' Pdf');
	$pdf->SetKeywords('Designed and Developed By Seven Oceans Holdings pvt. Ltd.');
	
	
	$pdf->AddFont("CalibriBold",'',"CalibriBold.php");
	$pdf->AddFont("Calibri",'',"Calibri.php");
	
	
	//---------------------------------------------------------------
	$pdf->Ln(2);
	$gety = $pdf->GetY();
	
	
	$pdf->SetFont('Calibri','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L','R','R');
	$arr2=array(14,121,25,30);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$invdate = date('d M Y',strtotime($rows['INVOICE_DATE'])); if($invdate=='01 January 1970'){$invdate = '';}
	$cpdate = date('d M Y',strtotime($obj->getFun9())); if($cpdate=='01 January 1970'){$cpdate = '';}
	
	$pdf->Row1(array("To        : ",$obj->getVendorListNewBasedOnID($vendorid).", ".stripslashes($obj->getVendorDataBasedOnID($vendorid,'STREET_1')),"Invoice No. : ",$rows['INVOICE_NO'].' '));
	$pdf->Ln(1);
	
	$pdf->SetFont('Calibri','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','L','R','R');
	$arr2=array(14,121,25,30);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("Vessel : ",$obj->getVesselIMOData($obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME")."                TC No. : ".$obj->getFun7()."                CP Date : ".$cpdate,"SOA Date : ",$invdate.' '));
	
	$gety1 = $pdf->GetY();
	$pdf->Ln(-($gety1 - $gety));
    $pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
	
	//--------------------------------------------------------------
	$gety = $pdf->GetY();
	$pdf->Ln(2);
	
	$pdf->SetFont('Calibri','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','R','R');
	$arr2=array(120,35,35);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array("ON-HIRE DETAILS","",""));
	
	
	if($rows['HIRE_FROM_DATE']=='0000-00-00 00:00:00' || $rows['HIRE_FROM_DATE']=='1970-01-01 08:00:00'){$hirefrom = '';}else{$hirefrom = date('d-m-Y H:i',strtotime($rows['HIRE_FROM_DATE']));}
	if($rows['HIRE_TO_DATE']=='0000-00-00 00:00:00' || $rows['HIRE_TO_DATE']=='1970-01-01 08:00:00'){$hireto = '';}else{$hireto = date('d-m-Y H:i',strtotime($rows['HIRE_TO_DATE']));}
	
	$pdf->SetFont('Calibri','',10);
	
	$sql2 = "select SUM(OFF_DAYS) as OFFHIREDAYS from invoice_tchire_slave4 where INVOICEID='".$rows['INVOICEID']."'";
    $res2 = mysql_query($sql2);
    $rows2 = mysql_fetch_assoc($res2);
	
	$pdf->SetFont('Calibri','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','R','R','R');
	$arr2=array(70, 50, 35, 35);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);

	$hiredays = 0;
	$sqlslave = "select * from invoice_tchire_slave5 where INVOICEID='".$rows['INVOICEID']."'";
	$resultslave = mysql_query($sqlslave);
	$numslave = mysql_num_rows($resultslave);
	$kl = 0;$hirefrom = '';$hireto = '';
	if($numslave > 0)
	{
		while($rowsslave = mysql_fetch_assoc($resultslave))
		{
			$kl++;
			if($kl==1)
			{
				if($rowsslave['HIRE_FROM']=='0000-00-00 00:00:00' || $rowsslave['HIRE_FROM']=='1970-01-01 08:00:00' || $rowsslave['HIRE_FROM']=='1970-01-01 01:00:00'){$hirefrom = '';}else{$hirefrom = date('d-m-Y H:i',strtotime($rowsslave['HIRE_FROM']));}
			}
			if($rowsslave['HIRE_TO']!='0000-00-00 00:00:00' && $rowsslave['HIRE_TO']!='1970-01-01 08:00:00' && $rowsslave['HIRE_TO']!='1970-01-01 01:00:00'){$hireto = date('d-m-Y H:i',strtotime($rowsslave['HIRE_TO']));}
			$hiredays = $hiredays + $rowsslave['UTILISED_DAYS'];
		}
	}else
	{
		if($rows['HIRE_FROM_DATE']=='0000-00-00 00:00:00' || $rows['HIRE_FROM_DATE']=='1970-01-01 08:00:00'){$hirefrom = '';}else{$hirefrom = date('d-m-Y H:i',strtotime($rows['HIRE_FROM_DATE']));}
	    if($rows['HIRE_TO_DATE']=='0000-00-00 00:00:00' || $rows['HIRE_TO_DATE']=='1970-01-01 08:00:00'){$hireto = '';}else{$hireto = date('d-m-Y H:i',strtotime($rows['HIRE_TO_DATE']));}
		$hiredays = $rows['HIRE_DAYS'];
	}
	
	$pdf->Row1(array("Delivery : ".$obj->getFun44(),$hirefrom."  UTC", "Days On-hire : ", number_format(($hiredays + $rows2['OFFHIREDAYS']),5,'.',',').' Days '));
	$pdf->Row1(array("Re Delivery : ".$obj->getFun53(), $hireto."  UTC", "Days Off-hire : ", number_format($rows2['OFFHIREDAYS'],5,'.',',').' Days '));
	
	$pdf->Ln(2);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array("Net Days On Hire : ".number_format($hiredays,5,'.',',')." Days", "", ""));
	
	$gety1 = $pdf->GetY();
	$pdf->Ln(-($gety1 - $gety));
    $pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
	
	//---------------------------------------------------------
	
	$gety = $pdf->GetY();
	$lineid = 1;
	
	$pdf->SetFont('CalibriBold','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','L','R','R');
	$arr2=array(10,106,37,37);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("No", "Description", "Due to Owners", "Due to charterers "));
	
	$gety1 = $pdf->GetY();
	$pdf->Ln(-($gety1 - $gety));
    $pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
	
	$sumleft = $sumright = 0;
	
	
	//-------------------------------------------------------------------
	$gety = $pdf->GetY();
	
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Hire", "", ""));
	
	$pdf->SetFont('Calibri','',10);
	
	$sqlslave = "select * from invoice_tchire_slave5 where INVOICEID='".$rows['INVOICEID']."' and UTILISED_DAYS > 0";
	$resultslave = mysql_query($sqlslave);
	$numslave = mysql_num_rows($resultslave);
	if($numslave > 0)
	{
		while($rowsslave = mysql_fetch_assoc($resultslave))
		{
			$sql_2 = "select HIRE_RATE, RANDOMID from chartering_estimate_tc_slave8 where chartering_estimate_tc_slave8.TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."' and RANDOMID='".$rowsslave['RANDOMID']."'";	
			$result_2 = mysql_query($sql_2);
			$num_2 = mysql_num_rows($result_2);
			$rows_2 = mysql_fetch_assoc($result_2);
			
			$pdf->Row1(array("", $rowsslave['UTILISED_DAYS'].' Days   X   $ '.number_format($rows_2['HIRE_RATE'],2,'.',',').' Per Day', "$ ".number_format($rowsslave['HIRE_AMT'],2,'.',','), ""));
			$sumleft = $sumleft + $rowsslave['HIRE_AMT'];
			$pdf->Ln(1);
		}
	}else
	{
		if(date('d-m-Y',strtotime($rows['HIRE_FROM']))!='01-01-1970' && date('d-m-Y',strtotime($rows['HIRE_TO']))!='01-01-1970')
		{
			$hiredays = $rows['HIRE_DAYS'];
			$pdf->Row1(array("", $rows['HIRE_DAYS'].' Days   X   $ '.number_format($rowstc['DAILY_GROSS_HIRE_EST'],2,'.',',').' Per Day', "$ ".number_format($rows['HIRE_INV_AMT'],2,'.',','), ""));
			$sumleft = $sumleft + $rows['HIRE_INV_AMT'];
		}
	}
	
	/* $hiredays = $rows['HIRE_DAYS'];
	$pdf->Row1(array("", $rows['HIRE_DAYS'].' Days   X   $ '.number_format($rowstc['DAILY_GROSS_HIRE_EST'],2,'.',',').' Per Day', "$ ".number_format($rows['HIRE_INV_AMT'],2,'.',','), ""));
	$sumleft = $sumleft + $rows['HIRE_INV_AMT']; */
	
	
	
	
	//$pdf->Ln(1);
	$lineid++;
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Ballast Bonus", "", ""));
	
	if($rows['CHK_BALLAST_BONUS']==1 && $rowstc['BALLAST_BONUS_AMT']>0)
	{
		$pdf->SetFont('Calibri','',10);
		$pdf->Row1(array("", "", "$ ".number_format($rowstc['BALLAST_BONUS_AMT'],2,'.',','), ""));
		$sumleft = $sumleft + $rowstc['BALLAST_BONUS_AMT'];
	}
	
	$lineid++;
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Commission", "", ""));
	
	if($rows['ADDRESS_COMMISSION_AMOUNT']>0)
	{
		$pdf->SetFont('Calibri','',10);
		$pdf->Row1(array("", "Address         ".$rows['ADDRESS_COMMISSION']." %", "", "$ ".number_format($rows['ADDRESS_COMMISSION_AMOUNT'],2,'.',',').' '));
		$sumright = $sumright + $rows['ADDRESS_COMMISSION_AMOUNT'];
	}
	if($rows['BROKER_COMMISSION_AMOUNT']>0)
	{
		$pdf->Row1(array("", "Brokerage     ".$rows['BROKER_COMMISSION']." %", "", "$ ".number_format($rows['BROKER_COMMISSION_AMOUNT'],2,'.',',').' '));
		
		$sumright = $sumright + $rows['BROKER_COMMISSION_AMOUNT'];
	}
	
	
	//$pdf->Ln(1);
	$lineid++;
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Bunker on delivery", "", ""));
	
	if($rows['IS_DELIVERYBUNKERS']==1)
	{
		$pdf->SetFont('Calibri','',10);
		$sqltc4 = "SELECT BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY from invoice_tchire_slave2 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='DEL'";
		$restc4 	= mysql_query($sqltc4);
		$rectc4 	= mysql_num_rows($restc4);
		$delbunkeramt = 0;
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
		    $arr1=array('L','L','R','R','R');
			$arr2=array(10,20,33,33,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row1(array("", $obj->getBunkerGradeBasedOnID($rowstc4['BUNKERID']), $rowstc4['BUNKER_QTY']." MT @ ", "$ ".number_format($rowstc4['BUNKER_PRICE'],2,'.',',')." Per MT = ", "$ ".number_format($rowstc4['BUNKER_AMT'],2,'.',',')));
			$delbunkeramt = $delbunkeramt + $rowstc4['BUNKER_AMT'];
		}
		
		$pdf->SetFont('Calibri','',10);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','L','R','R');
		$arr2=array(10,106,37,37);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("", "", "$ ".number_format($delbunkeramt,2,'.',','), ""));
		$sumleft = $sumleft + $delbunkeramt;
	}
	
	
	//$pdf->Ln(1);
	$lineid++;
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Bunker on Re delivery", "", ""));
	if($rows['IS_REDELIVERYBUNKERS']==1)
	{
		$pdf->SetFont('Calibri','',10);
		$sqltc4 = "SELECT BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY from invoice_tchire_slave2 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='REDEL'";
		$restc4 	= mysql_query($sqltc4);
		$rectc4 	= mysql_num_rows($restc4);
		$delbunkeramt = 0;
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
		    $arr1=array('L','L','R','R','R');
			$arr2=array(10,20,33,33,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row1(array("", $obj->getBunkerGradeBasedOnID($rowstc4['BUNKERID']), $rowstc4['BUNKER_QTY']." MT @ ", "$ ".number_format($rowstc4['BUNKER_PRICE'],2,'.',',')." Per MT = ", "$ ".number_format($rowstc4['BUNKER_AMT'],2,'.',',')));
			$delbunkeramt = $delbunkeramt + $rowstc4['BUNKER_AMT'];
			
			if($pdf->GetY()>260)
			{
			    $gety1 = $pdf->GetY();
				$pdf->Ln(-($gety1 - $gety));
				$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			    $pdf->AddPage('P');
				$pdf->Ln(2);
				$gety = $pdf->GetY();
			} 
		}
		$pdf->SetFont('Calibri','',10);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','L','R','R');
		$arr2=array(10,106,37,37);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("", "", "", "$ ".number_format($delbunkeramt,2,'.',',').' '));
		$sumright = $sumright + $delbunkeramt;
		
		if($pdf->GetY()>260)
		{
			$gety1 = $pdf->GetY();
			$pdf->Ln(-($gety1 - $gety));
			$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			$pdf->AddPage('P');
			$pdf->Ln(2);
			$gety = $pdf->GetY();
		} 
	}
	
	
	//$pdf->Ln(1);
	$lineid++;
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Off-Hire Bunker Cost", "", ""));
	if($rows['IS_OFFHIRE']==1)
	{
		$pdf->SetFont('Calibri','',10);
		$sqltc1 = "SELECT BUNKERID, BUNKER_PRICE from invoice_tchire_slave41 where INVOICEID='".$rows['INVOICEID']."' GROUP BY BUNKERID";
		$restc1 	= mysql_query($sqltc1);
		$rectc1 	= mysql_num_rows($restc1);
		$delbunkeramt = 0;
		while($rowstc1 = mysql_fetch_assoc($restc1))
		{
			$sqltc4 = "SELECT SUM(BUNKER_QTY) as BUNKER_QTY, SUM(BUNKER_AMT) as BUNKERAMT from invoice_tchire_slave41 where INVOICEID='".$rows['INVOICEID']."' and BUNKERID='".$rowstc1['BUNKERID']."'";
			$restc4 	= mysql_query($sqltc4);
			$rectc4 	= mysql_num_rows($restc4);
			
			while($rowstc4 = mysql_fetch_assoc($restc4))
			{
				$arr1=array('L','L','R','R','R');
				$arr2=array(10,20,33,33,24);
				$pdf->SetAligns($arr1);
				$pdf->SetWidths($arr2);
				$pdf->Row1(array("", $obj->getBunkerGradeBasedOnID($rowstc1['BUNKERID']), $rowstc4['BUNKER_QTY']." MT @ ", "$ ".number_format($rowstc1['BUNKER_PRICE'],2,'.',',')." Per MT = ", "$ ".number_format($rowstc4['BUNKERAMT'],2,'.',',')));
				$delbunkeramt = $delbunkeramt + $rowstc4['BUNKERAMT'];
				
				if($pdf->GetY()>260)
				{
					$gety1 = $pdf->GetY();
					$pdf->Ln(-($gety1 - $gety));
					$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
					$pdf->AddPage('P');
					$pdf->Ln(2);
					$gety = $pdf->GetY();
					
				} 
			}
		}
		
		$pdf->SetFont('Calibri','',10);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','L','R','R');
		$arr2=array(10,106,37,37);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("", "", "", "$ ".number_format($delbunkeramt,2,'.',',').' '));
		$sumright = $sumright + $delbunkeramt;
		
		if($pdf->GetY()>260)
		{
			$gety1 = $pdf->GetY();
			$pdf->Ln(-($gety1 - $gety));
			$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			$pdf->AddPage('P');
			$pdf->Ln(2);
			$gety = $pdf->GetY();
			
		} 
	}
	
	
	//$pdf->Ln(1);
	$lineid++;
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Bunker Over Consumption as per Weather Routing", "", ""));
	if($rows['CHK_OVERCONSP']==1)
	{
		$pdf->SetFont('Calibri','',10);
		$sqltc4 = "SELECT BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY from invoice_tchire_slave2 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='OVERCONSP'";
		$restc4 	= mysql_query($sqltc4);
		$rectc4 	= mysql_num_rows($restc4);
		$delbunkeramt = 0;
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
		    $arr1=array('L','L','R','R','R');
			$arr2=array(10,20,33,33,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row1(array("", $obj->getBunkerGradeBasedOnID($rowstc4['BUNKERID']), $rowstc4['BUNKER_QTY']." MT @ ", "$ ".number_format($rowstc4['BUNKER_PRICE'],2,'.',',')." Per MT = ", "$ ".number_format($rowstc4['BUNKER_AMT'],2,'.',',')));
			$delbunkeramt = $delbunkeramt + $rowstc4['BUNKER_AMT'];
			
			if($pdf->GetY()>260)
			{
			    $gety1 = $pdf->GetY();
				$pdf->Ln(-($gety1 - $gety));
				$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			    $pdf->AddPage('P');
				$pdf->Ln(2);
				$gety = $pdf->GetY();
			} 
		}
		$pdf->SetFont('Calibri','',10);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','L','R','R');
		$arr2=array(10,106,37,37);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("", "", "", "$ ".number_format($delbunkeramt,2,'.',',').' '));
		$sumright = $sumright + $delbunkeramt;
		
		if($pdf->GetY()>260)
		{
			$gety1 = $pdf->GetY();
			$pdf->Ln(-($gety1 - $gety));
			$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			$pdf->AddPage('P');
			$pdf->Ln(2);
			$gety = $pdf->GetY();
		} 
	}
	
	
	//$pdf->Ln(1);
	$lineid++;
	$arr1=array('C','L','R','R');
	$arr2=array(10,106,37,37);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Cable/Victualing/Entertainment", "", ""));
	if($rows['CVE_AMOUNT']>0)
	{
		$pdf->SetFont('Calibri','',10);
		$cveamt = (($rows['CVE']*12)/365)*$hiredays;
		$pdf->Row1(array("", $rows['CVE_MONTH']." PER MONTH          ".$hiredays." Days", "$ ".number_format($rows['CVE_AMOUNT'],2,'.',','), ""));
		$sumleft = $sumleft + $rows['CVE_AMOUNT'];
	}
	
	//$pdf->Ln(1);
	$lineid++;
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Hold Cleaning", "", ""));
	$sqltc4 = "select * from invoice_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='HOLD_CLEANING' and AMOUNT>0";
	$restc4 	= mysql_query($sqltc4);
	$rectc4 	= mysql_num_rows($restc4);
	if($rectc4>0)
	{
		$pdf->SetFont('Calibri','',10);
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
			$arr1=array('C','L','R','R');
			$arr2=array(10,106,37,37);
			$pdf->SetAligns($arr1);
            $pdf->SetWidths($arr2);
			$pdf->Row1(array("", $rowstc4['DESCRIPTION'], "$ ".number_format($rowstc4['AMOUNT'],2,'.',','), ""));
			$sumleft = $sumleft + $rowstc4['AMOUNT'];
			
			if($pdf->GetY()>260)
			{
			    $gety1 = $pdf->GetY();
				$pdf->Ln(-($gety1 - $gety));
				$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			    $pdf->AddPage('P');
				$pdf->Ln(2);
				$gety = $pdf->GetY();
			} 
		}
	}
	
	
	//$pdf->Ln(1);
	$lineid++;
	$arr1=array('C','L','R','R');
	$arr2=array(10,106,37,37);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "On/Off hire survey", "", ""));
	$sqltc4 = "select * from invoice_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='HIRE_SURVEY' and AMOUNT>0";
	$restc4 	= mysql_query($sqltc4);
	$rectc4 	= mysql_num_rows($restc4);
	if($rectc4>0)
	{
		$pdf->SetFont('Calibri','',10);
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
			$arr1=array('C','L','R','R');
			$arr2=array(10,106,37,37);
			$pdf->SetAligns($arr1);
            $pdf->SetWidths($arr2);
			
			if($rowstc4['CHK_OWNER_ACC'] == 1)
			{
				$pdf->Row1(array("", $rowstc4['DESCRIPTION'], "$ ".number_format($rowstc4['AMOUNT'],2,'.',','), ""));
				$sumleft = $sumleft + $rowstc4['AMOUNT'];
			}else{
			    $pdf->Row1(array("", $rowstc4['DESCRIPTION'], "", "$ ".number_format($rowstc4['AMOUNT'],2,'.',',').' '));
				$sumright = $sumright + $rowstc4['AMOUNT'];

			}
			
			if($pdf->GetY()>260)
			{
			    $gety1 = $pdf->GetY();
				$pdf->Ln(-($gety1 - $gety));
				$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			    $pdf->AddPage('P');
				$pdf->Ln(2);
				$gety = $pdf->GetY();
			} 
		}
	}
	
	//$pdf->Ln(1);
	$lineid++;
	$arr1=array('C','L','R','R');
	$arr2=array(10,106,37,37);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Others", "", ""));
	$sqltc4 = "select * from invoice_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD' and AMOUNT>0";
	$restc4 	= mysql_query($sqltc4);
	$rectc4 	= mysql_num_rows($restc4);
	if($rectc4>0)
	{
		$pdf->SetFont('Calibri','',10);
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
			$arr1=array('C','L','R','R');
			$arr2=array(10,106,37,37);
			$pdf->SetAligns($arr1);
            $pdf->SetWidths($arr2);
			$pdf->Row1(array("", $rowstc4['DESCRIPTION'], "$ ".number_format($rowstc4['AMOUNT'],2,'.',','), ""));
			$sumleft = $sumleft + $rowstc4['AMOUNT'];
			
			if($pdf->GetY()>260)

			{
			    $gety1 = $pdf->GetY();
				$pdf->Ln(-($gety1 - $gety));
				$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			    $pdf->AddPage('P');
				$pdf->Ln(2);
				$gety = $pdf->GetY();
			} 
		}
	}
	
	
	//$pdf->Ln(1);
	$lineid++;
	$arr1=array('C','L','R','R');
	$arr2=array(10,106,37,37);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->Row1(array($lineid, "Others", "", ""));
	
	$sqltc4 = "select * from invoice_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0";
	$restc4 	= mysql_query($sqltc4);
	$rectc4 	= mysql_num_rows($restc4);
	if($rectc4>0)
	{	
		$pdf->SetFont('Calibri','',10);
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
		    $pdf->SetFont('Calibri','',10);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('C','L','R','R');
			$arr2=array(10,106,37,37);
			$pdf->SetAligns($arr1);
		    $pdf->SetWidths($arr2);
			$pdf->Row1(array("", $rowstc4['DESCRIPTION'], "", "$ ".number_format($rowstc4['AMOUNT'],2,'.',',').' '));
			$sumright = $sumright + $rowstc4['AMOUNT'];
			
			if($pdf->GetY()>260)
			{
			    $gety1 = $pdf->GetY();
				$pdf->Ln(-($gety1 - $gety));
				$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
			    $pdf->AddPage('P');
				$pdf->Ln(2);
				$gety = $pdf->GetY();
			} 
		}
	}
	
	//$pdf->Ln(1);
	$pdf->SetX(80);
	$pdf->Cell(46, 5, 'Sum', 'T', 0, 'L');
	$pdf->Cell(37, 5, "$ ".number_format($sumleft,2,'.',','), 'T', 0, 'R');
	$pdf->Cell(37, 5, "$ ".number_format($sumright,2,'.',',').' ', 'T', 1, 'R');
	
	$pdf->SetX(80);
	$pdf->Cell(46, 5, 'Total Payable To Owners', '0', 0, 'L');
	$pdf->Cell(37, 5, '', '0', 0, 'R');
	$pdf->Cell(37, 5, "$ ".number_format(($sumleft - $sumright),2,'.',',').' ', '0', 1, 'R');

	
	$gety1 = $pdf->GetY();
	$pdf->Ln(-($gety1 - $gety));
    $pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
	
	
	$sqlprev = "SELECT * from invoice_tchire_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and STATUS=5 and INVOICEID<'".$rows['INVOICEID']."' order by INVOICEID ASC";
	$resprev = mysql_query($sqlprev);
	$recprev = mysql_num_rows($resprev);
	
	$receivedamt = 0;
	
	if($recprev > 0)
	{
	    $rowheight = $recprev*5 + $pdf->GetY();
		
		if($rowheight > 260)
		{
			$pdf->AddPage('P');
			$pdf->Ln(2);
			$gety = $pdf->GetY();
		} 
		else
		{
		    $pdf->Ln(3);
			$gety = $pdf->GetY();
		}
		
		$lineid++;$receivedamt = 0;
		$arr1=array('C','L','R','R');
		$arr2=array(10,106,37,37);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->SetFont('CalibriBold','',10);
	    $pdf->Row1(array($lineid, "Payments ", "", ""));
		while($rowsprev = mysql_fetch_assoc($resprev))
		{$m++;
			$pdf->SetFont('Calibri','',10);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('L','L','R');
			$arr2=array(10,80,26);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$paymentdate = date('d-m-Y',strtotime($rowsprev['P_DATE']));
			if($paymentdate =='01-01-1970'){$paymentdate = '';}
			$pdf->Row1(array("", $rowsprev['INVOICE_NO'].' - '.$paymentdate ,"$ ".number_format($rowsprev['P_AMT'],2,'.',',').' '));
			
			$receivedamt = $receivedamt + $rowsprev['P_AMT']; 
		}
		
		
		$pdf->SetFont('CalibriBold','',10);
		$pdf->SetX(100);
		$pdf->Cell(26, 5, "$ ".number_format($receivedamt,2,'.',','), 'T', 0, 'R');
		$pdf->Cell(37, 5, '', '0', 0, 'R');
		$pdf->Cell(37, 5, "$ ".number_format($receivedamt,2,'.',',').' ', '0', 1, 'R');
		
		$sumright = $sumright + $receivedamt; 
		$gety1 = $pdf->GetY();
		$pdf->Ln(-($gety1 - $gety));
		$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
	}
	
	if($pdf->GetY()>255)
	{
		$pdf->AddPage('P');
		$pdf->Ln(2);
	} 
	$gety = $pdf->GetY();
	
	$pdf->SetFont('CalibriBold','',10);
	$pdf->SetX(80);
	$pdf->Cell(46, 5, 'Total After Payment', '0', 0, 'L');
	$pdf->Cell(37, 5, "$ ".number_format($sumleft,2,'.',','), '0', 0, 'R');
	$pdf->Cell(37, 5, "$ ".number_format($sumright,2,'.',',').' ', '0', 1, 'R');
	
	$pdf->SetX(80);
	$pdf->Cell(46, 5, 'Balance Due to (from) Owners', '0', 0, 'L');
	$pdf->Cell(37, 5, '', '0', 0, 'R');
	$pdf->Cell(37, 5, "$ ".number_format(($sumleft - $sumright),2,'.',',').' ', '0', 1, 'R');
	
	$sumright = $sumright + ($sumleft - $sumright);
	
	$pdf->SetX(80);
	$pdf->Cell(46, 5, '', '0', 0, 'L');
	$pdf->Cell(37, 5, "$ ".number_format($sumleft,2,'.',','), 'T', 0, 'R');
	$pdf->Cell(37, 5, "$ ".number_format($sumright,2,'.',',').' ', 'T', 1, 'R');
	
	
	$gety1 = $pdf->GetY();
	$pdf->Ln(-($gety1 - $gety));
	$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
	$pdf->Cell(46, 5, '*E&OE', 'T', 1, 'L');
	
	//-------------------------------------------------------------------
	
	$sqltc4 = "select * from invoice_tchire_slave4 where INVOICEID='".$rows['INVOICEID']."'";
	$restc4 	= mysql_query($sqltc4);
	$rectc4 	= mysql_num_rows($restc4);
	
	
	if($rectc4>0)
	{
	    if($pdf->GetY()>130)
		{
			$pdf->AddPage('P');
			$pdf->Ln(2);
		} 
		//$pdf->AddPage('P');
		//$pdf->Ln(11);
		
		$pdf->Ln(3);
		$gety = $pdf->GetY();
		$pdf->Ln(3);
		$arr1=array('C');
		$arr2=array(190);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->SetFont('CalibriBold','',14);
		$pdf->Row1(array("STATEMENT OF OFF-HIRE"));
		
		
		$pdf->Ln(3);
		$arr1=array('L');
		$arr2=array(190);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->SetFont('CalibriBold','',10);
		$pdf->Row1(array("OFF-HIRE"));
		
		// $pdf->Ln(2);
		
		// $pdf->SetFont('Calibri','',10);
		// $pdf->SetTextColor(0,0,0);
		// $arr1=array('C','C','C','C','R','L');
		// $arr2=array(10, 40, 10, 40, 25, 65);
		// $pdf->SetAligns($arr1);
		// $pdf->SetWidths($arr2);

		$pdf->Ln(2);
		
		$pdf->SetFont('Calibri','',10);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','C','C','C','R','L');
		$arr2=array(10, 30, 10, 30, 25, 75);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$i = 0;$sumdays = 0;
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{$i++;
		    $OFF_FROM = date('d-m-Y H:i',strtotime($rowstc4['OFF_FROM']));
			if($OFF_FROM=='01-01-1970 00:00' || $OFF_FROM=='01-01-1970 08:00' || $OFF_FROM=='01-01-1970 01:00'){$OFF_FROM = '';}
			$OFF_TO = date('d-m-Y H:i',strtotime($rowstc4['OFF_TO']));
			if($OFF_TO=='01-01-1970 00:00' || $OFF_TO=='01-01-1970 08:00' || $OFF_TO=='01-01-1970 01:00'){$OFF_TO = '';}
			$pdf->Row1(array($i.".", $OFF_FROM, "To", $OFF_TO, "X ".$rowstc4['OFF_HIRE_PERCENT']." %    =   ", number_format($rowstc4['OFF_DAYS'],5,'.',',')." Days, ".$rowstc4['OFF_REASON'].","." Amount: ".$rowstc4['OFF_HIRE']));
			$sumdays = $sumdays + $rowstc4['OFF_DAYS'];
		}
		
		
		$gety2 = $pdf->GetY();
		$pdf->SetFont('CalibriBold','',10);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','L');
		$arr2=array(10, 115, 65);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("", "TOTAL OFF-HIRE", number_format($sumdays,5,'.',',')." Days"));
		
		
		$gety3 = $pdf->GetY();
		$pdf->Ln(-($gety3 - $gety2));$pdf->SetX(20);
		$pdf->Cell(170,($gety3 - $gety2),"",1,1,'L',0);
		
		$sqltc5 = "select *, (select OFF_REASON from invoice_tchire_slave4 where invoice_tchire_slave4.INVOICE_SLAVE4ID=invoice_tchire_slave41.INVOICE_SLAVE4ID) as OFF_REASON from invoice_tchire_slave41 where INVOICEID='".$rows['INVOICEID']."'";
		$restc5 	= mysql_query($sqltc5);
		$rectc5 	= mysql_num_rows($restc5);
		if($rectc5 > 0)
		{
			$pdf->Ln(3);
			$arr1=array('L');
			$arr2=array(190);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->SetFont('CalibriBold','',10);
			$pdf->Row1(array("BUNKER CONSUMPTION DURING OFF-HIRE"));
			
			$pdf->Ln(2);
			
			$pdf->SetFont('Calibri','',10);
			$i = 0;$ifobunker = $mdobunker = 0;
			while($rowstc5 = mysql_fetch_assoc($restc5))
			{$i++;
							
				$pdf->SetTextColor(0,0,0);
				$arr1=array('C','L','L','L');
				$arr2=array(10, 30, 85, 65);
				$pdf->SetAligns($arr1);
				$pdf->SetWidths($arr2);
				$pdf->Row1(array($i.".", $obj->getBunkerGradeBasedOnID($rowstc5['BUNKERID'])."  : ", $rowstc5['OFF_REASON'], $rowstc5['BUNKER_QTY']. " MT,"."Amount:".$rowstc5['BUNKER_AMT']));
				
				if($obj->getBunkerGradeTypeBasedOnID($rowstc5['BUNKERID']) == 'IFO')
				{
				    $ifobunker = $ifobunker + $rowstc5['BUNKERQTY'];
				}
				if($obj->getBunkerGradeTypeBasedOnID($rowstc5['BUNKERID']) == 'MDO')
				{
				    $mdobunker = $mdobunker + $rowstc5['BUNKERQTY'];
				}
			}
			
			$dofobunkertext = '';
			$sqltc1 = "select * from invoice_tchire_slave41 where INVOICEID='".$rows['INVOICEID']."' GROUP BY BUNKERID";
			$restc1 	= mysql_query($sqltc1);
			$rectc1 	= mysql_num_rows($restc1);
			while($rowstc1 = mysql_fetch_assoc($restc1))
			{
			    $sqltc2 = "select SUM(BUNKER_QTY) as BUNKERQTY from invoice_tchire_slave41 where INVOICEID='".$rows['INVOICEID']."' and BUNKERID='".$rowstc1['BUNKERID']."'";
				$restc2 	= mysql_query($sqltc2);
				$rectc2 	= mysql_num_rows($restc2);
				while($rowstc2 = mysql_fetch_assoc($restc2))
				{
				    $dofobunkertext.='           '.$obj->getBunkerGradeBasedOnID($rowstc1['BUNKERID']).'  :  '.$rowstc2['BUNKERQTY'].' MT';
				}
			}
			
			$gety2 = $pdf->GetY();
			$pdf->SetFont('CalibriBold','',10);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('C','L');
			$arr2=array(10, 170);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row1(array("", "TOTAL OFF-HIRE BUNKER   ".$dofobunkertext));
			
			$gety3 = $pdf->GetY();
			$pdf->Ln(-($gety3 - $gety2));$pdf->SetX(20);
			$pdf->Cell(170,($gety3 - $gety2),"",1,1,'L',0);
			
		}
		
		$pdf->Ln(3);
		$gety1 = $pdf->GetY();
		$pdf->Ln(-($gety1 - $gety));
		$pdf->Cell(0,($gety1 - $gety),"",1,1,'L',0);
		
		$pdf->SetFont('CalibriBold','',10);
	
	    $pdf->Cell(0,6,"*E&OE ",0,1,'L',0);
	}
	
	
	$sql2 = "select * from banking_details where BD_ID='".$rows['BANKINGID']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	if($rows2['IFSC']!='')
	{
		$ifsc = '\nIFSC No.: .'.$rows2['IFSC'];
	}else{$ifsc = '';}
	
	if($pdf->GetY()>230)
	{
		$pdf->AddPage('P');
		$pdf->Ln(2);
	} 
	
	$pdf->Ln(3);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->SetTextColor(0,0,0);
	$pdf->Cell(190,6,"Banking Details",0,1,'L');
	
	$pdf->SetFont('Calibri','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L');
	$arr2=array(190);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	//$pdf->Row1(array($_SESSION['companyname']));$pdf->Ln(1);
	$pdf->Row1(array("BENEFICIARY NAME: ".$rows2['NAME']));$pdf->Ln(1);
	$pdf->Row1(array("BENEFICIARY BANK: ".$rows2['BANK']));$pdf->Ln(1);
	$pdf->Row1(array("ADDRESS: ".$rows2['B_ADDRESS']));$pdf->Ln(1);
	$pdf->Row1(array("ACCOUNT NUMBER: ".$rows2['AC_NO']));$pdf->Ln(1);
	$pdf->Row1(array("SWIFT CODE: ".$rows2['BANK_SWIFT_CODE']));$pdf->Ln(1);
	$pdf->Row1(array("IBAN No.: ".$rows2['IBAN_NO']));$pdf->Ln(1);
	$pdf->Row1(array($ifsc));


	if($rows2['C_BANK_NAME']!='')
	{
		$pdf->Ln(3);
		$pdf->SetFont('CalibriBold','',10);
		$pdf->SetTextColor(0,0,0);
		$pdf->Cell(190,6,"INTERMEDIARY BANK DETAILS:",0,1,'L');
		$pdf->SetFont('Calibri','',10);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L');
		$arr2=array(190);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("BANK NAME: ".$rows2['C_BANK_NAME']));$pdf->Ln(1);
		$pdf->Row1(array("ADDRESS: ".$rows2['CORRES_ADDRESS']));$pdf->Ln(1);
		$pdf->Row1(array("SWIFT CODE: ".$rows2['C_SWIFT_CODE']));$pdf->Ln(1);
		//$pdf->Row1(array("ACCOUNT NO: ".$rows2['B_ACNO']));$pdf->Ln(1);//

	
	}
	
	//
	$pdf->Ln(1);
	$pdf->SetFont('Calibri','',10);
	$pdf->SetTextColor(10,10,10);
	$pdf->Cell(0,6,"* This is a system generated ".strtolower($invtitle)." and no signatures are required",0,1,'L',0);

    $filename = "Hire ".$invtitle." TC (".$obj->getVesselIMOData($vlsImoId,"VESSEL_NAME").") ".date("d-m-Y",time()).".pdf";

    $pdf->Output($filename,'D');

}



function getFreightPdf()
{


		


		$obj = new data();
		$amttoword = new Numbertowordconversion();
		$obj->funConnect();


		$im_id = $_REQUEST['im_id'];
		$pdfpassword = $_REQUEST['pdfpassword'];

		$sql = "select * from freight_invoice_master where INVOICEID='".$im_id."'";
		
		$res = mysql_query($sql);
		$rows = mysql_fetch_assoc($res);



	if($rows['SHIP_OWNER']!='CH0146' && $rows['SHIP_OWNER']!='OB0147' && $rows['SHIP_OWNER']!='OB0149')
	{


			$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
			$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
			$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);
			
			$_SESSION['companyname']        =  $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME");
			$_SESSION['companyaddress']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1");
			$_SESSION['companycity']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY");
			$_SESSION['companycountry']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY");
			$_SESSION['companycode']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE");
			$_SESSION['companyemail']       = $obj->getVendorListNewData($rows['SHIP_OWNER'],"EMAILID");
			$_SESSION['companytel']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PHONE");
			$_SESSION['companyfax']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FAX");
			$_SESSION['companyvat']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
			$_SESSION['panno']              = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PANNO");
			$_SESSION['CINno']              = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CINNO");
			$_SESSION['footeraddr']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
			$_SESSION['vendorlogo']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");
			
			$vlsImoId 						= $obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID");
		
			if($rows['RDOTAXAPPLICABLE'] == 1)
			{
				if($rows['RDOVATGST'] == 1)
				{
					$_SESSION['taxno2'] = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
				}else{
					$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
				}
			}else{
				$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) :';
			}
		
			if($rows['I_TYPE']=='Credit'){
				$invtitle = 'Credit Note';
				$invtitleType = 'Credit Note';
				$inv_amt_title = 'to Credit';
			}else{
				$invtitle = 'Invoice';
				if($rows['I_TYPE']=='Interim'){$invtitleType = 'TAX INVOICE - FREIGHT';}else{$invtitleType = 'TAX INVOICE - FREIGHT';}
				$inv_amt_title = 'Invoiced';
			}
		
				class PDF extends FPDF_Protection
				{
					function Header()
					{

						
						$image_path1 = '../../img/'.$_SESSION['vendorlogo'];


						$this->Image($image_path1,10,2,140,22);
						$this->AddFont("CalibriBold",'',"CalibriBold.php");
						$this->AddFont("Calibri",'',"Calibri.php");
						
						$this->SetFillColor(255,255,255);
						$this->SetTextColor(45,45,45);
						$this->SetFont('CalibriBold','',9);
						$this->Ln(3);
						if($_SESSION['companyvat']!=''){$headertext1 = "GSTIN : ".$_SESSION['companyvat'];}
						if($_SESSION['panno']!=''){$headertext2 = "PAN NO : ".$_SESSION['panno'];}
						if($_SESSION['CINno']!=''){$headertext3 = "CIN NO : ".$_SESSION['CINno'];}
						$this->Cell(0,4,$headertext1,0,1,'R');
						$this->Cell(0,4,$headertext2,0,1,'R');
						$this->Cell(0,4,$headertext3,0,1,'R');
						$this->SetY(15);
					}
					
					function Footer()
					{
						$this->SetY(-10);
						$this->SetFillColor(255,255,255);
						$this->SetTextColor(177,175,175);
						
						$this->AddFont("CalibriBold",'',"CalibriBold.php");
						$this->AddFont("Calibri",'',"Calibri.php");
						$this->SetTextColor(027,119,166);
						
						$this->SetFont('Calibri','',9);
						$this->Cell(0,3,$_SESSION['footeraddr'],0,1,'C');
						$this->Cell(0,3,"Tel: ".$_SESSION['companytel']." | Fax: ".$_SESSION['companyfax'],0,1,'C');
						$this->Cell(0,3,"Email: ".$_SESSION['companyemail']." | Web: www.actship.com",0,1,'C');
					}
				}
		
				$quantity = $totalfreight = $freightrate = 0;$maincargoid = 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='".$rows['RANDOMID']."' and STATUS=1";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
					{
						$quantity = $row12['sum2'];
					}
					else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
					{
						$quantity = $row12['sum2'];
					}
					else
					{
					$quantity = $row12['sum1'];
					}
					$totalfreight = $row12['SUM3'];
					$freightrate = $row12['SUM4'];
					$maincargoid = $row12['CARGOID'];
				}
			else
			{
					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");
					
					if($obj->getFun228()==1)
					{
					if($obj->getFun171()==1)
					{
						$totalfreight = $obj->getFun172();
						$freightrate = '';
						$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
					}else
					{
						$res1_1 = mysql_query("select * from freight_cost_estimete_slave12 where FCAID='".$obj->getFun1()."' and CUSTOMER = '".$rows['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='".$rows['RANDOMID']."' and STATUS=1";
						$res12 = mysql_query($sql12);
						$row12 = mysql_fetch_assoc($res12);
						if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
						{
							$quantity = $row12['sum2'];
						}
						else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
						{
							$quantity = $row12['sum2'];
						}
						else
						{
							$quantity = $row12['sum1'];
						}
						$totalfreight = $row12['SUM3'];
						$maincargoid = $row12['CARGOID'];
					}
				}
				else
				{
						if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
						{
							$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
							$totalfreight = $obj->getCompareEstimateData($rows['COMID'],"TOTAL_PREIGHT_ADJ");
							$freightrate = $obj->getCompareEstimateData($rows['COMID'],"FREIGHT_GROSS");
							$maincargoid = $obj->getCompareEstimateData($rows['COMID'],"CARGO_ID");
						}
						else
						{
							$sql12 = "select QUANTITY, GROSS_FREIGHT, AGREED_GROSS_FREIGHT, CARGO, addnlCargoQty from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and RANDOMID='".$rows['RANDOMID']."'";
							
							$res12 = mysql_query($sql12) or die($sql12);
							$row12 = mysql_fetch_assoc($res12);
							$quantity = $row12['QUANTITY'] + $row12['addnlCargoQty'];
							$totalfreight = $row12['GROSS_FREIGHT'];
							$freightrate = $row12['AGREED_GROSS_FREIGHT'];
							$maincargoid = $row12['CARGO'];
						}
				}
			
			}
								
					
			$lp_name = array(); 
			$dp_name = array();
			$discharge_port = "";
		
			for($j=0;$j<count($arrports);$j++)
			{   
				$arr_explode = explode('@@',$arrports[$j]);
				if($arr_explode[0] == "LP"){$lp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
				if($arr_explode[0] == "DP"){$dp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
			}
		
			$lp_name  = implode(', ',$lp_name);
			$dp_name  = implode(', ',$dp_name);
			if($rows['LOAD_PORT_NAME']!='')
			{
				$lp_name = $rows['LOAD_PORT_NAME'];
			}
			if($rows['DISCHARGE_PORT_NAME']!='')
			{
				$dp_name = $rows['DISCHARGE_PORT_NAME'];
			}
		
			if($obj->getFun175()!='')
			{
				$sqlcoa = "select * from coa_master where COAID='".$obj->getFun175()."'";
				$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
				$rowscoa   = mysql_fetch_assoc($resultcoa);
				$currency = $rowscoa['CURRENCY'];
			}else
			{
				$currency = 'USD';
			}
		
			$pdf = new PDF();
			$pdf->SetProtection(array('print'),$pdfpassword);
			$pdf->AddPage('P');
			
			$pdf->AddFont("CalibriBold",'',"CalibriBold.php");
			$pdf->AddFont("Calibri",'',"Calibri.php");


			$pdf->SetDisplayMode('real','single');
			$pdf->SetTitle('Generate Freight '.$invtitle.' Pdf');
			$pdf->SetAuthor('Seven Oceans Holdings');
			$pdf->SetSubject('Generate Freight '.$invtitle.' Pdf');
			$pdf->SetKeywords('Designed and Developed By Seven Oceans Holdings pvt. Ltd.');
			
			$pdf->Ln(17);
			$initialY =  $pdf->GetY();
			
			$pdf->Ln(2);
			$pdf->SetFont('calibri','',11);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('L','L');
			$arr2=array(190);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$invdate = date('d M Y',strtotime($rows['DATE'])); if($invdate=='01-01-1970'){$invdate = '';}
			$pdf->Row1(array($invdate));
			$pdf->Ln(1);
			$pdf->Row1(array("To the attention of the Finance Manager"));
		
			$pdf->Ln(6);
			$pdf->Row1(array("Dear Sir/Madam,"));
			
			$pdf->Ln(14);
			$pdf->Row1(array('Not unlike many other companies in our industry, '.ucwords(strtolower($_SESSION['companyname'])).'. has been targeted by fraudsters who have sent us false payment requests purporting to be from our existing suppliers in the form of "revised invoices" or "changed payment instructions". We have recently been informed of fake invoices or fake changes to bank accounts being sent to customers. You have probably noticed an increased level of fraud attempts on your end as well.'));
			
			$pdf->Ln(2);
			$pdf->Row1(array('The purpose of this letter is to further raise awareness around this topic with our counterparties as well as to confirm our USD bank account details for the '.ucwords(strtolower($_SESSION['companyname'])).'.'));
			
			$pdf->Ln(14);
			
			$pdf->SetFont('CalibriBold','',11);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('L','L');
			$arr2=array(40,70);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
		
			$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
			$res2 = mysql_query($sql2);
			$rows2 = mysql_fetch_assoc($res2);
			
			$pdf->SetX(40);

			$pdf->Row1(array('BENEFICIARY', strtoupper($rows2['NAME'])));
			$pdf->SetX(40);
			$pdf->Row1(array('ACCOUNT NO.', strtoupper($rows2['AC_NO'])));
			$pdf->SetX(40);
			$pdf->Row1(array('BANK NAME', strtoupper($rows2['BANK'])));
			$pdf->SetX(40);
			$pdf->Row1(array('BRANCH', strtoupper($rows2['BRANCH'])));
			$pdf->SetX(40);
			$pdf->Row1(array('BANK ADDRESS', strtoupper($rows2['B_ADDRESS'])));
			$pdf->SetX(40);
			$pdf->Row1(array('SWIFT CODE', strtoupper($rows2['BANK_SWIFT_CODE'])));
			if($rows2['IBAN_NO']!='')
			{
				$pdf->SetX(40);
				$pdf->Row1(array('IBAN NO.', strtoupper($rows2['IBAN_NO'])));
			}
		
		
		$pdf->Ln(15);
		$pdf->SetFont('calibri','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','L');
		$arr2=array(190);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("Note: Please Make the Payment Specified to the Bank account mentioned in the freight Invoice. M/s ".ucwords(strtolower($_SESSION['companyname'])).", ".ucwords(strtolower($_SESSION['companycountry']))." will only use account holder as M/s. ".ucwords(strtolower($_SESSION['companyname']))." ,".ucwords(strtolower($_SESSION['companycountry']))."  and Our bank is ".ucwords(strtolower($rows2['BANK'])).". We will never request payment to another bank or other company on behalf of us to collect the remittance, if you received any invoice or payment request not matching with this information, please inform us immediately at chartaccounts@actship.com, Mobile No. +91-9824502029/ sekhar@actship.com, Mobile No.+91-9924295511. We will not be liable for any losses arising from failure to adhere to the above instructions. We recommend you to kindly check with us telephonically, before processing the funds. If required, we shall FAX the invoice to your office."));
		
		
		$pdf->Ln(50);
		$gety1 = $pdf->GetY();
		$pdf->Ln(-($gety1 - $initialY));
		$pdf->Cell(190,($gety1 - $initialY),"",1,1,'L',0);
		
		//$pdf->Row1(array('*E&OE'));
		$pdf->AddPage('P');
		
		$pdf->Ln(9);
		
		$pdf->SetFont('CalibriBold','',10);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C');
		$arr2=array(190);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array($invtitleType));
		
		$pdf->Ln(1);
		$initialY =  $pdf->GetY();
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','C','L','L','C','L');
		$arr2=array(22,7,65,25,7,65);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			if($rows['RDOVATGST'] == 1)
			{
				$taxno1 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
				$taxno2 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}else{
				$taxno1 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
				$taxno2 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}
		}else{
			$taxno1 = '';
			$taxno2 = '';
		}
		
		$supplydate = date('d-m-Y',strtotime($rows['SUPPLY_DATE'])); if($supplydate=='01-01-1970'){$supplydate = '';}
		$invdate = date('d-m-Y',strtotime($rows['DATE'])); if($invdate=='01-01-1970'){$invdate = '';}
		
		$invmonth = date('m',strtotime($rows['DATE']));
		$invyear = date('Y',strtotime($rows['DATE']));
		
		if($invmonth > 3)
		{
			$fyear = $invyear.' - '.($invyear + 1);
		}else{
			$fyear = ($invyear - 1).' - '.$invyear;
		}
		
		$pdf->Row1(array("Reverse Charges",":",($rows['REVERSE_CHARGE']==1)?'Yes':'No',"Service Description",":",$rows['REMARKS']));
		$pdf->Ln(-1);
		$pdf->Row1(array("Financial Year",":",$fyear,"Vehicle No.",":",$rows['VEHICLE_NO']));
		$pdf->Ln(-1);
		$pdf->Row1(array("Invoice No.",":",$rows['MESSAGE'],"Date Of Supply",":",$supplydate));
		$pdf->Ln(-1);
		$pdf->Row1(array("Invoice Date",":",$invdate,"Place Of Supply",":",$rows['SUPPLY_PLACE']));
		$pdf->Ln(-1);
		$pdf->Row1(array("Voyage No.",":",$obj->getFun8(),"","",""));
		$pdf->Ln(-1);
		$pdf->Row1(array("State",":",$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STATE')."              State Code:".$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STATE_CODE'),"","",""));
		
		$initialY1 =  $pdf->GetY();
		$ydifference = $initialY1 - $initialY;
		$pdf->Ln(-($initialY1 - $initialY));
		$pdf->Cell(22,($initialY1 - $initialY),"",1,0,'L',0);
		$pdf->Cell(7,$ydifference,"",1,0,'L',0);
		$pdf->Cell(65,$ydifference,"",1,0,'L',0);
		$pdf->Cell(25,$ydifference,"",1,0,'L',0);
		$pdf->Cell(7,$ydifference,"",1,0,'L',0);
		$pdf->Cell(65,$ydifference,"",1,1,'L',0);
		
		$initialY =  $pdf->GetY();
		
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','C','L','L','L','L','C','L','L','L');
		$arr2=array(22,7,24,17,24,25,7,24,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->Row(array("Vessel Name",":",$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME"),"Load Port :",$lp_name,"Commodity",":",$obj->getMaterialCodeDesBasedOnId($maincargoid),"Quantity :",$quantity.'MT'));
		$cpdate = date('d-m-Y',strtotime($obj->getFun9())); if($cpdate=='01-01-1970'){$cpdate = '';}
		$exchangedate = date('d-m-Y',strtotime($rows['EXCHANGE_DATE'])); if($exchangedate=='01-01-1970'){$exchangedate = '';}
		
		$pdf->Row(array("CP Date",":",$cpdate,"Discharge Port :",$dp_name,"Ex Rate(USD)",":",$rows['EXCHANGE_RATE'],"Date : ",$exchangedate));
		
		
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','C');
		$arr2=array(94,97);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->Row(array("Details of Receiver / Billed To","Details of Consignee / Shipped To"));
		
		$initialY =  $pdf->GetY();
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','C','L','L','C','L');
		$arr2=array(22,7,65,25,7,64);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("Name",":","M/S ".$obj->getVendorListNewBasedOnID($rows['VENDOR']),"Name",":","M/S ".$obj->getVendorListNewBasedOnID($rows['SHIPPER_VENDOR'])));
		$pdf->Ln(-1);
		$pdf->Row1(array("Address",":",stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'STREET_1'))).' '.stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'COUNTRY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY_POSTAL_CODE'))),"Address",":",stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STREET_1'))).' '.stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'CITY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'COUNTRY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'CITY_POSTAL_CODE')))));
		$pdf->Ln(-1);
		$pdf->Row1(array("PAN",":",$obj->getVendorDataBasedOnID($rows['VENDOR'],'PANNO'),"PAN",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'PANNO')));
		$pdf->Ln(-1);
		$pdf->Row1(array("GSTIN",":",$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER'),"GSTIN",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'VAT_NUMBER')));
		$pdf->Ln(-1);
		$pdf->Row1(array("State",":",$obj->getVendorDataBasedOnID($rows['VENDOR'],'STATE')."               State Code : ".$obj->getVendorDataBasedOnID($rows['VENDOR'],'STATE_CODE'),"State",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STATE')."               State Code : ".$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STATE_CODE')));
		
		$initialY1 =  $pdf->GetY();
		$ydifference = $initialY1 - $initialY;
		$pdf->Ln(-($initialY1 - $initialY));
		$pdf->Cell(94,($initialY1 - $initialY),"",1,0,'L',0);
		$pdf->Cell(97,$ydifference,"",1,1,'L',0);
		
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','C','L','L','C','L');
		$arr2=array(94,97);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$bldate = date('d-m-Y',strtotime($rows['BL_DATE'])); if($bldate=='01-01-1970'){$bldate = '';}
		$pdf->Row(array("BL NO. : ".$rows['BL_NO'].',    Dtd : '.$bldate,""));
		
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','C','C','C','C','C','C');
		$arr2=array(22,72,25,7,24,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->Row(array("S.No.", "Particulars", ($rows['GST_PERCENT']>0)?"":"HSN/SAC", "UO", "QTY", "RATE", "Amount(USD)"));
		
		
		$initialY =  $pdf->GetY();
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','L','C','C','C','C','R');
		$arr2=array(22,72,25,7,24,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$i = 0;

       



		if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
		{
			
		}
		else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==3)
		{

			
            
			if($obj->getFun96()==1)
			{
				$i++;
				$pdf->Row1(array($i, "FREIGHT (".strtoupper($obj->getMaterialCodeDesBasedOnId($maincargoid)).')', $rows['HSN_SAC'], "MT", number_format($quantity,3,'.',','),$freightrate, number_format($obj->getFun66(),2,'.',',')));

				if($obj->getFun71() > 0){
					$i++;
					$pdf->Ln(-1);
					$pdf->Row1(array($i, "DF FREIGHT", $rows['HSN_SAC'], "MT", number_format($obj->getFun53(),3,'.',','),$freightrate, number_format($obj->getFun67(),2,'.',',')));
				}
			}
			else if($obj->getFun96()==2)
			{
				$i++;
				$pdf->Row1(array($i, "FREIGHT (".strtoupper($obj->getMaterialCodeDesBasedOnId($maincargoid)).')', $rows['HSN_SAC'], "MT", number_format($quantity,3,'.',','),$freightrate, number_format($obj->getFun66(),2,'.',',')));

				if($obj->getFun54()>0)
				{
					$i++;
					$pdf->Ln(-1);
					$pdf->Row1(array($i, "ADDITIONAL FREIGHT", $rows['HSN_SAC'], "MT", number_format($obj->getFun54(),3,'.',','),$obj->getFun49(), number_format($obj->getFun68(),2,'.',',')));
				}
			}
			else
			{
				$i++;

				$sqldis = "select * from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and QTY_VENDORID='".$rows['VENDOR']."' and RANDOMID='".$rows['RANDOMID']."'";
				$resdis = mysql_query($sqldis);
				while($rowsdis = mysql_fetch_assoc($resdis))
				{
					$pdf->Ln(-1);

					$totalGrossFreight = $rowsdis['AGREED_GROSS_FREIGHT'] * $rowsdis['QUANTITY'];

					$totalAddnlGrossFreight = $rowsdis['addnlCargoRate'] * $rowsdis['addnlCargoQty'];

					$pdf->Row1(array($i, "FREIGHT (".strtoupper($obj->getMaterialCodeDesBasedOnId($rowsdis['CARGO'])).')', $rows['HSN_SAC'], "MT", number_format($rowsdis['QUANTITY'],3,'.',','),$freightrate, number_format($totalGrossFreight,2,'.',',')));

					if($rowsdis['addnlCargoRate']>0)
					{
						$pdf->Row1(array('',"FREIGHT FOR ADDITIONAL CARGO (".strtoupper($obj->getMaterialCodeDesBasedOnId($rowsdis['CARGO'])).')', $rows['HSN_SAC'], "MT", number_format($rowsdis['addnlCargoQty'],3,'.',','), $rowsdis['addnlCargoRate'], number_format($totalAddnlGrossFreight,2,'.',',')));
					}
				}

				$sqlclub = "select * from freight_invoice_slave1 where INVOICEID='".$rows['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++;
						$pdf->Ln(-1);
						$pdf->Row1(array($i, "FREIGHT FOR ADDITIONAL CARGO (".strtoupper($obj->getMaterialCodeDesBasedOnId($rowsclub['CARGO'])).')', $rows['HSN_SAC'], "MT", number_format($rowsclub1['QUANTITY'],3,'.',','), number_format($rowsclub1['AGREED_GROSS_FREIGHT'],4,'.',','), number_format($rowsclub1['NET_FREIGHT'],2,'.',',')));
					}
				}
					
			}
		}
		
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','R','C','C','C','C','R');
		$arr2=array(22,72,25,7,24,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		if($rows['TO_1']<100)
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("", "100% FREIGHT ".number_format($rows['GROSS_FREIGHT'],2,'.',','), '','','','', ''));
		}
		$pdf->Ln(-1);
		$pdf->Row1(array("", "OCEAN FREIGHT (".$rows['TO_1']."% FREIGHT AMOUNT", '', '', '', '',number_format($rows['NET_AMOUNT'],2,'.',',')));
		
		$amount = $rows['NET_AMOUNT'];
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','L','C','C','C','C','R');
		$arr2=array(22,72,25,7,24,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$sql2 = "select * from freight_invoice_slave3 where INVOICEID='".$rows['INVOICEID']."'";
		$res2 = mysql_query($sql2);
		$num2 = mysql_num_rows($res2);
		
		$array_number = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l');
		$index = 0;
		if($num2>0)
		{
			$pdf->SetFont('CalibriBold','',8);
			$pdf->Ln(-1);
			$pdf->Row1(array("", strtoupper("Demurrage/Dispatch:"),"","","",""));
			
			$pdf->SetFont('Calibri','',8);
		}

		$res21 = mysql_query($sql2);
		while($rows21 = mysql_fetch_assoc($res21))
		{
			if($rows21['PORT']=='LP')
			{
				if($rows21['DEM_AMT']>0)
				{
					$pdf->Ln(-1);
					$pdf->Row1(array($array_number[$index], "      Load Port ".$obj->getPortNameBasedOnID($rows21['PORTID']), '', '', '',number_format($rows21['DEM_AMT'],2,'.',',')));
					$index++;
				}else{
					$pdf->Ln(-1);
					$pdf->Row1(array($array_number[$index], "      Load Port ".$obj->getPortNameBasedOnID($rows21['PORTID']), '', '', '',str_replace("-","",number_format($rows21['DEM_AMT'],2,'.',','))));
					$index++;
				}  
				$amount = $amount + $rows21['DEM_AMT'];
			}
			
			if($rows21['PORT']=='DP')
			{
				if($rows21['DEM_AMT']>0)
				{
					$pdf->Ln(-1);
					$pdf->Row1(array("", $array_number[$index]." Discharge Port ".$obj->getPortNameBasedOnID($rows21['PORTID']), '', '', '',number_format($rows21['DEM_AMT'],2,'.',',')));
					$index++;
				}else{
					$pdf->Ln(-1);
					$pdf->Row1(array("", $array_number[$index]." Discharge Port ".$obj->getPortNameBasedOnID($rows21['PORTID']), '', '', '',"(-) ".str_replace("-","",number_format($rows21['DEM_AMT'],2,'.',','))));
					$index++;
				}  
				$amount = $amount + $rows21['DEM_AMT'];
			}
		}
		
		if($rows['ADDCOM_AMOUNT'] > 0)
		{
			$pdf->SetFont('Calibri','',8);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('C','L','C','C','C','C','R');
			$arr2=array(22,72,25,7,24,17,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Ln(-1);
			$pdf->Row1(array("", "(".$array_number[$index].") Less ".$rows['ADDCOM']."% ADD COMM ON 100% FREIGHT", '', '', '', '',number_format($rows['ADDCOM_AMOUNT'],2,'.',',')));
			$index++;
			$amount = $amount - $rows['ADDCOM_AMOUNT'];
		}
		
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','R','C','C','C','C','R');
		$arr2=array(22,72,25,7,24,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->SetX(177);
		$pdf->Cell(24, 1, '', 'T', 1, 'L');
		$pdf->Ln(-1);
		$pdf->Row1(array("", "SUB TOTAL", '', '', '', '',number_format($amount,2,'.',',')));
		
		
		
		if($rows['BROKERAGE'] > 0)
		{
			$pdf->SetFont('Calibri','',8);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('C','L','C','C','C','C','R');
			$arr2=array(22,72,25,7,24,17,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Ln(-1);
			$pdf->Row1(array("", "(".$array_number[$index].") Less BROKERAGE(".$rows['BROKERAGE_PERCENT']."%)", '', '', '', '',number_format($rows['BROKERAGE'],2,'.',',')));
			$index++;
		}
		
		$sql2 = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD' and AMOUNT>0";
		$res2 = mysql_query($sql2);
		$num2 = mysql_num_rows($res2);

		
		while($rows2 = mysql_fetch_assoc($res2))
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("", $rows2['DESCRIPTION'], '', '', '', '',number_format($rows2['AMOUNT'],2,'.',',')));
		}
		
		$sql2 = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0";
		$res2 = mysql_query($sql2);
		$num2 = mysql_num_rows($res2);
			
		while($rows2 = mysql_fetch_assoc($res2))
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("","Less ".$rows2['DESCRIPTION'], '', '', '', '',number_format($rows2['AMOUNT'],2,'.',',')));
		}
		
		
		$initialY1 =  $pdf->GetY();
		$ydifference = $initialY1 - $initialY;
		$pdf->Ln(-($initialY1 - $initialY));
		$pdf->Cell(22,($initialY1 - $initialY),"",1,0,'L',0);
		$pdf->Cell(72,$ydifference,"",1,0,'L',0);
		$pdf->Cell(25,$ydifference,"",1,0,'L',0);
		$pdf->Cell(7,$ydifference,"",1,0,'L',0);
		$pdf->Cell(24,$ydifference,"",1,0,'L',0);
		$pdf->Cell(17,$ydifference,"",1,0,'L',0);
		$pdf->Cell(24,$ydifference,"",1,1,'L',0);
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('R','R','R');
		$arr2=array(150,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$initialY =  $pdf->GetY();
		
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("Total value       ",number_format($rows['NET_PAYABLE'],2,'.',',')));
			$pdf->SetFont('Calibri','',8);
			if($rows['RDOVATGST'] == 1)
			{
				if($rows['GST_PERCENT']>0)
				{
					$pdf->Cell(150,4,"Total GST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['GST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['GST_PERCENT_AMOUNT'],2,'.',','),0,1,'R',0);
				}
				if($rows['IGST_PERCENT']>0)
				{
					$pdf->Cell(150,4,"Total IGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['IGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',','),0,1,'R',0);
				}
				if($rows['SGST_PERCENT']>0)
				{   
					$pdf->Cell(150,4,"Total SGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['SGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['SGST_PERCENT_AMOUNT'],2,'.',','),0,1,'R',0);
				}
				if($rows['CGST_PERCENT']>0)
				{
					$pdf->Cell(150,4,"Total CGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['CGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['CGST_PERCENT_AMOUNT'],2,'.',','),0,1,'R',0);
				}
			}else{
				if($rows['VAT_PERCENT']>0)
				{
					$pdf->Cell(150,4,"Total VAT          ",0,0,'R',0);$pdf->Cell(17,4,$rows['VAT_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['VAT_PERCENT_AMOUNT'],2,'.',','),0,1,'R',0);
				}
			}
		}
		
		
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('R','R','R');
		$arr2=array(150,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$sqlprev = "select * from freight_invoice_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR = '".$rows['VENDOR']."' and P_TYPE='".$rows['P_TYPE']."' and CARGOID='".$rows['CARGOID']."' and RANDOMID='".$rows['RANDOMID']."' and STATUS=5 and INVOICEID<'".$rows['INVOICEID']."'";
		$resprev = mysql_query($sqlprev) or die($sqlprev);
		while($rowsprev = mysql_fetch_assoc($resprev))
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("INITIAL FREIGHT RECEIVED          ", "", "(-) ".number_format($rowsprev['P_AMT'],2,'.',',')));
		}
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetX(177);
		$pdf->Cell(24, 1, '', 'T', 1, 'L');
		$pdf->Ln(-1);
		$pdf->Row1(array("Grand Total (".$currency.")       ", "",number_format($rows['NET_PAYABLE_TAX'],2,'.',',')));
		
		
		
		$pdf->SetX(177);
		$pdf->Cell(24, 1, '', 'T', 1, 'L');
		
		if($rows['EXCHANGE_RATE']!=1)
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("Grand Total (".$rows['EXCHANGE_CURRENCY'].")       ", "",number_format(($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE']),2,'.',',')));
			$pdf->SetX(177);
			$pdf->Cell(24, 1, '', 'T', 1, 'L');
		}
		
		$pdf->SetX(177);
		$pdf->Cell(24, 1, '', 'T', 1, 'L');
		
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','R','R');
		$arr2=array(150,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Ln(-1);
		$pdf->Row1(array("AMOUNT IN WORDS : ".strtoupper($amttoword->convert_number_to_words($rows['NET_PAYABLE_TAX'],$currency)), '', ''));
		if($rows['EXCHANGE_RATE']!=1)
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("AMOUNT IN WORDS : ".strtoupper($amttoword->convert_number_to_words(number_format($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE'],2,'.',''),$rows['EXCHANGE_CURRENCY'])), '', ''));
		}
		
		$initialY1 =  $pdf->GetY();
		$ydifference = $initialY1 - $initialY;
		$pdf->Ln(-($initialY1 - $initialY));
		$pdf->Cell(150,($initialY1 - $initialY),"",1,0,'L',0);
		$pdf->Cell(17,$ydifference,"",1,0,'L',0);
		$pdf->Cell(24,$ydifference,"",1,1,'L',0);
		
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L');
		$arr2=array(191);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		
		$pdf->Cell(191,4,"E & OE",1,1,'L',0);
		$pdf->Cell(191,4,"BANKING DETAILS:",1,1,'L',0);
		
		$initialY =  $pdf->GetY();
		
		$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
		$res2 = mysql_query($sql2);
		$rows2 = mysql_fetch_assoc($res2);
		
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L',"C","L");
		$arr2=array(25,6, 165);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->Cell(25,4,"BENEFICIARY",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['NAME'],0,1,'L',0);
		$pdf->Cell(25,4,"ACCOUNT NO",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['AC_NO'],0,1,'L',0);
		$pdf->Cell(25,4,"BANK NAME",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BANK'],0,1,'L',0);
		$pdf->Cell(25,4,"BRANCH",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BRANCH'],0,1,'L',0);
		$pdf->Cell(25,4,"BANK ADDRESS",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['B_ADDRESS'],0,1,'L',0);
		
		if($rows2['BANK_SWIFT_CODE']!='')
		{
			$pdf->Cell(25,4,"SWIFT CODE",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BANK_SWIFT_CODE'],0,1,'L',0);
		}
		if($rows2['IFSC']!='')
		{
			$pdf->Cell(25,4,"IFSC/NEFT Code",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['IFSC'],0,1,'L',0);
		}
		if($rows2['IBAN_NO']!='')
		{
			$pdf->Cell(25,4,"IBAN NO.",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['IBAN_NO'],0,1,'L',0);
		}
		
		$initialY1 =  $pdf->GetY();
		$ydifference = $initialY1 - $initialY;
		$pdf->Ln(-($initialY1 - $initialY));
		$pdf->Cell(191,($initialY1 - $initialY),"",1,1,'L',0);
		
		$pdf->SetFont('CalibriBold','',9);
		$pdf->SetTextColor(10,10,10);
		$pdf->Cell(0,5,"FOR ".strtoupper($_SESSION['companyname']),0,1,'R',0);
		
		
		if($pdf->GetY()>245)
		{
			$pdf->AddPage('P');
		
			$pdf->Ln(9);
		}
		$pdf->Ln(12);
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetTextColor(10,10,10);
		//$pdf->Cell("",1,1,'L',0);
		$pdf->SetX(10);
		$pdf->MultiCell(191,4,addslashes("Note: Please make the payment specified to the bank account mentioned in the Freight Invoice.\nM/s ".$_SESSION['companyname'].' India will only use account holder as M/s '.$_SESSION['companyname'].' India & our banker is '.$rows2['BANK'].". We will never request payment to another bank or other company on behalf of us to collect the remittance, if you received any invoice or payment request not matching with this information, please inform us immediately at /chartaccounts@actship.com/accounts.gim@actship.com. We will not be liable for any losses arising from failure to adhere to the above instructions. We recommed you to kindly check with us telephonically, before processing the funds. If required we shall FAX the invoice to your office."),0,'L',false);
		

	}
	else
	{
	
		$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
		$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
		$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);
		
		$_SESSION['companyname']        =  $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME");
		$_SESSION['companyaddress']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1");
		$_SESSION['companycity']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY");
		$_SESSION['companycountry']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY");
		$_SESSION['companycode']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE");
		$_SESSION['companyemail']       = $obj->getVendorListNewData($rows['SHIP_OWNER'],"EMAILID");
		$_SESSION['companytel']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PHONE");
		$_SESSION['companyfax']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FAX");
		$_SESSION['companyvat']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
		$_SESSION['footeraddr']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
		$_SESSION['vendorlogo']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");
		
		$vlsImoId 						= $obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID");
		
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			if($rows['RDOVATGST'] == 1)
			{
				$_SESSION['taxno2'] = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}else{
				$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}
		}else{
			$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) :';
		}
		
		if($rows['I_TYPE']=='Credit'){
			$invtitle = 'Credit Note';
			$invtitleType = 'Credit Note';
			$inv_amt_title = 'to Credit';
		}else{
			$invtitle = 'Invoice';
			if($rows['I_TYPE']=='Interim'){$invtitleType = $rows['invoice_title'];}else{$invtitleType = $rows['invoice_title'];}
			$inv_amt_title = 'Invoiced';
		}
		
		class PDF extends FPDF_Protection
		{
			function Header()
			{
				$image_path1 = '../../img/'.$_SESSION['vendorlogo'];
				$this->Image($image_path1,10,2,190,26);
				$this->AddFont("daxcondensedlight",'',"daxcondensedlight.php");
				
				$this->SetY(18);
				
			}
			
			function Footer()
			{
				$this->SetY(-15);
				$this->SetFillColor(255,255,255);
				$this->SetTextColor(177,175,175);
				$this->SetX(0);
				
				
				$this->AddFont("CalibriBold",'',"CalibriBold.php");
				$this->AddFont("Calibri",'',"Calibri.php");
				$this->SetFont('CalibriBold','',11);
				$this->SetTextColor(027,119,166);
				
				$this->Cell(0,4,$_SESSION['companyname'],0,1,'C');
				$this->Ln(1);
				$this->SetFont('Calibri','',10);
				$this->Cell(0,3,$_SESSION['footeraddr'],0,1,'C');
				$this->Cell(0,3,"Tel: ".$_SESSION['companytel']." | Fax: ".$_SESSION['companyfax'],0,1,'C');
				$this->Cell(0,3,"Email: ".$_SESSION['companyemail']." | Web: www.actship.com",0,1,'C');
			}
		}
		
		$quantity = $totalfreight = $freightrate = 0;$maincargoid = 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='".$rows['RANDOMID']."' and STATUS=1";
			$res12 = mysql_query($sql12);
			$row12 = mysql_fetch_assoc($res12);
			if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
			{
				$quantity = $row12['sum2'];
			}
			else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
			{
				$quantity = $row12['sum2'];
			}
			else
			{
			$quantity = $row12['sum1'];
			}
			$totalfreight = $row12['SUM3'];
			$freightrate = $row12['SUM4'];
			$maincargoid = $row12['CARGOID'];
		}
		else
		{
			
			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");
				
				if($obj->getFun228()==1)
				{
					if($obj->getFun171()==1)
					{
						$totalfreight = $obj->getFun172();
						$freightrate = '';
						$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
					}else
					{
						$res1_1 = mysql_query("select * from freight_cost_estimete_slave12 where FCAID='".$obj->getFun1()."' and CUSTOMER = '".$rows['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='".$rows['RANDOMID']."' and STATUS=1";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
					{
						$quantity = $row12['sum2'];
					}
					else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
					{
						$quantity = $row12['sum2'];
					}
					else
					{
						$quantity = $row12['sum1'];
					}
					$totalfreight = $row12['SUM3'];
					$maincargoid = $row12['CARGOID'];
				}
			}
			else
			{


				if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
				{
					$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
					$totalfreight = $obj->getCompareEstimateData($rows['COMID'],"TOTAL_PREIGHT_ADJ");
						
				
					$freightrate = $obj->getCompareEstimateData($rows['COMID'],"FREIGHT_GROSS");

					

					$maincargoid = $obj->getCompareEstimateData($rows['COMID'],"CARGO_ID");
				}
				else
				{
					$sql12 = "select QUANTITY, GROSS_FREIGHT, AGREED_GROSS_FREIGHT, CARGO, addnlCargoQty from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and RANDOMID='".$rows['RANDOMID']."'";
					
					$res12 = mysql_query($sql12) or die($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$quantity = $row12['QUANTITY'] + $row12['addnlCargoQty'];
					$totalfreight = $row12['GROSS_FREIGHT'];
					$freightrate = $row12['AGREED_GROSS_FREIGHT'];
					$maincargoid = $row12['CARGO'];
				}
			}
			
		}
								
					
		$lp_name = array(); 
		$dp_name = array();
		$discharge_port = "";
		
		for($j=0;$j<count($arrports);$j++)
		{   
			$arr_explode = explode('@@',$arrports[$j]);
			if($arr_explode[0] == "LP"){$lp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
			if($arr_explode[0] == "DP"){$dp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
		}
		
		$lp_name  = implode(', ',$lp_name);
		$dp_name  = implode(', ',$dp_name);
		
		if($obj->getFun175()!='')
		{
			$sqlcoa = "select * from coa_master where COAID='".$obj->getFun175()."'";
			$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
			$rowscoa   = mysql_fetch_assoc($resultcoa);
			$currency = $rowscoa['CURRENCY'];
		}else
		{
			$currency = 'USD';
		}
		
		$pdf = new PDF();
		$pdf->SetProtection(array('print'),$pdfpassword);
		$pdf->AddPage('P');
		
		$pdf->AddFont("CalibriBold",'',"CalibriBold.php");
		$pdf->AddFont("Calibri",'',"Calibri.php");


		$pdf->SetDisplayMode('real','single');
		$pdf->SetTitle('Generate Freight '.$invtitle.' Pdf');
		$pdf->SetAuthor('Seven Oceans Holdings');
		$pdf->SetSubject('Generate Freight '.$invtitle.' Pdf');
		$pdf->SetKeywords('Designed and Developed By Seven Oceans Holdings pvt. Ltd.');
		
		$pdf->Ln(17);
		$initialY =  $pdf->GetY();
		
		$pdf->Ln(2);
		$pdf->SetFont('calibri','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','L');
		$arr2=array(190);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$invdate = date('d M Y',strtotime($rows['DATE'])); if($invdate=='01-01-1970'){$invdate = '';}
		$pdf->Row1(array($invdate));
		$pdf->Ln(1);
		$pdf->Row1(array("To the attention of the Finance Manager"));
		
		$pdf->Ln(6);
		$pdf->Row1(array("Dear Sir/Madam,"));
		
		$pdf->Ln(14);
		$pdf->Row1(array('Not unlike many other companies in our industry, '.ucwords(strtolower($_SESSION['companyname'])).'. has been targeted by fraudsters who have sent us false payment requests purporting to be from our existing suppliers in the form of "revised invoices" or "changed payment instructions". We have recently been informed of fake invoices or fake changes to bank accounts being sent to customers. You have probably noticed an increased level of fraud attempts on your end as well.'));
		
		$pdf->Ln(2);
		$pdf->Row1(array('The purpose of this letter is to further raise awareness around this topic with our counterparties as well as to confirm our USD bank account details for the '.ucwords(strtolower($_SESSION['companyname'])).'.'));
		
		$pdf->Ln(14);
		
		$pdf->SetFont('CalibriBold','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','L');
		$arr2=array(40,70);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
		$res2 = mysql_query($sql2);
		$rows2 = mysql_fetch_assoc($res2);
		
		$pdf->SetX(40);
		// ldj
		$pdf->Row1(array('BENEFICIARY', strtoupper($rows2['NAME'])));
		$pdf->SetX(40);
		$pdf->Row1(array('ACCOUNT NO.', strtoupper($rows2['AC_NO'])));
		$pdf->SetX(40);
		$pdf->Row1(array('BANK NAME', strtoupper($rows2['BANK'])));
		$pdf->SetX(40);
		$pdf->Row1(array('BRANCH', strtoupper($rows2['BRANCH'])));
		$pdf->SetX(40);
		// $pdf->Row1(array('ADDRESS', strtoupper($rows2['ADDRESS'])));
		// $pdf->SetX(40);
		$pdf->Row1(array('BANK ADDRESS', strtoupper($rows2['B_ADDRESS'])));
		$pdf->SetX(40);
		$pdf->Row1(array('SWIFT CODE', strtoupper($rows2['BANK_SWIFT_CODE'])));
		if($rows2['IBAN_NO']!='')
		{
			$pdf->SetX(40);
			$pdf->Row1(array('IBAN NO.', strtoupper($rows2['IBAN_NO'])));
		}
		// end ldj
		
		$pdf->Ln(15);
		$pdf->SetFont('calibri','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','L');
		$arr2=array(190);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("Note: Please Make the Payment Specified to the Bank account mentioned in the freight Invoice. M/s ".ucwords(strtolower($_SESSION['companyname'])).", ".ucwords(strtolower($_SESSION['companycountry']))." will only use account holder as M/s. ".ucwords(strtolower($_SESSION['companyname']))." ,".ucwords(strtolower($_SESSION['companycountry']))."  and Our bank is ".ucwords(strtolower($rows2['BANK'])).". We will never request payment to another bank or other company on behalf of us to collect the remittance, if you received any invoice or payment request not matching with this information, please inform us immediately at chartaccounts@actship.com, Mobile No. +91-9824502029/ sekhar@actship.com, Mobile No.+91-9924295511. We will not be liable for any losses arising from failure to adhere to the above instructions. We recommend you to kindly check with us telephonically, before processing the funds. If required, we shall FAX the invoice to your office."));
		
		
		$pdf->Ln(50);
		$gety1 = $pdf->GetY();
		$pdf->Ln(-($gety1 - $initialY));
		$pdf->Cell(190,($gety1 - $initialY),"",1,1,'L',0);
		
		//$pdf->Row1(array('*E&OE'));
		$pdf->AddPage('P');
		
		$pdf->Ln(17);
		
		$pdf->SetFont('CalibriBold','',14);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C');
		$arr2=array(190);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row(array($invtitleType));
		
		$initialY =  $pdf->GetY();
		$pdf->Ln(1);
		$pdf->Cell(190, 1,'', 'T', 1, 'R');
		
		
		
		
		$pdf->SetFont('CalibriBold','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','L');
		$arr2=array(125,65);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			if($rows['RDOVATGST'] == 1)
			{
				$taxno1 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
				$taxno2 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}else{
				$taxno1 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
				$taxno2 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}
		}else{
			$taxno1 = '';
			$taxno2 = '';
		}
		
		$urnno = $obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		if($urnno!=''){$urntext = "\nOUR ".$urnno;}else{$urntext = '';}
		
		$pdf->Row1(array("M/S ".$obj->getVendorListNewBasedOnID($rows['VENDOR']),''));
		$pdf->Row1(array(stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'STREET_1')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'COUNTRY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY_POSTAL_CODE')))."\n ".$taxno1,strtoupper($invtitle).' NO.     :  '.$rows['MESSAGE']."\n".strtoupper($invtitle)." DATE  :  ".$invdate.$urntext."\n".'REF NO               :  '.$rows['REF_NO']));
		
		$initialY1 =  $pdf->GetY();
		
		$pdf->Ln(-($initialY1 - $initialY));
		$pdf->Cell(0,($initialY1 - $initialY),"",1,1,'L',0);
		
		
		$pdf->SetFont('CalibriBold','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','L');
		$arr2=array(50,94, 46);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->Row(array("VESSEL NAME : ",strtoupper($obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME")), "VOYAGE NO : ".$obj->getCompareEstimateData($rows['COMID'],"VOYAGE_NO")));
		
		
		if($rows['IMO_NO']!='' && $rows['FLAG']!='')
		{
		$pdf->Row(array("IMO NO. : ",strtoupper($rows['IMO_NO']), "FLAG : ",strtoupper($rows['FLAG'])));
		}
		
		if($rows['BL_NO']!='' && $rows['BL_DATE']!='' && $rows['BL_DATE']!='1970-01-01')
		{
		$bldate = date('d M Y',strtotime($rows['BL_DATE'])); if($bldate=='01-01-1970'){$bldate = '';}
		$pdf->Row(array("B/L NO. : ",strtoupper($rows['BL_NO']), "B/L DATE : ".$bldate));
		}
		
		
		$pdf->SetFont('CalibriBold','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','L');
		$arr2=array(50,140);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->Row(array("CHARTER PARTY DATED : ",date("d M Y",strtotime($obj->getFun3()))));
		
		
		$gety = $pdf->GetY();
		$pdf->SetFont('CalibriBold','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','C');
		$arr2=array(144,46);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("DESCRIPTION :",strtoupper("Amount in ".$currency."")));
		$pdf->SetFont('CalibriBold','',10);
		$pdf->Row1(array($rows['REMARKS'],""));
		
		
		$pdf->SetFont('CalibriBold','',11);
		$arr1=array('L','L','R');
		$arr2=array(60,84,46);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->Row1(array("VOYAGE :",strtoupper($rows['LOAD_PORT_NAME']).' / '.strtoupper($rows['DISCHARGE_PORT_NAME']),''));
		

		if($obj->getFun243()>0 && $obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==3 && $obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO") == 1)


		{
			$pdf->Row1(array("TOTAL B/L QUANTITY:",number_format($obj->getFun244(),3,'.',',')." MT ".strtoupper($obj->getMaterialCodeDesBasedOnId($maincargoid)),""));
			$pdf->Row1(array("LESS ".$obj->getFun243()."% ILOW ON B/L QTY:",number_format(($obj->getFun244()*$obj->getFun243())/100,3,'.',',')." MT ",""));
			$pdf->Row1(array("NETT QUANTITY:",number_format($quantity,3,'.',',')." MT ",""));
		}
		else
		{
			$additionalqty = 0;
			if($obj->getFun96()==2 && $obj->getFun72()>0)
			{
				$additionalqty = $obj->getFun54();
			}
			$pdf->Row1(array("TOTAL B/L QUANTITY :",number_format(($quantity + $additionalqty),3,'.',',')." MT ".strtoupper($obj->getMaterialCodeDesBasedOnId($maincargoid)),""));
			
			$sqlclub = "select * from freight_invoice_slave1 where INVOICEID='".$rows['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))
				{
					$pdf->Row1(array(" ",number_format($rowsclub1['QUANTITY'],3,'.',',')." MT ".strtoupper($obj->getMaterialCodeDesBasedOnId($rowsclub['CARGO'])),""));
				}
			}
		}
		
		if($obj->getFun96()==1 && $obj->getFun71() > 0)
		{
			$pdf->Row1(array("     DF QUANTITY :",number_format($obj->getFun53(),3,'.',',')." MT ".strtoupper($obj->getMaterialCodeDesBasedOnId($maincargoid)),""));
		}
		$pdf->Row1(array("AGREED FREIGHT RATE AS PER CP:", $currency." ".number_format($freightrate,2,'.',','),""));
		
		$sqlclub = "select * from freight_invoice_slave1 where INVOICEID='".$rows['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))
			{
				$pdf->Row1(array("FREIGHT FOR ADDITIONAL CARGO:", $currency." ".number_format($rowsclub1['AGREED_GROSS_FREIGHT'],4,'.',','),""));
			}
		}
		
		$pdf->SetFont('calibri','',11);
		$arr1=array('R','R');
		$arr2=array(144,46);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		if($obj->getFun96()==1 && $obj->getFun71() > 0)
		{

		
			
			if($rows['DIFF_AM_CHECK']==1){
				

				if($obj->getFun53() != '')
				{
					$total_freight_amt=$obj->getFun66();
				}else{
					$total_freight_amt=$obj->getFun69();
				}
			}
			else{
				if($obj->getFun53() != '')
				{
					$total_freight_amt=$obj->getFun66();
				}else{
					$total_freight_amt=$obj->getFun69() - ($obj->getFun50() * $obj->getFun257());
				}
				
			}
			
		$pdf->Row1(array("     ".number_format($quantity,3,'.',',')." MT CARGO AS PER  B/L X FREIGHT  ".$currency." ".number_format($freightrate,2,'.',',')." PMT", number_format($total_freight_amt,2,'.',',')));
			
		$pdf->Row1(array("     ".number_format($obj->getFun53(),3,'.',',')." MT CARGO AS PER  B/L X DEAD FREIGHT ".$currency." ".number_format($freightrate,2,'.',',')." PMT", number_format($obj->getFun67(),2,'.',',')));
		}
		else if($obj->getFun96()==2 && $obj->getFun54()>0)
		{
			if($rows['DIFF_AM_CHECK']==1){
				$total_freight_amt=$obj->getFun66();
			}
			else{
				$total_freight_amt=$obj->getFun66() - ($obj->getFun50() * $obj->getFun257());
			}
		$pdf->Row1(array("     ".number_format($quantity,3,'.',',')." MT CARGO AS PER B/L  X FREIGHT ".$currency." ".number_format($freightrate,2,'.',',')." PMT", number_format($obj->getFun66(),2,'.',',')));
			
		$pdf->Row1(array("     ".number_format($obj->getFun54(),3,'.',',')." MT CARGO AS PER B/L  X ADDITIONAL FREIGHT ".$currency." ".number_format($obj->getFun49(),2,'.',',')." PMT", number_format($obj->getFun68(),2,'.',',')));
		}
		else
		{


			
			if($rows['DIFF_AM_CHECK']==1){
				$total_freight_amt=$obj->getFun66();
			}
			else{
				$total_freight_amt=$obj->getFun66() - ($obj->getFun50() * $obj->getFun257());
			}
			// echo $total_freight_amt;

			// die();


			// 

		
		// $sqlclub = "select * from freight_invoice_slave1 where INVOICEID='".$rows['INVOICEID']."' ";
		// 	$resclub = mysql_query($sqlclub);

		// 	echo $sqlclub;


		// 	die();

			// while($rowsclub = mysql_fetch_assoc($resclub))
			// {

				$totalGrossFreight = 0;

				$totalAddnlGrossFreight = 0;
				$sqlclub1 = "select * from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and QTY_VENDORID='".$rows['VENDOR']."' and FCA_SLAVE7ID!='".$_GET['slaveids']."'";


				

				$resclub1 = mysql_query($sqlclub1);
				while($rowsclub1 = mysql_fetch_assoc($resclub1))
				{

					$sql_check=mysql_num_rows(mysql_query("select * from freight_invoice_slave1 where RANDOMID =  '".$rowsclub1['RANDOMID']."'"));

					
					
					$totalGrossFreight = $rowsclub1['AGREED_GROSS_FREIGHT'] * $rowsclub1['QUANTITY'];

					$totalAddnlGrossFreight = $rowsclub1['addnlCargoRate'] * $rowsclub1['addnlCargoQty'];
				
					

					if($sql_check >0){
						$pdf->Row1(array("     ".number_format($rowsclub1['QUANTITY'],3,'.',',')." MT CARGO AS PER B/L X FREIGHT  ".$currency." ".number_format($freightrate,2,'.',',')." PMT", number_format($totalGrossFreight,2,'.',',')));
					}
						
                    // ldjcheck
                    // AGREED_GROSS_FREIGHT   *     QUANTITY
					



					$pdf->Row1(array("".number_format($rowsclub1['QUANTITY'],3,'.',',')." MT CARGO AS PER B/L  X AGREED GROSS FREIGHT ".$currency." ".number_format($rowsclub1['AGREED_GROSS_FREIGHT'],3,'.',',')." PMT", number_format($rowsclub1['GROSS_FREIGHT'],2,'.',',')));




					if($rowsclub1['addnlCargoRate']!=0){
						$pdf->Row1(array("     ".number_format($rowsclub1['addnlCargoQty'],3,'.',',')." MT CARGO AS PER B/L  X ADDITIONAL FREIGHT ".$currency." ".number_format($rowsclub1['addnlCargoRate'],3,'.',',')." PMT", number_format($totalAddnlGrossFreight,2,'.',',')));
					}
				}

				
			// }
		}
		
		$pdf->SetFont('CalibriBold','',11);
		$arr1=array('R','R');
		$arr2=array(144,46);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("     TOTAL ".$rows['TO_1']."% FREIGHT DUE",number_format($rows['NET_AMOUNT'],2,'.',',')));

		$sql2 = "select * from freight_invoice_slave3 where INVOICEID='".$rows['INVOICEID']."'";
		$res2 = mysql_query($sql2);
		$num2 = mysql_num_rows($res2);

		if($num2>0)
		{
			$pdf->Ln(1);
			$pdf->SetFont('CalibriBold','',11);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('L','R');
			$arr2=array(144,46);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row1(array(strtoupper("Demurrage/Dispatch:"),""));
			
			$pdf->SetFont('Calibri','',11);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('R','R');
			$arr2=array(144,46);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			
		}

		$res21 = mysql_query($sql2);
		while($rows21 = mysql_fetch_assoc($res21))
		{
			if($rows21['PORT']=='LP')
			{
				if($rows21['DEM_AMT']>0)
				{
					$pdf->Row1(array(strtoupper("     Load Port ".$obj->getPortNameBasedOnID($rows21['PORTID'])),"(+) ".number_format($rows21['DEM_AMT'],2,'.',',')));
				}else{
					$pdf->Row1(array(strtoupper("     Load Port ".$obj->getPortNameBasedOnID($rows21['PORTID'])),"(-) ".str_replace("-","",number_format($rows21['DEM_AMT'],2,'.',','))));
				}  
			}
			
			if($rows21['PORT']=='DP')
			{
				if($rows21['DEM_AMT']>0)
				{
					$pdf->Row1(array(strtoupper("     Discharge Port ".$obj->getPortNameBasedOnID($rows21['PORTID'])),"(+) ".number_format($rows21['DEM_AMT'],2,'.',',')));
				}else{
					$pdf->Row1(array(strtoupper("     Discharge Port ".$obj->getPortNameBasedOnID($rows21['PORTID'])),"(-) ".str_replace("-","",number_format($rows21['DEM_AMT'],2,'.',','))));
				}  
			}
		}
		

		$sql2 = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD' and AMOUNT>0";
		$res2 = mysql_query($sql2);
		$num2 = mysql_num_rows($res2);
		
		$pdf->Ln(1);
		
		
		$pdf->SetFont('Calibri','',11);
		
		while($rows2 = mysql_fetch_assoc($res2))
		{
			$pdf->Row1(array(strtoupper("     ".$rows2['DESCRIPTION']),"(+) ".number_format($rows2['AMOUNT'],2,'.',',')));
		}
		
		$sql2 = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0";
		
		$res2 = mysql_query($sql2);
		$num2 = mysql_num_rows($res2);

	$pdf->Ln(1);
	
		$pdf->SetFont('Calibri','',11);
		if ((int) $rows['GST_BROKAGE'] >0 ) {
			$pdf->Row1(array(strtoupper(" GST ON BROKERAGE@ ".$rows['GST_PERC'])."%","(-) ".number_format($rows['GST_BROKAGE'],2,'.',',')));
		}
		
		
		while($rows2 = mysql_fetch_assoc($res2))
		{

			
			$pdf->Row1(array(strtoupper(" ".$rows2['DESCRIPTION']),"(-) ".number_format($rows2['AMOUNT'],2,'.',',')));
		}
	
		if($rows['BROKERAGE'] > 0)
		{
			$pdf->SetFont('Calibri','',11);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('R','R');
			$arr2=array(144,46);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			
			$pdf->Row1(array("     BROKERAGE(".$rows['BROKERAGE_PERCENT']."%)","(-) ".number_format($rows['BROKERAGE'],2,'.',',')));
		}
		
		if($rows['ADDCOM_AMOUNT'] > 0)
		{
			$pdf->SetFont('Calibri','',11);
			$pdf->SetTextColor(0,0,0);
			$arr1=array('R','R');
			$arr2=array(144,46);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			
			$pdf->Row1(array("     ADDCOM(".$rows['ADDCOM']."%)","(-) ".number_format($rows['ADDCOM_AMOUNT'],2,'.',',')));
		}
		
		
		$pdf->SetFont('Calibri','',11);
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			if($rows['RDOVATGST'] == 1)
			{
				$pdf->Ln(1);
				if($rows['GST_PERCENT']>0)
				{
					$pdf->Row1(array("     GST OUTPUT(".$rows['GST_PERCENT']."%)","(+) ".number_format($rows['GST_PERCENT_AMOUNT'],2,'.',',')));
				}
				else if($rows['IGST_PERCENT']>0)
				{
					$pdf->Row1(array("     IGST OUTPUT(".$rows['IGST_PERCENT']."%)","(+) ".number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
				}else{
					$pdf->Row1(array("     SGST OUTPUT(".$rows['SGST_PERCENT']."%)","(+) ".number_format($rows['SGST_PERCENT_AMOUNT'],2,'.',',')));
					$pdf->Row1(array("     CGST OUTPUT(".$rows['CGST_PERCENT']."%)","(+) ".number_format($rows['CGST_PERCENT_AMOUNT'],2,'.',',')));
				}
			}else{
				$pdf->Ln(1);
				$pdf->Row1(array("     VAT OUTPUT(".$rows['VAT_PERCENT']."%)","(+) ".number_format($rows['VAT_PERCENT_AMOUNT'],2,'.',',')));
			}
		}
		
		$pdf->Ln(1);
		// $sqlprev = "select * from freight_invoice_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR = '".$rows['VENDOR']."' and P_TYPE='".$rows['P_TYPE']."' and CARGOID='".$rows['CARGOID']."' and RANDOMID='".$rows['RANDOMID']."' and STATUS=5 and INVOICEID='".$rows['INVOICEID']."'";
		$sqlprev = "select * from freight_invoice_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR = '".$rows['VENDOR']."' and P_TYPE='".$rows['P_TYPE']."' and CARGOID='".$rows['CARGOID']."' and RANDOMID='".$rows['RANDOMID']."' and STATUS=5 ";

		
		$resprev = mysql_query($sqlprev) or die($sqlprev);
		while($rowsprev = mysql_fetch_assoc($resprev))
		{
			$pdf->Row1(array("     INITIAL FREIGHT RECEIVED","(-) ".number_format($rowsprev['P_AMT'],2,'.',',')));
		}
		
		$pdf->Ln(1);
		$pdf->SetFont('CalibriBold','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('R','R');
		$arr2=array(144,46);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$pdf->SetX(154);
		$pdf->SetTextColor(0,0,0);
		$pdf->Cell(46, 1,'', 'T', 1, 'R');
		
		$pdf->Row1(array("TOTAL PAYABLE DUE ",number_format($rows['NET_PAYABLE_TAX'],2,'.',',')));
		
		$pdf->Ln(1);
		$pdf->SetX(154);
		$pdf->SetTextColor(0,0,0);
		$pdf->Cell(46, 1,'', 'T', 1, 'R');
		
		$pdf->SetX(154);
		$pdf->SetTextColor(0,0,0);
		$pdf->Cell(46, 1,'', 'T', 1, 'R');
		
		$pdf->Ln(1);
		if($rows['EXCHANGE_RATE']!=1)
		{
			$pdf->SetFont('CalibriBold','',11);
			$pdf->Row1(array("TOTAL PAYABLE DUE (".$rows['EXCHANGE_CURRENCY'].")",number_format(($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE']),2,'.',',')));
			$pdf->SetX(154);
			$pdf->Cell(46,0,"",0,1,'C','1');
		}
		
		$pdf->SetFont('CalibriBold','',11);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('L','R');
		$arr2=array(144,46);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Row1(array("(AMOUNT IN WORDS : ".strtoupper($amttoword->convert_number_to_words($rows['NET_PAYABLE_TAX'],$currency)).")", ''));
		if($rows['EXCHANGE_RATE']!=1)
		{$pdf->Ln(1);
			$pdf->SetFont('CalibriBold','',11);
			$pdf->Row1(array("(AMOUNT IN WORDS : ".strtoupper($amttoword->convert_number_to_words(number_format($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE'],2,'.',''),$rows['EXCHANGE_CURRENCY'])).")", ''));
		}
		
		
		$pdf->SetFont('CalibriBold','',11);
		$pdf->Row1(array("REMIT VIDE WIRE TRANSFER : ", ''));
		
		$pdf->SetFont('CalibriBold','',11);
		$pdf->Row1(array("PAYMENT DUE DATE  :     ".$rows['PAYMENT_TERMS'], ''));

		// $pdf->MultiCell(0,5,' ');
		
		
		$pdf->SetFont('CalibriBold','',11);
		$pdf->Row1(array("PAYMENT INSTRUCTIONS : ", ''));
		
		$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
		$res2 = mysql_query($sql2);
		$rows2 = mysql_fetch_assoc($res2);
		$pdf->SetFont('CalibriBold','',10);
		$arr1=array('L', 'L', 'L', 'L', 'L');
		$arr2=array(25, 25, 5, 89,46);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		// ldj
		$pdf->Row1(array('', 'BENEFICIARY',' : ',$rows2['NAME'],''));
		
		// $pdf->Row1(array('', 'ADDRESS',' : ',$rows2['ADDRESS'],''));
		$pdf->Row1(array('', 'ACCOUNT NO.',' : ',$rows2['AC_NO'],''));
		$pdf->Row1(array('', 'BANK NAME',' : ',$rows2['BANK'],''));
		$pdf->Row1(array('', 'BRANCH',' : ',$rows2['BRANCH'],''));
		$pdf->Row1(array('', 'SWIFT CODE',' : ',$rows2['BANK_SWIFT_CODE'],''));
		$pdf->Row1(array('', 'BANK ADDRESS',' : ',$rows2['B_ADDRESS'],''));
		if($rows2['IFSC']!='')
		{
			$pdf->Row1(array('', 'IFSC',' : ',$rows2['IFSC'],''));
		}
		if($rows2['IBAN_NO']!='')
		{
			$pdf->Row1(array('', 'IBAN NO.',' : ',$rows2['IBAN_NO'], ''));
		}
		if($rows2['IBAN_NO']!='')
		{
			$pdf->Row1(array('', 'IBAN NO.',' : ',$rows2['IBAN_NO'], ''));
		}
		
		if($rows2['C_BANK_NAME']!='')
		{
			$arr1=array('L');
			$arr2=array(190);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row1(array('  INTERMEDIARY BANK DETAILS:'));
			
			$arr1=array('L', 'L', 'L', 'L', 'L');
			$arr2=array(25, 25, 5, 89,46);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);
			$pdf->Row1(array('', 'BANK NAME:',' : ',$rows2['C_BANK_NAME'], ''));
			$pdf->Row1(array('', 'ADDRESS:',' : ',$rows2['CORRES_ADDRESS'], ''));
			$pdf->Row1(array('', 'SWIFT CODE:',' : ',$rows2['C_SWIFT_CODE'], ''));
			//$pdf->Row1(array('', 'ACCOUNT NO:',' : ',$rows2['B_ACNO'], ''));//
		
		}
		
		
		
		
		$gety1 = $pdf->GetY();
		$pdf->Ln(-($gety1 - $gety));
		$pdf->Cell(144,($gety1 - $gety),"",1,1,'L',0);
		
		$gety1 = $pdf->GetY();
		$pdf->Ln(-($gety1 - $gety));
		$pdf->SetX(154);
		$pdf->Cell(46,($gety1 - $gety),"",1,1,'L',0);
		
		
		
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			
			if($rows['RDOVATGST'] == 1)
			{
				$pdf->SetFont('Calibri','',11);
				$pdf->SetTextColor(0,0,0);
				$arr1=array('C','C','C','C');
				$arr2=array(100,30,30,30);
				$pdf->SetAligns($arr1);
				$pdf->SetWidths($arr2);
				$pdf->Row(array(($rows['GST_PERCENT']>0)?"":"HSN/SAC","TAXABLE VALUE", "RATE", "TAX AMOUNT"));
				
				$pdf->SetFont('Calibri','',11);
				$pdf->SetTextColor(0,0,0);
				$arr1=array('L','R','R','R');
				$arr2=array(100,30,30,30);
				$pdf->SetAligns($arr1);
				$pdf->SetWidths($arr2);
				if($rows['GST_PERCENT']>0)
				{
					$pdf->Row(array(' ', $rows['NET_PAYABLE_TAX'],"GST ". $rows['GST_PERCENT']."%",number_format($rows['GST_PERCENT_AMOUNT'],2,'.',',')));
					$pdf->SetFont('Calibri','',11);
					$pdf->Row(array("Total", $rows['NET_PAYABLE_TAX'],"",number_format($rows['GST_PERCENT_AMOUNT'],2,'.',',')));
				}
				else if($rows['IGST_PERCENT']>0)
				{
					$pdf->Row(array(' ', $rows['NET_PAYABLE_TAX'],"IGST ". $rows['IGST_PERCENT']."%",number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
					$pdf->SetFont('Calibri','',11);
					$pdf->Row(array("Total", $rows['NET_PAYABLE_TAX'],"",number_format($rows['IGST_PERCENT_AMOUNT'],2,'.',',')));
				}else{
					$pdf->Row(array(' ', $rows['NET_PAYABLE_TAX'],"SGST ". $rows['SGST_PERCENT']."%",number_format($rows['SGST_PERCENT_AMOUNT'],2,'.',',')));
					$pdf->Row(array(' ', $rows['NET_PAYABLE_TAX'],"CGST ". $rows['CGST_PERCENT']."%",number_format($rows['CGST_PERCENT_AMOUNT'],2,'.',',')));
					$pdf->SetFont('Calibri','',11);
					$pdf->Row(array("Total", $rows['NET_PAYABLE_TAX'],"",number_format(($rows['CGST_PERCENT_AMOUNT'] + $rows['SGST_PERCENT_AMOUNT']),2,'.',',')));
				}
			}else{
				//$pdf->Ln(2);
				//$pdf->Row(array("     VAT Output(".$rows['VAT_PERCENT']."%)","(+) ".number_format($rows['VAT_PERCENT_AMOUNT'],2,'.',',')));
			}
		}
		
		
		$pdf->SetFont('Calibri','',11);
		$pdf->Row1(array('*E&OE'));
		
		if($rows['EXCHANGE_RATE'] > 1 || $rows['EXCHANGE_RATE'] < 1)
		{
			if($pdf->GetY()> 245)
			{
				$pdf->AddPage('P');
				$pdf->Ln(17);
				
			}
				$gety = $pdf->GetY();
				
				$pdf->SetFont('CalibriBold','',11);
				$pdf->SetTextColor(0,0,0);
				$arr1=array('L','R');
				$arr2=array(60, 40);
				$pdf->SetAligns($arr1);
				$pdf->SetWidths($arr2);
				$pdf->Row1(array("FOR VAT PURPOSE ONLY",""));
				
				$pdf->SetFont('Calibri','',10);
				$pdf->Row1(array("EXCHANGE RATE", "USD 1 = ".$rows['EXCHANGE_RATE']." ".$rows['EXCHANGE_CURRENCY']));
				$pdf->Row1(array("TOTAL AMOUNT (".$rows['EXCHANGE_CURRENCY'].") EXCL. VAT", number_format(($rows['NET_PAYABLE']*$rows['EXCHANGE_RATE']),2,'.',',')));
				$pdf->Row1(array("AMOUNT VAT ".$rows['VAT_PERCENT']." @ %", number_format(($rows['VAT_PERCENT_AMOUNT']*$rows['EXCHANGE_RATE']),2,'.',',')));
				$pdf->Row1(array("TOTAL AMOUNT DUE (".$rows['EXCHANGE_CURRENCY'].") INCL. VAT", number_format(($rows['NET_PAYABLE_TAX']*$rows['EXCHANGE_RATE']),2,'.',',')));
				
				$gety1 = $pdf->GetY();
				$pdf->Ln(-($gety1 - $gety));
				$pdf->Cell(140,($gety1 - $gety),"",1,1,'L',0);
		}
		
		
		$pdf->SetFont('Calibri','',10);
		$pdf->SetTextColor(10,10,10);
		
	}

	$filename = $invtitle." Of ".$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME")."(".$rows['I_TYPE'].")".date("d-M-Y",time()).".pdf";
	$pdf->Output($filename,'D');
}

function getFreightINRPdf()
{
	
		$obj = new data();
		$amttoword = new Numbertowordconversion_inr();

		
		$obj->funConnect();


		$im_id = $_REQUEST['im_id'];
		$pdfpassword = $_REQUEST['pdfpassword'];

		$sql = "select * from freight_invoice_master where INVOICEID='".$im_id."'";
	   
		
		$res = mysql_query($sql);
		$rows = mysql_fetch_assoc($res);

		$sqljson = "select * from gst_json_form_data where INVOICEID='".$im_id."' and INVOICE_TYPE='FREIGHT'";

		$resultjson = mysql_query($sqljson);

		$numjson = mysql_num_rows($resultjson);

		$rowjson = mysql_fetch_assoc($resultjson);

		$commodity_arr = array();
		if($numjson > 0)
		{
			
			$sqljson_slave = "select * from gst_json_form_data_slave where JSONID='".$rowjson['JSONID']."'";
			

			$resjson_slave = mysql_query($sqljson_slave);
			while($rowsjson_slave = mysql_fetch_assoc($resjson_slave))
			{
				$commodity_arr[] = $rowsjson_slave['PRODUCT_DESCRIPTION'];
			}

		}

			$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'];

		
		$commodity_arr = array_unique($commodity_arr);
	

		$exchange_rate = $rows['EXCHANGE_RATE'];
		$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
		$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
		$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);
		
		$_SESSION['companyname']        =  $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME");
		$_SESSION['companyaddress']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1");
		$_SESSION['companycity']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY");
		$_SESSION['companycountry']     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY");
		$_SESSION['companycode']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE");
		$_SESSION['companyemail']       = $obj->getVendorListNewData($rows['SHIP_OWNER'],"EMAILID");
		$_SESSION['companytel']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PHONE");
		$_SESSION['companyfax']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FAX");
		$_SESSION['companyvat']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
		$_SESSION['panno']              = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PANNO");
		$_SESSION['CINno']              = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CINNO");
		$_SESSION['footeraddr']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
		$_SESSION['vendorlogo']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");
		
		$vlsImoId 						= $obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID");

		$_SESSION['BARCODE_ATTACHMENT'] = $rowjson['BARCODE_ATTACHMENT'];
		$_SESSION['IRN_NO']             = $rowjson['IRN_NO'];
	
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			if($rows['RDOVATGST'] == 1)
			{
				$_SESSION['taxno2'] = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}else{
				$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
			}
		}else{
			$_SESSION['taxno2'] = 'TAX REGISTRATION No. (TRN) :';
		}
	
		if($rows['I_TYPE']=='Credit'){
			$invtitle = 'Credit Note';
			$invtitleType = 'Credit Note';
			$inv_amt_title = 'to Credit';
		}else{
			$invtitle = 'Invoice';
			if($rows['I_TYPE']=='Interim'){$invtitleType = 'TAX INVOICE - FREIGHT';}else{$invtitleType = 'TAX INVOICE - FREIGHT';}
			$inv_amt_title = 'Invoiced';
		}
	
			class PDF extends FPDF_Protection
			{
				function Header()
				{
					$this->AddFont("CalibriBold",'',"CalibriBold.php");
					$this->AddFont("Calibri",'',"Calibri.php");
                    $this->Ln(-5);
					$this->SetFillColor(255,255,255);
					$this->SetTextColor(45,45,45);
					$this->SetFont('Calibri','',8);
					$this->Cell(0,3,"E-MAIL        :        accounts.gim@actship.com",0,1,'L');
					$this->Cell(0,3,"                     :        chartaccounts@actship.com",0,1,'L');
					$this->SetFont('CalibriBold','',9);
					$this->Cell(0,4,$_SESSION['companyname'],0,1,'C');
					$this->SetFont('Calibri','',8);
					$this->Cell(0,3,"( Chartering Division )",0,1,'C');
					$this->Ln(1);
					$this->Cell(0,3,"PLOT NO.391 & 392 SECTOR 1 (A), GANDHIDHAM - 370 201",0,1,'C');
					$this->Cell(0,3,"REGD. OFFICE NO.14, SHIPPING HOUSE, GR.FLOOR,",0,1,'C');
					$this->Cell(0,3,"KUMPTA STREET, FORT, MUMBAI - 400 001",0,1,'C');
					$this->Cell(0,3,"TEL NO. (02836) 229967/239743/231734/FAX NO.(02836) 238864/270579",0,1,'C');
					$this->SetFont('CalibriBold','',8);
					$this->Cell(0,3,"GSTIN : ".$_SESSION['companyvat'],0,1,'C');
					$this->Cell(0,3,"PAN NO. : ".$_SESSION['panno'], 0,1,'C');
					$this->Cell(0,3,"CIN No. : ".$_SESSION['CINno'], 0,1,'C');
					$this->Cell(0,3,"IRN No. : ".$_SESSION['IRN_NO'], 0,1,'C');
					if($_SESSION['BARCODE_ATTACHMENT']!='')
					{
						
						$image_path1 = '../../attachment/'.$_SESSION['BARCODE_ATTACHMENT'];
						$this->Image($image_path1,162,8,36,36);
						
					}
					$this->SetY(34);
					
				}
				
				function Footer()
				{

					
					
					
				}
			}
	
			$quantity = $totalfreight = $freightrate = 0;$maincargoid = 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='".$rows['RANDOMID']."' and STATUS=1";
				$res12 = mysql_query($sql12);
				$row12 = mysql_fetch_assoc($res12);
				if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
				{
					$quantity = $row12['sum2'];
				}
				else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
				{
					$quantity = $row12['sum2'];
				}
				else
				{
				$quantity = $row12['sum1'];
				}
				$totalfreight = $row12['SUM3']*$exchange_rate;
				$freightrate = $row12['SUM4'];
				$maincargoid = $row12['CARGOID'];
			}
			else
			{
				
				if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
				{
					$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
					$totalfreight = $row12['SUM3']*$exchange_rate;
					$freightrate = $row12['GAS_BASE_RATE'];
				}
				else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
				{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
				
				if($obj->getFun228()==1)
				{
				 if($obj->getFun171()==1)
				 {
				     $totalfreight = $obj->getFun172()*$exchange_rate;
					 $freightrate = '';
					 $quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
				 }else
				 {
				     $res1_1 = mysql_query("select * from freight_cost_estimete_slave12 where FCAID='".$obj->getFun1()."' and CUSTOMER = '".$rows['VENDOR']."' ");
					 $row1_1 = mysql_fetch_assoc($res1_1);
					 $totalfreight = $row1_1['TOTAL_AMOUNT']*$exchange_rate;
					 $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='".$rows['RANDOMID']."' and STATUS=1";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
					{
						$quantity = $row12['sum2'];
					}
					else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
					{
						$quantity = $row12['sum2'];
					}
					else
					{
						$quantity = $row12['sum1'];
					}
					$totalfreight = $row12['SUM3']*$exchange_rate;
					$maincargoid = $row12['CARGOID'];
				 }
			}
			else
			{
				
					if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
					{
						$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
						$totalfreight = $obj->getCompareEstimateData($rows['COMID'],"TOTAL_PREIGHT_ADJ")*$exchange_rate;
						$freightrate = $obj->getCompareEstimateData($rows['COMID'],"FREIGHT_GROSS");
						$maincargoid = $obj->getCompareEstimateData($rows['COMID'],"CARGO_ID");
					}
					else
					{
						$sql12 = "select QUANTITY, GROSS_FREIGHT, AGREED_GROSS_FREIGHT, CARGO, addnlCargoQty from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and RANDOMID='".$rows['RANDOMID']."'";
						
						$res12 = mysql_query($sql12) or die($sql12);
						$row12 = mysql_fetch_assoc($res12);
						$quantity = $row12['QUANTITY'] + $row12['addnlCargoQty'];
						$totalfreight = $row12['GROSS_FREIGHT']*$exchange_rate;
						$freightrate = $row12['AGREED_GROSS_FREIGHT'];
						$maincargoid = $row12['CARGO'];
					}
			}
		
		}
				
		
		$lp_name = array(); 
		$dp_name = array();
		$discharge_port = "";
	
		for($j=0;$j<count($arrports);$j++)
		{   
			$arr_explode = explode('@@',$arrports[$j]);
			if($arr_explode[0] == "LP"){$lp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
			if($arr_explode[0] == "DP"){$dp_name[]= explode('/',$obj->getPortNameBasedOnID($arr_explode[1]))[0];}
		}
		
		$lp_name  = implode(', ',$lp_name);
		$dp_name  = implode(', ',$dp_name);
		if($rows['LOAD_PORT_NAME']!='')
		{
			$lp_name = $rows['LOAD_PORT_NAME'];
		}
		if($rows['DISCHARGE_PORT_NAME']!='')
		{
			$dp_name = $rows['DISCHARGE_PORT_NAME'];
		}
	
		if($obj->getFun175()!='')
		{
			$sqlcoa = "select * from coa_master where COAID='".$obj->getFun175()."'";
			$resultcoa = mysql_query($sqlcoa) or die($sqlcoa);
			$rowscoa   = mysql_fetch_assoc($resultcoa);
			$currency = $rowscoa['CURRENCY'];
		}else
		{
			$currency = 'USD';
		}
		
	
	$pdf = new PDF();

	$pdf->SetProtection(array('print'),$pdfpassword);
	
	$pdf->AddPage('P');

	$pdf->AddFont("CalibriBold",'',"CalibriBold.php");
	$pdf->AddFont("Calibri",'',"Calibri.php");

	$pdf->SetDisplayMode('real','single');
	$pdf->SetTitle('Generate Freight '.$invtitle.' Pdf');
	$pdf->SetAuthor('Seven Oceans Holdings');
	$pdf->SetSubject('Generate Freight '.$invtitle.' Pdf');
	$pdf->SetKeywords('Designed and Developed By Seven Oceans Holdings pvt. Ltd.');

	$pdf->Ln(9);
	$pdf->SetFont('CalibriBold','',10);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C');
	$arr2=array(190);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array($rows['invoice_title']));

	$pdf->Ln(1);
	$initialY =  $pdf->GetY();
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','C','L','L','C','L');
	$arr2=array(22,7,65,25,7,65);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	if($rows['RDOTAXAPPLICABLE'] == 1)
	{
	    if($rows['RDOVATGST'] == 1)
	    {
			$taxno1 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
			$taxno2 = 'GSTIN/UIN : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}else{
			$taxno1 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER');
			$taxno2 = 'TAX REGISTRATION No. (TRN) : '.$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'VAT_NUMBER');
		}
	}else{
	     $taxno1 = '';
		 $taxno2 = '';
	}

	$supplydate = date('d-m-Y',strtotime($rows['SUPPLY_DATE'])); if($supplydate=='01-01-1970'){$supplydate = '';}
	$invdate = date('d-m-Y',strtotime($rows['DATE'])); if($invdate=='01-01-1970'){$invdate = '';}
	
	$invmonth = date('m',strtotime($rows['DATE']));
	$invyear = date('Y',strtotime($rows['DATE']));
	
	if($invmonth > 3)
	{
	    $fyear = $invyear.' - '.($invyear + 1);
	}else{
	    $fyear = ($invyear - 1).' - '.$invyear;
	}
	
	$pdf->Row1(array("Reverse Charges",":",($rows['REVERSE_CHARGE']==1)?'Yes':'No',"Service Description",":",$rowjson['SERVICE_DESC']));
	$pdf->Ln(-1);
	$pdf->Row1(array("Financial Year",":",$fyear,"Vehicle No.",":",$rows['VEHICLE_NO']));
	$pdf->Ln(-1);
	$pdf->Row1(array("Invoice No.",":",$rows['MESSAGE'],"Date Of Supply",":",$supplydate));
	$pdf->Ln(-1);
	$pdf->Row1(array("Invoice Date",":",$invdate,"Place Of Supply",":",$rows['SUPPLY_PLACE']));
	$pdf->Ln(-1);
	$pdf->Row1(array("Voyage No.",":",$obj->getFun8(),"","",""));
	$pdf->Ln(-1);
	$pdf->Row1(array("State",":",$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STATE')."              State Code:".$obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STATE_CODE'),"","",""));
	
	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(22,($initialY1 - $initialY),"",1,0,'L',0);
	$pdf->Cell(7,$ydifference,"",1,0,'L',0);
	$pdf->Cell(65,$ydifference,"",1,0,'L',0);
	$pdf->Cell(25,$ydifference,"",1,0,'L',0);
	$pdf->Cell(7,$ydifference,"",1,0,'L',0);
	$pdf->Cell(65,$ydifference,"",1,1,'L',0);
	
	$initialY =  $pdf->GetY();
	
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','C','L','L','L','L','C','L','L','L');
	$arr2=array(22,7,24,17,24,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	// dpkldj

	
	
	
	$pdf->Row(array("Vessel Name",":",$obj->getVesselIMOData($obj->getFun5(),"VESSEL_NAME"),"Load Port :",$lp_name,"Commodity",":", implode(', ',$commodity_arr),"Quantity :",number_format($quantity_test,3,'.',',').' MT'));
	$cpdate = date('d-m-Y',strtotime($obj->getFun3())); if($cpdate=='01-01-1970'){$cpdate = '';}
	$exchangedate = date('d-m-Y',strtotime($rows['EXCHANGE_DATE'])); if($exchangedate=='01-01-1970'){$exchangedate = '';}
	
	$pdf->Row(array("CP Date",":",$cpdate,"Discharge Port :",$dp_name,"Ex Rate(USD)",":",$rows['EXCHANGE_RATE'],"Date : ",$exchangedate));
	// 	$pdf->Row(array("CP Date",":",$cpdate,"Discharge Port :",$dp_name,"Ex Rate(USD)",":","","Date : ",$exchangedate));
	
	
	
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','C');
	$arr2=array(94,97);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$pdf->Row(array("Details of Receiver / Billed To","Details of Consignee / Shipped To"));
	
	$initialY =  $pdf->GetY();
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','C','L','L','C','L');
	$arr2=array(22,7,65,25,7,64);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Row1(array("Name",":","M/S ".$obj->getVendorListNewBasedOnID($rows['VENDOR']),"Name",":","M/S ".$obj->getVendorListNewBasedOnID($rows['SHIPPER_VENDOR'])));
	$pdf->Ln(-1);
	$pdf->Row1(array("Address",":",stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'STREET_1'))).' '.stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'COUNTRY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['VENDOR'],'CITY_POSTAL_CODE'))),"Address",":",stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STREET_1'))).' '.stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'CITY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'COUNTRY')))." ".stripslashes(strtoupper($obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'CITY_POSTAL_CODE')))));
	$pdf->Ln(-1);
	$pdf->Row1(array("PAN",":",$obj->getVendorDataBasedOnID($rows['VENDOR'],'PANNO'),"PAN",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'PANNO')));
	$pdf->Ln(-1);
	// 	$pdf->Row1(array("GSTIN",":",$obj->getVendorDataBasedOnID($rows['VENDOR'],'VAT_NUMBER')."LDJ","GSTIN",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'VAT_NUMBER')));

	
	$pdf->Row1(array("GSTIN",":",$rowjson['BUYER_GSTIN'],"GSTIN",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'VAT_NUMBER')));
	$pdf->Ln(-1);
	$pdf->Row1(array("State",":",$obj->getVendorDataBasedOnID($rows['VENDOR'],'STATE')."               State Code : ".$obj->getVendorDataBasedOnID($rows['VENDOR'],'STATE_CODE'),"State",":",$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STATE')."               State Code : ".$obj->getVendorDataBasedOnID($rows['SHIPPER_VENDOR'],'STATE_CODE')));
	
	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(94,($initialY1 - $initialY),"",1,0,'L',0);
	$pdf->Cell(97,$ydifference,"",1,1,'L',0);
	
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L');
	$arr2=array(191);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$bldate = date('d-m-Y',strtotime($rows['BL_DATE'])); if($bldate=='01-01-1970'){$bldate = '';}
	// $pdf->Row(array("BL NO. : ".$rows['BL_NO'].',    Dtd : '.$bldate,""));
	
	$pdf->Row(array("BL NO. : ".$rows['BL_NO'].", Dtd . : ".$bldate." , Ref No. : ".$rows['REF_NO']." "));

	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','C','C','C','C','C','C');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);

	if($rowjson['UNIT_CURRENCY']=='INR')
	{
		$freight_exchangerate = $exchange_rate;
		$currency_code = "";
	}else{
		$freight_exchangerate = 1;
		$currency_code = "$";
	}
	$pdf->Row(array("S.No.", "Particulars", ($rows['GST_PERCENT']>0)?"":"HSN/SAC", "UO", "QTY", "RATE (".$rowjson['UNIT_CURRENCY'].")", "Amount(".$rows['EXCHANGE_CURRENCY'].")"));
	
	
	$initialY =  $pdf->GetY();
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','L','C','C','C','C','R');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);

	$i = 0;
	if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
	{
	    
	}
	else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==3)
	{
		if($obj->getFun96()==1)
		{
		   $i++;
		   $pdf->Row1(array($i, "FREIGHT (".strtoupper($obj->getMaterialCodeDesBasedOnId($maincargoid)).')', $rows['HSN_SAC'], "MT", number_format($quantity,3,'.',','),$currency_code." ".number_format($freightrate*$freight_exchangerate,4,'.',','), number_format($obj->getFun66()*$exchange_rate,2,'.',',')));

		   if($obj->getFun71() > 0)
		   {
				$i++;
				$pdf->Ln(-1);
				$pdf->Row1(array($i, "DF FREIGHT", $rows['HSN_SAC'], "MT", number_format($obj->getFun53(),3,'.',','), $currency_code." ".number_format($freightrate*$freight_exchangerate,4,'.',','), number_format($obj->getFun67()*$exchange_rate,2,'.',',')));
		   }
		   
		}
		else if($obj->getFun96()==2)
		{
		   $i++;
		   $pdf->Row1(array($i, "FREIGHT (".strtoupper($obj->getMaterialCodeDesBasedOnId($maincargoid)).')', $rows['HSN_SAC'], "MT", number_format($quantity,3,'.',','),$currency_code." ".number_format($freightrate*$freight_exchangerate,4,'.',','), number_format($obj->getFun66()*$exchange_rate,2,'.',',')));

		   if($obj->getFun54()>0)
		   {
				$i++;
				$pdf->Ln(-1);
				$pdf->Row1(array($i, "ADDITIONAL FREIGHT", $rows['HSN_SAC'], "MT", number_format($obj->getFun54(),3,'.',','),$currency_code." ".number_format($obj->getFun49()*$freight_exchangerate,4,'.',','), number_format($obj->getFun68()*$exchange_rate,2,'.',',')));
		   }
		}
		else
		{
			$i++;
			$sqldis = "select * from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and QTY_VENDORID='".$rows['VENDOR']."' and RANDOMID='".$rows['RANDOMID']."'";
			$resdis = mysql_query($sqldis);
			
			while($rowsdis = mysql_fetch_assoc($resdis))
			{
				$pdf->Ln(-1);

				$totalGrossFreight = $rowsdis['AGREED_GROSS_FREIGHT'] * $rowsdis['QUANTITY'];

				$totalAddnlGrossFreight = $rowsdis['addnlCargoRate'] * $rowsdis['addnlCargoQty'];

				$pdf->Row1(array($i, "FREIGHT (".strtoupper($obj->getMaterialCodeDesBasedOnId($rowsdis['CARGO'])).')', $rows['HSN_SAC'], "MT", number_format($rowsdis['QUANTITY'],3,'.',','), $currency_code." ".number_format($rowsdis['AGREED_GROSS_FREIGHT']*$freight_exchangerate,4,'.',','), number_format($totalGrossFreight*$exchange_rate,2,'.',',')));

				if($rowsdis['addnlCargoRate']>0)
				{
					$pdf->Row1(array('',"FREIGHT FOR ADDITIONAL CARGO (".strtoupper($obj->getMaterialCodeDesBasedOnId($rowsdis['CARGO'])).')', $rows['HSN_SAC'], "MT", number_format($rowsdis['addnlCargoQty'],3,'.',','), $currency_code." ".number_format($rowsdis['addnlCargoRate']*$freight_exchangerate,4,'.',','), number_format($totalAddnlGrossFreight*$exchange_rate,2,'.',',')));
				}
			}
		
		   
		    $sqlclub = "select * from freight_invoice_slave1 where INVOICEID='".$rows['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++;
					$pdf->Ln(-1);
					$pdf->Row1(array($i, "FREIGHT FOR ADDITIONAL CARGO (".strtoupper($obj->getMaterialCodeDesBasedOnId($rowsclub['CARGO'])).')', $rows['HSN_SAC'], "MT", number_format($rowsclub1['QUANTITY'],3,'.',','),$currency_code." ".number_format($rowsclub1['AGREED_GROSS_FREIGHT']*$freight_exchangerate,4,'.',','), number_format($rowsclub1['NET_FREIGHT']*$exchange_rate,2,'.',',')));
				}
			}
		}
    }
	
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','R','C','C','C','C','R');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	if($rows['TO_1']<100)
	{
	    $pdf->Ln(-1);
		$pdf->Row1(array("", "100% FREIGHT ".number_format($rows['GROSS_FREIGHT']*$exchange_rate,2,'.',','), '','','','', ''));
	}
	$pdf->Ln(-1);

	if($rows['NET_AMOUNT']>0){
		$pdf->Row1(array("", "OCEAN FREIGHT (".$rows['TO_1']."% FREIGHT AMOUNT - $ ".$rows['NET_AMOUNT'], '', '', '', '',number_format($rows['NET_AMOUNT']*$exchange_rate,2,'.',',')));
	}

    
	
	$amount = $rows['NET_AMOUNT']*$exchange_rate;

	
	
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','L', 'R','C','C','C','C','R');
	$arr2=array(22,50,22,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$sql2 = "select * from freight_invoice_slave3 where INVOICEID='".$rows['INVOICEID']."'";
    $res2 = mysql_query($sql2);
	$num2 = mysql_num_rows($res2);
    
	$array_number = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l');
	$index = 0;
    if($num2>0)
	{
		$pdf->SetFont('CalibriBold','',8);
		$pdf->Ln(-1);
		$pdf->Row1(array("", strtoupper("Demurrage/Dispatch:"),"","","","",""));
		
		$pdf->SetFont('Calibri','',8);
	}

    $res21 = mysql_query($sql2);
    while($rows21 = mysql_fetch_assoc($res21))
	{
		$currency_symbol=$exchange_rate != 1?"$":"";
	    if($rows21['PORT']=='LP')
		{
		    if($rows21['DEM_AMT']>0)
			{
			    $pdf->Ln(-1);

			
		   	    $pdf->Row1(array($array_number[$index], "      Load Port ".$obj->getPortNameBasedOnID($rows21['PORTID']), $currency_symbol." ".$rows21['DEM_AMT'], '', '', '', '',number_format($rows21['DEM_AMT']*$exchange_rate,2,'.',',')));
				$index++;
			}else{
			    $pdf->Ln(-1);
			    $pdf->Row1(array($array_number[$index], "      Load Port ".$obj->getPortNameBasedOnID($rows21['PORTID']),$currency_symbol."  (-) ".str_replace("-","",$rows21['DEM_AMT']), '', '', '', '',"(-) ".str_replace("-","",number_format($rows21['DEM_AMT']*$exchange_rate,2,'.',','))));
				$index++;
			}  
			$amount = $amount + $rows21['DEM_AMT']*$exchange_rate;

			
		}
		
		if($rows21['PORT']=='DP')
		{
			if($rows21['DEM_AMT']>0)
			{
			    $pdf->Ln(-1);
		   	    $pdf->Row1(array($array_number[$index], " Discharge Port ".$obj->getPortNameBasedOnID($rows21['PORTID']), $currency_symbol." ".$rows21['DEM_AMT'], '', '', '', '',number_format($rows21['DEM_AMT']*$exchange_rate,2,'.',',')));
				$index++;
			}else{
			    $pdf->Ln(-1);
			    $pdf->Row1(array($array_number[$index], " Discharge Port ".$obj->getPortNameBasedOnID($rows21['PORTID']), $currency_symbol." (-) ".str_replace("-","",$rows21['DEM_AMT']), '', '', '', '',"(-) ".str_replace("-","",number_format($rows21['DEM_AMT']*$exchange_rate,2,'.',','))));
				$index++;
			}  
			$amount = $amount + $rows21['DEM_AMT']*$exchange_rate;

			
		}
	}
	
	$arr1=array('C','L','C','C','C','C','R');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);

	if($rows['ADDCOM_AMOUNT'] > 0)
	{
	    $pdf->SetFont('Calibri','',8);
	    $pdf->SetTextColor(0,0,0);
		$arr1=array('C','L','C','C','C','C','R');
		$arr2=array(22,72,25,7,24,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Ln(-1);
		$pdf->Row1(array("", "(".$array_number[$index].") Less ".$rows['ADDCOM']."% ADD COMM ON 100% FREIGHT", '', '', '', '',number_format($rows['ADDCOM_AMOUNT']*$exchange_rate,2,'.',',')));
	    $index++;
		$amount = $amount - $rows['ADDCOM_AMOUNT']*$exchange_rate;

		
	}
	
	
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('C','R','C','C','C','C','R');
	$arr2=array(22,72,25,7,24,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$pdf->SetX(177);
	$pdf->Cell(24, 1, '', 'T', 1, 'L');
	$pdf->Ln(-1);



	$pdf->Row1(array("", "SUB TOTAL", '', '', '', '',number_format($amount,2,'.',',')));
	
	
	
	if($rows['BROKERAGE'] > 0)
	{
	    $pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('C','L','C','C','C','C','R');
		$arr2=array(22,72,25,7,24,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$pdf->Ln(-1);
		$pdf->Row1(array("", "(".$array_number[$index].") Less BROKERAGE(".$rows['BROKERAGE_PERCENT']."%)", '', '', '', '',number_format($rows['BROKERAGE']*$exchange_rate,2,'.',',')));
		
		$index++;
	}

	if ((int) $rows['GST_PERC'] > 0) {
		$pdf->Row1(array("", "(".$array_number[$index].") Less ".$rows['GST_PERC']." % GST on Brokerage", '', '', '', '',number_format($rows['GST_BROKAGE']*$exchange_rate,2,'.',',')));
	}
	
	$index++;
	// Less  18 % GST on Brokerage


		
	$sql2 = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD' and AMOUNT>0";
    $res2 = mysql_query($sql2);
	$num2 = mysql_num_rows($res2);

	
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $pdf->Ln(-1);
		$pdf->Row1(array("", $rows2['DESCRIPTION'], '', '', '', '',number_format($rows2['AMOUNT']*$exchange_rate,2,'.',',')));
	}
	
	$sql2 = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0";
    $res2 = mysql_query($sql2);
	$num2 = mysql_num_rows($res2);
		
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $pdf->Ln(-1);
		$pdf->Row1(array("","Less ".$rows2['DESCRIPTION'], '', '', '', '',number_format($rows2['AMOUNT']*$exchange_rate,2,'.',',')));
	}
	
	
	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(22,($initialY1 - $initialY),"",1,0,'L',0);
	$pdf->Cell(72,$ydifference,"",1,0,'L',0);
	$pdf->Cell(25,$ydifference,"",1,0,'L',0);
	$pdf->Cell(7,$ydifference,"",1,0,'L',0);
	$pdf->Cell(24,$ydifference,"",1,0,'L',0);
	$pdf->Cell(17,$ydifference,"",1,0,'L',0);
	$pdf->Cell(24,$ydifference,"",1,1,'L',0);
	
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('R','R','R');
	$arr2=array(150,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$initialY =  $pdf->GetY();

	if($rowjson['NOTIFICATION']!='')
	{
		
		$arr1=array('L');
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			$arr2=array(119);
		}else{
            $arr2=array(190);
		}
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		$initialY_n =  $pdf->GetY();
		$pdf->SetFont('Calibri','',8);
        $pdf->Row(array($rowjson['NOTIFICATION']));
		$initialY_n1 =  $pdf->GetY();
		$pdf->SetY($initialY_n);

		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			$pdf->SetX(129);
			$arr1=array('R','R','R');
			$arr2=array(30,17,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);

			
			$pdf->Row1(array("Total value        ","",number_format($rows['NET_PAYABLE']*$exchange_rate,2,'.',',')));
			$pdf->SetFont('Calibri','',8);
			if($rows['RDOVATGST'] == 1)
			{
				if($rows['GST_PERCENT']>0)
				{
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total GST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['GST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['GST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['IGST_PERCENT']>0)
				{
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total IGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['IGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['IGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['SGST_PERCENT']>0)
				{   
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total SGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['SGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['SGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['CGST_PERCENT']>0)
				{
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total CGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['CGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['CGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
			}else{
				if($rows['VAT_PERCENT']>0)
				{
					$pdf->SetX(129);
					$pdf->Cell(30,4,"Total VAT          ",0,0,'R',0);$pdf->Cell(17,4,$rows['VAT_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['VAT_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
			}
		}
       
		$pdf->SetX(129);
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('R','R','R');
		$arr2=array(30,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$sqlprev = "select * from freight_invoice_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR = '".$rows['VENDOR']."' and P_TYPE='".$rows['P_TYPE']."' and CARGOID='".$rows['CARGOID']."' and RANDOMID='".$rows['RANDOMID']."' and STATUS=5 and INVOICEID='".$rows['INVOICEID']."'";
		$resprev = mysql_query($sqlprev) or die($sqlprev);

		if($rows['I_TYPE'] !='Credit'){
			while($rowsprev = mysql_fetch_assoc($resprev))
			{
				$pdf->Ln(-1);
				$pdf->Row1(array("INITIAL FREIGHT RECEIVED", "", "(-) ".number_format($rowsprev['P_AMT']*$exchange_rate,2,'.',',')));
			}
		}
		
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetX(177);
		$pdf->Cell(24, 1, '', 'T', 1, 'L');

		$pdf->Ln(-1);
		$pdf->SetX(129);
		// $pdf->Row1(array("Grand Total (".$rows['EXCHANGE_CURRENCY'].")       ", "",number_format($rows['IGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',',')+number_format($rows['NET_PAYABLE']*$exchange_rate,2,'.',',')));

		
		$total_ldj_amt=($rows['GST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['SGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['IGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['CGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['NET_PAYABLE']*$exchange_rate);
		$total_ldj_amt = round($total_ldj_amt);
		$pdf->Row1(array("Grand Total (".$rows['EXCHANGE_CURRENCY'].")       ", "", number_format($total_ldj_amt,2,'.',',')));

		$initialY_n2 =  $pdf->GetY();
		if($initialY_n2 > $initialY_n1)
		{$lastY = $initialY_n2;}
		else{$lastY = $initialY_n1;}
	}
	else{
		if($rows['RDOTAXAPPLICABLE'] == 1)
		{
			$pdf->Ln(-1);
			$arr1=array('R','R','R');
			$arr2=array(150,17,24);
			$pdf->SetAligns($arr1);
			$pdf->SetWidths($arr2);

			
			$pdf->Row1(array("Total value       ","",number_format($rows['NET_PAYABLE']*$exchange_rate,2,'.',',')));
			$pdf->SetFont('Calibri','',8);
			if($rows['RDOVATGST'] == 1)
			{
				if($rows['GST_PERCENT']>0)
				{
					$pdf->Cell(150,4,"Total GST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['GST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['GST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['IGST_PERCENT']>0)
				{
					$pdf->Cell(150,4,"Total IGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['IGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['IGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['SGST_PERCENT']>0)
				{   
					$pdf->Cell(150,4,"Total SGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['SGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['SGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
				if($rows['CGST_PERCENT']>0)
				{
					$pdf->Cell(150,4,"Total CGST          ",0,0,'R',0);$pdf->Cell(17,4,$rows['CGST_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['CGST_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
			}else{
				if($rows['VAT_PERCENT']>0)
				{
					$pdf->Cell(150,4,"Total VAT          ",0,0,'R',0);$pdf->Cell(17,4,$rows['VAT_PERCENT']."%",0,0,'C',0);$pdf->Cell(24,4,number_format($rows['VAT_PERCENT_AMOUNT']*$exchange_rate,2,'.',','),0,1,'R',0);
				}
			}
		}
		$pdf->SetFont('Calibri','',8);
		$pdf->SetTextColor(0,0,0);
		$arr1=array('R','R','R');
		$arr2=array(150,17,24);
		$pdf->SetAligns($arr1);
		$pdf->SetWidths($arr2);
		
		$sqlprev = "select * from freight_invoice_master where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR = '".$rows['VENDOR']."' and P_TYPE='".$rows['P_TYPE']."' and CARGOID='".$rows['CARGOID']."' and RANDOMID='".$rows['RANDOMID']."' and STATUS=5 and INVOICEID<'".$rows['INVOICEID']."'";
		$resprev = mysql_query($sqlprev) or die($sqlprev);
		while($rowsprev = mysql_fetch_assoc($resprev))
		{
			$pdf->Ln(-1);
			$pdf->Row1(array("INITIAL FREIGHT RECEIVED          ", "", "(-) ".number_format($rowsprev['P_AMT']*$exchange_rate,2,'.',',')));
		}
		
		$pdf->SetFont('CalibriBold','',8);
		$pdf->SetX(177);
		$pdf->Cell(24, 1, '', 'T', 1, 'L');
		$pdf->Ln(-1);
		// $pdf->Row1(array("Grand Total (".$rows['EXCHANGE_CURRENCY'].")       ", "",number_format($rows['NET_PAYABLE_TAX']*$exchange_rate,2,'.',',')));
		
		//$total_ldj_amt=($rows['IGST_PERCENT_AMOUNT']*$exchange_rate)+($rows['NET_PAYABLE']*$exchange_rate);
		$total_ldj_amt=($rows['GST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['SGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['IGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['CGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['NET_PAYABLE']*$exchange_rate);
		$total_ldj_amt = round($total_ldj_amt);
		$pdf->Row1(array("Grand Total (".$rows['EXCHANGE_CURRENCY'].")       ", "",number_format($total_ldj_amt,2,'.',',')));

		$lastY = $pdf->GetY();
	}
	
	$pdf->SetY($lastY);
	$pdf->SetX(177);
	$pdf->Cell(24, 1, '', 'T', 1, 'L');
	
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L','R','R');
	$arr2=array(150,17,24);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	$pdf->Ln(-1);


	// $words_rs=str

	//$total_ldj_amt= explode(".",(string ) number_format(($rows['IGST_PERCENT_AMOUNT']*$exchange_rate)+($rows['NET_PAYABLE']*$exchange_rate),2,'.',''));
	$total_ldj = number_format(round(($rows['GST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['SGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['IGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['CGST_PERCENT_AMOUNT']*$exchange_rate) + ($rows['NET_PAYABLE']*$exchange_rate)),2,'.','');
	$total_ldj_amt= explode(".",(string ) $total_ldj);
	// ldj rs

	

	// library


	// $pdf->Row1(array("AMOUNT IN WORDS : ".strtoupper($rows['amount_in_words']), '', ''));


	if($total_ldj_amt[1] != '00'){
		$pdf->Row1(array("AMOUNT IN WORDS : RUPEES ".strtoupper($amttoword->convert_number_to_words($total_ldj_amt[0])." AND ".$amttoword->convert_number_to_words($total_ldj_amt[1])." Paise Only"), '', ''));
	}
	else{
		$pdf->Row1(array("AMOUNT IN WORDS : RUPEES ".strtoupper($amttoword->convert_number_to_words($total_ldj_amt[0])."  Only"), '', ''));
	}
	

	
	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(150,($initialY1 - $initialY),"",1,0,'L',0);
	$pdf->Cell(17,$ydifference,"",1,0,'L',0);
	$pdf->Cell(24,$ydifference,"",1,1,'L',0);
	
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L');
	$arr2=array(191);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	
	$pdf->Cell(191,4,"E & OE",1,1,'L',0);
	$pdf->Cell(191,4,"BANKING DETAILS:",1,1,'L',0);
	
	$initialY =  $pdf->GetY();
	
	$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	
	$pdf->SetFont('Calibri','',8);
	$pdf->SetTextColor(0,0,0);
	$arr1=array('L',"C","L");
	$arr2=array(25,6, 165);
	$pdf->SetAligns($arr1);
	$pdf->SetWidths($arr2);
	
	$pdf->Cell(25,4,"BENEFICIARY",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['NAME'],0,1,'L',0);
	$pdf->Cell(25,4,"ACCOUNT NO",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['AC_NO'],0,1,'L',0);

	if($rows2['ACCOUNT_TYPE']!=' ' || $rows2['ACCOUNT_TYPE']!=NULL){

		$pdf->Cell(25,4,"A/C TYPE",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['ACCOUNT_TYPE'],0,1,'L',0);
		
	}
	$pdf->Cell(25,4,"BANK NAME",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BANK'],0,1,'L',0);
	$pdf->Cell(25,4,"BRANCH",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BRANCH'],0,1,'L',0);
	$pdf->Cell(25,4,"BANK ADDRESS",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['B_ADDRESS'],0,1,'L',0);
	
	if($rows2['BANK_SWIFT_CODE']!='')
	{
	    $pdf->Cell(25,4,"SWIFT CODE",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['BANK_SWIFT_CODE'],0,1,'L',0);
	}
	if($rows2['IFSC']!='')
	{
		$pdf->Cell(25,4,"IFSC/NEFT Code",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['IFSC'],0,1,'L',0);
	}
	if($rows2['IBAN_NO']!='')
	{
		$pdf->Cell(25,4,"IBAN NO.",0,0,'L',0);$pdf->Cell(6,4,":",0,0,'L',0);$pdf->Cell(165,4,$rows2['IBAN_NO'],0,1,'L',0);
	}
	
			
			// $pdf->SetX(20);
			// $pdf->SetY(7);
			// $pdf->SetX(21);

	$initialY1 =  $pdf->GetY();
	$ydifference = $initialY1 - $initialY;
	$pdf->Ln(-($initialY1 - $initialY));
	$pdf->Cell(191,($initialY1 - $initialY),"",1,1,'L',0);
	
	$pdf->SetFont('CalibriBold','',9);
	$pdf->SetTextColor(10,10,10);
	$pdf->Cell(0,5,"FOR ".strtoupper($_SESSION['companyname']),0,1,'R',0);
	
	
	
		
		// $image_path12 = '../../attachment/'.$_SESSION['BARCODE_ATTACHMENT'];

		
	
		
	

	if($pdf->GetY()>245)
	{
	    $pdf->AddPage('P');
	
	    // $pdf->Ln(9);
	}
	$pdf->Ln(12);
	$pdf->SetFont('CalibriBold','',8);
	$pdf->SetTextColor(10,10,10);
	//$pdf->Cell("",1,1,'L',0);
	$pdf->SetX(10);

	if ($_SESSION['uid']=='159' || $_SESSION['uid']=='160') {
		if ($_SESSION['uid']=='159' && $rowjson['SHOW_SIGN'] == 1) {
			$image_path_ldj = '../../img/anilsign.jpg';
			
			$pdf->Image($image_path_ldj,175 ,($pdf->GetY()-10),23,0);

		}

		if ($_SESSION['uid']=='160' && $rowjson['SHOW_SIGN'] == 1) {
			$image_path_ldj = '../../img/poojasign.png';
			
			$pdf->Image($image_path_ldj,175 ,($pdf->GetY()-10),18,0);

		}
		

		
	}	


	// 	if($rowjson['SIGN'] !=''){
	// 	    $image_path_ldj = '../../attachment/'.$_SESSION['BARCODE_ATTACHMENT'];
	// 			$pdf->Image($image_path_ldj,158,10,38,38);
			
	//                     // 	$pdf->Image(",175 ,240,23,0);
			
	// 	}				

			
	
	$pdf->MultiCell(191,4,addslashes("Note: Please make the payment specified to the bank account mentioned in the Freight Invoice.\nM/s ".$_SESSION['companyname'].' India will only use account holder as M/s '.$_SESSION['companyname'].' India & our banker is '.$rows2['BANK'].". We will never request payment to another bank or other company on behalf of us to collect the remittance, if you received any invoice or payment request not matching with this information, please inform us immediately at /chartaccounts@actship.com/accounts.gim@actship.com. We will not be liable for any losses arising from failure to adhere to the above instructions. We recommed you to kindly check with us telephonically, before processing the funds. If required we shall FAX the invoice to your office."),0,'L',false);

	

	

	$filename = $invtitle." Of ".$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME")."(".$rows['I_TYPE'].")".date("d-M-Y",time()).".pdf";
	

	$pdf->Output($filename,'D');
}


?>
