<?php
/*
   QUICKBOOK CLASS
   Author  :  A.R. ZERIN
   version :  1.0
   Company :  Premium Web Cart


   QuickBook  Class easily exports data to iif files so that you can use your PWC data in your QuickBook

 */

class Quickbook{

	var $data;               # 
	var $invoiceheader = array();
	var $SPLheader = array();
	var $custheader = array();
	var $custdictheader = array();
	var $custdictheaderdata = array();
	var $custdata = array();
	var $itemheader = array();
	var $itemdata = array();
	var $trnsdata = array();
	var $spldata = array();
	
	var $accheader = array();
	var $accdata = array();
	var $jobtypeheader = array();
	var $vtypeheader = array();
	var $vtypedata = array();
	var $vendheader = array();
	var $venddata = array();
	
	function Quickbook(){
		//$this->InitCustomerHeader();
		//$this->InitItemListHeader();
		//$this->InitSPLheader();
		//$this->InitTRNSheader();
		//$this->InitDictheader();
		$this->InitAccHeader();
		$this->InitItemListHeader();
		$this->InitJobTypeHeader();
		$this->InitCustomerHeader();
		$this->InitVendorTypeHeader();
		$this->InitVendorHeader();
		$this->InitTRNSheader();
		$this->InitSPLheader();
	}
	
