<?php 
session_start();
require_once("../../includes/display_internal_user_dryout.inc.php");
require_once("../../includes/functions_internal_user_dryout.inc.php");
$obj = new data();
$connect = $obj->funConnect();
$display = new display();
$display->logout_iu();

$senddata 		= explode(",",$_REQUEST['senddata']);
$comid 	= $senddata['5'];
$randomid 	= $senddata['3'];
$vendorid 	= $senddata['4'];
$page  		= $_REQUEST['page'];

if (@$_REQUEST['action'] == 'submit')
{
	$msg = $obj->insertRequestDetailstc();
	header('Location:./payment_gridtc.php?msg='.$msg.'&comid='.$comid.'&page='.$page);
}

if (@$_REQUEST['action1'] == 'submit1')
{
	$msg = $obj->insertRequestUploadDetailstc();
	header('Location:./payment_gridtc.php?msg='.$msg.'&comid='.$comid.'&page='.$page."&name=".$_REQUEST['name']);
}

if (@$_REQUEST['action'] == 'submit2')
{
	$msg = $obj->deleteRequestDetailstc();
	$msg = explode("_",$msg);
	header('Location:./request_port_costtc.php?msg='.$msg[0].'&senddata='.$msg[1].'&page='.$page."&name=".$_REQUEST['name']);
}

$id = $obj->getLatestCostSheetIDTC($comid);
$obj->viewTCEstimationTempleteRecordsNew($id);
$pagename = basename($_SERVER['PHP_SELF'])."?senddata=".$_REQUEST['senddata']."&page=".$page."&name=".$_REQUEST['name'];

