;==File=================================================================;
; POIHIST.DBL
;=======================================================================;
; Copyright 1999 by TAH Software Systems (TAH), Oklahoma City, Oklahoma ;
;									;
;	TAH provides this software under a license and may only be	;
;	used in accordance with the terms and conditions of such	;
;	license and with the inclusion of the above Copyright notice.	;
;==Function=============================================================;
;	po_inq_hist	Vendor order history search routine.
;	poll_pohist	Load List with history information
;==Changes==============================================================;
; 04/24/2007 lso - Adjust for Syn9 requirements
; 07/14/1998 TAH - Modify list processing for Synergy V6
;=======================================================================;
.subroutine po_inq_hist

	a_vend		,n	; IN  - Vendor ID
	a_order		,n	; IN  - Order number
	a_item		,a	; IN  - Item ID
	a_selected	,n	; OUT - True if a valid record selected
				;	False if no record selected

.start nopage,nolist
.include "WND:tools.def"
.include "WND:system.def"
.include "WND:inpctl.def"
.include "UTS:dteut.def"
.include "POS:dtepo.def"

.include "UTS:utcomm.gbl"
.include "POS:pocomm.gbl"
.include "POS:pohist.rec"

global data section list_pohist, init
record
	c_pohist_key	,a34
	c_vend		,d8
	c_item		,a24
	c_order		,d6
	wrk_key		,a34			; history file alt key 4
	  wrk_comp	,a2	@wrk_key
	  wrk_vend	,d8	@wrk_key+2
	  wrk_item	,a24	@wrk_key+10
	  wrk_order	,d6	@wrk_key+10
	  wrk_line	,d3	@wrk_key+16
record	sel_line			; selection window item
        sel_rfa         ,a6                     ; RFA
	sel_order	,d6			; order number
	sel_seqn	,d3			; line number
	sel_item	,a45			; item id/description
	sel_orqt	,d6			; order quantity
        sel_amt         ,d9.3                   ; extended amount
	sel_uom		,a3			; unit of measure
endglobal

.align
record
	colid		,i4		; column id
	fndid		,i4		; find id
	inpid		,i4		; input column id
	selid		,i4		; selection column id
	req		,i4
	srch		,i4		; search parameter
	field_no	,d3		; field number from i_fldinf
	lfind		,a*,	'i_lxxxxxx'
	  lfind_file	,a6	@lfind+3
	lclass		,a*,	'l_xxxxxx'
	  lclass_file	,a6	@lclass+2
	wind_header	,a160		; window header from script
	  wind_hleft	,a80	@wind_header
	  wind_hright	,a80	@wind_header+80
	wrk_rfa		,d6
.start nopage,list

.proc
	lfind_file = 'pohist'
	lclass_file = lfind_file
	if (.not.a_vend) xreturn	; return if nothing to find
	if (pohist_chan.eq.0) xcall open (pohist_chan,'I:I',pohist_name)
	c_vend = a_vend
	if %passed(a_item)
	 then c_item = a_item
	 else clear c_item
	if %passed(a_order)
	 then c_order = a_order
	 else clear c_order

.include "UTS:utfind.inc"

	if (g_entnam.eq.'O_EXIT')
	 then a_selected = FALSE
	 else
	  begin
	    a_selected = TRUE
	    xcall posrfa (pohist_chan,sel_rfa)
	  end
	xcall e_exit
	xreturn

find_first_match,
	wrk_comp = ut_cmcomp
	wrk_vend = a_vend
	if (.not.%passed(a_order)) .and.
	&  (.not.%passed(a_item))
	  begin
	    xcall db_find (pohist_chan,wrk_key(1:10),2,'M',,,opcde)
	  end
	if %passed(a_order)
	  begin
	    wrk_order = a_order
	    xcall db_find (pohist_chan,wrk_key(1:16),2,'M',,,opcde)
	    c_order = wrk_order
	  end
	if %passed(a_item)
	  begin
	    wrk_item = a_item
	    xcall db_find (pohist_chan,wrk_key,0,'M',,,opcde)
	  end
	c_pohist_key = wrk_key
	case opcde of
	  begincase
	  1: xcall message (DTER_RNF)
	  2: xcall message (DTER_LOK)
	  endcase
	return

utfind_find,
	return
.end
;=======================================================================;
.subroutine poll_pohist

	a_listid	,n	; IN  - ID for list
	a_request	,n	; IN  - List request code
	a_data		,a	; I/O - Data record area
	a_inpid		,n	; IN  - Input window ID
	a_disabled	,n	; IN  - True/False to disable list item
	a_index		,n	; IN  - List item index

.start nopage,nolist
.include "UTS:utcomm.gbl"

.include "POS:pocomm.gbl"
.include "POS:pohist.rec"

global data section list_pohist
record
	c_pohist_key	,a34
	c_vend		,d8
	c_item		,a24
	c_order		,d6
	wrk_key		,a34			; history file alt key 4
	  wrk_comp	,a2	@wrk_key
	  wrk_vend	,d8	@wrk_key+2
	  wrk_item	,a24	@wrk_key+10
	  wrk_order	,d6	@wrk_key+10
	  wrk_line	,d3	@wrk_key+16
record	sel_line			; selection window item
	sel_rfa		,d6			; RFA
	sel_order	,d6			; order number
	sel_seqn	,d3			; line number
	sel_item	,a45			; item id/description
	sel_orqt	,d6			; order quantity
        sel_amt         ,d9.3                   ; extended amount
	sel_uom		,a3			; unit of measure
endglobal

record
	wrk_rfa		,d6
.start nopage,list

.proc
	repeat
	  begin
	    xcall db_next (pohist_chan,pohist,'F','M',,,opcde)
	    unlock pohist_chan
	    case opcde of
	      begincase
	      1: a_request = D_LEOF
	      2: a_request = D_LEOF
	      endcase
	     else
	      if (poh_comp.eq.ut_cmcomp) .and.
	      &  (poh_vend.eq.c_vend) then
		begin
		  if (c_order.eq.0) .and.
		  &  (c_item.eq.UT_BLANKS)
		    begin
		      call load_line
		      exitloop
		    end
		  if (c_order.ne.0) .and.
		  &  (poh_order.eq.c_order)
		    begin
		      call load_line
		      exitloop
		    end
		  if (c_item.ne.UT_BLANKS) .and.
		  &  (poh_item.eq.c_item)
		    begin
		      call load_line
		      exitloop
		    end
		end
	       else a_request = D_LEOF
	    if (a_request.eq.D_LEOF) exitloop
	  end
	xreturn

load_line,
	sel_rfa = wrk_rfa
	sel_order = poh_order
	sel_seqn = poh_lineno
	xcall s_bld (sel_item,,"%a / %a",poh_item,poh_descr)
	sel_orqt = poh_ordqty
	sel_amt = poh_ucost - (poh_ucost * poh_discpct)
	sel_uom = poh_buomcode
	xcall i_display (a_inpid,'set1',sel_line)
	a_data = sel_line
	return
.end
;=======================================================================;

