/////////////////////////////////////////////////////////////////////////////
// fixsstip.sqc
// This script fixes problems with employees tips going into the 
// social security wages (box 3) in addition to the social security
// tips (box 7).  There was a bug in V5.00.0 that would create an
// extra emplbuck to put the tips into box 3 as well as box 7.
//
// This script will be run as part of the autodetect feature.
// This script will remove the amount from the wb_total (so the total
// will be right on the w2 box 3 field (can be seen in report or in
// user interface.  It will also remove the emplbuck so that tips
// will no longer be added into box 3.
/////////////////////////////////////////////////////////////////////////////

// Can't do version checking because would need match
// 5.00.0 and up

// Update the w2 total for box 3 to no longer include the tips.
update w2detvw set wb_total = wb_total - eb_total where
  wx_box = 'Box 3' and eb_type = 1 and eb_dtoid in
    (select eb_dtoid from w2detvw where 
      wx_box = 'Box 7' and eb_type = 1);

// Remove the emplbuck so tips will not be included in any future paychecks.
delete from emplbuck where eb_oid in 
  (select eb_oid from w2detvw where 
    wx_box = 'Box 3' and eb_type = 1 and eb_dtoid in
      (select eb_dtoid from w2detvw where 
        wx_box = 'Box 7' and eb_type = 1));

COMMIT;