Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.85 KB | None | 0 0
  1. (function(){
  2. 'use strict';
  3.  
  4. angular
  5. .module('cmsOrderApp')
  6. .controller('CmsOrderCtrl', CmsOrderCtrl)
  7. .controller('CmsOrderDetailCtrl', CmsOrderDetailCtrl);
  8.  
  9. CmsOrderCtrl.$inject = ['$scope','$state','$stateParams','$uibModal','$log','CmsOrderService', 'toastr'];
  10. CmsOrderDetailCtrl.$inject = ['$scope','$state','$stateParams','$uibModal','$log','CmsOrderService', 'toastr'];
  11.  
  12. function CmsOrderCtrl($scope,$state,$stateParams,$uibModal,$log,CmsOrderService, toastr){
  13. $('#block').show();
  14. $scope.roleName = window.Laravel.suppType;
  15. $scope.roleGudang = window.Laravel.roleGudang;
  16. $scope.roleAdmin = window.Laravel.roleAdmin;
  17. $scope.roleManagement = window.Laravel.roleManagement;
  18.  
  19. function defaultDate(){
  20. var date1 = new Date();
  21. var date2 = new Date();
  22. $scope.endDate = date1;
  23. date2.setDate(date2.getDate()-1);
  24. $scope.startDate = date2;
  25. }
  26. defaultDate();
  27.  
  28. $scope.checkTask = function($task){
  29. var taskList = window.Laravel.taskList;
  30. taskList = taskList.split(",");
  31. var index = taskList.indexOf($task);
  32. if(index == -1){
  33. return false;
  34. }else{
  35. return true;
  36. }
  37. }
  38.  
  39. $scope.limit = 10;
  40. $scope.offset = 1;
  41.  
  42. $scope.sort = true; // true = ASC
  43.  
  44. $scope.orderBy = ''
  45. $scope.orderType = '';
  46.  
  47. $scope.back = function(){
  48. window.history.back();
  49. }
  50.  
  51. $scope.filter = function(){
  52. $scope.startDateFilter = $scope.startDate;
  53. $scope.endDateFilter = $scope.endDate;
  54. $scope.getOrderList();
  55. }
  56.  
  57. $scope.getOrderList = function(){
  58. $('#block').show();
  59. var input = {};
  60. input.orderNo = $scope.orderNo;
  61. // input.startDate = $scope.startDateFilter;
  62. // input.endDate = $scope.endDateFilter;
  63. input.startDate = $scope.startDate;
  64. input.endDate = $scope.endDate;
  65. if($scope.salesmanList != undefined && $scope.salesmanList.selected != undefined){
  66. input.salesmanUserId = $scope.salesmanList.selected.user_id;
  67. }else{
  68. input.salesmanUserId = '';
  69. }
  70. if($scope.tokoList != undefined && $scope.tokoList.selected != undefined){
  71. input.tokoUserId = $scope.tokoList.selected.user_id;
  72. }else{
  73. input.tokoUserId = '';
  74. }
  75. if($scope.cabangList != undefined && $scope.cabangList.selected != undefined){
  76. input.cabang = $scope.cabangList.selected.ou_id;
  77. }else{
  78. input.cabang = '';
  79. }
  80.  
  81. input.limit = $scope.limit;
  82. input.offset = $scope.offset;
  83. input.status = $scope.status;
  84. input.orderBy = $scope.orderBy;
  85. input.orderType = $scope.orderType;
  86.  
  87. CmsOrderService.getOrderList(input)
  88. .then(function(response){
  89. if(response.data.status == 'OK'){
  90. $scope.orderList = response.data.orderList;
  91. $scope.orderTotal = response.data.totalOrder;
  92. $('#block').hide();
  93. }else{
  94. $('#block').hide();
  95. swal("Error!", response.data.error, "error");
  96. }
  97. });
  98. }
  99.  
  100.  
  101. $scope.getOrderList();
  102.  
  103. $scope.changeLimit = function(){
  104. if($scope.pageItem != ''){
  105. $scope.limit = $scope.pageItem;
  106. }else{
  107. $scope.limit = 10;
  108. }
  109. $scope.getOrderList();
  110. }
  111.  
  112. $scope.setOrder = function(by,type){
  113. $scope.sort = type;
  114. if($scope.sort == true){
  115. $scope.orderType = 'ASC';
  116. $scope.orderIcon = 'fa fa-sort-amount-asc';
  117. }else{
  118. $scope.orderType = 'DESC';
  119. $scope.orderIcon = 'fa fa-sort-amount-desc';
  120. }
  121. $scope.orderBy = by;
  122.  
  123. $scope.getOrderList();
  124. }
  125.  
  126. $scope.getCabangList = function(){
  127. var defaultOu = {
  128. ou_id:"",
  129. ou_code:"",
  130. ou_name:"SEMUA CABANG"
  131. }
  132. CmsOrderService.getCabangList()
  133. .then(function(response){
  134. if(response.data.status == 'OK'){
  135. $scope.cabangList = response.data.cabangList;
  136. $scope.cabangList.unshift(defaultOu);
  137. $scope.cabangList.selected = defaultOu;
  138. }else{
  139. swal("Error!", response.data.error, "error");
  140. }
  141. });
  142. }
  143. $scope.getSalesmanList = function(){
  144. CmsOrderService.getSalesmanList()
  145. .then(function(response){
  146. if(response.data.status == 'OK'){
  147. $scope.salesmanList = response.data.salesmanList;
  148. console.log("DATA SALESMAN DARI ORDER");
  149. console.log($scope.salesmanList);
  150. }else{
  151. swal("Error!", response.data.error, "error");
  152. }
  153. });
  154. }
  155. $scope.getTokoList = function(){
  156. CmsOrderService.getTokoList()
  157. .then(function(response){
  158. if(response.data.status == 'OK'){
  159. $scope.tokoList = response.data.tokoList;
  160. }else{
  161. swal("Error!", response.data.error, "error");
  162. }
  163. });
  164. }
  165.  
  166. $scope.getCabangList();
  167. $scope.getSalesmanList();
  168. $scope.getTokoList();
  169. }
  170. function CmsOrderDetailCtrl($scope,$state,$stateParams,$uibModal,$log,CmsOrderService, toastr){
  171. $('#block').show();
  172.  
  173. $scope.roleName = window.Laravel.suppType;
  174. $scope.roleGudang = window.Laravel.roleGudang;
  175. $scope.roleAdmin = window.Laravel.roleAdmin;
  176. $scope.roleManagement = window.Laravel.roleManagement;
  177.  
  178. $scope.flgAddBonus = false;
  179. $scope.flgUpdateStatusByAdminSales = false;
  180. $scope.flgUpdateStatusByAdminGudang = false;
  181. $scope.flgShowRemarkInternal = false;
  182. $scope.flgInputRemarkInternal = false;
  183. $scope.flgInputDiscountHeader = false;
  184. $scope.flgShowDiscount = false;
  185. $scope.flgInputDiscount = false;
  186.  
  187. $scope.flgShowTotalOrderDiscount = false;
  188. $scope.flgShowTotalDeliveryDiscount = false;
  189. $scope.flgShowTotalReceivedDiscount = false;
  190.  
  191. $scope.flgShowTotalOrderAmountAfterDisc = false;
  192. $scope.flgShowTotalDeliveryAmountAfterDisc = false;
  193. $scope.flgShowTotalReceivedAmountAfterDisc = false;
  194.  
  195. $scope.flgShowQtyReceive = false;
  196. $scope.flgShowRemark = false;
  197. $scope.flgShowRowForAdminSales = false;
  198. $scope.flgShowRowForAdminGudang = false;
  199. $scope.flgEditUnitPrice = false;
  200. $scope.flgEditQtyOrderFreeProduct = false;
  201.  
  202. $scope.statusD = 'D';
  203. $scope.statusR = 'R';
  204. $scope.statusC = 'C';
  205. $scope.statusS = 'S';
  206. $scope.statusF = 'F';
  207.  
  208. $scope.externalList = [];
  209. $scope.expanded = [];
  210. $scope.soList = [];
  211.  
  212. $scope.setFalse = function(){
  213. $scope.flgAddBonus = false;
  214. $scope.flgUpdateStatusByAdminSales = false;
  215. $scope.flgUpdateStatusByAdminGudang = false;
  216. $scope.flgShowRemarkInternal = false;
  217. $scope.flgInputRemarkInternal = false;
  218. $scope.flgInputDiscountHeader = false;
  219. $scope.flgShowDiscount = false;
  220. $scope.flgInputDiscount = false;
  221. $scope.flgShowTotalDeliveryDiscount = false;
  222. $scope.flgShowTotalOrderDiscount = false;
  223. $scope.flgShowTotalOrderAmountAfterDisc = false;
  224. $scope.flgShowTotalDeliveryAmountAfterDisc = false;
  225. $scope.flgShowTotalReceivedAmountAfterDisc = false;
  226. $scope.flgShowQtyReceive = false;
  227. $scope.flgShowRemark = false;
  228. $scope.flgShowRowForAdminSales = false;
  229. $scope.flgShowRowForAdminGudang = false;
  230. $scope.flgEditUnitPrice = false;
  231. $scope.flgEditQtyOrderFreeProduct = false;
  232.  
  233. $scope.flgD = false;
  234. $scope.flgR = false;
  235. $scope.flgS = false;
  236. $scope.flgF = false;
  237. $scope.flgC = false;
  238. }
  239.  
  240. $scope.setTrue = function(){
  241. $scope.setFalse();
  242.  
  243. if(($scope.roleName == $scope.roleAdmin || $scope.roleName == $scope.roleManagement) && ($scope.orderDetail.status == $scope.statusR || $scope.orderDetail.status == $scope.statusS || $scope.orderDetail.status == $scope.statusD)){
  244. $scope.flgUpdateStatusByAdminSales = true;
  245. }
  246.  
  247. if(($scope.roleName == $scope.roleAdmin || $scope.roleName == $scope.roleManagement) && ($scope.orderDetail.status == $scope.statusR || $scope.orderDetail.status == $scope.statusS)){
  248. $scope.flgShowTotalDeliveryDiscount = true;
  249. $scope.flgShowTotalDeliveryAmountAfterDisc = true;
  250. }
  251.  
  252. if(($scope.roleName == $scope.roleAdmin || $scope.roleName == $scope.roleManagement) && $scope.orderDetail.status == $scope.statusF){
  253. $scope.flgShowTotalReceivedDiscount = true;
  254. $scope.flgShowTotalReceivedAmountAfterDisc = true;
  255. }
  256.  
  257. if(($scope.roleName == $scope.roleGudang || $scope.roleName == $scope.roleManagement) && ($scope.orderDetail.status == $scope.statusR || $scope.orderDetail.status == $scope.statusS)){
  258. $scope.flgUpdateStatusByAdminGudang = true;
  259. }
  260.  
  261. if(($scope.roleName == $scope.roleAdmin || $scope.roleName == $scope.roleManagement) ){
  262. $scope.flgShowRowForAdminSales = true;
  263. $scope.flgShowRemark = true;
  264. $scope.flgShowRemarkInternal = true;
  265. $scope.flgShowDiscount = true;
  266. }
  267.  
  268. if(($scope.roleName == $scope.roleGudang || $scope.roleName == $scope.roleManagement) ){
  269. $scope.flgShowRowForAdminGudang = true;
  270. }
  271.  
  272. if($scope.orderDetail.status == $scope.statusR || $scope.orderDetail.status == $scope.statusD){
  273. $scope.flgInputRemarkInternal = true;
  274. }
  275.  
  276. if(($scope.roleName == $scope.roleAdmin || $scope.roleName == $scope.roleManagement) && $scope.orderDetail.status == $scope.statusD){
  277. $scope.flgInputDiscountHeader = true;
  278. }
  279.  
  280. if($scope.orderDetail.status == $scope.statusD || $scope.orderDetail.status == $scope.statusC){
  281. $scope.flgShowTotalOrderAmountAfterDisc = true;
  282. }
  283.  
  284. if($scope.orderDetail.status == $scope.statusD && ($scope.roleName == $scope.roleAdmin || $scope.roleName == $scope.roleManagement)){
  285. $scope.flgAddBonus = true;
  286. $scope.flgInputDiscount = true;
  287. $scope.flgEditUnitPrice = true;
  288. $scope.flgEditQtyOrderFreeProduct = true;
  289. }
  290. if($scope.orderDetail.status == $scope.statusD){
  291. $scope.flgD = false;
  292. $scope.flgR = true;
  293. $scope.flgS = false;
  294. $scope.flgF = false;
  295. $scope.flgC = true;
  296. }else if($scope.orderDetail.status == $scope.statusR){
  297. $scope.flgD = false;
  298. $scope.flgR = false;
  299. $scope.flgS = true;
  300. $scope.flgF = false;
  301. if(($scope.roleName == $scope.roleGudang || $scope.roleName == $scope.roleManagement))
  302. $scope.flgC = false;
  303. else
  304. $scope.flgC = true;
  305. }else if($scope.orderDetail.status == $scope.statusS){
  306. $scope.flgD = false;
  307. $scope.flgR = false;
  308. $scope.flgS = false;
  309. $scope.flgF = true;
  310. $scope.flgC = false;
  311. }else if($scope.orderDetail.status == $scope.statusF){
  312. $scope.flgD = false;
  313. $scope.flgR = false;
  314. $scope.flgS = false;
  315. $scope.flgF = false;
  316. $scope.flgC = false;
  317. $scope.flgShowQtyReceive = true;
  318. }else if($scope.orderDetail.status == $scope.statusC){
  319. $scope.flgD = false;
  320. $scope.flgR = false;
  321. $scope.flgS = false;
  322. $scope.flgF = false;
  323. $scope.flgC = false;
  324. }else{
  325. $scope.flgD = false;
  326. $scope.flgR = false;
  327. $scope.flgS = false;
  328. $scope.flgF = false;
  329. $scope.flgC = false;
  330. }
  331.  
  332. }
  333.  
  334.  
  335. $scope.checkTask = function($task){
  336. var taskList = window.Laravel.taskList;
  337. taskList = taskList.split(",");
  338. var index = taskList.indexOf($task);
  339. if(index == -1){
  340. return false;
  341. }else{
  342. return true;
  343. }
  344. }
  345. $scope.getOrderDetail = function(){
  346. $('#block').show();
  347. var input = {};
  348. input.orderId = $stateParams.orderId;
  349. CmsOrderService.getOrderDetail(input)
  350. .then(function(response){
  351. if(response.data.status == 'OK'){
  352. $scope.orderDetail = response.data.detailOrder;
  353. $scope.discountHeader = $scope.orderDetail.header_discount;
  354. // $scope.remarkInternal = $scope.orderDetail.remark_internal;
  355. if($scope.orderDetail.status == 'D' || $scope.orderDetail.status == 'C' || $scope.orderDetail.status == 'R') {
  356. $scope.flgDelivered = false;
  357. }else if($scope.orderDetail.status == 'S' || $scope.orderDetail.status == 'F'){
  358. $scope.flgDelivered = true;
  359. }else{
  360. swal('Error','Terjadi Kesalahan Pada Sistem','error');
  361. }
  362.  
  363. if($scope.orderDetail.status == 'D') {
  364. $scope.colspan = 4;
  365. }else{
  366. $scope.colspan = 3;
  367. }
  368.  
  369. var i = 1;
  370. angular.forEach($scope.orderDetail.orderItem,function(row){
  371. row.number = i;
  372. i++;
  373. });
  374. $scope.setTrue();
  375. $('#block').hide();
  376. }else{
  377. $('#block').hide();
  378. swal('Error',response.data.error,'error');
  379. }
  380. });
  381. }
  382.  
  383. $scope.getOrderDetail();
  384.  
  385. $scope.getOrderSO = function(){
  386. $('#block').show();
  387. var input = {};
  388. input.orderId = $stateParams.orderId;
  389. CmsOrderService.getOrderSO(input)
  390. .then(function(response){
  391. if(response.data.status == 'OK'){
  392. $scope.soList = response.data.orderList.orderList;
  393. console.log("SOLIST", $scope.soList)
  394. $('#block').hide();
  395. }else{
  396. $('#block').hide();
  397. swal('Error',response.data.error,'error');
  398. }
  399. });
  400. }
  401.  
  402. $scope.getItemList = function(order_external_id){
  403. $scope.expanded[order_external_id] = !$scope.expanded[order_external_id];
  404. var input = {
  405. orderExternalId : order_external_id
  406. };
  407. CmsOrderService.getOrderExternalItemList(input)
  408. .then(function(response){
  409. if(response.data.status == 'OK'){
  410. $scope.externalList[order_external_id] = response.data.orderExternalList.orderExternalList;
  411. $scope.orderExternal = order_external_id;
  412. $('#block').hide();
  413. }else{
  414. $('#block').hide();
  415. swal('Error',response.data.error,'error');
  416. }
  417. });
  418. }
  419.  
  420. $scope.getOrderSO();
  421. $scope.getItemList();
  422.  
  423. $scope.back = function(){
  424. window.history.back();
  425. }
  426.  
  427. $scope.updateStatus = function(status){
  428. var message;
  429. if(status == 'R'){
  430. message = 'Apakah anda yakin akan mengubah status order ini menjadi Dalam Proses';
  431. }else if(status == 'S'){
  432. message = 'Apakah anda yakin akan mengubah status order ini menjadi Dalam Pengiriman Toko';
  433. }else if(status == 'F'){
  434. message = 'Apakah anda yakin akan mengubah status order ini menjadi Diterima Toko';
  435. }else if(status == 'C'){
  436. message = 'Apakah anda yakin akan mengubah status order ini menjadi Dibatalkan';
  437. }
  438.  
  439. swal({
  440. title: "Update Status?",
  441. text: message,
  442. type: "warning",
  443. showCancelButton: true,
  444. confirmButtonText: "Yes"
  445. })
  446. .then((result)=>{
  447. if(result.value){
  448. $('#block').show();
  449. var input = {};
  450. input.orderId = $stateParams.orderId;
  451. input.status = status;
  452. CmsOrderService.updateStatusOrder(input)
  453. .then(function(response){
  454. if(response.data.status == 'OK'){
  455. if(status == 'R'){
  456. $scope.editDiscountHeader();
  457. }
  458. $scope.getOrderDetail();
  459. $scope.closeModalStatus();
  460. }else{
  461. $('#block').hide();
  462. swal('Error',response.data.error,'error');
  463. }
  464. });
  465. }
  466. })
  467. }
  468.  
  469. $scope.closeModalStatus = function(){
  470. $('#statusModal').modal('hide');
  471. }
  472.  
  473. $scope.calculateDiscountHeader = function(){
  474. console.log($scope.discountHeaderPercent);
  475. $scope.discountHeader = $scope.orderDetail.total_order_amount * ($scope.discountHeaderPercent / 100);
  476. }
  477.  
  478. $scope.editDiscountHeader = function(){
  479. $('#block').show();
  480. var input = {};
  481. input.discountHeader = $scope.discountHeader;
  482. input.discountHeaderPercent = $scope.discountHeaderPercent;
  483. input.orderId = $stateParams.orderId;
  484. console.log(input);
  485. CmsOrderService.editDiscountHeader(input)
  486. .then(function(response){
  487. if(response.data.status == 'OK'){
  488. $scope.getOrderDetail();
  489. }else{
  490. $('#block').hide();
  491. swal('Error',response.data.error,'error');
  492. }
  493. });
  494. }
  495.  
  496. $scope.editDiscountItem = function(id){
  497. $('#block').show();
  498. var input = {};
  499. input.orderId = $stateParams.orderId;
  500. input.orderItemId = id;
  501. if($scope.discountItemPercent == undefined){
  502. $scope.closeModalDiscountItem();
  503. $('#block').hide();
  504. return [];
  505. }else{
  506. input.discountItemPercent = $scope.discountItemPercent;
  507. }
  508. CmsOrderService.editDiscountItem(input)
  509. .then(function(response){
  510. if(response.data.status == 'OK'){
  511. $scope.getOrderDetail();
  512. $scope.closeModalDiscountItem();
  513. $scope.discountItemPercent = undefined;
  514. }else{
  515. $('#block').hide();
  516. swal('Error',response.data.error,'error');
  517. }
  518. });
  519. }
  520.  
  521. $scope.openModalDiscountItem = function(item,id){
  522. $scope.oldDiscountItem = item;
  523. $scope.discountItemPercent = undefined;
  524. $('#discountModal').modal('show');
  525. $scope.selectedOrderItem = id;
  526. }
  527. $scope.closeModalDiscountItem = function(){
  528. $('#discountModal').modal('hide');
  529. }
  530.  
  531. $scope.editQtyDeliveryItem = function(id){
  532. $('#block').show();
  533. var input = {};
  534. input.orderId = $stateParams.orderId;
  535. input.orderItemId = id;
  536. if($scope.qtyDelivery == undefined){
  537. $scope.closeModalQtyDeliveryItem();
  538. $('#block').hide();
  539. return [];
  540. }else{
  541. $('#block').hide();
  542. input.qtyDelivery = $scope.qtyDelivery;
  543. if(input.qtyDelivery < 0) {
  544. sweetAlert('Error', 'Qty Kirim harus lebih dari 0', 'error');
  545. return;
  546. }
  547. }
  548. CmsOrderService.editQtyDeliveryItem(input)
  549. .then(function(response){
  550. if(response.data.status == 'OK'){
  551. $scope.getOrderDetail();
  552. $scope.closeModalQtyDeliveryItem();
  553. $scope.qtyDelivery = undefined;
  554. }else{
  555. $('#block').hide();
  556. swal('Error',response.data.error,'error');
  557. }
  558. });
  559. }
  560.  
  561. $scope.openModalQtyDeliveryItem = function(item,id){
  562. $scope.oldQtyDelivery = item;
  563. $('#qtyDevModal').modal('show');
  564. $scope.selectedOrderItem = id;
  565. $scope.qtyDelivery = item.qty_delivery;
  566. }
  567. $scope.closeModalQtyDeliveryItem = function(){
  568. $('#qtyDevModal').modal('hide');
  569. }
  570.  
  571. // $scope.addFreeProduct = function(id){
  572. // $('#block').show();
  573. // var input = {};
  574. // input.orderId = $stateParams.orderId;
  575. // input.orderItemId = id;
  576. // CmsOrderService.addFreeProduct(input)
  577. // .then(function(response){
  578. // if(response.data.status == 'OK'){
  579. // $scope.getOrderDetail();
  580. // }else{
  581. // $('#block').hide();
  582. // swal('Error',response.data.error,'error');
  583. // }
  584. // });
  585. // }
  586.  
  587. $scope.removeFreeProduct = function(id){
  588. $('#block').show();
  589. var input = {};
  590. input.orderId = $stateParams.orderId;
  591. input.orderItemId = id;
  592. CmsOrderService.removeFreeProduct(input)
  593. .then(function(response){
  594. if(response.data.status == 'OK'){
  595. $scope.getOrderDetail();
  596. }else{
  597. $('#block').hide();
  598. swal('Error',response.data.error,'error');
  599. }
  600. });
  601. }
  602.  
  603. $scope.editQtyOrderFreeProduct = function(id){
  604. $('#block').show();
  605. var input = {};
  606. input.orderId = $stateParams.orderId;
  607. input.orderItemId = id;
  608. if($scope.qtyOrder == undefined){
  609. $scope.closeModalQtyOrderFreeProduct();
  610. $('#block').hide();
  611. return [];
  612. }else{
  613. input.qtyOrder = $scope.qtyOrder;
  614. }
  615. CmsOrderService.editQtyOrderFreeProduct(input)
  616. .then(function(response){
  617. if(response.data.status == 'OK'){
  618. $scope.getOrderDetail();
  619. $scope.closeModalQtyOrderFreeProduct();
  620. $scope.unitPrice = undefined;
  621. }else{
  622. $('#block').hide();
  623. swal('Error',response.data.error,'error');
  624. }
  625. });
  626. }
  627.  
  628. $scope.openModalQtyOrderFreeProduct = function(item,id){
  629. $scope.qtyOrder = undefined;
  630. $scope.oldQtyOrderForFree = item;
  631. $('#qtyOrderModal').modal('show');
  632. $scope.selectedOrderItem = id;
  633. }
  634. $scope.closeModalQtyOrderFreeProduct = function(){
  635. $('#qtyOrderModal').modal('hide');
  636. }
  637.  
  638. $scope.editUnitPriceOrderItem = function(id){
  639. $('#block').show();
  640. var input = {};
  641. input.orderId = $stateParams.orderId;
  642. input.orderItemId = id;
  643. if($scope.unitPrice == undefined){
  644. $scope.closeModalUnitPrice();
  645. $('#block').hide();
  646. return [];
  647. }else{
  648. $('#block').hide();
  649. input.unitPrice = $scope.unitPrice;
  650. if(input.unitPrice < 0){
  651. swal('Error','Unit price harus lebih dari 0','error');
  652. return;
  653. }
  654. }
  655. CmsOrderService.editUnitPriceOrderItem(input)
  656. .then(function(response){
  657. if(response.data.status == 'OK'){
  658. $scope.getOrderDetail();
  659. $scope.closeModalUnitPrice();
  660. $scope.unitPrice = undefined;
  661. }else{
  662. $('#block').hide();
  663. swal('Error',response.data.error,'error');
  664. }
  665. });
  666. }
  667.  
  668. $scope.openModalUnitPrice = function(item,id){
  669. $scope.oldUnitPrice = item;
  670. $scope.unitPrice = undefined;
  671. $('#unitPriceModal').modal('show');
  672. $scope.selectedOrderItem = id;
  673. }
  674. $scope.closeModalUnitPrice = function(){
  675. $('#unitPriceModal').modal('hide');
  676. }
  677.  
  678. $scope.openModalRemarkInternal = function(order){
  679. $scope.orderRemarkEdited = order;
  680. $scope.remarkInternal = order.remark_internal;
  681. $('#remarkInternalModal').modal('show');
  682. }
  683. $scope.closeModalRemarkInternal = function(){
  684. $('#remarkInternalModal').modal('hide');
  685. }
  686.  
  687. $scope.addRemarkInternalOrder = function(order){
  688. $('#block').show();
  689. var input = {};
  690. input.orderId = $stateParams.orderId;
  691. input.remarkInternal = $scope.remarkInternal;
  692. CmsOrderService.addRemarkInternalOrder(input)
  693. .then(function(response){
  694. if(response.data.status == 'OK'){
  695. // $scope.getOrderDetail();
  696. order.remark_internal = $scope.remarkInternal;
  697. $scope.closeModalRemarkInternal();
  698. $('#block').hide();
  699. // swal('Success','Keterangan Telah Disimpan','success');
  700. }else{
  701. $('#block').hide();
  702. swal('Error',response.data.error,'error');
  703. }
  704. });
  705. }
  706.  
  707. $scope.openModalQtyTerima = function(){
  708. $('#block').show();
  709.  
  710. var input = {};
  711. input.orderId = $stateParams.orderId;
  712. CmsOrderService.getOrderItemByOrderId(input)
  713. .then(function(response){
  714. if(response.data.status == 'OK'){
  715. $scope.qtyTerimaList = response.data.orderItemList;
  716. angular.forEach($scope.qtyTerimaList,function(row){
  717. row.qty_received = row.qty_delivery;
  718. });
  719. $('#qtyTerimaModal').modal('show');
  720. $('#block').hide();
  721. }else{
  722. $('#block').hide();
  723. swal('Error',response.data.error,'error');
  724. }
  725. });
  726. }
  727. $scope.closeModalQtyTerima = function(){
  728. $('#qtyTerimaModal').modal('hide');
  729. }
  730.  
  731. $scope.saveQtyTerima = function(){
  732. $('#block').show();
  733. var input = {};
  734. input.orderItem = $scope.qtyTerimaList;
  735. input.orderId = $stateParams.orderId;
  736. console.log(input);
  737. CmsOrderService.editQtyTerimaOrderItem(input)
  738. .then(function(response){
  739. if(response.data.status == 'OK'){
  740. $scope.getOrderDetail();
  741. $('#qtyTerimaModal').modal('hide');
  742. $('#statusModal').modal('hide');
  743. $('#block').hide();
  744. }else{
  745. $('#block').hide();
  746. swal('Error',response.data.error,'error');
  747. }
  748. });
  749. }
  750.  
  751. $scope.openFreeProductModal = function(item){
  752. $('#block').show();
  753. $scope.qtyOrderFreeProduct = undefined;
  754. $('#freeProductModal').modal('show');
  755. var input = {};
  756. input.styleProduct = item.style_product;
  757. CmsOrderService.getProductListByStyleProduct(input)
  758. .then(function(response){
  759. if(response.data.status == 'OK'){
  760. $scope.productByStyle = response.data.productList;
  761. $scope.freeProduct = item;
  762. $('#block').hide();
  763. }else{
  764. $('#block').hide();
  765. swal('Error',response.data.error,'error');
  766. }
  767. });
  768. }
  769. $scope.closeFreeProductModal = function(item){
  770. $('#freeProductModal').modal('hide');
  771. }
  772.  
  773. $scope.addFreeProduct = function(freeProduct){
  774. $('#block').show();
  775. var input = {};
  776. if(angular.isUndefined($scope.productByStyle.selected) || angular.isUndefined($scope.productByStyle.selected.product_id)){
  777. input.productId = freeProduct.product_id;
  778. input.productPrice = freeProduct.unit_price;
  779. }else{
  780. input.productId = $scope.productByStyle.selected.product_id;
  781. input.productPrice = $scope.productByStyle.selected.sell_price;
  782. }
  783. input.orderId = $stateParams.orderId;
  784. input.orderItemId = freeProduct.order_item_id;
  785. input.qtyOrder = $scope.qtyOrderFreeProduct;
  786. input.discPc = freeProduct.disc_pc;
  787.  
  788. CmsOrderService.addFreeProduct(input)
  789. .then(function(response){
  790. if(response.data.status == 'OK'){
  791. $scope.getOrderDetail();
  792. $('#freeProductModal').modal('hide');
  793. }else{
  794. $('#block').hide();
  795. swal('Error',response.data.error,'error');
  796. }
  797. });
  798. }
  799.  
  800. }
  801.  
  802. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement