;==File=================================================================;
; PO4700.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=============================================================;
;	po4700		Post receivings control module.
;==Changes==============================================================;
;=======================================================================;
.subroutine po4700

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

.include "UTS:utcomm.gbl"
.include "POS:pocomm.gbl"
.include "INS:incomm.gbl"
.include "SMS:smcmpy.rec"

record
	abort		,d1
	log_msg		,a*,	'     /      /        /      '
	  log_function	,a5	@log_msg
	  log_prog	,a6	@log_msg+6
	  log_date	,a8	@log_msg+13
	  log_time	,a6	@log_msg+22
	ptr		,d2		; loop control
	start_ptr	,d2		; beginning loop value
.start nopage,list

.proc
	;>>>>>	Main processing  <<<<<;
	call do_setup
	call open_files
	call process_data
	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 (poline_chan,'U:I',poline_name)
	return

	;	Close the needed data files
close_files,
	xcall close (pohedr_chan,DTE_CLOSE)
	xcall close (poline_chan,DTE_CLOSE)
	return

	;	Process the data
process_data,
	abort = FALSE
	xcall status (DTEM_PRC)

	;	look for abort file
	start_ptr = 1
	ut_filedev = 'WRK'
	ut_filename = 'poperr'
	ut_fileext = ut_userid
	xcall open (ut_chan,'I',ut_file,DTE_WARN)
	if (.not.opcde)
	  begin
	    reads (ut_chan,ut_ert)
	    if (ut_ert.ne.'start' .and. ut_ert.ne.'restart')
	      begin
		xcall message (DTER_IRO,D_ERROR)
		xcall close (ut_chan,DTE_CLOSE)
		return
	      end
	    if (ut_ert.eq.'restart/') start_ptr = ut_ert(9:2)
	    xcall close (ut_chan,DTE_CLOSE)
	  end

	;	open log file
	xcall open (ut_chan,'O',ut_file)
	xcall close (ut_chan,DTE_CLOSE)

	case po_cmrectyp of
	  begincase
	  1: call one_step		; single step receivings
	  2: call one_step		; two step receivings
	  endcase
	return

	;	loop to execute all posting modules
one_step,
	for ptr from start_ptr thru 4 by 1
	  begin
	    case ptr of
	      begincase
	      begin			; build work file - 1
		log_prog = 'po4710'
		call log_start
		xcall po4710
		call log_end
	      end
	      begin			; posting register - 2
		log_prog = 'po4720'
		call log_start
		xcall po4720
		call log_end
	      end
	      begin			; inventory - 3
		log_prog = 'po4730'
		call log_start
		xcall po4730
		call log_end
	      end
	      begin			; history - 4
		log_prog = 'po4740'
		call log_start
		xcall po4740
		call log_end
	      end
	      endcase	
	    if (ut_err)		; Error - abort the loop
	      begin
		xcall open (ut_chan,'A',ut_file)
		writes (ut_chan,ut_ert)
		xcall message (DTEPO_PBA,D_ERROR)
		xcall close (ut_chan,DTE_CLOSE)
		return
	      end
	  end
	log_prog = 'post'
	call log_end
	return

	;	write starting log record
log_start,
	log_function = 'start'
	call log_write
	return

	;	write ending log record
log_end,
	log_function = 'end'
	call log_write
	return

	;	write log record
log_write,
	if (ut_filename.ne.'poperr')
	  begin
	    ut_filedev = 'WRK'
	    ut_filename = 'poperr'
	    ut_fileext = ut_userid
	  end
	xcall open (ut_chan,'A',ut_file)
	log_date = ut_datdsp
	xcall time (log_time)
	writes (ut_chan,log_msg)
	xcall close (ut_chan,DTE_CLOSE)
	return
.end

