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

/*echo '<pre>';
print_r($_POST);
print_r($_SESSION);
echo '</pre>';
exit;
*/
if(!$_POST)
{
	unset($_SESSION['supp_data']);
}

if(isset($_GET['delprod_id'])&&$_GET['delprod_id']!='')
{
	try
	{
		$prodStatusOb = new classProduct;
		$prodStatusOb->setProductID($_GET['delprod_id']);
		$prodStatusOb->setActive("0");
		$prodStatusOb->updateProductStatus();
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}
}

if(isset($_POST['Add_New_Product'])&&$_POST['Add_New_Product']=='Add New Product')
{
	if(isset($_SESSION['temp']['prod_id'])&&$_SESSION['temp']['prod_id']!='')
	{
		unset($_SESSION['temp']);
	}
	else
	{
		header("Location:addprod.php");
	}
}

try
{
	if(isset($_POST['add_supp'])&&$_POST['add_supp']!='')
	{
		$_SESSION['supp_data'] = $_POST;
		$addProdOb = new classProduct;
		$addProdOb->setProductID($_POST['product_id']);
		$addProdOb->setSupplierID($_POST['supplier_id']);
		$addProdOb->setProductBoxTradePrice("0");
		$addProdOb->setProductLeafTradePrice("0");
		$addProdOb->setProductUnitTradePrice("0");
		
		$addProdOb->insertProductSupplierRelationshipData();
	}
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}

if(isset($_SESSION['temp']['prod_id'])&&$_SESSION['temp']['prod_id']!='')
{
	$product_id = $_SESSION['temp']['prod_id'];
}
if(isset($_GET['prod_id'])&&$_GET['prod_id']!='')
{
	$product_id = $_GET['prod_id'];
}

try
{
	$retrieveOb = new classProduct;
	$retrieveOb->setOrganizationID($_SESSION['security']['org_id']);
	$product_array = $retrieveOb->retrieveActiveProducts();
	
	$retrieveOb->setLocationID($_SESSION['security']['location_id']);
	$suppliers_array = $retrieveOb->retrieveSuppliers();
	$manufacturer_array = $retrieveOb->retrieveManufacturers();
	
	if(isset($product_id)&&$product_id!='')
	{
		$singleProdOb = new classProduct;
		
		$singleProdOb->setProductID($product_id);
		$single_prod_array = $singleProdOb->retrieveProductByProductID();
		$prod_supp_array = $singleProdOb->retrieveProductSupplierDataByProductID();
		$prod_loc_array = $singleProdOb->retrieveProductLocationRelationship($product_id,$_SESSION['security']['location_id']);
		
	}
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}			



?>
<!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="../css/style.css" rel="stylesheet">
    <link href="../css/style-responsive.css" rel="stylesheet"/> 
    <link href="../popUp/popUp.css" rel="stylesheet">
    <link href="../css/bootstrap-fullcalendar.css" rel="stylesheet"/> 
    
    <link href="../css/clndr.css" rel="stylesheet">
    
    <link href="../css/css/font-awesome.css" rel="stylesheet">
    
    <link href="../assets/jquery-ui/jquery-ui-1.10.1.custom.min.css" rel="stylesheet">
    <link href="../assets/jvector-map/jquery-jvectormap-1.2.2.css" rel="stylesheet">    
    <link href="../assets/jquery-multi-select/css/multi-select.css" rel="stylesheet" type="text/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="../datepicker/jquery-ui.css" rel="stylesheet" >   
