<?php @session_start();
@ob_start();
 
class class_core_library extends Database
 {
 var $Save;
 
  var $message;

  function class_core_library(){}
  function showmsg()
  {
	return "hello class";  
  }
 
		function table_GETDATA($sid)
		{
		  $where="md5(id)='$sid'";
		  return $this->getRows($this->Table_Name,$where);
		}
		
		function trasaction_no()
		{
		$maxsql="select max(invoice_no) as invoice_no from tbl_account";
				$maxrs=mysql_query($maxsql);
				$rsmax=mysql_fetch_array($maxrs);
				$invoice_no=$rsmax["invoice_no"];
				if($invoice_no>0)
				{
				$invoice_no=$invoice_no+1;
				}
				else
				{
				$invoice_no=1;
				}
				return $invoice_no;
		}
		
		 function sales_list()
  {
  
  
  $table="view_sales_master";
	 $rows="*";
	
 	$adjacents = 3; 

 	 $q = 'SELECT '.$rows.' FROM '.$table."  where cancel_status=0 ". $_SESSION["abc"] ."  order by id desc";
 
  
        if($this->tableExists($table))
       {
        $query = @mysql_query($q) or $this->Notify(mysql_error());
        if($query)
        {
	 	$total_pages = mysql_num_rows(mysql_query($q));
		$targetpage=$_SESSION["varFileName"];

		 $limit = 20; //how many items to show per page
			if(isset($_GET['page'])) {
			$page = $_GET['page'];
			$start = ($page - 1) * $limit; //first item to display on this page
			} else {
			$page = 0;
			$start = 0; //if no page var is given, set start to 0
			}
			$sql=' LIMIT '.$start.','. $limit;
			 $q=$q.$sql;
			
								if ($page == 0)
							 $page = 1;
								$prev = $page - 1;
								$next = $page + 1;
								$lastpage = ceil($total_pages / $limit);
								$lpm1 = $lastpage - 1;
							
								$pagination = "";
								if ($lastpage > 1) {}
								 $query = @mysql_query($q)  or $this->Notify(mysql_error());
					
         ?>
		 <br />
		 <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
		 <thead>
  <tr>
    <th><strong>Sales Date</strong></th>
    <th><strong>Invoice No. </strong></th>
	 <th><strong>Client Name </strong></th>
     <th><strong>Client Contact No. </strong></th>
     <th ><strong>Cancel Invoice</strong> </th>
     <th><strong>Return</strong></th>
     
     <th ><strong>Print 1st Reciept Only </strong></th>
    
   </tr>
  </thead>
  <tbody>
  <?php 
  
  while($row=mysql_fetch_array($query)){  
     
	$salesmas_id=$row["id"];
	 $sqlact="select actual_amt,count(id) as cont from tbl_account where mas_id='$salesmas_id' and (sales_type= 'Sales'  or sales_type= 'Sales_Due')  order by id";
	$exeact=mysql_query($sqlact);
	$rsact=mysql_fetch_array($exeact);
	 $act_amt=$rsact["actual_amt"];			
  ?>
  <tr>
    <td><?php echo $this->IntToDate($row["stampdate"]);?></td>
	<td><?php echo $row["sale_no"];?></td>
    <td><?php echo $row["client_name"];?></td>
	 <td><?php echo $row["contact_no"];?></td>
	 <td style="width:2px" ><?php if($rsact["cont"]==1){?><a href="sales_cancel.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-danger">Cancel Invoice</a><?php }?></td>
	 <td style="width:2px" ><a href="sales_return.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-success">Return</a></td>
	
	 <td style="width:2px" ><a href="sales_reciept.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-primary">Print</a></td>
	 
	<?php  $sqlpaid="select sum(Dr_Amt) as paid_amt from tbl_account where mas_id='$salesmas_id' and sales_type='Sales'";
	$exepaid=mysql_query($sqlpaid);
	$rspaid=mysql_fetch_array($exepaid);
	 $totamt=$rspaid["paid_amt"];
	
	?>
	 
    </tr>

	<?php }?>
	 </tbody>
</table>

		 <?php
			 }
			echo "<div align='right'>". $pagination."</div>"; 
			 
			 
	}
	
	}
		
		function salesreturn_list()
  {
  
  
  $table="view_salesreturn";
	 $rows="*";
	
 	$adjacents = 3; 

 	 $q = 'SELECT '.$rows.' FROM '.$table."  ". $_SESSION["abc"] ."  order by id desc";
 
  
        if($this->tableExists($table))
       {
        $query = @mysql_query($q) or $this->Notify(mysql_error());
        if($query)
        {
	 	$total_pages = mysql_num_rows(mysql_query($q));
		$targetpage=$_SESSION["varFileName"];

		 $limit = 20; //how many items to show per page
			if(isset($_GET['page'])) {
			$page = $_GET['page'];
			$start = ($page - 1) * $limit; //first item to display on this page
			} else {
			$page = 0;
			$start = 0; //if no page var is given, set start to 0
			}
			$sql=' LIMIT '.$start.','. $limit;
			 $q=$q.$sql;
			
								if ($page == 0)
							 $page = 1;
								$prev = $page - 1;
								$next = $page + 1;
								$lastpage = ceil($total_pages / $limit);
								$lpm1 = $lastpage - 1;
							
								$pagination = "";
								if ($lastpage > 1) {}
								 $query = @mysql_query($q)  or $this->Notify(mysql_error());
					
         ?>
		 <br />
		<table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%"> <thead>
  <tr>
    <th><strong>Sales Return No. </strong></th>
    <th><strong>Sales Return Date</strong></th>
    
	 <th><strong>Client Name </strong></th>
     <th><strong>Client Contact No. </strong></th>
     <th >View</th>
     <th>Credit Note</th>
   </tr>
  </thead>
  <tbody>
  <?php 
  
  while($row=mysql_fetch_array($query)){  		
  ?>
  <tr>
    <td><?php echo $row["salereturn_no"];?></td>
    <td><?php echo $this->IntToDate($row["return_date"]);?></td>
    <td><?php echo $row["client_name"];?></td>
	 <td><?php echo $row["contact_no"];?></td>
	 
	
	 <td  > <a href="salereturn_view.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-primary">View</a>
	  <td  > <a href="creditnote.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-success">View</a>
 	  </td>
    </tr>

	<?php }?>
	 </tbody>
</table>

		 <?php
			 }
			echo "<div align='right'>". $pagination."</div>"; 
			 
			 
	}
	
	}
		/*************************item List ****************************/
		function bankdet_list()
{ 

			//die('hello');
			if(isset($_POST["Search"]))
{ $_SESSION["where"]="head like('%".$_POST["search"]."%')"; } 
			
			$this->Table_Name="tbl_bank_det";
			$viewname="tbl_bank_det";
 		
			$this->getList($viewname,'id ,acc_no as "Acc No.",bank_name as "Bank Name",branch_name as "Branch Name"',$_SESSION["where"],'id',$this->Table_Name);
}

function bankdet_alter()
{
		$this->Table_Name="tbl_bank_det";
		$vtablename="tbl_bank_det";
		
		$this->checkurl($vtablename);
		$this->acc_no=$this->temp["acc_no"];
		$this->bank_name=$this->temp["bank_name"];
		$this->branch_name=$this->temp["branch_name"];
       
		
		
		if(isset($_POST["Save"]))
		{
		$this->acc_no=($_POST["accno"]);
		$this->bank_name=($_POST["bank_name"]);
		$this->branch_name=($_POST["branch_name"]);
		
			
	
	
	
		if($_POST["Save"]=="New")
		{
		$whr="acc_no='".$_POST["acc_no"]."'";
		if($this->getNumRows($this->Table_Name, $whr)<=0)
		{		$lastid=$this->insert($this->Table_Name,array($this->acc_no,$this->bank_name,$this->branch_name),"acc_no,bank_name,branch_name");
				header("location:Bankdetail_list.php");
				$this->message='<div class="alert alert-danger">One New Record Added</div>';
				$_SESSION["msg"]=$this->message;
		}		
		else { echo $this->error='<div class="alert alert-danger">Account No. Must be Unique</div>';}
		}
		if($_POST["Save"]=="Edit")
		{
			$uid= $_GET["uid"];
			 $where ="md5(id)='$uid'";
			$this->update($this->Table_Name,array('acc_no'=>$this->acc_no,'bank_name'=>$this->bank_name,'branch_name'=>$this->branch_name),$where);

			header("location:Bankdetail_list.php");
			 			 $this->message='<div class="alert alert-danger">One Record Updated</div>';
						 $_SESSION["msg"]=$this->message;
		}
		if($_POST["Save"]=="View")
		{
						header("location:Bankdetail_list.php");
		}
		 
	}
	
	}
		
		
function bank_list()
{ 

			//die('hello');
			if(isset($_POST["Search"]))
{ $_SESSION["where"]="head like('%".$_POST["search"]."%')"; } 
			
			$this->Table_Name="tbl_bank";
			$viewname="view_bank";
 		
			$this->getList($viewname,'id ,stampdate as "IntToDate_Transaction Date",head as "Head",acc_no as "Acc No.",debit as "Debit(Rs)",credit as "Credit(Rs)"',$_SESSION["where"],'id',$this->Table_Name);
}
function bank_alter()
{
		$this->Table_Name="tbl_bank";
		$vtablename="tbl_bank";
		
		$this->checkurl($vtablename);
		
		
        $this->head=$this->temp["head"];
		$this->acc_no=$this->temp["bankdet_id"];
		$this->debit=$this->temp["debit"];
		$this->credit=$this->temp["credit"];
       
		
		
		if(isset($_POST["Save"]))
		{
		$this->acchead=($_POST["acchead"]);
		$this->acc_no=($_POST["acc_no"]);
		$this->debit=($_POST["debit"]);
		$this->credit=($_POST["credit"]);
		$this->stampdate=$this->DateToInt(date("d-m-Y"));
		$this->session_i=($_SESSION['login_id']);
		
			
	
	
	
		if($_POST["Save"]=="New")
		{
		$whr="head='".$_POST["acchead"]."' and bankdet_id='".$_POST["acc_no"]."' and stampdate='".$this->stampdate."'";
		if($this->getNumRows($this->Table_Name, $whr)<=0)
		{		$lastid=$this->insert($this->Table_Name,array($this->acchead,$this->acc_no,$this->debit,$this->credit,$this->stampdate,$this->session_i),"head,bankdet_id,debit,credit,stampdate");
				header("location:Bank_list.php");
				$this->message='<div class="alert alert-danger">One New Record Added</div>';
				$_SESSION["msg"]=$this->message;
		}		
		else { echo $this->error='<div class="alert alert-danger">Head Must be Unique</div>';}
		}
		if($_POST["Save"]=="Edit")
		{
			$uid= $_GET["uid"];
			 $where ="md5(id)='$uid' and session_login_id = '".$_SESSION['login_id']."'";
			$this->update($this->Table_Name,array('head'=>$this->acchead,'bankdet_id'=>$this->acc_no,'debit'=>$this->debit,'credit'=>$this->credit,'stampdate'=>$this->stampdate),$where);

			header("location:Bank_list.php");
			 			 $this->message='<div class="alert alert-danger">One Record Updated</div>';
						 $_SESSION["msg"]=$this->message;
		}
		if($_POST["Save"]=="View")
		{
						header("location:Bank_list.php");
		}
		 
	}
	
	}
  
		/*************************item List ****************************/
function expense_list()
{ 

			//die('hello');
			if(isset($_POST["Search"]))
{ $_SESSION["where"]="expense_type like('%".$_POST["search"]."%')"; } 
			
			$this->Table_Name="tbl_expense";
			$viewname="tbl_expense";
 			
			$this->getList($viewname,'id ,stampdate as "IntToDate_Expense Date",expense_type as "Item Name",amount as "Amount"',$_SESSION["where"],'id',$this->Table_Name);
}
function expense_alter()
{
		$this->Table_Name="tbl_expense";
		$vtablename="tbl_expense";
		
		$this->checkurl($vtablename);
		
		
        $this->expense_type=$this->temp["expense_type"];
		$this->amount=$this->temp["amount"];
		$this->remarks=$this->temp["remarks"];
       
		
		
		if(isset($_POST["Save"]))
		{
		$this->expense_type=($_POST["expense_type"]);
		$this->amount=($_POST["amount"]);
		$this->remarks=($_POST["Remarks"]);
		$this->stampdate=$this->DateToInt(date("d-m-Y"));
		
			
	
	
	
		if($_POST["Save"]=="New")
		{
		$whr="expense_type='".$_POST["expense_type"]."' and stampdate='".$this->stampdate."'";
		if($this->getNumRows($this->Table_Name, $whr)<=0)
		{		$lastid=$this->insert($this->Table_Name,array($this->expense_type,$this->amount,$this->remarks,$this->stampdate),"expense_type,amount,remarks,stampdate");
				header("location:expance_list.php");
				$this->message='<div class="alert alert-danger">One New Record Added</div>';
				$_SESSION["msg"]=$this->message;
		}		
		else { echo $this->error='<div class="alert alert-danger">Item Type Name Must be Unique</div>';}
		}
		if($_POST["Save"]=="Edit")
		{
			$uid= $_GET["uid"];
			 $where ="md5(id)='$uid'";
			$this->update($this->Table_Name,array('expense_type'=>$this->expense_type,'amount'=>$this->amount,'remarks'=>$this->remarks,'stampdate'=>$this->stampdate),$where);

			header("location:expance_list.php");
			 			 $this->message='<div class="alert alert-danger">One Record Updated</div>';
						 $_SESSION["msg"]=$this->message;
		}
		if($_POST["Save"]=="View")
		{
						header("location:expance_list.php");
		}
		 
	}
	
	}
  
/************************* client End ****************************/
		 function purchase_list()
  {
  
  if(isset($_POST["Search"]))
{ $_SESSION["where"]="where receiving_no='".$_POST["search"]."' or order_no like('%".$_POST["search"]."%') or supplier_name like('%".$_POST["search"]."%')"; } 
  $table="view_purchase_supplier";
	 $rows="*";
	
 	$adjacents = 3; 

 	 $q = 'SELECT '.$rows.' FROM '.$table."  ". $_SESSION["where"] ." order by id desc";
 
  
        if($this->tableExists($table))
       {
        $query = @mysql_query($q) or $this->Notify(mysql_error());
        if($query)
        {
	 	$total_pages = mysql_num_rows(mysql_query($q));
		$targetpage=$_SESSION["varFileName"];

		 $limit = 20; //how many items to show per page
			if(isset($_GET['page'])) {
			$page = $_GET['page'];
			$start = ($page - 1) * $limit; //first item to display on this page
			} else {
			$page = 0;
			$start = 0; //if no page var is given, set start to 0
			}
			$sql=' LIMIT '.$start.','. $limit;
			 $q=$q.$sql;
			
								if ($page == 0)
							 $page = 1;
								$prev = $page - 1;
								$next = $page + 1;
								$lastpage = ceil($total_pages / $limit);
								$lpm1 = $lastpage - 1;
							
								$pagination = "";
								if ($lastpage > 1) {}
								 $query = @mysql_query($q)  or $this->Notify(mysql_error());
					
         ?>
		
		
                                    <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                                        <thead>
  <tr>
   <th></th>
	 <th  nowrap="nowrap"><strong>Order No </strong></th>
     <th  nowrap="nowrap"><strong>Supplier </strong></th>
     <th nowrap="nowrap"><strong>Purchase Date</strong></th>
	 <th  nowrap="nowrap" ><strong>Action</strong></th>
	 
	 
   </tr>
  </thead>
  <tbody>
  <?php 
  
  while($row=mysql_fetch_array($query)){  
     
	
				
  ?>
  <tr>
   <td><?php echo $row["receiving_no"];?></td>
    <td><?php echo $row["order_no"];?></td>
    <td><?php echo $row["supplier_name"];?></td>
	 <td><?php echo $this->IntToDate($row["purchase_date"]);?></td>
   <td > <a href="purchase_return.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-warning btn-sm">Return</a> <a href="purchase_view.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-primary btn-sm">View</a> <a href="purchase_edit.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-success btn-sm">Edit</a></td>
  
   
    </tr>

	<?php }?>
	 </tbody>
</table>

		 <?php
			 }
			echo "<div align='right'>". $pagination."</div>"; 
			 
			 
	}
	
	}
	
	 function purchasereturn_list()
  {
  
  if(isset($_POST["Search"]))
{ $_SESSION["where"]="where return_no like('%".$_POST["search"]."%') or order_no like('%".$_POST["search"]."%') or supplier_name like('%".$_POST["search"]."%')"; } 
  $table="view_purchasereturn_supplier";
	 $rows="*";
	
 	$adjacents = 3; 

 	 $q = 'SELECT '.$rows.' FROM '.$table."  ". $_SESSION["where"] ." order by id desc";
 
  
        if($this->tableExists($table))
       {
        $query = @mysql_query($q) or $this->Notify(mysql_error());
        if($query)
        {
	 	$total_pages = mysql_num_rows(mysql_query($q));
		$targetpage=$_SESSION["varFileName"];

		 $limit = 20; //how many items to show per page
			if(isset($_GET['page'])) {
			$page = $_GET['page'];
			$start = ($page - 1) * $limit; //first item to display on this page
			} else {
			$page = 0;
			$start = 0; //if no page var is given, set start to 0
			}
			$sql=' LIMIT '.$start.','. $limit;
			 $q=$q.$sql;
			
								if ($page == 0)
							 $page = 1;
								$prev = $page - 1;
								$next = $page + 1;
								$lastpage = ceil($total_pages / $limit);
								$lpm1 = $lastpage - 1;
							
								$pagination = "";
								if ($lastpage > 1) {}
								 $query = @mysql_query($q)  or $this->Notify(mysql_error());
					
         ?>
		 <br />
		<table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%"> <thead>
  <tr>
    <th><strong>Purchase Return No. </strong></th>
    
	 <th ><strong>Purchase Order No </strong></th>
     <th><strong>Supplier Name </strong></th>
     <th><strong>Return  Date</strong></th>
	 <th><strong>View</strong></th>
	 <th ><strong>Debit Note</strong></th>
	 </tr>
  </thead>
  <tbody>
  <?php 
  
  while($row=mysql_fetch_array($query)){  
     
	
				
  ?>
  <tr>
    <td><?php echo $row["return_no"];?></td>
    <td><?php echo $row["order_no"];?></td>
    <td><?php echo $row["supplier_name"];?></td>
	 <td><?php echo $this->IntToDate($row["ret_date"]);?></td>
   <td style="width:2px" > <a href="purchasereturn_view.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-primary">View</a></td>
   <td style="width:2px" > <a href="debitnote.php?uid=<?php echo md5($row["id"]);?>" class="btn btn-success">Note</a></td>
   </tr>

	<?php }?>
	 </tbody>
</table>

		 <?php
			 }
			echo "<div align='right'>". $pagination."</div>"; 
			 
			 
	}
	
	}
	
	
/*************************item List ****************************/
function unitmaster_list()
{ 

			//die('hello');
			if(isset($_POST["Search"]))
{ $_SESSION["where"]="unit_name like('%".$_POST["search"]."%')"; } 
			
			$this->Table_Name="tbl_unit";
			$viewname="tbl_unit";
 			
			$this->getList($viewname,'id ,unit_name as "Unit Name"',$_SESSION["where"],'id',$this->Table_Name);
}
function unitmaster_alter()
{
		$this->Table_Name="tbl_unit";
		$vtablename="tbl_unit";
		
		// $this->checkurl($vtablename);
		
		
        $this->unit_name=$this->temp["unit_name"];
       
		
		
		if(isset($_POST["Save"]))
		{
		$this->unit_name=($_POST["unit_name"]);
		
			
	
	
	
		if($_POST["Save"]=="New")
		{
		$whr="unit_name='".$_POST["unit_name"]."'";
		if($this->getNumRows($this->Table_Name, $whr)<=0)
		{		$lastid=$this->insert($this->Table_Name,array($this->unit_name),"unit_name");
				header("location:unitmaster_list.php");
				$this->message='<div class="alert alert-danger">One New Record Added</div>';
				$_SESSION["msg"]=$this->message;
		}		
		else { echo $this->error='<div class="alert alert-danger">Item Type Name Must be Unique</div>';}
		}
		if($_POST["Save"]=="Edit")
		{
			$uid= $_GET["uid"];
			 $where ="md5(id)='$uid'";
			$this->update($this->Table_Name,array('unit_name'=>$this->unit_name),$where);

			header("location:unitmaster_list.php");
			 			 $this->message='<div class="alert alert-danger">One Record Updated</div>';
						 $_SESSION["msg"]=$this->message;
		}
		if($_POST["Save"]=="View")
		{
						header("location:unitmaster_list.php");
		}
		 
	}
	
	}
  
/************************* client End ****************************/
/*************************item List ****************************/
function itemmaster_list()
{ 

			//die('hello');
			if(isset($_POST["Search"]))
{ $_SESSION["where"]="item_name like('%".$_POST["search"]."%')"; } 
			
			$this->Table_Name="tbl_item";
			$viewname="tbl_item";
 			
			$this->getList($viewname,'id ,item_name as "Item Name",hsn_code as "HSN/SAC Code"',$_SESSION["where"],'id',$this->Table_Name);
}
function itemmaster_alter()
{
		$this->Table_Name="tbl_item";
		$vtablename="tbl_item";
		
		// $this->checkurl($vtablename);
		
		
        $this->item_name=$this->temp["item_name"];
       $this->hsn_code=$this->temp["hsn_code"];
		
		
		if(isset($_POST["Save"]))
		{
		$this->item_name=($_POST["item_name"]);
		$this->hsn_code=($_POST["hsn_code"]);
			
	
	
	
		if($_POST["Save"]=="New")
		{
		$whr="item_name='".$_POST["item_name"]."' and hsn_code='".$_POST["hsn_code"]."'";
		if($this->getNumRows($this->Table_Name, $whr)<=0)
		{		$lastid=$this->insert($this->Table_Name,array($this->item_name,$this->hsn_code),"item_name,hsn_code");
				header("location:itemmaster_list.php");
				$this->message='<div class="alert alert-danger">One New Record Added</div>';
				$_SESSION["msg"]=$this->message;
		}		
		else { echo $this->error='<div class="alert alert-danger">Item Type Name Must be Unique</div>';}
		}
		if($_POST["Save"]=="Edit")
		{
			$uid= $_GET["uid"];
			 $where ="md5(id)='$uid'";
			$this->update($this->Table_Name,array('item_name'=>$this->item_name,'hsn_code'=>$this->hsn_code),$where);

			header("location:itemmaster_list.php");
			 			 $this->message='<div class="alert alert-danger">One Record Updated</div>';
						 $_SESSION["msg"]=$this->message;
		}
		if($_POST["Save"]=="View")
		{
						header("location:itemmaster_list.php");
		}
		 
	}
	
	}
  
/************************* client End ****************************/
/*************************tax List ****************************/
function tax_list()
{ 

			//die('hello');
			if(isset($_POST["Search"]))
{ $_SESSION["where"]="tax_name like('%".$_POST["search"]."%') "; } 
			
			$this->Table_Name="tbl_tax_mstr";
			$viewname="tbl_tax_mstr";
 			
			$this->getList($viewname,'id ,tax_name as "tax Name",tax_percent as "Tax(in %)",tax_for as "Tax For"',$_SESSION["where"],'id',$this->Table_Name);
}
function tax_alter()
{
		$this->Table_Name="tbl_tax_mstr";
		$vtablename="tbl_tax_mstr";
		
		$this->checkurl($vtablename);
		
		
        $this->tax_name=$this->temp["tax_name"];
        $this->taxpercent=$this->temp["tax_percent"]; 
		$this->tax_for=$this->temp["tax_for"]; 
		
		
		if(isset($_POST["Save"]))
		{
		$this->tax_name=($_POST["tax_name"]);
		$this->taxpercent=($_POST["taxpercent"]);
		$this->tax_for=$_POST["tax_for"];
			
	
	
	
		if($_POST["Save"]=="New")
		{
		$whr="tax_name='".$_POST["tax_name"]."'";
		if($this->getNumRows($this->Table_Name, $whr)<=0)
		{		$lastid=$this->insert($this->Table_Name,array($this->tax_name,$this->taxpercent,$this->tax_for),"tax_name,tax_percent,tax_for");
				header("location:taxmstr_list.php");
				$this->message='<div class="alert alert-danger">One New Record Added</div>';
				$_SESSION["msg"]=$this->message;
		}		
		else { echo $this->error='<div class="alert alert-danger">Item Type Name Must be Unique</div>';}
		}
		if($_POST["Save"]=="Edit")
		{
			$uid= $_GET["uid"];
			 $where ="md5(id)='$uid'";
			$this->update($this->Table_Name,array('tax_name'=>$this->tax_name,'tax_percent'=>$this->taxpercent,'tax_for'=>$this->tax_for),$where);

			header("location:taxmstr_list.php");
			 			 $this->message='<div class="alert alert-danger">One Record Updated</div>';
						 $_SESSION["msg"]=$this->message;
		}
		if($_POST["Save"]=="View")
		{
						header("location:taxmstr_list.php");
		}
		 
	}
	
	}
  
/************************* client End ****************************/
/*************************client List ****************************/
function client_list()
{ 

			//die('hello');
			if(isset($_POST["Search"]))
{ $_SESSION["where"]="client_name like('%".$_POST["search"]."%') or contact_person like('%".$_POST["search"]."%')  "; } 
			
			$this->Table_Name="tbl_client";
			$viewname="tbl_client";
 			
			$this->getList($viewname,'id ,client_name as "Client Name",contact_no as "Contact No",contact_person as "Contact Person",email_id as "Email"',$_SESSION["where"],'id',$this->Table_Name);
}
function client_alter()
{
		$this->Table_Name="tbl_client";
		$vtablename="tbl_client";
		
	//	$this->checkurl($vtablename);
		
		
        $this->client_name=$this->temp["client_name"];
        $this->contact_no=$this->temp["contact_no"]; 
		$this->address=$this->temp["address"];
		$this->contact_person=$this->temp["contact_person"];
		$this->email_id=$this->temp["email_id"];
		$this->tin_no=$this->temp["tin_no"];
		
		if(isset($_POST["Save"]))
		{
		$this->client_name=($_POST["client_name"]);
		$this->address=($_POST["address"]);
		$this->contact_no=($_POST["contact_no"]);
		$this->contact_person=($_POST["contact_person"]);
		$this->email=($_POST["email"]);
		$this->tin_no=($_POST["tin_no"]);	
	
	
	
		if($_POST["Save"]=="New")
		{
		$whr="client_name='".$_POST["client_name"]."' and contact_no='".$_POST["contact_no"]."'";
		if($this->getNumRows($this->Table_Name, $whr)<=0)
		{		$lastid=$this->insert($this->Table_Name,array($this->client_name,$this->address,$this->contact_no,$this->contact_person,$this->email,$this->tin_no),"client_name,address,contact_no,contact_person,email_id,tin_no");
				header("location:client_list.php");
				$this->message='<div class="alert alert-danger">One New Record Added</div>';
				$_SESSION["msg"]=$this->message;
		}		
		else { echo $this->error='<div class="alert alert-danger">Item Type Name Must be Unique</div>';}
		}
		if($_POST["Save"]=="Edit")
		{
			$uid= $_GET["uid"];
			 $where ="md5(id)='$uid'";
			$this->update($this->Table_Name,array('client_name'=>$this->client_name,'address'=>$this->address,'contact_no'=>$this->contact_no,'contact_person'=>$this->contact_person,'email_id'=>$this->email,'tin_no'=>$this->tin_no),$where);

			header("location:client_list.php");
			 			 $this->message='<div class="alert alert-danger">One Record Updated</div>';
						 $_SESSION["msg"]=$this->message;
		}
		if($_POST["Save"]=="View")
		{
						header("location:client_list.php");
		}
		 
	}
	
	}
  
/************************* client End ****************************/
/*************************Supplier List ****************************/
function supplier_list()
{ 

			//die('hello');
			if(isset($_POST["Search"]))
{ $_SESSION["where"]="supplier_name like('%".$_POST["search"]."%') or contact_person like('%".$_POST["search"]."%')  "; } 
			
			$this->Table_Name="tbl_supplier";
			$viewname="tbl_supplier";
 			
			$this->getList($viewname,'id ,supplier_name as "Supplier Name",contact_no as "Contact No",contact_person as "Contact Person",email_id as "Email"',$_SESSION["where"],'id',$this->Table_Name);
}
function supplier_alter()
{
		$this->Table_Name="tbl_supplier";
		$vtablename="tbl_supplier";
		
	//	$this->checkurl($vtablename);
		
		
        $this->supplier_name=$this->temp["supplier_name"];
        $this->contact_no=$this->temp["contact_no"]; 
		$this->address=$this->temp["address"];
		$this->contact_person=$this->temp["contact_person"];
		$this->email_id=$this->temp["email_id"];
		$this->gstin=$this->temp["gstin"];
		
		if(isset($_POST["Save"]))
		{
		$this->supplier_name=($_POST["supplier_name"]);
		$this->address=($_POST["address"]);
		$this->contact_no=($_POST["contact_no"]);
		$this->contact_person=($_POST["contact_person"]);
		$this->email=($_POST["email"]);
		$this->gstin=$_POST["gstin"];
			
	
	
	
		if($_POST["Save"]=="New")
		{
		$whr="supplier_name='".$_POST["supplier_name"]."' and contact_no='".$_POST["contact_no"]."'";
		if($this->getNumRows($this->Table_Name, $whr)<=0)
		{		$lastid=$this->insert($this->Table_Name,array($this->supplier_name,$this->address,$this->contact_no,$this->contact_person,$this->email,$this->gstin),"supplier_name,address,contact_no,contact_person,email_id,gstin");
				header("location:supplier_list.php");
				$this->message='<div class="alert alert-danger">One New Record Added</div>';
				$_SESSION["msg"]=$this->message;
		}		
		else { echo $this->error='<div class="alert alert-danger">Item Type Name Must be Unique</div>';}
		}
		if($_POST["Save"]=="Edit")
		{
			$uid= $_GET["uid"];
			 $where ="md5(id)='$uid'";
			$this->update($this->Table_Name,array('supplier_name'=>$this->supplier_name,'address'=>$this->address,'contact_no'=>$this->contact_no,'contact_person'=>$this->contact_person,'email_id'=>$this->email,'gstin'=>$this->gstin),$where);

			header("location:supplier_list.php");
			 			 $this->message='<div class="alert alert-danger">One Record Updated</div>';
						 $_SESSION["msg"]=$this->message;
		}
		if($_POST["Save"]=="View")
		{
						header("location:supplier_list.php");
		}
		 
	}
	
	}
  
/************************* supplier End ****************************/





/*************************Change Password ****************************/

function password_alter()
{
	if(isset($_POST["Save"])){
		$old_password=$_POST["old_pass"];
		$new_password=$_POST["new_password"];
		$confirm_pass=$_POST["confirm_pass"];
		$spassword=$_SESSION["spass"];
		$slogin=$_SESSION["slogin"];
		if($old_password==$spassword)
		{   
			if($new_password==$confirm_pass ){
			
					mysql_query("update  stf_login set spass='".$confirm_pass."' where slogin='".$slogin."' AND spass='".$spassword."' ");
					//header("location:index.php");
					$this->message='<div class="alert alert-success">Password Changed Sucessfully</div>';;
					$_SESSION["spass"]=$confirm_pass;
					}
			else{
				$this->message='<div class="alert alert-danger">Password not Matched</div>';}		
			
			}
		else{
				$this->message='<div class="alert alert-danger">Wrong Old Password</div>';	}	
	
	
		}		
			
			
}	
/*************************End ****************************/
/*************************Login Page ****************************/

function loginpage_alter()
{	
	unset($_SESSION["slogin"]);
	unset($_SESSION["spass"]);
	
	if(isset($_POST["Save"])){
	
	
	  $query = mysql_query("SELECT * FROM stf_login where slogin = '".$_POST["slogin"]."' AND spass = '".$_POST["spass"]."'");
	$row = mysql_fetch_array($query) or die(mysql_error());
	if(!empty($row["slogin"]) AND !empty($row["spass"]))
	
	{
		$_SESSION["slogin"] = $row["slogin"];
		$_SESSION["spass"] = $row["spass"];
		
		
		echo $ip=$_SERVER["REMOTE_ADDR"];
		 echo $lastlogin_date=date("d-m-Y");
		 echo $last_time=date("H:i:s");
	mysql_query("update  stf_login set lastlogin_date='".$lastlogin_date."',last_time='".$last_time."' where slogin='".$_POST["slogin"]."' AND spass='".$_POST["spass"]."' ");
		header("location:index.php");
	}
	else
	{	//header("location:login_page.php");
		echo "Wrong ID or Password";
		
	}		
		}	
}	
/*************************End ****************************/

/*************************End Task ****************************/

} 
?> 		