<?php


session_start();
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("function.inc.php");


if (!empty($creation_date))	{
	$creation_date  = explodeword($creation_date);
	$creation_date  = "$creation_date";

}	
else {$creation_date= 'null';}


$clientact_remark= ereg_replace("'", "\'",$clientact_remark);

if (!empty($clientact_startdate))	{
	$clientact_startdate  = explodeword($clientact_startdate);
	$clientact_startdate  = "$clientact_startdate";

}	
else {$clientact_startdate= 'null';}


if (!empty($deactivatedate))	{
	$deactivatedate  = explodeword($deactivatedate);
	$deactivatedate  = "'$deactivatedate'";

}	
else {$deactivatedate= 'null';}


if (!empty($vat_date))	{
	$vat_date  = explodeword($vat_date);
	$vat_date  = "'$vat_date'";

}	
else {$vat_date= 'null';}


if (!empty($clientact_enddate))	{
	$clientact_enddate  = explodeword($clientact_enddate);
	$clientact_enddate  = "$clientact_enddate";

}	
else {$clientact_enddate= 'null';}






	  if(empty($costcenter_code))
  $costcenter_code= 'null' ;
else
  $costcenter_code="'$costcenter_code'";

 	  if(empty($project_code))
  $project_code='null';
else
  $project_code="'$project_code'"; 
  
  
   	  if(empty($client_groupcode))
  $client_groupcode='null';
else
  $client_groupcode="'$client_groupcode'"; 

if(empty($client_frequencyofvisit))
$client_frequencyofvisit=0;


if(empty($credit_limit))
$credit_limit=0;


if(empty($budget_limit))
$budget_limit=0;


   	  if(empty($client_paytermtype))
$client_paytermtype='null';
else
  $client_paytermtype="'$client_paytermtype'"; 

if(empty($client_paymentterm))
$client_paymentterm=0;

if(empty($client_paymentterm2))
$client_paymentterm2=0;


if(empty($client_chterms))
$client_chterms=0;

if(empty($client_invrounded))
$client_invrounded=0;


if(empty($client_gcino))
$client_gcino=0;

if(empty($client_tobcode))
$client_tobcode=0;

	if(empty($deactivateclient))
					$deactivateclient=0;
					
					
					
if(empty($sent_email))
$sent_email=0;

if(empty($client_tax0))
$client_tax0=0;

if(empty($client_tax1))
$client_tax1=0;

if(empty($client_tax2))
$client_tax2=0;

if(empty($client_tax3))
$client_tax3=0;

if(empty($client_tax4))
$client_tax4=0;


if(empty($client_tax5))
$client_tax5=0;


	  if(empty($client_vat))
$client_vat=0;


if(empty($client_multiplesales))
$client_multiplesales=0;

 if(empty($salesman_com))
		 $salesman_com=0;
		 
		 
		 
$ledger_name = ereg_replace("'", "\'", $ledger_name);
$client_tc = ereg_replace("'", "\'", $client_tc);
$ledger_description = ereg_replace("'", "\'",$ledger_description);
$client_vatno = ereg_replace("'", "\'",$client_vatno);
$credit_control = ereg_replace("'", "\'",$credit_control);
$client_group = ereg_replace("'", "\'",$client_group);
$client_checkaccount = ereg_replace("'", "\'",$client_checkaccount);
$country = ereg_replace("'", "\'",$country);
$state = ereg_replace("'", "\'",$state);
$city_client = ereg_replace("'", "\'",$city_client);
$Address = ereg_replace("'", "\'",$Address);
$Address2 = ereg_replace("'", "\'",$Address2);	
$email = ereg_replace("'", "\'",$email);
$homepage = ereg_replace("'", "\'",$homepage);
$phone1 = ereg_replace("'", "\'",$phone1);
$phone2 = ereg_replace("'", "\'",$phone2);
$fax = ereg_replace("'", "\'",$fax);
$pobox = ereg_replace("'", "\'",$pobox);
$bussiness_type = ereg_replace("'", "\'",$bussiness_type);
$client_companyowner = ereg_replace("'", "\'",$client_companyowner);
$client_referedby = ereg_replace("'", "\'",$client_referedby);
$client_deliveryassistant = ereg_replace("'", "\'",$client_deliveryassistant);
$client_dlvworktitle = ereg_replace("'", "\'",$client_dlvworktitle);
$delivery_phone = ereg_replace("'", "\'",$delivery_phone);
$delivery_fax = ereg_replace("'", "\'",$delivery_fax);
$client_deliveryaddress = ereg_replace("'", "\'",$client_deliveryaddress);
$client_deliveryaddress2 = ereg_replace("'", "\'",$client_deliveryaddress2);
$client_archivefileno = ereg_replace("'", "\'",$client_archivefileno);
$client_evaluationpoints = ereg_replace("'", "\'",$client_evaluationpoints);
$client_weakness = ereg_replace("'", "\'",$client_weakness);
$client_tips = ereg_replace("'", "\'",$client_tips);
$client_businesssector = ereg_replace("'", "\'",$client_businesssector);
$client_tobcode= ereg_replace("'", "\'",$client_tobcode);
$client_btype2= ereg_replace("'", "\'",$client_btype2);
$client_btype3= ereg_replace("'", "\'",$client_btype3);
$Client_BusinessType= ereg_replace("'", "\'",$Client_BusinessType);
		 
$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'])
		or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


$update_client="Update clients set 

