Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- 'use strict';
- console.warn = function () {
- };
- var isProductionApplication = true;
- function config ( $httpProvider , $stateProvider , $urlRouterProvider , uiGmapGoogleMapApiProvider , $mdThemingProvider , $mdIconProvider , iconsUrls , $provide ) {
- uiGmapGoogleMapApiProvider.configure ( {
- key : 'AIzaSyCsbEsgOYk2FhLgvVp_1Yct-kj5XOueaAE' ,
- v : '3.17' ,
- libraries : 'geometry,visualization,drawing'
- } );
- //=====================================================================
- //HTTP
- //=====================================================================
- $httpProvider.defaults.withCredentials = true;
- $httpProvider.defaults.headers.common[ 'Content-Type' ] = "application/json;charset=utf-8";
- // # reduce the number of $apply calls
- $httpProvider.useApplyAsync ( true );
- $httpProvider.interceptors.push ( function ( $q , $log , $rootScope , $window ) {
- return {
- 'response' : function ( response ) {
- //detecting login page:
- if ( _.has ( response , 'data' ) && typeof response.data === 'string' ) {
- if ( response.data.indexOf ( '<!DOCTYPE html>' ) != -1 ) {
- //yeap, it's the login page
- $window.location = "/";
- }
- }
- return response;
- } ,
- 'responseError' : function ( rejection ) {
- $rootScope.$broadcast ( 'showAPICallError' , rejection );
- return $q.reject ( rejection );
- }
- };
- } );
- $mdThemingProvider.theme ( 'default' ).primaryPalette ( 'light-blue' );
- //register icons
- angular.forEach ( iconsUrls , function ( url ) {
- $mdIconProvider.icon ( url.alias , url.uri , 24 );
- } );
- //=====================================================================
- // STATES
- //=====================================================================
- $urlRouterProvider
- .when ( '/' , '/main' )
- .otherwise ( '/' );
- $stateProvider
- .state ( "dashboard" , {
- url : "/" ,
- templateUrl : 'views/dashboard.html'
- } )
- .state ( "dashboard.main" , {
- url : "main" ,
- views : {
- '' : {
- templateUrl : 'views/main_dashboard.html' ,
- controller : "dashboardController"
- }
- }
- } )
- .state ( "dashboard.administrare" , {
- url : "admin" ,
- views : {
- '' : {
- templateUrl : 'views/admin_dashboard.html' ,
- controller : "adminDashboardController"
- }
- }
- } )
- .state ( 'lucrari' , {
- abstract : true ,
- url : '/lucrari' ,
- templateUrl : 'views/rapoarte/lucrari_main.html'
- } )
- .state ( 'lucrari.lista' , {
- url : '/lista' ,
- views : {
- '' : {
- templateUrl : 'views/rapoarte/rapoarte_lucrari.html' ,
- controller : 'rapoarteLucrariController'
- }
- }
- } )
- // .state('lucrari.rapoarte-ferme', {
- // url: '/rapoarte-ferme',
- // views: {
- // '': {
- // templateUrl: 'views/rapoarte/rapoarte_ferme.html',
- // controller: 'rapoarteFermeController'
- // }
- // }
- // })
- .state ( 'lucrari.toate' , {
- url : '/toate' ,
- views : {
- '' : {
- templateUrl : 'views/rapoarte/rapoarte_lucrari_all.html' ,
- controller : 'rapoarteLucrariToateController'
- }
- }
- } )
- .state ( 'lucrari.rapoarte' , {
- url : '/rapoarte' ,
- views : {
- '' : {
- templateUrl : 'views/rapoarte/rapoarte_sole.html' ,
- controller : "rapoartePeSoleController"
- }
- }
- } )
- .state ( 'lucrari.grafice' , {
- url : '/grafice' ,
- views : {
- '' : {
- templateUrl : 'views/rapoarte/rapoarte_grafice.html' ,
- controller : "rapoarteGraficeController"
- }
- }
- } )
- .state ( 'note' , {
- abstract : true ,
- url : '/note' ,
- templateUrl : 'views/note/note_main.html'
- } )
- .state ( 'note.lista' , {
- url : '/lista' ,
- views : {
- '' : {
- templateUrl : 'views/note/note_lista.html' ,
- controller : "listaNoteController"
- }
- }
- } )
- .state ( 'sole' , {
- abstract : true ,
- url : '/sole' ,
- templateUrl : 'views/sole/sole_main.html'
- } )
- .state ( 'sole.lista' , {
- url : '/lista' ,
- views : {
- '' : {
- templateUrl : 'views/sole/sole_lista.html' ,
- controller : "listaSoleController"
- }
- }
- } )
- .state ( 'nomenclator' , {
- abstract : true ,
- url : '/nomenclatoare' ,
- templateUrl : 'views/nomenclatoare/nomenclatoare_main.html'
- } )
- .state ( 'nomenclator.fertilizari' , {
- url : '/fertilizari' ,
- views : {
- '' : {
- templateUrl : 'views/nomenclatoare/fertilizari.html' ,
- controller : "nomenclatorFertilizariController"
- }
- }
- } )
- .state ( 'nomenclator.echipamente' , {
- url : '/echipamente' ,
- views : {
- '' : {
- templateUrl : 'views/nomenclatoare/echipamente.html' ,
- controller : "nomenclatorEchipamenteController"
- }
- }
- } )
- .state ( 'nomenclator.tratamente' , {
- url : '/tratamente' ,
- views : {
- '' : {
- templateUrl : 'views/nomenclatoare/tratamente.html' ,
- controller : "nomenclatorTratamenteController"
- }
- }
- } )
- .state ( 'nomenclator.culturi' , {
- url : '/culturi' ,
- views : {
- '' : {
- templateUrl : 'views/nomenclatoare/culturi.html' ,
- controller : "nomenclatorCulturiController"
- }
- }
- } )
- .state ( 'nomenclator.lucrari' , {
- url : '/lucrari' ,
- views : {
- '' : {
- templateUrl : 'views/unused/lucrari.html' ,
- controller : "nomenclatorLucrariController"
- }
- }
- } )
- .state ( 'utilizatori' , {
- abstract : true ,
- url : '/utilizatori' ,
- templateUrl : 'views/utilizatori/utilizatori_main.html'
- } )
- .state ( 'utilizatori.lista' , {
- url : '/lista' ,
- views : {
- '' : {
- templateUrl : 'views/utilizatori/utilizatori_lista.html' ,
- controller : "listaUtilizatoriController"
- }
- }
- } )
- .state ( 'ferme' , {
- abstract : true ,
- url : '/ferme' ,
- templateUrl : 'views/ferme/ferme_main.html'
- } )
- .state ( 'ferme.lista' , {
- url : '/lista' ,
- views : {
- '' : {
- templateUrl : 'views/ferme/ferme_lista.html' ,
- controller : "listaFermeController"
- }
- }
- } )
- .state ( 'companii' , {
- abstract : true ,
- url : '/companii' ,
- templateUrl : 'views/companii/companii_main.html'
- } )
- .state ( 'companii.lista' , {
- url : '/lista' ,
- views : {
- '' : {
- templateUrl : 'views/companii/companii_lista.html' ,
- controller : "listaCompaniiController"
- }
- }
- } );
- // if(isProductionApplication) {
- // $provide.decorator("$exceptionHandler", ['$delegate', '$injector', function ($delegate, $injector) {
- // return function (exception, cause) {
- // var $rootScope = $injector.get('$rootScope');
- //
- // function removeAngularTrace(stack) {
- // var arr = stack.split('\n'),
- // index = arr.length;
- // while (index) {
- // index -= 1;
- // if (arr[index].toLowerCase().indexOf('angular') > -1) {
- // arr.splice(index, 1);
- // }
- // }
- // return arr.join("\n");
- // }
- //
- // var smallMessage = removeAngularTrace(exception.stack);
- // console.error(smallMessage, cause);
- // $rootScope.$broadcast('globalException', {
- // exception: smallMessage,
- // cause: cause
- // });
- // // (Optional) Pass the error through to the delegate
- // //$delegate(exception, cause);
- // }
- // }]);
- // }
- //$provide.decorator('$state', function($delegate, $stateParams) {
- // $delegate.forceReload = function() {
- // return $delegate.go($delegate.current, $stateParams, {
- // reload: true,
- // inherit: false,
- // notify: true
- // });
- // };
- // return $delegate;
- //});
- // # Force reload the page. Hopefully we won't get in an infinite loop. Decorated state provider in app.js,
- }
- config.$inject = [ '$httpProvider' , '$stateProvider' , '$urlRouterProvider' , 'uiGmapGoogleMapApiProvider' , '$mdThemingProvider' , '$mdIconProvider' , 'iconsUrls' , '$provide' ];
- angular.module ( 'sefDeFermaApp' ,
- [
- 'ngCookies' ,
- 'ui.router' ,
- 'ngAnimate' ,
- 'ngMaterial' ,
- 'uiGmapgoogle-maps' ,
- 'angularLoad' ,
- 'mdTable' ,
- 'input-directives' ,
- 'ngFileUpload' ,
- 'dynamicForm' ,
- 'mdDatePicker' ,
- 'angularLocalStorage' ,
- 'mp.colorPicker' ,
- 'ngMessages'
- ] )
- .constant ( "REPORTS_URL" , isProductionApplication ? "http://clienti.sefdeferma.ro/api/public/" : "http://ferma.dev/api/public/" )
- .constant ( "APP_URL" , isProductionApplication ? "http://clienti.sefdeferma.ro/api/v1" : "http://ferma.dev/api/v1" )
- .constant ( "IS_PRODUCTION" , isProductionApplication )
- .constant ( "BUTTON" , 'BUTTON' )
- .constant ( "DAUNATORUL" , 'daunatorul' )
- .constant ( "DOZE_RECOMANDATE" , 'doze recomandate' )
- .constant ( "DOZA_UTILIZATA" , 'doza utilizata' )
- .constant ( "TRATAMENT" , 'tratament' )
- .constant ( "CULTURA" , 'cultura' )
- .constant ( "FERTILIZATOR" , 'fertil' )
- .constant ( "COST" , 'cost' )
- .constant ( "KG" , 'kilogr' )
- .constant ( "CANTITATE" , 'cantitate' )
- .constant ( "INTORS_CULTURA" , 'intors' )
- .constant ( "DENSITATE" , 'densitate' )
- .constant ( "SEMANAT" , 'semanat' )
- .constant ( "KM1" , 'pret pe kilometru' )
- .constant ( "KM2" , 'numar kilometri' )
- .constant ( 'COSTKG' , 'st kg' )
- .constant ( 'iconsUrls' ,
- [
- {
- uri : 'css/icons/album.svg' ,
- alias : 'album'
- } ,
- {
- uri : 'css/icons/import.svg' ,
- alias : 'import'
- } ,
- {
- uri : 'css/icons/arrow-up.svg' ,
- alias : 'arrow-up'
- } ,
- {
- uri : 'css/icons/arrow-down.svg' ,
- alias : 'arrow-down'
- } ,
- {
- uri : 'css/icons/alert.svg' ,
- alias : 'alert'
- } ,
- {
- uri : 'css/icons/account-key.svg' ,
- alias : 'account-key'
- } ,
- {
- uri : 'css/icons/plus.svg' ,
- alias : 'plus'
- } ,
- {
- uri : 'css/icons/bookmark-check.svg' ,
- alias : 'bookmark-check'
- } ,
- {
- uri : 'css/icons/folder-move.svg' ,
- alias : 'folder-move'
- } ,
- {
- uri : 'css/icons/menu.svg' ,
- alias : 'menu'
- } ,
- {
- uri : 'css/icons/view-carousel.svg' ,
- alias : 'view-carousel'
- } ,
- {
- uri : 'css/icons/logout.svg' ,
- alias : 'logout'
- } ,
- {
- uri : 'css/icons/library-plus.svg' ,
- alias : 'library-plus'
- } ,
- {
- uri : 'css/icons/dice-2.svg' ,
- alias : 'dice-2'
- } ,
- {
- uri : 'css/icons/magnify.svg' ,
- alias : 'magnify'
- } ,
- {
- uri : 'css/icons/chevron-left.svg' ,
- alias : 'chevron-left'
- } ,
- {
- uri : 'css/icons/chevron-right.svg' ,
- alias : 'chevron-right'
- } ,
- {
- uri : 'css/icons/chevron-up.svg' ,
- alias : 'chevron-up'
- } ,
- {
- uri : 'css/icons/chevron-down.svg' ,
- alias : 'chevron-down'
- } ,
- {
- uri : 'css/icons/close.svg' ,
- alias : 'close'
- } ,
- {
- uri : 'css/icons/alarm.svg' ,
- alias : 'alarm'
- } ,
- {
- uri : 'css/icons/alert.svg' ,
- alias : 'alert'
- } ,
- {
- uri : 'css/icons/account-check.svg' ,
- alias : 'account-check'
- } ,
- {
- uri : 'css/icons/account.svg' ,
- alias : 'account'
- } ,
- {
- uri : 'css/icons/account-remove.svg' ,
- alias : 'account-remove'
- } ,
- {
- uri : 'css/icons/account-key.svg' ,
- alias : 'account-key'
- } ,
- {
- uri : 'css/icons/check.svg' ,
- alias : 'check'
- } ,
- {
- uri : 'css/icons/check-all.svg' ,
- alias : 'check-all'
- } ,
- {
- uri : 'css/icons/cloud-check.svg' ,
- alias : 'cloud-check'
- } ,
- {
- uri : 'css/icons/delete.svg' ,
- alias : 'delete'
- } ,
- {
- uri : 'css/icons/settings.svg' ,
- alias : 'settings'
- } ,
- {
- uri : 'css/icons/database-outline.svg' ,
- alias : 'database-outline'
- } ,
- {
- uri : 'css/icons/calendar-multiple-check.svg' ,
- alias : 'calendar-multiple-check'
- } ,
- {
- uri : 'css/icons/pencil.svg' ,
- alias : 'pencil'
- } ,
- {
- uri : 'css/icons/home.svg' ,
- alias : 'home'
- } ,
- {
- uri : 'css/icons/arrow-collapse.svg' ,
- alias : 'arrow-collapse'
- } ,
- {
- uri : 'css/icons/arrow-expand.svg' ,
- alias : 'arrow-expand'
- } ,
- {
- uri : 'css/icons/watch-export.svg' ,
- alias : 'watch-export'
- } ,
- {
- uri : 'css/icons/wizard.svg' ,
- alias : 'wizard'
- } ,
- {
- uri : 'css/icons/android-studio.svg' ,
- alias : 'android-studio'
- } ,
- {
- uri : 'css/icons/fullscreen.svg' ,
- alias : 'fullscreen'
- } ,
- {
- uri : 'css/icons/fullscreen-exit.svg' ,
- alias : 'fullscreen-exit'
- } ,
- {
- uri : 'css/icons/people.svg' ,
- alias : 'people'
- } ,
- {
- uri : 'css/icons/money.svg' ,
- alias : 'money'
- } ,
- {
- uri : 'css/icons/calendar-plus.svg' ,
- alias : 'calendar-plus'
- } ,
- {
- uri : 'css/icons/information-outline.svg' ,
- alias : 'information-outline'
- } ,
- {
- uri : 'css/icons/ic_account_balance_wallet_black_24px.svg' ,
- alias : 'mdi-wallet-membership'
- } ,
- {
- uri : 'css/icons/ic_airline_seat_legroom_normal_black_24px.svg' ,
- alias : 'mdi-elevation-rise'
- } ,
- {
- uri : 'css/icons/ic_leak_add_black_24px.svg' ,
- alias : 'mdi-calendar-today'
- } ,
- {
- uri : 'css/icons/ic_chrome_reader_mode_black_24px.svg' ,
- alias : 'ic_chrome_reader_mode_black_24px'
- } ,
- {
- uri : 'css/icons/ic_build_black_24px.svg' ,
- alias : 'ic_build_black_24px'
- } ,
- {
- uri : 'css/icons/ic_invert_colors_black_24px.svg' ,
- alias : 'ic_invert_colors_black_24px'
- } ,
- {
- uri : 'css/icons/ic_rounded_corner_black_24px.svg' ,
- alias : 'ic_rounded_corner_black_24px'
- } ,
- {
- uri : 'css/icons/ic_perm_identity_black_24px.svg' ,
- alias : 'ic_perm_identity_black_24px'
- } ,
- {
- uri : 'css/icons/ic_language_black_24px.svg' ,
- alias : 'ic_language_black_24px'
- }
- ] )
- .factory ( 'SessionService' , function () {
- return {
- get : function ( key ) {
- return sessionStorage.getItem ( key );
- } ,
- set : function ( key , val ) {
- return sessionStorage.setItem ( key , val );
- } ,
- unset : function ( key ) {
- return sessionStorage.removeItem ( key );
- }
- }
- } )
- .config ( config )
- .run ( appStartUp );
- function appStartUp ( $log , $rootScope , $window , $http , APP_URL , uiGmapGoogleMapApi , $mdToast , angularLoad , nomenclatoareService , $mdDialog , $mdSidenav , $state , storage , $location , iconsUrls , $templateCache ,
- BUTTON ,
- DAUNATORUL ,
- DOZE_RECOMANDATE ,
- DOZA_UTILIZATA ,
- TRATAMENT ,
- CULTURA ,
- FERTILIZATOR ,
- COST ,
- CANTITATE ,
- KG ,
- DENSITATE ,
- SEMANAT ,
- KM1 ,
- KM2 ,
- utilizatorService ) {
- // # Listen for changes on the dashboard.administrare view changes. Use uiRoute's $state.reload() function to reinitialize the controller
- // # and bring it to a clean state.
- //$rootScope.$on('$stateChangeSuccess', function (e, to, toParams, from, fromParams) {
- // console.log('Logging from', from);
- // if (from.name === 'dashboard.administrare') {
- // console.info('Exiting `dashboard.administrare`. Controller has been reset.');
- // $state.reload();
- // }
- //});
- var body = angular.element ( document ).find ( 'body' );
- body.css ( 'display' , 'flex' );
- angular.forEach ( iconsUrls , function ( url ) {
- $http.get ( url.uri , { cache : $templateCache } );
- } );
- $rootScope.APP_URL = APP_URL;
- $rootScope.mainLoading = true;
- $rootScope.mainMenu = [];
- $rootScope.normalLeftMenuButtons = [
- {
- ariaLabel : "listă rapoarte" ,
- uiSRef : "lucrari.rapoarte" ,
- buttonLabel : "Rapoarte sole - lucrări" ,
- icon : 'mdi-wallet-membership'
- } ,
- // {
- // ariaLabel: "raport ferme",
- // uiSRef: "lucrari.rapoarte-ferme",
- // buttonLabel: "Rapoarte ferme - lucrări",
- // icon: 'mdi-wallet-membership'
- // },
- {
- ariaLabel : "lucrari lista" ,
- uiSRef : "lucrari.lista" ,
- buttonLabel : "Rapoarte tipuri lucrări" ,
- icon : "mdi-elevation-rise"
- } ,
- {
- ariaLabel : "raport grafic lucrari" ,
- uiSRef : "lucrari.grafice" ,
- buttonLabel : "Evolutie lucrari" ,
- icon : "mdi-elevation-rise" ,
- } ,
- {
- ariaLabel : "raport lista lucrari" ,
- uiSRef : "lucrari.toate" ,
- buttonLabel : "Lucrari An Curent" ,
- icon : "mdi-calendar-today" ,
- } ,
- ];
- $rootScope.soleSelectate = storage.get ( 'listaSoleSelectate' ) !== undefined ? storage.get ( 'listaSoleSelectate' ) : [];
- if ( !angular.isArray ( $rootScope.soleSelectate ) ) {
- $rootScope.soleSelectate = [];
- }
- $rootScope.adminLeftMenuButtons = [
- {
- ariaLabel : "nomenclator fertilizări" ,
- uiSRef : "nomenclator.fertilizari" ,
- buttonLabel : "Nomenclator fertilizări" ,
- icon : "ic_chrome_reader_mode_black_24px" ,
- } ,
- {
- ariaLabel : "nomenclator echipamente" ,
- uiSRef : "nomenclator.echipamente" ,
- buttonLabel : "Nomenclator echipamente" ,
- icon : "ic_build_black_24px" ,
- } ,
- {
- ariaLabel : "nomenclator tratamente" ,
- uiSRef : "nomenclator.tratamente" ,
- buttonLabel : "Nomenclator tratamente" ,
- icon : "ic_invert_colors_black_24px" ,
- } ,
- {
- ariaLabel : "nomenclator culturi" ,
- uiSRef : "nomenclator.culturi" ,
- buttonLabel : "Nomenclator culturi" ,
- icon : "ic_rounded_corner_black_24px" ,
- } ,
- {
- ariaLabel : "listă utilizatori" ,
- uiSRef : "utilizatori.lista" ,
- buttonLabel : "Listă utilizatori" ,
- icon : "ic_perm_identity_black_24px" ,
- } ,
- {
- ariaLabel : "listă ferme" ,
- uiSRef : "ferme.lista" ,
- buttonLabel : "Listă ferme" ,
- icon : "ic_language_black_24px" ,
- }
- ];
- $rootScope.logout = function () {
- $http.post ( APP_URL + "/post/logout" ).then ( function () {
- $state.go ( 'dashboard.main' );
- storage.remove ( 'listaSoleSelectate' );
- delete $window.sessionStorage[ "userInfo" ];
- $rootScope.mainLoading = true;
- displayLoginDialog ();
- } );
- };
- $rootScope.isInFullscreen = false;
- function launchIntoFullscreen ( element ) {
- if ( element.requestFullscreen ) {
- element.requestFullscreen ();
- } else if ( element.mozRequestFullScreen ) {
- element.mozRequestFullScreen ();
- } else if ( element.webkitRequestFullscreen ) {
- element.webkitRequestFullscreen ();
- } else if ( element.msRequestFullscreen ) {
- element.msRequestFullscreen ();
- }
- }
- var getFuelCost = $rootScope.getFuelCost = function () {
- return utilizatorService.fuelCostForCurrentUser ().then ( function ( res ) {
- $rootScope.pretCombustibil = Number ( res );
- // console.info('$rootScope.pretCombustibil', $rootScope.pretCombustibil);
- } , function ( err ) {
- console.error ( 'err in getFuelCost' , err );
- $rootScope.displayToast ( 'Eroare ! Nu am putut aduce costul combustibilului de la server ! Daca eroarea persista, va rugam contactati administratorul.' );
- } );
- };
- function exitFullscreen () {
- if ( document.exitFullscreen ) {
- document.exitFullscreen ();
- } else if ( document.mozCancelFullScreen ) {
- document.mozCancelFullScreen ();
- } else if ( document.webkitExitFullscreen ) {
- document.webkitExitFullscreen ();
- }
- }
- $rootScope.toggleFullscreen = function () {
- $rootScope.isInFullscreen = !$rootScope.isInFullscreen;
- if ( $rootScope.isInFullscreen ) {
- launchIntoFullscreen ( document.documentElement )
- } else {
- exitFullscreen ();
- }
- };
- $rootScope.fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled;
- if ( $rootScope.fullscreenEnabled ) {
- //console.log('can use fullscreen');
- } else {
- console.error ( 'can NOT use fullscreen' );
- }
- $rootScope.toggleMenu = function () {
- $mdSidenav ( "left" ).toggle ();
- };
- $rootScope.toggleSettings = function () {
- //console.log('TODO : implement user profile');
- };
- $rootScope.isAdmin = function () {
- if ( !$rootScope.loggedInUser ) return false;
- return $rootScope.loggedInUser.rol === 1;
- };
- $rootScope.isUser = function () {
- if ( !$rootScope.loggedInUser ) return false;
- return $rootScope.loggedInUser.rol === 2;
- };
- //console.log('$rootScope.loggedInUser', $rootScope.isUser());
- var changeMenuForAdmin = function () {
- if ( $rootScope.isAdmin () ) {
- //bottom to top
- $rootScope.adminLeftMenuButtons.reverse ();
- //inapoi la operare
- //$rootScope.adminLeftMenuButtons.pop();
- //administrare sole
- //$rootScope.adminLeftMenuButtons.pop();
- $rootScope.adminLeftMenuButtons.push ( {
- ariaLabel : "listă companii" ,
- uiSRef : "companii.lista" ,
- buttonLabel : "Listă companii"
- } );
- //top to bottom
- $rootScope.adminLeftMenuButtons.reverse ();
- $rootScope.mainMenu = $rootScope.adminLeftMenuButtons;
- }
- };
- var displayLoginDialog = function () {
- $rootScope.inLoginMode = true;
- $rootScope.loginError = false;
- var dialogScope = $rootScope.$new ();
- dialogScope.user = { username : '' , password : '' };
- dialogScope.submitLogin = function ( ev , user ) {
- dialogScope.isWaitingForLogin = true;
- $http.post ( APP_URL + "/post/login" , { username : user.username , password : user.password } ).then (
- function ( data , status , headers , config ) {
- $rootScope.getFuelCost ();
- dialogScope.isWaitingForLogin = false;
- $rootScope.inLoginMode = false;
- $rootScope.loggedInUser = data.data;
- changeMenuForAdmin ();
- $window.sessionStorage.setItem ( "userInfo" , JSON.stringify ( $rootScope.loggedInUser ) );
- aquireInitialData ();
- $mdDialog.cancel ();
- $rootScope.loginError = true;
- $location.url ( '/' );
- // location.reload();
- } , function ( error ) {
- dialogScope.isWaitingForLogin = false;
- $rootScope.loginError = true;
- } );
- };
- $mdDialog.show ( {
- controller : function () {
- } ,
- templateUrl : 'login.html' ,
- scope : dialogScope ,
- onComplete : afterShowLoginAnimation
- } );
- };
- var afterShowLoginAnimation = function ( scope , element , options ) {
- element.find ( 'input' )[ 0 ].focus ();
- };
- $rootScope.proceseazaSola = function ( sola ) {
- var polygonCoords = [];
- sola.coordonate = JSON.parse ( sola.coordonate.coordonate );
- sola.coordonate.forEach ( function ( coord ) {
- var coordLatLng = new $rootScope.mapsReference.LatLng ( coord.lat , coord.lng );
- polygonCoords.push ( coordLatLng );
- $rootScope.mapBounds.extend ( coordLatLng );
- } );
- if ( !sola.culoare ) {
- console.error ( 'Sola #' + sola.id + " nu are culoare!!! Folosim ALB" );
- sola.culoare = '#FFFFFF';
- }
- if ( sola.culoare && sola.culoare.indexOf ( '#' ) < 0 ) {
- sola.culoare = '#' + sola.culoare;
- }
- var aPolygon = new $rootScope.mapsReference.Polygon ( {
- path : polygonCoords ,
- geodesic : true ,
- strokeColor : '#FFFFFF' ,
- strokeOpacity : 1.0 ,
- strokeWeight : 1 ,
- clickable : true ,
- fillColor : sola.culoare
- } );
- aPolygon.solaId = sola.id;
- $rootScope.poligoane.push ( aPolygon );
- };
- $rootScope.proceseazaSole = function ( raspunsServer ) {
- var testHash = [];
- if ( raspunsServer && raspunsServer.length > 0 ) {
- raspunsServer.forEach ( function ( sola ) {
- if ( testHash[ sola.parcela_nr + "_" + sola.bloc_nr ] ) {
- //console.error(sola.id + " -> parcela:" + sola.parcela_nr + " bloc:" + sola.bloc_nr + " exista (" + sola.suprafata + " ha)!");
- } else {
- testHash[ sola.parcela_nr + "_" + sola.bloc_nr ] = true;
- }
- if ( sola.coordonate ) {
- $rootScope.proceseazaSola ( sola );
- $rootScope.hashRelations[ sola.id ] = sola;
- } else {
- console.error ( 'Sola #' + sola.id + " nu are coordonate!" );
- }
- if ( sola.subsole ) {
- angular.forEach ( sola.subsole , function ( s ) {
- s.depth = 1;
- $rootScope.proceseazaSola ( s );
- $rootScope.hashRelations[ s.id ] = s;
- } )
- }
- } );
- } else {
- console.error ( 'Nu avem sole!' , raspunsServer );
- raspunsServer = [];
- }
- return raspunsServer;
- };
- /** selectie / deselectie nomenclatoare generale din tabel **/
- $rootScope.toggleAll = function ( flag , data ) {
- data.forEach ( function ( tratament ) {
- tratament.selected = flag;
- } );
- };
- $rootScope.toastIfEmpty = function () {
- if ( $rootScope.echipamente.length === 0 ) {
- $rootScope.displayToast ( 'Vă rugăm definiți echipamente în nomenclatorul dvs!' , 'error' , parent );
- return true;
- }
- if ( $rootScope.culturi.length === 0 ) {
- $rootScope.displayToast ( 'Vă rugăm definiți culturi în nomenclatorul dvs!' , 'error' , parent );
- return true;
- }
- if ( $rootScope.fertilizari.length === 0 ) {
- $rootScope.displayToast ( 'Vă rugăm definiți fertilizari în nomenclatorul dvs!' , 'error' , parent );
- return true;
- }
- };
- var callInitialAquisition = function () {
- // var useCachedBulkData = false;
- // var cachedBulkData = storage.get('cachedBulkData');
- //
- // if(useCachedBulkData && cachedBulkData) {
- // initialDataDecorator(cachedBulkData);
- // } else {
- //
- // }
- nomenclatoareService.getInitialData ().then ( function ( serverResponse ) {
- initialDataDecorator ( serverResponse );
- } );
- function initialDataDecorator ( bulkData ) {
- // if(!cachedBulkData) {
- // storage.set('cachedBulkData', bulkData);
- // }
- var echipamente = [];
- var implementuri = [];
- angular.forEach ( bulkData.echipamente , function ( echipamentSauImplement ) {
- if ( echipamentSauImplement.tip.este_implement ) {
- implementuri.push ( echipamentSauImplement );
- } else {
- echipamente.push ( echipamentSauImplement );
- }
- } );
- $rootScope.echipamente = echipamente;
- $rootScope.implementuri = implementuri;
- $rootScope.tipuriEchipamente = bulkData.tipuriEchipamente;
- $rootScope.producatoriEchipamente = bulkData.producatoriEchipamente;
- $rootScope.producatoriCulturi = bulkData.producatoriCulturi;
- $rootScope.tipuriCulturi = bulkData.tipuriCulturi;
- // console.log('$rootScope.tipuriCulturi', $rootScope.tipuriCulturi);
- angular.forEach ( bulkData.culturi , function ( cultura ) {
- var producatorExistent = _.findWhere ( bulkData.producatoriCulturi , { id : cultura.id_producator } );
- if ( angular.isDefined ( producatorExistent ) ) {
- cultura.producator = producatorExistent;
- } else {
- console.error ( "Producator cultura #" + cultura.id_producator + " nu a fost gasit!" )
- }
- var tipCulturaExistenta = _.findWhere ( bulkData.tipuriCulturi , { id : cultura.id_tip } );
- if ( angular.isDefined ( tipCulturaExistenta ) ) {
- cultura.tip = tipCulturaExistenta;
- } else {
- console.error ( "Tip cultura #" + cultura.id_tip + " nu a fost gasit" );
- }
- } );
- $rootScope.culturi = bulkData.culturi;
- /**
- angular.forEach($rootScope.culturi, function(cultura) {
- cultura.nume_complet = cultura.tip.tip + ' (' + cultura.specia + ')';
- });
- console.info('$rootScope.culturi', $rootScope.culturi);
- **/
- $rootScope.nomenclatorLucrari = bulkData.tipuriLucrari;
- //console.warn('$rootScope.nomenclatorLucrari', $rootScope.nomenclatorLucrari);
- $rootScope.culturi_sole = bulkData.culturi_sole;
- if ( $rootScope.isAdmin () ) {
- $rootScope.companii = bulkData.companii;
- //console.warn($rootScope.companii);
- }
- $rootScope.operatori = bulkData.operatori;
- $rootScope.fermeDetalii = bulkData.ferme;
- //console.info($rootScope.fermeDetalii);
- $rootScope.producatoriFertilizari = bulkData.producatoriFertilizari;
- angular.forEach ( bulkData.fertilizari , function ( fertilizator ) {
- var producatorFertilizator = _.findWhere ( $rootScope.producatoriFertilizari , { id : fertilizator.id_producator } );
- if ( angular.isDefined ( producatorFertilizator ) ) {
- fertilizator.producator = producatorFertilizator;
- } else {
- console.error ( "Producator fertilizator #" + fertilizator.id_producator + " nu a fost gasit!" );
- }
- } );
- $rootScope.fertilizari = bulkData.fertilizari;
- //tratamente
- $rootScope.tipuriTratamente = bulkData.tipuriTratamente;
- $rootScope.producatoriTratamente = bulkData.producatoriTratamente;
- //restaurare tip, producator, cultura
- angular.forEach ( bulkData.tratamente , function ( tratament ) {
- var tipTratament = _.findWhere ( $rootScope.tipuriTratamente , { id : tratament.id_tip } );
- if ( angular.isDefined ( tipTratament ) ) {
- tratament.tip = tipTratament;
- } else {
- console.error ( "Tip tratament #" + tratament.id_tip + " nu a fost gasit" );
- }
- var producatorTratament = _.findWhere ( $rootScope.producatoriTratamente , { id : tratament.id_producator } );
- if ( angular.isDefined ( producatorTratament ) ) {
- tratament.producator = producatorTratament;
- } else {
- console.error ( "Producator tratament #" + tratament.id_producator + " nu a fost gasit" );
- }
- var culturaTratament = _.findWhere ( $rootScope.tipuriCulturi , { id : tratament.id_cultura } );
- if ( angular.isDefined ( culturaTratament ) ) {
- tratament.cultura = culturaTratament;
- } else {
- console.error ( "Cultura tratament #" + tratament.id_cultura + " nu a fost gasita" );
- }
- } );
- $rootScope.tratamente = bulkData.tratamente;
- if ( $rootScope.isUser () ) {
- //restaurare ferme
- angular.forEach ( bulkData.sole , function ( sola ) {
- var fermaSolei = _.findWhere ( bulkData.ferme , { id : sola.id_ferma } );
- if ( angular.isDefined ( fermaSolei ) ) {
- sola.ferma = fermaSolei;
- } else {
- console.error ( "Ferma #" + sola.id_ferma + " solei nu a fost gasita" );
- }
- } );
- $rootScope.listaSole = $rootScope.proceseazaSole ( bulkData.sole );
- $rootScope.listaLucrari = bulkData.lucrari;
- //console.log($rootScope.listaLucrari);
- }
- // add a 'val' field to 'tratament' so the dynamic directive
- // can display that value as the default one
- _.each ( $rootScope.tratamente , function ( val ) {
- if ( val.nume_popular )
- val.val = val.nume_popular;
- } );
- if ( _.isEmpty ( $rootScope.mainMenu ) ) {
- $rootScope.mainMenu = $rootScope.normalLeftMenuButtons;
- }
- $rootScope.mainLoading = false;
- }
- };
- var aquireInitialData = function () {
- //console.log('post-login data', $rootScope.loggedInUser);
- if ( $rootScope.isUser () ) {
- $rootScope.poligoane = [];
- $rootScope.hashRelations = [];
- uiGmapGoogleMapApi.then ( function ( maps ) {
- //console.log('Maps reference obtained');
- $rootScope.mapsReference = maps;
- $rootScope.mapBounds = new $rootScope.mapsReference.LatLngBounds ();
- angularLoad.loadScript ( './js/vendor/deletemenu.js' ).then ( function () {
- callInitialAquisition ();
- } );
- } );
- } else if ( $rootScope.isAdmin () ) {
- callInitialAquisition ();
- }
- };
- var init = function () {
- var now = moment ();
- var start;
- var end;
- if ( now.month () > 8 ) {
- start = now.clone ().month ( 8 ).startOf ( 'month' );
- end = now.clone ().year ( now.year () + 1 ).month ( 8 ).startOf ( 'month' );
- } else {
- end = now.clone ().month ( 8 ).startOf ( 'month' );
- start = now.clone ().year ( now.year () - 1 ).month ( 8 ).startOf ( 'month' );
- }
- $rootScope.startAnAgricol = start;
- $rootScope.sfarsitAnAgricol = end;
- if ( $window.sessionStorage[ "userInfo" ] ) {
- $rootScope.loggedInUser = angular.fromJson ( $window.sessionStorage.getItem ( "userInfo" ) );
- changeMenuForAdmin ();
- //console.log($rootScope.loggedInUser);
- aquireInitialData ();
- } else {
- if ( !$rootScope.inLoginMode ) {
- displayLoginDialog ();
- }
- }
- };
- $rootScope.$on ( 'showAPICallError' , function ( event , rejection ) {
- var message;
- if ( rejection.status == 401 ) {
- if ( $rootScope.inLoginMode ) return;
- message = "Sesiunea a expirat! Logați-vă din nou!";
- displayLoginDialog ();
- }
- if ( rejection.status == 400 ) {
- if ( angular.isDefined ( rejection.config ) && angular.isDefined ( rejection.config.url ) ) {
- //it's bad username or password
- if ( rejection.config.url.indexOf ( "/post/login" ) >= 0 ) {
- return;
- }
- }
- //message = "Bad username or password";
- }
- message = rejection.data;
- //console.log("============interceptor=============================");
- console.error ( rejection );
- //console.log("============end interceptor=============================");
- var msg = message;
- if ( angular.isDefined ( msg ) && angular.isDefined ( msg.data ) ) {
- msg = msg.data;
- }
- //console.log("Display toast");
- $rootScope.displayToast ( 'Eroare ! ' + msg , 'error' );
- } );
- $rootScope.$on ( '$stateChangeSuccess' , function ( event , toState , toParams , fromState , fromParams ) {
- //console.log('STATE : ' + toState.name);
- if ( $rootScope.isAdmin () ) {
- //cand e admin, fortam starea initiala
- $rootScope.mainMenu = $rootScope.adminLeftMenuButtons;
- if ( toState.name == "dashboard.main" || toState.name == "dashboard.administrare" ) {
- $state.go ( 'companii.lista' );
- }
- return;
- }
- // hide home button when you are on home page
- $rootScope.hideHomeButton = toState.name == "dashboard.main";
- $rootScope.hideDashButton = toState.name == "dashboard.administrare";
- //Atentie : cand se adauga o ruta in meniu, trebuie declarata si aici, ca sa se poata restaura meniul
- if ( toState.name == "dashboard.main"
- || toState.name == "lucrari.lista"
- || toState.name == "lucrari.toate"
- || toState.name == "lucrari.rapoarte"
- || toState.name == "lucrari.grafice"
- || toState.name == "note.lista"
- ) {
- if ( !angular.isDefined ( $rootScope.inMainView ) ) {
- $rootScope.inMainView = true;
- $rootScope.mainMenu = $rootScope.normalLeftMenuButtons;
- } else if ( !$rootScope.inMainView ) {
- $rootScope.inMainView = true;
- $rootScope.mainMenu = $rootScope.normalLeftMenuButtons;
- }
- }
- if ( toState.name == "dashboard.administrare"
- || toState.name == "nomenclator.fertilizari"
- || toState.name == "nomenclator.echipamente"
- || toState.name == "nomenclator.tratamente"
- || toState.name == "nomenclator.culturi"
- || toState.name == "nomenclator.lucrari"
- || toState.name == "utilizatori.lista"
- || toState.name == "ferme.lista"
- || toState.name == "companii.lista"
- ) {
- if ( !angular.isDefined ( $rootScope.inMainView ) ) {
- $rootScope.inMainView = false;
- $rootScope.mainMenu = $rootScope.adminLeftMenuButtons;
- } else if ( $rootScope.inMainView ) {
- $rootScope.inMainView = false;
- $rootScope.mainMenu = $rootScope.adminLeftMenuButtons;
- }
- }
- } );
- $rootScope.$on ( '$stateNotFound' , function ( event , unfoundState , fromState , fromParams ) {
- $log.error ( "State not found : " + unfoundState );
- } );
- $rootScope.changeStateTo = function ( menu ) {
- $state.go ( menu.uiSRef ).then ( function () {
- if ( $mdSidenav ( "left" ) ) {
- if ( $mdSidenav ( "left" ).isOpen () ) {
- $mdSidenav ( "left" ).toggle ();
- }
- }
- } )
- };
- $rootScope.toggleMobileSidenav = function () {
- $mdSidenav ( 'right' )
- .toggle ();
- };
- $rootScope.displayToast = function ( message , toastType , parent ) {
- var hideDelay = 6000;
- var aToast = {
- template : '<md-toast>' +
- '<div class="md-toast-content">' +
- message +
- '</div>' +
- '</md-toast>' ,
- hideDelay : hideDelay ,
- position : 'bottom left'
- };
- if ( parent ) {
- aToast.parent = parent;
- }
- var e = angular.element ( parent || document.body );
- var p = e.parent ();
- var po = p.css ( "overflow" );
- p.css ( "overflow" , "hidden" );
- setTimeout ( function () {
- p.css ( "overflow" , po );
- } , hideDelay + 1000 );
- $mdToast.show ( aToast );
- };
- $rootScope.replaceInCollection = function ( collection , item , newItem ) {
- var existingItem = _.findWhere ( collection , { id : item.id } ) ,
- keys = _.keys ( newItem );
- _.each ( keys , function ( key ) {
- existingItem[ key ] = newItem[ key ];
- } );
- };
- //announcing global exception
- $rootScope.$on ( 'globalException' , function ( event , ex ) {
- if ( $rootScope.hasGlobalException ) {
- //display only one Global Exception message
- return;
- }
- $rootScope.hasGlobalException = true;
- var aToast = {
- template : '<md-toast class="md-toast" style="background-color:red"><b>Ar trebui sa faceti captura de ecran si refresh la pagina (F5)!</b><br/>Eroare:' + ex.exception + '<br/>...</md-toast>' ,
- hideDelay : 0 ,
- position : 'bottom left'
- };
- $mdToast.show ( aToast );
- } );
- $rootScope.traverseAndPrepareData = function ( raportLucrari ) {
- var listaLucrariProcesata = [];
- angular.forEach ( raportLucrari , function ( lucrare ) {
- if ( lucrare.consum == null ) {
- lucrare.consum = undefined;
- }
- var lucrareProcesata = {
- id : lucrare.id ,
- tip : lucrare.tip ? lucrare.tip.nume : "fara tip???" ,
- id_ferma : lucrare.sola.id_ferma ,
- nume_sola : lucrare.sola.nume_comun ? lucrare.sola.nume_comun : lucrare.sola.nume ,
- suprafata : lucrare.suprafata ? lucrare.suprafata : lucrare.sola.suprafata ,
- data_inregistrare : lucrare.data_inregistrare ,
- cost : isNaN ( Number ( lucrare.cost ) ) ? Number ( 0 ) : lucrare.cost ,
- consum : isNaN ( Number ( lucrare.consum ) ) ? Number ( 0 ) : lucrare.consum ,// + (lucrare.consum > 1 ? " litri" : " litru"),
- model_echipament : lucrare.echipament ? lucrare.echipament.model : "fara echipament" ,
- model_implement : lucrare.implement ? lucrare.implement.model : "nici unul" ,
- nume_operator : lucrare.operator ? lucrare.operator.nume : "fara operator" ,
- observatii : lucrare.observatii ,
- cost_total : 0 ,
- cost_exploatare : 0 ,
- cantitate_total : 0 ,
- children : [] ,
- childrenExpanded : true
- };
- var lucrareCuTert = false;
- if ( !isNaN ( Number ( lucrare.cost ) ) ) {
- if ( !isNaN ( Number ( lucrare.consum ) ) && Number ( lucrare.consum ) > 0 ) {
- lucrareProcesata.cost_exploatare = (Number ( lucrareProcesata.suprafata ) * Number ( lucrare.consum ) * Number ( lucrare.cost ));
- } else {
- lucrareCuTert = true;
- lucrareProcesata.cost_exploatare = (Number ( lucrareProcesata.suprafata ) * Number ( lucrare.cost ));
- }
- //row-ul principal in tabel
- listaLucrariProcesata.push ( lucrareProcesata );
- //adaugam row-ul de costuri
- var valoriIntroduse = {
- child : true ,
- visible : true ,
- valoare_introdusa : lucrareProcesata.cost_exploatare.toFixed ( 2 ) + " RON fără TVA" ,
- nume_camp : lucrareCuTert ? "Cost lucrare (terț): " : "Cost lucrare motorina : "
- };
- //punem row-ul de motorina in tabel
- listaLucrariProcesata.push ( valoriIntroduse );
- //punem copilul in parinte (pentru al putea ascunde)
- lucrareProcesata.children.push ( valoriIntroduse );
- } else {
- listaLucrariProcesata.push ( {
- child : true ,
- visible : true ,
- valoare_introdusa : "Cost gresit!" ,
- nume_camp : "Eroare!"
- } );
- //punem copilul in parinte (pentru al putea ascunde)
- lucrareProcesata.children.push ( {
- child : true ,
- visible : true ,
- valoare_introdusa : "Cost gresit!" ,
- nume_camp : "Eroare!"
- } );
- }
- //fiecare camp
- var cost = undefined;
- var doza = undefined;
- //pentru fiecare camp, mai facem un row in tabel
- if ( angular.isDefined ( lucrare.campuri ) ) {
- angular.forEach ( lucrare.campuri , function ( camp ) {
- var valoriIntroduse = {
- child : true ,
- visible : true ,
- valoare_introdusa : camp.valoare_introdusa ,
- valoare_originala : camp.valoare_introdusa ,
- nume_camp : camp.nume_camp
- };
- if ( camp.nume_camp.toLowerCase ().indexOf ( DOZE_RECOMANDATE ) == -1 ) {
- if ( camp.nume_camp.toLowerCase ().indexOf ( FERTILIZATOR ) >= 0 ) {
- var fertilizatorSelectat = _.findWhere ( $rootScope.fertilizari , { id : Number ( camp.valoare_introdusa ) } );
- if ( angular.isDefined ( fertilizatorSelectat ) ) {
- if ( angular.isDefined ( fertilizatorSelectat.continut_sa_procente ) && angular.isDefined ( fertilizatorSelectat.continut_sa_grame ) ) {
- lucrareProcesata.fertilizator = fertilizatorSelectat;
- valoriIntroduse.valoare_introdusa = fertilizatorSelectat.denumire_comerciala + " (" + fertilizatorSelectat.continut_sa_grame + "g - " + fertilizatorSelectat.continut_sa_procente + "%)";
- } else {
- valoriIntroduse.valoare_introdusa = fertilizatorSelectat.denumire_comerciala + " ( lipsesc substantele)";
- }
- } else {
- valoriIntroduse.valoare_introdusa = "Fertilizator LIPSA# " + camp.valoare_introdusa;
- }
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( TRATAMENT ) >= 0 ) {
- var tratamentSelectat = _.findWhere ( $rootScope.tratamente , { id : Number ( camp.valoare_introdusa ) } );
- if ( angular.isDefined ( tratamentSelectat ) ) {
- lucrareProcesata.tratament = tratamentSelectat;
- valoriIntroduse.valoare_introdusa = tratamentSelectat.nume + " (" + tratamentSelectat.cultura.tip + " - " + tratamentSelectat.tip.tip + ")";
- } else {
- valoriIntroduse.valoare_introdusa = "Tratament LIPSA# " + camp.valoare_introdusa;
- }
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( DAUNATORUL ) >= 0 ) {
- valoriIntroduse.valoare_introdusa = camp.valoarea_text_introdusa;
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( DOZA_UTILIZATA ) >= 0 ) {
- doza = Number ( Number ( lucrareProcesata.suprafata ) * Number ( camp.valoare_introdusa ) * 0.001 ).toFixed ( 2 );
- valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura + " - Total : " + doza + " kg";
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( COST ) >= 0 ) {
- cost = Number ( camp.valoare_introdusa );
- if ( isNaN ( cost ) ) {
- console.error ( camp.nume_camp + " = " + camp.valoare_introdus );
- }
- valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura + " - Total : " + Number ( doza * cost ).toFixed ( 2 ) + " " + camp.unitate_de_masura;
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( KG ) >= 0 ) {
- doza = Number ( Number ( lucrareProcesata.suprafata ) * Number ( camp.valoare_introdusa ) ).toFixed ( 2 );
- valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura + " Total : " + doza + " kg";
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( DENSITATE ) >= 0 ) {
- valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura;
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( CANTITATE ) >= 0 ) {
- //console.log("Cantitate " + camp.valoare_introdusa);
- doza = Number ( Number ( lucrareProcesata.suprafata ) * Number ( camp.valoare_introdusa ) ).toFixed ( 2 );
- valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura + " Total : " + doza + " kg.";
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( KM1 ) >= 0 ) {
- cost = Number ( camp.valoare_introdusa );
- valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura;
- } else if ( camp.nume_camp.toLowerCase ().indexOf ( KM2 ) >= 0 ) {
- doza = Number ( camp.valoare_introdusa );
- valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura;
- }
- }
- if ( !isNaN ( Number ( doza ) ) ) {
- lucrareProcesata.cantitate_total = doza;
- if ( !isNaN ( Number ( cost ) ) ) {
- lucrareProcesata.cost_total = Number ( Number ( lucrareProcesata.cost_total ) + Number ( doza * cost ) );
- }
- }
- //punem row-ul in tabel
- listaLucrariProcesata.push ( valoriIntroduse );
- //punem copilul in parinte (pentru al putea ascunde)
- lucrareProcesata.children.push ( valoriIntroduse );
- } );
- }
- } );
- return listaLucrariProcesata;
- };
- $rootScope.postProcesareLucrari = function ( idSola , rapoarte , tableHeaders ) {
- var costTotal = 0;
- var listaSubstanteFertilizatori = [];
- var listaSubstanteTratamente = [];
- var dataSemanatului;
- var areSubstanteFertilizatori = false;
- var areSubstanteTratamente = false;
- _.each ( rapoarte , function ( raport ) {
- if ( _.has ( raport , 'children' ) ) {
- raport.cost_total = Number ( Number ( raport.cost_total ) + Number ( raport.cost_exploatare ) );
- costTotal = Number ( costTotal ) + Number ( raport.cost_total );
- var kilogrameSubstanta = 0;
- if ( raport.tip.toLowerCase ().indexOf ( TRATAMENT ) >= 0 ) {
- if ( angular.isDefined ( raport.tratament ) && angular.isDefined ( raport.tratament.substanta_activa ) ) {
- _.each ( raport.children , function ( child ) {
- if ( child.nume_camp.toLowerCase ().indexOf ( DOZA_UTILIZATA ) >= 0 ) {
- kilogrameSubstanta = Number ( Number ( child.valoare_originala ) * 0.001 * Number ( raport.suprafata ) ).toFixed ( 2 );
- //console.log(child.valoare_originala + " g x " + raport.suprafata + " ha = " + kilogrameSubstanta);
- }
- } );
- areSubstanteTratamente = true;
- if ( angular.isDefined ( listaSubstanteTratamente[ raport.tratament.substanta_activa ] ) ) {
- listaSubstanteTratamente[ raport.tratament.substanta_activa ] = listaSubstanteTratamente[ raport.tratament.substanta_activa ] + Number ( kilogrameSubstanta );
- } else {
- listaSubstanteTratamente[ raport.tratament.substanta_activa ] = Number ( kilogrameSubstanta );
- }
- }
- } else if ( raport.tip.toLowerCase ().indexOf ( FERTILIZATOR ) >= 0 ) {
- if ( angular.isDefined ( raport.fertilizator ) && angular.isDefined ( raport.fertilizator.denumire_comerciala ) ) {
- _.each ( raport.children , function ( child ) {
- if ( child.nume_camp.toLowerCase ().indexOf ( CANTITATE ) >= 0 ) {
- kilogrameSubstanta = Number ( Number ( child.valoare_originala ) * Number ( raport.suprafata ) ).toFixed ( 2 );
- //console.log(child.valoare_originala + " kg x " + raport.suprafata + " ha = " + kilogrameSubstanta);
- }
- } );
- areSubstanteFertilizatori = true;
- if ( angular.isDefined ( listaSubstanteFertilizatori[ raport.fertilizator.denumire_comerciala ] ) ) {
- listaSubstanteFertilizatori[ raport.fertilizator.denumire_comerciala ] = listaSubstanteFertilizatori[ raport.fertilizator.denumire_comerciala ] + Number ( kilogrameSubstanta );
- } else {
- listaSubstanteFertilizatori[ raport.fertilizator.denumire_comerciala ] = Number ( kilogrameSubstanta );
- }
- }
- } else if ( raport.tip.toLowerCase ().indexOf ( SEMANAT ) >= 0 ) {
- dataSemanatului = moment ( raport.data_inregistrare ).format ( "LL" );
- }
- }
- } );
- if ( angular.isDefined ( dataSemanatului ) ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : dataSemanatului ,
- nume_camp : "Data semanatului"
- } );
- } else {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : "nu are" ,
- nume_camp : "Data semanatului"
- } );
- }
- if ( angular.isDefined ( idSola ) ) {
- var cultura = _.findWhere ( $rootScope.culturi , { id : $rootScope.culturi_sole[ idSola ] } );
- if ( angular.isDefined ( cultura ) ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : cultura.tip.tip + "(" + cultura.specia + ")" ,
- nume_camp : "Cultura curentă"
- } );
- } else {
- //console.log("Fara cultura curenta");
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : "nu are" ,
- nume_camp : "Cultura curentă"
- } );
- }
- }
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : costTotal.toFixed ( 2 ) + " RON fără TVA" ,
- nume_camp : "Cost total"
- } );
- if ( areSubstanteTratamente ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : "" ,
- nume_camp : "Substanțe tratamente"
- } );
- }
- for ( var key in listaSubstanteTratamente ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : Number ( listaSubstanteTratamente[ key ] ).toFixed ( 2 ) + " kg" ,
- nume_camp : key
- } );
- }
- if ( areSubstanteFertilizatori ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : "" ,
- nume_camp : "Substanțe fertilizări"
- } );
- }
- for ( var key2 in listaSubstanteFertilizatori ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : Number ( listaSubstanteFertilizatori[ key2 ] ).toFixed ( 2 ) + " kg" ,
- nume_camp : key2
- } );
- }
- if ( idSola ) {
- var solaSelectata = _.findWhere ( $rootScope.listaSole , { id : idSola } );
- if ( solaSelectata ) {
- if ( solaSelectata.data_arendare ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : moment ( solaSelectata.data_arendare ).format ( "MMM Do YY" ) ,
- nume_camp : "Data inceput arendare:" ,
- isDate : true
- } );
- }
- if ( solaSelectata.data_final_arendare ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : moment ( solaSelectata.data_final_arendare ).format ( "MMM Do YY" ) ,
- nume_camp : "Data final arendare:" ,
- isDate : true
- } );
- }
- if ( solaSelectata.proprietar ) {
- tableHeaders.push ( {
- isNotHeader : true ,
- valoare_introdusa : solaSelectata.proprietar ,
- nume_camp : "Contract si proprietari:"
- } );
- }
- }
- }
- };
- // # Maybe some utils.
- // # Return the key of the inserted object value.
- $rootScope.getKeyByValue = function ( thisObject , value ) {
- for ( var prop in this ) {
- if ( thisObject.hasOwnProperty ( prop ) ) {
- if ( thisObject[ prop ] === value )
- return prop;
- }
- }
- };
- // # index.html helpers
- $rootScope.changeFuelCost = function ( fuelCost ) {
- return utilizatorService.changeFuelCost ( fuelCost ).then ( function ( res ) {
- // getFuelCost();
- $rootScope.displayToast ( 'Pretul combustibilului a fost modificat cu succes !' );
- } , function ( err ) {
- console.error ( 'err in changeFuelCost' , err );
- $rootScope.displayToast ( 'Eroare ! Nu am putut modifica costul combustibilului ! Daca eroarea persista, va rugam contactati administratorul.' );
- } );
- };
- init ();
- }
- appStartUp.$inject = [
- '$log' ,
- '$rootScope' ,
- '$window' ,
- '$http' ,
- 'APP_URL' ,
- 'uiGmapGoogleMapApi' ,
- '$mdToast' ,
- 'angularLoad' ,
- 'nomenclatoareService' ,
- '$mdDialog' ,
- '$mdSidenav' ,
- '$state' ,
- 'storage' ,
- '$location' ,
- 'iconsUrls' ,
- '$templateCache' ,
- 'BUTTON' ,
- 'DAUNATORUL' ,
- 'DOZE_RECOMANDATE' ,
- 'DOZA_UTILIZATA' ,
- 'TRATAMENT' ,
- 'CULTURA' ,
- 'FERTILIZATOR' ,
- 'COST' ,
- 'CANTITATE' ,
- 'KG' ,
- 'DENSITATE' ,
- 'SEMANAT' ,
- 'KM1' ,
- 'KM2' ,
- 'utilizatorService' ];
- }).call ( this );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement