<?php
include('../config/config.php');
include('../classes/classProduct.php');
include('../classes/classReceiveInvoice.php');
include('../classes/classTransaction.php');
include('../classes/classProductClosingReconcilation.php');

/*echo '<pre>';
print_r($_POST);
print_r($_SESSION);
echo '</pre>';
exit;
*/
################## Delete Receive Invoice Start ####################################

if(isset($_GET['delrecinvoice'])&&$_GET['delrecinvoice']!='')
{
	try
	{
		$delRecInvOb = new classReceiveInvoice;
		$delRecInvOb->setReceiveInvoiceID(base64_decode($_GET['delrecinvoice']));
		$delRecInvOb->deleteReceiveInvoice();
		header("Location:mgmtincoming.php");
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}
}
unset($_SESSION['print']);
$retrieveInvoiceOb = new classReceiveInvoice;
if(isset($_POST['search_invoice_by_date'])&&$_POST['search_invoice_by_date']!='')
{
	$_SESSION['print']['search_invoice_by_date'] = $_POST['search_invoice_by_date'];
	$invoice_array = $retrieveInvoiceOb->retrieveInvoiceDetailByDate($_POST['search_invoice_by_date'],$_SESSION['security']['location_id']);
}
elseif(isset($_GET['view'])&&$_GET['view']=='all')
{
	$_SESSION['print']['view'] = $_GET['view'];
	$retrieveInvoiceOb->setLocationID($_SESSION['security']['location_id']);
	$invoice_array = $retrieveInvoiceOb->retrieveInvoiceDetailByLocationID();	
}
else
{
	$date = date('Y-m-d',time());
	$invoice_array = $retrieveInvoiceOb->retrieveInvoiceDetailByDate($date,$_SESSION['security']['location_id']);
}

$total_invoices = 0;
$total_payables = 0;
$total_payments = 0;
  
if(isset($invoice_array[0]['recinvoice_id'])&&$invoice_array[0]['recinvoice_id']!='')
{
 	for($int=0;$int<count($invoice_array);$int++)
	{
	  $total_invoices ++;
	  $total_payables += $invoice_array[$int]['amount_payable'];
	  $total_payments += $invoice_array[$int]['payment'];
	}
}

try
{
	$tranOb = new classTransaction;
	$account_data = $tranOb->retrieveAccountHeadAndAccountByID(3,4);	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}
$location_id = $_SESSION['security']['location_id'];
$query = "SELECT * FROM product_supplier_relationship JOIN product_recinvoice on product_supplier_relationship.supplier_id = product_recinvoice.supplier_id";
$queryOb = new classQueryGlobal;
$product_supplier_relationship = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");

if(isset($product_supplier_relationship[0]['recinvoice_id'])&&$product_supplier_relationship[0]['recinvoice_id']!='')
{
	for($i=0;$i<count($product_supplier_relationship);$i++)
	{
		$unittrade_price = $product_supplier_relationship[$i]['unit_tradeprice'];
		$recinvoice_id = $product_supplier_relationship[$i]['recinvoice_id'];
		$product_id = $product_supplier_relationship[$i]['product_id'];
		
		$query = "UPDATE product_recitems SET unittrade_price = '$unittrade_price' WHERE recinvoice_id = '$recinvoice_id' AND product_id = '$product_id'";
		$queryOb = new classQueryGlobal;
		$queryOb->check_fetch_query($query,'update',$server="",$debug_mode="off");
		
	}
}


/*echo '<pre>';
print_r($product_supplier_relationship);
echo '</pre>';
exit;*/

