**TKBWHRSE.prg to work with 'Monthly Hours by Job/Employee/Day/Paytype' Excel (called from tk_repor)
SET STEP ON
SELECT PY_EMPLO
SET RELATION TO
SET ORDER TO TAG Employee
SELECT SYJOBCST
SET RELATION TO
SET ORDER TO JOB
**ds date
m.ldstart = D_BEGINDATE
m.ldend = D_ENDDATE
SELECT Job, Employee FROM tktimcrd;
WHERE WORK_DATE>=m.ldStart AND WORK_DATE<=m.ldEnd AND Pay_Cycle=m.Pay_Cycle;
GROUP BY Job, Employee;
ORDER BY Job, Employee;
INTO CURSOR Job_Emp
SELECT Job, Employee, sum(Hours) as Hours, pay_type, work_date ;
FROM tktimcrd;
WHERE WORK_DATE>=m.ldStart AND WORK_DATE<=m.ldEnd AND Pay_Cycle=m.Pay_Cycle;
GROUP BY Job, Employee, work_date, Pay_type;
ORDER BY Job, Employee, work_date, pay_type;
INTO CURSOR TCs READWRITE
INDEX ON Job+Employee TAG Job_Emp
**new
*WAIT WINDOW 'creating cursor'
CREATE CURSOR QUERY (JOB C(7), Employee C(15), Hrs_1_1 N(6,2), Type_1_1 C(1),Hrs_1_2 N(6,2), Type_1_2 C(1),Hrs_1_3 N(6,2), Type_1_3 C(1),;
Hrs_1_4 N(6,2), Type_1_4 C(1),Hrs_2_1 N(6,2), Type_2_1 C(1),Hrs_2_2 N(6,2), Type_2_2 C(1),Hrs_2_3 N(6,2), Type_2_3 C(1),Hrs_2_4 N(6,2),;
Type_2_4 C(1),Hrs_3_1 N(6,2), Type_3_1 C(1),Hrs_3_2 N(6,2), Type_3_2 C(1),Hrs_3_3 N(6,2), Type_3_3 C(1),Hrs_3_4 N(6,2), Type_3_4 C(1),;
Hrs_4_1 N(6,2), Type_4_1 C(1),Hrs_4_2 N(6,2), Type_4_2 C(1),Hrs_4_3 N(6,2), Type_4_3 C(1),Hrs_4_4 N(6,2), Type_4_4 C(1),Hrs_5_1 N(6,2),;
Type_5_1 C(1),Hrs_5_2 N(6,2), Type_5_2 C(1),Hrs_5_3 N(6,2), Type_5_3 C(1),Hrs_5_4 N(6,2), Type_5_4 C(1),Hrs_6_1 N(6,2), Type_6_1 C(1),;
Hrs_6_2 N(6,2), Type_6_2 C(1),Hrs_6_3 N(6,2), Type_6_3 C(1),Hrs_6_4 N(6,2), Type_6_4 C(1),Hrs_7_1 N(6,2), Type_7_1 C(1),Hrs_7_2 N(6,2),;
Type_7_2 C(1),Hrs_7_3 N(6,2), Type_7_3 C(1),Hrs_7_4 N(6,2), Type_7_4 C(1),Hrs_8_1 N(6,2), Type_8_1 C(1),Hrs_8_2 N(6,2), Type_8_2 C(1),;
Hrs_8_3 N(6,2), Type_8_3 C(1),Hrs_8_4 N(6,2), Type_8_4 C(1),Hrs_9_1 N(6,2), Type_9_1 C(1),Hrs_9_2 N(6,2), Type_9_2 C(1),Hrs_9_3 N(6,2),;
Type_9_3 C(1),Hrs_9_4 N(6,2), Type_9_4 C(1),Hrs_10_1 N(6,2), Type_10_1 C(1),Hrs_10_2 N(6,2), Type_10_2 C(1),Hrs_10_3 N(6,2),;
Type_10_3 C(1),Hrs_10_4 N(6,2), Type_10_4 C(1),Hrs_11_1 N(6,2), Type_11_1 C(1),Hrs_11_2 N(6,2), Type_11_2 C(1),Hrs_11_3 N(6,2),;
Type_11_3 C(1),Hrs_11_4 N(6,2), Type_11_4 C(1),Hrs_12_1 N(6,2), Type_12_1 C(1),Hrs_12_2 N(6,2), Type_12_2 C(1),Hrs_12_3 N(6,2),;
Type_12_3 C(1),Hrs_12_4 N(6,2), Type_12_4 C(1),Hrs_13_1 N(6,2), Type_13_1 C(1),Hrs_13_2 N(6,2), Type_13_2 C(1),Hrs_13_3 N(6,2),;
Type_13_3 C(1),Hrs_13_4 N(6,2), Type_13_4 C(1),Hrs_14_1 N(6,2), Type_14_1 C(1),Hrs_14_2 N(6,2), Type_14_2 C(1),Hrs_14_3 N(6,2),;
Type_14_3 C(1),Hrs_14_4 N(6,2), Type_14_4 C(1),Hrs_15_1 N(6,2), Type_15_1 C(1),Hrs_15_2 N(6,2), Type_15_2 C(1),Hrs_15_3 N(6,2),;
Type_15_3 C(1),Hrs_15_4 N(6,2), Type_15_4 C(1),Hrs_16_1 N(6,2), Type_16_1 C(1),Hrs_16_2 N(6,2), Type_16_2 C(1),Hrs_16_3 N(6,2),;
Type_16_3 C(1),Hrs_16_4 N(6,2), Type_16_4 C(1),Hrs_17_1 N(6,2), Type_17_1 C(1),Hrs_17_2 N(6,2), Type_17_2 C(1),Hrs_17_3 N(6,2),;
Type_17_3 C(1),Hrs_17_4 N(6,2), Type_17_4 C(1),Hrs_18_1 N(6,2), Type_18_1 C(1),Hrs_18_2 N(6,2), Type_18_2 C(1),Hrs_18_3 N(6,2),;
Type_18_3 C(1),Hrs_18_4 N(6,2), Type_18_4 C(1),Hrs_19_1 N(6,2), Type_19_1 C(1),Hrs_19_2 N(6,2), Type_19_2 C(1),Hrs_19_3 N(6,2),;
Type_19_3 C(1),Hrs_19_4 N(6,2), Type_19_4 C(1),Hrs_20_1 N(6,2), Type_20_1 C(1),Hrs_20_2 N(6,2), Type_20_2 C(1),;
Hrs_20_3 N(6,2), Type_20_3 C(1),Hrs_20_4 N(6,2), Type_20_4 C(1),Hrs_21_1 N(6,2), Type_21_1 C(1),Hrs_21_2 N(6,2),;
Type_21_2 C(1),Hrs_21_3 N(6,2), Type_21_3 C(1),Hrs_21_4 N(6,2), Type_21_4 C(1),Hrs_22_1 N(6,2), Type_22_1 C(1),;
Hrs_22_2 N(6,2), Type_22_2 C(1),Hrs_22_3 N(6,2), Type_22_3 C(1),Hrs_22_4 N(6,2), Type_22_4 C(1),Hrs_23_1 N(6,2),;
Type_23_1 C(1),Hrs_23_2 N(6,2), Type_23_2 C(1),Hrs_23_3 N(6,2), Type_23_3 C(1),Hrs_23_4 N(6,2), Type_23_4 C(1),;
Hrs_24_1 N(6,2), Type_24_1 C(1),Hrs_24_2 N(6,2), Type_24_2 C(1),Hrs_24_3 N(6,2), Type_24_3 C(1),Hrs_24_4 N(6,2),;
Type_24_4 C(1),Hrs_25_1 N(6,2), Type_25_1 C(1),Hrs_25_2 N(6,2), Type_25_2 C(1),Hrs_25_3 N(6,2), Type_25_3 C(1),;
Hrs_25_4 N(6,2), Type_25_4 C(1),Hrs_26_1 N(6,2), Type_26_1 C(1),Hrs_26_2 N(6,2), Type_26_2 C(1),Hrs_26_3 N(6,2),;
Type_26_3 C(1),Hrs_26_4 N(6,2), Type_26_4 C(1),Hrs_27_1 N(6,2), Type_27_1 C(1),Hrs_27_2 N(6,2), Type_27_2 C(1),;
Hrs_27_3 N(6,2), Type_27_3 C(1),Hrs_27_4 N(6,2), Type_27_4 C(1),Hrs_28_1 N(6,2), Type_28_1 C(1),Hrs_28_2 N(6,2),;
Type_28_2 C(1),Hrs_28_3 N(6,2), Type_28_3 C(1),Hrs_28_4 N(6,2), Type_28_4 C(1),Hrs_29_1 N(6,2), Type_29_1 C(1),;
Hrs_29_2 N(6,2), Type_29_2 C(1),Hrs_29_3 N(6,2), Type_29_3 C(1),Hrs_29_4 N(6,2), Type_29_4 C(1),Hrs_30_1 N(6,2),;
Type_30_1 C(1),Hrs_30_2 N(6,2), Type_30_2 C(1),Hrs_30_3 N(6,2), Type_30_3 C(1),Hrs_30_4 N(6,2), Type_30_4 C(1),;
Hrs_31_1 N(6,2), Type_31_1 C(1),Hrs_31_2 N(6,2), Type_31_2 C(1),Hrs_31_3 N(6,2), Type_31_3 C(1),Hrs_31_4 N(6,2),;
Type_31_4 C(1), Hours N(6,2))
************THE CURSOR ABOVE IS WHERE IT MESSES UP!*************
*WAIT WINDOW 'just created cursor'
INDEX ON Job+Employee TAG Job_Emp
SELECT Job_Emp
SCAN
INSERT INTO Query (Job, Employee) VALUES (Job_Emp.job, Job_Emp.employee)
SELECT TCs
SCAN FOR TCs.Job = Job_Emp.job AND TCs.employee = Job_Emp.employee
m.Whc_day = TCs.work_date - m.ldStart + 1
*!* IF EVALUATE('QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_1') = 0 && first pay type for this date
*!* m.Whc_Hrs = 'QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_1'
*!* m.Whc_Type = 'QUERY.Type_'+ALLT(STR(m.Whc_day,2))+'_1'
*!* ELSE && already entered 1 pay type for this date
*!* m.Whc_Hrs = 'QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_2'
*!* m.Whc_Type = 'QUERY.Type_'+ALLT(STR(m.Whc_day,2))+'_2'
*!* ENDIF
DO case
case EVALUATE('QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_1') = 0 && first pay type for this date
m.Whc_Hrs = 'QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_1'
m.Whc_Type = 'QUERY.Type_'+ALLT(STR(m.Whc_day,2))+'_1'
case EVALUATE('QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_2') = 0 && already entered 1 pay type for this date
m.Whc_Hrs = 'QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_2'
m.Whc_Type = 'QUERY.Type_'+ALLT(STR(m.Whc_day,2))+'_2'
case EVALUATE('QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_3') = 0 && already entered 1 pay type for this date
m.Whc_Hrs = 'QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_3'
m.Whc_Type = 'QUERY.Type_'+ALLT(STR(m.Whc_day,2))+'_3'
case EVALUATE('QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_4') = 0 && already entered 1 pay type for this date
m.Whc_Hrs = 'QUERY.Hrs_'+ALLT(STR(m.Whc_day,2))+'_4'
m.Whc_Type = 'QUERY.Type_'+ALLT(STR(m.Whc_day,2))+'_4'
ENDCASE
REPLACE &Whc_Hrs WITH TCs.Hours
REPLACE &Whc_Type WITH ALLTRIM(TCs.pay_type)
ENDSCAN
SELECT Job_Emp
ENDSCAN
SELECT Query
SCAN
*!* REPLACE Hours WITH Hrs_1_1+Hrs_1_2+Hrs_2_1+Hrs_2_2+Hrs_3_1+Hrs_3_2+Hr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rs_21_1+ Hrs_21_2+ Hrs_21_3+ Hrs_21_4+ Hrs_22_1+ Hrs_22_2+ Hrs_22_3+ Hrs_22_4+;
Hrs_23_1+ Hrs_23_2+ Hrs_23_3+ Hrs_23_4+ Hrs_24_1+ Hrs_24_2+ Hrs_24_3+ Hrs_24_4+ Hrs_25_1+ Hrs_25_2+ Hrs_25_3+ Hrs_25_4+;
Hrs_26_1+ Hrs_26_2+ Hrs_26_3+ Hrs_26_4+ Hrs_27_1+ Hrs_27_2+ Hrs_27_3+ Hrs_27_4+ Hrs_28_1+ Hrs_28_2+ Hrs_28_3+ Hrs_28_4+;
Hrs_29_1+ Hrs_29_2+ Hrs_29_3+ Hrs_29_4+ Hrs_30_1+ Hrs_30_2+ Hrs_30_3+ Hrs_30_4+ Hrs_31_1+ Hrs_31_2+ Hrs_31_3+ Hrs_31_4
ENDSCAN
*BROWSE norm
SET RELATION TO Employee INTO PY_EMPLO ADDI
SET RELATION TO JOB INTO SYJOBCST ADDI
USE IN Job_Emp
USE IN TCs
************EXCEL TIME!!*************
SET STEP ON
#define xlLastCell 11
#define xlMaximized -4137
#define xlRangeAutoformatClassic2 2
#define xlPortrait 1
#define xlCenter -4108
*open excel in background, the program, not a workbook.
oExcel = CreateObject("Excel.Application")
if vartype(oExcel) != "O"
* could not instantiate Excel object
* show an error message here
return .F.
ENDIF
*Get paytype descriptions for KeyCode at headers
myF = IIF(seek('F','pypaytyp'), PYPAYTYP.descriptn,'')
myJ = IIF(seek('J','pypaytyp'), PYPAYTYP.descriptn,'')
my1 = IIF(seek('1','pypaytyp'), PYPAYTYP.descriptn,'')
myW = IIF(seek('W','pypaytyp'), PYPAYTYP.descriptn,'')
myP = IIF(seek('P','pypaytyp'), PYPAYTYP.descriptn,'')
my3 = IIF(seek('3','pypaytyp'), PYPAYTYP.descriptn,'')
myS = IIF(seek('S','pypaytyp'), PYPAYTYP.descriptn,'')
myV = IIF(seek('V','pypaytyp'), PYPAYTYP.descriptn,'')
my4 = IIF(seek('4','pypaytyp'), PYPAYTYP.descriptn,'')
myH = IIF(seek('H','pypaytyp'), PYPAYTYP.descriptn,'')
myT = IIF(seek('T','pypaytyp'), PYPAYTYP.descriptn,'')
my5 = IIF(seek('5','pypaytyp'), PYPAYTYP.descriptn,'')
numDays = m.ldEnd - m.ldStart + 1 &&how many full days in the month?
*create a blank workbook
oWorkbook = oExcel.Application.Workbooks.Add()
*make excel invisible for a bit
oExcel.visible = .f.
y = 1 &¤t row in excel
lastJob=''
lastEmp = ''
SELECT query
SCAN
curJob = query.job
curEmp = query.employee
IF curJob = lastJob then
*same job, keep going
IF curEmp = lastEmp then
*same emp, keep going
ELSE
*new emp, new line
y=y+1
endif
ELSE
lastJob = curJob
*different job, page break, new headers
curLoc = IIF(seek(curJob,'syjobcst'), syjobcst.location,'')
DO NewHeader1
endif
**ds test, add A1 = 'hello', a2 = 'there'
*oExcel.Range("f2").Value = m.c_reportname
*oExcel.cells(1,3).Value = "Tset 12312313213"
ENDSCAN
*make excel visible now
oExcel.visible = .t.
RETURN
**********************************************************
PROCEDURE NewHeader1
*Creates a new header after the pagebreak in Excel
WITH oExcel.range("f"+TRANSFORM(y))
.Value = m.c_company
.HorizontalAlignment = xlCenter
.font.bold = .t.
ENDWITH
WITH oExcel.range("f"+TRANSFORM(y+1))
.Value = m.c_reportname
.HorizontalAlignment = xlCenter
.font.bold = .t.
ENDWITH
oExcel.range("o"+TRANSFORM(y)).Value = "Key Code"
oExcel.range("m"+TRANSFORM(y+1)).Value = "F"
oExcel.range("n"+TRANSFORM(y+1)).Value = myF
oExcel.range("o"+TRANSFORM(y+1)).Value = "J"
oExcel.range("p"+TRANSFORM(y+1)).Value = myJ
oExcel.range("q"+TRANSFORM(y+1)).Value = "1"
oExcel.range("r"+TRANSFORM(y+1)).Value = my1
oExcel.range("m"+TRANSFORM(y+2)).Value = "W"
oExcel.range("n"+TRANSFORM(y+2)).Value = myW
oExcel.range("o"+TRANSFORM(y+2)).Value = "P"
oExcel.range("p"+TRANSFORM(y+2)).Value = myP
oExcel.range("q"+TRANSFORM(y+2)).Value = "3"
oExcel.range("r"+TRANSFORM(y+2)).Value = my3
**DATE RANGE AND JOB**
oExcel.range("a"+TRANSFORM(y+2)).Value = "Date Range Selected:"
oExcel.range("c"+TRANSFORM(y+2)).Value = m.ldStart
oExcel.range("d"+TRANSFORM(y+2)).Value = "to"
oExcel.range("e"+TRANSFORM(y+2)).Value = m.ldEnd
oExcel.range("a"+TRANSFORM(y+4)).Value = "Job:" &&Job
oExcel.range("b"+TRANSFORM(y+4)).Value = curJob
oExcel.range("a"+TRANSFORM(y+5)).Value = "Location:" &&Loc
oExcel.range("b"+TRANSFORM(y+5)).Value = curLoc
oExcel.range("m"+TRANSFORM(y+3)).Value = "S"
oExcel.range("n"+TRANSFORM(y+3)).Value = myS
oExcel.range("o"+TRANSFORM(y+3)).Value = "V"
oExcel.range("p"+TRANSFORM(y+3)).Value = myV
oExcel.range("q"+TRANSFORM(y+3)).Value = "4"
oExcel.range("r"+TRANSFORM(y+3)).Value = my4
oExcel.range("m"+TRANSFORM(y+4)).Value = "H"
oExcel.range("n"+TRANSFORM(y+4)).Value = myH
oExcel.range("o"+TRANSFORM(y+4)).Value = "T"
oExcel.range("p"+TRANSFORM(y+4)).Value = myT
oExcel.range("q"+TRANSFORM(y+4)).Value = "5"
oExcel.range("r"+TRANSFORM(y+4)).Value = my5
oExcel.range("a"+TRANSFORM(y+7)).Value = "File #"
oExcel.range("b"+TRANSFORM(y+7)).Value = "Name"
y=y+6
curDate = m.ldStart
FOR z = 1 TO numDays
oExcel.cells(y,z+2).value = left(DTOC(curDate),5)
oExcel.cells(y+1,z+2).value = left(CDOW(curDate),3)
curDate = curDate+1
ENDFOR
ENDPROC
**********************************************************