DO alert WITH 'Modify for Multi branch'

PRIVATE ldfrom_dt,lctmp_wind,LCBRNCH_TAG
ldfrom_dt = DATE()
lctmp_wind = SYS(2015)
LCBRNCH_TAG = ' ' 
DO SET_MENU
DEFINE WINDOW (LCTMP_WIND) FROM 0,0 TO 8,50
ACTIVATE WINDOW (lctmp_wind)
MOVE WINDOW (lctmp_wind) CENTER 
@ 2,2 say 'DATE : ' GET ldfrom_dt valid validdt(ldfrom_dt)
@ 3,2 SAY 'BRANCH TAG : ' GET LCBRNCH_TAG SIZE 1,3 
READ cycle  
RELEASE WINDOWS (LCTMP_WIND)
SELECT TRANSECT
LOCATE FOR DATE = ldfrom_dt AND SOURCE = 'BRN'
IF FOUND()
	DO ERR_MSG WITH 'DATA FOR DATE : ' + DTOC(ldfrom_dt) + ' IS ALREADY IMPORTED ON ' + DTOC(TRANSECT.ADD_DT)
	DO CLS_MENU
	RETURN
ENDIF
PRIVATE lcINFile
lcInFile = (path_nam) + '\IMPORT\' + ALLTRIM(LCBRNCH_TAG) + ALLTRIM(STR(YEAR(ldFrom_dt))) + PADL(ALLTRIM(STR(MONTH(ldFrom_dt))),2,'0') + PADL(ALLTRIM(STR(DAY(ldFrom_dt))),2,'0') + '.DBF' 
IF ! FILE(lcInFile)
	DO err_msg WITH 'FILE : ' + lcInFile + ' REQUIRED FOR IMPORT NOT FOUND' + CHR(13) + 'PROCESS TERMINATED'
	DO CLS_MENU
	RETURN 
ENDIF
SELECT * ;
	FROM (lcInFile) ;
	INTO CURSOR QUERY ;
	READWRITE 
SELECT QUERY

*!*	SELECT * from (sele debit,debitparent FROM query WHERE debit NOT in (sele DISTINCT account FROM ledger WHERE ! group_flg))
SET ORDER TO ACCOUNT IN LEDGER
SET RELATION TO DEBIT INTO LEDGER 
LOCATE FOR PADL(DEBIT,LEN(LEDGER.ACCOUNT)) <> LEDGER.ACCOUNT
IF FOUND()
	DO ERR_MSG WITH 'SOME NEW ACCOUNTS ARE FOUND' + CHR(13) + 'IMPORT OPERATION WILL BE TERMINATED'
	BROWSE FIELDS DEBIT,DR_PARENT NOMODIFY ;
		FOR PADL(DEBIT,LEN(LEDGER.ACCOUNT)) <> LEDGER.ACCOUNT 
	USE IN QUERY
	DO CLS_MENU
	RETURN
ELSE
	REPLACE ALL ACCOUNT1 WITH LEDGER.ACCOUNT_NO
ENDIF 
SET RELATION TO PADL(CREDIT,LEN(LEDGER.ACCOUNT)) INTO LEDGER
LOCATE FOR CREDIT <> LEDGER.ACCOUNT
IF FOUND()
	DO ERR_MSG WITH 'SOME NEW ACCOUNTS ARE FOUND' + CHR(13) + 'IMPORT OPERATION WILL BE TERMINATED'
	BROWSE FIELDS CREDIT,CR_PARENT NOMODIFY ;
		FOR PADL(CREDIT,LEN(LEDGER.ACCOUNT)) <> LEDGER.ACCOUNT 
	USE IN QUERY
	DO CLS_MENU
	RETURN
ELSE
	REPLACE ALL ACCOUNT2 WITH LEDGER.ACCOUNT_NO
ENDIF 

IF ALIAS() = 'QUERY'
	IF FLOCK('TRANSECT')
		PRIVATE lctran_no,lcsr_no
		lcsr_no = PADL('1',LEN(transect.sr_no),'0')
		lctran_no = ' ' 
		= NEXTCNO('TRANSECT','TRAN_NO','TRAN_NO',lctran_no)
		SELECT query 
		SCAN 
			REPLACE SOURCE WITH 'BRN' ;
				add_dt WITH DATE() ;
				tran_no WITH lctran_no ;
				sr_no WITH lcsr_no ;
				IN query 
			lcsr_no = PADL(ALLTRIM(STR(VAL(lcsr_no) + 1)),LEN(transect.sr_no),'0')
			SCATTER memv
			INSERT INTO transect FROM memv
		ENDSCAN 
		UNLOCK IN transect
	ENDIF
ENDIF
do chkacbal with mend_dt
DO CLS_MENU