Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by sts on 21/05/18.
- */
- (function (){
- 'use strict';
- angular.module('tokoModule')
- .controller('RegisterTokoController', RegisterTokoController);
- RegisterTokoController.$inject = ['$uibModalInstance', 'items','RestService', 'ApiConstant', 'TokoService'];
- function RegisterTokoController($uibModalInstance, items, RestService, ApiConstant, TokoService) {
- var $ctrl = this;
- $ctrl.inputToko = {};
- $ctrl.current_status_toko = 'Agen';
- $ctrl.initYearMonthList = function() {
- $ctrl.yearMonthList = [];
- var today = new Date();
- var mm = today.getMonth()+1;
- if(mm<10){
- var mmNow = '0'+mm;
- } else {
- var mmNow = mm;
- }
- var yyyyNow = today.getFullYear(),
- counter = 0;
- for(var i=yyyyNow; i<=(yyyyNow+2); i++){
- for (var j = 1; j <= 12; j++) {
- if(i==yyyyNow && j<mm) continue;
- if(counter>=24) break;
- if(j<10){
- j = '0'+j;
- }
- var ym = i+''+j;
- var ymd = i+'-'+j+'-01';
- var date = new Date(ymd);
- $ctrl.yearMonthList.push({
- key : ym,
- value : date.toLocaleString("in-IN", { year: "numeric", month: "long"})
- });
- counter++;
- }
- }
- $ctrl.inputToko.start_date_trx = $ctrl.yearMonthList[0].key;
- }
- $ctrl.initYearMonthList();
- $ctrl.resetForm = function () {
- $ctrl.inputToko = {};
- $ctrl.initYearMonthList();
- };
- $ctrl.checkValidateToko = function(id) {
- if(id != undefined) {
- TokoService.checkTokoByTokoIdSas(id).then(function (result) {
- if (result.data.result.exists) {
- // Toko sudah terdaftar di database
- errorAlert(result.data.result.message);
- } else {
- TokoService.checkValidateToko(id)
- .then(function (result) {
- if (result.data.success) {
- $ctrl.resetForm();
- var data = result.data.result;
- $ctrl.inputToko.ou_company = data.nama_toko;
- $ctrl.inputToko.ou_branch = data.nama_cabang;
- $ctrl.inputToko.ou_sub_branch = data.nama_sub_cabang;
- $ctrl.inputToko.email = "";
- $ctrl.inputToko.warehouse_name = "DEFAULT";
- $ctrl.inputToko.warehouse_code = "DEFAULT";
- $ctrl.inputToko.cashbank_name = "KAS";
- $ctrl.inputToko.cashbank_code = "KAS";
- $ctrl.inputToko.record_owner_code = data.kode_toko;
- $ctrl.inputToko.toko_id_sas = id;
- $ctrl.inputToko.current_status_toko = data.peran;
- successAlert("ID Toko SAS : " + data.kode_toko +
- " telah terdaftarkan pada sistem SAS, Silakan klik submit, agar data toko"
- + " tersimpan pada sistem ini");
- } else {
- errorAlert(result.data.error_message);
- // $ctrl.resetForm();
- }
- }, function error() {
- errorAlert("Terjadi kesalahan pada server");
- });
- }
- });
- }
- };
- $ctrl.addToko = function() {
- if($ctrl.inputToko.toko_id_sas === undefined || $ctrl.inputToko.toko_id_sas == '' || $ctrl.inputToko.toko_id_sas==null){
- errorAlert("ID Toko SAS harus diisi");
- return false;
- }
- // dd($ctrl.inputToko);
- if($ctrl.inputToko.record_owner_code === undefined || $ctrl.inputToko.record_owner_code == '' || $ctrl.inputToko.record_owner_code == null){
- errorAlert("Toko ID SAS belum dicek validasi, silahkan input Toko ID SAS "
- +" lalu daftarkan");
- return false;
- }
- RestService.call({
- "name" : "addToko",
- "task": "addToko"
- }, $ctrl.inputToko)
- .then(function(response) {
- var result = response.result;
- if(result.status == "OK"){
- $ctrl.resetForm();
- $uibModalInstance.close({
- success: true,
- infoUserPassword: result.userPassword
- })
- } else {
- errorAlert(result.errorList.error_message);
- }
- }).catch(function(err) {
- errorAlert("terjadi kesalahan pada server");
- });
- };
- $ctrl.cancel = function () {
- $uibModalInstance.dismiss('cancel');
- }
- }
- })();
Add Comment
Please, Sign In to add comment