$uid	  = $_SESSION['uid'];
$moduleid = $_SESSION['moduleid'];
if($page == 1)
{
	$linkid = 4;
}
else
{
	$linkid = 5;
}
$rights = $obj->getUserRights($uid,$moduleid,$linkid);
$result = mysql_query("select MESSAGE from chartering_estimate_tc_compare where COMID='".$comid."'") or die;
$rows1 = mysql_fetch_assoc($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php $display->title(); ?></title>
<?php $display->favicon(); ?>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<?php $display->css(); ?>
<?php $display->js(); ?>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="../js/html5shiv.js"></script>
  <script src="../js/respond.min.js"></script>
<![endif]-->
<style>
.animated {
	vertical-align: top; 
	transition: height 0.2s;
	-webkit-transition: height 0.2s; 
	-moz-transition: height 0.2s; 
}

form.cmxform label.error, label.error {
	/* remove the next line when you have trouble in IE6 with labels in list */
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:10px;
	color: red;
	font-style:normal;
	font-weight:lighter;
	margin:5px;
	vertical-align:top;
}
.span span{
	font-weight:bold;
}
</style>
</head>
    <body class="skin-blue fixed">
        <!-- header logo: style can be found in header.less -->
        <?php $display->header_tag(); ?>
		<div class="wrapper row-offcanvas row-offcanvas-left">
            <?php $display->leftmenu(5); ?>
			<aside class="right-side">                
                <!-- Content Header (Page header) -->
                 <section class="content-header">
                    <h1>
                        <i class="fa fa-book"></i>&nbsp;Daily Tasks&nbsp;&nbsp;&nbsp;&nbsp;<small><div class="headline text-center" id="time" style="color:#000; font-weight:bold; font-size:12px;">( 20 Jul 2015 4:40:44 PM )</div></small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="../"><i class="fa fa-home"></i> Home</a></li>
                        <li class="active">Daily Tasks&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;In Ops at a glance&nbsp;&nbsp;&nbsp;</li>
                    </ol>
                </section>
				<?php
				$sql3 = "select max(REQ_ID) as max from request_mastertc where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and LOGIN='INTERNAL_USER' and NAME='".$senddata[1]."' and NAME_ID='".$senddata[0]."' and GRADEID='".$senddata[2]."' and VENDOR='".$senddata[4]."' and RANDOMID='".$senddata[3]."'";
				$res3  = mysql_query($sql3);
				$rows3 = mysql_fetch_assoc($res3);
				
				$sql5  = "select STATUS, REQUESTED, REQ_ID from request_mastertc where REQ_ID='".$rows3['max']."'";
				$res5  = mysql_query($sql5);
				$rows5 = mysql_fetch_assoc($res5);
				
				$sql4 = "select * from request_mastertc where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and LOGIN='INTERNAL_USER' and NAME='".$senddata[1]."' and NAME_ID='".$senddata[0]."' and GRADEID='".$senddata[2]."' and VENDOR='".$senddata[4]."' and RANDOMID='".$senddata[3]."'";
				$res4 = mysql_query($sql4);
				$rec4 = mysql_num_rows($res4);
				?>

                <!-- Main content -->
                <section class="content invoice">
				<!--   content put here..................-->
				<div align="right">					
					<?php if($rows5['STATUS'] == 1 || $rec4 == 0){ $idd = 0;?>
						<button class="btn btn-info btn-flat" type="button" onClick="getShow()">Add</button>&nbsp;
					<?php }else{$idd = $rows5['REQ_ID'];}?>
					<a href="payment_gridtc.php?comid=<?php echo $comid;?>&page=<?php echo $page;?>">
							<button class="btn btn-info btn-flat" type="button" >Back</button>
					</a>
					<input type="hidden" name="txtReq_id" id="txtReq_id" value="<?php echo $rows3['max'];?>" />
					<input type="hidden" name="txtRequested" id="txtRequested" value="<?php echo $rows5['REQUESTED'];?>"/>
				</div>
				<div style="height:10px;">&nbsp;</div>
					<form role="form" name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post">			
						<div style="display:none;" id="row">	
							<div class="row">
								<div class="col-xs-12">
									<h2 class="page-header">
									Account <?php echo $senddata[1];?> : <?php echo $_REQUEST['name']?>
									</h2>                            
								</div><!-- /.col -->
							</div>
						
							<div class="row invoice-info">
								<div class="col-sm-4 invoice-col">
								   Account Type
									<address>
										<select  name="selAType" class="select form-control" id="selAType" onChange="getAlert()">
											<?php 
											$obj->getAccountType();
											?>
										</select>
									</address>
								</div><!-- /.col -->
								<div class="col-sm-4 invoice-col">
								   Payment No/Description
									<address>
										<input type="text" name="txtAccNO" id="txtAccNO" class="form-control" value="" autocomplete="off" placeholder="Payment No/Description"/>
									</address>
								</div><!-- /.col -->
								<div class="col-sm-4 invoice-col">
								   CP Date
									<address>
                                    <?php
								  $cpdate = date("d-m-Y",strtotime($obj->getFun16())); echo $cpdate;?>
										<input type="hidden" name="txtCP_Date" id="txtCP_Date" class="form-control" value="<?php echo $cpdate; ?>" autocomplete="off" readonly/>
									</address>
								</div><!-- /.col -->
							</div>
							<div class="row invoice-info">	
								<div class="col-sm-4 invoice-col">
								   Date
									<address>
										<input type="text" name="txtDate" id="txtDate" class="form-control" value="<?php echo date("d-m-Y",time());?>" />
									</address>
								</div><!-- /.col -->
								
								<div class="col-sm-4 invoice-col">
								   Nom ID
									<address>
										<?php echo $rows1["MESSAGE"];?>
									</address>
								</div><!-- /.col -->
								
								<div class="col-sm-4 invoice-col">
								   Vessel
									<address>
										<?php echo $obj->getVesselIMOData($obj->getFun2(),"VESSEL_NAME");?>
                                        <input type="hidden" name="vesselid" id="vesselid" value="<?php echo $obj->getFun2();?>" />
									</address>
								</div><!-- /.col -->
								
								<div class="col-sm-4 invoice-col">
								    Vendor
									<address>
										<?php echo $obj->getVendorListNewBasedOnID($vendorid).'('.$vendorid.')';?><input type="hidden" name="txtVendor" id="txtVendor" class="form-control" readonly value="<?php echo $vendorid;?>" />
									</address>
								</div><!-- /.col -->
								
								<div class="col-sm-4 invoice-col">
								   Remarks
									<address>
										<textarea name="txtRemarks" id="txtRemarks" class="form-control" rows="3" cols="15" placeholder="Remarks.."></textarea>
									</address>
								</div><!-- /.col -->
								
								<div class="col-sm-4 invoice-col">
								   Cost Type Desc.
									<address>
										<?php echo $_REQUEST['name']?>
									</address>
								</div><!-- /.col -->
								
								<div class="col-sm-4 invoice-col">
								   Vendor Invoice Amount
									<address>
										<input type="text" name="txtV_I_Amt" id="txtV_I_Amt" class="form-control" autocomplete="off" value="" placeholder="Vendor Invoice Amount" />
									</address>
								</div><!-- /.col -->
								
								<div class="col-sm-4 invoice-col">
								   Invoice Date
									<address>
										<input type="text" name="txtI_Date" id="txtI_Date" class="form-control" value="" placeholder="dd-mm-yyyy" />
									</address>
								</div><!-- /.col -->
							</div>
							
							<div class="box">
								<div class="box-header">
									<h3 class="box-title">Account <?php echo $senddata[1];?> : Details</h3>
								</div><!-- /.box-header -->
								<div class="box-body no-padding">
									<table class="table table-striped">
										<thead>
											<tr>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
											</tr>
										</thead>
										<tbody>
											<tr>
												<td>Total Payable</td>
												<td><input type="text" name="txtTtl_Outs" id="txtTtl_Outs" class="form-control" readonly value="<?php echo sprintf("%.2f",$senddata[6]);?>"/></td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
											<?php
											$sql6 = "select * from request_mastertc where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and LOGIN='INTERNAL_USER' and NAME='".$senddata[1]."' and NAME_ID='".$senddata[0]."' and GRADEID='".$senddata[2]."' and VENDOR='".$senddata[4]."' and RANDOMID='".$senddata[3]."' and STATUS=1"; 
											$res6 = mysql_query($sql6);
											$rec6 = mysql_num_rows($res6);
											$n = 1;
											$cost = 0; $addition = $deduction = 0;
											while($rows6 = mysql_fetch_assoc($res6))
											{
												$sql7 = "select * from request_mastertc_slave where REQ_ID='".$rows6['REQ_ID']."'";
												$res7 = mysql_query($sql7);
												while($rows7 = mysql_fetch_assoc($res7))
												{ 
													if($rows7['IDENTIFY'] =='ADD')
													{
													   $addition = $addition + $rows7['AMOUNT'];
													}
													else
													{
													   $deduction   = $deduction + $rows7['AMOUNT']; 
													}
												}
												$cost = $cost + $rows6['REQ_TO_PAY'];
											?>
											<tr id="row_1_<?php echo $n;?>" >
												<td>Amount Paid <?php echo $rows6['PAYMENT_NO'];?></td>											
												<td><input type="text" name="txtP_<?php echo $n;?>" id="txtP_<?php echo $n;?>" class="form-control" readonly value="<?php echo sprintf("%.2f",$rows6['REQ_TO_PAY']);?>" /></td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
								<?php $n++;}?>
											
											
											
											<tr>
												<td>Balance Outstanding</td>
												<?php $cost = $senddata[6]-$cost; 
												if($rec6 == 0){?>
												<td><input type="text" name="txtBal_Outs" id="txtBal_Outs" class="form-control" readonly value="<?php echo sprintf("%.2f",$senddata[6]);?>"/></td>
												<?php }else{$cost = $senddata[6]-$cost;?>
												<td><input type="text" name="txtBal_Outs" id="txtBal_Outs" class="form-control" readonly value="<?php echo sprintf("%.2f",$cost);?>" /></td>
												<?php }?>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
											
										</tbody>
									</table>
								</div>
							</div>
							
							
							<div class="row">
							<div class="col-xs-12">
								<h2 class="page-header">
							     Add
								</h2>                            
							</div><!-- /.col -->
				    </div>	
						
					<div class="box">
                      <div class="box-body no-padding">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Description</th>
                                    <?php $sql2 = "select * from request_mastertc_slave where REQ_ID='".$idd."' and IDENTIFY='ADD'";
									$res2 = mysql_query($sql2);
									$num2 = mysql_num_rows($res2);
									$sum1 = $sum2 = 0;
									if($num2 >0){$num21 = $num2;}else{$num21 = 1;}
									?>
                          			<th>Amount<input type="hidden" name="txtAddID" id="txtAddID" value="<?php echo $num21;?>"/></th>
                                </tr>
                            </thead>
                            <tbody id="tblAdd">
                            <?php if($num2 >0)
							   {$i = 0;
								while($rows2 = mysql_fetch_assoc($res2))
								{$i++;$sum1 = $sum1 + $rows2['AMOUNT'];
								?>
                                <tr id="add_Row_<?php echo $i;?>">
                                   <td align="center"><a href="#pr<?php echo $i;?>" onClick="removeAddRow(<?php echo $i;?>);"><i class="fa fa-times" style="color:red;"></i></a></td>
                                   <td><textarea class="form-control areasize" name="txtAddDes_<?php echo $i;?>" id="txtAddDes_<?php echo $i;?>" rows="2" placeholder="Description..."><?php echo $rows2['DESCRIPTION'];?></textarea></td>
                                   <td><input type="text" name="txtAddDesAmt_<?php echo $i;?>" id="txtAddDesAmt_<?php echo $i;?>" class="form-control"  placeholder="Amount" autocomplete="off" value="<?php echo $rows2['AMOUNT'];?>" onKeyUp="getDeduction();"/></td>
                                </tr>
                                <?php }}else{?>
                                <tr id="add_Row_1">
                                   <td align="center"><a href="#pr1" onClick="removeAddRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td>
                                   <td><textarea class="form-control areasize" name="txtAddDes_1" id="txtAddDes_1" rows="2" placeholder="Description..."></textarea></td>
                                   <td><input type="text" name="txtAddDesAmt_1" id="txtAddDesAmt_1" class="form-control"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getDeduction();"/></td>
                                </tr>
                                <?php }?>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td align="left"><button type="button" class="btn btn-primary btn-flat" onClick="AddNewAddRow();">Add</button></td>
									<td>Total</td>
									<td><input type="text" name="txtAddDesTotalAmt" id="txtAddDesTotalAmt" class="form-control" readonly  placeholder="0.00" autocomplete="off" value=""/></td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                  </div>
				  
				  
				 <div class="row">
							<div class="col-xs-12">
								<h2 class="page-header">
							     Less
								</h2>                            
							</div><!-- /.col -->
				    </div>	
				  <div class="box">
                      <div class="box-body no-padding">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Description</th>
                                     <?php $sql2 = "select * from request_mastertc_slave where REQ_ID='".$idd."' and IDENTIFY='SUB'";
									$res2 = mysql_query($sql2);
									$num2 = mysql_num_rows($res2);
									if($num2 >0){$num21 = $num2;}else{$num21 = 1;}
									?>
                          			<th>Amount<input type="hidden" name="txtSubID" id="txtSubID" value="<?php echo $num21;?>"/></th>
                                </tr>
                            </thead>
                            <tbody id="tblSub">
                            <?php if($num2 >0)
							   {$i = 0;
								while($rows2 = mysql_fetch_assoc($res2))
								{$i++;$sum2 = $sum2 + $rows2['AMOUNT'];
								?>
                                <tr id="Sub_Row_<?php echo $i;?>">
                                   <td align="center"><a href="#pr<?php echo $i;?>" onClick="removeSubRow(<?php echo $i;?>);"><i class="fa fa-times" style="color:red;"></i></a></td>
                                   <td><textarea class="form-control areasize" name="txtSubDes_<?php echo $i;?>" id="txtSubDes_<?php echo $i;?>" rows="2" placeholder="Description..."><?php echo $rows2['DESCRIPTION'];?></textarea></td>
                                   <td><input type="text" name="txtSubDesAmt_<?php echo $i;?>" id="txtSubDesAmt_<?php echo $i;?>" class="form-control"  placeholder="Amount" autocomplete="off" value="<?php echo $rows2['AMOUNT'];?>" onKeyUp="getDeduction();"/></td>
                                </tr>
                                <?php }}else{?>
                                <tr id="Sub_Row_1">
                                   <td align="center"><a href="#pr1" onClick="removeSubRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td>
                                   <td><textarea class="form-control areasize" name="txtSubDes_1" id="txtSubDes_1" rows="2" placeholder="Description..."></textarea></td>
                                   <td><input type="text" name="txtSubDesAmt_1" id="txtSubDesAmt_1" class="form-control"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getDeduction();"/></td>
                                </tr>
                                <?php }?>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td align="left"><button type="button" class="btn btn-primary btn-flat" onClick="SubNewSubRow();">Add</button></td>
									<td>Total</td>
									<td><input type="text" name="txtSubDesTotalAmt" id="txtSubDesTotalAmt" class="form-control" readonly  placeholder="0.00" autocomplete="off" value=""/></td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                  </div>
							
							
							
							<div class="box">
								<div class="box-header">
									<h3 class="box-title">Account <?php echo $senddata[1];?> : Net Payable</h3>
								</div><!-- /.box-header -->
								<div class="box-body no-padding">
									<table class="table table-striped">
										<thead>
											<tr>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
											</tr>
										</thead>
										<tbody>
											<tr>
												<td>Net Payable</td>
												<td><input type="text" name="txtNET" id="txtNET" class="form-control" value="<?php echo sprintf("%.2f",$cost);?>" autocomplete="off" readonly/></td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
							
							<div class="box">
								<div class="box-header">
									<h3 class="box-title">Account <?php echo $id[1];?> : Requested To Pay/Recover</h3>
								</div><!-- /.box-header -->
								<div class="box-body no-padding">
									<table class="table table-striped">
										<thead>
											<tr>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
												<th width="25%">&nbsp;</th>
											</tr>
										</thead>
										<tbody>
											<tr>
												<td>Requested To Pay/Recover</td>
												<td><input type="text" name="txtROP_3" id="txtROP_3" class="form-control" value="0.00" autocomplete="off" /></td>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>						
							
							<?php if($rights == 1){ ?>
							<div class="box-footer" align="right">
								<button type="submit" class="btn btn-primary btn-flat">Submit</button>
								<button type="button" class="btn btn-primary btn-flat" onClick="return getSubmit(1)">Submit & Close</button>							
								<input type="hidden" id="action" name="action" value="submit" />
								<input type="hidden" name="txtID" id="txtID" value=""/>
								<input type="hidden" name="txtStatus" id="txtStatus" value="0"/>
							</div>
							<?php } ?>
						</div>							
						<div class="box">
							<div class="box-header">
								<h3 class="box-title">&nbsp;</h3>
							</div><!-- /.box-header -->
							<div class="box-body no-padding" style="overflow:auto;">
								<table class="table table-striped">
									<thead>
										<tr>
											<th>Nom ID</th>
											<th>Vessel</th>
											<th>Cost Type</th>
											<th>Cost Desc.</th>
											<th>Account Type</th>
											<th>Payment No.</th>
											<th>Date</th>
											<th>Vendor</th>
											<th>Pdf</th>
											<th>Paid Payment</th>
											<th>Details</th>
											<?php if($rights == 1){?>
											<th>Cancelled</th>
											<?php }?>
										</tr>
									</thead>
									<tbody>
										<?php 
										$sql2 = "select * from request_mastertc where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and LOGIN='INTERNAL_USER' and NAME='".$senddata[1]."' and NAME_ID='".$senddata[0]."' and GRADEID='".$senddata[2]."' and VENDOR='".$senddata[4]."' and RANDOMID='".$senddata[3]."'";
										$res2 = mysql_query($sql2);
										$rec2 = mysql_num_rows($res2);
										if($rec2 == 0)
										{
											$sql3 = "select * from request_cancel_mastertc where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and LOGIN='INTERNAL_USER' and NAME='".$senddata[1]."' and NAME_ID='".$senddata[0]."' and GRADEID='".$senddata[2]."' and VENDOR='".$senddata[4]."' and RANDOMID='".$senddata[3]."' and P_STATUS='1'";
											$res3 = mysql_query($sql3);
											$rec3 = mysql_num_rows($res3);
											if($rec3 == 0)
											{
										?>
										<tr>
											<td align="center" valign="middle" class="input-text" style="color:red;letter-spacing:1px;" colspan="12">SORRY CURRENTLY THERE ARE ZERO(0) RECORDS</td>
										</tr>
										<?php }else{while($rows3 = mysql_fetch_assoc($res3)){?>
										<tr>
											<td><?php echo $obj->getCompareEstimateData($comid,"VOYAGE_NO");?></td>
											<td><?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");?></td>
											<td><?php echo $id[1];?></td>
											<td><?php echo $_REQUEST['name']?></td>
											<td><?php echo $rows3['ACCOUNT_TYPE'];?></td>
											<td><?php echo $rows3['PAYMENT_NO'];?></td>
											<td><?php echo date("d-M-Y",strtotime($rows3['DATE']));?></td>
											<td><?php echo $obj->getVendorListNewBasedOnID($rows3['VENDOR']).'('.$rows3['VENDOR'].')';?></td>
											<td></td>
											<td></td>
											<td></td>
											<td>Cancelled</td>
										</tr>
										<?php }}?>
										
										<?php } else { 
										$sql3 = "select * from request_cancel_master where COMID='".$comid."' and MODULEID='".$_SESSION['moduleid']."' and MCOMPANYID='".$_SESSION['company']."' and LOGIN='INTERNAL_USER' and NAME='".$id[1]."' and NAME_ID='".$id[0]."' and GRADEID='".$id[2]."' and VENDOR='".$id[4]."' and P_STATUS='1'";
										$res3 = mysql_query($sql3);
										$rec3 = mysql_num_rows($res3);
										if($rec3 != 0)
										{
										while($rows3 = mysql_fetch_assoc($res3)){?>
										<tr>
											<td><?php echo $obj->getCompareTableData($comid,"MESSAGE");?></td>
											<td><?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");?></td>
											<td><?php echo $id[1];?></td>
											<td><?php echo $_REQUEST['name']?></td>
											<td><?php echo $rows3['ACCOUNT_TYPE'];?></td>
											<td><?php echo $rows3['PAYMENT_NO'];?></td>
											<td><?php echo date("d-M-Y",strtotime($rows3['DATE']));?></td>
											<td><?php echo $obj->getVendorListNewBasedOnID($rows3['VENDOR']).'('.$rows3['VENDOR'].')';?></td>
											<td></td>
											<td></td>
											<td></td>
											<td>Cancelled</td>
										</tr>
										
										<?php  }}while($rows2 = mysql_fetch_assoc($res2)){
										if($rows2['P_STATUS'] != 2)
										{
										?>
										<tr>
											<td><?php echo $obj->getCompareTableData($comid,"MESSAGE");?></td>
											<td><?php echo $obj->getVesselIMOData($obj->getCompareEstimateData($comid,"VESSEL_IMO_ID"),"VESSEL_NAME");?></td>
											<td><?php echo $id[1];?></td>
											<td><?php echo $_REQUEST['name']?></td>
											<td><?php echo $rows2['ACCOUNT_TYPE'];?></td>
											<td><?php echo $rows2['PAYMENT_NO'];?></td>
											<td><?php echo date("d-M-Y",strtotime($rows2['DATE']));?></td>
											<td><?php echo $obj->getVendorListNewBasedOnID($rows2['VENDOR']).'('.$rows2['VENDOR'].')';?></td>
											
											<td><a href="#" title="Pdf" onClick="getPdf(<?php echo $rows2['REQ_ID'];?>);"><button class="btn btn-default" style="margin-right: 5px;" type="button"><i class="fa fa-download"></i>Generate PDF</button></a>
                                            
                                            </td>
											<td>
											<?php if($rows2['STATUS'] == 0){?>
											<?php }else {  ?>
												<a href="#?" title="Paid Payment" class="btn btn-default btn-sm" data-toggle="modal" data-target="#compose-modal" onClick="openWin1(<?php echo $rows2['REQ_ID'];?>);">Paid Payment</a>
											<?php }?>
											</td>
											<td>
											<?php if($rows2['STATUS'] == 0){?>
												<a href="#1" title="Edit" onClick="getData(<?php echo $rows2['REQ_ID'];?>);"><img src="../../img/edit.png" width="20" height="16" /></a>
											<?php }?>
											</td>											
											<?php if($rights == 1){
											?>
											<td><a href="#1" title="Cancel Entry" onClick="return getDel(<?php echo $rows2['REQ_ID'];?>);"><img src="../../img/icon_delete.gif" /></a></td>
											<?php }?>
										</tr>
										<?php }}}?>
									</tbody>
								</table>
							</div>
						</div>				
					</form>
					<div class="modal fade" id="compose-modal" tabindex="-1" role="dialog" aria-hidden="true">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
								</div>
								<div class="modal-body">
									<form name="frm2" id="frm2" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post"/>
                                        <div id="divPayment">
                                            
                                        </div>
                                        <div class="box-footer" align="right">
                                            <button type="submit" id="btnhide" class="btn btn-primary btn-flat" onClick="return getValid();" >Submit</button>
                                            <input type="hidden" id="action1" name="action1" value="submit1" />
                                            <input type="hidden" name="txtCRMFILE1" id="txtCRMFILE1" value="" />
                                            <input type="hidden" name="txtCRMNAME1" id="txtCRMNAME1" value="" />
                                        </div>
									</form>
								</div>
							</div><!-- /.modal-content -->
						</div><!-- /.modal-dialog -->
					</div>
				<!--   content ends here..................-->
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
			
        </div><!-- ./wrapper -->
<?php $display->footer(); ?>
<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
<script src='../../js/jquery.autosize.js'></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>
<script src="../../js/timer.js" type="text/javascript"></script>
<link href="../../css/datepicker/datepicker.css" rel="stylesheet" type="text/css" />
<script src="../../js/bootstrap-datepicker.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.numeric.js"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.calculation-min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
$("#txtROP_3,[id^=txtVC_DED_], #txtV_I_Amt,[id^=txtAddDesAmt_],[id^=txtSubDesAmt_]").numeric();

$('[id^=txtRemarks]').autosize({append: "\n"});

$("#frm1").validate({
rules: {
	txtAccNO: "required",
	txtV_I_Amt: "required",
	txtI_Date: "required"
	},
messages: {	
	txtAccNO : "*",
	txtV_I_Amt : "*",
	txtI_Date : "*"
	}
});

$('#txtDate, #txtI_Date').datepicker({
	autoclose: true,
	format: 'dd-m-yyyy'
});

$('#txtROP_3').keyup(function(){
	if($('#txtROP_3').val() > 0)
	{
		var var1 = parseFloat($('#txtROP_3').val());
	}
	else
	{
		var var1 = parseFloat(-($('#txtROP_3').val()));
	}
	
	if($('#txtNET').val() > 0)
	{
		var var3 = parseFloat($('#txtNET').val());
	}
	else
	{
		var var3 = parseFloat(-($('#txtNET').val()));
	}
	
	if(var3 < var1)
	{
		jAlert('Requested to pay is more than Net Payable', 'Alert');
		$('#txtROP_3').val('0.00');
	}
	
});	
getDeduction();
});