<!-- 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="#"><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="pharminventory.php"><img src="../images/iconinventory.png"></a></td>    
              <td width="12%" align="center"><a href="#add_manf-box" class="add_manf-window" id="add_manufacturer"><img src="../images/iconsupplier.png"></a></td>
              <td width="12%" align="center"><a href="#add_supp-box" class="add_supp-window" id="add_supplier"><img src="../images/iconsupplier.png"></a></td>
              <td width="12%" align="center"><a href="pharmdeactivated.php"><img src="../images/iconshiftclose.png"></a></td>
              <td width="12%" align="center"></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="pharminventory.php">Products Inventory</a></td> 
              <td align="center"><a href="#add_manf-box" class="add_manf-window" id="add_manufacturer">Add Manufacturer</a></td>
              <td align="center"><a href="#add_supp-box" class="add_supp-window" id="add_supplier">Add Supplier</a></td>
              <td align="center"><a href="pharmdel.php">Deleted Products</a></td>
              <td align="center"></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>ADD PRODUCTS</h2>
            </header>
            
           	<div class="panel-body">
            
			<?php
            if(isset($error_message)&&$error_message!='')
            {
				?>
				<span class="message_red"><?php echo $error_message;?></span>
				<?php
            }
            ?>
        
            <div class="row">
            <table width="100%" border="0" cellpadding="10" cellspacing="10">
            
                <tr>
                
                <td valign="top">
                    <div class="panel-body"> 
                    <strong>Products</strong>
                        <div class="scrollbar" style="height:440px;">
                          <table width="100%" border="0" cellpadding="2" cellspacing="2" class="display table table-bordered table-striped" style="font-weight:200;">
                            <?php
                            if(isset($product_array[0]['product_id'])&&$product_array[0]['product_id']!='')
                            {
                                for($p=0;$p<count($product_array);$p++)
                                {
                                    ?>
                                    <tr>
                                        <td><a href="?prod_id=<?php echo $product_array[$p]['product_id'];?>"><?php echo $product_array[$p]['product_id'];?></a></td>
                                        <td><a href="?prod_id=<?php echo $product_array[$p]['product_id'];?>"><?php echo $product_array[$p]['product_name'];?></a></td>
                                        <td><a href="?prod_id=<?php echo $product_array[$p]['product_id'];?>"><?php echo $product_array[$p]['medicine_type'];?></a></td>
                                        <td><a href="?delprod_id=<?php echo $product_array[$p]['product_id'];?>"><img src='../images/delete.png' alt='Delete'/></a></td>
                                    </tr>
                                    <?php
                                }
                            }
                            ?>
                            </table>
                        </div>
                     </div>
                 </td>
                  
                <td valign="top">
                    <div id="result_insert_product_form"></div>
                
                    <form method="post" id="insert_product_form" class="cmxform form-horizontal">
                                        
                    <table width="100%" border="0" cellspacing="0" cellpadding="2">
                    
                        <tr>
                            <td width="50%" align="right"></td>
                            <td width="50%" align="right"><input name="Add_New_Product" type="submit" class="btn btn-info" value="Add New Product" style="margin-right:20px;"/><input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Save"/></td>
                        </tr>
                        
                        <tr>
                            <td>
                            <div class="form-group">
                                <label class="control-label col-lg-3" for="lastname">Product Name:</label>
                                <div class="col-lg-6">
                                    <input type="text" name="prod_name" value="<?php if(isset($single_prod_array[0]['product_name'])&&$single_prod_array[0]['product_name']!=''){echo $single_prod_array[0]['product_name'];}?>" id="lastname" class="form-control">
                                </div>
                            </div>
                            </td>
                        </tr>  
                        
                        <tr>
                            <td>
                            <div class="form-group">
                                <label class="control-label col-lg-3" for="username">Category:</label>
                                <div class="col-lg-6">
                            <input type="radio" value="medicine" <?php if(isset($single_prod_array[0]['category'])&&$single_prod_array[0]['category']=='medicine'){echo 'checked';}else{echo 'checked';}?> name="prod_category">Medicine
                            <input type="radio" value="other" <?php if(isset($single_prod_array[0]['category'])&&$single_prod_array[0]['category']=='other'){echo 'checked';}?> name="prod_category">Other
                            </div>
                            </div>
                        </td>
                        
                        <td>
                        <div class="form-group">
                        <label class="control-label col-lg-3" for="confirm_password">Re-order Qty:</label>
                        <div class="col-lg-6">
                        <input type="text" name="prod_reorder_qty" value="<?php if(isset($single_prod_array[0]['reorder_qty'])&&$single_prod_array[0]['reorder_qty']!=''){echo $single_prod_array[0]['reorder_qty'];}else{echo 10;}?>" class="form-control">
                        </div>
                        </div>
                        </td>
                        </tr> 
                        
                        <tr>
                            <td>
                            <div class="form-group">
                            <label class="control-label col-lg-3" for="password">Medicine Type:</label>
                            <div class="col-lg-6">
                            <select name="medicine_type" class="form-control input-sm m-bot15">
                            <option value="">Select One</option>
                            <option  value="Tablets/Capsules" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Tablets/Capsules'){echo 'selected';}?>>Tablets/Capsules</option>
                            <option value="Cream" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Cream'){echo 'selected';}?>>Cream</option>
                            <option value="Ointment" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Ointment'){echo 'selected';}?>>Ointment</option>
                            <option value="Syrup" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Syrup'){echo 'selected';}?>>Syrup</option>
                            <option value="Injection" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Injection'){echo 'selected';}?>>Injection</option>
                            <option value="Sachet" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Sachet'){echo 'selected';}?>>Sachet</option>
                            <option value="Lotion" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Lotion'){echo 'selected';}?>>Lotion</option>
                            <option value="Drops" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Drops'){echo 'selected';}?>>Drops</option>
                            <option value="Gel" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Gel'){echo 'selected';}?>>Gel</option>
                            <option value="Soap" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Soap'){echo 'selected';}?>>Soap</option>
                            <option value="Paste" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Paste'){echo 'selected';}?>>Paste</option>
                            <option value="Other" <?php if(isset($single_prod_array[0]['medicine_type'])&&$single_prod_array[0]['medicine_type']=='Other'){echo 'selected';}?>>Other</option>
                            </select>
                            </div>
                            </div>
                            </td>
                        
                            <td>
                            <div class="form-group">
                            <label class="control-label col-lg-3" for="firstname">Manufacturer:</label>
                            <div class="col-lg-6">
                            <select name="manf_id" class="form-control input-sm m-bot15">
                            <option value="">Select Manufacturer</option>
                            <?php
                            if(isset($manufacturer_array[0]['manf_id'])&&$manufacturer_array[0]['manf_id']!='')
                            {
                            for($m=0;$m<count($manufacturer_array);$m++)
                            {
                            ?>
                            <option value="<?php echo $manufacturer_array[$m]['manf_id'];?>" <?php if(isset($single_prod_array[0]['manf_id'])&&$single_prod_array[0]['manf_id']==$manufacturer_array[$m]['manf_id']){echo 'selected';}?>><?php echo $manufacturer_array[$m]['manf_name'];?></option>
                            <?php
                            }
                            }
                            ?>
                            </select>
                            </div>
                            </div>
                            </td>
                        </tr>  
                        
                    </table>
                       
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="display table table-bordered table-striped" style="font-weight:200;">
                    
                        <tr>
                            <td width="25%" align="center"></td>
                            <td width="25%" align="center">Box qty</td>
                            <td width="25%" align="center">Leaf per Box</td>
                            <td width="25%" align="center">Unit/Tablet per Box</td>
                        </tr>
                        
                        <tr>
                            <td align="center">Quantity:</td>
                            <td align="center"><input type="text" name="boxqty" id="boxqty" size="5" value="<?php if(isset($single_prod_array[0]['box_qty'])&&$single_prod_array[0]['box_qty']!=''){echo $single_prod_array[0]['box_qty'];}else{echo 1;}?>" disabled="disabled"/></td>
                            <td align="center"><input type="text" name="leafqtybox" id="leafqtybox" size="5" value="<?php if(isset($single_prod_array[0]['leafperbox'])&&$single_prod_array[0]['leafperbox']!=''){echo $single_prod_array[0]['leafperbox'];}else{echo 1;}?>"/></td>
                            <td align="center"><input type="text" name="unitqtybox" id="unitqtybox" size="5" value="<?php if(isset($single_prod_array[0]['unitperbox'])&&$single_prod_array[0]['unitperbox']!=''){echo $single_prod_array[0]['unitperbox'];}else{echo 1;}?>"/></td>
                        </tr>
                        
                        <tr>
                            <td align="center">Retail Price:</td>
                            <td align="center">Rs. <input type="text" name="retailpricebox" id="retailpricebox" size="5" value="<?php if(isset($prod_loc_array[0]['box_retailprice'])&&$prod_loc_array[0]['box_retailprice']!=''){echo $prod_loc_array[0]['box_retailprice'];}?>"/></td>
                            <td align="center"><input type="text" name="retailpriceleaf" id="retailpriceleaf" size="5" value="<?php if(isset($prod_loc_array[0]['leaf_retailprice'])&&$prod_loc_array[0]['leaf_retailprice']!=''){echo $prod_loc_array[0]['leaf_retailprice'];}?>" disabled="disabled"/></td>
                            <td align="center"><input type="text" name="retailpriceunit" id="retailpriceunit" size="5" value="<?php if(isset($prod_loc_array[0]['unit_retailprice'])&&$prod_loc_array[0]['unit_retailprice']!=''){echo $prod_loc_array[0]['unit_retailprice'];}?>" disabled="disabled"/></td>
                        </tr>
                        
                        <tr>
                            <td align="center" valign="bottom"><br>Trade Price:</td>
                            <td align="left" colspan="3" valign="bottom"></td>
                        </tr>
                        
                        <?php
                        if(isset($prod_supp_array[0]['supplier_id'])&&$prod_supp_array[0]['supplier_id']!='')
                        {
                            for($sup=0;$sup<count($prod_supp_array);$sup++)
                            {
                                $suppOb = new classProduct;
                                $supp_data = $suppOb->retrieveSupplierBySupplierID($prod_supp_array[$sup]['supplier_id']);
                                ?>
                                <tr>
                                
                                <td align="center"><?php echo $supp_data[0]['supplier_name'];?></td>
                                
                                <td align="center">Rs. <input type="text" name="tradepricebox[]" id="tradepricebox_<?php echo $sup;?>" class="boxtradeprice" size="5" value="<?php if(isset($_SESSION['supp_data']['tradepricebox'][$sup])&&$_SESSION['supp_data']['tradepricebox'][$sup]!=''){echo $_SESSION['supp_data']['tradepricebox'][$sup];}elseif(isset($prod_supp_array[$sup]['box_tradeprice'])&&$prod_supp_array[$sup]['box_tradeprice']!=''){echo $prod_supp_array[$sup]['box_tradeprice'];}?>"/></td>
                                
                                <td align="center"><input type="text" name="tradepriceleaf[]" id="tradepriceleaf_<?php echo $sup;?>" class="leaftradeprice" size="5" value="<?php if(isset($_SESSION['supp_data']['trade_price_leaf'][$sup])&&$_SESSION['supp_data']['trade_price_leaf'][$sup]!=''){echo $_SESSION['supp_data']['trade_price_leaf'][$sup];}elseif(isset($prod_supp_array[$sup]['leaf_tradeprice'])&&$prod_supp_array[$sup]['leaf_tradeprice']!=''){echo $prod_supp_array[$sup]['leaf_tradeprice'];}?>" disabled="disabled"/></td>
                                
                                <td align="center"><input type="text" name="tradepriceunit[]" id="tradepriceunit_<?php echo $sup;?>" class="unittradeprice" size="5" value="<?php if(isset($_SESSION['supp_data']['trade_price_unit'][$sup])&&$_SESSION['supp_data']['trade_price_unit'][$sup]!=''){echo $_SESSION['supp_data']['trade_price_unit'][$sup];}elseif(isset($prod_supp_array[$sup]['unit_tradeprice'])&&$prod_supp_array[$sup]['unit_tradeprice']!=''){echo $prod_supp_array[$sup]['unit_tradeprice'];}?>" disabled="disabled"/></td>
                                
                                </tr>
                                
                                <input type="hidden" id="trade_price_box_<?php echo $sup;?>" class="boxtradepricehidden" name="trade_price_box[]" value="<?php if(isset($_SESSION['supp_data']['trade_price_box'][$sup])&&$_SESSION['supp_data']['trade_price_box'][$sup]!=''){echo $_SESSION['supp_data']['trade_price_box'][$sup];}elseif(isset($prod_supp_array[$sup]['box_tradeprice'])&&$prod_supp_array[$sup]['box_tradeprice']!=''){echo $prod_supp_array[$sup]['box_tradeprice'];}?>">
                                
                                <input type="hidden" id="trade_price_leaf_<?php echo $sup;?>" class="leaftradepricehidden" name="trade_price_leaf[]" value="<?php if(isset($_SESSION['supp_data']['trade_price_leaf'][$sup])&&$_SESSION['supp_data']['trade_price_leaf'][$sup]!=''){echo $_SESSION['supp_data']['trade_price_leaf'][$sup];}elseif(isset($prod_supp_array[$sup]['leaf_tradeprice'])&&$prod_supp_array[$sup]['leaf_tradeprice']!=''){echo $prod_supp_array[$sup]['leaf_tradeprice'];}?>">
                                
                                <input type="hidden" id="trade_price_unit_<?php echo $sup;?>" class="unittradepricehidden" name="trade_price_unit[]" value="<?php if(isset($_SESSION['supp_data']['trade_price_unit'][$sup])&&$_SESSION['supp_data']['trade_price_unit'][$sup]!=''){echo $_SESSION['supp_data']['trade_price_unit'][$sup];}elseif(isset($prod_supp_array[$sup]['unit_tradeprice'])&&$prod_supp_array[$sup]['unit_tradeprice']!=''){echo $prod_supp_array[$sup]['unit_tradeprice'];}?>">
                                
                                <input type="hidden" name="supplier_ids[]" value="<?php echo $prod_supp_array[$sup]['supplier_id']?>">
                                
                                <?php
                            }
                        }
                        ?>
                        
                    </table>
                            
                    <div class="form-group">
                   
                    <?php
                        if(isset($single_prod_array[0]['product_id'])&&$single_prod_array[0]['product_id']!='')
                        {
                            ?>
                            <input name="add_supp" type="submit" class="btn btn-info" value="Add Supplier"/>
                            <?php
                        }
                        ?>
                    
                        <div class="col-lg-6">
                        <select name="supplier_id" class="form-control input-sm m-bot15">
                        <option value="">Select Supplier</option>
                        <?php
                        if(isset($suppliers_array[0]['supplier_id'])&&$suppliers_array[0]['supplier_id']!='')
                        {
                            for($s=0;$s<count($suppliers_array);$s++)
                            {
                                ?>
                                <option value="<?php echo $suppliers_array[$s]['supplier_id'];?>"><?php echo $suppliers_array[$s]['supplier_name'];?></option>
                                <?php
                            }
                        }
                        ?>
                        </select>
                        </div>
                    </div>
                            
                    <input type="hidden" name="box_qty" id="box_qty" value="<?php if(isset($single_prod_array[0]['box_qty'])&&$single_prod_array[0]['box_qty']!=''){echo $single_prod_array[0]['box_qty'];}else{echo 1;}?>">
                    <input type="hidden" name="leaf_qty_box" id="leaf_qty_box" value="<?php if(isset($single_prod_array[0]['leafperbox'])&&$single_prod_array[0]['leafperbox']!=''){echo $single_prod_array[0]['leafperbox'];}else{echo 1;}?>">
                    <input type="hidden" name="unit_qty_box" id="unit_qty_box" value="<?php if(isset($single_prod_array[0]['unitperbox'])&&$single_prod_array[0]['unitperbox']!=''){echo $single_prod_array[0]['unitperbox'];}else{echo 1;}?>">
                    
                  	<input type="hidden" name="retail_price_box" id="retail_price_box" value="<?php if(isset($prod_loc_array[0]['box_retailprice'])&&$prod_loc_array[0]['box_retailprice']!=''){echo $prod_loc_array[0]['box_retailprice'];}else{echo 1;}?>">
                	<input type="hidden" name="retail_price_leaf" id="retail_price_leaf" value="<?php if(isset($prod_loc_array[0]['leaf_retailprice'])&&$prod_loc_array[0]['leaf_retailprice']!=''){echo $prod_loc_array[0]['leaf_retailprice'];}else{echo 1;}?>">
                	<input type="hidden" name="retail_price_unit" id="retail_price_unit" value="<?php if(isset($prod_loc_array[0]['unit_retailprice'])&&$prod_loc_array[0]['unit_retailprice']!=''){echo $prod_loc_array[0]['unit_retailprice'];}else{echo 1;}?>">
                    <?php
                    if(isset($single_prod_array[0]['product_id'])&&$single_prod_array[0]['product_id']!='')
                    {
                        ?>
                        <input type="hidden" name="product_id" value="<?php echo $single_prod_array[0]['product_id'];?>">
                        <?php
                    }
                    ?>
                    <input type="hidden" name="add_prod" value="Add_Product">
                    </form>
              
                </td>
                  
                </tr>
                
            </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>

