/** * @ngdoc MaeklarObjektCtrl * @name fasit.component.#MaeklarObjektCtrl * @MaeklarObjektCtrl * * @description * Controllern för att visa och editera maeklarobjekt */ angular.module('fasit') .controller('MaeklarObjektCtrl', [ '$scope', '$routeParams', '$location', '$timeout', '$http', '$q', '$sce', '$translate', '$window', '$filter', '$upload', '$rootScope', 'scrollService', 'maeklarObjektService', 'domainService', 'navigationService', 'commonService', 'sideDrawerService', 'stateService', 'filService', 'kommunService', 'foereningService', 'kommunalskattService', 'medarbetareService', 'journalService', 'xmlExportIntegrationService', 'vaerderingsdataService', 'valueguardService', 'intressentService', 'bildbestaellningService', 'globalTimerService', 'uiService', 'anticimexService', 'postadressService', 'meddelandeTillAnvaendareService', 'maeklarObjektBesiktningService', 'foersaekringsPrisService', 'objektIProjektService', 'taggService', 'maeklarObjektCommonService', 'kommentarService', 'haendelseService', 'instaellningarService', function ( $scope: fb.IMaeklarObjektScope, $routeParams: any, $location: ng.ILocationService, $timeout: ng.ITimeoutService, $http: ng.IHttpService, $q: ng.IQService, $sce: ng.ISCEService, $translate, $window: ng.IWindowService, $filter: ng.IFilterService, $upload: any, $rootScope: fb.IRootScope, scrollService: fb.IScrollService, maeklarObjektService: fb.IMaeklarObjektService, domainService: fb.IDomainService, navigationService: fb.INavigationService, commonService: fb.ICommonService, sideDrawerService: fb.ISideDrawerService, stateService: fb.IStateService, filService: fb.IFilService, kommunService: fb.IKommunService, foereningService: fb.IFoereningService, kommunalskattService: fb.IKommunalskattService, medarbetareService: fb.IMedarbetareService, journalService: fb.IJournalService, xmlExportIntegrationService: fb.IXmlExportIntegrationService, vaerderingsDataService: fb.IVaerderingsdataService, valueguardService: fb.IValueguardService, intressentService: fb.IIntressentService, bildbestaellningService: fb.IBildbestaellningService, globalTimerService: fb.IGlobalTimerService, uiService: fb.IUIService, anticimexService: fb.IAnticimexService, postadressService: fb.IPostadressService, meddelandeTillAnvaendareService: fb.IMeddelandeTillAnvaendareService, maeklarObjektBesiktningService: fb.IMaeklarObjektBesiktningService, foersaekringsPrisService: fb.IFoersaekringsPrisService, objektIProjektService: fb.IObjektIProjektService, taggService: fb.ITaggService, maeklarObjektCommonService, kommentarService: fb.IKommentarService, haendelseService: fb.IHaendelseService, instaellningarService: fb.IInstaellningarService ) { 'use strict'; $scope.navigateBack = function () { history.back(); } $scope.showKontrolleraNyckelNummer = false; $scope.showFoersaeljningsrapporteratKommentar = false; $scope.showNyckelNummerInputError = false; $scope.UppdragStatus = fb.FasITDomain.UppdragStatus; $scope.Boendeform = fb.FasITDomain.Boendeform; $scope.kanAktiveraKundportalen = kanAktiveraKundportalen; $scope.kanVisaKundportalen = kanVisaKundportalen; $scope.openKundportalenSideDrawer = openKundportalenSideDrawer; const kundportalAktivInstaellning: fb.Instaellning = instaellningarService.getInstaellningFoerKontor(fb.FasITDomain.InstaellningId.KUNDPORTALEN_AKTIV); kundportalAktivInstaellning.$promise.then(() => { if (kundportalAktivInstaellning.InstaellningVaerde && kundportalAktivInstaellning.InstaellningVaerde.value !== null) { $scope.isKundportalAktiv = kundportalAktivInstaellning.InstaellningVaerde.value; } else { $scope.isKundportalAktiv = false; } }); $scope.setRequiredFieldsFotograferingDatum = saettFaeltSomKraevsFoerFotograferingDatum; $scope.isAllowedFotograferingDatum = allowFotograferingDatum; $scope.haemtaAntalOloestaKommentarer = haemtaAntalOloestaKommentarer; uiService.view(fb.FasITDomain.VyerNamn.MaeklarObjekt); if (uiService.getCurrentBreakpoint() === fb.FasITDomain.Breakpoints.xs || uiService.getCurrentBreakpoint() === fb.FasITDomain.Breakpoints.sm) { uiService.close(fb.FasITDomain.UIState.HoegerMeny); } else { uiService.open(fb.FasITDomain.UIState.HoegerMeny); } $scope.gotoObjekt = function (MaeklarObjektId: number) { var breakpoint = uiService.getCurrentBreakpoint(); if ( breakpoint === fb.FasITDomain.Breakpoints.xs || breakpoint === fb.FasITDomain.Breakpoints.sm ) { uiService.close(fb.FasITDomain.UIState.HoegerMeny); } navigationService.findOpenObjekt(fb.FasITDomain.NavigationController.MAEKLAROBJEKT, MaeklarObjektId, true); } $scope.DriftstoerningsmeddelandeNivaa = fb.FasITDomain.DriftstoerningsmeddelandeNivaa; $scope.prioriterat = meddelandeTillAnvaendareService.getPrioriterat(); // Basfakta $scope.besiktningOBM = { url: $sce.trustAsResourceUrl(fb.Environment.obmGruppenBesiktningUrl), xml: null, isBestaeller: false, doBestaell: function () { $scope.besiktningOBM.isBestaeller = true; $scope.besiktningOBM.xml = xmlExportIntegrationService.getBesiktningOBM($routeParams.id); $scope.besiktningOBM.xml.$promise .finally(function () { $scope.besiktningOBM.isBestaeller = false; }); } }; $scope.besiktningAnticimex = { url: $sce.trustAsResourceUrl(fb.Environment.anticimexBesiktningUrl), xml: null, isBestaeller: false, doBestaell: function () { $scope.besiktningAnticimex.isBestaeller = true; $scope.besiktningAnticimex.xml = xmlExportIntegrationService.getBesiktningAnticimex($routeParams.id); $scope.besiktningAnticimex.xml.$promise .finally(function () { $scope.besiktningAnticimex.isBestaeller = false; }); } }; //saettFaeltSomKraevsFoerAvtalsdag var requirementCallback = function (remainingRequirements: {}) { sideDrawerService.clearDrawer(); }; var getUnfilledRequirements = function () { var unfilledRequirements = {}; if ($scope.maeklarObjekt.$resolved) { switch ($scope.maeklarObjekt.UppdragTyp.value) { case fb.FasITDomain.UppdragTyp.SKRIVNING: if ((!$scope.maeklarObjekt.ProvisFast.value && $scope.maeklarObjekt.ProvisFast.value !== 0) && !$scope.maeklarObjekt.ProvisProc.value && $scope.maeklarObjekt.ProvisProc.value !==0) { unfilledRequirements['ProvisFast'] = $scope.maeklarObjekt.ProvisFast; unfilledRequirements['ProvisProc'] = $scope.maeklarObjekt.ProvisProc; } if (!$scope.maeklarObjekt.SlutPris.value) { unfilledRequirements['SlutPris'] = $scope.maeklarObjekt.SlutPris; } break; case fb.FasITDomain.UppdragTyp.VAERDERING: if ((!$scope.maeklarObjekt.ProvisFast.value && $scope.maeklarObjekt.ProvisFast.value !== 0) && !$scope.maeklarObjekt.ProvisProc.value && $scope.maeklarObjekt.ProvisProc.value !== 0) { unfilledRequirements['ProvisFast'] = $scope.maeklarObjekt.ProvisFast; unfilledRequirements['ProvisProc'] = $scope.maeklarObjekt.ProvisProc; } break; } } return unfilledRequirements; }; $scope.saettFaeltSomKraevsFoerAvtalsdag = function () { var unfilledRequirements = getUnfilledRequirements(); sideDrawerService.setSideDrawer('StatusByte', { 'missingFields': unfilledRequirements, 'maeklarObjekt': $scope.maeklarObjekt, 'status': '', 'saknasFoerText': $scope.getTranslateNameFromModel('maeklarObjekt.Avtalsdag').toLowerCase() }, '50%', requirementCallback); }; $scope.allowAvtalsdag = function () { var unfilledRequirements = getUnfilledRequirements(); return (Object.keys(unfilledRequirements).length === 0); }; // END saettFaeltSomKraevsFoerAvtalsdag function saettFaeltSomKraevsFoerFotograferingDatum(): void { var unfilledRequirements = getUnfilledRequirements(); sideDrawerService.setSideDrawer('StatusByte', { 'missingFields': unfilledRequirements, 'maeklarObjekt': $scope.maeklarObjekt, 'status': '', 'saknasFoerText': $scope.getTranslateNameFromModel('maeklarObjekt.FotograferingDatum').toLowerCase() }, '50%', requirementCallback); } function allowFotograferingDatum(): boolean { var unfilledRequirements = getUnfilledRequirements(); return (Object.keys(unfilledRequirements).length === 0); } $scope.showChangeUppdragTypFoerFoersaeljningsrapporterat = false; $scope.$watch('maeklarObjekt.UppdragTyp.value', function (newVal, oldVal) { if ($scope.maeklarObjekt.$resolved && typeof oldVal !== 'undefined' && newVal !== oldVal) { if ($scope.maeklarObjekt.isSaald()) { throw 'Kan inte ändra uppdragtyp för försäljningsrapporterat objekt'; } else { if ($scope.maeklarObjekt.isFoersaeljning() && (oldVal === fb.FasITDomain.UppdragTyp.SKRIVNING || oldVal === fb.FasITDomain.UppdragTyp.VAERDERING)) { // Om uppdragstyp ändras från skrivning/värdering till försäljning så sätt uppdragsstatus Intagsförsök $scope.maeklarObjekt.setValue($scope.maeklarObjekt.UppdragStatus, fb.FasITDomain.UppdragStatus.FOERBEARBETNING); } else if ($scope.maeklarObjekt.isSkrivning()) { // nollställ värden som inte ska sättas för skrivning (vill inte ha info som sparas i databasen men är dold för användaren) $scope.maeklarObjekt.setValue($scope.maeklarObjekt.UppdragStatus, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.UppdragStatusSpecifikation, fb.FasITDomain.UppdragStatusSpecifikation.SKRIVNING); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.StartPris, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.PrisText, null); // Provision under Ekonomi $scope.maeklarObjekt.setValue($scope.maeklarObjekt.ProvisVisaEjIAvtal, null); // Används också för provisionFast (så ska inte nullas) //$scope.maeklarObjekt.ProvisFast,null); // provisionLaegst & provisionFritext //$scope.maeklarObjekt.ProvisFast.dirty = true); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.ProvisProc, null); // provisionProcent $scope.maeklarObjekt.setValue($scope.maeklarObjekt.ProvisText, null); // provisionText $scope.maeklarObjekt.PaaGaang.setValue(null); } else if ($scope.maeklarObjekt.isVaerdering()) { // nollställ värden som inte ska sättas för värdering (vill inte ha info som sparas i databasen men är dold för användaren) $scope.maeklarObjekt.setValue($scope.maeklarObjekt.UppdragStatus, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.UppdragStatusSpecifikation, fb.FasITDomain.UppdragStatusSpecifikation.VAERDERING); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.SlutPris, null); // Provision under Ekonomi $scope.maeklarObjekt.setValue($scope.maeklarObjekt.ProvisVisaEjIAvtal, null); // Används också för provisionFast (så ska inte nullas) //$scope.maeklarObjekt.ProvisFast,null); // provisionLaegst & provisionFritext //$scope.maeklarObjekt.ProvisFast.dirty = true); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.ProvisProc, null); // provisionProcent $scope.maeklarObjekt.setValue($scope.maeklarObjekt.ProvisText, null); // provisionText // Köpeskilling $scope.maeklarObjekt.setValue($scope.maeklarObjekt.HandpenningDeponeras, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.HandpenningBelopp, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.HandpenningSkaErlaeggasDatum, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.HandpenningErlagdDatum, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.HandpenningRedovisadDatum, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.HandpenningRedovisaRaenta, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.DellikvidDatum, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.DellikvidBelopp, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.ReversBelopp, null); $scope.maeklarObjekt.PaaGaang.setValue(null); } globalTimerService.globalSave(true); } } }); $scope.$watch('maeklarObjekt.Latitud.value', function (newVal, oldVal) { if ($scope.maeklarObjekt.$resolved && typeof oldVal !== 'undefined' && newVal !== oldVal) { $scope.maeklarObjekt.Latitud.dirty = true; $scope.maeklarObjekt.enqueue(); } if ($scope.maeklarObjekt.Longitud !== undefined && $scope.maeklarObjekt.Longitud.value !== null) { $scope.mapMarkerCoordinates = { Latitud: $scope.maeklarObjekt.Latitud, Longitud: $scope.maeklarObjekt.Longitud }; } }); $scope.$watch('maeklarObjekt.Longitud.value', function (newVal, oldVal) { if ($scope.maeklarObjekt.$resolved && typeof oldVal !== 'undefined' && newVal !== oldVal) { $scope.maeklarObjekt.Longitud.dirty = true; $scope.maeklarObjekt.enqueue(); } if ($scope.maeklarObjekt.Latitud !== undefined && $scope.maeklarObjekt.Latitud.value !== null) { $scope.mapMarkerCoordinates = { Latitud: $scope.maeklarObjekt.Latitud, Longitud: $scope.maeklarObjekt.Longitud }; } }); // TODO frha: Se till att flytta all logik som har med collapsible hit, dvs även collapsibleControls och heading title $scope.maeklarObjektId = parseInt($routeParams.id, 10); $scope.fullViews = { fullViewConditionBasfakta: false, fullViewConditionBostadsbeskrivning: false, fullViewConditionParter: false, fullViewConditionBilder: false, fullViewConditionAnnonsering: false, fullViewConditionSpekulanter: false, fullViewConditionVisningar: false, fullViewConditionIntressent: false, fullViewConditionEkonomi: false, fullViewConditionDokument: false, fullViewConditionTilltraede: false, fullViewConditionHaendelse: false, fullViewConditionObjektIProjekt: false, fullViewConditionVaerdenTillObjektIProjekt: false, }; $scope.collapsibleControls = { fullViewConditionBasfakta: null, fullViewConditionBostadsbeskrivning: null, fullViewConditionParter: null, fullViewConditionBilder: null, fullViewConditionAnnonsering: null, fullViewConditionSpekulanter: null, fullViewConditionVisningar: null, fullViewConditionIntressent: null, fullViewConditionEkonomi: null, fullViewConditionDokument: null, fullViewConditionHaendelse: null, fullViewConditionTilltraede: null, fullViewConditionObjektIProjekt: null, fullViewConditionVaerdenTillObjektIProjekt: null, } $scope.$watch('maeklarObjekt.ExtraKontaktId.value', function (newVal: number, oldVal: number) { if (newVal !== oldVal) { if (typeof newVal !== 'undefined' && newVal !== $scope.maeklarObjekt.ExtraKontaktId.originalValue) { var objektIntressent = new fb.NyObjektIntressent({ PersonId: newVal, MaeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, ObjektIntressentRoll: fb.FasITDomain.ObjIntressentRoll.MAEKLARASSISTENT, }); $scope.maeklarObjekt.ExtraKontaktId.originalValue = newVal; objektIntressent.enqueue(); } else if (typeof newVal === 'undefined') { if (typeof oldVal !== 'undefined') { // Dequeuea eventuell existerande intressent från sparning så att den inte sparas under/efter den blir borttagen var removed = new fb.NyObjektIntressent({ PersonId: oldVal, MaeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, ObjektIntressentRoll: fb.FasITDomain.ObjIntressentRoll.MAEKLARASSISTENT, }); removed.dequeue(); } //Har rensats, sätts till undefined i fbforminputtypeahead då. var assistenter = intressentService.query($scope.maeklarObjekt.MaeklarObjektId.value, fb.FasITDomain.ObjIntressentRoll.MAEKLARASSISTENT) assistenter.$promise.then(function () { _.each(assistenter, function (assistent: fb.Objektintressent) { if ($scope.maeklarObjekt.isProjekt()) { intressentService.removeProjektIntressent(assistent, fb.FasITDomain.ObjIntressentRoll.MAEKLARASSISTENT); } else { intressentService.remove(assistent, fb.FasITDomain.ObjIntressentRoll.MAEKLARASSISTENT); } }) }); $scope.maeklarObjekt.ExtraKontaktId.originalValue = newVal; } } }); $scope.$watch('maeklarObjekt.IntagareId.value', function (newVal: number, oldVal: number) { if (newVal !== oldVal) { if (typeof newVal !== 'undefined' && newVal !== $scope.maeklarObjekt.IntagareId.originalValue) { var objektIntressent = new fb.NyObjektIntressent({ PersonId: newVal, MaeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, ObjektIntressentRoll: fb.FasITDomain.ObjIntressentRoll.INTAGARE, }); $scope.maeklarObjekt.IntagareId.originalValue = newVal; objektIntressent.enqueue(); } else if (typeof newVal === 'undefined') { if (typeof oldVal !== 'undefined') { // Dequeuea eventuell existerande intressent från sparning så att den inte sparas under/efter den blir borttagen var removed = new fb.NyObjektIntressent({ PersonId: oldVal, MaeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, ObjektIntressentRoll: fb.FasITDomain.ObjIntressentRoll.INTAGARE, }); removed.dequeue(); } //Har rensats, sätts till undefined i fbforminputtypeahead då. var intagareList = intressentService.query($scope.maeklarObjekt.MaeklarObjektId.value, fb.FasITDomain.ObjIntressentRoll.INTAGARE) intagareList.$promise.then(function () { _.each(intagareList, function (intagare: fb.Objektintressent) { if ($scope.maeklarObjekt.isProjekt()) { intressentService.removeProjektIntressent(intagare, fb.FasITDomain.ObjIntressentRoll.INTAGARE); } else { intressentService.remove(intagare, fb.FasITDomain.ObjIntressentRoll.INTAGARE); } }) }); $scope.maeklarObjekt.IntagareId.originalValue = newVal; } } }); var showFoersaeljningsrapporteratKommentarTimeout; var changeFoersaeljningsrapporteringsRelatedFields = function (newVal, oldVal, changeTrackField: fb.ChangeTrack) { if (newVal !== oldVal && newVal !== changeTrackField.originalValue) { // Vill inte att denna ska triggas när man sätter fast provision där det innan inte var angivet. if (oldVal === null && (changeTrackField).propertyReference === 'MaeklarObjektDO.ProvisFast') { return; } if ((changeTrackField).propertyReference === 'MaeklarObjektDO.ProvisProc' && _.contains([fb.FasITDomain.UppdragTyp.SKRIVNING, fb.FasITDomain.UppdragTyp.VAERDERING], $scope.maeklarObjekt.UppdragTyp.value)) { return; } if ($scope.maeklarObjekt.isSaald()) { $timeout.cancel(showFoersaeljningsrapporteratKommentarTimeout); showFoersaeljningsrapporteratKommentarTimeout = $timeout(function () { $scope.maeklarObjekt.SenasteProvisionsFoeraendringKommentar.required = true; $scope.maeklarObjekt.applyValue($scope.maeklarObjekt.SenasteProvisionsFoeraendringKommentar); $scope.foersaeljningsrapporteratKommentarValues = { changeTrack: changeTrackField, requiredError: false } $scope.showFoersaeljningsrapporteratKommentar = true; if (!_.find(($scope.maeklarObjekt).invalidField, function (item) { return item === 'MaeklarObjektDO.angeFoersaeljningsrapporteratKommentar' })) { ($scope.maeklarObjekt).invalidField.push('MaeklarObjektDO.angeFoersaeljningsrapporteratKommentar') } $scope.tmpFoersaeljningsrapporteratKommentar = new fb.ChangeTrack($scope.maeklarObjekt.SenasteProvisionsFoeraendringKommentar.value); $scope.tmpFoersaeljningsrapporteratKommentar.required = true; $timeout(function () { $('#tmpFoersaeljningsrapporteratKommentar textarea').focus(); }, 1); }, 1000); } } }; $scope.foersaeljningsrapporteratKommentarCallBack = { Ok: function () { if (!$scope.tmpFoersaeljningsrapporteratKommentar.valid) { $scope.showFoersaeljningsrapporteratKommentar = true; $scope.foersaeljningsrapporteratKommentarValues.requiredError = true; } else { ($scope.maeklarObjekt).invalidField.splice(($scope.maeklarObjekt).invalidField.indexOf('MaeklarObjektDO.angeFoersaeljningsrapporteratKommentar')); $scope.maeklarObjekt.SenasteProvisionsFoeraendringKommentar.value = $scope.tmpFoersaeljningsrapporteratKommentar.value; $scope.maeklarObjekt.applyValue($scope.maeklarObjekt.SenasteProvisionsFoeraendringKommentar); } }, Cancel: function () { ($scope.maeklarObjekt).invalidField.splice(($scope.maeklarObjekt).invalidField.indexOf('MaeklarObjektDO.angeFoersaeljningsrapporteratKommentar')); $scope.maeklarObjekt.SenasteProvisionsFoeraendringKommentar.required = false; $scope.maeklarObjekt.applyValue($scope.maeklarObjekt.SenasteProvisionsFoeraendringKommentar); $scope.tmpFoersaeljningsrapporteratKommentar.required = false; $scope.foersaeljningsrapporteratKommentarValues.changeTrack.setValue( $scope.foersaeljningsrapporteratKommentarValues.changeTrack.originalValue); } }; $scope.openKalenderHandelseSideDrawer = function (resource: fb.ResourceBase, changeTrackPropName: string, relatedChangeTrackPropName?: string) { var openSideDrawer = function () { var changeTrack = >resource[changeTrackPropName]; var relatedChangeTrack = _.isUndefined(relatedChangeTrackPropName) ? { dirty: false } : >resource[relatedChangeTrackPropName]; var metaVaerde = resource.getPrimaryKey() + ''; var metaNamn = resource.$rootName === fb.MaeklarObjektDO.$rootName ? changeTrackPropName : resource.$rootName === fb.Visning.$rootName ? 'Visning' : (resource.$rootName === fb.MaeklarObjektVillkor.$rootName && changeTrackPropName === 'LaanDatum') ? 'VillkorsdagLaan' : (resource.$rootName === fb.MaeklarObjektVillkor.$rootName && changeTrackPropName === 'BesiktigadDatum') ? 'VillkorsdagBesiktigad' : (resource.$rootName === fb.MaeklarObjektVillkor.$rootName && changeTrackPropName === 'OevrigaVillkorDatum') ? 'VillkorsdagOevrigt' : undefined; if (_.isUndefined(changeTrack)) { return console.warn('Saknar changetrack'); } if (_.isUndefined(metaNamn)) { return console.warn('Okänt metanamn'); } sideDrawerService.setSideDrawer('KalenderHandelse', { MetadataNamn: metaNamn, MetadataVaerde: metaVaerde, preSaveGlobalQueue: changeTrack.dirty || relatedChangeTrack.dirty, MaeklarObjekt: $scope.maeklarObjekt }, '500px'); }; if ($scope.maeklarObjekt.MaeklarObjektTilltraedelse.MedarbetareId.dirty || $scope.maeklarObjekt.TilltraedelseDatum.dirty) { globalTimerService.globalSave(true).then(function () { openSideDrawer(); }); } else { openSideDrawer(); } }; $scope.tipsaOmKoepare = function () { var parter = intressentService.queryParter($scope.maeklarObjekt.MaeklarObjektId.value); parter.$promise.then(function () { sideDrawerService.setSideDrawer('Tipsa', { tipsKontakter: _.filter(parter, function (p: fb.ObjIntressentPartDO) { return p.ObjIntressentRoll.value === fb.ObjektIntressentRollId.Koepare; }), typAvKontakt: 'koepare', foervaldMottagare: 'bank', maeklarObjekt: $scope.maeklarObjekt }, '640px'); }); }; $scope.tipsaOmSaeljare = function () { var parter = intressentService.queryParter($scope.maeklarObjekt.MaeklarObjektId.value); parter.$promise.then(function () { sideDrawerService.setSideDrawer('Tipsa', { tipsKontakter: _.filter(parter, function (p: fb.ObjIntressentPartDO) { return p.ObjIntressentRoll.value === fb.ObjektIntressentRollId.Saeljare; }), typAvKontakt: 'saeljare', foervaldMottagare: 'bank', maeklarObjekt: $scope.maeklarObjekt }, '640px'); }); }; $scope.mainContentInnerWrapper = angular.element('#mainContentInnerWrapper'); //State var obj = stateService.loadState('MaeklarObjektCtrl', $routeParams.id); if (obj) { if (obj.drawer) { sideDrawerService.setSideDrawer(obj.drawer.drawerName, obj.drawer.params, obj.drawer.width); } } //End state //Anchors var getAnchorLinks = function () { if (!$scope.maeklarObjekt) { return []; } var tmpAnchors = []; tmpAnchors.push({ id: 'maeklarObjektInnerWrapper', name: 'Uppdragsinfo', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBasfakta' } }); tmpAnchors.push({ id: 'parterData', name: 'Parter', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionParter' } }); tmpAnchors.push({ id: 'bostadsbeskrivningData', name: $scope.getTranslateNameFromModel('BOSTADSBESKRIVNING-HEADER'), active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' } }); var bostadsbeskrivningUnderAnchors = [ { id: 'BOSTADSBESKRIVNING-SAELJBESKRIVNING', name: 'Säljbeskrivning', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-INTERIOERBESKRIVNING', name: 'Interiörbeskrivning', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-BOSTAD', name: 'Lägenhet', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-BOSTAD', name: 'Byggnad', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-FOERENING', name: 'Förening', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-BOSTADSEKONOMI', name: 'Bostadsekonomi', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-OEVRIG_BESKRIVNING', name: 'Övrig beskrivning', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-FOERBESIKTNING', name: 'Förbesiktning', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-NAEROMRAADE', name: 'Närområde', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-FASTIGHET', name: 'Fastighet', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-PROJEKTBESKRIVNING', name: 'Projektbeskrivning', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-BYGGNAD', name: 'Byggnad', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-INTERIOERBESKRIVNING', name: 'Byggnad', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-INTERIOERBESKRIVNING', name: 'Beskrivning', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-BOSTADSEKONOMI', name: $translate.instant('MAEKLAROBJEKT_BOSTADSBESKRIVNING.OBJEKTEKONOMI'), active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, { id: 'BOSTADSBESKRIVNING-BOSTAD', name: $translate.instant('MAEKLAROBJEKT_BOSTADSBESKRIVNING.BOSTADSDEL'), active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostadsbeskrivning' }, subheader: true, parent: 'bostadsbeskrivningData', parentIndex: 2 }, ]; // Om maeklarobjektet är en fastighet if ($scope.maeklarObjekt.isSmaahus && !$scope.maeklarObjekt.isProjekt()) { tmpAnchors.push(bostadsbeskrivningUnderAnchors[0]); //Säljbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[1]); //Interiörbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[3]); //Byggnad tmpAnchors.push(bostadsbeskrivningUnderAnchors[9]); //Fastighet tmpAnchors.push(bostadsbeskrivningUnderAnchors[5]); //Bostadsekonomi tmpAnchors.push(bostadsbeskrivningUnderAnchors[6]); //Övrig beskrivning' tmpAnchors.push(bostadsbeskrivningUnderAnchors[7]); //Förbesiktning tmpAnchors.push(bostadsbeskrivningUnderAnchors[8]); //Närområde } else if ($scope.maeklarObjekt.isGaard) { tmpAnchors.push(bostadsbeskrivningUnderAnchors[0]); //Säljbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[12]); //Byggnad tmpAnchors.push(bostadsbeskrivningUnderAnchors[9]); //Fastighet tmpAnchors.push(bostadsbeskrivningUnderAnchors[5]); //Bostadsekonomi tmpAnchors.push(bostadsbeskrivningUnderAnchors[6]); //Övrig beskrivning' tmpAnchors.push(bostadsbeskrivningUnderAnchors[7]); //Förbesiktning tmpAnchors.push(bostadsbeskrivningUnderAnchors[8]); //Närområde } else if ($scope.maeklarObjekt.isOevrig) { tmpAnchors.push(bostadsbeskrivningUnderAnchors[0]); //Säljbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[13]); // Beskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[3]); //Byggnad tmpAnchors.push(bostadsbeskrivningUnderAnchors[9]); //Fastighet tmpAnchors.push(bostadsbeskrivningUnderAnchors[14]); //Bostadsekonomi tmpAnchors.push(bostadsbeskrivningUnderAnchors[6]); //Övrig beskrivning' tmpAnchors.push(bostadsbeskrivningUnderAnchors[8]); //Närområde } else if ($scope.maeklarObjekt.isAegarlgh) { tmpAnchors.push(bostadsbeskrivningUnderAnchors[0]); //Säljbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[1]); //Interiörbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[15]); //Bostadsdel tmpAnchors.push(bostadsbeskrivningUnderAnchors[11]); //Byggnad tmpAnchors.push(bostadsbeskrivningUnderAnchors[9]); //Fastighet tmpAnchors.push(bostadsbeskrivningUnderAnchors[4]); //Förening tmpAnchors.push(bostadsbeskrivningUnderAnchors[5]); //Bostadsekonomi tmpAnchors.push(bostadsbeskrivningUnderAnchors[6]); //Övrig beskrivning' tmpAnchors.push(bostadsbeskrivningUnderAnchors[7]); //Förbesiktning tmpAnchors.push(bostadsbeskrivningUnderAnchors[8]); //Närområde } else if ($scope.maeklarObjekt.isArrende) { tmpAnchors.push(bostadsbeskrivningUnderAnchors[0]); // Säljbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[1]); // Interiörbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[3]); // Byggnad tmpAnchors.push(bostadsbeskrivningUnderAnchors[9]); // Fastighet tmpAnchors.push(bostadsbeskrivningUnderAnchors[5]); // Bostadsekonomi tmpAnchors.push(bostadsbeskrivningUnderAnchors[6]); // Övrig beskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[7]); // Förbesiktning tmpAnchors.push(bostadsbeskrivningUnderAnchors[8]); // Närområde } else if ($scope.maeklarObjekt.isUtland) { tmpAnchors.push(bostadsbeskrivningUnderAnchors[0]); //Säljbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[1]); //Interiörbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[3]); //Byggnad tmpAnchors.push(bostadsbeskrivningUnderAnchors[9]); //Fastighet tmpAnchors.push(bostadsbeskrivningUnderAnchors[5]); //Bostadsekonomi tmpAnchors.push(bostadsbeskrivningUnderAnchors[6]); //Övrig beskrivning' tmpAnchors.push(bostadsbeskrivningUnderAnchors[8]); //Närområde } else if (!$scope.maeklarObjekt.isProjekt()) { tmpAnchors.push(bostadsbeskrivningUnderAnchors[0]); //Säljbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[1]); //Interiörbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[2]); //Lägenhet tmpAnchors.push(bostadsbeskrivningUnderAnchors[11]); //Byggnad tmpAnchors.push(bostadsbeskrivningUnderAnchors[4]); //Förening tmpAnchors.push(bostadsbeskrivningUnderAnchors[5]); //Bostadsekonomi tmpAnchors.push(bostadsbeskrivningUnderAnchors[6]); //Övrig beskrivning' tmpAnchors.push(bostadsbeskrivningUnderAnchors[7]); //Förbesiktning tmpAnchors.push(bostadsbeskrivningUnderAnchors[8]); //Närområde } else if ($scope.maeklarObjekt.isProjekt()) { tmpAnchors.push(bostadsbeskrivningUnderAnchors[10]); //Projektbeskrivning tmpAnchors.push(bostadsbeskrivningUnderAnchors[8]); //Närområde } if ($scope.maeklarObjekt.isProjekt()) { tmpAnchors.push({ id: 'objektIProjektData', name: 'Objekt i projektet', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionObjektIProjekt' } }); } if ($scope.maeklarObjekt.isProjekt()) { tmpAnchors.push({ id: 'vaerdenTillObjektIProjektData', name: 'Uppdatera objekt', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionVaerdenTillObjektIProjekt' } }); } //{ id: 'bostadenData', name: 'Fakta om bostaden', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBostaden' } }, tmpAnchors.push({ id: 'bilderData', name: 'Bilder', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionBilder' } }); tmpAnchors.push({ id: 'visningarData', name: 'Visningar', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionVisningar' } }); tmpAnchors.push({ id: 'annonseringData', name: 'Annonsering', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionAnnonsering' } }); if ($scope.maeklarObjekt.isFoersaeljning()) { tmpAnchors.push({ id: 'spekulanterData', name: 'Spekulanter', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionSpekulanter' } }); } //Ny ProjektIntressent tmpAnchors.push({ id: 'intressentData', name: 'Intressenter', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionIntressent' } }); if (!$scope.maeklarObjekt.isProjekt()) { tmpAnchors.push({ id: 'ekonomiData', name: 'Ekonomi', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionEkonomi' } }); tmpAnchors.push({ id: 'tilltraedeData', name: 'Tillträde', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionTilltraede' } }); } tmpAnchors.push({ id: 'dokumentData', name: 'Dokument', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionDokument' } }); tmpAnchors.push({ id: 'haendelseData', name: 'Logg', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionHaendelse' } }); return tmpAnchors; }; //End Anchors $scope.dimensions = commonService.getScreenDimensions(); $scope.maeklarObjekt = maeklarObjektService.get($routeParams.id); $scope.maeklarObjekt.$promise.then(() => { $scope.dagarTillTilltraede = $scope.maeklarObjekt.TilltraedelseDatum.value ? moment($scope.maeklarObjekt.TilltraedelseDatum.value).diff(moment(), 'days') : Infinity; // Sätter postort ifall postnummer är 5 tecken långt och det inte finns någon postort satt och objektet är utland if (!$scope.maeklarObjekt.isUtland) { $scope.$watch('maeklarObjekt.Adress.Postnummer.value', function (newVal: string) { if (newVal && (newVal + '').length > 4 && !$scope.maeklarObjekt.Adress.Postort.value) { var postort = postadressService.getPostort(newVal + ''); postort.$promise.then(function () { // Verifierar så att användaren inte har hunnit fylla i ett värde när promise resolvas if (!$scope.maeklarObjekt.Adress.Postort.value) { $scope.maeklarObjekt.Adress.Postort.setValue(postort.Postort); } }); } }); } if ($scope.maeklarObjekt.Latitud.value !== null && $scope.maeklarObjekt.Longitud !== null) { $scope.mapMarkerCoordinates = { Latitud: $scope.maeklarObjekt.Latitud, Longitud: $scope.maeklarObjekt.Longitud }; } else { $scope.mapMarkerCoordinates = null; } haemtaAntalOloestaKommentarer(); }); $scope.kontoretsMaeklareOchAssistenter = medarbetareService.getByRoll(false); var omPersonenFannsPaaKontoretMenInteAerKvarOchAegerDetHaerObjektet = medarbetareService.getByRoll(true); $scope.kontoretsMaeklareDef = $q.all([$scope.kontoretsMaeklareOchAssistenter.$promise, omPersonenFannsPaaKontoretMenInteAerKvarOchAegerDetHaerObjektet.$promise, $scope.maeklarObjekt.$promise]).then(function () { $scope.kontoretsMaeklare = []; angular.forEach($scope.kontoretsMaeklareOchAssistenter, function (val, key) { if (val.MedarbetareRoll.value === fb.FasITDomain.MedarbetareRoll.MAEKLARE || val.MedarbetareRoll.value === fb.FasITDomain.MedarbetareRoll.SAELJARE_UTLAND || val.MedarbetareRoll.value === fb.FasITDomain.MedarbetareRoll.INNESAELJARE_UTLAND) { $scope.kontoretsMaeklare.push(val); } }); if (!_.contains(_.map($scope.kontoretsMaeklare, item => item.PersonId.value), $scope.maeklarObjekt.AnsvarigMaeklareId.value)) { var riktigMaeklare = _.find(omPersonenFannsPaaKontoretMenInteAerKvarOchAegerDetHaerObjektet, function (item: fb.Medarbetare) { return item.PersonId.value === $scope.maeklarObjekt.AnsvarigMaeklareId.value }) if (riktigMaeklare) { $scope.kontoretsMaeklare.push(riktigMaeklare); } } if (!_.contains(_.map($scope.kontoretsMaeklareOchAssistenter, item => item.PersonId.value), $scope.maeklarObjekt.ExtraKontaktId.value)) { var riktigAss = _.find(omPersonenFannsPaaKontoretMenInteAerKvarOchAegerDetHaerObjektet, function (item: fb.Medarbetare) { return item.PersonId.value === $scope.maeklarObjekt.ExtraKontaktId.value }) if (riktigAss) { $scope.kontoretsMaeklareOchAssistenter.push(riktigAss); } } // Filtrerar bort mäklare som har slutat (och inte står som ansvarig mäklare eller extrakontakt på objektet) $scope.kontoretsMaeklare = _.filter($scope.kontoretsMaeklare, function (item: fb.Medarbetare) { return (item.HarSlutat.value === false || item.PersonId.value === $scope.maeklarObjekt.AnsvarigMaeklareId.value || item.PersonId.value === $scope.maeklarObjekt.ExtraKontaktId.value); }); }); $scope.foereningWrapper = { foerening: new fb.JuridiskPersonDO({}) }; $scope.ansvarigMaeklare = new fb.ChangeTrack(null); $scope.ansvarigMaeklare.required = true; $scope.maeklarObjekt.$promise.then(function () { if ($scope.maeklarObjekt.ObjektIProjekt && $scope.maeklarObjekt.ObjektIProjekt.ProjektId) { uiService.open('ObjektIProjekt'); } if ($scope.maeklarObjekt.isBRL || $scope.maeklarObjekt.isAegarlgh) { $scope.foereningWrapper.foerening = foereningService.getByMaeklarObjektId($scope.maeklarObjekt.MaeklarObjektId.value, $scope.maeklarObjekt.ObjektTypId.value); } $scope.leftNavObj = _.find(navigationService.getNavigationObjects().OeppnaObjekt.OeppnaMaeklarObjekt, function (item: fb.OeppnaMaeklarObjekt) { return item.MaeklarObjektId === $scope.maeklarObjekt.MaeklarObjektId.value; }) $scope.ansvarigMaeklare.setValue($scope.maeklarObjekt.AnsvarigMaeklareId.value); // Flyttat denna från ekonomi-controller så den inte triggas av watchers $scope.maeklarObjekt.ProvisAerInklusiveMoms.value = $scope.maeklarObjekt.ProvisAerInklusiveMoms.value === null ? true : $scope.maeklarObjekt.ProvisAerInklusiveMoms.value; $scope.laenkarTillExternaSiterFull = maeklarObjektService.laenkarTillExternaSiteFull($scope.maeklarObjekt.MaeklarObjektId.value, $scope.maeklarObjekt.Kontorsnummer.value); }, function (error) { if (error.status === 403) { $scope.showErrorTillhoerAnnatKontor = true; } }); $scope.ansvarigMaeklareSpinner = { $resolved: true }; $scope.onFoereningChange = function (nyFoerening) { $scope.foereningWrapper.foerening = nyFoerening.foerening; }; var originalAnsvarigMaeklare; var nyAnsvarigMaeklare; $scope.cancelChangeAnsvarigMaeklare = function () { $scope.showChangeAnsvarigMaeklareFoerFoersaeljningsrapporterat = false; $scope.ansvarigMaeklare.setValue(originalAnsvarigMaeklare); }; $scope.kontrolleraNyckelNummer = (nyckelNummer: fb.ChangeTrack, maeklarObjektId: fb.ChangeTrack) => { $scope.showNyckelNummerInputError = false; if (typeof nyckelNummer.value === 'undefined' || nyckelNummer.value == null || nyckelNummer.value === "") { $scope.showNyckelNummerInputError = true; return; } $scope.nyckelNummerObjekt = ""; $scope.showKontrolleraNyckelNummer = false; var maeklarObjektMinimalList; $scope.maeklarObjekt.$promise.then(() => { maeklarObjektMinimalList = maeklarObjektService.getKontrolleraNyckelNummer(nyckelNummer.value, maeklarObjektId.value); maeklarObjektMinimalList[0].$promise.then(function (data) { if (maeklarObjektMinimalList[0].some(i => i === $scope.maeklarObjekt.MaeklarObjektId.value)) { $scope.ledigtNyckelNummer = true; maeklarObjektMinimalList[0] = maeklarObjektMinimalList[0] .filter(resource => resource && resource.ObjektNummer === $scope.maeklarObjekt.ObjektNummer.value); } if (maeklarObjektMinimalList[0].length > 0) { $scope.ledigtNyckelNummer = false; } else { $scope.ledigtNyckelNummer = true; } if ($scope.ledigtNyckelNummer) { $scope.nyckelNummerText = $filter('translate')('MAEKLAROBJEKT_BASFAKTA.NYCKELNUMMER_LEDIGT'); $scope.showKontrolleraNyckelNummer = true; } else { for (var i = 0; i < maeklarObjektMinimalList.length; i++) { for (var j = 0; j < maeklarObjektMinimalList[i].length; j++) { if (maeklarObjektMinimalList[i][j].ObjektNummer !== $scope.maeklarObjekt.ObjektNummer.value) { var anchorTag = '' + maeklarObjektMinimalList[i][j].ObjektNummer + ' ' + ''; $scope.nyckelNummerObjekt += anchorTag; } } } $scope.nyckelNummerText = $filter('translate')('MAEKLAROBJEKT_BASFAKTA.NYCKELNUMMER_ANVAENDS_AV') + $filter('translate')('MAEKLAROBJEKT_BASFAKTA.NYCKELNUMMER_VAD_VILL_DU_GOERA'); $scope.showKontrolleraNyckelNummer = true; } }); }); }; $scope.openMaeklarObjekt = function (maeklarObjektId) { navigationService.findOpenObjekt(fb.FasITDomain.NavigationController.MAEKLAROBJEKT, maeklarObjektId, true); }; $scope.taBortNyckelNummerFraanAllaObjekt = function (nyckelNummer: fb.ChangeTrack, maeklarObjektId: fb.ChangeTrack) { var success = maeklarObjektService.putTaBortNyckelNummerFraanAllaObjekt(nyckelNummer.value, maeklarObjektId.value); success.$promise.then(() => { $scope.showKontrolleraNyckelNummer = false; }); } $scope.closePopover = function () { $scope.showKontrolleraNyckelNummer = false; } $scope.updateAnsvarigMaeklareSpinner = function () { $scope.showChangeAnsvarigMaeklareFoerFoersaeljningsrapporterat = false; if (nyAnsvarigMaeklare !== undefined && nyAnsvarigMaeklare !== null) { //Bytt mäklare $scope.ansvarigMaeklareSpinner = maeklarObjektService.aendraMaeklareTill(nyAnsvarigMaeklare, [$scope.maeklarObjekt.MaeklarObjektId.value]); $scope.ansvarigMaeklareSpinner.$promise.then(function () { $scope.maeklarObjekt.AnsvarigMaeklareId = new fb.ChangeTrack(nyAnsvarigMaeklare, $scope.maeklarObjekt, ''); }); } }; var valideraKanBytaAnsvarigMaeklare = function () { return !$scope.maeklarObjekt.AerFoersaeljningsrapporterat.value && !_.contains([ fb.FasITDomain.UppdragStatus.INGET_UPPDRAG, fb.FasITDomain.UppdragStatus.AATERTAGEN, fb.FasITDomain.UppdragStatus.SAALD, fb.FasITDomain.UppdragStatus.PROJEKT_AVSLUTAT ], $scope.maeklarObjekt.UppdragStatus.value); }; $scope.$watch('ansvarigMaeklare.value', function (newval, oldval) { if (newval !== oldval && angular.isDefined(newval) && newval !== null) { if ($scope.maeklarObjekt.AnsvarigMaeklareId.value !== newval) { originalAnsvarigMaeklare = oldval; nyAnsvarigMaeklare = newval; if (!valideraKanBytaAnsvarigMaeklare()) { $scope.showChangeAnsvarigMaeklareFoerFoersaeljningsrapporterat = true; } else { $scope.updateAnsvarigMaeklareSpinner(); } } } }); function scrollToId(id: string, offset: number) { var target = angular.element("#" + id); if (target.length > 0) { var scrollContainer = angular.element('#maeklarObjektOuterWrapper'); offset = scrollContainer.scrollTop() + target.offset().top; scrollContainer.animate({ scrollTop: offset }, '500', 'swing'); } } $scope.scrollToBasplatta = function (id: string) { var anchor = _.findWhere(getAnchorLinks(), { id: id }); var offset = 0; if (anchor.fullViewCondition && anchor.fullViewCondition.fullViews && anchor.fullViewCondition.name) { if ($scope.fullViews[anchor.fullViewCondition.name] === false) { var removeListener = $rootScope.$on("fbCollapsible_expanded", () => { $timeout(() => { if (anchor.name !== 'Uppdragsinfo') { scrollToId(id, offset); } removeListener(); }, 0); }); if (anchor.name === 'Uppdragsinfo') { $scope.collapsibleControls[anchor.fullViewCondition.name].expand(false); } else { $scope.collapsibleControls[anchor.fullViewCondition.name].expand(true); } } else { scrollToId(id, offset); } } }; $scope.close = function (strategi?: fb.NavigationStrategy) { if (strategi === undefined || strategi === null) { navigationService.closeWoNavigationObjekt(parseInt($routeParams.id, 10), 'MaeklarObjekt'); } else { navigationService.closeWoNavigationObjekt(parseInt($routeParams.id, 10), 'MaeklarObjekt', strategi); } } $q.all([$scope.maeklarObjekt.$promise, $rootScope.InloggadAnvaendare.promise]).then(function () { $timeout(function () { //Närområde $scope.$emit('fbContentReady'); if ($scope.maeklarObjekt.ExtraKontaktId) { $scope.extraKontaktId = new fb.ChangeTrack($scope.maeklarObjekt.ExtraKontaktId.value); } $scope.upplatelseform = domainService.upplatelseform.query($scope.maeklarObjekt.ObjektTypId.value) || new fb.List([], fb.Upplaatelseform); $scope.boendeform = domainService.boendeform.query($scope.maeklarObjekt.ObjektTypId.value, $scope.maeklarObjekt.Boendeform.value) || new fb.List([], fb.Boendeform); if (obj && obj.fullViews) { $timeout(function () { $scope.fullViews = obj.fullViews; $scope.anchorLinks = getAnchorLinks(); }, 100); } else { $timeout(function () { $scope.fullViews.fullViewConditionBasfakta = true; $scope.anchorLinks = getAnchorLinks(); }, 100); } $scope.$watch('maeklarObjekt.UppdragStatus.value', () => haemtaAntalOloestaKommentarer()); $scope.$watch('maeklarObjekt.UppdragStatusSpecifikation.value', () => haemtaAntalOloestaKommentarer()); }); $scope.isProjektUtland = $rootScope.InloggadAnvaendare.BostadsmarknadId === fb.FasITDomain.Bostadsmarknad.UTLAND && $scope.maeklarObjekt.isProjekt(); if (!$scope.maeklarObjekt.isUtland && !$scope.isProjektUtland) { $scope.journalProgress = journalService.getTotalProgress($scope.maeklarObjektId); $scope.oeppnaJournal = function () { sideDrawerService.setSideDrawer('Journal', { maeklarObjekt: $scope.maeklarObjekt, journalProgress: $scope.journalProgress }, '820px'); }; } $scope.utoekadeSoekbegreppOptions = domainService.getUtoekadeSoekbegreppDomain; $scope.bostadsBeskrivningHeader = $scope.getTranslateNameFromModel('BOSTADSBESKRIVNING-HEADER'); $scope.GaarAttBestaellaInfoOmSlutprisOptions = maeklarObjektCommonService.getGaarAttBestaellaInfoOmSlutprisList(); $scope.$watch('maeklarObjekt.ProvisFast.value', function (newVal, oldVal) { changeFoersaeljningsrapporteringsRelatedFields(newVal, oldVal, $scope.maeklarObjekt.ProvisFast); }); $scope.$watch('maeklarObjekt.ProvisProc.value', function (newVal, oldVal) { changeFoersaeljningsrapporteringsRelatedFields(newVal, oldVal, $scope.maeklarObjekt.ProvisProc); }); $scope.$watch('maeklarObjekt.SlutPris.value', function (newVal, oldVal) { if ($scope.maeklarObjekt.ProvisProc.value) { changeFoersaeljningsrapporteringsRelatedFields(newVal, oldVal, $scope.maeklarObjekt.SlutPris); } }); $scope.$watch('maeklarObjekt.ProvisAerInklusiveMoms.value', function (newVal, oldVal) { changeFoersaeljningsrapporteringsRelatedFields(newVal, oldVal, $scope.maeklarObjekt.ProvisAerInklusiveMoms); }); $scope.$watch('maeklarObjekt.ExtraKostn1.value', function (newVal, oldVal) { changeFoersaeljningsrapporteringsRelatedFields(newVal, oldVal, $scope.maeklarObjekt.ExtraKostn1); }); $scope.$watch('maeklarObjekt.ExtraKostn2.value', function (newVal, oldVal) { changeFoersaeljningsrapporteringsRelatedFields(newVal, oldVal, $scope.maeklarObjekt.ExtraKostn2); }); $scope.$watch('maeklarObjekt.ExtraKostnInklMoms.value', function (newVal, oldVal) { changeFoersaeljningsrapporteringsRelatedFields(newVal, oldVal, $scope.maeklarObjekt.ExtraKostnInklMoms); }); $scope.$watch('maeklarObjekt.Boendeform.value', function (newVal: number, oldVal) { if (!angular.isUndefined(newVal)) { $scope.boendeform = domainService.boendeform.query($scope.maeklarObjekt.ObjektTypId.value, newVal) || new fb.List([], fb.Boendeform); } }); if ($scope.maeklarObjekt.isUtland) { $scope.$watchCollection('maeklarObjekt.ObjNyckelordList', function (newVal: fb.ChangeTrack[], oldVal: fb.ChangeTrack[]) { if (newVal !== oldVal && newVal && oldVal && newVal.length !== oldVal.length) { $scope.maeklarObjekt.enqueue(); } }); } if (!$scope.maeklarObjekt.isUtland && !$scope.isProjektUtland) { $scope.$watch('maeklarObjekt.KommunId.value', function (newVal, oldVal) { if (newVal !== oldVal && typeof oldVal !== 'undefined') { refreshKommunalskatt(); } }); $scope.$watch('maeklarObjekt.Foersamlingskod.value', function (newVal, oldVal) { if (newVal !== oldVal && typeof oldVal !== 'undefined') { refreshKommunalskatt(); } }); $scope.$watch('maeklarObjekt.KommunId.value', function (newVal, oldVal) { if (typeof newVal !== 'undefined' && newVal !== null) { $scope.foersamling = domainService.foersamling.get($scope.maeklarObjekt.KommunId.value); } if (newVal !== oldVal && typeof oldVal !== 'undefined') { $scope.maeklarObjekt.Foersamlingskod.setValue(null); } }); } }); $scope.scroll = 0; $scope.kommun = kommunService.query(true); $scope.land = domainService.land.subquery([204, 191, 170]); $scope.soekbegrepp = domainService.soekbegrepp.query(); $scope.valutakod = domainService.valutakod.query(); $scope.uppdragtyp = domainService.uppdragtyp.query(); $scope.uppdragtypProjekt = domainService.uppdragtyp.queryProjekt(); $scope.intagskaella = domainService.intagskaella.query(); //$scope.energiklass = domainService.energiklass.query(); //Basfakta var refreshKommunalskatt = function () { if ($scope.maeklarObjekt.KommunId && $scope.maeklarObjekt.KommunId.value && $scope.maeklarObjekt.Foersamlingskod && $scope.maeklarObjekt.Foersamlingskod.value) { var kommunalSkatt = kommunalskattService.getByKommunFoersamlingInkomstaar($scope.maeklarObjekt.KommunId.value, $scope.maeklarObjekt.Foersamlingskod.value); kommunalSkatt.$promise.then(function () { if (kommunalSkatt.length > 0) { $scope.maeklarObjekt.Kommunalskatt.value = kommunalSkatt[0].SummaInklKyrkoavgift; } else { $scope.maeklarObjekt.Kommunalskatt.value = null; } }); } }; $scope.adress = function () { try { return navigationService.getCurrentlyViewedObject().Visningstext.toString(); } catch (ex) { } return ''; }; $scope.scrollTo = function (id, event) { $location.search('scroll', id); scrollService.scrollTo(id); } $scope.isopen = true; if ($location.search()['scroll'] !== undefined) { var initialScroll: string = $location.search()['scroll']; scrollService.scrollTo(initialScroll); $scope.isopen = true; } else { //scrollService.scrollTo('basinformationData'); } $scope.saeljare = function () { try { return navigationService.getCurrentlyViewedObject().Alternativtext.join(', '); } catch (ex) { } return ''; }; $scope.harSaeljare = function () { try { return navigationService.getCurrentlyViewedObject().Alternativtext.length > 0; } catch (ex) { } return false; }; $scope.taggOptions = taggService.query(fb.FasITDomain.TaggTyp.MAEKLAROBJEKTTAGG); $scope.$watchCollection(() => $scope.maeklarObjekt.ObjektTagg, function (newVal, oldVal) { if (newVal !== oldVal && newVal && oldVal && newVal.length !== oldVal.length) { $scope.maeklarObjekt.enqueue(); } }); $scope.editTaggar = function () { const taggSidedrawerParams = { taggar: $scope.taggOptions, isStackedSideDrawer: false, taggTyp: fb.FasITDomain.TaggTyp.MAEKLAROBJEKTTAGG }; sideDrawerService.setSideDrawer('Taggar', taggSidedrawerParams); }; /** Parter & intressenter **/ var rollConverter = function () { var intressentlista = domainService.objektintressentroll.query(); return function (obj) { var d = _.findWhere(intressentlista, { RollId: Number(obj.ObjektIntressentRoll.value) }); if (d !== undefined && d.Namn !== undefined && !isNaN(Number(obj.ObjektIntressentRoll.value))) { return d.Namn; } return "Ej valt"; } } /** END: Parter & intressenter & Visningar **/ // Karta $scope.openMapInSideDrawer = function () { sideDrawerService.setSideDrawer( 'Karta', { maeklarObjekt: $scope.maeklarObjekt, maeklarObjektAdress: $scope.maeklarObjekt.Adress }); }; // End karta // Duplicera $scope.changeUppdragTypFoerFoersaeljningsrapporteratDialogCallback = function (duplicera) { $scope.showChangeUppdragTypFoerFoersaeljningsrapporterat = false; if (duplicera) { $scope.openDupliceraInSideDrawer(true); } }; $scope.openDupliceraInSideDrawer = function (defaultSammaSaeljare) { sideDrawerService.setSideDrawer( 'DupliceraMaeklarObjekt', { maeklarObjekt: $scope.maeklarObjekt, defaultSammaSaeljare: defaultSammaSaeljare }); }; $scope.showArkiveraPopover = false; $scope.showTaBortSaaldPopover = false; // End Duplicera $scope.valideraObjektStatusFoerArkivering = function () { if (!$scope.maeklarObjekt || !$scope.maeklarObjekt.UppdragStatus || !$scope.maeklarObjekt.UppdragTyp) { return false; } return maeklarObjektService.validation.valideraObjektStatusFoerArkivering($scope.maeklarObjekt.UppdragStatus.value, $scope.maeklarObjekt.UppdragTyp.value); } $scope.valideraObjektStatusFoerBorttag = function () { if (!$scope.maeklarObjekt || !$scope.maeklarObjekt.UppdragStatus || !$scope.maeklarObjekt.UppdragTyp) { return false; } return maeklarObjektService.validation.valideraObjektStatusFoerBorttag($scope.maeklarObjekt.UppdragStatus.value, $scope.maeklarObjekt.UppdragTyp.value, $scope.maeklarObjekt.isSaald()); } $scope.aktivera = function () { $scope.maeklarObjekt.setValue($scope.maeklarObjekt.StatusLagring, 0); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.AerBorttagenIBasen, 0) $scope.laddaOmObjekt(); }; $scope.arkivera = function () { if (!$scope.valideraObjektStatusFoerArkivering()) { $scope.showArkiveraPopover = true; } else { $scope.maeklarObjekt.setValue($scope.maeklarObjekt.StatusLagring, 1); $scope.laddaOmObjekt(); } }; $scope.radera = function () { if ($scope.maeklarObjekt.isSaald()) { $scope.showTaBortSaaldPopover = true; } else if (!$scope.valideraObjektStatusFoerBorttag()) { $scope.showArkiveraPopover = true; } else { $scope.maeklarObjekt.setValue($scope.maeklarObjekt.StatusLagring, 2); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.AerBorttagenIBasen, true); $scope.maeklarObjekt.enqueue(); globalTimerService.saveItem($scope.maeklarObjekt.getGlobalUniqueId()).$promise.then(function () { }); $scope.close(fb.NavigationStrategy.STAENG_ENBART); } } $scope.showTaBortPopover = false; $scope.godtyckligaFiler = filService.maeklarObjekt.query($routeParams.id); var startUpload = function (index) { var fildo = { FilId: 0, Storlek: 0, Namn: '', Filaendelse: '', SkallVisasPaaInternet: false, MaeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, PersonId: null }; var obstr = JSON.stringify(fildo); $scope.upload = $upload.upload({ url: '/WebAPI/api/Fil/', method: 'POST', data: { FilDO: obstr }, 'file': $scope.uploadProgress[index].File, }).progress(function (evt) { $scope.uploadProgress[index].Progress = Math.round(100.0 * evt.loaded / evt.total); }).success(function (data, status, headers, config) { $scope.godtyckligaFiler.push(new fb.Fil(data)); $scope.uploadProgress[index].Message = $filter('translate')('FILUPPLADDNING_FAERDIG'); }).error(function (data, status, headers, config) { $scope.uploadProgress[index].Message = data.ExceptionMessage; }); }; //Filuppladdning $scope.onFileSelect = function ($files) { $scope.uploadProgress = []; /* jshint ignore:start */ for (var i = 0; i < $files.length; i++) { var file = $files[i]; $scope.uploadProgress[i] = { File: file, Progress: 0, Message: null }; startUpload(i); } /* jshint ignore:end */ }; //End Filuppladdning $scope.removeFile = function (fil: fb.Fil) { $scope.godtyckligaFiler.splice($scope.godtyckligaFiler.indexOf(fil), 1); filService.remove(fil.FilId.value); } // Funktioner för högernavigationen $scope.oeppnaBearbetning = function (chilli) { sideDrawerService.setSideDrawer('BearbetningsPalett', { maeklarObjekt: $scope.maeklarObjekt }, '640px'); } $scope.toggleHoegerPanel = function () { uiService.toggle(fb.FasITDomain.UIState.HoegerMeny); } $scope.intag = { url: $sce.trustAsResourceUrl(fb.Environment.vaerderingsdataURL), data: '', xml: null, isBestaeller: false, doBestaell: function () { $scope.intag.isBestaeller = true; vaerderingsDataService.intagsrapportEncoded($routeParams.id).then(function (data) { $scope.intag.data = data; $window.open($scope.intag.url + $scope.intag.data, '_blank'); }); } }; $scope.valueguardIntag = { url: $sce.trustAsResourceUrl(fb.Environment.valueguardURL), data: '', xml: null, isBestaeller: false, doBestaell: function () { $scope.valueguardIntag.isBestaeller = true; valueguardService.intagsrapportEncoded($routeParams.id).then(function (data) { $scope.valueguardIntag.data = data; $window.open($scope.valueguardIntag.url + 'data=' + $scope.valueguardIntag.data, '_blank'); }); } }; $scope.bildleverantoerer = bildbestaellningService.GetLeverantoerer(); $scope.bildleverantoerer.$promise.then(function () { angular.forEach($scope.bildleverantoerer, function (value: fb.BildleverantoerLO) { value.SecureUrl = $sce.trustAsResourceUrl(value.BestaellningsUrl); }); }); $scope.bildbestaellning = { Bestaell: function (leverantoer: fb.BildleverantoerLO) { leverantoer.Bestaellning = bildbestaellningService.GetXMLFoerMaeklarObjekt($scope.maeklarObjekt.MaeklarObjektId.value); leverantoer.Bestaellning.$promise.then(function () { bildbestaellningService.BestaelldHaendelse($scope.maeklarObjekt.MaeklarObjektId.value, leverantoer.LeverantoerId); }); } }; $scope.getTranslateNameFromModel = function (modelName) { return maeklarObjektCommonService.getTranslateNameFromModel($scope.maeklarObjekt, modelName); }; // Bäställ besiktning övrig $scope.oevrig = { besiktning: { openSideDrawer: function () { if ($scope.maeklarObjekt.isBRL) { sideDrawerService.setSideDrawer('EpostUtskick', { textMallNamn: fb.FasITDomain.TextMallNamn.BESIKTNINGSBESTAELLNING_ANTICIMEX_BR, maeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, mailSentCallback: function () { haendelseService.createHaendelseLoggBesiktningOevrigLeverantoer($scope.maeklarObjekt.MaeklarObjektId.value); $rootScope.$broadcast(fb.FasITDomain.GlobalEvents.LADDA_OM_MAEKLAROBJEKT_LOGG); } }); } else { sideDrawerService.setSideDrawer('EpostUtskick', { textMallNamn: fb.FasITDomain.TextMallNamn.BESIKTNINGSBESTAELLNING_OEVRIG, maeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, mailSentCallback: function () { haendelseService.createHaendelseLoggBesiktningOevrigLeverantoer($scope.maeklarObjekt.MaeklarObjektId.value); $rootScope.$broadcast(fb.FasITDomain.GlobalEvents.LADDA_OM_MAEKLAROBJEKT_LOGG); } }); } } }, personbevis: { openSideDrawer: function () { sideDrawerService.setSideDrawer('EpostUtskick', { textMallNamn: fb.FasITDomain.TextMallNamn.PERSONBEVIS, maeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, mailSentCallback: function () { $rootScope.$broadcast(fb.FasITDomain.GlobalEvents.LADDA_OM_MAEKLAROBJEKT_LOGG); } }); } } }; $scope.foersaekringsPris = foersaekringsPrisService.get(); $scope.besiktning = maeklarObjektBesiktningService.get($scope.maeklarObjektId); $scope.maeklarObjekt.$promise.then(() => { $scope.tilltrade = moment($scope.maeklarObjekt.SkapadIMS.value); $scope.byttProdukt = false; $scope.innanNyDoldaFel = $scope.tilltrade < moment(fb.FasITDomain.AnticimexDatum.NY_DOLDA_FEL_SEKTION_STARTDATUM); }); $scope.foersaekringBelopp = new fb.ChangeTrack(0); $scope.besiktning.$promise.then(() => { if ($scope.besiktning.MaeklarObjektId.value === null && !$rootScope.InloggadAnvaendare.AerSupport) { $scope.besiktning = new fb.MaeklarObjektBesiktning({ MaeklarObjektId: $scope.maeklarObjektId, FoersaekringsProduktId: null, FakturaTill: 1, OCR: null, BesiktningsFoeretag: 1, OeverlaatelseFoersaekrad: false, OeverlaatelseFoersaekradFoerbesiktningsDatum: null, BestaellningsDatum: null, OeverlaatelseFoersaekradBesiktningsprotokollsnummer: null }); $scope.besiktning = maeklarObjektBesiktningService.post($scope.besiktning); } }); $scope.checkIfProjektThenChangeObjektIProjekt = function () { if ($scope.maeklarObjekt.isProjekt()) { $scope.objektListaIProjekt = objektIProjektService.getObjektIProjekt($scope.maeklarObjekt.MaeklarObjektId.value); $scope.objektListaIProjekt.$promise.then(function () { for (var i = 0; i < $scope.objektListaIProjekt.getArray().length; ++i) { $scope.setNyproduktion(maeklarObjektService.get($scope.objektListaIProjekt[i].MaeklarObjektId.value, false)); } }); } } $scope.setNyproduktion = function (objektiProjekt: fb.MaeklarObjektDO) { if (objektiProjekt instanceof fb.MaeklarObjektDO) { objektiProjekt.$promise.then(function () { objektiProjekt.AerNyproduktion.setValue($scope.maeklarObjekt.AerNyproduktion.value); }); } } // Inget translate-stöd ges för anticimex alternativ eftersom att Anticimex är speciifkt för Sverige $scope.anticimex = { besiktning: { openSideDrawer: function () { if ($scope.maeklarObjekt.isBRL) { sideDrawerService.setSideDrawer('EpostUtskick', { textMallNamn: fb.FasITDomain.TextMallNamn.BESIKTNINGSBESTAELLNING_ANTICIMEX_BR, maeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, mailSentCallback: function () { $rootScope.$broadcast(fb.FasITDomain.GlobalEvents.LADDA_OM_MAEKLAROBJEKT_LOGG); } }); } else { sideDrawerService.setSideDrawer('EpostUtskick', { textMallNamn: fb.FasITDomain.TextMallNamn.BESIKTNINGSBESTAELLNING_OEVRIG, maeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, mailSentCallback: function () { $rootScope.$broadcast(fb.FasITDomain.GlobalEvents.LADDA_OM_MAEKLAROBJEKT_LOGG); } }); } } }, foersaekring: { status: 0, showPopover: false, datumOchProtokollsnummerVaerdenSparade: true, sparar: false, besiktningsfoeretag: new fb.ChangeTrack(fb.FasITDomain.AnticimexBesiktningsfoeretag.ANTICIMEX), produkt: new fb.ChangeTrack(null), fakturaTill: new fb.ChangeTrack(fb.FasITDomain.AnticimexFakturaTill.KUND), extraInformation: new fb.ChangeTrack(null), optionsBesiktningsfoeretag: [ { Id: fb.FasITDomain.AnticimexBesiktningsfoeretag.ANTICIMEX, Namn: "Anticimex" }, { Id: fb.FasITDomain.AnticimexBesiktningsfoeretag.OBM, Namn: "OBM" }, { Id: fb.FasITDomain.AnticimexBesiktningsfoeretag.ANNAT, Namn: "Annat" }, ], optionsProdukt: [ { Id: fb.FasITDomain.AnticimexProdukt.BESIKTNING_MED_DAALDA_FEL_FOERSAEKRING, Namn: "Besiktning med Dolda Fel-Försäkring", }, { Id: fb.FasITDomain.AnticimexProdukt.BESIKTNING_MED_DAALDA_FEL_FOERSAEKRING_UTOEKAD_BESIKTNING, Namn: "Besiktning med Dolda Fel-Försäkring - utökad besiktning", }, { Id: fb.FasITDomain.AnticimexProdukt.ENKEL_DAALDA_FEL_FOERSAKRING, Namn: "Enkel Dolda Fel-Försäkring", }, { Id: fb.FasITDomain.AnticimexProdukt.INGEN, Namn: "Ingen", }, ], optionsFakturaTill: [ { Id: fb.FasITDomain.AnticimexFakturaTill.KUND, Namn: "Säljare" }, { Id: fb.FasITDomain.AnticimexFakturaTill.MAEKLARE, Namn: "Mäklare" } ], save: function () { $scope.anticimex.foersaekring.sparar = true; if ($scope.maeklarObjekt.isDirty() || $scope.besiktning.isDirty()) { globalTimerService.globalSave(true).then(function () { $scope.anticimex.foersaekring.datumOchProtokollsnummerVaerdenSparade = true; $scope.anticimex.foersaekring.sparar = false; }); } else { //Redan autosparat $scope.anticimex.foersaekring.sparar = false; $scope.anticimex.foersaekring.datumOchProtokollsnummerVaerdenSparade = true } }, send: function () { if ($scope.maeklarObjekt.isDirty() || $scope.besiktning.isDirty()) { globalTimerService.globalSave(true).then(function () { $scope.anticimex.foersaekring.sendInternal(); }); } else { $scope.anticimex.foersaekring.sendInternal(); } }, sendInternal: function () { var obj: fb.IAnticimexFoersaekringsBestaellning = { MaeklarObjektId: $scope.maeklarObjekt.MaeklarObjektId.value, Besiktningsfoeretag: $scope.besiktning.BesiktningsFoeretag.value, Produkt: $scope.besiktning.FoersaekringsProduktId.value, FakturaTill: $scope.besiktning.FakturaTill.value, ExtraInformation: $scope.anticimex.foersaekring.extraInformation.value }; maeklarObjektBesiktningService.save($scope.besiktning).$promise.then(() => { $scope.anticimex.foersaekring.bestaellningPromise = anticimexService.bestaellFoersaekring(obj); $scope.anticimex.foersaekring.status = 1; $scope.anticimex.foersaekring.bestaellningPromise.$promise.then(function () { $scope.anticimex.foersaekring.status = 2; $timeout(function () { $scope.anticimex.foersaekring.status = 0; $scope.anticimex.foersaekring.bestaellningPromise = null; $scope.anticimex.foersaekring.showPopover = false; }, 1500); maeklarObjektBesiktningService.get($scope.maeklarObjektId).$promise.then((b) => { $scope.besiktning.BestaellningsDatum.setValue(b.BestaellningsDatum); }); }); $scope.anticimex.foersaekring.bestaellningPromise.$promise.catch(function () { $scope.anticimex.foersaekring.status = 3; $timeout(function () { $scope.anticimex.foersaekring.status = 0; $scope.anticimex.foersaekring.bestaellningPromise = null; }, 2000); }); }); }, sendButtonOptions: { disabled: false }, reset: function () { if (!$scope.besiktning.OeverlaatelseFoersaekrad.value) { $scope.besiktning.BesiktningsFoeretag.value = fb.FasITDomain.AnticimexBesiktningsfoeretag.ANTICIMEX; $scope.besiktning.FoersaekringsProduktId.value = null; $scope.besiktning.FakturaTill.value = fb.FasITDomain.AnticimexFakturaTill.KUND; $scope.anticimex.foersaekring.extraInformation.value = null; } }, openPopover: function () { $scope.anticimex.foersaekring.showPopover = true; $scope.anticimex.foersaekring.datumOchProtokollsnummerVaerdenSparade = (!!$scope.besiktning.OeverlaatelseFoersaekradFoerbesiktningsDatum.value && !!$scope.besiktning.OeverlaatelseFoersaekradBesiktningsprotokollsnummer.value && !!$scope.maeklarObjekt.TilltraedelseDatum.value); // Blockerar stäng-funktionen i 500 ms så att inte öppningseventet även stänger popovern $scope.anticimex.foersaekring.preventClose = true; $timeout(function () { $scope.anticimex.foersaekring.preventClose = false; }, 500); }, preventClose: false, closePopover: function () { if ($scope.anticimex.foersaekring.preventClose) { return; } $scope.anticimex.foersaekring.showPopover = false; $scope.anticimex.foersaekring.reset(); } } }; var prisid = 0; $scope.foersaekringAendrad = function () { if (!$scope.besiktning.$resolved) { return; } //om produkt är odefinierad så sätt produkt till null. Om produkt är odefinierad eller Ingen, sätt även belopp till 0 och töm marknadsför //om produkt är 1 eller 2 marknadsför, om besiktningsföretag är Annat(3) -> sätt företag till Anticimex(1) switch ($scope.besiktning.FoersaekringsProduktId.value) { case 1: case 2: $scope.besiktning.OeverlaatelseFoersaekrad.value = true; if ($scope.besiktning.BesiktningsFoeretag.value === 3) { $scope.besiktning.BesiktningsFoeretag.value = 1; } $scope.byttProdukt = true; break; case 3: $scope.besiktning.OeverlaatelseFoersaekrad.value = false; $scope.byttProdukt = true; break; case 4: $scope.foersaekringBelopp.value = 0; if ($scope.gammalOchRedigeradEllerNy() && $scope.innanNyDoldaFel !== undefined) { $scope.besiktning.OeverlaatelseFoersaekrad.value = false; } if ($scope.besiktning.BesiktningsFoeretag.value === 3) { $scope.besiktning.BesiktningsFoeretag.value = 1; } break; case null: $scope.besiktning.FoersaekringsProduktId.value = null; $scope.foersaekringBelopp.value = 0; if ($scope.gammalOchRedigeradEllerNy() && $scope.innanNyDoldaFel !== undefined) { $scope.besiktning.OeverlaatelseFoersaekrad.value = false; } if ($scope.besiktning.BesiktningsFoeretag.value === 3) { $scope.besiktning.BesiktningsFoeretag.value = 1; } break; default: break; } //om marknadsför som besiktigad och datum finns??? if ($scope.besiktning.OeverlaatelseFoersaekrad !== null && $scope.besiktning.OeverlaatelseFoersaekradFoerbesiktningsDatum !== null) { const idag = new Date(); idag.setHours(-idag.getTimezoneOffset() / 60, 0, 0, 0); const compDate = moment($scope.besiktning.OeverlaatelseFoersaekradFoerbesiktningsDatum.value || idag).startOf('day'); const prisObj = ($scope.foersaekringsPris.toArray() .filter(fp => fp.FoersaekringsProduktId === $scope.besiktning.FoersaekringsProduktId.value) .filter(fp => fp.StartDatum === null || moment(fp.StartDatum).diff(compDate, 'days') <= 0) .filter(fp => fp.SlutDatum === null || moment(fp.SlutDatum).diff(compDate, 'days') >= 0))[0]; $scope.foersaekringBelopp.value = prisObj ? prisObj.Pris : null; } }; //När ett beställningsdatum finns är en beställning lagd $scope.bestaellningLagd = function () { return ($scope.besiktning.BestaellningsDatum && $scope.besiktning.BestaellningsDatum.value !== null); } $scope.gammalOchRedigeradEllerNy = function () { return (($scope.byttProdukt && $scope.innanNyDoldaFel) || !$scope.innanNyDoldaFel); } $scope.openLantmaeteriutdragSideDrawer = function () { sideDrawerService.setSideDrawer('Lantmaeteriutdrag', { maeklarObjekt: $scope.maeklarObjekt, // Scrolla till dokument och öppna Uppladdade dokument när beställningen är slurförd callback: () => { const anchor = { id: 'dokumentData', name: 'Dokument', active: false, fullViewCondition: { fullViews: $scope.fullViews, name: 'fullViewConditionDokument' } }; const hasFullViewCondition = anchor.fullViewCondition && anchor.fullViewCondition.fullViews && anchor.fullViewCondition.name; const isCollapsed = hasFullViewCondition && !anchor.fullViewCondition.fullViews[anchor.fullViewCondition.name]; if (isCollapsed) { $timeout(function () { anchor.fullViewCondition.fullViews[anchor.fullViewCondition.name] = true; }); setTimeout(() => angular.element('li[heading="Uppladdade dokument"]').triggerHandler('click'), 500); } else { const offset = angular.element('#dokumentData').offset().top - angular.element('#maeklarObjektOuterWrapper').offset().top; const scrollTo = angular.element('#maeklarObjektOuterWrapper').scrollTop() + offset; const hasFullViewCondition = anchor.fullViewCondition && anchor.fullViewCondition.fullViews && anchor.fullViewCondition.name; angular.element('#maeklarObjektOuterWrapper').animate({ scrollTop: scrollTo }, 400, 'swing', function () { $("body").animate({ scrollTop: $('#dokumentData').offset().top }, 400, 'swing', () => angular.element('li[heading="Uppladdade dokument"]').triggerHandler('click')); }); } } }, '600px'); }; $scope.bestaellSpinner = false; $scope.redoAttBestaella = true; var callBestaellning = function () { }; var resetEfterBestaellning = function () { // Trigga beställningsanropet när objektet är sparat och återställ sedan till utgångsläge $scope.bestaellSpinner = false; $scope.redoAttBestaella = true; var clickEvent: MouseEvent = new (MouseEvent)('click', { 'view': window, 'bubbles': true, 'cancelable': true }); _.defer(function () { document.dispatchEvent(clickEvent); }); // För att stänga dropdownen efter att allt sparats callBestaellning(); callBestaellning = function () { }; } $scope.sparaInnanBestaell = function () { if ($scope.redoAttBestaella && $scope.maeklarObjekt.$dirty) { // Om mäklarobjektet har förändrats, tvinga det att sparas innan någon form av beställning från Beställ-dropdownen kan göras $scope.redoAttBestaella = false; var save = globalTimerService.saveItem($scope.maeklarObjekt.getGlobalUniqueId()); if (save !== null) { save.$promise.then(function () { resetEfterBestaellning(); }); } } }; $scope.onClickBestaellning = function (call: any, param: any = null) { // När ett val i Beställ-dropdownen görs redirectas anropet hit och sparas undan för att triggas ifall/när objektet är sparat if (!$scope.redoAttBestaella) { event.stopPropagation(); // Hindra dropdownen-från att stängas om den sparar $scope.bestaellSpinner = true; } if (typeof (call) === 'string') { callBestaellning = function () { window.open(call, param) }; } else if (typeof (call) === 'function') { if (!!param) { callBestaellning = function () { call(param); }; } else { callBestaellning = function () { call(); }; } } if ($scope.redoAttBestaella) { resetEfterBestaellning(); } }; $scope.laddaOmObjekt = function () { $scope.maeklarObjekt.enqueue(); globalTimerService.globalSave(true); }; $scope.tilltraedePasserat = function () { return moment($scope.maeklarObjekt.TilltraedelseDatum.value) < moment(); } $scope.$on(fb.FasITDomain.GlobalEvents.LANTMAETERIDATA_KOPIERAT, function () { $scope.maeklarObjekt = maeklarObjektService.get($routeParams.id); }); var paramId = $routeParams.id; $scope.$on('$destroy', function () { if (uiService.state['ObjektIProjekt']) { delete uiService.state['ObjektIProjekt']; } var drawer = sideDrawerService.getStateObject(); sideDrawerService.clearDrawer(); var state = { drawer: drawer, fullViews: _.clone($scope.fullViews) }; stateService.setState('MaeklarObjektCtrl', paramId, state); stateService.offLoadState('MaeklarObjektCtrl', paramId); }); $scope.$watch('maeklarObjekt.AerNyproduktion.value', function (newVal, oldVal) { if ($scope.maeklarObjekt && $scope.maeklarObjekt.$resolved && typeof newVal !== 'undefined' && !newVal) { $scope.maeklarObjekt.setValue($scope.maeklarObjekt.Saeljstartsdag, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.Bokningsavtalsdag, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.Foerhandsavtalsdag, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.MaeklarObjektNyproduktion.Husnummer, null); $scope.maeklarObjekt.setValue($scope.maeklarObjekt.MaeklarObjektNyproduktion.VisaBaadeSomNyProduktionOchBostaederTillSaluPaaHemnet, null); if ($scope.maeklarObjekt.isUtland) { $scope.maeklarObjekt.PaaGaang.setValue(false); } } if ($scope.maeklarObjekt.isProjekt() && oldVal !== undefined && newVal !== oldVal) { $scope.checkIfProjektThenChangeObjektIProjekt(); } }); $scope.$watch('maeklarObjekt.TilltraedelseDatum.value', function () { if ($scope.maeklarObjekt && $scope.maeklarObjekt.$resolved && !$scope.maeklarObjekt.TilltraedelseDatum.value) { $scope.maeklarObjekt.TilltraedelseTid.setValue(null); } }); $scope.$watch('maeklarObjekt.DatumForIntagsforsok.value', function () { if ($scope.maeklarObjekt && $scope.maeklarObjekt.$resolved && !$scope.maeklarObjekt.DatumForIntagsforsok.value) { $scope.maeklarObjekt.TidFoerIntagsfoersoek.setValue(null); } }); $scope.$watch('maeklarObjekt.Avtalsdag.value', function () { if ($scope.maeklarObjekt && $scope.maeklarObjekt.$resolved && $scope.maeklarObjekt.Avtalsdag) { var datePart = commonService.date.datePart($scope.maeklarObjekt.Avtalsdag.value || '') || ''; if (datePart === '') { $scope.maeklarObjekt.Avtalsdag.setValue(null); } } }); $scope.$watch('maeklarObjekt.FotograferingDatum.value', function () { if ($scope.maeklarObjekt && $scope.maeklarObjekt.$resolved && $scope.maeklarObjekt.FotograferingDatum) { var datePart = commonService.date.datePart($scope.maeklarObjekt.FotograferingDatum.value || '') || ''; if (datePart === '') { $scope.maeklarObjekt.FotograferingDatum.setValue(null); } } }); $scope.$watch('maeklarObjekt.Uppdragsdag.value', function (newVal, oldVal) { if ($scope.maeklarObjekt && $scope.maeklarObjekt.$resolved && $scope.maeklarObjekt.Uppdragsdag) { //Om uppdragsdag är SATT och vi är i uppdragstatus >= UPPDRAG så får vi inte sätta newval till if ($scope.maeklarObjekt.UppdragStatus.value >= $scope.maeklarObjekt.uppdragStatusDomain.UPPDRAG && newVal === null && $scope.maeklarObjekt.UppdragTyp.value === 'F') { $scope.maeklarObjekt.Uppdragsdag.required = true; $scope.maeklarObjekt.Uppdragsdag.requiredErrorMessage = $translate.instant('MAEKLAROBJEKT_BASFAKTA.UPPDRAGSDAG_KRAEVS_VID_UPPDRAG'); } else { $scope.maeklarObjekt.Uppdragsdag.required = false; } } }); $scope.$watch('maeklarObjekt.$dirty', function (newVal, oldVal) { if ($scope.maeklarObjekt && $scope.maeklarObjekt.$resolved) { if (!newVal && !$scope.redoAttBestaella) { resetEfterBestaellning(); } } }); $scope.$watch('besiktning.FoersaekringsProduktId.value', function (newVal, oldVal) { if (!$scope.anticimex.foersaekring.optionsBesiktningsfoeretag[2] && newVal === $scope.anticimex.foersaekring.optionsProdukt[2].Id) { { // Lägg till alternativet Annat om valet är tredje produktalternativet, dvs Enkel Dolda Fel-Försäkring $scope.anticimex.foersaekring.optionsBesiktningsfoeretag.push({ Id: fb.FasITDomain.AnticimexBesiktningsfoeretag.ANNAT, Namn: "Annat" }); } } else if ($scope.anticimex.foersaekring.optionsBesiktningsfoeretag[2]) { // Annars ta bort det om det finns $scope.anticimex.foersaekring.optionsBesiktningsfoeretag.splice(2, 1); } }); $scope.$watch('besiktning.FoersaekringsProduktId.value', $scope.foersaekringAendrad); function haemtaAntalOloestaKommentarer(): void { if (kanVisaAntalKommentarerBubblor()) { kommentarService.getOloestaKommentarer($routeParams.id) .$promise .then(data => raeknaAntalaOloestaKommentarer(data)); } else { $scope.visaOloestaKommentarerBubblor = false; } } function aerObjektAnnonserat(): boolean { if ($scope.maeklarObjekt && $scope.maeklarObjekt.$resolved) { return _.some( $scope.maeklarObjekt.ObjektAnnons, annons => !annons.AerVilande.value && !annons.AerHistorisk.value ); } return false; } function kanAktiveraKundportalen(): boolean { // Inaktivera knappen i dessa fall: if ( !$scope.maeklarObjekt || !$scope.maeklarObjekt.$resolved || $scope.maeklarObjekt.UppdragStatus.value < fb.FasITDomain.UppdragStatus.UPPDRAG || // Innan objektet har bytt status till Uppdrag $scope.maeklarObjekt.isUtland || // Är utland objekt $scope.maeklarObjekt.isProjekt() ||// Är projekt $scope.maeklarObjekt.isObjektIProjekt() || // Är objekt i projekt $scope.maeklarObjekt.isOevrig // Är övrig objekt ) { return false; } return true; } function kanVisaKundportalen(): boolean { // Kan inte visa knappen i dessa fall: if ( !$scope.maeklarObjekt || !$scope.maeklarObjekt.$resolved || $scope.maeklarObjekt.isUtland || // Är utland objekt $scope.maeklarObjekt.isProjekt() ||// Är projekt $scope.maeklarObjekt.isObjektIProjekt() || // Är objekt i projekt $scope.maeklarObjekt.isOevrig // Är övrig objekt ) { return false; } return true; } function openKundportalenSideDrawer(onCloseCB?) { sideDrawerService.setSideDrawer(fb.FasITDomain.SideDrawerName.KUNDPORTAL, { maeklarObjekt: $scope.maeklarObjekt }, '640px', onCloseCB); } function kanVisaAntalKommentarerBubblor(): boolean { return $scope.isKundportalAktiv && kanVisaKundportalen() && !aerObjektAnnonserat() && $scope.maeklarObjekt.UppdragStatus.value < fb.FasITDomain.UppdragStatus.SAALD; } function raeknaAntalaOloestaKommentarer(data: fb.Models_OloestKundportalKommentarLO[]): void { $scope.antalOloestaBildKommentarTraadar = 0; $scope.antalOloestaBostadsBeskrivningKommentarTraadar = 0; data.forEach(item => { if (item.MotivId) { $scope.antalOloestaBildKommentarTraadar++; } else { $scope.antalOloestaBostadsBeskrivningKommentarTraadar++; } }); if (kanVisaAntalKommentarerBubblor() && ($scope.antalOloestaBildKommentarTraadar > 0 || $scope.antalOloestaBostadsBeskrivningKommentarTraadar > 0)) { $scope.visaOloestaKommentarerBubblor = true; } else { $scope.visaOloestaKommentarerBubblor = false; } } } ]);