function getShow()
{
	$('#row').show();
	
}

function getData(var1)
{
	$('#row').show();
	
	
	var code = <?php echo $obj->getRequestDataWithJsontc(); ?>;
	$.each(code[var1], function(index, array) {
		$('#selAType').val(array['account_type']);
		$('#txtAccNO').val(array['payment_no']);
		$('#txtDate').val(array['date']);
		$('#txtRemarks').val(array['remarks']);
		$('#txtBal_Outs').val((parseFloat(array['bal_outstandings'])).toFixed(2));
		$('#txtROP_3').val((parseFloat(array['req_to_pay'])).toFixed(2));
		$('#txtID').val(var1);
		$('#txtV_I_Amt').val((parseFloat(array['i_amt'])).toFixed(2));
		
		if(array['i_date'] != '01-Jan-1970')
		{$('#txtI_Date').val(array['i_date']);}
	});
	
	var code1 = <?php echo $obj->getRequestDeductionDataWithJsontc(); ?>;
	var var2 = 1; 
	var cost = 0;
	$.each(code1[var1], function(index, array1) {
		$('#txtVC_NAME_'+var2).val(array1['deduction_id']);
		$('#txtVC_DED_'+var2).val((parseFloat(array1['cost'])).toFixed(2));
		
		cost = (parseFloat(cost)+parseFloat(array1['cost'])).toFixed(2);
		var2++;
	});
	
	var nett = (parseFloat($('#txtBal_Outs').val())).toFixed(2);
	$('#txtNET').val(nett);
	getDeduction();
}

