<?php

function upload_image()
{
 if(isset($_FILES["item_image"]))
 {
  $extension = explode('.', $_FILES['item_image']['name']);
  $new_name = rand() . '.' . $extension[1];
  $destination = './upload/' . $new_name;
  move_uploaded_file($_FILES['item_image']['tmp_name'], $destination);
  return $new_name;
 }
}
function get_image_name($item_no)
{
 include('db_con.php');
 $statement = $connection->prepare("SELECT item_image FROM items WHERE item_no = '$item_no'");
 $statement->execute();
 $result = $statement->fetchAll();
 foreach($result as $row)
 {
  return $row["item_image"];
 }
}
function fill_brand($connect)
{
$query = "SELECT * FROM item_brand 
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Brand</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["brand_id"].'">'.$row["brand_name"].'</option>';
	}
	return $output;
}

function fill_bank($connect)
{
$query = "SELECT * FROM accounts where acc_parent = 102
	OR acc_parent = 101 and status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_city($connect)
{
$query = "SELECT DISTINCT city FROM accounts where (acc_type = 'DEBTOR' OR acc_type = 'CREDITOR')
	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select City(ALL)</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["city"].'">'.$row["city"].'</option>';
	}
	return $output;
}
function fill_itemname($connect)
{
$query = "SELECT * FROM items
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Item</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["item_name"].'">'.$row["item_name"].'</option>';
	}
	return $output;
}
function fill_emp($connect)
{
$query = "SELECT * FROM employees
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Employee</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["emp_id"].'">'.$row["first_name"].'</option>';
	}
	return $output;
}
function fill_consume($connect)
{
$query = "SELECT * FROM accounts where acc_name LIKE '%consume%'
	AND status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_titles($connect)
{
$query = "SELECT * FROM titles
	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Print Titles</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["id"].'">'.$row["heading1"].'</option>';
	}
	return $output;
}
function fill_color($connect)
{
$query = "SELECT * FROM item_color
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Color</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["color_id"].'">'.$row["color_name"].'</option>';
	}
	return $output;
}
function fill_cur_user($connect,$user_acc_no)
{
$query = "SELECT * FROM accounts where acc_no = '".$user_acc_no."'
	and status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select </option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_itemtype($connect)
{
$query = "SELECT * FROM item_type 
	WHERE status = 'active' order by type_name 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Type</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["type_id"].'">'.$row["type_name"].'</option>';
	}
	return $output;
}

