PageRenderTime 66ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/src/azora.local/prms/shlrsvc_pointexpiration.php

https://gitlab.com/nvtdn2006/azora
PHP | 136 lines | 94 code | 36 blank | 6 comment | 15 complexity | 924f148ea95208e5335c48666ae2e07c MD5 | raw file
  1. <?php
  2. /*
  3. * 05-04-2013 FX.1304.002 Read Default CC email
  4. */
  5. require_once './includes/service.php';
  6. ?>
  7. <?php
  8. $return = array();
  9. $return['status'] = true;
  10. $return['message'] = 'Process done.';
  11. $manual = false;
  12. $config = Factory::getConfig(); //FX.1304.002
  13. try {
  14. if (isset($_GET['m']) && $_GET['m'] == 1) {
  15. $manual = true;
  16. }
  17. DomainManager::getInstance()->load('Reward');
  18. $rewardObj = new Reward();
  19. DomainManager::getInstance()->load('Company');
  20. $companyObj = new Company();
  21. $company = $companyObj->getCompany();
  22. $company = $company[0];
  23. $rewards = $rewardObj->getReward();
  24. $expiry_on = null;
  25. if (isset($rewards) && count($rewards) > 0) {
  26. $reward = $rewards[0];
  27. if ($reward['expiration_required'] == 1) {
  28. $expiration_month = $reward['expiration_month'];
  29. DomainManager::getInstance()->load('Customer');
  30. $customerObj = new Customer();
  31. $customers = $customerObj->getCustomerProfileByValues();
  32. foreach ($customers as $customer) {
  33. $customer_id = $customer['customer_id'];
  34. DomainManager::getInstance()->load('Point');
  35. $pointObj = new Point();
  36. $startdate = new DateTime($pointObj->getPointStartedDate($customer_id));
  37. $startdate->modify('+'.$expiration_month.' month');
  38. $today = getdate();
  39. $today = new DateTime(date("Y-m-d", mktime(0,0,0,$today['mon'],$today['mday'],$today['year'])));
  40. if ($startdate < $today) {
  41. $pointdetatils = $pointObj->getPointDetailsByCustomer($customer_id);
  42. $pdTable = '<table border="1">
  43. <thead>
  44. <tr>
  45. <th><b>Branch</b></th>
  46. <th><b>Store</b></th>
  47. <th><b>Accumulated Points</b></th>
  48. <th><b>Last transaction</b></th>
  49. </tr>
  50. </thead>
  51. <tbody>';
  52. foreach($pointdetatils as $detail) {
  53. $pdTable .= '<tr>';
  54. $pdTable .= '<td>'. $detail['branch_name'] .'</td>';
  55. $pdTable .= '<td>'. $detail['store_name'] .'</td>';
  56. $pdTable .= '<td>'. $detail['accumulated_points'] .'</td>';
  57. $pdTable .= '<td>'. $detail['last_transaction'] .'</td>';
  58. $pdTable .= '</tr>';
  59. }
  60. $pdTable .= '</tbody></table>';
  61. if ($pointObj->expiredPoints($customer_id)) {
  62. //Send Mail
  63. $property = array ('name' => $customer['name'],
  64. 'points' => $pdTable,
  65. 'csmail' => $company['company_customersupport_email'],
  66. 'company_name' => $company['company_name']);
  67. $mailer = new SiteMailer();
  68. $mailer->toMail = $customer['email'];
  69. //+START FX.1304.002 Add Default CC email
  70. if (isset($config['PRMSConfig']->PRMS_default_cc_mail)
  71. && $config['PRMSConfig']->PRMS_default_cc_mail != "") {
  72. if (is_array($config['PRMSConfig']->PRMS_default_cc_mail)) {
  73. foreach ( $config['PRMSConfig']->PRMS_default_cc_mail as $ccMail) {
  74. $mailer->AddCc($ccMail);
  75. }
  76. } else {
  77. $mailer->AddCc($config['PRMSConfig']->PRMS_default_cc_mail);
  78. }
  79. }
  80. //-END FX.1304.002
  81. $mailer->subject = 'Your reward points have been expired at '.$company['company_name'].' redemption website';
  82. $mailer->PrepareMail('sendPointshavebeenexpired', $property);
  83. $mailer->Send();
  84. }
  85. }
  86. }
  87. }
  88. }
  89. } catch(PDOException $e) {
  90. $return['status'] = false;
  91. }
  92. $log = array( 'scheduler_name' => 'Point expiration',
  93. 'status' => $return['status'],
  94. 'is_manual' => $manual);
  95. SchedulerLog::Log($log);
  96. if ($manual) {
  97. header('Content-type: application/json');
  98. echo json_encode($return);
  99. }
  100. ?>