?>
<!DOCTYPE html><html><!-- InstanceBegin template="/Templates/main.dwt.php" codeOutsideHTMLIsLocked="false" -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head> 
    <link rel="shortcut icon" href="../images/favicon.png">
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Med2TEC Hospital Management Information System</title>
    <!-- InstanceEndEditable -->
    <!--Core CSS -->
    <link href="../bs3/css/bootstrap.min.css" rel="stylesheet">
    <link href="../assets/jquery-ui/jquery-ui-1.10.1.custom.min.css" rel="stylesheet">
    <link href="../css/bootstrap-reset.css" rel="stylesheet"> 
    <link href="../css/css/font-awesome.css" rel="stylesheet">
    <link href="../css/css/font-awesome.min.css" rel="stylesheet">
    <link href="../assets/jvector-map/jquery-jvectormap-1.2.2.css" rel="stylesheet">
    <link href="../css/clndr.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../assets/jquery-multi-select/css/multi-select.css" />
    <!--clock css-->
    <link href="../assets/css3clock/css/style.css" rel="stylesheet"> 
    <!--Morris Chart CSS -->
    <link rel="stylesheet" href="../assets/morris-chart/morris.css">
    <!-- Custom styles for this template -->
    <link href="../css/style.css" rel="stylesheet">
    <link href="../css/style-responsive.css" rel="stylesheet"/> 
    <link rel="stylesheet" href="../popUp/popUp.css" />
    <link href="../css/custom.css" rel="stylesheet"/>
    <link href="../css/bootstrap-fullcalendar.css" rel="stylesheet"/> 
     <link rel="stylesheet" href="../datepicker/jquery-ui.css">   
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body>

<section id="container">
    <!--header start-->
    <header class="header fixed-top clearfix">
        <!--logo start-->
        <div class="brand">

            <a href="home.php" class="logo">
                <img src="../images/logo.png" alt="">
            </a>
            <div class="sidebar-toggle-box">
                <div class="fa fa-bars"></div>  
            </div>
        </div> 
        <!--logo end-->

        <div class="nav notify-row" id="top_menu" style="float: right; margin-top: 16px; margin-left: 0px; margin-right: 10px;">
            <!--  notification start -->
             <img alt="" src="../images/org_logos/<?php echo $_SESSION['security']['org_id']?>.png">
            <!--  notification end -->
        </div>
        <div class="top-nav clearfix">
            <!--search & user info start-->
            <ul class="nav pull-right top-menu">
                <li>
                    <div class="toggle-right-box"><!-- InstanceBeginEditable name="print" -->
                    <a href="javascript:Popup('printmgmtincoming.php')"><i class="fa fa-print" style="margin-left: 11px; margin-top: 11px;"></i></a>
					<!-- InstanceEndEditable --></div>
                </li>
                <!-- user login dropdown start-->
                <li class="dropdown">
                    <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                        <img alt="" src="../images/avatar1_small.jpg"> 
                        <span class="username"><?php echo $username;?></span>
                        <b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu extended logout">
                        <li><a href="profile.php"><i class=" fa fa-suitcase"></i>Profile</a></li>
                        <li><a href="#update_password-box" class="update_password-window"><i class="fa fa-cog"></i> Change Password</a></li>
                        <li><a href="../logout.php"><i class="fa fa-key"></i> Log Out</a></li>
                    </ul>
                </li>
                <!-- user login dropdown end -->
                <li>
                    <div class="toggle-right-box">
                        <div class="fa fa-bars"></div>
                    </div>
                </li>
            </ul>
            <!--search & user info end-->
        </div>
    </header>
    <!--header end-->
    <!--sidebar start-->
   <aside>
        <div id="sidebar" class="nav-collapse">
            <!-- sidebar menu start-->
            <ul class="sidebar-menu" id="nav-accordion">
					  	<li>
                    	<a class="active" href="db.php" style="background:#0072BC;">
                        <i class="fa fa-dashboard"></i>
                        <span>Dashboard</span>
                    	</a>
                		</li>
					  <?php
					  
				
					  
