This portal only for GCC Officers. Based on there roles and Group ID they can view there module`s Like PGR, QR Public Asset Feedback, Makkalai Thedi Mayor,etc...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

924 lines
41 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" dir="">
  3. <html xmlns:th="http://www.thymeleaf.org">
  4. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  5. <style>
  6. .required{
  7. color: red;
  8. }
  9. /* Mobile screens - targeting devices with a max width of 767px */
  10. @media (max-width: 767px)
  11. {
  12. #qaqcRequestForm label{
  13. margin-top: 10px;
  14. }
  15. }
  16. .card-box {
  17. box-shadow: rgba(0, 0, 0, 0.5) 0px 3px 8px;
  18. }
  19. .bg-grey-inline-text {
  20. padding:2px 2px;
  21. background-color: #e6e6e6;
  22. border-radius: 4px;
  23. }
  24. </style>
  25. <body>
  26. <!--[if lt IE 8]>
  27. <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
  28. <![endif]-->
  29. <div class="wrapper">
  30. <!-- header top menu Start -->
  31. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  32. <!-- header top menu end -->
  33. <div class="page-wrap">
  34. <!--=============== Left Menu side Start ================-->
  35. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  36. <!--=============== Left side End ================-->
  37. <div class="main-content">
  38. <div class="container-fluid">
  39. <div class="page-header mb-2">
  40. <div class="row align-items-end">
  41. <div class="col-lg-8">
  42. <div class="page-header-title">
  43. <i class="far fa-calendar-plus bg-blue"></i>
  44. <div class="d-inline">
  45. <h5>Assign Agents</h5>
  46. <span>Assign Agents for Task</span>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="col-lg-4">
  51. <nav class="breadcrumb-container" aria-label="breadcrumb">
  52. <ol class="breadcrumb">
  53. <li class="breadcrumb-item"><a href="/gcc/index"><i
  54. class="ik ik-home"></i></a></li>
  55. <li class="breadcrumb-item" aria-current="page">1913 QAQC</li>
  56. <li class="breadcrumb-item" aria-current="page">Admin QAQC</li>
  57. <li class="breadcrumb-item active" aria-current="page">Assign Agents</li>
  58. </ol>
  59. </nav>
  60. </div>
  61. </div>
  62. </div>
  63. <div class="row mt-4">
  64. <div class="col-sm-4 mb-2">
  65. <label for="displaystartDate" class="form-label"
  66. style="font-size: medium; margin-bottom: 0px; font-weight: bold;">From
  67. Date:</label> <input type="date" id="displaystartDate"
  68. class="form-control" >
  69. </div>
  70. <div class="col-sm-4 mb-2">
  71. <label for="displayendDate" class="form-label"
  72. style="font-size: medium; margin-bottom: 0px; font-weight: bold;">To
  73. Date:</label> <input type="date" id="displayendDate"
  74. class="form-control">
  75. </div>
  76. </div>
  77. <div class="row mt-3">
  78. <div class="col-xl-3 col-md-4 col-sm-12">
  79. <div class="card card-box" id="closedCard" style="display: none;">
  80. <p class="text-facebook mb-20 text-center mt-4" id="displayClosename"><b></b></p>
  81. <h2 class="text-twitter fw-700 ml-5 text-center" id="displayClosedcount"></h2>
  82. </div>
  83. <div class="card card-box" id="reopenedCard" style="display: none;">
  84. <p class="text-facebook mb-20 text-center mt-4" id="displayReopenname"><b></b></p>
  85. <h3 class="text-twitter fw-700 ml-5 text-center" id="displayReopenedcount"></h3>
  86. </div>
  87. <div class="card card-box" id="inProgressCard" style="display: none;">
  88. <p class="text-facebook mb-20 text-center mt-4" id="displayInProgressname"><b></b></p>
  89. <h3 class="text-twitter fw-700 ml-5 text-center" id="displayInProgresscount"></h3>
  90. </div>
  91. <div class="card card-box" id="redressedCard" style="display: none;">
  92. <p class="text-facebook mb-20 text-center mt-4" id="displayRedressedname"><b></b></p>
  93. <h3 class="text-twitter fw-700 ml-5 text-center" id="displayRedressedcount"></h3>
  94. </div>
  95. <div class="card card-box" id="followupCard1" style="display: none;">
  96. <p class="text-facebook mb-20 text-center mt-4" id="displayFollowupname1"><b></b></p>
  97. <h3 class="text-twitter fw-700 ml-5 text-center" id="displayfollowupcount1"></h3>
  98. </div>
  99. <div class="card card-box" id="followupCard2" style="display: none;">
  100. <p class="text-facebook mb-20 text-center mt-4" id="displayFollowupname2"><b></b></p>
  101. <h3 class="text-twitter fw-700 ml-5 text-center" id="displayfollowupcount2"></h3>
  102. </div>
  103. <div class="card card-box" id="withdrawCard" style="display: none;">
  104. <p class="text-facebook mb-20 text-center mt-4" id="displaywithdrawname"><b></b></p>
  105. <h3 class="text-twitter fw-700 ml-5 text-center" id="displaywithdrawcount"></h3>
  106. </div>
  107. </div>
  108. </div>
  109. <div class="row">
  110. <div class="col-12">
  111. <div class="card">
  112. <div class="card-block">
  113. <label>Task Description If any</label>
  114. <textarea rows="1" cols="5" style="width: 100%;height:50px;" placeholder="Enter description"></textarea>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="row">
  120. <div class="col-12">
  121. <div class="card">
  122. <div class="card-block">
  123. <div class="row">
  124. <div class=" col-lg-4 col-md-5 col-sm-12">
  125. <label style="font-size: medium;font-weight: bold;">Click this Button to Clear the Pending Calls...</label>
  126. </div>
  127. <div class="col-lg-8 col-md-7 col-sm-12">
  128. <button id="clearButton" class="btn btn-danger">Clear</button>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <div class="row">
  136. <div class="col-12">
  137. <div class="card">
  138. <div class="card-header">
  139. <h3><b>Available Agent List</b></h3>
  140. </div>
  141. <div class="card-body">
  142. <div class="d-flex justify-content-end mb-2">
  143. <button class="btn btn-light mr-4" disabled style="color: blue;border-color: blue;"><i class="ik ik-user-plus f-16" style="color: blue;"></i>Productivity Count:<span class="ml-4" id="productivitycount" style="color: blue;"></span></button>
  144. <button class="btn btn-primary" disabled><i class="ik ik-user-plus f-16"></i>Total Available agents:<span class="ml-4" id="availableagentcount"></span></button>
  145. </div>
  146. <table id="AgentDatatable" class="table table-striped table-bordered table-hover dataTable" role="grid" >
  147. <thead class="thead-dark">
  148. <tr role="row">
  149. <th class="text-center">
  150. <input type="checkbox" id="selectAll" />
  151. <label for="selectAll">Select All</label>
  152. </th>
  153. <th class="text-center" width="1%">S.No</th>
  154. <th class="text-center">AGENT ID</th>
  155. <th class="text-center">NAME</th>
  156. <th class="text-center">CAMPAIGN PENDING CALLS</th>
  157. <th class="text-center">ALREADY ASSIGNED CALLS</th>
  158. <th class="text-center">CALLS ASSIGNED</th>
  159. <th class="text-center">TOTAL CALLS</th>
  160. <th class="text-center">ACTION</th>
  161. </tr>
  162. </thead>
  163. <tbody style="text-align:center;">
  164. </tbody>
  165. <!-- Transfer Modal -->
  166. <div id="transferModal" class="modal" tabindex="-1" role="dialog">
  167. <div class="modal-dialog" role="document">
  168. <div class="modal-content">
  169. <div class="modal-header">
  170. <h5 class="modal-title">Transfer Calls</h5>
  171. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  172. <span aria-hidden="true">&times;</span>
  173. </button>
  174. </div>
  175. <div class="modal-body">
  176. <!-- Editable Calls Assigned Count -->
  177. <div class="form-group">
  178. <label for="callsAssignedInput">Calls Assigned Count</label>
  179. <input type="number" id="callsAssignedInput" class="form-control" min="1" placeholder="Enter Calls Count">
  180. </div>
  181. <!-- Transfer To Dropdown -->
  182. <div class="form-group">
  183. <label for="transferToDropdown">Transfer To</label>
  184. <select id="transferToDropdown" class="form-control">
  185. <!-- Options populated dynamically -->
  186. </select>
  187. </div>
  188. </div>
  189. <div class="modal-footer">
  190. <button type="button" id="transferButton" class="btn btn-primary">Transfer</button>
  191. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. </table>
  197. <div class="text-center">
  198. <button class="btn btn-primary" id="assignBtn">Click to Assign</button>
  199. </div>
  200. <div>
  201. <button class="btn btn-secondary" id="backBtn">Back</button>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. </div>
  209. <div id="pageLoader" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.8); z-index: 9999; text-align: center;">
  210. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  211. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  212. <span class="sr-only">Loading...</span>
  213. </div>
  214. <!-- Add the 'Please wait' text below the spinner -->
  215. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  216. </div>
  217. </div>
  218. <footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
  219. </div>
  220. </div>
  221. <div th:replace="~{fragments/modules/base/app_module_menu_box :: div}"></div>
  222. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  223. <script src="node_modules/tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.min.js"></script>
  224. <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  225. <script type="text/javascript">
  226. $(document).ready(function () {
  227. const redirected = sessionStorage.getItem('redirected'); // Check if redirected flag is set
  228. const cardType = sessionStorage.getItem('cardType'); // Get the card type
  229. //console.log("Redirected flag:", redirected);
  230. //console.log("Card Type:", cardType);
  231. if (redirected === 'true') {
  232. // Fetch data from sessionStorage
  233. const closeName = sessionStorage.getItem("closename");
  234. const closedCount = sessionStorage.getItem("closedcount");
  235. const reopenName = sessionStorage.getItem("reopenname");
  236. const reopenedCount = sessionStorage.getItem("reopenedcount");
  237. const inProgressName = sessionStorage.getItem("inProgressName");
  238. const inProgressCount = sessionStorage.getItem("inProgressCount");
  239. const redressedName = sessionStorage.getItem("redressedName");
  240. const redressedCount = sessionStorage.getItem("redressedCount");
  241. const startDate = sessionStorage.getItem("startDate");
  242. const endDate = sessionStorage.getItem("endDate");
  243. const followupName1=sessionStorage.getItem("followupname1");
  244. const followupCount1=sessionStorage.getItem("followupcount1");
  245. const followupName2=sessionStorage.getItem("followupname2");
  246. const followupCount2=sessionStorage.getItem("followupcount2");
  247. const withdrawname = sessionStorage.getItem("withdrawname");
  248. const withdrawCount = sessionStorage.getItem("withdrawCount");
  249. const group=sessionStorage.getItem("group");
  250. const type=sessionStorage.getItem("type");
  251. const mode=sessionStorage.getItem("mode");
  252. const zone=sessionStorage.getItem("zone");
  253. const region=sessionStorage.getItem("region");
  254. /* console.log("CloseName:", closeName);
  255. console.log("ClosedCount:", closedCount);
  256. console.log("ReopenName:", reopenName);
  257. console.log("ReopenedCount:", reopenedCount);
  258. console.log("InProgressName:", inProgressName);
  259. console.log("InProgressCount:", inProgressCount);
  260. console.log("RedressedName:", redressedName);
  261. console.log("RedressedCount:", redressedCount);
  262. console.log("StartDate:", startDate);
  263. console.log("EndDate:", endDate);
  264. console.log("followupName:", followupName);
  265. console.log("followupCount:", followupCount);
  266. console.log("group:",group);
  267. console.log("type",type);
  268. console.log("mode",mode);
  269. console.log("zone",zone); */
  270. /* console.log("ofollowupName:", followupName1);
  271. console.log("ofollowupCount:", followupCount1);
  272. console.log("pfollowupName:", followupName2);
  273. console.log("pfollowupCount:", followupCount2); */
  274. let cardName = '';
  275. let cardCount = '';
  276. // Set the relevant data based on cardType
  277. if (cardType === 'Closed') {
  278. cardName = closeName;
  279. cardCount = closedCount;
  280. $("#displayClosename").text(closeName); // Display Closed
  281. $("#displayClosedcount").text(closedCount);
  282. // Hide others
  283. $("#reopenedCard, #inProgressCard, #redressedCard","#followupCard1","#followupCard2").hide();
  284. $("#closedCard").show(); // Show the Closed card
  285. } else if (cardType === 'Reopened') {
  286. cardName = reopenName;
  287. cardCount = reopenedCount;
  288. $("#displayReopenname").text(reopenName); // Display Reopened
  289. $("#displayReopenedcount").text(reopenedCount);
  290. // Hide others
  291. $("#closedCard, #inProgressCard, #redressedCard","#followupCard1","#followupCard2").hide();
  292. $("#reopenedCard").show(); // Show the Reopened card
  293. } else if (cardType === 'In Progress') {
  294. cardName = inProgressName;
  295. cardCount = inProgressCount;
  296. $("#displayInProgressname").text(inProgressName); // Display In Progress
  297. $("#displayInProgresscount").text(inProgressCount);
  298. // Hide others
  299. $("#closedCard, #reopenedCard, #redressedCard","#followupCard1","#followupCard2").hide();
  300. $("#inProgressCard").show(); // Show the In Progress card
  301. } else if (cardType === 'Redressed') {
  302. cardName = redressedName;
  303. cardCount = redressedCount;
  304. $("#displayRedressedname").text(redressedName); // Display Redressed
  305. $("#displayRedressedcount").text(redressedCount);
  306. // Hide others
  307. $("#closedCard, #reopenedCard, #inProgressCard","#followupCard1","#followupCard2").hide();
  308. $("#redressedCard").show(); // Show the Redressed card
  309. }
  310. else if (cardType === 'Followup1') {
  311. cardName = followupName1;
  312. cardCount = followupCount1;
  313. $("#displayFollowupname1").text(followupName1); // Display Redressed
  314. $("#displayfollowupcount1").text(followupCount1);
  315. // Hide others
  316. $("#closedCard, #reopenedCard,#redressedCard, #inProgressCard","#followupCard2").hide();
  317. $("#followupCard1").show(); // Show the Redressed card
  318. }
  319. else if (cardType === 'Followup2') {
  320. cardName = followupName2;
  321. cardCount = followupCount2;
  322. $("#displayFollowupname2").text(followupName2); // Display Redressed
  323. $("#displayfollowupcount2").text(followupCount2);
  324. // Hide others
  325. $("#closedCard, #reopenedCard,#redressedCard, #inProgressCard","#followupCard1").hide();
  326. $("#followupCard2").show(); // Show the Redressed card
  327. }
  328. else if (cardType === 'withdraw') {
  329. cardName = withdrawname;
  330. cardCount = withdrawCount;
  331. $("#displaywithdrawname").text(withdrawname); // Display Redressed
  332. $("#displaywithdrawcount").text(withdrawCount);
  333. // Hide others
  334. $("#closedCard, #reopenedCard,#redressedCard, #inProgressCard","#followupCard1","#followupCard2").hide();
  335. $("#withdrawCard").show(); // Show the Redressed card
  336. }
  337. // Fill in date values
  338. $("#displaystartDate").val(startDate);
  339. $("#displayendDate").val(endDate);
  340. // Disable the start and end date inputs
  341. $("#displaystartDate, #displayendDate").prop("disabled", true);
  342. // Call the getStart function
  343. getStart(cardName, cardCount, startDate, endDate);
  344. $('#assignBtn').click(function (event) {
  345. event.preventDefault();
  346. if (!isCleared) {
  347. // Trigger Clear button flow
  348. Swal.fire({
  349. allowOutsideClick: false, // Disable clicking outside the modal to close it
  350. allowEscapeKey: false, // Disable escape key to close the modal
  351. allowEnterKey: false, // Disable enter key to close the modal
  352. title: 'Clear pending calls before assigning?',
  353. icon: 'info',
  354. showCancelButton: true,
  355. showDenyButton: true, // Show the Deny button
  356. confirmButtonColor: 'green',
  357. cancelButtonColor: 'orange',
  358. denyButtonColor: 'grey',
  359. confirmButtonText: 'Yes, clear it!', // Confirm button text
  360. cancelButtonText: 'No, assign without clearing', // Cancel button text
  361. denyButtonText: 'Exit' // Deny button text
  362. }).then((result) => {
  363. if (result.isConfirmed) {
  364. // Trigger Clear logic
  365. $('#clearButton').click();
  366. // Wait until Clear logic completes
  367. const interval = setInterval(() => {
  368. if (isCleared) {
  369. clearInterval(interval); // Stop checking
  370. assignLogic(); // Proceed to Assign logic
  371. }
  372. }, 500); // Check every 500ms
  373. }
  374. else if (result.isDenied) {
  375. // Do nothing on cancel (Cancel button clicked)
  376. Swal.fire('Cancelled', 'No action performed.', 'info');
  377. }
  378. else {
  379. // Proceed directly to Assign logic
  380. assignLogic();
  381. }
  382. });
  383. } else {
  384. // Proceed with Assign logic directly if Clear is already done
  385. assignLogic();
  386. }
  387. });
  388. function assignLogic() {
  389. // Fetch the values from the fields
  390. const startDate = $('#displaystartDate').val();
  391. const endDate = $('#displayendDate').val();
  392. const description = $('textarea').val().trim() || "N/A"; // Default to "N/A" if empty
  393. /* console.log("startDate",startDate);
  394. console.log("endDate",endDate); */
  395. // Validate inputs if necessary
  396. if (!startDate || !endDate || !cardName || !cardCount) {
  397. Swal.fire({
  398. icon: 'error',
  399. title: 'Error',
  400. text: 'All fields must be filled!',
  401. });
  402. return;
  403. }
  404. const allAgents = [];
  405. const table = $('#AgentDatatable').DataTable();
  406. //Loop through all rows in the DataTable
  407. table.rows().every(function (rowIdx, tableLoop, rowLoop) {
  408. const row = $(this.node()); // Get the DOM row
  409. const checkbox = row.find('.select-agent');
  410. const agentId = row.find('td:nth-child(3)').text().trim();
  411. const callsPerAgent = row.find('td:nth-child(7)').text().trim();
  412. // Add agent to allAgents with default callsPerAgent = 0
  413. allAgents.push({ agentId: agentId, callsPerAgent: 0 });
  414. // If checkbox is checked, update callsPerAgent
  415. if (checkbox.is(':checked')) {
  416. const agent = allAgents.find(a => a.agentId === agentId);
  417. if (agent) {
  418. agent.callsPerAgent = callsPerAgent;
  419. }
  420. }
  421. });
  422. // Remove agents with callsPerAgent still set to 0
  423. const filteredAgents = allAgents.filter(agent => agent.callsPerAgent > 0);
  424. // Check if no agents were selected
  425. if (filteredAgents.length === 0) {
  426. Swal.fire({
  427. icon: 'error',
  428. title: 'Error',
  429. text: 'Please select at least one agent to assign calls!',
  430. });
  431. return;
  432. }
  433. //console.log('Filtered agents:', filteredAgents);
  434. // Prepare the data object to send in the AJAX request
  435. const data = {
  436. startDate: startDate,
  437. endDate: endDate,
  438. closeName: cardName,
  439. closedCount: cardCount,
  440. description: description,
  441. group:group,
  442. type:type,
  443. mode:mode,
  444. zone:zone,
  445. region:region,
  446. agents:filteredAgents // Send only agents with callsPerAgent > 0
  447. };
  448. console.log('Data to send:', data);
  449. // Show the loader
  450. $('#pageLoader').show();
  451. // Send the AJAX request
  452. $.ajax({
  453. type: "POST",
  454. url: "/gcc/api/callcenterqaqc/agentassign/taskassign", // Replace with your API endpoint
  455. data: JSON.stringify(data),
  456. contentType: "application/json",
  457. success: function (response) {
  458. // Hide the loader
  459. $('#pageLoader').hide();
  460. // Show a success message using Swal
  461. Swal.fire({
  462. icon: 'success',
  463. title: 'Success',
  464. allowOutsideClick: false, // Disable clicking outside the modal to close it
  465. allowEscapeKey: false, // Disable escape key to close the modal
  466. allowEnterKey: false, // Disable enter key to close the modal
  467. showConfirmButton: true, // Ensure the confirm button is visible
  468. text: response.message || 'Data transferred successfully!',
  469. }).then((result) => {
  470. if (result.isConfirmed) {
  471. window.location.href = `/gcc/callcenterqaqcreports/qaqctasklist`;
  472. }
  473. });
  474. },
  475. error: function (error) {
  476. $('#pageLoader').hide();
  477. // Show an error message using Swal
  478. Swal.fire({
  479. allowOutsideClick: false, // Disable clicking outside the modal to close it
  480. allowEscapeKey: false, // Disable escape key to close the modal
  481. allowEnterKey: false, // Disable enter key to close the modal
  482. showConfirmButton: true, // Ensure the confirm button is visible
  483. icon: 'error',
  484. title: 'Error',
  485. text: error.responseJSON?.message,
  486. }).then((result) => {
  487. if (result.isConfirmed) {
  488. window.location.href = `/gcc/callcenterqaqc/admin/qaqcgrievancedashboard`;
  489. }
  490. });
  491. }
  492. });
  493. }
  494. // Clear the redirected flag after use
  495. sessionStorage.removeItem('redirected');
  496. } else {
  497. // Clear sessionStorage and notify the user
  498. sessionStorage.clear();
  499. // Show Swal alert and redirect on OK button
  500. Swal.fire({
  501. allowOutsideClick: false, // Disable clicking outside the modal to close it
  502. allowEscapeKey: false, // Disable escape key to close the modal
  503. allowEnterKey: false, // Disable enter key to close the modal
  504. showConfirmButton: true, // Ensure the confirm button is visible
  505. icon: 'error',
  506. title: 'Access Denied',
  507. text: 'Please navigate from the Dashboard Page.',
  508. confirmButtonText: 'OK',
  509. }).then((result) => {
  510. if (result.isConfirmed) {
  511. // Redirect to the desired page
  512. window.location.href = `/gcc/callcenterqaqc/admin/qaqcgrievancedashboard`;
  513. }
  514. }); }
  515. // Optional: You can still allow toggling of cards if needed:
  516. $('.card-box').on('click', function () {
  517. // Hide all the card-box elements
  518. $('.card-box').hide();
  519. // Get the id of the clicked card-box and show it
  520. const cardId = $(this).attr('id');
  521. $('#' + cardId).show();
  522. });
  523. function getStart(closeName,closedCount,startDate,endDate)
  524. {
  525. // Show the loader
  526. $('#pageLoader').show();
  527. $.ajax({
  528. url: '/gcc/api/callcenterqaqc/agentassign/getavailableagents?totalDataCount='+closedCount,
  529. type: 'GET',
  530. dataType: 'json',
  531. success: function(response) {
  532. // Hide the loader
  533. $('#pageLoader').hide();
  534. if (response.status === 'success') {
  535. populateDataTable(response);
  536. $("#productivitycount").text(response.productivity_count);
  537. $("#availableagentcount").text(response.agent_available_count);
  538. } if (response.status === 'error') {
  539. $('#pageLoader').hide();
  540. Swal.fire({
  541. icon: 'error',
  542. title: 'Error',
  543. text: response.message || "Error fetching Agents.",
  544. confirmButtonText: 'OK',
  545. }).then((result) => {
  546. if (result.isConfirmed) {
  547. // Reload the same page
  548. window.location.href = `/gcc/callcenterqaqc/admin/qaqcgrievancedashboard`;
  549. }
  550. });
  551. }
  552. },
  553. error: function(xhr, status, error) {
  554. $('#pageLoader').hide();
  555. console.error('Error fetching assigned agents:', error);
  556. }
  557. });
  558. }
  559. function populateDataTable(data) {
  560. // Clear existing rows
  561. var table = $('#AgentDatatable').DataTable();
  562. table.clear();
  563. // Populate table
  564. data.available_agents.forEach((agent, index) => {
  565. table.row.add([
  566. `<input type="checkbox" class="select-agent" value="${agent.agent_id}" checked />`,
  567. index + 1,
  568. agent.agent_id,
  569. agent.agent_name,
  570. agent.campaignPendingCount,
  571. agent.todayCount1,
  572. agent.calls_per_agent,
  573. agent.totalCallsCount,
  574. `<button class="btn btn-warning btn-sm edit-agent" data-id="${agent.agent_id}"><i class="ik ik-edit"></i></button>`
  575. ]);
  576. });
  577. // Redraw table to reflect new data
  578. table.draw();
  579. }
  580. let selectedAgentId; // Store the agent being edited
  581. // Handle "Edit" button click
  582. $(document).on('click', '.edit-agent', function () {
  583. const row = $(this).closest('tr'); // Get the parent row of the clicked button
  584. selectedAgentId = row.find('td:nth-child(3)').text().trim(); // Get the Agent ID
  585. const callsAssigned = row.find('td:nth-child(7)').text().trim(); // Get Calls Assigned Count
  586. // Populate the Calls Assigned input field
  587. $('#callsAssignedInput').val(callsAssigned);
  588. // Populate the Transfer To dropdown
  589. const dropdown = $('#transferToDropdown');
  590. dropdown.empty(); // Clear previous options
  591. $('#AgentDatatable tbody tr').each(function () {
  592. const agentId = $(this).find('td:nth-child(3)').text().trim();
  593. const agentName = $(this).find('td:nth-child(4)').text().trim();
  594. // Exclude the currently selected agent from the dropdown
  595. if (agentId !== selectedAgentId) {
  596. dropdown.append(`<option value="${agentId}">${agentName}</option>`);
  597. }
  598. });
  599. // Show the modal
  600. $('#transferModal').modal('show');
  601. });
  602. // Handle "Transfer" button click
  603. $('#transferButton').click(function () {
  604. const transferCount = parseInt($('#callsAssignedInput').val(), 10);
  605. const transferToAgentId = $('#transferToDropdown').val();
  606. if (!transferCount || transferCount <= 0) {
  607. alert('Please enter a valid calls count!');
  608. return;
  609. }
  610. if (!transferToAgentId) {
  611. alert('Please select an agent to transfer the calls!');
  612. return;
  613. }
  614. let deductionSuccess = false; // Flag for successful deduction from the current agent
  615. let additionSuccess = false; // Flag for successful addition to the receiving agent
  616. const productivityCount = parseInt($('#productivitycount').text().trim(), 10); // Fetch dynamic productivity count from the button
  617. // Validate and update the table
  618. $('#AgentDatatable tbody tr').each(function () {
  619. const agentId = $(this).find('td:nth-child(3)').text().trim();
  620. const callsAssignedCell = $(this).find('td:nth-child(7)'); // Calls Assigned column
  621. // Validate deduction from the current agent
  622. if (agentId === selectedAgentId) {
  623. const currentCount = parseInt(callsAssignedCell.text().trim(), 10);
  624. if (currentCount >= transferCount) {
  625. deductionSuccess = true;
  626. } else {
  627. alert('Transfer not allowed! Transferring more calls than assigned.');
  628. return false; // Stop the operation
  629. }
  630. }
  631. // Validate addition to the receiving agent
  632. if (agentId === transferToAgentId) {
  633. const currentCount = parseInt(callsAssignedCell.text().trim(), 10);
  634. const newCount = currentCount + transferCount;
  635. if (newCount <= productivityCount) {
  636. additionSuccess = true;
  637. } else {
  638. alert(`Transfer not allowed! Transferring ${transferCount} calls will exceed the productivity count of ${productivityCount} for agent ID: ${transferToAgentId}.`);
  639. return false; // Stop the operation
  640. }
  641. }
  642. });
  643. // If both validations pass, proceed to update the table
  644. if (deductionSuccess && additionSuccess) {
  645. $('#AgentDatatable tbody tr').each(function () {
  646. const agentId = $(this).find('td:nth-child(3)').text().trim();
  647. const callsAssignedCell = $(this).find('td:nth-child(7)'); // Calls Assigned column
  648. const totalCallsCell = $(this).find('td:nth-child(8)'); // TOTAL CALLS column
  649. // Deduct calls from the current agent
  650. if (agentId === selectedAgentId) {
  651. const currentCount = parseInt(callsAssignedCell.text().trim(), 10);
  652. callsAssignedCell.text(currentCount - transferCount);
  653. // Update TOTAL CALLS for the current agent
  654. const currentTotalCalls = parseInt(totalCallsCell.text().trim(), 10);
  655. totalCallsCell.text(currentTotalCalls - transferCount);
  656. }
  657. // Add calls to the receiving agent
  658. if (agentId === transferToAgentId) {
  659. const currentCount = parseInt(callsAssignedCell.text().trim(), 10);
  660. callsAssignedCell.text(currentCount + transferCount);
  661. // Update TOTAL CALLS for the receiving agent
  662. const currentTotalCalls = parseInt(totalCallsCell.text().trim(), 10);
  663. totalCallsCell.text(currentTotalCalls + transferCount);
  664. }
  665. });
  666. // Dynamically update the total calls across all agents
  667. let totalCalls = 0;
  668. $('#AgentDatatable tbody tr').each(function () {
  669. const totalCallsCell = $(this).find('td:nth-child(8)'); // TOTAL CALLS column
  670. totalCalls += parseInt(totalCallsCell.text().trim(), 10);
  671. });
  672. $('#totalCallsCount').text(totalCalls); // Update total calls count across all agents
  673. // Close the modal
  674. $('#transferModal').modal('hide');
  675. }
  676. });
  677. // Initialize DataTable
  678. var table = $('#AgentDatatable').DataTable({
  679. dom: 'Bftip',
  680. columnDefs: [
  681. { targets: 'no-sort', orderable: false }
  682. ],
  683. lengthMenu: [
  684. [200, 500, -1],
  685. [ '200 rows','500 rows', 'Show all']
  686. ],
  687. scrollY: '70vh',
  688. fixedColumns: {
  689. left: 1,
  690. right: 1
  691. },
  692. buttons: [
  693. {
  694. extend: 'pageLength',
  695. className: 'btn btn-warning'
  696. },
  697. {
  698. title: 'Data export',
  699. extend: 'copyHtml5',
  700. text: 'Copy',
  701. className: 'btn btn-secondary',
  702. id: 'copyBtn'
  703. },
  704. {
  705. extend: 'excelHtml5',
  706. text: 'Excel',
  707. className: 'btn btn-secondary',
  708. id: 'excelBtn'
  709. },
  710. {
  711. extend: 'csvHtml5',
  712. text: 'CSV',
  713. className: 'btn btn-secondary',
  714. id: 'csvBtn'
  715. },
  716. {
  717. extend: 'pdfHtml5',
  718. text: 'PDF',
  719. className: 'btn btn-secondary',
  720. id: 'pdfBtn'
  721. }
  722. ],
  723. fixedHeader: true,
  724. autoWidth: true,
  725. responsive: true,
  726. searching: true,
  727. select: false,
  728. processing: false
  729. });
  730. });
  731. $(document).ready(function () {
  732. // "Select All" checkbox functionality
  733. $('#selectAll').on('change', function () {
  734. const isChecked = $(this).is(':checked');
  735. $('.select-agent').prop('checked', isChecked); // Check/uncheck all checkboxes
  736. });
  737. // Ensure "Select All" is checked/unchecked based on individual checkboxes
  738. $(document).on('change', '.select-agent', function () {
  739. const allChecked = $('.select-agent:checked').length === $('.select-agent').length;
  740. $('#selectAll').prop('checked', allChecked); // Check "Select All" only if all checkboxes are selected
  741. });
  742. });
  743. </script>
  744. <script type="text/javascript">
  745. $(document).ready(function () {
  746. $('#backBtn').click(function (event) {
  747. window.location.href = `/gcc/callcenterqaqc/admin/qaqcgrievancedashboard`;
  748. });
  749. });
  750. </script>
  751. <script>
  752. // Global flag to track if Clear logic has been executed
  753. let isCleared = false;
  754. document.getElementById('clearButton').addEventListener('click', function () {
  755. Swal.fire({
  756. title: 'Are you sure to clear calls?',
  757. icon: 'warning',
  758. allowOutsideClick: false, // Disable clicking outside the modal to close it
  759. allowEscapeKey: false, // Disable escape key to close the modal
  760. allowEnterKey: false, // Disable enter key to close the modal
  761. showCancelButton: true,
  762. confirmButtonColor: '#d33',
  763. cancelButtonColor: '#3085d6',
  764. confirmButtonText: 'Yes, clear it!',
  765. cancelButtonText: 'No, cancel'
  766. }).then((result) => {
  767. if (result.isConfirmed) {
  768. // Logic to clear calls can be added here
  769. $.ajax({
  770. url: '/gcc/api/callcenterqaqc/agentassign/deleteRecords',
  771. type: 'GET',
  772. contentType: 'application/json',
  773. success: function (response) {
  774. //console.log("response",response);
  775. if (response==="success") {
  776. Swal.fire(
  777. 'Cleared!',
  778. 'The calls have been cleared.',
  779. 'success'
  780. );
  781. isCleared = true; // Mark as cleared
  782. }
  783. else {
  784. Swal.fire("Info", "No Records to clear,You can Assign", "info");
  785. isCleared = true; // Mark as cleared
  786. }
  787. },
  788. error: function (xhr, status, error) {
  789. Swal.fire("Error", `An error occurred: ${xhr.responseText || error}`, "error");
  790. }
  791. });
  792. } else {
  793. Swal.fire(
  794. 'Cancelled',
  795. 'Your data is safe,If you wish you can Assign :)',
  796. 'info'
  797. );
  798. isCleared = true;
  799. }
  800. });
  801. });
  802. </script>
  803. </body>
  804. </html>