function getSubmit(var1)
{
	jConfirm('Are you sure you want to "Submit & Close"?', 'Confirmation', function(r) {
	if(r)
	{
		$('#txtStatus').val(var1);
		if($('#txtAccNO').val() != '' && $('#txtV_I_Amt').val() != '' && $('#txtI_Date').val() != '')
		{
			document.frm1.submit();
		}
		else
		{
			jAlert('Please fill Payment No., Vendor Invoice Amount and Invoice Date', 'Alert');
			return false;
		}
	}
	else
	{
		return false;
	}
	});
}



function getValid()
{
	if($('#txtfile').val() == '')
	{
		jAlert('Please choose the file', 'Alert');
		return false;
	}
	else
	{
		return true;
	}
}

function getPdf(var1)
{
	location.href='allPdf.php?id=60&req_id='+var1+'&comid='+<?php echo $comid;?>+'&name_id='+<?php echo $senddata[0];?>+'&grade='+<?php echo $senddata[2];?>+'&name='+<?php echo "'".$senddata['1']." : ".$_REQUEST['name']."'";?>+'&vendorid='+<?php echo "'".$vendorid."'";?>+'&randomid='+<?php echo "'".$randomid."'";?>+'&ttl_outs='+<?php echo $senddata[5];?>;
}

