<?php

include_once("../../connection/setting_jaldhi_class.php");

include_once("../../PHPMailer-5.2.26/PHPMailerAutoload.php");

class data
{
var $var_1;
var $var_2;
var $var_3;
var $var_4;
var $var_5;
var $var_6;
var $var_7;
var $var_8;
var $var_9;
var $var_10;
var $var_11;
var $var_12;
var $var_13;
var $var_14;
var $var_15;
var $var_16;
var $var_17;
var $var_18;
var $var_19;
var $var_20;
var $var_21;
var $var_22;
var $var_23;
var $var_24;
var $var_25;
var $var_26;
var $var_27;
var $var_28;
var $var_29;
var $var_30;
var $var_31;
var $var_32;
var $var_33;
var $var_34;
var $var_35;
var $var_36;
var $var_37;
var $var_38;
var $var_39;
var $var_40;
var $var_41;
var $var_42;
var $var_43;
var $var_44;
var $var_45;
var $var_46;
var $var_47;
var $var_48;
var $var_49;
var $var_50;
var $var_51;
var $var_52;
var $var_53;
var $var_54;
var $var_55;
var $var_56;
var $var_57;
var $var_58;
var $var_59;
var $var_60;
var $var_61;
var $var_62;
var $var_63;
var $var_64;
var $var_65;
var $var_66;
var $var_67;
var $var_68;
var $var_69;
var $var_70;
var $var_71;
var $var_72;
var $var_73;
var $var_74;
var $var_75;
var $var_76;
var $var_77;
var $var_78;
var $var_79;
var $var_80;
var $var_81;
var $var_82;
var $var_83;
var $var_84;
var $var_85;
var $var_86;
var $var_87;
var $var_88;
var $var_90;
var $var_91;
var $var_92;
var $var_93;
var $var_94;
var $var_95;
var $var_96;
var $var_97;
var $var_98;
var $var_99;
var $var_100;
var $var_101;
var $var_102;
var $var_103;
var $var_104;
var $var_105;
var $var_106;
var $var_107;
var $var_108;
var $var_109;
var $var_110;
var $var_111;
var $var_112;
var $var_113;
var $var_114;
var $var_115;
var $var_116;
var $var_117;
var $var_118;
var $var_119;
var $var_120;
var $var_121;
var $var_122;
var $var_123;
var $var_124;
var $var_125;
var $var_126;
var $var_127;
var $var_128;
var $var_129;
var $var_130;
var $var_131;
var $var_132;
var $var_133;
var $var_134;
var $var_135;
var $var_136;
var $var_137;
var $var_138;
var $var_139;
var $var_140;
var $var_141;
var $var_142;
var $var_143;
var $var_144;
var $var_145;
var $var_146;
var $var_147;
var $var_148;
var $var_149;
var $var_150;
var $var_151;
var $var_152;
var $var_153;
var $var_154;
var $var_155;
var $var_156;
var $var_157;
var $var_158;
var $var_159;
var $var_160;
var $var_161;
var $var_162;
var $var_163;
var $var_164;
var $var_165;
var $var_166;
var $var_167;
var $var_168;
var $var_169;
var $var_170;
var $var_171;
var $var_172;
var $var_173;
var $var_174;
var $var_175;
var $var_176;
var $var_177;
var $var_178;
var $var_179;
var $var_180;
var $var_181;
var $var_182;
var $var_183;
var $var_184;
var $var_185;
var $var_186;
var $var_187;
var $var_188;
var $var_189;
var $var_190;
var $var_191;
var $var_192;
var $var_193;
var $var_194;
var $var_195;
var $var_196;
var $var_197;
var $var_198;
var $var_199;
var $var_200;
var $var_201;
var $var_202;
var $var_203;
var $var_204;
var $var_205;
var $var_206;
var $var_207;
var $var_208;
var $var_209;
var $var_210;
var $var_211;
var $var_212;
var $var_213;
var $var_214;
var $var_215;
var $var_216;
var $var_217;
var $var_218;
var $var_219;
var $var_220;
var $var_221;
var $var_222;
var $var_223;
var $var_224;
var $var_225;
var $var_226;
var $var_227;
var $var_228;
var $var_229;
var $var_230;
var $var_231;
var $var_232;
var $var_233;
var $var_234;
var $var_235;
var $var_236;
var $var_237;
var $var_238;
var $var_239;
var $var_240;
var $var_241;
var $var_242;
var $var_243;
var $var_244;
var $var_245;
var $var_246;
var $var_247;
var $var_248;
var $var_249;
var $var_250;
var $var_251;
var $var_252;
var $var_253;
var $var_254;
var $var_255;
var $var_256;
var $var_257;
var $var_258;
var $var_259;
var $var_260;
var $var_261;
var $var_262;
var $var_263;
var $var_264;
var $var_265;
var $var_266;
var $var_267;
var $var_268;
var $var_269;
var $var_270;
var $var_271;
var $var_272;
var $var_273;
var $var_274;
var $var_275;
var $var_276;
var $var_277;
var $var_278;
var $var_279;
var $var_280;
var $var_281;
var $var_282;
var $var_283;
var $var_284;
var $var_285;
var $var_286;
var $var_287;
var $var_288;
var $var_289;
var $var_290;
var $var_291;
var $var_292;
var $var_293;
var $var_294;
var $var_295;
var $var_296;
var $var_297;
var $var_298;
var $var_299;
var $var_300;
var $var_301;
var $var_302;
var $var_303;
var $var_304;
var $var_305;
var $var_306;
var $var_307;
var $var_308;
var $var_309;
var $var_310;
var $var_311;
var $var_312;
var $var_313;
var $var_314;
var $var_315;
var $var_316;
var $var_317;
var $var_318;
var $var_319;
var $var_320;
var $var_321;
var $var_322;
var $var_323;
var $var_324;
var $var_325;
var $var_326;
var $var_327;
var $var_328;
var $var_329;
var $var_330;
var $var_331;
var $var_332;
var $var_333;
var $var_334;
var $var_335;
var $var_336;
var $var_337;
var $var_338;
var $var_339;
var $var_340;
var $var_341;
var $var_342;
var $var_343;
var $var_344;
var $var_345;
var $var_346;
var $var_347;
var $var_348;
var $var_349;
var $var_350;
var $var_351;
var $var_352;
var $var_353;
var $var_354;

function getFun1(){return $this->var_1;}
function getFun2(){return $this->var_2;}
function getFun3(){return $this->var_3;}
function getFun4(){return $this->var_4;}
function getFun5(){return $this->var_5;}
function getFun6(){return $this->var_6;}
function getFun7(){return $this->var_7;}
function getFun8(){return $this->var_8;}
function getFun9(){return $this->var_9;}
function getFun10(){return $this->var_10;}
function getFun11(){return $this->var_11;}
function getFun12(){return $this->var_12;}
function getFun13(){return $this->var_13;}
function getFun14(){return $this->var_14;}
function getFun15(){return $this->var_15;}
function getFun16(){return $this->var_16;}
function getFun17(){return $this->var_17;}
function getFun18(){return $this->var_18;}
function getFun19(){return $this->var_19;}
function getFun20(){return $this->var_20;}
function getFun21(){return $this->var_21;}
function getFun22(){return $this->var_22;}
function getFun23(){return $this->var_23;}
function getFun24(){return $this->var_24;}
function getFun25(){return $this->var_25;}
function getFun26(){return $this->var_26;}
function getFun27(){return $this->var_27;}
function getFun28(){return $this->var_28;}
function getFun29(){return $this->var_29;}
function getFun30(){return $this->var_30;}
function getFun31(){return $this->var_31;}
function getFun32(){return $this->var_32;}
function getFun33(){return $this->var_33;}
function getFun34(){return $this->var_34;}
function getFun35(){return $this->var_35;}
function getFun36(){return $this->var_36;}
function getFun37(){return $this->var_37;}
function getFun38(){return $this->var_38;}
function getFun39(){return $this->var_39;}
function getFun40(){return $this->var_40;}
function getFun41(){return $this->var_41;}
function getFun42(){return $this->var_42;}
function getFun43(){return $this->var_43;}
function getFun44(){return $this->var_44;}
function getFun45(){return $this->var_45;}
function getFun46(){return $this->var_46;}
function getFun47(){return $this->var_47;}
function getFun48(){return $this->var_48;}
function getFun49(){return $this->var_49;}
function getFun50(){return $this->var_50;}
function getFun51(){return $this->var_51;}
function getFun52(){return $this->var_52;}
function getFun53(){return $this->var_53;}
function getFun54(){return $this->var_54;}
function getFun55(){return $this->var_55;}
function getFun56(){return $this->var_56;}
function getFun57(){return $this->var_57;}
function getFun58(){return $this->var_58;}
function getFun59(){return $this->var_59;}
function getFun60(){return $this->var_60;}
function getFun61(){return $this->var_61;}
function getFun62(){return $this->var_62;}
function getFun63(){return $this->var_63;}
function getFun64(){return $this->var_64;}
function getFun65(){return $this->var_65;}
function getFun66(){return $this->var_66;}
function getFun67(){return $this->var_67;}
function getFun68(){return $this->var_68;}
function getFun69(){return $this->var_69;}
function getFun70(){return $this->var_70;}
function getFun71(){return $this->var_71;}
function getFun72(){return $this->var_72;}
function getFun73(){return $this->var_73;}
function getFun74(){return $this->var_74;}
function getFun75(){return $this->var_75;}
function getFun76(){return $this->var_76;}
function getFun77(){return $this->var_77;}
function getFun78(){return $this->var_78;}
function getFun79(){return $this->var_79;}
function getFun80(){return $this->var_80;}
function getFun81(){return $this->var_81;}
function getFun82(){return $this->var_82;}
function getFun83(){return $this->var_83;}
function getFun84(){return $this->var_84;}
function getFun85(){return $this->var_85;}
function getFun86(){return $this->var_86;}
function getFun87(){return $this->var_87;}
function getFun88(){return $this->var_88;}
function getFun89(){return $this->var_89;}
function getFun90(){return $this->var_90;}
function getFun91(){return $this->var_91;}
function getFun92(){return $this->var_92;}
function getFun93(){return $this->var_93;}
function getFun94(){return $this->var_94;}
function getFun95(){return $this->var_95;}
function getFun96(){return $this->var_96;}
function getFun97(){return $this->var_97;}
function getFun98(){return $this->var_98;}
function getFun99(){return $this->var_99;}
function getFun100(){return $this->var_100;}
function getFun101(){return $this->var_101;}
function getFun102(){return $this->var_102;}
function getFun103(){return $this->var_103;}
function getFun104(){return $this->var_104;}
function getFun105(){return $this->var_105;}
function getFun106(){return $this->var_106;}
function getFun107(){return $this->var_107;}
function getFun108(){return $this->var_108;}
function getFun109(){return $this->var_109;}
function getFun110(){return $this->var_110;}
function getFun111(){return $this->var_111;}
function getFun112(){return $this->var_112;}
function getFun113(){return $this->var_113;}
function getFun114(){return $this->var_114;}
function getFun115(){return $this->var_115;}
function getFun116(){return $this->var_116;}
function getFun117(){return $this->var_117;}
function getFun118(){return $this->var_118;}
function getFun119(){return $this->var_119;}
function getFun120(){return $this->var_120;}
function getFun121(){return $this->var_121;}
function getFun122(){return $this->var_122;}
function getFun123(){return $this->var_123;}
function getFun124(){return $this->var_124;}
function getFun125(){return $this->var_125;}
function getFun126(){return $this->var_126;}
function getFun127(){return $this->var_127;}
function getFun128(){return $this->var_128;}
function getFun129(){return $this->var_129;}
function getFun130(){return $this->var_130;}
function getFun131(){return $this->var_131;}
function getFun132(){return $this->var_132;}
function getFun133(){return $this->var_133;}
function getFun134(){return $this->var_134;}
function getFun135(){return $this->var_135;}
function getFun136(){return $this->var_136;}
function getFun137(){return $this->var_137;}
function getFun138(){return $this->var_138;}
function getFun139(){return $this->var_139;}
function getFun140(){return $this->var_140;}
function getFun141(){return $this->var_141;}
function getFun142(){return $this->var_142;}
function getFun143(){return $this->var_143;}
function getFun144(){return $this->var_144;}
function getFun145(){return $this->var_145;}
function getFun146(){return $this->var_146;}
function getFun147(){return $this->var_147;}
function getFun148(){return $this->var_148;}
function getFun149(){return $this->var_149;}
function getFun150(){return $this->var_150;}
function getFun151(){return $this->var_151;}
function getFun152(){return $this->var_152;}
function getFun153(){return $this->var_153;}
function getFun154(){return $this->var_154;}
function getFun155(){return $this->var_155;}
function getFun156(){return $this->var_156;}
function getFun157(){return $this->var_157;}
function getFun158(){return $this->var_158;}
function getFun159(){return $this->var_159;}
function getFun160(){return $this->var_160;}
function getFun161(){return $this->var_161;}
function getFun162(){return $this->var_162;}
function getFun163(){return $this->var_163;}
function getFun164(){return $this->var_164;}
function getFun165(){return $this->var_165;}
function getFun166(){return $this->var_166;}
function getFun167(){return $this->var_167;}
function getFun168(){return $this->var_168;}
function getFun169(){return $this->var_169;}
function getFun170(){return $this->var_170;}
function getFun171(){return $this->var_171;}
function getFun172(){return $this->var_172;}
function getFun173(){return $this->var_173;}
function getFun174(){return $this->var_174;}
function getFun175(){return $this->var_175;}
function getFun176(){return $this->var_176;}
function getFun177(){return $this->var_177;}
function getFun178(){return $this->var_178;}
function getFun179(){return $this->var_179;}
function getFun180(){return $this->var_180;}
function getFun181(){return $this->var_181;}
function getFun182(){return $this->var_182;}
function getFun183(){return $this->var_183;}
function getFun184(){return $this->var_184;}
function getFun185(){return $this->var_185;}
function getFun186(){return $this->var_186;}
function getFun187(){return $this->var_187;}
function getFun188(){return $this->var_188;}
function getFun189(){return $this->var_189;}
function getFun190(){return $this->var_190;}
function getFun191(){return $this->var_191;}
function getFun192(){return $this->var_192;}
function getFun193(){return $this->var_193;}
function getFun194(){return $this->var_194;}
function getFun195(){return $this->var_195;}
function getFun196(){return $this->var_196;}
function getFun197(){return $this->var_197;}
function getFun198(){return $this->var_198;}
function getFun199(){return $this->var_199;}
function getFun200(){return $this->var_200;}
function getFun201(){return $this->var_201;}
function getFun202(){return $this->var_202;}
function getFun203(){return $this->var_203;}
function getFun204(){return $this->var_204;}
function getFun205(){return $this->var_205;}
function getFun206(){return $this->var_206;}
function getFun207(){return $this->var_207;}
function getFun208(){return $this->var_208;}
function getFun209(){return $this->var_209;}
function getFun210(){return $this->var_210;}
function getFun211(){return $this->var_211;}
function getFun212(){return $this->var_212;}
function getFun213(){return $this->var_213;}
function getFun214(){return $this->var_214;}
function getFun215(){return $this->var_215;}
function getFun216(){return $this->var_216;}
function getFun217(){return $this->var_217;}
function getFun218(){return $this->var_218;}
function getFun219(){return $this->var_219;}
function getFun220(){return $this->var_220;}
function getFun221(){return $this->var_221;}
function getFun222(){return $this->var_222;}
function getFun223(){return $this->var_223;}
function getFun224(){return $this->var_224;}
function getFun225(){return $this->var_225;}
function getFun226(){return $this->var_226;}
function getFun227(){return $this->var_227;}
function getFun228(){return $this->var_228;}
function getFun229(){return $this->var_229;}
function getFun230(){return $this->var_230;}
function getFun231(){return $this->var_231;}
function getFun232(){return $this->var_232;}
function getFun233(){return $this->var_233;}
function getFun234(){return $this->var_234;}
function getFun235(){return $this->var_235;}
function getFun236(){return $this->var_236;}
function getFun237(){return $this->var_237;}
function getFun238(){return $this->var_238;}
function getFun239(){return $this->var_239;}
function getFun240(){return $this->var_240;}
function getFun241(){return $this->var_241;}
function getFun242(){return $this->var_242;}
function getFun243(){return $this->var_243;}
function getFun244(){return $this->var_244;}
function getFun245(){return $this->var_245;}
function getFun246(){return $this->var_246;}
function getFun247(){return $this->var_247;}
function getFun248(){return $this->var_248;}
function getFun249(){return $this->var_249;}
function getFun250(){return $this->var_250;}
function getFun251(){return $this->var_251;}
function getFun252(){return $this->var_252;}
function getFun253(){return $this->var_253;}
function getFun254(){return $this->var_254;}
function getFun255(){return $this->var_255;}
function getFun256(){return $this->var_256;}
function getFun257(){return $this->var_257;}
function getFun258(){return $this->var_258;}
function getFun259(){return $this->var_259;}
function getFun260(){return $this->var_260;}
function getFun261(){return $this->var_261;}
function getFun262(){return $this->var_262;}
function getFun263(){return $this->var_263;}
function getFun264(){return $this->var_264;}
function getFun265(){return $this->var_265;}
function getFun266(){return $this->var_266;}
function getFun267(){return $this->var_267;}
function getFun268(){return $this->var_268;}
function getFun269(){return $this->var_269;}
function getFun270(){return $this->var_270;}
function getFun271(){return $this->var_271;}
function getFun272(){return $this->var_272;}
function getFun273(){return $this->var_273;}
function getFun274(){return $this->var_274;}
function getFun275(){return $this->var_275;}
function getFun276(){return $this->var_276;}
function getFun277(){return $this->var_277;}
function getFun278(){return $this->var_278;}
function getFun279(){return $this->var_279;}
function getFun280(){return $this->var_280;}
function getFun281(){return $this->var_281;}
function getFun282(){return $this->var_282;}
function getFun283(){return $this->var_283;}
function getFun284(){return $this->var_284;}
function getFun285(){return $this->var_285;}
function getFun286(){return $this->var_286;}
function getFun287(){return $this->var_287;}
function getFun288(){return $this->var_288;}
function getFun289(){return $this->var_289;}
function getFun290(){return $this->var_290;}
function getFun291(){return $this->var_291;}
function getFun292(){return $this->var_292;}
function getFun293(){return $this->var_293;}
function getFun294(){return $this->var_294;}
function getFun295(){return $this->var_295;}
function getFun296(){return $this->var_296;}
function getFun297(){return $this->var_297;}
function getFun298(){return $this->var_298;}
function getFun299(){return $this->var_299;}
function getFun300(){return $this->var_300;}
function getFun301(){return $this->var_301;}
function getFun302(){return $this->var_302;}
function getFun303(){return $this->var_303;}
function getFun304(){return $this->var_304;}
function getFun305(){return $this->var_305;}
function getFun306(){return $this->var_306;}
function getFun307(){return $this->var_307;}
function getFun308(){return $this->var_308;}
function getFun309(){return $this->var_309;}
function getFun310(){return $this->var_310;}
function getFun311(){return $this->var_311;}
function getFun312(){return $this->var_312;}
function getFun313(){return $this->var_313;}
function getFun314(){return $this->var_314;}
function getFun315(){return $this->var_315;}
function getFun316(){return $this->var_316;}
function getFun317(){return $this->var_317;}
function getFun318(){return $this->var_318;}
function getFun319(){return $this->var_319;}
function getFun320(){return $this->var_320;}
function getFun321(){return $this->var_321;}
function getFun322(){return $this->var_322;}
function getFun323(){return $this->var_323;}
function getFun324(){return $this->var_324;}
function getFun325(){return $this->var_325;}
function getFun326(){return $this->var_326;}
function getFun327(){return $this->var_327;}
function getFun328(){return $this->var_328;}
function getFun329(){return $this->var_329;}
function getFun330(){return $this->var_330;}
function getFun331(){return $this->var_331;}
function getFun332(){return $this->var_332;}
function getFun333(){return $this->var_333;}
function getFun334(){return $this->var_334;}
function getFun335(){return $this->var_335;}
function getFun336(){return $this->var_336;}
function getFun337(){return $this->var_337;}
function getFun338(){return $this->var_338;}
function getFun339(){return $this->var_339;}
function getFun340(){return $this->var_340;}
function getFun341(){return $this->var_341;}
function getFun342(){return $this->var_342;}
function getFun343(){return $this->var_343;}
function getFun344(){return $this->var_344;}
function getFun345(){return $this->var_345;}
function getFun346(){return $this->var_346;}
function getFun347(){return $this->var_347;}
function getFun348(){return $this->var_348;}
function getFun349(){return $this->var_349;}
function getFun350(){return $this->var_350;}
function getFun351(){return $this->var_351;}
function getFun352(){return $this->var_352;}
function getFun353(){return $this->var_353;}
function getFun354(){return $this->var_354;}


function getFun355(){return $this->var_262;}
/*
* function used for connecting to the database
*/
function funConnect()
{
  $info = new clsSettings(); 
	$admin_site_server	= $info->admin_site;
	$admin_site_user	= $info->admin_siteuser;				
	$admin_site_passwd	= $info->admin_sitepass;
	$admin_site_db		= $info->admin_sitedatabase;
	//mysql_get_last_message()
	$link = mysql_connect($admin_site_server, $admin_site_user, $admin_site_passwd)			
			or die ('I cannot connect to the database because: ' . mysql_error());
			
	/* checks to see if the connection actually works */ 			
	if (!$link)
	{ 
		$this->errno = 1; 
		return NULL; 
	}
	mysql_select_db($admin_site_db,$link) or die( "unable to select the database becoz of : " . mysql_error());	
	return $link;
}


function funConnectMysqli()
{
  $info = new clsSettings(); 
	$admin_site_server	= $info->admin_site;
	$admin_site_user	= $info->admin_siteuser;				
	$admin_site_passwd	= $info->admin_sitepass;
	$admin_site_db		= $info->admin_sitedatabase;
	
	$link = mysqli_connect($admin_site_server, $admin_site_user, $admin_site_passwd, $admin_site_db)			
			or die ('I cannot connect to the database because: ' . mysqli_connect_error());
					
	if (!$link)
	{ 
		$this->errno = 1; 
		return NULL; 
	}
	return $link;
}

function updateviewEstimateDetails($id){


	$connect = $this->funConnect();
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 		= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	$market_rdo 		= addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	$txtAddnlCRate 		= addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlCRatePer   = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
    $txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	$txtCVE             = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt      	= addslashes(trim($_REQUEST['txtCVEAmt']));
	$txtHidCVEAmt   	= addslashes(trim($_REQUEST['txtHidCVEAmt']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	$txtDistributedRemarks     = addslashes(trim($_REQUEST['txtDistributedRemarks']));
	
	
	$selOpenPort 	 	= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 		= addslashes(trim($_REQUEST['selZone']));
	$selBroker          = addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 	= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 	= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    		= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    = addslashes(trim($_REQUEST['selOwner']));
	$txtDisponentOwner	= addslashes(trim($_REQUEST['txtDisponentOwner']));
	if($_REQUEST['txtFDate']!="")
	{
	$txtFDate     		= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	}


	else{$txtFDate     		= "1970-01-01";}
	if($_REQUEST['txtTDate']!="")
	{
	$txtTDate     		= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	}
	else{$txtTDate     		= "1970-01-01";}
	if($_REQUEST['txtETADate']!="")
	{
	$txtETADate     		= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	}
	else{$txtETADate     		= "1970-01-01";}
	if($_REQUEST['txtCPDate']!="")
	{
	$txtCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	}
	else{$txtCPDate     		= "1970-01-01";}
	$txtNotes     		= addslashes(trim($_REQUEST['txtNotes']));
	
	
	$txtCID 	 		= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       = addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 		= implode(',',$_REQUEST['selMType']);
	$txtMCode    		= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance	= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    = addslashes(trim($_REQUEST['selDPort']));
	
	if($_REQUEST['txtLCSDate']!="")
	{
	$txtLCSDate   		= date("Y-m-d",strtotime($_REQUEST['txtLCSDate']));
	}
	else{$txtLCSDate     		= "1970-01-01";}
	if($_REQUEST['txtLCFDate']!="")
	{
	$txtLCFDate     	= date("Y-m-d",strtotime($_REQUEST['txtLCFDate']));
	}
	else{$txtLCFDate     		= "1970-01-01";}
	
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$txtLumpsumQty          = $_REQUEST['txtLumpsumQty'];
	$selLumsumVendor        = addslashes(trim($_REQUEST['selLumsumVendor']));
	
	$txtBaseRateFloating    = addslashes(trim($_REQUEST['txtBaseRateFloating']));
	$txtBaseRateFixed       = addslashes(trim($_REQUEST['txtBaseRateFixed']));
	$txtBaseRateAverage     = addslashes(trim($_REQUEST['txtBaseRateAverage']));
	
	$txtGFreightFloating    = addslashes(trim($_REQUEST['txtGFreightFloating']));
	$txtGFreightFixed       = addslashes(trim($_REQUEST['txtGFreightFixed']));
	$txtGFreightAverage     = addslashes(trim($_REQUEST['txtGFreightAverage']));
	
	$txtNFreightFloating    = addslashes(trim($_REQUEST['txtNFreightFloating']));
	$txtNFreightFixed       = addslashes(trim($_REQUEST['txtNFreightFixed']));
	$txtNFreightAverage     = addslashes(trim($_REQUEST['txtNFreightAverage']));
	
	$txtOExpensesFloating   = addslashes(trim($_REQUEST['txtOExpensesFloating']));
	$txtOExpensesFixed      = addslashes(trim($_REQUEST['txtOExpensesFixed']));
	$txtOExpensesAverage    = addslashes(trim($_REQUEST['txtOExpensesAverage']));
	
	$txtVEarningFloating    = addslashes(trim($_REQUEST['txtVEarningFloating']));
	$txtVEarningFixed       = addslashes(trim($_REQUEST['txtVEarningFixed']));
	$txtVEarningAverage     = addslashes(trim($_REQUEST['txtVEarningAverage']));
	
	$txtDailyEarningFloating= addslashes(trim($_REQUEST['txtDailyEarningFloating']));
	$txtDailyEarningFixed   = addslashes(trim($_REQUEST['txtDailyEarningFixed']));
	$txtDailyEarningAverage = addslashes(trim($_REQUEST['txtDailyEarningAverage']));
	
	$txtTCEMonthFloating    = addslashes(trim($_REQUEST['txtTCEMonthFloating']));
	$txtTCEMonthFixed       = addslashes(trim($_REQUEST['txtTCEMonthFixed']));
	$txtTCEMonthAverage     = addslashes(trim($_REQUEST['txtTCEMonthAverage']));
	
	$txtOPExpensesFloating  = addslashes(trim($_REQUEST['txtOPExpensesFloating']));
	$txtOPExpensesFixed     = addslashes(trim($_REQUEST['txtOPExpensesFixed']));
	$txtOPExpensesAverage   = addslashes(trim($_REQUEST['txtOPExpensesAverage']));
	
	$txtNetDailyEarningFloating= addslashes(trim($_REQUEST['txtNetDailyEarningFloating']));
	$txtNetDailyEarningFixed= addslashes(trim($_REQUEST['txtNetDailyEarningFixed']));
	$txtNetDailyEarningAverage= addslashes(trim($_REQUEST['txtNetDailyEarningAverage']));
	
	$txtNetDailyProfitFloating= addslashes(trim($_REQUEST['txtNetDailyProfitFloating']));
	$txtNetDailyProfitFixed = addslashes(trim($_REQUEST['txtNetDailyProfitFixed']));
	$txtNetDailyProfitAverage= addslashes(trim($_REQUEST['txtNetDailyProfitAverage']));
	$selCargoPlanning  = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	
	$txtSDWTMT 	 	    = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	 		= addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM         = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 	 	= addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT     	 	= addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT    		= addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT    		= addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT           = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT     = addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT  	= addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM 	= addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT		= addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM   = addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT	 	= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT 	= addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT    	= addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT  		= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$rdoTankType        = addslashes(trim($_REQUEST['rdoTankType']));
	$txtTCNo            = addslashes(trim($_REQUEST['txtTCNo']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	$selPeriodContract = addslashes(trim($_REQUEST['selPeriodContract']));
	$txtBLCQMT              = addslashes(trim($_REQUEST['txtBLCQMT']));
    $txtLessPerQty          = addslashes(trim($_REQUEST['txtLessPerQty']));
	
    $txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$txtCRMFILE2							= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2							= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload2 = $this->getUpload($_FILES['attach_file1']);
	$name2 = $this->getUploadName($_FILES['attach_file1']);
	
	$upload2 = implode(',',$upload2);
	$name2 = implode(',',$name2);
	
	if($txtCRMFILE2 != '' && $upload2 != ''){ $upload2 = $txtCRMFILE2.','.$upload2;}
	else if($txtCRMFILE2 == '' && $upload2 != ''){ $upload2 = $upload2;}
	else if($txtCRMFILE2 != '' && $upload2 == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name2 != ''){ $name2 = $txtCRMNAME2.','.$name2;}
	else if($txtCRMNAME2 == '' && $name2 != ''){ $name2 = $name2;}
	else if($txtCRMNAME2 != '' && $name2 == ''){ $name2 = $txtCRMNAME2;}
	
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	
	if($_REQUEST['txtTCDeliveryDate']!="")
	{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate']));}
	else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtTCReDeliveryDate']!="")
	{$txtTCReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate']));}
	else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	$txtTCDelivery = addslashes(trim($_REQUEST['txtTCDelivery']));
	$txtTCReDelivery = addslashes(trim($_REQUEST['txtTCReDelivery']));
	$txtTankerFreightRate = addslashes(trim($_REQUEST['txtTankerFreightRate']));
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));

	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	
	$sql = "update freight_cost_estimete_master set FIXTURETYPEID='".$this->getCheckNullValue($selFType)."', TRANS_DATE='".$txtDate."', ADD_ON_DATE=NOW(), VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', VESSEL_TYPE='".$txtVType."', FLAG='".$txtFlag."', VOYAGE_NO='".$txtVNo."', VOYAGE_NAME='".$txtENo."', DWT_SUMMER='".$this->getCheckNullValue($txtDWTS)."', DWT_TOPICAL='".$this->getCheckNullValue($txtDWTT)."', RDO_CAP='".$this->getCheckNullValue($rdoCap)."', GRAIN_CAP='".$this->getCheckNullValue($txtGCap)."', BALE_CAP='".$this->getCheckNullValue($txtBCap)."', SF='".$this->getCheckNullValue($txtSF)."', LODABLE='".$this->getCheckNullValue($txtLoadable)."', GNRT='".$this->getCheckNullValue($txtGNRT)."', LOA='".$this->getCheckNullValue($txtLOA)."', GEAR='".$this->getCheckNullValue($txtGear)."', BUILD_YEAR='".$txtBuiltYear."', BEAM='".$this->getCheckNullValue($txtBeam)."', TPC='".$this->getCheckNullValue($txtTPC)."', BFULLSPEED='".$this->getCheckNullValue($txtBFullSpeed)."', BECOSPEED1='".$this->getCheckNullValue($txtBEcoSpeed1)."', BECOSPEED2='".$this->getCheckNullValue($txtBEcoSpeed2)."', LFULLSPEED='".$this->getCheckNullValue($txtLFullSpeed)."', LECOSPEED1='".$this->getCheckNullValue($txtLEcoSpeed1)."', LECOSPEED2='".$this->getCheckNullVal($txtLEcoSpeed2)."', BFOFULLSPEED='".$this->getCheckNullVal($txtBFOFullSpeed)."', BFOECOSPEED1='".$this->getCheckNullVal($txtBFOEcoSpeed1)."', BFOECOSPEED2='".$this->getCheckNullVal($txtBFOEcoSpeed2)."', LFOFULLSPEED='".$this->getCheckNullVal($txtLFOFullSpeed)."', LFOECOSPEED1='".$this->getCheckNullVal($txtLFOEcoSpeed1)."', LFOECOSPEED2='".$this->getCheckNullVal($txtLFOEcoSpeed2)."', PIFOFULLSPEED='".$this->getCheckNullValue($txtPIFOFullSpeed)."', PWFOFULLSPEED='".$this->getCheckNullValue($txtPWFOFullSpeed)."', BDOFULLSPEED='".$this->getCheckNullValue($txtBDOFullSpeed)."', BDOECOSPEED1='".$this->getCheckNullValue($txtBDOEcoSpeed1)."', BDOECOSPEED2='".$this->getCheckNullVal($txtBDOEcoSpeed2)."', LDOFULLSPEED='".$this->getCheckNullVal($txtLDOFullSpeed)."', LDOECOSPEED1='".$this->getCheckNullVal($txtLDOEcoSpeed1)."', LDOECOSPEED2='".$this->getCheckNullVal($txtLDOEcoSpeed2)."', PIDOFULLSPEED='".$this->getCheckNullVal($txtPIDOFullSpeed)."', PWDOFULLSPEED='".$this->getCheckNullVal($txtPWDOFullSpeed)."', RDO_MARKER='".$this->getCheckNullVal($rdoMMarket)."', RDO_DWT='".$this->getCheckNullValue($rdoDWT)."', FREIGHT_GROSS='".$this->getCheckNullVal($txtMTCPDRate)."', LUMSUM='".$this->getCheckNullVal($txtMLumpsum)."', CARGO_RATE='".$this->getCheckNullVal($txtAddnlCRate)."', QUANTITY='".$this->getCheckNullVal($txtCQMT)."', CARGO_TYPE='".$this->getCheckNullVal($selCType)."', CARGO_ID='".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."', DF_QUANTITY='".$this->getCheckNullVal($txtDFQMT)."', ADDNL_QUANTITY='".$this->getCheckNullValue($txtAddnlQMT)."', LADEN_DIST='".$this->getCheckNullValue($txtLDist)."', BALLAST_DIST='".$this->getCheckNullValue($txtBDist)."', LADEN_DAYS='".$this->getCheckNullValue($txtLDays)."', BALLAST_DAYS='".$this->getCheckNullVal($txtBDays)."', TOTAL_PASSAGE_DAYS='".$this->getCheckNullVal($txtTSDays)."', IDEAL_DAYS='".$this->getCheckNullVal($txtTtPIDays)."', WORKING_DAYS='".$this->getCheckNullVal($txtTtPWDays)."', TOTAL_DAYS='".$this->getCheckNullVal($txtTDays)."', TOTAL_DISTANCE='".$this->getCheckNullVal($txtTDist)."', FO_CONSP='".$this->getCheckNullVal($txtTFUMT)."', DO_CONSP='".$this->getCheckNullVal($txtTDUMT)."', GROSS_PREIGHT_ADJ='".$this->getCheckNullValue($txtFrAdjUsdGF)."', DEAD_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdDF)."', ADDNL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdAF)."', TOTAL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdTF)."', GROSS_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdGFMT)."', DEAD_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdDFMT)."', ADDNL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdAFMT)."', TOTAL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdTFMT)."', ADDRESS_COMMISSION_PER='".$this->getCheckNullValue($txtFrAdjPerAC)."', ADDRESS_COMMISSION_AMT='".$this->getCheckNullValue($txtFrAdjUsdAC)."', ADDRESS_COMMISSION_PRMT='".$this->getCheckNullValue($txtFrAdjUsdACMT)."', BROKERAGE_PER='".$this->getCheckNullValue($txtFrAdjPerAgC)."', BROKERAGE_AMT='".$this->getCheckNullVal($txtFrAdjUsdAgC)."', NET_PAYABLE='".$this->getCheckNullVal($txtFrAdjUsdFP)."', FINAL_NET_FREIGHT='".$this->getCheckNullVal($txtFGFFD)."', FINAL_NET_FREIGHT_PRMT='".$this->getCheckNullVal($txtFGFFDMT)."', BROKERAGE_COMMISSION_PER='".$this->getCheckNullVal($txtBrCommPercent)."', BROKERAGE_COMMISSION_AMT='".$this->getCheckNullVal($txtBrComm)."', REVENUES_FREIGHT='".$this->getCheckNullVal($txtRevenue)."', VOYAGE_EARNING='".$this->getCheckNullValue($txtVoyageEarnings)."', DAILY_EARNING='".$this->getCheckNullValue($txtDailyEarnings)."', DAILY_VESSEL_OPERATION_EXP='".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."', TOTAL_VOYAGE_EARNING='".$this->getCheckNullVal($txtGTTLVoyageEarnings)."', NET_DAILY_EARNING='".$this->getCheckNullVal($txtNettDailyEarnings)."', NET_DAILY_PROFIT='".$this->getCheckNullVal($txtNettDailyProfit)."', PROFIT_LOSS= '".$this->getCheckNullVal($txtPL)."', RDO_QTY='".$this->getCheckNullVal($rdoQty)."', HIREAGE_AMT='".$this->getCheckNullVal($txtHireargeAmt)."', HIREAGE_PERCENT='".$this->getCheckNullVal($txtHireargePercent)."', HIREAGE_PER_AMT='".$this->getCheckNullVal($txtHireargePercentAmt)."', HIREAGE_NETT_AMT='".$this->getCheckNullVal($txtNettHireargeAmt)."', CVE_AMT='".$this->getCheckNullVal($txtCVE)."', CVE_TOTALAMT='".$this->getCheckNullVal($txtCVEAmt)."', BALLAST_BONUS='".$this->getCheckNullVal($txtBallastBonus)."', BUNKER_EXPENSES='".$this->getCheckNullVal($txtTotalBunkerCost)."', PORT_EXPENSES='".$this->getCheckNullVal($txtTotalPortCost)."', QTY_TYPE_RADIO='".$rdoQtyType."', AGREED_GROSS_FREIGHT_LOCAL='".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', CURRENCYID='".$this->getCheckNullVal($selCurrencyMarList)."', EXCHANGE_RATE='".$this->getCheckNullVal($txtMarExchangeRate)."', DISTRIBUTED_REMARKS='".$txtDistributedRemarks."', OPEN_PORT='".$selOpenPort."', ZONE_OPEN='".$selZone."', BROKER='".$selBroker."', COA_SPOT='".$selCOASpot."', COA_NUMBER='".$selCOA."', COA_NUMBER_LIFT='".$txtNoLift."', NO_OF_SHIPMENT='', OWNER='".$selOwner."', DISPONENT_OWNER='".$txtDisponentOwner."', LAYCAN_START_DATE='".$txtFDate."', LAYCAN_FINISH_DATE='".$txtTDate."', ETA_DATE='".$txtETADate."', CP_DATE='".$txtCPDate."', REMARKS='".$txtNotes."', ATTACHMENT='".$upload1."', ATTACHMENT_NAME='".$name1."', CARGOID='".$txtCID."', SHIPPER='".$selShipper."', TOLERANCE='".$txtTolerance."', MATERIALID='".$selMType."', MATERIAL_CODE='".$txtMCode."', TERM_TOLERANCE='".$txtTermTolerance."', LPID='".$selLPort."', DPID='".$selDPort."', LAYCAN_CARGO_START_DATE='".$txtLCSDate."', LAYCAN_CARGO_FINISH_DATE='".$txtLCFDate."', ADDNL_FREIGHT_PER='".$this->getCheckNullVal($txtAddnlCRatePer)."', ESTIMATE_TYPE='".$this->getCheckNullVal($rdoEstimateType)."', GAS_MARKET='".$this->getCheckNullVal($rdoQtyMar)."', GAS_BALTIC='".$this->getCheckNullVal($txtBalticRate)."', ADDNL_PRENIUM='".$this->getCheckNullVal($txtAdnlPrenium)."', GAS_BASE_RATE='".$this->getCheckNullVal($txtBaseRate)."', GAS_QUANTITY='".$this->getCheckNullVal($txtGasCQMT)."', GAS_LUMSUM='".$this->getCheckNullVal($txtGASLumpsum)."', TANK_WS_FROM='".$this->getCheckNullVal($selWSFPort)."', TANK_WS_TO='".$this->getCheckNullVal($selWSTPort)."', TANK_FIXED_DIFF='".$this->getCheckNullVal($txtFixedDiff)."', TANK_QUANTITY='".$this->getCheckNullVal($txtTankQuantity)."', ATTACHMENT2='".$upload2."', ATTACHMENT2_NAME='".$name2."', CHK_LUMPSUM='".$this->getCheckNullVal($ChkLumpsum)."', LUMPSUMAMT='".$this->getCheckNullVal($txtLumpsum)."', WS_QTY='".$this->getCheckNullVal($txtLumpsumQty)."', LUMP_VENDOR='".$selLumsumVendor."', BASERATE_FLOAT='".$this->getCheckNullVal($txtBaseRateFloating)."', BASERATE_FIXED='".$this->getCheckNullVal($txtBaseRateFixed)."', BASERATE_AVERAGE='".$this->getCheckNullVal($txtBaseRateAverage)."', GROSS_FREIGHT_FLOAT='".$this->getCheckNullVal($txtGFreightFloating)."', GROSS_FREIGHT_FIXED='".$this->getCheckNullVal($txtGFreightFixed)."', GROSS_FREIGHT_AVERAGE='".$this->getCheckNullVal($txtGFreightAverage)."', NETFREIGHT_FLOAT='".$this->getCheckNullVal($txtNFreightFloating)."', NETFREIGHT_FIXED='".$this->getCheckNullVal($txtNFreightFixed)."', NETFREIGHT_AVERAGE='".$this->getCheckNullVal($txtNFreightAverage)."', OWNER_EXPENSES_FLOAT='".$this->getCheckNullVal($txtOExpensesFloating)."', OWNER_EXPENSES_FIXED='".$this->getCheckNullVal($txtOExpensesFixed)."', OWNER_EXPENSES_AVERAGE='".$this->getCheckNullVal($txtOExpensesAverage)."', VEARNING_FLOAT='".$this->getCheckNullVal($txtVEarningFloating)."', VEARNING_FIXED='".$this->getCheckNullVal($txtVEarningFixed)."', VEARNING_AVERAGE='".$this->getCheckNullVal($txtVEarningAverage)."', TCEEARNING_FLOAT='".$this->getCheckNullVal($txtDailyEarningFloating)."', TCEEARNING_FIXED='".$this->getCheckNullVal($txtDailyEarningFixed)."', TCEEARNING_AVERAGE='".$this->getCheckNullVal($txtDailyEarningAverage)."', TCE_MONTH_FLOAT='".$this->getCheckNullVal($txtTCEMonthFloating)."', TCE_MONTH_FIXED='".$this->getCheckNullVal($txtTCEMonthFixed)."', TCE_MONTH_AVERAGE='".$this->getCheckNullVal($txtTCEMonthAverage)."', OEXPENSES_FLOAT='".$this->getCheckNullVal($txtOPExpensesFloating)."', OEXPENSES_FIXED='".$this->getCheckNullVal($txtOPExpensesFixed)."', OEXPENSES_AVERAGE='".$this->getCheckNullVal($txtOPExpensesAverage)."', NET_DAILY_ER_FLOAT='".$this->getCheckNullVal($txtNetDailyEarningFloating)."', NET_DAILY_ER_FIXED='".$this->getCheckNullVal($txtNetDailyEarningFixed)."', NET_DAILY_ER_AVERAGE='".$this->getCheckNullVal($txtNetDailyEarningAverage)."', NET_DAILY_PROFIT_FLOAT='".$this->getCheckNullVal($txtNetDailyProfitFloating)."', NET_DAILY_PROFIT_FIXED='".$this->getCheckNullVal($txtNetDailyProfitFixed)."', NET_DAILY_PROFIT_AVERAGE='".$this->getCheckNullVal($txtNetDailyProfitAverage)."', OPEN_CARGOID='".$this->getCheckNullVal($selCargoPlanning)."', SUMMERDWTMT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMERDWTLT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMERDRAFTM='".$this->getCheckNullVal($txtSDraftM)."', SUMMERDRAFTFT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANT_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANT_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFTM='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CBFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', GROSS_BREAKDOWN='".$this->getCheckNullVal($txtGrossBreakeven)."', BREAKDOWN_MT='".$this->getCheckNullVal($txtBreakevenMT)."', TOTAL_ORC_EXP_AMT='".$this->getCheckNullVal($txtTTLORCAmt)."', TANKER_RADIO_SINGLE_DIS='".$this->getCheckNullVal($rdoTankType)."', TC_NO='".$txtTCNo."', GROSS_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtGrossHireargeAmt)."', HIERAGE_CVE='".$this->getCheckNullVal($txtHireargeCVE)."', HIERAGE_CVE_AMOUNT='".$this->getCheckNullVal($txtHireargeCVEAMT)."', OFF_HIRE_CVE='".$this->getCheckNullVal($txtOffHireCVE)."', OFF_HIRE_CVE_AMOUNT='".$this->getCheckNullVal($txtOffHireCVEAMT)."', LESS_OFF_HIRE='".$this->getCheckNullVal($txtLessOffHire)."', FINAL_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtFinalHireargeAmt)."', HIERAGE_BROKER_PERCENT= '".$this->getCheckNullVal($txtHireargeBroPercent)."', HIERAGE_BROKER_AMT= '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', TC_HIRE_DAYS='".$this->getCheckNullVal($txtTotalVoyageDays)."', TC_CP_DATE='".$txtTC_CPDate."', PERIODID='".$this->getCheckNullValue($selPeriodContract)."', LESS_PER_BLQTY='".$this->getCheckNullValue($txtLessPerQty)."', BL_QTY_FREIGHT='".$this->getCheckNullValue($txtBLCQMT)."', TC_DELIVERY_DATE='".$txtTCDeliveryDate."', TC_RE_DELIVERY_DATE='".$txtTCReDeliveryDate."', TC_DELIVERY_RANGE='".$txtTCDelivery."', TC_RE_DELIVERY_RANGE='".$txtTCReDelivery."', TANKER_FREIGHT_RATE='".$txtTankerFreightRate."', TANK_CLEANING_SECA_HRS='".$this->getCheckNullVal($txtTKSECAHrs)."', TANK_CLEANING_NONSECA_HRS='".$this->getCheckNullVal($txtTKNONSECAHrs)."', INERTING_SECA_HRS='".$this->getCheckNullVal($txtInertSECAHrs)."', INERTING_NONSECA_HRS='".$this->getCheckNullVal($txtInertNONSECAHrs)."', GAS_FREEING_SECA_HRS='".$this->getCheckNullVal($txtGFSECAHrs)."', GAS_FREEING_NONSECA_HRS='".$this->getCheckNullVal($txtGFNONSECAHrs)."', HEATING_SECA_HRS='".$this->getCheckNullVal($txtHeatSECAHrs)."', HEATING_NONSECA_HRS='".$this->getCheckNullVal($txtHeatNONSECAHrs)."', HEATING_SECA_HRS_1='".$this->getCheckNullVal($txtHeatSECAHrs1)."', HEATING_NONSECA_HRS_1='".$this->getCheckNullVal($txtHeatNONSECAHrs1)."' WHERE FCAID='".$id."' and MODULEID='".$this->getCheckNullValue($_SESSION['moduleid'])."' and MCOMPANYID='".$this->getCheckNullValue($_SESSION['company'])."'";
	
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	$arr_passage = array();
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['txtFCASlaveID_'.$i]))
		{
			$arr_passage[] = $_REQUEST['txtFCASlaveID_'.$i];
		}
	}
	$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$id."'";
    $res1 = mysql_query($sql1);
	while($rows1 = mysql_fetch_assoc($res1))
	{
		if(!in_array($rows1['FCA_SLAVEID'], $arr_passage))
        {
			$del_query2 = "delete from freight_cost_estimete_slave1 where FCAID='".$id."' and FCA_SLAVEID='".$rows1['FCA_SLAVEID']."' ";
            mysql_query($del_query2);
			mysql_query("commit");
		}
	}
	
	$del_query3 = "delete from  freight_cost_estimete_slave2 where FCAID='".$id."'";
	$del_query4 = "delete from  freight_cost_estimete_slave3 where FCAID='".$id."'";
	$del_query5 = "delete from  freight_cost_estimete_slave4 where FCAID='".$id."'";
	$del_query6 = "delete from  freight_cost_estimete_slave5 where FCAID='".$id."'";
	$del_query7 = "delete from  freight_cost_estimete_slave6 where FCAID='".$id."'";
	$del_query8 = "delete from  freight_cost_estimete_slave7 where FCAID='".$id."'";
	$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$id."'";
	$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$id."'";
	$del_query9 = "delete from  freight_cost_estimete_slave8 where FCAID='".$id."'";
	$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$id."'";
	$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$id."'";
	$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$id."'";
	$del_query16 = "delete from  freight_cost_estimete_slave16 where FCAID='".$id."'";
	$del_query17 = "delete from  freight_cost_estimete_slave17 where FCAID='".$id."'";
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query($del_query5);
	mysql_query($del_query6);
	mysql_query($del_query7);
	mysql_query($del_query8);
	mysql_query($del_query12);
	mysql_query($del_query10);
	mysql_query($del_query9);
	mysql_query($del_query13);
	mysql_query($del_query14);
	mysql_query($del_query15);
	mysql_query($del_query16);
	mysql_query($del_query17);
	mysql_query("commit");
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{
			if(isset($_REQUEST['txtFCASlaveID_'.$i]) && $_REQUEST['txtFCASlaveID_'.$i]!='')
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "update freight_cost_estimete_slave1 set FROM_PORT='".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."', TO_PORT='".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."', DIS_TYPE='".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."', PASSAGE_TYPE='".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."', DISTANCE='".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."', SPEED_TYPE='".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."', SPEED_ADJ='".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."', MARGIN_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."', LOAD_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."', LOAD_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."', LOAD_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."', LOAD_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."', LOAD_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."', LOAD_PORT_IDEAL_DAYS='".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."', DISC_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."', DISC_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."', DISC_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."', DISC_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."', DISC_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."', DISC_PORT_IDEAL_DATE='".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."', TRANSIT_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."', TRANSIT_PORT_IDLE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', DDCLP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."', DDCLP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."', DDCLP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."', DDCDP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."', DDCDP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."', DDCDP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."', IS_SHOW_DDCLP='".$_REQUEST['ChkShowDDCLP_'.$i]."', IS_SHOW_DDCDP='".$_REQUEST['ChkShowDDCDP_'.$i]."', RANDOMID='".$randomid."', DDCLP_COMM='".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', DDCDP_COMM='".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', CHK_LP_SECA='".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', CHK_DP_SECA='".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', CHK_TP_SECA='".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', TOTAL_VOYAGE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', SECA_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', SECA_DAYS='".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."' where FCAID='".$id."' and FCA_SLAVEID='".$_REQUEST['txtFCASlaveID_'.$i]."'";	
			}
			else
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
			    $sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_NETCOST, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_NETCOST, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, DDCLP_COMM, DDCDP_COMM, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS) values ('".$id."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['ChkShowDDCLP_'.$i]."','".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."')";	
			}
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] >0)
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."',1,'".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] >0)
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] >0)
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT) values ('".$id."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT) values ('".$id."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		$txtTID = $_REQUEST['txtTID'];
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtDisponentOwner_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_slave5 (FCAID, DISPONENT_OWNER) values ('".$id."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$txtQTYID = $_REQUEST['txtQTYID'];
		for($i=1 ; $i<=$txtQTYID ;$i++)
		{
			if($_REQUEST['selQtyVendorList_'.$i] != "")
			{
			    $randomid = $_REQUEST['txtQtySlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtQtySlaveRandomID_'.$i]) || $_REQUEST['txtQtySlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql2 = "insert into freight_cost_estimete_slave7 (FCAID, QTY_VENDORID, AGREED_GROSS_FREIGHT, QUANTITY, GROSS_FREIGHT, BROKERAGE, NET_BROKERAGE, NET_FREIGHT, NET_FREIGHT_PERMT, CURRENCYID, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, CARGO, RANDOMID) values ('".$id."','".$_REQUEST['selQtyVendorList_'.$i]."','".$_REQUEST['txtQtyAggriedFreight_'.$i]."','".$_REQUEST['txtFreightQty_'.$i]."','".$_REQUEST['txtQtyFreight_'.$i]."','".$_REQUEST['txtQtyBrokeragePer_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtQtyBrokerageAmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreightMT1_'.$i])."','".$this->getCheckNullVal($_REQUEST['selCurrencyDisList_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyLocalAggriedFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDisExchangeRate_'.$i])."','".$this->getCheckNullVal($_REQUEST['selQtyCargo_'.$i])."', '".$randomid."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		} 
		
		$txtTankID = $_REQUEST['txtTankID'];
		for($i=1 ; $i<=$txtTankID ;$i++)
		{
			if($_REQUEST['txtFreightSpecs_'.$i] != "")
			{
				$sql12 = "insert into freight_cost_estimete_slave12 (FCAID, FREIGHT_SPECS, CUSTOMER, MIN_CARGO_QTY, OVE_CARGO_QTY, MIN_FLAT_RATE, OVE_FLAT_RATE, MIN_WS, OVE_WS, MIN_DIS_LEG, OVE_DIS_LEG, MIN_DISTANCE, OVE_DISTANCE, MIN_AMOUNT, OVE_AMOUNT, TOTAL_QTY, TOTAL_AMOUNT) values ('".$id."', '".$_REQUEST['txtFreightSpecs_'.$i]."', '".$_REQUEST['selTankVendor_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtMinCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtOveCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinDisLeg_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveDisLeg_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinTotalDis_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveTotalDis_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinAmount_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtTotalTankQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTotalTankAmount_'.$i])."')";
				mysql_query($sql12) or die($sql12);
				mysql_query("commit");
			}
		}
		
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$id."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$id."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$txtHIREID = $_REQUEST['txtHIREID'];
		for($i=1 ; $i<=$txtHIREID ;$i++)
		{
			if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
			{
				if($_REQUEST['txtHireFrom_'.$i]!="")
				{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
				else{$txtHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtHireTo_'.$i]!="")
				{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
				else{$txtHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCHireRandom_'.$i]) || $_REQUEST['txtTCHireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCHireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave17 (FCAID, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE, HIRE_AMT, RANDOMID) values ('".$id."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireAmt_'.$i])."', '".$this->getCheckNullValue($randomid4)."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$id."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$id."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						 if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$id."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg; 
}


function getLoginidWiseAlertData($vesselid,$alerttype)
{
	$connect = $this->funConnect();
	$sql = "select * from alert_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and UPDATE_STATUS=1 and VESSEL_IMO_ID in (".$vesselid.") ";
	if($alerttype != "")
	{
		$sql .= " and ALERT_TYPE='".$alerttype."'";
	}
	
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$arr = array();
	if($rec > 0 )
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$arr[] = array("work" => $rows['WORK'] , "datetime" => date("d M Y H:i",strtotime($rows['WORK_DATE'])) ,"reportid" => $rows['ALERT_REPORT_ID'] ,"alert_msg" => $rows['ALERT_MESSAGE'],"alert_type" => $rows['ALERT_TYPE'],"vessel" => $rows['VESSEL_IMO_ID']);
		}
		return $arr;
	}
	else
	{
		return $arr;
	}
}

function getLoginidWiseRecentFiveWorks()
{
	$connect = $this->funConnect();
	$sql = "select * from recent_work_master where LOGINID='".$_SESSION['uid']."' order by RECENT_WORKID desc limit 10";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$arr = array();
	if($rec > 0 )
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$arr[] = array("work" => $rows['WORK'] , "datetime" => date("d M Y H:i",strtotime($rows['WORK_DATE'])));
		}
		return $arr;
	}
	else
	{
		return $arr;
	}
}


function getLoginidWiseAlerts()
{
	$connect = $this->funConnect();
	
	$sql = "select ALERTID, REDIRECTTO, COMMENTS, IDENTIFYID, ADDONDATE, IDENTIFY from alert_master where SENDTO='".$_SESSION['uid']."' and SHOW_STATUS=1 order by ADDONDATE desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$arr = array();
	if($rec > 0 )
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$arr[] = array("redirectto" => $rows['REDIRECTTO'], "alertid" => $rows['ALERTID'], 'identify'=> $rows['IDENTIFY'], "comment" => $rows['COMMENTS'] , "datetime" => date("d M Y H:i",strtotime($rows['ADDONDATE'])));
		}
		return $arr;
	}
	else
	{
		return $arr;
	}
}

function getCompanyNameBasedOnID($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from main_company where MCOMPANYID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function displayApprovalList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="approval_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle">#</th>';
	echo '<th align="left" valign="middle">Approval Name</th>';
	echo '<th align="left" valign="middle">Description</th>';
	echo '<th align="left" valign="middle">Status</th>';
	echo '<th align="center" valign="middle">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from approvals_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle">'.$i.'.</td>';
				echo '<td align="left" valign="middle">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['APPROVALID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['APPROVALID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatenecessaryapproval.php?id='.$rows['APPROVALID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function changeApprovalMasterStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	$sql = "update approvals_master set STATUS='".$tblstatus."' where APPROVALID='".$tblid."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Approval Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function insertApprovalsDetails()
{
	$connect = $this->funConnect();
	$name 		= addslashes(trim($_REQUEST['txtAName']));
	$desc 		= addslashes(trim($_REQUEST['txtDesc']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into approvals_master (NAME,DESCRIPTION,MODULEID,MCOMPANYID) values ('".$name."','".$desc."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Approval Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}


function viewApprovalRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM approvals_master where APPROVALID='".$id."' ";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['DESCRIPTION'];
	}
}

function updateApprovalMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtAName 				= addslashes(trim($_REQUEST['txtAName']));
	$txtDesc			 	= addslashes(trim($_REQUEST['txtDesc']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update approvals_master set NAME='".$txtAName."',DESCRIPTION='".$txtDesc."' where APPROVALID='".$id."' and  MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Approval Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}



function changeTerminallMasterStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	$sql = "update terminal_master set STATUS='".$tblstatus."' where TERMINALID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Terminal Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayTerminalList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="terminal_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="25%"  >Terminal Name</th>';
	echo '<th align="left" valign="middle" width="25%"  >Port Name</th>';
	echo '<th align="left" valign="middle" width="25%"  >Description</th>';	
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from terminal_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getPortNameBasedOnCode($rows['PORT_CODE']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['TERMINALID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['TERMINALID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateterminal.php?id='.$rows['TERMINALID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertTerminalDetails()
{
	$connect = $this->funConnect();
	$name 		= addslashes(trim($_REQUEST['txtTName']));
	$port_code	= addslashes(trim($_REQUEST['selPort']));
	$desc 		= addslashes(trim($_REQUEST['txtDesc']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into terminal_master (NAME,PORT_CODE,DESCRIPTION,MODULEID,MCOMPANYID) values ('".$name."','".$port_code."','".$desc."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Terminal Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}


function getPortList()
{
	$this->funConnect();
	$query = mysql_query("select PortId, PortName from port_master where STATUS=1 order by PortName ");
	echo '<option value = "" >---Select from list---</option>';
	@$selPort = @$_REQUEST['selPort'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['PortId'];
		 $value= $rows['PortName'];
	     echo '<option value="'.$key.'"';
		 if($key == @$selPort){ echo " selected";}
		 echo '>'.$value.'</option>';
		}
}

function getPortNameBasedOnCode($id)
{
	$this->funConnect();
	$sql 	= "select PortName, COUNTRY_NAME from port_master where PortCode='".$id."'";
	$res 	= mysql_query($sql);
	$rows 	= mysql_fetch_assoc($res);
	return $rows['PortName'].'('.$this->getCountryNameBasedOnID($rows['COUNTRY_NAME']).')';
}

function getPortCodeBasedOnID($id)
{
	$this->funConnect();
	$sql 	= "select PortCode from port_master where PortId='".$id."'";
	$res 	= mysql_query($sql);
	$rows 	= mysql_fetch_assoc($res);
	return $rows['PortCode'];
}

function viewTerminalRecords($id)
{
	$connect 	= $this->funConnect();
	$query 		= "SELECT * FROM terminal_master where TERMINALID='".$id."' ";
	$result 	= mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['DESCRIPTION'];
		$this->var_3 = $rows['PORT_CODE'];
	}
}

function updateTerminalMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtTName 				= addslashes(trim($_REQUEST['txtTName']));
	$port_code				= addslashes(trim($_REQUEST['selPort']));
	$txtDesc			 	= addslashes(trim($_REQUEST['txtDesc']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update terminal_master set NAME='".$txtTName."',DESCRIPTION='".$txtDesc."',PORT_CODE='".$port_code."' where TERMINALID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Terminal Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}



function changeCargoMasterStatusRecords()
{
	$connect			= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	$sql = "update cargo_master set STATUS='".$tblstatus."' where MATERIALID='".$tblid."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cargo Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function displayCargoList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="material_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="15%"  >Material Name</th>';
	echo '<th align="left" valign="middle" width="15%"  >Material Type</th>';
	echo '<th align="left" valign="middle" width="15%"  >Material Code</th>';
	echo '<th align="left" valign="middle" width="25%"  >Material Code Description</th>';
	echo '<th align="left" valign="middle" width="5%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from cargo_master order by MATERIALID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$arr = array(''=>'','1'=>'Gas','2'=>'Tanker','3'=>'Dry Cargo');
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MATERIAL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$arr[$rows['MATERIAL_TYPEID']].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MATERIAL_CODE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MATERIAL_CODE_DESC'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['MATERIALID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['MATERIALID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatematerial.php?id='.$rows['MATERIALID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertCargoDetails()
{
	$connect = $this->funConnect();
	$mtype 			= addslashes(trim($_REQUEST['txtMType']));
	$mcode	 		= addslashes(trim($_REQUEST['txtMCode']));
	$mtype_desc		= addslashes(trim($_REQUEST['txtMTypeDesc']));
	$mcode_desc		= addslashes(trim($_REQUEST['txtMCodeDesc']));
	$mgroup			= addslashes(trim($_REQUEST['txtMGroup']));
	$mgroup_desc	= addslashes(trim($_REQUEST['txtMGroupDesc']));
	$rdoMaterialType	= addslashes(trim($_REQUEST['rdoMaterialType']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into cargo_master (MATERIAL_TYPE,MATERIAL_CODE,MATERIAL_TYPE_DESC,MATERIAL_CODE_DESC,MODULEID,MCOMPANYID,MATERIAL_GROUP,MATERIAL_GROUP_DESC,MATERIAL_TYPEID) values ('".$mtype."','".$mcode."','".$mtype_desc."','".$mcode_desc."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$mgroup."','".$mgroup_desc."','".$rdoMaterialType."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cargo Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}

function viewCargoRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM cargo_master where MATERIALID='".$id."' ";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['MATERIAL_TYPE'];
		$this->var_2 = $rows['MATERIAL_CODE'];
		$this->var_3 = $rows['MATERIAL_TYPE_DESC'];
		$this->var_4 = $rows['MATERIAL_CODE_DESC'];
		$this->var_5 = $rows['MATERIAL_GROUP'];
		$this->var_6 = $rows['MATERIAL_GROUP_DESC'];
		$this->var_7 = $rows['MATERIAL_TYPEID'];
	}
}

function updateCargoMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$mtype 			= addslashes(trim($_REQUEST['txtMType']));
	$mcode	 		= addslashes(trim($_REQUEST['txtMCode']));
	$mtype_desc		= addslashes(trim($_REQUEST['txtMTypeDesc']));
	$mcode_desc		= addslashes(trim($_REQUEST['txtMCodeDesc']));
	$mgroup			= addslashes(trim($_REQUEST['txtMGroup']));
	$mgroup_desc	= addslashes(trim($_REQUEST['txtMGroupDesc']));
	$rdoMaterialType	= addslashes(trim($_REQUEST['rdoMaterialType']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update cargo_master set MATERIAL_TYPE='".$mtype."',MATERIAL_CODE='".$mcode."',MATERIAL_TYPE_DESC='".$mtype_desc."',MATERIAL_CODE_DESC='".$mcode_desc."',MATERIAL_GROUP='".$mgroup."',MATERIAL_GROUP_DESC='".$mgroup_desc."',MATERIAL_TYPEID='".$rdoMaterialType."' where MATERIALID='".$id."' ";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cargo Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function changeContractTypeStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update contract_type_master set STATUS='".$tblstatus."' where  CONTRACTTYPEID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Contract Type Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayContractTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="contract_list_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="25%"  >Contract Type</th>';
	echo '<th align="left" valign="middle" width="35%"  >Description</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from contract_type_master order by STATUS,CONTRACT_TYPE";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['CONTRACTTYPEID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CONTRACT_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['CONTRACTTYPEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['CONTRACTTYPEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatecontract_type.php?id='.$rows['CONTRACTTYPEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertContractTypeRecords()
{
	$connect				= $this->funConnect();
 	$contract_type			= addslashes(trim($_REQUEST['txtCType']));
	$description			= addslashes(trim($_REQUEST['txtDescription']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$sql = "insert into contract_type_master (CONTRACT_TYPE,DESCRIPTION,MODULEID,MCOMPANYID) values ('".$contract_type."','".$description."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Contract Type Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewContractTypeMasterRecords($id)
{
 	$connect = $this->funConnect();
	$query = "SELECT * FROM contract_type_master where CONTRACTTYPEID='".$id."' ";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['CONTRACT_TYPE'];
		$this->var_2 = $rows['DESCRIPTION'];
	}
}

function updateContractTypeRecords()
{
	$connect				= $this->funConnect();
	$contract_type			= addslashes(trim($_REQUEST['txtCType']));
	$description			= addslashes(trim($_REQUEST['txtDescription']));
	
	$id = $_REQUEST['id'];
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update contract_type_master set CONTRACT_TYPE='".$contract_type."',DESCRIPTION='".$description."' where CONTRACTTYPEID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Contract Type Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}





function InsertPortCostTypeMasterRecords()
{
	$connect				= $this->funConnect();
 	$id		 				= addslashes(trim($_REQUEST['txtCID']));
	$countries 				= implode(",",$_REQUEST['selCountry']);
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	for($i=1;$i<=$id;$i++)
	{
		if($_REQUEST['txtPCType_'.$i] != "")
		{
			$sql = "insert into port_cost_type_master (NAME ,COUNTRY_IDS,MODULEID,MCOMPANYID) values ('".$_REQUEST['txtPCType_'.$i]."' ,'".$countries."' ,'".$_SESSION['moduleid']."','".$_SESSION['company']."')";
			mysql_query($sql);
			$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Cost Type Record added successfully.',NOW())";
	        mysql_query($sql3) or die(mysql_error());
			mysql_query("commit"); 
		}
	}
	
	return $msg;
}

function getCountryListForMultiple()
{
	$connect = $this->funConnect();
	$query = mysql_query("select * from country_master where STATUS = 1 order by COUNTRY_NAME ");
	while($rows = mysql_fetch_assoc($query))
		{
			$value = $rows['COUNTRY_NAME'];
			$key = $rows['COUNTRYID'];
			echo "<option value=$key";
			if($key == $id){ echo " selected";}
			echo ">".$value."</option>";
		}
}

function updatePortCostTypeMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtPCType 				= addslashes(trim($_REQUEST['txtPCType']));
	$countries 				= implode(",",$_REQUEST['selCountry']);
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update port_cost_type_master set NAME='".$txtPCType."',COUNTRY_IDS='".$countries."'  where PC_TYPE_ID='".$id."' AND MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Cost Type Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewPortCostTypeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM port_cost_type_master where PC_TYPE_ID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['COUNTRY_IDS'];
	}
}


function changePortCostTypeMasterStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update port_cost_type_master set STATUS='".$tblstatus."' where PC_TYPE_ID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Cost Type Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayPortCostTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="port_cost_type_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle">#</th>';
	echo '<th align="left" valign="middle">Port Cost Type</th>';
	echo '<th align="left" valign="middle">Countries</th>';
	echo '<th align="left" valign="middle">Status</th>';
	echo '<th align="center" valign="middle">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from port_cost_type_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['PC_TYPE_ID'];
				echo '<tr>';
				echo '<td align="center" valign="middle">'.$i.'.</td>';
				echo '<td align="left" valign="middle">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle">'.$this->getCountryNameForMultiple($rows['COUNTRY_IDS']).'</td>';
				echo '<td align="left" valign="middle">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['PC_TYPE_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['PC_TYPE_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle"><a href="updateport_cost_type.php?id='.$rows['PC_TYPE_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function getCountryNameForMultiple($id)
{
	$connect				= $this->funConnect();
	$arr = explode(",",$id);
	for($i=0;$i<count($arr);$i++)
	{
		$country_arr[] = $this->getCountryNameBasedOnID($arr[$i]);
	}
	return implode(" , ",$country_arr);
}


function getCountryData($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from country_master where COUNTRYID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getCountryListForMultipleUpdate($country_ids)
{
	$connect = $this->funConnect();
	$c_arr = explode(",",$country_ids);
	$query = mysql_query("select * from country_master where STATUS = 1 order by COUNTRY_NAME ");
	while($rows = mysql_fetch_assoc($query))
		{
			$value = $rows['COUNTRY_NAME'];
			$key = $rows['COUNTRYID'];
			echo "<option value=$key";
			if(in_array($key, $c_arr)){ echo " selected";}
			echo ">".$value."</option>";
		}
}



function changeAgencyFeeStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update agency_fee_record_master set STATUS='".$tblstatus."' where  AGENCYFEE_RECORDID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Agency Fee Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayAgencyFeeRecordList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="agency_fee_record_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="15%"  >Agent Name</th>';
	echo '<th align="left" valign="middle" width="15%"  >Port</th>';
	echo '<th align="left" valign="middle" width="15%"  >Date</th>';
	echo '<th align="left" valign="middle" width="15%"  >Fee</th>';
	echo '<th align="left" valign="middle" width="15%"  >Sundries</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from agency_fee_record_master order by STATUS,AGENCYFEE_RECORDID";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['AGENCYFEE_RECORDID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getVendorListNewBasedOnID($rows['AGENTMASTERID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getPortNameBasedOnID($rows['PORTID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.date("d-M-Y",strtotime($rows['DATE'])).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['FEE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SUNDRIES'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['AGENCYFEE_RECORDID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['AGENCYFEE_RECORDID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateagency_fee_record.php?id='.$rows['AGENCYFEE_RECORDID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function getPortNameBasedOnID($id)
{
	$this->funConnect();
	$sql = "select PortName, COUNTRY_KEY from port_master where PortId='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['PortName'].' ('.$rows['COUNTRY_KEY'].')';
}


function InsertAgencyFeeRecords()
{
	$connect				= $this->funConnect();
 	$date	 				= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$vendor_type			= addslashes(trim($_REQUEST['selVType']));
	$agentid 				= addslashes(trim($_REQUEST['selAgent']));
	$portid 				= addslashes(trim($_REQUEST['selPort']));
	$fee	 				= addslashes(trim($_REQUEST['txtAFee']));
	$txtSundries			= addslashes(trim($_REQUEST['txtSundries']));
	$selCurrency	 		= addslashes(trim($_REQUEST['selCurrency']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$query = "select * from agency_fee_record_master where DATE='".$date."' and AGENTMASTERID='".$agentid."' and PORTID='".$portid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($query);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{//CURRENCYID, NAME, STATUS
		$sql = "insert into agency_fee_record_master (DATE, VENDOR_TYPEID, AGENTMASTERID, PORTID, FEE, MODULEID, MCOMPANYID, CURRENCYID, SUNDRIES) values ('".$date."','".$vendor_type."','".$agentid."','".$portid."','".$fee."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$selCurrency."','".$txtSundries."')";
		mysql_query($sql);
		$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Agency Fee Record added successfully.',NOW())";
	    mysql_query($sql3) or die(mysql_error());
		mysql_query("commit"); 
		return $msg;
	}
	else
	{
		return 1;
	}
}

function getVendorTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from vendor_type_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selVType = @$_REQUEST['selVType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['VENDOR_TYPEID'];
		 $value= addslashes($rows['NAME']);
		 echo "<option value='".$key."' ";
		 if($key == @$selVType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getVendorListNew()
{
	$this->funConnect();
	$query = mysql_query("select * from vendor_master where STATUS=1 and MCOMPANYID='".$_SESSION['company']."' order by NAME ");
	echo '<option value = "" >---Select from list---</option>';
	@$selVendor = @$_REQUEST['selVendor'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CODE'];
		 $value= addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
	     echo '<option value="'.$key.'"';
		 if($key == @$selVendor){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}

function getZoneList()
{
	$this->funConnect();
	$query = mysql_query("select ZoneId, ZoneName from ZONE_MASTER where STATUS=1 order by ZoneName ");
	echo "<option value = '' >---Select from list---</option>";
	@$selZone = @$_REQUEST['selZone'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['ZoneId'];
		 $value= $rows['ZoneName'];
		 echo "<option value='".$key."' ";
		 if($key == @$selZone){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getZoneNameBasedOnID($id)
{
	$this->funConnect();
	$query = mysql_query("select * from ZONE_MASTER where ZoneId='".$id."' and STATUS=1 order by ZoneName ");
	while($rows = mysql_fetch_assoc($query))
		{
		 $value= $rows['ZoneName'];
		}
		return $value;
}

function updateAgencyFeeRecords()
{
	$connect				= $this->funConnect();	
	$date	 				= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$vendor_type			= addslashes(trim($_REQUEST['selVType']));
	$agentid 				= addslashes(trim($_REQUEST['selAgent']));
	$portid 				= addslashes(trim($_REQUEST['selPort']));
	$fee	 				= addslashes(trim($_REQUEST['txtAFee']));
	$txtSundries			= addslashes(trim($_REQUEST['txtSundries']));
	$selCurrency	 		= addslashes(trim($_REQUEST['selCurrency']));
	
	$id = $_REQUEST['id'];
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	
	$sql = "update agency_fee_record_master set DATE='".$date."', FEE='".$fee."', VENDOR_TYPEID='".$vendor_type."', AGENTMASTERID='".$agentid."', PORTID='".$portid."', CURRENCYID='".$selCurrency."', SUNDRIES='".$txtSundries."' where AGENCYFEE_RECORDID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Agency Fee Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewAgencyFeeMasterRecords($id)
{
 	$connect = $this->funConnect();
	$query = "SELECT * FROM agency_fee_record_master where AGENCYFEE_RECORDID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['DATE'];
		$this->var_2 = $rows['VENDOR_TYPEID'];
		$this->var_3 = $rows['AGENTMASTERID'];
		$this->var_4 = $rows['PORTID'];
		$this->var_5 = $rows['FEE'];
		$this->var_6 = $rows['CURRENCYID'];
		$this->var_7 = $rows['SUNDRIES'];	}
}


function getVendorListNewBasedOnID($id)
{
	$this->funConnect();
	$sql 	= "select NAME, CODE from vendor_master where CODE='".$id."'";
	$res 	= mysql_query($sql);
	while($rows 	= mysql_fetch_assoc($res))
	{return addslashes($rows['NAME']);}
	return '';
}

function getVendorDataBasedOnID($id,$field)
{
	$connect = $this->funConnect();
	$sql  = "select ".$field." from vendor_master where CODE='".$id."' ";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return addslashes($rows[$field]);
}

function getVendorOnlyNameBasedOnID($id)
{
	$this->funConnect();
	$sql 	= "select NAME from vendor_master where VENDORID='".$id."'  and MCOMPANYID='".$_SESSION['company']."'";
	$res 	= mysql_query($sql);
	$rows 	= mysql_fetch_assoc($res);
	return addslashes($rows['NAME']);
}



function changeOtherShippingCostMasterStatusRecords()
{
	$connect	= $this->funConnect();
 	$tblid		= addslashes(trim($_REQUEST['txttblid']));
	$value 		= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update other_shipping_cost_master set STATUS='".$tblstatus."' where OTHER_SCOSTID='".$tblid."'"; /*and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";*/
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Other Shipping Cost Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function InsertOtherShippingCostMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$ecg	 				= addslashes(trim($_REQUEST['txtECG']));
	$ec		 				= addslashes(trim($_REQUEST['txtEC']));
	$ate	 				= addslashes(trim($_REQUEST['txtATE']));
	$pte	 				= addslashes(trim($_REQUEST['txtPTE']));
	$ct		 				= addslashes(trim($_REQUEST['txtCT']));
	$pn		 				= addslashes(trim($_REQUEST['txtPN']));
	$ck		 				= addslashes(trim($_REQUEST['txtCK']));
	$tax_code 				= addslashes(trim($_REQUEST['txtTaxCode']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into other_shipping_cost_master (NAME ,EXP_CLS_GROUP,EXP_CLS,ACC_TYP_EXP,POSTING_TYP_EXP,CONDITION_TYP,PARTNER_NUMBER,CURRENCY_KEY,TAX_CODE,MODULEID ,MCOMPANYID) values ('".$txtName."' ,'".$ecg."' ,'".$ec."' ,'".$ate."' ,'".$pte."' ,'".$ct."' ,'".$pn."' ,'".$ck."' ,'".$tax_code."' ,'".$_SESSION['moduleid']."' ,'".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Other Shipping Cost Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayOtherShippingCostList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="othershippingcost_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	
	$sql = "select * from other_shipping_cost_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['OTHER_SCOSTID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['OTHER_SCOSTID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['OTHER_SCOSTID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateother_shipping_cost_master.php?id='.$rows['OTHER_SCOSTID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>'; 
}

function updateOtherShippingCostMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$ecg	 				= addslashes(trim($_REQUEST['txtECG']));
	$ec		 				= addslashes(trim($_REQUEST['txtEC']));
	$ate	 				= addslashes(trim($_REQUEST['txtATE']));
	$pte	 				= addslashes(trim($_REQUEST['txtPTE']));
	$ct		 				= addslashes(trim($_REQUEST['txtCT']));
	$pn		 				= addslashes(trim($_REQUEST['txtPN']));
	$ck		 				= addslashes(trim($_REQUEST['txtCK']));
	$tax_code 				= addslashes(trim($_REQUEST['txtTaxCode']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update other_shipping_cost_master set NAME='".$txtName."' ,EXP_CLS_GROUP='".$ecg."' ,EXP_CLS='".$ec."' ,ACC_TYP_EXP='".$ate."' ,POSTING_TYP_EXP='".$pte."' ,CONDITION_TYP='".$ct."' ,PARTNER_NUMBER='".$pn."' ,CURRENCY_KEY='".$ck."' ,TAX_CODE='".$tax_code."' where OTHER_SCOSTID='".$id."'"; /*and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";*/
	
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Other Shipping Cost Record Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function viewOtherShippingCostRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM other_shipping_cost_master where OTHER_SCOSTID='".$id."' and MODULEID='".$_SESSION['moduleid']."'"; /*AND MCOMPANYID='".$_SESSION['company']."'";*/
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['EXP_CLS_GROUP'];
		$this->var_3 = $rows['EXP_CLS'];
		$this->var_4 = $rows['ACC_TYP_EXP'];
		$this->var_5 = $rows['POSTING_TYP_EXP'];
		$this->var_6 = $rows['CONDITION_TYP'];
		$this->var_7 = $rows['PARTNER_NUMBER'];
		$this->var_8 = $rows['CURRENCY_KEY'];
		$this->var_9 = $rows['TAX_CODE'];
	}
}

function changeOtherMiscCostMasterStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update other_misc_cost_master set STATUS='".$tblstatus."' where OTHER_MCOSTID='".$tblid."'"; /*and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";*/
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Other Miscellaneous Cost Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayOtherMiscCostList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="othermiscost_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	
	$sql = "select * from other_misc_cost_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
	
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['OTHER_MCOSTID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['OTHER_MCOSTID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['OTHER_MCOSTID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateother_miscellaneous_cost_master.php?id='.$rows['OTHER_MCOSTID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>'; 
}


function InsertOtherMiscCostMasterRecords()
{
	$connect				= $this->funConnect();
	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$ecg	 				= addslashes(trim($_REQUEST['txtECG']));
	$ec		 				= addslashes(trim($_REQUEST['txtEC']));
	$ate	 				= addslashes(trim($_REQUEST['txtATE']));
	$pte	 				= addslashes(trim($_REQUEST['txtPTE']));
	$ct		 				= addslashes(trim($_REQUEST['txtCT']));
	$pn		 				= addslashes(trim($_REQUEST['txtPN']));
	$ck		 				= addslashes(trim($_REQUEST['txtCK']));
	$tax_code 				= addslashes(trim($_REQUEST['txtTaxCode']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into other_misc_cost_master (NAME ,EXP_CLS_GROUP,EXP_CLS,ACC_TYP_EXP,POSTING_TYP_EXP,CONDITION_TYP,PARTNER_NUMBER,CURRENCY_KEY,TAX_CODE,MODULEID ,MCOMPANYID) values ('".$txtName."' ,'".$ecg."' ,'".$ec."' ,'".$ate."' ,'".$pte."' ,'".$ct."' ,'".$pn."' ,'".$ck."' ,'".$tax_code."' ,'".$_SESSION['moduleid']."' ,'".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Other Miscellaneous Cost Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateOtherMiscCostMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$ecg	 				= addslashes(trim($_REQUEST['txtECG']));
	$ec		 				= addslashes(trim($_REQUEST['txtEC']));
	$ate	 				= addslashes(trim($_REQUEST['txtATE']));
	$pte	 				= addslashes(trim($_REQUEST['txtPTE']));
	$ct		 				= addslashes(trim($_REQUEST['txtCT']));
	$pn		 				= addslashes(trim($_REQUEST['txtPN']));
	$ck		 				= addslashes(trim($_REQUEST['txtCK']));
	$tax_code 				= addslashes(trim($_REQUEST['txtTaxCode']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update other_misc_cost_master set NAME='".$txtName."',EXP_CLS_GROUP='".$ecg."' ,EXP_CLS='".$ec."' ,ACC_TYP_EXP='".$ate."' ,POSTING_TYP_EXP='".$pte."' ,CONDITION_TYP='".$ct."' ,PARTNER_NUMBER='".$pn."' ,CURRENCY_KEY='".$ck."' ,TAX_CODE='".$tax_code."' where OTHER_MCOSTID='".$id."'"; /*and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";*/
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Other Miscellaneous Cost Record Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewOtherMiscCostRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM other_misc_cost_master where OTHER_MCOSTID='".$id."' AND MODULEID='".$_SESSION['moduleid']."'"; /*AND MCOMPANYID='".$_SESSION['company']."'";*/
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['EXP_CLS_GROUP'];
		$this->var_3 = $rows['EXP_CLS'];
		$this->var_4 = $rows['ACC_TYP_EXP'];
		$this->var_5 = $rows['POSTING_TYP_EXP'];
		$this->var_6 = $rows['CONDITION_TYP'];
		$this->var_7 = $rows['PARTNER_NUMBER'];
		$this->var_8 = $rows['CURRENCY_KEY'];
		$this->var_9 = $rows['TAX_CODE'];
	}
}

function changeOwnerRelatedCostMasterStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update owner_related_cost_master set STATUS='".$tblstatus."' where OWNER_RCOSTID='".$tblid."'"; /*AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";*/
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Owner Related Cost Record Status Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function displayOwnerRelatedCostList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="ownerrelatedcost_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	/*$sql = "select * from owner_related_cost_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' order by STATUS,NAME";*/
	$sql = "select * from owner_related_cost_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['OWNER_RCOSTID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['OWNER_RCOSTID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['OWNER_RCOSTID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateowner_related_cost.php?id='.$rows['OWNER_RCOSTID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertOwnerRelatedCostMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$status 				= addslashes(trim($_REQUEST['rdoStatus']));
	$ecg	 				= addslashes(trim($_REQUEST['txtECG']));
	$ec		 				= addslashes(trim($_REQUEST['txtEC']));
	$ate	 				= addslashes(trim($_REQUEST['txtATE']));
	$pte	 				= addslashes(trim($_REQUEST['txtPTE']));
	$ct		 				= addslashes(trim($_REQUEST['txtCT']));
	$pn		 				= addslashes(trim($_REQUEST['txtPN']));
	$ck		 				= addslashes(trim($_REQUEST['txtCK']));
	$tax_code 				= addslashes(trim($_REQUEST['txtTaxCode']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into owner_related_cost_master (NAME ,EXP_CLS_GROUP,EXP_CLS,ACC_TYP_EXP,POSTING_TYP_EXP,CONDITION_TYP,PARTNER_NUMBER,CURRENCY_KEY,TAX_CODE,RDO_STATUS,MODULEID,MCOMPANYID) values ('".$txtName."' ,'".$ecg."' ,'".$ec."' ,'".$ate."' ,'".$pte."' ,'".$ct."' ,'".$pn."' ,'".$ck."' ,'".$tax_code."','".$status."' ,'".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Owner Related Cost Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateOwnerRelatedCostMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$status 				= addslashes(trim($_REQUEST['rdoStatus']));
	$ecg	 				= addslashes(trim($_REQUEST['txtECG']));
	$ec		 				= addslashes(trim($_REQUEST['txtEC']));
	$ate	 				= addslashes(trim($_REQUEST['txtATE']));
	$pte	 				= addslashes(trim($_REQUEST['txtPTE']));
	$ct		 				= addslashes(trim($_REQUEST['txtCT']));
	$pn		 				= addslashes(trim($_REQUEST['txtPN']));
	$ck		 				= addslashes(trim($_REQUEST['txtCK']));
	$tax_code 				= addslashes(trim($_REQUEST['txtTaxCode']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update owner_related_cost_master set NAME='".$txtName."',RDO_STATUS='".$status."',EXP_CLS_GROUP='".$ecg."' ,EXP_CLS='".$ec."' ,ACC_TYP_EXP='".$ate."' ,POSTING_TYP_EXP='".$pte."' ,CONDITION_TYP='".$ct."' ,PARTNER_NUMBER='".$pn."' ,CURRENCY_KEY='".$ck."' ,TAX_CODE='".$tax_code."' where OWNER_RCOSTID='".$id."'"; /*and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";*/
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Owner Related Cost Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewOwnerRelatedCostRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM owner_related_cost_master where OWNER_RCOSTID='".$id."'"; 
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['EXP_CLS_GROUP'];
		$this->var_3 = $rows['EXP_CLS'];
		$this->var_4 = $rows['ACC_TYP_EXP'];
		$this->var_5 = $rows['POSTING_TYP_EXP'];
		$this->var_6 = $rows['CONDITION_TYP'];
		$this->var_7 = $rows['PARTNER_NUMBER'];
		$this->var_8 = $rows['CURRENCY_KEY'];
		$this->var_9 = $rows['TAX_CODE'];
		$this->var_10 = $rows['RDO_STATUS'];
	}
}




function changeCargoWorkStageMasterStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update cargo_work_stage_master set STATUS='".$tblstatus."' where  CARGOWORKSTAGEID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cargo Work Stage Record Status Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function displayCargoWorkStageList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="cargo_work_stage_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from cargo_work_stage_master  order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';

		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['CARGOWORKSTAGEID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['CARGOWORKSTAGEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['CARGOWORKSTAGEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatecargo_work_stage.php?id='.$rows['CARGOWORKSTAGEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function InsertCargoWorkStageMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into cargo_work_stage_master (NAME ,MODULEID,MCOMPANYID) values ('".$txtName."' ,'".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cargo Work Stage Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function updateCargoWorkStageMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update cargo_work_stage_master set NAME='".$txtName."' where CARGOWORKSTAGEID='".$id."' AND MODULEID = '".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Cargo Work Stage Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewCargoWorkStageRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM cargo_work_stage_master where CARGOWORKSTAGEID='".$id."' AND MODULEID = '".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
	}
}







function changeVendorMasterStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	$sql = "update vendor_master set STATUS='".$tblstatus."' where VENDORID='".$tblid."'  and MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Vendor Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayVendorMasterList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="vendor_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="10%"  >Vendor Type</th>';
	echo '<th align="left" valign="middle" width="10%"  >Vendor Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Short Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Code</th>';
	echo '<th align="center" valign="middle" width="5%" >Status</th>';
	echo '<th align="center" valign="top" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from vendor_master WHERE 1=1 and MCOMPANYID='".$_SESSION['company']."' order by VENDORID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['VENDORID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getVendorTypeNameBasedOnID($rows['VENDOR_TYPEID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SHORT_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CODE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['VENDORID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['VENDORID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatevendor.php?id='.$rows['VENDORID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function getVendorTypeNameBasedOnID($id)
{
	$connect = $this->funConnect();
	$sql = "select NAME from vendor_type_master where VENDOR_TYPEID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return addslashes($rows['NAME']);
}

function viewVendorMasterRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM vendor_master where VENDORID='".$id."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['VENDOR_TYPEID'];
		$this->var_2 = $rows['NAME'];
		$this->var_3 = $rows['SHORT_NAME'];
		$this->var_4 = $rows['CODE'];
		$this->var_5 = $rows['ADDRESS'];
		$this->var_6 = $rows['COUNTRY'];
		$this->var_7 = $rows['RECONCILIATION_AC'];
		$this->var_8 = $rows['BANKING_DETAILS'];
		$this->var_9 = $rows['COUNTRY_CODE'];
		$this->var_10 = $rows['BANKING_KEY'];
		$this->var_11 = $rows['STREET_1'];
		$this->var_12 = $rows['STREET_2'];
		$this->var_13 = $rows['STREET_3'];
		$this->var_14 = $rows['STREET_4'];
		$this->var_15 = $rows['STREET_5'];
		$this->var_16 = $rows['CITY'];
		$this->var_17 = $rows['CITY_CODE'];
		$this->var_18 = $rows['CITY_POSTAL_CODE'];
		$this->var_19 = $rows['PHONE'];
		$this->var_20 = $rows['FAX'];
		$this->var_21 = $rows['EMAILID'];
		$this->var_22 = $rows['VAT_NUMBER'];
		$this->var_23 = $rows['FOOTER_DETAILS'];
	}
}


function InsertVendorMasterRecords()
{
	$connect				= $this->funConnect();
 	$v_type 				= addslashes(trim($_REQUEST['selVType']));
	$name	 				= addslashes(trim($_REQUEST['txtVName']));	
	$query = mysql_query("select VENDOR_PREFIX from vendor_type_master where VENDOR_TYPEID='".$v_type."'");
	$rows = mysql_fetch_assoc($query);
	$v_code 				= strtoupper($rows['VENDOR_PREFIX']).$this->getMaxVendorCode($v_type);
	$short_name				= addslashes(trim($_REQUEST['txtVSName']));
	$txtBankingDetails		= addslashes(trim($_REQUEST['txtBankingDetails']));
	$txtAddress1			= addslashes(trim($_REQUEST['txtAddress1']));
	$txtAddress2			= addslashes(trim($_REQUEST['txtAddress2']));
	$txtCity	 			= addslashes(trim($_REQUEST['txtCity']));
	$txtCountry				= addslashes(trim($_REQUEST['txtCountry']));
	$txtPinCode     		= addslashes(trim($_REQUEST['txtPinCode']));
	$txtPhoneNo				= addslashes(trim($_REQUEST['txtPhoneNo']));
	$txtFax         		= addslashes(trim($_REQUEST['txtFax']));
	$txtEmail         		= addslashes(trim($_REQUEST['txtEmail']));
	$txtFooterDetails       = addslashes(trim($_REQUEST['txtFooterDetails']));
	
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into vendor_master (VENDOR_TYPEID, NAME, SHORT_NAME, CODE, MODULEID, MCOMPANYID, BANKING_DETAILS, VENDOR_AUTO_GENID, COUNTRY, STREET_1, STREET_2, CITY, CITY_POSTAL_CODE, PHONE, FAX, EMAILID, FOOTER_DETAILS) values ('".$v_type."' ,'".$name."' ,'".$short_name."' ,'".$v_code."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$txtBankingDetails."','".$this->getMaxVendorCode($v_type)."', '".$txtCountry."', '".$txtAddress1."' ,'".$txtAddress2."' ,'".$txtCity."', '".$txtPinCode."', '".$txtPhoneNo."', '".$txtFax."', '".$txtEmail."', '".$txtFooterDetails."')";
	
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Vendor Record Added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 		
	return $msg;
}

function getMaxVendorCode($v_type)
{
  $this->funConnect();
	
	$query = "SELECT MAX(VENDOR_AUTO_GENID) + 1 as VENDOR_AUTO_GENID FROM vendor_master where  VENDOR_TYPEID='".$v_type."' and MCOMPANYID='".$_SESSION['company']."' "; 
	$result = mysql_query($query);
	$rec=mysql_num_rows($result);
	
	while($rows = mysql_fetch_array($result))
	{
	$code = $rows['VENDOR_AUTO_GENID'];
	if($rows['VENDOR_AUTO_GENID'] != NULL)
		{
		if(strlen($code)<=4)
			{
				$x = 4- strlen($code);
				for($i = 1; $i<=$x;$i++)
					{
						$code = "0".$code;
					}
			}
		}
	else
		{
			$code='0001';
		}
	}
	
return $code;
}


function UpdateVendorMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
	
 	$v_type 				= addslashes(trim($_REQUEST['selVType']));
	$v_code 				= addslashes(trim($_REQUEST['txtVCode']));
	$name	 				= addslashes(trim($_REQUEST['txtVName']));
	$short_name				= addslashes(trim($_REQUEST['txtVSName']));
	$txtVatNumber			= addslashes(trim($_REQUEST['txtVatNumber']));
	$txtBankingDetails		= addslashes(trim($_REQUEST['txtBankingDetails']));
	
	$txtAddress1			= addslashes(trim($_REQUEST['txtAddress1']));
	$txtAddress2			= addslashes(trim($_REQUEST['txtAddress2']));
	$txtCity	 			= addslashes(trim($_REQUEST['txtCity']));
	$txtCountry				= addslashes(trim($_REQUEST['txtCountry']));
	$txtPinCode     		= addslashes(trim($_REQUEST['txtPinCode']));
	$txtPhoneNo				= addslashes(trim($_REQUEST['txtPhoneNo']));
	$txtFax         		= addslashes(trim($_REQUEST['txtFax']));
	$txtEmail         		= addslashes(trim($_REQUEST['txtEmail']));
	$txtFooterDetails       = addslashes(trim($_REQUEST['txtFooterDetails']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update vendor_master set NAME='".$name."',SHORT_NAME='".$short_name."',CODE='".$v_code."', BANKING_DETAILS='".$txtBankingDetails."', COUNTRY='".$txtCountry."', VAT_NUMBER='".$txtVatNumber."', STREET_1='".$txtAddress1."', STREET_2='".$txtAddress2."', CITY='".$txtCity."', CITY_POSTAL_CODE='".$txtPinCode."', PHONE='".$txtPhoneNo."', FAX='".$txtFax."', EMAILID='".$txtEmail."', FOOTER_DETAILS='".$txtFooterDetails."' where VENDORID='".$id."'";
	
	$sql1  = "delete from vendor_master_slave where VENDORID='".$id."'";
	$res1  = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	$maxid1    = $rows1['max'];
	
	$txtSubID = $_REQUEST['txtSubID'];
	for($i=1 ; $i<=$txtSubID ;$i++)
	{
		if($_REQUEST['txtName_'.$i] != "")
		{
		    if(!isset($_REQUEST['txtRandomID_'.$i]) || $_REQUEST['txtRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}else
			{
				$randomid = $_REQUEST['txtRandomID_'.$i];
			}
			$sql3 = "insert into vendor_master_slave (VENDORID, NAME, ADDRESS, ACCOUNTNO, IBAN_NO, IBAN_REMARKS, BANK_NAME, BANK_ADDRESS, SWIFT_CODE, US_CORRES_BANK, RANDOMID) values ('".$id."', '".addslashes(trim($_REQUEST['txtName_'.$i]))."', '".addslashes(trim($_REQUEST['txtAddress_'.$i]))."', '".addslashes(trim($_REQUEST['txtAccNo_'.$i]))."', '".addslashes(trim($_REQUEST['txtIBANNO_'.$i]))."', '".addslashes(trim($_REQUEST['txtIBANRemarks_'.$i]))."', '".addslashes(trim($_REQUEST['txtBankName_'.$i]))."', '".addslashes(trim($_REQUEST['txtBankAddress_'.$i]))."', '".addslashes(trim($_REQUEST['txtBankSwiftCode_'.$i]))."', '".addslashes(trim($_REQUEST['txtUSCorrBank_'.$i]))."', '".$randomid."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Vendor Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 		
	return $msg;
}


function changePortInformationStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update port_information_master set STATUS='".$tblstatus."' where PORT_INFORMATIONID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Information Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayPortInformationList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="port_information_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="35%"  >Port Name</th>';
	echo '<th align="left" valign="middle" width="35%" >Cargo Name</th>';
	echo '<th align="left" valign="middle" width="35%" >Terminal</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from port_information_master order by STATUS,PORT_INFORMATIONID DESC";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['PORT_INFORMATIONID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getPortNameBasedOnCode($rows['PORTID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getMaterialCodeDesBasedOnId($rows['CARGOID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getTerminalNameBasedOnID($rows['TERMINALID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['PORT_INFORMATIONID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['PORT_INFORMATIONID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateport_information.php?id='.$rows['PORT_INFORMATIONID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function getMaterialCodeDesBasedOnId($id)
{
	$this->funConnect();
	$sql = "select MATERIAL_CODE_DESC,MATERIAL_CODE from cargo_master where MATERIALID in (".$id.") ";
	$res = mysql_query($sql);
	$material = "";
	while($rows = mysql_fetch_assoc($res))
	{
		if($material_name!="")
		{
			$material_name = $material_name.", ";
		}
	$material_name = $material_name."".$rows['MATERIAL_CODE_DESC'];
	}
	return $material_name;
}

function getTerminalNameBasedOnID($id)
{
	$this->funConnect();
	$sql = "select NAME from terminal_master where TERMINALID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}

function InsertPortInformationRecords()
{
	$connect				= $this->funConnect();
	
 	$selCargo 				= addslashes(trim($_REQUEST['selCargo']));
	$portid 				= addslashes(trim($_REQUEST['selDPort']));
	$loaderid 				= addslashes(trim($_REQUEST['selLoader']));
	$l_method 				= addslashes(trim($_REQUEST['txtLMethod']));
	$remarks 				= addslashes(trim($_REQUEST['txtRemarks']));
	
	
	$max_draft 				= addslashes(trim($_REQUEST['txtMaxDraft']));
	$max_loa 				= addslashes(trim($_REQUEST['txtMaxLOA']));
	$max_beam 				= addslashes(trim($_REQUEST['txtMaxBeam']));
	$max_height				= addslashes(trim($_REQUEST['txtMaxHeight']));
	$lrate_day 				= addslashes(trim($_REQUEST['txtLRate_day']));
	$drate_day 				= addslashes(trim($_REQUEST['txtDRate_day']));
	$lrate_hr 				= addslashes(trim($_REQUEST['txtLRate_hr']));
	$drate_hr 				= addslashes(trim($_REQUEST['txtDRate_hr']));
	$dwt	 				= addslashes(trim($_REQUEST['txtDWT']));
	$dcts	 				= addslashes(trim($_REQUEST['txtDCTS']));
	
	$displacement			= addslashes(trim($_REQUEST['txtDisplacement']));
	$cor	 				= addslashes(trim($_REQUEST['txtCOR']));
	$hatch_di 				= addslashes(trim($_REQUEST['txtHDimension']));
	
	$terminalid 			= addslashes(trim($_REQUEST['selTerminal']));
	
	if($max_draft == ""){$max_draft1 = 0;}else{$max_draft1 = $max_draft;}
	if($max_loa == ""){$max_loa1 = 0;}else{$max_loa1 = $max_loa;}
	if($max_beam == ""){$max_beam1 = 0;}else{$max_beam1 = $max_beam;}
	if($max_height == ""){$max_height1 = 0;}else{$max_height1 = $max_height;}
	if($lrate_day == ""){$lrate_day1 = 0;}else{$lrate_day1 = $lrate_day;}
	if($drate_day == ""){$drate_day1 = 0;}else{$drate_day1 = $drate_day;}
	if($lrate_hr == ""){$lrate_hr1 = 0;}else{$lrate_hr1 = $lrate_hr;}
	if($drate_hr == ""){$drate_hr1 = 0;}else{$drate_hr1 = $drate_hr;}
	if($dwt == ""){$dwt1 = 0;}else{$dwt1 = $dwt;}
	if($dcts == ""){$dcts1 = 0;}else{$dcts1 = $dcts;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "select * from port_information_master where PORTID='".$portid."' and CARGOID='".$selCargo."' and TERMINALID='".$terminalid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		$query = "insert into port_information_master (PORTID,CARGOID,MAX_DRAFT,MAX_LOA,MAX_BEAM,MAX_HEIGHT,LOADING_METHOD,LOADING_RATE_DAY,DISCH_RATE_DAY,LOADING_RATE_HR,DISCH_RATE_HR,DWT,DCTS,LOADER,REMARKS,MODULEID,MCOMPANYID,DISPLACEMENT,CRANE_OUT_REACH,HATCH_DIMENSION,TERMINALID) values ('".$portid."','".$selCargo."','".$max_draft1."','".$max_loa1."','".$max_beam1."','".$max_height1."','".$l_method."','".$lrate_day1."','".$drate_day1."','".$lrate_hr1."','".$drate_hr1."','".$dwt1."','".$dcts1."','".$loaderid."','".$remarks."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$displacement."','".$cor."','".$hatch_di."','".$terminalid."')";
		mysql_query($query);
		$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Information Record added successfully.',NOW())";
	    mysql_query($sql3) or die(mysql_error());
		mysql_query("commit"); 
		return 0;
	}
	else
	{
		return 1;
	}
}

function getTerminalBasedOnPortWithJson()
{
	$connect = $this->funConnect();
	
	$query = mysql_query("select * from port_master where 1=1 ");
	while($row = mysql_fetch_assoc($query))
	{
	    $code = $row['PortCode'];
	    $sql = "select NAME, TERMINALID from terminal_master where MODULEID = '".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT_CODE='".$code."'";
		$result = mysql_query($sql);
		while($rows = mysql_fetch_assoc($result))
			{
			$a[$code][] = array('name' => $rows['NAME'] , 'id' => $rows['TERMINALID'] );
			}
	}
	echo json_encode($a);
}

function getCargoNameList()
{
	$this->funConnect();
	$query = mysql_query("select * from cargo_master where STATUS=1 AND MCOMPANYID='".$_SESSION['company']."' order by MATERIAL_CODE_DESC ");
	echo '<option value = "" >---Select from list---</option>';
	@$selCName = @$_REQUEST['selCName'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['MATERIALID'];
		 $value= $rows['MATERIAL_CODE_DESC']." (".$rows['MATERIAL_CODE'].")";
		 echo '<option value='.$key;
		 if($key == @$selCName){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}

function getLoader()
{
$state = array( 1 =>'Yes' , 2 =>'No');
$selLoader = @$_REQUEST['selLoader'];
echo "<option value = '' >---Select from list---</option>";
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selLoader){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function viewPortInformationRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM port_information_master where PORT_INFORMATIONID=".$id;
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['PORTID'];
		$this->var_2 = $rows['MAX_DRAFT'];
		$this->var_3 = $rows['MAX_LOA'];
		$this->var_4 = $rows['MAX_BEAM'];
		$this->var_5 = $rows['MAX_HEIGHT'];
		$this->var_6 = $rows['LOADING_METHOD'];
		$this->var_7 = $rows['LOADING_RATE_DAY'];
		$this->var_8 = $rows['DISCH_RATE_DAY'];
		$this->var_9 = $rows['LOADING_RATE_HR'];
		$this->var_10 = $rows['DISCH_RATE_HR'];
		$this->var_11 = $rows['DWT'];
		$this->var_12 = $rows['DCTS'];
		$this->var_13 = $rows['LOADER'];
		$this->var_14 = $rows['REMARKS'];
		$this->var_15 = $rows['CARGOID'];
		
		$this->var_16 = $rows['DISPLACEMENT'];
		$this->var_17 = $rows['CRANE_OUT_REACH'];
		$this->var_18 = $rows['HATCH_DIMENSION'];
		$this->var_19 = $rows['TERMINALID'];
	}
}

function updatePortInformationRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
	
	$loaderid 				= addslashes(trim($_REQUEST['selLoader']));
	$l_method 				= addslashes(trim($_REQUEST['txtLMethod']));
	$remarks 				= addslashes(trim($_REQUEST['txtRemarks']));
	
	
	$max_draft 				= addslashes(trim($_REQUEST['txtMaxDraft']));
	$max_loa 				= addslashes(trim($_REQUEST['txtMaxLOA']));
	$max_beam 				= addslashes(trim($_REQUEST['txtMaxBeam']));
	$max_height				= addslashes(trim($_REQUEST['txtMaxHeight']));
	$lrate_day 				= addslashes(trim($_REQUEST['txtLRate_day']));
	$drate_day 				= addslashes(trim($_REQUEST['txtDRate_day']));
	$lrate_hr 				= addslashes(trim($_REQUEST['txtLRate_hr']));
	$drate_hr 				= addslashes(trim($_REQUEST['txtDRate_hr']));
	$dwt	 				= addslashes(trim($_REQUEST['txtDWT']));
	$dcts	 				= addslashes(trim($_REQUEST['txtDCTS']));
	
	$displacement			= addslashes(trim($_REQUEST['txtDisplacement']));
	$cor	 				= addslashes(trim($_REQUEST['txtCOR']));
	$hatch_di 				= addslashes(trim($_REQUEST['txtHDimension']));
	
	if($max_draft == ""){$max_draft1 = 0;}else{$max_draft1 = $max_draft;}
	if($max_loa == ""){$max_loa1 = 0;}else{$max_loa1 = $max_loa;}
	if($max_beam == ""){$max_beam1 = 0;}else{$max_beam1 = $max_beam;}
	if($max_height == ""){$max_height1 = 0;}else{$max_height1 = $max_height;}
	if($lrate_day == ""){$lrate_day1 = 0;}else{$lrate_day1 = $lrate_day;}
	if($drate_day == ""){$drate_day1 = 0;}else{$drate_day1 = $drate_day;}
	if($lrate_hr == ""){$lrate_hr1 = 0;}else{$lrate_hr1 = $lrate_hr;}
	if($drate_hr == ""){$drate_hr1 = 0;}else{$drate_hr1 = $drate_hr;}
	if($dwt == ""){$dwt1 = 0;}else{$dwt1 = $dwt;}
	if($dcts == ""){$dcts1 = 0;}else{$dcts1 = $dcts;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
		$query = "update port_information_master set MAX_DRAFT='".$max_draft1."',MAX_LOA='".$max_loa1."',MAX_BEAM='".$max_beam1."',MAX_HEIGHT='".$max_height1."',LOADING_METHOD='".$l_method."',LOADING_RATE_DAY='".$lrate_day1."',DISCH_RATE_DAY='".$drate_day1."',LOADING_RATE_HR='".$lrate_hr1."',DISCH_RATE_HR='".$drate_hr1."',DWT='".$dwt1."',DCTS='".$dcts1."',LOADER='".$loaderid."',REMARKS='".$remarks."',DISPLACEMENT='".$displacement."',CRANE_OUT_REACH='".$cor."',HATCH_DIMENSION='".$hatch_di."'  where PORT_INFORMATIONID='".$id."'"; 
		
		mysql_query($query);
		$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Information Record updated successfully.',NOW())";
	    mysql_query($sql3) or die(mysql_error());
		mysql_query("commit"); 
		return $msg;
}


function changeTC_deductionsStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update tc_deduction_master set STATUS='".$tblstatus."' where TC_DEDUCTIONID='".$tblid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','TC Deduction Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function displayTC_deductionsList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="tc_deduction_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from tc_deduction_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['TC_DEDUCTIONID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['TC_DEDUCTIONID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['TC_DEDUCTIONID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatetc_deductions.php?id='.$rows['TC_DEDUCTIONID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';

}

function InsertTC_deductionsRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into tc_deduction_master (NAME ,MODULEID,MCOMPANYID) values ('".$txtName."' ,'".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','TC Deduction Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function updateTC_deductionsRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update tc_deduction_master set NAME='".$txtName."' where TC_DEDUCTIONID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','TC Deduction Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewTC_deductionsRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM tc_deduction_master where TC_DEDUCTIONID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
	}
}




function displayVC_deductionsList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="vc_deduction_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from vc_deduction_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['VC_DEDUCTIONID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['VC_DEDUCTIONID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['VC_DEDUCTIONID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatevc_deductions.php?id='.$rows['VC_DEDUCTIONID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';

}

function changeVC_deductionsStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update vc_deduction_master set STATUS='".$tblstatus."' where VC_DEDUCTIONID='".$tblid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','VC Deduction Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function InsertVC_deductionsRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into vc_deduction_master (NAME ,MODULEID,MCOMPANYID) values ('".$txtName."' ,'".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','VC Deduction Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewVC_deductionsRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM vc_deduction_master where VC_DEDUCTIONID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
	}
}

function updateVC_deductionsRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update vc_deduction_master set NAME='".$txtName."' where VC_DEDUCTIONID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','VC Deduction Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}



function changeBunkerGradeRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update bunker_grade_master set STATUS='".$tblstatus."' where BUNKERGRADEID='".$tblid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Bunker Grade Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayBunkerGradeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="bunker_grade" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from bunker_grade_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['BUNKERGRADEID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['BUNKERGRADEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['BUNKERGRADEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatebunker_grade.php?id='.$rows['BUNKERGRADEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertBunkerGradeRecords()
{
	$connect				= $this->funConnect();
 	$rdoBUNKERType 				= addslashes(trim($_REQUEST['rdoBUNKERType']));
	
	$txtName = trim(ereg_replace(' +','_',$_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into bunker_grade_master (NAME, BUNKERTYPE, MODULEID, MCOMPANYID) values ('".$txtName."', '".$rdoBUNKERType."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Bunker Grade Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewBunkerGradeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM bunker_grade_master where BUNKERGRADEID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['BUNKERTYPE'];
	}
}

function updateBunkerGradeRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$rdoBUNKERType 				= addslashes(trim($_REQUEST['rdoBUNKERType']));
	$txtName = trim(ereg_replace(' +','_',$_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update bunker_grade_master set NAME='".$txtName."', BUNKERTYPE='".$rdoBUNKERType."' where BUNKERGRADEID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Bunker Grade Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}



function deletePortDataRecords()
{
	$connect				= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['delId']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "select UPLOAD from port_data_master where PORTDATA_ID='".$id."'";
	$res1 = mysql_query($sql1) or die($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	$name = explode(",",$rows1['UPLOAD']);
	
	for($i=0;$i<sizeof($name);$i++)
	{
		unlink('../../attachment/'.$name[$i]);
	}
		
	$msg = 2;
	$sql = "delete from port_data_master where PORTDATA_ID='".$id."'";
	mysql_query($sql) or die($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Data Record Deleted successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayPortDataList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="port_data" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="10%"  >Port</th>';
	echo '<th align="left" valign="middle" width="10%"  >Terminal</th>';
	echo '<th align="left" valign="middle" width="25%"  >Cargo</th>';
	echo '<th align="left" valign="middle" width="5%"  >Upload</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from port_data_master WHERE 1=1";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody id="tbody">';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getPortNameBasedOnID($rows['PORT_ID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getTerminalNameBasedOnID($rows['TERMINALID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MATERIALCODE_DESC'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				$name = explode(",",$rows['UPLOAD']);
				for($j=0;$j<sizeof($name);$j++)
				{
				if(trim($name[$j]) != "")
				{
					echo '<a href="../../attachment/'.$name[$j].'" target="_blank" title="Upload" >Upload</a>&nbsp;';
				}
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateport_data.php?id='.$rows['PORTDATA_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a>&nbsp;|&nbsp;<a title="Delete Link" href="#'.$i.'" onclick="return getDelete('.$rows['PORTDATA_ID'].');" ><i class="fa fa-times" style="color:red;"></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertPortDataDetails()
{
	$connect = $this->funConnect();
	
	$selPName 			= addslashes(trim($_REQUEST['selPName']));
	$selTer	 			= addslashes(trim($_REQUEST['selTer']));
	$txtDesc	 		= addslashes(trim($_REQUEST['txtDesc']));
	$selCargo			= implode(",",$_REQUEST['selCargo']);
	
	for($i=0;$i<sizeof($_REQUEST['selCargo']);$i++)
	{
		$sql = "select MATERIAL_CODE_DESC from cargo_master where MATERIALID=".$_REQUEST['selCargo'][$i];
		$res = mysql_query($sql) or die($sql);
		$rows = mysql_fetch_assoc($res);
		$desc[$i] = $rows['MATERIAL_CODE_DESC'];
	}
	
	$code_desc = implode(",",$desc);
	
	
	$upload2 = $this->getUpload($_FILES['mul_file']);
	$name2 = $this->getUploadName($_FILES['mul_file']);
	$upload1 = implode(',',$upload2);
	$name1 = implode(',',$name2);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into port_data_master (PORT_ID, TERMINALID, MATERIALID, MATERIALCODE_DESC, REMARKS, UPLOAD, MODULEID, MCOMPANYID, STATUS, UPLOAD_NAME) values ('".$selPName."', '".$selTer."', '".$selCargo."', '".$code_desc."', '".$txtDesc."', '".$upload1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '1','".$name1."')";
	mysql_query($sql) or die($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Data Record Added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}

function getCargoListMultiple()
{
	$this->funConnect();
	$query = mysql_query("select * from cargo_master where STATUS=1 order by MATERIAL_CODE_DESC ");
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['MATERIALID'];
		 $value= $rows['MATERIAL_CODE_DESC'];
		 echo "<option value=$key";
		 echo ">".$value."</option>";
		}
}

function getTerminalList()
{
	$this->funConnect();
	$query = mysql_query("select * from terminal_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selTerminal = @$_REQUEST['selTerminal'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['TERMINALID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selTerminal){ echo " selected";}
		 echo ">".$value."</option>";
		}
}



function getUpload($upload)
{
	if(gettype($upload['name']) == 'array')
	{
		foreach($upload['name'] as $key=>$value)
		{
			if(trim($upload['name'][$key]) != '')
			{
				$ext_arr = explode(".", $upload['name'][$key]);
				list($txt, $ext) = explode(".", $upload['name'][$key]);
				$filename = substr(number_format(time() * rand(),0,'',''),0,10).'.'.$ext_arr[count($ext_arr) - 1];
				$name[$key] = $filename;
				move_uploaded_file($upload['tmp_name'][$key], '../../attachment/'.$filename);
			}
		}
	}
	else
	{
		if(trim($upload['name'] ) != '')
		{
			$ext_arr = explode(".", $upload['name']);
			list($txt, $ext) = explode(".", $upload['name']);
			$filename = substr(number_format(time() * rand(),0,'',''),0,10).'.'.$ext_arr[count($ext_arr) - 1];
			$name = $filename;
			move_uploaded_file($upload['tmp_name'], '../../attachment/'.$filename);
		}
	}
	
	return $name;
}



function getUpload3($upload)
{
	if(gettype($upload['name']) == 'array')
	{
		foreach($upload['name'] as $key=>$value)
		{
			if(trim($upload['name'][$key]) != '')
			{
				$ext_arr = explode(".", $upload['name'][$key]);
				list($txt, $ext) = explode(".", $upload['name'][$key]);
				$filename = substr(number_format(time() * rand(),0,'',''),0,10).'.'.$ext_arr[count($ext_arr) - 1];
				$name[$key] = $filename;
				move_uploaded_file($upload['tmp_name'][$key], '../../attachment/'.$filename);
			}
		}
	}
	else
	{ 
		if(trim($upload['name'] ) != '')
		{
			$ext_arr = explode(".", $upload['name']); 
			list($txt, $ext) = explode(".", $upload['name']);
			$filename = substr(number_format(time() * rand(),0,'',''),0,10).'.'.$ext_arr[count($ext_arr) - 1];
			$name = $filename;
			move_uploaded_file($upload['tmp_name'], '../../attachment/'.$filename);
		}
	}
	
	return $name;
}


function getUploadName($upload)
{
	if(gettype($upload['name']) == 'array')
	{
		foreach($upload['name'] as $key=>$value)
		{
			if(trim($upload['name'][$key]) != '')
			{
				$ext_arr = explode(".", $upload['name'][$key]);
				list($txt, $ext) = explode(".", $upload['name'][$key]);
				$filename = $upload['name'][$key];
				$name[$key] = $filename;
			}
		}
	}
	else
	{
		if(trim($upload['name'] ) != '')
		{
			$ext_arr = explode(".", $upload['name']);
			list($txt, $ext) = explode(".", $upload['name']);
			$filename = $upload['name'];
			$name = $filename;
		}
	}
	
	return $name;
}


function updatePortDataRecords()
{
	$connect			= $this->funConnect();
	
	$id 				= $_REQUEST['id'];
	$txtDesc	 		= addslashes(trim($_REQUEST['txtDesc']));
	
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	$txtCRM1				= addslashes(trim($_REQUEST['txtCRM1']));
	$txtCRM2				= addslashes(trim($_REQUEST['txtCRM2']));

	
	if($txtCRM1 != '' && $upload != ''){ $upload1 = $txtCRM1.','.$upload; $name1 = $txtCRM2.','.$name;}
	else if($txtCRM1 == '' && $upload != ''){ $upload1 = $upload; $name1 = $name;}
	else if($txtCRM1 != '' && $upload == ''){ $upload1 = $txtCRM1; $name1 = $txtCRM2;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	
		$sql = "update port_data_master set REMARKS='".$txtDesc."',UPLOAD='".$upload1."',UPLOAD_NAME='".$name1."'  where PORTDATA_ID='".$id."' ";
		mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Port Data Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewPortDataRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM port_data_master where PORTDATA_ID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['PORT_ID'];
		$this->var_2 = $rows['TERMINALID'];
		$this->var_3 = $rows['MATERIALID'];
		$this->var_4 = $rows['REMARKS'];
		$this->var_5 = $rows['UPLOAD'];
		$this->var_6 = $rows['MATERIALCODE_DESC'];
		$this->var_7 = $rows['UPLOAD_NAME'];
	}
}





function displayBilticRouteList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="biltic_route_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle">#</th>';
	echo '<th align="left" valign="middle">Baltic Route Code</th>';
	echo '<th align="left" valign="middle">Baltic Route Description</th>';
	echo '<th align="left" valign="middle">Status</th>';
	echo '<th align="center" valign="middle">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "SELECT * FROM baltic_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CODE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['BALTICID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['BALTICID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="update_baltic_route.php?id='.$rows['BALTICID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function changeBalticMasterRouteStatusRecords()
{
	$connect			= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	$sql = "UPDATE baltic_master SET STATUS='".$tblstatus."' WHERE BALTICID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'"; 
	mysql_query($sql);
	mysql_query("commit");
	return $msg;
}

function insertBalticRouteDetails()
{
	$connect = $this->funConnect();
	$txtBalticCode 		= addslashes(trim($_REQUEST['txtBalticCode']));
	$txtBalticIndex 	= addslashes(trim($_REQUEST['txtBalticIndex']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "INSERT INTO baltic_master (CODE,NAME,MODULEID,MCOMPANYID) VALUES ('".$txtBalticCode."','".$txtBalticIndex."','".$_SESSION['moduleid']."','".$_SESSION['company']."')"; 
	mysql_query($sql);
	mysql_query("commit");
	
	return $msg; 
}

function viewBalticRouteRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM baltic_master WHERE BALTICID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['CODE'];
	}
}

function updateBalticRouteMasterRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
	$txtBalticCode 			= addslashes(trim($_REQUEST['txtBalticCode']));
 	$txtBalticIndex 		= addslashes(trim($_REQUEST['txtBalticIndex']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "UPDATE baltic_master SET CODE='".$txtBalticCode."', NAME='".$txtBalticIndex."' WHERE BALTICID='".$id."' and  MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
	
}

/*********************************************/

function displayReferenceTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="reference_type_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="10%" >#</th>';
	echo '<th align="left" valign="middle" width="60%">Name</th>';
	echo '<th align="left" valign="middle" width="20%">Status</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "SELECT * FROM elibrary_refrences order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['REF_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['REF_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="update_reference_type.php?id='.$rows['REF_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function changeRefTypeMasterStatusRecords()
{
	$connect			= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "UPDATE elibrary_refrences SET STATUS='".$tblstatus."' WHERE  REF_ID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}

function insertReferenceTypeMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into elibrary_refrences (NAME ,MODULEID,MCOMPANYID) values ('".$txtName."' ,'".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
}

function viewReferencesRecords($id)
{

	$connect = $this->funConnect();
	$query = "SELECT * FROM elibrary_refrences where REF_ID='".$id."' AND MODULEID = '".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
	}
}

function updateReferenceTypeMasterRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "UPDATE elibrary_refrences SET NAME='".$txtName."' WHERE REF_ID='".$id."' AND MODULEID = '".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
}

/*****************************************/

function displayRefCategoryList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="reference_category_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="10%" >#</th>';
	echo '<th align="left" valign="middle" width="60%">Name</th>';
	echo '<th align="left" valign="middle" width="20%">Status</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "SELECT * FROM elibrary_categories order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['CATEGORY_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['CATEGORY_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="update_reference_category_type.php?id='.$rows['CATEGORY_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function changeRefCategoryMasterStatusRecords()
{
	$connect			= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "UPDATE elibrary_categories SET STATUS='".$tblstatus."' where  CATEGORY_ID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}

function insertReferenceCategoryMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into elibrary_categories (NAME ,MODULEID,MCOMPANYID) values ('".$txtName."' ,'".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
}

function viewRefCategoryRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM elibrary_categories where CATEGORY_ID='".$id."' AND MODULEID = '".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
	}
}

function updateReferenceCategoryMasterRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "UPDATE elibrary_categories SET NAME='".$txtName."' WHERE CATEGORY_ID='".$id."' AND MODULEID = '".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
}

/*******************************************/

function displayVesselCategoryList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="vessel_category_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="10%" >#</th>';
	echo '<th align="left" valign="middle" width="60%">Name</th>';
	echo '<th align="left" valign="middle" width="10%">Size</th>';
	echo '<th align="left" valign="middle" width="20%">Status</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "SELECT * FROM vessel_category_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SIZE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['VESSEL_CATEGORY_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['VESSEL_CATEGORY_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="update_vessel_cat_master.php?id='.$rows['VESSEL_CATEGORY_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function changeVesselCategoryStatusRecords()
{
	$connect			= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "UPDATE vessel_category_master SET STATUS='".$tblstatus."' WHERE VESSEL_CATEGORY_ID='".$tblid."' ";
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}

function InsertVesselCategoryMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$txtDesc 				= addslashes(trim($_REQUEST['txtDesc']));
	$txtSize 				= addslashes(trim($_REQUEST['txtSize']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "INSERT INTO vessel_category_master (NAME ,DESCRIPTION,SIZE) VALUES ('".$txtName."' ,'".$txtDesc."','".$txtSize."')";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
}

function viewVesselCategoryRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM vessel_category_master where VESSEL_CATEGORY_ID='".$id."' ";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['DESCRIPTION'];
		$this->var_3 = $rows['SIZE'];
	}
}

function updateVesselCategoryMasterRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$txtDesc 				= addslashes(trim($_REQUEST['txtDesc']));
	$txtSize 				= addslashes(trim($_REQUEST['txtSize']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "UPDATE vessel_category_master SET NAME='".$txtName."',DESCRIPTION='".$txtDesc."',SIZE='".$txtSize."' WHERE VESSEL_CATEGORY_ID='".$id."' ";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
}

/****************************************/


function getCargoListForMSDS()
{
	$this->funConnect();
	$query = mysql_query("SELECT * FROM cargo_master WHERE STATUS=1 order by MATERIAL_CODE_DESC ");
	echo "<option value=''>---select from list---</option>";
	@$selCName = @$_REQUEST['selCName'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['MATERIALID'];
		 $value= $rows['MATERIAL_CODE_DESC'];
		 echo "<option value=$key";
		 if($key == @$selCName){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getVendorList($type='')
{
	$this->funConnect();
	if($type=='')
	{
	$query = mysql_query("SELECT * FROM vendor_master WHERE STATUS=1 and MCOMPANYID='".$_SESSION['company']."' order by VENDOR_TYPEID,NAME ");
	}
	else
	{
	$query = mysql_query("SELECT * FROM vendor_master WHERE STATUS=1 and VENDOR_TYPEID='".$type."' and MCOMPANYID='".$_SESSION['company']."' order by VENDOR_TYPEID,NAME ");
	}
	echo "<option value = '' >---select from list---</option>";
	@$selShipper = @$_REQUEST['selShipper'];
	while($rows = mysql_fetch_assoc($query))
		{
			 $key= $rows['VENDORID'];
			 $value= addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
			 echo '<option value="'.$key.'"';
			 if($key == @$selShipper){ echo " selected";}
			 echo ">".$value."</option>";
		}
}


function getVendorNameBasedOnID($id)
{
	$connect = $this->funConnect();
	$sql  = "select * from vendor_master where VENDORID='".$id."' and MCOMPANYID='".$_SESSION['company']."'";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
}




function displayMSDSList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="material_safety_data_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="10%">#</th>';
	echo '<th align="left" valign="middle" width="15%">Cargo</th>';
	echo '<th align="left" valign="middle" width="15%">Port</th>';
	echo '<th align="left" valign="middle" width="40%">Shipper</th>';
	echo '<th align="left" valign="middle" width="10%">Upload</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from msds_master where 1=1";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';				
				echo '<td align="left" valign="middle" class="input-text">'.$this->getMaterialCodeDesBasedOnId($rows['MATERIALID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getPortNameBasedOnID($rows['PORT_ID']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getVendorNameBasedOnID($rows['VENDORID']).'</td>';				
				
				echo '<td align="left" valign="middle" class="input-text">';
				$name = explode(",",$rows['UPLOAD']);
				for($j=0;$j<sizeof($name);$j++)
				{
					if(trim($name[$j]) != "")
					{
						echo '<a href="../../attachment/'.$name[$j].'" target="_blank" title="Upload" style="text-decoration:underline;" >Upload</a>&nbsp;';
					}
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="update_material_safety_data.php?id='.$rows['MSDS_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a href="javascript:void(0);" title="Delete Details" onclick="return getDelete('.$rows['MSDS_ID'].');" ><i class="fa fa-times"></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertMSDSDetails()
{
	$connect = $this->funConnect();
	
	$selCName 			= addslashes(trim($_REQUEST['selCName']));
	$selPort	 		= addslashes(trim($_REQUEST['selPort']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtDesc	 		= addslashes(trim($_REQUEST['txtDesc']));
	
	foreach($_FILES["mul_file"]['name'] as $key=>$value)
	{
		$filename =$_FILES['mul_file']['name'][$key];
		$tmpFile = $_FILES["mul_file"]["tmp_name"];
		$name[$key] = $filename;
		move_uploaded_file($_FILES['mul_file']['tmp_name'][$key], '../../attachment/'.$filename);
	} 
	
	$filename = implode(",",$name);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "INSERT INTO msds_master (MATERIALID, PORT_ID, VENDORID, REMARKS, UPLOAD, MODULEID, MCOMPANYID, STATUS) VALUES ('".$selCName."', '".$selPort."', '".$selShipper."', '".$txtDesc."', '".$filename."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '1')";

	mysql_query($sql);
	mysql_query("commit");
	return $msg;
}

function viewMSDSRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM msds_master where MSDS_ID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['MATERIALID'];
		$this->var_2 = $rows['PORT_ID'];
		$this->var_3 = $rows['VENDORID'];
		$this->var_4 = $rows['REMARKS'];
		$this->var_5 = $rows['UPLOAD'];
	}
}

function updateMSDSRecords()
{
	$connect			= $this->funConnect();
	
	$id 				= $_REQUEST['id'];
	$txtDesc	 		= addslashes(trim($_REQUEST['txtDesc']));
	$txtCRM	 			= explode(",",$_REQUEST['txtCRM']);
	
	foreach($_FILES["mul_file"]['name'] as $key=>$value)
	{
		$filename =$_FILES['mul_file']['name'][$key];
		$tmpFile = $_FILES["mul_file"]["tmp_name"];
		$name[$key] = $filename;
		move_uploaded_file($_FILES['mul_file']['tmp_name'][$key], '../../attachment/'.$filename);
	} 
	
	$filename = implode(",",$name);
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	if(empty($filename))
	{
		$sql = "update msds_master set REMARKS='".$txtDesc."'  where MSDS_ID='".$id."' ";
		mysql_query($sql);
	}
	else
	{
		for($i=0;$i<sizeof($txtCRM);$i++)
		{
			unlink('../../attachment/'.$txtCRM[$i]);
		}
		
		$sql = "update msds_master set REMARKS='".$txtDesc."',UPLOAD='".$filename."'  where MSDS_ID='".$id."' ";
		mysql_query($sql);
	}
	
	mysql_query("commit"); 
	return $msg;
}

function deleteMSDSRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['delId']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1  = "select UPLOAD from msds_master where MSDS_ID='".$id."'";
	$res1  = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	$name  = explode(",",$rows1['UPLOAD']);
	
	for($i=0;$i<sizeof($name);$i++)
	{
		unlink('../../attachment/'.$name[$i]);
	}
		
	$msg = 2;
	$sql = "DELETE FROM msds_master WHERE MSDS_ID='".$id."'";
	
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}





function displayCOAList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="coa_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="middle" width="8%">COA Route</th>';
	echo '<th align="left" valign="middle" width="8%">COA ID</th>';
	echo '<th align="left" valign="middle" width="8%">COA No.</th>';
	echo '<th align="left" valign="middle" width="8%">COA Date</th>';
	echo '<th align="left" valign="middle" width="8%">Vessel Type</th>';
	echo '<th align="center" valign="middle" width="8%">Charterer</th>';
	echo '<th align="center" valign="middle" width="8%">Cargo</th>';
	echo '<th align="center" valign="middle" width="8%">Min Qty(MT)</th>';
	echo '<th align="center" valign="middle" width="8%">Total Shipments</th>';
	echo '<th align="center" valign="middle" width="8%">Shipments Performed</th>';
	echo '<th align="left" valign="middle" width="8%">Balance Cargo(MT)</th>';
	echo '<th align="left" valign="middle" width="8%">Nominate Vessel</th>';
	
	echo '<th align="center" valign="middle" width="7%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from coa_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS=1 order by COA_DATE desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody id="tbody">';
		
		echo '</tbody>';
	}
	else
	{
		echo '<tbody id="tbody">';
		while($rows = mysql_fetch_assoc($res))
		{
					echo '<tr>';
					echo '<td align="left" valign="middle" class="input-text">'.$this->getCOARouteNameBasedOnId($rows['COA_ROUTE']).'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$rows['COA_ID'].'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$rows['COA_NO'].'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.date("d-M-Y",strtotime($rows['COA_DATE'])).'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$this->getVesselTypeBasedOnID($rows['VESSEL_TYPE']).'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$this->getVendorListNewBasedOnID($rows['CHARTERER']).'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$this->getCargoNameListForMultipleName($rows['CARGO']).'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$rows['MIN_GUARANTEED_QTY'].'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_SHIPMENTS'].'</td>';
					echo '<td align="center" valign="middle" class="input-text"></td>';
					echo '<td align="center" valign="middle" class="input-text"></td>';
					echo '<td align="left" valign="middle" class="input-text" ><strong><a href="#" title="View Details" data-toggle="modal" data-target="#compose-modal" onclick="getListOFEstimate('.$rows['COAID'].');" style="font-size:14px;color:red;">Nominate</a></strong></td>';
					echo '<td align="center" valign="middle" class="input-text">';
					if($this->getPerformedVesselRec($rows['COAID']) == 0)
					{
						echo '<a href="cancel_coa.php?id='.$rows['COAID'].'" title="Cancel COA" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;|&nbsp;';
					}
					echo '&nbsp;<a href="updatecoa.php?id='.$rows['COAID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
					echo '</tr>';
					$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function getActiveOrCancelled()
{
$state = array( 1 =>'Active' , 3 =>'Completed', 2 =>'Cancelled' );
$selActive = @$_REQUEST['selActive'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selActive){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}



function getNomNameBasedOnOpenVesselID($open_vessel_id)
{
	$this->funConnect();
	$sql = "select * from mapping_master where OPEN_VESSEL_ID='".$open_vessel_id."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec > 0)
	{
		while($rows = mysql_fetch_assoc($res))
		{
			if($rows['STATUS'] == 2)
			{
				if(in_array("5",$this->getUserAuthenticationModuleWiseForMainMenu(5)))
				{
					$arr[] =  '<a href="in_ops_at_glance.php?vesselid='.$this->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],"VESSEL_IMO_ID").'" >'.$rows['NOM_NAME'].'</a>';
				}
				else
				{
					$arr[] =  '<a href="#msg" onclick="getMsg();" >'.$rows['NOM_NAME'].'</a>';
				}
			}
			if($rows['STATUS'] == 3 || $rows['STATUS'] == 4)
			{
				if(in_array("7",$this->getUserAuthenticationModuleWiseForMainMenu(5)))
				{
					$arr[] =  '<a href="vessel_in_history.php?vesselid='.$this->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],"VESSEL_IMO_ID").'" >'.$rows['NOM_NAME'].'</a>';
				}
				else
				{
					$arr[] =  '<a href="#msg" onclick="getMsg();" >'.$rows['NOM_NAME'].'</a>';
				}			
			}
			if($rows['STATUS'] == 5)
			{
				if(in_array("6",$this->getUserAuthenticationModuleWiseForMainMenu(5)))
				{
					$arr[] =  '<a href="vessel_in_post_ops.php?vesselid='.$this->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],"VESSEL_IMO_ID").'" >'.$rows['NOM_NAME'].'</a>';
				}
				else
				{
					$arr[] =  '<a href="#msg" onclick="getMsg();" >'.$rows['NOM_NAME'].'</a>';
				}
			}
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function addMonthlyCOADetails()
{
	$connect = $this->funConnect();
	$rec	     			= addslashes(trim($_REQUEST['txtMCOAID']));
	$id						= $_REQUEST['id'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$delQuery = "delete from coa_monthly_remark where COAID='".$id."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($delQuery);
	mysql_query("commit");
	//insert query here.............
	for($i=1;$i<=$rec;$i++)
	{
		if($_REQUEST['txtDate_'.$i] != "" && $_REQUEST['txtRemark_'.$i] != "")
		{
			$sql = "insert into coa_monthly_remark (COAID, MODULEID, MCOMPANYID, DATE, REMARK) values ('".$id."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".date("Y-m-d",strtotime($_REQUEST['txtDate_'.$i]))."', '".$_REQUEST['txtRemark_'.$i]."')";
			mysql_query($sql);
			mysql_query("commit");
		}
	}
	return $msg; 
}



function updateCOADetails($id)
{
	$connect = $this->funConnect();
	
	$txtCOAid 			= addslashes(trim($_REQUEST['txtCOAid']));
	$selCharterer 		= addslashes(trim($_REQUEST['selCharterer']));
	$selOwner 			= addslashes(trim($_REQUEST['selOwner']));
	$txtCOANo 			= addslashes(trim($_REQUEST['txtCOANo']));
	$selCOAroute		= addslashes(trim($_REQUEST['selCOAroute']));
	$txtNoofShipment 	= addslashes(trim($_REQUEST['txtNoofShipment']));
	$selBroker 			= addslashes(trim($_REQUEST['selBroker']));
	$selVesselType 		= addslashes(trim($_REQUEST['selVesselType']));
	$selLoadOpt 		= addslashes(trim($_REQUEST['selLoadOpt']));
	$selCargo 			= addslashes(trim($_REQUEST['selCargo']));
	$txtTolerance 		= addslashes(trim($_REQUEST['txtTolerance']));
	$txtCOAnoticeDays 	= addslashes(trim($_REQUEST['txtCOAnoticeDays']));
	$txtMinGuarQty 		= addslashes(trim($_REQUEST['txtMinGuarQty']));
	$txtLdPrtETAnot 	= addslashes(trim($_REQUEST['txtLdPrtETAnot']));
	$selVslSubs 		= addslashes(trim($_REQUEST['selVslSubs']));
	$txtCOAduration 	= addslashes(trim($_REQUEST['txtCOAduration']));
	$txtFreightDetails 	= addslashes(trim($_REQUEST['txtFreightDetails']));
	$txtLPDetails 		= addslashes(trim($_REQUEST['txtLPDetails']));
	$txtDPDetails 		= addslashes(trim($_REQUEST['txtDPDetails']));
	$txtDemLaytime 		= addslashes(trim($_REQUEST['txtDemLaytime']));
	$txtRemarks 		= addslashes(trim($_REQUEST['txtRemarks']));
	$selCurrency        = addslashes(trim($_REQUEST['selCurrency']));
	$selBType           = addslashes(trim($_REQUEST['selBType']));
	$upstatus           = addslashes(trim($_REQUEST['upstatus']));
	$txtFOPrice         = addslashes(trim($_REQUEST['txtFOPrice']));
	$txtBAF             = addslashes(trim($_REQUEST['txtBAF']));
	
	if($_REQUEST['txtCOADate']!="")
	{$txtCOADate     	= date("Y-m-d",strtotime($_REQUEST['txtCOADate']));}
    else{$txtCOADate  = "1970-01-01";}
	
	if($_REQUEST['txtStartDate']!="")
	{$txtStartDate     	= date("Y-m-d",strtotime($_REQUEST['txtStartDate']));}
    else{$txtStartDate  = "1970-01-01";}
	
	if($_REQUEST['txtEndDate']!="")
	{$txtEndDate     	= date("Y-m-d",strtotime($_REQUEST['txtEndDate']));}
    else{$txtEndDate  	= "1970-01-01";}	
	
	$txtCRMFILE1		= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1		= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update coa_master set COA_ID='".$txtCOAid."', COA_DATE='".$txtCOADate."', CHARTERER='".$this->getCheckNullVal($selCharterer)."', OWNER='".$this->getCheckNullVal($selOwner)."', COA_NO='".$this->getCheckNullVal($txtCOANo)."', COA_ROUTE='".$this->getCheckNullVal($selCOAroute)."', TOTAL_SHIPMENTS='".$this->getCheckNullVal($txtNoofShipment)."', BROKER='".$this->getCheckNullVal($selBroker)."', VESSEL_TYPE='".$this->getCheckNullVal($selVesselType)."', LOAD_OPTIONS='".$this->getCheckNullVal($selLoadOpt)."', CARGO='".$this->getCheckNullVal($selCargo)."', TOLERANCE='".$txtTolerance."', COA_NOTICE='".$this->getCheckNullVal($txtCOAnoticeDays)."', MIN_GUARANTEED_QTY='".$this->getCheckNullVal($txtMinGuarQty)."', LP_ETA_NOTICES='".$txtLdPrtETAnot."', VESSEL_SUBSTITUTE='".$this->getCheckNullVal($selVslSubs)."', COA_DURATION='".$this->getCheckNullVal($txtCOAduration)."', START_DATE='".$txtStartDate."', END_DATE='".$txtEndDate."', FREIGHT_DETAILS='".$this->getCheckNullVal($txtFreightDetails)."', LP_DETAILS= '".$txtLPDetails."', DP_DETAILS='".$txtDPDetails."', DEMM_LAYTIME='".$txtDemLaytime."', REMARKS='".$txtRemarks."', ATTACHMENT='".$upload1."', ATTACHMENT_NAME='".$name1."', CURRENCY='".$selCurrency."', BUSINESSTYPEID='".$selBType."', UPDATE_STATUS='".$upstatus."', FO_PRICE='".$txtFOPrice."', BAF_AMT='".$txtBAF."', UPDATE_ON_DATE=NOW() where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and COAID='".$id."' ";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql1  = "select max(COAID) as max from coa_master";
	$res1  = mysql_query($sql1,$connect);
	$rows1 = mysql_fetch_assoc($res1);
	$maxid1    = $rows1['max'];
	
	$sql2 = "delete from coa_master_s1 where COAID='".$maxid1."'";
	mysql_query($sql2) or die($sql2);
	mysql_query("commit");
	
	$hddnOtherID = $_REQUEST['hddnOtherID'];
	for($i=1 ; $i<=$hddnOtherID ;$i++)
	{
		if($_REQUEST['txtminGuarenteed_'.$i] != "" && $_REQUEST['selExPort_'.$i] != "")
		{
			$sql3 = "insert into coa_master_s1 (COAID, MIN_GUARANTEED, EX_PORT, STATUS, ADD_ON_DATE) values ('".$maxid1."', '".$_REQUEST['txtminGuarenteed_'.$i]."', '".$_REQUEST['selExPort_'.$i]."', 1, NOW())";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	mysql_query("commit");
	return $msg; 
}



function getEstimateData($id,$field)
{
	$connect = $this->funConnect();
	$sql     = "select ".$field." from freight_cost_estimete_master where MODULEID='".$_SESSION['moduleid']."' and FCAID='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getUserAuthenticationModuleWiseForMainMenu($moduleid)
{
	$this->funConnect();
	$sql 	= "select LINKID from user_rights where MODULEID='".$moduleid."' and LOGINID='".$_SESSION['uid']."'";
	$res 	= mysql_query($sql);
	while($rows = mysql_fetch_assoc($res))
	{
		$arr[] = $rows['LINKID'];
	}
	return $arr;
}


function getVesselCategoryTypeBasedOnId($id)
{
	$this->funConnect();
	$sql 	= "select NAME from vessel_category_master where VESSEL_CATEGORY_ID='".$id."'";
	$res 	= mysql_query($sql);
	$rows 	= mysql_fetch_assoc($res);
	return $rows['NAME'];
}


function getPerformedVesselRec($coaid)
{
	$this->funConnect();
	$sql 	= "select COA_NO from open_vessel_entry_master where COA_NO='".$coaid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS=1";
	$res 	= mysql_query($sql);
	$rec 	= mysql_num_rows($res);
	return $rec;
}


function getCargoNameBasedOnId($id)
{
	$this->funConnect();
	$sql 	= "select NAME from cargotype_master where CARGOTYPEID='".$id."'";
	$res 	= mysql_query($sql);
	$rows 	= mysql_fetch_assoc($res);
	return $rows['NAME'];
}


function insertCOADetails()
{
	$connect = $this->funConnect();
	
	$txtCOAid 			= addslashes(trim($_REQUEST['txtCOAid']));
	$messageno 			= explode('-',$_REQUEST['txtCOAid'])[1];
	$selCharterer 		= addslashes(trim($_REQUEST['selCharterer']));
	$selOwner 			= addslashes(trim($_REQUEST['selOwner']));
	$txtCOANo 			= addslashes(trim($_REQUEST['txtCOANo']));
	$selCOAroute		= addslashes(trim($_REQUEST['selCOAroute']));
	$txtNoofShipment 	= addslashes(trim($_REQUEST['txtNoofShipment']));
	$selBroker 			= addslashes(trim($_REQUEST['selBroker']));
	$selVesselType 		= addslashes(trim($_REQUEST['selVesselType']));
	$selLoadOpt 		= addslashes(trim($_REQUEST['selLoadOpt']));
	$selCargo 			= addslashes(trim($_REQUEST['selCargo']));
	$txtTolerance 		= addslashes(trim($_REQUEST['txtTolerance']));
	$txtCOAnoticeDays 	= addslashes(trim($_REQUEST['txtCOAnoticeDays']));
	$txtMinGuarQty 		= addslashes(trim($_REQUEST['txtMinGuarQty']));
	$txtLdPrtETAnot 	= addslashes(trim($_REQUEST['txtLdPrtETAnot']));
	$selVslSubs 		= addslashes(trim($_REQUEST['selVslSubs']));
	$txtCOAduration 	= addslashes(trim($_REQUEST['txtCOAduration']));
	$txtFreightDetails 	= addslashes(trim($_REQUEST['txtFreightDetails']));
	$txtLPDetails 		= addslashes(trim($_REQUEST['txtLPDetails']));
	$txtDPDetails 		= addslashes(trim($_REQUEST['txtDPDetails']));
	$txtDemLaytime 		= addslashes(trim($_REQUEST['txtDemLaytime']));
	$txtRemarks 		= addslashes(trim($_REQUEST['txtRemarks']));	
	$selCurrency        = addslashes(trim($_REQUEST['selCurrency']));
	$selBType           = addslashes(trim($_REQUEST['selBType']));
	$upstatus           = addslashes(trim($_REQUEST['upstatus']));
	$txtFOPrice         = addslashes(trim($_REQUEST['txtFOPrice']));
	$txtBAF             = addslashes(trim($_REQUEST['txtBAF']));
	
	if($_REQUEST['txtCOADate']!="")
	{$txtCOADate     	= date("Y-m-d",strtotime($_REQUEST['txtCOADate']));}
    else{$txtCOADate  = "1970-01-01";}
	
	if($_REQUEST['txtStartDate']!="")
	{$txtStartDate     	= date("Y-m-d",strtotime($_REQUEST['txtStartDate']));}
    else{$txtStartDate  = "1970-01-01";}
	
	if($_REQUEST['txtEndDate']!="")
	{$txtEndDate     	= date("Y-m-d",strtotime($_REQUEST['txtEndDate']));}
    else{$txtEndDate  	= "1970-01-01";}
	
	$txtCRMFILE1		= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1		= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name 	= $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name 	= implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}

	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into coa_master (COA_ID, MODULEID, MCOMPANYID, COA_DATE, CHARTERER, OWNER, COA_NO, COA_ROUTE, TOTAL_SHIPMENTS, BROKER, VESSEL_TYPE, LOAD_OPTIONS, CARGO, TOLERANCE, COA_NOTICE, MIN_GUARANTEED_QTY, LP_ETA_NOTICES, VESSEL_SUBSTITUTE, COA_DURATION, START_DATE, END_DATE, FREIGHT_DETAILS, LP_DETAILS, DP_DETAILS, DEMM_LAYTIME, REMARKS, UPDATE_STATUS, ATTACHMENT, ATTACHMENT_NAME, ADD_ON_DATE, MESSAGE_NO, CURRENCY, BUSINESSTYPEID, FO_PRICE, BAF_AMT) values ('".$txtCOAid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$txtCOADate."', '".$this->getCheckNullVal($selCharterer)."', '".$this->getCheckNullVal($selOwner)."', '".$this->getCheckNullVal($txtCOANo)."', '".$this->getCheckNullVal($selCOAroute)."', '".$this->getCheckNullVal($txtNoofShipment)."', '".$this->getCheckNullVal($selBroker)."', '".$this->getCheckNullVal($selVesselType)."', '".$this->getCheckNullVal($selLoadOpt)."', '".$this->getCheckNullVal($selCargo)."', '".$this->getCheckNullVal($txtTolerance)."', '".$this->getCheckNullVal($txtCOAnoticeDays)."', '".$this->getCheckNullVal($txtMinGuarQty)."', '".$this->getCheckNullVal($txtLdPrtETAnot)."', '".$this->getCheckNullVal($selVslSubs)."', '".$this->getCheckNullVal($txtCOAduration)."', '".$txtStartDate."', '".$txtEndDate."', '".$this->getCheckNullVal($txtFreightDetails)."', '".$this->getCheckNullVal($txtLPDetails)."', '".$this->getCheckNullVal($txtDPDetails)."', '".$this->getCheckNullVal($txtDemLaytime)."', '".$txtRemarks."', '".$upstatus."', '".$upload1."', '".$name1."', NOW(), '".$messageno."', '".$selCurrency."', '".$selBType."', '".$this->getCheckNullVal($txtFOPrice)."', '".$this->getCheckNullVal($txtBAF)."')";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql1  = "select max(COAID) as max from coa_master";
	$res1  = mysql_query($sql1,$connect);
	$rows1 = mysql_fetch_assoc($res1);
	$maxid1    = $rows1['max'];
	
	$hddnOtherID = $_REQUEST['hddnOtherID'];
	for($i=1 ; $i<=$hddnOtherID ;$i++)
	{
		if($_REQUEST['txtminGuarenteed_'.$i] != "" && $_REQUEST['selExPort_'.$i] != "")
		{
			$sql2 = "insert into coa_master_s1 (COAID, MIN_GUARANTEED, EX_PORT, STATUS, ADD_ON_DATE) values ('".$maxid1."', '".$_REQUEST['txtminGuarenteed_'.$i]."', '".$_REQUEST['selExPort_'.$i]."', 1, NOW())";
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
		}
	} 
		
	return $msg; 
}


function getCOArouteNamesList()
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from coaroute_master where STATUS=1 order by COAROUTE_NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selCOArouteType = @$_REQUEST['selCOArouteType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['COAROUTEID'];
		 $value= $rows['COAROUTE_NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selCOArouteType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getLoadOptionsNameList()
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from loadoption_master where STATUS=1 order by LOADOPTION_NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selLoadOpt = @$_REQUEST['selLoadOpt'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['LOADOPTIONSID'];
		 $value= $rows['LOADOPTION_NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selLoadOpt){ echo " selected";}
		 echo ">".$value."</option>";
		}
}



function getVesselSubstitutionList()
{
$state = array('1' =>'7 days eta', '2' =>'5 days eta', '3' =>'Not Applicable');
echo "<option value = '' >---Select from list---</option>";
$selVslSubs = @$_REQUEST['selVslSubs'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		echo "<option value=$key";
		if($key == $selVslSubs){ echo " selected";}
		echo ">".$value."</option>";
	}
}


function getCOARouteNameBasedOnId($id)
{
	$this->funConnect();
	$sql 	= "select COAROUTE_NAME from coaroute_master where COAROUTEID='".$id."'";
	$res 	= mysql_query($sql);
	$rows 	= mysql_fetch_assoc($res);
	return $rows['COAROUTE_NAME'];
}



function getCargoTypeList()
{
	$connect 	= $this->funConnect();
	$query 	 	= mysql_query("select * from cargotype_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selCType 	= @$_REQUEST['selCType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CARGOTYPEID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selCType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getVesselCategoryList()
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from vessel_category_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selVCType = @$_REQUEST['selVCType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['VESSEL_CATEGORY_ID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selVCType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getVendorListNewForCOA($id)
{
	$connect 	= $this->funConnect();
	$sql = "select CODE, NAME from vendor_master where STATUS=1 and VENDOR_TYPEID in (".$id.") and MCOMPANYID='".$_SESSION['company']."' order by NAME ";
	$result 		= mysql_query($sql) or die($sql);
	echo '<option value = "" >---Select from list---</option>';
	@$selVendor = @$_REQUEST['selVendor'];
	while($rows = mysql_fetch_assoc($result))
		{
		 $key = $rows['CODE'];
		 $value = addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
		 echo '<option value="'.$key.'"';
		 if($key == @$selVendor){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}


function viewCOARecords($id)
{
	$connect = $this->funConnect();
	$sql = "select * from coa_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COAID='".$id."'";
	$result = mysql_query($sql) or die($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['COA_ID'];
		$this->var_2 = $rows['MODULEID'];
		$this->var_3 = $rows['MCOMPANYID'];
		$this->var_4 = $rows['COA_DATE'];
		$this->var_5 = $rows['CHARTERER'];
		$this->var_6 = $rows['OWNER'];
		$this->var_7 = $rows['COA_NO'];
		$this->var_8 = $rows['COA_ROUTE'];
		$this->var_9 = $rows['TOTAL_SHIPMENTS'];
		$this->var_10 = $rows['BROKER'];
		$this->var_11 = $rows['VESSEL_TYPE'];
		$this->var_12 = $rows['LOAD_OPTIONS'];
		$this->var_13 = $rows['CARGO'];
		$this->var_14 = $rows['TOLERANCE'];
		$this->var_15 = $rows['COA_NOTICE'];
		$this->var_16 = $rows['MIN_GUARANTEED_QTY'];
		$this->var_17 = $rows['LP_ETA_NOTICES'];
		$this->var_18 = $rows['VESSEL_SUBSTITUTE'];
		$this->var_19 = $rows['COA_DURATION'];
		$this->var_20 = $rows['START_DATE'];
		$this->var_21 = $rows['END_DATE'];
		$this->var_22 = $rows['FREIGHT_DETAILS'];
		$this->var_23 = $rows['LP_DETAILS'];
		$this->var_24 = $rows['DP_DETAILS'];
		$this->var_25 = $rows['DEMM_LAYTIME'];
		$this->var_26 = $rows['REMARKS'];
		$this->var_27 = $rows['UPDATE_STATUS'];
		$this->var_28 = $rows['ATTACHMENT'];
		$this->var_29 = $rows['ATTACHMENT_NAME'];
		$this->var_30 = $rows['ADD_ON_DATE'];
		$this->var_31 = $rows['UPDATE_ON_DATE'];
		$this->var_32 = $rows['COAID'];
		$this->var_33 = $rows['CURRENCY'];
		$this->var_34 = $rows['BUSINESSTYPEID'];
		$this->var_35 = $rows['FO_PRICE'];
		$this->var_36 = $rows['BAF_AMT'];
	}
}

function getCargoTypeNameBasedOnID($id)
{
	$connect 	= $this->funConnect();
	$sql 		= "select NAME from cargotype_master where CARGOTYPEID='".$id."'";
	$res 		= mysql_query($sql);
	$rows 		= mysql_fetch_assoc($res);
	return $rows['NAME'];
}


function cancelCOADetails()
{
	$connect 	= $this->funConnect();
	$remarks 	= addslashes(trim($_REQUEST['txtRemarks']));
	$id			= $_REQUEST['id'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update coa_master set CANCEL_REMARKS='".$remarks."',STATUS='2' where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and COAID='".$id."' ";
	mysql_query($sql);
	mysql_query("commit");
	return $msg; 
}


function displayVesselOpenEntryInternalUsersList(){
	
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="open_vessel_position_internal_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="top" width="10%">Vessel</th>';
	echo '<th align="left" valign="top" width="10%">Owner / COA No.</th>';	
	echo '<th align="left" valign="top" width="10%">Broker</th>';
	echo '<th align="left" valign="top" width="10%">ETA During Fixture</th>';
	echo '<th align="left" valign="top" width="10%">CP Date</th>';
	echo '<th align="left" valign="top" width="10%">Port Opening</th>';
	echo '<th align="left" valign="top" width="10%">Laycan Date Range</th>';
	echo '<th align="left" valign="top" width="10%">Filled By</th>';
	echo '<th align="center" valign="top" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from open_vessel_entry_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS=1 AND VESSEL_STATUS=0 order by SHOW_STATUS";

	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else
	{
		
		echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
		{
			if($rows['SHOW_STATUS'] == 1)
			{
				echo '<tr>';
				echo '<td align="left" valign="middle">'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
				if($rows['COA_SPOT'] == 2)
				{
					echo '<td align="left" valign="middle">'.$this->getVendorListNewBasedOnID($rows['OWNER']).' / '.$this->getCOANumberBasedOnID($rows['COA_NO']).'</td>';
				}
				else
				{
					echo '<td align="left" valign="middle">'.$this->getVendorListNewBasedOnID($rows['OWNER']).'</td>';
				}
				echo '<td align="left" valign="middle">'.$this->getVendorListNewBasedOnID($rows['BROKER']).'</td>';
				if(date("d-M-Y",strtotime($rows['ETA_DATE'])) == "01-Jan-1970")
				{
					echo '<td align="left" valign="middle"></td>';
				}
				else
				{
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows['ETA_DATE'])).'</td>';
				}
				
				if(date("d-M-Y",strtotime($rows['CP_DATE'])) == "01-Jan-1970")
				{
					echo '<td align="left" valign="middle"></td>';
				}
				else
				{
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows['CP_DATE'])).'</td>';
				}
				
				echo '<td align="left" valign="middle">'.$this->getPortNameBasedOnCode($rows['PORT_CODE']).'</td>';
				echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows['FROM_DATE'])).'<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To <br/>'.date("d-m-Y",strtotime($rows['TO_DATE'])).'</td>';
				echo '<td align="left" valign="middle" style="color:red;">'.$rows['LOGINTYPE'].'<br/>'.$this->getUserDetailBaseOnId($rows['LOGINID'],'CONTACT_PERSON').'</td>';
				
				$uid	  = $_SESSION['uid'];
				$moduleid = $_SESSION['moduleid'];
				
				$rigts = $this->getUserRights($uid,$moduleid,1); 
				if($rigts == 1)
				{
					echo '<td align="center" valign="middle"><a href="updateVesselOpenPosition.php?id='.$rows['OPENVESSEL_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#'.$i.'" onclick="return getDelete('.$rows['OPENVESSEL_ID'].');" ><i class="fa fa-times" style="color:red;"></i></a></td>';
				}
				else
				{
					echo '<td align="center" valign="middle"><a href="updateVesselOpenPosition.php?id='.$rows['OPENVESSEL_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';
				}
				
				
				echo '</tr>';
			}				
			$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function displayVesselOpenEntryExternalUsersList(){

	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="open_vessel_position_external_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="top" width="10%">Vessel</th>';
	echo '<th align="left" valign="top" width="10%">Owner / COA No.</th>';	
	echo '<th align="left" valign="top" width="10%">Broker</th>';
	echo '<th align="left" valign="top" width="10%">ETA During Fixture</th>';
	echo '<th align="left" valign="top" width="10%">CP Date</th>';
	echo '<th align="left" valign="top" width="10%">Port Opening</th>';
	echo '<th align="left" valign="top" width="10%">Laycan Date Range</th>';
	echo '<th align="left" valign="top" width="10%">Filled By</th>';
	echo '<th align="center" valign="top" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from open_vessel_entry_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS=1 AND CLOSE_STATUS=1 AND VESSEL_STATUS=0 order by SHOW_STATUS";

	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else
	{
		
		echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
		{
			if($rows['SHOW_STATUS'] == 2)
			{
				$title = "DWT : ".$this->getExternalVesselData($rows['VESSEL_IMO_ID'],"DWT")." , Year Built : ".$this->getExternalVesselData($rows['VESSEL_IMO_ID'],"YEARBUILT")." , DRAFT(M) : ".$this->getExternalVesselData($rows['VESSEL_IMO_ID'],"DRAFTM")." , Crane Size : ".$this->getExternalVesselData($rows['VESSEL_IMO_ID'],"CRANESIZE")." , Grab Size : ".$this->getExternalVesselData($rows['VESSEL_IMO_ID'],"GRABSIZE");
					
				echo '<tr>';
				echo '<td align="left" valign="middle" class="input-text"><span title="'.$title.'" id="vessel_external_'.$i.'" data-toggle="tooltip" data-original-title="">'.$this->getExternalVesselData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</span></td>';
				
				
				if($rows['COA_SPOT'] == 2)
				{
					echo '<td align="left" valign="middle">'.$this->getExternalVesselData($rows['OWNER']).' / '.$this->getCOANumberBasedOnID($rows['COA_NO']).'</td>';
				}
				else
				{
					echo '<td align="left" valign="middle">'.$this->getExternalVesselData($rows['OWNER']).'</td>';
				}
				
				echo '<td align="left" valign="middle">'.$this->getExternalVesselData($rows['BROKER']).'</td>';
				
				if(date("d-M-Y",strtotime($rows['ETA_DATE'])) == "01-Jan-1970")
				{
					echo '<td align="left" valign="middle"></td>';
				}
				else
				{
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows['ETA_DATE'])).'</td>';
				}
				
				if(date("d-M-Y",strtotime($rows['CP_DATE'])) == "01-Jan-1970")
				{
					echo '<td align="left" valign="middle"></td>';
				}
				else
				{
					echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows['CP_DATE'])).'</td>';
				}
				
				echo '<td align="left" valign="middle">'.$this->getPortNameBasedOnCode($rows['PORT_CODE']).'</td>';
				
				echo '<td align="left" valign="middle">'.date("d-m-Y",strtotime($rows['FROM_DATE'])).'<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To <br/>'.date("d-m-Y",strtotime($rows['TO_DATE'])).'</td>';
				echo '<td align="left" valign="middle" style="color:red;">'.$rows['LOGINTYPE'].'<br/>'.$this->getUserDetailBaseOnId($rows['LOGINID'],'CONTACT_PERSON').'</td>';
				
				$uid	  = $_SESSION['uid'];
				$moduleid = $_SESSION['moduleid'];
				$rigts = $this->getUserRights($uid,$moduleid,1); 
				if($rigts == 1)
				{
					echo '<td align="left" valign="middle" class="input-text"><button class="btn btn-info btn-flat" id="inner-login-button" type="button" onclick="return getConfirmVessel('.$rows['OPENVESSEL_ID'].');" ><b>Confirm</b></button><br><br><button class="btn btn-info btn-flat" id="inner-login-button" type="button" onclick="return getDelete('.$rows['OPENVESSEL_ID'].');" ><b>&nbsp;&nbsp;Delete&nbsp;&nbsp;</b></button></td>';
				}
				else
				{
					echo '<td align="left" valign="middle" class="input-text"></td>';
				}
				
				echo '</tr>';
			}
				
			$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function getVesselIMOData($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from vessel_imo_master where VESSEL_IMO_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getCOANumberBasedOnID($id)
{
	$this->funConnect();
	$sql = "select COA_NO from coa_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COAID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['COA_NO'];
}





function getVesselTypeListMemberWise($rdoEstimateType='')
{
	$this->funConnect();
	if($rdoEstimateType!='')
	{
		$query = mysql_query("select VESSEL_NAME, VESSEL_IMO_ID from vessel_imo_master where BUSINESSTYPEID='".$rdoEstimateType."' order by VESSEL_NAME ");
	}else{
		$query = mysql_query("select VESSEL_NAME, VESSEL_IMO_ID from vessel_imo_master where 1=1 order by VESSEL_NAME ");
	} 
	echo "<option value = '' >---Select from list---</option>";
	@$selVName = @$_REQUEST['selVName'];
	while($rows = mysql_fetch_assoc($query))
		{
			 $key= $rows['VESSEL_IMO_ID'];
			 $value= $rows['VESSEL_NAME'];
			 echo "<option value='".$key."' ";
			 if($key == @$selVName){ echo " selected";}
			 echo ">".$value."</option>";
		}
}

function getVesselList()
{
	$this->funConnect();
	$query = mysql_query("select VESSEL_NAME, VESSEL_IMO_ID from vessel_imo_master order by VESSEL_NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selVName = @$_REQUEST['selVName'];
	while($rows = mysql_fetch_assoc($query))
		{
			 $key= $rows['VESSEL_IMO_ID'];
			 $value= $rows['VESSEL_NAME'];
			 echo "<option value='".$key."' ";
			 if($key == @$selVName){ echo " selected";}
			 echo ">".$value."</option>";
		}
}


function msort_ascending($array, $key, $sort_flags = SORT_REGULAR) {
    if (is_array($array) && count($array) > 0) {
        if (!empty($key)) {
            $mapping = array();
            foreach ($array as $k => $v) {
                $sort_key = '';
                if (!is_array($key)) {
                    $sort_key = $v[$key];
                } else {
                    foreach ($key as $key_key) {
                        $sort_key .= $v[$key_key];
                    }
                    $sort_flags = SORT_STRING;
                }
                $mapping[$k] = $sort_key;
            }
            asort($mapping, $sort_flags);
            $sorted = array();
            foreach ($mapping as $k => $v) {
                $sorted[] = $array[$k];
            }
            return $sorted;
        }
    }
    return $array;
}

function getCOAMasterDataJson()
{
	$connect = $this->funconnect();
	$sql = "select * from coa_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS=1 order by COA_DATE desc";
	$res = mysql_query($sql);
	while($rows = mysql_fetch_assoc($res))
	{
		$a[$rows['COAID']][] = array( 'NO_OF_SHIPMENT' => $rows['NO_OF_SHIPMENT'],'OWNER' => $rows['OWNER'],'BROKER' => $rows['BROKER'],'COA_DATE' => date("d-m-Y",strtotime($rows['COA_DATE'])));
		$i++;
	}	
	echo json_encode($a);
}


function getPortListNew()
{
	$this->funConnect();
	$query = mysql_query("select * from port_master where STATUS=1 order by PortName ");
	echo '<option value = "" >---Select from list---</option>';
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['PortCode'];
		 $value= $rows['PortName'];
		 echo '<option value="'.$key.'"';
		 echo '>'.$value.'</option>';
		}
}


function getCOASpotList()
{
$state = array( 1 =>'SPOT' , 2 =>'COA');
$selCOASpot = @$_REQUEST['selCOASpot'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selCOASpot){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getBusinessTypeForCargoPlanning($selBType)
{
	$state = array( 1 =>'Cargo Relet' , 2 =>'Voyage');
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selBType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getStatusForCargoPlanning($selStatus)
{
	$state = array( 1 =>'Confirmed' , 2 =>' Un Comﬁrmed');
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selStatus){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getStatusForCargoPlanningBasedOnID($selStatus)
{
	$state = array( 1 =>'Confirmed' , 2 =>' Un Comﬁrmed');
	return $state[$selStatus];
}

function getCOAList()
{
	$connect = $this->funConnect();
	$query = mysql_query("select * from coa_master WHERE STATUS=1 order by COA_DATE desc");
	$selCOA = @$_REQUEST['selCOA'];
	echo '<option value = "" >---Select from list---</option>';
	while($rows = mysql_fetch_assoc($query))
		{
			if($this->getPerformedVesselRec($rows['COAID']) < $rows['NO_OF_SHIPMENT'])
			{
				$value = $rows['COA_NO'];
				$key = $rows['COAID'];
				echo "<option value=$key";
				if($key == $selCOA){ echo " selected";}
				echo ">".$value."</option>";
			}
		}
}


function getMaterialType()
{
	$this->funConnect();
	$query = mysql_query("select MATERIAL_TYPE, MATERIAL_CODE, MATERIAL_CODE_DESC from cargo_master where STATUS=1 order by MATERIAL_CODE_DESC ");
	echo '<option value = "" >---Select from list---</option>';
	@$selMType = @$_REQUEST['selMType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['MATERIAL_TYPE']."@@@".$rows['MATERIAL_CODE'];
		 $value= $rows['MATERIAL_CODE_DESC'];
		 echo '<option value='.$key;
		 if($key == @$selMType){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}



function getOpenVesselPositionList()
{
	$this->funConnect();
	$query = mysql_query("select * from open_vessel_entry_master where STATUS=1 AND VESSEL_STATUS=0 AND SHOW_STATUS=1 order by OPENVESSEL_ID desc");
	echo "<option value = '' >---Select from list---</option>";
	@$selVOPID = @$_REQUEST['selVOPID'];	
	while($rows = mysql_fetch_assoc($query))
		{
			 $key= $rows['OPENVESSEL_ID'];
			 $value= $this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME")." (".date("d M Y",strtotime($rows['FROM_DATE']))." to ".date("d M Y",strtotime($rows['TO_DATE'])).")";
			 echo "<option value='".$key."' ";
			 if($key == @$selVOPID){ echo " selected";}
			 echo ">".$value."</option>";
		}
}



function insertCargoOpenPositionDetails()
{
	$connect 				= $this->funConnect();
	$txtCID 			    = addslashes(trim($_REQUEST['txtCID']));
	$messageno 			    = explode('-',$_REQUEST['txtCID'])[1];
	$selShipper			    = addslashes(trim($_REQUEST['selShipper']));
	$selCharterer			= addslashes(trim($_REQUEST['selCharterer']));
	$selOwner				= addslashes(trim($_REQUEST['selOwner']));
	$selReceiver 			= addslashes(trim($_REQUEST['selReceiver']));
	$selCargo 				= addslashes(trim($_REQUEST['selCargo']));
	$txtFDate 				= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	$txtTDate 				= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	$txtTolerance			= addslashes(trim($_REQUEST['txtTolerance']));
	$txtQty     			= addslashes(trim($_REQUEST['txtQty']));
	$selBType	 			= addslashes(trim($_REQUEST['selBType']));
	$txtFreight	 			= addslashes(trim($_REQUEST['txtFreight']));
	$selPlannintType		= addslashes(trim($_REQUEST['selPlannintType']));
	$txtCOADate             = date("Y-m-d",strtotime($_REQUEST['txtCOADate']));
	$selBaseIn      		= addslashes(trim($_REQUEST['selBaseIn']));
	$selLPort        		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort       		= addslashes(trim($_REQUEST['selDPort']));
	$selCType        		= addslashes(trim($_REQUEST['selCType']));
	$selVesselType 		    = addslashes(trim($_REQUEST['selVesselType']));
	$selStatus		        = addslashes(trim($_REQUEST['selStatus']));
	$txtNomClause    		= addslashes(trim($_REQUEST['txtNomClause']));
	$txtRemarks     		= addslashes(trim($_REQUEST['txtRemarks']));
	$selBunkerHedge     	= addslashes(trim($_REQUEST['selBunkerHedge']));
	$upstatus               = addslashes(trim($_REQUEST['upstatus']));
	$rdoWstype              = $_REQUEST['rdoWstype'];
	$txtWsLumpsum           = addslashes(trim($_REQUEST['txtWsLumpsum']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$mysql = "select * from open_cargo_master where CPID='".$txtCID."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' ";
	$myres = mysql_query($mysql) or die($mysql);
	$myrec = mysql_num_rows($myres);
	if($myrec == 0)
	{
		$sql = "insert into open_cargo_master (CPID, CHARTERER, OWNER, CARGO, CARGOSTEAMSIZE, BUSINESSTYPEID, BASE_FREIGHT, RECEAVER, COA_SPOT, COA_DATE, STATUS, BASINID, LOAD_PORT, DISCHARGE_PORT, VESSEL_TYPE, LAYCAN_SDATE, LAYCAN_EDATE, CARGO_RELET, NOMCLAUSE, REMARKS, MCOMPANYID, TOLERANCE, SHIPPER, MESSAGE_NO, MODULEID, BUNKER_HEDGE, UPDATE_STATUS, ADDONDATE, RDO_WS_TYPE, WS_LUMPSUM_AMOUNT) values ('".$txtCID."','".$selCharterer."','".$selOwner."','".$selCargo."','".$this->getCheckNullVal($txtQty)."','".$selBType."','".$this->getCheckNullVal($txtFreight)."','".$selReceiver."','".$selPlannintType."', '".$txtCOADate."', '".$selStatus."', '".$selBaseIn."', '".$selLPort."', '".$selDPort."', '".$selVesselType."', '".$txtFDate."', '".$txtTDate."', '".$selCType."', '".$txtNomClause."', '".$txtRemarks."','".$_SESSION['company']."', '".$txtTolerance."', '".$selShipper."', '".$messageno."', '".$_SESSION['moduleid']."', '".$selBunkerHedge."', '".$upstatus."', NOW(), '".$rdoWstype."','".$txtWsLumpsum."')";
	
		mysql_query($sql) or die($sql);
		mysql_query("commit");
	
		return $msg; 
	}
	else
	{
		return 3;
	}
}





function getMaterialCodeDesBasedOnCode($id)
{
	$this->funConnect();
	$sql = "select MATERIAL_TYPE from cargo_master where MATERIALID in (".$id.")";
	$res = mysql_query($sql);
	$material = "";
	while($rows = mysql_fetch_assoc($res))
	{
		if($material_name!="")
		{
			$material_name = $material_name.", ";
		}
	$material_name = $material_name."".$rows['MATERIAL_TYPE'];
	}
	return $material_name;
	//return $rows['MATERIAL_CODE_DESC'];
}


function deleteCargoEntry($cargoid)
{
	$connect				= $this->funConnect();
	$msg = 4;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	$del_query = "delete from  open_cargo_master where OPEN_CARGOID='".$cargoid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($del_query);

	mysql_query("commit"); 
	
	return $msg;
}



function getOpenCargoPositionData($cargoid,$field)
{
	$connect				= $this->funConnect();
	$sql = "select ".$field." from open_cargo_master where OPEN_CARGOID='".$cargoid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}



function viewOpenCargoPositionRecords($id)
{
	$connect = $this->funConnect();
	
	$sql = "select * from open_cargo_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and OPEN_CARGOID='".$id."'";
	$result = mysql_query($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['CPID'];
		$this->var_2 = $rows['CHARTERER'];
		$this->var_3 = $rows['OWNER'];
		$this->var_4 = $rows['CARGO'];
		$this->var_5 = $rows['CARGOSTEAMSIZE'];
		$this->var_6 = $rows['BUSINESSTYPEID'];
		$this->var_7 = $rows['BASE_FREIGHT'];
		$this->var_8 = $rows['RECEAVER'];
		$this->var_9 = $rows['COA_SPOT'];
		$this->var_10 = $rows['COA_DATE'];
		$this->var_11 = $rows['STATUS'];
		$this->var_12 = $rows['BASINID'];
		$this->var_13 = $rows['LOAD_PORT'];
		$this->var_14 = $rows['DISCHARGE_PORT'];
		$this->var_15 = $rows['VESSEL_TYPE'];
		$this->var_16 = $rows['LAYCAN_SDATE'];
		$this->var_17 = $rows['LAYCAN_EDATE'];
		$this->var_18 = $rows['CARGO_RELET'];
		$this->var_19 = $rows['NOMCLAUSE'];
		$this->var_20 = $rows['REMARKS'];
		$this->var_21 = $rows['TOLERANCE'];
		$this->var_22 = $rows['SHIPPER'];
		$this->var_23 = $rows['MAP_STATUS'];
		$this->var_24 = $rows['BUNKER_HEDGE'];
		$this->var_25 = $rows['UPDATE_STATUS'];
		$this->var_26 = $rows['MCOMPANYID'];
		$this->var_27 = $rows['RDO_WS_TYPE'];
		$this->var_28 = $rows['WS_LUMPSUM_AMOUNT'];
	}
}


function updateCargoOpenPositionDetails()
{
	$connect 				= $this->funConnect();
	$id 					= $_REQUEST['id'];
	$selShipper			    = addslashes(trim($_REQUEST['selShipper']));
	$selCharterer			= addslashes(trim($_REQUEST['selCharterer']));
	$selOwner				= addslashes(trim($_REQUEST['selOwner']));
	$selReceiver 			= addslashes(trim($_REQUEST['selReceiver']));
	$selCargo 				= addslashes(trim($_REQUEST['selCargo']));
	$txtFDate 				= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	$txtTDate 				= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	$txtTolerance			= addslashes(trim($_REQUEST['txtTolerance']));
	$txtQty     			= addslashes(trim($_REQUEST['txtQty']));
	$selBType	 			= addslashes(trim($_REQUEST['selBType']));
	$txtFreight	 			= addslashes(trim($_REQUEST['txtFreight']));
	$selPlannintType		= addslashes(trim($_REQUEST['selPlannintType']));
	$txtCOADate             = date("Y-m-d",strtotime($_REQUEST['txtCOADate']));
	$selBaseIn      		= addslashes(trim($_REQUEST['selBaseIn']));
	$selLPort        		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort       		= addslashes(trim($_REQUEST['selDPort']));
	$selCType        		= addslashes(trim($_REQUEST['selCType']));
	$selVesselType 		    = addslashes(trim($_REQUEST['selVesselType']));
	$selStatus		        = addslashes(trim($_REQUEST['selStatus']));
	$txtNomClause    		= addslashes(trim($_REQUEST['txtNomClause']));
	$txtRemarks     		= addslashes(trim($_REQUEST['txtRemarks']));
	$selBunkerHedge         = addslashes(trim($_REQUEST['selBunkerHedge']));
	$upstatus               = addslashes(trim($_REQUEST['upstatus']));
	$rdoWstype              = $_REQUEST['rdoWstype'];
	$txtWsLumpsum           = addslashes(trim($_REQUEST['txtWsLumpsum']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update open_cargo_master set CHARTERER='".$selCharterer."', OWNER='".$selOwner."', CARGO='".$selCargo."', CARGOSTEAMSIZE='".$this->getCheckNullVal($txtQty)."', BUSINESSTYPEID='".$selBType."', BASE_FREIGHT='".$this->getCheckNullVal($txtFreight)."', RECEAVER='".$selReceiver."', COA_SPOT='".$selPlannintType."', COA_DATE='".$txtCOADate."', STATUS='".$selStatus."', BASINID='".$selBaseIn."', LOAD_PORT='".$selLPort."', DISCHARGE_PORT='".$selDPort."', VESSEL_TYPE='".$selVesselType."', LAYCAN_SDATE='".$txtFDate."', LAYCAN_EDATE='".$txtTDate."', CARGO_RELET='".$selCType."', NOMCLAUSE='".$txtNomClause."', REMARKS='".$txtRemarks."', TOLERANCE='".$txtTolerance."', SHIPPER='".$selShipper."', BUNKER_HEDGE='".$selBunkerHedge."', UPDATE_STATUS='".$upstatus."',RDO_WS_TYPE='".$rdoWstype."',WS_LUMPSUM_AMOUNT='".$txtWsLumpsum."' where OPEN_CARGOID='".$id."'";
	//echo $sql;die;
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	return $msg; 
	
}


function getOpenCargoMasterDataBasedOnContractID($id,$field)
{
	$connect = $this->funConnect();
	$sql  = "select ".$field." from open_cargo_master where CONTRACTID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}



function getOpenVesselPositionListForUpdate($open_vesselid)
{
	$this->funConnect();
	$query = mysql_query("select * from open_vessel_entry_master where STATUS=1 AND VESSEL_STATUS=0 AND SHOW_STATUS=1 order by OPENVESSEL_ID desc");
	echo "<option value = '' >---Select from list---</option>";
	@$selVOPID = @$_REQUEST['selVOPID'];
	
	echo "<option value='0' ";
	if(@$open_vesselid == 0){ echo " selected";}
	echo ">TBN</option>";
	
	while($rows = mysql_fetch_assoc($query))
		{
			 $key= $rows['OPENVESSEL_ID'];
			 $value= $this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME")." (".date("d M Y",strtotime($rows['FROM_DATE']))." to ".date("d M Y",strtotime($rows['TO_DATE'])).")";
			 echo "<option value='".$key."' ";
			 if($key == @$selVOPID){ echo " selected";}
			 echo ">".$value."</option>";
		}
	if($open_vesselid != 0)
	{
		$value1 = $this->getVesselIMOData($this->getVesselOpenEntryDeta($open_vesselid,'VESSEL_IMO_ID'),"VESSEL_NAME")." (".date("d M Y",strtotime($this->getVesselOpenEntryDeta($open_vesselid,'FROM_DATE')))." to ".date("d M Y",strtotime($this->getVesselOpenEntryDeta($open_vesselid,'TO_DATE'))).")";
		echo "<option value='".$open_vesselid."' ";
	    if($open_vesselid == @$selVOPID){ echo " selected";}
	    echo ">".$value1."</option>";
	}
}



function getEditNominationValues($comid)
{
	$this->funConnect();
	$sql = mysql_query("select * from nom_details where COMID='".$comid."'");
	$rec = mysql_num_rows($sql);
	
	$sql1 = mysql_query("select * from tc_cp_terms where COMID='".$comid."'");
	$rec1 = mysql_num_rows($sql1);
	
	if($rec != 0 && $rec1 != 0 ){return 1;}
	else{return 0;}
}


function getAllStandardsValues($comid)
{
	$this->funConnect();
	$sql = mysql_query("select * from mapping_standards where COMID='".$comid."'");
	$rec = mysql_num_rows($sql);
	
	$sql1 = mysql_query("select * from approvals_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS=1");
	$rec1 = mysql_num_rows($sql1);
	
	if($rec == $rec1){return 0;}
	else{return 1;}
}


function getFreightEstimationRecProcessWise($mappingid,$sheet_no)
{
	$connect = $this->funConnect();
	$sql = "select * from freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$mappingid."' and  SHEET_NO='".$sheet_no."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	return $rec;
}

function getFreightEstimationStatus($comid)
{
	$connect = $this->funConnect();
	$sql = "select FIXTURETYPEID from freight_cost_estimete_master where MODULEID='".$_SESSION['moduleid']."' and COMID='".$comid."' order by FCAID desc";
	$res 	= mysql_query($sql);
	$rec	= mysql_num_rows($res);
	$rows 	= mysql_fetch_assoc($res);
	return $rows['FIXTURETYPEID'];
}

function getFreightEstimationStatusForVcIn($comid)
{
	$connect = $this->funConnect();
	$sql = "select FIXTURETYPEID from freight_cost_estimete_in_master where MODULEID='".$_SESSION['moduleid']."' and COMID='".$comid."' order by FCAID desc";
	$res 	= mysql_query($sql);
	$rec	= mysql_num_rows($res);
	$rows 	= mysql_fetch_assoc($res);
	return $rows['FIXTURETYPEID'];
}


function getFreightEstimationStatusForAll($comid)
{
	$connect = $this->funConnect();
	$sql = "select FINAL_STATUS from freight_cost_estimete_master where MODULEID='".$_SESSION['moduleid']."' and COMID='".$comid."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$val = 0;
	while($rows = mysql_fetch_assoc($res))
	{
		if($rows['FINAL_STATUS'] == 1)
		{
			$arr[] = $rows['FINAL_STATUS'];
		}
	}
	$val = count($arr);
	return $val;
}

function getBusinessTypeBasedOnID($id)
{
	$this->funConnect();
	$sql = "select NAME from business_type_master where BUSINESSTYPEID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}





function getVesselTypeBasedOnID($id)
{
 $this->funConnect();
 $sql  = "select VESSELTYPE from vessel_type_master where VESSELTYPEID=".$id;
 $res  = mysql_query($sql) or die(mysql_error());
 $rows = mysql_fetch_assoc($res);
 return $rows['VESSELTYPE'];
}



function insertVesselOpenPositionDetails()
{
	$connect 			= $this->funConnect();
	
	$vessel_id			= addslashes(trim($_REQUEST['selVName']));
	$vendorid	 		= addslashes(trim($_REQUEST['selVendor']));
	$portcode			= addslashes(trim($_REQUEST['selPort']));
	$zoneid			    = addslashes(trim($_REQUEST['selZone']));
	$from_date			= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	$to_date 			= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	$notes				= addslashes(trim($_REQUEST['txtNotes']));
	
	$direction			= addslashes(trim($_REQUEST['txtDirection']));
	
	$selBroker			= addslashes(trim($_REQUEST['selBroker']));
	$eta_date			= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	$cp_date 			= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	
    $coa_spot 			= addslashes(trim($_REQUEST['selCOASpot']));
    $owner	 			= addslashes(trim($_REQUEST['selOwner']));
    $coa_no 			= addslashes(trim($_REQUEST['selCOA']));
    $txtLayDate 		= date("Y-m-d",strtotime($_REQUEST['txtLayDate']));
	
	$txtexpectedhire 	= addslashes(trim($_REQUEST['txtexpectedhire']));
	$txtDisponentOwner 	= addslashes(trim($_REQUEST['txtDisponentOwner']));
	
	if($_REQUEST['txtNoLift']== "")
	{
		$no_of_lift = 0;
	}
	else
	{
		$no_of_lift	= addslashes(trim($_REQUEST['txtNoLift']));
	}
	
	$selVCType				= addslashes(trim($_REQUEST['selVCType']));
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$filename = $this->getUpload($_FILES['attach_file']); 
	$filename = implode(',',$filename);
	
	$fname = $this->getUploadName($_FILES['attach_file']);
	$fname = implode(',',$fname);
	
	//insert query here.............
	$sql = "insert into open_vessel_entry_master (VESSEL_IMO_ID, PORT_CODE, ZONEID, FROM_DATE, TO_DATE, NOTES, DIRECTION, IS_PRIVATE, PRIVATE_DATE ,MODULEID,MCOMPANYID,LOGINID,LOGINTYPE,BROKER,ETA_DATE,CP_DATE,ATTACHMENT,COA_SPOT,OWNER,COA_NO,NO_OF_LIFT,VESSEL_CATEGORY,LAYCAN_NOM_DATE, EXPECTED_HIRE, DISPONENT_OWNER,ATTACHMENT_NAME) values ('".$vessel_id."','".$portcode."','".$zoneid."','".$from_date."','".$to_date."','".$notes."','".$direction."','0',NULL,'".$_SESSION['moduleid']."','".$_SESSION['company']."','".$_SESSION['uid']."','Internal User','".$selBroker."','".$eta_date."','".$cp_date."','".$filename."','".$coa_spot."','".$owner."','".$coa_no."','".$no_of_lift."','".$selVCType."','".$txtLayDate."', '".$txtexpectedhire."','".$txtDisponentOwner."','".$fname."')";
	//echo $sql;die();
	mysql_query($sql);
	mysql_query("commit");
	
	$sql1 = "select max(OPENVESSEL_ID) as max from open_vessel_entry_master";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	$id = $rows1['max'];
	
	$tabid = count($_REQUEST['txttabid']); 
	$txtTID = $_REQUEST['txtTID_'.$tabid]; 
	
	$query = "select * from open_vessel_entry_disponent_owner where OPENVESSEL_ID='".$id."'";
	$queryres = mysql_query($query,$connect);
	$queryrows = mysql_num_rows($queryres);
		
	for($i=$queryrows+1 ; $i<=$txtTID ;$i++)
	{
		if($_REQUEST['txtDisponentOwner_'.$i] != "")
		{
			$sql2 = "insert into open_vessel_entry_disponent_owner (OPENVESSEL_ID,DISPONENT_OWNER) values ('".$id."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
			mysql_query($sql2,$connect);
			mysql_query("commit");
		}
	} 
	
	return $msg; 
}



function viewVesselOpenPositionRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM open_vessel_entry_master where OPENVESSEL_ID='".$id."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['VESSEL_IMO_ID'];
		$this->var_2 = $rows['VENDORID'];
		$this->var_3 = $rows['PORT_CODE'];
		$this->var_4 = $rows['ZONEID'];
		$this->var_5 = $rows['FROM_DATE'];
		$this->var_6 = $rows['TO_DATE'];
		$this->var_7 = $rows['NOTES'];
		$this->var_8 = $rows['DIRECTION'];
		$this->var_9 = $rows['IS_PRIVATE'];
		$this->var_10 = $rows['PRIVATE_DATE'];
		$this->var_11 = $rows['OWNER'];
		$this->var_12 = $rows['BROKER'];
		$this->var_13 = $rows['ETA_DATE'];
		$this->var_14 = $rows['CP_DATE'];
		$this->var_15 = $rows['ATTACHMENT'];
		$this->var_16 = $rows['COA_SPOT'];
		$this->var_17 = $rows['COA_NO'];	
		$this->var_18 = $rows['NO_OF_LIFT'];	
		$this->var_19 = $rows['VESSEL_CATEGORY'];	
		$this->var_20 = $rows['EXPECTED_HIRE'];
		$this->var_21 = $rows['DISPONENT_OWNER'];
		$this->var_22 = $rows['ATTACHMENT_NAME'];
	}
}



function updateVesselOpenPositionDetails()
{
	$connect 			= $this->funConnect();
	$id 				= $_REQUEST['id'];
	$vendorid	 		= addslashes(trim($_REQUEST['selVendor']));
	$portcode			= addslashes(trim($_REQUEST['selPort']));
	$zoneid			    = addslashes(trim($_REQUEST['selZone']));
	$from_date			= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	$to_date 			= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	$notes				= addslashes(trim($_REQUEST['txtNotes']));
	
	$direction			= addslashes(trim($_REQUEST['txtDirection']));
	
	$selBroker			= addslashes(trim($_REQUEST['selBroker']));
	$eta_date			= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	$cp_date 			= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	
	$coa_spot 			= addslashes(trim($_REQUEST['selCOASpot']));
	$owner	 			= addslashes(trim($_REQUEST['selOwner']));
	$coa_no 			= addslashes(trim($_REQUEST['selCOA']));
	$txtLayDate 		= date("Y-m-d",strtotime($_REQUEST['txtLayDate']));
	
	if($_REQUEST['txtNoLift']==""){ $no_of_lift = 0; } else { $no_of_lift = addslashes(trim($_REQUEST['txtNoLift'])); }
	
	$selVCType				= addslashes(trim($_REQUEST['selVCType']));
	$txtexpectedhire 	= addslashes(trim($_REQUEST['txtexpectedhire']));
	$txtDisponentOwner 	= addslashes(trim($_REQUEST['txtDisponentOwner']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$upload = $upload1 = $name = $name1 = $txtCRMFILE = $txtCRMNAME = "";
	$txtCRMFILE							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE != '' && $upload != ''){ $upload1 = $txtCRMFILE.','.$upload;}
	else if($txtCRMFILE == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE != '' && $upload == ''){ $upload1 = $txtCRMFILE;}
	
	if($txtCRMNAME != '' && $name != ''){ $name1 = $txtCRMNAME.','.$name;}
	else if($txtCRMNAME == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME != '' && $name == ''){ $name1 = $txtCRMNAME;}
	
	
	$sql = "update open_vessel_entry_master set PORT_CODE='".$portcode."',ZONEID='".$zoneid."',FROM_DATE='".$from_date."',TO_DATE='".$to_date."',NOTES='".$notes."',DIRECTION='".$direction."',IS_PRIVATE='0',PRIVATE_DATE = NULL,OWNER='".$owner."',BROKER='".$selBroker."',ETA_DATE='".$eta_date."',CP_DATE='".$cp_date."',ATTACHMENT='".$upload1."',ATTACHMENT_NAME='".$name1."',COA_SPOT='".$coa_spot."',COA_NO='".$coa_no."',NO_OF_LIFT='".$no_of_lift."',VESSEL_CATEGORY='".$selVCType."', LAYCAN_NOM_DATE='".$txtLayDate."', EXPECTED_HIRE='".$txtexpectedhire."', DISPONENT_OWNER='".$txtDisponentOwner."' where OPENVESSEL_ID='".$id."'";

	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql1 = "select max(OPENVESSEL_ID) as max from open_vessel_entry_master";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	$id = $rows1['max'];
	
	$tabid = count($_REQUEST['txttabid']); 
	$txtTID = $_REQUEST['txtTID_'.$tabid]; 
	
	$query = "select * from open_vessel_entry_disponent_owner where OPENVESSEL_ID='".$id."'";
	$queryres = mysql_query($query,$connect);
	$queryrows = mysql_num_rows($queryres);
		
	for($i=$queryrows+1 ; $i<=$txtTID ;$i++)
	{
		if($_REQUEST['txtDisponentOwner_'.$i] != "")
		{
			$sql2 = "insert into open_vessel_entry_disponent_owner (OPENVESSEL_ID,DISPONENT_OWNER) values ('".$id."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
			mysql_query($sql2,$connect);
			mysql_query("commit");
		}
	}
	
	return $msg; 
}

function deleteVesselOpenPositionStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 3;
	$sql = "delete from open_vessel_entry_master where OPENVESSEL_ID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'"; 
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}



function nominateCargoEntry($cargoid)
{
	$connect				= $this->funConnect();
	$msg = 5;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update open_cargo_master set MAP_STATUS=2 where OPEN_CARGOID='".$cargoid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	mysql_query("commit");	 
	
	$nomination_id = "V".$this->getOpenCargoPositionData($cargoid,"OPENVESSEL_ID")."_C".$cargoid;
	
	$sql1 = "insert into mapping_master (CARGO_IDS,CARGO_POSITION,OPEN_VESSEL_ID,NOMINATION_ID,MAPPING_DATE,STATUS,MODULEID,MCOMPANYID) values ('".$this->getOpenCargoPositionData($cargoid,"CONTRACTID")."','open','".$this->getOpenCargoPositionData($cargoid,"OPENVESSEL_ID")."','".$nomination_id."','".date("Y-m-d",time())."','1','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql1);
	mysql_query("commit");	 
	
	$open_vessel_id = $this->getOpenCargoPositionData($cargoid,"OPENVESSEL_ID");
			
	$sql2 = "update open_vessel_entry_master set VESSEL_STATUS='2' where OPENVESSEL_ID='".$open_vessel_id."'";
	mysql_query($sql2);
		
	mysql_query("commit"); 
	
	return $msg;
}


function deleteEntry($comid)
{
	$connect				= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;
	
	$mysql = "update open_cargo_master set MAP_STATUS=1 where CONTRACTID='".$this->getMappingData($mappingid,"CARGO_IDS")."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($mysql) or die($mysql);
	
	$del_query1 = "delete from  mapping_standards where MAPPINGID='".$mappingid."'";
	$del_query2 = "delete from  nom_details where COMID='".$comid."'";
	$del_query3 = "delete from  tc_cp_terms where MAPPINGID='".$mappingid."'";
	$del_query4 = "delete from  cost_sheet_name_master where MAPPINGID='".$mappingid."'";
	$del_query5 = "delete from  mapping_master where MAPPINGID='".$mappingid."'";
	$del_query19 = "delete from  commercial_parameters_nomnation_wise where MAPPINGID='".$mappingid."'";
	
	$sql = "select FCAID,FIXTURETYPEID from freight_cost_analysis_master where MAPPINGID='".$mappingid."'";
	$res = mysql_query($sql) or die($sql);
	while($rows = mysql_fetch_assoc($res))
	{
		if($rows['FIXTURETYPEID'] == 1)
		{
			$del_query6 = "delete from  fca_tci_sea_passage where FCAID='".$rows['FCAID']."'";
			$del_query7 = "delete from  fca_tci_load_port where FCAID='".$rows['FCAID']."'";
			$del_query8 = "delete from  fca_tci_portcosts where FCAID='".$rows['FCAID']."'";
			$del_query9 = "delete from  fca_tci_dd_shipper where FCAID='".$rows['FCAID']."'";
			$del_query10 = "delete from  fca_tci_disch_port where FCAID='".$rows['FCAID']."'";
			$del_query11 = "delete from  fca_tci_dd_receiver where FCAID='".$rows['FCAID']."'";
			$del_query12 = "delete from  fca_tci_transit_port where FCAID='".$rows['FCAID']."'";
			$del_query13 = "delete from  fca_tci_totals where FCAID='".$rows['FCAID']."'";
			$del_query14 = "delete from  fca_tci_bunker where FCAID='".$rows['FCAID']."'";
			$del_query15 = "delete from  fca_tci_owner_related_cost where FCAID='".$rows['FCAID']."'";
			$del_query16 = "delete from  fca_tci_other_shipping_cost where FCAID='".$rows['FCAID']."'";
			$del_query17 = "delete from  fca_tci_other_misc_cost where FCAID='".$rows['FCAID']."'";
			$del_query18 = "delete from  freight_cost_analysis_master where FCAID='".$rows['FCAID']."'";
			
			mysql_query($del_query6) or die($del_query6);
			mysql_query($del_query7) or die($del_query7);
			mysql_query($del_query8) or die($del_query8);
			mysql_query($del_query9) or die($del_query9);
			mysql_query($del_query10) or die($del_query10);
			mysql_query($del_query11) or die($del_query11);
			mysql_query($del_query12) or die($del_query12);
			mysql_query($del_query13) or die($del_query13);
			mysql_query($del_query14) or die($del_query14);
			mysql_query($del_query15) or die($del_query15);
			mysql_query($del_query16) or die($del_query16);	
			mysql_query($del_query17) or die($del_query17);
			mysql_query($del_query18) or die($del_query18);	
			mysql_query("commit");
		}
		else
		{
			$del_query6 = "delete from  fca_vci_load_port where FCAID='".$rows['FCAID']."'";
			$del_query7 = "delete from  fca_vci_shipowner where FCAID='".$rows['FCAID']."'";
			$del_query8 = "delete from  fca_vci_dd_shipper where FCAID='".$rows['FCAID']."'";
			$del_query9 = "delete from  fca_vci_disch_port where FCAID='".$rows['FCAID']."'";
			$del_query10 = "delete from  fca_vci_dd_receiver where FCAID='".$rows['FCAID']."'";
			$del_query11 = "delete from  fca_vci_totals where FCAID='".$rows['FCAID']."'";
			$del_query12 = "delete from  fca_vci_other_shipping_cost where FCAID='".$rows['FCAID']."'";
			$del_query13 = "delete from  fca_vci_other_misc_cost where FCAID='".$rows['FCAID']."'";
			$del_query14 = "delete from  freight_cost_analysis_master where FCAID='".$rows['FCAID']."'";
			
			mysql_query($del_query6) or die($del_query6);
			mysql_query($del_query7) or die($del_query7);
			mysql_query($del_query8) or die($del_query8);
			mysql_query($del_query9) or die($del_query9);
			mysql_query($del_query10) or die($del_query10);
			mysql_query($del_query11) or die($del_query11);
			mysql_query($del_query12) or die($del_query12);
			mysql_query($del_query13) or die($del_query13);
			mysql_query($del_query14) or die($del_query14);
			mysql_query("commit");
		}
	}
	
	mysql_query($del_query1) or die($del_query1);
	mysql_query($del_query2) or die($del_query2);
	mysql_query($del_query3) or die($del_query3);
	mysql_query($del_query4) or die($del_query4);
	mysql_query($del_query5) or die($del_query5);
	mysql_query($del_query19) or die($del_query19);
	mysql_query("commit");	 
	return $msg;
}



function getCompareEstimateData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from freight_cost_estimete_master where COMID='".$id."' and MODULEID='".$_SESSION['moduleid']."' order by FCAID desc";
	
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getCompareCargoReletData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from cargo_relet_estimate_masster where COMID='".$id."' and MODULEID='".$_SESSION['moduleid']."' order by FCAID desc";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}



function insertStandardsDetails()
{
	$connect = $this->funConnect();
	$comid    = $_REQUEST['comid'];
	$rec	      = $_REQUEST['txtRec'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$query = "delete from mapping_standards where COMID='".$comid."'";
	mysql_query($query);
	mysql_query("commit");
	//insert query here.............
	for($i=1 ; $i<=$rec ;$i++)
	{
			if($_REQUEST['checkApprovedbox_'.$i] != ""){$app_status = 1;}else{$app_status = 0;}
			
			$sql = "insert into mapping_standards (COMID,APPROVALID,APPROVAL_STATUS,DATE,REMARKS) values ('".$comid."','".$_REQUEST['txtApprovalid_'.$i]."','".$app_status."','".date("Y-m-d",strtotime($_REQUEST['txtDate_'.$i]))."','".$_REQUEST['txtRemarks_'.$i]."')";
			mysql_query($sql) or die($sql);
			mysql_query("commit");
	}
	return $msg; 
}


function getApprovalNameBasedOnID($id)
{
	$this->funConnect();
	$sql = "select NAME from approvals_master where APPROVALID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}


function getFixtureTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from fixture_type_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selFixtureType = @$_REQUEST['selFixtureType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['FIXTURETYPE_ID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selFixtureType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getNomDetailsData($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from nom_details where COMID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getContractLoadPortBasedOnID($cargoids,$field)
{
	$connect = $this->funConnect();
	$arr = explode(",",$cargoids);
	for($i=0;$i<count($arr);$i++)
	{
		$contractid[] = $this->getPortNameBasedOnCode($this->getOpenCargoMasterDataBasedOnContractID($arr[$i],$field));
	}
	return implode(" , ",$contractid);
}



function getCargoContarctForMapping($cargoids,$cargo_possition)
{
	$connect 				= $this->funConnect();
	if($cargo_possition == "open")
	{
		return $this->getMaterialCodeDesBasedOnCode($this->getOpenCargoMasterDataBasedOnContractID($cargoids,"MATERIAL_CODE"));
	}
}


function getCargoContarctQTYForMapping1($cargoids,$cargo_possition)
{
	$connect 				= $this->funConnect();
	if($cargo_possition == "open")
	{
		return $this->getOpenCargoMasterDataBasedOnContractID($cargoids,"MATERIAL_QUANTITY")."  ".$this->getOpenCargoMasterDataBasedOnContractID($cargoids,"UOM");
	}
}

function getTC_CP_TERMS_Data($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from tc_cp_terms where MAPPINGID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getVesselParameterDataNominationWise($comid,$vessel_id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from commercial_parameters_nomnation_wise where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VESSEL_IMO_ID='".$vessel_id."'";
	$res 	 = mysql_query($sql);
	$rows	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getVesselParticularData($field,$table,$id)
{
	$connect = $this->funConnect();
	
	$sql 	= "select ".$field." from ".$table." where VESSEL_IMO_ID='".$id."'";
	$res 	= mysql_query($sql);
	$rows	= mysql_fetch_assoc($res);
	return $rows[$field];
}


function getStatusTypeList()
{
$state = array( '1' =>'YES' , '2' =>'NO' , '3' =>'N/A');
$selAType = @$_REQUEST['selAType'];

echo '<option value="">---Select from list---</option>';
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selAType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getClaSocList()
{
	$this->funconnect();
	$query = mysql_query("select * from classification_soc_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['CLA_SOC_ID'];
		 $value = $rows['NAME'];
		 echo"<option value = ".$key." " .">";
		 echo " ".$value." " ."</option>" ;
		}
}


function getCertificateList()
{
	$this->funconnect();
	$query = mysql_query("select * from certificate_master where STATUS=1 order by CERTIFICATE ");
	echo '<option value = "0" >---Select from list---</option>';
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CERTIFICATEID'];
		 $value= $rows['CERTIFICATE'];
		 echo"<option value = ".$key." " .">";
		 echo " ".$value." " ."</option>" ;
		}
}


function getCertificateUpdateList($id)
{
	$this->funconnect();
	$query = mysql_query("select * from certificate_master where STATUS=1 order by CERTIFICATE ");
	echo '<option value = "" >---Select from list---</option>';
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CERTIFICATEID'];
		 $value= $rows['CERTIFICATE'];
		 echo "<option value=$key";
		 if($key == $id){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function checkVesselDate($field,$table,$id)
{
	$connect = $this->funConnect();
	$sql     = "select ".$field." from ".$table." where VESSEL_IMO_ID='".$id."'";
	$res     = mysql_query($sql);
	$rows    = mysql_fetch_assoc($res);
	
	if($rows[$field] == "" || $rows[$field] == "1970-01-01" || $rows[$field] == "0000-00-00"){
		return $rows = "";
	}else{	
		return $rows[$field];
	}
}


function getVesselParameterData($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from vessel_commercial_parameters where VESSEL_IMO_ID='".$id."' and MODULEID='".$_SESSION['moduleid']."' ";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function insertNomDetails()
{
 $connect     			= $this->funConnect();
 $comid           	    = $_REQUEST['comid'];
 $fixture_type          = addslashes(trim($_REQUEST['selFixtureType']));
 $charterer          	= addslashes(trim($_REQUEST['txtCharterer']));
 $fri_rate          	= addslashes(trim($_REQUEST['txtFRUsdMT']));
 if($fri_rate == ""){$fri_rate = 0;}
 $cp_ref           		= addslashes(trim($_REQUEST['txtCPRef']));
 $cp_date          		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
 $laycan_starts         = date("Y-m-d",strtotime($_REQUEST['txtDPLayCanStarts']));
 $laycan_finish         = date("Y-m-d",strtotime($_REQUEST['txtDPLayCanFinishes']));
 $dod           		= date("Y-m-d",strtotime($_REQUEST['txtDateofDelivery']));
 $pod              		= addslashes(trim($_REQUEST['txtPOD']));
 $alarm              	= addslashes(trim($_REQUEST['txtAlarm']));
 if($alarm == ""){$alarm = 0;}
 $broker              	= addslashes(trim($_REQUEST['txtBroker']));
  
 $msg = 0;
 mysql_query("Set Autocommit=0");
 mysql_query("START TRANSACTION");

 $sql = "select * from nom_details where COMID='".$comid."'";
 $res = mysql_query($sql) or die($sql);
 $rec = mysql_num_rows($res);
 if($rec == 0)
 {
  //insert query.......
  $sql1 = "insert into nom_details (COMID, FIXTURETYPE_ID, CHARTERER, FREIGHT_RATE, CP_REF, CP_DATE, LAYCAN_STARTS, LAYCAN_FINISHES, ALARM, DATE_OF_DELIVERY, PLACE_OF_DELIVERY, BROKER) values ('".$comid."','".$fixture_type."','".$charterer."','".$fri_rate."','".$cp_ref."','".$cp_date."','".$laycan_starts."','".$laycan_finish."','".$alarm."','".$dod."','".$pod."','".$broker."')";
  mysql_query($sql1) or die($sql1);
  mysql_query("commit");
 }else{
  //edit query......
  $sql1 = "update nom_details set FIXTURETYPE_ID='".$fixture_type."',CHARTERER='".$charterer."',FREIGHT_RATE='".$fri_rate."',CP_REF='".$cp_ref."',CP_DATE='".$cp_date."',LAYCAN_STARTS='".$laycan_starts."',LAYCAN_FINISHES='".$laycan_finish."',ALARM='".$alarm."',DATE_OF_DELIVERY='".$dod."',PLACE_OF_DELIVERY='".$pod."',BROKER='".$broker."'  where COMID='".$comid."'";
  mysql_query($sql1) or die($sql1);
  mysql_query("commit");
 }

 return $msg; 
}



function insertTC_CP_TERMS_Details()
{
	$connect = $this->funConnect();
	$comid          	    = $_REQUEST['comid'];
	$cp_wind_force          = addslashes(trim($_REQUEST['txtCPWindForce']));
	$cp_speed_laden	        = addslashes(trim($_REQUEST['txtCPSpeedLaden']));
	$cp_speed_ballast       = addslashes(trim($_REQUEST['txtCPSpeedBallast']));
	$cp_fo_consp_laden      = addslashes(trim($_REQUEST['txtCPFOConspLaden']));
	$cp_do_consp_laden      = addslashes(trim($_REQUEST['txtCPDOConspLaden']));
	$cp_fo_consp_ballast    = addslashes(trim($_REQUEST['txtCPFOConspBallast']));
	$cp_do_consp_ballast    = addslashes(trim($_REQUEST['txtCPDOConspBallast']));
	$cp_fo_tk_cleaning      = addslashes(trim($_REQUEST['txtCPFOTkCleaning']));
	$cp_fo_gas_freeing      = addslashes(trim($_REQUEST['txtCPFOGasFreeing']));
	$cp_fo_inserting        = addslashes(trim($_REQUEST['txtCPFOInerting']));
	$cp_fo_cargo_heating    = addslashes(trim($_REQUEST['txtCPFOCargoHeating']));
	$cp_do_tk_cleaning      = addslashes(trim($_REQUEST['txtCPDOTkCleaning']));
	$cp_do_gas_freeing      = addslashes(trim($_REQUEST['txtCPDOGasFreeing']));
	$cp_do_inserting        = addslashes(trim($_REQUEST['txtCPDOInerting']));
	$cp_do_cargo_heating    = addslashes(trim($_REQUEST['txtCPDOCargoHeating']));
	
	$cp_man_pressure        = addslashes(trim($_REQUEST['txtCPManPressure']));
	$cp_load_rate           = addslashes(trim($_REQUEST['txtCPLoadRate']));
	$cp_disch_rate	        = addslashes(trim($_REQUEST['txtCPDischRate']));
	$cp_fo_consp_loading    = addslashes(trim($_REQUEST['txtCPFOConspLoading']));
	$cp_do_consp_loading    = addslashes(trim($_REQUEST['txtCPDOConspLoading']));
	$cp_fo_consp_disch      = addslashes(trim($_REQUEST['txtCPFOConspDisch']));
	$cp_do_consp_disch      = addslashes(trim($_REQUEST['txtCPDOConspDisch']));
	$cp_fo_consp_idling     = addslashes(trim($_REQUEST['txtCPFOConspIdling']));
	
	$txtSpeedAllowances     = addslashes(trim($_REQUEST['txtSpeedAllowances']));
	$txtCPDOConspIdling     = addslashes(trim($_REQUEST['txtCPDOConspIdling']));
	$txtCPLoadRate_1     	= addslashes(trim($_REQUEST['txtCPLoadRate_1']));
	$txtDischRate_1     	= addslashes(trim($_REQUEST['txtDischRate_1']));
	
	
	if($cp_wind_force == ""){$cp_wind_force1 = 0;}else{$cp_wind_force1 = $cp_wind_force;}
	if($cp_speed_laden == ""){$cp_speed_laden1 = 0;}else{$cp_speed_laden1 = $cp_speed_laden;}
	if($cp_speed_ballast == ""){$cp_speed_ballast1 = 0;}else{$cp_speed_ballast1 = $cp_speed_ballast;}
	if($cp_fo_consp_laden == ""){$cp_fo_consp_laden1 = 0;}else{$cp_fo_consp_laden1 = $cp_fo_consp_laden;}
	if($cp_do_consp_laden == ""){$cp_do_consp_laden1 = 0;}else{$cp_do_consp_laden1 = $cp_do_consp_laden;}
	if($cp_fo_consp_ballast == ""){$cp_fo_consp_ballast1 = 0;}else{$cp_fo_consp_ballast1 = $cp_fo_consp_ballast;}
	if($cp_do_consp_ballast == ""){$cp_do_consp_ballast1 = 0;}else{$cp_do_consp_ballast1 = $cp_do_consp_ballast;}
	if($cp_fo_tk_cleaning == ""){$cp_fo_tk_cleaning1 = 0;}else{$cp_fo_tk_cleaning1 = $cp_fo_tk_cleaning;}
	if($cp_fo_gas_freeing == ""){$cp_fo_gas_freeing1 = 0;}else{$cp_fo_gas_freeing1 = $cp_fo_gas_freeing;}
	if($cp_fo_inserting == ""){$cp_fo_inserting1 = 0;}else{$cp_fo_inserting1 = $cp_fo_inserting;}
	if($cp_fo_cargo_heating == ""){$cp_fo_cargo_heating1 = 0;}else{$cp_fo_cargo_heating1 = $cp_fo_cargo_heating;}
	if($cp_do_tk_cleaning == ""){$cp_do_tk_cleaning1 = 0;}else{$cp_do_tk_cleaning1 = $cp_do_tk_cleaning;}
	if($cp_do_gas_freeing == ""){$cp_do_gas_freeing1 = 0;}else{$cp_do_gas_freeing1 = $cp_do_gas_freeing;}
	if($cp_do_inserting == ""){$cp_do_inserting1 = 0;}else{$cp_do_inserting1 = $cp_do_inserting;}
	if($cp_do_cargo_heating == ""){$cp_do_cargo_heating1 = 0;}else{$cp_do_cargo_heating1 = $cp_do_cargo_heating;}
	

	if($cp_man_pressure == ""){$cp_man_pressure1 = 0;}else{$cp_man_pressure1 = $cp_man_pressure;}
	if($cp_load_rate == ""){$cp_load_rate1 = 0;}else{$cp_load_rate1 = $cp_load_rate;}
	if($cp_disch_rate == ""){$cp_disch_rate1 = 0;}else{$cp_disch_rate1 = $cp_disch_rate;}
	if($cp_fo_consp_loading == ""){$cp_fo_consp_loading1 = 0;}else{$cp_fo_consp_loading1 = $cp_fo_consp_loading;}
	if($cp_do_consp_loading == ""){$cp_do_consp_loading1 = 0;}else{$cp_do_consp_loading1 = $cp_do_consp_loading;}
	if($cp_fo_consp_disch == ""){$cp_fo_consp_disch1 = 0;}else{$cp_fo_consp_disch1 = $cp_fo_consp_disch;}
	if($cp_do_consp_disch == ""){$cp_do_consp_disch1 = 0;}else{$cp_do_consp_disch1 = $cp_do_consp_disch;}
	if($cp_fo_consp_idling == ""){$cp_fo_consp_idling1 = 0;}else{$cp_fo_consp_idling1 = $cp_fo_consp_idling;}
	
	if($txtSpeedAllowances == ""){$txtSpeedAllowances1 = 0;}else{$txtSpeedAllowances1 = $txtSpeedAllowances;}
	if($txtCPDOConspIdling == ""){$txtCPDOConspIdling1 = 0;}else{$txtCPDOConspIdling1 = $txtCPDOConspIdling;}
	if($txtCPLoadRate_1 == ""){$txtCPLoadRate_11 = 0;}else{$txtCPLoadRate_11 = $txtCPLoadRate_1;}
	if($txtDischRate_1 == ""){$txtDischRate_11 = 0;}else{$txtDischRate_11 = $txtDischRate_1;}
	
		
		
	$msg = 1;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	$sql = "select * from tc_cp_terms where MAPPINGID='".$mappingid."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		//insert query.......
		$sql1 = "insert into tc_cp_terms (COMID, CP_WIND_FORCE, CP_SPEED_LADEN, CP_SPEED_BALLAST ,CP_FO_CONSP_LADEN, CP_DO_CONSP_LADEN, CP_FO_CONSP_BALLAST, CP_DO_CONSP_BALLAST, CP_FO_TK_CLEANING, CP_FO_GAS_FREEING, CP_FO_INSERTING, CP_FO_CARGO_HEATING, CP_DO_TK_CLEANING, CP_DO_GAS_FREEING ,CP_DO_INSERTING, CP_DO_CARGO_HEATING, CP_MAN_PRESSURE, CP_LOAD_RATE, CP_DISCH_RATE, CP_FO_CONSP_LOADING, CP_DO_CONSP_LOADING,CP_FO_CONSP_DISCH,CP_DO_CONSP_DISCH,CP_FO_CONSP_IDLING,CP_SPEED_ALLOWANCES,CP_LOAD_RATE_1,CP_DISCH_RATE_1,CP_DO_CONSP_IDLING) values ('".$comid."','".$cp_wind_force1."','".$cp_speed_laden1."','".$cp_speed_ballast1."','".$cp_fo_consp_laden1."','".$cp_do_consp_laden1."','".$cp_fo_consp_ballast1."','".$cp_do_consp_ballast1."','".$cp_fo_tk_cleaning1."','".$cp_fo_gas_freeing1."','".$cp_fo_inserting1."','".$cp_fo_cargo_heating1."','".$cp_do_tk_cleaning1."','".$cp_do_gas_freeing1."','".$cp_do_inserting1."','".$cp_do_cargo_heating1."','".$cp_man_pressure1."','".$cp_load_rate1."','".$cp_disch_rate1."','".$cp_fo_consp_loading1."','".$cp_do_consp_loading1."','".$cp_fo_consp_disch1."','".$cp_do_consp_disch1."','".$cp_fo_consp_idling1."','".$txtSpeedAllowances1."','".$txtCPLoadRate_11."','".$txtDischRate_11."','".$txtCPDOConspIdling1."')";
		
		mysql_query($sql1);
		mysql_query("commit");
	}
	else
	{
		//edit query......
		$sql1 = "update tc_cp_terms set CP_WIND_FORCE='".$cp_wind_force1."',CP_SPEED_LADEN='".$cp_speed_laden1."',CP_SPEED_BALLAST='".$cp_speed_ballast1."',CP_FO_CONSP_LADEN='".$cp_fo_consp_laden1."',CP_DO_CONSP_LADEN='".$cp_do_consp_laden1."',CP_FO_CONSP_BALLAST='".$cp_fo_consp_ballast1."',CP_DO_CONSP_BALLAST='".$cp_do_consp_ballast1."',CP_FO_TK_CLEANING='".$cp_fo_tk_cleaning1."',CP_FO_GAS_FREEING='".$cp_fo_gas_freeing1."',CP_FO_INSERTING='".$cp_fo_inserting1."',CP_FO_CARGO_HEATING='".$cp_fo_cargo_heating1."',CP_DO_TK_CLEANING='".$cp_do_tk_cleaning1."',CP_DO_GAS_FREEING= '".$cp_do_gas_freeing1."',CP_DO_INSERTING='".$cp_do_inserting1."',CP_DO_CARGO_HEATING='".$cp_do_cargo_heating1."',CP_MAN_PRESSURE='".$cp_man_pressure1."',CP_LOAD_RATE='".$cp_load_rate1."',CP_DISCH_RATE='".$cp_disch_rate1."',CP_FO_CONSP_LOADING='".$cp_fo_consp_loading1."',CP_DO_CONSP_LOADING='".$cp_do_consp_loading1."',CP_FO_CONSP_DISCH='".$cp_fo_consp_disch1."',CP_DO_CONSP_DISCH='".$cp_do_consp_disch1."',CP_FO_CONSP_IDLING='".$cp_fo_consp_idling1."',CP_SPEED_ALLOWANCES='".$txtSpeedAllowances1."',CP_LOAD_RATE_1='".$txtCPLoadRate_11."',CP_DISCH_RATE_1='".$txtDischRate_11."',CP_DO_CONSP_IDLING='".$txtCPDOConspIdling1."'      where COMID='".$comid."'";
		mysql_query($sql1);
		mysql_query("commit");
	}
	return $msg; 
}



function insertVesselCommercialParametersDetailsNominationWise($submitid)
{

	$connect 				= $this->funConnect();
	$comid 				    = $_REQUEST['comid'];
	$vessel_id 				= $_REQUEST['vessel_id'];
	
	$date					= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	
	$b_full_speed 			= addslashes(trim($_REQUEST['txtBFullSpeed']));
	if($b_full_speed == ""){$b_full_speed = 0;}
	$b_eco_speed1			= addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	if($b_eco_speed1 == ""){$b_eco_speed1 = 0;}
	$b_eco_speed2			= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	if($b_eco_speed2 == ""){$b_eco_speed2 = 0;}
	$l_full_speed			= addslashes(trim($_REQUEST['txtLFullSpeed']));
	if($l_full_speed == ""){$l_full_speed = 0;}
	$l_eco_speed1			= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	if($l_eco_speed1 == ""){$l_eco_speed1 = 0;}
	$l_eco_speed2			= addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	if($l_eco_speed2 == ""){$l_eco_speed2 = 0;}
	$bp_fo_fs				= addslashes(trim($_REQUEST['txtFOBPassageFS']));
	if($bp_fo_fs == ""){$bp_fo_fs = 0;}
	$bp_fo_es1				= addslashes(trim($_REQUEST['txtFOBPassageES1']));
	if($bp_fo_es1 == ""){$bp_fo_es1 = 0;}
	$bp_fo_es2				= addslashes(trim($_REQUEST['txtFOBPassageES2']));
	if($bp_fo_es2 == ""){$bp_fo_es2 = 0;}
	$lp_fo_fs				= addslashes(trim($_REQUEST['txtFOLPassageFS']));
	if($lp_fo_fs == ""){$lp_fo_fs = 0;}
	$lp_fo_es1				= addslashes(trim($_REQUEST['txtFOLPassageES1']));
	if($lp_fo_es1 == ""){$lp_fo_es1 = 0;}
	$lp_fo_es2				= addslashes(trim($_REQUEST['txtFOLPassageES2']));
	if($lp_fo_es2 == ""){$lp_fo_es2 = 0;}
	$pi_fo_fs				= addslashes(trim($_REQUEST['txtFOIPIdleFS']));
	if($pi_fo_fs == ""){$pi_fo_fs = 0;}
	$pw_fo_fs				= addslashes(trim($_REQUEST['txtFOIPWorkingFS']));
	if($pw_fo_fs == ""){$pw_fo_fs = 0;}
	$oth_fo_fs				= addslashes(trim($_REQUEST['txtFOOthersFS']));
	if($oth_fo_fs == ""){$oth_fo_fs = 0;}
	$bp_do_fs				= addslashes(trim($_REQUEST['txtDOBPassageFS']));
	if($bp_do_fs == ""){$bp_do_fs = 0;}
	$bp_do_es1				= addslashes(trim($_REQUEST['txtDOBPassageES1']));
	if($bp_do_es1 == ""){$bp_do_es1 = 0;}
	$bp_do_es2				= addslashes(trim($_REQUEST['txtDOBPassageES2']));
	if($bp_do_es2 == ""){$bp_do_es2 = 0;}
	$lp_do_fs				= addslashes(trim($_REQUEST['txtDOLPassageFS']));
	if($lp_do_fs == ""){$lp_do_fs = 0;}
	$lp_do_es1				= addslashes(trim($_REQUEST['txtDOLPassageES1']));
	if($lp_do_es1 == ""){$lp_do_es1 = 0;}
	$lp_do_es2				= addslashes(trim($_REQUEST['txtDOLPassageES2']));
	if($lp_do_es2 == ""){$lp_do_es2 = 0;}
	$pi_do_fs				= addslashes(trim($_REQUEST['txtDOIPIdleFS']));
	if($pi_do_fs == ""){$pi_do_fs = 0;}
	$pw_do_fs				= addslashes(trim($_REQUEST['txtDOIPWorkingFS']));
	if($pw_do_fs == ""){$pw_do_fs = 0;}
	$oth_do_fs				= addslashes(trim($_REQUEST['txtDOOthersFS']));
	if($oth_do_fs == ""){$oth_do_fs = 0;}
	
	if($pi_fo_es1 == ""){$pi_fo_es1 = 0;}
	if($pi_fo_es2 == ""){$pi_fo_es2 = 0;}
	
	if($pw_fo_es1 == ""){$pw_fo_es1 = 0;}
	if($pw_fo_es2 == ""){$pw_fo_es2 = 0;}
	
	if($oth_fo_es1 == ""){$oth_fo_es1 = 0;}
	if($oth_fo_es2 == ""){$oth_fo_es2 = 0;}
	
	if($pi_do_es1 == ""){$pi_do_es1 = 0;}
	if($pi_do_es2 == ""){$pi_do_es2 = 0;}
	
	if($pw_do_es1 == ""){$pw_do_es1 = 0;}
	if($pw_do_es2 == ""){$pw_do_es2 = 0;}
	
	if($oth_do_es1 == ""){$oth_do_es1 = 0;}
	if($oth_do_es2 == ""){$oth_do_es2 = 0;}
	
	$fo_grade				= addslashes(trim($_REQUEST['txtFOGrade']));
	$do_grade				= addslashes(trim($_REQUEST['txtDOGrade']));
	
	$remarks				= addslashes(trim($_REQUEST['txtRemarks']));
	$msg = 2;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$query = "select * from commercial_parameters_nomnation_wise where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VESSEL_IMO_ID='".$vessel_id."'";
	$res = mysql_query($query) or die($query);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		$sql = "insert into commercial_parameters_nomnation_wise (COMID,MODULEID,MCOMPANYID,VESSEL_IMO_ID,MAIN_DATA_DATE,B_FULL_SPEED,B_ECO_SPEED1,B_ECO_SPEED2,L_FULL_SPEED,L_ECO_SPEED1,L_ECO_SPEED2,BP_FO_FULL_SPEED,BP_FO_ECO_SPEED1,BP_FO_ECO_SPEED2,LP_FO_FULL_SPEED,LP_FO_ECO_SPEED1,LP_FO_ECO_SPEED2,PI_FO_FULL_SPEED,PI_FO_ECO_SPEED1,PI_FO_ECO_SPEED2,PW_FO_FULL_SPEED,PW_FO_ECO_SPEED1,PW_FO_ECO_SPEED2,OTH_FO_FULL_SPEED,OTH_FO_ECO_SPEED1,OTH_FO_ECO_SPEED2,BP_DO_FULL_SPEED,BP_DO_ECO_SPEED1,BP_DO_ECO_SPEED2,LP_DO_FULL_SPEED,LP_DO_ECO_SPEED1,LP_DO_ECO_SPEED2,PI_DO_FULL_SPEED,PI_DO_ECO_SPEED1,PI_DO_ECO_SPEED2,PW_DO_FULL_SPEED,PW_DO_ECO_SPEED1,PW_DO_ECO_SPEED2,OTH_DO_FULL_SPEED,OTH_DO_ECO_SPEED1,OTH_DO_ECO_SPEED2,FO_GRADE,DO_GRADE,SUBMITID,REMARKS) values ('".$comid."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$vessel_id."','".$date."','".$b_full_speed."','".$b_eco_speed1."','".$b_eco_speed2."','".$l_full_speed."','".$l_eco_speed1."','".$l_eco_speed2."','".$bp_fo_fs."','".$bp_fo_es1."','".$bp_fo_es2."','".$lp_fo_fs."','".$lp_fo_es1."','".$lp_fo_es2."','".$pi_fo_fs."','".$pi_fo_es1."','".$pi_fo_es2."','".$pw_fo_fs."','".$pw_fo_es1."','".$pw_fo_es2."','".$oth_fo_fs."','".$oth_fo_es1."','".$oth_fo_es2."','".$bp_do_fs."','".$bp_do_es1."','".$bp_do_es2."','".$lp_do_fs."','".$lp_do_es1."','".$lp_do_es2."','".$pi_do_fs."','".$pi_do_es1."','".$pi_do_es2."','".$pw_do_fs."','".$pw_do_es1."','".$pw_do_es2."','".$oth_do_fs."','".$oth_do_es1."','".$oth_do_es2."','".$fo_grade."','".$do_grade."','".$submitid."','".$remarks."')";	
		mysql_query($sql) or die($sql);
		mysql_query("commit");
	}
	else
	{
		$rows = mysql_fetch_assoc($res);
		$sql = "update commercial_parameters_nomnation_wise set MAIN_DATA_DATE='".$date."',B_FULL_SPEED='".$b_full_speed."',B_ECO_SPEED1='".$b_eco_speed1."',B_ECO_SPEED2='".$b_eco_speed2."',L_FULL_SPEED='".$l_full_speed."',L_ECO_SPEED1='".$l_eco_speed1."',L_ECO_SPEED2='".$l_eco_speed2."',BP_FO_FULL_SPEED='".$bp_fo_fs."',BP_FO_ECO_SPEED1='".$bp_fo_es1."',BP_FO_ECO_SPEED2='".$bp_fo_es2."',LP_FO_FULL_SPEED='".$lp_fo_fs."',LP_FO_ECO_SPEED1='".$lp_fo_es1."',LP_FO_ECO_SPEED2='".$lp_fo_es2."',PI_FO_FULL_SPEED='".$pi_fo_fs."',PI_FO_ECO_SPEED1='".$pi_fo_es1."',PI_FO_ECO_SPEED2='".$pi_fo_es2."',PW_FO_FULL_SPEED='".$pw_fo_fs."',PW_FO_ECO_SPEED1='".$pw_fo_es1."',PW_FO_ECO_SPEED2='".$pw_fo_es2."',OTH_FO_FULL_SPEED='".$oth_fo_fs."',OTH_FO_ECO_SPEED1='".$oth_fo_es1."',OTH_FO_ECO_SPEED2='".$oth_fo_es2."',BP_DO_FULL_SPEED='".$bp_do_fs."',BP_DO_ECO_SPEED1='".$bp_do_es1."',BP_DO_ECO_SPEED2='".$bp_do_es2."',LP_DO_FULL_SPEED='".$lp_do_fs."',LP_DO_ECO_SPEED1='".$lp_do_es1."',LP_DO_ECO_SPEED2='".$lp_do_es2."',PI_DO_FULL_SPEED='".$pi_do_fs."',PI_DO_ECO_SPEED1='".$pi_do_es1."',PI_DO_ECO_SPEED2='".$pi_do_es2."',PW_DO_FULL_SPEED='".$pw_do_fs."',PW_DO_ECO_SPEED1='".$pw_do_es1."',PW_DO_ECO_SPEED2='".$pw_do_es2."',OTH_DO_FULL_SPEED='".$oth_do_fs."',OTH_DO_ECO_SPEED1='".$oth_do_es1."',OTH_DO_ECO_SPEED2='".$oth_do_es2."',FO_GRADE='".$fo_grade."',DO_GRADE='".$do_grade."',SUBMITID='".$submitid."',REMARKS='".$remarks."'  where CP_NOMID='".$rows['CP_NOMID']."' ";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
	}
	return $msg; 
}



function deletePdfDetails($comid,$file_name)
{
	$connect				= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;	
	$sql = "delete from cp_pdf_details where COMID='".$comid."' and FILE_NAME='".$file_name."'";
	mysql_query($sql) or die($sql);	
	mysql_query("commit");	 
	return $msg;
}



function displayCostSheetList($mappingid,$page)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
    echo '<table id="cost_sheet_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle">#</th>';
	echo '<th align="left" valign="middle">Voyage Financials Name</th>';
	echo '<th align="center" valign="middle">Voyage Financials View</th>';
	echo '<th align="center" valign="middle">Finalize Voyage Financials</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from freight_cost_analysis_master where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
		{
				$this->id = $rows['FCAID'];
				echo '<tr>';
				echo '<td align="center" valign="middle">'.$i.'.</td>';
				echo '<td align="left" valign="middle">'.$rows['ESTIMATION_NO'].'</td>';
				if($rows['FINAL_STATUS'] == 0){
					echo '<td align="center" valign="middle"><a href="#" onClick="msg();">View</a></td>';
				}else{
				echo '<td align="center" valign="middle"><a href="./view_cost_sheet.php?mappingid='.$mappingid.'&cost_sheet_id='.$rows['SHEET_NO'].'&page='.$page.'">View</a></td>';
				}
				if($this->getFinalCostSheetDataRec($mappingid) == 0){
				echo '<td align="center" valign="middle"><input name="rdoFCA" class="checkbox" id="rdoFCA_'.$rows['SHEET_NO'].'" type="radio" style="cursor:pointer;" value="'.$rows['SHEET_NO'].'" /></td>';
				}
				else
				{
					if($rows['FINAL_STATUS'] == 0){$value = "Not - Confirmed";}else if($rows['FINAL_STATUS'] == 1){$value = "Confirmed";}
					echo '<td align="center" valign="middle" class="input-text">'.$value.'</td>';
				}
				echo '</tr>';
				$i++;
		}
		echo '<tr>';
		
			$uid	  = $_SESSION['uid'];
			$moduleid = $_SESSION['moduleid'];
			
			if($page == 1)
			{
				$linkid = 4;
			}
			else
			{
				$linkid = 5;
			}
			
			$rights = $this->getUserRights($uid,$moduleid,$linkid);
		
			echo '<td align="right" colspan="4" valign="middle" >';
			 if($rights == 1){ 
				if($this->getFinalCostSheetDataRec($mappingid) == 0){
					echo '<button class="btn btn-primary btn-flat" id="inner-login-button" type="submit" onclick="return getValidate();"  ><b><span id="d27e53">Confirm Final Estimated Cost Sheet</span></b></button><input type="hidden" name="action" value="submit" />';
				}}
			echo '</td>';
		echo '</tr>';
	echo '</tbody>';
	}
	echo '</table>';
	echo "</div>";
}

function getPaymentAmtForhireage($id){

	$connect = $this->funConnect();

	$sql = "select * from invoice_hire_master where COMID='".$id."' and P_DATE is not NULL order by date(P_DATE) desc";

	$res = mysql_query($sql);

	$rows = mysql_fetch_assoc($res);

	if($rows){
		return $rows['P_AMT'];
	}
	else{
		return '&nbsp';
	}
}

function getDateForhireage($id){

	$connect = $this->funConnect();

	$sql = "select * from invoice_hire_master where COMID='".$id."' and P_DATE is not NULL order by date(P_DATE) desc";

	$res = mysql_query($sql);

	$rows = mysql_fetch_assoc($res);

	if($rows){
		return $rows['P_DATE'];
	}
	else{
		return '&nbsp';
	}

}



function insertCostSheetName()
{
	$connect = $this->funConnect();
	$file_name          	= $_REQUEST['txtFile'];
	$mappingid              = $_REQUEST['txtMappingid1'];
		
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "insert into cost_sheet_name_master (SHEET_NAME,MAPPINGID,MODULEID,MCOMPANYID,PROCESS) values ('".$file_name."','".$mappingid."','".$_SESSION['moduleid']."','".$_SESSION['company']."','EST')";
	mysql_query($sql1);
	mysql_query("commit");
	return $msg; 
}


function getFreightEstimationStatus1($mappingid)
{
	$connect = $this->funConnect();
	$sql  = "select FIXTURETYPEID from freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$mappingid."' ";
	$res  = mysql_query($sql);
	$rec  = mysql_num_rows($res);
	$rows = mysql_fetch_assoc($res);
	return $rows['FIXTURETYPEID'];
}




function insertVCIDetails()
{
	$connect = $this->funConnect();
	$mappingid          = $_REQUEST['mappingid'];
	$cost_sheet_id      = $_REQUEST['cost_sheet_id'];
	
	$fixture_type 		= addslashes(trim($_REQUEST['selFType']));
	$estmation_no 		= addslashes(trim($_REQUEST['txtENo']));
	$cap_rdo	 		= addslashes(trim($_REQUEST['rdoCap']));
	$grain_cap	 		= addslashes(trim($_REQUEST['txtGCap']));
	$bale_cap	 		= addslashes(trim($_REQUEST['txtBCap']));
	$sf			 		= addslashes(trim($_REQUEST['txtSF']));
	$voyage_no	 		= addslashes(trim($_REQUEST['txtVNo']));
	$tc_no		 		= addslashes(trim($_REQUEST['txtTCNo']));
	$market_rdo 		= addslashes(trim($_REQUEST['rdoMMarket']));
	$cost_usd_mt 		= addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$lumpsum	 		= addslashes(trim($_REQUEST['txtMLumpsum']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$cargo_qty	 		= addslashes(trim($_REQUEST['txtCQMT']));
	$cargo_type_id 		= addslashes(trim($_REQUEST['selCType']));
	$voyage_status 		= addslashes(trim($_REQUEST['selVType']));
	
	$ttl_voyage_time	= addslashes(trim($_REQUEST['txtVoyageTime']));
	$ttl_voyage_days	= addslashes(trim($_REQUEST['txtTTLVoyageDays']));
	$ttl_fo_consp 		= addslashes(trim($_REQUEST['txtTTLFoConsp']));
	$ttl_do_consp 		= addslashes(trim($_REQUEST['txtTTLDoConsp']));
	
	$dwt_rdo	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$summer_dwt	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$tropical_dwt 		= addslashes(trim($_REQUEST['txtDWTT']));
	
	$addnl_rate 		= addslashes(trim($_REQUEST['txtAddnlCRate']));
	$actual_qty 		= addslashes(trim($_REQUEST['txtAQMT']));
	$df_qty		 		= addslashes(trim($_REQUEST['txtDFQMT']));
	$addnl_qty	 		= addslashes(trim($_REQUEST['txtAddnlQMT']));
	
	$loadable	 		= addslashes(trim($_REQUEST['txtLoadable']));
	
	$date 				= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$rdoQty 			= addslashes(trim($_REQUEST['rdoQty']));
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION"); 
	
	$query = "select (MAX(CAST(PROCESSID AS int)) + 1) as max from freight_cost_analysis_master where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	$qres = mysql_query($query);
	$qrows = mysql_fetch_assoc($qres);
	
	//insert query here.............
	$sql = "insert into freight_cost_analysis_master (FIXTURETYPEID,TRANS_DATE,MODULEID,MCOMPANYID,MAPPINGID,VOY_EST_STATUS,PROCESSID,ESTIMATION_NO,CAP_RDO,GRAIN_CAP,BALE_CAP,SF,VOYAGE_NO,TC_NO,MARKET_RDO,COST_USD_MT,LUMPSUM,CARGO_QTY,CARGO_TYPEID,TTL_VOYAGE_TIME,TTL_VOYAGE_DAYS,TTL_FO_CONSP,TTL_DO_CONSP,DWT_RDO,SUMMER_DWT,TROPICAL_DWT,LOADABLE,SHEET_NO,ADDNL_CARGO_RATE,ACTUAL_QTY,DF_QTY,ADDNL_QTY,RDO_QTY) values ('".$fixture_type."','".$date."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$mappingid."','".$voyage_status."','".$qrows['max']."','".$estmation_no."','".$cap_rdo."','".$grain_cap."','".$bale_cap."','".$sf."','".$voyage_no."','".$tc_no."','".$market_rdo."','".$cost_usd_mt."','".$lumpsum."','".$cargo_qty."','".$cargo_type_id."','".$ttl_voyage_time."','".$ttl_voyage_days."','".$ttl_fo_consp."','".$ttl_do_consp."','".$dwt_rdo."','".$summer_dwt."','".$tropical_dwt."','".$loadable."','".$cost_sheet_id."','".$addnl_rate."','".$actual_qty."','".$df_qty."','".$addnl_qty."','".$rdoQty."')";
	
	mysql_query($sql);
	mysql_query("commit");
	
	$mysql = "select max(FCAID) as max from freight_cost_analysis_master";
	$myres  =  mysql_query($mysql);
	$myrows = mysql_fetch_assoc($myres);
	$maxid = $myrows['max'];
	
		
	for($i=1; $i<= $_REQUEST['load_portID']; $i++)
	{
		if(isset($_REQUEST['txtLoadPort_'.$i]))
		{
			$sql2 = "insert into fca_vci_load_port (FCAID,LOADPORTID,PURCHASE_ALLOCATIONID,QTY_MT,RATE,WORK_DAYS,PORTCOSTS) values ('".$maxid."','".$_REQUEST['txtLoadPort_'.$i]."','".$_REQUEST['txtLPCID_'.$i]."','".$_REQUEST['txtLpQMT_'.$i]."','".$_REQUEST['txtLpRate_'.$i]."','".$_REQUEST['txtLpBLWorkDays_'.$i]."','".$_REQUEST['txtLPPCosts_'.$i]."')";	
			mysql_query($sql2);
			mysql_query("commit");
			
			$query1 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT) values ('".$maxid."','Load', '".$_REQUEST['txtLoadPort_'.$i]."','".$_REQUEST['txtLPOSCCost_'.$i]."','".$_REQUEST['txtLPOSCCostMT_'.$i]."')";
			mysql_query($query1);
			mysql_query("commit");
			
			$sql9 = "insert into fca_vci_shipowner (FCAID,PORT,LOADPORTID,COST,COST_MT) values ('".$maxid."','Load', '".$_REQUEST['txtLoadPort_'.$i]."','".$_REQUEST['txtddswLPCost_'.$i]."','".$_REQUEST['txtddswLPCostMT_'.$i]."')";
			mysql_query($sql9);
			mysql_query("commit");
			
			$sql11 = "insert into fca_vci_dd_shipper (FCAID,LOADPORTID,COST,COST_MT) values ('".$maxid."' , '".$_REQUEST['txtLoadPort_'.$i]."','".$_REQUEST['txtddshipLPCost_'.$i]."','".$_REQUEST['txtddshipLPCostMT_'.$i]."')";
			mysql_query($sql11);
			mysql_query("commit");
		}
	}
	
	for($i=1; $i<= $_REQUEST['dis_portID']; $i++)
	{
		if(isset($_REQUEST['txtDisPort_'.$i]))
		{
			$sql3 = "insert into fca_vci_disch_port (FCAID,DIS_PORT_ID,PURCHASE_ALLOCID,QTY_MT,RATE,WORK_DAYS,PORTCOSTS) values ('".$maxid."','".$_REQUEST['txtDisPort_'.$i]."','".$_REQUEST['txtDPCID_'.$i]."','".$_REQUEST['txtDpQMT_'.$i]."','".$_REQUEST['txtDpRate_'.$i]."','".$_REQUEST['txtDpBLWorkDays_'.$i]."','".$_REQUEST['txtDPPCosts_'.$i]."')";	
			mysql_query($sql3);
			mysql_query("commit");
			
			$query2 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT) values ('".$maxid."','Discharge' , '".$_REQUEST['txtDisPort_'.$i]."','".$_REQUEST['txtDPOSCCost_'.$i]."','".$_REQUEST['txtDPOSCCostMT_'.$i]."')";
			mysql_query($query2);
			mysql_query("commit");
			
			$sql10 = "insert into fca_vci_shipowner (FCAID,PORT,LOADPORTID,COST,COST_MT) values ('".$maxid."','Discharge' , '".$_REQUEST['txtDisPort_'.$i]."','".$_REQUEST['txtddswDPCost_'.$i]."','".$_REQUEST['txtddswDPCostMT_'.$i]."')";
			mysql_query($sql10);
			mysql_query("commit");
				
			$sql12 = "insert into fca_vci_dd_receiver (FCAID,LOADPORTID,COST,COST_MT) values ('".$maxid."' , '".$_REQUEST['txtDisPort_'.$i]."','".$_REQUEST['txtDDReceiDPCost_'.$i]."','".$_REQUEST['txtDDReceiDPCostMT_'.$i]."')";
			mysql_query($sql12);
			mysql_query("commit");
		}
	}
	
		
		$sql4 = "insert into fca_vci_totals (FCAID,GROSS_FREIGHT_USD,GROSS_FREIGHT_PERMT,DEAD_FREIGHT_USD,DEAD_FREIGHT_PERMT,ADDNL_FREIGHT_USD,ADDNL_FREIGHT_PERMT,TTL_FREIGHT_USD,TTL_FREIGHT_PERMT,AC_PERCENT,AC_USD,AC_PERMT,AGC_PERCENT,AGC_USD,NETT_FRT_PAYABLE,FREIGHT_PAYMENT,ORC_VENDOR,ORC_COSTMT,DDNR_LP_COST,DDNR_LP_COSTMT,DDNR_DP_COST,DDNR_DP_COSTMT,TTL_SHIPPING_COST,TTL_SHIPPING_COSTMT,TTL_PORT_COSTS,TTL_PORT_COSTS_MT) values ('".$maxid."','".$_REQUEST['txtFrAdjUsdGF']."','".$_REQUEST['txtFrAdjUsdGFMT']."','".$_REQUEST['txtFrAdjUsdDF']."','".$_REQUEST['txtFrAdjUsdDFMT']."','".$_REQUEST['txtFrAdjUsdAF']."','".$_REQUEST['txtFrAdjUsdAFMT']."','".$_REQUEST['txtFrAdjUsdTF']."','".$_REQUEST['txtFrAdjUsdTFMT']."','".$_REQUEST['txtFrAdjPerAC']."','".$_REQUEST['txtFrAdjUsdAC']."','".$_REQUEST['txtFrAdjUsdACMT']."','".$_REQUEST['txtFrAdjPerAgC']."','".$_REQUEST['txtFrAdjUsdAgC']."','".$_REQUEST['txtFrAdjUsdFP']."','".$_REQUEST['txtTTLORCFP']."','".$_REQUEST['selORCVList']."','".$_REQUEST['txtTTLORCFPCostMT']."','".$_REQUEST['txtDDNRLPCost']."','".$_REQUEST['txtDDNRLPCostMT']."','".$_REQUEST['txtDDNRDPCost']."','".$_REQUEST['txtDDNRDPCostMT']."','".$_REQUEST['txtTTLShippingCost']."','".$_REQUEST['txtTTLShippingCostMT']."','".$_REQUEST['txtTTLPortCosts']."','".$_REQUEST['txtTTLPortCostsMT']."')";	
		mysql_query($sql4);
		mysql_query("commit");
		
		
		$aosc_id = $_REQUEST['txtAOSC_id'];
		for($i=1;$i<=$aosc_id;$i++)
		{
			$sql7 = "insert into fca_vci_other_shipping_cost (FCAID,OTHER_SCOSTID,ABSOLUTE,VENDORID,COST_MT) values ('".$maxid."' , '".$_REQUEST['txtHidOSCID_'.$i]."','".$_REQUEST['txtOSCAbs_'.$i]."','".$_REQUEST['selOSCVList_'.$i]."','".$_REQUEST['txtOSCCostMT_'.$i]."')";
			mysql_query($sql7);
			mysql_query("commit");
		}
		
		
		$aomc_id = $_REQUEST['txtAOMC_id'];
		for($i=1;$i<=$aomc_id;$i++)
		{
			$sql8 = "insert into fca_vci_other_misc_cost (FCAID,OTHER_MCOSTID,AMOUNT,VENDORID,COST_MT) values ('".$maxid."' , '".$_REQUEST['txtHidOMCID_'.$i]."','".$_REQUEST['txtOMCAbs_'.$i]."','".$_REQUEST['selOMCVList_'.$i]."','".$_REQUEST['txtOMCCostMT_'.$i]."')";
			mysql_query($sql8);
			mysql_query("commit");
		}
	return $msg; 
}



function getLastCostSheetID($mappingid)
{
	$connect				= $this->funConnect();
	$sql = "select SHEET_NO from freight_cost_analysis_master where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$val = 0;
	while($rows = mysql_fetch_assoc($res))
	{
		$val = $rows['SHEET_NO'];
	}
	return $val;
}




function getFreightFixtureBasedOnID($id)
{
	if($id == 1){return "Time Charter In";}
	if($id == 2){return "VC Out";}
}


function getCostSheetNameBasedOnID($id)
{
	$connect    = $this->funConnect();
	$sql        = "select SHEET_NAME from cost_sheet_name_master where COST_SHEETID='".$id."'";
	$res        = mysql_query($sql);
	$rows       = mysql_fetch_assoc($res);
	return $rows['SHEET_NAME'];
}


function getVesselMaster1Data($id,$field)
{
	$connect = $this->funConnect();
	$sql   	 = "SELECT ".$field." FROM vessel_master_1 where VESSEL_IMO_ID='".$id."'";
	$res     = mysql_query($sql);
	$rows    = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getVesselMaster2Data($id,$field)
{
	$connect = $this->funConnect();
	$sql   	 = "SELECT ".$field." FROM vessel_master_2 where VESSEL_IMO_ID='".$id."'";
	$res     = mysql_query($sql);
	$rows    = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getVesselMaster8Data($id,$field)
{
	$connect = $this->funConnect();
	$sql="SELECT ".$field." FROM vessel_master_8 where VESSEL_IMO_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}



function getGreaterCargoQuantity($cargo_possition,$cargoids)
{
	$connect 				= $this->funConnect();
	if($cargo_possition == "open")
	{
		$value = $this->getOpenCargoMasterDataBasedOnContractID($cargoids,"MATERIAL_QUANTITY");
		return $value;
	}
}	


function getContractIdBasedOnIDList($cargo_possition,$cargoids)
{
	$connect = $this->funConnect();
	echo "<option value=''>--Select from list--</option>";
	if($cargo_possition == "open")
	{
		//$value = $this->getMaterialCodeDesBasedOnCode($this->getOpenCargoMasterDataBasedOnContractID($cargoids,"MATERIAL_CODE"))." (".$cargoids.")";
		$value = $this->getMaterialCodeDesBasedOnCode($this->getOpenCargoMasterDataBasedOnContractID($cargoids,"MATERIAL_CODE"))." ";
		$key = $cargoids;
		echo "<option value=$key";
		echo ">".$value."</option>";
	}
}


function getFreightEstimationTotalVCIRecords($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from fca_vci_totals where FCAID='".$id."'";
	$result = mysql_query($sql);
	$rows = mysql_fetch_assoc($result);
	return $rows[$field];
}


function getOtherShippingCostNameBasedOnID($id)
{
	$connect				= $this->funConnect();
	$sql = "select * from other_shipping_cost_master where OTHER_SCOSTID='".$id."' and MODULEID='".$_SESSION['moduleid']."'"; /*AND MCOMPANYID='".$_SESSION['company']."'";*/
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}


function getVoyageType()
{
$state = array( 1 =>'Open' , 2 =>'Complete');
$selVType = @$_REQUEST['selVType'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selVType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}






function updateVesselChapterTwoMaster(){
	
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;
	
	
	$sql12 = "delete from vessel_master_2 where VESSEL_IMO_ID=".$id;
	mysql_query($sql12);
	
	
	$DOLSS = date("Y-m-d",strtotime($_REQUEST['txtDOLSS']));
	
	if(($_REQUEST['txtDOLSS']) == ""){
		$DOLSS1 = "1970-01-01";
	}else{
		$DOLSS1 = $DOLSS;
	}
	
	$DOLAS = date("Y-m-d",strtotime($_REQUEST['txtDOLAS']));
	
	if(($_REQUEST['txtDOLAS']) == ""){
		$DOLAS1 = "1970-01-01";
	}else{
		$DOLAS1 = $DOLAS;
	}

	$DOLI = date("Y-m-d",strtotime($_REQUEST['txtDOLI']));
	
	if(($_REQUEST['txtDOLI']) == ""){
		$DOLI1 = "1970-01-01";
	}else{
		$DOLI1 = $DOLI;
	}
	
	$DONI = date("Y-m-d",strtotime($_REQUEST['txtDONI']));
	
	if(($_REQUEST['txtDONI']) == ""){
		$DONI1 = "1970-01-01";
	}else{
		$DONI1 = $DONI;
	}
	
	$Date_Dry = date("Y-m-d",strtotime($_REQUEST['txtDate_Dry']));
	
	if(($_REQUEST['txtDate_Dry']) == ""){
		$Date_Dry1 = "1970-01-01";
	}else{
		$Date_Dry1 = $Date_Dry;
	}
	
	$LAST_AUDIT = date("Y-m-d",strtotime($_REQUEST['txtLAST_AUDIT']));
	
	if(($_REQUEST['txtLAST_AUDIT']) == ""){
		$LAST_AUDIT1 = "1970-01-01";
	}else{
		$LAST_AUDIT1 = $LAST_AUDIT;
	}
	
	$NEXT_AUDIT = date("Y-m-d",strtotime($_REQUEST['txtNEXT_AUDIT']));
	
	if(($_REQUEST['txtNEXT_AUDIT']) == ""){
		$NEXT_AUDIT1 = "1970-01-01";
	}else{
		$NEXT_AUDIT1 = $NEXT_AUDIT;
	}
	
	$ADVISE_DATE = date("Y-m-d",strtotime($_REQUEST['txtADVISE_DATE']));
	
	if(($_REQUEST['txtADVISE_DATE']) == ""){
		$ADVISE_DATE1 = "1970-01-01";
	}else{
		$ADVISE_DATE1 = $ADVISE_DATE;
	}
	
	$DATE_SMC = date("Y-m-d",strtotime($_REQUEST['txtDATE_SMC']));
	
	if(($_REQUEST['txtDATE_SMC']) == ""){
		$DATE_SMC1 = "1970-01-01";
	}else{
		$DATE_SMC1 = $DATE_SMC;
	}
	
	
	$sql2 = "insert into vessel_master_2 (VESSEL_IMO_ID, CLASS_SOC_ID, CLASS_NOTATION, DATE_LAST_1, DATE_LAST_2, CLASS_1, DATE_INS_1, DATE_INS_2, STR, STR_1, DATE_DRYDOCK, PORT_DRYDOCK, GROUND, ISM, STATE_DOC, STATE_SMC, DATE_LAST_AUDIT, DATE_NEXT_AUDIT, STATE_OUTS, DATE_ADVISE, PORT_ADVISE, DETEN, STATE_OUTS_1, ITF, ITF_AGREE, FULL_DETAILS, IMO_R_NO, DATE_SMC) values ('".$id."', '".addslashes(trim($_REQUEST['selCLASS_SOC']))."', '".addslashes(trim($_REQUEST['txtCLASS_NOT']))."', '".$DOLSS1."', '".$DOLAS1."', '".addslashes(trim($_REQUEST['selCLASS_1']))."', '".$DOLI1."', '".$DONI1."', '".addslashes(trim($_REQUEST['selSTR']))."', '".addslashes(trim($_REQUEST['selSTR_1']))."', '".$Date_Dry1."', '".addslashes(trim($_REQUEST['selPOLD']))."', '".addslashes(trim($_REQUEST['txtGROUND']))."', '".addslashes(trim($_REQUEST['selISM']))."', '".addslashes(trim($_REQUEST['txtSTATE_DOC']))."', '".addslashes(trim($_REQUEST['txtSTATE_SMC']))."', '".$LAST_AUDIT1."', '".$NEXT_AUDIT1."', '".addslashes(trim($_REQUEST['txtSTATE_OUTS']))."', '".$ADVISE_DATE1."', '".addslashes(trim($_REQUEST['selADVISE_PORT']))."', '".addslashes(trim($_REQUEST['selDETEN']))."', '".addslashes(trim($_REQUEST['txtSTATE_OUTS_1']))."', '".addslashes(trim($_REQUEST['txtITF']))."', '".addslashes(trim($_REQUEST['txtITF_AGREE']))."', '".addslashes(trim($_REQUEST['txtFULL_DETAILS']))."', '".addslashes(trim($_REQUEST['txtIMO_REGS_NO']))."', '".$DATE_SMC1."')";
	
	mysql_query($sql2) or die(mysql_error());
	
	
	
	$txtCID	=	addslashes(trim($_REQUEST['txtCID']));;
	
	for($j=1; $j<=$txtCID; $j++)
	{
		echo $selCert	=	addslashes(trim($_REQUEST['selCert_'.$j]));
		
		//$txtIDate	=	addslashes(trim($_REQUEST['txtIDate_'.$j]));
		
		$txtIDate = date("Y-m-d",strtotime($_REQUEST['txtIDate_'.$j]));
		if(($_REQUEST['txtIDate_'.$j]) == ""){
			$txtIDate1 = "1970-01-01";
		}else{
			$txtIDate1 = $txtIDate;
		}		
		
		//$txtLAIDate	=	addslashes(trim($_REQUEST['txtLAIDate_'.$j]));
		
		$txtLAIDate = date("Y-m-d",strtotime($_REQUEST['txtLAIDate_'.$j]));
		if(($_REQUEST['txtLAIDate_'.$j]) == ""){
			$txtLAIDate1 = "1970-01-01";
		}else{
			$txtLAIDate1 = $txtLAIDate;
		}
		
		
		//$txtEDate	=	addslashes(trim($_REQUEST['txtEDate_'.$j]));
		
		$txtEDate = date("Y-m-d",strtotime($_REQUEST['txtEDate_'.$j]));
		if(($_REQUEST['txtEDate_'.$j]) == ""){
			$txtEDate1 = "1970-01-01";
		}else{
			$txtEDate1 = $txtEDate;
		}
		
		
		$filename =$_FILES['txtfile_'.$j]['name'];
		$tmpFile = $_FILES["txtfile_".$j]["tmp_name"];
		move_uploaded_file($_FILES['txtfile_'.$j]['tmp_name'], '../../attachment/'.$filename);
		
		if(!empty($selCert))
		{
			$qsql = "select * from vessel_master_slave where VESSEL_IMO_ID='".$id."' and CERTIFICATE_ID='".$selCert."'";
			$qres = mysql_query($qsql) or die(mysql_error());
			$qrec = mysql_num_rows($qres);
			if($qrec == 0)
			{ 
				$sql3 = "insert into vessel_master_slave (VESSEL_IMO_ID, CERTIFICATE_ID, DATE_ISSUE, DATE_LAST, DATE_EXPIRY, UPLOAD) values ('".$id."', '".$selCert."', '".$txtIDate1."','".$txtLAIDate1."','".$txtEDate1."','".$filename."')";
				
				mysql_query($sql3) or die(mysql_error());
			}
			else
			{
				$qrows = mysql_fetch_assoc($qres);
				
				if(empty($_FILES['txtfile_'.$j]['name']))
				{ 
					$filename_1 = $qrows['UPLOAD'];
				}else{ 
					$filename_1 = $filename;}
			
				$qsql1 = "update vessel_master_slave set DATE_ISSUE='".$txtIDate1."', DATE_LAST='".$txtLAIDate1."', DATE_EXPIRY='".$txtEDate1."', UPLOAD='".$filename_1."' where VESSEL_SLAVE_ID='".$qrows['VESSEL_SLAVE_ID']."'";
				
				mysql_query($qsql1) or die(mysql_error());
			}
		}
	}
	
	
	mysql_query("commit"); 
	return $msg;	
}



function updateVesselChapterThreeMaster(){
	
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;	
	
	$sql13 = "delete from vessel_master_3 where VESSEL_IMO_ID=".$id;
	mysql_query($sql13);
	
	$sql3 = "insert into vessel_master_3 (VESSEL_IMO_ID, NOC, NOM, NOO, NOCR) values ('".$id."', '".addslashes(trim($_REQUEST['txtNOC']))."', '".addslashes(trim($_REQUEST['txtNOM']))."', '".addslashes(trim($_REQUEST['txtNOO']))."', '".addslashes(trim($_REQUEST['txtNOCR']))."')";
	
	
	mysql_query($sql3) or die(mysql_error());
	
	mysql_query("commit"); 
	return $msg;
	
}

function updateVesselChapterFourMaster(){
	
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;	
	
	$sql14 = "delete from vessel_master_4 where VESSEL_IMO_ID=".$id;
	mysql_query($sql14);
	
	$sql4 = "insert into vessel_master_4 (VESSEL_IMO_ID, NOH, HOLDS_CLEAR, GRAIN, CARRIAGE, TANKTOP, BULKHEAD, SQM, CO2, DET_SYS, LADDER, CALC, HOLD_SIDE, F_BULKHEAD, AFT_BULKHEAD, SHAPED, H1_1, H1_2, H1_3, H2_1, H2_2, H2_3, H3_1, H3_2, H3_3, H4_1, H4_2, H4_3, H5_1, H5_2, H5_3, H6_1, H6_2, H6_3, H7_1, H7_2, H7_3, VENT, NOHA, NOHA_COV, HATCH_SIZE, HATCH_SQM, FAR, OPEN_1, LAST_OPEN, STR_SQM, CHNPH, DOH, POH, MAKE_TYPE, NOCS, BSR, HOOK, HATCH_COAM, HOOK_CARGO, H_LIFT, E_HYDRA, TYPE_CAP, N_WORK, BOARD, MOATS) values ('".$id."', '".addslashes(trim($_REQUEST['txtNOH']))."', '".addslashes(trim($_REQUEST['selHOLDS_CLEAR']))."', '".addslashes(trim($_REQUEST['txtGRAIN']))."', '".addslashes(trim($_REQUEST['txtCARRIAGE']))."', '".addslashes(trim($_REQUEST['selTANKTOP']))."', '".addslashes(trim($_REQUEST['txtBULKHEAD']))."', '".addslashes(trim($_REQUEST['txtSQM']))."', '".addslashes(trim($_REQUEST['selCO2']))."', '".addslashes(trim($_REQUEST['selDET_SYS']))."', '".addslashes(trim($_REQUEST['selLADDER']))."', '".addslashes(trim($_REQUEST['selCALC']))."', '".addslashes(trim($_REQUEST['selHOLD_SIDE']))."', '".addslashes(trim($_REQUEST['selF_BULKHEAD']))."', '".addslashes(trim($_REQUEST['selAFT_BULKHEAD']))."', '".addslashes(trim($_REQUEST['selSHAPED']))."', '".addslashes(trim($_REQUEST['txtHid_1_1']))."', '".addslashes(trim($_REQUEST['txtHid_1_2']))."', '".addslashes(trim($_REQUEST['txtHid_1_3']))."', '".addslashes(trim($_REQUEST['txtHid_2_1']))."', '".addslashes(trim($_REQUEST['txtHid_2_2']))."', '".addslashes(trim($_REQUEST['txtHid_2_3']))."', '".addslashes(trim($_REQUEST['txtHid_3_1']))."', '".addslashes(trim($_REQUEST['txtHid_3_2']))."', '".addslashes(trim($_REQUEST['txtHid_3_3']))."', '".addslashes(trim($_REQUEST['txtHid_4_1']))."', '".addslashes(trim($_REQUEST['txtHid_4_2']))."', '".addslashes(trim($_REQUEST['txtHid_4_3']))."', '".addslashes(trim($_REQUEST['txtHid_5_1']))."', '".addslashes(trim($_REQUEST['txtHid_5_2']))."', '".addslashes(trim($_REQUEST['txtHid_5_3']))."', '".addslashes(trim($_REQUEST['txtHid_6_1']))."', '".addslashes(trim($_REQUEST['txtHid_6_2']))."', '".addslashes(trim($_REQUEST['txtHid_6_3']))."', '".addslashes(trim($_REQUEST['txtHid_7_1']))."', '".addslashes(trim($_REQUEST['txtHid_7_2']))."', '".addslashes(trim($_REQUEST['txtHid_7_3']))."', '".addslashes(trim($_REQUEST['txtVENT']))."', '".addslashes(trim($_REQUEST['txtNOHA']))."', '".addslashes(trim($_REQUEST['txtNOHA_COV']))."', '".addslashes(trim($_REQUEST['txtHATCH_SIZE']))."', '".addslashes(trim($_REQUEST['txtHATCH_SQM']))."', '".addslashes(trim($_REQUEST['txtFAR']))."', '".addslashes(trim($_REQUEST['txtOPEN']))."', '".addslashes(trim($_REQUEST['txtLAST_OPEN']))."', '".addslashes(trim($_REQUEST['txtSTRENGTH_SQM']))."', '".addslashes(trim($_REQUEST['txtCHNPH']))."', '".addslashes(trim($_REQUEST['txtDOH']))."', '".addslashes(trim($_REQUEST['txtPOH']))."', '".addslashes(trim($_REQUEST['txtMAKE_TYPE']))."', '".addslashes(trim($_REQUEST['txtNOCS']))."', '".addslashes(trim($_REQUEST['txtBSR']))."', '".addslashes(trim($_REQUEST['txtHOOK']))."', '".addslashes(trim($_REQUEST['txtHATCH_COAM']))."', '".addslashes(trim($_REQUEST['txtHOOK_CARGO']))."', '".addslashes(trim($_REQUEST['selH_LIFT']))."', '".addslashes(trim($_REQUEST['selE_HYDRA']))."', '".addslashes(trim($_REQUEST['txtTYPE_CAP']))."', '".addslashes(trim($_REQUEST['selN_WORK']))."', '".addslashes(trim($_REQUEST['txtBOARD']))."', '".addslashes(trim($_REQUEST['txtMOATS']))."')";
	
	
	mysql_query($sql4) or die(mysql_error());
	
	mysql_query("commit"); 
	return $msg;
	
}

function updateVesselChapterFiveMaster(){
	
	
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;	
	
	$sql15 = "delete from vessel_master_5 where VESSEL_IMO_ID=".$id;
	mysql_query($sql15);
	
	
	$sql5 = "insert into vessel_master_5 (VESSEL_IMO_ID, LADEN_1, LADEN_2, BALLAST_1, BALLAST_2, BUNKER_G, BUNKER_C, P_WORK, EMAT, MOB) values ('".$id."', '".addslashes(trim($_REQUEST['txtADid_1_1']))."', '".addslashes(trim($_REQUEST['txtADid_1_2']))."', '".addslashes(trim($_REQUEST['txtADid_2_1']))."', '".addslashes(trim($_REQUEST['txtADid_2_2']))."', '".addslashes(trim($_REQUEST['txtBUNKER_G']))."', '".addslashes(trim($_REQUEST['txtBUNKER_C']))."', '".addslashes(trim($_REQUEST['txtP_WORK']))."', '".addslashes(trim($_REQUEST['txtEMAT']))."', '".addslashes(trim($_REQUEST['txtMOB']))."')";
	
	
	mysql_query($sql5) or die(mysql_error());
	
	mysql_query("commit"); 
	return $msg;
	
}


function updateVesselChapterSixMaster(){
	
	$connect 		= $this->funConnect();
	$id 	 		= $_REQUEST['id'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;	
	
	$sql16 = "delete from vessel_master_6 where VESSEL_IMO_ID=".$id;
	mysql_query($sql16);
	
	
	$sql6 = "insert into vessel_master_6 (VESSEL_IMO_ID, CALL_SIGN, NOR, COMM_SYS, HAMIV, P_I, PLACED, CARGO, CARGO_1, CARGO_2, INMARSAT_NUMBER,TELEX_NUMBER ,FAX_NUMBER ,EMAIL_ADDRESS ,MMSI_NUMBER) values ('".$id."', '".addslashes(trim($_REQUEST['txtCALL_SIGN']))."', '".addslashes(trim($_REQUEST['txtNOR']))."', '".addslashes(trim($_REQUEST['txtCOMM_SYS']))."', '".addslashes(trim($_REQUEST['txtHAMIV']))."', '".addslashes(trim($_REQUEST['txtPI']))."', '".addslashes(trim($_REQUEST['txtPLACED']))."', '".addslashes(trim($_REQUEST['txtCARGO']))."', '".addslashes(trim($_REQUEST['selCARGO_1']))."', '".addslashes(trim($_REQUEST['txtCARGO_2']))."', '".addslashes(trim($_REQUEST['txtINMARSAT_Number']))."', '".addslashes(trim($_REQUEST['txtTelex_Number']))."', '".addslashes(trim($_REQUEST['txtFax_Number']))."', '".addslashes(trim($_REQUEST['txtEmail_Address']))."', '".addslashes(trim($_REQUEST['txtMMSI_No']))."')";
	
	mysql_query($sql6) or die(mysql_error());
	
	mysql_query("commit"); 
	return $msg;
	
}

function updateVesselChapterSevenMaster(){
	
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;	
	
	$sql17 = "delete from vessel_master_7 where VESSEL_IMO_ID=".$id;
	mysql_query($sql17);
	
	$sql7 = "insert into vessel_master_7 (VESSEL_IMO_ID, EMPTY, THW, GEAR, FEU, COVERS, PER_TEU, PER_FEU, SPREAD_BOARD, REEFER_PLUGS, TWEENS, NOHH, TOH, WEATHER_DECK, TWEEN_DECK, FLUSH, TANKTOP, SQM_TD, SQM_WD, SQM_HC, B_FITTED, CO2_FITT, REMARK) values ('".$id."', '".addslashes(trim($_REQUEST['txtEMPTY']))."', '".addslashes(trim($_REQUEST['txtTHW']))."', '".addslashes(trim($_REQUEST['txtGEAR']))."', '".addslashes(trim($_REQUEST['selFEU']))."', '".addslashes(trim($_REQUEST['selCOVERS']))."', '".addslashes(trim($_REQUEST['txtPER_TEU']))."', '".addslashes(trim($_REQUEST['txtPER_FEU']))."', '".addslashes(trim($_REQUEST['txtSPREAD_BOARD']))."', '".addslashes(trim($_REQUEST['txtREEFER_PLUGS']))."', '".addslashes(trim($_REQUEST['selTWEENS']))."', '".addslashes(trim($_REQUEST['txtNOHH']))."', '".addslashes(trim($_REQUEST['txtTOH']))."', '".addslashes(trim($_REQUEST['txtWEATHERDECK']))."', '".addslashes(trim($_REQUEST['txtTWEENDECK']))."', '".addslashes(trim($_REQUEST['selFLUSH']))."', '".addslashes(trim($_REQUEST['txtTANKTOP']))."', '".addslashes(trim($_REQUEST['txtSQM_TD']))."', '".addslashes(trim($_REQUEST['txtSQM_WD']))."', '".addslashes(trim($_REQUEST['txtSQM_HC']))."', '".addslashes(trim($_REQUEST['selCO2_FITT']))."', '".addslashes(trim($_REQUEST['selB_FITTED']))."', '".addslashes(trim($_REQUEST['txtREMARK']))."')";
	mysql_query($sql8);
	
	mysql_query($sql7) or die(mysql_error());
	
	mysql_query("commit"); 
	return $msg;
	
}

function getCountryNameList()
{
	$this->funconnect();
	$sql   = "SELECT * FROM country_master WHERE STATUS=1 ORDER by COUNTRY_NAME";
	$query = mysql_query($sql);
	echo "<option value = '' >---Select from list---</option>";
	while($rows = mysql_fetch_assoc($query))
	{
		$key= $rows['COUNTRYID'];
		$value= $rows['COUNTRY_NAME'];
		echo"<option value = ".$key." " .">";
		echo " ".$value." " ."</option>" ;
	}
}


function insertVesselCommercialParametersDetails()
{
 $connect     = $this->funConnect();
 $id                  = $_REQUEST['id'];
 $date     = date("Y-m-d",strtotime($_REQUEST['txtDate']));
 
 $b_full_speed    = addslashes(trim($_REQUEST['txtBFullSpeed']));
 $b_eco_speed1   = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
 $b_eco_speed2   = addslashes(trim($_REQUEST['txtBEcoSpeed2']));
 $l_full_speed   = addslashes(trim($_REQUEST['txtLFullSpeed']));
 $l_eco_speed1   = addslashes(trim($_REQUEST['txtLEcoSpeed1']));
 $l_eco_speed2   = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
 
 $remarks    = addslashes(trim($_REQUEST['txtRemarks']));
 
 $txtCRMFILE1		= addslashes(trim($_REQUEST['txtCRMFILE']));
 $txtCRMNAME1		= addslashes(trim($_REQUEST['txtCRMNAME']));
 
 $upload = $this->getUpload($_FILES['attach_file']);
 $name 	= $this->getUploadName($_FILES['attach_file']);
	
 $upload = implode(',',$upload);
 $name 	= implode(',',$name);
	
 if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
 else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
 else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
 if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
 else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
 else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
 
 $msg = 2;
 mysql_query("Set Autocommit=0");
 mysql_query("START TRANSACTION");
 
 //insert query here.............
 $query = "select * from vessel_commercial_parameters where VESSEL_IMO_ID='".$id."' and MODULEID='".$_SESSION['moduleid']."'";
 $res = mysql_query($query);
 $rec = mysql_num_rows($res);
 if($rec == 0)
 {
	//insert query...........
	$sql = "insert into vessel_commercial_parameters (VESSEL_IMO_ID, MAIN_DATA_DATE, B_FULL_SPEED, B_ECO_SPEED1, B_ECO_SPEED2, L_FULL_SPEED, L_ECO_SPEED1, L_ECO_SPEED2, MODULEID, REMARKS, ATTACHMENT, ATTACHMENT_NAME) values ('".$id."','".$date."','".$b_full_speed."','".$b_eco_speed1."','".$b_eco_speed2."','".$l_full_speed."','".$l_eco_speed1."','".$l_eco_speed2."','".$_SESSION['moduleid']."','".$remarks."','".$upload1."','".$name1."')";
	
	mysql_query($sql) or die(mysql_error());
	mysql_query("commit");
	
	$mysql = "select max(COMMERCIAL_PARAMETERID) as max from vessel_commercial_parameters";
	$myres  =  mysql_query($mysql);
	$myrows = mysql_fetch_assoc($myres);
	$maxid = $myrows['max'];
	
	$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
	for($i=1;$i<=$txtFOAtSeaID;$i++)
	{
	    if($_REQUEST['selFOAtSeaBunker_'.$i]!='')
		{
			$sql1 = "insert into vessel_commercial_parameters_slave1 (COMMERCIAL_PARAMETERID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['selFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";
			
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
	
	$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
	for($i=1;$i<=$txtDOAtSeaID;$i++)
	{
	    if($_REQUEST['selDOAtSeaBunker_'.$i]!='')
		{
			$sql1 = "insert into vessel_commercial_parameters_slave1 (COMMERCIAL_PARAMETERID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['selDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
			
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
	
 }else{
  
	$rows = mysql_fetch_assoc($res);
	$sql = "update vessel_commercial_parameters set MAIN_DATA_DATE='".$date."', B_FULL_SPEED='".$b_full_speed."', B_ECO_SPEED1='".$b_eco_speed1."', B_ECO_SPEED2='".$b_eco_speed2."', L_FULL_SPEED='".$l_full_speed."', L_ECO_SPEED1='".$l_eco_speed1."', L_ECO_SPEED2='".$l_eco_speed2."', REMARKS='".$remarks."', ATTACHMENT='".$upload1."', ATTACHMENT_NAME='".$name1."' where COMMERCIAL_PARAMETERID='".$rows['COMMERCIAL_PARAMETERID']."' ";
	
	mysql_query($sql) or die(mysql_error());  
	mysql_query("commit");
	
	$sql1 = "delete from vessel_commercial_parameters_slave1 where COMMERCIAL_PARAMETERID=".$rows['COMMERCIAL_PARAMETERID'];
	mysql_query($sql1);
	$sql2 = "delete from vessel_commercial_parameters_slave2 where COMMERCIAL_PARAMETERID=".$rows['COMMERCIAL_PARAMETERID'];
	mysql_query($sql2);
	
	$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
	for($i=1;$i<=$txtFOAtSeaID;$i++)
	{
	    if($_REQUEST['selFOAtSeaBunker_'.$i]!='')
		{
			$sql1 = "insert into vessel_commercial_parameters_slave1 (COMMERCIAL_PARAMETERID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$rows['COMMERCIAL_PARAMETERID']."', '".$this->getCheckNullVal($_REQUEST['selFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";
			
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
	
	$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
	for($i=1;$i<=$txtDOAtSeaID;$i++)
	{
	    if($_REQUEST['selDOAtSeaBunker_'.$i]!='')
		{
			$sql1 = "insert into vessel_commercial_parameters_slave1 (COMMERCIAL_PARAMETERID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$rows['COMMERCIAL_PARAMETERID']."', '".$this->getCheckNullVal($_REQUEST['selDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
			
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
 }
 return $msg; 
}


function getNameBasedOnID($id)
{
  $connect = $this->funConnect();
  if($id == 1)
  {
   return YES;
  }
  else if($id == 2)
  {
   return NO;
  }
  else if($id == 3)
  {
   return N.'/'.A;
  }
  else
  {
   return ' ';
  }
}


function getClaSocNameOnId($id)
{
 $connect = $this->funConnect();
 $sql  = "select NAME from classification_soc_master where CLA_SOC_ID=".$id;
 $res  = mysql_query($sql);
 $rows = mysql_fetch_assoc($res);
 return $rows['NAME'];
}

function getCertificateNameOnId($id)
{
 $connect = $this->funConnect();
 $sql = "select CERTIFICATE from certificate_master where CERTIFICATEID=".$id;
 $res = mysql_query($sql);
 $rows = mysql_fetch_assoc($res);
 return $rows['CERTIFICATE'];
}

function getCountryNameOnId($id)
{
	 if($id!='') 
	 {
	 $connect = $this->funConnect();
	 $sql = "select COUNTRY_NAME from country_master where COUNTRYID=".$id;
	 $res = mysql_query($sql);
	 $rows = mysql_fetch_assoc($res);
	 return $rows['COUNTRY_NAME'];
	 }
	 else
	 {
		 return '';
	 }
}

function displayWSPCList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="wspc_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="15%"  >From Port</th>';
	echo '<th align="left" valign="middle" width="15%"  >To Port</th>';
	echo '<th align="left" valign="middle" width="15%"  >WS Flat Rate</th>';
	echo '<th align="left" valign="middle" width="10%"  >Fixed Diff</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from wspc_master where MCOMPANYID='".$_SESSION['company']."' order by WSPC_ID";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{ //echo'<pre>';print_r($rows);
				$arr = array();
				$arr = explode(",",$rows['MODULEID']);
				if(in_array($_SESSION['moduleid'],$arr))
				{
					echo '<tr>';
					echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$rows['FP_NAME'].'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$rows['TP_NAME'].'</td>';
					echo '<td align="left" valign="middle" class="input-text">'.$rows['WS_F_RATE'].'</td>';	
					echo '<td align="left" valign="middle" class="input-text">'.$rows['FIXED_DIFF'].'</td>';	
					echo '</tr>';
					$i++;
				}
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function getPortListWSPC()
{
	$this->funConnect();
	$query = mysql_query("select * from port_master where STATUS=1 order by PortName ");
	//echo "<option value = '' >---Select from list---</option>";
	@$selPort = @$_REQUEST['selPort'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['PortId'];
		 $value= $rows['PortName'];
		 echo "<option value='".$key."' ";
		 if($key == @$selPort){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getUserStatusList()
{
$state = array( 1 =>'Active' , 2 =>'In-Active');
$selUStatus = @$_REQUEST['selUStatus'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selUStatus){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getPortName($id)
{
	if($id!='') 
	 {
	    $this->funConnect();
	    $sql = "select PortName, COUNTRY_NAME from port_master where PortId=".$id;
	    $res = mysql_query($sql);
	    $rows = mysql_fetch_assoc($res);
	    return $rows['PortName'].'('.$this->getCountryNameBasedOnID($rows['COUNTRY_NAME']).')';
	 }
	 else
	 {
		 return '';
	 }
}

function InsertWSPCRecords()
{  
	$connect = $this->funConnect();
	
	$selFPort 				= implode(",",$_REQUEST['selP_From']);
	$selTPort 				= implode(",",$_REQUEST['selP_To']);
	$txtWSFR 				= addslashes(trim($_REQUEST['txtWSFR']));
	$selStatus 				= addslashes(trim($_REQUEST['selStatus']));
	$txtRemarks 			= addslashes(trim($_REQUEST['txtRemarks']));
	$fixed_diff 			= addslashes(trim($_REQUEST['txtFixedDiff']));

	for($i=0;$i<sizeof($_REQUEST['selP_From']);$i++)
	{
		$FPort[] = $this->getPortName($_REQUEST['selP_From'][$i]);
	}
	
	for($i=0;$i<sizeof($_REQUEST['selP_To']);$i++)
	{
		$PPort[] = $this->getPortName($_REQUEST['selP_To'][$i]);
	}
	
	$FPort_Name 			= implode(",",$FPort);
	$TPort_Name 			= implode(",",$PPort);

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	
	$sql1 = "select * from wspc_master where FROM_PORT='".$selFPort."' and TO_PORT='".$selTPort."' and MCOMPANYID='".$_SESSION['company']."' and MODULEID='".$_SESSION['moduleid']."'";
	$result1 = mysql_query($sql1);
	$rec1 = mysql_num_rows($result1);
	$rows1 = mysql_fetch_assoc($result1);
	if($rec1 == 0)
	{
		$sql2 = "select * from wspc_master where FROM_PORT='".$selTPort."' and TO_PORT='".$selFPort."' and MCOMPANYID='".$_SESSION['company']."' and MODULEID='".$_SESSION['moduleid']."'";
		$result2 = mysql_query($sql2);
		$rec2 = mysql_num_rows($result2);
		$rows2 = mysql_fetch_assoc($result2);
		if($rec2 == 0)
		{
			$sql = "insert into wspc_master (FROM_PORT, FP_NAME, TO_PORT, TP_NAME, WS_F_RATE, MODULEID, MCOMPANYID, STATUS, REMARKS,FIXED_DIFF) values ('".$selFPort."', '".$FPort_Name."', '".$selTPort."', '".$TPort_Name."', '".$txtWSFR."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."','".$selStatus."','".$txtRemarks."','".$fixed_diff."')";
			mysql_query($sql);
		}
		else
		{
			$sql3 = "delete from wspc_master where WSPC_ID=".$rows2['WSPC_ID'];
			mysql_query($sql3);
			$sql = "insert into wspc_master (FROM_PORT, FP_NAME, TO_PORT, TP_NAME, WS_F_RATE, MODULEID, MCOMPANYID, STATUS, REMARKS ,FIXED_DIFF) values ('".$selFPort."', '".$FPort_Name."', '".$selTPort."', '".$TPort_Name."', '".$txtWSFR."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."','".$selStatus."','".$txtRemarks."','".$fixed_diff."')";
			mysql_query($sql);
		}
	}
	else
	{
		$sql4 = "delete from wspc_master where WSPC_ID=".$rows1['WSPC_ID'];
		mysql_query($sql4);
		$sql = "insert into wspc_master (FROM_PORT, FP_NAME, TO_PORT, TP_NAME, WS_F_RATE, MODULEID, MCOMPANYID, STATUS, REMARKS,FIXED_DIFF) values ('".$selFPort."', '".$FPort_Name."', '".$selTPort."', '".$TPort_Name."', '".$txtWSFR."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."','".$selStatus."','".$txtRemarks."','".$fixed_diff."')";
		mysql_query($sql);
	}
	
	mysql_query("commit"); 
	return $msg;
}

function getNominationListMappingidWise()
{
	$this->funConnect();
	$query = mysql_query("select * from mapping_master where STATUS in (2,5) order by MAPPINGID");
	echo "<option value = '' >------------------------Select Nomination Detail------------------------</option>";
	@$selMappingid = @$_REQUEST['selMappingid'];
	while($rows = mysql_fetch_assoc($query))
		{
			 $key= $rows['MAPPINGID']."_".$this->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],'VESSEL_IMO_ID');
			 $value= "[".$this->getMappingData($rows['MAPPINGID'],"NOM_NAME")."] / [".$this->getVesselIMOData($this->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],'VESSEL_IMO_ID'),"VESSEL_NAME")."] / [".date("d M Y",strtotime($this->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],'FROM_DATE')))." to ".date("d M Y",strtotime($this->getVesselOpenEntryDeta($rows['OPEN_VESSEL_ID'],'TO_DATE')))."]";
			 echo "<option value='".$key."' ";
			 if($key == @$selMappingid){ echo " selected";}
			 echo ">".$value."</option>";
		}
}

function getOpenDepartureList()
{
	$this->funConnect();
	$query = mysql_query("select * from departure_master where MAPPINGID='' and UPDATE_STATUS=3 order by DEPARTUREID");
	echo "<option value = '' >------------------------------------Select Vessel Message------------------------------------</option>";
	@$selDepartureid = @$_REQUEST['selDepartureid'];
	while($rows = mysql_fetch_assoc($query))
		{
			 $key= $rows['DEPARTUREID']."_".$rows['VESSEL_IMO_ID'];
			 $value= "[".$rows['LEG']."] / [".$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME")."] / [".$rows['VOY_NO']."] / [".$rows['VSL_GP_VOY_NO']."] / [".$rows['MESSAGE']."] / [".date("d M Y H:i",strtotime($rows['REPORTING_DATE_LT']))."]";
			 echo "<option value='".$key."' ";
			 if($key == @$selDepartureid){ echo " selected";}
			 echo ">".$value."</option>";
		}
}

function mapSynchronisedDataRecords()
{
	$connect				= $this->funConnect();
 	$mappingid 				= explode("_",$_REQUEST['selMappingid']);
	$departureid 			= explode("_",$_REQUEST['selDepartureid']);
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update departure_master set MAPPINGID='".$mappingid[0]."' where DEPARTUREID='".$departureid[0]."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}

function displayInvoiceStatusList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="invoice_status_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="10%" >#</th>';
	echo '<th align="left" valign="middle" width="60%">Name</th>';
	echo '<th align="left" valign="middle" width="20%">Status</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from invoice_status_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['IS_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['IS_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateInvoiceStatus.php?id='.$rows['IS_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function displayLawArbitrationList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="lawarbitration_status_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="10%" >#</th>';
	echo '<th align="left" valign="middle" width="60%">Law/Arbitration</th>';
	echo '<th align="left" valign="middle" width="20%">Status</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from lawarbitration_master_list order by STATUS,LAW_ARBITRATION";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LAW_ARBITRATION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['LAWARBITRA_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['LAWARBITRA_ID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateLawArbitrationlist.php?id='.$rows['LAWARBITRA_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertInvoiceStatusDetails()
{
	$connect = $this->funConnect();
	$name 		= addslashes(trim($_REQUEST['txtName']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into invoice_status_master (NAME,MODULEID,MCOMPANYID) values ('".$name."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	mysql_query("commit");
	return $msg; 
}

function insertLawArbitrationMasterDetails()
{
	$connect			= $this->funConnect();
	$txtLawArbit		= addslashes(trim($_REQUEST['txtLawArbit']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into lawarbitration_master_list (LAW_ARBITRATION,MODULEID,MCOMPANYID) values ('".$txtLawArbit."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	mysql_query("commit");
	return $msg; 
}

function changeInvoiceStatusMasterStatusRecords()
{
	$connect			= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	$sql = "update invoice_status_master set STATUS='".$tblstatus."' where IS_ID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}

function changeLawArbitrationMasterStatusRecords()
{
	$connect		= $this->funConnect();
	$tblid			= addslashes(trim($_REQUEST['txttblid']));
	$value			= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1)	{$tblstatus = 2;}
	else {$tblstatus = 1;}	

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	$sql = "update lawarbitration_master_list set STATUS='".$tblstatus."' where LAWARBITRA_ID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	//echo $sql; die();
	mysql_query($sql);
	mysql_query("commit");
	return $msg;
}

function viewInvoiceStatusRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM invoice_status_master where IS_ID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
	}
}

function viewLawArbitrationRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM lawarbitration_master_list where LAWARBITRA_ID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['LAW_ARBITRATION'];
	}
}

function updateInvoiceStatusMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtName 				= addslashes(trim($_REQUEST['txtName']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update invoice_status_master set NAME='".$txtName."' where IS_ID='".$id."' and  MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
}

function updateLawArbitrationMasterRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
 	$txtLawArbit 			= addslashes(trim($_REQUEST['txtLawArbit']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update lawarbitration_master_list set LAW_ARBITRATION='".$txtLawArbit."' where LAWARBITRA_ID='".$id."' and  MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	
	mysql_query("commit"); 
	return $msg;
}

function getElibraryCategoryList()
{
	$this->funConnect();
	$query = mysql_query("select * from elibrary_categories where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select Category---</option>";
	@$selCategort = @$_REQUEST['selCategory'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CATEGORY_ID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selCategort){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getElibraryReferenceTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from elibrary_refrences where STATUS = 1 order by NAME ");
	echo "<option value = ''>---Select Reference---</option>";
	@$selReference = @$_REQUEST['selRefType'];
	while($rows = mysql_fetch_array($query))
	{
		$key = $rows['REF_ID'];
		$value = $rows['NAME'];
		echo "<option value = '".$key."' ";
		if($key == @$selReference){ echo "selected";}
		echo ">" .$value. "</option>";
	}
}

function viewCategoryDetails($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from elibrary_categories where CATEGORY_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function viewReferenceTypeDetails($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from elibrary_refrences where REF_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function displayAddRefrences()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="elibrary_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="top" width="10%" >Category</th>';
	echo '<th align="left" valign="top" width="10%" >Reference Type</th>';
	echo '<th align="left" valign="top" width="10%" >Date</th>';	
	echo '<th align="left" valign="top" width="10%" >Name</th>';
	echo '<th align="left" valign="top" width="10%" >Description</th>';
	echo '<th align="left" valign="top" width="10%" >Source</th>';
	echo '<th align="center" valign="top" width="10%" >Upload</th>';
	echo '<th align="center" valign="top" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from elibrary where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody id="tbody">';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody id="tbody">';
		while($rows = mysql_fetch_assoc($res))
			{
				//if((int)$rows['NO_OF_SHIPMENT'] != (int)$this->getPerformedVesselRec($rows['COAID']))
				//{
				echo '<tr>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->viewCategoryDetails($rows['CATEGORY'],"NAME").'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->viewReferenceTypeDetails($rows['REFERENCE'],"NAME").'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.date("d M Y",strtotime($rows['DATE'])).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SOURCE'].'</td>';
				
				$attachments = explode(",",$rows['UPLOAD']);
				echo '<td align="left" valign="middle" class="input-text">';
				for($m=0;$m<count($attachments);$m++)
				{
					if(trim($attachments[$m]) != "")
					{
						echo '&nbsp;&nbsp;<a href="../../attachment/'.$attachments[$m].'" target="_blank" title="View"><i class="fa fa-external-link"></i></a>';
					}
				}
				echo '</td>';
						
				echo '<td align="center" valign="middle" class="input-text "><a href="updateReferences.php?id='.$rows['ELIBREF_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#'.$i.'" onclick="return getDelete('.$rows['ELIBREF_ID'].');"  ><i class="fa fa-times" style="color:red;"></i></a></td>';
				echo '</tr>';
				$i++;
				//}
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertElibraryReferencesDetails()
{
	$connect = $this->funConnect();
	$selCategory		= addslashes(trim($_REQUEST['selCategory']));
	$selRefType	 		= addslashes(trim($_REQUEST['selRefType']));
	$txtDate			= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtName			= addslashes(trim($_REQUEST['txtName']));
	$txtSource		    = addslashes(trim($_REQUEST['txtSource']));
	$txtDirection		= addslashes(trim($_REQUEST['txtDirection']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	$upload = $this->getUpload($_FILES["mul_file"]);
	$name = $this->getUploadName($_FILES['mul_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	//insert query here.............
	$sql = "insert into elibrary (CATEGORY, REFERENCE, DATE, NAME, SOURCE, DESCRIPTION, UPLOAD, UPLOAD_NAME ,MODULEID , MCOMPANYID) values ('".$selCategory."','".$selRefType."','".$txtDate."','".$txtName."','".$txtSource."','".$txtDirection."','".$upload."','".$name."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	//echo $sql;die();
	mysql_query($sql);
	mysql_query("commit");
	return $msg; 
}

function viewRefTypeRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM elibrary where ELIBREF_ID='".$id."' AND MODULEID = '".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['CATEGORY'];
		$this->var_2 = $rows['REFERENCE'];
		$this->var_3 = $rows['DATE'];
		$this->var_4 = $rows['NAME'];
		$this->var_5 = $rows['SOURCE'];
		$this->var_6 = $rows['DESCRIPTION'];
		$this->var_7 = $rows['UPLOAD'];
		$this->var_8 = $rows['UPLOAD_NAME'];
	}
}

function deleteReferenceStatusRecords()
{
	$connect			= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 3;
	$sql = "delete from elibrary where ELIBREF_ID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'"; 
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}

function deleteReferenceAttachment()
{
	$connect				= $this->funConnect();
 	$id 					= addslashes(trim($_REQUEST['id']));
	$file_name 				= addslashes(trim($_REQUEST['txtFileName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "SELECT * FROM elibrary where ELIBREF_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$sql1 = "update elibrary set UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."'  where ELIBREF_ID='".$id."'";
	mysql_query($sql1);
	mysql_query("commit");
	return $msg;
}

function updateReferencesDetails()
{
	$connect = $this->funConnect();
	$id				    = $_REQUEST['id'];
	$selCategory		= addslashes(trim($_REQUEST['selCategory']));
	$selRefType	 		= addslashes(trim($_REQUEST['selRefType']));
	$txtDate			= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtName			= addslashes(trim($_REQUEST['txtName']));
	$txtSource		    = addslashes(trim($_REQUEST['txtSource']));
	$txtDirection		= addslashes(trim($_REQUEST['txtDirection']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	

	//insert query here.............
	$sql = "update elibrary set CATEGORY='".$selCategory."', REFERENCE='".$selRefType."', DATE='".$txtDate."', NAME='".$txtName."', SOURCE='".$txtSource."', DESCRIPTION='".$txtDirection."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', MODULEID='".$_SESSION['moduleid']."', MCOMPANYID='".$_SESSION['company']."' where ELIBREF_ID='".$id."'";

	mysql_query($sql);
	mysql_query("commit");
	return $msg; 
}

function displayCargoOpenPositionReport($selBType)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="cargo_open_position" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="top">Cargo ID</th>';
	echo '<th align="left" valign="top">Shipper</th>';	
	echo '<th align="left" valign="top">Material Desc</th>';
	echo '<th align="left" valign="top">Material Qty</th>';	
	echo '<th align="left" valign="top">Load Port</th>';
	echo '<th align="left" valign="top">Dis Port</th>';
	echo '<th align="left" valign="top">Date Range</th>';
	echo '<th align="center" valign="top">Open Vessel</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	if($selBType!='')
	{
		$sql = "select * from freight_cost_estimete_master where SHEET_NO is NULL and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and CARGOID!='' and ESTIMATE_TYPE='".$selBType."'";
		$res = mysql_query($sql) or die($sql);
		$rec = mysql_num_rows($res);
		if($rec == 0)
		{
		}
		else
		{
			while($rows = mysql_fetch_assoc($res))
			{   
				$quantity = 0;
				if($rows['ESTIMATE_TYPE']==1)
				{
					$quantity = $rows['GAS_QUANTITY'];
				}
				else if($rows['ESTIMATE_TYPE']==2)
				{
					$quantity = $rows['TANK_QUANTITY'];
				}
				else
				{
					if($rows['QTY_TYPE_RADIO'] == 1)
					{
						$quantity = $rows['QUANTITY'];
					}
					else
					{
						$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$rows['FCAID']."'";
						$res12 = mysql_query($sql12);
						$row12 = mysql_fetch_assoc($res12);
						$quantity = $row12['sum'];
					}
				}
				if($rows['LAYCAN_START_DATE']=="" || $rows['LAYCAN_START_DATE']=="1970-01-01"){$txtFDate = "";}else{$txtFDate = date('d-m-Y',strtotime($rows['LAYCAN_START_DATE']));}
				if($rows['LAYCAN_FINISH_DATE']=="" || $rows['LAYCAN_FINISH_DATE']=="1970-01-01"){$txtTDate = "";}else{$txtTDate = date('d-m-Y',strtotime($rows['LAYCAN_FINISH_DATE']));}
				$arr_load = $arr_discharge = array();
				$sql1 = "select FROM_PORT, TO_PORT, LOAD_PORT_COST, LOAD_PORT_QTY, DISC_PORT_COST, DISC_PORT_QTY from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
				$res1 = mysql_query($sql1);
				while($row1 = mysql_fetch_assoc($res1))
				{
					if($row1['LOAD_PORT_QTY']>0)
					{
						$arr_load[] = $this->getPortNameBasedOnID($row1['FROM_PORT']);
					}
					if($row1['DISC_PORT_QTY']>0)
					{
						$arr_discharge[] = $this->getPortNameBasedOnID($row1['TO_PORT']);
					}
				}
				echo '<tr>';
				echo '<td align="left" valign="middle">'.$rows['CARGOID'].'</td>';
				echo '<td align="left" valign="middle">'.$this->getVendorListNewBasedOnID($rows['SHIPPER']).'</td>';
				echo '<td align="left" valign="middle">'.$this->getCargoNameListForMultipleNamemultiple($rows['CARGO_ID']).'</td>';
				echo '<td align="left" valign="middle">'.$quantity.'</td>';
				echo '<td align="left" valign="middle">'.implode(', ',$arr_load).'</td>';
				echo '<td align="left" valign="middle">'.implode(', ',$arr_discharge).'</td>';
				echo '<td align="left" valign="middle">'.$txtFDate.' To '.$txtTDate.'</td>';
				echo '<td align="left" valign="middle" style="color:red;">'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
				echo '</tr>';
			}
		}
	}
	echo '</tbody>';
	echo '</table></div>';
}

function getLatestCostSheetID($comid)
{
	$connect = $this->funConnect();
	$sql 	 = "select FCAID from freight_cost_estimete_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' order by FCAID desc";
	$res 	 = mysql_query($sql);
	$rows  	 = mysql_fetch_assoc($res);
	return $rows['FCAID'];
}


function getLatestCostSheetIDForVcIn($comid)
{
	$connect = $this->funConnect();
	$sql 	 = "select FCAID from freight_cost_estimete_in_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' order by FCAID desc";
	$res 	 = mysql_query($sql);
	$rows  	 = mysql_fetch_assoc($res);
	return $rows['FCAID'];
}


function getLatestCostSheetID_in($vesselimoid, $voyageno)
{
	$connect = $this->funConnect();
	$sql 	 = "select FCAID from freight_cost_estimete_master where VESSEL_IMO_ID='".$vesselimoid."' and VOYAGE_NO='".$voyageno."' order by FCAID desc";
	$res 	 = mysql_query($sql);
	$rows  	 = mysql_fetch_assoc($res);
	return $rows['FCAID'];
}

function getLatestCostSheetIDRelet($comid)
{
	$connect = $this->funConnect();
	$sql 	 = "select FCAID from cargo_relet_estimate_masster where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' order by FCAID desc";
	$res 	 = mysql_query($sql);
	$rows  	 = mysql_fetch_assoc($res);
	return $rows['FCAID'];
}

function getLatestCostSheetIDTC($comid)
{
	$connect = $this->funConnect();
	$sql 	 = "select TCOUTID from chartering_estimate_tc_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' order by TCOUTID desc";
	$res 	 = mysql_query($sql);
	$rows  	 = mysql_fetch_assoc($res);
	return $rows['TCOUTID'];
}

function getLabelsForOwnerAndBroker()
{
$state = array( 11 =>'Owner' , 12 =>'Broker');
$selBOwner = @$_REQUEST['selBOwner'];
echo "<option value = '' >---Select from list---</option>";
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key   = $array_cell['key'];
		echo "<option value=$key";
		if($key == $selBOwner){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getOwnerAndBrokerListJson()
{
	$connect = $this->funconnect();
	$arr = array(11,12);
	for($i=0;$i<count($arr);$i++)
	{
		$query = mysql_query("select * from vendor_master where STATUS=1 and VENDOR_TYPEID=".$arr[$i]." and MCOMPANYID='".$_SESSION['company']."' order by NAME");
		while($rows = mysql_fetch_assoc($query))
		{
			$a[$arr[$i]][] = array('key' => $rows['CODE'] , 'value' => $rows['NAME']." ( ".$rows['CODE']." )" );
		}
	}
	echo json_encode($a);
}


function getPortDistanceType()
{
	$state = array( 1 =>'Shortest Distance (NM)' , 2 =>'250 nm Distance', 3 =>'600 nm Distance', 4 =>'Longest Distance (NM)');
	$selDType = @$_REQUEST['selDType'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo '<option value="'.$key.'"';
		if($key == $selDType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getPortDistanceType_new()
{
	$state = array( 1 =>'Great-Circle' , 2 =>'Rhumb-Line');
	$selDType = @$_REQUEST['selDType'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo '<option value="'.$key.'"';
		if($key == $selDType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getPassageType()
{
	$state = array( 1 =>'Ballast' , 2 =>'Laden');
	$selPType = @$_REQUEST['selPType'];
	echo '<option value="">--Select from list--</option>';
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo '<option value="'.$key.'"';
		if($key == $selPType){ echo " selected";}
		echo ">".$value."</option>";
		
	}

}

function getSelectSpeedList()
{
	$state = array( 1 =>'Full Speed' , 2 =>'Service Speed' , 3 =>'Most Eco Speed');
	$selSSpeed = @$_REQUEST['selSSpeed'];
	echo '<option value="">--Select from list--</option>';
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo '<option value="'.$key.'"';
		if($key == $selSSpeed){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getSelectSpeedNamebasedOnID($id)
{
	$state = array( 1 =>'Full Speed' , 2 =>'Service Speed' , 3 =>'Most Eco Speed');
	return $state[$id];
}

function getDurationFixedPeriod($id)
{
	$dfp = array( 1 => 'Trip TC', 2 => 'Period');
	echo '<option value = "">--Select from list--</option>';
	while($array_cell = each($dfp))
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		echo '<option value = "'.$key.'"';
		if($key == $id )
		{
			echo " selected";
		}
		echo ">".$value."</option>";
	}
}

function getCheckNullValue($var){
	
	if($var == "" || $var == "NaN"  || $var == "Infinity" || !isset($var)){
		return 0;
	}else{
		return $var;
	}
}




function getPassageTypeNameBasedOnID($id)
{
	if($id == 1){return "Ballast";}
	if($id == 2){return "Laden";}
}


function getPassageSpeedBasedOnID($id)
{
	if($id == 1){return "Full Speed";}
	if($id == 2){return "Ech Speed 1";}
	if($id == 3){return "Ech Speed 2";}
}

function getDistanceTypeBasedOnID($id)
{
	if($id == 1){return "Shortest Distance (NM)";}
	if($id == 2){return "250 nm Distance";}
	if($id == 3){return "600 nm Distance";}
	if($id == 4){return "Longest Distance (NM)";}
}

function getDistanceTypeBasedOnID_New($id)
{
	if($id == 1){return "Great-Circle";}
	if($id == 2){return "Rhumb-Line";}
}

function getFreightEstimationTotalRecords($id,$field)
{
	$connect = $this->funConnect();
	$sql    = "select ".$field." from fca_tci_totals where FCAID='".$id."'";
	$result = mysql_query($sql);
	$rows   = mysql_fetch_assoc($result);
	return $rows[$field];
}

function getFreightEstimationTotalTCIRecords($id,$field)
{
	$connect = $this->funConnect();
	$sql    = "select ".$field." from fca_tci_totals where FCAID='".$id."'";
	$result = mysql_query($sql);
	$rows   = mysql_fetch_assoc($result);
	return $rows[$field];
}

function getBunkerGradeBasedOnID($id)
{
	$connect = $this->funConnect();
	$query  = "SELECT * FROM bunker_grade_master where BUNKERGRADEID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	$rows   = mysql_fetch_assoc($result);
	return $rows['NAME'];
}

function getBunkerGradeTypeBasedOnID($id)
{
	$connect = $this->funConnect();
	$query  = "SELECT * FROM bunker_grade_master where BUNKERGRADEID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	$rows   = mysql_fetch_assoc($result);
	return $rows['BUNKERTYPE'];
}

function getOwnerRelatedCostNameBasedOnID($id)
{
	$connect				= $this->funConnect();
	$sql  = "select * from owner_related_cost_master where OWNER_RCOSTID='".$id."' AND MODULEID='".$_SESSION['moduleid']."'";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}


function getOwnerRelatedCostData($id,$field)
{
	$connect				= $this->funConnect();
	$sql  = "select ".$field." from owner_related_cost_master where OWNER_RCOSTID='".$id."' AND MODULEID='".$_SESSION['moduleid']."'";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}




function getBunkerValues($fcaid,$bunkergradeid,$field)
{
	$this->funConnect();
	$sql  = "select $field from freight_cost_estimete_slave2 where FCAID='".$fcaid."' and BUNKERGRADEID='".$bunkergradeid."'";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getFreightFixtureOutBasedOnID($id)
{
	if($id == 1){return "Time Charter Out";}
	if($id == 2){return "Voyage Charter Out";}
}


function getCheckNullVal($var){
	
	if($var == "" || $var == "NaN" || $var == "Infinity" || empty($var)){
		return 0;
	}else{
		return $var;
	}
}


function getChartererCostNameBasedOnID($id)
{
	$connect	= $this->funConnect();
	$sql  		= "select * from charterers_master where CHARTERER_COSTID='".$id."' and MODULEID='".$_SESSION['moduleid']."'";
	$res  		= mysql_query($sql);
	$rows 		= mysql_fetch_assoc($res);
	return $rows['NAME'];
}


function changeChartererCostMasterStatusRecords()
{
	$connect	= $this->funConnect();
 	$tblid		= addslashes(trim($_REQUEST['txttblid']));
	$value 		= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update charterers_master set STATUS='".$tblstatus."' where CHARTERER_COSTID='".$tblid."'"; 
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Charterer Cost Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function displayChartererCostList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="charterercost_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	
	$sql = "select * from charterers_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['CHARTERER_COSTID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['CHARTERER_COSTID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['CHARTERER_COSTID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatechartering_cost_master.php?id='.$rows['CHARTERER_COSTID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>'; 
}

function InsertChartererCostRecords($id)
{
	$connect	= $this->funConnect();
	$txtCCost 	= $_REQUEST['txtCCost'];
	$msg 		= 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$sql  		= "insert into charterers_master (NAME, MODULEID, MCOMPANYID, STATUS) values('".$txtCCost."','".$_SESSION['moduleid']."','".$_SESSION['company']."',1)";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Charterer Cost Record Inserted successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");

	return $msg;
}

function viewCharteringCostRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM charterers_master where CHARTERER_COSTID='".$id."' and MODULEID='".$_SESSION['moduleid']."'"; 
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
		$this->var_2 = $rows['STATUS'];
	}
}



function UpdateChartererCostRecords($id)
{
	$connect	= $this->funConnect();
	
	$txtCCost 	= $_REQUEST['txtCCost'];
	$msg 		= 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$sql  		= "update charterers_master set NAME='".$txtCCost."' where CHARTERER_COSTID='".$id."' and MODULEID='".$_SESSION['moduleid']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Charterer Cost Record Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");

	return $msg;
}



function getOtherMiscCostNameBasedOnID($id)
{
	$connect	= $this->funConnect();
	$sql 		= "select * from other_misc_cost_master where OTHER_MCOSTID='".$id."' and MODULEID='".$_SESSION['moduleid']."'";
	$res 		= mysql_query($sql);
	$rows 		= mysql_fetch_assoc($res);
	return $rows['NAME'];

}

function FixedMapping()
{
	$connect   	= $this->funConnect();
	$mappingid 	= $_REQUEST['mappingid'];
	$nom_name  	= $_REQUEST['txtNomID'];
	$msg 		= 4;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql 		= "update mapping_master set STATUS=2,NOM_NAME='".$nom_name."' where MAPPINGID='".$mappingid."' and  MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	mysql_query("commit");

	return $msg;
}

function getFinalCostSheetDataRec($comid)
{
	$this->funConnect();
	$sql 	= "select FINAL_STATUS from freight_cost_estimete_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'";
	$res 	= mysql_query($sql);
	$rec 	= mysql_num_rows($res);
	$val	=0;
	while($rows = mysql_fetch_assoc($res))
	{
		if($rows['FINAL_STATUS'] == 1)
		{
			$val = 1;
		}	
	}
	return $val;
}


function getCostSheetFixtureID($comid,$field)
{
	$connect 	= $this->funConnect();
	$sql 		= "select ".$field." from freight_cost_estimete_master where MODULEID='".$_SESSION['moduleid']."' and COMID='".$comid."' and FINAL='1'";
	$result 	= mysql_query($sql);
	$rows 		= mysql_fetch_assoc($result);
	return $rows[$field];
}

function getCostSheetCargoreletID($comid,$field)
{
	$connect 	= $this->funConnect();
	$sql 		= "select ".$field." from cargo_relet_estimate_masster where MODULEID='".$_SESSION['moduleid']."' and COMID='".$comid."' and FINAL='1'";
	$result 	= mysql_query($sql);
	$rows 		= mysql_fetch_assoc($result);
	return $rows[$field];
}


function getFreightCostData($comid,$cost_sheet_id,$field)
{
	$connect 	= $this->funConnect();
	$sql 		= "select ".$field." from freight_cost_estimete_master where MODULEID='".$_SESSION['moduleid']."' and COMID='".$comid."' and SHEET_NO='".$cost_sheet_id."'";
	$result	 	= mysql_query($sql);
	$rows 		= mysql_fetch_assoc($result);
	return $rows[$field];
}


function getCurrentCostSheetStatus($comid,$cost_sheet_id)
{
	$connect 	= $this->funConnect();
	$sql 		= "select VOY_EST_STATUS from freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' and SHEET_NO ='".$cost_sheet_id."' and FINAL=1";
	$result 	= mysql_query($sql);
	while($rows = mysql_fetch_assoc($result))
	{
		$status = $rows['VOY_EST_STATUS'];
	}
	return $status;
}


function getCostSheetDataBasedOnID($id,$field)
{
	$connect	= $this->funConnect();
	$sql 		= "select ".$field." from cost_sheet_name_master where COST_SHEETID='".$id."'";
	$res 		= mysql_query($sql);
	$rows 		= mysql_fetch_assoc($res);
	return $rows[$field];
}


function insertActualCostSheetName()
{
	$connect 	= $this->funConnect();
	$file_name  = $_REQUEST['txtFile'];
	$comid  = $_REQUEST['txtComid1'];
		
	$msg = 4;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "insert into cost_sheet_name_master (SHEET_NAME, COMID, MODULEID, MCOMPANYID, PROCESS) values ('".$file_name."', '".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'Actual')";
	mysql_query($sql1);
	mysql_query("commit");
	return $msg; 
}


function insertCargoReletActualCostSheetName()
{
	$connect 	= $this->funConnect();
	$file_name  = $_REQUEST['txtFile'];
	$comid  = $_REQUEST['txtComid1'];
		
	$msg = 4;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "insert into cost_sheetrelet_name_master (SHEET_NAME, COMID, MODULEID, MCOMPANYID, PROCESS) values ('".$file_name."', '".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'Actual')";
	mysql_query($sql1);
	mysql_query("commit");
	return $msg; 
}


function deleteInOpsEntry($comid)
{
	$connect				= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;	
	$sql = "update freight_cost_estimate_compare set STATUS=3 where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);	
	mysql_query("commit");	
	
	$mysql = "select GEN_AGENCY_ID from generate_agency_letter where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."' and STATUS=2";
	$myres = mysql_query($mysql);
	$myrows = mysql_fetch_assoc($myres);
	
	
	$sql1 = "update generate_agency_letter set STATUS=3 where GEN_AGENCY_ID='".$myrows['GEN_AGENCY_ID']."' and  COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql1);
	mysql_query("commit");
			 
	return $msg;
}


function convertToPostOps($comid)
{
	$connect		= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;	
	$sql = "update freight_cost_estimate_compare set STATUS=2 where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);	
	mysql_query("commit");	 
	return $msg;
}


function insertPerfAtSeaUploadDetails()
{
	$connect = $this->funConnect();
	
	$comid   			= addslashes(trim($_REQUEST['txtMapid']));
	$vesselid 			= addslashes(trim($_REQUEST['txtVesselid']));
	
	$filename 			= $_FILES['txtfile']['name'];
	$tmpFile 			= $_FILES["txtfile"]["tmp_name"];
	move_uploaded_file($_FILES['txtfile']['tmp_name'], '../../attachment/'.$filename);
	
	$data = explode("##",file_get_contents('../../attachment/'.$filename)); 
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "select * from perf_at_sea where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and LOGIN='INTERNAL_USER' and DATE='".date("Y-m-d",strtotime($data[7]))."'";
	$res1 = mysql_query($sql1);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		$rows1 = mysql_fetch_assoc($res1);
		
		$sql2 = "delete from perf_at_sea where PASID='".$rows1['PASID']."'";
		mysql_query($sql2);
	}
	
	//insert query here.............
	$sql = "insert into perf_at_sea (COMID, VESSEL_IMO_ID, MODULEID, MCOMPANYID, LOGIN, VESSEL_NAME, DEP_PORT, ARR_PORT, CONDITION, STOPPAGE, REPORT_TYPE, DATE, TIME, LAT, LONG, ROB_FO, CONS_FO, ROB_DO, CONS_DO, RATE_FO, RATE_DO, RPM, DISTANCE, SPEED, FORCE, CONS_FO_CLEAN, CONS_FO_INERT, CONS_FO_G_FREEING, CONS_FO_HEATING, CONS_DO_CLEAN, CONS_DO_INERT, CONS_DO_G_FREEING, CONS_DO_HEATING, DURATION) values ('".$comid."', '".$vesselid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$data[1]."', '".$data[2]."', '".$data[3]."', '".$data[4]."', '".$data[5]."', '".$data[6]."', '".date("Y-m-d",strtotime($data[7]))."', '".$data[8]."', '".$data[9]."', '".$data[10]."', '".$data[11]."', '".$data[12]."', '".$data[13]."', '".$data[14]."', '".$data[15]."', '".$data[16]."', '".$data[17]."', '".$data[18]."', '".$data[19]."', '".$data[20]."', '".$data[21]."', '".$data[22]."', '".$data[23]."', '".$data[24]."', '".$data[25]."', '".$data[26]."', '".$data[27]."', '".$data[28]."', '".$data[29]."')";
	mysql_query($sql);
	mysql_query("commit");
	
	return $msg; 
}


function insertPerfAtPortUploadDetails()
{
	$connect = $this->funConnect();
	
	$mappingid 			= addslashes(trim($_REQUEST['txtMapid']));
	$vesselid 			= addslashes(trim($_REQUEST['txtVesselid']));
	
	$filename  = $_FILES['txtfile']['name'];
	$tmpFile   = $_FILES["txtfile"]["tmp_name"];
	move_uploaded_file($_FILES['txtfile']['tmp_name'], '../../attachment/'.$filename);
	
	$data = explode("##",file_get_contents('../../attachment/'.$filename)); 

	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "select * from perf_at_port where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and LOGIN='INTERNAL_USER' and DATE='".date("Y-m-d",strtotime($data[7]))."'";
	$res1 = mysql_query($sql1);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		$rows1 = mysql_fetch_assoc($res1);
		
		$sql2  = "delete from perf_at_port where PAPID='".$rows1['PAPID']."'";
		mysql_query($sql2);
	}
	
	//insert query here.............
	$sql = "insert into perf_at_port (MAPPINGID, VESSEL_IMO_ID, MODULEID, MCOMPANYID, LOGIN, VESSEL_NAME, PORT, REPORT_TYPE, CARGO_NAME, DATE, TIME, LOAD_RATE, DIS_RATE, LOAD_RATE_1, DIS_RATE_1, MAN_PRESS, CONS_FO_LDG, CONS_FO_DIS, CONS_DO_LDG, CONS_DO_DIS, CONS_FO_IDLE, CONS_DO_IDLE) values ('".$mappingid."', '".$vesselid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$data[1]."', '".$data[2]."', '".$data[3]."', '".$data[4]."', '".date("Y-m-d",strtotime($data[5]))."', '".$data[6]."', '".$data[7]."', '".$data[8]."', '".$data[9]."', '".$data[10]."', '".$data[11]."', '".$data[12]."', '".$data[13]."', '".$data[14]."', '".$data[15]."', '".$data[16]."', '".$data[17]."')";
	mysql_query($sql);
	mysql_query("commit");
	
	return $msg; 
}




function getWSPCListFP()
{
	$this->funConnect();
	$query = mysql_query("select distinct FP_NAME,FROM_PORT from wspc_master where STATUS=1 order by FP_NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selWSPCFP = @$_REQUEST['selWSPCFP'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['FROM_PORT'];
		 $value= $rows['FP_NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selWSPCFP){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getWSPCListTP()
{
	$this->funConnect();
	$query = mysql_query("select distinct TP_NAME,TO_PORT from wspc_master where STATUS=1 order by TP_NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selWSPCTP = @$_REQUEST['selWSPCTP'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['TO_PORT'];
		 $value= $rows['TP_NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selWSPCTP){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getTCICostSheetRecDetails($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select * from freight_cost_estimete_master where COMID='".$comid."' and SHEET_NO='".$cost_sheet_id."'";	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	return $rec;
}

function getTCICostSheetStatusDetails($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select FINAL_STATUS from freight_cost_estimete_master where COMID='".$comid."' and SHEET_NO='".$cost_sheet_id."'";	
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['FINAL_STATUS'];
}

function getReletSheetStatusDetails($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select FINAL_STATUS from cargo_relet_estimate_masster where COMID='".$comid."' and SHEET_NO='".$cost_sheet_id."'";	
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['FINAL_STATUS'];
}

function getTCICostSheetID($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select FCAID from freight_cost_estimete_master where COMID='".$comid."' and SHEET_NO='".$cost_sheet_id."'";	
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['FCAID'];
}

function getTCICostSheetIDRelet($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select * from cargo_relet_estimate_masster where COMID='".$comid."' and SHEET_NO='".$cost_sheet_id."'";	
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['FCAID'];
}


function getActualSeaPassageData($fcaid)
{
	$connect	= $this->funConnect();
	$sql 		= "select * from fca_tci_actual_sea_passage where FCAID='".$fcaid."'";
	$res 		= mysql_query($sql);
	$i=1;
	while($rows = mysql_fetch_assoc($res))
	{
		if(is_null($rows['FROM_DATE']) || date("Y-m-d",strtotime($rows['FROM_DATE'])) == "1969-12-31" || date("Y-m-d",strtotime($rows['FROM_DATE'])) == "1970-01-01"){$from_date = "";}else{$from_date = date("d-m-Y H:i",strtotime($rows['FROM_DATE']));}
		
		if(is_null($rows['TO_DATE']) || date("Y-m-d",strtotime($rows['TO_DATE'])) == "1969-12-31" || date("Y-m-d",strtotime($rows['TO_DATE'])) == "1970-01-01"){$to_date = "";}else{$to_date = date("d-m-Y H:i",strtotime($rows['TO_DATE']));}
		
		$a[$i] = array( 'FROM_DATE' => $from_date, 'TO_DATE' => $to_date, 'DAYS' => $rows['DAYS'], 'OFF_HIRE_DEV_HRS' => $rows['OFF_HIRE_DEV_HRS'], 'OFF_HIRE_DEV_DAYS' => $rows['OFF_HIRE_DEV_DAYS'], 'OFF_HIRE_IDLE_HRS' => $rows['OFF_HIRE_IDLE_HRS'], 'OFF_HIRE_IDLE_DAYS' => $rows['OFF_HIRE_IDLE_DAYS'], 'MARGIN_HRS' => $rows['MARGIN_HRS'], 'MARGIN_DAYS' => $rows['MARGIN_DAYS'], 'ACTUAL_DAYS' => $rows['ACTUAL_DAYS'] );
		$i++;
	}	
	return $a;
}




function getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$status  = $this->getFreightEstimationStatus($comid);
	$sql  = "select FROM_PORT, TO_PORT, RANDOMID, LOAD_PORT_QTY, DISC_PORT_QTY, PORT_COSTLP_VENDOR, PORT_COSTDP_VENDOR, LOAD_PORT_COST, DISC_PORT_COST, TRANSIT_PORT_COST, PORT_COSTTP_VENDOR, DDCLP_ESTCOST, DDCDP_ESTCOST, LOAD_PORT_RATE, DISC_PORT_RATE, PORT_COSTLP_VENDOR, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP from freight_cost_estimete_slave1 where FCAID='".$cost_sheet_id."' order by FCA_SLAVEID asc";
	$res  = mysql_query($sql);
	while($rows  = mysql_fetch_assoc($res))
	{
		if($this->getPortNameBasedOnID($rows['FROM_PORT']) != "TBN")
		{
			if($rows['PORT_COSTLP_VENDOR'] !='')
		    {
				$arr[] = "LP@@".$rows['FROM_PORT']."@@".$rows['RANDOMID']."@@".$rows['LOAD_PORT_QTY']."@@".$rows['PORT_COSTLP_VENDOR']."@@".$rows['DDCLP_ESTCOST']."@@".$rows['LOAD_PORT_RATE']."@@".$rows['PORT_COSTLP_VENDOR']."@@".$rows['IS_SHOW_DDCLP'];
			}
			if($rows['PORT_COSTDP_VENDOR'] !='' )
		    {
				$arr[] = "DP@@".$rows['TO_PORT']."@@".$rows['RANDOMID']."@@".$rows['DISC_PORT_QTY']."@@".$rows['PORT_COSTDP_VENDOR']."@@".$rows['DDCDP_ESTCOST']."@@".$rows['DISC_PORT_RATE']."@@".$rows['PORT_COSTDP_VENDOR']."@@".$rows['IS_SHOW_DDCDP'];
			}
			if($rows['PORT_COSTTP_VENDOR']!='')
		    {
				$arr[] = "TP@@".$rows['FROM_PORT']."@@".$rows['RANDOMID']."@@0@@".$rows['PORT_COSTTP_VENDOR'];;
			}
		}
	}
	return $arr;
}



function getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBNForVcIn($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$status  = $this->getFreightEstimationStatusForVcIn($comid);
	$sql  = "select * from freight_cost_estimete_in_slave1 where FCAID='".$cost_sheet_id."' order by FCA_SLAVEID asc";

	// echo $sql;

	// die();

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

		// echo '<pre>';

		// print_r($rows);
		

		
		if($this->getPortNameBasedOnID($rows['FROM_PORT']) != "TBN")
		{

			
			if($rows['PORT_COSTLP_VENDOR'] !='')
		    {

				
				$arr[] = "LP@@".$rows['FROM_PORT']."@@".$rows['RANDOMID']."@@".$rows['LOAD_PORT_QTY']."@@".$rows['PORT_COSTLP_VENDOR']."@@".$rows['DDCLP_ESTCOST']."@@".$rows['LOAD_PORT_RATE']."@@".$rows['PORT_COSTLP_VENDOR']."@@".$rows['IS_SHOW_DDCLP'];
			}
			if($rows['PORT_COSTDP_VENDOR'] !='' )
		    {
				
				$arr[] = "DP@@".$rows['TO_PORT']."@@".$rows['RANDOMID']."@@".$rows['DISC_PORT_QTY']."@@".$rows['PORT_COSTDP_VENDOR']."@@".$rows['DDCDP_ESTCOST']."@@".$rows['DISC_PORT_RATE']."@@".$rows['PORT_COSTDP_VENDOR']."@@".$rows['IS_SHOW_DDCDP'];
			}
			if($rows['PORT_COSTTP_VENDOR']!='')
		    {
				echo $this->getPortNameBasedOnID($rows['FROM_PORT']);die();
				$arr[] = "TP@@".$rows['FROM_PORT']."@@".$rows['RANDOMID']."@@0@@".$rows['PORT_COSTTP_VENDOR'];;
			}
		}
	}

	
	// echo '<pre>';

	// print_r($arr);
	return $arr;
}



function getLoadPortAndDischargePortRandomArrBasedOnCommidAndProcessWithoutTBN($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$status  = $this->getFreightEstimationStatus($comid);
	$sql  = "select FROM_PORT, TO_PORT from freight_cost_estimete_slave1 where FCAID='".$cost_sheet_id."' order by FCA_SLAVEID asc";
	$res  = mysql_query($sql);
	$i = 0 ;
	while($rows  = mysql_fetch_assoc($res))
	{$i = $i + 1;
		if($this->getPortNameBasedOnID($rows['FROM_PORT']) != "TBN")
		{
			$arr[] = "LP-".$rows['RANDOMID'];
			$arr[] = "DP-".$rows['RANDOMID'];
			$arr[] = "TP-".$rows['RANDOMID'];
		}
	}
	return $arr;
}


function getVendorListNewData($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from vendor_master where CODE='".$id."' and MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getContractTypeMasterData($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from contract_type_master where CONTRACTTYPEID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getLawArbitrationNameBasedOnID($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM lawarbitration_master_list where LAWARBITRA_ID='".$id."'";
	$result = mysql_query($query);
	$rows = mysql_fetch_assoc($result); 
	return $rows['LAW_ARBITRATION'];
}


function updatecheckListChartererPniByVendorListNewForCOA($id,$saveid)
{
	$this->funConnect();
	$query = mysql_query("select * from vendor_master where STATUS=1 and VENDOR_TYPEID=".$id." and MCOMPANYID='".$_SESSION['company']."' order by NAME ");
	echo '<option value = "" >---Select from list---</option>';
	@$selVendor = @$_REQUEST['selVendor'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CODE'];
		 $value= $rows['NAME']." ( ".$rows['CODE']." )";
		 echo '<option value='.$key;
		 if($saveid == $key){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}


function getFCAIDBasedOnid($mappingid,$cost_sheet_id)
{
	$connect				= $this->funConnect();
	$sql = "select FCAID from freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$mappingid."' and SHEET_NO='".$cost_sheet_id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['FCAID'];
}


function getPumpsType()
{
$state = array( 1 =>'Pumps' , 2 =>'No - Pumps');
$selPpType = @$_REQUEST['selPpType'];
echo "<option value=''>--Select from list--</option>";
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selPpType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getFixtureTypeList1($selFType)
{
	$charterertype = array( 1 =>'Time Charterer Out' , 2 =>'Voyage Charterer Out');
	$selFType = @$_REQUEST['selFType'];
	while ($array_cell = each($charterertype)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selFType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getActualLoadPortDataJson($fcaid)
{
	$connect = $this->funconnect();
	$sql = "select * from fca_tci_actual_lp where FCAID='".$fcaid."'";
	$res = mysql_query($sql);
	$i=1;
	while($rows = mysql_fetch_assoc($res))
	{
		if(is_null($rows['IDLE_FROM_DATE']) || date("Y-m-d",strtotime($rows['IDLE_FROM_DATE'])) == "1969-12-31" || date("Y-m-d",strtotime($rows['IDLE_FROM_DATE'])) == "1970-01-01"){$ifrom_date = "";}else{$ifrom_date = date("d-M-Y H:i",strtotime($rows['IDLE_FROM_DATE']));}
		if(is_null($rows['IDLE_TO_DATE']) || date("Y-m-d",strtotime($rows['IDLE_TO_DATE'])) == "1969-12-31" || date("Y-m-d",strtotime($rows['IDLE_TO_DATE'])) == "1970-01-01"){$ito_date = "";}else{$ito_date = date("d-M-Y H:i",strtotime($rows['IDLE_TO_DATE']));}
		
		if(is_null($rows['WRKING_FROM_DATE']) || date("Y-m-d",strtotime($rows['WRKING_FROM_DATE'])) == "1969-12-31" || date("Y-m-d",strtotime($rows['WRKING_FROM_DATE'])) == "1970-01-01"){$wfrom_date = "";}else{$wfrom_date = date("d-M-Y H:i",strtotime($rows['WRKING_FROM_DATE']));}
		if(is_null($rows['WRKING_TO_DATE']) || date("Y-m-d",strtotime($rows['WRKING_TO_DATE'])) == "1969-12-31" || date("Y-m-d",strtotime($rows['WRKING_TO_DATE'])) == "1970-01-01"){$wto_date = "";}else{$wto_date = date("d-M-Y H:i",strtotime($rows['WRKING_TO_DATE']));}
		
		$a[] = array('LOADPORTID' => $rows['LOADPORTID'], 'IDLE_FROM_DATE' => $ifrom_date, 'IDLE_TO_DATE' => $ito_date, 'IDLE_DAYS' => $rows['IDLE_DAYS'], 'WRKING_FROM_DATE' => $wfrom_date, 'WRKING_TO_DATE' => $wto_date, 'WRKING_DAYS' => $rows['WRKING_DAYS'], 'REASON_OFF_HIRE' => $rows['REASON_OFF_HIRE'], 'OFF_HIRE_HRS' => $rows['OFF_HIRE_HRS'], 'OFF_HIRE_DAYS' => $rows['OFF_HIRE_DAYS'], 'ACTUAL_DAYS' => $rows['ACTUAL_DAYS'], 'PUMPS' => abs($rows['CRANES']), 'LPTERM' => abs($rows['LPTERMS']) );
		$i++;
	}	
	echo json_encode($a);
}


function getFDA($comid,$port,$portid,$randomno)
{
	$connect = $this->funConnect();
	
	$rows = mysql_fetch_assoc($res);
	$sql1 = "select TTL_ACTUAL_COST_USD from loadport_cost_master where SUBMITID=5 and COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$randomno."'";
	$res1 = mysql_query($sql1) or die($sql1);
	$rec1 = mysql_num_rows($res1);
	$rows1 = mysql_fetch_assoc($res1);
	if($rec1==0)
	{
	   return 0;
	}
	else
	{
	   return $rows1['TTL_ACTUAL_COST_USD'];
	}
   
}


function getBLDateBasedOnMappingidAndPort($mappingid,$port,$portid)
{
	$connect = $this->funConnect();
	$sql = "select BL_DATE from sof_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$mappingid."' and LOGIN = 'INTERNAL_USER' and PORT='".$port."' and PORTID='".$portid."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec > 0)
	{
		$rows = mysql_fetch_assoc($res);
		return date("d-m-Y",strtotime($rows['BL_DATE']));
	}
	else
	{
		return '';
	}
}



function getVendorListNewUpdate()
{
	$this->funConnect();
	$query = mysql_query("select NAME, CODE from vendor_master where STATUS=1 and MCOMPANYID='".$_SESSION['company']."' order by NAME ");
	echo '<option value = "" >---Select from list---</option>';
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CODE'];
		 $value= addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
		 echo '<option value="'.$key.'">'.$value.'</option>';
		}
}


function getDemurrageData($mappingid,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from laytime_master where MAPPINGID='".$mappingid."' and LOGIN='INTERNAL_USER' and MCOMPANYID='".$_SESSION['company']."' and MODULEID='".$_SESSION['moduleid']."' and PORT='DP' and ENTITY='SHIP_OWNER' order by LAYTIME_ID";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$value = "";
	if($rec > 0)
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$value = $rows[$field];
		}
		return $value;
	}
	else
	{
		return "0.00";
	}
}


function getDemurrageData1($mappingid,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from laytime_master where MAPPINGID='".$mappingid."' and LOGIN='INTERNAL_USER' and MCOMPANYID='".$_SESSION['company']."' and MODULEID='".$_SESSION['moduleid']."' and PORT='LP' and ENTITY='SHIP_OWNER' order by LAYTIME_ID";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$value = "";
	if($rec > 0)
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$value = $rows[$field];
		}
		return $value;
	}
	else
	{
		return "0.00";
	}
}


function insertTCICostSheetDetails()
{	
	$connect = $this->funConnect();
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 		= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	$rdoQty             = addslashes(trim($_REQUEST['rdoQty']));
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
	$txtAddnlCRatePer                  = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	
	
	$selOpenPort 	 	= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 		= addslashes(trim($_REQUEST['selZone']));
	$selBroker          = addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 	= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 	= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    		= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    = addslashes(trim($_REQUEST['selOwner']));
	$txtDisponentOwner	= addslashes(trim($_REQUEST['txtDisponentOwner']));
	if($_REQUEST['txtFDate']!="")
	{
	$txtFDate     		= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	}

	else{$txtFDate     		= "1970-01-01";}
	if($_REQUEST['txtTDate']!="")
	{
	$txtTDate     		= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	}
	else{$txtTDate     		= "1970-01-01";}
	if($_REQUEST['txtETADate']!="")
	{
	$txtETADate     		= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	}
	else{$txtETADate     		= "1970-01-01";}
	if($_REQUEST['txtCPDate']!="")
	{
	$txtCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	}
	else{$txtCPDate     		= "1970-01-01";}
	$txtNotes     		= addslashes(trim($_REQUEST['txtNotes']));
	
	$txtCID 	 		= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       = addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 		= implode(',',$_REQUEST['selMType']);
	$txtMCode    		= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance	= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    = addslashes(trim($_REQUEST['selDPort']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	
	$txtTFUMTManual 		   = addslashes(trim($_REQUEST['txtTFUMTManual']));
	$txtTDUMTManual            = addslashes(trim($_REQUEST['txtTDUMTManual']));
	$txtTFOCOffHire		 	   = addslashes(trim($_REQUEST['txtTFOCOffHire']));
	$txtTDOCOffHire     	   = addslashes(trim($_REQUEST['txtTDOCOffHire']));
	$selDTCVendor       	   = addslashes(trim($_REQUEST['selDTCVendor']));
	$txtFGFFVendor       	   = addslashes(trim($_REQUEST['txtFGFFVendor']));
	
	$txtCVE           	   = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt       	   = addslashes(trim($_REQUEST['txtCVEAmt']));
	$selCVEVendor          = addslashes(trim($_REQUEST['selCVEVendor']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selBroVendor       = addslashes(trim($_REQUEST['selBroVendor']));
	$selILOHCVendor     = addslashes(trim($_REQUEST['selILOHCVendor']));
	$txtDistributedRemarks     = addslashes(trim($_REQUEST['txtDistributedRemarks']));  
	
	if(isset($_REQUEST['txtHiddenHirage']))
	{
	   $txtHiddenHirage     		= $_REQUEST['txtHiddenHirage'];
	}
	else{$txtHiddenHirage     		= $_REQUEST['txtHireargeAmt'];}
	
	if($_REQUEST['txtLCSDate']!="")
	{
	$txtLCSDate   		= date("Y-m-d",strtotime($_REQUEST['txtLCSDate']));
	}
	else{$txtLCSDate     		= "1970-01-01";}
	if($_REQUEST['txtLCFDate']!="")
	{
	$txtLCFDate     	= date("Y-m-d",strtotime($_REQUEST['txtLCFDate']));
	}
	else{$txtLCFDate     		= "1970-01-01";}
	
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$txtCRMFILE2							= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2							= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['attach_file1']);
	$name = $this->getUploadName($_FILES['attach_file1']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$selLumsumVendor 	    = addslashes(trim($_REQUEST['selLumsumVendor']));
	$txtLumpsumQty          = $_REQUEST['txtLumpsumQty'];
	
	$txtBaseRateFloating    = addslashes(trim($_REQUEST['txtBaseRateFloating']));
	$txtBaseRateFixed       = addslashes(trim($_REQUEST['txtBaseRateFixed']));
	$txtBaseRateAverage     = addslashes(trim($_REQUEST['txtBaseRateAverage']));
	
	$txtGFreightFloating    = addslashes(trim($_REQUEST['txtGFreightFloating']));
	$txtGFreightFixed       = addslashes(trim($_REQUEST['txtGFreightFixed']));
	$txtGFreightAverage     = addslashes(trim($_REQUEST['txtGFreightAverage']));
	
	$txtNFreightFloating    = addslashes(trim($_REQUEST['txtNFreightFloating']));
	$txtNFreightFixed       = addslashes(trim($_REQUEST['txtNFreightFixed']));
	$txtNFreightAverage     = addslashes(trim($_REQUEST['txtNFreightAverage']));
	
	$txtOExpensesFloating   = addslashes(trim($_REQUEST['txtOExpensesFloating']));
	$txtOExpensesFixed      = addslashes(trim($_REQUEST['txtOExpensesFixed']));
	$txtOExpensesAverage    = addslashes(trim($_REQUEST['txtOExpensesAverage']));
	
	$txtVEarningFloating    = addslashes(trim($_REQUEST['txtVEarningFloating']));
	$txtVEarningFixed       = addslashes(trim($_REQUEST['txtVEarningFixed']));
	$txtVEarningAverage     = addslashes(trim($_REQUEST['txtVEarningAverage']));
	
	$txtDailyEarningFloating= addslashes(trim($_REQUEST['txtDailyEarningFloating']));
	$txtDailyEarningFixed   = addslashes(trim($_REQUEST['txtDailyEarningFixed']));
	$txtDailyEarningAverage = addslashes(trim($_REQUEST['txtDailyEarningAverage']));
	
	$txtTCEMonthFloating    = addslashes(trim($_REQUEST['txtTCEMonthFloating']));
	$txtTCEMonthFixed       = addslashes(trim($_REQUEST['txtTCEMonthFixed']));
	$txtTCEMonthAverage     = addslashes(trim($_REQUEST['txtTCEMonthAverage']));
	
	$txtOPExpensesFloating  = addslashes(trim($_REQUEST['txtOPExpensesFloating']));
	$txtOPExpensesFixed     = addslashes(trim($_REQUEST['txtOPExpensesFixed']));
	$txtOPExpensesAverage   = addslashes(trim($_REQUEST['txtOPExpensesAverage']));
	
	$txtNetDailyEarningFloating= addslashes(trim($_REQUEST['txtNetDailyEarningFloating']));
	$txtNetDailyEarningFixed= addslashes(trim($_REQUEST['txtNetDailyEarningFixed']));
	$txtNetDailyEarningAverage= addslashes(trim($_REQUEST['txtNetDailyEarningAverage']));
	
	$txtNetDailyProfitFloating= addslashes(trim($_REQUEST['txtNetDailyProfitFloating']));
	$txtNetDailyProfitFixed = addslashes(trim($_REQUEST['txtNetDailyProfitFixed']));
	$txtNetDailyProfitAverage= addslashes(trim($_REQUEST['txtNetDailyProfitAverage']));
	$selCargoPlanning       = $_REQUEST['selCargoPlanning'];
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$rdoTankType        = addslashes(trim($_REQUEST['rdoTankType']));
	$txtTCNo                = addslashes(trim($_REQUEST['txtTCNo']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	$selPeriodContract = addslashes(trim($_REQUEST['selPeriodContract']));
	
	$txtBLCQMT              = addslashes(trim($_REQUEST['txtBLCQMT']));
    $txtLessPerQty          = addslashes(trim($_REQUEST['txtLessPerQty']));
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	if($_REQUEST['txtTCDeliveryDate']!="")
	{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate']));}
	else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtTCReDeliveryDate']!="")
	{$txtTCReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate']));}
	else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	$txtTCDelivery = addslashes(trim($_REQUEST['txtTCDelivery']));
	$txtTCReDelivery = addslashes(trim($_REQUEST['txtTCReDelivery']));
	$txtTankerFreightRate = addslashes(trim($_REQUEST['txtTankerFreightRate']));

    $txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['comid'];
	$update_status       	   = addslashes(trim($_REQUEST['update_status']));
	
	$sql_fetch = "select FCAID from freight_cost_estimete_master where COMID='".$comid."' and SHEET_NO='".$sheet_no."'";
	$res_fetch = mysql_query($sql_fetch) or die($sql_fetch);
	$num_fetch = mysql_num_rows($res_fetch);
	if($num_fetch == 0)
	{
		$sql = "insert into freight_cost_estimete_master (FIXTURETYPEID, TRANS_DATE, MODULEID, MCOMPANYID, ADDED_BY, ADD_ON_DATE, VESSEL_IMO_ID, VESSEL_TYPE, FLAG, VOYAGE_NO, VOYAGE_NAME, DWT_SUMMER, DWT_TOPICAL, RDO_CAP, GRAIN_CAP, BALE_CAP, SF, LODABLE, GNRT, LOA, GEAR, BUILD_YEAR, BEAM, TPC, BFULLSPEED, BECOSPEED1, BECOSPEED2, LFULLSPEED, LECOSPEED1, LECOSPEED2, BFOFULLSPEED, BFOECOSPEED1, BFOECOSPEED2, LFOFULLSPEED, LFOECOSPEED1, LFOECOSPEED2, PIFOFULLSPEED, PWFOFULLSPEED, BDOFULLSPEED, BDOECOSPEED1, BDOECOSPEED2, LDOFULLSPEED, LDOECOSPEED1, LDOECOSPEED2, PIDOFULLSPEED, PWDOFULLSPEED, RDO_MARKER, RDO_DWT, FREIGHT_GROSS, LUMSUM, CARGO_RATE, QUANTITY, CARGO_TYPE, CARGO_ID, DF_QUANTITY, ADDNL_QUANTITY, LADEN_DIST, BALLAST_DIST, LADEN_DAYS, BALLAST_DAYS, TOTAL_PASSAGE_DAYS, IDEAL_DAYS, WORKING_DAYS, TOTAL_DAYS, TOTAL_DISTANCE, FO_CONSP, DO_CONSP, GROSS_PREIGHT_ADJ, DEAD_PREIGHT_ADJ, ADDNL_PREIGHT_ADJ, TOTAL_PREIGHT_ADJ, GROSS_PREIGHT_ADJ_PRMT, DEAD_PREIGHT_ADJ_PRMT, ADDNL_PREIGHT_ADJ_PRMT, TOTAL_PREIGHT_ADJ_PRMT, ADDRESS_COMMISSION_PER, ADDRESS_COMMISSION_AMT, ADDRESS_COMMISSION_PRMT, BROKERAGE_PER, BROKERAGE_AMT, NET_PAYABLE, FINAL_NET_FREIGHT, FINAL_NET_FREIGHT_PRMT, BROKERAGE_COMMISSION_PER, BROKERAGE_COMMISSION_AMT, TOTAL_ORC_EXP_AMT, TOTAL_ORC_EXP_PRMT, REVENUES_FREIGHT, TOTAL_OWNER_EXP, CHARTERER_EXP, VOYAGE_EARNING, DAILY_EARNING, DAILY_VESSEL_OPERATION_EXP, TOTAL_VOYAGE_EARNING, NET_DAILY_EARNING, NET_DAILY_PROFIT, PROFIT_LOSS, RDO_QTY  , OPEN_PORT, ZONE_OPEN, BROKER, COA_SPOT, COA_NUMBER, COA_NUMBER_LIFT, NO_OF_SHIPMENT, OWNER, DISPONENT_OWNER, LAYCAN_START_DATE, LAYCAN_FINISH_DATE, ETA_DATE, CP_DATE, REMARKS, ATTACHMENT, ATTACHMENT_NAME, CARGOID, SHIPPER, TOLERANCE, MATERIALID, MATERIAL_CODE, TERM_TOLERANCE, LPID, DPID, LAYCAN_CARGO_START_DATE, LAYCAN_CARGO_FINISH_DATE, HIREAGE_AMT, HIREAGE_PERCENT, HIREAGE_PER_AMT, HIREAGE_NETT_AMT, QTY_TYPE_RADIO, AGREED_GROSS_FREIGHT_LOCAL, CURRENCYID, EXCHANGE_RATE, TTL_FO_CONSP_MT_MANUAL, TTL_DO_CONSP_MT_MANUAL, TTL_FO_CONSP_OFFHIRE, TTL_DO_CONSP_OFFHIRE, SHEET_NO, COMID, DTCVENDORID, FINAL_STATUS, FGFF_VENDORID, CVE_AMT, CVE_TOTALAMT, CVE_VENDORID, BALLAST_BONUS, BUNKER_EXPENSES, PORT_EXPENSES, BROKERAGE_VENDORID, ILOHC_VENDORID, HIDDEN_HIRAGE, DISTRIBUTED_REMARKS, FIXED, ADDNL_FREIGHT_PER, ESTIMATE_TYPE, GAS_MARKET, GAS_BALTIC, ADDNL_PRENIUM, GAS_BASE_RATE, GAS_QUANTITY, GAS_LUMSUM, TANK_WS_FROM, TANK_WS_TO, TANK_FIXED_DIFF, TANK_QUANTITY, ATTACHMENT2, ATTACHMENT2_NAME, CHK_LUMPSUM, LUMPSUMAMT, WS_QTY, LUMP_VENDOR, BASERATE_FLOAT, BASERATE_FIXED, BASERATE_AVERAGE, GROSS_FREIGHT_FLOAT, GROSS_FREIGHT_FIXED, GROSS_FREIGHT_AVERAGE, NETFREIGHT_FLOAT, NETFREIGHT_FIXED, NETFREIGHT_AVERAGE, OWNER_EXPENSES_FLOAT, OWNER_EXPENSES_FIXED, OWNER_EXPENSES_AVERAGE, VEARNING_FLOAT, VEARNING_FIXED, VEARNING_AVERAGE, TCEEARNING_FLOAT, TCEEARNING_FIXED, TCEEARNING_AVERAGE, TCE_MONTH_FLOAT, TCE_MONTH_FIXED, TCE_MONTH_AVERAGE, OEXPENSES_FLOAT, OEXPENSES_FIXED, OEXPENSES_AVERAGE, NET_DAILY_ER_FLOAT, NET_DAILY_ER_FIXED, NET_DAILY_ER_AVERAGE, NET_DAILY_PROFIT_FLOAT, NET_DAILY_PROFIT_FIXED, NET_DAILY_PROFIT_AVERAGE, OPEN_CARGOID, GROSS_BREAKDOWN, BREAKDOWN_MT, TANKER_RADIO_SINGLE_DIS, TC_NO, GROSS_HIERAGE_AMOUNT, HIERAGE_CVE, HIERAGE_CVE_AMOUNT, OFF_HIRE_CVE, OFF_HIRE_CVE_AMOUNT, LESS_OFF_HIRE, FINAL_HIERAGE_AMOUNT, HIERAGE_BROKER_PERCENT, HIERAGE_BROKER_AMT, TC_HIRE_DAYS, TC_CP_DATE, PERIODID, LESS_PER_BLQTY, BL_QTY_FREIGHT, TC_DELIVERY_DATE, TC_RE_DELIVERY_DATE, TC_DELIVERY_RANGE, TC_RE_DELIVERY_RANGE, ACTUAL_PL, TANKER_FREIGHT_RATE, TANK_CLEANING_SECA_HRS, TANK_CLEANING_NONSECA_HRS, INERTING_SECA_HRS, INERTING_NONSECA_HRS, GAS_FREEING_SECA_HRS, GAS_FREEING_NONSECA_HRS, HEATING_SECA_HRS, HEATING_NONSECA_HRS, HEATING_SECA_HRS_1, HEATING_NONSECA_HRS_1) values ('".$this->getCheckNullValue($selFType)."','".$txtDate."','".$_SESSION['moduleid']."','".$this->getCheckNullValue($_SESSION['company'])."','".$_SESSION['uid']."', NOW(),'".$this->getCheckNullValue($selVName)."','".$txtVType."','".$txtFlag."','".$txtVNo."','".$txtENo."','".$this->getCheckNullValue($txtDWTS)."','".$this->getCheckNullValue($txtDWTT)."','".$this->getCheckNullValue($rdoCap)."','".$this->getCheckNullValue($txtGCap)."','".$this->getCheckNullValue($txtBCap)."','".$this->getCheckNullValue($txtSF)."','".$this->getCheckNullValue($txtLoadable)."','".$this->getCheckNullValue($txtGNRT)."','".$this->getCheckNullValue($txtLOA)."','".$txtGear."','".$txtBuiltYear."','".$this->getCheckNullValue($txtBeam)."','".$this->getCheckNullValue($txtTPC)."','".$this->getCheckNullValue($txtBFullSpeed)."','".$this->getCheckNullValue($txtBEcoSpeed1)."','".$this->getCheckNullValue($txtBEcoSpeed2)."','".$this->getCheckNullValue($txtLFullSpeed)."','".$this->getCheckNullValue($txtLEcoSpeed1)."','".$this->getCheckNullVal($txtLEcoSpeed2)."','".$this->getCheckNullVal($txtBFOFullSpeed)."','".$this->getCheckNullVal($txtBFOEcoSpeed1)."','".$this->getCheckNullVal($txtBFOEcoSpeed2)."','".$this->getCheckNullVal($txtLFOFullSpeed)."','".$this->getCheckNullVal($txtLFOEcoSpeed1)."','".$this->getCheckNullVal($txtLFOEcoSpeed2)."', '".$this->getCheckNullValue($txtPIFOFullSpeed)."', '".$this->getCheckNullValue($txtPWFOFullSpeed)."','".$this->getCheckNullValue($txtBDOFullSpeed)."','".$this->getCheckNullValue($txtBDOEcoSpeed1)."','".$this->getCheckNullVal($txtBDOEcoSpeed2)."','".$this->getCheckNullVal($txtLDOFullSpeed)."','".$this->getCheckNullVal($txtLDOEcoSpeed1)."','".$this->getCheckNullVal($txtLDOEcoSpeed2)."','".$this->getCheckNullVal($txtPIDOFullSpeed)."','".$this->getCheckNullVal($txtPWDOFullSpeed)."','".$this->getCheckNullVal($rdoMMarket)."','".$this->getCheckNullValue($rdoDWT)."','".$this->getCheckNullVal($txtMTCPDRate)."','".$this->getCheckNullVal($txtMLumpsum)."','".$this->getCheckNullVal($txtAddnlCRate)."','".$this->getCheckNullVal($txtCQMT)."','".$this->getCheckNullVal($selCType)."','".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."','".$this->getCheckNullVal($txtDFQMT)."', '".$this->getCheckNullValue($txtAddnlQMT)."', '".$this->getCheckNullValue($txtLDist)."','".$this->getCheckNullValue($txtBDist)."','".$this->getCheckNullValue($txtLDays)."','".$this->getCheckNullVal($txtBDays)."','".$this->getCheckNullVal($txtTSDays)."','".$this->getCheckNullVal($txtTtPIDays)."','".$this->getCheckNullVal($txtTtPWDays)."','".$this->getCheckNullVal($txtTDays)."','".$this->getCheckNullVal($txtTDist)."','".$this->getCheckNullVal($txtTFUMT)."', '".$this->getCheckNullVal($txtTDUMT)."','".$this->getCheckNullValue($txtFrAdjUsdGF)."','".$this->getCheckNullVal($txtFrAdjUsdDF)."','".$this->getCheckNullVal($txtFrAdjUsdAF)."','".$this->getCheckNullVal($txtFrAdjUsdTF)."','".$this->getCheckNullVal($txtFrAdjUsdGFMT)."','".$this->getCheckNullVal($txtFrAdjUsdDFMT)."','".$this->getCheckNullVal($txtFrAdjUsdAFMT)."','".$this->getCheckNullVal($txtFrAdjUsdTFMT)."',    '".$this->getCheckNullValue($txtFrAdjPerAC)."', '".$this->getCheckNullValue($txtFrAdjUsdAC)."', '".$this->getCheckNullValue($txtFrAdjUsdACMT)."','".$this->getCheckNullValue($txtFrAdjPerAgC)."','".$this->getCheckNullVal($txtFrAdjUsdAgC)."','".$this->getCheckNullVal($txtFrAdjUsdFP)."','".$this->getCheckNullVal($txtFGFFD)."','".$this->getCheckNullVal($txtFGFFDMT)."',  '".$this->getCheckNullVal($txtBrCommPercent)."','".$this->getCheckNullVal($txtBrComm)."','".$this->getCheckNullVal($txtTTLORCAmt)."', '".$this->getCheckNullVal($txtTTLORCCostMT)."','".$this->getCheckNullVal($txtRevenue)."',    '".$this->getCheckNullValue($txtTTLOwnersExpenses)."', '".$this->getCheckNullValue($txtTTLCharterersExpenses)."', '".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtDailyEarnings)."','".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."','".$this->getCheckNullVal($txtGTTLVoyageEarnings)."','".$this->getCheckNullVal($txtNettDailyEarnings)."','".$this->getCheckNullVal($txtNettDailyProfit)."',  '".$this->getCheckNullVal($txtPL)."', '".$this->getCheckNullVal($rdoQty)."', '".$selOpenPort."', '".$selZone."', '".$selBroker."', '".$selCOASpot."', '".$selCOA."', '".$txtNoLift."', '', '".$selOwner."', '".$txtDisponentOwner."', '".$txtFDate."', '".$txtTDate."', '".$txtETADate."', '".$txtCPDate."', '".$txtNotes."', '".$upload1."', '".$name1."', '".$txtCID."', '".$selShipper."', '".$txtTolerance."', '".$selMType."', '".$txtMCode."', '".$txtTermTolerance."', '".$selLPort."', '".$selDPort."', '".$txtLCSDate."', '".$txtLCFDate."','".$this->getCheckNullVal($txtHireargeAmt)."','".$this->getCheckNullVal($txtHireargePercent)."','".$this->getCheckNullVal($txtHireargePercentAmt)."', '".$this->getCheckNullVal($txtNettHireargeAmt)."', '".$rdoQtyType."', '".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', '".$this->getCheckNullVal($selCurrencyMarList)."', '".$this->getCheckNullVal($txtMarExchangeRate)."'   , '".$this->getCheckNullVal($txtTFUMTManual)."', '".$this->getCheckNullVal($txtTDUMTManual)."', '".$this->getCheckNullVal($txtTFOCOffHire)."', '".$this->getCheckNullVal($txtTDOCOffHire)."', '".$this->getCheckNullVal($sheet_no)."', '".$this->getCheckNullVal($comid)."', '".$selDTCVendor."', '".$update_status."', '".$txtFGFFVendor."', '".$this->getCheckNullVal($txtCVE)."', '".$this->getCheckNullVal($txtCVEAmt)."', '".$this->getCheckNullVal($selCVEVendor)."'    , '".$this->getCheckNullVal($txtBallastBonus)."', '".$this->getCheckNullVal($txtTotalBunkerCost)."', '".$this->getCheckNullVal($txtTotalPortCost)."' , '".$selBroVendor."', '".$selILOHCVendor."', '".$this->getCheckNullVal($txtHiddenHirage)."', '".$txtDistributedRemarks."', 1, '".$this->getCheckNullVal($txtAddnlCRatePer)."', '".$this->getCheckNullVal($rdoEstimateType)."', '".$this->getCheckNullVal($rdoQtyMar)."', '".$this->getCheckNullVal($txtBalticRate)."', '".$this->getCheckNullVal($txtAdnlPrenium)."', '".$this->getCheckNullVal($txtBaseRate)."', '".$this->getCheckNullVal($txtGasCQMT)."', '".$this->getCheckNullVal($txtGASLumpsum)."', '".$this->getCheckNullVal($selWSFPort)."', '".$this->getCheckNullVal($selWSTPort)."', '".$this->getCheckNullVal($txtFixedDiff)."', '".$this->getCheckNullVal($txtTankQuantity)."', '".$upload2."', '".$name2."', '".$this->getCheckNullVal($ChkLumpsum)."', '".$this->getCheckNullVal($txtLumpsum)."','".$this->getCheckNullVal($txtLumpsumQty)."', '".$selLumsumVendor."', '".$this->getCheckNullVal($txtBaseRateFloating)."', '".$this->getCheckNullVal($txtBaseRateFixed)."', '".$this->getCheckNullVal($txtBaseRateAverage)."', '".$this->getCheckNullVal($txtGFreightFloating)."', '".$this->getCheckNullVal($txtGFreightFixed)."', '".$this->getCheckNullVal($txtGFreightAverage)."', '".$this->getCheckNullVal($txtNFreightFloating)."', '".$this->getCheckNullVal($txtNFreightFixed)."', '".$this->getCheckNullVal($txtNFreightAverage)."', '".$this->getCheckNullVal($txtOExpensesFloating)."', '".$this->getCheckNullVal($txtOExpensesFixed)."', '".$this->getCheckNullVal($txtOExpensesAverage)."', '".$this->getCheckNullVal($txtVEarningFloating)."', '".$this->getCheckNullVal($txtVEarningFixed)."', '".$this->getCheckNullVal($txtVEarningAverage)."', '".$this->getCheckNullVal($txtDailyEarningFloating)."', '".$this->getCheckNullVal($txtDailyEarningFixed)."', '".$this->getCheckNullVal($txtDailyEarningAverage)."', '".$this->getCheckNullVal($txtTCEMonthFloating)."', '".$this->getCheckNullVal($txtTCEMonthFixed)."', '".$this->getCheckNullVal($txtTCEMonthAverage)."', '".$this->getCheckNullVal($txtOPExpensesFloating)."', '".$this->getCheckNullVal($txtOPExpensesFixed)."', '".$this->getCheckNullVal($txtOPExpensesAverage)."', '".$this->getCheckNullVal($txtNetDailyEarningFloating)."', '".$this->getCheckNullVal($txtNetDailyEarningFixed)."', '".$this->getCheckNullVal($txtNetDailyEarningAverage)."', '".$this->getCheckNullVal($txtNetDailyProfitFloating)."', '".$this->getCheckNullVal($txtNetDailyProfitFixed)."', '".$this->getCheckNullVal($txtNetDailyProfitAverage)."', '".$this->getCheckNullVal($selCargoPlanning)."', '".$this->getCheckNullVal($txtGrossBreakeven)."', '".$this->getCheckNullVal($txtBreakevenMT)."', '".$this->getCheckNullVal($rdoTankType)."', '".$txtTCNo."', '".$this->getCheckNullVal($txtGrossHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeCVE)."', '".$this->getCheckNullVal($txtHireargeCVEAMT)."', '".$this->getCheckNullVal($txtOffHireCVE)."', '".$this->getCheckNullVal($txtOffHireCVEAMT)."', '".$this->getCheckNullVal($txtLessOffHire)."', '".$this->getCheckNullVal($txtFinalHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeBroPercent)."', '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', '".$this->getCheckNullVal($txtTotalVoyageDays)."', '".$txtTC_CPDate."', '".$this->getCheckNullValue($selPeriodContract)."', '".$this->getCheckNullValue($txtLessPerQty)."', '".$this->getCheckNullValue($txtBLCQMT)."', '".$txtTCDeliveryDate."', '".$txtTCReDeliveryDate."', '".$txtTCDelivery."', '".$txtTCReDelivery."',  '".$this->getCheckNullVal($txtPL)."', '".$txtTankerFreightRate."', '".$this->getCheckNullVal($txtTKSECAHrs)."', '".$this->getCheckNullVal($txtTKNONSECAHrs)."', '".$this->getCheckNullVal($txtInertSECAHrs)."', '".$this->getCheckNullVal($txtInertNONSECAHrs)."', '".$this->getCheckNullVal($txtGFSECAHrs)."', '".$this->getCheckNullVal($txtGFNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs1)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs1)."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(FCAID) as max from freight_cost_estimete_master";
		$myres  =  mysql_query($mysql,$connect);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
	}else{
	    $rows_fetch = mysql_fetch_assoc($res_fetch);
		$maxid = $rows_fetch['FCAID'];
		
		$del_query2 = "delete from  freight_cost_estimete_slave1 where FCAID='".$maxid."'";
		$del_query3 = "delete from  freight_cost_estimete_slave2 where FCAID='".$maxid."'";
		$del_query4 = "delete from  freight_cost_estimete_slave3 where FCAID='".$maxid."'";
		$del_query5 = "delete from  freight_cost_estimete_slave4 where FCAID='".$maxid."'";
		$del_query6 = "delete from  freight_cost_estimete_slave5 where FCAID='".$maxid."'";
		$del_query7 = "delete from  freight_cost_estimete_slave6 where FCAID='".$maxid."'";
		$del_query8 = "delete from  freight_cost_estimete_slave7 where FCAID='".$maxid."'";
		$del_query9 = "delete from  freight_cost_estimete_slave8 where FCAID='".$maxid."'";
		$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$maxid."'";
		$del_query11 = "delete from  freight_cost_estimete_slave11 where FCAID='".$maxid."'";
		$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$maxid."'";
		$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$maxid."'";
		$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$maxid."'";
		$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$maxid."'";
		$del_query15 = "delete from  freight_cost_estimete_slave16 where FCAID='".$maxid."'";
		mysql_query($del_query2);
		mysql_query($del_query3);
		mysql_query($del_query4);
		mysql_query($del_query5);
		mysql_query($del_query6);
		mysql_query($del_query7);
		mysql_query($del_query8);
		mysql_query($del_query9);
		mysql_query($del_query10);
		mysql_query($del_query11);
		mysql_query($del_query12);
		mysql_query($del_query13);
		mysql_query($del_query14);
		mysql_query($del_query15);
		mysql_query($del_query16);
		mysql_query("commit");
		
	}
		
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{   
		    $randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, PORT_COSTLP_VENDOR, DDCLP_COMM, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_VENDOR, DDCLP_NETCOST, DDCDP_COMM, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_VENDOR, DDCDP_NETCOST, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, PORT_COSTTP_VENDOR, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS, LP_OPA_VENDOR, DP_OPA_VENDOR, LP_CA_VENDOR, DP_CA_VENDOR) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."' ,'".$_REQUEST['selLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$_REQUEST['selDDCLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$_REQUEST['selDDCDPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['selDPVendor_'.$i]."', '".$_REQUEST['ChkShowDDCLP_'.$i]."', '".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$_REQUEST['selTPVendor_'.$i]."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."','".$_REQUEST['selLPOPAVendor_'.$i]."','".$_REQUEST['selDPOPAVendor_'.$i]."','".$_REQUEST['selLPCharterAgentVendor_'.$i]."','".$_REQUEST['selDPCharterAgentVendor_'.$i]."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtRateUSDmt_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] != "")
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."', 1, '".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtRateUSDmt2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] != "")
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtRateUSDmt3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] != "")
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, VENDORID, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$_REQUEST['selQtyVendor3_'.$i]."', '".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
		    $randomid = $_REQUEST['txtORCSlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtORCSlaveRandomID_'.$i]) || $_REQUEST['txtORCSlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT, VENDORID, RANDOMID) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selORCVendor_'.$i])."', '".$randomid."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
		    $randomid = $_REQUEST['txtOISlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtOISlaveRandomID_'.$i]) || $_REQUEST['txtOISlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT, VENDORID, RANDOMID) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOtherIncVendor_'.$i])."', '".$randomid."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."', '".$_REQUEST['selBrCommVendor_'.$i]."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		$txtTID = $_REQUEST['txtTID'];
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtDisponentOwner_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_slave5 (FCAID, DISPONENT_OWNER) values ('".$maxid."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$p_locationID = $_REQUEST['p_locationID'];
		for($i=1 ; $i<=$p_locationID ;$i++)
		{
			if($_REQUEST['txtFromLocation_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_slave6 (FCAID, LOCATION_FROM, LOCATION_TO, PASSAGE_TYPE, SPEED_TYPE, DISTANCE) values ('".$maxid."', '".$_REQUEST['txtFromLocation_'.$i]."','".$_REQUEST['txtToLocation_'.$i]."','".$this->getCheckNullVal($_REQUEST['selPLocationType_'.$i])."','".$this->getCheckNullVal($_REQUEST['selSLocationSpeed_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtLocationDistance_'.$i])."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$txtQTYID = $_REQUEST['txtQTYID'];
		for($i=1 ; $i<=$txtQTYID ;$i++)
		{
			if($_REQUEST['selQtyVendorList_'.$i] != "")
			{
			    $randomid = $_REQUEST['txtQtySlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtQtySlaveRandomID_'.$i]) || $_REQUEST['txtQtySlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql2 = "insert into freight_cost_estimete_slave7 (FCAID, QTY_VENDORID, AGREED_GROSS_FREIGHT, QUANTITY, GROSS_FREIGHT, BROKERAGE, NET_BROKERAGE, NET_FREIGHT, NET_FREIGHT_PERMT, CURRENCYID, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, CARGO, RANDOMID) values ('".$maxid."','".$_REQUEST['selQtyVendorList_'.$i]."','".$_REQUEST['txtQtyAggriedFreight_'.$i]."','".$_REQUEST['txtFreightQty_'.$i]."','".$_REQUEST['txtQtyFreight_'.$i]."','".$_REQUEST['txtQtyBrokeragePer_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtQtyBrokerageAmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreightMT1_'.$i])."','".$this->getCheckNullVal($_REQUEST['selCurrencyDisList_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyLocalAggriedFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDisExchangeRate_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selQtyCargo_'.$i])."', '".$randomid."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		} 
		
		
		$txtNoOfInvoice = $_REQUEST['txtNoOfInvoice'];
		for($i=1;$i<=$txtNoOfInvoice;$i++)
		{
			if($_REQUEST['txtInvoiceID_'.$i]!='')
			{
				$sql11 = "insert into freight_cost_estimete_slave11 (INVOICEID, FCAID) values ('".addslashes(trim($_REQUEST['txtInvoiceID_'.$i]))."', '".$maxid."' )";
				mysql_query($sql11) or die($sql11);
				mysql_query("commit");
			}
		}
		
		$txtTankID = $_REQUEST['txtTankID'];
		for($i=1 ; $i<=$txtTankID ;$i++)
		{
			if($_REQUEST['txtFreightSpecs_'.$i] != "")
			{
				$sql12 = "insert into freight_cost_estimete_slave12 (FCAID, FREIGHT_SPECS, CUSTOMER, MIN_CARGO_QTY, OVE_CARGO_QTY, MIN_FLAT_RATE, OVE_FLAT_RATE, MIN_WS, OVE_WS, MIN_DIS_LEG, OVE_DIS_LEG, MIN_DISTANCE, OVE_DISTANCE, MIN_AMOUNT, OVE_AMOUNT, TOTAL_QTY, TOTAL_AMOUNT) values ('".$maxid."', '".$_REQUEST['txtFreightSpecs_'.$i]."', '".$_REQUEST['selTankVendor_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtMinCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtOveCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinDisLeg_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveDisLeg_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinTotalDis_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveTotalDis_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinAmount_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtTotalTankQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTotalTankAmount_'.$i])."')";
				mysql_query($sql12) or die($sql12);
				mysql_query("commit");
			}
		} 
		
		$txtHIREID = $_REQUEST['txtHIREID'];
		for($i=1 ; $i<=$txtHIREID ;$i++)
		{
			if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
			{
				if($_REQUEST['txtHireFrom_'.$i]!="")
				{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
				else{$txtHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtHireTo_'.$i]!="")
				{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
				else{$txtHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCHireRandom_'.$i]) || $_REQUEST['txtTCHireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCHireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave17 (FCAID, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE, HIRE_AMT, RANDOMID) values ('".$maxid."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireAmt_'.$i])."', '".$this->getCheckNullValue($randomid4)."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$maxid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$maxid."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg; 
}



function updateTCICostSheetDetails()
{
	$connect = $this->funConnect();
	$selFType	 			= $_REQUEST['selFType'];
	$selVName 		    	= addslashes(trim($_REQUEST['selVName']));
	$txtVType	 			= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 			= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 			= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo  	 			= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 			= addslashes(trim($_REQUEST['txtENo']));
	$rdoDWT 	 			= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 			= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT           	 	= addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 			= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    			= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    			= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      			= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 			= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 			= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     			= addslashes(trim($_REQUEST['txtLOA']));
	$txtGear	 			= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 			= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    			= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 				= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed			= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    	= addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2			= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    	= addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1			= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    	= addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed		= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1   	 	= addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2		= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    	= addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    	= addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2		= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   	= addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed		= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    	= addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1		= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2		= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed   	    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1		= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    	= addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed  	 	= addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed		= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	$rdoQty             	= addslashes(trim($_REQUEST['rdoQty']));
	$rdoMMarket        		 = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	   		 = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    	= addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT            = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    	= addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    	= addslashes(trim($_REQUEST['selCType']));
	$txtMLumpsum	        = addslashes(trim($_REQUEST['txtMLumpsum']));
	
	$selCName           	= addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            	= addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        	= addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    	= addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    	= addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           	= addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        	= addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        	= addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    	= addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    	= addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          	= addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    	= addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    	= addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    	= addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    	= addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           	= addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    	= addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT		= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 			= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    	= addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      	= addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT		= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    	= addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    	= addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 			= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      	= addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT		= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    	= addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     	= addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 			= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           	= addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         	= addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    	= addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        	= addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB  = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount		= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   	= addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        	= addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        	= addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       	= addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    	= addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	
	
	$selOpenPort 	 		= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 			= addslashes(trim($_REQUEST['selZone']));
	$selBroker         	 	= addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 		= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 		= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    			= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    	= addslashes(trim($_REQUEST['selOwner']));
	$txtDisponentOwner		= addslashes(trim($_REQUEST['txtDisponentOwner']));
	if($_REQUEST['txtFDate']!="")
	{
	$txtFDate     			= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	}


	else{$txtFDate     		= "1970-01-01";}
	if($_REQUEST['txtTDate']!="")
	{	
	$txtTDate     			= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	}
	else{$txtTDate     		= "1970-01-01";}
	if($_REQUEST['txtETADate']!="")
	{
	$txtETADate     		= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	}
	else{$txtETADate     		= "1970-01-01";}
	if($_REQUEST['txtCPDate']!="")
	{
	$txtCPDate     			= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	}
	else{$txtCPDate     		= "1970-01-01";}
	$txtNotes     			= addslashes(trim($_REQUEST['txtNotes']));
	
	$txtCID 	 			= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 			= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       	= addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 			= implode(',',$_REQUEST['selMType']);
	$txtMCode    			= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance		= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      			= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    	= addslashes(trim($_REQUEST['selDPort']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	
	$txtTFUMTManual 		   = addslashes(trim($_REQUEST['txtTFUMTManual']));
	$txtTDUMTManual            = addslashes(trim($_REQUEST['txtTDUMTManual']));
	$txtTFOCOffHire		 	   = addslashes(trim($_REQUEST['txtTFOCOffHire']));
	$txtTDOCOffHire     	   = addslashes(trim($_REQUEST['txtTDOCOffHire']));
	$selDTCVendor       	   = addslashes(trim($_REQUEST['selDTCVendor']));
	$txtFGFFVendor       	   = addslashes(trim($_REQUEST['txtFGFFVendor']));
	
	$txtCVE           	   = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt       	   = addslashes(trim($_REQUEST['txtCVEAmt']));
	$selCVEVendor          = addslashes(trim($_REQUEST['selCVEVendor']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selBroVendor       = addslashes(trim($_REQUEST['selBroVendor']));
	$selILOHCVendor     = addslashes(trim($_REQUEST['selILOHCVendor']));
	$txtDistributedRemarks     = addslashes(trim($_REQUEST['txtDistributedRemarks'])); 
	
	if(isset($_REQUEST['txtHiddenHirage']))
	{
	   $txtHiddenHirage     		= $_REQUEST['txtHiddenHirage'];
	}
	else{$txtHiddenHirage     		= $_REQUEST['txtHireargeAmt'];}
	
	
	if($_REQUEST['txtLCSDate']!="")
	{
	$txtLCSDate   			= date("Y-m-d",strtotime($_REQUEST['txtLCSDate']));
	}
	else{$txtLCSDate     		= "1970-01-01";}
	if($_REQUEST['txtLCFDate']!="")
	{
	$txtLCFDate     		= date("Y-m-d",strtotime($_REQUEST['txtLCFDate']));
	}
	else{$txtLCFDate     		= "1970-01-01";}
	
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$txtCRMFILE2							= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2							= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['attach_file1']);
	$name = $this->getUploadName($_FILES['attach_file1']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$txtLumpsumQty          = addslashes(trim($_REQUEST['txtLumpsumQty']));
    $selLumsumVendor        = addslashes(trim($_REQUEST['selLumsumVendor']));
	
	
	$txtBaseRateFloating    = addslashes(trim($_REQUEST['txtBaseRateFloating']));
	$txtBaseRateFixed       = addslashes(trim($_REQUEST['txtBaseRateFixed']));
	$txtBaseRateAverage     = addslashes(trim($_REQUEST['txtBaseRateAverage']));
	
	$txtGFreightFloating    = addslashes(trim($_REQUEST['txtGFreightFloating']));
	$txtGFreightFixed       = addslashes(trim($_REQUEST['txtGFreightFixed']));
	$txtGFreightAverage     = addslashes(trim($_REQUEST['txtGFreightAverage']));
	
	$txtNFreightFloating    = addslashes(trim($_REQUEST['txtNFreightFloating']));
	$txtNFreightFixed       = addslashes(trim($_REQUEST['txtNFreightFixed']));
	$txtNFreightAverage     = addslashes(trim($_REQUEST['txtNFreightAverage']));
	
	$txtOExpensesFloating   = addslashes(trim($_REQUEST['txtOExpensesFloating']));
	$txtOExpensesFixed      = addslashes(trim($_REQUEST['txtOExpensesFixed']));
	$txtOExpensesAverage    = addslashes(trim($_REQUEST['txtOExpensesAverage']));
	
	$txtVEarningFloating    = addslashes(trim($_REQUEST['txtVEarningFloating']));
	$txtVEarningFixed       = addslashes(trim($_REQUEST['txtVEarningFixed']));
	$txtVEarningAverage     = addslashes(trim($_REQUEST['txtVEarningAverage']));
	
	$txtDailyEarningFloating= addslashes(trim($_REQUEST['txtDailyEarningFloating']));
	$txtDailyEarningFixed   = addslashes(trim($_REQUEST['txtDailyEarningFixed']));
	$txtDailyEarningAverage = addslashes(trim($_REQUEST['txtDailyEarningAverage']));
	
	$txtTCEMonthFloating    = addslashes(trim($_REQUEST['txtTCEMonthFloating']));
	$txtTCEMonthFixed       = addslashes(trim($_REQUEST['txtTCEMonthFixed']));
	$txtTCEMonthAverage     = addslashes(trim($_REQUEST['txtTCEMonthAverage']));
	
	$txtOPExpensesFloating  = addslashes(trim($_REQUEST['txtOPExpensesFloating']));
	$txtOPExpensesFixed     = addslashes(trim($_REQUEST['txtOPExpensesFixed']));
	$txtOPExpensesAverage   = addslashes(trim($_REQUEST['txtOPExpensesAverage']));
	
	$txtNetDailyEarningFloating= addslashes(trim($_REQUEST['txtNetDailyEarningFloating']));
	$txtNetDailyEarningFixed= addslashes(trim($_REQUEST['txtNetDailyEarningFixed']));
	$txtNetDailyEarningAverage= addslashes(trim($_REQUEST['txtNetDailyEarningAverage']));
	
	$txtNetDailyProfitFloating= addslashes(trim($_REQUEST['txtNetDailyProfitFloating']));
	$txtNetDailyProfitFixed = addslashes(trim($_REQUEST['txtNetDailyProfitFixed']));
	$txtNetDailyProfitAverage= addslashes(trim($_REQUEST['txtNetDailyProfitAverage']));
	$selCargoPlanning       = $_REQUEST['selCargoPlanning'];
	
	$txtSDWTMT 	 	    = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	 		= addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM         = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 	 	= addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT     	 	= addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT    		= addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT    		= addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT           = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT     = addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT  	= addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM 	= addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT		= addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM   = addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT	 	= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT 	= addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT    	= addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT  		= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$txtTCNo            = addslashes(trim($_REQUEST['txtTCNo']));
	$rdoTankType        = addslashes(trim($_REQUEST['rdoTankType']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	$selPeriodContract = addslashes(trim($_REQUEST['selPeriodContract']));
	$txtBLCQMT              = addslashes(trim($_REQUEST['txtBLCQMT']));
    $txtLessPerQty          = addslashes(trim($_REQUEST['txtLessPerQty']));
	$chartering_pic =addslashes(trim($_REQUEST['chartering_pic']));
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	if($_REQUEST['txtTCDeliveryDate']!="")
	{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate']));}
	else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtTCReDeliveryDate']!="")
	{$txtTCReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate']));}
	else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	$txtTCDelivery = addslashes(trim($_REQUEST['txtTCDelivery']));
	$txtTCReDelivery = addslashes(trim($_REQUEST['txtTCReDelivery']));
	$txtTankerFreightRate = addslashes(trim($_REQUEST['txtTankerFreightRate']));
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['comid'];
	$update_status = addslashes(trim($_REQUEST['update_status']));
	
	$profit_diff = $this->getCompareEstimateData($comid,'PL_DIFF');
	if($profit_diff!='' && $profit_diff!=NULL)
	{
	    $actualpl = $this->getCompareEstimateData($comid,'ACTUAL_PL');
	}else
	{
	    $actualpl = $this->getCheckNullVal($txtPL);
	}
	
	$id = $this->getTCICostSheetID($comid,$sheet_no);
	$sql = "update freight_cost_estimete_master set FIXTURETYPEID='".$this->getCheckNullValue($selFType)."', TRANS_DATE='".$txtDate."', MODULEID='".$this->getCheckNullValue($_SESSION['moduleid'])."', MCOMPANYID='".$this->getCheckNullValue($_SESSION['company'])."', ADDED_BY='".$_SESSION['uid']."', VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', VESSEL_TYPE='".$txtVType."', FLAG='".$txtFlag."', VOYAGE_NO='".$txtVNo."', VOYAGE_NAME='".$txtENo."', DWT_SUMMER='".$this->getCheckNullValue($txtDWTS)."', DWT_TOPICAL='".$this->getCheckNullValue($txtDWTT)."', RDO_CAP='".$this->getCheckNullValue($rdoCap)."', GRAIN_CAP='".$this->getCheckNullValue($txtGCap)."', BALE_CAP='".$this->getCheckNullValue($txtBCap)."', SF='".$this->getCheckNullValue($txtSF)."', LODABLE='".$this->getCheckNullValue($txtLoadable)."', GNRT='".$this->getCheckNullValue($txtGNRT)."', LOA='".$this->getCheckNullValue($txtLOA)."', GEAR='".$txtGear."', BUILD_YEAR='".$txtBuiltYear."', BEAM='".$this->getCheckNullValue($txtBeam)."', TPC='".$this->getCheckNullValue($txtTPC)."', BFULLSPEED='".$this->getCheckNullValue($txtBFullSpeed)."', BECOSPEED1='".$this->getCheckNullValue($txtBEcoSpeed1)."', BECOSPEED2='".$this->getCheckNullValue($txtBEcoSpeed2)."', LFULLSPEED='".$this->getCheckNullValue($txtLFullSpeed)."', LECOSPEED1='".$this->getCheckNullValue($txtLEcoSpeed1)."', LECOSPEED2='".$this->getCheckNullVal($txtLEcoSpeed2)."', BFOFULLSPEED='".$this->getCheckNullVal($txtBFOFullSpeed)."', BFOECOSPEED1='".$this->getCheckNullVal($txtBFOEcoSpeed1)."', BFOECOSPEED2='".$this->getCheckNullVal($txtBFOEcoSpeed2)."', LFOFULLSPEED='".$this->getCheckNullVal($txtLFOFullSpeed)."', LFOECOSPEED1='".$this->getCheckNullVal($txtLFOEcoSpeed1)."', LFOECOSPEED2='".$this->getCheckNullVal($txtLFOEcoSpeed2)."', PIFOFULLSPEED='".$this->getCheckNullValue($txtPIFOFullSpeed)."', PWFOFULLSPEED='".$this->getCheckNullValue($txtPWFOFullSpeed)."', BDOFULLSPEED='".$this->getCheckNullValue($txtBDOFullSpeed)."', BDOECOSPEED1='".$this->getCheckNullValue($txtBDOEcoSpeed1)."', BDOECOSPEED2='".$this->getCheckNullVal($txtBDOEcoSpeed2)."', LDOFULLSPEED='".$this->getCheckNullVal($txtLDOFullSpeed)."', LDOECOSPEED1='".$this->getCheckNullVal($txtLDOEcoSpeed1)."', LDOECOSPEED2='".$this->getCheckNullVal($txtLDOEcoSpeed2)."', PIDOFULLSPEED='".$this->getCheckNullVal($txtPIDOFullSpeed)."', PWDOFULLSPEED='".$this->getCheckNullVal($txtPWDOFullSpeed)."', RDO_MARKER='".$this->getCheckNullVal($rdoMMarket)."', RDO_DWT='".$this->getCheckNullValue($rdoDWT)."', FREIGHT_GROSS='".$this->getCheckNullVal($txtMTCPDRate)."', LUMSUM='".$this->getCheckNullVal($txtMLumpsum)."', CARGO_RATE='".$this->getCheckNullVal($txtAddnlCRate)."', QUANTITY='".$this->getCheckNullVal($txtCQMT)."', CARGO_TYPE='".$this->getCheckNullVal($selCType)."', CARGO_ID='".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."', DF_QUANTITY='".$this->getCheckNullVal($txtDFQMT)."', ADDNL_QUANTITY='".$this->getCheckNullValue($txtAddnlQMT)."', LADEN_DIST='".$this->getCheckNullValue($txtLDist)."', BALLAST_DIST='".$this->getCheckNullValue($txtBDist)."', LADEN_DAYS='".$this->getCheckNullValue($txtLDays)."', BALLAST_DAYS='".$this->getCheckNullVal($txtBDays)."', TOTAL_PASSAGE_DAYS='".$this->getCheckNullVal($txtTSDays)."', IDEAL_DAYS='".$this->getCheckNullVal($txtTtPIDays)."', WORKING_DAYS='".$this->getCheckNullVal($txtTtPWDays)."', TOTAL_DAYS='".$this->getCheckNullVal($txtTDays)."', TOTAL_DISTANCE='".$this->getCheckNullVal($txtTDist)."', FO_CONSP='".$this->getCheckNullVal($txtTFUMT)."', DO_CONSP='".$this->getCheckNullVal($txtTDUMT)."', GROSS_PREIGHT_ADJ='".$this->getCheckNullValue($txtFrAdjUsdGF)."', DEAD_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdDF)."', ADDNL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdAF)."', TOTAL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdTF)."', GROSS_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdGFMT)."', DEAD_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdDFMT)."', ADDNL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdAFMT)."', TOTAL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdTFMT)."', ADDRESS_COMMISSION_PER='".$this->getCheckNullValue($txtFrAdjPerAC)."', ADDRESS_COMMISSION_AMT='".$this->getCheckNullValue($txtFrAdjUsdAC)."', ADDRESS_COMMISSION_PRMT='".$this->getCheckNullValue($txtFrAdjUsdACMT)."', BROKERAGE_PER='".$this->getCheckNullValue($txtFrAdjPerAgC)."', BROKERAGE_AMT='".$this->getCheckNullVal($txtFrAdjUsdAgC)."', NET_PAYABLE='".$this->getCheckNullVal($txtFrAdjUsdFP)."', FINAL_NET_FREIGHT='".$this->getCheckNullVal($txtFGFFD)."', FINAL_NET_FREIGHT_PRMT='".$this->getCheckNullVal($txtFGFFDMT)."', BROKERAGE_COMMISSION_PER='".$this->getCheckNullVal($txtBrCommPercent)."', BROKERAGE_COMMISSION_AMT='".$this->getCheckNullVal($txtBrComm)."', TOTAL_ORC_EXP_AMT='".$this->getCheckNullVal($txtTTLORCAmt)."', TOTAL_ORC_EXP_PRMT='".$this->getCheckNullVal($txtTTLORCCostMT)."', REVENUES_FREIGHT='".$this->getCheckNullVal($txtRevenue)."', TOTAL_OWNER_EXP='".$this->getCheckNullValue($txtTTLOwnersExpenses)."', CHARTERER_EXP='".$this->getCheckNullValue($txtTTLCharterersExpenses)."', VOYAGE_EARNING='".$this->getCheckNullValue($txtVoyageEarnings)."', DAILY_EARNING='".$this->getCheckNullValue($txtDailyEarnings)."', DAILY_VESSEL_OPERATION_EXP='".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."', TOTAL_VOYAGE_EARNING='".$this->getCheckNullVal($txtGTTLVoyageEarnings)."', NET_DAILY_EARNING='".$this->getCheckNullVal($txtNettDailyEarnings)."', NET_DAILY_PROFIT='".$this->getCheckNullVal($txtNettDailyProfit)."', PROFIT_LOSS='".$this->getCheckNullVal($txtPL)."', RDO_QTY='".$this->getCheckNullVal($rdoQty)."', OPEN_PORT='".$selOpenPort."', ZONE_OPEN='".$selZone."', BROKER='".$selBroker."', COA_SPOT='".$selCOASpot."', COA_NUMBER='".$selCOA."', COA_NUMBER_LIFT='".$txtNoLift."', NO_OF_SHIPMENT='', OWNER='".$selOwner."', DISPONENT_OWNER='".$txtDisponentOwner."', LAYCAN_START_DATE='".$txtFDate."', LAYCAN_FINISH_DATE='".$txtTDate."', ETA_DATE='".$txtETADate."', CP_DATE='".$txtCPDate."', REMARKS='".$txtNotes."', ATTACHMENT='".$upload1."', ATTACHMENT_NAME='".$name1."', CARGOID='".$txtCID."', SHIPPER='".$selShipper."', TOLERANCE='".$txtTolerance."', MATERIALID='".$selMType."', MATERIAL_CODE='".$txtMCode."', TERM_TOLERANCE='".$txtTermTolerance."', LPID='".$selLPort."', DPID='".$selDPort."', LAYCAN_CARGO_START_DATE='".$txtLCSDate."', LAYCAN_CARGO_FINISH_DATE='".$txtLCFDate."', HIREAGE_AMT='".$this->getCheckNullVal($txtHireargeAmt)."', HIREAGE_PERCENT='".$this->getCheckNullVal($txtHireargePercent)."', HIREAGE_PER_AMT='".$this->getCheckNullVal($txtHireargePercentAmt)."', HIREAGE_NETT_AMT='".$this->getCheckNullVal($txtNettHireargeAmt)."', QTY_TYPE_RADIO='".$rdoQtyType."', AGREED_GROSS_FREIGHT_LOCAL='".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', CURRENCYID='".$this->getCheckNullVal($selCurrencyMarList)."', EXCHANGE_RATE='".$this->getCheckNullVal($txtMarExchangeRate)."', TTL_FO_CONSP_MT_MANUAL='".$this->getCheckNullVal($txtTFUMTManual)."', TTL_DO_CONSP_MT_MANUAL='".$this->getCheckNullVal($txtTDUMTManual)."', TTL_FO_CONSP_OFFHIRE='".$this->getCheckNullVal($txtTFOCOffHire)."', TTL_DO_CONSP_OFFHIRE='".$this->getCheckNullVal($txtTDOCOffHire)."', DTCVENDORID='".$selDTCVendor."', FINAL_STATUS='".$update_status."', FGFF_VENDORID='".$txtFGFFVendor."', CVE_AMT='".$this->getCheckNullVal($txtCVE)."', CVE_TOTALAMT='".$this->getCheckNullVal($txtCVEAmt)."', CVE_VENDORID='".$this->getCheckNullVal($selCVEVendor)."', BALLAST_BONUS='".$this->getCheckNullVal($txtBallastBonus)."', BUNKER_EXPENSES='".$this->getCheckNullVal($txtTotalBunkerCost)."', PORT_EXPENSES='".$this->getCheckNullVal($txtTotalPortCost)."', BROKERAGE_VENDORID='".$selBroVendor."', ILOHC_VENDORID='".$selILOHCVendor."', HIDDEN_HIRAGE='".$this->getCheckNullVal($txtHiddenHirage)."',  DISTRIBUTED_REMARKS='".$txtDistributedRemarks."', FIXED=1, ESTIMATE_TYPE='".$this->getCheckNullVal($rdoEstimateType)."', GAS_MARKET='".$this->getCheckNullVal($rdoQtyMar)."', GAS_BALTIC='".$this->getCheckNullVal($txtBalticRate)."', ADDNL_PRENIUM='".$this->getCheckNullVal($txtAdnlPrenium)."', GAS_BASE_RATE='".$this->getCheckNullVal($txtBaseRate)."', GAS_QUANTITY='".$this->getCheckNullVal($txtGasCQMT)."', GAS_LUMSUM='".$this->getCheckNullVal($txtGASLumpsum)."', TANK_WS_FROM='".$this->getCheckNullVal($selWSFPort)."', TANK_WS_TO='".$this->getCheckNullVal($selWSTPort)."', TANK_FIXED_DIFF='".$this->getCheckNullVal($txtFixedDiff)."', TANK_QUANTITY='".$this->getCheckNullVal($txtTankQuantity)."', ATTACHMENT2='".$upload2."', ATTACHMENT2_NAME='".$name2."', CHK_LUMPSUM='".$this->getCheckNullVal($ChkLumpsum)."', LUMPSUMAMT='".$this->getCheckNullVal($txtLumpsum)."', WS_QTY='".$this->getCheckNullVal($txtLumpsumQty)."', LUMP_VENDOR ='".$selLumsumVendor."', BASERATE_FLOAT='".$this->getCheckNullVal($txtBaseRateFloating)."', BASERATE_FIXED='".$this->getCheckNullVal($txtBaseRateFixed)."', BASERATE_AVERAGE='".$this->getCheckNullVal($txtBaseRateAverage)."', GROSS_FREIGHT_FLOAT='".$this->getCheckNullVal($txtGFreightFloating)."', GROSS_FREIGHT_FIXED='".$this->getCheckNullVal($txtGFreightFixed)."', GROSS_FREIGHT_AVERAGE='".$this->getCheckNullVal($txtGFreightAverage)."', NETFREIGHT_FLOAT='".$this->getCheckNullVal($txtNFreightFloating)."', NETFREIGHT_FIXED='".$this->getCheckNullVal($txtNFreightFixed)."', NETFREIGHT_AVERAGE='".$this->getCheckNullVal($txtNFreightAverage)."', OWNER_EXPENSES_FLOAT='".$this->getCheckNullVal($txtOExpensesFloating)."', OWNER_EXPENSES_FIXED='".$this->getCheckNullVal($txtOExpensesFixed)."', OWNER_EXPENSES_AVERAGE='".$this->getCheckNullVal($txtOExpensesAverage)."', VEARNING_FLOAT='".$this->getCheckNullVal($txtVEarningFloating)."', VEARNING_FIXED='".$this->getCheckNullVal($txtVEarningFixed)."', VEARNING_AVERAGE='".$this->getCheckNullVal($txtVEarningAverage)."', TCEEARNING_FLOAT='".$this->getCheckNullVal($txtDailyEarningFloating)."', TCEEARNING_FIXED='".$this->getCheckNullVal($txtDailyEarningFixed)."', TCEEARNING_AVERAGE='".$this->getCheckNullVal($txtDailyEarningAverage)."', TCE_MONTH_FLOAT='".$this->getCheckNullVal($txtTCEMonthFloating)."', TCE_MONTH_FIXED='".$this->getCheckNullVal($txtTCEMonthFixed)."', TCE_MONTH_AVERAGE='".$this->getCheckNullVal($txtTCEMonthAverage)."', OEXPENSES_FLOAT='".$this->getCheckNullVal($txtOPExpensesFloating)."', OEXPENSES_FIXED='".$this->getCheckNullVal($txtOPExpensesFixed)."', OEXPENSES_AVERAGE='".$this->getCheckNullVal($txtOPExpensesAverage)."', NET_DAILY_ER_FLOAT='".$this->getCheckNullVal($txtNetDailyEarningFloating)."', NET_DAILY_ER_FIXED='".$this->getCheckNullVal($txtNetDailyEarningFixed)."', NET_DAILY_ER_AVERAGE='".$this->getCheckNullVal($txtNetDailyEarningAverage)."', NET_DAILY_PROFIT_FLOAT='".$this->getCheckNullVal($txtNetDailyProfitFloating)."', NET_DAILY_PROFIT_FIXED='".$this->getCheckNullVal($txtNetDailyProfitFixed)."', NET_DAILY_PROFIT_AVERAGE='".$this->getCheckNullVal($txtNetDailyProfitAverage)."', OPEN_CARGOID='".$this->getCheckNullVal($selCargoPlanning)."', SUMMERDWTMT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMERDWTLT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMERDRAFTM='".$this->getCheckNullVal($txtSDraftM)."', SUMMERDRAFTFT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANT_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANT_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFTM='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CBFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', GROSS_BREAKDOWN='".$this->getCheckNullVal($txtGrossBreakeven)."', BREAKDOWN_MT='".$this->getCheckNullVal($txtBreakevenMT)."', TANKER_RADIO_SINGLE_DIS='".$this->getCheckNullVal($rdoTankType)."', TC_NO='".$txtTCNo."', GROSS_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtGrossHireargeAmt)."', HIERAGE_CVE='".$this->getCheckNullVal($txtHireargeCVE)."', HIERAGE_CVE_AMOUNT='".$this->getCheckNullVal($txtHireargeCVEAMT)."', OFF_HIRE_CVE='".$this->getCheckNullVal($txtOffHireCVE)."', OFF_HIRE_CVE_AMOUNT='".$this->getCheckNullVal($txtOffHireCVEAMT)."', LESS_OFF_HIRE='".$this->getCheckNullVal($txtLessOffHire)."', FINAL_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtFinalHireargeAmt)."', HIERAGE_BROKER_PERCENT= '".$this->getCheckNullVal($txtHireargeBroPercent)."', HIERAGE_BROKER_AMT= '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', TC_HIRE_DAYS='".$this->getCheckNullVal($txtTotalVoyageDays)."', TC_CP_DATE='".$txtTC_CPDate."', PERIODID='".$this->getCheckNullValue($selPeriodContract)."', LESS_PER_BLQTY='".$this->getCheckNullValue($txtLessPerQty)."', BL_QTY_FREIGHT='".$this->getCheckNullValue($txtBLCQMT)."', TC_DELIVERY_DATE='".$txtTCDeliveryDate."', TC_RE_DELIVERY_DATE='".$txtTCReDeliveryDate."', TC_DELIVERY_RANGE='".$txtTCDelivery."', TC_RE_DELIVERY_RANGE='".$txtTCReDelivery."', ACTUAL_PL='".$actualpl."', TANKER_FREIGHT_RATE='".$txtTankerFreightRate."', TANK_CLEANING_SECA_HRS='".$this->getCheckNullVal($txtTKSECAHrs)."', TANK_CLEANING_NONSECA_HRS='".$this->getCheckNullVal($txtTKNONSECAHrs)."', INERTING_SECA_HRS='".$this->getCheckNullVal($txtInertSECAHrs)."', INERTING_NONSECA_HRS='".$this->getCheckNullVal($txtInertNONSECAHrs)."', GAS_FREEING_SECA_HRS='".$this->getCheckNullVal($txtGFSECAHrs)."', GAS_FREEING_NONSECA_HRS='".$this->getCheckNullVal($txtGFNONSECAHrs)."', HEATING_SECA_HRS='".$this->getCheckNullVal($txtHeatSECAHrs)."', HEATING_NONSECA_HRS='".$this->getCheckNullVal($txtHeatNONSECAHrs)."', HEATING_SECA_HRS_1='".$this->getCheckNullVal($txtHeatSECAHrs1)."', HEATING_NONSECA_HRS_1='".$this->getCheckNullVal($txtHeatNONSECAHrs1)."',CHARTERING_PIC='".$this->getCheckNullVal($chartering_pic)."' where COMID='".$this->getCheckNullVal($comid)."' and SHEET_NO='".$this->getCheckNullVal($sheet_no)."'";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['txtFCASlaveID_'.$i]))
		{
			$arr_passage[] = $_REQUEST['txtFCASlaveID_'.$i];
		}
	}
	$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$id."'";
    $res1 = mysql_query($sql1);
	while($rows1 = mysql_fetch_assoc($res1))
	{
		if(!in_array($rows1['FCA_SLAVEID'], $arr_passage))
        {
			$del_query2 = "delete from freight_cost_estimete_slave1 where FCAID='".$id."' and FCA_SLAVEID='".$rows1['FCA_SLAVEID']."' ";
            mysql_query($del_query2);
			mysql_query("commit");
		}
	}
	
	$del_query3 = "delete from  freight_cost_estimete_slave2 where FCAID='".$id."'";
	$del_query4 = "delete from  freight_cost_estimete_slave3 where FCAID='".$id."'";
	$del_query5 = "delete from  freight_cost_estimete_slave4 where FCAID='".$id."'";
	$del_query6 = "delete from  freight_cost_estimete_slave5 where FCAID='".$id."'";
	$del_query7 = "delete from  freight_cost_estimete_slave6 where FCAID='".$id."'";
	$del_query8 = "delete from  freight_cost_estimete_slave7 where FCAID='".$id."'";
	$del_query9 = "delete from  freight_cost_estimete_slave8 where FCAID='".$id."'";
	$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$id."'";
	$del_query11 = "delete from  freight_cost_estimete_slave11 where FCAID='".$id."'";
	$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$id."'";
	$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$id."'";
	$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$id."'";
	$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$id."'";
	$del_query16 = "delete from  freight_cost_estimete_slave16 where FCAID='".$id."'";
	$del_query17 = "delete from  freight_cost_estimete_slave17 where FCAID='".$id."'";
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query($del_query5);
	mysql_query($del_query6);
	mysql_query($del_query7);
	mysql_query($del_query8);
	mysql_query($del_query9);
	mysql_query($del_query10);
	mysql_query($del_query11);
	mysql_query($del_query12);
	mysql_query($del_query13);
	mysql_query($del_query14);
	mysql_query($del_query15);
	mysql_query($del_query16);
	mysql_query($del_query17);
	mysql_query("commit");
	
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{
			if(isset($_REQUEST['txtFCASlaveID_'.$i]) && $_REQUEST['txtFCASlaveID_'.$i]!='')
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "update freight_cost_estimete_slave1 set FROM_PORT='".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."', TO_PORT='".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."', DIS_TYPE='".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."', PASSAGE_TYPE='".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."', DISTANCE='".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."', SPEED_TYPE='".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."', SPEED_ADJ='".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."', MARGIN_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."', LOAD_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."', LOAD_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."', LOAD_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."', LOAD_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."', LOAD_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."', LOAD_PORT_IDEAL_DAYS='".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."', DISC_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."', DISC_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."', DISC_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."', DISC_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."', DISC_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."', DISC_PORT_IDEAL_DATE='".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."', TRANSIT_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."', TRANSIT_PORT_IDLE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', PORT_COSTLP_VENDOR='".$_REQUEST['selLPVendor_'.$i]."', DDCLP_COMM='".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', DDCLP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."', DDCLP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."', DDCLP_VENDOR='".$_REQUEST['selDDCLPVendor_'.$i]."', DDCLP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."', DDCDP_COMM='".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', DDCDP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."', DDCDP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."', DDCDP_VENDOR='".$_REQUEST['selDDCDPVendor_'.$i]."', DDCDP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."', PORT_COSTDP_VENDOR='".$_REQUEST['selDPVendor_'.$i]."', IS_SHOW_DDCLP='".$_REQUEST['ChkShowDDCLP_'.$i]."', IS_SHOW_DDCDP='".$_REQUEST['ChkShowDDCDP_'.$i]."', RANDOMID='".$randomid."', PORT_COSTTP_VENDOR='".$_REQUEST['selTPVendor_'.$i]."', CHK_LP_SECA='".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', CHK_DP_SECA='".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', CHK_TP_SECA='".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', TOTAL_VOYAGE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', SECA_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', SECA_DAYS='".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."', LP_OPA_VENDOR='".$_REQUEST['selLPOPAVendor_'.$i]."', DP_OPA_VENDOR='".$_REQUEST['selDPOPAVendor_'.$i]."', LP_CA_VENDOR='".$_REQUEST['selLPCharterAgentVendor_'.$i]."', DP_CA_VENDOR='".$_REQUEST['selDPCharterAgentVendor_'.$i]."' where FCAID='".$id."' and FCA_SLAVEID='".$_REQUEST['txtFCASlaveID_'.$i]."'";	
			}
			else
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, PORT_COSTLP_VENDOR, DDCLP_COMM, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_VENDOR, DDCLP_NETCOST, DDCDP_COMM, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_VENDOR, DDCDP_NETCOST, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, PORT_COSTTP_VENDOR, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS, LP_OPA_VENDOR, DP_OPA_VENDOR, LP_CA_VENDOR, DP_CA_VENDOR) values ('".$id."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."' ,'".$_REQUEST['selLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$_REQUEST['selDDCLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$_REQUEST['selDDCDPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['selDPVendor_'.$i]."','".$_REQUEST['ChkShowDDCLP_'.$i]."','".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$_REQUEST['selTPVendor_'.$i]."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."','".$_REQUEST['selLPOPAVendor_'.$i]."','".$_REQUEST['selDPOPAVendor_'.$i]."','".$_REQUEST['selLPCharterAgentVendor_'.$i]."','".$_REQUEST['selDPCharterAgentVendor_'.$i]."')";	
			}
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtRateUSDmt_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] != "")
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."', 1, '".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtRateUSDmt2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] != "")
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtRateUSDmt3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] != "")
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, VENDORID, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$_REQUEST['selQtyVendor3_'.$i]."', '".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$id."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$id."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
		    $randomid = $_REQUEST['txtORCSlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtORCSlaveRandomID_'.$i]) || $_REQUEST['txtORCSlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT, VENDORID, RANDOMID) values ('".$id."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selORCVendor_'.$i])."', '".$randomid."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
		    $randomid = $_REQUEST['txtOISlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtOISlaveRandomID_'.$i]) || $_REQUEST['txtOISlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT, VENDORID, RANDOMID) values ('".$id."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOtherIncVendor_'.$i])."', '".$randomid."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql8 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."', '".$_REQUEST['selBrCommVendor_'.$i]."')";
				mysql_query($sql8)or die($sql8);
				mysql_query("commit");
			}
		}
		
		$txtTID = $_REQUEST['txtTID'];
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtDisponentOwner_'.$i] != "")
			{
				$sql9 = "insert into freight_cost_estimete_slave5 (FCAID, DISPONENT_OWNER) values ('".$id."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
				mysql_query($sql9) or die($sql9);
				mysql_query("commit");
			}
		} 
		
		$p_locationID = $_REQUEST['p_locationID'];
		for($i=1 ; $i<=$p_locationID ;$i++)
		{
			if($_REQUEST['txtFromLocation_'.$i] != "")
			{
				$sql10 = "insert into freight_cost_estimete_slave6 (FCAID, LOCATION_FROM, LOCATION_TO, PASSAGE_TYPE, SPEED_TYPE, DISTANCE) values ('".$id."', '".$_REQUEST['txtFromLocation_'.$i]."','".$_REQUEST['txtToLocation_'.$i]."','".$this->getCheckNullVal($_REQUEST['selPLocationType_'.$i])."','".$this->getCheckNullVal($_REQUEST['selSLocationSpeed_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtLocationDistance_'.$i])."')";
				mysql_query($sql10) or die($sql10);
				mysql_query("commit");
			}
		} 
		
		$txtQTYID = $_REQUEST['txtQTYID'];
		for($i=1 ; $i<=$txtQTYID ;$i++)
		{
			if($_REQUEST['selQtyVendorList_'.$i] != "")
			{
			    $randomid = $_REQUEST['txtQtySlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtQtySlaveRandomID_'.$i]) || $_REQUEST['txtQtySlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql2 = "insert into freight_cost_estimete_slave7 (FCAID, QTY_VENDORID, AGREED_GROSS_FREIGHT, QUANTITY, GROSS_FREIGHT, BROKERAGE, NET_BROKERAGE, NET_FREIGHT, NET_FREIGHT_PERMT, CURRENCYID, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, CARGO, RANDOMID) values ('".$id."','".$_REQUEST['selQtyVendorList_'.$i]."','".$_REQUEST['txtQtyAggriedFreight_'.$i]."','".$_REQUEST['txtFreightQty_'.$i]."','".$_REQUEST['txtQtyFreight_'.$i]."','".$_REQUEST['txtQtyBrokeragePer_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtQtyBrokerageAmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreightMT1_'.$i])."','".$this->getCheckNullVal($_REQUEST['selCurrencyDisList_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyLocalAggriedFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDisExchangeRate_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selQtyCargo_'.$i])."', '".$randomid."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		} 
		
		$txtNoOfInvoice = $_REQUEST['txtNoOfInvoice'];
		for($i=1;$i<=$txtNoOfInvoice;$i++)
		{
			if($_REQUEST['txtInvoiceID_'.$i]!='')
			{
				$sql11 = "insert into freight_cost_estimete_slave11 (INVOICEID, FCAID) values ('".addslashes(trim($_REQUEST['txtInvoiceID_'.$i]))."', '".$id."' )";
				mysql_query($sql11) or die($sql11);
				mysql_query("commit");
			}
		}
		
		
		$txtTankID = $_REQUEST['txtTankID'];
		for($i=1 ; $i<=$txtTankID ;$i++)
		{
			if($_REQUEST['txtFreightSpecs_'.$i] != "")
			{
				$sql12 = "insert into freight_cost_estimete_slave12 (FCAID, FREIGHT_SPECS, CUSTOMER, MIN_CARGO_QTY, OVE_CARGO_QTY, MIN_FLAT_RATE, OVE_FLAT_RATE, MIN_WS, OVE_WS, MIN_DIS_LEG, OVE_DIS_LEG, MIN_DISTANCE, OVE_DISTANCE, MIN_AMOUNT, OVE_AMOUNT, TOTAL_QTY, TOTAL_AMOUNT) values ('".$id."', '".$_REQUEST['txtFreightSpecs_'.$i]."', '".$_REQUEST['selTankVendor_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtMinCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtOveCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinDisLeg_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveDisLeg_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinTotalDis_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveTotalDis_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinAmount_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtTotalTankQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTotalTankAmount_'.$i])."')";
				mysql_query($sql12) or die($sql12);
				mysql_query("commit");
			}
		}
		
		$txtHIREID = $_REQUEST['txtHIREID'];
		for($i=1 ; $i<=$txtHIREID ;$i++)
		{
			if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
			{
				if($_REQUEST['txtHireFrom_'.$i]!="")
				{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
				else{$txtHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtHireTo_'.$i]!="")
				{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
				else{$txtHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCHireRandom_'.$i]) || $_REQUEST['txtTCHireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCHireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave17 (FCAID, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE, HIRE_AMT, RANDOMID) values ('".$id."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireAmt_'.$i])."', '".$this->getCheckNullValue($randomid4)."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		} 
		
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$id."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$id."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$id."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg; 
}


function getDateTimeCurrect($dateTime){
	
	if($dateTime !== ""){
		return date('Y-m-d H:i', strtotime($dateTime));
	}else{
		return '1970-01-01 08:00';
	}
}

function getCountryNameBasedOnID($id)
{
	$query = mysql_query("select COUNTRY_NAME from country_master where COUNTRYID='".$id."'");
	$rows  = mysql_fetch_assoc($query);
	return $rows['COUNTRY_NAME'];
}


function getLoadPortAndDischargePortQtyArrBasedOnMappingidAndProcesid($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$status  = $this->getFreightEstimationStatus($comid,$cost_sheet_id);
	//select FROM_PORT, TO_PORT, RANDOMID from freight_cost_estimete_slave1 where FCAID='".$cost_sheet_id."' order by FCA_SLAVEID asc
	$sql  = "select LOAD_PORT_QTY, DISC_PORT_QTY from freight_cost_estimete_slave1 where FCAID='".$this->getFCAIDBasedOnid($comid,$cost_sheet_id)."' order by FCA_SLAVEID asc";
	$res = mysql_query($sql);
	while($rows  = mysql_fetch_assoc($res))
	{
		$arr[] = $rows['LOAD_PORT_QTY'];
		$arr[] = $rows['DISC_PORT_QTY'];
	}
	return $arr;
}


function getValidateAgencyLetter($arr)
{
	for($i=0;$i<count($arr);$i++)
	{
		$j=$i+1;
		echo '$("#frm'.$j.'").validate({
		rules: {
			txtDate_'.$j.':"required",
			selAList_'.$j.':"required",
			txtName_'.$j.':"required",
			txtUName_'.$j.':"required",
			txtPassword_'.$j.':"required",
			selCOB_'.$j.':"required"
			},
		messages: {
			txtDate_'.$j.':"*",
			selAList_'.$j.':"*",
			txtName_'.$j.':"*",
			txtUName_'.$j.':"*",
			txtPassword_'.$j.':"*",
			selCOB_'.$j.':"*"
			}
			});';
	}
}


function getLoginShortNameBasedOnID()
{
	$sql = "select SHORT_NAME from main_company where MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['SHORT_NAME'];
}


function getContractMaterialTypeBasedOnID($cargo_position,$cargoids)
{
	$connect = $this->funConnect();
	if($cargo_position == "open")
	{
		$material = explode("@@@",$this->getOpenCargoMasterDataBasedOnContractID($cargoids,"MATERIAL_TYPE"));
		return $material[0];
	}
}

function getMaxAgencyNumber()
{
  $this->funConnect();
	
	$query = "SELECT MAX(USERNAMEID) + 1 as USERNAMEID FROM generate_agency_letter where 1=1 "; 
	//echo $query;
	$result = mysql_query($query);
	$rec=mysql_num_rows($result);
	
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['USERNAMEID'];
	if($rows['USERNAMEID'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}
		}//if ends here.
	else
		{
			$empcode='001';
		}
	}//WHILE ends here.
	
return $empcode;
}

function getCountryNameBasedOnPort($id)
{
	$connect 				= $this->funConnect();
	$sql = "select COUNTRY_NAME from port_master where PortId='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['COUNTRY_NAME'];
}



function insertGenerateAgencyLetterDetails()
{
	
	$connect 				= $this->funConnect();
	
	$tabid		          	= $_REQUEST['txttabid'][0];
	$submitid		        = addslashes(trim($_REQUEST['txtsubmitid_'.$tabid]));
	$genAgencyId		    = $_REQUEST['genAgencyId_'.$tabid];
	$comid          	= $_REQUEST['comid'];
	$sheetNo          	    = $_REQUEST['sheetNo'];
	$port		          	= $_REQUEST['txtport_'.$tabid];
	$portid		          	= $_REQUEST['txtportid_'.$tabid];
	$txtRandomID		    = $_REQUEST['txtRandomID_'.$tabid];
	
	/***********tolerance*****************************************/
	
	$txtTOfTolerance        = addslashes(trim($_REQUEST['txtTOfTolerance_'.$tabid]));
	$txtCargoPackDesc       = addslashes(trim($_REQUEST['txtCargoPackDesc_'.$tabid]));
	$txtTolerancePer1       = $this->getCheckNullValue($_REQUEST['txtTolerancePer1_'.$tabid]);
	$txtToleranceSub        = addslashes(trim($_REQUEST['txtToleranceSub_'.$tabid]));
	$txtToleranceAdd        = addslashes(trim($_REQUEST['txtToleranceAdd_'.$tabid]));
	$txtTolerancePer2       = $this->getCheckNullValue($_REQUEST['txtTolerancePer2_'.$tabid]);
	
	$date			        = date("Y-m-d",strtotime($_REQUEST['txtDate_'.$tabid]));
	$vendorid	            = addslashes(trim($_REQUEST['selAList_'.$tabid]));
	$qty		            = addslashes(trim($_REQUEST['txtQty_'.$tabid]));
	$kind_attn_to           = addslashes(trim($_REQUEST['txtName_'.$tabid]));
	$username	            = addslashes(trim($_REQUEST['txtUName_'.$tabid]));
	$password	            = addslashes(trim($_REQUEST['txtPassword_'.$tabid]));
	$qty		            = addslashes(trim($_REQUEST['txtQty_'.$tabid]));
	$country	            = addslashes(trim($_REQUEST['txtCountry_'.$tabid]));
	
	$txtVSLContactDetails	= addslashes(trim($_REQUEST['txtVSLContactDetails_'.$tabid]));
	$txtVSLDetails          = addslashes(trim($_REQUEST['txtVSLDetails_'.$tabid]));
	$txtAbout	            = addslashes(trim($_REQUEST['txtAbout_'.$tabid]));
	
	$txtEmail_1	            = addslashes(trim($_REQUEST['txtEmail_'.$tabid.'_1']));
	$txtEmail_2	            = addslashes(trim($_REQUEST['txtEmail_'.$tabid.'_2']));
	
	$txtCharEmail_1	        = addslashes(trim($_REQUEST['txtCharEmail_'.$tabid.'_1']));
	$txtCharEmail_2	        = addslashes(trim($_REQUEST['txtCharEmail_'.$tabid.'_2']));
	$txtCharEmail_3	        = addslashes(trim($_REQUEST['txtCharEmail_'.$tabid.'_3']));
	$txtCharEmail_4	        = addslashes(trim($_REQUEST['txtCharEmail_'.$tabid.'_4']));
	$txtCharEmail_5	        = addslashes(trim($_REQUEST['txtCharEmail_'.$tabid.'_5']));
	
	$selShipOwner		    = $this->getCheckNullValue($_REQUEST['selShipOwner_'.$tabid]);
	$PDIIniPayPer		    = $this->getCheckNullValue($_REQUEST['txtPDAIniPayPer_'.$tabid]);
	$PDIFinPayPer		    = $this->getCheckNullValue($_REQUEST['txtPDAFinPayPer_'.$tabid]);
	
	/********************************LETTER TO MASTER - BUNKER STEMMED************************************/
	
	$txtSupplier			= addslashes(trim($_REQUEST['txtSupplier_'.$tabid]));
	$txtPhysical          	= addslashes(trim($_REQUEST['txtPhysical_'.$tabid]));
	$txtFuelGrSp            = addslashes(trim($_REQUEST['txtFuelGrSp_'.$tabid]));
	$txtQuantity            = addslashes(trim($_REQUEST['txtQuantity_'.$tabid]));
	$txtETADate1_            = addslashes(trim($_REQUEST['txtETADate1_'.$tabid]));
	
	if($_REQUEST['txtETADate1_'.$tabid]!="")
	{
		$etadate1				= date("Y-m-d H:i",strtotime($_REQUEST['txtETADate1_'.$tabid]));
	}
	else
	{
		$etadate1				= "1970-01-01 08:00:00";
	}
	
	if($_REQUEST['txtETADATE_'.$tabid]!="")
	{
		$etadate				= date("Y-m-d H:i",strtotime($_REQUEST['txtETADATE_'.$tabid]));
	}
	else
	{
		$etadate				= "1970-01-01 08:00:00";
	}
	
	/********************************LETTER TO AGENT - BUNKER STEMMED***********************************/
	
	$txtBSBunPort			= addslashes(trim($_REQUEST['sel_Bunkering_Port_'.$tabid]));
	$txtBUNKER_SURVEYOR     = addslashes(trim($_REQUEST['txtBUNKER_SURVEYOR_'.$tabid]));
	$txtBUNKER_SURVEYORCOM  = addslashes(trim($_REQUEST['txtBUNKER_SURVEYORCOM_'.$tabid]));
		
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "select * from generate_agency_letter where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and VENDORID='".$vendorid."' and RANDOMID='".$txtRandomID."' ";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		$sql = "insert into generate_agency_letter (COMID,MODULEID,MCOMPANYID,PORT,PORTID,DATE,VENDORID,KIND_ATTN_TO,USERNAMEID,USERNAME,PASSWORD,QTY,COUNTRY_ID, VSL_CONTACT_DETAILS, VSL_DETAILS, VSL_ABOUT, SHIP_OWNER, BS_SUPPLIER, BS_PHYSICAL, BS_FUEL_GR_SP, BS_QUANTITY, BS_DOLOR_APP, BA_ABOUT, BA_HSFO_QTY, BA_SUPPLIER_T_B_AD, BA_NECESSARY_GUID, BS_BUNKERING_PORT, TERMO_OF_TOLERANCE, CARGO_PACKING_DESC, TOLERANCE_PERCENT_SUB, TOLERANCE_PERCENT_ADD, RANDOMID, STATUS, ETA_DATE, BUNKER_SURVEYOR, BUNKER_SURVEYORCOM, LOGINID, ETA_DATE1) values ('".$comid."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$port."','".$portid."','".$date."','".$vendorid."','".$kind_attn_to."','".$this->getMaxAgencyNumber()."','".$username."','".$password."','".$this->getCheckNullVal($qty)."','".$country."', '".$txtVSLContactDetails."', '".$txtVSLDetails."', '".$txtAbout."','".$selShipOwner."','".$txtSupplier."','".$txtPhysical."','".$txtFuelGrSp."','".$txtQuantity."','".$txtDolorApp."','".$txtBAAbout."','".$txtHSFOQty."','".$txtSuppliersToBeAd."','".$txtNecessaryGd."','".$txtBSBunPort."','".$txtTOfTolerance."','".$txtCargoPackDesc."','".$txtTolerancePer1."','".$txtTolerancePer2."','".$txtRandomID."', '".$submitid."', '".$etadate."', '".$txtBUNKER_SURVEYOR."', '".$txtBUNKER_SURVEYORCOM."', '".$_SESSION['uid']."', '".$etadate1."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(GEN_AGENCY_ID) as max from generate_agency_letter";
		$myres  =  mysql_query($mysql,$connect);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
		
		for($i=1;$i<= $_REQUEST['rowcount'.$tabid]; $i++)
		{
			if($_REQUEST['selEntity_'.$tabid.'_'.$i]!='' && $_REQUEST['txtEntityName_'.$tabid.'_'.$i]!='' && $_REQUEST['txtEntityEmail_'.$tabid.'_'.$i]!='')
			{
				$sql1 = "insert into generate_agency_letter_slave1 (GEN_AGENCY_ID, ENTITY, ENTITY_NAME, EMAILID) values ('".$maxid."','".$_REQUEST['selEntity_'.$tabid.'_'.$i]."','".$_REQUEST['txtEntityName_'.$tabid.'_'.$i]."','".$_REQUEST['txtEntityEmail_'.$tabid.'_'.$i]."')";	
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		for($i=1;$i<= $_REQUEST['rowcount1'.$tabid]; $i++)
		{
			if($_REQUEST['txtGrade_'.$tabid.'_'.$i]!='' && $_REQUEST['txtSupplier_'.$tabid.'_'.$i]!='' && $_REQUEST['txtPhysical_'.$tabid.'_'.$i]!='' && $_REQUEST['txtQuantity_'.$tabid.'_'.$i]!='')
			{
				$sql1 = "insert into generate_agency_letter_slave2 (GEN_AGENCY_ID, GRADE, SUPPLIER, PHYSICAL, QUANTITY, BUNKERPORT) values ('".$maxid."','".$_REQUEST['txtGrade_'.$tabid.'_'.$i]."','".$_REQUEST['txtSupplier_'.$tabid.'_'.$i]."','".$_REQUEST['txtPhysical_'.$tabid.'_'.$i]."','".$_REQUEST['txtQuantity_'.$tabid.'_'.$i]."','".$_REQUEST['selBunkeringPort_'.$tabid.'_'.$i]."')";	
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
	}
	else
	{
		
		if($genAgencyId !='')
		{
			$sql = "update generate_agency_letter set DATE='".$date."', VENDORID='".$vendorid."', KIND_ATTN_TO='".$kind_attn_to."', USERNAME='".$username."', PASSWORD='".$password."', QTY='".$this->getCheckNullVal($qty)."', COUNTRY_ID='".$country."', VSL_CONTACT_DETAILS='".$txtVSLContactDetails."', VSL_DETAILS='".$txtVSLDetails."', VSL_ABOUT='".$txtAbout."', SHIP_OWNER='".$selShipOwner."', EMAIL_ADDRESS_1='".$txtEmail_1."', EMAIL_ADDRESS_2='".$txtEmail_2."', EMAIL_CHARTER_1='".$txtCharEmail_1."', EMAIL_CHARTER_2='".$txtCharEmail_2."', EMAIL_CHARTER_3='".$txtCharEmail_3."', EMAIL_CHARTER_4='".$txtCharEmail_4."', EMAIL_CHARTER_5='".$txtCharEmail_5."', BS_SUPPLIER='".$txtSupplier."', BS_PHYSICAL='".$txtPhysical."', BS_FUEL_GR_SP='".$txtFuelGrSp."', BS_QUANTITY='".$txtQuantity."', BS_DOLOR_APP='".$txtDolorApp."', BA_ABOUT='".$txtBAAbout."', BA_HSFO_QTY='".$txtHSFOQty."', BA_SUPPLIER_T_B_AD='".$txtSuppliersToBeAd."', BA_NECESSARY_GUID='".$txtNecessaryGd."', BS_BUNKERING_PORT='".$txtBSBunPort."', TERMO_OF_TOLERANCE='".$txtTOfTolerance."', CARGO_PACKING_DESC='".$txtCargoPackDesc."', TOLERANCE_PERCENT_SUB='".$txtTolerancePer1."', TOLERANCE_PERCENT_ADD='".$txtTolerancePer2."', RANDOMID='".$txtRandomID."', STATUS='".$submitid."', ETA_DATE='".$etadate."', BUNKER_SURVEYOR='".$txtBUNKER_SURVEYOR."', BUNKER_SURVEYORCOM='".$txtBUNKER_SURVEYORCOM."', ETA_DATE1='".$etadate1."' where GEN_AGENCY_ID='".$genAgencyId."'  AND COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and VENDORID='".$vendorid."'";
			mysql_query($sql) or die($sql);
			mysql_query("commit");
			
			$del_query3 = "delete from  generate_agency_letter_slave1 where GEN_AGENCY_ID='".$genAgencyId."'";
			$del_query4 = "delete from  generate_agency_letter_slave2 where GEN_AGENCY_ID='".$genAgencyId."'";
			mysql_query($del_query3);
			mysql_query($del_query4);
			mysql_query("commit");
			
			
			for($i=1;$i<= $_REQUEST['rowcount'.$tabid]; $i++)
			{
				if($_REQUEST['selEntity_'.$tabid.'_'.$i]!='' && $_REQUEST['txtEntityName_'.$tabid.'_'.$i]!='' && $_REQUEST['txtEntityEmail_'.$tabid.'_'.$i]!='')
				{
					$sql1 = "insert into generate_agency_letter_slave1 (GEN_AGENCY_ID, ENTITY, ENTITY_NAME, EMAILID) values ('".$genAgencyId."','".$_REQUEST['selEntity_'.$tabid.'_'.$i]."','".$_REQUEST['txtEntityName_'.$tabid.'_'.$i]."','".$_REQUEST['txtEntityEmail_'.$tabid.'_'.$i]."')";	
					mysql_query($sql1) or die($sql1);
				}
			}
			
			for($i=1;$i<= $_REQUEST['rowcount1'.$tabid]; $i++)
			{
				if($_REQUEST['txtGrade_'.$tabid.'_'.$i]!='' && $_REQUEST['txtSupplier_'.$tabid.'_'.$i]!='' && $_REQUEST['txtPhysical_'.$tabid.'_'.$i]!='' && $_REQUEST['txtQuantity_'.$tabid.'_'.$i]!='')
				{
					$sql1 = "insert into generate_agency_letter_slave2 (GEN_AGENCY_ID, GRADE, SUPPLIER, PHYSICAL, QUANTITY, BUNKERPORT) values ('".$genAgencyId."','".$_REQUEST['txtGrade_'.$tabid.'_'.$i]."','".$_REQUEST['txtSupplier_'.$tabid.'_'.$i]."','".$_REQUEST['txtPhysical_'.$tabid.'_'.$i]."','".$_REQUEST['txtQuantity_'.$tabid.'_'.$i]."','".$_REQUEST['selBunkeringPort_'.$tabid.'_'.$i]."')";	
					mysql_query($sql1) or die($sql1);
				}
			}
		
		}else{
			
			return 1;
		}
	}
	mysql_query("commit");
	return $msg; 
}


function getLoadPortCostData($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from loadport_cost_master where GEN_AGENCY_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getFinancialYear()
{
	$year = date("Y",time());
	if(date("m",time()) < '04'){$curr_fyear = ($year-1)."-".$year;}
	else{$curr_fyear = $year."-".($year+1);}
	for($i=($year-11);$i<=($year+9);$i++) 
	{
	$value = date("Y", mktime(0, 0, 0, 1, 1, $i))."-".date("Y", mktime(0, 0, 0, 1, 1, ($i+1)));
	$key = date("Y", mktime(0, 0, 0, 1, 1, $i))."-".date("Y", mktime(0, 0, 0, 1, 1, ($i+1)));
	
	echo "<option value='$key'";
	if($key == $curr_fyear){ echo " selected";}
	echo ">".$value."</option>";
	}
}
function getNumberFormat($number)
{
	$this->funConnect();
	if($number < 0)
	{
		return "( ".number_format(abs($number),2,'.',',')." )";
	}
	else
	{
		return number_format($number,2,'.',',');
	}
}

function getNumberFormat1($number)
{
	$this->funConnect();
	return number_format($number,2,'.',',');
}

function getAttachedVesselWithCOABasedOnFinancialYear($coaid,$year,$month)
{
	$connect = $this->funConnect();
	$next_year = $year + 1;
	$sql = "select * from open_vessel_entry_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FROM_DATE between '".$year."-04-01' and '".$next_year."-03-31' and COA_NO='".$coaid."' order by OPENVESSEL_ID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	
	if($rec > 0)
	{
		while($rows = mysql_fetch_assoc($res))
		{
			if(date("m",strtotime($rows['FROM_DATE'])) == $month)
			{
				$arr[] = '('.date("d-M-Y",strtotime($rows['FROM_DATE'])).' To '.date("d-M-Y",strtotime($rows['TO_DATE'])).')<br>'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME");
			}
		}
		if (count($arr) > 0)
		{	
			return implode("<br><br>",$arr);
		}
		else
		{
			$sql1 = "select * from coa_monthly_remark where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COAID='".$coaid."' and DATE between '".$year."-04-01' and '".$next_year."-03-31'";
			$res1 = mysql_query($sql1);
			$rec1 = mysql_num_rows($res1);
			if($rec1 > 0)
			{
				while($rows1 = mysql_fetch_assoc($res1))
				{
					if(date("m",strtotime($rows1['DATE'])) == $month)
					{
						$arr1[] = $rows1['REMARK'];
					}
				}	
				return implode("<br>",$arr1);
			}
			else
			{
				return "";
			}
		}
	}
	else
	{
		$sql1 = "select * from coa_monthly_remark where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COAID='".$coaid."' and DATE between '".$year."-04-01' and '".$next_year."-03-31'";
		$res1 = mysql_query($sql1);
		$rec1 = mysql_num_rows($res1);
		if($rec1 > 0)
		{
			while($rows1 = mysql_fetch_assoc($res1))
			{
				if(date("m",strtotime($rows1['DATE'])) == $month)
				{
					$arr1[] = $rows1['REMARK'];
				}
			}	
			return implode("<br>",$arr1);
		}
		else
		{
			return "";
		}
	}
}

function getAgentList()
{
	$connect = $this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table width="100%" id="AgentTable" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th>Sr. No</th>';
	echo '<th>Voyage Financials Name</th>';
	echo '<th width="10%">CP Date</th>';
	echo '<th>Vessel Name</th>';
	echo '<th>Port</th>';
	echo '<th>Material Code</th>';
	echo '<th>Agent</th>';
	echo '<th>Shipper</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	$sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,3,4) order by freight_cost_estimate_compare.COMID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i=1;
	$cost_sheet_id = "";
	$arr = array();
	while($rows = mysql_fetch_assoc($res))
	{
		$l_cost_sheet_id = $this->getLatestCostSheetID($rows['COMID']);
		$arr = $this->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($rows['COMID'],$l_cost_sheet_id);
		$port_arr = $this->getPortNameBasedOnID($rows['LPID']);
		for($j=0;$j<count($arr);$j++)
		{
			$arr_portval = explode('@@',$arr[$j]);
			echo '<tr>';
			echo '<td>'.$i.'.</td>';
			echo '<td>'.$rows['VOYAGE_NAME'].'</td>';
			if(date("d-M-Y",strtotime($rows['TRANS_DATE'])) == "01-Jan-1970")
			{
				echo '<td></td>';
			}
			else
			{
				echo '<td>'.date("d-m-Y",strtotime($rows['TRANS_DATE'])).'</td>';
			}
			echo '<td>'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
			echo '<td>'.$this->getPortName($arr_portval[1]).'</td>';
			echo '<td>'.$this->getMaterialCodeDesBasedOnId($this->getCompareEstimateData($rows['COMID'],"CARGO_ID")).'</td>';
			
			$mysql = "select * from generate_agency_letter where COMID='".$rows['COMID']."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and PORT='".substr($arr[$j],0,2)."' and PORTID='".$arr_portval[1]."' and RANDOMID='".$arr_portval[2]."' and STATUS=2";
			$myres = mysql_query($mysql);
			$myrec = mysql_num_rows($myres);
			if($myrec == 1)
			{
				$myrows  = mysql_fetch_assoc($myres);
				echo '<td>'.$this->getVendorListNewBasedOnID($myrows['VENDORID']).'</td>';
			}
			else
			{
				echo '<td></td>';
			}
			echo '<td>'.$this->getVendorListNewBasedOnID($this->getCompareEstimateData($rows['COMID'],"SHIPPER")).'</td>';
			echo '</tr>';
			$i++;
		}
	}
	
	echo '</tbody>';	
	echo '</table></div>';
}

function getDailyPositionReport($selBType)
{
	$connect = $this->funConnect();
	
	 echo '<h3 style="text-align:center;">'.date("d M Y",time()).' - DAILY POSITION REPORT</h3>';
	 echo '<div style="overflow:auto;">';	
	 echo '<div class="box-body table-responsive">';	
	 echo '<table cellspacing="0" id="GridView1" class="table table-bordered table-striped" style="width:100%;border-collapse:collapse;">';
	 
	 $sql = "select * from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID= freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and freight_cost_estimate_compare.FINAL_ID!='' and freight_cost_estimete_master.FIXED=1 and freight_cost_estimate_compare.STATUS in (1,2) and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBType."'  order by freight_cost_estimate_compare.COMID desc";
	 $res  = mysql_query($sql);
	 $res1 = mysql_query($sql);
	 $res2 = mysql_query($sql);
	 $res3 = mysql_query($sql);
	 $rec  = mysql_num_rows($res);
	 if($rec == 0)
	 {
		 echo '<tr>';
		 echo '<td align="center" colspan="18" valign="middle" style="color:#ff0000;letter-spacing:1px;">'.strtoupper("Sorry Currently there are zero(0) records").'</td>';
		 echo '</tr>';
	 }
	 else
	 {
	 		//............................for TOWARDS LOAD PORT - AT SEA .........................................................
	 	 	echo '<tr class="GridviewScrollHeader" style="font-size:12px;color:#000; background-color:#1E85BE;">';
		 	echo '<td align="left" valign="top">TOWARDS </td>';
			echo '<td align="left" valign="top">LOAD PORT - AT SEA</td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '</tr>';
		 
			echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
			echo '<td align="center" valign="top">S. No.</td>';
			echo '<td align="center" valign="top">Vessel</td>';
			echo '<td align="center" valign="top">Operator</td>';
			echo '<td align="center" valign="top">Nom ID</td>';
			echo '<td align="center" valign="top">Owner</td>';
			echo '<td align="center" valign="top">Port</td>';
			echo '<td align="center" valign="top">Shipper</td>';
			echo '<td align="center" valign="top">ETA</td>';
			echo '<td align="center" valign="top">Quantity</td>';
			echo '<td align="center" valign="top" colspan="2">Laycan (Shipper)</td>';
			echo '<td align="center" valign="top">Agent</td>';
			echo '<td align="center" valign="top">Broker</td>';
			echo '<td align="center" valign="top">NT</td>';
			echo '<td align="center" valign="top">Laycan (Owner)</td>';
			echo '<td align="center" valign="top">Discharge Port</td>';
			echo '<td align="center" valign="top">Remarks</td>';
			echo '<td align="center" valign="top">Dem. Rate1</td>';
			echo '</tr>';
			$j=1;
		 while($rows = mysql_fetch_assoc($res))
		  {
			  $port_arr_lp       = $this->getLoadPortArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID']);
			 	for($i=0;$i<count($port_arr_lp);$i++)
				{
					if($this->getCheckListRecordsRecBasedOnComID($rows['COMID']) > 0)
					{
						$arr_loadport = explode('###',$port_arr_lp[$i]);
						if($this->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"NOR TENDERED") == " ")
						{
							$count_arr_lp1[] = $j;
							echo '<tr class="GridviewScrollItem">';
							echo '<td align="center" valign="top">'.$j.'.</td>';
							echo '<td align="left" valign="top">'.$this->getVesselIMOData($this->getCompareEstimateData($rows['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
							echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"OPERATOR").'</td>';
							echo '<td align="left" valign="top">'.$this->getCompareTableData($rows['COMID'],"MESSAGE").'</td>';
							echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"OWNER_NAME").'</td>';
							echo '<td align="left" valign="top">'.$this->getPortNameBasedOnID($arr_loadport[0]).'</td>';
							echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"SHIPPER").'</td>';
							echo '<td align="left" valign="top">'.$this->getMaxETADate($rows['COMID'],"LP",$arr_loadport[0],$arr_loadport[1]).'</td>';
							echo '<td align="left" valign="top">'.$this->getFreightCostData($rows['COMID'],$this->getLatestCostSheetID($rows['COMID']),"CARGO_QTY").'</td>';
							echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"LAYCAN (SHIPPER)").'</td>';
							echo '<td align="left" valign="top"></td>';
							echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"AGENT").'</td>';
							echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"BROKER").'</td>';
							echo '<td align="left" valign="top">'.$this->getETARec($rows['COMID'],"LP",$arr_loadport[0],$arr_loadport[1]).'</td>';
							echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"LAYCAN (OWNER)").'</td>';
							echo '<td align="left" valign="top">'.implode(" , ",$this->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID'])).'</td>';
							echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"REMARKS 1").'</td>';
							echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows['COMID'],"DEMM_RATE").'</td>';
							echo '</tr>';
							 $j++;
						}
					}
			   }
			}//die;
			if(!is_array($count_arr_lp1))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '</tr>';
			}
		  //....................................ends here................................................................
		  
		  //............................for AT LOAD PORT  .........................................................
	 	 	echo '<tr class="GridviewScrollHeader" style="font-size:12px;color:#fff; background-color:#1E85BE;">';
		 	echo '<td align="left" valign="top">AT&nbsp;&nbsp;&nbsp;LOAD</td>';
			echo '<td align="left" valign="top" >PORT</td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '</tr>';
		 
			echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
			echo '<td align="center"  valign="top">S. No.</td>';
			echo '<td align="center"  valign="top">Vessel</td>';
			echo '<td align="center"  valign="top">Operator</td>';
			echo '<td align="center"  valign="top">Nom ID</td>';
			echo '<td align="center"  valign="top">Owner</td>';
			echo '<td align="center"  valign="top">Port&nbsp;</td>';
			echo '<td align="center"  valign="top">Shipper</td>';
			echo '<td align="center"  valign="top">ETC/D</td>';
			echo '<td align="center"  valign="top">Balance</td>';
			echo '<td align="center" valign="top">Total</td>';
			echo '<td align="center" valign="top">24 Hrs</td>';
			echo '<td align="center"  valign="top">Agent</td>';
			echo '<td align="center"  valign="top">Broker</td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top">Laycan (Owner)</td>';
			echo '<td align="center"  valign="top">Discharge Port</td>';
			echo '<td align="center"  valign="top">Remarks</td>';
			echo '<td align="center"  valign="top">Dem. Rate2</td>';
			echo '</tr>';
			$j=1;
		 	while($rows1 = mysql_fetch_assoc($res1))
		  	{
			    $port_arr_lp       = $this->getLoadPortArrBasedOnIDComidAndProcessWithoutTBN($rows1['COMID']);
			 	for($i=0;$i<count($port_arr_lp);$i++)
				{
				if($this->getCheckListRecordsRecBasedOnComID($rows1['COMID']) > 0)
				{
					$arr_loadport = explode('###',$port_arr_lp[$i]);
					if($this->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"NOR TENDERED") != " ")
					{
						$count_arr_lp2[] = $j;
						echo '<tr class="GridviewScrollItem">';
						echo '<td align="center" valign="top">'.$j.'.</td>';
						echo '<td align="left" valign="top">'.$this->getVesselIMOData($this->getCompareEstimateData($rows1['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"OPERATOR").'</td>';
						echo '<td align="left" valign="top">'.$this->getCompareTableData($rows1['COMID'],"MESSAGE").'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"OWNER_NAME").'</td>';
						echo '<td align="left" valign="top">'.$this->getPortNameBasedOnID($arr_loadport[0]).'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"SHIPPER").'</td>';
						$etc_date = $this->getAgentOrCheckListData($rows1['COMID'],"LP",$arr_loadport[0],$arr_loadport[1],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"ETCD","ETC/D");
						if($etc_date!= "" && $etc_date!= "1970-01-01 08:00:00")
						{
							echo '<td>'.date("d-M-Y H:i",strtotime($etc_date)).'</td>';
						}
						else
						{
							echo '<td></td>';
						}
						echo '<td align="left" valign="top">'.$this->getAgentOrCheckListData($rows1['COMID'],"LP",$arr_loadport[0],$arr_loadport[1],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"BALANCE","BALANCE").'</td>';
						echo '<td align="left" valign="top">'.$this->getAgentOrCheckListData($rows1['COMID'],"LP",$arr_loadport[0],$arr_loadport[1],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"TTL_LOAD","TOTAL").'</td>';
						echo '<td align="left" valign="top">'.$this->getAgentOrCheckListData($rows1['COMID'],"LP",$arr_loadport[0],$arr_loadport[1],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"LOAD_LAST","24HRS").'</td>';
						echo '<td align="left" valign="top" >'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"AGENT").'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"BROKER").'</td>';
						echo '<td align="left" valign="top"></td>';
						echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"LAYCAN (OWNER)").'</td>';
						echo '<td align="left" valign="top" >'.implode(", ",$this->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows1['COMID'])).'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows1['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"CHECKLIST_ID"),"LP",$arr_loadport[0],$arr_loadport[1],"REMARKS 2").'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows1['COMID'],"DEMM_RATE").'</td>';
						echo '</tr>';
						 $j++;
					}
				}
			   }
			}
			if(!is_array($count_arr_lp2))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top"></td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '</tr>';
			}
		  //....................................ends here................................................................
	   	  //............................for TOWARDS DISCHARGE PORT - AT SEA .........................................................
	 	 	echo '<tr class="GridviewScrollHeader" style="font-size:12px;color:#000; background-color:#1E85BE;">';
		 	echo '<td align="left" valign="top">TOWARDS </td>';
			echo '<td align="left" valign="top">DISCHARGE PORT - AT SEA</td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '</tr>';
		 
			echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
			echo '<td align="center" valign="top" >S. No.</td>';
			echo '<td align="center" valign="top">Vessel</td>';
			echo '<td align="center" valign="top">Operator</td>';
			echo '<td align="center" valign="top">Nom ID</td>';
			echo '<td align="center" valign="top">Owner</td>';
			echo '<td align="center" valign="top">Port</td>';
			echo '<td align="center" valign="top">Receiver</td>';
			echo '<td align="center" valign="top">ETA</td>';
			echo '<td align="center" valign="top">Quantity</td>';
			echo '<td align="center" valign="top" colspan="2">LOI to Owner</td>';
			echo '<td align="center" valign="top">Agent</td>';
			echo '<td align="center" valign="top">Broker</td>';
			echo '<td align="center" valign="top">&nbsp;&nbsp;NT&nbsp;&nbsp;</td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top">Load Port</td>';
			echo '<td align="center" valign="top">Remarks</td>';
			echo '<td align="center" valign="top">Dem. Rate3</td>';
			echo '</tr>';
			$j=1;
		 	while($rows2 = mysql_fetch_assoc($res2))
		  	{
			    $port_arr_dp       = $this->getDisPortArrBasedOnIDComidAndProcessWithoutTBN($rows2['COMID']);
			 	for($i=0;$i<count($port_arr_dp);$i++)
				{
				if($this->getCheckListRecordsRecBasedOnComID($rows2['COMID']) > 0)
				{
					$arr_dischargeport = explode('###',$port_arr_dp[$i]);
					if($this->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"NOR TENDERED") == " ")
					{
						$count_arr_dp1[] = $j;
						echo '<tr class="GridviewScrollItem">';
						echo '<td align="center" valign="top">'.$j.'.</td>';
						echo '<td align="left" valign="top">'.$this->getVesselIMOData($this->getCompareEstimateData($rows2['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"OPERATOR").'</td>';
						echo '<td align="left" valign="top">'.$this->getCompareTableData($rows2['COMID'],"MESSAGE").'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"OWNER_NAME").'</td>';
						echo '<td align="left" valign="top">'.$this->getPortNameBasedOnID($arr_dischargeport[0]).'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"RECEIVER").'</td>';
						echo '<td align="left" valign="top">'.$this->getMaxETADate($rows2['COMID'],"DP",$arr_dischargeport[0],$arr_dischargeport[1]).'</td>';
						echo '<td align="left" valign="top">'.$this->getFreightCostData($rows2['COMID'],$this->getLatestCostSheetID($rows2['COMID']),"CARGO_QTY").'</td>';
						if($this->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"LOI TO OWNER") == 1)
						{
							echo '<td align="left" valign="top">Yes</td>';
						}
						else
						{
							echo '<td align="left" valign="top">No</td>';
						}
						echo '<td align="left" valign="top"></td>';
						echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"AGENT").'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"BROKER").'</td>';
						echo '<td align="left" valign="top">'.$this->getETARec($rows2['COMID'],"DP",$arr_dischargeport[0],$arr_dischargeport[1]).'</td>';
						echo '<td align="left" valign="top"></td>';
						echo '<td align="left" valign="top">'.implode(", ",$this->getLoadPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows2['COMID'])).'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows2['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"REMARKS").'</td>';
						echo '<td align="left" valign="top">'.$this->getCheckListRecordsDataBasedOnComID($rows2['COMID'],"DEMM_RATE").'</td>';
						echo '</tr>';
						 $j++;
					}
				}
			   }
		  	}
			if(!is_array($count_arr_dp))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top"></td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '<td align="center" valign="top">-</td>';
				echo '</tr>';
			}
		  	//....................................ends here................................................................
		  	//............................for AT DISCHARGE PORT  .........................................................
	 	 	echo '<tr class="GridviewScrollHeader" style="font-size:12px;color:#000; background-color:#1E85BE;">';
		 	echo '<td align="left" valign="top">AT&nbsp;&nbsp;&nbsp;DISCHARGE</td>';
			echo '<td align="left" valign="top" >PORT</td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '<td align="left" valign="top"></td>';
			echo '</tr>';
		 
			echo '<tr class="GridviewScrollHeader" style="font-size:12px; background-color:#eee;">';
			echo '<td align="center" valign="top">S. No.</td>';
			echo '<td align="center" valign="top">Vessel</td>';
			echo '<td align="center" valign="top">Operator</td>';
			echo '<td align="center" valign="top">Nom ID</td>';
			echo '<td align="center" valign="top">Owner</td>';
			echo '<td align="center" valign="top">Port</td>';
			echo '<td align="center" valign="top">Receiver</td>';
			echo '<td align="center" valign="top">ETC/D</td>';
			echo '<td align="center" valign="top">Balance</td>';
			echo '<td align="center" valign="top">Total</td>';
			echo '<td align="center" valign="top">24 Hrs</td>';
			echo '<td align="center" valign="top">Agent</td>';
			echo '<td align="center" valign="top">Broker</td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top"></td>';
			echo '<td align="center" valign="top">Load Port</td>';
			echo '<td align="center" valign="top">Remarks</td>';
			echo '<td align="center" valign="top">Dem. Rate4</td>';
			echo '</tr>';
			$j=1;
			while($rows3 = mysql_fetch_assoc($res3))
			{
				$port_arr_dp   = $this->getDisPortArrBasedOnIDComidAndProcessWithoutTBN($rows3['COMID']);
				for($i=0;$i<count($port_arr_dp);$i++)
				{
				if($this->getCheckListRecordsRecBasedOnComID($rows3['COMID']) > 0)
				{
					$arr_dischargeport = explode('###',$port_arr_dp[$i]);
					if($this->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"NOR TENDERED") != " ")
					{
						$count_arr_dp2[] = $j;
						echo '<tr class="GridviewScrollItem">';
						echo '<td align="center" valign="top" >'.$j.'.</td>';
						echo '<td align="left" valign="top" >'.$this->getVesselIMOData($this->getCompareEstimateData($rows3['COMID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</td>';
						echo '<td align="left" valign="top" >'.$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"OPERATOR").'</td>';
						echo '<td align="left" valign="top" >'.$this->getCompareTableData($rows3['COMID'],"MESSAGE").'</td>';
						echo '<td align="left" valign="top" >'.$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"OWNER_NAME").'</td>';
						echo '<td align="left" valign="top" >'.$this->getPortNameBasedOnID($arr_dischargeport[0]).'</td>';
						echo '<td align="left" valign="top" >'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"RECEIVER").'</td>';
						$etc_date = $this->getAgentOrCheckListData($rows3['COMID'],"DP",$arr_dischargeport[0],$arr_dischargeport[1],$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID"),"ETCD","ETC/D");
						if($etc_date!= "" && $etc_date!= "1970-01-01 08:00:00")
						{
							echo '<td align="left"  valign="top">'.date("d-M-Y H:i",strtotime($etc_date)).'</td>';
						}
						else
						{
							echo '<td align="left" valign="top" ></td>';
						}
						echo '<td align="left" valign="top" >'.$this->getAgentOrCheckListData($rows3['COMID'],"DP",$arr_dischargeport[0],$arr_dischargeport[1],$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID"),"BALANCE","BALANCE").'</td>';
						echo '<td align="left" valign="top" >'.$this->getAgentOrCheckListData($rows3['COMID'],"DP",$arr_dischargeport[0],$arr_dischargeport[1],$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID"),"TTL_LOAD","TOTAL").'</td>';
						echo '<td align="left" valign="top" >'.$this->getAgentOrCheckListData($rows3['COMID'],"DP",$arr_dischargeport[0],$arr_dischargeport[1],$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID"),"LOAD_LAST","24HRS").'</td>';
						echo '<td align="left" valign="top" >'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"AGENT").'</td>';
						echo '<td align="left" valign="top" >'.$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"BROKER").'</td>';
						echo '<td align="left" valign="top" ></td>';
						echo '<td align="left" valign="top" ></td>';
						echo '<td align="left" valign="top" >'.implode(", ",$this->getLoadPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows3['COMID'])).'</td>';
						echo '<td align="left" valign="top" >'.$this->getCheckListPortDataRecordsRecBasedOnComID($rows3['COMID'],$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"CHECKLIST_ID"),"DP",$arr_dischargeport[0],$arr_dischargeport[1],"REMARKS 4").'</td>';
						echo '<td align="left" valign="top" >'.$this->getCheckListRecordsDataBasedOnComID($rows3['COMID'],"DEMM_RATE").'</td>';
						echo '</tr>';
						 $j++;
					}
				}
			   }
			}


			if(!is_array($count_arr_dp1))
			{
				echo '<tr class="GridviewScrollItem">';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" ></td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '<td align="center" valign="top" >-</td>';
				echo '</tr>';
			}
		  //....................................ends here................................................................
	  }
	
	echo '</table>';
	echo '</div>';	
	echo '</div>';
}

function getCOA_SPOTBasedOnID($id)
{
	if($id == 1){return 'SPOT';}
	if($id == 2){return 'COA';}
	if($id == 3){return 'TC';}
	if($id == 4){return 'POOL';}
}

function getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($comid)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$sql1 = "select TO_PORT from freight_cost_estimete_slave1 where FCAID='".$this->getLatestCostSheetID($comid)."' and DISC_PORT_QTY>0";
	$res1 = mysql_query($sql1);
	while($rows1  = mysql_fetch_assoc($res1))
	{
		if($this->getPortNameBasedOnID($rows1['TO_PORT']) != "TBN")
		{
			$arr[] = $this->getPortNameBasedOnID($rows1['TO_PORT']);
		}
	}
	return $arr;
}

function getLoadPortNameArrBasedOnIDComidAndProcessWithoutTBN($comid)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$sql  = "select FROM_PORT from freight_cost_estimete_slave1 where FCAID='".$this->getLatestCostSheetID($comid)."' and LOAD_PORT_QTY>0";
	$res = mysql_query($sql);
	while($rows  = mysql_fetch_assoc($res))
	{
		if($this->getPortNameBasedOnID($rows['FROM_PORT']) != "TBN")
		{
			$arr[] = $this->getPortNameBasedOnID($rows['FROM_PORT']);
		}
	}
	return $arr;
}


function changeVessel()
{
	$connect = $this->funConnect();
	$id 				= $_REQUEST['id'];
	$selVName	 		= addslashes(trim($_REQUEST['selVName']));
	$from_date			= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	$to_date 			= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
		
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	//insert query here.............
	$sql = "update open_vessel_entry_master set VESSEL_IMO_ID='".$selVName."',FROM_DATE='".$from_date."',TO_DATE='".$to_date."' where OPENVESSEL_ID='".$id."'";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	return $msg; 
}


function getBLDateNew($mappingid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$fcaid   = $this->getCurrentCostSheetFCAID($mappingid,$cost_sheet_id);
	$portid  = $this->getFirstLoadPortID($mappingid,$fcaid);
	
	$sql = "select BL_DATE from sof_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$mappingid."' and LOGIN = 'INTERNAL_USER' and PORT='LP' and PORTID='".$portid."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		return "";
	}
	else
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$bl_date = $rows['BL_DATE'];
		}
		return date("d-m-Y",strtotime($bl_date));
	}
}


function getFirstLoadPortID($mappingid,$fcaid)
{
	$connect = $this->funConnect();
	if($this->getFreightEstimationStatus1($mappingid) == 1)
	{
		$sql = "select LOADPORTID from fca_tci_load_port where FCAID='".$fcaid."'";
	}
	else if($this->getFreightEstimationStatus1($mappingid) == 2)
	{
		$sql = "select LOADPORTID from fca_vci_load_port where FCAID='".$fcaid."'";
	}
	$result = mysql_query($sql);
	$rows   = mysql_fetch_assoc($result);
	return $rows['LOADPORTID'];
}


function getCurrentCostSheetFCAID($mappingid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql 	 = "select FCAID from freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$mappingid."' and SHEET_NO = '".$cost_sheet_id."' and FINAL_STATUS=1";
	$result  = mysql_query($sql);
	while($rows = mysql_fetch_assoc($result))
	{
		$fcaid = $rows['FCAID'];
	}
	return $fcaid;
}


function getPortCostTypeNameBasedOnID($id)
{
	$connect = $this->funConnect();
	$sql 	 = "select NAME from port_cost_type_master where PC_TYPE_ID='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows['NAME'];
}

function getLoadPortCostSlaveData($id,$port_costid,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from loadport_cost_slave where LP_COST_ID='".$id."' and PC_TYPE_ID='".$port_costid."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function nominateAgent()
{
	$connect = $this->funConnect();
	$comid               	= $_REQUEST['comid'];
	$tabid		          	= $_REQUEST['txttabid'][0];
	$port		          	= $_REQUEST['txtport_'.$tabid];
	$portid		          	= $_REQUEST['txtportid_'.$tabid];
	$txtRandomID         	= $_REQUEST['txtRandomID_'.$tabid];
	$txtsubmitid         	= $_REQUEST['txtsubmitid_'.$tabid];
	$rowcount1	            = addslashes(trim($_REQUEST['rowcount1'.$tabid]));
	$txtOperatorRemarks     = addslashes(trim($_REQUEST['txtOperatorRemarks_'.$tabid]));
	$txtERate               = addslashes(trim($_REQUEST['txtERate_'.$tabid]));
	$rdoExchange            = addslashes(trim($_REQUEST['rdoExchange_'.$tabid]));
	$txtttlActualCost       = addslashes(trim($_REQUEST['txtttlActualCost_'.$tabid]));
	$txtttlActualCostUSD    = addslashes(trim($_REQUEST['txtttlActualCostUSD_'.$tabid]));
	$selLocalCurrency       = addslashes(trim($_REQUEST['selLocalCurrency_'.$tabid]));
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE_'.$tabid]));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME_'.$tabid]));
	//echo $tabid;
	//echo $_FILES['attach_file_'+$tabid];die;
	$upload = $this->getUpload($_FILES['attach_file_'.$tabid]);
	$name = $this->getUploadName($_FILES['attach_file_'.$tabid]);
	//print_r($upload);die;
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}	

    $selApprovers             = $_REQUEST['selApprovers_'.$tabid];
	$loadportcostid = '';$creatorloginid = '';
	$voyageno = $this->getCompareEstimateData($comid,"VOYAGE_NO");

	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "select * from loadport_cost_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$txtRandomID."'";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	if($rec==0)
	{
	    $sql = "insert into loadport_cost_master (EXCHANGE_RATE, TTL_ACTUAL_COST_LC, TTL_ACTUAL_COST_USD, ATTACHMENTS, ATTACHMENTS_NAME, RDO_EXCHANGE, SUBMITID, OPERATOR_REMARKS, COMID, PORTID, PORT, RANDOMID, MODULEID, MCOMPANYID, CREATOR, APPROVERS, LOCAL_CURRENCY) values ('".$this->getCheckNullValue($txtERate)."','".$this->getCheckNullValue($txtttlActualCost)."','".$this->getCheckNullValue($txtttlActualCostUSD)."','".$upload1."','".$name1."','".$this->getCheckNullValue($rdoExchange)."','".$this->getCheckNullValue($txtsubmitid)."', '".addslashes($txtOperatorRemarks)."', '".$comid."', '".$portid."', '".$port."', '".$txtRandomID."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$_SESSION['uid']."', '".implode(',',$_REQUEST['selApprovers'])."', '".$selLocalCurrency."')";
	    
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(LP_COST_ID) as max from loadport_cost_master";
		$myres = mysql_query($mysql);
		$myrows = mysql_fetch_assoc($myres);
		$max = $myrows['max'];
		
		$loadportcostid = $max;
		$creatorloginid = $_SESSION['uid'];
		
		for($i=1;$i<=$rowcount1;$i++)
		{		
			$sql2 = "insert into loadport_cost_slave (LP_COST_ID, PORT_COST_DESC, ACTUAL_COST_LC, ACTUAL_COST_USD, REMARKS_OPERATOR) values ('".$max."','".$this->getCheckNullValue($_REQUEST['txtPortCostDesc_'.$tabid.'_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtActualCost_'.$tabid.'_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtActualCostUSD_'.$tabid.'_'.$i])."', '".addslashes(trim($_REQUEST['txtRemarksOperator_'.$tabid.'_'.$i]))."')";
			mysql_query($sql2);
			mysql_query("commit");
		}
	}
	else
	{
	    $rows = mysql_fetch_assoc($res);
		
		$loadportcostid = $rows['LP_COST_ID'];
		if($txtsubmitid ==0 || $txtsubmitid ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers_'.$tabid]);
		}else
		{
		    $approversel = $rows['APPROVERS'];
		}
		$creatorloginid = $rows['CREATOR'];
		
	    $sql = "update loadport_cost_master set EXCHANGE_RATE='".$this->getCheckNullValue($txtERate)."', TTL_ACTUAL_COST_LC='".$this->getCheckNullValue($txtttlActualCost)."', TTL_ACTUAL_COST_USD='".$this->getCheckNullValue($txtttlActualCostUSD)."', ATTACHMENTS='".$upload1."', ATTACHMENTS_NAME='".$name1."', RDO_EXCHANGE='".$this->getCheckNullValue($rdoExchange)."', SUBMITID='".$this->getCheckNullValue($txtsubmitid)."', OPERATOR_REMARKS='".addslashes($txtOperatorRemarks)."', APPROVERS='".$approversel."', LOCAL_CURRENCY='".$selLocalCurrency."' where LP_COST_ID=".$rows['LP_COST_ID'];
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sqldel = "delete from loadport_cost_slave where LP_COST_ID=".$rows['LP_COST_ID'];
		mysql_query($sqldel) or die($sqldel);
		mysql_query("commit");
		
		for($i=1;$i<=$rowcount1;$i++)
		{		
			$sql2 = "insert into loadport_cost_slave (LP_COST_ID, PORT_COST_DESC, ACTUAL_COST_LC, ACTUAL_COST_USD, REMARKS_OPERATOR) values ('".$rows['LP_COST_ID']."','".$this->getCheckNullValue($_REQUEST['txtPortCostDesc_'.$tabid.'_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtActualCost_'.$tabid.'_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtActualCostUSD_'.$tabid.'_'.$i])."', '".addslashes(trim($_REQUEST['txtRemarksOperator_'.$tabid.'_'.$i]))."')";
			mysql_query($sql2);
			mysql_query("commit");
		}
	}
	
	
	$this->inactiveUserAlerts('FDA', $_SESSION['uid'], $loadportcostid);
	
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers_'.$tabid];
	$approverarr2 = $this->getUsersWithAuthority('FDA_CHK_APP_2');
	
	$url = './nominate_agent.php?comid='.$_REQUEST['comid'].'&page='.$_REQUEST['page'].'&tab='.($_REQUEST['txttabid'][0]-1);
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'FDA';
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($_REQUEST['comid'],"VESSEL_IMO_ID"),"VESSEL_NAME");
	if($loadportcostid != '' && $txtsubmitid >= 1)
	{
	    $userarray = array();
	    if($txtsubmitid == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent FDA of Port ('.$port.' - '.$this->getPortNameBasedOnID($portid).') of Voyage No. ('.$vesselname.' - '.$voyageno.') for Level 1 Approval', $loadportcostid);				  
				  }
			 }
		}
		
		if($txtsubmitid == 2)
		{  
		     $userarray = $creatorsarr;
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent FDA of Port ('.$port.' - '.$this->getPortNameBasedOnID($portid).') of Voyage No. ('.$vesselname.' - '.$voyageno.') for Review', $loadportcostid);				  
				  }
			 }
		}
		
		if($txtsubmitid == 4)
		{  
		     $userarray = $approverarr1;
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent FDA of Port ('.$port.' - '.$this->getPortNameBasedOnID($portid).') of Voyage No. ('.$vesselname.' - '.$voyageno.') for Review', $loadportcostid);				  
				  }
			 }
		}
		
		if($txtsubmitid == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent FDA of Port ('.$port.' - '.$this->getPortNameBasedOnID($portid).') of Voyage No. ('.$vesselname.' - '.$voyageno.') for Level 2 Approval', $loadportcostid);				  
				  }
			 }
		}
	}
	
	return $msg; 
}

function getAgencyLetterData($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from generate_agency_letter where GEN_AGENCY_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getPDAPortCostsBasedOnCountryID($countryid,$genagencyid)
{
	$connect = $this->funConnect();
	$arr = array();
	echo '<div class="box-body table-responsive">';
	echo '<table cellpadding="1" cellspacing="1" border="0" width="100%" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th width="25%" align="left" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Port Cost Type</th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Estmd Cost <span style="font-size:10px; font-style:italic;">(LC)</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Estmd Cost <span style="font-size:10px; font-style:italic;">(USD)</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Actual Cost <span style="font-size:10px; font-style:italic;">(LC)</span></th>';
	echo '<th width="10%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Actual Cost <span style="font-size:10px; font-style:italic;">(USD)</span></th>';
	echo '<th width="13%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Remarks <span style="font-size:10px; font-style:italic;">(Operator)</span></th>';
	echo '<th width="13%" align="center" valign="top" style="background-color:#3c8dbc;color:#fff;font-size:12px;">Remarks <span style="font-size:10px; font-style:italic;">(Agent)</span></th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	$sql = "select * from port_cost_type_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' order by NAME";
	$res = mysql_query($sql);
	$i = 1;
	while($rows = mysql_fetch_assoc($res))
	{
		if(!is_null($rows['COUNTRY_IDS']) && $rows['COUNTRY_IDS'] != "")
		{
			$c_arr = explode(",",$rows['COUNTRY_IDS']);
			if(in_array($countryid,$c_arr))
			{
				$lp_costid = $this->getLoadPortCostData($genagencyid,"LP_COST_ID");
				echo '<tr>';
				echo '<td align="left">'.$rows['NAME'].'<input type="hidden" name="txtPortCostID_'.$i.'" id="txtPortCostID_'.$i.'" size="1" readonly="true" value="'.$rows['PC_TYPE_ID'].'" /></td>';
				
				echo '<td align="center"><input type="text" name="txtEstmdCost_'.$i.'" id="txtEstmdCost_'.$i.'" class="form-control" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ESTMD_COST_LC").'" onkeyup="calculateEstmdCostUSD1('.$i.');"/></td>';
				
				echo '<td align="center"><input type="text" name="txtEstmdCostUSD_'.$i.'" id="txtEstmdCostUSD_'.$i.'" class="form-control" readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ESTMD_COST_USD").'" onkeyup="calculateEstmdCostUSD1('.$i.');"/></td>';
				
				echo '<td align="center"><input type="text" name="txtActualCost_'.$i.'" id="txtActualCost_'.$i.'" class="form-control"  value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ACTUAL_COST_LC").'" onkeyup="calculateEstmdCostUSD('.$i.');"  /></td>';	
				
				echo '<td align="center"><input type="text" name="txtActualCostUSD_'.$i.'" id="txtActualCostUSD_'.$i.'" class="form-control" readonly="true" value="'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"ACTUAL_COST_USD").'" onkeyup="calculateEstmdCostUSD('.$i.');"/></td>';
				
				echo '<td align="center"><textarea class="form-control areasize" name="txtRemarksOperator_'.$i.'" id="txtRemarksOperator_'.$i.'">'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"REMARKS_OPERATOR").'</textarea></td>';
				
				echo '<td align="center"><textarea class="form-control areasize" name="txtRemarksAgent_'.$i.'" id="txtRemarksAgent_'.$i.'" readonly="true">'.$this->getLoadPortCostSlaveData($lp_costid,$rows['PC_TYPE_ID'],"REMARKS_AGENTS").'</textarea></td>';
				echo '</tr>';
				$i++;
			}
		}
	}
	echo '</tbody>';
	echo '<tfoot>';
	echo '<tr>';
	echo '<th align="left" width="14%" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" >TOTAL<input type="hidden" name="txtRec" id="txtRec" value="'.($i-1).'"/></th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlEstmdCost" id="txtttlEstmdCost" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($genagencyid,"TTL_ESTMD_COST_LC").'" placeholder="0.00" /></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlEstmdCostUSD" id="txtttlEstmdCostUSD" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($genagencyid,"TTL_ESTMD_COST_USD").'" placeholder="0.00" /></th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlActualCost" id="txtttlActualCost" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($genagencyid,"TTL_ACTUAL_COST_LC").'" placeholder="0.00"/></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"><input type="text" name="txtttlActualCostUSD" id="txtttlActualCostUSD" class="form-control" readonly="true" value="'.$this->getLoadPortCostData($genagencyid,"TTL_ACTUAL_COST_USD").'" placeholder="0.00"/></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<th align="right" width="14%" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" colspan="3">Advance Requested 1&nbsp;&nbsp;</th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;">';
	echo '<input type="text" name="txtAdvRequestedCost1" id="txtAdvRequestedCost1" class="form-control" value="'.$this->getLoadPortCostData($genagencyid,"ADV_REQUESTED_1").'" placeholder="0.00" />';
	echo '</th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<th align="right" width="14%" valign="middle" style="background-color:#3c8dbc;font-size:12px; color:#fff;" colspan="3">Advance Requested 2&nbsp;&nbsp;</th>';
	echo '<th align="center" width="8%" valign="middle" style="background-color:#3c8dbc;font-size:10px;">';
	echo '<input type="text" name="txtAdvRequestedCost2" id="txtAdvRequestedCost2" class="form-control" value="'.$this->getLoadPortCostData($genagencyid,"ADV_REQUESTED_2").'" placeholder="0.00" />';
	echo '</th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="13%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '<th align="center" width="11%" valign="middle" style="background-color:#3c8dbc;font-size:10px;"></th>';
	echo '</tr>';
	
	echo '</tfoot>';
	echo '</table>';
	echo '</div>';
}

function insertLoadPortCostDetails()
{
	$connect = $this->funConnect();
	$comid              				= $_REQUEST['comid'];
	$gen_agency_id          			= $_REQUEST['gen_agency_id'];
	$ttl_actual_cost                	= addslashes(trim($_REQUEST['txtttlActualCost']));
	$ttl_actual_cost_usd            	= addslashes(trim($_REQUEST['txtttlActualCostUSD']));
	$txtOperatorRemarks              	= addslashes(trim($_REQUEST['txtOperatorRemarks']));
	$txtSubmitid        		  		= $_REQUEST['txtSubmitid'];
	$upstatus 			                = addslashes(trim($_REQUEST['upstatus']));
	
	$upstatus 			          = addslashes(trim($_REQUEST['upstatus']));
	$date			   	     	  = date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$preparedby			          = addslashes(trim($_REQUEST['txtPreparedBy']));
	$bank_details	              = addslashes(trim($_REQUEST['txtBDetails']));
	$authorizedby	              = addslashes(trim($_REQUEST['txtAuthorizedBy']));
	
	
	$ttl_estmd_cost                = addslashes(trim($_REQUEST['txtttlEstmdCost']));
	$ttl_estmd_cost_usd	           = addslashes(trim($_REQUEST['txtttlEstmdCostUSD']));
	$ttl_actual_cost               = addslashes(trim($_REQUEST['txtttlActualCost']));
	$ttl_actual_cost_usd           = addslashes(trim($_REQUEST['txtttlActualCostUSD']));
	
	$adv_req1		               = addslashes(trim($_REQUEST['txtAdvRequestedCost1']));
	$adv_req2			           = addslashes(trim($_REQUEST['txtAdvRequestedCost2']));
	$e_rate	   			           = addslashes(trim($_REQUEST['txtERate']));
	
	$rdoExchange	               = addslashes(trim($_REQUEST['rdoExchange']));
	$txtAgentRemarks               = addslashes(trim($_REQUEST['txtAgentRemarks']));
	

	$rec = $_REQUEST['txtRec'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$query = "select * from loadport_cost_master where GEN_AGENCY_ID='".$gen_agency_id."'"; 
	$qres = mysql_query($query);
	$qrec = mysql_num_rows($qres);
	if($qrec == 1)
	{
		$qrows = mysql_fetch_assoc($qres);
		$max = $qrows['LP_COST_ID'];
		
		$sql = "update loadport_cost_master set DATE='".$date."', FINAL_EXCHANGE_RATE='".$this->getCheckNullValue($e_rate)."', TTL_ESTMD_COST_LC='".$this->getCheckNullValue($ttl_estmd_cost)."', TTL_ESTMD_COST_USD='".$this->getCheckNullValue($ttl_estmd_cost_usd)."', TTL_ACTUAL_COST_LC='".$this->getCheckNullValue($ttl_actual_cost)."', TTL_ACTUAL_COST_USD='".$this->getCheckNullValue($ttl_actual_cost_usd)."', ADV_REQUESTED_1='".$this->getCheckNullValue($adv_req1)."', ADV_REQUESTED_2='".$this->getCheckNullValue($adv_req2)."', BANK_DETAILS='".$bank_details."', PREPARED_BY='".$preparedby."', AUTHORIZED_BY='".$authorizedby."',  ATTACHMENTS='".$upload1."', ATTACHMENTS_NAME='".addslashes($name2)."', RDO_EXCHANGE='".$rdoExchange."', AGENT_REMARKS='".$txtAgentRemarks."', STATUS='".$upstatus."', SUBMITID='".$txtSubmitid."', OPERATOR_REMARKS='".$txtOperatorRemarks."' where GEN_AGENCY_ID='".$gen_agency_id."' and LP_COST_ID='".$qrows['LP_COST_ID']."'"; 
		//echo $sql;die;
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$delquery = "delete from loadport_cost_slave where LP_COST_ID='".$max."'";
		mysql_query($delquery);
		mysql_query("commit");		
		
		for($i=1;$i<=$rec;$i++)
		{		
			$sql2 = "insert into loadport_cost_slave (LP_COST_ID, PC_TYPE_ID, ESTMD_COST_LC, ESTMD_COST_USD ,ACTUAL_COST_LC, ACTUAL_COST_USD, REMARKS_OPERATOR, REMARKS_AGENTS) values ('".$max."','".$_REQUEST['txtPortCostID_'.$i]."','".$_REQUEST['txtEstmdCost_'.$i]."','".$_REQUEST['txtEstmdCostUSD_'.$i]."','".$_REQUEST['txtActualCost_'.$i]."','".$_REQUEST['txtActualCostUSD_'.$i]."','".addslashes(trim($_REQUEST['txtRemarksOperator_'.$i]))."','".addslashes(trim($_REQUEST['txtRemarksAgent_'.$i]))."')";
			mysql_query($sql2);
			mysql_query("commit");
		}
	}
	else
	{
		$sql = "insert into loadport_cost_master (GEN_AGENCY_ID,DATE,EXCHANGE_RATE,TTL_ESTMD_COST_LC,TTL_ESTMD_COST_USD,TTL_ACTUAL_COST_LC,TTL_ACTUAL_COST_USD,ADV_REQUESTED_1,ADV_REQUESTED_2,BANK_DETAILS,PREPARED_BY,AUTHORIZED_BY, ATTACHMENTS, ATTACHMENTS_NAME, RDO_EXCHANGE, AGENT_REMARKS, STATUS, SUBMITID, OPERATOR_REMARKS) values ('".$gen_agency_id."','".$date."','".$this->getCheckNullValue($e_rate)."','".$this->getCheckNullValue($ttl_estmd_cost)."','".$this->getCheckNullValue($ttl_estmd_cost_usd)."','".$this->getCheckNullValue($ttl_actual_cost)."','".$this->getCheckNullValue($ttl_actual_cost_usd)."','".$this->getCheckNullValue($adv_req1)."','".$this->getCheckNullValue($adv_req2)."','".$bank_details."','".$preparedby."','".$authorizedby."', '".$upload1."', '".addslashes($name2)."', '".$rdoExchange."', '".$txtAgentRemarks."', '".$upstatus."','".$txtSubmitid."', '".addslashes($txtOperatorRemarks)."')";
			
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(LP_COST_ID) as max from loadport_cost_master";
		$myres = mysql_query($mysql);
		$myrows = mysql_fetch_assoc($myres);
		$max = $myrows['max'];
		
		for($i=1;$i<=$rec;$i++)
		{		
			$sql2 = "insert into loadport_cost_slave (LP_COST_ID, PC_TYPE_ID, ESTMD_COST_LC, ESTMD_COST_USD ,ACTUAL_COST_LC, ACTUAL_COST_USD, REMARKS_OPERATOR, REMARKS_AGENTS) values ('".$max."','".$this->getCheckNullValue($_REQUEST['txtPortCostID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstmdCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstmdCostUSD_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtActualCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtActualCostUSD_'.$i])."','".addslashes(trim($_REQUEST['txtRemarksOperator_'.$i]))."','".addslashes(trim($_REQUEST['txtRemarksAgent_'.$i]))."')";
			mysql_query($sql2);
			mysql_query("commit");
		}
	}
return $msg;
}

function getVendorCodeListNew()
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from vendor_master where STATUS=1 and MCOMPANYID='".$_SESSION['company']."' order by NAME ");
	
	echo '<option value = "" >---Select from list---</option>';
	@$selVendor = @$_REQUEST['selVendor'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CODE'];
		 $value=  addslashes($rows['NAME']).'('.$rows['CODE'].')';
		 echo '<option value="'.$key.'"';
		 if($key == @$selVendor){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}

function getDaysSection(){
	
	$connect 		= $this->funConnect();
	$arr 			= array("1"=>"All","2"=>"less than 30 days","3"=>"31-60 days","4"=>"61-90 days","5"=>"above 90 days");	
	@$selDate_Type  = @$_REQUEST['selDate_Type'];
	while (list($key, $val) = each($arr)) 
	{
		echo '<option value='.$key;
		 if($key == @$selDate_Type){ echo ' selected';}
		 echo '>'.$val.'</option>';
	
	}
}


function getNoticeDays($id=''){
	
	$connect 		= $this->funConnect();
	$arr 			= array("0"=>"0", "1"=>"1","2"=>"2","3"=>"3","4"=>"4","5"=>"5","6"=>"6","7"=>"7","8"=>"8","9"=>"9","10"=>"10","11"=>"11","12"=>"12","13"=>"13","14"=>"14","15"=>"15","16"=>"16","17"=>"17","18"=>"18","19"=>"19","20"=>"20","21"=>"21","22"=>"22","23"=>"23","24"=>"24","25"=>"25","26"=>"26","27"=>"27","28"=>"28","29"=>"29","30"=>"30","31"=>"31");	
	echo '<option value = "" >---Select from list---</option>';
	while (list($key, $val) = each($arr)) 
	{
		echo '<option value='.$key;
		 if($key == @$id){ echo ' selected';}
		 echo '>'.$val.'</option>';
	
	}
}

function getVendorListForCustomer()
{
	$this->funConnect();
	$query = mysql_query("select * from vendor_master where STATUS=1 and VENDOR_TYPEID=18 and MCOMPANYID='".$_SESSION['company']."' order by NAME ");
	echo '<option value = "" >---Select from list---</option>';
	@$selVendor = @$_REQUEST['selVendor'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['CODE'];
		 $value= addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
		 echo '<option value="'.$key.'"';
		 if($key == @$selVendor){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}

function getAmountType(){
	
	$connect 		= $this->funConnect();
	$arr 			= array("1"=>"Amount Based","2"=>"Freight Based");	
	echo '<option value= "" >---Select from list---</option>';
	@$selAmt_Type  = @$_REQUEST['selAmt_Type'];
	while (list($key, $val) = each($arr)) 
	{
		echo '<option value='.$key;
		 if($key == @$selAmt_Type){ echo ' selected';}
		 echo '>'.$val.'</option>';
	
	}
	
}


function getDateType(){
	
	$connect 		= $this->funConnect();
	$arr 			= array("1"=>"ETA Date Based","2"=>"ETCD Date Based");	
	echo '<option value= "" >---Select from list---</option>';
	@$selDate_Type  = @$_REQUEST['selDate_Type'];
	while (list($key, $val) = each($arr)) 
	{
		echo '<option value='.$key;
		 if($key == @$selDate_Type){ echo ' selected';}
		 echo '>'.$val.'</option>';
	
	}
	
}

function getMaterialTypeForShipment()
{
	$this->funConnect();
	$query = mysql_query("select MATERIAL_TYPE from cargo_master where STATUS=1 group by MATERIAL_TYPE order by MATERIAL_TYPE ");
	echo '<option value = "" >---Select from list---</option>';
	echo '<option value = "All" >All</option>';
	@$selMType = @$_REQUEST['selMType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['MATERIAL_TYPE'];
		 $value= $rows['MATERIAL_TYPE'];
		 echo '<option value='.$key;
		 if($key == @$selMType){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}


function getShipmentDateType(){
	
	$connect 		= $this->funConnect();
	$arr 			= array("1"=>"BL Date Based","2"=>"Financial Year Date Based");	
	echo '<option value= "" >---Select from list---</option>';
	@$selDate_Type  = @$_REQUEST['selDate_Type'];
	while (list($key, $val) = each($arr)) 
	{
		echo '<option value='.$key;
		 if($key == @$selDate_Type){ echo ' selected';}
		 echo '>'.$val.'</option>';
	
	}
	
}

function getSOFdata($comid,$port,$portid,$randomid,$field)
{
	$connect 				= $this->funConnect();	
	$sql = "select ".$field." from sof_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$randomid."' ";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		$sql1 = "select ".$field." from sof_master where COMID='".$comid."' and LOGIN='AGENT' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."'  and RANDOMID='".$randomid."' ";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		return $rows1[$field];
	}
	else
	{
		$rows = mysql_fetch_assoc($res);
		return $rows[$field];
	}
}


function getInvoiceType()
{
	$state = array('Interim'=>'Interim', 'Final'=>'Final', 'Memo'=>'Memo', 'Debit Note'=>'Debit Note', 'Credit Note'=>'Credit Note', 'Adjustment'=>'Adjustment', 'PFHS'=>'PFHS', 'FHS2'=>'FHS - 2');
	$selIType = @$_REQUEST['selIType'];
	echo '<option value="">---Select from list---</option>';
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selIType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getInvoiceTypeForInterimFinal($invtype)
{
    if($invtype == 'Interim')
	{
		$state = array('Interim'=>'Interim', 'Memo'=>'Memo', 'Debit Note'=>'Debit Note', 'Credit Note'=>'Credit Note', 'Adjustment'=>'Adjustment');
	}else
	{
		$state = array('Final'=>'Final', 'Memo'=>'Memo', 'Debit Note'=>'Debit Note', 'Credit Note'=>'Credit Note', 'Adjustment'=>'Adjustment');
	}
	$selIType = @$_REQUEST['selIType'];
	echo '<option value="">---Select from list---</option>';
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selIType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getMessageNumberForInvoice($vessel)
{
  $this->funConnect();
	
	$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM invoice_master where 1=1 ";
	echo $query;die;
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['MESSAGE_NO'];
	if($rows['MESSAGE_NO'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode =strtoupper($vessel).'/INV/'.$empcode.'/'.date("Y",time());//INNER if ends here.
		}//if ends here.
	else
		{
			$empcode= strtoupper($vessel).'/INV/001/2014';
		}
	}//WHILE ends here.BW/DM/001/2014
	
return $empcode;
}

function getBankingDetailsDataWithJson()
{
	$connect = $this->funconnect();	
	$query   = mysql_query("select * from banking_details where STATUS=1 and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' order by NAME");
	while($row = mysql_fetch_assoc($query))
	{
	    $id = $row['BD_ID'];
		$a[$id][] = array(addslashes($row['ADDRESS']),addslashes($row['AC_NO']),addslashes($row['BANK']),addslashes($row['B_ADDRESS']),$row['BANK_SWIFT_CODE'],$row['IBAN_NO'],$row['FED_ABA'],$row['C_BANK_NAME'],$row['C_SWIFT_CODE'],$row['REFERENCE'],$row['CORRES_ADDRESS']);
	}
	header('Content-type:application/json;');
	echo json_encode(utf8_encode($a),true);
}

function getBankingDetailsDataWithJson_1($id)
{
	$connect 	= $this->funconnect();	
	$query 		= mysql_query("select * from banking_details_slave where STATUS='".$id."'");
	while($row 	= mysql_fetch_assoc($query))
	{
	    $id = $row['BD_ID'];
		$a[$id][] = array('name' => $row['NAME'], 'value' => $row['VALUE']);
	}
	echo json_encode(utf8_encode($a));
}


function getBankingDetailsDataWithJsonVendor($id, $slaveid)
{
	$connect 	= $this->funconnect();	
	$query 		= mysql_query("select vendor_master_slave.RANDOMID, vendor_master_slave.SLAVEID, vendor_master_slave.NAME, vendor_master_slave.ADDRESS, vendor_master_slave.ACCOUNTNO, vendor_master_slave.IBAN_NO, vendor_master_slave.IBAN_REMARKS, vendor_master_slave.BANK_NAME, vendor_master_slave.BANK_ADDRESS, vendor_master_slave.SWIFT_CODE, vendor_master_slave.US_CORRES_BANK from vendor_master_slave inner join vendor_master on vendor_master.VENDORID=vendor_master_slave.VENDORID where vendor_master.CODE='".$id."'");
	echo '<option value = "" >---Select from list---</option>';
	while($rows = mysql_fetch_assoc($query))
	{
	     $key= $rows['RANDOMID'];
		 $value= $rows['NAME'].' - '.$rows['ACCOUNTNO'].' - '.$rows['IBAN_NO'];
		 echo '<option value='.$key;
		 if($key == @$slaveid){ echo ' selected';}
		 echo '>'.$value.'</option>';
	}
}

function getInvoiceDetailsDataWithJson()
{
	$connect   = $this->funconnect();	
	$query     = mysql_query("select * from invoice_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'");
	while($row = mysql_fetch_assoc($query))
	{
	    $id = $row['IM_ID'];
		$a[$id][] = array('customer' => $row['CUSTOMER'], 'date' =>  date("d-m-Y",strtotime($row['DATE'])), 'debit_note' => $row['DEBIT_NOTE'], 'i_type' => $row['I_TYPE'], 'payment_no' => $row['PAYMENT_NO'], 'p_type' => $row['P_TYPE'], 'qty_1' => $row['QTY_1'], 'freight_1' => $row['FREIGHT_1'], 'amt_1' => $row['AMOUNT_1'], 'qty_2' => $row['QTY_2'], 'freight_2' => $row['FREIGHT_2'], 'amt_2' => $row['AMOUNT_2'], 'qty_3' => $row['QTY_3'], 'freight_3' => $row['FREIGHT_3'], 'amt_3' => $row['AMOUNT_3'], 'qty_4' => $row['QTY_4'], 'freight_4' => $row['FREIGHT_4'], 'amt_4' => $row['AMOUNT_4'], 'ttl_amt' => $row['TTL_AMOUNT'], 'to_percent' => $row['TO_PERCENT'], 'to_amt' => $row['TO_AMOUNT'], 'dedu_percent' => $row['DEDU_PERCENT'], 'dedu_amt' => $row['DEDU_AMOUNT'], 'net_amt' => $row['NET_AMOUNT'], 'net_amt_name' => $row['NET_AMT_NAME'], 'nob' => $row['NOB'], 'p_remarks' => $row['P_REMARKS'], 'p_amt' => $row['P_AMT'], 'p_date' => date("d-m-Y",strtotime($row['P_DATE'])));
	}
	echo json_encode($a);
}

function getBankingDetails()
{
	$this->funConnect();
	$query = mysql_query("select * from banking_details where STATUS=1 order by NAME");
	echo '<option value = "" >---Select from list---</option>';
	@$selNOB = @$_REQUEST['selNOB'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['BD_ID'];
		 $value= $rows['NAME'].' - '.$rows['BANK'];
		 echo '<option value='.$key;
		 if($key == @$selNOB){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}

function insertInvoiceDetails()
{
	$connect 			= $this->funConnect();	
	$mappingid 			= addslashes(trim($_REQUEST['mappingid']));
	
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtDNote	 		= addslashes(trim($_REQUEST['txtDNote']));
	
	$txtDNote_1	 		= explode("/",$_REQUEST['txtDNote']);
	
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtNameid	 		= addslashes(trim($_REQUEST['txtNameid']));
	$txtGradeid	 		= addslashes(trim($_REQUEST['txtGradeid']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtFCAID	 		= addslashes(trim($_REQUEST['txtFCAID']));
	$txtTotal	 		= addslashes(trim($_REQUEST['txtTotal']));
	$txtTO	 			= addslashes(trim($_REQUEST['txtTO']));
	$txtNet	 			= addslashes(trim($_REQUEST['txtNet']));
	$txtNet_Name	 	= addslashes(trim($_REQUEST['txtNet_Name']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	$selNOB	 			= addslashes(trim($_REQUEST['selNOB']));
	$txtHTtl	 		= addslashes(trim($_REQUEST['txtHTtl']));
	$txtAddComm	 		= addslashes(trim($_REQUEST['txtAddComm']));
	$txtQty             = $_REQUEST['txtQty'];
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$qsql = "select * from invoice_master where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and MESSAGE = '".$txtDNote."'";
	$qres = mysql_query($qsql);
	$qrec = mysql_num_rows($qres);
	if($qrec == 0)
	{
		//insert query here.............
		$sql = "insert into invoice_master (MAPPINGID, MODULEID, MCOMPANYID, I_TYPE, MESSAGE, MESSAGE_NO, VENDOR, NAMEID, GRADEID, DATE, CPDATE, FCAID, TOTAL, TO_1, NET, NETNAME, NOB, REMARKS, STATUS, COST, ADDCOMM, QUANTITY) values ('".$mappingid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$selIType."', '".$txtDNote."', '".$txtDNote_1[2]."', '".$txtVendor."', '".$txtNameid."', '".$txtGradeid."', '".$txtDate."', '".$txtCP_Date."', '".$txtFCAID."', '".$txtTotal."', '".$txtTO."', '".$txtNet."', '".$txtNet_Name."', '".$selNOB."', '".$txtRemarks."', '".$txtStatus."', '".$this->getCheckNullVal($txtHTtl)."', '".$this->getCheckNullVal($txtAddComm)."', '".$txtQty."')";
		mysql_query($sql);
		mysql_query("commit");
		//$qrows['IM_ID']
		
		$sql1 = "select max(IM_ID) as max from invoice_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into invoice_slave (IM_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into invoice_slave (IM_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
	}
	else
	{
		$qrows = mysql_fetch_assoc($qres);
		$sql = "update invoice_master set I_TYPE='".$selIType."', DATE='".$txtDate."', TO_1='".$txtTO."', NET='".$txtNet."', NETNAME='".$txtNet_Name."', NOB='".$selNOB."', REMARKS='".$txtRemarks."', STATUS='".$txtStatus."' where IM_ID='".$qrows['IM_ID']."'";
		mysql_query($sql);
		mysql_query("commit");
		
		$sql_del = "delete from invoice_slave where IM_ID='".$qrows['IM_ID']."'";
		mysql_query($sql_del);
		mysql_query("commit");
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if(isset($_REQUEST['txtAddDes_'.$i]))
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into invoice_slave (IM_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['IM_ID']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if(isset($_REQUEST['txtSubDes_'.$i]))
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into invoice_slave (IM_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['IM_ID']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
				mysql_query($sql2);
			}
		}
	}
	
	mysql_query("commit");
	return $msg.','.$mappingid;  
}


function insertPaymentReceivedDetails()
{
	//echo '<pre>';print_r($_POST);die();
	$connect = $this->funConnect();
	$id					= addslashes(trim($_REQUEST['mappingid']));
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update invoice_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."' where IM_ID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	return $msg.'_'.$id; 
}

function deleteInvoiceRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txtDEL_ID']));
	$mappingid 			= addslashes(trim($_REQUEST['mappingid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	$sql = "delete from invoice_master where IM_ID='".$id."'";
	mysql_query($sql);
	
	$sql1 = "delete invoice_slave where IM_ID='".$id."'";
	mysql_query($sql1);
	
	mysql_query("commit"); 
	return $msg.','.$mappingid;
}


function openLaytimeRecords()
{
	$connect			= $this->funConnect();
 	$comid              	= $_REQUEST['comid'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	$sql = "update laytime_master set SUBMITID=0 where COMID='".$comid."'";
	mysql_query($sql);
	
	$this->saveRecentWork("Laytime for the Voyage No. (".$voyageno.") opened Successfully.");
	mysql_query("commit"); 
	return $msg;
}



function updationLaytimeRecords()
{
	$connect = $this->funConnect();
	
	//echo '<pre>';print_r($_REQUEST);  die();
	
	$comid              	= $_REQUEST['comid'];
	$tabid		          	= $_REQUEST['txttabid'][0];
	$port		          	= $_REQUEST['txtport_'.$tabid];
	$portid		          	= $_REQUEST['txtportid_'.$tabid];
	$txtSerialNo          	= $_REQUEST['txtSerialNo_'.$tabid];
	$txtsubmitid		    = $_REQUEST['txtsubmitid_'.$tabid];
	
	$selApp			        = $_REQUEST['selApp_'.$tabid];
	
	$loaded_qty	            = addslashes(trim($_REQUEST['txtLPLoadedQty_'.$tabid]));	
	$loaded_rate	        = addslashes(trim($_REQUEST['txtLPLoadedRate_'.$tabid]));
	$laytime_allowed	    = addslashes(trim($_REQUEST['txtLPLaytimeAllowed_'.$tabid]));
	$actual_laytime	    	= addslashes(trim($_REQUEST['txtLPActualLaytime_'.$tabid]));
	$actual_laytime_insert 	= addslashes(trim($_REQUEST['txtLPActualLaytimeInsert_'.$tabid]));
	$lp_time_to_demurrage	= addslashes(trim($_REQUEST['txtLPTimetodemurrage_'.$tabid]));
	$demmurage_rate	    	= addslashes(trim($_REQUEST['txtLPDRate_'.$tabid]));
	$lp_time_to_despatch	= addslashes(trim($_REQUEST['txtLPTimetodespatch_'.$tabid]));
	$despatch_rate			= addslashes(trim($_REQUEST['txtLPDespatchRate_'.$tabid]));
	$lpttl_demurrage		= addslashes(trim($_REQUEST['txtLPTTLDemurrage_'.$tabid]));
	$lpttl_despatch			= addslashes(trim($_REQUEST['txtLPTTLDespatch_'.$tabid]));
	$vendor					= addslashes(trim($_REQUEST['selVendor_'.$tabid]));
	$remarks				= addslashes(trim($_REQUEST['txtRemarks_'.$tabid]));
	
	$lp_terms				= addslashes(trim($_REQUEST['txtLPTerms_'.$tabid]));
	$lp_nor_terms			= addslashes(trim($_REQUEST['txtLPNORTerms_'.$tabid]));

	
	$sof_loadport_id        = addslashes(trim($_REQUEST['txtSofLoadPortID_'.$tabid]));
	
	$reversible				= addslashes(trim($_REQUEST['checkLPReverssible_'.$tabid]));
	
	
	$txtTerminal		    = addslashes(trim($_REQUEST['txtTerminal_'.$tabid]));
	$txtStowageQty	        = addslashes(trim($_REQUEST['txtStowageQty_'.$tabid]));
	$txtVessel_Arrived     	= addslashes(trim($_REQUEST['txtVessel_Arrived_'.$tabid]));
	$txtNor_Tendered        = addslashes(trim($_REQUEST['txtNor_Tendered_'.$tabid]));
	$txtPilot_onBoard      	= addslashes(trim($_REQUEST['txtPilot_onBoard_'.$tabid]));
	$txtDIS_LOD_Commenced   = addslashes(trim($_REQUEST['txtDIS_LOD_Commenced_'.$tabid]));
	$txtDIS_LOD_Completed   = addslashes(trim($_REQUEST['txtDIS_LOD_Completed_'.$tabid]));
	$txtVessel_Sailed       = addslashes(trim($_REQUEST['txtVessel_Sailed_'.$tabid]));
	$txtLPTurnTime          = addslashes(trim($_REQUEST['txtLPTurnTime_'.$tabid]));
	$txtLPDaysAtPort        = addslashes(trim($_REQUEST['txtLPDaysAtPort_'.$tabid]));
	
	$txtNOR_Accepted        = addslashes(trim($_REQUEST['txtNOR_Accepted_'.$tabid]));
	$txtStart_Counting      = addslashes(trim($_REQUEST['txtStart_Counting_'.$tabid]));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE_'.$tabid]));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME_'.$tabid]));
	
	$upload = $this->getUpload($_FILES['attach_file_'.$tabid]);
	$name = $this->getUploadName($_FILES['attach_file_'.$tabid]);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}	
	
	
	$txtTBID     			= $_REQUEST['txtTBID_'.$tabid];
	$txtTBODYID     	    = $_REQUEST['txtTBODYID_'.$tabid];
	
	$selApprovers             = $_REQUEST['selApprovers_'.$tabid];
	$laytimeid = '';$creatorloginid = '';
	$voyageno = $this->getCompareEstimateData($comid,"VOYAGE_NO");
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$query = "select * from laytime_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$txtSerialNo."' and SOF_LOADPORTID='".$sof_loadport_id."'";
	
	$qres = mysql_query($query) or die($query);
	$qrec = mysql_num_rows($qres);
    
	if($qrec == 0)
	{
		$sql = "insert into laytime_master (COMID,LOGIN,LOGINID,MODULEID,MCOMPANYID,PORT,PORTID,LOADED_QTY,LOADED_RATE,LAYTIME_ALLOWED,ACTUAL_LAYTIME,TIME_TO_DEMURRAGE,TIME_TO_DESPATCH,DEMURRAGE_RATE,DESPATCH_RATE,SOF_LOADPORTID,ENTITY,TTL_DEMURRAGE,TTL_DESPATCH,VENDOR, APPLICABLE_STATUS,SUBMITID, REMARKS,LOADED_TERMS,NOR_TERMS,ACTUAL_LAYTIME_INSERT,REVERSIBLE,RANDOMID, VESSEL_SAILED, LOAD_DIS_COMPLETED, LOAD_DIS_COMMENCED, PILOT_ON_BOARD, NOR_TENDERED, VESSEL_ARRIVED, STOWAGE_QTY, TERMINAL, ATTACHMENTS, ATTACHMENTS_NAME, TURN_TIME, TOTAL_DAYS_AT_PORT, NOR_ACCEPTED, START_COUNTING, APPROVERS) values ('".$comid."','INTERNAL_USER','".$_SESSION['uid']."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$port."','".$this->getCheckNullValue($portid)."','".$this->getCheckNullValue($loaded_qty)."','".$this->getCheckNullValue($loaded_rate)."','".$laytime_allowed."','".$actual_laytime."','".$lp_time_to_demurrage."','".$lp_time_to_despatch."','".$this->getCheckNullValue($demmurage_rate)."','".$this->getCheckNullValue($despatch_rate)."','".$this->getCheckNullValue($sof_loadport_id)."','SHIP_OWNER','".$this->getCheckNullValue($lpttl_demurrage)."','".$this->getCheckNullValue($lpttl_despatch)."','".$vendor."', '".$this->getCheckNullValue($selApp)."','".$this->getCheckNullValue($txtsubmitid)."','".$remarks."','".$lp_terms."','".$lp_nor_terms."','".$this->getCheckNullValue($actual_laytime_insert)."','".$this->getCheckNullValue($reversible)."','".$txtSerialNo."', '".$txtVessel_Sailed."', '".$txtDIS_LOD_Completed."', '".$txtDIS_LOD_Commenced."', '".$txtPilot_onBoard."', '".$txtNor_Tendered."', '".$txtVessel_Arrived."', '".$txtStowageQty."', '".$txtTerminal."', '".$upload1."', '".$name1."', '".$txtLPTurnTime."', '".$txtLPDaysAtPort."', '".$txtNOR_Accepted."', '".$txtStart_Counting."', '".implode(',',$_REQUEST['selApprovers'])."')"; 
	
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(LAYTIME_ID) as max from laytime_master";
		$myres = mysql_query($mysql);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
		
		$laytimeid = $maxid;
		$creatorloginid = $_SESSION['uid'];
		
		if($selApp == 1)
		{		
			for($i=1 ; $i<=$txtTBID ;$i++)
			{
				if($_REQUEST['checkLPLTNoCounts_'.$tabid.'_'.$i] == ""){$ltno_counts = 0;}else{$ltno_counts = $_REQUEST['checkLPLTNoCounts_'.$tabid.'_'.$i];}
				if($_REQUEST['checkLPLTCounts_'.$tabid.'_'.$i] == ""){$lt_counts = 0;}else{$lt_counts = $_REQUEST['checkLPLTCounts_'.$tabid.'_'.$i];}
				if($_REQUEST['txtLPLTparcel_'.$tabid.'_'.$i] == ""){$lt_partial = 0;}else{$lt_partial = $_REQUEST['txtLPLTparcel_'.$tabid.'_'.$i];}
				
				if($_REQUEST['txtActivity_'.$tabid.'_'.$i] != "")
				{	
					 $sql1 = "insert into laytime_slave (LAYTIME_ID, ACTIVITYID, SOFLOADPORTID, LT_C, LT_NC ,LT_PARTIAL, NOTES ,START_DATETIME ,FINISH_DATETIME  ,DURATION ,LT_PARTIAL_MINUTE,CUMMULATIVE_TIME) values ('".$maxid."','".$_REQUEST['txtActivity_'.$tabid.'_'.$i]."','".$this->getCheckNullValue($sof_loadport_id)."','".$this->getCheckNullValue($lt_counts)."','".$this->getCheckNullValue($ltno_counts)."', '".$this->getCheckNullValue($lt_partial)."','".addslashes($_REQUEST['txtLPNotes_'.$tabid.'_'.$i])."','".date("Y-m-d H:i",strtotime($_REQUEST['txtLPDStart_'.$tabid.'_'.$i]))."','".date("Y-m-d H:i",strtotime($_REQUEST['txtLPDEnd_'.$tabid.'_'.$i]))."' ,'".$_REQUEST['txtLPDiff1_'.$tabid.'_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPVal_'.$tabid.'_'.$i])."','".$_REQUEST['txtCummulative1_'.$tabid.'_'.$i]."')"; 
					mysql_query($sql1) or die($sql1);
					mysql_query("commit");
				}
					
			}
		}
		
		for($i=1 ; $i<=$txtTBODYID ;$i++)
		{
			if($_REQUEST['txtDeductionActivity_'.$tabid.'_'.$i] != "")
			{	
				$sql1 = "insert into laytime_slave1 (LAYTIME_ID, ACTIVITYID, LT_PARTIAL, NOTES ,START_DATETIME ,FINISH_DATETIME, DURATION, CUMMULATIVE_TIME) values ('".$maxid."', '".$_REQUEST['txtDeductionActivity_'.$tabid.'_'.$i]."', '".$this->getCheckNullValue($_REQUEST['txtLPLDeductionTparcent_'.$tabid.'_'.$i])."', '".addslashes($_REQUEST['txtLPDeductionNotes_'.$tabid.'_'.$i])."','".date("Y-m-d H:i",strtotime($_REQUEST['txtLPDDeductionStart_'.$tabid.'_'.$i]))."', '".date("Y-m-d H:i",strtotime($_REQUEST['txtLPDDeductionEnd_'.$tabid.'_'.$i]))."', '".$_REQUEST['txtLPDeductionDiff_'.$tabid.'_'.$i]."', '".$_REQUEST['txtLPDeductionDiff1_'.$tabid.'_'.$i]."')"; 
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}	
		}
		
		$txtCID     	    = $_REQUEST['txtCID_'.$tabid];
		for($i=1; $i<=$txtCID; $i++)
		{
			if($_REQUEST['txtAV_Name_'.$tabid.'_'.$i] != "" && $_REQUEST['txtAV_Value_'.$tabid.'_'.$i] != "")
			{
				$sql3 = "insert into laytime_slave2 (LAYTIME_ID, ENTITY_NAME, ENTITY_VALUE) values ('".$maxid."', '".addslashes(trim($_REQUEST['txtAV_Name_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtAV_Value_'.$tabid.'_'.$i]))."')";
				mysql_query($sql3);
				mysql_query("commit");
			}
		}
		
		$this->saveRecentWork("Laytime of Port (".$port." - ".$this->getPortNameBasedOnID($portid).") of Voyage No. (".$voyageno.") Created Successfully.");
	}
	else
	{ 
		$qrows = mysql_fetch_assoc($qres);
		$laytimeid = $qrows['LAYTIME_ID'];
		if($txtsubmitid ==0 || $txtsubmitid ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers_'.$tabid]);
		}else
		{
		    $approversel = $qrows['APPROVERS'];
		}
		$creatorloginid = $qrows['LOGINID'];
		
		$sql = "update laytime_master set LOADED_QTY='".$this->getCheckNullValue($loaded_qty)."',LOADED_RATE='".$this->getCheckNullValue($loaded_rate)."',LAYTIME_ALLOWED='".$laytime_allowed."',ACTUAL_LAYTIME='".$actual_laytime."',TIME_TO_DEMURRAGE='".$lp_time_to_demurrage."',TIME_TO_DESPATCH='".$lp_time_to_despatch."',DEMURRAGE_RATE='".$this->getCheckNullValue($demmurage_rate)."',DESPATCH_RATE='".$this->getCheckNullValue($despatch_rate)."',TTL_DEMURRAGE='".$this->getCheckNullValue($lpttl_demurrage)."',TTL_DESPATCH='".$this->getCheckNullValue($lpttl_despatch)."',VENDOR='".$vendor."', APPLICABLE_STATUS='".$this->getCheckNullValue($selApp)."',SUBMITID='".$this->getCheckNullValue($txtsubmitid)."',REMARKS='".$remarks."',LOADED_TERMS='".$lp_terms."',NOR_TERMS='".$lp_nor_terms."',ACTUAL_LAYTIME_INSERT='".$this->getCheckNullValue($actual_laytime_insert)."',REVERSIBLE='".$this->getCheckNullValue($reversible)."', VESSEL_SAILED='".$txtVessel_Sailed."', LOAD_DIS_COMPLETED='".$txtDIS_LOD_Completed."', LOAD_DIS_COMMENCED='".$txtDIS_LOD_Commenced."', PILOT_ON_BOARD='".$txtPilot_onBoard."', NOR_TENDERED='".$txtNor_Tendered."', VESSEL_ARRIVED='".$txtVessel_Arrived."', STOWAGE_QTY='".$txtStowageQty."', TERMINAL='".$txtTerminal."', ATTACHMENTS='".$upload1."', ATTACHMENTS_NAME='".$name1."', TURN_TIME='".$txtLPTurnTime."', TOTAL_DAYS_AT_PORT='".$txtLPDaysAtPort."', NOR_ACCEPTED='".$txtNOR_Accepted."', START_COUNTING='".$txtStart_Counting."', APPROVERS='".$approversel."' where LAYTIME_ID='".$qrows['LAYTIME_ID']."'";
		
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		$delquery = "delete from laytime_slave where LAYTIME_ID='".$qrows['LAYTIME_ID']."'"; 
		mysql_query($delquery);
		mysql_query("commit");
		
		$delquery2 = "delete from laytime_slave1 where LAYTIME_ID='".$qrows['LAYTIME_ID']."'"; 
		mysql_query($delquery2);
		mysql_query("commit");
		
		$delquery3 = "delete from laytime_slave2 where LAYTIME_ID='".$qrows['LAYTIME_ID']."'"; 
		mysql_query($delquery3);
		mysql_query("commit");
		
		if($selApp == 1)
		{			
			for($i=1 ; $i<=$txtTBID ;$i++)
			{
				if($_REQUEST['checkLPLTNoCounts_'.$tabid.'_'.$i] == ""){$ltno_counts = 0;}else{$ltno_counts = $_REQUEST['checkLPLTNoCounts_'.$tabid.'_'.$i];}
				if($_REQUEST['checkLPLTCounts_'.$tabid.'_'.$i] == ""){$lt_counts = 0;}else{$lt_counts = $_REQUEST['checkLPLTCounts_'.$tabid.'_'.$i];}
				if($_REQUEST['txtLPLTparcel_'.$tabid.'_'.$i] == ""){$lt_partial = 0;}else{$lt_partial = $_REQUEST['txtLPLTparcel_'.$tabid.'_'.$i];}
				
				if($_REQUEST['txtActivity_'.$tabid.'_'.$i] != "")
				{	
					$sql1 = "insert into laytime_slave (LAYTIME_ID, ACTIVITYID, SOFLOADPORTID, LT_C, LT_NC ,LT_PARTIAL, NOTES ,START_DATETIME ,FINISH_DATETIME  ,DURATION ,LT_PARTIAL_MINUTE,CUMMULATIVE_TIME) values ('".$qrows['LAYTIME_ID']."','".$_REQUEST['txtActivity_'.$tabid.'_'.$i]."','".$this->getCheckNullValue($sof_loadport_id)."','".$this->getCheckNullValue($lt_counts)."','".$this->getCheckNullValue($ltno_counts)."', '".$this->getCheckNullValue($lt_partial)."','".$_REQUEST['txtLPNotes_'.$tabid.'_'.$i]."','".date("Y-m-d H:i",strtotime($_REQUEST['txtLPDStart_'.$tabid.'_'.$i]))."','".date("Y-m-d H:i",strtotime($_REQUEST['txtLPDEnd_'.$tabid.'_'.$i]))."' ,'".$_REQUEST['txtLPDiff1_'.$tabid.'_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPVal_'.$tabid.'_'.$i])."','".$_REQUEST['txtCummulative1_'.$tabid.'_'.$i]."')"; 
					mysql_query($sql1) or die($sql1);
					mysql_query("commit");
				}
			}
		}
		
		for($i=1 ; $i<=$txtTBODYID ;$i++)
		{
			if($_REQUEST['txtDeductionActivity_'.$tabid.'_'.$i] != "")
			{	
				$sql1 = "insert into laytime_slave1 (LAYTIME_ID, ACTIVITYID, LT_PARTIAL, NOTES ,START_DATETIME ,FINISH_DATETIME, DURATION, CUMMULATIVE_TIME) values ('".$qrows['LAYTIME_ID']."', '".$_REQUEST['txtDeductionActivity_'.$tabid.'_'.$i]."', '".$this->getCheckNullValue($_REQUEST['txtLPLDeductionTparcent_'.$tabid.'_'.$i])."', '".addslashes($_REQUEST['txtLPDeductionNotes_'.$tabid.'_'.$i])."','".date("Y-m-d H:i",strtotime($_REQUEST['txtLPDDeductionStart_'.$tabid.'_'.$i]))."', '".date("Y-m-d H:i",strtotime($_REQUEST['txtLPDDeductionEnd_'.$tabid.'_'.$i]))."', '".$_REQUEST['txtLPDeductionDiff_'.$tabid.'_'.$i]."', '".$_REQUEST['txtLPDeductionDiff1_'.$tabid.'_'.$i]."')"; 
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}	
		}
		
		$txtCID     	    = $_REQUEST['txtCID_'.$tabid];
		for($i=1; $i<=$txtCID; $i++)
		{
			if($_REQUEST['txtAV_Name_'.$tabid.'_'.$i] != "" && $_REQUEST['txtAV_Value_'.$tabid.'_'.$i] != "")
			{
				$sql3 = "insert into laytime_slave2 (LAYTIME_ID, ENTITY_NAME, ENTITY_VALUE) values ('".$qrows['LAYTIME_ID']."', '".addslashes(trim($_REQUEST['txtAV_Name_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtAV_Value_'.$tabid.'_'.$i]))."')";
				mysql_query($sql3);
				mysql_query("commit");
			}
		}
		
		$this->saveRecentWork("Laytime of Port (".$port." - ".$this->getPortNameBasedOnID($portid).") of Voyage No. (".$voyageno.") Updated Successfully.");
	}	
	
	$this->inactiveUserAlerts('LAYTIME', $_SESSION['uid'], $laytimeid);
	
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers_'.$tabid];
	$approverarr2 = $this->getUsersWithAuthority('LAYTIME_CHK_APP_2');
	
	$url = './laytime_calculation.php?comid='.$_REQUEST['comid'].'&page='.$_REQUEST['page'].'&tab='.($_REQUEST['txttabid'][0]-1);
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'LAYTIME';
	
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($_REQUEST['comid'],"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($laytimeid != '' && $txtsubmitid >= 1)
	{
	    $userarray = array();
	    if($txtsubmitid == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent Laytime of Port ('.$port.' - '.$this->getPortNameBasedOnID($portid).') of Voyage No. ('.$vesselname.' - '.$voyageno.') for Level 1 Approval', $laytimeid);				  
				  }
			 }
		}
		
		if($txtsubmitid == 2)
		{  
		     $userarray = $creatorsarr;
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent Laytime of Port ('.$port.' - '.$this->getPortNameBasedOnID($portid).') of Voyage No. ('.$vesselname.' - '.$voyageno.') for Review', $laytimeid);				  
				  }
			 }
		}
		
		if($txtsubmitid == 4)
		{  
		     $userarray = $approverarr1;
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent Laytime of Port ('.$port.' - '.$this->getPortNameBasedOnID($portid).') of Voyage No. ('.$vesselname.' - '.$voyageno.') for Review', $laytimeid);				  
				  }
			 }
		}
		
		if($txtsubmitid == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent Laytime of Port ('.$port.' - '.$this->getPortNameBasedOnID($portid).') of Voyage No. ('.$vesselname.' - '.$voyageno.') for Level 2 Approval', $laytimeid);				  
				  }
			 }
		}
	}
	
	return $msg; 
}


function insertchecklistDetails()
{
	$connect = $this->funConnect();
	
	$lpsize = $_REQUEST['txtLPSize'];
	$dpsize = $_REQUEST['txtDPSize'];
	$eTAdateSize = $_REQUEST['txtETAdateSize'];
	
	$comid           		 = $_REQUEST['comid'];
	$dem_rate        		 = addslashes(trim($_REQUEST['dem_rate']));
	$refid 	   	    		 = addslashes(trim($_REQUEST['refid']));
	$ownname        		 = addslashes(trim($_REQUEST['txtOwnname']));
	$brocker 	    		 = addslashes(trim($_REQUEST['txtBroker']));
	$deadweight   	  	     = addslashes(trim($_REQUEST['deadweight']));
	$draft 		      	     = addslashes(trim($_REQUEST['draft']));
	$built         			 = addslashes(trim($_REQUEST['built']));
	$grt 		   			 = addslashes(trim($_REQUEST['grt']));
	$tpc            		 = addslashes(trim($_REQUEST['tpc']));
	$club 	   	    		 = addslashes(trim($_REQUEST['clube']));
	$regcheckbox  			 = addslashes(trim($_REQUEST['regcheckbox']));
	$classcheckbox 			 = addslashes(trim($_REQUEST['classcheckbox']));
	$pnicheckbox     		 = addslashes(trim($_REQUEST['pnicheckbox']));
	$ismcheckbox 			 = addslashes(trim($_REQUEST['ismcheckbox']));
	$doccheckbox    		 = addslashes(trim($_REQUEST['doccheckbox']));
	$itccheckbox 			 = addslashes(trim($_REQUEST['itccheckbox']));
	$ispscheckbox   		 = addslashes(trim($_REQUEST['ispscheckbox']));
	$llcheckbox     		 = addslashes(trim($_REQUEST['llcheckbox']));
	$bqcheckbox    		     = addslashes(trim($_REQUEST['bqcheckbox']));
	$hmcheckbox 		     = addslashes(trim($_REQUEST['hmcheckbox']));
	$seawebcheckbox          = addslashes(trim($_REQUEST['seawebcheckbox']));
	$cargodmcheckbox         = addslashes(trim($_REQUEST['cargodmcheckbox']));
	$cbiseakcheckbox 	     = addslashes(trim($_REQUEST['cbiseakcheckbox']));
	$pl_club	 		     = addslashes(trim($_REQUEST['pl_club']));
	$LPAdetail		         = addslashes(trim($_REQUEST['LPAdetail']));
	$operator		         = addslashes(trim($_REQUEST['operator']));
	
	$laycanO		 	     = addslashes(trim($_REQUEST['laycanO']));
	$laycanSone	 		     = addslashes(trim($_REQUEST['laycanSone']));
	$laycanStwo		         = addslashes(trim($_REQUEST['laycanStwo']));
	$laycanSthree		     = addslashes(trim($_REQUEST['laycanSthree']));
	$depfname		 	     = addslashes(trim($_REQUEST['depfname']));
	$depaname	 		     = addslashes(trim($_REQUEST['depaname']));
	$arrfname		         = addslashes(trim($_REQUEST['arrfname']));
	$arraname			     = addslashes(trim($_REQUEST['arraname']));
	$draftbl		 	     = addslashes(trim($_REQUEST['draftbl']));
	$blsplitqty1	 		 = addslashes(trim($_REQUEST['blsplitqty1']));
	$blsplitqty2		     = addslashes(trim($_REQUEST['blsplitqty2']));
	$ftfcheckbox		     = addslashes(trim($_REQUEST['ftfcheckbox']));
	
	$lfreciv		    	 = addslashes(trim($_REQUEST['lfreciv']));
	$ltowner		 	     = addslashes(trim($_REQUEST['ltowner']));
	$blmainfest  	 		 = addslashes(trim($_REQUEST['blmainfest']));
	$disinstr			     = addslashes(trim($_REQUEST['disinstr']));
	$ftfcheckbox2		     = addslashes(trim($_REQUEST['ftfcheckbox2']));
	$ownlaytime			     = addslashes(trim($_REQUEST['ownlaytime']));
	$remark				     = addslashes(trim($_REQUEST['remark']));
	$date 				     = date("d-M-Y H:i",strtotime($_REQUEST['date']));
	$txtReDelDate 			 = date("Y-m-d",strtotime($_REQUEST['txtReDelDate']));
	
	/*--------------------------- New Checklist filds ----------------------- */
	
	$chartPni		    	 = addslashes(trim($_REQUEST['chartPni']));
	$workingCp		    	 = addslashes(trim($_REQUEST['workingCp']));
	$lfrecivcheckbox		 = addslashes(trim($_REQUEST['lfrecivcheckbox']));
	$ltownercheckbox		 = addslashes(trim($_REQUEST['ltownercheckbox']));
	$blmainfestcheckbox  	 = addslashes(trim($_REQUEST['blmainfestcheckbox']));
	$disinstrcheckbox	     = addslashes(trim($_REQUEST['disinstrcheckbox']));
	
	$frepaycheckbox		     = addslashes(trim($_REQUEST['frepaycheckbox']));
	$daadvagecheckbox	     = addslashes(trim($_REQUEST['daadvagecheckbox']));
	//echo $frepaycheckbox;die();
	
	$cost_sheet_id = $this->getLatestCostSheetID($comid);
	$arr  = $this->getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($comid,$cost_sheet_id);
	//print_r($arr);die;
	
	$msg = $id = 0;
	
	$sql = "select * from check_list where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$rows = mysql_fetch_assoc($res);
	if($rec > 0)
		{  
		$sql = "update check_list set DEMM_RATE='".$this->getCheckNullValue($dem_rate)."',REF_ID='".$refid."',OWNER_NAME='".$ownname."',BROKER='".$brocker."',DEADWEIGHT='".$deadweight."',DRAFT='".$draft."',BUILT='".$built."',GRT='".$grt."',TPC='".$tpc."',CLUB='".$club."',REG='".$this->getCheckNullValue($regcheckbox)."',CLASS='".$this->getCheckNullValue($classcheckbox)."',PNI='".$this->getCheckNullValue($pnicheckbox)."',ISM='".$this->getCheckNullValue($ismcheckbox)."',DOC='".$this->getCheckNullValue($doccheckbox)."',ITC='".$this->getCheckNullValue($itccheckbox)."',ISPS='".$this->getCheckNullValue($ispscheckbox)."',LL='".$this->getCheckNullValue($llcheckbox)."',BQ='".$this->getCheckNullValue($bqcheckbox)."',H_M='".$this->getCheckNullValue($hmcheckbox)."',SEA_WEB='".$this->getCheckNullValue($seawebcheckbox)."',CARGODECL_MASTER='".$this->getCheckNullValue($cargodmcheckbox)."',CERTBQ_DESK='".$this->getCheckNullValue($cbiseakcheckbox)."',PL_CLUB='".$pl_club."',LPA_DETAIL='".$LPAdetail."',OPERATOR='".$operator."',LAYCAN_O='".$laycanO."',LAYCAN_SONE='".$laycanSone."',LAYCAN_STWO='".$laycanStwo."',LAYCAN_STHREE='".$laycanSthree."',SPDEP_F='".$depfname."',SPDEP_A='".$depaname."',SPARR_F='".$arrfname."',SPARR_A='".$arraname."',DRAFT_BL='".$draftbl."',BLQTY_ONE='".$blsplitqty1."',BLQTY_TWO='".$blsplitqty2."',LP_FTF='".$this->getCheckNullValue($ftfcheckbox)."',LOIFM_RECEVER='".$lfreciv."',LOITO_OWNER='".$ltowner."',BL_MANIFEST='".$blmainfest."',DISCH_INSTR='".$disinstr."',DP_FTF='".$this->getCheckNullValue($ftfcheckbox2)."', OWNER_LAYTIME='".$this->getCheckNullValue($ownlaytime)."',DATE='".$date."',REMARKS='".$remark."',CHARTERER_PNI='".$chartPni."',WORKING_CP='".$workingCp."',LOIFOM_RECIVED='".$this->getCheckNullValue($lfrecivcheckbox)."',LOITOOWNER='".$this->getCheckNullValue($ltownercheckbox)."',BLMANIFEST='".$this->getCheckNullValue($blmainfestcheckbox)."',DISCHARGE_INCT='".$this->getCheckNullValue($disinstrcheckbox)."',FREIGHT_PAYMENT='".$this->getCheckNullValue($frepaycheckbox)."',DAADV_AGENT='".$this->getCheckNullValue($daadvagecheckbox)."', REDEL_DATE='".$txtReDelDate."' where CHECKLIST_ID='".$rows['CHECKLIST_ID']."' ";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		$sql3 = "delete from checklist_loadport where CHECKLIST_ID='".$rows['CHECKLIST_ID']."'";
		mysql_query($sql3) or die($sql3);
		mysql_query("commit");
		$id = $rows['CHECKLIST_ID'];
		}
		else
		{  
		$sql =	"insert into check_list (DEMM_RATE,REF_ID,OWNER_NAME,BROKER,DEADWEIGHT,DRAFT,BUILT,GRT,TPC,CLUB,REG,CLASS,PNI,ISM,DOC,ITC,ISPS,LL,BQ,H_M,SEA_WEB,CARGODECL_MASTER,CERTBQ_DESK,PL_CLUB,LPA_DETAIL,OPERATOR,LAYCAN_O,LAYCAN_SONE,LAYCAN_STWO,LAYCAN_STHREE,SPDEP_F,SPDEP_A,SPARR_F,SPARR_A,DRAFT_BL,BLQTY_ONE,BLQTY_TWO,LP_FTF,LOIFM_RECEVER,LOITO_OWNER,BL_MANIFEST,DISCH_INSTR,DP_FTF,OWNER_LAYTIME,DATE,REMARKS,COMID,MODULEID,MCOMPANYID,CHARTERER_PNI,WORKING_CP,LOIFOM_RECIVED,LOITOOWNER,BLMANIFEST,DISCHARGE_INCT,FREIGHT_PAYMENT,DAADV_AGENT, REDEL_DATE) values ('".$this->getCheckNullValue($dem_rate)."','".$refid."','".$ownname."','".$brocker."','".$deadweight."','".$draft."','".$built."','".$grt."','".$tpc."','".$club."','".$this->getCheckNullValue($regcheckbox)."','".$this->getCheckNullValue($classcheckbox)."','".$this->getCheckNullValue($pnicheckbox)."','".$this->getCheckNullValue($ismcheckbox)."','".$this->getCheckNullValue($doccheckbox)."','".$this->getCheckNullValue($itccheckbox)."','".$this->getCheckNullValue($ispscheckbox)."','".$this->getCheckNullValue($llcheckbox)."','".$this->getCheckNullValue($bqcheckbox)."','".$this->getCheckNullValue($hmcheckbox)."','".$this->getCheckNullValue($seawebcheckbox)."','".$this->getCheckNullValue($cargodmcheckbox)."','".$this->getCheckNullValue($cbiseakcheckbox)."','".$pl_club."','".$LPAdetail."','".$operator."','".$laycanO."','".$laycanSone."','".$laycanStwo."','".$laycanSthree."','".$depfname."','".$depaname."','".$arrfname."','".$arraname."','".$draftbl."','".$blsplitqty1."','".$blsplitqty2."','".$this->getCheckNullValue($ftfcheckbox)."','".$lfreciv."','".$ltowner."','".$blmainfest."','".$disinstr."','".$this->getCheckNullValue($ftfcheckbox2)."','".$this->getCheckNullValue($ownlaytime)."','".$date."','".$remark."','".$comid."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$chartPni."','".$workingCp."','".$this->getCheckNullValue($lfrecivcheckbox)."','".$this->getCheckNullValue($ltownercheckbox)."','".$this->getCheckNullValue($blmainfestcheckbox)."','".$this->getCheckNullValue($disinstrcheckbox)."','".$this->getCheckNullValue($frepaycheckbox)."','".$this->getCheckNullValue($daadvagecheckbox)."','".$txtReDelDate."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		$sql1 = "select max(CHECKLIST_ID) as max from check_list";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$id = $rows1['max'];
		}
	
	
	$tabid1 = count($_REQUEST['txttabid1']); 
	$txtBOL = $_REQUEST['txtBOL_'.$tabid1]; 
	
	$sql_fty = "select * from checklist_finalqty where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	$res_fty = mysql_query($sql_fty);
	$rec_fty = mysql_num_rows($res_fty);
	$rows_fty = mysql_fetch_assoc($res_fty);
	
	$sql3 = "delete from checklist_finalqty where CHECKLIST_ID='".$id."'"; 
	mysql_query($sql3);
	
	for($i=1;$i<=$txtBOL;++$i)
	{ 	
		for($j=0;$j<count($arr);$j++)
		{	$arr_explode = explode('@@',$arr[$j]);$port_name = $this->getPortNameBasedOnID($arr_explode[1]);
			if($arr_explode[0] == "LP")
			{	
				$sql2 = "insert into checklist_finalqty (CHECKLIST_ID, PORT, PORTID, ENTITY_NAME, ENTITY_VALUE, COMID, MODULEID, MCOMPANYID, RANDOMID) values ('".$id."', 'LP', '".$this->getCheckNullValue($arr_explode[1])."', '".addslashes(trim($_REQUEST['txtfty_Name_'.$i]))."', '".addslashes(trim($_REQUEST['txtfty_Value_'.$i.'_'.$j]))."', '".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$arr_explode[2]."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			} 
		}
	}
	
	for($i=0;$i<$lpsize;$i++)
	{ 
		for($j=0;$j<count($arr);$j++)
		{   $arr_explode = explode('@@',$arr[$j]);$port_name = $this->getPortNameBasedOnID($arr_explode[1]);
			if($arr_explode[0] == "LP")
			{	
				if(isset($_REQUEST['txtlpid_'.$i.'_'.$j]))
				{
				$sql2 = "insert into checklist_loadport (CHECKLIST_ID, PORT, PORTID, ENTITY_NAME, ENTITY_VALUE, COMID, MODULEID, MCOMPANYID, RANDOMID) values ('".$id."', 'LP', '".$this->getCheckNullValue($arr_explode[1])."', '".addslashes(trim($_REQUEST['txtlpentity_'.$i]))."', '".addslashes(trim($_REQUEST['txtlpid_'.$i.'_'.$j]))."', '".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$arr_explode[2]."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
				}
			}
		}
	} 
	
	for($i=0;$i<$dpsize;$i++)
	{
		for($j=0;$j<count($arr);$j++)
		{   $arr_explode = explode('@@',$arr[$j]);$port_name = $this->getPortNameBasedOnID($arr_explode[1]);
			if($arr_explode[0] == "DP")
			{	
				if(isset($_REQUEST['txtdpid_'.$i.'_'.$j]))
				{
				$sql2 = "insert into checklist_loadport (CHECKLIST_ID, PORT, PORTID, ENTITY_NAME, ENTITY_VALUE, COMID, MODULEID, MCOMPANYID, RANDOMID) values ('".$id."', 'DP', '".$this->getCheckNullValue($arr_explode[1])."', '".addslashes(trim($_REQUEST['txtdpentity_'.$i]))."', '".addslashes(trim($_REQUEST['txtdpid_'.$i.'_'.$j]))."', '".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$arr_explode[2]."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
				}
			}
		}
	} 
	
	$notice = "delete from checklist_redelivery_notice where CHECKLIST_ID='".$rows['CHECKLIST_ID']."'";
	mysql_query($notice);
	
	for($i=0;$i<$eTAdateSize;$i++)
	{ 
		for($j=0;$j<count($arr);$j++)
		{   $arr_explode = explode('@@',$arr[$j]);$port_name = $this->getPortNameBasedOnID($arr_explode[1]);
			if($arr_explode[0] == "LP")
			{	
				$sql2 = "insert into checklist_redelivery_notice (CHECKLIST_ID, PORT, PORTID, ENTITY_NAME, ENTITY_VALUE, COMID, MODULEID, MCOMPANYID, RANDOMID) values ('".$id."', 'LP', '".$this->getCheckNullValue($arr_explode[1])."', '".addslashes(trim($_REQUEST['txtredelivery_date_'.$i]))."', '".addslashes(trim($_REQUEST['txredelivery_'.$i.'_'.$j]))."', '".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$arr_explode[2]."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		}
	} 
	
	mysql_query("commit");
	return $msg;
}

function getLaytimeRecordsBestOnMappingIdAndLoadPort($mappingid,$portDetail,$portID,$field){
	
	$connect = $this->funConnect();
	$port_arr = explode(' - ',$portDetail);
	
	$sql = "select ".$field." from laytime_master  where MAPPINGID='".$mappingid."' and LOGIN='INTERNAL_USER' and MCOMPANYID='".$_SESSION['company']."' and MODULEID='".$_SESSION['moduleid']."' and PORT='".$port_arr[0]."' and ENTITY='SHIP_OWNER' and PORTID='".$portID."' and SUBMITID=5 ";// and SUBMITID=2 .....for submit to close
	
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	
	if($rec == 0){
		
		return "";
	}else{
		
		$rows = mysql_fetch_assoc($res);
		return $rows[$field];		
	}
}

function getAccountType()
{
$state = array( 'Interim' =>'Interim' , 'Final' =>'Final');
$selAType = @$_REQUEST['selAType'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selAType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getRequestDataWithJson()
{
	$connect = $this->funconnect();
	
	$query = mysql_query("select * from request_master where LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'");
	while($row = mysql_fetch_assoc($query))
	{
	    $id = $row['REQ_ID'];
		$a[$id][] = array('account_type' => $row['ACCOUNT_TYPE'], 'payment_no' => $row['PAYMENT_NO'], 'date' => date("d-m-Y",strtotime($row['DATE'])), 'remarks' => $row['REMARKS'], 'ttl_outstandings' => $row['TTL_OUTSTANDINGS'], 'bal_outstandings' => $row['BAL_OUTSTANDINGS'], 'req_to_pay' => $row['REQ_TO_PAY'], 'r_type' => $row['R_TYPE'], 'p_type' => $row['P_TYPE'], 'i_amt' => $row['INVOICE_AMT'], 'i_date' => date("d-m-Y",strtotime($row['INVOICE_DATE'])));
	}
	echo json_encode($a);
}

function getRequestDeductionDataWithJson($id)
{
	$connect   = $this->funconnect();	
	$query     = mysql_query("select * from request_deduction_master where 1=1");
	while($row = mysql_fetch_assoc($query))
	{
		if($id == 1)
		{
			$sql = "select NAME from vc_deduction_master where VC_DEDUCTIONID='".$row['VC_DEDUCTIONID']."'";
		}
		
		$res  = mysql_query($sql);
		$rows = mysql_fetch_assoc($res);
	    $id   = $row['REQ_ID'];
		$a[$id][] = array('deduction_id' => $row['VC_DEDUCTIONID'], 'cost' => $row['COST'], 'name' => $rows['NAME']);
	}
	echo json_encode($a);
}




function insertRequestDetails()
{

	$connect 			= $this->funConnect();	
	$id 				= explode(",",$_REQUEST['id']);
	$comid 			    = $id['4'];
	//print_r($id);
	$selAType 			= addslashes(trim($_REQUEST['selAType']));
	$txtAccNO	 		= addslashes(trim($_REQUEST['txtAccNO']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	
	$txtTtl_Outs	 	= addslashes(trim($_REQUEST['txtTtl_Outs']));
	$txtBal_Outs	 	= addslashes(trim($_REQUEST['txtBal_Outs']));
	
	$txtROP	 			= addslashes(trim($_REQUEST['txtROP_3']));
	
	$txtROP_1	 		= addslashes(trim($_REQUEST['txtROP_1']));
	
	$txtPaymentID	 	= addslashes(trim($_REQUEST['txtPaymentID']));
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtCID	 			= addslashes(trim($_REQUEST['txtCID']));
	$txtV_I_Amt	 		= addslashes(trim($_REQUEST['txtV_I_Amt']));
	
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	
	$selBankingID       = addslashes(trim($_REQUEST['selBankingID']));
	
	$txtI_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtI_Date']));
	$txtNET             = $_REQUEST['txtNET'];
	
	
	$txtCRMFILE			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME			= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE != '' && $upload != ''){ $upload1 = $txtCRMFILE.','.$upload;}
	else if($txtCRMFILE == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE != '' && $upload == ''){ $upload1 = $txtCRMFILE;}
	
	if($txtCRMNAME != '' && $name != ''){ $name1 = $txtCRMNAME.','.$name;}
	else if($txtCRMNAME == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME != '' && $name == ''){ $name1 = $txtCRMNAME;}
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	$selApprovers             = $_REQUEST['selApprovers'];
	$invoiceidd = '';$creatorloginid = '';
	
	if($txtPaymentID=='')
	{
		$sql = "insert into request_master (COMID, MODULEID, MCOMPANYID, LOGIN, NAME, NAME_ID, GRADEID, VENDOR, PORT, ACCOUNT_TYPE, PAYMENT_NO, DATE, REMARKS, TTL_OUTSTANDINGS, BAL_OUTSTANDINGS, REQ_TO_PAY, STATUS, CP_DATE, REQUESTED, VESSELID, R_TYPE, P_TYPE, INVOICE_AMT, INVOICE_DATE, NET_AMT, UPLOAD, UPLOAD_NAME, APPROVERS, CREATOR, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_CURRENCY, BANKING_DETAILS,VENDOR_SLAVEID,PAYMENT_STATUS) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$id[1]."', '".$id[0]."', '".$id[2]."', '".$txtVendor."', '".$id[6]."', '".$selAType."', '".$txtAccNO."', '".$txtDate."', '".$txtRemarks."', '".$this->getCheckNullVal($txtTtl_Outs)."', '".$this->getCheckNullVal($txtBal_Outs)."', '".$this->getCheckNullVal($txtROP)."', '".$txtStatus."', '".$txtCP_Date."', '0', '".$this->getCompareEstimateData($comid,"VESSEL_IMO_ID")."', '".$this->getCheckNullVal($_REQUEST['rdoQty'])."', '".$this->getCheckNullVal($txtROP_1)."', '".$this->getCheckNullVal($txtV_I_Amt)."', '".$txtI_Date."', '".$this->getCheckNullVal($txtNET)."', '".$upload1."', '".$name1."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$this->getCheckNullVal($txtExchangeRate)."', '".$txtExchangeDate."', '".$selExchangeCurrency."', '".addslashes(trim($this->getVendorListNewData($txtVendor,"BANKING_DETAILS")))."', '".$selBankingID."', '".$_REQUEST['payment_status']."')";
		
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql1  = "select max(REQ_ID) as max from request_master";
		$res1  = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$invoiceidd = $rows1['max'];
		$creatorloginid =  $_SESSION['uid'];
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into request_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into request_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$this->saveRecentWork($selAType." ".$_REQUEST['name']."  Payment (".$txtAccNO.") Created Successfully.");

	}else
	{
	    $invoiceidd = $txtPaymentID;
		
		$sql_sel = "select APPROVERS, CREATOR from request_master where REQ_ID='".$txtPaymentID."'";
		$res_sel = mysql_query($sql_sel) or die($sql_sel);
		$rows_sel = mysql_fetch_assoc($res_sel);
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $rows_sel['APPROVERS'];
		}
		$creatorloginid = $rows_sel['CREATOR'];
		

		


		$sql = "update request_master set NAME='".$id[1]."', NAME_ID='".$id[0]."', GRADEID='".$id[2]."', VENDOR='".$txtVendor."', PORT='".$id[6]."', ACCOUNT_TYPE='".$selAType."', PAYMENT_NO='".$txtAccNO."', DATE='".$txtDate."', REMARKS='".$txtRemarks."', TTL_OUTSTANDINGS='".$this->getCheckNullVal($txtTtl_Outs)."', BAL_OUTSTANDINGS='".$this->getCheckNullVal($txtBal_Outs)."', REQ_TO_PAY='".$this->getCheckNullVal($txtROP)."', STATUS= '".$txtStatus."', CP_DATE='".$txtCP_Date."', REQUESTED='0', VESSELID='".$this->getCompareEstimateData($comid,"VESSEL_IMO_ID")."', R_TYPE='".$this->getCheckNullVal($_REQUEST['rdoQty'])."', P_TYPE='".$this->getCheckNullVal($txtROP_1)."', INVOICE_AMT='".$this->getCheckNullVal($txtV_I_Amt)."', INVOICE_DATE='".$txtI_Date."', NET_AMT='".$this->getCheckNullVal($txtNET)."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', APPROVERS='".$approversel."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', EXCHANGE_DATE='".$txtExchangeDate."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', BANKING_DETAILS='".addslashes(trim($this->getVendorListNewData($txtVendor,"BANKING_DETAILS")))."', VENDOR_SLAVEID='".$selBankingID."', PAYMENT_STATUS='".$_REQUEST['payment_status']."' where REQ_ID='".$txtPaymentID."'";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql5 = "delete from request_master_slave where REQ_ID='".$txtPaymentID."'";
		mysql_query($sql5) or die($sql5);
		mysql_query("commit");
		
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into request_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtPaymentID."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into request_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtPaymentID."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$this->saveRecentWork($selAType." ".$_REQUEST['name']." Payment (".$txtAccNO.") Added/Updated Successfully.");
	}
	$this->inactiveUserAlerts('PAYMENT', $_SESSION['uid'], $invoiceidd);
	
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	
	if($id[1] == 'Load Port Costs' || $id[1] == 'Discharge Port Costs' || $id[1] == 'Transit Port Costs')
	{
		$portcost = 0;
		if($id[1] == 'Load Port Costs')
		{
			$portcost = $this->getFDA($comid,'LP',$id[2],$id['7']);
		}
		if($id[1] == 'Discharge Port Costs')
		{
			$portcost = $this->getFDA($comid,'DP',$id[2],$id['7']);
		}
		if($id[1] == 'Transit Port Costs')
		{
			$portcost = $this->getFDA($comid,'TP',$id[2],$id['7']);
		}
		if($portcost >0)
		{
			$approverarr2 = $this->getUsersWithAuthority('FDA_CHK_APP_2');
			$appaccountarr   = $this->getUsersWithAuthority('FDA_CHK_ACC');
		}else
		{
			$approverarr2 = $this->getUsersWithAuthority('PDA_CHK_APP_2');
			$appaccountarr   = $this->getUsersWithAuthority('PDA_CHK_ACC');
		}
	}
	else
	{
		$approverarr2 = $this->getUsersWithAuthority('OTHER_PAYMENT_CHK_APP_2');
		$appaccountarr   = $this->getUsersWithAuthority('OTHER_PAYMENT_CHK_ACC');
	}
	
	$approverarraccount2 = $this->getUsersWithAuthority('HIRE_STSTMENT_CHK_ACC');
	
	$url = './request_port_cost.php?id='.$_REQUEST['id'].'&page='.$_REQUEST['page'].'&name='.$_REQUEST['name'];
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'PAYMENT';
	
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{
		     if(!empty($appaccountarr))
			 {
			     $userarray = $appaccountarr;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' Approved '.$_REQUEST['name'].' '.$invtitleType.' ('.$vesselname.' - '.$txtAccNO.').', $invoiceidd);				  
				  }
			 }
		}
	}
	
	mysql_query("commit");
	return $msg; 
}



function insertRequestReletDetails()
{
	
	
	$connect 			= $this->funConnect();	
	$id 				= explode(",",$_REQUEST['id']);
	$comid 			    = $id['2'];
	//print_r($id);
	$selAType 			= addslashes(trim($_REQUEST['selAType']));
	$txtAccNO	 		= addslashes(trim($_REQUEST['txtAccNO']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	
	$txtTtl_Outs	 	= addslashes(trim($_REQUEST['txtTtl_Outs']));
	$txtBal_Outs	 	= addslashes(trim($_REQUEST['txtBal_Outs']));
	
	$txtROP	 			= addslashes(trim($_REQUEST['txtROP_3']));
	
	$txtROP_1	 		= addslashes(trim($_REQUEST['txtROP_1']));
	
	$txtID	 			= addslashes(trim($_REQUEST['txtID']));
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtCID	 			= addslashes(trim($_REQUEST['txtCID']));
	$txtV_I_Amt	 		= addslashes(trim($_REQUEST['txtV_I_Amt']));
	$txtI_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtI_Date']));
	$txtNET             = $_REQUEST['txtNET'];
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	if($txtID!='')
	{
		$sql4 = "delete from request_relet_master where REQ_ID='".$txtID."'";
		mysql_query($sql4) or die($sql4);
		mysql_query("commit");
		
		$sql5 = "delete from request_relet_master_slave where REQ_ID='".$txtID."'";
		mysql_query($sql5) or die($sql5);
		mysql_query("commit");
	}
	
	//insert query here.............
	$sql = "insert into request_relet_master (COMID, MODULEID, MCOMPANYID, LOGIN, NAME, VENDOR, ACCOUNT_TYPE, PAYMENT_NO, DATE, REMARKS, TTL_OUTSTANDINGS, BAL_OUTSTANDINGS, REQ_TO_PAY, STATUS, CP_DATE, REQUESTED, INVOICE_AMT, INVOICE_DATE, NET_AMT) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$id[0]."', '".$id[1]."', '".$selAType."', '".$txtAccNO."', '".$txtDate."', '".$txtRemarks."', '".$this->getCheckNullVal($txtTtl_Outs)."', '".$this->getCheckNullVal($txtBal_Outs)."', '".$this->getCheckNullVal($txtROP)."', '".$txtStatus."', '".$txtCP_Date."', '0', '".$this->getCheckNullVal($txtV_I_Amt)."', '".$txtI_Date."', '".$this->getCheckNullVal($txtNET)."')";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql1  = "select max(REQ_ID) as max from request_relet_master";
	$res1  = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	
	$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into request_relet_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into request_relet_master_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
	
	
	mysql_query("commit");
	return $msg; 
}


function insertRequestUploadDetails()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update request_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where REQ_ID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$this->inactiveUserAlerts('PAYMENT', $_SESSION['uid'], $txtP_ID);
	
	return $msg; 
}

function insertRequestReletUploadDetails()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update request_relet_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."' where REQ_ID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	return $msg; 
}


function deleteRequestDetails()
{
	$connect = $this->funConnect();
	
	$txtID 				= addslashes(trim($_REQUEST['txtPaymentID2']));
	$id 				= addslashes(trim($_REQUEST['id']));
	
	$msg = 2;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "select * from request_master where REQ_ID='".$txtID."'";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	
	$qsql = "delete from  request_master_slave where REQ_ID='".$txtID."'";
	mysql_query($qsql);
	
	$sql = "delete from  request_master where REQ_ID='".$txtID."'";
	mysql_query($sql);
	
	$sql3 = "select * from vwpr_master where VENDORID='".$rows1['VENDOR']."'";
	$res3 = mysql_query($sql3);
	while($rows3 = mysql_fetch_assoc($res3))
	{
		$reqid  = explode(",",$rows3['REQ_ID']);
		$vessel = explode(",",$rows3['VESSEL']);
		$remark = explode(",",$rows3['REMARK']);
		
		
		if(sizeof($reqid) == 1)
		{
			$sql4 = "delete from vwpr_master where VWPR_ID='".$rows3['VWPR_ID']."'";
			mysql_query($sql4);
		}
		else
		{
			for($i=0;$i<sizeof($reqid);$i++)
			{
				if($txtID != $reqid[$i])
				{
					$reqid_1[$i] = $reqid[$i];
					$vessel_1[$i] = $vessel[$i];
					$remark_1[$i] = $remark[$i];
				}
				
			}
			
			$reqid_2 = implode(",",$reqid_1);
			$vessel_2 = implode(",",$vessel_1);
			$remark_2 = implode(",",$remark_1);
			
			$total = $rows3['TOTAL']-$rows1['REQ_TO_PAY'];
			$g_total = $total*$rows3['RATE'];
			
			$sql4 = "update vwpr_master set VESSEL='".$vessel_2."', REMARK='".$remark_2."', REQ_ID='".$reqid_2."', TOTAL='".$total."', GRANDTOTAL='".$g_total."' where VWPR_ID='".$rows3['VWPR_ID']."'";
			mysql_query($sql4);
		}
	}
	
	mysql_query("commit");	
	return $msg.'_'.$id;
}



function deleteRequestReletDetails()
{
	$connect = $this->funConnect();
	
	$txtID 				= addslashes(trim($_REQUEST['txtID']));
	$id 				= addslashes(trim($_REQUEST['id']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$qsql = "delete from  request_relet_master where REQ_ID='".$txtID."'";
	mysql_query($qsql);
	
	$sql = "delete from  request_relet_master_slave where REQ_ID='".$txtID."'";
	mysql_query($sql);
	
	
	mysql_query("commit");	
	return $msg.'_'.$id;
}


function getBankingListNewBasedOnID($id)
{
	$this->funConnect();
	$sql  = "select NAME from banking_details where BD_ID='".$id."' ";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}



function insertInvoiceHireDetails()
{
	$connect = $this->funConnect(); 
	
	$comid 			    = addslashes(trim($_REQUEST['comid']));
	$txtInID	 	    = addslashes(trim($_REQUEST['txtInID']));
	$txtFCAID           = addslashes(trim($_REQUEST['txtFCAID']));
	$txtStatus	 	    = addslashes(trim($_REQUEST['txtStatus']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtInvNo    	 	= addslashes(trim($_REQUEST['txtInvNo']));
	$txtInvDate	 		= date("Y-m-d",strtotime($_REQUEST['txtInvDate']));
	$txtExchangeRate 	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$txtExchangeDate	= date('Y-m-d',strtotime($_REQUEST['txtExchangeDate']));
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc	 		= addslashes(trim($_REQUEST['txtDesc']));
	$txtEstHireDays   	= addslashes(trim($_REQUEST['txtEstHireDays']));
	$txtHireperDay	 	= addslashes(trim($_REQUEST['txtHireperDay']));	
	$txtHireFrom    	= date('Y-m-d H:i',strtotime($_REQUEST['txtHireFrom']));
	$txtHireTo    	    = date('Y-m-d H:i',strtotime($_REQUEST['txtHireTo']));
	$txtHireDays    	= addslashes(trim($_REQUEST['txtHireDays']));
	$txtTotalHire 		= addslashes(trim($_REQUEST['txtTotalHire']));
	$txtCVEMonth    	= addslashes(trim($_REQUEST['txtCVEMonth']));
	$txtCVE_Amt  	 	= addslashes(trim($_REQUEST['txtCVE_Amt']));
	$txtAddrCommPer	    = addslashes(trim($_REQUEST['txtAddrCommPer']));
	$txtAddrCommAmt	 	= addslashes(trim($_REQUEST['txtAddrCommAmt']));
	$txtBroCommPer  	= addslashes(trim($_REQUEST['txtBroCommPer']));
	$txtBroCommAmt      = addslashes(trim($_REQUEST['txtBroCommAmt']));
	$ChkShowOffHire     = addslashes(trim($_REQUEST['ChkShowOffHire']));
	$ChkOverConspBunker = addslashes(trim($_REQUEST['ChkOverConspBunker']));
	$txtOffHireDays	 	= addslashes(trim($_REQUEST['txtOffHireDays']));
	$txtOffHire     	= addslashes(trim($_REQUEST['txtOffHire']));
	$txtCVEOffHireMonth = addslashes(trim($_REQUEST['txtCVEOffHireMonth']));
	$txtCVEOFFHIRE_Amt  = addslashes(trim($_REQUEST['txtCVEOFFHIRE_Amt']));
	$ChkDeliveryBunker  = addslashes(trim($_REQUEST['ChkDeliveryBunker']));
	$ChkReDeliveryBunker= addslashes(trim($_REQUEST['ChkReDeliveryBunker']));
	$txtFinalAmt        = addslashes(trim($_REQUEST['txtFinalAmt']));
	$selFromOwner        = addslashes(trim($_REQUEST['selFromOwner']));
	$txtOFFHIRE_Bunker   = addslashes(trim($_REQUEST['txtOFFHIRE_Bunker']));
	$txtBalanceShipOwner = addslashes(trim($_REQUEST['txtBalanceShipOwner']));
	$ChkBallastBonus     = addslashes(trim($_REQUEST['ChkBallastBonus']));
	
	
	$offhireRandomCount     = addslashes(trim($_REQUEST['offhireRandomCount']));
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$filename = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$filename = implode(',',$filename);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $filename != ''){ $name1 = $txtCRMNAME1.','.$filename;}
	else if($txtCRMNAME1 == '' && $filename != ''){ $name1 = $filename;}
	else if($txtCRMNAME1 != '' && $filename == ''){ $name1 = $txtCRMNAME1;}
	
	$selApprovers             = $_REQUEST['selApprovers'];
	$selBankingID             = $_REQUEST['selBankingID'];
	$selBankingID1             = $_REQUEST['selBankingID1'];
	$invoiceidd = '';$creatorloginid = '';
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	if($txtInID == '')
	{
		$sql = "insert into invoice_hire_master (MCOMPANYID, MODULEID, COMID, INVOICE_DATE, STATUS, INVOICE_TYPE, INVOICE_NO, EXCHANGE_DATE, EXCHANGE_RATE, CURRENCY, PAYMENT_TERMS, DESCRIPTION, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_AMT, CVE, CVE_AMT, ADD_COMM_PER, ADD_COMM_AMT, OFFHIRE_DAYS, OFFHIRE_AMT, OFFHIRE_CVE, OFFHIRE_CVE_AMT, FINAL_AMT, BRO_COMM_PER, BRO_COMM_AMT, CHK_OFFHIRE, CHK_DELIVERY, CHK_REDELIVERY, SHIP_OWNER, FCAID, BUNKER_CONSUMPTION, CHK_BALLAST_BONUS, BALANCE_TO_OWNER, APPROVERS, CREATOR, DAILY_HIRE_RATE, UPLOAD, UPLOAD_NAME, CHK_OVERCONSP, BANKING_DETAILS, VENDOR_SLAVEID, BANKINGDETAILID,PAYMENT_STATUS,CVE_AMT_MANUAL) values ('".$_SESSION['company']."', '".$_SESSION['moduleid']."', '".$comid."', '".$txtInvDate."', '".$txtStatus."', '".$selIType."', '".$txtInvNo."', '".$txtExchangeDate."', '".$this->getCheckNullVal($txtExchangeRate)."', '".$selExchangeCurrency."', '".$txtPaymentTerms."', '".$txtDesc."', '".$txtHireFrom."', '".$txtHireTo."', '".$txtHireDays."', '".$txtTotalHire."', '".$txtCVEMonth."', '".$txtCVE_Amt."', '".$this->getCheckNullVal($txtAddrCommPer)."', '".$this->getCheckNullVal($txtAddrCommAmt)."', '".$this->getCheckNullVal($txtOffHireDays)."', '".$this->getCheckNullVal($txtOffHire)."', '".$this->getCheckNullVal($txtCVEOffHireMonth)."', '".$this->getCheckNullVal($txtCVEOFFHIRE_Amt)."', '".$this->getCheckNullVal($txtFinalAmt)."', '".$this->getCheckNullVal($txtBroCommPer)."', '".$this->getCheckNullVal($txtBroCommAmt)."', '".$this->getCheckNullVal($ChkShowOffHire)."', '".$this->getCheckNullVal($ChkDeliveryBunker)."', '".$this->getCheckNullVal($ChkReDeliveryBunker)."', '".$selFromOwner."', '".$txtFCAID."', '".$this->getCheckNullVal($txtOFFHIRE_Bunker)."', '".$this->getCheckNullVal($ChkBallastBonus)."', '".$this->getCheckNullVal($txtBalanceShipOwner)."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$this->getCheckNullVal($txtHireperDay)."', '".$upload1."', '".$name1."', '".$this->getCheckNullVal($ChkOverConspBunker)."', '".addslashes(trim($this->getVendorListNewData($this->getCompareEstimateData($comid,"DTCVENDORID"),"BANKING_DETAILS")))."', '".$this->getCheckNullVal($selBankingID)."', '".$this->getCheckNullVal($selBankingID1)."', '".$this->getCheckNullVal($_REQUEST['payment_status'])."', '".$this->getCheckNullVal($_REQUEST['txtCVE_AmtManual'])."')";
		mysql_query($sql) or die($sql);
		
		
		$sql1 = "select max(INVOICEID) as max from invoice_hire_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$invoiceidd = $rows1['max'];
		$creatorloginid =  $_SESSION['uid'];
		
		
		$totalDaysTows  = $_REQUEST['totalDaysTows'];
		for($i=1;$i<=$totalDaysTows;$i++)
		{
			$txtRandom	 	  = addslashes(trim($_REQUEST['txtRandom_'.$i]));
			$txtInvDay  	  = $this->getCheckNullVal($_REQUEST['txtInvDay_'.$i]);
			$txtInvHire 	  = addslashes(trim($_REQUEST['txtInvHire_'.$i]));
			
			$txtHireFrom    	= date('Y-m-d H:i',strtotime($_REQUEST['txtHireFrom_'.$i]));
	        $txtHireTo    	    = date('Y-m-d H:i',strtotime($_REQUEST['txtHireTo_'.$i]));



			$sql2 = "insert into invoice_hire_slave8 (INVOICEID, RANDOMID, UTILISED_DAYS, HIRE_AMT, HIRE_FROM, HIRE_TO) values ('".$rows1['max']."', '".$txtRandom."', '".$txtInvDay."', '".$txtInvHire."', '".$txtHireFrom."', '".$txtHireTo."')";
			mysql_query($sql2);
		}
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into invoice_hire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into invoice_hire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$txtHoldID  = $_REQUEST['txtHoldID'];
		for($i=1;$i<=$txtHoldID;$i++)
		{
			$txtHoldDes	 	  = addslashes(trim($_REQUEST['txtHoldDes_'.$i]));
			$txtHoldDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHoldDesAmt_'.$i]);
			$sql2 = "insert into invoice_hire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtHoldDes."', '".$txtHoldDesAmt."', 'HOLD_CLEANING')";
			mysql_query($sql2);
		}
		
		$txtHireSurveyID  = $_REQUEST['txtHireSurveyID'];
		for($i=1;$i<=$txtHireSurveyID;$i++)
		{
			$txtHireSurveyDes	 	  = addslashes(trim($_REQUEST['txtHireSurveyDes_'.$i]));
			$Chk_Owner_Account  	  = $this->getCheckNullVal($_REQUEST['Chk_Owner_Account_'.$i]);
			$txtHireSurveyDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHireSurveyDesAmt_'.$i]);
			$sql2 = "insert into invoice_hire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY, CHK_OWNER_ACC) values ('".$rows1['max']."', '".$txtHireSurveyDes."', '".$txtHireSurveyDesAmt."', 'HIRE_SURVEY', '".$this->getCheckNullVal($Chk_Owner_Account)."')";
			mysql_query($sql2);
		}
		
		if($ChkShowOffHire==1)
		{
			$txtOFFID = $_REQUEST['txtOFFID'];
			for($i=1 ; $i<=$txtOFFID ;$i++)
			{
				if($_REQUEST['txtOffHireReason_'.$i] != "")
				{
					if($_REQUEST['txtOffHireFrom_'.$i]!="")
					{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
					else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtOffHireTo_'.$i]!="")
					{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
					else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
					
					$sql3 = "insert into invoice_hire_slave6 (INVOICEID, OFF_REASON, OFF_FROM, OFF_TO, OFF_HIRE_PERCENT, OFF_DAYS, OFF_HIRE, HIRE_RATE) values ('".$rows1['max']."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHirePercent_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOffHirePerDay_'.$i])."')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
					
					$mysql14 = "select max(INVOICE_SLAVE6ID) as max from invoice_hire_slave6 where INVOICEID='".$rows1['max']."'";
					$myres14  =  mysql_query($mysql14);
					$myrows14 = mysql_fetch_assoc($myres14);
					$maxid14 = $myrows14['max'];
					
					$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
					for($m=1 ; $m<=$txtDELID ;$m++)
					{
						if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
						{
							$sql15 = "insert into invoice_hire_slave61 (INVOICE_SLAVE6ID, INVOICEID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT) values ('".$maxid14."', '".$rows1['max']."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."')";
							mysql_query($sql15) or die($sql15);
							mysql_query("commit");
						}
					}
				}
			}
		}
		
		$txtDelbid  = $_REQUEST['txtAddDELID'];
		for($i=1;$i<=$txtDelbid;$i++)
		{
			if($_REQUEST['selDELBunker_'.$i]!='')
			{
				$selDELBunker	 	      = $this->getCheckNullVal($_REQUEST['selDELBunker_'.$i]);
				$txtDelBunkerQty	      = $this->getCheckNullVal($_REQUEST['txtDelBunkerQty_'.$i]);
				$txtDelBunkerPrice	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerPrice_'.$i]);
				$txtDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selDELBunker."', '".$txtDelBunkerQty."', '".$txtDelBunkerPrice."', '".$txtDelBunkerAmt."', 'DEL')";
				mysql_query($sql2);
			}
		}
		
		$txtAddREDELID = $_REQUEST['txtAddREDELID'];
		for($i=1;$i<=$txtAddREDELID;$i++)
		{
			if($_REQUEST['selReDELBunker_'.$i]!='')
			{
				$txtReDelBunkerQty	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerQty_'.$i]);
				$selReDELBunker  	      = $this->getCheckNullVal($_REQUEST['selReDELBunker_'.$i]);
				$txtReDelBunkerPrice	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerPrice_'.$i]);
				$txtReDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selReDELBunker."', '".$txtReDelBunkerQty."', '".$txtReDelBunkerPrice."', '".$txtReDelBunkerAmt."', 'REDEL')";
				mysql_query($sql2);
			}
		}
		
		
		$txtAddOVERCONPID = $_REQUEST['txtAddOVERCONPID'];
		for($i=1;$i<=$txtAddOVERCONPID;$i++)
		{
			if($_REQUEST['selOverConspBunker_'.$i]!='')
			{
				$txtOverConspBunkerQty 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerQty_'.$i]);
				$selOverConspBunker	      = $this->getCheckNullVal($_REQUEST['selOverConspBunker_'.$i]);
				$txtOverConspBunkerPrice  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerPrice_'.$i]);
				$txtOverConspBunkerAmt 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selOverConspBunker."', '".$txtOverConspBunkerQty."', '".$txtOverConspBunkerPrice."', '".$txtOverConspBunkerAmt."', 'OVERCONSP')";
				mysql_query($sql2);
			}
		}
		
		
		$txtORCID  = $_REQUEST['txtORCID'];
		for($i=1;$i<=$txtORCID;$i++)
		{
		    if(isset($_REQUEST['chkORC_'.$i]))
			{
				$txtORCRandomid	 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCRandomid_'.$i])));
				$txtORCVendorid  	  = addslashes(trim($_REQUEST['txtORCVendorid_'.$i]));
				$txtORCIdentify 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCIdentify_'.$i])));
				$txtORCAmt      	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCAmt_'.$i])));
				
				$sql2 = "insert into invoice_hire_slave5 (INVOICEID, RANDOMID, IDENTITYID, VENDORID, AMOUNT) values ('".$rows1['max']."', '".$txtORCRandomid."', '".$txtORCIdentify."', '".$txtORCVendorid."', '".$txtORCAmt."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		
		$hddnprevinvid  = $_REQUEST['hddnprevinvid'];
		for($i=1;$i<=$hddnprevinvid;$i++)
		{
		    if(isset($_REQUEST['chkPrevInv_'.$i]))
			{
				$txtPrevInvID	 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtPrevInvID_'.$i])));
				$txtPrevInvIdentify	  = addslashes(trim($_REQUEST['txtPrevInvIdentify_'.$i]));
				$sql2 = "insert into invoice_hire_slave7 (INVOICEID, PINVOICEID, IDENTIFY) values ('".$rows1['max']."', '".$txtPrevInvID."', '".$txtPrevInvIdentify."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." Hire Statement (".$txtInvNo.") Created Successfully.");
	}
	else
	{
	    $invoiceidd = $txtInID;
		
		$sql_sel = "select APPROVERS, CREATOR from invoice_hire_master where INVOICEID='".$txtInID."'";
		$res_sel = mysql_query($sql_sel) or die($sql_sel);
		$rows_sel = mysql_fetch_assoc($res_sel);
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $rows_sel['APPROVERS'];
		}
		$creatorloginid = $rows_sel['CREATOR'];
	
		$sql = "update invoice_hire_master set COMID='".$comid."', INVOICE_DATE='".$txtInvDate."', STATUS='".$txtStatus."', INVOICE_TYPE='".$selIType."', INVOICE_NO='".$txtInvNo."', EXCHANGE_DATE='".$txtExchangeDate."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', CURRENCY='".$selExchangeCurrency."', PAYMENT_TERMS='".$txtPaymentTerms."', DESCRIPTION='".$txtDesc."', HIRE_FROM='".$txtHireFrom."', HIRE_TO='".$txtHireTo."', HIRE_DAYS='".$txtHireDays."', HIRE_AMT='".$txtTotalHire."', CVE='".$txtCVEMonth."', CVE_AMT='".$txtCVE_Amt."', ADD_COMM_PER='".$this->getCheckNullVal($txtAddrCommPer)."', ADD_COMM_AMT='".$this->getCheckNullVal($txtAddrCommAmt)."', OFFHIRE_DAYS='".$this->getCheckNullVal($txtOffHireDays)."', OFFHIRE_AMT='".$this->getCheckNullVal($txtOffHire)."', OFFHIRE_CVE='".$this->getCheckNullVal($txtCVEOffHireMonth)."', OFFHIRE_CVE_AMT='".$this->getCheckNullVal($txtCVEOFFHIRE_Amt)."', FINAL_AMT='".$this->getCheckNullVal($txtFinalAmt)."', BRO_COMM_PER='".$this->getCheckNullVal($txtBroCommPer)."', BRO_COMM_AMT='".$this->getCheckNullVal($txtBroCommAmt)."', CHK_OFFHIRE='".$this->getCheckNullVal($ChkShowOffHire)."', CHK_DELIVERY='".$this->getCheckNullVal($ChkDeliveryBunker)."', CHK_REDELIVERY='".$this->getCheckNullVal($ChkReDeliveryBunker)."', SHIP_OWNER='".$selFromOwner."', BUNKER_CONSUMPTION='".$this->getCheckNullVal($txtOFFHIRE_Bunker)."', CHK_BALLAST_BONUS='".$this->getCheckNullVal($ChkBallastBonus)."', BALANCE_TO_OWNER='".$this->getCheckNullVal($txtBalanceShipOwner)."', APPROVERS='".$approversel."', DAILY_HIRE_RATE='".$this->getCheckNullVal($txtHireperDay)."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', CHK_OVERCONSP='".$this->getCheckNullVal($ChkOverConspBunker)."', BANKING_DETAILS='".addslashes(trim($this->getVendorListNewData($this->getCompareEstimateData($comid,"DTCVENDORID"),"BANKING_DETAILS")))."', VENDOR_SLAVEID='".$this->getCheckNullVal($selBankingID)."', BANKINGDETAILID='".$this->getCheckNullVal($selBankingID1)."',PAYMENT_STATUS='".$this->getCheckNullVal($_REQUEST['payment_status'])."',CVE_AMT_MANUAL='".$this->getCheckNullVal($_REQUEST['txtCVE_AmtManual'])."' where INVOICEID='".$txtInID."'";
		mysql_query($sql) or die($sql);

		
		
		$sql1 = "delete from invoice_hire_slave1 where INVOICEID='".$txtInID."'";
		$sql2 = "delete from invoice_hire_slave2 where INVOICEID='".$txtInID."'";
		$sql3 = "delete from invoice_hire_slave4 where INVOICEID='".$txtInID."'";
		$sql6 = "delete from invoice_hire_slave6 where INVOICEID='".$txtInID."'";
		$sql61 = "delete from invoice_hire_slave61 where INVOICEID='".$txtInID."'";
		$sql4 = "delete from invoice_hire_slave5 where INVOICEID='".$txtInID."'";
		$sql7 = "delete from invoice_hire_slave7 where INVOICEID='".$txtInID."'";
		$sql8 = "delete from invoice_hire_slave8 where INVOICEID='".$txtInID."'";
		mysql_query($sql1);
		mysql_query($sql2);
		mysql_query($sql3);
		mysql_query($sql6);
		mysql_query($sql61);
		mysql_query($sql4);
		mysql_query($sql7);
		mysql_query($sql8);
		
		$totalDaysTows  = $_REQUEST['totalDaysTows'];
		for($i=1;$i<=$totalDaysTows;$i++)
		{
			$txtRandom	 	  = addslashes(trim($_REQUEST['txtRandom_'.$i]));
			$txtInvDay  	  = $this->getCheckNullVal($_REQUEST['txtInvDay_'.$i]);
			$txtInvHire 	  = addslashes(trim($_REQUEST['txtInvHire_'.$i]));
			
			$txtHireFrom    	= date('Y-m-d H:i',strtotime($_REQUEST['txtHireFrom_'.$i]));
	        $txtHireTo    	    = date('Y-m-d H:i',strtotime($_REQUEST['txtHireTo_'.$i]));


			// echo $txtRandom;

			// die();

			$sql2 = "insert into invoice_hire_slave8 (INVOICEID, RANDOMID, UTILISED_DAYS, HIRE_AMT, HIRE_FROM, HIRE_TO) values ('".$txtInID."', '".$txtRandom."', '".$txtInvDay."', '".$txtInvHire."', '".$txtHireFrom."', '".$txtHireTo."')";
			mysql_query($sql2) or die($sql2);
		}
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into invoice_hire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into invoice_hire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$txtHoldID  = $_REQUEST['txtHoldID'];
		for($i=1;$i<=$txtHoldID;$i++)
		{
			$txtHoldDes	 	  = addslashes(trim($_REQUEST['txtHoldDes_'.$i]));
			$txtHoldDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHoldDesAmt_'.$i]);
			$sql2 = "insert into invoice_hire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtHoldDes."', '".$txtHoldDesAmt."', 'HOLD_CLEANING')";
			mysql_query($sql2);
		}
		
		$txtHireSurveyID  = $_REQUEST['txtHireSurveyID'];
		for($i=1;$i<=$txtHireSurveyID;$i++)
		{
			$txtHireSurveyDes	 	  = addslashes(trim($_REQUEST['txtHireSurveyDes_'.$i]));
			$Chk_Owner_Account  	  = $this->getCheckNullVal($_REQUEST['Chk_Owner_Account_'.$i]);
			$txtHireSurveyDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHireSurveyDesAmt_'.$i]);
			$sql2 = "insert into invoice_hire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY, CHK_OWNER_ACC) values ('".$txtInID."', '".$txtHireSurveyDes."', '".$txtHireSurveyDesAmt."', 'HIRE_SURVEY', '".$this->getCheckNullVal($Chk_Owner_Account)."')";
			mysql_query($sql2);
		}
		
		if($ChkShowOffHire==1)
		{
			$txtOFFID = $_REQUEST['txtOFFID'];
			for($i=1 ; $i<=$txtOFFID ;$i++)
			{
				if($_REQUEST['txtOffHireReason_'.$i] != "")
				{
					if($_REQUEST['txtOffHireFrom_'.$i]!="")
					{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
					else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtOffHireTo_'.$i]!="")
					{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
					else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
					
					$sql3 = "insert into invoice_hire_slave6 (INVOICEID, OFF_REASON, OFF_FROM, OFF_TO, OFF_HIRE_PERCENT, OFF_DAYS, OFF_HIRE, HIRE_RATE) values ('".$txtInID."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHirePercent_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOffHirePerDay_'.$i])."')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
					
					$mysql14 = "select max(INVOICE_SLAVE6ID) as max from invoice_hire_slave6 where INVOICEID='".$txtInID."'";
					$myres14  =  mysql_query($mysql14);
					$myrows14 = mysql_fetch_assoc($myres14);
					$maxid14 = $myrows14['max'];
					
					$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
					for($m=1 ; $m<=$txtDELID ;$m++)
					{
						if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
						{
							$sql15 = "insert into invoice_hire_slave61 (INVOICE_SLAVE6ID, INVOICEID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT) values ('".$maxid14."', '".$txtInID."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."')";
							mysql_query($sql15) or die($sql15);
							mysql_query("commit");
						}
					}
				}
			}
		}
		
		$txtDelbid  = $_REQUEST['txtAddDELID'];
		for($i=1;$i<=$txtDelbid;$i++)
		{
			if($_REQUEST['selDELBunker_'.$i]!='')
			{
				$selDELBunker	 	      = $this->getCheckNullVal($_REQUEST['selDELBunker_'.$i]);
				$txtDelBunkerQty	      = $this->getCheckNullVal($_REQUEST['txtDelBunkerQty_'.$i]);
				$txtDelBunkerPrice	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerPrice_'.$i]);
				$txtDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selDELBunker."', '".$txtDelBunkerQty."', '".$txtDelBunkerPrice."', '".$txtDelBunkerAmt."', 'DEL')";
				mysql_query($sql2);
			}
		}
		
		$txtAddREDELID = $_REQUEST['txtAddREDELID'];
		for($i=1;$i<=$txtAddREDELID;$i++)
		{
			
			if($_REQUEST['selReDELBunker_'.$i]!='')
			{
				$txtReDelBunkerQty	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerQty_'.$i]);
				$selReDELBunker  	      = $this->getCheckNullVal($_REQUEST['selReDELBunker_'.$i]);
				$txtReDelBunkerPrice	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerPrice_'.$i]);
				$txtReDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selReDELBunker."', '".$txtReDelBunkerQty."', '".$txtReDelBunkerPrice."', '".$txtReDelBunkerAmt."', 'REDEL')";
				mysql_query($sql2);
			}
		}
		
		$txtAddOVERCONPID = $_REQUEST['txtAddOVERCONPID'];
		for($i=1;$i<=$txtAddOVERCONPID;$i++)
		{
			if($_REQUEST['selOverConspBunker_'.$i]!='')
			{
				$txtOverConspBunkerQty 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerQty_'.$i]);
				$selOverConspBunker	      = $this->getCheckNullVal($_REQUEST['selOverConspBunker_'.$i]);
				$txtOverConspBunkerPrice  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerPrice_'.$i]);
				$txtOverConspBunkerAmt 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selOverConspBunker."', '".$txtOverConspBunkerQty."', '".$txtOverConspBunkerPrice."', '".$txtOverConspBunkerAmt."', 'OVERCONSP')";
				mysql_query($sql2);
			}
		}
		
		$txtORCID  = $_REQUEST['txtORCID'];
		for($i=1;$i<=$txtORCID;$i++)
		{
		    if(isset($_REQUEST['chkORC_'.$i]))
			{
				$txtORCRandomid	 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCRandomid_'.$i])));
				$txtORCVendorid  	  = addslashes(trim($_REQUEST['txtORCVendorid_'.$i]));
				$txtORCIdentify 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCIdentify_'.$i])));
				$txtORCAmt      	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCAmt_'.$i])));
				
				$sql2 = "insert into invoice_hire_slave5 (INVOICEID, RANDOMID, IDENTITYID, VENDORID, AMOUNT) values ('".$txtInID."', '".$txtORCRandomid."', '".$txtORCIdentify."', '".$txtORCVendorid."', '".$txtORCAmt."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$hddnprevinvid  = $_REQUEST['hddnprevinvid'];
		for($i=1;$i<=$hddnprevinvid;$i++)
		{
		    if(isset($_REQUEST['chkPrevInv_'.$i]))
			{
				$txtPrevInvID	 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtPrevInvID_'.$i])));
				$txtPrevInvIdentify	  = addslashes(trim($_REQUEST['txtPrevInvIdentify_'.$i]));
				$sql2 = "insert into invoice_hire_slave7 (INVOICEID, PINVOICEID, IDENTIFY) values ('".$txtInID."', '".$txtPrevInvID."', '".$txtPrevInvIdentify."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." Hire Statement (".$txtInvNo.") Updated Successfully.");
	}
	
	$this->inactiveUserAlerts('HIRE STATEMENT', $_SESSION['uid'], $invoiceidd);
	
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	$approverarr2 = $this->getUsersWithAuthority('HIRE_STSTMENT_CHK_APP_2');
	$approverarraccount2 = $this->getUsersWithAuthority('HIRE_STSTMENT_CHK_ACC');
	
	$url = './invoice_hire.php?comid='.$_REQUEST['comid'].'&page='.$_REQUEST['page'];
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'HIRE STATEMENT';
	
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($_REQUEST['comid'],"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{
		     if(!empty($approverarraccount2))
			 {
			     $userarray = $approverarraccount2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' Approved '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.')', $invoiceidd);				  
				  }
			 }
		}
	}
	
	
	mysql_query("commit");
	return $msg.','.$comid;  
}


function getO_CType()
{
$state = array( 'Owner' =>'Owner' , 'Charterer' =>'Charterer');
$selIType = @$_REQUEST['selIType'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selIType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getInvoiceStatusList()
{
	$this->funConnect();
	$query = mysql_query("select * from invoice_status_master where STATUS=1 order by NAME ");
	echo '<option value="" >---Select from list---</option>';
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows["IS_ID"];
		 $value= $rows["NAME"];
		 echo '<option value=".$key." ';
		 echo '>'.$value.'</option>';
		}
}


function confirmVesselOpenPositionRecord()
{
	$connect				= $this->funConnect();
 	$openvesselid 				= addslashes(trim($_REQUEST['txttblid']));
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$sql = "select VESSEL_IMO_ID from open_vessel_entry_master where OPENVESSEL_ID='".$openvesselid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	
	$sql1 = "select * from external_vessel_details where EXTERNAL_VESSEL_ID='".$rows['VESSEL_IMO_ID']."'";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	$IMO_NO = $rows1['IMO_NO']; 
	
	$sql2 = "select * from vessel_imo_master where IMO_NO='".$IMO_NO."'"; 
	$res2 = mysql_query($sql2);
	$rec2 = mysql_num_rows($res2);
	if($rec2 == 0)
	{
		
		$sql3 = "insert into vessel_imo_master (VESSEL_NAME, DWT, YEARBUILT, ALLOCATE_STATUS, TRANS_DATE,  MCOMPANYID, DRAFTM, CRANESIZE, GRABSIZE, VESSEL_TYPE, OWNER, BUILDER, HULL_TYPE, EXTERNAL_VESSEL_ID, IMO_NO, LOA, EXT_BREADTH, GRT_NRT, GRAIN, BALE, NOH, NOHA, HATCH_SIZE, CARGO_GEAR, P_I) values ('".$rows1['VESSEL_NAME']."', '".$rows1['DWT']."', '".$rows1['YEARBUILT']."', '0', '".date("Y-m-d",time())."', '".$_SESSION['company']."', '".$rows1['DRAFTM']."', '".$rows1['CRANESIZE']."', '".$rows1['GRABSIZE']."', '".$this->getCheckNullVal($rows1['VESSEL_TYPE'])."', '".$rows1['OWNER']."', '".$this->getCheckNullVal($rows1['BUILDER'])."', '".$this->getCheckNullVal($rows1['HULLTYPE'])."', '".$this->getCheckNullVal($rows1['EXTERNAL_VESSEL_ID'])."', '".$this->getCheckNullVal($rows1['IMO_NO'])."', '".$this->getCheckNullVal($rows1['LOA'])."', '".$this->getCheckNullVal($rows1['EXT_BREADTH'])."', '".$this->getCheckNullVal($rows1['GRT_NRT'])."', '".$this->getCheckNullVal($rows1['GRAIN'])."', '".$this->getCheckNullVal($rows1['BALE'])."', '".$this->getCheckNullVal($rows1['NOH'])."', '".$this->getCheckNullVal($rows1['NOHA'])."', '".$this->getCheckNullVal($rows1['HATCH_SIZE'])."', '".$this->getCheckNullVal($rows1['CARGO_GEAR'])."', '".$this->getCheckNullVal($rows1['P_I'])."')"; 
		
		mysql_query($sql3);
		mysql_query("commit"); 
		
		$mysql = "select max(VESSEL_IMO_ID) as max from vessel_imo_master";
		$myres = mysql_query($mysql);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
		
		$sql4 = "insert into vessel_allocation_master (VESSEL_IMO_ID,TRANS_DATE,MODULE_ID,MCOMPANYID) values ('".$maxid."','".date("Y-m-d",time())."','".$_SESSION['moduleid']."','".$_SESSION['company']."')"; 
		mysql_query($sql4);
		mysql_query("commit");
	}
	else
	{
		$rows2 = mysql_fetch_assoc($res2);
		$maxid = $rows2['VESSEL_IMO_ID'];
	}	
		$sql5 = "update open_vessel_entry_master set SHOW_STATUS=1 ,VESSEL_IMO_ID='".$maxid."' where OPENVESSEL_ID='".$openvesselid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'"; 
		mysql_query($sql5);
		mysql_query("commit");
		return $msg;
}


function getExternalVesselData($id,$field)
{
	$this->funConnect();
	$sql = "select ".$field." from external_vessel_details where EXTERNAL_VESSEL_ID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getUserDetailBaseOnId($uid,$field){
	
	$this->funConnect();
	$sql = "select ".$field." from login where LOGINID=".$uid;
	$res = mysql_query($sql);
	$row = mysql_fetch_assoc($res);
	return $row[$field];
}


function getUserRights($loginid,$moduleid,$linkid)
{
	$connect = $this->funConnect();
	$sql = "SELECT LINK_AUTH FROM user_rights WHERE LOGINID='".$loginid."' and MODULEID='".$moduleid."' and LINKID='".$linkid."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	$arr = $rows['LINK_AUTH'];
	return $arr;
}

function getRedeliveryNotice($portid,$checklistid,$entityname,$serialno)
{
	$connect = $this->funConnect();
	$sql = "select * from checklist_redelivery_notice where PORT='LP' and PORTID='".$portid."' and CHECKLIST_ID='".$checklistid."' and ENTITY_NAME='".$entityname."' and RANDOMID='".$serialno."' ";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	$arr = $rows['ENTITY_VALUE'];
	return $arr;
}

function updateVesselChapterEightMaster()
{
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	$txtCRM  = addslashes(trim($_REQUEST['txtCRM']));
	
	$txtCRMFILE3				= addslashes(trim($_REQUEST['txtCRMFILE']));
	$ExATTACHMENTS   			= $this->getUpload($_FILES['mul_file']);
	$ExATTACHMENTS				= implode(',',$ExATTACHMENTS);	

	if($txtCRMFILE3 != '' && $ExATTACHMENTS != ''){ $ExATTACHMENTS = $txtCRMFILE3.','.$ExATTACHMENTS;}
	else if($txtCRMFILE3 == '' && $ExATTACHMENTS != ''){ $ExATTACHMENTS = $ExATTACHMENTS;}
	else if($txtCRMFILE3 != '' && $ExATTACHMENTS == ''){ $ExATTACHMENTS = $txtCRMFILE3;}


	$txtCRMNAME3				= addslashes(trim($_REQUEST['txtCRMNAME']));
	$ExATTACHMENTS_NAME   		= $this->getUploadName($_FILES['mul_file']);
	$ExATTACHMENTS_NAME			= implode(',',$ExATTACHMENTS_NAME);
	if($txtCRMNAME3 != '' && $ExATTACHMENTS_NAME != ''){ $ExATTACHMENTS_NAME = $txtCRMNAME3.','.$ExATTACHMENTS_NAME;}
	else if($txtCRMNAME3 == '' && $ExATTACHMENTS_NAME != ''){ $ExATTACHMENTS_NAME = $ExATTACHMENTS_NAME;}
	else if($txtCRMNAME3 != '' && $ExATTACHMENTS_NAME == ''){ $ExATTACHMENTS_NAME = $txtCRMNAME3;}	
	
	
	
	
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;
	
	$sql18 = "delete from vessel_master_8 where VESSEL_IMO_ID='".$id."'";
	mysql_query($sql18);
	
	$sql9 = "insert into vessel_master_8 (VESSEL_IMO_ID, GRT, NRT, GRAIN, BALE, CARGO_GEAR, CRANE_SIZE, GRAB, P_I, ATTACHMENT, ATTACHMENT_NAME) values ('".$id."', '".$this->getCheckNullVal(addslashes(trim($_REQUEST['txtGRT'])))."', '".$this->getCheckNullVal(addslashes(trim($_REQUEST['txtNRT'])))."', '".$this->getCheckNullVal(addslashes(trim(number_format($_REQUEST['txtGRAIN_1'],2,'.',''))))."', '".$this->getCheckNullVal(addslashes(trim($_REQUEST['txtBALE_1'])))."', '".$this->getCheckNullVal(addslashes(trim($_REQUEST['txtCARGO_GEAR'])))."', '".$this->getCheckNullVal(addslashes(trim($_REQUEST['txtCRANE_SIZE'])))."', '".$this->getCheckNullVal(addslashes(trim($_REQUEST['txtGRAB'])))."', '".$this->getCheckNullVal(addslashes(trim($_REQUEST['txtPI_1'])))."', '".addslashes(trim($ExATTACHMENTS))."', '".addslashes(trim($ExATTACHMENTS_NAME))."')";
	mysql_query($sql9) or die($sql9);
	
	mysql_query("commit"); 
	return $msg;
}


function getVendorListNewForDisponentOwner($id,$row)
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from vendor_master where STATUS=1 and VENDOR_TYPEID=".$id." and MCOMPANYID='".$_SESSION['company']."' order by NAME ");
	echo '<option value = "" >---Select from list---</option>';
	@$selVendor = @$_REQUEST['txtDisponentOwner_'.$row];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['CODE'];
		 $value = addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
		 echo '<option value="'.$key.'"';
		 if($key == @$selVendor){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}



function getCommercialParameterDataVoyageEstimates($id,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from commercial_parameters_voyage_estimates where FCATMPID='".$id."'";
	$res = mysql_query($sql,$connect);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getCurrencyNameBasedOnID($id)
{
	$connect = $this->funConnect();
	$sql = "select CURRENCY_NAME from country_master where COUNTRYID='".$id."'";
	$res = mysql_query($sql,$connect);
	$rows = mysql_fetch_assoc($res);
	return $rows['CURRENCY_NAME'];
}


function getCurrencyList()
{
	$this->funConnect();
	$currency = array('EURO'=>'Euro (EUR)', 'USD'=>'United States Dollar (USD)', 'AUD'=>'Australian dollar (AUD)', 'GBP'=>'United Kingdom Pound (GBP)', 'INR'=>'Indian Rupee (INR)', 'AED'=>'Emirati Dirham (AED)', 'JPY'=>'Japanese Yen (JPY)','SGD'=>'Singapore Doller (SGD)');
	echo '<option value="">---Select from list---</option>';
	while ($array_cell = each($currency)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo '<option value="'.$key.'">'.$value.'</option>';	
	}
}


function getCheckListPortDataRecordsRecBasedOnComID($comid,$id,$port,$portid,$randomid,$entity_name)
{
	$connect = $this->funConnect();
	$sql 	 = "select ENTITY_VALUE from checklist_loadport where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' and CHECKLIST_ID='".$id."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$randomid."' and ENTITY_NAME='".$entity_name."'";
	$result  = mysql_query($sql) or die($sql);
	$rows    = mysql_fetch_assoc($result);
	return $rows["ENTITY_VALUE"];
}

function getLoadPortArrBasedOnIDComidAndProcessWithoutTBN($comid)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$sql  = "select FROM_PORT, RANDOMID from freight_cost_estimete_slave1 where  FCAID='".$this->getLatestCostSheetID($comid)."' and LOAD_PORT_QTY>0";
	$res = mysql_query($sql);
	while($rows  = mysql_fetch_assoc($res))
	{
		if($this->getPortNameBasedOnID($rows['FROM_PORT']) != "TBN")
		{
			$arr[] = $rows['FROM_PORT'].'###'.$rows['RANDOMID'];
		}
	}
	return $arr;
}


function getCheckListRecordsRecBasedOnComID($comid)
{
	$connect = $this->funConnect();
	$sql     = "select * from check_list where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."'";
	$result  = mysql_query($sql);
	$rec     = mysql_num_rows($result);
	return $rec;
}

function getCheckListRecordsDataBasedOnComID($comid,$field)
{
	$connect = $this->funConnect();
	$sql     = "select ".$field." from check_list where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."'";
	$result  = mysql_query($sql);
	$rows    = mysql_fetch_assoc($result);
	return $rows[$field];
}


function getETARec($comid,$port,$portid,$randomid)
{
	$connect = $this->funConnect();
	if($this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 7 DAYS") != " " || $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 5 DAYS") != " " || $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 3 DAYS") != " " || $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 2 DAYS") != " " || $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 1 DAY") != " ")
	{
		return "Y";
	}
	else
	{
		return "N";
	}
}


function getMaxETADate($comid,$port,$portid,$randomid)
{
	$connect = $this->funConnect();
	if($this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 7 DAYS") != " " || $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 5 DAYS") != " " || $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 3 DAYS") != " " || $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 2 DAYS") != " " || $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 1 DAY") != " ")
	{
		$eta_7_days = strtotime($this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 7 DAYS"));
		$eta_5_days = strtotime($this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 5 DAYS"));
		$eta_3_days = strtotime($this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 3 DAYS"));
		$eta_2_days = strtotime($this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 2 DAYS"));
		$eta_1_days = strtotime($this->getCheckListPortDataRecordsRecBasedOnComID($comid,$this->getCheckListRecordsDataBasedOnComID($comid,"CHECKLIST_ID"),$port,$portid,$randomid,"ETA 1 DAY"));
	
		$max_date = max($eta_7_days,$eta_5_days,$eta_3_days,$eta_2_days,$eta_1_days);
		return date("d M Y H:i",$max_date);
	}
	else
	{
		return "";
	}
}

function getAgentOrCheckListData($comid,$port,$portid,$randomid,$checklistid,$agent_field,$check_list_field)
{
	
	$connect = $this->funConnect();
	$sql 	 = "select ".$agent_field." from sof_slave_5 where LOGIN='AGENT' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$randomid."' and COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' ";
	$res 	 = mysql_query($sql) or die($sql);
	$rec 	 = mysql_num_rows($res);
	//return 1;
	if($rec == 0)
	{
		return $this->getCheckListPortDataRecordsRecBasedOnComID($comid,$checklistid,$port,$portid,$randomid,$check_list_field);
	}
	else
	{
		while($rows = mysql_fetch_assoc($res))
		{
			$value = $rows[$agent_field];
		}
		return $value;
	}
}


function getDisPortArrBasedOnIDComidAndProcessWithoutTBN($comid)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$sql1 = "select TO_PORT, RANDOMID from freight_cost_estimete_slave1 where FCAID='".$this->getLatestCostSheetID($comid)."' and DISC_PORT_QTY>0";
	$res1 = mysql_query($sql1);
	while($rows1  = mysql_fetch_assoc($res1))
	{
		if($this->getPortNameBasedOnID($rows1['TO_PORT']) != "TBN")
		{
			$arr[] = $rows1['TO_PORT'].'###'.$rows1['RANDOMID'];
		}
	}
	return $arr;
}



function getVoyageFinancialsEstimatesList()
{
	$connect = $this->funConnect();
	$sql1 = "select * from freight_cost_analysis_tmp_master order by FCATMPID desc";
	$res1 = mysql_query($sql1);
	while($rows1 = mysql_fetch_assoc($res1))
	{
		echo "<option value='".$rows1['FCATMPID']."'";
		echo ">".$rows1['ESTIMATION_NO']." ( ".$this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"VESSEL_NAME")." ) </option>";	
	}
}

function getFreightCostEstimationTempleteData($id,$field)
{
	$connect = $this->funConnect();
	$sql="SELECT ".$field." FROM freight_cost_analysis_tmp_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FCATMPID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getFCEPortNameBasedOnID($id,$table,$field)
{
	$connect = $this->funConnect();
	$sql1 = "select ".$field." from ".$table." where FCATMPID='".$id."'";
	$res1 = mysql_query($sql1,$connect);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$arr[] = $this->getPortNameBasedOnID($rows1[$field]);
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function getFoConspDataBasedOnID($id,$field)
{
	$connect = $this->funConnect();
	$sql1 = "select BUNKERGRADEID,".$field." from fca_tci_tmp_bunker where FCATMPID='".$id."'";
	$res1 = mysql_query($sql1,$connect);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$str = substr($this->getBunkerGradeBasedOnID($rows1['BUNKERGRADEID']),0,3);
			if($str == "IFO")
			{
				$arr[] = $rows1[$field];
			}
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function getDoConspDataBasedOnID($id,$field)
{
	$connect = $this->funConnect();
	$sql1 = "select BUNKERGRADEID,".$field." from fca_tci_tmp_bunker where FCATMPID='".$id."'";
	$res1 = mysql_query($sql1,$connect);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$str = substr($this->getBunkerGradeBasedOnID($rows1['BUNKERGRADEID']),0,3);
			if($str == "MDO" || $str == "MGO")
			{
				$arr[] = $rows1[$field];
			}
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function getOSCSumTMP($fca_tmpid)
{
	$this->funConnect();
	$sql = "select sum(ABSOLUTE) as sum from fca_tci_tmp_other_shipping_cost where FCATMPID='".$fca_tmpid."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec > 0)
	{
		$rows = mysql_fetch_assoc($res);
		return $rows['sum'];
	}
	else
	{
		return 0;
	}
}

function getFCEPortDataBasedOnID($id,$table,$field)
{
	$connect = $this->funConnect();
	$sql1 = "select ".$field." from ".$table." where FCATMPID='".$id."'";
	$res1 = mysql_query($sql1,$connect);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$arr[] = $rows1[$field];
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function getOMCSumTMP($fca_tmpid)
{
	$this->funConnect();
	$sql = "select sum(AMOUNT) as sum from fca_tci_tmp_other_misc_cost where FCATMPID='".$fca_tmpid."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec > 0)
	{
		$rows = mysql_fetch_assoc($res);
		return $rows['sum'];
	}
	else
	{
		return 0;
	}
}


function getLoadPortAndDischargePortAgentArrBasedOnMappingidAndProcesid($mappingid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$status  = $this->getFreightEstimationStatus($mappingid,$cost_sheet_id);
	if($status  == 1)
	{
		$sql  = "select LOADPORTID, VENDORID from fca_tci_portcosts where  FCAID='".$this->getFCAIDBasedOnid($mappingid,$cost_sheet_id)."'";
		$res = mysql_query($sql);
		while($rows  = mysql_fetch_assoc($res))
		{
			$arr[] = $rows['VENDORID'];
		}
		
		$sql1 = "select LOADPORTID, VENDORID from fca_tci_portcosts where  FCAID='".$this->getFCAIDBasedOnid($mappingid,$cost_sheet_id)."'";
		$res1 = mysql_query($sql1);
		while($rows1  = mysql_fetch_assoc($res1))
		{
			$arr[] = $rows1['VENDORID'];
		}
		
		
	}
	else if($status  == 2)
	{
		$sql  = "select LOADPORTID, VENDORID from fca_tci_portcosts where  FCAID='".$this->getFCAIDBasedOnid($mappingid,$cost_sheet_id)."'";
		$res = mysql_query($sql);
		while($rows  = mysql_fetch_assoc($res))
		{
			$arr[] = $rows['VENDORID'];
		}
		
		$sql1 = "select LOADPORTID, VENDORID from fca_tci_portcosts where  FCAID='".$this->getFCAIDBasedOnid($mappingid,$cost_sheet_id)."'";
		$res1 = mysql_query($sql1);
		while($rows1  = mysql_fetch_assoc($res1))
		{
			$arr[] = $rows1['VENDORID'];
		}
	}
	return $arr;
}


function getLayTimeValuesBasedOnComID($comid,$portid,$port_type,$txtSerialNo)
{
	$this->funConnect();
	
	$num = $sum1 = $sum2 = 0;
	$sql1 = "select * from laytime_master where COMID='".$comid."' and PORT='".$port_type."' and PORTID='".$portid."' and SUBMITID=5 and RANDOMID='".$txtSerialNo."' and REVERSIBLE!=1";
	$res1 = mysql_query($sql1);
	$rec1 = mysql_num_rows($res1);
	$sql = "select sum(TTL_DEMURRAGE) as sum1, sum(TTL_DESPATCH) as sum2 from laytime_master where COMID='".$comid."' and PORT='".$port_type."' and PORTID='".$portid."' and SUBMITID=5 and RANDOMID='".$txtSerialNo."' and REVERSIBLE!=1";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec1 > 0)
	{
		$rows = mysql_fetch_assoc($res);
		return $rec1."@#@".number_format($rows['sum1'],2,'.','')."@#@-".number_format($rows['sum2'],2,'.','');
	}
	else
	{
		return $rec1."@#@".$rows['sum1']."@#@".$rows['sum2'];
	}
}



function getLayTimeValuesBasedOnComID1($comid,$portid,$port_type,$txtSerialNo)
{
	$this->funConnect();
	
	$num = $sum1 = $sum2 = 0;//LAYTIME_ID, COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, LOADED_QTY, LOADED_RATE, LAYTIME_ALLOWED, ACTUAL_LAYTIME, TIME_TO_DEMURRAGE, TIME_TO_DESPATCH, DEMURRAGE_RATE, DESPATCH_RATE, SOF_LOADPORTID, ENTITY, TTL_DEMURRAGE, TTL_DESPATCH, VENDOR, SUBMITID, APPLICABLE_STATUS, METHOD, QTY, REMARKS, LOADED_TERMS, NOR_TERMS, TURN_TIME, TT_TERMS, LAYCAN, NS_1, NS_2, NS_3, NS_4, NS_5, NS_6, NS_7, NS_8, ACTUAL_LAYTIME_INSERT, REVERSIBLE, FCA_SERIALID, RANDOMID
	$sql1 = "select * from laytime_master where COMID='".$comid."' and PORT='".$port_type."' and PORTID='".$portid."' and RANDOMID='".$txtSerialNo."'";
	$res1 = mysql_query($sql1);
	$rec1 = mysql_num_rows($res1);
	$sql = "select TTL_DEMURRAGE as sum1, TTL_DESPATCH as sum2, DEMURRAGE_RATE, DESPATCH_RATE from laytime_master where COMID='".$comid."' and PORT='".$port_type."' and PORTID='".$portid."' and RANDOMID='".$txtSerialNo."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec1 > 0)
	{
		$rows = mysql_fetch_assoc($res);
		return $rec1."@#@".number_format($rows['sum1'],2,'.','')."@#@-".number_format($rows['sum2'],2,'.','')."@#@".number_format($rows['DEMURRAGE_RATE'],2,'.','')."@#@".number_format($rows['DESPATCH_RATE'],2,'.','');
	}
	else
	{
		return $rec1."@#@0@#@0@#@0@#@0";
	}
}



function updatecheckListChartererPniByVendorListNewForCOATe($saveid)
{
	$this->funConnect();
	$query = "select * from vendor_master where STATUS=1 and VENDOR_TYPEID='17' and CODE='".$saveid."' and MCOMPANYID='".$_SESSION['company']."'";
	$res 	= mysql_query($query);
	$rows  	= mysql_fetch_assoc($res);
	return $rows['NAME']."(".$rows['CODE'].")";
}


function getVoyageFinancialsNameList($mappingid)
{
	$connect = $this->funConnect();
	$sql = "select * from freight_cost_analysis_master where MAPPINGID='".$mappingid."' ";
	$res = mysql_query($sql);
	while($rows = mysql_fetch_assoc($res))
	{
		echo "<option value='".$rows['FCAID']."'";
		echo ">".$rows['ESTIMATION_NO']."  </option>";	
	}
}

function getFreightCostEstimationData($id,$field)
{
	$connect = $this->funConnect();
	$sql="SELECT ".$field." FROM freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FCAID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getFCECostSheetPortNameBasedOnID($id,$table,$field)
{
	$connect = $this->funConnect();
	$sql1 = "select ".$field." from ".$table." where FCAID='".$id."'";
	$res1 = mysql_query($sql1,$connect);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$arr[] = $this->getPortNameBasedOnID($rows1[$field]);
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function getFCECostSheetPortDataBasedOnID($id,$table,$field)
{
	$connect = $this->funConnect();
	$sql1 = "select ".$field." from ".$table." where FCAID='".$id."'";
	$res1 = mysql_query($sql1,$connect);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$arr[] = $rows1[$field];
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function getDoConspCostSheetDataBasedOnID($id,$field)
{
	$connect = $this->funConnect();
	$sql1 = "select BUNKERGRADEID,".$field." from fca_tci_bunker where FCAID='".$id."'";
	$res1 = mysql_query($sql1,$connect);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$str = substr($this->getBunkerGradeBasedOnID($rows1['BUNKERGRADEID']),0,3);
			if($str == "MDO" || $str == "MGO")
			{
				$arr[] = $rows1[$field];
			}
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function getFoConspCostSheetDataBasedOnID($id,$field)
{
	$connect = $this->funConnect();
	$sql1 = "select BUNKERGRADEID,".$field." from fca_tci_bunker where FCAID='".$id."'";
	$res1 = mysql_query($sql1,$connect);
	$rec1 = mysql_num_rows($res1);
	if($rec1 > 0)
	{
		while($rows1 = mysql_fetch_assoc($res1))
		{
			$str = substr($this->getBunkerGradeBasedOnID($rows1['BUNKERGRADEID']),0,3);
			if($str == "IFO")
			{
				$arr[] = $rows1[$field];
			}
		}
		return implode(" , ",$arr);
	}
	else
	{
		return "";
	}
}

function getOMCSumCostSheet($fca_tmpid)
{
	$this->funConnect();
	$sql = "select sum(AMOUNT) as sum from fca_tci_other_misc_cost where FCAID='".$fca_tmpid."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec > 0)
	{
		$rows = mysql_fetch_assoc($res);
		return $rows['sum'];
	}
	else
	{
		return 0;
	}
}

function getBAFDataBasedOnID($comid,$field)
{
	$connect = $this->funConnect();
	$sql = "select ".$field." from baf_master where COMID='".$comid."'";
	$res = mysql_query($sql,$connect);
	$rec = mysql_num_rows($res);
    $rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function updateNewBAFDetails()
{
	$connect 		= $this->funConnect();
	$mappingid      = $_REQUEST['mappingid'];
	$bafid      	= $_REQUEST['bafid'];
	$apply_baf     	= $_REQUEST['checkApplyBAF'];
	$applicable_baf = $_REQUEST['txtApplicableBAF'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	if($apply_baf == 1)
	{
		$sql = "update baf_master set APPLY_BAF='".$apply_baf."',APPLICABLE_BAF='".$applicable_baf."' where MAPPINGID='".$mappingid."' and BAFID='".$bafid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	}
	else
	{
		$sql = "update baf_master set APPLICABLE_BAF='".$applicable_baf."' where MAPPINGID='".$mappingid."' and BAFID='".$bafid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	}
	mysql_query($sql,$connect);
	mysql_query("commit");
	
	$delquery = "delete from baf_slave3 where BAFID='".$bafid."'";
	mysql_query($delquery);
	mysql_query("commit");
	
	$sql2 = "select * from baf_slave1 where BAFID = ".$bafid;
	$res2 = mysql_query($sql2);
	$rec2 = mysql_num_rows($res2);
	$i=1;
	while($rows2 = mysql_fetch_assoc($res2))
	{
		$sql3 = "select * from baf_slave2 where BAFID = ".$bafid;
		$res3 = mysql_query($sql3);
		$rec3 = mysql_num_rows($res3);
		$j=1;
		while($rows3 = mysql_fetch_assoc($res3))
		{
			if($_REQUEST['checkApprovedbox_'.$i.'_'.$j])
			{
				$sql3 = "insert into baf_slave3 (BAFID, BAF_SLAVE1_ID, BAF_SLAVE2_ID, CHECK_STATUS, DATE, AMOUNT) values ('".$bafid."','".$rows2['BAF_SLAVE1_ID']."','".$rows3['BAF_SLAVE2_ID']."','".$_REQUEST['checkApprovedbox_'.$i.'_'.$j]."','".date("Y-m-d",strtotime($_REQUEST['txtADate_'.$i.'_'.$j]))."','".$_REQUEST['txtARateIFO_'.$i.'_'.$j]."')";
				mysql_query($sql3,$connect);
				mysql_query("commit");
			}
			$j++;
		}
		$i++;
	}
	return $msg; 
}


function deleteBAFDetails()
{
	$connect 		= $this->funConnect();
	$mappingid      = $_REQUEST['mappingid'];
	$bafid      	= $_REQUEST['bafid'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$delquery  = "delete from baf_slave1 where BAFID='".$bafid."'";
	$delquery1 = "delete from baf_slave2 where BAFID='".$bafid."'";
	$delquery2 = "delete from baf_slave3 where BAFID='".$bafid."'";
	$delquery3 = "delete from baf_master where BAFID='".$bafid."'";
	mysql_query($delquery);
	mysql_query($delquery1);
	mysql_query($delquery2);
	mysql_query($delquery3);
	mysql_query("commit");
	
	return $msg;
}


function getBAF_slave3Data($bafid,$baf_slave1,$baf_slave2,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from baf_slave3 where BAFID='".$bafid."' and BAF_SLAVE1_ID='".$baf_slave1."' and BAF_SLAVE2_ID='".$baf_slave2."' ";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function viewBAFCalculationRecords($mappingid)
{
	$connect = $this->funConnect();
	$query 	 = "select * from baf_master where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	$result  = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['BAFID'];
		$this->var_2 = $rows['BUNKER_PRICE'];
		$this->var_3 = $rows['BAF_TERMS'];
		$this->var_4 = $rows['BAF_USD'];
		$this->var_5 = $rows['TOTAL_BL_QTY'];	
		$this->var_6 = $rows['APPLY_BAF'];	
		$this->var_7 = $rows['APPLICABLE_BAF'];		
	}
}


function insertBAFDetails()
{
	$connect = $this->funConnect();
	$mappingid          = $_REQUEST['mappingid'];
	$bunker_price       = $_REQUEST['txtBPrice'];
	$baf_terms          = $_REQUEST['txtBAFTerms'];
	$baf_usd            = $_REQUEST['txtIncDec'];
	$total_bl_qty       = $_REQUEST['txtTotalBLQty'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into baf_master (BUNKER_PRICE,BAF_TERMS,BAF_USD,MODULEID,MCOMPANYID,MAPPINGID,TOTAL_BL_QTY) values ('".$bunker_price."','".$baf_terms."','".$baf_usd."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$mappingid."','".$total_bl_qty."')";
	mysql_query($sql,$connect);
	mysql_query("commit");
	
	$mysql 	= "select max(BAFID) as max from baf_master";
	$myres 	= mysql_query($mysql);
	$myrows = mysql_fetch_assoc($myres);
	$max	= $myrows['max'];
	$bl_id  = $_REQUEST['txtBLID'];
	
	//insert query here.............
	for($i=1 ; $i<=$bl_id ;$i++)
	{
		if($_REQUEST['selPort_'.$i] != "" && $_REQUEST['txtBLQty_'.$i] != "" && $_REQUEST['txtBLDate_'.$i] != "")
		{
			$sql1 = "insert into baf_slave1 (BAFID,PORT_CODE,BL_QTY,BL_DATE,REMARKS) values ('".$max."','".$_REQUEST['selPort_'.$i]."','".$_REQUEST['txtBLQty_'.$i]."','".date("Y-m-d",strtotime($_REQUEST['txtBLDate_'.$i]))."','".$_REQUEST['txtRemarks_'.$i]."')";
			mysql_query($sql1,$connect);
			mysql_query("commit");
		}
	}
	
	$date_id       = $_REQUEST['txtDateID'];	
	//insert query here.............
	for($i=1 ; $i<=$date_id ;$i++)
	{
		if($_REQUEST['txtDate_'.$i] != "" && $_REQUEST['txtDay_'.$i] != "" && $_REQUEST['txtRateIFO_'.$i] != "")
		{
			$sql2 = "insert into baf_slave2 (BAFID,DATE,DAY,RATE_IFO,REMARKS) values ('".$max."','".date("Y-m-d",strtotime($_REQUEST['txtDate_'.$i]))."','".$_REQUEST['txtDay_'.$i]."','".$_REQUEST['txtRateIFO_'.$i]."','".$_REQUEST['txtDRemarks_'.$i]."')";
			mysql_query($sql2,$connect);
			mysql_query("commit");
		}
	}
	
	return $msg; 
}


function getBAFCalculationRec($mappingid)
{
	$connect = $this->funConnect();
	$sql 	 = "select * from baf_master where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	$res 	 = mysql_query($sql);
	$rec 	 = mysql_num_rows($res);
	return $rec;
}

function getCOANumberDataBasedOnID($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from coa_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COAID='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}


function insertProfitHeadDetails()
{	
	//echo '<pre>';print_r($_POST);die;
	
	$connect 			= $this->funConnect();
	$comid              = $_REQUEST['comid'];
	
	$txtfreightCostIn	= addslashes(trim($_REQUEST['txtfreightCostIn']));
	$txtBrkCommCostIn	= addslashes(trim($_REQUEST['txtBrkCommCostIn']));
	$txtFreightVendor	= addslashes(trim($_REQUEST['txtFreightVendor']));
	
	$txtfreightCostOut	= addslashes(trim($_REQUEST['txtfreightCostOut']));
	$txtBrkCommCostOut	= addslashes(trim($_REQUEST['txtBrkCommCostOut']));
	$txtBrkCommVendor	= addslashes(trim($_REQUEST['txtBrkCommVendor']));
	
	$txttotalCostIn		= addslashes(trim($_REQUEST['txttotalCostIn']));
	$txttotalCostOut	= addslashes(trim($_REQUEST['txttotalCostOut']));
	$txttotalDiff 		= addslashes(trim($_REQUEST['txttotalDiff']));
	$sheetid	 		= addslashes(trim($_REQUEST['sheetid']));
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "delete from profit_head_master where  MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' and SHEET_NO='".$sheetid."'";
	mysql_query($sql1)or die($sql1);
	mysql_query("commit");
	//insert query here.............
	$txtFreightNum = $_REQUEST['txtFreightNum'];
	for($i=1;$i<=$txtFreightNum;$i++)
	{
		$fdiff = $_REQUEST['txtfreightCostIn_'.$i] - $_REQUEST['txtfreightCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtfreightCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtfreightCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtFreightVendor_'.$i]."', 'FREIGHT', '".$this->getCheckNullVal($fdiff)."', '".$i."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	$bdiff = $txtBrkCommCostIn - $txtBrkCommCostOut;
	$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE) values ('".$this->getCheckNullVal($txtBrkCommCostIn)."','".$this->getCheckNullVal($txtBrkCommCostOut)."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$txtBrkCommVendor."', 'BROKERAGE', '".$this->getCheckNullVal($bdiff)."')";

	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$bunker_nettid = $_REQUEST['txtbunker_nettid'];
	for($i=1;$i<=$bunker_nettid;$i++)
	{
	    $bndiff = $_REQUEST['txtbunkerSupplyCostIn_'.$i] - $_REQUEST['txtbunkerSupplyCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtbunkerSupplyCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtbunkerSupplyCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtbunkerSupplyVendor_'.$i]."', 'BUNKERNETT', '".$this->getCheckNullVal($bndiff)."','".$this->getCheckNullVal($_REQUEST['txtbunker_nett_supid_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	$orc_id = $_REQUEST['txtORC_id'];
	for($i=1;$i<=$orc_id;$i++)
	{
		$orcdiff = $_REQUEST['txtORCAmtCostIn_'.$i] - $_REQUEST['txtORCAmtCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtORCAmtCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtORCAmtCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtORCAmtVendor_'.$i]."', 'OWNERRELATED', '".$this->getCheckNullVal($orcdiff)."','".$this->getCheckNullVal($_REQUEST['txtownercost_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	$cc_id = $_REQUEST['txtCC_id'];
	for($i=1;$i<=$cc_id;$i++)
	{
		$ccdiff = $_REQUEST['txtCCCostIn_'.$i] - $_REQUEST['txtCCCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtCCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCCCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtCCCostVendor_'.$i]."', 'CHARTERER', '".$this->getCheckNullVal($ccdiff)."','".$this->getCheckNullVal($_REQUEST['txtCharterCost_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	for($i=1; $i<= $_REQUEST['load_portID']; $i++)
	{
		
		$lpdiff = $_REQUEST['txtLPOSCCostIn_'.$i] - $_REQUEST['txtLPOSCCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtLPOSCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtLPOSCCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtLPOSCCostVendor_'.$i]."', 'LPCOST', '".$this->getCheckNullVal($lpdiff)."','".$this->getCheckNullVal($_REQUEST['txtLoadPortid_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	for($i=1; $i<= $_REQUEST['dis_portID']; $i++)
	{  
		$dpdiff = $_REQUEST['txtDPOSCCostIn_'.$i] - $_REQUEST['txtDPOSCCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtDPOSCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDPOSCCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtDPOSCCostVendor_'.$i]."', 'DPCOST', '".$this->getCheckNullVal($dpdiff)."','".$this->getCheckNullVal($_REQUEST['txtDischargePortid_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	for($i=1; $i<= $_REQUEST['transit_portID']; $i++)
	{
		$tpdiff = $_REQUEST['txtTPOSCCostIn_'.$i] - $_REQUEST['txtTPOSCCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtTPOSCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTPOSCCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtTPOSCCostVendor_'.$i]."', 'TPCOST', '".$this->getCheckNullVal($tpdiff)."','".$this->getCheckNullVal($_REQUEST['txtTransPortid_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	
	for($i=1; $i<= $_REQUEST['load_portID']; $i++)
	{
		
		$dlpdiff = $_REQUEST['txtDDSOLPCommCostIn_'.$i] - $_REQUEST['txtDDSOLPCommCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtDDSOLPCommCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDDSOLPCommCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtDDSOLPVendor_'.$i]."', 'DLPCOST', '".$this->getCheckNullVal($dlpdiff)."','".$this->getCheckNullVal($_REQUEST['txtDDSPLPPortid_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	for($i=1; $i<= $_REQUEST['dis_portID']; $i++)
	{  
		$ddpdiff = $_REQUEST['txtDDSODPCommCostIn_'.$i] - $_REQUEST['txtDDSODPCommCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtDDSODPCommCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDDSODPCommCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtDDSODPVendor_'.$i]."', 'DDPCOST', '".$this->getCheckNullVal($ddpdiff)."','".$this->getCheckNullVal($_REQUEST['txtDDSPDPPortid_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	$omi_id = $_REQUEST['txtAOMC_id'];
	for($i=1;$i<=$omi_id;$i++)
	{
		$ompdiff = $_REQUEST['txtOMCCostIn_'.$i] - $_REQUEST['txtOMCCostOut_'.$i];
		$sql = "insert into profit_head_master (COSTIN, COSTOUT, MODULEID, MCOMPANYID, COMID, SHEET_NO, VENDORID, IDENTIFY, DIFFERENCE, IDENTIFY_ID) values ('".$this->getCheckNullVal($_REQUEST['txtOMCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOMCCostOut_'.$i])."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$comid."','".$sheetid."', '".$_REQUEST['txtOMCCostVendor_'.$i]."', 'OTHERMISC', '".$this->getCheckNullVal($ompdiff)."','".$this->getCheckNullVal($_REQUEST['txtOMCost_'.$i])."')";
		mysql_query($sql)or die($sql);
		mysql_query("commit");
	}
	
	return $msg; 
}



function getHeadWiseProfitdata($field,$sheetid,$comid,$identify,$ident_id)
{
	$this->funConnect();
	$sql = "select ".$field." from profit_head_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and SHEET_NO='".$sheetid."' and IDENTIFY='".$identify."'";
	if($ident_id!="")
	{
	  $sql.= " and IDENTIFY_ID='".$ident_id."'";
	}
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getHeadWiseProfitdatabasedOnTable($id,$table,$field,$getfield,$bunkernetid)
{
	$this->funConnect();
	$sql = "select ".$field." from ".$table." where PHID='".$id."' and ".$getfield."='".$bunkernetid."'"; 
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getHeadWiseProfitdatabasedOnTableAndPort($id,$table,$field,$port,$getfield,$portid)
{
	$this->funConnect();
	$sql = "select ".$field." from ".$table." where PHID='".$id."' and PORT='".$port."' and ".$getfield."='".$portid."'"; 
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function getHeadWiseProfitdatabasedOnTableAndPort_type($id,$table,$field,$port,$getfield,$portid)
{
	$this->funConnect();
	$sql = "select ".$field." from ".$table." where PHID='".$id."' and PORT_TYPE='".$port."' and ".$getfield."='".$portid."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function UpdateProfitHeadDetails()
{	
	//echo '<pre>';print_r($_POST);die;
	
	$connect 			= $this->funConnect();
	$mappingid          = $_REQUEST['mappingid'];
	
	$txtfreightCostIn	= addslashes(trim($_REQUEST['txtfreightCostIn']));
	$txtBrkCommCostIn	= addslashes(trim($_REQUEST['txtBrkCommCostIn']));
	
	$txtfreightCostOut	= addslashes(trim($_REQUEST['txtfreightCostOut']));
	$txtBrkCommCostOut	= addslashes(trim($_REQUEST['txtBrkCommCostOut']));
	
	$txttotalCostIn		= addslashes(trim($_REQUEST['txttotalCostIn']));
	$txttotalCostOut	= addslashes(trim($_REQUEST['txttotalCostOut']));
	$txttotalDiff 		= addslashes(trim($_REQUEST['txttotalDiff']));
	$sheetid	 		= addslashes(trim($_REQUEST['sheetid']));
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//Update query here.............
	
	$query = "select * from profit_head_master where MODULEID='".$_SESSION['moduleid']."' and MAPPINGID='".$mappingid."' and MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	$rows 	= mysql_fetch_assoc($result);
	$Ph_id = $rows['PHID']; 
	
	$sql = "update profit_head_master set FNF_COSTIN='".$this->getCheckNullVal($txtfreightCostIn)."',FNF_COSTOUT='".$this->getCheckNullVal($txtfreightCostOut)."',TBC_COSTIN='".$this->getCheckNullVal($txtBrkCommCostIn)."',TBC_COSTOUT='".$this->getCheckNullVal($txtBrkCommCostOut)."',TOTAL_COSTIN='".$this->getCheckNullVal($txttotalCostIn)."',TOTAL_COSTOUT='".$this->getCheckNullVal($txttotalCostOut)."',PROFIT_LOSS='".$this->getCheckNullVal($txttotalDiff)."',SHEET_NO='".$sheetid."'  where PHID='".$Ph_id."'";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$maxid = $Ph_id;
	
	$del_query1 = "delete from  profit_head_bunker_supply_cost where PHID='".$maxid."'";
	$del_query3 = "delete from  profit_head_owner_related_cost where PHID='".$maxid."'";
	$del_query4 = "delete from  profit_head_charterer_cost where PHID='".$maxid."'";
	$del_query5 = "delete from  profit_head_portcosts where PHID='".$maxid."'";
	$del_query6 = "delete from  profit_head_dd_shipowner where PHID='".$maxid."'";
	$del_query7 = "delete from  profit_head_other_misc_cost where PHID='".$maxid."'";
	
	mysql_query($del_query1)or die($del_query1);
	mysql_query("commit");
	mysql_query($del_query3)or die($del_query3);
	mysql_query("commit");
	mysql_query($del_query4)or die($del_query4);
	mysql_query("commit");
	mysql_query($del_query5)or die($del_query5);
	mysql_query("commit");
	mysql_query($del_query6)or die($del_query6);
	mysql_query("commit");
	mysql_query($del_query7)or die($del_query7);
	mysql_query("commit");
	
	$bunker_nettid = $_REQUEST['txtbunker_nettid'];
	for($i=1;$i<=$bunker_nettid;$i++)
	{
		$sql1 = "insert into profit_head_bunker_supply_cost (PHID,BUNKER_SUPPLY_COSTIN,BUNKER_SUPPLY_COSTOUT,BUNKER_NET_ID) values ('".$maxid."' , '".$this->getCheckNullVal($_REQUEST['txtbunkerSupplyCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtbunkerSupplyCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtbunker_nett_supid_'.$i])."')";
		mysql_query($sql1)or die($sql1);
		mysql_query("commit");
	}
	
	$orc_id = $_REQUEST['txtORC_id'];
	for($i=1;$i<=$orc_id;$i++)
	{
		$sql3 = "insert into profit_head_owner_related_cost (PHID,OWNER_RCOSTIN,OWNER_RCOSTOUT,OWRCID) values ('".$maxid."' , '".$this->getCheckNullVal($_REQUEST['txtORCAmtCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtORCAmtCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtownercost_'.$i])."')";
		mysql_query($sql3)or die($sql3);
		mysql_query("commit");
	}
	
	$cc_id = $_REQUEST['txtCC_id'];
	for($i=1;$i<=$cc_id;$i++)
	{
		$sql4 = "insert into profit_head_charterer_cost (PHID,CHARTERER_COSTIN,CHARTERER_COSTOUT,FCA_CCID) values ('".$maxid."' , '".$this->getCheckNullVal($_REQUEST['txtCCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCCCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCharterCost_'.$i])."')";
		mysql_query($sql4)or die($sql4);
		mysql_query("commit");
	}
	
	for($i=1; $i<= $_REQUEST['load_portID']; $i++)
	{
		if(isset($_REQUEST['txtLoadPort_'.$i]))
		{
			$sql5 = "insert into profit_head_portcosts (PHID,PORT,LOADPORTID,COSTIN,COSTOUT,FCA_PORTCOSTID) values ('".$maxid."','Load', '".$_REQUEST['txtLoadPort_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtLPOSCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtLPOSCCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtLoadPortid_'.$i])."')";
			mysql_query($sql5)or die($sql5);
			mysql_query("commit");
			
			$sql6 = "insert into profit_head_dd_shipowner (PHID,PORT_TYPE,LOADPORTID,COSTIN,COSTOUT,FCA_DD_SHIPOWNERID) values ('".$maxid."', 'Load', '".$_REQUEST['txtLoadPort_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtDDSOLPCommCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDDSOLPCommCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDDSPLPPortid_'.$i])."')";
			mysql_query($sql6)or die($sql6);
			mysql_query("commit");
		}
	}
	
	for($i=1; $i<= $_REQUEST['dis_portID']; $i++)
	{  
		if(isset($_REQUEST['txtDisPort_'.$i]))
		{ 
			$sql7 = "insert into profit_head_portcosts (PHID,PORT,LOADPORTID,COSTIN,COSTOUT,FCA_PORTCOSTID) values ('".$maxid."','Discharge' , '".$_REQUEST['txtDisPort_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtDPOSCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDPOSCCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDischargePortid_'.$i])."')";
			mysql_query($sql7)or die($sql7);
			mysql_query("commit");
			
			$sql8 = "insert into profit_head_dd_shipowner (PHID,PORT_TYPE,LOADPORTID,COSTIN,COSTOUT,FCA_DD_SHIPOWNERID) values ('".$maxid."', 'Discharge', '".$_REQUEST['txtDisPort_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtDDSODPCommCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDDSODPCommCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDDSPDPPortid_'.$i])."')";
			mysql_query($sql8)or die($sql8);
			mysql_query("commit");
		}
	}
	
	for($i=1; $i<= $_REQUEST['transit_portID']; $i++)
	{
		if(isset($_REQUEST['txtTLoadPort_'.$i]))
		{
			$sql9 = "insert into profit_head_portcosts (PHID,PORT,LOADPORTID,COSTIN,COSTOUT,FCA_PORTCOSTID) values ('".$maxid."','Transit', '".$_REQUEST['txtTLoadPort_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtTPOSCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTPOSCCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTransPortid_'.$i])."')";
			mysql_query($sql9)or die($sql9);
			mysql_query("commit");
		}
	}
	
	$omi_id = $_REQUEST['txtAOMC_id'];
	for($i=1;$i<=$omi_id;$i++)
	{
		$sql10 = "insert into profit_head_other_misc_cost (PHID,OTHER_MCOSTIN,OTHER_MCOSTOUT,FCA_OMCID) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtOMCCostIn_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOMCCostOut_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOMCost_'.$i])."')";
		mysql_query($sql10)or die($sql10);
		mysql_query("commit");
	}
	
	return $msg; 
}



function displayHireInvioceListList($comid,$page)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="invoice_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="15%">Invoice Type</th>';
	echo '<th align="left" valign="middle" width="15%">Invoice No.</th>';
	echo '<th align="left" valign="middle" width="15%">Invoice Date</th>';
	echo '<th align="left" valign="middle" width="15%">Release Days</th>';
	echo '<th align="center" valign="middle" width="11%">Invoice Amount</th>';
	echo '<th align="center" valign="middle" width="11%" >Paid Payment</th>';
	echo '<th align="center" valign="middle" width="7%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from invoice_hire_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' order by INVOICEID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody id="tbody">';		
		echo '</tbody>';
	}
	else{
	echo '<tbody id="tbody">';
		while($rows = mysql_fetch_assoc($res))
		{
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['INVOICE_TYPE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['INVOICE_NO'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.date('d-m-Y',strtotime($rows['INVOICE_DATE'])).'</td>';
			echo '<td align="center" valign="middle" class="input-text">'.$rows['RELEASE_HIRE_DAYS'].'</td>';
			echo '<td align="center" valign="middle" class="input-text">'.$rows['BALANCE_TO_OWNER'].'</td>';
			echo '<td align="center" valign="middle" class="input-text">';
			if($rows['STATUS']==2)
			{
			    echo '<a href="#Payment" title="Payment Paid" class="btn btn-default btn-sm" data-toggle="modal" data-target="#compose-modal" onClick="openWin('.$rows['INVOICEID'].');">Payment Paid</a>';	
		    }
			echo '</td>';
			if($rows['STATUS']<2)
			{
			    echo '<td align="center" valign="middle" class="input-text"><a href="invoice_hire.php?id='.$comid.'&page='.$page.'" title="Edit Details" ><i class="fa fa-edit"></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#Delete" onclick="getDelete('.$rows['INVOICEID'].');" ><i class="fa fa-times" style="color:red;"></i></td>';	
		    }
			else
			{
			    echo '<td align="center" valign="middle" class="input-text"><a href="view_invoice_hire.php?id='.$comid.'&page='.$page.'&invoiceid='.$rows['INVOICEID'].'" title="View Details" ><i class="fa fa-file-text"></i></a></td>';		
			}
			echo '</tr>';
			$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function deleteHireInvoiceRecords()
{
	$connect						= $this->funConnect();
	$id 						    = addslashes(trim($_REQUEST['txtDEL_ID']));
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 3;
	
	$sqlsel = "select * from invoice_hire_master where INVOICEID='".$id."'";
	$ressel = mysql_query($sqlsel);
	$rowssel = mysql_fetch_assoc($ressel);
	$this->saveRecentWork($rowssel['INVOICE_TYPE']." Hire Statement (".$rowssel['INVOICE_NO'].") deleted Successfully.");

	$sql = "delete from invoice_hire_master where INVOICEID='".$id."'";
	$sql1 = "delete from invoice_hire_slave1 where INVOICEID='".$id."'";
	$sql2 = "delete from invoice_hire_slave2 where INVOICEID='".$id."'";
	$sql3 = "delete from invoice_hire_slave3 where INVOICEID='".$id."'";
	$sql4 = "delete from invoice_hire_slave4 where INVOICEID='".$id."'";
	$sql5 = "delete from invoice_hire_slave5 where INVOICEID='".$id."'";
	$sql6 = "delete from invoice_hire_slave6 where INVOICEID='".$id."'";
	$sql7 = "delete from invoice_hire_slave61 where INVOICEID='".$id."'";
	$sql8 = "delete from invoice_hire_slave7 where INVOICEID='".$id."'";
	$sql9 = "delete from invoice_hire_slave8 where INVOICEID='".$id."'";
	mysql_query($sql);
	mysql_query($sql1);
	mysql_query($sql2);
	mysql_query($sql3);
	mysql_query($sql4);
	mysql_query($sql5);
	mysql_query($sql6);
	mysql_query($sql7);
	mysql_query($sql8);
	mysql_query($sql9);
	mysql_query("commit"); 
	return $msg;
}



function insertPICLUBDecelarationDetails()
{
	$connect 			    = $this->funConnect();	
	$comid    			    = addslashes(trim($_REQUEST['comid']));
	
	$selPICover 			= addslashes(trim($_REQUEST['selPICover']));
	$txtChartererParty 		= addslashes(trim($_REQUEST['txtChartererParty']));
	$txtDateFrom	        = addslashes(trim($_REQUEST['txtDateFrom']));
	$txtDays    	 		= $_REQUEST['txtDays'];
	$txtSheet_no    	 	= $_REQUEST['txtSheet_no'];
	$txtRemarks 			= addslashes(trim($_REQUEST['txtRemarks']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$qsql = "delete from piclub_declaration where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and SHEET_NO = '".$txtSheet_no."'";
	$qres = mysql_query($qsql) or die($qsql);
	
	$sql = "insert into piclub_declaration (MCOMPANYID, MODULEID, COMID, SHEET_NO, CHARTERER_PARTY, DATE_FROM, DAYS, REMARKS) values ('".$_SESSION['company']."', '".$_SESSION['moduleid']."', '".$comid."', '".$txtSheet_no."', '".$txtChartererParty."', '".$txtDateFrom."', '".$txtDays."', '".$txtRemarks."')";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	return $msg;  
}


function getMessageNumberForFreightInvoice($vessel)
{
  $this->funConnect();
	
	$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM freight_invoice_master where 1=1 ";
	//echo $query;
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['MESSAGE_NO'];
	if($rows['MESSAGE_NO'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode =strtoupper($vessel).'/INV/'.$empcode.'/'.date("Y",time());//INNER if ends here.
		}//if ends here.
	else
		{
			$empcode= strtoupper($vessel).'/INV/001/2014';
		}
	}//WHILE ends here.BW/DM/001/2014
	
return $empcode;
}

function insertFreightInvoiceDetails()
{
	$connect 			= $this->funConnect();	
	$comid 				= addslashes(trim($_REQUEST['comid']));
	$name 				= addslashes(trim($_REQUEST['name']));
	$cargoid            = addslashes(trim($_REQUEST['cargoid']));
	$randomid           = addslashes(trim($_REQUEST['randomid']));
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtDNote	 		= addslashes(trim($_REQUEST['txtDNote']));
	$txtInvoiceid       = addslashes(trim($_REQUEST['txtInvoiceid']));
	
	$txtDNote_1	 		= explode("/",$_REQUEST['txtDNote']);
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtFCAID	 		= addslashes(trim($_REQUEST['txtFCAID']));

	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtDueDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	
	$txtGrossFreight	= addslashes(trim($_REQUEST['txtGrossFreight']));
	$txtBrokerage	 	= addslashes(trim($_REQUEST['txtBrokerage']));
	$txtBrokerageAmt    = addslashes(trim($_REQUEST['txtBrokerageAmt']));
	$txtNetFreight	 	= addslashes(trim($_REQUEST['txtNetFreight']));
	$txtTO	 	        = addslashes(trim($_REQUEST['txtTO']));
	$txtNet	 		    = addslashes(trim($_REQUEST['txtNet']));
	$txtFinalNetFreight	= addslashes(trim($_REQUEST['txtFinalNetFreight']));
	$txtNet_Name	 	= addslashes(trim($_REQUEST['txtNet_Name']));
	
	$selNOB	 		    = addslashes(trim($_REQUEST['selNOB']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	$txtQty             = $_REQUEST['txtQty'];
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtFreightAmtLocal = addslashes(trim($_REQUEST['txtFreightAmtLocal']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	
	$txtAddComm         = addslashes(trim($_REQUEST['txtAddComm']));
	$txtAddCommAmt	 	= addslashes(trim($_REQUEST['txtAddCommAmt']));
	$txtNetAmtPayable	= addslashes(trim($_REQUEST['txtNetAmtPayable']));
	$txtDNote1			= addslashes(trim($_REQUEST['txtDNote1']));
	
	$rdoTaxApplicable         = addslashes(trim($_REQUEST['rdoTaxApplicable']));
	$rdoGSTVAT                = addslashes(trim($_REQUEST['rdoGSTVAT']));
	$txtSGST                  = addslashes(trim($_REQUEST['txtSGST']));
	$txtSGST_Amount           = addslashes(trim($_REQUEST['txtSGST_Amount']));
	$txtCGST                  = addslashes(trim($_REQUEST['txtCGST']));
	$txtCGST_Amount           = addslashes(trim($_REQUEST['txtCGST_Amount']));
	$txtIGST                  = addslashes(trim($_REQUEST['txtIGST']));
	$txtIGST_Amount           = addslashes(trim($_REQUEST['txtIGST_Amount']));
	$txtVAT                   = addslashes(trim($_REQUEST['txtVAT']));
	$txtVAT_Amount            = addslashes(trim($_REQUEST['txtVAT_Amount']));
	$txtAmtPayableWithTax     = addslashes(trim($_REQUEST['txtAmtPayableWithTax']));
	$c_bank_check     = addslashes(trim($_REQUEST['c_bank_check']));

	
	$txtBLDate	 		      = $_REQUEST['txtBLDate'];
	$txtBLNo                  = addslashes(trim($_REQUEST['txtBLNo']));
	$txtFlag                  = addslashes(trim($_REQUEST['txtFlag']));
	$txtIMONo                 = addslashes(trim($_REQUEST['txtIMONo']));
	
	$txtLoadPortName          = addslashes(trim($_REQUEST['txtLoadPortName']));
	$txtDischargePortName     = addslashes(trim($_REQUEST['txtDischargePortName']));
	$txtManualVendorName     = addslashes(trim($_REQUEST['txtManualVendorName']));
	$selApprovers             = $_REQUEST['selApprovers'];
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));


	$txtFrieghtRate = trim($_REQUEST['txtFrieghtRate'],'USD/MT');


	$upload = $this->getUpload($_FILES['attach_file']);
	$filename = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$filename = implode(',',$filename);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $filename != ''){ $name1 = $txtCRMNAME1.','.$filename;}
	else if($txtCRMNAME1 == '' && $filename != ''){ $name1 = $filename;}
	else if($txtCRMNAME1 != '' && $filename == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$invoiceidd = '';$creatorloginid = '';
	 $qsql = "select * from freight_invoice_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR='".$txtVendor."' and MESSAGE = '".$txtDNote1."' and CARGOID='".$cargoid."' and RANDOMID='".$randomid."' and P_TYPE='".$name."'";
	
	$qres = mysql_query($qsql) or die($qsql);
	$qrec = mysql_num_rows($qres);
	if($qrec == 0)
	{
	 	$sql = "insert into freight_invoice_master (COMID, MODULEID, MCOMPANYID, DATE, I_TYPE, NOB, STATUS, MESSAGE, VENDOR, GROSS_FREIGHT, BROKERAGE, CPDATE, FCAID, FINAL_FREIGHT, TO_1, NET_AMOUNT, REMARKS, PAYMENT_TERMS, QUANTITY, BROKERAGE_PERCENT, EXCHANGE_CURRENCY, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, ADDCOM, ADDCOM_AMOUNT, NET_PAYABLE, P_TYPE, ATTEN, DUE_DATE, EXCHANGE_DATE,  SHIP_OWNER, CARGOID, RANDOMID, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME, BL_DATE, BL_NO, FLAG, IMO_NO, LOAD_PORT_NAME, DISCHARGE_PORT_NAME, MANUAL_VENDOR_NAME,FREIGHT_RATE,c_bank_check) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$txtDate."', '".$selIType."', '".$selNOB."', '".$txtStatus."', '".$txtDNote."', '".$txtVendor."', '".$this->getCheckNullVal($txtGrossFreight)."', '".$this->getCheckNullVal($txtBrokerageAmt)."', '".$txtCP_Date."', '".$txtFCAID."', '".$this->getCheckNullVal($txtNetFreight)."', '".$this->getCheckNullVal($txtTO)."', '".$this->getCheckNullVal($txtNet)."', '".$txtDesc."', '".$txtPaymentTerms."', '".$txtQty."', '".$txtBrokerage."', '".$selExchangeCurrency."', '".$txtFreightAmtLocal."', '".$txtExchangeRate."', '".$txtAddComm."', '".$txtAddCommAmt."', '".$txtNetAmtPayable."', '".$name."', '".$txtAttenName."', '".$txtDueDate."', '".$txtExchangeDate."', '".$selFromOwner."', '".$cargoid."', '".$this->getCheckNullVal($randomid)."', '".$this->getCheckNullVal($rdoTaxApplicable)."', '".$this->getCheckNullVal($rdoGSTVAT)."', '".$this->getCheckNullVal($txtSGST)."', '".$this->getCheckNullVal($txtCGST)."', '".$this->getCheckNullVal($txtIGST)."', '".$this->getCheckNullVal($txtVAT)."', '".$this->getCheckNullVal($txtAmtPayableWithTax)."', '".$this->getCheckNullVal($txtSGST_Amount)."', '".$this->getCheckNullVal($txtCGST_Amount)."', '".$this->getCheckNullVal($txtIGST_Amount)."', '".$this->getCheckNullVal($txtVAT_Amount)."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$upload1."', '".$name1."' , '".$txtBLDate."', '".$txtBLNo."', '".$txtFlag."', '".$txtIMONo."', '".$txtLoadPortName."', '".$txtDischargePortName."', '".$txtManualVendorName."', '".$txtFrieghtRate."','".$c_bank_check."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		

		
		$sql1 = "select max(INVOICEID) as max from freight_invoice_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$invoiceidd = $rows1['max'];
		$creatorloginid = $_SESSION['uid'];
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into freight_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into freight_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$hddnClubcount  = $_REQUEST['hddnClubcount'];
		for($i=1;$i<=$hddnClubcount;$i++)
		{
		    if(isset($_REQUEST['chkClubFreight_'.$i]))
			{
				$hddnVendorid	 	  = addslashes(trim($_REQUEST['hddnVendorid_'.$i]));
				$hddnrandomid         = $this->getCheckNullVal($_REQUEST['hddnrandomid_'.$i]);
				$hddncargoid	 	  = addslashes(trim($_REQUEST['hddncargoid_'.$i]));
				$sql2 = "insert into freight_invoice_slave1 (INVOICEID, VENDOR, CARGO, RANDOMID) values ('".$rows1['max']."', '".$hddnVendorid."', '".$hddncargoid."', '".$hddnrandomid."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$txtDemDisID  = $_REQUEST['txtDemDisID'];
		for($i=1;$i<=$txtDemDisID;$i++)
		{
		    if(isset($_REQUEST['chkDemDis_'.$i]))
			{
				$txtDemDisPort	 	  = addslashes(trim($_REQUEST['txtDemDisPort_'.$i]));
				$txtDemDisAmt         = $this->getCheckNullVal($_REQUEST['txtDemDisAmt_'.$i]);
				$txtDemDisPortid	  = addslashes(trim($_REQUEST['txtDemDisPortid_'.$i]));
				$txtDemDisRandomid 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtDemDisRandomid_'.$i])));
				$txtDemDisVendorid 	  = addslashes(trim($_REQUEST['txtDemDisVendorid_'.$i]));
				
				$sql2 = "insert into freight_invoice_slave3 (INVOICEID, VENDORID, DEM_AMT, RANDOMID, PORT, PORTID) values ('".$rows1['max']."', '".$txtDemDisVendorid."', '".$txtDemDisAmt."', '".$txtDemDisRandomid."', '".$txtDemDisPort."', '".$txtDemDisPortid."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." Freight Invoice (".$txtDNote.") Created Successfully.");
	}
	else
	{
		$qrows = mysql_fetch_assoc($qres);
		$invoiceidd = $qrows['INVOICEID'];
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $qrows['APPROVERS'];
		}
		$creatorloginid = $qrows['CREATOR'];
		
		 $sql = "update freight_invoice_master set DATE='".$txtDate."', I_TYPE='".$selIType."', NOB='".$selNOB."', STATUS='".$txtStatus."', MESSAGE='".$txtDNote."', GROSS_FREIGHT='".$this->getCheckNullVal($txtGrossFreight)."', BROKERAGE='".$this->getCheckNullVal($txtBrokerageAmt)."', CPDATE='".$txtCP_Date."', FINAL_FREIGHT='".$this->getCheckNullVal($txtNetFreight)."', TO_1='".$this->getCheckNullVal($txtTO)."', NET_AMOUNT='".$this->getCheckNullVal($txtNet)."', REMARKS='".$txtDesc."', PAYMENT_TERMS='".$txtPaymentTerms."', QUANTITY='".$txtQty."', BROKERAGE_PERCENT='".$txtBrokerage."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', AGREED_GROSS_FREIGHT_LOCAL='".$txtFreightAmtLocal."', EXCHANGE_RATE='".$txtExchangeRate."', ADDCOM='".$txtAddComm."', ADDCOM_AMOUNT='".$txtAddCommAmt."', NET_PAYABLE='".$txtNetAmtPayable."', P_TYPE='".$name."', ATTEN= '".$txtAttenName."', DUE_DATE='".$txtDueDate."', EXCHANGE_DATE= '".$txtExchangeDate."',  SHIP_OWNER='".$selFromOwner."', CARGOID='".$cargoid."', RANDOMID='".$this->getCheckNullVal($randomid)."', RDOTAXAPPLICABLE='".$this->getCheckNullVal($rdoTaxApplicable)."', RDOVATGST='".$this->getCheckNullVal($rdoGSTVAT)."', SGST_PERCENT='".$this->getCheckNullVal($txtSGST)."', CGST_PERCENT='".$this->getCheckNullVal($txtCGST)."', IGST_PERCENT='".$this->getCheckNullVal($txtIGST)."', VAT_PERCENT='".$this->getCheckNullVal($txtVAT)."', NET_PAYABLE_TAX='".$this->getCheckNullVal($txtAmtPayableWithTax)."', SGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtSGST_Amount)."', CGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtCGST_Amount)."', IGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtIGST_Amount)."', VAT_PERCENT_AMOUNT='".$this->getCheckNullVal($txtVAT_Amount)."', APPROVERS='".$approversel."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', BL_DATE='".$txtBLDate."', BL_NO='".$txtBLNo."', FLAG='".$txtFlag."', IMO_NO='".$txtIMONo."', LOAD_PORT_NAME='".$txtLoadPortName."', DISCHARGE_PORT_NAME='".$txtDischargePortName."', FREIGHT_RATE='".	 $txtFrieghtRate."', MANUAL_VENDOR_NAME='".$txtManualVendorName."',c_bank_check='".$c_bank_check."' where INVOICEID='".$qrows['INVOICEID']."'";
	
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql_del = "delete from freight_invoice_slave where INVOICEID='".$qrows['INVOICEID']."'";
		$sql_del1 = "delete from freight_invoice_slave1 where INVOICEID='".$qrows['INVOICEID']."'";
		$sql_del2 = "delete from freight_invoice_slave3 where INVOICEID='".$qrows['INVOICEID']."'";
		mysql_query($sql_del);
		mysql_query($sql_del1);
		mysql_query($sql_del2);
		mysql_query("commit");
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if(isset($_REQUEST['txtAddDes_'.$i]))
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into freight_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if(isset($_REQUEST['txtSubDes_'.$i]))
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into freight_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
				mysql_query($sql2);
			}
		}
		
		$hddnClubcount  = $_REQUEST['hddnClubcount'];
		for($i=1;$i<=$hddnClubcount;$i++)
		{
		    if(isset($_REQUEST['chkClubFreight_'.$i]))
			{
				$hddnVendorid	 	  = addslashes(trim($_REQUEST['hddnVendorid_'.$i]));
				$hddnrandomid         = $this->getCheckNullVal($_REQUEST['hddnrandomid_'.$i]);
				$hddncargoid	 	  = addslashes(trim($_REQUEST['hddncargoid_'.$i]));
				$sql2 = "insert into freight_invoice_slave1 (INVOICEID, VENDOR, CARGO, RANDOMID) values ('".$qrows['INVOICEID']."', '".$hddnVendorid."', '".$hddncargoid."', '".$hddnrandomid."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$txtDemDisID  = $_REQUEST['txtDemDisID'];
		for($i=1;$i<=$txtDemDisID;$i++)
		{
		    if(isset($_REQUEST['chkDemDis_'.$i]))
			{
				$txtDemDisPort	 	  = addslashes(trim($_REQUEST['txtDemDisPort_'.$i]));
				$txtDemDisAmt         = $this->getCheckNullVal($_REQUEST['txtDemDisAmt_'.$i]);
				$txtDemDisPortid	  = addslashes(trim($_REQUEST['txtDemDisPortid_'.$i]));
				$txtDemDisRandomid 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtDemDisRandomid_'.$i])));
				$txtDemDisVendorid 	  = addslashes(trim($_REQUEST['txtDemDisVendorid_'.$i]));
				
				$sql2 = "insert into freight_invoice_slave3 (INVOICEID, VENDORID, DEM_AMT, RANDOMID, PORT, PORTID) values ('".$qrows['INVOICEID']."', '".$txtDemDisVendorid."', '".$txtDemDisAmt."', '".$txtDemDisRandomid."', '".$txtDemDisPort."', '".$txtDemDisPortid."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." Freight Invoice (".$txtDNote.") Updated Successfully.");
	}
	
	$this->inactiveUserAlerts('FREIGHT INVOICE', $_SESSION['uid'], $invoiceidd);
	
	if($_REQUEST['invtype']=='Interim')
	{
		$creatorsarr = array($creatorloginid);
		$approverarr1 = $_REQUEST['selApprovers'];
		$approverarr2 = $this->getUsersWithAuthority('INI_FREIGHT_CHK_APP_2');
		$appaccountarr = $this->getUsersWithAuthority('INI_FREIGHT_CHK_ACC');
	}else
	{
	    $creatorsarr = array($creatorloginid);
		$approverarr1 = $_REQUEST['selApprovers'];
		$approverarr2 = $this->getUsersWithAuthority('FINL_FREIGHT_CHK_APP_2');
		$appaccountarr = $this->getUsersWithAuthority('FINL_FREIGHT_CHK_ACC');
	}
	$url = './invoice.php?id='.$_REQUEST['id'].'&page='.$_REQUEST['page'].'&name='.$_REQUEST['name']."&invtype=".$_REQUEST['invtype'];
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	if($_REQUEST['invtype']=='Interim'){$invtitleType = 'INITIAL FREIGHT INVOICE';}else{$invtitleType = 'FINAL FREIGHT INVOICE';}
	
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT INVOICE', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT INVOICE', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT INVOICE', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT INVOICE', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{
		     if(!empty($appaccountarr))
			 {
			     $userarray = $appaccountarr;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT INVOICE', $currentusername.' Approved '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.').', $invoiceidd);				  
				  }
			 }
		}
	}
	mysql_query("commit");
	return $msg.','.$comid;  
}


function insertFreightPaymentReceivedDetails()
{
	//echo '<pre>';print_r($_POST);die();
	$connect = $this->funConnect();
	$id					= addslashes(trim($_REQUEST['comid']));
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update freight_invoice_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where INVOICEID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$sql_del1 = "delete from freight_invoice_slave2 where INVOICEID='".$txtP_ID."'";
	mysql_query($sql_del1);
	mysql_query("commit");
	
	$txtPaymentID  = $_REQUEST['txtPaymentID'];
	for($i=1;$i<=$txtPaymentID;$i++)
	{
		if(isset($_REQUEST['txtP_Date_'.$i]) && $_REQUEST['txtP_Date_'.$i]!='' && $_REQUEST['txtP_PR_'.$i]!='')
		{
		    $txtP_Date	 	  = date("Y-m-d",strtotime($_REQUEST['txtP_Date_'.$i]));
			$txtP_Remarks 	  = addslashes(trim($_REQUEST['txtP_Remarks_'.$i]));
			$txtP_PR     	  = $this->getCheckNullVal($_REQUEST['txtP_PR_'.$i]);
			$sql2 = "insert into freight_invoice_slave2 (INVOICEID, RECVD_DATE, RECVD_REMARKS, RECVD_AMOUNT) values ('".$txtP_ID."', '".$txtP_Date."', '".$txtP_Remarks."', '".$txtP_PR."')";
			mysql_query($sql2);
			mysql_query("commit");
		}
	}
	
	$this->inactiveUserAlerts('FREIGHT INVOICE', $_SESSION['uid'], $txtP_ID);
	
	return $msg.'_'.$id; 
}

function getFreightInvoiceDetailsDataWithJson($comid)
{
	$connect   = $this->funconnect();	
	$query     = mysql_query("select * from freight_invoice_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."'");
	while($row = mysql_fetch_assoc($query))
	{
	    $id = $row['INVOICEID'];
		$a[$id][] = array('pay_no' => $row['PAYMENT_NO'], 'p_date' =>  date("d-m-Y",strtotime($row['P_DATE'])), 'p_type' => $row['P_TYPE'], 'remarks' => $row['P_REMARKS'], 'p_amt' => $row['P_AMT']);
	}
	echo json_encode($a);
}

function deletefreightInvoiceRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txtDEL_ID']));
	$comid 			= addslashes(trim($_REQUEST['comid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	
	
	$sql = "select * from freight_invoice_master where INVOICEID='".$id."'";
	$result = mysql_query($sql);
	while($rows = mysql_fetch_assoc($result))
	{
	    
		$this->saveRecentWork($rows['I_TYPE']." Freight Invoice (".$rows['MESSAGE'].") Cancelled Successfully.");
		
		$sql_insert = "insert into freight_invoice_master(COMID, MODULEID, MCOMPANYID, DATE, I_TYPE, PAYMENT_NO, P_TYPE, NOB, STATUS, P_REMARKS, P_AMT, P_DATE, MESSAGE, MESSAGE_NO, VENDOR, GROSS_FREIGHT, BROKERAGE, GRADEID, CPDATE, FCAID, FINAL_FREIGHT, TO_1, NET_AMOUNT, REMARKS, QUANTITY, NET_INWORDS, BROKERAGE_PERCENT, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, PAYMENT_TERMS, ADDCOM, ADDCOM_AMOUNT, NET_PAYABLE, ATTACHMENTS, ATTACHMENTS_NAME, ATTEN, DUE_DATE, EXCHANGE_DATE, EXCHANGE_CURRENCY, SHIP_OWNER, CARGOID, RANDOMID, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME, BL_DATE, BL_NO, FLAG, IMO_NO) value('".$rows['COMID']."', '".$rows['MODULEID']."', '".$rows['MCOMPANYID']."', '".$rows['DATE']."', 'Credit', '".$rows['PAYMENT_NO']."', '".$rows['P_TYPE']."', '".addslashes($rows['NOB'])."', '8', '".addslashes($rows['P_REMARKS'])."', '".$rows['P_AMT']."', '".$rows['P_DATE']."', '".$rows['MESSAGE']."', '".$rows['MESSAGE_NO']."', '".$rows['VENDOR']."', '".$rows['GROSS_FREIGHT']."', '".$rows['BROKERAGE']."', '".$rows['GRADEID']."', '".$rows['CPDATE']."', '".$rows['FCAID']."', '".$rows['FINAL_FREIGHT']."', '".$rows['TO_1']."', '".$rows['NET_AMOUNT']."', '".addslashes($rows['REMARKS'])."', '".$rows['QUANTITY']."', '".addslashes($rows['NET_INWORDS'])."', '".$rows['BROKERAGE_PERCENT']."', '".$rows['AGREED_GROSS_FREIGHT_LOCAL']."', '".$rows['EXCHANGE_RATE']."', '".addslashes($rows['PAYMENT_TERMS'])."', '".$rows['ADDCOM']."', '".$rows['ADDCOM_AMOUNT']."', '".$rows['NET_PAYABLE']."', '".$rows['ATTACHMENTS']."', '".addslashes($rows['ATTACHMENTS_NAME'])."', '".addslashes($rows['ATTEN'])."', '".$rows['DUE_DATE']."', '".$rows['EXCHANGE_DATE']."', '".$rows['EXCHANGE_CURRENCY']."', '".$rows['SHIP_OWNER']."', '".$rows['CARGOID']."', '".$rows['RANDOMID']."', '".$rows['RDOTAXAPPLICABLE']."', '".$rows['RDOVATGST']."', '".$rows['SGST_PERCENT']."', '".$rows['CGST_PERCENT']."', '".$rows['IGST_PERCENT']."', '".$rows['VAT_PERCENT']."', '".$rows['NET_PAYABLE_TAX']."', '".$rows['SGST_PERCENT_AMOUNT']."', '".$rows['CGST_PERCENT_AMOUNT']."', '".$rows['IGST_PERCENT_AMOUNT']."', '".$rows['VAT_PERCENT_AMOUNT']."', '".$rows['APPROVERS']."', '".$rows['CREATOR']."', '".$rows['UPLOAD']."', '".$rows['UPLOAD_NAME']."', '".$rows['BL_DATE']."', '".$rows['BL_NO']."', '".$rows['FLAG']."', '".$rows['IMO_NO']."')";
		mysql_query($sql_insert) or die($sql_insert);
		
		$sql_max = "select max(INVOICEID) as max from freight_invoice_master";
		$res_max = mysql_query($sql_max);
		$rows_max = mysql_fetch_assoc($res_max);
		
		$sql1 = "select * from freight_invoice_slave where INVOICEID='".$id."'";
		$result1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($result1))
		{
		    $sql_isert2 = "insert into freight_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) value ('".$rows_max['max']."', '".addslashes($rows1['DESCRIPTION'])."', '".$rows1['AMOUNT']."', '".$rows1['IDENTIFY']."')";
			mysql_query($sql_isert2) or die($sql_isert2);
		}
		
		$sql2 = "select * from freight_invoice_slave1 where INVOICEID='".$id."'";
		$result2 = mysql_query($sql2);
		while($rows2 = mysql_fetch_assoc($result2))
		{
		    $sql_isert3 = "insert into freight_invoice_slave1 (INVOICEID, VENDOR, CARGO, RANDOMID, QUANTITY) value ('".$rows_max['max']."', '".$rows2['VENDOR']."', '".addslashes($rows2['CARGO'])."', '".$rows2['RANDOMID']."', '".$rows2['QUANTITY']."')";
			mysql_query($sql_isert3) or die($sql_isert3);
		}
		
		$sql2 = "update freight_invoice_master set STATUS=8 where INVOICEID='".$id."'";
	    mysql_query($sql2);
	}

	// $queryDel = 'delet';

	$queryDel = "delete from  freight_invoice_slave3 where INVOICEID='".$id."'";
	mysql_query($queryDel);

	mysql_query("commit"); 
	return $msg.','.$comid;
}

function deleteOtherInvoiceRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txtDEL_ID']));
	$comid 			= addslashes(trim($_REQUEST['comid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	
	$sql = "select * from other_invoice_master where INVOICEID='".$id."'";
	$result = mysql_query($sql);
	while($rows = mysql_fetch_assoc($result))
	{
		$sql_insert = "insert into other_invoice_master(COMID, MODULEID, MCOMPANYID, DATE, I_TYPE, PAYMENT_NO, P_TYPE, NOB, STATUS, P_REMARKS, P_AMT, P_DATE, MESSAGE, MESSAGE_NO, VENDOR, GROSS_AMT, BROKERAGE, CPDATE, FCAID, REMARKS, EXCHANGE_RATE, PAYMENT_TERMS, NET_PAYABLE, ATTACHMENTS, ATTACHMENTS_NAME, ATTEN, DUE_DATE, EXCHANGE_DATE, EXCHANGE_CURRENCY, SHIP_OWNER, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME) value('".$rows['COMID']."', '".$rows['MODULEID']."', '".$rows['MCOMPANYID']."', '".$rows['DATE']."', 'Credit', '".$rows['PAYMENT_NO']."', '".$rows['P_TYPE']."', '".$rows['NOB']."', '8', '".addslashes($rows['P_REMARKS'])."', '".$rows['P_AMT']."', '".$rows['P_DATE']."', '".$rows['MESSAGE']."', '".$rows['MESSAGE_NO']."', '".$rows['VENDOR']."', '".$rows['GROSS_AMT']."', '".$rows['BROKERAGE']."', '".$rows['CPDATE']."', '".$rows['FCAID']."', '".addslashes($rows['REMARKS'])."', '".$rows['EXCHANGE_RATE']."', '".addslashes($rows['PAYMENT_TERMS'])."', '".$rows['NET_PAYABLE']."', '".$rows['ATTACHMENTS']."', '".addslashes($rows['ATTACHMENTS_NAME'])."', '".addslashes($rows['ATTEN'])."', '".$rows['DUE_DATE']."', '".$rows['EXCHANGE_DATE']."', '".$rows['EXCHANGE_CURRENCY']."', '".$rows['SHIP_OWNER']."', '".$rows['RDOTAXAPPLICABLE']."', '".$rows['RDOVATGST']."', '".$rows['SGST_PERCENT']."', '".$rows['CGST_PERCENT']."', '".$rows['IGST_PERCENT']."', '".$rows['VAT_PERCENT']."', '".$rows['NET_PAYABLE_TAX']."', '".$rows['SGST_PERCENT_AMOUNT']."', '".$rows['CGST_PERCENT_AMOUNT']."', '".$rows['IGST_PERCENT_AMOUNT']."', '".$rows['VAT_PERCENT_AMOUNT']."', '".$rows['APPROVERS']."', '".$rows['CREATOR']."', '".$rows['UPLOAD']."', '".$rows['UPLOAD_NAME']."')";
		mysql_query($sql_insert);
		
		$sql_max = "select max(INVOICEID) as max from other_invoice_master";
		$res_max = mysql_query($sql_max);
		$rows_max = mysql_fetch_assoc($res_max);
		
		$sql1 = "select * from other_invoice_slave where INVOICEID='".$id."'";
		$result1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($result1))
		{
		    $sql_isert2 = "insert into other_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) value ('".$rows_max['max']."', '".addslashes($rows1['DESCRIPTION'])."', '".$rows1['AMOUNT']."', '".$rows1['IDENTIFY']."')";
			mysql_query($sql_isert2);
		}
		
		$sql2 = "update other_invoice_master set STATUS=8 where INVOICEID='".$id."'";
	    mysql_query($sql2);
	}
	
	mysql_query("commit"); 
	return $msg.','.$comid;
}

function deleteOtherTCInvoiceRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txtDEL_ID']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	$sql = "select * from invoice_tcother_master where INVOICEID='".$id."'";
	$result = mysql_query($sql);
	while($rows = mysql_fetch_assoc($result))
	{
		$sql_insert = "insert into invoice_tcother_master(COMID, MODULEID, MCOMPANYID, INVOICE_TYPE, INVOICE_NO, INVOICE_DATE, EXCHANGE_RATE, EXCHANGE_CURRENCY, PAYMENT_TERMS, DESCRIPTION, BANKINGID, DUE_DATE, AMOUNT, FINAL_AMOUNT, STATUS, SHIP_OWNER, ATTEN, RANDOMID, EXCHANGE_DATE, INV_IDENTITY, VENDOR, SHORT_DESC, P_DATE, P_AMT, P_REMARKS, ATTACHMENTS, ATTACHMENTS_NAME, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME) value('".$rows['COMID']."', '".$rows['MODULEID']."', '".$rows['MCOMPANYID']."', 'Credit', '".$rows['INVOICE_NO']."', '".$rows['INVOICE_DATE']."', '".$rows['EXCHANGE_RATE']."', '".$rows['EXCHANGE_CURRENCY']."', '".addslashes($rows['PAYMENT_TERMS'])."', '".addslashes($rows['DESCRIPTION'])."', '".$rows['BANKINGID']."', '".$rows['DUE_DATE']."', '".$rows['AMOUNT']."', '".$rows['FINAL_AMOUNT']."', '8', '".$rows['SHIP_OWNER']."', '".addslashes($rows['ATTEN'])."', '".$rows['RANDOMID']."', '".$rows['EXCHANGE_DATE']."', '".$rows['INV_IDENTITY']."', '".$rows['VENDOR']."', '".addslashes($rows['SHORT_DESC'])."', '".$rows['P_DATE']."', '".$rows['P_AMT']."', '".addslashes($rows['P_REMARKS'])."', '".addslashes($rows['ATTACHMENTS'])."', '".addslashes($rows['ATTACHMENTS_NAME'])."', '".$rows['RDOTAXAPPLICABLE']."', '".$rows['RDOVATGST']."', '".$rows['SGST_PERCENT']."', '".$rows['CGST_PERCENT']."', '".$rows['IGST_PERCENT']."', '".$rows['VAT_PERCENT']."', '".$rows['NET_PAYABLE_TAX']."', '".$rows['SGST_PERCENT_AMOUNT']."', '".$rows['CGST_PERCENT_AMOUNT']."', '".$rows['IGST_PERCENT_AMOUNT']."', '".$rows['VAT_PERCENT_AMOUNT']."', '".$rows['APPROVERS']."', '".$rows['CREATOR']."', '".$rows['UPLOAD']."', '".$rows['UPLOAD_NAME']."')";
		mysql_query($sql_insert) or die($sql_insert);
		
		$sql_max = "select max(INVOICEID) as max from invoice_tcother_master";
		$res_max = mysql_query($sql_max);
		$rows_max = mysql_fetch_assoc($res_max);
		
		$sql1 = "select * from invoice_tcother_slave1 where INVOICEID='".$id."'";
		$result1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($result1))
		{
		    $sql_isert2 = "insert into invoice_tcother_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) value ('".$rows_max['max']."', '".addslashes($rows1['DESCRIPTION'])."', '".$rows1['AMOUNT']."', '".$rows1['IDENTIFY']."')";
			mysql_query($sql_isert2);
		}
		
		$sql2 = "update invoice_tcother_master set STATUS=8 where INVOICEID='".$id."'";
	    mysql_query($sql2);
	}
	mysql_query("commit"); 
	return $msg;
}


function getLPTermsList($id)
{
$state = array( '1' =>'SHINC' , '2' =>'SSHEX' , '3' =>'FSHEX', '4' =>'D.A.P.');
echo '<option value="">---Select from list---</option>';
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo '<option value="'.$key.'"';
		if($key == $id){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getLPTermsNameBasedOnID($id)
{
$state = array( '1' =>'SHINC' , '2' =>'SSHEX' , '3' =>'FSHEX', '4' =>'D.A.P.');
$name = "";
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		if($key == $id){ return $value;}
	}
}



function getVesselRelatedData()
{
	$connect=$this->funConnect();
	$query1 = "select * from vessel_allocation_master WHERE MCOMPANYID='".$_SESSION['company']."' order by ALLOCATEID ";
	$res1 = mysql_query($query1);
	$a = array();
	while($rows1 = mysql_fetch_assoc($res1))
	{
		 $arr = array();
		 $arr = explode(",",$rows1['MODULE_ID']);
		 if(in_array($_SESSION['moduleid'],$arr))
		 {
			$query = "select * from vessel_commercial_parameters where VESSEL_IMO_ID='".$rows1['VESSEL_IMO_ID']."'";
			$res = mysql_query($query);
			$rec = mysql_num_rows($res);
			
			
			if($this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"DWT") == ""){$dwt_sum = "0.0";}else{$dwt_sum = $this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"DWT");}
			if($this->getVesselParticularData('TROPICAL_1','vessel_master_1',$rows1['VESSEL_IMO_ID']) == ""){$dwt_trop = "0.0";}else{$dwt_trop = $this->getVesselParticularData('TROPICAL_1','vessel_master_1',$rows1['VESSEL_IMO_ID']);}
			if($this->getVesselMaster8Data($rows1['VESSEL_IMO_ID'],"GRAIN") == ""){$grain = "0.0";}else{$grain = $this->getVesselMaster8Data($rows1['VESSEL_IMO_ID'],"GRAIN");}
			if($this->getVesselMaster8Data($rows1['VESSEL_IMO_ID'],"BALE") == ""){$bale = "0.0";}else{$bale = $this->getVesselMaster8Data($rows1['VESSEL_IMO_ID'],"BALE");}
			
			if(is_null($rows1["EXTERNAL_VESSEL_ID"]))
			{
				$vesselid = $rows1['VESSEL_IMO_ID'];
				$user = "";
			}
			else
			{
				$vesselid = $rows1['EXTERNAL_VESSEL_ID'];
				$user = "EXTERNAL_USER";
			}
			
			
			$b_full_speed = $this->getVesselParameterData($vesselid,"B_FULL_SPEED",$user);
			if($b_full_speed == "" ){$bfs = 0;}else{$bfs = $b_full_speed;}
			$b_ech_speed1 = $this->getVesselParameterData($vesselid,"B_ECO_SPEED1",$user);
			if($b_ech_speed1 == "" ){$bes1 = 0;}else{$bes1 = $b_ech_speed1;}
			$b_ech_speed2 = $this->getVesselParameterData($vesselid,"B_ECO_SPEED2",$user);
			if($b_ech_speed2 == "" ){$bes2 = 0;}else{$bes2 = $b_ech_speed2;}
			$fo_b_full_speed = $this->getVesselParameterData($vesselid,"BP_FO_FULL_SPEED",$user);
			if($fo_b_full_speed == ""){$fo_bfs = 0;}else{$fo_bfs = $fo_b_full_speed;}
			$fo_b_ech_speed1 = $this->getVesselParameterData($vesselid,"BP_FO_ECO_SPEED1",$user);
			if($fo_b_ech_speed1 == ""){$fo_bes1 = 0;}else{$fo_bes1 = $fo_b_ech_speed1;}
			$fo_b_ech_speed2 = $this->getVesselParameterData($vesselid,"BP_FO_ECO_SPEED2",$user);
			if($fo_b_ech_speed2 == ""){$fo_bes2 = 0;}else{$fo_bes2 = $fo_b_ech_speed2;}
			$do_b_full_speed = $this->getVesselParameterData($vesselid,"BP_DO_FULL_SPEED",$user);
			if($do_b_full_speed == ""){$do_bfs = 0;}else{$do_bfs = $do_b_full_speed;}
			$do_b_ech_speed1 = $this->getVesselParameterData($vesselid,"BP_DO_ECO_SPEED1",$user);
			if($do_b_ech_speed1 == ""){$do_bes1 = 0;}else{$do_bes1 = $do_b_ech_speed1;}
			$do_b_ech_speed2 = $this->getVesselParameterData($vesselid,"BP_DO_ECO_SPEED2",$user);
			if($do_b_ech_speed2 == ""){$do_bes2 = 0;}else{$do_bes2 = $do_b_ech_speed2;}
			
			$l_full_speed = $this->getVesselParameterData($vesselid,"L_FULL_SPEED",$user);
			if($l_full_speed == "" ){$lfs = 0;}else{$lfs = $l_full_speed;}
			$l_ech_speed1 = $this->getVesselParameterData($vesselid,"L_ECO_SPEED1",$user);
			if($l_ech_speed1 == "" ){$les1 = 0;}else{$les1 = $l_ech_speed1;}
			$l_ech_speed2 = $this->getVesselParameterData($vesselid,"L_ECO_SPEED2",$user);
			if($l_ech_speed2 == "" ){$les2 = 0;}else{$les2 = $l_ech_speed2;}
			$fo_l_full_speed = $this->getVesselParameterData($vesselid,"LP_FO_FULL_SPEED",$user);
			if($fo_l_full_speed == ""){$fo_lfs = 0;}else{$fo_lfs = $fo_l_full_speed;}
			$fo_l_ech_speed1 = $this->getVesselParameterData($vesselid,"LP_FO_ECO_SPEED1",$user);
			if($fo_l_ech_speed1 == ""){$fo_les1 = 0;}else{$fo_les1 = $fo_l_ech_speed1;}
			$fo_l_ech_speed2 = $this->getVesselParameterData($vesselid,"LP_FO_ECO_SPEED2",$user);
			if($fo_l_ech_speed2 == ""){$fo_les2 = 0;}else{$fo_les2 = $fo_l_ech_speed2;}
			$do_l_full_speed = $this->getVesselParameterData($vesselid,"LP_DO_FULL_SPEED",$user);
			if($do_l_full_speed == ""){$do_lfs = 0;}else{$do_lfs = $do_l_full_speed;}
			$do_l_ech_speed1 = $this->getVesselParameterData($vesselid,"LP_DO_ECO_SPEED1",$user);
			if($do_l_ech_speed1 == ""){$do_les1 = 0;}else{$do_les1 = $do_l_ech_speed1;}
			$do_l_ech_speed2 = $this->getVesselParameterData($vesselid,"LP_DO_ECO_SPEED2",$user);
			if($do_l_ech_speed2 == ""){$do_les2 = 0;}else{$do_les2 = $do_l_ech_speed2;}
			
			$fo_inport_idle = $this->getVesselParameterData($vesselid,"PI_FO_FULL_SPEED",$user);
			if($fo_inport_idle == ""){$foidle = 0;}else{$foidle = $fo_inport_idle;}
			$fo_inport_wrking = $this->getVesselParameterData($vesselid,"PW_FO_FULL_SPEED",$user);
			if($fo_inport_wrking == ""){$fowrking = 0;}else{$fowrking = $fo_inport_wrking;}
			
			$do_inport_idle = $this->getVesselParameterData($vesselid,"PI_DO_FULL_SPEED",$user);
			if($do_inport_idle == ""){$doidle = 0;}else{$doidle = $do_inport_idle;}
			$do_inport_wrking = $this->getVesselParameterData($vesselid,"PW_DO_FULL_SPEED",$user);
			if($do_inport_wrking == ""){$dowrking = 0;}else{$dowrking = $do_inport_wrking;}
			
			$flag = $this->getCountryNameOnId($this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"FLAG"));
			if($flag == ""){$flag = 0;}else{$flag = $flag;}
			
			if($rec == 0){$vesselrecord = 0;}else{$vesselrecord = $rec;}
			
			//echo $this->getVesselTypeBasedOnID($this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_TYPE"))."#".$dwt_sum."#".$dwt_trop."#".$."#".$bale."#".$bfs."#".$bes1."#".$."#".$fo_bfs."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$."#".$vesselrecord;
			$a[$rows1['VESSEL_IMO_ID']][] = array('type' => $this->getVesselTypeBasedOnID($this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"VESSEL_TYPE")) , 'dwtsum' => $dwt_sum, 'dwttrop' => $dwt_trop, 'grain' => $grain, 'bale' => $bale, 'bfs' => $bfs, 'bes1' => $bes1, 'bes2' => $bes2, 'fobfs' => $fo_bfs, 'fobes1' => $fo_bes1, 'fobes2' => $fo_bes2, 'dobfs' => $do_bfs, 'dobes1' => $do_bes1, 'dobes2' => $do_bes2, 'lfs' => $lfs, 'les1' => $les1, 'les2' => $les2, 'folfs' => $fo_lfs, 'foles1' => $fo_les1, 'foles2' => $fo_les2, 'dolfs' => $do_lfs, 'doles1' => $do_les1, 'doles2' => $do_les2, 'foidle' => $foidle, 'fwking' => $fowrking, 'ddle' => $doidle, 'dwking' => $dowrking, 'num' => $rec, 'flag' => $flag, 'year' => $this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"YEARBUILT"), 'gnrt' => $this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"GRT_NRT"), 'gear' => $this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"CARGO_GEAR"), 'loa' => $this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"LOA"), 'beam' => $this->getVesselIMOData($rows1['VESSEL_IMO_ID'],"EXT_BREADTH"), 'tpc' => $this->getVesselParticularData('SUMMER_3','vessel_master_1',$rows1['VESSEL_IMO_ID']));
		 }
	}
	echo json_encode($a);
}



function insertTCITemplateDetailsNew()
{
	$connect = $this->funConnect();
	
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	$txtBStatus          = addslashes(trim($_REQUEST['txtBStatus']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 		= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	$market_rdo 		= addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	$txtAddnlCRate 		= addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlCRatePer   = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
	
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
    $txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	$txtCVE             = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt      	= addslashes(trim($_REQUEST['txtCVEAmt']));
	$txtHidCVEAmt   	= addslashes(trim($_REQUEST['txtHidCVEAmt']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	$txtDistributedRemarks     = addslashes(trim($_REQUEST['txtDistributedRemarks']));
	
	
	$selOpenPort 	 	= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 		= addslashes(trim($_REQUEST['selZone']));
	$selBroker          = addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 	= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 	= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    		= addslashes(trim($_REQUEST['txtNoLift']));
	$selVCType    		= addslashes(trim($_REQUEST['selVCType']));
	$txtexpectedhire    = addslashes(trim($_REQUEST['txtexpectedhire']));
	$selOwner 		    = addslashes(trim($_REQUEST['selOwner']));
	$txtDisponentOwner	= addslashes(trim($_REQUEST['txtDisponentOwner']));
	if($_REQUEST['txtFDate']!="")
	{
	$txtFDate     		= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	}


	else{$txtFDate     		= "1970-01-01";}
	if($_REQUEST['txtTDate']!="")
	{
	$txtTDate     		= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	}
	else{$txtTDate     		= "1970-01-01";}
	if($_REQUEST['txtETADate']!="")
	{
	$txtETADate     		= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	}
	else{$txtETADate     		= "1970-01-01";}
	if($_REQUEST['txtCPDate']!="")
	{
	$txtCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	}
	else{$txtCPDate     		= "1970-01-01";}
	
	
	if($_REQUEST['txtLCSDate']!="")
	{
	$txtLCSDate   		= date("Y-m-d",strtotime($_REQUEST['txtLCSDate']));
	}
	else{$txtLCSDate     		= "1970-01-01";}
	if($_REQUEST['txtLCFDate']!="")
	{
	$txtLCFDate     	= date("Y-m-d",strtotime($_REQUEST['txtLCFDate']));
	}
	else{$txtLCFDate     		= "1970-01-01";}
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	$txtNotes     		= addslashes(trim($_REQUEST['txtNotes']));
	$txtDirection     	= addslashes(trim($_REQUEST['txtDirection']));
	
	$txtCID 	 		= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       = addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 		= implode(',',$_REQUEST['selMType']);
	$txtMCode    		= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance	= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    = addslashes(trim($_REQUEST['selDPort']));
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$txtCRMFILE2							= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2							= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['attach_file1']);
	$name = $this->getUploadName($_FILES['attach_file1']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	
	$rdoEstimateType      	= addslashes(trim($_REQUEST['rdoEstimateType']));
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum             = $_REQUEST['ChkLumpsum'];
	$txtLumpsum             = $_REQUEST['txtLumpsum'];
	$txtLumpsumQty          = $_REQUEST['txtLumpsumQty'];
	$selLumsumVendor        = addslashes(trim($_REQUEST['selLumsumVendor']));
	
	
	$txtBaseRateFloating    = addslashes(trim($_REQUEST['txtBaseRateFloating']));
	$txtBaseRateFixed       = addslashes(trim($_REQUEST['txtBaseRateFixed']));
	$txtBaseRateAverage     = addslashes(trim($_REQUEST['txtBaseRateAverage']));
	
	$txtGFreightFloating    = addslashes(trim($_REQUEST['txtGFreightFloating']));
	$txtGFreightFixed       = addslashes(trim($_REQUEST['txtGFreightFixed']));
	$txtGFreightAverage     = addslashes(trim($_REQUEST['txtGFreightAverage']));
	
	$txtNFreightFloating    = addslashes(trim($_REQUEST['txtNFreightFloating']));
	$txtNFreightFixed       = addslashes(trim($_REQUEST['txtNFreightFixed']));
	$txtNFreightAverage     = addslashes(trim($_REQUEST['txtNFreightAverage']));
	
	$txtOExpensesFloating   = addslashes(trim($_REQUEST['txtOExpensesFloating']));
	$txtOExpensesFixed      = addslashes(trim($_REQUEST['txtOExpensesFixed']));
	$txtOExpensesAverage    = addslashes(trim($_REQUEST['txtOExpensesAverage']));
	
	$txtVEarningFloating    = addslashes(trim($_REQUEST['txtVEarningFloating']));
	$txtVEarningFixed       = addslashes(trim($_REQUEST['txtVEarningFixed']));
	$txtVEarningAverage     = addslashes(trim($_REQUEST['txtVEarningAverage']));
	
	$txtDailyEarningFloating= addslashes(trim($_REQUEST['txtDailyEarningFloating']));
	$txtDailyEarningFixed   = addslashes(trim($_REQUEST['txtDailyEarningFixed']));
	$txtDailyEarningAverage = addslashes(trim($_REQUEST['txtDailyEarningAverage']));
	
	$txtTCEMonthFloating    = addslashes(trim($_REQUEST['txtTCEMonthFloating']));
	$txtTCEMonthFixed       = addslashes(trim($_REQUEST['txtTCEMonthFixed']));
	$txtTCEMonthAverage     = addslashes(trim($_REQUEST['txtTCEMonthAverage']));
	
	$txtOPExpensesFloating  = addslashes(trim($_REQUEST['txtOPExpensesFloating']));
	$txtOPExpensesFixed     = addslashes(trim($_REQUEST['txtOPExpensesFixed']));
	$txtOPExpensesAverage   = addslashes(trim($_REQUEST['txtOPExpensesAverage']));
	
	$txtNetDailyEarningFloating= addslashes(trim($_REQUEST['txtNetDailyEarningFloating']));
	$txtNetDailyEarningFixed= addslashes(trim($_REQUEST['txtNetDailyEarningFixed']));
	$txtNetDailyEarningAverage= addslashes(trim($_REQUEST['txtNetDailyEarningAverage']));
	
	$txtNetDailyProfitFloating= addslashes(trim($_REQUEST['txtNetDailyProfitFloating']));
	$txtNetDailyProfitFixed = addslashes(trim($_REQUEST['txtNetDailyProfitFixed']));
	$txtNetDailyProfitAverage= addslashes(trim($_REQUEST['txtNetDailyProfitAverage']));
	$selCargoPlanning = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	$txtSDWTMT 	 	    = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	 		= addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM         = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 	 	= addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT     	 	= addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT    		= addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT    		= addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT           = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT     = addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT  	= addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM 	= addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT		= addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM   = addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT	 	= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT 	= addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT    	= addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT  		= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$rdoTankType        = addslashes(trim($_REQUEST['rdoTankType']));
	$txtTCNo            = addslashes(trim($_REQUEST['txtTCNo']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	$selPeriodContract = addslashes(trim($_REQUEST['selPeriodContract']));
	
	$txtBLCQMT              = addslashes(trim($_REQUEST['txtBLCQMT']));
	$txtLessPerQty          = addslashes(trim($_REQUEST['txtLessPerQty']));
	
	
	if($_REQUEST['txtTCDeliveryDate']!="")
	{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate']));}
	else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtTCReDeliveryDate']!="")
	{$txtTCReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate']));}
	else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	$txtTCDelivery = addslashes(trim($_REQUEST['txtTCDelivery']));
	$txtTCReDelivery = addslashes(trim($_REQUEST['txtTCReDelivery']));
	$txtTankerFreightRate = addslashes(trim($_REQUEST['txtTankerFreightRate']));
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));
	$chartering_pic      = addslashes(trim($_REQUEST['chartering_pic']));

	$selBusiType=addslashes(trim($_REQUEST['selBusinessType']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into freight_cost_estimete_master (FIXTURETYPEID, TRANS_DATE, MODULEID, MCOMPANYID, ADDED_BY, ADD_ON_DATE, VESSEL_IMO_ID, VESSEL_TYPE, FLAG, VOYAGE_NO, VOYAGE_NAME, DWT_SUMMER, DWT_TOPICAL, RDO_CAP, GRAIN_CAP, BALE_CAP, SF, LODABLE, GNRT, LOA, GEAR, BUILD_YEAR, BEAM, TPC, BFULLSPEED, BECOSPEED1, BECOSPEED2, LFULLSPEED, LECOSPEED1, LECOSPEED2, BFOFULLSPEED, BFOECOSPEED1, BFOECOSPEED2, LFOFULLSPEED, LFOECOSPEED1, LFOECOSPEED2, PIFOFULLSPEED, PWFOFULLSPEED, BDOFULLSPEED, BDOECOSPEED1, BDOECOSPEED2, LDOFULLSPEED, LDOECOSPEED1, LDOECOSPEED2, PIDOFULLSPEED, PWDOFULLSPEED, RDO_MARKER, RDO_DWT, FREIGHT_GROSS, LUMSUM, CARGO_RATE, QUANTITY, CARGO_TYPE, CARGO_ID, DF_QUANTITY, ADDNL_QUANTITY, LADEN_DIST, BALLAST_DIST, LADEN_DAYS, BALLAST_DAYS, TOTAL_PASSAGE_DAYS, IDEAL_DAYS, WORKING_DAYS, TOTAL_DAYS, TOTAL_DISTANCE, FO_CONSP, DO_CONSP, GROSS_PREIGHT_ADJ, DEAD_PREIGHT_ADJ, ADDNL_PREIGHT_ADJ, TOTAL_PREIGHT_ADJ, GROSS_PREIGHT_ADJ_PRMT, DEAD_PREIGHT_ADJ_PRMT, ADDNL_PREIGHT_ADJ_PRMT, TOTAL_PREIGHT_ADJ_PRMT, ADDRESS_COMMISSION_PER, ADDRESS_COMMISSION_AMT, ADDRESS_COMMISSION_PRMT, BROKERAGE_PER, BROKERAGE_AMT, NET_PAYABLE, FINAL_NET_FREIGHT, FINAL_NET_FREIGHT_PRMT, BROKERAGE_COMMISSION_PER, BROKERAGE_COMMISSION_AMT, REVENUES_FREIGHT, VOYAGE_EARNING, DAILY_EARNING, DAILY_VESSEL_OPERATION_EXP, TOTAL_VOYAGE_EARNING, NET_DAILY_EARNING, NET_DAILY_PROFIT, PROFIT_LOSS, RDO_QTY, HIREAGE_AMT, HIREAGE_PERCENT, HIREAGE_PER_AMT, HIREAGE_NETT_AMT, CVE_AMT, CVE_TOTALAMT, BALLAST_BONUS, BUNKER_EXPENSES, PORT_EXPENSES, QTY_TYPE_RADIO, AGREED_GROSS_FREIGHT_LOCAL, CURRENCYID, EXCHANGE_RATE, DISTRIBUTED_REMARKS, OPEN_PORT, ZONE_OPEN, BROKER, COA_SPOT, COA_NUMBER, COA_NUMBER_LIFT, NO_OF_SHIPMENT, OWNER, DISPONENT_OWNER, LAYCAN_START_DATE, LAYCAN_FINISH_DATE, ETA_DATE, CP_DATE, REMARKS, ATTACHMENT, ATTACHMENT_NAME, CARGOID, SHIPPER, TOLERANCE, MATERIALID, MATERIAL_CODE, TERM_TOLERANCE, LPID, DPID, LAYCAN_CARGO_START_DATE, LAYCAN_CARGO_FINISH_DATE, ADDNL_FREIGHT_PER, ESTIMATE_TYPE, GAS_MARKET, GAS_BALTIC, ADDNL_PRENIUM, GAS_BASE_RATE, GAS_QUANTITY, GAS_LUMSUM, TANK_WS_FROM, TANK_WS_TO, TANK_FIXED_DIFF, TANK_QUANTITY, ATTACHMENT2, ATTACHMENT2_NAME, CHK_LUMPSUM, LUMPSUMAMT, WS_QTY, LUMP_VENDOR, IF_BENCHMARK, BASERATE_FLOAT, BASERATE_FIXED, BASERATE_AVERAGE, GROSS_FREIGHT_FLOAT, GROSS_FREIGHT_FIXED, GROSS_FREIGHT_AVERAGE, NETFREIGHT_FLOAT, NETFREIGHT_FIXED, NETFREIGHT_AVERAGE, OWNER_EXPENSES_FLOAT, OWNER_EXPENSES_FIXED, OWNER_EXPENSES_AVERAGE, VEARNING_FLOAT, VEARNING_FIXED, VEARNING_AVERAGE, TCEEARNING_FLOAT, TCEEARNING_FIXED, TCEEARNING_AVERAGE, TCE_MONTH_FLOAT, TCE_MONTH_FIXED, TCE_MONTH_AVERAGE, OEXPENSES_FLOAT, OEXPENSES_FIXED, OEXPENSES_AVERAGE, NET_DAILY_ER_FLOAT, NET_DAILY_ER_FIXED, NET_DAILY_ER_AVERAGE, NET_DAILY_PROFIT_FLOAT, NET_DAILY_PROFIT_FIXED, NET_DAILY_PROFIT_AVERAGE, OPEN_CARGOID, SUMMERDWTMT, SUMMERDWTLT, SUMMERDRAFTM, SUMMERDRAFTFT, TPI_MT_INCH, TPI_LT_INCH, TPC_MT, TPC_LT, CONSTANT_MT, CONSTANT_LT, GRAIN_CAP_CBM, GRAIN_CAP_CFT, ALLOWED_DRAFTM, BUNKER_ROB_MT, CARGO_INTAKE_MT, SF_CBM_MT, SF_CBFT_MT, CARGO_LOADABLE_MT, GROSS_BREAKDOWN, BREAKDOWN_MT, TANKER_RADIO_SINGLE_DIS, TC_NO, GROSS_HIERAGE_AMOUNT, HIERAGE_CVE, HIERAGE_CVE_AMOUNT, OFF_HIRE_CVE, OFF_HIRE_CVE_AMOUNT, LESS_OFF_HIRE, FINAL_HIERAGE_AMOUNT, HIERAGE_BROKER_PERCENT, HIERAGE_BROKER_AMT, TC_HIRE_DAYS, TC_CP_DATE, PERIODID, LESS_PER_BLQTY, BL_QTY_FREIGHT, TC_DELIVERY_DATE, TC_RE_DELIVERY_DATE, TC_DELIVERY_RANGE, TC_RE_DELIVERY_RANGE, ACTUAL_PL, TANKER_FREIGHT_RATE, TANK_CLEANING_SECA_HRS, TANK_CLEANING_NONSECA_HRS, INERTING_SECA_HRS, INERTING_NONSECA_HRS, GAS_FREEING_SECA_HRS, GAS_FREEING_NONSECA_HRS, HEATING_SECA_HRS, HEATING_NONSECA_HRS, HEATING_SECA_HRS_1, HEATING_NONSECA_HRS_1,CHARTERING_PIC,SEL_BUSI_TYPE) values ('".$this->getCheckNullValue($selFType)."', '".$txtDate."', '".$this->getCheckNullValue($_SESSION['moduleid'])."', '".$this->getCheckNullValue($_SESSION['company'])."', '".$_SESSION['uid']."', NOW(), '".$this->getCheckNullValue($selVName)."', '".$txtVType."', '".$txtFlag."', '".$txtVNo."', '".$txtENo."', '".$this->getCheckNullValue($txtDWTS)."', '".$this->getCheckNullValue($txtDWTT)."', '".$this->getCheckNullValue($rdoCap)."', '".$this->getCheckNullValue($txtGCap)."', '".$this->getCheckNullValue($txtBCap)."', '".$this->getCheckNullValue($txtSF)."', '".$this->getCheckNullValue($txtLoadable)."', '".$this->getCheckNullValue($txtGNRT)."', '".$this->getCheckNullValue($txtLOA)."', '".$this->getCheckNullValue($txtGear)."', '".$txtBuiltYear."', '".$this->getCheckNullValue($txtBeam)."', '".$this->getCheckNullValue($txtTPC)."', '".$this->getCheckNullValue($txtBFullSpeed)."', '".$this->getCheckNullValue($txtBEcoSpeed1)."', '".$this->getCheckNullValue($txtBEcoSpeed2)."', '".$this->getCheckNullValue($txtLFullSpeed)."', '".$this->getCheckNullValue($txtLEcoSpeed1)."', '".$this->getCheckNullVal($txtLEcoSpeed2)."', '".$this->getCheckNullVal($txtBFOFullSpeed)."', '".$this->getCheckNullVal($txtBFOEcoSpeed1)."', '".$this->getCheckNullVal($txtBFOEcoSpeed2)."', '".$this->getCheckNullVal($txtLFOFullSpeed)."', '".$this->getCheckNullVal($txtLFOEcoSpeed1)."', '".$this->getCheckNullVal($txtLFOEcoSpeed2)."', '".$this->getCheckNullValue($txtPIFOFullSpeed)."', '".$this->getCheckNullValue($txtPWFOFullSpeed)."','".$this->getCheckNullValue($txtBDOFullSpeed)."','".$this->getCheckNullValue($txtBDOEcoSpeed1)."', '".$this->getCheckNullVal($txtBDOEcoSpeed2)."', '".$this->getCheckNullVal($txtLDOFullSpeed)."', '".$this->getCheckNullVal($txtLDOEcoSpeed1)."', '".$this->getCheckNullVal($txtLDOEcoSpeed2)."', '".$this->getCheckNullVal($txtPIDOFullSpeed)."', '".$this->getCheckNullVal($txtPWDOFullSpeed)."','".$this->getCheckNullVal($rdoMMarket)."','".$this->getCheckNullValue($rdoDWT)."','".$this->getCheckNullVal($txtMTCPDRate)."','".$this->getCheckNullVal($txtMLumpsum)."','".$this->getCheckNullVal($txtAddnlCRate)."','".$this->getCheckNullVal($txtCQMT)."','".$this->getCheckNullVal($selCType)."','".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."','".$this->getCheckNullVal($txtDFQMT)."', '".$this->getCheckNullValue($txtAddnlQMT)."', '".$this->getCheckNullValue($txtLDist)."','".$this->getCheckNullValue($txtBDist)."','".$this->getCheckNullValue($txtLDays)."','".$this->getCheckNullVal($txtBDays)."','".$this->getCheckNullVal($txtTSDays)."','".$this->getCheckNullVal($txtTtPIDays)."','".$this->getCheckNullVal($txtTtPWDays)."','".$this->getCheckNullVal($txtTDays)."','".$this->getCheckNullVal($txtTDist)."','".$this->getCheckNullVal($txtTFUMT)."', '".$this->getCheckNullVal($txtTDUMT)."','".$this->getCheckNullValue($txtFrAdjUsdGF)."','".$this->getCheckNullVal($txtFrAdjUsdDF)."','".$this->getCheckNullVal($txtFrAdjUsdAF)."','".$this->getCheckNullVal($txtFrAdjUsdTF)."','".$this->getCheckNullVal($txtFrAdjUsdGFMT)."','".$this->getCheckNullVal($txtFrAdjUsdDFMT)."','".$this->getCheckNullVal($txtFrAdjUsdAFMT)."'  ,'".$this->getCheckNullVal($txtFrAdjUsdTFMT)."',    '".$this->getCheckNullValue($txtFrAdjPerAC)."', '".$this->getCheckNullValue($txtFrAdjUsdAC)."', '".$this->getCheckNullValue($txtFrAdjUsdACMT)."','".$this->getCheckNullValue($txtFrAdjPerAgC)."','".$this->getCheckNullVal($txtFrAdjUsdAgC)."','".$this->getCheckNullVal($txtFrAdjUsdFP)."','".$this->getCheckNullVal($txtFGFFD)."','".$this->getCheckNullVal($txtFGFFDMT)."',  '".$this->getCheckNullVal($txtBrCommPercent)."','".$this->getCheckNullVal($txtBrComm)."', '".$this->getCheckNullVal($txtRevenue)."', '".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtDailyEarnings)."','".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."','".$this->getCheckNullVal($txtGTTLVoyageEarnings)."','".$this->getCheckNullVal($txtNettDailyEarnings)."','".$this->getCheckNullVal($txtNettDailyProfit)."',  '".$this->getCheckNullVal($txtPL)."', '".$this->getCheckNullVal($rdoQty)."','".$this->getCheckNullVal($txtHireargeAmt)."','".$this->getCheckNullVal($txtHireargePercent)."','".$this->getCheckNullVal($txtHireargePercentAmt)."', '".$this->getCheckNullVal($txtNettHireargeAmt)."', '".$this->getCheckNullVal($txtCVE)."', '".$this->getCheckNullVal($txtCVEAmt)."', '".$this->getCheckNullVal($txtBallastBonus)."', '".$this->getCheckNullVal($txtTotalBunkerCost)."', '".$this->getCheckNullVal($txtTotalPortCost)."', '".$rdoQtyType."', '".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', '".$this->getCheckNullVal($selCurrencyMarList)."', '".$this->getCheckNullVal($txtMarExchangeRate)."' , '".$txtDistributedRemarks."', '".$selOpenPort."', '".$selZone."', '".$selBroker."', '".$selCOASpot."', '".$selCOA."', '".$txtNoLift."', '', '".$selOwner."', '".$txtDisponentOwner."', '".$txtFDate."', '".$txtTDate."', '".$txtETADate."', '".$txtCPDate."', '".$txtNotes."', '".$upload1."', '".$name1."', '".$txtCID."', '".$selShipper."', '".$txtTolerance."', '".$selMType."', '".$txtMCode."', '".$txtTermTolerance."', '".$selLPort."', '".$selDPort."', '".$txtLCSDate."', '".$txtLCFDate."', '".$this->getCheckNullVal($txtAddnlCRatePer)."' , '".$this->getCheckNullVal($rdoEstimateType)."', '".$this->getCheckNullVal($rdoQtyMar)."', '".$this->getCheckNullVal($txtBalticRate)."', '".$this->getCheckNullVal($txtAdnlPrenium)."', '".$this->getCheckNullVal($txtBaseRate)."', '".$this->getCheckNullVal($txtGasCQMT)."', '".$this->getCheckNullVal($txtGASLumpsum)."', '".$this->getCheckNullVal($selWSFPort)."', '".$this->getCheckNullVal($selWSTPort)."', '".$this->getCheckNullVal($txtFixedDiff)."', '".$this->getCheckNullVal($txtTankQuantity)."', '".$upload2."', '".$name2."', '".$this->getCheckNullVal($ChkLumpsum)."', '".$this->getCheckNullVal($txtLumpsum)."', '".$this->getCheckNullVal($txtLumpsumQty)."', '".$selLumsumVendor."', '".$txtBStatus."', '".$this->getCheckNullVal($txtBaseRateFloating)."', '".$this->getCheckNullVal($txtBaseRateFixed)."', '".$this->getCheckNullVal($txtBaseRateAverage)."', '".$this->getCheckNullVal($txtGFreightFloating)."', '".$this->getCheckNullVal($txtGFreightFixed)."', '".$this->getCheckNullVal($txtGFreightAverage)."', '".$this->getCheckNullVal($txtNFreightFloating)."', '".$this->getCheckNullVal($txtNFreightFixed)."', '".$this->getCheckNullVal($txtNFreightAverage)."', '".$this->getCheckNullVal($txtOExpensesFloating)."', '".$this->getCheckNullVal($txtOExpensesFixed)."', '".$this->getCheckNullVal($txtOExpensesAverage)."', '".$this->getCheckNullVal($txtVEarningFloating)."', '".$this->getCheckNullVal($txtVEarningFixed)."', '".$this->getCheckNullVal($txtVEarningAverage)."', '".$this->getCheckNullVal($txtDailyEarningFloating)."', '".$this->getCheckNullVal($txtDailyEarningFixed)."', '".$this->getCheckNullVal($txtDailyEarningAverage)."', '".$this->getCheckNullVal($txtTCEMonthFloating)."', '".$this->getCheckNullVal($txtTCEMonthFixed)."', '".$this->getCheckNullVal($txtTCEMonthAverage)."', '".$this->getCheckNullVal($txtOPExpensesFloating)."', '".$this->getCheckNullVal($txtOPExpensesFixed)."', '".$this->getCheckNullVal($txtOPExpensesAverage)."', '".$this->getCheckNullVal($txtNetDailyEarningFloating)."', '".$this->getCheckNullVal($txtNetDailyEarningFixed)."', '".$this->getCheckNullVal($txtNetDailyEarningAverage)."', '".$this->getCheckNullVal($txtNetDailyProfitFloating)."', '".$this->getCheckNullVal($txtNetDailyProfitFixed)."', '".$this->getCheckNullVal($txtNetDailyProfitAverage)."', '".$this->getCheckNullVal($selCargoPlanning)."', '".$this->getCheckNullVal($txtSDWTMT)."', '".$this->getCheckNullVal($txtSDWTLT)."', '".$this->getCheckNullVal($txtSDraftM)."', '".$this->getCheckNullVal($txtSDraftFT)."', '".$this->getCheckNullVal($txtTPIMT)."', '".$this->getCheckNullVal($txtTPILT)."', '".$this->getCheckNullVal($txtTPCMT)."', '".$this->getCheckNullVal($txtTPCLT)."', '".$this->getCheckNullVal($txtConstantsMT)."', '".$this->getCheckNullVal($txtConstantsLT)."', '".$this->getCheckNullVal($txtGrainCapCBM)."', '".$this->getCheckNullVal($txtGrainCapCFT)."', '".$this->getCheckNullVal($txtAllawedDraftM)."', '".$this->getCheckNullVal($txtBunkerRobMT)."', '".$this->getCheckNullVal($txtCargoIntakeMT)."', '".$this->getCheckNullVal($txtSFCBM_MT)."', '".$this->getCheckNullVal($txtSFCBFT_MT)."', '".$this->getCheckNullVal($txtCargoLoadableMT)."', '".$this->getCheckNullVal($txtGrossBreakeven)."', '".$this->getCheckNullVal($txtBreakevenMT)."', '".$rdoTankType."', '".$txtTCNo."', '".$this->getCheckNullVal($txtGrossHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeCVE)."', '".$this->getCheckNullVal($txtHireargeCVEAMT)."', '".$this->getCheckNullVal($txtOffHireCVE)."', '".$this->getCheckNullVal($txtOffHireCVEAMT)."', '".$this->getCheckNullVal($txtLessOffHire)."', '".$this->getCheckNullVal($txtFinalHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeBroPercent)."', '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', '".$this->getCheckNullVal($txtTotalVoyageDays)."', '".$txtTC_CPDate."', '".$this->getCheckNullValue($selPeriodContract)."', '".$this->getCheckNullValue($txtLessPerQty)."', '".$this->getCheckNullValue($txtBLCQMT)."', '".$txtTCDeliveryDate."', '".$txtTCReDeliveryDate."', '".$txtTCDelivery."', '".$txtTCReDelivery."', '".$this->getCheckNullVal($txtPL)."', '".$this->getCheckNullVal($txtTankerFreightRate)."', '".$this->getCheckNullVal($txtTKSECAHrs)."', '".$this->getCheckNullVal($txtTKNONSECAHrs)."', '".$this->getCheckNullVal($txtInertSECAHrs)."', '".$this->getCheckNullVal($txtInertNONSECAHrs)."', '".$this->getCheckNullVal($txtGFSECAHrs)."', '".$this->getCheckNullVal($txtGFNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs1)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs1)."','".$this->getCheckNullVal($chartering_pic)."','".$this->getCheckNullVal($selBusiType)."')";
	
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$mysql = "select max(FCAID) as max from freight_cost_estimete_master";
	$myres  =  mysql_query($mysql,$connect);
	$myrows = mysql_fetch_assoc($myres);
	$maxid = $myrows['max'];
	
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{
			$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			
			$sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_NETCOST, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_NETCOST, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, DDCLP_COMM, DDCDP_COMM, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['ChkShowDDCLP_'.$i]."','".$_REQUEST['ChkShowDDCDP_'.$i]."','".$randomid."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] >0)
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."',1,'".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] >0)
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] >0)
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		$txtTID = $_REQUEST['txtTID'];
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtDisponentOwner_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_slave5 (FCAID, DISPONENT_OWNER) values ('".$maxid."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$txtQTYID = $_REQUEST['txtQTYID'];
		for($i=1 ; $i<=$txtQTYID ;$i++)
		{
			if($_REQUEST['selQtyVendorList_'.$i] != "")
			{
			    $randomid = $_REQUEST['txtQtySlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtQtySlaveRandomID_'.$i]) || $_REQUEST['txtQtySlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql2 = "insert into freight_cost_estimete_slave7 (FCAID, QTY_VENDORID, AGREED_GROSS_FREIGHT, QUANTITY, GROSS_FREIGHT, BROKERAGE, NET_BROKERAGE, NET_FREIGHT, NET_FREIGHT_PERMT, CURRENCYID, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, CARGO, RANDOMID) values ('".$maxid."','".$_REQUEST['selQtyVendorList_'.$i]."','".$_REQUEST['txtQtyAggriedFreight_'.$i]."','".$_REQUEST['txtFreightQty_'.$i]."','".$_REQUEST['txtQtyFreight_'.$i]."','".$_REQUEST['txtQtyBrokeragePer_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtQtyBrokerageAmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreightMT1_'.$i])."','".$this->getCheckNullVal($_REQUEST['selCurrencyDisList_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyLocalAggriedFreight_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDisExchangeRate_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selQtyCargo_'.$i])."', '".$randomid."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		} 
		
		
		$txtTankID = $_REQUEST['txtTankID'];
		for($i=1 ; $i<=$txtTankID ;$i++)
		{
			if($_REQUEST['txtFreightSpecs_'.$i] != "")
			{
				$sql12 = "insert into freight_cost_estimete_slave12 (FCAID, FREIGHT_SPECS, CUSTOMER, MIN_CARGO_QTY, OVE_CARGO_QTY, MIN_FLAT_RATE, OVE_FLAT_RATE, MIN_WS, OVE_WS, MIN_DIS_LEG, OVE_DIS_LEG, MIN_DISTANCE, OVE_DISTANCE, MIN_AMOUNT, OVE_AMOUNT, TOTAL_QTY, TOTAL_AMOUNT) values ('".$maxid."', '".$_REQUEST['txtFreightSpecs_'.$i]."', '".$_REQUEST['selTankVendor_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtMinCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtOveCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinDisLeg_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveDisLeg_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinTotalDis_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveTotalDis_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinAmount_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtTotalTankQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTotalTankAmount_'.$i])."')";
				mysql_query($sql12) or die($sql12);
				mysql_query("commit");
			}
		} 
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$txtHIREID = $_REQUEST['txtHIREID'];
		for($i=1 ; $i<=$txtHIREID ;$i++)
		{
			if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
			{
				if($_REQUEST['txtHireFrom_'.$i]!="")
				{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
				else{$txtHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtHireTo_'.$i]!="")
				{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
				else{$txtHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCHireRandom_'.$i]) || $_REQUEST['txtTCHireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCHireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave17 (FCAID, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE, HIRE_AMT, RANDOMID) values ('".$maxid."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireAmt_'.$i])."', '".$this->getCheckNullValue($randomid4)."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$maxid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$maxid."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
					    if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
			
	return $msg; 
}

function deleteFCETempleteRecordsNew()
{
	$connect				= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['delId']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	
	$del_query1 = "delete from  freight_cost_estimete_master where FCAID='".$id."'";
	$del_query2 = "delete from  freight_cost_estimete_slave1 where FCAID='".$id."'";
	$del_query3 = "delete from  freight_cost_estimete_slave2 where FCAID='".$maxid."'";
	$del_query4 = "delete from  freight_cost_estimete_slave3 where FCAID='".$maxid."'";
	$del_query5 = "delete from  freight_cost_estimete_slave4 where FCAID='".$maxid."'";
	$del_query8 = "delete from  freight_cost_estimete_slave8 where FCAID='".$maxid."'";
	$del_query9 = "delete from  freight_cost_estimete_slave9 where FCAID='".$maxid."'";
	$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$maxid."'";
	$del_query11 = "delete from  freight_cost_estimete_slave11 where FCAID='".$maxid."'";
	$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$maxid."'";
	$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$maxid."'";
	$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$maxid."'";
	$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$maxid."'";
	$del_query16 = "delete from  freight_cost_estimete_slave16 where FCAID='".$maxid."'";
	$del_query17 = "delete from  freight_cost_estimete_slave17 where FCAID='".$id."'";
	mysql_query($del_query1);
	mysql_query($del_query2);
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query($del_query5);
	mysql_query($del_query8);
	mysql_query($del_query9);
	mysql_query($del_query10);
	mysql_query($del_query11);
	mysql_query($del_query12);
	mysql_query($del_query13);
	mysql_query($del_query14);
	mysql_query($del_query15);
	mysql_query($del_query16);
	mysql_query($del_query17);
	mysql_query("commit");
	 
	return $msg;
}


function deleteCOACargoRelateRecordsNew()
{
	$connect		= $this->funConnect();
 	$id 			= addslashes(trim($_REQUEST['txttblid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	
	$del_query1 = "delete from  cargo_relet_estimate_masster where FCAID='".$id."'";
	$del_query2 = "delete from  cargo_relet_estimate_slave1 where FCAID='".$id."'";
	$del_query3 = "delete from  cargo_relet_estimate_slave2 where FCAID='".$maxid."'";
	
	mysql_query($del_query1);
	mysql_query($del_query2);
	mysql_query($del_query3);
	mysql_query("commit");
	 
	return $msg;
}





function updateTCITemplateDetailsNew($id)
{
	$connect = $this->funConnect();
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 		= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	$market_rdo 		= addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	$txtAddnlCRate 		= addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlCRatePer   = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
    $txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	$txtCVE             = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt      	= addslashes(trim($_REQUEST['txtCVEAmt']));
	$txtHidCVEAmt   	= addslashes(trim($_REQUEST['txtHidCVEAmt']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	$txtDistributedRemarks     = addslashes(trim($_REQUEST['txtDistributedRemarks']));
	
	
	$selOpenPort 	 	= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 		= addslashes(trim($_REQUEST['selZone']));
	$selBroker          = addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 	= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 	= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    		= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    = addslashes(trim($_REQUEST['selOwner']));
	$txtDisponentOwner	= addslashes(trim($_REQUEST['txtDisponentOwner']));
	if($_REQUEST['txtFDate']!="")
	{
	$txtFDate     		= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	}


	else{$txtFDate     		= "1970-01-01";}
	if($_REQUEST['txtTDate']!="")
	{
	$txtTDate     		= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	}
	else{$txtTDate     		= "1970-01-01";}
	if($_REQUEST['txtETADate']!="")
	{
	$txtETADate     		= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	}
	else{$txtETADate     		= "1970-01-01";}
	if($_REQUEST['txtCPDate']!="")
	{
	$txtCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	}
	else{$txtCPDate     		= "1970-01-01";}
	$txtNotes     		= addslashes(trim($_REQUEST['txtNotes']));
	
	
	$txtCID 	 		= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       = addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 		= implode(',',$_REQUEST['selMType']);
	$txtMCode    		= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance	= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    = addslashes(trim($_REQUEST['selDPort']));
	
	if($_REQUEST['txtLCSDate']!="")
	{
	$txtLCSDate   		= date("Y-m-d",strtotime($_REQUEST['txtLCSDate']));
	}
	else{$txtLCSDate     		= "1970-01-01";}
	if($_REQUEST['txtLCFDate']!="")
	{
	$txtLCFDate     	= date("Y-m-d",strtotime($_REQUEST['txtLCFDate']));
	}
	else{$txtLCFDate     		= "1970-01-01";}
	
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$txtLumpsumQty          = $_REQUEST['txtLumpsumQty'];
	$selLumsumVendor        = addslashes(trim($_REQUEST['selLumsumVendor']));
	
	$txtBaseRateFloating    = addslashes(trim($_REQUEST['txtBaseRateFloating']));
	$txtBaseRateFixed       = addslashes(trim($_REQUEST['txtBaseRateFixed']));
	$txtBaseRateAverage     = addslashes(trim($_REQUEST['txtBaseRateAverage']));
	
	$txtGFreightFloating    = addslashes(trim($_REQUEST['txtGFreightFloating']));
	$txtGFreightFixed       = addslashes(trim($_REQUEST['txtGFreightFixed']));
	$txtGFreightAverage     = addslashes(trim($_REQUEST['txtGFreightAverage']));
	
	$txtNFreightFloating    = addslashes(trim($_REQUEST['txtNFreightFloating']));
	$txtNFreightFixed       = addslashes(trim($_REQUEST['txtNFreightFixed']));
	$txtNFreightAverage     = addslashes(trim($_REQUEST['txtNFreightAverage']));
	
	$txtOExpensesFloating   = addslashes(trim($_REQUEST['txtOExpensesFloating']));
	$txtOExpensesFixed      = addslashes(trim($_REQUEST['txtOExpensesFixed']));
	$txtOExpensesAverage    = addslashes(trim($_REQUEST['txtOExpensesAverage']));
	
	$txtVEarningFloating    = addslashes(trim($_REQUEST['txtVEarningFloating']));
	$txtVEarningFixed       = addslashes(trim($_REQUEST['txtVEarningFixed']));
	$txtVEarningAverage     = addslashes(trim($_REQUEST['txtVEarningAverage']));
	
	$txtDailyEarningFloating= addslashes(trim($_REQUEST['txtDailyEarningFloating']));
	$txtDailyEarningFixed   = addslashes(trim($_REQUEST['txtDailyEarningFixed']));
	$txtDailyEarningAverage = addslashes(trim($_REQUEST['txtDailyEarningAverage']));
	
	$txtTCEMonthFloating    = addslashes(trim($_REQUEST['txtTCEMonthFloating']));
	$txtTCEMonthFixed       = addslashes(trim($_REQUEST['txtTCEMonthFixed']));
	$txtTCEMonthAverage     = addslashes(trim($_REQUEST['txtTCEMonthAverage']));
	
	$txtOPExpensesFloating  = addslashes(trim($_REQUEST['txtOPExpensesFloating']));
	$txtOPExpensesFixed     = addslashes(trim($_REQUEST['txtOPExpensesFixed']));
	$txtOPExpensesAverage   = addslashes(trim($_REQUEST['txtOPExpensesAverage']));
	
	$txtNetDailyEarningFloating= addslashes(trim($_REQUEST['txtNetDailyEarningFloating']));
	$txtNetDailyEarningFixed= addslashes(trim($_REQUEST['txtNetDailyEarningFixed']));
	$txtNetDailyEarningAverage= addslashes(trim($_REQUEST['txtNetDailyEarningAverage']));
	
	$txtNetDailyProfitFloating= addslashes(trim($_REQUEST['txtNetDailyProfitFloating']));
	$txtNetDailyProfitFixed = addslashes(trim($_REQUEST['txtNetDailyProfitFixed']));
	$txtNetDailyProfitAverage= addslashes(trim($_REQUEST['txtNetDailyProfitAverage']));
	$selCargoPlanning  = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	
	$txtSDWTMT 	 	    = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	 		= addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM         = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 	 	= addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT     	 	= addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT    		= addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT    		= addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT           = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT     = addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT  	= addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM 	= addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT		= addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM   = addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT	 	= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT 	= addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT    	= addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT  		= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$rdoTankType        = addslashes(trim($_REQUEST['rdoTankType']));
	$txtTCNo            = addslashes(trim($_REQUEST['txtTCNo']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	$selPeriodContract = addslashes(trim($_REQUEST['selPeriodContract']));
	$txtBLCQMT              = addslashes(trim($_REQUEST['txtBLCQMT']));
    $txtLessPerQty          = addslashes(trim($_REQUEST['txtLessPerQty']));
	
    $txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$txtCRMFILE2							= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2							= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload2 = $this->getUpload($_FILES['attach_file1']);
	$name2 = $this->getUploadName($_FILES['attach_file1']);
	
	$upload2 = implode(',',$upload2);
	$name2 = implode(',',$name2);
	
	if($txtCRMFILE2 != '' && $upload2 != ''){ $upload2 = $txtCRMFILE2.','.$upload2;}
	else if($txtCRMFILE2 == '' && $upload2 != ''){ $upload2 = $upload2;}
	else if($txtCRMFILE2 != '' && $upload2 == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name2 != ''){ $name2 = $txtCRMNAME2.','.$name2;}
	else if($txtCRMNAME2 == '' && $name2 != ''){ $name2 = $name2;}
	else if($txtCRMNAME2 != '' && $name2 == ''){ $name2 = $txtCRMNAME2;}
	
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	
	if($_REQUEST['txtTCDeliveryDate']!="")
	{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate']));}
	else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtTCReDeliveryDate']!="")
	{$txtTCReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate']));}
	else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	$txtTCDelivery = addslashes(trim($_REQUEST['txtTCDelivery']));
	$txtTCReDelivery = addslashes(trim($_REQUEST['txtTCReDelivery']));
	$txtTankerFreightRate = addslashes(trim($_REQUEST['txtTankerFreightRate']));
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));

	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	
	$sql = "update freight_cost_estimete_master set FIXTURETYPEID='".$this->getCheckNullValue($selFType)."', TRANS_DATE='".$txtDate."', ADD_ON_DATE=NOW(), VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', VESSEL_TYPE='".$txtVType."', FLAG='".$txtFlag."', VOYAGE_NO='".$txtVNo."', VOYAGE_NAME='".$txtENo."', DWT_SUMMER='".$this->getCheckNullValue($txtDWTS)."', DWT_TOPICAL='".$this->getCheckNullValue($txtDWTT)."', RDO_CAP='".$this->getCheckNullValue($rdoCap)."', GRAIN_CAP='".$this->getCheckNullValue($txtGCap)."', BALE_CAP='".$this->getCheckNullValue($txtBCap)."', SF='".$this->getCheckNullValue($txtSF)."', LODABLE='".$this->getCheckNullValue($txtLoadable)."', GNRT='".$this->getCheckNullValue($txtGNRT)."', LOA='".$this->getCheckNullValue($txtLOA)."', GEAR='".$this->getCheckNullValue($txtGear)."', BUILD_YEAR='".$txtBuiltYear."', BEAM='".$this->getCheckNullValue($txtBeam)."', TPC='".$this->getCheckNullValue($txtTPC)."', BFULLSPEED='".$this->getCheckNullValue($txtBFullSpeed)."', BECOSPEED1='".$this->getCheckNullValue($txtBEcoSpeed1)."', BECOSPEED2='".$this->getCheckNullValue($txtBEcoSpeed2)."', LFULLSPEED='".$this->getCheckNullValue($txtLFullSpeed)."', LECOSPEED1='".$this->getCheckNullValue($txtLEcoSpeed1)."', LECOSPEED2='".$this->getCheckNullVal($txtLEcoSpeed2)."', BFOFULLSPEED='".$this->getCheckNullVal($txtBFOFullSpeed)."', BFOECOSPEED1='".$this->getCheckNullVal($txtBFOEcoSpeed1)."', BFOECOSPEED2='".$this->getCheckNullVal($txtBFOEcoSpeed2)."', LFOFULLSPEED='".$this->getCheckNullVal($txtLFOFullSpeed)."', LFOECOSPEED1='".$this->getCheckNullVal($txtLFOEcoSpeed1)."', LFOECOSPEED2='".$this->getCheckNullVal($txtLFOEcoSpeed2)."', PIFOFULLSPEED='".$this->getCheckNullValue($txtPIFOFullSpeed)."', PWFOFULLSPEED='".$this->getCheckNullValue($txtPWFOFullSpeed)."', BDOFULLSPEED='".$this->getCheckNullValue($txtBDOFullSpeed)."', BDOECOSPEED1='".$this->getCheckNullValue($txtBDOEcoSpeed1)."', BDOECOSPEED2='".$this->getCheckNullVal($txtBDOEcoSpeed2)."', LDOFULLSPEED='".$this->getCheckNullVal($txtLDOFullSpeed)."', LDOECOSPEED1='".$this->getCheckNullVal($txtLDOEcoSpeed1)."', LDOECOSPEED2='".$this->getCheckNullVal($txtLDOEcoSpeed2)."', PIDOFULLSPEED='".$this->getCheckNullVal($txtPIDOFullSpeed)."', PWDOFULLSPEED='".$this->getCheckNullVal($txtPWDOFullSpeed)."', RDO_MARKER='".$this->getCheckNullVal($rdoMMarket)."', RDO_DWT='".$this->getCheckNullValue($rdoDWT)."', FREIGHT_GROSS='".$this->getCheckNullVal($txtMTCPDRate)."', LUMSUM='".$this->getCheckNullVal($txtMLumpsum)."', CARGO_RATE='".$this->getCheckNullVal($txtAddnlCRate)."', QUANTITY='".$this->getCheckNullVal($txtCQMT)."', CARGO_TYPE='".$this->getCheckNullVal($selCType)."', CARGO_ID='".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."', DF_QUANTITY='".$this->getCheckNullVal($txtDFQMT)."', ADDNL_QUANTITY='".$this->getCheckNullValue($txtAddnlQMT)."', LADEN_DIST='".$this->getCheckNullValue($txtLDist)."', BALLAST_DIST='".$this->getCheckNullValue($txtBDist)."', LADEN_DAYS='".$this->getCheckNullValue($txtLDays)."', BALLAST_DAYS='".$this->getCheckNullVal($txtBDays)."', TOTAL_PASSAGE_DAYS='".$this->getCheckNullVal($txtTSDays)."', IDEAL_DAYS='".$this->getCheckNullVal($txtTtPIDays)."', WORKING_DAYS='".$this->getCheckNullVal($txtTtPWDays)."', TOTAL_DAYS='".$this->getCheckNullVal($txtTDays)."', TOTAL_DISTANCE='".$this->getCheckNullVal($txtTDist)."', FO_CONSP='".$this->getCheckNullVal($txtTFUMT)."', DO_CONSP='".$this->getCheckNullVal($txtTDUMT)."', GROSS_PREIGHT_ADJ='".$this->getCheckNullValue($txtFrAdjUsdGF)."', DEAD_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdDF)."', ADDNL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdAF)."', TOTAL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdTF)."', GROSS_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdGFMT)."', DEAD_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdDFMT)."', ADDNL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdAFMT)."', TOTAL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdTFMT)."', ADDRESS_COMMISSION_PER='".$this->getCheckNullValue($txtFrAdjPerAC)."', ADDRESS_COMMISSION_AMT='".$this->getCheckNullValue($txtFrAdjUsdAC)."', ADDRESS_COMMISSION_PRMT='".$this->getCheckNullValue($txtFrAdjUsdACMT)."', BROKERAGE_PER='".$this->getCheckNullValue($txtFrAdjPerAgC)."', BROKERAGE_AMT='".$this->getCheckNullVal($txtFrAdjUsdAgC)."', NET_PAYABLE='".$this->getCheckNullVal($txtFrAdjUsdFP)."', FINAL_NET_FREIGHT='".$this->getCheckNullVal($txtFGFFD)."', FINAL_NET_FREIGHT_PRMT='".$this->getCheckNullVal($txtFGFFDMT)."', BROKERAGE_COMMISSION_PER='".$this->getCheckNullVal($txtBrCommPercent)."', BROKERAGE_COMMISSION_AMT='".$this->getCheckNullVal($txtBrComm)."', REVENUES_FREIGHT='".$this->getCheckNullVal($txtRevenue)."', VOYAGE_EARNING='".$this->getCheckNullValue($txtVoyageEarnings)."', DAILY_EARNING='".$this->getCheckNullValue($txtDailyEarnings)."', DAILY_VESSEL_OPERATION_EXP='".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."', TOTAL_VOYAGE_EARNING='".$this->getCheckNullVal($txtGTTLVoyageEarnings)."', NET_DAILY_EARNING='".$this->getCheckNullVal($txtNettDailyEarnings)."', NET_DAILY_PROFIT='".$this->getCheckNullVal($txtNettDailyProfit)."', PROFIT_LOSS= '".$this->getCheckNullVal($txtPL)."', RDO_QTY='".$this->getCheckNullVal($rdoQty)."', HIREAGE_AMT='".$this->getCheckNullVal($txtHireargeAmt)."', HIREAGE_PERCENT='".$this->getCheckNullVal($txtHireargePercent)."', HIREAGE_PER_AMT='".$this->getCheckNullVal($txtHireargePercentAmt)."', HIREAGE_NETT_AMT='".$this->getCheckNullVal($txtNettHireargeAmt)."', CVE_AMT='".$this->getCheckNullVal($txtCVE)."', CVE_TOTALAMT='".$this->getCheckNullVal($txtCVEAmt)."', BALLAST_BONUS='".$this->getCheckNullVal($txtBallastBonus)."', BUNKER_EXPENSES='".$this->getCheckNullVal($txtTotalBunkerCost)."', PORT_EXPENSES='".$this->getCheckNullVal($txtTotalPortCost)."', QTY_TYPE_RADIO='".$rdoQtyType."', AGREED_GROSS_FREIGHT_LOCAL='".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', CURRENCYID='".$this->getCheckNullVal($selCurrencyMarList)."', EXCHANGE_RATE='".$this->getCheckNullVal($txtMarExchangeRate)."', DISTRIBUTED_REMARKS='".$txtDistributedRemarks."', OPEN_PORT='".$selOpenPort."', ZONE_OPEN='".$selZone."', BROKER='".$selBroker."', COA_SPOT='".$selCOASpot."', COA_NUMBER='".$selCOA."', COA_NUMBER_LIFT='".$txtNoLift."', NO_OF_SHIPMENT='', OWNER='".$selOwner."', DISPONENT_OWNER='".$txtDisponentOwner."', LAYCAN_START_DATE='".$txtFDate."', LAYCAN_FINISH_DATE='".$txtTDate."', ETA_DATE='".$txtETADate."', CP_DATE='".$txtCPDate."', REMARKS='".$txtNotes."', ATTACHMENT='".$upload1."', ATTACHMENT_NAME='".$name1."', CARGOID='".$txtCID."', SHIPPER='".$selShipper."', TOLERANCE='".$txtTolerance."', MATERIALID='".$selMType."', MATERIAL_CODE='".$txtMCode."', TERM_TOLERANCE='".$txtTermTolerance."', LPID='".$selLPort."', DPID='".$selDPort."', LAYCAN_CARGO_START_DATE='".$txtLCSDate."', LAYCAN_CARGO_FINISH_DATE='".$txtLCFDate."', ADDNL_FREIGHT_PER='".$this->getCheckNullVal($txtAddnlCRatePer)."', ESTIMATE_TYPE='".$this->getCheckNullVal($rdoEstimateType)."', GAS_MARKET='".$this->getCheckNullVal($rdoQtyMar)."', GAS_BALTIC='".$this->getCheckNullVal($txtBalticRate)."', ADDNL_PRENIUM='".$this->getCheckNullVal($txtAdnlPrenium)."', GAS_BASE_RATE='".$this->getCheckNullVal($txtBaseRate)."', GAS_QUANTITY='".$this->getCheckNullVal($txtGasCQMT)."', GAS_LUMSUM='".$this->getCheckNullVal($txtGASLumpsum)."', TANK_WS_FROM='".$this->getCheckNullVal($selWSFPort)."', TANK_WS_TO='".$this->getCheckNullVal($selWSTPort)."', TANK_FIXED_DIFF='".$this->getCheckNullVal($txtFixedDiff)."', TANK_QUANTITY='".$this->getCheckNullVal($txtTankQuantity)."', ATTACHMENT2='".$upload2."', ATTACHMENT2_NAME='".$name2."', CHK_LUMPSUM='".$this->getCheckNullVal($ChkLumpsum)."', LUMPSUMAMT='".$this->getCheckNullVal($txtLumpsum)."', WS_QTY='".$this->getCheckNullVal($txtLumpsumQty)."', LUMP_VENDOR='".$selLumsumVendor."', BASERATE_FLOAT='".$this->getCheckNullVal($txtBaseRateFloating)."', BASERATE_FIXED='".$this->getCheckNullVal($txtBaseRateFixed)."', BASERATE_AVERAGE='".$this->getCheckNullVal($txtBaseRateAverage)."', GROSS_FREIGHT_FLOAT='".$this->getCheckNullVal($txtGFreightFloating)."', GROSS_FREIGHT_FIXED='".$this->getCheckNullVal($txtGFreightFixed)."', GROSS_FREIGHT_AVERAGE='".$this->getCheckNullVal($txtGFreightAverage)."', NETFREIGHT_FLOAT='".$this->getCheckNullVal($txtNFreightFloating)."', NETFREIGHT_FIXED='".$this->getCheckNullVal($txtNFreightFixed)."', NETFREIGHT_AVERAGE='".$this->getCheckNullVal($txtNFreightAverage)."', OWNER_EXPENSES_FLOAT='".$this->getCheckNullVal($txtOExpensesFloating)."', OWNER_EXPENSES_FIXED='".$this->getCheckNullVal($txtOExpensesFixed)."', OWNER_EXPENSES_AVERAGE='".$this->getCheckNullVal($txtOExpensesAverage)."', VEARNING_FLOAT='".$this->getCheckNullVal($txtVEarningFloating)."', VEARNING_FIXED='".$this->getCheckNullVal($txtVEarningFixed)."', VEARNING_AVERAGE='".$this->getCheckNullVal($txtVEarningAverage)."', TCEEARNING_FLOAT='".$this->getCheckNullVal($txtDailyEarningFloating)."', TCEEARNING_FIXED='".$this->getCheckNullVal($txtDailyEarningFixed)."', TCEEARNING_AVERAGE='".$this->getCheckNullVal($txtDailyEarningAverage)."', TCE_MONTH_FLOAT='".$this->getCheckNullVal($txtTCEMonthFloating)."', TCE_MONTH_FIXED='".$this->getCheckNullVal($txtTCEMonthFixed)."', TCE_MONTH_AVERAGE='".$this->getCheckNullVal($txtTCEMonthAverage)."', OEXPENSES_FLOAT='".$this->getCheckNullVal($txtOPExpensesFloating)."', OEXPENSES_FIXED='".$this->getCheckNullVal($txtOPExpensesFixed)."', OEXPENSES_AVERAGE='".$this->getCheckNullVal($txtOPExpensesAverage)."', NET_DAILY_ER_FLOAT='".$this->getCheckNullVal($txtNetDailyEarningFloating)."', NET_DAILY_ER_FIXED='".$this->getCheckNullVal($txtNetDailyEarningFixed)."', NET_DAILY_ER_AVERAGE='".$this->getCheckNullVal($txtNetDailyEarningAverage)."', NET_DAILY_PROFIT_FLOAT='".$this->getCheckNullVal($txtNetDailyProfitFloating)."', NET_DAILY_PROFIT_FIXED='".$this->getCheckNullVal($txtNetDailyProfitFixed)."', NET_DAILY_PROFIT_AVERAGE='".$this->getCheckNullVal($txtNetDailyProfitAverage)."', OPEN_CARGOID='".$this->getCheckNullVal($selCargoPlanning)."', SUMMERDWTMT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMERDWTLT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMERDRAFTM='".$this->getCheckNullVal($txtSDraftM)."', SUMMERDRAFTFT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANT_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANT_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFTM='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CBFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', GROSS_BREAKDOWN='".$this->getCheckNullVal($txtGrossBreakeven)."', BREAKDOWN_MT='".$this->getCheckNullVal($txtBreakevenMT)."', TOTAL_ORC_EXP_AMT='".$this->getCheckNullVal($txtTTLORCAmt)."', TANKER_RADIO_SINGLE_DIS='".$this->getCheckNullVal($rdoTankType)."', TC_NO='".$txtTCNo."', GROSS_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtGrossHireargeAmt)."', HIERAGE_CVE='".$this->getCheckNullVal($txtHireargeCVE)."', HIERAGE_CVE_AMOUNT='".$this->getCheckNullVal($txtHireargeCVEAMT)."', OFF_HIRE_CVE='".$this->getCheckNullVal($txtOffHireCVE)."', OFF_HIRE_CVE_AMOUNT='".$this->getCheckNullVal($txtOffHireCVEAMT)."', LESS_OFF_HIRE='".$this->getCheckNullVal($txtLessOffHire)."', FINAL_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtFinalHireargeAmt)."', HIERAGE_BROKER_PERCENT= '".$this->getCheckNullVal($txtHireargeBroPercent)."', HIERAGE_BROKER_AMT= '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', TC_HIRE_DAYS='".$this->getCheckNullVal($txtTotalVoyageDays)."', TC_CP_DATE='".$txtTC_CPDate."', PERIODID='".$this->getCheckNullValue($selPeriodContract)."', LESS_PER_BLQTY='".$this->getCheckNullValue($txtLessPerQty)."', BL_QTY_FREIGHT='".$this->getCheckNullValue($txtBLCQMT)."', TC_DELIVERY_DATE='".$txtTCDeliveryDate."', TC_RE_DELIVERY_DATE='".$txtTCReDeliveryDate."', TC_DELIVERY_RANGE='".$txtTCDelivery."', TC_RE_DELIVERY_RANGE='".$txtTCReDelivery."', TANKER_FREIGHT_RATE='".$txtTankerFreightRate."', TANK_CLEANING_SECA_HRS='".$this->getCheckNullVal($txtTKSECAHrs)."', TANK_CLEANING_NONSECA_HRS='".$this->getCheckNullVal($txtTKNONSECAHrs)."', INERTING_SECA_HRS='".$this->getCheckNullVal($txtInertSECAHrs)."', INERTING_NONSECA_HRS='".$this->getCheckNullVal($txtInertNONSECAHrs)."', GAS_FREEING_SECA_HRS='".$this->getCheckNullVal($txtGFSECAHrs)."', GAS_FREEING_NONSECA_HRS='".$this->getCheckNullVal($txtGFNONSECAHrs)."', HEATING_SECA_HRS='".$this->getCheckNullVal($txtHeatSECAHrs)."', HEATING_NONSECA_HRS='".$this->getCheckNullVal($txtHeatNONSECAHrs)."', HEATING_SECA_HRS_1='".$this->getCheckNullVal($txtHeatSECAHrs1)."', HEATING_NONSECA_HRS_1='".$this->getCheckNullVal($txtHeatNONSECAHrs1)."' WHERE FCAID='".$id."' and MODULEID='".$this->getCheckNullValue($_SESSION['moduleid'])."' and MCOMPANYID='".$this->getCheckNullValue($_SESSION['company'])."'";
	
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	$arr_passage = array();
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['txtFCASlaveID_'.$i]))
		{
			$arr_passage[] = $_REQUEST['txtFCASlaveID_'.$i];
		}
	}
	$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$id."'";
    $res1 = mysql_query($sql1);
	while($rows1 = mysql_fetch_assoc($res1))
	{
		if(!in_array($rows1['FCA_SLAVEID'], $arr_passage))
        {
			$del_query2 = "delete from freight_cost_estimete_slave1 where FCAID='".$id."' and FCA_SLAVEID='".$rows1['FCA_SLAVEID']."' ";
            mysql_query($del_query2);
			mysql_query("commit");
		}
	}
	
	$del_query3 = "delete from  freight_cost_estimete_slave2 where FCAID='".$id."'";
	$del_query4 = "delete from  freight_cost_estimete_slave3 where FCAID='".$id."'";
	$del_query5 = "delete from  freight_cost_estimete_slave4 where FCAID='".$id."'";
	$del_query6 = "delete from  freight_cost_estimete_slave5 where FCAID='".$id."'";
	$del_query7 = "delete from  freight_cost_estimete_slave6 where FCAID='".$id."'";
	$del_query8 = "delete from  freight_cost_estimete_slave7 where FCAID='".$id."'";
	$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$id."'";
	$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$id."'";
	$del_query9 = "delete from  freight_cost_estimete_slave8 where FCAID='".$id."'";
	$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$id."'";
	$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$id."'";
	$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$id."'";
	$del_query16 = "delete from  freight_cost_estimete_slave16 where FCAID='".$id."'";
	$del_query17 = "delete from  freight_cost_estimete_slave17 where FCAID='".$id."'";
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query($del_query5);
	mysql_query($del_query6);
	mysql_query($del_query7);
	mysql_query($del_query8);
	mysql_query($del_query12);
	mysql_query($del_query10);
	mysql_query($del_query9);
	mysql_query($del_query13);
	mysql_query($del_query14);
	mysql_query($del_query15);
	mysql_query($del_query16);
	mysql_query($del_query17);
	mysql_query("commit");
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{
			if(isset($_REQUEST['txtFCASlaveID_'.$i]) && $_REQUEST['txtFCASlaveID_'.$i]!='')
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "update freight_cost_estimete_slave1 set FROM_PORT='".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."', TO_PORT='".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."', DIS_TYPE='".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."', PASSAGE_TYPE='".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."', DISTANCE='".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."', SPEED_TYPE='".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."', SPEED_ADJ='".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."', MARGIN_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."', LOAD_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."', LOAD_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."', LOAD_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."', LOAD_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."', LOAD_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."', LOAD_PORT_IDEAL_DAYS='".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."', DISC_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."', DISC_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."', DISC_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."', DISC_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."', DISC_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."', DISC_PORT_IDEAL_DATE='".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."', TRANSIT_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."', TRANSIT_PORT_IDLE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', DDCLP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."', DDCLP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."', DDCLP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."', DDCDP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."', DDCDP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."', DDCDP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."', IS_SHOW_DDCLP='".$_REQUEST['ChkShowDDCLP_'.$i]."', IS_SHOW_DDCDP='".$_REQUEST['ChkShowDDCDP_'.$i]."', RANDOMID='".$randomid."', DDCLP_COMM='".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', DDCDP_COMM='".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', CHK_LP_SECA='".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', CHK_DP_SECA='".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', CHK_TP_SECA='".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', TOTAL_VOYAGE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', SECA_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', SECA_DAYS='".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."' where FCAID='".$id."' and FCA_SLAVEID='".$_REQUEST['txtFCASlaveID_'.$i]."'";	
			}
			else
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
			    $sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_NETCOST, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_NETCOST, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, DDCLP_COMM, DDCDP_COMM, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS) values ('".$id."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['ChkShowDDCLP_'.$i]."','".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."')";	
			}
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] >0)
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."',1,'".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] >0)
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] >0)
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT) values ('".$id."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT) values ('".$id."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		$txtTID = $_REQUEST['txtTID'];
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtDisponentOwner_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_slave5 (FCAID, DISPONENT_OWNER) values ('".$id."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$txtQTYID = $_REQUEST['txtQTYID'];
		for($i=1 ; $i<=$txtQTYID ;$i++)
		{
			if($_REQUEST['selQtyVendorList_'.$i] != "")
			{
			    $randomid = $_REQUEST['txtQtySlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtQtySlaveRandomID_'.$i]) || $_REQUEST['txtQtySlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql2 = "insert into freight_cost_estimete_slave7 (FCAID, QTY_VENDORID, AGREED_GROSS_FREIGHT, QUANTITY, GROSS_FREIGHT, BROKERAGE, NET_BROKERAGE, NET_FREIGHT, NET_FREIGHT_PERMT, CURRENCYID, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, CARGO, RANDOMID) values ('".$id."','".$_REQUEST['selQtyVendorList_'.$i]."','".$_REQUEST['txtQtyAggriedFreight_'.$i]."','".$_REQUEST['txtFreightQty_'.$i]."','".$_REQUEST['txtQtyFreight_'.$i]."','".$_REQUEST['txtQtyBrokeragePer_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtQtyBrokerageAmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreightMT1_'.$i])."','".$this->getCheckNullVal($_REQUEST['selCurrencyDisList_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyLocalAggriedFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDisExchangeRate_'.$i])."','".$this->getCheckNullVal($_REQUEST['selQtyCargo_'.$i])."', '".$randomid."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		} 
		
		$txtTankID = $_REQUEST['txtTankID'];
		for($i=1 ; $i<=$txtTankID ;$i++)
		{
			if($_REQUEST['txtFreightSpecs_'.$i] != "")
			{
				$sql12 = "insert into freight_cost_estimete_slave12 (FCAID, FREIGHT_SPECS, CUSTOMER, MIN_CARGO_QTY, OVE_CARGO_QTY, MIN_FLAT_RATE, OVE_FLAT_RATE, MIN_WS, OVE_WS, MIN_DIS_LEG, OVE_DIS_LEG, MIN_DISTANCE, OVE_DISTANCE, MIN_AMOUNT, OVE_AMOUNT, TOTAL_QTY, TOTAL_AMOUNT) values ('".$id."', '".$_REQUEST['txtFreightSpecs_'.$i]."', '".$_REQUEST['selTankVendor_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtMinCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtOveCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinDisLeg_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveDisLeg_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinTotalDis_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveTotalDis_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinAmount_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtTotalTankQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTotalTankAmount_'.$i])."')";
				mysql_query($sql12) or die($sql12);
				mysql_query("commit");
			}
		}
		
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$id."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$id."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$txtHIREID = $_REQUEST['txtHIREID'];
		for($i=1 ; $i<=$txtHIREID ;$i++)
		{
			if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
			{
				if($_REQUEST['txtHireFrom_'.$i]!="")
				{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
				else{$txtHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtHireTo_'.$i]!="")
				{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
				else{$txtHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCHireRandom_'.$i]) || $_REQUEST['txtTCHireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCHireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave17 (FCAID, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE, HIRE_AMT, RANDOMID) values ('".$id."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireAmt_'.$i])."', '".$this->getCheckNullValue($randomid4)."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$id."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$id."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						 if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$id."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg; 
 }
  



function getSheetNameFromTCEListNew($estimatetype)
{
	$this->funConnect();
	$sql = "select * from freight_cost_estimete_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and ESTIMATE_TYPE='".$estimatetype."' and SHEET_NO is NULL order by FCAID desc";
	$res = mysql_query($sql) or die($sql);
	while($rows = mysql_fetch_assoc($res))
	{
		$value = $rows['VOYAGE_NAME'];
		$key = $rows['FCAID'];
		if($rows['IF_BENCHMARK']==0){$class = '';}else{$class = 'benchclass';}
		echo "<option class='".$class."' value=$key";
		if($key == @$id){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getEstimateList($id)
{
	$type = array( 1 =>'Gas' , 2 =>'Tanker', 3 =>'Dry Cargo');
	return $type[$id];
}


function displayFCETempleteListNew($selBType)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="fce_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">Vessel Name/Type</th>';
	echo '<th align="left" valign="middle" width="10%">Business Type</th>';
	echo '<th align="left" valign="middle" width="10%">Sheet Name</th>';
	echo '<th align="left" valign="middle" width="10%">CP Date</th>';
	echo '<th align="left" valign="middle" width="10%">DWT</th>';
	echo '<th align="left" valign="middle" width="6%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="10%">Duration</th>';
	echo '<th align="left" valign="middle" width="10%">Cargo Quantity</th>';
	echo '<th align="left" valign="middle" width="5%">TCE</th>';
	echo '<th align="left" valign="middle" width="5%">Daily Time Charter <span style="font-size:10px; font-style:italic;">(USD/Day)</span></th>';
	echo '<th align="left" valign="middle" width="5%">P/L</th>';
	echo '<th align="center" valign="middle" width="10%">Select All<br/>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chkAll" id="chkAll" value="1" class="checkbox"/></th>';
	echo '<th align="center" valign="middle" width="7%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	if($selBType!='')
	{
		$sql = "select FCAID, VESSEL_IMO_ID, VOYAGE_NAME, VESSEL_TYPE, FREIGHT_GROSS, TOTAL_DAYS, QUANTITY, DAILY_EARNING, DAILY_VESSEL_OPERATION_EXP, PROFIT_LOSS, TRANS_DATE, (select COA_DATE from open_cargo_master where open_cargo_master.OPEN_CARGOID=freight_cost_estimete_master.OPEN_CARGOID) as CP_DATE, QTY_TYPE_RADIO, ESTIMATE_TYPE, GAS_QUANTITY, TANK_QUANTITY, IF_BENCHMARK from freight_cost_estimete_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and ESTIMATE_TYPE='".$selBType."' and COAID is NULL and FIXED=0 order by FCAID desc";
		$res = mysql_query($sql) or die($sql);
		$rec = mysql_num_rows($res);
		$i = 1;
		if($rec == 0)
		{
			
		}
		else{
			while($rows = mysql_fetch_assoc($res))
			{
				$arr_load = $arr_discharge = array();
				$sql1 = "select FROM_PORT, TO_PORT, LOAD_PORT_COST, LOAD_PORT_QTY, DISC_PORT_COST, DISC_PORT_QTY from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
				$res1 = mysql_query($sql1);
				while($row1 = mysql_fetch_assoc($res1))
				{
					if($row1['LOAD_PORT_QTY']>0)
					{
						$arr_load[] = $this->getPortNameBasedOnID($row1['FROM_PORT']);
					}
					if($row1['DISC_PORT_QTY']>0)
					{
						$arr_discharge[] = $this->getPortNameBasedOnID($row1['TO_PORT']);
					}
				}
				
				$quantity = 0;
				if($rows['ESTIMATE_TYPE']==1)
				{
					$quantity = $rows['GAS_QUANTITY'];
				}
				else if($rows['ESTIMATE_TYPE']==2)
				{
					$quantity = $rows['TANK_QUANTITY'];
				}
				else
				{
					if($rows['QTY_TYPE_RADIO'] == 1)
					{
						$quantity = $rows['QUANTITY'];
					}
					else
					{
						$sql12 = "select sum(QUANTITY) as sum from freight_cost_estimete_slave7 where FCAID='".$rows['FCAID']."'";
						$res12 = mysql_query($sql12);
						$row12 = mysql_fetch_assoc($res12);
						$quantity = $row12['sum'];
					}
				}
				if($rows['IF_BENCHMARK']==0){$class = '';}else{$class = 'benchclass';}
				echo '<tr class="'.$class.'">';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'/ '.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getEstimateList($rows['ESTIMATE_TYPE']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NAME'].'</td>';
				
				echo '<td align="left" valign="middle" class="input-text">'.date('d-m-Y',strtotime($rows['TRANS_DATE'])).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"DWT").'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_load).'/ '.implode(', ',$arr_discharge).'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_DAYS'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$quantity.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_EARNING'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_VESSEL_OPERATION_EXP'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PROFIT_LOSS'].'</td>';
				
				if($rows['COMID']=="")
				{
					echo '<td align="center" valign="middle" class="input-text"><input type="checkbox" name="chkFCA[]" id="chkFCA_'.$i.'" value="'.$rows['FCAID'].'" class="checkbox"/></td>';
					echo '<td align="center" valign="middle" class="input-text"><a href="updateestimate.php?id='.$rows['FCAID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#Delete" onclick="return getDelete('.$rows['FCAID'].');" ><i class="fa fa-times" style="color:red;"></i>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="allPdf.php?id=77&fcaid='.$rows['FCAID'].'" style="color:green;" title="Click me" ><span class="glyphicon glyphicon-download-alt"></span></a></td>';
				}
				else
				{
					echo '<td align="center" valign="middle" class="input-text">Sent to Decision Chart</td>';
					echo '<td align="center" valign="middle" class="input-text"><a href="viewestimate.php?id='.$rows['FCAID'].'&rttype=1" title="Edit Details" ><i class="fa fa-file "></i></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="allPdf.php?id=77&fcaid='.$rows['FCAID'].'" style="color:green;" title="Click me" ><span class="glyphicon glyphicon-download-alt"></span></a></td>';
				}
				echo '</tr>';
				$i++;
			}
		
		}
	}
	echo '</tbody>';
	echo '</table></div>';
}
	
	
function viewFreightCostEstimationTempleteRecordsNew($id)
{
	$connect = $this->funConnect();
	$sql = "select * from freight_cost_estimete_master where MODULEID='".$_SESSION['moduleid']."' and FCAID='".$id."'";
	$result = mysql_query($sql) or die($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['FCAID'];
		$this->var_2 = $rows['FIXTURETYPEID'];
		$this->var_3 = $rows['TRANS_DATE'];
		$this->var_4 = $rows['ADDED_BY'];
		$this->var_5 = $rows['VESSEL_IMO_ID'];
		$this->var_6 = $rows['VESSEL_TYPE'];
		$this->var_7 = $rows['FLAG'];
		$this->var_8 = $rows['VOYAGE_NO'];
		$this->var_9 = $rows['VOYAGE_NAME'];
		$this->var_10 = $rows['DWT_SUMMER'];
		$this->var_11 = $rows['DWT_TOPICAL'];
		$this->var_12 = $rows['RDO_CAP'];
		$this->var_13 = $rows['GRAIN_CAP'];
		$this->var_14 = $rows['BALE_CAP'];
		$this->var_15 = $rows['SF'];
		$this->var_16 = $rows['LODABLE'];
		$this->var_17 = $rows['GNRT'];
		$this->var_18 = $rows['LOA'];
		$this->var_19 = $rows['GEAR'];
		$this->var_20 = $rows['BUILD_YEAR'];
		$this->var_21 = $rows['BEAM'];
		$this->var_22 = $rows['TPC'];
		$this->var_23 = $rows['BFULLSPEED'];
		$this->var_24 = $rows['BECOSPEED1'];
		$this->var_25 = $rows['BECOSPEED2'];
		$this->var_26 = $rows['LFULLSPEED'];
		$this->var_27 = $rows['LECOSPEED1'];
		$this->var_28 = $rows['LECOSPEED2'];
		$this->var_29 = $rows['BFOFULLSPEED'];
		$this->var_30 = $rows['BFOECOSPEED1'];
		$this->var_31 = $rows['BFOECOSPEED2'];
		$this->var_32 = $rows['LFOFULLSPEED'];
		$this->var_33 = $rows['LFOECOSPEED1'];
		$this->var_34 = $rows['LFOECOSPEED2'];
		$this->var_35 = $rows['PIFOFULLSPEED'];
		$this->var_36 = $rows['PWFOFULLSPEED'];
		$this->var_37 = $rows['BDOFULLSPEED'];
		$this->var_38 = $rows['BDOECOSPEED1'];
		$this->var_39 = $rows['BDOECOSPEED2'];
		$this->var_40 = $rows['LDOFULLSPEED'];
		$this->var_41 = $rows['LDOECOSPEED1'];
		$this->var_42 = $rows['LDOECOSPEED2'];
		$this->var_43 = $rows['PIDOFULLSPEED'];
		$this->var_44 = $rows['PWDOFULLSPEED'];
		$this->var_45 = $rows['RDO_MARKER'];
		$this->var_46 = $rows['RDO_DWT'];
		$this->var_47 = $rows['FREIGHT_GROSS'];
		$this->var_48 = $rows['LUMSUM'];
		$this->var_49 = $rows['CARGO_RATE'];
		$this->var_50 = $rows['QUANTITY'];
		$this->var_51 = $rows['CARGO_TYPE'];
		$this->var_52 = $rows['CARGO_ID'];
		$this->var_53 = $rows['DF_QUANTITY'];
		$this->var_54 = $rows['ADDNL_QUANTITY'];
		$this->var_55 = $rows['LADEN_DIST'];
		$this->var_56 = $rows['BALLAST_DIST'];
		$this->var_57 = $rows['LADEN_DAYS'];
		$this->var_58 = $rows['BALLAST_DAYS'];
		$this->var_59 = $rows['TOTAL_PASSAGE_DAYS'];
		$this->var_60 = $rows['IDEAL_DAYS'];
		$this->var_61 = $rows['WORKING_DAYS'];
		$this->var_62 = $rows['TOTAL_DAYS'];
		$this->var_63 = $rows['TOTAL_DISTANCE'];
		$this->var_64 = $rows['FO_CONSP'];
		$this->var_65 = $rows['DO_CONSP'];
		$this->var_66 = $rows['GROSS_PREIGHT_ADJ'];
		$this->var_67 = $rows['DEAD_PREIGHT_ADJ'];
		$this->var_68 = $rows['ADDNL_PREIGHT_ADJ'];
		$this->var_69 = $rows['TOTAL_PREIGHT_ADJ'];
		$this->var_70 = $rows['GROSS_PREIGHT_ADJ_PRMT'];
		$this->var_71 = $rows['DEAD_PREIGHT_ADJ_PRMT'];
		$this->var_72 = $rows['ADDNL_PREIGHT_ADJ_PRMT'];
		$this->var_73 = $rows['TOTAL_PREIGHT_ADJ_PRMT'];
		$this->var_74 = $rows['ADDRESS_COMMISSION_PER'];
		$this->var_75 = $rows['ADDRESS_COMMISSION_AMT'];
		$this->var_76 = $rows['ADDRESS_COMMISSION_PRMT'];
		$this->var_77 = $rows['BROKERAGE_PER'];
		$this->var_78 = $rows['BROKERAGE_AMT'];
		$this->var_79 = $rows['BROKERAGE_PRMT'];
		$this->var_80 = $rows['FINAL_NET_FREIGHT'];
		$this->var_81 = $rows['FINAL_NET_FREIGHT_PRMT'];
		$this->var_82 = $rows['BROKERAGE_COMMISSION_PER'];
		$this->var_83 = $rows['BROKERAGE_COMMISSION_AMT'];
		$this->var_84 = $rows['TOTAL_ORC_EXP_AMT'];
		$this->var_85 = $rows['TOTAL_ORC_EXP_PRMT'];
		$this->var_86 = $rows['REVENUES_FREIGHT'];
		$this->var_87 = $rows['TOTAL_OWNER_EXP'];
		$this->var_88 = $rows['CHARTERER_EXP'];
		$this->var_89 = $rows['VOYAGE_EARNING'];
		$this->var_90 = $rows['DAILY_EARNING'];
		$this->var_91 = $rows['DAILY_VESSEL_OPERATION_EXP'];
		$this->var_92 = $rows['TOTAL_VOYAGE_EARNING'];
		$this->var_93 = $rows['NET_DAILY_PROFIT'];
		$this->var_94 = $rows['NET_DAILY_EARNING'];
		$this->var_95 = $rows['PROFIT_LOSS'];
		$this->var_96 = $rows['RDO_QTY'];
		$this->var_97 = $rows['FIXED'];
		$this->var_98 = $rows['COMID'];
		$this->var_99 = $rows['SHEET_NO'];
		$this->var_100 = $rows['OPEN_PORT'];
		$this->var_101 = $rows['ZONE_OPEN'];
		$this->var_127 = $rows['BROKER'];
		$this->var_126 = $rows['COA_SPOT'];
		$this->var_102 = $rows['COA_NUMBER'];
		$this->var_103 = $rows['COA_NUMBER_LIFT'];
		$this->var_104 = $rows['NO_OF_SHIPMENT'];
		$this->var_105 = $rows['VESSEL_CATEGORY'];
		$this->var_106 = $rows['EXPECTED_HIRE'];
		$this->var_107 = $rows['OWNER'];
		$this->var_108 = $rows['DISPONENT_OWNER'];
		$this->var_109 = $rows['LAYCAN_START_DATE'];
		$this->var_110 = $rows['LAYCAN_FINISH_DATE'];
		$this->var_111 = $rows['ETA_DATE'];
		$this->var_112 = $rows['CP_DATE'];
		$this->var_113 = $rows['REMARKS'];
		$this->var_114 = $rows['TC_DESC'];
		$this->var_115 = $rows['ATTACHMENT'];
		$this->var_116 = $rows['ATTACHMENT_NAME'];
		$this->var_128 = $rows['CARGOID'];
		$this->var_117 = $rows['SHIPPER'];
		$this->var_118 = $rows['TOLERANCE'];
		$this->var_119 = $rows['MATERIALID'];
		$this->var_120 = $rows['MATERIAL_CODE'];
		$this->var_121 = $rows['TERM_TOLERANCE'];
		$this->var_122 = $rows['LPID'];
		$this->var_123 = $rows['DPID'];
		$this->var_124 = $rows['LAYCAN_CARGO_START_DATE'];
		$this->var_125 = $rows['LAYCAN_CARGO_FINISH_DATE'];
		$this->var_132 = $rows['HIREAGE_AMT'];
		$this->var_129 = $rows['HIREAGE_PERCENT'];
		$this->var_130 = $rows['HIREAGE_PER_AMT'];
		$this->var_131 = $rows['HIREAGE_NETT_AMT'];
		$this->var_155 = $rows['QTY_TYPE_RADIO'];
		$this->var_133 = $rows['AGREED_GROSS_FREIGHT_LOCAL'];
		$this->var_134 = $rows['CURRENCYID'];
		$this->var_135 = $rows['EXCHANGE_RATE'];
		$this->var_136 = $rows['TTL_FO_CONSP_MT_MANUAL'];
		$this->var_137 = $rows['TTL_DO_CONSP_MT_MANUAL'];
		$this->var_138 = $rows['TTL_FO_CONSP_OFFHIRE'];
		$this->var_139 = $rows['TTL_DO_CONSP_OFFHIRE'];
		$this->var_140 = $rows['DTCVENDORID'];
		$this->var_141 = $rows['FGFF_VENDORID'];
		$this->var_142 = $rows['CVE_AMT'];
		$this->var_143 = $rows['CVE_TOTALAMT'];
		$this->var_144 = $rows['CVE_VENDORID'];
		$this->var_145 = $rows['BALLAST_BONUS'];
		$this->var_146 = $rows['BROKERAGE_PERCENT'];
		$this->var_147 = $rows['BROKERAGE_AMOUNT'];
		$this->var_148 = $rows['ILOHC_AMT'];
		$this->var_149 = $rows['BALLAST_VENDORID'];
		$this->var_150 = $rows['BROKERAGE_VENDORID'];
		$this->var_151 = $rows['ILOHC_VENDORID'];
		$this->var_152 = $rows['BUNKER_EXPENSES'];
		$this->var_153 = $rows['PORT_EXPENSES'];
		$this->var_154 = $rows['HIDDEN_HIRAGE'];
		$this->var_156 = $rows['DISTRIBUTED_REMARKS'];
		$this->var_157 = $rows['ADDNL_FREIGHT_PER'];
		
		$this->var_158 = $rows['ESTIMATE_TYPE'];
		$this->var_159 = $rows['GAS_MARKET'];
		$this->var_160 = $rows['GAS_BALTIC'];
		$this->var_161 = $rows['ADDNL_PRENIUM'];
		$this->var_162 = $rows['GAS_BASE_RATE'];
		$this->var_163 = $rows['GAS_QUANTITY'];
		$this->var_164 = $rows['GAS_LUMSUM'];
		$this->var_165 = $rows['TANK_WS_FROM'];
		$this->var_166 = $rows['TANK_WS_TO'];
		$this->var_167 = $rows['TANK_FIXED_DIFF'];
		$this->var_168 = $rows['TANK_QUANTITY'];
		$this->var_169 = $rows['ATTACHMENT2'];
		$this->var_170 = $rows['ATTACHMENT2_NAME'];
		$this->var_171 = $rows['CHK_LUMPSUM'];
		$this->var_172 = $rows['LUMPSUMAMT'];
		$this->var_173 = $rows['WS_QTY'];
		$this->var_174 = $rows['LUMP_VENDOR'];
		$this->var_175 = $rows['COAID'];
		$this->var_176 = $rows['BASERATE_FLOAT'];
		$this->var_177 = $rows['BASERATE_FIXED'];
		$this->var_178 = $rows['BASERATE_AVERAGE'];
		$this->var_179 = $rows['GROSS_FREIGHT_FLOAT'];
		$this->var_180 = $rows['GROSS_FREIGHT_FIXED'];
		$this->var_181 = $rows['GROSS_FREIGHT_AVERAGE'];
		$this->var_182 = $rows['NETFREIGHT_FLOAT'];
		$this->var_183 = $rows['NETFREIGHT_FIXED'];
		$this->var_184 = $rows['NETFREIGHT_AVERAGE'];
		$this->var_185 = $rows['OWNER_EXPENSES_FLOAT'];
		$this->var_186 = $rows['OWNER_EXPENSES_FIXED'];
		$this->var_187 = $rows['OWNER_EXPENSES_AVERAGE'];
		$this->var_188 = $rows['VEARNING_FLOAT'];
		$this->var_189 = $rows['VEARNING_FIXED'];
		$this->var_190 = $rows['VEARNING_AVERAGE'];
		$this->var_191 = $rows['TCEEARNING_FLOAT'];
		$this->var_192 = $rows['TCEEARNING_FIXED'];
		$this->var_193 = $rows['TCEEARNING_AVERAGE'];
		$this->var_194 = $rows['TCE_MONTH_FLOAT'];
		$this->var_195 = $rows['TCE_MONTH_FIXED'];
		$this->var_196 = $rows['TCE_MONTH_AVERAGE'];
		$this->var_197 = $rows['OEXPENSES_FLOAT'];
		$this->var_198 = $rows['OEXPENSES_FIXED'];
		$this->var_199 = $rows['OEXPENSES_AVERAGE'];
		$this->var_200 = $rows['NET_DAILY_ER_FLOAT'];
		$this->var_201 = $rows['NET_DAILY_ER_FIXED'];
		$this->var_202 = $rows['NET_DAILY_ER_AVERAGE'];
		$this->var_203 = $rows['NET_DAILY_PROFIT_FLOAT'];
		$this->var_204 = $rows['NET_DAILY_PROFIT_FIXED'];
		$this->var_205 = $rows['NET_DAILY_PROFIT_AVERAGE'];
		$this->var_206 = $rows['OPEN_CARGOID'];
		
		$this->var_207 = $rows['SUMMERDWTMT'];
		$this->var_208 = $rows['SUMMERDWTLT'];
		$this->var_209 = $rows['SUMMERDRAFTM'];
		$this->var_210 = $rows['SUMMERDRAFTFT'];
		$this->var_211 = $rows['TPI_MT_INCH'];
		$this->var_212 = $rows['TPI_LT_INCH'];
		$this->var_213 = $rows['TPC_MT'];
		$this->var_214 = $rows['TPC_LT'];
		$this->var_215 = $rows['CONSTANT_MT'];
		$this->var_216 = $rows['CONSTANT_LT'];
		$this->var_217 = $rows['GRAIN_CAP_CBM'];
		$this->var_218 = $rows['GRAIN_CAP_CFT'];
		$this->var_219 = $rows['ALLOWED_DRAFTM'];
		$this->var_220 = $rows['BUNKER_ROB_MT'];
		$this->var_221 = $rows['CARGO_INTAKE_MT'];
		$this->var_222 = $rows['SF_CBM_MT'];
		$this->var_223 = $rows['SF_CBFT_MT'];
		$this->var_224 = $rows['CARGO_LOADABLE_MT'];
		$this->var_226 = $rows['GROSS_BREAKDOWN'];
	    $this->var_227 = $rows['BREAKDOWN_MT'];
		$this->var_228 = $rows['TANKER_RADIO_SINGLE_DIS'];
		$this->var_229 = $rows['TC_NO'];
		
		$this->var_230 = $rows['GROSS_HIERAGE_AMOUNT'];
		$this->var_231 = $rows['HIERAGE_CVE'];
		$this->var_232 = $rows['HIERAGE_CVE_AMOUNT'];
	    $this->var_233 = $rows['OFF_HIRE_CVE'];
		$this->var_234 = $rows['OFF_HIRE_CVE_AMOUNT'];
		$this->var_235 = $rows['LESS_OFF_HIRE'];
		$this->var_236 = $rows['FINAL_HIERAGE_AMOUNT'];
		$this->var_237 = $rows['HIERAGE_BROKER_PERCENT'];
		$this->var_238 = $rows['HIERAGE_BROKER_AMT'];
		$this->var_239 = $rows['TC_HIRE_DAYS'];
		$this->var_240 = $rows['TC_CP_DATE'];
		$this->var_241 = $rows['PERIODID'];
		$this->var_242 = $rows['AUTO_PL'];
		
		$this->var_243 = $rows['LESS_PER_BLQTY'];
		$this->var_244 = $rows['BL_QTY_FREIGHT'];
		
		$this->var_245 = $rows['TC_DELIVERY_DATE'];
		$this->var_246 = $rows['TC_RE_DELIVERY_DATE'];
		$this->var_247 = $rows['TC_DELIVERY_RANGE'];
		$this->var_248 = $rows['TC_RE_DELIVERY_RANGE'];
		$this->var_249 = $rows['ACTUAL_PL'];
		$this->var_250 = $rows['TANKER_FREIGHT_RATE'];
		
		$this->var_251 = $rows['TANK_CLEANING_SECA_HRS'];
		$this->var_252 = $rows['TANK_CLEANING_NONSECA_HRS'];
		$this->var_253 = $rows['INERTING_SECA_HRS'];
		$this->var_254 = $rows['INERTING_NONSECA_HRS'];
		$this->var_255 = $rows['GAS_FREEING_SECA_HRS'];
		$this->var_256 = $rows['GAS_FREEING_NONSECA_HRS'];
		$this->var_257 = $rows['HEATING_SECA_HRS'];
		$this->var_258 = $rows['HEATING_NONSECA_HRS'];
		$this->var_259 = $rows['HEATING_SECA_HRS_1'];
		$this->var_260 = $rows['HEATING_NONSECA_HRS_1'];
		$this->var_261 = $rows['CHARTERING_PIC'];

		$this->var_262 = $rows['SEL_BUSI_TYPE'];
		
		$sql2 = "select OPEN_CARGOID, CPID, (select MATERIAL_CODE_DESC from cargo_master where cargo_master.MATERIALID = open_cargo_master.CARGO) as CARGONAME, CARGOSTEAMSIZE, LAYCAN_SDATE, BASE_FREIGHT, RDO_WS_TYPE, WS_LUMPSUM_AMOUNT, (case when (RDO_WS_TYPE = 1) THEN 'WS' ELSE 'Lumpsum' END) as WS_RDO_TEXT, (case when (RDO_WS_TYPE = 1) THEN 'Base Freight' ELSE 'Lumpsum' END) as WS_RDO_TEXT1, CARGO_RELET, COA_SPOT from open_cargo_master where OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
		
		$result2 = mysql_query($sql2) or die($sql2);
		$rows2   = mysql_fetch_assoc($result2);
		$freightdata = '';
		if($_SESSION['selBType']==1)
		{
			 if($rows2['RDO_WS_TYPE'] ==1)
		 	 {
		     	$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Base Freight(USD): '.$rows2['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT/Lumpsum (USD):'.$rows2['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==2)
		{
			 if($rows2['RDO_WS_TYPE'] ==1)
		 	 {
		     	$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, WS:'.$rows2['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Lumpsum (USD):'.$rows2['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==3)
		{
			$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Freight (USD):'.$rows2['BASE_FREIGHT'].' ';
		}
	}
}



function viewFreightCostEstimationTempleteRecordsNewForVcIn($id)
{
	$connect = $this->funConnect();
	$sql = "select * from freight_cost_estimete_in_master where MODULEID='".$_SESSION['moduleid']."' and FCAID='".$id."'";
	$result = mysql_query($sql) or die($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['FCAID'];
		$this->var_2 = $rows['FIXTURETYPEID'];
		$this->var_3 = $rows['TRANS_DATE'];
		$this->var_4 = $rows['ADDED_BY'];
		$this->var_5 = $rows['VESSEL_IMO_ID'];
		$this->var_6 = $rows['VESSEL_TYPE'];
		$this->var_7 = $rows['FLAG'];
		$this->var_8 = $rows['VOYAGE_NO'];
		$this->var_9 = $rows['VOYAGE_NAME'];
		$this->var_10 = $rows['DWT_SUMMER'];
		$this->var_11 = $rows['DWT_TOPICAL'];
		$this->var_12 = $rows['RDO_CAP'];
		$this->var_13 = $rows['GRAIN_CAP'];
		$this->var_14 = $rows['BALE_CAP'];
		$this->var_15 = $rows['SF'];
		$this->var_16 = $rows['LODABLE'];
		$this->var_17 = $rows['GNRT'];
		$this->var_18 = $rows['LOA'];
		$this->var_19 = $rows['GEAR'];
		$this->var_20 = $rows['BUILD_YEAR'];
		$this->var_21 = $rows['BEAM'];
		$this->var_22 = $rows['TPC'];
		$this->var_23 = $rows['BFULLSPEED'];
		$this->var_24 = $rows['BECOSPEED1'];
		$this->var_25 = $rows['BECOSPEED2'];
		$this->var_26 = $rows['LFULLSPEED'];
		$this->var_27 = $rows['LECOSPEED1'];
		$this->var_28 = $rows['LECOSPEED2'];
		$this->var_29 = $rows['BFOFULLSPEED'];
		$this->var_30 = $rows['BFOECOSPEED1'];
		$this->var_31 = $rows['BFOECOSPEED2'];
		$this->var_32 = $rows['LFOFULLSPEED'];
		$this->var_33 = $rows['LFOECOSPEED1'];
		$this->var_34 = $rows['LFOECOSPEED2'];
		$this->var_35 = $rows['PIFOFULLSPEED'];
		$this->var_36 = $rows['PWFOFULLSPEED'];
		$this->var_37 = $rows['BDOFULLSPEED'];
		$this->var_38 = $rows['BDOECOSPEED1'];
		$this->var_39 = $rows['BDOECOSPEED2'];
		$this->var_40 = $rows['LDOFULLSPEED'];
		$this->var_41 = $rows['LDOECOSPEED1'];
		$this->var_42 = $rows['LDOECOSPEED2'];
		$this->var_43 = $rows['PIDOFULLSPEED'];
		$this->var_44 = $rows['PWDOFULLSPEED'];
		$this->var_45 = $rows['RDO_MARKER'];
		$this->var_46 = $rows['RDO_DWT'];
		$this->var_47 = $rows['FREIGHT_GROSS'];
		$this->var_48 = $rows['LUMSUM'];
		$this->var_49 = $rows['CARGO_RATE'];
		$this->var_50 = $rows['QUANTITY'];
		$this->var_51 = $rows['CARGO_TYPE'];
		$this->var_52 = $rows['CARGO_ID'];
		$this->var_53 = $rows['DF_QUANTITY'];
		$this->var_54 = $rows['ADDNL_QUANTITY'];
		$this->var_55 = $rows['LADEN_DIST'];
		$this->var_56 = $rows['BALLAST_DIST'];
		$this->var_57 = $rows['LADEN_DAYS'];
		$this->var_58 = $rows['BALLAST_DAYS'];
		$this->var_59 = $rows['TOTAL_PASSAGE_DAYS'];
		$this->var_60 = $rows['IDEAL_DAYS'];
		$this->var_61 = $rows['WORKING_DAYS'];
		$this->var_62 = $rows['TOTAL_DAYS'];
		$this->var_63 = $rows['TOTAL_DISTANCE'];
		$this->var_64 = $rows['FO_CONSP'];
		$this->var_65 = $rows['DO_CONSP'];
		$this->var_66 = $rows['GROSS_PREIGHT_ADJ'];
		$this->var_67 = $rows['DEAD_PREIGHT_ADJ'];
		$this->var_68 = $rows['ADDNL_PREIGHT_ADJ'];
		$this->var_69 = $rows['TOTAL_PREIGHT_ADJ'];
		$this->var_70 = $rows['GROSS_PREIGHT_ADJ_PRMT'];
		$this->var_71 = $rows['DEAD_PREIGHT_ADJ_PRMT'];
		$this->var_72 = $rows['ADDNL_PREIGHT_ADJ_PRMT'];
		$this->var_73 = $rows['TOTAL_PREIGHT_ADJ_PRMT'];
		$this->var_74 = $rows['ADDRESS_COMMISSION_PER'];
		$this->var_75 = $rows['ADDRESS_COMMISSION_AMT'];
		$this->var_76 = $rows['ADDRESS_COMMISSION_PRMT'];
		$this->var_77 = $rows['BROKERAGE_PER'];
		$this->var_78 = $rows['BROKERAGE_AMT'];
		$this->var_79 = $rows['BROKERAGE_PRMT'];
		$this->var_80 = $rows['FINAL_NET_FREIGHT'];
		$this->var_81 = $rows['FINAL_NET_FREIGHT_PRMT'];
		$this->var_82 = $rows['BROKERAGE_COMMISSION_PER'];
		$this->var_83 = $rows['BROKERAGE_COMMISSION_AMT'];
		$this->var_84 = $rows['TOTAL_ORC_EXP_AMT'];
		$this->var_85 = $rows['TOTAL_ORC_EXP_PRMT'];
		$this->var_86 = $rows['REVENUES_FREIGHT'];
		$this->var_87 = $rows['TOTAL_OWNER_EXP'];
		$this->var_88 = $rows['CHARTERER_EXP'];
		$this->var_89 = $rows['VOYAGE_EARNING'];
		$this->var_90 = $rows['DAILY_EARNING'];
		$this->var_91 = $rows['DAILY_VESSEL_OPERATION_EXP'];
		$this->var_92 = $rows['TOTAL_VOYAGE_EARNING'];
		$this->var_93 = $rows['NET_DAILY_PROFIT'];
		$this->var_94 = $rows['NET_DAILY_EARNING'];
		$this->var_95 = $rows['PROFIT_LOSS'];
		$this->var_96 = $rows['RDO_QTY'];
		$this->var_97 = $rows['FIXED'];
		$this->var_98 = $rows['COMID'];
		$this->var_99 = $rows['SHEET_NO'];
		$this->var_100 = $rows['OPEN_PORT'];
		$this->var_101 = $rows['ZONE_OPEN'];
		$this->var_127 = $rows['BROKER'];
		$this->var_126 = $rows['COA_SPOT'];
		$this->var_102 = $rows['COA_NUMBER'];
		$this->var_103 = $rows['COA_NUMBER_LIFT'];
		$this->var_104 = $rows['NO_OF_SHIPMENT'];
		$this->var_105 = $rows['VESSEL_CATEGORY'];
		$this->var_106 = $rows['EXPECTED_HIRE'];
		$this->var_107 = $rows['OWNER'];
		$this->var_108 = $rows['DISPONENT_OWNER'];
		$this->var_109 = $rows['LAYCAN_START_DATE'];
		$this->var_110 = $rows['LAYCAN_FINISH_DATE'];
		$this->var_111 = $rows['ETA_DATE'];
		$this->var_112 = $rows['CP_DATE'];
		$this->var_113 = $rows['REMARKS'];
		$this->var_114 = $rows['TC_DESC'];
		$this->var_115 = $rows['ATTACHMENT'];
		$this->var_116 = $rows['ATTACHMENT_NAME'];
		$this->var_128 = $rows['CARGOID'];
		$this->var_117 = $rows['SHIPPER'];
		$this->var_118 = $rows['TOLERANCE'];
		$this->var_119 = $rows['MATERIALID'];
		$this->var_120 = $rows['MATERIAL_CODE'];
		$this->var_121 = $rows['TERM_TOLERANCE'];
		$this->var_122 = $rows['LPID'];
		$this->var_123 = $rows['DPID'];
		$this->var_124 = $rows['LAYCAN_CARGO_START_DATE'];
		$this->var_125 = $rows['LAYCAN_CARGO_FINISH_DATE'];
		$this->var_132 = $rows['HIREAGE_AMT'];
		$this->var_129 = $rows['HIREAGE_PERCENT'];
		$this->var_130 = $rows['HIREAGE_PER_AMT'];
		$this->var_131 = $rows['HIREAGE_NETT_AMT'];
		$this->var_155 = $rows['QTY_TYPE_RADIO'];
		$this->var_133 = $rows['AGREED_GROSS_FREIGHT_LOCAL'];
		$this->var_134 = $rows['CURRENCYID'];
		$this->var_135 = $rows['EXCHANGE_RATE'];
		$this->var_136 = $rows['TTL_FO_CONSP_MT_MANUAL'];
		$this->var_137 = $rows['TTL_DO_CONSP_MT_MANUAL'];
		$this->var_138 = $rows['TTL_FO_CONSP_OFFHIRE'];
		$this->var_139 = $rows['TTL_DO_CONSP_OFFHIRE'];
		$this->var_140 = $rows['DTCVENDORID'];
		$this->var_141 = $rows['FGFF_VENDORID'];
		$this->var_142 = $rows['CVE_AMT'];
		$this->var_143 = $rows['CVE_TOTALAMT'];
		$this->var_144 = $rows['CVE_VENDORID'];
		$this->var_145 = $rows['BALLAST_BONUS'];
		$this->var_146 = $rows['BROKERAGE_PERCENT'];
		$this->var_147 = $rows['BROKERAGE_AMOUNT'];
		$this->var_148 = $rows['ILOHC_AMT'];
		$this->var_149 = $rows['BALLAST_VENDORID'];
		$this->var_150 = $rows['BROKERAGE_VENDORID'];
		$this->var_151 = $rows['ILOHC_VENDORID'];
		$this->var_152 = $rows['BUNKER_EXPENSES'];
		$this->var_153 = $rows['PORT_EXPENSES'];
		$this->var_154 = $rows['HIDDEN_HIRAGE'];
		$this->var_156 = $rows['DISTRIBUTED_REMARKS'];
		$this->var_157 = $rows['ADDNL_FREIGHT_PER'];
		
		$this->var_158 = $rows['ESTIMATE_TYPE'];
		$this->var_159 = $rows['GAS_MARKET'];
		$this->var_160 = $rows['GAS_BALTIC'];
		$this->var_161 = $rows['ADDNL_PRENIUM'];
		$this->var_162 = $rows['GAS_BASE_RATE'];
		$this->var_163 = $rows['GAS_QUANTITY'];
		$this->var_164 = $rows['GAS_LUMSUM'];
		$this->var_165 = $rows['TANK_WS_FROM'];
		$this->var_166 = $rows['TANK_WS_TO'];
		$this->var_167 = $rows['TANK_FIXED_DIFF'];
		$this->var_168 = $rows['TANK_QUANTITY'];
		$this->var_169 = $rows['ATTACHMENT2'];
		$this->var_170 = $rows['ATTACHMENT2_NAME'];
		$this->var_171 = $rows['CHK_LUMPSUM'];
		$this->var_172 = $rows['LUMPSUMAMT'];
		$this->var_173 = $rows['WS_QTY'];
		$this->var_174 = $rows['LUMP_VENDOR'];
		$this->var_175 = $rows['COAID'];
		$this->var_176 = $rows['BASERATE_FLOAT'];
		$this->var_177 = $rows['BASERATE_FIXED'];
		$this->var_178 = $rows['BASERATE_AVERAGE'];
		$this->var_179 = $rows['GROSS_FREIGHT_FLOAT'];
		$this->var_180 = $rows['GROSS_FREIGHT_FIXED'];
		$this->var_181 = $rows['GROSS_FREIGHT_AVERAGE'];
		$this->var_182 = $rows['NETFREIGHT_FLOAT'];
		$this->var_183 = $rows['NETFREIGHT_FIXED'];
		$this->var_184 = $rows['NETFREIGHT_AVERAGE'];
		$this->var_185 = $rows['OWNER_EXPENSES_FLOAT'];
		$this->var_186 = $rows['OWNER_EXPENSES_FIXED'];
		$this->var_187 = $rows['OWNER_EXPENSES_AVERAGE'];
		$this->var_188 = $rows['VEARNING_FLOAT'];
		$this->var_189 = $rows['VEARNING_FIXED'];
		$this->var_190 = $rows['VEARNING_AVERAGE'];
		$this->var_191 = $rows['TCEEARNING_FLOAT'];
		$this->var_192 = $rows['TCEEARNING_FIXED'];
		$this->var_193 = $rows['TCEEARNING_AVERAGE'];
		$this->var_194 = $rows['TCE_MONTH_FLOAT'];
		$this->var_195 = $rows['TCE_MONTH_FIXED'];
		$this->var_196 = $rows['TCE_MONTH_AVERAGE'];
		$this->var_197 = $rows['OEXPENSES_FLOAT'];
		$this->var_198 = $rows['OEXPENSES_FIXED'];
		$this->var_199 = $rows['OEXPENSES_AVERAGE'];
		$this->var_200 = $rows['NET_DAILY_ER_FLOAT'];
		$this->var_201 = $rows['NET_DAILY_ER_FIXED'];
		$this->var_202 = $rows['NET_DAILY_ER_AVERAGE'];
		$this->var_203 = $rows['NET_DAILY_PROFIT_FLOAT'];
		$this->var_204 = $rows['NET_DAILY_PROFIT_FIXED'];
		$this->var_205 = $rows['NET_DAILY_PROFIT_AVERAGE'];
		$this->var_206 = $rows['OPEN_CARGOID'];
		
		$this->var_207 = $rows['SUMMERDWTMT'];
		$this->var_208 = $rows['SUMMERDWTLT'];
		$this->var_209 = $rows['SUMMERDRAFTM'];
		$this->var_210 = $rows['SUMMERDRAFTFT'];
		$this->var_211 = $rows['TPI_MT_INCH'];
		$this->var_212 = $rows['TPI_LT_INCH'];
		$this->var_213 = $rows['TPC_MT'];
		$this->var_214 = $rows['TPC_LT'];
		$this->var_215 = $rows['CONSTANT_MT'];
		$this->var_216 = $rows['CONSTANT_LT'];
		$this->var_217 = $rows['GRAIN_CAP_CBM'];
		$this->var_218 = $rows['GRAIN_CAP_CFT'];
		$this->var_219 = $rows['ALLOWED_DRAFTM'];
		$this->var_220 = $rows['BUNKER_ROB_MT'];
		$this->var_221 = $rows['CARGO_INTAKE_MT'];
		$this->var_222 = $rows['SF_CBM_MT'];
		$this->var_223 = $rows['SF_CBFT_MT'];
		$this->var_224 = $rows['CARGO_LOADABLE_MT'];
		$this->var_226 = $rows['GROSS_BREAKDOWN'];
	    $this->var_227 = $rows['BREAKDOWN_MT'];
		$this->var_228 = $rows['TANKER_RADIO_SINGLE_DIS'];
		$this->var_229 = $rows['TC_NO'];
		
		$this->var_230 = $rows['GROSS_HIERAGE_AMOUNT'];
		$this->var_231 = $rows['HIERAGE_CVE'];
		$this->var_232 = $rows['HIERAGE_CVE_AMOUNT'];
	    $this->var_233 = $rows['OFF_HIRE_CVE'];
		$this->var_234 = $rows['OFF_HIRE_CVE_AMOUNT'];
		$this->var_235 = $rows['LESS_OFF_HIRE'];
		$this->var_236 = $rows['FINAL_HIERAGE_AMOUNT'];
		$this->var_237 = $rows['HIERAGE_BROKER_PERCENT'];
		$this->var_238 = $rows['HIERAGE_BROKER_AMT'];
		$this->var_239 = $rows['TC_HIRE_DAYS'];
		$this->var_240 = $rows['TC_CP_DATE'];
		$this->var_241 = $rows['PERIODID'];
		$this->var_242 = $rows['AUTO_PL'];
		
		$this->var_243 = $rows['LESS_PER_BLQTY'];
		$this->var_244 = $rows['BL_QTY_FREIGHT'];
		
		$this->var_245 = $rows['TC_DELIVERY_DATE'];
		$this->var_246 = $rows['TC_RE_DELIVERY_DATE'];
		$this->var_247 = $rows['TC_DELIVERY_RANGE'];
		$this->var_248 = $rows['TC_RE_DELIVERY_RANGE'];
		$this->var_249 = $rows['ACTUAL_PL'];
		$this->var_250 = $rows['TANKER_FREIGHT_RATE'];
		
		$this->var_251 = $rows['TANK_CLEANING_SECA_HRS'];
		$this->var_252 = $rows['TANK_CLEANING_NONSECA_HRS'];
		$this->var_253 = $rows['INERTING_SECA_HRS'];
		$this->var_254 = $rows['INERTING_NONSECA_HRS'];
		$this->var_255 = $rows['GAS_FREEING_SECA_HRS'];
		$this->var_256 = $rows['GAS_FREEING_NONSECA_HRS'];
		$this->var_257 = $rows['HEATING_SECA_HRS'];
		$this->var_258 = $rows['HEATING_NONSECA_HRS'];
		$this->var_259 = $rows['HEATING_SECA_HRS_1'];
		$this->var_260 = $rows['HEATING_NONSECA_HRS_1'];
		$this->var_261 = $rows['CHARTERING_PIC'];

		$this->var_262 = $rows['SEL_BUSI_TYPE'];
		
		$sql2 = "select OPEN_CARGOID, CPID, (select MATERIAL_CODE_DESC from cargo_master where cargo_master.MATERIALID = open_cargo_master.CARGO) as CARGONAME, CARGOSTEAMSIZE, LAYCAN_SDATE, BASE_FREIGHT, RDO_WS_TYPE, WS_LUMPSUM_AMOUNT, (case when (RDO_WS_TYPE = 1) THEN 'WS' ELSE 'Lumpsum' END) as WS_RDO_TEXT, (case when (RDO_WS_TYPE = 1) THEN 'Base Freight' ELSE 'Lumpsum' END) as WS_RDO_TEXT1, CARGO_RELET, COA_SPOT from open_cargo_master where OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
		
		$result2 = mysql_query($sql2) or die($sql2);
		$rows2   = mysql_fetch_assoc($result2);
		$freightdata = '';
		if($_SESSION['selBType']==1)
		{
			 if($rows2['RDO_WS_TYPE'] ==1)
		 	 {
		     	$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Base Freight(USD): '.$rows2['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT/Lumpsum (USD):'.$rows2['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==2)
		{
			 if($rows2['RDO_WS_TYPE'] ==1)
		 	 {
		     	$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, WS:'.$rows2['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Lumpsum (USD):'.$rows2['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==3)
		{
			$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Freight (USD):'.$rows2['BASE_FREIGHT'].' ';
		}
	}
}


function getBunkerValuesEstimate($fcaid,$bunkergradeid,$field)
{
	$this->funConnect();
	$sql  = "select $field from freight_cost_estimete_slave2 where FCAID='".$fcaid."' and BUNKERGRADEID='".$bunkergradeid."'";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows[$field];
}


function submitFinalFCARecordCompare()
{
	
	$this->funConnect();
	$hddnCount = $_REQUEST['hddnCount'];
	$rdoFCA 	 = $_REQUEST['rdoFCA'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;
	$year = date('Y',time());
	$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM freight_cost_estimate_compare where Year(ADD_ON_DATE) = '".$year."' and MCOMPANYID='".$_SESSION['company']."' and COAAID is NULL";
	$result = mysql_query($query) or die(mysql_error());
	$rec=mysql_num_rows($result);
	
	$year1 = $year[2].''.$year[3];
	
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['MESSAGE_NO'];
	if($rows['MESSAGE_NO'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode =$empcode;
		}
	else
		{
			$empcode= "001";
		}
	}
	
	$msg1 = $year1."-".$empcode;
	for($i=1;$i<=$hddnCount;$i++)
	{
		if($_REQUEST['rdoFCA'] == $_REQUEST['hiddnFca_'.$i])
	    {$val = $_REQUEST['rdoFCA'];}else{$val = "";}
		
		$query_check = "SELECT * FROM freight_cost_estimate_compare where FINAL_ID = '".$_REQUEST['hiddnFca_'.$i]."'";
		$result_check = mysql_query($query_check) or die($query_check);
		$rec_check = mysql_num_rows($result_check);
		if($rec_check==0)
		{
			$sql2 = "insert into freight_cost_estimate_compare (FCAID, FINAL_ID, MESSAGE_NO, USERID, REMARKS, ADD_ON_DATE, MESSAGE, MODULEID, MCOMPANYID) values ('".$_REQUEST['hiddnFca_'.$i]."', '".$val."', '".$empcode."', '".$_SESSION['uid']."', '".$_REQUEST['txtDesc_'.$i]."', NOW(), '".$msg1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."')";
			mysql_query($sql2) or die($sql2);
			mysql_query("commit"); 
			if($_REQUEST['rdoFCA'] == $_REQUEST['hiddnFca_'.$i])
			{
				$query1 = "SELECT MAX(COMID) as MAX FROM freight_cost_estimate_compare where MESSAGE='".$msg1."' and FINAL_ID!='' ";
				$result1 = mysql_query($query1) or die(mysql_error());
				$rows1 = mysql_fetch_array($result1);
				
				$sql3 = "update freight_cost_estimete_master set COMID='".$rows1['MAX']."' where FCAID='".$_REQUEST['hiddnFca_'.$i]."' ";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit"); 
			}
		}
	}
	return $msg;
}


function displayDecisionChartList($selBtype)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="fce_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">Decision Chart</th>';
	echo '<th align="left" valign="middle" width="12%">Chart No.</th>';
	echo '<th align="left" valign="middle" width="12%">Voyage No.</th>';
	echo '<th align="left" valign="middle" width="12%">Vessel</th>';
	echo '<th align="left" valign="middle" width="12%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="10%">Add On Date</th>';
	echo '<th align="left" valign="middle" width="10%">Added By</th>';
	echo '<th align="center" valign="middle" width="7%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	$sql = "select MESSAGE, MESSAGE_NO, freight_cost_estimate_compare.ADD_ON_DATE, USERID, freight_cost_estimate_compare.COMID, freight_cost_estimate_compare.FINAL_ID from freight_cost_estimate_compare inner join freight_cost_estimete_master on freight_cost_estimete_master.FCAID = freight_cost_estimate_compare.FCAID WHERE freight_cost_estimate_compare.MODULEID='".$_SESSION['moduleid']."' AND freight_cost_estimate_compare.MCOMPANYID='".$_SESSION['company']."' and FINAL_ID !='' and freight_cost_estimete_master.ESTIMATE_TYPE='".$selBtype."' order by freight_cost_estimate_compare.ADD_ON_DATE desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
		    $sql1 = "SELECT FCAID, (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=freight_cost_estimete_master.VESSEL_IMO_ID) as VESSEL_NAME, VOYAGE_NO FROM freight_cost_estimete_master WHERE FCAID= ".$rows['FINAL_ID'];
			$res1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($res1);
			$loadports = $this->getLoadPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID']);
			$disports = $this->getDisPortNameArrBasedOnIDComidAndProcessWithoutTBN($rows['COMID']);
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows1['VOYAGE_NO'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows1['VESSEL_NAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(',',$loadports).' / '.implode(',',$disports).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.date('d-m-Y',strtotime($rows['ADD_ON_DATE'])).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$this->getUserDetailBaseOnId($rows['USERID'],'CONTACT_PERSON').'</td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="#" title="View Details" data-toggle="modal" data-target="#compose-modal" onclick="getListToCompare('.explode('-',$rows['MESSAGE'])[0].','.$rows['MESSAGE_NO'].');" ><i class="fa fa-file"></i></a></td>';	
			echo '</tr>';
			$i++;
		}
	
	}echo '</tbody>';
	echo '</table></div>';
}


function displayFinalisedVoyageFixturesList($selBType)
{
	$this->funConnect();
	$sql1 = "select * from freight_cost_estimate_compare WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FINAL_ID!='' and COAAID is NULL  ";
	$res1 = mysql_query($sql1);
	$arr = array();
	while($row1 = mysql_fetch_assoc($res1))
	{
		$arr[] = $row1['FINAL_ID'];
	}
	$arr1 = implode(',',$arr);
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="fce_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="10%">Vessel Name</th>';
	echo '<th align="left" valign="middle" width="10%">Sheet Name</th>';
	echo '<th align="left" valign="middle" width="10%">DWT</th>';
	if($selBType==1)
	{
	echo '<th align="left" valign="middle" width="10%">Base Freight <span style="font-size:10px; font-style:italic;">(USD/MT)</span> / Lumpsum <span style="font-size:10px; font-style:italic;">(USD)</span></th>';
	}
	if($selBType==3)
	{
	echo '<th align="left" valign="middle" width="10%">Freight <span style="font-size:10px; font-style:italic;">(USD/MT)</th>';
	}
	if($selBType==2)
	{
	echo '<th align="left" valign="middle" width="10%">WS/<br/>Lumpsum <span style="font-size:10px; font-style:italic;">(USD/MT)</th>';
	}
	
	echo '<th align="left" valign="middle" width="6%">Delivery Port</th>';
	echo '<th align="left" valign="middle" width="6%">LP/DP</th>';
	echo '<th align="left" valign="middle" width="8%">Duration</th>';
	echo '<th align="left" valign="middle" width="8%">Cargo Quantity</th>';
	echo '<th align="left" valign="middle" width="5%">TCE</th>';
	echo '<th align="left" valign="middle" width="5%">Daily Time Charter <span style="font-size:10px; font-style:italic;">(USD/Day)</span></th>';
	echo '<th align="left" valign="middle" width="5%">P/L</th>';
	echo '<th align="left" valign="middle" width="5%">Status</th>';
	echo '<th align="left" valign="middle" width="12%">Operator</th>';
	echo '<th align="center" valign="middle" width="5%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	$sql = "select *, (select CONTACT_PERSON from login where login.LOGINID=(select OPERATOR from freight_cost_estimate_compare where freight_cost_estimate_compare.COMID = freight_cost_estimete_master.COMID)) as OPERATORNAME from freight_cost_estimete_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FCAID in (".$arr1.") and ESTIMATE_TYPE='".$selBType."' order by COMID desc ";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
		    $arr_ballast = $arr_load = $arr_discharge = array();
			$sql2 = "select PASSAGE_TYPE, LOAD_PORT_QTY, DISC_PORT_QTY, FROM_PORT, TO_PORT from freight_cost_estimete_slave1 where FCAID='".$rows['FCAID']."'";
            $res2 = mysql_query($sql2);
			while($rows2 = mysql_fetch_assoc($res2))
			{
				
				  if($rows2['LOAD_PORT_QTY']>0){$arr_load[] = $this->getPortNameBasedOnID($rows2['FROM_PORT']);}
				  if($rows2['DISC_PORT_QTY']>0){$arr_discharge[] = $this->getPortNameBasedOnID($rows2['TO_PORT']);}
				
				if($rows2['PASSAGE_TYPE'] == 1)
				{
					$arr_ballast[] = $this->getPortNameBasedOnID($rows2['FROM_PORT']);
				}
			}
			
			
			$sql2 = "select * from freight_cost_estimate_compare WHERE FCAID='".$rows['FCAID']."' ";
			$res2 = mysql_query($sql2);
			$row2 = mysql_fetch_assoc($res2);
			if($rows['FIXED']==1){$fixed = "Finalised";}else{$fixed = "Not Fixed";}
			
			$quantity = $freight = 0;
			if($rows['ESTIMATE_TYPE']==1)
			{
				$quantity = $rows['GAS_QUANTITY'];
				if($rows['GAS_MARKET']==1){$freight = 'Base Rate '.$rows['GAS_BASE_RATE'];}else{$freight = 'Lumpsum '.$rows['GAS_LUMSUM'];}
			}
			else if($rows['ESTIMATE_TYPE']==2)
			{
				$quantity = $rows['TANK_QUANTITY'];
				if($rows['TANKER_RADIO_SINGLE_DIS']==1)
				{
					$sql21 = "select MIN_WS from freight_cost_estimete_slave12 where FCAID='".$rows['FCAID']."' ";
					$res21 = mysql_query($sql21);
					$row21 = mysql_fetch_assoc($res21);
					if($rows['CHK_LUMPSUM']==1){$freight = 'Lumpsum '.$rows['LUMPSUMAMT'];}else{$freight = 'WS '.$row21['MIN_WS'];}
				}
				else
				{
					$sql12 = "select sum(AMOUNT_USD) as sum1 from freight_cost_estimete_slave10 where FCAID='".$rows['FCAID']."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$freight = 'Lumpsum '.$row12['sum1'];
				}
			
			}
			else
			{
				if($rows['QTY_TYPE_RADIO'] == 1)
				{
					$quantity = $rows['QUANTITY'];
					$freight = $rows['FREIGHT_GROSS'];
				}
				else
				{
					$sql12 = "select sum(QUANTITY) as sum, sum(GROSS_FREIGHT) as sum1 from freight_cost_estimete_slave7 where FCAID='".$rows['FCAID']."'";
					$res12 = mysql_query($sql12);
					$row12 = mysql_fetch_assoc($res12);
					$quantity = $row12['sum'];
					$freight = $row12['sum1'];
				}
			}
			
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"DWT").'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$freight.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_ballast).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.implode(', ',$arr_load).'/ '.implode(', ',$arr_discharge).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_DAYS'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$quantity.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_EARNING'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DAILY_VESSEL_OPERATION_EXP'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['PROFIT_LOSS'].'</td>';
			if($rows['FIXED']==1){
			    echo '<td align="left" valign="middle" class="input-text"><strong>'.$fixed.'</strong></td>';
				echo '<td align="left" valign="middle" class="input-text"><strong>'.$rows['OPERATORNAME'].'</strong></td>';
			}else
			{
			    echo '<td align="center" valign="middle" class="input-text"><input type="radio" name="rdoFCA" id="rdoFCA_'.$i.'" value="'.$rows['FCAID'].'" class="checkbox"/></td>';	
				echo '<td align="center" valign="middle" class="input-text"><select name="selUser_'.$i.'" id="selUser_'.$i.'" class="form-control"></select><input type="hidden" name="txtComId_'.$i.'" id="txtComId_'.$i.'" class="form-control" value="'.$rows['COMID'].'"></td>';	
			}
			
			echo '<td align="center" valign="middle" class="input-text"><a href="viewestimate.php?id='.$rows['FCAID'].'&rttype=0" title="View Details"><strong><i class="fa fa-file"></i></strong></a></td>';
			echo '</tr>';
			$i++;
		}
	
	}echo '</tbody>';
	echo '</table></div>';
}



function fixfinalisedfixturesheet()
{
	$connect				= $this->funConnect();
 	$hddnFCA1      		    = $_REQUEST['hddnFCA1'];
	$selOP      		    = $_REQUEST['selOP'];
	$hddnCOMID              = $_REQUEST['hddnCOMID'];
	$msg = 3;
	//echo $hddnCOMID;die;
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$sql = "update freight_cost_estimete_master set FIXED='1', FINAL_DATETIME=NOW(), FINAL_STATUS=1 where FCAID = '".$hddnFCA1."'";
	$sql1 = "update freight_cost_estimate_compare set OPERATOR='".$selOP."' where COMID = '".$hddnCOMID."'";
	mysql_query($sql) or die($sql); mysql_query("commit");
	mysql_query($sql1) or die($sql1); 
	mysql_query("commit");
	return $msg;
}


function completeVoyageEntry($comid)
{
	$connect				= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;	
	$sql = "update freight_cost_estimate_compare set STATUS=4 where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);	
	mysql_query("commit");	
	
	$mysql = "select GEN_AGENCY_ID from generate_agency_letter where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."' and STATUS=2";
	$myres = mysql_query($mysql);
	$myrows = mysql_fetch_assoc($myres);
	
	
	$sql1 = "update generate_agency_letter set STATUS=3 where GEN_AGENCY_ID='".$myrows['GEN_AGENCY_ID']."' and  COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql1,$connect);
	mysql_query("commit"); 
	return $msg;
}


function getVesselTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from vessel_type_master where STATUS = 1 and VesselTypeId NOT IN (6,7,8,9,10,11,12) order by VesselType ");
	echo "<option value = '' >---Select from list---</option>";
	@$selVType = @$_REQUEST['selVType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['VesselTypeId'];
		 $value= $rows['VesselType'];
		 echo "<option value='".$key."' ";
		 if($key == @$selVType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getBusinessTypeList()
{
	$this->funConnect();
	$query = mysql_query("select * from business_type_master where STATUS = 1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selBType = @$_REQUEST['selBType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['BUSINESSTYPEID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selBType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}



function insertVesselParticularDetails()
{
	$connect = $this->funConnect();
	$vessel_name 		= addslashes(trim($_REQUEST['txtVName']));
	$vessel_type		= addslashes(trim($_REQUEST['selVType']));
	$builder		    = 0;
	$hull_type			= 0;
	$dwt	 			= addslashes(trim($_REQUEST['txtDWT']));
	$year_built			= addslashes(trim($_REQUEST['txtYBDate']));
	$txtVCode			= addslashes(trim($_REQUEST['txtVCode']));
	
	$owner				= addslashes(trim($_REQUEST['txtOwner']));
	$coating			= addslashes(trim($_REQUEST['txtCoating']));
	$selBType			= addslashes(trim($_REQUEST['selBType']));
	
	$draftm				= addslashes(trim($_REQUEST['txtDraft']));
	$cranesize			= addslashes(trim($_REQUEST['txtCraneSize']));
	$grabsize			= addslashes(trim($_REQUEST['txtGrabSize']));
	
	$txtIMONo			= addslashes(trim($_REQUEST['txtIMONo']));
	$selFlag			= addslashes(trim($_REQUEST['selFlag']));
	$txtLOA				= addslashes(trim($_REQUEST['txtLOA']));
	$txtEX_Breadth		= addslashes(trim($_REQUEST['txtEX_Breadth']));
	$txtGRT				= addslashes(trim($_REQUEST['txtGRT']));
	$txtGrain			= addslashes(trim($_REQUEST['txtGrain']));
	$txtBale			= addslashes(trim($_REQUEST['txtBale']));
	$txtNOH				= addslashes(trim($_REQUEST['txtNOH']));
	$txtNOHA			= addslashes(trim($_REQUEST['txtNOHA']));
	$txtHatch_Size		= addslashes(trim($_REQUEST['txtHatch_Size']));
	$txtCargo_Gear		= addslashes(trim($_REQUEST['txtCargo_Gear']));
	$txtPI				= addslashes(trim($_REQUEST['txtPI']));
	$selCLASS_SOC		= addslashes(trim($_REQUEST['selCLASS_SOC']));
	$txtRemarks			= addslashes(trim($_REQUEST['txtRemarks']));
	
	$txtNoOfCargoTanks	= addslashes(trim($_REQUEST['txtNoOfCargoTanks']));
	$txtTankCapacity98  = addslashes(trim($_REQUEST['txtTankCapacity98']));
	$txtNoOfCargoPump	= addslashes(trim($_REQUEST['txtNoOfCargoPump']));
	$txtCargoPumpCap	= addslashes(trim($_REQUEST['txtCargoPumpCap']));
	$txtNoOfManilfolds	= addslashes(trim($_REQUEST['txtNoOfManilfolds']));
	$txtGasSBTCapacity	= addslashes(trim($_REQUEST['txtGasSBTCapacity']));
	$txtTankCapacity	= addslashes(trim($_REQUEST['txtTankCapacity']));
	$txtNoofGradeDouble	= addslashes(trim($_REQUEST['txtNoofGradeDouble']));
	$txtNoOfCargoPumpTank= addslashes(trim($_REQUEST['txtNoOfCargoPumpTank']));
	$txtTankCargoPumpCap= addslashes(trim($_REQUEST['txtTankCargoPumpCap']));
	$txtSBTCapacity		= addslashes(trim($_REQUEST['txtSBTCapacity']));
	$txtNRT     		= addslashes(trim($_REQUEST['txtNRT']));
	
	$txtCRMFILE1		= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1		= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name 	= $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name 	= implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
		//insert query here.............
		$sql = "insert into vessel_imo_master (VESSEL_NAME,VESSEL_TYPE,BUILDER,HULL_TYPE,DWT,YEARBUILT,ALLOCATE_STATUS,OWNER,COATING ,TRANS_DATE, BUSINESSTYPEID,MCOMPANYID,DRAFTM,CRANESIZE,GRABSIZE,IMO_NO,FLAG,LOA,EXT_BREADTH,GRT_NRT,GRAIN,BALE,NOH,NOHA,HATCH_SIZE,CARGO_GEAR,P_I,CLA_SOC_ID,REMARKS, ATTACHMENT, ATTACHMENT_NAME, GAS_CARGO_TANKS, GAS_TANK_CAPACITY, GAS_CARGO_PUMPS, GAS_MAIN_CARGO_PUMPS, SIZE_OF_MONIFOLDS, SBT_CAPACITY, TANKER_CAPACITY, NO_OF_GRADE, TANKER_CARGO_PUMP, TANKER_SBT_CAPACITY, TANKER_PUMP_MAINCAP, NRT, VESSEL_CODE) values ('".$vessel_name."','".$vessel_type."','".$builder."','".$hull_type."','".$dwt."','".$year_built."','0','".$owner."','".$coating."','".date("Y-m-d",time())."','".$selBType."','".$_SESSION['company']."','".$draftm."','".$cranesize."','".$grabsize."','".$txtIMONo."','".$selFlag."','".$txtLOA."','".$txtEX_Breadth."','".$txtGRT."','".$txtGrain."','".$txtBale."','".$txtNOH."','".$txtNOHA."','".$txtHatch_Size."','".$txtCargo_Gear."','".$txtPI."','".$selCLASS_SOC."','".$txtRemarks."','".addslashes($upload1)."','".addslashes($name1)."','".$txtNoOfCargoTanks."','".$txtTankCapacity98."','".$txtNoOfCargoPump."','".$txtCargoPumpCap."','".$txtNoOfManilfolds."','".$txtGasSBTCapacity."','".$txtTankCapacity."','".$txtNoofGradeDouble."','".$txtNoOfCargoPumpTank."','".$txtSBTCapacity."','".$txtTankCargoPumpCap."','".$txtNRT."','".$txtVCode."')";
		mysql_query($sql) or die($sql);
		$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Added successfully.',NOW())";
	mysql_query($sql3) or die($sql3);
		mysql_query("commit");
		return $msg; 
}

function VesselAllocation()
{
	$connect = $this->funConnect();
	$arr     = $_REQUEST['checkIMObox'];
	$msg     = 0;
 
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
 
	for($i=0;$i<count($arr);$i++)
	{
		$sql = "select * from vessel_allocation_master where VESSEL_IMO_ID='".$arr[$i]."' ";
		$res = mysql_query($sql);
		$rec = mysql_num_rows($res);
		if($rec == 0)
		{
			$product  = implode(",",$_REQUEST['selCProduct_'.$arr[$i]]);
			$sql2     = "insert into vessel_allocation_master (VESSEL_IMO_ID,TRANS_DATE,MODULE_ID,MCOMPANYID) values ('".$arr[$i]."','".date("Y-m-d",time())."','".$product."','".$_SESSION['company']."')";
			mysql_query($sql2)or die($sql2);
			
			$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Allocated successfully.',NOW())";
			mysql_query($sql3) or die($sql3);
		}else{
			
			$product   = implode(",",$_REQUEST['selCProduct_'.$arr[$i]]);
			$sql2 = "update vessel_allocation_master set MODULE_ID='".$product."'  where VESSEL_IMO_ID='".$arr[$i]."' and MCOMPANYID='".$_SESSION['company']."' ";
			mysql_query($sql2)or die($sql2);
			
			$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Allocated successfully.',NOW())";
			mysql_query($sql3) or die($sql3);
		}
	}
	mysql_query("commit");
	return $msg; 
}


function VesselAllocationTab()
{
	$connect = $this->funConnect();
	$value     = $_REQUEST['numvsl'];
	$msg     = 0;
 
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	for($i=1;$i<=$value;$i++)
	{
		if(isset($_REQUEST['checkIMObox1_'.$i]))
		{
			$sql = "select * from vessel_allocation_master where VESSEL_IMO_ID='".$_REQUEST['checkIMObox1_'.$i]."' ";
			$res = mysql_query($sql);
			$rec = mysql_num_rows($res);
			if($rec == 0)
			{
				$product   = implode(",",$_REQUEST['selCProduct1_'.$i]);
				$sql2     = "insert into vessel_allocation_master (VESSEL_IMO_ID,TRANS_DATE,MODULE_ID,MCOMPANYID) values ('".$_REQUEST['checkIMObox1_'.$i]."','".date("Y-m-d",time())."','".$product."','".$_SESSION['company']."')";
				//echo $sql2;
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
				$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Allocated successfully.',NOW())";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
			}else{
				$product   = implode(",",$_REQUEST['selCProduct1_'.$i]);
				$sql2 = "update vessel_allocation_master set MODULE_ID='".$product."'  where VESSEL_IMO_ID='".$_REQUEST['checkIMObox1_'.$i]."' and MCOMPANYID='".$_SESSION['company']."' ";
				//echo $sql2;
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
				$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Allocated successfully.',NOW())";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		else
		{
			
		}
	}//die();
	mysql_query("commit");
	return $msg; 
}


function getProductListForUser()
{
$state = array( 5 =>'COD &ndash; In', 6 =>'COD &ndash; Out', 7 =>'Vessel Relet');
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $id){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getProductListForUserForUpdate($modules)
{
	$this->funConnect();
	$product_id = '5,6,7';
	$arr = explode(",",$product_id);
	$m_arr = explode(",",$modules);
	for($i=0;$i<count($arr);$i++)
	{
		 $key= $arr[$i];
		 $value= $this->getProductShortNameBasedOnID($arr[$i]);
		 echo "<option value='".$key."' ";
		 if (in_array($key, $m_arr)) { echo " selected";}
		 echo ">".$value."</option>";
	}
}

function getProductShortNameBasedOnID($id)
{
	if($id == 1){return 'CMW';}
	if($id == 2){return 'COW &ndash; In';}
	if($id == 3){return 'COW &ndash; Out';}
	if($id == 4){return 'CMD';}
	if($id == 5){return 'COD &ndash; In';}
	if($id == 6){return 'COD &ndash; Out';}
	if($id == 7){return 'Vessel Relet';}
}

function updateVesselMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtVName 				= addslashes(trim($_REQUEST['txtVName']));
	$selVType 				= addslashes(trim($_REQUEST['selVType']));
	$selBuilder 			= 0;
	$selHullType 			= 0;
	$txtDWT 				= addslashes(trim($_REQUEST['txtDWT']));
	$txtYBDate 				= addslashes(trim($_REQUEST['txtYBDate']));
	$txtOwner 				= addslashes(trim($_REQUEST['txtOwner']));
	$txtCoating 			= addslashes(trim($_REQUEST['txtCoating']));
	$selBType				= addslashes(trim($_REQUEST['selBType']));
	$txtVCode				= addslashes(trim($_REQUEST['txtVCode']));
	
	$draftm				= addslashes(trim($_REQUEST['txtDraft']));
	$cranesize			= addslashes(trim($_REQUEST['txtCraneSize']));
	$grabsize			= addslashes(trim($_REQUEST['txtGrabSize']));
	
	$txtIMONo			= addslashes(trim($_REQUEST['txtIMONo']));
	$selFlag			= addslashes(trim($_REQUEST['selFlag']));
	$txtLOA				= addslashes(trim($_REQUEST['txtLOA']));
	$txtEX_Breadth		= addslashes(trim($_REQUEST['txtEX_Breadth']));
	$txtGRT				= addslashes(trim($_REQUEST['txtGRT']));
	$txtGrain			= addslashes(trim($_REQUEST['txtGrain']));
	$txtBale			= addslashes(trim($_REQUEST['txtBale']));
	$txtNOH				= addslashes(trim($_REQUEST['txtNOH']));
	$txtNOHA			= addslashes(trim($_REQUEST['txtNOHA']));
	$txtHatch_Size		= addslashes(trim($_REQUEST['txtHatch_Size']));
	$txtCargo_Gear		= addslashes(trim($_REQUEST['txtCargo_Gear']));
	$txtPI				= addslashes(trim($_REQUEST['txtPI']));
	$selCLASS_SOC		= addslashes(trim($_REQUEST['selCLASS_SOC']));
	$txtRemarks			= addslashes(trim($_REQUEST['txtRemarks']));
	
	$txtNoOfCargoTanks	= addslashes(trim($_REQUEST['txtNoOfCargoTanks']));
	$txtTankCapacity98  = addslashes(trim($_REQUEST['txtTankCapacity98']));
	$txtNoOfCargoPump	= addslashes(trim($_REQUEST['txtNoOfCargoPump']));
	$txtCargoPumpCap	= addslashes(trim($_REQUEST['txtCargoPumpCap']));
	$txtNoOfManilfolds	= addslashes(trim($_REQUEST['txtNoOfManilfolds']));
	$txtGasSBTCapacity	= addslashes(trim($_REQUEST['txtGasSBTCapacity']));
	$txtTankCapacity	= addslashes(trim($_REQUEST['txtTankCapacity']));
	$txtNoofGradeDouble	= addslashes(trim($_REQUEST['txtNoofGradeDouble']));
	$txtNoOfCargoPumpTank= addslashes(trim($_REQUEST['txtNoOfCargoPumpTank']));
	$txtTankCargoPumpCap= addslashes(trim($_REQUEST['txtTankCargoPumpCap']));
	$txtSBTCapacity		= addslashes(trim($_REQUEST['txtSBTCapacity']));
	$txtNRT     		= addslashes(trim($_REQUEST['txtNRT']));

	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update vessel_imo_master set VESSEL_TYPE='".$selVType."',BUILDER='".$selBuilder."',HULL_TYPE='".$selHullType."',DWT='".$txtDWT."',YEARBUILT='".$txtYBDate."',OWNER='".$txtOwner."',COATING='".$txtCoating."',BUSINESSTYPEID='".$selBType."',DRAFTM='".$draftm."',CRANESIZE='".$cranesize."',GRABSIZE='".$grabsize."',IMO_NO='".$txtIMONo."',FLAG='".$selFlag."',LOA='".$txtLOA."',EXT_BREADTH='".$txtEX_Breadth."',GRT_NRT='".$txtGRT."',GRAIN='".$txtGrain."',BALE='".$txtBale."',NOH='".$txtNOH."',NOHA='".$txtNOHA."',HATCH_SIZE='".$txtHatch_Size."',CARGO_GEAR='".$txtCargo_Gear."',P_I='".$txtPI."',CLA_SOC_ID='".$selCLASS_SOC."',REMARKS='".$txtRemarks."',ATTACHMENT='".addslashes($upload1)."', ATTACHMENT_NAME='".addslashes($name1)."', GAS_CARGO_TANKS='".$txtNoOfCargoTanks."', GAS_TANK_CAPACITY='".$txtTankCapacity98."', GAS_CARGO_PUMPS='".$txtNoOfCargoPump."', GAS_MAIN_CARGO_PUMPS='".$txtCargoPumpCap."', SIZE_OF_MONIFOLDS='".$txtNoOfManilfolds."', SBT_CAPACITY='".$txtGasSBTCapacity."', TANKER_CAPACITY='".$txtTankCapacity."', NO_OF_GRADE='".$txtNoofGradeDouble."', TANKER_CARGO_PUMP='".$txtNoOfCargoPumpTank."', TANKER_SBT_CAPACITY='".$txtSBTCapacity."', TANKER_PUMP_MAINCAP='".$txtTankCargoPumpCap."', NRT='".$txtNRT."', VESSEL_CODE='".$txtVCode."'  where  VESSEL_IMO_ID='".$id."'";
	mysql_query($sql) or die($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Fleet Updated successfully.',NOW())";
	mysql_query($sql3,$connect) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewVesselRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM vessel_imo_master where VESSEL_IMO_ID=".$id;
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['REGID'];
		$this->var_2 = $rows['VESSEL_NAME'];
		$this->var_3 = $rows['VESSEL_TYPE'];
		$this->var_4 = $rows['BUILDER'];
		$this->var_5 = $rows['HULL_TYPE'];
		$this->var_6 = $rows['DWT'];
		$this->var_7 = $rows['YEARBUILT'];
		$this->var_8 = $rows['OWNER'];
		$this->var_9 = $rows['COATING'];
		$this->var_10 = $rows['BUSINESSTYPEID'];
		$this->var_11 = $rows['DRAFTM'];
		$this->var_12 = $rows['CRANESIZE'];
		$this->var_13 = $rows['GRABSIZE'];
		$this->var_14 = $rows['IMO_NO'];
		$this->var_15 = $rows['FLAG'];
		$this->var_16 = $rows['LOA'];
		$this->var_17 = $rows['EXT_BREADTH'];
		$this->var_18 = $rows['GRT_NRT'];
		$this->var_19 = $rows['GRAIN'];
		$this->var_20 = $rows['BALE'];
		$this->var_21 = $rows['NOH'];
		$this->var_22 = $rows['NOHA'];
		$this->var_23 = $rows['HATCH_SIZE'];
		$this->var_24 = $rows['CARGO_GEAR'];
		$this->var_25 = $rows['P_I'];
		$this->var_26 = $rows['CLA_SOC_ID'];
		$this->var_27 = $rows['REMARKS'];
		$this->var_28 = $rows['GAS_CARGO_TANKS'];
		$this->var_29 = $rows['GAS_TANK_CAPACITY'];
		$this->var_30 = $rows['GAS_CARGO_PUMPS'];
		$this->var_31 = $rows['GAS_MAIN_CARGO_PUMPS'];
		$this->var_32 = $rows['SIZE_OF_MONIFOLDS'];
		$this->var_33 = $rows['SBT_CAPACITY'];
		$this->var_34 = $rows['TANKER_CAPACITY'];
		$this->var_35 = $rows['NO_OF_GRADE'];
		$this->var_36 = $rows['TANKER_CARGO_PUMP'];
		$this->var_37 = $rows['TANKER_SBT_CAPACITY'];
		$this->var_38 = $rows['TANKER_PUMP_MAINCAP'];
		$this->var_39 = $rows['NRT'];
		$this->var_40 = $rows['ATTACHMENT'];
		$this->var_41 = $rows['ATTACHMENT_NAME'];
		$this->var_42 = $rows['VESSEL_CODE'];
	}
}


function insertOtherInvoiceDetails($comid)
{
	$connect 			= $this->funConnect();	
	$comid 				= addslashes(trim($_REQUEST['comid']));
	$name 				= addslashes(trim($_REQUEST['name']));
	
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtDNote	 		= addslashes(trim($_REQUEST['txtDNote']));
	$txtInvoiceid       = addslashes(trim($_REQUEST['txtInvoiceid']));
	
	$txtDNote_1	 		= explode("/",$_REQUEST['txtDNote']);
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtFCAID	 		= addslashes(trim($_REQUEST['txtFCAID']));

	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtDueDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	
	$txtInvAmount	    = addslashes(trim($_REQUEST['txtInvAmount']));
	
	$selNOB	 		    = addslashes(trim($_REQUEST['selNOB']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	
	$txtNetAmtPayable	= addslashes(trim($_REQUEST['txtNetAmtPayable']));
	$txtDNote1			= addslashes(trim($_REQUEST['txtDNote1']));
	
	
	$rdoTaxApplicable         = addslashes(trim($_REQUEST['rdoTaxApplicable']));
	$rdoGSTVAT                = addslashes(trim($_REQUEST['rdoGSTVAT']));
	$txtSGST                  = addslashes(trim($_REQUEST['txtSGST']));
	$txtSGST_Amount           = addslashes(trim($_REQUEST['txtSGST_Amount']));
	$txtCGST                  = addslashes(trim($_REQUEST['txtCGST']));
	$txtCGST_Amount           = addslashes(trim($_REQUEST['txtCGST_Amount']));
	$txtIGST                  = addslashes(trim($_REQUEST['txtIGST']));
	$txtIGST_Amount           = addslashes(trim($_REQUEST['txtIGST_Amount']));
	$txtVAT                   = addslashes(trim($_REQUEST['txtVAT']));
	$txtVAT_Amount            = addslashes(trim($_REQUEST['txtVAT_Amount']));
	$txtAmtPayableWithTax     = addslashes(trim($_REQUEST['txtAmtPayableWithTax']));
	$selApprovers             = $_REQUEST['selApprovers'];
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$filename = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$filename = implode(',',$filename);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $filename != ''){ $filename1 = $txtCRMNAME1.','.$filename;}
	else if($txtCRMNAME1 == '' && $filename != ''){ $filename1 = $filename;}
	else if($txtCRMNAME1 != '' && $filename == ''){ $filename1 = $txtCRMNAME1;}
	
	
	$invoiceidd = '';$creatorloginid = '';
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$qsql = "select * from other_invoice_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR='".$txtVendor."' and MESSAGE = '".$txtDNote1."' and P_TYPE='".$name."'";
	//echo $qsql;die;
	$qres = mysql_query($qsql) or die($qsql);
	$qrec = mysql_num_rows($qres);
	if($qrec == 0)
	{
		$sql = "insert into other_invoice_master (COMID, MODULEID, MCOMPANYID, DATE, I_TYPE, NOB, STATUS, MESSAGE, VENDOR, GROSS_AMT, CPDATE, FCAID, REMARKS, PAYMENT_TERMS, EXCHANGE_CURRENCY, EXCHANGE_RATE, NET_PAYABLE, P_TYPE, ATTEN, DUE_DATE, EXCHANGE_DATE,  SHIP_OWNER, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$txtDate."', '".$selIType."', '".$selNOB."', '".$txtStatus."', '".$txtDNote."', '".$txtVendor."', '".$this->getCheckNullVal($txtInvAmount)."', '".$txtCP_Date."', '".$txtFCAID."', '".$txtDesc."', '".$txtPaymentTerms."', '".$selExchangeCurrency."', '".$txtExchangeRate."', '".$txtNetAmtPayable."', '".$name."', '".$txtAttenName."', '".$txtDueDate."', '".$txtExchangeDate."', '".$selFromOwner."', '".$this->getCheckNullVal($rdoTaxApplicable)."', '".$this->getCheckNullVal($rdoGSTVAT)."', '".$this->getCheckNullVal($txtSGST)."', '".$this->getCheckNullVal($txtCGST)."', '".$this->getCheckNullVal($txtIGST)."', '".$this->getCheckNullVal($txtVAT)."', '".$this->getCheckNullVal($txtAmtPayableWithTax)."', '".$this->getCheckNullVal($txtSGST_Amount)."', '".$this->getCheckNullVal($txtCGST_Amount)."', '".$this->getCheckNullVal($txtIGST_Amount)."', '".$this->getCheckNullVal($txtVAT_Amount)."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$upload1."', '".$filename1."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql1 = "select max(INVOICEID) as max from other_invoice_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$invoiceidd = $rows1['max'];
		$creatorloginid = $_SESSION['uid'];
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into other_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into other_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$txtDemDisID  = $_REQUEST['txtDemDisID'];
		for($i=1;$i<=$txtDemDisID;$i++)
		{
		    if(isset($_REQUEST['chkDemDis_'.$i]))
			{
				$txtDemDisPort	 	  = addslashes(trim($_REQUEST['txtDemDisPort_'.$i]));
				$txtDemDisAmt         = $this->getCheckNullVal($_REQUEST['txtDemDisAmt_'.$i]);
				$txtDemDisPortid	  = addslashes(trim($_REQUEST['txtDemDisPortid_'.$i]));
				$txtDemDisRandomid 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtDemDisRandomid_'.$i])));
				$txtDemDisVendorid 	  = addslashes(trim($_REQUEST['txtDemDisVendorid_'.$i]));
				
				$sql2 = "insert into other_invoice_slave1 (INVOICEID, VENDORID, DEM_AMT, RANDOMID, PORT, PORTID) values ('".$rows1['max']."', '".$txtDemDisVendorid."', '".$txtDemDisAmt."', '".$txtDemDisRandomid."', '".$txtDemDisPort."', '".$txtDemDisPortid."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." ".$name." (".$txtDNote.") Created Successfully.");
	}
	else
	{
		$qrows = mysql_fetch_assoc($qres);
		$invoiceidd = $qrows['INVOICEID'];
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $qrows['APPROVERS'];
		}
		$creatorloginid = $qrows['CREATOR'];
		
		$sql = "update other_invoice_master set DATE='".$txtDate."', I_TYPE='".$selIType."', NOB='".$selNOB."', STATUS='".$txtStatus."', MESSAGE='".$txtDNote."', VENDOR='".$txtVendor."', GROSS_AMT='".$this->getCheckNullVal($txtInvAmount)."', CPDATE='".$txtCP_Date."', FCAID='".$txtFCAID."', REMARKS='".$txtDesc."', PAYMENT_TERMS='".$txtPaymentTerms."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', NET_PAYABLE='".$txtNetAmtPayable."', P_TYPE='".$name."', ATTEN='".$txtAttenName."', DUE_DATE='".$txtDueDate."', EXCHANGE_DATE='".$txtExchangeDate."',  SHIP_OWNER='".$selFromOwner."', EXCHANGE_RATE='".$txtExchangeRate."', RDOTAXAPPLICABLE='".$this->getCheckNullVal($rdoTaxApplicable)."', RDOVATGST='".$this->getCheckNullVal($rdoGSTVAT)."', SGST_PERCENT='".$this->getCheckNullVal($txtSGST)."', CGST_PERCENT='".$this->getCheckNullVal($txtCGST)."', IGST_PERCENT='".$this->getCheckNullVal($txtIGST)."', VAT_PERCENT='".$this->getCheckNullVal($txtVAT)."', NET_PAYABLE_TAX='".$this->getCheckNullVal($txtAmtPayableWithTax)."', SGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtSGST_Amount)."', CGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtCGST_Amount)."', IGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtIGST_Amount)."', VAT_PERCENT_AMOUNT='".$this->getCheckNullVal($txtVAT_Amount)."', APPROVERS='".$approversel."', UPLOAD='".$upload1."', UPLOAD_NAME='".$filename1."' where INVOICEID='".$qrows['INVOICEID']."'";
		
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql_del = "delete from other_invoice_slave where INVOICEID='".$qrows['INVOICEID']."'";
		$sql_del1 = "delete from other_invoice_slave1 where INVOICEID='".$qrows['INVOICEID']."'";
		mysql_query($sql_del);
		mysql_query($sql_del1);
		mysql_query("commit");
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if(isset($_REQUEST['txtAddDes_'.$i]))
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into other_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if(isset($_REQUEST['txtSubDes_'.$i]))
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into other_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
				mysql_query($sql2);
			}
		}
		
		$txtDemDisID  = $_REQUEST['txtDemDisID'];
		for($i=1;$i<=$txtDemDisID;$i++)
		{
		    if(isset($_REQUEST['chkDemDis_'.$i]))
			{
				$txtDemDisPort	 	  = addslashes(trim($_REQUEST['txtDemDisPort_'.$i]));
				$txtDemDisAmt         = $this->getCheckNullVal($_REQUEST['txtDemDisAmt_'.$i]);
				$txtDemDisPortid	  = addslashes(trim($_REQUEST['txtDemDisPortid_'.$i]));
				$txtDemDisRandomid 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtDemDisRandomid_'.$i])));
				$txtDemDisVendorid 	  = addslashes(trim($_REQUEST['txtDemDisVendorid_'.$i]));
				
				$sql2 = "insert into other_invoice_slave1 (INVOICEID, VENDORID, DEM_AMT, RANDOMID, PORT, PORTID) values ('".$qrows['INVOICEID']."', '".$txtDemDisVendorid."', '".$txtDemDisAmt."', '".$txtDemDisRandomid."', '".$txtDemDisPort."', '".$txtDemDisPortid."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." ".$name." (".$txtDNote.") Updated Successfully.");
	}
	
	$this->inactiveUserAlerts('OTHER INVOICE', $_SESSION['uid'], $invoiceidd);
	
	$creatorsarr   = array($creatorloginid);
	$approverarr1  = $_REQUEST['selApprovers'];
	$approverarr2  = $this->getUsersWithAuthority('INI_FREIGHT_CHK_APP_2');
	$appaccountarr = $this->getUsersWithAuthority('INI_FREIGHT_CHK_ACC');
	
	$url = './invoice_others.php?id='.$_REQUEST['id'].'&page='.$_REQUEST['page'].'&name='.$_REQUEST['name'].'&amounttitle='.$_REQUEST['amounttitle'];
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'OTHER INVOICE';
	
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$name.' ('.$vesselname.' - '.$txtDNote.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$name.' ('.$vesselname.' - '.$txtDNote.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$name.' ('.$vesselname.' - '.$txtDNote.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$name.' ('.$vesselname.' - '.$txtDNote.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{
		     if(!empty($appaccountarr))
			 {
			     $userarray = $appaccountarr;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' Approved '.$name.' ('.$vesselname.' - '.$txtDNote.')', $invoiceidd);				  
				  }
			 }
		}
	}
	
	mysql_query("commit");
	return $msg.','.$comid;  
}

function insertOtherInvoiceReceivedDetails($comid)
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update other_invoice_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where INVOICEID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$this->inactiveUserAlerts('OTHER INVOICE', $_SESSION['uid'], $txtP_ID);
	
	return $msg; 
}


function deleteDumerageInvoiceRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txtDEL_ID']));
	$comid 			    = addslashes(trim($_REQUEST['comid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	$sql = "delete from dumerage_invoice_master where INVOICEID='".$id."'";
	mysql_query($sql);
	
	$sql1 = "delete dumerage_invoice_slave where INVOICEID='".$id."'";
	mysql_query($sql1);
	
	mysql_query("commit"); 
	return $msg;
}


function getMessageNumberForDemurrageInvoice($vessel)
{
  $this->funConnect();
	
	$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM dumerage_invoice_master where 1=1 ";
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['MESSAGE_NO'];
	if($rows['MESSAGE_NO'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode =strtoupper($vessel).'/INV/'.$empcode.'/'.date("Y",time());//INNER if ends here.
		}//if ends here.
	else
		{
			$empcode= strtoupper($vessel).'/INV/001/2014';
		}
	}//WHILE ends here.BW/DM/001/2014
	
return $empcode;
}


function getVesselIMOIDBaseOnVesselName($vlsName)
{
	$this->funConnect();
	$sql  = "select  VESSEL_IMO_ID from vessel_imo_master where VESSEL_NAME='".$vlsName."'";
	$res  = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['VESSEL_IMO_ID'];
}

function getCheckListLoadPortRecordsDataBasedOnMappingIDEntryName($comid,$entity_name,$field,$port,$portid,$randomno)
{
	$connect = $this->funConnect();
	if($port == "LP")
	{
	$sql = "select ".$field." from checklist_loadport where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' and ENTITY_NAME in ('ETA 30 DAYS','ETA 25 DAYS','ETA 20 DAYS','ETA 15 DAYS','ETA 10 DAYS','ETA 7 DAYS','ETA 5 DAYS','ETA 3 DAYS','ETA 2 DAYS','ETA 1 DAY') and PORT='".$port."' and RANDOMID='".$randomno."' and PORTID='".$portid."' order by CHKLIST_LPID desc";
	}
	else if($port == "DP")
	{
	$sql = "select ".$field." from checklist_loadport where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' and ENTITY_NAME in ('ETA 30 DAYS','ETA 25 DAYS','ETA 20 DAYS','ETA 15 DAYS','ETA 10 DAYS','ETA 7 DAYS','ETA 5 DAYS','ETA 3 DAYS','ETA 2 DAYS','ETA 1 DAY') and ENTITY_VALUE!='' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$randomno."' order by CHKLIST_LPID desc";
	}
	$result  = mysql_query($sql);
	$rows    = mysql_fetch_assoc($result);
	return $rows[$field];
}


function getVendorBasedOnTypeIDList()
{
	$this->funConnect();
	$query = mysql_query("SELECT * FROM vendor_master WHERE VENDOR_TYPEID=17 and MCOMPANYID='".$_SESSION['company']."' order by VENDOR_TYPEID,NAME ");
	echo "<option value = '' >---select from list---</option>";
	@$selShipper = @$_REQUEST['selShipper'];
	while($rows = mysql_fetch_assoc($query))
		{
			 $key= $rows['VENDORID'];
			 $value= addslashes($rows['NAME'])." ( ".$rows['CODE']." )";
			 echo '<option value="'.$key.'"';
			 if($key == @$selShipper){ echo " selected";}
			 echo ">".$value."</option>";
		}
}

function getPaymentTermName($id)
{
    if($id == 1){return "SHINC";}
	if($id == 2){return "SSHEX";}
	if($id == 3){return "FSHEX";}
	if($id == 4){return "D.A.P.";}
}





function updateVesselMainMasterOne()
{
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;
	
	$sql1 = "delete from vessel_master_1 where VESSEL_IMO_ID=".$id;
	mysql_query($sql1);
	
	
	$dateOfChange = date("Y-m-d",strtotime($_REQUEST['txtDOC']));
	
	if($_REQUEST['txtDOC'] == ""){
		$dateOfChange1 = "1970-01-01";
	}else{
		$dateOfChange1 = $dateOfChange;
	}
	
	$dateICPADOS = date("Y-m-d",strtotime($_REQUEST['txtICPADOS_3']));
	
	if($_REQUEST['txtICPADOS_3'] == ""){
		$dateICPADOS1 = "1970-01-01";
	}else{
		$dateICPADOS1 = $dateICPADOS;
	}
	
	$sql2 = "insert into vessel_master_1 (VESSEL_IMO_ID, VP_NAME, DATE_OF_CHANGE, FLAG_ID, BUILT_DATE, COUNTRY_ID, YARD_NAME, CLASS_R_NO, OFFICIAL_NO, IMO_NO, PORT_ID, OWNERS_FULL, MANAGERS_FULL, OWNERS_STATE, OPERATION_PURPOSE, BAREBOAT, DISPONENT_OWNER, SUMMER_1, SUMMER_2, SUMMER_3, WINTER_1, WINTER_2, WINTER_3, TROPICAL_1, TROPICAL_2, TROPICAL_3, SUMMER_TIM_1, SUMMER_TIM_2, SUMMER_TIM_3, WINTER_TIM_1, WINTER_TIM_2, WINTER_TIM_3, TROPICAL_TIM_1, TROPICAL_TIM_2, TROPICAL_TIM_3, PANAMA_CANAL, SUEZ_CANAL, SEAWAY, PANAMA_CANAL_1, PANAMA_RADIUS, SEAWAY_1, GT_INATERNATIONAL, GT_SUEZ, GT_PANAMA, GT_BRITISH, LOA, LBW, EXTREME_BREADTH, DEPTH_MODULE, FULL_BALLAST_1, FULL_BALLAST_2, FULL_BALLAST_3, LIGHT_BALLAST_1, LIGHT_BALLAST_2, LIGHT_BALLAST_3, TSTE_1, TSTE_2, TSTE_3, NOH_1, NOH_2, NOH_3, MIDSHIPS_1, MIDSHIPS_2, MIDSHIPS_3, LAST_HATCH_1, LAST_HATCH_2, LAST_HATCH_3, AT_1, NOH_1_1, MIDSHIPS_1_1, LAST_HATCH_1_1, VESSEL_BALLAST, DISTANCE_KEEL, COBT, COBC, CEF, DFC, FWC, SCAD, POE, NFWR, SHAFT_GEN, VOES, DOAS, VESSEL_IMAGE, WINTER_4, TROPICAL_4, SUMMER_TIM_4, WINTER_TIM_4, TROPICAL_TIM_4, DISPLACEMENT, DWT_LT, DRAFT_FT, TPI_MT, TPI_LT, TPC_LT, WINTER_5, WINTER_6, WINTER_7, WINTER_8, TROPICAL_5, TROPICAL_6, TROPICAL_7, TROPICAL_8, SUMMER_TIM_5, SUMMER_TIM_6, SUMMER_TIM_7, SUMMER_TIM_8, WINTER_TIM_5, WINTER_TIM_6, WINTER_TIM_7, WINTER_TIM_8, TROPICAL_TIM_5, TROPICAL_TIM_6, TROPICAL_TIM_7, TROPICAL_TIM_8, CONSTANTMT, CONSTANTLT, TPC_MT) values ('".$id."', '".addslashes(trim($_REQUEST['txtVPName']))."', '".$dateOfChange1."', '".addslashes(trim($_REQUEST['selFlag']))."', '".date("Y-m-d",strtotime($_REQUEST['txtBuiltDate']))."', '".addslashes(trim($_REQUEST['selCountry']))."', '".addslashes(trim($_REQUEST['txtYName']))."', '".addslashes(trim($_REQUEST['txtCRNo']))."', '".addslashes(trim($_REQUEST['txtOfficialNo']))."', '".addslashes(trim($_REQUEST['txtIMONo']))."', '".addslashes(trim($_REQUEST['selPort']))."', '".addslashes(trim($_REQUEST['txtOwner']))."', '".addslashes(trim($_REQUEST['txtManager']))."', '".addslashes(trim($_REQUEST['txtICPADOS']))."', '".addslashes(trim($_REQUEST['txtICPADOS_1']))."', '".addslashes(trim($_REQUEST['txtICPADOS_2']))."', '".$dateICPADOS1."', '".addslashes(trim($_REQUEST['txtSumid_1']))."', '".addslashes(trim($_REQUEST['txtSumid_2']))."', '".addslashes(trim($_REQUEST['txtSumid_3']))."', '".addslashes(trim($_REQUEST['txtWinid_1']))."', '".addslashes(trim($_REQUEST['txtWinid_2']))."', '".addslashes(trim($_REQUEST['txtWinid_3']))."', '".addslashes(trim($_REQUEST['txtTropicalid_1']))."', '".addslashes(trim($_REQUEST['txtTropicalid_2']))."', '".addslashes(trim($_REQUEST['txtTropicalid_3']))."', '".addslashes(trim($_REQUEST['txtSumTimid_1']))."', '".addslashes(trim($_REQUEST['txtSumTimid_2']))."', '".addslashes(trim($_REQUEST['txtSumTimid_3']))."', '".addslashes(trim($_REQUEST['txtWinTimid_1']))."', '".addslashes(trim($_REQUEST['txtWinTimid_2']))."', '".addslashes(trim($_REQUEST['txtWinTimid_3']))."', '".addslashes(trim($_REQUEST['txtTropicalTimid_1']))."', '".addslashes(trim($_REQUEST['txtTropicalTimid_2']))."', '".addslashes(trim($_REQUEST['txtTropicalTimid_3']))."', '".addslashes(trim($_REQUEST['selIVFFTO_1']))."', '".addslashes(trim($_REQUEST['selIVFFTO_2']))."', '".addslashes(trim($_REQUEST['selIVFFTO_3']))."', '".addslashes(trim($_REQUEST['txtPanama']))."', '".addslashes(trim($_REQUEST['selPanama']))."', '".addslashes(trim($_REQUEST['txtPanama_1']))."', '".addslashes(trim($_REQUEST['txtGT_1']))."', '".addslashes(trim($_REQUEST['txtGT_2']))."', '".addslashes(trim($_REQUEST['txtGT_3']))."', '".addslashes(trim($_REQUEST['txtGT_4']))."', '".addslashes(trim($_REQUEST['txtLOA']))."', '".addslashes(trim($_REQUEST['txtLBP']))."', '".addslashes(trim($_REQUEST['txtEB']))."', '".addslashes(trim($_REQUEST['txtDM']))."', '".addslashes(trim($_REQUEST['txtFB_1']))."', '".addslashes(trim($_REQUEST['txtFB_2']))."', '".addslashes(trim($_REQUEST['txtFB_3']))."', '".addslashes(trim($_REQUEST['txtLB_1']))."', '".addslashes(trim($_REQUEST['txtLB_2']))."', '".addslashes(trim($_REQUEST['txtLB_3']))."', '".addslashes(trim($_REQUEST['txtTSTE_1']))."', '".addslashes(trim($_REQUEST['txtTSTE_2']))."', '".addslashes(trim($_REQUEST['txtTSTE_3']))."', '".addslashes(trim($_REQUEST['txtNOH_1']))."', '".addslashes(trim($_REQUEST['txtNOH_2']))."', '".addslashes(trim($_REQUEST['txtNOH_3']))."', '".addslashes(trim($_REQUEST['txtMS_1']))."', '".addslashes(trim($_REQUEST['txtMS_2']))."', '".addslashes(trim($_REQUEST['txtMS_3']))."', '".addslashes(trim($_REQUEST['txtLH_1']))."', '".addslashes(trim($_REQUEST['txtLH_2']))."', '".addslashes(trim($_REQUEST['txtLH_3']))."', '".addslashes(trim($_REQUEST['txtAT_1']))."', '".addslashes(trim($_REQUEST['txtNOH_1_1']))."', '".addslashes(trim($_REQUEST['txtMS_1_1']))."', '".addslashes(trim($_REQUEST['txtLH_1_1']))."', '".addslashes(trim($_REQUEST['txtVBDT']))."', '".addslashes(trim($_REQUEST['txtKeel_Distance']))."', '".addslashes(trim($_REQUEST['txtCOBT']))."', '".addslashes(trim($_REQUEST['txtCOBC']))."', '".addslashes(trim($_REQUEST['txtCEF']))."', '".addslashes(trim($_REQUEST['txtDFC']))."', '".addslashes(trim($_REQUEST['txtFWC']))."', '".addslashes(trim($_REQUEST['txtSCAD']))."', '".addslashes(trim($_REQUEST['txtPOE']))."', '".addslashes(trim($_REQUEST['txtNFWR']))."', '".addslashes(trim($_REQUEST['selSHAFT_GEN']))."', '".addslashes(trim($_REQUEST['txtVOES']))."', '".addslashes(trim($_REQUEST['txtDOAS']))."', '".$_SESSION['pictureid']."', '".addslashes(trim($_REQUEST['txtWinid_4']))."', '".addslashes(trim($_REQUEST['txtTropicalid_4']))."', '".addslashes(trim($_REQUEST['txtSumTimid_4']))."', '".addslashes(trim($_REQUEST['txtWinTimid_4']))."', '".addslashes(trim($_REQUEST['txtTropicalTimid_4']))."', '".addslashes(trim($_REQUEST['txtSumid_4']))."', '".addslashes(trim($_REQUEST['txtSumid_2']))."', '".addslashes(trim($_REQUEST['txtSumid_4']))."', '".addslashes(trim($_REQUEST['txtSumid_5']))."', '".addslashes(trim($_REQUEST['txtSumid_6']))."', '".addslashes(trim($_REQUEST['txtSumid_8']))."', '".addslashes(trim($_REQUEST['txtWinid_5']))."', '".addslashes(trim($_REQUEST['txtWinid_6']))."', '".addslashes(trim($_REQUEST['txtWinid_7']))."', '".addslashes(trim($_REQUEST['txtWinid_8']))."', '".addslashes(trim($_REQUEST['txtTropicalid_5']))."', '".addslashes(trim($_REQUEST['txtTropicalid_6']))."', '".addslashes(trim($_REQUEST['txtTropicalid_7']))."', '".addslashes(trim($_REQUEST['txtTropicalid_8']))."', '".addslashes(trim($_REQUEST['txtSumTimid_5']))."', '".addslashes(trim($_REQUEST['txtSumTimid_6']))."', '".addslashes(trim($_REQUEST['txtSumTimid_7']))."', '".addslashes(trim($_REQUEST['txtSumTimid_8']))."', '".addslashes(trim($_REQUEST['txtWinTimid_5']))."', '".addslashes(trim($_REQUEST['txtWinTimid_6']))."', '".addslashes(trim($_REQUEST['txtWinTimid_7']))."', '".addslashes(trim($_REQUEST['txtWinTimid_8']))."', '".addslashes(trim($_REQUEST['txtTropicalTimid_5']))."', '".addslashes(trim($_REQUEST['txtTropicalTimid_6']))."', '".addslashes(trim($_REQUEST['txtTropicalTimid_7']))."', '".addslashes(trim($_REQUEST['txtTropicalTimid_8']))."', '".addslashes(trim($_REQUEST['txtConstantMT']))."', '".addslashes(trim($_REQUEST['txtConstantLT']))."', '".addslashes(trim($_REQUEST['txtSumid_7']))."')";
		
	mysql_query($sql2) or die(mysql_error());
	
	//-------------------2-----------------------------------------
	$sql3 = "delete from vessel_master_2 where VESSEL_IMO_ID=".$id;
	mysql_query($sql3);
	
	
	$DOLSS = date("Y-m-d",strtotime($_REQUEST['txtDOLSS']));
	
	if(($_REQUEST['txtDOLSS']) == ""){
		$DOLSS1 = "1970-01-01";
	}else{
		$DOLSS1 = $DOLSS;
	}
	
	$DOLAS = date("Y-m-d",strtotime($_REQUEST['txtDOLAS']));
	
	if(($_REQUEST['txtDOLAS']) == ""){
		$DOLAS1 = "1970-01-01";
	}else{
		$DOLAS1 = $DOLAS;
	}

	$DOLI = date("Y-m-d",strtotime($_REQUEST['txtDOLI']));
	
	if(($_REQUEST['txtDOLI']) == ""){
		$DOLI1 = "1970-01-01";
	}else{
		$DOLI1 = $DOLI;
	}
	
	$DONI = date("Y-m-d",strtotime($_REQUEST['txtDONI']));
	
	if(($_REQUEST['txtDONI']) == ""){
		$DONI1 = "1970-01-01";
	}else{
		$DONI1 = $DONI;
	}
	
	$Date_Dry = date("Y-m-d",strtotime($_REQUEST['txtDate_Dry']));
	
	if(($_REQUEST['txtDate_Dry']) == ""){
		$Date_Dry1 = "1970-01-01";
	}else{
		$Date_Dry1 = $Date_Dry;
	}
	
	$LAST_AUDIT = date("Y-m-d",strtotime($_REQUEST['txtLAST_AUDIT']));
	
	if(($_REQUEST['txtLAST_AUDIT']) == ""){
		$LAST_AUDIT1 = "1970-01-01";
	}else{
		$LAST_AUDIT1 = $LAST_AUDIT;
	}
	
	$NEXT_AUDIT = date("Y-m-d",strtotime($_REQUEST['txtNEXT_AUDIT']));
	
	if(($_REQUEST['txtNEXT_AUDIT']) == ""){
		$NEXT_AUDIT1 = "1970-01-01";
	}else{
		$NEXT_AUDIT1 = $NEXT_AUDIT;
	}
	
	$ADVISE_DATE = date("Y-m-d",strtotime($_REQUEST['txtADVISE_DATE']));
	
	if(($_REQUEST['txtADVISE_DATE']) == ""){
		$ADVISE_DATE1 = "1970-01-01";
	}else{
		$ADVISE_DATE1 = $ADVISE_DATE;
	}
	
	$DATE_SMC = date("Y-m-d",strtotime($_REQUEST['txtDATE_SMC']));
	
	if(($_REQUEST['txtDATE_SMC']) == ""){
		$DATE_SMC1 = "1970-01-01";
	}else{
		$DATE_SMC1 = $DATE_SMC;
	}
	
	
	$sql4 = "insert into vessel_master_2 (VESSEL_IMO_ID, CLASS_SOC_ID, CLASS_NOTATION, DATE_LAST_1, DATE_LAST_2, CLASS_1, DATE_INS_1, DATE_INS_2, STR, STR_1, DATE_DRYDOCK, PORT_DRYDOCK, GROUND, ISM, STATE_DOC, STATE_SMC, DATE_LAST_AUDIT, DATE_NEXT_AUDIT, STATE_OUTS, DATE_ADVISE, PORT_ADVISE, DETEN, STATE_OUTS_1, ITF, ITF_AGREE, FULL_DETAILS, IMO_R_NO, DATE_SMC) values ('".$id."', '".addslashes(trim($_REQUEST['selCLASS_SOC']))."', '".addslashes(trim($_REQUEST['txtCLASS_NOT']))."', '".$DOLSS1."', '".$DOLAS1."', '".addslashes(trim($_REQUEST['selCLASS_1']))."', '".$DOLI1."', '".$DONI1."', '".addslashes(trim($_REQUEST['selSTR']))."', '".addslashes(trim($_REQUEST['selSTR_1']))."', '".$Date_Dry1."', '".addslashes(trim($_REQUEST['selPOLD']))."', '".addslashes(trim($_REQUEST['txtGROUND']))."', '".addslashes(trim($_REQUEST['selISM']))."', '".addslashes(trim($_REQUEST['txtSTATE_DOC']))."', '".addslashes(trim($_REQUEST['txtSTATE_SMC']))."', '".$LAST_AUDIT1."', '".$NEXT_AUDIT1."', '".addslashes(trim($_REQUEST['txtSTATE_OUTS']))."', '".$ADVISE_DATE1."', '".addslashes(trim($_REQUEST['selADVISE_PORT']))."', '".addslashes(trim($_REQUEST['selDETEN']))."', '".addslashes(trim($_REQUEST['txtSTATE_OUTS_1']))."', '".addslashes(trim($_REQUEST['txtITF']))."', '".addslashes(trim($_REQUEST['txtITF_AGREE']))."', '".addslashes(trim($_REQUEST['txtFULL_DETAILS']))."', '".addslashes(trim($_REQUEST['txtIMO_REGS_NO']))."', '".$DATE_SMC1."')";
	
	mysql_query($sql4) or die(mysql_error());
	$txtCID	=	addslashes(trim($_REQUEST['txtCID']));;
	
	for($j=1; $j<=$txtCID; $j++)
	{
		$selCert	=	addslashes(trim($_REQUEST['selCert_'.$j]));
		$txtIDate = date("Y-m-d",strtotime($_REQUEST['txtIDate_'.$j]));
		if(($_REQUEST['txtIDate_'.$j]) == ""){
			$txtIDate1 = "1970-01-01";
		}else{
			$txtIDate1 = $txtIDate;
		}		
		$txtLAIDate = date("Y-m-d",strtotime($_REQUEST['txtLAIDate_'.$j]));
		if(($_REQUEST['txtLAIDate_'.$j]) == ""){
			$txtLAIDate1 = "1970-01-01";
		}else{
			$txtLAIDate1 = $txtLAIDate;
		}
		$txtEDate = date("Y-m-d",strtotime($_REQUEST['txtEDate_'.$j]));
		if(($_REQUEST['txtEDate_'.$j]) == ""){
			$txtEDate1 = "1970-01-01";
		}else{
			$txtEDate1 = $txtEDate;
		}
		
		
		$filename =$_FILES['txtfile_'.$j]['name'];
		$tmpFile = $_FILES["txtfile_".$j]["tmp_name"];
		move_uploaded_file($_FILES['txtfile_'.$j]['tmp_name'], '../../attachment/'.$filename);
		
		if(!empty($selCert))
		{
			$qsql = "select * from vessel_master_slave where VESSEL_IMO_ID='".$id."' and CERTIFICATE_ID='".$selCert."'";
			$qres = mysql_query($qsql) or die(mysql_error());
			$qrec = mysql_num_rows($qres);
			if($qrec == 0)
			{ 
				$sql5 = "insert into vessel_master_slave (VESSEL_IMO_ID, CERTIFICATE_ID, DATE_ISSUE, DATE_LAST, DATE_EXPIRY, UPLOAD) values ('".$id."', '".$selCert."', '".$txtIDate1."','".$txtLAIDate1."','".$txtEDate1."','".$filename."')";
				
				mysql_query($sql5) or die(mysql_error());
			}
			else
			{
				$qrows = mysql_fetch_assoc($qres);
				
				if(empty($_FILES['txtfile_'.$j]['name']))
				{ 
					$filename_1 = $qrows['UPLOAD'];
				}else{ 
					$filename_1 = $filename;}
			
				$qsql1 = "update vessel_master_slave set DATE_ISSUE='".$txtIDate1."', DATE_LAST='".$txtLAIDate1."', DATE_EXPIRY='".$txtEDate1."', UPLOAD='".$filename_1."' where VESSEL_SLAVE_ID='".$qrows['VESSEL_SLAVE_ID']."'";
				
				mysql_query($qsql1) or die(mysql_error());
			}
		}
	}
	
	
	//---------------------3-------------------------
	$sql6 = "delete from vessel_master_3 where VESSEL_IMO_ID=".$id;
	mysql_query($sql6);
	
	$sql7 = "insert into vessel_master_3 (VESSEL_IMO_ID, NOC, NOM, NOO, NOCR) values ('".$id."', '".addslashes(trim($_REQUEST['txtNOC']))."', '".addslashes(trim($_REQUEST['txtNOM']))."', '".addslashes(trim($_REQUEST['txtNOO']))."', '".addslashes(trim($_REQUEST['txtNOCR']))."')";
	mysql_query($sql7);
	
	//------------------------4------------------------
	$sql8 = "delete from vessel_master_4 where VESSEL_IMO_ID=".$id;
	mysql_query($sql8);
	
	$sql9 = "insert into vessel_master_4 (VESSEL_IMO_ID, NOH, HOLDS_CLEAR, GRAIN, CARRIAGE, TANKTOP, BULKHEAD, SQM, CO2, DET_SYS, LADDER, CALC, HOLD_SIDE, F_BULKHEAD, AFT_BULKHEAD, SHAPED, H1_1, H1_2, H1_3, H2_1, H2_2, H2_3, H3_1, H3_2, H3_3, H4_1, H4_2, H4_3, H5_1, H5_2, H5_3, H6_1, H6_2, H6_3, H7_1, H7_2, H7_3, VENT, NOHA, NOHA_COV, HATCH_SIZE, HATCH_SQM, FAR, OPEN_1, LAST_OPEN, STR_SQM, CHNPH, DOH, POH, MAKE_TYPE, NOCS, BSR, HOOK, HATCH_COAM, HOOK_CARGO, H_LIFT, E_HYDRA, TYPE_CAP, N_WORK, BOARD, MOATS) values ('".$id."', '".addslashes(trim($_REQUEST['txtNOH']))."', '".addslashes(trim($_REQUEST['selHOLDS_CLEAR']))."', '".addslashes(trim($_REQUEST['txtGRAIN']))."', '".addslashes(trim($_REQUEST['txtCARRIAGE']))."', '".addslashes(trim($_REQUEST['selTANKTOP']))."', '".addslashes(trim($_REQUEST['txtBULKHEAD']))."', '".addslashes(trim($_REQUEST['txtSQM']))."', '".addslashes(trim($_REQUEST['selCO2']))."', '".addslashes(trim($_REQUEST['selDET_SYS']))."', '".addslashes(trim($_REQUEST['selLADDER']))."', '".addslashes(trim($_REQUEST['selCALC']))."', '".addslashes(trim($_REQUEST['selHOLD_SIDE']))."', '".addslashes(trim($_REQUEST['selF_BULKHEAD']))."', '".addslashes(trim($_REQUEST['selAFT_BULKHEAD']))."', '".addslashes(trim($_REQUEST['selSHAPED']))."', '".addslashes(trim($_REQUEST['txtHid_1_1']))."', '".addslashes(trim($_REQUEST['txtHid_1_2']))."', '".addslashes(trim($_REQUEST['txtHid_1_3']))."', '".addslashes(trim($_REQUEST['txtHid_2_1']))."', '".addslashes(trim($_REQUEST['txtHid_2_2']))."', '".addslashes(trim($_REQUEST['txtHid_2_3']))."', '".addslashes(trim($_REQUEST['txtHid_3_1']))."', '".addslashes(trim($_REQUEST['txtHid_3_2']))."', '".addslashes(trim($_REQUEST['txtHid_3_3']))."', '".addslashes(trim($_REQUEST['txtHid_4_1']))."', '".addslashes(trim($_REQUEST['txtHid_4_2']))."', '".addslashes(trim($_REQUEST['txtHid_4_3']))."', '".addslashes(trim($_REQUEST['txtHid_5_1']))."', '".addslashes(trim($_REQUEST['txtHid_5_2']))."', '".addslashes(trim($_REQUEST['txtHid_5_3']))."', '".addslashes(trim($_REQUEST['txtHid_6_1']))."', '".addslashes(trim($_REQUEST['txtHid_6_2']))."', '".addslashes(trim($_REQUEST['txtHid_6_3']))."', '".addslashes(trim($_REQUEST['txtHid_7_1']))."', '".addslashes(trim($_REQUEST['txtHid_7_2']))."', '".addslashes(trim($_REQUEST['txtHid_7_3']))."', '".addslashes(trim($_REQUEST['txtVENT']))."', '".addslashes(trim($_REQUEST['txtNOHA']))."', '".addslashes(trim($_REQUEST['txtNOHA_COV']))."', '".addslashes(trim($_REQUEST['txtHATCH_SIZE']))."', '".addslashes(trim($_REQUEST['txtHATCH_SQM']))."', '".addslashes(trim($_REQUEST['txtFAR']))."', '".addslashes(trim($_REQUEST['txtOPEN']))."', '".addslashes(trim($_REQUEST['txtLAST_OPEN']))."', '".addslashes(trim($_REQUEST['txtSTRENGTH_SQM']))."', '".addslashes(trim($_REQUEST['txtCHNPH']))."', '".addslashes(trim($_REQUEST['txtDOH']))."', '".addslashes(trim($_REQUEST['txtPOH']))."', '".addslashes(trim($_REQUEST['txtMAKE_TYPE']))."', '".addslashes(trim($_REQUEST['txtNOCS']))."', '".addslashes(trim($_REQUEST['txtBSR']))."', '".addslashes(trim($_REQUEST['txtHOOK']))."', '".addslashes(trim($_REQUEST['txtHATCH_COAM']))."', '".addslashes(trim($_REQUEST['txtHOOK_CARGO']))."', '".addslashes(trim($_REQUEST['selH_LIFT']))."', '".addslashes(trim($_REQUEST['selE_HYDRA']))."', '".addslashes(trim($_REQUEST['txtTYPE_CAP']))."', '".addslashes(trim($_REQUEST['selN_WORK']))."', '".addslashes(trim($_REQUEST['txtBOARD']))."', '".addslashes(trim($_REQUEST['txtMOATS']))."')";
	mysql_query($sql9) or die($sql9);
	
	//-------------------5---------------------------
	$sql10 = "delete from vessel_master_5 where VESSEL_IMO_ID=".$id;
	mysql_query($sql10);
	
	
	$sql11 = "insert into vessel_master_5 (VESSEL_IMO_ID, LADEN_1, LADEN_2, BALLAST_1, BALLAST_2, BUNKER_G, BUNKER_C, P_WORK, EMAT, MOB) values ('".$id."', '".addslashes(trim($_REQUEST['txtADid_1_1']))."', '".addslashes(trim($_REQUEST['txtADid_1_2']))."', '".addslashes(trim($_REQUEST['txtADid_2_1']))."', '".addslashes(trim($_REQUEST['txtADid_2_2']))."', '".addslashes(trim($_REQUEST['txtBUNKER_G']))."', '".addslashes(trim($_REQUEST['txtBUNKER_C']))."', '".addslashes(trim($_REQUEST['txtP_WORK']))."', '".addslashes(trim($_REQUEST['txtEMAT']))."', '".addslashes(trim($_REQUEST['txtMOB']))."')";
	mysql_query($sql11) or die($sql11);
	
	
	//--------------------------6---------------------------
	$sql12 = "delete from vessel_master_6 where VESSEL_IMO_ID=".$id;
	mysql_query($sql12);
	
	
	$sql13 = "insert into vessel_master_6 (VESSEL_IMO_ID, CALL_SIGN, NOR, COMM_SYS, HAMIV, P_I, PLACED, CARGO, CARGO_1, CARGO_2, INMARSAT_NUMBER,TELEX_NUMBER ,FAX_NUMBER ,EMAIL_ADDRESS ,MMSI_NUMBER) values ('".$id."', '".addslashes(trim($_REQUEST['txtCALL_SIGN']))."', '".addslashes(trim($_REQUEST['txtNOR']))."', '".addslashes(trim($_REQUEST['txtCOMM_SYS']))."', '".addslashes(trim($_REQUEST['txtHAMIV']))."', '".addslashes(trim($_REQUEST['txtPI']))."', '".addslashes(trim($_REQUEST['txtPLACED']))."', '".addslashes(trim($_REQUEST['txtCARGO']))."', '".addslashes(trim($_REQUEST['selCARGO_1']))."', '".addslashes(trim($_REQUEST['txtCARGO_2']))."', '".addslashes(trim($_REQUEST['txtINMARSAT_Number']))."', '".addslashes(trim($_REQUEST['txtTelex_Number']))."', '".addslashes(trim($_REQUEST['txtFax_Number']))."', '".addslashes(trim($_REQUEST['txtEmail_Address']))."', '".addslashes(trim($_REQUEST['txtMMSI_No']))."')";
	mysql_query($sql13) or die($sql13);
	
	//-------------------7---------------------------------
	$sql14 = "delete from vessel_master_7 where VESSEL_IMO_ID=".$id;
	mysql_query($sql14);
	
	$sql15 = "insert into vessel_master_7 (VESSEL_IMO_ID, EMPTY, THW, GEAR, FEU, COVERS, PER_TEU, PER_FEU, SPREAD_BOARD, REEFER_PLUGS, TWEENS, NOHH, TOH, WEATHER_DECK, TWEEN_DECK, FLUSH, TANKTOP, SQM_TD, SQM_WD, SQM_HC, B_FITTED, CO2_FITT, REMARK) values ('".$id."', '".addslashes(trim($_REQUEST['txtEMPTY']))."', '".addslashes(trim($_REQUEST['txtTHW']))."', '".addslashes(trim($_REQUEST['txtGEAR']))."', '".addslashes(trim($_REQUEST['selFEU']))."', '".addslashes(trim($_REQUEST['selCOVERS']))."', '".addslashes(trim($_REQUEST['txtPER_TEU']))."', '".addslashes(trim($_REQUEST['txtPER_FEU']))."', '".addslashes(trim($_REQUEST['txtSPREAD_BOARD']))."', '".addslashes(trim($_REQUEST['txtREEFER_PLUGS']))."', '".addslashes(trim($_REQUEST['selTWEENS']))."', '".addslashes(trim($_REQUEST['txtNOHH']))."', '".addslashes(trim($_REQUEST['txtTOH']))."', '".addslashes(trim($_REQUEST['txtWEATHERDECK']))."', '".addslashes(trim($_REQUEST['txtTWEENDECK']))."', '".addslashes(trim($_REQUEST['selFLUSH']))."', '".addslashes(trim($_REQUEST['txtTANKTOP']))."', '".addslashes(trim($_REQUEST['txtSQM_TD']))."', '".addslashes(trim($_REQUEST['txtSQM_WD']))."', '".addslashes(trim($_REQUEST['txtSQM_HC']))."', '".addslashes(trim($_REQUEST['selCO2_FITT']))."', '".addslashes(trim($_REQUEST['selB_FITTED']))."', '".addslashes(trim($_REQUEST['txtREMARK']))."')";
	mysql_query($sql15) or die($sql15);
	
	//---------------------------8------------------------------
	
	
	
	mysql_query("commit"); 
	return $msg;
	
}


function getCargoNameListForMultiple($type,$ids='')
{
	$this->funConnect();
	$id_arr = explode(",",$ids);
	$query = mysql_query("select * from cargo_master where MATERIAL_TYPEID=".$type." order by MATERIAL_CODE_DESC ");
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['MATERIALID'];
		 $value= $rows['MATERIAL_CODE_DESC'];
		 echo '<option value='.$key;
		 if(in_array($key,$id_arr)){ echo " selected";}
		 echo '>'.$value.'</option>';
		}
}


function getMaterialTypeForMultiple($ids)
{
	$this->funConnect();
	$id_arr = explode(",",$ids);
	$query = mysql_query("select MATERIAL_TYPE, MATERIAL_CODE, MATERIAL_CODE_DESC from cargo_master where STATUS=1 order by MATERIAL_CODE_DESC ");
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['MATERIALID'];
		 $value= $rows['MATERIAL_CODE_DESC'];
		 echo '<option value='.$key;
		 if(in_array($key,$id_arr)){ echo " selected";}
		 echo '>'.$value.'</option>';
		}
}


function getCargoIDBasedOnMaterialCode($ids)
{
	$material = $ids;
	$mat_arr = explode(',',$material);
	$array_code = array();
	for($i=0;$i<count($mat_arr);$i++)
	{
		if($mat_arr[$i]!="")
		{
			$mat_arr1 = explode('@@@',$mat_arr[$i]);
			$array_code[$i] = $mat_arr1[1];
		}
	}
	$arr_code = implode(',',$array_code);
	return $arr_code;
}


function getMaterialDescBasedOnMaterialCode($id)
{
	$this->funConnect();
	$sql = "select MATERIAL_CODE_DESC from cargo_master where MATERIAL_CODE in (".$id.") ";
	$res = mysql_query($sql);
	$material_name = "";
	while($rows = mysql_fetch_assoc($res))
	{
		if($material_name!="")
		{
			$material_name = $material_name.", ";
		}
	$material_name = $material_name."".$rows['MATERIAL_CODE_DESC'];
	}
	return $material_name;
}


function getCargoNameListForMultipleNamemultiple($id)
{
	$this->funConnect();
	$sql = "select MATERIAL_TYPE from cargo_master where MATERIALID in (".$id.") ";
	$res = mysql_query($sql);
	$material_name = "";
	while($rows = mysql_fetch_assoc($res))
	{
		if($material_name!="")
		{
			$material_name = $material_name.",  ";
		}
	$material_name = $material_name."".$rows['MATERIAL_TYPE'];
	}
	return $material_name;
}


function getCargoNameListForMultipleName($id)
{
	$this->funConnect();
	$sql 	= "select MATERIAL_CODE_DESC ,MATERIAL_CODE from cargo_master where MATERIALID='".$id."'  order by MATERIAL_CODE_DESC ";
	$res 	= mysql_query($sql);
	$rows 	= mysql_fetch_assoc($res);
       	
	return $rows['MATERIAL_CODE_DESC']." (".$rows['MATERIAL_CODE'].")";
}


function getCompareTableData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from freight_cost_estimate_compare where COMID='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getCompareReletTableData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from cargo_relet_estimate_compare where COMID='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}


function displayDataMgmtList($value)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="data_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="13%">Vessel Name</th>';
	echo '<th align="left" valign="middle" width="13%">CP Date</th>';
	echo '<th align="left" valign="middle" width="13%">Last Updated Date</th>';
	echo '<th align="left" valign="middle" width="20%">Remarks</th>';
	echo '<th align="left" valign="middle" width="10%">Added By</th>';
	echo '<th align="left" valign="middle" width="15%">Attached Files</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from post_fix_data_management WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' order by UPDATE_ON_DATE desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{$color="";
				if($value==1)
				{
					if($rows['SOH_ALERT_STATUS']==1)
					{
						$color= 'style="color:red;"';
					}
					
				}
				if($value==2)
				{
					if($rows['JALDHI_ALERT_STATUS']==1)
					{
						$color= 'style="color:red;"';
					}
				}
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text" '.$color.'>'.$i.'.</td>';				
				echo '<td align="left" valign="middle" class="input-text" '.$color.'>'.$rows['VASSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text" '.$color.'>'.date('d-m-Y',strtotime($rows['CP_DATE'])).'</td>';
				echo '<td align="left" valign="middle" class="input-text" '.$color.'>'.date('d-m-Y',strtotime($rows['UPDATE_ON_DATE'])).'</td>';				
				echo '<td align="left" valign="middle" class="input-text" '.$color.'>'.addslashes($rows['REMARKS']).'</td>';	 
				echo '<td align="left" valign="middle" class="input-text" '.$color.'>'.$this->getUserDetailBaseOnId($rows['UPLOAD_BY'],'CONTACT_PERSON').'</td>';		
				echo '<td align="left" valign="middle" class="input-text">';
				$upload = explode(",",$rows['ATTACHMENTS']);
				$name = explode(",",$rows['ATTACHMENTS_NAME']);
				for($j=0;$j<count($name);$j++)
				{
					if(trim($name[$j]) != "")
					{
						echo '<a href="../../attachment/'.$upload[$j].'" target="_blank" title="Upload" style="text-decoration:underline;" >'.$name[$j].'</a>&nbsp;<br/>';
					}
				}
				echo '</td>';
				
				if($value==1)
				{
				    echo '<td align="center" valign="middle" class="input-text"><a href="updatejaldhidatamgmt.php?id='.$rows['DATAMGMTID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a href="javascript:void(0);" title="Delete Details" onclick="return getDelete('.$rows['DATAMGMTID'].');" style="color:red;"><i class="fa fa-times"></i></a></td>';	
				}
				else
				{
					echo '<td align="center" valign="middle" class="input-text"><a href="viewjaldhidatamgmt.php?id='.$rows['DATAMGMTID'].'" title="View Details" ><i class="fa fa-file"></i></a><br/><a href="sohdatamgmt_list.php?val='.$rows['DATAMGMTID'].'" title="View Details" >Change&nbsp;Color</a></td>';	
				}
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function insertDtatMGMTDetails()
{
	$connect = $this->funConnect();
	
	$txtVesselName 			= addslashes(trim($_REQUEST['txtVesselName']));
	$txtCPDate	 		    = $_REQUEST['txtCPDate'];
	$txtRemarks	 		    = addslashes(trim($_REQUEST['txtRemarks']));
	
	$upload = $this->getUpload($_FILES["mul_file"]);
	$name = $this->getUploadName($_FILES["mul_file"]);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "INSERT INTO post_fix_data_management (VASSEL_NAME, ADD_ON_DATE, UPDATE_ON_DATE, CP_DATE, UPLOAD_BY, REMARKS, ATTACHMENTS, ATTACHMENTS_NAME, JALDHI_ALERT_STATUS, MODULEID, MCOMPANYID, SOH_ALERT_STATUS) VALUES ('".$txtVesselName."', NOW(), NOW(), '".date('Y-m-d',strtotime($txtCPDate))."', '".$_SESSION['uid']."', '".$txtRemarks."', '".addslashes(trim(implode(',',$upload)))."', '".addslashes(trim(implode(',',$name)))."', '1', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 0)";

	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql1 = "select max(DATAMGMTID) as max from post_fix_data_management";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	$sql2 = "INSERT INTO post_fix_data_management_slave (DATAMGMTID, ADD_ON_DATE, LOGINID, REMARKS, BY_USER) VALUES ('".$rows1['max']."', NOW(), '".$_SESSION['uid']."', '".$txtRemarks."', '1')";
	mysql_query($sql2) or die($sql2);
	mysql_query("commit");
	
	return $msg;
}


function getDataMGMTData($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM post_fix_data_management where DATAMGMTID=".$id;
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['VASSEL_NAME'];
		$this->var_2 = $rows['ADD_ON_DATE'];
		$this->var_3 = $rows['UPDATE_ON_DATE'];
		$this->var_4 = $rows['CP_DATE'];
		$this->var_5 = $rows['UPLOAD_BY'];
		$this->var_6 = $rows['REMARKS'];
		$this->var_7 = $rows['ATTACHMENTS'];
		$this->var_8 = $rows['ATTACHMENTS_NAME'];
		$this->var_9 = $rows['JALDHI_ALERT_STATUS'];
		$this->var_10 = $rows['SOH_ALERT_STATUS'];
	}
}

function deleteDataMgmtRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['delId']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1  = "select ATTACHMENTS from post_fix_data_management where DATAMGMTID='".$id."'";
	$res1  = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	$name  = explode(",",$rows1['ATTACHMENTS']);
	
	for($i=0;$i<sizeof($name);$i++)
	{
		unlink('../../attachment/'.$name[$i]);
	}
		
	$msg = 2;
	$sql = "DELETE FROM post_fix_data_management WHERE DATAMGMTID='".$id."'";
	
	mysql_query($sql);
	mysql_query("commit"); 
	
	$sql2 = "DELETE FROM post_fix_data_management_slave WHERE DATAMGMTID='".$id."'";
	
	mysql_query($sql2);
	mysql_query("commit"); 
	
	return $msg;
}


function updateDtatMGMTDetails($id)
{
	$connect = $this->funConnect();
	
	$txtVesselName 			= addslashes(trim($_REQUEST['txtVesselName']));
	$txtCPDate	 		    = $_REQUEST['txtCPDate'];
	$txtRemarks	 		    = addslashes(trim($_REQUEST['txtRemarks']));
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update post_fix_data_management set VASSEL_NAME='".$txtVesselName."', UPDATE_ON_DATE=NOW(), CP_DATE='".date('Y-m-d',strtotime($txtCPDate))."', REMARKS= '".$txtRemarks."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', JALDHI_ALERT_STATUS=1, SOH_ALERT_STATUS=0 where DATAMGMTID='".$id."'";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql2 = "INSERT INTO post_fix_data_management_slave (DATAMGMTID, ADD_ON_DATE, LOGINID, REMARKS, BY_USER) VALUES ('".$id."', NOW(), '".$_SESSION['uid']."', '".$txtRemarks."', '1')";
	mysql_query($sql2) or die($sql2);
	mysql_query("commit");
	
	return $msg;
}


function InsertRemarksDtatMGMT($id)
{
	$connect = $this->funConnect();
	
	$txtRemarks	 		    = addslashes(trim($_REQUEST['txtRemarks']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$sql = "update post_fix_data_management set JALDHI_ALERT_STATUS=0, SOH_ALERT_STATUS=1 where DATAMGMTID='".$id."'";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	//insert query here.............
	$sql2 = "INSERT INTO post_fix_data_management_slave (DATAMGMTID, ADD_ON_DATE, LOGINID, REMARKS, BY_USER) VALUES ('".$id."', NOW(), '".$_SESSION['uid']."', '".$txtRemarks."', '2')";
	mysql_query($sql2) or die($sql2);
	mysql_query("commit");
	return $msg;
}


function getYearList($year)
{
	$this->funConnect();
	$arr_year = array();
	$i = 0;
	$query = mysql_query("select distinct(Year(ADD_ON_DATE)) as year from freight_cost_estimete_master group by year(ADD_ON_DATE) desc ");
	while($rows = mysql_fetch_assoc($query))
	{
		$arr_year[] = $rows['year'];
	    $key= $rows['year'];
	    $value= $rows['year'];
	    echo '<option value='.$key;
	    if($year==$key){ echo " selected";$i = 1;}
	    echo '>'.$value.'</option>';
	}
	if(!in_array(date('Y',time()), $arr_year))
	{
		echo '<option value='.date('Y',time());
	    if($i==0){ echo " selected";}
	    echo '>'.date('Y',time()).'</option>';
	}
}

function getYearListTC($year)
{
	$this->funConnect();
	$arr_year = array();
	$i = 0;
	$query = mysql_query("select distinct(Year(UPDATE_ON_DATE)) as year from chartering_estimate_tc_master group by year(UPDATE_ON_DATE) desc ");
	while($rows = mysql_fetch_assoc($query))
	{
		$arr_year[] = $rows['year'];
	    $key= $rows['year'];
	    $value= $rows['year'];
	    echo '<option value='.$key;
	    if($year==$key){ echo " selected";$i = 1;}
	    echo '>'.$value.'</option>';
	}
	if(!in_array(date('Y',time()), $arr_year))
	{
		echo '<option value='.date('Y',time());
	    if($i==0){ echo " selected";}
	    echo '>'.date('Y',time()).'</option>';
	}
}

function getCargoreletYearList($year)
{
	$this->funConnect();
	$query = mysql_query("select distinct(Year(ADDONDATE)) as year from cargo_relet_estimate_masster group by year(ADDONDATE) desc ");
	while($rows = mysql_fetch_assoc($query))
	{
	    $key= $rows['year'];
	    $value= $rows['year'];
	    echo '<option value='.$key;
	    if($year==$key){ echo " selected";}
	    echo '>'.$value.'</option>';
	}
}

function updationSOFRecords()
{
	$connect = $this->funConnect();
	//echo'<pre>';print_r($_REQUEST); die();
	
	$comid              	= $_REQUEST['comid'];
	$tabid		          	= $_REQUEST['txttabid'][0];
	$port		          	= $_REQUEST['txtport_'.$tabid];
	$portid		          	= $_REQUEST['txtportid_'.$tabid];
	$txtRandomID          	= $_REQUEST['txtRandomID_'.$tabid];
	$submitid		        = addslashes(trim($_REQUEST['txtsubmitid_'.$tabid]));
	
	$terminalid	            = addslashes(trim($_REQUEST['selTerminal_'.$tabid]));	
	
	if($port == 'LP')
	{$loaded_qty	            = addslashes(trim($_REQUEST['txtTTLQty_'.$tabid]));}
	else{ $loaded_qty	            = 0;}
	
	if($port == 'DP')
	{$disch_qty	            = addslashes(trim($_REQUEST['txtTTLQty_'.$tabid]));
	}else{$disch_qty	            = 0;}
	
	$txtNarration           = addslashes(trim($_REQUEST['txtNarration_'.$tabid]));
	$txtTurnTime            = addslashes(trim($_REQUEST['txtTurnTime_'.$tabid]));
	
	$txtNOM	             	= addslashes(trim($_REQUEST['txtNOM_'.$tabid]));
	$txtNOR	             	= addslashes(trim($_REQUEST['txtNOR_'.$tabid]));
	$txtNOS	             	= addslashes(trim($_REQUEST['txtNOS_'.$tabid]));
	$txtLP	             	= addslashes(trim($_REQUEST['txtLP_'.$tabid]));
	$txtDP	             	= addslashes(trim($_REQUEST['txtDP_'.$tabid]));
	$txtCargo_Desc	        = addslashes(trim($_REQUEST['txtCargo_Desc_'.$tabid]));
	$txtCargo_Qty	        = addslashes(trim($_REQUEST['txtCargo_Qty_'.$tabid]));
	$txtTerminal	        = addslashes(trim($_REQUEST['txtTerminal_'.$tabid]));
	$txtVAPS	        	= addslashes(trim($_REQUEST['txtVAPS_'.$tabid]));
	$txtVAPS_1	        	= addslashes(trim($_REQUEST['txtVAPS_1_'.$tabid]));
	$txtVA		        	= addslashes(trim($_REQUEST['txtVA_'.$tabid]));
	$txtVA_1		        = addslashes(trim($_REQUEST['txtVA_1_'.$tabid]));
	$txtNT		        	= addslashes(trim($_REQUEST['txtNT_'.$tabid]));
	$txtNT_1		        = addslashes(trim($_REQUEST['txtNT_1_'.$tabid]));
	$txtNR		        	= addslashes(trim($_REQUEST['txtNR_'.$tabid]));
	$txtNR_1		        = addslashes(trim($_REQUEST['txtNR_1_'.$tabid]));
	$txtNA		        	= addslashes(trim($_REQUEST['txtNA_'.$tabid]));
	$txtNA_1		        = addslashes(trim($_REQUEST['txtNA_1_'.$tabid]));
	$txtAA		        	= addslashes(trim($_REQUEST['txtAA_'.$tabid]));
	$txtAA_1		        = addslashes(trim($_REQUEST['txtAA_1_'.$tabid]));
	$txtPBFB		        = addslashes(trim($_REQUEST['txtPBFB_'.$tabid]));
	$txtPBFB_1		        = addslashes(trim($_REQUEST['txtPBFB_1_'.$tabid]));
	$txtVAF		       	 	= addslashes(trim($_REQUEST['txtVAF_'.$tabid]));
	$txtFPG		       	 	= addslashes(trim($_REQUEST['txtFPG_'.$tabid]));
	$txtCC		       	 	= addslashes(trim($_REQUEST['txtCC_'.$tabid]));
	$txtIDSC		       	= addslashes(trim($_REQUEST['txtIDSC_'.$tabid]));
	$txtIDSC1		       	= addslashes(trim($_REQUEST['txtIDSC1_'.$tabid]));
	$txtHIC		       		= addslashes(trim($_REQUEST['txtHIC_'.$tabid]));
	$txtHIC1		       	= addslashes(trim($_REQUEST['txtHIC1_'.$tabid]));
	$txtHP		       		= addslashes(trim($_REQUEST['txtHP_'.$tabid]));
	$txtOHSC		       	= addslashes(trim($_REQUEST['txtOHSC_'.$tabid]));
	$txtOHSC1		       	= addslashes(trim($_REQUEST['txtOHSC1_'.$tabid]));
	$txtLC		       		= addslashes(trim($_REQUEST['txtLC_'.$tabid]));
	$txtLC1		       		= addslashes(trim($_REQUEST['txtLC1_'.$tabid]));
	$txtCLAPDS		       	= addslashes(trim($_REQUEST['txtCLAPDS_'.$tabid]));
	$txtDC		       		= addslashes(trim($_REQUEST['txtDC1_'.$tabid]));
	$txtVS		       		= addslashes(trim($_REQUEST['txtVS_'.$tabid]));
	$txtFDSS		       	= addslashes(trim($_REQUEST['txtFDSS_'.$tabid]));
	$txtFDSC		       	= addslashes(trim($_REQUEST['txtFDSC_'.$tabid]));
	
	$txtRemarks1		    = addslashes(trim($_REQUEST['txtRemarks1_'.$tabid]));
	$txtRemarks2		    = addslashes(trim($_REQUEST['txtRemarks2_'.$tabid]));
	$txtRemarks3		    = addslashes(trim($_REQUEST['txtRemarks3_'.$tabid]));
	$txtRemarks4		    = addslashes(trim($_REQUEST['txtRemarks4_'.$tabid]));
	$txtRemarks5		    = addslashes(trim($_REQUEST['txtRemarks5_'.$tabid]));
	$txtRemarks6		    = addslashes(trim($_REQUEST['txtRemarks6_'.$tabid]));
	$txtRemarks7		    = addslashes(trim($_REQUEST['txtRemarks7_'.$tabid]));
	$txtRemarks8		    = addslashes(trim($_REQUEST['txtRemarks8_'.$tabid]));
	$txtRemarks9		    = addslashes(trim($_REQUEST['txtRemarks9_'.$tabid]));
	$txtRemarks10		    = addslashes(trim($_REQUEST['txtRemarks10_'.$tabid]));
	$txtSat				    = addslashes(trim($_REQUEST['txtSat_'.$tabid]));
	$txtSun				    = addslashes(trim($_REQUEST['txtSun_'.$tabid]));
	$txtHol				    = addslashes(trim($_REQUEST['txtHol_'.$tabid]));
	$txtRRemarks			= addslashes(trim($_REQUEST['txtRRemarks_'.$tabid]));
	$txtCRemarks			= addslashes(trim($_REQUEST['txtCRemarks_'.$tabid]));
	$txtMRemarks			= addslashes(trim($_REQUEST['txtMRemarks_'.$tabid]));
	
	foreach($_FILES["mul_file"]['name'] as $key=>$value)
	{
		$filename =$_FILES['mul_file']['name'][$key];
		$tmpFile = $_FILES["mul_file"]["tmp_name"];
		$name[$key] = $filename;
		move_uploaded_file($_FILES['mul_file']['tmp_name'][$key], '../../attachment/'.$filename);
	} 
	
	$filename = implode(",",$name); 
	
	$txtCID     			= $_REQUEST['txtCID_'.$tabid];
	$txtTID     			= $_REQUEST['txtTID_'.$tabid];
	$txtSID     			= $_REQUEST['txtSID_'.$tabid];
	
	$bl_date	            = date("Y-m-d",strtotime($_REQUEST['txtBLDate_'.$tabid.'_1']));
	$bl_qty		            = $_REQUEST['txtTTLBLQty_'.$tabid];
	
	$arr = array("0","HATCH OPENING AND CLOSING","GRAB FIXING","HATCH WISE COMMENCEMENT AND COMPLETION OF CARGO WORK","PORT WORKING / RECESS HOURS","CRANE DELAYS - DELAYS/DETENTION/STOPPAGE OF WORK DUE TO CRANE /GRAB BREAKDOWN","DELAYS/DETENTION/STOPPAGE OF WORK ON SHIPS ACCOUNT (OTHER THAN GEAR)","DELAYS/DETENTION/STOPPAGE OF WORK ON SHORE ACCOUNT","BARGE TIMINGS - CARGO BARGE ARRIVAL / DEPARTURE TIMINGS","RAIN AND BAD WEATHER DELAYS (PRE BERTHING)","RAIN AND BAD WEATHER DELAYS (AT BERTH)","1");

	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$query = "select * from sof_master where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$txtRandomID."' ";
	$qres = mysql_query($query);
	$qrec = mysql_num_rows($qres);
	
	if($qrec == 0)
	{ 
		$query1 = "select * from sof_master where COMID='".$comid."' and LOGIN='AGENT' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$txtRandomID."' ";
		$qres1 = mysql_query($query1);
		$qrows1 = mysql_fetch_assoc($qres1);
		
		$txtCRMFILE2=$_REQUEST["txtCRMFILE2"];
		$filename = implode(",",$name);
	
		if($txtCRMFILE2 != '' && $filename != ''){ $filename = $txtCRMFILE2.','.$filename;}
	    else if($txtCRMFILE2 == '' && $filename != ''){ $filename = $filename;}
	    else if($txtCRMFILE2 != '' && $filename == ''){ $filename = $txtCRMFILE2;}
		
		//$filename_2 = substr($filename_1,0,2); 
		//if(trim($filename_2) == ',')
		//{$filename_1 = substr($filename_1,2);}
		
		$sql = "insert into sof_master (COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, BL_DATE, LOADED_QTY, DISCH_QTY, BL_QTY_LOADED, SUBMITID, NAME_OF_MASTER, NAME_OF_SHIPPER, NAME_OF_STEVEDORES, LOAD_PORT, DISCHARGE_PORT, CARGO_DESC, CARGO_QTY, TERMINAL, VAPS, VA, NT, NR, NA, AA, PBFB, VAF, FPG, CC, IDSC, IDSC_1, HIC, HIC_1, HP, OHSC, OHSC_1, LC, LC1, CLAPDS, DC, VS, REMARKS_1, REMARKS_2, REMARKS_3, REMARKS_4, REMARKS_5, REMARKS_6, REMARKS_7, REMARKS_8, REMARKS_9, REMARKS_10, SATURDAYS, SUNDAYS, HOLIDAYS, SHIPPER_REMARKS, CHARTERER_REMARKS, MASTER_REMARKS, UPLOAD, FDSS, FDSC, VAPS_1, VA_1, NT_1, NR_1, NA_1, AA_1, PBFB_1, RANDOMID) values ('".$comid."', 'INTERNAL_USER', '".$_SESSION['uid']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$port."', '".$this->getCheckNullValue($portid)."', '".$bl_date."', '".$this->getCheckNullValue($loaded_qty)."', '".$disch_qty."', '".$bl_qty."', '".$submitid."', '".$txtNOM."', '".$txtNOR."', '".$txtNOS."', '".$txtLP."', '".$txtDP."', '".$txtCargo_Desc."', '".$txtCargo_Qty."', '".$txtTerminal."', '".$txtVAPS."', '".$txtVA."', '".$txtNT."', '".$txtNR."', '".$txtNA."', '".$txtAA."', '".$txtPBFB."', '".$txtVAF."', '".$txtFPG."', '".$txtCC."', '".$txtIDSC."', '".$txtIDSC1."', '".$txtHIC."', '".$txtHIC1."', '".$txtHP."', '".$txtOHSC."', '".$txtOHSC1."', '".$txtLC."', '".$txtLC1."', '".$txtCLAPDS."', '".$txtDC."', '".$txtVS."', '".$txtRemarks1."', '".$txtRemarks2."', '".$txtRemarks3."', '".$txtRemarks4."', '".$txtRemarks5."', '".$txtRemarks6."', '".$txtRemarks7."', '".$txtRemarks8."', '".$txtRemarks9."', '".$txtRemarks10."', '".$txtSat."', '".$txtSun."', '".$txtHol."', '".$txtRRemarks."', '".$txtCRemarks."', '".$txtMRemarks."', '".$filename."', '".$txtFDSS."', '".$txtFDSC."', '".$this->getCheckNullValue($txtVAPS_1)."', '".$txtVA_1."', '".$txtNT_1."', '".$txtNR_1."', '".$txtNA_1."', '".$txtAA_1."', '".$txtPBFB_1."', '".$txtRandomID."')";
		mysql_query($sql,$connect);
		mysql_query("commit");
		
		$mysql = "select max(SOFID) as max from sof_master";
		$myres = mysql_query($mysql);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
		
		for($i=1; $i<=$txtCID; $i++)
		{
			if($_REQUEST['txtAV_Name_'.$tabid.'_'.$i] != "" && $_REQUEST['txtAV_Value_'.$tabid.'_'.$i] != "")
			{
				$sql3 = "insert into sof_slave_3 (SOFID, ENTITY_NAME, ENTITY_VALUE) values ('".$maxid."', '".addslashes(trim($_REQUEST['txtAV_Name_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtAV_Value_'.$tabid.'_'.$i]))."')";
				mysql_query($sql3,$connect);
				mysql_query("commit");
			}
		}
		
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtBLDate_'.$tabid.'_'.$i] != "")
			{
				$sql2 = "insert into sof_slave_1 (SOFID, BL_DATE, BL_GROSS_QTY, BL_QTY, CARGO) values ('".$maxid."', '".date("Y-m-d",strtotime($_REQUEST['txtBLDate_'.$tabid.'_'.$i]))."', '".$this->getCheckNullValue($_REQUEST['txtQty_'.$tabid.'_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtBLQty_'.$tabid.'_'.$i])."', '".addslashes($_REQUEST['txtCargo_'.$tabid.'_'.$i])."')";
				
				mysql_query($sql2,$connect);
				mysql_query("commit");
			}
		}
		
		
		for($j=1; $j<12; $j++)
		{
			$txtTBID     			= $_REQUEST['txtTBID'.$j.'_'.$tabid];
			$txtCRM     			= explode(",",$_REQUEST['txtCRM'.$j.'_'.$tabid]);
			
			for($i=0 ; $i<$txtTBID ;$i++)
			{
				if($_REQUEST['txtROW_ID'.$j.'_'.$tabid.'_'.$txtCRM[$i]] != 0)
				{
					if($_REQUEST['txtActivity'.$j.'_'.$tabid.'_'.$txtCRM[$i]] != "")
					{
						$sql1 = "insert into sof_slave (SOFID, ACTIVITYID, START_DATETIME, FINISH_DATETIME, DURATION, LAY_TIME_COUNT, PORT_TIME_COUNT, NOTES, GROUP_NAME) values ('".$maxid."','".addslashes(trim($_REQUEST['txtActivity'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."','".date("Y-m-d H:i",strtotime($_REQUEST['txtDStart'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."','".date("Y-m-d H:i",strtotime($_REQUEST['txtDEnd'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."', '".$_REQUEST['txtDiff'.$j.'_'.$tabid.'_'.$txtCRM[$i]]."','0','0','".addslashes($_REQUEST['txtNotes'.$j.'_'.$tabid.'_'.$txtCRM[$i]])."', '".$arr[$j]."')";
						mysql_query($sql1,$connect);
						mysql_query("commit");
					}
				}
			}
		}
		
		for($i=1 ; $i<=$txtSID ;$i++)
		{
			$sql2 = "insert into sof_slave_2(SOFID, ACTIVITYID, ARRIVAL_COND, DEPARTURE_COND) values ('".$maxid."', '".addslashes(trim($_REQUEST['txtMI_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtAC_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtDC_'.$tabid.'_'.$i]))."')";
			mysql_query($sql2,$connect);
			mysql_query("commit");
		}
	}
	else
	{
		$qrows = mysql_fetch_assoc($qres);
		
		foreach($_FILES["mul_file"]['name'] as $key=>$value)
		{
			$filename =$_FILES['mul_file']['name'][$key];
			$tmpFile = $_FILES["mul_file"]["tmp_name"];
			$name[$key] = $filename;
			move_uploaded_file($_FILES['mul_file']['tmp_name'][$key], '../../attachment/'.$filename);
		}
		
		$txtCRMFILE2=$_REQUEST["txtCRMFILE2"];
		$filename = implode(",",$name);
	
		if($txtCRMFILE2 != '' && $filename != ''){ $filename = $txtCRMFILE2.','.$filename;}
	    else if($txtCRMFILE2 == '' && $filename != ''){ $filename = $filename;}
	    else if($txtCRMFILE2 != '' && $filename == ''){ $filename = $txtCRMFILE2;}
		
		$sql = "update sof_master set BL_DATE='".$bl_date."', LOADED_QTY='".$this->getCheckNullValue($loaded_qty)."', DISCH_QTY='".$this->getCheckNullValue($disch_qty)."', BL_QTY_LOADED='".$this->getCheckNullValue($bl_qty)."', SUBMITID='".$this->getCheckNullValue($submitid)."', NAME_OF_MASTER='".$txtNOM."', NAME_OF_SHIPPER='".$txtNOR."', NAME_OF_STEVEDORES='".$txtNOS."', LOAD_PORT='".$txtLP."', DISCHARGE_PORT='".$txtDP."', CARGO_DESC='".$txtCargo_Desc."', CARGO_QTY='".$txtCargo_Qty."', TERMINAL='".$txtTerminal."', VAPS='".$txtVAPS."', VA='".$txtVA."', NT='".$txtNT."', NR='".$txtNR."', NA='".$txtNA."', AA='".$txtAA."', PBFB='".$txtPBFB."', VAF='".$txtVAF."', FPG='".$txtFPG."', CC='".$txtCC."', IDSC='".$txtIDSC."', IDSC_1='".$txtIDSC1."', HIC='".$txtHIC."', HIC_1='".$txtHIC1."', HP='".$txtHP."', OHSC='".$txtOHSC."', OHSC_1='".$txtOHSC1."', LC='".$txtLC."', LC1='".$txtLC1."', CLAPDS='".$txtCLAPDS."', DC='".$txtDC."', VS='".$txtVS."', REMARKS_1='".$txtRemarks1."', REMARKS_2='".$txtRemarks2."', REMARKS_3='".$txtRemarks3."', REMARKS_4='".$txtRemarks4."', REMARKS_5='".$txtRemarks5."', REMARKS_6='".$txtRemarks6."', REMARKS_7='".$txtRemarks7."', REMARKS_8='".$txtRemarks8."', REMARKS_9='".$txtRemarks9."', REMARKS_10='".$txtRemarks10."', SATURDAYS='".$txtSat."', SUNDAYS='".$txtSun."', HOLIDAYS='".$txtHol."', SHIPPER_REMARKS='".$txtRRemarks."', CHARTERER_REMARKS='".$txtCRemarks."', MASTER_REMARKS='".$txtMRemarks."', UPLOAD='".$filename."', FDSS='".$txtFDSS."', FDSC='".$txtFDSC."', VAPS_1='".$this->getCheckNullValue($txtVAPS_1)."', VA_1='".$txtVA_1."', NT_1='".$txtNT_1."', NR_1='".$txtNR_1."', NA_1='".$txtNA_1."', AA_1='".$txtAA_1."', PBFB_1='".$txtPBFB_1."' where SOFID='".$qrows['SOFID']."'";
		mysql_query($sql,$connect);
		mysql_query("commit");
		
		$delquery = "delete from sof_slave where SOFID='".$qrows['SOFID']."'";
		mysql_query($delquery);
		mysql_query("commit");
		
		$delquery_1 = "delete from sof_slave_1 where SOFID='".$qrows['SOFID']."'";
		mysql_query($delquery_1);
		mysql_query("commit");
		
		$delquery_2 = "delete from sof_slave_2 where SOFID='".$qrows['SOFID']."'";
		mysql_query($delquery_2);
		mysql_query("commit");
		
		$delquery_3 = "delete from sof_slave_3 where SOFID='".$qrows['SOFID']."'";
		mysql_query($delquery_3);
		mysql_query("commit");
		
		for($i=1; $i<=$txtCID; $i++)
		{
			if($_REQUEST['txtAV_Name_'.$tabid.'_'.$i] != "" && $_REQUEST['txtAV_Value_'.$tabid.'_'.$i] != "")
			{
				$sql3 = "insert into sof_slave_3 (SOFID, ENTITY_NAME, ENTITY_VALUE) values ('".$qrows['SOFID']."', '".addslashes(trim($_REQUEST['txtAV_Name_'.$tabid.'_'.$i]))."', '".addslashes(trim($_REQUEST['txtAV_Value_'.$tabid.'_'.$i]))."')";
				mysql_query($sql3,$connect);
				mysql_query("commit");
			}
		}
		
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtBLDate_'.$tabid.'_'.$i] != "")
			{
				$sql2 = "insert into sof_slave_1 (SOFID, BL_DATE, BL_GROSS_QTY, BL_QTY, CARGO) values ('".$qrows['SOFID']."', '".date("Y-m-d",strtotime($_REQUEST['txtBLDate_'.$tabid.'_'.$i]))."', '".$this->getCheckNullValue($_REQUEST['txtQty_'.$tabid.'_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtBLQty_'.$tabid.'_'.$i])."', '".addslashes($_REQUEST['txtCargo_'.$tabid.'_'.$i])."')";
				mysql_query($sql2);
				mysql_query("commit");
			}
		}
				
		for($j=1; $j<12; $j++)
		{
			$txtTBID     			= $_REQUEST['txtTBID'.$j.'_'.$tabid];
			$txtCRM     			= explode(",",$_REQUEST['txtCRM'.$j.'_'.$tabid]);
			
			for($i=0 ; $i<$txtTBID ;$i++)
			{
				if($_REQUEST['txtROW_ID'.$j.'_'.$tabid.'_'.$txtCRM[$i]] != 0)
				{
					if($_REQUEST['txtActivity'.$j.'_'.$tabid.'_'.$txtCRM[$i]] != "")
					{
						$sql1 = "insert into sof_slave (SOFID, ACTIVITYID, START_DATETIME, FINISH_DATETIME, DURATION, LAY_TIME_COUNT, PORT_TIME_COUNT, NOTES, GROUP_NAME) values ('".$qrows['SOFID']."','".$_REQUEST['txtActivity'.$j.'_'.$tabid.'_'.$txtCRM[$i]]."','".date("Y-m-d H:i",strtotime($_REQUEST['txtDStart'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."','".date("Y-m-d H:i",strtotime($_REQUEST['txtDEnd'.$j.'_'.$tabid.'_'.$txtCRM[$i]]))."', '".$_REQUEST['txtDiff'.$j.'_'.$tabid.'_'.$txtCRM[$i]]."','0','0','".addslashes($_REQUEST['txtNotes'.$j.'_'.$tabid.'_'.$txtCRM[$i]])."', '".$arr[$j]."')";
						mysql_query($sql1,$connect);
						mysql_query("commit");
					}
				}
			}
		}
		
		for($i=1 ; $i<=$txtSID ;$i++)
		{
			$sql2 = "insert into sof_slave_2(SOFID, ACTIVITYID, ARRIVAL_COND, DEPARTURE_COND) values ('".$qrows['SOFID']."', '".$_REQUEST['txtMI_'.$tabid.'_'.$i]."', '".$_REQUEST['txtAC_'.$tabid.'_'.$i]."', '".$_REQUEST['txtDC_'.$tabid.'_'.$i]."')";
			mysql_query($sql2);
			mysql_query("commit");
		}
	}	
	
	$txtcheckbox	        = addslashes(trim($_REQUEST['txtcheckbox_'.$tabid]));
	$txtPA_1	        	= addslashes(trim($_REQUEST['txtPA_1_'.$tabid]));
	$txtPA_2	        	= addslashes(trim($_REQUEST['txtPA_2_'.$tabid]));
	$txtPA_3	        	= addslashes(trim($_REQUEST['txtPA_3_'.$tabid]));
	
	$txtETA_1	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_1_'.$tabid]));
	$txtETA_2	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_2_'.$tabid]));
	$txtETA_3	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_3_'.$tabid]));
	$txtETA_4	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_4_'.$tabid]));
	$txtETA_5	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_5_'.$tabid]));
	
	$txtETA_6	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_6_'.$tabid]));
	$txtETA_7	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_7_'.$tabid]));
	$txtETA_8	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_8_'.$tabid]));
	$txtETA_9	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_9_'.$tabid]));
	$txtETA_10	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_10_'.$tabid]));
	$txtETA_11	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_11_'.$tabid]));
	$txtETA_12	        	= date("Y-m-d H:i",strtotime($_REQUEST['txtETA_12_'.$tabid]));
	
	$txtTBID12	        	= $_REQUEST['txtTBID12_'.$tabid];
	
	$sql = "select * from sof_slave_4 where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$txtRandomID."'";
	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		$sql1 = "insert into sof_slave_4 (COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, CARGO_DECL, STOW_PLAN_QTY, SP_DEPT_DRAFT, SP_ARR_DRAFT, ETA_30_DAYS, ETA_25_DAYS, ETA_20_DAYS, ETA_15_DAYS, ETA_10_DAYS, ETA_7_DAYS, ETA_5_DAYS, ETA_3_DAYS, ETA_2_DAYS, ETA_1_DAYS, ACTUAL_ARRIVAL, NOR_TENDERED, RANDOMID) values ('".$comid."', 'INTERNAL_USER', '".$_SESSION['uid']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$port."', '".$this->getCheckNullValue($portid)."', '".$this->getCheckNullValue($txtcheckbox)."', '".$this->getCheckNullValue($txtPA_1)."', '".$txtPA_2."', '".$txtPA_3."', '".$txtETA_1."', '".$txtETA_2."', '".$txtETA_3."', '".$txtETA_4."', '".$txtETA_5."', '".$txtETA_6."', '".$txtETA_7."', '".$txtETA_8."', '".$txtETA_9."', '".$txtETA_10."', '".$txtETA_11."', '".$txtETA_12."', '".$txtRandomID."')";
		mysql_query($sql1) or die($sql1);
		
		for($i=1;$i<=$txtTBID12;$i++)
		{
			if(addslashes(trim($_REQUEST['txtDate12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtLQty12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtLoadLast12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtTotalLoad12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtBal12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtETCD12_'.$tabid.'_'.$i])) != '')
			{echo $txtTBID12;
				$sql2 = "insert into sof_slave_5 (COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, PRE_DATE, ENGAGEMENT_QTY, LOAD_LAST, TTL_LOAD, BALANCE, ETCD, RANDOMID) values ('".$comid."', 'INTERNAL_USER', '".$_SESSION['uid']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$port."', '".$this->getCheckNullValue($portid)."', '".date("Y-m-d",strtotime($_REQUEST['txtDate12_'.$tabid.'_'.$i]))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtLQty12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtLoadLast12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtTotalLoad12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtBal12_'.$tabid.'_'.$i])))."', '".date("Y-m-d H:i",strtotime($_REQUEST['txtETCD12_'.$tabid.'_'.$i]))."', '".$txtRandomID."')";
				mysql_query($sql2) or die($sql2);
			}
		}//die;
	}
	else
	{ 
		$rows = mysql_fetch_assoc($res);
		
		$sql1 = "update sof_slave_4 set CARGO_DECL='".$this->getCheckNullValue($txtcheckbox)."', STOW_PLAN_QTY='".$this->getCheckNullValue($txtPA_1)."', SP_DEPT_DRAFT='".$txtPA_2."', SP_ARR_DRAFT='".$txtPA_3."', ETA_30_DAYS='".$txtETA_1."' , ETA_25_DAYS='".$txtETA_2."', ETA_20_DAYS='".$txtETA_3."', ETA_15_DAYS='".$txtETA_4."', ETA_10_DAYS='".$txtETA_5."', ETA_7_DAYS='".$txtETA_6."', ETA_5_DAYS='".$txtETA_7."', ETA_3_DAYS='".$txtETA_8."', ETA_2_DAYS='".$txtETA_9."', ETA_1_DAYS='".$txtETA_10."', ACTUAL_ARRIVAL='".$txtETA_11."', NOR_TENDERED='".$txtETA_12."' where SOFSLAVEID='".$rows['SOFSLAVEID']."'"; 
		mysql_query($sql1) or die($sql1);
		
		$sql2 = "delete from sof_slave_5 where COMID='".$comid."' and LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and PORT='".$port."' and PORTID='".$portid."' and RANDOMID='".$txtRandomID."'";
		mysql_query($sql2) or die($sql2);
		
		for($i=1;$i<=$txtTBID12;$i++)
		{ 
			if(addslashes(trim($_REQUEST['txtDate12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtLQty12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtLoadLast12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtTotalLoad12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtBal12_'.$tabid.'_'.$i])) != '' && addslashes(trim($_REQUEST['txtETCD12_'.$tabid.'_'.$i])) != '')
			{
				$sql3 = "insert into sof_slave_5 (COMID, LOGIN, LOGINID, MODULEID, MCOMPANYID, PORT, PORTID, PRE_DATE, ENGAGEMENT_QTY, LOAD_LAST, TTL_LOAD, BALANCE, ETCD, RANDOMID) values ('".$comid."', 'INTERNAL_USER', '".$_SESSION['uid']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$port."', '".$this->getCheckNullValue($portid)."', '".date("Y-m-d",strtotime($_REQUEST['txtDate12_'.$tabid.'_'.$i]))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtLQty12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtLoadLast12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtTotalLoad12_'.$tabid.'_'.$i])))."', '".$this->getCheckNullValue(addslashes(trim($_REQUEST['txtBal12_'.$tabid.'_'.$i])))."', '".date("Y-m-d H:i",strtotime($_REQUEST['txtETCD12_'.$tabid.'_'.$i]))."', '".$txtRandomID."')";
				mysql_query($sql3) or die($sql3);
			}
		}
	}
	mysql_query("commit");
	return $msg; 
}


function insertHirePaymentReceivedDetails()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update invoice_hire_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where INVOICEID='".$txtP_ID."' ";
	//echo $sql;die;
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$this->inactiveUserAlerts('HIRE STATEMENT', $_SESSION['uid'], $txtP_ID);
	
	return $msg; 
}

function getReDelDate($comid)
{
	$query = "select REDEL_DATE from check_list where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'";
	$qres = mysql_query($query) or die($query);
	$qrec = mysql_num_rows($qres);
	$qrows = mysql_fetch_assoc($qres);
	return $qrows['REDEL_DATE'];
}


function insertPdfDetails($comid)
{
	$connect				= $this->funConnect();
	 $txtFile               = $_REQUEST['txtFile'];
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$filename = implode(",",$upload);
	$user_file_name = implode(",",$name);
		
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$sql = "insert into cp_pdf_details (COMID, FILE_NAME, USER_FILE_NAME, FILE_NAME_1) values ('".$comid."', '".addslashes($filename)."', '".addslashes(trim($txtFile))."', '".addslashes($user_file_name)."')";
	mysql_query($sql);
	mysql_query("commit");
	return $msg; 
}


function insertInvoiceHireDetailsAdjustment()
{
	$connect = $this->funConnect(); //echo '<pre>'; print_r($_REQUEST); die();
	
	$comid 			= addslashes(trim($_REQUEST['comid']));
	$txtFcaid 		= addslashes(trim($_REQUEST['txtFcaid']));
	$txtMapId	 	= addslashes(trim($_REQUEST['txtMapId']));
	$txtInID	 	= addslashes(trim($_REQUEST['txtInID']));
	$txtStatus	 	= addslashes(trim($_REQUEST['txtStatus']));
	$selIType 		= addslashes(trim($_REQUEST['selIType']));
	$txtInvoiceNo	= addslashes(trim($_REQUEST['txtInvoiceNo']));
	$txtDate	 	= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	
	$txtRemarks	 	= addslashes(trim($_REQUEST['txtRemarks']));
	
	$txtFinalAmt    = addslashes(trim($_REQUEST['txtFinalAmt']));
	$txtVendor      = addslashes(trim($_REQUEST['txtVendor']));
	$txtINVType     = 2;
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	if($txtInID == '')
	{
		//insert query here.............
		$sql = "insert into invoice_hire_master (MODULEID, MCOMPANYID, COMID, INVOICE_TYPE, INVOICE_NO, INVOICE_DATE, BALANCE_TO_OWNER, REMARKS, STATUS, VENDORID, INV_TYPE) values ('".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$comid."', '".$selIType."', '".$txtInvoiceNo."', '".$txtDate."', '".$this->getCheckNullVal($txtFinalAmt)."', '".$txtRemarks."', '".$txtStatus."', '".$txtVendor."', '".$txtINVType."')";
		mysql_query($sql) or die($sql);
	}
	else
	{
		
		$sql = "update invoice_hire_master set INVOICE_TYPE='".$selIType."', INVOICE_NO='".$txtInvoiceNo."', INVOICE_DATE='".$txtDate."', BALANCE_TO_OWNER='".$this->getCheckNullVal($txtFinalAmt)."', REMARKS='".$txtRemarks."', STATUS='".$txtStatus."', VENDORID='".$txtVendor."' where INVOICEID='".$txtInID."'";
		mysql_query($sql);
	}
	
	mysql_query("commit");
	return $msg.','.$comid;  
}


function getOwnerRelatedCostList($selid)
{
	$this->funConnect();
	$query = mysql_query("select NAME, OWNER_RCOSTID from owner_related_cost_master where STATUS=1 order by NAME");
	echo '<option value = "" >---Select from list---</option>';
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['OWNER_RCOSTID'];
		 $value= $rows['NAME'];
		 echo '<option value='.$key;
		 if($key == $selid){ echo ' selected';}
		 echo '>'.$value.'</option>';
		}
}

function getBunkerList()
{
	$this->funConnect();
	$query = mysql_query("select * from bunker_grade_master where STATUS=1 order by NAME ");
	echo '<option value = "" >---Select from list---</option>';
	@$selCName = @$_REQUEST['selCName'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['BUNKERGRADEID'];
		 $value= $rows['NAME'];
		 echo '<option value='.$key;
		 echo '>'.$value.'</option>';
		}
}


function insertTCEstimate()
{


	 

	// die();

	$connect = $this->funConnect();
	
	$selFType					= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    		= addslashes(trim($_REQUEST['selVName']));
	$txtVType	 				= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 				= addslashes(trim($_REQUEST['txtFlag']));
	$txtTCNo	 				= addslashes(trim($_REQUEST['txtTCNo']));
	$selCPType					= addslashes(trim($_REQUEST['selCPType']));
	$selCharterers				= addslashes(trim($_REQUEST['selCharterers']));
	$selCharOperation			= addslashes(trim($_REQUEST['selCharOperation']));
	$selLawArbit				= addslashes(trim($_REQUEST['selLawArbit']));
	$txtAddress					= addslashes(trim($_REQUEST['txtAddress']));
	$txtBuildYard				= addslashes(trim($_REQUEST['txtBuildYard']));
	$txtYearBuild				= addslashes(trim($_REQUEST['txtYearBuild']));
	$txtFlag1					= addslashes(trim($_REQUEST['txtFlag1']));
	$txtPortOfRegis				= addslashes(trim($_REQUEST['txtPortOfRegis']));
	$txtIMOnum					= addslashes(trim($_REQUEST['txtIMOnum']));
	$txtClassID					= addslashes(trim($_REQUEST['txtClassID']));
	$txtLastSpSurvey			= addslashes(trim($_REQUEST['txtLastSpSurvey']));
	$txtLastDD 		    		= addslashes(trim($_REQUEST['txtLastDD']));
	$txtOwnerPandI 				= addslashes(trim($_REQUEST['txtOwnerPandI']));
	$txtMastersName				= addslashes(trim($_REQUEST['txtMastersName']));
	$txtCallSign 				= addslashes(trim($_REQUEST['txtCallSign']));
	$txtInmarsatTel				= addslashes(trim($_REQUEST['txtInmarsatTel']));
	$txtInmarsatEmail			= addslashes(trim($_REQUEST['txtInmarsatEmail']));
	$txtLOA1					= addslashes(trim($_REQUEST['txtLOA1']));
	$txtBreadth					= addslashes(trim($_REQUEST['txtBreadth']));
	$txtSummerDWT				= addslashes(trim($_REQUEST['txtSummerDWT']));
	$txtSummerDraft				= addslashes(trim($_REQUEST['txtSummerDraft']));
	$txtTPC1					= addslashes(trim($_REQUEST['txtTPC1']));
	$txtGrossTonnage			= addslashes(trim($_REQUEST['txtGrossTonnage']));
	$txtNetTonnage				= addslashes(trim($_REQUEST['txtNetTonnage']));
	$txtSuezGRT					= addslashes(trim($_REQUEST['txtSuezGRT']));
	$txtSuezNRT					= addslashes(trim($_REQUEST['txtSuezNRT']));
	$txtPanamaNRT	    		= addslashes(trim($_REQUEST['txtPanamaNRT']));
	$txtGrainCap 				= addslashes(trim($_REQUEST['txtGrainCap']));
	$txtBaleCap	 				= addslashes(trim($_REQUEST['txtBaleCap']));
	$txtCranes	 				= addslashes(trim($_REQUEST['txtCranes']));
	$txtGrabs					= addslashes(trim($_REQUEST['txtGrabs']));
	$txtKeelTopMast				= addslashes(trim($_REQUEST['txtKeelTopMast']));
	$txtWaterlineTopMast		= addslashes(trim($_REQUEST['txtWaterlineTopMast']));
	$txtDelRangePort			= addslashes(trim($_REQUEST['txtDelRangePort']));
	$selDurFixPeriod			= addslashes(trim($_REQUEST['selDurFixPeriod']));
	$txtTripTC					= addslashes(trim($_REQUEST['txtTripTC']));
	$txtPeriod					= addslashes(trim($_REQUEST['txtPeriod']));
	$txtNoOfTrips				= addslashes(trim($_REQUEST['txtNoOfTrips']));
	$txtDurOptPer				= addslashes(trim($_REQUEST['txtDurOptPer']));
	$txtCommOptPer				= addslashes(trim($_REQUEST['txtCommOptPer']));
	$txtLaycanNarr				= addslashes(trim($_REQUEST['txtLaycanNarr']));
	$txtRedeliveryRange			= addslashes(trim($_REQUEST['txtRedeliveryRange']));
	$txtHireFixPerUSD			= addslashes(trim($_REQUEST['txtHireFixPerUSD']));
	$selExchangeCurrency		= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtExchangeRate			= addslashes(trim($_REQUEST['txtExchangeRate']));
	$txtHireOptPer				= addslashes(trim($_REQUEST['txtHireOptPer']));
	$txtDeliveryHFO	    		= addslashes(trim($_REQUEST['txtDeliveryHFO']));
	$txtDeliveryMGO				= addslashes(trim($_REQUEST['txtDeliveryMGO']));
	$txtRedeliveryHFO    		= addslashes(trim($_REQUEST['txtRedeliveryHFO']));
	$txtRedeliveryMGO           = addslashes(trim($_REQUEST['txtRedeliveryMGO']));
	$txtPriceDelHFO				= addslashes(trim($_REQUEST['txtPriceDelHFO']));
	$txtPriceDelMGO				= addslashes(trim($_REQUEST['txtPriceDelMGO']));
	$txtPriceRedelHFO			= addslashes(trim($_REQUEST['txtPriceRedelHFO']));
	$txtPriceRedelMGO           = addslashes(trim($_REQUEST['txtPriceRedelMGO']));
	$txtFuelSpecs				= addslashes(trim($_REQUEST['txtFuelSpecs']));
	$txtCVEmonth				= addslashes(trim($_REQUEST['txtCVEmonth']));
	$txtSupercargoMeals			= addslashes(trim($_REQUEST['txtSupercargoMeals']));
	$txtHoldCleanInterm			= addslashes(trim($_REQUEST['txtHoldCleanInterm']));
	$txtILOHCtcFix				= addslashes(trim($_REQUEST['txtILOHCtcFix']));
	$txtILOCremarksCP			= addslashes(trim($_REQUEST['txtILOCremarksCP']));
	$txtBrokCommPayableBy		= addslashes(trim($_REQUEST['txtBrokCommPayableBy']));
	$txtAddComm					= addslashes(trim($_REQUEST['txtAddComm']));
	$txtBrokerCommTCfix			= addslashes(trim($_REQUEST['txtBrokerCommTCfix']));
	$txtBankingDetails			= addslashes(trim($_REQUEST['txtBankingDetails']));
	$txtDocCreatBy				= addslashes(trim($_REQUEST['txtDocCreatBy']));
	$txtAddInformation			= addslashes(trim($_REQUEST['txtAddInformation']));
	
	$txtCTankCap				= addslashes(trim($_REQUEST['txtCTankCap']));
	$txtCTankNoOfGrades			= addslashes(trim($_REQUEST['txtCTankNoOfGrades']));
	$txtCPumpCap				= addslashes(trim($_REQUEST['txtCPumpCap']));
	$txtCTotalSBTCap			= addslashes(trim($_REQUEST['txtCTotalSBTCap']));
	
	if($_REQUEST['txtDate']!="")
	{$txtDate     		= date("Y-m-d",strtotime($_REQUEST['txtDate']));}
    else{$txtDate  		= "1970-01-01";}
	
	if($_REQUEST['txtCPdate']!="")
	{$txtCPdate    		= date("Y-m-d",strtotime($_REQUEST['txtCPdate']));}
	else{$txtCPdate    	= "1970-01-01";}
	
	if($_REQUEST['txtLastSpSurvey']!="")
	{$txtLastSpSurvey    		= date("Y-m-d",strtotime($_REQUEST['txtLastSpSurvey']));}
	else{$txtLastSpSurvey    	= "1970-01-01";}
	
	if($_REQUEST['txtLastDD']!="")
	{$txtLastDD    		= date("Y-m-d",strtotime($_REQUEST['txtLastDD']));}
	else{$txtLastDD    	= "1970-01-01";}
	
	if($_REQUEST['txtDeliveryDate']!="")
	{$txtDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtDeliveryDate']));}
	else{$txtDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtReDeliveryDate']!="")
	{$txtReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtReDeliveryDate']));}
	else{$txtReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtLaycanFrom']!="")
	{$txtLaycanFrom					= date("Y-m-d H:i",strtotime($_REQUEST['txtLaycanFrom']));}
	else{$txtLaycanFrom 			= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtLaycanTo']!="")
	{$txtLaycanTo					= date("Y-m-d H:i",strtotime($_REQUEST['txtLaycanTo']));}
	else{$txtLaycanTo 				= "1970-01-01 08:00:00";}
	
	
	/*-------------------------\\\\\\-----END TC FIXTURE NOTE DATA-----/////////----------------------------------*/
	
	/*-----------START---------\\\\\\-----COMMERCIAL PARAMETERS DATA-----/////////--------------------------------*/
	
	$txtDWTS					= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT 		    		= addslashes(trim($_REQUEST['txtDWTT']));
	$txtGCap	 				= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap	 				= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF	 					= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable				= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT					= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA						= addslashes(trim($_REQUEST['txtLOA']));
	$txtGear					= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear				= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam					= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC						= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed				= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1				= addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2				= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed				= addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1				= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2				= addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed    		= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1			= addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2			= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed			= addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1			= addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2			= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed			= addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed			= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed			= addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1			= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2			= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed			= addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1			= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2			= addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed    		= addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed			= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	/*-----------ENDD---------\\\\\\-----COMMERCIAL PARAMETERS DATA-----/////////--------------------------------*/
	
	/*-----------START---------\\\\\\----------TC/CP TERMS DATA---------/////////--------------------------------*/
	
	$txtWindForce				= addslashes(trim($_REQUEST['txtWindForce']));
	$txtSpeedLaden				= addslashes(trim($_REQUEST['txtSpeedLaden']));
	$txtSpeedBallast			= addslashes(trim($_REQUEST['txtSpeedBallast']));
	$txtCPSpeed					= addslashes(trim($_REQUEST['txtCPSpeed']));
	$txtFOConsLaden				= addslashes(trim($_REQUEST['txtFOConsLaden']));
	$txtDOConsLaden				= addslashes(trim($_REQUEST['txtDOConsLaden']));
	$txtFOConsBallast			= addslashes(trim($_REQUEST['txtFOConsBallast']));
	$txtDOConsBallast			= addslashes(trim($_REQUEST['txtDOConsBallast']));
	$txtFOConsLdg				= addslashes(trim($_REQUEST['txtFOConsLdg']));
	$txtDOConsLdg				= addslashes(trim($_REQUEST['txtDOConsLdg']));
	$txtFOConsDisch				= addslashes(trim($_REQUEST['txtFOConsDisch']));
	$txtDOConsDisch				= addslashes(trim($_REQUEST['txtDOConsDisch']));
	$txtFOConsIdle				= addslashes(trim($_REQUEST['txtFOConsIdle']));
	$txtDOConsIdle				= addslashes(trim($_REQUEST['txtDOConsIdle']));
	$txtLoadRate				= addslashes(trim($_REQUEST['txtLoadRate']));
	$txtDischRate				= addslashes(trim($_REQUEST['txtDischRate']));
	$selPeriodContract          = addslashes(trim($_REQUEST['selPeriodContract']));
	
	$selBalticRoute				= addslashes(trim($_REQUEST['selBalticRoute']));
	$txtBalticValue				= addslashes(trim($_REQUEST['txtBalticValue']));
	$chartering_pic				= addslashes(trim($_REQUEST['chartering_pic']));
	if($_REQUEST['txtBalticDate']!="")
	{$txtBalticDate					= date("Y-m-d",strtotime($_REQUEST['txtBalticDate']));}
	else{$txtBalticDate 				= "1970-01-01";}
	
	/*-----------ENDD---------\\\\\\----------TC/CP TERMS DATA---------/////////--------------------------------*/
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	$sql = "insert into chartering_estimate_tc_master (MODULEID, MCOMPANYID, ESTIMATE_TYPE, FIXTURE_TYPE, VESSEL_IMO_ID, VESSEL_TYPE, FLAG, TC_DATE, TC_NO, CP_DATE1, SEL_CP_TYPE, SEL_CHARTERER, SEL_CHAR_OPER, LAW_ARBITRA, CHAR_OPER_ADD, BUILD_YARD, BUILT_YEAR1, FLAG_1, PORT_OF_REG, IMO_NO, CLASS_ID, LAST_SP_SURVEY, LAST_DD, OWNERS_PI, MASTERS_NAME, CALL_SIGN,	INMARSAT_TEL, INMARSAT_MAIL, LOA1, BREADTH, SUMMER_DWT, SUMMER_DRAFT, TPC1, GROSS_TONN, NET_TONN, CARGO_TANK_CAP, NO_OF_GRADES, CARGO_PUMP_CAP, TOTAL_SBT_CAP, SUEZ_GRT, SUEZ_NRT, PANAMA_NRT, GRAIN_CAP1, BALE_CAP1, CRANES, GRABS, KEEL_TOP_MAST, WTR_TOP_MAST_FB, DEL_RANGE_PORT, DUR_FIX_PER, TRIP_TC, PERIOD, NO_OF_TRIP, DEL_DATE, RE_DEL_DATE, DUR_OPT_PER, COMM_OPT_PER, LAYCAN_FROM, LAYCAN_TO, LAYCAN_NARR, RE_DEL_RANGE, HIRE_FIX_PER, EXCHANGE_CURRENCY, EXCHANGE_RATE, HIRE_OPT_PER, FUEL_SPECS, CVE_MONTH, SUP_CARGO_MEAL, HOLD_CLEAN_INTER, ILOHC_USD, ILOHC_REMARKS, BRO_COMM_PAYABLE, ADD_COMM, BROKER_COMM, OWNERS_BANK_DET, DOC_CREAT_BY, ADDIT_INFORM, UPDATE_ON_DATE, DWT_SUMMER_CP, DWT_TROPICAL_CP, GRAIN_CAP_CP, BALE_CAP_CP, SF_CP, LOADABLE_CP,	GRT_NRT_CP,	LOA_CP,	GEAR_CP, BUILT_YEAR_CP,	BEAM_CP, TPC_CP, B_FULL_SPEED_CP, B_ECO_SPEED1_CP, B_ECO_SPEED2_CP, L_FULL_SPEED_CP, L_ECO_SPEED1_CP, L_ECO_SPEED2_CP,	B_PASS_FULL_CP,	B_PASS_ECO1_CP,	B_PASS_ECO2_CP, L_PASS_FULL_CP,	L_PASS_ECO1_CP,	L_PASS_ECO2_CP,	INPORT_IDLE_CP,	INPORT_WORK_CP,	BP_FUL_SPEED_CP, BP_ECO_SPEED1_CP, BP_ECO_SPEED2_CP, LP_FUL_SPEED_CP, LP_ECO_SPEED1_CP, LP_ECO_SPEED2_CP, INPORT_IDLE1_CP,	INPORT_WORK1_CP, RE_DEL_MGO, PR_REDEL_MGO, WIND_FORCE_TCCP, SPD_LADEN_TCCP, SPD_BLST_TCCP,	CP_SPD_TCCP, FO_CONS_LDN_TCCP, DO_CONS_LDN_TCCP, FO_CONS_BLST_TCCP, DO_CONS_BLST_TCCP, FO_CONS_LDN2_TCCP, DO_CONS_LDN2_TCCP, FO_CONS_DISH_TCCP, DO_CONS_DISH_TCCP, FO_CONS_IDLE_TCCP, DO_CONS_IDLE_TCCP, LODE_RATE_TCCP, DISH_RATE_TCCP, BALTIC_ROUTE, BALTIC_DATE, BALTIC_RATE, PERIODID,CHARTERING_PIC,F_YEAR) values ('".$this->getCheckNullValue($_SESSION['moduleid'])."', '".$this->getCheckNullValue($_SESSION['company'])."','".$_SESSION['selBType']."','".$selFType."','".$selVName."','".$txtVType."','".$txtFlag."','".$txtDate."','".$txtTCNo."','".$txtCPdate."','".$selCPType."','".$selCharterers."','".$selCharOperation."','".$selLawArbit."','".$txtAddress."','".$txtBuildYard."','".$txtYearBuild."','".$txtFlag1."','".$txtPortOfRegis."','".$txtIMOnum."','".$txtClassID."','".$txtLastSpSurvey."','".$txtLastDD."','".$txtOwnerPandI."','".$txtMastersName."','".$txtCallSign."','".$txtInmarsatTel."','".$txtInmarsatEmail."','".$txtLOA1."','".$txtBreadth."','".$txtSummerDWT."','".$txtSummerDraft."','".$txtTPC1."','".$txtGrossTonnage."','".$txtNetTonnage."','".$txtCTankCap."','".$txtCTankNoOfGrades."','".$txtCPumpCap."','".$txtCTotalSBTCap."','".$txtSuezGRT."','".$txtSuezNRT."','".$txtPanamaNRT."','".$txtGrainCap."','".$txtBaleCap."','".$txtCranes."','".$txtGrabs."',	'".$txtKeelTopMast."','".$txtWaterlineTopMast."','".$txtDelRangePort."','".$selDurFixPeriod."','".$txtTripTC."','".$txtPeriod."','".$txtNoOfTrips."','".$txtDeliveryDate."','".$txtReDeliveryDate."','".$txtDurOptPer."','".$txtCommOptPer."','".$txtLaycanFrom."','".$txtLaycanTo."','".$txtLaycanNarr."','".$txtRedeliveryRange."','".$this->getCheckNullValue($txtHireFixPerUSD)."','".$this->getCheckNullValue($selExchangeCurrency)."','".$this->getCheckNullValue($txtExchangeRate)."','".$this->getCheckNullValue($txtHireOptPer)."','".$txtFuelSpecs."','".$this->getCheckNullValue($txtCVEmonth)."','".$txtSupercargoMeals."','".$txtHoldCleanInterm."','".$this->getCheckNullValue($txtILOHCtcFix)."','".$txtILOCremarksCP."','".$txtBrokCommPayableBy."','".$this->getCheckNullValue($txtAddComm)."','".$this->getCheckNullValue($txtBrokerCommTCfix)."','".$txtBankingDetails."','".$txtDocCreatBy."','".$txtAddInformation."', NOW(),'".$txtDWTS."','".$txtDWTT."','".$txtGCap."','".$txtBCap."','".$txtSF."','".$txtLoadable."','".$txtGNRT."','".$txtLOA."','".$txtGear."','".$txtBuiltYear."','".$txtBeam."','".$txtTPC."','".$this->getCheckNullValue($txtBFullSpeed)."','".$this->getCheckNullValue($txtBEcoSpeed1)."','".$this->getCheckNullValue($txtBEcoSpeed2)."','".$this->getCheckNullValue($txtLFullSpeed)."','".$this->getCheckNullValue($txtLEcoSpeed1)."','".$this->getCheckNullValue($txtLEcoSpeed2)."','".$this->getCheckNullValue($txtBFOFullSpeed)."','".$this->getCheckNullValue($txtBFOEcoSpeed1)."','".$this->getCheckNullValue($txtBFOEcoSpeed2)."','".$this->getCheckNullValue($txtLFOFullSpeed)."','".$this->getCheckNullValue($txtLFOEcoSpeed1)."','".$this->getCheckNullValue($txtLFOEcoSpeed2)."','".$this->getCheckNullValue($txtPIFOFullSpeed)."','".$this->getCheckNullValue($txtPWFOFullSpeed)."','".$this->getCheckNullValue($txtBDOFullSpeed)."','".$this->getCheckNullValue($txtBDOEcoSpeed1)."','".$this->getCheckNullValue($txtBDOEcoSpeed2)."','".$this->getCheckNullValue($txtLDOFullSpeed)."','".$this->getCheckNullValue($txtLDOEcoSpeed1)."','".$this->getCheckNullValue($txtLDOEcoSpeed2)."','".$this->getCheckNullValue($txtPIDOFullSpeed)."','".$this->getCheckNullValue($txtPWDOFullSpeed)."','".$this->getCheckNullValue($txtRedeliveryMGO)."','".$this->getCheckNullValue($txtPriceRedelMGO)."','".$this->getCheckNullValue($txtWindForce)."','".$this->getCheckNullValue($txtSpeedLaden)."','".$this->getCheckNullValue($txtSpeedBallast)."','".$this->getCheckNullValue($txtCPSpeed)."','".$this->getCheckNullValue($txtFOConsLaden)."','".$this->getCheckNullValue($txtDOConsLaden)."','".$this->getCheckNullValue($txtFOConsBallast)."','".$this->getCheckNullValue($txtDOConsBallast)."','".$this->getCheckNullValue($txtFOConsLdg)."','".$this->getCheckNullValue($txtDOConsLdg)."','".$this->getCheckNullValue($txtFOConsDisch)."','".$this->getCheckNullValue($txtDOConsDisch)."','".$this->getCheckNullValue($txtFOConsIdle)."','".$this->getCheckNullValue($txtDOConsIdle)."','".$this->getCheckNullValue($txtLoadRate)."','".$this->getCheckNullValue($txtDischRate)."','".$this->getCheckNullValue($selBalticRoute)."','".$txtBalticDate."','".$this->getCheckNullValue($txtBalticValue)."', '".$this->getCheckNullValue($selPeriodContract)."','".$this->getCheckNullValue($chartering_pic)."','".date('Y', strtotime($_REQUEST['txtCPdate']))."')";
	mysql_query($sql) or die($sql);
	mysql_query("commit");

	
    
	$mysql = "select max(TCOUTID) as max from chartering_estimate_tc_master";
	$myres  =  mysql_query($mysql);
	$myrows = mysql_fetch_assoc($myres);
	$maxid = $myrows['max'];
	
	$txtDELID = $_REQUEST['txtDELID'];
	for($j=1 ; $j<=$txtDELID ;$j++)
	{
		if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
		{
			if($_REQUEST['txtDelBunDate_'.$j]!="")
			{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
			else{$txtDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into chartering_estimate_tc_slave4 (TCOUTID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtREDELID = $_REQUEST['txtREDELID'];
	for($j=1 ; $j<=$txtREDELID ;$j++)
	{
		if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
		{
			if($_REQUEST['txtReDelBunDate_'.$j]!="")
			{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
			else{$txtReDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into chartering_estimate_tc_slave4 (TCOUTID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
	for($i=1;$i<=$txtFOAtSeaID;$i++)
	{
		$sql1 = "insert into chartering_estimate_tc_slave6 (TCOUTID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";	
		mysql_query($sql1) or die($sql1);
		mysql_query("commit");
	}
	
	$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
	for($i=1;$i<=$txtDOAtSeaID;$i++)
	{
		$sql1 = "insert into chartering_estimate_tc_slave6 (TCOUTID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
			
		mysql_query($sql1) or die($sql1);
		mysql_query("commit");
	}
	return $msg; 
}




function getCharteringEstimateTCData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from chartering_estimate_tc_master where COMID='".$id."' and MODULEID='".$_SESSION['moduleid']."' order by TCOUTID desc";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}




function getTCSheetNameFromTCEListNew($estimatetype)
{
	$this->funConnect();
	$sql = "select * from chartering_estimate_tc_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and ESTIMATE_TYPE='".$estimatetype."' and SHEET_NO is NULL order by TCOUTID desc";
	$res = mysql_query($sql) or die($sql);
	while($rows = mysql_fetch_assoc($res))
	{
		$value = $rows['TC_NO'];
		$key = $rows['TCOUTID'];
		
		echo "<option value=$key";
		if($key == @$id){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}



function displayTCETempleteListNew($selBType)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="fce_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	
	echo '<th align="left" valign="middle" width="10%">Vessel</th>';
	echo '<th align="left" valign="middle" width="10%">Vessel Type</th>';
	echo '<th align="left" valign="middle" width="7%">TC No.</th>';
	echo '<th align="left" valign="middle" width="11%">CP Date</th>';
	echo '<th align="left" valign="middle" width="9%">DWT</th>';
	echo '<th align="left" valign="middle" width="9%">Del Port</th>';
	echo '<th align="left" valign="middle" width="9%">Re Del Port</th>';
	echo '<th align="left" valign="middle" width="7%">TC Days</th>';
	echo '<th align="left" valign="middle" width="9%">Daily Gross Hire(USD)</th>';
	echo '<th align="left" valign="middle" width="9%">Total Rev(USD)</th>';
	echo '<th align="center" valign="middle" width="10%">Select All<br/>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chkAll" id="chkAll" value="1" class="checkbox"/></th>';
	echo '<th align="center" valign="middle" width="10%">Fixture Note</th>';
	echo '<th align="left" valign="middle" width="5%">Estimate</th>';
	
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	
	$sql = "SELECT TCOUTID, chartering_estimate_tc_master.VESSEL_TYPE, chartering_estimate_tc_master.EXCHANGE_RATE, chartering_estimate_tc_master.COMID, vessel_imo_master.VESSEL_NAME, (select SUM(TC_DAYS_EST) as SUM from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID) as TC_DAYS_EST, (select SUM(TOTAL_REV_EST) as SUM from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID) as TOTAL_REV_EST, vessel_imo_master.VESSEL_IMO_ID, TC_NO, SEL_CP_TYPE, CP_DATE1, FUEL_SPECS, MASTERS_NAME, DWT_SUMMER_CP, DEL_RANGE_PORT, RE_DEL_RANGE, HIRE_FIX_PER FROM chartering_estimate_tc_master inner JOIN vessel_imo_master ON vessel_imo_master.VESSEL_IMO_ID=chartering_estimate_tc_master.VESSEL_IMO_ID WHERE chartering_estimate_tc_master.MCOMPANYID='".$_SESSION['company']."' AND vessel_imo_master.BUSINESSTYPEID='".$selBType."' and chartering_estimate_tc_master.SHEET_NO is NULL and chartering_estimate_tc_master.FIXED is NULL ORDER BY TCOUTID DESC";
	
	$res  = mysql_query($sql) or die($sql);
	$rec  = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else 
	{
		while($rows = mysql_fetch_assoc($res))
		{
			if($rows['EXCHANGE_RATE']>0 || $rows['EXCHANGE_RATE']<0){$exchangerate = $rows['EXCHANGE_RATE'];}else{$exchangerate = 1;}
		echo '<tr>';
		echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
		echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
		echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
		echo '<td align="left" valign="middle" class="input-text">'.$rows['TC_NO'].'</td>';
		if($rows['CP_DATE1']=="" || $rows['CP_DATE1']=="1970-01-01"){$CP_DATE1 = "";}else{$CP_DATE1 = date('d-m-Y',strtotime($rows['CP_DATE1']));}
		echo '<td align="left" valign="middle" class="input-text">'.$CP_DATE1.'</td>';
		echo '<td align="left" valign="middle" class="input-text">'.$rows['DWT_SUMMER_CP'].'</td>';
		echo '<td align="left" valign="middle" class="input-text">'.$rows['DEL_RANGE_PORT'].'</td>';
		echo '<td align="left" valign="middle" class="input-text">'.$rows['RE_DEL_RANGE'].'</td>';
		echo '<td align="left" valign="middle" class="input-text">'.$rows['TC_DAYS_EST'].'</td>';
		echo '<td align="left" valign="middle" class="input-text">'.number_format(($rows['HIRE_FIX_PER']*$exchangerate),2,'.','').'</td>';
		echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_REV_EST'].'</td>';
		
		if($rows['COMID']=="")
		{
			if($rows['TOTAL_REV_EST'] >0){$checkbox = '<input type="checkbox" name="chkFCA[]" id="chkFCA_'.$i.'" value="'.$rows['TCOUTID'].'" class="checkbox"/>';}else{$checkbox = 'Create Estimate';}
			echo '<td align="center" valign="middle" class="input-text">'.$checkbox.'</td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="updatetcestimate.php?id='.$rows['TCOUTID'].'" title="Edit Details"><i class="fa fa-edit"></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#Delete" onclick="return getDelete('.$rows['TCOUTID'].');" ><i class="fa fa-times" style="color:red;"></i></td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="updatetcestimatecal.php?id='.$rows['TCOUTID'].'" title="Edit TC Estimate"><i class="fa fa-edit"></i></a></td>';
		}
		else
		{
			echo '<td align="center" valign="middle" class="input-text">Sent to Decision Chart</td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="updatetcestimate.php?id='.$rows['TCOUTID'].'" title="Edit Details"><i class="fa fa-edit"></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#Delete" onclick="return getDelete('.$rows['TCOUTID'].');" ><i class="fa fa-times" style="color:red;"></i></td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="viewtcestimate.php?id='.$rows['TCOUTID'].'&rttype=" title="Edit Details" ><i class="fa fa-file "></i></a></td>';
		}
		echo '</tr>';
		$i++;
	 }
	
	}
	echo '</tbody>';
	echo '</table></div>';
}

function deleteTCETempleteRecordsNew()
{
	$connect				= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['delId']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 2;
	
	$del_query1 = "delete from  chartering_estimate_tc_master where TCOUTID='".$id."'";
	$del_query2 = "delete from  chartering_estimate_tc_slave1 where TCOUTID='".$id."'";
	$del_query3 = "delete from  chartering_estimate_tc_slave2 where TCOUTID='".$id."'";
	$del_query4 = "delete from  chartering_estimate_tc_slave3 where TCOUTID='".$id."'";
	$del_query5 = "delete from  chartering_estimate_tc_slave4 where TCOUTID='".$id."'";
	$del_query5 = "delete from  chartering_estimate_tc_slave5 where TCOUTID='".$id."'";
	
	
	mysql_query($del_query1);
	mysql_query($del_query2);
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query($del_query5);
	mysql_query("commit");
	 
	return $msg;
}


function submitFinalTCRecordCompare()
{
	
	$this->funConnect();
	$hddnCount = $_REQUEST['hddnCount'];
	$rdoFCA 	 = $_REQUEST['rdoFCA'];
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;
	$year = date('Y',time());
	$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM chartering_estimate_tc_compare where Year(ADD_ON_DATE) = '".$year."'";
	$result = mysql_query($query) or die(mysql_error());
	$rec=mysql_num_rows($result);
	
	$year1 = $year[2].''.$year[3];
	
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['MESSAGE_NO'];
	if($rows['MESSAGE_NO'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode =$empcode;
		}
	else
		{
			$empcode= "001";
		}
	}
	
	$msg1 = $year1."-".$empcode;
	for($i=1;$i<=$hddnCount;$i++)
	{
		if($_REQUEST['rdoFCA'] == $_REQUEST['hiddnFca_'.$i])
	    {$val = $_REQUEST['rdoFCA'];}else{$val = "";}
		$sql2 = "insert into chartering_estimate_tc_compare (TCOUTID, FINAL_ID, MESSAGE_NO, USERID, REMARKS, ADD_ON_DATE, MESSAGE, MODULEID, MCOMPANYID) values ('".$_REQUEST['hiddnFca_'.$i]."', '".$val."', '".$empcode."', '".$_SESSION['uid']."', '".$_REQUEST['txtDesc_'.$i]."', NOW(), '".$msg1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."')";
		mysql_query($sql2) or die($sql2);
		mysql_query("commit"); 
		if($_REQUEST['rdoFCA'] == $_REQUEST['hiddnFca_'.$i])
		{
			$query1 = "SELECT MAX(COMID) as MAX FROM chartering_estimate_tc_compare where MESSAGE='".$msg1."' and FINAL_ID!='' ";
			$result1 = mysql_query($query1) or die(mysql_error());
			$rows1 = mysql_fetch_array($result1);
		    
			$sql3 = "update chartering_estimate_tc_master set COMID='".$rows1['MAX']."' where TCOUTID='".$_REQUEST['hiddnFca_'.$i]."' ";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit"); 
		}
	}
	return $msg;
}

function displayTCDecisionChartList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="fce_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">Decision Chart</th>';
	echo '<th align="left" valign="middle" width="12%">Chart No.</th>';
	echo '<th align="left" valign="middle" width="12%">TC No.</th>';
	echo '<th align="left" valign="middle" width="12%">Vessel</th>';
	echo '<th align="left" valign="middle" width="12%">Del Port/Redel Port</th>';
	echo '<th align="left" valign="middle" width="10%">Add On Date</th>';
	echo '<th align="left" valign="middle" width="10%">Added By</th>';
	echo '<th align="center" valign="middle" width="7%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	$sql = "select MESSAGE, MESSAGE_NO, ADD_ON_DATE, FINAL_ID, USERID from chartering_estimate_tc_compare WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FINAL_ID !='' order by  ADD_ON_DATE desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
			$sql1 = "SELECT TCOUTID, (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=chartering_estimate_tc_master.VESSEL_IMO_ID) as VESSEL_NAME, TC_NO, DEL_RANGE_PORT, RE_DEL_RANGE FROM chartering_estimate_tc_master WHERE TCOUTID= ".$rows['FINAL_ID'];
			$res1 = mysql_query($sql1) or die($sql1);
			$rows1 = mysql_fetch_assoc($res1);
		  
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows1['TC_NO'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows1['VESSEL_NAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows1['DEL_RANGE_PORT'].'/'.$rows1['RE_DEL_RANGE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.date('d-m-Y',strtotime($rows['ADD_ON_DATE'])).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$this->getUserDetailBaseOnId($rows['USERID'],'CONTACT_PERSON').'</td>';
			echo '<td align="center" valign="middle" class="input-text"><a href="#" title="View Details" data-toggle="modal" data-target="#compose-modal" onclick="getListToCompare('.explode('-',$rows['MESSAGE'])[0].','.$rows['MESSAGE_NO'].');" ><i class="fa fa-file"></i></a></td>';	
			echo '</tr>';
			$i++;
		}
	
	}echo '</tbody>';
	echo '</table></div>';
}



function viewTCEstimationTempleteRecordsNew($id)
{
	$connect = $this->funConnect();
	$sql = "select * from chartering_estimate_tc_master where MODULEID='".$_SESSION['moduleid']."' and TCOUTID='".$id."' ";
	
	
	$result = mysql_query($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
	//TC FIXTURE NOTE DATA
		$this->var_1 = $rows['TCOUTID'];
		$this->var_2 = $rows['FIXTURE_TYPE'];	
		$this->var_3 = $rows['VESSEL_IMO_ID'];
		$this->var_4 = $rows['VESSEL_TYPE'];
		$this->var_5 = $rows['FLAG'];
		$this->var_6 = $rows['TC_DATE'];
		$this->var_7 = $rows['TC_NO'];
		$this->var_9 = $rows['CP_DATE1'];
		$this->var_10 = $rows['SEL_CP_TYPE'];
		$this->var_11 = $rows['SEL_CHARTERER'];
		$this->var_12 = $rows['SEL_CHAR_OPER'];
		$this->var_13 = $rows['LAW_ARBITRA'];
		$this->var_14 = $rows['CHAR_OPER_ADD'];
		$this->var_15 = $rows['BUILD_YARD'];
		$this->var_16 = $rows['BUILT_YEAR1'];
		$this->var_17 = $rows['FLAG_1'];
		$this->var_18 = $rows['PORT_OF_REG'];
		$this->var_19 = $rows['IMO_NO'];
		$this->var_20 = $rows['CLASS_ID'];
		$this->var_21 = $rows['LAST_SP_SURVEY'];
		$this->var_22 = $rows['LAST_DD'];
		$this->var_23 = $rows['OWNERS_PI'];
		$this->var_24 = $rows['MASTERS_NAME'];
		$this->var_25 = $rows['CALL_SIGN'];
		$this->var_26 = $rows['INMARSAT_TEL'];
		$this->var_27 = $rows['INMARSAT_MAIL'];
		$this->var_28 = $rows['LOA1'];
		$this->var_29 = $rows['BREADTH'];
		$this->var_30 = $rows['SUMMER_DWT'];
		$this->var_31 = $rows['SUMMER_DRAFT'];
		$this->var_32 = $rows['TPC1'];
		$this->var_33 = $rows['GROSS_TONN'];
		$this->var_34 = $rows['NET_TONN'];
		$this->var_35 = $rows['SUEZ_GRT'];
		$this->var_36 = $rows['SUEZ_NRT'];
		$this->var_37 = $rows['PANAMA_NRT'];
		$this->var_38 = $rows['GRAIN_CAP1'];
		$this->var_39 = $rows['BALE_CAP1'];
		$this->var_40 = $rows['CRANES'];
		$this->var_41 = $rows['GRABS'];
		$this->var_42 = $rows['KEEL_TOP_MAST'];
		$this->var_43 = $rows['WTR_TOP_MAST_FB'];
		$this->var_44 = $rows['DEL_RANGE_PORT'];
		$this->var_45 = $rows['DUR_FIX_PER'];
		$this->var_46 = $rows['DEL_DATE'];
		$this->var_47 = $rows['RE_DEL_DATE'];
		$this->var_48 = $rows['DUR_OPT_PER'];
		$this->var_49 = $rows['COMM_OPT_PER'];
		$this->var_50 = $rows['LAYCAN_FROM'];
		$this->var_51 = $rows['LAYCAN_TO'];
		$this->var_52 = $rows['LAYCAN_NARR'];
		$this->var_53 = $rows['RE_DEL_RANGE'];
		$this->var_54 = $rows['HIRE_FIX_PER'];
		$this->var_55 = $rows['HIRE_OPT_PER'];
		$this->var_56 = $rows['DEL_HFO'];
		$this->var_57 = $rows['DEL_MGO'];
		$this->var_58 = $rows['RE_DEL_HFO'];
		$this->var_59 = $rows['PRICE_DEL_HFO'];
		$this->var_60 = $rows['PRICE_DEL_MGO'];
		$this->var_61 = $rows['PR_REDEL_HFO'];
		$this->var_62 = $rows['FUEL_SPECS'];
		$this->var_63 = $rows['CVE_MONTH'];
		$this->var_64 = $rows['HOLD_CLEAN_INTER'];
		$this->var_65 = $rows['ILOHC_USD'];
		$this->var_66 = $rows['ILOHC_REMARKS'];
		$this->var_67 = $rows['BRO_COMM_PAYABLE'];
		$this->var_68 = $rows['ADD_COMM'];
		$this->var_69 = $rows['BROKER_COMM'];
		$this->var_70 = $rows['OWNERS_BANK_DET'];
		$this->var_71 = $rows['DOC_CREAT_BY'];
		$this->var_72 = $rows['ADDIT_INFORM'];
		$this->var_73 = $rows['SUP_CARGO_MEAL'];
		$this->var_74 = $rows['TRIP_TC'];
		$this->var_75 = $rows['PERIOD'];
		$this->var_76 = $rows['NO_OF_TRIP'];
		$this->var_137 = $rows['EXCHANGE_CURRENCY'];
		$this->var_138 = $rows['EXCHANGE_RATE'];
		$this->var_77 = $rows['DWT_SUMMER_CP'];
		$this->var_78 = $rows['DWT_TROPICAL_CP'];
		$this->var_79 = $rows['GRAIN_CAP_CP'];
		$this->var_80 = $rows['BALE_CAP_CP'];
		$this->var_81 = $rows['SF_CP'];
		$this->var_82 = $rows['LOADABLE_CP'];
		$this->var_83 = $rows['GRT_NRT_CP'];
		$this->var_84 = $rows['LOA_CP'];
		$this->var_85 = $rows['GEAR_CP'];
		$this->var_86 = $rows['BUILT_YEAR_CP'];
		$this->var_87 = $rows['BEAM_CP'];
		$this->var_88 = $rows['TPC_CP'];
		$this->var_89 = $rows['B_FULL_SPEED_CP'];
		$this->var_90 = $rows['B_ECO_SPEED1_CP'];
		$this->var_91 = $rows['B_ECO_SPEED2_CP'];
		$this->var_92 = $rows['L_FULL_SPEED_CP'];
		$this->var_93 = $rows['L_ECO_SPEED1_CP'];
		$this->var_94 = $rows['L_ECO_SPEED2_CP'];
		$this->var_95 = $rows['B_PASS_FULL_CP'];
		$this->var_96 = $rows['B_PASS_ECO1_CP'];
		$this->var_97 = $rows['B_PASS_ECO2_CP'];
		$this->var_98 = $rows['L_PASS_FULL_CP'];
		$this->var_99 = $rows['L_PASS_ECO1_CP'];
		$this->var_100 = $rows['L_PASS_ECO2_CP'];
		$this->var_101 = $rows['INPORT_IDLE_CP'];
		$this->var_102 = $rows['INPORT_WORK_CP'];
		$this->var_103 = $rows['BP_FUL_SPEED_CP'];
		$this->var_104 = $rows['BP_ECO_SPEED1_CP'];
		$this->var_105 = $rows['BP_ECO_SPEED2_CP'];
		$this->var_106 = $rows['LP_FUL_SPEED_CP'];
		$this->var_107 = $rows['LP_ECO_SPEED1_CP'];
		$this->var_108 = $rows['LP_ECO_SPEED2_CP'];
		$this->var_109 = $rows['INPORT_IDLE1_CP'];
		$this->var_110 = $rows['INPORT_WORK1_CP'];
		$this->var_111 = $rows['CARGO_TANK_CAP'];
		$this->var_112 = $rows['NO_OF_GRADES'];
		$this->var_113 = $rows['CARGO_PUMP_CAP'];
		$this->var_114 = $rows['TOTAL_SBT_CAP'];
		$this->var_115 = $rows['TANK_CLEAN_EXP'];
		$this->var_116 = $rows['ADD_EXP_LINE_ITEM'];
		$this->var_117 = $rows['TOTAL_DAYS'];
		$this->var_118 = $rows['TOTAL_EARNING'];
		$this->var_119 = $rows['RE_DEL_MGO'];
		$this->var_120 = $rows['PR_REDEL_MGO'];
	//TC/CP TERMS DATA START
		$this->var_121 = $rows['WIND_FORCE_TCCP'];
		$this->var_122 = $rows['SPD_LADEN_TCCP'];
		$this->var_123 = $rows['SPD_BLST_TCCP'];
		$this->var_124 = $rows['CP_SPD_TCCP'];
		$this->var_125 = $rows['FO_CONS_LDN_TCCP'];
		$this->var_126 = $rows['DO_CONS_LDN_TCCP'];
		$this->var_127 = $rows['FO_CONS_BLST_TCCP'];
		$this->var_128 = $rows['DO_CONS_BLST_TCCP'];
		$this->var_129 = $rows['FO_CONS_LDN2_TCCP'];
		$this->var_130 = $rows['DO_CONS_LDN2_TCCP'];
		$this->var_131 = $rows['FO_CONS_DISH_TCCP'];
		$this->var_132 = $rows['DO_CONS_DISH_TCCP'];
		$this->var_133 = $rows['FO_CONS_IDLE_TCCP'];
		$this->var_134 = $rows['DO_CONS_IDLE_TCCP'];
		$this->var_135 = $rows['LODE_RATE_TCCP'];
		$this->var_136 = $rows['DISH_RATE_TCCP'];
		
		$this->var_140 = $rows['BALTIC_ROUTE'];
		$this->var_141 = $rows['BALTIC_DATE'];
		$this->var_142 = $rows['BALTIC_RATE'];
		$this->var_143 = $rows['PERIODID'];
		$this->var_144 = $rows['OWNER'];
		$this->var_145 = $rows['CARGO_QTY'];
		$this->var_146 = $rows['CARGO'];
		$this->var_147 = $rows['CHARTERING_PIC'];
	}
}

function updateTCEstimate($id)
{
	$connect = $this->funConnect();
	
	/*-------------------------\\\\\\-----TC FIXTURE NOTE DATA-----/////////--------------------------------------*/
	
	$selFType					= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    		= addslashes(trim($_REQUEST['selVName']));
	$txtVType	 				= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 				= addslashes(trim($_REQUEST['txtFlag']));
	$txtTCNo	 				= addslashes(trim($_REQUEST['txtTCNo']));
	$selCPType					= addslashes(trim($_REQUEST['selCPType']));
	$selCharterers				= addslashes(trim($_REQUEST['selCharterers']));
	$selCharOperation			= addslashes(trim($_REQUEST['selCharOperation']));
	$selLawArbit				= addslashes(trim($_REQUEST['selLawArbit']));
	$txtAddress					= addslashes(trim($_REQUEST['txtAddress']));
	$txtBuildYard				= addslashes(trim($_REQUEST['txtBuildYard']));
	$txtYearBuild				= addslashes(trim($_REQUEST['txtYearBuild']));
	$txtFlag1					= addslashes(trim($_REQUEST['txtFlag1']));
	$txtPortOfRegis				= addslashes(trim($_REQUEST['txtPortOfRegis']));
	$txtIMOnum					= addslashes(trim($_REQUEST['txtIMOnum']));
	$txtClassID					= addslashes(trim($_REQUEST['txtClassID']));
	$txtLastSpSurvey			= addslashes(trim($_REQUEST['txtLastSpSurvey']));
	$txtLastDD 		    		= addslashes(trim($_REQUEST['txtLastDD']));
	$txtOwnerPandI 				= addslashes(trim($_REQUEST['txtOwnerPandI']));
	$txtMastersName				= addslashes(trim($_REQUEST['txtMastersName']));
	$txtCallSign 				= addslashes(trim($_REQUEST['txtCallSign']));
	$txtInmarsatTel				= addslashes(trim($_REQUEST['txtInmarsatTel']));
	$txtInmarsatEmail			= addslashes(trim($_REQUEST['txtInmarsatEmail']));
	$txtLOA1					= addslashes(trim($_REQUEST['txtLOA1']));
	$txtBreadth					= addslashes(trim($_REQUEST['txtBreadth']));
	$txtSummerDWT				= addslashes(trim($_REQUEST['txtSummerDWT']));
	$txtSummerDraft				= addslashes(trim($_REQUEST['txtSummerDraft']));
	$txtTPC1					= addslashes(trim($_REQUEST['txtTPC1']));
	$txtGrossTonnage			= addslashes(trim($_REQUEST['txtGrossTonnage']));
	$txtNetTonnage				= addslashes(trim($_REQUEST['txtNetTonnage']));
	$txtSuezGRT					= addslashes(trim($_REQUEST['txtSuezGRT']));
	$txtSuezNRT					= addslashes(trim($_REQUEST['txtSuezNRT']));
	$txtPanamaNRT	    		= addslashes(trim($_REQUEST['txtPanamaNRT']));
	$txtGrainCap 				= addslashes(trim($_REQUEST['txtGrainCap']));
	$txtBaleCap	 				= addslashes(trim($_REQUEST['txtBaleCap']));
	$txtCranes	 				= addslashes(trim($_REQUEST['txtCranes']));
	$txtGrabs					= addslashes(trim($_REQUEST['txtGrabs']));
	$txtKeelTopMast				= addslashes(trim($_REQUEST['txtKeelTopMast']));
	$txtWaterlineTopMast		= addslashes(trim($_REQUEST['txtWaterlineTopMast']));
	$txtDelRangePort			= addslashes(trim($_REQUEST['txtDelRangePort']));
	//$selDurFixPeriod			= addslashes(trim($_REQUEST['selDurFixPeriod']));
	$txtDurOptPer				= addslashes(trim($_REQUEST['txtDurOptPer']));
	$txtCommOptPer				= addslashes(trim($_REQUEST['txtCommOptPer']));
	$txtLaycanNarr				= addslashes(trim($_REQUEST['txtLaycanNarr']));
	$txtRedeliveryRange			= addslashes(trim($_REQUEST['txtRedeliveryRange']));
	$txtHireFixPerUSD			= addslashes(trim($_REQUEST['txtHireFixPerUSD']));
	$selExchangeCurrency		= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtExchangeRate			= addslashes(trim($_REQUEST['txtExchangeRate']));
	$txtHireOptPer				= addslashes(trim($_REQUEST['txtHireOptPer']));
	$txtDeliveryHFO	    		= addslashes(trim($_REQUEST['txtDeliveryHFO']));
	$txtDeliveryMGO				= addslashes(trim($_REQUEST['txtDeliveryMGO']));
	$txtRedeliveryHFO    		= addslashes(trim($_REQUEST['txtRedeliveryHFO']));
	$txtRedeliveryMGO           = addslashes(trim($_REQUEST['txtRedeliveryMGO']));
	$txtPriceDelHFO				= addslashes(trim($_REQUEST['txtPriceDelHFO']));
	$txtPriceDelMGO				= addslashes(trim($_REQUEST['txtPriceDelMGO']));
	$txtPriceRedelHFO			= addslashes(trim($_REQUEST['txtPriceRedelHFO']));
	$txtPriceRedelMGO           = addslashes(trim($_REQUEST['txtPriceRedelMGO']));
	$txtFuelSpecs				= addslashes(trim($_REQUEST['txtFuelSpecs']));
	$txtCVEmonth				= addslashes(trim($_REQUEST['txtCVEmonth']));
	$txtSupercargoMeals			= addslashes(trim($_REQUEST['txtSupercargoMeals']));
	$txtHoldCleanInterm			= addslashes(trim($_REQUEST['txtHoldCleanInterm']));
	$txtILOHCtcFix				= addslashes(trim($_REQUEST['txtILOHCtcFix']));
	$txtILOCremarksCP			= addslashes(trim($_REQUEST['txtILOCremarksCP']));
	$txtBrokCommPayableBy		= addslashes(trim($_REQUEST['txtBrokCommPayableBy']));
	$txtAddComm					= addslashes(trim($_REQUEST['txtAddComm']));
	$txtBrokerCommTCfix			= addslashes(trim($_REQUEST['txtBrokerCommTCfix']));
	$txtBankingDetails			= addslashes(trim($_REQUEST['txtBankingDetails']));
	$txtDocCreatBy				= addslashes(trim($_REQUEST['txtDocCreatBy']));
	$txtAddInformation			= addslashes(trim($_REQUEST['txtAddInformation']));
	
	$txtCTankCap				= addslashes(trim($_REQUEST['txtCTankCap']));
	$txtCTankNoOfGrades			= addslashes(trim($_REQUEST['txtCTankNoOfGrades']));
	$txtCPumpCap				= addslashes(trim($_REQUEST['txtCPumpCap']));
	$txtCTotalSBTCap			= addslashes(trim($_REQUEST['txtCTotalSBTCap']));
	
	
	if($_REQUEST['txtDate']!="")
	{$txtDate     		= date("Y-m-d",strtotime($_REQUEST['txtDate']));}
    else{$txtDate  		= "1970-01-01";}
	
	if($_REQUEST['txtCPdate']!="")
	{$txtCPdate    		= date("Y-m-d",strtotime($_REQUEST['txtCPdate']));}
	else{$txtCPdate    	= "1970-01-01";}
	
	if($_REQUEST['txtLastSpSurvey']!="")
	{$txtLastSpSurvey    		= date("Y-m-d",strtotime($_REQUEST['txtLastSpSurvey']));}
	else{$txtLastSpSurvey    	= "1970-01-01";}
	
	if($_REQUEST['txtLastDD']!="")
	{$txtLastDD    		= date("Y-m-d",strtotime($_REQUEST['txtLastDD']));}
	else{$txtLastDD    	= "1970-01-01";}
	
	if($_REQUEST['txtDeliveryDate']!="")
	{$txtDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtDeliveryDate']));}
	else{$txtDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtReDeliveryDate']!="")
	{$txtReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtReDeliveryDate']));}
	else{$txtReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtLaycanFrom']!="")
	{$txtLaycanFrom					= date("Y-m-d H:i",strtotime($_REQUEST['txtLaycanFrom']));}
	else{$txtLaycanFrom 			= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtLaycanTo']!="")
	{$txtLaycanTo					= date("Y-m-d H:i",strtotime($_REQUEST['txtLaycanTo']));}
	else{$txtLaycanTo				= "1970-01-01 08:00:00";}
	
	
	/*--------------------\\\\\\-----ENDD TC FIXTURE NOTE TRANSFER DATA-----/////////---------------------------------*/
	
	/*----------START--\\\\\\-----START COMMERCIAL PARAMETERS DATA---------/////////--------------------------------*/
	
	$txtDWTS					= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT 		    		= addslashes(trim($_REQUEST['txtDWTT']));
	$txtGCap	 				= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap	 				= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF	 					= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable				= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT					= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA						= addslashes(trim($_REQUEST['txtLOA']));
	$txtGear					= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear				= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam					= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC						= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed				= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1				= addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2				= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed				= addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1				= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2				= addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed    		= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1			= addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2			= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed			= addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1			= addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2			= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed			= addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed			= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed			= addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1			= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2			= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed			= addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1			= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2			= addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed    		= addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed			= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	/*--------ENDD-----\\\\\\-----ENDD COMMERCIAL PARAMETERS DATA-----/////////-------------ENDD--------------------*/
	
	/*-----------START---------\\\\\\----------TC/CP TERMS DATA---------/////////--------------------------------*/
	
	$txtWindForce				= addslashes(trim($_REQUEST['txtWindForce']));
	$txtSpeedLaden				= addslashes(trim($_REQUEST['txtSpeedLaden']));
	$txtSpeedBallast			= addslashes(trim($_REQUEST['txtSpeedBallast']));
	$txtCPSpeed					= addslashes(trim($_REQUEST['txtCPSpeed']));
	$txtFOConsLaden				= addslashes(trim($_REQUEST['txtFOConsLaden']));
	$txtDOConsLaden				= addslashes(trim($_REQUEST['txtDOConsLaden']));
	$txtFOConsBallast			= addslashes(trim($_REQUEST['txtFOConsBallast']));
	$txtDOConsBallast			= addslashes(trim($_REQUEST['txtDOConsBallast']));
	$txtFOConsLdg				= addslashes(trim($_REQUEST['txtFOConsLdg']));
	$txtDOConsLdg				= addslashes(trim($_REQUEST['txtDOConsLdg']));
	$txtFOConsDisch				= addslashes(trim($_REQUEST['txtFOConsDisch']));
	$txtDOConsDisch				= addslashes(trim($_REQUEST['txtDOConsDisch']));
	$txtFOConsIdle				= addslashes(trim($_REQUEST['txtFOConsIdle']));
	$txtDOConsIdle				= addslashes(trim($_REQUEST['txtDOConsIdle']));
	$txtLoadRate				= addslashes(trim($_REQUEST['txtLoadRate']));
	$txtDischRate				= addslashes(trim($_REQUEST['txtDischRate']));
	$selPeriodContract          = addslashes(trim($_REQUEST['selPeriodContract']));
	
	$selBalticRoute				= addslashes(trim($_REQUEST['selBalticRoute']));
	$txtBalticValue				= addslashes(trim($_REQUEST['txtBalticValue']));
	if($_REQUEST['txtBalticDate']!="")
	{$txtBalticDate					= date("Y-m-d",strtotime($_REQUEST['txtBalticDate']));}
	else{$txtBalticDate 				= "1970-01-01";}
	
	/*-----------ENDD---------\\\\\\----------TC/CP TERMS DATA---------/////////--------------------------------*/

	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update chartering_estimate_tc_master set FIXTURE_TYPE='".$selFType."',VESSEL_IMO_ID='".$selVName."',VESSEL_TYPE='".$txtVType."',FLAG='".$txtFlag."',TC_DATE='".$txtDate."',TC_NO='".$txtTCNo."',CP_DATE1='".$txtCPdate."',SEL_CP_TYPE='".$selCPType."',SEL_CHARTERER='".$selCharterers."',SEL_CHAR_OPER='".$selCharOperation."',LAW_ARBITRA='".$selLawArbit."',CHAR_OPER_ADD='".$txtAddress."',BUILD_YARD='".$txtBuildYard."',BUILT_YEAR1='".$txtYearBuild."',FLAG_1='".$txtFlag1."',PORT_OF_REG='".$txtPortOfRegis."',IMO_NO='".$txtIMOnum."',CLASS_ID='".$txtClassID."',LAST_SP_SURVEY='".$txtLastSpSurvey."',LAST_DD='".$txtLastDD."',OWNERS_PI='".$txtOwnerPandI."',MASTERS_NAME='".$txtMastersName."',CALL_SIGN='".$txtCallSign."',INMARSAT_TEL='".$txtInmarsatTel."',INMARSAT_MAIL='".$txtInmarsatEmail."',LOA1='".$txtLOA1."',BREADTH='".$txtBreadth."',SUMMER_DWT='".$txtSummerDWT."',SUMMER_DRAFT='".$txtSummerDraft."',TPC1='".$txtTPC1."',GROSS_TONN='".$txtGrossTonnage."',NET_TONN='".$txtNetTonnage."',CARGO_TANK_CAP='".$txtCTankCap."',NO_OF_GRADES='".$txtCTankNoOfGrades."',CARGO_PUMP_CAP='".$txtCPumpCap."',TOTAL_SBT_CAP='".$txtCTotalSBTCap."',SUEZ_GRT='".$txtSuezGRT."',SUEZ_NRT='".$txtSuezNRT."',PANAMA_NRT='".$txtPanamaNRT."',GRAIN_CAP1='".$txtGrainCap."',BALE_CAP1='".$txtBaleCap."',CRANES='".$txtCranes."',GRABS='".$txtGrabs."',KEEL_TOP_MAST='".$txtKeelTopMast."',WTR_TOP_MAST_FB='".$txtWaterlineTopMast."',DEL_RANGE_PORT='".$txtDelRangePort."',DEL_DATE='".$txtDeliveryDate."',RE_DEL_DATE='".$txtReDeliveryDate."',DUR_OPT_PER='".$this->getCheckNullValue($txtDurOptPer)."',COMM_OPT_PER='".$this->getCheckNullValue($txtCommOptPer)."',LAYCAN_FROM='".$txtLaycanFrom."',LAYCAN_TO='".$txtLaycanTo."',LAYCAN_NARR='".$txtLaycanNarr."',RE_DEL_RANGE='".$txtRedeliveryRange."',HIRE_FIX_PER='".$this->getCheckNullValue($txtHireFixPerUSD)."',EXCHANGE_CURRENCY='".$selExchangeCurrency."',EXCHANGE_RATE='".$txtExchangeRate."',HIRE_OPT_PER='".$this->getCheckNullValue($txtHireOptPer)."',FUEL_SPECS='".$txtFuelSpecs."',CVE_MONTH='".$this->getCheckNullValue($txtCVEmonth)."',SUP_CARGO_MEAL='".$txtSupercargoMeals."',HOLD_CLEAN_INTER='".$txtHoldCleanInterm."',ILOHC_USD='".$this->getCheckNullValue($txtILOHCtcFix)."',ILOHC_REMARKS='".$txtILOCremarksCP."',BRO_COMM_PAYABLE='".$this->getCheckNullValue($txtBrokCommPayableBy)."',ADD_COMM='".$this->getCheckNullValue($txtAddComm)."',BROKER_COMM='".$this->getCheckNullValue($txtBrokerCommTCfix)."',OWNERS_BANK_DET='".$txtBankingDetails."',DOC_CREAT_BY='".$txtDocCreatBy."',ADDIT_INFORM='".$txtAddInformation."',UPDATE_ON_DATE=NOW(),DWT_SUMMER_CP='".$txtDWTS."',DWT_TROPICAL_CP='".$txtDWTT."',GRAIN_CAP_CP='".$txtGCap."',BALE_CAP_CP='".$txtBCap."',SF_CP='".$txtSF."',LOADABLE_CP='".$txtLoadable."',GRT_NRT_CP='".$txtGNRT."',LOA_CP='".$txtLOA."',GEAR_CP='".$txtGear."',BUILT_YEAR_CP='".$txtBuiltYear."',BEAM_CP='".$txtBeam."',TPC_CP='".$this->getCheckNullValue($txtTPC)."',B_FULL_SPEED_CP='".$this->getCheckNullValue($txtBFullSpeed)."',B_ECO_SPEED1_CP='".$this->getCheckNullValue($txtBEcoSpeed1)."',B_ECO_SPEED2_CP='".$this->getCheckNullValue($txtBEcoSpeed2)."',L_FULL_SPEED_CP='".$this->getCheckNullValue($txtLFullSpeed)."',L_ECO_SPEED1_CP='".$this->getCheckNullValue($txtLEcoSpeed1)."',L_ECO_SPEED2_CP='".$this->getCheckNullValue($txtLEcoSpeed2)."',B_PASS_FULL_CP='".$this->getCheckNullValue($txtBFOFullSpeed)."',B_PASS_ECO1_CP='".$this->getCheckNullValue($txtBFOEcoSpeed1)."',B_PASS_ECO2_CP='".$this->getCheckNullValue($txtBFOEcoSpeed2)."',L_PASS_FULL_CP='".$this->getCheckNullValue($txtLFOFullSpeed)."',L_PASS_ECO1_CP='".$this->getCheckNullValue($txtLFOEcoSpeed1)."',L_PASS_ECO2_CP='".$this->getCheckNullValue($txtLFOEcoSpeed2)."',INPORT_IDLE_CP='".$this->getCheckNullValue($txtPIFOFullSpeed)."',INPORT_WORK_CP='".$this->getCheckNullValue($txtPWFOFullSpeed)."',BP_FUL_SPEED_CP='".$this->getCheckNullValue($txtBDOFullSpeed)."',BP_ECO_SPEED1_CP='".$this->getCheckNullValue($txtBDOEcoSpeed1)."',BP_ECO_SPEED2_CP='".$this->getCheckNullValue($txtBDOEcoSpeed2)."',LP_FUL_SPEED_CP='".$this->getCheckNullValue($txtLDOFullSpeed)."',LP_ECO_SPEED1_CP='".$this->getCheckNullValue($txtLDOEcoSpeed1)."',LP_ECO_SPEED2_CP='".$this->getCheckNullValue($txtLDOEcoSpeed2)."',INPORT_IDLE1_CP='".$this->getCheckNullValue($txtPIDOFullSpeed)."',INPORT_WORK1_CP='".$this->getCheckNullValue($txtPWDOFullSpeed)."',WIND_FORCE_TCCP='".$txtWindForce."',SPD_LADEN_TCCP='".$this->getCheckNullValue($txtSpeedLaden)."',SPD_BLST_TCCP='".$this->getCheckNullValue($txtSpeedBallast)."',CP_SPD_TCCP='".$this->getCheckNullValue($txtCPSpeed)."',FO_CONS_LDN_TCCP='".$this->getCheckNullValue($txtFOConsLaden)."',DO_CONS_LDN_TCCP='".$this->getCheckNullValue($txtDOConsLaden)."',FO_CONS_BLST_TCCP='".$this->getCheckNullValue($txtFOConsBallast)."',DO_CONS_BLST_TCCP='".$this->getCheckNullValue($txtDOConsBallast)."',FO_CONS_LDN2_TCCP='".$this->getCheckNullValue($txtFOConsLdg)."',DO_CONS_LDN2_TCCP='".$this->getCheckNullValue($txtDOConsLdg)."',FO_CONS_DISH_TCCP='".$this->getCheckNullValue($txtFOConsDisch)."',DO_CONS_DISH_TCCP='".$this->getCheckNullValue($txtDOConsDisch)."',FO_CONS_IDLE_TCCP='".$this->getCheckNullValue($txtFOConsIdle)."',DO_CONS_IDLE_TCCP='".$this->getCheckNullValue($txtDOConsIdle)."',LODE_RATE_TCCP='".$this->getCheckNullValue($txtLoadRate)."',DISH_RATE_TCCP='".$this->getCheckNullValue($txtDischRate)."', BALTIC_ROUTE='".$this->getCheckNullValue($selBalticRoute)."', BALTIC_DATE='".$txtBalticDate."', BALTIC_RATE='".$this->getCheckNullValue($txtBalticValue)."', PERIODID='".$this->getCheckNullValue($selPeriodContract)."' WHERE TCOUTID='".$id."' ";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$del_query = "delete from chartering_estimate_tc_slave4 where TCOUTID='".$id."'";
	mysql_query($del_query);mysql_query("commit");
	
	$del_query2 = "delete from chartering_estimate_tc_slave6 where TCOUTID='".$id."'";
	mysql_query($del_query2);mysql_query("commit");
    
	$txtDELID = $_REQUEST['txtDELID'];
	for($j=1 ; $j<=$txtDELID ;$j++)
	{
		if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
		{
			if($_REQUEST['txtDelBunDate_'.$j]!="")
			{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
			else{$txtDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into chartering_estimate_tc_slave4 (TCOUTID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtREDELID = $_REQUEST['txtREDELID'];
	for($j=1 ; $j<=$txtREDELID ;$j++)
	{
		if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
		{
			if($_REQUEST['txtReDelBunDate_'.$j]!="")
			{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
			else{$txtReDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into chartering_estimate_tc_slave4 (TCOUTID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
	for($i=1;$i<=$txtFOAtSeaID;$i++)
	{
		$sql1 = "insert into chartering_estimate_tc_slave6 (TCOUTID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";	
		mysql_query($sql1) or die($sql1);
		mysql_query("commit");
	}
	
	$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
	for($i=1;$i<=$txtDOAtSeaID;$i++)
	{
		$sql1 = "insert into chartering_estimate_tc_slave6 (TCOUTID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
			
		mysql_query($sql1) or die($sql1);
		mysql_query("commit");
	}
	
	return $msg; 
}


function updateTCinOpsFixtureNoteData($id)
{
	$connect = $this->funConnect();
	/*-----------START---------\\\\\\----------TC/CP TERMS DATA---------/////////--------------------------------*/
	$txtWindForce				= addslashes(trim($_REQUEST['txtWindForce']));
	$txtSpeedLaden				= addslashes(trim($_REQUEST['txtSpeedLaden']));
	$txtSpeedBallast			= addslashes(trim($_REQUEST['txtSpeedBallast']));
	$txtCPSpeed					= addslashes(trim($_REQUEST['txtCPSpeed']));
	$txtFOConsLaden				= addslashes(trim($_REQUEST['txtFOConsLaden']));
	$txtDOConsLaden				= addslashes(trim($_REQUEST['txtDOConsLaden']));
	$txtFOConsBallast			= addslashes(trim($_REQUEST['txtFOConsBallast']));
	$txtDOConsBallast			= addslashes(trim($_REQUEST['txtDOConsBallast']));
	$txtFOConsLdg				= addslashes(trim($_REQUEST['txtFOConsLdg']));
	$txtDOConsLdg				= addslashes(trim($_REQUEST['txtDOConsLdg']));
	$txtFOConsDisch				= addslashes(trim($_REQUEST['txtFOConsDisch']));
	$txtDOConsDisch				= addslashes(trim($_REQUEST['txtDOConsDisch']));
	$txtFOConsIdle				= addslashes(trim($_REQUEST['txtFOConsIdle']));
	$txtDOConsIdle				= addslashes(trim($_REQUEST['txtDOConsIdle']));
	$txtLoadRate				= addslashes(trim($_REQUEST['txtLoadRate']));
	$txtDischRate				= addslashes(trim($_REQUEST['txtDischRate']));
	/*-----------ENDD---------\\\\\\----------TC/CP TERMS DATA---------/////////--------------------------------*/
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update chartering_estimate_tc_master set UPDATE_ON_DATE=NOW(), WIND_FORCE_TCCP='".$this->getCheckNullValue($txtWindForce)."', SPD_LADEN_TCCP='".$this->getCheckNullValue($txtSpeedLaden)."', SPD_BLST_TCCP='".$this->getCheckNullValue($txtSpeedBallast)."',	CP_SPD_TCCP='".$this->getCheckNullValue($txtCPSpeed)."', FO_CONS_LDN_TCCP='".$this->getCheckNullValue($txtFOConsLaden)."', DO_CONS_LDN_TCCP='".$this->getCheckNullValue($txtDOConsLaden)."', FO_CONS_BLST_TCCP='".$this->getCheckNullValue($txtFOConsBallast)."', DO_CONS_BLST_TCCP='".$this->getCheckNullValue($txtDOConsBallast)."', FO_CONS_LDN2_TCCP='".$this->getCheckNullValue($txtFOConsLdg)."', DO_CONS_LDN2_TCCP='".$this->getCheckNullValue($txtDOConsLdg)."', FO_CONS_DISH_TCCP='".$this->getCheckNullValue($txtFOConsDisch)."', DO_CONS_DISH_TCCP='".$this->getCheckNullValue($txtDOConsDisch)."', FO_CONS_IDLE_TCCP='".$this->getCheckNullValue($txtFOConsIdle)."', DO_CONS_IDLE_TCCP='".$this->getCheckNullValue($txtDOConsIdle)."', LODE_RATE_TCCP='".$this->getCheckNullValue($txtLoadRate)."', DISH_RATE_TCCP='".$this->getCheckNullValue($txtDischRate)."' WHERE TCOUTID='".$id."' ";
	mysql_query($sql) or die($sql);
	mysql_query("commit");

	return $msg; 
}

function updateTCEstimateCal($id)
{
	$connect = $this->funConnect(); 
	
	/*-------------------------\\\\\\-----START TC ESTIMATE------------/////////--------------------------------------*/
	
	$txtTripTC1					= addslashes(trim($_REQUEST['txtTripTC1']));
	$txtPeriod1 		    	= addslashes(trim($_REQUEST['txtPeriod1']));
	$txtNoOfTrips1	 			= addslashes(trim($_REQUEST['txtNoOfTrips1']));
	$txtCPType	 				= addslashes(trim($_REQUEST['txtCPType']));
	$txtCharterers				= addslashes(trim($_REQUEST['txtCharterers']));
	$txtDelHFOmt				= addslashes(trim($_REQUEST['txtDelHFOmt']));
	$txtDelHFOusdmt				= addslashes(trim($_REQUEST['txtDelHFOusdmt']));
	$txtDelMGOmt				= addslashes(trim($_REQUEST['txtDelMGOmt']));
	$txtDelMGOusdmt				= addslashes(trim($_REQUEST['txtDelMGOusdmt']));
	$txtReDelHFOmt				= addslashes(trim($_REQUEST['txtReDelHFOmt']));
	$txtReDelHFOusdmt			= addslashes(trim($_REQUEST['txtReDelHFOusdmt']));
	$txtReDelMGOmt				= addslashes(trim($_REQUEST['txtReDelMGOmt']));
	$txtReDelMGOusdmt			= addslashes(trim($_REQUEST['txtReDelMGOusdmt']));
	
	$txtDelTotalHFOUSD			= addslashes(trim($_REQUEST['txtDelTotalHFOUSD']));
	$txtDelTotalMDOUSD			= addslashes(trim($_REQUEST['txtDelTotalMDOUSD']));
	$txtReDelTotalHFOUSD		= addslashes(trim($_REQUEST['txtReDelTotalHFOUSD']));
	$txtReDelTotalMDOUSD		= addslashes(trim($_REQUEST['txtReDelTotalMDOUSD']));
	$txtBunkerDifference		= addslashes(trim($_REQUEST['txtBunkerDifference']));
	
	$txtTCdays					= addslashes(trim($_REQUEST['txtTCdays']));
	$txtUtilisationDays			= addslashes(trim($_REQUEST['txtUtilisationDays']));
	$txtExchangeCurrency        = addslashes(trim($_REQUEST['txtExchangeCurrency']));
	$txtExchangeRate            = addslashes(trim($_REQUEST['txtExchangeRate']));
	$txtDailyGrossHireUSD		= addslashes(trim($_REQUEST['txtDailyGrossHireUSD']));
	$txtAddCommPerct			= addslashes(trim($_REQUEST['txtAddCommPerct']));
	$txtAddComm1				= addslashes(trim($_REQUEST['txtAddComm1']));
	$txtChartererAcc			= addslashes(trim($_REQUEST['txtChartererAcc']));
	$txtBrokerComm				= addslashes(trim($_REQUEST['txtBrokerComm']));
	$txtNettHire				= addslashes(trim($_REQUEST['txtNettHire']));
	$txtNettRev					= addslashes(trim($_REQUEST['txtNettRev']));
	$txtLessOffHire				= addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtCVE						= addslashes(trim($_REQUEST['txtCVE']));
	$txtOtherIncome				= addslashes(trim($_REQUEST['txtOtherIncome']));
	$txtTotalRev	    		= addslashes(trim($_REQUEST['txtTotalRev']));
	
	$txtTotalExpenses			= addslashes(trim($_REQUEST['txtTotalExpenses']));
	$txtVoyageEarnings			= addslashes(trim($_REQUEST['txtVoyageEarnings']));
	$txtProfitPerDay			= addslashes(trim($_REQUEST['txtProfitPerDay']));
	
	$txtTCPerDay    			= addslashes(trim($_REQUEST['txtTCPerDay']));
	$txtTotalHireage			= addslashes(trim($_REQUEST['txtTotalHireage']));
	$txtAddComm     			= addslashes(trim($_REQUEST['txtAddComm']));
	$txtAddCommAmt   			= addslashes(trim($_REQUEST['txtAddCommAmt']));
	$txtNetHireage  			= addslashes(trim($_REQUEST['txtNetHireage']));
	$txtCVEM                    = addslashes(trim($_REQUEST['txtCVEM']));
	$txtNETHire                 = addslashes(trim($_REQUEST['txtNETHire']));
	
	if($_REQUEST['txtCPdate2']!="")
	{$txtCPdate2     		= date("Y-m-d",strtotime($_REQUEST['txtCPdate2']));}
    else{$txtCPdate2  		= "1970-01-01";}
	
	if($_REQUEST['txtDeliveryDate']!="")
	{$txtDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtDeliveryDate']));}
	else{$txtDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtReDeliveryDate']!="")
	{$txtReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtReDeliveryDate']));}
	else{$txtReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtDeldate']!="")
	{$txtDeldate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtDeldate']));}
	else{$txtDeldate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtReDeldate']!="")
	{$txtReDeldate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtReDeldate']));}
	else{$txtReDeldate  		= "1970-01-01 08:00:00";}
	
	$randomid = $_REQUEST['txtCOUTSlaveRandomID'];
	if(!isset($_REQUEST['txtCOUTSlaveRandomID']) || $_REQUEST['txtCOUTSlaveRandomID']=='')
	{
		$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
	}
	
	
	if($_REQUEST['txtTCCPDate']!="")
	{$txtTCCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCCPDate']));}
	else{$txtTCCPDate  		= "1970-01-01";}
	$txtTCDeliveryPort        	= addslashes(trim($_REQUEST['txtTCDeliveryPort']));
	$txtTCReDeliveryPort		= addslashes(trim($_REQUEST['txtTCReDeliveryPort']));
	$txtTCOffHireCVE        	= addslashes(trim($_REQUEST['txtTCOffHireCVE']));
	$txtTCOffHireCVEAMT			= addslashes(trim($_REQUEST['txtTCOffHireCVEAMT']));
	$txtTCBunkerOnOwnerAmt      = addslashes(trim($_REQUEST['txtTCBunkerOnOwnerAmt']));
	$txtTCLessOffHire  			= addslashes(trim($_REQUEST['txtTCLessOffHire']));
	$txtFinalHireargeAmt		= addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$selTCVendor      			= addslashes(trim($_REQUEST['selTCVendor']));
	$txtTCCPNumber     			= addslashes(trim($_REQUEST['txtTCCPNumber']));
	
	/*-----------------\\\\\\-----ENDD TC ESTIMATE TRANSFER DATA-----/////////--------------------------------------*/
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$mainid = $id;
	//echo $mainid;die;
	$sql2 = "select * from chartering_tc_estimate_slave1 where TCOUTID = '".$mainid."'";
	$res2 = mysql_query($sql2) or die($sql2);
	$num  = mysql_num_rows($res2);
	
	if($num==0)
	{
		
		$sql1 = "insert into chartering_tc_estimate_slave1 (TCOUTID, TRIP_TC_EST, PERIOD_TC_EST, NO_OF_TRIP_EST, CP_DATE_EST, CP_TYPE_EST, CHARTERERS_EST, DEL_DATE_EST, DEL_HFO_MT_EST, DEL_HFO_USD_EST, DEL_MGO_MT_EST, DEL_MGO_USD_EST, REDEL_DATE_EST, REDEL_HFO_MT_EST, REDEL_HFO_USD_EST, REDEL_MGO_MT_EST, REDEL_MGO_USD_EST, TC_DAYS_EST, UTILISATION_DAY_EST, DAILY_GROSS_HIRE_EST, ADD_COMM_EST, ADD_COMM_CAL_EST, BROKER_COMM_EST, BROKER_COMM_CAL_EST, NETT_HIRE_EST, NETT_REV_EST, LESS_OFF_HIRE_EST, CVE_EST, OTHER_INCOME_EST, TOTAL_REV_EST, TOTAL_EXP_EST, VOYAGE_EARN_EST, PROFIT_PER_DAY_EST, UPDATE_ON_DATE, DEL_HFO_AMT, DEL_MDO_AMT, REDEL_HFO_AMT, REDEL_MDO_AMT, BUNKER_DIFF_AMT, RANDOMID, TC_RATE, TOTAL_HIREAGE, ADD_COMM, ADD_COMM_AMT, NET_HIREAGE, CVE_MONTH, NET_HIRE_AMT, EXCHANGE_CURRENCY, EXCHANGE_RATE, TC_CP_DATE, TC_PORT_DELIVERY, TC_PORT_REDELIVERY, TC_CVE_MONTH_OFFHIRE, TC_CVE_AMOUNT_OFFHIRE, TC_BUNKERS_ON_OWNER, TC_OFF_HIRE, TC_FINAL_HIERAGE, TC_FINAL_HIERAGE_VENDOR, TC_CP_NUMBER) values ('".$mainid."','".$txtTripTC1."','".$txtPeriod1."','".$txtNoOfTrips1."','".$txtCPdate2."','".$this->getCheckNullValue($txtCPType)."','".$this->getCheckNullValue($txtCharterers)."','".$txtDeldate."','".$this->getCheckNullValue($txtDelHFOmt)."','".$this->getCheckNullValue($txtDelHFOusdmt)."','".$this->getCheckNullValue($txtDelMGOmt)."','".$this->getCheckNullValue($txtDelMGOusdmt)."','".$txtReDeldate."','".$this->getCheckNullValue($txtReDelHFOmt)."','".$this->getCheckNullValue($txtReDelHFOusdmt)."','".$this->getCheckNullValue($txtReDelMGOmt)."','".$this->getCheckNullValue($txtReDelMGOusdmt)."','".$this->getCheckNullValue($txtTCdays)."','".$this->getCheckNullValue($txtUtilisationDays)."','".$this->getCheckNullValue($txtDailyGrossHireUSD)."','".$this->getCheckNullValue($txtAddCommPerct)."','".$this->getCheckNullValue($txtAddComm1)."','".$this->getCheckNullValue($txtChartererAcc)."','".$this->getCheckNullValue($txtBrokerComm)."','".$this->getCheckNullValue($txtNettHire)."','".$this->getCheckNullValue($txtNettRev)."','".$this->getCheckNullValue($txtLessOffHire)."','".$this->getCheckNullValue($txtCVE)."','".$this->getCheckNullValue($txtOtherIncome)."','".$this->getCheckNullValue($txtTotalRev)."','".$this->getCheckNullValue($txtTotalExpenses)."','".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtProfitPerDay)."',NOW(),'".$this->getCheckNullValue($txtDelTotalHFOUSD)."','".$this->getCheckNullValue($txtDelTotalMDOUSD)."','".$this->getCheckNullValue($txtReDelTotalHFOUSD)."','".$this->getCheckNullValue($txtReDelTotalMDOUSD)."','".$this->getCheckNullValue($txtBunkerDifference)."','".$this->getCheckNullValue($randomid)."','".$this->getCheckNullValue($txtTCPerDay)."','".$this->getCheckNullValue($txtTotalHireage)."','".$this->getCheckNullValue($txtAddComm)."','".$this->getCheckNullValue($txtAddCommAmt)."','".$this->getCheckNullValue($txtNetHireage)."','".$this->getCheckNullValue($txtCVEM)."','".$this->getCheckNullValue($txtNETHire)."','".$txtExchangeCurrency."','".$this->getCheckNullValue($txtExchangeRate)."', '".$txtTCCPDate."', '".$txtTCDeliveryPort."', '".$txtTCReDeliveryPort."', '".$this->getCheckNullValue($txtTCOffHireCVE)."', '".$this->getCheckNullValue($txtTCOffHireCVEAMT)."', '".$this->getCheckNullValue($txtTCBunkerOnOwnerAmt)."', '".$this->getCheckNullValue($txtTCLessOffHire)."', '".$this->getCheckNullValue($txtFinalHireargeAmt)."', '".$selTCVendor."', '".$txtTCCPNumber."')";
		
		mysql_query($sql1) or die($sql1);
	    mysql_query("commit");
		
		$mysql = "select max(TC_SLAVE1ID) as max from chartering_tc_estimate_slave1 where TCOUTID='".$mainid."'";
		$myres  =  mysql_query($mysql,$connect);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
		
	}
	else
	{
		$rows2 = mysql_fetch_assoc($res2);
	    $maxid = $rows2['TC_SLAVE1ID'];
		
		$sql1 = "update chartering_tc_estimate_slave1 set TRIP_TC_EST='".$txtTripTC1."', PERIOD_TC_EST='".$txtPeriod1."',  NO_OF_TRIP_EST='".$txtNoOfTrips1."', CP_DATE_EST='".$txtCPdate2."', CP_TYPE_EST='".$this->getCheckNullValue($txtCPType)."', CHARTERERS_EST='".$this->getCheckNullValue($txtCharterers)."', DEL_DATE_EST='".$txtDeldate."', DEL_HFO_MT_EST='".$this->getCheckNullValue($txtDelHFOmt)."', DEL_HFO_USD_EST='".$this->getCheckNullValue($txtDelHFOusdmt)."', DEL_MGO_MT_EST='".$this->getCheckNullValue($txtDelMGOmt)."', DEL_MGO_USD_EST='".$this->getCheckNullValue($txtDelMGOusdmt)."', REDEL_DATE_EST='".$txtReDeldate."', REDEL_HFO_MT_EST='".$this->getCheckNullValue($txtReDelHFOmt)."', REDEL_HFO_USD_EST='".$this->getCheckNullValue($txtReDelHFOusdmt)."', REDEL_MGO_MT_EST='".$this->getCheckNullValue($txtReDelMGOmt)."', REDEL_MGO_USD_EST='".$this->getCheckNullValue($txtReDelMGOusdmt)."', TC_DAYS_EST='".$this->getCheckNullValue($txtTCdays)."', UTILISATION_DAY_EST='".$this->getCheckNullValue($txtUtilisationDays)."', DAILY_GROSS_HIRE_EST='".$this->getCheckNullValue($txtDailyGrossHireUSD)."', ADD_COMM_EST='".$this->getCheckNullValue($txtAddCommPerct)."', ADD_COMM_CAL_EST='".$this->getCheckNullValue($txtAddComm1)."', BROKER_COMM_EST='".$this->getCheckNullValue($txtChartererAcc)."', BROKER_COMM_CAL_EST='".$this->getCheckNullValue($txtBrokerComm)."', NETT_HIRE_EST='".$this->getCheckNullValue($txtNettHire)."', NETT_REV_EST='".$this->getCheckNullValue($txtNettRev)."', LESS_OFF_HIRE_EST='".$this->getCheckNullValue($txtLessOffHire)."', CVE_EST='".$this->getCheckNullValue($txtCVE)."', OTHER_INCOME_EST='".$this->getCheckNullValue($txtOtherIncome)."', TOTAL_REV_EST='".$this->getCheckNullValue($txtTotalRev)."', TOTAL_EXP_EST='".$this->getCheckNullValue($txtTotalExpenses)."', VOYAGE_EARN_EST='".$this->getCheckNullValue($txtVoyageEarnings)."', PROFIT_PER_DAY_EST='".$this->getCheckNullValue($txtProfitPerDay)."', UPDATE_ON_DATE=NOW(), DEL_HFO_AMT='".$this->getCheckNullValue($txtDelTotalHFOUSD)."', DEL_MDO_AMT='".$this->getCheckNullValue($txtDelTotalMDOUSD)."', REDEL_HFO_AMT='".$this->getCheckNullValue($txtReDelTotalHFOUSD)."', REDEL_MDO_AMT='".$this->getCheckNullValue($txtReDelTotalMDOUSD)."', BUNKER_DIFF_AMT='".$this->getCheckNullValue($txtBunkerDifference)."', RANDOMID='".$this->getCheckNullValue($randomid)."', TC_RATE='".$this->getCheckNullValue($txtTCPerDay)."', TOTAL_HIREAGE='".$this->getCheckNullValue($txtTotalHireage)."', ADD_COMM='".$this->getCheckNullValue($txtAddComm)."', ADD_COMM_AMT='".$this->getCheckNullValue($txtAddCommAmt)."', NET_HIREAGE='".$this->getCheckNullValue($txtNetHireage)."', NET_HIRE_AMT='".$this->getCheckNullValue($txtNETHire)."', EXCHANGE_CURRENCY='".$txtExchangeCurrency."', EXCHANGE_RATE='".$this->getCheckNullValue($txtExchangeRate)."', TC_CP_DATE='".$txtTCCPDate."', TC_PORT_DELIVERY='".$txtTCDeliveryPort."', TC_PORT_REDELIVERY='".$txtTCReDeliveryPort."', TC_CVE_MONTH_OFFHIRE='".$this->getCheckNullValue($txtTCOffHireCVE)."', TC_CVE_AMOUNT_OFFHIRE='".$this->getCheckNullValue($txtTCOffHireCVEAMT)."', TC_BUNKERS_ON_OWNER='".$this->getCheckNullValue($txtTCBunkerOnOwnerAmt)."', TC_OFF_HIRE='".$this->getCheckNullValue($txtTCLessOffHire)."', TC_FINAL_HIERAGE='".$this->getCheckNullValue($txtFinalHireargeAmt)."', TC_FINAL_HIERAGE_VENDOR='".$selTCVendor."', TC_CP_NUMBER='".$txtTCCPNumber."' WHERE TCOUTID='".$mainid."' and TC_SLAVE1ID='".$rows2['TC_SLAVE1ID']."'";
		
		mysql_query($sql1) or die($sql1);
	    mysql_query("commit");
	}
	
	$del_query = "delete from chartering_estimate_tc_slave2 where TC_SLAVE1ID='".$maxid."'";
	mysql_query($del_query);mysql_query("commit");
	
	$del_query1 = "delete from chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$maxid."'";
	mysql_query($del_query1);mysql_query("commit");
	
	$del_query = "delete from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$maxid."'";
	mysql_query($del_query);mysql_query("commit");
	
	$del_query3 = "delete from chartering_tc_estimate_slave3 where TC_SLAVE1ID='".$maxid."'";
	mysql_query($del_query3);mysql_query("commit");
	
	$del_query4 = "delete from chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$maxid."'";
	mysql_query($del_query4);mysql_query("commit");
	
	$del_query5 = "delete from chartering_tc_estimate_slave5 where TC_SLAVE1ID='".$maxid."'";
	mysql_query($del_query5);mysql_query("commit");
	
	$del_query2 = "delete from chartering_tc_estimate_slave2 where TC_SLAVE1ID='".$maxid."'";
	mysql_query($del_query2);mysql_query("commit");
    
	
	$hddnOtherID = $_REQUEST['hddnOtherID'];
	for($i=1 ; $i<=$hddnOtherID ;$i++)
	{
		if($_REQUEST['txtOtherIncome_'.$i] != "")
		{
			$sql3 = "insert into chartering_estimate_tc_slave2 (TC_SLAVE1ID, DESCRIPTION, OTHER_AMT, STATUS) values ('".$maxid."', '".$_REQUEST['txtOtherIncomeText_'.$i]."', '".$this->getCheckNullValue($_REQUEST['txtOtherIncome_'.$i])."', 1)";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	} 
	
	$hddnOtherExID = $_REQUEST['hddnOtherExID'];
	for($i=1 ; $i<=$hddnOtherExID ;$i++)
	{
		if($_REQUEST['txtOtherExpense_'.$i] != "")
		{
			if(isset($_REQUEST['ChkAddToTTL_'.$i])){$ChkAddToTTL = $_REQUEST['ChkAddToTTL_'.$i]; }else{$ChkAddToTTL = 0;}
			
			$sql3 = "insert into chartering_estimate_tc_slave2 (TC_SLAVE1ID, EXPENSETYPEID, DESCRIPTION, CHK_ADDTTL, OTHER_AMT, STATUS) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selExpenseType_'.$i])."', '".addslashes(trim($_REQUEST['txtExpenseDesc_'.$i]))."', '".$ChkAddToTTL."', '".$this->getCheckNullValue($_REQUEST['txtOtherExpense_'.$i])."', 2)";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	} 
	
	$txtOFFID = $_REQUEST['txtOFFID'];
	for($i=1 ; $i<=$txtOFFID ;$i++)
	{
		if($_REQUEST['txtOffHireReason_'.$i] != "")
		{
			if($_REQUEST['txtOffHireFrom_'.$i]!="")
			{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
			else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
			
			if($_REQUEST['txtOffHireTo_'.$i]!="")
			{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
			else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
			$sql3 = "insert into chartering_estimate_tc_slave3 (TC_SLAVE1ID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE) values ('".$maxid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	} 
	
	$txtDELID = $_REQUEST['txtDELID'];
	for($j=1 ; $j<=$txtDELID ;$j++)
	{
		if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
		{
			if($_REQUEST['txtDelBunDate_'.$j]!="")
			{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
			else{$txtDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into chartering_estimate_tc_slave5 (TC_SLAVE1ID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtREDELID = $_REQUEST['txtREDELID'];
	for($j=1 ; $j<=$txtREDELID ;$j++)
	{
		if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
		{
			if($_REQUEST['txtReDelBunDate_'.$j]!="")
			{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
			else{$txtReDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into chartering_estimate_tc_slave5 (TC_SLAVE1ID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	//-------------------------------------------------------------
	
	$txtTCDELID = $_REQUEST['txtTCDELID'];
	for($k=1 ; $k<=$txtTCDELID ;$k++)
	{
		if(isset($_REQUEST['selTCDelBunker_'.$k]))
		{
			if($_REQUEST['selTCDelBunker_'.$k] != "" && $_REQUEST['txtTCDelQty_'.$k] != "" && $_REQUEST['txtTCDelAmount_'.$k] != "")
			{
				if($_REQUEST['txtTCDelBunDate_'.$k]!="")
				{$txtTCDelBunDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCDelBunDate_'.$k]));}
				else{$txtTCDelBunDate  		= "1970-01-01";}
				
				$sql4 = "insert into chartering_tc_estimate_slave3 (TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_DATE, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCDelBunker_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCDelQty_'.$k])."', '".$txtTCDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtTCDelPrice_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCDelAmount_'.$k])."', 'DEL')";
				mysql_query($sql4) or die($sql4);
				mysql_query("commit");
			}
		}
	}
	
	$txtTCREDELID = $_REQUEST['txtTCREDELID'];
	for($k=1 ; $k<=$txtTCREDELID ;$k++)
	{
		if(isset($_REQUEST['selTCReDelBunker_'.$k]))
		{
			if($_REQUEST['selTCReDelBunker_'.$k] != "" && $_REQUEST['txtTCReDelQty_'.$k] != "" && $_REQUEST['txtTCReDelAmount_'.$k] != "")
			{
				if($_REQUEST['txtTCReDelBunDate_'.$k]!="")
				{$txtTCReDelBunDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCReDelBunDate_'.$k]));}
				else{$txtTCReDelBunDate  		= "1970-01-01";}
				
				$sql5 = "insert into chartering_tc_estimate_slave3 (TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_DATE, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCReDelBunker_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelQty_'.$k])."', '".$txtTCReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelPrice_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelAmount_'.$k])."', 'REDEL')";
				mysql_query($sql5) or die($sql5);
				mysql_query("commit");
			}
		}
	}
	
	
	$txtTCOFFID = $_REQUEST['txtTCOFFID'];
	for($k=1 ; $k<=$txtTCOFFID ;$k++)
	{
		if(isset($_REQUEST['txtTCOffHireReason_'.$k]))
		{
			if($_REQUEST['txtTCOffHireReason_'.$k] != "" && $_REQUEST['txtTCReDelQty_'.$k] != "" && $_REQUEST['txtTCDelAmount_'.$k] != "")
			{
				if($_REQUEST['txtTCOffHireFrom_'.$k]!="")
				{$txtTCOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCOffHireFrom_'.$k]));}
				else{$txtTCOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtTCOffHireTo_'.$k]!="")
				{$txtTCOffHireTo	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCOffHireTo_'.$k]));}
				else{$txtTCOffHireTo  		= "1970-01-01 08:00:00";}
				
				$randomid = $_REQUEST['txtTCOffHireRandomID_'.$k];
				if(!isset($_REQUEST['txtTCOffHireRandomID_'.$k]) || $_REQUEST['txtTCOffHireRandomID_'.$k]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				
				$sql6 = "insert into chartering_tc_estimate_slave4 (TC_SLAVE1ID, OFFHIRE_REASON, OFF_HIRE_FROM, OFF_HIRE_TO, OFF_HIRE_DAYS, OFF_HIRE_RATE, OF_HIRE_AMT, RANDOMID) values ('".$maxid."', '".addslashes(trim($_REQUEST['txtTCOffHireReason_'.$k]))."', '".$txtTCOffHireFrom."', '".$txtTCOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireDays_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireRate_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireAmt_'.$k])."', '".$randomid."')";
				mysql_query($sql6) or die($sql6);
				mysql_query("commit");
				
				$mysqlmax4 = "select max(TC_SLAVE4ID) as max from chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$maxid."'";
				$myresmax4  =  mysql_query($mysqlmax4);
				$myrowsmax4 = mysql_fetch_assoc($myresmax4);
				$mslave4id = $myrowsmax4['max'];
				

				$txtTCConBunkerCount = $_REQUEST['txtTCConBunkerCount_'.$k];
				for($l=1 ; $l<=$txtTCConBunkerCount;$l++)
				{
					if(isset($_REQUEST['selTCConBunker_'.$k.'_'.$l]))
					{
						if($_REQUEST['selTCConBunker_'.$k.'_'.$l] != "" && $_REQUEST['txtTCConBunkerQty_'.$k.'_'.$l] != "" && $_REQUEST['txtTCConBunkerAmt_'.$k.'_'.$l] != "")
						{   
							if(isset($_REQUEST['ChkOFFHireCal_'.$k.'_'.$l])){$ChkOFFHireCal = $_REQUEST['ChkOFFHireCal_'.$k.'_'.$l];}
							else{$ChkOFFHireCal  = 0;}
							$sql7 = "insert into chartering_tc_estimate_slave5 (TC_SLAVE4ID, TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IS_OWNER_ACCOUNT) values ('".$mslave4id."', '".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$k.'_'.$l])."', '".$this->getCheckNullValue($ChkOFFHireCal)."')";
							mysql_query($sql7) or die($sql7);
							mysql_query("commit");
						}
					}
				}
			}
		}
	}
	
	$txtTCHOSTID = $_REQUEST['txtTCHOSTID'];
	
	for($j=1 ; $j<=$txtTCHOSTID ;$j++)
	{
		if($_REQUEST['txtTCDeliveryDate_'.$j] != "" && $_REQUEST['txtTCReDeliveryDate_'.$j] != "")
		{
			if($_REQUEST['txtTCDeliveryDate_'.$j]!="")
			{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate_'.$j]));}
			else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
			
			if($_REQUEST['txtTCReDeliveryDate_'.$j]!="")
			{$txtTCReDeliveryDate 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate_'.$j]));}
			else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
			
			$randomid = $_REQUEST['txtTCINSlaveRandomID_'.$j];
			if(!isset($_REQUEST['txtTCINSlaveRandomID_'.$j]) || $_REQUEST['txtTCINSlaveRandomID_'.$j]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			
			$sql3 = "insert into chartering_tc_estimate_slave2 (TC_SLAVE1ID, RANDOMID, TC_DELIVERY_DATE, TC_REDELIVERY_DATE, TC_RATE, TD_DAYS, HIERAGE, BALLAST_BONUS, GROSS_HIERAGE, ADD_COMM, ADD_COMM_AMT, ADD_COMM_VENDOR, BROKERAGE_COMM, BROKERAGE_COMM_AMT, BRO_COMM_VENDOR, NET_HIERAGE, CVE_MONTH, CVE_AMOUNT) values ('".$maxid."', '".$randomid."', '".$txtTCDeliveryDate."', '".$txtTCReDeliveryDate."', '".$this->getCheckNullValue($_REQUEST['txtTCinDailyHire_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTotalVoyageDays_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeAmt_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtBallastBonus_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtGrossHireargeAmt_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargePercent_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargePercentAmt_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selTCAddCoVendor_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeBroPercent_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeBroPercentAmt_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selTCBroComVendor_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtNettHireargeAmt_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTCHireargeCVE_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTCHireargeCVEAMT_'.$j])."')";
			
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");	
		}
	}
	return $msg; 
}


function displayFinalisedVoyageFixturesTCList()
{
	$this->funConnect();
	$sql1 = "select * from chartering_estimate_tc_compare WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FINAL_ID!=''  ";
	$res1 = mysql_query($sql1);
	$arr = array();
	while($row1 = mysql_fetch_assoc($res1))
	{
		$arr[] = $row1['FINAL_ID'];
	}
	$arr1 = implode(',',$arr);
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="fce_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="12%">Vessel</th>';
	echo '<th align="left" valign="middle" width="10%">Vessel Type</th>';
	echo '<th align="left" valign="middle" width="10%">TC No.</th>';
	echo '<th align="left" valign="middle" width="10%">CP Date</th>';
	echo '<th align="left" valign="middle" width="10%">DWT</th>';
	echo '<th align="left" valign="middle" width="10%">Del Port</th>';
	echo '<th align="left" valign="middle" width="6%">Re Del Port</th>';
	echo '<th align="left" valign="middle" width="10%">TC Days</th>';
	echo '<th align="left" valign="middle" width="5%">Daily Gross Hire(USD)</th>';
	echo '<th align="left" valign="middle" width="5%">Total Rev(USD)</th>';
	echo '<th align="left" valign="middle" width="5%">Status</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody id="tbody">';
	
	$sql = "SELECT TCOUTID, chartering_estimate_tc_master.VESSEL_TYPE, chartering_estimate_tc_master.FIXED, chartering_estimate_tc_master.EXCHANGE_RATE, vessel_imo_master.VESSEL_NAME, (select SUM(TC_DAYS_EST) as SUM from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID) as TC_DAYS_EST, (select SUM(TOTAL_REV_EST) as SUM from chartering_tc_estimate_slave1 where chartering_tc_estimate_slave1.TCOUTID= chartering_estimate_tc_master.TCOUTID) as TOTAL_REV_EST, vessel_imo_master.VESSEL_IMO_ID, TC_NO, SEL_CP_TYPE, CP_DATE1, FUEL_SPECS, MASTERS_NAME, DWT_SUMMER_CP, DEL_RANGE_PORT, RE_DEL_RANGE, HIRE_FIX_PER FROM chartering_estimate_tc_master inner JOIN vessel_imo_master ON vessel_imo_master.VESSEL_IMO_ID=chartering_estimate_tc_master.VESSEL_IMO_ID WHERE MODULEID='".$_SESSION['moduleid']."' AND chartering_estimate_tc_master.MCOMPANYID='".$_SESSION['company']."' and TCOUTID in (".$arr1.") order by TCOUTID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
		while($rows = mysql_fetch_assoc($res))
		{
			$sql2 = "select * from chartering_estimate_tc_compare WHERE TCOUTID='".$rows['TCOUTID']."' ";
			$res2 = mysql_query($sql2);
			$row2 = mysql_fetch_assoc($res2);
			if($rows['FIXED']==1){$fixed = "Finalised";}else{$fixed = "Not Fixed";}
			if($rows['EXCHANGE_RATE']>0 || $rows['EXCHANGE_RATE']<0){$exchangerate = $rows['EXCHANGE_RATE'];}else{$exchangerate = 1;}
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TC_NO'].'</td>';
			if($rows['CP_DATE1']=="" || $rows['CP_DATE1']=="1970-01-01"){$CP_DATE1 = "";}else{$CP_DATE1 = date('d-m-Y',strtotime($rows['CP_DATE1']));}
			echo '<td align="left" valign="middle" class="input-text">'.$CP_DATE1.'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DWT_SUMMER_CP'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['DEL_RANGE_PORT'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['RE_DEL_RANGE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TC_DAYS_EST'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.number_format(($rows['HIRE_FIX_PER']*$exchangerate),2,'.','').'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['TOTAL_REV_EST'].'</td>';
			if($rows['FIXED']==1)
			{
			    echo '<td align="left" valign="middle" class="input-text"><strong>'.$fixed.'</strong></td>';
			}else
			{
			    echo '<td align="center" valign="middle" class="input-text"><input type="checkbox" name="chkFCA[]" id="chkFCA_'.$i.'" value="'.$rows['TCOUTID'].'" class="checkbox"/></td>';	
			}
			echo '<td align="center" valign="middle" class="input-text"><a href="viewtcestimate.php?id='.$rows['TCOUTID'].'" title="View Details"><strong><i class="fa fa-file"></i></strong></a></td>';
			echo '</tr>';
			$i++;
		}
	}
	echo '</tbody>';
	echo '</table></div>';
}

function fixfinalisedfixturesheettc()
{
	$connect				= $this->funConnect();
 	$chkFCA      		    = implode(',',$_REQUEST['chkFCA']);
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	$sql = "update chartering_estimate_tc_master set FIXED='1', FINAL_DATETIME=NOW(), FINAL_STATUS=1 where TCOUTID in (".$chkFCA.")"; 
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	return $msg;
}

function getEstimateDatatc($id,$sheetid)
{
	$connect = $this->funConnect();
	$sql     = "select FINAL_STATUS from chartering_estimate_tc_master where MODULEID='".$_SESSION['moduleid']."' and TCOUTID='".$id."' and SHEET_NO='".$sheetid."'";
	$res 	 = mysql_query($sql);
	$num  	 = mysql_num_rows($res);
	if($num>0)
	{
		$rows 	 = mysql_fetch_assoc($res);
		return $rows['FINAL_STATUS'];
	}
	else
	{
		return 0;
	}
}


function getLatestSheetIDTC($comid)
{
	$connect = $this->funConnect();
	$sql 	 = "select COST_SHEETID from cost_sheettc_name_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' order by COST_SHEETID desc";
	$res 	 = mysql_query($sql);
	$num  	 = mysql_num_rows($res);
	if($num>0)
	{
	$rows  	 = mysql_fetch_assoc($res);
	return $rows['COST_SHEETID'];
	}
	else
	{
		return 0;
	}
}


function insertActualCostSheetNametc()
{
	$connect 	= $this->funConnect();
	$file_name  = $_REQUEST['txtFile'];
	$comid  = $_REQUEST['txtComid1'];
		
	$msg = 4;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "insert into cost_sheettc_name_master (SHEET_NAME, COMID, MODULEID, MCOMPANYID, PROCESS) values ('".$file_name."', '".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'Actual')";
	mysql_query($sql1);
	mysql_query("commit");
	return $msg; 
}

function getTCCostSheetStatusDetails($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select FINAL_STATUS from chartering_estimate_tc_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and SHEET_NO='".$cost_sheet_id."'";	
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['FINAL_STATUS'];
}

function getTCCostSheetID($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select * from chartering_estimate_tc_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and SHEET_NO='".$cost_sheet_id."'";	
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['TCOUTID'];
}

function getTCCostSheetRecDetails($comid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select * from chartering_estimate_tc_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and SHEET_NO='".$cost_sheet_id."'";	
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	return $rec;
}


function insertTCCostSheetDetails()
{	
	$connect = $this->funConnect(); 
	
	/*-------------------------\\\\\\-----START TC ESTIMATE------------/////////--------------------------------------*/
	$cost_sheet_id              = $_REQUEST['cost_sheet_id'];
	$comid                      = $_REQUEST['comid'];
	$txtTotalUdays				= addslashes(trim($_REQUEST['txtTotalUdays']));
	$txtTotalVoyageEarning		= addslashes(trim($_REQUEST['txtTotalVoyageEarning']));
	$txtTripTC   				= addslashes(trim($_REQUEST['txtTripTC']));
	$txtPeriod          		= addslashes(trim($_REQUEST['txtPeriod']));
	$txtNoOfTrips       		= addslashes(trim($_REQUEST['txtNoOfTrips']));
	$selPeriodContract          = addslashes(trim($_REQUEST['selPeriodContract']));
	$update_status              = addslashes(trim($_REQUEST['update_status']));
	
	/*-----------ENDD---------\\\\\\-----COMMERCIAL PARAMETERS DATA-----/////////--------------------------------*/
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$mysqlprev  = "select * from chartering_estimate_tc_master where COMID='".$comid."' order by TCOUTID DESC";
	$myresprev  =  mysql_query($mysqlprev,$connect);
	$myrowsprev = mysql_fetch_assoc($myresprev);
	
	$sql = "insert into chartering_estimate_tc_master (MODULEID, MCOMPANYID, FIXTURE_TYPE, VESSEL_IMO_ID, VESSEL_TYPE, FLAG, TC_DATE, TC_NO, CP_DATE1, SEL_CP_TYPE, SEL_CHARTERER, SEL_CHAR_OPER, LAW_ARBITRA, CHAR_OPER_ADD, BUILD_YARD, BUILT_YEAR1, FLAG_1, PORT_OF_REG, IMO_NO, CLASS_ID, LAST_SP_SURVEY, LAST_DD, OWNERS_PI, MASTERS_NAME, CALL_SIGN, INMARSAT_TEL, INMARSAT_MAIL, LOA1, BREADTH, SUMMER_DWT, SUMMER_DRAFT, TPC1, GROSS_TONN, NET_TONN, CARGO_TANK_CAP, NO_OF_GRADES, CARGO_PUMP_CAP, TOTAL_SBT_CAP, SUEZ_GRT, SUEZ_NRT, PANAMA_NRT, GRAIN_CAP1, BALE_CAP1, CRANES, GRABS, KEEL_TOP_MAST, WTR_TOP_MAST_FB, DEL_RANGE_PORT, DUR_FIX_PER, TRIP_TC, PERIOD, NO_OF_TRIP, DEL_DATE, RE_DEL_DATE, DUR_OPT_PER, COMM_OPT_PER, LAYCAN_FROM, LAYCAN_TO, LAYCAN_NARR, RE_DEL_RANGE, HIRE_FIX_PER, HIRE_OPT_PER, DEL_HFO, DEL_MGO, RE_DEL_HFO, RE_DEL_MGO, PRICE_DEL_HFO, PRICE_DEL_MGO, PR_REDEL_HFO, PR_REDEL_MGO, FUEL_SPECS, CVE_MONTH, TANK_CLEAN_EXP, ADD_EXP_LINE_ITEM, SUP_CARGO_MEAL, HOLD_CLEAN_INTER, ILOHC_USD, ILOHC_REMARKS, BRO_COMM_PAYABLE, ADD_COMM, BROKER_COMM, OWNERS_BANK_DET, DOC_CREAT_BY, ADDIT_INFORM, COMID, UPDATE_ON_DATE, DWT_SUMMER_CP, DWT_TROPICAL_CP, GRAIN_CAP_CP, BALE_CAP_CP, SF_CP, LOADABLE_CP, GRT_NRT_CP, LOA_CP, GEAR_CP, BUILT_YEAR_CP, BEAM_CP, TPC_CP, B_FULL_SPEED_CP, B_ECO_SPEED1_CP, B_ECO_SPEED2_CP, L_FULL_SPEED_CP, L_ECO_SPEED1_CP, L_ECO_SPEED2_CP, B_PASS_FULL_CP, B_PASS_ECO1_CP, B_PASS_ECO2_CP, L_PASS_FULL_CP, L_PASS_ECO1_CP, L_PASS_ECO2_CP, INPORT_IDLE_CP, INPORT_WORK_CP, BP_FUL_SPEED_CP, BP_ECO_SPEED1_CP, BP_ECO_SPEED2_CP, LP_FUL_SPEED_CP, LP_ECO_SPEED1_CP, LP_ECO_SPEED2_CP, INPORT_IDLE1_CP, INPORT_WORK1_CP, FINAL_DATETIME, FINAL_STATUS, FIXED, ESTIMATE_TYPE, SHEET_NO, TOTAL_DAYS, TOTAL_EARNING, WIND_FORCE_TCCP, SPD_LADEN_TCCP, SPD_BLST_TCCP,	CP_SPD_TCCP, FO_CONS_LDN_TCCP, DO_CONS_LDN_TCCP, FO_CONS_BLST_TCCP, DO_CONS_BLST_TCCP, FO_CONS_LDN2_TCCP, DO_CONS_LDN2_TCCP, FO_CONS_DISH_TCCP, DO_CONS_DISH_TCCP, FO_CONS_IDLE_TCCP, DO_CONS_IDLE_TCCP, LODE_RATE_TCCP, DISH_RATE_TCCP) values ('".$myrowsprev['MODULEID']."', '".$myrowsprev['MCOMPANYID']."', '".$myrowsprev['FIXTURE_TYPE']."', '".$myrowsprev['VESSEL_IMO_ID']."', '".$myrowsprev['VESSEL_TYPE']."', '".$myrowsprev['FLAG']."', '".$myrowsprev['TC_DATE']."', '".$myrowsprev['TC_NO']."', '".$myrowsprev['CP_DATE1']."', '".addslashes($myrowsprev['SEL_CP_TYPE'])."', '".addslashes($myrowsprev['SEL_CHARTERER'])."', '".addslashes($myrowsprev['SEL_CHAR_OPER'])."', '".addslashes($myrowsprev['LAW_ARBITRA'])."', '".addslashes($myrowsprev['CHAR_OPER_ADD'])."', '".addslashes($myrowsprev['BUILD_YARD'])."', '".addslashes($myrowsprev['BUILT_YEAR1'])."', '".addslashes($myrowsprev['FLAG_1'])."', '".addslashes($myrowsprev['PORT_OF_REG'])."', '".addslashes($myrowsprev['IMO_NO'])."', '".addslashes($myrowsprev['CLASS_ID'])."', '".addslashes($myrowsprev['LAST_SP_SURVEY'])."', '".addslashes($myrowsprev['LAST_DD'])."', '".addslashes($myrowsprev['OWNERS_PI'])."', '".addslashes($myrowsprev['MASTERS_NAME'])."', '".addslashes($myrowsprev['CALL_SIGN'])."', '".addslashes($myrowsprev['INMARSAT_TEL'])."', '".addslashes($myrowsprev['INMARSAT_MAIL'])."', '".addslashes($myrowsprev['LOA1'])."', '".addslashes($myrowsprev['BREADTH'])."', '".addslashes($myrowsprev['SUMMER_DWT'])."', '".addslashes($myrowsprev['SUMMER_DRAFT'])."', '".addslashes($myrowsprev['TPC1'])."', '".addslashes($myrowsprev['GROSS_TONN'])."', '".addslashes($myrowsprev['NET_TONN'])."', '".addslashes($myrowsprev['CARGO_TANK_CAP'])."', '".addslashes($myrowsprev['NO_OF_GRADES'])."', '".addslashes($myrowsprev['CARGO_PUMP_CAP'])."', '".addslashes($myrowsprev['TOTAL_SBT_CAP'])."', '".addslashes($myrowsprev['SUEZ_GRT'])."', '".addslashes($myrowsprev['SUEZ_NRT'])."', '".addslashes($myrowsprev['PANAMA_NRT'])."', '".addslashes($myrowsprev['GRAIN_CAP1'])."', '".addslashes($myrowsprev['BALE_CAP1'])."', '".addslashes($myrowsprev['CRANES'])."', '".addslashes($myrowsprev['GRABS'])."', '".addslashes($myrowsprev['KEEL_TOP_MAST'])."', '".addslashes($myrowsprev['WTR_TOP_MAST_FB'])."', '".addslashes($myrowsprev['DEL_RANGE_PORT'])."', '".addslashes($myrowsprev['DUR_FIX_PER'])."', '".addslashes($txtTripTC)."', '".addslashes($txtPeriod)."', '".addslashes($txtNoOfTrips)."', '".addslashes($myrowsprev['DEL_DATE'])."', '".addslashes($myrowsprev['RE_DEL_DATE'])."', '".addslashes($myrowsprev['DUR_OPT_PER'])."', '".addslashes($myrowsprev['COMM_OPT_PER'])."', '".addslashes($myrowsprev['LAYCAN_FROM'])."', '".addslashes($myrowsprev['LAYCAN_TO'])."', '".addslashes($myrowsprev['LAYCAN_NARR'])."', '".addslashes($myrowsprev['RE_DEL_RANGE'])."', '".addslashes($myrowsprev['HIRE_FIX_PER'])."', '".addslashes($this->getCheckNullValue($myrowsprev['HIRE_OPT_PER']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DEL_HFO']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DEL_MGO']))."', '".addslashes($this->getCheckNullValue($myrowsprev['RE_DEL_HFO']))."', '".addslashes($this->getCheckNullValue($myrowsprev['RE_DEL_MGO']))."', '".addslashes($this->getCheckNullValue($myrowsprev['PRICE_DEL_HFO']))."', '".addslashes($this->getCheckNullValue($myrowsprev['PRICE_DEL_MGO']))."', '".addslashes($this->getCheckNullValue($myrowsprev['PR_REDEL_HFO']))."', '".addslashes($this->getCheckNullValue($myrowsprev['PR_REDEL_MGO']))."', '".addslashes($myrowsprev['FUEL_SPECS'])."', '".addslashes($this->getCheckNullValue($myrowsprev['CVE_MONTH']))."', '".addslashes($this->getCheckNullValue($myrowsprev['TANK_CLEAN_EXP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['ADD_EXP_LINE_ITEM']))."', '".addslashes($this->getCheckNullValue($myrowsprev['SUP_CARGO_MEAL']))."', '".addslashes($myrowsprev['HOLD_CLEAN_INTER'])."', '".addslashes($this->getCheckNullValue($myrowsprev['ILOHC_USD']))."', '".addslashes($myrowsprev['ILOHC_REMARKS'])."', '".addslashes($myrowsprev['BRO_COMM_PAYABLE'])."', '".addslashes($myrowsprev['ADD_COMM'])."', '".addslashes($this->getCheckNullValue($myrowsprev['BROKER_COMM']))."', '".addslashes($myrowsprev['OWNERS_BANK_DET'])."', '".addslashes($myrowsprev['DOC_CREAT_BY'])."', '".addslashes($myrowsprev['ADDIT_INFORM'])."', '".addslashes($this->getCheckNullValue($myrowsprev['COMID']))."', '".addslashes($myrowsprev['UPDATE_ON_DATE'])."', '".addslashes($this->getCheckNullValue($myrowsprev['DWT_SUMMER_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DWT_TROPICAL_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['GRAIN_CAP_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['BALE_CAP_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['SF_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['LOADABLE_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['GRT_NRT_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['LOA_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['GEAR_CP']))."', '".addslashes($myrowsprev['BUILT_YEAR_CP'])."', '".addslashes($myrowsprev['BEAM_CP'])."', '".addslashes($this->getCheckNullValue($myrowsprev['TPC_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['B_FULL_SPEED_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['B_ECO_SPEED1_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['B_ECO_SPEED2_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['L_FULL_SPEED_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['L_ECO_SPEED1_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['L_ECO_SPEED2_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['B_PASS_FULL_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['B_PASS_ECO1_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['B_PASS_ECO2_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['L_PASS_FULL_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['L_PASS_ECO1_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['L_PASS_ECO2_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['INPORT_IDLE_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['INPORT_WORK_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['BP_FUL_SPEED_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['BP_ECO_SPEED1_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['BP_ECO_SPEED2_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['LP_FUL_SPEED_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['LP_ECO_SPEED1_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['LP_ECO_SPEED2_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['INPORT_IDLE1_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['INPORT_WORK1_CP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['FINAL_DATETIME']))."', '".addslashes($update_status)."', 1, '".addslashes($myrowsprev['ESTIMATE_TYPE'])."', '".addslashes($cost_sheet_id)."','".addslashes($this->getCheckNullValue($txtTotalUdays))."','".addslashes($this->getCheckNullValue($txtTotalVoyageEarning))."', '".addslashes($this->getCheckNullValue($myrowsprev['WIND_FORCE_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['SPD_LADEN_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['SPD_BLST_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['CP_SPD_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['FO_CONS_LDN_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DO_CONS_LDN_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['FO_CONS_BLST_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DO_CONS_BLST_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['FO_CONS_LDN2_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DO_CONS_LDN2_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['FO_CONS_DISH_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DO_CONS_DISH_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['FO_CONS_IDLE_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DO_CONS_IDLE_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['LODE_RATE_TCCP']))."', '".addslashes($this->getCheckNullValue($myrowsprev['DISH_RATE_TCCP']))."')";
	mysql_query($sql) or die($sql);
	
	$sql_update = "update chartering_estimate_tc_master set PERIODID='".$this->getCheckNullValue($selPeriodContract)."' where COMID='".$comid."' ";
	mysql_query($sql_update) or die($sql_update);
	mysql_query("commit");
	
	$mysqlmax = "select max(TCOUTID) as max from chartering_estimate_tc_master";
	$myresmax  =  mysql_query($mysqlmax,$connect);
	$myrowsmax = mysql_fetch_assoc($myresmax);
	$maxid = $myrowsmax['max'];
	
	$mysqlm1 = "select * from chartering_estimate_tc_slave4 where TCOUTID= ".$myrowsprev['TCOUTID'];
	$myresm1  =  mysql_query($mysqlm1,$connect);
	while($myrowsm1 = mysql_fetch_assoc($myresm1))
	{
		$sql3 = "insert into chartering_estimate_tc_slave4 (TCOUTID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$myrowsm1['BUNKERID']."', '".$this->getCheckNullValue($myrowsm1['AMOUNT'])."', '".$myrowsm1['BUNKER_DATE']."', '".$this->getCheckNullValue($myrowsm1['QTY'])."', '".$this->getCheckNullValue($myrowsm1['PRICE'])."', '".$this->getCheckNullValue($myrowsm1['IDENTITY'])."')";
		mysql_query($sql3) or die($sql3);
		mysql_query("commit");
	} 
	
	
	$txtTripID                  = addslashes(trim($_REQUEST['txtTripID']));
	for($i =1;$i<=$txtTripID;$i++)
	{
		if(isset($_REQUEST['txtDeldate_'.$i]))
		{
			$txtTCdays					= addslashes(trim($_REQUEST['txtTCdays_'.$i]));
			$txtUtilisationDays			= addslashes(trim($_REQUEST['txtUtilisationDays_'.$i]));			
			$selExchangeCurrency		= addslashes(trim($_REQUEST['selExchangeCurrency_'.$i]));
			$txtExchangeRate			= addslashes(trim($_REQUEST['txtExchangeRate_'.$i]));
			$txtDailyGrossHireUSD		= addslashes(trim($_REQUEST['txtDailyGrossHireUSD_'.$i]));
			$txtBallastBonusAMT 		= addslashes(trim($_REQUEST['txtBallastBonusAMT_'.$i]));
			$txtAddCommPerct			= addslashes(trim($_REQUEST['txtAddCommPerct_'.$i]));
			$txtAddComm1				= addslashes(trim($_REQUEST['txtAddComm1_'.$i]));
			$txtChartererAcc			= addslashes(trim($_REQUEST['txtChartererAcc_'.$i]));
			$selAddCommVendor			= addslashes(trim($_REQUEST['selAddCommVendor_'.$i]));
			$txtBrokerComm				= addslashes(trim($_REQUEST['txtBrokerComm_'.$i]));
			$selBroCommVendor			= addslashes(trim($_REQUEST['selBroCommVendor_'.$i]));
			$txtNettHire				= addslashes(trim($_REQUEST['txtNettHire_'.$i]));
			$txtNettRev					= addslashes(trim($_REQUEST['txtNettRev_'.$i]));
			$txtLessOffHire				= addslashes(trim($_REQUEST['txtLessOffHire_'.$i]));
			$txtCVE						= addslashes(trim($_REQUEST['txtCVE_'.$i]));
			$txtOtherIncome				= addslashes(trim($_REQUEST['txtOtherIncome_'.$i]));
			$txtTotalRev	    		= addslashes(trim($_REQUEST['txtTotalRev_'.$i]));
			$selESTtcVendor	    		= addslashes(trim($_REQUEST['selESTtcVendor_'.$i]));
			
			$txtTotalExpenses			= addslashes(trim($_REQUEST['txtTotalExpenses_'.$i]));

			$txtVoyageEarnings			= addslashes(trim($_REQUEST['txtVoyageEarnings_'.$i]));
			$txtProfitPerDay			= addslashes(trim($_REQUEST['txtProfitPerDay_'.$i]));
			
			$txtTCPerDay    			= addslashes(trim($_REQUEST['txtTCPerDay_'.$i]));
			$txtTotalHireage			= addslashes(trim($_REQUEST['txtTotalHireage_'.$i]));
			$txtAddComm     			= addslashes(trim($_REQUEST['txtAddComm_'.$i]));
			$txtAddCommAmt   			= addslashes(trim($_REQUEST['txtAddCommAmt_'.$i]));
			$txtNetHireage  			= addslashes(trim($_REQUEST['txtNetHireage_'.$i]));
			$selTcInExpVendor  			= addslashes(trim($_REQUEST['selTcInExpVendor_'.$i]));
			$txtCVEM        			= addslashes(trim($_REQUEST['txtCVEM_'.$i]));
			$txtNETHire        			= addslashes(trim($_REQUEST['txtNETHire_'.$i]));
			
			if($_REQUEST['txtTCCPDate_'.$i]!="")
			{$txtTCCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCCPDate_'.$i]));}
			else{$txtTCCPDate  		= "1970-01-01";}
			$txtTCDeliveryPort        	= addslashes(trim($_REQUEST['txtTCDeliveryPort_'.$i]));
			$txtTCReDeliveryPort		= addslashes(trim($_REQUEST['txtTCReDeliveryPort_'.$i]));
			$txtTCOffHireCVE        	= addslashes(trim($_REQUEST['txtTCOffHireCVE_'.$i]));
			$txtTCOffHireCVEAMT			= addslashes(trim($_REQUEST['txtTCOffHireCVEAMT_'.$i]));
			$txtTCBunkerOnOwnerAmt      = addslashes(trim($_REQUEST['txtTCBunkerOnOwnerAmt_'.$i]));
			$txtTCLessOffHire  			= addslashes(trim($_REQUEST['txtTCLessOffHire_'.$i]));
			$txtFinalHireargeAmt		= addslashes(trim($_REQUEST['txtFinalHireargeAmt_'.$i]));
			$selTCVendor      			= addslashes(trim($_REQUEST['selTCVendor_'.$i]));
			$txtTCCPNumber     			= addslashes(trim($_REQUEST['txtTCCPNumber_'.$i]));
			
			if($_REQUEST['txtDeldate_'.$i]!="")
			{$txtDeldate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtDeldate_'.$i]));}
			else{$txtDeldate  		= "1970-01-01 08:00:00";}
			
			if($_REQUEST['txtReDeldate_'.$i]!="")
			{$txtReDeldate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtReDeldate_'.$i]));}
			else{$txtReDeldate  		= "1970-01-01 08:00:00";}
			
			$randomid = $_REQUEST['txtCOUTSlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtCOUTSlaveRandomID_'.$i]) || $_REQUEST['txtCOUTSlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			
			
			$sql1 = "insert into chartering_tc_estimate_slave1 (TCOUTID, TRIP_TC_EST, PERIOD_TC_EST, NO_OF_TRIP_EST, CP_TYPE_EST, CHARTERERS_EST, DEL_DATE_EST, REDEL_DATE_EST, TC_DAYS_EST, UTILISATION_DAY_EST, DAILY_GROSS_HIRE_EST, EXCHANGE_CURRENCY, EXCHANGE_RATE, ADD_COMM_EST, ADD_COMM_CAL_EST, ADD_COMM_VENDOR, BROKER_COMM_EST, BROKER_COMM_CAL_EST, BROKER_COMM_VENDOR, NETT_HIRE_EST, NETT_REV_EST, LESS_OFF_HIRE_EST, CVE_EST, OTHER_INCOME_EST, TOTAL_REV_EST, TTL_REV_VENDOR, TOTAL_EXP_EST, VOYAGE_EARN_EST, PROFIT_PER_DAY_EST, UPDATE_ON_DATE, BUNKER_DIFF_AMT, RANDOMID, TC_RATE, TOTAL_HIREAGE, ADD_COMM, ADD_COMM_AMT, NET_HIREAGE, NET_HIR_VENDOR, CVE_MONTH, NET_HIRE_AMT, TC_CP_DATE, TC_PORT_DELIVERY, TC_PORT_REDELIVERY, TC_CVE_MONTH_OFFHIRE, TC_CVE_AMOUNT_OFFHIRE, TC_BUNKERS_ON_OWNER, TC_OFF_HIRE, TC_FINAL_HIERAGE, TC_FINAL_HIERAGE_VENDOR, TC_CP_NUMBER, BALLAST_BONUS_AMT) values ('".$maxid."','".$txtTripTC1."','".$txtPeriod1."','".$this->getCheckNullValue($txtNoOfTrips1)."','".$this->getCheckNullValue($txtCPType)."','".$this->getCheckNullValue($txtCharterers)."','".$txtDeldate."','".$txtReDeldate."','".$this->getCheckNullValue($txtTCdays)."','".$this->getCheckNullValue($txtUtilisationDays)."','".$this->getCheckNullValue($txtDailyGrossHireUSD)."','".$this->getCheckNullValue($selExchangeCurrency)."','".$txtExchangeRate."','".$this->getCheckNullValue($txtAddCommPerct)."','".$this->getCheckNullValue($txtAddComm1)."','".$this->getCheckNullValue($selAddCommVendor)."','".$this->getCheckNullValue($txtChartererAcc)."','".$this->getCheckNullValue($txtBrokerComm)."','".$this->getCheckNullValue($selBroCommVendor)."','".$this->getCheckNullValue($txtNettHire)."','".$this->getCheckNullValue($txtNettRev)."','".$this->getCheckNullValue($txtLessOffHire)."','".$this->getCheckNullValue($txtCVE)."','".$this->getCheckNullValue($txtOtherIncome)."','".$this->getCheckNullValue($txtTotalRev)."','".$this->getCheckNullValue($selESTtcVendor)."','".$this->getCheckNullValue($txtTotalExpenses)."','".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtProfitPerDay)."',NOW(),'".$this->getCheckNullValue($txtBunkerDifference)."','".$this->getCheckNullValue($randomid)."','".$this->getCheckNullValue($txtTCPerDay)."','".$this->getCheckNullValue($txtTotalHireage)."','".$this->getCheckNullValue($txtAddComm)."','".$this->getCheckNullValue($txtAddCommAmt)."','".$this->getCheckNullValue($txtNetHireage)."', '".$this->getCheckNullValue($selTcInExpVendor)."', '".$this->getCheckNullValue($txtCVEM)."', '".$this->getCheckNullValue($txtNETHire)."', '".$txtTCCPDate."', '".$txtTCDeliveryPort."', '".$txtTCReDeliveryPort."', '".$this->getCheckNullValue($txtTCOffHireCVE)."', '".$this->getCheckNullValue($txtTCOffHireCVEAMT)."', '".$this->getCheckNullValue($txtTCBunkerOnOwnerAmt)."', '".$this->getCheckNullValue($txtTCLessOffHire)."', '".$this->getCheckNullValue($txtFinalHireargeAmt)."', '".$selTCVendor."', '".$txtTCCPNumber."', '".$this->getCheckNullValue($txtBallastBonusAMT)."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
			
			$mysql = "select max(TC_SLAVE1ID) as max from chartering_tc_estimate_slave1 where TCOUTID='".$maxid."'";
			$myres  =  mysql_query($mysql,$connect);
			$myrows = mysql_fetch_assoc($myres);
			$maxslaveid = $myrows['max'];
			
			
			$hddnOtherID = $_REQUEST['hddnOtherID_'.$i];
			for($j=1 ; $j<=$hddnOtherID ;$j++)
			{
				if($_REQUEST['txtOtherIncome_'.$i.'_'.$j] != "")
				{
					$sql3 = "insert into chartering_estimate_tc_slave2 (TC_SLAVE1ID, DESCRIPTION, OTHER_AMT, OTHER_EXP_VENDOR, STATUS) values ('".$maxslaveid."', '".$_REQUEST['txtOtherIncomeText_'.$i.'_'.$j]."', '".$this->getCheckNullValue($_REQUEST['txtOtherIncome_'.$i.'_'.$j])."', '".addslashes(trim($_REQUEST['selOthIncVendor_'.$i.'_'.$j]))."', 1)";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
				}
			} 
			
			$hddnOtherExID = $_REQUEST['hddnOtherExID_'.$i];
			for($j=1 ; $j<=$hddnOtherExID ;$j++)
			{
				if($_REQUEST['txtOtherExpense_'.$i.'_'.$j] != "")
				{
					if(isset($_REQUEST['ChkAddToTTL_'.$i.'_'.$j])){$ChkAddToTTL = $_REQUEST['ChkAddToTTL_'.$i.'_'.$j]; }else{$ChkAddToTTL = 0;}
					
					$sql3 = "insert into chartering_estimate_tc_slave2 (TC_SLAVE1ID, EXPENSETYPEID, DESCRIPTION, CHK_ADDTTL, OTHER_AMT, OTHER_EXP_VENDOR, STATUS) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selExpenseType_'.$i.'_'.$j])."', '".addslashes(trim($_REQUEST['txtExpenseDesc_'.$i.'_'.$j]))."', '".$ChkAddToTTL."', '".$this->getCheckNullValue($_REQUEST['txtOtherExpense_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selOthExpVendor_'.$i.'_'.$j])."', 2)";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
				}
			} 
			
			$txtOFFID = $_REQUEST['txtOFFID_'.$i];
			for($j=1 ; $j<=$txtOFFID ;$j++)
			{
				if($_REQUEST['txtOffHireReason_'.$i.'_'.$j] != "")
				{
					if($_REQUEST['txtOffHireFrom_'.$i.'_'.$j]!="")
					{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i.'_'.$j]));}
					else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtOffHireTo_'.$i.'_'.$j]!="")
					{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i.'_'.$j]));}
					else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
					$sql3 = "insert into chartering_estimate_tc_slave3 (TC_SLAVE1ID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE) values ('".$maxslaveid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i.'_'.$j])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i.'_'.$j])."')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
					
					$mysqlmax4 = "select max(TC_SLAVE3ID) as max from chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$maxslaveid."'";
					$myresmax4  =  mysql_query($mysqlmax4) or die($mysqlmax4);
					$myrowsmax4 = mysql_fetch_assoc($myresmax4);
					$mslave4id = $myrowsmax4['max'];
					
					$txtOFFConBunkerCount_ = $_REQUEST['txtOFFConBunkerCount_'.$i.'_'.$j];
					for($l=1 ; $l<=$txtOFFConBunkerCount_;$l++)
					{
						if(isset($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l]))
						{
							if($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l] != "" && $_REQUEST['txtConBunkerQty_'.$i.'_'.$j.'_'.$l] != "" && $_REQUEST['txtConBunkerAmt_'.$i.'_'.$j.'_'.$l] != "")
							{   
								$sql7 = "insert into chartering_estimate_tc_slave7 (TC_SLAVE3ID, TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT) values ('".$mslave4id."', '".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerQty_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerPrice_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerAmt_'.$i.'_'.$j.'_'.$l])."')";
								mysql_query($sql7) or die($sql7);
								mysql_query("commit");
							}
						}
					}
				}
			}
			
			$txtDELID = $_REQUEST['txtDELID_'.$i];
			for($j=1 ; $j<=$txtDELID ;$j++)
			{
				if($_REQUEST['selDelBunker_'.$i.'_'.$j] != "" && $_REQUEST['txtDelQty_'.$i.'_'.$j] != "")
				{
					if($_REQUEST['txtDelBunDate_'.$i.'_'.$j]!="")
					{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$i.'_'.$j]));}
					else{$txtDelBunDate    	= "1970-01-01";}
					$sql3 = "insert into chartering_estimate_tc_slave5 (TC_SLAVE1ID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$i.'_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$i.'_'.$j])."', 'DEL')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
				}
			}
			
			$txtREDELID = $_REQUEST['txtREDELID_'.$i];
			for($j=1 ; $j<=$txtREDELID ;$j++)
			{
				if($_REQUEST['selReDelBunker_'.$i.'_'.$j] != "" && $_REQUEST['txtReDelQty_'.$i.'_'.$j] != "")
				{
					if($_REQUEST['txtReDelBunDate_'.$i.'_'.$j]!="")
					{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$i.'_'.$j]));}
					else{$txtReDelBunDate    	= "1970-01-01";}
					$sql3 = "insert into chartering_estimate_tc_slave5 (TC_SLAVE1ID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$i.'_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$i.'_'.$j])."', 'REDEL')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
				}
			}
			
			
			$txtTCDELID = $_REQUEST['txtTCDELID_'.$i];
			for($k=1 ; $k<=$txtTCDELID ;$k++)
			{
				if(isset($_REQUEST['selTCDelBunker_'.$i.'_'.$k]))
				{
					if($_REQUEST['selTCDelBunker_'.$i.'_'.$k] != "" && $_REQUEST['txtTCDelQty_'.$i.'_'.$k] != "" && $_REQUEST['txtTCDelAmount_'.$i.'_'.$k] != "")
					{
						if($_REQUEST['txtTCDelBunDate_'.$i.'_'.$k]!="")
						{$txtTCDelBunDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCDelBunDate_'.$i.'_'.$k]));}
						else{$txtTCDelBunDate  		= "1970-01-01";}
						
						$sql4 = "insert into chartering_tc_estimate_slave3 (TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_DATE, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCDelBunker_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCDelQty_'.$i.'_'.$k])."', '".$txtTCDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtTCDelPrice_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCDelAmount_'.$i.'_'.$k])."', 'DEL')";
						mysql_query($sql4) or die($sql4);
						mysql_query("commit");
					}
				}
			}
			
			$txtTCREDELID = $_REQUEST['txtTCREDELID_'.$i];
			for($k=1 ; $k<=$txtTCREDELID ;$k++)
			{
				if(isset($_REQUEST['selTCReDelBunker_'.$i.'_'.$k]))
				{
					if($_REQUEST['selTCReDelBunker_'.$i.'_'.$k] != "" && $_REQUEST['txtTCReDelQty_'.$i.'_'.$k] != "" && $_REQUEST['txtTCReDelAmount_'.$i.'_'.$k] != "")
					{
						if($_REQUEST['txtTCReDelBunDate_'.$i.'_'.$k]!="")
						{$txtTCReDelBunDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCReDelBunDate_'.$i.'_'.$k]));}
						else{$txtTCReDelBunDate  		= "1970-01-01";}
						
						$sql5 = "insert into chartering_tc_estimate_slave3 (TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_DATE, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCReDelBunker_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelQty_'.$i.'_'.$k])."', '".$txtTCReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelPrice_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelAmount_'.$i.'_'.$k])."', 'REDEL')";
						mysql_query($sql5) or die($sql5);
						mysql_query("commit");
					}
				}
			}
			
			
			$txtTCOFFID = $_REQUEST['txtTCOFFID_'.$i];
			for($k=1 ; $k<=$txtTCOFFID ;$k++)
			{
				if(isset($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k]))
				{
					if($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k] != "" && $_REQUEST['txtTCOffHireFrom_'.$i.'_'.$k] != "" && $_REQUEST['txtTCOffHireTo_'.$i.'_'.$k] != "")
					{
						if($_REQUEST['txtTCOffHireFrom_'.$i.'_'.$k]!="")
						{$txtTCOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCOffHireFrom_'.$i.'_'.$k]));}
						else{$txtTCOffHireFrom  		= "1970-01-01 08:00:00";}
						
						if($_REQUEST['txtTCOffHireTo_'.$i.'_'.$k]!="")
						{$txtTCOffHireTo	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCOffHireTo_'.$i.'_'.$k]));}
						else{$txtTCOffHireTo  		= "1970-01-01 08:00:00";}
						
						$randomid = $_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k];
						if(!isset($_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k]) || $_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k]=='')
						{
							$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
						}
						
						$sql6 = "insert into chartering_tc_estimate_slave4 (TC_SLAVE1ID, OFFHIRE_REASON, OFF_HIRE_FROM, OFF_HIRE_TO, OFF_HIRE_DAYS, OFF_HIRE_RATE, OF_HIRE_AMT, RANDOMID) values ('".$maxslaveid."', '".addslashes(trim($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k]))."', '".$txtTCOffHireFrom."', '".$txtTCOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireDays_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireRate_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireAmt_'.$i.'_'.$k])."', '".$randomid."')";
						mysql_query($sql6) or die($sql6);
						mysql_query("commit");
						
						$mysqlmax4 = "select max(TC_SLAVE4ID) as max from chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$maxslaveid."'";
						$myresmax4  =  mysql_query($mysqlmax4);
						$myrowsmax4 = mysql_fetch_assoc($myresmax4);
						$mslave4id = $myrowsmax4['max'];
						

						$txtTCConBunkerCount = $_REQUEST['txtTCConBunkerCount_'.$i.'_'.$k];
						for($l=1 ; $l<=$txtTCConBunkerCount;$l++)
						{
							if(isset($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l]))
							{
								if($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l] != "" && $_REQUEST['txtTCConBunkerQty_'.$i.'_'.$k.'_'.$l] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$k.'_'.$l] != "")
								{   
									if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$k.'_'.$l])){$ChkOFFHireCal = $_REQUEST['ChkOFFHireCal_'.$i.'_'.$k.'_'.$l];}
									else{$ChkOFFHireCal  = 0;}
									$sql7 = "insert into chartering_tc_estimate_slave5 (TC_SLAVE4ID, TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IS_OWNER_ACCOUNT) values ('".$mslave4id."', '".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($ChkOFFHireCal)."')";
									mysql_query($sql7) or die($sql7);
									mysql_query("commit");
								}
							}
						}
					}
				}
			}
			
			$txtTCHOSTID = $_REQUEST['txtTCHOSTID_'.$i];
			for($j=1 ; $j<=$txtTCHOSTID ;$j++)
			{
				if($_REQUEST['txtTCDeliveryDate_'.$i.'_'.$j] != "" && $_REQUEST['txtTCReDeliveryDate_'.$i.'_'.$j] != "")
				{
					if($_REQUEST['txtTCDeliveryDate_'.$i.'_'.$j]!="")
					{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate_'.$i.'_'.$j]));}
					else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtTCReDeliveryDate_'.$i.'_'.$j]!="")
					{$txtTCReDeliveryDate 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate_'.$i.'_'.$j]));}
					else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
					
					$randomid = $_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j];
					if(!isset($_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j]) || $_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j]=='')
					{
						$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
					}
					
					$sql3 = "insert into chartering_tc_estimate_slave2 (TC_SLAVE1ID, RANDOMID, TC_DELIVERY_DATE, TC_REDELIVERY_DATE, TC_RATE, TD_DAYS, HIERAGE, BALLAST_BONUS, GROSS_HIERAGE, ADD_COMM, ADD_COMM_AMT, ADD_COMM_VENDOR, BROKERAGE_COMM, BROKERAGE_COMM_AMT, BRO_COMM_VENDOR, NET_HIERAGE, CVE_MONTH, CVE_AMOUNT) values ('".$maxslaveid."', '".$randomid."', '".$txtTCDeliveryDate."', '".$txtTCReDeliveryDate."', '".$this->getCheckNullValue($_REQUEST['txtTCinDailyHire_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTotalVoyageDays_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtBallastBonus_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtGrossHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargePercent_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargePercentAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selTCAddCoVendor_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeBroPercent_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeBroPercentAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selTCBroComVendor_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtNettHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTCHireargeCVE_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTCHireargeCVEAMT_'.$i.'_'.$j])."')";
					mysql_query($sql3) or die($sql3);//echo $sql3;
					mysql_query("commit");	
				}
			}			
		}
	}
	return $msg; 
}

function updateTCCostSheetDetails()
{
	$connect = $this->funConnect();
	$id                 = $_REQUEST['id'];
	$txtTotalUdays				= addslashes(trim($_REQUEST['txtTotalUdays']));
	$txtTotalVoyageEarning		= addslashes(trim($_REQUEST['txtTotalVoyageEarning']));
	$txtTripTC   				= addslashes(trim($_REQUEST['txtTripTC']));
	$txtPeriod          		= addslashes(trim($_REQUEST['txtPeriod']));
	$txtNoOfTrips       		= addslashes(trim($_REQUEST['txtNoOfTrips']));
	$selPeriodContract     		= addslashes(trim($_REQUEST['selPeriodContract']));
	$update_status              = addslashes(trim($_REQUEST['update_status']));
	
	$sheet_no                   = $_REQUEST['cost_sheet_id'];
	$comid                      = $_REQUEST['comid'];
	$this->viewTCEstimationTempleteRecordsNew($id);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update chartering_estimate_tc_master set FINAL_DATETIME = NOW(), TRIP_TC='".$txtTripTC."', PERIOD='".$txtPeriod."', NO_OF_TRIP='".$this->getCheckNullValue($txtNoOfTrips)."', FINAL_STATUS='".$this->getCheckNullValue($update_status)."', FIXED=1, TOTAL_DAYS='".$this->getCheckNullValue($txtTotalUdays)."', TOTAL_EARNING='".$this->getCheckNullValue($txtTotalVoyageEarning)."' where SHEET_NO='".$this->getCheckNullValue($sheet_no)."' and COMID='".$comid."' ";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql_update = "update chartering_estimate_tc_master set PERIODID='".$this->getCheckNullValue($selPeriodContract)."' where COMID='".$comid."' ";
	mysql_query($sql_update) or die($sql_update);
	mysql_query("commit");
	
	for($i=1;$i<= $_REQUEST['txtTripID']; $i++)
	{
		$txtBunkerDifference		= addslashes(trim($_REQUEST['txtBunkerDifference_'.$i]));
		$txtTCdays					= addslashes(trim($_REQUEST['txtTCdays_'.$i]));
		$txtUtilisationDays			= addslashes(trim($_REQUEST['txtUtilisationDays_'.$i]));
		$txtDailyGrossHireUSD		= addslashes(trim($_REQUEST['txtDailyGrossHireUSD_'.$i]));
		$txtBallastBonusAMT  		= addslashes(trim($_REQUEST['txtBallastBonusAMT_'.$i]));
		$selExchangeCurrency		= addslashes(trim($_REQUEST['selExchangeCurrency_'.$i]));
		$txtExchangeRate			= addslashes(trim($_REQUEST['txtExchangeRate_'.$i]));		
		$txtAddCommPerct			= addslashes(trim($_REQUEST['txtAddCommPerct_'.$i]));
		$txtAddComm1				= addslashes(trim($_REQUEST['txtAddComm1_'.$i]));
		$txtChartererAcc			= addslashes(trim($_REQUEST['txtChartererAcc_'.$i]));
		$selAddCommVendor			= addslashes(trim($_REQUEST['selAddCommVendor_'.$i]));
		$txtBrokerComm				= addslashes(trim($_REQUEST['txtBrokerComm_'.$i]));
		$selBroCommVendor			= addslashes(trim($_REQUEST['selBroCommVendor_'.$i]));
		$txtNettHire				= addslashes(trim($_REQUEST['txtNettHire_'.$i]));
		$txtNettRev					= addslashes(trim($_REQUEST['txtNettRev_'.$i]));
		$txtLessOffHire				= addslashes(trim($_REQUEST['txtLessOffHire_'.$i]));
		$txtCVE						= addslashes(trim($_REQUEST['txtCVE_'.$i]));
		$txtOtherIncome				= addslashes(trim($_REQUEST['txtOtherIncome_'.$i]));
		$txtTotalRev	    		= addslashes(trim($_REQUEST['txtTotalRev_'.$i]));
		$selESTtcVendor	    		= addslashes(trim($_REQUEST['selESTtcVendor_'.$i]));
		$txtTotalExpenses			= addslashes(trim($_REQUEST['txtTotalExpenses_'.$i]));
		$txtVoyageEarnings			= addslashes(trim($_REQUEST['txtVoyageEarnings_'.$i]));
		$txtProfitPerDay			= addslashes(trim($_REQUEST['txtProfitPerDay_'.$i]));
		$txtTCPerDay    			= addslashes(trim($_REQUEST['txtTCPerDay_'.$i]));
		$txtTotalHireage			= addslashes(trim($_REQUEST['txtTotalHireage_'.$i]));
		$txtAddComm     			= addslashes(trim($_REQUEST['txtAddComm_'.$i]));
		$txtAddCommAmt   			= addslashes(trim($_REQUEST['txtAddCommAmt_'.$i]));
		$txtNetHireage  			= addslashes(trim($_REQUEST['txtNetHireage_'.$i]));
		$selTcInExpVendor  			= addslashes(trim($_REQUEST['selTcInExpVendor_'.$i]));
		$txtCVEM        			= addslashes(trim($_REQUEST['txtCVEM_'.$i]));
		$txtNETHire        			= addslashes(trim($_REQUEST['txtNETHire_'.$i]));
		
		if($_REQUEST['txtTCCPDate_'.$i]!="")
		{$txtTCCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCCPDate_'.$i]));}
		else{$txtTCCPDate  		= "1970-01-01";}
		$txtTCDeliveryPort        	= addslashes(trim($_REQUEST['txtTCDeliveryPort_'.$i]));
		$txtTCReDeliveryPort		= addslashes(trim($_REQUEST['txtTCReDeliveryPort_'.$i]));
		$txtTCOffHireCVE        	= addslashes(trim($_REQUEST['txtTCOffHireCVE_'.$i]));
		$txtTCOffHireCVEAMT			= addslashes(trim($_REQUEST['txtTCOffHireCVEAMT_'.$i]));
		$txtTCBunkerOnOwnerAmt      = addslashes(trim($_REQUEST['txtTCBunkerOnOwnerAmt_'.$i]));
		$txtTCLessOffHire  			= addslashes(trim($_REQUEST['txtTCLessOffHire_'.$i]));
		$txtFinalHireargeAmt		= addslashes(trim($_REQUEST['txtFinalHireargeAmt_'.$i]));
		$selTCVendor      			= addslashes(trim($_REQUEST['selTCVendor_'.$i]));
		$txtTCCPNumber     			= addslashes(trim($_REQUEST['txtTCCPNumber_'.$i]));
		
		if($_REQUEST['txtDeldate_'.$i]!="")
		{$txtDeldate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtDeldate_'.$i]));}
		else{$txtDeldate  		= "1970-01-01 08:00:00";}
		
		if($_REQUEST['txtReDeldate_'.$i]!="")
		{$txtReDeldate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtReDeldate_'.$i]));}
		else{$txtReDeldate  		= "1970-01-01 08:00:00";}
		
		if(isset($_REQUEST['txtCOUTSlaveIdentify_'.$i]))
		{
			if($_REQUEST['txtCOUTSlaveIdentify_'.$i] == 'add'  || $_REQUEST['txtCOUTSlaveIdentify_'.$i]=='update')
			{
				if($_REQUEST['txtCOUTSlaveIdentify_'.$i] == 'add')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
					
					$sql1 = "insert into chartering_tc_estimate_slave1 (TCOUTID, TRIP_TC_EST, PERIOD_TC_EST, NO_OF_TRIP_EST, CP_TYPE_EST, CHARTERERS_EST, DEL_DATE_EST, DEL_HFO_MT_EST, DEL_HFO_USD_EST, DEL_MGO_MT_EST, DEL_MGO_USD_EST, REDEL_DATE_EST, REDEL_HFO_MT_EST, REDEL_HFO_USD_EST, REDEL_MGO_MT_EST, REDEL_MGO_USD_EST, TC_DAYS_EST, UTILISATION_DAY_EST, DAILY_GROSS_HIRE_EST, EXCHANGE_CURRENCY, EXCHANGE_RATE, ADD_COMM_EST, ADD_COMM_CAL_EST, ADD_COMM_VENDOR, BROKER_COMM_EST, BROKER_COMM_CAL_EST, BROKER_COMM_VENDOR, NETT_HIRE_EST, NETT_REV_EST, LESS_OFF_HIRE_EST, CVE_EST, OTHER_INCOME_EST, TOTAL_REV_EST, TTL_REV_VENDOR, TOTAL_EXP_EST, VOYAGE_EARN_EST, PROFIT_PER_DAY_EST, UPDATE_ON_DATE, DEL_HFO_AMT, DEL_MDO_AMT, REDEL_HFO_AMT, REDEL_MDO_AMT, BUNKER_DIFF_AMT, RANDOMID, TC_RATE, TOTAL_HIREAGE, ADD_COMM, ADD_COMM_AMT, NET_HIREAGE, NET_HIR_VENDOR, CVE_MONTH, NET_HIRE_AMT, TC_CP_DATE, TC_PORT_DELIVERY, TC_PORT_REDELIVERY, TC_CVE_MONTH_OFFHIRE, TC_CVE_AMOUNT_OFFHIRE, TC_BUNKERS_ON_OWNER, TC_OFF_HIRE, TC_FINAL_HIERAGE, TC_FINAL_HIERAGE_VENDOR, TC_CP_NUMBER, BALLAST_BONUS_AMT) values ('".$this->getFun1()."','".$txtTripTC1."','".$txtPeriod1."','".$this->getCheckNullValue($txtNoOfTrips1)."','".$this->getCheckNullValue($txtCPType)."','".$this->getCheckNullValue($txtCharterers)."','".$txtDeldate."','".$this->getCheckNullValue($txtDelHFOmt)."','".$this->getCheckNullValue($txtDelHFOusdmt)."','".$this->getCheckNullValue($txtDelMGOmt)."','".$this->getCheckNullValue($txtDelMGOusdmt)."','".$txtReDeldate."','".$this->getCheckNullValue($txtReDelHFOmt)."','".$this->getCheckNullValue($txtReDelHFOusdmt)."','".$this->getCheckNullValue($txtReDelMGOmt)."','".$this->getCheckNullValue($txtReDelMGOusdmt)."','".$this->getCheckNullValue($txtTCdays)."','".$this->getCheckNullValue($txtUtilisationDays)."','".$this->getCheckNullValue($txtDailyGrossHireUSD)."','".$this->getCheckNullValue($selExchangeCurrency)."','".$txtExchangeRate."','".$this->getCheckNullValue($txtAddCommPerct)."','".$this->getCheckNullValue($txtAddComm1)."','".$this->getCheckNullValue($selAddCommVendor)."','".$this->getCheckNullValue($txtChartererAcc)."','".$this->getCheckNullValue($txtBrokerComm)."','".$this->getCheckNullValue($selBroCommVendor)."','".$this->getCheckNullValue($txtNettHire)."','".$this->getCheckNullValue($txtNettRev)."','".$this->getCheckNullValue($txtLessOffHire)."','".$this->getCheckNullValue($txtCVE)."','".$this->getCheckNullValue($txtOtherIncome)."','".$this->getCheckNullValue($txtTotalRev)."','".$this->getCheckNullValue($selESTtcVendor)."','".$this->getCheckNullValue($txtTotalExpenses)."','".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtProfitPerDay)."',NOW(),'".$this->getCheckNullValue($txtDelTotalHFOUSD)."','".$this->getCheckNullValue($txtDelTotalMDOUSD)."','".$this->getCheckNullValue($txtReDelTotalHFOUSD)."','".$this->getCheckNullValue($txtReDelTotalMDOUSD)."','".$this->getCheckNullValue($txtBunkerDifference)."','".$this->getCheckNullValue($randomid)."','".$this->getCheckNullValue($txtTCPerDay)."','".$this->getCheckNullValue($txtTotalHireage)."','".$this->getCheckNullValue($txtAddComm)."','".$this->getCheckNullValue($txtAddCommAmt)."','".$this->getCheckNullValue($txtNetHireage)."', '".$this->getCheckNullValue($selTcInExpVendor)."', '".$this->getCheckNullValue($txtCVEM)."', '".$this->getCheckNullValue($txtNETHire)."', '".$txtTCCPDate."', '".$txtTCDeliveryPort."', '".$txtTCReDeliveryPort."', '".$this->getCheckNullValue($txtTCOffHireCVE)."', '".$this->getCheckNullValue($txtTCOffHireCVEAMT)."', '".$this->getCheckNullValue($txtTCBunkerOnOwnerAmt)."', '".$this->getCheckNullValue($txtTCLessOffHire)."', '".$this->getCheckNullValue($txtFinalHireargeAmt)."', '".$selTCVendor."', '".$txtTCCPNumber."', '".$this->getCheckNullValue($txtBallastBonusAMT)."')";
					mysql_query($sql1) or die($sql1);
			        mysql_query("commit");
					
					$mysql = "select max(TC_SLAVE1ID) as max from chartering_tc_estimate_slave1 where TCOUTID='".$this->getFun1()."'";
					$myres  =  mysql_query($mysql,$connect);
					$myrows = mysql_fetch_assoc($myres);
					$maxslaveid = $myrows['max'];
				}
				else
				{
					$maxslaveid = $_REQUEST['txtCOUTSlaveID_'.$i];
					$randomid = $_REQUEST['txtCOUTSlaveRandomID_'.$i];
					if(!isset($_REQUEST['txtCOUTSlaveRandomID_'.$i]) || $_REQUEST['txtCOUTSlaveRandomID_'.$i]=='')
					{
						$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
					}
					$sql1 = "update chartering_tc_estimate_slave1 set TRIP_TC_EST='".$txtTripTC1."', PERIOD_TC_EST='".$txtPeriod1."', NO_OF_TRIP_EST='".$this->getCheckNullValue($txtNoOfTrips1)."', CP_TYPE_EST='".$this->getCheckNullValue($txtCPType)."', CHARTERERS_EST='".$this->getCheckNullValue($txtCharterers)."', DEL_DATE_EST='".$txtDeldate."', DEL_HFO_MT_EST='".$this->getCheckNullValue($txtDelHFOmt)."', DEL_HFO_USD_EST='".$this->getCheckNullValue($txtDelHFOusdmt)."', DEL_MGO_MT_EST='".$this->getCheckNullValue($txtDelMGOmt)."', DEL_MGO_USD_EST='".$this->getCheckNullValue($txtDelMGOusdmt)."', REDEL_DATE_EST='".$txtReDeldate."', REDEL_HFO_MT_EST='".$this->getCheckNullValue($txtReDelHFOmt)."', REDEL_HFO_USD_EST='".$this->getCheckNullValue($txtReDelHFOusdmt)."', REDEL_MGO_MT_EST='".$this->getCheckNullValue($txtReDelMGOmt)."', REDEL_MGO_USD_EST='".$this->getCheckNullValue($txtReDelMGOusdmt)."', TC_DAYS_EST='".$this->getCheckNullValue($txtTCdays)."', UTILISATION_DAY_EST='".$this->getCheckNullValue($txtUtilisationDays)."', DAILY_GROSS_HIRE_EST='".$this->getCheckNullValue($txtDailyGrossHireUSD)."', EXCHANGE_CURRENCY='".$this->getCheckNullValue($selExchangeCurrency)."', EXCHANGE_RATE='".$txtExchangeRate."', ADD_COMM_EST='".$this->getCheckNullValue($txtAddCommPerct)."', ADD_COMM_CAL_EST='".$this->getCheckNullValue($txtAddComm1)."', ADD_COMM_VENDOR='".$this->getCheckNullValue($selAddCommVendor)."', BROKER_COMM_EST='".$this->getCheckNullValue($txtChartererAcc)."', BROKER_COMM_CAL_EST='".$this->getCheckNullValue($txtBrokerComm)."', BROKER_COMM_VENDOR='".$this->getCheckNullValue($selBroCommVendor)."', NETT_HIRE_EST='".$this->getCheckNullValue($txtNettHire)."', NETT_REV_EST='".$this->getCheckNullValue($txtNettRev)."', LESS_OFF_HIRE_EST='".$this->getCheckNullValue($txtLessOffHire)."', CVE_EST='".$this->getCheckNullValue($txtCVE)."', OTHER_INCOME_EST='".$this->getCheckNullValue($txtOtherIncome)."', TOTAL_REV_EST='".$this->getCheckNullValue($txtTotalRev)."', TTL_REV_VENDOR='".$this->getCheckNullValue($selESTtcVendor)."', TOTAL_EXP_EST='".$this->getCheckNullValue($txtTotalExpenses)."', VOYAGE_EARN_EST='".$this->getCheckNullValue($txtVoyageEarnings)."', PROFIT_PER_DAY_EST='".$this->getCheckNullValue($txtProfitPerDay)."', UPDATE_ON_DATE=NOW(), DEL_HFO_AMT='".$this->getCheckNullValue($txtDelTotalHFOUSD)."', DEL_MDO_AMT='".$this->getCheckNullValue($txtDelTotalMDOUSD)."', REDEL_HFO_AMT='".$this->getCheckNullValue($txtReDelTotalHFOUSD)."', REDEL_MDO_AMT='".$this->getCheckNullValue($txtReDelTotalMDOUSD)."', BUNKER_DIFF_AMT='".$this->getCheckNullValue($txtBunkerDifference)."', RANDOMID='".$this->getCheckNullValue($randomid)."', TC_RATE='".$this->getCheckNullValue($txtTCPerDay)."', TOTAL_HIREAGE='".$this->getCheckNullValue($txtTotalHireage)."', ADD_COMM='".$this->getCheckNullValue($txtAddComm)."', ADD_COMM_AMT='".$this->getCheckNullValue($txtAddCommAmt)."', NET_HIREAGE='".$this->getCheckNullValue($txtNetHireage)."', NET_HIR_VENDOR='".$this->getCheckNullValue($selTcInExpVendor)."', CVE_MONTH='".$this->getCheckNullValue($txtCVEM)."', NET_HIRE_AMT='".$this->getCheckNullValue($txtNETHire)."', TC_CP_DATE='".$txtTCCPDate."', TC_PORT_DELIVERY='".$txtTCDeliveryPort."', TC_PORT_REDELIVERY='".$txtTCReDeliveryPort."', TC_CVE_MONTH_OFFHIRE='".$this->getCheckNullValue($txtTCOffHireCVE)."', TC_CVE_AMOUNT_OFFHIRE='".$this->getCheckNullValue($txtTCOffHireCVEAMT)."', TC_BUNKERS_ON_OWNER='".$this->getCheckNullValue($txtTCBunkerOnOwnerAmt)."', TC_OFF_HIRE='".$this->getCheckNullValue($txtTCLessOffHire)."', TC_FINAL_HIERAGE='".$this->getCheckNullValue($txtFinalHireargeAmt)."', TC_FINAL_HIERAGE_VENDOR='".$selTCVendor."', TC_CP_NUMBER= '".$txtTCCPNumber."', BALLAST_BONUS_AMT='".$this->getCheckNullValue($txtBallastBonusAMT)."' where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					mysql_query($sql1) or die($sql1);
			        mysql_query("commit");
					
					$del_query3 = "delete from  chartering_estimate_tc_slave2 where TC_SLAVE1ID='".$maxslaveid."'";
					$del_query4 = "delete from  chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$maxslaveid."'";
					$del_query5 = "delete from  chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$maxslaveid."'";
					$del_query6 = "delete from  chartering_tc_estimate_slave3 where TC_SLAVE1ID='".$maxslaveid."'";
					$del_query7 = "delete from  chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$maxslaveid."'";
					$del_query8 = "delete from  chartering_tc_estimate_slave5 where TC_SLAVE1ID='".$maxslaveid."'";
					$del_query9 = "delete from  chartering_tc_estimate_slave2 where TC_SLAVE1ID='".$maxslaveid."'";
					$del_query10 = "delete from  chartering_estimate_tc_slave7 where TC_SLAVE1ID='".$maxslaveid."'";
					mysql_query($del_query3);
					mysql_query($del_query4);
					mysql_query($del_query5);
					mysql_query($del_query6);
					mysql_query($del_query7);
					mysql_query($del_query8);
					mysql_query($del_query9);
					mysql_query($del_query10);
					mysql_query("commit");
				}
				$hddnOtherID = $_REQUEST['hddnOtherID_'.$i];
				for($j=1 ; $j<=$hddnOtherID ;$j++)
				{
					if($_REQUEST['txtOtherIncome_'.$i.'_'.$j] != "")
					{
						$sql3 = "insert into chartering_estimate_tc_slave2 (TC_SLAVE1ID, DESCRIPTION, OTHER_AMT, OTHER_EXP_VENDOR, STATUS) values ('".$maxslaveid."', '".$_REQUEST['txtOtherIncomeText_'.$i.'_'.$j]."', '".$this->getCheckNullValue($_REQUEST['txtOtherIncome_'.$i.'_'.$j])."', '".addslashes(trim($_REQUEST['selOthIncVendor_'.$i.'_'.$j]))."', 1)";
						mysql_query($sql3) or die($sql3);
						mysql_query("commit");
					}
				} 
				
				$hddnOtherExID = $_REQUEST['hddnOtherExID_'.$i];
				for($j=1 ; $j<=$hddnOtherExID ;$j++)
				{
					if($_REQUEST['txtOtherExpense_'.$i.'_'.$j] != "")
					{
						if(isset($_REQUEST['ChkAddToTTL_'.$i.'_'.$j])){$ChkAddToTTL = $_REQUEST['ChkAddToTTL_'.$i.'_'.$j]; }else{$ChkAddToTTL = 0;}
						
						$sql3 = "insert into chartering_estimate_tc_slave2 (TC_SLAVE1ID, EXPENSETYPEID, DESCRIPTION, CHK_ADDTTL, OTHER_AMT, OTHER_EXP_VENDOR, STATUS) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selExpenseType_'.$i.'_'.$j])."', '".addslashes(trim($_REQUEST['txtExpenseDesc_'.$i.'_'.$j]))."', '".$ChkAddToTTL."', '".$this->getCheckNullValue($_REQUEST['txtOtherExpense_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selOthExpVendor_'.$i.'_'.$j])."', 2)";
						mysql_query($sql3) or die($sql3);
						mysql_query("commit");
					}
				} 
				
				$txtOFFID = $_REQUEST['txtOFFID_'.$i];
				for($j=1 ; $j<=$txtOFFID ;$j++)
				{
					if($_REQUEST['txtOffHireReason_'.$i.'_'.$j] != "")
					{
						if($_REQUEST['txtOffHireFrom_'.$i.'_'.$j]!="")
						{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i.'_'.$j]));}
						else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
						
						if($_REQUEST['txtOffHireTo_'.$i.'_'.$j]!="")
						{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i.'_'.$j]));}
						else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
						$sql3 = "insert into chartering_estimate_tc_slave3 (TC_SLAVE1ID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE) values ('".$maxslaveid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i.'_'.$j])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i.'_'.$j])."')";
						mysql_query($sql3) or die($sql3);
						mysql_query("commit");
						
						$mysqlmax4 = "select max(TC_SLAVE3ID) as max from chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$maxslaveid."'";
						$myresmax4  =  mysql_query($mysqlmax4)or die($mysqlmax4);
						$myrowsmax4 = mysql_fetch_assoc($myresmax4);
						$mslave4id = $myrowsmax4['max'];
						
						$txtOFFConBunkerCount_ = $_REQUEST['txtOFFConBunkerCount_'.$i.'_'.$j];
						for($l=1 ; $l<=$txtOFFConBunkerCount_;$l++)
						{
							if(isset($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l]))
							{
								if($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l] != "" && $_REQUEST['txtConBunkerQty_'.$i.'_'.$j.'_'.$l] != "" && $_REQUEST['txtConBunkerAmt_'.$i.'_'.$j.'_'.$l] != "")
								{  
									$sql7 = "insert into chartering_estimate_tc_slave7 (TC_SLAVE3ID, TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT) values ('".$mslave4id."', '".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerQty_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerPrice_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerAmt_'.$i.'_'.$j.'_'.$l])."')";
									mysql_query($sql7) or die($sql7);
									mysql_query("commit");
								}
							}
						}//die;
					}
				}
				
				$txtDELID = $_REQUEST['txtDELID_'.$i];
				for($j=1 ; $j<=$txtDELID ;$j++)
				{
					if($_REQUEST['selDelBunker_'.$i.'_'.$j] != "" && $_REQUEST['txtDelQty_'.$i.'_'.$j] != "")
					{
						if($_REQUEST['txtDelBunDate_'.$i.'_'.$j]!="")
						{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$i.'_'.$j]));}
						else{$txtDelBunDate    	= "1970-01-01";}
						$sql3 = "insert into chartering_estimate_tc_slave5 (TC_SLAVE1ID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$i.'_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$i.'_'.$j])."', 'DEL')";
						mysql_query($sql3) or die($sql3);
						mysql_query("commit");
					}
				}
				
				$txtREDELID = $_REQUEST['txtREDELID_'.$i];
				for($j=1 ; $j<=$txtREDELID ;$j++)
				{
					if($_REQUEST['selReDelBunker_'.$i.'_'.$j] != "" && $_REQUEST['txtReDelQty_'.$i.'_'.$j] != "")
					{
						if($_REQUEST['txtReDelBunDate_'.$i.'_'.$j]!="")
						{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$i.'_'.$j]));}
						else{$txtReDelBunDate    	= "1970-01-01";}
						$sql3 = "insert into chartering_estimate_tc_slave5 (TC_SLAVE1ID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$i.'_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$i.'_'.$j])."', 'REDEL')";
						mysql_query($sql3) or die($sql3);
						mysql_query("commit");
					}
				}
				
				
				$txtTCDELID = $_REQUEST['txtTCDELID_'.$i];
				for($k=1 ; $k<=$txtTCDELID ;$k++)
				{
					if(isset($_REQUEST['selTCDelBunker_'.$i.'_'.$k]))
					{
						if($_REQUEST['selTCDelBunker_'.$i.'_'.$k] != "" && $_REQUEST['txtTCDelQty_'.$i.'_'.$k] != "" && $_REQUEST['txtTCDelAmount_'.$i.'_'.$k] != "")
						{
							if($_REQUEST['txtTCDelBunDate_'.$i.'_'.$k]!="")
							{$txtTCDelBunDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCDelBunDate_'.$i.'_'.$k]));}
							else{$txtTCDelBunDate  		= "1970-01-01";}
							
							$sql4 = "insert into chartering_tc_estimate_slave3 (TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_DATE, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCDelBunker_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCDelQty_'.$i.'_'.$k])."', '".$txtTCDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtTCDelPrice_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCDelAmount_'.$i.'_'.$k])."', 'DEL')";
							mysql_query($sql4) or die($sql4);
							mysql_query("commit");
						}
					}
				}
				
				$txtTCREDELID = $_REQUEST['txtTCREDELID_'.$i];
				for($k=1 ; $k<=$txtTCREDELID ;$k++)
				{
				    
					if(isset($_REQUEST['selTCReDelBunker_'.$i.'_'.$k]))
					{
						if($_REQUEST['selTCReDelBunker_'.$i.'_'.$k] != "" && $_REQUEST['txtTCReDelQty_'.$i.'_'.$k] != "" && $_REQUEST['txtTCReDelAmount_'.$i.'_'.$k] != "")
						{
							if($_REQUEST['txtTCReDelBunDate_'.$i.'_'.$k]!="")
							{$txtTCReDelBunDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCReDelBunDate_'.$i.'_'.$k]));}
							else{$txtTCReDelBunDate  		= "1970-01-01";}
							
							$sql5 = "insert into chartering_tc_estimate_slave3 (TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_DATE, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCReDelBunker_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelQty_'.$i.'_'.$k])."', '".$txtTCReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelPrice_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelAmount_'.$i.'_'.$k])."', 'REDEL')";
							mysql_query($sql5) or die($sql5);
							mysql_query("commit");
						}
					}
				}
				
				
				$txtTCOFFID = $_REQUEST['txtTCOFFID_'.$i];
				for($k=1 ; $k<=$txtTCOFFID ;$k++)
				{
					if(isset($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k]))
					{
						if($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k] != "" )
						{
							if($_REQUEST['txtTCOffHireFrom_'.$i.'_'.$k]!="")
							{$txtTCOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCOffHireFrom_'.$i.'_'.$k]));}
							else{$txtTCOffHireFrom  		= "1970-01-01 08:00:00";}
							
							if($_REQUEST['txtTCOffHireTo_'.$i.'_'.$k]!="")
							{$txtTCOffHireTo	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCOffHireTo_'.$i.'_'.$k]));}
							else{$txtTCOffHireTo  		= "1970-01-01 08:00:00";}
							
							$randomid = $_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k];
							if(!isset($_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k]) || $_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k]=='')
							{
								$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
							}
							
							$sql6 = "insert into chartering_tc_estimate_slave4 (TC_SLAVE1ID, OFFHIRE_REASON, OFF_HIRE_FROM, OFF_HIRE_TO, OFF_HIRE_DAYS, OFF_HIRE_RATE, OF_HIRE_AMT, RANDOMID) values ('".$maxslaveid."', '".addslashes(trim($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k]))."', '".$txtTCOffHireFrom."', '".$txtTCOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireDays_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireRate_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireAmt_'.$i.'_'.$k])."', '".$randomid."')";
							mysql_query($sql6) or die($sql6);
							mysql_query("commit");
							
							$mysqlmax4 = "select max(TC_SLAVE4ID) as max from chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$maxslaveid."'";
							$myresmax4  =  mysql_query($mysqlmax4);
							$myrowsmax4 = mysql_fetch_assoc($myresmax4);
							$mslave4id = $myrowsmax4['max'];
							

							$txtTCConBunkerCount = $_REQUEST['txtTCConBunkerCount_'.$i.'_'.$k];
							for($l=1 ; $l<=$txtTCConBunkerCount;$l++)
							{
								if(isset($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l]))
								{
									if($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l] != "" && $_REQUEST['txtTCConBunkerQty_'.$i.'_'.$k.'_'.$l] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$k.'_'.$l] != "")
									{   
										if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$k.'_'.$l])){$ChkOFFHireCal = $_REQUEST['ChkOFFHireCal_'.$i.'_'.$k.'_'.$l];}
										else{$ChkOFFHireCal  = 0;}
										$sql7 = "insert into chartering_tc_estimate_slave5 (TC_SLAVE4ID, TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IS_OWNER_ACCOUNT) values ('".$mslave4id."', '".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($ChkOFFHireCal)."')";
										mysql_query($sql7) or die($sql7);
										mysql_query("commit");
									}
								}
							}
						}
					}
				}
				
				$txtTCHOSTID = $_REQUEST['txtTCHOSTID_'.$i];
				
				for($j=1 ; $j<=$txtTCHOSTID ;$j++)
				{
					if($_REQUEST['txtTCDeliveryDate_'.$i.'_'.$j] != "" && $_REQUEST['txtTCReDeliveryDate_'.$i.'_'.$j] != "")
					{
						if($_REQUEST['txtTCDeliveryDate_'.$i.'_'.$j]!="")
						{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate_'.$i.'_'.$j]));}
						else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
						
						if($_REQUEST['txtTCReDeliveryDate_'.$i.'_'.$j]!="")
						{$txtTCReDeliveryDate 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate_'.$i.'_'.$j]));}
						else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
						
						$randomid = $_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j];
						if(!isset($_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j]) || $_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j]=='')
						{
							$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
						}
						
						$sql3 = "insert into chartering_tc_estimate_slave2 (TC_SLAVE1ID, RANDOMID, TC_DELIVERY_DATE, TC_REDELIVERY_DATE, TC_RATE, TD_DAYS, HIERAGE, BALLAST_BONUS, GROSS_HIERAGE, ADD_COMM, ADD_COMM_AMT, ADD_COMM_VENDOR, BROKERAGE_COMM, BROKERAGE_COMM_AMT, BRO_COMM_VENDOR, NET_HIERAGE, CVE_MONTH, CVE_AMOUNT) values ('".$maxslaveid."', '".$randomid."', '".$txtTCDeliveryDate."', '".$txtTCReDeliveryDate."', '".$this->getCheckNullValue($_REQUEST['txtTCinDailyHire_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTotalVoyageDays_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtBallastBonus_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtGrossHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargePercent_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargePercentAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selTCAddCoVendor_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeBroPercent_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeBroPercentAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selTCBroComVendor_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtNettHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTCHireargeCVE_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTCHireargeCVEAMT_'.$i.'_'.$j])."')";
						mysql_query($sql3) or die($sql3);//echo $sql3;
						mysql_query("commit");	
					}
				}
				//die;
				
			}
			else
			{
				if($_REQUEST['txtCOUTSlaveIdentify_'.$i] == 'delete'  && $_REQUEST['txtCOUTSlaveID_'.$i]!='')
			    {
			   	    $sql1 = "delete from chartering_tc_estimate_slave1 where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					mysql_query($sql1) or die($sql1);
			        mysql_query("commit");
					
					$del_query3 = "delete from  chartering_estimate_tc_slave2 where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					$del_query4 = "delete from  chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					$del_query5 = "delete from  chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					$del_query7 = "DELETE FROM chartering_tc_estimate_slave2 where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					$del_query8 = "DELETE FROM chartering_tc_estimate_slave3 where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					$del_query9 = "DELETE FROM chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					$del_query10 = "DELETE FROM chartering_tc_estimate_slave5 where TC_SLAVE1ID='".$_REQUEST['txtCOUTSlaveID_'.$i]."'";
					mysql_query($del_query3);
					mysql_query($del_query4);
					mysql_query($del_query5);
					mysql_query($del_query7);
					mysql_query($del_query8);
					mysql_query($del_query9);
					mysql_query($del_query10);
					mysql_query("commit");
				}
			}
		}
	}
			
	return $msg; 
}


function displaytcHireInvioceListList($comid,$page)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="invoice_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%">#</th>';
	echo '<th align="left" valign="middle" width="15%">Invoice Type</th>';
	echo '<th align="left" valign="middle" width="15%">Invoice No.</th>';
	echo '<th align="left" valign="middle" width="15%">Invoice Date</th>';
	echo '<th align="left" valign="middle" width="15%">Release Days</th>';
	echo '<th align="center" valign="middle" width="11%">Invoice Amount</th>';
	echo '<th align="center" valign="middle" width="11%" >Receive Payment</th>';
	echo '<th align="center" valign="middle" width="7%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from invoice_tchire_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."' order by INVOICEID desc";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody id="tbody">';		
		echo '</tbody>';
	}
	else{
	echo '<tbody id="tbody">';
		while($rows = mysql_fetch_assoc($res))
		{
			echo '<tr>';
			echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['INVOICE_TYPE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['INVOICE_NO'].'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.date('d-m-Y',strtotime($rows['INVOICE_DATE'])).'</td>';
			echo '<td align="center" valign="middle" class="input-text">'.$rows['RELEASE_HIRE_DAYS'].'</td>';
			echo '<td align="center" valign="middle" class="input-text">'.$rows['BALANCE_TO_OWNER'].'</td>';
			echo '<td align="center" valign="middle" class="input-text">';
			if($rows['STATUS']==2)
			{
			    echo '<a href="#Payment" title="Payment Paid" class="btn btn-default btn-sm" data-toggle="modal" data-target="#compose-modal" onClick="openWin('.$rows['INVOICEID'].');">Receipt</a>';	
		    }
			echo '</td>';
			if($rows['STATUS']<2)
			{
			    echo '<td align="center" valign="middle" class="input-text"><a href="invoice_tchire.php?comid='.$comid.'&page='.$page.'" title="Edit Details" ><i class="fa fa-edit"></i></a>&nbsp;|&nbsp;<a title="Delete Link" href="#Delete" onclick="getDelete('.$rows['INVOICEID'].');" ><i class="fa fa-times" style="color:red;"></i></td>';	
		    }
			else
			{
			    echo '<td align="center" valign="middle" class="input-text"><a href="view_tcinvoice_hire.php?comid='.$comid.'&page='.$page.'&invoiceid='.$rows['INVOICEID'].'" title="View Details" ><i class="fa fa-file-text"></i></a></td>';		
			}
			echo '</tr>';
			$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function deletetcHireInvoiceRecords()
{
	$connect						= $this->funConnect();
	$id 						    = addslashes(trim($_REQUEST['tblid']));
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 3;

	$sql = "delete from invoice_tchire_master where INVOICEID='".$id."'";
	$sql1 = "delete from invoice_tchire_slave1 where INVOICEID='".$id."'";
	mysql_query($sql);
	mysql_query($sql1);
	mysql_query("commit"); 
	return $msg;
}


function inserttcHirePaymentReceivedDetails()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update invoice_tchire_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where INVOICEID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$this->inactiveUserAlerts('HIRE INVOICE', $_SESSION['uid'], $txtP_ID);
	
	return $msg; 
}


function getTCLoadPortAndDischargePortArrBasedOnCommidAndProcessWithoutTBN($tcoutid)
{
	$connect = $this->funConnect();
	$arr  =  array();
	$sql  = "select FROM_PORT, TO_PORT, RANDOMID, LOAD_QTY, DISC_QTY, LOAD_PORT_COST, DISC_PORT_COST, TRANSIT_PORT_COST, LOAD_RATE, DISC_RATE, PORT_COSTLP_VENDOR, PORT_COSTDP_VENDOR, PORT_COSTTP_VENDOR from chartering_estimate_tc_slave1 where TCOUTID='".$tcoutid."' order by TC_SLAVE1ID asc";
	$res  = mysql_query($sql);
	while($rows  = mysql_fetch_assoc($res))
	{
		if($this->getPortNameBasedOnID($rows['FROM_PORT']) != "TBN")
		{
			if($rows['LOAD_QTY'] > 0)
		    {
				$arr[] = "LP@@".$rows['FROM_PORT']."@@".$rows['RANDOMID']."@@".$rows['LOAD_QTY']."@@".$rows['PORT_COSTLP_VENDOR']."@@".$rows['LOAD_PORT_COST']."@@".$rows['LOAD_RATE']."@@".$rows['PORT_COSTLP_VENDOR'];
			}
			if($rows['DISC_QTY'] > 0)
		    {
				$arr[] = "DP@@".$rows['TO_PORT']."@@".$rows['RANDOMID']."@@".$rows['DISC_QTY']."@@".$rows['PORT_COSTDP_VENDOR']."@@".$rows['DISC_PORT_COST']."@@".$rows['DISC_RATE']."@@".$rows['PORT_COSTDP_VENDOR'];
			}
			if($rows['TRANSIT_PORT_COST'] > 0)
		    {
				$arr[] = "TP@@".$rows['FROM_PORT']."@@".$rows['RANDOMID']."@@0@@".$rows['PORT_COSTTP_VENDOR'];
			}
		}
	
		
	}
	return $arr;
}



function convertToPostOpstc($comid)
{
	$connect		= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;	
	$sql = "update chartering_estimate_tc_compare set STATUS=2 where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);	
	mysql_query("commit");	 
	return $msg;
}


function completeVoyageEntrytc($comid)
{
	$connect				= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;	
	$sql = "update chartering_estimate_tc_compare set STATUS=4 where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);	
	mysql_query("commit");	
	return $msg;
}


function deleteInOpsEntrytc($comid)
{
	$connect				= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;	
	$sql = "update chartering_estimate_tc_compare set STATUS=3 where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."'  AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);	
	mysql_query("commit");	
			 
	return $msg;
}





function insertRequestDetailstc()
{
	
	
	$connect 			= $this->funConnect();	
	$senddata 				= explode(",",$_REQUEST['senddata']);
	$comid 			    = $senddata['5'];
	$selAType 			= addslashes(trim($_REQUEST['selAType']));
	$txtAccNO	 		= addslashes(trim($_REQUEST['txtAccNO']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	
	$txtTtl_Outs	 	= addslashes(trim($_REQUEST['txtTtl_Outs']));
	$txtBal_Outs	 	= addslashes(trim($_REQUEST['txtBal_Outs']));
	
	$txtROP	 			= addslashes(trim($_REQUEST['txtROP_3']));
	
	$txtROP_1	 		= addslashes(trim($_REQUEST['txtROP_1']));
	
	$txtID	 			= addslashes(trim($_REQUEST['txtID']));
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtCID	 			= addslashes(trim($_REQUEST['txtCID']));
	$vesselid	 		= addslashes(trim($_REQUEST['vesselid']));
	$txtV_I_Amt	 		= addslashes(trim($_REQUEST['txtV_I_Amt']));
	$txtI_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtI_Date']));
	$txtNET             = $_REQUEST['txtNET'];
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql4 = "delete from request_mastertc where REQ_ID='".$txtID."'";
	mysql_query($sql4) or die($sql4);
	mysql_query("commit");
	
	$sql5 = "delete from request_mastertc_slave where REQ_ID='".$txtID."'";
	mysql_query($sql5) or die($sql5);
	mysql_query("commit");
	
	//insert query here.............
	$sql = "insert into request_mastertc (COMID, MODULEID, MCOMPANYID, LOGIN, NAME, NAME_ID, GRADEID, VENDOR, RANDOMID, ACCOUNT_TYPE, PAYMENT_NO, DATE, REMARKS, TTL_OUTSTANDINGS, BAL_OUTSTANDINGS, REQ_TO_PAY, STATUS, CP_DATE, REQUESTED, VESSELID, R_TYPE, P_TYPE, INVOICE_AMT, INVOICE_DATE, NET_AMT) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$senddata[1]."', '".$senddata[0]."', '".$senddata[2]."', '".$txtVendor."', '".$senddata[3]."', '".$selAType."', '".$txtAccNO."', '".$txtDate."', '".$txtRemarks."', '".$this->getCheckNullVal($txtTtl_Outs)."', '".$this->getCheckNullVal($txtBal_Outs)."', '".$this->getCheckNullVal($txtROP)."', '".$txtStatus."', '".$txtCP_Date."', '0', '".$vesselid."', '".$this->getCheckNullVal($_REQUEST['rdoQty'])."', '".$this->getCheckNullVal($txtROP_1)."', '".$this->getCheckNullVal($txtV_I_Amt)."', '".$txtI_Date."', '".$this->getCheckNullVal($txtNET)."')";
	//echo $sql;die;
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql1  = "select max(REQ_ID) as max from request_mastertc";
	$res1  = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	
	$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into request_mastertc_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into request_mastertc_slave (REQ_ID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
	
	
	mysql_query("commit");
	return $msg; 
}


function insertRequestUploadDetailstc()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update request_mastertc set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where REQ_ID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	return $msg; 
}


function deleteRequestDetailstc()
{
	$connect = $this->funConnect();
	
	$txtID 				= addslashes(trim($_REQUEST['txtID']));
	$id 				= addslashes(trim($_REQUEST['id']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql1 = "select * from request_mastertc where REQ_ID='".$txtID."'";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	$sql2 = "insert into request_cancel_master (REQ_ID, COMID, MODULEID, MCOMPANYID, LOGIN, NAME, NAME_ID, GRADEID, VENDOR, PORT, ACCOUNT_TYPE, PAYMENT_NO, DATE, REMARKS, TTL_OUTSTANDINGS, BAL_OUTSTANDINGS, REQ_TO_PAY, STATUS, CP_DATE, REQUESTED, P_STATUS, RANDOMID) values ('".$txtID."','".$rows1['MAPPINGID']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$rows1['NAME']."', '".$rows1['NAME_ID']."', '".$rows1['GRADEID']."', '".$rows1['VENDOR']."', '".$rows1['PORT']."', '".$rows1['ACCOUNT_TYPE']."', '".$rows1['PAYMENT_NO']."', '".$rows1['DATE']."', '".$rows1['REMARKS']."', '".$rows1['TTL_OUTSTANDINGS']."', '".$rows1['BAL_OUTSTANDINGS']."', '".$rows1['REQ_TO_PAY']."', '".$rows1['STATUS']."', '".$rows1['CP_DATE']."', '0', '1', '".$rows1['RANDOMID']."')";
	mysql_query($sql2);
	
	$sql5 = "insert into request_cancel_master (REQ_ID, COMID, MODULEID, MCOMPANYID, LOGIN, NAME, NAME_ID, GRADEID, VENDOR, PORT, ACCOUNT_TYPE, PAYMENT_NO, DATE, REMARKS, TTL_OUTSTANDINGS, BAL_OUTSTANDINGS, REQ_TO_PAY, STATUS, CP_DATE, REQUESTED, P_STATUS, RANDOMID) values ('".$txtID."','".$rows1['MAPPINGID']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$rows1['NAME']."', '".$rows1['NAME_ID']."', '".$rows1['GRADEID']."', '".$rows1['VENDOR']."', '".$rows1['PORT']."', '".$rows1['ACCOUNT_TYPE']."', '".$rows1['PAYMENT_NO']."', '".$rows1['DATE']."', '".$rows1['REMARKS']."', '".$rows1['TTL_OUTSTANDINGS']."', '".$rows1['BAL_OUTSTANDINGS']."', '".-$rows1['REQ_TO_PAY']."', '".$rows1['STATUS']."', '".$rows1['CP_DATE']."', '0', '2', '".$rows1['RANDOMID']."')";
	mysql_query($sql5);
	
	$qsql = "delete from  request_master_slave where REQ_ID='".$txtID."'";
	mysql_query($qsql);
	
	$sql = "delete from  request_master where REQ_ID='".$txtID."'";
	mysql_query($sql);
	
	$sql3 = "select * from vwpr_master where VENDORID='".$rows1['VENDOR']."'";
	$res3 = mysql_query($sql3);
	while($rows3 = mysql_fetch_assoc($res3))
	{
		$reqid  = explode(",",$rows3['REQ_ID']);
		$vessel = explode(",",$rows3['VESSEL']);
		$remark = explode(",",$rows3['REMARK']);
		
		
		if(sizeof($reqid) == 1)
		{
			$sql4 = "delete from vwpr_master where VWPR_ID='".$rows3['VWPR_ID']."'";
			mysql_query($sql4);
		}
		else
		{
			for($i=0;$i<sizeof($reqid);$i++)
			{
				if($txtID != $reqid[$i])
				{
					$reqid_1[$i] = $reqid[$i];
					$vessel_1[$i] = $vessel[$i];
					$remark_1[$i] = $remark[$i];
				}
				
			}
			
			$reqid_2 = implode(",",$reqid_1);
			$vessel_2 = implode(",",$vessel_1);
			$remark_2 = implode(",",$remark_1);
			
			$total = $rows3['TOTAL']-$rows1['REQ_TO_PAY'];
			$g_total = $total*$rows3['RATE'];
			
			$sql4 = "update vwpr_master set VESSEL='".$vessel_2."', REMARK='".$remark_2."', REQ_ID='".$reqid_2."', TOTAL='".$total."', GRANDTOTAL='".$g_total."' where VWPR_ID='".$rows3['VWPR_ID']."'";
			mysql_query($sql4);
		}
	}
	
	mysql_query("commit");	
	return $msg.'_'.$id;
}


function getRequestDataWithJsontc()
{
	$connect = $this->funconnect();
	
	$query = mysql_query("select * from request_mastertc where LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'");
	while($row = mysql_fetch_assoc($query))
	{
	    $id = $row['REQ_ID'];
		$a[$id][] = array('account_type' => $row['ACCOUNT_TYPE'], 'payment_no' => $row['PAYMENT_NO'], 'date' => date("d-m-Y",strtotime($row['DATE'])), 'remarks' => $row['REMARKS'], 'ttl_outstandings' => $row['TTL_OUTSTANDINGS'], 'bal_outstandings' => $row['BAL_OUTSTANDINGS'], 'req_to_pay' => $row['REQ_TO_PAY'], 'r_type' => $row['R_TYPE'], 'p_type' => $row['P_TYPE'], 'i_amt' => $row['INVOICE_AMT'], 'i_date' => date("d-m-Y",strtotime($row['INVOICE_DATE'])));
	}
	echo json_encode($a);
}

function getRequestReletDataWithJson()
{
	$connect = $this->funconnect();
	
	$query = mysql_query("select * from request_relet_master where LOGIN='INTERNAL_USER' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'");
	while($row = mysql_fetch_assoc($query))
	{
	    $id = $row['REQ_ID'];
		$a[$id][] = array('account_type' => $row['ACCOUNT_TYPE'], 'payment_no' => $row['PAYMENT_NO'], 'date' => date("d-m-Y",strtotime($row['DATE'])), 'remarks' => $row['REMARKS'], 'ttl_outstandings' => $row['TTL_OUTSTANDINGS'], 'bal_outstandings' => $row['BAL_OUTSTANDINGS'], 'req_to_pay' => $row['REQ_TO_PAY'], 'r_type' => $row['R_TYPE'], 'p_type' => $row['P_TYPE'], 'i_amt' => $row['INVOICE_AMT'], 'i_date' => date("d-m-Y",strtotime($row['INVOICE_DATE'])));
	}
	echo json_encode($a);
}

function getRequestDeductionDataWithJsontc($id)
{
	$connect   = $this->funconnect();	
	$query     = mysql_query("select * from request_deductiontc_master where 1=1");
	while($row = mysql_fetch_assoc($query))
	{
		if($id == 1)
		{
			$sql = "select NAME from vc_deductiontc_master where VC_DEDUCTIONID='".$row['VC_DEDUCTIONID']."'";
		}
		
		$res  = mysql_query($sql);
		$rows = mysql_fetch_assoc($res);
	    $id   = $row['REQ_ID'];
		$a[$id][] = array('deduction_id' => $row['VC_DEDUCTIONID'], 'cost' => $row['COST'], 'name' => $rows['NAME']);
	}
	echo json_encode($a);
}



function insertchecklistDetailstc($id)
{
	$connect = $this->funConnect();
	
	$comid           		 = $_REQUEST['comid'];
	
	$regcheckbox  			 = addslashes(trim($_REQUEST['regcheckbox']));
	$classcheckbox 			 = addslashes(trim($_REQUEST['classcheckbox']));
	$pnicheckbox     		 = addslashes(trim($_REQUEST['pnicheckbox']));
	$ismcheckbox 			 = addslashes(trim($_REQUEST['ismcheckbox']));
	$doccheckbox    		 = addslashes(trim($_REQUEST['doccheckbox']));
	$itccheckbox 			 = addslashes(trim($_REQUEST['itccheckbox']));
	$ispscheckbox   		 = addslashes(trim($_REQUEST['ispscheckbox']));
	$llcheckbox     		 = addslashes(trim($_REQUEST['llcheckbox']));
	$bqcheckbox    		     = addslashes(trim($_REQUEST['bqcheckbox']));
	$hmcheckbox 		     = addslashes(trim($_REQUEST['hmcheckbox']));
	$seawebcheckbox          = addslashes(trim($_REQUEST['seawebcheckbox']));
	$cdecsigmcheckbox		 = addslashes(trim($_REQUEST['cdecsigmcheckbox']));
	$reqdoccheckbox 	     = addslashes(trim($_REQUEST['reqdoccheckbox']));
	
	$selVName	 		     = addslashes(trim($_REQUEST['selVName']));
	$txtLastPortAgnt		 = addslashes(trim($_REQUEST['txtLastPortAgnt']));
	
	if($_REQUEST['txtLaycanFrom']!="")
	{$laycanfromdate     	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLaycanFrom']));}
    else{$laycanfromdate  	 = "1970-01-01 00:00:00";}
	
	if($_REQUEST['txtLaycanTo']!="")
	{$laycantodate     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLaycanTo']));}
    else{$laycantodate  	 = "1970-01-01 00:00:00";}
	
	$txtDrftResAsPerCP 	     = addslashes(trim($_REQUEST['txtDrftResAsPerCP']));
	$txtLoadRateCP	 	     = addslashes(trim($_REQUEST['txtLoadRateCP']));
	$txtDischargeRateCP	     = addslashes(trim($_REQUEST['txtDischargeRateCP']));
	$txtActualArrival	     = addslashes(trim($_REQUEST['txtActualArrival']));
	$txtNorTendered		     = addslashes(trim($_REQUEST['txtNorTendered']));
	$txtDelPlacePort	     = addslashes(trim($_REQUEST['txtDelPlacePort']));
	$txtDelPlacePortData	 = addslashes(trim($_REQUEST['txtDelPlacePortData']));
	$txtDelFoDo				 = addslashes(trim($_REQUEST['txtDelFoDo']));
	$txtDelFoDoData	 		 = addslashes(trim($_REQUEST['txtDelFoDoData']));
	$txtDelDateTime		     = addslashes(trim($_REQUEST['txtDelDateTime']));
	$txtActualArrival2	     = addslashes(trim($_REQUEST['txtActualArrival2']));
	$txtNorTendered2		 = addslashes(trim($_REQUEST['txtNorTendered2']));
	$txtReDelPlacePort	 	 = addslashes(trim($_REQUEST['txtReDelPlacePort']));
	$txtReDelPlacePortData   = addslashes(trim($_REQUEST['txtReDelPlacePortData']));
	$txtReDeliveryFoDo		 = addslashes(trim($_REQUEST['txtReDeliveryFoDo']));
	$txtReDelFoDoData		 = addslashes(trim($_REQUEST['txtReDelFoDoData']));
	$txtReDelDateTime		 = addslashes(trim($_REQUEST['txtReDelDateTime']));
	$tcchklistRemarks		 = addslashes(trim($_REQUEST['txttcchklistRemarks']));
	
	if($_REQUEST['txtActualArrivalDate']!="")
	{$actualArrivalDate      = date("Y-m-d H:i",strtotime($_REQUEST['txtActualArrivalDate']));}
    else{$actualArrivalDate  = "1970-01-01 00:00";}
	
	if($_REQUEST['txtNorTenderedDate']!="")
	{$norTenderedDate        = date("Y-m-d H:i",strtotime($_REQUEST['txtNorTenderedDate']));}
    else{$norTenderedDate    = "1970-01-01 00:00";}
	
	if($_REQUEST['txtDelDateTimeDate']!="")
	{$delDateTimeDate        = date("Y-m-d",strtotime($_REQUEST['txtDelDateTimeDate']));}
    else{$delDateTimeDate    = "1970-01-01";}
	
	if($_REQUEST['txtActualArrivalDate2']!="")
	{$actualArrivalDate2        = date("Y-m-d H:i",strtotime($_REQUEST['txtActualArrivalDate2']));}
    else{$actualArrivalDate2    = "1970-01-01 00:00";}
	
	if($_REQUEST['txtNorTenderedDate2']!="")
	{$norTenderedDate2        = date("Y-m-d H:i",strtotime($_REQUEST['txtNorTenderedDate2']));}
    else{$norTenderedDate2    = "1970-01-01 00:00";}
	
	if($_REQUEST['txtReDelDateTimeDate']!="")
	{$reDelDateTimeDate        = date("Y-m-d",strtotime($_REQUEST['txtReDelDateTimeDate']));}
    else{$reDelDateTimeDate    = "1970-01-01";}
	
	$chartPni		    	 = addslashes(trim($_REQUEST['chartPni']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$idd = $id;
	
	$sql = "select * from check_list_tc where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	if($rec > 0)
	{  
		$rows = mysql_fetch_assoc($res);
		$maxid1 = $rows['CHKLISTTC_ID'];
		
		$sql = "update check_list_tc set REG='".$this->getCheckNullValue($regcheckbox)."', CLASS='".$this->getCheckNullValue($classcheckbox)."', PNI='".$this->getCheckNullValue($pnicheckbox)."', ISM='".$this->getCheckNullValue($ismcheckbox)."', DOC='".$this->getCheckNullValue($doccheckbox)."', ITC='".$this->getCheckNullValue($itccheckbox)."', ISPS='".$this->getCheckNullValue($ispscheckbox)."', LL='".$this->getCheckNullValue($llcheckbox)."', BQ='".$this->getCheckNullValue($bqcheckbox)."', H_M='".$this->getCheckNullValue($hmcheckbox)."', SEA_WEB='".$this->getCheckNullValue($seawebcheckbox)."', CARGODECL_MASTER='".$this->getCheckNullValue($cdecsigmcheckbox)."', REQDOCSSENTTOINS='".$this->getCheckNullValue($reqdoccheckbox)."', CHARTERER_PNI='".$this->getCheckNullValue($selVName)."', LASTPORTAGENT='".$this->getCheckNullValue($txtLastPortAgnt)."', LAYCAN_FROM='".$laycanfromdate."', LAYCAN_TO='".$laycantodate."', DRFTRESASPERCP='".$txtDrftResAsPerCP."', LOAD_RATE_CP='".$txtLoadRateCP."', DIS_RATE_CP='".$txtDischargeRateCP."', DEL_ARRI_TEXT='".$this->getCheckNullValue($txtActualArrival)."', DEL_ARRI_DATA='".$actualArrivalDate."', DEL_NORTEN_TEXT='".$this->getCheckNullValue($txtNorTendered)."', DEL_NORTEN_DATA='".$norTenderedDate."', DEL_PORT_TEXT='".$this->getCheckNullValue($txtDelPlacePort)."', DEL_PORT_DATA='".$txtDelPlacePortData."', DEL_FO_DO_TEXT='".$this->getCheckNullValue($txtDelFoDo)."', DEL_FO_DO_DATA='".$txtDelFoDoData."', DEL_DATETIM_TXT='".$this->getCheckNullValue($txtDelDateTime)."', DEL_DATETIM_DATA='".$delDateTimeDate."', RDEL_ARRI_TEXT='".$this->getCheckNullValue($txtActualArrival2)."', RDEL_ARRI_DATA='".$actualArrivalDate2."', RDEL_NORTEN_TEXT='".$this->getCheckNullValue($txtNorTendered2)."', RDEL_NORTEN_DATE='".$norTenderedDate2."', RDEL_PORT_TEXT='".$this->getCheckNullValue($txtReDelPlacePort)."', RDEL_PORT_DATA='".$txtReDelPlacePortData."', RDEL_FO_DO_TEXT='".$this->getCheckNullValue($txtReDeliveryFoDo)."', RDEL_FO_DO_DATA='".$txtReDelFoDoData."', RDEL_DATETIM_TXT='".$this->getCheckNullValue($txtReDelDateTime)."', RDEL_DATETIM_DATA='".$reDelDateTimeDate."', REMARKS='".$tcchklistRemarks."', UPDATE_ON_DATE=NOW() WHERE CHKLISTTC_ID='".$rows['CHKLISTTC_ID']."' ";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql3 = "delete from check_list_tc_s1 where CHKLISTTC_ID='".$maxid1."'";
		mysql_query($sql3) or die($sql3);
		mysql_query("commit");
	}
	else
	{  
		$sql =	"insert into check_list_tc ( COMID, MODULEID, MCOMPANYID, REG, CLASS, PNI, ISM, DOC, ITC, ISPS, LL, BQ, H_M, SEA_WEB, CARGODECL_MASTER, REQDOCSSENTTOINS, CHARTERER_PNI, LASTPORTAGENT, LAYCAN_FROM, LAYCAN_TO, DRFTRESASPERCP, LOAD_RATE_CP, DIS_RATE_CP, DEL_ARRI_TEXT, DEL_ARRI_DATA, DEL_NORTEN_TEXT, DEL_NORTEN_DATA, DEL_PORT_TEXT, DEL_PORT_DATA, DEL_FO_DO_TEXT, DEL_FO_DO_DATA, DEL_DATETIM_TXT, DEL_DATETIM_DATA, RDEL_ARRI_TEXT, RDEL_ARRI_DATA, RDEL_NORTEN_TEXT, RDEL_NORTEN_DATE, RDEL_PORT_TEXT, RDEL_PORT_DATA, RDEL_FO_DO_TEXT, RDEL_FO_DO_DATA, RDEL_DATETIM_TXT, RDEL_DATETIM_DATA, REMARKS, ADD_ON_DATE ) values ( '".$comid."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$this->getCheckNullValue($regcheckbox)."','".$this->getCheckNullValue($classcheckbox)."','".$this->getCheckNullValue($pnicheckbox)."','".$this->getCheckNullValue($ismcheckbox)."','".$this->getCheckNullValue($doccheckbox)."','".$this->getCheckNullValue($itccheckbox)."','".$this->getCheckNullValue($ispscheckbox)."','".$this->getCheckNullValue($llcheckbox)."','".$this->getCheckNullValue($bqcheckbox)."','".$this->getCheckNullValue($hmcheckbox)."','".$this->getCheckNullValue($seawebcheckbox)."','".$this->getCheckNullValue($cdecsigmcheckbox)."','".$this->getCheckNullValue($reqdoccheckbox)."','".$this->getCheckNullValue($selVName)."','".$this->getCheckNullValue($txtLastPortAgnt)."','".$laycanfromdate."','".$laycantodate."','".$txtDrftResAsPerCP."','".$txtLoadRateCP."','".$txtDischargeRateCP."','".$this->getCheckNullValue($txtActualArrival)."','".$actualArrivalDate."','".$this->getCheckNullValue($txtNorTendered)."','".$norTenderedDate."','".$this->getCheckNullValue($txtDelPlacePort)."','".$txtDelPlacePortData."','".$this->getCheckNullValue($txtDelFoDo)."','".$txtDelFoDoData."','".$this->getCheckNullValue($txtDelDateTime)."','".$delDateTimeDate."','".$this->getCheckNullValue($txtActualArrival2)."','".$actualArrivalDate2."','".$this->getCheckNullValue($txtNorTendered2)."','".$norTenderedDate2."','".$this->getCheckNullValue($txtReDelPlacePort)."','".$txtReDelPlacePortData."','".$this->getCheckNullValue($txtReDeliveryFoDo)."','".$txtReDelFoDoData."','".$this->getCheckNullValue($txtReDelDateTime)."','".$reDelDateTimeDate."','".$tcchklistRemarks."',NOW())";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql1  = "select max(CHKLISTTC_ID) as max from check_list_tc where COMID='".$comid."'";
		$res1  = mysql_query($sql1,$connect);
		$rows1 = mysql_fetch_assoc($res1);
		$maxid1    = $rows1['max'];
	}
	
	$hddnOtherID = $_REQUEST['hddnOtherID'];
	for($i=1 ; $i<=$hddnOtherID ;$i++)
	{
		if($_REQUEST['txtEtaNoticesData_'.$i] != "")
		{
			$sql2 = "insert into check_list_tc_s1 (CHKLISTTC_ID, ETA_NOTICES_TEXT, ETA_NOTICES_DATA, STATUS, UPDATE_ON_DATE) values ('".$maxid1."', '".$_REQUEST['txtEtaNoticesText_'.$i]."', '".date("Y-m-d H:i",strtotime($_REQUEST['txtEtaNoticesData_'.$i]))."', 1, NOW())";
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
		}
	} 
	
	$hddnOtherID2 = $_REQUEST['hddnOtherID2'];
	for($i=1 ; $i<=$hddnOtherID2 ;$i++)
	{
		if($_REQUEST['txtEtaNoticesData2_'.$i] != "")
		{
			$sql3 = "insert into check_list_tc_s1 (CHKLISTTC_ID, ETA_NOTICES_TEXT, ETA_NOTICES_DATA, STATUS, UPDATE_ON_DATE) values ('".$maxid1."', '".$this->getCheckNullValue($_REQUEST['txtEtaNoticesText2_'.$i])."', '".date("Y-m-d H:i",strtotime($_REQUEST['txtEtaNoticesData2_'.$i]))."', 2, NOW())";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	} 
	
	mysql_query("commit");
	return $msg;
}



function insertchecklistLoadportDetailstc($id)
{
	$connect = $this->funConnect();
	
	$comid           		 = $_REQUEST['comid'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$idd = $id;
	
	$sql = "select * from check_list_tc where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."'";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	if($rec > 0)
	{  
		$rows = mysql_fetch_assoc($res);
		$maxid1 = $rows['CHKLISTTC_ID'];
		
		$sql3 = "delete from check_list_tc_slave1 where CHKLISTTC_ID='".$maxid1."'";
		mysql_query($sql3) or die($sql3);
		
		$sql3 = "delete from check_list_tc_slave2 where CHKLISTTC_ID='".$maxid1."'";
		mysql_query($sql3) or die($sql3);
		
		$sql3 = "delete from check_list_tc_slave3 where CHKLISTTC_ID='".$maxid1."'";
		mysql_query($sql3) or die($sql3);
		
		mysql_query("commit");
	
		$txtTotalLPID = $_REQUEST['txtTotalLPID'];
		for($i=1 ; $i<=$txtTotalLPID ;$i++)
		{
			if($_REQUEST['selLPPort_'.$i] != "" && $_REQUEST['txtLPQuantity_'.$i] != "" && $_REQUEST['txtLPRate_'.$i] != "" && $_REQUEST['selLPAgent_'.$i] != "")
			{
				$selLPPort    			 = addslashes(trim($_REQUEST['selLPPort_'.$i]));
				$txtLPQuantity    	     = addslashes(trim($_REQUEST['txtLPQuantity_'.$i]));
				$txtLPRate    			 = addslashes(trim($_REQUEST['txtLPRate_'.$i]));
				$txtLPDraftRes    	     = addslashes(trim($_REQUEST['txtLPDraftRes_'.$i]));
				if($_REQUEST['txtLPLaycanDate_'.$i]!="")
				{$txtLPLaycanDate     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPLaycanDate_'.$i]));}
				else{$txtLPLaycanDate  	 = "1970-01-01 00:00:00";}
				$selLPTerms    			 = addslashes(trim($_REQUEST['selLPTerms_'.$i]));
				$selLPShipper  			 = addslashes(trim($_REQUEST['selLPShipper_'.$i]));
				$selLPAgent    			 = addslashes(trim($_REQUEST['selLPAgent_'.$i]));
				$txtLPAgentPIC    	     = addslashes(trim($_REQUEST['txtLPAgentPIC_'.$i]));
				$txtLPStowageQty		 = addslashes(trim($_REQUEST['txtLPStowageQty_'.$i]));
				$txtLPSPDraftDepFwd		 = addslashes(trim($_REQUEST['txtLPSPDraftDepFwd_'.$i]));
				$txtLPSPDraftDepAft  	 = addslashes(trim($_REQUEST['txtLPSPDraftDepAft_'.$i]));
				$txtLPSPDraftDepMean	 = addslashes(trim($_REQUEST['txtLPSPDraftDepMean_'.$i]));
				$txtLPSPDraftArrivlFwd	 = addslashes(trim($_REQUEST['txtLPSPDraftArrivlFwd_'.$i]));
				$txtLPSPDraftArrivlAft   = addslashes(trim($_REQUEST['txtLPSPDraftArrivlAft_'.$i]));
				$txtLPSPDraftArrivlMean	 = addslashes(trim($_REQUEST['txtLPSPDraftArrivlMean_'.$i]));
				$selLPETANotices		 = addslashes(trim($_REQUEST['selLPETANotices_'.$i]));
				$selLPETANoticeDays		 = addslashes(trim($_REQUEST['selLPETANoticeDays_'.$i]));
				$LPCLubDeccheckbox		 = addslashes(trim($_REQUEST['LPCLubDeccheckbox_'.$i]));
				if($_REQUEST['txtLPETA5Days_'.$i]!="")
				{$txtLPETA5Days     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPETA5Days_'.$i]));}
				else{$txtLPETA5Days  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPETA4Days_'.$i]!="")
				{$txtLPETA4Days     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPETA4Days_'.$i]));}
				else{$txtLPETA4Days  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPETA3Days_'.$i]!="")
				{$txtLPETA3Days     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPETA3Days_'.$i]));}
				else{$txtLPETA3Days  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPETA2Days_'.$i]!="")
				{$txtLPETA2Days     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPETA2Days_'.$i]));}
				else{$txtLPETA2Days  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPETA1Days_'.$i]!="")
				{$txtLPETA1Days     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPETA1Days_'.$i]));}
				else{$txtLPETA1Days  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPIdleCommenced_'.$i]!="")
				{$txtLPIdleCommenced     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPIdleCommenced_'.$i]));}
				else{$txtLPIdleCommenced  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPCompleted_'.$i]!="")
				{$txtLPCompleted     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPCompleted_'.$i]));}
				else{$txtLPCompleted  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPDocOnBoard_'.$i]!="")
				{$txtLPDocOnBoard     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPDocOnBoard_'.$i]));}
				else{$txtLPDocOnBoard  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPSailed_'.$i]!="")
				{$txtLPSailed     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPSailed_'.$i]));}
				else{$txtLPSailed  	 = "1970-01-01 00:00:00";}
				$selIssueingParty		 = addslashes(trim($_REQUEST['selIssueingParty_'.$i]));
				if($_REQUEST['txtLPReceivedFromDeck_'.$i]!="")
				{$txtLPReceivedFromDeck     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPReceivedFromDeck_'.$i]));}
				else{$txtLPReceivedFromDeck  	 = "1970-01-01 00:00:00";}
				if($_REQUEST['txtLPSentToAgent_'.$i]!="")
				{$txtLPSentToAgent     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPSentToAgent_'.$i]));}
				else{$txtLPSentToAgent  	 = "1970-01-01 00:00:00";}
				$txtLPDraftBLRemarks     = addslashes(trim($_REQUEST['txtLPDraftBLRemarks_'.$i]));
				$selAddnlDeadType		 = addslashes(trim($_REQUEST['selAddnlDeadType_'.$i]));
				$txtLPBlQty     		 = addslashes(trim($_REQUEST['txtLPBlQty_'.$i]));
				$txtLPBLReasons  		 = addslashes(trim($_REQUEST['txtLPBLReasons_'.$i]));
				$upstatus    			 = addslashes(trim($_REQUEST['upstatus']));
				
				$sql2 = "insert into check_list_tc_slave1 (CHKLISTTC_ID, PORTID, QUANTITY, LOAD_RATE, DRAFT_RESTRICTION, LAYCAN_START, LOAD_TERMS, SHIPPER, PORT_AGENT, AGENT_PIC, STW_QUANTITY, SP_DRAFT_DEPARTURE_FWD, SP_DRAFT_DEPARTURE_AFT, SP_DRAFT_DEPARTURE_MEAN, SP_DRAFT_ARRIVAL_FWD, SP_DRAFT_ARRIVAL_AFT, SP_DRAFT_ARRIVAL_MEAN, ETA_NOTICES, ETA_NOTICE_DAYS, CLUB_DELARATION, ETA_5_DAYS, ETA_4_DAYS, ETA_3_DAYS, ETA_2_DAYS, ETA_1_DAYS, COMMENCED, COMPLETED, DOC_ON_BOARD, SAILED, ADDNL_DEAD_TYPE, ADDNL_DEAD_QUANTITY, REASON, UPDATE_STATUS, ISSUEING_PARTY, RECVD_FROM_DECK, SENT_TO_AGENT, DRAFT_BL_REMARKS) values ('".$maxid1."', '".$selLPPort."', '".$txtLPQuantity."', '".$txtLPRate."', '".$txtLPDraftRes."', '".$txtLPLaycanDate."', '".$selLPTerms."', '".$selLPShipper."', '".$selLPAgent."', '".$txtLPAgentPIC."', '".$txtLPStowageQty."', '".$txtLPSPDraftDepFwd."', '".$txtLPSPDraftDepAft."', '".$txtLPSPDraftDepMean."', '".$txtLPSPDraftArrivlFwd."', '".$txtLPSPDraftArrivlAft."', '".$txtLPSPDraftArrivlMean."', '".$selLPETANotices."', '".$selLPETANoticeDays."', '".$LPCLubDeccheckbox."', '".$txtLPETA5Days."', '".$txtLPETA4Days."', '".$txtLPETA3Days."', '".$txtLPETA2Days."', '".$txtLPETA1Days."', '".$txtLPIdleCommenced."', '".$txtLPCompleted."', '".$txtLPDocOnBoard."', '".$txtLPSailed."', '".$selAddnlDeadType."', '".$txtLPBlQty."', '".$txtLPBLReasons."', '".$upstatus."', '".$selIssueingParty."', '".$txtLPReceivedFromDeck."', '".$txtLPSentToAgent."', '".$txtLPDraftBLRemarks."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
				
				$sql21  = "select max(CHECKLIST_SLAVEID) as max from check_list_tc_slave1 where CHKLISTTC_ID='".$maxid1."'";
				$res21  = mysql_query($sql21,$connect);
				$rows21 = mysql_fetch_assoc($res21);
				$maxidslave1    = $rows21['max'];
				
				$txtLPIDLEID = $_REQUEST['txtLPIDLEID_'.$i];
				for($j=1 ; $j<=$txtLPIDLEID ;$j++)
				{
					if($_REQUEST['txtLPIdleDateTime_'.$j] != "" && $_REQUEST['txtLPIdleDayQuantity_'.$j] != "" && $_REQUEST['txtLPIdleETCD_'.$j] != "")
					{
						if($_REQUEST['txtLPIdleDateTime_'.$i.'_'.$j]!="")
						{$txtLPIdleDateTime     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPIdleDateTime_'.$i.'_'.$j]));}
						else{$txtLPIdleDateTime  	 = "1970-01-01 00:00:00";}
						
						if($_REQUEST['txtLPIdleETCD_'.$i.'_'.$j]!="")
						{$txtLPIdleETCD     	 	 = date("Y-m-d h:i",strtotime($_REQUEST['txtLPIdleETCD_'.$i.'_'.$j]));}
						else{$txtLPIdleETCD  	 = "1970-01-01 00:00:00";}
						
						$sql3 = "insert into check_list_tc_slave2 (CHECKLIST_SLAVEID, CHKLISTTC_ID, DATE_TIME, QUANTITY, ETCD) values ('".$maxidslave1."', '".$maxid1."', '".$txtLPIdleDateTime."', '".$_REQUEST['txtLPIdleDayQuantity_'.$i.'_'.$j]."', '".$txtLPIdleETCD."')";
						mysql_query($sql3) or die($sql3);
						mysql_query("commit");
					}
				} 
				
				$txtLPBILLLADINGHID = $_REQUEST['txtLPBILLLADINGHID_'.$i];
				for($k=1 ; $k<=$txtLPBILLLADINGHID ;$k++)
				{
					if($_REQUEST['txtLPBillNoOfBL_'.$k] != "" && $_REQUEST['txtLPBillBLDate_'.$k] != "" && $_REQUEST['txtLPBillBLQty_'.$k] != "")
					{
						if($_REQUEST['txtLPBillBLDate_'.$i.'_'.$k]!="")
						{$txtLPBillBLDate     	 	 = date("Y-m-d",strtotime($_REQUEST['txtLPBillBLDate_'.$i.'_'.$k]));}
						else{$txtLPBillBLDate  	 = "1970-01-01";}
						$sql4 = "insert into check_list_tc_slave3 (CHECKLIST_SLAVEID, CHKLISTTC_ID, NO_OF_BL, BL_DATE, BL_QTY) values ('".$maxidslave1."', '".$maxid1."', '".$_REQUEST['txtLPBillNoOfBL_'.$i.'_'.$k]."', '".$txtLPBillBLDate."', '".$_REQUEST['txtLPBillBLQty_'.$i.'_'.$k]."')";
						mysql_query($sql4) or die($sql4);
						mysql_query("commit");
					}
				} 
				
			}
		} 
	}
	
	mysql_query("commit");
	return $msg;
}


function getFreightInvoiceType()
{
	$state = array('Initial Freight'=>'Initial Freight', 'Final Freight'=>'Final Freight', 'Subsiquent Dr./Cr.'=>'Subsiquent Dr./Cr.', 'Port DA'=>'Debit Note', 'Credit Note'=>'Credit Note', 'Adjustment'=>'Adjustment');
	$selIType = @$_REQUEST['selIType'];
	echo '<option value="">---Select from list---</option>';
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selIType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getBusinessTypeList1($selBType)
{
	$state = array('1'=>'Gas', '2'=>'Tanker', '3'=>'Dry Cargo');
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selBType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getBusinessTypeBasedOnID1($id)
{
	$state = array('1'=>'Gas', '2'=>'Tanker', '3'=>'Dry Cargo');
	return $state[$id];
}



function InsertVesselTypeMasterRecords()
{
	$connect				= $this->funConnect();
 	$txtVesselType 			= addslashes(trim($_REQUEST['txtVesselType']));
	$selBusinessType	 	= addslashes(trim($_REQUEST['selBusinessType']));
	$selStatus		 		= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into vessel_type_master (VesselType, Status, BusinessType) values ('".$txtVesselType."', '".$selStatus."', '".$selBusinessType."')";
	mysql_query($sql) or die($sql);
	mysql_query("commit"); 
	return $msg;
}

function displayVesselTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="vtype" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="30%"  >Name</th>';
	echo '<th align="left" valign="middle" width="30%"  >Business Type</th>';
	echo '<th align="left" valign="middle" width="30%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	
	$sql = "select * from vessel_type_master order by Status, VesselType";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['VesselTypeId'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VesselType'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$this->getBusinessTypeBasedOnID1($rows['BusinessType']).'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['Status'] == 1)
				{
					echo 'Active';
				}
				else
				{
					echo 'In-active';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatevesseltype.php?id='.$rows['VesselTypeId'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>'; 
}

function updateVesselTypeMasterRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
 	$txtVesselType 			= addslashes(trim($_REQUEST['txtVesselType']));
	$selBusinessType	 	= addslashes(trim($_REQUEST['selBusinessType']));
	$selStatus		 		= addslashes(trim($_REQUEST['selStatus']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	
	$sql = "update vessel_type_master set VesselType='".$txtVesselType."', Status='".$selStatus."', BusinessType='".$selBusinessType."' where VesselTypeId='".$id."'";
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}

function viewVesselTypeMasterData($id)
{
	$connect = $this->funConnect();
	$sql = "select * from vessel_type_master where VesselTypeId='".$id."'";
	$result = mysql_query($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['VesselTypeId'];
		$this->var_2 = $rows['VesselType'];
		$this->var_3 = $rows['BusinessType'];
		$this->var_4 = $rows['Status'];
	}
}


function getVesselTypeListJson()
{
	$connect   = $this->funconnect();	
	$state = array('1'=>'Gas', '2'=>'Tanker', '3'=>'Dry Cargo');
	$a = array();
	while($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		$sql = "select VesselTypeId, VesselType from vessel_type_master where BusinessType='".$key."'";
		$res  = mysql_query($sql);
		while($rows = mysql_fetch_assoc($res))
		{
		$a[$key][] = array('id' => $rows['VesselTypeId'], 'name' => $rows['VesselType']);
		}
	}
	echo json_encode($a);
}


function getVesselListJsonBasedOnBusinessType()
{
	$connect   = $this->funconnect();	
	$state = array('1'=>'Gas', '2'=>'Tanker', '3'=>'Dry Cargo');
	$a = array();
	while($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		$sql = "select VESSEL_IMO_ID, VESSEL_NAME from vessel_imo_master where BUSINESSTYPEID='".$key."'";
		$res  = mysql_query($sql);
		while($rows = mysql_fetch_assoc($res))
		{
		$a[$key][] = array('id' => $rows['VESSEL_IMO_ID'], 'name' => $rows['VESSEL_NAME']);
		}
	}
	echo json_encode($a);
}



function getCargoListJson()
{
	$connect   = $this->funconnect();	
	$state = array('1'=>'Gas', '2'=>'Tanker', '3'=>'Dry Cargo');
	$a = array();
	while($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		$sql = "select MATERIALID, MATERIAL_CODE_DESC from cargo_master where MATERIAL_TYPEID='".$key."'  order by MATERIAL_CODE_DESC ";
		$res  = mysql_query($sql);
		while($rows = mysql_fetch_assoc($res))
		{
		$a[$key][] = array('id' => $rows['MATERIALID'], 'name' => $rows['MATERIAL_CODE_DESC']);
		}
	}
	echo json_encode($a);
}



function updateVesselMainMasterTankers()
{
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	
	//echo '<pre>';print_r($_REQUEST);die;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;
	
	$sql1 = "delete from vessel_master_tankers_slave where VESSEL_IMO_ID=".$id;
	mysql_query($sql1);
	$sql1 = "delete from vessel_master_tankers where VESSEL_IMO_ID=".$id;
	mysql_query($sql1);
	
	
	$txtDOC = date("Y-m-d",strtotime($_REQUEST['txtDOC']));
	if($_REQUEST['txtDOC'] == ""){
		$txtDOC = "1970-01-01";
	}else{
		$txtDOC = $txtDOC;
	}
	
	$txtDateDelivered = date("Y-m-d",strtotime($_REQUEST['txtDateDelivered']));
	if($_REQUEST['txtDateDelivered'] == ""){
		$txtDateDelivered = "1970-01-01";
	}else{
		$txtDateDelivered = $txtDateDelivered;
	}
	
	$txtClassSOCChnageDate = date("Y-m-d",strtotime($_REQUEST['txtClassSOCChnageDate']));
	if($_REQUEST['txtClassSOCChnageDate'] == ""){
		$txtClassSOCChnageDate = "1970-01-01";
	}else{
		$txtClassSOCChnageDate = $txtClassSOCChnageDate;
	}
	
	$txtSurveyDate = date("Y-m-d",strtotime($_REQUEST['txtSurveyDate']));
	if($_REQUEST['txtSurveyDate'] == ""){
		$txtSurveyDate = "1970-01-01";
	}else{
		$txtSurveyDate = $txtSurveyDate;
	}
	
	$txtDryDockDate = date("Y-m-d",strtotime($_REQUEST['txtDryDockDate']));
	if($_REQUEST['txtDryDockDate'] == ""){
		$txtDryDockDate = "1970-01-01";
	}else{
		$txtDryDockDate = $txtDryDockDate;
	}
	
	$txtNextDryDockDate = date("Y-m-d",strtotime($_REQUEST['txtNextDryDockDate']));
	if($_REQUEST['txtNextDryDockDate'] == ""){
		$txtNextDryDockDate = "1970-01-01";
	}else{
		$txtNextDryDockDate = $txtNextDryDockDate;
	}
	
	$txtDueSurveyDate = date("Y-m-d",strtotime($_REQUEST['txtDueSurveyDate']));
	if($_REQUEST['txtDueSurveyDate'] == ""){
		$txtDueSurveyDate = "1970-01-01";
	}else{
		$txtDueSurveyDate = $txtDueSurveyDate;
	}
	
	$txtAnnualSurveyDate = date("Y-m-d",strtotime($_REQUEST['txtAnnualSurveyDate']));
	if($_REQUEST['txtAnnualSurveyDate'] == ""){
		$txtAnnualSurveyDate = "1970-01-01";
	}else{
		$txtAnnualSurveyDate = $txtAnnualSurveyDate;
	}
	
	$txtExpiryStatDate = date("Y-m-d",strtotime($_REQUEST['txtExpiryStatDate']));
	if($_REQUEST['txtExpiryStatDate'] == ""){
		$txtExpiryStatDate = "1970-01-01";
	}else{
		$txtExpiryStatDate = $txtExpiryStatDate;
	}
	
	$txtClassSOCChnageDate = date("Y-m-d",strtotime($_REQUEST['txtClassSOCChnageDate']));
	if($_REQUEST['txtClassSOCChnageDate'] == ""){
		$txtClassSOCChnageDate = "1970-01-01";
	}else{
		$txtClassSOCChnageDate = $txtClassSOCChnageDate;
	}
	
	$txtLastPortStateDate = date("Y-m-d",strtotime($_REQUEST['txtLastPortStateDate']));
	if($_REQUEST['txtLastPortStateDate'] == ""){
		$txtLastPortStateDate = "1970-01-01";
	}else{
		$txtLastPortStateDate = $txtLastPortStateDate;
	}
	
	
	$txtLastSireDate = date("Y-m-d",strtotime($_REQUEST['txtLastSireDate']));
	if($_REQUEST['txtLastSireDate'] == ""){
		$txtLastSireDate = "1970-01-01";
	}else{
		$txtLastSireDate = $txtLastSireDate;
	}
	
	$txtLastCDIDate = date("Y-m-d",strtotime($_REQUEST['txtLastCDIDate']));
	if($_REQUEST['txtLastCDIDate'] == ""){
		$txtLastCDIDate = "1970-01-01";
	}else{
		$txtLastCDIDate = $txtLastCDIDate;
	}
	
	
	$sql2 = "insert into vessel_master_tankers (VESSEL_IMO_ID, UPDATEONDATE, PREVIOUS_NAME, DATEOFCHANGE, DATEOFDELIVERY, BUILDER, REGISTRY_PORT, CALL_SIGN, PHONE_NO, FAXNO, TELEX_NO, EMAIL_ADDRESS, HULL_TYPE, CLASS_NOTATION, PREV_CLA_SOC_ID, DATEOFCLASSCHANGE, IMO_TYPE, RDO_ICE_CLASS, ICE_CLASS, DRY_DOCK_DATE, DRY_DOCK_PORT, NEXT_DRY_DOCK_DATE, SURVEY_DATE, DUE_SURVEY_DATE, ANNUAL_SURVEY_DATE, OVERALL_RATING, RDOIS_STATEMENT, EXPIRY_STAT_DATE, LBP_LENGTH, BEAM, MODULER_DEPTH, KEEL_KTM, KTM_COLLAPSED, BCENTER_MANIFOLD, SCENTER_MANIFOLD, FCENTER_MANIFOLD, LIGHTSHIP_1, LIGHTSHIP_2, LIGHTSHIP_3, BALLAST_1, BALLAST_2, BALLAST_3, SDRAFT_1, SDRAFT_2, SDRAFT_3, FWA_SUMMER, TPC_SUMMER, FULL_MAST_1, FULL_MAST_2, FULL_MAST_3, COLLAPSED_MAST_1, COLLAPSED_MAST_2, COLLAPSED_MAST_3, NET_TONNAGE, GROSS_TONNAGE, REGROSS_TONNAGE, CANAL_TONNAGE, NET_SCNT, PCN_TONNAGE, FREEBOARD_1, FREEBOARD_2, FREEBOARD_3, FREEBOARD_4, FREEBOARD_5, DRAFT_1, DRAFT_2, DRAFT_3, DRAFT_4, DRAFT_5, DEADWEIGHT_1, DEADWEIGHT_2, DEADWEIGHT_3, DEADWEIGHT_4, DEADWEIGHT_5, DISPLACEMENT_1, DISPLACEMENT_2, DISPLACEMENT_3, DISPLACEMENT_4, DISPLACEMENT_5, RDODEADWEIGHT, ASSDEADWEIGHT, REGISTEREDOWNER, TECHNICALOPERATOR, COMMERCIALOPERATOR, DISPONENTOWNER, PROPULTION_FUEL, PLANT_FUEL, IFO_CAPACITY, DO_CAPACITY, PITCHTYPE, P_I_CLUB, P_I_COVERAGE, LAST_PORT_STATE_DATE, LAST_PORT_STATE_PLACE, REPORTED_DETAILS, RDOREPORTED, RDOACCIDENT, ACCIDENT_DETAILS, RDOGROUNDING, GROUNDING_DETAILS, RDOPOLUTION, POLUTION_DETAILS, RDOCASUALTY, CASUALTY_DETAILS, LAST_SIRE_DATE, SIRE_PORT, LAST_CDI_DATE, CDI_PORT, MOORNO_1, MOORNO_2, MOORNO_3, MOORNO_4, MOORDIAMETER_1, MOORDIAMETER_2, MOORDIAMETER_3, MOORDIAMETER_4, MOORMATERIAL_1, MOORMATERIAL_2, MOORMATERIAL_3, MOORMATERIAL_4, MOORLENGTH_1, MOORLENGTH_2, MOORLENGTH_3, MOORLENGTH_4, MOORBREAKSTREANGTH_1, MOORBREAKSTREANGTH_2, MOORBREAKSTREANGTH_3, MOORBREAKSTREANGTH_4, MOORNO1_1, MOORNO1_2, MOORNO1_3, MOORNO1_4, MOORDIAMETER1_1, MOORDIAMETER1_2, MOORDIAMETER1_3, MOORDIAMETER1_4, MOORMATERIAL1_1, MOORMATERIAL1_2, MOORMATERIAL1_3, MOORMATERIAL1_4, MOORLENGTH1_1, MOORLENGTH1_2, MOORLENGTH1_3, MOORLENGTH1_4, MOORBREAKSTREANGTH1_1, MOORBREAKSTREANGTH1_2, MOORBREAKSTREANGTH1_3, MOORBREAKSTREANGTH1_4, MOORNO2_1, MOORNO2_2, MOORNO2_3, MOORNO2_4, MOORDIAMETER2_1, MOORDIAMETER2_2, MOORDIAMETER2_3, MOORDIAMETER2_4, MOORMATERIAL2_1, MOORMATERIAL2_2, MOORMATERIAL2_3, MOORMATERIAL2_4, MOORLENGTH2_1, MOORLENGTH2_2, MOORLENGTH2_3, MOORLENGTH2_4, MOORBREAKSTREANGTH2_1, MOORBREAKSTREANGTH2_2, MOORBREAKSTREANGTH2_3, MOORBREAKSTREANGTH2_4, MOORNO3_1, MOORNO3_2, MOORNO3_3, MOORNO3_4, MOORDIAMETER3_1, MOORDIAMETER3_2, MOORDIAMETER3_3, MOORDIAMETER3_4, MOORMATERIAL3_1, MOORMATERIAL3_2, MOORMATERIAL3_3, MOORMATERIAL3_4, MOORLENGTH3_1, MOORLENGTH3_2, MOORLENGTH3_3, MOORLENGTH3_4, MOORBREAKSTREANGTH3_1, MOORBREAKSTREANGTH3_2, MOORBREAKSTREANGTH3_3, MOORBREAKSTREANGTH3_4, MOORFAIRNO_1, MOORFAIRNO_2, MOORFAIRNO_3, MOORFAIRNO_4, MOORFAIRSWL_1, MOORFAIRSWL_2, MOORFAIRSWL_3, MOORFAIRSWL_4, CLOSED_CHOCK_SWL, CLOSED_CHOCK_SIZE, BOLLARDSWL, HPBOWTHRUSTER, KWBOWTHRUSTER, HPSTERNTHRUSTER, KWSTERNTHRUSTER, CHAINSTOPPER, CHAINSTOPPERTYPE, LOADCHAINSTOPPER, SIZECHAINSTOPPER, DISTANCECHAINSTOPPER, RDOOCIMF, RDOOCIMFSIZE, OCIMF_SIZE, CCRANE_NUMBER, CCRANE_SWL, CCRANE_LOCATION, CCRANE_OUTREACH, RDOOCIMFICS, ETSF_TYPE, ETSF_SWL, ETSA_TYPE_AFT, ETSA_SWL_AFT, SHACKLESCABLENO, SHACKLESSCABLENO, MOORWINNO_1, MOORWINNO_2, MOORWINNO_3, MOORWINNO_4, MOORBRAKECAP_1, MOORBRAKECAP_2, MOORBRAKECAP_3, MOORBRAKECAP_4, MOORDRUMS_1, MOORDRUMS_2, MOORDRUMS_3, MOORDRUMS_4, MOORBITTNO_1, MOORBITTNO_2, MOORBITTNO_3, MOORBITTNO_4, MOORSWL_1, MOORSWL_2, MOORSWL_3, MOORSWL_4, RDOGASSYSTEM, IGS_SUPPLIED, CRUDEOILWASHING, RDOBULKHEAD, BULKHEAD, CAPACITY_98, CUBIC_CAPACITY, SLOP_CAPACITY98, OIL_TANKCAPACITY98, RDOMARPOLANNEX, NO_OF_CRUDE_PRODUCT, CARGORATE_PERMANIFOLD, CARGOTANKRESTRICTIONS, RDOCARGOTANKRESTRICTIONS, PUMPSNO_1, PUMPSNO_2, PUMPSNO_3, PUMPSNO_4, PUMPSTYPE_1, PUMPSTYPE_2, PUMPSTYPE_3, PUMPSTYPE_4, PUMPSCAPACITY_1, PUMPSCAPACITY_2, PUMPSCAPACITY_3, PUMPSCAPACITY_4, NO_OF_CARGO_PUMPS, RDOTANKINNAGECCR, RDOSHIPOPERATEUNDERCLOSED, RDOCARGOCONTROLROOM, RDOOVERFILLALARM, OVERFILLALARM, TYPE_OF_GAUGING_SYSTEM, RDOVAPORRETURNSYSTEM, NO_OF_VRS, SIZE_OF_VRS, TYPE_OF_VENTING_SYSTEM, CARGO_CONNECTION_PER_SIDE, SIZE_OF_CARGO_CONNECTION, MATERIAL_OF_MANIFOLDS, RDOOCIMFEDITION, MANIFOLDS_DISTANCE, SHIPS_RAIL_MANIFOLD, MANIFOLD_SHIPSIDE_DISTANCE, TOPRAIL_CENTER_MANIFOLD, HEIGHT_AT_BALLAST, HEIGHT_AT_SDWT, NUM_SIZE_REDUCERS, RDOFITTEDSTERMMANIFOLD, FITTEDSTERMMANIFOLD, TYPEODCARGOHEATING, TANKCOILED, RDOTANKCOILED, MAXIMUMTEMPRATURE, RDOTANKCOATING1, RDOTANKCOATING2, RDOTANKCOATING3, COATINGTYPE_1, COATINGTYPE_2, COATINGTYPE_3,  COATINGEXTENT_1, COATINGEXTENT_2, COATINGEXTENT_3, COATINGTYPEUSED, RDOPUBLICATIONS, RDOOWNERWARRANT, MASTER_NATIONALITY, OFFICER_NATIONALITY, CREW_NATIONALITY, MANNING_AGENCY, WORKING_LANGUAGE, RDOUNDERSTAND_ENGLISH, ITF_SPECIAL_AGREEMENT, ICSHELICOPTER_AREA, QUALIFIED_INDIVIDUAL, SPILL_RESPONSE, RDOSPILLRESPONSE, RDOAGREEMENTUS, RDOICSHELICOPTER, SEGREGATED_BALLAST, SBT_CAPACITY, SDWT_PERCENT, RDOCHAINSTOPPER, CARGORATE_ALLMANIFOLD, DISTANCE_MAIN_DECK, INMARSAT_NUMBER, MMSI_NUMBER) values ('".$id."', NOW(), '".addslashes(trim($_REQUEST['txtVPName']))."', '".$txtDOC."', '".$txtDateDelivered."', '".$_REQUEST['txtBuilder']."', '".addslashes(trim($_REQUEST['selRegistryPort']))."', '".addslashes(trim($_REQUEST['txtCallSign']))."', '".addslashes(trim($_REQUEST['txtPhoneNo']))."', '".addslashes(trim($_REQUEST['txtFaxNo']))."', '".addslashes(trim($_REQUEST['txtTelexNo']))."', '".addslashes(trim($_REQUEST['txtEmailAddress']))."', '".addslashes(trim($_REQUEST['txtHullType']))."', '".addslashes(trim($_REQUEST['txtClassNotation']))."', '".addslashes(trim($_REQUEST['selPrevCLASS_SOC']))."', '".$txtClassSOCChnageDate."', '".addslashes(trim($_REQUEST['txtIMOType']))."', ".$_REQUEST['rdoIceClass'].", '".addslashes(trim($_REQUEST['txtIceClass']))."', '".$txtDryDockDate."', '".addslashes(trim($_REQUEST['selDryDockPort']))."', '".$txtNextDryDockDate."', '".$txtSurveyDate."', '".$txtDueSurveyDate."', '".$txtAnnualSurveyDate."', '".addslashes(trim($_REQUEST['txtOverallRating']))."', ".$_REQUEST['rdoIsStatement'].", '".$txtExpiryStatDate."', '".addslashes(trim($_REQUEST['txtLBPLength']))."', '".addslashes(trim($_REQUEST['txtBeam']))."', '".addslashes(trim($_REQUEST['txtMDepth']))."', '".addslashes(trim($_REQUEST['txtKeelKTM']))."', '".addslashes(trim($_REQUEST['txtKtmCollapsed']))."', '".addslashes(trim($_REQUEST['txtBCenterManifold']))."', '".addslashes(trim($_REQUEST['txtSCenterManifold']))."', '".addslashes(trim($_REQUEST['txtFCenterManifold']))."', '".addslashes(trim($_REQUEST['txtLightship_1']))."', '".addslashes(trim($_REQUEST['txtLightship_2']))."', '".addslashes(trim($_REQUEST['txtTropicalid_3']))."', '".addslashes(trim($_REQUEST['txtBallast_1']))."', '".addslashes(trim($_REQUEST['txtBallast_2']))."', '".addslashes(trim($_REQUEST['txtBallast_3']))."', '".addslashes(trim($_REQUEST['txtSummer_1']))."', '".addslashes(trim($_REQUEST['txtSummer_2']))."', '".addslashes(trim($_REQUEST['txtSummer_3']))."', '".addslashes(trim($_REQUEST['txtFWASummer']))."', '".addslashes(trim($_REQUEST['txtTPCSummer']))."', '".addslashes(trim($_REQUEST['txtFULL_MAST_1']))."', '".addslashes(trim($_REQUEST['txtFULL_MAST_2']))."', '".addslashes(trim($_REQUEST['txtFULL_MAST_3']))."', '".addslashes(trim($_REQUEST['txtCollapsed_mast_1']))."', '".addslashes(trim($_REQUEST['txtCollapsed_mast_2']))."', '".addslashes(trim($_REQUEST['txtCollapsed_mast_3']))."', '".addslashes(trim($_REQUEST['txtNET_TONNAGE']))."', '".addslashes(trim($_REQUEST['txtGROSS_TONNAGE']))."', '".addslashes(trim($_REQUEST['txtREGROSS_TONNAGE']))."', '".addslashes(trim($_REQUEST['txtCANAL_TONNAGE']))."', '".addslashes(trim($_REQUEST['txtNet_SCNT']))."', '".addslashes(trim($_REQUEST['txtPanamaTonnage']))."', '".addslashes(trim($_REQUEST['txtFreeboard_1']))."', '".addslashes(trim($_REQUEST['txtFreeboard_2']))."', '".addslashes(trim($_REQUEST['txtFreeboard_3']))."', '".addslashes(trim($_REQUEST['txtFreeboard_4']))."', '".addslashes(trim($_REQUEST['txtFreeboard_5']))."', '".addslashes(trim($_REQUEST['txtDraft_1']))."', '".addslashes(trim($_REQUEST['txtDraft_2']))."', '".addslashes(trim($_REQUEST['txtDraft_3']))."', '".addslashes(trim($_REQUEST['txtDraft_4']))."', '".addslashes(trim($_REQUEST['txtDraft_5']))."', '".addslashes(trim($_REQUEST['txtDeadWeight_1']))."', '".addslashes(trim($_REQUEST['txtDeadWeight_2']))."', '".addslashes(trim($_REQUEST['txtDeadWeight_3']))."', '".addslashes(trim($_REQUEST['txtDeadWeight_4']))."', '".addslashes(trim($_REQUEST['txtDeadWeight_5']))."', '".addslashes(trim($_REQUEST['txtDisplacement_1']))."', '".addslashes(trim($_REQUEST['txtDisplacement_2']))."', '".addslashes(trim($_REQUEST['txtDisplacement_3']))."', '".addslashes(trim($_REQUEST['txtDisplacement_4']))."', '".addslashes(trim($_REQUEST['txtDisplacement_5']))."', ".$_REQUEST['rdoIsSDWT'].", '".addslashes(trim($_REQUEST['txtASSDEADWEIGHT']))."', '".addslashes(trim($_REQUEST['txtRegisteredOwner']))."', '".addslashes(trim($_REQUEST['txtTechnicalOperator']))."', '".addslashes(trim($_REQUEST['txtCommercialOperator']))."', '".addslashes(trim($_REQUEST['txtDisponentOwner']))."', '".addslashes(trim($_REQUEST['txtPropultionFuel']))."', '".addslashes(trim($_REQUEST['txtPlantFuel']))."', '".addslashes(trim($_REQUEST['txtIFO_Capacity']))."', '".addslashes(trim($_REQUEST['txtDO_Capacity']))."', ".$_REQUEST['rdoPitch'].", '".addslashes(trim($_REQUEST['txtP_I_CLUB']))."', '".addslashes(trim($_REQUEST['txtP_I_Coverage']))."', '".$txtLastPortStateDate."', '".addslashes(trim($_REQUEST['txtLastPortStatePlace']))."', '".addslashes(trim($_REQUEST['txtReportedDetails']))."', ".$_REQUEST['rdoIsReported'].", ".$_REQUEST['rdoIsAccident'].", '".addslashes(trim($_REQUEST['txtAccidentDetails']))."', ".$_REQUEST['rdoIsGrounding'].", '".addslashes(trim($_REQUEST['txtGroundingDetails']))."', ".$_REQUEST['rdoIsPolution'].", '".addslashes(trim($_REQUEST['txtPolutionDetails']))."', ".$_REQUEST['rdoIsCasualty'].", '".addslashes(trim($_REQUEST['txtCasualtyDetails']))."', '".$txtLastSireDate."', '".addslashes(trim($_REQUEST['selSirePort']))."', '".addslashes(trim($txtLastCDIDate))."', '".addslashes(trim($_REQUEST['selCDIPort']))."', '".addslashes(trim($_REQUEST['txtMooringNo_1']))."', '".addslashes(trim($_REQUEST['txtMooringNo_2']))."', '".addslashes(trim($_REQUEST['txtMooringNo_3']))."', '".addslashes(trim($_REQUEST['txtMooringNo_4']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter_1']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter_2']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter_3']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter_4']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial_1']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial_2']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial_3']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial_4']))."', '".addslashes(trim($_REQUEST['txtMooringLength_1']))."', '".addslashes(trim($_REQUEST['txtMooringLength_2']))."', '".addslashes(trim($_REQUEST['txtMooringLength_3']))."', '".addslashes(trim($_REQUEST['txtMooringLength_4']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength_1']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength_2']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength_3']))."',  '".addslashes(trim($_REQUEST['txtMooringBreakStrength_4']))."', '".addslashes(trim($_REQUEST['txtMooringNo1_1']))."', '".addslashes(trim($_REQUEST['txtMooringNo1_2']))."', '".addslashes(trim($_REQUEST['txtMooringNo1_3']))."', '".addslashes(trim($_REQUEST['txtMooringNo1_4']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter1_1']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter1_2']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter1_3']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter1_4']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial1_1']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial1_2']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial1_3']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial1_4']))."', '".$_REQUEST['txtMooringLength1_1']."', '".addslashes(trim($_REQUEST['txtMooringLength1_2']))."', '".addslashes(trim($_REQUEST['txtMooringLength1_3']))."', '".addslashes(trim($_REQUEST['txtMooringLength1_4']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength1_1']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength1_2']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength1_3']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength1_4']))."', '".addslashes(trim($_REQUEST['txtMooringNo2_1']))."', '".addslashes(trim($_REQUEST['txtMooringNo2_2']))."', '".addslashes(trim($_REQUEST['txtMooringNo2_3']))."', '".$_REQUEST['txtMooringNo2_4']."', '".addslashes(trim($_REQUEST['txtMooringDiameter2_1']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter2_2']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter2_3']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter2_4']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial2_1']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial2_2']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial2_3']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial2_4']))."', '".addslashes(trim($_REQUEST['txtMooringLength2_1']))."', '".addslashes(trim($_REQUEST['txtMooringLength2_2']))."', '".addslashes(trim($_REQUEST['txtMooringLength2_3']))."', '".addslashes(trim($_REQUEST['txtMooringLength2_4']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength2_1']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength2_2']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength2_3']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength2_4']))."', '".addslashes(trim($_REQUEST['txtMooringNo3_1']))."', '".addslashes(trim($_REQUEST['txtMooringNo3_2']))."', '".addslashes(trim($_REQUEST['txtMooringNo3_3']))."', '".addslashes(trim($_REQUEST['txtMooringNo3_4']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter3_1']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter3_2']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter3_3']))."', '".addslashes(trim($_REQUEST['txtMooringDiameter3_4']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial3_1']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial3_2']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial3_3']))."', '".addslashes(trim($_REQUEST['txtMooringMaterial3_4']))."', '".addslashes(trim($_REQUEST['txtMooringLength3_1']))."', '".addslashes(trim($_REQUEST['txtMooringLength3_2']))."', '".addslashes(trim($_REQUEST['txtMooringLength3_3']))."', '".addslashes(trim($_REQUEST['txtMooringLength3_4']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength3_1']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength3_2']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength3_3']))."', '".addslashes(trim($_REQUEST['txtMooringBreakStrength3_4']))."', '".addslashes(trim($_REQUEST['txtMooringFairNo_1']))."', '".addslashes(trim($_REQUEST['txtMooringFairNo_2']))."', '".addslashes(trim($_REQUEST['txtMooringFairNo_3']))."', '".addslashes(trim($_REQUEST['txtMooringFairNo_4']))."', '".addslashes(trim($_REQUEST['txtMooringFairSWL_1']))."', '".addslashes(trim($_REQUEST['txtMooringFairSWL_2']))."', '".addslashes(trim($_REQUEST['txtMooringFairSWL_3']))."', '".addslashes(trim($_REQUEST['txtMooringFairSWL_4']))."', '".addslashes(trim($_REQUEST['txtClosedChockSWL']))."', '".addslashes(trim($_REQUEST['txtClosedChockSize']))."', '".addslashes(trim($_REQUEST['txtBOllardSWL']))."', '".addslashes(trim($_REQUEST['txtHPOfBowThruster']))."', '".addslashes(trim($_REQUEST['txtKWOfBowThruster']))."', '".addslashes(trim($_REQUEST['txtHPOfSternThruster']))."', '".addslashes(trim($_REQUEST['txtKWOfSternThruster']))."', '".addslashes(trim($_REQUEST['txtChainStopper']))."', '".addslashes(trim($_REQUEST['txtChainStopperType']))."', '".addslashes(trim($_REQUEST['txtLoadChainStopper']))."', '".addslashes(trim($_REQUEST['txtChainStopperSize']))."', '".addslashes(trim($_REQUEST['txtChainStopperDistance']))."', ".$_REQUEST['rdoOCIMF'].", ".$_REQUEST['rdoOCIMFSize'].", '".addslashes(trim($_REQUEST['txtOCIMFSize']))."', '".addslashes(trim($_REQUEST['txtCraneNumber']))."', '".addslashes(trim($_REQUEST['txtCraneSWL']))."', '".addslashes(trim($_REQUEST['txtCraneLocation']))."', '".addslashes(trim($_REQUEST['txtCraneOutreach']))."', ".$_REQUEST['rdoOCIMFICS'].", '".addslashes(trim($_REQUEST['txtETSFType']))."', '".addslashes(trim($_REQUEST['txtETSFSWL']))."', '".addslashes(trim($_REQUEST['txtETSFAFT']))."', '".addslashes(trim($_REQUEST['txtETSFSWLAFT']))."', '".addslashes(trim($_REQUEST['txtShacklesCableNo']))."', '".addslashes(trim($_REQUEST['txtShacklesSCableNo']))."', '".addslashes(trim($_REQUEST['txtMooringWinNo_1']))."', '".addslashes(trim($_REQUEST['txtMooringWinNo_2']))."', '".addslashes(trim($_REQUEST['txtMooringWinNo_3']))."', '".addslashes(trim($_REQUEST['txtMooringWinNo_4']))."', '".addslashes(trim($_REQUEST['txtMooringBrakeCap_1']))."', '".addslashes(trim($_REQUEST['txtMooringBrakeCap_2']))."', '".addslashes(trim($_REQUEST['txtMooringBrakeCap_3']))."', '".addslashes(trim($_REQUEST['txtMooringBrakeCap_4']))."', '".addslashes(trim($_REQUEST['txtMooringDrums_1']))."', '".addslashes(trim($_REQUEST['txtMooringDrums_2']))."', '".addslashes(trim($_REQUEST['txtMooringDrums_3']))."', '".addslashes(trim($_REQUEST['txtMooringDrums_4']))."', '".addslashes(trim($_REQUEST['txtMooringBittNo_1']))."', '".addslashes(trim($_REQUEST['txtMooringBittNo_2']))."', '".addslashes(trim($_REQUEST['txtMooringBittNo_3']))."', '".addslashes(trim($_REQUEST['txtMooringBittNo_4']))."',  '".addslashes(trim($_REQUEST['txtMooringSWL_1']))."', '".addslashes(trim($_REQUEST['txtMooringSWL_2']))."', '".addslashes(trim($_REQUEST['txtMooringSWL_3']))."', '".addslashes(trim($_REQUEST['txtMooringSWL_4']))."', ".$_REQUEST['rdoGasSystem'].", '".addslashes(trim($_REQUEST['txtIGSSupplied']))."', '".addslashes(trim($_REQUEST['txtCrudeOilWashing']))."', ".$_REQUEST['rdoBulkhead'].", '".addslashes(trim($_REQUEST['txtBulkhead']))."', '".addslashes(trim($_REQUEST['txtCapacity98']))."', '".addslashes(trim($_REQUEST['txtCubicCapacity98']))."', '".addslashes(trim($_REQUEST['txtSlopCapacity98']))."', '".addslashes(trim($_REQUEST['txtTankCapacity98']))."', ".$_REQUEST['rdoMARPOLAnnex'].", '".addslashes(trim($_REQUEST['txtNoOfGradeProduct']))."', '".addslashes(trim($_REQUEST['txtCargoRatePerManifold']))."', '".addslashes(trim($_REQUEST['txtCargoTankRestrictions']))."', ".$_REQUEST['rdoCargoTankRestrictions'].", '".addslashes(trim($_REQUEST['txtPumpsNo_1']))."', '".addslashes(trim($_REQUEST['txtPumpsNo_2']))."', '".addslashes(trim($_REQUEST['txtPumpsNo_3']))."', '".addslashes(trim($_REQUEST['txtPumpsNo_4']))."', '".addslashes(trim($_REQUEST['txtPumpsType_1']))."', '".addslashes(trim($_REQUEST['txtPumpsType_2']))."', '".addslashes(trim($_REQUEST['txtPumpsType_3']))."', '".addslashes(trim($_REQUEST['txtPumpsType_4']))."', '".addslashes(trim($_REQUEST['txtPumpsCapacity_1']))."', '".addslashes(trim($_REQUEST['txtPumpsCapacity_2']))."', '".addslashes(trim($_REQUEST['txtPumpsCapacity_3']))."', '".addslashes(trim($_REQUEST['txtPumpsCapacity_4']))."', '".addslashes(trim($_REQUEST['txtNoOfCargoPumps']))."', ".$_REQUEST['rdoTankInnageCCR'].", ".$_REQUEST['rdoShipOperateUnderClosed'].", ".$_REQUEST['rdoCargoControlRoom'].", ".$_REQUEST['rdoOverFillAlarm'].", '".addslashes(trim($_REQUEST['txtOverFillAlarm']))."', '".addslashes(trim($_REQUEST['txtTypeOfGaugingSystem']))."', ".$_REQUEST['rdoVaporReturnSystem'].", '".addslashes(trim($_REQUEST['txtNoOfVRS']))."', '".addslashes(trim($_REQUEST['txtSizeOfVRS']))."', '".addslashes(trim($_REQUEST['txtTypeOfVentingSystem']))."', '".addslashes(trim($_REQUEST['txtCargoConnectionPerSide']))."', '".addslashes(trim($_REQUEST['txtSizeOfCargoConnection']))."', '".addslashes(trim($_REQUEST['txtMaterialOfManifolds']))."', ".$_REQUEST['rdoOCIMFEdition'].", '".addslashes(trim($_REQUEST['txtManifoldsDistance']))."', '".addslashes(trim($_REQUEST['txtShipRailToManifold']))."', '".addslashes(trim($_REQUEST['txtShipSideDistance']))."', '".addslashes(trim($_REQUEST['txtTopRailCenterManifold']))."', '".addslashes(trim($_REQUEST['txtHeightAtBallast']))."', '".addslashes(trim($_REQUEST['txtHeightAtSDWT']))."', '".addslashes(trim($_REQUEST['txtNumSizeReducers']))."', ".$_REQUEST['rdoFittedStermManifold'].", '".addslashes(trim($_REQUEST['txtFittedStermManifold']))."', '".addslashes(trim($_REQUEST['txtTypeOfCargoHeating']))."', '".addslashes(trim($_REQUEST['txtTankCoiled']))."', ".$_REQUEST['rdoTankCoiled'].", '".addslashes(trim($_REQUEST['txtMaximumTempreature']))."', ".$_REQUEST['rdoTankCoating1'].", ".$_REQUEST['rdoTankCoating2'].", ".$_REQUEST['rdoTankCoating3'].", '".addslashes(trim($_REQUEST['txtCoatingType_1']))."', '".addslashes(trim($_REQUEST['txtCoatingType_2']))."', '".addslashes(trim($_REQUEST['txtCoatingType_3']))."', '".addslashes(trim($_REQUEST['txtCoatingExtent_1']))."', '".addslashes(trim($_REQUEST['txtCoatingExtent_2']))."', '".addslashes(trim($_REQUEST['txtCoatingExtent_3']))."', '".addslashes(trim($_REQUEST['txtCoatingTypeUsed']))."', ".$_REQUEST['rdoPublications'].", ".$_REQUEST['rdoOwnerWarrant'].", '".addslashes(trim($_REQUEST['txtMasterNationality']))."', '".addslashes(trim($_REQUEST['txtOfficerNationality']))."', '".addslashes(trim($_REQUEST['txtCrewNationality']))."', '".addslashes(trim($_REQUEST['txtManningAgency']))."', '".addslashes(trim($_REQUEST['txtOnboardWorkingLanguage']))."', ".$_REQUEST['rdoUnderstandEnglish'].", '".addslashes(trim($_REQUEST['txtITFSpecialAgreement']))."', '".addslashes(trim($_REQUEST['txtICSHelicopter']))."', '".addslashes(trim($_REQUEST['txtQualifiedIndividual']))."', '".addslashes(trim($_REQUEST['txtSpillResponse']))."', ".$_REQUEST['rdoSpillResponse'].", ".$_REQUEST['rdoAgreementUS'].", ".$_REQUEST['rdoICSHelicopter'].", '".addslashes(trim($_REQUEST['txtSegregated']))."', '".addslashes(trim($_REQUEST['txtSBTCapacity']))."', '".addslashes(trim($_REQUEST['txtSDWTPercent']))."', ".$_REQUEST['rdoChainStopper'].", '".addslashes(trim($_REQUEST['txtCargoRateAllManifold']))."', '".addslashes(trim($_REQUEST['txtDistanceMainDeck']))."','".addslashes(trim($_REQUEST['txtINMARSAT_Number']))."','".addslashes(trim($_REQUEST['txtMMSI_No']))."')";
		
	mysql_query($sql2) or die($sql2);
	$txtCID	=	addslashes(trim($_REQUEST['txtCID']));
	for($j=1; $j<=$txtCID; $j++)
	{
		if(!empty($_REQUEST['selCert_'.$j]))
		{
			$txtIDate = date("Y-m-d",strtotime($_REQUEST['txtIDate_'.$j]));
			if($_REQUEST['txtIDate_'.$j] == ""){
				$txtIDate = "1970-01-01";
			}else{
				$txtIDate = $txtIDate;
			}
					
			$txtLAIDate = date("Y-m-d",strtotime($_REQUEST['txtLAIDate_'.$j]));
			if($_REQUEST['txtLAIDate_'.$j] == ""){
				$txtLAIDate = "1970-01-01";
			}else{
				$txtLAIDate = $txtLAIDate;
			}
			
			$txtEDate = date("Y-m-d",strtotime($_REQUEST['txtEDate_'.$j]));
			if($_REQUEST['txtEDate_'.$j] == ""){
				$txtEDate = "1970-01-01";
			}else{
				$txtEDate = $txtEDate;
			}
			
			$upload1 = '';
			$name1 = '';
			
		    $txtCRMFILE			= addslashes(trim($_REQUEST['txtCRMFILE_'.$j]));
			$txtCRMNAME			= addslashes(trim($_REQUEST['txtCRMNAME_'.$j]));
			$upload = $this->getUpload($_FILES['attach_file_'.$j]);
			$name = $this->getUploadName($_FILES['attach_file_'.$j]);
			$upload = implode(',',$upload);
			$name = implode(',',$name);
			if($txtCRMFILE != '' && $upload != ''){ $upload1 = $txtCRMFILE.','.$upload;}
			else if($txtCRMFILE == '' && $upload != ''){ $upload1 = $upload;}
			else if($txtCRMFILE != '' && $upload == ''){ $upload1 = $txtCRMFILE;}
			
			if($txtCRMNAME != '' && $name != ''){ $name1 = $txtCRMNAME.','.$name;}
			else if($txtCRMNAME == '' && $name != ''){ $name1 = $name;}
			else if($txtCRMNAME != '' && $name == ''){ $name1 = $txtCRMNAME;}
			
			$qsql1 = "insert into vessel_master_tankers_slave (VESSEL_IMO_ID, CERTIFICATE_ID, DATE_ISSUE, DATE_LAST, DATE_EXPIRY, UPLOAD, UPLOAD_NANE) value('".$id."', '".$_REQUEST['selCert_'.$j]."', '".$txtIDate."', '".$txtLAIDate."', '".$txtEDate."', '".$upload1."', '".$name1."')";
			
		//	echo $qsql1; die();
			mysql_query($qsql1) or die($qsql1);
		}
	}
	
	mysql_query("commit"); 
	return $msg;
	
}

function getCPTypeList()
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from cp_type_master where STATUS=1 order by NAME ");
	echo "<option value = '' >---Select from list---</option>";
	@$selCPType = @$_REQUEST['selCPType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['CP_TYPE_ID'];
		 $value= $rows['NAME'];
		 echo "<option value='".$key."' ";
		 if($key == @$selCPType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getLawArbitrationList()
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from lawarbitration_master_list where STATUS=1 order by LAW_ARBITRATION ");
	echo "<option value = '' >---Select from list---</option>";
	@$selLawArbit = @$_REQUEST['selLawArbit'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['LAWARBITRA_ID'];
		 $value= $rows['LAW_ARBITRATION'];
		 echo "<option value='".$key."' ";
		 if($key == @$selLawArbit){ echo " selected";}
		 echo ">".$value."</option>";
		}
}


function getContractTypeList()
{
	$connect 	= $this->funConnect(); 
	$query 		= mysql_query("select * from contract_type_master where STATUS=1 order by CONTRACT_TYPE ");
	
	echo "<option value = '' >---Select from list---</option>";
	@$selCPType = @$_REQUEST['selCPType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['CONTRACTTYPEID'];
		 $value= $rows['CONTRACT_TYPE'];
		 echo "<option value='".$key."' ";
		 if($key == @$selCPType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getPayableByList()
{
$state = array( 'Charterer' =>'Charterer' , 'Operator' =>'Operator', 'N/A' =>'N/A');
$selAType = @$_REQUEST['selAType'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selAType){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function deleteCharteringEstTcMasterRecords()
{
	$connect		= $this->funConnect();
	$id 			= addslashes(trim($_REQUEST['txttblid']));
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 3;
	$sql = "delete from chartering_estimate_tc_master where TCOUTID='".$id."'";
	$sql1 = "delete from chartering_tc_estimate_slave1 where TCOUTID='".$id."'";
	$sql2 = "delete from chartering_estimate_tc_slave2 where TCOUTID='".$id."'";
	mysql_query($sql);
	mysql_query($sql1);
	mysql_query($sql2);
	mysql_query("commit"); 
	return $msg;
}


function InsertExpenseTypeRecords()
{
	$connect				= $this->funConnect();
 	$txtExpType				= addslashes(trim($_REQUEST['txtExpType']));
	$txtExpDescription		= addslashes(trim($_REQUEST['txtExpDescription']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$sql = "insert into expense_type_master (EXPENSE_TYPE,DESCRIPTION,MODULEID,MCOMPANYID) values ('".$txtExpType."','".$txtExpDescription."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Expense Type Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg;
}



function displayExpenseTypeList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="expense_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="25%"  >Expense Type</th>';
	echo '<th align="left" valign="middle" width="35%"  >Description</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from expense_type_master order by STATUS, EXPENSE_TYPE";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['EXPENSETYPEID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['EXPENSE_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['EXPENSETYPEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['EXPENSETYPEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateexpense_type.php?id='.$rows['EXPENSETYPEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function changeExpenseTypeStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update expense_type_master set STATUS='".$tblstatus."' where  EXPENSETYPEID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Contract Type Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function viewExpenseTypeMasterRecords($id)
{
 	$connect = $this->funConnect();
	$query = "SELECT * FROM expense_type_master where EXPENSETYPEID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['EXPENSE_TYPE'];
		$this->var_2 = $rows['DESCRIPTION'];
	}
}


function updateExpenseTypeRecords()
{
	$connect				= $this->funConnect();
	$txtExpType				= addslashes(trim($_REQUEST['txtExpType']));
	$txtExpDescription		= addslashes(trim($_REQUEST['txtExpDescription']));
	
	$id = $_REQUEST['id'];
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update expense_type_master set EXPENSE_TYPE='".$txtExpType."',DESCRIPTION='".$txtExpDescription."' where EXPENSETYPEID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Expense Type Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function getExpenseTypeList()
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from expense_type_master where STATUS=1 order by EXPENSE_TYPE ");
	echo "<option value = '' >---Select from list---</option>";
	@$selExpenseType = @$_REQUEST['selExpenseType'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['EXPENSETYPEID'];
		 $value= $rows['EXPENSE_TYPE'];
		 echo "<option value='".$key."' ";
		 if($key == @$selExpenseType){ echo " selected";}
		 echo ">".$value."</option>";
		}
}

function getExpenseTypeNameBasedOnID($id)
{
	$connect 	= $this->funConnect();
	$query 		= mysql_query("select * from expense_type_master where EXPENSETYPEID='".$id."'") or die("select * from expense_type_master where EXPENSETYPEID='".$id."'");
	$rows = mysql_fetch_assoc($query);
	return $rows['EXPENSE_TYPE'];
}


function getCompareTableDataTC($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from chartering_estimate_tc_compare where COMID='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getPurposeList()
{
	$this->funConnect();
	$query = mysql_query("select PORT_CALLID, NAME from port_call_purpose_master where STATUS=1 order by Name ");
	echo '<option value = "" >---Select from list---</option>';
	@$selPort = @$_REQUEST['selPort'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['PORT_CALLID'];
		 $value= $rows['NAME'];
	     echo '<option value="'.$key.'"';
		 if($key == @$selPort){ echo " selected";}
		 echo '>'.$value.'</option>';
		}
}

function getMaxAgencyNumberTC()
{
  $this->funConnect();
	
	$query = "SELECT MAX(USERNAMEID) + 1 as USERNAMEID FROM generate_agency_letter_tc where 1=1 "; 
	$result = mysql_query($query);
	$rec=mysql_num_rows($result);
	
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['USERNAMEID'];
	if($rows['USERNAMEID'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}
		}//if ends here.
	else
		{
			$empcode='001';
		}
	}//WHILE ends here.
	
return $empcode;
}


function getPurposeListBasedOnID($id)
{
	$this->funConnect();
	$sql = "select NAME from port_call_purpose_master where PORT_CALLID='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}


function insertGenerateAgencyLetterDetailsTC()
{
	
	$connect 				= $this->funConnect();
	
	$genAgencyId		    = $_REQUEST['genAgencyId'];
	$comid          		= $_REQUEST['comid'];
	$date			        = date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVSLDetails          = addslashes(trim($_REQUEST['txtVName']));
	$vendorid	            = addslashes(trim($_REQUEST['selAList']));
	$PortOfCall	            = addslashes(trim($_REQUEST['selPortOfCall']));
	$PurpOfCall	            = addslashes(trim($_REQUEST['selPurpOfCall']));
	$txtTOfTolerance        = addslashes(trim($_REQUEST['txtTOfTolerance']));
	$selShipOwner           = addslashes(trim($_REQUEST['selShipOwner']));
	$mainDescription        = addslashes(trim(str_replace("…","...", str_replace("”",'"', str_replace("’","'", $_REQUEST['txtMainDescription'])))));
	$status			        = addslashes(trim($_REQUEST['update_status']));
		//echo $status; die();
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "select * from generate_agency_letter_tc where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS = 1 "; 
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);

	if($rec == 0)
	{
		$sql = "insert into generate_agency_letter_tc ( COMID, MODULEID, MCOMPANYID, DATE, VSL_DETAILS, VENDORID, PORT_OF_CALL, PURPOSE_OF_CALL, TERMO_OF_TOLERANCE, USERNAMEID, STATUS, SHIP_OWNER, MAIN_DESCRIPTION, LOGINID) values ('".$comid."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$date."','".$txtVSLDetails."','".$vendorid."','".$PortOfCall."','".$PurpOfCall."','".$txtTOfTolerance."','".$this->getMaxAgencyNumberTC()."','".$status."','".$selShipOwner."','".$mainDescription."','".$_SESSION['uid']."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
	}
	else
	{
		if($genAgencyId !='')
		{
			$sql = "update generate_agency_letter_tc set DATE='".$date."', VSL_DETAILS='".$txtVSLDetails."', VENDORID='".$vendorid."', PORT_OF_CALL='".$PortOfCall."', PURPOSE_OF_CALL='".$PurpOfCall."', TERMO_OF_TOLERANCE='".$txtTOfTolerance."', USERNAMEID='".$this->getMaxAgencyNumberTC()."', STATUS='".$status."', SHIP_OWNER='".$selShipOwner."', MAIN_DESCRIPTION='".$mainDescription."' where GEN_AGENCY_TC_ID='".$genAgencyId."' AND COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
			mysql_query($sql) or die($sql);
			mysql_query("commit");
			
		}
		else
		{
			
			return 1;
		}
	}
	mysql_query("commit");
	return $msg;
}

function insertTCInvoiceHireDetails()
{
	$connect = $this->funConnect();
	
	$comid 			    = addslashes(trim($_REQUEST['comid']));
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType	 		= addslashes(trim($_REQUEST['selIType']));
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$txtInvNo	 	    = addslashes(trim($_REQUEST['txtInvNo']));
	$txtInvDate	 		= date("Y-m-d",strtotime($_REQUEST['txtInvDate']));
	$txtDueDate     	= date('Y-m-d H:i',strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate    = date('Y-m-d H:i',strtotime($_REQUEST['txtExchangeDate']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$selBankingDetails 	= addslashes(trim($_REQUEST['selBankingDetails']));
	$txtHireFrom 		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom']));
	$txtHireTo       	= date('Y-m-d H:i',strtotime($_REQUEST['txtHireTo']));
	$txtHireDays	    = addslashes(trim($_REQUEST['txtHireDays']));
	$txtTotalHire	 	= addslashes(trim($_REQUEST['txtTotalHire']));
	$txtBalanceShipOwner= addslashes(trim($_REQUEST['txtBalanceShipOwner']));
	$txtFinalAmt        = addslashes(trim($_REQUEST['txtFinalAmt']));
	$txtStatus          = addslashes(trim($_REQUEST['txtStatus']));
	$txtInID            = addslashes(trim($_REQUEST['txtInID']));
	$txtRandomid        = addslashes(trim($_REQUEST['randomid']));
	$txtOldExchangeRate = addslashes(trim($_REQUEST['txtOldExchangeRate']));
	$txtOldExchangeCurrency = addslashes(trim($_REQUEST['txtOldExchangeCurrency']));
	$txtOldHireRate     = addslashes(trim($_REQUEST['txtOldHireRate']));
	
	$txtCVEMonth        = addslashes(trim($_REQUEST['txtCVEMonth']));
	$txtCVE_Amt         = addslashes(trim($_REQUEST['txtCVE_Amt']));
	$txtAddrCommPer     = addslashes(trim($_REQUEST['txtAddrCommPer']));
	$txtAddrCommAmt     = addslashes(trim($_REQUEST['txtAddrCommAmt']));
	$txtBroCommPer      = addslashes(trim($_REQUEST['txtBroCommPer']));
	$txtBroCommAmt      = addslashes(trim($_REQUEST['txtBroCommAmt']));
	$txtCVEOffHireMonth = addslashes(trim($_REQUEST['txtCVEOffHireMonth']));
	$txtCVEOFFHIRE_Amt  = addslashes(trim($_REQUEST['txtCVEOFFHIRE_Amt']));
	$ChkShowOffHire     = addslashes(trim($_REQUEST['ChkShowOffHire']));
	$txtCVEOFFHIRE_Amt  = addslashes(trim($_REQUEST['txtCVEOFFHIRE_Amt']));
	$txtCVEOffHireMonth = addslashes(trim($_REQUEST['txtCVEOffHireMonth']));
	$ChkDeliveryBunker  = addslashes(trim($_REQUEST['ChkDeliveryBunker']));
	$ChkReDeliveryBunker= addslashes(trim($_REQUEST['ChkReDeliveryBunker']));
	$ChkBallastBonus    = addslashes(trim($_REQUEST['ChkBallastBonus']));
	$ChkOverConspBunker = addslashes(trim($_REQUEST['ChkOverConspBunker']));
	
	$rdoTaxApplicable         = addslashes(trim($_REQUEST['rdoTaxApplicable']));
	$rdoGSTVAT                = addslashes(trim($_REQUEST['rdoGSTVAT']));
	$txtSGST                  = addslashes(trim($_REQUEST['txtSGST']));
	$txtSGST_Amount           = addslashes(trim($_REQUEST['txtSGST_Amount']));
	$txtCGST                  = addslashes(trim($_REQUEST['txtCGST']));
	$txtCGST_Amount           = addslashes(trim($_REQUEST['txtCGST_Amount']));
	$txtIGST                  = addslashes(trim($_REQUEST['txtIGST']));
	$txtIGST_Amount           = addslashes(trim($_REQUEST['txtIGST_Amount']));
	$txtVAT                   = addslashes(trim($_REQUEST['txtVAT']));
	$txtVAT_Amount            = addslashes(trim($_REQUEST['txtVAT_Amount']));
	$txtAmtPayableWithTax     = addslashes(trim($_REQUEST['txtAmtPayableWithTax']));
	$txtManualVendorName     = addslashes(trim($_REQUEST['txtManualVendorName']));
	
	$selApprovers             = $_REQUEST['selApprovers'];
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$filename = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$filename = implode(',',$filename);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $filename != ''){ $filename1 = $txtCRMNAME1.','.$filename;}
	else if($txtCRMNAME1 == '' && $filename != ''){ $filename1 = $filename;}
	else if($txtCRMNAME1 != '' && $filename == ''){ $filename1 = $txtCRMNAME1;}
	
	$msg = 0;
	$invoiceidd = '';$creatorloginid = '';
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	if($txtInID == '')
	{
		//insert query here.............
		$sql = "insert into invoice_tchire_master (MODULEID, MCOMPANYID, COMID, INVOICE_TYPE, INVOICE_NO, INVOICE_DATE, EXCHANGE_RATE, EXCHANGE_CURRENCY, PAYMENT_TERMS, DESCRIPTION, BANKINGID, DUE_DATE, HIRE_FROM_DATE, HIRE_TO_DATE, HIRE_DAYS, HIRE_INV_AMT, BALANCE_TO_OWNER, FINAL_AMOUNT, STATUS, SHIP_OWNER, ATTEN, RANDOMID, EXCHANGE_DATE, OLD_EXCHANGE_RATE, OLD_EXCHANGE_CURRENCY, OLD_DAILY_HIRE_RATE, CVE_MONTH, CVE_AMOUNT, ADDRESS_COMMISSION, ADDRESS_COMMISSION_AMOUNT, BROKER_COMMISSION, BROKER_COMMISSION_AMOUNT, IS_OFFHIRE, CVE_OFFHIRE_MONTH, CVE_OFFHIRE_AMOUNT, IS_DELIVERYBUNKERS, IS_REDELIVERYBUNKERS, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME, CHK_BALLAST_BONUS, CHK_OVERCONSP, MANUAL_VENDOR_NAME) values ('".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$comid."', '".$selIType."', '".$txtInvNo."', '".$txtInvDate."', '".$this->getCheckNullVal($txtExchangeRate)."', '".$selExchangeCurrency."', '".$txtPaymentTerms."', '".$txtDesc."', '".$selBankingDetails."', '".$txtDueDate."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullVal($txtHireDays)."', '".$this->getCheckNullVal($txtTotalHire)."', '".$this->getCheckNullVal($txtBalanceShipOwner)."', '".$this->getCheckNullVal($txtFinalAmt)."', '".$txtStatus."', '".$selFromOwner."', '".$txtAttenName."', '".$txtRandomid."', '".$txtExchangeDate."', '".$this->getCheckNullVal($txtOldExchangeRate)."', '".$txtOldExchangeCurrency."', '".$this->getCheckNullVal($txtOldHireRate)."', '".$this->getCheckNullVal($txtCVEMonth)."', '".$this->getCheckNullVal($txtCVE_Amt)."', '".$this->getCheckNullVal($txtAddrCommPer)."', '".$this->getCheckNullVal($txtAddrCommAmt)."', '".$this->getCheckNullVal($txtBroCommPer)."', '".$this->getCheckNullVal($txtBroCommAmt)."', '".$this->getCheckNullVal($ChkShowOffHire)."', '".$this->getCheckNullVal($txtCVEOffHireMonth)."', '".$this->getCheckNullVal($txtCVEOFFHIRE_Amt)."', '".$this->getCheckNullVal($ChkDeliveryBunker)."', '".$this->getCheckNullVal($ChkReDeliveryBunker)."', '".$this->getCheckNullVal($rdoTaxApplicable)."', '".$this->getCheckNullVal($rdoGSTVAT)."', '".$this->getCheckNullVal($txtSGST)."', '".$this->getCheckNullVal($txtCGST)."', '".$this->getCheckNullVal($txtIGST)."', '".$this->getCheckNullVal($txtVAT)."', '".$this->getCheckNullVal($txtAmtPayableWithTax)."', '".$this->getCheckNullVal($txtSGST_Amount)."', '".$this->getCheckNullVal($txtCGST_Amount)."', '".$this->getCheckNullVal($txtIGST_Amount)."', '".$this->getCheckNullVal($txtVAT_Amount)."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$upload1."', '".$filename1."', '".$this->getCheckNullVal($ChkBallastBonus)."', '".$this->getCheckNullVal($ChkOverConspBunker)."', '".$txtManualVendorName."')";
		mysql_query($sql) or die($sql);
		$sql1 = "select max(INVOICEID) as max from invoice_tchire_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$invoiceidd = $rows1['max'];
		$creatorloginid  = $_SESSION['uid'];
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if($_REQUEST['txtAddDesAmt_'.$i] > 0)
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$this->getCheckNullVal($txtAddDesAmt)."', 'ADD')";
				mysql_query($sql2);
			}
		}
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if($_REQUEST['txtSubDesAmt_'.$i] > 0)
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$this->getCheckNullVal($txtSubDesAmt)."', 'SUB')";
				mysql_query($sql2);
			}
		}
		
		
		$txtHoldID  = $_REQUEST['txtHoldID'];
		for($i=1;$i<=$txtHoldID;$i++)
		{
			$txtHoldDes	 	  = addslashes(trim($_REQUEST['txtHoldDes_'.$i]));
			$txtHoldDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHoldDesAmt_'.$i]);
			$sql2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtHoldDes."', '".$txtHoldDesAmt."', 'HOLD_CLEANING')";
			mysql_query($sql2);
		}
		
		$txtHireSurveyID  = $_REQUEST['txtHireSurveyID'];
		for($i=1;$i<=$txtHireSurveyID;$i++)
		{
			$txtHireSurveyDes	 	  = addslashes(trim($_REQUEST['txtHireSurveyDes_'.$i]));
			$Chk_Owner_Account  	  = $this->getCheckNullVal($_REQUEST['Chk_Owner_Account_'.$i]);
			$txtHireSurveyDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHireSurveyDesAmt_'.$i]);
			$sql2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY, CHK_OWNER_ACC) values ('".$rows1['max']."', '".$txtHireSurveyDes."', '".$txtHireSurveyDesAmt."', 'HIRE_SURVEY', '".$this->getCheckNullVal($Chk_Owner_Account)."')";
			mysql_query($sql2);
		}
		
		if($ChkShowOffHire==1)
		{
			$txtOFFID = $_REQUEST['txtOFFID'];
			for($i=1 ; $i<=$txtOFFID ;$i++)
			{
				if($_REQUEST['txtOffHireReason_'.$i] != "")
				{
					if($_REQUEST['txtOffHireFrom_'.$i]!="")
					{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
					else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtOffHireTo_'.$i]!="")
					{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
					else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
					
					$sql3 = "insert into invoice_tchire_slave4 (INVOICEID, OFF_REASON, OFF_FROM, OFF_TO, OFF_HIRE_PERCENT, OFF_DAYS, OFF_HIRE) values ('".$rows1['max']."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHirePercent_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
					
					$mysql14 = "select max(INVOICE_SLAVE4ID) as max from invoice_tchire_slave4 where INVOICEID='".$rows1['max']."'";
					$myres14  =  mysql_query($mysql14);
					$myrows14 = mysql_fetch_assoc($myres14);
					$maxid14 = $myrows14['max'];
					
					$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
					for($m=1 ; $m<=$txtDELID ;$m++)
					{
						if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
						{
							$sql15 = "insert into invoice_tchire_slave41 (INVOICE_SLAVE4ID, INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT) values ('".$maxid14."', '".$rows1['max']."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."')";
							mysql_query($sql15) or die($sql15);
							mysql_query("commit");
						}
					}
				}
			}
		}
		
		
		$txtAddOVERCONPID = $_REQUEST['txtAddOVERCONPID'];
		for($i=1;$i<=$txtAddOVERCONPID;$i++)
		{
			if($_REQUEST['selOverConspBunker_'.$i]!='')
			{
				$txtOverConspBunkerQty 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerQty_'.$i]);
				$selOverConspBunker	      = $this->getCheckNullVal($_REQUEST['selOverConspBunker_'.$i]);
				$txtOverConspBunkerPrice  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerPrice_'.$i]);
				$txtOverConspBunkerAmt 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_tchire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selOverConspBunker."', '".$txtOverConspBunkerQty."', '".$txtOverConspBunkerPrice."', '".$txtOverConspBunkerAmt."', 'OVERCONSP')";
				mysql_query($sql2);
			}
		}
		
		$txtDelbid  = $_REQUEST['txtAddDELID'];
		for($i=1;$i<=$txtDelbid;$i++)
		{
			if($_REQUEST['selDELBunker_'.$i]!='')
			{
				$selDELBunker	 	      = $this->getCheckNullVal($_REQUEST['selDELBunker_'.$i]);
				$txtDelBunkerQty	      = $this->getCheckNullVal($_REQUEST['txtDelBunkerQty_'.$i]);
				$txtDelBunkerPrice	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerPrice_'.$i]);
				$txtDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerAmt_'.$i]);
				
				$sql2 = "insert into invoice_tchire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selDELBunker."', '".$txtDelBunkerQty."', '".$txtDelBunkerPrice."', '".$txtDelBunkerAmt."', 'DEL')";
				mysql_query($sql2);
			}
		}
		
		$txtAddREDELID = $_REQUEST['txtAddREDELID'];
		for($i=1;$i<=$txtAddREDELID;$i++)
		{
			if($_REQUEST['selReDELBunker_'.$i]!='')
			{
				$txtReDelBunkerQty	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerQty_'.$i]);
				$selReDELBunker  	      = $this->getCheckNullVal($_REQUEST['selReDELBunker_'.$i]);
				$txtReDelBunkerPrice	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerPrice_'.$i]);
				$txtReDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_tchire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selReDELBunker."', '".$txtReDelBunkerQty."', '".$txtReDelBunkerPrice."', '".$txtReDelBunkerAmt."', 'REDEL')";
				mysql_query($sql2);
			}
		}
		$this->saveRecentWork($selIType." Hire Invoice (".$txtInvNo.") Created Successfully.");
	}
	else
	{
	    $invoiceidd = $txtInID;
		
		$sql_sel = "select APPROVERS, CREATOR from invoice_tchire_master where INVOICEID='".$txtInID."'";
		//echo $txtStatus;die;
		$res_sel = mysql_query($sql_sel) or die($sql_sel);
		$rows_sel = mysql_fetch_assoc($res_sel);
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $rows_sel['APPROVERS'];
		}
		//echo $approversel;die;
		$creatorloginid  = $qrows['CREATOR'];
	    
		$sql = "update invoice_tchire_master set INVOICE_TYPE='".$selIType."', INVOICE_NO='".$txtInvNo."', INVOICE_DATE='".$txtInvDate."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', PAYMENT_TERMS='".$txtPaymentTerms."', DESCRIPTION='".$txtDesc."', BANKINGID='".$selBankingDetails."', DUE_DATE='".$txtDueDate."', HIRE_FROM_DATE='".$txtHireFrom."', HIRE_TO_DATE='".$txtHireTo."', HIRE_DAYS='".$this->getCheckNullVal($txtHireDays)."', HIRE_INV_AMT='".$this->getCheckNullVal($txtTotalHire)."', BALANCE_TO_OWNER='".$this->getCheckNullVal($txtBalanceShipOwner)."', FINAL_AMOUNT='".$this->getCheckNullVal($txtFinalAmt)."', STATUS='".$txtStatus."', SHIP_OWNER='".$selFromOwner."', ATTEN='".$txtAttenName."', EXCHANGE_DATE='".$txtExchangeDate."', OLD_EXCHANGE_RATE= '".$this->getCheckNullVal($txtOldExchangeRate)."', OLD_EXCHANGE_CURRENCY='".$txtOldExchangeCurrency."', OLD_DAILY_HIRE_RATE='".$this->getCheckNullVal($txtOldHireRate)."', CVE_MONTH='".$this->getCheckNullVal($txtCVEMonth)."', CVE_AMOUNT='".$this->getCheckNullVal($txtCVE_Amt)."', ADDRESS_COMMISSION='".$this->getCheckNullVal($txtAddrCommPer)."', ADDRESS_COMMISSION_AMOUNT='".$this->getCheckNullVal($txtAddrCommAmt)."', BROKER_COMMISSION='".$this->getCheckNullVal($txtBroCommPer)."', BROKER_COMMISSION_AMOUNT='".$this->getCheckNullVal($txtBroCommAmt)."', IS_OFFHIRE='".$this->getCheckNullVal($ChkShowOffHire)."', CVE_OFFHIRE_MONTH='".$this->getCheckNullVal($txtCVEOffHireMonth)."', CVE_OFFHIRE_AMOUNT='".$this->getCheckNullVal($txtCVEOFFHIRE_Amt)."', IS_DELIVERYBUNKERS='".$this->getCheckNullVal($ChkDeliveryBunker)."', IS_REDELIVERYBUNKERS='".$this->getCheckNullVal($ChkReDeliveryBunker)."', RDOTAXAPPLICABLE='".$this->getCheckNullVal($rdoTaxApplicable)."', RDOVATGST='".$this->getCheckNullVal($rdoGSTVAT)."', SGST_PERCENT='".$this->getCheckNullVal($txtSGST)."', CGST_PERCENT='".$this->getCheckNullVal($txtCGST)."', IGST_PERCENT='".$this->getCheckNullVal($txtIGST)."', VAT_PERCENT='".$this->getCheckNullVal($txtVAT)."', NET_PAYABLE_TAX='".$this->getCheckNullVal($txtAmtPayableWithTax)."', SGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtSGST_Amount)."', CGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtCGST_Amount)."', IGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtIGST_Amount)."', VAT_PERCENT_AMOUNT='".$this->getCheckNullVal($txtVAT_Amount)."', APPROVERS='".$approversel."', UPLOAD='".$upload1."', UPLOAD_NAME='".$filename1."', CHK_BALLAST_BONUS='".$this->getCheckNullVal($ChkBallastBonus)."', CHK_OVERCONSP='".$this->getCheckNullVal($ChkOverConspBunker)."', MANUAL_VENDOR_NAME='".$txtManualVendorName."' where INVOICEID='".$txtInID."'";
		mysql_query($sql) or die($sql);
		
		$sql1 = "delete from invoice_tchire_slave1  where INVOICEID='".$txtInID."'";
		$sql2 = "delete from invoice_tchire_slave2  where INVOICEID='".$txtInID."'";
		$sql4 = "delete from invoice_tchire_slave4  where INVOICEID='".$txtInID."'";
		$sql41 = "delete from invoice_tchire_slave41  where INVOICEID='".$txtInID."'";
		mysql_query($sql1);
		mysql_query($sql2);
		mysql_query($sql4);
		mysql_query($sql41);
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if($_REQUEST['txtAddDesAmt_'.$i] > 0)
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtAddDes."', '".$this->getCheckNullVal($txtAddDesAmt)."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if($_REQUEST['txtSubDesAmt_'.$i] > 0)
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtSubDes."', '".$this->getCheckNullVal($txtSubDesAmt)."', 'SUB')";
				mysql_query($sql2);
			}
		}
		
		$txtHoldID  = $_REQUEST['txtHoldID'];
		for($i=1;$i<=$txtHoldID;$i++)
		{
			$txtHoldDes	 	  = addslashes(trim($_REQUEST['txtHoldDes_'.$i]));
			$txtHoldDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHoldDesAmt_'.$i]);
			$sql2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtHoldDes."', '".$txtHoldDesAmt."', 'HOLD_CLEANING')";
			mysql_query($sql2);
		}
		
		$txtHireSurveyID  = $_REQUEST['txtHireSurveyID'];
		for($i=1;$i<=$txtHireSurveyID;$i++)
		{
			$txtHireSurveyDes	 	  = addslashes(trim($_REQUEST['txtHireSurveyDes_'.$i]));
			$Chk_Owner_Account  	  = $this->getCheckNullVal($_REQUEST['Chk_Owner_Account_'.$i]);
			$txtHireSurveyDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHireSurveyDesAmt_'.$i]);
			$sql2 = "insert into invoice_tchire_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY, CHK_OWNER_ACC) values ('".$txtInID."', '".$txtHireSurveyDes."', '".$txtHireSurveyDesAmt."', 'HIRE_SURVEY', '".$this->getCheckNullVal($Chk_Owner_Account)."')";
			mysql_query($sql2);
		}
		
		if($ChkShowOffHire==1)
		{
			$txtOFFID = $_REQUEST['txtOFFID'];
			for($i=1 ; $i<=$txtOFFID ;$i++)
			{
				if($_REQUEST['txtOffHireReason_'.$i] != "")
				{
					if($_REQUEST['txtOffHireFrom_'.$i]!="")
					{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
					else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtOffHireTo_'.$i]!="")
					{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
					else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
					
					$sql3 = "insert into invoice_tchire_slave4 (INVOICEID, OFF_REASON, OFF_FROM, OFF_TO, OFF_HIRE_PERCENT, OFF_DAYS, OFF_HIRE) values ('".$txtInID."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHirePercent_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
					
					$mysql14 = "select max(INVOICE_SLAVE4ID) as max from invoice_tchire_slave4 where INVOICEID='".$txtInID."'";
					$myres14  =  mysql_query($mysql14);
					$myrows14 = mysql_fetch_assoc($myres14);
					$maxid14 = $myrows14['max'];
					
					$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
					for($m=1 ; $m<=$txtDELID ;$m++)
					{
						if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
						{
							$sql15 = "insert into invoice_tchire_slave41 (INVOICE_SLAVE4ID, INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT) values ('".$maxid14."', '".$txtInID."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."')";
							mysql_query($sql15) or die($sql15);
							mysql_query("commit");
						}
					}
				}
			}
		}
		
		$txtAddOVERCONPID = $_REQUEST['txtAddOVERCONPID'];
		for($i=1;$i<=$txtAddOVERCONPID;$i++)
		{
			if($_REQUEST['selOverConspBunker_'.$i]!='')
			{
				$txtOverConspBunkerQty 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerQty_'.$i]);
				$selOverConspBunker	      = $this->getCheckNullVal($_REQUEST['selOverConspBunker_'.$i]);
				$txtOverConspBunkerPrice  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerPrice_'.$i]);
				$txtOverConspBunkerAmt 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_tchire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selOverConspBunker."', '".$txtOverConspBunkerQty."', '".$txtOverConspBunkerPrice."', '".$txtOverConspBunkerAmt."', 'OVERCONSP')";
				mysql_query($sql2);
			}
		}
		
		$txtDelbid  = $_REQUEST['txtAddDELID'];
		for($i=1;$i<=$txtDelbid;$i++)
		{
			if($_REQUEST['selDELBunker_'.$i]!='')
			{
				$selDELBunker	 	      = $this->getCheckNullVal($_REQUEST['selDELBunker_'.$i]);
				$txtDelBunkerQty	      = $this->getCheckNullVal($_REQUEST['txtDelBunkerQty_'.$i]);
				$txtDelBunkerPrice	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerPrice_'.$i]);
				$txtDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerAmt_'.$i]);
				
				$sql2 = "insert into invoice_tchire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selDELBunker."', '".$txtDelBunkerQty."', '".$txtDelBunkerPrice."', '".$txtDelBunkerAmt."', 'DEL')";
				mysql_query($sql2);
			}
		}
		
		$txtAddREDELID = $_REQUEST['txtAddREDELID'];
		for($i=1;$i<=$txtAddREDELID;$i++)
		{
			if($_REQUEST['selReDELBunker_'.$i]!='')
			{
				$txtReDelBunkerQty	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerQty_'.$i]);
				$selReDELBunker  	      = $this->getCheckNullVal($_REQUEST['selReDELBunker_'.$i]);
				$txtReDelBunkerPrice	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerPrice_'.$i]);
				$txtReDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_tchire_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selReDELBunker."', '".$txtReDelBunkerQty."', '".$txtReDelBunkerPrice."', '".$txtReDelBunkerAmt."', 'REDEL')";
				mysql_query($sql2);
			}
			
		}
		
	    $this->saveRecentWork($selIType." Hire Invoice (".$txtInvNo.") Updated Successfully.");
	
	}
	
	$this->inactiveUserAlerts('HIRE INVOICE', $_SESSION['uid'], $invoiceidd);
	
	$sql12 = "update vendor_master set BANKING_DETAILS='".$txtBankingDetails."' where CODE='".$txtVendor."' and MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql12) or die($sql12);
	
	mysql_query("commit");
	
	
	//$creatorsarr = array($creatorloginid);
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	$approverarr2 = $this->getUsersWithAuthority('HIRE_INVOICE_CHK_APP_2');
	$appaccountarr = $this->getUsersWithAuthority('HIRE_INVOICE_CHK_ACC');
	
	$url = './hireinvoicetc.php?comid='.$_REQUEST['comid'].'&page='.$_REQUEST['page'].'&randomid='.$_REQUEST['randomid'];
	
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'HIRE INVOICE';
	
	$vesselname = $this->getVesselIMOData($this->getCharteringEstimateTCData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'HIRE INVOICE', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'HIRE INVOICE', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'HIRE INVOICE', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'HIRE INVOICE', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{
		     if(!empty($appaccountarr))
			 {
			     $userarray = $appaccountarr;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'HIRE INVOICE', $currentusername.' Approved '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.')', $invoiceidd);				  
				  }
			 }
		}
	}
	
	return $msg;  
}


function insertTCInvoiceOthersDetails()
{
	$connect = $this->funConnect();
	
	$comid 			    = addslashes(trim($_REQUEST['comid']));
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType	 		= addslashes(trim($_REQUEST['selIType']));
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$txtInvNo	 	    = addslashes(trim($_REQUEST['txtInvNo']));
	$txtInvDate	 		= date("Y-m-d",strtotime($_REQUEST['txtInvDate']));
	$txtDueDate     	= date('Y-m-d H:i',strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate    = date('Y-m-d H:i',strtotime($_REQUEST['txtExchangeDate']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$selBankingDetails 	= addslashes(trim($_REQUEST['selBankingDetails']));
	$txtInvAmt  	    = addslashes(trim($_REQUEST['txtInvAmt']));
	$txtINVVendor       = addslashes(trim($_REQUEST['txtINVVendor']));
	$txtINVidentity     = addslashes(trim($_REQUEST['txtINVidentity']));
	$txtINVShortDesc    = addslashes(trim($_REQUEST['txtINVShortDesc']));
	$txtFinalAmt        = addslashes(trim($_REQUEST['txtFinalAmt']));
	$txtStatus          = addslashes(trim($_REQUEST['txtStatus']));
	$txtInID            = addslashes(trim($_REQUEST['txtInID']));
	$txtRandomid        = addslashes(trim($_REQUEST['randomid']));
	
	
	$rdoTaxApplicable         = addslashes(trim($_REQUEST['rdoTaxApplicable']));
	$rdoGSTVAT                = addslashes(trim($_REQUEST['rdoGSTVAT']));
	$txtSGST                  = addslashes(trim($_REQUEST['txtSGST']));
	$txtSGST_Amount           = addslashes(trim($_REQUEST['txtSGST_Amount']));
	$txtCGST                  = addslashes(trim($_REQUEST['txtCGST']));
	$txtCGST_Amount           = addslashes(trim($_REQUEST['txtCGST_Amount']));
	$txtIGST                  = addslashes(trim($_REQUEST['txtIGST']));
	$txtIGST_Amount           = addslashes(trim($_REQUEST['txtIGST_Amount']));
	$txtVAT                   = addslashes(trim($_REQUEST['txtVAT']));
	$txtVAT_Amount            = addslashes(trim($_REQUEST['txtVAT_Amount']));
	$txtAmtPayableWithTax     = addslashes(trim($_REQUEST['txtAmtPayableWithTax']));
	$selApprovers             = $_REQUEST['selApprovers'];
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$filename = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$filename = implode(',',$filename);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $filename != ''){ $filename1 = $txtCRMNAME1.','.$filename;}
	else if($txtCRMNAME1 == '' && $filename != ''){ $filename1 = $filename;}
	else if($txtCRMNAME1 != '' && $filename == ''){ $filename1 = $txtCRMNAME1;}
	
	$msg = 0;
	$invoiceidd = '';$creatorloginid = '';
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	if($txtInID == '')
	{
		//insert query here.............
		$sql = "insert into invoice_tcother_master (MODULEID, MCOMPANYID, COMID, INVOICE_TYPE, INVOICE_NO, INVOICE_DATE, EXCHANGE_RATE, EXCHANGE_CURRENCY, PAYMENT_TERMS, DESCRIPTION, BANKINGID, DUE_DATE, AMOUNT, FINAL_AMOUNT, STATUS, SHIP_OWNER, ATTEN, RANDOMID, EXCHANGE_DATE, VENDOR, INV_IDENTITY, SHORT_DESC, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME) values ('".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$comid."', '".$selIType."', '".$txtInvNo."', '".$txtInvDate."', '".$this->getCheckNullVal($txtExchangeRate)."', '".$selExchangeCurrency."', '".$txtPaymentTerms."', '".$txtDesc."', '".$selBankingDetails."', '".$txtDueDate."', '".$this->getCheckNullVal($txtInvAmt)."', '".$this->getCheckNullVal($txtFinalAmt)."', '".$txtStatus."', '".$selFromOwner."', '".$txtAttenName."', '".$txtRandomid."', '".$txtExchangeDate."', '".$txtINVVendor."', '".$txtINVidentity."', '".$txtINVShortDesc."', '".$this->getCheckNullVal($rdoTaxApplicable)."', '".$this->getCheckNullVal($rdoGSTVAT)."', '".$this->getCheckNullVal($txtSGST)."', '".$this->getCheckNullVal($txtCGST)."', '".$this->getCheckNullVal($txtIGST)."', '".$this->getCheckNullVal($txtVAT)."', '".$this->getCheckNullVal($txtAmtPayableWithTax)."', '".$this->getCheckNullVal($txtSGST_Amount)."', '".$this->getCheckNullVal($txtCGST_Amount)."', '".$this->getCheckNullVal($txtIGST_Amount)."', '".$this->getCheckNullVal($txtVAT_Amount)."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$upload1."', '".$filename1."')";
		mysql_query($sql) or die($sql);
		
		$sql1 = "select max(INVOICEID) as max from invoice_tcother_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$invoiceidd = $rows1['max'];
		$creatorloginid  = $_SESSION['uid'];
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if($_REQUEST['txtAddDesAmt_'.$i] > 0)
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into invoice_tcother_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$this->getCheckNullVal($txtAddDesAmt)."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if($_REQUEST['txtSubDesAmt_'.$i] > 0)
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into invoice_tcother_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$this->getCheckNullVal($txtSubDesAmt)."', 'SUB')";
				mysql_query($sql2);
			}
		}
		$this->saveRecentWork($selIType." ".$_REQUEST['invtype']." (".$txtInvNo.") Created Successfully.");
	}
	else
	{
		$invoiceidd = $txtInID;
		
		$sql_sel = "select APPROVERS, CREATOR from invoice_tcother_master where INVOICEID='".$txtInID."'";
		$res_sel = mysql_query($sql_sel) or die($sql_sel);
		$rows_sel = mysql_fetch_assoc($res_sel);
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $rows_sel['APPROVERS'];
		}
		$creatorloginid  = $rows_sel['CREATOR'];
		
		$sql = "update invoice_tcother_master set INVOICE_TYPE='".$selIType."', INVOICE_NO='".$txtInvNo."', INVOICE_DATE='".$txtInvDate."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', PAYMENT_TERMS='".$txtPaymentTerms."', DESCRIPTION='".$txtDesc."', BANKINGID='".$selBankingDetails."', DUE_DATE='".$txtDueDate."', AMOUNT='".$this->getCheckNullVal($txtInvAmt)."', VENDOR='".$txtINVVendor."', INV_IDENTITY='".$txtINVidentity."', FINAL_AMOUNT='".$this->getCheckNullVal($txtFinalAmt)."', STATUS='".$txtStatus."', SHIP_OWNER='".$selFromOwner."', ATTEN='".$txtAttenName."', EXCHANGE_DATE='".$txtExchangeDate."', SHORT_DESC='".$txtINVShortDesc."', RDOTAXAPPLICABLE='".$this->getCheckNullVal($rdoTaxApplicable)."', RDOVATGST='".$this->getCheckNullVal($rdoGSTVAT)."', SGST_PERCENT='".$this->getCheckNullVal($txtSGST)."', CGST_PERCENT='".$this->getCheckNullVal($txtCGST)."', IGST_PERCENT='".$this->getCheckNullVal($txtIGST)."', VAT_PERCENT='".$this->getCheckNullVal($txtVAT)."', NET_PAYABLE_TAX='".$this->getCheckNullVal($txtAmtPayableWithTax)."', SGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtSGST_Amount)."', CGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtCGST_Amount)."', IGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtIGST_Amount)."', VAT_PERCENT_AMOUNT='".$this->getCheckNullVal($txtVAT_Amount)."' , APPROVERS='".$approversel."', UPLOAD='".$upload1."', UPLOAD_NAME='".$filename1."' where INVOICEID='".$txtInID."'";
		mysql_query($sql) or die($sql);
		
		$sql1 = "delete from invoice_tcother_slave1  where INVOICEID='".$txtInID."'";
		mysql_query($sql1);
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if($_REQUEST['txtAddDesAmt_'.$i] > 0)
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into invoice_tcother_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtAddDes."', '".$this->getCheckNullVal($txtAddDesAmt)."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if($_REQUEST['txtSubDesAmt_'.$i] > 0)
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into invoice_tcother_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtSubDes."', '".$this->getCheckNullVal($txtSubDesAmt)."', 'SUB')";
				mysql_query($sql2);
			}
		}
		$this->saveRecentWork($selIType." ".$_REQUEST['invtype']." (".$txtInvNo.") Updated Successfully.");
	}
	
	$sql12 = "update vendor_master set BANKING_DETAILS='".$txtBankingDetails."' where CODE='".$txtVendor."' and MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql12) or die($sql12);
	
	mysql_query("commit");
	
	$this->inactiveUserAlerts('OTHER TC INVOICE', $_SESSION['uid'], $invoiceidd);
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	$approverarr2 = $this->getUsersWithAuthority('HIRE_INVOICE_CHK_APP_2');
	$appaccountarr = $this->getUsersWithAuthority('HIRE_INVOICE_CHK_ACC');
	
	$url = './otherinvoicetc.php?comid='.$_REQUEST['comid'].'&page='.$_REQUEST['page']."&randomid=".$_REQUEST['randomid']."&vendor=".$_REQUEST['vendor']."&amount=".$_REQUEST['amount']."&desc=".$_REQUEST['desc']."&invtype=".$_REQUEST['invtype'];
	
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'OTHER TC INVOICE';
	
	$vesselname = $this->getVesselIMOData($this->getCharteringEstimateTCData($_REQUEST['comid'],"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC INVOICE', $currentusername.' sent '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC INVOICE', $currentusername.' sent '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC INVOICE', $currentusername.' sent '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC INVOICE', $currentusername.' sent '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		if($txtStatus == 5)
		{
		     if(!empty($appaccountarr))
			 {
			     $userarray = $appaccountarr;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC INVOICE', $currentusername.' Approved '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.')', $invoiceidd);				  
				  }
			 }
		}
	}
	
	return $msg;  
}


function inserttcOthersPaymentReceivedDetails()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update invoice_tcother_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where INVOICEID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$this->inactiveUserAlerts('OTHER TC INVOICE', $_SESSION['uid'], $txtP_ID);
	
	return $msg; 
}


function InsertCOArouteRecords()
{
	$connect				= $this->funConnect();
 	$txtCOArouteName		= addslashes(trim($_REQUEST['txtCOArouteName']));
	$description			= addslashes(trim($_REQUEST['txtCOArouteDesc']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$sql = "insert into coaroute_master (COAROUTE_NAME,COAROUTE_DESC,MODULEID,MCOMPANYID) values ('".$txtCOArouteName."','".$description."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	$sql1 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','COA Route Record added successfully.',NOW())";
	mysql_query($sql1) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function changeCOArouteStatusRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update coaroute_master set STATUS='".$tblstatus."' where  COAROUTEID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql1 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','COA Route Record Status updated successfully.',NOW())";
	mysql_query($sql1) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}


function displayCOArouteList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="coaroute_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="25%"  >COA Route</th>';
	echo '<th align="left" valign="middle" width="35%"  >Description</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from coaroute_master order by STATUS,COAROUTE_NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['COAROUTEID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['COAROUTE_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['COAROUTE_DESC'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['COAROUTEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['COAROUTEID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatecoaroute_list.php?id='.$rows['COAROUTEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function updateCOArouteRecords()
{
	$connect				= $this->funConnect();
	$txtCOArouteName		= addslashes(trim($_REQUEST['txtCOArouteName']));
	$description			= addslashes(trim($_REQUEST['txtCOArouteDesc']));
	
	$id = $_REQUEST['id'];
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update coaroute_master set COAROUTE_NAME='".$txtCOArouteName."',COAROUTE_DESC='".$description."' where COAROUTEID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql1 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','COA Route Record updated successfully.',NOW())";
	mysql_query($sql1) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewCOArouteMasterRecords($id)
{
 	$connect = $this->funConnect();
	$query = "SELECT * FROM coaroute_master where COAROUTEID='".$id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['COAROUTE_NAME'];
		$this->var_2 = $rows['COAROUTE_DESC'];
	}
}

function insertLoadOptionsMasterDetails()
{
	$connect			= $this->funConnect();
	$txtLoadOptions		= addslashes(trim($_REQUEST['txtLoadOptions']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into loadoption_master (LOADOPTION_NAME,MODULEID,MCOMPANYID) values ('".$txtLoadOptions."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	mysql_query($sql);
	mysql_query("commit");
	return $msg; 
}


function changeLoadOptionMasterStatusRecords()
{
	$connect		= $this->funConnect();
	$tblid			= addslashes(trim($_REQUEST['txttblid']));
	$value			= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1)	{$tblstatus = 2;}
	else {$tblstatus = 1;}	

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	$sql = "update loadoption_master set STATUS='".$tblstatus."' where LOADOPTIONSID='".$tblid."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	mysql_query("commit");
	return $msg;
}



function displayLoadOptionList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="loadoption_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="10%" >#</th>';
	echo '<th align="left" valign="middle" width="60%">Load Options</th>';
	echo '<th align="left" valign="middle" width="20%">Status</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from loadoption_master order by STATUS,LOADOPTION_NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LOADOPTION_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['LOADOPTIONSID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['LOADOPTIONSID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updateLoadOptionlist.php?id='.$rows['LOADOPTIONSID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}





function updateLoadOptionMasterRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
 	$txtLoadOptions			= addslashes(trim($_REQUEST['txtLoadOptions']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update loadoption_master set LOADOPTION_NAME='".$txtLoadOptions."' where LOADOPTIONSID='".$id."' and  MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	mysql_query("commit"); 
	return $msg;
}





function viewLoadOptionRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM loadoption_master where LOADOPTIONSID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['LOADOPTION_NAME'];
	}
}


function getMessageNumberForCOA()
{
  $this->funConnect();
	
	$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM coa_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['MESSAGE_NO'];
	if($rows['MESSAGE_NO'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode ='COA-'.$empcode.'-'.date("Y",time());
		}
	else
		{
			$empcode= 'COA-001-'.date("Y",time());
		}
	}
	
return $empcode;
}



function getMessageNumberForCP()
{
  $this->funConnect();
	
	$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM open_cargo_master where year(ADDONDATE)='".date("Y",time())."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query) or die($query);
	$rec	= mysql_num_rows($result);
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['MESSAGE_NO'];
	if($rows['MESSAGE_NO'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode ='CP-'.$empcode.'-'.date("Y",time());
		}
	else
		{
			$empcode= 'CP-001-'.date("Y",time());
		}
	}
	
return $empcode;
}

function insertCOAestimatesDetails()
{
	$connect = $this->funConnect();
	$coaid 	 = $_REQUEST['coaid'];
	$txtStatus          = $_REQUEST['txtStatus'];
	
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCPDate	 		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	$market_rdo 		= addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	$txtAddnlCRate 		= addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlCRatePer   = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
    $txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	$txtCVE             = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt      	= addslashes(trim($_REQUEST['txtCVEAmt']));
	$txtHidCVEAmt   	= addslashes(trim($_REQUEST['txtHidCVEAmt']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selCargoPlanning   = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	
	$txtSDWTMT 	 	    = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	 		= addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM         = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 	 	= addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT     	 	= addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT    		= addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT    		= addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT           = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT     = addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT  	= addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM 	= addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT		= addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM   = addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT	 	= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT 	= addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT    	= addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT  		= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into freight_cost_estimete_master (FIXTURETYPEID, TRANS_DATE, CP_DATE, MODULEID, MCOMPANYID, ADDED_BY, ADD_ON_DATE, VESSEL_IMO_ID, VESSEL_TYPE, VOYAGE_NO, DWT_SUMMER, DWT_TOPICAL, RDO_CAP, GRAIN_CAP, BALE_CAP, SF, LODABLE, GNRT, LOA, GEAR, BUILD_YEAR, BEAM, TPC, BFULLSPEED, BECOSPEED1, BECOSPEED2, LFULLSPEED, LECOSPEED1, LECOSPEED2, BFOFULLSPEED, BFOECOSPEED1, BFOECOSPEED2, LFOFULLSPEED, LFOECOSPEED1, LFOECOSPEED2, PIFOFULLSPEED, PWFOFULLSPEED, BDOFULLSPEED, BDOECOSPEED1, BDOECOSPEED2, LDOFULLSPEED, LDOECOSPEED1, LDOECOSPEED2, PIDOFULLSPEED, PWDOFULLSPEED, FREIGHT_GROSS, LUMSUM, CARGO_RATE, QUANTITY, CARGO_TYPE, CARGO_ID, DF_QUANTITY, ADDNL_QUANTITY, LADEN_DIST, BALLAST_DIST, LADEN_DAYS, BALLAST_DAYS, TOTAL_PASSAGE_DAYS, IDEAL_DAYS, WORKING_DAYS, TOTAL_DAYS, TOTAL_DISTANCE, FO_CONSP, DO_CONSP, GROSS_PREIGHT_ADJ, DEAD_PREIGHT_ADJ, ADDNL_PREIGHT_ADJ, TOTAL_PREIGHT_ADJ, GROSS_PREIGHT_ADJ_PRMT, DEAD_PREIGHT_ADJ_PRMT, ADDNL_PREIGHT_ADJ_PRMT, TOTAL_PREIGHT_ADJ_PRMT, ADDRESS_COMMISSION_PER, ADDRESS_COMMISSION_AMT, ADDRESS_COMMISSION_PRMT, BROKERAGE_PER, BROKERAGE_AMT, NET_PAYABLE, FINAL_NET_FREIGHT, FINAL_NET_FREIGHT_PRMT, BROKERAGE_COMMISSION_PER, BROKERAGE_COMMISSION_AMT, REVENUES_FREIGHT, VOYAGE_EARNING, DAILY_EARNING, DAILY_VESSEL_OPERATION_EXP, TOTAL_VOYAGE_EARNING, NET_DAILY_EARNING, NET_DAILY_PROFIT, PROFIT_LOSS, RDO_QTY, HIREAGE_AMT, HIREAGE_PERCENT, HIREAGE_PER_AMT, HIREAGE_NETT_AMT, CVE_AMT, CVE_TOTALAMT, BALLAST_BONUS, BUNKER_EXPENSES, PORT_EXPENSES, ADDNL_FREIGHT_PER, ESTIMATE_TYPE, COAID, OPEN_CARGOID, SUMMERDWTMT, SUMMERDWTLT, SUMMERDRAFTM, SUMMERDRAFTFT, TPI_MT_INCH, TPI_LT_INCH, TPC_MT, TPC_LT, CONSTANT_MT, CONSTANT_LT, GRAIN_CAP_CBM, GRAIN_CAP_CFT, ALLOWED_DRAFTM, BUNKER_ROB_MT, CARGO_INTAKE_MT, SF_CBM_MT, SF_CBFT_MT, CARGO_LOADABLE_MT, GROSS_BREAKDOWN, BREAKDOWN_MT, GROSS_HIERAGE_AMOUNT, HIERAGE_CVE, HIERAGE_CVE_AMOUNT, OFF_HIRE_CVE, OFF_HIRE_CVE_AMOUNT, LESS_OFF_HIRE, FINAL_HIERAGE_AMOUNT, HIERAGE_BROKER_PERCENT, HIERAGE_BROKER_AMT, TC_HIRE_DAYS, TC_CP_DATE, TANK_CLEANING_SECA_HRS, TANK_CLEANING_NONSECA_HRS, INERTING_SECA_HRS, INERTING_NONSECA_HRS, GAS_FREEING_SECA_HRS, GAS_FREEING_NONSECA_HRS, HEATING_SECA_HRS, HEATING_NONSECA_HRS, HEATING_SECA_HRS_1, HEATING_NONSECA_HRS_1) values ('".$this->getCheckNullValue($selFType)."', '".$txtDate."', '".$txtCPDate."', '".$this->getCheckNullValue($_SESSION['moduleid'])."', '".$this->getCheckNullValue($_SESSION['company'])."', '".$_SESSION['uid']."', NOW(), '".$this->getCheckNullValue($selVName)."', '".$txtVType."', '".$txtVNo."', '".$this->getCheckNullValue($txtDWTS)."', '".$this->getCheckNullValue($txtDWTT)."', '".$this->getCheckNullValue($rdoCap)."', '".$this->getCheckNullValue($txtGCap)."', '".$this->getCheckNullValue($txtBCap)."', '".$this->getCheckNullValue($txtSF)."', '".$this->getCheckNullValue($txtLoadable)."', '".$this->getCheckNullValue($txtGNRT)."', '".$this->getCheckNullValue($txtLOA)."', '".$this->getCheckNullValue($txtGear)."', '".$txtBuiltYear."', '".$this->getCheckNullValue($txtBeam)."', '".$this->getCheckNullValue($txtTPC)."', '".$this->getCheckNullValue($txtBFullSpeed)."', '".$this->getCheckNullValue($txtBEcoSpeed1)."', '".$this->getCheckNullValue($txtBEcoSpeed2)."', '".$this->getCheckNullValue($txtLFullSpeed)."', '".$this->getCheckNullValue($txtLEcoSpeed1)."', '".$this->getCheckNullVal($txtLEcoSpeed2)."', '".$this->getCheckNullVal($txtBFOFullSpeed)."', '".$this->getCheckNullVal($txtBFOEcoSpeed1)."', '".$this->getCheckNullVal($txtBFOEcoSpeed2)."', '".$this->getCheckNullVal($txtLFOFullSpeed)."', '".$this->getCheckNullVal($txtLFOEcoSpeed1)."', '".$this->getCheckNullVal($txtLFOEcoSpeed2)."', '".$this->getCheckNullValue($txtPIFOFullSpeed)."', '".$this->getCheckNullValue($txtPWFOFullSpeed)."','".$this->getCheckNullValue($txtBDOFullSpeed)."','".$this->getCheckNullValue($txtBDOEcoSpeed1)."', '".$this->getCheckNullVal($txtBDOEcoSpeed2)."', '".$this->getCheckNullVal($txtLDOFullSpeed)."', '".$this->getCheckNullVal($txtLDOEcoSpeed1)."', '".$this->getCheckNullVal($txtLDOEcoSpeed2)."', '".$this->getCheckNullVal($txtPIDOFullSpeed)."', '".$this->getCheckNullVal($txtPWDOFullSpeed)."','".$this->getCheckNullVal($txtMTCPDRate)."','".$this->getCheckNullVal($txtMLumpsum)."','".$this->getCheckNullVal($txtAddnlCRate)."','".$this->getCheckNullVal($txtCQMT)."','".$this->getCheckNullVal($selCType)."','".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."','".$this->getCheckNullVal($txtDFQMT)."', '".$this->getCheckNullValue($txtAddnlQMT)."', '".$this->getCheckNullValue($txtLDist)."','".$this->getCheckNullValue($txtBDist)."','".$this->getCheckNullValue($txtLDays)."','".$this->getCheckNullVal($txtBDays)."','".$this->getCheckNullVal($txtTSDays)."','".$this->getCheckNullVal($txtTtPIDays)."','".$this->getCheckNullVal($txtTtPWDays)."','".$this->getCheckNullVal($txtTDays)."','".$this->getCheckNullVal($txtTDist)."','".$this->getCheckNullVal($txtTFUMT)."', '".$this->getCheckNullVal($txtTDUMT)."','".$this->getCheckNullValue($txtFrAdjUsdGF)."','".$this->getCheckNullVal($txtFrAdjUsdDF)."','".$this->getCheckNullVal($txtFrAdjUsdAF)."','".$this->getCheckNullVal($txtFrAdjUsdTF)."','".$this->getCheckNullVal($txtFrAdjUsdGFMT)."','".$this->getCheckNullVal($txtFrAdjUsdDFMT)."','".$this->getCheckNullVal($txtFrAdjUsdAFMT)."'  ,'".$this->getCheckNullVal($txtFrAdjUsdTFMT)."',    '".$this->getCheckNullValue($txtFrAdjPerAC)."', '".$this->getCheckNullValue($txtFrAdjUsdAC)."', '".$this->getCheckNullValue($txtFrAdjUsdACMT)."','".$this->getCheckNullValue($txtFrAdjPerAgC)."','".$this->getCheckNullVal($txtFrAdjUsdAgC)."','".$this->getCheckNullVal($txtFrAdjUsdFP)."','".$this->getCheckNullVal($txtFGFFD)."','".$this->getCheckNullVal($txtFGFFDMT)."',  '".$this->getCheckNullVal($txtBrCommPercent)."','".$this->getCheckNullVal($txtBrComm)."', '".$this->getCheckNullVal($txtRevenue)."', '".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtDailyEarnings)."','".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."','".$this->getCheckNullVal($txtGTTLVoyageEarnings)."','".$this->getCheckNullVal($txtNettDailyEarnings)."','".$this->getCheckNullVal($txtNettDailyProfit)."',  '".$this->getCheckNullVal($txtPL)."', '".$this->getCheckNullVal($rdoQty)."','".$this->getCheckNullVal($txtHireargeAmt)."','".$this->getCheckNullVal($txtHireargePercent)."','".$this->getCheckNullVal($txtHireargePercentAmt)."', '".$this->getCheckNullVal($txtNettHireargeAmt)."', '".$this->getCheckNullVal($txtCVE)."', '".$this->getCheckNullVal($txtCVEAmt)."', '".$this->getCheckNullVal($txtBallastBonus)."', '".$this->getCheckNullVal($txtTotalBunkerCost)."', '".$this->getCheckNullVal($txtTotalPortCost)."', '".$this->getCheckNullVal($txtAddnlCRatePer)."' , '".$this->getCheckNullVal($rdoEstimateType)."', '".$coaid."', '".$this->getCheckNullVal($selCargoPlanning)."', '".$this->getCheckNullVal($txtSDWTMT)."', '".$this->getCheckNullVal($txtSDWTLT)."', '".$this->getCheckNullVal($txtSDraftM)."', '".$this->getCheckNullVal($txtSDraftFT)."', '".$this->getCheckNullVal($txtTPIMT)."', '".$this->getCheckNullVal($txtTPILT)."', '".$this->getCheckNullVal($txtTPCMT)."', '".$this->getCheckNullVal($txtTPCLT)."', '".$this->getCheckNullVal($txtConstantsMT)."', '".$this->getCheckNullVal($txtConstantsLT)."', '".$this->getCheckNullVal($txtGrainCapCBM)."', '".$this->getCheckNullVal($txtGrainCapCFT)."', '".$this->getCheckNullVal($txtAllawedDraftM)."', '".$this->getCheckNullVal($txtBunkerRobMT)."', '".$this->getCheckNullVal($txtCargoIntakeMT)."', '".$this->getCheckNullVal($txtSFCBM_MT)."', '".$this->getCheckNullVal($txtSFCBFT_MT)."', '".$this->getCheckNullVal($txtCargoLoadableMT)."', '".$this->getCheckNullVal($txtGrossBreakeven)."', '".$this->getCheckNullVal($txtBreakevenMT)."', '".$this->getCheckNullVal($txtGrossHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeCVE)."', '".$this->getCheckNullVal($txtHireargeCVEAMT)."', '".$this->getCheckNullVal($txtOffHireCVE)."', '".$this->getCheckNullVal($txtOffHireCVEAMT)."', '".$this->getCheckNullVal($txtLessOffHire)."', '".$this->getCheckNullVal($txtFinalHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeBroPercent)."', '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', '".$this->getCheckNullVal($txtTotalVoyageDays)."', '".$txtTC_CPDate."', '".$this->getCheckNullVal($txtTKSECAHrs)."', '".$this->getCheckNullVal($txtTKNONSECAHrs)."', '".$this->getCheckNullVal($txtInertSECAHrs)."', '".$this->getCheckNullVal($txtInertNONSECAHrs)."', '".$this->getCheckNullVal($txtGFSECAHrs)."', '".$this->getCheckNullVal($txtGFNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs1)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs1)."')";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$mysql = "select max(FCAID) as max from freight_cost_estimete_master where COAID='".$coaid."'";
	$myres  =  mysql_query($mysql,$connect);
	$myrows = mysql_fetch_assoc($myres);
	$maxid = $myrows['max'];
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{
			$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			
			$sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_NETCOST, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_NETCOST, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, DDCLP_COMM, DDCDP_COMM, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['ChkShowDDCLP_'.$i]."','".$_REQUEST['ChkShowDDCDP_'.$i]."','".$randomid."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] >0)
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."',1,'".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] >0)
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] >0)
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}      
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$maxid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$maxid."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						 if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		
		if($txtStatus == 1)
	    {
			$year = date('Y',time());
			$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM freight_cost_estimate_compare where Year(ADD_ON_DATE) = '".$year."' and MCOMPANYID='".$_SESSION['company']."' and COAAID is not NULL";
			$result = mysql_query($query) or die(mysql_error());
			$rec=mysql_num_rows($result);
			
			$year1 = $year[2].''.$year[3];
			
			while($rows = mysql_fetch_array($result))
			{
			$empcode = $rows['MESSAGE_NO'];
			if($rows['MESSAGE_NO'] != NULL)
				{
				if(strlen($empcode)<=3)
					{
						$x = 3- strlen($empcode);
						for($i = 1; $i<=$x;$i++)
							{
								$empcode = "0".$empcode;
							}
					}$empcode =$empcode;//INNER if ends here.
				}//if ends here.
			else
				{
					$empcode= "001";
				}
			}
			
			$msg1 = $year1."-".$empcode;
			
			$sql2 = "insert into freight_cost_estimate_compare (FCAID, FINAL_ID, MESSAGE_NO, USERID, ADD_ON_DATE, MESSAGE, MODULEID, MCOMPANYID, COAAID, OPERATOR) values ('".$maxid."', '".$maxid."', '".$empcode."', '".$_SESSION['uid']."', NOW(), '".$msg1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$coaid."', '".$_REQUEST['selOperator']."')";
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
			 
			$query1 = "SELECT MAX(COMID) as MAX FROM freight_cost_estimate_compare where COAAID is not NULL";
			$result1 = mysql_query($query1) or die(mysql_error());
			$rows1 = mysql_fetch_array($result1);
			
			$sql3 = "update freight_cost_estimete_master set COMID='".$rows1['MAX']."', FIXED='1', FINAL_DATETIME=NOW(), FINAL_STATUS=1 where FCAID='".$maxid."' ";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit"); 
		}
			
	return $msg; 
}



function updateCOAestimatesDetails($id)
{
	$connect = $this->funConnect();
	$coaid 	 = $_REQUEST['coaid'];
	$txtStatus          = $_REQUEST['txtStatus'];
	
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCPDate	 		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	$market_rdo 		= addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	$txtAddnlCRate 		= addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlCRatePer   = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
    $txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	$txtCVE             = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt      	= addslashes(trim($_REQUEST['txtCVEAmt']));
	$txtHidCVEAmt   	= addslashes(trim($_REQUEST['txtHidCVEAmt']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selCargoPlanning   = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	
	$txtSDWTMT 	 	    = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	 		= addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM         = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 	 	= addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT     	 	= addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT    		= addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT    		= addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT           = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT     = addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT  	= addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM 	= addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT		= addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM   = addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT	 	= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT 	= addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT    	= addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT  		= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));

	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update freight_cost_estimete_master set TRANS_DATE='".$txtDate."', CP_DATE='".$txtCPDate."', VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', VESSEL_TYPE='".$txtVType."', VOYAGE_NO='".$txtVNo."', DWT_SUMMER='".$this->getCheckNullValue($txtDWTS)."', RDO_CAP='".$this->getCheckNullValue($rdoCap)."', GRAIN_CAP='".$this->getCheckNullValue($txtGCap)."', BALE_CAP='".$this->getCheckNullValue($txtBCap)."', SF='".$this->getCheckNullValue($txtSF)."', LODABLE='".$this->getCheckNullValue($txtLoadable)."', GNRT='".$this->getCheckNullValue($txtGNRT)."', LOA='".$this->getCheckNullValue($txtLOA)."', GEAR='".$this->getCheckNullValue($txtGear)."', BUILD_YEAR='".$txtBuiltYear."', BEAM='".$this->getCheckNullValue($txtBeam)."', TPC='".$this->getCheckNullValue($txtTPC)."', BFULLSPEED='".$this->getCheckNullValue($txtBFullSpeed)."', BECOSPEED1='".$this->getCheckNullValue($txtBEcoSpeed1)."', BECOSPEED2='".$this->getCheckNullValue($txtBEcoSpeed2)."', LFULLSPEED='".$this->getCheckNullValue($txtLFullSpeed)."', LECOSPEED1='".$this->getCheckNullValue($txtLEcoSpeed1)."', LECOSPEED2='".$this->getCheckNullVal($txtLEcoSpeed2)."', BFOFULLSPEED='".$this->getCheckNullVal($txtBFOFullSpeed)."', BFOECOSPEED1='".$this->getCheckNullVal($txtBFOEcoSpeed1)."', BFOECOSPEED2='".$this->getCheckNullVal($txtBFOEcoSpeed2)."', LFOFULLSPEED='".$this->getCheckNullVal($txtLFOFullSpeed)."', LFOECOSPEED1='".$this->getCheckNullVal($txtLFOEcoSpeed1)."', LFOECOSPEED2='".$this->getCheckNullVal($txtLFOEcoSpeed2)."', PIFOFULLSPEED='".$this->getCheckNullValue($txtPIFOFullSpeed)."', PWFOFULLSPEED='".$this->getCheckNullValue($txtPWFOFullSpeed)."', BDOFULLSPEED='".$this->getCheckNullValue($txtBDOFullSpeed)."', BDOECOSPEED1='".$this->getCheckNullValue($txtBDOEcoSpeed1)."', BDOECOSPEED2='".$this->getCheckNullVal($txtBDOEcoSpeed2)."', LDOFULLSPEED='".$this->getCheckNullVal($txtLDOFullSpeed)."', LDOECOSPEED1='".$this->getCheckNullVal($txtLDOEcoSpeed1)."', LDOECOSPEED2='".$this->getCheckNullVal($txtLDOEcoSpeed2)."', PIDOFULLSPEED='".$this->getCheckNullVal($txtPIDOFullSpeed)."', PWDOFULLSPEED='".$this->getCheckNullVal($txtPWDOFullSpeed)."', LADEN_DIST='".$this->getCheckNullValue($txtLDist)."', BALLAST_DIST='".$this->getCheckNullValue($txtBDist)."', LADEN_DAYS='".$this->getCheckNullValue($txtLDays)."', BALLAST_DAYS='".$this->getCheckNullVal($txtBDays)."', TOTAL_PASSAGE_DAYS='".$this->getCheckNullVal($txtTSDays)."', IDEAL_DAYS='".$this->getCheckNullVal($txtTtPIDays)."', WORKING_DAYS='".$this->getCheckNullVal($txtTtPWDays)."', TOTAL_DAYS='".$this->getCheckNullVal($txtTDays)."', TOTAL_DISTANCE='".$this->getCheckNullVal($txtTDist)."', FO_CONSP='".$this->getCheckNullVal($txtTFUMT)."', DO_CONSP='".$this->getCheckNullVal($txtTDUMT)."', GROSS_PREIGHT_ADJ='".$this->getCheckNullValue($txtFrAdjUsdGF)."', DEAD_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdDF)."', ADDNL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdAF)."', TOTAL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdTF)."', GROSS_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdGFMT)."', DEAD_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdDFMT)."', ADDNL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdAFMT)."', TOTAL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdTFMT)."', ADDRESS_COMMISSION_PER='".$this->getCheckNullValue($txtFrAdjPerAC)."', ADDRESS_COMMISSION_AMT='".$this->getCheckNullValue($txtFrAdjUsdAC)."', ADDRESS_COMMISSION_PRMT='".$this->getCheckNullValue($txtFrAdjUsdACMT)."', BROKERAGE_PER='".$this->getCheckNullValue($txtFrAdjPerAgC)."', BROKERAGE_AMT='".$this->getCheckNullVal($txtFrAdjUsdAgC)."', NET_PAYABLE='".$this->getCheckNullVal($txtFrAdjUsdFP)."', FINAL_NET_FREIGHT='".$this->getCheckNullVal($txtFGFFD)."', FINAL_NET_FREIGHT_PRMT='".$this->getCheckNullVal($txtFGFFDMT)."', BROKERAGE_COMMISSION_PER='".$this->getCheckNullVal($txtBrCommPercent)."', BROKERAGE_COMMISSION_AMT='".$this->getCheckNullVal($txtBrComm)."', REVENUES_FREIGHT='".$this->getCheckNullVal($txtRevenue)."', VOYAGE_EARNING='".$this->getCheckNullValue($txtVoyageEarnings)."', DAILY_EARNING='".$this->getCheckNullValue($txtDailyEarnings)."', DAILY_VESSEL_OPERATION_EXP='".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."', TOTAL_VOYAGE_EARNING='".$this->getCheckNullVal($txtGTTLVoyageEarnings)."', NET_DAILY_EARNING='".$this->getCheckNullVal($txtNettDailyEarnings)."', NET_DAILY_PROFIT='".$this->getCheckNullVal($txtNettDailyProfit)."', PROFIT_LOSS='".$this->getCheckNullVal($txtPL)."', RDO_QTY='".$this->getCheckNullVal($rdoQty)."', HIREAGE_AMT='".$this->getCheckNullVal($txtHireargeAmt)."', HIREAGE_PERCENT='".$this->getCheckNullVal($txtHireargePercent)."', HIREAGE_PER_AMT='".$this->getCheckNullVal($txtHireargePercentAmt)."', HIREAGE_NETT_AMT='".$this->getCheckNullVal($txtNettHireargeAmt)."', CVE_AMT='".$this->getCheckNullVal($txtCVE)."', CVE_TOTALAMT='".$this->getCheckNullVal($txtCVEAmt)."', BALLAST_BONUS='".$this->getCheckNullVal($txtBallastBonus)."', BUNKER_EXPENSES='".$this->getCheckNullVal($txtTotalBunkerCost)."', PORT_EXPENSES='".$this->getCheckNullVal($txtTotalPortCost)."', ADDNL_FREIGHT_PER='".$this->getCheckNullVal($txtAddnlCRatePer)."', OPEN_CARGOID='".$this->getCheckNullVal($selCargoPlanning)."', SUMMERDWTMT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMERDWTLT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMERDRAFTM='".$this->getCheckNullVal($txtSDraftM)."', SUMMERDRAFTFT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANT_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANT_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFTM='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CBFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', GROSS_BREAKDOWN='".$this->getCheckNullVal($txtGrossBreakeven)."', BREAKDOWN_MT='".$this->getCheckNullVal($txtBreakevenMT)."', GROSS_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtGrossHireargeAmt)."', HIERAGE_CVE='".$this->getCheckNullVal($txtHireargeCVE)."', HIERAGE_CVE_AMOUNT='".$this->getCheckNullVal($txtHireargeCVEAMT)."', OFF_HIRE_CVE='".$this->getCheckNullVal($txtOffHireCVE)."', OFF_HIRE_CVE_AMOUNT='".$this->getCheckNullVal($txtOffHireCVEAMT)."', LESS_OFF_HIRE='".$this->getCheckNullVal($txtLessOffHire)."', FINAL_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtFinalHireargeAmt)."', HIERAGE_BROKER_PERCENT= '".$this->getCheckNullVal($txtHireargeBroPercent)."', HIERAGE_BROKER_AMT= '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', TC_HIRE_DAYS='".$this->getCheckNullVal($txtTotalVoyageDays)."', TC_CP_DATE='".$txtTC_CPDate."', TANK_CLEANING_SECA_HRS='".$this->getCheckNullVal($txtTKSECAHrs)."', TANK_CLEANING_NONSECA_HRS='".$this->getCheckNullVal($txtTKNONSECAHrs)."', INERTING_SECA_HRS='".$this->getCheckNullVal($txtInertSECAHrs)."', INERTING_NONSECA_HRS='".$this->getCheckNullVal($txtInertNONSECAHrs)."', GAS_FREEING_SECA_HRS='".$this->getCheckNullVal($txtGFSECAHrs)."', GAS_FREEING_NONSECA_HRS='".$this->getCheckNullVal($txtGFNONSECAHrs)."', HEATING_SECA_HRS='".$this->getCheckNullVal($txtHeatSECAHrs)."', HEATING_NONSECA_HRS='".$this->getCheckNullVal($txtHeatNONSECAHrs)."', HEATING_SECA_HRS_1='".$this->getCheckNullVal($txtHeatSECAHrs1)."', HEATING_NONSECA_HRS_1='".$this->getCheckNullVal($txtHeatNONSECAHrs1)."' where FCAID='".$id."'";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$arr_passage = array();
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['txtFCASlaveID_'.$i]))
		{
			$arr_passage[] = $_REQUEST['txtFCASlaveID_'.$i];
		}
	}
	
	$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$id."'";
    $res1 = mysql_query($sql1);
	while($rows1 = mysql_fetch_assoc($res1))
	{
		if(!in_array($rows1['FCA_SLAVEID'], $arr_passage))
        {
			$del_query2 = "delete from freight_cost_estimete_slave1 where FCAID='".$id."' and FCA_SLAVEID='".$rows1['FCA_SLAVEID']."' ";
            mysql_query($del_query2);
			mysql_query("commit");
		}
	}
	
	$del_query2 = "delete from  freight_cost_estimete_slave2 where FCAID='".$id."'";
	$del_query3 = "delete from  freight_cost_estimete_slave3 where FCAID='".$id."'";
	$del_query4 = "delete from  freight_cost_estimete_slave4 where FCAID='".$id."'";
	$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$id."'";
	$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$id."'";
	$del_query12 = "delete from  freight_cost_estimete_slave8 where FCAID='".$id."'";
	$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$id."'";
	$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$id."'";
	$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$id."'";
	$del_query16 = "delete from  freight_cost_estimete_slave16 where FCAID='".$id."'";
	mysql_query($del_query2);
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query($del_query10);
	mysql_query($del_query12);
	mysql_query($del_query8);
	mysql_query($del_query13);
	mysql_query($del_query14);
	mysql_query($del_query15);
	mysql_query($del_query16);
	mysql_query("commit");
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{
			if(isset($_REQUEST['txtFCASlaveID_'.$i]) && $_REQUEST['txtFCASlaveID_'.$i]!='')
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "update freight_cost_estimete_slave1 set FROM_PORT='".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."', TO_PORT='".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."', DIS_TYPE='".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."', PASSAGE_TYPE='".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."', DISTANCE='".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."', SPEED_TYPE='".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."', SPEED_ADJ='".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."', MARGIN_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."', LOAD_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."', LOAD_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."', LOAD_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."', LOAD_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."', LOAD_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."', LOAD_PORT_IDEAL_DAYS='".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."', DISC_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."', DISC_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."', DISC_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."', DISC_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."', DISC_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."', DISC_PORT_IDEAL_DATE='".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."', TRANSIT_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."', TRANSIT_PORT_IDLE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', DDCLP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."', DDCLP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."', DDCLP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."', DDCDP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."', DDCDP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."', DDCDP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."', IS_SHOW_DDCLP='".$_REQUEST['ChkShowDDCLP_'.$i]."', IS_SHOW_DDCDP='".$_REQUEST['ChkShowDDCDP_'.$i]."', RANDOMID='".$randomid."', DDCLP_COMM='".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', DDCDP_COMM='".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', CHK_LP_SECA='".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', CHK_DP_SECA='".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', CHK_TP_SECA='".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', TOTAL_VOYAGE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', SECA_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', SECA_DAYS='".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."' where FCAID='".$id."' and FCA_SLAVEID='".$_REQUEST['txtFCASlaveID_'.$i]."'";	
			}
			else
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
			    $sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_NETCOST, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_NETCOST, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, DDCLP_COMM, DDCDP_COMM, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS) values ('".$id."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['ChkShowDDCLP_'.$i]."','".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."')";	
			}
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT) values ('".$id."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT) values ('".$id."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] >0)
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."',1,'".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] >0)
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] >0)
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$id."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$id."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$id."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$id."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						 if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$id."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		if($txtStatus == 1)
	    {
			
			$year = date('Y',time());
			$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM freight_cost_estimate_compare where Year(ADD_ON_DATE) = '".$year."' and MCOMPANYID='".$_SESSION['company']."' and COAAID is not NULL";
			$result = mysql_query($query) or die(mysql_error());
			$rec=mysql_num_rows($result);
			
			$year1 = $year[2].''.$year[3];
			
			while($rows = mysql_fetch_array($result))
			{
			$empcode = $rows['MESSAGE_NO'];
			if($rows['MESSAGE_NO'] != NULL)
				{
				if(strlen($empcode)<=3)
					{
						$x = 3- strlen($empcode);
						for($i = 1; $i<=$x;$i++)
							{
								$empcode = "0".$empcode;
							}
					}$empcode =$empcode;//INNER if ends here.
				}//if ends here.
			else
				{
					$empcode= "001";
				}
			}
			
			$msg1 = $year1."-".$empcode;
			
			$sql2 = "insert into freight_cost_estimate_compare (FCAID, FINAL_ID, MESSAGE_NO, USERID, ADD_ON_DATE, MESSAGE, MODULEID, MCOMPANYID, COAAID, OPERATOR) values ('".$id."', '".$id."', '".$empcode."', '".$_SESSION['uid']."', NOW(), '".$msg1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$coaid."', '".$_REQUEST['selOperator']."')";
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
			 
			$query1 = "SELECT MAX(COMID) as MAX FROM freight_cost_estimate_compare where COAAID is not NULL";
			$result1 = mysql_query($query1) or die(mysql_error());
			$rows1 = mysql_fetch_array($result1);
			
			$sql3 = "update freight_cost_estimete_master set COMID='".$rows1['MAX']."', FIXED='1', FINAL_DATETIME=NOW(), FINAL_STATUS=1 where FCAID='".$id."' ";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit"); 
		}
			
	return $msg; 
}




function insertTCICostSheetDetailsCoa()
{	
	$connect = $this->funConnect();
	$coaid	 		    = addslashes(trim($_REQUEST['coaid']));
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 		= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCPDate	 		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	$rdoQty             = addslashes(trim($_REQUEST['rdoQty']));
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
	$txtAddnlCRatePer                  = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	
	
	$selOpenPort 	 	= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 		= addslashes(trim($_REQUEST['selZone']));
	$selBroker          = addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 	= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 	= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    		= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    = addslashes(trim($_REQUEST['selOwner']));
	
	
	$txtCID 	 		= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       = addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 		= implode(',',$_REQUEST['selMType']);
	$txtMCode    		= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance	= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    = addslashes(trim($_REQUEST['selDPort']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	

	$selDTCVendor       	   = addslashes(trim($_REQUEST['selDTCVendor']));
	$txtFGFFVendor       	   = addslashes(trim($_REQUEST['txtFGFFVendor']));
	
	$txtCVE           	   = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt       	   = addslashes(trim($_REQUEST['txtCVEAmt']));
	$selCVEVendor          = addslashes(trim($_REQUEST['selCVEVendor']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selBroVendor       = addslashes(trim($_REQUEST['selBroVendor']));
	$selILOHCVendor     = addslashes(trim($_REQUEST['selILOHCVendor']));
	
	
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$selLumsumVendor 	    = addslashes(trim($_REQUEST['selLumsumVendor']));
	$txtLumpsumQty          = $_REQUEST['txtLumpsumQty'];
	$selCargoPlanning       = $_REQUEST['selCargoPlanning'];
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));

	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['comid'];
	$update_status       	   = addslashes(trim($_REQUEST['update_status']));
	
	$sql_fetch = "select FCAID from freight_cost_estimete_master where COMID='".$comid."' and SHEET_NO='".$sheet_no."'";
	$res_fetch = mysql_query($sql_fetch) or die($sql_fetch);
	$num_fetch = mysql_num_rows($res_fetch);
	if($num_fetch == 0)
	{
		$sql = "insert into freight_cost_estimete_master (FIXTURETYPEID, TRANS_DATE, MODULEID, MCOMPANYID, ADDED_BY, ADD_ON_DATE, VESSEL_IMO_ID, VESSEL_TYPE, VOYAGE_NO, DWT_SUMMER, RDO_CAP, GRAIN_CAP, BALE_CAP, SF, LODABLE, GNRT, LOA, GEAR, BUILD_YEAR, BEAM, TPC, BFULLSPEED, BECOSPEED1, BECOSPEED2, LFULLSPEED, LECOSPEED1, LECOSPEED2, BFOFULLSPEED, BFOECOSPEED1, BFOECOSPEED2, LFOFULLSPEED, LFOECOSPEED1, LFOECOSPEED2, PIFOFULLSPEED, PWFOFULLSPEED, BDOFULLSPEED, BDOECOSPEED1, BDOECOSPEED2, LDOFULLSPEED, LDOECOSPEED1, LDOECOSPEED2, PIDOFULLSPEED, PWDOFULLSPEED, RDO_MARKER, RDO_DWT, FREIGHT_GROSS, LUMSUM, CARGO_RATE, QUANTITY, CARGO_TYPE, CARGO_ID, DF_QUANTITY, ADDNL_QUANTITY, LADEN_DIST, BALLAST_DIST, LADEN_DAYS, BALLAST_DAYS, TOTAL_PASSAGE_DAYS, IDEAL_DAYS, WORKING_DAYS, TOTAL_DAYS, TOTAL_DISTANCE, FO_CONSP, DO_CONSP, GROSS_PREIGHT_ADJ, DEAD_PREIGHT_ADJ, ADDNL_PREIGHT_ADJ, TOTAL_PREIGHT_ADJ, GROSS_PREIGHT_ADJ_PRMT, DEAD_PREIGHT_ADJ_PRMT, ADDNL_PREIGHT_ADJ_PRMT, TOTAL_PREIGHT_ADJ_PRMT, ADDRESS_COMMISSION_PER, ADDRESS_COMMISSION_AMT, ADDRESS_COMMISSION_PRMT, BROKERAGE_PER, BROKERAGE_AMT, NET_PAYABLE, FINAL_NET_FREIGHT, FINAL_NET_FREIGHT_PRMT, BROKERAGE_COMMISSION_PER, BROKERAGE_COMMISSION_AMT, TOTAL_ORC_EXP_AMT, TOTAL_ORC_EXP_PRMT, REVENUES_FREIGHT, TOTAL_OWNER_EXP, CHARTERER_EXP, VOYAGE_EARNING, DAILY_EARNING, DAILY_VESSEL_OPERATION_EXP, TOTAL_VOYAGE_EARNING, NET_DAILY_EARNING, NET_DAILY_PROFIT, PROFIT_LOSS, CP_DATE, CARGOID, HIREAGE_AMT, HIREAGE_PERCENT, HIREAGE_PER_AMT, HIREAGE_NETT_AMT, QTY_TYPE_RADIO, AGREED_GROSS_FREIGHT_LOCAL, SHEET_NO, COMID, DTCVENDORID, FINAL_STATUS, FGFF_VENDORID, CVE_AMT, CVE_TOTALAMT, CVE_VENDORID, BALLAST_BONUS, BUNKER_EXPENSES, PORT_EXPENSES, BROKERAGE_VENDORID, ILOHC_VENDORID, HIDDEN_HIRAGE, FIXED, ADDNL_FREIGHT_PER, ESTIMATE_TYPE, COAID, OPEN_CARGOID, SUMMERDWTMT, SUMMERDWTLT, SUMMERDRAFTM, SUMMERDRAFTFT, TPI_MT_INCH, TPI_LT_INCH, TPC_MT, TPC_LT, CONSTANT_MT, CONSTANT_LT, GRAIN_CAP_CBM, GRAIN_CAP_CFT, ALLOWED_DRAFTM, BUNKER_ROB_MT, CARGO_INTAKE_MT, SF_CBM_MT, SF_CBFT_MT, CARGO_LOADABLE_MT, GROSS_BREAKDOWN, BREAKDOWN_MT, GROSS_HIERAGE_AMOUNT, HIERAGE_CVE, HIERAGE_CVE_AMOUNT, OFF_HIRE_CVE, OFF_HIRE_CVE_AMOUNT, LESS_OFF_HIRE, FINAL_HIERAGE_AMOUNT, HIERAGE_BROKER_PERCENT, HIERAGE_BROKER_AMT, TC_HIRE_DAYS, TC_CP_DATE, TANK_CLEANING_SECA_HRS, TANK_CLEANING_NONSECA_HRS, INERTING_SECA_HRS, INERTING_NONSECA_HRS, GAS_FREEING_SECA_HRS, GAS_FREEING_NONSECA_HRS, HEATING_SECA_HRS, HEATING_NONSECA_HRS, HEATING_SECA_HRS_1, HEATING_NONSECA_HRS_1) values ('".$this->getCheckNullValue($selFType)."','".$txtDate."','".$this->getCheckNullValue($_SESSION['moduleid'])."','".$this->getCheckNullValue($_SESSION['company'])."','".$_SESSION['uid']."', NOW(),'".$this->getCheckNullValue($selVName)."','".$txtVType."','".$txtVNo."','".$this->getCheckNullValue($txtDWTS)."','".$this->getCheckNullValue($rdoCap)."','".$this->getCheckNullValue($txtGCap)."','".$this->getCheckNullValue($txtBCap)."','".$this->getCheckNullValue($txtSF)."','".$this->getCheckNullValue($txtLoadable)."','".$this->getCheckNullValue($txtGNRT)."','".$this->getCheckNullValue($txtLOA)."','".$txtGear."','".$txtBuiltYear."','".$this->getCheckNullValue($txtBeam)."','".$this->getCheckNullValue($txtTPC)."','".$this->getCheckNullValue($txtBFullSpeed)."','".$this->getCheckNullValue($txtBEcoSpeed1)."','".$this->getCheckNullValue($txtBEcoSpeed2)."','".$this->getCheckNullValue($txtLFullSpeed)."','".$this->getCheckNullValue($txtLEcoSpeed1)."','".$this->getCheckNullVal($txtLEcoSpeed2)."','".$this->getCheckNullVal($txtBFOFullSpeed)."','".$this->getCheckNullVal($txtBFOEcoSpeed1)."','".$this->getCheckNullVal($txtBFOEcoSpeed2)."','".$this->getCheckNullVal($txtLFOFullSpeed)."','".$this->getCheckNullVal($txtLFOEcoSpeed1)."','".$this->getCheckNullVal($txtLFOEcoSpeed2)."', '".$this->getCheckNullValue($txtPIFOFullSpeed)."', '".$this->getCheckNullValue($txtPWFOFullSpeed)."','".$this->getCheckNullValue($txtBDOFullSpeed)."','".$this->getCheckNullValue($txtBDOEcoSpeed1)."','".$this->getCheckNullVal($txtBDOEcoSpeed2)."','".$this->getCheckNullVal($txtLDOFullSpeed)."','".$this->getCheckNullVal($txtLDOEcoSpeed1)."','".$this->getCheckNullVal($txtLDOEcoSpeed2)."','".$this->getCheckNullVal($txtPIDOFullSpeed)."','".$this->getCheckNullVal($txtPWDOFullSpeed)."','".$this->getCheckNullVal($rdoMMarket)."','".$this->getCheckNullValue($rdoDWT)."','".$this->getCheckNullVal($txtMTCPDRate)."','".$this->getCheckNullVal($txtMLumpsum)."','".$this->getCheckNullVal($txtAddnlCRate)."','".$this->getCheckNullVal($txtCQMT)."','".$this->getCheckNullVal($selCType)."','".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."','".$this->getCheckNullVal($txtDFQMT)."', '".$this->getCheckNullValue($txtAddnlQMT)."', '".$this->getCheckNullValue($txtLDist)."','".$this->getCheckNullValue($txtBDist)."','".$this->getCheckNullValue($txtLDays)."','".$this->getCheckNullVal($txtBDays)."','".$this->getCheckNullVal($txtTSDays)."','".$this->getCheckNullVal($txtTtPIDays)."','".$this->getCheckNullVal($txtTtPWDays)."','".$this->getCheckNullVal($txtTDays)."','".$this->getCheckNullVal($txtTDist)."','".$this->getCheckNullVal($txtTFUMT)."', '".$this->getCheckNullVal($txtTDUMT)."','".$this->getCheckNullValue($txtFrAdjUsdGF)."','".$this->getCheckNullVal($txtFrAdjUsdDF)."','".$this->getCheckNullVal($txtFrAdjUsdAF)."','".$this->getCheckNullVal($txtFrAdjUsdTF)."','".$this->getCheckNullVal($txtFrAdjUsdGFMT)."','".$this->getCheckNullVal($txtFrAdjUsdDFMT)."','".$this->getCheckNullVal($txtFrAdjUsdAFMT)."','".$this->getCheckNullVal($txtFrAdjUsdTFMT)."',    '".$this->getCheckNullValue($txtFrAdjPerAC)."', '".$this->getCheckNullValue($txtFrAdjUsdAC)."', '".$this->getCheckNullValue($txtFrAdjUsdACMT)."','".$this->getCheckNullValue($txtFrAdjPerAgC)."','".$this->getCheckNullVal($txtFrAdjUsdAgC)."','".$this->getCheckNullVal($txtFrAdjUsdFP)."','".$this->getCheckNullVal($txtFGFFD)."','".$this->getCheckNullVal($txtFGFFDMT)."',  '".$this->getCheckNullVal($txtBrCommPercent)."','".$this->getCheckNullVal($txtBrComm)."','".$this->getCheckNullVal($txtTTLORCAmt)."', '".$this->getCheckNullVal($txtTTLORCCostMT)."','".$this->getCheckNullVal($txtRevenue)."',    '".$this->getCheckNullValue($txtTTLOwnersExpenses)."', '".$this->getCheckNullValue($txtTTLCharterersExpenses)."', '".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtDailyEarnings)."','".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."','".$this->getCheckNullVal($txtGTTLVoyageEarnings)."','".$this->getCheckNullVal($txtNettDailyEarnings)."','".$this->getCheckNullVal($txtNettDailyProfit)."',  '".$this->getCheckNullVal($txtPL)."', '".$txtCPDate."', '".$txtCID."','".$this->getCheckNullVal($txtHireargeAmt)."','".$this->getCheckNullVal($txtHireargePercent)."','".$this->getCheckNullVal($txtHireargePercentAmt)."', '".$this->getCheckNullVal($txtNettHireargeAmt)."', '".$rdoQtyType."', '".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', '".$this->getCheckNullVal($sheet_no)."', '".$this->getCheckNullVal($comid)."', '".$selDTCVendor."', '".$update_status."', '".$txtFGFFVendor."', '".$this->getCheckNullVal($txtCVE)."', '".$this->getCheckNullVal($txtCVEAmt)."', '".$this->getCheckNullVal($selCVEVendor)."'    , '".$this->getCheckNullVal($txtBallastBonus)."', '".$this->getCheckNullVal($txtTotalBunkerCost)."', '".$this->getCheckNullVal($txtTotalPortCost)."' , '".$selBroVendor."', '".$selILOHCVendor."', '".$this->getCheckNullVal($txtHiddenHirage)."', 1, '".$this->getCheckNullVal($txtAddnlCRatePer)."', '".$this->getCheckNullVal($rdoEstimateType)."', '".$this->getCheckNullVal($coaid)."', '".$this->getCheckNullVal($selCargoPlanning)."', '".$this->getCheckNullVal($txtSDWTMT)."', '".$this->getCheckNullVal($txtSDWTLT)."', '".$this->getCheckNullVal($txtSDraftM)."', '".$this->getCheckNullVal($txtSDraftFT)."', '".$this->getCheckNullVal($txtTPIMT)."', '".$this->getCheckNullVal($txtTPILT)."', '".$this->getCheckNullVal($txtTPCMT)."', '".$this->getCheckNullVal($txtTPCLT)."', '".$this->getCheckNullVal($txtConstantsMT)."', '".$this->getCheckNullVal($txtConstantsLT)."', '".$this->getCheckNullVal($txtGrainCapCBM)."', '".$this->getCheckNullVal($txtGrainCapCFT)."', '".$this->getCheckNullVal($txtAllawedDraftM)."', '".$this->getCheckNullVal($txtBunkerRobMT)."', '".$this->getCheckNullVal($txtCargoIntakeMT)."', '".$this->getCheckNullVal($txtSFCBM_MT)."', '".$this->getCheckNullVal($txtSFCBFT_MT)."', '".$this->getCheckNullVal($txtCargoLoadableMT)."', '".$this->getCheckNullVal($txtGrossBreakeven)."', '".$this->getCheckNullVal($txtBreakevenMT)."', '".$this->getCheckNullVal($txtGrossHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeCVE)."', '".$this->getCheckNullVal($txtHireargeCVEAMT)."', '".$this->getCheckNullVal($txtOffHireCVE)."', '".$this->getCheckNullVal($txtOffHireCVEAMT)."', '".$this->getCheckNullVal($txtLessOffHire)."', '".$this->getCheckNullVal($txtFinalHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeBroPercent)."', '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', '".$this->getCheckNullVal($txtTotalVoyageDays)."', '".$txtTC_CPDate."', '".$this->getCheckNullVal($txtTKSECAHrs)."', '".$this->getCheckNullVal($txtTKNONSECAHrs)."', '".$this->getCheckNullVal($txtInertSECAHrs)."', '".$this->getCheckNullVal($txtInertNONSECAHrs)."', '".$this->getCheckNullVal($txtGFSECAHrs)."', '".$this->getCheckNullVal($txtGFNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs1)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs1)."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(FCAID) as max from freight_cost_estimete_master";
		$myres  =  mysql_query($mysql,$connect);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
    }else
	{
		$rows_fetch = mysql_fetch_assoc($res_fetch);
		$maxid = $rows_fetch['FCAID'];
		
		$del_query2 = "delete from  freight_cost_estimete_slave1 where FCAID='".$maxid."'";
		$del_query3 = "delete from  freight_cost_estimete_slave2 where FCAID='".$maxid."'";
		$del_query4 = "delete from  freight_cost_estimete_slave3 where FCAID='".$maxid."'";
		$del_query5 = "delete from  freight_cost_estimete_slave4 where FCAID='".$maxid."'";
		$del_query6 = "delete from  freight_cost_estimete_slave5 where FCAID='".$maxid."'";
		$del_query7 = "delete from  freight_cost_estimete_slave6 where FCAID='".$maxid."'";
		$del_query8 = "delete from  freight_cost_estimete_slave7 where FCAID='".$maxid."'";
		$del_query9 = "delete from  freight_cost_estimete_slave8 where FCAID='".$maxid."'";
		$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$maxid."'";
		$del_query11 = "delete from  freight_cost_estimete_slave11 where FCAID='".$maxid."'";
		$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$maxid."'";
		$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$maxid."'";
		$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$maxid."'";
		$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$maxid."'";
		$del_query16 = "delete from  freight_cost_estimete_slave16 where FCAID='".$maxid."'";
		mysql_query($del_query2);
		mysql_query($del_query3);
		mysql_query($del_query4);
		mysql_query($del_query5);
		mysql_query($del_query6);
		mysql_query($del_query7);
		mysql_query($del_query8);
		mysql_query($del_query9);
		mysql_query($del_query10);
		mysql_query($del_query11);
		mysql_query($del_query12);
		mysql_query($del_query13);
		mysql_query($del_query14);
		mysql_query($del_query15);
		mysql_query($del_query16);
		mysql_query("commit");
	}		
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{   
		    $randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, PORT_COSTLP_VENDOR, DDCLP_COMM, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_VENDOR, DDCLP_NETCOST, DDCDP_COMM, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_VENDOR, DDCDP_NETCOST, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, PORT_COSTTP_VENDOR, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."' ,'".$_REQUEST['selLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$_REQUEST['selDDCLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$_REQUEST['selDDCDPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['selDPVendor_'.$i]."', '".$_REQUEST['ChkShowDDCLP_'.$i]."', '".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$_REQUEST['selTPVendor_'.$i]."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT, VENDORID ) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selORCVendor_'.$i])."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT, VENDORID) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOtherIncVendor_'.$i])."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."', '".$_REQUEST['selBrCommVendor_'.$i]."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtRateUSDmt_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] != "")
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."', 1, '".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtRateUSDmt2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] != "")
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtRateUSDmt3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] != "")
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, VENDORID, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$_REQUEST['selQtyVendor3_'.$i]."', '".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$maxid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$maxid."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg; 
}

function updateTCICostSheetDetailsCOA()
{	
	$connect = $this->funConnect();
	$coaid	 		    = addslashes(trim($_REQUEST['coaid']));
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 		= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCPDate	 		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	$rdoQty             = addslashes(trim($_REQUEST['rdoQty']));
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
	$txtAddnlCRatePer                  = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	
	
	$selOpenPort 	 	= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 		= addslashes(trim($_REQUEST['selZone']));
	$selBroker          = addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 	= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 	= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    		= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    = addslashes(trim($_REQUEST['selOwner']));
	
	
	$txtCID 	 		= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       = addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 		= implode(',',$_REQUEST['selMType']);
	$txtMCode    		= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance	= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    = addslashes(trim($_REQUEST['selDPort']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	

	$selDTCVendor       	   = addslashes(trim($_REQUEST['selDTCVendor']));
	$txtFGFFVendor       	   = addslashes(trim($_REQUEST['txtFGFFVendor']));
	
	$txtCVE           	   = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt       	   = addslashes(trim($_REQUEST['txtCVEAmt']));
	$selCVEVendor          = addslashes(trim($_REQUEST['selCVEVendor']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selBroVendor       = addslashes(trim($_REQUEST['selBroVendor']));
	$selILOHCVendor     = addslashes(trim($_REQUEST['selILOHCVendor']));
	
	
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$selLumsumVendor 	    = addslashes(trim($_REQUEST['selLumsumVendor']));
	$txtLumpsumQty          = $_REQUEST['txtLumpsumQty'];
	$selCargoPlanning       = $_REQUEST['selCargoPlanning'];
	
	$txtSDWTMT 	 	    = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	 		= addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM         = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 	 	= addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT     	 	= addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT    		= addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT    		= addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT           = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT     = addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT  	= addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM 	= addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT		= addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM   = addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT	 	= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT 	= addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT    	= addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT  		= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
    $txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['comid'];
	$update_status = addslashes(trim($_REQUEST['update_status']));
	$id = $this->getTCICostSheetID($comid,$sheet_no);
	
	$sql = "update freight_cost_estimete_master set TRANS_DATE='".$txtDate."', ADD_ON_DATE=NOW(), VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', VESSEL_TYPE='".$txtVType."', VOYAGE_NO='".$txtVNo."', DWT_SUMMER='".$this->getCheckNullValue($txtDWTS)."', RDO_CAP='".$this->getCheckNullValue($rdoCap)."', GRAIN_CAP='".$this->getCheckNullValue($txtGCap)."', BALE_CAP='".$this->getCheckNullValue($txtBCap)."', SF='".$this->getCheckNullValue($txtSF)."', LODABLE='".$this->getCheckNullValue($txtLoadable)."', GNRT='".$this->getCheckNullValue($txtGNRT)."', LOA='".$this->getCheckNullValue($txtLOA)."', GEAR='".$txtGear."', BUILD_YEAR='".$txtBuiltYear."', BEAM='".$this->getCheckNullValue($txtBeam)."', TPC='".$this->getCheckNullValue($txtTPC)."', BFULLSPEED='".$this->getCheckNullValue($txtBFullSpeed)."', BECOSPEED1='".$this->getCheckNullValue($txtBEcoSpeed1)."', BECOSPEED2='".$this->getCheckNullValue($txtBEcoSpeed2)."', LFULLSPEED='".$this->getCheckNullValue($txtLFullSpeed)."', LECOSPEED1='".$this->getCheckNullValue($txtLEcoSpeed1)."', LECOSPEED2='".$this->getCheckNullVal($txtLEcoSpeed2)."', BFOFULLSPEED='".$this->getCheckNullVal($txtBFOFullSpeed)."', BFOECOSPEED1='".$this->getCheckNullVal($txtBFOEcoSpeed1)."', BFOECOSPEED2='".$this->getCheckNullVal($txtBFOEcoSpeed2)."', LFOFULLSPEED='".$this->getCheckNullVal($txtLFOFullSpeed)."', LFOECOSPEED1='".$this->getCheckNullVal($txtLFOEcoSpeed1)."', LFOECOSPEED2='".$this->getCheckNullVal($txtLFOEcoSpeed2)."', PIFOFULLSPEED='".$this->getCheckNullValue($txtPIFOFullSpeed)."', PWFOFULLSPEED='".$this->getCheckNullValue($txtPWFOFullSpeed)."', BDOFULLSPEED='".$this->getCheckNullValue($txtBDOFullSpeed)."', BDOECOSPEED1='".$this->getCheckNullValue($txtBDOEcoSpeed1)."', BDOECOSPEED2='".$this->getCheckNullVal($txtBDOEcoSpeed2)."', LDOFULLSPEED='".$this->getCheckNullVal($txtLDOFullSpeed)."', LDOECOSPEED1='".$this->getCheckNullVal($txtLDOEcoSpeed1)."', LDOECOSPEED2='".$this->getCheckNullVal($txtLDOEcoSpeed2)."', PIDOFULLSPEED='".$this->getCheckNullVal($txtPIDOFullSpeed)."', PWDOFULLSPEED='".$this->getCheckNullVal($txtPWDOFullSpeed)."', RDO_MARKER='".$this->getCheckNullVal($rdoMMarket)."', RDO_DWT='".$this->getCheckNullValue($rdoDWT)."', FREIGHT_GROSS='".$this->getCheckNullVal($txtMTCPDRate)."', LUMSUM='".$this->getCheckNullVal($txtMLumpsum)."', CARGO_RATE='".$this->getCheckNullVal($txtAddnlCRate)."', LADEN_DIST='".$this->getCheckNullValue($txtLDist)."', BALLAST_DIST='".$this->getCheckNullValue($txtBDist)."', LADEN_DAYS='".$this->getCheckNullValue($txtLDays)."', BALLAST_DAYS='".$this->getCheckNullVal($txtBDays)."', TOTAL_PASSAGE_DAYS='".$this->getCheckNullVal($txtTSDays)."', IDEAL_DAYS='".$this->getCheckNullVal($txtTtPIDays)."', WORKING_DAYS='".$this->getCheckNullVal($txtTtPWDays)."', TOTAL_DAYS='".$this->getCheckNullVal($txtTDays)."', TOTAL_DISTANCE='".$this->getCheckNullVal($txtTDist)."', FO_CONSP='".$this->getCheckNullVal($txtTFUMT)."', DO_CONSP='".$this->getCheckNullVal($txtTDUMT)."', GROSS_PREIGHT_ADJ='".$this->getCheckNullValue($txtFrAdjUsdGF)."', DEAD_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdDF)."', ADDNL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdAF)."', TOTAL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdTF)."', GROSS_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdGFMT)."', DEAD_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdDFMT)."', ADDNL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdAFMT)."', TOTAL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdTFMT)."', ADDRESS_COMMISSION_PER='".$this->getCheckNullValue($txtFrAdjPerAC)."', ADDRESS_COMMISSION_AMT='".$this->getCheckNullValue($txtFrAdjUsdAC)."', ADDRESS_COMMISSION_PRMT='".$this->getCheckNullValue($txtFrAdjUsdACMT)."', BROKERAGE_PER='".$this->getCheckNullValue($txtFrAdjPerAgC)."', BROKERAGE_AMT='".$this->getCheckNullVal($txtFrAdjUsdAgC)."', NET_PAYABLE='".$this->getCheckNullVal($txtFrAdjUsdFP)."', FINAL_NET_FREIGHT='".$this->getCheckNullVal($txtFGFFD)."', FINAL_NET_FREIGHT_PRMT='".$this->getCheckNullVal($txtFGFFDMT)."', BROKERAGE_COMMISSION_PER='".$this->getCheckNullVal($txtBrCommPercent)."', BROKERAGE_COMMISSION_AMT='".$this->getCheckNullVal($txtBrComm)."', TOTAL_ORC_EXP_AMT='".$this->getCheckNullVal($txtTTLORCAmt)."', TOTAL_ORC_EXP_PRMT='".$this->getCheckNullVal($txtTTLORCCostMT)."', REVENUES_FREIGHT='".$this->getCheckNullVal($txtRevenue)."', TOTAL_OWNER_EXP='".$this->getCheckNullValue($txtTTLOwnersExpenses)."', CHARTERER_EXP='".$this->getCheckNullValue($txtTTLCharterersExpenses)."', VOYAGE_EARNING= '".$this->getCheckNullValue($txtVoyageEarnings)."', DAILY_EARNING='".$this->getCheckNullValue($txtDailyEarnings)."', DAILY_VESSEL_OPERATION_EXP='".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."', TOTAL_VOYAGE_EARNING='".$this->getCheckNullVal($txtGTTLVoyageEarnings)."', NET_DAILY_EARNING='".$this->getCheckNullVal($txtNettDailyEarnings)."', NET_DAILY_PROFIT='".$this->getCheckNullVal($txtNettDailyProfit)."', PROFIT_LOSS='".$this->getCheckNullVal($txtPL)."', CP_DATE='".$txtCPDate."', CARGOID='".$txtCID."', HIREAGE_AMT='".$this->getCheckNullVal($txtHireargeAmt)."', HIREAGE_PERCENT='".$this->getCheckNullVal($txtHireargePercent)."', HIREAGE_PER_AMT='".$this->getCheckNullVal($txtHireargePercentAmt)."', HIREAGE_NETT_AMT='".$this->getCheckNullVal($txtNettHireargeAmt)."', QTY_TYPE_RADIO='".$rdoQtyType."', AGREED_GROSS_FREIGHT_LOCAL='".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', DTCVENDORID='".$selDTCVendor."', FINAL_STATUS='".$update_status."', FGFF_VENDORID='".$txtFGFFVendor."', CVE_AMT='".$this->getCheckNullVal($txtCVE)."', CVE_TOTALAMT='".$this->getCheckNullVal($txtCVEAmt)."', CVE_VENDORID='".$this->getCheckNullVal($selCVEVendor)."', BALLAST_BONUS='".$this->getCheckNullVal($txtBallastBonus)."', BUNKER_EXPENSES='".$this->getCheckNullVal($txtTotalBunkerCost)."', PORT_EXPENSES='".$this->getCheckNullVal($txtTotalPortCost)."', BROKERAGE_VENDORID='".$selBroVendor."', ILOHC_VENDORID='".$selILOHCVendor."', HIDDEN_HIRAGE='".$this->getCheckNullVal($txtHiddenHirage)."', FIXED=1, ADDNL_FREIGHT_PER='".$this->getCheckNullVal($txtAddnlCRatePer)."', ESTIMATE_TYPE='".$this->getCheckNullVal($rdoEstimateType)."', COAID='".$this->getCheckNullVal($coaid)."', OPEN_CARGOID='".$this->getCheckNullVal($selCargoPlanning)."', SUMMERDWTMT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMERDWTLT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMERDRAFTM='".$this->getCheckNullVal($txtSDraftM)."', SUMMERDRAFTFT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANT_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANT_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFTM='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CBFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', GROSS_BREAKDOWN='".$this->getCheckNullVal($txtGrossBreakeven)."', BREAKDOWN_MT='".$this->getCheckNullVal($txtBreakevenMT)."', TANKER_RADIO_SINGLE_DIS='".$this->getCheckNullVal($rdoTankType)."', GROSS_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtGrossHireargeAmt)."', HIERAGE_CVE='".$this->getCheckNullVal($txtHireargeCVE)."', HIERAGE_CVE_AMOUNT='".$this->getCheckNullVal($txtHireargeCVEAMT)."', OFF_HIRE_CVE='".$this->getCheckNullVal($txtOffHireCVE)."', OFF_HIRE_CVE_AMOUNT='".$this->getCheckNullVal($txtOffHireCVEAMT)."', LESS_OFF_HIRE='".$this->getCheckNullVal($txtLessOffHire)."', FINAL_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtFinalHireargeAmt)."', HIERAGE_BROKER_PERCENT= '".$this->getCheckNullVal($txtHireargeBroPercent)."', HIERAGE_BROKER_AMT= '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', TC_HIRE_DAYS='".$this->getCheckNullVal($txtTotalVoyageDays)."', TC_CP_DATE='".$txtTC_CPDate."', TANK_CLEANING_SECA_HRS='".$this->getCheckNullVal($txtTKSECAHrs)."', TANK_CLEANING_NONSECA_HRS='".$this->getCheckNullVal($txtTKNONSECAHrs)."', INERTING_SECA_HRS='".$this->getCheckNullVal($txtInertSECAHrs)."', INERTING_NONSECA_HRS='".$this->getCheckNullVal($txtInertNONSECAHrs)."', GAS_FREEING_SECA_HRS='".$this->getCheckNullVal($txtGFSECAHrs)."', GAS_FREEING_NONSECA_HRS='".$this->getCheckNullVal($txtGFNONSECAHrs)."', HEATING_SECA_HRS='".$this->getCheckNullVal($txtHeatSECAHrs)."', HEATING_NONSECA_HRS='".$this->getCheckNullVal($txtHeatNONSECAHrs)."', HEATING_SECA_HRS_1='".$this->getCheckNullVal($txtHeatSECAHrs1)."', HEATING_NONSECA_HRS_1='".$this->getCheckNullVal($txtHeatNONSECAHrs1)."'  where SHEET_NO='".$this->getCheckNullVal($sheet_no)."' and COMID='".$this->getCheckNullVal($comid)."'";
	//echo $sql;die;
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	
	$maxid = $id;
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['txtFCASlaveID_'.$i]))
		{
			$arr_passage[] = $_REQUEST['txtFCASlaveID_'.$i];
		}
	}
	$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$id."'";
    $res1 = mysql_query($sql1);
	while($rows1 = mysql_fetch_assoc($res1))
	{
		if(!in_array($rows1['FCA_SLAVEID'], $arr_passage))
        {
			$del_query2 = "delete from freight_cost_estimete_slave1 where FCAID='".$id."' and FCA_SLAVEID='".$rows1['FCA_SLAVEID']."' ";
            mysql_query($del_query2);
			mysql_query("commit");
		}
	}
	
	$del_query3 = "delete from  freight_cost_estimete_slave2 where FCAID='".$id."'";
	$del_query4 = "delete from  freight_cost_estimete_slave3 where FCAID='".$id."'";
	$del_query5 = "delete from  freight_cost_estimete_slave4 where FCAID='".$id."'";
	$del_query6 = "delete from  freight_cost_estimete_slave5 where FCAID='".$id."'";
	$del_query7 = "delete from  freight_cost_estimete_slave6 where FCAID='".$id."'";
	$del_query8 = "delete from  freight_cost_estimete_slave7 where FCAID='".$id."'";
	$del_query9 = "delete from  freight_cost_estimete_slave8 where FCAID='".$id."'";
	$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$id."'";
	$del_query11 = "delete from  freight_cost_estimete_slave11 where FCAID='".$id."'";
	$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$id."'";
	$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$id."'";
	$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$id."'";
	$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$id."'";
	$del_query16 = "delete from  freight_cost_estimete_slave16 where FCAID='".$id."'";
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query($del_query5);
	mysql_query($del_query6);
	mysql_query($del_query7);
	mysql_query($del_query8);
	mysql_query($del_query9);
	mysql_query($del_query10);
	mysql_query($del_query11);
	mysql_query($del_query12);
	mysql_query($del_query13);
	mysql_query($del_query14);
	mysql_query($del_query15);
	mysql_query($del_query16);
	mysql_query("commit");
	
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{
			if(isset($_REQUEST['txtFCASlaveID_'.$i]) && $_REQUEST['txtFCASlaveID_'.$i]!='')
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "update freight_cost_estimete_slave1 set FROM_PORT='".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."', TO_PORT='".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."', DIS_TYPE='".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."', PASSAGE_TYPE='".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."', DISTANCE='".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."', SPEED_TYPE='".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."', SPEED_ADJ='".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."', MARGIN_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."', LOAD_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."', LOAD_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."', LOAD_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."', LOAD_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."', LOAD_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."', LOAD_PORT_IDEAL_DAYS='".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."', DISC_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."', DISC_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."', DISC_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."', DISC_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."', DISC_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."', DISC_PORT_IDEAL_DATE='".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."', TRANSIT_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."', TRANSIT_PORT_IDLE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', PORT_COSTLP_VENDOR='".$_REQUEST['selLPVendor_'.$i]."', DDCLP_COMM='".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', DDCLP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."', DDCLP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."', DDCLP_VENDOR='".$_REQUEST['selDDCLPVendor_'.$i]."', DDCLP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."', DDCDP_COMM='".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', DDCDP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."', DDCDP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."', DDCDP_VENDOR='".$_REQUEST['selDDCDPVendor_'.$i]."', DDCDP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."', PORT_COSTDP_VENDOR='".$_REQUEST['selDPVendor_'.$i]."', IS_SHOW_DDCLP='".$_REQUEST['ChkShowDDCLP_'.$i]."', IS_SHOW_DDCDP='".$_REQUEST['ChkShowDDCDP_'.$i]."', RANDOMID='".$randomid."', PORT_COSTTP_VENDOR='".$_REQUEST['selTPVendor_'.$i]."', CHK_LP_SECA='".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', CHK_DP_SECA='".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', CHK_TP_SECA='".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', TOTAL_VOYAGE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', SECA_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', SECA_DAYS='".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."' where FCAID='".$id."' and FCA_SLAVEID='".$_REQUEST['txtFCASlaveID_'.$i]."'";	
			}
			else
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, PORT_COSTLP_VENDOR, DDCLP_COMM, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_VENDOR, DDCLP_NETCOST, DDCDP_COMM, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_VENDOR, DDCDP_NETCOST, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, PORT_COSTTP_VENDOR, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS) values ('".$id."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."' ,'".$_REQUEST['selLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$_REQUEST['selDDCLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$_REQUEST['selDDCDPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['selDPVendor_'.$i]."','".$_REQUEST['ChkShowDDCLP_'.$i]."','".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$_REQUEST['selTPVendor_'.$i]."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."')";	
			}
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$id."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$id."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
	
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT, VENDORID ) values ('".$id."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selORCVendor_'.$i])."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT, VENDORID) values ('".$id."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOtherIncVendor_'.$i])."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."', '".$_REQUEST['selBrCommVendor_'.$i]."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtRateUSDmt_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] != "")
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."', 1, '".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtRateUSDmt2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] != "")
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtRateUSDmt3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] != "")
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, VENDORID, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$_REQUEST['selQtyVendor3_'.$i]."', '".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$id."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$id."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						 if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$id."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg; 
}


function displayVoyageReports()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="voyagereports" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="8%">Report Title/type</th>';
	echo '<th align="left" valign="middle" width="8%">Vessel Type</th>';
	echo '<th align="left" valign="middle" width="8%">Message No.</th>';
	echo '<th align="left" valign="middle" width="8%">Vessel Name</th>';
	echo '<th align="left" valign="middle" width="8%">Voy No.</th>';
	echo '<th align="left" valign="middle" width="8%">Charterer</th>';
	echo '<th align="left" valign="middle" width="8%">Reporting Date/Time(LT)</th>';
	echo '<th align="left" valign="middle" width="8%">Time Zone</th>';
	echo '<th align="left" valign="middle" width="8%">Reporting Date/Time(UTC)</th>';
	echo '<th align="left" valign="middle" width="8%">Draft Fore(M)</th>';
	echo '<th align="left" valign="middle" width="8%">Draft Fore(A)</th>';
	echo '<th align="left" valign="middle" width="8%">Dep Port</th>';
	echo '<th align="left" valign="middle" width="8%">Port Of Arrival</th>';
	echo '<th align="left" valign="middle" width="8%">Port Visit Reasons</th>';
	echo '<th align="left" valign="middle" width="8%">Next Port</th>';
	echo '<th align="left" valign="middle" width="10%">ETA Next Port</th>';
	echo '<th align="left" valign="middle" width="8%">Vessel Condition</th>';
	echo '<th align="left" valign="middle" width="8%">Weather Direction</th>';
	echo '<th align="left" valign="middle" width="8%">Wind Force</th>';
	echo '<th align="left" valign="middle" width="8%">Sea State</th>';
	echo '<th align="left" valign="middle" width="8%">Swell State</th>';
	echo '<th align="left" valign="middle" width="8%">Swell Direction</th>';
	echo '<th align="left" valign="middle" width="8%">Lat</th>';
	echo '<th align="left" valign="middle" width="8%">Long</th>';
	echo '<th align="left" valign="middle" width="8%">Ordered Speed</th>';
	echo '<th align="left" valign="middle" width="8%">Dist To Go (Nm)</th>';
	echo '<th align="left" valign="middle" width="8%">Total Voyage Dist. (Nm)</th>';
	echo '<th align="left" valign="middle" width="8%">Obsd Dist. (Nm)</th>';
	echo '<th align="left" valign="middle" width="8%">Noon Hdg (Deg)</th>';
	echo '<th align="left" valign="middle" width="8%">Stoppage (Hrs)</th>';
	echo '<th align="left" valign="middle" width="8%">Effective Steaming (Hrs)</th>';
	echo '<th align="left" valign="middle" width="8%">Obsd Speed (Kts)</th>';
	
	echo '<th align="left" valign="middle" width="8%">Down&nbsp;Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>';
	echo '<th align="left" valign="middle" width="8%">Consp (Main Propulsion + AEs)</th>';
	echo '<th align="left" valign="middle" width="8%">Consp (Tank Cleaning/Crude Oil Washing)</th>';
	echo '<th align="left" valign="middle" width="8%">Consp (Gas Freeing/Inerting)</th>';
	echo '<th align="left" valign="middle" width="8%">Consp Other</th>';
	echo '<th align="left" valign="middle" width="8%">Total ROB</th>';
	echo '<th align="left" valign="middle" width="8%">Total Consp</th>';
	echo '<th align="left" valign="middle" width="8%">Bunker Supplied</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	
	$sql = "select * from sa_departure_master WHERE IMO_NO='".$_REQUEST['vesselimono']."'  ";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['REPORT_TITLE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CHARTERER'].'</td>';
				if($rows['REPORTING_DATETIME_LT']=="" || $rows['REPORTING_DATETIME_LT']=="1970-01-01 00:00"){$REPORTING_DATETIME_LT = "";}else{$REPORTING_DATETIME_LT = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_LT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_LT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PREFIX'].' '.$rows['TIME_RELATIVE_UTC'].'</td>';
				if($rows['REPORTING_DATETIME_UTC']=="" || $rows['REPORTING_DATETIME_UTC']=="1970-01-01 00:00"){$REPORTING_DATETIME_UTC = "";}else{$REPORTING_DATETIME_UTC = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_UTC']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_UTC.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_FORE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_AFT'].'</td>';			
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PORT_DEPARTED_FROM'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NEXT_PORT'].'</td>';
				if($rows['ETA_NEXT_PORT']=="" || $rows['ETA_NEXT_PORT']=="1970-01-01 00:00"){$ETA_NEXT_PORT = "";}else{$ETA_NEXT_PORT = date('d-m-Y H:i',strtotime($rows['ETA_NEXT_PORT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$ETA_NEXT_PORT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_CONDITION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WEATHER_DIRECTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WIND_FORCE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SEA_STATE'].'</td>';				
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWEEL_STATE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWELL_DIRN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LATTITUDE'].' '.$rows['LAT_DEG'].' '.$rows['LAT_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LONGITUDE'].' '.$rows['LONG_DEG'].' '.$rows['LONG_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SPEED_TO_NEXT_PORT'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DISTANCE_TO_GO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				
				$sql2 = "select * from sa_departure_slave WHERE DEPARTUREID='".$rows['DEPARTUREID']."'  ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '</tr>';
				$i++;
		}
	
	}
	
	
	$sql = "select * from sa_noon_master WHERE IMO_NO='".$_REQUEST['vesselimono']."'  ";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['REPORT_TITLE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CHARTERER'].'</td>';
				if($rows['REPORTING_DATETIME_LT']=="" || $rows['REPORTING_DATETIME_LT']=="1970-01-01 00:00"){$REPORTING_DATETIME_LT = "";}else{$REPORTING_DATETIME_LT = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_LT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_LT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PREFIX'].' '.$rows['TIME_RELATIVE_UTC'].'</td>';
				if($rows['REPORTING_DATETIME_UTC']=="" || $rows['REPORTING_DATETIME_UTC']=="1970-01-01 00:00"){$REPORTING_DATETIME_UTC = "";}else{$REPORTING_DATETIME_UTC = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_UTC']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_UTC.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_FORE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_AFT'].'</td>';			
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NEXT_PORT'].'</td>';
				if($rows['ETA_NEXT_PORT']=="" || $rows['ETA_NEXT_PORT']=="1970-01-01 00:00"){$ETA_NEXT_PORT = "";}else{$ETA_NEXT_PORT = date('d-m-Y H:i',strtotime($rows['ETA_NEXT_PORT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$ETA_NEXT_PORT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_CONDITION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WEATHER_DIRECTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WIND_FORCE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SEA_STATE'].'</td>';				
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWEEL_STATE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWELL_DIRN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LATTITUDE'].' '.$rows['LAT_DEG'].' '.$rows['LAT_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LONGITUDE'].' '.$rows['LONG_DEG'].' '.$rows['LONG_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DISTANCE_TO_GO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['OBSERVED_DIST'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NOON_HDG'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['STOPPAGE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['EFFECTIVE_STEAMING'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['OBSERVED_SPEED'].'</td>';
				
				$sql2 = "select * from sa_noon_slave2 WHERE NOONID='".$rows['NOONID']."'";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robssspdowntime = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				    $sql3 = "select * from sa_noon_slave3 WHERE NOONID='".$rows['NOONID']."' and NOON_SLAVEID ='".$rows2['NOON_SLAVEID']."' ";
					$res3 = mysql_query($sql3) or die($sql3);
					$rec3 = mysql_num_rows($res3);
					$robssspbunker = array();
					while($rows3 = mysql_fetch_assoc($res3))
					{ 
						 $robssspbunker[] =  $rows3['BUNKER'].'&nbsp;-&nbsp;'.$rows3['QUANTITY'].'&nbsp;MT';
					}
				     $robssspdowntime[] =  $rows2['DOWNTIME_TYPE'].' - '.date('d-m-Y H:i', strtotime($rows2['FROM_LT_DATETIME'])).' To '.date('d-m-Y H:i', strtotime($rows2['TO_LT_DATETIME'])).' Bunker Consumed :<br/>'.implode('<br/>',$robssspbunker).'<Br/>';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robssspdowntime).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('MAINPROP_AE_BUNKER','CONSP_MP_AE_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('OT_OTHERS_BUNKER','CONSPGC_OTHER_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('ROB_BUNKER', 'ROB_TOTAL_BUNKER','ROBGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('CONSUMPTION_BUNKER', 'CONSP_TOTAL_BUNKER','CONSPGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '</tr>';
				$i++;
		}
	
	}
	
	
	$sql = "select * from sa_arrival_master WHERE IMO_NO='".$_REQUEST['vesselimono']."'  ";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['REPORT_TITLE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				if($rows['REPORTING_DATETIME_LT']=="" || $rows['REPORTING_DATETIME_LT']=="1970-01-01 00:00"){$REPORTING_DATETIME_LT = "";}else{$REPORTING_DATETIME_LT = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_LT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_LT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PREFIX'].' '.$rows['TIME_RELATIVE_UTC'].'</td>';
				if($rows['REPORTING_DATETIME_UTC']=="" || $rows['REPORTING_DATETIME_UTC']=="1970-01-01 00:00"){$REPORTING_DATETIME_UTC = "";}else{$REPORTING_DATETIME_UTC = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_UTC']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_UTC.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_FORE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_AFT'].'</td>';			
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PORT_OF_ARRIVAL'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PORT_VISIT_REASON'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				if($rows['ETA_NEXT_PORT']=="" || $rows['ETA_NEXT_PORT']=="1970-01-01 00:00"){$ETA_NEXT_PORT = "";}else{$ETA_NEXT_PORT = date('d-m-Y H:i',strtotime($rows['ETA_NEXT_PORT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$ETA_NEXT_PORT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_CONDITION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WEATHER_DIRECTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WIND_FORCE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SEA_STATE'].'</td>';				
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWEEL_STATE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWELL_DIRN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LATTITUDE'].' '.$rows['LAT_DEG'].' '.$rows['LAT_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LONGITUDE'].' '.$rows['LONG_DEG'].' '.$rows['LONG_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_DISTANCE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['OBSERVED_DIST'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NOON_HDG'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['STOPPAGE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['EFFECTIVE_STEAMING'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['OBSERVED_SPEED'].'</td>';
				
				$sql2 = "select * from sa_arrival_slave2 WHERE ARRIVALID='".$rows['ARRIVALID']."'";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robssspdowntime = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				    $sql3 = "select * from sa_arrival_slave3 WHERE ARRIVALID='".$rows['ARRIVALID']."' and ARRIVAL_SLAVEID ='".$rows2['ARRIVAL_SLAVEID']."' ";
					$res3 = mysql_query($sql3) or die($sql3);
					$rec3 = mysql_num_rows($res3);
					$robssspbunker = array();
					while($rows3 = mysql_fetch_assoc($res3))
					{ 
						 $robssspbunker[] =  $rows3['BUNKER'].'&nbsp;-&nbsp;'.$rows3['QUANTITY'].'&nbsp;MT';
					}
				     $robssspdowntime[] =  $rows2['DOWNTIME_TYPE'].' - '.date('d-m-Y H:i', strtotime($rows2['FROM_LT_DATETIME'])).' To '.date('d-m-Y H:i', strtotime($rows2['TO_LT_DATETIME'])).' Bunker Consumed :<br/>'.implode('<br/>',$robssspbunker).'<Br/>';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robssspdowntime).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('MAINPROP_AE_BUNKER','CONSP_MP_AE_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('OT_OTHERS_BUNKER','CONSPGC_OTHER_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('ROB_BUNKER', 'ROB_TOTAL_BUNKER','ROBGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('CONSUMPTION_BUNKER', 'CONSP_TOTAL_BUNKER','CONSPGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '</tr>';
				$i++;
		}
	
	}
	
	
	$sql = "select * from sa_portmessage_master WHERE IMO_NO='".$_REQUEST['vesselimono']."'  ";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['REPORT_TITLE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				if($rows['REPORTING_DATETIME_LT']=="" || $rows['REPORTING_DATETIME_LT']=="1970-01-01 00:00"){$REPORTING_DATETIME_LT = "";}else{$REPORTING_DATETIME_LT = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_LT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_LT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PREFIX'].' '.$rows['TIME_RELATIVE_UTC'].'</td>';
				if($rows['REPORTING_DATETIME_UTC']=="" || $rows['REPORTING_DATETIME_UTC']=="1970-01-01 00:00"){$REPORTING_DATETIME_UTC = "";}else{$REPORTING_DATETIME_UTC = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_UTC']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_UTC.'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';			
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PORT_OF_ARRIVAL'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';				
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				
				$sql2 = "select * from sa_portmessage_slave2 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."'";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robssspdowntime = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				    $sql3 = "select * from sa_portmessage_slave3 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and PORTMESSAGE_SLAVEID ='".$rows2['PORTMESSAGE_SLAVEID']."' ";
					$res3 = mysql_query($sql3) or die($sql3);
					$rec3 = mysql_num_rows($res3);
					$robssspbunker = array();
					while($rows3 = mysql_fetch_assoc($res3))
					{ 
						 $robssspbunker[] =  $rows3['BUNKER'].'&nbsp;-&nbsp;'.$rows3['QUANTITY'].'&nbsp;MT';
					}
				     $robssspdowntime[] =  $rows2['DOWNTIME_TYPE'].' - '.date('d-m-Y H:i', strtotime($rows2['FROM_LT_DATETIME'])).' To '.date('d-m-Y H:i', strtotime($rows2['TO_LT_DATETIME'])).' Bunker Consumed :<br/>'.implode('<br/>',$robssspbunker).'<Br/>';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robssspdowntime).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('MAINPROP_AE_BUNKER','CONSP_MP_AE_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('OT_OTHERS_BUNKER','CONSPGC_OTHER_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('ROB_BUNKER', 'ROB_TOTAL_BUNKER','ROBGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('CONSUMPTION_BUNKER', 'CONSP_TOTAL_BUNKER','CONSPGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave4 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'MT @ '.$rows2['RATE_MT'].'USD + '.$rows2['ADDNL_COST'].'USD = '.$rows2['TOTAL_COST'].'USD';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				echo '</tr>';
				$i++;
		}
	
	}
	
	echo '</tbody>';
	echo '</table></div>';
}



function insertInvoiceHireDetailsTC()
{
	$connect = $this->funConnect(); 
	
	$comid 			    = addslashes(trim($_REQUEST['comid']));
	$txtInID	 	    = addslashes(trim($_REQUEST['txtInID']));
	$txtTCOUTID         = addslashes(trim($_REQUEST['txtTCOUTID']));
	$randomid           = addslashes(trim($_REQUEST['randomid']));
	$txtStatus	 	    = addslashes(trim($_REQUEST['txtStatus']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtInvNo    	 	= addslashes(trim($_REQUEST['txtInvNo']));
	$txtInvDate	 		= date("Y-m-d",strtotime($_REQUEST['txtInvDate']));
	$txtHireStatementDate = date("Y-m-d",strtotime($_REQUEST['txtHireStatementDate']));
	$txtExchangeRate 	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$txtExchangeDate	= date('Y-m-d',strtotime($_REQUEST['txtExchangeDate']));
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc	 		= addslashes(trim($_REQUEST['txtDesc']));
	$txtEstHireDays   	= addslashes(trim($_REQUEST['txtEstHireDays']));
	$txtHireperDay	 	= addslashes(trim($_REQUEST['txtHireperDay']));	
	
	$ChkOverConspBunker = addslashes(trim($_REQUEST['ChkOverConspBunker']));
	
	$txtHireDays    	= addslashes(trim($_REQUEST['txtHireDays']));
	$txtTotalHire 		= addslashes(trim($_REQUEST['txtTotalHire']));
	$txtCVEMonth    	= addslashes(trim($_REQUEST['txtCVEMonth']));
	$txtCVE_Amt  	 	= addslashes(trim($_REQUEST['txtCVE_Amt']));
	$txtAddrCommPer	    = addslashes(trim($_REQUEST['txtAddrCommPer']));
	$txtAddrCommAmt	 	= addslashes(trim($_REQUEST['txtAddrCommAmt']));
	$txtBroCommPer  	= addslashes(trim($_REQUEST['txtBroCommPer']));
	$txtBroCommAmt      = addslashes(trim($_REQUEST['txtBroCommAmt']));
	$ChkShowOffHire     = addslashes(trim($_REQUEST['ChkShowOffHire']));
	$ChkBallastBonus    = addslashes(trim($_REQUEST['ChkBallastBonus']));
	$txtOffHireDays	 	= addslashes(trim($_REQUEST['txtOffHireDays']));
	$txtOffHire     	= addslashes(trim($_REQUEST['txtOffHire']));
	$txtCVEOffHireMonth = addslashes(trim($_REQUEST['txtCVEOffHireMonth']));
	$txtCVEOFFHIRE_Amt  = addslashes(trim($_REQUEST['txtCVEOFFHIRE_Amt']));
	$ChkDeliveryBunker  = addslashes(trim($_REQUEST['ChkDeliveryBunker']));
	$ChkReDeliveryBunker= addslashes(trim($_REQUEST['ChkReDeliveryBunker']));
	$txtFinalAmt        = addslashes(trim($_REQUEST['txtFinalAmt']));
	$selFromOwner       = addslashes(trim($_REQUEST['selFromOwner']));
	$txtBallastBonus    = addslashes(trim($_REQUEST['txtBallastBonus']));
	
	$txtBalanceShipOwner    = addslashes(trim($_REQUEST['txtBalanceShipOwner']));
	$selBankingID       = addslashes(trim($_REQUEST['selBankingID']));
	$selBankingID1             = $_REQUEST['selBankingID1'];
	//echo $selBankingID;die;
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$filename = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$filename = implode(',',$filename);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $filename != ''){ $filename1 = $txtCRMNAME1.','.$filename;}
	else if($txtCRMNAME1 == '' && $filename != ''){ $filename1 = $filename;}
	else if($txtCRMNAME1 != '' && $filename == ''){ $filename1 = $txtCRMNAME1;}
	
	$selApprovers             = $_REQUEST['selApprovers'];
	$invoiceidd = '';$creatorloginid = '';
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$this->getCharteringEstimateTCData($comid,"TCOUTID")."' and RANDOMID='".$_REQUEST['randomid']."'";
	$restc 	= mysql_query($sqltc);
	$rectc 	= mysql_num_rows($restc);
	$rowstc = mysql_fetch_assoc($restc);
	
	
	if($txtInID == '')
	{
		$sql = "insert into invoice_hiretc_master (MCOMPANYID, MODULEID, COMID, INVOICE_DATE, STATUS, INVOICE_TYPE, INVOICE_NO, EXCHANGE_DATE, EXCHANGE_RATE, CURRENCY, PAYMENT_TERMS, DESCRIPTION, HIRE_DAYS, HIRE_AMT, CVE, CVE_AMT, ADD_COMM_PER, ADD_COMM_AMT, OFFHIRE_DAYS, OFFHIRE_AMT, OFFHIRE_CVE, OFFHIRE_CVE_AMT, FINAL_AMT, BRO_COMM_PER, BRO_COMM_AMT, CHK_OFFHIRE, CHK_DELIVERY, CHK_REDELIVERY, SHIP_OWNER, TCOUTID, RANDOMID, CHK_BALLAST_BONUS, BALLAST_BONUS, STATEMENT_DATE, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME, CHK_OVERCONSP, BALANCE_TO_OWNER, BANKING_DETAILS, VENDOR_SLAVEID, BANKINGDETAILID,PAYMENT_STATUS) values ('".$_SESSION['company']."', '".$_SESSION['moduleid']."', '".$comid."', '".$txtInvDate."', '".$txtStatus."', '".$selIType."', '".$txtInvNo."', '".$txtExchangeDate."', '".$this->getCheckNullVal($txtExchangeRate)."', '".$selExchangeCurrency."', '".$txtPaymentTerms."', '".$txtDesc."', '".$this->getCheckNullVal($txtHireDays)."', '".$txtTotalHire."', '".$this->getCheckNullVal($txtCVEMonth)."', '".$this->getCheckNullVal($txtCVE_Amt)."', '".$this->getCheckNullVal($txtAddrCommPer)."', '".$this->getCheckNullVal($txtAddrCommAmt)."', '".$this->getCheckNullVal($txtOffHireDays)."', '".$this->getCheckNullVal($txtOffHire)."', '".$this->getCheckNullVal($txtCVEOffHireMonth)."', '".$this->getCheckNullVal($txtCVEOFFHIRE_Amt)."', '".$this->getCheckNullVal($txtFinalAmt)."', '".$this->getCheckNullVal($txtBroCommPer)."', '".$this->getCheckNullVal($txtBroCommAmt)."', '".$this->getCheckNullVal($ChkShowOffHire)."', '".$this->getCheckNullVal($ChkDeliveryBunker)."', '".$this->getCheckNullVal($ChkReDeliveryBunker)."', '".$selFromOwner."', '".$txtTCOUTID."', '".$randomid."', '".$this->getCheckNullVal($ChkBallastBonus)."', '".$this->getCheckNullVal($txtBallastBonus)."', '".$txtHireStatementDate."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$upload1."', '".$filename1."', '".$this->getCheckNullVal($ChkOverConspBunker)."', '".$this->getCheckNullVal($txtBalanceShipOwner)."', '".addslashes(trim($this->getVendorListNewData($rowstc['TC_FINAL_HIERAGE_VENDOR'],"BANKING_DETAILS")))."', '".$this->getCheckNullVal($selBankingID)."', '".$this->getCheckNullVal($selBankingID1)."', '".$this->getCheckNullVal($_REQUEST['payment_status'])."')";
		mysql_query($sql) or die($sql);
		
		$sql1 = "select max(INVOICEID) as max from invoice_hiretc_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$invoiceidd = $rows1['max'];
		$creatorloginid =  $_SESSION['uid'];
		
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into invoice_hiretc_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into invoice_hiretc_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		
		$totalDaysTows  = $_REQUEST['totalDaysTows'];
		for($i=1;$i<=$totalDaysTows;$i++)
		{
			$txtRandom	 	  = addslashes(trim($_REQUEST['txtRandom_'.$i]));
			$txtInvDay  	  = $this->getCheckNullVal($_REQUEST['txtInvDay_'.$i]);
			$txtAddCommAmt 	  = addslashes(trim($_REQUEST['txtAddCommAmt_'.$i]));
			$txtBroCommAmt	  = $this->getCheckNullVal($_REQUEST['txtBroCommAmt_'.$i]);
			$txtCVEPerAmt 	  = addslashes(trim($_REQUEST['txtCVEPerAmt_'.$i]));
			$txtInvHire 	  = addslashes(trim($_REQUEST['txtInvHire_'.$i]));
			
			$txtHireFrom    	= date('Y-m-d H:i',strtotime($_REQUEST['txtHireFrom_'.$i]));
	        $txtHireTo    	    = date('Y-m-d H:i',strtotime($_REQUEST['txtHireTo_'.$i]));
			
			$sql2 = "insert into invoice_hiretc_slave3 (INVOICEID, RANDOMID, UTILISED_DAYS, ADD_COMM, BROKERAGE_AMT, CVE_AMT, HIRE_AMT, HIRE_FROM, HIRE_TO) values ('".$rows1['max']."', '".$txtRandom."', '".$txtInvDay."', '".$txtAddCommAmt."', '".$txtBroCommAmt."', '".$txtCVEPerAmt."', '".$txtInvHire."', '".$txtHireFrom."', '".$txtHireTo."')";
			mysql_query($sql2);
		}
		
		$txtHoldID  = $_REQUEST['txtHoldID'];
		for($i=1;$i<=$txtHoldID;$i++)
		{
			$txtHoldDes	 	  = addslashes(trim($_REQUEST['txtHoldDes_'.$i]));
			$txtHoldDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHoldDesAmt_'.$i]);
			$sql2 = "insert into invoice_hiretc_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtHoldDes."', '".$txtHoldDesAmt."', 'HOLD_CLEANING')";
			mysql_query($sql2);
		}
		
		$txtHireSurveyID  = $_REQUEST['txtHireSurveyID'];
		for($i=1;$i<=$txtHireSurveyID;$i++)
		{
			$txtHireSurveyDes	 	  = addslashes(trim($_REQUEST['txtHireSurveyDes_'.$i]));
			$Chk_Owner_Account  	  = $this->getCheckNullVal($_REQUEST['Chk_Owner_Account_'.$i]);
			$txtHireSurveyDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHireSurveyDesAmt_'.$i]);
			$sql2 = "insert into invoice_hiretc_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY, CHK_OWNER_ACC) values ('".$rows1['max']."', '".$txtHireSurveyDes."', '".$txtHireSurveyDesAmt."', 'HIRE_SURVEY', '".$this->getCheckNullVal($Chk_Owner_Account)."')";
			mysql_query($sql2);
		}
		
		if($ChkShowOffHire==1)
		{
			$txtOFFID = $_REQUEST['txtOFFID'];
			for($i=1 ; $i<=$txtOFFID ;$i++)
			{
				if($_REQUEST['txtOffHireReason_'.$i] != "")
				{
					if($_REQUEST['txtOffHireFrom_'.$i]!="")
					{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
					else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtOffHireTo_'.$i]!="")
					{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
					else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
					
					$sql3 = "insert into invoice_hiretc_slave5 (INVOICEID, OFFHIRE_REASON, OFF_HIRE_FROM, OFF_HIRE_TO, OFF_HIRE_PERCENT, OFF_HIRE_DAYS, OF_HIRE_AMT, OFF_HIRE_RATE) values ('".$rows1['max']."', '".$_REQUEST['txtOffHireReason_'.$i]."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHirePercent_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOffHirePerDay_'.$i])."')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
					
					$mysql14 = "select max(INVOICE_SLAVE5ID) as max from invoice_hiretc_slave5 where INVOICEID='".$rows1['max']."'";
					$myres14  =  mysql_query($mysql14);
					$myrows14 = mysql_fetch_assoc($myres14);
					$maxid14 = $myrows14['max'];
					
					$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
					for($m=1 ; $m<=$txtDELID ;$m++)
					{
						if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
						{
							$sql15 = "insert into invoice_hiretc_slave51 (INVOICE_SLAVE5ID, INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT) values ('".$maxid14."', '".$rows1['max']."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."')";
							mysql_query($sql15) or die($sql15);
							mysql_query("commit");
						}
					}
				}
			}
		}
		
		$txtAddOVERCONPID = $_REQUEST['txtAddOVERCONPID'];
		for($i=1;$i<=$txtAddOVERCONPID;$i++)
		{
			if($_REQUEST['selOverConspBunker_'.$i]!='')
			{
				$txtOverConspBunkerQty 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerQty_'.$i]);
				$selOverConspBunker	      = $this->getCheckNullVal($_REQUEST['selOverConspBunker_'.$i]);
				$txtOverConspBunkerPrice  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerPrice_'.$i]);
				$txtOverConspBunkerAmt 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hiretc_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selOverConspBunker."', '".$txtOverConspBunkerQty."', '".$txtOverConspBunkerPrice."', '".$txtOverConspBunkerAmt."', 'OVERCONSP')";
				mysql_query($sql2);
			}
		}
		
		
		$txtDelbid  = $_REQUEST['txtAddDELID'];
		for($i=1;$i<=$txtDelbid;$i++)
		{
			if($_REQUEST['selDELBunker_'.$i]!='')
			{
				$selDELBunker	 	      = $this->getCheckNullVal($_REQUEST['selDELBunker_'.$i]);
				$txtDelBunkerQty	      = $this->getCheckNullVal($_REQUEST['txtDelBunkerQty_'.$i]);
				$txtDelBunkerPrice	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerPrice_'.$i]);
				$txtDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hiretc_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selDELBunker."', '".$txtDelBunkerQty."', '".$txtDelBunkerPrice."', '".$txtDelBunkerAmt."', 'DEL')";
				mysql_query($sql2);
			}
		}
		
		$txtAddREDELID = $_REQUEST['txtAddREDELID'];
		for($i=1;$i<=$txtAddREDELID;$i++)
		{
			if($_REQUEST['selReDELBunker_'.$i]!='')
			{
				$txtReDelBunkerQty	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerQty_'.$i]);
				$selReDELBunker  	      = $this->getCheckNullVal($_REQUEST['selReDELBunker_'.$i]);
				$txtReDelBunkerPrice	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerPrice_'.$i]);
				$txtReDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hiretc_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$rows1['max']."', '".$selReDELBunker."', '".$txtReDelBunkerQty."', '".$txtReDelBunkerPrice."', '".$txtReDelBunkerAmt."', 'REDEL')";
				mysql_query($sql2);
			}
		}
		
		$txtORCID  = $_REQUEST['txtORCID'];
		for($i=1;$i<=$txtORCID;$i++)
		{
		    if(isset($_REQUEST['chkORC_'.$i]))
			{
				$txtORCIdentity	 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCIdentity_'.$i])));
				$txtORCVendorid  	  = addslashes(trim($_REQUEST['txtORCVendorid_'.$i]));
				$txtORCDesc     	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCDesc_'.$i])));
				$txtORCAmt      	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCAmt_'.$i])));
				
				$sql2 = "insert into invoice_hiretc_slave6 (INVOICEID, VENDORID, IDENTITY, AMOUNT, DESCRIPTION) values ('".$rows1['max']."', '".$txtORCVendorid."', '".$txtORCIdentity."', '".$txtORCAmt."', '".$txtORCDesc."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$hddnprevinvid  = $_REQUEST['hddnprevinvid'];
		for($i=1;$i<=$hddnprevinvid;$i++)
		{
		    if(isset($_REQUEST['chkPrevInv_'.$i]))
			{
				$txtPrevInvID	 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtPrevInvID_'.$i])));
				$txtPrevInvIdentify	  = addslashes(trim($_REQUEST['txtPrevInvIdentify_'.$i]));
				$sql2 = "insert into invoice_hiretc_slave7 (INVOICEID, PINVOICEID, IDENTIFY) values ('".$rows1['max']."', '".$txtPrevInvID."', '".$txtPrevInvIdentify."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		
		$this->saveRecentWork($selIType." Hire Statement (".$txtInvNo.") Created Successfully.");
	}
	else
	{
	    $invoiceidd = $txtInID;
		
		$sql_sel = "select APPROVERS, CREATOR from invoice_hiretc_master where INVOICEID='".$txtInID."'";
		$res_sel = mysql_query($sql_sel) or die($sql_sel);
		$rows_sel = mysql_fetch_assoc($res_sel);
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $rows_sel['APPROVERS'];
		}
		$creatorloginid = $rows_sel['CREATOR'];
	
		$sql = "update invoice_hiretc_master set COMID='".$comid."', INVOICE_DATE='".$txtInvDate."', STATUS='".$txtStatus."', INVOICE_TYPE='".$selIType."', INVOICE_NO='".$txtInvNo."', EXCHANGE_DATE='".$txtExchangeDate."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', CURRENCY='".$selExchangeCurrency."', PAYMENT_TERMS='".$txtPaymentTerms."', DESCRIPTION='".$txtDesc."', HIRE_FROM='".$txtHireFrom."', HIRE_TO='".$txtHireTo."', HIRE_DAYS='".$this->getCheckNullVal($txtHireDays)."', HIRE_AMT='".$this->getCheckNullVal($txtTotalHire)."', CVE='".$this->getCheckNullVal($txtCVEMonth)."', CVE_AMT='".$this->getCheckNullVal($txtCVE_Amt)."', ADD_COMM_PER='".$this->getCheckNullVal($txtAddrCommPer)."', ADD_COMM_AMT='".$this->getCheckNullVal($txtAddrCommAmt)."', OFFHIRE_DAYS='".$this->getCheckNullVal($txtOffHireDays)."', OFFHIRE_AMT='".$this->getCheckNullVal($txtOffHire)."', OFFHIRE_CVE='".$this->getCheckNullVal($txtCVEOffHireMonth)."', OFFHIRE_CVE_AMT='".$this->getCheckNullVal($txtCVEOFFHIRE_Amt)."', FINAL_AMT='".$this->getCheckNullVal($txtFinalAmt)."', BRO_COMM_PER='".$this->getCheckNullVal($txtBroCommPer)."', BRO_COMM_AMT='".$this->getCheckNullVal($txtBroCommAmt)."', CHK_OFFHIRE='".$this->getCheckNullVal($ChkShowOffHire)."', CHK_DELIVERY='".$this->getCheckNullVal($ChkDeliveryBunker)."', CHK_REDELIVERY='".$this->getCheckNullVal($ChkReDeliveryBunker)."', SHIP_OWNER='".$selFromOwner."', STATEMENT_DATE='".$txtHireStatementDate."', APPROVERS='".$approversel."', UPLOAD='".$upload1."', UPLOAD_NAME='".$filename1."', CHK_OVERCONSP='".$this->getCheckNullVal($ChkOverConspBunker)."', BALANCE_TO_OWNER='".$this->getCheckNullVal($txtBalanceShipOwner)."', BALLAST_BONUS='".$this->getCheckNullVal($txtBallastBonus)."', CHK_BALLAST_BONUS='".$this->getCheckNullVal($ChkBallastBonus)."', BANKING_DETAILS = '".addslashes(trim($this->getVendorListNewData($rowstc['TC_FINAL_HIERAGE_VENDOR'],"BANKING_DETAILS")))."', VENDOR_SLAVEID='".$this->getCheckNullVal($selBankingID)."', BANKINGDETAILID='".$this->getCheckNullVal($selBankingID1)."', PAYMENT_STATUS='".$this->getCheckNullVal($_REQUEST['payment_status'])."' where INVOICEID='".$txtInID."'";
		
		mysql_query($sql) or die($sql);
		
		$sql1 = "delete from invoice_hiretc_slave1  where INVOICEID='".$txtInID."'";
		$sql2 = "delete from invoice_hiretc_slave2  where INVOICEID='".$txtInID."'";
		$sql3 = "delete from invoice_hiretc_slave3  where INVOICEID='".$txtInID."'";
		$sql4 = "delete from invoice_hiretc_slave4  where INVOICEID='".$txtInID."'";
		$sql5 = "delete from invoice_hiretc_slave5  where INVOICEID='".$txtInID."'";
		$sql51 = "delete from invoice_hiretc_slave51  where INVOICEID='".$txtInID."'";
		$sql6 = "delete from invoice_hiretc_slave6  where INVOICEID='".$txtInID."'";
		$sql7 = "delete from invoice_hiretc_slave7  where INVOICEID='".$txtInID."'";
		mysql_query($sql1);
		mysql_query($sql2);
		mysql_query($sql3);
		mysql_query($sql4);
		mysql_query($sql5);
		mysql_query($sql51);
		mysql_query($sql6);
		mysql_query($sql7);
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into invoice_hiretc_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into invoice_hiretc_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		
		$totalDaysTows  = $_REQUEST['totalDaysTows'];
		for($i=1;$i<=$totalDaysTows;$i++)
		{
			$txtRandom	 	  = addslashes(trim($_REQUEST['txtRandom_'.$i]));
			$txtInvDay  	  = $this->getCheckNullVal($_REQUEST['txtInvDay_'.$i]);
			$txtAddCommAmt 	  = addslashes(trim($_REQUEST['txtAddCommAmt_'.$i]));
			$txtBroCommAmt	  = $this->getCheckNullVal($_REQUEST['txtBroCommAmt_'.$i]);
			$txtCVEPerAmt 	  = addslashes(trim($_REQUEST['txtCVEPerAmt_'.$i]));
			$txtInvHire 	  = addslashes(trim($_REQUEST['txtInvHire_'.$i]));
			
			$txtHireFrom    	= date('Y-m-d H:i',strtotime($_REQUEST['txtHireFrom_'.$i]));
	        $txtHireTo    	    = date('Y-m-d H:i',strtotime($_REQUEST['txtHireTo_'.$i]));
			
			$sql2 = "insert into invoice_hiretc_slave3 (INVOICEID, RANDOMID, UTILISED_DAYS, ADD_COMM, BROKERAGE_AMT, CVE_AMT, HIRE_AMT, HIRE_FROM, HIRE_TO) values ('".$txtInID."', '".$txtRandom."', '".$txtInvDay."', '".$txtAddCommAmt."', '".$txtBroCommAmt."', '".$txtCVEPerAmt."', '".$txtInvHire."', '".$txtHireFrom."', '".$txtHireTo."')";
			mysql_query($sql2);
		}
		
		$txtHoldID  = $_REQUEST['txtHoldID'];
		for($i=1;$i<=$txtHoldID;$i++)
		{
			$txtHoldDes	 	  = addslashes(trim($_REQUEST['txtHoldDes_'.$i]));
			$txtHoldDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHoldDesAmt_'.$i]);
			$sql2 = "insert into invoice_hiretc_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtHoldDes."', '".$txtHoldDesAmt."', 'HOLD_CLEANING')";
			mysql_query($sql2);
		}
		
		$txtHireSurveyID  = $_REQUEST['txtHireSurveyID'];
		for($i=1;$i<=$txtHireSurveyID;$i++)
		{
			$txtHireSurveyDes	 	  = addslashes(trim($_REQUEST['txtHireSurveyDes_'.$i]));
			$Chk_Owner_Account  	  = $this->getCheckNullVal($_REQUEST['Chk_Owner_Account_'.$i]);
			$txtHireSurveyDesAmt	  = $this->getCheckNullVal($_REQUEST['txtHireSurveyDesAmt_'.$i]);
			$sql2 = "insert into invoice_hiretc_slave1 (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY, CHK_OWNER_ACC) values ('".$txtInID."', '".$txtHireSurveyDes."', '".$txtHireSurveyDesAmt."', 'HIRE_SURVEY', '".$this->getCheckNullVal($Chk_Owner_Account)."')";
			mysql_query($sql2);
		}
		
		if($ChkShowOffHire==1)
		{
			$txtOFFID = $_REQUEST['txtOFFID'];
			for($i=1 ; $i<=$txtOFFID ;$i++)
			{
				if($_REQUEST['txtOffHireReason_'.$i] != "")
				{
					if($_REQUEST['txtOffHireFrom_'.$i]!="")
					{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
					else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtOffHireTo_'.$i]!="")
					{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
					else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
					
					$sql3 = "insert into invoice_hiretc_slave5 (INVOICEID, OFFHIRE_REASON, OFF_HIRE_FROM, OFF_HIRE_TO, OFF_HIRE_PERCENT, OFF_HIRE_DAYS, OF_HIRE_AMT, OFF_HIRE_RATE) values ('".$txtInID."', '".$_REQUEST['txtOffHireReason_'.$i]."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHirePercent_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOffHirePerDay_'.$i])."')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
					
					$mysql14 = "select max(INVOICE_SLAVE5ID) as max from invoice_hiretc_slave5 where INVOICEID='".$txtInID."'";
					$myres14  =  mysql_query($mysql14);
					$myrows14 = mysql_fetch_assoc($myres14);
					$maxid14 = $myrows14['max'];
					
					$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
					for($m=1 ; $m<=$txtDELID ;$m++)
					{
						if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
						{
							$sql15 = "insert into invoice_hiretc_slave51 (INVOICE_SLAVE5ID, INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT) values ('".$maxid14."', '".$txtInID."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."')";
							mysql_query($sql15) or die($sql15);
							mysql_query("commit");
						}
					}
				}
			}
		}
		
		$txtAddOVERCONPID = $_REQUEST['txtAddOVERCONPID'];
		for($i=1;$i<=$txtAddOVERCONPID;$i++)
		{
			if($_REQUEST['selOverConspBunker_'.$i]!='')
			{
				$txtOverConspBunkerQty 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerQty_'.$i]);
				$selOverConspBunker	      = $this->getCheckNullVal($_REQUEST['selOverConspBunker_'.$i]);
				$txtOverConspBunkerPrice  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerPrice_'.$i]);
				$txtOverConspBunkerAmt 	  = $this->getCheckNullVal($_REQUEST['txtOverConspBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hiretc_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selOverConspBunker."', '".$txtOverConspBunkerQty."', '".$txtOverConspBunkerPrice."', '".$txtOverConspBunkerAmt."', 'OVERCONSP')";
				mysql_query($sql2);
			}
		}
		
		$txtDelbid  = $_REQUEST['txtAddDELID'];
		for($i=1;$i<=$txtDelbid;$i++)
		{
			if($_REQUEST['selDELBunker_'.$i]!='')
			{
				$selDELBunker	 	      = $this->getCheckNullVal($_REQUEST['selDELBunker_'.$i]);
				$txtDelBunkerQty	      = $this->getCheckNullVal($_REQUEST['txtDelBunkerQty_'.$i]);
				$txtDelBunkerPrice	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerPrice_'.$i]);
				$txtDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hiretc_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selDELBunker."', '".$txtDelBunkerQty."', '".$txtDelBunkerPrice."', '".$txtDelBunkerAmt."', 'DEL')";
				mysql_query($sql2);
			}
		}
		
		$txtAddREDELID = $_REQUEST['txtAddREDELID'];
		for($i=1;$i<=$txtAddREDELID;$i++)
		{
			if($_REQUEST['selReDELBunker_'.$i]!='')
			{
				$txtReDelBunkerQty	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerQty_'.$i]);
				$selReDELBunker  	      = $this->getCheckNullVal($_REQUEST['selReDELBunker_'.$i]);
				$txtReDelBunkerPrice	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerPrice_'.$i]);
				$txtReDelBunkerAmt	 	  = $this->getCheckNullVal($_REQUEST['txtReDelBunkerAmt_'.$i]);
				$sql2 = "insert into invoice_hiretc_slave2 (INVOICEID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$txtInID."', '".$selReDELBunker."', '".$txtReDelBunkerQty."', '".$txtReDelBunkerPrice."', '".$txtReDelBunkerAmt."', 'REDEL')";
				mysql_query($sql2);
			}
		}
		
		
		$txtORCID  = $_REQUEST['txtORCID'];
		for($i=1;$i<=$txtORCID;$i++)
		{
		    if(isset($_REQUEST['chkORC_'.$i]))
			{
				$txtORCIdentity	 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCIdentity_'.$i])));
				$txtORCVendorid  	  = addslashes(trim($_REQUEST['txtORCVendorid_'.$i]));
				$txtORCDesc     	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCDesc_'.$i])));
				$txtORCAmt      	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtORCAmt_'.$i])));
				
				$sql2 = "insert into invoice_hiretc_slave6 (INVOICEID, VENDORID, IDENTITY, AMOUNT, DESCRIPTION) values ('".$txtInID."', '".$txtORCVendorid."', '".$txtORCIdentity."', '".$txtORCAmt."', '".$txtORCDesc."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$hddnprevinvid  = $_REQUEST['hddnprevinvid'];
		for($i=1;$i<=$hddnprevinvid;$i++)
		{
		    if(isset($_REQUEST['chkPrevInv_'.$i]))
			{
				$txtPrevInvID	 	  = $this->getCheckNullVal(addslashes(trim($_REQUEST['txtPrevInvID_'.$i])));
				$txtPrevInvIdentify	  = addslashes(trim($_REQUEST['txtPrevInvIdentify_'.$i]));
				$sql2 = "insert into invoice_hiretc_slave7 (INVOICEID, PINVOICEID, IDENTIFY) values ('".$txtInID."', '".$txtPrevInvID."', '".$txtPrevInvIdentify."')";
				mysql_query($sql2) or die($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." TC Hire Statement (".$txtInvNo.") Updated Successfully.");
	}
	
	$this->inactiveUserAlerts('TC HIRE STATEMENT', $_SESSION['uid'], $invoiceidd);
	
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	$approverarr2 = $this->getUsersWithAuthority('HIRE_STSTMENT_CHK_APP_2');
	$approverarraccount2 = $this->getUsersWithAuthority('HIRE_STSTMENT_CHK_ACC');
	
	$url = './invoice_hiretc.php?comid='.$_REQUEST['comid'].'&page='.$_REQUEST['page'].'&randomid='.$_REQUEST['randomid'];
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'TC HIRE STATEMENT';
	
	$vesselname = $this->getVesselIMOData($this->getCharteringEstimateTCData($_REQUEST['comid'],"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{
		     if(!empty($approverarraccount2))
			 {
			     $userarray = $approverarraccount2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' Approved '.$invtitleType.' ('.$vesselname.' - '.$txtInvNo.')', $invoiceidd);				  
				  }
			 }
		}
	}
	
	mysql_query("commit");
	//return $msg;
	return $msg.','.$comid;  
}


function insertHirePaymentReceivedDetailsTC()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update invoice_hiretc_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where INVOICEID='".$txtP_ID."' ";
	//echo $sql;die;
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$this->inactiveUserAlerts('TC HIRE STATEMENT', $_SESSION['uid'], $txtP_ID);
	
	return $msg; 
}

function deleteHireInvoiceRecordsTC()
{
	$connect						= $this->funConnect();
	$id 						    = addslashes(trim($_REQUEST['txtDEL_ID']));
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 3;
    $sqlsel = "select * from invoice_hiretc_master where INVOICEID='".$id."'";
	$ressel = mysql_query($sqlsel);
	$rowssel = mysql_fetch_assoc($ressel);
	$this->saveRecentWork($rowssel['INVOICE_TYPE']." TC Hire Statement (".$rowssel['INVOICE_NO'].") deleted Successfully.");
	
	$sql = "delete from invoice_hiretc_master where INVOICEID='".$id."'";
	$sql1 = "delete from invoice_hiretc_slave1 where INVOICEID='".$id."'";
	$sql2 = "delete from invoice_hiretc_slave2 where INVOICEID='".$id."'";
	$sql3 = "delete from invoice_hiretc_slave3 where INVOICEID='".$id."'";
	$sql4 = "delete from invoice_hiretc_slave4 where INVOICEID='".$id."'";
	$sql5 = "delete from invoice_hiretc_slave5 where INVOICEID='".$id."'";
	$sql51 = "delete from invoice_hiretc_slave51 where INVOICEID='".$id."'";
	$sql6 = "delete from invoice_hiretc_slave6 where INVOICEID='".$id."'";
	mysql_query($sql);
	mysql_query($sql1);
	mysql_query($sql2);
	mysql_query($sql3);
	mysql_query($sql4);
	mysql_query($sql5);
	mysql_query($sql51);
	mysql_query($sql6);
	mysql_query("commit"); 
	return $msg;
}






function changeBaseinRecords()
{
	$connect				= $this->funConnect();
 	$tblid 				= addslashes(trim($_REQUEST['txttblid']));
	$value 				= addslashes(trim($_REQUEST['txttblstatus']));
	if($value == 1){$tblstatus = 2;}else{$tblstatus = 1;}
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
			
	$msg = 2;
	$sql = "update basein_master set STATUS='".$tblstatus."' where BASEINID='".$tblid."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Bunker Grade Record Status updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function displayBaseinList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="bunker_grade" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="45%"  >Name</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from basein_master order by STATUS,NAME";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody>';
		
		echo '</tbody>';
	}
	else{
	echo '<tbody>';
		while($rows = mysql_fetch_assoc($res))
			{
				$this->id = $rows['BASEINID'];
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">';
				if($rows['STATUS'] == 1)
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" checked="checked" onclick="return getChangeStatus('.$rows['BASEINID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				else
				{
					echo '<div class="onoffswitch">
					<input type="text" name="onoffswitch_'.$i.'" class="onoffswitch-checkbox" id="myonoffswitch_'.$i.'" unchecked onclick="return getChangeStatus('.$rows['BASEINID'].','.$rows['STATUS'].','.$i.');">
					<label class="onoffswitch-label" for="myonoffswitch_'.$i.'">
						<div class="onoffswitch-inner"></div>
						<div class="onoffswitch-switch"></div>
					</label>
					</div>';
				}
				echo '</td>';
				echo '<td align="center" valign="middle" class="input-text"><a href="updatebasein.php?id='.$rows['BASEINID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function InsertBaseinRecords()
{
	$connect				= $this->funConnect();	
	$txtName = trim(addslashes($_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into basein_master (NAME, MODULEID, MCOMPANYID) values ('".$txtName."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."')";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Basein Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function viewBaseinRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM basein_master where BASEINID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['NAME'];
	}
}

function updateBaseinRecords()
{
	$connect				= $this->funConnect();
	$id = $_REQUEST['id'];
	$txtName = trim(addslashes($_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update basein_master set NAME='".$txtName."' where BASEINID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
	mysql_query($sql);
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Basein Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function getBaseinList()
{
	$this->funConnect();
	$query = mysql_query("select * from basein_master where STATUS=1 order by NAME ");
	echo '<option value = "" >---Select from list---</option>';
	@$selCName = @$_REQUEST['selCName'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['BASEINID'];
		 $value= $rows['NAME'];
		 echo '<option value='.$key;
		 echo '>'.$value.'</option>';
		}
}

function getCargoPlanningList($rdobType,$coaspot,$relet)
{
	$this->funConnect();
	$query = mysql_query("select OPEN_CARGOID, CPID, LAYCAN_SDATE, (select MATERIAL_CODE_DESC from cargo_master where cargo_master.MATERIALID=open_cargo_master.CARGO) as MATERIAL_CODE_DESC, CARGOSTEAMSIZE, BASE_FREIGHT, RDO_WS_TYPE, WS_LUMPSUM_AMOUNT from open_cargo_master where UPDATE_STATUS=2 and STATUS=1 and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and BUSINESSTYPEID='".$rdobType."' and COA_SPOT='".$coaspot."' and CARGO_RELET='".$relet."' order by MESSAGE_NO ");
	echo '<option value = "" >---Select from list---</option>';
	@$selCName = @$_REQUEST['selCName'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['OPEN_CARGOID'];
		 if($rdobType ==1)
		 {
			 if($rows['RDO_WS_TYPE'] ==1)
		 	 {
		     	$value= $rows['CPID'].'/'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).'/'.$rows['MATERIAL_CODE_DESC'].'/'.$rows['CARGOSTEAMSIZE'].' MT/Base Freight(USD):'.$rows['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$value= $rows['CPID'].'/'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).'/'.$rows['MATERIAL_CODE_DESC'].'/'.$rows['CARGOSTEAMSIZE'].' MT/Lumpsum(USD):'.$rows['WS_LUMPSUM_AMOUNT'] ;
			 }
		 }
		 if($rdobType ==2)
		 {
		     if($rows['RDO_WS_TYPE'] ==1)
		 	 {
		     	$value= $rows['CPID'].'/'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).'/'.$rows['MATERIAL_CODE_DESC'].'/'.$rows['CARGOSTEAMSIZE'].' MT/WS:'.$rows['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$value= $rows['CPID'].'/'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).'/'.$rows['MATERIAL_CODE_DESC'].'/'.$rows['CARGOSTEAMSIZE'].' MT/Lumpsum(USD):'.$rows['WS_LUMPSUM_AMOUNT'] ;
			 }
		 }
		 if($rdobType ==3)
		 {
		     $value= $rows['CPID'].'/'.date('d-m-Y',strtotime($rows['LAYCAN_SDATE'])).'/'.$rows['MATERIAL_CODE_DESC'].'/'.$rows['CARGOSTEAMSIZE'].' MT/Freight(USD):'.$rows['BASE_FREIGHT'].' ';
		 }
		 echo '<option value='.$key;
		 echo '>'.$value.'</option>';
		}
}



function insertCOACargoReletDetails()
{
	$connect = $this->funConnect();
	$coaid 	            = $_REQUEST['coaid'];
	$txtStatus          = $_REQUEST['txtStatus'];
	
	$selVName	 		= addslashes(trim($_REQUEST['selVName']));
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo	 		    = addslashes(trim($_REQUEST['txtVNo']));
	$txtVName    		= addslashes(trim($_REQUEST['txtVName']));
	$selCargoPlanning   = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	$txtActualQty    	= addslashes(trim($_REQUEST['txtActualQty']));
	$txtFreightUSD		= addslashes(trim($_REQUEST['txtFreightUSD']));
	$txtBAFUSD  	    = addslashes(trim($_REQUEST['txtBAFUSD']));
	$txtApplicableFrom	= date("Y-m-d",strtotime($_REQUEST['txtApplicableFrom']));
	$txtApplicableTo	= date("Y-m-d",strtotime($_REQUEST['txtApplicableTo']));
	$txtAddComm  		= addslashes(trim($_REQUEST['txtAddComm']));
	$txtBrokerage	    = addslashes(trim($_REQUEST['txtBrokerage']));
	$txtDemRate 		= addslashes(trim($_REQUEST['txtDemRate']));
	$txtDespatchRate	= addslashes(trim($_REQUEST['txtDespatchRate']));
	$txtConFOPrice  	= addslashes(trim($_REQUEST['txtConFOPrice']));
	$txtCurFOPrice      = addslashes(trim($_REQUEST['txtCurFOPrice']));
	$txtPaymentClause	= addslashes(trim($_REQUEST['txtPaymentClause']));
	$txtBunkerClause    = addslashes(trim($_REQUEST['txtBunkerClause']));
	$txtFreightAmt      = addslashes(trim($_REQUEST['txtFreightAmt']));
	$txtBunkerSurcharge	= addslashes(trim($_REQUEST['txtBunkerSurcharge']));
	$txtDemmurageAmt    = addslashes(trim($_REQUEST['txtDemmurageAmt']));
	$txtDespatchAmt	    = addslashes(trim($_REQUEST['txtDespatchAmt']));
	$txtAddCommAmt      = addslashes(trim($_REQUEST['txtAddCommAmt']));
	$txtBrokerageAmt	= addslashes(trim($_REQUEST['txtBrokerageAmt']));
	$txtTotals        	= addslashes(trim($_REQUEST['txtTotals']));
	$txtProfit          = addslashes(trim($_REQUEST['txtProfit']));
	$txtCOARef       	= addslashes(trim($_REQUEST['txtCOARef']));
	$selLoadPortAgent   = addslashes(trim($_REQUEST['selLoadPortAgent']));
	$txtLAgentRemarks   = addslashes(trim($_REQUEST['txtLAgentRemarks']));
	$selDisPortAgent	= addslashes(trim($_REQUEST['selDisPortAgent']));
	$txtDAgentRemarks	= addslashes(trim($_REQUEST['txtDAgentRemarks']));
	$txtNotices         = addslashes(trim($_REQUEST['txtNotices']));
	$txtDA      	    = addslashes(trim($_REQUEST['txtDA']));
	$txtExtraInsurance  = addslashes(trim($_REQUEST['txtExtraInsurance']));
	$txtMinTerms	    = addslashes(trim($_REQUEST['txtMinTerms']));
	$txtSpecialComments = addslashes(trim($_REQUEST['txtSpecialComments']));
	$txtNominationProc  = addslashes(trim($_REQUEST['txtNominationProc']));
	$upload             = $this->getUpload($_FILES['mul_file']);
	$name               = $this->getUploadName($_FILES['mul_file']);
	$upload1 			= implode(',',$upload);
	$name1              = implode(',',$name);	
	
	$txtFreightUSDout       = addslashes(trim($_REQUEST['txtFreightUSDout']));
	$txtBAFUSDout  	        = addslashes(trim($_REQUEST['txtBAFUSDout']));
	$txtApplicableFromout	= date("Y-m-d",strtotime($_REQUEST['txtApplicableFromout']));
	$txtApplicableToout	    = date("Y-m-d",strtotime($_REQUEST['txtApplicableToout']));
	$txtAddCommout  		= addslashes(trim($_REQUEST['txtAddCommout']));
	$txtBrokerageout	    = addslashes(trim($_REQUEST['txtBrokerageout']));
	$txtDemRateout 		    = addslashes(trim($_REQUEST['txtDemRateout']));
	$txtDespatchRateout	    = addslashes(trim($_REQUEST['txtDespatchRateout']));
	$txtConFOPriceout  	    = addslashes(trim($_REQUEST['txtConFOPriceout']));
	$txtCurFOPriceout       = addslashes(trim($_REQUEST['txtCurFOPriceout']));
	$txtPaymentClauseout	= addslashes(trim($_REQUEST['txtPaymentClauseout']));
	$txtBunkerClauseout     = addslashes(trim($_REQUEST['txtBunkerClauseout']));
	$txtFreightAmtout       = addslashes(trim($_REQUEST['txtFreightAmtout']));
	$txtBunkerSurchargeout	= addslashes(trim($_REQUEST['txtBunkerSurchargeout']));
	$txtDemmurageAmtout     = addslashes(trim($_REQUEST['txtDemmurageAmtout']));
	$txtDespatchAmtout	    = addslashes(trim($_REQUEST['txtDespatchAmtout']));
	$txtAddCommAmtout       = addslashes(trim($_REQUEST['txtAddCommAmtout']));
	$txtBrokerageAmtout	    = addslashes(trim($_REQUEST['txtBrokerageAmtout']));
	$txtTotalsout        	= addslashes(trim($_REQUEST['txtTotalsout']));
	$txtCOARefout       	= addslashes(trim($_REQUEST['txtCOARefout']));
	$selLoadPortAgentout    = addslashes(trim($_REQUEST['selLoadPortAgentout']));
	$txtLAgentRemarksout    = addslashes(trim($_REQUEST['txtLAgentRemarksout']));
	$selDisPortAgentout	    = addslashes(trim($_REQUEST['selDisPortAgentout']));
	$txtDAgentRemarksout	= addslashes(trim($_REQUEST['txtDAgentRemarksout']));
	$txtNoticesout          = addslashes(trim($_REQUEST['txtNoticesout']));
	$txtDAout      	        = addslashes(trim($_REQUEST['txtDAout']));
	$txtExtraInsuranceout   = addslashes(trim($_REQUEST['txtExtraInsuranceout']));
	$txtMinTermsout	        = addslashes(trim($_REQUEST['txtMinTermsout']));
	$txtSpecialCommentsout  = addslashes(trim($_REQUEST['txtSpecialCommentsout']));
	$txtNominationProcout   = addslashes(trim($_REQUEST['txtNominationProcout']));
	$upload             	= $this->getUpload($_FILES['mul_fileout']);
	$name               	= $this->getUploadName($_FILES['mul_fileout']);
	$upload2 				= implode(',',$upload);
	$name2              	= implode(',',$name);
	
	
	$txtSDWTMT	            = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	            = addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM 		    = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 		    = addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT               = addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT   	        = addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT	            = addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT    		    = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT 		= addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT         = addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM	        = addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT  	    = addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM 		= addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT 		= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT       = addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT	        = addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT       	= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT     = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");

	$sql = "insert into cargo_relet_estimate_masster (COAID, UPDATE_STATUS, OPEN_CARGOID, MODULEID, MCOMPANYID, ADDONDATE, VESSEL_IMO_ID, TRANS_DATE, CARGO_RELET_NO, CARGO_RELET_NAME, VESSEL_TYPE, CARGO_QMT_MT, FREIGHT_USD, BAF_USD, FREIGHT_FDATE, FREIGHT_TDATE, ADD_COM, BROKERAGE, DEM_RATE, DES_RATE, CONTRACT_FO_PRICE, CURRENT_FO_PRICE, FREIGHT_USD_OUT, BAF_USD_OUT, FREIGHT_FDATE_OUT, FREIGHT_TDATE_OUT, ADD_COM_OUT, BROKERAGE_OUT, DEM_RATE_OUT, DES_RATE_OUT, PAYMENT_CLAUSE, BUNKER_CLAUSE, PAYMENT_CLAUSE_OUT, BUNKER_CLAUSE_OUT, FREIGHT_AMT, BUNKER_SURCHARGE_AMT, DEMMURAGE_AMT, DESPATCH_AMT, ADD_COMM_AMT, BROKERAGE_AMT, TOTAL_AMT, PROFIT, FREIGHT_AMT_OUT, BUNKER_SURCHARGE_AMT_OUT, DEMMURAGE_AMT_OUT, DESPATCH_AMT_OUT, ADD_COMM_AMT_OUT, BROKERAGE_AMT_OUT, TOTAL_AMT_OUT, COA_REF, LOADPORT_AGENT, LOADPORT_REMARKS, DISPORT_AGENT, DISPORT_REMARKS, NOTICES, D_A, EXTRA_INSURANCE, MIN_TERM, ATTACHMENT, ATTACHMENT_NAME, SPCL_COMMENTS, NOM_PROC, COA_REF_OUT, LOADPORT_AGENT_OUT, LOADPORT_REMARKS_OUT, DISPORT_AGENT_OUT, DISPORT_REMARKS_OUT, NOTICES_OUT, D_A_OUT, EXTRA_INSURANCE_OUT, MIN_TERM_OUT, ATTACHMENT_OUT, ATTACHMENT_NAME_OUT, SPCL_COMMENTS_OUT, NOM_PROC_OUT, SUMMER_DWT_MT, SUMMER_DWT_LT, SUMMER_DRAFT_M, SUMMER_DRAFT_FT, TPI_MT_INCH, TPI_LT_INCH, TPC_MT, TPC_LT, CONSTANTS_MT, CONSTANTS_LT, GRAIN_CAP_CBM, GRAIN_CAP_CFT, ALLOWED_DRAFT_M, BUNKER_ROB_MT, CARGO_INTAKE_MT, SF_CBM_MT, SF_CFT_MT, CARGO_LOADABLE_MT, BUSINESSTYPEID, FINAL_STATUS, FIXED) values ('".$this->getCheckNullValue($coaid)."', '".$this->getCheckNullValue($txtStatus)."', '".$this->getCheckNullVal($selCargoPlanning)."', '".$this->getCheckNullValue($_SESSION['moduleid'])."', '".$this->getCheckNullValue($_SESSION['company'])."', NOW(), '".$this->getCheckNullValue($selVName)."', '".$txtDate."', '".$txtVNo."', '".$txtVName."', '".$txtVType."', '".$this->getCheckNullValue($txtActualQty)."', '".$this->getCheckNullValue($txtFreightUSD)."', '".$this->getCheckNullValue($txtBAFUSD)."', '".$txtApplicableFrom."', '".$txtApplicableTo."', '".$this->getCheckNullValue($txtAddComm)."', '".$this->getCheckNullValue($txtBrokerage)."', '".$this->getCheckNullValue($txtDemRate)."', '".$this->getCheckNullValue($txtDespatchRate)."', '".$this->getCheckNullValue($txtConFOPrice)."', '".$this->getCheckNullValue($txtCurFOPrice)."', '".$this->getCheckNullValue($txtFreightUSDout)."', '".$this->getCheckNullValue($$txtBAFUSDout)."', '".$txtApplicableFromout."', '".$txtApplicableToout."', '".$this->getCheckNullValue($txtAddCommout)."', '".$this->getCheckNullValue($txtBrokerageout)."', '".$this->getCheckNullValue($txtDemRateout)."', '".$this->getCheckNullValue($txtDespatchRateout)."', '".$txtPaymentClause."', '".$txtBunkerClause."', '".$txtPaymentClauseout."', '".$txtBunkerClauseout."', '".$this->getCheckNullVal($txtFreightAmt)."', '".$this->getCheckNullVal($txtBunkerSurcharge)."', '".$this->getCheckNullVal($txtDemmurageAmt)."', '".$this->getCheckNullVal($txtDespatchAmt)."', '".$this->getCheckNullValue($txtAddCommAmt)."', '".$this->getCheckNullValue($txtBrokerageAmt)."','".$this->getCheckNullValue($txtTotals)."','".$this->getCheckNullValue($txtProfit)."', '".$this->getCheckNullVal($txtFreightAmtout)."', '".$this->getCheckNullVal($txtBunkerSurchargeout)."', '".$this->getCheckNullVal($txtDemmurageAmtout)."', '".$this->getCheckNullVal($txtDespatchAmtout)."', '".$this->getCheckNullVal($txtAddCommAmtout)."', '".$this->getCheckNullVal($txtBrokerageAmtout)."','".$this->getCheckNullVal($txtTotalsout)."','".$txtCOARef."','".$selLoadPortAgent."','".$txtLAgentRemarks."','".$selDisPortAgent."','".$txtDAgentRemarks."','".$txtNotices."', '".$txtDA."', '".$txtExtraInsurance."','".$txtMinTerms."','".addslashes($upload1)."','".addslashes($name1)."','".$txtSpecialComments."','".$txtNominationProc."','".$txtCOARefout."','".$selLoadPortAgentout."','".$txtLAgentRemarksout."','".$selDisPortAgentout."','".$txtDAgentRemarksout."','".$txtNoticesout."', '".$txtDAout."', '".$txtExtraInsuranceout."','".$txtMinTermsout."','".addslashes($upload2)."','".addslashes($name2)."','".$txtSpecialCommentsout."','".$txtNominationProcout."', '".$this->getCheckNullVal($txtSDWTMT)."', '".$this->getCheckNullVal($txtSDWTLT)."', '".$this->getCheckNullVal($txtSDraftM)."', '".$this->getCheckNullVal($txtSDraftFT)."', '".$this->getCheckNullVal($txtTPIMT)."', '".$this->getCheckNullVal($txtTPILT)."', '".$this->getCheckNullVal($txtTPCMT)."', '".$this->getCheckNullVal($txtTPCLT)."', '".$this->getCheckNullVal($txtConstantsMT)."', '".$this->getCheckNullVal($txtConstantsLT)."', '".$this->getCheckNullVal($txtGrainCapCBM)."', '".$this->getCheckNullVal($txtGrainCapCFT)."', '".$this->getCheckNullVal($txtAllawedDraftM)."', '".$this->getCheckNullVal($txtBunkerRobMT)."', '".$this->getCheckNullVal($txtCargoIntakeMT)."', '".$this->getCheckNullVal($txtSFCBM_MT)."', '".$this->getCheckNullVal($txtSFCBFT_MT)."', '".$this->getCheckNullVal($txtCargoLoadableMT)."', '".$this->getCheckNullVal($rdoEstimateType)."', 0, 0)";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$mysql = "select max(FCAID) as max from cargo_relet_estimate_masster where COAID='".$coaid."'";
	$myres  =  mysql_query($mysql,$connect);
	$myrows = mysql_fetch_assoc($myres);
	$maxid = $myrows['max'];
		
		$txtPartiesID = $_REQUEST['txtPartiesID'];
		for($i=1;$i<=$txtPartiesID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave1 (FCAID, CHARTERER, OWNER, BROKER, IDENTIFY) values ('".$maxid."','".$_REQUEST['selCharterers_'.$i]."','".$_REQUEST['selOwner_'.$i]."','".$_REQUEST['selBroker_'.$i]."','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		$txtPartiesoutID = $_REQUEST['txtPartiesoutID'];
		for($i=1;$i<=$txtPartiesoutID;$i++)
		{
				$sql2 = "insert into cargo_relet_estimate_slave1 (FCAID, CHARTERER, OWNER, BROKER, IDENTIFY) values ('".$maxid."','".$_REQUEST['selCharterersout_'.$i]."','".$_REQUEST['selOwnerout_'.$i]."','".$_REQUEST['selBrokerout_'.$i]."','OUT')";
				mysql_query($sql2)or die($sql2);
				mysql_query("commit");
		}
		
		
		$txtLPortID = $_REQUEST['txtLPortID'];
		for($i=1;$i<=$txtLPortID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$maxid."','".$_REQUEST['selLoadPort_'.$i]."','".$_REQUEST['txtLComments_'.$i]."','LP','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		$txtLPortoutID = $_REQUEST['txtLPortoutID'];
		for($i=1;$i<=$txtLPortoutID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$maxid."','".$_REQUEST['selLoadPortout_'.$i]."','".$_REQUEST['txtLCommentsout_'.$i]."','LP','OUT')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		
		$txtDPortID = $_REQUEST['txtDPortID'];
		for($i=1;$i<=$txtDPortID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$maxid."','".$_REQUEST['selDisPort_'.$i]."','".$_REQUEST['txtDComments_'.$i]."','DP','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		
		$txtDPortoutID = $_REQUEST['txtDPortoutID'];
		for($i=1;$i<=$txtDPortoutID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$maxid."','".$_REQUEST['selDisPortout_'.$i]."','".$_REQUEST['txtDCommentsout_'.$i]."','DP','OUT')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}   
		
		
		if($txtStatus == 2)
	    {
			$year = date('Y',time());
			$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM cargo_relet_estimate_compare where Year(ADD_ON_DATE) = '".$year."' and MCOMPANYID='".$_SESSION['company']."' and COAAID is not NULL";
			$result = mysql_query($query) or die(mysql_error());
			$rec=mysql_num_rows($result);
			
			$year1 = $year[2].''.$year[3];
			
			while($rows = mysql_fetch_array($result))
			{
			$empcode = $rows['MESSAGE_NO'];
			if($rows['MESSAGE_NO'] != NULL)
				{
				if(strlen($empcode)<=3)
					{
						$x = 3- strlen($empcode);
						for($i = 1; $i<=$x;$i++)
							{
								$empcode = "0".$empcode;
							}
					}$empcode =$empcode;
				}
			else
				{
					$empcode= "001";
				}
			}
			
			$msg1 = $year1."-".$empcode;
			
			$sql2 = "insert into cargo_relet_estimate_compare (FCAID, FINAL_ID, MESSAGE_NO, USERID, ADD_ON_DATE, MESSAGE, MODULEID, MCOMPANYID, COAAID) values ('".$maxid."', '".$maxid."', '".$empcode."', '".$_SESSION['uid']."', NOW(), '".$msg1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$coaid."')";
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
			 
			$query1 = "SELECT MAX(COMID) as MAX FROM cargo_relet_estimate_compare where COAAID is not NULL";
			$result1 = mysql_query($query1) or die(mysql_error());
			$rows1 = mysql_fetch_array($result1);
			
			$sql3 = "update cargo_relet_estimate_masster set COMID='".$rows1['MAX']."', FIXED='1', FINAL_DATETIME=NOW(), FINAL_STATUS=1 where FCAID='".$maxid."' ";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit"); 
		}
			
	return $msg; 
}


function viewCargoReletEstimationTempleteRecordsNew($id)
{
	$connect = $this->funConnect();
	$sql = "select * from cargo_relet_estimate_masster where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FCAID='".$id."'";
	$result = mysql_query($sql) or die($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['FCAID'];
		$this->var_2 = $rows['COAID'];
		$this->var_3 = $rows['OPEN_CARGOID'];
		$this->var_4 = $rows['UPDATE_STATUS'];
		$this->var_5 = $rows['VESSEL_IMO_ID'];
		$this->var_6 = $rows['COMID'];
		$this->var_7 = $rows['TRANS_DATE'];
		$this->var_8 = $rows['CARGO_RELET_NO'];
		$this->var_9 = $rows['CARGO_RELET_NAME'];
		$this->var_10 = $rows['CARGO_QMT_MT'];
		$this->var_11 = $rows['FREIGHT_USD'];
		$this->var_12 = $rows['BAF_USD'];
		$this->var_13 = $rows['FREIGHT_FDATE'];
		$this->var_14 = $rows['FREIGHT_TDATE'];
		$this->var_15 = $rows['ADD_COM'];
		$this->var_16 = $rows['BROKERAGE'];
		$this->var_17 = $rows['DEM_RATE'];
		$this->var_18 = $rows['DES_RATE'];
		$this->var_19 = $rows['CONTRACT_FO_PRICE'];
		$this->var_20 = $rows['CURRENT_FO_PRICE'];
		$this->var_21 = $rows['FREIGHT_USD_OUT'];
		$this->var_22 = $rows['BAF_USD_OUT'];
		$this->var_23 = $rows['FREIGHT_FDATE_OUT'];
		$this->var_24 = $rows['FREIGHT_TDATE_OUT'];
		$this->var_25 = $rows['ADD_COM_OUT'];
		$this->var_26 = $rows['BROKERAGE_OUT'];
		$this->var_27 = $rows['DEM_RATE_OUT'];
		$this->var_28 = $rows['DES_RATE_OUT'];
		$this->var_29 = $rows['PAYMENT_CLAUSE'];
		$this->var_30 = $rows['BUNKER_CLAUSE'];
		$this->var_31 = $rows['PAYMENT_CLAUSE_OUT'];
		$this->var_32 = $rows['BUNKER_CLAUSE_OUT'];
		$this->var_33 = $rows['FREIGHT_AMT'];
		$this->var_34 = $rows['BUNKER_SURCHARGE_AMT'];
		$this->var_35 = $rows['DEMMURAGE_AMT'];
		$this->var_36 = $rows['DESPATCH_AMT'];
		$this->var_37 = $rows['ADD_COMM_AMT'];
		$this->var_38 = $rows['BROKERAGE_AMT'];
		$this->var_39 = $rows['TOTAL_AMT'];
		$this->var_40 = $rows['PROFIT'];
		$this->var_41 = $rows['FREIGHT_AMT_OUT'];
		$this->var_42 = $rows['BUNKER_SURCHARGE_AMT_OUT'];
		$this->var_43 = $rows['DEMMURAGE_AMT_OUT'];
		$this->var_44 = $rows['DESPATCH_AMT_OUT'];
		$this->var_45 = $rows['ADD_COMM_AMT_OUT'];
		$this->var_46 = $rows['BROKERAGE_AMT_OUT'];
		$this->var_47 = $rows['TOTAL_AMT_OUT'];
		$this->var_48 = $rows['COA_REF'];
		$this->var_49 = $rows['LOADPORT_AGENT'];
		$this->var_50 = $rows['LOADPORT_REMARKS'];
		$this->var_51 = $rows['DISPORT_AGENT'];
		$this->var_52 = $rows['DISPORT_REMARKS'];
		$this->var_53 = $rows['NOTICES'];
		$this->var_54 = $rows['D_A'];
		$this->var_55 = $rows['EXTRA_INSURANCE'];
		$this->var_56 = $rows['MIN_TERM'];
		$this->var_57 = $rows['ATTACHMENT'];
		$this->var_58 = $rows['ATTACHMENT_NAME'];
		$this->var_59 = $rows['SPCL_COMMENTS'];
		$this->var_60 = $rows['NOM_PROC'];
		$this->var_61 = $rows['COA_REF_OUT'];
		$this->var_62 = $rows['LOADPORT_AGENT_OUT'];
		$this->var_63 = $rows['LOADPORT_REMARKS_OUT'];
		$this->var_64 = $rows['DISPORT_AGENT_OUT'];
		$this->var_65 = $rows['DISPORT_REMARKS_OUT'];
		$this->var_66 = $rows['NOTICES_OUT'];
		$this->var_67 = $rows['D_A_OUT'];
		$this->var_68 = $rows['EXTRA_INSURANCE_OUT'];
		$this->var_69 = $rows['MIN_TERM_OUT'];
		$this->var_70 = $rows['ATTACHMENT_OUT'];
		$this->var_71 = $rows['ATTACHMENT_NAME_OUT'];
		$this->var_72 = $rows['SPCL_COMMENTS_OUT'];
		$this->var_73 = $rows['NOM_PROC_OUT'];
		$this->var_74 = $rows['SUMMER_DWT_MT'];
		$this->var_75 = $rows['SUMMER_DWT_LT'];
		$this->var_76 = $rows['SUMMER_DRAFT_M'];
		$this->var_77 = $rows['SUMMER_DRAFT_FT'];
		$this->var_78 = $rows['TPI_MT_INCH'];
		$this->var_79 = $rows['TPI_LT_INCH'];
		$this->var_80 = $rows['TPC_MT'];
		$this->var_81 = $rows['TPC_LT'];
		$this->var_82 = $rows['CONSTANTS_MT'];
		$this->var_83 = $rows['CONSTANTS_LT'];
		$this->var_84 = $rows['GRAIN_CAP_CBM'];
		$this->var_85 = $rows['GRAIN_CAP_CFT'];
		$this->var_86 = $rows['ALLOWED_DRAFT_M'];
		$this->var_87 = $rows['BUNKER_ROB_MT'];
		$this->var_88 = $rows['CARGO_INTAKE_MT'];
		$this->var_89 = $rows['SF_CBM_MT'];
		$this->var_90 = $rows['SF_CFT_MT'];
		$this->var_91 = $rows['CARGO_LOADABLE_MT'];
		$this->var_92 = $rows['BUSINESSTYPEID'];
		$this->var_93 = $rows['VESSEL_TYPE'];
		$this->var_94 = $rows['FINAL_STATUS'];
		$this->var_95 = $rows['PROFIT_LOSS'];
		$this->var_96 = $rows['FIXED'];
		$this->var_97 = $rows['FINAL_DATETIME'];
		$this->var_98 = $rows['SHEET_NO'];
		$this->var_99  = $rows['FREIGHT_VENDOR'];
		$this->var_100 = $rows['BUNKER_SUR_VENDOR'];
		$this->var_101 = $rows['DEMURRAGE_VENDOR'];
		$this->var_102 = $rows['FREIGHT_VENDOR_OUT'];
		$this->var_103 = $rows['DEMURRAGE_VENDOR_OUT'];
		$this->var_104 = $rows['TO_DATE'];
		
		$sql2 = "select OPEN_CARGOID, CPID, (select MATERIAL_CODE_DESC from cargo_master where cargo_master.MATERIALID = open_cargo_master.CARGO) as CARGONAME, CARGOSTEAMSIZE, LAYCAN_SDATE, BASE_FREIGHT, RDO_WS_TYPE, WS_LUMPSUM_AMOUNT, (case when (RDO_WS_TYPE = 1) THEN 'WS' ELSE 'Lumpsum' END) as WS_RDO_TEXT, (case when (RDO_WS_TYPE = 1) THEN 'Base Freight' ELSE 'Lumpsum' END) as WS_RDO_TEXT1, CARGO_RELET, COA_SPOT from open_cargo_master where OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
		
		$result2 = mysql_query($sql2) or die($sql2);
		$rows2   = mysql_fetch_assoc($result2);
		$freightdata = '';
		if($_SESSION['selBType']==1)
		{
			 if($rows2['RDO_WS_TYPE'] ==1)
		 	 {
		     	$this->var_105 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Base Freight(USD): '.$rows2['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$this->var_105 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT/Lumpsum (USD):'.$rows2['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==2)
		{
			 if($rows2['RDO_WS_TYPE'] ==1)
		 	 {
		     	$this->var_105 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, WS:'.$rows2['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$this->var_105 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Lumpsum (USD):'.$rows2['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==3)
		{
			$this->var_105 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Freight (USD):'.$rows2['BASE_FREIGHT'].' ';
		}
	}
}



function updateCOACargoReletDetails()
{
	$connect = $this->funConnect();
	$id 	            = $_REQUEST['id'];
	$coaid 	            = $_REQUEST['coaid'];
	$txtStatus          = $_REQUEST['txtStatus'];
	
	$selVName	 		= addslashes(trim($_REQUEST['selVName']));
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo	 		    = addslashes(trim($_REQUEST['txtVNo']));
	$txtVName    		= addslashes(trim($_REQUEST['txtVName']));
	$selCargoPlanning   = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	$txtActualQty    	= addslashes(trim($_REQUEST['txtActualQty']));
	$txtFreightUSD		= addslashes(trim($_REQUEST['txtFreightUSD']));
	$txtBAFUSD  	    = addslashes(trim($_REQUEST['txtBAFUSD']));
	$txtApplicableFrom	= date("Y-m-d",strtotime($_REQUEST['txtApplicableFrom']));
	$txtApplicableTo	= date("Y-m-d",strtotime($_REQUEST['txtApplicableTo']));
	$txtAddComm  		= addslashes(trim($_REQUEST['txtAddComm']));
	$txtBrokerage	    = addslashes(trim($_REQUEST['txtBrokerage']));
	$txtDemRate 		= addslashes(trim($_REQUEST['txtDemRate']));
	$txtDespatchRate	= addslashes(trim($_REQUEST['txtDespatchRate']));
	$txtConFOPrice  	= addslashes(trim($_REQUEST['txtConFOPrice']));
	$txtCurFOPrice      = addslashes(trim($_REQUEST['txtCurFOPrice']));
	$txtPaymentClause	= addslashes(trim($_REQUEST['txtPaymentClause']));
	$txtBunkerClause    = addslashes(trim($_REQUEST['txtBunkerClause']));
	$txtFreightAmt      = addslashes(trim($_REQUEST['txtFreightAmt']));
	$txtBunkerSurcharge	= addslashes(trim($_REQUEST['txtBunkerSurcharge']));
	$txtDemmurageAmt    = addslashes(trim($_REQUEST['txtDemmurageAmt']));
	$txtDespatchAmt	    = addslashes(trim($_REQUEST['txtDespatchAmt']));
	$txtAddCommAmt      = addslashes(trim($_REQUEST['txtAddCommAmt']));
	$txtBrokerageAmt	= addslashes(trim($_REQUEST['txtBrokerageAmt']));
	$txtTotals        	= addslashes(trim($_REQUEST['txtTotals']));
	$txtProfit          = addslashes(trim($_REQUEST['txtProfit']));
	$txtCOARef       	= addslashes(trim($_REQUEST['txtCOARef']));
	$selLoadPortAgent   = addslashes(trim($_REQUEST['selLoadPortAgent']));
	$txtLAgentRemarks   = addslashes(trim($_REQUEST['txtLAgentRemarks']));
	$selDisPortAgent	= addslashes(trim($_REQUEST['selDisPortAgent']));
	$txtDAgentRemarks	= addslashes(trim($_REQUEST['txtDAgentRemarks']));
	$txtNotices         = addslashes(trim($_REQUEST['txtNotices']));
	$txtDA      	    = addslashes(trim($_REQUEST['txtDA']));
	$txtExtraInsurance  = addslashes(trim($_REQUEST['txtExtraInsurance']));
	$txtMinTerms	    = addslashes(trim($_REQUEST['txtMinTerms']));
	$txtSpecialComments = addslashes(trim($_REQUEST['txtSpecialComments']));
	$txtNominationProc  = addslashes(trim($_REQUEST['txtNominationProc']));	
	
	$txtFreightUSDout       = addslashes(trim($_REQUEST['txtFreightUSDout']));
	$txtBAFUSDout  	        = addslashes(trim($_REQUEST['txtBAFUSDout']));
	$txtApplicableFromout	= date("Y-m-d",strtotime($_REQUEST['txtApplicableFromout']));
	$txtApplicableToout	    = date("Y-m-d",strtotime($_REQUEST['txtApplicableToout']));
	$txtAddCommout  		= addslashes(trim($_REQUEST['txtAddCommout']));
	$txtBrokerageout	    = addslashes(trim($_REQUEST['txtBrokerageout']));
	$txtDemRateout 		    = addslashes(trim($_REQUEST['txtDemRateout']));
	$txtDespatchRateout	    = addslashes(trim($_REQUEST['txtDespatchRateout']));
	$txtConFOPriceout  	    = addslashes(trim($_REQUEST['txtConFOPriceout']));
	$txtCurFOPriceout       = addslashes(trim($_REQUEST['txtCurFOPriceout']));
	$txtPaymentClauseout	= addslashes(trim($_REQUEST['txtPaymentClauseout']));
	$txtBunkerClauseout     = addslashes(trim($_REQUEST['txtBunkerClauseout']));
	$txtFreightAmtout       = addslashes(trim($_REQUEST['txtFreightAmtout']));
	$txtBunkerSurchargeout	= addslashes(trim($_REQUEST['txtBunkerSurchargeout']));
	$txtDemmurageAmtout     = addslashes(trim($_REQUEST['txtDemmurageAmtout']));
	$txtDespatchAmtout	    = addslashes(trim($_REQUEST['txtDespatchAmtout']));
	$txtAddCommAmtout       = addslashes(trim($_REQUEST['txtAddCommAmtout']));
	$txtBrokerageAmtout	    = addslashes(trim($_REQUEST['txtBrokerageAmtout']));
	$txtTotalsout        	= addslashes(trim($_REQUEST['txtTotalsout']));
	$txtCOARefout       	= addslashes(trim($_REQUEST['txtCOARefout']));
	$selLoadPortAgentout    = addslashes(trim($_REQUEST['selLoadPortAgentout']));
	$txtLAgentRemarksout    = addslashes(trim($_REQUEST['txtLAgentRemarksout']));
	$selDisPortAgentout	    = addslashes(trim($_REQUEST['selDisPortAgentout']));
	$txtDAgentRemarksout	= addslashes(trim($_REQUEST['txtDAgentRemarksout']));
	$txtNoticesout          = addslashes(trim($_REQUEST['txtNoticesout']));
	$txtDAout      	        = addslashes(trim($_REQUEST['txtDAout']));
	$txtExtraInsuranceout   = addslashes(trim($_REQUEST['txtExtraInsuranceout']));
	$txtMinTermsout	        = addslashes(trim($_REQUEST['txtMinTermsout']));
	$txtSpecialCommentsout  = addslashes(trim($_REQUEST['txtSpecialCommentsout']));
	$txtNominationProcout   = addslashes(trim($_REQUEST['txtNominationProcout']));
	$txtSDWTMT	            = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	            = addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM 		    = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 		    = addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT               = addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT   	        = addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT	            = addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT    		    = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT 		= addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT         = addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM	        = addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT  	    = addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM 		= addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT 		= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT       = addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT	        = addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT       	= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT     = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	$upload 				= $this->getUpload($_FILES['mul_file']);
	$name                   = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	
	$txtCRMFILE2			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	$upload                 = $this->getUpload($_FILES['mul_fileout']);
	$name                   = $this->getUploadName($_FILES['mul_fileout']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");

	$sql = "update cargo_relet_estimate_masster set UPDATE_STATUS='".$this->getCheckNullValue($txtStatus)."', OPEN_CARGOID='".$selCargoPlanning."', VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', TRANS_DATE='".$txtDate."', CARGO_RELET_NO='".$txtVNo."', CARGO_RELET_NAME='".$txtVName."', VESSEL_TYPE='".$txtVType."', CARGO_QMT_MT='".$this->getCheckNullValue($txtActualQty)."', FREIGHT_USD='".$this->getCheckNullValue($txtFreightUSD)."', BAF_USD='".$this->getCheckNullValue($txtBAFUSD)."', FREIGHT_FDATE='".$txtApplicableFrom."', FREIGHT_TDATE='".$txtApplicableTo."', ADD_COM='".$this->getCheckNullValue($txtAddComm)."', BROKERAGE='".$this->getCheckNullValue($txtBrokerage)."', DEM_RATE='".$this->getCheckNullValue($txtDemRate)."', DES_RATE='".$this->getCheckNullValue($txtDespatchRate)."', CONTRACT_FO_PRICE='".$this->getCheckNullValue($txtConFOPrice)."', CURRENT_FO_PRICE='".$this->getCheckNullValue($txtCurFOPrice)."', FREIGHT_USD_OUT='".$this->getCheckNullValue($txtFreightUSDout)."', BAF_USD_OUT='".$this->getCheckNullValue($$txtBAFUSDout)."', FREIGHT_FDATE_OUT='".$txtApplicableFromout."', FREIGHT_TDATE_OUT='".$txtApplicableToout."', ADD_COM_OUT='".$this->getCheckNullValue($txtAddCommout)."', BROKERAGE_OUT='".$this->getCheckNullValue($txtBrokerageout)."', DEM_RATE_OUT='".$this->getCheckNullValue($txtDemRateout)."', DES_RATE_OUT='".$this->getCheckNullValue($txtDespatchRateout)."', PAYMENT_CLAUSE='".$txtPaymentClause."', BUNKER_CLAUSE='".$txtBunkerClause."', PAYMENT_CLAUSE_OUT='".$txtPaymentClauseout."', BUNKER_CLAUSE_OUT='".$txtBunkerClauseout."', FREIGHT_AMT='".$this->getCheckNullVal($txtFreightAmt)."', BUNKER_SURCHARGE_AMT='".$this->getCheckNullVal($txtBunkerSurcharge)."', DEMMURAGE_AMT='".$this->getCheckNullVal($txtDemmurageAmt)."', DESPATCH_AMT='".$this->getCheckNullVal($txtDespatchAmt)."', ADD_COMM_AMT='".$this->getCheckNullValue($txtAddCommAmt)."', BROKERAGE_AMT='".$this->getCheckNullValue($txtBrokerageAmt)."', TOTAL_AMT='".$this->getCheckNullValue($txtTotals)."', PROFIT='".$this->getCheckNullValue($txtProfit)."', FREIGHT_AMT_OUT='".$this->getCheckNullVal($txtFreightAmtout)."', BUNKER_SURCHARGE_AMT_OUT='".$this->getCheckNullVal($txtBunkerSurchargeout)."', DEMMURAGE_AMT_OUT='".$this->getCheckNullVal($txtDemmurageAmtout)."', DESPATCH_AMT_OUT='".$this->getCheckNullVal($txtDespatchAmtout)."', ADD_COMM_AMT_OUT='".$this->getCheckNullVal($txtAddCommAmtout)."', BROKERAGE_AMT_OUT='".$this->getCheckNullVal($txtBrokerageAmtout)."', TOTAL_AMT_OUT='".$this->getCheckNullVal($txtTotalsout)."', COA_REF='".$txtCOARef."', LOADPORT_AGENT='".$selLoadPortAgent."', LOADPORT_REMARKS='".$txtLAgentRemarks."', DISPORT_AGENT='".$selDisPortAgent."', DISPORT_REMARKS='".$txtDAgentRemarks."', NOTICES='".$txtNotices."', D_A='".$txtDA."', EXTRA_INSURANCE='".$txtExtraInsurance."', MIN_TERM='".$txtMinTerms."', ATTACHMENT='".addslashes($upload1)."', ATTACHMENT_NAME='".addslashes($name1)."', SPCL_COMMENTS='".$txtSpecialComments."', NOM_PROC='".$txtNominationProc."', COA_REF_OUT='".$txtCOARefout."', LOADPORT_AGENT_OUT='".$selLoadPortAgentout."', LOADPORT_REMARKS_OUT='".$txtLAgentRemarksout."', DISPORT_AGENT_OUT='".$selDisPortAgentout."', DISPORT_REMARKS_OUT='".$txtDAgentRemarksout."', NOTICES_OUT='".$txtNoticesout."', D_A_OUT='".$txtDAout."', EXTRA_INSURANCE_OUT='".$txtExtraInsuranceout."', MIN_TERM_OUT='".$txtMinTermsout."', ATTACHMENT_OUT='".addslashes($upload2)."', ATTACHMENT_NAME_OUT='".addslashes($name2)."', SPCL_COMMENTS_OUT='".$txtSpecialCommentsout."', NOM_PROC_OUT='".$txtNominationProcout."', SUMMER_DWT_MT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMER_DWT_LT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMER_DRAFT_M='".$this->getCheckNullVal($txtSDraftM)."', SUMMER_DRAFT_FT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANTS_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANTS_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFT_M='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', FINAL_STATUS=0, FIXED=0 where FCAID='".$id."'";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$del_query3 = "delete from  cargo_relet_estimate_slave1 where FCAID='".$id."'";
	$del_query4 = "delete from  cargo_relet_estimate_slave2 where FCAID='".$id."'";
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query("commit");
		
		$txtPartiesID = $_REQUEST['txtPartiesID'];
		for($i=1;$i<=$txtPartiesID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave1 (FCAID, CHARTERER, OWNER, BROKER, IDENTIFY) values ('".$id."','".$_REQUEST['selCharterers_'.$i]."','".$_REQUEST['selOwner_'.$i]."','".$_REQUEST['selBroker_'.$i]."','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		$txtPartiesoutID = $_REQUEST['txtPartiesoutID'];
		for($i=1;$i<=$txtPartiesoutID;$i++)
		{
				$sql2 = "insert into cargo_relet_estimate_slave1 (FCAID, CHARTERER, OWNER, BROKER, IDENTIFY) values ('".$id."','".$_REQUEST['selCharterersout_'.$i]."','".$_REQUEST['selOwnerout_'.$i]."','".$_REQUEST['selBrokerout_'.$i]."','OUT')";
				mysql_query($sql2)or die($sql2);
				mysql_query("commit");
		}
		
		
		$txtLPortID = $_REQUEST['txtLPortID'];
		for($i=1;$i<=$txtLPortID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$id."','".$_REQUEST['selLoadPort_'.$i]."','".$_REQUEST['txtLComments_'.$i]."','LP','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		$txtLPortoutID = $_REQUEST['txtLPortoutID'];
		for($i=1;$i<=$txtLPortoutID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$id."','".$_REQUEST['selLoadPortout_'.$i]."','".$_REQUEST['txtLCommentsout_'.$i]."','LP','OUT')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		
		$txtDPortID = $_REQUEST['txtDPortID'];
		for($i=1;$i<=$txtDPortID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$id."','".$_REQUEST['selDisPort_'.$i]."','".$_REQUEST['txtDComments_'.$i]."','DP','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		
		$txtDPortoutID = $_REQUEST['txtDPortoutID'];
		for($i=1;$i<=$txtDPortoutID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$id."','".$_REQUEST['selDisPortout_'.$i]."','".$_REQUEST['txtDCommentsout_'.$i]."','DP','OUT')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}   
		
		
		if($txtStatus == 2)
	    {
			$year = date('Y',time());
			$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM cargo_relet_estimate_compare where Year(ADD_ON_DATE) = '".$year."' and MCOMPANYID='".$_SESSION['company']."' and COAAID is not NULL";
			$result = mysql_query($query) or die(mysql_error());
			$rec=mysql_num_rows($result);
			
			$year1 = $year[2].''.$year[3];
			
			while($rows = mysql_fetch_array($result))
			{
			$empcode = $rows['MESSAGE_NO'];
			if($rows['MESSAGE_NO'] != NULL)
				{
				if(strlen($empcode)<=3)
					{
						$x = 3- strlen($empcode);
						for($i = 1; $i<=$x;$i++)
							{
								$empcode = "0".$empcode;
							}
					}$empcode =$empcode;
				}
			else
				{
					$empcode= "001";
				}
			}
			
			$msg1 = $year1."-".$empcode;
			
			$sql2 = "insert into cargo_relet_estimate_compare (FCAID, FINAL_ID, MESSAGE_NO, USERID, ADD_ON_DATE, MESSAGE, MODULEID, MCOMPANYID, COAAID) values ('".$id."', '".$id."', '".$empcode."', '".$_SESSION['uid']."', NOW(), '".$msg1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$coaid."')";
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
			 
			$query1 = "SELECT MAX(COMID) as MAX FROM cargo_relet_estimate_compare where COAAID is not NULL";
			$result1 = mysql_query($query1) or die(mysql_error());
			$rows1 = mysql_fetch_array($result1);
			
			$sql3 = "update cargo_relet_estimate_masster set COMID='".$rows1['MAX']."', FIXED='1', FINAL_DATETIME=NOW(), FINAL_STATUS=1 where FCAID='".$id."' ";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit"); 
		}
			
	return $msg; 
}


function getCoaData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from coa_master where COAID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function getCargoPlanningData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from open_cargo_master where OPEN_CARGOID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}



function insertReletCostSheetDetailsCoa()
{
	$connect = $this->funConnect();
	$coaid 	            = $_REQUEST['coaid'];
	$txtStatus          = $_REQUEST['txtStatus'];
	
	$selVName	 		= addslashes(trim($_REQUEST['selVName']));
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo	 		    = addslashes(trim($_REQUEST['txtVNo']));
	$txtVName    		= addslashes(trim($_REQUEST['txtVName']));
	$selCargoPlanning   = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	$txtActualQty    	= addslashes(trim($_REQUEST['txtActualQty']));
	$txtFreightUSD		= addslashes(trim($_REQUEST['txtFreightUSD']));
	$txtBAFUSD  	    = addslashes(trim($_REQUEST['txtBAFUSD']));
	$txtApplicableFrom	= date("Y-m-d",strtotime($_REQUEST['txtApplicableFrom']));
	$txtApplicableTo	= date("Y-m-d",strtotime($_REQUEST['txtApplicableTo']));
	$txtAddComm  		= addslashes(trim($_REQUEST['txtAddComm']));
	$txtBrokerage	    = addslashes(trim($_REQUEST['txtBrokerage']));
	$txtDemRate 		= addslashes(trim($_REQUEST['txtDemRate']));
	$txtDespatchRate	= addslashes(trim($_REQUEST['txtDespatchRate']));
	$txtConFOPrice  	= addslashes(trim($_REQUEST['txtConFOPrice']));
	$txtCurFOPrice      = addslashes(trim($_REQUEST['txtCurFOPrice']));
	$txtPaymentClause	= addslashes(trim($_REQUEST['txtPaymentClause']));
	$txtBunkerClause    = addslashes(trim($_REQUEST['txtBunkerClause']));
	$txtFreightAmt      = addslashes(trim($_REQUEST['txtFreightAmt']));
	$txtBunkerSurcharge	= addslashes(trim($_REQUEST['txtBunkerSurcharge']));
	$txtDemmurageAmt    = addslashes(trim($_REQUEST['txtDemmurageAmt']));
	$txtDespatchAmt	    = addslashes(trim($_REQUEST['txtDespatchAmt']));
	$txtAddCommAmt      = addslashes(trim($_REQUEST['txtAddCommAmt']));
	$txtBrokerageAmt	= addslashes(trim($_REQUEST['txtBrokerageAmt']));
	$txtTotals        	= addslashes(trim($_REQUEST['txtTotals']));
	$txtProfit          = addslashes(trim($_REQUEST['txtProfit']));
	$txtCOARef       	= addslashes(trim($_REQUEST['txtCOARef']));
	$selLoadPortAgent   = addslashes(trim($_REQUEST['selLoadPortAgent']));
	$txtLAgentRemarks   = addslashes(trim($_REQUEST['txtLAgentRemarks']));
	$selDisPortAgent	= addslashes(trim($_REQUEST['selDisPortAgent']));
	$txtDAgentRemarks	= addslashes(trim($_REQUEST['txtDAgentRemarks']));
	$txtNotices         = addslashes(trim($_REQUEST['txtNotices']));
	$txtDA      	    = addslashes(trim($_REQUEST['txtDA']));
	$txtExtraInsurance  = addslashes(trim($_REQUEST['txtExtraInsurance']));
	$txtMinTerms	    = addslashes(trim($_REQUEST['txtMinTerms']));
	$txtSpecialComments = addslashes(trim($_REQUEST['txtSpecialComments']));
	$txtNominationProc  = addslashes(trim($_REQUEST['txtNominationProc']));
		
	
	$txtFreightUSDout       = addslashes(trim($_REQUEST['txtFreightUSDout']));
	$txtBAFUSDout  	        = addslashes(trim($_REQUEST['txtBAFUSDout']));
	$txtApplicableFromout	= date("Y-m-d",strtotime($_REQUEST['txtApplicableFromout']));
	$txtApplicableToout	    = date("Y-m-d",strtotime($_REQUEST['txtApplicableToout']));
	$txtAddCommout  		= addslashes(trim($_REQUEST['txtAddCommout']));
	$txtBrokerageout	    = addslashes(trim($_REQUEST['txtBrokerageout']));
	$txtDemRateout 		    = addslashes(trim($_REQUEST['txtDemRateout']));
	$txtDespatchRateout	    = addslashes(trim($_REQUEST['txtDespatchRateout']));
	$txtConFOPriceout  	    = addslashes(trim($_REQUEST['txtConFOPriceout']));
	$txtCurFOPriceout       = addslashes(trim($_REQUEST['txtCurFOPriceout']));
	$txtPaymentClauseout	= addslashes(trim($_REQUEST['txtPaymentClauseout']));
	$txtBunkerClauseout     = addslashes(trim($_REQUEST['txtBunkerClauseout']));
	$txtFreightAmtout       = addslashes(trim($_REQUEST['txtFreightAmtout']));
	$txtBunkerSurchargeout	= addslashes(trim($_REQUEST['txtBunkerSurchargeout']));
	$txtDemmurageAmtout     = addslashes(trim($_REQUEST['txtDemmurageAmtout']));
	$txtDespatchAmtout	    = addslashes(trim($_REQUEST['txtDespatchAmtout']));
	$txtAddCommAmtout       = addslashes(trim($_REQUEST['txtAddCommAmtout']));
	$txtBrokerageAmtout	    = addslashes(trim($_REQUEST['txtBrokerageAmtout']));
	$txtTotalsout        	= addslashes(trim($_REQUEST['txtTotalsout']));
	$txtCOARefout       	= addslashes(trim($_REQUEST['txtCOARefout']));
	$selLoadPortAgentout    = addslashes(trim($_REQUEST['selLoadPortAgentout']));
	$txtLAgentRemarksout    = addslashes(trim($_REQUEST['txtLAgentRemarksout']));
	$selDisPortAgentout	    = addslashes(trim($_REQUEST['selDisPortAgentout']));
	$txtDAgentRemarksout	= addslashes(trim($_REQUEST['txtDAgentRemarksout']));
	$txtNoticesout          = addslashes(trim($_REQUEST['txtNoticesout']));
	$txtDAout      	        = addslashes(trim($_REQUEST['txtDAout']));
	$txtExtraInsuranceout   = addslashes(trim($_REQUEST['txtExtraInsuranceout']));
	$txtMinTermsout	        = addslashes(trim($_REQUEST['txtMinTermsout']));
	$txtSpecialCommentsout  = addslashes(trim($_REQUEST['txtSpecialCommentsout']));
	$txtNominationProcout   = addslashes(trim($_REQUEST['txtNominationProcout']));
	
	$txtSDWTMT	            = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	            = addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM 		    = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 		    = addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT               = addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT   	        = addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT	            = addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT    		    = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT 		= addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT         = addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM	        = addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT  	    = addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM 		= addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT 		= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT       = addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT	        = addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT       	= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT     = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	$selFriegntVendor       = addslashes(trim($_REQUEST['selFriegntVendor']));
	$selBunkerSurVendor     = addslashes(trim($_REQUEST['selBunkerSurVendor']));
	$selDemmurageVendor     = addslashes(trim($_REQUEST['selDemmurageVendor']));
	$selFriegntVendorOut    = addslashes(trim($_REQUEST['selFriegntVendorOut']));
	$selDemmurageVendorOut  = addslashes(trim($_REQUEST['selDemmurageVendorOut']));
	$txtTODate           	= date("Y-m-d",strtotime($_REQUEST['txtTODate']));
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	$upload 				= $this->getUpload($_FILES['mul_file']);
	$name                   = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	
	$txtCRMFILE2			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	$upload                 = $this->getUpload($_FILES['mul_fileout']);
	$name                   = $this->getUploadName($_FILES['mul_fileout']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['comid'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");

	$sql = "insert into cargo_relet_estimate_masster (COAID, UPDATE_STATUS, OPEN_CARGOID, MODULEID, MCOMPANYID, ADDONDATE, VESSEL_IMO_ID, TRANS_DATE, CARGO_RELET_NO, CARGO_RELET_NAME, VESSEL_TYPE, CARGO_QMT_MT, FREIGHT_USD, BAF_USD, FREIGHT_FDATE, FREIGHT_TDATE, ADD_COM, BROKERAGE, DEM_RATE, DES_RATE, CONTRACT_FO_PRICE, CURRENT_FO_PRICE, FREIGHT_USD_OUT, BAF_USD_OUT, FREIGHT_FDATE_OUT, FREIGHT_TDATE_OUT, ADD_COM_OUT, BROKERAGE_OUT, DEM_RATE_OUT, DES_RATE_OUT, PAYMENT_CLAUSE, BUNKER_CLAUSE, PAYMENT_CLAUSE_OUT, BUNKER_CLAUSE_OUT, FREIGHT_AMT, BUNKER_SURCHARGE_AMT, DEMMURAGE_AMT, DESPATCH_AMT, ADD_COMM_AMT, BROKERAGE_AMT, TOTAL_AMT, PROFIT, FREIGHT_AMT_OUT, BUNKER_SURCHARGE_AMT_OUT, DEMMURAGE_AMT_OUT, DESPATCH_AMT_OUT, ADD_COMM_AMT_OUT, BROKERAGE_AMT_OUT, TOTAL_AMT_OUT, COA_REF, LOADPORT_AGENT, LOADPORT_REMARKS, DISPORT_AGENT, DISPORT_REMARKS, NOTICES, D_A, EXTRA_INSURANCE, MIN_TERM, ATTACHMENT, ATTACHMENT_NAME, SPCL_COMMENTS, NOM_PROC, COA_REF_OUT, LOADPORT_AGENT_OUT, LOADPORT_REMARKS_OUT, DISPORT_AGENT_OUT, DISPORT_REMARKS_OUT, NOTICES_OUT, D_A_OUT, EXTRA_INSURANCE_OUT, MIN_TERM_OUT, ATTACHMENT_OUT, ATTACHMENT_NAME_OUT, SPCL_COMMENTS_OUT, NOM_PROC_OUT, SUMMER_DWT_MT, SUMMER_DWT_LT, SUMMER_DRAFT_M, SUMMER_DRAFT_FT, TPI_MT_INCH, TPI_LT_INCH, TPC_MT, TPC_LT, CONSTANTS_MT, CONSTANTS_LT, GRAIN_CAP_CBM, GRAIN_CAP_CFT, ALLOWED_DRAFT_M, BUNKER_ROB_MT, CARGO_INTAKE_MT, SF_CBM_MT, SF_CFT_MT, CARGO_LOADABLE_MT, BUSINESSTYPEID, FINAL_STATUS, FIXED, SHEET_NO, COMID, FREIGHT_VENDOR, BUNKER_SUR_VENDOR, DEMURRAGE_VENDOR, FREIGHT_VENDOR_OUT, DEMURRAGE_VENDOR_OUT, TO_DATE) values ('".$this->getCheckNullValue($coaid)."', '".$this->getCheckNullValue($txtStatus)."', '".$selCargoPlanning."', '".$this->getCheckNullValue($_SESSION['moduleid'])."', '".$this->getCheckNullValue($_SESSION['company'])."', NOW(), '".$this->getCheckNullValue($selVName)."', '".$txtDate."', '".$txtVNo."', '".$txtVName."', '".$txtVType."', '".$this->getCheckNullValue($txtActualQty)."', '".$this->getCheckNullValue($txtFreightUSD)."', '".$this->getCheckNullValue($txtBAFUSD)."', '".$txtApplicableFrom."', '".$txtApplicableTo."', '".$this->getCheckNullValue($txtAddComm)."', '".$this->getCheckNullValue($txtBrokerage)."', '".$this->getCheckNullValue($txtDemRate)."', '".$this->getCheckNullValue($txtDespatchRate)."', '".$this->getCheckNullValue($txtConFOPrice)."', '".$this->getCheckNullValue($txtCurFOPrice)."', '".$this->getCheckNullValue($txtFreightUSDout)."', '".$this->getCheckNullValue($$txtBAFUSDout)."', '".$txtApplicableFromout."', '".$txtApplicableToout."', '".$this->getCheckNullValue($txtAddCommout)."', '".$this->getCheckNullValue($txtBrokerageout)."', '".$this->getCheckNullValue($txtDemRateout)."', '".$this->getCheckNullValue($txtDespatchRateout)."', '".$txtPaymentClause."', '".$txtBunkerClause."', '".$txtPaymentClauseout."', '".$txtBunkerClauseout."', '".$this->getCheckNullVal($txtFreightAmt)."', '".$this->getCheckNullVal($txtBunkerSurcharge)."', '".$this->getCheckNullVal($txtDemmurageAmt)."', '".$this->getCheckNullVal($txtDespatchAmt)."', '".$this->getCheckNullValue($txtAddCommAmt)."', '".$this->getCheckNullValue($txtBrokerageAmt)."','".$this->getCheckNullValue($txtTotals)."','".$this->getCheckNullValue($txtProfit)."', '".$this->getCheckNullVal($txtFreightAmtout)."', '".$this->getCheckNullVal($txtBunkerSurchargeout)."', '".$this->getCheckNullVal($txtDemmurageAmtout)."', '".$this->getCheckNullVal($txtDespatchAmtout)."', '".$this->getCheckNullVal($txtAddCommAmtout)."', '".$this->getCheckNullVal($txtBrokerageAmtout)."','".$this->getCheckNullVal($txtTotalsout)."','".$txtCOARef."','".$selLoadPortAgent."','".$txtLAgentRemarks."','".$selDisPortAgent."','".$txtDAgentRemarks."','".$txtNotices."', '".$txtDA."', '".$txtExtraInsurance."','".$txtMinTerms."','".addslashes($upload1)."','".addslashes($name1)."','".$txtSpecialComments."','".$txtNominationProc."','".$txtCOARefout."','".$selLoadPortAgentout."','".$txtLAgentRemarksout."','".$selDisPortAgentout."','".$txtDAgentRemarksout."','".$txtNoticesout."', '".$txtDAout."', '".$txtExtraInsuranceout."','".$txtMinTermsout."','".addslashes($upload2)."','".addslashes($name2)."','".$txtSpecialCommentsout."','".$txtNominationProcout."', '".$this->getCheckNullVal($txtSDWTMT)."', '".$this->getCheckNullVal($txtSDWTLT)."', '".$this->getCheckNullVal($txtSDraftM)."', '".$this->getCheckNullVal($txtSDraftFT)."', '".$this->getCheckNullVal($txtTPIMT)."', '".$this->getCheckNullVal($txtTPILT)."', '".$this->getCheckNullVal($txtTPCMT)."', '".$this->getCheckNullVal($txtTPCLT)."', '".$this->getCheckNullVal($txtConstantsMT)."', '".$this->getCheckNullVal($txtConstantsLT)."', '".$this->getCheckNullVal($txtGrainCapCBM)."', '".$this->getCheckNullVal($txtGrainCapCFT)."', '".$this->getCheckNullVal($txtAllawedDraftM)."', '".$this->getCheckNullVal($txtBunkerRobMT)."', '".$this->getCheckNullVal($txtCargoIntakeMT)."', '".$this->getCheckNullVal($txtSFCBM_MT)."', '".$this->getCheckNullVal($txtSFCBFT_MT)."', '".$this->getCheckNullVal($txtCargoLoadableMT)."', '".$this->getCheckNullVal($rdoEstimateType)."', 0, 0, '".$this->getCheckNullVal($sheet_no)."', '".$this->getCheckNullVal($comid)."', '".$this->getCheckNullVal($selFriegntVendor)."', '".$this->getCheckNullVal($selBunkerSurVendor)."', '".$this->getCheckNullVal($selDemmurageVendor)."', '".$this->getCheckNullVal($selFriegntVendorOut)."', '".$this->getCheckNullVal($selDemmurageVendorOut)."', '".$txtTODate."')";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$mysql = "select max(FCAID) as max from cargo_relet_estimate_masster where COAID='".$coaid."'";
	$myres  =  mysql_query($mysql,$connect);
	$myrows = mysql_fetch_assoc($myres);
	$maxid = $myrows['max'];
		
		$txtPartiesID = $_REQUEST['txtPartiesID'];
		for($i=1;$i<=$txtPartiesID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave1 (FCAID, CHARTERER, OWNER, BROKER, IDENTIFY) values ('".$maxid."','".$_REQUEST['selCharterers_'.$i]."','".$_REQUEST['selOwner_'.$i]."','".$_REQUEST['selBroker_'.$i]."','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		$txtPartiesoutID = $_REQUEST['txtPartiesoutID'];
		for($i=1;$i<=$txtPartiesoutID;$i++)
		{
				$sql2 = "insert into cargo_relet_estimate_slave1 (FCAID, CHARTERER, OWNER, BROKER, IDENTIFY) values ('".$maxid."','".$_REQUEST['selCharterersout_'.$i]."','".$_REQUEST['selOwnerout_'.$i]."','".$_REQUEST['selBrokerout_'.$i]."','OUT')";
				mysql_query($sql2)or die($sql2);
				mysql_query("commit");
		}
		
		
		$txtLPortID = $_REQUEST['txtLPortID'];
		for($i=1;$i<=$txtLPortID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$maxid."','".$_REQUEST['selLoadPort_'.$i]."','".$_REQUEST['txtLComments_'.$i]."','LP','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		$txtLPortoutID = $_REQUEST['txtLPortoutID'];
		for($i=1;$i<=$txtLPortoutID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$maxid."','".$_REQUEST['selLoadPortout_'.$i]."','".$_REQUEST['txtLCommentsout_'.$i]."','LP','OUT')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		
		$txtDPortID = $_REQUEST['txtDPortID'];
		for($i=1;$i<=$txtDPortID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$maxid."','".$_REQUEST['selDisPort_'.$i]."','".$_REQUEST['txtDComments_'.$i]."','DP','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		
		$txtDPortoutID = $_REQUEST['txtDPortoutID'];
		for($i=1;$i<=$txtDPortoutID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$maxid."','".$_REQUEST['selDisPortout_'.$i]."','".$_REQUEST['txtDCommentsout_'.$i]."','DP','OUT')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}   
			
	return $msg; 
}



function updateCOACargoReletSheetDetails()
{
	$connect = $this->funConnect();
	$id 	            = $_REQUEST['id'];
	$coaid 	            = $_REQUEST['coaid'];
	$txtStatus          = $_REQUEST['txtStatus'];
	
	$selVName	 		= addslashes(trim($_REQUEST['selVName']));
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo	 		    = addslashes(trim($_REQUEST['txtVNo']));
	$txtVName    		= addslashes(trim($_REQUEST['txtVName']));
	$selCargoPlanning   = addslashes(trim($_REQUEST['selCargoPlanning']));
	
	$txtActualQty    	= addslashes(trim($_REQUEST['txtActualQty']));
	$txtFreightUSD		= addslashes(trim($_REQUEST['txtFreightUSD']));
	$txtBAFUSD  	    = addslashes(trim($_REQUEST['txtBAFUSD']));
	$txtApplicableFrom	= date("Y-m-d",strtotime($_REQUEST['txtApplicableFrom']));
	$txtApplicableTo	= date("Y-m-d",strtotime($_REQUEST['txtApplicableTo']));
	$txtAddComm  		= addslashes(trim($_REQUEST['txtAddComm']));
	$txtBrokerage	    = addslashes(trim($_REQUEST['txtBrokerage']));
	$txtDemRate 		= addslashes(trim($_REQUEST['txtDemRate']));
	$txtDespatchRate	= addslashes(trim($_REQUEST['txtDespatchRate']));
	$txtConFOPrice  	= addslashes(trim($_REQUEST['txtConFOPrice']));
	$txtCurFOPrice      = addslashes(trim($_REQUEST['txtCurFOPrice']));
	$txtPaymentClause	= addslashes(trim($_REQUEST['txtPaymentClause']));
	$txtBunkerClause    = addslashes(trim($_REQUEST['txtBunkerClause']));
	$txtFreightAmt      = addslashes(trim($_REQUEST['txtFreightAmt']));
	$txtBunkerSurcharge	= addslashes(trim($_REQUEST['txtBunkerSurcharge']));
	$txtDemmurageAmt    = addslashes(trim($_REQUEST['txtDemmurageAmt']));
	$txtDespatchAmt	    = addslashes(trim($_REQUEST['txtDespatchAmt']));
	$txtAddCommAmt      = addslashes(trim($_REQUEST['txtAddCommAmt']));
	$txtBrokerageAmt	= addslashes(trim($_REQUEST['txtBrokerageAmt']));
	$txtTotals        	= addslashes(trim($_REQUEST['txtTotals']));
	$txtProfit          = addslashes(trim($_REQUEST['txtProfit']));
	$txtCOARef       	= addslashes(trim($_REQUEST['txtCOARef']));
	$selLoadPortAgent   = addslashes(trim($_REQUEST['selLoadPortAgent']));
	$txtLAgentRemarks   = addslashes(trim($_REQUEST['txtLAgentRemarks']));
	$selDisPortAgent	= addslashes(trim($_REQUEST['selDisPortAgent']));
	$txtDAgentRemarks	= addslashes(trim($_REQUEST['txtDAgentRemarks']));
	$txtNotices         = addslashes(trim($_REQUEST['txtNotices']));
	$txtDA      	    = addslashes(trim($_REQUEST['txtDA']));
	$txtExtraInsurance  = addslashes(trim($_REQUEST['txtExtraInsurance']));
	$txtMinTerms	    = addslashes(trim($_REQUEST['txtMinTerms']));
	$txtSpecialComments = addslashes(trim($_REQUEST['txtSpecialComments']));
	$txtNominationProc  = addslashes(trim($_REQUEST['txtNominationProc']));	
	
	$txtFreightUSDout       = addslashes(trim($_REQUEST['txtFreightUSDout']));
	$txtBAFUSDout  	        = addslashes(trim($_REQUEST['txtBAFUSDout']));
	$txtApplicableFromout	= date("Y-m-d",strtotime($_REQUEST['txtApplicableFromout']));
	$txtApplicableToout	    = date("Y-m-d",strtotime($_REQUEST['txtApplicableToout']));
	$txtAddCommout  		= addslashes(trim($_REQUEST['txtAddCommout']));
	$txtBrokerageout	    = addslashes(trim($_REQUEST['txtBrokerageout']));
	$txtDemRateout 		    = addslashes(trim($_REQUEST['txtDemRateout']));
	$txtDespatchRateout	    = addslashes(trim($_REQUEST['txtDespatchRateout']));
	$txtConFOPriceout  	    = addslashes(trim($_REQUEST['txtConFOPriceout']));
	$txtCurFOPriceout       = addslashes(trim($_REQUEST['txtCurFOPriceout']));
	$txtPaymentClauseout	= addslashes(trim($_REQUEST['txtPaymentClauseout']));
	$txtBunkerClauseout     = addslashes(trim($_REQUEST['txtBunkerClauseout']));
	$txtFreightAmtout       = addslashes(trim($_REQUEST['txtFreightAmtout']));
	$txtBunkerSurchargeout	= addslashes(trim($_REQUEST['txtBunkerSurchargeout']));
	$txtDemmurageAmtout     = addslashes(trim($_REQUEST['txtDemmurageAmtout']));
	$txtDespatchAmtout	    = addslashes(trim($_REQUEST['txtDespatchAmtout']));
	$txtAddCommAmtout       = addslashes(trim($_REQUEST['txtAddCommAmtout']));
	$txtBrokerageAmtout	    = addslashes(trim($_REQUEST['txtBrokerageAmtout']));
	$txtTotalsout        	= addslashes(trim($_REQUEST['txtTotalsout']));
	$txtCOARefout       	= addslashes(trim($_REQUEST['txtCOARefout']));
	$selLoadPortAgentout    = addslashes(trim($_REQUEST['selLoadPortAgentout']));
	$txtLAgentRemarksout    = addslashes(trim($_REQUEST['txtLAgentRemarksout']));
	$selDisPortAgentout	    = addslashes(trim($_REQUEST['selDisPortAgentout']));
	$txtDAgentRemarksout	= addslashes(trim($_REQUEST['txtDAgentRemarksout']));
	$txtNoticesout          = addslashes(trim($_REQUEST['txtNoticesout']));
	$txtDAout      	        = addslashes(trim($_REQUEST['txtDAout']));
	$txtExtraInsuranceout   = addslashes(trim($_REQUEST['txtExtraInsuranceout']));
	$txtMinTermsout	        = addslashes(trim($_REQUEST['txtMinTermsout']));
	$txtSpecialCommentsout  = addslashes(trim($_REQUEST['txtSpecialCommentsout']));
	$txtNominationProcout   = addslashes(trim($_REQUEST['txtNominationProcout']));
	$txtSDWTMT	            = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	            = addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM 		    = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 		    = addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT               = addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT   	        = addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT	            = addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT    		    = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT 		= addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT         = addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM	        = addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT  	    = addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM 		= addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT 		= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT       = addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT	        = addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT       	= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT     = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	$selFriegntVendor       = addslashes(trim($_REQUEST['selFriegntVendor']));
	$selBunkerSurVendor     = addslashes(trim($_REQUEST['selBunkerSurVendor']));
	$selDemmurageVendor     = addslashes(trim($_REQUEST['selDemmurageVendor']));
	$selFriegntVendorOut    = addslashes(trim($_REQUEST['selFriegntVendorOut']));
	$selDemmurageVendorOut  = addslashes(trim($_REQUEST['selDemmurageVendorOut']));
	$txtTODate           	= date("Y-m-d",strtotime($_REQUEST['txtTODate']));
	$rdoEstimateType      	= $_SESSION['selBType'];
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	$upload 				= $this->getUpload($_FILES['mul_file']);
	$name                   = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	
	$txtCRMFILE2			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	$upload                 = $this->getUpload($_FILES['mul_fileout']);
	$name                   = $this->getUploadName($_FILES['mul_fileout']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	if($txtStatus ==2){$update_status = 1;}else{$update_status = 0;}
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['comid'];
	$id = $this->getLatestCostSheetIDRelet($comid,$sheet_no);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");

	$sql = "update cargo_relet_estimate_masster set UPDATE_STATUS='".$this->getCheckNullValue($txtStatus)."', OPEN_CARGOID='".$selCargoPlanning."', VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', TRANS_DATE='".$txtDate."', CARGO_RELET_NO='".$txtVNo."', CARGO_RELET_NAME='".$txtVName."', VESSEL_TYPE='".$txtVType."', CARGO_QMT_MT='".$this->getCheckNullValue($txtActualQty)."', FREIGHT_USD='".$this->getCheckNullValue($txtFreightUSD)."', BAF_USD='".$this->getCheckNullValue($txtBAFUSD)."', FREIGHT_FDATE='".$txtApplicableFrom."', FREIGHT_TDATE='".$txtApplicableTo."', ADD_COM='".$this->getCheckNullValue($txtAddComm)."', BROKERAGE='".$this->getCheckNullValue($txtBrokerage)."', DEM_RATE='".$this->getCheckNullValue($txtDemRate)."', DES_RATE='".$this->getCheckNullValue($txtDespatchRate)."', CONTRACT_FO_PRICE='".$this->getCheckNullValue($txtConFOPrice)."', CURRENT_FO_PRICE='".$this->getCheckNullValue($txtCurFOPrice)."', FREIGHT_USD_OUT='".$this->getCheckNullValue($txtFreightUSDout)."', BAF_USD_OUT='".$this->getCheckNullValue($$txtBAFUSDout)."', FREIGHT_FDATE_OUT='".$txtApplicableFromout."', FREIGHT_TDATE_OUT='".$txtApplicableToout."', ADD_COM_OUT='".$this->getCheckNullValue($txtAddCommout)."', BROKERAGE_OUT='".$this->getCheckNullValue($txtBrokerageout)."', DEM_RATE_OUT='".$this->getCheckNullValue($txtDemRateout)."', DES_RATE_OUT='".$this->getCheckNullValue($txtDespatchRateout)."', PAYMENT_CLAUSE='".$txtPaymentClause."', BUNKER_CLAUSE='".$txtBunkerClause."', PAYMENT_CLAUSE_OUT='".$txtPaymentClauseout."', BUNKER_CLAUSE_OUT='".$txtBunkerClauseout."', FREIGHT_AMT='".$this->getCheckNullVal($txtFreightAmt)."', BUNKER_SURCHARGE_AMT='".$this->getCheckNullVal($txtBunkerSurcharge)."', DEMMURAGE_AMT='".$this->getCheckNullVal($txtDemmurageAmt)."', DESPATCH_AMT='".$this->getCheckNullVal($txtDespatchAmt)."', ADD_COMM_AMT='".$this->getCheckNullValue($txtAddCommAmt)."', BROKERAGE_AMT='".$this->getCheckNullValue($txtBrokerageAmt)."', TOTAL_AMT='".$this->getCheckNullValue($txtTotals)."', PROFIT='".$this->getCheckNullValue($txtProfit)."', FREIGHT_AMT_OUT='".$this->getCheckNullVal($txtFreightAmtout)."', BUNKER_SURCHARGE_AMT_OUT='".$this->getCheckNullVal($txtBunkerSurchargeout)."', DEMMURAGE_AMT_OUT='".$this->getCheckNullVal($txtDemmurageAmtout)."', DESPATCH_AMT_OUT='".$this->getCheckNullVal($txtDespatchAmtout)."', ADD_COMM_AMT_OUT='".$this->getCheckNullVal($txtAddCommAmtout)."', BROKERAGE_AMT_OUT='".$this->getCheckNullVal($txtBrokerageAmtout)."', TOTAL_AMT_OUT='".$this->getCheckNullVal($txtTotalsout)."', COA_REF='".$txtCOARef."', LOADPORT_AGENT='".$selLoadPortAgent."', LOADPORT_REMARKS='".$txtLAgentRemarks."', DISPORT_AGENT='".$selDisPortAgent."', DISPORT_REMARKS='".$txtDAgentRemarks."', NOTICES='".$txtNotices."', D_A='".$txtDA."', EXTRA_INSURANCE='".$txtExtraInsurance."', MIN_TERM='".$txtMinTerms."', ATTACHMENT='".addslashes($upload1)."', ATTACHMENT_NAME='".addslashes($name1)."', SPCL_COMMENTS='".$txtSpecialComments."', NOM_PROC='".$txtNominationProc."', COA_REF_OUT='".$txtCOARefout."', LOADPORT_AGENT_OUT='".$selLoadPortAgentout."', LOADPORT_REMARKS_OUT='".$txtLAgentRemarksout."', DISPORT_AGENT_OUT='".$selDisPortAgentout."', DISPORT_REMARKS_OUT='".$txtDAgentRemarksout."', NOTICES_OUT='".$txtNoticesout."', D_A_OUT='".$txtDAout."', EXTRA_INSURANCE_OUT='".$txtExtraInsuranceout."', MIN_TERM_OUT='".$txtMinTermsout."', ATTACHMENT_OUT='".addslashes($upload2)."', ATTACHMENT_NAME_OUT='".addslashes($name2)."', SPCL_COMMENTS_OUT='".$txtSpecialCommentsout."', NOM_PROC_OUT='".$txtNominationProcout."', SUMMER_DWT_MT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMER_DWT_LT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMER_DRAFT_M='".$this->getCheckNullVal($txtSDraftM)."', SUMMER_DRAFT_FT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANTS_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANTS_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFT_M='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', FINAL_STATUS='".$update_status."', FIXED=0, FREIGHT_VENDOR='".$this->getCheckNullVal($selFriegntVendor)."', BUNKER_SUR_VENDOR='".$this->getCheckNullVal($selBunkerSurVendor)."', DEMURRAGE_VENDOR='".$this->getCheckNullVal($selDemmurageVendor)."', FREIGHT_VENDOR_OUT='".$this->getCheckNullVal($selFriegntVendorOut)."', DEMURRAGE_VENDOR_OUT='".$this->getCheckNullVal($selDemmurageVendorOut)."', TO_DATE='".$txtTODate."' where SHEET_NO='".$this->getCheckNullVal($sheet_no)."' and COMID='".$this->getCheckNullVal($comid)."'";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$del_query3 = "delete from  cargo_relet_estimate_slave1 where FCAID='".$id."'";
	$del_query4 = "delete from  cargo_relet_estimate_slave2 where FCAID='".$id."'";
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query("commit");
		
		$txtPartiesID = $_REQUEST['txtPartiesID'];
		for($i=1;$i<=$txtPartiesID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave1 (FCAID, CHARTERER, OWNER, BROKER, IDENTIFY) values ('".$id."','".$_REQUEST['selCharterers_'.$i]."','".$_REQUEST['selOwner_'.$i]."','".$_REQUEST['selBroker_'.$i]."','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		$txtPartiesoutID = $_REQUEST['txtPartiesoutID'];
		for($i=1;$i<=$txtPartiesoutID;$i++)
		{
				$sql2 = "insert into cargo_relet_estimate_slave1 (FCAID, CHARTERER, OWNER, BROKER, IDENTIFY) values ('".$id."','".$_REQUEST['selCharterersout_'.$i]."','".$_REQUEST['selOwnerout_'.$i]."','".$_REQUEST['selBrokerout_'.$i]."','OUT')";
				mysql_query($sql2)or die($sql2);
				mysql_query("commit");
		}
		
		
		$txtLPortID = $_REQUEST['txtLPortID'];
		for($i=1;$i<=$txtLPortID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$id."','".$_REQUEST['selLoadPort_'.$i]."','".$_REQUEST['txtLComments_'.$i]."','LP','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		$txtLPortoutID = $_REQUEST['txtLPortoutID'];
		for($i=1;$i<=$txtLPortoutID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$id."','".$_REQUEST['selLoadPortout_'.$i]."','".$_REQUEST['txtLCommentsout_'.$i]."','LP','OUT')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		
		$txtDPortID = $_REQUEST['txtDPortID'];
		for($i=1;$i<=$txtDPortID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$id."','".$_REQUEST['selDisPort_'.$i]."','".$_REQUEST['txtDComments_'.$i]."','DP','IN')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}
		
		
		$txtDPortoutID = $_REQUEST['txtDPortoutID'];
		for($i=1;$i<=$txtDPortoutID;$i++)
		{
				$sql1 = "insert into cargo_relet_estimate_slave2 (FCAID, PORTID, COMMENTS, PORT_TYPE, IDENTIFY) values ('".$id."','".$_REQUEST['selDisPortout_'.$i]."','".$_REQUEST['txtDCommentsout_'.$i]."','DP','OUT')";
				mysql_query($sql1)or die($sql1);
				mysql_query("commit");
		}   
			
	return $msg; 
}



function insertFreightInvoiceDetailsRelet()
{
	$connect 			= $this->funConnect();	
	$comid 				= addslashes(trim($_REQUEST['comid']));
	$name 				= addslashes(trim($_REQUEST['name']));
	
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtDNote	 		= addslashes(trim($_REQUEST['txtDNote']));
	$txtInvoiceid       = addslashes(trim($_REQUEST['txtInvoiceid']));
	
	$txtDNote_1	 		= explode("/",$_REQUEST['txtDNote']);
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtFCAID	 		= addslashes(trim($_REQUEST['txtFCAID']));

	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtDueDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	
	$txtGrossFreight	= addslashes(trim($_REQUEST['txtGrossFreight']));
	$txtBrokerage	 	= addslashes(trim($_REQUEST['txtBrokerage']));
	$txtBrokerageAmt    = addslashes(trim($_REQUEST['txtBrokerageAmt']));
	$txtNetFreight	 	= addslashes(trim($_REQUEST['txtNetFreight']));
	$txtTO	 	        = addslashes(trim($_REQUEST['txtTO']));
	$txtNet	 		    = addslashes(trim($_REQUEST['txtNet']));
	$txtFinalNetFreight	= addslashes(trim($_REQUEST['txtFinalNetFreight']));
	$txtNet_Name	 	= addslashes(trim($_REQUEST['txtNet_Name']));
	
	$selNOB	 		    = addslashes(trim($_REQUEST['selNOB']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	$txtQty             = $_REQUEST['txtQty'];
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtFreightAmtLocal = addslashes(trim($_REQUEST['txtFreightAmtLocal']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	
	$txtAddComm         = addslashes(trim($_REQUEST['txtAddComm']));
	$txtAddCommAmt	 	= addslashes(trim($_REQUEST['txtAddCommAmt']));
	$txtNetAmtPayable	= addslashes(trim($_REQUEST['txtNetAmtPayable']));
	$txtDNote1			= addslashes(trim($_REQUEST['txtDNote1']));
	
	$ChkBunkerSur   	= addslashes(trim($_REQUEST['ChkBunkerSur']));
	$txtBunkerSurcharge	= addslashes(trim($_REQUEST['txtBunkerSurcharge']));
	$ChkDemmurage   	= addslashes(trim($_REQUEST['ChkDemmurage']));
	$txtDemmurage    	= addslashes(trim($_REQUEST['txtDemmurage']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$qsql = "select * from freight_invoicerelet_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR='".$txtVendor."' and MESSAGE = '".$txtDNote1."' and P_TYPE='".$name."'";
	
	$qres = mysql_query($qsql) or die($qsql);
	$qrec = mysql_num_rows($qres);
	if($qrec == 0)
	{
		$sql = "insert into freight_invoicerelet_master (COMID, MODULEID, MCOMPANYID, DATE, I_TYPE, NOB, STATUS, MESSAGE, VENDOR, GROSS_FREIGHT, BROKERAGE, CPDATE, FCAID, FINAL_FREIGHT, TO_1, NET_AMOUNT, REMARKS, PAYMENT_TERMS, QUANTITY, BROKERAGE_PERCENT, EXCHANGE_CURRENCY, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, ADDCOM, ADDCOM_AMOUNT, NET_PAYABLE, P_TYPE, ATTEN, DUE_DATE, EXCHANGE_DATE,  SHIP_OWNER, CHK_BUNK_SUR, BUNKERSURCHARGE_AMT, DEMMURAGE_AMT, CHK_DEM) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$txtDate."', '".$selIType."', '".$selNOB."', '".$txtStatus."', '".$txtDNote."', '".$txtVendor."', '".$this->getCheckNullVal($txtGrossFreight)."', '".$this->getCheckNullVal($txtBrokerageAmt)."', '".$txtCP_Date."', '".$txtFCAID."', '".$this->getCheckNullVal($txtNetFreight)."', '".$this->getCheckNullVal($txtTO)."', '".$this->getCheckNullVal($txtNet)."', '".$txtDesc."', '".$txtPaymentTerms."', '".$txtQty."', '".$txtBrokerage."', '".$selExchangeCurrency."', '".$txtFreightAmtLocal."', '".$txtExchangeRate."', '".$txtAddComm."', '".$txtAddCommAmt."', '".$txtNetAmtPayable."', '".$name."', '".$txtAttenName."', '".$txtDueDate."', '".$txtExchangeDate."', '".$selFromOwner."', '".$this->getCheckNullVal($ChkBunkerSur)."', '".$this->getCheckNullVal($txtBunkerSurcharge)."', '".$this->getCheckNullVal($txtDemmurage)."', '".$this->getCheckNullVal($ChkDemmurage)."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql1 = "select max(INVOICEID) as max from freight_invoicerelet_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into freight_invoicerelet_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into freight_invoicerelet_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
	}
	else
	{
		$qrows = mysql_fetch_assoc($qres);
		$sql = "update freight_invoicerelet_master set DATE='".$txtDate."', I_TYPE='".$selIType."', NOB='".$selNOB."', STATUS='".$txtStatus."', MESSAGE='".$txtDNote."', GROSS_FREIGHT='".$this->getCheckNullVal($txtGrossFreight)."', BROKERAGE='".$this->getCheckNullVal($txtBrokerageAmt)."', CPDATE='".$txtCP_Date."', FINAL_FREIGHT='".$this->getCheckNullVal($txtNetFreight)."', TO_1='".$this->getCheckNullVal($txtTO)."', NET_AMOUNT='".$this->getCheckNullVal($txtNet)."', REMARKS='".$txtDesc."', PAYMENT_TERMS='".$txtPaymentTerms."', QUANTITY='".$txtQty."', BROKERAGE_PERCENT='".$txtBrokerage."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', AGREED_GROSS_FREIGHT_LOCAL='".$txtFreightAmtLocal."', EXCHANGE_RATE='".$txtExchangeRate."', ADDCOM='".$txtAddComm."', ADDCOM_AMOUNT='".$txtAddCommAmt."', NET_PAYABLE='".$txtNetAmtPayable."', P_TYPE='".$name."', ATTEN= '".$txtAttenName."', DUE_DATE='".$txtDueDate."', EXCHANGE_DATE= '".$txtExchangeDate."',  SHIP_OWNER='".$selFromOwner."', CHK_BUNK_SUR='".$this->getCheckNullVal($ChkBunkerSur)."', BUNKERSURCHARGE_AMT='".$this->getCheckNullVal($txtBunkerSurcharge)."', DEMMURAGE_AMT='".$this->getCheckNullVal($txtDemmurage)."', CHK_DEM='".$this->getCheckNullVal($ChkDemmurage)."' where INVOICEID='".$qrows['INVOICEID']."'";
		
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql_del = "delete from freight_invoicerelet_slave where INVOICEID='".$qrows['INVOICEID']."'";
		mysql_query($sql_del);
		mysql_query("commit");
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if(isset($_REQUEST['txtAddDes_'.$i]))
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into freight_invoicerelet_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if(isset($_REQUEST['txtSubDes_'.$i]))
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into freight_invoicerelet_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
				mysql_query($sql2);
			}
		}
	}
	
	mysql_query("commit");
	return $msg.','.$comid;  
}

function insertFreightPaymentReceivedDetailsRelet()
{
	//echo '<pre>';print_r($_POST);die();
	$connect = $this->funConnect();
	$id					= addslashes(trim($_REQUEST['comid']));
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update freight_invoicerelet_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."' where INVOICEID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	return $msg.'_'.$id; 
}

function getFreightInvoiceDetailsDataWithJsonRelet($comid)
{
	$connect   = $this->funconnect();	
	$query     = mysql_query("select * from freight_invoicerelet_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and COMID='".$comid."'");
	while($row = mysql_fetch_assoc($query))
	{
	    $id = $row['INVOICEID'];
		$a[$id][] = array('pay_no' => $row['PAYMENT_NO'], 'p_date' =>  date("d-m-Y",strtotime($row['P_DATE'])), 'p_type' => $row['P_TYPE'], 'remarks' => $row['P_REMARKS'], 'p_amt' => $row['P_AMT']);
	}
	echo json_encode($a);
}

function deletefreightInvoiceRecordsRelet()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txtDEL_ID']));
	$comid 			= addslashes(trim($_REQUEST['comid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	$sql = "delete from freight_invoicerelet_master where INVOICEID='".$id."'";
	mysql_query($sql);
	
	$sql1 = "delete freight_invoicerelet_slave where INVOICEID='".$id."'";
	mysql_query($sql1);
	
	mysql_query("commit"); 
	return $msg.','.$comid;
}


function getMonthList()
{
	$state = array( 1 =>'January' , 2 =>'February', 3 =>'March' , 4 =>'April', 5 =>'May', 6 =>'June', 7 =>'July', 8 =>'August', 9 =>'September', 10 =>'October', 11 =>'November', 12 =>'December');
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		echo "<option value='$key'>".$value."</option>";
	}
}

function getQuaterList()
{
	$state = array( 1 =>'1st Qtr' , 2 =>'2nd Qtr', 3 =>'3rd Qtr' , 4 =>'4th Qtr');
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		echo "<option value='$key'>".$value."</option>";
	}
}

function getYearListForCargoPlanning()
{
	$this->funConnect();
	$query = mysql_query("select distinct(Year(LAYCAN_SDATE)) as year from open_cargo_master group by year(LAYCAN_SDATE) desc ");
	while($rows = mysql_fetch_assoc($query))
	{
	    $key= $rows['year'];
	    $value= $rows['year'];
	    echo "<option value='$key'>".$value."</option>";
	}
}

function getBalticRouteList()
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM baltic_master WHERE STATUS=1";
	echo '<option value = "" >---Select from list---</option>';
	$result = mysql_query($query);
	while($rows = mysql_fetch_assoc($result))
	{
	    $key= $rows['BALTICID'];
	    $value= $rows['CODE'].' - '.$rows['NAME'];
	    echo "<option value='$key'>".$value."</option>";
	}
}

function getUserList()
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM login WHERE STATUS=1 and USER_TYPE in ('internal_user','mgmt_user')";
	echo "<option value = '' >---Select from list---</option>";
	$result = mysql_query($query);
	while($rows = mysql_fetch_assoc($result))
	{
	    $key= $rows['LOGINID'];
	    $value= $rows['CONTACT_PERSON'];
	    echo "<option value='".$key."'>".$value."</option>";
	}
}


function tc_baltic_report()
{
	$connect = $this->funConnect();
	$sql = "select chartering_estimate_tc_master.TC_NO, chartering_estimate_tc_master.CP_DATE1, chartering_estimate_tc_master.VESSEL_IMO_ID, SEL_CHARTERER, OWNERS_PI, DEL_DATE, RE_DEL_DATE, DEL_RANGE_PORT, RE_DEL_RANGE, HIRE_FIX_PER, EXCHANGE_RATE, BALTIC_ROUTE, (select CONCAT(CODE, ' - ' ,NAME) from baltic_master where baltic_master.BALTICID=chartering_estimate_tc_master.BALTIC_ROUTE) as BALTIC_ROUTENAME, BALTIC_DATE, BALTIC_RATE from chartering_estimate_tc_compare inner join chartering_estimate_tc_master on chartering_estimate_tc_master.TCOUTID= chartering_estimate_tc_compare.TCOUTID WHERE chartering_estimate_tc_compare.MODULEID='".$_SESSION['moduleid']."' AND chartering_estimate_tc_compare.MCOMPANYID='".$_SESSION['company']."' and chartering_estimate_tc_compare.FINAL_ID!='' and chartering_estimate_tc_master.FIXED=1 and chartering_estimate_tc_compare.STATUS in (1,2,3)";
	$res = mysql_query($sql) or die($sql);
	$i = 1;
	while($rows = mysql_fetch_assoc($res))
	{
		echo '<tr>';
		if(date('d-m-Y',strtotime($rows['BALTIC_DATE']))!='01-01-1970'){$txtBalticDate = date('d-m-Y',strtotime($rows['BALTIC_DATE']));}else{$txtBalticDate = '';}
		echo '<td align="left">'.$i.'</td>';
		echo '<td align="left">'.$rows['TC_NO'].'</td>';
		echo '<td align="left">'.date('d-m-Y',strtotime($rows['CP_DATE1'])).'</td>';
		echo '<td align="left">'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'], 'VESSEL_NAME').'</td>';
		echo '<td align="left">'.$this->getVendorListNewData($rows['SEL_CHARTERER'],"NAME").'</td>';
		echo '<td align="left">'.$this->getCompanyNameBasedOnID($_SESSION['company'],"COMPANY_NAME").'</td>';
		echo '<td align="left">'.date('d-m-Y H:i',strtotime($rows['DEL_DATE'])).'</td>';
		echo '<td align="left">'.date('d-m-Y H:i',strtotime($rows['RE_DEL_DATE'])).'</td>';
		echo '<td align="left">'.$rows['DEL_RANGE_PORT'].'</td>';
		echo '<td align="left">'.$rows['RE_DEL_RANGE'].'</td>';
		echo '<td align="left">'.number_format($rows['HIRE_FIX_PER']*$rows['EXCHANGE_RATE'],2,'.','').'</td>';
		echo '<td align="left">'.$rows['BALTIC_ROUTENAME'].'</td>';
		echo '<td align="left">'.$txtBalticDate.'</td>';
		echo '<td align="left">'.$rows['BALTIC_RATE'].'</td>';
		$diff = number_format(($rows['BALTIC_RATE'] - ($rows['HIRE_FIX_PER']*$rows['EXCHANGE_RATE'])),2,'.','');
		$diffper = number_format((($diff/$rows['BALTIC_RATE'])*100),2,'.','');
		echo '<td align="left">'.$diff.'</td>';
		echo '<td align="left">'.$diffper.'</td>';
		$i++;
	}
}


function insertOtherReletInvoiceDetails($comid)
{
	$connect 			= $this->funConnect();	
	$comid 				= addslashes(trim($_REQUEST['comid']));
	$name 				= addslashes(trim($_REQUEST['name']));
	
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtDNote	 		= addslashes(trim($_REQUEST['txtDNote']));
	$txtInvoiceid       = addslashes(trim($_REQUEST['txtInvoiceid']));
	
	$txtDNote_1	 		= explode("/",$_REQUEST['txtDNote']);
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtFCAID	 		= addslashes(trim($_REQUEST['txtFCAID']));

	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtDueDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	
	$txtInvAmount	    = addslashes(trim($_REQUEST['txtInvAmount']));
	
	$selNOB	 		    = addslashes(trim($_REQUEST['selNOB']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	
	$txtNetAmtPayable	= addslashes(trim($_REQUEST['txtNetAmtPayable']));
	$txtDNote1			= addslashes(trim($_REQUEST['txtDNote1']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$qsql = "select * from other_relet_invoice_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR='".$txtVendor."' and MESSAGE = '".$txtDNote1."' and P_TYPE='".$name."'";
	
	$qres = mysql_query($qsql) or die($qsql);
	$qrec = mysql_num_rows($qres);
	if($qrec == 0)
	{
		$sql = "insert into other_relet_invoice_master (COMID, MODULEID, MCOMPANYID, DATE, I_TYPE, NOB, STATUS, MESSAGE, VENDOR, GROSS_AMT, CPDATE, FCAID, REMARKS, PAYMENT_TERMS, EXCHANGE_CURRENCY, EXCHANGE_RATE, NET_PAYABLE, P_TYPE, ATTEN, DUE_DATE, EXCHANGE_DATE,  SHIP_OWNER) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$txtDate."', '".$selIType."', '".$selNOB."', '".$txtStatus."', '".$txtDNote."', '".$txtVendor."', '".$this->getCheckNullVal($txtInvAmount)."', '".$txtCP_Date."', '".$txtFCAID."', '".$txtDesc."', '".$txtPaymentTerms."', '".$selExchangeCurrency."', '".$txtExchangeRate."', '".$txtNetAmtPayable."', '".$name."', '".$txtAttenName."', '".$txtDueDate."', '".$txtExchangeDate."', '".$selFromOwner."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql1 = "select max(INVOICEID) as max from other_relet_invoice_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into other_relet_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into other_relet_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
	}
	else
	{
		$qrows = mysql_fetch_assoc($qres);
		$sql = "update other_relet_invoice_master set DATE='".$txtDate."', I_TYPE='".$selIType."', NOB='".$selNOB."', STATUS='".$txtStatus."', MESSAGE='".$txtDNote."', VENDOR='".$txtVendor."', GROSS_AMT='".$this->getCheckNullVal($txtInvAmount)."', CPDATE='".$txtCP_Date."', FCAID='".$txtFCAID."', REMARKS='".$txtDesc."', PAYMENT_TERMS='".$txtPaymentTerms."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', NET_PAYABLE='".$txtNetAmtPayable."', P_TYPE='".$name."', ATTEN='".$txtAttenName."', DUE_DATE='".$txtDueDate."', EXCHANGE_DATE='".$txtExchangeDate."',  SHIP_OWNER='".$selFromOwner."', EXCHANGE_RATE='".$txtExchangeRate."' where INVOICEID='".$qrows['INVOICEID']."'";
		
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql_del = "delete from other_relet_invoice_slave where INVOICEID='".$qrows['INVOICEID']."'";
		mysql_query($sql_del);
		mysql_query("commit");
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if(isset($_REQUEST['txtAddDes_'.$i]))
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into other_relet_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if(isset($_REQUEST['txtSubDes_'.$i]))
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into other_relet_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
				mysql_query($sql2);
			}
		}
	}
	
	mysql_query("commit");
	return $msg.','.$comid;  
}

function insertOtherReletInvoiceReceivedDetails($comid)
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update other_relet_invoice_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."' where INVOICEID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	return $msg; 
}

function getNoticesList($id)							
{
	$state = array( '1' =>'14/10/7/5/3/2/1' , '2' =>'10/7/5/3/2/1' , '3' =>'7/5/3/2/1' , '4' =>'3/2/1' , '5' =>'prompt/as applicable');
	echo '<option value="">---Select from list---</option>';
		while ($array_cell = each($state)) 
		{
			$value = $array_cell['value'];
			$key = $array_cell['key'];
			
			echo "<option value=$key";
			if($key == $id){ echo " selected";}
			echo ">".$value."</option>";
			
		}
}


function getSelectAddDeadQTY($id)
{
	$state = array( '1' =>'Additional Quantity' , '2' =>'DeadFreight' , '3' =>'Not Applicable');
	echo '<option value="">---Select from list---</option>';
		while ($array_cell = each($state)) 
		{
			$value = $array_cell['value'];
			$key = $array_cell['key'];
			
			echo "<option value=$key";
			if($key == $id){ echo " selected";}
			echo ">".$value."</option>";
			
		}
}

function getBLManifestList($id)
{
	$state = array( '1' =>'OBL' , '2' =>'SBL');
	echo '<option value="">---Select from list---</option>';
		while ($array_cell = each($state)) 
		{
			$value = $array_cell['value'];
			$key = $array_cell['key'];
			
			echo "<option value=$key";
			if($key == $id){ echo " selected";}
			echo ">".$value."</option>";
			
		}
}


function getNORList($id)
{
	$state = array( '1' =>'ATDNSHINC' , '2' =>'OFFICE HRS');
	echo '<option value="">---Select from list---</option>';
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $id){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getTCENoticesList($id)							
{
	$state = array( '1' =>'15/10/7 approx. 5/3/2/1 definite' , '2' =>'10/7 approx. 5/3/2/1 definite' , '3' =>'10/7/5 approx. 3/2/1 definite' , '4' =>'5/3/2/1 definite' , '5' =>'3/2/1 definite' , '6' =>'Prompt / as applicable');
	echo '<option value="">---Select from list---</option>';
		while ($array_cell = each($state)) 
		{
			$value = $array_cell['value'];
			$key = $array_cell['key'];
			
			echo "<option value=$key";
			if($key == $id){ echo " selected";}
			echo ">".$value."</option>";
			
		}
}



function getTCDeliverySurveyList($id)
{
	$state = array( '1' =>'Full time and half cost Owners a/c' , '2' =>'Full time and full cost Owners a/c' , '3' =>'No time but half cost Owners a/c' , '4' =>'Time and cost shared half with owners');
	echo '<option value="">---Select from list---</option>';
		while ($array_cell = each($state)) 
		{
			$value = $array_cell['value'];
			$key = $array_cell['key'];
			
			echo "<option value=$key";
			if($key == $id){ echo " selected";}
			echo ">".$value."</option>";
			
		}
}



function getBunkerListBasedOnBunkerType($type)
{
	$this->funConnect();
	$query = mysql_query("select * from bunker_grade_master where STATUS=1 and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and BUNKERTYPE='".$type."' order by NAME ");
	@$selCName = @$_REQUEST['selCName'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key= $rows['BUNKERGRADEID'];
		 $value= $rows['NAME'];
		 echo '<option value='.$key;
		 echo '>'.$value.'</option>';
		}
}




function updationBunkerRecords()
{
	$connect = $this->funConnect(); 
	
	$comid 			    = addslashes(trim($_REQUEST['comid']));
	$txtNOOFPORT	 	= addslashes(trim($_REQUEST['txtNOOFPORT']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	if(isset($_REQUEST['selPrevComid'])){
		$sqlcom = "update freight_cost_estimate_compare set PREVCOMID='".$_REQUEST['selPrevComid']."' where COMID='".$comid."'";
		mysql_query($sqlcom);
	}
	
	
	$sql1 = "delete from freight_cost_estimate_compare_slave  where COMID='".$comid."'";
	$sql2 = "delete from freight_cost_estimate_compare_slave2  where COMID='".$comid."'";
	$sql3 = "delete from freight_cost_estimate_compare_slave3  where COMID='".$comid."'";
	$sql4 = "delete from freight_cost_estimate_compare_slave4  where COMID='".$comid."'";
	$sql5 = "delete from freight_cost_estimate_compare_slave5  where COMID='".$comid."'";
	mysql_query($sql1);
	mysql_query($sql2);
	mysql_query($sql3);
	mysql_query($sql4);
	mysql_query($sql5);
	
	$txtFORPREVID  = $_REQUEST['txtFORPREVID'];
	for($j=1;$j<=$txtFORPREVID;$j++)
	{
		$sql11 = "insert into freight_cost_estimate_compare_slave5 (COMID, BUNKERID, ROB_SOSP, BUNKER_PRICE, CAL_DESC) values ('".$comid."', '".$_REQUEST['hddnFOPrevBunkerid_'.$j]."', '".$_REQUEST['txtFOPrevQTY_'.$j]."', '".$_REQUEST['txtFOPrevPrice_'.$j]."', '".$_REQUEST['txtFOPrevCalDesc_'.$j]."')";
		mysql_query($sql11) or die($sql11);
	}
	
	$txtDORPREVID  = $_REQUEST['txtDORPREVID'];
	for($j=1;$j<=$txtDORPREVID;$j++)
	{
		$sql12 = "insert into freight_cost_estimate_compare_slave5 (COMID, BUNKERID, ROB_SOSP, BUNKER_PRICE, CAL_DESC) values ('".$comid."', '".$_REQUEST['hddnDOPrevBunkerid_'.$j]."', '".$_REQUEST['txtDOPrevQTY_'.$j]."', '".$_REQUEST['txtDOPrevPrice_'.$j]."', '".$_REQUEST['txtDOPrevCalDesc_'.$j]."')";
		mysql_query($sql12) or die($sql12);
	}
	
	for($i = 1;$i <= $txtNOOFPORT;$i++)
	{
		$txtSOSPDate	 		= date("Y-m-d H:i:s",strtotime($_REQUEST['txtSOSPDate_'.$i]));
		$sql = "insert into freight_cost_estimate_compare_slave (COMID, PORTID, RANDOMID, ROB_DATE) values ('".$comid."', '".$_REQUEST['txtPortID_'.$i]."', '".$_REQUEST['txtRandomID_'.$i]."', '".$txtSOSPDate."')";
		mysql_query($sql) or die($sql);
		
		$sql1 = "select max(COM_SLAVEID) as max from freight_cost_estimate_compare_slave";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		
		$txtFORID  = $_REQUEST['txtFORID_'.$i];
		for($j=1;$j<=$txtFORID;$j++)
		{
			$sql2 = "insert into freight_cost_estimate_compare_slave2 (COMID, COM_SLAVEID, BUNKER_TYPE, BUNKERID, ROB_SOSP, STEEMED_QTY, SUPPLY_PRICE, ADDNL_COST, EFFECTIVE_PRICE, STEEMED_VALUE, REMARKS, ONACCOUNT_OF) values ('".$comid."', '".$rows1['max']."', 'FO', '".$_REQUEST['selFOBunkerID_'.$i.'_'.$j]."', '".$_REQUEST['txtFOROBSOSP_'.$i.'_'.$j]."', '".$_REQUEST['txtFOQtyStemmed_'.$i.'_'.$j]."', '".$_REQUEST['txtFOSupplyPrice_'.$i.'_'.$j]."', '".$_REQUEST['txtFOAddCost_'.$i.'_'.$j]."', '".$_REQUEST['txtFOEffectivePrice_'.$i.'_'.$j]."', '".$_REQUEST['txtFOStemmedValue_'.$i.'_'.$j]."', '".trim(addslashes($_REQUEST['txtFORemarks_'.$i.'_'.$j]))."', '".$_REQUEST['selFOAccountOf_'.$i.'_'.$j]."')";
			mysql_query($sql2);
		}
		
		$txtDORID  = $_REQUEST['txtDORID_'.$i];
		for($j=1;$j<=$txtDORID;$j++)
		{
			$sql2 = "insert into freight_cost_estimate_compare_slave2 (COMID, COM_SLAVEID, BUNKER_TYPE, BUNKERID, ROB_SOSP, STEEMED_QTY, SUPPLY_PRICE, ADDNL_COST, EFFECTIVE_PRICE, STEEMED_VALUE, REMARKS, ONACCOUNT_OF) values ('".$comid."', '".$rows1['max']."', 'DO', '".$_REQUEST['selDOBunkerID_'.$i.'_'.$j]."', '".$_REQUEST['txtDOROBSOSP_'.$i.'_'.$j]."', '".$_REQUEST['txtDOQtyStemmed_'.$i.'_'.$j]."', '".$_REQUEST['txtDOSupplyPrice_'.$i.'_'.$j]."', '".$_REQUEST['txtDOAddCost_'.$i.'_'.$j]."', '".$_REQUEST['txtDOEffectivePrice_'.$i.'_'.$j]."', '".$_REQUEST['txtDOStemmedValue_'.$i.'_'.$j]."', '".trim(addslashes($_REQUEST['txtDORemarks_'.$i.'_'.$j]))."', '".$_REQUEST['selDOAccountOf_'.$i.'_'.$j]."')";
			mysql_query($sql2);
		}
	}
	
	$txtFOSOSPRID  = $_REQUEST['txtFOSOSPRID'];
	for($j=1;$j<=$txtFOSOSPRID;$j++)
	{
		$sql2 = "insert into freight_cost_estimate_compare_slave3 (COMID, BUNKER_TYPE, BUNKERID, SOSP_VALUE, CAL_DESC) values ('".$comid."', 'FO', '".$_REQUEST['hddnFOSOSPBunkerID_'.$j]."', '".$_REQUEST['txtFOSOSPResult_'.$j]."', '".$_REQUEST['txtFOSOSPDesc_'.$j]."')";
		mysql_query($sql2);
	}
	
	$txtDOSOSPRID  = $_REQUEST['txtDOSOSPRID'];
	for($j=1;$j<=$txtDOSOSPRID;$j++)
	{
		$sql2 = "insert into freight_cost_estimate_compare_slave3 (COMID, BUNKER_TYPE, BUNKERID, SOSP_VALUE, CAL_DESC) values ('".$comid."', 'DO', '".$_REQUEST['hddnDOSOSPBunkerID_'.$j]."', '".$_REQUEST['txtDOSOSPResult_'.$j]."', '".$_REQUEST['txtDOSOSPDesc_'.$j]."')";
		mysql_query($sql2);
	}
	
	
	$txtFOCONSUMEDRID  = $_REQUEST['txtFOCONSUMEDRID'];
	for($j=1;$j<=$txtFOCONSUMEDRID;$j++)
	{
		$sql2 = "insert into freight_cost_estimate_compare_slave4 (COMID, BUNKERID, BUNKER_TYPE, QTY_USER, USED_AMT, CONSUMEDON) values ('".$comid."', '".$_REQUEST['hddnFOCONSUMEDBunkerID_'.$j]."', 'FO', '".$_REQUEST['txtFOCONSUMEDQty_'.$j]."', '".$_REQUEST['txtFOCONSUMEDValue_'.$j]."', 'CHARTERER')";
		mysql_query($sql2);
	}
	
	$txtDOCONSUMEDRID  = $_REQUEST['txtDOCONSUMEDRID'];
	for($j=1;$j<=$txtDOCONSUMEDRID;$j++)
	{
		$sql2 = "insert into freight_cost_estimate_compare_slave4 (COMID, BUNKERID, BUNKER_TYPE, QTY_USER, USED_AMT, CONSUMEDON) values ('".$comid."', '".$_REQUEST['hddnDOCONSUMEDBunkerID_'.$j]."', 'DO', '".$_REQUEST['txtDOCONSUMEDQty_'.$j]."', '".$_REQUEST['txtDOCONSUMEDValue_'.$j]."', 'CHARTERER')";
		mysql_query($sql2);
	}
	
	
	$txtFOCONSUMEDORID  = $_REQUEST['txtFOCONSUMEDORID'];
	for($j=1;$j<=$txtFOCONSUMEDORID;$j++)
	{
		$sql2 = "insert into freight_cost_estimate_compare_slave4 (COMID, BUNKERID, BUNKER_TYPE, QTY_USER, USED_AMT, CONSUMEDON) values ('".$comid."', '".$_REQUEST['hddnFOCONSUMEDOBunkerID_'.$j]."', 'FO', '".$_REQUEST['txtFOCONSUMEDOQty_'.$j]."', '".$_REQUEST['txtFOCONSUMEDOValue_'.$j]."', 'OWNER')";
		mysql_query($sql2);
	}
	
	$txtDOCONSUMEDORID  = $_REQUEST['txtDOCONSUMEDORID'];
	for($j=1;$j<=$txtDOCONSUMEDORID;$j++)
	{
		$sql2 = "insert into freight_cost_estimate_compare_slave4 (COMID, BUNKERID, BUNKER_TYPE, QTY_USER, USED_AMT, CONSUMEDON) values ('".$comid."', '".$_REQUEST['hddnDOCONSUMEDOBunkerID_'.$j]."', 'DO', '".$_REQUEST['txtDOCONSUMEDOQty_'.$j]."', '".$_REQUEST['txtDOCONSUMEDOValue_'.$j]."', 'OWNER')";
		mysql_query($sql2);
	}
	
	mysql_query("commit");
	return $msg;  
}

function getVC_COAListBasedOnVesselID($comid,$vesselid)
{
	$this->funConnect();
	$query = "select COMID, COAAID, MESSAGE, (select VOYAGE_NO from freight_cost_estimete_master where freight_cost_estimete_master.COMID=freight_cost_estimate_compare.COMID LIMIT 1) as VOYAGE_NO from freight_cost_estimate_compare where COMID !='".$comid."' and (select VESSEL_IMO_ID from freight_cost_estimete_master where freight_cost_estimete_master.COMID=freight_cost_estimate_compare.COMID LIMIT 1)='".$vesselid."' and (select FIXED from freight_cost_estimete_master where freight_cost_estimete_master.COMID=freight_cost_estimate_compare.COMID LIMIT 1)=1 and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' order by ADD_ON_DATE DESC";
	$result = mysql_query($query);
	@$selPrevComid = @$_REQUEST['selPrevComid'];
	while($rows = mysql_fetch_assoc($result))
	{
		 $sql1 = "select * from freight_cost_estimate_compare where PREVCOMID='".$rows['COMID']."' and COMID!='".$comid."'";
		 $res1 = mysql_query($sql1);
		 $num1 = mysql_num_rows($res1);
		 if($num1==0)
		 {
			 $key = $rows['COMID'];
			 if($rows['COAAID']!=NULL){
				 $value= $rows['VOYAGE_NO'].' ('.$rows['MESSAGE'].') - COA';
			 }else{
				 $value= $rows['VOYAGE_NO'].' ('.$rows['MESSAGE'].') - VC';
			 }
			 echo '<option value='.$key;
			 echo '>'.$value.'</option>';
		}
	}
}


function insertTCPaymentOthersDetails()
{
	$connect = $this->funConnect();
	
	$comid 			    = addslashes(trim($_REQUEST['comid']));
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType	 		= addslashes(trim($_REQUEST['selIType']));
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$txtInvNo	 	    = addslashes(trim($_REQUEST['txtInvNo']));
	$txtInvDate	 		= date("Y-m-d",strtotime($_REQUEST['txtInvDate']));
	$txtINVoiceNo     	= $_REQUEST['txtINVoiceNo'];
	$txtINCOM_InvoiceDate = date('Y-m-d H:i',strtotime($_REQUEST['txtINCOM_InvoiceDate']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$selBankingDetails 	= addslashes(trim($_REQUEST['selBankingDetails']));
	$txtInvAmt  	    = addslashes(trim($_REQUEST['txtInvAmt']));
	$txtINVVendor       = addslashes(trim($_REQUEST['txtINVVendor']));
	$txtINVidentity     = addslashes(trim($_REQUEST['txtINVidentity']));
	$txtINVShortDesc    = addslashes(trim($_REQUEST['txtINVShortDesc']));
	$txtFinalAmt        = addslashes(trim($_REQUEST['txtFinalAmt']));
	$txtStatus          = addslashes(trim($_REQUEST['txtStatus']));
	$txtInID            = addslashes(trim($_REQUEST['txtInID']));
	$txtRandomid        = addslashes(trim($_REQUEST['randomid']));
	$txtInvoicedAmt     = addslashes(trim($_REQUEST['txtInvoicedAmt']));
	$selBankingID       = addslashes(trim($_REQUEST['selBankingID']));
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$filename = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$filename = implode(',',$filename);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $filename != ''){ $filename1 = $txtCRMNAME1.','.$filename;}
	else if($txtCRMNAME1 == '' && $filename != ''){ $filename1 = $filename;}
	else if($txtCRMNAME1 != '' && $filename == ''){ $filename1 = $txtCRMNAME1;}
	
	$selApprovers             = $_REQUEST['selApprovers'];
	$invoiceidd = '';$creatorloginid = '';
	
	$sqltc = "SELECT * from chartering_tc_estimate_slave1 where TCOUTID='".$this->getCharteringEstimateTCData($comid, "TCOUTID")."' and RANDOMID='".$_REQUEST['randomid']."'";
	$restc 	= mysql_query($sqltc);
	$rectc 	= mysql_num_rows($restc);
	$rowstc = mysql_fetch_assoc($restc);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	if($txtInID == '')
	{
		//insert query here.............
		$sql = "insert into payment_tcother_master (MODULEID, MCOMPANYID, COMID, INVOICE_TYPE, INVOICE_NO, INVOICE_DATE, EXCHANGE_RATE, EXCHANGE_CURRENCY, PAYMENT_TERMS, DESCRIPTION, INCOM_INVOICE_NO, AMOUNT, FINAL_AMOUNT, STATUS, SHIP_OWNER, ATTEN, RANDOMID, INCOM_INVOICE_DATE, VENDOR, INV_IDENTITY, SHORT_DESC, INVOICED_AMT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME, BANKING_DETAILS, VENDOR_SLAVEID) values ('".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$comid."', '".$selIType."', '".$txtInvNo."', '".$txtInvDate."', '".$this->getCheckNullVal($txtExchangeRate)."', '".$selExchangeCurrency."', '".$txtPaymentTerms."', '".$txtDesc."', '".$txtINVoiceNo."', '".$this->getCheckNullVal($txtInvAmt)."', '".$this->getCheckNullVal($txtFinalAmt)."', '".$txtStatus."', '".$selFromOwner."', '".$txtAttenName."', '".$txtRandomid."', '".$txtINCOM_InvoiceDate."', '".$txtINVVendor."', '".$txtINVidentity."', '".$txtINVShortDesc."', '".$this->getCheckNullVal($txtInvoicedAmt)."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$upload1."', '".$filename1."', '".addslashes(trim($this->getVendorListNewData($rowstc['TC_FINAL_HIERAGE_VENDOR'],"BANKING_DETAILS")))."', '".$selBankingID."')";
		mysql_query($sql) or die($sql);
		
		$sql1 = "select max(PAYMENTID) as max from payment_tcother_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if($_REQUEST['txtAddDesAmt_'.$i] > 0)
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into payment_tcother_slave1 (PAYMENTID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$this->getCheckNullVal($txtAddDesAmt)."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if($_REQUEST['txtSubDesAmt_'.$i] > 0)
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into payment_tcother_slave1 (PAYMENTID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$this->getCheckNullVal($txtSubDesAmt)."', 'SUB')";
				mysql_query($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." TC Other Payment (".$txtInvNo.") Created Successfully.");
	}
	else
	{
		$invoiceidd = $txtInID;
		
		$sql_sel = "select APPROVERS, CREATOR from payment_tcother_master where PAYMENTID='".$txtInID."'";
		$res_sel = mysql_query($sql_sel) or die($sql_sel);
		$rows_sel = mysql_fetch_assoc($res_sel);
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $rows_sel['APPROVERS'];
		}
		$creatorloginid = $rows_sel['CREATOR'];
		
		$sql = "update payment_tcother_master set INVOICE_TYPE='".$selIType."', INVOICE_NO='".$txtInvNo."', INVOICE_DATE='".$txtInvDate."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', PAYMENT_TERMS='".$txtPaymentTerms."', DESCRIPTION='".$txtDesc."', INCOM_INVOICE_NO='".$txtINVoiceNo."', AMOUNT='".$this->getCheckNullVal($txtInvAmt)."', VENDOR='".$txtINVVendor."', INV_IDENTITY='".$txtINVidentity."', FINAL_AMOUNT='".$this->getCheckNullVal($txtFinalAmt)."', STATUS='".$txtStatus."', SHIP_OWNER='".$selFromOwner."', ATTEN='".$txtAttenName."', INCOM_INVOICE_DATE='".$txtINCOM_InvoiceDate."', SHORT_DESC='".$txtINVShortDesc."', INVOICED_AMT='".$this->getCheckNullVal($txtInvoicedAmt)."', UPLOAD='".$upload1."', UPLOAD_NAME='".$filename1."', APPROVERS='".$approversel."', BANKING_DETAILS = '".addslashes(trim($this->getVendorListNewData($rowstc['TC_FINAL_HIERAGE_VENDOR'],"BANKING_DETAILS")))."', VENDOR_SLAVEID='".$selBankingID."' where PAYMENTID='".$txtInID."'";
		mysql_query($sql) or die($sql);
		
		$sql1 = "delete from payment_tcother_slave1  where PAYMENTID='".$txtInID."'";
		mysql_query($sql1);
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if($_REQUEST['txtAddDesAmt_'.$i] > 0)
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into payment_tcother_slave1 (PAYMENTID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtAddDes."', '".$this->getCheckNullVal($txtAddDesAmt)."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if($_REQUEST['txtSubDesAmt_'.$i] > 0)
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into payment_tcother_slave1 (PAYMENTID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$txtInID."', '".$txtSubDes."', '".$this->getCheckNullVal($txtSubDesAmt)."', 'SUB')";
				mysql_query($sql2);
			}
		}
		
		$this->saveRecentWork($selIType." TC Other Payment (".$txtInvNo.") Updated Successfully.");
	}
	
	mysql_query("commit");
	
	
	$this->inactiveUserAlerts('OTHER TC PAYMENT', $_SESSION['uid'], $invoiceidd);
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	$approverarr2 = $this->getUsersWithAuthority('HIRE_STSTMENT_CHK_APP_2');
	$appaccountarr = $this->getUsersWithAuthority('HIRE_STSTMENT_CHK_ACC');
	
	$url = './payment_otherstc.php?comid='.$_REQUEST['comid'].'&page='.$_REQUEST['page']."&randomid=".$_REQUEST['randomid']."&vendor=".$_REQUEST['vendor']."&amount=".$_REQUEST['amount']."&desc=".$_REQUEST['desc']."&invtype=".$_REQUEST['invtype'];
	
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'OTHER TC PAYMENT';
	
	$vesselname = $this->getVesselIMOData($this->getCharteringEstimateTCData($_REQUEST['comid'],"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC PAYMENT', $currentusername.' sent '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC PAYMENT', $currentusername.' sent '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC PAYMENT', $currentusername.' sent '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC PAYMENT', $currentusername.' sent '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		if($txtStatus == 5)
		{
		     if(!empty($appaccountarr))
			 {
			     $userarray = $appaccountarr;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'OTHER TC PAYMENT', $currentusername.' Approved '.$_REQUEST['invtype'].' ('.$vesselname.' - '.$txtInvNo.')', $invoiceidd);				  
				  }
			 }
		}
	}
	
	return $msg;  
}


function deleteOtherTCPaymentRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txtDEL_ID']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	$sql = "delete from payment_tcother_master where PAYMENTID='".$id."'";
	mysql_query($sql);
	
	$sql1 = "delete payment_tcother_slave1 where PAYMENTID='".$id."'";
	mysql_query($sql1);
	
	mysql_query("commit"); 
	return $msg;
}

function inserttcOthersINvPaymentPaidDetails()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update payment_tcother_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where PAYMENTID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$this->inactiveUserAlerts('OTHER TC PAYMENT', $_SESSION['uid'], $txtP_ID);
	
	return $msg; 
}


function getCOASpotTCList()
{
$state = array( 1 =>'SPOT' , 2 =>'COA' , 3 =>'TC');
$selCOASpot = @$_REQUEST['selCOASpot'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selCOASpot){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}


function getInvoiceTypeName1($type)
{
	$state = array('Interim'=>'Interim', 'Final'=>'Final', 'Memo'=>'Memo', 'Debit'=>'Debit Note', 'Credit'=>'Credit Note', 'Adjustment'=>'Adjustment', 'PFHS'=>'PFHS', 'FHS2'=>'FHS - 2');
	return $state[$type];
}



function insertGenericFinancesDetails()
{
	$connect 			= $this->funConnect();	
	
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtInvoiceNo	    = addslashes(trim($_REQUEST['txtInvoiceNo']));
	$txtContractDetails	= addslashes(trim($_REQUEST['txtContractDetails']));
	$selContractType   	= addslashes(trim($_REQUEST['selContractType']));
	
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$selVendor	 		= addslashes(trim($_REQUEST['selVendor']));
	
	$txtInvoiceDate	 	= date("Y-m-d",strtotime($_REQUEST['txtInvoiceDate']));
	$txtDueDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	
	$txtAmountDesc	    = addslashes(trim($_REQUEST['txtAmountDesc']));
	$txtMainAmount	 	= addslashes(trim($_REQUEST['txtMainAmount']));
	$txtNetAmtPayable	= addslashes(trim($_REQUEST['txtNetAmtPayable']));
	
	$selNOB	 		    = addslashes(trim($_REQUEST['selNOB']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$selBType           = $_REQUEST['selBType'];

	$type=addslashes(trim($_REQUEST['type']));
	
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into generic_invoice_master (MODULEID, MCOMPANYID, INVOICE_DATE, INVOICE_NO, I_TYPE, NOB, STATUS, VENDOR, AMOUNT, NET_PAYABLE, REMARKS, PAYMENT_TERMS, ATTEN, DUE_DATE, EXCHANGE_CURRENCY, SHIP_OWNER, CONTRACT_DETAILS, CONTRACT_TYPE, BUSINESSTYPEID, AMOUNT_DESC,type) values ('".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$txtInvoiceDate."', '".$txtInvoiceNo."', '".$selIType."', '".$selNOB."', '".$txtStatus."', '".$selVendor."', '".$this->getCheckNullVal($txtMainAmount)."', '".$this->getCheckNullVal($txtNetAmtPayable)."', '".$txtDesc."', '".$txtPaymentTerms."', '".$txtAttenName."', '".$txtDueDate."', '".$selExchangeCurrency."', '".$selFromOwner."', '".$txtContractDetails."', '".$selContractType."', '".$selBType."', '".$txtAmountDesc."','".$type."')";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
		
	$sql1 = "select max(INVOICEID) as max from generic_invoice_master";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	$txtAddID  = $_REQUEST['txtAddID'];
	for($i=1;$i<=$txtAddID;$i++)
	{
		$txtAddDes	 	  = addslashes(trim($REQUEST['txtAddDes'.$i]));
		$txtAddDesAmt	  = $this->getCheckNullVal($REQUEST['txtAddDesAmt'.$i]);
		$sql2 = "insert into generic_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
		mysql_query($sql2);
	}
	
	$txtSubID  = $_REQUEST['txtSubID'];
	for($i=1;$i<=$txtSubID;$i++)
	{
		$txtSubDes	 	  = addslashes(trim($REQUEST['txtSubDes'.$i]));
		$txtSubDesAmt	  = $this->getCheckNullVal($REQUEST['txtSubDesAmt'.$i]);
		$sql2 = "insert into generic_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
		mysql_query($sql2);
	}
	mysql_query("commit");
	return $msg;  
}

function getYearListForInvoices($year)
{
	$this->funConnect();
	$arr_year = array();
	$i = 0;
	$query = mysql_query("select distinct(Year(INVOICE_DATE)) as year from generic_invoice_master group by year(INVOICE_DATE) desc ");
	while($rows = mysql_fetch_assoc($query))
	{
		$arr_year[] = $rows['year'];
	    $key= $rows['year'];
	    $value= $rows['year'];
	    echo '<option value='.$key;
	    if($year==$key){ echo " selected";$i = 1;}
	    echo '>'.$value.'</option>';
	}
	if(!in_array(date('Y',time()), $arr_year))
	{
		echo '<option value='.date('Y',time());
	    if($i==0){ echo " selected";}
	    echo '>'.date('Y',time()).'</option>';
	}
}


function displayGenericFinancesList($selBType,$selYear)
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="elibrary_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="left" valign="top" width="9%" >Business Type</th>';	
	echo '<th align="left" valign="top" width="9%" >Contract Type</th>';
	echo '<th align="left" valign="top" width="9%" >Invoice Date</th>';

	echo '<th align="left" valign="top" width="9%" >Invoice To</th>';	
	echo '<th align="left" valign="top" width="9%" >Invoice No.</th>';
	echo '<th align="left" valign="top" width="9%" >Invoice Amount</th>';
	echo '<th align="left" valign="top" width="9%" >Invoice Type</th>';
	echo '<th align="left" valign="top" width="9%" >Status</th>';
	echo '<th align="center" valign="top" width="25%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from generic_invoice_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' ";
	if($selBType!='')
	{
		$sql.=" and BUSINESSTYPEID='".$selBType."'"; 
	}
	if($selYear!='')
	{
		$sql.=" and year(INVOICE_DATE)='".$selYear."'"; 
	}
	$sql.=" order by INVOICE_DATE DESC"; 
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		echo '<tbody id="tbody">';
		
		echo '</tbody>';
	}
	else{
	    echo '<tbody id="tbody">';
		while($rows = mysql_fetch_assoc($res))
		{
			echo '<tr>';
			echo '<td align="left" valign="middle" class="input-text">'.$this->getEstimateList($rows['BUSINESSTYPEID']).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$this->getCOA_SPOTBasedOnID($rows['CONTRACT_TYPE']).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.date("d-m-Y",strtotime($rows['INVOICE_DATE'])).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$this->getVendorListNewBasedOnID($rows['VENDOR']).'</td>';
			echo '<td align="left" valign="middle" class="input-text">'.$rows['INVOICE_NO'].'</td>';
			echo '<td align="right" valign="middle" class="input-text"><code style="float:left;">'.$rows['EXCHANGE_CURRENCY'].'</code>'.$rows['NET_PAYABLE'].'</td>';
			echo '<td align="left" valign="middle" class="input-text"><b><span class="label label-primary" style="font-size:11px;">'.$this->getInvoiceTypeName1($rows['I_TYPE']).'</span></b></td>';
			
			if($rows['STATUS']==0)
			{
				echo '<td align="left" valign="middle" class="input-text"><b><span class="label label-warning" style="font-size:11px;">Draft</span></b></td>';
			}
			if($rows['STATUS']==1)
			{
				echo '<td align="left" valign="middle" class="input-text"><b><span class="label label-success" style="font-size:11px;">Submitted</span></b></td>';
			}
			if($rows['STATUS']==2)
			{
				echo '<td align="left" valign="middle" class="input-text"><b><span class="label label-danger" style="font-size:11px;">Cancelled</span></b></td>';
			}
			if($rows['STATUS']==0)
			{
				echo '<td align="center" valign="middle" class="input-text "><a href="updateginvoice.php?id='.$rows['INVOICEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;&nbsp;<a href="#" title="Pdf" onClick="getPdf('.$rows['INVOICEID'].');"><button class="btn btn-success" type="button" style="margin-right: 5px;"><i class="fa fa-download"></i> PDF</button></a>&nbsp;|&nbsp;<a title="Delete Link" href="#'.$i.'" class="btn btn-warning" onclick="return getDelete('.$rows['INVOICEID'].');"  ><i class="fa fa-times"></i> Cancel</a></td>';
			}
			if($rows['STATUS']==1)
			{
				echo '<td align="center" valign="middle" class="input-text "><a href="updateginvoice.php?id='.$rows['INVOICEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a title="Cancel Link" href="#1" onClick="return getDelete('.$rows['INVOICEID'].');" ><button class="btn btn-danger" type="button"><i class="fa fa-times"></i> Cancel</button></a>&nbsp;|&nbsp;&nbsp;<a href="#" title="Pdf" onClick="getPdf('.$rows['INVOICEID'].');"><button class="btn btn-success" type="button" style="margin-right: 5px;"><i class="fa fa-download"></i> PDF</button></a>&nbsp;|&nbsp;<a href="#Payment" title="Payment Received" class="btn btn-default btn-sm" data-toggle="modal" data-target="#compose-modal" onClick="openWin('.$rows['INVOICEID'].','.$rows['NET_PAYABLE'].');">Payment Received</a></td>';
			}
			if($rows['STATUS']==2)
			{
				echo '<td align="center" valign="middle" class="input-text "><a href="updateginvoice.php?id='.$rows['INVOICEID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;&nbsp;<a href="#" title="Pdf" onClick="getPdf('.$rows['INVOICEID'].');"><button class="btn btn-success" type="button" style="margin-right: 5px;"><i class="fa fa-download"></i> PDF</button></a></td>';
			}
			echo '</tr>';
			$i++;
	    }
	    echo '</tbody>';
	}
	echo '</table></div>';
}

function viewGenericFinanceRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM generic_invoice_master where INVOICEID='".$id."'"; 
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['INVOICEID'];
		$this->var_2 = $rows['INVOICE_DATE'];
		$this->var_3 = $rows['I_TYPE'];
		$this->var_4 = $rows['INVOICE_NO'];
		$this->var_5 = $rows['NOB'];
		$this->var_6 = $rows['STATUS'];
		$this->var_7 = $rows['VENDOR'];
		$this->var_8 = $rows['AMOUNT'];
		$this->var_9 = $rows['NET_AMOUNT'];
		$this->var_10 = $rows['REMARKS'];
		$this->var_11 = $rows['EXCHANGE_RATE'];
		$this->var_12 = $rows['PAYMENT_TERMS'];
		$this->var_13 = $rows['NET_PAYABLE'];
		$this->var_14 = $rows['ATTEN'];
		$this->var_15 = $rows['DUE_DATE'];
		$this->var_16 = $rows['EXCHANGE_DATE'];
		$this->var_17 = $rows['EXCHANGE_CURRENCY'];
		$this->var_18 = $rows['SHIP_OWNER'];
		$this->var_19 = $rows['RDOIDENT'];
		$this->var_20 = $rows['CHKVAT'];
		$this->var_21 = $rows['CONTRACT_DETAILS'];
		$this->var_22 = $rows['CONTRACT_TYPE'];
		$this->var_23 = $rows['BUSINESSTYPEID'];
		$this->var_24 = $rows['AMOUNT_DESC'];
	}
}


function updateGenericFinancesDetails($id)
{
	$connect 			= $this->funConnect();	
	
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtInvoiceNo	    = addslashes(trim($_REQUEST['txtInvoiceNo']));
	$txtContractDetails	= addslashes(trim($_REQUEST['txtContractDetails']));
	$selContractType   	= addslashes(trim($_REQUEST['selContractType']));
	
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$selVendor	 		= addslashes(trim($_REQUEST['selVendor']));
	
	$txtInvoiceDate	 	= date("Y-m-d",strtotime($_REQUEST['txtInvoiceDate']));
	$txtDueDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	
	$txtAmountDesc	    = addslashes(trim($_REQUEST['txtAmountDesc']));
	$txtMainAmount	 	= addslashes(trim($_REQUEST['txtMainAmount']));
	$txtNetAmtPayable	= addslashes(trim($_REQUEST['txtNetAmtPayable']));
	
	$selNOB	 		    = addslashes(trim($_REQUEST['selNOB']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	$selBType           = $_REQUEST['selBType'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update generic_invoice_master set INVOICE_DATE='".$txtInvoiceDate."', INVOICE_NO='".$txtInvoiceNo."', I_TYPE='".$selIType."', NOB='".$selNOB."', STATUS='".$txtStatus."', VENDOR='".$selVendor."', AMOUNT='".$this->getCheckNullVal($txtMainAmount)."', NET_PAYABLE='".$this->getCheckNullVal($txtNetAmtPayable)."', REMARKS='".$txtDesc."', PAYMENT_TERMS='".$txtPaymentTerms."', ATTEN='".$txtAttenName."', DUE_DATE='".$txtDueDate."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', SHIP_OWNER='".$selFromOwner."', CONTRACT_DETAILS='".$txtContractDetails."', CONTRACT_TYPE='".$selContractType."', BUSINESSTYPEID='".$selBType."', AMOUNT_DESC='".$txtAmountDesc."' where INVOICEID=".$id;
	mysql_query($sql) or die($sql);
	mysql_query("commit");
		
	$sql1 = "delete from generic_invoice_slave where INVOICEID=".$id;
	$res1 = mysql_query($sql1);
	
	$txtAddID  = $_REQUEST['txtAddID'];
	for($i=1;$i<=$txtAddID;$i++)
	{
		$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
		$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
		$sql2 = "insert into generic_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$id."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
		mysql_query($sql2);
	}
	
	$txtSubID  = $_REQUEST['txtSubID'];
	for($i=1;$i<=$txtSubID;$i++)
	{
		$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
		$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
		$sql2 = "insert into generic_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$id."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
		mysql_query($sql2);
	}
	mysql_query("commit");
	return $msg;  
}


function insertGenericPaymentReceivedDetails()
{
	$connect = $this->funConnect();
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	$txtP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtP_Date']));
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update generic_invoice_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."',P_DATE='".$txtP_Date."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."' where INVOICEID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	return 2; 
}

function deletegenericInvoiceRecords()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txttblid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 3;
	
	$sql = "select * from generic_invoice_master where INVOICEID='".$id."'";
	$result = mysql_query($sql);
	while($rows = mysql_fetch_assoc($result))
	{
	
		$sql_insert = "insert into generic_invoice_master(MODULEID, MCOMPANYID, INVOICE_DATE, INVOICE_NO, I_TYPE, NOB, STATUS, VENDOR, AMOUNT, NET_PAYABLE, REMARKS, EXCHANGE_RATE, PAYMENT_TERMS, ATTEN, DUE_DATE, EXCHANGE_DATE, EXCHANGE_CURRENCY, SHIP_OWNER, CONTRACT_DETAILS, CONTRACT_TYPE, BUSINESSTYPEID, AMOUNT_DESC, P_TYPE, P_REMARKS, P_AMT, P_DATE, ATTACHMENTS, ATTACHMENTS_NAME) value('".$rows['MODULEID']."', '".$rows['MCOMPANYID']."', '".$rows['INVOICE_DATE']."', '".$rows['INVOICE_NO']."', 'Credit', '".addslashes($rows['NOB'])."', '2', '".addslashes($rows['VENDOR'])."', '".$rows['AMOUNT']."', '".$rows['NET_PAYABLE']."', '".$rows['REMARKS']."', '".$rows['EXCHANGE_RATE']."', '".$rows['PAYMENT_TERMS']."', '".$rows['ATTEN']."', '".$rows['DUE_DATE']."', '".$rows['EXCHANGE_DATE']."', '".$rows['EXCHANGE_CURRENCY']."', '".$rows['SHIP_OWNER']."', '".$rows['CONTRACT_DETAILS']."', '".addslashes($rows['CONTRACT_TYPE'])."', '".$rows['BUSINESSTYPEID']."', '".addslashes($rows['AMOUNT_DESC'])."', '".$rows['P_TYPE']."', '".$rows['P_REMARKS']."', '".$rows['P_AMT']."', '".$rows['P_DATE']."', '".$rows['ATTACHMENTS']."', '".$rows['ATTACHMENTS_NAME']."')";
		mysql_query($sql_insert);
		
		$sql_max = "select max(INVOICEID) as max from generic_invoice_master";
		$res_max = mysql_query($sql_max);
		$rows_max = mysql_fetch_assoc($res_max);
		
		$sql1 = "select * from generic_invoice_slave where INVOICEID='".$id."'";
		$result1 = mysql_query($sql1);
		while($rows1 = mysql_fetch_assoc($result1))
		{
		    $sql_isert2 = "insert into generic_invoice_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) value ('".$rows_max['max']."', '".addslashes($rows1['DESCRIPTION'])."', '".$rows1['AMOUNT']."', '".$rows1['IDENTIFY']."')";
			mysql_query($sql_isert2);
		}
		
		$sql2 = "update generic_invoice_master set STATUS=2 where INVOICEID='".$id."'";
	    mysql_query($sql2);
	}
	
	mysql_query("commit"); 
	return $msg;
}


function getUserTypeList($usertype)
{
    $state = array('internal_user' =>'Internal User', 'mgmt_user' =>'Management User');
	return $state[$usertype];
}


function getPeriodTypeList()
{
    $state = array( 1 =>'Months' , 2 =>'Days');
    echo '<option value = "" >---Select from list---</option>';
    $selCOASpot = @$_REQUEST['selCOASpot'];
	while ($array_cell = each($state)) 
	{
		$value = $array_cell['value'];
		$key = $array_cell['key'];
		
		echo "<option value=$key";
		if($key == $selCOASpot){ echo " selected";}
		echo ">".$value."</option>";
		
	}
}

function getUserAuthority($loginid, $field)
{
	$connect			= $this->funConnect();
	$query = "SELECT ".$field." FROM approval_matrix where MCOMPANYID='".$_SESSION['company']."' and LOGINID='".$loginid."'";
	$result = mysql_query($query) or die($query);
	$rows = mysql_fetch_assoc($result);
	if($rows[$field]!=1)
	{
		return 0;
	}
	else
	{
	    return 1;
	}
}

function getUsersWithAuthority($field)
{
	$connect			= $this->funConnect();
	$query = "SELECT GROUP_CONCAT(LOGINID) as USERS FROM approval_matrix where MCOMPANYID='".$_SESSION['company']."' and ".$field."=1";
	$result = mysql_query($query) or die($query);
	$rows = mysql_fetch_assoc($result);
	return explode(',',$rows['USERS']);
	
}


function saveRecentWork($workdesc)
{
    $connect = $this->funConnect();
    $sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','".addslashes($workdesc)."',NOW())";
	mysql_query($sql3) or die($sql3);
    mysql_query("commit");
}

function saveUserAlerts($sentby, $sentto, $redirectto, $identify, $comments, $identifyid)
{
    $connect = $this->funConnect();
	
    $sql3 = "insert into alert_master (ADDEDBY, ADDONDATE, SENDTO, REDIRECTTO, SHOW_STATUS, IDENTIFY, COMMENTS, IDENTIFYID, MCOMPANYID) values ('".$sentby."', NOW(), '".$sentto."', '".addslashes($redirectto)."', 1, '".$identify."', '".addslashes($comments)."', '".$identifyid."', '".$_SESSION['company']."')";
	mysql_query($sql3) or die($sql3);
    mysql_query("commit");
}

function inactiveUserAlerts($identify, $userid, $identityid)
{
    $connect = $this->funConnect();
	if($identify!='' && $userid!='' && $identityid!='')
	{
		$sql3 = "update alert_master set SHOW_STATUS=0 where IDENTIFY='".$identify."' and IDENTIFYID='".$identityid."'";
		mysql_query($sql3) or die($sql3);
		mysql_query("commit");
	}
}

function getApproverListBasedOnApprovalMatrix($fieldsname, $approvers = '')
{
    $userarr = $this->getUsersWithAuthority($fieldsname);
	$approverarr = explode(',',$approvers);
	if(!empty($userarr))
	{
	    $query = "SELECT LOGINID, CONTACT_PERSON FROM login where LOGINID in (".implode(',', $userarr).") and STATUS=1";
		$result = mysql_query($query) or die($query);
		while($rows = mysql_fetch_assoc($result))
		{
		     $key= $rows['LOGINID'];
			 $value= $rows['CONTACT_PERSON'];
			 echo '<option value="'.$key.'"';
			 if(in_array($key, $approverarr)){ echo " selected";}
			 echo '>'.$value.'</option>';
		}
	}
}


function getApproverNameBasedOnApprovalMatrix($fieldsname)
{
    $userarr = $this->getUsersWithAuthority($fieldsname);
	$userarray = array();
	if(!empty($userarr))
	{
	    $query = "SELECT LOGINID, CONTACT_PERSON FROM login where LOGINID in (".implode(',', $userarr).") and STATUS=1";
		$result = mysql_query($query) or die($query);
		while($rows = mysql_fetch_assoc($result))
		{
		     $userarray[] = $rows['CONTACT_PERSON'];
		}
	}
	return implode(', ',$userarray);
}

function getApproverNameBasedOnApprovalMatrixUnImploded($userarr)
{
	$userarray = array();
	if($userarr!='')
	{
	    $query = "SELECT LOGINID, CONTACT_PERSON FROM login where LOGINID in (".$userarr.") and STATUS=1";
		$result = mysql_query($query) or die($query);
		while($rows = mysql_fetch_assoc($result))
		{
		     $userarray[] = $rows['CONTACT_PERSON'];
		}
	}
	return implode(', ',$userarray);
}


function getMessageNumberForPeriod()
{
  $this->funConnect();
	
	$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM period_contract_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['MESSAGE_NO'];
	if($rows['MESSAGE_NO'] != NULL)
		{
		if(strlen($empcode)<=3)
			{
				$x = 3- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode ='PERIOD-'.$empcode.'-'.date("Y",time());
		}
	else
		{
			$empcode= 'PERIOD-001-'.date("Y",time());
		}
	}
	
return $empcode;
}


function insertPeriodContractDetails()
{
    $connect 			= $this->funConnect();	
	$messageno 			= explode('-',$_REQUEST['txtContract_ID'])[1];
	
	$txtContractDate	= date("Y-m-d",strtotime($_REQUEST['txtContractDate']));
	$txtStartDate 		= date("Y-m-d",strtotime($_REQUEST['txtStartDate']));
	$txtEndDate     	= date("Y-m-d",strtotime($_REQUEST['txtEndDate']));
	$txtDelDate     	= date("Y-m-d",strtotime($_REQUEST['txtDelDate']));
	$txtReDelDate     	= date("Y-m-d",strtotime($_REQUEST['txtReDelDate']));
	
	$txtMaxReDelDate    = date("Y-m-d",strtotime($_REQUEST['txtMaxReDelDate']));
	
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$upload_name = implode(',',$name);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into period_contract_master (MESSAGE_NO, CONTRACT_ID, CONTRACT_NO, CONTRACT_DATE, OWN_BUSINESS_ACCOUNT, BUSINESSTYPE, VESSEL_TYPE, VESSEL_IMO_ID, OWNER, DIS_OWNER, MANAGER_NAME, BROKER, BROKERAGE, HIRE, HIRE_REMARKS, WORKING_CURRENCY, LAYCAN_START_DATE, LAYCAN_END_DATE, DEL_PORT, DELIVERY_DATE, ADD_COMM, PERIOD_TYPE, PERIOD_MIN, PERIOD_MAX, RE_DEL_MIN_DATE, RE_DEL_PORT, TRADE_EXCLUSIONS, CARGO_EXCLUSIONS, INTERMEDIATE_HOLD_CLEANING, REMARKS, DIRTIES_ALLOWED, DIRTIES_DONE, DIRTIES_REMAINING, HOLD_CLEANING_MATERIAL, ADDNL_PREM_HRA, ILOHC, LEG_DETAILS, UPDATE_STATUS, ATTACHMENT, ATTACHMENT_NAME, MODULEID, MCOMPANYID, LOGINID, DAYS_MONTH, ABOUT_DAYS, RE_DEL_MAX_DATE, REDEL_RANGE) values ('".$messageno."', '".$_REQUEST['txtContract_ID']."', '".$_REQUEST['txtContractNo']."', '".$txtContractDate."', '".$_REQUEST['selOwnBusinessAccount']."', '".$_REQUEST['selBType']."', '".$_REQUEST['selVesselType']."', '".$_REQUEST['selVessel']."', '".$_REQUEST['selOwner']."', '".$_REQUEST['selDisOwner']."', '".$_REQUEST['txtManager']."', '".$_REQUEST['selBroker']."', '".$_REQUEST['txtBrokerage']."', '".$_REQUEST['txtHire']."', '".trim(addslashes($_REQUEST['txtHireRemarks']))."', '".$_REQUEST['selCurrency']."', '".$txtStartDate."', '".$txtEndDate."', '".$_REQUEST['selDelPort']."', '".$txtDelDate."', '".$_REQUEST['txtAddComm']."', '".$_REQUEST['selPeriodType']."', '".$_REQUEST['txtPeriodMin']."', '".$_REQUEST['txtPeriodMax']."', '".$txtReDelDate."', '".$_REQUEST['selReDelPort']."', '".trim(addslashes($_REQUEST['txtTradeExclusion']))."', '".trim(addslashes($_REQUEST['txtCargoExclusion']))."', '".trim(addslashes($_REQUEST['txtIntHoldClearing']))."', '".trim(addslashes($_REQUEST['txtRemarks']))."', '".$_REQUEST['txtDirtiesAllowed']."', '".trim(addslashes($_REQUEST['txtDirtiesDone']))."', '".trim(addslashes($_REQUEST['txtDirtiesRemaining']))."', '".trim(addslashes($_REQUEST['txtHoldCleaningMaterial']))."', '".trim(addslashes($_REQUEST['txtAddnlPremiumHRA']))."', '".trim(addslashes($_REQUEST['txtILOHC']))."', '".trim(addslashes($_REQUEST['txtLegDetails']))."', '".trim(addslashes($_REQUEST['upstatus']))."', '".$upload."', '".trim(addslashes($upload_name))."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$_SESSION['uid']."', '".$this->getCheckNullVal($_REQUEST['txtMonthDays'])."', '".$this->getCheckNullVal($_REQUEST['selAboutDays'])."', '".$txtMaxReDelDate."', '".trim(addslashes($_REQUEST['txtREDelRange']))."')";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
		
	$sql1 = "select max(PERIODID) as max from period_contract_master";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	
	$hddnOtherID = $_REQUEST['hddnOtherID'];
	for($j=1 ; $j<=$hddnOtherID ;$j++)
	{
		if($_REQUEST['txtDeliveryNotices_'.$j] != "" && $_REQUEST['txtNoticeDate_'.$j] != "")
		{
			if($_REQUEST['txtNoticeDate_'.$j]!="")
			{$txtNoticeDate    		= date("Y-m-d",strtotime($_REQUEST['txtNoticeDate_'.$j]));}
			else{$txtNoticeDate    	= "1970-01-01";}
			$sql3 = "insert into period_contract_master_slave3 (PERIODID, DELIVERY_NOTICES, DELIVERY_DATE_TIME) values ('".$rows1['max']."', '".addslashes(trim($_REQUEST['txtDeliveryNotices_'.$j]))."', '".$txtNoticeDate."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtOFFID = $_REQUEST['txtOFFID'];
	for($i=1 ; $i<=$txtOFFID ;$i++)
	{
		if($_REQUEST['txtOffHireReason_'.$i] != "")
		{
			if($_REQUEST['txtOffHireFrom_'.$i]!="")
			{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
			else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
			
			if($_REQUEST['txtOffHireTo_'.$i]!="")
			{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
			else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
			
			$sql3 = "insert into period_contract_master_slave2 (PERIODID, OFF_HIRE_REASON, OFF_HIRE_FROM, OFF_HIRE_TO, OFF_HIRE_DAYS, OFF_HIRE_RATE, OFF_HIRE_AMT) values ('".$rows1['max']."', '".$_REQUEST['txtOffHireReason_'.$i]."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
			
			$mysql14 = "select max(PERIOD_SLAVEID) as max from period_contract_master_slave2 where PERIODID='".$rows1['max']."'";
			$myres14  =  mysql_query($mysql14);
			$myrows14 = mysql_fetch_assoc($myres14);
			$maxid14 = $myrows14['max'];
			
			$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
			for($m=1 ; $m<=$txtDELID ;$m++)
			{
				if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
				{
					 if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
					$sql15 = "insert into period_contract_master_slave21 (PERIOD_SLAVEID, PERIODID, BUNKERGRADEID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, CHK_OWNER_ACCOUNT) values ('".$maxid14."', '".$rows1['max']."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
					mysql_query($sql15) or die($sql15);
					mysql_query("commit");
				}
			}
		}
	} 
	
	$txtHIREID = $_REQUEST['txtHIREID'];
	for($i=1 ; $i<=$txtHIREID ;$i++)
	{
		if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
		{
			if($_REQUEST['txtHireFrom_'.$i]!="")
			{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
			else{$txtHireFrom  		= "1970-01-01 08:00:00";}
			
			if($_REQUEST['txtHireTo_'.$i]!="")
			{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
			else{$txtHireTo  		= "1970-01-01 08:00:00";}
			
			$sql3 = "insert into period_contract_master_slave4 (PERIODID, REMARKS, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE) values ('".$maxid14."', '".addslashes(trim($_REQUEST['txtHireRemarks_'.$i]))."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtDELID = $_REQUEST['txtDELID'];
	for($j=1 ; $j<=$txtDELID ;$j++)
	{
		if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
		{
			if($_REQUEST['txtDelBunDate_'.$j]!="")
			{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
			else{$txtDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into period_contract_master_slave1 (PERIODID, BUNKERGRADEID, BUNKER_AMT, BUNKER_DATE, BUNKER_QTY, BUNKER_PRICE, IDENTITY) values ('".$rows1['max']."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtREDELID = $_REQUEST['txtREDELID'];
	for($j=1 ; $j<=$txtREDELID ;$j++)
	{
		if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
		{
			if($_REQUEST['txtReDelBunDate_'.$j]!="")
			{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
			else{$txtReDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into period_contract_master_slave1 (PERIODID, BUNKERGRADEID, BUNKER_AMT, BUNKER_DATE, BUNKER_QTY, BUNKER_PRICE, IDENTITY) values ('".$rows1['max']."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	mysql_query("commit");
	return $msg;
}


function viewPeriodContractData($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM period_contract_master where PERIODID='".$id."'"; 
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['PERIODID'];
		$this->var_2 = $rows['CONTRACT_ID'];
		$this->var_3 = $rows['CONTRACT_NO'];
		$this->var_4 = $rows['CONTRACT_DATE'];
		$this->var_5 = $rows['OWN_BUSINESS_ACCOUNT'];
		$this->var_6 = $rows['BUSINESSTYPE'];
		$this->var_7 = $rows['VESSEL_TYPE'];
		$this->var_8 = $rows['VESSEL_IMO_ID'];
		$this->var_9 = $rows['OWNER'];
		$this->var_10 = $rows['DIS_OWNER'];
		$this->var_11 = $rows['MANAGER_NAME'];
		$this->var_12 = $rows['BROKER'];
		$this->var_13 = $rows['BROKERAGE'];
		$this->var_14 = $rows['HIRE'];
		$this->var_15 = $rows['HIRE_REMARKS'];
		$this->var_16 = $rows['WORKING_CURRENCY'];
		$this->var_17 = $rows['LAYCAN_START_DATE'];
		$this->var_18 = $rows['LAYCAN_END_DATE'];
		$this->var_19 = $rows['DEL_PORT'];
		$this->var_20 = $rows['DELIVERY_DATE'];
		$this->var_21 = $rows['ADD_COMM'];
		$this->var_22 = $rows['PERIOD_TYPE'];
		$this->var_23 = $rows['PERIOD_MIN'];
		$this->var_24 = $rows['PERIOD_MAX'];
		$this->var_25 = $rows['RE_DEL_MIN_DATE'];
		$this->var_26 = $rows['RE_DEL_PORT'];
		$this->var_27 = $rows['TRADE_EXCLUSIONS'];
		$this->var_28 = $rows['CARGO_EXCLUSIONS'];
		$this->var_29 = $rows['INTERMEDIATE_HOLD_CLEANING'];
		$this->var_30 = $rows['REMARKS'];
		$this->var_31 = $rows['DIRTIES_ALLOWED'];
		$this->var_32 = $rows['DIRTIES_DONE'];
		$this->var_33 = $rows['DIRTIES_REMAINING'];
		$this->var_34 = $rows['HOLD_CLEANING_MATERIAL'];
		$this->var_35 = $rows['ADDNL_PREM_HRA'];
		$this->var_36 = $rows['ILOHC'];
		$this->var_37 = $rows['LEG_DETAILS'];
		$this->var_38 = $rows['UPDATE_STATUS'];
		$this->var_39 = $rows['ATTACHMENT'];
		$this->var_40 = $rows['ATTACHMENT_NAME'];
		$this->var_41 = $rows['DAYS_MONTH'];
		$this->var_42 = $rows['ABOUT_DAYS'];
		$this->var_43 = $rows['RE_DEL_MAX_DATE'];
		$this->var_44 = $rows['RE_DEL_MIN_DATE_1'];
		$this->var_45 = $rows['RE_DEL_MAX_DATE_1'];
		$this->var_46 = $rows['REDEL_RANGE'];
	}
}


function updatePeriodContractDetails()
{
    $connect 			= $this->funConnect();	
	//$messageno 			= explode('-',$_REQUEST['txtContract_ID'])[1];
	$id = $_REQUEST['id'];
	$txtContractDate	= date("Y-m-d",strtotime($_REQUEST['txtContractDate']));
	$txtStartDate 		= date("Y-m-d",strtotime($_REQUEST['txtStartDate']));
	$txtEndDate     	= date("Y-m-d",strtotime($_REQUEST['txtEndDate']));
	$txtDelDate     	= date("Y-m-d",strtotime($_REQUEST['txtDelDate']));
	$txtReDelDate     	= date("Y-m-d",strtotime($_REQUEST['txtReDelDate']));
	
	$txtMaxReDelDate    = date("Y-m-d",strtotime($_REQUEST['txtMaxReDelDate']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$upload_name = implode(',',$name);
	
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $upload_name != ''){ $name1 = $txtCRMNAME1.','.$upload_name;}
	else if($txtCRMNAME1 == '' && $upload_name != ''){ $name1 = $upload_name;}
	else if($txtCRMNAME1 != '' && $upload_name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update period_contract_master set CONTRACT_NO='".$_REQUEST['txtContractNo']."', CONTRACT_DATE='".$txtContractDate."', OWN_BUSINESS_ACCOUNT='".$_REQUEST['selOwnBusinessAccount']."', BUSINESSTYPE='".$_REQUEST['selBType']."', VESSEL_TYPE='".$_REQUEST['selVesselType']."', VESSEL_IMO_ID='".$_REQUEST['selVessel']."', OWNER='".$_REQUEST['selOwner']."', DIS_OWNER='".$_REQUEST['selDisOwner']."', MANAGER_NAME='".$_REQUEST['txtManager']."', BROKER='".$_REQUEST['selBroker']."', BROKERAGE='".$_REQUEST['txtBrokerage']."', HIRE='".$_REQUEST['txtHire']."', HIRE_REMARKS='".trim(addslashes($_REQUEST['txtHireRemarks']))."', WORKING_CURRENCY='".$_REQUEST['selCurrency']."', LAYCAN_START_DATE='".$txtStartDate."', LAYCAN_END_DATE='".$txtEndDate."', DEL_PORT='".$_REQUEST['selDelPort']."', DELIVERY_DATE='".$txtDelDate."', ADD_COMM='".$_REQUEST['txtAddComm']."', PERIOD_TYPE='".$_REQUEST['selPeriodType']."', PERIOD_MIN='".$_REQUEST['txtPeriodMin']."', PERIOD_MAX='".$_REQUEST['txtPeriodMax']."', RE_DEL_MIN_DATE='".$txtReDelDate."', RE_DEL_PORT='".$_REQUEST['selReDelPort']."', TRADE_EXCLUSIONS='".trim(addslashes($_REQUEST['txtTradeExclusion']))."', CARGO_EXCLUSIONS='".trim(addslashes($_REQUEST['txtCargoExclusion']))."', INTERMEDIATE_HOLD_CLEANING='".trim(addslashes($_REQUEST['txtIntHoldClearing']))."', REMARKS='".trim(addslashes($_REQUEST['txtRemarks']))."', DIRTIES_ALLOWED='".$_REQUEST['txtDirtiesAllowed']."', DIRTIES_DONE='".trim(addslashes($_REQUEST['txtDirtiesDone']))."', DIRTIES_REMAINING='".trim(addslashes($_REQUEST['txtDirtiesRemaining']))."', HOLD_CLEANING_MATERIAL='".trim(addslashes($_REQUEST['txtHoldCleaningMaterial']))."', ADDNL_PREM_HRA='".trim(addslashes($_REQUEST['txtAddnlPremiumHRA']))."', ILOHC='".trim(addslashes($_REQUEST['txtILOHC']))."', LEG_DETAILS='".trim(addslashes($_REQUEST['txtLegDetails']))."', UPDATE_STATUS='".trim(addslashes($_REQUEST['upstatus']))."', ATTACHMENT='".$upload1."', ATTACHMENT_NAME='".trim(addslashes($name1))."', DAYS_MONTH='".$this->getCheckNullVal($_REQUEST['txtMonthDays'])."', ABOUT_DAYS='".$this->getCheckNullVal($_REQUEST['selAboutDays'])."', RE_DEL_MAX_DATE='".$txtMaxReDelDate."', REDEL_RANGE='".trim(addslashes($_REQUEST['txtREDelRange']))."' where PERIODID=".$id;
	
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
		
	$sqldel1 = "delete from period_contract_master_slave1 where PERIODID=".$id;
	$sqldel2 = "delete from period_contract_master_slave2 where PERIODID=".$id;
	$sqldel21 = "delete from period_contract_master_slave21 where PERIODID=".$id;
	$sqldel3 = "delete from period_contract_master_slave3 where PERIODID=".$id;
	$sqldel4 = "delete from period_contract_master_slave4 where PERIODID=".$id;
	mysql_query($sqldel1);
	mysql_query($sqldel2);
	mysql_query($sqldel21);
	mysql_query($sqldel3);
	mysql_query($sqldel4);
	
	
	$hddnOtherID = $_REQUEST['hddnOtherID'];
	for($j=1 ; $j<=$hddnOtherID ;$j++)
	{
		if($_REQUEST['txtDeliveryNotices_'.$j] != "" && $_REQUEST['txtNoticeDate_'.$j] != "")
		{
			if($_REQUEST['txtNoticeDate_'.$j]!="")
			{$txtNoticeDate    		= date("Y-m-d",strtotime($_REQUEST['txtNoticeDate_'.$j]));}
			else{$txtNoticeDate    	= "1970-01-01";}
			$sql3 = "insert into period_contract_master_slave3 (PERIODID, DELIVERY_NOTICES, DELIVERY_DATE_TIME) values ('".$id."', '".addslashes(trim($_REQUEST['txtDeliveryNotices_'.$j]))."', '".$txtNoticeDate."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtHIREID = $_REQUEST['txtHIREID'];
	for($i=1 ; $i<=$txtHIREID ;$i++)
	{
		if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
		{
			if($_REQUEST['txtHireFrom_'.$i]!="")
			{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
			else{$txtHireFrom  		= "1970-01-01 08:00:00";}
			
			if($_REQUEST['txtHireTo_'.$i]!="")
			{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
			else{$txtHireTo  		= "1970-01-01 08:00:00";}
			
			$sql3 = "insert into period_contract_master_slave4 (PERIODID, REMARKS, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE) values ('".$id."', '".addslashes(trim($_REQUEST['txtHireRemarks_'.$i]))."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	
	$txtOFFID = $_REQUEST['txtOFFID'];
	for($i=1 ; $i<=$txtOFFID ;$i++)
	{
		if($_REQUEST['txtOffHireReason_'.$i] != "")
		{
			if($_REQUEST['txtOffHireFrom_'.$i]!="")
			{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
			else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
			
			if($_REQUEST['txtOffHireTo_'.$i]!="")
			{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
			else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
			
			$sql3 = "insert into period_contract_master_slave2 (PERIODID, OFF_HIRE_REASON, OFF_HIRE_FROM, OFF_HIRE_TO, OFF_HIRE_DAYS, OFF_HIRE_RATE, OFF_HIRE_AMT) values ('".$id."', '".addslashes(trim($_REQUEST['txtOffHireReason_'.$i]))."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
			
			$mysql14 = "select max(PERIOD_SLAVEID) as max from period_contract_master_slave2 where PERIODID='".$id."'";
			$myres14  =  mysql_query($mysql14);
			$myrows14 = mysql_fetch_assoc($myres14);
			$maxid14 = $myrows14['max'];
			
			$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
			for($m=1 ; $m<=$txtDELID ;$m++)
			{
				if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
				{
					 if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
					$sql15 = "insert into period_contract_master_slave21 (PERIOD_SLAVEID, PERIODID, BUNKERGRADEID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, CHK_OWNER_ACCOUNT) values ('".$maxid14."', '".$id."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
					mysql_query($sql15) or die($sql15);
					mysql_query("commit");
				}
			}
		}
	} 
	
	$txtDELID = $_REQUEST['txtDELID'];
	for($j=1 ; $j<=$txtDELID ;$j++)
	{
		if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
		{
			if($_REQUEST['txtDelBunDate_'.$j]!="")
			{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
			else{$txtDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into period_contract_master_slave1 (PERIODID, BUNKERGRADEID, BUNKER_AMT, BUNKER_DATE, BUNKER_QTY, BUNKER_PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	
	$txtREDELID = $_REQUEST['txtREDELID'];
	for($j=1 ; $j<=$txtREDELID ;$j++)
	{
		if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
		{
			if($_REQUEST['txtReDelBunDate_'.$j]!="")
			{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
			else{$txtReDelBunDate    	= "1970-01-01";}
			$sql3 = "insert into period_contract_master_slave1 (PERIODID, BUNKERGRADEID, BUNKER_AMT, BUNKER_DATE, BUNKER_QTY, BUNKER_PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	}
	mysql_query("commit");
	return $msg;
}


function getPeriodContractList($periodid)
{
	$this->funConnect();
	$query = "select PERIODID, CONTRACT_ID, CONTRACT_NO from period_contract_master where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' order by CONTRACT_DATE DESC";
	echo '<option value = "" >---Select from list---</option>';
	$result = mysql_query($query);
	while($rows = mysql_fetch_assoc($result))
	{
		$key = $rows['PERIODID'];
	    $value= $rows['CONTRACT_ID'].' ('.$rows['CONTRACT_NO'].')';
		
		echo '<option value="'.$key.'"';
		if($key == $periodid){ echo " selected";}
		echo ">".$value."</option>";
	}
}


function insertTCICostSheetDetails_entry()
{	
	$connect = $this->funConnect();
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 		= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	$rdoQty             = addslashes(trim($_REQUEST['rdoQty']));
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
	$txtActualPL                       = addslashes(trim($_REQUEST['txtActualPL']));
	$txtAddnlCRatePer                  = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	
	
	$selOpenPort 	 	= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 		= addslashes(trim($_REQUEST['selZone']));
	$selBroker          = addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 	= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 	= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    		= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    = addslashes(trim($_REQUEST['selOwner']));
	$txtDisponentOwner	= addslashes(trim($_REQUEST['txtDisponentOwner']));
	if($_REQUEST['txtFDate']!="")
	{
	$txtFDate     		= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	}

	else{$txtFDate     		= "1970-01-01";}
	if($_REQUEST['txtTDate']!="")
	{
	$txtTDate     		= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	}
	else{$txtTDate     		= "1970-01-01";}
	if($_REQUEST['txtETADate']!="")
	{
	$txtETADate     		= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	}
	else{$txtETADate     		= "1970-01-01";}
	if($_REQUEST['txtCPDate']!="")
	{
	$txtCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	}
	else{$txtCPDate     		= "1970-01-01";}
	$txtNotes     		= addslashes(trim($_REQUEST['txtNotes']));
	
	$txtCID 	 		= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       = addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 		= implode(',',$_REQUEST['selMType']);
	$txtMCode    		= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance	= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    = addslashes(trim($_REQUEST['selDPort']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	
	$txtTFUMTManual 		   = addslashes(trim($_REQUEST['txtTFUMTManual']));
	$txtTDUMTManual            = addslashes(trim($_REQUEST['txtTDUMTManual']));
	$txtTFOCOffHire		 	   = addslashes(trim($_REQUEST['txtTFOCOffHire']));
	$txtTDOCOffHire     	   = addslashes(trim($_REQUEST['txtTDOCOffHire']));
	$selDTCVendor       	   = addslashes(trim($_REQUEST['selDTCVendor']));
	$txtFGFFVendor       	   = addslashes(trim($_REQUEST['txtFGFFVendor']));
	
	$txtCVE           	   = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt       	   = addslashes(trim($_REQUEST['txtCVEAmt']));
	$selCVEVendor          = addslashes(trim($_REQUEST['selCVEVendor']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selBroVendor       = addslashes(trim($_REQUEST['selBroVendor']));
	$selILOHCVendor     = addslashes(trim($_REQUEST['selILOHCVendor']));
	$txtDistributedRemarks     = addslashes(trim($_REQUEST['txtDistributedRemarks']));  
	
	if(isset($_REQUEST['txtHiddenHirage']))
	{
	   $txtHiddenHirage     		= $_REQUEST['txtHiddenHirage'];
	}
	else{$txtHiddenHirage     		= $_REQUEST['txtHireargeAmt'];}
	
	if($_REQUEST['txtLCSDate']!="")
	{
	$txtLCSDate   		= date("Y-m-d",strtotime($_REQUEST['txtLCSDate']));
	}
	else{$txtLCSDate     		= "1970-01-01";}
	if($_REQUEST['txtLCFDate']!="")
	{
	$txtLCFDate     	= date("Y-m-d",strtotime($_REQUEST['txtLCFDate']));
	}
	else{$txtLCFDate     		= "1970-01-01";}
	
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$txtCRMFILE2							= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2							= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['attach_file1']);
	$name = $this->getUploadName($_FILES['attach_file1']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$selLumsumVendor 	    = addslashes(trim($_REQUEST['selLumsumVendor']));
	$txtLumpsumQty          = $_REQUEST['txtLumpsumQty'];
	
	$txtBaseRateFloating    = addslashes(trim($_REQUEST['txtBaseRateFloating']));
	$txtBaseRateFixed       = addslashes(trim($_REQUEST['txtBaseRateFixed']));
	$txtBaseRateAverage     = addslashes(trim($_REQUEST['txtBaseRateAverage']));
	
	$txtGFreightFloating    = addslashes(trim($_REQUEST['txtGFreightFloating']));
	$txtGFreightFixed       = addslashes(trim($_REQUEST['txtGFreightFixed']));
	$txtGFreightAverage     = addslashes(trim($_REQUEST['txtGFreightAverage']));
	
	$txtNFreightFloating    = addslashes(trim($_REQUEST['txtNFreightFloating']));
	$txtNFreightFixed       = addslashes(trim($_REQUEST['txtNFreightFixed']));
	$txtNFreightAverage     = addslashes(trim($_REQUEST['txtNFreightAverage']));
	
	$txtOExpensesFloating   = addslashes(trim($_REQUEST['txtOExpensesFloating']));
	$txtOExpensesFixed      = addslashes(trim($_REQUEST['txtOExpensesFixed']));
	$txtOExpensesAverage    = addslashes(trim($_REQUEST['txtOExpensesAverage']));
	
	$txtVEarningFloating    = addslashes(trim($_REQUEST['txtVEarningFloating']));
	$txtVEarningFixed       = addslashes(trim($_REQUEST['txtVEarningFixed']));
	$txtVEarningAverage     = addslashes(trim($_REQUEST['txtVEarningAverage']));
	
	$txtDailyEarningFloating= addslashes(trim($_REQUEST['txtDailyEarningFloating']));
	$txtDailyEarningFixed   = addslashes(trim($_REQUEST['txtDailyEarningFixed']));
	$txtDailyEarningAverage = addslashes(trim($_REQUEST['txtDailyEarningAverage']));
	
	$txtTCEMonthFloating    = addslashes(trim($_REQUEST['txtTCEMonthFloating']));
	$txtTCEMonthFixed       = addslashes(trim($_REQUEST['txtTCEMonthFixed']));
	$txtTCEMonthAverage     = addslashes(trim($_REQUEST['txtTCEMonthAverage']));
	
	$txtOPExpensesFloating  = addslashes(trim($_REQUEST['txtOPExpensesFloating']));
	$txtOPExpensesFixed     = addslashes(trim($_REQUEST['txtOPExpensesFixed']));
	$txtOPExpensesAverage   = addslashes(trim($_REQUEST['txtOPExpensesAverage']));
	
	$txtNetDailyEarningFloating= addslashes(trim($_REQUEST['txtNetDailyEarningFloating']));
	$txtNetDailyEarningFixed= addslashes(trim($_REQUEST['txtNetDailyEarningFixed']));
	$txtNetDailyEarningAverage= addslashes(trim($_REQUEST['txtNetDailyEarningAverage']));
	
	$txtNetDailyProfitFloating= addslashes(trim($_REQUEST['txtNetDailyProfitFloating']));
	$txtNetDailyProfitFixed = addslashes(trim($_REQUEST['txtNetDailyProfitFixed']));
	$txtNetDailyProfitAverage= addslashes(trim($_REQUEST['txtNetDailyProfitAverage']));
	$selCargoPlanning       = $_REQUEST['selCargoPlanning'];
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$rdoTankType        = addslashes(trim($_REQUEST['rdoTankType']));
	$txtTCNo                = addslashes(trim($_REQUEST['txtTCNo']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	$selPeriodContract = addslashes(trim($_REQUEST['selPeriodContract']));
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}

	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['comid'];
	$update_status       	   = addslashes(trim($_REQUEST['update_status']));
	
	$sql_fetch = "select FCAID from freight_cost_estimete_master where COMID='".$comid."' and SHEET_NO='".$sheet_no."'";
	$res_fetch = mysql_query($sql_fetch) or die($sql_fetch);
	$num_fetch = mysql_num_rows($res_fetch);
	if($num_fetch == 0)
	{
	    $year = date('Y',time());
		$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM freight_cost_estimate_compare where Year(ADD_ON_DATE) = '".$year."' and MCOMPANYID='".$_SESSION['company']."' and COAAID is NULL";
		$result = mysql_query($query) or die(mysql_error());
		$rec=mysql_num_rows($result);
		
		$year1 = $year[2].''.$year[3];
		
		while($rows = mysql_fetch_array($result))
		{
		$empcode = $rows['MESSAGE_NO'];
		if($rows['MESSAGE_NO'] != NULL)
			{
			if(strlen($empcode)<=3)
				{
					$x = 3- strlen($empcode);
					for($i = 1; $i<=$x;$i++)
						{
							$empcode = "0".$empcode;
						}
				}$empcode =$empcode;
			}
		else
			{
				$empcode= "001";
			}
		}
		
		$msg1 = $year1."-".$empcode;
	
	    $sql2 = "insert into freight_cost_estimate_compare (MESSAGE_NO, USERID, REMARKS, ADD_ON_DATE, MESSAGE, MODULEID, MCOMPANYID) values ('".$empcode."', '".$_SESSION['uid']."', '".$_REQUEST['txtDesc_'.$i]."', NOW(), '".$msg1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."')";
		mysql_query($sql2) or die($sql2);
		mysql_query("commit"); 
		$querymax1 = "SELECT MAX(COMID) as MAX FROM freight_cost_estimate_compare where MESSAGE='".$msg1."' ";
		$resultmax1 = mysql_query($querymax1) or die(mysql_error());
		$rowsmax1 = mysql_fetch_array($resultmax1);
		
	    $sql1 = "insert into cost_sheet_name_master (SHEET_NAME, COMID, MODULEID, MCOMPANYID, PROCESS) values ('".$txtVNo."', '".$rowsmax1['MAX']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'Actual')";
		mysql_query($sql1);
		mysql_query("commit");
		
		$querysheet1 = "SELECT MAX(COST_SHEETID) as MAX FROM cost_sheet_name_master where COMID='".$rowsmax1['MAX']."' ";
		$resultsheet1 = mysql_query($querysheet1) or die(mysql_error());
		$rowssheet1 = mysql_fetch_array($resultsheet1);
		
		$sql = "insert into freight_cost_estimete_master (FIXTURETYPEID, TRANS_DATE, MODULEID, MCOMPANYID, ADDED_BY, ADD_ON_DATE, VESSEL_IMO_ID, VESSEL_TYPE, FLAG, VOYAGE_NO, VOYAGE_NAME, DWT_SUMMER, DWT_TOPICAL, RDO_CAP, GRAIN_CAP, BALE_CAP, SF, LODABLE, GNRT, LOA, GEAR, BUILD_YEAR, BEAM, TPC, BFULLSPEED, BECOSPEED1, BECOSPEED2, LFULLSPEED, LECOSPEED1, LECOSPEED2, BFOFULLSPEED, BFOECOSPEED1, BFOECOSPEED2, LFOFULLSPEED, LFOECOSPEED1, LFOECOSPEED2, PIFOFULLSPEED, PWFOFULLSPEED, BDOFULLSPEED, BDOECOSPEED1, BDOECOSPEED2, LDOFULLSPEED, LDOECOSPEED1, LDOECOSPEED2, PIDOFULLSPEED, PWDOFULLSPEED, RDO_MARKER, RDO_DWT, FREIGHT_GROSS, LUMSUM, CARGO_RATE, QUANTITY, CARGO_TYPE, CARGO_ID, DF_QUANTITY, ADDNL_QUANTITY, LADEN_DIST, BALLAST_DIST, LADEN_DAYS, BALLAST_DAYS, TOTAL_PASSAGE_DAYS, IDEAL_DAYS, WORKING_DAYS, TOTAL_DAYS, TOTAL_DISTANCE, FO_CONSP, DO_CONSP, GROSS_PREIGHT_ADJ, DEAD_PREIGHT_ADJ, ADDNL_PREIGHT_ADJ, TOTAL_PREIGHT_ADJ, GROSS_PREIGHT_ADJ_PRMT, DEAD_PREIGHT_ADJ_PRMT, ADDNL_PREIGHT_ADJ_PRMT, TOTAL_PREIGHT_ADJ_PRMT, ADDRESS_COMMISSION_PER, ADDRESS_COMMISSION_AMT, ADDRESS_COMMISSION_PRMT, BROKERAGE_PER, BROKERAGE_AMT, NET_PAYABLE, FINAL_NET_FREIGHT, FINAL_NET_FREIGHT_PRMT, BROKERAGE_COMMISSION_PER, BROKERAGE_COMMISSION_AMT, TOTAL_ORC_EXP_AMT, TOTAL_ORC_EXP_PRMT, REVENUES_FREIGHT, TOTAL_OWNER_EXP, CHARTERER_EXP, VOYAGE_EARNING, DAILY_EARNING, DAILY_VESSEL_OPERATION_EXP, TOTAL_VOYAGE_EARNING, NET_DAILY_EARNING, NET_DAILY_PROFIT, PROFIT_LOSS, RDO_QTY, OPEN_PORT, ZONE_OPEN, BROKER, COA_SPOT, COA_NUMBER, COA_NUMBER_LIFT, NO_OF_SHIPMENT, OWNER, DISPONENT_OWNER, LAYCAN_START_DATE, LAYCAN_FINISH_DATE, ETA_DATE, CP_DATE, REMARKS, ATTACHMENT, ATTACHMENT_NAME, CARGOID, SHIPPER, TOLERANCE, MATERIALID, MATERIAL_CODE, TERM_TOLERANCE, LPID, DPID, LAYCAN_CARGO_START_DATE, LAYCAN_CARGO_FINISH_DATE, HIREAGE_AMT, HIREAGE_PERCENT, HIREAGE_PER_AMT, HIREAGE_NETT_AMT, QTY_TYPE_RADIO, AGREED_GROSS_FREIGHT_LOCAL, CURRENCYID, EXCHANGE_RATE, TTL_FO_CONSP_MT_MANUAL, TTL_DO_CONSP_MT_MANUAL, TTL_FO_CONSP_OFFHIRE, TTL_DO_CONSP_OFFHIRE, SHEET_NO, DTCVENDORID, FINAL_STATUS, FGFF_VENDORID, CVE_AMT, CVE_TOTALAMT, CVE_VENDORID, BALLAST_BONUS, BUNKER_EXPENSES, PORT_EXPENSES, BROKERAGE_VENDORID, ILOHC_VENDORID, HIDDEN_HIRAGE, DISTRIBUTED_REMARKS, FIXED, ADDNL_FREIGHT_PER, ESTIMATE_TYPE, GAS_MARKET, GAS_BALTIC, ADDNL_PRENIUM, GAS_BASE_RATE, GAS_QUANTITY, GAS_LUMSUM, TANK_WS_FROM, TANK_WS_TO, TANK_FIXED_DIFF, TANK_QUANTITY, ATTACHMENT2, ATTACHMENT2_NAME, CHK_LUMPSUM, LUMPSUMAMT, WS_QTY, LUMP_VENDOR, BASERATE_FLOAT, BASERATE_FIXED, BASERATE_AVERAGE, GROSS_FREIGHT_FLOAT, GROSS_FREIGHT_FIXED, GROSS_FREIGHT_AVERAGE, NETFREIGHT_FLOAT, NETFREIGHT_FIXED, NETFREIGHT_AVERAGE, OWNER_EXPENSES_FLOAT, OWNER_EXPENSES_FIXED, OWNER_EXPENSES_AVERAGE, VEARNING_FLOAT, VEARNING_FIXED, VEARNING_AVERAGE, TCEEARNING_FLOAT, TCEEARNING_FIXED, TCEEARNING_AVERAGE, TCE_MONTH_FLOAT, TCE_MONTH_FIXED, TCE_MONTH_AVERAGE, OEXPENSES_FLOAT, OEXPENSES_FIXED, OEXPENSES_AVERAGE, NET_DAILY_ER_FLOAT, NET_DAILY_ER_FIXED, NET_DAILY_ER_AVERAGE, NET_DAILY_PROFIT_FLOAT, NET_DAILY_PROFIT_FIXED, NET_DAILY_PROFIT_AVERAGE, OPEN_CARGOID, GROSS_BREAKDOWN, BREAKDOWN_MT, TANKER_RADIO_SINGLE_DIS, TC_NO, GROSS_HIERAGE_AMOUNT, HIERAGE_CVE, HIERAGE_CVE_AMOUNT, OFF_HIRE_CVE, OFF_HIRE_CVE_AMOUNT, LESS_OFF_HIRE, FINAL_HIERAGE_AMOUNT, HIERAGE_BROKER_PERCENT, HIERAGE_BROKER_AMT, TC_HIRE_DAYS, TC_CP_DATE, PERIODID, COMID, AUTO_PL) values ('".$this->getCheckNullValue($selFType)."','".$txtDate."','".$_SESSION['moduleid']."','".$this->getCheckNullValue($_SESSION['company'])."','".$_SESSION['uid']."', NOW(),'".$this->getCheckNullValue($selVName)."','".$txtVType."','".$txtFlag."','".$txtVNo."','".$txtENo."','".$this->getCheckNullValue($txtDWTS)."','".$this->getCheckNullValue($txtDWTT)."','".$this->getCheckNullValue($rdoCap)."','".$this->getCheckNullValue($txtGCap)."','".$this->getCheckNullValue($txtBCap)."','".$this->getCheckNullValue($txtSF)."','".$this->getCheckNullValue($txtLoadable)."','".$this->getCheckNullValue($txtGNRT)."','".$this->getCheckNullValue($txtLOA)."','".$txtGear."','".$txtBuiltYear."','".$this->getCheckNullValue($txtBeam)."','".$this->getCheckNullValue($txtTPC)."','".$this->getCheckNullValue($txtBFullSpeed)."','".$this->getCheckNullValue($txtBEcoSpeed1)."','".$this->getCheckNullValue($txtBEcoSpeed2)."','".$this->getCheckNullValue($txtLFullSpeed)."','".$this->getCheckNullValue($txtLEcoSpeed1)."','".$this->getCheckNullVal($txtLEcoSpeed2)."','".$this->getCheckNullVal($txtBFOFullSpeed)."','".$this->getCheckNullVal($txtBFOEcoSpeed1)."','".$this->getCheckNullVal($txtBFOEcoSpeed2)."','".$this->getCheckNullVal($txtLFOFullSpeed)."','".$this->getCheckNullVal($txtLFOEcoSpeed1)."','".$this->getCheckNullVal($txtLFOEcoSpeed2)."', '".$this->getCheckNullValue($txtPIFOFullSpeed)."', '".$this->getCheckNullValue($txtPWFOFullSpeed)."','".$this->getCheckNullValue($txtBDOFullSpeed)."','".$this->getCheckNullValue($txtBDOEcoSpeed1)."','".$this->getCheckNullVal($txtBDOEcoSpeed2)."','".$this->getCheckNullVal($txtLDOFullSpeed)."','".$this->getCheckNullVal($txtLDOEcoSpeed1)."','".$this->getCheckNullVal($txtLDOEcoSpeed2)."','".$this->getCheckNullVal($txtPIDOFullSpeed)."','".$this->getCheckNullVal($txtPWDOFullSpeed)."','".$this->getCheckNullVal($rdoMMarket)."','".$this->getCheckNullValue($rdoDWT)."','".$this->getCheckNullVal($txtMTCPDRate)."','".$this->getCheckNullVal($txtMLumpsum)."','".$this->getCheckNullVal($txtAddnlCRate)."','".$this->getCheckNullVal($txtCQMT)."','".$this->getCheckNullVal($selCType)."','".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."','".$this->getCheckNullVal($txtDFQMT)."', '".$this->getCheckNullValue($txtAddnlQMT)."', '".$this->getCheckNullValue($txtLDist)."','".$this->getCheckNullValue($txtBDist)."','".$this->getCheckNullValue($txtLDays)."','".$this->getCheckNullVal($txtBDays)."','".$this->getCheckNullVal($txtTSDays)."','".$this->getCheckNullVal($txtTtPIDays)."','".$this->getCheckNullVal($txtTtPWDays)."','".$this->getCheckNullVal($txtTDays)."','".$this->getCheckNullVal($txtTDist)."','".$this->getCheckNullVal($txtTFUMT)."', '".$this->getCheckNullVal($txtTDUMT)."','".$this->getCheckNullValue($txtFrAdjUsdGF)."','".$this->getCheckNullVal($txtFrAdjUsdDF)."','".$this->getCheckNullVal($txtFrAdjUsdAF)."','".$this->getCheckNullVal($txtFrAdjUsdTF)."','".$this->getCheckNullVal($txtFrAdjUsdGFMT)."','".$this->getCheckNullVal($txtFrAdjUsdDFMT)."','".$this->getCheckNullVal($txtFrAdjUsdAFMT)."','".$this->getCheckNullVal($txtFrAdjUsdTFMT)."',    '".$this->getCheckNullValue($txtFrAdjPerAC)."', '".$this->getCheckNullValue($txtFrAdjUsdAC)."', '".$this->getCheckNullValue($txtFrAdjUsdACMT)."','".$this->getCheckNullValue($txtFrAdjPerAgC)."','".$this->getCheckNullVal($txtFrAdjUsdAgC)."','".$this->getCheckNullVal($txtFrAdjUsdFP)."','".$this->getCheckNullVal($txtFGFFD)."','".$this->getCheckNullVal($txtFGFFDMT)."',  '".$this->getCheckNullVal($txtBrCommPercent)."','".$this->getCheckNullVal($txtBrComm)."','".$this->getCheckNullVal($txtTTLORCAmt)."', '".$this->getCheckNullVal($txtTTLORCCostMT)."','".$this->getCheckNullVal($txtRevenue)."',    '".$this->getCheckNullValue($txtTTLOwnersExpenses)."', '".$this->getCheckNullValue($txtTTLCharterersExpenses)."', '".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtDailyEarnings)."','".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."','".$this->getCheckNullVal($txtGTTLVoyageEarnings)."','".$this->getCheckNullVal($txtNettDailyEarnings)."','".$this->getCheckNullVal($txtNettDailyProfit)."',  '".$this->getCheckNullVal($txtActualPL)."', '".$this->getCheckNullVal($rdoQty)."', '".$selOpenPort."', '".$selZone."', '".$selBroker."', '".$selCOASpot."', '".$selCOA."', '".$txtNoLift."', '', '".$selOwner."', '".$txtDisponentOwner."', '".$txtFDate."', '".$txtTDate."', '".$txtETADate."', '".$txtCPDate."', '".$txtNotes."', '".$upload1."', '".$name1."', '".$txtCID."', '".$selShipper."', '".$txtTolerance."', '".$selMType."', '".$txtMCode."', '".$txtTermTolerance."', '".$selLPort."', '".$selDPort."', '".$txtLCSDate."', '".$txtLCFDate."','".$this->getCheckNullVal($txtHireargeAmt)."','".$this->getCheckNullVal($txtHireargePercent)."','".$this->getCheckNullVal($txtHireargePercentAmt)."', '".$this->getCheckNullVal($txtNettHireargeAmt)."', '".$rdoQtyType."', '".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', '".$this->getCheckNullVal($selCurrencyMarList)."', '".$this->getCheckNullVal($txtMarExchangeRate)."'   , '".$this->getCheckNullVal($txtTFUMTManual)."', '".$this->getCheckNullVal($txtTDUMTManual)."', '".$this->getCheckNullVal($txtTFOCOffHire)."', '".$this->getCheckNullVal($txtTDOCOffHire)."', '".$this->getCheckNullVal($rowssheet1['MAX'])."', '".$selDTCVendor."', '".$update_status."', '".$txtFGFFVendor."', '".$this->getCheckNullVal($txtCVE)."', '".$this->getCheckNullVal($txtCVEAmt)."', '".$this->getCheckNullVal($selCVEVendor)."'    , '".$this->getCheckNullVal($txtBallastBonus)."', '".$this->getCheckNullVal($txtTotalBunkerCost)."', '".$this->getCheckNullVal($txtTotalPortCost)."' , '".$selBroVendor."', '".$selILOHCVendor."', '".$this->getCheckNullVal($txtHiddenHirage)."', '".$txtDistributedRemarks."', 1, '".$this->getCheckNullVal($txtAddnlCRatePer)."', '".$this->getCheckNullVal($rdoEstimateType)."', '".$this->getCheckNullVal($rdoQtyMar)."', '".$this->getCheckNullVal($txtBalticRate)."', '".$this->getCheckNullVal($txtAdnlPrenium)."', '".$this->getCheckNullVal($txtBaseRate)."', '".$this->getCheckNullVal($txtGasCQMT)."', '".$this->getCheckNullVal($txtGASLumpsum)."', '".$this->getCheckNullVal($selWSFPort)."', '".$this->getCheckNullVal($selWSTPort)."', '".$this->getCheckNullVal($txtFixedDiff)."', '".$this->getCheckNullVal($txtTankQuantity)."', '".$upload2."', '".$name2."', '".$this->getCheckNullVal($ChkLumpsum)."', '".$this->getCheckNullVal($txtLumpsum)."','".$this->getCheckNullVal($txtLumpsumQty)."', '".$selLumsumVendor."', '".$this->getCheckNullVal($txtBaseRateFloating)."', '".$this->getCheckNullVal($txtBaseRateFixed)."', '".$this->getCheckNullVal($txtBaseRateAverage)."', '".$this->getCheckNullVal($txtGFreightFloating)."', '".$this->getCheckNullVal($txtGFreightFixed)."', '".$this->getCheckNullVal($txtGFreightAverage)."', '".$this->getCheckNullVal($txtNFreightFloating)."', '".$this->getCheckNullVal($txtNFreightFixed)."', '".$this->getCheckNullVal($txtNFreightAverage)."', '".$this->getCheckNullVal($txtOExpensesFloating)."', '".$this->getCheckNullVal($txtOExpensesFixed)."', '".$this->getCheckNullVal($txtOExpensesAverage)."', '".$this->getCheckNullVal($txtVEarningFloating)."', '".$this->getCheckNullVal($txtVEarningFixed)."', '".$this->getCheckNullVal($txtVEarningAverage)."', '".$this->getCheckNullVal($txtDailyEarningFloating)."', '".$this->getCheckNullVal($txtDailyEarningFixed)."', '".$this->getCheckNullVal($txtDailyEarningAverage)."', '".$this->getCheckNullVal($txtTCEMonthFloating)."', '".$this->getCheckNullVal($txtTCEMonthFixed)."', '".$this->getCheckNullVal($txtTCEMonthAverage)."', '".$this->getCheckNullVal($txtOPExpensesFloating)."', '".$this->getCheckNullVal($txtOPExpensesFixed)."', '".$this->getCheckNullVal($txtOPExpensesAverage)."', '".$this->getCheckNullVal($txtNetDailyEarningFloating)."', '".$this->getCheckNullVal($txtNetDailyEarningFixed)."', '".$this->getCheckNullVal($txtNetDailyEarningAverage)."', '".$this->getCheckNullVal($txtNetDailyProfitFloating)."', '".$this->getCheckNullVal($txtNetDailyProfitFixed)."', '".$this->getCheckNullVal($txtNetDailyProfitAverage)."', '".$this->getCheckNullVal($selCargoPlanning)."', '".$this->getCheckNullVal($txtGrossBreakeven)."', '".$this->getCheckNullVal($txtBreakevenMT)."', '".$this->getCheckNullVal($rdoTankType)."', '".$txtTCNo."', '".$this->getCheckNullVal($txtGrossHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeCVE)."', '".$this->getCheckNullVal($txtHireargeCVEAMT)."', '".$this->getCheckNullVal($txtOffHireCVE)."', '".$this->getCheckNullVal($txtOffHireCVEAMT)."', '".$this->getCheckNullVal($txtLessOffHire)."', '".$this->getCheckNullVal($txtFinalHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeBroPercent)."', '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', '".$this->getCheckNullVal($txtTotalVoyageDays)."', '".$txtTC_CPDate."', '".$this->getCheckNullValue($selPeriodContract)."', '".$rowsmax1['MAX']."', '".$this->getCheckNullValue($txtPL)."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(FCAID) as max from freight_cost_estimete_master";
		$myres  =  mysql_query($mysql,$connect);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
		
		$sql = "update freight_cost_estimate_compare set STATUS=5, FCAID='".$myrows['max']."', FINAL_ID='".$myrows['max']."' where COMID='".$rowsmax1['MAX']."' ";
		mysql_query($sql);	
		mysql_query("commit");	
		
	}else{
	    $rows_fetch = mysql_fetch_assoc($res_fetch);
		$maxid = $rows_fetch['FCAID'];
	    
		$sql = "update freight_cost_estimete_master set FIXTURETYPEID='".$this->getCheckNullValue($selFType)."', TRANS_DATE='".$txtDate."', MODULEID='".$this->getCheckNullValue($_SESSION['moduleid'])."', MCOMPANYID='".$this->getCheckNullValue($_SESSION['company'])."', ADDED_BY='".$_SESSION['uid']."', VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', VESSEL_TYPE='".$txtVType."', FLAG='".$txtFlag."', VOYAGE_NO='".$txtVNo."', VOYAGE_NAME='".$txtENo."', DWT_SUMMER='".$this->getCheckNullValue($txtDWTS)."', DWT_TOPICAL='".$this->getCheckNullValue($txtDWTT)."', RDO_CAP='".$this->getCheckNullValue($rdoCap)."', GRAIN_CAP='".$this->getCheckNullValue($txtGCap)."', BALE_CAP='".$this->getCheckNullValue($txtBCap)."', SF='".$this->getCheckNullValue($txtSF)."', LODABLE='".$this->getCheckNullValue($txtLoadable)."', GNRT='".$this->getCheckNullValue($txtGNRT)."', LOA='".$this->getCheckNullValue($txtLOA)."', GEAR='".$txtGear."', BUILD_YEAR='".$txtBuiltYear."', BEAM='".$this->getCheckNullValue($txtBeam)."', TPC='".$this->getCheckNullValue($txtTPC)."', BFULLSPEED='".$this->getCheckNullValue($txtBFullSpeed)."', BECOSPEED1='".$this->getCheckNullValue($txtBEcoSpeed1)."', BECOSPEED2='".$this->getCheckNullValue($txtBEcoSpeed2)."', LFULLSPEED='".$this->getCheckNullValue($txtLFullSpeed)."', LECOSPEED1='".$this->getCheckNullValue($txtLEcoSpeed1)."', LECOSPEED2='".$this->getCheckNullVal($txtLEcoSpeed2)."', BFOFULLSPEED='".$this->getCheckNullVal($txtBFOFullSpeed)."', BFOECOSPEED1='".$this->getCheckNullVal($txtBFOEcoSpeed1)."', BFOECOSPEED2='".$this->getCheckNullVal($txtBFOEcoSpeed2)."', LFOFULLSPEED='".$this->getCheckNullVal($txtLFOFullSpeed)."', LFOECOSPEED1='".$this->getCheckNullVal($txtLFOEcoSpeed1)."', LFOECOSPEED2='".$this->getCheckNullVal($txtLFOEcoSpeed2)."', PIFOFULLSPEED='".$this->getCheckNullValue($txtPIFOFullSpeed)."', PWFOFULLSPEED='".$this->getCheckNullValue($txtPWFOFullSpeed)."', BDOFULLSPEED='".$this->getCheckNullValue($txtBDOFullSpeed)."', BDOECOSPEED1='".$this->getCheckNullValue($txtBDOEcoSpeed1)."', BDOECOSPEED2='".$this->getCheckNullVal($txtBDOEcoSpeed2)."', LDOFULLSPEED='".$this->getCheckNullVal($txtLDOFullSpeed)."', LDOECOSPEED1='".$this->getCheckNullVal($txtLDOEcoSpeed1)."', LDOECOSPEED2='".$this->getCheckNullVal($txtLDOEcoSpeed2)."', PIDOFULLSPEED='".$this->getCheckNullVal($txtPIDOFullSpeed)."', PWDOFULLSPEED='".$this->getCheckNullVal($txtPWDOFullSpeed)."', RDO_MARKER='".$this->getCheckNullVal($rdoMMarket)."', RDO_DWT='".$this->getCheckNullValue($rdoDWT)."', FREIGHT_GROSS='".$this->getCheckNullVal($txtMTCPDRate)."', LUMSUM='".$this->getCheckNullVal($txtMLumpsum)."', CARGO_RATE='".$this->getCheckNullVal($txtAddnlCRate)."', QUANTITY='".$this->getCheckNullVal($txtCQMT)."', CARGO_TYPE='".$this->getCheckNullVal($selCType)."', CARGO_ID='".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."', DF_QUANTITY='".$this->getCheckNullVal($txtDFQMT)."', ADDNL_QUANTITY='".$this->getCheckNullValue($txtAddnlQMT)."', LADEN_DIST='".$this->getCheckNullValue($txtLDist)."', BALLAST_DIST='".$this->getCheckNullValue($txtBDist)."', LADEN_DAYS='".$this->getCheckNullValue($txtLDays)."', BALLAST_DAYS='".$this->getCheckNullVal($txtBDays)."', TOTAL_PASSAGE_DAYS='".$this->getCheckNullVal($txtTSDays)."', IDEAL_DAYS='".$this->getCheckNullVal($txtTtPIDays)."', WORKING_DAYS='".$this->getCheckNullVal($txtTtPWDays)."', TOTAL_DAYS='".$this->getCheckNullVal($txtTDays)."', TOTAL_DISTANCE='".$this->getCheckNullVal($txtTDist)."', FO_CONSP='".$this->getCheckNullVal($txtTFUMT)."', DO_CONSP='".$this->getCheckNullVal($txtTDUMT)."', GROSS_PREIGHT_ADJ='".$this->getCheckNullValue($txtFrAdjUsdGF)."', DEAD_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdDF)."', ADDNL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdAF)."', TOTAL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdTF)."', GROSS_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdGFMT)."', DEAD_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdDFMT)."', ADDNL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdAFMT)."', TOTAL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdTFMT)."', ADDRESS_COMMISSION_PER='".$this->getCheckNullValue($txtFrAdjPerAC)."', ADDRESS_COMMISSION_AMT='".$this->getCheckNullValue($txtFrAdjUsdAC)."', ADDRESS_COMMISSION_PRMT='".$this->getCheckNullValue($txtFrAdjUsdACMT)."', BROKERAGE_PER='".$this->getCheckNullValue($txtFrAdjPerAgC)."', BROKERAGE_AMT='".$this->getCheckNullVal($txtFrAdjUsdAgC)."', NET_PAYABLE='".$this->getCheckNullVal($txtFrAdjUsdFP)."', FINAL_NET_FREIGHT='".$this->getCheckNullVal($txtFGFFD)."', FINAL_NET_FREIGHT_PRMT='".$this->getCheckNullVal($txtFGFFDMT)."', BROKERAGE_COMMISSION_PER='".$this->getCheckNullVal($txtBrCommPercent)."', BROKERAGE_COMMISSION_AMT='".$this->getCheckNullVal($txtBrComm)."', TOTAL_ORC_EXP_AMT='".$this->getCheckNullVal($txtTTLORCAmt)."', TOTAL_ORC_EXP_PRMT='".$this->getCheckNullVal($txtTTLORCCostMT)."', REVENUES_FREIGHT='".$this->getCheckNullVal($txtRevenue)."', TOTAL_OWNER_EXP='".$this->getCheckNullValue($txtTTLOwnersExpenses)."', CHARTERER_EXP='".$this->getCheckNullValue($txtTTLCharterersExpenses)."', VOYAGE_EARNING='".$this->getCheckNullValue($txtVoyageEarnings)."', DAILY_EARNING='".$this->getCheckNullValue($txtDailyEarnings)."', DAILY_VESSEL_OPERATION_EXP='".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."', TOTAL_VOYAGE_EARNING='".$this->getCheckNullVal($txtGTTLVoyageEarnings)."', NET_DAILY_EARNING='".$this->getCheckNullVal($txtNettDailyEarnings)."', NET_DAILY_PROFIT='".$this->getCheckNullVal($txtNettDailyProfit)."', PROFIT_LOSS='".$this->getCheckNullVal($txtActualPL)."', RDO_QTY='".$this->getCheckNullVal($rdoQty)."', OPEN_PORT='".$selOpenPort."', ZONE_OPEN='".$selZone."', BROKER='".$selBroker."', COA_SPOT='".$selCOASpot."', COA_NUMBER='".$selCOA."', COA_NUMBER_LIFT='".$txtNoLift."', NO_OF_SHIPMENT='', OWNER='".$selOwner."', DISPONENT_OWNER='".$txtDisponentOwner."', LAYCAN_START_DATE='".$txtFDate."', LAYCAN_FINISH_DATE='".$txtTDate."', ETA_DATE='".$txtETADate."', CP_DATE='".$txtCPDate."', REMARKS='".$txtNotes."', ATTACHMENT='".$upload1."', ATTACHMENT_NAME='".$name1."', CARGOID='".$txtCID."', SHIPPER='".$selShipper."', TOLERANCE='".$txtTolerance."', MATERIALID='".$selMType."', MATERIAL_CODE='".$txtMCode."', TERM_TOLERANCE='".$txtTermTolerance."', LPID='".$selLPort."', DPID='".$selDPort."', LAYCAN_CARGO_START_DATE='".$txtLCSDate."', LAYCAN_CARGO_FINISH_DATE='".$txtLCFDate."', HIREAGE_AMT='".$this->getCheckNullVal($txtHireargeAmt)."', HIREAGE_PERCENT='".$this->getCheckNullVal($txtHireargePercent)."', HIREAGE_PER_AMT='".$this->getCheckNullVal($txtHireargePercentAmt)."', HIREAGE_NETT_AMT='".$this->getCheckNullVal($txtNettHireargeAmt)."', QTY_TYPE_RADIO='".$rdoQtyType."', AGREED_GROSS_FREIGHT_LOCAL='".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', CURRENCYID='".$this->getCheckNullVal($selCurrencyMarList)."', EXCHANGE_RATE='".$this->getCheckNullVal($txtMarExchangeRate)."', TTL_FO_CONSP_MT_MANUAL='".$this->getCheckNullVal($txtTFUMTManual)."', TTL_DO_CONSP_MT_MANUAL='".$this->getCheckNullVal($txtTDUMTManual)."', TTL_FO_CONSP_OFFHIRE='".$this->getCheckNullVal($txtTFOCOffHire)."', TTL_DO_CONSP_OFFHIRE='".$this->getCheckNullVal($txtTDOCOffHire)."', DTCVENDORID='".$selDTCVendor."', FINAL_STATUS='".$update_status."', FGFF_VENDORID='".$txtFGFFVendor."', CVE_AMT='".$this->getCheckNullVal($txtCVE)."', CVE_TOTALAMT='".$this->getCheckNullVal($txtCVEAmt)."', CVE_VENDORID='".$this->getCheckNullVal($selCVEVendor)."', BALLAST_BONUS='".$this->getCheckNullVal($txtBallastBonus)."', BUNKER_EXPENSES='".$this->getCheckNullVal($txtTotalBunkerCost)."', PORT_EXPENSES='".$this->getCheckNullVal($txtTotalPortCost)."', BROKERAGE_VENDORID='".$selBroVendor."', ILOHC_VENDORID='".$selILOHCVendor."', HIDDEN_HIRAGE='".$this->getCheckNullVal($txtHiddenHirage)."',  DISTRIBUTED_REMARKS='".$txtDistributedRemarks."', FIXED=1, ESTIMATE_TYPE='".$this->getCheckNullVal($rdoEstimateType)."', GAS_MARKET='".$this->getCheckNullVal($rdoQtyMar)."', GAS_BALTIC='".$this->getCheckNullVal($txtBalticRate)."', ADDNL_PRENIUM='".$this->getCheckNullVal($txtAdnlPrenium)."', GAS_BASE_RATE='".$this->getCheckNullVal($txtBaseRate)."', GAS_QUANTITY='".$this->getCheckNullVal($txtGasCQMT)."', GAS_LUMSUM='".$this->getCheckNullVal($txtGASLumpsum)."', TANK_WS_FROM='".$this->getCheckNullVal($selWSFPort)."', TANK_WS_TO='".$this->getCheckNullVal($selWSTPort)."', TANK_FIXED_DIFF='".$this->getCheckNullVal($txtFixedDiff)."', TANK_QUANTITY='".$this->getCheckNullVal($txtTankQuantity)."', ATTACHMENT2='".$upload2."', ATTACHMENT2_NAME='".$name2."', CHK_LUMPSUM='".$this->getCheckNullVal($ChkLumpsum)."', LUMPSUMAMT='".$this->getCheckNullVal($txtLumpsum)."', WS_QTY='".$this->getCheckNullVal($txtLumpsumQty)."', LUMP_VENDOR ='".$selLumsumVendor."', BASERATE_FLOAT='".$this->getCheckNullVal($txtBaseRateFloating)."', BASERATE_FIXED='".$this->getCheckNullVal($txtBaseRateFixed)."', BASERATE_AVERAGE='".$this->getCheckNullVal($txtBaseRateAverage)."', GROSS_FREIGHT_FLOAT='".$this->getCheckNullVal($txtGFreightFloating)."', GROSS_FREIGHT_FIXED='".$this->getCheckNullVal($txtGFreightFixed)."', GROSS_FREIGHT_AVERAGE='".$this->getCheckNullVal($txtGFreightAverage)."', NETFREIGHT_FLOAT='".$this->getCheckNullVal($txtNFreightFloating)."', NETFREIGHT_FIXED='".$this->getCheckNullVal($txtNFreightFixed)."', NETFREIGHT_AVERAGE='".$this->getCheckNullVal($txtNFreightAverage)."', OWNER_EXPENSES_FLOAT='".$this->getCheckNullVal($txtOExpensesFloating)."', OWNER_EXPENSES_FIXED='".$this->getCheckNullVal($txtOExpensesFixed)."', OWNER_EXPENSES_AVERAGE='".$this->getCheckNullVal($txtOExpensesAverage)."', VEARNING_FLOAT='".$this->getCheckNullVal($txtVEarningFloating)."', VEARNING_FIXED='".$this->getCheckNullVal($txtVEarningFixed)."', VEARNING_AVERAGE='".$this->getCheckNullVal($txtVEarningAverage)."', TCEEARNING_FLOAT='".$this->getCheckNullVal($txtDailyEarningFloating)."', TCEEARNING_FIXED='".$this->getCheckNullVal($txtDailyEarningFixed)."', TCEEARNING_AVERAGE='".$this->getCheckNullVal($txtDailyEarningAverage)."', TCE_MONTH_FLOAT='".$this->getCheckNullVal($txtTCEMonthFloating)."', TCE_MONTH_FIXED='".$this->getCheckNullVal($txtTCEMonthFixed)."', TCE_MONTH_AVERAGE='".$this->getCheckNullVal($txtTCEMonthAverage)."', OEXPENSES_FLOAT='".$this->getCheckNullVal($txtOPExpensesFloating)."', OEXPENSES_FIXED='".$this->getCheckNullVal($txtOPExpensesFixed)."', OEXPENSES_AVERAGE='".$this->getCheckNullVal($txtOPExpensesAverage)."', NET_DAILY_ER_FLOAT='".$this->getCheckNullVal($txtNetDailyEarningFloating)."', NET_DAILY_ER_FIXED='".$this->getCheckNullVal($txtNetDailyEarningFixed)."', NET_DAILY_ER_AVERAGE='".$this->getCheckNullVal($txtNetDailyEarningAverage)."', NET_DAILY_PROFIT_FLOAT='".$this->getCheckNullVal($txtNetDailyProfitFloating)."', NET_DAILY_PROFIT_FIXED='".$this->getCheckNullVal($txtNetDailyProfitFixed)."', NET_DAILY_PROFIT_AVERAGE='".$this->getCheckNullVal($txtNetDailyProfitAverage)."', OPEN_CARGOID='".$this->getCheckNullVal($selCargoPlanning)."', SUMMERDWTMT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMERDWTLT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMERDRAFTM='".$this->getCheckNullVal($txtSDraftM)."', SUMMERDRAFTFT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANT_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANT_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFTM='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CBFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', GROSS_BREAKDOWN='".$this->getCheckNullVal($txtGrossBreakeven)."', BREAKDOWN_MT='".$this->getCheckNullVal($txtBreakevenMT)."', TANKER_RADIO_SINGLE_DIS='".$this->getCheckNullVal($rdoTankType)."', TC_NO='".$txtTCNo."', GROSS_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtGrossHireargeAmt)."', HIERAGE_CVE='".$this->getCheckNullVal($txtHireargeCVE)."', HIERAGE_CVE_AMOUNT='".$this->getCheckNullVal($txtHireargeCVEAMT)."', OFF_HIRE_CVE='".$this->getCheckNullVal($txtOffHireCVE)."', OFF_HIRE_CVE_AMOUNT='".$this->getCheckNullVal($txtOffHireCVEAMT)."', LESS_OFF_HIRE='".$this->getCheckNullVal($txtLessOffHire)."', FINAL_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtFinalHireargeAmt)."', HIERAGE_BROKER_PERCENT= '".$this->getCheckNullVal($txtHireargeBroPercent)."', HIERAGE_BROKER_AMT= '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', TC_HIRE_DAYS='".$this->getCheckNullVal($txtTotalVoyageDays)."', TC_CP_DATE='".$txtTC_CPDate."', PERIODID='".$this->getCheckNullValue($selPeriodContract)."', AUTO_PL='".$this->getCheckNullValue($txtPL)."' where FCAID='".$maxid."'";
		
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$del_query2 = "delete from  freight_cost_estimete_slave1 where FCAID='".$maxid."'";
		$del_query3 = "delete from  freight_cost_estimete_slave2 where FCAID='".$maxid."'";
		$del_query4 = "delete from  freight_cost_estimete_slave3 where FCAID='".$maxid."'";
		$del_query5 = "delete from  freight_cost_estimete_slave4 where FCAID='".$maxid."'";
		$del_query6 = "delete from  freight_cost_estimete_slave5 where FCAID='".$maxid."'";
		$del_query7 = "delete from  freight_cost_estimete_slave6 where FCAID='".$maxid."'";
		$del_query8 = "delete from  freight_cost_estimete_slave7 where FCAID='".$maxid."'";
		$del_query9 = "delete from  freight_cost_estimete_slave8 where FCAID='".$maxid."'";
		$del_query10 = "delete from  freight_cost_estimete_slave10 where FCAID='".$maxid."'";
		$del_query11 = "delete from  freight_cost_estimete_slave11 where FCAID='".$maxid."'";
		$del_query12 = "delete from  freight_cost_estimete_slave12 where FCAID='".$maxid."'";
		$del_query13 = "delete from  freight_cost_estimete_slave13 where FCAID='".$maxid."'";
		$del_query14 = "delete from  freight_cost_estimete_slave14 where FCAID='".$maxid."'";
		$del_query15 = "delete from  freight_cost_estimete_slave15 where FCAID='".$maxid."'";
		$del_query15 = "delete from  freight_cost_estimete_slave16 where FCAID='".$maxid."'";
		mysql_query($del_query2);
		mysql_query($del_query3);
		mysql_query($del_query4);
		mysql_query($del_query5);
		mysql_query($del_query6);
		mysql_query($del_query7);
		mysql_query($del_query8);
		mysql_query($del_query9);
		mysql_query($del_query10);
		mysql_query($del_query11);
		mysql_query($del_query12);
		mysql_query($del_query13);
		mysql_query($del_query14);
		mysql_query($del_query15);
		mysql_query($del_query16);
		mysql_query("commit");
		
	}
		
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{   
		    $randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql1 = "insert into freight_cost_estimete_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, PORT_COSTLP_VENDOR, DDCLP_COMM, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_VENDOR, DDCLP_NETCOST, DDCDP_COMM, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_VENDOR, DDCDP_NETCOST, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, PORT_COSTTP_VENDOR, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."' ,'".$_REQUEST['selLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$_REQUEST['selDDCLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$_REQUEST['selDDCDPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['selDPVendor_'.$i]."', '".$_REQUEST['ChkShowDDCLP_'.$i]."', '".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$_REQUEST['selTPVendor_'.$i]."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtRateUSDmt_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] != "")
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."', 1, '".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtRateUSDmt2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] != "")
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtRateUSDmt3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] != "")
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, VENDORID, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$_REQUEST['selQtyVendor3_'.$i]."', '".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
			$sql10 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT, VENDORID ) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selORCVendor_'.$i])."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
			$sql120 = "insert into freight_cost_estimete_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT, VENDORID) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOtherIncVendor_'.$i])."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."', '".$_REQUEST['selBrCommVendor_'.$i]."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		$txtTID = $_REQUEST['txtTID'];
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtDisponentOwner_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_slave5 (FCAID, DISPONENT_OWNER) values ('".$maxid."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$p_locationID = $_REQUEST['p_locationID'];
		for($i=1 ; $i<=$p_locationID ;$i++)
		{
			if($_REQUEST['txtFromLocation_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_slave6 (FCAID, LOCATION_FROM, LOCATION_TO, PASSAGE_TYPE, SPEED_TYPE, DISTANCE) values ('".$maxid."', '".$_REQUEST['txtFromLocation_'.$i]."','".$_REQUEST['txtToLocation_'.$i]."','".$this->getCheckNullVal($_REQUEST['selPLocationType_'.$i])."','".$this->getCheckNullVal($_REQUEST['selSLocationSpeed_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtLocationDistance_'.$i])."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$txtQTYID = $_REQUEST['txtQTYID'];
		for($i=1 ; $i<=$txtQTYID ;$i++)
		{
			if($_REQUEST['selQtyVendorList_'.$i] != "")
			{
			    $randomid = $_REQUEST['txtQtySlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtQtySlaveRandomID_'.$i]) || $_REQUEST['txtQtySlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql2 = "insert into freight_cost_estimete_slave7 (FCAID, QTY_VENDORID, AGREED_GROSS_FREIGHT, QUANTITY, GROSS_FREIGHT, BROKERAGE, NET_BROKERAGE, NET_FREIGHT, NET_FREIGHT_PERMT, CURRENCYID, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, CARGO, RANDOMID) values ('".$maxid."','".$_REQUEST['selQtyVendorList_'.$i]."','".$_REQUEST['txtQtyAggriedFreight_'.$i]."','".$_REQUEST['txtFreightQty_'.$i]."','".$_REQUEST['txtQtyFreight_'.$i]."','".$_REQUEST['txtQtyBrokeragePer_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtQtyBrokerageAmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreightMT1_'.$i])."','".$this->getCheckNullVal($_REQUEST['selCurrencyDisList_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyLocalAggriedFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDisExchangeRate_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selQtyCargo_'.$i])."', '".$randomid."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		} 
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1;$i<=$txtOFFID;$i++)
		{
			if($_REQUEST['txtFromOff_'.$i]!='' && $_REQUEST['txtOffHireReason_'.$i]!='')
			{
				$sql10 = "insert into freight_cost_estimete_slave10 (FCAID, OFFHIRE_REASON, FROM_OFF_DATE, TO_OFF_DATE, OFF_HIRE_DAYS) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtOffHireReason_'.$i]))."','".date('Y-m-d H:i',strtotime($_REQUEST['txtFromOff_'.$i]))."' ,'".date('Y-m-d H:i',strtotime($_REQUEST['txtToOff_'.$i]))."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."')";
				mysql_query($sql10) or die($sql10);
				mysql_query("commit");
			}
		}
		
		$txtNoOfInvoice = $_REQUEST['txtNoOfInvoice'];
		for($i=1;$i<=$txtNoOfInvoice;$i++)
		{
			if($_REQUEST['txtInvoiceID_'.$i]!='')
			{
				$sql11 = "insert into freight_cost_estimete_slave11 (INVOICEID, FCAID) values ('".addslashes(trim($_REQUEST['txtInvoiceID_'.$i]))."', '".$maxid."' )";
				mysql_query($sql11) or die($sql11);
				mysql_query("commit");
			}
		}
		
		$txtTankID = $_REQUEST['txtTankID'];
		for($i=1 ; $i<=$txtTankID ;$i++)
		{
			if($_REQUEST['txtFreightSpecs_'.$i] != "")
			{
				$sql12 = "insert into freight_cost_estimete_slave12 (FCAID, FREIGHT_SPECS, CUSTOMER, MIN_CARGO_QTY, OVE_CARGO_QTY, MIN_FLAT_RATE, OVE_FLAT_RATE, MIN_WS, OVE_WS, MIN_DIS_LEG, OVE_DIS_LEG, MIN_DISTANCE, OVE_DISTANCE, MIN_AMOUNT, OVE_AMOUNT, TOTAL_QTY, TOTAL_AMOUNT) values ('".$maxid."', '".$_REQUEST['txtFreightSpecs_'.$i]."', '".$_REQUEST['selTankVendor_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtMinCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtOveCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinDisLeg_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveDisLeg_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinTotalDis_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveTotalDis_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinAmount_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtTotalTankQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTotalTankAmount_'.$i])."')";
				mysql_query($sql12) or die($sql12);
				mysql_query("commit");
			}
		} 
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$maxid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_slave14 where FCAID='".$maxid."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg; 
}



function createCombinedSOA()
{
    $connect 			= $this->funConnect();
	$soa_no             = $this->getMessageNumberForCombinedSOA();	
	$soa_serialNo 		= explode('-',$soa_no)[1];
	$soa_date       	= date("Y-m-d",time());
	$txtRemarks         = trim(addslashes($_REQUEST['txtRemarks']));
	
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$upload_name = implode(',',$name);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into combined_soa_master (SOA_DATE, SOA_NO, SOA_SERIAL_NO, UPLOAD, UPLOAD_NAME, CREATOR, REMARKS, STATUS) values ('".$soa_date."', '".$soa_no."', '".$soa_serialNo."', '".$upload."', '".$upload_name."', '".$_SESSION['uid']."', '".$txtRemarks."', '0')";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
		
	$sql1 = "select max(SOAID) as max from combined_soa_master";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	foreach($_REQUEST['chkSelect'] as $chkSelect)
	{
		if($_REQUEST['txtInvoiceID_'.$chkSelect] != "")
		{
			$txtInvoiceID     		= $_REQUEST['txtInvoiceID_'.$chkSelect];
			$txtInvoiceType 	    = trim(addslashes($_REQUEST['txtInvoiceType_'.$chkSelect]));
			$txtAmountPaid   	    = trim(addslashes($_REQUEST['txtAmountPaid_'.$chkSelect]));
			$txtRemarks     	    = trim(addslashes($_REQUEST['txtRemarks_'.$chkSelect]));
			
			$sql3 = "insert into combined_soa_slave (SOAID, INVOICEID, INVOICE_TYPE, REMARKS, AMOUNT_SANCTIONED, SOA_STATUS) values ('".$rows1['max']."', '".$txtInvoiceID."', '".$txtInvoiceType."', '".$txtRemarks."', '".$this->getCheckNullValue($txtAmountPaid)."', '0')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	} 
	
	$this->saveRecentWork("Combined SOA (".$soa_no.") Created Successfully.");
	mysql_query("commit");
	return $rows1['max'];
}


function viewCombinedSOAData($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM combined_soa_master where SOAID='".$id."'"; 
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['SOAID'];
		$this->var_2 = $rows['SOA_DATE'];
		$this->var_3 = $rows['SOA_NO'];
		$this->var_4 = $rows['UPLOAD'];
		$this->var_5 = $rows['UPLOAD_NAME'];
		$this->var_6 = $rows['CREATOR'];
		$this->var_7 = $rows['APPROVERS'];
		$this->var_8 = $rows['ACC_USER'];
		$this->var_9 = $rows['REMARKS'];
		$this->var_10 = $rows['STATUS'];		
	}
}


function updateCombinedSOA()
{
    $connect 			= $this->funConnect();	
	$id = $_REQUEST['id'];
	$txtRemarks         = trim(addslashes($_REQUEST['txtRemarks']));
	$txtStatus          = $_REQUEST['txtStatus'];
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$upload_name = implode(',',$name);
	
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $upload_name != ''){ $name1 = $txtCRMNAME1.','.$upload_name;}
	else if($txtCRMNAME1 == '' && $upload_name != ''){ $name1 = $upload_name;}
	else if($txtCRMNAME1 != '' && $upload_name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$query_sel = "SELECT * FROM combined_soa_master where SOAID='".$id."'"; 
	$result_sel = mysql_query($query_sel);
	$rows_sel = mysql_fetch_assoc($result_sel);
	
	if($txtStatus ==0 || $txtStatus ==1)
	{
		$approversel = implode(',',$_REQUEST['selApprovers']);
	}else
	{
		$approversel = $rows_sel['APPROVERS'];
	}
	
	if($txtStatus == 5)
	{
		$accountuser = $_SESSION['uid'];
	}else
	{
	    $accountuser = $rows_sel['ACC_USER'];
	}
	$creatorloginid = $rows_sel['CREATOR'];
	
	$sql = "update combined_soa_master set REMARKS='".$txtRemarks."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', APPROVERS='".$approversel."', STATUS='".$txtStatus."', ACC_USER='".$accountuser."' where SOAID=".$id;
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql = "delete from combined_soa_slave where SOAID='".$id."'";
	mysql_query($sql) or die($sql);
	
	foreach($_REQUEST['chkSelect'] as $chkSelect)
	{
		if($_REQUEST['txtInvoiceID_'.$chkSelect] != "")
		{
			$txtInvoiceID     		= $_REQUEST['txtInvoiceID_'.$chkSelect];
			$txtInvoiceType 	    = trim(addslashes($_REQUEST['txtInvoiceType_'.$chkSelect]));
			$txtAmountPaid   	    = trim(addslashes($_REQUEST['txtAmountPaid_'.$chkSelect]));
			$txtRemarks     	    = trim(addslashes($_REQUEST['txtRemarks_'.$chkSelect]));
			
			$sql3 = "insert into combined_soa_slave (SOAID, INVOICEID, INVOICE_TYPE, REMARKS, AMOUNT_SANCTIONED, SOA_STATUS) values ('".$id."', '".$txtInvoiceID."', '".$txtInvoiceType."', '".$txtRemarks."', '".$this->getCheckNullValue($txtAmountPaid)."', '0')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
			
			if($txtStatus == 6)
		    {
			    if($txtInvoiceType == "HIRE STATEMENT")
				{
			    	$sql4 = "update invoice_hire_master set P_AMT='".$this->getCheckNullValue($txtAmountPaid)."', P_DATE='".date('Y-m-d',time())."', P_REMARKS='".$txtRemarks."' where INVOICEID='".$txtInvoiceID."'";
					$this->inactiveUserAlerts('HIRE STATEMENT', $_SESSION['uid'], $txtInvoiceID);
				}
				if($txtInvoiceType == "PAYMENT")
				{
			    	$sql4 = "update request_master set P_AMT='".$this->getCheckNullValue($txtAmountPaid)."', P_DATE='".date('Y-m-d',time())."', P_REMARKS='".$txtRemarks."' where REQ_ID='".$txtInvoiceID."'";
					$this->inactiveUserAlerts('PAYMENT', $_SESSION['uid'], $txtInvoiceID);
				}
				if($txtInvoiceType == "TC HIRE STATEMENT")
				{
			    	$sql4 = "update invoice_hiretc_master set P_AMT='".$this->getCheckNullValue($txtAmountPaid)."', P_DATE='".date('Y-m-d',time())."', P_REMARKS='".$txtRemarks."' where INVOICEID='".$txtInvoiceID."'";
					$this->inactiveUserAlerts('TC HIRE STATEMENT', $_SESSION['uid'], $txtInvoiceID);
				}
				if($txtInvoiceType == "TC PAYMENT")
				{
			    	$sql4 = "update payment_tcother_master set P_AMT='".$this->getCheckNullValue($txtAmountPaid)."', P_DATE='".date('Y-m-d',time())."', P_REMARKS='".$txtRemarks."' where PAYMENTID='".$txtInvoiceID."'";
					$this->inactiveUserAlerts('OTHER TC PAYMENT', $_SESSION['uid'], $txtInvoiceID);
				}
				mysql_query($sql4) or die($sql4);
				mysql_query("commit");
			}
		}
	} 
	
	mysql_query("commit");
	
	
	$this->saveRecentWork("Combined SOA (".$rows_sel['SOA_NO'].") Updated Successfully.");
	
	$this->inactiveUserAlerts('COMBINED SOA', $_SESSION['uid'], $id);
	
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	$approverarr2 = $this->getUsersWithAuthority('SOA_CHK_APP_2');
	$approverarraccount2 = $this->getUsersWithAuthority('SOA_CHK_ACC');
	
	$url = './updatecombinedsoa.php?id='.$id;
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'COMBINED SOA';
	
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($_REQUEST['comid'],"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($id != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$rows_sel['SOA_NO'].') for Level 1 Approval', $id);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$rows_sel['SOA_NO'].') for Review', $id);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$rows_sel['SOA_NO'].') for Review', $id);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$rows_sel['SOA_NO'].') for Level 2 Approval', $id);				  
				  }
			 }
		}
		
		/*if($txtStatus == 3)
		{
		     if(!empty($approverarraccount2))
			 {
			     $userarray = $approverarraccount2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' Approved '.$invtitleType.' ('.$rows_sel['SOA_NO'].')', $invoiceidd);				  
				  }
			 }
		}*/
	}
	
	
	return $msg;
}


function getMessageNumberForCombinedSOA()
{
  $this->funConnect();
	$query = "SELECT (MAX(SOA_SERIAL_NO) + 1) as SOA_SERIAL_NO FROM combined_soa_master where YEAR(SOA_DATE)='".date('Y',time())."'";
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['SOA_SERIAL_NO'];
	if($rows['SOA_SERIAL_NO'] != NULL)
		{
		if(strlen($empcode)<=4)
			{
				$x = 4- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode ='SOA-'.$empcode.'-'.date("Y",time());
		}
	else
		{
			$empcode= 'SOA-0001-'.date("Y",time());
		}
	}
	
return $empcode;
}


function getRemarksFromCompTable($comid,$identityid)
{
  $this->funConnect();
	$query = "SELECT REMARKS FROM com_report_master where COMID='".$comid."' and IDENTITYID='".$identityid."'";
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	$rows = mysql_fetch_array($result);
	
    return $rows['REMARKS'];
}

function getRemarksFromCompTableSlave($comid, $identityid, $subidentity)
{
  $this->funConnect();
	$query = "SELECT REMARKS FROM com_report_slave where COMID='".$comid."' and IDENTITYID='".$identityid."' and SUB_IDENTITY='".$subidentity."'";
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	$rows = mysql_fetch_array($result);
	
    return $rows['REMARKS'];
}

function insertSheetComRecords()
{
    $connect 			= $this->funConnect();	
	
	$txtRowCount        = $_REQUEST['txtRowCount'];
	$txtIdentity8ID        = $_REQUEST['txtIdentity8ID'];
	$txtCOMID           = $_REQUEST['txtCOMID'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "delete from com_report_master where COMID='".$txtCOMID."'";
	mysql_query($sql) or die($sql);
	
	$sql1 = "delete from com_report_slave where COMID='".$txtCOMID."'";
	mysql_query($sql1) or die($sql1);
	mysql_query("commit");
	
	for($i=1;$i<=$txtRowCount;$i++)
	{
		$txtRemarks             = trim(addslashes($_REQUEST['txtRemarks_'.$i]));
		$txtIdentity     		= trim(addslashes($_REQUEST['txtIdentity_'.$i]));
		if($_REQUEST['txtIdentity_'.$i]!='')
		{
			$sql3 = "insert into com_report_master (COMID, IDENTITY, REMARKS, IDENTITYID) values ('".$txtCOMID."', '".$txtIdentity."', '".$txtRemarks."', '".$i."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	} 
	
	for($i=1;$i<=$txtIdentity8ID;$i++)
	{
		$txtRemarks             = trim(addslashes($_REQUEST['txtRemarks_8_'.$i]));
		$txtIdentity     		= trim(addslashes($_REQUEST['txtIdentity_8_'.$i]));
		
		$sql3 = "insert into com_report_slave (IDENTITYID, SUB_IDENTITY, REMARKS, COMID) values ('8', '".$txtIdentity."', '".$txtRemarks."', '".$txtCOMID."')";
		mysql_query($sql3) or die($sql3);
		mysql_query("commit");
	} 	
	return $msg;
}


function insertTCCostSheetDetails_entry()
{	
	$connect = $this->funConnect(); 
	
	/*-------------------------\\\\\\-----START TC ESTIMATE------------/////////--------------------------------------*/
	$cost_sheet_id              = $_REQUEST['cost_sheet_id'];
	$comid                      = $_REQUEST['comid'];
	$txtTotalUdays				= addslashes(trim($_REQUEST['txtTotalUdays']));
	$txtTotalVoyageEarning		= addslashes(trim($_REQUEST['txtTotalVoyageEarning']));
	
	$selVName                   = addslashes(trim($_REQUEST['selVName']));
	$txtVType                   = addslashes(trim($_REQUEST['txtVType']));
	$txtFlag                    = addslashes(trim($_REQUEST['txtFlag']));
	$date	 				    = date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCPdate2	 				= date("Y-m-d",strtotime($_REQUEST['txtCPdate2']));
	$txtTCNo                    = addslashes(trim($_REQUEST['txtTCNo']));
	$selOwner                   = addslashes(trim($_REQUEST['selOwner']));
	$selCharterer               = addslashes(trim($_REQUEST['selCharterer']));
	$txtDelRangePort            = addslashes(trim($_REQUEST['txtDelRangePort']));
	$txtCargoQty                = addslashes(trim($_REQUEST['txtCargoQty']));
	$selCargo                   = addslashes(trim($_REQUEST['selCargo']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	
	
	$sql_fetch = "select TCOUTID from chartering_estimate_tc_master where COMID='".$comid."' and SHEET_NO='".$cost_sheet_id."'";
	$res_fetch = mysql_query($sql_fetch) or die($sql_fetch);
	$num_fetch = mysql_num_rows($res_fetch);
	if($num_fetch == 0)
	{
	    $year = date('Y',time());
		$query = "SELECT (MAX(MESSAGE_NO) + 1) as MESSAGE_NO FROM chartering_estimate_tc_compare where Year(ADD_ON_DATE) = '".$year."' and MCOMPANYID='".$_SESSION['company']."'";
		$result = mysql_query($query) or die(mysql_error());
		$rec=mysql_num_rows($result);
		
		$year1 = $year[2].''.$year[3];
		
		while($rows = mysql_fetch_array($result))
		{
		$empcode = $rows['MESSAGE_NO'];
		if($rows['MESSAGE_NO'] != NULL)
			{
			if(strlen($empcode)<=3)
				{
					$x = 3- strlen($empcode);
					for($i = 1; $i<=$x;$i++)
						{
							$empcode = "0".$empcode;
						}
				}$empcode =$empcode;
			}
		else
			{
				$empcode= "001";
			}
		}
		
		$msg1 = $year1."-".$empcode;
	
	    $sql2 = "insert into chartering_estimate_tc_compare (MESSAGE_NO, USERID, REMARKS, ADD_ON_DATE, MESSAGE, MODULEID, MCOMPANYID) values ('".$empcode."', '".$_SESSION['uid']."', '".$_REQUEST['txtDesc_'.$i]."', NOW(), '".$msg1."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."')";
		mysql_query($sql2) or die($sql2);
		mysql_query("commit"); 
		$querymax1 = "SELECT MAX(COMID) as MAX FROM chartering_estimate_tc_compare where MESSAGE='".$msg1."' ";
		$resultmax1 = mysql_query($querymax1) or die(mysql_error());
		$rowsmax1 = mysql_fetch_array($resultmax1);
		
	    $sql1 = "insert into cost_sheettc_name_master (SHEET_NAME, COMID, MODULEID, MCOMPANYID, PROCESS) values ('".$txtTCNo."', '".$rowsmax1['MAX']."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'Actual')";
		mysql_query($sql1);
		mysql_query("commit");
		
		$querysheet1 = "SELECT MAX(COST_SHEETID) as MAX FROM cost_sheettc_name_master where COMID='".$rowsmax1['MAX']."' ";
		$resultsheet1 = mysql_query($querysheet1) or die(mysql_error());
		$rowssheet1 = mysql_fetch_array($resultsheet1);
		
		$sql = "insert into chartering_estimate_tc_master (MODULEID, MCOMPANYID, FIXTURE_TYPE, VESSEL_IMO_ID, VESSEL_TYPE, FLAG, TC_DATE, TC_NO, CP_DATE1, SEL_CHARTERER, COMID, UPDATE_ON_DATE, FINAL_DATETIME, FINAL_STATUS, FIXED, ESTIMATE_TYPE, SHEET_NO, TOTAL_DAYS, TOTAL_EARNING, OWNER, CARGO_QTY, DEL_RANGE_PORT, CARGO) values ('".$_SESSION['moduleid']."', '".$this->getCheckNullValue($_SESSION['company'])."', '', '".$this->getCheckNullValue($selVName)."', '".$txtVType."', '".$txtFlag."', '".$date."', '".$txtTCNo."', '".$txtCPdate2."', '".$selCharterer."', '".$rowsmax1['MAX']."', NOW(), NOW(), 1, 1, 3, '".$rowssheet1['MAX']."', '".$this->getCheckNullValue($txtTotalUdays)."', '".$this->getCheckNullValue($txtTotalVoyageEarning)."', '".$selOwner."', '".$txtCargoQty."', '".$txtDelRangePort."', '".$this->getCheckNullValue($selCargo)."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(TCOUTID) as max from chartering_estimate_tc_master";
		$myres  =  mysql_query($mysql,$connect);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
		
		$sql = "update chartering_estimate_tc_compare set STATUS=5, TCOUTID='".$myrows['max']."', FINAL_ID='".$myrows['max']."' where COMID='".$rowsmax1['MAX']."' ";
		mysql_query($sql);	
		mysql_query("commit");	
		
	}else{
	    $rows_fetch = mysql_fetch_assoc($res_fetch);
		$maxid = $rows_fetch['TCOUTID'];
	    
		$sql = "update chartering_estimate_tc_master set VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', VESSEL_TYPE='".$txtVType."', FLAG='".$txtFlag."', TC_DATE='".$date."', TC_NO='".$txtTCNo."', CP_DATE1='".$txtCPdate2."', SEL_CHARTERER='".$selCharterer."', UPDATE_ON_DATE=NOW(), TOTAL_DAYS='".$this->getCheckNullValue($txtTotalUdays)."', TOTAL_EARNING='".$this->getCheckNullValue($txtTotalVoyageEarning)."', OWNER='".$selOwner."', CARGO_QTY='".$txtCargoQty."', DEL_RANGE_PORT='".$txtDelRangePort."', CARGO='".$this->getCheckNullValue($selCargo)."' where TCOUTID='".$maxid."'";
		
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysqsel = "select TC_SLAVE1ID from chartering_tc_estimate_slave1 where TCOUTID='".$maxid."'";
		$myressel  =  mysql_query($mysqsel,$connect);
		$myrowssel = mysql_fetch_assoc($myressel);
		$slaveid = $myrowssel['TC_SLAVE1ID'];
		
		$del_query2 = "delete from  chartering_tc_estimate_slave1 where TCOUTID='".$maxid."'";
		mysql_query($del_query2);
		if($slaveid!='')
		{
		    $del_query3 = "delete from  chartering_estimate_tc_slave2 where TC_SLAVE1ID='".$slaveid."'";
			$del_query4 = "delete from  chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$slaveid."'";
			$del_query5 = "delete from  chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$slaveid."'";
			$del_query6 = "delete from  chartering_tc_estimate_slave3 where TC_SLAVE1ID='".$slaveid."'";
			$del_query7 = "delete from  chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$slaveid."'";
			$del_query8 = "delete from  chartering_tc_estimate_slave5 where TC_SLAVE1ID='".$slaveid."'";
			$del_query9 = "delete from  chartering_tc_estimate_slave2 where TC_SLAVE1ID='".$slaveid."'";
			$del_query10 = "delete from  chartering_estimate_tc_slave7 where TC_SLAVE1ID='".$slaveid."'";
			mysql_query($del_query3);
			mysql_query($del_query4);
			mysql_query($del_query5);
			mysql_query($del_query6);
			mysql_query($del_query7);
			mysql_query($del_query8);
			mysql_query($del_query9);
			mysql_query($del_query10);
		}
		
		mysql_query("commit");
		
	}
	
	
	$txtTripID                  = addslashes(trim($_REQUEST['txtTripID']));
	for($i =1;$i<=$txtTripID;$i++)
	{
		if(isset($_REQUEST['txtDeldate_'.$i]))
		{
			$txtTCdays					= addslashes(trim($_REQUEST['txtTCdays_'.$i]));
			$txtUtilisationDays			= addslashes(trim($_REQUEST['txtUtilisationDays_'.$i]));			
			$selExchangeCurrency		= addslashes(trim($_REQUEST['selExchangeCurrency_'.$i]));
			$txtExchangeRate			= addslashes(trim($_REQUEST['txtExchangeRate_'.$i]));
			$txtDailyGrossHireUSD		= addslashes(trim($_REQUEST['txtDailyGrossHireUSD_'.$i]));
			$txtBallastBonusAMT 		= addslashes(trim($_REQUEST['txtBallastBonusAMT_'.$i]));
			$txtAddCommPerct			= addslashes(trim($_REQUEST['txtAddCommPerct_'.$i]));
			$txtAddComm1				= addslashes(trim($_REQUEST['txtAddComm1_'.$i]));
			$txtChartererAcc			= addslashes(trim($_REQUEST['txtChartererAcc_'.$i]));
			$selAddCommVendor			= addslashes(trim($_REQUEST['selAddCommVendor_'.$i]));
			$txtBrokerComm				= addslashes(trim($_REQUEST['txtBrokerComm_'.$i]));
			$selBroCommVendor			= addslashes(trim($_REQUEST['selBroCommVendor_'.$i]));
			$txtNettHire				= addslashes(trim($_REQUEST['txtNettHire_'.$i]));
			$txtNettRev					= addslashes(trim($_REQUEST['txtNettRev_'.$i]));
			$txtLessOffHire				= addslashes(trim($_REQUEST['txtLessOffHire_'.$i]));
			$txtCVE						= addslashes(trim($_REQUEST['txtCVE_'.$i]));
			$txtOtherIncome				= addslashes(trim($_REQUEST['txtOtherIncome_'.$i]));
			$txtTotalRev	    		= addslashes(trim($_REQUEST['txtTotalRev_'.$i]));
			$selESTtcVendor	    		= addslashes(trim($_REQUEST['selESTtcVendor_'.$i]));
			
			$txtTotalExpenses			= addslashes(trim($_REQUEST['txtTotalExpenses_'.$i]));

			$txtVoyageEarnings			= addslashes(trim($_REQUEST['txtVoyageEarnings_'.$i]));
			$txtProfitPerDay			= addslashes(trim($_REQUEST['txtProfitPerDay_'.$i]));
			
			$txtTCPerDay    			= addslashes(trim($_REQUEST['txtTCPerDay_'.$i]));
			$txtTotalHireage			= addslashes(trim($_REQUEST['txtTotalHireage_'.$i]));
			$txtAddComm     			= addslashes(trim($_REQUEST['txtAddComm_'.$i]));
			$txtAddCommAmt   			= addslashes(trim($_REQUEST['txtAddCommAmt_'.$i]));
			$txtNetHireage  			= addslashes(trim($_REQUEST['txtNetHireage_'.$i]));
			$selTcInExpVendor  			= addslashes(trim($_REQUEST['selTcInExpVendor_'.$i]));
			$txtCVEM        			= addslashes(trim($_REQUEST['txtCVEM_'.$i]));
			$txtNETHire        			= addslashes(trim($_REQUEST['txtNETHire_'.$i]));
			
			if($_REQUEST['txtTCCPDate_'.$i]!="")
			{$txtTCCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCCPDate_'.$i]));}
			else{$txtTCCPDate  		= "1970-01-01";}
			$txtTCDeliveryPort        	= addslashes(trim($_REQUEST['txtTCDeliveryPort_'.$i]));
			$txtTCReDeliveryPort		= addslashes(trim($_REQUEST['txtTCReDeliveryPort_'.$i]));
			$txtTCOffHireCVE        	= addslashes(trim($_REQUEST['txtTCOffHireCVE_'.$i]));
			$txtTCOffHireCVEAMT			= addslashes(trim($_REQUEST['txtTCOffHireCVEAMT_'.$i]));
			$txtTCBunkerOnOwnerAmt      = addslashes(trim($_REQUEST['txtTCBunkerOnOwnerAmt_'.$i]));
			$txtTCLessOffHire  			= addslashes(trim($_REQUEST['txtTCLessOffHire_'.$i]));
			$txtFinalHireargeAmt		= addslashes(trim($_REQUEST['txtFinalHireargeAmt_'.$i]));
			$selTCVendor      			= addslashes(trim($_REQUEST['selTCVendor_'.$i]));
			$txtTCCPNumber     			= addslashes(trim($_REQUEST['txtTCCPNumber_'.$i]));
			
			if($_REQUEST['txtDeldate_'.$i]!="")
			{$txtDeldate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtDeldate_'.$i]));}
			else{$txtDeldate  		= "1970-01-01 08:00:00";}
			
			if($_REQUEST['txtReDeldate_'.$i]!="")
			{$txtReDeldate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtReDeldate_'.$i]));}
			else{$txtReDeldate  		= "1970-01-01 08:00:00";}
			
			$randomid = $_REQUEST['txtCOUTSlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtCOUTSlaveRandomID_'.$i]) || $_REQUEST['txtCOUTSlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			
			
			$sql1 = "insert into chartering_tc_estimate_slave1 (TCOUTID, TRIP_TC_EST, PERIOD_TC_EST, NO_OF_TRIP_EST, CP_TYPE_EST, CHARTERERS_EST, DEL_DATE_EST, REDEL_DATE_EST, TC_DAYS_EST, UTILISATION_DAY_EST, DAILY_GROSS_HIRE_EST, EXCHANGE_CURRENCY, EXCHANGE_RATE, ADD_COMM_EST, ADD_COMM_CAL_EST, ADD_COMM_VENDOR, BROKER_COMM_EST, BROKER_COMM_CAL_EST, BROKER_COMM_VENDOR, NETT_HIRE_EST, NETT_REV_EST, LESS_OFF_HIRE_EST, CVE_EST, OTHER_INCOME_EST, TOTAL_REV_EST, TTL_REV_VENDOR, TOTAL_EXP_EST, VOYAGE_EARN_EST, PROFIT_PER_DAY_EST, UPDATE_ON_DATE, BUNKER_DIFF_AMT, RANDOMID, TC_RATE, TOTAL_HIREAGE, ADD_COMM, ADD_COMM_AMT, NET_HIREAGE, NET_HIR_VENDOR, CVE_MONTH, NET_HIRE_AMT, TC_CP_DATE, TC_PORT_DELIVERY, TC_PORT_REDELIVERY, TC_CVE_MONTH_OFFHIRE, TC_CVE_AMOUNT_OFFHIRE, TC_BUNKERS_ON_OWNER, TC_OFF_HIRE, TC_FINAL_HIERAGE, TC_FINAL_HIERAGE_VENDOR, TC_CP_NUMBER, BALLAST_BONUS_AMT) values ('".$maxid."','".$txtTripTC1."','".$txtPeriod1."','".$this->getCheckNullValue($txtNoOfTrips1)."','".$this->getCheckNullValue($txtCPType)."','".$this->getCheckNullValue($txtCharterers)."','".$txtDeldate."','".$txtReDeldate."','".$this->getCheckNullValue($txtTCdays)."','".$this->getCheckNullValue($txtUtilisationDays)."','".$this->getCheckNullValue($txtDailyGrossHireUSD)."','".$this->getCheckNullValue($selExchangeCurrency)."','".$txtExchangeRate."','".$this->getCheckNullValue($txtAddCommPerct)."','".$this->getCheckNullValue($txtAddComm1)."','".$this->getCheckNullValue($selAddCommVendor)."','".$this->getCheckNullValue($txtChartererAcc)."','".$this->getCheckNullValue($txtBrokerComm)."','".$this->getCheckNullValue($selBroCommVendor)."','".$this->getCheckNullValue($txtNettHire)."','".$this->getCheckNullValue($txtNettRev)."','".$this->getCheckNullValue($txtLessOffHire)."','".$this->getCheckNullValue($txtCVE)."','".$this->getCheckNullValue($txtOtherIncome)."','".$this->getCheckNullValue($txtTotalRev)."','".$this->getCheckNullValue($selESTtcVendor)."','".$this->getCheckNullValue($txtTotalExpenses)."','".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtProfitPerDay)."',NOW(),'".$this->getCheckNullValue($txtBunkerDifference)."','".$this->getCheckNullValue($randomid)."','".$this->getCheckNullValue($txtTCPerDay)."','".$this->getCheckNullValue($txtTotalHireage)."','".$this->getCheckNullValue($txtAddComm)."','".$this->getCheckNullValue($txtAddCommAmt)."','".$this->getCheckNullValue($txtNetHireage)."', '".$this->getCheckNullValue($selTcInExpVendor)."', '".$this->getCheckNullValue($txtCVEM)."', '".$this->getCheckNullValue($txtNETHire)."', '".$txtTCCPDate."', '".$txtTCDeliveryPort."', '".$txtTCReDeliveryPort."', '".$this->getCheckNullValue($txtTCOffHireCVE)."', '".$this->getCheckNullValue($txtTCOffHireCVEAMT)."', '".$this->getCheckNullValue($txtTCBunkerOnOwnerAmt)."', '".$this->getCheckNullValue($txtTCLessOffHire)."', '".$this->getCheckNullValue($txtFinalHireargeAmt)."', '".$selTCVendor."', '".$txtTCCPNumber."', '".$this->getCheckNullValue($txtBallastBonusAMT)."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
			
			$mysql = "select max(TC_SLAVE1ID) as max from chartering_tc_estimate_slave1 where TCOUTID='".$maxid."'";
			$myres  =  mysql_query($mysql,$connect);
			$myrows = mysql_fetch_assoc($myres);
			$maxslaveid = $myrows['max'];
			
			
			$hddnOtherID = $_REQUEST['hddnOtherID_'.$i];
			for($j=1 ; $j<=$hddnOtherID ;$j++)
			{
				if($_REQUEST['txtOtherIncome_'.$i.'_'.$j] != "")
				{
					$sql3 = "insert into chartering_estimate_tc_slave2 (TC_SLAVE1ID, DESCRIPTION, OTHER_AMT, OTHER_EXP_VENDOR, STATUS) values ('".$maxslaveid."', '".$_REQUEST['txtOtherIncomeText_'.$i.'_'.$j]."', '".$this->getCheckNullValue($_REQUEST['txtOtherIncome_'.$i.'_'.$j])."', '".addslashes(trim($_REQUEST['selOthIncVendor_'.$i.'_'.$j]))."', 1)";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
				}
			} 
			
			$hddnOtherExID = $_REQUEST['hddnOtherExID_'.$i];
			for($j=1 ; $j<=$hddnOtherExID ;$j++)
			{
				if($_REQUEST['txtOtherExpense_'.$i.'_'.$j] != "")
				{
					if(isset($_REQUEST['ChkAddToTTL_'.$i.'_'.$j])){$ChkAddToTTL = $_REQUEST['ChkAddToTTL_'.$i.'_'.$j]; }else{$ChkAddToTTL = 0;}
					
					$sql3 = "insert into chartering_estimate_tc_slave2 (TC_SLAVE1ID, EXPENSETYPEID, DESCRIPTION, CHK_ADDTTL, OTHER_AMT, OTHER_EXP_VENDOR, STATUS) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selExpenseType_'.$i.'_'.$j])."', '".addslashes(trim($_REQUEST['txtExpenseDesc_'.$i.'_'.$j]))."', '".$ChkAddToTTL."', '".$this->getCheckNullValue($_REQUEST['txtOtherExpense_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selOthExpVendor_'.$i.'_'.$j])."', 2)";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
				}
			} 
			
			$txtOFFID = $_REQUEST['txtOFFID_'.$i];
			for($j=1 ; $j<=$txtOFFID ;$j++)
			{
				if($_REQUEST['txtOffHireReason_'.$i.'_'.$j] != "")
				{
					if($_REQUEST['txtOffHireFrom_'.$i.'_'.$j]!="")
					{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i.'_'.$j]));}
					else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtOffHireTo_'.$i.'_'.$j]!="")
					{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i.'_'.$j]));}
					else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
					$sql3 = "insert into chartering_estimate_tc_slave3 (TC_SLAVE1ID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE) values ('".$maxslaveid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i.'_'.$j])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i.'_'.$j])."')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
					
					$mysqlmax4 = "select max(TC_SLAVE3ID) as max from chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$maxslaveid."'";
					$myresmax4  =  mysql_query($mysqlmax4) or die($mysqlmax4);
					$myrowsmax4 = mysql_fetch_assoc($myresmax4);
					$mslave4id = $myrowsmax4['max'];
					
					$txtOFFConBunkerCount_ = $_REQUEST['txtOFFConBunkerCount_'.$i.'_'.$j];
					for($l=1 ; $l<=$txtOFFConBunkerCount_;$l++)
					{
						if(isset($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l]))
						{
							if($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l] != "" && $_REQUEST['txtConBunkerQty_'.$i.'_'.$j.'_'.$l] != "" && $_REQUEST['txtConBunkerAmt_'.$i.'_'.$j.'_'.$l] != "")
							{   
								$sql7 = "insert into chartering_estimate_tc_slave7 (TC_SLAVE3ID, TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT) values ('".$mslave4id."', '".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selConBunker_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerQty_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerPrice_'.$i.'_'.$j.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtConBunkerAmt_'.$i.'_'.$j.'_'.$l])."')";
								mysql_query($sql7) or die($sql7);
								mysql_query("commit");
							}
						}
					}
				}
			}
			
			$txtDELID = $_REQUEST['txtDELID_'.$i];
			for($j=1 ; $j<=$txtDELID ;$j++)
			{
				if($_REQUEST['selDelBunker_'.$i.'_'.$j] != "" && $_REQUEST['txtDelQty_'.$i.'_'.$j] != "")
				{
					if($_REQUEST['txtDelBunDate_'.$i.'_'.$j]!="")
					{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$i.'_'.$j]));}
					else{$txtDelBunDate    	= "1970-01-01";}
					$sql3 = "insert into chartering_estimate_tc_slave5 (TC_SLAVE1ID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$i.'_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$i.'_'.$j])."', 'DEL')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
				}
			}
			
			$txtREDELID = $_REQUEST['txtREDELID_'.$i];
			for($j=1 ; $j<=$txtREDELID ;$j++)
			{
				if($_REQUEST['selReDelBunker_'.$i.'_'.$j] != "" && $_REQUEST['txtReDelQty_'.$i.'_'.$j] != "")
				{
					if($_REQUEST['txtReDelBunDate_'.$i.'_'.$j]!="")
					{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$i.'_'.$j]));}
					else{$txtReDelBunDate    	= "1970-01-01";}
					$sql3 = "insert into chartering_estimate_tc_slave5 (TC_SLAVE1ID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$i.'_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$i.'_'.$j])."', 'REDEL')";
					mysql_query($sql3) or die($sql3);
					mysql_query("commit");
				}
			}
			
			
			$txtTCDELID = $_REQUEST['txtTCDELID_'.$i];
			for($k=1 ; $k<=$txtTCDELID ;$k++)
			{
				if(isset($_REQUEST['selTCDelBunker_'.$i.'_'.$k]))
				{
					if($_REQUEST['selTCDelBunker_'.$i.'_'.$k] != "" && $_REQUEST['txtTCDelQty_'.$i.'_'.$k] != "" && $_REQUEST['txtTCDelAmount_'.$i.'_'.$k] != "")
					{
						if($_REQUEST['txtTCDelBunDate_'.$i.'_'.$k]!="")
						{$txtTCDelBunDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCDelBunDate_'.$i.'_'.$k]));}
						else{$txtTCDelBunDate  		= "1970-01-01";}
						
						$sql4 = "insert into chartering_tc_estimate_slave3 (TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_DATE, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCDelBunker_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCDelQty_'.$i.'_'.$k])."', '".$txtTCDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtTCDelPrice_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCDelAmount_'.$i.'_'.$k])."', 'DEL')";
						mysql_query($sql4) or die($sql4);
						mysql_query("commit");
					}
				}
			}
			
			$txtTCREDELID = $_REQUEST['txtTCREDELID_'.$i];
			for($k=1 ; $k<=$txtTCREDELID ;$k++)
			{
				if(isset($_REQUEST['selTCReDelBunker_'.$i.'_'.$k]))
				{
					if($_REQUEST['selTCReDelBunker_'.$i.'_'.$k] != "" && $_REQUEST['txtTCReDelQty_'.$i.'_'.$k] != "" && $_REQUEST['txtTCReDelAmount_'.$i.'_'.$k] != "")
					{
						if($_REQUEST['txtTCReDelBunDate_'.$i.'_'.$k]!="")
						{$txtTCReDelBunDate     		= date("Y-m-d",strtotime($_REQUEST['txtTCReDelBunDate_'.$i.'_'.$k]));}
						else{$txtTCReDelBunDate  		= "1970-01-01";}
						
						$sql5 = "insert into chartering_tc_estimate_slave3 (TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_DATE, BUNKER_PRICE, BUNKER_AMT, IDENTIFY) values ('".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCReDelBunker_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelQty_'.$i.'_'.$k])."', '".$txtTCReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelPrice_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCReDelAmount_'.$i.'_'.$k])."', 'REDEL')";
						mysql_query($sql5) or die($sql5);
						mysql_query("commit");
					}
				}
			}
			
			
			$txtTCOFFID = $_REQUEST['txtTCOFFID_'.$i];
			for($k=1 ; $k<=$txtTCOFFID ;$k++)
			{
				if(isset($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k]))
				{
					if($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k] != "" && $_REQUEST['txtTCOffHireFrom_'.$i.'_'.$k] != "" && $_REQUEST['txtTCOffHireTo_'.$i.'_'.$k] != "")
					{
						if($_REQUEST['txtTCOffHireFrom_'.$i.'_'.$k]!="")
						{$txtTCOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCOffHireFrom_'.$i.'_'.$k]));}
						else{$txtTCOffHireFrom  		= "1970-01-01 08:00:00";}
						
						if($_REQUEST['txtTCOffHireTo_'.$i.'_'.$k]!="")
						{$txtTCOffHireTo	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCOffHireTo_'.$i.'_'.$k]));}
						else{$txtTCOffHireTo  		= "1970-01-01 08:00:00";}
						
						$randomid = $_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k];
						if(!isset($_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k]) || $_REQUEST['txtTCOffHireRandomID_'.$i.'_'.$k]=='')
						{
							$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
						}
						
						$sql6 = "insert into chartering_tc_estimate_slave4 (TC_SLAVE1ID, OFFHIRE_REASON, OFF_HIRE_FROM, OFF_HIRE_TO, OFF_HIRE_DAYS, OFF_HIRE_RATE, OF_HIRE_AMT, RANDOMID) values ('".$maxslaveid."', '".addslashes(trim($_REQUEST['txtTCOffHireReason_'.$i.'_'.$k]))."', '".$txtTCOffHireFrom."', '".$txtTCOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireDays_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireRate_'.$i.'_'.$k])."', '".$this->getCheckNullValue($_REQUEST['txtTCOffHireAmt_'.$i.'_'.$k])."', '".$randomid."')";
						mysql_query($sql6) or die($sql6);
						mysql_query("commit");
						
						$mysqlmax4 = "select max(TC_SLAVE4ID) as max from chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$maxslaveid."'";
						$myresmax4  =  mysql_query($mysqlmax4);
						$myrowsmax4 = mysql_fetch_assoc($myresmax4);
						$mslave4id = $myrowsmax4['max'];
						

						$txtTCConBunkerCount = $_REQUEST['txtTCConBunkerCount_'.$i.'_'.$k];
						for($l=1 ; $l<=$txtTCConBunkerCount;$l++)
						{
							if(isset($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l]))
							{
								if($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l] != "" && $_REQUEST['txtTCConBunkerQty_'.$i.'_'.$k.'_'.$l] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$k.'_'.$l] != "")
								{   
									if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$k.'_'.$l])){$ChkOFFHireCal = $_REQUEST['ChkOFFHireCal_'.$i.'_'.$k.'_'.$l];}
									else{$ChkOFFHireCal  = 0;}
									$sql7 = "insert into chartering_tc_estimate_slave5 (TC_SLAVE4ID, TC_SLAVE1ID, BUNKERID, BUNKER_QTY, BUNKER_PRICE, BUNKER_AMT, IS_OWNER_ACCOUNT) values ('".$mslave4id."', '".$maxslaveid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$k.'_'.$l])."', '".$this->getCheckNullValue($ChkOFFHireCal)."')";
									mysql_query($sql7) or die($sql7);
									mysql_query("commit");
								}
							}
						}
					}
				}
			}
			
			$txtTCHOSTID = $_REQUEST['txtTCHOSTID_'.$i];
			for($j=1 ; $j<=$txtTCHOSTID ;$j++)
			{
				if($_REQUEST['txtTotalVoyageDays_'.$i.'_'.$j] != "")
				{
					if($_REQUEST['txtTCDeliveryDate_'.$i.'_'.$j]!="")
					{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate_'.$i.'_'.$j]));}
					else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
					
					if($_REQUEST['txtTCReDeliveryDate_'.$i.'_'.$j]!="")
					{$txtTCReDeliveryDate 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate_'.$i.'_'.$j]));}
					else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
					
					$randomid = $_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j];
					if(!isset($_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j]) || $_REQUEST['txtTCINSlaveRandomID_'.$i.'_'.$j]=='')
					{
						$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
					}
					
					$sql3 = "insert into chartering_tc_estimate_slave2 (TC_SLAVE1ID, RANDOMID, TC_DELIVERY_DATE, TC_REDELIVERY_DATE, TC_RATE, TD_DAYS, HIERAGE, BALLAST_BONUS, GROSS_HIERAGE, ADD_COMM, ADD_COMM_AMT, ADD_COMM_VENDOR, BROKERAGE_COMM, BROKERAGE_COMM_AMT, BRO_COMM_VENDOR, NET_HIERAGE, CVE_MONTH, CVE_AMOUNT) values ('".$maxslaveid."', '".$randomid."', '".$txtTCDeliveryDate."', '".$txtTCReDeliveryDate."', '".$this->getCheckNullValue($_REQUEST['txtTCinDailyHire_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTotalVoyageDays_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtBallastBonus_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtGrossHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargePercent_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargePercentAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selTCAddCoVendor_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeBroPercent_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtHireargeBroPercentAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['selTCBroComVendor_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtNettHireargeAmt_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTCHireargeCVE_'.$i.'_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtTCHireargeCVEAMT_'.$i.'_'.$j])."')";
					mysql_query($sql3) or die($sql3);//echo $sql3;
					mysql_query("commit");	
				}
			}			
		}
	}
	return $msg; 
}


function updatePLDifference()
{
    $connect 			= $this->funConnect();	
	
	$txtPLDifference    = $_REQUEST['txtPLDifference'];
	$txtActualPL        = $_REQUEST['txtActualPL'];
	$txtCOMID           = $_REQUEST['txtCOMID'];
	$fcaid              = $this->getCompareEstimateData($txtCOMID,"FCAID");
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update freight_cost_estimete_master set PL_DIFF='".$this->getCheckNullValue($txtPLDifference)."', ACTUAL_PL='".$this->getCheckNullValue($txtActualPL)."' where FCAID='".$fcaid."'";
	mysql_query($sql) or die($sql);
    mysql_query("commit");
		
	return $msg;
}


function getVoyageNoList()
{
	$this->funConnect();
	$sql = "select (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=(select VESSEL_IMO_ID from freight_cost_estimete_master where freight_cost_estimete_master.COMID = freight_cost_estimate_compare.COMID order by freight_cost_estimete_master.FCAID LIMIT 0,1)) as VESSEL_NAME, (select VOYAGE_NO from freight_cost_estimete_master where freight_cost_estimete_master.COMID = freight_cost_estimate_compare.COMID order by freight_cost_estimete_master.FCAID LIMIT 0,1) as VOYAGE_NO, COMID, MESSAGE from freight_cost_estimate_compare where STATUS in (1,2,3) order by COMID ";
	$result = mysql_query($sql) or die($sql);
	while($rows = mysql_fetch_assoc($result))
		{
		 $key= $rows['COMID'];
		 $value= $rows['MESSAGE'].' - '.$rows['VOYAGE_NO'].' - '.$rows['VESSEL_NAME'];
		 echo '<option value='.$key;
		 if(in_array($key,$id_arr)){ echo " selected";}
		 echo '>'.$value.'</option>';
		}
}

function getTCNoList()
{
	$this->funConnect();
	$sql = "select (select VESSEL_NAME from vessel_imo_master where vessel_imo_master.VESSEL_IMO_ID=(select VESSEL_IMO_ID from chartering_estimate_tc_master where chartering_estimate_tc_master.COMID = chartering_estimate_tc_compare.COMID order by chartering_estimate_tc_master.TCOUTID LIMIT 0,1)) as VESSEL_NAME, (select TC_NO from chartering_estimate_tc_master where chartering_estimate_tc_master.COMID = chartering_estimate_tc_compare.COMID order by chartering_estimate_tc_master.TCOUTID LIMIT 0,1) as TC_NO, COMID, MESSAGE from chartering_estimate_tc_compare where STATUS in (1,2,3) order by COMID";
	$result = mysql_query($sql) or die($sql);
	while($rows = mysql_fetch_assoc($result))
		{
		 $key= $rows['COMID'];
		 $value= $rows['MESSAGE'].' - '.$rows['TC_NO'].' - '.$rows['VESSEL_NAME'];
		 echo '<option value='.$key;
		 if(in_array($key,$id_arr)){ echo " selected";}
		 echo '>'.$value.'</option>';
		}
}

function getDaysDifference($date1,$date2)
{
    if($date1!='' && $date2!='' && $date1!='1970-01-01' && $date2!='1970-01-01')
	{
	    $diff = strtotime($date2) - strtotime($date1);
		return round($diff / (60 * 60 * 24));
	}
	else
	{
	    return 0;
	}
}


function uploadVoyageReportData()
{
	$connect				= $this->funConnect();
	
	$upload = $this->getUploadVoyageReport($_FILES['attach_file']);
	$uploadname = $this->getUploadName($_FILES['attach_file']);
	
	$upload_imp = implode(',',$upload);
	$name_imp = implode(',',$uploadname);
	
	if($name_imp=='')
	{
	   return 1;
	}
	else
	{
		mysql_query("Set Autocommit=0");
		mysql_query("START TRANSACTION");
			
		$msg = 0;
		
		for($i=0;$i<count($upload);$i++)
		{	
		    $json_data = file_get_contents('../../voyage_attachments/'.$upload[$i]);
			$data = json_decode($json_data, true);
			
		    $textfilename = explode('_',$uploadname[$i]);	
		    if(in_array("DEPARTURE", $textfilename))
			{
				$Vessel_Type = isset($data[Vessel_Type]) ? mysql_real_escape_string($data[Vessel_Type]) : '';
				$Message = isset($data[Message]) ? mysql_real_escape_string($data[Message]) : '';
				$Report_Title = isset($data[Report_Title]) ? mysql_real_escape_string($data[Report_Title]) : '';
				$Vessel_Name = isset($data[Vessel_Name]) ? mysql_real_escape_string($data[Vessel_Name]) : '';
				$Vessel_IMO_NO = isset($data[Vessel_IMO_NO]) ? mysql_real_escape_string($data[Vessel_IMO_NO]) : '';
				$SSP_FAOP_Date_Time = isset($data[SSP_FAOP_Date_Time]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[SSP_FAOP_Date_Time]))) : '';
				$Reporting_Date_Time = isset($data[Reporting_Date_Time]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Reporting_Date_Time]))) : '';
				$Prefix = isset($data[Prefix]) ? mysql_real_escape_string($data[Prefix]) : '';
				$Time_Relative_to_UTC = isset($data[Time_Relative_to_UTC]) ? mysql_real_escape_string($data[Time_Relative_to_UTC]) : '';
				$Reporting_Date_Time_UTC = isset($data[Reporting_Date_Time_UTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Reporting_Date_Time_UTC]))) : '';
				$Voy_No = isset($data[Voy_No]) ? mysql_real_escape_string($data[Voy_No]) : '';
				$Draft_Fore = isset($data[Draft_Fore]) ? mysql_real_escape_string($data[Draft_Fore]) : '';
				$Draft_Aft = isset($data[Draft_Aft]) ? mysql_real_escape_string($data[Draft_Aft]) : '';
				$Vessel_Condition = isset($data[Vessel_Condition]) ? mysql_real_escape_string($data[Vessel_Condition]) : '';
				$Charterer = isset($data[Charterer]) ? mysql_real_escape_string($data[Charterer]) : '';
				$CP_Date = isset($data[CP_Date]) ? date('Y-m-d',strtotime(mysql_real_escape_string($data[CP_Date]))) : '';
				$CP_Speed = isset($data[CP_Speed]) ? mysql_real_escape_string($data[CP_Speed]) : '';
				$Port_Departed_From = isset($data[Port_Departed_From]) ? mysql_real_escape_string($data[Port_Departed_From]) : '';
				$Deadweight = isset($data[Deadweight]) ? mysql_real_escape_string($data[Deadweight]) : '';
				$Weather_Direction = isset($data[Weather_Direction]) ? mysql_real_escape_string($data[Weather_Direction]) : '';
				$Wind_Force = isset($data[Wind_Force]) ? mysql_real_escape_string($data[Wind_Force]) : '';
				$Sea_State = isset($data[Sea_State]) ? mysql_real_escape_string($data[Sea_State]) : '';
				$Swell_State = isset($data[Swell_State]) ? mysql_real_escape_string($data[Swell_State]) : '';
				$Swell_Dirn = isset($data[Swell_Dirn]) ? mysql_real_escape_string($data[Swell_Dirn]) : '';
				$Lat = isset($data[Lat]) ? mysql_real_escape_string($data[Lat]) : '';
				$Min1 = isset($data[Min1]) ? mysql_real_escape_string($data[Min1]) : '';
				$Deg1 = isset($data[Deg1]) ? mysql_real_escape_string($data[Deg1]) : '';
				$Long = isset($data[Long]) ? mysql_real_escape_string($data[Long]) : '';
				$Deg2 = isset($data[Deg2]) ? mysql_real_escape_string($data[Deg2]) : '';
				$Min2 = isset($data[Min2]) ? mysql_real_escape_string($data[Min2]) : '';
				$Ordered_Speed_To_Next_Port = isset($data[Ordered_Speed_To_Next_Port]) ? mysql_real_escape_string($data[Ordered_Speed_To_Next_Port]) : '';
				$Dist_To_Go = isset($data[Dist_To_Go]) ? mysql_real_escape_string($data[Dist_To_Go]) : '';
				$EOSPdata = isset($data[EOSPdata]) ? mysql_real_escape_string($data[EOSPdata]) : '';
				$Next_Port = isset($data[Next_Port]) ? mysql_real_escape_string($data[Next_Port]) : '';
				$ETA_Next_Port = isset($data[ETA_Next_Port]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[ETA_Next_Port]))) : '';
				$Remarks = isset($data[Remarks]) ? mysql_real_escape_string(addslashes($data[Remarks])) : '';
				if(!empty(trim($Vessel_IMO_NO)))
				{
				$sql = "select * from sa_departure_master where IMO_NO = '".trim($Vessel_IMO_NO)."' and date(REPORTING_DATETIME_LT)='".date('Y-m-d', strtotime($Reporting_Date_Time))."' and MESSAGE_NO='".$Message."'";
				$res = mysql_query($sql);
				$rec = mysql_num_rows($res);
				if($rec == 0)
					{
						$query = "INSERT INTO sa_departure_master (VESSEL_TYPE, MESSAGE_NO, REPORT_TITLE, VESSEL_NAME, IMO_NO, SSP_FAOP_DATE_TIME, REPORTING_DATETIME_LT, TIME_RELATIVE_UTC, REPORTING_DATETIME_UTC, VOYAGE_NO, DRAFT_FORE, DRAFT_AFT, VESSEL_CONDITION, CHARTERER, CP_DATE, CP_SPEED, PORT_DEPARTED_FROM, DEADWEIGHT, WEATHER_DIRECTION, WIND_FORCE, SEA_STATE, SWEEL_STATE, SWELL_DIRN, LATTITUDE, LAT_DEG, LAT_MIN, LONGITUDE, LONG_DEG, LONG_MIN, SPEED_TO_NEXT_PORT, DISTANCE_TO_GO, NEXT_PORT, ETA_NEXT_PORT, REMARKS, ADDONDATE, PREFIX) VALUES ('".addslashes($Vessel_Type)."','".addslashes($Message)."','".addslashes($Report_Title)."','".addslashes($Vessel_Name)."','".addslashes($Vessel_IMO_NO)."','".$SSP_FAOP_Date_Time."','".$Reporting_Date_Time."','".$Time_Relative_to_UTC."','".$Reporting_Date_Time_UTC."','".addslashes($Voy_No)."','".$Draft_Fore."','".$Draft_Aft."','".addslashes($Vessel_Condition)."','".addslashes($Charterer)."','".$CP_Date."','".$CP_Speed."','".addslashes($Port_Departed_From)."','".$Deadweight."','".addslashes($Weather_Direction)."', '".$Wind_Force."','".$Sea_State."','".$Swell_State."','".$Swell_Dirn."','".$Lat."','".$Deg1."','".$Min1."','".$Long."','".$Deg2."','".$Min2."','".$Ordered_Speed_To_Next_Port."','".$Dist_To_Go."','".addslashes($Next_Port)."','".$ETA_Next_Port."','".addslashes($Remarks)."','".$Prefix."',NOW())";
						$insert = mysql_query($query);
						
						$sql1 = "select max(DEPARTUREID) as max from sa_departure_master";
						$res1 = mysql_query($sql1);
						$rows1 = mysql_fetch_assoc($res1);
						
						for($i=0;$i<count($data[EOSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_departure_slave (DEPARTUREID, BUNKER, QUANTITY) VALUES ('".$rows1['max']."','".$data[EOSPdata][$i][EOSP_Bunker]."','".$data[EOSPdata][$i][EOSP_Qty]."')";
							mysql_query($sql2) or die($sql2);
						}
						if($insert){
							$msg = 0;
						} else {
							$msg = 1;
						}		
					}
				else{
						$rows = mysql_fetch_assoc($res);
						$query = "update sa_departure_master set VESSEL_TYPE='".addslashes($Vessel_Type)."', MESSAGE_NO='".addslashes($Message)."', REPORT_TITLE='".addslashes($Report_Title)."', VESSEL_NAME='".addslashes($Vessel_Name)."', IMO_NO='".addslashes($Vessel_IMO_NO)."', SSP_FAOP_DATE_TIME='".$SSP_FAOP_Date_Time."', REPORTING_DATETIME_LT='".$Reporting_Date_Time."', TIME_RELATIVE_UTC='".$Time_Relative_to_UTC."', REPORTING_DATETIME_UTC='".$Reporting_Date_Time_UTC."', VOYAGE_NO='".addslashes($Voy_No)."', DRAFT_FORE='".$Draft_Fore."', DRAFT_AFT='".$Draft_Aft."', VESSEL_CONDITION='".addslashes($Vessel_Condition)."', CHARTERER='".addslashes($Charterer)."', CP_DATE='".$CP_Date."', CP_SPEED='".$CP_Speed."', PORT_DEPARTED_FROM='".addslashes($Port_Departed_From)."', DEADWEIGHT='".$Deadweight."', WEATHER_DIRECTION='".addslashes($Weather_Direction)."', WIND_FORCE='".$Wind_Force."', SEA_STATE='".$Sea_State."', SWEEL_STATE='".$Swell_State."', SWELL_DIRN='".$Swell_Dirn."', LATTITUDE='".$Lat."', LAT_DEG='".$Deg1."', LAT_MIN='".$Min1."', LONGITUDE='".$Long."', LONG_DEG='".$Deg2."', LONG_MIN='".$Min2."', SPEED_TO_NEXT_PORT='".$Ordered_Speed_To_Next_Port."', DISTANCE_TO_GO='".$Dist_To_Go."', NEXT_PORT='".addslashes($Next_Port)."', ETA_NEXT_PORT='".$ETA_Next_Port."', REMARKS='".addslashes($Remarks)."', UPDATEONDATE=NOW(), PREFIX='".$Prefix."' where DEPARTUREID='".$rows['DEPARTUREID']."'";
						$update = mysql_query($query);
						
						$sql1 = "delete from sa_departure_slave where DEPARTUREID='".$rows['DEPARTUREID']."'";
						mysql_query($sql1);
						
						for($i=0;$i<count($data[EOSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_departure_slave (DEPARTUREID, BUNKER, QUANTITY) VALUES ('".$rows['DEPARTUREID']."','".$data[EOSPdata][$i][EOSP_Bunker]."','".$data[EOSPdata][$i][EOSP_Qty]."')";
							mysql_query($sql2) or die($sql2);
						}
						if($update){
							$msg = 0;
						}else {
							$msg = 1;
						}
					}
					if($msg == 0)
					{
						$sql3 = "insert into upload_voyage_report_log (LOGINID, ADDONDATE, UPLOAD_NAME, UPLOAD, IDENTITY) values ('".$_SESSION['uid']."', NOW(), '".$uploadname[$i]."', '".$upload[$i]."', 'DEPARTURE')";
						mysql_query($sql3,$connect) or die(mysql_error());
						mysql_query("commit");
					}
				} 
				else 
				{
					 $msg = 1;
				}
            }
			
			
			if(in_array("NOON", $textfilename))
			{	            
				$Vessel_Type = isset($data[Vessel_Type]) ? mysql_real_escape_string($data[Vessel_Type]) : '';
				$Message = isset($data[Message]) ? mysql_real_escape_string($data[Message]) : '';
				$Report_Title = isset($data[Report_Title]) ? mysql_real_escape_string($data[Report_Title]) : '';
				$Vessel_Name = isset($data[Vessel_Name]) ? mysql_real_escape_string($data[Vessel_Name]) : '';
				$Vessel_IMO_NO = isset($data[Vessel_IMO_NO]) ? mysql_real_escape_string($data[Vessel_IMO_NO]) : '';
				$SSP_FAOP_Date_Time = isset($data[SSP_FAOP_Date_Time]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[SSP_FAOP_Date_Time]))) : '';
				$Reporting_Date_Time = isset($data[Reporting_Date_Time]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Reporting_Date_Time]))) : '';
				$Prefix = isset($data[Prefix]) ? mysql_real_escape_string($data[Prefix]) : '';
				$Time_Relative_to_UTC = isset($data[Time_Relative_to_UTC]) ? mysql_real_escape_string($data[Time_Relative_to_UTC]) : '';
				$Reporting_Date_Time_UTC = isset($data[Reporting_Date_Time_UTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Reporting_Date_Time_UTC]))) : '';
				$Voy_No = isset($data[Voy_No]) ? mysql_real_escape_string($data[Voy_No]) : '';
				$Draft_Fore = isset($data[Draft_Fore]) ? mysql_real_escape_string($data[Draft_Fore]) : '';
				$Draft_Aft = isset($data[Draft_Aft]) ? mysql_real_escape_string($data[Draft_Aft]) : '';
				$Vessel_Condition = isset($data[Vessel_Condition]) ? mysql_real_escape_string($data[Vessel_Condition]) : '';
				$Charterer = isset($data[Charterer]) ? mysql_real_escape_string($data[Charterer]) : '';
				$CP_Date = isset($data[CP_Date]) ? date('Y-m-d',strtotime(mysql_real_escape_string($data[CP_Date]))) : '';
				$CP_Speed = isset($data[CP_Speed]) ? mysql_real_escape_string($data[CP_Speed]) : '';
				$Deadweight = isset($data[Deadweight]) ? mysql_real_escape_string($data[Deadweight]) : '';
				$Weather_Direction = isset($data[Weather_Direction]) ? mysql_real_escape_string($data[Weather_Direction]) : '';
				$Wind_Force = isset($data[Wind_Force]) ? mysql_real_escape_string($data[Wind_Force]) : '';
				$Sea_State = isset($data[Sea_State]) ? mysql_real_escape_string($data[Sea_State]) : '';
				$Swell_State = isset($data[Swell_State]) ? mysql_real_escape_string($data[Swell_State]) : '';
				$Swell_Dirn = isset($data[Swell_Dirn]) ? mysql_real_escape_string($data[Swell_Dirn]) : '';
				$Lat = isset($data[Lat]) ? mysql_real_escape_string($data[Lat]) : '';
				$Min1 = isset($data[Min1]) ? mysql_real_escape_string($data[Min1]) : '';
				$Deg1 = isset($data[Deg1]) ? mysql_real_escape_string($data[Deg1]) : '';
				$Long = isset($data[Long]) ? mysql_real_escape_string($data[Long]) : '';
				$Deg2 = isset($data[Deg2]) ? mysql_real_escape_string($data[Deg2]) : '';
				$Min2 = isset($data[Min2]) ? mysql_real_escape_string($data[Min2]) : '';
				$ObsdDistance = isset($data[ObsdDistance]) ? mysql_real_escape_string($data[ObsdDistance]) : '';
				$NoonHDG = isset($data[NoonHDG]) ? mysql_real_escape_string($data[NoonHDG]) : '';
				$StoppageHrs = isset($data[StoppageHrs]) ? mysql_real_escape_string($data[StoppageHrs]) : '';
				$EffectiveSteaming = isset($data[EffectiveSteaming]) ? mysql_real_escape_string($data[EffectiveSteaming]) : '';
				$ObsdSpeed = isset($data[ObsdSpeed]) ? mysql_real_escape_string($data[ObsdSpeed]) : '';
				$Dist_To_Go = isset($data[Dist_To_Go]) ? mysql_real_escape_string($data[Dist_To_Go]) : '';
								
				$Downtimedata = isset($data[Downtimedata]) ? mysql_real_escape_string($data[Downtimedata]) : '';
				$EOSPdata = isset($data[EOSPdata]) ? mysql_real_escape_string($data[EOSPdata]) : '';
				$ROBdata = isset($data[ROBdata]) ? mysql_real_escape_string($data[ROBdata]) : '';
				$CONSPdata = isset($data[CONSPdata]) ? mysql_real_escape_string($data[CONSPdata]) : '';
				$CONSPOTdata = isset($data[CONSPOTdata]) ? mysql_real_escape_string($data[CONSPOTdata]) : '';
				$CONSPOTTCdata = isset($data[CONSPOTTCdata]) ? mysql_real_escape_string($data[CONSPOTTCdata]) : '';
				$CONSPOTGFdata = isset($data[CONSPOTGFdata]) ? mysql_real_escape_string($data[CONSPOTGFdata]) : '';
				$CONSPOTOTdata = isset($data[CONSPOTOTdata]) ? mysql_real_escape_string($data[CONSPOTOTdata]) : '';
				$ROBOTTTLdata = isset($data[ROBOTTTLdata]) ? mysql_real_escape_string($data[ROBOTTTLdata]) : '';
				$CONSPOTTTLdata = isset($data[CONSPOTTTLdata]) ? mysql_real_escape_string($data[CONSPOTTTLdata]) : '';
				$CONSPGCdata = isset($data[CONSPGCdata]) ? mysql_real_escape_string($data[CONSPGCdata]) : '';
				$CONSPGCTCdata = isset($data[CONSPGCTCdata]) ? mysql_real_escape_string($data[CONSPGCTCdata]) : '';
				$CONSPGCGFdata = isset($data[CONSPGCGFdata]) ? mysql_real_escape_string($data[CONSPGCGFdata]) : '';
				$CONSPGCOTdata = isset($data[CONSPGCOTdata]) ? mysql_real_escape_string($data[CONSPGCOTdata]) : '';
				$ROBGCTTdata = isset($data[ROBGCTTdata]) ? mysql_real_escape_string($data[ROBGCTTdata]) : '';
				$CONSPGCTTLdata = isset($data[CONSPGCTTLdata]) ? mysql_real_escape_string($data[CONSPGCTTLdata]) : '';
				
				$Next_Port = isset($data[Next_Port]) ? mysql_real_escape_string($data[Next_Port]) : '';
				$ETA_Next_Port = isset($data[ETA_Next_Port]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[ETA_Next_Port]))) : '';
				$Remarks = isset($data[Remarks]) ? mysql_real_escape_string(addslashes($data[Remarks])) : '';
				
				if(!empty(trim($Vessel_IMO_NO)))
				{
				$sql = "select * from sa_noon_master where IMO_NO = '".trim($Vessel_IMO_NO)."' and date(REPORTING_DATETIME_LT)='".date('Y-m-d', strtotime($Reporting_Date_Time))."' and MESSAGE_NO='".$Message."'";
				$res = mysql_query($sql);
				$rec = mysql_num_rows($res);
				if($rec == 0)
					{
						$query = "INSERT INTO sa_noon_master (VESSEL_TYPE, MESSAGE_NO, REPORT_TITLE, VESSEL_NAME, IMO_NO, SSP_FAOP_DATE_TIME, REPORTING_DATETIME_LT, TIME_RELATIVE_UTC, REPORTING_DATETIME_UTC, VOYAGE_NO, DRAFT_FORE, DRAFT_AFT, VESSEL_CONDITION, CHARTERER, CP_DATE, CP_SPEED, WEATHER_DIRECTION, WIND_FORCE, SEA_STATE, SWEEL_STATE, SWELL_DIRN, LATTITUDE, LAT_DEG, LAT_MIN, LONGITUDE, LONG_DEG, LONG_MIN, DISTANCE_TO_GO, NEXT_PORT, ETA_NEXT_PORT, REMARKS, PREFIX, ADDONDATE, OBSERVED_DIST, NOON_HDG, STOPPAGE, EFFECTIVE_STEAMING, OBSERVED_SPEED) VALUES ('".addslashes($Vessel_Type)."','".addslashes($Message)."','".addslashes($Report_Title)."','".addslashes($Vessel_Name)."','".addslashes($Vessel_IMO_NO)."','".$SSP_FAOP_Date_Time."','".$Reporting_Date_Time."','".$Time_Relative_to_UTC."','".$Reporting_Date_Time_UTC."','".addslashes($Voy_No)."','".$Draft_Fore."','".$Draft_Aft."','".addslashes($Vessel_Condition)."','".addslashes($Charterer)."','".$CP_Date."','".$CP_Speed."','".addslashes($Weather_Direction)."', '".$Wind_Force."','".$Sea_State."','".$Swell_State."','".$Swell_Dirn."','".$Lat."','".$Deg1."','".$Min1."','".$Long."','".$Deg2."','".$Min2."','".$Dist_To_Go."','".addslashes($Next_Port)."','".$ETA_Next_Port."','".addslashes($Remarks)."','".$Prefix."',NOW(),'".addslashes($ObsdDistance)."','".addslashes($NoonHDG)."','".addslashes($StoppageHrs)."','".addslashes($EffectiveSteaming)."','".addslashes($ObsdSpeed)."')";
						$insert = mysql_query($query);
						
						$sql1 = "select max(NOONID) as max from sa_noon_master";
						$res1 = mysql_query($sql1);
						$rows1 = mysql_fetch_assoc($res1);
						
						
						for($i=0;$i<count($data[Downtimedata]);$i++)
						{
						    $DowntimeFromLT = isset($data[Downtimedata][$i][DowntimeFromLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromLT]))) : '';
							$DowntimeFromUTC = isset($data[Downtimedata][$i][DowntimeFromUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromUTC]))) : '';
							$DowntimeToLT = isset($data[Downtimedata][$i][DowntimeToLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToLT]))) : '';
							$DowntimeToUTC = isset($data[Downtimedata][$i][DowntimeToUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToUTC]))) : '';
							
						    $sql2 = "INSERT INTO sa_noon_slave2 (NOONID, DOWNTIME_TYPE, FROM_LT_DATETIME, FROM_PREFIX, FROM_TIMEZONE, FROM_UTC_DATETIME, TO_LT_DATETIME, TO_PREFIX, TO_TIMEZONE, TO_UTC_DATETIME, REMARKS) VALUES ('".$rows1['max']."', '".$data[Downtimedata][$i][Downtime]."', '".$DowntimeFromLT."', '".$data[Downtimedata][$i][PrefixFrom]."', '".$data[Downtimedata][$i][TimeZoneFrom]."', '".$DowntimeFromUTC."','".$DowntimeToLT."','".$data[Downtimedata][$i][PrefixTo]."','".$data[Downtimedata][$i][TimeZoneTo]."','".$DowntimeToUTC."','".$data[Downtimedata][$i][DwntimeRemark]."')";
							mysql_query($sql2) or die($sql2);
							
							$sqlalave1 = "select max(NOON_SLAVEID) as max from sa_noon_slave2";
							$resslave1 = mysql_query($sqlalave1);
							$rowsslave1 = mysql_fetch_assoc($resslave1);
							
							for($j=0;$j<count($data[Downtimedata][$i][EOSPBunker]);$j++)
							{
								$sql2 = "INSERT INTO sa_noon_slave3 (NOONID, NOON_SLAVEID, BUNKER, QUANTITY) VALUES ('".$rows1['max']."', '".$rowsslave1['max']."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Bunker]."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Qty]."')";
								mysql_query($sql2) or die($sql2);
							}
						}
						
						
						for($i=0;$i<count($data[ROBdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBdata][$i][ROB_Bunker]."', '".$data[ROBdata][$i][ROB_Qty]."', 'ROB_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPdata][$i][CONSP_Bunker]."', '".$data[CONSPdata][$i][CONSP_Qty]."', 'CONSUMPTION_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTdata][$i][CONSP_BunkerOT]."', '".$data[CONSPOTdata][$i][CONSP_QtyOT]."', 'MAINPROP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTTCdata][$i][CONSP_BunkerOTTC]."', '".$data[CONSPOTTCdata][$i][CONSP_QtyOTTC]."', 'TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTGFdata][$i][CONSP_BunkerOTGF]."', '".$data[CONSPOTGFdata][$i][CONSP_QtyOTGF]."', 'GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTOTdata][$i][CONSP_BunkerOTOT]."', '".$data[CONSPOTOTdata][$i][CONSP_QtyOTOT]."', 'OT_OTHERS_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBOTTTLdata][$i][ROB_BunkerOTTTL]."', '".$data[ROBOTTTLdata][$i][ROB_QtyOTTTL]."', 'ROB_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTTTLdata][$i][CONSP_BunkerOTTTL]."', '".$data[CONSPOTTTLdata][$i][CONSP_QtyOTTTL]."', 'CONSP_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCTCdata][$i][CONSP_BunkerGC1]."', '".$data[CONSPGCTCdata][$i][CONSP_QtyGC1]."', 'CONSP_TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCGFdata][$i][CONSP_BunkerGCGF]."', '".$data[CONSPGCGFdata][$i][CONSP_QtyGCGF]."', 'CONSP_GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCOTdata][$i][CONSP_BunkerGCOT]."', '".$data[CONSPGCOTdata][$i][CONSP_QtyGCOT]."', 'CONSPGC_OTHER_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBGCTTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBGCTTdata][$i][ROB_BunkerGCTT]."', '".$data[ROBGCTTdata][$i][ROB_QtyGCTT]."', 'ROBGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCTTLdata][$i][CONSP_BunkerGCTTL]."', '".$data[CONSPGCTTLdata][$i][CONSP_QtyGCTTL]."', 'CONSPGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						if($insert){
							$msg = 0;
						} else {
							$msg = 1;
						}		
					}
				else{
						$rows = mysql_fetch_assoc($res);
						$query = "update sa_noon_master set VESSEL_TYPE='".addslashes($Vessel_Type)."', MESSAGE_NO='".addslashes($Message)."', REPORT_TITLE='".addslashes($Report_Title)."', VESSEL_NAME='".addslashes($Vessel_Name)."', IMO_NO='".addslashes($Vessel_IMO_NO)."', SSP_FAOP_DATE_TIME='".$SSP_FAOP_Date_Time."', REPORTING_DATETIME_LT='".$Reporting_Date_Time."', TIME_RELATIVE_UTC='".$Time_Relative_to_UTC."', REPORTING_DATETIME_UTC='".$Reporting_Date_Time_UTC."', VOYAGE_NO='".addslashes($Voy_No)."', DRAFT_FORE='".$Draft_Fore."', DRAFT_AFT='".$Draft_Aft."', VESSEL_CONDITION='".addslashes($Vessel_Condition)."', CHARTERER='".addslashes($Charterer)."', CP_DATE='".$CP_Date."', CP_SPEED='".$CP_Speed."', WEATHER_DIRECTION='".addslashes($Weather_Direction)."', WIND_FORCE='".$Wind_Force."', SEA_STATE='".$Sea_State."', SWEEL_STATE='".$Swell_State."', SWELL_DIRN='".$Swell_Dirn."', LATTITUDE='".$Lat."', LAT_DEG='".$Deg1."', LAT_MIN='".$Min1."', LONGITUDE='".$Long."', LONG_DEG='".$Deg2."', LONG_MIN='".$Min2."', DISTANCE_TO_GO='".$Dist_To_Go."', NEXT_PORT='".addslashes($Next_Port)."', ETA_NEXT_PORT='".$ETA_Next_Port."', REMARKS='".addslashes($Remarks)."', UPDATEONDATE=NOW(), PREFIX='".$Prefix."', OBSERVED_DIST='".addslashes($ObsdDistance)."', NOON_HDG='".addslashes($NoonHDG)."', STOPPAGE='".addslashes($StoppageHrs)."', EFFECTIVE_STEAMING='".addslashes($EffectiveSteaming)."', OBSERVED_SPEED='".addslashes($ObsdSpeed)."' where NOONID='".$rows['NOONID']."'";
						$update = mysql_query($query);
						
						$sql1 = "delete from sa_noon_slave1 where NOONID='".$rows['NOONID']."'";
						$sql2 = "delete from sa_noon_slave2 where NOONID='".$rows['NOONID']."'";
						$sql3 = "delete from sa_noon_slave3 where NOONID='".$rows['NOONID']."'";
						mysql_query($sql1);
						mysql_query($sql2);
						mysql_query($sql3);
						
						for($i=0;$i<count($data[Downtimedata]);$i++)
						{
						    $DowntimeFromLT = isset($data[Downtimedata][$i][DowntimeFromLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromLT]))) : '';
							$DowntimeFromUTC = isset($data[Downtimedata][$i][DowntimeFromUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromUTC]))) : '';
							$DowntimeToLT = isset($data[Downtimedata][$i][DowntimeToLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToLT]))) : '';
							$DowntimeToUTC = isset($data[Downtimedata][$i][DowntimeToUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToUTC]))) : '';
							
						    $sql2 = "INSERT INTO sa_noon_slave2 (NOONID, DOWNTIME_TYPE, FROM_LT_DATETIME, FROM_PREFIX, FROM_TIMEZONE, FROM_UTC_DATETIME, TO_LT_DATETIME, TO_PREFIX, TO_TIMEZONE, TO_UTC_DATETIME, REMARKS) VALUES ('".$rows['NOONID']."', '".$data[Downtimedata][$i][Downtime]."', '".$DowntimeFromLT."', '".$data[Downtimedata][$i][PrefixFrom]."', '".$data[Downtimedata][$i][TimeZoneFrom]."', '".$DowntimeFromUTC."','".$DowntimeToLT."','".$data[Downtimedata][$i][PrefixTo]."','".$data[Downtimedata][$i][TimeZoneTo]."','".$DowntimeToUTC."','".$data[Downtimedata][$i][DwntimeRemark]."')";
							mysql_query($sql2) or die($sql2);
							
							$sqlalave1 = "select max(NOON_SLAVEID) as max from sa_noon_slave2";
							$resslave1 = mysql_query($sqlalave1);
							$rowsslave1 = mysql_fetch_assoc($resslave1);
							
							for($j=0;$j<count($data[Downtimedata][$i][EOSPBunker]);$j++)
							{
								$sql2 = "INSERT INTO sa_noon_slave3 (NOONID, NOON_SLAVEID, BUNKER, QUANTITY) VALUES ('".$rows['NOONID']."', '".$rowsslave1['max']."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Bunker]."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Qty]."')";
								mysql_query($sql2) or die($sql2);
							}
						}
						
						for($i=0;$i<count($data[EOSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[EOSPdata][$i][EOSP_Bunker]."', '".$data[EOSPdata][$i][EOSP_Qty]."', 'DOWNTIME_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[ROBdata][$i][ROB_Bunker]."', '".$data[ROBdata][$i][ROB_Qty]."', 'ROB_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPdata][$i][CONSP_Bunker]."', '".$data[CONSPdata][$i][CONSP_Qty]."', 'CONSUMPTION_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPOTdata][$i][CONSP_BunkerOT]."', '".$data[CONSPOTdata][$i][CONSP_QtyOT]."', 'MAINPROP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPOTTCdata][$i][CONSP_BunkerOTTC]."', '".$data[CONSPOTTCdata][$i][CONSP_QtyOTTC]."', 'TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPOTGFdata][$i][CONSP_BunkerOTGF]."', '".$data[CONSPOTGFdata][$i][CONSP_QtyOTGF]."', 'GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPOTOTdata][$i][CONSP_BunkerOTOT]."', '".$data[CONSPOTOTdata][$i][CONSP_QtyOTOT]."', 'OT_OTHERS_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[ROBOTTTLdata][$i][ROB_BunkerOTTTL]."', '".$data[ROBOTTTLdata][$i][ROB_QtyOTTTL]."', 'ROB_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPOTTTLdata][$i][CONSP_BunkerOTTTL]."', '".$data[CONSPOTTTLdata][$i][CONSP_QtyOTTTL]."', 'CONSP_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPGCTCdata][$i][CONSP_BunkerGC1]."', '".$data[CONSPGCTCdata][$i][CONSP_QtyGC1]."', 'CONSP_TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPGCGFdata][$i][CONSP_BunkerGCGF]."', '".$data[CONSPGCGFdata][$i][CONSP_QtyGCGF]."', 'CONSP_GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPGCOTdata][$i][CONSP_BunkerGCOT]."', '".$data[CONSPGCOTdata][$i][CONSP_QtyGCOT]."', 'CONSPGC_OTHER_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBGCTTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[ROBGCTTdata][$i][ROB_BunkerGCTT]."', '".$data[ROBGCTTdata][$i][ROB_QtyGCTT]."', 'ROBGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_noon_slave1 (NOONID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['NOONID']."', '".$data[CONSPGCTTLdata][$i][CONSP_BunkerGCTTL]."', '".$data[CONSPGCTTLdata][$i][CONSP_QtyGCTTL]."', 'CONSPGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						if($update){
							$msg = 0;
						}else {
							$msg = 1;
						}
					}
					if($msg == 0)
					{
						$sql3 = "insert into upload_voyage_report_log (LOGINID, ADDONDATE, UPLOAD_NAME, UPLOAD, IDENTITY) values ('".$_SESSION['uid']."', NOW(), '".$uploadname[$i]."', '".$upload[$i]."', 'NOON')";
						mysql_query($sql3,$connect) or die(mysql_error());
						mysql_query("commit");
					}
				} 
				else 
				{
					 $msg = 1;
				}
            }
			
			
			
			if(in_array("ARRIVAL", $textfilename))
			{	            
				$Vessel_Type = isset($data[Vessel_Type]) ? mysql_real_escape_string($data[Vessel_Type]) : '';
				$Message = isset($data[Message]) ? mysql_real_escape_string($data[Message]) : '';
				$Report_Title = isset($data[Report_Title]) ? mysql_real_escape_string($data[Report_Title]) : '';
				$Vessel_Name = isset($data[Vessel_Name]) ? mysql_real_escape_string($data[Vessel_Name]) : '';
				$Vessel_IMO_NO = isset($data[Vessel_IMO_NO]) ? mysql_real_escape_string($data[Vessel_IMO_NO]) : '';
				$SSP_FAOP_Date_Time = isset($data[EOSP_Date]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[EOSP_Date]))) : '';
				$Reporting_Date_Time = isset($data[Reporting_Date_Time]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Reporting_Date_Time]))) : '';
				$Prefix = isset($data[Prefix]) ? mysql_real_escape_string($data[Prefix]) : '';
				$Time_Relative_to_UTC = isset($data[Time_Relative_to_UTC]) ? mysql_real_escape_string($data[Time_Relative_to_UTC]) : '';
				$Reporting_Date_Time_UTC = isset($data[Reporting_Date_Time_UTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Reporting_Date_Time_UTC]))) : '';
				$Voy_No = isset($data[Voy_No]) ? mysql_real_escape_string($data[Voy_No]) : '';
				$Draft_Fore = isset($data[Draft_Fore]) ? mysql_real_escape_string($data[Draft_Fore]) : '';
				$Draft_Aft = isset($data[Draft_Aft]) ? mysql_real_escape_string($data[Draft_Aft]) : '';
				$Port_Of_Arrival = isset($data[Port_Of_Arrival]) ? mysql_real_escape_string($data[Port_Of_Arrival]) : '';
				$Port_Visit_Reason = isset($data[Port_Visit_Reason]) ? mysql_real_escape_string($data[Port_Visit_Reason]) : '';
				$Vessel_Condition = isset($data[Vessel_Condition]) ? mysql_real_escape_string($data[Vessel_Condition]) : '';
				$Weather_Direction = isset($data[Weather_Direction]) ? mysql_real_escape_string($data[Weather_Direction]) : '';
				$Wind_Force = isset($data[Wind_Force]) ? mysql_real_escape_string($data[Wind_Force]) : '';
				$Sea_State = isset($data[Sea_State]) ? mysql_real_escape_string($data[Sea_State]) : '';
				$Swell_State = isset($data[Swell_State]) ? mysql_real_escape_string($data[Swell_State]) : '';
				$Swell_Dirn = isset($data[Swell_Dirn]) ? mysql_real_escape_string($data[Swell_Dirn]) : '';
				$Lat = isset($data[Lat]) ? mysql_real_escape_string($data[Lat]) : '';
				$Min1 = isset($data[Min1]) ? mysql_real_escape_string($data[Min1]) : '';
				$Deg1 = isset($data[Deg1]) ? mysql_real_escape_string($data[Deg1]) : '';
				$Long = isset($data[Long]) ? mysql_real_escape_string($data[Long]) : '';
				$Deg2 = isset($data[Deg2]) ? mysql_real_escape_string($data[Deg2]) : '';
				$Min2 = isset($data[Min2]) ? mysql_real_escape_string($data[Min2]) : '';
				$ObsdDistance = isset($data[ObsdDistance]) ? mysql_real_escape_string($data[ObsdDistance]) : '';
				
				$NoonHDG = isset($data[NoonHDG]) ? mysql_real_escape_string($data[NoonHDG]) : '';
				$StoppageHrs = isset($data[StoppageHrs]) ? mysql_real_escape_string($data[StoppageHrs]) : '';
				$EffectiveSteaming = isset($data[EffectiveSteaming]) ? mysql_real_escape_string($data[EffectiveSteaming]) : '';
				$ObsdSpeed = isset($data[ObsdSpeed]) ? mysql_real_escape_string($data[ObsdSpeed]) : '';
				$Voyage_dist = isset($data[Voyage_dist]) ? mysql_real_escape_string($data[Voyage_dist]) : '';		
				$Downtimedata = isset($data[Downtimedata]) ? mysql_real_escape_string($data[Downtimedata]) : '';
				$ROBdata = isset($data[ROBdata]) ? mysql_real_escape_string($data[ROBdata]) : '';
				$CONSPdata = isset($data[CONSPdata]) ? mysql_real_escape_string($data[CONSPdata]) : '';
				$CONSPOTdata = isset($data[CONSPOTdata]) ? mysql_real_escape_string($data[CONSPOTdata]) : '';
				$CONSPOTTCdata = isset($data[CONSPOTTCdata]) ? mysql_real_escape_string($data[CONSPOTTCdata]) : '';
				$CONSPOTGFdata = isset($data[CONSPOTGFdata]) ? mysql_real_escape_string($data[CONSPOTGFdata]) : '';
				$CONSPOTOTdata = isset($data[CONSPOTOTdata]) ? mysql_real_escape_string($data[CONSPOTOTdata]) : '';
				$ROBOTTTLdata = isset($data[ROBOTTTLdata]) ? mysql_real_escape_string($data[ROBOTTTLdata]) : '';
				$CONSPOTTTLdata = isset($data[CONSPOTTTLdata]) ? mysql_real_escape_string($data[CONSPOTTTLdata]) : '';
				$CONSPGCdata = isset($data[CONSPGCdata]) ? mysql_real_escape_string($data[CONSPGCdata]) : '';
				$CONSPGCTCdata = isset($data[CONSPGCTCdata]) ? mysql_real_escape_string($data[CONSPGCTCdata]) : '';
				$CONSPGCGFdata = isset($data[CONSPGCGFdata]) ? mysql_real_escape_string($data[CONSPGCGFdata]) : '';
				$CONSPGCOTdata = isset($data[CONSPGCOTdata]) ? mysql_real_escape_string($data[CONSPGCOTdata]) : '';
				$ROBGCTTdata = isset($data[ROBGCTTdata]) ? mysql_real_escape_string($data[ROBGCTTdata]) : '';
				$CONSPGCTTLdata = isset($data[CONSPGCTTLdata]) ? mysql_real_escape_string($data[CONSPGCTTLdata]) : '';
				
				$ETB_Next_Port = isset($data[ETB_Next_Port]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[ETB_Next_Port]))) : '';
				$ETA_Next_Port = isset($data[ETA_Next_Port]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[ETA_Next_Port]))) : '';
				$Remarks = isset($data[Remarks]) ? mysql_real_escape_string(addslashes($data[Remarks])) : '';
				
				if(!empty(trim($Vessel_IMO_NO)))
				{
				$sql = "select * from sa_arrival_master where IMO_NO = '".trim($Vessel_IMO_NO)."' and date(REPORTING_DATETIME_LT)='".date('Y-m-d', strtotime($Reporting_Date_Time))."' and MESSAGE_NO='".$Message."'";
				$res = mysql_query($sql);
				$rec = mysql_num_rows($res);
				if($rec == 0)
					{
						$query = "INSERT INTO sa_arrival_master (VESSEL_TYPE, MESSAGE_NO, REPORT_TITLE, VESSEL_NAME, IMO_NO, SSP_FAOP_DATE_TIME, REPORTING_DATETIME_LT, TIME_RELATIVE_UTC, REPORTING_DATETIME_UTC, VOYAGE_NO, DRAFT_FORE, DRAFT_AFT, VESSEL_CONDITION, WEATHER_DIRECTION, WIND_FORCE, SEA_STATE, SWEEL_STATE, SWELL_DIRN, LATTITUDE, LAT_DEG, LAT_MIN, LONGITUDE, LONG_DEG, LONG_MIN, VOYAGE_DISTANCE, ETA_NEXT_PORT, REMARKS, PREFIX, ADDONDATE, OBSERVED_DIST, STOPPAGE, EFFECTIVE_STEAMING, OBSERVED_SPEED, PORT_OF_ARRIVAL, PORT_VISIT_REASON, ETB_DATE) VALUES ('".addslashes($Vessel_Type)."','".addslashes($Message)."','".addslashes($Report_Title)."','".addslashes($Vessel_Name)."','".addslashes($Vessel_IMO_NO)."','".$SSP_FAOP_Date_Time."','".$Reporting_Date_Time."','".$Time_Relative_to_UTC."','".$Reporting_Date_Time_UTC."','".addslashes($Voy_No)."','".$Draft_Fore."','".$Draft_Aft."','".addslashes($Vessel_Condition)."','".addslashes($Weather_Direction)."', '".$Wind_Force."','".$Sea_State."','".$Swell_State."','".$Swell_Dirn."','".$Lat."','".$Deg1."','".$Min1."','".$Long."','".$Deg2."','".$Min2."','".$Voyage_dist."','".$ETA_Next_Port."','".addslashes($Remarks)."','".$Prefix."',NOW(),'".addslashes($ObsdDistance)."','".addslashes($StoppageHrs)."','".addslashes($EffectiveSteaming)."','".addslashes($ObsdSpeed)."','".addslashes($Port_Of_Arrival)."','".addslashes($Port_Visit_Reason)."','".addslashes($ETB_Next_Port)."')";
						$insert = mysql_query($query);
						
						$sql1 = "select max(ARRIVALID) as max from sa_arrival_master";
						$res1 = mysql_query($sql1);
						$rows1 = mysql_fetch_assoc($res1);
						
						
						for($i=0;$i<count($data[Downtimedata]);$i++)
						{
						    $DowntimeFromLT = isset($data[Downtimedata][$i][DowntimeFromLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromLT]))) : '';
							$DowntimeFromUTC = isset($data[Downtimedata][$i][DowntimeFromUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromUTC]))) : '';
							$DowntimeToLT = isset($data[Downtimedata][$i][DowntimeToLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToLT]))) : '';
							$DowntimeToUTC = isset($data[Downtimedata][$i][DowntimeToUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToUTC]))) : '';
							
						    $sql2 = "INSERT INTO sa_arrival_slave2 (ARRIVALID, DOWNTIME_TYPE, FROM_LT_DATETIME, FROM_PREFIX, FROM_TIMEZONE, FROM_UTC_DATETIME, TO_LT_DATETIME, TO_PREFIX, TO_TIMEZONE, TO_UTC_DATETIME, REMARKS) VALUES ('".$rows1['max']."', '".$data[Downtimedata][$i][Downtime]."', '".$DowntimeFromLT."', '".$data[Downtimedata][$i][PrefixFrom]."', '".$data[Downtimedata][$i][TimeZoneFrom]."', '".$DowntimeFromUTC."','".$DowntimeToLT."','".$data[Downtimedata][$i][PrefixTo]."','".$data[Downtimedata][$i][TimeZoneTo]."','".$DowntimeToUTC."','".$data[Downtimedata][$i][DwntimeRemark]."')";
							mysql_query($sql2) or die($sql2);
							
							$sqlalave1 = "select max(ARRIVAL_SLAVEID) as max from sa_arrival_slave2";
							$resslave1 = mysql_query($sqlalave1);
							$rowsslave1 = mysql_fetch_assoc($resslave1);
							
							for($j=0;$j<count($data[Downtimedata][$i][EOSPBunker]);$j++)
							{
								$sql2 = "INSERT INTO sa_arrival_slave3 (ARRIVALID, ARRIVAL_SLAVEID, BUNKER, QUANTITY) VALUES ('".$rows1['max']."', '".$rowsslave1['max']."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Bunker]."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Qty]."')";
								mysql_query($sql2) or die($sql2);
							}
						}
						
						
						for($i=0;$i<count($data[ROBdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBdata][$i][ROB_Bunker]."', '".$data[ROBdata][$i][ROB_Qty]."', 'ROB_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPdata][$i][CONSP_Bunker]."', '".$data[CONSPdata][$i][CONSP_Qty]."', 'CONSUMPTION_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTdata][$i][CONSP_BunkerOT]."', '".$data[CONSPOTdata][$i][CONSP_QtyOT]."', 'MAINPROP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTTCdata][$i][CONSP_BunkerOTTC]."', '".$data[CONSPOTTCdata][$i][CONSP_QtyOTTC]."', 'TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTGFdata][$i][CONSP_BunkerOTGF]."', '".$data[CONSPOTGFdata][$i][CONSP_QtyOTGF]."', 'GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTOTdata][$i][CONSP_BunkerOTOT]."', '".$data[CONSPOTOTdata][$i][CONSP_QtyOTOT]."', 'OT_OTHERS_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBOTTTLdata][$i][ROB_BunkerOTTTL]."', '".$data[ROBOTTTLdata][$i][ROB_QtyOTTTL]."', 'ROB_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTTTLdata][$i][CONSP_BunkerOTTTL]."', '".$data[CONSPOTTTLdata][$i][CONSP_QtyOTTTL]."', 'CONSP_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCTCdata][$i][CONSP_BunkerGC1]."', '".$data[CONSPGCTCdata][$i][CONSP_QtyGC1]."', 'CONSP_TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCGFdata][$i][CONSP_BunkerGCGF]."', '".$data[CONSPGCGFdata][$i][CONSP_QtyGCGF]."', 'CONSP_GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCOTdata][$i][CONSP_BunkerGCOT]."', '".$data[CONSPGCOTdata][$i][CONSP_QtyGCOT]."', 'CONSPGC_OTHER_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBGCTTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBGCTTdata][$i][ROB_BunkerGCTT]."', '".$data[ROBGCTTdata][$i][ROB_QtyGCTT]."', 'ROBGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCTTLdata][$i][CONSP_BunkerGCTTL]."', '".$data[CONSPGCTTLdata][$i][CONSP_QtyGCTTL]."', 'CONSPGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						if($insert){
							$msg = 0;
						} else {
							$msg = 1;
						}		
					}
				else{
						$rows = mysql_fetch_assoc($res);
						
						$query = "update sa_arrival_master set VESSEL_TYPE='".addslashes($Vessel_Type)."', MESSAGE_NO='".addslashes($Message)."', REPORT_TITLE='".addslashes($Report_Title)."', VESSEL_NAME='".addslashes($Vessel_Name)."', IMO_NO='".addslashes($Vessel_IMO_NO)."', SSP_FAOP_DATE_TIME='".$SSP_FAOP_Date_Time."', REPORTING_DATETIME_LT='".$Reporting_Date_Time."', TIME_RELATIVE_UTC='".$Time_Relative_to_UTC."', REPORTING_DATETIME_UTC='".$Reporting_Date_Time_UTC."', VOYAGE_NO='".addslashes($Voy_No)."', DRAFT_FORE='".$Draft_Fore."', DRAFT_AFT='".$Draft_Aft."', VESSEL_CONDITION='".addslashes($Vessel_Condition)."', WEATHER_DIRECTION='".addslashes($Weather_Direction)."', WIND_FORCE='".$Wind_Force."', SEA_STATE='".$Sea_State."', SWEEL_STATE='".$Swell_State."', SWELL_DIRN='".$Swell_Dirn."', LATTITUDE='".$Lat."', LAT_DEG='".$Deg1."', LAT_MIN='".$Min1."', LONGITUDE='".$Long."', LONG_DEG='".$Deg2."', LONG_MIN='".$Min2."', VOYAGE_DISTANCE='".$Voyage_dist."', ETA_NEXT_PORT='".$ETA_Next_Port."', REMARKS='".addslashes($Remarks)."', PREFIX='".$Prefix."', UPDATEONDATE=NOW(), OBSERVED_DIST='".addslashes($ObsdDistance)."', STOPPAGE='".addslashes($StoppageHrs)."', EFFECTIVE_STEAMING='".addslashes($EffectiveSteaming)."', OBSERVED_SPEED='".addslashes($ObsdSpeed)."', PORT_OF_ARRIVAL='".addslashes($Port_Of_Arrival)."', PORT_VISIT_REASON='".addslashes($Port_Visit_Reason)."', ETB_DATE='".addslashes($ETB_Next_Port)."' where ARRIVALID='".$rows['ARRIVALID']."'";
						$update = mysql_query($query);
						
						$sql1 = "delete from sa_arrival_slave1 where ARRIVALID='".$rows['ARRIVALID']."'";
						$sql2 = "delete from sa_arrival_slave2 where ARRIVALID='".$rows['ARRIVALID']."'";
						$sql3 = "delete from sa_arrival_slave3 where ARRIVALID='".$rows['ARRIVALID']."'";
						mysql_query($sql1);
						mysql_query($sql2);
						mysql_query($sql3);
						
						for($i=0;$i<count($data[Downtimedata]);$i++)
						{
						    $DowntimeFromLT = isset($data[Downtimedata][$i][DowntimeFromLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromLT]))) : '';
							$DowntimeFromUTC = isset($data[Downtimedata][$i][DowntimeFromUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromUTC]))) : '';
							$DowntimeToLT = isset($data[Downtimedata][$i][DowntimeToLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToLT]))) : '';
							$DowntimeToUTC = isset($data[Downtimedata][$i][DowntimeToUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToUTC]))) : '';
							
						    $sql2 = "INSERT INTO sa_arrival_slave2 (ARRIVALID, DOWNTIME_TYPE, FROM_LT_DATETIME, FROM_PREFIX, FROM_TIMEZONE, FROM_UTC_DATETIME, TO_LT_DATETIME, TO_PREFIX, TO_TIMEZONE, TO_UTC_DATETIME, REMARKS) VALUES ('".$rows['ARRIVALID']."', '".$data[Downtimedata][$i][Downtime]."', '".$DowntimeFromLT."', '".$data[Downtimedata][$i][PrefixFrom]."', '".$data[Downtimedata][$i][TimeZoneFrom]."', '".$DowntimeFromUTC."','".$DowntimeToLT."','".$data[Downtimedata][$i][PrefixTo]."','".$data[Downtimedata][$i][TimeZoneTo]."','".$DowntimeToUTC."','".$data[Downtimedata][$i][DwntimeRemark]."')";
							mysql_query($sql2) or die($sql2);
							
							$sqlalave1 = "select max(ARRIVAL_SLAVEID) as max from sa_arrival_slave2";
							$resslave1 = mysql_query($sqlalave1);
							$rowsslave1 = mysql_fetch_assoc($resslave1);
							
							for($j=0;$j<count($data[Downtimedata][$i][EOSPBunker]);$j++)
							{
								$sql2 = "INSERT INTO sa_arrival_slave3 (ARRIVALID, ARRIVAL_SLAVEID, BUNKER, QUANTITY) VALUES ('".$rows['ARRIVALID']."', '".$rowsslave1['max']."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Bunker]."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Qty]."')";
								mysql_query($sql2) or die($sql2);
							}
						}
						
						for($i=0;$i<count($data[EOSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[EOSPdata][$i][EOSP_Bunker]."', '".$data[EOSPdata][$i][EOSP_Qty]."', 'DOWNTIME_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[ROBdata][$i][ROB_Bunker]."', '".$data[ROBdata][$i][ROB_Qty]."', 'ROB_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPdata][$i][CONSP_Bunker]."', '".$data[CONSPdata][$i][CONSP_Qty]."', 'CONSUMPTION_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPOTdata][$i][CONSP_BunkerOT]."', '".$data[CONSPOTdata][$i][CONSP_QtyOT]."', 'MAINPROP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPOTTCdata][$i][CONSP_BunkerOTTC]."', '".$data[CONSPOTTCdata][$i][CONSP_QtyOTTC]."', 'TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPOTGFdata][$i][CONSP_BunkerOTGF]."', '".$data[CONSPOTGFdata][$i][CONSP_QtyOTGF]."', 'GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPOTOTdata][$i][CONSP_BunkerOTOT]."', '".$data[CONSPOTOTdata][$i][CONSP_QtyOTOT]."', 'OT_OTHERS_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[ROBOTTTLdata][$i][ROB_BunkerOTTTL]."', '".$data[ROBOTTTLdata][$i][ROB_QtyOTTTL]."', 'ROB_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPOTTTLdata][$i][CONSP_BunkerOTTTL]."', '".$data[CONSPOTTTLdata][$i][CONSP_QtyOTTTL]."', 'CONSP_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPGCTCdata][$i][CONSP_BunkerGC1]."', '".$data[CONSPGCTCdata][$i][CONSP_QtyGC1]."', 'CONSP_TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPGCGFdata][$i][CONSP_BunkerGCGF]."', '".$data[CONSPGCGFdata][$i][CONSP_QtyGCGF]."', 'CONSP_GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPGCOTdata][$i][CONSP_BunkerGCOT]."', '".$data[CONSPGCOTdata][$i][CONSP_QtyGCOT]."', 'CONSPGC_OTHER_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBGCTTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[ROBGCTTdata][$i][ROB_BunkerGCTT]."', '".$data[ROBGCTTdata][$i][ROB_QtyGCTT]."', 'ROBGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_arrival_slave1 (ARRIVALID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['ARRIVALID']."', '".$data[CONSPGCTTLdata][$i][CONSP_BunkerGCTTL]."', '".$data[CONSPGCTTLdata][$i][CONSP_QtyGCTTL]."', 'CONSPGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						if($update){
							$msg = 0;
						}else {
							$msg = 1;
						}
					}
					if($msg == 0)
					{
						$sql3 = "insert into upload_voyage_report_log (LOGINID, ADDONDATE, UPLOAD_NAME, UPLOAD, IDENTITY) values ('".$_SESSION['uid']."', NOW(), '".$uploadname[$i]."', '".$upload[$i]."', 'ARRIVAL')";
						mysql_query($sql3,$connect) or die(mysql_error());
						mysql_query("commit");
					}
				} 
				else 
				{
					 $msg = 1;
				}
			}
			
			
			
			if(in_array("PORTMESSAGE", $textfilename))
			{	            
				$Vessel_Type = isset($data[Vessel_Type]) ? mysql_real_escape_string($data[Vessel_Type]) : '';
				$Message = isset($data[Message]) ? mysql_real_escape_string($data[Message]) : '';
				$Report_Title = isset($data[Report_Title]) ? mysql_real_escape_string($data[Report_Title]) : '';
				$Vessel_Name = isset($data[Vessel_Name]) ? mysql_real_escape_string($data[Vessel_Name]) : '';
				$Vessel_IMO_NO = isset($data[Vessel_IMO_NO]) ? mysql_real_escape_string($data[Vessel_IMO_NO]) : '';
				$Reporting_Date_Time = isset($data[Reporting_Date_Time]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Reporting_Date_Time]))) : '';
				$Prefix = isset($data[Prefix]) ? mysql_real_escape_string($data[Prefix]) : '';
				$Time_Relative_to_UTC = isset($data[Time_Relative_to_UTC]) ? mysql_real_escape_string($data[Time_Relative_to_UTC]) : '';
				$Reporting_Date_Time_UTC = isset($data[Reporting_Date_Time_UTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Reporting_Date_Time_UTC]))) : '';
				$Voy_No = isset($data[Voy_No]) ? mysql_real_escape_string($data[Voy_No]) : '';
				
				$Port_Of_Arrival = isset($data[Port_Of_arrival]) ? mysql_real_escape_string($data[Port_Of_arrival]) : '';
				$Remarks = isset($data[Remarks]) ? mysql_real_escape_string($data[Remarks]) : '';
				$Downtimedata = isset($data[Downtimedata]) ? mysql_real_escape_string($data[Downtimedata]) : '';
				$ROBdata = isset($data[ROBdata]) ? mysql_real_escape_string($data[ROBdata]) : '';
				$CONSPdata = isset($data[CONSPdata]) ? mysql_real_escape_string($data[CONSPdata]) : '';
				$CONSPOTdata = isset($data[CONSPOTdata]) ? mysql_real_escape_string($data[CONSPOTdata]) : '';
				$CONSPOTTCdata = isset($data[CONSPOTTCdata]) ? mysql_real_escape_string($data[CONSPOTTCdata]) : '';
				$CONSPOTGFdata = isset($data[CONSPOTGFdata]) ? mysql_real_escape_string($data[CONSPOTGFdata]) : '';
				$CONSPOTOTdata = isset($data[CONSPOTOTdata]) ? mysql_real_escape_string($data[CONSPOTOTdata]) : '';
				$ROBOTTTLdata = isset($data[ROBOTTTLdata]) ? mysql_real_escape_string($data[ROBOTTTLdata]) : '';
				$CONSPOTTTLdata = isset($data[CONSPOTTTLdata]) ? mysql_real_escape_string($data[CONSPOTTTLdata]) : '';
				$CONSPGCdata = isset($data[CONSPGCdata]) ? mysql_real_escape_string($data[CONSPGCdata]) : '';
				$CONSPGCTCdata = isset($data[CONSPGCTCdata]) ? mysql_real_escape_string($data[CONSPGCTCdata]) : '';
				$CONSPGCGFdata = isset($data[CONSPGCGFdata]) ? mysql_real_escape_string($data[CONSPGCGFdata]) : '';
				$CONSPGCOTdata = isset($data[CONSPGCOTdata]) ? mysql_real_escape_string($data[CONSPGCOTdata]) : '';
				$ROBGCTTdata = isset($data[ROBGCTTdata]) ? mysql_real_escape_string($data[ROBGCTTdata]) : '';
				$CONSPGCTTLdata = isset($data[CONSPGCTTLdata]) ? mysql_real_escape_string($data[CONSPGCTTLdata]) : '';
				$BRSUPPLIEDdata = isset($data[BRSUPPLIEDdata]) ? mysql_real_escape_string($data[BRSUPPLIEDdata]) : '';
				
				if(!empty(trim($Vessel_IMO_NO)))
				{
				$sql = "select * from sa_portmessage_master where IMO_NO = '".trim($Vessel_IMO_NO)."' and date(REPORTING_DATETIME_LT)='".date('Y-m-d', strtotime($Reporting_Date_Time))."' and MESSAGE_NO='".$Message."'";
				$res = mysql_query($sql);
				$rec = mysql_num_rows($res);
				if($rec == 0)
					{
						$query = "INSERT INTO sa_portmessage_master (VESSEL_TYPE, MESSAGE_NO, REPORT_TITLE, VESSEL_NAME, IMO_NO, REPORTING_DATETIME_LT, TIME_RELATIVE_UTC, REPORTING_DATETIME_UTC, VOYAGE_NO, REMARKS, PREFIX, ADDONDATE, PORT_OF_ARRIVAL) VALUES ('".addslashes($Vessel_Type)."','".addslashes($Message)."','".addslashes($Report_Title)."','".addslashes($Vessel_Name)."','".addslashes($Vessel_IMO_NO)."','".$Reporting_Date_Time."','".$Time_Relative_to_UTC."','".$Reporting_Date_Time_UTC."','".addslashes($Voy_No)."','".addslashes($Remarks)."','".$Prefix."',NOW(),'".addslashes($Port_Of_Arrival)."')";
						$insert = mysql_query($query);
						
						$sql1 = "select max(PORTMESSAGEID) as max from sa_portmessage_master";
						$res1 = mysql_query($sql1);
						$rows1 = mysql_fetch_assoc($res1);
						
						
						for($i=0;$i<count($data[Downtimedata]);$i++)
						{
						    $DowntimeFromLT = isset($data[Downtimedata][$i][DowntimeFromLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromLT]))) : '';
							$DowntimeFromUTC = isset($data[Downtimedata][$i][DowntimeFromUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromUTC]))) : '';
							$DowntimeToLT = isset($data[Downtimedata][$i][DowntimeToLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToLT]))) : '';
							$DowntimeToUTC = isset($data[Downtimedata][$i][DowntimeToUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToUTC]))) : '';
							
						    $sql2 = "INSERT INTO sa_portmessage_slave2 (PORTMESSAGEID, DOWNTIME_TYPE, FROM_LT_DATETIME, FROM_PREFIX, FROM_TIMEZONE, FROM_UTC_DATETIME, TO_LT_DATETIME, TO_PREFIX, TO_TIMEZONE, TO_UTC_DATETIME, REMARKS) VALUES ('".$rows1['max']."', '".$data[Downtimedata][$i][Downtime]."', '".$DowntimeFromLT."', '".$data[Downtimedata][$i][PrefixFrom]."', '".$data[Downtimedata][$i][TimeZoneFrom]."', '".$DowntimeFromUTC."','".$DowntimeToLT."','".$data[Downtimedata][$i][PrefixTo]."','".$data[Downtimedata][$i][TimeZoneTo]."','".$DowntimeToUTC."','".$data[Downtimedata][$i][DwntimeRemark]."')";
							mysql_query($sql2) or die($sql2);
							
							$sqlalave1 = "select max(PORTMESSAGE_SLAVEID) as max from sa_portmessage_slave2";
							$resslave1 = mysql_query($sqlalave1);
							$rowsslave1 = mysql_fetch_assoc($resslave1);
							
							for($j=0;$j<count($data[Downtimedata][$i][EOSPBunker]);$j++)
							{
								$sql2 = "INSERT INTO sa_portmessage_slave3 (PORTMESSAGEID, PORTMESSAGE_SLAVEID, BUNKER, QUANTITY) VALUES ('".$rows1['max']."', '".$rowsslave1['max']."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Bunker]."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Qty]."')";
								mysql_query($sql2) or die($sql2);
							}
						}
						
						for($i=0;$i<count($data[BRSUPPLIEDdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave4 (PORTMESSAGEID, BUNKER, QUANTITY, SUPPLIER, RATE_MT, ADDNL_COST, TOTAL_COST) VALUES ('".$rows1['max']."', '".$data[BRSUPPLIEDdata][$i][BR_BunkerGrade]."', '".$data[BRSUPPLIEDdata][$i][BR_Supplied]."', '".$data[BRSUPPLIEDdata][$i][BR_Supplier]."', '".$data[BRSUPPLIEDdata][$i][BR_SuppliedPrice]."', '".$data[BRSUPPLIEDdata][$i][BR_ADDCost]."', '".$data[BRSUPPLIEDdata][$i][BR_TotalValue]."')";
							mysql_query($sql2) or die($sql2);
						}
						
						
						for($i=0;$i<count($data[ROBdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBdata][$i][ROB_Bunker]."', '".$data[ROBdata][$i][ROB_Qty]."', 'ROB_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPdata][$i][CONSP_Bunker]."', '".$data[CONSPdata][$i][CONSP_Qty]."', 'CONSUMPTION_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTdata][$i][CONSP_BunkerOT]."', '".$data[CONSPOTdata][$i][CONSP_QtyOT]."', 'MAINPROP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTTCdata][$i][CONSP_BunkerOTTC]."', '".$data[CONSPOTTCdata][$i][CONSP_QtyOTTC]."', 'TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTGFdata][$i][CONSP_BunkerOTGF]."', '".$data[CONSPOTGFdata][$i][CONSP_QtyOTGF]."', 'GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTOTdata][$i][CONSP_BunkerOTOT]."', '".$data[CONSPOTOTdata][$i][CONSP_QtyOTOT]."', 'OT_OTHERS_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBOTTTLdata][$i][ROB_BunkerOTTTL]."', '".$data[ROBOTTTLdata][$i][ROB_QtyOTTTL]."', 'ROB_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPOTTTLdata][$i][CONSP_BunkerOTTTL]."', '".$data[CONSPOTTTLdata][$i][CONSP_QtyOTTTL]."', 'CONSP_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCTCdata][$i][CONSP_BunkerGC1]."', '".$data[CONSPGCTCdata][$i][CONSP_QtyGC1]."', 'CONSP_TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCGFdata][$i][CONSP_BunkerGCGF]."', '".$data[CONSPGCGFdata][$i][CONSP_QtyGCGF]."', 'CONSP_GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCOTdata][$i][CONSP_BunkerGCOT]."', '".$data[CONSPGCOTdata][$i][CONSP_QtyGCOT]."', 'CONSPGC_OTHER_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBGCTTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[ROBGCTTdata][$i][ROB_BunkerGCTT]."', '".$data[ROBGCTTdata][$i][ROB_QtyGCTT]."', 'ROBGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows1['max']."', '".$data[CONSPGCTTLdata][$i][CONSP_BunkerGCTTL]."', '".$data[CONSPGCTTLdata][$i][CONSP_QtyGCTTL]."', 'CONSPGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						if($insert){
							$msg = 0;
						} else {
							$msg = 1;
						}		
					}
				else{
						$rows = mysql_fetch_assoc($res);
						
						$query = "update sa_portmessage_master set VESSEL_TYPE='".addslashes($Vessel_Type)."', MESSAGE_NO='".addslashes($Message)."', REPORT_TITLE='".addslashes($Report_Title)."', VESSEL_NAME='".addslashes($Vessel_Name)."', IMO_NO='".addslashes($Vessel_IMO_NO)."', REPORTING_DATETIME_LT='".$Reporting_Date_Time."', TIME_RELATIVE_UTC='".$Time_Relative_to_UTC."', REPORTING_DATETIME_UTC='".$Reporting_Date_Time_UTC."', VOYAGE_NO='".addslashes($Voy_No)."', REMARKS='".addslashes($Remarks)."', PREFIX='".$Prefix."', UPDATEONDATE=NOW(), PORT_OF_ARRIVAL='".addslashes($Port_Of_Arrival)."' where PORTMESSAGEID='".$rows['PORTMESSAGEID']."'";
						$update = mysql_query($query);
						
						$sql1 = "delete from sa_portmessage_slave1 where PORTMESSAGEID='".$rows['PORTMESSAGEID']."'";
						$sql2 = "delete from sa_portmessage_slave2 where PORTMESSAGEID='".$rows['PORTMESSAGEID']."'";
						$sql3 = "delete from sa_portmessage_slave3 where PORTMESSAGEID='".$rows['PORTMESSAGEID']."'";
						$sql4 = "delete from sa_portmessage_slave4 where PORTMESSAGEID='".$rows['PORTMESSAGEID']."'";
						mysql_query($sql1);
						mysql_query($sql2);
						mysql_query($sql3);
						mysql_query($sql4);
						
						for($i=0;$i<count($data[Downtimedata]);$i++)
						{
						    $DowntimeFromLT = isset($data[Downtimedata][$i][DowntimeFromLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromLT]))) : '';
							$DowntimeFromUTC = isset($data[Downtimedata][$i][DowntimeFromUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeFromUTC]))) : '';
							$DowntimeToLT = isset($data[Downtimedata][$i][DowntimeToLT]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToLT]))) : '';
							$DowntimeToUTC = isset($data[Downtimedata][$i][DowntimeToUTC]) ? date('Y-m-d H:i:s',strtotime(mysql_real_escape_string($data[Downtimedata][$i][DowntimeToUTC]))) : '';
							
						    $sql2 = "INSERT INTO sa_portmessage_slave2 (PORTMESSAGEID, DOWNTIME_TYPE, FROM_LT_DATETIME, FROM_PREFIX, FROM_TIMEZONE, FROM_UTC_DATETIME, TO_LT_DATETIME, TO_PREFIX, TO_TIMEZONE, TO_UTC_DATETIME, REMARKS) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[Downtimedata][$i][Downtime]."', '".$DowntimeFromLT."', '".$data[Downtimedata][$i][PrefixFrom]."', '".$data[Downtimedata][$i][TimeZoneFrom]."', '".$DowntimeFromUTC."','".$DowntimeToLT."','".$data[Downtimedata][$i][PrefixTo]."','".$data[Downtimedata][$i][TimeZoneTo]."','".$DowntimeToUTC."','".$data[Downtimedata][$i][DwntimeRemark]."')";
							mysql_query($sql2) or die($sql2);
							
							$sqlalave1 = "select max(PORTMESSAGE_SLAVEID) as max from sa_portmessage_slave2";
							$resslave1 = mysql_query($sqlalave1);
							$rowsslave1 = mysql_fetch_assoc($resslave1);
							
							for($j=0;$j<count($data[Downtimedata][$i][EOSPBunker]);$j++)
							{
								$sql2 = "INSERT INTO sa_portmessage_slave3 (PORTMESSAGEID, PORTMESSAGE_SLAVEID, BUNKER, QUANTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$rowsslave1['max']."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Bunker]."', '".$data[Downtimedata][$i][EOSPBunker][$j][DownEOSP_Qty]."')";
								mysql_query($sql2) or die($sql2);
							}
						}
						
						for($i=0;$i<count($data[BRSUPPLIEDdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave4 (PORTMESSAGEID, BUNKER, QUANTITY, SUPPLIER, RATE_MT, ADDNL_COST, TOTAL_COST) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[BRSUPPLIEDdata][$i][BR_BunkerGrade]."', '".$data[BRSUPPLIEDdata][$i][BR_Supplied]."', '".$data[BRSUPPLIEDdata][$i][BR_Supplier]."', '".$data[BRSUPPLIEDdata][$i][BR_SuppliedPrice]."', '".$data[BRSUPPLIEDdata][$i][BR_ADDCost]."', '".$data[BRSUPPLIEDdata][$i][BR_TotalValue]."')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[EOSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[EOSPdata][$i][EOSP_Bunker]."', '".$data[EOSPdata][$i][EOSP_Qty]."', 'DOWNTIME_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[ROBdata][$i][ROB_Bunker]."', '".$data[ROBdata][$i][ROB_Qty]."', 'ROB_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPdata][$i][CONSP_Bunker]."', '".$data[CONSPdata][$i][CONSP_Qty]."', 'CONSUMPTION_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPOTdata][$i][CONSP_BunkerOT]."', '".$data[CONSPOTdata][$i][CONSP_QtyOT]."', 'MAINPROP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPOTTCdata][$i][CONSP_BunkerOTTC]."', '".$data[CONSPOTTCdata][$i][CONSP_QtyOTTC]."', 'TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPOTGFdata][$i][CONSP_BunkerOTGF]."', '".$data[CONSPOTGFdata][$i][CONSP_QtyOTGF]."', 'GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPOTOTdata][$i][CONSP_BunkerOTOT]."', '".$data[CONSPOTOTdata][$i][CONSP_QtyOTOT]."', 'OT_OTHERS_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[ROBOTTTLdata][$i][ROB_BunkerOTTTL]."', '".$data[ROBOTTTLdata][$i][ROB_QtyOTTTL]."', 'ROB_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPOTTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPOTTTLdata][$i][CONSP_BunkerOTTTL]."', '".$data[CONSPOTTTLdata][$i][CONSP_QtyOTTTL]."', 'CONSP_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPGCdata][$i][CONSP_BunkerGC]."', '".$data[CONSPGCdata][$i][CONSP_QtyGC]."', 'CONSP_MP_AE_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTCdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPGCTCdata][$i][CONSP_BunkerGC1]."', '".$data[CONSPGCTCdata][$i][CONSP_QtyGC1]."', 'CONSP_TANK_CLEANING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCGFdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPGCGFdata][$i][CONSP_BunkerGCGF]."', '".$data[CONSPGCGFdata][$i][CONSP_QtyGCGF]."', 'CONSP_GAS_FREEING_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCOTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPGCOTdata][$i][CONSP_BunkerGCOT]."', '".$data[CONSPGCOTdata][$i][CONSP_QtyGCOT]."', 'CONSPGC_OTHER_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[ROBGCTTdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[ROBGCTTdata][$i][ROB_BunkerGCTT]."', '".$data[ROBGCTTdata][$i][ROB_QtyGCTT]."', 'ROBGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						for($i=0;$i<count($data[CONSPGCTTLdata]);$i++)
						{
							$sql2 = "INSERT INTO sa_portmessage_slave1 (PORTMESSAGEID, BUNKER, QUANTITY, IDENTITY) VALUES ('".$rows['PORTMESSAGEID']."', '".$data[CONSPGCTTLdata][$i][CONSP_BunkerGCTTL]."', '".$data[CONSPGCTTLdata][$i][CONSP_QtyGCTTL]."', 'CONSPGC_TOTAL_BUNKER')";
							mysql_query($sql2) or die($sql2);
						}
						
						if($update){
							$msg = 0;
						}else {
							$msg = 1;
						}
					}
					if($msg == 0)
					{
						$sql3 = "insert into upload_voyage_report_log (LOGINID, ADDONDATE, UPLOAD_NAME, UPLOAD, IDENTITY) values ('".$_SESSION['uid']."', NOW(), '".$uploadname[$i]."', '".$upload[$i]."', 'PORTMESSAGE')";
						mysql_query($sql3,$connect) or die(mysql_error());
						mysql_query("commit");
					}
				} 
				else 
				{
					 $msg = 1;
				}
			}
			
			
		}
		
		return $msg;
	}
}


function getUploadVoyageReport($upload)
{
	if(gettype($upload['name']) == 'array')
	{
		foreach($upload['name'] as $key=>$value)
		{
			if(trim($upload['name'][$key]) != '')
			{
				$ext_arr = explode(".", $upload['name'][$key]);
				list($txt, $ext) = explode(".", $upload['name'][$key]);
				$filename = substr(number_format(time() * rand(),0,'',''),0,10).'.'.$ext_arr[count($ext_arr) - 1];
				$name[$key] = $filename;
				move_uploaded_file($upload['tmp_name'][$key], '../../voyage_attachments/'.$filename);
			}
		}
	}
	else
	{
		if(trim($upload['name'] ) != '')
		{
			$ext_arr = explode(".", $upload['name']);
			list($txt, $ext) = explode(".", $upload['name']);
			$filename = substr(number_format(time() * rand(),0,'',''),0,10).'.'.$ext_arr[count($ext_arr) - 1];
			$name = $filename;
			move_uploaded_file($upload['tmp_name'], '../../voyage_attachments/'.$filename);
		}
	}
	
	return $name;
}



function getVoyageNoForReport($vesselimono = '')
{
	$this->funConnect();
	if($vesselimono!='')
	{
		$query = "select d.VOYAGE_NO as VOYAGENO, d.VESSEL_NAME as VESSELNAME from sa_departure_master d where d.VESSEL_IMO_ID ='".$vesselimoid."' union select a.VOYAGE_NO as VOYAGENO, a.VESSEL_NAME as VESSELNAME from sa_arrival_master a where a.IMO_NO ='".$vesselimono."' union select n.VOYAGE_NO as VOYAGENO, n.VESSEL_NAME as VESSELNAME from sa_noon_master n where n.IMO_NO ='".$vesselimono."' union select p.VOYAGE_NO as VOYAGENO, p.VESSEL_NAME as VESSELNAME from sa_departure_master p where p.IMO_NO ='".$vesselimono."'";
	}else{
		$query = "select d.VOYAGE_NO as VOYAGENO, d.VESSEL_NAME as VESSELNAME from sa_departure_master d union select a.VOYAGE_NO as VOYAGENO, a.VESSEL_NAME as VESSELNAME from sa_arrival_master a union select n.VOYAGE_NO as VOYAGENO, n.VESSEL_NAME as VESSELNAME from sa_noon_master n union select p.VOYAGE_NO as VOYAGENO, p.VESSEL_NAME as VESSELNAME from sa_departure_master p";
	}
	$i = 0;
	$result = mysql_query($query);
	while($rows = mysql_fetch_assoc($result))
	{   
	    $i++;
	    if($i==1)
		{$this->var_1 = trim($rows['VOYAGENO']);
		$this->var_2 = trim($rows['VESSELNAME']);}
	    $key= trim($rows['VESSELNAME']).'@@@@'.trim($rows['VOYAGENO']);
	    $value= trim($rows['VESSELNAME']).' - '.trim($rows['VOYAGENO']);
	    echo "<option value='".$key."'>".$value."</option>";
	}
}



function displayVoyageReports1($vesselimono='')
{
	if(isset($_REQUEST['selVoyageNo']))
	{
		$selVoyageNo = explode('@@@@',$_REQUEST['selVoyageNo'])[1];
		$selvesselname = explode('@@@@',$_REQUEST['selVoyageNo'])[0];
		$this->var_1 = $selVoyageNo;
		$this->var_2 = $selvesselname;
	}
	else
	{
		$selVoyageNo = $this->getFun1();
		$selvesselname = $this->getFun2();
	}
	$this->funConnect();
	echo '<div class="box-body table-responsive" style="overflow:auto;">';
	echo '<table id="voyagereports" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th align="center" valign="middle" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="8%">Report Title/type</th>';
	echo '<th align="left" valign="middle" width="8%">Vessel Type</th>';
	echo '<th align="left" valign="middle" width="8%">Message No.</th>';
	echo '<th align="left" valign="middle" width="8%">Vessel Name</th>';
	echo '<th align="left" valign="middle" width="8%">Voy No.</th>';
	echo '<th align="left" valign="middle" width="8%">Charterer</th>';
	echo '<th align="left" valign="middle" width="8%">Reporting Date/Time(LT)</th>';
	echo '<th align="left" valign="middle" width="8%">Time Zone</th>';
	echo '<th align="left" valign="middle" width="8%">Reporting Date/Time(UTC)</th>';
	echo '<th align="left" valign="middle" width="8%">Draft Fore(M)</th>';
	echo '<th align="left" valign="middle" width="8%">Draft Fore(A)</th>';
	echo '<th align="left" valign="middle" width="8%">Dep Port</th>';
	echo '<th align="left" valign="middle" width="8%">Port Of Arrival</th>';
	echo '<th align="left" valign="middle" width="8%">Port Visit Reasons</th>';
	echo '<th align="left" valign="middle" width="8%">Next Port</th>';
	echo '<th align="left" valign="middle" width="10%">ETA Next Port</th>';
	echo '<th align="left" valign="middle" width="8%">Vessel Condition</th>';
	echo '<th align="left" valign="middle" width="8%">Weather Direction</th>';
	echo '<th align="left" valign="middle" width="8%">Wind Force</th>';
	echo '<th align="left" valign="middle" width="8%">Sea State</th>';
	echo '<th align="left" valign="middle" width="8%">Swell State</th>';
	echo '<th align="left" valign="middle" width="8%">Swell Direction</th>';
	echo '<th align="left" valign="middle" width="8%">Lat</th>';
	echo '<th align="left" valign="middle" width="8%">Long</th>';
	echo '<th align="left" valign="middle" width="8%">Ordered Speed</th>';
	echo '<th align="left" valign="middle" width="8%">Dist To Go (Nm)</th>';
	echo '<th align="left" valign="middle" width="8%">Total Voyage Dist. (Nm)</th>';
	echo '<th align="left" valign="middle" width="8%">Obsd Dist. (Nm)</th>';
	echo '<th align="left" valign="middle" width="8%">Noon Hdg (Deg)</th>';
	echo '<th align="left" valign="middle" width="8%">Stoppage (Hrs)</th>';
	echo '<th align="left" valign="middle" width="8%">Effective Steaming (Hrs)</th>';
	echo '<th align="left" valign="middle" width="8%">Obsd Speed (Kts)</th>';
	
	echo '<th align="left" valign="middle" width="8%">Down&nbsp;Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>';
	echo '<th align="left" valign="middle" width="8%">Consp (Main Propulsion + AEs)</th>';
	echo '<th align="left" valign="middle" width="8%">Consp (Tank Cleaning/Crude Oil Washing)</th>';
	echo '<th align="left" valign="middle" width="8%">Consp (Gas Freeing/Inerting)</th>';
	echo '<th align="left" valign="middle" width="8%">Consp Other</th>';
	echo '<th align="left" valign="middle" width="8%">Total ROB</th>';
	echo '<th align="left" valign="middle" width="8%">Total Consp</th>';
	echo '<th align="left" valign="middle" width="8%">Bunker Supplied</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	
	$sql = "select * from sa_departure_master WHERE VESSEL_NAME='".$selvesselname."' and VOYAGE_NO='".$selVoyageNo."' order by REPORTING_DATETIME_LT desc ";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['REPORT_TITLE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CHARTERER'].'</td>';
				if($rows['REPORTING_DATETIME_LT']=="" || $rows['REPORTING_DATETIME_LT']=="1970-01-01 00:00"){$REPORTING_DATETIME_LT = "";}else{$REPORTING_DATETIME_LT = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_LT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_LT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PREFIX'].' '.$rows['TIME_RELATIVE_UTC'].'</td>';
				if($rows['REPORTING_DATETIME_UTC']=="" || $rows['REPORTING_DATETIME_UTC']=="1970-01-01 00:00"){$REPORTING_DATETIME_UTC = "";}else{$REPORTING_DATETIME_UTC = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_UTC']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_UTC.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_FORE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_AFT'].'</td>';			
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PORT_DEPARTED_FROM'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NEXT_PORT'].'</td>';
				if($rows['ETA_NEXT_PORT']=="" || $rows['ETA_NEXT_PORT']=="1970-01-01 00:00"){$ETA_NEXT_PORT = "";}else{$ETA_NEXT_PORT = date('d-m-Y H:i',strtotime($rows['ETA_NEXT_PORT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$ETA_NEXT_PORT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_CONDITION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WEATHER_DIRECTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WIND_FORCE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SEA_STATE'].'</td>';				
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWEEL_STATE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWELL_DIRN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LATTITUDE'].' '.$rows['LAT_DEG'].' '.$rows['LAT_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LONGITUDE'].' '.$rows['LONG_DEG'].' '.$rows['LONG_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SPEED_TO_NEXT_PORT'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DISTANCE_TO_GO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				
				$sql2 = "select * from sa_departure_slave WHERE DEPARTUREID='".$rows['DEPARTUREID']."'  ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '</tr>';
				$i++;
		}
	
	}
	
	
	$sql = "select * from sa_noon_master WHERE VESSEL_NAME='".$selvesselname."' and VOYAGE_NO='".$selVoyageNo."' order by REPORTING_DATETIME_LT desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['REPORT_TITLE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['CHARTERER'].'</td>';
				if($rows['REPORTING_DATETIME_LT']=="" || $rows['REPORTING_DATETIME_LT']=="1970-01-01 00:00"){$REPORTING_DATETIME_LT = "";}else{$REPORTING_DATETIME_LT = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_LT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_LT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PREFIX'].' '.$rows['TIME_RELATIVE_UTC'].'</td>';
				if($rows['REPORTING_DATETIME_UTC']=="" || $rows['REPORTING_DATETIME_UTC']=="1970-01-01 00:00"){$REPORTING_DATETIME_UTC = "";}else{$REPORTING_DATETIME_UTC = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_UTC']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_UTC.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_FORE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_AFT'].'</td>';			
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NEXT_PORT'].'</td>';
				if($rows['ETA_NEXT_PORT']=="" || $rows['ETA_NEXT_PORT']=="1970-01-01 00:00"){$ETA_NEXT_PORT = "";}else{$ETA_NEXT_PORT = date('d-m-Y H:i',strtotime($rows['ETA_NEXT_PORT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$ETA_NEXT_PORT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_CONDITION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WEATHER_DIRECTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WIND_FORCE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SEA_STATE'].'</td>';				
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWEEL_STATE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWELL_DIRN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LATTITUDE'].' '.$rows['LAT_DEG'].' '.$rows['LAT_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LONGITUDE'].' '.$rows['LONG_DEG'].' '.$rows['LONG_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DISTANCE_TO_GO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['OBSERVED_DIST'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NOON_HDG'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['STOPPAGE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['EFFECTIVE_STEAMING'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['OBSERVED_SPEED'].'</td>';
				
				$sql2 = "select * from sa_noon_slave2 WHERE NOONID='".$rows['NOONID']."'";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robssspdowntime = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				    $sql3 = "select * from sa_noon_slave3 WHERE NOONID='".$rows['NOONID']."' and NOON_SLAVEID ='".$rows2['NOON_SLAVEID']."' ";
					$res3 = mysql_query($sql3) or die($sql3);
					$rec3 = mysql_num_rows($res3);
					$robssspbunker = array();
					while($rows3 = mysql_fetch_assoc($res3))
					{ 
						 $robssspbunker[] =  $rows3['BUNKER'].'&nbsp;-&nbsp;'.$rows3['QUANTITY'].'&nbsp;MT';
					}
				     $robssspdowntime[] =  $rows2['DOWNTIME_TYPE'].' - '.date('d-m-Y H:i', strtotime($rows2['FROM_LT_DATETIME'])).' To '.date('d-m-Y H:i', strtotime($rows2['TO_LT_DATETIME'])).' Bunker Consumed :<br/>'.implode('<br/>',$robssspbunker).'<Br/>';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robssspdowntime).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('MAINPROP_AE_BUNKER','CONSP_MP_AE_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('OT_OTHERS_BUNKER','CONSPGC_OTHER_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('ROB_BUNKER', 'ROB_TOTAL_BUNKER','ROBGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_noon_slave1 WHERE NOONID='".$rows['NOONID']."' and IDENTITY in ('CONSUMPTION_BUNKER', 'CONSP_TOTAL_BUNKER','CONSPGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '</tr>';
				$i++;
		}
	
	}
	
	
	$sql = "select * from sa_arrival_master WHERE VESSEL_NAME='".$selvesselname."' and VOYAGE_NO='".$selVoyageNo."' order by REPORTING_DATETIME_LT desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['REPORT_TITLE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				if($rows['REPORTING_DATETIME_LT']=="" || $rows['REPORTING_DATETIME_LT']=="1970-01-01 00:00"){$REPORTING_DATETIME_LT = "";}else{$REPORTING_DATETIME_LT = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_LT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_LT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PREFIX'].' '.$rows['TIME_RELATIVE_UTC'].'</td>';
				if($rows['REPORTING_DATETIME_UTC']=="" || $rows['REPORTING_DATETIME_UTC']=="1970-01-01 00:00"){$REPORTING_DATETIME_UTC = "";}else{$REPORTING_DATETIME_UTC = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_UTC']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_UTC.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_FORE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['DRAFT_AFT'].'</td>';			
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PORT_OF_ARRIVAL'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PORT_VISIT_REASON'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				if($rows['ETA_NEXT_PORT']=="" || $rows['ETA_NEXT_PORT']=="1970-01-01 00:00"){$ETA_NEXT_PORT = "";}else{$ETA_NEXT_PORT = date('d-m-Y H:i',strtotime($rows['ETA_NEXT_PORT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$ETA_NEXT_PORT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_CONDITION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WEATHER_DIRECTION'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['WIND_FORCE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SEA_STATE'].'</td>';				
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWEEL_STATE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['SWELL_DIRN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LATTITUDE'].' '.$rows['LAT_DEG'].' '.$rows['LAT_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['LONGITUDE'].' '.$rows['LONG_DEG'].' '.$rows['LONG_MIN'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_DISTANCE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['OBSERVED_DIST'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['NOON_HDG'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['STOPPAGE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['EFFECTIVE_STEAMING'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['OBSERVED_SPEED'].'</td>';
				
				$sql2 = "select * from sa_arrival_slave2 WHERE ARRIVALID='".$rows['ARRIVALID']."'";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robssspdowntime = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				    $sql3 = "select * from sa_arrival_slave3 WHERE ARRIVALID='".$rows['ARRIVALID']."' and ARRIVAL_SLAVEID ='".$rows2['ARRIVAL_SLAVEID']."' ";
					$res3 = mysql_query($sql3) or die($sql3);
					$rec3 = mysql_num_rows($res3);
					$robssspbunker = array();
					while($rows3 = mysql_fetch_assoc($res3))
					{ 
						 $robssspbunker[] =  $rows3['BUNKER'].'&nbsp;-&nbsp;'.$rows3['QUANTITY'].'&nbsp;MT';
					}
				     $robssspdowntime[] =  $rows2['DOWNTIME_TYPE'].' - '.date('d-m-Y H:i', strtotime($rows2['FROM_LT_DATETIME'])).' To '.date('d-m-Y H:i', strtotime($rows2['TO_LT_DATETIME'])).' Bunker Consumed :<br/>'.implode('<br/>',$robssspbunker).'<Br/>';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robssspdowntime).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('MAINPROP_AE_BUNKER','CONSP_MP_AE_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('OT_OTHERS_BUNKER','CONSPGC_OTHER_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('ROB_BUNKER', 'ROB_TOTAL_BUNKER','ROBGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_arrival_slave1 WHERE ARRIVALID='".$rows['ARRIVALID']."' and IDENTITY in ('CONSUMPTION_BUNKER', 'CONSP_TOTAL_BUNKER','CONSPGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '</tr>';
				$i++;
		}
	
	}
	
	
	$sql = "select * from sa_portmessage_master WHERE VESSEL_NAME='".$selvesselname."' and VOYAGE_NO='".$selVoyageNo."' order by REPORTING_DATETIME_LT desc";
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	$i = 1;
	if($rec == 0)
	{
		
	}
	else{
	
		while($rows = mysql_fetch_assoc($res))
		{
				echo '<tr>';
				echo '<td align="center" valign="middle" class="input-text">'.$i.'.</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['REPORT_TITLE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_TYPE'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['MESSAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VESSEL_NAME'].'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['VOYAGE_NO'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				if($rows['REPORTING_DATETIME_LT']=="" || $rows['REPORTING_DATETIME_LT']=="1970-01-01 00:00"){$REPORTING_DATETIME_LT = "";}else{$REPORTING_DATETIME_LT = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_LT']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_LT.'</td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PREFIX'].' '.$rows['TIME_RELATIVE_UTC'].'</td>';
				if($rows['REPORTING_DATETIME_UTC']=="" || $rows['REPORTING_DATETIME_UTC']=="1970-01-01 00:00"){$REPORTING_DATETIME_UTC = "";}else{$REPORTING_DATETIME_UTC = date('d-m-Y H:i',strtotime($rows['REPORTING_DATETIME_UTC']));}
				echo '<td align="left" valign="middle" class="input-text">'.$REPORTING_DATETIME_UTC.'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';			
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text">'.$rows['PORT_OF_ARRIVAL'].'</td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';				
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				echo '<td align="left" valign="middle" class="input-text"></td>';
				
				$sql2 = "select * from sa_portmessage_slave2 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."'";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robssspdowntime = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				    $sql3 = "select * from sa_portmessage_slave3 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and PORTMESSAGE_SLAVEID ='".$rows2['PORTMESSAGE_SLAVEID']."' ";
					$res3 = mysql_query($sql3) or die($sql3);
					$rec3 = mysql_num_rows($res3);
					$robssspbunker = array();
					while($rows3 = mysql_fetch_assoc($res3))
					{ 
						 $robssspbunker[] =  $rows3['BUNKER'].'&nbsp;-&nbsp;'.$rows3['QUANTITY'].'&nbsp;MT';
					}
				     $robssspdowntime[] =  $rows2['DOWNTIME_TYPE'].' - '.date('d-m-Y H:i', strtotime($rows2['FROM_LT_DATETIME'])).' To '.date('d-m-Y H:i', strtotime($rows2['TO_LT_DATETIME'])).' Bunker Consumed :<br/>'.implode('<br/>',$robssspbunker).'<Br/>';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robssspdowntime).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('MAINPROP_AE_BUNKER','CONSP_MP_AE_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('TANK_CLEANING_BUNKER','CONSP_TANK_CLEANING_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('OT_OTHERS_BUNKER','CONSPGC_OTHER_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('ROB_BUNKER', 'ROB_TOTAL_BUNKER','ROBGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave1 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' and IDENTITY in ('CONSUMPTION_BUNKER', 'CONSP_TOTAL_BUNKER','CONSPGC_TOTAL_BUNKER') ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'&nbsp;MT';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				
				$sql2 = "select * from sa_portmessage_slave4 WHERE PORTMESSAGEID='".$rows['PORTMESSAGEID']."' ";
				$res2 = mysql_query($sql2) or die($sql2);
				$rec2 = mysql_num_rows($res2);
				$robsssp = array();
				while($rows2 = mysql_fetch_assoc($res2))
				{ 
				     $robsssp[] =  $rows2['BUNKER'].'&nbsp;-&nbsp;'.$rows2['QUANTITY'].'MT @ '.$rows2['RATE_MT'].'USD + '.$rows2['ADDNL_COST'].'USD = '.$rows2['TOTAL_COST'].'USD';
				}
				echo '<td align="left" valign="middle" class="input-text">'.implode('<br/>',$robsssp).'</td>';
				echo '</tr>';
				$i++;
		}
	
	}
	
	
	echo '</tbody>';
	echo '</table></div>';
}


function viewAdminRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM login where LOGINID=".$id;
	$result = mysql_query($query) or die(mysql_error());
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['MCOMPANYID'];
		$this->var_2 = $rows['ADDRESS'];
		$this->var_3 = $rows['PHONE_NO'];
		$this->var_4 = $rows['EMAILID'];
		$this->var_5 = $rows['CONTACT_PERSON'];
		$this->var_6 = $rows['STATUS'];
		$this->var_7 = $rows['USERNAME'];
		$this->var_8 = $rows['PASSWORD'];
	}
}

function updateUserProfileRecords()
{
	$connect				= $this->funConnect();
	$id = $_SESSION['uid'];
 	
	$user_name 			= addslashes(trim($_REQUEST['txtUserName']));
	$password 			= addslashes(trim($_REQUEST['txtPassword']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update login set PASSWORD='".$password."'  where LOGINID='".$id."'";
	
	mysql_query($sql) or die(mysql_error());	
	mysql_query("commit"); 
	
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Password changed successfully.',NOW())";
	mysql_query($sql3,$connect) or die(mysql_error());
		
	if(mysql_error($connect))
	{
		$msg = 1;
		mysql_query("ROLLBACK");
	}
	else
	{
		mysql_query("commit"); 
	}
		
	return $msg;
}


		function PDFHeader()
		{
			$this->funConnect();
		
			$this->SetFillColor(255,255,255);
			$image_path1 = '../../img/slogo.jpg';
			$this->Image($image_path1,83,5,40,18);
			$this->SetTextColor(27,119,166);
			$this->AddFont("daxcondensedlight",'',"daxcondensedlight.php");
			$this->SetFont('daxcondensedlight','',25);
			$this->SetX(20);
			$this->SetY(7);
			$this->SetX(21);
			
			$this->Ln(1);
			$this->SetFont('Arial','',10);
			$this->SetX(20);
			$this->Cell(170,6,"",0,1,'C',0);
			$this->SetTextColor(177,175,175);
		    $this->Ln(12);
			$this->Cell(0,1,"___________________________________________________________________________________________________________________________________________________________________________",0,1,'C','1');
			$this->Ln(2);

			
		}

		function PDFFooter()
		{
			$this->SetY(-20);
			$this->SetFillColor(255,255,255);
			$this->SetTextColor(177,175,175);
			$this->SetFont('Arial','',10);
			$this->SetX(0);
			$this->Cell(0,1,"___________________________________________________________________________________________________________________________________________________________________________",0,1,'C','1');
			$this->Ln(1);
			$this->AddFont("daxcondensedlight",'',"daxcondensedlight.php");
			$this->SetFont('daxcondensedlight','',8);
			$this->SetTextColor(027,119,166);
			$this->Ln(1);
			$obj = new data();
			$this->Cell(0,4,$obj->getCompanyNameBasedOnID($_SESSION['company'],"ADDRESS"),0,1,'C');
			$this->Cell(0,4,"Tel: ".$obj->getCompanyNameBasedOnID($_SESSION['company'],"PHONE_NO")."  email: ".$obj->getCompanyNameBasedOnID($_SESSION['company'],"EMAIL_ID"),0,1,'C');
			$this->Cell(0,4,"www.bainbridgenav.com",0,1,'C');
		}
	

function createCombinedSOAPayable()
{

	// die('dpk is not a problem');
    $connect 			 = $this->funConnect();
	$soa_no              = $this->getMessageNumberForCombinedSOAPayable();	
	$soa_serialNo 		 = explode('-',$soa_no)[1];
	$soa_date       	 = date("Y-m-d",strtotime(trim(addslashes($_REQUEST['txtPaymentDate']))));
	$txtRemarks          = trim(addslashes($_REQUEST['txtRemarks']));
	
    $selExchangeCurrency = trim(addslashes($_REQUEST['selExchangeCurrency']));
	$txtExchangeDate     = date("Y-m-d",strtotime(trim(addslashes($_REQUEST['txtExchangeDate']))));
	$txtExchangeRate     = $this->getCheckNullValue($_REQUEST['txtExchangeRate']);
	$selBankingDetails   = trim(addslashes($_REQUEST['selBankingDetails']));
	$selVendor           = trim(addslashes($_REQUEST['selVendor']));
 	
	
	// $upload = $this->getUpload($_FILES['attach_file']);
	// $name = $this->getUploadName($_FILES['attach_file']);
	
	// $upload = implode(',',$upload);
	// $upload_name = implode(',',$name);
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "insert into combined_soa_payable_master (SOA_DATE, SOA_NO, SOA_SERIAL_NO, UPLOAD, UPLOAD_NAME, CREATOR, REMARKS, STATUS, EXCHANGE_CURRENCY, EXCHANGE_DATE, EXCHANGE_RATE, BANKING_ID, VENDOR) values ('".$soa_date."', '".$soa_no."', '".$soa_serialNo."', '".$upload."', '".$upload_name."', '".$_SESSION['uid']."', '".$txtRemarks."', '0', '".$selExchangeCurrency."', '".$txtExchangeDate."', '".$txtExchangeRate."', '".$selBankingDetails."', '".$selVendor."')";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
		
	$sql1 = "select max(SOAID) as max from combined_soa_payable_master";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	
	foreach($_REQUEST['chkSelect'] as $chkSelect)
	{
		if($_REQUEST['COMID_'.$chkSelect] != "")
		{
			$comid          		= $_REQUEST['COMID_'.$chkSelect];
			$NAME           	    = trim(addslashes($_REQUEST['NAME_'.$chkSelect]));
			$NAME_ID		 	    = trim(addslashes($_REQUEST['NAME_ID_'.$chkSelect]));
			$PORT           	    = trim(addslashes($_REQUEST['PORT_'.$chkSelect]));
			$GRADEID         	    = trim(addslashes($_REQUEST['GRADEID_'.$chkSelect]));
			$ACCOUNT_TYPE      	    = trim(addslashes($_REQUEST['ACCOUNT_TYPE_'.$chkSelect]));
			$txtPaymentNo    	    = trim(addslashes($_REQUEST['txtPaymentNo_'.$chkSelect]));
			$txtRemarks      	    = trim(addslashes($_REQUEST['txtRemarks_'.$chkSelect]));
			$txtActualAmt   	    = trim(addslashes($_REQUEST['txtActualAmt_'.$chkSelect]));
			$txtCP_Date             = $this->getCompareEstimateData($comid,"TRANS_DATE");
			$txtInvoiceAmount  	    = trim(addslashes($_REQUEST['txtInvoiceAmount_'.$chkSelect]));
			$txtInvoiceDate   	    = date("Y-m-d",strtotime(trim(addslashes($_REQUEST['txtInvoiceDate_'.$chkSelect]))));

			$upload = $this->getUpload($_FILES['attach_file_'.$chkSelect.'']);
         	$name = $this->getUploadName($_FILES['attach_file_'.$chkSelect.'']);
	
	         $upload = implode(',',$upload);
            $upload_name = implode(',',$name);
           
			$sql3 = "insert into request_master (COMID, MODULEID, MCOMPANYID, LOGIN, NAME, NAME_ID, GRADEID, VENDOR, PORT, ACCOUNT_TYPE, PAYMENT_NO, DATE, REMARKS, TTL_OUTSTANDINGS, BAL_OUTSTANDINGS, REQ_TO_PAY, STATUS, CP_DATE, REQUESTED, VESSELID, INVOICE_AMT, INVOICE_DATE, NET_AMT, UPLOAD, UPLOAD_NAME, APPROVERS, CREATOR, EXCHANGE_RATE, EXCHANGE_DATE, EXCHANGE_CURRENCY, BANKING_DETAILS, VENDOR_SLAVEID, SOAID,ATTACHMENTS,ATTACHMENTS_NAME) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', 'INTERNAL_USER', '".$NAME."', '".$NAME_ID."', '".$GRADEID."', '".$selVendor."', '".$PORT."', '".$ACCOUNT_TYPE."', '".$txtPaymentNo."', '".$soa_date."', '".$txtRemarks."', '".$this->getCheckNullVal($txtActualAmt)."', '".$this->getCheckNullVal($txtActualAmt)."', '".$this->getCheckNullVal($txtActualAmt)."', '0', '".$txtCP_Date."', '0', '".$this->getCompareEstimateData($comid,"VESSEL_IMO_ID")."', '".$this->getCheckNullVal($txtInvoiceAmount)."', '".$txtInvoiceDate."', '".$this->getCheckNullVal($txtActualAmt)."', '".$upload."', '".$upload_name."', '', '".$_SESSION['uid']."', '".$this->getCheckNullVal($txtExchangeRate)."', '".$txtExchangeDate."', '".$selExchangeCurrency."', '".addslashes(trim($this->getVendorListNewData($selVendor,"BANKING_DETAILS")))."', '".$selBankingDetails."', '".$rows1['max']."', '".$upload."', '".$upload_name."')";
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	} 
	
	$this->saveRecentWork("Combined SOA (".$soa_no.") Payable Created Successfully.");
	mysql_query("commit");
	return $rows1['max'];
}

function getMessageNumberForCombinedSOAPayable()
{
  $this->funConnect();
	$query = "SELECT (MAX(SOA_SERIAL_NO) + 1) as SOA_SERIAL_NO FROM combined_soa_payable_master where YEAR(SOA_DATE)='".date('Y',time())."'";
	$result = mysql_query($query);
	$rec	= mysql_num_rows($result);
	while($rows = mysql_fetch_array($result))
	{
	$empcode = $rows['SOA_SERIAL_NO'];
	if($rows['SOA_SERIAL_NO'] != NULL)
		{
		if(strlen($empcode)<=4)
			{
				$x = 4- strlen($empcode);
				for($i = 1; $i<=$x;$i++)
					{
						$empcode = "0".$empcode;
					}
			}$empcode ='SOA-'.$empcode.'-'.date("Y",time());
		}
	else
		{
			$empcode= 'SOA-0001-'.date("Y",time());
		}
	}
	
return $empcode;
}

function viewCombinedSOAPayableData($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM combined_soa_payable_master where SOAID='".$id."'"; 
	$result = mysql_query($query);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['SOAID'];
		$this->var_2 = $rows['SOA_DATE'];
		$this->var_3 = $rows['SOA_NO'];
		$this->var_4 = $rows['UPLOAD'];
		$this->var_5 = $rows['UPLOAD_NAME'];
		$this->var_6 = $rows['CREATOR'];
		$this->var_7 = $rows['APPROVERS'];
		$this->var_8 = $rows['ACC_USER'];
		$this->var_9 = $rows['REMARKS'];
		$this->var_10 = $rows['STATUS'];
		$this->var_11 = $rows['EXCHANGE_CURRENCY'];
		$this->var_12 = $rows['EXCHANGE_DATE'];
		$this->var_13 = $rows['EXCHANGE_RATE'];
		$this->var_14 = $rows['BANKING_ID'];
		$this->var_15 = $rows['VENDOR'];
		$this->var_16 = $rows['PAYMENT_STATUS'];
			
	}
}


function updateCombinedSOAPayable()
{

    $connect 			= $this->funConnect();	
	
	$id = $_REQUEST['id'];
	
	$txtRemarks         = trim(addslashes($_REQUEST['txtRemarks']));
	$txtStatus          = $_REQUEST['txtStatus'];
	$soa_date       	 = date("Y-m-d",strtotime(trim(addslashes($_REQUEST['txtPaymentDate']))));
    $selExchangeCurrency = trim(addslashes($_REQUEST['selExchangeCurrency']));
	$txtExchangeDate     = date("Y-m-d",strtotime(trim(addslashes($_REQUEST['txtExchangeDate']))));
	$txtExchangeRate     = $this->getCheckNullValue($_REQUEST['txtExchangeRate']);
	$selBankingDetails   = trim(addslashes($_REQUEST['selBankingDetails']));
	$txtrowcount         = trim(addslashes($_REQUEST['txtrowcount']));
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$upload_name = implode(',',$name);
	

	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $upload_name != ''){ $name1 = $txtCRMNAME1.','.$upload_name;}
	else if($txtCRMNAME1 == '' && $upload_name != ''){ $name1 = $upload_name;}
	else if($txtCRMNAME1 != '' && $upload_name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$query_sel = "SELECT * FROM combined_soa_payable_master where SOAID='".$id."'"; 
	$result_sel = mysql_query($query_sel);
	$rows_sel = mysql_fetch_assoc($result_sel);
	
	if($txtStatus ==0 || $txtStatus ==1)
	{

		$approversel = implode(',',$_REQUEST['selApprovers']);
	}else
	{
		$approversel = $rows_sel['APPROVERS'];
	}
	
	if($txtStatus == 5)
	{
		$accountuser = $_SESSION['uid'];
	}else
	{
	    $accountuser = $rows_sel['ACC_USER'];
	}
	$creatorloginid = $rows_sel['CREATOR'];
	
	$sql = "update combined_soa_payable_master set REMARKS='".$txtRemarks."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', APPROVERS='".$approversel."', STATUS='".$txtStatus."', ACC_USER='".$accountuser."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', EXCHANGE_DATE='".$txtExchangeDate."', EXCHANGE_RATE='".$txtExchangeRate."', BANKING_ID='".$selBankingDetails."', PAYMENT_STATUS='".$_REQUEST['payment_status']."' where SOAID=".$id;
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	for($i=1;$i<=$txtrowcount;$i++)
	{
		if($_REQUEST['REQ_ID_'.$i] != "")
		{



		
			$REQ_ID     		= $_REQUEST['REQ_ID_'.$i];
			
			$txtPaymentNo    	    = trim(addslashes($_REQUEST['txtPaymentNo_'.$i]));
			$txtRemarks      	    = trim(addslashes($_REQUEST['txtRemarks_'.$i]));
			$txtActualAmt   	    = trim(addslashes($_REQUEST['txtActualAmt_'.$i]));
			$txtCP_Date             = $this->getCompareEstimateData($comid,"TRANS_DATE");
			$txtInvoiceAmount  	    = trim(addslashes($_REQUEST['txtInvoiceAmount_'.$i]));
			$txtInvoiceDate   	    = date("Y-m-d",strtotime(trim(addslashes($_REQUEST['txtInvoiceDate_'.$i]))));


			$upload = $this->getUpload($_FILES['attach_file_'.$i]);
			$name = $this->getUploadName($_FILES['attach_file_'.$i]);
			// if($upload==' ')
			$uploadForGrid = implode(',',$upload);
			$upload_nameForGrid = implode(',',$name);

			



			for($k=1;$k<=$_REQUEST['countForAttachment_'.$i];$k++){
	

			$txtCRMFILEForGrid=addslashes(trim($_REQUEST['fileGrid_'.$i.'_'.$k]));

			$txtCRMNAMEForGrid=addslashes(trim($_REQUEST['nameGrid_'.$i.'_'.$k]));

			if($txtCRMFILEForGrid != '' && $uploadForGrid != ''){ $uploadForGrid = $txtCRMFILEForGrid.','.$uploadForGrid;}

			else if($txtCRMFILEForGrid == '' && $uploadForGrid != ''){ $uploadForGrid = $uploadForGrid;}
			else if($txtCRMFILEForGrid != '' && $uploadForGrid == ''){ $uploadForGrid = $txtCRMFILEForGrid;}
	
			if($txtCRMNAMEForGrid != '' && $upload_nameForGrid != ''){ $upload_nameForGrid = $txtCRMNAMEForGrid.','.$upload_nameForGrid;}
			else if($txtCRMNAMEForGrid == '' && $upload_nameForGrid != ''){ $upload_nameForGrid = $upload_nameForGrid;}
			else if($txtCRMNAMEForGrid != '' && $upload_nameForGrid == ''){ $upload_nameForGrid = $txtCRMNAMEForGrid;}


			}

				if($txtStatus < 6)
				{
	
				
					$sql3 = "update request_master set PAYMENT_NO='".$txtPaymentNo."', DATE='".$soa_date."', REMARKS='".$txtRemarks."', TTL_OUTSTANDINGS='".$this->getCheckNullVal($txtActualAmt)."', BAL_OUTSTANDINGS='".$this->getCheckNullVal($txtActualAmt)."', REQ_TO_PAY='".$this->getCheckNullVal($txtActualAmt)."', STATUS='".$txtStatus."', CP_DATE='".$txtCP_Date."', VESSELID='".$this->getCompareEstimateData($comid,"VESSEL_IMO_ID")."', INVOICE_AMT='".$this->getCheckNullVal($txtInvoiceAmount)."', INVOICE_DATE='".$txtInvoiceDate."', NET_AMT='".$this->getCheckNullVal($txtActualAmt)."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', APPROVERS='".$approversel."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', EXCHANGE_DATE='".$txtExchangeDate."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', BANKING_DETAILS='".addslashes(trim($this->getVendorListNewData($selVendor,"BANKING_DETAILS")))."', VENDOR_SLAVEID='".$selBankingDetails."', ATTACHMENTS='".$uploadForGrid."', ATTACHMENTS_NAME='".$upload_nameForGrid."', ACC_USER='".$accountuser."' where REQ_ID=".$REQ_ID;
				}
				else
				{
	
					
	
					$sql3 = "update request_master set PAYMENT_NO='".$txtPaymentNo."', DATE='".$soa_date."', REMARKS='".$txtRemarks."', TTL_OUTSTANDINGS='".$this->getCheckNullVal($txtActualAmt)."', BAL_OUTSTANDINGS='".$this->getCheckNullVal($txtActualAmt)."', REQ_TO_PAY='".$this->getCheckNullVal($txtActualAmt)."', STATUS=5, CP_DATE='".$txtCP_Date."', VESSELID='".$this->getCompareEstimateData($comid,"VESSEL_IMO_ID")."', INVOICE_AMT='".$this->getCheckNullVal($txtInvoiceAmount)."', INVOICE_DATE='".$txtInvoiceDate."', NET_AMT='".$this->getCheckNullVal($txtActualAmt)."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', APPROVERS='".$approversel."', EXCHANGE_RATE='".$this->getCheckNullVal($txtExchangeRate)."', EXCHANGE_DATE='".$txtExchangeDate."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', BANKING_DETAILS='".addslashes(trim($this->getVendorListNewData($selVendor,"BANKING_DETAILS")))."', VENDOR_SLAVEID='".$selBankingDetails."', ACC_USER='".$accountuser."', ATTACHMENTS='".$uploadForGrid."', ATTACHMENTS_NAME='".$upload_nameForGrid."', P_AMT='".$this->getCheckNullVal($txtActualAmt)."', P_DATE='".date('Y-m-d',time())."', P_REMARKS='Paid' where REQ_ID=".$REQ_ID;
				}

				


	
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
		}
	} 
	
	mysql_query("commit");
	
	
	$this->saveRecentWork("Combined SOA Payable (".$rows_sel['SOA_NO'].") Updated Successfully.");
	
	$this->inactiveUserAlerts('COMBINED SOA PAYABLE', $_SESSION['uid'], $id);
	
	$creatorsarr =  ($creatorloginid!='' && $creatorloginid!=NULL)?array($creatorloginid):array();
	$approverarr1 = $_REQUEST['selApprovers'];
	$approverarr2 = $this->getUsersWithAuthority('SOA_CHK_APP_2');
	$approverarraccount2 = $this->getUsersWithAuthority('SOA_CHK_ACC');
	
	$url = './updatecombinedpayablesoa.php?id='.$id;
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	$invtitleType = 'COMBINED SOA PAYABLE';
	
	$vendorname = $this->getVendorListNewBasedOnID($rows_sel['VENDOR']);
	if($id != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$rows_sel['SOA_NO'].' for '.$vendorname.') for Level 1 Approval', $id);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$rows_sel['SOA_NO'].' for '.$vendorname.') for Review', $id);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$rows_sel['SOA_NO'].' for '.$vendorname.') for Review', $id);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' sent '.$invtitleType.' ('.$rows_sel['SOA_NO'].' for '.$vendorname.') for Level 2 Approval', $id);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{
		     if(!empty($approverarraccount2))
			 {
			     $userarray = $approverarraccount2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, $invtitleType, $currentusername.' Approved '.$invtitleType.' ('.$rows_sel['SOA_NO'].' for '.$vendorname.')', $id);		
				  }
			 }
		}
	}
	
	
	return $msg;
}



function getLoadPortAndDischargePortArrBasedOnCommidAndProcessWithout_in($fcaid)
{
	$connect = $this->funConnect();
	$arr  =  array();
	
	$sql  = "select FROM_PORT, TO_PORT, RANDOMID, LOAD_PORT_QTY, DISC_PORT_QTY, PORT_COSTLP_VENDOR, PORT_COSTDP_VENDOR, LOAD_PORT_COST, DISC_PORT_COST, TRANSIT_PORT_COST, PORT_COSTTP_VENDOR, DDCLP_ESTCOST, DDCDP_ESTCOST, LOAD_PORT_RATE, DISC_PORT_RATE, PORT_COSTLP_VENDOR, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP from freight_cost_estimete_in_slave1 where FCAID='".$fcaid."' order by FCA_SLAVEID asc";
	$res  = mysql_query($sql);
	while($rows  = mysql_fetch_assoc($res))
	{
		if($this->getPortNameBasedOnID($rows['FROM_PORT']) != "TBN")
		{
			if($rows['PORT_COSTLP_VENDOR'] !='')
		    {
				$arr[] = "LP@@".$rows['FROM_PORT']."@@".$rows['RANDOMID']."@@".$rows['LOAD_PORT_QTY']."@@".$rows['PORT_COSTLP_VENDOR']."@@".$rows['DDCLP_ESTCOST']."@@".$rows['LOAD_PORT_RATE']."@@".$rows['PORT_COSTLP_VENDOR']."@@".$rows['IS_SHOW_DDCLP'];
			}
			if($rows['PORT_COSTDP_VENDOR'] !='' )
		    {
				$arr[] = "DP@@".$rows['TO_PORT']."@@".$rows['RANDOMID']."@@".$rows['DISC_PORT_QTY']."@@".$rows['PORT_COSTDP_VENDOR']."@@".$rows['DDCDP_ESTCOST']."@@".$rows['DISC_PORT_RATE']."@@".$rows['PORT_COSTDP_VENDOR']."@@".$rows['IS_SHOW_DDCDP'];
			}
			if($rows['PORT_COSTTP_VENDOR']!='')
		    {
				$arr[] = "TP@@".$rows['FROM_PORT']."@@".$rows['RANDOMID']."@@0@@".$rows['PORT_COSTTP_VENDOR'];;
			}
		}
	}
	return $arr;
}


function insertFreightInvoiceDetails_in()
{
	$connect 			= $this->funConnect();	
	$comid 				= addslashes(trim($_REQUEST['comid']));
	$name 				= addslashes(trim($_REQUEST['name']));
	$cargoid            = addslashes(trim($_REQUEST['cargoid']));
	$randomid           = addslashes(trim($_REQUEST['randomid']));
	$selFromOwner 		= addslashes(trim($_REQUEST['selFromOwner']));
	$selIType 			= addslashes(trim($_REQUEST['selIType']));
	$txtDNote	 		= addslashes(trim($_REQUEST['txtDNote']));
	$txtInvoiceid       = addslashes(trim($_REQUEST['txtInvoiceid']));
	
	$txtDNote_1	 		= explode("/",$_REQUEST['txtDNote']);
	$txtAttenName	 	= addslashes(trim($_REQUEST['txtAttenName']));
	$txtVendor	 		= addslashes(trim($_REQUEST['txtVendor']));
	$txtFCAID	 		= addslashes(trim($_REQUEST['txtFCAID']));

	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtCP_Date	 		= date("Y-m-d",strtotime($_REQUEST['txtCP_Date']));
	$txtDueDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDueDate']));
	$txtExchangeDate	= date("Y-m-d",strtotime($_REQUEST['txtExchangeDate']));
	
	$txtGrossFreight	= addslashes(trim($_REQUEST['txtGrossFreight']));
	$txtBrokerage	 	= addslashes(trim($_REQUEST['txtBrokerage']));
	$txtBrokerageAmt    = addslashes(trim($_REQUEST['txtBrokerageAmt']));
	$txtNetFreight	 	= addslashes(trim($_REQUEST['txtNetFreight']));
	$txtTO	 	        = addslashes(trim($_REQUEST['txtTO']));
	$txtNet	 		    = addslashes(trim($_REQUEST['txtNet']));
	$txtFinalNetFreight	= addslashes(trim($_REQUEST['txtFinalNetFreight']));
	$txtNet_Name	 	= addslashes(trim($_REQUEST['txtNet_Name']));
	
	$selNOB	 		    = addslashes(trim($_REQUEST['selNOB']));
	$txtPaymentTerms	= addslashes(trim($_REQUEST['txtPaymentTerms']));
	$txtDesc        	= addslashes(trim($_REQUEST['txtDesc']));
	$txtRemarks	 		= addslashes(trim($_REQUEST['txtRemarks']));
	$txtQty             = $_REQUEST['txtQty'];
	$txtStatus	 		= addslashes(trim($_REQUEST['txtStatus']));
	
	$selExchangeCurrency= addslashes(trim($_REQUEST['selExchangeCurrency']));
	$txtFreightAmtLocal = addslashes(trim($_REQUEST['txtFreightAmtLocal']));
	$txtExchangeRate	= addslashes(trim($_REQUEST['txtExchangeRate']));
	
	$txtAddComm         = addslashes(trim($_REQUEST['txtAddComm']));
	$txtAddCommAmt	 	= addslashes(trim($_REQUEST['txtAddCommAmt']));
	$txtNetAmtPayable	= addslashes(trim($_REQUEST['txtNetAmtPayable']));
	$txtDNote1			= addslashes(trim($_REQUEST['txtDNote1']));
	
	$rdoTaxApplicable         = addslashes(trim($_REQUEST['rdoTaxApplicable']));
	$rdoGSTVAT                = addslashes(trim($_REQUEST['rdoGSTVAT']));
	$txtSGST                  = addslashes(trim($_REQUEST['txtSGST']));
	$txtSGST_Amount           = addslashes(trim($_REQUEST['txtSGST_Amount']));
	$txtCGST                  = addslashes(trim($_REQUEST['txtCGST']));
	$txtCGST_Amount           = addslashes(trim($_REQUEST['txtCGST_Amount']));
	$txtIGST                  = addslashes(trim($_REQUEST['txtIGST']));
	$txtIGST_Amount           = addslashes(trim($_REQUEST['txtIGST_Amount']));
	$txtVAT                   = addslashes(trim($_REQUEST['txtVAT']));
	$txtVAT_Amount            = addslashes(trim($_REQUEST['txtVAT_Amount']));
	$txtAmtPayableWithTax     = addslashes(trim($_REQUEST['txtAmtPayableWithTax']));
	$c_bank_check     = addslashes(trim($_REQUEST['c_bank_check']));

	
	$txtBLDate	 		      = $_REQUEST['txtBLDate'];
	$txtBLNo                  = addslashes(trim($_REQUEST['txtBLNo']));
	$txtFlag                  = addslashes(trim($_REQUEST['txtFlag']));
	$txtIMONo                 = addslashes(trim($_REQUEST['txtIMONo']));
	
	$txtLoadPortName          = addslashes(trim($_REQUEST['txtLoadPortName']));
	$txtDischargePortName     = addslashes(trim($_REQUEST['txtDischargePortName']));
	$txtManualVendorName     = addslashes(trim($_REQUEST['txtManualVendorName']));
	$selApprovers             = $_REQUEST['selApprovers'];
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME']));


	$txtFrieghtRate = trim($_REQUEST['txtFrieghtRate'],'USD/MT');


	$upload = $this->getUpload($_FILES['attach_file']);
	$filename = $this->getUploadName($_FILES['attach_file']);
	$upload = implode(',',$upload);
	$filename = implode(',',$filename);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $filename != ''){ $name1 = $txtCRMNAME1.','.$filename;}
	else if($txtCRMNAME1 == '' && $filename != ''){ $name1 = $filename;}
	else if($txtCRMNAME1 != '' && $filename == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$invoiceidd = '';$creatorloginid = '';
	 $qsql = "select * from freight_invoice_in_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and VENDOR='".$txtVendor."'";
	
	$qres = mysql_query($qsql) or die($qsql);
	$qrec = mysql_num_rows($qres);
	if($qrec == 0)
	{
	 	$sql = "insert into freight_invoice_in_master (COMID, MODULEID, MCOMPANYID, DATE, I_TYPE, NOB, STATUS, MESSAGE, VENDOR, GROSS_FREIGHT, BROKERAGE, CPDATE, FCAID, FINAL_FREIGHT, TO_1, NET_AMOUNT, REMARKS, PAYMENT_TERMS, QUANTITY, BROKERAGE_PERCENT, EXCHANGE_CURRENCY, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, ADDCOM, ADDCOM_AMOUNT, NET_PAYABLE, P_TYPE, ATTEN, DUE_DATE, EXCHANGE_DATE,  SHIP_OWNER, CARGOID, RANDOMID, RDOTAXAPPLICABLE, RDOVATGST, SGST_PERCENT, CGST_PERCENT, IGST_PERCENT, VAT_PERCENT, NET_PAYABLE_TAX, SGST_PERCENT_AMOUNT, CGST_PERCENT_AMOUNT, IGST_PERCENT_AMOUNT, VAT_PERCENT_AMOUNT, APPROVERS, CREATOR, UPLOAD, UPLOAD_NAME, BL_DATE, BL_NO, FLAG, IMO_NO, LOAD_PORT_NAME, DISCHARGE_PORT_NAME, MANUAL_VENDOR_NAME,FREIGHT_RATE,c_bank_check) values ('".$comid."', '".$_SESSION['moduleid']."', '".$_SESSION['company']."', '".$txtDate."', '".$selIType."', '".$selNOB."', '".$txtStatus."', '".$txtDNote."', '".$txtVendor."', '".$this->getCheckNullVal($txtGrossFreight)."', '".$this->getCheckNullVal($txtBrokerageAmt)."', '".$txtCP_Date."', '".$txtFCAID."', '".$this->getCheckNullVal($txtNetFreight)."', '".$this->getCheckNullVal($txtTO)."', '".$this->getCheckNullVal($txtNet)."', '".$txtDesc."', '".$txtPaymentTerms."', '".$txtQty."', '".$txtBrokerage."', '".$selExchangeCurrency."', '".$txtFreightAmtLocal."', '".$txtExchangeRate."', '".$txtAddComm."', '".$txtAddCommAmt."', '".$txtNetAmtPayable."', '".$name."', '".$txtAttenName."', '".$txtDueDate."', '".$txtExchangeDate."', '".$selFromOwner."', '".$cargoid."', '".$this->getCheckNullVal($randomid)."', '".$this->getCheckNullVal($rdoTaxApplicable)."', '".$this->getCheckNullVal($rdoGSTVAT)."', '".$this->getCheckNullVal($txtSGST)."', '".$this->getCheckNullVal($txtCGST)."', '".$this->getCheckNullVal($txtIGST)."', '".$this->getCheckNullVal($txtVAT)."', '".$this->getCheckNullVal($txtAmtPayableWithTax)."', '".$this->getCheckNullVal($txtSGST_Amount)."', '".$this->getCheckNullVal($txtCGST_Amount)."', '".$this->getCheckNullVal($txtIGST_Amount)."', '".$this->getCheckNullVal($txtVAT_Amount)."', '".implode(',',$_REQUEST['selApprovers'])."', '".$_SESSION['uid']."', '".$upload1."', '".$name1."' , '".$txtBLDate."', '".$txtBLNo."', '".$txtFlag."', '".$txtIMONo."', '".$txtLoadPortName."', '".$txtDischargePortName."', '".$txtManualVendorName."', '".$txtFrieghtRate."','".$c_bank_check."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		

		
		$sql1 = "select max(INVOICEID) as max from freight_invoice_in_master";
		$res1 = mysql_query($sql1);
		$rows1 = mysql_fetch_assoc($res1);
		$invoiceidd = $rows1['max'];
		$creatorloginid = $_SESSION['uid'];
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
			$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
			$sql2 = "insert into freight_invoice_in_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
			mysql_query($sql2);
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
			$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
			$sql2 = "insert into freight_invoice_in_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$rows1['max']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
			mysql_query($sql2);
		}
		
		$this->saveRecentWork($selIType." Freight Payment (".$txtDNote.") Created Successfully.");
	}
	else
	{
		$qrows = mysql_fetch_assoc($qres);
		$invoiceidd = $qrows['INVOICEID'];
		
		if($txtStatus ==0 || $txtStatus ==1)
		{
		    $approversel = implode(',',$_REQUEST['selApprovers']);
		}else
		{
		    $approversel = $qrows['APPROVERS'];
		}
		$creatorloginid = $qrows['CREATOR'];
		
		 $sql = "update freight_invoice_in_master set DATE='".$txtDate."', I_TYPE='".$selIType."', NOB='".$selNOB."', STATUS='".$txtStatus."', MESSAGE='".$txtDNote."', GROSS_FREIGHT='".$this->getCheckNullVal($txtGrossFreight)."', BROKERAGE='".$this->getCheckNullVal($txtBrokerageAmt)."', CPDATE='".$txtCP_Date."', FINAL_FREIGHT='".$this->getCheckNullVal($txtNetFreight)."', TO_1='".$this->getCheckNullVal($txtTO)."', NET_AMOUNT='".$this->getCheckNullVal($txtNet)."', REMARKS='".$txtDesc."', PAYMENT_TERMS='".$txtPaymentTerms."', QUANTITY='".$txtQty."', BROKERAGE_PERCENT='".$txtBrokerage."', EXCHANGE_CURRENCY='".$selExchangeCurrency."', AGREED_GROSS_FREIGHT_LOCAL='".$txtFreightAmtLocal."', EXCHANGE_RATE='".$txtExchangeRate."', ADDCOM='".$txtAddComm."', ADDCOM_AMOUNT='".$txtAddCommAmt."', NET_PAYABLE='".$txtNetAmtPayable."', P_TYPE='".$name."', ATTEN= '".$txtAttenName."', DUE_DATE='".$txtDueDate."', EXCHANGE_DATE= '".$txtExchangeDate."',  SHIP_OWNER='".$selFromOwner."', CARGOID='".$cargoid."', RANDOMID='".$this->getCheckNullVal($randomid)."', RDOTAXAPPLICABLE='".$this->getCheckNullVal($rdoTaxApplicable)."', RDOVATGST='".$this->getCheckNullVal($rdoGSTVAT)."', SGST_PERCENT='".$this->getCheckNullVal($txtSGST)."', CGST_PERCENT='".$this->getCheckNullVal($txtCGST)."', IGST_PERCENT='".$this->getCheckNullVal($txtIGST)."', VAT_PERCENT='".$this->getCheckNullVal($txtVAT)."', NET_PAYABLE_TAX='".$this->getCheckNullVal($txtAmtPayableWithTax)."', SGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtSGST_Amount)."', CGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtCGST_Amount)."', IGST_PERCENT_AMOUNT='".$this->getCheckNullVal($txtIGST_Amount)."', VAT_PERCENT_AMOUNT='".$this->getCheckNullVal($txtVAT_Amount)."', APPROVERS='".$approversel."', UPLOAD='".$upload1."', UPLOAD_NAME='".$name1."', BL_DATE='".$txtBLDate."', BL_NO='".$txtBLNo."', FLAG='".$txtFlag."', IMO_NO='".$txtIMONo."', LOAD_PORT_NAME='".$txtLoadPortName."', DISCHARGE_PORT_NAME='".$txtDischargePortName."', FREIGHT_RATE='".	 $txtFrieghtRate."', MANUAL_VENDOR_NAME='".$txtManualVendorName."',c_bank_check='".$c_bank_check."' where INVOICEID='".$qrows['INVOICEID']."'";
	
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$sql_del = "delete from freight_invoice_in_slave where INVOICEID='".$qrows['INVOICEID']."'";
		mysql_query($sql_del);
		mysql_query("commit");
		
		$txtAddID  = $_REQUEST['txtAddID'];
		for($i=1;$i<=$txtAddID;$i++)
		{
			if(isset($_REQUEST['txtAddDes_'.$i]))
			{
				$txtAddDes	 	  = addslashes(trim($_REQUEST['txtAddDes_'.$i]));
				$txtAddDesAmt	  = $this->getCheckNullVal($_REQUEST['txtAddDesAmt_'.$i]);
				$sql2 = "insert into freight_invoice_in_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtAddDes."', '".$txtAddDesAmt."', 'ADD')";
				mysql_query($sql2);
			}
		}
		
		$txtSubID  = $_REQUEST['txtSubID'];
		for($i=1;$i<=$txtSubID;$i++)
		{
			if(isset($_REQUEST['txtSubDes_'.$i]))
			{
				$txtSubDes	 	  = addslashes(trim($_REQUEST['txtSubDes_'.$i]));
				$txtSubDesAmt	  = $this->getCheckNullVal($_REQUEST['txtSubDesAmt_'.$i]);
				$sql2 = "insert into freight_invoice_in_slave (INVOICEID, DESCRIPTION, AMOUNT, IDENTIFY) values ('".$qrows['INVOICEID']."', '".$txtSubDes."', '".$txtSubDesAmt."', 'SUB')";
				mysql_query($sql2);
			}
		}
		
		
		$this->saveRecentWork($selIType." Freight Payment (".$txtDNote.") Updated Successfully.");
	}
	
	$this->inactiveUserAlerts('FREIGHT PAYMENT', $_SESSION['uid'], $invoiceidd);
	
	if($_REQUEST['invtype']=='Interim')
	{
		$creatorsarr = array($creatorloginid);
		$approverarr1 = $_REQUEST['selApprovers'];
		$approverarr2 = $this->getUsersWithAuthority('INI_FREIGHT_CHK_APP_2');
		$appaccountarr = $this->getUsersWithAuthority('INI_FREIGHT_CHK_ACC');
	}else
	{
	    $creatorsarr = array($creatorloginid);
		$approverarr1 = $_REQUEST['selApprovers'];
		$approverarr2 = $this->getUsersWithAuthority('FINL_FREIGHT_CHK_APP_2');
		$appaccountarr = $this->getUsersWithAuthority('FINL_FREIGHT_CHK_ACC');
	}
	$url = './invoice_payment.php?id='.$_REQUEST['id'].'&page='.$_REQUEST['page'].'&name='.$_REQUEST['name']."&invtype=".$_REQUEST['invtype'];
	$currentusername = $this->getUserDetailBaseOnId($_SESSION['uid'], 'CONTACT_PERSON');
	if($_REQUEST['invtype']=='Interim'){$invtitleType = 'INITIAL FREIGHT PAYMENT';}else{$invtitleType = 'FINAL FREIGHT PAYMENT';}
	
	$vesselname = $this->getVesselIMOData($this->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");
	
	if($invoiceidd != '' && $txtStatus >= 1)
	{
	    $userarray = array();
	    if($txtStatus == 1)
		{  
		     if(!empty($approverarr1))
			 {
			 	 $userarray = $approverarr1;
			 }
		     else if(empty($approverarr1) && !empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT PAYMENT', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.') for Level 1 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 2)
		{  
		     $userarray = $creatorsarr;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT PAYMENT', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 4)
		{  
		     $userarray = $approverarr1;
			 
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT PAYMENT', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.') for Review', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 3)
		{
		     if(!empty($approverarr2))
			 {
			     $userarray = $approverarr2;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT PAYMENT', $currentusername.' sent '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.') for Level 2 Approval', $invoiceidd);				  
				  }
			 }
		}
		
		if($txtStatus == 5)
		{
		     if(!empty($appaccountarr))
			 {
			     $userarray = $appaccountarr;
			 }
			 if(!empty($userarray))
			 {
			      foreach($userarray as $userarray1)
				  {
				       $this->saveUserAlerts($_SESSION['uid'], $userarray1, $url, 'FREIGHT PAYMENT', $currentusername.' Approved '.$invtitleType.' ('.$vesselname.' - '.$txtDNote.').', $invoiceidd);				  
				  }
			 }
		}
	}
	mysql_query("commit");
	return $msg.','.$comid;  
}

function insertFreightPaymentReceivedDetails_in()
{
	$connect = $this->funConnect();
	$id					= addslashes(trim($_REQUEST['comid']));
	$txtP_ID 			= addslashes(trim($_REQUEST['txtP_ID']));
	
	$txtP_Remarks 		= addslashes(trim($_REQUEST['txtP_Remarks']));
	$txtP_PR 			= addslashes(trim($_REQUEST['txtP_PR']));
	
	
	$txtCRMFILE1			= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME1			= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['mul_file']);
	$name = $this->getUploadName($_FILES['mul_file']);
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "update freight_invoice_in_master set P_REMARKS='".$txtP_Remarks."',P_AMT='".$txtP_PR."', ATTACHMENTS='".addslashes(trim($upload1))."', ATTACHMENTS_NAME='".addslashes(trim($name1))."', ACC_USER='".$_SESSION['uid']."' where INVOICEID='".$txtP_ID."' ";
	mysql_query($sql)or die($sql);
	mysql_query("commit");
	
	$sql_del1 = "delete from freight_invoice_in_slave1 where INVOICEID='".$txtP_ID."'";
	mysql_query($sql_del1);
	mysql_query("commit");
	
	$txtPaymentID  = $_REQUEST['txtPaymentID'];
	for($i=1;$i<=$txtPaymentID;$i++)
	{
		if(isset($_REQUEST['txtP_Date_'.$i]) && $_REQUEST['txtP_Date_'.$i]!='' && $_REQUEST['txtP_PR_'.$i]!='')
		{
		    $txtP_Date	 	  = date("Y-m-d",strtotime($_REQUEST['txtP_Date_'.$i]));
			$txtP_Remarks 	  = addslashes(trim($_REQUEST['txtP_Remarks_'.$i]));
			$txtP_PR     	  = $this->getCheckNullVal($_REQUEST['txtP_PR_'.$i]);
			$sql2 = "insert into freight_invoice_in_slave1 (INVOICEID, RECVD_DATE, RECVD_REMARKS, RECVD_AMOUNT) values ('".$txtP_ID."', '".$txtP_Date."', '".$txtP_Remarks."', '".$txtP_PR."')";
			mysql_query($sql2);
			mysql_query("commit");
		}
	}
	
	$this->inactiveUserAlerts('FREIGHT PAYMENT', $_SESSION['uid'], $txtP_ID);
	
	return $msg.'_'.$id; 
}


function deletefreightInvoiceRecords_in()
{
	$connect			= $this->funConnect();
 	$id 				= addslashes(trim($_REQUEST['txtDEL_ID']));
	$comid 			= addslashes(trim($_REQUEST['comid']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 2;
	
	
	$sql = "delete from freight_invoice_in_master where INVOICEID='".$id."'";
	$result = mysql_query($sql);
	
		
	$sql1 = "delete from freight_invoice_in_slave where INVOICEID='".$id."'";
	$result1 = mysql_query($sql1);
	
	$sql1 = "delete from freight_invoice_in_slave1 where INVOICEID='".$id."'";
	$result1 = mysql_query($sql1);

	mysql_query("commit"); 
	return $msg.','.$comid;
}

function viewFreightCostEstimationTempleteRecords_in($vesselimoid, $voyageno)
{
	$connect = $this->funConnect();
	$sql = "select * from freight_cost_estimete_in_master where VESSEL_IMO_ID='".$vesselimoid."' and VOYAGE_NO='".$voyageno."'";
	$result = mysql_query($sql) or die($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['FCAID'];
		$this->var_2 = $rows['FIXTURETYPEID'];
		$this->var_3 = $rows['TRANS_DATE'];
		$this->var_4 = $rows['ADDED_BY'];
		$this->var_5 = $rows['VESSEL_IMO_ID'];
		$this->var_6 = $rows['VESSEL_TYPE'];
		$this->var_7 = $rows['FLAG'];
		$this->var_8 = $rows['VOYAGE_NO'];
		$this->var_9 = $rows['VOYAGE_NAME'];
		$this->var_10 = $rows['DWT_SUMMER'];
		$this->var_11 = $rows['DWT_TOPICAL'];
		$this->var_12 = $rows['RDO_CAP'];
		$this->var_13 = $rows['GRAIN_CAP'];
		$this->var_14 = $rows['BALE_CAP'];
		$this->var_15 = $rows['SF'];
		$this->var_16 = $rows['LODABLE'];
		$this->var_17 = $rows['GNRT'];
		$this->var_18 = $rows['LOA'];
		$this->var_19 = $rows['GEAR'];
		$this->var_20 = $rows['BUILD_YEAR'];
		$this->var_21 = $rows['BEAM'];
		$this->var_22 = $rows['TPC'];
		$this->var_23 = $rows['BFULLSPEED'];
		$this->var_24 = $rows['BECOSPEED1'];
		$this->var_25 = $rows['BECOSPEED2'];
		$this->var_26 = $rows['LFULLSPEED'];
		$this->var_27 = $rows['LECOSPEED1'];
		$this->var_28 = $rows['LECOSPEED2'];
		$this->var_29 = $rows['BFOFULLSPEED'];
		$this->var_30 = $rows['BFOECOSPEED1'];
		$this->var_31 = $rows['BFOECOSPEED2'];
		$this->var_32 = $rows['LFOFULLSPEED'];
		$this->var_33 = $rows['LFOECOSPEED1'];
		$this->var_34 = $rows['LFOECOSPEED2'];
		$this->var_35 = $rows['PIFOFULLSPEED'];
		$this->var_36 = $rows['PWFOFULLSPEED'];
		$this->var_37 = $rows['BDOFULLSPEED'];
		$this->var_38 = $rows['BDOECOSPEED1'];
		$this->var_39 = $rows['BDOECOSPEED2'];
		$this->var_40 = $rows['LDOFULLSPEED'];
		$this->var_41 = $rows['LDOECOSPEED1'];
		$this->var_42 = $rows['LDOECOSPEED2'];
		$this->var_43 = $rows['PIDOFULLSPEED'];
		$this->var_44 = $rows['PWDOFULLSPEED'];
		$this->var_45 = $rows['RDO_MARKER'];
		$this->var_46 = $rows['RDO_DWT'];
		$this->var_47 = $rows['FREIGHT_GROSS'];
		$this->var_48 = $rows['LUMSUM'];
		$this->var_49 = $rows['CARGO_RATE'];
		$this->var_50 = $rows['QUANTITY'];
		$this->var_51 = $rows['CARGO_TYPE'];
		$this->var_52 = $rows['CARGO_ID'];
		$this->var_53 = $rows['DF_QUANTITY'];
		$this->var_54 = $rows['ADDNL_QUANTITY'];
		$this->var_55 = $rows['LADEN_DIST'];
		$this->var_56 = $rows['BALLAST_DIST'];
		$this->var_57 = $rows['LADEN_DAYS'];
		$this->var_58 = $rows['BALLAST_DAYS'];
		$this->var_59 = $rows['TOTAL_PASSAGE_DAYS'];
		$this->var_60 = $rows['IDEAL_DAYS'];
		$this->var_61 = $rows['WORKING_DAYS'];
		$this->var_62 = $rows['TOTAL_DAYS'];
		$this->var_63 = $rows['TOTAL_DISTANCE'];
		$this->var_64 = $rows['FO_CONSP'];
		$this->var_65 = $rows['DO_CONSP'];
		$this->var_66 = $rows['GROSS_PREIGHT_ADJ'];
		$this->var_67 = $rows['DEAD_PREIGHT_ADJ'];
		$this->var_68 = $rows['ADDNL_PREIGHT_ADJ'];
		$this->var_69 = $rows['TOTAL_PREIGHT_ADJ'];
		$this->var_70 = $rows['GROSS_PREIGHT_ADJ_PRMT'];
		$this->var_71 = $rows['DEAD_PREIGHT_ADJ_PRMT'];
		$this->var_72 = $rows['ADDNL_PREIGHT_ADJ_PRMT'];
		$this->var_73 = $rows['TOTAL_PREIGHT_ADJ_PRMT'];
		$this->var_74 = $rows['ADDRESS_COMMISSION_PER'];
		$this->var_75 = $rows['ADDRESS_COMMISSION_AMT'];
		$this->var_76 = $rows['ADDRESS_COMMISSION_PRMT'];
		$this->var_77 = $rows['BROKERAGE_PER'];
		$this->var_78 = $rows['BROKERAGE_AMT'];
		$this->var_79 = $rows['BROKERAGE_PRMT'];
		$this->var_80 = $rows['FINAL_NET_FREIGHT'];
		$this->var_81 = $rows['FINAL_NET_FREIGHT_PRMT'];
		$this->var_82 = $rows['BROKERAGE_COMMISSION_PER'];
		$this->var_83 = $rows['BROKERAGE_COMMISSION_AMT'];
		$this->var_84 = $rows['TOTAL_ORC_EXP_AMT'];
		$this->var_85 = $rows['TOTAL_ORC_EXP_PRMT'];
		$this->var_86 = $rows['REVENUES_FREIGHT'];
		$this->var_87 = $rows['TOTAL_OWNER_EXP'];
		$this->var_88 = $rows['CHARTERER_EXP'];
		$this->var_89 = $rows['VOYAGE_EARNING'];
		$this->var_90 = $rows['DAILY_EARNING'];
		$this->var_91 = $rows['DAILY_VESSEL_OPERATION_EXP'];
		$this->var_92 = $rows['TOTAL_VOYAGE_EARNING'];
		$this->var_93 = $rows['NET_DAILY_PROFIT'];
		$this->var_94 = $rows['NET_DAILY_EARNING'];
		$this->var_95 = $rows['PROFIT_LOSS'];
		$this->var_96 = $rows['RDO_QTY'];
		$this->var_97 = $rows['FIXED'];
		$this->var_98 = $rows['COMID'];
		$this->var_99 = $rows['SHEET_NO'];
		$this->var_100 = $rows['OPEN_PORT'];
		$this->var_101 = $rows['ZONE_OPEN'];
		$this->var_127 = $rows['BROKER'];
		$this->var_126 = $rows['COA_SPOT'];
		$this->var_102 = $rows['COA_NUMBER'];
		$this->var_103 = $rows['COA_NUMBER_LIFT'];
		$this->var_104 = $rows['NO_OF_SHIPMENT'];
		$this->var_105 = $rows['VESSEL_CATEGORY'];
		$this->var_106 = $rows['EXPECTED_HIRE'];
		$this->var_107 = $rows['OWNER'];
		$this->var_108 = $rows['DISPONENT_OWNER'];
		$this->var_109 = $rows['LAYCAN_START_DATE'];
		$this->var_110 = $rows['LAYCAN_FINISH_DATE'];
		$this->var_111 = $rows['ETA_DATE'];
		$this->var_112 = $rows['CP_DATE'];
		$this->var_113 = $rows['REMARKS'];
		$this->var_114 = $rows['TC_DESC'];
		$this->var_115 = $rows['ATTACHMENT'];
		$this->var_116 = $rows['ATTACHMENT_NAME'];
		$this->var_128 = $rows['CARGOID'];
		$this->var_117 = $rows['SHIPPER'];
		$this->var_118 = $rows['TOLERANCE'];
		$this->var_119 = $rows['MATERIALID'];
		$this->var_120 = $rows['MATERIAL_CODE'];
		$this->var_121 = $rows['TERM_TOLERANCE'];
		$this->var_122 = $rows['LPID'];
		$this->var_123 = $rows['DPID'];
		$this->var_124 = $rows['LAYCAN_CARGO_START_DATE'];
		$this->var_125 = $rows['LAYCAN_CARGO_FINISH_DATE'];
		$this->var_132 = $rows['HIREAGE_AMT'];
		$this->var_129 = $rows['HIREAGE_PERCENT'];
		$this->var_130 = $rows['HIREAGE_PER_AMT'];
		$this->var_131 = $rows['HIREAGE_NETT_AMT'];
		$this->var_155 = $rows['QTY_TYPE_RADIO'];
		$this->var_133 = $rows['AGREED_GROSS_FREIGHT_LOCAL'];
		$this->var_134 = $rows['CURRENCYID'];
		$this->var_135 = $rows['EXCHANGE_RATE'];
		$this->var_136 = $rows['TTL_FO_CONSP_MT_MANUAL'];
		$this->var_137 = $rows['TTL_DO_CONSP_MT_MANUAL'];
		$this->var_138 = $rows['TTL_FO_CONSP_OFFHIRE'];
		$this->var_139 = $rows['TTL_DO_CONSP_OFFHIRE'];
		$this->var_140 = $rows['DTCVENDORID'];
		$this->var_141 = $rows['FGFF_VENDORID'];
		$this->var_142 = $rows['CVE_AMT'];
		$this->var_143 = $rows['CVE_TOTALAMT'];
		$this->var_144 = $rows['CVE_VENDORID'];
		$this->var_145 = $rows['BALLAST_BONUS'];
		$this->var_146 = $rows['BROKERAGE_PERCENT'];
		$this->var_147 = $rows['BROKERAGE_AMOUNT'];
		$this->var_148 = $rows['ILOHC_AMT'];
		$this->var_149 = $rows['BALLAST_VENDORID'];
		$this->var_150 = $rows['BROKERAGE_VENDORID'];
		$this->var_151 = $rows['ILOHC_VENDORID'];
		$this->var_152 = $rows['BUNKER_EXPENSES'];
		$this->var_153 = $rows['PORT_EXPENSES'];
		$this->var_154 = $rows['HIDDEN_HIRAGE'];
		$this->var_156 = $rows['DISTRIBUTED_REMARKS'];
		$this->var_157 = $rows['ADDNL_FREIGHT_PER'];
		
		$this->var_158 = $rows['ESTIMATE_TYPE'];
		$this->var_159 = $rows['GAS_MARKET'];
		$this->var_160 = $rows['GAS_BALTIC'];
		$this->var_161 = $rows['ADDNL_PRENIUM'];
		$this->var_162 = $rows['GAS_BASE_RATE'];
		$this->var_163 = $rows['GAS_QUANTITY'];
		$this->var_164 = $rows['GAS_LUMSUM'];
		$this->var_165 = $rows['TANK_WS_FROM'];
		$this->var_166 = $rows['TANK_WS_TO'];
		$this->var_167 = $rows['TANK_FIXED_DIFF'];
		$this->var_168 = $rows['TANK_QUANTITY'];
		$this->var_169 = $rows['ATTACHMENT2'];
		$this->var_170 = $rows['ATTACHMENT2_NAME'];
		$this->var_171 = $rows['CHK_LUMPSUM'];
		$this->var_172 = $rows['LUMPSUMAMT'];
		$this->var_173 = $rows['WS_QTY'];
		$this->var_174 = $rows['LUMP_VENDOR'];
		$this->var_175 = $rows['COAID'];
		$this->var_176 = $rows['BASERATE_FLOAT'];
		$this->var_177 = $rows['BASERATE_FIXED'];
		$this->var_178 = $rows['BASERATE_AVERAGE'];
		$this->var_179 = $rows['GROSS_FREIGHT_FLOAT'];
		$this->var_180 = $rows['GROSS_FREIGHT_FIXED'];
		$this->var_181 = $rows['GROSS_FREIGHT_AVERAGE'];
		$this->var_182 = $rows['NETFREIGHT_FLOAT'];
		$this->var_183 = $rows['NETFREIGHT_FIXED'];
		$this->var_184 = $rows['NETFREIGHT_AVERAGE'];
		$this->var_185 = $rows['OWNER_EXPENSES_FLOAT'];
		$this->var_186 = $rows['OWNER_EXPENSES_FIXED'];
		$this->var_187 = $rows['OWNER_EXPENSES_AVERAGE'];
		$this->var_188 = $rows['VEARNING_FLOAT'];
		$this->var_189 = $rows['VEARNING_FIXED'];
		$this->var_190 = $rows['VEARNING_AVERAGE'];
		$this->var_191 = $rows['TCEEARNING_FLOAT'];
		$this->var_192 = $rows['TCEEARNING_FIXED'];
		$this->var_193 = $rows['TCEEARNING_AVERAGE'];
		$this->var_194 = $rows['TCE_MONTH_FLOAT'];
		$this->var_195 = $rows['TCE_MONTH_FIXED'];
		$this->var_196 = $rows['TCE_MONTH_AVERAGE'];
		$this->var_197 = $rows['OEXPENSES_FLOAT'];
		$this->var_198 = $rows['OEXPENSES_FIXED'];
		$this->var_199 = $rows['OEXPENSES_AVERAGE'];
		$this->var_200 = $rows['NET_DAILY_ER_FLOAT'];
		$this->var_201 = $rows['NET_DAILY_ER_FIXED'];
		$this->var_202 = $rows['NET_DAILY_ER_AVERAGE'];
		$this->var_203 = $rows['NET_DAILY_PROFIT_FLOAT'];
		$this->var_204 = $rows['NET_DAILY_PROFIT_FIXED'];
		$this->var_205 = $rows['NET_DAILY_PROFIT_AVERAGE'];
		$this->var_206 = $rows['OPEN_CARGOID'];
		
		$this->var_207 = $rows['SUMMERDWTMT'];
		$this->var_208 = $rows['SUMMERDWTLT'];
		$this->var_209 = $rows['SUMMERDRAFTM'];
		$this->var_210 = $rows['SUMMERDRAFTFT'];
		$this->var_211 = $rows['TPI_MT_INCH'];
		$this->var_212 = $rows['TPI_LT_INCH'];
		$this->var_213 = $rows['TPC_MT'];
		$this->var_214 = $rows['TPC_LT'];
		$this->var_215 = $rows['CONSTANT_MT'];
		$this->var_216 = $rows['CONSTANT_LT'];
		$this->var_217 = $rows['GRAIN_CAP_CBM'];
		$this->var_218 = $rows['GRAIN_CAP_CFT'];
		$this->var_219 = $rows['ALLOWED_DRAFTM'];
		$this->var_220 = $rows['BUNKER_ROB_MT'];
		$this->var_221 = $rows['CARGO_INTAKE_MT'];
		$this->var_222 = $rows['SF_CBM_MT'];
		$this->var_223 = $rows['SF_CBFT_MT'];
		$this->var_224 = $rows['CARGO_LOADABLE_MT'];
		$this->var_226 = $rows['GROSS_BREAKDOWN'];
	    $this->var_227 = $rows['BREAKDOWN_MT'];
		$this->var_228 = $rows['TANKER_RADIO_SINGLE_DIS'];
		$this->var_229 = $rows['TC_NO'];
		
		$this->var_230 = $rows['GROSS_HIERAGE_AMOUNT'];
		$this->var_231 = $rows['HIERAGE_CVE'];
		$this->var_232 = $rows['HIERAGE_CVE_AMOUNT'];
	    $this->var_233 = $rows['OFF_HIRE_CVE'];
		$this->var_234 = $rows['OFF_HIRE_CVE_AMOUNT'];
		$this->var_235 = $rows['LESS_OFF_HIRE'];
		$this->var_236 = $rows['FINAL_HIERAGE_AMOUNT'];
		$this->var_237 = $rows['HIERAGE_BROKER_PERCENT'];
		$this->var_238 = $rows['HIERAGE_BROKER_AMT'];
		$this->var_239 = $rows['TC_HIRE_DAYS'];
		$this->var_240 = $rows['TC_CP_DATE'];
		$this->var_241 = $rows['PERIODID'];
		$this->var_242 = $rows['AUTO_PL'];
		
		$this->var_243 = $rows['LESS_PER_BLQTY'];
		$this->var_244 = $rows['BL_QTY_FREIGHT'];
		
		$this->var_245 = $rows['TC_DELIVERY_DATE'];
		$this->var_246 = $rows['TC_RE_DELIVERY_DATE'];
		$this->var_247 = $rows['TC_DELIVERY_RANGE'];
		$this->var_248 = $rows['TC_RE_DELIVERY_RANGE'];
		$this->var_249 = $rows['ACTUAL_PL'];
		$this->var_250 = $rows['TANKER_FREIGHT_RATE'];
		
		$this->var_251 = $rows['TANK_CLEANING_SECA_HRS'];
		$this->var_252 = $rows['TANK_CLEANING_NONSECA_HRS'];
		$this->var_253 = $rows['INERTING_SECA_HRS'];
		$this->var_254 = $rows['INERTING_NONSECA_HRS'];
		$this->var_255 = $rows['GAS_FREEING_SECA_HRS'];
		$this->var_256 = $rows['GAS_FREEING_NONSECA_HRS'];
		$this->var_257 = $rows['HEATING_SECA_HRS'];
		$this->var_258 = $rows['HEATING_NONSECA_HRS'];
		$this->var_259 = $rows['HEATING_SECA_HRS_1'];
		$this->var_260 = $rows['HEATING_NONSECA_HRS_1'];
		$this->var_261 = $rows['CHARTERING_PIC'];
		
		$sql2 = "select OPEN_CARGOID, CPID, (select MATERIAL_CODE_DESC from cargo_master where cargo_master.MATERIALID = open_cargo_master.CARGO) as CARGONAME, CARGOSTEAMSIZE, LAYCAN_SDATE, BASE_FREIGHT, RDO_WS_TYPE, WS_LUMPSUM_AMOUNT, (case when (RDO_WS_TYPE = 1) THEN 'WS' ELSE 'Lumpsum' END) as WS_RDO_TEXT, (case when (RDO_WS_TYPE = 1) THEN 'Base Freight' ELSE 'Lumpsum' END) as WS_RDO_TEXT1, CARGO_RELET, COA_SPOT from open_cargo_master where OPEN_CARGOID='".$rows['OPEN_CARGOID']."'";
		
		$result2 = mysql_query($sql2) or die($sql2);
		$rows2   = mysql_fetch_assoc($result2);
		$freightdata = '';
		if($_SESSION['selBType']==1)
		{
			 if($rows2['RDO_WS_TYPE'] ==1)
		 	 {
		     	$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Base Freight(USD): '.$rows2['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT/Lumpsum (USD):'.$rows2['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==2)
		{
			 if($rows2['RDO_WS_TYPE'] ==1)
		 	 {
		     	$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, WS:'.$rows2['WS_LUMPSUM_AMOUNT'].' ';
			 }else{
				$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Lumpsum (USD):'.$rows2['WS_LUMPSUM_AMOUNT'] ;
			 }
		}
		if($_SESSION['selBType']==3)
		{
			$this->var_225 = "CPID:".$rows2['CPID'].', Laycan Start:'.date('d-m-Y',strtotime($rows2['LAYCAN_SDATE'])).', Cargo:'.$rows2['CARGONAME'].', Qty:'.$rows2['CARGOSTEAMSIZE'].' MT, Freight (USD):'.$rows2['BASE_FREIGHT'].' ';
		}
	}
}


function getTCICostSheetRecDetails_IN($vesselimoid, $voyageno)
{
	$connect = $this->funConnect();
	$sql = "select * from freight_cost_estimete_in_master where VESSEL_IMO_ID='".$vesselimoid."' and VOYAGE_NO='".$voyageno."'";	
	$res = mysql_query($sql) or die($sql);
	$rec = mysql_num_rows($res);
	return $rec;
}


function insertTCICostSheetDetails_in()
{	
	$connect = $this->funConnect();
	$selFType	 		= addslashes(trim($_REQUEST['selFType']));
	$selVName 		    = addslashes(trim($_REQUEST['selVName']));
	
	$txtVType	 		= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 		= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 		= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo  	 		= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 		= addslashes(trim($_REQUEST['txtENo']));
	
	$rdoDWT 	 		= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 		= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT            = addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 		= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    		= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    		= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      		= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 		= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 		= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     		= addslashes(trim($_REQUEST['txtLOA']));
	
	$txtGear	 		= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 		= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    		= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 			= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed		= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    = addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2		= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    = addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1		= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    = addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed	= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1    = addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2	= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    = addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    = addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2	= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   = addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed	= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    = addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1	= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2	= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1	= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    = addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed   = addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed	= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	$rdoQty             = addslashes(trim($_REQUEST['rdoQty']));
	$rdoMMarket         = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	    = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    = addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT        = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    = addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	$txtMLumpsum	    = addslashes(trim($_REQUEST['txtMLumpsum']));
	
	$selCName           = addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            = addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        = addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    = addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    = addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           = addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        = addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        = addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    = addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    = addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          = addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    = addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    = addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    = addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    = addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           = addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    = addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 		= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      = addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT	= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    = addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    = addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 		= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      = addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT	= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    = addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     = addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 		= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           = addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         = addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    = addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        = addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount	= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   = addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        = addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        = addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       = addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    = addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
	$txtAddnlCRatePer                  = addslashes(trim($_REQUEST['txtAddnlCRatePer']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	
	
	$selOpenPort 	 	= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 		= addslashes(trim($_REQUEST['selZone']));
	$selBroker          = addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 	= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 	= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    		= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    = addslashes(trim($_REQUEST['selOwner']));
	$txtDisponentOwner	= addslashes(trim($_REQUEST['txtDisponentOwner']));
	if($_REQUEST['txtFDate']!="")
	{
	$txtFDate     		= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	}

	else{$txtFDate     		= "1970-01-01";}
	if($_REQUEST['txtTDate']!="")
	{
	$txtTDate     		= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	}
	else{$txtTDate     		= "1970-01-01";}
	if($_REQUEST['txtETADate']!="")
	{
	$txtETADate     		= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	}
	else{$txtETADate     		= "1970-01-01";}
	if($_REQUEST['txtCPDate']!="")
	{
	$txtCPDate     		= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	}
	else{$txtCPDate     		= "1970-01-01";}
	$txtNotes     		= addslashes(trim($_REQUEST['txtNotes']));
	
	$txtCID 	 		= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 		= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       = addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 		= implode(',',$_REQUEST['selMType']);
	$txtMCode    		= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance	= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      		= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    = addslashes(trim($_REQUEST['selDPort']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	
	$txtTFUMTManual 		   = addslashes(trim($_REQUEST['txtTFUMTManual']));
	$txtTDUMTManual            = addslashes(trim($_REQUEST['txtTDUMTManual']));
	$txtTFOCOffHire		 	   = addslashes(trim($_REQUEST['txtTFOCOffHire']));
	$txtTDOCOffHire     	   = addslashes(trim($_REQUEST['txtTDOCOffHire']));
	$selDTCVendor       	   = addslashes(trim($_REQUEST['selDTCVendor']));
	$txtFGFFVendor       	   = addslashes(trim($_REQUEST['txtFGFFVendor']));
	
	$txtCVE           	   = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt       	   = addslashes(trim($_REQUEST['txtCVEAmt']));
	$selCVEVendor          = addslashes(trim($_REQUEST['selCVEVendor']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selBroVendor       = addslashes(trim($_REQUEST['selBroVendor']));
	$selILOHCVendor     = addslashes(trim($_REQUEST['selILOHCVendor']));
	$txtDistributedRemarks     = addslashes(trim($_REQUEST['txtDistributedRemarks']));  
	
	if(isset($_REQUEST['txtHiddenHirage']))
	{
	   $txtHiddenHirage     		= $_REQUEST['txtHiddenHirage'];
	}
	else{$txtHiddenHirage     		= $_REQUEST['txtHireargeAmt'];}
	
	if($_REQUEST['txtLCSDate']!="")
	{
	$txtLCSDate   		= date("Y-m-d",strtotime($_REQUEST['txtLCSDate']));
	}
	else{$txtLCSDate     		= "1970-01-01";}
	if($_REQUEST['txtLCFDate']!="")
	{
	$txtLCFDate     	= date("Y-m-d",strtotime($_REQUEST['txtLCFDate']));
	}
	else{$txtLCFDate     		= "1970-01-01";}
	
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$txtCRMFILE2							= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2							= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['attach_file1']);
	$name = $this->getUploadName($_FILES['attach_file1']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$selLumsumVendor 	    = addslashes(trim($_REQUEST['selLumsumVendor']));
	$txtLumpsumQty          = $_REQUEST['txtLumpsumQty'];
	
	$txtBaseRateFloating    = addslashes(trim($_REQUEST['txtBaseRateFloating']));
	$txtBaseRateFixed       = addslashes(trim($_REQUEST['txtBaseRateFixed']));
	$txtBaseRateAverage     = addslashes(trim($_REQUEST['txtBaseRateAverage']));
	
	$txtGFreightFloating    = addslashes(trim($_REQUEST['txtGFreightFloating']));
	$txtGFreightFixed       = addslashes(trim($_REQUEST['txtGFreightFixed']));
	$txtGFreightAverage     = addslashes(trim($_REQUEST['txtGFreightAverage']));
	
	$txtNFreightFloating    = addslashes(trim($_REQUEST['txtNFreightFloating']));
	$txtNFreightFixed       = addslashes(trim($_REQUEST['txtNFreightFixed']));
	$txtNFreightAverage     = addslashes(trim($_REQUEST['txtNFreightAverage']));
	
	$txtOExpensesFloating   = addslashes(trim($_REQUEST['txtOExpensesFloating']));
	$txtOExpensesFixed      = addslashes(trim($_REQUEST['txtOExpensesFixed']));
	$txtOExpensesAverage    = addslashes(trim($_REQUEST['txtOExpensesAverage']));
	
	$txtVEarningFloating    = addslashes(trim($_REQUEST['txtVEarningFloating']));
	$txtVEarningFixed       = addslashes(trim($_REQUEST['txtVEarningFixed']));
	$txtVEarningAverage     = addslashes(trim($_REQUEST['txtVEarningAverage']));
	
	$txtDailyEarningFloating= addslashes(trim($_REQUEST['txtDailyEarningFloating']));
	$txtDailyEarningFixed   = addslashes(trim($_REQUEST['txtDailyEarningFixed']));
	$txtDailyEarningAverage = addslashes(trim($_REQUEST['txtDailyEarningAverage']));
	
	$txtTCEMonthFloating    = addslashes(trim($_REQUEST['txtTCEMonthFloating']));
	$txtTCEMonthFixed       = addslashes(trim($_REQUEST['txtTCEMonthFixed']));
	$txtTCEMonthAverage     = addslashes(trim($_REQUEST['txtTCEMonthAverage']));
	
	$txtOPExpensesFloating  = addslashes(trim($_REQUEST['txtOPExpensesFloating']));
	$txtOPExpensesFixed     = addslashes(trim($_REQUEST['txtOPExpensesFixed']));
	$txtOPExpensesAverage   = addslashes(trim($_REQUEST['txtOPExpensesAverage']));
	
	$txtNetDailyEarningFloating= addslashes(trim($_REQUEST['txtNetDailyEarningFloating']));
	$txtNetDailyEarningFixed= addslashes(trim($_REQUEST['txtNetDailyEarningFixed']));
	$txtNetDailyEarningAverage= addslashes(trim($_REQUEST['txtNetDailyEarningAverage']));
	
	$txtNetDailyProfitFloating= addslashes(trim($_REQUEST['txtNetDailyProfitFloating']));
	$txtNetDailyProfitFixed = addslashes(trim($_REQUEST['txtNetDailyProfitFixed']));
	$txtNetDailyProfitAverage= addslashes(trim($_REQUEST['txtNetDailyProfitAverage']));
	$selCargoPlanning       = $_REQUEST['selCargoPlanning'];
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$rdoTankType        = addslashes(trim($_REQUEST['rdoTankType']));
	$txtTCNo                = addslashes(trim($_REQUEST['txtTCNo']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	$selPeriodContract = addslashes(trim($_REQUEST['selPeriodContract']));
	
	$txtBLCQMT              = addslashes(trim($_REQUEST['txtBLCQMT']));
    $txtLessPerQty          = addslashes(trim($_REQUEST['txtLessPerQty']));
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	if($_REQUEST['txtTCDeliveryDate']!="")
	{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate']));}
	else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtTCReDeliveryDate']!="")
	{$txtTCReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate']));}
	else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	$txtTCDelivery = addslashes(trim($_REQUEST['txtTCDelivery']));
	$txtTCReDelivery = addslashes(trim($_REQUEST['txtTCReDelivery']));
	$txtTankerFreightRate = addslashes(trim($_REQUEST['txtTankerFreightRate']));

    $txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['comid'];
	$update_status       	   = addslashes(trim($_REQUEST['update_status']));
	
	$sql_fetch = "select FCAID from freight_cost_estimete_in_master where VESSEL_IMO_ID='".$this->getCheckNullValue($selFType)."' and VOYAGE_NO='".$txtVNo."'";
	$res_fetch = mysql_query($sql_fetch) or die($sql_fetch);
	$num_fetch = mysql_num_rows($res_fetch);
	if($num_fetch == 0)
	{
		$sql = "insert into freight_cost_estimete_in_master (FIXTURETYPEID, TRANS_DATE, MODULEID, MCOMPANYID, ADDED_BY, ADD_ON_DATE, VESSEL_IMO_ID, VESSEL_TYPE, FLAG, VOYAGE_NO, VOYAGE_NAME, DWT_SUMMER, DWT_TOPICAL, RDO_CAP, GRAIN_CAP, BALE_CAP, SF, LODABLE, GNRT, LOA, GEAR, BUILD_YEAR, BEAM, TPC, BFULLSPEED, BECOSPEED1, BECOSPEED2, LFULLSPEED, LECOSPEED1, LECOSPEED2, BFOFULLSPEED, BFOECOSPEED1, BFOECOSPEED2, LFOFULLSPEED, LFOECOSPEED1, LFOECOSPEED2, PIFOFULLSPEED, PWFOFULLSPEED, BDOFULLSPEED, BDOECOSPEED1, BDOECOSPEED2, LDOFULLSPEED, LDOECOSPEED1, LDOECOSPEED2, PIDOFULLSPEED, PWDOFULLSPEED, RDO_MARKER, RDO_DWT, FREIGHT_GROSS, LUMSUM, CARGO_RATE, QUANTITY, CARGO_TYPE, CARGO_ID, DF_QUANTITY, ADDNL_QUANTITY, LADEN_DIST, BALLAST_DIST, LADEN_DAYS, BALLAST_DAYS, TOTAL_PASSAGE_DAYS, IDEAL_DAYS, WORKING_DAYS, TOTAL_DAYS, TOTAL_DISTANCE, FO_CONSP, DO_CONSP, GROSS_PREIGHT_ADJ, DEAD_PREIGHT_ADJ, ADDNL_PREIGHT_ADJ, TOTAL_PREIGHT_ADJ, GROSS_PREIGHT_ADJ_PRMT, DEAD_PREIGHT_ADJ_PRMT, ADDNL_PREIGHT_ADJ_PRMT, TOTAL_PREIGHT_ADJ_PRMT, ADDRESS_COMMISSION_PER, ADDRESS_COMMISSION_AMT, ADDRESS_COMMISSION_PRMT, BROKERAGE_PER, BROKERAGE_AMT, NET_PAYABLE, FINAL_NET_FREIGHT, FINAL_NET_FREIGHT_PRMT, BROKERAGE_COMMISSION_PER, BROKERAGE_COMMISSION_AMT, TOTAL_ORC_EXP_AMT, TOTAL_ORC_EXP_PRMT, REVENUES_FREIGHT, TOTAL_OWNER_EXP, CHARTERER_EXP, VOYAGE_EARNING, DAILY_EARNING, DAILY_VESSEL_OPERATION_EXP, TOTAL_VOYAGE_EARNING, NET_DAILY_EARNING, NET_DAILY_PROFIT, PROFIT_LOSS, RDO_QTY  , OPEN_PORT, ZONE_OPEN, BROKER, COA_SPOT, COA_NUMBER, COA_NUMBER_LIFT, NO_OF_SHIPMENT, OWNER, DISPONENT_OWNER, LAYCAN_START_DATE, LAYCAN_FINISH_DATE, ETA_DATE, CP_DATE, REMARKS, ATTACHMENT, ATTACHMENT_NAME, CARGOID, SHIPPER, TOLERANCE, MATERIALID, MATERIAL_CODE, TERM_TOLERANCE, LPID, DPID, LAYCAN_CARGO_START_DATE, LAYCAN_CARGO_FINISH_DATE, HIREAGE_AMT, HIREAGE_PERCENT, HIREAGE_PER_AMT, HIREAGE_NETT_AMT, QTY_TYPE_RADIO, AGREED_GROSS_FREIGHT_LOCAL, CURRENCYID, EXCHANGE_RATE, TTL_FO_CONSP_MT_MANUAL, TTL_DO_CONSP_MT_MANUAL, TTL_FO_CONSP_OFFHIRE, TTL_DO_CONSP_OFFHIRE, SHEET_NO, COMID, DTCVENDORID, FINAL_STATUS, FGFF_VENDORID, CVE_AMT, CVE_TOTALAMT, CVE_VENDORID, BALLAST_BONUS, BUNKER_EXPENSES, PORT_EXPENSES, BROKERAGE_VENDORID, ILOHC_VENDORID, HIDDEN_HIRAGE, DISTRIBUTED_REMARKS, FIXED, ADDNL_FREIGHT_PER, ESTIMATE_TYPE, GAS_MARKET, GAS_BALTIC, ADDNL_PRENIUM, GAS_BASE_RATE, GAS_QUANTITY, GAS_LUMSUM, TANK_WS_FROM, TANK_WS_TO, TANK_FIXED_DIFF, TANK_QUANTITY, ATTACHMENT2, ATTACHMENT2_NAME, CHK_LUMPSUM, LUMPSUMAMT, WS_QTY, LUMP_VENDOR, BASERATE_FLOAT, BASERATE_FIXED, BASERATE_AVERAGE, GROSS_FREIGHT_FLOAT, GROSS_FREIGHT_FIXED, GROSS_FREIGHT_AVERAGE, NETFREIGHT_FLOAT, NETFREIGHT_FIXED, NETFREIGHT_AVERAGE, OWNER_EXPENSES_FLOAT, OWNER_EXPENSES_FIXED, OWNER_EXPENSES_AVERAGE, VEARNING_FLOAT, VEARNING_FIXED, VEARNING_AVERAGE, TCEEARNING_FLOAT, TCEEARNING_FIXED, TCEEARNING_AVERAGE, TCE_MONTH_FLOAT, TCE_MONTH_FIXED, TCE_MONTH_AVERAGE, OEXPENSES_FLOAT, OEXPENSES_FIXED, OEXPENSES_AVERAGE, NET_DAILY_ER_FLOAT, NET_DAILY_ER_FIXED, NET_DAILY_ER_AVERAGE, NET_DAILY_PROFIT_FLOAT, NET_DAILY_PROFIT_FIXED, NET_DAILY_PROFIT_AVERAGE, OPEN_CARGOID, GROSS_BREAKDOWN, BREAKDOWN_MT, TANKER_RADIO_SINGLE_DIS, TC_NO, GROSS_HIERAGE_AMOUNT, HIERAGE_CVE, HIERAGE_CVE_AMOUNT, OFF_HIRE_CVE, OFF_HIRE_CVE_AMOUNT, LESS_OFF_HIRE, FINAL_HIERAGE_AMOUNT, HIERAGE_BROKER_PERCENT, HIERAGE_BROKER_AMT, TC_HIRE_DAYS, TC_CP_DATE, PERIODID, LESS_PER_BLQTY, BL_QTY_FREIGHT, TC_DELIVERY_DATE, TC_RE_DELIVERY_DATE, TC_DELIVERY_RANGE, TC_RE_DELIVERY_RANGE, ACTUAL_PL, TANKER_FREIGHT_RATE, TANK_CLEANING_SECA_HRS, TANK_CLEANING_NONSECA_HRS, INERTING_SECA_HRS, INERTING_NONSECA_HRS, GAS_FREEING_SECA_HRS, GAS_FREEING_NONSECA_HRS, HEATING_SECA_HRS, HEATING_NONSECA_HRS, HEATING_SECA_HRS_1, HEATING_NONSECA_HRS_1) values ('".$this->getCheckNullValue($selFType)."','".$txtDate."','".$_SESSION['moduleid']."','".$this->getCheckNullValue($_SESSION['company'])."','".$_SESSION['uid']."', NOW(),'".$this->getCheckNullValue($selVName)."','".$txtVType."','".$txtFlag."','".$txtVNo."','".$txtENo."','".$this->getCheckNullValue($txtDWTS)."','".$this->getCheckNullValue($txtDWTT)."','".$this->getCheckNullValue($rdoCap)."','".$this->getCheckNullValue($txtGCap)."','".$this->getCheckNullValue($txtBCap)."','".$this->getCheckNullValue($txtSF)."','".$this->getCheckNullValue($txtLoadable)."','".$this->getCheckNullValue($txtGNRT)."','".$this->getCheckNullValue($txtLOA)."','".$txtGear."','".$txtBuiltYear."','".$this->getCheckNullValue($txtBeam)."','".$this->getCheckNullValue($txtTPC)."','".$this->getCheckNullValue($txtBFullSpeed)."','".$this->getCheckNullValue($txtBEcoSpeed1)."','".$this->getCheckNullValue($txtBEcoSpeed2)."','".$this->getCheckNullValue($txtLFullSpeed)."','".$this->getCheckNullValue($txtLEcoSpeed1)."','".$this->getCheckNullVal($txtLEcoSpeed2)."','".$this->getCheckNullVal($txtBFOFullSpeed)."','".$this->getCheckNullVal($txtBFOEcoSpeed1)."','".$this->getCheckNullVal($txtBFOEcoSpeed2)."','".$this->getCheckNullVal($txtLFOFullSpeed)."','".$this->getCheckNullVal($txtLFOEcoSpeed1)."','".$this->getCheckNullVal($txtLFOEcoSpeed2)."', '".$this->getCheckNullValue($txtPIFOFullSpeed)."', '".$this->getCheckNullValue($txtPWFOFullSpeed)."','".$this->getCheckNullValue($txtBDOFullSpeed)."','".$this->getCheckNullValue($txtBDOEcoSpeed1)."','".$this->getCheckNullVal($txtBDOEcoSpeed2)."','".$this->getCheckNullVal($txtLDOFullSpeed)."','".$this->getCheckNullVal($txtLDOEcoSpeed1)."','".$this->getCheckNullVal($txtLDOEcoSpeed2)."','".$this->getCheckNullVal($txtPIDOFullSpeed)."','".$this->getCheckNullVal($txtPWDOFullSpeed)."','".$this->getCheckNullVal($rdoMMarket)."','".$this->getCheckNullValue($rdoDWT)."','".$this->getCheckNullVal($txtMTCPDRate)."','".$this->getCheckNullVal($txtMLumpsum)."','".$this->getCheckNullVal($txtAddnlCRate)."','".$this->getCheckNullVal($txtCQMT)."','".$this->getCheckNullVal($selCType)."','".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."','".$this->getCheckNullVal($txtDFQMT)."', '".$this->getCheckNullValue($txtAddnlQMT)."', '".$this->getCheckNullValue($txtLDist)."','".$this->getCheckNullValue($txtBDist)."','".$this->getCheckNullValue($txtLDays)."','".$this->getCheckNullVal($txtBDays)."','".$this->getCheckNullVal($txtTSDays)."','".$this->getCheckNullVal($txtTtPIDays)."','".$this->getCheckNullVal($txtTtPWDays)."','".$this->getCheckNullVal($txtTDays)."','".$this->getCheckNullVal($txtTDist)."','".$this->getCheckNullVal($txtTFUMT)."', '".$this->getCheckNullVal($txtTDUMT)."','".$this->getCheckNullValue($txtFrAdjUsdGF)."','".$this->getCheckNullVal($txtFrAdjUsdDF)."','".$this->getCheckNullVal($txtFrAdjUsdAF)."','".$this->getCheckNullVal($txtFrAdjUsdTF)."','".$this->getCheckNullVal($txtFrAdjUsdGFMT)."','".$this->getCheckNullVal($txtFrAdjUsdDFMT)."','".$this->getCheckNullVal($txtFrAdjUsdAFMT)."','".$this->getCheckNullVal($txtFrAdjUsdTFMT)."',    '".$this->getCheckNullValue($txtFrAdjPerAC)."', '".$this->getCheckNullValue($txtFrAdjUsdAC)."', '".$this->getCheckNullValue($txtFrAdjUsdACMT)."','".$this->getCheckNullValue($txtFrAdjPerAgC)."','".$this->getCheckNullVal($txtFrAdjUsdAgC)."','".$this->getCheckNullVal($txtFrAdjUsdFP)."','".$this->getCheckNullVal($txtFGFFD)."','".$this->getCheckNullVal($txtFGFFDMT)."',  '".$this->getCheckNullVal($txtBrCommPercent)."','".$this->getCheckNullVal($txtBrComm)."','".$this->getCheckNullVal($txtTTLORCAmt)."', '".$this->getCheckNullVal($txtTTLORCCostMT)."','".$this->getCheckNullVal($txtRevenue)."',    '".$this->getCheckNullValue($txtTTLOwnersExpenses)."', '".$this->getCheckNullValue($txtTTLCharterersExpenses)."', '".$this->getCheckNullValue($txtVoyageEarnings)."','".$this->getCheckNullValue($txtDailyEarnings)."','".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."','".$this->getCheckNullVal($txtGTTLVoyageEarnings)."','".$this->getCheckNullVal($txtNettDailyEarnings)."','".$this->getCheckNullVal($txtNettDailyProfit)."',  '".$this->getCheckNullVal($txtPL)."', '".$this->getCheckNullVal($rdoQty)."', '".$selOpenPort."', '".$selZone."', '".$selBroker."', '".$selCOASpot."', '".$selCOA."', '".$txtNoLift."', '', '".$selOwner."', '".$txtDisponentOwner."', '".$txtFDate."', '".$txtTDate."', '".$txtETADate."', '".$txtCPDate."', '".$txtNotes."', '".$upload1."', '".$name1."', '".$txtCID."', '".$selShipper."', '".$txtTolerance."', '".$selMType."', '".$txtMCode."', '".$txtTermTolerance."', '".$selLPort."', '".$selDPort."', '".$txtLCSDate."', '".$txtLCFDate."','".$this->getCheckNullVal($txtHireargeAmt)."','".$this->getCheckNullVal($txtHireargePercent)."','".$this->getCheckNullVal($txtHireargePercentAmt)."', '".$this->getCheckNullVal($txtNettHireargeAmt)."', '".$rdoQtyType."', '".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', '".$this->getCheckNullVal($selCurrencyMarList)."', '".$this->getCheckNullVal($txtMarExchangeRate)."'   , '".$this->getCheckNullVal($txtTFUMTManual)."', '".$this->getCheckNullVal($txtTDUMTManual)."', '".$this->getCheckNullVal($txtTFOCOffHire)."', '".$this->getCheckNullVal($txtTDOCOffHire)."', '".$this->getCheckNullVal($sheet_no)."', '".$this->getCheckNullVal($comid)."', '".$selDTCVendor."', '".$update_status."', '".$txtFGFFVendor."', '".$this->getCheckNullVal($txtCVE)."', '".$this->getCheckNullVal($txtCVEAmt)."', '".$this->getCheckNullVal($selCVEVendor)."'    , '".$this->getCheckNullVal($txtBallastBonus)."', '".$this->getCheckNullVal($txtTotalBunkerCost)."', '".$this->getCheckNullVal($txtTotalPortCost)."' , '".$selBroVendor."', '".$selILOHCVendor."', '".$this->getCheckNullVal($txtHiddenHirage)."', '".$txtDistributedRemarks."', 1, '".$this->getCheckNullVal($txtAddnlCRatePer)."', '".$this->getCheckNullVal($rdoEstimateType)."', '".$this->getCheckNullVal($rdoQtyMar)."', '".$this->getCheckNullVal($txtBalticRate)."', '".$this->getCheckNullVal($txtAdnlPrenium)."', '".$this->getCheckNullVal($txtBaseRate)."', '".$this->getCheckNullVal($txtGasCQMT)."', '".$this->getCheckNullVal($txtGASLumpsum)."', '".$this->getCheckNullVal($selWSFPort)."', '".$this->getCheckNullVal($selWSTPort)."', '".$this->getCheckNullVal($txtFixedDiff)."', '".$this->getCheckNullVal($txtTankQuantity)."', '".$upload2."', '".$name2."', '".$this->getCheckNullVal($ChkLumpsum)."', '".$this->getCheckNullVal($txtLumpsum)."','".$this->getCheckNullVal($txtLumpsumQty)."', '".$selLumsumVendor."', '".$this->getCheckNullVal($txtBaseRateFloating)."', '".$this->getCheckNullVal($txtBaseRateFixed)."', '".$this->getCheckNullVal($txtBaseRateAverage)."', '".$this->getCheckNullVal($txtGFreightFloating)."', '".$this->getCheckNullVal($txtGFreightFixed)."', '".$this->getCheckNullVal($txtGFreightAverage)."', '".$this->getCheckNullVal($txtNFreightFloating)."', '".$this->getCheckNullVal($txtNFreightFixed)."', '".$this->getCheckNullVal($txtNFreightAverage)."', '".$this->getCheckNullVal($txtOExpensesFloating)."', '".$this->getCheckNullVal($txtOExpensesFixed)."', '".$this->getCheckNullVal($txtOExpensesAverage)."', '".$this->getCheckNullVal($txtVEarningFloating)."', '".$this->getCheckNullVal($txtVEarningFixed)."', '".$this->getCheckNullVal($txtVEarningAverage)."', '".$this->getCheckNullVal($txtDailyEarningFloating)."', '".$this->getCheckNullVal($txtDailyEarningFixed)."', '".$this->getCheckNullVal($txtDailyEarningAverage)."', '".$this->getCheckNullVal($txtTCEMonthFloating)."', '".$this->getCheckNullVal($txtTCEMonthFixed)."', '".$this->getCheckNullVal($txtTCEMonthAverage)."', '".$this->getCheckNullVal($txtOPExpensesFloating)."', '".$this->getCheckNullVal($txtOPExpensesFixed)."', '".$this->getCheckNullVal($txtOPExpensesAverage)."', '".$this->getCheckNullVal($txtNetDailyEarningFloating)."', '".$this->getCheckNullVal($txtNetDailyEarningFixed)."', '".$this->getCheckNullVal($txtNetDailyEarningAverage)."', '".$this->getCheckNullVal($txtNetDailyProfitFloating)."', '".$this->getCheckNullVal($txtNetDailyProfitFixed)."', '".$this->getCheckNullVal($txtNetDailyProfitAverage)."', '".$this->getCheckNullVal($selCargoPlanning)."', '".$this->getCheckNullVal($txtGrossBreakeven)."', '".$this->getCheckNullVal($txtBreakevenMT)."', '".$this->getCheckNullVal($rdoTankType)."', '".$txtTCNo."', '".$this->getCheckNullVal($txtGrossHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeCVE)."', '".$this->getCheckNullVal($txtHireargeCVEAMT)."', '".$this->getCheckNullVal($txtOffHireCVE)."', '".$this->getCheckNullVal($txtOffHireCVEAMT)."', '".$this->getCheckNullVal($txtLessOffHire)."', '".$this->getCheckNullVal($txtFinalHireargeAmt)."', '".$this->getCheckNullVal($txtHireargeBroPercent)."', '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', '".$this->getCheckNullVal($txtTotalVoyageDays)."', '".$txtTC_CPDate."', '".$this->getCheckNullValue($selPeriodContract)."', '".$this->getCheckNullValue($txtLessPerQty)."', '".$this->getCheckNullValue($txtBLCQMT)."', '".$txtTCDeliveryDate."', '".$txtTCReDeliveryDate."', '".$txtTCDelivery."', '".$txtTCReDelivery."',  '".$this->getCheckNullVal($txtPL)."', '".$txtTankerFreightRate."', '".$this->getCheckNullVal($txtTKSECAHrs)."', '".$this->getCheckNullVal($txtTKNONSECAHrs)."', '".$this->getCheckNullVal($txtInertSECAHrs)."', '".$this->getCheckNullVal($txtInertNONSECAHrs)."', '".$this->getCheckNullVal($txtGFSECAHrs)."', '".$this->getCheckNullVal($txtGFNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs)."', '".$this->getCheckNullVal($txtHeatSECAHrs1)."', '".$this->getCheckNullVal($txtHeatNONSECAHrs1)."')";
		mysql_query($sql) or die($sql);
		mysql_query("commit");
		
		$mysql = "select max(FCAID) as max from freight_cost_estimete_in_master";
		$myres  =  mysql_query($mysql,$connect);
		$myrows = mysql_fetch_assoc($myres);
		$maxid = $myrows['max'];
	}else{
	    $rows_fetch = mysql_fetch_assoc($res_fetch);
		$maxid = $rows_fetch['FCAID'];
		
		$del_query2 = "delete from  freight_cost_estimete_in_slave1 where FCAID='".$maxid."'";
		$del_query3 = "delete from  freight_cost_estimete_in_slave2 where FCAID='".$maxid."'";
		$del_query4 = "delete from  freight_cost_estimete_in_slave3 where FCAID='".$maxid."'";
		$del_query5 = "delete from  freight_cost_estimete_in_slave4 where FCAID='".$maxid."'";
		$del_query6 = "delete from  freight_cost_estimete_in_slave5 where FCAID='".$maxid."'";
		$del_query7 = "delete from  freight_cost_estimete_in_slave6 where FCAID='".$maxid."'";
		$del_query8 = "delete from  freight_cost_estimete_in_slave7 where FCAID='".$maxid."'";
		$del_query9 = "delete from  freight_cost_estimete_in_slave8 where FCAID='".$maxid."'";
		$del_query10 = "delete from  freight_cost_estimete_in_slave10 where FCAID='".$maxid."'";
		$del_query11 = "delete from  freight_cost_estimete_in_slave11 where FCAID='".$maxid."'";
		$del_query12 = "delete from  freight_cost_estimete_in_slave12 where FCAID='".$maxid."'";
		$del_query13 = "delete from  freight_cost_estimete_in_slave13 where FCAID='".$maxid."'";
		$del_query14 = "delete from  freight_cost_estimete_in_slave14 where FCAID='".$maxid."'";
		$del_query15 = "delete from  freight_cost_estimete_in_slave15 where FCAID='".$maxid."'";
		$del_query15 = "delete from  freight_cost_estimete_in_slave16 where FCAID='".$maxid."'";
		mysql_query($del_query2);
		mysql_query($del_query3);
		mysql_query($del_query4);
		mysql_query($del_query5);
		mysql_query($del_query6);
		mysql_query($del_query7);
		mysql_query($del_query8);
		mysql_query($del_query9);
		mysql_query($del_query10);
		mysql_query($del_query11);
		mysql_query($del_query12);
		mysql_query($del_query13);
		mysql_query($del_query14);
		mysql_query($del_query15);
		mysql_query($del_query16);
		mysql_query("commit");
		
	}
		
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{   
		    $randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql1 = "insert into freight_cost_estimete_in_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, PORT_COSTLP_VENDOR, DDCLP_COMM, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_VENDOR, DDCLP_NETCOST, DDCDP_COMM, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_VENDOR, DDCDP_NETCOST, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, PORT_COSTTP_VENDOR, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS, LP_OPA_VENDOR, DP_OPA_VENDOR, LP_CA_VENDOR, DP_CA_VENDOR) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."' ,'".$_REQUEST['selLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$_REQUEST['selDDCLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$_REQUEST['selDDCDPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['selDPVendor_'.$i]."', '".$_REQUEST['ChkShowDDCLP_'.$i]."', '".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$_REQUEST['selTPVendor_'.$i]."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."','".$_REQUEST['selLPOPAVendor_'.$i]."','".$_REQUEST['selDPOPAVendor_'.$i]."','".$_REQUEST['selLPCharterAgentVendor_'.$i]."','".$_REQUEST['selDPCharterAgentVendor_'.$i]."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_in_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_in_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_in_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_in_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtRateUSDmt_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] != "")
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_in_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."', 1, '".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtRateUSDmt2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] != "")
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_in_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtRateUSDmt3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] != "")
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_in_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, VENDORID, CARGOID, RANDOMID) values ('".$maxid."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$_REQUEST['selQtyVendor3_'.$i]."', '".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_in_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_in_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$maxid."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
		    $randomid = $_REQUEST['txtORCSlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtORCSlaveRandomID_'.$i]) || $_REQUEST['txtORCSlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql10 = "insert into freight_cost_estimete_in_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT, VENDORID, RANDOMID) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selORCVendor_'.$i])."', '".$randomid."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
		    $randomid = $_REQUEST['txtOISlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtOISlaveRandomID_'.$i]) || $_REQUEST['txtOISlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql120 = "insert into freight_cost_estimete_in_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT, VENDORID, RANDOMID) values ('".$maxid."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOtherIncVendor_'.$i])."', '".$randomid."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into freight_cost_estimete_in_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$maxid."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."', '".$_REQUEST['selBrCommVendor_'.$i]."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
		
		$txtTID = $_REQUEST['txtTID'];
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtDisponentOwner_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_in_slave5 (FCAID, DISPONENT_OWNER) values ('".$maxid."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$p_locationID = $_REQUEST['p_locationID'];
		for($i=1 ; $i<=$p_locationID ;$i++)
		{
			if($_REQUEST['txtFromLocation_'.$i] != "")
			{
				$sql2 = "insert into freight_cost_estimete_in_slave6 (FCAID, LOCATION_FROM, LOCATION_TO, PASSAGE_TYPE, SPEED_TYPE, DISTANCE) values ('".$maxid."', '".$_REQUEST['txtFromLocation_'.$i]."','".$_REQUEST['txtToLocation_'.$i]."','".$this->getCheckNullVal($_REQUEST['selPLocationType_'.$i])."','".$this->getCheckNullVal($_REQUEST['selSLocationSpeed_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtLocationDistance_'.$i])."')";
				mysql_query($sql2) or die($sql121);
				mysql_query("commit");
			}
		} 
		
		$txtQTYID = $_REQUEST['txtQTYID'];
		for($i=1 ; $i<=$txtQTYID ;$i++)
		{
			if($_REQUEST['selQtyVendorList_'.$i] != "")
			{
			    $randomid = $_REQUEST['txtQtySlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtQtySlaveRandomID_'.$i]) || $_REQUEST['txtQtySlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql2 = "insert into freight_cost_estimete_in_slave7 (FCAID, QTY_VENDORID, AGREED_GROSS_FREIGHT, QUANTITY, GROSS_FREIGHT, BROKERAGE, NET_BROKERAGE, NET_FREIGHT, NET_FREIGHT_PERMT, CURRENCYID, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, CARGO, RANDOMID) values ('".$maxid."','".$_REQUEST['selQtyVendorList_'.$i]."','".$_REQUEST['txtQtyAggriedFreight_'.$i]."','".$_REQUEST['txtFreightQty_'.$i]."','".$_REQUEST['txtQtyFreight_'.$i]."','".$_REQUEST['txtQtyBrokeragePer_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtQtyBrokerageAmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreightMT1_'.$i])."','".$this->getCheckNullVal($_REQUEST['selCurrencyDisList_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyLocalAggriedFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDisExchangeRate_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selQtyCargo_'.$i])."', '".$randomid."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		} 
		
		
		$txtNoOfInvoice = $_REQUEST['txtNoOfInvoice'];
		for($i=1;$i<=$txtNoOfInvoice;$i++)
		{
			if($_REQUEST['txtInvoiceID_'.$i]!='')
			{
				$sql11 = "insert into freight_cost_estimete_in_slave11 (INVOICEID, FCAID) values ('".addslashes(trim($_REQUEST['txtInvoiceID_'.$i]))."', '".$maxid."' )";
				mysql_query($sql11) or die($sql11);
				mysql_query("commit");
			}
		}
		
		$txtTankID = $_REQUEST['txtTankID'];
		for($i=1 ; $i<=$txtTankID ;$i++)
		{
			if($_REQUEST['txtFreightSpecs_'.$i] != "")
			{
				$sql12 = "insert into freight_cost_estimete_in_slave12 (FCAID, FREIGHT_SPECS, CUSTOMER, MIN_CARGO_QTY, OVE_CARGO_QTY, MIN_FLAT_RATE, OVE_FLAT_RATE, MIN_WS, OVE_WS, MIN_DIS_LEG, OVE_DIS_LEG, MIN_DISTANCE, OVE_DISTANCE, MIN_AMOUNT, OVE_AMOUNT, TOTAL_QTY, TOTAL_AMOUNT) values ('".$maxid."', '".$_REQUEST['txtFreightSpecs_'.$i]."', '".$_REQUEST['selTankVendor_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtMinCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtOveCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinDisLeg_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveDisLeg_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinTotalDis_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveTotalDis_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinAmount_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtTotalTankQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTotalTankAmount_'.$i])."')";
				mysql_query($sql12) or die($sql12);
				mysql_query("commit");
			}
		} 
		
		$txtHIREID = $_REQUEST['txtHIREID'];
		for($i=1 ; $i<=$txtHIREID ;$i++)
		{
			if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
			{
				if($_REQUEST['txtHireFrom_'.$i]!="")
				{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
				else{$txtHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtHireTo_'.$i]!="")
				{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
				else{$txtHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCHireRandom_'.$i]) || $_REQUEST['txtTCHireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCHireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_in_slave17 (FCAID, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE, HIRE_AMT, RANDOMID) values ('".$maxid."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireAmt_'.$i])."', '".$this->getCheckNullValue($randomid4)."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_in_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$maxid."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_in_slave14 where FCAID='".$maxid."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_in_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$maxid."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_in_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_in_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg; 
}


function updateTCICostSheetDetails_in()
{

	// echo $_REQUEST['id'];

	// die();
	$connect = $this->funConnect();
	$selFType	 			= $_REQUEST['selFType'];
	$selVName 		    	= addslashes(trim($_REQUEST['selVName']));
	$txtVType	 			= addslashes(trim($_REQUEST['txtVType']));
	$txtFlag	 			= addslashes(trim($_REQUEST['txtFlag']));
	$txtDate	 			= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	$txtVNo  	 			= addslashes(trim($_REQUEST['txtVNo']));
	$txtENo 	 			= addslashes(trim($_REQUEST['txtENo']));
	$rdoDWT 	 			= addslashes(trim($_REQUEST['rdoDWT']));
	$txtDWTS	 			= addslashes(trim($_REQUEST['txtDWTS']));
	$txtDWTT           	 	= addslashes(trim($_REQUEST['txtDWTT']));
	$rdoCap 	 			= addslashes(trim($_REQUEST['rdoCap']));
	$txtGCap    			= addslashes(trim($_REQUEST['txtGCap']));
	$txtBCap    			= addslashes(trim($_REQUEST['txtBCap']));
	$txtSF      			= addslashes(trim($_REQUEST['txtSF']));
	$txtLoadable 			= addslashes(trim($_REQUEST['txtLoadable']));
	$txtGNRT	 			= addslashes(trim($_REQUEST['txtGNRT']));
	$txtLOA     			= addslashes(trim($_REQUEST['txtLOA']));
	$txtGear	 			= addslashes(trim($_REQUEST['txtGear']));
	$txtBuiltYear 			= addslashes(trim($_REQUEST['txtBuiltYear']));
	$txtBeam    			= addslashes(trim($_REQUEST['txtBeam']));
	$txtTPC 				= addslashes(trim($_REQUEST['txtTPC']));
	$txtBFullSpeed			= addslashes(trim($_REQUEST['txtBFullSpeed']));
	$txtBEcoSpeed1	    	= addslashes(trim($_REQUEST['txtBEcoSpeed1']));
	$txtBEcoSpeed2			= addslashes(trim($_REQUEST['txtBEcoSpeed2']));
	$txtLFullSpeed	    	= addslashes(trim($_REQUEST['txtLFullSpeed']));
	$txtLEcoSpeed1			= addslashes(trim($_REQUEST['txtLEcoSpeed1']));
	$txtLEcoSpeed2	    	= addslashes(trim($_REQUEST['txtLEcoSpeed2']));
	$txtBFOFullSpeed		= addslashes(trim($_REQUEST['txtBFOFullSpeed']));
	$txtBFOEcoSpeed1   	 	= addslashes(trim($_REQUEST['txtBFOEcoSpeed1']));
	$txtBFOEcoSpeed2		= addslashes(trim($_REQUEST['txtBFOEcoSpeed2']));
	$txtLFOFullSpeed    	= addslashes(trim($_REQUEST['txtLFOFullSpeed']));
	$txtLFOEcoSpeed1    	= addslashes(trim($_REQUEST['txtLFOEcoSpeed1']));
	$txtLFOEcoSpeed2		= addslashes(trim($_REQUEST['txtLFOEcoSpeed2']));
	$txtPIFOFullSpeed   	= addslashes(trim($_REQUEST['txtPIFOFullSpeed']));
	$txtPWFOFullSpeed		= addslashes(trim($_REQUEST['txtPWFOFullSpeed']));
	$txtBDOFullSpeed    	= addslashes(trim($_REQUEST['txtBDOFullSpeed']));
	$txtBDOEcoSpeed1		= addslashes(trim($_REQUEST['txtBDOEcoSpeed1']));
	$txtBDOEcoSpeed2		= addslashes(trim($_REQUEST['txtBDOEcoSpeed2']));
	$txtLDOFullSpeed   	    = addslashes(trim($_REQUEST['txtLDOFullSpeed']));
	$txtLDOEcoSpeed1		= addslashes(trim($_REQUEST['txtLDOEcoSpeed1']));
	$txtLDOEcoSpeed2    	= addslashes(trim($_REQUEST['txtLDOEcoSpeed2']));
	$txtPIDOFullSpeed  	 	= addslashes(trim($_REQUEST['txtPIDOFullSpeed']));
	$txtPWDOFullSpeed		= addslashes(trim($_REQUEST['txtPWDOFullSpeed']));
	
	$rdoQty             	= addslashes(trim($_REQUEST['rdoQty']));
	$rdoMMarket        		 = addslashes(trim($_REQUEST['rdoMMarket']));
	$txtMTCPDRate	   		 = addslashes(trim($_REQUEST['txtMTCPDRate']));
	$txtAddnlCRate	    	= addslashes(trim($_REQUEST['txtAddnlCRate']));
	$txtAddnlQMT            = addslashes(trim($_REQUEST['txtAddnlQMT']));
	$txtCQMT 		    	= addslashes(trim($_REQUEST['txtCQMT']));
	$selCType 		    	= addslashes(trim($_REQUEST['selCType']));
	$txtMLumpsum	        = addslashes(trim($_REQUEST['txtMLumpsum']));
	
	$selCName           	= addslashes(trim($_REQUEST['selCName']));
	$rdoQty	            	= addslashes(trim($_REQUEST['rdoQty']));
	$txtAQMT	        	= addslashes(trim($_REQUEST['txtAQMT']));
	$txtDFQMT 		    	= addslashes(trim($_REQUEST['txtDFQMT']));
	$selCType 		    	= addslashes(trim($_REQUEST['selCType']));
	
	$txtLDist           	= addslashes(trim($_REQUEST['txtLDist']));
	$txtBDist	        	= addslashes(trim($_REQUEST['txtBDist']));
	$txtTDist	        	= addslashes(trim($_REQUEST['txtTDist']));
	$txtLDays 		    	= addslashes(trim($_REQUEST['txtLDays']));
	$txtBDays 		    	= addslashes(trim($_REQUEST['txtBDays']));
	$txtTSDays          	= addslashes(trim($_REQUEST['txtTSDays']));
	$txtTtPIDays	    	= addslashes(trim($_REQUEST['txtTtPIDays']));
	$txtTtPWDays	    	= addslashes(trim($_REQUEST['txtTtPWDays']));
	$txtTDays 		    	= addslashes(trim($_REQUEST['txtTDays']));
	$txtTFUMT 		    	= addslashes(trim($_REQUEST['txtTFUMT']));
	$txtTDUMT           	= addslashes(trim($_REQUEST['txtTDUMT']));
	$txtFrAdjUsdGF	    	= addslashes(trim($_REQUEST['txtFrAdjUsdGF']));
	$txtFrAdjUsdGFMT		= addslashes(trim($_REQUEST['txtFrAdjUsdGFMT']));
	$txtFrAdjUsdDF 			= addslashes(trim($_REQUEST['txtFrAdjUsdDF']));
	$txtFrAdjUsdDFMT    	= addslashes(trim($_REQUEST['txtFrAdjUsdDFMT']));
	$txtFrAdjUsdAF      	= addslashes(trim($_REQUEST['txtFrAdjUsdAF']));
	$txtFrAdjUsdAFMT		= addslashes(trim($_REQUEST['txtFrAdjUsdAFMT']));
	$txtFrAdjUsdTF	    	= addslashes(trim($_REQUEST['txtFrAdjUsdTF']));
	$txtFrAdjUsdTFMT    	= addslashes(trim($_REQUEST['txtFrAdjUsdTFMT']));
	$txtFrAdjPerAC 			= addslashes(trim($_REQUEST['txtFrAdjPerAC']));
	$txtFrAdjUsdAC      	= addslashes(trim($_REQUEST['txtFrAdjUsdAC']));
	$txtFrAdjUsdACMT		= addslashes(trim($_REQUEST['txtFrAdjUsdACMT']));
	$txtFrAdjPerAgC	    	= addslashes(trim($_REQUEST['txtFrAdjPerAgC']));
	$txtFrAdjUsdAgC     	= addslashes(trim($_REQUEST['txtFrAdjUsdAgC']));
	$txtFrAdjUsdFP 			= addslashes(trim($_REQUEST['txtFrAdjUsdFP']));
	
	
	$txtFGFFD           	= addslashes(trim($_REQUEST['txtFGFFD']));
	$txtFGFFDMT         	= addslashes(trim($_REQUEST['txtFGFFDMT']));
	$txtBunkerRec	    	= addslashes(trim($_REQUEST['txtBunkerRec']));
	$txtBHID1	        	= addslashes(trim($_REQUEST['txtBHID1']));
	$txtBunkerCost_MDO_DMB  = addslashes(trim($_REQUEST['txtBunkerCost_MDO_DMB']));
	$txtBRokageCount		= addslashes(trim($_REQUEST['txtBRokageCount']));
	$txtBrCommPercent   	= addslashes(trim($_REQUEST['txtBrCommPercent']));
	$txtBrComm	        	= addslashes(trim($_REQUEST['txtBrComm']));
	$txtORC_id	        	= addslashes(trim($_REQUEST['txtORC_id']));
	$txtTTLORCAmt       	= addslashes(trim($_REQUEST['txtTotalOperationalCost']));
	$txtTTLORCCostMT    	= addslashes(trim($_REQUEST['txtTTLORCCostMT']));
	
	
	$txtCC_id	                       = addslashes(trim($_REQUEST['txtCC_id']));
	$txtAOMC_id                        = addslashes(trim($_REQUEST['txtAOMC_id']));
	$txtRevenue	                       = addslashes(trim($_REQUEST['txtRevenue']));
	$txtTTLOwnersExpenses              = addslashes(trim($_REQUEST['txtTTLOwnersExpenses']));
	$txtTTLCharterersExpenses          = addslashes(trim($_REQUEST['txtTTLCharterersExpenses']));
	$txtVoyageEarnings                 = addslashes(trim($_REQUEST['txtVoyageEarnings']));
	
	$txtDailyEarnings	               = addslashes(trim($_REQUEST['txtDailyEarnings']));
	$txtDailyVesselOperatingExpenses   = addslashes(trim($_REQUEST['txtDailyVesselOperatingExpenses']));
	$txtHireargeAmt                    = addslashes(trim($_REQUEST['txtHireargeAmt']));
	$txtHireargePercent                = addslashes(trim($_REQUEST['txtHireargePercent']));
	$txtHireargePercentAmt             = addslashes(trim($_REQUEST['txtHireargePercentAmt']));
	$txtGTTLVoyageEarnings	           = addslashes(trim($_REQUEST['txtGTTLVoyageEarnings']));
	$txtNettHireargeAmt                = addslashes(trim($_REQUEST['txtNettHireargeAmt']));
	$txtNettDailyEarnings              = addslashes(trim($_REQUEST['txtNettDailyEarnings']));
	$txtNettDailyProfit                = addslashes(trim($_REQUEST['txtNettDailyProfit']));
	$txtPL                             = addslashes(trim($_REQUEST['txtPL']));
	$vesselrec                         = addslashes(trim($_REQUEST['vesselrec']));
	
	
	$selOpenPort 	 		= addslashes(trim($_REQUEST['selOpenPort']));
	$selZone	 			= addslashes(trim($_REQUEST['selZone']));
	$selBroker         	 	= addslashes(trim($_REQUEST['selBroker']));
	$selCOASpot 	 		= addslashes(trim($_REQUEST['selCOASpot']));
	$selCOA     	 		= addslashes(trim($_REQUEST['selCOA']));
	$txtNoLift    			= addslashes(trim($_REQUEST['txtNoLift']));
	$selOwner 		    	= addslashes(trim($_REQUEST['selOwner']));
	$txtDisponentOwner		= addslashes(trim($_REQUEST['txtDisponentOwner']));
	if($_REQUEST['txtFDate']!="")
	{
	$txtFDate     			= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	}


	else{$txtFDate     		= "1970-01-01";}
	if($_REQUEST['txtTDate']!="")
	{	
	$txtTDate     			= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	}
	else{$txtTDate     		= "1970-01-01";}
	if($_REQUEST['txtETADate']!="")
	{
	$txtETADate     		= date("Y-m-d",strtotime($_REQUEST['txtETADate']));
	}
	else{$txtETADate     		= "1970-01-01";}
	if($_REQUEST['txtCPDate']!="")
	{
	$txtCPDate     			= date("Y-m-d",strtotime($_REQUEST['txtCPDate']));
	}
	else{$txtCPDate     		= "1970-01-01";}
	$txtNotes     			= addslashes(trim($_REQUEST['txtNotes']));
	
	$txtCID 	 			= addslashes(trim($_REQUEST['txtCID']));
	$selShipper	 			= addslashes(trim($_REQUEST['selShipper']));
	$txtTolerance       	= addslashes(trim($_REQUEST['txtTolerance']));
	$selMType 	 			= implode(',',$_REQUEST['selMType']);
	$txtMCode    			= addslashes(trim($_REQUEST['txtMCode']));
	$txtTermTolerance		= addslashes(trim($_REQUEST['txtTermTolerance']));
	$selLPort      			= addslashes(trim($_REQUEST['selLPort']));
	$selDPort 		    	= addslashes(trim($_REQUEST['selDPort']));
	
	$rdoQtyType 		       = addslashes(trim($_REQUEST['rdoQtyType']));
	$txtMarLocalAggriedFreight = addslashes(trim($_REQUEST['txtMarLocalAggriedFreight']));
	$selCurrencyMarList 	   = addslashes(trim($_REQUEST['selCurrencyMarList']));
	$txtMarExchangeRate 	   = addslashes(trim($_REQUEST['txtMarExchangeRate']));
	
	$txtTFUMTManual 		   = addslashes(trim($_REQUEST['txtTFUMTManual']));
	$txtTDUMTManual            = addslashes(trim($_REQUEST['txtTDUMTManual']));
	$txtTFOCOffHire		 	   = addslashes(trim($_REQUEST['txtTFOCOffHire']));
	$txtTDOCOffHire     	   = addslashes(trim($_REQUEST['txtTDOCOffHire']));
	$selDTCVendor       	   = addslashes(trim($_REQUEST['selDTCVendor']));
	$txtFGFFVendor       	   = addslashes(trim($_REQUEST['txtFGFFVendor']));
	
	$txtCVE           	   = addslashes(trim($_REQUEST['txtCVE']));
	$txtCVEAmt       	   = addslashes(trim($_REQUEST['txtCVEAmt']));
	$selCVEVendor          = addslashes(trim($_REQUEST['selCVEVendor']));
	
	$txtBallastBonus	= addslashes(trim($_REQUEST['txtBallastBonus']));
	$txtTotalBunkerCost	= addslashes(trim($_REQUEST['txtTotalBunkerCost']));
	$txtTotalPortCost   = addslashes(trim($_REQUEST['txtTotalPortCost']));
	$selBroVendor       = addslashes(trim($_REQUEST['selBroVendor']));
	$selILOHCVendor     = addslashes(trim($_REQUEST['selILOHCVendor']));
	$txtDistributedRemarks     = addslashes(trim($_REQUEST['txtDistributedRemarks'])); 
	
	if(isset($_REQUEST['txtHiddenHirage']))
	{
	   $txtHiddenHirage     		= $_REQUEST['txtHiddenHirage'];
	}
	else{$txtHiddenHirage     		= $_REQUEST['txtHireargeAmt'];}
	
	
	if($_REQUEST['txtLCSDate']!="")
	{
	$txtLCSDate   			= date("Y-m-d",strtotime($_REQUEST['txtLCSDate']));
	}
	else{$txtLCSDate     		= "1970-01-01";}
	if($_REQUEST['txtLCFDate']!="")
	{
	$txtLCFDate     		= date("Y-m-d",strtotime($_REQUEST['txtLCFDate']));
	}
	else{$txtLCFDate     		= "1970-01-01";}
	
	
	$txtCRMFILE1							= addslashes(trim($_REQUEST['txtCRMFILE']));
	$txtCRMNAME1							= addslashes(trim($_REQUEST['txtCRMNAME']));
	
	$upload = $this->getUpload($_FILES['attach_file']);
	$name = $this->getUploadName($_FILES['attach_file']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE1 != '' && $upload != ''){ $upload1 = $txtCRMFILE1.','.$upload;}
	else if($txtCRMFILE1 == '' && $upload != ''){ $upload1 = $upload;}
	else if($txtCRMFILE1 != '' && $upload == ''){ $upload1 = $txtCRMFILE1;}
	
	if($txtCRMNAME1 != '' && $name != ''){ $name1 = $txtCRMNAME1.','.$name;}
	else if($txtCRMNAME1 == '' && $name != ''){ $name1 = $name;}
	else if($txtCRMNAME1 != '' && $name == ''){ $name1 = $txtCRMNAME1;}
	
	$txtCRMFILE2							= addslashes(trim($_REQUEST['txtCRMFILE1']));
	$txtCRMNAME2							= addslashes(trim($_REQUEST['txtCRMNAME1']));
	
	$upload = $this->getUpload($_FILES['attach_file1']);
	$name = $this->getUploadName($_FILES['attach_file1']);
	
	$upload = implode(',',$upload);
	$name = implode(',',$name);
	
	if($txtCRMFILE2 != '' && $upload != ''){ $upload2 = $txtCRMFILE2.','.$upload;}
	else if($txtCRMFILE2 == '' && $upload != ''){ $upload2 = $upload;}
	else if($txtCRMFILE2 != '' && $upload == ''){ $upload2 = $txtCRMFILE2;}
	
	if($txtCRMNAME2 != '' && $name != ''){ $name2 = $txtCRMNAME2.','.$name;}
	else if($txtCRMNAME2 == '' && $name != ''){ $name2 = $name;}
	else if($txtCRMNAME2 != '' && $name == ''){ $name2 = $txtCRMNAME2;}
	
	$rdoEstimateType      	= $_SESSION['selBType'];
	$rdoQtyMar 		        = addslashes(trim($_REQUEST['rdoQtyMar']));
	$txtBalticRate      	= addslashes(trim($_REQUEST['txtBalticRate']));
	$txtAdnlPrenium 	    = addslashes(trim($_REQUEST['txtAdnlPrenium']));
	$txtBaseRate      		= addslashes(trim($_REQUEST['txtBaseRate']));
	$txtGASLumpsum 		    = addslashes(trim($_REQUEST['txtGASLumpsum']));
	$txtGasCQMT      		= addslashes(trim($_REQUEST['txtGasCQMT']));
	$txtTankQuantity 	    = addslashes(trim($_REQUEST['txtTankQuantity']));
	$selWSFPort 		    = addslashes(trim($_REQUEST['selWSFPort']));
	$selWSTPort      		= addslashes(trim($_REQUEST['selWSTPort']));
	$txtFixedDiff 	        = addslashes(trim($_REQUEST['txtFixedDiff']));
	$ChkLumpsum 	        = addslashes(trim($_REQUEST['ChkLumpsum']));
	$txtLumpsum 	        = addslashes(trim($_REQUEST['txtLumpsum']));
	$txtLumpsumQty          = addslashes(trim($_REQUEST['txtLumpsumQty']));
    $selLumsumVendor        = addslashes(trim($_REQUEST['selLumsumVendor']));
	
	
	$txtBaseRateFloating    = addslashes(trim($_REQUEST['txtBaseRateFloating']));
	$txtBaseRateFixed       = addslashes(trim($_REQUEST['txtBaseRateFixed']));
	$txtBaseRateAverage     = addslashes(trim($_REQUEST['txtBaseRateAverage']));
	
	$txtGFreightFloating    = addslashes(trim($_REQUEST['txtGFreightFloating']));
	$txtGFreightFixed       = addslashes(trim($_REQUEST['txtGFreightFixed']));
	$txtGFreightAverage     = addslashes(trim($_REQUEST['txtGFreightAverage']));
	
	$txtNFreightFloating    = addslashes(trim($_REQUEST['txtNFreightFloating']));
	$txtNFreightFixed       = addslashes(trim($_REQUEST['txtNFreightFixed']));
	$txtNFreightAverage     = addslashes(trim($_REQUEST['txtNFreightAverage']));
	
	$txtOExpensesFloating   = addslashes(trim($_REQUEST['txtOExpensesFloating']));
	$txtOExpensesFixed      = addslashes(trim($_REQUEST['txtOExpensesFixed']));
	$txtOExpensesAverage    = addslashes(trim($_REQUEST['txtOExpensesAverage']));
	
	$txtVEarningFloating    = addslashes(trim($_REQUEST['txtVEarningFloating']));
	$txtVEarningFixed       = addslashes(trim($_REQUEST['txtVEarningFixed']));
	$txtVEarningAverage     = addslashes(trim($_REQUEST['txtVEarningAverage']));
	
	$txtDailyEarningFloating= addslashes(trim($_REQUEST['txtDailyEarningFloating']));
	$txtDailyEarningFixed   = addslashes(trim($_REQUEST['txtDailyEarningFixed']));
	$txtDailyEarningAverage = addslashes(trim($_REQUEST['txtDailyEarningAverage']));
	
	$txtTCEMonthFloating    = addslashes(trim($_REQUEST['txtTCEMonthFloating']));
	$txtTCEMonthFixed       = addslashes(trim($_REQUEST['txtTCEMonthFixed']));
	$txtTCEMonthAverage     = addslashes(trim($_REQUEST['txtTCEMonthAverage']));
	
	$txtOPExpensesFloating  = addslashes(trim($_REQUEST['txtOPExpensesFloating']));
	$txtOPExpensesFixed     = addslashes(trim($_REQUEST['txtOPExpensesFixed']));
	$txtOPExpensesAverage   = addslashes(trim($_REQUEST['txtOPExpensesAverage']));
	
	$txtNetDailyEarningFloating= addslashes(trim($_REQUEST['txtNetDailyEarningFloating']));
	$txtNetDailyEarningFixed= addslashes(trim($_REQUEST['txtNetDailyEarningFixed']));
	$txtNetDailyEarningAverage= addslashes(trim($_REQUEST['txtNetDailyEarningAverage']));
	
	$txtNetDailyProfitFloating= addslashes(trim($_REQUEST['txtNetDailyProfitFloating']));
	$txtNetDailyProfitFixed = addslashes(trim($_REQUEST['txtNetDailyProfitFixed']));
	$txtNetDailyProfitAverage= addslashes(trim($_REQUEST['txtNetDailyProfitAverage']));
	$selCargoPlanning       = $_REQUEST['selCargoPlanning'];
	
	$txtSDWTMT 	 	    = addslashes(trim($_REQUEST['txtSDWTMT']));
	$txtSDWTLT	 		= addslashes(trim($_REQUEST['txtSDWTLT']));
	$txtSDraftM         = addslashes(trim($_REQUEST['txtSDraftM']));
	$txtSDraftFT 	 	= addslashes(trim($_REQUEST['txtSDraftFT']));
	$txtTPIMT     	 	= addslashes(trim($_REQUEST['txtTPIMT']));
	$txtTPILT    		= addslashes(trim($_REQUEST['txtTPILT']));
	$txtTPCMT    		= addslashes(trim($_REQUEST['txtTPCMT']));
	$txtTPCLT           = addslashes(trim($_REQUEST['txtTPCLT']));
	$txtConstantsMT     = addslashes(trim($_REQUEST['txtConstantsMT']));
	$txtConstantsLT  	= addslashes(trim($_REQUEST['txtConstantsLT']));
	$txtGrainCapCBM 	= addslashes(trim($_REQUEST['txtGrainCapCBM']));
	$txtGrainCapCFT		= addslashes(trim($_REQUEST['txtGrainCapCFT']));
	$txtAllawedDraftM   = addslashes(trim($_REQUEST['txtAllawedDraftM']));
	$txtBunkerRobMT	 	= addslashes(trim($_REQUEST['txtBunkerRobMT']));
	$txtCargoIntakeMT 	= addslashes(trim($_REQUEST['txtCargoIntakeMT']));
	$txtSFCBM_MT    	= addslashes(trim($_REQUEST['txtSFCBM_MT']));
	$txtSFCBFT_MT  		= addslashes(trim($_REQUEST['txtSFCBFT_MT']));
	$txtCargoLoadableMT = addslashes(trim($_REQUEST['txtCargoLoadableMT']));
	
	$txtGrossBreakeven  = addslashes(trim($_REQUEST['txtGrossBreakeven']));
	$txtBreakevenMT     = addslashes(trim($_REQUEST['txtBreakevenMT']));
	$txtTCNo            = addslashes(trim($_REQUEST['txtTCNo']));
	$rdoTankType        = addslashes(trim($_REQUEST['rdoTankType']));
	
	$txtGrossHireargeAmt     = addslashes(trim($_REQUEST['txtGrossHireargeAmt']));
	$txtHireargeCVE          = addslashes(trim($_REQUEST['txtHireargeCVE']));
	$txtHireargeCVEAMT       = addslashes(trim($_REQUEST['txtHireargeCVEAMT']));
	$txtOffHireCVE           = addslashes(trim($_REQUEST['txtOffHireCVE']));
	$txtOffHireCVEAMT        = addslashes(trim($_REQUEST['txtOffHireCVEAMT']));
	$txtLessOffHire          = addslashes(trim($_REQUEST['txtLessOffHire']));
	$txtFinalHireargeAmt     = addslashes(trim($_REQUEST['txtFinalHireargeAmt']));
	$txtHireargeBroPercent    = addslashes(trim($_REQUEST['txtHireargeBroPercent']));
	$txtHireargeBroPercentAmt = addslashes(trim($_REQUEST['txtHireargeBroPercentAmt']));
	$txtTotalVoyageDays = addslashes(trim($_REQUEST['txtTotalVoyageDays']));
	$selPeriodContract = addslashes(trim($_REQUEST['selPeriodContract']));
	$txtBLCQMT              = addslashes(trim($_REQUEST['txtBLCQMT']));
    $txtLessPerQty          = addslashes(trim($_REQUEST['txtLessPerQty']));
	$chartering_pic =addslashes(trim($_REQUEST['chartering_pic']));
	
	if($_REQUEST['txtTC_CPDate']!="")
	{
	$txtTC_CPDate     	= date("Y-m-d",strtotime($_REQUEST['txtTC_CPDate']));
	}
	else{$txtTC_CPDate     		= "1970-01-01";}
	
	if($_REQUEST['txtTCDeliveryDate']!="")
	{$txtTCDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCDeliveryDate']));}
	else{$txtTCDeliveryDate  		= "1970-01-01 08:00:00";}
	
	if($_REQUEST['txtTCReDeliveryDate']!="")
	{$txtTCReDeliveryDate     		= date("Y-m-d H:i",strtotime($_REQUEST['txtTCReDeliveryDate']));}
	else{$txtTCReDeliveryDate  		= "1970-01-01 08:00:00";}
	
	$txtTCDelivery = addslashes(trim($_REQUEST['txtTCDelivery']));
	$txtTCReDelivery = addslashes(trim($_REQUEST['txtTCReDelivery']));
	$txtTankerFreightRate = addslashes(trim($_REQUEST['txtTankerFreightRate']));
	
	$txtTKSECAHrs            = addslashes(trim($_REQUEST['txtTKSECAHrs']));
	$txtTKNONSECAHrs         = addslashes(trim($_REQUEST['txtTKNONSECAHrs']));
	$txtInertSECAHrs         = addslashes(trim($_REQUEST['txtInertSECAHrs']));
	$txtInertNONSECAHrs      = addslashes(trim($_REQUEST['txtInertNONSECAHrs']));
	$txtGFSECAHrs            = addslashes(trim($_REQUEST['txtGFSECAHrs']));
	$txtGFNONSECAHrs         = addslashes(trim($_REQUEST['txtGFNONSECAHrs']));
	$txtHeatSECAHrs          = addslashes(trim($_REQUEST['txtHeatSECAHrs']));
	$txtHeatNONSECAHrs       = addslashes(trim($_REQUEST['txtHeatNONSECAHrs']));
	$txtHeatSECAHrs1         = addslashes(trim($_REQUEST['txtHeatSECAHrs1']));
	$txtHeatNONSECAHrs1      = addslashes(trim($_REQUEST['txtHeatNONSECAHrs1']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sheet_no    = $_REQUEST['cost_sheet_id'];
	$comid       = $_REQUEST['id'];
	$update_status = addslashes(trim($_REQUEST['update_status']));
	
	$actualpl = $this->getCheckNullVal($txtPL);
	$sql_in = "select * from freight_cost_estimete_in_master where VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."' and VOYAGE_NO='".$txtVNo."'";
    $res_in = mysql_query($sql_in);
	$rows_in = mysql_fetch_assoc($res_in);
	$id = $rows_in['FCAID'];

	

	$sql = "update freight_cost_estimete_in_master set FIXTURETYPEID='".$this->getCheckNullValue($selFType)."', TRANS_DATE='".$txtDate."', MODULEID='".$this->getCheckNullValue($_SESSION['moduleid'])."', MCOMPANYID='".$this->getCheckNullValue($_SESSION['company'])."', ADDED_BY='".$_SESSION['uid']."', VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."', VESSEL_TYPE='".$txtVType."', FLAG='".$txtFlag."', VOYAGE_NO='".$txtVNo."', VOYAGE_NAME='".$txtENo."', COMID='".$comid."', DWT_SUMMER='".$this->getCheckNullValue($txtDWTS)."', DWT_TOPICAL='".$this->getCheckNullValue($txtDWTT)."', RDO_CAP='".$this->getCheckNullValue($rdoCap)."', GRAIN_CAP='".$this->getCheckNullValue($txtGCap)."', BALE_CAP='".$this->getCheckNullValue($txtBCap)."', SF='".$this->getCheckNullValue($txtSF)."', LODABLE='".$this->getCheckNullValue($txtLoadable)."', GNRT='".$this->getCheckNullValue($txtGNRT)."', LOA='".$this->getCheckNullValue($txtLOA)."', GEAR='".$txtGear."', BUILD_YEAR='".$txtBuiltYear."', BEAM='".$this->getCheckNullValue($txtBeam)."', TPC='".$this->getCheckNullValue($txtTPC)."', BFULLSPEED='".$this->getCheckNullValue($txtBFullSpeed)."', BECOSPEED1='".$this->getCheckNullValue($txtBEcoSpeed1)."', BECOSPEED2='".$this->getCheckNullValue($txtBEcoSpeed2)."', LFULLSPEED='".$this->getCheckNullValue($txtLFullSpeed)."', LECOSPEED1='".$this->getCheckNullValue($txtLEcoSpeed1)."', LECOSPEED2='".$this->getCheckNullVal($txtLEcoSpeed2)."', BFOFULLSPEED='".$this->getCheckNullVal($txtBFOFullSpeed)."', BFOECOSPEED1='".$this->getCheckNullVal($txtBFOEcoSpeed1)."', BFOECOSPEED2='".$this->getCheckNullVal($txtBFOEcoSpeed2)."', LFOFULLSPEED='".$this->getCheckNullVal($txtLFOFullSpeed)."', LFOECOSPEED1='".$this->getCheckNullVal($txtLFOEcoSpeed1)."', LFOECOSPEED2='".$this->getCheckNullVal($txtLFOEcoSpeed2)."', PIFOFULLSPEED='".$this->getCheckNullValue($txtPIFOFullSpeed)."', PWFOFULLSPEED='".$this->getCheckNullValue($txtPWFOFullSpeed)."', BDOFULLSPEED='".$this->getCheckNullValue($txtBDOFullSpeed)."', BDOECOSPEED1='".$this->getCheckNullValue($txtBDOEcoSpeed1)."', BDOECOSPEED2='".$this->getCheckNullVal($txtBDOEcoSpeed2)."', LDOFULLSPEED='".$this->getCheckNullVal($txtLDOFullSpeed)."', LDOECOSPEED1='".$this->getCheckNullVal($txtLDOEcoSpeed1)."', LDOECOSPEED2='".$this->getCheckNullVal($txtLDOEcoSpeed2)."', PIDOFULLSPEED='".$this->getCheckNullVal($txtPIDOFullSpeed)."', PWDOFULLSPEED='".$this->getCheckNullVal($txtPWDOFullSpeed)."', RDO_MARKER='".$this->getCheckNullVal($rdoMMarket)."', RDO_DWT='".$this->getCheckNullValue($rdoDWT)."', FREIGHT_GROSS='".$this->getCheckNullVal($txtMTCPDRate)."', LUMSUM='".$this->getCheckNullVal($txtMLumpsum)."', CARGO_RATE='".$this->getCheckNullVal($txtAddnlCRate)."', QUANTITY='".$this->getCheckNullVal($txtCQMT)."', CARGO_TYPE='".$this->getCheckNullVal($selCType)."', CARGO_ID='".$this->getCheckNullVal(implode(',',$_REQUEST['selCName']))."', DF_QUANTITY='".$this->getCheckNullVal($txtDFQMT)."', ADDNL_QUANTITY='".$this->getCheckNullValue($txtAddnlQMT)."', LADEN_DIST='".$this->getCheckNullValue($txtLDist)."', BALLAST_DIST='".$this->getCheckNullValue($txtBDist)."', LADEN_DAYS='".$this->getCheckNullValue($txtLDays)."', BALLAST_DAYS='".$this->getCheckNullVal($txtBDays)."', TOTAL_PASSAGE_DAYS='".$this->getCheckNullVal($txtTSDays)."', IDEAL_DAYS='".$this->getCheckNullVal($txtTtPIDays)."', WORKING_DAYS='".$this->getCheckNullVal($txtTtPWDays)."', TOTAL_DAYS='".$this->getCheckNullVal($txtTDays)."', TOTAL_DISTANCE='".$this->getCheckNullVal($txtTDist)."', FO_CONSP='".$this->getCheckNullVal($txtTFUMT)."', DO_CONSP='".$this->getCheckNullVal($txtTDUMT)."', GROSS_PREIGHT_ADJ='".$this->getCheckNullValue($txtFrAdjUsdGF)."', DEAD_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdDF)."', ADDNL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdAF)."', TOTAL_PREIGHT_ADJ='".$this->getCheckNullVal($txtFrAdjUsdTF)."', GROSS_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdGFMT)."', DEAD_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdDFMT)."', ADDNL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdAFMT)."', TOTAL_PREIGHT_ADJ_PRMT='".$this->getCheckNullVal($txtFrAdjUsdTFMT)."', ADDRESS_COMMISSION_PER='".$this->getCheckNullValue($txtFrAdjPerAC)."', ADDRESS_COMMISSION_AMT='".$this->getCheckNullValue($txtFrAdjUsdAC)."', ADDRESS_COMMISSION_PRMT='".$this->getCheckNullValue($txtFrAdjUsdACMT)."', BROKERAGE_PER='".$this->getCheckNullValue($txtFrAdjPerAgC)."', BROKERAGE_AMT='".$this->getCheckNullVal($txtFrAdjUsdAgC)."', NET_PAYABLE='".$this->getCheckNullVal($txtFrAdjUsdFP)."', FINAL_NET_FREIGHT='".$this->getCheckNullVal($txtFGFFD)."', FINAL_NET_FREIGHT_PRMT='".$this->getCheckNullVal($txtFGFFDMT)."', BROKERAGE_COMMISSION_PER='".$this->getCheckNullVal($txtBrCommPercent)."', BROKERAGE_COMMISSION_AMT='".$this->getCheckNullVal($txtBrComm)."', TOTAL_ORC_EXP_AMT='".$this->getCheckNullVal($txtTTLORCAmt)."', TOTAL_ORC_EXP_PRMT='".$this->getCheckNullVal($txtTTLORCCostMT)."', REVENUES_FREIGHT='".$this->getCheckNullVal($txtRevenue)."', TOTAL_OWNER_EXP='".$this->getCheckNullValue($txtTTLOwnersExpenses)."', CHARTERER_EXP='".$this->getCheckNullValue($txtTTLCharterersExpenses)."', VOYAGE_EARNING='".$this->getCheckNullValue($txtVoyageEarnings)."', DAILY_EARNING='".$this->getCheckNullValue($txtDailyEarnings)."', DAILY_VESSEL_OPERATION_EXP='".$this->getCheckNullVal($txtDailyVesselOperatingExpenses)."', TOTAL_VOYAGE_EARNING='".$this->getCheckNullVal($txtGTTLVoyageEarnings)."', NET_DAILY_EARNING='".$this->getCheckNullVal($txtNettDailyEarnings)."', NET_DAILY_PROFIT='".$this->getCheckNullVal($txtNettDailyProfit)."', PROFIT_LOSS='".$this->getCheckNullVal($txtPL)."', RDO_QTY='".$this->getCheckNullVal($rdoQty)."', OPEN_PORT='".$selOpenPort."', ZONE_OPEN='".$selZone."', BROKER='".$selBroker."', COA_SPOT='".$selCOASpot."', COA_NUMBER='".$selCOA."', COA_NUMBER_LIFT='".$txtNoLift."', NO_OF_SHIPMENT='', OWNER='".$selOwner."', DISPONENT_OWNER='".$txtDisponentOwner."', LAYCAN_START_DATE='".$txtFDate."', LAYCAN_FINISH_DATE='".$txtTDate."', ETA_DATE='".$txtETADate."', CP_DATE='".$txtCPDate."', REMARKS='".$txtNotes."', ATTACHMENT='".$upload1."', ATTACHMENT_NAME='".$name1."', CARGOID='".$txtCID."', SHIPPER='".$selShipper."', TOLERANCE='".$txtTolerance."', MATERIALID='".$selMType."', MATERIAL_CODE='".$txtMCode."', TERM_TOLERANCE='".$txtTermTolerance."', LPID='".$selLPort."', DPID='".$selDPort."', LAYCAN_CARGO_START_DATE='".$txtLCSDate."', LAYCAN_CARGO_FINISH_DATE='".$txtLCFDate."', HIREAGE_AMT='".$this->getCheckNullVal($txtHireargeAmt)."', HIREAGE_PERCENT='".$this->getCheckNullVal($txtHireargePercent)."', HIREAGE_PER_AMT='".$this->getCheckNullVal($txtHireargePercentAmt)."', HIREAGE_NETT_AMT='".$this->getCheckNullVal($txtNettHireargeAmt)."', QTY_TYPE_RADIO='".$rdoQtyType."', AGREED_GROSS_FREIGHT_LOCAL='".$this->getCheckNullVal($txtMarLocalAggriedFreight)."', CURRENCYID='".$this->getCheckNullVal($selCurrencyMarList)."', EXCHANGE_RATE='".$this->getCheckNullVal($txtMarExchangeRate)."', TTL_FO_CONSP_MT_MANUAL='".$this->getCheckNullVal($txtTFUMTManual)."', TTL_DO_CONSP_MT_MANUAL='".$this->getCheckNullVal($txtTDUMTManual)."', TTL_FO_CONSP_OFFHIRE='".$this->getCheckNullVal($txtTFOCOffHire)."', TTL_DO_CONSP_OFFHIRE='".$this->getCheckNullVal($txtTDOCOffHire)."', DTCVENDORID='".$selDTCVendor."', FINAL_STATUS='".$update_status."', FGFF_VENDORID='".$txtFGFFVendor."', CVE_AMT='".$this->getCheckNullVal($txtCVE)."', CVE_TOTALAMT='".$this->getCheckNullVal($txtCVEAmt)."', CVE_VENDORID='".$this->getCheckNullVal($selCVEVendor)."', BALLAST_BONUS='".$this->getCheckNullVal($txtBallastBonus)."', BUNKER_EXPENSES='".$this->getCheckNullVal($txtTotalBunkerCost)."', PORT_EXPENSES='".$this->getCheckNullVal($txtTotalPortCost)."', BROKERAGE_VENDORID='".$selBroVendor."', ILOHC_VENDORID='".$selILOHCVendor."', HIDDEN_HIRAGE='".$this->getCheckNullVal($txtHiddenHirage)."',  DISTRIBUTED_REMARKS='".$txtDistributedRemarks."', FIXED=1, ESTIMATE_TYPE='".$this->getCheckNullVal($rdoEstimateType)."', GAS_MARKET='".$this->getCheckNullVal($rdoQtyMar)."', GAS_BALTIC='".$this->getCheckNullVal($txtBalticRate)."', ADDNL_PRENIUM='".$this->getCheckNullVal($txtAdnlPrenium)."', GAS_BASE_RATE='".$this->getCheckNullVal($txtBaseRate)."', GAS_QUANTITY='".$this->getCheckNullVal($txtGasCQMT)."', GAS_LUMSUM='".$this->getCheckNullVal($txtGASLumpsum)."', TANK_WS_FROM='".$this->getCheckNullVal($selWSFPort)."', TANK_WS_TO='".$this->getCheckNullVal($selWSTPort)."', TANK_FIXED_DIFF='".$this->getCheckNullVal($txtFixedDiff)."', TANK_QUANTITY='".$this->getCheckNullVal($txtTankQuantity)."', ATTACHMENT2='".$upload2."', ATTACHMENT2_NAME='".$name2."', CHK_LUMPSUM='".$this->getCheckNullVal($ChkLumpsum)."', LUMPSUMAMT='".$this->getCheckNullVal($txtLumpsum)."', WS_QTY='".$this->getCheckNullVal($txtLumpsumQty)."', LUMP_VENDOR ='".$selLumsumVendor."', BASERATE_FLOAT='".$this->getCheckNullVal($txtBaseRateFloating)."', BASERATE_FIXED='".$this->getCheckNullVal($txtBaseRateFixed)."', BASERATE_AVERAGE='".$this->getCheckNullVal($txtBaseRateAverage)."', GROSS_FREIGHT_FLOAT='".$this->getCheckNullVal($txtGFreightFloating)."', GROSS_FREIGHT_FIXED='".$this->getCheckNullVal($txtGFreightFixed)."', GROSS_FREIGHT_AVERAGE='".$this->getCheckNullVal($txtGFreightAverage)."', NETFREIGHT_FLOAT='".$this->getCheckNullVal($txtNFreightFloating)."', NETFREIGHT_FIXED='".$this->getCheckNullVal($txtNFreightFixed)."', NETFREIGHT_AVERAGE='".$this->getCheckNullVal($txtNFreightAverage)."', OWNER_EXPENSES_FLOAT='".$this->getCheckNullVal($txtOExpensesFloating)."', OWNER_EXPENSES_FIXED='".$this->getCheckNullVal($txtOExpensesFixed)."', OWNER_EXPENSES_AVERAGE='".$this->getCheckNullVal($txtOExpensesAverage)."', VEARNING_FLOAT='".$this->getCheckNullVal($txtVEarningFloating)."', VEARNING_FIXED='".$this->getCheckNullVal($txtVEarningFixed)."', VEARNING_AVERAGE='".$this->getCheckNullVal($txtVEarningAverage)."', TCEEARNING_FLOAT='".$this->getCheckNullVal($txtDailyEarningFloating)."', TCEEARNING_FIXED='".$this->getCheckNullVal($txtDailyEarningFixed)."', TCEEARNING_AVERAGE='".$this->getCheckNullVal($txtDailyEarningAverage)."', TCE_MONTH_FLOAT='".$this->getCheckNullVal($txtTCEMonthFloating)."', TCE_MONTH_FIXED='".$this->getCheckNullVal($txtTCEMonthFixed)."', TCE_MONTH_AVERAGE='".$this->getCheckNullVal($txtTCEMonthAverage)."', OEXPENSES_FLOAT='".$this->getCheckNullVal($txtOPExpensesFloating)."', OEXPENSES_FIXED='".$this->getCheckNullVal($txtOPExpensesFixed)."', OEXPENSES_AVERAGE='".$this->getCheckNullVal($txtOPExpensesAverage)."', NET_DAILY_ER_FLOAT='".$this->getCheckNullVal($txtNetDailyEarningFloating)."', NET_DAILY_ER_FIXED='".$this->getCheckNullVal($txtNetDailyEarningFixed)."', NET_DAILY_ER_AVERAGE='".$this->getCheckNullVal($txtNetDailyEarningAverage)."', NET_DAILY_PROFIT_FLOAT='".$this->getCheckNullVal($txtNetDailyProfitFloating)."', NET_DAILY_PROFIT_FIXED='".$this->getCheckNullVal($txtNetDailyProfitFixed)."', NET_DAILY_PROFIT_AVERAGE='".$this->getCheckNullVal($txtNetDailyProfitAverage)."', OPEN_CARGOID='".$this->getCheckNullVal($selCargoPlanning)."', SUMMERDWTMT='".$this->getCheckNullVal($txtSDWTMT)."', SUMMERDWTLT='".$this->getCheckNullVal($txtSDWTLT)."', SUMMERDRAFTM='".$this->getCheckNullVal($txtSDraftM)."', SUMMERDRAFTFT='".$this->getCheckNullVal($txtSDraftFT)."', TPI_MT_INCH='".$this->getCheckNullVal($txtTPIMT)."', TPI_LT_INCH='".$this->getCheckNullVal($txtTPILT)."', TPC_MT='".$this->getCheckNullVal($txtTPCMT)."', TPC_LT='".$this->getCheckNullVal($txtTPCLT)."', CONSTANT_MT='".$this->getCheckNullVal($txtConstantsMT)."', CONSTANT_LT='".$this->getCheckNullVal($txtConstantsLT)."', GRAIN_CAP_CBM='".$this->getCheckNullVal($txtGrainCapCBM)."', GRAIN_CAP_CFT='".$this->getCheckNullVal($txtGrainCapCFT)."', ALLOWED_DRAFTM='".$this->getCheckNullVal($txtAllawedDraftM)."', BUNKER_ROB_MT='".$this->getCheckNullVal($txtBunkerRobMT)."', CARGO_INTAKE_MT='".$this->getCheckNullVal($txtCargoIntakeMT)."', SF_CBM_MT='".$this->getCheckNullVal($txtSFCBM_MT)."', SF_CBFT_MT='".$this->getCheckNullVal($txtSFCBFT_MT)."', CARGO_LOADABLE_MT='".$this->getCheckNullVal($txtCargoLoadableMT)."', GROSS_BREAKDOWN='".$this->getCheckNullVal($txtGrossBreakeven)."', BREAKDOWN_MT='".$this->getCheckNullVal($txtBreakevenMT)."', TANKER_RADIO_SINGLE_DIS='".$this->getCheckNullVal($rdoTankType)."', TC_NO='".$txtTCNo."', GROSS_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtGrossHireargeAmt)."', HIERAGE_CVE='".$this->getCheckNullVal($txtHireargeCVE)."', HIERAGE_CVE_AMOUNT='".$this->getCheckNullVal($txtHireargeCVEAMT)."', OFF_HIRE_CVE='".$this->getCheckNullVal($txtOffHireCVE)."', OFF_HIRE_CVE_AMOUNT='".$this->getCheckNullVal($txtOffHireCVEAMT)."', LESS_OFF_HIRE='".$this->getCheckNullVal($txtLessOffHire)."', FINAL_HIERAGE_AMOUNT='".$this->getCheckNullVal($txtFinalHireargeAmt)."', HIERAGE_BROKER_PERCENT= '".$this->getCheckNullVal($txtHireargeBroPercent)."', HIERAGE_BROKER_AMT= '".$this->getCheckNullVal($txtHireargeBroPercentAmt)."', TC_HIRE_DAYS='".$this->getCheckNullVal($txtTotalVoyageDays)."', TC_CP_DATE='".$txtTC_CPDate."', PERIODID='".$this->getCheckNullValue($selPeriodContract)."', LESS_PER_BLQTY='".$this->getCheckNullValue($txtLessPerQty)."', BL_QTY_FREIGHT='".$this->getCheckNullValue($txtBLCQMT)."', TC_DELIVERY_DATE='".$txtTCDeliveryDate."', TC_RE_DELIVERY_DATE='".$txtTCReDeliveryDate."', TC_DELIVERY_RANGE='".$txtTCDelivery."', TC_RE_DELIVERY_RANGE='".$txtTCReDelivery."', ACTUAL_PL='".$actualpl."', TANKER_FREIGHT_RATE='".$txtTankerFreightRate."', TANK_CLEANING_SECA_HRS='".$this->getCheckNullVal($txtTKSECAHrs)."', TANK_CLEANING_NONSECA_HRS='".$this->getCheckNullVal($txtTKNONSECAHrs)."', INERTING_SECA_HRS='".$this->getCheckNullVal($txtInertSECAHrs)."', INERTING_NONSECA_HRS='".$this->getCheckNullVal($txtInertNONSECAHrs)."', GAS_FREEING_SECA_HRS='".$this->getCheckNullVal($txtGFSECAHrs)."', GAS_FREEING_NONSECA_HRS='".$this->getCheckNullVal($txtGFNONSECAHrs)."', HEATING_SECA_HRS='".$this->getCheckNullVal($txtHeatSECAHrs)."', HEATING_NONSECA_HRS='".$this->getCheckNullVal($txtHeatNONSECAHrs)."', HEATING_SECA_HRS_1='".$this->getCheckNullVal($txtHeatSECAHrs1)."', HEATING_NONSECA_HRS_1='".$this->getCheckNullVal($txtHeatNONSECAHrs1)."',CHARTERING_PIC='".$this->getCheckNullVal($chartering_pic)."' where VESSEL_IMO_ID='".$this->getCheckNullValue($selVName)."' and VOYAGE_NO='".$txtVNo."'";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['txtFCASlaveID_'.$i]))
		{
			$arr_passage[] = $_REQUEST['txtFCASlaveID_'.$i];
		}
	}
	$sql1 = "select * from freight_cost_estimete_in_slave1 where FCAID='".$id."'";
    $res1 = mysql_query($sql1);
	while($rows1 = mysql_fetch_assoc($res1))
	{
		if(!in_array($rows1['FCA_SLAVEID'], $arr_passage))
        {
			$del_query2 = "delete from freight_cost_estimete_in_slave1 where FCAID='".$id."' and FCA_SLAVEID='".$rows1['FCA_SLAVEID']."' ";
            mysql_query($del_query2);
			mysql_query("commit");
		}
	}
	
	$del_query3 = "delete from  freight_cost_estimete_in_slave2 where FCAID='".$id."'";
	$del_query4 = "delete from  freight_cost_estimete_in_slave3 where FCAID='".$id."'";
	$del_query5 = "delete from  freight_cost_estimete_in_slave4 where FCAID='".$id."'";
	$del_query6 = "delete from  freight_cost_estimete_in_slave5 where FCAID='".$id."'";
	$del_query7 = "delete from  freight_cost_estimete_in_slave6 where FCAID='".$id."'";
	$del_query8 = "delete from  freight_cost_estimete_in_slave7 where FCAID='".$id."'";
	$del_query9 = "delete from  freight_cost_estimete_in_slave8 where FCAID='".$id."'";
	$del_query10 = "delete from  freight_cost_estimete_in_slave10 where FCAID='".$id."'";
	$del_query11 = "delete from  freight_cost_estimete_in_slave11 where FCAID='".$id."'";
	$del_query12 = "delete from  freight_cost_estimete_in_slave12 where FCAID='".$id."'";
	$del_query13 = "delete from  freight_cost_estimete_in_slave13 where FCAID='".$id."'";
	$del_query14 = "delete from  freight_cost_estimete_in_slave14 where FCAID='".$id."'";
	$del_query15 = "delete from  freight_cost_estimete_in_slave15 where FCAID='".$id."'";
	$del_query16 = "delete from  freight_cost_estimete_in_slave16 where FCAID='".$id."'";
	$del_query17 = "delete from  freight_cost_estimete_in_slave17 where FCAID='".$id."'";
	mysql_query($del_query3);
	mysql_query($del_query4);
	mysql_query($del_query5);
	mysql_query($del_query6);
	mysql_query($del_query7);
	mysql_query($del_query8);
	mysql_query($del_query9);
	mysql_query($del_query10);
	mysql_query($del_query11);
	mysql_query($del_query12);
	mysql_query($del_query13);
	mysql_query($del_query14);
	mysql_query($del_query15);
	mysql_query($del_query16);
	mysql_query($del_query17);
	mysql_query("commit");
	
	
	for($i=1;$i<= $_REQUEST['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['selFPort_'.$i]))
		{
			if(isset($_REQUEST['txtFCASlaveID_'.$i]) && $_REQUEST['txtFCASlaveID_'.$i]!='')
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "update freight_cost_estimete_in_slave1 set FROM_PORT='".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."', TO_PORT='".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."', DIS_TYPE='".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."', PASSAGE_TYPE='".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."', DISTANCE='".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."', SPEED_TYPE='".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."', SPEED_ADJ='".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."', MARGIN_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."', LOAD_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."', LOAD_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."', LOAD_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."', LOAD_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."', LOAD_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."', LOAD_PORT_IDEAL_DAYS='".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."', DISC_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."', DISC_PORT_QTY='".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."', DISC_PORT_RATE='".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."', DISC_PORT_TERMS='".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."', DISC_PORT_WORK_DAYS='".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."', DISC_PORT_IDEAL_DATE='".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."', TRANSIT_PORT_COST='".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."', TRANSIT_PORT_IDLE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."', PORT_COSTLP_VENDOR='".$_REQUEST['selLPVendor_'.$i]."', DDCLP_COMM='".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."', DDCLP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."', DDCLP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."', DDCLP_VENDOR='".$_REQUEST['selDDCLPVendor_'.$i]."', DDCLP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."', DDCDP_COMM='".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."', DDCDP_ESTCOST='".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."', DDCDP_REALCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."', DDCDP_VENDOR='".$_REQUEST['selDDCDPVendor_'.$i]."', DDCDP_NETCOST='".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."', PORT_COSTDP_VENDOR='".$_REQUEST['selDPVendor_'.$i]."', IS_SHOW_DDCLP='".$_REQUEST['ChkShowDDCLP_'.$i]."', IS_SHOW_DDCDP='".$_REQUEST['ChkShowDDCDP_'.$i]."', RANDOMID='".$randomid."', PORT_COSTTP_VENDOR='".$_REQUEST['selTPVendor_'.$i]."', CHK_LP_SECA='".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', CHK_DP_SECA='".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', CHK_TP_SECA='".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', TOTAL_VOYAGE_DAYS='".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', SECA_DISTANCE='".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', SECA_DAYS='".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."', LP_OPA_VENDOR='".$_REQUEST['selLPOPAVendor_'.$i]."', DP_OPA_VENDOR='".$_REQUEST['selDPOPAVendor_'.$i]."', LP_CA_VENDOR='".$_REQUEST['selLPCharterAgentVendor_'.$i]."', DP_CA_VENDOR='".$_REQUEST['selDPCharterAgentVendor_'.$i]."' where FCAID='".$id."' and FCA_SLAVEID='".$_REQUEST['txtFCASlaveID_'.$i]."'";	
			}
			else
			{
				$randomid = $_REQUEST['txtFCASlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtFCASlaveRandomID_'.$i]) || $_REQUEST['txtFCASlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_in_slave1 (FCAID, FROM_PORT, TO_PORT, DIS_TYPE, PASSAGE_TYPE, DISTANCE, SPEED_TYPE, SPEED_ADJ, MARGIN_DISTANCE, LOAD_PORT_COST, LOAD_PORT_QTY, LOAD_PORT_RATE, LOAD_PORT_TERMS, LOAD_PORT_WORK_DAYS, LOAD_PORT_IDEAL_DAYS, DISC_PORT_COST, DISC_PORT_QTY, DISC_PORT_RATE, DISC_PORT_TERMS, DISC_PORT_WORK_DAYS, DISC_PORT_IDEAL_DATE, TRANSIT_PORT_COST, TRANSIT_PORT_IDLE_DAYS, PORT_COSTLP_VENDOR, DDCLP_COMM, DDCLP_ESTCOST, DDCLP_REALCOST, DDCLP_VENDOR, DDCLP_NETCOST, DDCDP_COMM, DDCDP_ESTCOST, DDCDP_REALCOST, DDCDP_VENDOR, DDCDP_NETCOST, PORT_COSTDP_VENDOR, IS_SHOW_DDCLP, IS_SHOW_DDCDP, RANDOMID, PORT_COSTTP_VENDOR, CHK_LP_SECA, CHK_DP_SECA, CHK_TP_SECA, TOTAL_VOYAGE_DAYS, SECA_DISTANCE, SECA_DAYS, LP_OPA_VENDOR, DP_OPA_VENDOR, LP_CA_VENDOR, DP_CA_VENDOR) values ('".$id."','".$this->getCheckNullValue($_REQUEST['selFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['selSSpeed_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selLPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDPTerms_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTLIDays_'.$i])."' ,'".$_REQUEST['selLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCLPCost_'.$i])."','".$_REQUEST['selDDCLPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCLPNetCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPADDComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtEstDDCDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDCDPCost_'.$i])."','".$_REQUEST['selDDCDPVendor_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDCDPNetCostMT_'.$i])."','".$_REQUEST['selDPVendor_'.$i]."','".$_REQUEST['ChkShowDDCLP_'.$i]."','".$_REQUEST['ChkShowDDCDP_'.$i]."', '".$randomid."', '".$_REQUEST['selTPVendor_'.$i]."', '".$this->getCheckNullValue($_REQUEST['ChkLPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkDPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['ChkTPSECA_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtTtlDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDistance_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtSecaDays_'.$i])."','".$_REQUEST['selLPOPAVendor_'.$i]."','".$_REQUEST['selDPOPAVendor_'.$i]."','".$_REQUEST['selLPCharterAgentVendor_'.$i]."','".$_REQUEST['selDPCharterAgentVendor_'.$i]."')";	
			}
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
		
		$txtSECAConBunkerCount = $_REQUEST['txtSECAConBunkerCount'];
		for($i=1 ; $i<=$txtSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_in_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtSECABunkerAmt_'.$i])."', 'SECA', '".$this->getCheckNullVal($_REQUEST['ChkSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtNONSECAConBunkerCount = $_REQUEST['txtNONSECAConBunkerCount'];
		for($i=1 ; $i<=$txtNONSECAConBunkerCount ;$i++)
		{
				$sql6 = "insert into freight_cost_estimete_in_slave2 (FCAID, BUNKERGRADEID, EST_MT, EST_PRICE, EST_COST, IDENTIFY, CHK_IF_CAL, BUNKER_TYPE) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerid_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtNONSECABunkerAmt_'.$i])."', 'NON_SECA', '".$this->getCheckNullVal($_REQUEST['ChkNONSECACalBunker_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtNONSECAIdentify_'.$i])."')";
				mysql_query($sql6)or die($sql6);
				mysql_query("commit");
		}
		
		$txtFOAtSeaID = $_REQUEST['txtFOAtSeaID'];
		for($i=1;$i<=$txtFOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_in_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtFOAtSeaBunker_'.$i])."', 'FO', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtFOOtherNONSECAConspHeat1_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		$txtDOAtSeaID = $_REQUEST['txtDOAtSeaID'];
		for($i=1;$i<=$txtDOAtSeaID;$i++)
		{
			$sql1 = "insert into freight_cost_estimete_in_slave16 (FCAID, BUNKERID, IDENTIFY, FO_BALAST_ATSEA_SECA_CONSP_FS, FO_LADEN_ATSEA_SECA_CONSP_FS, FO_BALAST_ATSEA_NONSECA_CONSP_FS, FO_LADEN_ATSEA_NONSECA_CONSP_FS, FO_BALAST_ATSEA_SECA_CONSP_SS, FO_LADEN_ATSEA_SECA_CONSP_SS, FO_BALAST_ATSEA_NONSECA_CONSP_SS, FO_LADEN_ATSEA_NONSECA_CONSP_SS, FO_BALAST_ATSEA_SECA_CONSP_MES, FO_LADEN_ATSEA_SECA_CONSP_MES, FO_BALAST_ATSEA_NONSECA_CONSP_MES, FO_LADEN_ATSEA_NONSECA_CONSP_MES, FO_INPORT_SECA_CONSP_WORKING, FO_INPORT_NONSECA_CONSP_WORKING, FO_INPORT_SECA_CONSP_IDLE, FO_INPORT_NONSECA_CONSP_IDLE, FO_INPORT_SECA_CONSP_OTHER, FO_INPORT_NONSECA_CONSP_OTHER, FO_INPORT_SECA_CONSP_IDLE_BALLAST, FO_INPORT_NONSECA_CONSP_IDLE_BALLAST, FO_INPORT_SECA_CONSP_IDLE_LADEN, FO_INPORT_NONSECA_CONSP_IDLE_LADEN, FO_INPORT_SECA_CONSP_WORKING_LP, FO_INPORT_NONSECA_CONSP_WORKING_LP, FO_INPORT_SECA_CONSP_WORKING_DP, FO_INPORT_NONSECA_CONSP_WORKING_DP, FO_OTHER_SECA_CONSP_TK, FO_OTHER_NONSECA_CONSP_TK, FO_OTHER_SECA_CONSP_INERT, FO_OTHER_NONSECA_CONSP_INERT, FO_OTHER_SECA_CONSP_GF, FO_OTHER_NONSECA_CONSP_GF, FO_OTHER_SECA_CONSP_HEAT, FO_OTHER_NONSECA_CONSP_HEAT, FO_OTHER_SECA_CONSP_HEAT_1, FO_OTHER_NONSECA_CONSP_HEAT_1) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtDOAtSeaBunker_'.$i])."', 'DO', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspFS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspSS_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOBalAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOLadAtSeaNONSECAConspMES_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorking_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdle_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspOther_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleBallast_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspIdleLaden_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingLP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOInPortNONSECAConspWorkingDP_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspTK_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspInert_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspGF_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherSECAConspHeat1_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtDOOtherNONSECAConspHeat1_'.$i])."')";
				
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
		
		
		$txtMainCargoDetailID = $_REQUEST['txtMainCargoDetailID'];
		for($i=1 ; $i<=$txtMainCargoDetailID ;$i++)
		{
			if($_REQUEST['selCharterers_'.$i] != "" && $_REQUEST['txtRateUSDmt_'.$i] != "" && $_REQUEST['txtAmountUSD_'.$i] != "")
			{
				$randomid1 = $_REQUEST['txtMSlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID_'.$i]) || $_REQUEST['txtMSlaveRandomID_'.$i]=='')
				{
					$randomid1 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_in_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD_'.$i])."', 1, '".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo_'.$i])."', '".$randomid1."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtoveragedetailID = $_REQUEST['txtoveragedetailID'];
		for($i=1 ; $i<=$txtoveragedetailID ;$i++)
		{
			if($_REQUEST['selCharterers2_'.$i] != "" && $_REQUEST['txtRateUSDmt2_'.$i] != "" && $_REQUEST['txtAmountUSD2_'.$i] != "")
			{
				$randomid2 = $_REQUEST['txtMSlaveRandomID2_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID2_'.$i]) || $_REQUEST['txtMSlaveRandomID2_'.$i]=='')
				{
					$randomid2 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_in_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, DEM_AMT, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers2_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt2_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD2_'.$i])."',2,'".$this->getCheckNullVal($_REQUEST['txtDemAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selCargo2_'.$i])."', '".$randomid2."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtdeadfreightdetailID = $_REQUEST['txtdeadfreightdetailID'];
		for($i=1 ; $i<=$txtdeadfreightdetailID ;$i++)
		{
			if($_REQUEST['selCharterers3_'.$i] != "" && $_REQUEST['txtRateUSDmt3_'.$i] != "" && $_REQUEST['txtAmountUSD3_'.$i] != "")
			{
				$randomid3 = $_REQUEST['txtMSlaveRandomID3_'.$i];
				if(!isset($_REQUEST['txtMSlaveRandomID3_'.$i]) || $_REQUEST['txtMSlaveRandomID3_'.$i]=='')
				{
					$randomid3 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql1 = "insert into freight_cost_estimete_in_slave10 (FCAID, SHIPPER_CHARTER, CARGO_CBM, CARGO_MT, RATE_USD_MT, AMOUNT_USD, STATUS, VENDORID, CARGOID, RANDOMID) values ('".$id."','".$_REQUEST['selCharterers3_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtCargocbm3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtCargomt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtRateUSDmt3_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtAmountUSD3_'.$i])."',3,'".$_REQUEST['selQtyVendor3_'.$i]."', '".$this->getCheckNullVal($_REQUEST['selCargo3_'.$i])."', '".$randomid3."')";
				mysql_query($sql1) or die($sql1);
				mysql_query("commit");
			}
		}
		
		$txtBunkerCount = $_REQUEST['txtBunkerCount'];
		for($i=1 ; $i<=$txtBunkerCount ;$i++)
		{
			if($_REQUEST['txtBunkerQty_'.$i] != "" && $_REQUEST['txtBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_in_slave8 (FCAID, BUNKERGRADEID, COST, VENDORID, COST_MT, QTY, PRICE, PORT, IDENTIFY) values ('".$id."', '".$_REQUEST['selBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtBunkerAmt_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerVendor_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtBunkerPrice_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selBunkerPort_'.$i])."', 'SUPPLY')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		} 
		
		$txtConBunkerCount = $_REQUEST['txtConBunkerCount'];
		for($i=1 ; $i<=$txtConBunkerCount ;$i++)
		{
			if($_REQUEST['txtConBunkerQty_'.$i] != "" && $_REQUEST['txtConBunkerPrice_'.$i] != "")
			{
				$sql8 = "insert into freight_cost_estimete_in_slave8 (FCAID, BUNKERGRADEID, COST, COST_MT, QTY, PRICE, IDENTIFY) values ('".$id."', '".$_REQUEST['selConBunker_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerAmt_'.$i])."', '0.00', '".$this->getCheckNullVal($_REQUEST['txtConBunkerQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtConBunkerPrice_'.$i])."', 'CONSUMPTION')";
				mysql_query($sql8) or die($sql8);
				mysql_query("commit");
			}
		}
		
		$orc_id = $_REQUEST['txtOWCCount'];
		for($i=1;$i<=$orc_id;$i++)
		{
		    $randomid = $_REQUEST['txtORCSlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtORCSlaveRandomID_'.$i]) || $_REQUEST['txtORCSlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql10 = "insert into freight_cost_estimete_in_slave3 (FCAID, IDENTY_ID, IDENTIFY, RAW_AMOUNT, COST_MT, VENDORID, RANDOMID) values ('".$id."' , '".addslashes(trim($_REQUEST['txtHidORCID_'.$i]))."','ORC','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."' ,'".$this->getCheckNullValue($_REQUEST['txtORCAmtMT_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selORCVendor_'.$i])."', '".$randomid."')";
			mysql_query($sql10,$connect) or die($sql10);
			mysql_query("commit");
		}
		
		
		$txtOthInCount = $_REQUEST['txtOthInCount'];
		for($i=1;$i<=$txtOthInCount;$i++)
		{
		    $randomid = $_REQUEST['txtOISlaveRandomID_'.$i];
			if(!isset($_REQUEST['txtOISlaveRandomID_'.$i]) || $_REQUEST['txtOISlaveRandomID_'.$i]=='')
			{
				$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
			}
			$sql120 = "insert into freight_cost_estimete_in_slave3 (FCAID, IDENTY_ID, IDENTIFY, COST, ADDCOMM, RAW_AMOUNT, VENDORID, RANDOMID) values ('".$id."' , '".addslashes(trim($_REQUEST['txtDesc_'.$i]))."','OTHERINCOME','".$this->getCheckNullValue($_REQUEST['txtOtherAmt_'.$i])."' , '".$this->getCheckNullValue($_REQUEST['txtOtherAddComm_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOtherNetAmt_'.$i])."', '".$this->getCheckNullValue($_REQUEST['selOtherIncVendor_'.$i])."', '".$randomid."')";
			mysql_query($sql120,$connect) or die($sql120);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql8 = "insert into freight_cost_estimete_in_slave4 (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$id."', '".$this->getCheckNullVal($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtBrComm_'.$i])."', '".$_REQUEST['selBrCommVendor_'.$i]."')";
				mysql_query($sql8)or die($sql8);
				mysql_query("commit");
			}
		}
		
		$txtTID = $_REQUEST['txtTID'];
		for($i=1 ; $i<=$txtTID ;$i++)
		{
			if($_REQUEST['txtDisponentOwner_'.$i] != "")
			{
				$sql9 = "insert into freight_cost_estimete_in_slave5 (FCAID, DISPONENT_OWNER) values ('".$id."','".$_REQUEST['txtDisponentOwner_'.$i]."')";
				mysql_query($sql9) or die($sql9);
				mysql_query("commit");
			}
		} 
		
		$p_locationID = $_REQUEST['p_locationID'];
		for($i=1 ; $i<=$p_locationID ;$i++)
		{
			if($_REQUEST['txtFromLocation_'.$i] != "")
			{
				$sql10 = "insert into freight_cost_estimete_in_slave6 (FCAID, LOCATION_FROM, LOCATION_TO, PASSAGE_TYPE, SPEED_TYPE, DISTANCE) values ('".$id."', '".$_REQUEST['txtFromLocation_'.$i]."','".$_REQUEST['txtToLocation_'.$i]."','".$this->getCheckNullVal($_REQUEST['selPLocationType_'.$i])."','".$this->getCheckNullVal($_REQUEST['selSLocationSpeed_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtLocationDistance_'.$i])."')";
				mysql_query($sql10) or die($sql10);
				mysql_query("commit");
			}
		} 
		
		$txtQTYID = $_REQUEST['txtQTYID'];
		for($i=1 ; $i<=$txtQTYID ;$i++)
		{
			if($_REQUEST['selQtyVendorList_'.$i] != "")
			{
			    $randomid = $_REQUEST['txtQtySlaveRandomID_'.$i];
				if(!isset($_REQUEST['txtQtySlaveRandomID_'.$i]) || $_REQUEST['txtQtySlaveRandomID_'.$i]=='')
				{
					$randomid = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}
				$sql2 = "insert into freight_cost_estimete_in_slave7 (FCAID, QTY_VENDORID, AGREED_GROSS_FREIGHT, QUANTITY, GROSS_FREIGHT, BROKERAGE, NET_BROKERAGE, NET_FREIGHT, NET_FREIGHT_PERMT, CURRENCYID, AGREED_GROSS_FREIGHT_LOCAL, EXCHANGE_RATE, CARGO, RANDOMID) values ('".$id."','".$_REQUEST['selQtyVendorList_'.$i]."','".$_REQUEST['txtQtyAggriedFreight_'.$i]."','".$_REQUEST['txtFreightQty_'.$i]."','".$_REQUEST['txtQtyFreight_'.$i]."','".$_REQUEST['txtQtyBrokeragePer_'.$i]."','".$this->getCheckNullVal($_REQUEST['txtQtyBrokerageAmt_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyNetFreightMT1_'.$i])."','".$this->getCheckNullVal($_REQUEST['selCurrencyDisList_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtQtyLocalAggriedFreight_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtDisExchangeRate_'.$i])."', '".$this->getCheckNullVal($_REQUEST['selQtyCargo_'.$i])."', '".$randomid."')";
				mysql_query($sql2) or die($sql2);
				mysql_query("commit");
			}
		} 
		
		$txtNoOfInvoice = $_REQUEST['txtNoOfInvoice'];
		for($i=1;$i<=$txtNoOfInvoice;$i++)
		{
			if($_REQUEST['txtInvoiceID_'.$i]!='')
			{
				$sql11 = "insert into freight_cost_estimete_in_slave11 (INVOICEID, FCAID) values ('".addslashes(trim($_REQUEST['txtInvoiceID_'.$i]))."', '".$id."' )";
				mysql_query($sql11) or die($sql11);
				mysql_query("commit");
			}
		}
		
		
		$txtTankID = $_REQUEST['txtTankID'];
		for($i=1 ; $i<=$txtTankID ;$i++)
		{
			if($_REQUEST['txtFreightSpecs_'.$i] != "")
			{
				$sql12 = "insert into freight_cost_estimete_in_slave12 (FCAID, FREIGHT_SPECS, CUSTOMER, MIN_CARGO_QTY, OVE_CARGO_QTY, MIN_FLAT_RATE, OVE_FLAT_RATE, MIN_WS, OVE_WS, MIN_DIS_LEG, OVE_DIS_LEG, MIN_DISTANCE, OVE_DISTANCE, MIN_AMOUNT, OVE_AMOUNT, TOTAL_QTY, TOTAL_AMOUNT) values ('".$id."', '".$_REQUEST['txtFreightSpecs_'.$i]."', '".$_REQUEST['selTankVendor_'.$i]."', '".$this->getCheckNullVal($_REQUEST['txtMinCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtOveCargoQty_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveFlatRateQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveWSQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtMinDisLeg_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveDisLeg_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinTotalDis_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveTotalDis_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtMinAmount_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtOveAmount_'.$i])."', '".$this->getCheckNullVal($_REQUEST['txtTotalTankQty_'.$i])."','".$this->getCheckNullVal($_REQUEST['txtTotalTankAmount_'.$i])."')";
				mysql_query($sql12) or die($sql12);
				mysql_query("commit");
			}
		}
		
		$txtHIREID = $_REQUEST['txtHIREID'];
		for($i=1 ; $i<=$txtHIREID ;$i++)
		{
			if($_REQUEST['txtHireFrom_'.$i] != "" && $_REQUEST['txtHireTo_'.$i] != "")
			{
				if($_REQUEST['txtHireFrom_'.$i]!="")
				{$txtHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireFrom_'.$i]));}
				else{$txtHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtHireTo_'.$i]!="")
				{$txtHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtHireTo_'.$i]));}
				else{$txtHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCHireRandom_'.$i]) || $_REQUEST['txtTCHireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCHireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_in_slave17 (FCAID, HIRE_FROM, HIRE_TO, HIRE_DAYS, HIRE_RATE, HIRE_AMT, RANDOMID) values ('".$id."', '".$txtHireFrom."', '".$txtHireTo."', '".$this->getCheckNullValue($_REQUEST['txtHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtHireAmt_'.$i])."', '".$this->getCheckNullValue($randomid4)."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		} 
		
		
		$txtOFFID = $_REQUEST['txtOFFID'];
		for($i=1 ; $i<=$txtOFFID ;$i++)
		{
			if($_REQUEST['txtOffHireReason_'.$i] != "")
			{
				if($_REQUEST['txtOffHireFrom_'.$i]!="")
				{$txtOffHireFrom     		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireFrom_'.$i]));}
				else{$txtOffHireFrom  		= "1970-01-01 08:00:00";}
				
				if($_REQUEST['txtOffHireTo_'.$i]!="")
				{$txtOffHireTo 	    		= date("Y-m-d H:i",strtotime($_REQUEST['txtOffHireTo_'.$i]));}
				else{$txtOffHireTo  		= "1970-01-01 08:00:00";}
				
				if(!isset($_REQUEST['txtTCOFFhireRandom_'.$i]) || $_REQUEST['txtTCOFFhireRandom_'.$i]=='')
				{
					$randomid4 = intval( rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) );
				}else
				{
				    $randomid4 = $_REQUEST['txtTCOFFhireRandom_'.$i];
				}
				
				$sql3 = "insert into freight_cost_estimete_in_slave14 (FCAID, OFF_REASON, OFF_FROM, OFF_TO, OFF_DAYS, HIRE_RATE, OFF_HIRE, RANDOMID) values ('".$id."', '".addslashes($_REQUEST['txtOffHireReason_'.$i])."', '".$txtOffHireFrom."', '".$txtOffHireTo."', '".$this->getCheckNullValue($_REQUEST['txtOffHireDays_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireRate_'.$i])."', '".$this->getCheckNullValue($_REQUEST['txtOffHireAmt_'.$i])."', '".$randomid4."')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
				
				$mysql14 = "select max(FCA_SLAVE14ID) as max from freight_cost_estimete_in_slave14 where FCAID='".$id."'";
				$myres14  =  mysql_query($mysql14);
				$myrows14 = mysql_fetch_assoc($myres14);
				$maxid14 = $myrows14['max'];
				
				$txtDELID = $_REQUEST['txtTCConBunkerCount_'.$i];
				for($m=1 ; $m<=$txtDELID ;$m++)
				{
					if($_REQUEST['selTCConBunker_'.$i.'_'.$m] != "" && $_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m] != "")
					{
						if(isset($_REQUEST['ChkOFFHireCal_'.$i.'_'.$m])){$checkboxvalue =  $_REQUEST['ChkOFFHireCal_'.$i.'_'.$m];}else{$checkboxvalue = 0;}
						$sql15 = "insert into freight_cost_estimete_in_slave15 (FCA_SLAVE14ID, FCAID, BUNKERID, BUNKERQTY, BUNKERPRICE, BUNKERAMT, CHECK_BUNKER_CAL) values ('".$maxid14."', '".$id."', '".$this->getCheckNullValue($_REQUEST['selTCConBunker_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerQty_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerPrice_'.$i.'_'.$m])."', '".$this->getCheckNullValue($_REQUEST['txtTCConBunkerAmt_'.$i.'_'.$m])."', '".$checkboxvalue."')";
						mysql_query($sql15) or die($sql15);
						mysql_query("commit");
					}
				}
			}
		} 
		
		$txtDELID = $_REQUEST['txtDELID'];
		for($j=1 ; $j<=$txtDELID ;$j++)
		{
			if($_REQUEST['selDelBunker_'.$j] != "" && $_REQUEST['txtDelQty_'.$j] != "")
			{
				if($_REQUEST['txtDelBunDate_'.$j]!="")
				{$txtDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtDelBunDate_'.$j]));}
				else{$txtDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_in_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelAmount_'.$j])."', '".$txtDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtDelPrice_'.$j])."', 'DEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
		$txtREDELID = $_REQUEST['txtREDELID'];
		for($j=1 ; $j<=$txtREDELID ;$j++)
		{
			if($_REQUEST['selReDelBunker_'.$j] != "" && $_REQUEST['txtReDelQty_'.$j] != "")
			{
				if($_REQUEST['txtReDelBunDate_'.$j]!="")
				{$txtReDelBunDate    		= date("Y-m-d",strtotime($_REQUEST['txtReDelBunDate_'.$j]));}
				else{$txtReDelBunDate    	= "1970-01-01";}
				$sql3 = "insert into freight_cost_estimete_in_slave13 (FCAID, BUNKERID, AMOUNT, BUNKER_DATE, QTY, PRICE, IDENTITY) values ('".$id."', '".$this->getCheckNullValue($_REQUEST['selReDelBunker_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelAmount_'.$j])."', '".$txtReDelBunDate."', '".$this->getCheckNullValue($_REQUEST['txtReDelQty_'.$j])."', '".$this->getCheckNullValue($_REQUEST['txtReDelPrice_'.$j])."', 'REDEL')";
				mysql_query($sql3) or die($sql3);
				mysql_query("commit");
			}
		}
		
	return $msg.'&comid='.$comid; 
}

} // class data ends



?>