Advertisement
Guest User

Untitled

a guest
May 29th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1.     /*
  2.      * Get all applicants with expired or soon-to-be expired cards
  3.      * Assumptions:
  4.      *      * 5 year expiry date cannot be relyed upon for
  5.      *        citizens/applicants younger than 16 -- will need to be
  6.      *        checked separately
  7.      *
  8.      *      * citizens older than 16 may not have renewed their cards
  9.      *        when they expired at 15
  10.      */
  11.     $sql2 = <<<QUER
  12.     SELECT c_id, c_first_name, c_last_name, c_citizenship_id,
  13.         c_process_action, region_name, ci_card_type, ci_datetime,
  14.         expiry_date, age
  15.     FROM
  16.         (SELECT c_id, c_first_name, c_last_name, c_citizenship_id,
  17.         c_process_action, c_region_id, ci_card_type, ci_received_type,
  18.         c_renew_notic_0_6, c_renew_notic_6_10, c_renew_notic_11_15,
  19.         c_renew_notic_older_0_6, DATE(ci_datetime) ci_datetime,
  20.         IF(YEAR(ci_datetime) <=2004,
  21.             DATE_ADD(DATE(ci_datetime), INTERVAL $renewal_interval YEAR),
  22.             IF(DATE_ADD(DATE(ci_datetime), INTERVAL $renewal_interval YEAR) >
  23.                 DATE_ADD(
  24.                     DATE_SUB(c_date_of_birth,
  25.                         INTERVAL YEAR(c_date_of_birth) YEAR),
  26.                     INTERVAL YEAR(DATE_ADD(ci_datetime, INTERVAL $renewal_interval YEAR))
  27.                     YEAR),
  28.                          
  29.                 DATE_ADD(
  30.                     DATE_SUB(c_date_of_birth,
  31.                         INTERVAL YEAR(c_date_of_birth) YEAR),
  32.                     INTERVAL YEAR(DATE_ADD(ci_datetime, INTERVAL $intervalPlus YEAR))
  33.                     YEAR),
  34.                
  35.                 DATE_ADD(
  36.                     DATE_SUB(c_date_of_birth,
  37.                         INTERVAL YEAR(c_date_of_birth) YEAR),
  38.                         INTERVAL YEAR(
  39.                             DATE_ADD(ci_datetime, INTERVAL $renewal_interval YEAR))YEAR))
  40.         ) as expiry_date,
  41.         (DATE_FORMAT(Now(), '%Y') -
  42.             DATE_FORMAT(c_date_of_birth, '%Y') -
  43.             (DATE_FORMAT(Now(), '00-%m-%d') <
  44.                 DATE_FORMAT(c_date_of_birth, '00-%m-%d')) ) as age
  45.         FROM citizenship
  46.             JOIN card_issued ON card_issued.ci_c_id=citizenship.c_id
  47.         WHERE (c_process_action='Citizen'
  48.             OR c_process_action='Approved')
  49.             AND c_deceased='No' AND c_moved_out_of_province='No') as citizenship
  50.         JOIN region ON region.region_id=citizenship.c_region_id
  51.         WHERE ($renewal_condition OR age < 16
  52.             OR (age >=16 AND NOT EXISTS (SELECT c2.ci_id
  53.                 FROM card_issued c2
  54.                 WHERE c2.ci_card_type="Adult 16 up")))
  55.             AND c_renew_notic_0_6='No' AND c_renew_notic_6_10='No'
  56.             AND c_renew_notic_11_15='No' AND c_renew_notic_older_0_6='No'
  57.             AND ci_received_type='Correct'
  58.         ORDER BY age, c_last_name, c_first_name, ci_datetime DESC
  59. QUER
  60. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement