Advertisement
Guest User

container_procurement

a guest
Mar 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.33 KB | None | 0 0
  1. <?php include '../../styles/dashboard/ProfileController/fetch_profile.php'; ?>
  2. <?php
  3. $conn = $pdo->open();
  4.  
  5. $cont_id = $_GET['container_id'];
  6.  
  7. $stmt = $conn->prepare("SELECT container_status FROM container WHERE container_id=:cont_id");
  8. $stmt->execute(['cont_id' => $cont_id]);
  9.  
  10. $container_status = $stmt->fetchColumn();
  11.  
  12. if ($container_status != 0){
  13. $_SESSION['error'] = 'Container Has Been Finalized Already!! Please Ask The IT Department For Editing.';
  14.  
  15. header('Location: manage_container.php');
  16. }
  17. else{
  18. ?>
  19. <?php
  20. if (!isset($_SESSION['releasing']) || $_SESSION["position"] == null){
  21.  
  22. unset($_SESSION['position']); //Position ID
  23.  
  24. unset($_SESSION['releasing']); //Position
  25.  
  26. $_SESSION['unathorized'] = "We Are Watching You, You've Visiting Unathorized Access..";
  27.  
  28. header('Location: /');
  29.  
  30. exit();
  31. }
  32. ?>
  33. <?php include '../../styles/dashboard/user-navigation/header.php'; ?>
  34. <body class="hold-transition skin-blue sidebar-mini">
  35. <div class="wrapper">
  36.  
  37. <?php include '../../styles/dashboard/user-navigation/navbar.php'; ?>
  38. <?php include '../../styles/dashboard/user-Sidebar/sidebarReleasing.php'; ?>
  39.  
  40. <div class="content-wrapper">
  41. <section class="content-header">
  42. <h1>Container Under Procurement</h1>
  43. <ol class="breadcrumb">
  44. <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
  45. <li><a href="#"><i class="fa fa-cubes"></i>Product</a></li>
  46. <li class="active">QR Products</li>
  47. </ol>
  48. </section>
  49.  
  50. <section class="content">
  51. <?php include '../../styles/message.php'; ?>
  52. <input type="hidden" id="container_id" value="<?php echo $_GET['container_id'];?>">
  53. <div class="row">
  54. <div class="col-xs-6">
  55. <div class="box">
  56. <div class="box-header with-border">
  57. <h3><strong>Container Details</strong></h3>
  58. <hr>
  59. <h4>Container Number:<strong><span id="procure_container_name"></span></strong> </h4>
  60. <h4>Item Quantity:<strong><span id="procure_container_qty" style="font-style:italic;"></span></strong></h4>
  61. </div>
  62. <div class="box-body">
  63. <div class="col-sm-12">
  64. <strong> <span>Select Brand:</span></strong>
  65. <input type="hidden" id="selected_brand_id">
  66. <select id="select_brand" class="form-control"></select>
  67. </div>
  68. <div class="col-sm-12">
  69. <strong> <span>Select Model:</span></strong>
  70. <input type="hidden" id="selected_model_id">
  71. <select id="select_model" class="form-control"></select>
  72. </div>
  73. <div class="col-sm-12">
  74. <strong> <span>Input QR Code:</span></strong><input type="text" class="form-control" id="input_qr_code">
  75. </div>
  76. </div>
  77. <div class="box-footer">
  78. <div>
  79. <button type="submit" class='btn btn-success btn-flat' style="float:right" id="add_item"><i class='fa fa-plus'></i> Add Item </button>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. <div class="col-xs-6">
  85. <div class="box">
  86. <div class="box-header with-border">
  87. <button type="button" class="btn btn-success btn-flat" id="item-container-success" style="display:none;">Click me</button>
  88. <button type="button" class="btn btn-danger btn-flat" id="item-container-delete" style="display:none;">Click me</button>
  89. <h3><strong>Container Product Lists</strong><button type="submit" class='btn btn-primary btn-flat' style="float:right" id="finalize_container" style="display:none;"><i class='fa fa-check'></i> Finalize </button></h3>
  90. </div>
  91. <div class="box-body">
  92. <table id="container_product_tbl" class="table table-bordered">
  93. <thead>
  94. <th>QR Code</th>
  95. <th>Brand Name</th>
  96. <th>Model Name</th>
  97. <th>Delete Item</th>
  98. </thead>
  99. <tbody>
  100. </tbody>
  101. </table>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </section>
  107. </div>
  108. <?php include '../../styles/dashboard/user-navigation/footer.php'; ?>
  109. </div>
  110. <?php include '../../styles/dashboard/user-navigation/scripts.php'; ?>
  111. <script>
  112. $(function(){
  113. $(document).ready(function(){
  114.  
  115. var container_id = $('#container_id').val();
  116. // GET CONTAINER NUMBER
  117. $.ajax({
  118. type: 'POST',
  119. url: 'AJAX/getContainerDetails.php',
  120. data:
  121. {
  122. container_id:container_id
  123. },
  124. dataType: 'json',
  125. success:function(result){
  126. $('#procure_container_name').text(result[0].container_number);
  127. }
  128. });
  129. var container_product_tbl = $('#container_product_tbl').DataTable({
  130. lengthMenu: [ [5, 10, 15, 20, 25, -1], [5, 10, 15, 20, 25, "All"] ],
  131. pageLength: 5,
  132. paging: true,
  133. searching: true,
  134. bLengthChange: true,
  135. bFilter: true,
  136. bInfo: false,
  137. bAutoWidth: false,
  138. responsive:true,
  139. order: [],
  140. ajax:
  141. {
  142. url:'AJAX/container_procurement_result.php',
  143. type: 'POST',
  144. data:
  145. {
  146. container_id:container_id
  147. },
  148. dataType: 'json',
  149. dataSrc: "container_procurement_result"
  150. },
  151. fnDrawCallback: function() {
  152. var oSettings = this.fnSettings();
  153. var iTotalRecords = oSettings.fnRecordsTotal();
  154.  
  155. $('#procure_container_qty').text(iTotalRecords + ' ' + 'PC/s');
  156.  
  157. if (iTotalRecords == "0") {
  158. $('#finalize_container').css('display', 'none');
  159. } else {
  160. $('#finalize_container').css('display', 'block');
  161. }
  162. },
  163. columnDefs:
  164. [
  165. { className: 'text-center', targets: [0], orderable:false },
  166. { className: 'text-center', targets: [1], orderable:false },
  167. { className: 'text-center', targets: [2], orderable:false },
  168. { className: 'text-center', targets: [3], orderable:false }
  169. ],
  170. columns:
  171. [
  172. { data: 'qr_code' },
  173. { data: 'brand_name' },
  174. { data: 'model_name' },
  175. { data: 'product_id', data: 'container_id',
  176. render: function (data, type, row, meta){
  177. return type === 'display' ?
  178. '<button class="btn btn-danger btn-sm delete btn-flat" data-product_id='+row.product_id+' data-container_id='+row.container_id+'><i class="fa fa-trash"></i> Delete</button>' : data;
  179. }
  180. }
  181. ],
  182. createdRow: function (row, data, dataIndex) {
  183. var deleteProductItem = $(row).find('.delete');
  184.  
  185. $(deleteProductItem).on('click', function(e){
  186. e.preventDefault();
  187.  
  188. var product_id = $(this).data('product_id');
  189. var container_id = $(this).data('container_id');
  190. var container_number = $('#procure_container_name').text();
  191. // console.log(container_number);
  192. $.ajax({
  193. type: 'POST',
  194. url: 'AJAX/deleteProductItem.php',
  195. data:
  196. {
  197. product_id:product_id,
  198. container_id:container_id,
  199. // FOR USER LOG
  200. container_number:container_number
  201. },
  202. dataType: 'json',
  203. success: function(result){
  204. if (result[0].result == true) {
  205. $('#item-container-delete').click();
  206. container_product_tbl.ajax.reload();
  207. }
  208. }
  209. });
  210. });
  211. }
  212. });
  213. // SELECT BRAND
  214. $.ajax({
  215. type: 'POST',
  216. url: 'AJAX/selectBrand.php',
  217. dataType: 'json',
  218. success: function(result){
  219. // MAKE SELECT EMPTY FIRST
  220. $('#select_brand').empty();
  221. // APPEND DEFAULT OPTION VALUE
  222. $('#select_brand').append('<option selected disabled readonly>Choose Brand</option>');
  223. // APPEND AJAX VALUE TO OPTION
  224. $.each(result, function(i, v){
  225. $('#select_brand').append('<option value='+v.brand_id+'>'+v.brand_name+'</option>');
  226. });
  227. }
  228. });
  229.  
  230. $('#select_brand').select2();
  231. $('#select_brand').on('change', function(){
  232. $('#selected_brand_id').val($('#select_brand option:selected').val());
  233. var selected_brand_id = $('#selected_brand_id').val();
  234.  
  235. $.ajax({
  236. type: 'POST',
  237. url: 'AJAX/selectModel.php',
  238. data:
  239. {
  240. selected_brand_id:selected_brand_id
  241. },
  242. dataType: 'json',
  243. success: function(result){
  244. // MAKE SELECT EMPTY FIRST
  245. $('#select_model').empty();
  246. // APPEND DEFAULT OPTION VALUE
  247. $('#select_model').append('<option selected disabled readonly>Choose Model</option>');
  248. // APPEND AJAX VALUE TO OPTION
  249. $.each(result, function(i, v){
  250. $('#select_model').append('<option value='+v.model_id+'>'+v.model_name+'</option>');
  251. });
  252. }
  253. });
  254.  
  255. $('#select_model').select2();
  256. $('#select_model').on('change', function(){
  257. $('#selected_model_id').val($('#select_model option:selected').val());
  258. });
  259. });
  260.  
  261. $("#input_qr_code").keyup(function(event){
  262. if(event.keyCode == 13){
  263. $("#add_item").click();
  264. }
  265. });
  266. // INSERT ITEM
  267. $('#add_item').on('click', function(e){
  268. e.preventDefault();
  269.  
  270. var selected_brand_id = $("#selected_brand_id").val();
  271. var selected_model_id = $("#selected_model_id").val();
  272. var input_qr = $('#input_qr_code').val();
  273. var procure_container_name = $('#procure_container_name').text();
  274.  
  275. if (selected_brand_id == "" || selected_brand_id == "0") {
  276. swal(
  277. {
  278. icon: 'error',
  279. title: 'Invalid Action!',
  280. text: 'Kindly Choose a Brand!'
  281. }
  282. )
  283. } else if (selected_model_id == "" || selected_model_id == "0") {
  284. swal(
  285. {
  286. icon: 'error',
  287. title: 'Invalid Action!',
  288. text: 'Kindly Choose a Model!'
  289. }
  290. )
  291. } else if (input_qr == "" || input_qr == "0") {
  292. swal(
  293. {
  294. icon: 'error',
  295. title: 'Invalid Action!',
  296. text: 'Please Input QR Code!'
  297. }
  298. )
  299. } else {
  300. $.ajax({
  301. type: 'POST',
  302. url: 'AJAX/insertContainerItem.php',
  303. data:
  304. {
  305. selected_model_id:selected_model_id,
  306. input_qr:input_qr,
  307. container_id:container_id,
  308. procure_container_name:procure_container_name
  309. },
  310. dataType:'json',
  311. success: function(result){
  312. if (result == false) {
  313. swal(
  314. {
  315. icon: 'error',
  316. title: 'Invalid Action!',
  317. text: 'QR Code Already Exist!'
  318. }
  319. )
  320. } else if (result == true){
  321. $('#item-container-success').click();
  322. $('#input_qr_code').val('');
  323. container_product_tbl.ajax.reload();
  324. }
  325. }
  326. });
  327. }
  328. });
  329. // FINALIZE CONTAINER
  330. $("#finalize_container").on('click', function(){
  331.  
  332. var procure_container_name = $('#procure_container_name').text();
  333.  
  334. $.ajax({
  335. type: 'POST',
  336. url: 'AJAX/confirm_container_finalize.php',
  337. data:
  338. {
  339. container_id:container_id,
  340. procure_container_name:procure_container_name
  341. },
  342. dataType: 'json',
  343. success: function(result){
  344. if (result[0].result == true) {
  345. swal({
  346. title: "Success!",
  347. text: "Container Finalize Success!",
  348. icon: "success",
  349. button: {
  350. text: "Redirect"
  351. },
  352. closeOnEsc: false,
  353. closeOnClickOutside: false
  354. }).then(function() {
  355. window.location = "http://localhost/OneTrinity/Users/Releasing/manage_container.php";
  356. });
  357. }
  358. }
  359. });
  360. });
  361. });
  362. });
  363. </script>
  364. </body>
  365. <?php
  366. }
  367. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement