(function () { angular.module("agora.plus.process.services", []) .service("ProcessService", [ "$http", "$q", ProcessService ]); function ProcessService($http, $q) { var vm = this, promise; return { getWorkflowListByUserID2: function () { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "GetWorkflowNameListToUserId2") .then(function (response) { return response; }).catch(function(error) { console.error("Error fetching workflow name list: " + error); }); return promise; }, getWorkflowListByUserID: function (payload) { payload = (payload === undefined || payload === "undefined" || payload === null) ? { order: 'POSITION ASC', limit: 9999 * 9999, page: 1, filter: "%" } : payload; var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "GetWorkflowNameListToUserId", payload, { headers: { "Content-Type": "application/json" } } ).then(function (response) { return response.data.DATA; }).catch(function(error) { console.error("Error fetching email logs list: " + error); }); return promise; }, getIhmByStepId: function (stepId) { if (typeof stepId === "undefined" || stepId !== parseInt(stepId, 10)) { throw new Error("Invalid parameter stepId: " + stepId + " Step id must be an integer"); } var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "GetIhmToStepId" + "/", { params: { stepId: stepId } }) .then(function (response) { return response; }).catch(function(error) { console.error("Error fetching IHM data for current step: " + error); }); return promise; }, getAnctionAndNextStepToReplyProcess: function (stepId, workflowID) { if (typeof stepId === "undefined" || stepId !== parseInt(stepId, 10)) { throw new Error("Invalid parameter stepId: " + stepId + " Step id must be an integer"); } if (typeof workflowID === "undefined" || workflowID !== parseInt(workflowID, 10)) { throw new Error("Invalid parameter workflowID: " + workflowID + " Step id must be an integer"); } var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "GetAnctionAndNextStepToReplyProcess" + "/", { params: { stepId: stepId, workflowId: workflowID } }) .then(function (response) { return response; }).catch(function(error) { console.error("Error geting action and next step: " + error); }); return promise; }, valideProcessIsCheckOut: function (processId) { if (typeof processId === "undefined" || processId !== parseInt(processId, 10)) { throw new Error("Invalid parameter workflowID: " + processId + " Step id must be an integer"); } var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "ValideProcessIsCheckOut" + "/", { params: { idWfProcess: processId } }) .then(function (response) { return response; }).catch(function(error) { console.error("Error validating if process is checkout: " + error); }); return promise; }, valideProcessIsCheckOutByUser: function (processId) { if (typeof processId === "undefined" || processId !== parseInt(processId, 10)) { throw new Error("Invalid parameter workflowID: " + processId + " Step id must be an integer"); } var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "ValideProcessIsCheckOutByUser" + "/", { params: { idWfProcess: processId } }) .then(function (response) { return response; }).catch(function(error) { console.error("Error validating if process is checked out by user: " + error); }); return promise; }, checkOutCheckIn: function (processID, type) { if (typeof processID === "undefined" || processID !== parseInt(processID, 10)) { throw new Error("Invalid parameter processID: " + processID + " processID must be an integer"); } var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "SetProcessCheckInOut" + "/?idProcess=" + processID + "&operationType=" + type) .then(function (response) { return response; }).catch(function (error) { console.error("Error setting process checked out: " + error); }); return promise; }, save: function (dataJson) { var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "SetWorkflowProcess", dataJson, { "Content-Type": "application/json" }) .then(function (response) { return response; }) .catch(function(error) { console.error("Error setting workflow process: " + error); }); return promise; }, getUserProcessByType: function (type) { var userProcessType = { "todo": "", "done": "", "inprogress": "GetUserProcess" }, defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + userProcessType[type] + "/", { params: { option: type } }) .then(function (response) { if (parseInt(response.data.TYPE_RESULT, 10) > 0) { defer.resolve(response.data.DATA); } else { defer.reject(response.data.ERROR.MESSAGE); } }).catch(function(error) { defer.reject("Error occured fetching user process: " + error); }); return defer.promise; }, getIhmDataFromStepId: function (processStepId) { return $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "GetIhmData" + "/", { params: { processStepId: parseInt(processStepId, 10) } }) .then(function (response) { return response.data.DATA; }).catch(function(error) { console.error("Error fetching IHM data: " + error); }); }, checkUserProcessAccess: function (processstepid,stepid,workflowid,processid) { return $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "checkUserProcessAccess", { params: { processstepid: parseInt(processstepid), stepid: parseInt(stepid), workflowid: parseInt(workflowid), processid: parseInt(processid) } }) .catch(function (error) { console.error("Error" + error); }); }, getIhmsPreviousSteps: function (processStepId) { var promise = $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "GetIhmPrevStep" + "/?id_wf_process=" + processStepId) .then(function (response) { return response.data.DATA; }).catch(function(error) { console.error("Error fetching previous steps IHM data: " + error); }); return promise; }, editPreviewStep: function (data) { var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "EditPreviewStep", data, { "Content-Type": "application/json" }) .then(function (response) { return response; }) .catch(function(error) { console.error("Error editing previous step: " + error); }); return promise; }, controlPainelProcessListToTreat: function (data) { var promise = $http({ method: 'POST', url: PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "controlPainelProcessListToTreat", data: data, headers: { 'Content-Type': 'application/json' }}) .then(function (response) { return response.data; }) .catch(function(error) { console.error("Error editing previous step: " + error); }); return promise; }, controlPainelProcessListStatus: function (data, context) { var promise = $http({ method: 'POST', url: PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "controlPainelProcessListStatus?context=" +context, data: data, headers: { 'Content-Type': 'application/json' }}) .then(function (response) { return response.data; }) .catch(function(error) { console.error("Error editing previous step: " + error); }); return promise; }, sendEmail: function (data) { var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "sendEmail?idProcess="+ data.id + "&emailTo=" + data.email + "&emailSubject=" + data.subject, data.body, { "Content-Type": "application/json" }) .then(function (response) { return response; }) .catch(function(error) { console.error("Error editing previous step: " + error); }); return promise; }, saveDraft: function (dataJson) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "SetProcessIHMDraft", dataJson, { "Content-Type": "application/json" }) .then(function (response) { return response; }) .catch(function(error) { console.log(error); console.error("Error setting IHM draft" + error); }); return promise; }, getProcessDraft: function (idWorkflow, idStep, idProcess) { var promise = $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "GetIhmDataDraft" + "/?idWorkflow=" + idWorkflow + "&idStep=" + idStep + "&idProcess=" + idProcess) .then(function (response) { return response.data; }).catch(function(error) { console.error("Error getting IHM draft data: " + error); }); return promise; }, /*sendEmail: function (emailTemplate) { return $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "Email", emailTemplate ); },*/ getUploadFilesInfo: function (processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "File/?p_id_process=" + processId ) .catch(function(error) { console.error("Error uploading files: " + error); }); }, getPersonalInfo: function(processId) { return $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "InputIntegrationIhm9/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM 9: " + error); }); }, getSchoolInformationDependencies: function(processId) { return $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "InputIntegrationIhm14/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error in input integration for IHM 14: " + error); }); }, //Get the possible motives to chose other school getDerogationMotifs: function () { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "derogationMotifs/") .then(function (response) { return response; }).catch(function(error) { console.error("Error in derogation motifs: " + error); }); return promise; }, //Get the REFERENCE YEAR //TODO - check if its not deprecated getReferenceYear: function () { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "referenceYear/") .then(function (response) { return response; }).catch(function(error) { console.log("Error getting reference year: " + error); }); return promise; }, //Get family types for Link to Kids getfamilyTypeList: function () { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "familyTypeList/") .then(function (response) { return response; }).catch(function(error) { console.log("Error getting family type list: " + error); }); return promise; }, //Get Diet Regime getdietRegimeList: function () { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "getDietList/") .then(function (response) { return response; }).catch(function(error) { console.log("Error getting diet list: " + error); }); return promise; }, //Get Profile info for My Profile page getMyProfileInfo: function () { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "getMyProfileInfo/") .then(function (response) { return response; }).catch(function(error) { console.log("Error getting Profile Info: " + error); }); return promise; }, checkEmailToken: function(token) { var promise = $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "checkEmailToken/?token=" + token ).then(function (response) { return response; }).catch(function(error) { console.error("Error token send: " + error); }); return promise; }, sendEmailReset: function(email, lang) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "sendEmail/changePassword?email=" + email + "&lang=" + lang, {headers: {"Content-Type": "application/json"}} ).then(function (response) { return response; }).catch(function(error) { console.error("Error email send: " + error); }); return promise; }, changePassword: function(oldPassword, newPassword, token) { var dataJson = {}; dataJson = { "oldPassword": oldPassword, "newPassword": newPassword, "token": token } var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "changePassword", dataJson, {headers: {"Content-Type": "application/json"}} ).then(function (response) { return response; }).catch(function(error) { console.error("Error changing password: " + error); }); return promise; }, changeEmailApply: function(token) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "changeEmail/apply?token=" + token, {headers: {"Content-Type": "application/json"}} ).then(function (response) { return response; }).catch(function(error) { console.error("Error apply new email: " + error); }); return promise; }, changeEmailRevert: function(token) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "changeEmail/revert?token=" + token, {headers: {"Content-Type": "application/json"}} ).then(function (response) { return response; }).catch(function(error) { console.error("Error revert old email: " + error); }); return promise; }, changeEmail: function(oldEmail, newEmail, lang) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "sendEmail/changeEmail?oldEmail=" + oldEmail + "&newEmail=" + newEmail + "&lang=" + lang, {headers: {"Content-Type": "application/json"}} ).then(function (response) { return response; }).catch(function(error) { console.error("Error email change: " + error); }); return promise; }, saveProfile: function(profile) { var dataJson = {}; dataJson = JSON.stringify(profile); var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "profile", dataJson, {headers: {"Content-Type": "application/json"}} ).then(function (response) { return response; }).catch(function(error) { console.error("Error saving data: " + error); }); return promise; }, getinputIntegrationIhm29: function(processId, canDeleteContact) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm29/", { params: { idProcess: processId, canBeDeleted: canDeleteContact } }) .catch(function(error) { console.error("Error getting input integration for IHM29: " + error); }); }, getinputIntegrationIhm30: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm30/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM30: " + error); }); }, getinputIntegrationIhm32: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm32/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM32: " + error); }); }, getinputIntegrationIhm33: function (processId, refYear, hideOccupationMoreThan, activityList, tagList, typeTargetList) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm33/?idProcess=" + processId + "&refYear=" + refYear + "&hideOccupationMoreThan=" + hideOccupationMoreThan + "&activityList=" + activityList + "&tagList=" + tagList + "&idTypeTarget=" + typeTargetList ) .catch(function(error) { console.error("Error getting input integration for IHM33: " + error); }); }, getinputIntegrationIhm34: function (processId, refYear, filterDocument) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm34/?idProcess=" + processId + "&refYear=" + refYear + "&filterDocument=" + filterDocument, { /* params: { idProcess: processId, refYear: refYear, }*/ }) .catch(function(error) { console.error("Error getting input integration for IHM34: " + error); }); }, getinputIntegrationIhm35: function(zipCode,numAllocataire) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm35/", { params: { zipCode: zipCode, numAllocataire: numAllocataire } }) .catch(function(error) { console.error("Error getting input integration for IHM 35: " + error); }); }, getinputIntegrationIhm39: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm39/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM39: " + error); }); }, getinputIntegrationIhm41: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm41/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM41: " + error); }); }, getinputIntegrationIhm43: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm43/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM 43: " + error); }); }, getinputIntegrationIhm44: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm44/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM 44: " + error); }); }, getinputIntegrationIhm52: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm52/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM 52: " + error.status); }); }, getinputIntegrationIhm45: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm45/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM 45: " + error); }); }, getinputIntegrationIhm48: function(processId, startDate, tags, directDebit, typeTargetList) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm48/?directDebit=" + directDebit + "&idProcess=" + processId + "&startDate=" + startDate + "&tags=" + tags + "&idTypeTarget=" + typeTargetList, { }) .catch(function(error) { console.error("Error getting input integration for IHM 48: " + error); }); }, getinputIntegrationIhm46: function(processId, context) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm46/", { params: { idProcess: processId, context: context } }) .catch(function(error) { console.error("Error getting input integration for IHM 46: " + error); }); }, getinputIntegrationIhm49: function(processId, childMaxDate) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm49/", { params: { idProcess: processId, childMaxDate: childMaxDate } }) .catch(function(error) { console.error("Error getting input integration for IHM 49: " + error); }); }, /** * getCurrentSysDate For the current context get the current * system date (date from the server) * @param {Integer} idContext Unique identifier of the current * context * @return {Object} A promise is returned */ getCurrentSysDate: function(idContext) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_CALENDAR_COMP + "date/?idContext=1" ) .catch(function(error) { console.error("Error current date"+error); }); }, getinputIntegrationIhm50: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm50/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM 50: " + error); }); }, getinputIntegrationIhm58: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm58/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM 58: " + error.status); }); }, getinputIntegrationIhm51: function(processId, refYear, childMindate, childMaxDate) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm51/", { params: { idProcess: processId, refYear: refYear, childMindate: childMindate, childMaxDate: childMaxDate } }) .catch(function(error) { console.error("Error getting input integration for IHM 51: " + error); }); }, getinputIntegrationIhm56: function(processId, miscellaneousFilter) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm56/", { params: { idProcess: processId, miscFilter: miscellaneousFilter } }) .catch(function(error) { console.error("Error getting input integration for IHM 56: " + error); }); }, getKidInformationDependencies: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "InputIntegrationIhm10/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting kid information dependencies: " + error); }); }, getSubventionLevel: function () { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "subventionLevel") .then(function (response) { return response; }) .catch(function(error) { console.error("Error getting subvention level: " + error); }); return promise; }, getfamilySituation: function () { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "familySituation") .then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error fetching family situation: " + error); }); return defer.promise; }, outputIntegrationEngine: function (processID) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "outputIntegrationEngine/?idProcess=" + processID ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, getDocumentsListGrid: function (payload) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "getDocumentsListGrid", payload, { headers: { "Content-Type": "application/json" } } ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, getAccountBalanceListGrid: function (payload, top, accountBalanceIsFamilyTarget) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "getAccountBalanceGrid?getTop=" + top + "&isFamilyTarget=" + accountBalanceIsFamilyTarget, payload, { headers: { "Content-Type": "application/json" } } ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, getActivitiesPrices: function (payload) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "activities-prices", payload, { headers: { "Content-Type": "application/json" } } ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, getAccountBalanceReport: function (sessionId, id) { if (id === null) id = ""; var promise = $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "/reports/frontoffice?solution=regie&path=balance_accompte&action=balance_accompte.xaction&data=p_id_compte_payeur=" + id + "%26p_token=" + sessionId ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, addCretitRegie: function (idRegie, montant, accountBalanceIsFamilyTarget) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "addCretitRegie?idRegie=" +idRegie + "&montant=" + montant + "&isFamilyTarget=" + accountBalanceIsFamilyTarget, { headers: { "Content-Type": "application/json" } } ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, getStatusPaymentAddCredit: function (id) { var promise = $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "getStatusPaymentAddCredit?idActionCompte=" + id ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, getRegies: function () { var promise = $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "getRegies" ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, /** * deleteDocument * @param id * @returns {angular.IPromise} */ deleteDocument: function (id) { var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "deleteDocument?idDocument=" + id ).then(function(response) { return response; }) .catch(function(error) { console.error("Error chanching post status: " + error); }); return promise; }, /** * deleteDocument * @param id * @returns {angular.IPromise} */ postUploadFile: function (payload) { var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "updateDocument?idDocument=" + payload.ID_REL_FILE +"&nameDocument=" + payload.UploadDocument.name +"&documentGUID=" + payload.UploadDocument.guid) .then(function(response) { return response; }) .catch(function(error) { console.error("Error chanching post status: " + error); }); return promise; }, /* //TF get message for income declaration acording the context getIncomeDeclarationMessage: function (context) { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "genericMessageIncomeDeclaration?context=" + context) .then(function (response) { return response; }).catch(function(error) { console.error("Error gettin generic message for income declaration: " + error); }); return promise; }, /* //TF get message for financial declaration type IHM getFinancialDlarationTypeMessage: function () { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "financialDeclarationTypeMessage") .then(function (response) { return response; }).catch(function(error) { console.error("Error getting financial declaration type message: " + error); }); return promise; },*/ //TF GET INCOME DECLARATION MESSAGE CONTEXT getIncomeDeclarationContext: function(processId) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm22/", { params: { idProcess: processId } }) .catch(function(error) { console.error("Error getting input integration for IHM 22: " + error); }); }, //TF GET INCOME DECLARATION INFORMATION getIncomeInformation: function (idDeclaration) { return $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_USER_CONFIG + "IcomeDeclaration/" + idDeclaration) .catch(function(error) { console.error("Error getting income declaration: " + error); }); }, getAutomaticIncomeDeclaration: function (taxNumber, reference, refYear) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "automaticIncomeDeclaration/?taxNumber=" + taxNumber + "&reference=" + reference + "&refYear=" + refYear) .then(function(response) { defer.resolve(response); }) .catch(function(error) { defer.reject("Error getting automatic income declaration: " + error); }); return defer.promise; }, createMandat: function (iban, bic, prevStartDate) { var defer = $q.defer(); $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_USER_CONFIG + "sepaRequest/", { params: { iban: iban, bic: bic, prevStartDate: prevStartDate } } ) .then(function (response) { defer.resolve(response); }) .catch(function (error) { defer.reject("Error getting automatic income declaration: " + error); }); return defer.promise; }, //CREATE A NEW RIB AND MANDAT FOR THE FAMILY createMandat: function (iban, bic, regie, activityList, prevStartDate, refYear) { var defer = $q.defer(); $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_USER_CONFIG + "sepaRequest/?iban=" + iban + "&bic=" + bic + "®ie=" + regie + "&prevStartDate=" + prevStartDate + "&refYear=" + refYear.join(','), activityList, { headers: { "Content-Type": "application/json" } } ).then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error creating mandat: " + error); }); return defer.promise; }, getNumber: function(number) { if (!Number.isInteger(number)) { number = 0; } return new Array(number); }, getVRS: function (ref_year) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm28/?ref_year=" + ref_year) .then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error occured while fetching vrs list: " + error); }); return defer.promise; }, getIHM27Integration: function (processId, refYear) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "InputIntegrationIhm27/", { params: { idProcess: processId, refYear: refYear.join(',') } }).then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting input integration for IHM27: " + error); }); return defer.promise; }, getIHM27IntegrationIBAN: function () { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm27IBAN/") .then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting input integration for IHM27-IBAN: " + error); }); return defer.promise; }, getIHM31Integration: function (processId) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm31/", { params: { idProcess: processId } }) .then(function (response) { defer.resolve(response); }) .catch(function(error) { defer.reject("Error getting input integration for IHM 31: " + error); }); return defer.promise; }, getIHM33Integration: function (processId) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm34/", { params: { idProcess: processId } }) .then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting input integration for IHM 34: " + error); }); return defer.promise; }, /** * getIHM25Integration Get IHM25 data integration * @param {Integer} processId Id of the process being executed * @return {Object} A promise should be returned */ getIHM25Integration: function (processId) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm25/", { params: { idProcess: processId } }).then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting IHM 25 input integration data: " + error); }); return defer.promise; }, /** * getIHM36Integration Get IHM36 data integration * @param {Integer} processId Id of the process being executed * @return {Object} A promise should be returned */ getIHM36Integration: function (processId) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm36/", { params: { idProcess: processId } }).then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting IHM 36 input integration data: " + error); }); return defer.promise; }, /** * getIHM37Integration Get IHM37 data integration * @param {Integer} processId Id of the process being executed * @return {Object} A promise should be returned */ getIHM37Integration: function (processId) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm37/", { params: { idProcess: processId } }).then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting IHM 37 input integration data: " + error); }); return defer.promise; }, /** * getIHM40Integration Get IHM40 data integration * @param {Integer} processId Id of the process being executed * @return {Object} A promise should be returned */ getIHM40Integration: function (processId) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm40/", { params: { idProcess: processId } }).then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting IHM 40 input integration data: " + error); }); return defer.promise; }, /** * getNotificationTexts * @param {Integer} idStep Id of the current step * @param {Integer} idAction Id of the action performed * @return {Object} A promise should be returned */ getNotificationTexts: function (idStep, idAction) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "getStepNotificationTexts/", { params: { idStep: idStep, idAction: idAction } }).then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting step notifications: " + error); }); return defer.promise; }, /** * getIHM42Integration Get IHM42 data integration * @param {Integer} processId Id of the process being executed * @return {Object} A promise should be returned */ getIHM42Integration: function (processId) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm42/", { params: { idProcess: processId } }).then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting IHM 42 input integration data: " + error); }); return defer.promise; }, getIHM47Integration: function (tagList, refYear) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm47/?tags=" + tagList.join(',') + "&refYear=" + refYear.join(',')) .then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting IHM 47 input integration data: " + error); }); return defer.promise; }, getIHM53Integration: function(idProcess) { var defer = $q.defer(); $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "inputIntegrationIhm53/?idProcess=" + idProcess) .then(function (response) { defer.resolve(response); }).catch(function(error) { defer.reject("Error getting IHM 53 input integration data: " + error); }); return defer.promise; }, getHomeCoordinates: function (address) { var promise = $http.get("https://api-adresse.data.gouv.fr/search/?q=" + address + "&limit=1", {headers: { 'Pragma': undefined, 'ref_year': undefined, 'session_id': undefined, 'Cache-Control': undefined, 'jndi': undefined } }) .then(function (response) { return response.data.features[0].geometry.coordinates; }).catch(function(error) { console.error("Error fetching responsibles house coordinate: " + error); }); return promise; }, getLocationByIP: function (ip) { var promise = $http.get("http://api.ipapi.com/check?access_key=e0a4b081a3a5c39981ef6162590f0fc5", {headers: { 'Pragma': undefined, 'ref_year': undefined, 'session_id': undefined, 'Cache-Control': undefined, 'jndi': undefined } }) .then(function (response) { return response.data; }).catch(function(error) { console.error("Error fetching Location: " + error); }); return promise; }, getAddressByCoordinates: function (longitude,latitude) { var promise = $http.get("http://nominatim.openstreetmap.org/reverse?format=json&lon=" + longitude + "&lat=" + latitude, {headers: { 'Pragma': undefined, 'ref_year': undefined, 'session_id': undefined, 'Cache-Control': undefined, 'jndi': undefined } }) .then(function (response) { return response.data.address; }).catch(function(error) { console.error("Error fetching responsibles house coordinate: " + error); }); return promise; }, validateMailExist: function (email) { var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + "validateMailExist?mail=" + email) .then(function (response) { return response.data.DATA; }).catch(function(error) { console.error("Error checking validate mail exist: " + error); }); return promise; }, getProcessStatus: function (getTopValue) { var getTop = (getTopValue === 1) ? 1 : 0; var promise = $http.get(PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW + "processCloseCancelList?getTop=" + getTop) .then(function (response) { return response.data.DATA; }).catch(function(error) { console.error("Error fetching workflow process list: " + error); }); return promise; }, getRamInfoGrid: function (payload) { var promise = $http.post( PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "getRamInfoGrid", payload, { headers: { "Content-Type": "application/json" } } ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, getNannyAddress: function () { var promise = $http.get( PCK_GLOBAL_VARIABLES.webservice_path_API_BACKOFFICE_CONFIG+ "nannyAddressList", { headers: { "Content-Type": "application/json" } } ).then(function (response) { return response; }).catch(function(error) { console.error("Output integration error: " + error); }); return promise; }, getEmailLogs: function (isFront, idAccount, payload) { var url = (isFront === true) ? "emailLogs/0/1" : "emailLogs/" +idAccount + "/2"; var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD + url, payload, { headers: { "Content-Type": "application/json" } } ).then(function (response) { return response.data.DATA; }).catch(function(error) { console.error("Error fetching email logs list: " + error); }); return promise; }, changeStatusOfNotifRead: function (payload) { var promise = $http.post(PCK_GLOBAL_VARIABLES.webservice_path_API_DASHBOARD+ "changeStatusOfNotifRead", payload, {headers: {"Content-Type": "application/json"}} ).then(function(response) { return response; }) .catch(function(error) { console.error("Error chanching post status: " + error); }); return promise; }, /** * Get original data of IHMs given a specific process ID * @param {Number} processId */ getIhmOriginalData: function(processId) { var defer = $q.defer(); if (processId !== +processId || processId < 0) { defer.reject("Invalid process step id"); return defer.promise; } $http.get([PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW, "getIhmOriginalData?idProcess=", processId].join("")) .then(function(response) { var typeResult = response.data.TYPE_RESULT; if (typeResult <= 0) { defer.resolve([]); } else { defer.resolve(response.data.DATA); } }) .catch(function(error) { defer.reject("Error fecthing IHM original data"); }); return defer.promise; }, compareJson: function(name, jsonObject1, jsonObject2) { var result = []; if(!(jsonObject1 && jsonObject2)){ result.push("root|'" + jsonObject1 + "'|'" + jsonObject2 + "'"); return result; } var keys = Object.keys(jsonObject1); // BEGIN: RV NAIL keys = keys.concat(Object.keys(jsonObject2)); keys = keys.filter(onlyUnique); // END: RV NAIL for (var i = 0; i < keys.length; i++) { var key = keys[i]; var nameAux = name + "#" + key; if(typeof(jsonObject1[key]) !== "object" && !Array.isArray(jsonObject1[key])){ if (jsonObject1[key] != jsonObject2[key]) { result.push(nameAux + "|" + jsonObject1[key] + "|" + jsonObject2[key]); } } else if(typeof(jsonObject1[key]) === "object" && !Array.isArray(jsonObject1[key])){ if (jsonObject1[key] && jsonObject2[key]) result = result.concat(this.compareJson(nameAux, jsonObject1[key], jsonObject2[key])); else if((jsonObject1[key] && !jsonObject2[key])||(!jsonObject1[key] && jsonObject2[key])) result.push(nameAux + "|" + jsonObject1[key] + "|" + jsonObject2[key]); else result = result; } else if(Array.isArray(jsonObject1[key])) { if (jsonObject1[key] && jsonObject2[key]){ if (jsonObject1[key].length !== jsonObject2[key].length){ result.push(nameAux + "|" + jsonObject1[key] + "|" + jsonObject2[key]); } else { for (var j = 0; j < jsonObject1[key].length; j++) { result = result.concat(this.compareJson(nameAux, jsonObject1[key][j], jsonObject2[key][j])); } } } else if((jsonObject1[key] && !jsonObject2[key])||(!jsonObject1[key] && jsonObject2[key])){ result.push(nameAux + "|" + jsonObject1[key] + "|" + jsonObject2[key]); } else result = result; } } // BEGIN: RV NAIL function onlyUnique(value, index, self) { return self.indexOf(value) === index; } // END: RV NAIL return result; }, getRequiredDocumentsList: getRequiredDocumentsList }; function getRequiredDocumentsList(ihmList,idWorkflow,processId) { var defer = $q.defer(); var CHILD_INFO = []; if (processId) { $http.get([PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW,"InputIntegrationIhm16/?idProcess=",processId].join("")) .then(function (res) { if (res.data.TYPE_RESULT == "1") { ihmList = res.data.DATA.IHM_16.IHM_LIST.concat(ihmList); CHILD_INFO = res.data.DATA.IHM_16.CHILD_INFO; } else { defer.reject(res.data.ERROR.MESSAGE); } }) .catch(function(error) { defer.reject("Error getting input integration for IHM 16: " + error); }) .finally(function() { $http.get([PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW,"documents/?idIHM=",arrayToCSVString(ihmList),"&idWorkflow=",idWorkflow].join("")) .then(function (res) { if (res.data.TYPE_RESULT == "1") { defer.resolve({ documents: res.data.DATA.DOCUMENTS_INFO, CHILD_INFO: CHILD_INFO }); } else { defer.reject(res.data.ERROR.MESSAGE); } }) .catch(function(error) { defer.reject("Error getting documents: " + error); }); }); } else { $http.get([PCK_GLOBAL_VARIABLES.webservice_path_API_WORKFLOW,"documents/?idIHM=",arrayToCSVString(ihmList),"&idWorkflow=",idWorkflow].join("")) .then(function (res) { if (res.data.TYPE_RESULT == "1") { defer.resolve({ documents: res.data.DATA.DOCUMENTS_INFO, }); } else { defer.reject({ documents: res.data.DATA.DOCUMENTS_INFO, CHILD_INFO: CHILD_INFO }); } }) .catch(function(error) { defer.reject("Error getting documents: " + error); }); } return defer.promise; function arrayToCSVString(arr) { var str = ""; for (var i = 0; i < arr.length; i++) { str += arr[i]; str += ","; } str = str.replace(/,$/,""); return str; } }; } }).call();