	function WriteInvoiceHeader(){
		$str = '';
		for ($i=0;$i<count($this->invoiceheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->invoiceheader[$i];
			}
			else{
				$str .= ''.$this->invoiceheader[$i];
			}
			if ($i!=(count($this->invoiceheader)-1))
			$str .=  CHR(9);
		}
		return $str;
	}
	function WriteSPLHeader(){
		$str = '';
		for ($i=0;$i<count($this->SPLheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->SPLheader[$i];
			}
			else{
				$str .=  ''.$this->SPLheader[$i];
			}
			if ($i!=(count($this->SPLheader)-1))
			$str .=   CHR(9);
		}
		return $str;
	}	
	function WriteCustomerHeader(){
		$str = '';
		for ($i=0;$i<count($this->custheader);$i++){
			if ($i==0)
			{
				$str .= CHR(13).CHR(10).'!'.$this->custheader[$i];
			}
			else{
				$str .= ''.$this->custheader[$i];
			}
			if ($i!=(count($this->custheader)-1))
			$str .= CHR(9);
		}
		return $str;
		
	}		
	function WriteCustomerDictHeader(){
		$str = '';
		
		for ($i=0;$i<count($this->custdictheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->custdictheader[$i];
			}
			elseif ($i==(count($this->custdictheader)-1)){
				//echo $this->custdictheader[$i].CHR(13).CHR(10);
				$str .=  $this->custdictheader[$i];
			}			
			else{
				$str .=  ''.$this->custdictheader[$i];
			}
			if ($i!=(count($this->custdictheader)-1))
			$str .=  CHR(9);
		}
		$str .=  CHR(13).CHR(10).'!ENDCUSTITEMDICT';
		return $str;
	}	
	function WriteCustomerDictHeaderData(){
		echo '<br/>Customer Dictionary Data:<br/>';
		
		for ($i=0;$i<count($this->custdictheader);$i++){
			if ($i==0)
			{
				echo CHR(13).CHR(10).'!'.$this->custdictheader[$i];
			}
			elseif ($i==(count($this->custdictheader)-1)){
				//echo $this->custdictheader[$i].CHR(13).CHR(10);
				echo $this->custdictheader[$i];
			}			
			else{
				echo ''.$this->custdictheader[$i];
			}
			if ($i!=(count($this->custdictheader)-1))
			echo CHR(9);
		}
	}	
	function WriteCustomerDictHeaderEnd(){
		echo CHR(13).CHR(10).'!ENDCUSTITEMDICT';
	}	
	function EndHeader(){
		echo '!ENDTRNS';
		for ($i=0;$i<17;$i++)
		echo CHR(9);
		
	}	
	function SetTransactionHeader($name){
		$this->invoiceheader[]=$name;
	}	
	function SetSPLHeader($name){
		$this->SPLheader[]=$name;
	}
	function SetCustomerHeader($name){
		$this->custheader[]=$name;
	}	
	function SetCustomerDictHeader($name){
		$this->custdictheader[]=$name;
	}	
	function SetCustomerDictHeaderData($INDEX,$LABEL,$INUSE){
		$this->custdictheaderdata[]=array('INDEX' => $INDEX,'LABEL' => $LABEL,'INUSE' => $INUSE );
	}	
	function InitCustomerData(){
		$this->custdata = array();
		
		foreach($this->custheader as $head)
		$this->custdata[$head]='';
	}
	function InitItemData(){
		$this->itemdata = array();
		
		foreach($this->itemheader as $head)
		$this->itemdata[$head]='';
	}	
	function InitCustomerAccount(){
		$this->custaccount = array();
		
		foreach($this->custheader as $head)
		$this->custdata[$head]='';
	}	
	function InitCustomerHeader(){
			$this->SetCustomerHeader("CUST");			
			$this->SetCustomerHeader("NAME");			
			$this->SetCustomerHeader("REFNUM");			
			$this->SetCustomerHeader("TIMESTAMP");			
			$this->SetCustomerHeader("BADDR1");			
			$this->SetCustomerHeader("BADDR2");			
			$this->SetCustomerHeader("BADDR3");			
			$this->SetCustomerHeader("BADDR4");			
			$this->SetCustomerHeader("BADDR5");			
			$this->SetCustomerHeader("SADDR1");			
			$this->SetCustomerHeader("SADDR2");			
			$this->SetCustomerHeader("SADDR3");			
			$this->SetCustomerHeader("SADDR4");			
			$this->SetCustomerHeader("SADDR5");			
			$this->SetCustomerHeader("PHONE1");			
			$this->SetCustomerHeader("PHONE2");			
			$this->SetCustomerHeader("FAXNUM");			
			$this->SetCustomerHeader("EMAIL");			
			$this->SetCustomerHeader("NOTE");			
			$this->SetCustomerHeader("CONT1");			
			$this->SetCustomerHeader("CONT2");			
			$this->SetCustomerHeader("CTYPE");			
			$this->SetCustomerHeader("TERMS");			
			$this->SetCustomerHeader("TAXABLE");			
			$this->SetCustomerHeader("SALESTAXCODE");			
			$this->SetCustomerHeader("LIMIT");			
			$this->SetCustomerHeader("RESALENUM");			
			$this->SetCustomerHeader("REP");			
			$this->SetCustomerHeader("TAXITEM");			
			$this->SetCustomerHeader("NOTEPAD");			
			$this->SetCustomerHeader("SALUTATION");			
			$this->SetCustomerHeader("COMPANYNAME");			
			$this->SetCustomerHeader("FIRSTNAME");			
			$this->SetCustomerHeader("MIDINIT");			
			$this->SetCustomerHeader("LASTNAME");			
			$this->SetCustomerHeader("CUSTFLD1");		
			$this->SetCustomerHeader("CUSTFLD2");			
			$this->SetCustomerHeader("CUSTFLD3");			
			$this->SetCustomerHeader("CUSTFLD4");			
			$this->SetCustomerHeader("CUSTFLD5");			
			$this->SetCustomerHeader("CUSTFLD6");			
			$this->SetCustomerHeader("CUSTFLD7");			
			$this->SetCustomerHeader("CUSTFLD8");			
			$this->SetCustomerHeader("CUSTFLD9");			
			$this->SetCustomerHeader("CUSTFLD10");			
			$this->SetCustomerHeader("CUSTFLD11");			
			$this->SetCustomerHeader("CUSTFLD12");			
			$this->SetCustomerHeader("CUSTFLD13");			
			$this->SetCustomerHeader("CUSTFLD14");			
			$this->SetCustomerHeader("CUSTFLD15");			
			$this->SetCustomerHeader("JOBDESC");			
			$this->SetCustomerHeader("JOBTYPE");			
			$this->SetCustomerHeader("JOBSTATUS");			
			$this->SetCustomerHeader("JOBSTART");			
			$this->SetCustomerHeader("JOBPROJEND");			
			$this->SetCustomerHeader("JOBEND");			
			$this->SetCustomerHeader("HIDDEN");			
			$this->SetCustomerHeader("DELCOUNT");			
			$this->SetCustomerHeader("PRICELEVEL");		
	}
	function InitItemListHeader(){
		$this->itemheader[]='INVITEM';
		$this->itemheader[]='NAME';
		$this->itemheader[]='REFNUM';
		$this->itemheader[]='TIMESTAMP';
		$this->itemheader[]='INVITEMTYPE';
		$this->itemheader[]='DESC';
		$this->itemheader[]='PURCHASEDESC';
		$this->itemheader[]='ACCNT';
		$this->itemheader[]='ASSETACCNT';
		$this->itemheader[]='COGSACCNT';
		$this->itemheader[]='QNTY';
		$this->itemheader[]='PRICE';
		$this->itemheader[]='COST';
		$this->itemheader[]='TAXABLE';
		$this->itemheader[]='SALESTAXCODE';
		$this->itemheader[]='PAYMETH';
		$this->itemheader[]='TAXVEND';
		$this->itemheader[]='TAXDIST';//Ommited
		$this->itemheader[]='TOPRINT';//Ommited
		$this->itemheader[]='PREFVEND';
		$this->itemheader[]='REORDERPOINT';
		$this->itemheader[]='EXTRA';
		$this->itemheader[]='CUSTFLD1';
		$this->itemheader[]='CUSTFLD2';
		$this->itemheader[]='CUSTFLD3';
		$this->itemheader[]='CUSTFLD4';
		$this->itemheader[]='CUSTFLD5';
		$this->itemheader[]='DEP_TYPE';
		$this->itemheader[]='ISPASSEDTHRU';
		$this->itemheader[]='HIDDEN';
		$this->itemheader[]='DELCOUNT';
		$this->itemheader[]='USEID';
		$this->itemheader[]='ISNEW';
		$this->itemheader[]='PO_NUM';
		$this->itemheader[]='SERIALNUM';
		$this->itemheader[]='WARRANTY';
		$this->itemheader[]='LOCATION';
		$this->itemheader[]='VENDOR';
		$this->itemheader[]='ASSETDESC';
		$this->itemheader[]='SALEDATE';
		$this->itemheader[]='SALEEXPENSE';
		$this->itemheader[]='NOTES';
		$this->itemheader[]='ASSETNUM';
		$this->itemheader[]='COSTBASIS';
		$this->itemheader[]='ACCUMDEPR';
		$this->itemheader[]='UNRECBASIS';
		$this->itemheader[]='PURCHASEDATE';
	}			
	function SetItemListHeader($name){
		$this->itemheader[]=$name;
	}
	function SetItemListData($name,$value){
		$this->itemdata[$name]=$value;
	}	
	function SetCustomerData($name,$value){
		$this->custdata[$name]=$value;
	}
	function SetTRNSData($name,$value){
		$this->trnsdata[$name]=$value;
	}			
	function WriteCustomerDictData(){
		$str = '';
		foreach($this->custdictheaderdata as $headarray)
		{
			$j=0;
			$str .= CHR(13).CHR(10).'CUSTITEMDICT'.CHR(9);
			foreach($headarray as $key=>$val)
			{
				if($j==0)
					$str .= $val.CHR(9);
				elseif ($j<(count($headarray)-1))
					$str .= $val.CHR(9);
				else
					$str .= $val;				
					
				$j++;	
			}
		}
		return $str;
	}	
	function WriteCustomerItemDictEnd(){
		$str = '';
		$str .=  CHR(13).CHR(10).'ENDCUSTITEMDICT';
		return $str;
	}	
	function WriteCustomerData(){
		$str = '';
		$str .= CHR(13).CHR(10).'CUST';
		$j=0;
		foreach($this->custdata as $key=>$val)
		{
			//$str .= $key.'-'.$val.CHR(9);
			if($j!=0)
				$str .= $val.CHR(9);
			else	
				$str .= CHR(9);

			$j++;
		}
		return $str;
	}						
	function WriteItemListHeader(){
		$str = '';
		for ($i=0;$i<count($this->itemheader);$i++){
			if ($i==0)
			{
				$str .= CHR(13).CHR(10).'!'.$this->itemheader[$i];
			}
			else{
				$str .= ''.$this->itemheader[$i];
			}
			if ($i!=(count($this->itemheader)-1))
			$str .= CHR(9);
		}
		return $str;
		
	}	
	function WriteItemData(){
		$str = '';
		$str .= CHR(13).CHR(10).'INVITEM';
		$j=0;
		foreach($this->itemdata as $key=>$val)
		{
			//$str .= $key.'-'.$val.CHR(9);
			if($j!=0)
			{
				$str .= $val.CHR(9);
			}
			else	
				$str .= CHR(9);

			$j++;
		}
		return $str;
	}	
	function InitTRNSheader(){
		$this->SetTransactionHeader("TRNS");
		$this->SetTransactionHeader("TRNSID");
		$this->SetTransactionHeader("TRNSTYPE");
		$this->SetTransactionHeader("DATE");
		$this->SetTransactionHeader("ACCNT");
		$this->SetTransactionHeader("NAME");
		$this->SetTransactionHeader("CLASS");
		$this->SetTransactionHeader("AMOUNT");
		$this->SetTransactionHeader("DOCNUM");
		$this->SetTransactionHeader("MEMO");
		$this->SetTransactionHeader("CLEAR");
		$this->SetTransactionHeader("TOPRINT");
		$this->SetTransactionHeader("NAMEISTAXABLE");
		$this->SetTransactionHeader("ADDR1");
		$this->SetTransactionHeader("ADDR2");
		$this->SetTransactionHeader("ADDR3");
		$this->SetTransactionHeader("ADDR4");
		$this->SetTransactionHeader("ADDR5");
		$this->SetTransactionHeader("DUEDATE");
		$this->SetTransactionHeader("TERMS");
		$this->SetTransactionHeader("PAID");
		$this->SetTransactionHeader("PAYMETH");
		$this->SetTransactionHeader("SHIPDATE");
		$this->SetTransactionHeader("OTHER1");
		$this->SetTransactionHeader("REP");
		$this->SetTransactionHeader("FOB");
		$this->SetTransactionHeader("PONUM");
		$this->SetTransactionHeader("INVTITLE");
		$this->SetTransactionHeader("INVMEMO");
		$this->SetTransactionHeader("SADDR1");
		$this->SetTransactionHeader("SADDR2");
		$this->SetTransactionHeader("SADDR3");
		$this->SetTransactionHeader("SADDR4");
		$this->SetTransactionHeader("SADDR5");
		$this->SetTransactionHeader("PAYITEM");
		$this->SetTransactionHeader("YEARTODATE");
		$this->SetTransactionHeader("WAGEBASE");
		$this->SetTransactionHeader("EXTRA");
		$this->SetTransactionHeader("TOSEND");
		$this->SetTransactionHeader("ISAJE");
	}
	function InitTRNSData(){
		$this->trnsdata = array();
		
		foreach($this->invoiceheader as $head)
		$this->trnsdata[$head]='';
	}
	function InitSPLheader(){
			$this->SetSPLHeader("SPL");
			$this->SetSPLHeader("SPLID");			
			$this->SetSPLHeader("TRNSTYPE");			
			$this->SetSPLHeader("DATE");			
			$this->SetSPLHeader("ACCNT");			
			$this->SetSPLHeader("NAME");			
			$this->SetSPLHeader("CLASS");			
			$this->SetSPLHeader("AMOUNT");			
			$this->SetSPLHeader("DOCNUM");			
			$this->SetSPLHeader("MEMO");			
			$this->SetSPLHeader("CLEAR");			
			$this->SetSPLHeader("QNTY");	
			$this->SetSPLHeader("PRICE");		
			$this->SetSPLHeader("INVITEM");			
			$this->SetSPLHeader("PAYMETH");			
			$this->SetSPLHeader("TAXABLE");			
			$this->SetSPLHeader("VALADJ");			
			$this->SetSPLHeader("REIMBEXP");			
			$this->SetSPLHeader("SERVICEDATE");			
			$this->SetSPLHeader("OTHER2");	
			$this->SetSPLHeader("OTHER3");	
			$this->SetSPLHeader("PAYITEM");	
			$this->SetSPLHeader("YEARTODATE");	
			$this->SetSPLHeader("WAGEBASE");	
			$this->SetSPLHeader("EXTRA");	
	}
	function InitSPLData(){
		$this->spldata = array();
		
		foreach($this->SPLheader as $head)
		$this->spldata[$head]='';
	}		
	function InitDictheader(){
			$this->SetCustomerDictHeader("CUSTITEMDICT");	
			$this->SetCustomerDictHeader("INDEX");	
			$this->SetCustomerDictHeader("LABEL");	
			$this->SetCustomerDictHeader("INUSE");		
	}
	function GetTransactionHeaderEnd(){
		$str = '';
		$str .= CHR(13).CHR(10).'!ENDTRNS';
		return $str;
	}
	function GetTransactionEnd(){
		$str = '';
		$str .= CHR(13).CHR(10).'ENDTRNS';
		return $str;
	}		
	function WriteTransactionHeader(){
		$str = '';
		$str.=$this->WriteInvoiceHeader();
		$str.=$this->WriteSPLHeader();
		$str.=$this->GetTransactionHeaderEnd();
		return $str;
	}
	function WriteTRNSData(){
		$str = '';
		$str .= CHR(13).CHR(10).'TRNS';
		$j=0;
		foreach($this->trnsdata as $key=>$val)
		{
			if($j!=0)
			{
				if (!empty($val))
				$str .= $val.CHR(9);
				else
				$str .= ''.CHR(9);				
			}
			else	
				$str .= CHR(9);

			$j++;
		}
		return $str;
	}	
	function SetSPLData($name,$value){
		$this->spldata[$name]=$value;
	}
	function WriteSPLData(){
		$str = '';
		$str .= CHR(13).CHR(10).'SPL';
		$j=0;
		foreach($this->spldata as $key=>$val)
		{
			if($j!=0)
			{
				if (!empty($val))
				$str .= $val.CHR(9);
				else
				$str .= ''.CHR(9);				
			}
			else	
				$str .= CHR(9);

			$j++;
		}
		return $str;
	}	
	function WriteFileEnd(){
		$str = '';
		$str .= CHR(13).CHR(10).CHR(13).CHR(10);
		return $str;
	}
	function WriteAccHeader(){
		$str = '';
		for ($i=0;$i<count($this->accheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->accheader[$i];
			}
			else{
				$str .= ''.$this->accheader[$i];
			}
			if ($i!=(count($this->accheader)-1))
			$str .=  CHR(9);
		}
		//$str .=  CHR(13).CHR(10);
		return $str;
	}
	function InitAccHeader(){
		$this->SetAccHeader("ACCNT");		
		$this->SetAccHeader("NAME");		
		$this->SetAccHeader("REFNUM");
		$this->SetAccHeader("TIMESTAMP");
		$this->SetAccHeader("ACCNTTYPE");
		$this->SetAccHeader("OBAMOUNT");
		$this->SetAccHeader("DESC");
		$this->SetAccHeader("ACCNUM");
		$this->SetAccHeader("SCD");
		$this->SetAccHeader("BANKNUM");
		$this->SetAccHeader("EXTRA");
		$this->SetAccHeader("HIDDEN");
		$this->SetAccHeader("DELCOUNT");
		$this->SetAccHeader("USEID");
		$this->SetAccHeader("WKPAPERREF");
		
		/*
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		$this->SetAccHeader("XXX");
		*/
			
	}				
	function SetAccHeader($name){
		$this->accheader[]=$name;
	}	
	function SetACCData($name,$value){
		$this->accdata[$name]=$value;
	}	
	function InitACCData(){
		$this->accdata = array();
		
		foreach($this->accheader as $head)
		$this->accdata[$head]='';
	}	
	function WriteACCData(){
		$str = '';
		$str .= CHR(13).CHR(10).'ACCNT';
		$j=0;
		foreach($this->accdata as $key=>$val)
		{
			if($j!=0)
			{
				if ($val!='')
				$str .= $val.CHR(9);
				else
				$str .= ''.CHR(9);				
			}
			else	
				$str .= CHR(9);

			$j++;
		}
		return $str;
	}
	function WriteCustNameDict($id){
		$str = '';
		$str .=  CHR(13).CHR(10).'CUSTNAMEDICT'.CHR(9).$id.CHR(9).'N'.CHR(9).'N'.CHR(9).'N'.CHR(9);
		return $str;
	}	
	function WriteCustNameDictEnd($id){
		$str = '';
		$str .=  CHR(13).CHR(10).'ENDCUSTNAMEDICT';
		return $str;
	}
	