Client_CreationDate='$creation_date',
Client_deactivate='".$deactivateclient."',
Client_deactivatedate=$deactivatedate,
Client_TC='".$client_tc."',
ClientGrp_Code=$client_groupcode,

Ledger_name='".$ledger_name."',
Ledger_Desc='".$ledger_description."',
Salesmen_Code='".$salesman_code."',
Client_FrequencyOfVisit='".$client_frequencyofvisit."',
Salesmen_Commission='".$salesman_com."',
Client_Rating='".$client_rating."',
Client_VAT='".$client_vat."',
Client_VatNo='".$client_vatno."',
Client_VatDate=$vat_date,
Client_SellingPrice='".$client_sellingprice."',
Client_DiscountPer='".$discount."',
Client_CreditControl='".$credit_control."',
Client_budgetlimit='".$budget_limit."',
Currency_Code='".$currency_code."',
Client_CreditLimit='".$credit_limit."',
Client_Group='".$client_group."',
Project_Code=$project_code,
Client_PayTermType=$client_paytermtype,
Client_PaymentTerms='".$client_paymentterm."',
Client_paymentTerms2='".$client_paymentterm2."',
Client_PaymentMode='".$client_paymentmode."',
CostCenter_code=$costcenter_code,
Client_checkAccount='".$client_checkaccount."',
Client_ChkTerms='".$client_chterms."',
Client_CashMode='".$client_cashmode."',
Client_sentEmail='".$sent_email."',
Client_tax='".$client_tax0."',
Client_Tax1='".$client_tax1."',
Client_Tax2='".$client_tax2."',
Client_Tax3='".$client_tax3."',
Client_Tax4='".$client_tax4."',
Client_Tax5='".$client_tax5."',
client_export='".$client_export."',
client_local='".$client_local."',
Client_CompLegalType='".$client_legaltype."',
Client_Country='".$country."',
Client_State='".$state."',
Client_City='".$city_client."',
Area_Code='".$area_code."',
Client_Address='".$Address."',
Client_Address2='".$Address2."',
Client_Email='".$email."',
Client_Homepage='".$homepage."',
Client_Telephone1='".$phone1."',
Client_Telephone2='".$phone2."',
Client_Fax='".$fax."',
Client_Pobox='".$pobox."',
Client_AgentAccount='".$agent_code."',
Client_MotherCompany='".$client_mothercompany."',
Client_Work='".$bussiness_type."',
Client_CompOwnerTitle='".$title_owner."',
Client_CompOwner='".$client_companyowner."',
Client_ReferedByTitle='".$title_refered."',
Client_ReferedBy='".$client_referedby."',
Client_SDINo='".$client_sdino."',
Client_DlvAssistantTitle='".$title_assistant."',
Client_DeliveryAssistant='".$client_deliveryassistant."',
Client_DlvWorkTitle='".$client_dlvworktitle."',
Client_DeliveryPhone='".$delivery_phone."',
Client_DlvFax='".$delivery_fax."',
Client_DlvAreaCode='".$delivery_areacode."',
Client_DeliveryAddress='".$client_deliveryaddress."',
Client_DeliveryAddress2='".$client_deliveryaddress2."',
warehouse_code='".$warehouse."',
Client_GCIno='".$client_gcino."',
Client_ArchiveFileNo='".$client_archivefileno."',
Client_EvaluationPoints='".$client_evaluationpoints."',
client_Weakness='".$client_weakness."',
Client_Tips='".$client_tips."',
Client_InvRounded='".$client_invrounded."',
Client_InvLanguage='".$invoice_language."',
Client_BusinessSector='".$client_businesssector."',
Client_BusinessSectorDesc='".$client_businesssectordesc."',
Client_TOBcode='".$client_tobcode."',
Client_MultipleSales='".$client_multiplesales."',
Client_BType2='".$client_btype2."',
Client_BType3='".$client_btype3."',
Client_BusinessType='".$Client_BusinessType."'


where ledger_number='$ledger_number'";

//echo$update_client;
$resultupdate=mysql_query($update_client,$connection);
$message    = mysql_error();


if($str=='1'){
$queryactivation="insert into clientactivationhistoric

(Ledger_Number,
ClientAct_StartDate,
ClientAct_EndDate,
ClientAct_Remark)

values ('".$ledger_number."',
		'$clientact_startdate',
		'$clientact_enddate',
		'".$clientact_remark."')";
		
		//echo$queryactivation."<BR>";		
		
		$resultcompetitor=mysql_query($queryactivation,$connection);
		$message    = mysql_error();
}

else  {

$update_activation="Update clientactivationhistoric set
Ledger_Number='".$ledger_number."',
ClientAct_StartDate='$clientact_startdate',
ClientAct_EndDate='$clientact_enddate',
ClientAct_Remark='".$clientact_remark."'

									where clientact_id='$clientact_id'";

$resultactivationupdate=mysql_query($update_activation,$connection);
$message    = mysql_error();

}

//// Delete Activation Historic 
if($actionmode=='delete') {

$delete = "delete from clientactivationhistoric where clientact_id =".$clientact_id;
$result=mysql_query($delete);
$errornum= mysql_errno();

if($errornum=='1451') {
	$message="Delete Not Allowed . Code is used .";
				//echo $message;
							}
							}
							

if($actionmode=='delete')
header ("Location: ./Form_Clients.php?ledger_number=$ledger_number&actionmode=editmode&keepactivation=1&message=".$message);

else
header ("Location: ./Form_Clients.php?keepactivation=1&ledger_number=$ledger_number&actionmode=editmode&message=".$message);


?>