compile function order_comm(Branch)
begin condition
pre:
post:
end condition

$insert order_equ
$insert annual_contracts_equ
ReturnVar = 0
declare function set_property, fieldcount, get_property, msg, editcell
declare function send_event
Branches = 'PREV_LINE_DFLT,PO_DEFAULT'
convert ',' to @fm in Branches
locate Branch in Branches using @fm setting Bpos then
   on Bpos gosub PrevLineDflt, PODefault
end else
   Void = msg( '', 'Invalid Branch ':Bpos:' passed to order_comm' )
end
return ReturnVar
*===========================================================================*
PrevLineDflt:
   ReturnVar = ''
   SelPos = get_property( @window:'.ORDER_DETAIL', 'SELPOS' )
   OrderArray = get_property( @window:'.ORDER_DETAIL', 'ARRAY' )
   Column = SelPos<1>
   Row    = SelPos<2>
   if Row > 1 then
       CurRowData = get_property( @window:'.ORDER_DETAIL', 'ROWDATA' )
       convert @fm to @vm in CurRowData ;* it was @fm and should be @vm
                                        ;* according to the OI docs
       if field( CurRowData, @vm, 1, 12 ) = str( @vm, 11 ) then ;* blank row fill
	       PQuote = OrderArray<Column,Row-1>
	       PPsn   = OrderArray<2,Row-1>
	       PWo    = OrderArray<4,Row-1>
	       PPart  = OrderArray<5,Row-1>
	       PQty   = OrderArray<11,Row-1>
	       PPrice = OrderArray<12,Row-1>
	       *PAmt   = OrderArray<13,Row-1>
	       RowData = str( @vm, 12 )
	       RowData<1,1> = PQuote
	       RowData<1,2> = PPsn
	       RowData<1,4> = PWo
	       * DO NOT DUPLICATE THE WORK ORDER NUMBER FORCE ENTRY SO CHECK WITH PSN IS MADE
	       *RowData<1,4> = ''
	       * DO NOT DUPLICATE THE PART  NUMBER FORCE ENTRY SO CHECK WITH PSN IS MADE	       
	       RowData<1,5> = PPart
	       RowData<1,11> = PQty
	       RowData<1,12> = PPrice
	       TAmt = iconv( PPrice, 'MD2' ) * PQty
	       if Tamt = 0 then
	           Tamt = ''
	       end else
	           Tamt = oconv( Tamt, 'MD2,$' )
	       end
	       RowData<1,13> = TAmt
	       Void = set_property( @window:'.ORDER_DETAIL', 'ROWDATA', RowData )
	       Record = get_property( @window, 'RECORD' )
	       Record<order_quantity$,Row> = PQty
	       Record<order_price$,Row> = iconv( PPrice, 'MD2' )
	       Void = set_property( @window, 'RECORD', Record )
	       Void = send_event( @window:'.ORDER_TOT', 'CALCULATE', 1 )
	       Void = send_event( @window:'.QTY_TOT', 'CALCULATE', 1 )
		   ReturnVar = PQuote ;* to satisfy the default
	   end
   end 
return ReturnVar

*============================================================================*
PODefault:
   ReturnVar = ''
   ACID = get_property( @window:'.AC_ID', 'TEXT' )
   if ACID then
      BasePO = xlate( 'ANNUAL_CONTRACTS', ACID, annual_contracts_po$, 'X' )
      LastPO = xlate( 'ANNUAL_CONTRACTS', ACID, annual_contracts_rel_po$, 'X' )<1,1> ;* TAKE TOP ONE
      ReturnVar = field( BasePO, '-', 1 ):'-':field( LastPO, '-', 2 )+1
   end
return ReturnVar
*============================================================================*
