PageRenderTime 24ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/azora.local/prms/redemptiondetail.php

https://gitlab.com/nvtdn2006/azora
PHP | 316 lines | 257 code | 56 blank | 3 comment | 32 complexity | 4ccd94fc34a39943c267fbb40b040996 MD5 | raw file
  1. <?php require_once './includes/application.php'; $this->template = ''; $this->title = 'Redemption Detail'?>
  2. <?php
  3. JSManager::getInstance()->add('jquery');
  4. JSManager::getInstance()->add('validation');
  5. DomainManager::getInstance()->load('Redemption');
  6. $redemptionObj = new Redemption();
  7. DomainManager::getInstance()->load('Company');
  8. $companyObj = new Company();
  9. $company = $companyObj->getCompany();
  10. $company = $company[0];
  11. $error = array();
  12. $config = Factory::getConfig();
  13. $readonly = true;
  14. $redemption_id = 0;
  15. if(isset($_POST['redemption_id']) && $_POST['redemption_id'] > 0) {
  16. if(isset($_POST['status']) && $_POST['status'] == 2) {
  17. $update = array('redemption_id' => $_POST['redemption_id'],
  18. 'redemption_status' => $_POST['status'],
  19. 'updated_remarks' => $_POST['remarks'],
  20. 'updated_by' => Authentication::getUserId());
  21. if ($redemptionObj->updateRedemptionStatus($update)) {
  22. $redemption = $redemptionObj->getRedemption($_POST['redemption_id']);
  23. //Event Log
  24. $evtObj = new EventObject();
  25. $evtObj->event_id = EventTypes::PRMS_UpdateRedemptionStatus;
  26. $evtObj->description = Authentication::getAttribute('login_id') . ' updated redemption status (Collected) for no. '.$redemption['redemption']['redemption_no'].' submitted by ('.$redemption['redemption']['nric'].') on ('.$redemption['redemption']['transaction_dt'].').';
  27. $evtObj->action_by = Authentication::getAttribute('login_id');
  28. EventLog::Log($evtObj);
  29. header( 'Location: redemptiondone.php?id='.$_POST['redemption_id']);
  30. exit();
  31. } else {
  32. array_push($error, 'Saving process failed. Please try again.');
  33. }
  34. } else if (isset($_POST['status']) && $_POST['status'] == 4) {
  35. $update = array('redemption_id' => $_POST['redemption_id'],
  36. 'redemption_status' => $_POST['status'],
  37. 'updated_remarks' => $_POST['remarks'],
  38. 'updated_by' => Authentication::getUserId());
  39. if ($redemptionObj->updateRedemptionStatus($update)) {
  40. $redemption = $redemptionObj->getRedemption($_POST['redemption_id']);
  41. //Event Log
  42. $evtObj = new EventObject();
  43. $evtObj->event_id = EventTypes::PRMS_UpdateRedemptionStatus;
  44. $evtObj->description = Authentication::getAttribute('login_id') . ' updated redemption status (Cancelled) for no. '.$redemption['redemption']['redemption_no'].' submitted by ('.$redemption['redemption']['nric'].') on ('.$redemption['redemption']['transaction_dt'].').';
  45. $evtObj->action_by = Authentication::getAttribute('login_id');
  46. EventLog::Log($evtObj);
  47. require_once './includes/user.php';
  48. $userObj = new User();
  49. $users = $userObj->getUserForRedemptionReminder($redemption['redemption']['store_id']);
  50. if (isset($users)) {
  51. foreach($users as $user) {
  52. $property = array ('full_name' => $user['full_name'],
  53. 'company_name' => $company['company_name'],
  54. 'redemption_no' => $redemption['redemption']['redemption_no'],
  55. 'transaction_dt' => $redemption['redemption']['transaction_dt']);
  56. $mailer = new SiteMailer();
  57. $mailer->toMail = $user['email'];
  58. $mailer->subject = 'Reminder for cancelled redemption at '.$company['company_name'].' PRMS';
  59. $mailer->PrepareMail('sendReminderforcancelledredemptionToUser', $property);
  60. $mailer->Send();
  61. }
  62. }
  63. header( 'Location: redemptiondone.php?id='.$_POST['redemption_id']);
  64. exit();
  65. } else {
  66. array_push($error, 'Saving process failed. Please try again.');
  67. }
  68. }
  69. }
  70. if(isset($_GET['id'])) {
  71. //$redemption_id = Factory::getCryptographer()->Decrypt($_GET['id']);
  72. $redemption_id = $_GET['id'];
  73. if(isset($_GET['m'])) {
  74. if (Factory::getCryptographer()->Decrypt($_GET['m']) == 'write')
  75. $readonly = false;
  76. }
  77. $redemption = $redemptionObj->getRedemption($redemption_id);
  78. if ($redemption == null) {
  79. header( 'Location: redemptions.php');
  80. exit();
  81. }
  82. } else {
  83. header( 'Location: redemptions.php');
  84. exit();
  85. }
  86. ?>
  87. <?php
  88. if (isset($error) && count($error) > 0) {
  89. ?>
  90. <div class="error-info">
  91. <?php foreach ($error as $handle) {
  92. echo "<p>$handle</p>";
  93. } ?>
  94. </div>
  95. <?php
  96. }
  97. ?>
  98. <form name="rdetailform" id="rdetailform" action="redemptiondetail.php" method="post">
  99. <table class="formview" width="100%" border="0" cellspacing="3px" cellpadding="3px">
  100. <tr>
  101. <td >NRIC</td>
  102. <td><input type="text" name="nric" id="nric"class="input" value="<?php echo $redemption['redemption']['nric']; ?>" size="20" tabindex="10" disabled /></td>
  103. </tr>
  104. <tr>
  105. <td >Name</td>
  106. <td><input type="text" name="name" id="name"class="input" value="<?php echo $redemption['redemption']['name']; ?>" size="20" tabindex="20" disabled /></td>
  107. </tr>
  108. <tr>
  109. <td class="SectionBar" colspan="2">
  110. Redemption
  111. </td>
  112. </tr>
  113. <tr>
  114. <td >Total redemption points</td>
  115. <td><input type="text" name="t_points" id="t_points"class="input" value="<?php echo $redemption['redemption']['total_points']; ?>" size="20" tabindex="30" disabled /></td>
  116. </tr>
  117. <tr>
  118. <td >Store</td>
  119. <td><input type="text" name="Store" id="Store" class="input" value="<?php echo $redemption['redemption']['store_branch_name']; ?>" size="20" tabindex="40" disabled /></td>
  120. </tr>
  121. <tr>
  122. <td >Date <span class="hint">(DD/MM/YYYY)</span></td>
  123. <td><input type="text" name="date" id="date" class="input " value="<?php echo date('d/m/Y', strtotime($redemption['redemption']['collection_date'])); ?>" size="20" tabindex="50" disabled /></td>
  124. </tr>
  125. <tr>
  126. <td >Time</td>
  127. <td><input type="text" name="Time" id="Time" class="input " value="<?php echo date('h:i A', strtotime($redemption['redemption']['collection_time'])); ?>" size="20" tabindex="60" disabled /></td>
  128. </tr>
  129. <tr>
  130. <td class="SectionBar" colspan="2">
  131. Points
  132. </td>
  133. </tr>
  134. <tr>
  135. <td colspan="2">
  136. <table width="100%" border="0" cellspacing="3px" cellpadding="3px">
  137. <?php
  138. $tpoints = 0;
  139. foreach($redemption['redemption_points'] as $detail) {
  140. ?>
  141. <tr>
  142. <td><?php echo $detail['branch_name']; ?></td>
  143. <td><?php echo $detail['store_name']; ?></td>
  144. <td width="70px"><input type="text" name="points[]" class="input" value="<?php
  145. echo $detail['points'];
  146. ?>" size="20" tabindex="70" style="width:50px" disabled /></td>
  147. </tr>
  148. <?php
  149. $tpoints += $detail['points'];
  150. } ?>
  151. <tr>
  152. <td>&nbsp;</td>
  153. <td><b>Total</b></td>
  154. <td><span id="tpoints"><?php echo $tpoints; ?></span>&nbsp;pts</td>
  155. </tr>
  156. </table>
  157. </td>
  158. </tr>
  159. <tr>
  160. <td class="SectionBar" colspan="2">
  161. Products
  162. </td>
  163. </tr>
  164. <tr>
  165. <td colspan="2">
  166. <table width="100%" border="0" cellspacing="3px" cellpadding="3px">
  167. <tbody>
  168. <?php
  169. foreach($redemption['redemption_products'] as $item) {
  170. DomainManager::getInstance()->load('Product');
  171. $productObj = new Product();
  172. $product = $productObj->getProduct($item['product_id']);
  173. $images = $product['product_images'];
  174. $image = null;
  175. foreach($images as $img) {
  176. if ($img['image_type'] == 'S') {
  177. $image = $img;
  178. }
  179. }
  180. if (!$image) {
  181. foreach($images as $img) {
  182. if ($img['image_type'] == 'T') {
  183. $image = $img;
  184. }
  185. }
  186. }
  187. ?>
  188. <tr>
  189. <td width="60px">
  190. <img src="<?php echo $config['PRMSConfig']->live_site . '/domain/images/products/' . $image['sys_file_name']; ?>" width="50" height="50" alt="<?php echo $product['product']['product_name']; ?>" title="<?php echo $product['product']['product_name']; ?>"/></td>
  191. <td><b><?php echo $product['product']['product_name']; ?></b></td>
  192. <td><?php echo $product['product']['product_description']; ?></td>
  193. <td width="80px">&nbsp;<?php echo number_format($item['product_points']); ?> pts</td>
  194. <td width="50px"><input type="text" name="quantity[]" class="input Required numeric" value="<?php echo $item['quantity'] ?>" size="20" tabindex="80" style="width:30px" disabled /></td>
  195. </tr>
  196. <?php } ?>
  197. </tbody>
  198. </table>
  199. </td>
  200. </tr>
  201. <?php if(!$readonly) { ?>
  202. <tr>
  203. <td class="SectionBar" colspan="2">
  204. Redemption status
  205. </td>
  206. </tr>
  207. <tr>
  208. <td class="LabelCell Required">Status</td>
  209. <td>
  210. <select tabindex="50" name="status" tabindex="90" class="GreaterThanZero">
  211. <option value="2">Collected</option>
  212. <option value="4">Cancelled</option>
  213. </select>
  214. </td>
  215. </tr>
  216. <tr>
  217. <td class="LabelCell">Remarks</td>
  218. <td><input type="text" name="remarks" id="remarks" maxlength="1000" class="input" value="" size="20" tabindex="100" /></td>
  219. </tr>
  220. <?php } else { ?>
  221. <tr>
  222. <td class="SectionBar" colspan="2">
  223. Redemption Status
  224. </td>
  225. </tr>
  226. <tr>
  227. <td>Status</td>
  228. <td><?php echo $redemptionObj->getRedemptionStatus($redemption['redemption']['redemption_status']) ?></td>
  229. </tr>
  230. <tr>
  231. <td>Remark</td>
  232. <td><?php echo $redemption['redemption']['updated_remarks']; ?></td>
  233. </tr>
  234. <tr>
  235. <td>Updated By</td>
  236. <td><?php echo $redemption['redemption']['updated_username']; ?></td>
  237. </tr>
  238. <tr>
  239. <td>Updated On</td>
  240. <td><?php echo isset($redemption['redemption']['updated_dt']) ? date('Y-m-d h:i A', strtotime($redemption['redemption']['updated_dt'])) : ''; ?></td>
  241. </tr>
  242. <?php } ?>
  243. <tr>
  244. <td class="BottomToolBar" colspan="2">
  245. <?php if(!$readonly) { ?>
  246. <input id="redemption_id" name="redemption_id" type="hidden" value="<?php echo $redemption_id; ?>"/>
  247. <input type="submit" name="submit" id="submit" class="button-primary" value="Save" tabindex="110"/>
  248. <a href="redemptions.php" class="button-secondary" tabindex="120">Back</a>
  249. <?php } else { ?>
  250. <a href="redemptionrpt.php" class="button-secondary" tabindex="120">Back</a>
  251. <?php } ?>
  252. </td>
  253. </tr>
  254. </table>
  255. </form>
  256. <script type="text/javascript">
  257. $(document).ready(function() {
  258. loadValidation('rdetailform');
  259. });
  260. </script>