<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];

if (isset($_REQUEST['vouchdt'])) {
    $vouchdt = $_REQUEST['vouchdt'];

    
//    $getbal = mysqli_query($conn, "SELECT SUM(amount) as amt FROM `actran` WHERE accode = '$bankcode' AND 
//                                                           `date` < '$vouchdt' and (`retdate` != '' or `retdate` != '0000-00-00') ") or die(mysqli_error($conn));
//    $getamt = mysqli_fetch_array($getbal);
//    echo $vouchdt;
//    fdate1 = CTOD('01/' + cmonno + '/' + cyearno )
//tdate1 = CTOD('07/' + cmonno + '/' + cyearno )
//
//fdate2 = CTOD('08/' + cmonno + '/' + cyearno )
//tdate2 = CTOD('15/' + cmonno + '/' + cyearno )
//
//fdate3 = CTOD('16/' + cmonno + '/' + cyearno )
//tdate3 = CTOD('22/' + cmonno + '/' + cyearno )
//
//*********
//
//nmondate = GOMONTH(cdate,1)
//nmonno   = MONTH(nmondate)
//ncmonno = ALLTRIM(STR(nmonno))
//
//nyearno = YEAR(nmondate)
//ncyearno = ALLTRIM(STR(nyearno))
//
//ndate  = CTOD('01/' + ncmonno + '/' + ncyearno )
//
//IF monno = 12
//   fdate4 = CTOD('23/' + cmonno + '/' + cyearno )
//   tdate4 = CTOD('31/' + cmonno + '/' + cyearno )
//else   
//   fdate4 = CTOD('23/' + cmonno + '/' + cyearno )
//   tdate4 = ndate - 1
//ENDIF
//
//
//***********
//
//lmondate = GOMONTH(cdate,-1)
//lmonno   = MONTH(lmondate)
//lcmonno  = ALLTRIM(STR(lmonno))
//lyearno = YEAR(lmondate)
//lcyearno = ALLTRIM(STR(lyearno))
//
//fdate0 = CTOD('23/' + lcmonno + '/' + lcyearno )
//tdate0 = fdate1 - 1
//
//
//elimit = 1000
//
//
//*!*	errmess(fdate4)
//*!*	errmess(tdate4)
//
//*!*	errmess(fdate0)
//*!*	errmess(tdate0)
//
//
//***************  monthly
//
//
//fmdate1 = fdate1
//tmdate1 = ndate - 1
//
//fmdate0 = CTOD('01/' + lcmonno + '/' + lcyearno )
//tmdate0 = tdate0
//
//
//***************  half monthly
//
//
//f15date1 = fdate1
//t15date1 = CTOD('15/' + cmonno + '/' + cyearno )
//
//f15date2 = CTOD('16/' + cmonno + '/' + cyearno )
//t15date2 = ndate - 1
//
//f15date0 = CTOD('16/' + lcmonno + '/' + lcyearno )
//t15date0 = tdate0
//
//
//***************  ten days
//
//f10date1 = fdate1
//t10date1 = CTOD('10/' + cmonno + '/' + cyearno )
//
//f10date2 = CTOD('10/' + cmonno + '/' + cyearno )
//t10date2 = CTOD('20/' + cmonno + '/' + cyearno )
//
//f10date3 = CTOD('21/' + cmonno + '/' + cyearno )
//t10date3 = ndate - 1
//
//f10date0 = CTOD('21/' + lcmonno + '/' + lcyearno )
//t10date0 = tdate0
//
//
//***********************************
//
//wait'' TIME(.2)
//mdata = 'qx' + RIGHT(SYS(3),6)
//SELECT accode, custcode, name, billcycle, credtype, openbal, dc, SPACE(30) as cyclehead, 0000000000.00 as prelast, SPACE(1) as folwup, ;
//       0000000000.00 as lastbill, 0000000000.00 as recd, 0000000000.00 as balance FROM accmast ;
//       WHERE grpcode = '010' AND custcode > 0 AND accode != '000049' AND credtype = 'F' ORDER BY custcode INTO dbf &mdata
//GO top
//SCAN
//   SELECT &mdata
//   STORE accode TO maccode
//   STORE billcycle TO mbcycle
//   STORE credtype TO mcredtype
//   STORE openbal   TO mopenbal
//   STORE dc        TO mdc
//   
//   
//   DO CASE 
//   CASE MBCYCLE = 'W'
//        graced = 3
//		mperiod = 1
//		
//    	mperiod = 1
//	   DO case
//	   CASE cdate >= fdate1 AND cdate <= tdate1
//	        mperiod = 1
//
//	        frdate = fdate1
//	        foldate = cdate
//
//	        tilldate = tdate0
//	        
//	        pretilldt = fdate0 - 1
//	        
//	   CASE cdate >= fdate2 AND cdate <= tdate2
//	        mperiod = 2
//	        
//	        frdate = fdate2
//	        foldate = cdate
//
//	        tilldate = tdate1
//
//	        pretilldt = fdate1 - 1
//	        
//	   CASE cdate >= fdate3 AND cdate <= tdate3
//	        mperiod = 3
//
//	        frdate = fdate3 
//	        foldate = cdate
//	        
//	        tilldate = tdate2
//
//	        pretilldt = fdate2 - 1
//	        
//	   CASE cdate >= fdate4 AND cdate <= tdate4
//	        mperiod = 4
//
//	        frdate = fdate4 
//	        foldate = cdate
//	        
//	        tilldate = tdate3
//
//	        pretilldt = fdate3 - 1
//     	endc
//   CASE MBCYCLE = 'D'
//        tilldate = cdate - 1
//        
//        frdate = tilldate + 1
//        foldate = cdate
//        
//        pretilldt = tilldate - 1
//  
//   CASE MBCYCLE = 'M'
//        tilldate = tmdate0
//        
//        frdate = tilldate + 1
//        foldate = cdate
//
//        pretilldt = GOMONTH(tmdate0,-1)
//
//   CASE MBCYCLE = 'H'
//        graced = 7
//   
//		DO case
//		   CASE cdate >= f15date1 AND cdate <= t15date1
//                frdate = f15date1 
//                todate = t15date0
//		        
//                foldate = todate + graced
//                spbdate = cdate
//    		        
//                tilldate = t15date0 
//                
//    	        pretilldt = f15date0 - 1
//                
//		   CASE cdate >= f15date2 AND cdate <= t15date2
//                frdate = f15date2
//                todate = t15date1
//		        
//                foldate = todate + graced
//                spbdate = cdate
//    		        
//                tilldate = t15date1 
//
//    	        pretilldt = f15date1 - 1
//        ENDCASE
//   CASE MBCYCLE = 'T'
//        graced = 3
//   
//		DO case
//		   CASE cdate >= f10date1 AND cdate <= t10date1
//                frdate = f10date1
//                foldate = f10date1 + graced
//    		        
//                tilldate = f10date0 
//                
//    	        pretilldt = tilldate - 10
//                
//		   CASE cdate >= f10date2 AND cdate <= t10date2
//                frdate = f10date2
//                foldate = f10date2 + graced
//    		        
//                tilldate = f10date1 
//
//    	        pretilldt = tilldate - 10
//                
//		   CASE cdate >= f10date3 AND cdate <= t10date3
//                frdate = f10date3
//                foldate = f10date3 + graced
//    		        
//                tilldate = f10date2 
//
//    	        pretilldt = tilldate - 10
//        ENDCASE
//   ENDCASE
//
//*!*	IF custcode = 73
//*!*		errmess(tilldate)
//*!*	    errmess(frdate)
//*!*		errmess(foldate)
//*!*	ENDIF
//
//   
//   IF UPPER(mdc) = 'D'
//      xxmopen = mopenbal * - 1
//   ELSE
//      xxmopen = mopenbal 
//   ENDIF   
//   
//   
//   STORE 0 TO xtlamt, xramt, tillamt      
//   SELECT amount FROM actran WHERE accode = maccode AND date <= tilldate INTO CURSOR ctill
//   GO top
//   IF !EOF()
//      CALCULATE SUM(amount) to xtlamt 
//   ENDIF
//   
//   tillamt = xxmopen + xtlamt
//
//******************
//
//   STORE 0 TO pxtlamt, pxramt, ptillamt      
//   SELECT amount FROM actran WHERE accode = maccode AND date <= pretilldt INTO CURSOR ctill
//   GO top
//   IF !EOF()
//      CALCULATE SUM(amount) to pxtlamt 
//   ENDIF
//   
//   ptillamt = xxmopen + pxtlamt
//
//     
//   SELECT * FROM actran WHERE accode = maccode AND amount > 0 AND date >= frdate AND date <= foldate INTO CURSOR crecd
//   GO top
//   CALCULATE SUM(amount) to xramt 
//	   
//
//   SELECT &mdata
//   REPLACE prelast  WITH tillamt * -1
//   REPLACE recd     WITH xramt
//   
//   IF ABS(ptillamt) > 0
//      REPLACE folwup   WITH "Y"
//   else
//	   DO case
//	   case UPPER(mbcycle) = "W"
//	           DO case
//			   CASE cdate >= fdate1 AND cdate <= tdate1
//	                IF DAY(cdate) > 3
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//			   CASE cdate >= fdate2 AND cdate <= tdate2
//	                IF DAY(cdate) > 10
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//			   CASE cdate >= fdate3 AND cdate <= tdate3
//	                IF DAY(cdate) > 18
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//			   CASE cdate >= fdate4 AND cdate <= tdate4
//	                IF DAY(cdate) > 25
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//	           ENDCASE
//	   case UPPER(mbcycle) = "M"
//	        IF DAY(cdate) > 7
//	           REPLACE folwup   WITH "Y"
//	        ELSE
//	           REPLACE folwup   WITH "N"
//	        ENDIF
//	   case UPPER(mbcycle) = "H"
//			DO case
//			   CASE cdate >= f15date1 AND cdate <= t15date1
//	                IF DAY(cdate) > 7
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//			   CASE cdate >= f15date2 AND cdate <= t15date2
//	                IF DAY(cdate) > 22
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//	        ENDCASE
//	   case UPPER(mbcycle) = "T"
//			DO case
//			   CASE cdate >= f10date1 AND cdate <= t10date1
//	                IF DAY(cdate) > 3
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//			   CASE cdate >= f10date2 AND cdate <= t10date2
//	                IF DAY(cdate) > 13
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//			   CASE cdate >= f10date3 AND cdate <= t10date3
//	                IF DAY(cdate) > 23
//	                   REPLACE folwup   WITH "Y"
//	                ELSE
//	                   REPLACE folwup   WITH "N"
//	                ENDIF
//	        ENDCASE
//	   OTHERWISE
//	        REPLACE folwup   WITH "Y"
//	   ENDCASE
//   ENDIF
//ENDSCAN
//
//
//SELECT &mdata
//REPLACE ALL balance WITH prelast - recd
//
//SELECT * from &mdata WHERE balance >= elimit AND balance > 0 AND folwup = "Y" INTO CURSOR folwtmp

}