function fill_itemcategory($connect)
{
$query = "SELECT * FROM item_category
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Category</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["category_id"].'">'.$row["category_name"].'</option>';
	}
	return $output;
}
function fill_user($connect)
{
$query = "SELECT * FROM user_detail
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select User</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["user_id"].'">'.$row["user_name"].'</option>';
	}
	return $output;
}
function fill_uom($connect)
{
$query = "SELECT * FROM item_uom
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select UOM</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["uom_id"].'">'.$row["uom_name"].'</option>';
	}
	return $output;
}
function fill_branch($connect)
{
$query = "SELECT * FROM branch 
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Branch</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["branch_id"].'">'.$row["branch_name"].'</option>';
	}
	return $output;
}
function fill_store($connect)
{
$query = "SELECT * FROM store 
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select store</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["store_id"].'">'.$row["store_name"].'</option>';
	}
	return $output;
}
function count_total_credit_order_value($connect)
{
	$query = "
	SELECT sum(inventory_order_total) as total_order_value FROM inventory_order WHERE payment_status = 'credit' AND inventory_order_status='active'
	";
	if($_SESSION['type'] == 'user')
	{
		$query .= ' AND user_id = "'.$_SESSION["user_id"].'"';
	}
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	foreach($result as $row)
	{
		return number_format($row['total_order_value'], 2);
	}
}
function fill_made($connect)
{
$query = "SELECT DISTINCT item_made FROM items
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Made</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["item_made"].'">'.$row["item_made"].'</option>';
	}
	return $output;
}
function fill_type($connect)
{
$query = "SELECT DISTINCT item_type FROM items
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Type</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["item_type"].'">'.$row["item_type"].'</option>';
	}
	return $output;
}
function fill_currency($connect)
{
$query = "SELECT * FROM currency
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Currency</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["cur_name"].'">'.$row["cur_name"].'</option>';
	}
	return $output;
}
function fill_accounts($connect)
{
$query = "SELECT acc_no, CONCAT(acc_no, ' - ',acc_name ) as acc_name FROM accounts where acc_no > '1015'
and status = 'Active'
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_accounts_gl($connect)
{
$query = "SELECT acc_no, CONCAT(acc_no, ' - ',acc_name ) as acc_name FROM accounts where acc_no > 1015 and status = 'Active' and acc_type = 'Asset' OR acc_type = 'Liability' OR acc_type = 'Equity' OR acc_type = 'Expense'	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_customer_accounts($connect)
{
$query = "SELECT acc_no, acc_name FROM accounts where acc_type = 'DEBTOR'	
and status = 'Active'
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Customer</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_parent_accounts($connect)
{
$query = "SELECT acc_no, CONCAT(acc_no, ' - ',acc_name ) as acc_name FROM accounts_parent where status = 'Active' order by acc_name
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Parent Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_accounts_all($connect)
{
$query = "SELECT acc_no, CONCAT(acc_no, ' - ',acc_name ) as acc_name FROM accounts_parent where acc_no > '1015' and status = 'Active'	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	$query = "SELECT v_id,CONCAT(v_id,' - ',name ) as name FROM vendors 
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["v_id"].'">'.$row["name"].'</option>';
	}
	$query = "SELECT cust_id, CONCAT(cust_id, ' - ',name) as name FROM customers 
	WHERE cust_id > 1 and status = 'Active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["cust_id"].'">'.$row["name"].'</option>';
	}
	return $output;
}
function fill_accounts_pay($connect)
{
$query = "SELECT DISTINCT p.acc_no, CONCAT(p.acc_no, ' - ',a.acc_name ) as acc_name FROM accounts a, pay_voucher p where p.acc_no=a.acc_no 	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Bank Account</option>';
	$output .= '<option value="0">All</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_accountsall($connect)
{
$query = "SELECT acc_no, CONCAT(acc_no, ' - ',acc_name ) as acc_name FROM accounts	
where status = 'Active'
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_parents($connect)
{
$query = "select * from accounts_parent where status = 'Active'";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Parent Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function ar_outstandings($connect)
{
//delete
	$query = "delete from out_standings";
	$statement = $connect->prepare($query);
	$statement->execute();
$query = "insert into out_standings select b.cust_id, sale, payment, op_balance,balance from
(select a.cust_id, sum(sale) sale, sum(payment) payment, sum(op_balance) op_balance, sum(sale) + sum(op_balance)-sum(payment) balance
from (select acc_no as cust_id , IFNULL(debit,0) as sale, 0 as payment, 0 as op_balance from jv_detail 
union all
	select acc_no as cust_id , 0 as sale, IFNULL(credit,0) as payment, 0 as op_balance from jv_detail 
union all
select cust_id, 0 as sale,0 as payment, op_balance from customers ) a group by a.cust_id) b
";
	$statement = $connect->prepare($query);
	$statement->execute();
	
}
function ap_outstandings($connect)
{
//delete
	$query = "delete from out_standings";
	$statement = $connect->prepare($query);
	$statement->execute();
$query = "insert into out_standings select b.cust_id, sale, payment, op_balance,balance from
(select a.cust_id, sum(sale) sale, sum(payment) payment, sum(op_balance) op_balance, sum(sale) + sum(op_balance)-sum(payment) balance
from (select acc_no as cust_id , IFNULL(credit,0) as sale, 0 as payment, 0 as op_balance from jv_detail 
union all
	select acc_no as cust_id , 0 as sale, IFNULL(debit,0) as payment, 0 as op_balance from jv_detail 
union all
select cust_id, 0 as sale,0 as payment, op_balance from customers ) a group by a.cust_id) b
";
	$statement = $connect->prepare($query);
	$statement->execute();
	
}
function accounts_update($connect)
{
$statement = $connect->prepare("update accounts set balance = 0");
$statement->execute();
$statement = $connect->prepare("update accounts_parent set balance = 0");
$statement->execute();
$statement = $connect->prepare("delete from temp_accounts");
$statement->execute();
$sql = "insert into temp_accounts select acc_no,sum(debit-credit) balance from jv_detail group by acc_no";
$statement = $connect->prepare($sql);
$statement->execute();
$statement = $connect->prepare("update accounts a,temp_accounts t set a.balance=t.balance where a.acc_no=t.acc_no");
$statement->execute();
$statement = $connect->prepare("delete from temp_accounts");
$statement->execute();
$statement = $connect->prepare("insert into temp_accounts select acc_parent acc_no, sum(balance) balance from accounts group by acc_parent");
$statement->execute();
$statement = $connect->prepare("update accounts_parent a,temp_accounts t set a.balance=t.balance where a.acc_no=t.acc_no");
$statement->execute();


}
function stock_update($connect)
{
	
$query = "delete from cur_stock";
$statement = $connect->prepare($query);
$statement->execute();
$query = "update items set stock = 0";
$statement = $connect->prepare($query);
$statement->execute();
$query ="insert into cur_stock select b.item_no, purchase, pr, sale, sr, qty_in,qty_out, stock
from ( select a.item_no,  sum(purchase) purchase, sum(pr) pr, sum(sale) sale, 
	sum(sr) sr, sum(qty_in) qty_in,sum(qty_out) qty_out,sum(purchase) - sum(sale) - sum(pr) + sum(sr) + sum(qty_in) - sum(qty_out) stock 
	from (
	select item_no, sum(IFNULL(qty,0)) as purchase, 0 as pr, 0 as sale, 0 as sr,0 as qty_in, 0 as qty_out
	 from purchase_detail group by item_no
	 union all
	 select item_no, 0 as purchase, sum(IFNULL(qty,0)) as pr,0 as sale,0 as sr,0 as qty_in, 0 as qty_out 
	 from pr_detail group by item_no
	 union all
	 select item_no, 0 as purchase, 0 as pr, sum(IFNULL(qty,0)) as sale,0 as sr,0 as qty_in, 0 as qty_out 
	 from sale_detail group by item_no
	 union all
	 select item_no, 0 as purchase, 0 as pr, 0 as sale,sum(IFNULL(qty,0)) as sr,0 as qty_in, 0 as qty_out 
	  from sr_detail group by item_no
      union ALL      
	 select item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,sum(IFNULL(qty_in,0)) as qty_in, 0 as qty_out 
	  from adjusted_stock group by item_no
          UNION ALL
      select item_no,0 as purchase, 0 as pr, 0 as sale,0 as sr,0 as qty_in, sum(IFNULL(qty_out,0)) as qty_out 
	  from adjusted_stock group by item_no) a group by a.item_no) b";
$statement = $connect->prepare($query);
$statement->execute();
$query ="update items i,cur_stock s set i.stock = s.stock where i.item_id=s.item_no";
$statement = $connect->prepare($query);
$statement->execute();
}
function stock_instore($connect)
{
//delete
	$query = "delete from stock_instore";
	$statement = $connect->prepare($query);
	$statement->execute();
$query = "insert into stock_instore select b.store_id, b.item_no, purchase, pr, sale, sr, qty_in,qty_out,qty_from,qty_to, stock 
from ( select a.store_id, a.item_no, sum(purchase) purchase, sum(pr) pr, sum(sale) sale, 
	sum(sr) sr, sum(qty_in) qty_in,sum(qty_out) qty_out,sum(qty_from) qty_from,sum(qty_to) qty_to, sum(purchase) - sum(sale) - sum(pr) + sum(sr) + sum(qty_in) - sum(qty_out)
	-sum(qty_from)+sum(qty_to) stock 
	from ( select 1 as store_id, item_id as item_no, op_stock as purchase, 0 as pr, 0 as sale, 0 as sr,0 as qty_in, 0 as qty_out,0 as qty_from,0 as qty_to
	 from items 
	 union all
	select store_id, item_no, sum(IFNULL(qty,0)) as purchase, 0 as pr, 0 as sale, 0 as sr,0 as qty_in, 0 as qty_out,0 as qty_from,0 as qty_to
	 from purchase_detail group by store_id, item_no
	 
	 union all
	 select store_id, item_no, 0 as purchase, sum(IFNULL(qty,0)) as pr,0 as sale,0 as sr,0 as qty_in, 0 as qty_out,0 as qty_from,0 as qty_to
	 from pr_detail group by store_id, item_no
	 union all
	 select store_id, item_no, 0 as purchase, 0 as pr, sum(IFNULL(qty,0)) as sale,0 as sr,0 as qty_in, 0 as qty_out ,0 as qty_from,0 as qty_to
	 from sale_detail group by store_id, item_no
	 union all
	 select store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,sum(IFNULL(qty,0)) as sr,0 as qty_in, 0 as qty_out,0 as qty_from,0 as qty_to 
	  from sr_detail group by store_id, item_no
      union ALL      
	 select store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,sum(IFNULL(qty_in,0)) as qty_in, 0 as qty_out ,0 as qty_from,0 as qty_to
	  from adjusted_stock group by store_id, item_no
          UNION ALL
      select store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,0 as qty_in, sum(IFNULL(qty_out,0)) as qty_out ,0 as qty_from,0 as qty_to
	  from adjusted_stock group by store_id, item_no
	  UNION ALL
      select from_store as store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,0 as qty_in, 0 as qty_out ,sum(IFNULL(qty,0)) as qty_from,0 as qty_to
	  from adjust_stock group by store_id, item_no
	  UNION ALL
      select to_store as store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,0 as qty_in, 0 as qty_out ,0 as qty_from,sum(IFNULL(qty,0)) as qty_to
	  from adjust_stock group by store_id, item_no) a group by a.store_id, a.item_no) b";
	$statement = $connect->prepare($query);
	$statement->execute();
	
}
function item_stock_instore($connect)
{
//delete
	$query = "delete from stock_instore";
	$statement = $connect->prepare($query);
	$statement->execute();
$query = "insert into stock_instore select b.store_id, b.item_no, purchase, pr, sale, sr, qty_in,qty_out,qty_from,qty_to,0 as stock
 
	from ( select 1 as store_id, item_id as item_no, op_stock as purchase, 0 as pr, 0 as sale, 0 as sr,0 as qty_in, 0 as qty_out,0 as qty_from,0 as qty_to
	 from items 
	 union all
	select store_id, item_no, sum(IFNULL(qty,0)) as purchase, 0 as pr, 0 as sale, 0 as sr,0 as qty_in, 0 as qty_out,0 as qty_from,0 as qty_to
	 from purchase_detail group by store_id, item_no
	 
	 union all
	 select store_id, item_no, 0 as purchase, sum(IFNULL(qty,0)) as pr,0 as sale,0 as sr,0 as qty_in, 0 as qty_out,0 as qty_from,0 as qty_to
	 from pr_detail group by store_id, item_no
	 union all
	 select store_id, item_no, 0 as purchase, 0 as pr, sum(IFNULL(qty,0)) as sale,0 as sr,0 as qty_in, 0 as qty_out ,0 as qty_from,0 as qty_to
	 from sale_detail group by store_id, item_no
	 union all
	 select store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,sum(IFNULL(qty,0)) as sr,0 as qty_in, 0 as qty_out,0 as qty_from,0 as qty_to 
	  from sr_detail group by store_id, item_no
      union ALL      
	 select store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,sum(IFNULL(qty_in,0)) as qty_in, 0 as qty_out ,0 as qty_from,0 as qty_to
	  from adjusted_stock group by store_id, item_no
          UNION ALL
      select store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,0 as qty_in, sum(IFNULL(qty_out,0)) as qty_out ,0 as qty_from,0 as qty_to
	  from adjusted_stock group by store_id, item_no
	  UNION ALL
      select from_store as store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,0 as qty_in, 0 as qty_out ,sum(IFNULL(qty,0)) as qty_from,0 as qty_to
	  from adjust_stock group by store_id, item_no
	  UNION ALL
      select to_store as store_id, item_no, 0 as purchase, 0 as pr, 0 as sale,0 as sr,0 as qty_in, 0 as qty_out ,0 as qty_from,sum(IFNULL(qty,0)) as qty_to
	  from adjust_stock group by store_id, item_no) b";
	$statement = $connect->prepare($query);
	$statement->execute();
	
}
function fill_asset($connect)
{
$query = "SELECT acc_no,CONCAT(acc_no,' - ',acc_name) as acc_name FROM accounts where acc_type = 'Asset'
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	
	return $output;
}
function fill_liability($connect)
{
$query = "SELECT acc_no,CONCAT(acc_no,' - ',acc_name) as acc_name FROM accounts where acc_type = 'Liability'	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">To Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	$query = "SELECT acc_no,CONCAT(acc_no,' - ',acc_name) as acc_name FROM accounts where acc_type = 'Equity'	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_assetandliability($connect)
{
$query = "SELECT * FROM accounts where acc_type = 'Asset' and acc_type = 'Liability'	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_accounts_old($connect)
{
$query = "SELECT acc_no,CONCAT(acc_no,'-',acc_name) as acc_name FROM accounts_old	
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
function fill_sm($connect)
{
$query = "SELECT DISTINCT * FROM sales_man
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Sale Man</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["sm_id"].'">'.$row["sname"].'</option>';
	}
	return $output;
}
function fill_item($connect)
{
$query = "SELECT item_no,CONCAT(item_no, ' - ',item_name) as item_name FROM items  
	WHERE status = 'active' order by item_name ASC 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select item</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["item_no"].'">'.$row["item_name"].'</option>';
	}
	return $output;
}
function fill_itemstock($connect)
{
$query = "SELECT i.item_id, CONCAT(t.type_name, ' ',i.item_name, ' ( ',i.stock,' )') as item_name from items i,item_type t where t.type_id=i.type_id 
	AND i.status = 'active' order by item_name ASC 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select item</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["item_id"].'">'.$row["item_name"].'</option>';
	}
	return $output;
}
function fill_v_name($connect)
{
$query = "SELECT v_id,CONCAT(v_id,' - ',name ) as name FROM vendors 
	WHERE v_id > 6000 and status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Vendor</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["v_id"].'">'.$row["name"].'</option>';
	}
	return $output;
}
function fill_party($connect)
{
$query = "SELECT acc_no,concat(acc_no,' - ',acc_name) name FROM accounts where (acc_type='DEBTOR' OR acc_type='CREDITOR') AND status = 'Active' 
	 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Party</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["name"].'</option>';
	}
	return $output;
}
function fill_gstcustomer($connect)
{
$query = "SELECT cust_id acc_no,concat(cust_id,' - ',name) name from customers where gst = 'ON' 
	 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select GST Customer</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["name"].'</option>';
	}
	return $output;
}
function fill_sv_name($connect)
{
$query = "SELECT sv_id,CONCAT(sv_id,' - ',sv_name ) as name FROM sub_vendors 
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Vendor</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["sv_id"].'">'.$row["name"].'</option>';
	}
	return $output;
}
function fill_c_name($connect)
{
$query = "SELECT cust_id, CONCAT(cust_id, ' - ',name) as name FROM customers 
	WHERE status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Customer</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["cust_id"].'">'.$row["name"].'</option>';
	}
	return $output;
}
function fill_acc_name($connect)
{
	$query = "SELECT acc_no,CONCAT(acc_no,' - ',acc_name)as acc_name FROM accounts 
	WHERE acc_type='Current Asset' AND status = 'active' 
	";
	$statement = $connect->prepare($query);
	$statement->execute();
	$result = $statement->fetchAll();
	$output = '<option value="">Select Account</option>';
	foreach($result as $row)
	{
		$output .= '<option value="'.$row["acc_no"].'">'.$row["acc_name"].'</option>';
	}
	return $output;
}
?>