00001  def new global shared var prog-started as log.
00002  def new global shared var u-name as char.
00003  
00004  def shared var screen-title as char.
00005  
00006  def shared var total-floor-no as int init 4.
00007  def shared var room-types as char extent 5.
00008  
00009  def shared var res-state as char extent 4.
00010  def shared var res-state-ch as char extent 4.
00011  
00012  def shared var res-state-placed as int init 1.
00013  def shared var res-state-canceled as int init 2.
00014  def shared var res-state-checked-in as int init 3.
00015  def shared var res-state-checked-out as int init 4.
00016  
00017  prog-started = true. 
00018  def var h-time as char.
00019  
00020  form u-name view-as text
00021       screen-title view-as text
00022       h-time view-as text
00023       with frame f-main-header size 80 by 1 no-box no-underline no-labels at row 1 col 1.
00024   
00025  
00026  screen-title = "Check Out".
00027  
00028  def var sprog as char init ?.
00029  def var selection as char init ?.
00030  
00031  def buffer b-checkout for checkout.
00032  def buffer b-out-room for checkout-rooms.
00033  def buffer b-room for room.
00034  def buffer b-guest for guest.
00035  def buffer b-res for reservation.
00036  
00037  def var r-id like reservation.reservation-id.
00038  def var r-discount like reservation.discount.
00039  def var r-checkin like reservation.checkin.
00040  def var r-checkout like reservation.checkout.
00041  def var r-days as char format "x(7)".
00042  def var r-tguests as char format "x(10)".
00043  def var c-charges like checkout.room-charges.
00044  def var c-salestax like checkout.sales-tax.
00045  def var c-total like checkout.total.
00046  def var cr-guest-ids like checkout-room.guest-ids.
00047  def var cr-guest-names as char extent 4 format "x(20)".
00048  def var cr-minibar like checkout-room.minibar-charges.
00049  def var cr-laundry like checkout-room.laundry-charges.
00050  def var cr-charges like checkout-room.room-charges.
00051  def var cr-total like  checkout-room.room-charges label "Total".
00052  
00053  form r-id space(3) r-checkin r-checkout skip
00054       space(60) r-days no-label r-tguests no-label
00055       with frame f-checkout title "Checkout" size 80 by 20 side-labels at row 2 col 1.
00056       
00057  form c-charges at row 1 col 15 colon-aligned 
00058       r-discount at row 2 col 15 colon-aligned
00059       c-salestax at row 3 col 15 colon-aligned
00060       c-total at row 4 col 15 colon-aligned 
00061       with frame f-charges title "Total" side-labels.
00062       
00063  frame f-charges:frame = frame f-checkout:handle.
00064  frame f-charges:row = 4.
00065  frame f-charges:col = 1.
00066  
00067  form cr-minibar at row 1 col 16 colon-aligned skip
00068       cr-laundry at row 2 col 16 colon-aligned  skip
00069       cr-charges at row 3 col 16 colon-aligned  skip
00070       cr-total at row 4 col 16 colon-aligned  skip(2)
00071       "-------------Guests-----------" at row 5 col 1 view-as text skip
00072       cr-guest-ids[1] no-label space(1) cr-guest-names[1] no-label skip
00073       cr-guest-ids[2] no-label space(1) cr-guest-names[2] no-label skip
00074       cr-guest-ids[3] no-label space(1) cr-guest-names[3] no-label skip
00075       cr-guest-ids[4] no-label space(1) cr-guest-names[4] no-label
00076       with frame f-room title "Room" side-labels.
00077       
00078  frame f-room:frame = frame f-checkout:handle.
00079  frame f-room:row = 4.
00080  frame f-room:col = frame f-checkout:width-chars - frame f-room:width-chars - 2.
00081  
00082  def query q-checkout for checkout, reservation scrolling.
00083  open query q-checkout
00084     for each checkout no-lock,
00085         each reservation
00086           where reservation.reservation-id = checkout.reservation-id and
00087                 /* reservation.checkout >= today and reservation.checkin <= today and */
00088                  (checkout.state = 'I' or checkout.state = "O") no-lock use-index idx-r-id.
00089  def query q-room for checkout-room scrolling. 
00090  
00091  
00092  procedure open-q-room.
00093     open query q-room 
00094        for each checkout-room
00095           where checkout-room.reservation-id = checkout.reservation-id no-lock use-index idx-rc-room.
00096     get first q-room.
00097  end.
00098  
00099  procedure refresh.
00100     if not avail checkout-room then do:
00101        clear frame f-checkout all.
00102        clear frame f-charges all.
00103        clear frame f-room all.
00104        
00105        return.
00106     end.
00107     
00108     r-id = reservation.reservation-id.
00109     r-discount = reservation.discount.
00110     r-checkin = reservation.checkin.
00111     r-checkout = reservation.checkout.
00112     r-days = string(reservation.checkout - reservation.checkin) + " Days".
00113     
00114     def var t-guests as int.
00115     t-guests = 0.
00116     
00117     for each b-out-room where b-out-room.reservation-id = reservation.reservation-id:
00118        def var tid as int.
00119        do tid = 1 to extent(b-out-room.guest-ids):
00120           if b-out-room.guest-ids[tid] <> ? and b-out-room.guest-ids[tid] <> 0
00121              then t-guests = t-guests + 1.
00122        end.
00123     end.
00124     
00125     r-tguests = string(t-guests) + " Guests".
00126  
00127     c-charges = checkout.room-charges.
00128     c-salestax = checkout.sales-tax.
00129     c-total = checkout.total.
00130     
00131     cr-minibar = 0.
00132     cr-laundry = 0.
00133     cr-charges = 0.
00134     cr-guest-ids = ?.
00135     cr-guest-names = "".
00136     
00137     if avail checkout-room then do:
00138        find room where room.room-number = checkout-room.room-number.
00139        
00140        frame f-room:title = "[" + room-types[room.type-of-room] + "] - " + string(room.room-number).
00141        
00142        cr-minibar = checkout-room.minibar-charges.
00143        cr-laundry = checkout-room.laundry-charges.
00144        cr-charges = checkout-room.room-charges.
00145        cr-guest-ids = checkout-room.guest-ids.
00146        
00147        def var gid as int.
00148        do gid = 1 to extent(cr-guest-ids):
00149           find first guest where guest.guest-id = cr-guest-ids[gid] no-lock no-error.
00150           if avail guest then do:
00151              cr-guest-names[gid] = guest.last-name + ", " + guest.first-name.
00152           end.
00153        end.
00154     end.
00155     
00156     cr-total = cr-minibar + cr-laundry + cr-charges.
00157     
00158     display r-id r-checkin r-checkout r-days r-tguests with frame f-checkout.
00159     display c-charges r-discount c-salestax c-total with frame f-charges.
00160     display cr-minibar
00161             cr-laundry
00162             cr-charges
00163             cr-total
00164             cr-guest-ids[1] when can-find(guest where guest.guest-id = cr-guest-ids[1])
00165             cr-guest-names[1] when can-find(guest where guest.guest-id = cr-guest-ids[1])
00166             cr-guest-ids[2] when can-find(guest where guest.guest-id = cr-guest-ids[2]) 
00167             cr-guest-names[2] when can-find(guest where guest.guest-id = cr-guest-ids[2])
00168             cr-guest-ids[3] when can-find(guest where guest.guest-id = cr-guest-ids[3])
00169             cr-guest-names[3] when can-find(guest where guest.guest-id = cr-guest-ids[3])
00170             cr-guest-ids[4] when can-find(guest where guest.guest-id = cr-guest-ids[4]) 
00171             cr-guest-names[4] when can-find(guest where guest.guest-id = cr-guest-ids[4])
00172          with frame f-room.
00173  end.
00174  
00175  get first q-checkout.
00176  run open-q-room.
00177  run refresh.
00178  
00179  PROC:
00180  repeat:
00181     if u-name = ? or u-name = "" then do:
00182     message "You are not logged in - access denied" view-as alert-box.
00183     quit.
00184  end.
00185  
00186  h-time = string(now, "99/99/99 HH:MM:SS").
00187  h-time = substring(h-time, 10).
00188  
00189  do with frame f-main-header:
00190     u-name:column = 1.
00191     screen-title:column = u-name:column + length(u-name) + (frame f-main-header:width-chars - length(u-name) - length(screen-title) - length(h-time)) / 2.
00192     h-time:column = frame f-main-header:width-chars - length(h-time).
00193     screen-title:format = "x(" + string(length(screen-title)) + ")".
00194  end.
00195  
00196  display u-name screen-title h-time with frame f-main-header.
00197   
00198     
00199     sprog = ?.
00200     case selection:
00201        when "P" then do:
00202           get prev q-checkout.
00203           if not avail checkout then do:
00204              get first q-checkout.
00205           end.
00206  
00207           run open-q-room.
00208           run refresh.
00209        end.
00210        when "N" then do:
00211           get next q-checkout.
00212           if not avail checkout then do:
00213              get last q-checkout.
00214           end.
00215  
00216           run open-q-room.
00217           run refresh.
00218        end.
00219        when "F" then do:
00220           get first q-checkout.
00221           run open-q-room.
00222           run refresh.
00223        end.
00224        when "L" then do:
00225           get last q-checkout.
00226           run open-q-room.
00227           run refresh.
00228        end.
00229        when "I" then do:
00230           r-id = ?.
00231           def var f-room-id like room.room-number.
00232           f-room-id = ?.
00233        
00234           /* find by name, date of birth */
00235           def button btn-ok label "Find".
00236           def button btn-cancel label "Cancel".
00237           
00238           def var g-room like room.room-number.
00239           def var g-f-n like guest.first-name.
00240           def var g-l-n like guest.last-name.
00241           
00242           form g-room skip
00243                g-f-n skip
00244                g-l-n skip
00245                btn-ok
00246                btn-cancel
00247                with frame f-checkout-search side-labels overlay at row 2 col 1 title "Find Reservation"
00248                     cancel-button btn-cancel default-button btn-ok.
00249  
00250           on "choose" of btn-cancel in frame f-checkout-search do:
00251              apply "f4" to frame f-checkout-search.
00252           end.
00253           on "choose" of btn-ok in frame f-checkout-search do:
00254              apply "go" to frame f-checkout-search.
00255           end.
00256  
00257           /* FIND: by room number, guest first/last name*/
00258           G-SEARCH:
00259           repeat on endkey undo, leave:
00260              
00261              g-room = 0.
00262              g-f-n = "".
00263              g-l-n = "".
00264              update g-room g-f-n g-l-n btn-ok btn-cancel with frame f-checkout-search.
00265              
00266              if g-f-n = "" and g-l-n = "" and (g-room = 0 or g-room = ?)
00267              then do:
00268                 message "Enter at least one search criteria!".
00269                 next g-search.
00270              end.
00271              
00272              if g-room > 0 then do:
00273                 find first b-out-room where b-out-room.room-number = g-room no-lock no-error.
00274                 if not avail b-out-room then do:
00275                    message "No guests are in room " + string(g-room) + "!" view-as alert-box.
00276                    next G-SEARCH.
00277                 end.
00278                 
00279                 f-room-id = g-room.
00280                 r-id = b-out-room.reservation-id.
00281                 leave G-SEARCH.
00282              end.
00283        
00284              for each b-guest 
00285                 where (if g-f-n = ? or g-f-n = "" then true else b-guest.first-name matches g-f-n + "*") and 
00286                       (if g-l-n = ? or g-l-n = "" then true else b-guest.last-name matches g-l-n + "*") no-lock,
00287                  each b-res where b-res.checkout >= today use-index idx-r-checkin no-lock,
00288                  each b-out-room where b-out-room.reservation-id = b-res.reservation-id and
00289                       (b-out-room.guest-ids[1] = b-guest.guest-id or
00290                        b-out-room.guest-ids[2] = b-guest.guest-id or
00291                        b-out-room.guest-ids[3] = b-guest.guest-id or
00292                        b-out-room.guest-ids[4] = b-guest.guest-id) no-lock:
00293                  
00294                  f-room-id = b-out-room.room-number.
00295                  r-id = b-res.reservation-id.
00296                  leave G-SEARCH.
00297              end.
00298              
00299              message "No guests found with this criteria!" view-as alert-box.
00300           end.
00301           hide frame f-checkout-search no-pause.
00302           
00303           if r-id <> ? then do:
00304              find checkout where checkout.reservation-id = r-id no-lock.
00305              find reservation where reservation.reservation-id = r-id no-lock.
00306              reposition q-checkout to rowid rowid(checkout), rowid(reservation).
00307              get next q-checkout.
00308  
00309              run open-q-room.
00310              find checkout-room where checkout-room.reservation-id = r-id and checkout-room.room-number = f-room-id no-lock.
00311              reposition q-room to rowid rowid(checkout-room).
00312              get next q-room.
00313              run refresh.
00314           end.
00315        end.
00316        when "K" then do:
00317           if not avail reservation then leave.
00318           
00319           do transaction on endkey undo, leave:
00320              for each b-out-room where b-out-room.reservation-id = reservation.reservation-id:
00321                 
00322                 find b-room where b-room.room-number = b-out-room.room-number.
00323                 
00324                 frame f-room:title = "[" + room-types[b-room.type-of-room] + "] - " + string(b-room.room-number).
00325                 
00326                 update cr-minibar cr-laundry with frame f-room.
00327                 
00328                 b-out-room.minibar-charges = cr-minibar.
00329                 b-out-room.laundry-charges = cr-laundry.
00330              end.
00331  
00332              find b-checkout where recid(b-checkout) = recid(checkout) exclusive-lock.
00333              b-checkout.room-charges = 0.
00334              for each b-out-room where b-out-room.reservation-id = reservation.reservation-id:
00335                 b-checkout.room-charges = b-checkout.room-charges + b-out-room.minibar-charges + b-out-room.laundry-charges + b-out-room.room-charges. 
00336              end.
00337  
00338              b-checkout.sales-tax = b-checkout.room-charges * 0.19.
00339              b-checkout.total = b-checkout.room-charges * ((100.0 - reservation.discount) / 100.0) + b-checkout.sales-tax.
00340           end.
00341           
00342           find current checkout.
00343           find current room.
00344           
00345           run refresh.
00346        end.
00347        when "1" then do:
00348           get prev q-room. 
00349           if not avail checkout-room then do:
00350              get first q-room.
00351           end.
00352           
00353           run refresh.
00354        end.
00355        when "2" then do:
00356           get next q-room. 
00357           if not avail checkout-room then do:
00358              get last q-room.
00359           end.
00360           
00361           run refresh.
00362        end.
00363        
00364        when "R" then do:
00365           publish "pop-program".
00366           leave PROC.
00367        end.
00368        otherwise do:
00369           if selection <> ? then do:
00370              message "Invalid selection - try again".
00371              selection = ?.
00372              pause.
00373              next. 
00374           end.
00375        end.
00376     end.
00377  
00378     if sprog <> ? then leave PROC.
00379  
00380        selection = "R". /* assume we are returning; otherwise the user entered something valid */
00381  
00382     CHOICE: 
00383     repeat on endkey undo CHOICE, leave CHOICE:
00384        hide message no-pause.
00385        message "(P)rev   (N)ext   (F)irst   (L)ast".
00386        message "F(i)nd   Chec(k) out   (1) Next Room   (2) Prev Room   (R)eturn" update selection format "x(1)" auto-return.
00387  
00388        selection = caps(selection).
00389        leave.
00390     end.
00391   
00392  end.
00393  
00394  if sprog <> ? then do:
00395     publish "push-program" (sprog).
00396  end.