$orgOb = new classUser;
$orgOb->retrieveOrgDataByOrgID($_SESSION['security']['org_id']);
           
		  
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==5||$_SESSION['security']['userrole_id']==9||$_SESSION['security']['userrole_id']==10)
				{
					?>
					    <li class="sub-menu">
                    	<a href="dbpatient.php" style="background:#BC1C4A;">
                        <i class="fa fa-user"></i>
                        <span>Patient Registration</span>
                    	</a>
                    	</li>
					  <?php
				}
		  
		  if($orgOb->getOPD())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==4||$_SESSION['security']['userrole_id']==5||$_SESSION['security']['userrole_id']==9)
				{
					?>
						<li class="sub-menu">
						<a href="dbopd.php" style="background:#003366;">
						<i class="fa fa-th"></i>
						<span>Out-Patient (OPD)</span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getIPD())
		  {
			  	?>
						<li class="sub-menu">
						<a href="dbipd.php" style="background:#3AC7F9;">
						<i class="fa fa-th"></i>
						<span>In-Patient (IPD)</span>
						</a>
						</li>
						<?php
					
		  }
		  if($orgOb->getOT())
		  {
			   		?>
						<li class="sub-menu">
						<a href="dbot.php" style="background:#D6502A;">
						<i class="fa fa-th"></i>
						<span>Operation Theater</span>
						</a>
						</li>
                        <?php
		  }			
		  if($orgOb->getPharmacy())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==6||$_SESSION['security']['userrole_id']==7||$_SESSION['security']['userrole_id']==8||$_SESSION['security']['userrole_id']==9)
				{
			  		?>
						<li class="sub-menu">
						<a href="dbpharmacy.php" style="background:#00869C;">
						<i class="fa fa-th"></i>
						<span>Pharmacy</span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getDiagnostic())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==14||$_SESSION['security']['userrole_id']==9)
				{
			  	?>
						<li>
						<a href="dbdiagnostics.php" style="background:#380E4D;">
						<i class="fa fa-th"></i>
						<span>Diagnostics </span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getEmergency())
		  {
					  ?>
						<li class="sub-menu">
						<a href="dbemergency.php" style="background:#8EC63F;">
						<i class="fa fa-tasks"></i>
						<span>Emergency </span>
						</a>
						</li>
						<?php
		  }
          if($orgOb->getAdmin())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==9)
				{
					?>
						<li class="sub-menu">
						<a href="dbadmin.php" style="background:#28282E;">
						<i class="fa fa-laptop"></i>
						<span>Admin Panel</span>
						</a>
						</li>
						<?php
				}
		  }
		  ?>
               
            </ul> 
            <div style="position: absolute; bottom: 2%; padding-left:10%;"><a href="http://www.softusion.com/" target="_blank"><img width="30" height="40" src="../images/SoftusionLOGO.png" alt=""><span style="font-size: 11px; float: right; margin-top: 15%;">Designed by Softusion Inc.</span></a></div><br>
            <!-- sidebar menu end-->
        </div>
    </aside>
    <!--sidebar end-->
    <!--main content start-->
	<!-- InstanceBeginEditable name="center" -->
  <section id="main-content">
    <section class="wrapper">
     <table cellspacing="0" cellpadding="0" width="100%" border="0" style="font-size:11px;">
  <tbody>
    <tr>
      <td width="12%" align="center"><a href="dbpharmacy.php"><img src="../images/icondb.png"></a></td>
      <td width="12%" align="center"><a href="mgmtincoming.php"><img src="../images/iconinvoice.png"></a></td>
       <td width="12%" align="center">
      <?php
	 	$checkReportOb = new classProductClosingReconcilation;
	  if($checkReportOb->checkClosingReportAlreadyInProgress('in_progress',$_SESSION['security']['location_id']))
	  {
		  ?>
		  <a href="pharmrecinv.php?ref=<?php echo base64_encode('new');?>"><img src="../images/iconhistory.png" /></a>
		  <?php
	  }
	  else
	  {
			?>
			<a href="#" onClick="return inventoryclosing();"><img src="../images/iconhistory.png" /></a>
			<?php
	  }
	  ?>
      </td>    
      <td width="12%" align="center"><a href="addprod.php"><img src="../images/iconproduct.png"></a></td>
      <td width="12%" align="center"><a href="pharminventory.php"><img src="../images/iconinventory.png"></a></td>
      <td width="12%" align="center"><!--<a href="mgmtorders.php"><img src="../images/iconsupplier.png"></a>--></td>
      <td width="12%" align="center"></td>
      <td width="12%" align="center"></td>
      <td width="2%" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td align="center"><a href="dbpharmacy.php">Pharmacy</a></td>
      <td align="center"><a href="mgmtincoming.php">Incoming Products</a></td>
       <td align="center">
       <?php
	  $checkReportOb = new classProductClosingReconcilation;
	  if($checkReportOb->checkClosingReportAlreadyInProgress('in_progress',$_SESSION['security']['location_id']))
	  {
		  ?>
		  <a href="pharmrecinv.php?ref=<?php echo base64_encode('new');?>">Create Invoice</a>
		  <?php
	  }
	  else
	  {
			?>
			<a href="#" onClick="return inventoryclosing();">Create Invoice</a>
			<?php
	  }
	  ?>
      </td> 
      <td align="center"><a href="addprod.php">Add Product</a></td>
      <td align="center"><a href="pharminventory.php">Products Inventory</a></td>
      <td align="center"><!--<a href="mgmtorders.php">Product Orders</a>--></td>
      <td align="center"></td>
      <td align="center"></td>
      <td height="24" align="center">&nbsp;</td>
    </tr>
  </tbody>
