widana

3

Jan 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. /**
  2. * Created by sts on 21/05/18.
  3. */
  4. (function (){
  5.  
  6. 'use strict';
  7.  
  8. angular.module('tokoModule')
  9. .controller('RegisterTokoController', RegisterTokoController);
  10.  
  11. RegisterTokoController.$inject = ['$uibModalInstance', 'items','RestService', 'ApiConstant', 'TokoService'];
  12.  
  13. function RegisterTokoController($uibModalInstance, items, RestService, ApiConstant, TokoService) {
  14. var $ctrl = this;
  15.  
  16. $ctrl.inputToko = {};
  17. $ctrl.current_status_toko = 'Agen';
  18.  
  19. $ctrl.initYearMonthList = function() {
  20. $ctrl.yearMonthList = [];
  21. var today = new Date();
  22. var mm = today.getMonth()+1;
  23. if(mm<10){
  24. var mmNow = '0'+mm;
  25. } else {
  26. var mmNow = mm;
  27. }
  28. var yyyyNow = today.getFullYear(),
  29. counter = 0;
  30. for(var i=yyyyNow; i<=(yyyyNow+2); i++){
  31. for (var j = 1; j <= 12; j++) {
  32. if(i==yyyyNow && j<mm) continue;
  33. if(counter>=24) break;
  34.  
  35. if(j<10){
  36. j = '0'+j;
  37. }
  38. var ym = i+''+j;
  39. var ymd = i+'-'+j+'-01';
  40. var date = new Date(ymd);
  41.  
  42. $ctrl.yearMonthList.push({
  43. key : ym,
  44. value : date.toLocaleString("in-IN", { year: "numeric", month: "long"})
  45. });
  46. counter++;
  47. }
  48. }
  49.  
  50. $ctrl.inputToko.start_date_trx = $ctrl.yearMonthList[0].key;
  51. }
  52.  
  53. $ctrl.initYearMonthList();
  54.  
  55. $ctrl.resetForm = function () {
  56. $ctrl.inputToko = {};
  57. $ctrl.initYearMonthList();
  58. };
  59.  
  60. $ctrl.checkValidateToko = function(id) {
  61. if(id != undefined) {
  62. TokoService.checkTokoByTokoIdSas(id).then(function (result) {
  63. if (result.data.result.exists) {
  64. // Toko sudah terdaftar di database
  65. errorAlert(result.data.result.message);
  66. } else {
  67.  
  68. TokoService.checkValidateToko(id)
  69. .then(function (result) {
  70. if (result.data.success) {
  71.  
  72. $ctrl.resetForm();
  73.  
  74. var data = result.data.result;
  75. $ctrl.inputToko.ou_company = data.nama_toko;
  76. $ctrl.inputToko.ou_branch = data.nama_cabang;
  77. $ctrl.inputToko.ou_sub_branch = data.nama_sub_cabang;
  78. $ctrl.inputToko.email = "";
  79. $ctrl.inputToko.warehouse_name = "DEFAULT";
  80. $ctrl.inputToko.warehouse_code = "DEFAULT";
  81. $ctrl.inputToko.cashbank_name = "KAS";
  82. $ctrl.inputToko.cashbank_code = "KAS";
  83. $ctrl.inputToko.record_owner_code = data.kode_toko;
  84. $ctrl.inputToko.toko_id_sas = id;
  85. $ctrl.inputToko.current_status_toko = data.peran;
  86.  
  87. successAlert("ID Toko SAS : " + data.kode_toko +
  88. " telah terdaftarkan pada sistem SAS, Silakan klik submit, agar data toko"
  89. + " tersimpan pada sistem ini");
  90.  
  91. } else {
  92. errorAlert(result.data.error_message);
  93. // $ctrl.resetForm();
  94. }
  95. }, function error() {
  96. errorAlert("Terjadi kesalahan pada server");
  97. });
  98.  
  99. }
  100. });
  101. }
  102.  
  103. };
  104.  
  105. $ctrl.addToko = function() {
  106. if($ctrl.inputToko.toko_id_sas === undefined || $ctrl.inputToko.toko_id_sas == '' || $ctrl.inputToko.toko_id_sas==null){
  107. errorAlert("ID Toko SAS harus diisi");
  108. return false;
  109. }
  110.  
  111. // dd($ctrl.inputToko);
  112. if($ctrl.inputToko.record_owner_code === undefined || $ctrl.inputToko.record_owner_code == '' || $ctrl.inputToko.record_owner_code == null){
  113. errorAlert("Toko ID SAS belum dicek validasi, silahkan input Toko ID SAS "
  114. +" lalu daftarkan");
  115. return false;
  116. }
  117.  
  118. RestService.call({
  119. "name" : "addToko",
  120. "task": "addToko"
  121. }, $ctrl.inputToko)
  122. .then(function(response) {
  123. var result = response.result;
  124. if(result.status == "OK"){
  125. $ctrl.resetForm();
  126. $uibModalInstance.close({
  127. success: true,
  128. infoUserPassword: result.userPassword
  129. })
  130. } else {
  131. errorAlert(result.errorList.error_message);
  132. }
  133. }).catch(function(err) {
  134. errorAlert("terjadi kesalahan pada server");
  135. });
  136.  
  137. };
  138.  
  139.  
  140. $ctrl.cancel = function () {
  141. $uibModalInstance.dismiss('cancel');
  142. }
  143.  
  144.  
  145.  
  146. }
  147.  
  148.  
  149. })();
Add Comment
Please, Sign In to add comment