COMPILE FUNCTION obj_Company(Method,Parms)
/*
	Methods for the Company table
    
	12/04/2004 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    FaxNo(CompanyNo,ContactNo)			;* Returns FAX number for Contact in Company
	IFaxNo(CompanyNo,ContactNo)			;* Returns Internation FAX number for Contact in Company
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, Dialog_Box
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn

$INSERT MSG_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT COMPANY_EQU
$INSERT NAMES_EQU

ErrTitle = 'Error in Stored Procedure "obj_Company"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'FaxNo'		; GOSUB FaxNo
	CASE Method = 'IFaxNo'		; GOSUB IFaxNo
	CASE Method = 'BTAddr'		; GOSUB BTAddr
	CASE Method = 'BTCsz'		; GOSUB BTCsz
	CASE Method = 'STAddr'		; GOSUB STAddr
	CASE Method = 'STCsz'		; GOSUB STCsz
	CASE 1
		ErrorMsg = 'Unknown Method ':QUOTE(Method):' passed to routine.'

END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

RETURN Result


* * * * * * *
FaxNo:
* * * * * * *

CompNo	= Parms[1,@RM]
NameNo	= Parms[COL2()+1,@RM]

IF NOT(ASSIGNED(CompNo)) THEN ErrorMsg = 'Unassigned parameter "CompNo" passed to routine. (':Method:')'
IF NOT(ASSIGNED(NameNo)) THEN ErrorMsg = 'Unassigned parameter "NameNo" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

IF CompNo = '' THEN ErrorMsg = 'Null parameter "CompNo" passed to routine. (':Method:')'
IF NameNo = '' THEN ErrorMsg = 'Null parameter "NameNo" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN


CompanyRec = XLATE('COMPANY',CompNo,'','X')
IF CompanyRec = '' THEN RETURN

NameRec = XLATE('NAMES',NameNo,'','X')


* Get Company FAX number

CompPhones		= CompanyRec<COMPANY_PHONES$>
CompPhoneTypes	= CompanyRec<COMPANY_PHONE_TYPES$>

ExpInfo = ''
FOR I = 1 TO COUNT(CompPhones,@VM) + (CompPhones NE '')
	ThisPhoneType = CompPhoneTypes<1,I>
	ThisPhoneNum  = CompPhones<1,I>
	CONVERT @LOWER_CASE TO @UPPER_CASE IN ThisPhoneType
	IF ThisPhoneType = 'FAX' THEN
		ExpInfo := OCONV( CompNo, '[XLATE_CONV,COMPANY*CO_NAME]' ):@SVM:ThisPhoneNum:@VM
	END
NEXT I

* Get all FAX numbers for this contact name

NamePhones		= NameRec<NAMES_PHONE$>
NamePhoneTypes	= NameRec<NAMES_PHONE_TYPES$>

FOR I = 1 TO COUNT(NamePhones,@VM) + (NamePhones NE '')
	ThisPhoneType = NamePhoneTypes<1,I>
	ThisPhoneNum  = NamePhones<1,I>
	CONVERT @LOWER_CASE TO @UPPER_CASE IN ThisPhoneType
	IF ThisPhoneType = 'FAX' THEN
		ExpInfo := OCONV( NameNo, '[XLATE_CONV,NAMES*FIRST_LAST]' ):@SVM:THISPHONENUM:@VM
	END
NEXT I

IF ExpInfo THEN
	ExpInfo[-1,1] = ''
	OverRide = ''
	OverRide<PDISPLAY$> = ExpInfo
	Result = Popup(@WINDOW,OverRide,'FAX_NUMBERS')
END

RETURN


* * * * * * *
IFaxNo:
* * * * * * *

CompNo	= Parms[1,@RM]
NameNo	= Parms[COL2()+1,@RM]

IF NOT(ASSIGNED(CompNo)) THEN ErrorMsg = 'Unassigned parameter "CompNo" passed to routine. (':Method:')'
IF NOT(ASSIGNED(NameNo)) THEN ErrorMsg = 'Unassigned parameter "NameNo" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

IF CompNo = '' THEN ErrorMsg = 'Null parameter "CompNo" passed to routine. (':Method:')'
IF NameNo = '' THEN ErrorMsg = 'Null parameter "NameNo" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN


CompanyRec = XLATE('COMPANY',CompNo,'','X')
IF CompanyRec = '' THEN RETURN

NameRec = XLATE('NAMES',NameNo,'','X')


* Get Company FAX number

CompPhones		= CompanyRec<COMPANY_INTL_PHONES$>
CompPhoneTypes	= CompanyRec<COMPANY_INTL_PHONE_TYPES$>

ExpInfo = ''
FOR I = 1 TO COUNT(CompPhones,@VM) + (CompPhones NE '')
	ThisPhoneType = CompPhoneTypes<1,I>
	ThisPhoneNum  = CompPhones<1,I>
	CONVERT @LOWER_CASE TO @UPPER_CASE IN ThisPhoneType
	IF ThisPhoneType = 'FAX' THEN
		ExpInfo := OCONV( CompNo, '[XLATE_CONV,COMPANY*CO_NAME]' ):@SVM:ThisPhoneNum:@VM
	END
NEXT I

* Get all FAX numbers for this contact name

NamePhones		= NameRec<NAMES_INTL_PHONE$>
NamePhoneTypes	= NameRec<NAMES_INTL_PHONE_TYPES$>

FOR I = 1 TO COUNT(NamePhones,@VM) + (NamePhones NE '')
	ThisPhoneType = NamePhoneTypes<1,I>
	ThisPhoneNum  = NamePhones<1,I>
	CONVERT @LOWER_CASE TO @UPPER_CASE IN ThisPhoneType
	IF ThisPhoneType = 'FAX' THEN
		ExpInfo := OCONV( NameNo, '[XLATE_CONV,NAMES*FIRST_LAST]' ):@SVM:THISPHONENUM:@VM
	END
NEXT I

IF ExpInfo THEN
	ExpInfo[-1,1] = ''
	OverRide = ''
	OverRide<PDISPLAY$> = ExpInfo
	Result = Popup(@WINDOW,OverRide,'INTL_FAX_NUMBERS')
END

RETURN


* * * * * * *
BTAddr:
* * * * * * *

CompNo	= Parms[1,@RM]
CompRec	= Parms[COL2()+1,@RM]

IF CompNo = '' THEN RETURN

IF CompRec = '' THEN
	CompRec = XLATE('COMPANY',CompNo,'','X')
	IF CompRec = '' THEN RETURN
END

BillToNo	= CompRec<COMPANY_BILL_TO_CUST_NO$>
Address		= XLATE('COMPANY',BillToNo,COMPANY_BILL_TO_ADDRESS$,'X')

IF Address = '' THEN RETURN
SWAP @VM WITH ', ' IN Address
Result = Address

RETURN


* * * * * * *
BTCsz:
* * * * * * *

CompNo	= Parms[1,@RM]
CompRec	= Parms[COL2()+1,@RM]

IF CompNo = '' THEN RETURN

IF CompRec = '' THEN
	CompRec = XLATE('COMPANY',CompNo,'','X')
	IF CompRec = '' THEN RETURN
END

BillToNo	= CompRec<COMPANY_BILL_TO_CUST_NO$>
BillToRec	= XLATE('COMPANY',BillToNo,'','X')

IF BillToRec = '' THEN RETURN

City	= BillToRec<COMPANY_BILL_TO_CITY$>
ST		= BillToRec<COMPANY_BILL_TO_STATE$>
ZIP		= BillToRec<COMPANY_BILL_TO_ZIP$>

IF St = '' AND ZIP = '' THEN
	Address = BillToRec<20>
	SWAP @VM WITH ', ' IN Address
	Result = Address
END ELSE
 Result = City:', ':ST:' ':OCONV(ZIP,'[ZIP_FORMAT]')
END

RETURN


* * * * * * *
STAddr:
* * * * * * *

CompNo	= Parms[1,@RM]
CompRec	= Parms[COL2()+1,@RM]

IF CompNo = '' THEN RETURN

IF CompRec = '' THEN
	CompRec = XLATE('COMPANY',CompNo,'','X')
	IF CompRec = '' THEN RETURN
END

ShipToNos	= CompRec<COMPANY_SHIP_TO_CUST_NO$>

FOR I = 1 TO COUNT(ShipToNos,@VM) + (ShipToNos NE '')
	ShipToNo		= ShipToNos<1,I>
	ShipToAddress	= XLATE('COMPANY',ShipToNo,COMPANY_BILL_TO_ADDRESS$,'X')

	IF ShipToAddress = '' THEN RETURN

	SWAP @VM WITH ', ' IN ShipToAddress
	Result<1,I> = ShipToAddress
NEXT I


RETURN



* * * * * * *
STCsz:
* * * * * * *

CompNo	= Parms[1,@RM]
CompRec	= Parms[COL2()+1,@RM]

IF CompNo = '' THEN RETURN

IF CompRec = '' THEN
	CompRec = XLATE('COMPANY',CompNo,'','X')
	IF CompRec = '' THEN RETURN
END

ShipToNos	= CompRec<COMPANY_SHIP_TO_CUST_NO$>

FOR I = 1 TO COUNT(ShipToNos,@VM) + (ShipToNos NE '')
	ShipToNo	= ShipToNos<1,I>
	ShipToRec	= XLATE('COMPANY',ShipToNo,'','X')

	IF ShipToRec NE '' THEN

		City	= ShipToRec<COMPANY_BILL_TO_CITY$>
		ST		= ShipToRec<COMPANY_BILL_TO_STATE$>
		ZIP		= ShipToRec<COMPANY_BILL_TO_ZIP$>

		IF ST = '' AND ZIP = '' THEN
			Address = ShipToRec<20>
			SWAP @VM WITH ', ' IN Address
			Result<1,I> = Address
		END ELSE
			Result<1,I> = City:', ':ST:' ':OCONV(ZIP,'[ZIP_FORMAT]')
		END
	END ELSE
		Result<1,I> = ''
	END
NEXT I


RETURN