</table>

<br> 
      <!-- page start-->
      <div class="row">
        <div class="col-sm-12">
          <section class="panel">
			<header class="panel-heading">
              <h2>INCOMING INVOICES</h2>
            </header>
             <?php
			if(isset($error_message)&&$error_message!='')
			{
				?>
                <span class="message_red"><?php echo $error_message;?></span>
                
				<?php
			}
			?>
            <table width="100%" border="0" cellspacing="5" cellpadding="5">
              <tr>
              
                <td width="10%" align="right" valign="bottom">Search By Date:</td>
                
                <td width="20%" valign="bottom">
                <form action="" method="post" id="form_incoming">
                <input type="text" name="search_invoice_by_date" value="" id="datepicker" class="form-control" readonly style="display:inline; width:90%;">
                </form>
                 
                </td>
                
                <td width="20%" align="left" valign="bottom">
                <?php
				if(isset($_GET['view'])&&$_GET['view']=='all')
				{
					?>
                	<a href="mgmtincoming.php">Today Incoming</a>    
                    <?php
					
				}
				else
				{
					?>
                	<a href="mgmtincoming.php?view=all">View All</a>    
                    <?php
				}
				?>
                
                </td>
                
                <td width="70%" align="right">
                <div class="col-md-4" style="float: right; width:60%;">
                <div class="profile-nav alt">
                  <section class="panel">
                    <div class="user-heading alt clock-row terques-bg">
                      <h1><?php echo date('d F Y',time());?></h1>
                      <p class="text-left"><?php echo date('h:i A',time());?></p></br>
                      <p class="text-left"></p>
                      <span>Total Invoices: <div style="float:right;"><?php echo $total_invoices;?></div></span></br>
                      <span>Total Payables: <div style="float:right;">Rs. <?php echo number_format($total_payables,2);?></div></span></br>
                      <span>Total Payments: <div style="float:right;">Rs. <?php echo number_format($total_payments,2);?></div></span>
                    </div>
                  </section>
                </div>
          		</div>
          		</td>
                
              </tr>
            </table><br>