<div id="add_manf-box" class="add_manf-popup">
    
    <div class="pop_header">
        <span>Add Manufacturer</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_manufacturer_form" style="margin:10px;"></div>
          
          <form action="" method="post" id="insert_manufacturer_form" class="cmxform form-horizontal" onsubmit="return false;">
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Name:</label>
              <div class="col-lg-6">
                <input type="text" name="comp_name" id="lastname" class="form-control">
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Phone:</label>
              <div class="col-lg-6">
                <input type="text" name="phone" id="lastname" class="form-control">
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Address:</label>
              <div class="col-lg-6">
                <input type="text" name="address" id="lastname" class="form-control">
              </div>
            </div>
            <p align="right">
              <input type="hidden" name="add_manf" value="Add_Manufacturer">
              <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Save" />
            </p>
          </form>
          </td>
          
      </tr>
      <tr>
      	<td><a href="mgmtmanufacturer.php">Manage Manufacturer</a></td>
      </tr>
      
    </table>
</div>

<div id="add_supp-box" class="add_supp-popup">
    
    <div class="pop_header">
        <span>Add Supplier</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_supplier_form" style="margin:10px;"></div>
          
          <form action="" method="post" id="insert_supplier_form" class="cmxform form-horizontal" onsubmit="return false;">
          <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Supplier Name:</label>
              <div class="col-lg-6">
                <input type="text" name="supp_name" id="lastname" class="form-control">
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Supplier Phone:</label>
              <div class="col-lg-6">
                <input type="text" name="supp_phone" id="lastname" class="form-control">
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Supplier Address:</label>
              <div class="col-lg-6">
                <input type="text" name="comp_address" id="lastname" class="form-control">
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Contact Name:</label>
              <div class="col-lg-6">
                <input type="text" name="comp_name" id="lastname" class="form-control">
              </div>
            </div>
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Contact Phone:</label>
              <div class="col-lg-6">
                <input type="text" name="comp_phone" id="lastname" class="form-control">
              </div>
            </div>
            
            <p align="right">
              <input type="hidden" name="add_supp" value="Add_Supplier">
              <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Save" />
            </p>
          </form>
          </td>
          
      </tr>
      <tr>
      	<td><a href="mgmtsupplier.php">Manage Supplier</a></td>
      </tr>
      
    </table>
