<?php session_start(); ?> <!-- session start -->
<?php include("../include/config.php"); ?> <!-- database connection -->
<?php include("../include/connect_url.php"); ?> <!-- connection url/link folder -->
<?php include("../include/date_time.php"); ?> <!-- date & time format -->
<?php include("../database/account.php"); ?> <!-- query database account -->
<?php include("../include/lang.php"); ?> <!-- language -->
<?php include("../include/session_login.php"); ?> <!-- session login -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title><?php echo $lang['Add Charge']; ?></title>

<link rel="shortcut icon" href="<?php echo $connect_url_data; ?>/favicon.ico" />

<link href="<?php echo $connect_url_data; ?>/css/styles.css" rel="stylesheet" type="text/css" />
<!--[if IE]> <link href="<?php echo $connect_url_data; ?>/css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->
<link rel="stylesheet" href="<?php echo $connect_url_data; ?>/font/font-awesome-4.3.0/css/font-awesome.min.css">

<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/download/jquery183.js"></script> 
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/download/jquery192.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/charts/jquery.sparkline.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.collapsible.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.breadcrumbs.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/plugins/ui/jquery.easytabs.min.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data; ?>/js/files/functions_blank_no_sidebar.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data ?>/datatable/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="<?php echo $connect_url_data ?>/datatable/js/columnFilter.js"></script>

<script type="text/javascript" src="<?php echo $connect_url_data ?>/js/files/bootstrap.js"></script>

</head>

<body>

<!-- header-->
<?php include("../template/header.php"); ?>

<!-- sidebar-->
<?php include("../template/sidebar.php"); ?>
   
<!-- Content begins -->
<div id="content">
    
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="<?php echo $connect_url_data; ?>/dashboard"><?php echo $lang['Dashboard']; ?></a></li>
                <li class="current"><a href="#"><?php echo $lang['Add Charge']; ?></a></li>
            </ul>
        </div>
        
<!-- breaklink -->
<?php include("../menu/breadlink.php"); ?>
	
    </div>
    
    <!-- Main content -->
    <div class="wrapper">
	
<?php
$query_transaction2 = mysql_query("SELECT * FROM tbl_transaction WHERE id='$_GET[transaction_id]'"); 
while($row= mysql_fetch_assoc($query_transaction2))
{
    $db_transaction2_id = $row['id'];
    $db_transaction2_transaction_no = $row['transaction_no'];
    $db_transaction2_patient_id = $row['patient_id'];
    $db_transaction2_pt_type_id = $row['pt_type_id'];
    $db_transaction2_remark = $row['remark'];
    $db_transaction2_user_id = $row['user_id'];
    $db_transaction2_date = $row['date'];
    $db_transaction2_time = $row['time'];
    $db_transaction2_a_status = $row['a_status'];
}
?>

<?php
$query_patient_type2 = mysql_query("SELECT * FROM tbl_patient_type WHERE id='$db_transaction2_pt_type_id'"); 
while($row= mysql_fetch_assoc($query_patient_type2))
{
    $db_patient_type2_id = $row['id'];
    $db_patient_type2_patient_type = $row['patient_type'];
}
?>


<?php    
$query_patient2 = mysql_query("SELECT * FROM tbl_patient WHERE id='$db_transaction2_patient_id'"); 
while($row= mysql_fetch_assoc($query_patient2))
{
    $db_patient2_id = $row['id'];
    $db_patient2_patient_no = $row['patient_no'];
    $db_patient2_image = $row['image'];
    $db_patient2_firstname = $row['firstname'];
    $db_patient2_middlename = $row['middlename'];
    $db_patient2_middlename_str = substr($db_patient2_middlename,0,1);
    $db_patient2_lastname = $row['lastname'];
    $db_patient2_birth_date = $row['birth_date'];
    $db_patient2_gender = $row['gender'];
    $db_patient2_civil_status_id = $row['civil_status_id'];
    $db_patient2_nationality_id = $row['nationality_id'];
    $db_patient2_address = $row['address'];
    $db_patient2_phone_no = $row['phone_no'];
    $db_patient2_mobile_no = $row['mobile_no'];
    $db_patient2_email = $row['email'];
    $db_patient2_ref_name = $row['ref_name'];
    $db_patient2_ref_relationship_id = $row['ref_relationship_id'];
    $db_patient2_ref_address = $row['ref_address'];
    $db_patient2_ref_phone_no = $row['ref_phone_no'];
    $db_patient2_ref_mobile_no = $row['ref_mobile_no'];
    $db_patient2_date = $row['date'];
    $db_patient2_time = $row['time'];
    $db_patient2_a_status = $row['a_status'];
}
?>