function getDel(req_id)
{
	jConfirm('Are you sure you want to Delete this Entry?', 'Confirmation', function(r) {
	if(r)
	{
		$('#action').val('submit2');
		$('#txtID').val(req_id);
		document.frm1.submit();
	}
	else
	{
		return false;
	}
	});
}

function getDeduction()
{
    $("#txtAddDesTotalAmt").val(parseFloat($("[id^=txtAddDesAmt_]").sum()).toFixed(2));
	$("#txtSubDesTotalAmt").val(parseFloat($("[id^=txtSubDesAmt_]").sum()).toFixed(2));
	var add1 = parseFloat($("#txtAddDesTotalAmt").val());
	if(isNaN(add1)){add1 = 0;}
	var sub1 = parseFloat($("#txtSubDesTotalAmt").val());
	if(isNaN(sub1)){sub1 = 0;}
	var ttl = (parseFloat($("[id^=txtVC_DED_]").sum())).toFixed(2);
	var net = (parseFloat($('#txtBal_Outs').val()) + parseFloat(add1) - parseFloat(sub1)).toFixed(2);
	
	$('#txtNET').val(net);
}



function AddNewAddRow()
{
	var id = $("#txtAddID").val();
	if($("#txtAddDes_"+id).val() != "" && $("#txtAddDesAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="add_Row_'+id+'"><td align="center"><a href="#pr1" onClick="removeAddRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td><td><textarea class="form-control areasize" name="txtAddDes_'+id+'" id="txtAddDes_'+id+'" rows="2" placeholder="Description..."></textarea></td><td><input type="text" name="txtAddDesAmt_'+id+'" id="txtAddDesAmt_'+id+'" class="form-control"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getAmountThereOff();"/></td></tr>').appendTo("#tblAdd");
		$("#txtAddID").val(id);
		$("[id^=txtAddDesAmt_]").numeric();	
	}
}


function removeAddRow(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#add_Row_"+var1).remove();
					getDeduction();
				 }
			else{return false;}
			});
}



