;==File=================================================================;
; PO8400.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=============================================================;
;	po8400		Re-open purchase orders.
;==Changes==============================================================;
;=======================================================================;
.subroutine po8400

.start nopage,nolist
.include "UTL:tools.def"
.include "UTS:dteut.def"
.include "POS:dtepo.def"

.include "UTS:utcomm.gbl"
.include "POS:pocomm.gbl"
.include "POS:pohedr.rec"
.include "POS:porecv.rec"

record	scr_rec1		; input set 1
	scr_order	,d6		; order number
	scr_vendid	,d8		; vendor id
	scr_vendname	,a30		; vendor name
	scr_status	,a45		; order status line
	scr_confirm	,a3		; confirmation (YES/NO)

record
	abort		,d1
	recs_read	,d6
	set_name	,a4		; current input set name
	wdone		,d1
	wind_name	,a*,	'po8400'
	wind_no		,d2		; input window id
	wind_signal	,a31
.start nopage,list

.proc
	;>>>>>	Main processing  <<<<<;
	call do_setup
	call open_files
	repeat
	  begin
	    call get_parameters
	    if (abort.eq.TRUE) exitloop
	    call process_data
	    xcall i_init (wind_no)
	    set_name = 'set1'
	  end
	call close_files
	call do_shutdown
	xreturn		; to calling program

	;>>>>>	End of main processing  <<<<<;

	;	Set up environment
do_setup,
	xcall e_enter
	xcall lodcol ('RL')		; remove local columns
	xcall lodtoolbar ('AB',8)
	return

	;	Shut down environment
do_shutdown,
	xcall lodtoolbar ('RB',8)
	xcall e_exit
	return

	;	Open the needed data files
open_files,
	xcall open (pohedr_chan,'U:I',pohedr_name)
	xcall open (porecv_chan,'I:I',porecv_name)
	return

	;	Close the data files opened for the report
close_files,
	xcall close (pohedr_chan,DTE_CLOSE)
	xcall close (porecv_chan,DTE_CLOSE)
	return

	;	Get the report selection parameters
get_parameters,
	set_name = 'set1'
	repeat
	  begin
	    xcall get_parameters (wind_no,wind_name,set_name,scr_rec1,abort,wind_signal)
	    if (abort.eq.TRUE) exitloop
	    if (wind_signal)
	     then call process_signal
	     else
	      begin
		call verify_input_parameters
		if (wdone.eq.TRUE) exitloop
	      end
	  end
	return

	;	Process any break signals
process_signal,
	case g_entnam of
	  begincase
	  '@ORDER': begin
		      xcall status
		      call break_on_order
		    end
	  endcase
	return

verify_input_parameters,
	wdone = TRUE
	if (scr_confirm.ne.'YES')
	  begin
	    xcall i_init (wind_no,,,'ORDER,CONFIRM')
	    xcall i_init (wind_no,'set2')
	    set_name = 'set1'
	    wdone = FALSE
	  end
	return

	;	Process the data
process_data,
	abort = FALSE
	pom_status = 'P'
	clear pom_flag2, pom_flag3, pom_flag4
	xcall db_update (pohedr_chan,pohedr,pom_key,pohedr_log,opcde)
	xcall status (DTEPO_ONC)
	return

break_on_order,
	pom_comp = ut_cmcomp
	pom_order = scr_order
	xcall db_find (pohedr_chan,pom_key,0,'M',,,opcde)
	if (opcde)
	  begin
	    xcall message (DTEPO_ONF)
	    return
	  end
	xcall db_next (pohedr_chan,pohedr,'F','M',,,opcde)
	scr_vendid = pom_vend
	scr_vendname = pom_name
	case pom_status of
	  begincase
	  'O': xcall gettxt (DTEPO_ONC,scr_status)
	  'C': xcall gettxt (DTEPO_OIC,scr_status)
	  'D': xcall gettxt (DTEPO_OID,scr_status)
	  'R': xcall gettxt (DTEPO_PCN,scr_status)
	  'P': xcall gettxt (DTEPO_PRC,scr_status)
	  endcase
	xcall i_display (wind_no,'set2',scr_rec1)
	if (pom_status.ne.'O') .and.
	&  (pom_status.ne.'P') set_name = 'set3'
	if (pom_status.eq.'O') .or.
	&  (pom_status.eq.'P')
	  begin
	    xcall db_find (porecv_chan,pom_key,0,'M',,,opcde)
	    if (opcde) set_name = 'set3'
	  end
	return
.end

