compile subroutine WIN_PROD_SPEC_NUM_VALID(ConvType, DataIo, Branch, ReturnedValue)
begin condition
pre:
post:
end condition

$insert logical
$insert prod_spec_equ
$insert msg_equates

declare function msg, get_property, set_property
declare subroutine btree.extract

equ valid$         to 0    ;* successful
equ invalid_msg$   to 1    ;* bad data       -   print error message window
equ invalid_conv$  to 2    ;* bad conversion -          "         "
equ invalid_nomsg$ to 3    ;* bad but do not print the error message window
equ CrLf$          to char(13):char(10)

* this validates the quote number in windows like order and annual contracts
ReturnedValue = DataIo       
status() = Valid$              
*
begin case
   case ConvType = 'ICONV'
      CustNo = get_property( @window:'.CUST_NO', 'TEXT' )
      PSRec = xlate( 'PROD_SPEC', DataIo, '', 'X' )
      if ( PSRec<prod_spec_cust_id$> = CustNo ) else
          MsgInfo = ''
          MsgInfo<mtext$> = DataIo:' is not a valid product specification for ':oconv( CustNo, '[XLATE_CONV,COMPANY*CO_NAME]' ):'...':CrLf$:'Press [SF2] to view product specifications for this customer.' 
          MsgInfo<micon$> = 'H'
          Void = msg( '', MsgInfo )
          status() = invalid_nomsg$
      end
      * commented below cause lourdes said she need more than one active quote using the
      * same PSN
      *if status() = invalid_nomsg$ then
      *    * no need to check further they have already failed
      *end else
	  *    if @window = 'QUOTE' then
	  *        open 'DICT.QUOTE' to DictQuoteTable else
	  *           Void = msg( '', 'Unable to open DICT.QUOTE...' )
	  *           return 0
	  *        end
	  *        SearchStr = '' 
	  *        SearchStr<-1> = 'PROD_SPEC_ID':@vm:DataIo
	  *        SearchStr<-1> = 'STATUS':@vm:'#C'
	  *        * any quote that is using this psn and is not closed
	  *        btree.extract( SearchStr, 'QUOTE', DictQuoteTable, Keys, '', Flag )
	  *        if Flag <> 0 then
	  *           Void = msg( '', 'Error while extracting QUOTE records...' )
	  *           return 0
	  *        end
	  *        if Keys then
	  *           convert @vm to ',' in Keys
	  *           * should not happen cause there is only supposed to be one non closed quote at a time
	  *           * using the same PSN
	  *           MsgInfo = ''
	  *           MsgInfo<mtext$> = DataIo:' is used in quote ':Keys:'...You must close this quote. There can only be one quote using a given PSN at a time.'
	  *           MsgInfo<micon$> = 'H'
	  *           Void = msg( '', MsgInfo )
	  *           status() = invalid_nomsg$             
	  *        end
	  *    end
      *end
   case ConvType = 'OCONV'
      * no output
      ReturnedValue = DataIo
   case otherwise$
      ReturnedValue = ''
      status() = invalid_conv$
end case
return

