<?php
/**
 * This is general file which contains
 * connection file, common function file, etc.,
 *
 * PHP version 5
 *
 * @category Admin_Tool
 * @package  Admin_Tool
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  ACE
 * @version  CVS:1.0.1
 * @link     http://auminfosys.com/
 * @filesource
 */
 
/**
 * This is general file which contains
 * connection file, common function file, etc.,
 *
 */
  	require "../commonincludefiles.php";
    $Product_Ids = $_POST['ids']; // Get our array back and translate it :
	$deleteProduct_Id = 0;
   	$deleteProduct_Id = json_decode(stripslashes($Product_Ids));
	$deleteAccount_Id = json_decode(stripslashes($_POST['acountids']));


	if(sizeof($deleteProduct_Id)<1){
		echo '0';
	}
	else{
		$objVendorMgmt = new VendorMgmt();
		$product_id  = implode(",",$deleteProduct_Id);
		$account_id  = implode(",",$deleteAccount_Id);

		 if($account_id!="")
		 {
			$str_voucherid = "";
			$str_accountid = "";
		
			$qry1 = "SELECT am.account_id 
					FROM ams_accountmaster am
					WHERE am.company_id = '".$_SESSION["cCompany_id"]."' AND am.account_id = $account_id ";
					$result = dbQuery($qry1);
			
			if(dbRows($result)>0){
				$record_account = dbArray($result);
				$str_accountid = $record_account['account_id'];
				if($str_accountid!=""){
					$qry2 = "SELECT group_concat(vm.voucher_id) AS voucher_id
							FROM ams_vouchermaster vm,ams_voucherdetail vd
							WHERE vm.company_id = '".$_SESSION["cCompany_id"]."' 
								AND vd.company_id = '".$_SESSION["cCompany_id"]."' 
								AND vm.voucher_id=vd.voucher_id 
								AND vd.account_id in($str_accountid) ";
					$result = dbQuery($qry2);
					if(dbRows($result)>0){
						$record_voucher = dbArray($result);
						 $str_voucherid = $record_voucher['voucher_id'];
					}
				}
			}
			
		
			if($str_accountid!=""){
				$qry3 = "delete from ams_accountmasterdetail where account_id in ($str_accountid) And company_id='".$_SESSION["cCompany_id"]."'";
				$qry4 = "delete from ams_accountmaster where account_id in ($str_accountid) And company_id='".$_SESSION["cCompany_id"]."'";
				
				
				dbQuery($qry3);
				dbQuery($qry4);
			}
			
			if($str_voucherid != ""){
				$qry5 = "delete from ams_vouchermaster where voucher_id in ($str_voucherid) And company_id='".$_SESSION["cCompany_id"]."'";
				$qry6 = "delete from ams_voucherdetail where voucher_id in ($str_voucherid) And company_id='".$_SESSION["cCompany_id"]."'";
				dbQuery($qry5);
				dbQuery($qry6);
			}
		 }
		$objVendorMgmt ->deleteId = $product_id;
		$objVendorMgmt ->delete();
		echo '1';
	}       
?>