<?php
include_once("../../connection/setting_jaldhi_class.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;

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 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 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 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 displayBankingDetailList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="banking_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="30%"  >Name Of Beneficiary</th>';
	echo '<th align="left" valign="middle" width="40%"  >Address</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="10%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from banking_details WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">'.$rows['ADDRESS'].'</td>';
				echo '<td align="left">';
				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['BD_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['BD_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"><a href="updatebankingdetails.php?id='.$rows['BD_ID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a></td>';	
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

function changeBankingDetailStatusRecords()
{
	$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 banking_details set STATUS='".$tblstatus."' where BD_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']."','Banking Detail Record Status Updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}

function insertBankingDetails()


{
	$connect 		= $this->funConnect();
	$txtNOB 		= addslashes(trim($_REQUEST['txtNOB']));
	$txtAdd 		= addslashes(trim($_REQUEST['txtAdd']));
	$txtBAcc_No 	= addslashes(trim($_REQUEST['txtBAcc_No']));
	$txtBBank 		= addslashes(trim($_REQUEST['txtBBank']));
	$txtBBank_SCode = addslashes(trim($_REQUEST['txtBBank_SCode']));
	$txtIBAN_No 	= addslashes(trim($_REQUEST['txtIBAN_No']));
	$txtFed_Aba 	= addslashes(trim($_REQUEST['txtFed_Aba']));
	$txtCID 		= addslashes(trim($_REQUEST['txtCID']));
	$txtCBN 		= addslashes(trim($_REQUEST['txtCBN']));
	$txtSCN 		= addslashes(trim($_REQUEST['txtSCN']));
	$txtRef 		= addslashes(trim($_REQUEST['txtRef']));
	$txtBID 		= addslashes(trim($_REQUEST['txtBID']));
	$txtBAdd 		= addslashes(trim($_REQUEST['txtBAdd']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into banking_details (NAME, ADDRESS, AC_NO, MODULEID, MCOMPANYID, BANK, BANK_SWIFT_CODE, IBAN_NO, FED_ABA, C_BANK_NAME, C_SWIFT_CODE, REFERENCE, B_ADDRESS) values ('".$txtNOB."','".$txtAdd."','".$txtBAcc_No."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$txtBBank."','".$txtBBank_SCode."','".$txtIBAN_No."','".$txtFed_Aba."','".$txtCBN."','".$txtSCN."','".$txtRef."','".$txtBAdd."')";
	mysql_query($sql);
	mysql_query("commit");
	
	$sql1 = "select max(BD_ID) as max from banking_details";
	$res1 = mysql_query($sql1);
	$rows1 = mysql_fetch_assoc($res1);
	//echo $txtCID,$txtBID;
	for($i=1;$i<=$txtCID;$i++)
	{
		if(addslashes(trim($_REQUEST['txtBDName_'.$i])) != '' && addslashes(trim($_REQUEST['txtBDValue_'.$i])) != '')
		{
			$sql2 = "insert into banking_details_slave (BD_ID, NAME, VALUE, STATUS) values ('".$rows1['max']."', '".addslashes(trim($_REQUEST['txtBDName_'.$i]))."', '".addslashes(trim($_REQUEST['txtBDValue_'.$i]))."', 1)";
			mysql_query($sql2);
		}
	}
	
	for($i=1;$i<=$txtBID;$i++)
	{
		if(addslashes(trim($_REQUEST['txtCDName_'.$i])) != '' && addslashes(trim($_REQUEST['txtCDValue_'.$i])) != '')
		{
			$sql3 = "insert into banking_details_slave (BD_ID, NAME, VALUE, STATUS) values ('".$rows1['max']."', '".addslashes(trim($_REQUEST['txtCDName_'.$i]))."', '".addslashes(trim($_REQUEST['txtCDValue_'.$i]))."', 2)";
			mysql_query($sql3);
		}
	}
    $sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Banking Detail Record added successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit");
	return $msg; 
}

function viewBankingDetailsRecords($id)
{
	$connect = $this->funConnect();
	$query 	 = "SELECT * FROM banking_details where BD_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['ADDRESS'];
		$this->var_3 = $rows['AC_NO'];
		$this->var_4 = $rows['BANK'];
		$this->var_5 = $rows['BANK_SWIFT_CODE'];
		$this->var_6 = $rows['IBAN_NO'];
		$this->var_7 = $rows['FED_ABA'];
		$this->var_8 = $rows['C_BANK_NAME'];
		$this->var_9 = $rows['C_SWIFT_CODE'];
		$this->var_10 = $rows['REFERENCE'];
		$this->var_11 = $rows['B_ADDRESS'];
	}
}

function updateBankingDetailsRecords()
{
	$connect		= $this->funConnect();
	$id 			= $_REQUEST['id'];
 	$txtNOB 		= addslashes(trim($_REQUEST['txtNOB']));
	$txtAdd 		= addslashes(trim($_REQUEST['txtAdd']));
	$txtBAcc_No 	= addslashes(trim($_REQUEST['txtBAcc_No']));
	$txtBBank 		= addslashes(trim($_REQUEST['txtBBank']));
	$txtBBank_SCode = addslashes(trim($_REQUEST['txtBBank_SCode']));
	$txtIBAN_No 	= addslashes(trim($_REQUEST['txtIBAN_No']));
	$txtFed_Aba 	= addslashes(trim($_REQUEST['txtFed_Aba']));
	$txtCID 		= addslashes(trim($_REQUEST['txtCID']));
	$txtCBN 		= addslashes(trim($_REQUEST['txtCBN']));
	$txtSCN 		= addslashes(trim($_REQUEST['txtSCN']));
	$txtRef 		= addslashes(trim($_REQUEST['txtRef']));
	$txtBID 		= addslashes(trim($_REQUEST['txtBID']));
	$txtBAdd 		= addslashes(trim($_REQUEST['txtBAdd']));

	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update banking_details set NAME='".$txtNOB."',ADDRESS='".$txtAdd."',AC_NO='".$txtBAcc_No."',BANK='".$txtBBank."',BANK_SWIFT_CODE='".$txtBBank_SCode."',IBAN_NO='".$txtIBAN_No."',FED_ABA='".$txtFed_Aba."',C_BANK_NAME='".$txtCBN."',C_SWIFT_CODE='".$txtSCN."',REFERENCE='".$txtRef."',B_ADDRESS='".$txtBAdd."' where BD_ID='".$id."' and  MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	mysql_query($sql);
	
	$sql1 = "delete from banking_details_slave where BD_ID='".$id."'";
	mysql_query($sql1);
	
	for($i=1;$i<=$txtCID;$i++)
	{
		if(addslashes(trim($_REQUEST['txtBDName_'.$i])) != '' && addslashes(trim($_REQUEST['txtBDValue_'.$i])) != '')
		{
			$sql2 = "insert into banking_details_slave (BD_ID, NAME, VALUE, STATUS) values ('".$id."', '".addslashes(trim($_REQUEST['txtBDName_'.$i]))."', '".addslashes(trim($_REQUEST['txtBDValue_'.$i]))."', 1)";
			mysql_query($sql2);
		}
	}
	
	for($i=1;$i<=$txtBID;$i++)
	{
		if(addslashes(trim($_REQUEST['txtCDName_'.$i])) != '' && addslashes(trim($_REQUEST['txtCDValue_'.$i])) != '')
		{
			$sql3 = "insert into banking_details_slave (BD_ID, NAME, VALUE, STATUS) values ('".$id."', '".addslashes(trim($_REQUEST['txtCDName_'.$i]))."', '".addslashes(trim($_REQUEST['txtCDValue_'.$i]))."', 2)";
			mysql_query($sql3);
		}
	}
	$sql3 = "insert into recent_work_master (LOGINID, WORK, WORK_DATE) values ('".$_SESSION['uid']."','Banking Details Record updated successfully.',NOW())";
	mysql_query($sql3) or die(mysql_error());
	mysql_query("commit"); 
	return $msg;
}



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" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="30%"  >Approval Name</th>';
	echo '<th align="left" valign="middle" width="40%"  >Description</th>';
	echo '<th align="left" valign="middle" width="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="10%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from approvals_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left">';
				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"><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."' 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 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."' 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['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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">'.$this->getPortNameBasedOnID($rows['PORT_CODE']).'</td>';
				echo '<td align="left">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left">';
				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"><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 * 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 from PORT_MASTER where PortCode='".$id."'";
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['PortName'];
}

function viewTerminalRecords($id)
{
	$connect = $this->funConnect();
	$query = "SELECT * FROM terminal_master where TERMINALID='".$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['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 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))
			{
				echo '<tr>';
				echo '<td align="center">'.$i.'.</td>';
				echo '<td align="left">'.$rows['MATERIAL_TYPE'].'</td>';
				echo '<td align="left">'.$rows['MATERIAL_CODE'].'</td>';
				echo '<td align="left">'.$rows['MATERIAL_CODE_DESC'].'</td>';
				echo '<td align="left">';
				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"><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']));
	
	$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) values ('".$mtype."','".$mcode."','".$mtype_desc."','".$mcode_desc."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$mgroup."','".$mgroup_desc."')";
	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'];
	}
}

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

	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."' 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" width="5%">#</th>';
	echo '<th align="left" width="25%">Contract Type</th>';
	echo '<th align="left" width="35%">Description</th>';
	echo '<th align="left" width="10%">Status</th>';
	echo '<th align="center" width="5%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from contract_type_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['CONTRACT_TYPE'].'</td>';
				echo '<td align="left">'.$rows['DESCRIPTION'].'</td>';
				echo '<td align="left">';
				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"><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."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$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" width="5%" >#</th>';
	echo '<th align="left" valign="middle" width="30%"  >Port Cost Type</th>';
	echo '<th align="left" valign="middle" width="45%"  >Countries</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_cost_type_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">'.$this->getCountryData($rows['COUNTRY_IDS'],"COUNTRY_NAME").'</td>';
				echo '<td align="left">';
				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"><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="10%"  >Status</th>';
	echo '<th align="center" valign="middle" width="5%" >Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "select * from agency_fee_record_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$this->getVendorListNewBasedOnID($rows['AGENTMASTERID']).'</td>';
				echo '<td align="left">'.$this->getPortNameBasedOnID($rows['PORTID']).'</td>';
				echo '<td align="left">'.date("d-M-Y",strtotime($rows['DATE'])).'</td>';
				echo '<td align="left">'.$rows['FEE'].'</td>';
				echo '<td align="left">';
				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"><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)
{
	$connect = $this->funConnect();
	$sql 	 = "select PortName from PORT_MASTER where PortId='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows['PortName'];
}


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']));
	$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) values ('".$date."','".$vendor_type."','".$agentid."','".$portid."','".$fee."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$selCurrency."')";
		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()
{
	$connect = $this->funConnect();
	$query 	 = "select * from vendor_type_master where STATUS=1 order by NAME ";
	$result  = mysql_query($query);
	echo "<option value = '' >---Select from list---</option>";
	@$selVType = @$_REQUEST['selVType'];
	while($rows = mysql_fetch_assoc($result))
	{
		$key = $rows['VENDOR_TYPEID'];
		$value = $rows['NAME'];
		echo "<option value='".$key."' ";
		if($key == @$selVType){ echo " selected";}
		echo ">".$value."</option>";
	}
}


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

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



function updateAgencyFeeRecords()
{
	$connect		= $this->funConnect();
	$fee	 		= addslashes(trim($_REQUEST['txtAFee']));
	$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 FEE='".$fee."', CURRENCYID='".$selCurrency."' 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'];
	}
}


function getVendorListNewBasedOnID($id)
{
	$connect = $this->funConnect();
	$sql 	 = "select NAME from vendor_master where CODE='".$id."' ";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $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 WHERE MODULEID='".$_SESSION['moduleid']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' order by STATUS,NAME";*/
	$sql = "select * from other_misc_cost_master WHERE MODULEID='".$_SESSION['moduleid']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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 WHERE MODULEID='".$_SESSION['moduleid']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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."' ";
	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 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">'.$i.'.</td>';
				echo '<td align="left">'.$this->getVendorTypeNameBasedOnID($rows['VENDOR_TYPEID']).'</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">'.$rows['SHORT_NAME'].'</td>';
				echo '<td align="left">'.$rows['CODE'].'</td>';
				echo '<td align="left">';
				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"><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 $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['POSTAL_CODE'];
		$this->var_19 = $rows['PHONE'];
		$this->var_20 = $rows['FAX'];
	}
}


function InsertVendorMasterRecords()
{
	$connect				= $this->funConnect();
 	$v_type 				= addslashes(trim($_REQUEST['selVType']));
	$v_code 				= addslashes(trim($_REQUEST['txtVCode']));
	$name	 				= addslashes(trim($_REQUEST['txtVName']));
	$short_name				= addslashes(trim($_REQUEST['txtVSName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into vendor_master (VENDOR_TYPEID,NAME,SHORT_NAME,CODE,MODULEID,MCOMPANYID) values ('".$v_type."' ,'".$name."' ,'".$short_name."' ,'".$v_code."','".$_SESSION['moduleid']."','".$_SESSION['company']."')";
	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 UpdateVendorMasterRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
 	$v_type 				= addslashes(trim($_REQUEST['selVType']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "update vendor_master set VENDOR_TYPEID='".$v_type."' where VENDORID='".$id."'";
	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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$this->getPortNameBasedOnID($rows['PORTID']).'</td>';
				echo '<td align="left">'.$this->getMaterialCodeDesBasedOnId($rows['CARGOID']).'</td>';
				echo '<td align="left">'.$this->getTerminalNameBasedOnID($rows['TERMINALID']).'</td>';
				echo '<td align="left">';
				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"><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)
{
	$connect = $this->funConnect();
	$sql 	 = "select MATERIAL_CODE_DESC,MATERIAL_CODE from cargo_master where MATERIALID='".$id."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows['MATERIAL_CODE_DESC']." (".$rows['MATERIAL_CODE'].")";
}

function getTerminalNameBasedOnID($id)
{
	$connect = $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['PortId'];
	    $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 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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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();
 	//$txtName 				= addslashes(trim($_REQUEST['txtName']));
	
	$txtName 				= trim(ereg_replace(' +','_',$_REQUEST['txtName']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
		
	$msg = 0;
	$sql = "insert into bunker_grade_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']."','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'];
	}
}

function updateBunkerGradeRecords()
{
	$connect				= $this->funConnect();
	$id 					= $_REQUEST['id'];
 	//$txtName 				= addslashes(trim($_REQUEST['txtName']));
	$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."' 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 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 id="tbody">';
		while($rows = mysql_fetch_assoc($res))
			{
				echo '<tr>';
				echo '<td align="center">'.$i.'.</td>';
				echo '<td align="left">'.$this->getPortNameBasedOnID($rows['PORT_ID']).'</td>';
				echo '<td align="left">'.$this->getTerminalNameBasedOnID($rows['TERMINALID']).'</td>';
				echo '<td align="left">'.$rows['MATERIALCODE_DESC'].'</td>';
				echo '<td align="left">';
				$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"><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 MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and 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 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" width="10%" >#</th>';
	echo '<th align="left" valign="middle" width="30%">Baltic Route Code</th>';
	echo '<th align="left" valign="middle" width="30%">Baltic Route Description</th>';
	echo '<th align="left" valign="middle" width="10%">Status</th>';
	echo '<th align="center" valign="middle" width="10%">Details</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "SELECT * FROM baltic_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['CODE'].'</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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 WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' 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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">';
				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"><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">'.$i.'.</td>';
				echo '<td align="left">'.$rows['NAME'].'</td>';
				echo '<td align="left">'.$rows['SIZE'].'</td>';
				echo '<td align="left">';
				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"><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()
{
	$connect = $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()
{
	$connect = $this->funConnect();
	$query 	 = "SELECT * FROM vendor_master WHERE STATUS=1 order by VENDOR_TYPEID,NAME ";
	$result  = mysql_query($query);
	echo "<option value = '' >---select from list---</option>";
	@$selShipper = @$_REQUEST['selShipper'];
	while($rows = mysql_fetch_assoc($result))
	{
		$key= $rows['VENDORID'];
		$value= $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."'";
	$res  	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $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 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))
			{
				echo '<tr>';
				echo '<td align="center">'.$i.'.</td>';				
				echo '<td align="left">'.$this->getMaterialCodeDesBasedOnId($rows['MATERIALID']).'</td>';
				echo '<td align="left">'.$this->getPortNameBasedOnID($rows['PORT_ID']).'</td>';
				echo '<td align="left">'.$this->getVendorNameBasedOnID($rows['VENDORID']).'</td>';				
				
				echo '<td align="left">';
				$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"><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();	
	
	$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;
	
	echo '
	<div id="DivOwner" class="box-body table-responsive">
	<table id="coa_list" class="table table-bordered table-striped">
	<thead>
		<tr>
			<th width="13%">COA CP Date</th>
			<th width="13%">COA Number</th>
			<th width="13%">Cargo/Material Type</th>
			<th width="13%">Vessel Category</th>
			<th width="12%">No. of Shipments</th>
			<th width="12%">Performed</th>
			<th width="12%">Owner</th>
			<th width="12%">Details</th>
		</tr>
	</thead>';
	if($rec == 0)
	{
		echo '<tbody>';
		echo '</tbody>';
	}
	else{
		
		echo '<tbody>';		
		while($rows = mysql_fetch_assoc($res))
		{
			if((int)$rows['NO_OF_SHIPMENT'] != (int)$this->getPerformedVesselRec($rows['COAID']))
			{
				echo '<tr>';
				echo '<td>'.date("d-m-Y",strtotime($rows['COA_DATE'])).'</td>';
				echo '<td>'.$rows['COA_NO'].'</td>';
				echo '<td>'.$this->getCargoNameBasedOnId($rows['CARGOTYPEID']).'</td>';
				echo '<td>'.$this->getVesselCategoryTypeBasedOnId($rows['VESSEL_CATEGORY_ID']).'</td>';
				echo '<td>'.$rows['NO_OF_SHIPMENT'].'</td>';
				echo '<td>'.$this->getPerformedVesselRec($rows['COAID']).'</td>';
				echo '<td>'.$this->getVendorListNewBasedOnID($rows['OWNER']).' ('.$rows['OWNER'].')</td>';
				echo '<td align="center">';
				if($this->getPerformedVesselRec($rows['COAID']) == 0)
				{
					echo '<a href="#deleteList" onclick="return getDelete('.$rows['COAID'].')" title="Cancel COA"><i class="fa fa-times" style="color:red;"></i></a>&nbsp;|&nbsp;';
				}
				echo '<a href="monthly_coa_remarks.php?id='.$rows['COAID'].'" title="Monthly Remarks" ><i class="fa fa-edit "></i></a>&nbsp;|&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>';
echo '</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()
{
	$connect 				= $this->funConnect();
	$selCargoType 			= addslashes(trim($_REQUEST['selCargoType']));
	$selVCType 				= addslashes(trim($_REQUEST['selVCType']));
	$coa_no 				= addslashes(trim($_REQUEST['txtCOANo']));
	$coa_date 				= date("Y-m-d",strtotime($_REQUEST['txtCOADate']));
	$cargo_qty 				= addslashes(trim($_REQUEST['txtCQty']));
	$owner 					= addslashes(trim($_REQUEST['selOwner']));
	$broker 				= addslashes(trim($_REQUEST['selBroker']));
	$charterer				= addslashes(trim($_REQUEST['selCharterer']));
	$no_of_shipment 		= addslashes(trim($_REQUEST['txtNoofShipment']));
	$size_of_qty 			= addslashes(trim($_REQUEST['txtSQty']));
	$tolerance 				= addslashes(trim($_REQUEST['txtTolerance']));
	$shipment 				= addslashes(trim($_REQUEST['txtShipment']));
	$per 					= addslashes(trim($_REQUEST['txtper']));
	$start_date				= date("Y-m-d",strtotime($_REQUEST['txtStartDate']));
	$notice_days 			= addslashes(trim($_REQUEST['txtNotice']));
	$f_rate 				= addslashes(trim($_REQUEST['txtFRate']));
	$demu_rate 				= addslashes(trim($_REQUEST['txtDemuRate']));
	$dis_rate 				= addslashes(trim($_REQUEST['txtDisRate']));
	$add_comm 				= addslashes(trim($_REQUEST['txtAddComm']));
	$checkBAFbox 			= addslashes(trim($_REQUEST['checkBAFbox']));
	$b_price 				= addslashes(trim($_REQUEST['txtBPrice']));
	$baf_terms 				= addslashes(trim($_REQUEST['txtBAFTerms']));
	$inc_dec 				= addslashes(trim($_REQUEST['txtIncDec']));
	$remarks 				= addslashes(trim($_REQUEST['txtRemarks']));
	$id						= trim($_REQUEST['id']);
	
	$fm_file 				= $_FILES['fre_matrix']['name'];
	$txtCRM 				= addslashes(trim($_REQUEST['txtCRM']));
	$txtCRM1 				= addslashes(trim($_REQUEST['txtCRM1']));
	
	$selTCINOwner 			= addslashes(trim($_REQUEST['selTCINOwner']));
	$dailyHire 				= addslashes(trim($_REQUEST['txtDailyHire']));
	$dateOfDel				= $_REQUEST['txtDateOfDel'];
	$selDelPort 			= addslashes(trim($_REQUEST['selDelPort']));
	$dateOfReDel		 	= $_REQUEST['txtDateOfReDel'];
	$selReDelPort 			= addslashes(trim($_REQUEST['selReDelPort']));
	
	if(isset($_FILES["fre_matrix"])) {
		if($_FILES['fre_matrix']['name'] != '') { 
       		$upload = $this->getUpload($_FILES['fre_matrix']);
		} else {
			$upload = trim($_REQUEST['txtFileName1']);
		}
	}
	
	if(isset($_FILES["attach_file"])) {
		if($_FILES['attach_file']['name'] != '') { 
       		$upload1 = $this->getUpload($_FILES['attach_file']);
		} else {
			$upload1 = trim($_REQUEST['txtFileName2']);
		}
	}
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$sql = "update coa_master set COA_NO='".$coa_no."',COA_DATE='".$coa_date."',CARGO_QTY='".$cargo_qty."',OWNER='".$owner."',BROKER='".$broker."',CHARTERER='".$charterer."',NO_OF_SHIPMENT='".$no_of_shipment."',SIZE_OF_QTY='".$size_of_qty."',TOLERANCE='".$tolerance."',SHIPMENT='".$shipment."',PER_MONTH='".$per."',START_DATE='".$start_date."',NOTICE_DAYS='".$notice_days."',FREIGHT_RATE='".$f_rate."',DEMURRAGE_RATE='".$this->getCheckNullValue($demu_rate)."',DISPATCH_RATE='".$this->getCheckNullValue($dis_rate)."',ADD_COMM='".$this->getCheckNullValue($add_comm)."',BAF='".$checkBAFbox."',BUNKER_PRICE='".$b_price."',BAF_TERMS='".$baf_terms."',INCREASE_DECREASE='".$inc_dec."',REMARKS='".$remarks."',UPLOAD_FILE_NAME='".$name2."',CARGOTYPEID= '".$selCargoType."',VESSEL_CATEGORY_ID='".$selVCType."',TC_IN_OWNERS='".$selTCINOwner."',DAILY_HIRE_USD='".$this->getCheckNullValue($dailyHire)."',DATE_OF_DEL='".$this->getCheckDateTimeNullValue($dateOfDel)."',PORT_OF_DEL='".$selDelPort."',DATE_OF_RE_DEL='".$this->getCheckDateTimeNullValue($dateOfReDel)."',PORT_OF_RE_DEL='".$selReDelPort."',FREIGHT_MATRIX_UPLOAD='".$upload."', UPLOAD_FILE='".$upload1."' where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and COAID='".$id."' ";
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	if(!empty($fm_file))
	{
		$fm_tmpFile 	= $_FILES["fre_matrix"]["tmp_name"];
		move_uploaded_file($_FILES['fre_matrix']['tmp_name'], '../../attachment/'.$fm_file);
		
		$sql1 = "update coa_master set FREIGHT_MATRIX_UPLOAD='".$fm_file."'  where MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and COAID='".$id."'";
		mysql_query($sql1) or die($sql1);
	}
	
	$delQuery1 = "delete from coa_master_hire_slave1 where COAID='".$id."'";
	$delQuery2 = "delete from coa_master_bod_slave2 where COAID='".$id."'";
	$delQuery3 = "delete from coa_master_bctr_slave3 where COAID='".$id."'";
	$delQuery4 = "delete from coa_master_bor_slave4 where COAID='".$id."'";
	
	mysql_query($delQuery1) or die($delQuery1);
	mysql_query("commit");
	mysql_query($delQuery2) or die($delQuery2);
	mysql_query("commit");
	mysql_query($delQuery3) or die($delQuery3);
	mysql_query("commit");
	mysql_query($delQuery4) or die($delQuery4);
	mysql_query("commit");
	
	$coaid 		= $id;
	
	$ofhireId 	=  trim($_REQUEST['txtOFFID']);
	for($i = 1; $i<=$ofhireId; $i++){
		if(isset($_REQUEST['txtOffHireReason_'.$i])){
			$sql2 = " insert into coa_master_hire_slave1 (COAID, OFF_HIRE_REASON, OFF_HIRE_FROM_DATE, OFF_HIRE_TO_DATE) values ('".$coaid."','".$_REQUEST['txtOffHireReason_'.$i]."','".$this->getCheckDateTimeNullValue($_REQUEST['txtFromOff_'.$i])."','".$this->getCheckDateTimeNullValue($_REQUEST['txtToOff_'.$i])."')";
		}		
		mysql_query($sql2) or die($sql2);
		mysql_query("commit");
	}
	
	//1
	
	$bid = trim($_REQUEST['txtbid']);
	for($i = 1; $i<=$bid; $i++){
		
		if(isset($_REQUEST['txtBunkerID_'.$i])){		
		$sql3 = "insert into coa_master_bod_slave2 (COAID, BUNKERGRADID, QUANTITY_MT, PRICE_USD_MT, AMOUNT) values ('".$coaid."','".$_REQUEST['txtBunkerID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtConspQtyMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPrice_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtConspAmt_'.$i])."')";
		}
		mysql_query($sql3) or die($sql3);
		mysql_query("commit");
	}
	
	$sql11 = "insert into coa_master_bod_slave2 (COAID, CVE, ILOHC) values ('".$coaid."','".$this->getCheckNullValue(trim($_REQUEST['txtBODCVE']))."','".$this->getCheckNullValue(trim($_REQUEST['txtBODILOHC']))."')";
	mysql_query($sql11) or die($sql11);
	mysql_query("commit");	
	
	//2
	
	$redelbid = trim($_REQUEST['txtRedelbid']);
	for($i = 1; $i<=$redelbid; $i++){
		if(isset($_REQUEST['txtRedelBunkerID_'.$i])){
			$sql4 = "insert into coa_master_bctr_slave3 (COAID, BUNKERGRADID, QUANTITY_MT, PRICE_USD_MT, AMOUNT) values ('".$coaid."','".$_REQUEST['txtRedelBunkerID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtRedelConspQtyMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRedelPrice_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRedelConspAmt_'.$i])."')";
		}
		mysql_query($sql4) or die($sql4);
		mysql_query("commit");
	}
	
	$sql12 = "insert into coa_master_bctr_slave3 (COAID, CVE) values ('".$coaid."','".$this->getCheckNullValue(trim($_REQUEST['txtBCTRVE']))."')";
	mysql_query($sql12) or die($sql12);
	mysql_query("commit");
	
	//3
	
	$onRedelbid = trim($_REQUEST['txtOnRedelbid']);
	for($i = 1; $i<=$onRedelbid; $i++){
		if(isset($_REQUEST['txtOnRedelBunkerID_'.$i])){
			$sql5 = "insert into coa_master_bor_slave4 (COAID, BUNKERGRADID, QUANTITY_MT, PRICE_USD_MT, AMOUNT) values ('".$coaid."','".$_REQUEST['txtOnRedelBunkerID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtOnRedelConspQtyMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOnRedelPrice_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOnRedelConspAmt_'.$i])."')";
		}
		
		mysql_query($sql5) or die($sql5);
		mysql_query("commit");
	}
	
	$sql15 = "insert into coa_master_bor_slave4 (COAID, CVE) values ('".$coaid."','".$this->getCheckNullValue(trim($_REQUEST['txtBORCVE']))."')";
	mysql_query($sql15) or die($sql15);	
	mysql_query("commit");
	
	return $msg; 
}



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


function getUserAuthenticationModuleWiseForMainMenu($moduleid)
{
	$connect = $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)
{
	$connect = $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)
{
	$connect = $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)
{
	$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 insertCOADetails()
{
	$connect 				= $this->funConnect();
	$selCargoType 			= addslashes(trim($_REQUEST['selCargoType']));
	$selVCType 				= addslashes(trim($_REQUEST['selVCType']));
	$coa_no 				= addslashes(trim($_REQUEST['txtCOANo']));
	$coa_date 				= date("Y-m-d",strtotime($_REQUEST['txtCOADate']));
	$cargo_qty 				= addslashes(trim($_REQUEST['txtCQty']));
	$owner 					= addslashes(trim($_REQUEST['selOwner']));
	$broker 				= addslashes(trim($_REQUEST['selBroker']));
	$charterer				= addslashes(trim($_REQUEST['selCharterer']));
	$no_of_shipment 		= addslashes(trim($_REQUEST['txtNoofShipment']));
	$size_of_qty 			= addslashes(trim($_REQUEST['txtSQty']));
	$tolerance 				= addslashes(trim($_REQUEST['txtTolerance']));
	$shipment 				= addslashes(trim($_REQUEST['txtShipment']));
	$per 					= addslashes(trim($_REQUEST['txtper']));
	$start_date				= date("Y-m-d",strtotime($_REQUEST['txtStartDate']));
	$notice_days 			= addslashes(trim($_REQUEST['txtNotice']));
	$f_rate 				= addslashes(trim($_REQUEST['txtFRate']));
	$demu_rate 				= addslashes(trim($_REQUEST['txtDemuRate']));
	$dis_rate 				= addslashes(trim($_REQUEST['txtDisRate']));
	$add_comm 				= addslashes(trim($_REQUEST['txtAddComm']));
	$checkBAFbox 			= addslashes(trim($_REQUEST['checkBAFbox']));
	$b_price 				= addslashes(trim($_REQUEST['txtBPrice']));
	$baf_terms 				= addslashes(trim($_REQUEST['txtBAFTerms']));
	$inc_dec 				= addslashes(trim($_REQUEST['txtIncDec']));
	$remarks 				= addslashes(trim($_REQUEST['txtRemarks']));
	
	
	$selTCINOwner 			= addslashes(trim($_REQUEST['selTCINOwner']));
	$dailyHire 				= addslashes(trim($_REQUEST['txtDailyHire']));
	$dateOfDel				= $_REQUEST['txtDateOfDel'];
	$selDelPort 			= addslashes(trim($_REQUEST['selDelPort']));
	$dateOfReDel		 	= $_REQUEST['txtDateOfReDel'];
	$selReDelPort 			= addslashes(trim($_REQUEST['selReDelPort']));
	
	$upload1 = $this->getUpload($_FILES['fre_matrix']);
	$upload2 = $this->getUpload($_FILES['attach_file']);
	
	$msg = 0;
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	//insert query here.............
	$sql = "insert into coa_master (COA_NO,COA_DATE,MODULEID,MCOMPANYID,CARGO_QTY,OWNER,BROKER,CHARTERER,NO_OF_SHIPMENT,SIZE_OF_QTY,TOLERANCE,SHIPMENT,PER_MONTH,START_DATE,NOTICE_DAYS,FREIGHT_RATE,FREIGHT_MATRIX_UPLOAD,DEMURRAGE_RATE,DISPATCH_RATE,ADD_COMM,BAF,BUNKER_PRICE,BAF_TERMS,INCREASE_DECREASE,REMARKS,UPLOAD_FILE, CARGOTYPEID,VESSEL_CATEGORY_ID,STATUS,TC_IN_OWNERS,DAILY_HIRE_USD,DATE_OF_DEL,PORT_OF_DEL,DATE_OF_RE_DEL,PORT_OF_RE_DEL) values ('".$coa_no."','".$coa_date."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$cargo_qty."','".$owner."','".$broker."','".$charterer."','".$no_of_shipment."','".$size_of_qty."','".$tolerance."','".$shipment."','".$per."','".$start_date."','".$notice_days."','".$f_rate."','".$upload1."','".$this->getCheckNullValue($demu_rate)."','".$this->getCheckNullValue($dis_rate)."','".$this->getCheckNullValue($add_comm)."','".$checkBAFbox."','".$b_price."','".$baf_terms."','".$inc_dec."','".$remarks."','".$upload2."', '".$selCargoType."', '".$selVCType."',1,'".$selTCINOwner."','".$this->getCheckNullValue($dailyHire)."','".$this->getCheckDateTimeNullValue($dateOfDel)."','".$selDelPort."','".$this->getCheckDateTimeNullValue($dateOfReDel)."','".$selReDelPort."')";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	
	$sql1 		= "select max(COAID) as max from coa_master";
	$res1		= mysql_query($sql1) or die($sql1);
	$rows1 		= mysql_fetch_assoc($res1);
	$coaid 		= $rows1['max'];
	
	$ofhireId 	=  trim($_REQUEST['txtOFFID']);
	for($i = 1; $i<=$ofhireId; $i++){
		if(isset($_REQUEST['txtOffHireReason_'.$i])){
			$sql2 = " insert into coa_master_hire_slave1 (COAID, OFF_HIRE_REASON, OFF_HIRE_FROM_DATE, OFF_HIRE_TO_DATE) values ('".$coaid."','".$_REQUEST['txtOffHireReason_'.$i]."','".$this->getCheckDateTimeNullValue($_REQUEST['txtFromOff_'.$i])."','".$this->getCheckDateTimeNullValue($_REQUEST['txtToOff_'.$i])."')";
		}		
		mysql_query($sql2) or die($sql2);
		mysql_query("commit");
	}
	//1
	
	$bid = trim($_REQUEST['txtbid']);
	for($i = 1; $i<=$bid; $i++){
		
		if(isset($_REQUEST['txtBunkerID_'.$i])){		
		$sql3 = "insert into coa_master_bod_slave2 (COAID, BUNKERGRADID, QUANTITY_MT, PRICE_USD_MT, AMOUNT) values ('".$coaid."','".$_REQUEST['txtBunkerID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtConspQtyMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPrice_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtConspAmt_'.$i])."')";
		}
		mysql_query($sql3) or die($sql3);
		mysql_query("commit");
	}
	
	$sql11 = "insert into coa_master_bod_slave2 (COAID, CVE, ILOHC) values ('".$coaid."','".$this->getCheckNullValue(trim($_REQUEST['txtBODCVE']))."','".$this->getCheckNullValue(trim($_REQUEST['txtBODILOHC']))."')";
	mysql_query($sql11) or die($sql11);
	mysql_query("commit");	
	
	//2
	
	$redelbid = trim($_REQUEST['txtRedelbid']);
	for($i = 1; $i<=$redelbid; $i++){
		if(isset($_REQUEST['txtRedelBunkerID_'.$i])){
			$sql4 = "insert into coa_master_bctr_slave3 (COAID, BUNKERGRADID, QUANTITY_MT, PRICE_USD_MT, AMOUNT) values ('".$coaid."','".$_REQUEST['txtRedelBunkerID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtRedelConspQtyMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRedelPrice_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtRedelConspAmt_'.$i])."')";
		}
		mysql_query($sql4) or die($sql4);
		mysql_query("commit");
	}
	
	$sql12 = "insert into coa_master_bctr_slave3 (COAID, CVE) values ('".$coaid."','".$this->getCheckNullValue(trim($_REQUEST['txtBCTRVE']))."')";
	mysql_query($sql12) or die($sql12);
	mysql_query("commit");
	
	//3
	
	$onRedelbid = trim($_REQUEST['txtOnRedelbid']);
	for($i = 1; $i<=$onRedelbid; $i++){
		if(isset($_REQUEST['txtOnRedelBunkerID_'.$i])){
			$sql5 = "insert into coa_master_bor_slave4 (COAID, BUNKERGRADID, QUANTITY_MT, PRICE_USD_MT, AMOUNT) values ('".$coaid."','".$_REQUEST['txtOnRedelBunkerID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtOnRedelConspQtyMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOnRedelPrice_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOnRedelConspAmt_'.$i])."')";
		}
		
		mysql_query($sql5) or die($sql5);
		mysql_query("commit");
	}
	
	$sql15 = "insert into coa_master_bor_slave4 (COAID, CVE) values ('".$coaid."','".$this->getCheckNullValue(trim($_REQUEST['txtBORCVE']))."')";
	mysql_query($sql15) or die($sql15);	
	mysql_query("commit");
	
	return $msg; 
}

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 getCargoTypeDataBaseOnCargoId($cargoTypeId,$field)
{
	$connect = $this->funConnect();
	$query 	 = "select $field from cargotype_master where STATUS=1 and  CARGOTYPEID='".$cargoTypeId."' ";
	$result	 = mysql_query($query);
	$rows    = mysql_fetch_assoc($result);
	return   $rows[$field];
}

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();
	$query 	 = mysql_query("select * from vendor_master where STATUS=1 and VENDOR_TYPEID=".$id." 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($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."' and STATUS=1";
	$result  = mysql_query($sql);
	while ($rows = mysql_fetch_assoc($result)) 
	{
		$this->var_1 = $rows['COA_NO'];
		$this->var_2 = $rows['COA_DATE'];
		$this->var_3 = $rows['CARGO_QTY'];
		$this->var_4 = $rows['OWNER'];
		$this->var_5 = $rows['BROKER'];
		$this->var_6 = $rows['CHARTERER'];
		$this->var_7 = $rows['NO_OF_SHIPMENT'];
		$this->var_8 = $rows['SIZE_OF_QTY'];
		$this->var_9 = $rows['TOLERANCE'];
		$this->var_10 = $rows['SHIPMENT'];
		$this->var_11 = $rows['PER_MONTH'];
		$this->var_12 = $rows['START_DATE'];
		$this->var_13 = $rows['NOTICE_DAYS'];
		$this->var_14 = $rows['FREIGHT_RATE'];
		$this->var_15 = $rows['FREIGHT_MATRIX_UPLOAD'];
		$this->var_16 = $rows['DEMURRAGE_RATE'];
		$this->var_17 = $rows['DISPATCH_RATE'];
		$this->var_18 = $rows['ADD_COMM'];
		$this->var_19 = $rows['BAF'];
		$this->var_20 = $rows['BUNKER_PRICE'];
		$this->var_21 = $rows['BAF_TERMS'];
		$this->var_22 = $rows['INCREASE_DECREASE'];
		$this->var_23 = $rows['REMARKS'];
		$this->var_24 = $rows['UPLOAD_FILE'];
		$this->var_25 = $rows['CARGOTYPEID'];
		$this->var_26 = $rows['VESSEL_CATEGORY_ID'];
		$this->var_27 = $rows['UPLOAD_FILE_NAME'];
		$this->var_28 = $rows['COAID'];
				
		$this->var_29 = $rows['TC_IN_OWNERS'];
		$this->var_30 = $rows['DAILY_HIRE_USD'];
		$this->var_31 = $rows['DATE_OF_DEL'];
		$this->var_32 = $rows['PORT_OF_DEL'];
		$this->var_33 = $rows['DATE_OF_RE_DEL'];
		$this->var_34 = $rows['PORT_OF_RE_DEL'];
		
	}	
	
}


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 getVesselIMOData($id,$field)
{
	$connect = $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)
{
	$connect = $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()
{
	$this->funConnect();
	$query = mysql_query("select * from vessel_allocation_master WHERE MCOMPANYID='".$_SESSION['company']."' order by ALLOCATEID ");
	echo "<option value = '' >---Select from list---</option>";
	@$selVName = @$_REQUEST['selVName'];
	while($rows = mysql_fetch_assoc($query))
	{
		 $arr = array();
		 $arr = explode(",",$rows['MODULE_ID']);
		 if(in_array($_SESSION['moduleid'],$arr))
		 {
			 $key= $rows['VESSEL_IMO_ID'];
			 $value= $this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME");
			 $ttl_arr[] = array($key,$value);
		 }
	}
	$ttl_arr = $this->msort_ascending($ttl_arr, array('1','0'));
	for($i=0;$i<count($ttl_arr);$i++)
	{
		 $key= $ttl_arr[$i][0];
		 $value= $ttl_arr[$i][1];
		 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 getCOAList()
{
	$connect = $this->funConnect();
	$query 	 = mysql_query("select * from coa_master WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and 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()
{
	$connect = $this->funConnect();
	$query 	 = mysql_query("select * 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()
{
	$connect = $this->funConnect();
	$query 	 = mysql_query("select * from open_vessel_entry_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and 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();
	$contract_id 			= addslashes(trim($_REQUEST['txtCID']));
	$material_type			= addslashes(trim($_REQUEST['selMType']));
	$material_code			= addslashes(trim($_REQUEST['txtMCode']));
	$qty					= addslashes(trim($_REQUEST['txtQty']));
	$uom			 		= "MT";
	$load_port	 			= addslashes(trim($_REQUEST['selLPort']));
	$dis_port 				= addslashes(trim($_REQUEST['selDPort']));
	$from_date 				= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	$to_date 				= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	$tolerance				= addslashes(trim($_REQUEST['txtTolerance']));
	$vessel_id	 			= addslashes(trim($_REQUEST['selVOPID']));
	
	$shipper	 			= addslashes(trim($_REQUEST['selShipper']));
	$vessel_category		= addslashes(trim($_REQUEST['selVCType']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$mysql = "select * from open_cargo_master where CONTRACTID='".$contract_id."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' ";
	$myres = mysql_query($mysql) or die($mysql);
	$myrec = mysql_num_rows($myres);
	if($myrec == 0)
	{
	//insert query here.............
	$sql = "insert into open_cargo_master (CONTRACTID,CONTRACT_TYPE,MATERIAL_TYPE,MATERIAL_CODE,MATERIAL_QUANTITY,UOM,LOADPORT,DISPORT,LAYCAN_START,LAYCAN_FINISH,MODULEID,MCOMPANYID,TOLERANCE,OPENVESSEL_ID,VESSEL_CATEGORY,SHIPPER) values ('".$contract_id."','ZBP1','".$material_type."','".$material_code."','".$qty."','".$uom."','".$load_port."','".$dis_port."','".$from_date."','".$to_date."','".$_SESSION['moduleid']."','".$_SESSION['company']."', '".$tolerance."', '".$vessel_id."', '".$vessel_category."', '".$shipper."')";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$sql1 = "update open_vessel_entry_master set VESSEL_STATUS='1' where OPENVESSEL_ID='".$vessel_id."'";
	mysql_query($sql1) or die($sql1);
	mysql_query("commit");
	
	return $msg; 
	}
	else
	{
		return 3;
	}
}

function displayCargoOpenEntryList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="apen_cargo_position_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th width="9%"  >Contract ID</th>';
	echo '<th width="10%"  >Material Desc</th>';
	echo '<th width="10%"  >Material Qty</th>';
	echo '<th width="9%"  >Load Port</th>';
	echo '<th width="9%"  >Dis Port</th>';
	echo '<th width="10%"  >Date Range</th>';
	echo '<th width="10%"  >Open Vessel</th>';
	echo '<th width="7%" >Details</th>';
	echo '<th width="11%" >Nominate</th>';
	echo '</tr>';
	echo '</thead>';
	
	$sql = "select * from open_cargo_master where CONTRACT_TYPE in ('ZBP1') AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' AND STATUS=1 AND MAP_STATUS=1 and PUSH_STATUS=0 ORDER BY OPEN_CARGOID desc";
	
	$res = mysql_query($sql) or die($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>'.$rows['CONTRACTID'].'</td>';			
				echo '<td>'.$this->getMaterialCodeDesBasedOnCode($rows['MATERIAL_CODE']).'</td>';
				echo '<td>'.$rows['MATERIAL_QUANTITY'].' ('.$rows['UOM'].')</td>';
				echo '<td>'.$this->getPortNameBasedOnCode($rows['LOADPORT']).'</td>';
				echo '<td>'.$this->getPortNameBasedOnCode($rows['DISPORT']).'</td>';
				echo '<td>'.date("d-m-Y",strtotime($rows['LAYCAN_START'])).'</br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To </br>'.date("d-m-Y",strtotime($rows['LAYCAN_FINISH'])).'</td>';
				if($rows['OPENVESSEL_ID'] == 0)
				{
					echo '<td align="left" style="color:red;">TBN</td>';
				}
				else
				{
					echo '<td style="color:red;">'.$this->getVesselIMOData($this->getVesselOpenEntryDeta($rows['OPENVESSEL_ID'],"VESSEL_IMO_ID"),"VESSEL_NAME").'</br> ('.date("d-m-Y",strtotime($this->getVesselOpenEntryDeta($rows['OPENVESSEL_ID'],"FROM_DATE"))).' </br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to </br>'.date("d-m-Y",strtotime($this->getVesselOpenEntryDeta($rows['OPENVESSEL_ID'],"TO_DATE"))).')</td>';
				}
				
				echo '<td><a href="updateCargoOpenPosition.php?id='.$rows['OPEN_CARGOID'].'" title="Edit Details" ><i class="fa fa-edit "></i></a>&nbsp;|&nbsp;<a href="#Remove" title="Remove Details" onclick="return getDelete('.$rows['OPEN_CARGOID'].');" ><i class="fa fa-times" style="color:red;"></i></a></td>';
				//
				echo '<td align="center"><button type="button" class="btn btn-primary btn-small" onclick="getNominate('.$rows['OPEN_CARGOID'].','.$rows['OPENVESSEL_ID'].');">Nominate</button></td>';
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

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

function deleteCargoEntry($cargoid)
{
	$connect = $this->funConnect();
	$msg = 4;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$open_vessel_id = $this->getOpenCargoPositionData($cargoid,"OPENVESSEL_ID");
	
	$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");		
		
	$sql1 = "update open_vessel_entry_master set VESSEL_STATUS='0' where OPENVESSEL_ID='".$open_vessel_id."'";
	mysql_query($sql1);
	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['CONTRACTID'];
		$this->var_2 = $rows['COA_SPOT'];
		$this->var_3 = $rows['OWNER'];
		$this->var_4 = $rows['COA_NO'];
		$this->var_5 = $rows['MATERIAL_TYPE'];
		$this->var_6 = $rows['MATERIAL_CODE'];
		$this->var_7 = $rows['MATERIAL_QUANTITY'];
		$this->var_8 = $rows['UOM'];
		$this->var_9 = $rows['LOADPORT'];
		$this->var_10 = $rows['DISPORT'];
		$this->var_11 = $rows['LAYCAN_START'];
		$this->var_12 = $rows['LAYCAN_FINISH'];
		$this->var_13 = $rows['TOLERANCE'];
		$this->var_14 = $rows['OPENVESSEL_ID'];
		$this->var_15 = $rows['VESSEL_CATEGORY'];
		$this->var_16 = $rows['SHIPPER'];
	}
}

function updateCargoOpenPositionDetails()
{
	$connect 				= $this->funConnect();
	$id 					= $_REQUEST['id'];
	$contract_id 			= addslashes(trim($_REQUEST['txtCID']));
	$material_type			= addslashes(trim($_REQUEST['selMType']));
	$material_code			= addslashes(trim($_REQUEST['txtMCode']));
	$qty					= addslashes(trim($_REQUEST['txtQty']));
	$uom			 		= "MT";
	$load_port	 			= addslashes(trim($_REQUEST['selLPort']));
	$dis_port 				= addslashes(trim($_REQUEST['selDPort']));
	$from_date 				= date("Y-m-d",strtotime($_REQUEST['txtFDate']));
	$to_date 				= date("Y-m-d",strtotime($_REQUEST['txtTDate']));
	$tolerance				= addslashes(trim($_REQUEST['txtTolerance']));
	$vessel_id	 			= addslashes(trim($_REQUEST['selVOPID']));
	
	$shipper	 			= addslashes(trim($_REQUEST['selShipper']));
	$vessel_category		= addslashes(trim($_REQUEST['selVCType']));
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$open_vessel_id = $this->getOpenCargoMasterDataBasedOnContractID($contract_id,"OPENVESSEL_ID");
	
	$sql = "update open_cargo_master set MATERIAL_TYPE='".$material_type."',MATERIAL_CODE='".$material_code."',MATERIAL_QUANTITY='".$qty."',UOM='".$uom."',LOADPORT='".$load_port."',DISPORT='".$dis_port."',LAYCAN_START='".$from_date."',LAYCAN_FINISH='".$to_date."',TOLERANCE='".$tolerance."',OPENVESSEL_ID= '".$vessel_id."',VESSEL_CATEGORY='".$vessel_category."',SHIPPER='".$shipper."'  WHERE MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and OPEN_CARGOID='".$id."'";
	
	mysql_query($sql);
	mysql_query("commit");
	
	$sql1 = "update open_vessel_entry_master set VESSEL_STATUS='0' where OPENVESSEL_ID='".$open_vessel_id."'";
	mysql_query($sql1);
	
	$sql2 = "update open_vessel_entry_master set VESSEL_STATUS='1' where OPENVESSEL_ID='".$vessel_id."'";
	mysql_query($sql2);
	
	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)
{
	$connect = $this->funConnect();
	$query   = mysql_query("select * from open_vessel_entry_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and 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($mappingid)
{
	$connect = $this->funConnect();
	$sql 	 = mysql_query("select * from nom_details where MAPPINGID='".$mappingid."'");
	$rec 	 = mysql_num_rows($sql);
	
	$sql1 	 = mysql_query("select * from tc_cp_terms where MAPPINGID='".$mappingid."'");
	$rec1 	 = mysql_num_rows($sql1);
	
	if($rec != 0 && $rec1 != 0 ){
		return 1;
	}else{
		return 0;
	}
}


function getAllStandardsValues($mappingid)
{
	$connect = $this->funConnect();
	$sql 	 = mysql_query("select * from mapping_standards where MAPPINGID='".$mappingid."'");
	$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($mappingid,$sheet_no)
{
	$connect = $this->funConnect();
	$sql 	 = "select FIXTURETYPEID 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);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows['FIXTURETYPEID'];
}


function getFreightEstimationStatusForAll($mappingid)
{
	$connect = $this->funConnect();
	$sql 	 = "select VOY_EST_STATUS 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);
	$val 	 = 0;
	while($rows = mysql_fetch_assoc($res))
	{
		if($rows['VOY_EST_STATUS'] == 2)
		{
			$arr[] = $rows['VOY_EST_STATUS'];
		}
	}
	$val = count($arr);
	return $val;
}


function getBusinessTypeBasedOnID($id)
{
	$connect = $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 displayFleetlList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="fleet_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="20%">Vessel Type</th>';
	echo '<th align="left" valign="middle" width="20%">Vessel</th>';
	echo '<th align="left" valign="middle" width="20%">Built</th>';
	echo '<th align="center" valign="middle" width="15%">Vessel Particulars</th>';
	echo '<th align="center" valign="middle" width="10%">Commercial Parameters</th>';
	echo '</tr>';
	echo '</thead>';
	$sql = "SELECT * FROM vessel_allocation_master WHERE MCOMPANYID='".$_SESSION['company']."' order by ALLOCATEID";
	$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();
				$arr = explode(",",$rows['MODULE_ID']);
				if(in_array($_SESSION['moduleid'],$arr))
				{
					echo '<tr>';
					echo '<td align="center">'.$i.'.</td>';
					echo '<td align="left">'.$this->getVesselTypeBasedOnID($this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_TYPE")).'</td>';
					echo '<td align="left">'.strtoupper($this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME")).'</td>';
					echo '<td align="left">'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"YEARBUILT").'</td>';
					
					echo '<td align="center"><a class="fa fa-file-text-o" href="view_vessel.php?id='.$rows['VESSEL_IMO_ID'].'" title="View Vessel Particulars" ></a>&nbsp; | &nbsp;<a class="fa fa-edit" href="update_vessel.php?id='.$rows['VESSEL_IMO_ID'].'" title="Edit Vessel Particulars" ></td>';
					
					echo '<td align="center"><a class="fa fa-edit" href="commercial_parameter.php?id='.$rows['VESSEL_IMO_ID'].'" title="Commercial Parameters" ></td>';	
					echo '</tr>';
					
					$i++;
				}
			}
		echo '</tbody>';
		}
	echo '</table></div>';
}


function getVesselTypeBasedOnID($id)
{
	$connect = $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']); 
	
	//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) 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."')";
	//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) or die($sql1);
	$rows1 		= mysql_fetch_assoc($res1);
	
	$id 		= $rows1['max'];
	$tabid 		= count($_REQUEST['txttabid']); 
	$txtTID 	= $_REQUEST['txtTID']; 

		
	for($i=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) or die($sql2);
			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'];	
	}
}



function updateVesselOpenPositionDetails()
{
	$connect 			= $this->funConnect();
	$id 				= addslashes(trim($_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 = $this->getUpload($_FILES['attach_file']);
	
	$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='".$upload."',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");
	
	$dsql = "delete from open_vessel_entry_disponent_owner where OPENVESSEL_ID='".$id."'";
	mysql_query($dsql);
	mysql_query("commit");
	
	$txtTID 	= $_REQUEST['txtTID'];
		
	for($i=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);
			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($mappingid)
{
	$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 MAPPINGID='".$mappingid."'";
	$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 getMappingData($id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from mapping_master where MAPPINGID='".$id."' and MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}



function insertStandardsDetails()
{
	$connect 	= $this->funConnect();
	$mappingid  = $_REQUEST['mappingid'];
	$rec	    = $_REQUEST['txtRec'];
	
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$query = "delete from mapping_standards where MAPPINGID='".$mappingid."'";
	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 (MAPPINGID,APPROVALID,APPROVAL_STATUS,DATE,REMARKS) values ('".$mappingid."','".$_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)
{
	$connect = $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()
{
	$connect = $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 MAPPINGID='".$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"))." (".$cargoids.")";
	}
}


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($mappingid,$vessel_id,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select ".$field." from commercial_parameters_nomnation_wise where MAPPINGID='".$mappingid."' 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()
{
	$connect = $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()
{
	$connect = $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] == ""){
		return $rows = "0000-00-00";
	}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();
	$mappingid          	= $_REQUEST['mappingid'];
	$fixture_type           = addslashes(trim($_REQUEST['selFixtureType']));
	$charterer		        = addslashes(trim($_REQUEST['txtCharterer']));
	$fri_rate		        = addslashes(trim($_REQUEST['txtFRUsdMT']));
	$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']));
	if($_REQUEST['txtAlarm']!=""){$alarm= addslashes(trim($_REQUEST['txtAlarm']));}else{$alarm= "";}
	
	$broker		            = addslashes(trim($_REQUEST['txtBroker']));
		
	$msg = 0;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
		//echo $cp_date;die();
	$sql = "select * from nom_details where MAPPINGID='".$mappingid."'";
	$res = mysql_query($sql);
	$rec = mysql_num_rows($res);
	if($rec == 0)
	{
		//insert query.......
		$sql1 = "insert into nom_details (MAPPINGID,FIXTURETYPE_ID,CHARTERER,FREIGHT_RATE,CP_REF,CP_DATE,LAYCAN_STARTS,LAYCAN_FINISHES,ALARM,DATE_OF_DELIVERY,PLACE_OF_DELIVERY,BROKER) values ('".$mappingid."','".$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 MAPPINGID='".$mappingid."'";
		mysql_query($sql1) or die($sql1);
		mysql_query("commit");
	}

	return $msg; 
}



function insertTC_CP_TERMS_Details()
{
	$connect 				= $this->funConnect();
	$mappingid          	= $_REQUEST['mappingid'];
	$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 (MAPPINGID, 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 ('".$mappingid."','".$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 MAPPINGID='".$mappingid."'";
		
		mysql_query($sql1);
		mysql_query("commit");
	}
	return $msg; 
}



function insertVesselCommercialParametersDetailsNominationWise($submitid)
{
	$connect 				= $this->funConnect();
	$mappingid 				= $_REQUEST['mappingid'];
	$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 MAPPINGID='".$mappingid."' 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 (MAPPINGID,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 ('".$mappingid."','".$_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 insertPdfDetails($mappingid)
{
	$connect				= $this->funConnect();
	$user_file_name 			= addslashes(trim($_REQUEST['txtFile']));
	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");
	$sql = "insert into cp_pdf_details (MAPPINGID, FILE_NAME, USER_FILE_NAME) values ('".$mappingid."', '".$filename."', '".$user_file_name."')";
	mysql_query($sql);
	mysql_query("commit");
	return $msg; 
}


function deletePdfDetails($mappingid,$file_name)
{
	$connect				= $this->funConnect();
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 6;	
	$sql = "delete from cp_pdf_details where MAPPINGID='".$mappingid."' 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>#</th>';
	echo '<th>Voyage Financials Name</th>';
	echo '<th align="center">Voyage Financials View</th>';
	echo '<th align="center">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>'.$i.'.</td>';
				echo '<td>'.$rows['ESTIMATION_NO'].'</td>';
				if($this->getCostSheetDataBasedOnID($rows['SHEET_NO'],"PROCESS") == "EST")
				{
					if($_SESSION['company'] == 2)
					{
						echo '<td align="center"><a href="./view_cost_sheet_lpg.php?mappingid='.$mappingid.'&cost_sheet_id='.$rows['SHEET_NO'].'&page='.$page.'">View</a></td>';
					}
					else
					{
						echo '<td align="center"><a href="./view_cost_sheet.php?mappingid='.$mappingid.'&cost_sheet_id='.$rows['SHEET_NO'].'&page='.$page.'">View</a></td>';
					}
				}
				else
				{
					if($_SESSION['company'] == 2)
					{
						echo '<td align="center"><a href="./view_cost_sheet_actual_lpg.php?mappingid='.$mappingid.'&cost_sheet_id='.$rows['SHEET_NO'].'&page='.$page.'">View</a></td>';
					}
					else
					{
						echo '<td align="center"><a href="./view_cost_sheet_actual.php?mappingid='.$mappingid.'&cost_sheet_id='.$rows['SHEET_NO'].'&page='.$page.'">View</a></td>';
					}
				}
				if($this->getFinalCostSheetDataRec($mappingid) == 0){
				echo '<td align="center"><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">'.$value.'</td>';
				}
				echo '</tr>';
				$i++;
		}
		echo '<tr>';
		
			$uid	  = $_SESSION['uid'];
			$moduleid = $_SESSION['moduleid'];
			
			if($page == 1)
			{
				$linkid = 4;
			}
			else
			{
				$linkid = 5;
			}
			echo '<td colspan="4" valign="middle" align="right">';
				if($this->getFinalCostSheetDataRec($mappingid) == 0){
					echo '<button class="btn btn-primary btn-flat" id="inner-login-button" type="submit" onclick="return getValidate();">Confirm Final Estimated Cost Sheet</button><input type="hidden" name="action" value="submit" />';
				}
			echo '</td>';
		echo '</tr>';
	echo '</tbody>';
	}
	echo '</table>';
	echo "</div>";
}


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 getCheckNullValue($var){
	
	if($var == ""){
		return 0;
	}else{
		return $var;
	}
}

function getCheckDateNullValue($var){
	
	if($var == ""){
		return '0000-00-00';
	}else{
		return date("Y-m-d",strtotime($var));
	}
}

function getCheckDateTimeNullValue($var){
	
	if($var == ""){
		return '0000-00-00 00:00:00';
	}else{
		return date("Y-m-d H:i:s",strtotime($var));
	}
}

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']));
	$lumpsum	 			= addslashes(trim($_REQUEST['txtMLumpsum']));
	$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(PROCESSID + 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."','".$this->getCheckNullValue($qrows['max'])."','".$estmation_no."','".$cap_rdo."','".$this->getCheckNullValue($grain_cap)."','".$this->getCheckNullValue($bale_cap)."','".$this->getCheckNullValue($sf)."','".$voyage_no."','".$tc_no."','".$market_rdo."','".$this->getCheckNullValue($cost_usd_mt)."','".$this->getCheckNullValue($lumpsum)."','".$this->getCheckNullValue($cargo_qty)."','".$cargo_type_id."','".$this->getCheckNullValue($ttl_voyage_time)."','".$this->getCheckNullValue($ttl_voyage_days)."','".$this->getCheckNullValue($ttl_fo_consp)."','".$this->getCheckNullValue($ttl_do_consp)."','".$dwt_rdo."','".$this->getCheckNullValue($summer_dwt)."','".$this->getCheckNullValue($tropical_dwt)."','".$this->getCheckNullValue($loadable)."','".$cost_sheet_id."','".$addnl_rate."','".$this->getCheckNullValue($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]."','".$this->getCheckNullValue($_REQUEST['txtLpQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLpRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLpBLWorkDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPPCosts_'.$i])."')";	 
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
			
			 $query1 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Load', '".$_REQUEST['txtLoadPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCLPVendorList_'.$i])."')";
			mysql_query($query1) or die($query1);
			mysql_query("commit");
			
			/*$sql9 = "insert into fca_vci_shipowner (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Load', '".$_REQUEST['txtLoadPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtddswLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtddswLPCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDSOLPVendorList_'.$i])."')";
			mysql_query($sql9) or die($sql9);
			mysql_query("commit");*/
			
			/*$sql11 = "insert into fca_vci_dd_shipper (FCAID,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."' , '".$_REQUEST['txtLoadPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtddshipLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtddshipLPCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDSLPVendorList_'.$i])."')"; 
			mysql_query($sql11) or die($sql11);
			mysql_query("commit");*/
		}
	}
	
	//First Loop End 
	
	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]."','".$this->getCheckNullValue($_REQUEST['txtDpQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDpRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDpBLWorkDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPPCosts_'.$i])."')";	 
			mysql_query($sql3) or die($sql3);
			mysql_query("commit"); 
			
			$query2 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Discharge' , '".$_REQUEST['txtDisPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCDPVendorList_'.$i])."')";
			mysql_query($query2) or die($query2);
			mysql_query("commit");
			
			/*$sql10 = "insert into fca_vci_shipowner (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Discharge' , '".$_REQUEST['txtDisPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtddswDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtddswDPCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDSODPVendorList_'.$i])."')";
			mysql_query($sql10) or die($sql10);
			mysql_query("commit");*/
				
			/*$sql12 = "insert into fca_vci_dd_receiver (FCAID,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."' , '".$_REQUEST['txtDisPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDReceiDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDReceiDPCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDRDPVendorList_'.$i])."')";
			mysql_query($sql12) or die($sql12);
			mysql_query("commit");*/
		}
	}
	
	// Second Loop End
	
	$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,LP_VENDORID,DP_VENDORID) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdGF'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdGFMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdDF'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdDFMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAF'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAFMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdTF'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdTFMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjPerAC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdACMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjPerAgC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAgC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdFP'])."','".$this->getCheckNullValue($_REQUEST['txtTTLORCFP'])."','".$_REQUEST['selORCVList']."','".$this->getCheckNullValue($_REQUEST['txtTTLORCFPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRLPCost'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRLPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRDPCost'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRDPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLShippingCost'])."','".$this->getCheckNullValue($_REQUEST['txtTTLShippingCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCosts'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCostsMT'])."','".$this->getCheckNullValue($_REQUEST['selDDNRLPVendorList'])."','".$this->getCheckNullValue($_REQUEST['selDDNRDPVendorList'])."')";	
		mysql_query($sql4) or die($sql4);
		mysql_query("commit");
		
		$orc_id = $_REQUEST['txtORC_id'];
		if($orc_id > 0){
			for($i=1;$i<=$orc_id;$i++)
			{
				$sql10 = "insert into fca_vci_owner_related_cost (FCAID,OWNER_RCOSTID,AMOUNT,VENDORID) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtHidORCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtHidORCAmt_'.$i])."','".$this->getCheckNullValue($_REQUEST['selORCVList_'.$i])."')";
				mysql_query($sql10)or die($sql10);
				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,COST_MT,VENDORID) values ('".$maxid."' , '".$_REQUEST['txtHidOSCID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtOSCAbs_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selAOSCVendorList_'.$i])."')";
			mysql_query($sql7) or die($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,COST_MT,ADDCOMM,VENDORID) values ('".$maxid."' , '".$_REQUEST['txtHidOMCID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtOMCAbs_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOMCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOMCAbsComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['selAOMCVendorList_'.$i])."')"; 
			mysql_query($sql8) or die($sql8);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into fca_vci_brokage_commission (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtBrComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['selBroVList_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				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 viewFreightEstimationRecords($mappingid,$cost_sheet_id)
{
	$connect = $this->funConnect();
	$sql = "select * from freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and MAPPINGID='".$mappingid."' and SHEET_NO='".$cost_sheet_id."'";
	$result = mysql_query($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['VOY_EST_STATUS'];
		$this->var_5 = $rows['ESTIMATION_NO'];
		$this->var_6 = $rows['CAP_RDO'];
		$this->var_7 = $rows['GRAIN_CAP'];
		$this->var_8 = $rows['BALE_CAP'];
		$this->var_9 = $rows['SF'];
		$this->var_10 = $rows['VOYAGE_NO'];
		$this->var_11 = $rows['TC_NO'];
		$this->var_12 = $rows['MARKET_RDO'];
		$this->var_13 = $rows['COST_USD_MT'];
		$this->var_14 = $rows['LUMPSUM'];
		$this->var_15 = $rows['CARGO_QTY'];
		$this->var_16 = $rows['CARGO_TYPEID'];
		$this->var_17 = $rows['TTL_VOYAGE_TIME'];
		$this->var_18 = $rows['TTL_VOYAGE_DAYS'];
		$this->var_19 = $rows['TTL_FO_CONSP'];
		$this->var_20 = $rows['TTL_DO_CONSP'];
		
		$this->var_21 = $rows['DWT_RDO'];
		$this->var_22 = $rows['SUMMER_DWT'];
		$this->var_23 = $rows['TROPICAL_DWT'];
		$this->var_24 = $rows['LOADABLE'];
		
		$this->var_25 = $rows['ADDNL_CARGO_RATE'];
		$this->var_26 = $rows['ACTUAL_QTY'];
		$this->var_27 = $rows['DF_QTY'];
		$this->var_28 = $rows['ADDNL_QTY'];
		
		$this->var_29 = $rows['RDO_QTY'];
		$this->var_30 = $rows['FINAL_STATUS'];
	}
}


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


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 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.")";
		$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 updateVesselMainMaster()
{
	$connect = $this->funConnect();
	$id 	 = $_REQUEST['id'];
	
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;
	
	$sql11 = "delete from vessel_master_1 where VESSEL_IMO_ID=".$id;
	mysql_query($sql11);
	
	
	$dateOfChange = date("Y-m-d",strtotime($_REQUEST['txtDOC']));
	
	if($_REQUEST['txtDOC'] == ""){
		$dateOfChange1 = "0000-00-00";
	}else{
		$dateOfChange1 = $dateOfChange;
	}
	
	$dateICPADOS = date("Y-m-d",strtotime($_REQUEST['txtICPADOS_3']));
	
	if($_REQUEST['txtICPADOS_3'] == ""){
		$dateICPADOS1 = "0000-00-00";
	}else{
		$dateICPADOS1 = $dateICPADOS;
	}
	
	$sql = "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) 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']."')";
		
	mysql_query($sql) or die(mysql_error());
	
	mysql_query("commit"); 
	return $msg;
	
}

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 = "0000-00-00";
	}else{
		$DOLSS1 = $DOLSS;
	}
	
	$DOLAS = date("Y-m-d",strtotime($_REQUEST['txtDOLAS']));
	
	if(($_REQUEST['txtDOLAS']) == ""){
		$DOLAS1 = "0000-00-00";
	}else{
		$DOLAS1 = $DOLAS;
	}

	$DOLI = date("Y-m-d",strtotime($_REQUEST['txtDOLI']));
	
	if(($_REQUEST['txtDOLI']) == ""){
		$DOLI1 = "0000-00-00";
	}else{
		$DOLI1 = $DOLI;
	}
	
	$DONI = date("Y-m-d",strtotime($_REQUEST['txtDONI']));
	
	if(($_REQUEST['txtDONI']) == ""){
		$DONI1 = "0000-00-00";
	}else{
		$DONI1 = $DONI;
	}
	
	$Date_Dry = date("Y-m-d",strtotime($_REQUEST['txtDate_Dry']));
	
	if(($_REQUEST['txtDate_Dry']) == ""){
		$Date_Dry1 = "0000-00-00";
	}else{
		$Date_Dry1 = $Date_Dry;
	}
	
	$LAST_AUDIT = date("Y-m-d",strtotime($_REQUEST['txtLAST_AUDIT']));
	
	if(($_REQUEST['txtLAST_AUDIT']) == ""){
		$LAST_AUDIT1 = "0000-00-00";
	}else{
		$LAST_AUDIT1 = $LAST_AUDIT;
	}
	
	$NEXT_AUDIT = date("Y-m-d",strtotime($_REQUEST['txtNEXT_AUDIT']));
	
	if(($_REQUEST['txtNEXT_AUDIT']) == ""){
		$NEXT_AUDIT1 = "0000-00-00";
	}else{
		$NEXT_AUDIT1 = $NEXT_AUDIT;
	}
	
	$ADVISE_DATE = date("Y-m-d",strtotime($_REQUEST['txtADVISE_DATE']));
	
	if(($_REQUEST['txtADVISE_DATE']) == ""){
		$ADVISE_DATE1 = "0000-00-00";
	}else{
		$ADVISE_DATE1 = $ADVISE_DATE;
	}
	
	$DATE_SMC = date("Y-m-d",strtotime($_REQUEST['txtDATE_SMC']));
	
	if(($_REQUEST['txtDATE_SMC']) == ""){
		$DATE_SMC1 = "0000-00-00";
	}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++)
	{
		$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 = "0000-00-00";
		}else{
			$txtIDate1 = $txtIDate;
		}		
		
		//$txtLAIDate	=	addslashes(trim($_REQUEST['txtLAIDate_'.$j]));
		
		$txtLAIDate = date("Y-m-d",strtotime($_REQUEST['txtLAIDate_'.$j]));
		if(($_REQUEST['txtLAIDate_'.$j]) == ""){
			$txtLAIDate1 = "0000-00-00";
		}else{
			$txtLAIDate1 = $txtLAIDate;
		}
		
		
		//$txtEDate	=	addslashes(trim($_REQUEST['txtEDate_'.$j]));
		
		$txtEDate = date("Y-m-d",strtotime($_REQUEST['txtEDate_'.$j]));
		if(($_REQUEST['txtEDate_'.$j]) == ""){
			$txtEDate1 = "0000-00-00";
		}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) 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']))."')";
	
	
	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']));
 $bp_fo_fs    = addslashes(trim($_REQUEST['txtFOBPassageFS']));
 $bp_fo_es1    = addslashes(trim($_REQUEST['txtFOBPassageES1']));
 $bp_fo_es2    = addslashes(trim($_REQUEST['txtFOBPassageES2']));
 $lp_fo_fs    = addslashes(trim($_REQUEST['txtFOLPassageFS']));
 $lp_fo_es1    = addslashes(trim($_REQUEST['txtFOLPassageES1']));
 $lp_fo_es2    = addslashes(trim($_REQUEST['txtFOLPassageES2']));
 $pi_fo_fs    = addslashes(trim($_REQUEST['txtFOIPIdleFS']));
 //$pi_fo_es1   = addslashes(trim($_REQUEST['txtFOIPIdleES1']));
 //$pi_fo_es2   = addslashes(trim($_REQUEST['txtFOIPIdleES2']));
 $pw_fo_fs    = addslashes(trim($_REQUEST['txtFOIPWorkingFS']));
 //$pw_fo_es1   = addslashes(trim($_REQUEST['txtFOIPWorkingES1']));
 //$pw_fo_es2   = addslashes(trim($_REQUEST['txtFOIPWorkingES2']));
 $oth_fo_fs    = addslashes(trim($_REQUEST['txtFOOthersFS']));
 //$oth_fo_es1   = addslashes(trim($_REQUEST['txtFOOthersES1']));
 //$oth_fo_es2   = addslashes(trim($_REQUEST['txtFOOthersES2']));
 $bp_do_fs    = addslashes(trim($_REQUEST['txtDOBPassageFS']));
 $bp_do_es1    = addslashes(trim($_REQUEST['txtDOBPassageES1']));
 $bp_do_es2    = addslashes(trim($_REQUEST['txtDOBPassageES2']));
 $lp_do_fs    = addslashes(trim($_REQUEST['txtDOLPassageFS']));
 $lp_do_es1    = addslashes(trim($_REQUEST['txtDOLPassageES1']));
 $lp_do_es2    = addslashes(trim($_REQUEST['txtDOLPassageES2']));
 $pi_do_fs    = addslashes(trim($_REQUEST['txtDOIPIdleFS']));
 //$pi_do_es1   = addslashes(trim($_REQUEST['txtDOIPIdleES1']));
 //$pi_do_es2   = addslashes(trim($_REQUEST['txtDOIPIdleES2']));
 $pw_do_fs    = addslashes(trim($_REQUEST['txtDOIPWorkingFS']));
 //$pw_do_es1   = addslashes(trim($_REQUEST['txtDOIPWorkingES1']));
 //$pw_do_es2   = addslashes(trim($_REQUEST['txtDOIPWorkingES2']));
 $oth_do_fs    = addslashes(trim($_REQUEST['txtDOOthersFS']));
 //$oth_do_es1   = addslashes(trim($_REQUEST['txtDOOthersES1']));
 //$oth_do_es2   = addslashes(trim($_REQUEST['txtDOOthersES2']));
 $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 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...........
  echo $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,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,PW_FO_FULL_SPEED,OTH_FO_FULL_SPEED,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,PW_DO_FULL_SPEED,OTH_DO_FULL_SPEED,MODULEID,FO_GRADE,DO_GRADE,REMARKS) values ('".$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."','".$pw_fo_fs."','".$oth_fo_fs."','".$bp_do_fs."','".$bp_do_es1."','".$bp_do_es2."','".$lp_do_fs."','".$lp_do_es1."','".$lp_do_es2."','".$pi_do_fs."','".$pw_do_fs."','".$oth_do_fs."','".$_SESSION['moduleid']."','".$fo_grade."','".$do_grade."','".$remarks."')";
    
  mysql_query($sql) or die(mysql_error());
  mysql_query("commit");
 }else{
  
  //edit query..........
  $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."',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."',PW_FO_FULL_SPEED='".$pw_fo_fs."',OTH_FO_FULL_SPEED='".$oth_fo_fs."',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."',PW_DO_FULL_SPEED='".$pw_do_fs."',OTH_DO_FULL_SPEED='".$oth_do_fs."',FO_GRADE='".$fo_grade."',DO_GRADE='".$do_grade."',REMARKS='".$remarks."'  where COMMERCIAL_PARAMETERID='".$rows['COMMERCIAL_PARAMETERID']."' ";
  
  mysql_query($sql) or die(mysql_error());  
  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)
{
 $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'];
}

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

function getPortDistanceType()
{
$state = array( 1 =>'Shortest Distance (NM)' , 2 =>'250 nm Distance', 3 =>'600 nm Distance', 4 =>'Longest Distance (NM)');
$selDType = @$_REQUEST['selDType'];
//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 == $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 =>'Ech Speed 1' , 3 =>'Ech Speed 2');
$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 getOtherMiscCostNameBasedOnID($id)
{
	$connect				= $this->funConnect();
	$sql = "select * from other_misc_cost_master where OTHER_MCOSTID='".$id."' and MODULEID='".$_SESSION['moduleid']."'"; /*AND MCOMPANYID='".$_SESSION['company']."'";*/
	$res = mysql_query($sql);
	$rows = mysql_fetch_assoc($res);
	return $rows['NAME'];
}

function updateVCIDetails()
{
	
	$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']));
	$lumpsum	 			= addslashes(trim($_REQUEST['txtMLumpsum']));
	$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 FCAID from freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' and MAPPINGID='".$mappingid."' and SHEET_NO='".$cost_sheet_id."' and MCOMPANYID='".$_SESSION['company']."'"; 
	$result = mysql_query($query);
	$rows 	= mysql_fetch_assoc($result);
	$fca_id = $rows['FCAID'];
	
	//insert query here.............
	$sql = "update freight_cost_analysis_master set FIXTURETYPEID='".$fixture_type."',TRANS_DATE='".$date."',VOY_EST_STATUS='".$voyage_status."',ESTIMATION_NO='".$estmation_no."',CAP_RDO='".$cap_rdo."',GRAIN_CAP='".$this->getCheckNullValue($grain_cap)."',BALE_CAP='".$this->getCheckNullValue($bale_cap)."',SF='".$this->getCheckNullValue($sf)."',VOYAGE_NO='".$voyage_no."',TC_NO='".$tc_no."',MARKET_RDO='".$market_rdo."',COST_USD_MT='".$this->getCheckNullValue($cost_usd_mt)."',LUMPSUM='".$this->getCheckNullValue($lumpsum)."',CARGO_QTY='".$this->getCheckNullValue($cargo_qty)."',CARGO_TYPEID='".$cargo_type_id."',TTL_VOYAGE_TIME='".$this->getCheckNullValue($ttl_voyage_time)."',TTL_VOYAGE_DAYS= '".$this->getCheckNullValue($ttl_voyage_days)."',DWT_RDO='".$dwt_rdo."',SUMMER_DWT='".$this->getCheckNullValue($summer_dwt)."',TROPICAL_DWT='".$this->getCheckNullValue($tropical_dwt)."',LOADABLE='".$this->getCheckNullValue($loadable)."',ADDNL_CARGO_RATE='".$addnl_rate."',ACTUAL_QTY='".$this->getCheckNullValue($actual_qty)."',DF_QTY='".$df_qty."',ADDNL_QTY='".$addnl_qty."',RDO_QTY='".$rdoQty."'   where FCAID='".$fca_id."'"; 
		
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$maxid 			= $fca_id;
	
	$del_query1 	= "delete from  fca_vci_load_port where FCAID='".$maxid."'";
	$del_query2 	= "delete from  fca_vci_shipowner where FCAID='".$maxid."'";
	$del_query3 	= "delete from  fca_vci_dd_shipper where FCAID='".$maxid."'";
	$del_query4 	= "delete from  fca_vci_disch_port where FCAID='".$maxid."'";
	$del_query5 	= "delete from  fca_vci_dd_receiver where FCAID='".$maxid."'";
	$del_query6 	= "delete from  fca_vci_totals where FCAID='".$maxid."'";
	$del_query8 	= "delete from  fca_vci_other_shipping_cost where FCAID='".$maxid."'";
	$del_query9 	= "delete from  fca_vci_other_misc_cost where FCAID='".$maxid."'";
	$del_query10 	= "delete from  fca_vci_portcosts where FCAID='".$maxid."'";
	$del_query11 	= "delete from  fca_vci_owner_related_cost where FCAID='".$maxid."'";
	$del_query12 	= "delete from  fca_vci_brokage_commission where FCAID='".$maxid."'";
	
	mysql_query($del_query1);
	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("commit");
	
	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]."','".$this->getCheckNullValue($_REQUEST['txtLpQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLpRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLpBLWorkDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPPCosts_'.$i])."')";	 
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
			
			 $query1 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Load', '".$_REQUEST['txtLoadPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCLPVendorList_'.$i])."')";
			mysql_query($query1) or die($query1);
			mysql_query("commit");
			
			/*$sql9 = "insert into fca_vci_shipowner (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Load', '".$_REQUEST['txtLoadPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtddswLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtddswLPCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDSOLPVendorList_'.$i])."')";
			mysql_query($sql9) or die($sql9);
			mysql_query("commit");*/
			
			/*$sql11 = "insert into fca_vci_dd_shipper (FCAID,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."' , '".$_REQUEST['txtLoadPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtddshipLPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtddshipLPCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDSLPVendorList_'.$i])."')"; 
			mysql_query($sql11) or die($sql11);
			mysql_query("commit");*/
		}
	}
	
	//First Loop End 
	
	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]."','".$this->getCheckNullValue($_REQUEST['txtDpQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDpRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDpBLWorkDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPPCosts_'.$i])."')";	 
			mysql_query($sql3) or die($sql3);
			mysql_query("commit"); 
			
			$query2 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Discharge' , '".$_REQUEST['txtDisPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCDPVendorList_'.$i])."')";
			mysql_query($query2) or die($query2);
			mysql_query("commit");
			
			/*$sql10 = "insert into fca_vci_shipowner (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Discharge' , '".$_REQUEST['txtDisPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtddswDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtddswDPCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDSODPVendorList_'.$i])."')";
			mysql_query($sql10) or die($sql10);
			mysql_query("commit");*/
				
			/*$sql12 = "insert into fca_vci_dd_receiver (FCAID,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."' , '".$_REQUEST['txtDisPort_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtDDReceiDPCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDReceiDPCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDRDPVendorList_'.$i])."')";
			mysql_query($sql12) or die($sql12);
			mysql_query("commit");*/
		}
	}
	
	// Second Loop End
	
	$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,LP_VENDORID,DP_VENDORID) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdGF'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdGFMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdDF'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdDFMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAF'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAFMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdTF'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdTFMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjPerAC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdACMT'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjPerAgC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAgC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdFP'])."','".$this->getCheckNullValue($_REQUEST['txtTTLORCFP'])."','".$_REQUEST['selORCVList']."','".$this->getCheckNullValue($_REQUEST['txtTTLORCFPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRLPCost'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRLPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRDPCost'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRDPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLShippingCost'])."','".$this->getCheckNullValue($_REQUEST['txtTTLShippingCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCosts'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCostsMT'])."','".$this->getCheckNullValue($_REQUEST['selDDNRLPVendorList'])."','".$this->getCheckNullValue($_REQUEST['selDDNRDPVendorList'])."')";	
		mysql_query($sql4) or die($sql4);
		mysql_query("commit");
		
		$orc_id = $_REQUEST['txtORC_id'];
		if($orc_id > 0){
			for($i=1;$i<=$orc_id;$i++)
			{
				$sql10 = "insert into fca_vci_owner_related_cost (FCAID,OWNER_RCOSTID,AMOUNT,VENDORID) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtHidORCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtHidORCAmt_'.$i])."','".$this->getCheckNullValue($_REQUEST['selORCVList_'.$i])."')";
				mysql_query($sql10)or die($sql10);
				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,COST_MT,VENDORID) values ('".$maxid."' , '".$_REQUEST['txtHidOSCID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtOSCAbs_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selAOSCVendorList_'.$i])."')";
			mysql_query($sql7) or die($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,COST_MT,ADDCOMM,VENDORID) values ('".$maxid."' , '".$_REQUEST['txtHidOMCID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtOMCAbs_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOMCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOMCAbsComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['selAOMCVendorList_'.$i])."')"; 
			mysql_query($sql8) or die($sql8);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into fca_vci_brokage_commission (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtBrComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['selBroVList_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
	return $msg; 
}

function insertTCIDetails()
{ 
	$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['rdoMarket']));
	$cost_usd_mt 		= addslashes(trim($_REQUEST['txtTCPDRate']));
	$lumpsum	 		= addslashes(trim($_REQUEST['txtLumpsum']));
	$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']));
	
	$loadable	 		= addslashes(trim($_REQUEST['txtLoadable']));
	
	$date 				= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	
	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION"); 
	
	$query 	= "select MAX(PROCESSID + 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_query($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) values ('".$fixture_type."','".$date."','".$_SESSION['moduleid']."','".$_SESSION['company']."','".$mappingid."','".$voyage_status."','".$this->getCheckNullValue($qrows['max'])."','".$estmation_no."','".$cap_rdo."','".$this->getCheckNullValue($grain_cap)."','".$this->getCheckNullValue($bale_cap)."','".$this->getCheckNullValue($sf)."','".$voyage_no."','".$tc_no."','".$market_rdo."','".$this->getCheckNullValue($cost_usd_mt)."','".$this->getCheckNullValue($lumpsum)."','".$this->getCheckNullValue($cargo_qty)."','".$cargo_type_id."','".$this->getCheckNullValue($ttl_voyage_time)."','".$this->getCheckNullValue($ttl_voyage_days)."','".$this->getCheckNullValue($ttl_fo_consp)."','".$this->getCheckNullValue($ttl_do_consp)."','".$dwt_rdo."','".$this->getCheckNullValue($summer_dwt)."','".$this->getCheckNullValue($tropical_dwt)."','".$this->getCheckNullValue($loadable)."','".$cost_sheet_id."')";  
	
	mysql_query($sql) or die($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['p_rotationID']; $i++)
	{
		if(isset($_REQUEST['txtFPort_'.$i]))
		{
			$sql1 = "insert into fca_vci_sea_passage (FCAID,FROM_PORTID,TO_PORTID,DISTANCE_TYPEID,DISTANCE,WEATHER,MARGIN,PASSAGETYPEID,SPEEDID) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtSSpeed_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
	
	for($i=1; $i<= $_REQUEST['load_portID']; $i++)
	{
		if(isset($_REQUEST['txtLoadPort_'.$i]))
		{   
			$sql2 = "insert into fca_vci_load_port (FCAID,LOADPORTID,PORT_COST,PURCHASE_ALLOCATIONID,QTY_MT,RATE,IDLE_DAYS,WORK_DAYS,CRANES) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$_REQUEST['txtLPCID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLpQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPCType_'.$i])."')";	
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
			
			$sql13 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Load', '".$this->getCheckNullValue($_REQUEST['txtLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCLPVendorList_'.$i])."')";
			mysql_query($sql13) or die($sql13);
			mysql_query("commit");
			
			$sql19 = "insert into fca_vci_dd_shipper (FCAID,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDSLPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDLLPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDSLPVendorList_'.$i])."')";
			mysql_query($sql19) or die($sql19);
			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,PORT_COST,PURCHASE_ALLOCID,QTY_MT,RATE,IDLE_DAYS,WORK_DAYS,CRANES) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtDisPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDpQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPCType_'.$i])."')";	
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
			
			$sql14 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Discharge' , '".$this->getCheckNullValue($_REQUEST['txtDisPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCDPVendorList_'.$i])."')";
			mysql_query($sql14) or die($sql14);
			mysql_query("commit");
			
			$sql20 = "insert into fca_vci_dd_receiver (FCAID,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtDisPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDRDPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDRDPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDRLPVendorCList_'.$i])."')";
			mysql_query($sql20) or die($sql20);
			mysql_query("commit");
		}
	}
	
	for($i=1; $i<= $_REQUEST['transit_portID']; $i++)
	{
		if(isset($_REQUEST['txtTLoadPort_'.$i]))
		{	
			$sql4 = "insert into fca_vci_transit_port (FCAID,LOAD_PORTID,PORT_COST,IDLE_DAYS) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtTLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPIDays_'.$i])."')";	
			mysql_query($sql4) or die($sql4);
			mysql_query("commit");
			
			$sql15 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Transit', '".$this->getCheckNullValue($_REQUEST['txtTLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCTPVendorList_'.$i])."')";
			mysql_query($sql15) or die($sql15);
			mysql_query("commit");
	
		}
	}
	
		$sql5 = "insert into fca_vci_totals (FCAID,LADEN_DIST,BALLAST_DIST,TOTAL_DIST,LADEN_DAYS,BALLAST_DAYS,TTL_SEA_DAYS,TTL_PORT_IDLE_DAYS,TTL_PORT_WORK_DAYS,TTL_DAYS,TTL_FO_CONSP_MT,TTL_DO_CONSP_MT,TTL_FO_CONSP_OFFHIRE,TTL_DO_CONSP_OFFHIRE,TTL_HIRE_USD,ADD_COMM_PER,ADD_COMM_USD,BROKERAGE_COMM_PER,BROKERAGE_COMM_USD,NETT_HIRE_USD,BUNKER_ADUJ_ACC,TTL_SHIPOWNER_EXPENSES,ORC_VENDORID,ORC_COST_MT,TTL_PORT_COSTS,TTL_PORT_COSTS_MT,TTL_PORT_COST,TTL_PORT_COST_MT,TTL_DDNR_LP_COST,TTL_DDNR_LP_COST_MT,TTL_DDNR_DP_COST,TTL_DDNR_DP_COST_MT,TTL_SHIPPING_COSTS,TTL_SHIPPING_COSTS_MT,TTL_OTHER_COST,TTL_OTHER_COST_MT,TTL_FO_CONSP_MT_MANUAL, TTL_DO_CONSP_MT_MANUAL) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtLDist'])."','".$this->getCheckNullValue($_REQUEST['txtBDist'])."','".$this->getCheckNullValue($_REQUEST['txtTDist'])."','".$this->getCheckNullValue($_REQUEST['txtLDays'])."','".$this->getCheckNullValue($_REQUEST['txtBDays'])."','".$this->getCheckNullValue($_REQUEST['txtTSDays'])."','".$this->getCheckNullValue($_REQUEST['txtTtPIDays'])."','".$this->getCheckNullValue($_REQUEST['txtTtPWDays'])."','".$this->getCheckNullValue($_REQUEST['txtTDays'])."','".$this->getCheckNullValue($_REQUEST['txtTFUMT'])."','".$this->getCheckNullValue($_REQUEST['txtTDUMT'])."','".$this->getCheckNullValue($_REQUEST['txtTFOCOffHire'])."','".$this->getCheckNullValue($_REQUEST['txtTDOCOffHire'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdTH'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjPerAC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjPerAgC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAgC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdNH'])."','".$this->getCheckNullValue($_REQUEST['txtBunkerAdjAcc'])."','".$this->getCheckNullValue($_REQUEST['txtTTLORCAmt'])."','".$this->getCheckNullValue($_REQUEST['selORCVList'])."','".$this->getCheckNullValue($_REQUEST['txtTTLORCCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCosts'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCostsMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCost'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRLPCost'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRLPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRDPCost'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRDPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLShippingCost'])."','".$this->getCheckNullValue($_REQUEST['txtTTLShippingCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLOtherCost'])."','".$this->getCheckNullValue($_REQUEST['txtTTLOtherCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTFUMTManual'])."','".$this->getCheckNullValue($_REQUEST['txtTDUMTManual'])."')";
		mysql_query($sql5) or die($sql5);
		mysql_query("commit");
		
		$j = 1;
		$arr = array_unique($_REQUEST['txtBHID1']);
		for($i=0;$i<count($arr);$i++)
		{
			$sql6 = "insert into fca_vci_bunker(FCAID,MAPPINGID,BUNKERGRADEID,EST_MT,EST_PRICE,EST_COST) values ('".$maxid."','".$mappingid."','".$this->getCheckNullValue($_REQUEST['txtBunkerGradeID_'.$j])."','".$this->getCheckNullValue($_REQUEST['txt'.$_REQUEST['txtBHID_'.$arr[$i]].'_1_1'])."','".$this->getCheckNullValue($_REQUEST['txt'.$_REQUEST['txtBHID_'.$arr[$i]].'_1_2'])."','".$this->getCheckNullValue($_REQUEST['txt'.$_REQUEST['txtBHID_'.$arr[$i]].'_1_3'])."')";	 
			mysql_query($sql6) or die($sql6);
			mysql_query("commit");
		$j++;		
		}
		
		$orc_id = $_REQUEST['txtORC_id'];
		for($i=1;$i<=$orc_id;$i++)
		{
			 $sql10 = "insert into fca_vci_owner_related_cost (FCAID,OWNER_RCOSTID,AMOUNT,VENDORID) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtHidORCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."','".$this->getCheckNullValue($_REQUEST['selORCVendorList_'.$i])."')"; 
			mysql_query($sql10) or die($sql10);
			mysql_query("commit");
		}
		
		
		$aosc_id = $_REQUEST['txtAOSC_id'];
		for($i=1;$i<=$aosc_id;$i++)
		{
			 $sql11 = "insert into fca_vci_other_shipping_cost (FCAID,OTHER_SCOSTID,ABSOLUTE,VENDORID,COST_MT) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtHidOSCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOSCAbs_'.$i])."','".$this->getCheckNullValue($_REQUEST['selAOSCVendorList_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOSCCostMT_'.$i])."')";
			mysql_query($sql11) or die($sql11);
			mysql_query("commit");
		}  
		
		
		$aomc_id = $_REQUEST['txtAOMC_id'];
		for($i=1;$i<=$aomc_id;$i++)
		{
			$sql12 = "insert into fca_vci_other_misc_cost (FCAID,OTHER_MCOSTID,AMOUNT,VENDORID,COST_MT) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtHidOMCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOMCAbs_'.$i])."','".$this->getCheckNullValue($_REQUEST['selAOMCVendorList_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOMCCostMT_'.$i])."')"; 
			mysql_query($sql12) or die($sql12);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into fca_vci_brokage_commission (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtBrComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['selBroVendorList_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
	return $msg; 
}

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 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 getFreightEstimationTotalInRecords($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 getBunkerRec($fcaid,$mappingid,$bunkergradeid)
{
	$connect = $this->funConnect();
	$sql 	 = "select * from fca_tci_bunker where FCAID='".$fcaid."' and MAPPINGID='".$mappingid."' and BUNKERGRADEID='".$bunkergradeid."'";
	$res 	 = mysql_query($sql);
	$rec 	 = mysql_num_rows($res);
	return $rec;
}

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

function getVciBunkerValues($fcaid,$mappingid,$bunkergradeid,$field)
{
	$connect = $this->funConnect();
	$sql 	 = "select $field from fca_vci_bunker where FCAID='".$fcaid."' and MAPPINGID='".$mappingid."' and BUNKERGRADEID='".$bunkergradeid."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	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 getOwnerRelatedCostNameBasedOnID($id)
{
	$connect = $this->funConnect();
	$sql 	 = "select * from owner_related_cost_master where OWNER_RCOSTID='".$id."' AND MODULEID='".$_SESSION['moduleid']."'"; /*AND MCOMPANYID='".$_SESSION['company']."'";*/
	$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']."'"; /*AND MCOMPANYID='".$_SESSION['company']."'";*/
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows[$field];
}

function updateTCIDetails()
{
	$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['rdoMarket']));
	$cost_usd_mt 		= addslashes(trim($_REQUEST['txtTCPDRate']));
	$lumpsum	 		= addslashes(trim($_REQUEST['txtLumpsum']));
	$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']));
	
	$loadable	 		= addslashes(trim($_REQUEST['txtLoadable']));
	
	$date 				= date("Y-m-d",strtotime($_REQUEST['txtDate']));
	

	$msg = 3;
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$query 	= "select FCAID from freight_cost_analysis_master where MODULEID='".$_SESSION['moduleid']."' and MAPPINGID='".$mappingid."' and SHEET_NO='".$cost_sheet_id."' and MCOMPANYID='".$_SESSION['company']."'";
	$result = mysql_query($query);
	$rows 	= mysql_fetch_assoc($result);
	$fca_id = $rows['FCAID'];
	
	$sql 	= "update freight_cost_analysis_master set FIXTURETYPEID='".$fixture_type."',TRANS_DATE='".$date."',VOY_EST_STATUS='".$voyage_status."',ESTIMATION_NO='".$estmation_no."',CAP_RDO='".$cap_rdo."',GRAIN_CAP='".$this->getCheckNullValue($grain_cap)."',BALE_CAP='".$this->getCheckNullValue($bale_cap)."', SF='".$this->getCheckNullValue($sf)."',VOYAGE_NO='".$voyage_no."',TC_NO='".$tc_no."',MARKET_RDO='".$market_rdo."',COST_USD_MT='".$this->getCheckNullValue($cost_usd_mt)."',LUMPSUM='".$this->getCheckNullValue($lumpsum)."',CARGO_QTY='".$this->getCheckNullValue($cargo_qty)."',CARGO_TYPEID='".$cargo_type_id."',TTL_VOYAGE_TIME='".$this->getCheckNullValue($ttl_voyage_time)."',TTL_VOYAGE_DAYS='".$this->getCheckNullValue($ttl_voyage_days)."',TTL_FO_CONSP='".$this->getCheckNullValue($ttl_fo_consp)."',TTL_DO_CONSP='".$this->getCheckNullValue($ttl_do_consp)."',DWT_RDO='".$dwt_rdo."',SUMMER_DWT='".$this->getCheckNullValue($summer_dwt)."',TROPICAL_DWT='".$this->getCheckNullValue($tropical_dwt)."',LOADABLE='".$this->getCheckNullValue($loadable)."'   where FCAID='".$fca_id."'";
	
	mysql_query($sql) or die($sql);
	mysql_query("commit");
	
	$maxid = $fca_id;
	
	$del_query1 = "delete from  fca_vci_sea_passage where FCAID='".$maxid."'";
	$del_query2 = "delete from  fca_vci_load_port where FCAID='".$maxid."'";
	$del_query3 = "delete from  fca_vci_portcosts where FCAID='".$maxid."'";
	$del_query4 = "delete from  fca_vci_supplementary where FCAID='".$maxid."'";
	$del_query5 = "delete from  fca_vci_dd_shipper where FCAID='".$maxid."'";
	$del_query6 = "delete from  fca_vci_disch_port where FCAID='".$maxid."'";
	$del_query7 = "delete from  fca_vci_dd_receiver where FCAID='".$maxid."'";
	$del_query8 = "delete from  fca_vci_transit_port where FCAID='".$maxid."'";
	$del_query9 = "delete from  fca_vci_totals where FCAID='".$maxid."'";
	$del_query10 = "delete from  fca_vci_bunker where FCAID='".$maxid."'";
	$del_query11 = "delete from  fca_vci_bunker_nett where FCAID='".$maxid."'";
	$del_query12 = "delete from  fca_vci_cargo_contract_allocation where FCAID='".$maxid."'";
	$del_query13 = "delete from  fca_vci_owner_related_cost where FCAID='".$maxid."'";
	$del_query14 = "delete from  fca_vci_other_shipping_cost where FCAID='".$maxid."'";
	$del_query15 = "delete from  fca_vci_other_misc_cost where FCAID='".$maxid."'";
	$del_query16 = "delete from  fca_vci_brokage_commission where FCAID='".$maxid."'";
	
	mysql_query($del_query1);
	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['txtFPort_'.$i]))
		{
			$sql1 = "insert into fca_vci_sea_passage (FCAID,FROM_PORTID,TO_PORTID,DISTANCE_TYPEID,DISTANCE,WEATHER,MARGIN,PASSAGETYPEID,SPEEDID) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtFPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDistance_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtWeather_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtMargin_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPType_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtSSpeed_'.$i])."')";	
			mysql_query($sql1) or die($sql1);
			mysql_query("commit");
		}
	}
	
	for($i=1; $i<= $_REQUEST['load_portID']; $i++)
	{
		if(isset($_REQUEST['txtLoadPort_'.$i]))
		{   
			$sql2 = "insert into fca_vci_load_port (FCAID,LOADPORTID,PORT_COST,PURCHASE_ALLOCATIONID,QTY_MT,RATE,IDLE_DAYS,WORK_DAYS,CRANES) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtPCosts_'.$i])."','".$_REQUEST['txtLPCID_'.$i]."','".$this->getCheckNullValue($_REQUEST['txtLpQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPCType_'.$i])."')";	
			mysql_query($sql2) or die($sql2);
			mysql_query("commit");
			
			$sql13 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Load', '".$this->getCheckNullValue($_REQUEST['txtLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtLPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCLPVendorList_'.$i])."')";
			mysql_query($sql13) or die($sql13);
			mysql_query("commit");
			
			$sql19 = "insert into fca_vci_dd_shipper (FCAID,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDSLPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDLLPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDSLPVendorList_'.$i])."')";
			mysql_query($sql19) or die($sql19);
			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,PORT_COST,PURCHASE_ALLOCID,QTY_MT,RATE,IDLE_DAYS,WORK_DAYS,CRANES) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtDisPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDpQMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPRate_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPIDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPWDays_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPCType_'.$i])."')";	
			mysql_query($sql3) or die($sql3);
			mysql_query("commit");
			
			$sql14 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Discharge' , '".$this->getCheckNullValue($_REQUEST['txtDisPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCDPVendorList_'.$i])."')";
			mysql_query($sql14) or die($sql14);
			mysql_query("commit");
			
			$sql20 = "insert into fca_vci_dd_receiver (FCAID,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtDisPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDRDPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtDDRDPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selDDRLPVendorCList_'.$i])."')";
			mysql_query($sql20) or die($sql20);
			mysql_query("commit");
		}
	}
	
	for($i=1; $i<= $_REQUEST['transit_portID']; $i++)
	{
		if(isset($_REQUEST['txtTLoadPort_'.$i]))
		{	
			$sql4 = "insert into fca_vci_transit_port (FCAID,LOAD_PORTID,PORT_COST,IDLE_DAYS) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtTLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPCosts_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPIDays_'.$i])."')";	
			mysql_query($sql4) or die($sql4);
			mysql_query("commit");
			
			$sql15 = "insert into fca_vci_portcosts (FCAID,PORT,LOADPORTID,COST,COST_MT,VENDORID) values ('".$maxid."','Transit', '".$this->getCheckNullValue($_REQUEST['txtTLoadPort_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPOSCCost_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtTPOSCCostMT_'.$i])."','".$this->getCheckNullValue($_REQUEST['selPCTPVendorList_'.$i])."')";
			mysql_query($sql15) or die($sql15);
			mysql_query("commit");
	
		}
	}
	
		$sql5 = "insert into fca_vci_totals (FCAID,LADEN_DIST,BALLAST_DIST,TOTAL_DIST,LADEN_DAYS,BALLAST_DAYS,TTL_SEA_DAYS,TTL_PORT_IDLE_DAYS,TTL_PORT_WORK_DAYS,TTL_DAYS,TTL_FO_CONSP_MT,TTL_DO_CONSP_MT,TTL_FO_CONSP_OFFHIRE,TTL_DO_CONSP_OFFHIRE,TTL_HIRE_USD,ADD_COMM_PER,ADD_COMM_USD,BROKERAGE_COMM_PER,BROKERAGE_COMM_USD,NETT_HIRE_USD,BUNKER_ADUJ_ACC,TTL_SHIPOWNER_EXPENSES,ORC_VENDORID,ORC_COST_MT,TTL_PORT_COSTS,TTL_PORT_COSTS_MT,TTL_PORT_COST,TTL_PORT_COST_MT,TTL_DDNR_LP_COST,TTL_DDNR_LP_COST_MT,TTL_DDNR_DP_COST,TTL_DDNR_DP_COST_MT,TTL_SHIPPING_COSTS,TTL_SHIPPING_COSTS_MT,TTL_OTHER_COST,TTL_OTHER_COST_MT,TTL_FO_CONSP_MT_MANUAL, TTL_DO_CONSP_MT_MANUAL) values ('".$maxid."','".$this->getCheckNullValue($_REQUEST['txtLDist'])."','".$this->getCheckNullValue($_REQUEST['txtBDist'])."','".$this->getCheckNullValue($_REQUEST['txtTDist'])."','".$this->getCheckNullValue($_REQUEST['txtLDays'])."','".$this->getCheckNullValue($_REQUEST['txtBDays'])."','".$this->getCheckNullValue($_REQUEST['txtTSDays'])."','".$this->getCheckNullValue($_REQUEST['txtTtPIDays'])."','".$this->getCheckNullValue($_REQUEST['txtTtPWDays'])."','".$this->getCheckNullValue($_REQUEST['txtTDays'])."','".$this->getCheckNullValue($_REQUEST['txtTFUMT'])."','".$this->getCheckNullValue($_REQUEST['txtTDUMT'])."','".$this->getCheckNullValue($_REQUEST['txtTFOCOffHire'])."','".$this->getCheckNullValue($_REQUEST['txtTDOCOffHire'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdTH'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjPerAC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjPerAgC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdAgC'])."','".$this->getCheckNullValue($_REQUEST['txtFrAdjUsdNH'])."','".$this->getCheckNullValue($_REQUEST['txtBunkerAdjAcc'])."','".$this->getCheckNullValue($_REQUEST['txtTTLORCAmt'])."','".$this->getCheckNullValue($_REQUEST['selORCVList'])."','".$this->getCheckNullValue($_REQUEST['txtTTLORCCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCosts'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCostsMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPortCost'])."','".$this->getCheckNullValue($_REQUEST['txtTTLPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRLPCost'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRLPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRDPCost'])."','".$this->getCheckNullValue($_REQUEST['txtDDNRDPCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLShippingCost'])."','".$this->getCheckNullValue($_REQUEST['txtTTLShippingCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTTLOtherCost'])."','".$this->getCheckNullValue($_REQUEST['txtTTLOtherCostMT'])."','".$this->getCheckNullValue($_REQUEST['txtTFUMTManual'])."','".$this->getCheckNullValue($_REQUEST['txtTDUMTManual'])."')";
		mysql_query($sql5) or die($sql5);
		mysql_query("commit");
		
		$j = 1;
		$arr = array_unique($_REQUEST['txtBHID1']);
		for($i=0;$i<count($arr);$i++)
		{
			$sql6 = "insert into fca_vci_bunker(FCAID,MAPPINGID,BUNKERGRADEID,EST_MT,EST_PRICE,EST_COST) values ('".$maxid."','".$mappingid."','".$this->getCheckNullValue($_REQUEST['txtBunkerGradeID_'.$j])."','".$this->getCheckNullValue($_REQUEST['txt'.$_REQUEST['txtBHID_'.$arr[$i]].'_1_1'])."','".$this->getCheckNullValue($_REQUEST['txt'.$_REQUEST['txtBHID_'.$arr[$i]].'_1_2'])."','".$this->getCheckNullValue($_REQUEST['txt'.$_REQUEST['txtBHID_'.$arr[$i]].'_1_3'])."')";	 
			mysql_query($sql6) or die($sql6);
			mysql_query("commit");
		$j++;		
		}
		
		$orc_id = $_REQUEST['txtORC_id'];
		for($i=1;$i<=$orc_id;$i++)
		{
			 $sql10 = "insert into fca_vci_owner_related_cost (FCAID,OWNER_RCOSTID,AMOUNT,VENDORID) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtHidORCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtORCAmt_'.$i])."','".$this->getCheckNullValue($_REQUEST['selORCVendorList_'.$i])."')"; 
			mysql_query($sql10) or die($sql10);
			mysql_query("commit");
		}
		
		
		$aosc_id = $_REQUEST['txtAOSC_id'];
		for($i=1;$i<=$aosc_id;$i++)
		{
			 $sql11 = "insert into fca_vci_other_shipping_cost (FCAID,OTHER_SCOSTID,ABSOLUTE,VENDORID,COST_MT) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtHidOSCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOSCAbs_'.$i])."','".$this->getCheckNullValue($_REQUEST['selAOSCVendorList_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOSCCostMT_'.$i])."')";
			mysql_query($sql11) or die($sql11);
			mysql_query("commit");
		}  
		
		
		$aomc_id = $_REQUEST['txtAOMC_id'];
		for($i=1;$i<=$aomc_id;$i++)
		{
			$sql12 = "insert into fca_vci_other_misc_cost (FCAID,OTHER_MCOSTID,AMOUNT,VENDORID,COST_MT) values ('".$maxid."' , '".$this->getCheckNullValue($_REQUEST['txtHidOMCID_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOMCAbs_'.$i])."','".$this->getCheckNullValue($_REQUEST['selAOMCVendorList_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtOMCCostMT_'.$i])."')"; 
			mysql_query($sql12) or die($sql12);
			mysql_query("commit");
		}
		
		$txtBRokageCount = $_REQUEST['txtBRokageCount'];
		for($i=1;$i<=$txtBRokageCount;$i++)
		{
			if(isset($_REQUEST['txtBrCommPercent_'.$i])){
				$sql121 = "insert into fca_vci_brokage_commission (FCAID, BROKAGE_PERCENT, BROKAGE_AMT, VENDORID) values ('".$maxid."', '".$this->getCheckNullValue($_REQUEST['txtBrCommPercent_'.$i])."','".$this->getCheckNullValue($_REQUEST['txtBrComm_'.$i])."','".$this->getCheckNullValue($_REQUEST['selBroVendorList_'.$i])."')";
				mysql_query($sql121)or die($sql121);
				mysql_query("commit");
			}
		}
	return $msg; 
}


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) or die($sql);
	mysql_query("commit");

	return $msg;
}

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

function getCurrentCostSheetStatus($mappingid,$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 MAPPINGID='".$mappingid."' and SHEET_NO ='".$cost_sheet_id."' and FINAL_STATUS=1";
	$result 	= mysql_query($sql);
	while($rows = mysql_fetch_assoc($result))
	{
		$status = $rows['VOY_EST_STATUS'];
	}
	return $status;
}

function getFinalCostSheetDataRec($mappingid)
{
	$this->funConnect();
	$sql = "select FINAL_STATUS 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);
	$val = 0;
	while($rows = mysql_fetch_assoc($res))
	{
		if($rows['FINAL_STATUS'] == 1)
		{
			$val = 1;
		}	
	}
	return $val;
}

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

function getInternalUserRights($linkid)
{
	$connect = $this->funConnect();
	$sql 	 = "select LINK_AUTH from internal_user_rights where LOGINID='".$_SESSION['uid']."' and MODULEID='".$_SESSION['moduleid']."' and LINKID='".$linkid."'";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	$arr 	 = explode(",",$rows['LINK_AUTH']);
	return $arr;
}

function getLatestCostSheetID($mappingid)
{
	$connect = $this->funConnect();
	$sql 	 = "select max(SHEET_NO) as max from freight_cost_analysis_master where MAPPINGID='".$mappingid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and FINAL_STATUS=1";
	$res 	 = mysql_query($sql);
	$rows 	 = mysql_fetch_assoc($res);
	return $rows['max'];
}

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 getReDelDate($mappingid)
{
	$connect				= $this->funConnect();
	if(date("d-M-Y",strtotime($this->getNomDetailsData($mappingid,"DATE_OF_DELIVERY"))) == "01-Jan-1970")
	{
		$redelivery_date = "";
	}
	else
	{
		$redelivery_date = date("Y-m-d",strtotime($this->getNomDetailsData($mappingid,"DATE_OF_DELIVERY")));
	}
	
	$alarm 			= (int)$this->getNomDetailsData($mappingid,"ALARM");
	$cost_sheet_id 	= $this->getLatestCostSheetID($mappingid);
	$fcaid 			= $this->getCurrentCostSheetFCAID($mappingid,$cost_sheet_id);
	$ttl_days 		= (int)$this->getFreightEstimationTotalRecords($fcaid,"TTL_DAYS");
	if($redelivery_date != "" && $ttl_days != "" && $ttl_days != "0" && $alarm != "")
	{
		$date = strtotime($redelivery_date);
		//$days = $ttl_days - $alarm;
		//$date = strtotime("+".$days." day", $date);
		return date('Y-m-d', $date);
	}
}


function getCurrencyList()
{
	$this->funConnect();
	$query = mysql_query("select * from country_master order by CURRENCY_NAME ");
	echo '<option value = "" >---Select from list---</option>';
	@$selCurrency = @$_REQUEST['selCurrency'];
	while($rows = mysql_fetch_assoc($query))
		{
		 $key = $rows['COUNTRYID'];
		 $value = $rows['CURRENCY_NAME'];
	     echo '<option value="'.$key.'"';
		 if($key == @$selCurrency){ echo " selected";}
		 echo '>'.$value.'</option>';
		}
}

function displayVesselOpenEntryInternalUsersList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="apen_vessel_position_enternal_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th width="11%">Vessel</th>';
	echo '<th width="11%">Owner / COA No.</th>';	
	echo '<th width="11%">Broker</th>';
	echo '<th width="11%">ETA During Fixture</th>';
	echo '<th width="11%">CP Date</th>';
	echo '<th width="11%">Port Opening</th>';
	echo '<th width="11%">Laycan Date Range</th>';
	echo '<th width="11%">Filled By</th>';
	echo '<th width="11%">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";
	//echo $sql; die();
	$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['LOGINTYPE'] == 'External User')
				{ 
					$sql1 = "select USERNAME from login where LOGINID='".$rows['LOGINID']."'";
					$res1 = mysql_query($sql1);
					$rows1 = mysql_fetch_assoc($res1);
					
					$name = $rows1['USERNAME'];
				}
				else
				{ 
					$name = $this->getVendorListNewBasedOnID($rows['VENDORID']);
				}
				
				echo '<tr>';
				echo '<td >'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
				if($rows['COA_SPOT'] == 2)
				{
					echo '<td>'.$this->getVendorListNewBasedOnID($rows['OWNER']).' / '.$this->getCOANumberBasedOnID($rows['COA_NO']).'</td>';
				}
				else
				{
					echo '<td>'.$this->getVendorListNewBasedOnID($rows['OWNER']).'</td>';
				}
				echo '<td>'.$this->getVendorListNewBasedOnID($rows['BROKER']).'</td>';
				if(date("d-M-Y",strtotime($rows['ETA_DATE'])) == "01-Jan-1970")
				{
					echo '<td></td>';
				}
				else
				{
					echo '<td>'.date("d-m-Y",strtotime($rows['ETA_DATE'])).'</td>';
				}
				
				echo '<td>'.date("d-m-Y",strtotime($rows['CP_DATE'])).'</td>';
				echo '<td>'.$this->getPortNameBasedOnCode($rows['PORT_CODE']).'</td>';
				echo '<td>'.date("d-m-Y",strtotime($rows['FROM_DATE'])).'</br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To </br>'.date("d-m-Y",strtotime($rows['TO_DATE'])).'</td>';
				echo '<td style="color:red;">'.$rows['LOGINTYPE'].'<br/>'.$this->getUserDetailBaseOnId($rows['LOGINID'],'CONTACT_PERSON').'</td>';
				echo '<td align="center"><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>';
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}


function displayVesselOpenEntryExternalUsersList()
{
	$this->funConnect();
	echo '<div class="box-body table-responsive">';
	echo '<table id="apen_vessel_position_external_list" class="table table-bordered table-striped">';
	echo '<thead>';
	echo '<tr>';
	echo '<th width="11%">Vessel</th>';
	echo '<th width="11%">Owner / COA No.</th>';	
	echo '<th width="11%">Broker</th>';
	echo '<th width="11%">ETA During Fixture</th>';
	echo '<th width="11%">CP Date</th>';
	echo '<th width="11%">Port Opening</th>';
	echo '<th width="11%">Laycan Date Range</th>';
	echo '<th width="11%">Filled By</th>';
	echo '<th width="11%">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";
	//echo $sql; die();
	$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['LOGINTYPE'] == 'External User')
				{ 
					$sql1 = "select USERNAME from login where LOGINID='".$rows['LOGINID']."'";
					$res1 = mysql_query($sql1);
					$rows1 = mysql_fetch_assoc($res1);
					
					$name = $rows1['USERNAME'];
				}
				else
				{ 
					$name = $this->getVendorListNewBasedOnID($rows['VENDORID']);
				}
				
				echo '<tr>';
				echo '<td >'.$this->getVesselIMOData($rows['VESSEL_IMO_ID'],"VESSEL_NAME").'</td>';
				if($rows['COA_SPOT'] == 2)
				{
					echo '<td>'.$this->getVendorListNewBasedOnID($rows['OWNER']).' / '.$this->getCOANumberBasedOnID($rows['COA_NO']).'</td>';
				}
				else
				{
					echo '<td>'.$this->getVendorListNewBasedOnID($rows['OWNER']).'</td>';
				}
				echo '<td>'.$this->getVendorListNewBasedOnID($rows['BROKER']).'</td>';
				if(date("d-M-Y",strtotime($rows['ETA_DATE'])) == "01-Jan-1970")
				{
					echo '<td></td>';
				}
				else
				{
					echo '<td>'.date("d-m-Y",strtotime($rows['ETA_DATE'])).'</td>';
				}
				
				echo '<td>'.date("d-m-Y",strtotime($rows['CP_DATE'])).'</td>';
				echo '<td>'.$this->getPortNameBasedOnCode($rows['PORT_CODE']).'</td>';
				echo '<td>'.date("d-m-Y",strtotime($rows['FROM_DATE'])).'</br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To </br>'.date("d-m-Y",strtotime($rows['TO_DATE'])).'</td>';
				echo '<td style="color:red;">'.$rows['LOGINTYPE'].'<br/>'.$this->getUserDetailBaseOnId($rows['LOGINID'],'CONTACT_PERSON').'</td>';
				echo '<td align="center"><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>';
				echo '</tr>';
				$i++;
		}
	echo '</tbody>';
	}
	echo '</table></div>';
}

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


function confirmFinalCostSheet()
{
	$connect		= $this->funConnect();
 	$mappingid 		= addslashes(trim($_REQUEST['mappingid']));
	$cost_sheet_id 	= addslashes(trim($_REQUEST['rdoFCA']));
	
	mysql_query("Set Autocommit=0");
	mysql_query("START TRANSACTION");
	
	$msg = 0;

	$sql = "update freight_cost_analysis_master set FINAL_STATUS='1',VOY_EST_STATUS='2' where MAPPINGID='".$mappingid."' AND SHEET_NO='".$cost_sheet_id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."'";

	
	mysql_query($sql);
	mysql_query("commit"); 

	$mysql = "select FCAID,FIXTURETYPEID from freight_cost_analysis_master where MAPPINGID='".$mappingid."' AND SHEET_NO='".$cost_sheet_id."' AND MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and FINAL_STATUS='1' and VOY_EST_STATUS='2'";
	$myres = mysql_query($mysql);
	$myrec = mysql_num_rows($myres);
	
	if($myrec > 0)
	{
		$myrows = mysql_fetch_assoc($myres);
		if($myrows['FIXTURETYPEID'] == 2)
		{
			$mysql1 = "select * from fca_tci_load_port where FCAID='".$myrows['FCAID']."'";
			$myres1 = mysql_query($mysql1);
			$myrec1 = mysql_num_rows($myres1);
			if($myrec1 > 0)
			{
				while($myrows1 = mysql_fetch_assoc($myres1))
				{
					$myquery1 = "insert into fca_tci_actual_lp (FCAID,IDLE_DAYS,WRKING_DAYS,REASON_OFF_HIRE,OFF_HIRE_HRS,OFF_HIRE_DAYS,ACTUAL_DAYS,LOADPORTID,CRANES) values ('".$myrows['FCAID']."','0','0','','0','0','0','".$myrows1['LOADPORTID']."','0')";	
					mysql_query($myquery1);
					mysql_query("commit");
				}
			}
			
			
			$mysql2 = "select * from fca_tci_disch_port where FCAID='".$myrows['FCAID']."'";
			$myres2 = mysql_query($mysql2);
			$myrec2 = mysql_num_rows($myres2);
			if($myrec2 > 0)
			{
				while($myrows2 = mysql_fetch_assoc($myres2))
				{
					$myquery2 = "insert into fca_tci_actual_dp (FCAID,IDLE_DAYS,WRKING_DAYS,REASON_OFF_HIRE,OFF_HIRE_HRS,OFF_HIRE_DAYS,ACTUAL_DAYS,DISPORTID,CRANES) values ('".$myrows['FCAID']."','0','0','','0','0','0','".$myrows2['DIS_PORT_ID']."','0')";	
					mysql_query($myquery2);
					mysql_query("commit");
				}
			}
			
			
			$mysql3 = "select * from fca_tci_transit_port where FCAID='".$myrows['FCAID']."'";
			$myres3 = mysql_query($mysql3);
			$myrec3 = mysql_num_rows($myres3);
			if($myrec3 > 0)
			{
				while($myrows3 = mysql_fetch_assoc($myres3))
				{
					$myquery3 = "insert into fca_tci_actual_tp (FCAID,IDLE_DAYS,REASON_OFF_HIRE,OFF_HIRE_HRS,OFF_HIRE_DAYS,ACTUAL_DAYS,LOADPORTID) values ('".$myrows['FCAID']."','0','','0','0','0','".$myrows3['LOAD_PORTID']."')";	
					mysql_query($myquery3);
					mysql_query("commit");
				}
			}
			
			$mysql4 = "select * from fca_tci_sea_passage where FCAID='".$myrows['FCAID']."'";
			$myres4 = mysql_query($mysql4);
			$myrec4 = mysql_num_rows($myres4);
			if($myrec4 > 0)
			{
				while($myrows4 = mysql_fetch_assoc($myres4))
				{
					$myquery4 = "insert into fca_tci_actual_sea_passage (FCAID,DAYS,OFF_HIRE_DEV_HRS,OFF_HIRE_DEV_DAYS,OFF_HIRE_IDLE_HRS,OFF_HIRE_IDLE_DAYS,MARGIN_HRS,MARGIN_DAYS,ACTUAL_DAYS) values ('".$myrows['FCAID']."','0','0','0','0','0','0','0','0')";	
					mysql_query($myquery4);
					mysql_query("commit");
				}
			}			
		}	
	}
	return $msg;
}


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 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 insertActualCostSheetName()
{
	
	$connect 	= $this->funConnect();
	$file_name  = $_REQUEST['txtFile'];
	$mappingid  = $_REQUEST['txtMappingid1'];
		
	$msg = 3;
	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']."','Actual')";
	mysql_query($sql1) or die($sql1);
	mysql_query("commit");
	return $msg;
}

function getVendorListNewUpdate($id)
{
	$connect = $this->funConnect();
	$qurey 	 = "select * from vendor_master where STATUS=1 order by NAME ";
	$result	 = mysql_query($qurey);
	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 == @$id){ echo ' selected';}
		echo '>'.$value.'</option>';
	}
}

function getVendorNewUpdateBaseOnCode($code,$field)
{
	$connect = $this->funConnect();
	$qurey 	 = "select $field,CODE from vendor_master where CODE='".$code."' and STATUS=1";
	$result	 = mysql_query($qurey);
	$rows 	 = mysql_fetch_assoc($result);
	return 	$rows[$field]." ( ".$rows['CODE']." )";
	
}

function deleteCoaData()
{
	$coaId 			= @$_REQUEST['delId'];
	$msg 			= 3;
	
	$delQry			= "delete from coa_master where COAID = '".$coaId."'";
	$delQry1		= "delete from coa_master_hire_slave1 where COAID = '".$coaId."'";
	$delQry2		= "delete from coa_master_bod_slave2 where COAID = '".$coaId."'";
	$delQry3		= "delete from coa_master_bctr_slave3 where COAID = '".$coaId."'";
	$delQry4		= "delete from coa_master_bor_slave4 where COAID = '".$coaId."'";
		
	mysql_query($delQry);
	mysql_query("commit");
	mysql_query($delQry1);
	mysql_query("commit");
	mysql_query($delQry2);
	mysql_query("commit");
	mysql_query($delQry3);
	mysql_query("commit");
	mysql_query($delQry4);
	mysql_query("commit");
	
	return $msg;	
}


} // class data ends
?>