<br>
          
           <div class="panel-body" style="padding-top: 0px; margin-top: -34px;">
              <div class="adv-table">
                <table  class="display table table-bordered table-striped" id="dynamic-table">
                  <thead>
                    <tr>
                      <th width="5%" align="center">&nbsp;</th>
                      <th width="5%" align="center">ID</th>
                      <th width="10%" align="center">Date</th>
                      <th width="20%">Supplier Name</th>
                      <th width="15%">Invoice Total</th>
                      <th width="5%">Discount</th>
                      <th width="15%">Amount Payable</th>
                      <th width="15%">Payment</th>
                      <th width="15%">Balance</th>
                      <th width="10%" align="center" class="hidden-phone">Status</th>
                      <th width="5%" align="center" class="hidden-phone"></th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
				  if(isset($invoice_array[0]['recinvoice_id'])&&$invoice_array[0]['recinvoice_id']!='')
				  {
					  for($inv=0;$inv<count($invoice_array);$inv++)
					  {
						  if($inv%2==0){ $class = 'gradeX';}else{$class = 'gradeC';}
						  
						  $suppOb = new classProduct;
						  $supp_info = $suppOb->retrieveSupplierBySupplierID($invoice_array[$inv]['supplier_id']);
						  $supplier_name = $supp_info[0]['supplier_name'];
						 
						?>
						<tr class="<?php echo $class;?>">
                        
						  <td align="center">
                          <?php
						  if($invoice_array[$inv]['payment_status']!="paid") 
						  {
							  $checkReportOb = new classProductClosingReconcilation;
							  if($checkReportOb->checkLastClosingReportReconciled($_SESSION['security']['location_id']))
							  {
								  ?>
								  <a href="pharmrecinv.php?recinvoice_id=<?php echo base64_encode($invoice_array[$inv]['recinvoice_id']);?>&supplier_id=<?php echo base64_encode($invoice_array[$inv]['supplier_id']);?>">Edit</a>
								  <?php
							  }
							  else
							  {
									?>
									<a href="#" onClick="return inventoryclosing();">Edit</a>
									<?php
							  }
						  }
						  else
						  {
								?>
								<a href="pharmrecinvvw.php?recinvoice_id=<?php echo base64_encode($invoice_array[$inv]['recinvoice_id']);?>&supplier_id=<?php echo base64_encode($invoice_array[$inv]['supplier_id']);?>">View</a>
								<?php 
						  }
						  ?>
                          
                          </td>
                          
						  <td align="center"><?php echo $invoice_array[$inv]['recinvoice_id'];?></td>
                          
						  <td align="center"><?php echo date('d M Y',$invoice_array[$inv]['recinvoice_date']);?></td>
                          
						  <td><?php echo $supplier_name;?></td>
                          
                          <td align="right">Rs. <?php if($invoice_array[$inv]['invoice_amount']!=0){echo number_format($invoice_array[$inv]['invoice_amount'],2);}else{echo 0; }?></td>
                          
						  <td align="right"><?php echo $invoice_array[$inv]['discount'];?>%</td>
                          
                          
						  <td align="right">Rs. <?php if($invoice_array[$inv]['amount_payable']!=0){echo number_format($invoice_array[$inv]['amount_payable'],2);}else{echo 0; }?></td>
                          
						  <td align="right">Rs. <?php if($invoice_array[$inv]['payment']!=0){echo number_format($invoice_array[$inv]['payment'],2);}else{echo 0; }?></td>
                          
						  <td align="right">Rs. <?php if($invoice_array[$inv]['balance']!=0){echo number_format($invoice_array[$inv]['balance'],2);}else{echo 0;}?>
                           <?php
                           if($invoice_array[$inv]['balance']>0&&$invoice_array[$inv]['payment_status']=="paid") 
                            {
									?>
								  <a href="#transaction_expense-box" class="transaction_expense-window transaction_expense_data" id="<?php echo $inv;?>"><span class="label label-danger label-mini">Balance Payment</span></a>
								  <?php
								}
							  ?>
                          </td>
                          
						  <td align="center">
							<?php
                            if($invoice_array[$inv]['payment_status']=="paid") 
                            {
								?>
                                <span class="label label-success label-mini">Paid</span>
                                <?php 
                            }
							else
                            {
								?>
                                <a href="#transaction-box" class="transaction-window transaction_data" id="<?php echo $inv;?>"><span class="label label-danger label-mini">Make Payment</span></a>
                                <?php 
                            }
                            ?>
                          
                          </td>
                          
						  <td align="center">
                          <?php
						  if($invoice_array[$inv]['payment_status']!="paid") 
						  {
							  $checkReportOb = new classProductClosingReconcilation;
							  if($checkReportOb->checkLastClosingReportReconciled($_SESSION['security']['location_id']))
							  {
								  ?>
								  <a href="mgmtincoming.php?delrecinvoice=<?php echo base64_encode($invoice_array[$inv]['recinvoice_id']);?>"><img src="../images/delete.png"></a>
								  <?php
							  }
							  else
							  {
									?>
									<a href="#" onClick="return inventoryclosing();"><img src="../images/delete.png"></a>
									<?php
							  }
						  }
						  else
						  {
								?>
								<a href="javascript:Popup1('printpharmrecinv.php?recinvoice_id=<?php echo base64_encode($invoice_array[$inv]['recinvoice_id']);?>&supplier_id=<?php echo base64_encode($invoice_array[$inv]['supplier_id']);?>')">Print</a>
								<?php 
						  }
						  ?>
                          
                          
                          </td>
						</tr>
                        
                        <input type="hidden" name="recinvoice_id" class="set_to_pop" id="recinvoice_id_<?php echo $inv;?>" value="<?php echo $invoice_array[$inv]['recinvoice_id'];?>">
                        <input type="hidden" name="supplier_id" class="set_to_pop" id="supplier_id_<?php echo $inv;?>" value="<?php echo $invoice_array[$inv]['supplier_id'];?>">
                        <input type="hidden" name="amount_payable" class="set_to_pop" id="amount_payable_<?php echo $inv;?>" value="<?php echo $invoice_array[$inv]['amount_payable'];?>">
                        <input type="hidden" name="amount_payable_expense" class="set_to_pop" id="amount_payable_expense_<?php echo $inv;?>" value="<?php echo $invoice_array[$inv]['balance'];?>">
						
						<?php
					  }
				  }
					else
					{
						?>
						<tr>
							<table>
								<tr>
									<td>No entries found!</td>
								</tr>
							</table>
						</tr>
						<?php
					}
				  ?>
                    
                  </tbody>
                  <tfoot>
                  </tfoot>
                </table>
              </div>
            </div>
            
          </section>
        </div>
      </div>
      <!-- page end-->
    </section>
  </section>
  <!-- InstanceEndEditable --><!--main content end-->
