/* imp-student.p - Import basic student data */ /* Format for import lines is 1 - BldgCode 2 - Student ID 3 - Name 4 - Home Street # 5 - Home Street Name 6 - Home Street Apt 7 - Home City 8 - Home State 9 - Home Zip 10 - Home Phone 11 - Home Phone Unlisted? Y/N 12 - Ethnic code (default UNKNOWN) 13 - Gender (M/F) 14 - Birth Date 15 - Grade 16 - Status Code 17 - Home Room (default UNKN) 18 - SSN 19 - SPED Code (can be blank) 20 - SPED FTE 21 - Counselor Personnel Code (default UNKN) 22 - FTE 23 - Promotion Path (default: building promotion path) 24 - House (if used) */ /* Include commons */ {common.i NEW} {p-init.i "'IMPORTER'"} {addrutil.i DEFINE} {histutil.i DEFINE NEW} /* Constants */ &SCOPED WriteCmd PUT STREAM LogStream UNFORMATTED &SCOPED WriteHdr "#" LineCnt ", " ImportText[1] ", " ImportText[2] ": " &SCOPED WriteLog {&WriteCmd} {&WriteHdr} &SCOPED MaxIndex 24 /* Define Variables */ DEFINE VARIABLE SchoolYear AS CHARACTER NO-UNDO. DEFINE VARIABLE ImportFile AS CHARACTER NO-UNDO. DEFINE VARIABLE ExportFile AS CHARACTER NO-UNDO. DEFINE VARIABLE LogFile AS CHARACTER NO-UNDO. DEFINE VARIABLE ReplaceMode AS LOGICAL NO-UNDO. DEFINE VARIABLE PurgeMode AS LOGICAL NO-UNDO. DEFINE VARIABLE ImportText AS CHARACTER EXTENT {&MaxIndex} NO-UNDO. DEFINE VARIABLE LineCnt AS INTEGER NO-UNDO. DEFINE VARIABLE AutoCreate AS LOGICAL NO-UNDO. DEFINE VARIABLE TheIndex AS INTEGER NO-UNDO. DEFINE VARIABLE TheText AS CHARACTER NO-UNDO. DEFINE VARIABLE RequiredText AS CHARACTER NO-UNDO. DEFINE VARIABLE RequiredField AS LOGICAL EXTENT {&MaxIndex} NO-UNDO INITIAL [yes,yes,yes,yes,yes ,no,yes,yes,yes,no ,no,no,yes,yes,yes ,yes,no,no,no,no ,no,no,no,no]. /* Variables for statistics */ DEFINE VARIABLE TotalLineCnt AS INTEGER NO-UNDO. DEFINE VARIABLE StartTime AS INTEGER NO-UNDO. DEFINE VARIABLE LastUpdate AS INTEGER NO-UNDO. DEFINE VARIABLE PercentDone AS DECIMAL NO-UNDO. DEFINE VARIABLE LinesPerSec AS DECIMAL NO-UNDO. DEFINE VARIABLE ErrorCnt AS INTEGER NO-UNDO. DEFINE VARIABLE Elapsed AS CHARACTER NO-UNDO. DEFINE VARIABLE TimeRemain AS CHARACTER NO-UNDO. DEFINE VARIABLE Done AS LOGICAL NO-UNDO. DEFINE VARIABLE ImportDate AS DATE INITIAL TODAY NO-UNDO. DEFINE VARIABLE CreateOK AS LOGICAL NO-UNDO. /* Define Buffers */ DEFINE BUFFER YearBuff FOR school-year. DEFINE BUFFER BldgBuff FOR building. DEFINE BUFFER VrsnBuff FOR schd-version. /* Define Streams */ DEFINE STREAM ImportStream. DEFINE STREAM LogStream. DEFINE STREAM ExportStream. /* Status frame */ FORM TotalLineCnt COLUMN-LABEL "Total!Lines" FORMAT "zzzzz9" LineCnt COLUMN-LABEL "Curnt!Line" FORMAT "zzzzz9" PercentDone COLUMN-LABEL "%age!Done" FORMAT "zz9.99%" LinesPerSec COLUMN-LABEL "Lines!/sec" FORMAT "zz9.99" ErrorCnt COLUMN-LABEL "Errors" FORMAT "zzzz9" Elapsed COLUMN-LABEL "Elapsed!Time" TimeRemain COLUMN-LABEL "Time!Remain" WITH FRAME StatusFrame 1 DOWN CENTERED ROW 9 OVERLAY COLOR VALUE(the-color.c-proc) TITLE COLOR VALUE(the-color.c-title) " Student Importation Statistics ". /* Load the defaults */ DO FOR user-default TRANSACTION: {get-def.i "'SCHOOLYEAR'" SchoolYear} {get-def.i "'IMPORTFILE'" ImportFile} {get-def.i "'PURGEMODE'" TheText} PurgeMode = TheText = "Yes". {get-def.i "'REPLACE'" TheText} ReplaceMode = TheText = "Yes". {get-def.i "'LOGFILE'" LogFile} {get-def.i "'AUTOCREATE'" TheText} AutoCreate = TheText = "Yes". {get-def.i "'EXPORTFILE'" ExportFile} END. /* First, get the import file */ QueryBlock: DO WHILE TRUE ON ERROR UNDO, RETURN ON ENDKEY UNDO, RETURN: /* Define the form */ FORM SchoolYear LABEL " School Year to import to" FORMAT "x(9)" ImportFile LABEL " Import from" FORMAT "x(255)" VIEW-AS FILL-IN SIZE 32 BY 1 SPACE(1) ImportDate LABEL " Historical Date of Import" FORMAT "99/99/9999" SKIP PurgeMode LABEL " Purge students first" FORMAT "Yes/No" SKIP ReplaceMode LABEL " Existing records should be" FORMAT "Replaced/Kept" LogFile LABEL " Log import results to" FORMAT "x(255)" VIEW-AS FILL-IN SIZE 32 BY 1 SPACE(1) AutoCreate LABEL " Auto-create codes" FORMAT "Yes/No" SKIP ExportFile LABEL " Backup replaced data to" FORMAT "x(255)" VIEW-AS FILL-IN SIZE 32 BY 1 WITH FRAME QueryFrame OVERLAY 1 DOWN CENTERED ROW 7 SIDE-LABELS COLOR VALUE(the-color.c-proc) PROMPT VALUE(the-color.c-input). /* Default things for the user */ ON LEAVE OF ImportFile IN FRAME QueryFrame DO: /* Define Variables */ DEFINE VARIABLE DotPtr AS INTEGER NO-UNDO. /* Get pointer to decimal */ DotPtr = INDEX(ImportFile:SCREEN-VALUE, "."). IF DotPtr = 0 THEN RETURN. /* Default the log file */ IF LogFile:SCREEN-VALUE = "" THEN LogFile:SCREEN-VALUE = SUBSTR(SELF:SCREEN-VALUE, 1, DotPtr - 1) + ".log". /* Default the backup file */ IF ExportFile:SCREEN-VALUE = "" THEN ExportFile:SCREEN-VALUE = SUBSTR(SELF:SCREEN-VALUE, 1, DotPtr - 1) + ".org". END. /* Query the user */ UPDATE SchoolYear SKIP ImportFile SKIP ImportDate SKIP PurgeMode SKIP ReplaceMode SKIP LogFile SKIP AutoCreate SKIP ExportFile SKIP WITH FRAME QueryFrame OVERLAY 1 DOWN CENTERED ROW 7 SIDE-LABELS COLOR VALUE(the-color.c-proc) PROMPT VALUE(the-color.c-input) TITLE COLOR VALUE(the-color.c-title) " Import Students ". /* See if the note exists */ IF SEARCH(ImportFile) = ? THEN DO: BELL. {safe-msg.i "'Cannot find the import source file'"} NEXT. END. /* Load the year buffer */ FIND YearBuff WHERE YearBuff.school-year-name = SchoolYear NO-LOCK NO-ERROR. IF NOT AVAILABLE YearBuff THEN DO: BELL. {safe-msg.i "'School year not on file'"} NEXT. END. /* Make sure the backup file should be overwritten */ IF SEARCH(ExportFile) <> ? THEN DO: DO ON ERROR UNDO, NEXT QueryBlock ON ENDKEY UNDO, NEXT QueryBlock: MESSAGE COLOR VALUE(the-color.c-alert) " " ExportFile "already exists " SKIP " Do you want to overwrite it?" SKIP VIEW-AS ALERT-BOX QUESTION BUTTONS YES-NO UPDATE OverwriteFile AS LOGICAL. END. /* Iterate if not okay */ IF NOT OverwriteFile THEN NEXT. END. /* Done */ LEAVE. END. /* Save the defaults */ DO FOR user-default TRANSACTION: {set-def.i "'SCHOOLYEAR'" SchoolYear} {set-def.i "'IMPORTFILE'" ImportFile} {set-def.i "'PURGEMODE'" STRING(PurgeMode)} {set-def.i "'REPLACE'" STRING(ReplaceMode)} {set-def.i "'LOGFILE'" LogFile} {set-def.i "'AUTOCREATE'" STRING(AutoCreate)} {set-def.i "'EXPORTFILE'" ExportFile} END. /* Purge catalogs */ IF PurgeMode THEN DO: MESSAGE "Purging students, please be patient...". FOR EACH stu-base: RUN del-stu.p (BUFFER stu-base, Yes, OUTPUT Done). END. HIDE MESSAGE NO-PAUSE. END. /* Load the profile */ FIND FIRST spm-prof NO-LOCK. /* Get line count */ INPUT STREAM ImportStream THROUGH VALUE("wc -l " + ImportFile). IMPORT STREAM ImportStream ImportText. INPUT STREAM ImportStream CLOSE. TotalLineCnt = INTEGER(ImportText[1]). DISPLAY TotalLineCnt WITH FRAME StatusFrame. /* Open the file */ INPUT STREAM ImportStream FROM VALUE(ImportFile). OUTPUT STREAM LogStream TO VALUE(LogFile) PAGE-SIZE 0 UNBUFFERED. OUTPUT STREAM ExportStream TO VALUE(ExportFile) PAGE-SIZE 0. /* Hide the query frame */ HIDE FRAME QueryFrame NO-PAUSE. /* Reset counters */ ASSIGN StartTime = TIME LastUpdate = StartTime. /* Begin Processing */ ImportLoop: REPEAT ON ERROR UNDO, LEAVE ON ENDKEY UNDO, LEAVE: /* Get a line */ ImportText = "". IMPORT STREAM ImportStream ImportText. LineCnt = LineCnt + 1. /* Update status display */ IF (TIME - LastUpdate) > 2 THEN DO: DISPLAY LineCnt (LineCnt / TotalLineCnt) * 100 @ PercentDone LineCnt / (TIME - StartTime) @ LinesPerSec ErrorCnt STRING(TIME - StartTime, "HH:MM:SS") @ Elapsed STRING(INTEGER((TotalLineCnt - LineCnt) / (LineCnt / (TIME - StartTime))), "HH:MM:SS") @ TimeRemain WITH FRAME StatusFrame. LastUpdate = TIME. END. /* Make sure we have our required fields */ RequiredText = "". DO TheIndex = 1 TO {&MaxIndex}: IF RequiredField[TheIndex] AND (ImportText[TheIndex] = "") OR (ImportText[TheIndex] = ?) THEN RequiredText = RequiredText + " " + STRING(TheIndex). END. IF RequiredText <> "" THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Required fields (" + TRIM(RequiredText) + ") missing, NOT imported" SKIP. NEXT ImportLoop. END. /* Make sure we can find the building */ FIND FIRST BldgBuff OF YearBuff NO-LOCK WHERE BldgBuff.bldg-code = ImportText[1] NO-ERROR. IF NOT AVAILABLE BldgBuff THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Bldg is not on file, NOT imported" SKIP. NEXT ImportLoop. END. /* Load the version buffer */ FIND FIRST VrsnBuff OF BldgBuff NO-LOCK WHERE VrsnBuff.active-schedule = Yes. /* See if the student is already on file */ FIND stu-base WHERE stu-base.stu-id = ImportText[2] NO-ERROR. IF AVAILABLE stu-base THEN FIND FIRST stu-year OF YearBuff WHERE stu-year.stu-seq = stu-base.stu-seq NO-ERROR. IF AVAILABLE stu-base AND available stu-year THEN DO: /* Handle unreplacable mode */ IF NOT ReplaceMode THEN DO: {&WriteLog} "Existing student/year on file, NOT imported" SKIP. NEXT ImportLoop. END. /* Load ancillary records */ FIND ethnic-code OF stu-base NO-LOCK. FIND grade-catalog OF stu-year NO-LOCK. FIND status-code OF stu-year NO-LOCK. FIND room-catalog OF stu-year NO-LOCK. FIND sped-code OF stu-year NO-LOCK NO-ERROR. FIND personnel OF stu-year NO-LOCK. FIND house OF stu-year NO-LOCK NO-ERROR. FIND promotion-path-name OF stu-year NO-LOCK NO-ERROR. /* Create a backup */ EXPORT STREAM ExportStream BldgBuff.bldg-code stu-year.stu-id stu-year.stu-name stu-base.stu-street-num stu-base.stu-street stu-base.stu-street-apt stu-base.stu-city stu-base.stu-state stu-base.stu-zip stu-base.stu-phone stu-base.unlisted-phone ethnic-code.ethnic-code STRING(stu-base.gender, "M/F") stu-base.birth-date grade-catalog.grade-name status-code.status-code room-catalog.room-name stu-base.stu-ssn (IF AVAILABLE sped-code THEN sped-code.sped-code ELSE "") stu-year.sped-fte personnel.personnel-code stu-year.stu-fte promotion-path-name.promotion-path-name (IF BldgBuff.has-houses THEN house.house-code ELSE ""). END. ELSE DO: IF NOT AVAILABLE stu-base THEN DO: CREATE stu-base. ASSIGN stu-base.stu-id = ImportText[2]. END. IF NOT AVAILABLE stu-year THEN DO: CREATE stu-year. ASSIGN stu-year.school-year-id = BldgBuff.school-year-id stu-year.bldg-id = BldgBuff.bldg-id stu-year.stu-seq = stu-base.stu-seq stu-year.stu-id = stu-base.stu-id. END. END. /* Handle defaults */ IF (ImportText[12] = ?) OR (ImportText[12] = "") THEN ImportText[12] = "UNKNOWN". IF (ImportText[17] = ?) OR (ImportText[17] = "") THEN ImportText[17] = "UNKN". IF (ImportText[21] = ?) OR (ImportText[21] = "") THEN ImportText[21] = "UNKN". /* Lookup the grade-catalog */ FIND FIRST grade-catalog OF BldgBuff NO-LOCK WHERE grade-catalog.grade-name = ImportText[15] NO-ERROR. IF NOT AVAILABLE grade-catalog THEN DO: IF NOT AutoCreate THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Unknown grade-catalog code " ImportText[15] ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. CREATE grade-catalog. ASSIGN grade-catalog.school-year-id = BldgBuff.school-year-id grade-catalog.bldg-id = BldgBuff.bldg-id grade-catalog.grade-name = CAPS(ImportText[15]) grade-catalog.description = "<< CREATED BY IMPORTER >>". {&WriteLog} "Created grade-catalog " ImportText[15] ", Please check it out" SKIP. END. /* Handle/Lookup the Promotion Path */ IF (ImportText[23] = ?) OR (ImportText[23] = "") THEN DO: IF BldgBuff.promotion-path-id = ? THEN DO: {&WriteLog} "Building " + BldgBuff.bldg-code + " is missing default promotion path: " SKIP. UNDO ImportLoop, NEXT ImportLoop. END. FIND promotion-path-name OF BldgBuff NO-LOCK. ImportText[23] = promotion-path-name.promotion-path-name. END. /* Lookup the ethnic code */ FIND FIRST ethnic-code NO-LOCK WHERE ethnic-code.ethnic-code = ImportText[12] NO-ERROR. IF NOT AVAILABLE ethnic-code THEN DO: IF NOT AutoCreate THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Unknown ethnic code " ImportText[12] ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. CREATE ethnic-code. ASSIGN ethnic-code.ethnic-code = CAPS(ImportText[12]) ethnic-code.description = "<< CREATED BY IMPORTER >>". {&WriteLog} "Created ethnic code " ImportText[12] ", Please check it out" SKIP. END. /* Lookup the status-code */ FIND FIRST status-code OF YearBuff NO-LOCK WHERE status-code.status-code = ImportText[16] NO-ERROR. IF NOT AVAILABLE status-code THEN DO: IF NOT AutoCreate THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Unknown status code " ImportText[16] ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. CREATE status-code. ASSIGN status-code.school-year-id = BldgBuff.school-year-id status-code.status-code = CAPS(ImportText[16]) status-code.description = "<< CREATED BY IMPORTER >>". {&WriteLog} "Created status-code " ImportText[16] ", Please check it out" SKIP. END. /* Lookup the room-catalog */ FIND FIRST room-catalog OF BldgBuff NO-LOCK WHERE room-catalog.room-name = ImportText[17] NO-ERROR. IF NOT AVAILABLE room-catalog THEN DO: IF NOT AutoCreate THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Unknown room code " ImportText[17] ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. CREATE room-catalog. ASSIGN room-catalog.school-year-id = BldgBuff.school-year-id room-catalog.bldg-id = BldgBuff.bldg-id room-catalog.room-name = CAPS(ImportText[17]) room-catalog.description = "<< CREATED BY IMPORTER >>". {&WriteLog} "Created room " ImportText[17] ", Please check it out" SKIP. END. /* Handle optional SPED code */ IF (ImportText[19] <> "") AND (ImportText[19] <> ?) THEN DO: /* Lookup the sped-code */ FIND FIRST sped-code NO-LOCK WHERE sped-code.sped-code = ImportText[19] NO-ERROR. IF NOT AVAILABLE sped-code THEN DO: IF NOT AutoCreate THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Unknown SPED code " ImportText[19] ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. CREATE sped-code. ASSIGN sped-code.sped-code = CAPS(ImportText[19]) sped-code.description = "<< CREATED BY IMPORTER >>". {&WriteLog} "Created SPED code " ImportText[19] ", Please check it out" SKIP. END. END. ELSE FIND sped-code WHERE RECID(sped-code) = ? NO-ERROR. /* Make sure Sped FTE is not greater than Stu FTE */ IF (ImportText[22] <> "") AND (ImportText[22] <> ?) THEN /* If Sped FTE is greater than Stu FTE cap it at Stu FTE and Write a messge in the log */ IF DECIMAL(ImportText[20]) > DECIMAL(ImportText[22]) THEN DO: ImportText[20] = ImportText[22]. ErrorCnt = ErrorCnt + 1. {&WriteLog} "SPED FTE greater than Student FTE, SPED FTE capped at Student FTE" SKIP. END. /* Lookup the promotion-path-name */ FIND FIRST promotion-path-name OF YearBuff NO-LOCK WHERE promotion-path-name.promotion-path-name = ImportText[23] NO-ERROR. IF NOT AVAILABLE promotion-path-name THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Unknown promotion path " ImportText[23] ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Make sure the promotion path selected has the students grade */ FIND FIRST promotion-path-grade OF promotion-path-name NO-LOCK WHERE promotion-path-grade.bldg-id = grade-catalog.bldg-id AND promotion-path-grade.grade-id = grade-catalog.grade-id NO-ERROR. IF NOT AVAILABLE promotion-path-grade THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Student grade " grade-catalog.grade-name " is not in promotion path " promotion-path-name.promotion-path-name ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Optional house lookup */ IF BldgBuff.has-houses THEN DO: /* Lookup the house */ FIND FIRST house OF BldgBuff NO-LOCK WHERE house.house-code = ImportText[24] NO-ERROR. IF NOT AVAILABLE house THEN DO: IF NOT AutoCreate THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Unknown house code " ImportText[24] ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. CREATE house. ASSIGN house.school-year-id = BldgBuff.school-year-id house.bldg-id = BldgBuff.bldg-id house.house-code = CAPS(ImportText[24]) house.description = "<< CREATED BY IMPORTER >>". {&WriteLog} "Created house " ImportText[24] ", Please check it out" SKIP. END. END. /* Lookup counselor */ FIND FIRST personnel OF YearBuff NO-LOCK WHERE personnel.personnel-code = ImportText[21] NO-ERROR. IF NOT AVAILABLE personnel THEN DO: IF NOT AutoCreate THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Personnel code " ImportText[21] " is not on file, student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Get the personnel class */ FIND FIRST personnel-class WHERE personnel-class.school-year-id = BldgBuff.school-year-id AND personnel-class.personnel-class-code = "TEACHER" NO-LOCK NO-ERROR. IF NOT AVAILABLE personnel-class THEN FIND FIRST personnel-class WHERE personnel-class.school-year-id = BldgBuff.school-year-id NO-LOCK NO-ERROR. IF NOT AVAILABLE personnel-class THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "No personnel class codes on file - student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Create a record for the teacher */ CREATE personnel. ASSIGN personnel.fte = 1 personnel.known-as = "" personnel.name = personnel.known-as personnel.personnel-code = ImportText[21] personnel.school-year-id = BldgBuff.school-year-id personnel.personnel-class-id = personnel-class.personnel-class-id. /* Load a department up */ FIND FIRST department OF BldgBuff NO-LOCK NO-ERROR. IF NOT AVAILABLE department THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "No department codes on file - student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Load a house */ IF BldgBuff.has-houses THEN DO: FIND FIRST house OF BldgBuff NO-LOCK NO-ERROR. IF NOT AVAILABLE house THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "No house codes on file - student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. END. /* Create an entry for the building */ CREATE personnel-bldg. ASSIGN personnel-bldg.school-year-id = BldgBuff.school-year-id personnel-bldg.bldg-id = BldgBuff.bldg-id personnel-bldg.personnel-class-id = personnel-class.personnel-class-id personnel-bldg.personnel-id = personnel.personnel-id personnel-bldg.dept-id = department.dept-id. {&WriteLog} "Created personnel (counselor) " + ImportText[21] + ", Please check it out" SKIP. END. /* See if the person is assigned to the same building as the room */ FIND FIRST personnel-bldg OF BldgBuff NO-LOCK WHERE personnel-bldg.personnel-id = personnel.personnel-id NO-ERROR. IF NOT AVAILABLE personnel-bldg THEN DO: IF NOT AutoCreate THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "personnel code " ImportText[21] " not assigned to this building, student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Load a deartment up */ FIND FIRST department OF BldgBuff NO-LOCK NO-ERROR. IF NOT AVAILABLE department THEN DO: {&WriteLog} "Unable to load a department for building " BldgBuff.bldg-code ", student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Associate the person and building */ CREATE personnel-bldg. ASSIGN personnel-bldg.school-year-id = BldgBuff.school-year-id personnel-bldg.bldg-id = BldgBuff.bldg-id personnel-bldg.dept-id = department.dept-id personnel-bldg.personnel-id = personnel.personnel-id personnel-bldg.fte = personnel.fte personnel-bldg.personnel-class-id = personnel.personnel-class-id. /* Handle a house, if needed */ IF BldgBuff.has-houses THEN DO: FIND FIRST house OF BldgBuff NO-LOCK NO-ERROR. IF AVAILABLE house THEN personnel-bldg.house-id = house.house-id. END. END. /* Fix up the phone # */ IF LENGTH(ImportText[10]) = 7 THEN ImportText[10] = " " + ImportText[10]. /* See if we need to create a stu-year record */ IF NOT CAN-FIND(FIRST stu-year OF YearBuff WHERE stu-year.stu-seq = stu-base.stu-seq) THEN CREATE stu-year. /* Make it stick */ ASSIGN stu-base.stu-name = ImportText[3] stu-base.stu-street-num = ImportText[4] stu-base.stu-street = ImportText[5] stu-base.stu-street-apt = ImportText[6] stu-base.stu-city = ImportText[7] stu-base.stu-state = ImportText[8] stu-base.stu-zip = ImportText[9] stu-base.stu-phone = ImportText[10] stu-base.unlisted-phone = ImportText[11] BEGINS "Y" stu-base.ethnic-code-id = ethnic-code.ethnic-code-id stu-base.gender = ImportText[13] BEGINS "M" stu-base.birth-date = DATE(ImportText[14]) stu-year.school-year-id = BldgBuff.school-year-id stu-year.bldg-id = BldgBuff.bldg-id stu-year.stu-seq = stu-base.stu-seq stu-year.stu-id = stu-base.stu-id stu-year.stu-name = stu-base.stu-name stu-year.grade-id = grade-catalog.grade-id stu-year.status-code-id = status-code.status-code-id stu-year.room-id = room-catalog.room-id stu-base.stu-ssn = ImportText[18] stu-year.sped-code-id = (IF AVAILABLE sped-code THEN sped-code.sped-code-id ELSE ?) stu-year.personnel-id = personnel.personnel-id stu-year.stu-fte = DECIMAL(ImportText[22]) stu-year.sped-fte = DECIMAL(ImportText[20]) stu-year.promotion-path-id = promotion-path-name.promotion-path-id stu-year.house-id = (IF BldgBuff.has-houses THEN house.house-id ELSE ?) NO-ERROR. /* Check for errors */ IF ERROR-STATUS:ERROR THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Errors importing/converting student data, student NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Purge any outdated student history */ FOR EACH stu-history OF stu-year: DELETE stu-history. END. /* Lookup the history code */ FIND history-code WHERE history-code.history-code = "IMPORTED" NO-LOCK NO-ERROR. IF NOT AVAILABLE history-code THEN DO: CREATE history-code. ASSIGN history-code.history-code = "IMPORTED" history-code.description = "Initial Student Importation from 'old' system". {&WriteLog} "Created history code IMPORTED, please check it!" SKIP. END. /* Create a new history event */ CREATE stu-history. ASSIGN stu-history.school-year-id = stu-year.school-year-id stu-history.stu-seq = stu-year.stu-seq stu-history.history-date = ImportDate stu-history.history-code-id = history-code.history-code-id stu-history.comments = "Initial importation of records". /* Insert it into the history */ {histutil.i CREATE EVENT stu-history CreateOK} IF NOT CreateOK THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "HISTUTIL failed to record the history event, NOT imported" SKIP. UNDO ImportLoop, NEXT ImportLoop. END. /* Proof the carrier route */ IF spm-prof.use-carrier-route THEN DO: {addrutil.i LOOKUP stu-base.stu-street-num stu-base.stu-street stu-base.stu-city stu-base.stu-state stu-base.stu-zip stu-base.carrier-route-id} IF stu-base.carrier-route = ? THEN DO: ErrorCnt = ErrorCnt + 1. {&WriteLog} "Student address not in carrier route file" SKIP. END. END. END. /* Final statistics update */ DISPLAY LineCnt (LineCnt / TotalLineCnt) * 100 @ PercentDone LineCnt / (TIME - StartTime) @ LinesPerSec ErrorCnt STRING(TIME - StartTime, "HH:MM:SS") @ Elapsed STRING(INTEGER((TotalLineCnt - LineCnt) / (LineCnt / (TIME - StartTime))), "HH:MM:SS") @ TimeRemain WITH FRAME StatusFrame. /* Close the input & log streams */ INPUT STREAM ImportStream CLOSE. OUTPUT STREAM LogStream CLOSE. OUTPUT STREAM ExportStream CLOSE. /* Shut down histutil */ {histutil.i CLEAN_UP} /* We are done */ {safe-msg.i "'Import Complete'"} RETURN.