	function InitJobTypeHeader(){
		$this->SetJobTypeHeader("JOBTYPE");
		$this->SetJobTypeHeader("NAME");
		$this->SetJobTypeHeader("REFNUM");
		$this->SetJobTypeHeader("TIMESTAMP");
		$this->SetJobTypeHeader("HIDDEN");
	}	
	function SetJobTypeHeader($name){
		$this->jobtypeheader[]=$name;
	}	
	function WriteJobTypeHeader(){
		$str = '';
		for ($i=0;$i<count($this->jobtypeheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->jobtypeheader[$i];
			}
			else{
				$str .= ''.$this->jobtypeheader[$i];
			}
			if ($i!=(count($this->jobtypeheader)-1))
			$str .=  CHR(9);
		}
		//$str .=  CHR(13).CHR(10);
		return $str;
	}
	function WriteCustHeader(){
		$str = '';
		for ($i=0;$i<count($this->custheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->custheader[$i];
			}
			else{
				$str .= ''.$this->custheader[$i];
			}
			if ($i!=(count($this->custheader)-1))
			$str .=  CHR(9);
		}
		//$str .=  CHR(13).CHR(10);
		return $str;
	}		
	function InitVendorTypeHeader(){
		$this->SetVendorTypeHeader("VTYPE");
		$this->SetVendorTypeHeader("NAME");
		$this->SetVendorTypeHeader("REFNUM");
		$this->SetVendorTypeHeader("TIMESTAMP");
		$this->SetVendorTypeHeader("HIDDEN");
	}		
	function SetVendorTypeHeader($name){
		$this->vtypeheader[]=$name;
	}
	function WriteVendorTypeHeader(){
		$str = '';
		for ($i=0;$i<count($this->vtypeheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->vtypeheader[$i];
			}
			else{
				$str .= ''.$this->vtypeheader[$i];
			}
			if ($i!=(count($this->vtypeheader)-1))
			$str .=  CHR(9);
		}
		//$str .=  CHR(13).CHR(10);
		return $str;
	}	
	function WriteTRNSHeader(){
		$str = '';
		for ($i=0;$i<count($this->invoiceheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->invoiceheader[$i];
			}
			else{
				$str .= ''.$this->invoiceheader[$i];
			}
			if ($i!=(count($this->invoiceheader)-1))
			$str .=  CHR(9);
		}
		//$str .=  CHR(13).CHR(10);
		return $str;
	}		
	function WriteCustNameDictXXXXXXX($id){
		$str = '';
		$str .=  CHR(13).CHR(10).'VTYPE'.CHR(9).$id.CHR(9).'N'.CHR(9).'N'.CHR(9).'N'.CHR(9);
		return $str;
	}
	function InitVTypeData(){
		$this->vtypedata = array();
		
		foreach($this->vtypeheader as $head)
		$this->vtypedata[$head]='';
	}
	function SetVTypeData($name,$value){
		$this->vtypedata[$name]=$value;
	}
	function WriteVTypeData(){
		$str = '';
		$str .= CHR(13).CHR(10).'VTYPE';
		$j=0;
		foreach($this->vtypedata as $key=>$val)
		{
			if($j!=0)
			{
				if ($val!='')
				$str .= $val.CHR(9);
				else
				$str .= ''.CHR(9);				
			}
			else	
				$str .= CHR(9);

			$j++;
		}
		return $str;
	}	
	function InitVendorHeader(){
		$this->SetVendorHeader("VEND");		
		$this->SetVendorHeader("NAME");		
		$this->SetVendorHeader("REFNUM");
		$this->SetVendorHeader("TIMESTAMP");
		$this->SetVendorHeader("PRINTAS");
		$this->SetVendorHeader("ADDR1");
		$this->SetVendorHeader("ADDR2");
		$this->SetVendorHeader("ADDR3");
		$this->SetVendorHeader("ADDR4");
		$this->SetVendorHeader("ADDR5");
		$this->SetVendorHeader("VTYPE");
		$this->SetVendorHeader("CONT1");
		$this->SetVendorHeader("CONT2");
		$this->SetVendorHeader("PHONE1");
		$this->SetVendorHeader("PHONE2");
		$this->SetVendorHeader("FAXNUM");
		$this->SetVendorHeader("EMAIL");
		$this->SetVendorHeader("NOTE");
		$this->SetVendorHeader("TAXID");
		$this->SetVendorHeader("LIMIT");
		$this->SetVendorHeader("TERMS");
		$this->SetVendorHeader("NOTEPAD");
		$this->SetVendorHeader("SALUTATION");
		$this->SetVendorHeader("COMPANYNAME");
		$this->SetVendorHeader("FIRSTNAME");
		$this->SetVendorHeader("MIDINIT");
		$this->SetVendorHeader("LASTNAME");
		$this->SetVendorHeader("CUSTFLD1");
		$this->SetVendorHeader("CUSTFLD2");
		$this->SetVendorHeader("CUSTFLD3");
		$this->SetVendorHeader("CUSTFLD4");
		$this->SetVendorHeader("CUSTFLD5");
		$this->SetVendorHeader("CUSTFLD6");
		$this->SetVendorHeader("CUSTFLD7");
		$this->SetVendorHeader("CUSTFLD8");
		$this->SetVendorHeader("CUSTFLD9");
		$this->SetVendorHeader("CUSTFLD10");
		$this->SetVendorHeader("CUSTFLD11");
		$this->SetVendorHeader("CUSTFLD12");
		$this->SetVendorHeader("CUSTFLD13");
		$this->SetVendorHeader("CUSTFLD14");
		$this->SetVendorHeader("CUSTFLD15");
		$this->SetVendorHeader("1099");		
		$this->SetVendorHeader("HIDDEN");		
		$this->SetVendorHeader("DELCOUNT");										
										
	}				
	function SetVendorHeader($name){
		$this->vendheader[]=$name;
	}	
	function WriteVendorDataHeader(){
		$str = '';
		for ($i=0;$i<count($this->vendheader);$i++){
			if ($i==0)
			{
				$str .=  CHR(13).CHR(10).'!'.$this->vendheader[$i];
			}
			else{
				$str .= ''.$this->vendheader[$i];
			}
			if ($i!=(count($this->vendheader)-1))
			$str .=  CHR(9);
		}
		//$str .=  CHR(13).CHR(10);
		return $str;
	}		
	function SetVendorData($name,$value){
		$this->venddata[$name]=$value;
	}	
	function InitVendorData(){
		$this->venddata = array();
		
		foreach($this->vendheader as $head)
		$this->venddata[$head]='';
	}	
	function WriteVendorData(){
		$str = '';
		$str .= CHR(13).CHR(10).'VEND';
		$j=0;
		foreach($this->venddata as $key=>$val)
		{
			if($j!=0)
			{
				if ($val!='')
				$str .= $val.CHR(9);
				else
				$str .= ''.CHR(9);				
			}
			else	
				$str .= CHR(9);

			$j++;
		}
		return $str;
	}	
			
}	 
?>