<?php
if($_POST)
{

$remark =mysql_real_escape_string($_POST['remark']);

if($remark==""){
die ("<script> alert('Please fill remarks.');
window.location.href='javascript:history.back();';		
</script> ");
}

$sql = "UPDATE tbl_transaction_charge SET remark='$remark', a_status='1' WHERE  transaction_id='$db_transaction2_id'  AND user_id='$db_user_id' AND a_status='2' ";
$result = mysql_query($sql) or die("Error: Failed to Update!");

die ("<script> alert('Charged.');
window.location.href='$connect_url_data/charge/a/$db_transaction2_id';		
</script> ");
}
?>
    
    
<?php
if($_GET['type']=="delete"&&$_GET['tci_id']){
$sql = "UPDATE tbl_transaction_charge_item SET  a_status='3' WHERE id ='$_GET[tci_id]' AND a_status='1'";
$result = mysql_query($sql) or die("Error: Failed to Update!");      
    
die ("<script> alert('Deleted.');
window.location.href='$connect_url_data/charge/a/$db_transaction2_id';		
</script> ");   
}
?>

<form name="form" id="form" action="<?php echo $connect_url_data; ?>/charge/a/<?php echo $db_transaction2_id; ?>" class="main" method="POST"  enctype="multipart/form-data">
            <fieldset>
                <div class="widget fluid">
                    <div class="whead"><h6><span class="fa fa-plus-circle" style="margin-top:-2px;"></span>&nbsp; <?php echo $lang['Add Charge']; ?> </h6></div>
                    
		    <div class="formRow">
                        <div class="grid1"><label><?php echo $lang['Patient']; ?>:</label></div>
                        <div class="grid3"><input type="text" value="<?php echo "$db_patient2_firstname $db_patient2_middlename_str. $db_patient2_lastname"; ?>" style="background:#eee;font-weight:bold;" disabled/></div>
                        <div class="grid1"><label><?php echo $lang['Patient Type']; ?>:</label></div>
                        <div class="grid3"><input type="text" value="<?php echo $db_patient_type2_patient_type; ?>" style="background:#eee;" disabled/></div>
			            <div class="grid1"><label><?php echo $lang['Trans No']; ?>:</label></div>
                        <div class="grid3"><input type="text" value="<?php echo "#$db_transaction2_transaction_no"; ?>" style="background:#eee;" disabled/></div>
		    </div>
		    
		      <div class="formRow">
                        <div class="grid1"><label><?php echo $lang['Remarks']; ?>:</label></div>
                        <div class="grid3"><input type="text" name="remark" id="remark" /></div>
			 <div class="grid1"><label><?php echo $lang['Staff/User']; ?>:</label></div>
			 <div class="grid3"><input type="text" value="<?php echo $db_user_firstname; ?>" style="background:#eee;" disabled/></div>
			 <div class="grid1"><label><?php echo $lang['Date/Time']; ?>:</label></div>
			 <div class="grid3"><input type="text" value="<?php echo "$date $time"; ?>" style="background:#eee;" disabled/></div>
		    </div>
		      
<div class="formRow" ><h4><span class="fa fa-plus-circle" style="margin-top:-2px;"></span> <?php echo $lang['Add Charge']; ?> ( <span class="icon-user" style="margin-top:2px;margin-left:5px;"></span><?php echo "$db_patient2_firstname $db_patient2_middlename_str. $db_patient2_lastname | $db_patient2_patient_no"; ?> )</h4>

<div style="position:relative;height:1px;left:-15px;float:right;top:-35px;z-index:10;">
  <a class="buttonM bGold" href="#" onclick="window.open('<?php echo $connect_url_data; ?>/charge/item/<?php echo $db_transaction2_id; ?>', 'popup1',  'status,menubar=0,resizable=0,scrollbars=1,top=50,left=40,width=1250,height=550')"  style="border-radius:5px;"><span class="fa fa-dropbox"></span><span><?php echo $lang['Item & Service']; ?></span></a>
</div>

<script type="text/javascript" charset="utf-8">      
$(document).ready(function () {
  
  oTable =$('#item-datatable').dataTable(
  {
    
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
      
if ( aData[0]){$('td:eq(0)', nRow).html( '<center><i class="fa fa-dropbox"></i></center>');}

if ( aData[0]){$('td:eq(7)', nRow).html("<center><a href='#' onclick=\"window.open('<?php echo $connect_url_data; ?>/charge/e/"+ aData[0] +"', 'popup1',  'status,menubar=0,resizable=0,top=50,left=50,width=1220,height=550')\" class='btn' rel='tooltip' title='Edit'><i class='fa fa-edit'></i> <?php echo $lang['Edit']; ?></a>&nbsp;&nbsp;<a href='<?php echo $connect_url_data; ?>/charge/a/<?php echo $db_transaction2_id; ?>&tci_id="+aData[0]+"&type=delete' onclick=\"return confirm('Are you sure you want to delete this item?')\"><i class='fa fa-times'></i> <?php echo $lang['Delete']; ?></a></center>");}
      
     },
"iDisplayLength": 500,
"bFilter": false,
"bPaginate": false,
"sPaginationType": "full_numbers",
//"aaSorting": [[ 2, "asc" ]],
"sDom": '<"top"f>rt<"bottom"i><"bottom"p>',
"bAutoWidth": false,
"oLanguage": {
"sSearch": "<i class='fa fa-search' style='margin-left:20px;'></i>"
},

"sAjaxSource": "<?php echo $connect_url_data; ?>/charge/charge-add-datatable.php?transaction_id=<?php echo $db_transaction2_id; ?>",
"aoColumns": [
    { "mData": null },
           null,
           null,
           null,
	   null,
	   null,
	   null,
    { "mData": null },
           
         ]          
  });

$('.dataTables_filter input').attr("placeholder", "<?php echo $lang['Search Keywords']; ?>");

});
//end ready function

function RefreshTable(tableId, urlData)
{
  $.getJSON(urlData, null, function( json )
  {
    table = $(tableId).dataTable();
    oSettings = table.fnSettings();
    
    table.fnClearTable(this);

    for (var i=0; i<json.aaData.length; i++)
    {
      table.oApi._fnAddData(oSettings, json.aaData[i]);
    }

    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    table.fnDraw();
  });
}

function AutoReload()
{
  RefreshTable('#item-datatable', '<?php echo $connect_url_data; ?>/charge/charge-add-datatable.php?transaction_id=<?php echo $db_transaction2_id; ?>');
 
  setTimeout(function(){AutoReload();}, 1000);
}

$(document).ready(function () {
  setTimeout(function(){AutoReload();}, 1000);
});

</script>

<div class="shownpars">					
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dTable" id="item-datatable">
<thead>
    <tr>
	<th width="3%"></th>
	<th width="14%"><?php echo $lang['Item No/ Barcode']; ?></th>
	<th width="25%"><?php echo $lang['Item Name']; ?></th>
	<th width="14%"><?php echo $lang['Category']; ?></th>
	<th width="8%"><?php echo $lang['Qty']; ?></th>
	<th width="13%"><?php echo $lang['Price']; ?></th>
	<th width="13%"><?php echo $lang['Total']; ?></th>
	<th width="10%"><?php echo $lang['Action']; ?></th>
    </tr>	
</thead>
<tbody>

</tbody>
</table>
</div>
</div>

	
	
		      
		    <div class="formRow">
			
                 
                    <div class="grid6">
			<a href="#" class="buttonM bBlue" onclick="document.getElementById('form').submit();"><span class="fa fa-plus-circle"></span><span><?php echo $lang['Charge & Save']; ?> &nbsp;&nbsp;&nbsp;</span></a>
		        <a href="<?php echo $connect_url_data; ?>/<?php if($db_transaction2_pt_type_id==1){echo"inpatient";}else{echo "outpatient";}?>" class="buttonM bBlue"><span class="fa fa-times-circle"></span><span><?php echo $lang['Cancel']; ?></span></a>
		    </div>
		    
<script>
function total_amount()
{
$("#total_amount").load("<?php echo $connect_url_data; ?>/charge/total.php?transaction_id=<?php echo $db_transaction2_id; ?>");// a function which will load data from other file after x seconds
}
 setInterval('total_amount()', 100);
</script> 
		    
		    
		     <div class="grid6" style="float:right;text-align:right">
			<div id="total_amount"></div>
		     </div>
		    
		    </div>
                  
                </div>
            </fieldset>

	    
	    
        </div>
	
    </div>
    <!-- Main content ends -->
    
</div>
<!-- Content ends -->  
             
</body>
</html>
