<?php
session_start();
ini_set('display_errors', 1);
require_once("../../includes/Numbertowordconversion.php");
require_once("../../includes/functions_internal_user_dryout.inc.php");
require_once "../../vendor/autoload.php";

@$i = $_REQUEST['id'];
$ret = "";
switch ($i)
{
    case 1:
        $ret = create_freight_invoice_word();
				break;
	case 2:
        $ret = create_other_vc_invoice_word();
				break;
	case 3:
        $ret = create_hire_TC_invoice_word();
				break;
	case 4:
        $ret = create_Other_TC_invoice_word();
				break;
  
	default:
		    //$ret = funError();
				//echo $ret;
				break; 				
}

function create_Other_TC_invoice_word()
{
    $obj = new data();
	$amttoword = new Numbertowordconversion();
	$obj->funConnect();
	
	$invoiceid                      = $_REQUEST['im_id'];
	$comid 							= $_REQUEST['comid'];
	$tcoutid = $obj->getLatestCostSheetIDTC($comid);
    $obj->viewTCEstimationTempleteRecordsNew($tcoutid);
	$sql = "SELECT * from invoice_tcother_master where INVOICEID='".$invoiceid."' and COMID='".$comid."'";
	$res 	= mysql_query($sql);
	$rec 	= mysql_num_rows($res);
	$rows 	= mysql_fetch_assoc($res);
	
	$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); 
	
	$companyname        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME");
	$companyaddress     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1");
	$companycity        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY");
	$companycountry     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY");
	$companycode        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE");
	$companyemail       = $obj->getVendorListNewData($rows['SHIP_OWNER'],"EMAILID");
	$companytel         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PHONE");
	$companyvat         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
	$footeraddr         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
	$vendor_logo        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");
	$vlsImoId 		   = $obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID");

    if($rows['INVOICE_TYPE']=='Credit'){
		$invtitle = 'Credit Note';
		$inv_amt_title = 'to Credit';
	}else{
		$invtitle = 'Invoice';
		$inv_amt_title = 'Invoiced';
	}
	
	$phpWord = new \PhpOffice\PhpWord\PhpWord();
    $sectionstyle = array('marginLeft' => 600, 'marginRight' => 600);
	$section = $phpWord->addSection($sectionstyle);
	
	$header = $section->createHeader(array('marginTop' => 100, 'marginBottom' => 100));
	
	$table = $header->addTable();
	$table->addRow();
	$table->addCell(4000)->addImage('../../img/'.$vendor_logo, array('width' => 90, 'height' => 80, 'align' => 'left'));
	$table->addCell(8000)->addText($companyname,array('name' => 'Calibri', 'size' => 22, 'color' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKBLUE), array("align" => "right", 'space' => array('before' => 380)));
	$section->addLine(['weight' => 1, 'width' => 532, 'height' => 0, 'lineHeigth' => 1,'spaceBefore' => 0,'spaceAfter'=>0]);
	
	
	$footer = $section->createFooter();
	$footer->addLine(['weight' => 1, 'width' => 532, 'height' => 0, 'lineHeigth' => 10,'spaceBefore' => 0,'spaceAfter'=>0]);
	$footer->addText(ucwords(strtolower($footeraddr)),array('name' => 'Calibri', 'size' => 9), array('align' => 'center', 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$footer->addText(ucwords("Tel: ".$companytel."  email: ".$companyemail),array('name' => 'Calibri', 'size' => 9), array('align' => 'center', 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(3000)->addText($invtitle." No.",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($rows['INVOICE_NO'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Contract Ref.",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("CP Date ".date('d-m-Y',strtotime($obj->getFun9())),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText($invtitle." Date",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText(date('d-m-Y',strtotime($rows['INVOICE_DATE'])),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Due Date",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText(date('d-m-Y',strtotime($rows['DUE_DATE'])),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText("Vessel",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($obj->getVesselIMOData($vlsImoId,"VESSEL_NAME"),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($invtitle." Type",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Other",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(6000)->addText($invtitle." To:",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(6000)->addText($invtitle." From:",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addRow();
	$table->addCell(6000)->addText(htmlentities($obj->getVendorListNewData($rows['VENDOR'],"NAME"))."<w:br />".htmlentities(stripslashes($obj->getVendorListNewData($rows['VENDOR'],"STREET_1"))).", ".htmlentities(stripslashes($obj->getVendorListNewData($rows['VENDOR'],'CITY'))).", ".htmlentities(stripslashes($obj->getVendorListNewData($rows['VENDOR'],'COUNTRY'))).", ".htmlentities(stripslashes($obj->getVendorListNewData($rows['VENDOR'],'CITY_POSTAL_CODE'))),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(6000)->addText(htmlentities($companyname)."<w:br />".htmlentities(stripslashes($companyaddress))."<w:br />".htmlentities(stripslashes($companycity))."<w:br />".htmlentities(stripslashes($companycountry))."<w:br />".htmlentities(stripslashes($companycode)),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(12000)->addText("Payment Terms:- ".$rows['PAYMENT_TERMS'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$styleCell = ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff', 'borderSize' => 2];
	
	$table = $section->addTable([
	    'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	$table->addRow();
	$table->addCell(8000)->addText("Description",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000)->addText("Amount (USD)",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText($rows['INV_IDENTITY'],array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText(number_format($rows['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 10), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText($rows['SHORT_DESC'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>10));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>10));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText($rows['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>10));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>10));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Additional:",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from invoice_tcother_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD'";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     ".$rows2['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(+) ".number_format($rows2['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Less:",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	$sql2 = "select * from invoice_tcother_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB'";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     ".$rows2['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows2['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	
	$styleCell1 = ['borderTopColor' =>'ffffff', 'borderSize' => 2];
	$table->addRow();
	$table->addCell(8000, $styleCell1)->addText("Please remit above by SWIFT code and do NOT mention vessel name in order to avoid any delay in payment.",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell1)->addText("",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000)->addText("Total Amount ".$inv_amt_title,array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000)->addText(number_format($rows['FINAL_AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $table->addRow();
		$table->addCell(8000)->addText("Total Amount ".$inv_amt_title." (".$rows['EXCHANGE_CURRENCY'].")",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000)->addText(number_format(($rows['FINAL_AMOUNT']*$rows['EXCHANGE_RATE']),2,'.',','),array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(12000)->addText("Total amount in words: ",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addRow();
	$table->addCell(12000)->addText(strtoupper($amttoword->convert_number_to_words($rows['FINAL_AMOUNT'],"USD")),array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $table->addRow();
		$table->addCell(12000)->addText($amttoword->convert_number_to_words(number_format($rows['FINAL_AMOUNT']*$rows['EXCHANGE_RATE'],2,'.',''),$rows['EXCHANGE_CURRENCY']),array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(3000)->addText("Remit To:",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(9000)->addText("",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from banking_details where BD_ID='".$rows['BANKINGID']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	
	$table->addRow();
	$table->addCell(3000)->addText("Beneficiary",array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(9000)->addText($_SESSION['companyname']."<w:br />BENEFICIARY NAME: ".$rows2['NAME']."<w:br />BENEFICIARY BANK: ".$rows2['BANK']."<w:br />ADDRESS: ".$rows2['ADDRESS']."<w:br />ACCOUNT NUMBER: ".$rows2['AC_NO']."<w:br />SWIFT CODE: ".$rows2['BANK_SWIFT_CODE']."<w:br />IBAN No.: ".$rows2['IBAN_NO'],array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));

	
	$filename = $rows['INV_IDENTITY']." ".$invtitle." TC (".$obj->getVesselIMOData($vlsImoId,"VESSEL_NAME").") ".date("d-m-Y",time()).".docx";
	
	
	header("Content-Description: File Transfer");
	header('Content-Disposition: attachment; filename="'.$filename.'"');
	header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
	header('Content-Transfer-Encoding: binary');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Expires: 0');
	
	\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
	
	$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'Word2007');
	$xmlWriter->save("php://output");
	exit;

}


function create_hire_TC_invoice_word()
{
    $obj = new data();
	$amttoword = new Numbertowordconversion();
	$obj->funConnect();
	
	$invoiceid = $_REQUEST['im_id'];
	$comid 							= $_REQUEST['comid'];
	$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); 
	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'];}
	
	$companyname        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME");
	$companyaddress     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1");
	$companycity        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY");
	$companycountry     = $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY");
	$companycode        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE");
	$companyemail       = $obj->getVendorListNewData($rows['SHIP_OWNER'],"EMAILID");
	$companytel         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"PHONE");
	$companyvat         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
	$footeraddr         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
	$vendor_logo        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");
	$vlsImoId 		   = $obj->getCharteringEstimateTCData($rows['COMID'],"VESSEL_IMO_ID");

    if($rows['INVOICE_TYPE']=='Credit'){
		$invtitle = 'Credit Note';
		$inv_amt_title = 'to Credit';
	}else{
		$invtitle = 'Invoice';
		$inv_amt_title = 'Invoiced';
	}
	
	$phpWord = new \PhpOffice\PhpWord\PhpWord();
    $sectionstyle = array('marginLeft' => 600, 'marginRight' => 600);
	$section = $phpWord->addSection($sectionstyle);
	
	$header = $section->createHeader(array('marginTop' => 100, 'marginBottom' => 100));
	
	$table = $header->addTable();
	$table->addRow();
	$table->addCell(4000)->addImage('../../img/'.$vendor_logo, array('width' => 90, 'height' => 80, 'align' => 'left'));
	$table->addCell(8000)->addText($companyname,array('name' => 'Calibri', 'size' => 22, 'color' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKBLUE), array("align" => "right", 'space' => array('before' => 380)));
	$section->addLine(['weight' => 1, 'width' => 532, 'height' => 0, 'lineHeigth' => 1,'spaceBefore' => 0,'spaceAfter'=>0]);
	
	
	$footer = $section->createFooter();
	$footer->addLine(['weight' => 1, 'width' => 532, 'height' => 0, 'lineHeigth' => 10,'spaceBefore' => 0,'spaceAfter'=>0]);
	$footer->addText(ucwords(strtolower($footeraddr)),array('name' => 'Calibri', 'size' => 9), array('align' => 'center', 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$footer->addText(ucwords("Tel: ".$companytel."  email: ".$companyemail),array('name' => 'Calibri', 'size' => 9), array('align' => 'center', 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(3000)->addText($invtitle." No.",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($rows['INVOICE_NO'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Contract Ref.",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("CP Date ".date('d-m-Y',strtotime($obj->getFun9())),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$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 = '';}
	$table->addRow();
	$table->addCell(3000)->addText($invtitle." Date",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText(date('d-m-Y',strtotime($rows['INVOICE_DATE'])),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Due Date",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText(date('d-m-Y',strtotime($rows['DUE_DATE'])),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText("Vessel",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($obj->getVesselIMOData($vlsImoId,"VESSEL_NAME"),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($invtitle." Type",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Hire",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(6000)->addText($invtitle." To:",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(6000)->addText($invtitle." From:",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addRow();
	$table->addCell(6000)->addText(htmlentities($obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"NAME"))."<w:br />".htmlentities(stripslashes($obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],"STREET_1"))).", ".htmlentities(stripslashes($obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],'CITY'))).", ".htmlentities(stripslashes($obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],'COUNTRY'))).", ".htmlentities(stripslashes($obj->getVendorListNewData($rowstc['TTL_REV_VENDOR'],'CITY_POSTAL_CODE'))),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(6000)->addText(htmlentities($companyname)."<w:br />".htmlentities(stripslashes($companyaddress))."<w:br />".htmlentities(stripslashes($companycity))."<w:br />".htmlentities(stripslashes($companycountry))."<w:br />".htmlentities(stripslashes($companycode)),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(12000)->addText("Payment Terms:- ".$rows['PAYMENT_TERMS'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$styleCell = ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff', 'borderSize' => 2];
	
	$table = $section->addTable([
	    'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	$table->addRow();
	$table->addCell(8000)->addText("Description",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000)->addText("Amount (".$printcurrency.")",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Period ".date('d-m-Y H:i',strtotime($rows['HIRE_FROM_DATE']))." - ".date('d-m-Y H:i',strtotime($rows['HIRE_TO_DATE'])).", Total ".$rows['HIRE_DAYS']." Days",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText(number_format($rows['HIRE_INV_AMT'],2,'.',','),array('name' => 'Calibri', 'size' => 10), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("TC Hire for ".$rows['HIRE_DAYS']." days at ".$printcurrency." ".$dailyhirey." per day",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>10));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>10));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText($rows['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>10));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>10));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Additional:",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	if($rows['CVE_AMOUNT']>0)
	{
		
		$table->addRow();
		$table->addCell(8000, $styleCell)->addText("     CVE",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(+) ".number_format($rows['CVE_AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	$sql2 = "select * from invoice_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD'";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     ".$rows2['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(+) ".number_format($rows2['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	if($rows['IS_DELIVERYBUNKERS']==1)
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("   Delivery Bunkers",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		
		$sqltc4 = "SELECT BUNKERID, AMOUNT, QTY, PRICE, IDENTITY from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."'and IDENTITY='DEL'";
		$restc4 	= mysql_query($sqltc4);
		$rectc4 	= mysql_num_rows($restc4);
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
		    $table = $section->addTable([
				'borderSize' => 5, 
				'borderColor' => 'grey',  
				'Spacing'=> 0, 
				'cellMargin'  => 30
			]);
		    $table->addRow();
			$table->addCell(2000, ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff', 'borderRightColor' =>'ffffff', 'borderSize' => 2])->addText("     ".$obj->getBunkerGradeBasedOnID($rowstc4['BUNKERID']),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
			$table->addCell(3000, ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff','borderLeftColor' =>'ffffff', 'borderRightColor' =>'ffffff', 'borderSize' => 2])->addText($rowstc4['QTY'].'(MT)',array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
			$table->addCell(3000, ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff','borderLeftColor' =>'ffffff', 'borderSize' => 2])->addText(number_format(($rowstc4['PRICE']/$rowstc['EXCHANGE_RATE']),2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
			$table->addCell(4000, $styleCell)->addText("(+) ".number_format(($rowstc4['AMOUNT']/$rowstc['EXCHANGE_RATE']),2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
        }
	}
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Less:",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	if($rows['ADDRESS_COMMISSION_AMOUNT']>0)
	{    
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     Address Commission",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows['ADDRESS_COMMISSION_AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	if($rows['BROKER_COMMISSION_AMOUNT']>0)
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     Broker Commission",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows['BROKER_COMMISSION_AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	$sql2 = "select * from invoice_tchire_slave1 where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB'";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     ".$rows2['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows2['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	if($rows['IS_OFFHIRE']==1 && $rowstc3['SUM']>0)
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     Off-hire",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rowstc3['SUM'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	if($rows['CVE_OFFHIRE_AMOUNT']>0)
	{
		$table->addRow();
		$table->addCell(8000, $styleCell)->addText("     CVE on Off-Hire",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows['CVE_OFFHIRE_AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	if($rows['IS_REDELIVERYBUNKERS']==1)
	{
		$table->addRow();
		$table->addCell(8000, $styleCell)->addText("   Re-Delivery Bunkers",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$sqltc4 = "SELECT BUNKERID, AMOUNT, QTY, PRICE, IDENTITY from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rowstc['TC_SLAVE1ID']."'and IDENTITY='REDEL'";
		$restc4 	= mysql_query($sqltc4);
		$rectc4 	= mysql_num_rows($restc4);
		while($rowstc4 = mysql_fetch_assoc($restc4))
		{
		    $table = $section->addTable([
				'borderSize' => 5, 
				'borderColor' => 'grey',  
				'Spacing'=> 0, 
				'cellMargin'  => 30
			]);
		    $table->addRow();
			$table->addCell(2000, ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff', 'borderRightColor' =>'ffffff', 'borderSize' => 2])->addText("     ".$obj->getBunkerGradeBasedOnID($rowstc4['BUNKERID']),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
			$table->addCell(3000, ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff','borderLeftColor' =>'ffffff', 'borderRightColor' =>'ffffff', 'borderSize' => 2])->addText($rowstc4['QTY'].'(MT)',array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
			$table->addCell(3000, ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff','borderLeftColor' =>'ffffff', 'borderSize' => 2])->addText(number_format(($rowstc4['PRICE']/$rowstc['EXCHANGE_RATE']),2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
			$table->addCell(4000, $styleCell)->addText("(+) ".number_format(($rowstc4['AMOUNT']/$rowstc['EXCHANGE_RATE']),2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
        }
	}
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	
	$styleCell1 = ['borderTopColor' =>'ffffff', 'borderSize' => 2];
	$table->addRow();
	$table->addCell(8000, $styleCell1)->addText("Please remit above by SWIFT code and do NOT mention vessel name in order to avoid any delay in payment.",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell1)->addText("",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000)->addText("Total Amount ".$inv_amt_title,array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000)->addText(number_format($rows['FINAL_AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $table->addRow();
		$table->addCell(8000)->addText("Total Amount ".$inv_amt_title." (".$rows['EXCHANGE_CURRENCY'].")",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000)->addText(number_format(($rows['FINAL_AMOUNT']*$rows['EXCHANGE_RATE']),2,'.',','),array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(12000)->addText("Total amount in words: ",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addRow();
	$table->addCell(12000)->addText(strtoupper($amttoword->convert_number_to_words($rows['FINAL_AMOUNT'],$printcurrency)),array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $table->addRow();
		$table->addCell(12000)->addText($amttoword->convert_number_to_words(number_format($rows['FINAL_AMOUNT']*$rows['EXCHANGE_RATE'],2,'.',''),$rows['EXCHANGE_CURRENCY']),array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(3000)->addText("Remit To:",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(9000)->addText("",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from banking_details where BD_ID='".$rows['BANKINGID']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	
	$table->addRow();
	$table->addCell(3000)->addText("Beneficiary",array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(9000)->addText($_SESSION['companyname']."<w:br />BENEFICIARY NAME: ".$rows2['NAME']."<w:br />BENEFICIARY BANK: ".$rows2['BANK']."<w:br />ADDRESS: ".$rows2['ADDRESS']."<w:br />ACCOUNT NUMBER: ".$rows2['AC_NO']."<w:br />SWIFT CODE: ".$rows2['BANK_SWIFT_CODE']."<w:br />IBAN No.: ".$rows2['IBAN_NO'],array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));

	
	$filename = $invtitle." Of ".$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME")."(".$rows['I_TYPE'].")".date("d-M-Y",time()).".docx";
	
	
	header("Content-Description: File Transfer");
	header('Content-Disposition: attachment; filename="'.$filename.'"');
	header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
	header('Content-Transfer-Encoding: binary');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Expires: 0');
	
	\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
	
	$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'Word2007');
	$xmlWriter->save("php://output");
	exit;

}

function create_other_vc_invoice_word()
{
    $obj = new data();
	$amttoword = new Numbertowordconversion();
	$obj->funConnect();
	
	$im_id = $_REQUEST['im_id'];
    $sql = "select * from other_invoice_master where INVOICEID='".$im_id."'";
	$res = mysql_query($sql) or die($sql);
	$rows = mysql_fetch_assoc($res);
	$fcaid = $obj->getLatestCostSheetID($rows['COMID']);
	$obj->viewFreightCostEstimationTempleteRecordsNew($fcaid);
	$arr  = $obj->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$fcaid);

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

    
	$lp_name = array(); 
	$dp_name = array();
	
	if($rows['I_TYPE']=='Credit'){
		$invtitle = 'Credit Note';
		$inv_amt_title = 'to Credit';
	}else{
		$invtitle = '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';
	}
	
	$phpWord = new \PhpOffice\PhpWord\PhpWord();
    $sectionstyle = array('marginLeft' => 600, 'marginRight' => 600);
	$section = $phpWord->addSection($sectionstyle);
	//echo $vendor_logo;die;
	$header = $section->createHeader(array('marginTop' => 100, 'marginBottom' => 100));
	
	
	$table = $header->addTable();
	$table->addRow();
	$table->addCell(4000)->addImage('../../img/'.$vendor_logo, array('width' => 90, 'height' => 80, 'align' => 'left'));
	$table->addCell(8000)->addText($companyname,array('name' => 'Calibri', 'size' => 22, 'color' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKBLUE), array("align" => "right", 'space' => array('before' => 380)));
	$section->addLine(['weight' => 1, 'width' => 532, 'height' => 0, 'lineHeigth' => 1,'spaceBefore' => 0,'spaceAfter'=>0]);
	
	
	$footer = $section->createFooter();
	$footer->addLine(['weight' => 1, 'width' => 532, 'height' => 0, 'lineHeigth' => 10,'spaceBefore' => 0,'spaceAfter'=>0]);
	$footer->addText(ucwords(strtolower($_SESSION['footeraddr'])),array('name' => 'Calibri', 'size' => 9), array('align' => 'center', 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$footer->addText(ucwords("Tel: ".$_SESSION['companytel']."  email: ".$_SESSION['companyemail']),array('name' => 'Calibri', 'size' => 9), array('align' => 'center', 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(3000)->addText($invtitle." No.",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($rows['MESSAGE'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Contract Ref.",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("CP Date ".date("d-m-Y",strtotime($obj->getFun3())),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$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 = '';}
	$table->addRow();
	$table->addCell(3000)->addText($invtitle." Date",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($invdate,array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Due Date",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($duedate,array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText("Vessel",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME"),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($invtitle." Type",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Other",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText("Port of Loading",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($lp_name,array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Port of Discharging",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($dp_name,array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText("Voyage Number",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($obj->getFun8(),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(6000)->addText($invtitle." To:",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(6000)->addText($invtitle." From:",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addRow();
	$table->addCell(6000)->addText($obj->getVendorListNewBasedOnID($rows['VENDOR'])."<w:br />".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')),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(6000)->addText($obj->getVendorListNewBasedOnID($rows['SHIP_OWNER'])."<w:br />".stripslashes($obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STREET_1')),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(12000)->addText("Payment Terms:- ".$rows['PAYMENT_TERMS'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$styleCell = ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff', 'borderSize' => 2];
	
	$table = $section->addTable([
	    'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	$table->addRow();
	$table->addCell(8000)->addText("Description",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000)->addText("Amount (".$currency.")",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText($rows['REMARKS'],array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText(number_format($rows['GROSS_AMT'],2,'.',','),array('name' => 'Calibri', 'size' => 10), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Additional:",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from other_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD'";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     ".$rows2['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(+) ".number_format($rows2['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Less:",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from other_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB'";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     ".$rows2['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows2['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	
	$styleCell1 = ['borderTopColor' =>'ffffff', 'borderSize' => 2];
	$table->addRow();
	$table->addCell(8000, $styleCell1)->addText("PLEASE REMIT THE AMOUNT USING SWIFT CODE TO AVOID ANY PAYMENT DELAY (E &amp; O E)",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell1)->addText("",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000)->addText("Total Amount ".$inv_amt_title,array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000)->addText(number_format($rows['NET_PAYABLE'],2,'.',','),array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $table->addRow();
		$table->addCell(8000)->addText("Total Amount ".$inv_amt_title." (".$rows['EXCHANGE_CURRENCY'].")",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000)->addText(number_format(($rows['NET_PAYABLE']*$rows['EXCHANGE_RATE']),2,'.',','),array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(12000)->addText("Total amount in words: ",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addRow();
	$table->addCell(12000)->addText(strtoupper($amttoword->convert_number_to_words($rows['NET_PAYABLE'],$currency)),array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $table->addRow();
		$table->addCell(12000)->addText($amttoword->convert_number_to_words(number_format($rows['NET_PAYABLE']*$rows['EXCHANGE_RATE'],2,'.',''),$rows['EXCHANGE_CURRENCY']),array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(3000)->addText("Remit To:",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(9000)->addText("",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	
	$table->addRow();
	$table->addCell(3000)->addText("Beneficiary",array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(9000)->addText($_SESSION['companyname']."<w:br />BENEFICIARY NAME: ".$rows2['NAME']."<w:br />BENEFICIARY BANK: ".$rows2['BANK']."<w:br />ADDRESS: ".$rows2['ADDRESS']."<w:br />ACCOUNT NUMBER: ".$rows2['AC_NO']."<w:br />SWIFT CODE: ".$rows2['BANK_SWIFT_CODE']."<w:br />IBAN No.: ".$rows2['IBAN_NO'],array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));

	
	$filename = 'Generate Other '.$invtitle.'.docx';
	
	header("Content-Description: File Transfer");
	header('Content-Disposition: attachment; filename="'.$filename.'"');
	header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
	header('Content-Transfer-Encoding: binary');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Expires: 0');
	
	\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
	
	$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'Word2007');
	$xmlWriter->save("php://output");
	exit;

}



function create_freight_invoice_word()
{
    $obj = new data();
	$amttoword = new Numbertowordconversion();
	$obj->funConnect();
	
	$im_id = $_REQUEST['im_id'];
    $sql = "select * from freight_invoice_master where INVOICEID='".$im_id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	$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['companyvat']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER");
	$_SESSION['footeraddr']         = $obj->getVendorListNewData($rows['SHIP_OWNER'],"FOOTER_DETAILS");
	$_SESSION['vendor_logo']        = $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDOR_LOGO");

    
	if($rows['I_TYPE']=='Credit'){
		$invtitle = 'Credit Note';
		$inv_amt_title = 'to Credit';
	}else{
		$invtitle = 'Invoice';
		$inv_amt_title = 'Invoiced';
	}
	
	$phpWord = new \PhpOffice\PhpWord\PhpWord();
    $sectionstyle = array('marginLeft' => 600, 'marginRight' => 600);
	$section = $phpWord->addSection($sectionstyle);
	
	$header = $section->createHeader(array('marginTop' => 100, 'marginBottom' => 100));
	
	$table = $header->addTable();
	$table->addRow();
	$table->addCell(4000)->addImage('../../img/'.$_SESSION['vendor_logo'], array('width' => 90, 'height' => 80, 'align' => 'left'));
	$table->addCell(8000)->addText($_SESSION['companyname'],array('name' => 'Calibri', 'size' => 22, 'color' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKBLUE), array("align" => "right", 'space' => array('before' => 380)));
	$section->addLine(['weight' => 1, 'width' => 532, 'height' => 0, 'lineHeigth' => 1,'spaceBefore' => 0,'spaceAfter'=>0]);
	
	
	$footer = $section->createFooter();
	$footer->addLine(['weight' => 1, 'width' => 532, 'height' => 0, 'lineHeigth' => 10,'spaceBefore' => 0,'spaceAfter'=>0]);
	$footer->addText(ucwords(strtolower($_SESSION['footeraddr'])),array('name' => 'Calibri', 'size' => 9), array('align' => 'center', 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$footer->addText(ucwords("Tel: ".$_SESSION['companytel']."  email: ".$_SESSION['companyemail']),array('name' => 'Calibri', 'size' => 9), array('align' => 'center', 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	$quantity = 0;
	$freightRate = 0;
	if($obj->getFun175()!='')
	{
	
		$sql12 = "select CARGO_MT, CARGO_CBM, RATE_USD_MT from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and SHIPPER_CHARTER='".$rows['VENDOR']."' 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['CARGO_CBM'];
		}
		else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
		{
			$quantity = $row12['CARGO_CBM'];
		}
		else
		{
		   $quantity = $row12['CARGO_MT'];
		}
		
		$freightRate = $row12['RATE_USD_MT'];
		
		$sql12 = "select CARGO_MT, CARGO_CBM, RATE_USD_MT from freight_cost_estimete_slave10 where FCAID='".$fcaid."' and SHIPPER_CHARTER='".$rows['VENDOR']."'  and RANDOMID='".$rows['RANDOMID']."' and STATUS=3";
		$res12 = mysql_query($sql12);
		$row12 = mysql_fetch_assoc($res12);
		if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
		{
			$dfqty = $row12['CARGO_CBM'];
		}
		else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
		{
			$dfqty = $row12['CARGO_CBM'];
		}
		else
		{
		   $dfqty = $row12['CARGO_MT'];
		}
		
		$freightRate = $freightRate + $row12['RATE_USD_MT'];
		
		$quantity = $quantity + $dfqty;
	}
	else
	{
		if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==1)
		{
			$quantity = $obj->getCompareEstimateData($rows['COMID'],"GAS_QUANTITY");
		}
		else if($obj->getCompareEstimateData($rows['COMID'],"ESTIMATE_TYPE")==2)
		{
			$quantity = $obj->getCompareEstimateData($rows['COMID'],"TANK_QUANTITY");
		}
		else
		{
			if($obj->getCompareEstimateData($rows['COMID'],"QTY_TYPE_RADIO")== 1)
			{
				$quantity = $obj->getCompareEstimateData($rows['COMID'],"QUANTITY");
				$freightRate = $obj->getCompareEstimateData($rows['COMID'],"FREIGHT_GROSS");
			}
			else
			{
				$sql12 = "select sum(QUANTITY) as sum, sum(AGREED_GROSS_FREIGHT) as sum2 from freight_cost_estimete_slave7 where FCAID='".$fcaid."' and QTY_VENDORID='".$rows['VENDOR']."' and RANDOMID='".$rows['RANDOMID']."'";
				$res12 = mysql_query($sql12);
				$row12 = mysql_fetch_assoc($res12);
				$quantity = $row12['sum'];
				$freightRate = $row12['sum2'];
			}
		}
	}
	
	$lp_name = array(); 
	$dp_name = array();
	$discharge_port = "";
	
	for($j=0;$j<count($arr);$j++)
	{   
		$arr_explode = explode('@@',$arr[$j]);
		if($arr_explode[0] == "LP"){$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';
	}
	
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(3000)->addText($invtitle." No.",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($rows['MESSAGE'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Contract Ref.",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("CP Date ".date("d-m-Y",strtotime($obj->getFun3())),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$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 = '';}
	$table->addRow();
	$table->addCell(3000)->addText($invtitle." Date",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($invdate,array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Due Date",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($duedate,array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText("Vessel",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME"),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($invtitle." Type",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Freight",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText("Port of Loading",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($lp_name,array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Port of Discharging",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($dp_name,array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(3000)->addText("B/L Quantity (MT)",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($quantity,array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText("Freight Rate (".$currency." PMT)",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(3000)->addText($freightRate,array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(6000)->addText($invtitle." To:",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(6000)->addText($invtitle." From:",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addRow();
	$table->addCell(6000)->addText($obj->getVendorListNewBasedOnID($rows['VENDOR'])."<w:br />".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')),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(6000)->addText($obj->getVendorListNewBasedOnID($rows['SHIP_OWNER'])."<w:br />".stripslashes($obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'STREET_1')),array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(12000)->addText("Payment Terms:- ".$rows['PAYMENT_TERMS'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$styleCell = ['borderTopColor' =>'ffffff', 'borderBottomColor' =>'ffffff', 'borderSize' => 2];
	
	$table = $section->addTable([
	    'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	$table->addRow();
	$table->addCell(8000)->addText("Description",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000)->addText("Amount (".$currency.")",array('name' => 'Calibri', 'size' => 10), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText($rows['TO_1']." % of Freight",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText(number_format($rows['NET_AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 10), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText($rows['REMARKS'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>10));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>10));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Additional:",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='ADD' and AMOUNT>0";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     ".$rows2['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(+) ".number_format($rows2['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("Less:",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText('',array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from freight_invoice_slave where INVOICEID='".$rows['INVOICEID']."' and IDENTIFY='SUB' and AMOUNT>0";
    $res2 = mysql_query($sql2);
    while($rows2 = mysql_fetch_assoc($res2))
	{
	    $table->addRow();
		$table->addCell(8000, $styleCell)->addText("     ".$rows2['DESCRIPTION'],array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows2['AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("     Brokerage(".$rows['BROKERAGE_PERCENT']."%)",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows['BROKERAGE'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 90,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000, $styleCell)->addText("     Less Addcom(".$rows['ADDCOM']."%)",array('name' => 'Calibri', 'size' => 9), array("align" => "left", 'lineHeigth' => 190,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell)->addText("(-) ".number_format($rows['ADDCOM_AMOUNT'],2,'.',','),array('name' => 'Calibri', 'size' => 9), array("align" => "right", 'lineHeigth' => 190,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	$styleCell1 = ['borderTopColor' =>'ffffff', 'borderSize' => 2];
	$table->addRow();
	$table->addCell(8000, $styleCell1)->addText("PLEASE REMIT THE AMOUNT USING SWIFT CODE TO AVOID ANY PAYMENT DELAY (E &amp; O E)",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000, $styleCell1)->addText("",array('name' => 'Calibri', 'size' => 9, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$table->addRow();
	$table->addCell(8000)->addText("Total Amount ".$inv_amt_title,array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(4000)->addText(number_format($rows['NET_PAYABLE'],2,'.',','),array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $table->addRow();
		$table->addCell(8000)->addText("Total Amount ".$inv_amt_title." (".$rows['EXCHANGE_CURRENCY'].")",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
		$table->addCell(4000)->addText(number_format(($rows['NET_PAYABLE']*$rows['EXCHANGE_RATE']),2,'.',','),array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "right", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(12000)->addText("Total amount in words: ",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addRow();
	$table->addCell(12000)->addText(strtoupper($amttoword->convert_number_to_words($rows['NET_PAYABLE'],$currency)),array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	
	if($rows['EXCHANGE_RATE']!=1)
	{
	    $table->addRow();
		$table->addCell(12000)->addText($amttoword->convert_number_to_words(number_format($rows['NET_PAYABLE']*$rows['EXCHANGE_RATE'],2,'.',''),$rows['EXCHANGE_CURRENCY']),array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	}
	
	$section->addTextBreak(1);
	$table = $section->addTable([
		'borderSize' => 5, 
		'borderColor' => 'grey',  
		'Spacing'=> 0, 
		'cellMargin'  => 30
	]);
	
	$table->addRow();
	$table->addCell(3000)->addText("Remit To:",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(9000)->addText("",array('name' => 'Calibri', 'size' => 10, 'bold'=>true), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	
	$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);
	
	$table->addRow();
	$table->addCell(3000)->addText("Beneficiary",array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));
	$table->addCell(9000)->addText($_SESSION['companyname']."<w:br />BENEFICIARY NAME: ".$rows2['NAME']."<w:br />BENEFICIARY BANK: ".$rows2['BANK']."<w:br />ADDRESS: ".$rows2['ADDRESS']."<w:br />ACCOUNT NUMBER: ".$rows2['AC_NO']."<w:br />SWIFT CODE: ".$rows2['BANK_SWIFT_CODE']."<w:br />IBAN No.: ".$rows2['IBAN_NO'],array('name' => 'Calibri', 'size' => 9, 'bold'=>false), array("align" => "left", 'lineHeigth' => 100,'spaceBefore' => 0,'spaceAfter'=>0));

	
	$filename = $invtitle." Of ".$obj->getVesselIMOData($obj->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME")."(".$rows['I_TYPE'].")".date("d-M-Y",time()).".docx";
	
	
	header("Content-Description: File Transfer");
	header('Content-Disposition: attachment; filename="'.$filename.'"');
	header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
	header('Content-Transfer-Encoding: binary');
	header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	header('Expires: 0');
	
	\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
	
	$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'Word2007');
	$xmlWriter->save("php://output");
	exit;

}


?>