<!--right sidebar start-->
 
<!--right sidebar end-->
</section>
<!-- Placed js at the end of the document so the pages load faster -->
<!--Core js-->
<!--<script src="../js/jquery-1.10.2.min.js"></script>-->
  
 
<script src="../assets/jquery-ui/jquery-ui-1.10.1.custom.min.js"></script>
<script src="../bs3/js/bootstrap.min.js"></script>



<script src="../js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../popUp/popUp.js"></script>
<script src="../js/ajax.js"></script>

<script src="../js/lib/jquery.js"></script>
<script src="../assets/fullcalendar/fullcalendar/fullcalendar.min.js"></script>
<script src="../js/calendar/external-dragging-calendar.js"></script>
<script src="../js/accordion-menu/jquery.dcjqaccordion.2.7.js"></script>
<script src="../js/scrollTo/jquery.scrollTo.min.js"></script>
<script src="../js/nicescroll/jquery.nicescroll.js" type="text/javascript"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot-chart/excanvas.min.js"></script><![endif]-->
<script src="../assets/jQuery-slimScroll-1.3.0/jquery.slimscroll.js"></script>
<script src="../assets/skycons/skycons.js"></script>
<script src="../assets/jquery.scrollTo/jquery.scrollTo.js"></script>
<script src="../js/jquery.easing.min.js"></script>
<script src="../assets/calendar/clndr.js"></script>
<script src="../js/underscore-min.js"></script>
<script src="../assets/calendar/moment-2.2.1.js"></script>
<script src="../js/calendar/evnt.calendar.init.js"></script>
<script src="../assets/jvector-map/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../assets/jvector-map/jquery-jvectormap-us-lcc-en.js"></script>
<script src="../assets/gauge/gauge.js"></script>



<!--clock init-->
<script src="../assets/css3clock/js/script.js"></script>
<!--Easy Pie Chart-->
<script src="../assets/easypiechart/jquery.easypiechart.js"></script>
<!--Sparkline Chart-->
<!--Morris Chart-->
<script src="../assets/morris-chart/morris.js"></script>
<script src="../assets/morris-chart/raphael-min.js"></script>
<!--jQuery Flot Chart-->
<script src="../assets/flot-chart/jquery.flot.animator.min.js"></script>
<script src="../assets/flot-chart/jquery.flot.growraf.js"></script>
<script src="../js/dashboard.js"></script>
<script src="../js/custom-select/jquery.customSelect.min.js" ></script>
<!--common script init for all pages-->
<script src="../js/scripts.js"></script>
<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>



