<?php
require_once("../include/config.php");
require_once("../include/startup.php");
	
if($G_memberid > 0)
{
	
$obj  			= new Client();
$factory_obj   = new ClientFactories();
$branch_obj  	= new ClientBranches();
$objinfo  		= new AllTables();
$invoice_obj					=	new Invoice();
$proforma_obj	=	new Invoice_frproforma();
$quotation_obj	=	new Invoice_frquotation();

$memberid	   = $G_memberid;
$companyid 	   = (int)($_GET['clientcompanyid']);
	
		
			
	if($_POST['SUBMIT'])
	{
		 //Information
	 	$memberid 									= $_POST['txtmemberid'];
	 	$companyid 									= $_POST['txtcompanyid'];
	 	$NewProduct['clientcompanyid']     	= $companyid;
	 	$NewProduct['memberid']					= $memberid;
	 	$NewProduct['companyname']				= sanitize($_POST['txtcompanyname'],SQL);
	 	
	 	//Address		
		$NewProduct['Addline1'] 					= sanitize($_POST['Addline1'],SQL);
	 	$NewProduct['Addline2'] 					= sanitize($_POST['txtAddline1'],SQL);
	 	$NewProduct['head_CityName'] 				= sanitize($_POST['txthead_CityName1'],SQL);
	 	$state 											= explode("-",sanitize($_POST['txtstate'],SQL));
	 	$NewProduct['head_Stateid1'] 				= $state[0];
	 	$NewProduct['head_StateidName'] 			= $state[1];
	 	$Country											= explode("-",sanitize($_POST['txtcountry'],SQL));
	 	$NewProduct['Country'] 						= $Country[1];
		$NewProduct['head_Pin'] 					= sanitize($_POST['txtpincode1'],SQL);
		
	
	   //Contact Information
	 	$NewProduct['head_TelNo'] 	      		= sanitize($_POST['txthead_TelNo'],SQL);
		$NewProduct['head_mobNo'] 	     		 	= sanitize($_POST['head_mobNo'],SQL);
		$NewProduct['head_Email'] 	      		= sanitize($_POST['head_Email'],SQL);
		$NewProduct['head_FaxNo'] 	      		= sanitize($_POST['head_FaxNo'],SQL);
	
	
	   //Information
	 	$NewProduct['gstapplicable']					= $_POST['txtgstapplicable'];
	 	$NewProduct['gstno'] 							= sanitize($_POST['txtgstno1'],SQL);
	 	$NewProduct['Tan_No'] 							= sanitize($_POST['txttanno'],SQL);
	 	$NewProduct['panno']								= sanitize($_POST['txtpanno'],SQL);
	 	$NewProduct['memberapprovalstatus']			= sanitize($_POST['txtstatus'],SQL);
		
		//invoice edit 
	 		$invoicearray['billed_membername'] 				= sanitize($_POST['txtcompanyname'],SQL);
	 		$invoicearray['inv_Add1'] 							= sanitize($_POST['Addline1'],SQL);
			$invoicearray['inv_Add2'] 							= sanitize($_POST['txtAddline1'],SQL);
			$invoicearray['inv_Add3'] 							= sanitize($_POST['inv_Add3'],SQL);
			$invoicearray['inv_CityName'] 					= sanitize($_POST['txthead_CityName1'],SQL);
			$invoicearray['inv_Pin'] 							= sanitize($_POST['txtpincode1'],SQL);
			$state1 											= explode("-",sanitize($_POST['txtstate'],SQL));
			$invoicearray['inv_StateName'] 				= $state1[0];
	 		$invoicearray['inv_head_Stateid'] 			= $state1[1];
			$Country1											= explode("-",sanitize($_POST['txtcountry'],SQL));
		 	$invoicearray['inv_Country'] 						= $Country1[1];
			$invoicearray['inv_GST_no'] 						= sanitize($_POST['txtgstno1'],SQL);

			//proforma edit 
	 		$proformaarray['billed_membername'] 				= sanitize($_POST['txtcompanyname'],SQL);
	 		$proformaarray['inv_Add1'] 							= sanitize($_POST['Addline1'],SQL);
			$proformaarray['inv_Add2'] 							= sanitize($_POST['txtAddline1'],SQL);
			$proformaarray['inv_Add3'] 							= sanitize($_POST['inv_Add3'],SQL);
			$proformaarray['inv_CityName'] 					= sanitize($_POST['txthead_CityName1'],SQL);
			$proformaarray['inv_Pin'] 							= sanitize($_POST['txtpincode1'],SQL);
			$state1 											= explode("-",sanitize($_POST['txtstate'],SQL));
			$proformaarray['inv_StateName'] 				= $state1[0];
	 		$proformaarray['inv_head_Stateid'] 			= $state1[1];
			$Country1											= explode("-",sanitize($_POST['txtcountry'],SQL));
		 	$proformaarray['inv_Country'] 						= $Country1[1];
			$proformaarray['inv_GST_no'] 						= sanitize($_POST['txtgstno1'],SQL);

			//quotation edit 
	 		$quotationarray['billed_membername'] 				= sanitize($_POST['txtcompanyname'],SQL);
	 		$quotationarray['inv_Add1'] 							= sanitize($_POST['Addline1'],SQL);
			$quotationarray['inv_Add2'] 							= sanitize($_POST['txtAddline1'],SQL);
			$quotationarray['inv_Add3'] 							= sanitize($_POST['inv_Add3'],SQL);
			$quotationarray['inv_CityName'] 					= sanitize($_POST['txthead_CityName1'],SQL);
			$quotationarray['inv_Pin'] 							= sanitize($_POST['txtpincode1'],SQL);
			$state1 											= explode("-",sanitize($_POST['txtstate'],SQL));
			$quotationarray['inv_StateName'] 				= $state1[0];
	 		$quotationarray['inv_head_Stateid'] 			= $state1[1];
			$Country1											= explode("-",sanitize($_POST['txtcountry'],SQL));
		 	$quotationarray['inv_Country'] 						= $Country1[1];
			$quotationarray['inv_GST_no'] 						= sanitize($_POST['txtgstno1'],SQL);
	 	
		$whereclient = "clientcompanyid = ".$companyid."";
		$editData	= $obj -> EditClient($NewProduct,$whereclient);

		$whereclient1 = "billed_membercompanyid = ".$companyid."";
		$editData1	= $invoice_obj -> EditInvoice($invoicearray,$whereclient1);

		//$whereclient2 = "billed_membercompanyid = ".$companyid."";
		$editData2	= $proforma_obj -> EditInvoice($proformaarray,$whereclient1);

		//$whereclient3 = "billed_membercompanyid = ".$companyid."";
		$editData3	= $quotation_obj -> EditInvoice($quotationarray,$whereclient1);
		if($editData)
		{
				$redirect_url = DOC_ROOT."admin/viewclient.php";
				header("Location: $redirect_url");
    			exit;
		}
		
	}	
	else 
	{
		$sql = "select * from mstclients where clientcompanyid = $companyid";
	
		$sqllist = $obj->getClient('','',$sql);
	
		$productdatacount=count($sqllist);

		for($i=0;$i<$productdatacount;$i++)
		{
				$companyname 								= $sqllist[$i]['companyname'];
				$PersonName 								= $sqllist[$i]['PersonName1'];
				$gstapplicable 							= $sqllist[$i]['gstapplicable'];
				 if($gstapplicable == '1')
		      {
					$gstvalselect1      = "selected";
		      }
		      elseif($gstapplicable == '0')
		      {
					$gstvalselect0      = "selected";
		      }
		       elseif($gstapplicable == '2')
		      {
					$gstvalselect2      = "selected";
		      }
				$gstno										= $sqllist[$i]['gstno'];
	         $Tan_No										= $sqllist[$i]['Tan_No'];
				$panno										= $sqllist[$i]['panno'];
				$billing_address							= $sqllist[$i]['billing_address'];
				$taxnotapplicable							= $sqllist[$i]['taxnotapplicable'];
				$gstnotapplicable							= $sqllist[$i]['gstnotapplicable'];
				$Addline1									= $sqllist[$i]['Addline1'];
				$Addline2									= $sqllist[$i]['Addline2'];
				$head_CityName								= $sqllist[$i]['head_CityName'];
				$head_Stateid1								= $sqllist[$i]['head_Stateid1'];
				$head_StateidName							= $sqllist[$i]['head_StateidName'];
				$GCountry									= $sqllist[$i]['Country'];
				$head_Pin									= $sqllist[$i]['head_Pin'];
		      $head_TelNo									= $sqllist[$i]['head_TelNo'];
		      $head_mobNo									= $sqllist[$i]['head_mobNo'];
		      $head_FaxNo									= $sqllist[$i]['head_FaxNo'];
		      $head_Email									= $sqllist[$i]['head_Email'];
		      $memberapprovalstatus					= $sqllist[$i]['memberapprovalstatus'];
		      if($memberapprovalstatus == '1')
		      {
					$valselect1      = "selected";
		      }
		      elseif($memberapprovalstatus == '0')
		      {
					$valselect0      = "selected";
		      }
		     
		}
		require_once("header1.html");
		require_once("leftnav.html");
		require_once("edit-client1.html");
			require_once("footer1.html");

	}
		
	


}
else if (!headers_sent($filename, $linenum)) 
{
				$redirect_url = DOC_ROOT."login.php";
				header("Location: $redirect_url");
    				exit;
					// You would most likely trigger an error here.
}
else 
{
				echo "Headers already sent in $filename on line $linenum\n" .
          			"Cannot redirect, for now please click this <a ";
    				exit;
}   

	
	
?>