function SubNewSubRow()
{
	var id = $("#txtSubID").val();
	if($("#txtSubDes_"+id).val() != "" && $("#txtSubDesAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="Sub_Row_'+id+'"><td align="center"><a href="#pr1" onClick="removeSubRow(1);"><i class="fa fa-times" style="color:red;"></i></a></td><td><textarea class="form-control areasize" name="txtSubDes_'+id+'" id="txtSubDes_'+id+'" rows="2" placeholder="Description..."></textarea></td><td><input type="text" name="txtSubDesAmt_'+id+'" id="txtSubDesAmt_'+id+'" class="form-control"  placeholder="Amount" autocomplete="off" value="" onKeyUp="getAmountThereOff();"/></td></tr>').appendTo("#tblSub");
		$("#txtSubID").val(id);
		$("[id^=txtSubDesAmt_]").numeric();	
	}
}


function removeSubRow(var1)
{
	jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#Sub_Row_"+var1).remove();
				getDeduction();
			 }
		else{return false;}
		});
}



function getValid()
{
	if($('#txtP_PR').val() == '' || $('#txtP_Date').val() =='' || $('#txtP_Remarks').val()=='')
	{
		jAlert('Please fill the Payment Received & Date & Remarks', 'Alert');
		return false;
	}
	else
	{
		var file_temp_name = $("[id^=file1_]").map(function () {return this.value;}).get().join(",");
	    $('#txtCRMFILE1').val(file_temp_name);
	    var file_actual_name = $("[id^=name1_]").map(function () {return this.value;}).get().join(",");
	    $('#txtCRMNAME1').val(file_actual_name);
		document.frm1.submit();
		return true;
	}
}

function Del_Upload1(var2)
{
	jConfirm('Are you sure you want to delete this upload permanently ?', 'Confirmation', function(r) {
	if(r){ 
		$('#row_file1_'+var2).remove();
	}
	});
}

function onkeyUp1()
{
	if(parseFloat($('#txtP_PR').val()) > parseFloat($('#txtP_Amt').val()))
	{
		jAlert('Payment Received is more than Amount', 'Alert');
		$('#txtP_PR').val(0.00);
	}
}


function openWin1(var1)
{
	$("#divPayment").empty();
	$("#divPayment").html('<div><img src="../../img/ajax-loader.gif" /><br><b>Loading...</b></div>'); 
	$.post("options.php?id=47",{invoiceid:""+var1+""}, function(html) {
		$("#divPayment").empty();
		$("#divPayment").append(html);
		
		$("#txtP_PR").numeric();
        $('#txtP_Remarks').autosize({append: "\n"});
		$('#txtP_Date').datepicker({
			format: 'dd-mm-yyyy',
			autoclose:true
		});
	});
}

</script>
    </body>
</html>