<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>
<!--<start===================>-->
<script src="../js/lib/jquery.js"></script>


<script src="../bs3/js/bootstrap.min.js"></script>



<script class="include" type="text/javascript" src="../js/accordion-menu/jquery.dcjqaccordion.2.7.js"></script>

<script src="../js/scrollTo/jquery.scrollTo.min.js"></script>
<script src="../js/nicescroll/jquery.nicescroll.js" type="text/javascript"></script>
<!--Easy Pie Chart-->
<script src="../assets/easypiechart/jquery.easypiechart.js"></script>
<!--Sparkline Chart-->
<script src="../assets/sparkline/jquery.sparkline.js"></script>
<!--jQuery Flot Chart-->
<script src="../assets/flot-chart/jquery.flot.js"></script>
<script src="../assets/flot-chart/jquery.flot.tooltip.min.js"></script>
<script src="../assets/flot-chart/jquery.flot.resize.js"></script>
<script src="../assets/flot-chart/jquery.flot.pie.resize.js"></script>
<script type="text/javascript" src="../assets/bootstrap-daterangepicker/daterangepicker.js"></script>
<script type="text/javascript" src="../assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

<!--dynamic table-->
<!--common script init for all pages-->
<script src="../js/scripts.js"></script>

<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>

<script type="text/javascript" src="../datepicker/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../datepicker/jquery-ui.js"></script>

<!--<script type="text/javascript" src="../popUp/jquery-1.9.0.js"></script>-->
<script type="text/javascript">

 function Popup(apri) { 
	window.open(apri,"","top=10,left=200,width=800,height=700,status=no,menubar=no,toolbar=no,scrollbars=yes"); 
 }
</script> 

<div id="update_password-box" class="update_password-popup">
    
    <div class="pop_header">
        <span>Change Password</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_update_password_form"></div>
          
          <form action="" method="post" id="update_password_form" class="cmxform form-horizontal" onSubmit="return false;">
          	
            <br>
            
         	<div class="form-group">
            <label class="control-label col-lg-3" for="lastname">New Password:</label>
                <div class="col-lg-6">
                    <input type="password" name="password" class="form-control" value="" id="exampleInputPassword1">
                </div>
            </div>
           
            <p align="right">
            	<input type="hidden" name="user_id" value="<?php if(isset($user_id)&&$user_id!=''){echo $user_id;}else{ echo 
				$_SESSION['security']['user_id'];}?>">
                <input type="hidden" name="updateUserPwd" value="yes">
                <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Update"/>
            </p>
            
          </form>
          </td>
          
      </tr>
    </table>
</div> 
 
</body>  
<!-- InstanceEnd --></html> 
<script type="text/javascript">

     function Popup1(apri) { 
        window.open(apri,"","top=10,left=200,width=470,height=600,status=no,menubar=no,toolbar=no,scrollbars=yes"); 
     }