</div>


<script>

function calculation()
{
	
	
	<!--Qty Set-->
	boxqty = document.getElementById("boxqty").value;
	leafqtybox = document.getElementById("leafqtybox").value;
	unitqtybox = document.getElementById("unitqtybox").value;
	
	$("#box_qty").val(boxqty);
	$("#leaf_qty_box").val(leafqtybox);
	$("#unit_qty_box").val(unitqtybox);
	
	<!--Trade Prices Set-->
	var boxtradeprice = document.getElementsByClassName('boxtradeprice');
	
	$('.boxtradeprice').each(function(index) {
        
        boxtradepricevalue = $(this).val();
		
		$('#tradepriceleaf_'+index).val(boxtradepricevalue/leafqtybox);
		$('#tradepriceunit_'+index).val(boxtradepricevalue/unitqtybox);
		$('#trade_price_box_'+index).val(boxtradepricevalue);
		$('#trade_price_leaf_'+index).val(boxtradepricevalue/leafqtybox);
		$('#trade_price_unit_'+index).val(boxtradepricevalue/unitqtybox);
		
       
    });
	
	<!--Retail Prices Set-->
	retailpricebox = document.getElementById("retailpricebox").value;
	retailpriceleaf = retailpricebox/leafqtybox;
	retailpriceunit = retailpricebox/unitqtybox;
	
	$("#retailpriceleaf").val(retailpriceleaf);
	$("#retailpriceunit").val(retailpriceunit);
	$("#retail_price_box").val(retailpricebox);
	$("#retail_price_leaf").val(retailpriceleaf);
	$("#retail_price_unit").val(retailpriceunit);
	
}

$("#retailpricebox").keyup(function() {
	
	calculation();
});

$("#leafqtybox").keyup(function() {
	
	calculation();
});

$("#unitqtybox").keyup(function() {
	
	calculation();
	
});

$(".boxtradeprice").keyup(function() {
	
	var id = this.id;
	var data= id.split('_');
	var tradepricebox = document.getElementById(id).value;
	
	boxqty = document.getElementById("boxqty").value;
	leafqtybox = document.getElementById("leafqtybox").value;
	unitqtybox = document.getElementById("unitqtybox").value;
	
	leaftradeprice = tradepricebox/leafqtybox;
	unittradeprice = tradepricebox/unitqtybox;
	
	$("#tradepriceleaf_"+data[1]).val(leaftradeprice);
	$("#tradepriceunit_"+data[1]).val(unittradeprice);
	
	$("#trade_price_box_"+data[1]).val(tradepricebox);
	$("#trade_price_leaf_"+data[1]).val(leaftradeprice);
	$("#trade_price_unit_"+data[1]).val(unittradeprice);
	
	
});
	
</script>
