;==File=================================================================;
; PO4380.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=============================================================;
;	po4380		At dock report.
;==Changes==============================================================;
; 08/07/2002 tah - Change for new PORECV file.
;=======================================================================;
.subroutine po4380

.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:porecv.rec"

record	head1
		,a*	@1,	'ITEM'
		,a*	@26,	'DESCRIPTION'
		,a*	@56,	'ORDER'
		,a*	@64,	'DATE'
		,a*	@72,	'QUANTITY'

record	legnd1
		,a*	@1,	'COMPANY:'
	lcompy	,a2	@11

record	pline
		,a80
record	,X
	prt_item	,a24	@1
	prt_descr	,a28	@26
	prt_orno	,a6	@55
	prt_recdate	,a8	@62
	prt_atdqty	,a10	@71

record
	abort		,d1
	mask3		,a10,	'ZZZZZX.XXX'
	recs_read	,d6
	title		,a*,	'ITEMS AT DOCK'
	wrk_amt		,d10.3		; work area for computing values
.start nopage,list

.proc
	;>>>>>	Main processing  <<<<<;
	call do_setup
	call open_files
	call get_destination
	if (abort.eq.FALSE)
	  begin
	    call print_report
	    call print_report_totals
	    xcall clslp ('Items At Dock Report')
	  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 (porecv_chan,'I:I',porecv_name)
	return

	;	Get the output destination
get_destination,
	abort = FALSE
	lcompy = ut_cmcomp
	clear lp_sel
	xcall askpr (ut_cmname,80,61,0,ut_cmdefp)
	if (lp_sel.eq.'E') abort = TRUE
	return

	;	Print the report
print_report,
	xcall status (DTEM_PRT)
	clear recs_read
	xcall statusbar (0,porecv_chan)
	xcall db_find (porecv_chan,' ',1,'M',,,opcde)
	repeat
	  begin
	    xcall db_next (porecv_chan,porecv,'F','M',,,opcde)
	    if (opcde) return
	    incr recs_read
	    if (.not.recs_read(5:2)) xcall statusbar (recs_read)
	    if (por_comp.eq.ut_cmcomp)
	      begin
		wrk_amt = por_recuqty - por_recdqty - por_recrqty
		if (wrk_amt.gt.0)
		  begin
		    prt_item = por_item
		    prt_descr = por_descr
		    prt_orno = por_order, 'XXXXXX'
		    xcall dtdsp (por_recdate,prt_recdate)
		    prt_atdqty = wrk_amt, mask3
		    call print
		  end
	      end
	  end

	;	Print the report totals
print_report_totals,
	return

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

	;	Print a detail line of the report
print,
	xcall print (pline,title,head1,,,legnd1)
	clear pline
	if (lp_cnt.eq.-1)
	  begin
	    call close_files
	    call do_shutdown
	    xcall e_exit
	    xreturn		; to calling program
	  end
	return
.end