</script>
<div id="transaction-box" class="transaction-popup">
    
    <div class="pop_header">
        <span>Transaction</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_insert_expensetransaction_form" style="margin:10px;"></div>
          
          <form action="" method="post" id="insert_expensetransaction_form" class="cmxform form-horizontal" onSubmit="return false;">
          
           	<div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Head:</label>
              <div class="col-lg-6">
              <input type="hidden" name="acchead_id" value="<?php echo $account_data[0]['acchead_id'];?>">
               <?php echo $account_data[0]['acchead_name'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Name:</label>
              <div class= "col-lg-6">
                <input type="hidden" name="account_id" value="<?php echo $account_data[0]['account_id'];?>">
               <?php echo $account_data[0]['account_name'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Type:</label>
              <div class="col-lg-6">
                 <input type="hidden" name="type" value="<?php echo $account_data[0]['type'];?>">
               <?php echo $account_data[0]['type'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Amount Payable:</label>
              <div class="col-lg-6" id="amount_payable">
               
              </div>
              <input type="hidden" name="amount_payable" id="amount_payable_value" value="">
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Payment Amount:</label>
              <div class="col-lg-6">
                <input type="text" name="payment_amount" id="lastname" class="form-control">
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Description:</label>
              <div class="col-lg-6">
                <textarea name="description" cols="43" rows="5"></textarea>
              </div>
            </div>
            
            <p align="right">
              <input type="hidden" name="supplier_id" id="supplier_id" value="">
              <input type="hidden" name="recinvoice_id" id="recinvoice_id" value="">
              <input type="hidden" name="trx_incoming_prod" value="yes">
              <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Save" />
            </p>
            
          </form>
          </td>
          
      </tr>
    </table>
</div>

<div id="transaction_expense-box" class="transaction_expense-popup">
    
    <div class="pop_header">
        <span>Transaction Expense</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_insert_expensebalancetransaction_form" style="margin:10px;"></div>
          
          <form action="" method="post" id="insert_expensebalancetransaction_form" class="cmxform form-horizontal" onsubmit="return false;">
          
           	<div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Head:</label>
              <div class="col-lg-6">
              <input type="hidden" name="acchead_id" value="<?php echo $account_data[0]['acchead_id'];?>">
               <?php echo $account_data[0]['acchead_name'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Name:</label>
              <div class= "col-lg-6">
                <input type="hidden" name="account_id" value="<?php echo $account_data[0]['account_id'];?>">
               <?php echo $account_data[0]['account_name'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Type:</label>
              <div class="col-lg-6">
                 <input type="hidden" name="type" value="<?php echo $account_data[0]['type'];?>">
               <?php echo $account_data[0]['type'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Amount Payable:</label>
              <div class="col-lg-6" id="amount_payable_expense">
               
              </div>
              <input type="hidden" name="amount_payable" id="amount_payable_expense_value" value="">
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Payment Amount:</label>
              <div class="col-lg-6">
                <input type="text" name="payment_amount" id="lastname" class="form-control">
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Description:</label>
              <div class="col-lg-6">
                <textarea name="description" cols="43" rows="5"></textarea>
              </div>
            </div>
            
            <p align="right">
              <input type="hidden" name="supplier_id" id="supplier_id_expense" value="">
              <input type="hidden" name="recinvoice_id" id="recinvoice_id_expense" value="">
              <input type="hidden" name="trx_incoming_balance" value="yes">
              <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Save" />
            </p>
            
          </form>
          </td>
          
      </tr>
    </table>
</div>

<script>
$(function() {
	$("#datepicker").datepicker({
	showOn: "button",
	buttonImage: "../images/calendar.gif",
	buttonImageOnly: true,
	dateFormat: "yy-mm-dd",
	
	onClose: function(dateText, inst) {
	
    $("#form_incoming").submit();
} 
	/*minDate: '-1'*/
	});
});

$(".transaction_data").click(function() {
	
	var id = this.id;
	
	recinvoice_id = $("#recinvoice_id_"+id).val();
	supplier_id = $("#supplier_id_"+id).val();
	amount_payable = $("#amount_payable_"+id).val();
	
	$("#recinvoice_id").val(recinvoice_id);
	$("#supplier_id").val(supplier_id);
	$("#amount_payable").html(amount_payable);
	$("#amount_payable_value").val(amount_payable);
	
	
});

$(".transaction_expense_data").click(function() {
	
	var id = this.id;
	
	recinvoice_id = $("#recinvoice_id_"+id).val();
	supplier_id = $("#supplier_id_"+id).val();
	amount_payable = $("#amount_payable_expense_"+id).val();
	
	$("#recinvoice_id_expense").val(recinvoice_id);
	$("#supplier_id_expense").val(supplier_id);
	$("#amount_payable_expense").html(amount_payable);
	$("#amount_payable_expense_value").val(amount_payable);
	
	
});
</script>
<script>
function inventoryclosing()
{
	var x;
	var r=alert("Inventory closing is in progress. Please finalize inventory closing process to create new incoming invoices.");
	
	return r;
}
</script>