Initial commit

This commit is contained in:
Senad Uka
2018-06-11 11:09:35 +02:00
commit ed7df7b11f
1954 changed files with 483354 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
(function () {
global.dashModule
.controller('assignBrokerCtrl', ['$scope', '$http', '$', '$translate', 'utilsService', assignBrokerCtrl])
.directive('assignBroker', [assignBrokerDirective]);
function assignBrokerDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/assignBrokerTemplate'
};
}
function assignBrokerCtrl($scope, $http, $, $translate, utilsService) {
$scope.assignBroker = assignToBroker;
$scope.removeAssign = removeAssign;
$scope.selectedBroker = '';
function getIdBroker(brokerName) {
const foundBroker = $scope.brokers.find(broker => {
return broker.brokerName === brokerName;
});
return foundBroker && foundBroker.idBroker ? foundBroker.idBroker : 0;
}
function assignToBroker() {
const idBroker = getIdBroker($scope.selectedBroker);
if (idBroker === 0) {
const translatedMessage = $translate.instant('orders.messages.INVALID_BROKER');
utilsService.displayMessage('error', translatedMessage);
$scope.selectedBroker = '';
} else {
const params = $.param({
idOrder: $scope.idOrder,
idBroker
});
$http({
method: 'POST',
url: 'orders/api/assignBroker',
data: params
}).then(showAssignMessage, utilsService.onHttpError);
}
}
function removeAssign() {
$('#assign-broker-' + $scope.idOrder).remove();
}
function showAssignMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
removeAssign();
if(typeof $scope.onUpdate !== 'undefined'){
$scope.onUpdate();
}
});
}
}
}
})();

View File

@@ -0,0 +1,555 @@
(function () {
global.dashModule
.controller('changeOrdersStepsCtrl', ['$scope', '$rootScope', '$http', '$', '$translate', '$compile', '$sce', 'utilsService', 'ordersUtilsService', 'ORDER_STATUSES_ICONS', 'ORDER_STATUSES', changeOrdersStepsCtrl])
.directive('changeOrdersSteps', [changeOrdersStepsDirective]);
function changeOrdersStepsDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/changeOrdersStepsTemplate'
};
}
function changeOrdersStepsCtrl($scope, $rootScope, $http, $, $translate, $compile, $sce, utilsService, ordersUtilsService, ORDER_STATUSES_ICONS, ORDER_STATUSES) {
const expandedProces = [];
let currentStepStatus = '';
let firstInactivePosition = 0;
let ordersDetailsMail = [];
$scope.startOrdersStepsModule = startOrdersStepsModule;
$scope.getStatusClass = getStatusClass;
$scope.isNextButtonVisible = isNextButtonVisible;
$scope.toggleInfo = toggleInfo;
$scope.isEstimationDisabled = isEstimationDisabled;
$scope.isStepVisible = isStepVisible;
$scope.hasMoreSteps = hasMoreSteps;
$scope.showAllSteps = showAllSteps;
$scope.isExpanded = isExpanded;
$scope.isExpandedAndFirstStepInactive = isExpandedAndFirstStepInactive;
$scope.goToNextStep = goToNextStep;
$scope.undoStep = undoStep;
$scope.getOrderStatusIcon = getOrderStatusIcon;
$scope.updatePackageEndOfLife = updatePackageEndOfLife;
$scope.updateOrderEstimation = updateOrderEstimation;
$scope.updateStepActualDate = updateStepActualDate;
$scope.cancelOrder = cancelOrder;
$scope.isCancelDialogVisible = false;
$scope.isProcessDialogVisible = false;
$scope.isNextDialogVisible = {};
$scope.isUndoDialogVisible = {};
$scope.showHideCancelDialog = showHideCancelDialog;
$scope.showHideProcessDialog = showHideProcessDialog;
$scope.showHideNextDialog = showHideNextDialog;
$scope.isOrderOngoing = isOrderOngoing;
$scope.setProcessForOrder = setProcessForOrder;
$scope.hasNoSelectedProcess = hasNoSelectedProcess;
$scope.updateStepCommentVisibility = updateStepCommentVisibility;
$scope.isCommentVisible = isCommentVisible;
$scope.stepVisibleForCustomer = stepVisibleForCustomer;
$scope.setNewCommentVisibility = setNewCommentVisibility;
$scope.canAddComment = canAddComment;
$scope.hasAgreement = hasAgreement;
$scope.formatStepText = formatStepText;
$scope.isMyOrder = isMyOrder;
$scope.hasExtraAction = ordersUtilsService.hasExtraAction;
$scope.extraActionDirective = extraActionDirective;
$scope.enableAssignBrokerEdit = enableAssignBrokerEdit;
$scope.calculatePrice = ordersUtilsService.calculatePrice;
$scope.processSteps = [];
$scope.availableProcesses = [];
$scope.ordersInfo = {};
$scope.selections = [];
$scope.brokers = [];
$scope.selectedProcess = {};
$scope.orderComments = [];
$scope.orderOptions = [];
$scope.isNextBtnDisabled = isNextBtnDisabled;
$scope.getIconStepStatus = getIconStepStatus;
$scope.getDisplayDescriptionClass = getDisplayDescriptionClass;
$scope.isExtraActionOpen = {};
$scope.updateStepComment = updateStepComment;
$scope.updateOrderComment = updateOrderComment;
$scope.isSupportMailBtnVisible = false;
$scope.showHideSupportDialog = showHideSupportDialog;
$scope.sendSupportMail = sendSupportMail;
$scope.allowedLanguages = '';
$scope.allowedLanguagesDescription = '';
$scope.renderHtml = renderHtml;
$scope.getStatusText = getStatusText;
$scope.supportBtnNames = {
confirmation: $translate.instant('orders.buttons.SEND'),
cancel: $translate.instant('orders.buttons.CANCEL')
};
$scope.tinymceOptions = utilsService.getTynimceOptions({
height: '150px'
});
function getStatusText(status){
return ORDER_STATUSES[status] || status;
}
function renderHtml(htmlCode) {
return $sce.trustAsHtml(htmlCode);
}
function startOrdersStepsModule() {
ordersUtilsService.registerOrderFunction('showOrderInfo', showOrderInfo);
getSystemAllowedLanguages();
getOrderInfo();
getOrderSteps();
utilsService.registerFunction('isNextBtnDisabled', isNextBtnDisabled);
}
function isMyOrder(ordersInfo) {
return Object.keys(ordersInfo).length !== 0;
}
function getOrderInfo() {
ordersUtilsService.getOrderInfo();
}
function showOrderInfo(response) {
if (typeof response.data.info !== 'undefined' &&
typeof response.data.availableProcesses !== 'undefined' &&
typeof response.data.packages !== 'undefined' &&
typeof response.data.products !== 'undefined') {
$scope.ordersInfo = response.data.info[0];
$scope.packages = response.data.packages;
$scope.products = response.data.products;
$scope.orderComments = response.data.orderComments;
$scope.orderOptions = response.data.orderOptions;
$scope.additionalPackages = response.data.additionalPackages;
$scope.selections = response.data.selections;
$scope.availableProcesses = response.data.availableProcesses;
$scope.orderDocuments = response.data.orderDocuments;
ordersDetailsMail = {
idOrder: $scope.ordersInfo.id,
orderNumber: $scope.ordersInfo.orderNumber,
customer: $scope.ordersInfo.customer,
commercialLead: $scope.ordersInfo.commercialLead
};
getAvailabilityForSendSupportMail();
}
}
function getOrderSteps() {
const idOrder = global.getParameterByName('idOrder') || 0;
const params = $.param({
idOrder
});
$http({
method: 'POST',
url: 'orders/api/getOrderSteps',
data: params
}).then(showOrderSteps, utilsService.onHttpError);
}
function showOrderSteps(response) {
const idOrder = global.getParameterByName('idOrder') || 0;
if (typeof response.data === 'object') {
$scope.processSteps = response.data;
$.each($scope.processSteps, (processKey) => {
$scope.isExtraActionOpen[idOrder + '-' + processKey] = false;
});
}
}
function hasAgreement(packagePayPeriod, servicesContractPeriod) {
return parseInt(packagePayPeriod) > 0 || parseInt(servicesContractPeriod) > 0;
}
function enableAssignBrokerEdit() {
$('#enalbe-assign-edit').off('click');
$('#enalbe-assign-edit').on('click', function () {
const assignSelector = $(this).parent().find('.assign-broker');
if (assignSelector.length) {
assignSelector.remove();
} else {
const parent = $(this).parent();
const idOrder = parent.attr('id-order');
const directiveHtml = '<assign-broker id="assign-broker-' + idOrder + '" class="assign-broker" ng-controller="assignBrokerCtrl"></assign-broker>';
const scope = $rootScope.$new();
scope.idOrder = idOrder;
scope.onUpdate = getOrderInfo;
if ($scope.brokers.length > 0) {
scope.brokers = $scope.brokers;
const comp = $compile($(directiveHtml))(scope);
parent.append(comp);
} else {
$http({
method: 'POST',
url: 'orders/api/getBrokers'
}).then((response) => {
$scope.brokers = response.data;
scope.brokers = $scope.brokers;
const comp = $compile($(directiveHtml))(scope);
parent.append(comp);
}, utilsService.onHttpError);
}
}
});
}
function isCommentVisible(isVisible, isStepVisible) {
if (isStepVisible === '1') {
return isVisible === '1' ? 'glyphicon-eye-open' : 'glyphicon-eye-close';
}
return '';
}
function stepVisibleForCustomer(stepVisibleForCustomer) {
return stepVisibleForCustomer === '1' ? 'glyphicon-eye-open' : 'glyphicon-eye-close';
}
function isNextButtonVisible(stepStatus) {
return stepStatus === 'in-progress';
}
function getStatusClass(status) {
const statusClasses = {
'in-progress': 'step-in-progress',
'done': 'step-done'
};
currentStepStatus = status;
return statusClasses[status] || 'step-in-future';
}
function toggleInfo($event) {
$($event.target)
.parent()
.parent()
.find('.order-toggle-info')
.toggle('slow');
if ($($event.target).hasClass('glyphicon-plus-sign')) {
$($event.target).removeClass('glyphicon-plus-sign');
$($event.target).addClass('glyphicon-minus-sign');
} else {
$($event.target).removeClass('glyphicon-minus-sign');
$($event.target).addClass('glyphicon-plus-sign');
}
}
function isEstimationDisabled(status) {
return status === 'inactive' || status === 'done';
}
function isStepVisible(position, steps, proc) {
const currentStep = steps[position];
const nextStep = steps[position + 1] || {};
const prevStep = steps[position - 1] || {};
return (expandedProces.indexOf(proc.idProcess) >= 0) || !(nextStep.status === 'done' || (currentStep.status === 'inactive' && prevStep.status === 'inactive'));
}
function hasMoreSteps(position, steps, proc, location) {
const currentStepVisible = isStepVisible(position, steps, proc);
const prevStepVisible = steps[position - 1] ? isStepVisible(position - 1, steps, proc) : true;
const nextStepVisible = steps[position + 1] ? isStepVisible(position + 1, steps, proc) : true;
return (location === 'start' && currentStepVisible && !prevStepVisible) ||
(location === 'end' && currentStepVisible && !nextStepVisible);
}
function showAllSteps(proc) {
const elementIndex = expandedProces.indexOf(proc.idProcess);
if (elementIndex < 0) {
expandedProces.push(proc.idProcess);
} else {
expandedProces.splice(elementIndex);
}
}
function isExpanded(proc) {
return expandedProces.indexOf(proc.idProcess) >= 0;
}
function isExpandedAndFirstStepInactive(processStep, step, stepPosition) {
if (expandedProces.indexOf(processStep.idProcess) >= 0) {
if (step.status === 'in-progress') {
firstInactivePosition = stepPosition + 1;
}
return firstInactivePosition && firstInactivePosition === stepPosition ? true : false;
}
return false;
}
function goToNextStep(fctParams) {
const idNextBtn = fctParams.idOrder + '-' + fctParams.idProcess;
ordersDetailsMail = Object.assign(ordersDetailsMail, {
idProcess: fctParams.idProcess
});
if (!$scope.isExtraActionOpen[idNextBtn]) {
const params = $.param({
idOrder: fctParams.idOrder,
idProcessStep: fctParams.idProcessStep,
ordersDetailsMail: JSON.stringify(ordersDetailsMail)
});
$http({
method: 'POST',
url: 'orders/api/goToNextStep',
data: params
}).then((response) => {
showStepUpdateMessage(response, fctParams.idOrder);
}, utilsService.onHttpError);
}
}
function undoStep(fctParams) {
const params = $.param({
idOrder: fctParams.idOrder,
idProcessStep: fctParams.idProcessStep
});
$http({
method: 'POST',
url: 'orders/api/undoStep',
data: params
}).then((response) => {
showStepUpdateMessage(response, fctParams.idOrder);
}, utilsService.onHttpError);
}
function showStepUpdateMessage(response, idOrder) {
const stepsIdsForDeliveryDates = {
firstStepEnabled: 5,
lastStepEnabled: 6
};
ordersUtilsService.checkIfIsNextStepWanted(idOrder, 'setDeliveryDates', stepsIdsForDeliveryDates);
ordersUtilsService.checkIfIsNextStepWanted(idOrder, 'installationScheduling', stepsIdsForDeliveryDates);
updateMessage(response, startOrdersStepsModule);
}
function updateMessage(response, callback) {
if (typeof response.data.messages !== 'undefined') {
let shouldCallCallbackFunction = true;
response.data.messages.forEach((messageObj) => {
const key = messageObj.key ? $translate.instant('orders.messages.' + messageObj.key) : '';
let translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
translatedMessage = key !== '' ? key + ': ' + translatedMessage : translatedMessage;
if('additionalMessage' in messageObj) {
translatedMessage += messageObj.additionalMessage;
}
if (messageObj.message === 'ALLOWED_LANGUAGE') {
translatedMessage += $scope.allowedLanguages;
}
utilsService.displayMessage(messageObj.code, translatedMessage);
});
if (callback && shouldCallCallbackFunction) {
callback();
}
}
}
function getOrderStatusIcon(status) {
return ORDER_STATUSES_ICONS[status];
}
function updateOrderEstimation(estimationDate) {
const idOrder = global.getParameterByName('idOrder') || 0;
const params = $.param({
idOrder,
estimationDate
});
$http({
method: 'POST',
url: 'orders/api/updateOrderEstimation',
data: params
}).then(showUpdateEstimation, utilsService.onHttpError);
}
function showUpdateEstimation(response) {
updateMessage(response, getOrderInfo);
}
function updatePackageEndOfLife(endOfLifeDate, extraParams) {
const params = $.param({
idOrder: extraParams.idOrder,
endOfLife: endOfLifeDate,
idPackage: extraParams.idPackage,
ordersDetailsMail: JSON.stringify(ordersDetailsMail)
});
$http({
method: 'POST',
url: 'orders/api/updatePackageEndOfLife',
data: params
}).then(showUpdateEndOfLife, utilsService.onHttpError);
}
function showUpdateEndOfLife(response) {
updateMessage(response, getOrderInfo);
}
function updateStepActualDate(actualDate, step) {
const params = $.param({
idOrder: step.idOrder || 0,
idProcessStep: step.idProcessStep || 0,
actualDate,
ordersDetailsMail: JSON.stringify(ordersDetailsMail)
});
$http({
method: 'POST',
url: 'orders/api/updateStepActualDate',
data: params
}).then(showUpdateEstimation, utilsService.onHttpError);
}
function updateStepComment(comment, step) {
if (typeof comment !== 'undefined' && comment && step) {
const params = $.param({
idOrder: step.idOrder || 0,
idProcessStep: step.idProcessStep || 0,
comment,
isVisible: step.isNewCommentVisible,
ordersDetailsMail: JSON.stringify(ordersDetailsMail)
});
$http({
method: 'POST',
url: 'orders/api/updateStepComment',
data: params
}).then(showUpdateStepComment, utilsService.onHttpError);
}
}
function showUpdateStepComment(response) {
updateMessage(response, startOrdersStepsModule);
}
function updateOrderComment() {
if (typeof $scope.ordersInfo.orderCommentText !== 'undefined' && $scope.ordersInfo.orderCommentText !== '') {
const params = $.param({
idOrder: global.getParameterByName('idOrder') || 0,
comment: $scope.ordersInfo.orderCommentText,
ordersDetailsMail: JSON.stringify(ordersDetailsMail)
});
$http({
method: 'POST',
url: 'orders/api/updateOrderComment',
data: params
}).then(showUpdateOrderComment, utilsService.onHttpError);
}
}
function showUpdateOrderComment(response) {
updateMessage(response, startOrdersStepsModule);
}
function showHideCancelDialog() {
$scope.$evalAsync(() => {
$scope.isCancelDialogVisible = !$scope.isCancelDialogVisible;
});
}
function showHideNextDialog(params) {
const idNextBtn = params.idOrder + '-' + params.idProcess;
$scope.$evalAsync(() => {
if (params.action === 'next' && !$scope.isExtraActionOpen[idNextBtn]) {
$scope.isNextDialogVisible[params.idProcess] = !$scope.isNextDialogVisible[params.idProcess];
}
if (params.action === 'undo') {
$scope.isUndoDialogVisible[params.idProcess] = !$scope.isUndoDialogVisible[params.idProcess];
}
});
}
function showHideProcessDialog(selectedProcess) {
$scope.selectedProcess = selectedProcess;
$scope.$evalAsync(() => {
$scope.isProcessDialogVisible = !$scope.isProcessDialogVisible;
});
}
function showHideSupportDialog() {
$scope.$evalAsync(() => {
$scope.isSupportMailBtnVisible = !$scope.isSupportMailBtnVisible;
});
}
function cancelOrder(idOrder) {
const params = $.param({
idOrder,
ordersDetailsMail: JSON.stringify(ordersDetailsMail)
});
$http({
method: 'POST',
url: 'orders/api/cancelOrder',
data: params
}).then(showOrderCancelMessage, utilsService.onHttpError);
}
function showOrderCancelMessage(response) {
updateMessage(response, startOrdersStepsModule);
}
function isOrderOngoing(status) {
const orderFinishedStatuses = ['canceled', 'production', 'end-of-life'];
return orderFinishedStatuses.indexOf(status) === -1;
}
function setProcessForOrder(selectedProcess) {
const params = $.param({
idOrder: global.getParameterByName('idOrder') || 0,
idProcess: selectedProcess.idProcess,
ordersDetailsMail: JSON.stringify(ordersDetailsMail)
});
$scope.selectedProcess = selectedProcess;
$http({
method: 'POST',
url: 'orders/api/setProcessForOrder',
data: params
}).then(showProcessSelectedMessage, utilsService.onHttpError);
}
function showProcessSelectedMessage(response) {
updateMessage(response, startOrdersStepsModule);
}
function hasNoSelectedProcess(status) {
return status === 'open' ? true : false;
}
function updateStepCommentVisibility(commentObj) {
const isVisibleNewVal = commentObj.isVisible === '1' ? 0 : 1;
const params = $.param({
idComment: commentObj.id,
isVisible: isVisibleNewVal,
ordersDetailsMail: JSON.stringify(ordersDetailsMail)
});
$http({
method: 'POST',
url: 'orders/api/updateStepCommentVisibility',
data: params
}).then(showUpdateStepComment, utilsService.onHttpError);
}
function setNewCommentVisibility(step) {
step.isNewCommentVisible = step.isNewCommentVisible === '1' ? '0' : '1';
}
function canAddComment(step) {
return step.status === 'in-progress';
}
function formatStepText(stepStatus) {
return stepStatus.replace('-', '_');
}
function extraActionDirective(step) {
const directiveHtml = '<' + step.actionCode + '></' + step.actionCode + '>';
const scope = $rootScope.$new();
scope.step = step;
scope.packages = $scope.packages;
const comp = $compile($(directiveHtml))(scope);
$scope.$evalAsync(() => {
$('#extra-action-' + step.idProcess).append(comp);
});
}
function isNextBtnDisabled(stepInfo) {
const idNextBtn = stepInfo.idOrder + '-' + stepInfo.idProcess;
$scope.isExtraActionOpen[idNextBtn] = stepInfo.isNextButtonDisabled;
}
function getIconStepStatus() {
return currentStepStatus && currentStepStatus === 'in-progress' ? 'glyphicon-minus-sign' : 'glyphicon-plus-sign';
}
function getDisplayDescriptionClass() {
return currentStepStatus && currentStepStatus === 'in-progress' ? '' : 'order-step-description-display';
}
function getAvailabilityForSendSupportMail() {
const params = $.param({
idOrder: $scope.ordersInfo.id
});
$http({
method: 'POST',
url: 'orders/api/getAvailabilityForSendSupportMail',
data: params
}).then(setAvailabilityForSendSupportMail, utilsService.onHttpError);
}
function setAvailabilityForSendSupportMail(response) {
if (typeof response.data !== 'undefined') {
$scope.isSendSupportMailBtnAvailable = response.data;
}
}
function sendSupportMail(userText) {
if (!userText) {
const translatedMessage = $translate.instant('orders.messages.MAIL_TEXT_EMPTY');
utilsService.displayMessage('error', translatedMessage);
} else {
const params = $.param({
ordersInfo: JSON.stringify($scope.ordersInfo),
orderPackages: JSON.stringify($scope.packages),
userText
});
$http({
method: 'POST',
url: 'orders/api/sendSupportMail',
data: params
}).then(updateMessage, utilsService.onHttpError);
}
}
function getSystemAllowedLanguages() {
$http({
method: 'POST',
url: 'orders/api/getSystemAllowedLanguages'
}).then(setSystemAllowedLanguages, utilsService.onHttpError);
}
function setSystemAllowedLanguages(response) {
if (typeof response.data !== 'undefined' && Object.keys(response.data).length > 0) {
if(!$scope.allowedLanguages) {
response.data.languages.forEach(language => {
$scope.allowedLanguages = $scope.allowedLanguages ? $scope.allowedLanguages + ', ' + language : language;
});
}
const translatedMessage = $translate.instant('orders.messages.ALLOWED_LANGUAGE');
if (!$scope.allowedLanguagesDescription) {
$scope.allowedLanguagesDescription = translatedMessage + $scope.allowedLanguages + '!';
}
}
}
}
})();

View File

@@ -0,0 +1,78 @@
(function () {
global.dashModule
.controller('chooseInstallationCtrl', ['$scope', '$', '$http', '$translate', 'utilsService', chooseInstallationCtrl])
.directive('chooseInstallation', [chooseInstallationDirective]);
function chooseInstallationDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/chooseInstallationTemplate'
};
}
function chooseInstallationCtrl($scope, $, $http, $translate, utilsService) {
const step = $scope.$parent.step;
const idOrder = step.idOrder || 0;
const idPackage = step.idPackage || 0;
$scope.saveInstallationForPackage = saveInstallationForPackage;
$scope.getInstallCompaniesForPackage = getInstallCompaniesForPackage;
$scope.installCompany = {};
$scope.multipleInstallCompanies = false;
function getInstallCompaniesForPackage(step) {
const params = $.param({
idOrder,
idPackage
});
$http({
method: 'POST',
data: params,
url: 'orders/api/getInstallCompaniesForPackage'
}).then((response) => {
setInstallationCompanies(response, step);
}, utilsService.onHttpError);
}
function setInstallationCompanies(response, step) {
const availableInstallationCompanies = response.data.available;
const selectedInstallationCompany = response.data.selected;
if (response.data && availableInstallationCompanies.length) {
if (availableInstallationCompanies.length === 1) {
$scope.multipleInstallCompanies = false;
step.installationCompany = availableInstallationCompanies[0];
} else {
$scope.multipleInstallCompanies = true;
if (selectedInstallationCompany.length > 0) {
step.installationCompany = selectedInstallationCompany[0];
}
step.installCompanies = availableInstallationCompanies;
}
}
}
function saveInstallationForPackage(step) {
const params = $.param({
idOrder,
idPackage,
idInstallation: step.installationCompany.id
});
$http({
method: 'POST',
data: params,
url: 'orders/api/saveInstallationCompany'
}).then(showConfirmationMessage, utilsService.onHttpError);
}
function showConfirmationMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
});
}
}
}
})();

View File

@@ -0,0 +1,188 @@
(function () {
global.dashModule
.controller('customerAcceptanceCtrl', ['$scope', '$', '$http', '$translate', 'Upload', 'utilsService', customerAcceptanceCtrl])
.directive('customerAcceptance', [customerAcceptanceDirective]);
function customerAcceptanceDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/customerAcceptanceTemplate'
};
}
function customerAcceptanceCtrl($scope, $, $http, $translate, Upload, utilsService) {
const step = $scope.$parent.step;
const idOrder = step.idOrder;
const idProcess = step.idProcess;
const stepInfo = {
idOrder,
idProcess,
isNextButtonDisabled: true
};
$scope.getCustmerAcceptance = getCustmerAcceptance;
$scope.getDueDateClass = getDueDateClass;
$scope.uploadFile = uploadFile;
$scope.acceptDeclineInstallation = acceptDeclineInstallation;
$scope.getStatusIcon = getStatusIcon;
$scope.acceptance = {};
$scope.isInstallationNotAccepted = {};
$scope.showHideDialog = showHideDialog;
$scope.showDeclineInstallation = showDeclineInstallation;
$scope.isAcceptInstallationDisabled = false;
$scope.isDeclineInstallationDisabled = false;
$scope.isInstallationDeclined = {};
$scope.isDialogVisible = {};
$scope.getAcceptanceClass = getAcceptanceClass;
$scope.showCustomerAcceptance = showCustomerAcceptance;
$scope.getCustomerAcceptanceDescription = getCustomerAcceptanceDescription;
$scope.removeAcceptanceDocument = removeAcceptanceDocument;
function getCustmerAcceptance() {
const params = $.param({
idOrder
});
$http({
method: 'POST',
data: params,
url: 'orders/api/getCustomerAcceptance'
}).then(setCustomerAcceptance, utilsService.onHttpError);
}
function setCustomerAcceptance(response) {
if (response.data && Object.keys(response.data).length) {
$scope.acceptance = response.data[idOrder];
stepInfo.isNextButtonDisabled = parseInt($scope.acceptance.customerAccepted) === 0;
$scope.isAcceptInstallationDisabled = parseInt($scope.acceptance.customerAccepted) === 1;
$scope.isDeclineInstallationDisabled = parseInt($scope.acceptance.customerAccepted) === -1;
}
utilsService.executeRegisteredFunction('isNextBtnDisabled', stepInfo);
}
function getDueDateClass() {
if ($scope.acceptance.daysDiff <= 0) {
return 'alert-danger';
}
if ($scope.acceptance.daysDiff <= 3) {
return 'alert-warning';
}
return 'alert-info';
}
function displayMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
if (messageObj.code === 'success') {
getCustmerAcceptance();
}
if (messageObj.message === 'INSTALLATION_DECLINED') {
showDeclineInstallation();
$scope.installationDeclinedReason = '';
$scope.isDeclineInstallationDisabled = true;
}
});
}
}
function uploadFile(file) {
Upload.upload({
url: 'orders/api/uploadAcceptanceDocument',
method: 'POST',
file: file,
data: {
idPackage,
idOrder
}
}).then(displayMessage, utilsService.onHttpError);
}
function acceptDeclineInstallation(actionType) {
const params = $.param({
idOrder,
idPackage,
actionType,
declineReason: $scope.installationDeclinedReason
});
if ((actionType === 'accept' && !$scope.isAcceptInstallationDisabled) ||
(actionType === 'decline' && !$scope.isDeclineInstallationDisabled)) {
$http({
method: 'POST',
data: params,
url: 'orders/api/acceptDeclineInstallation'
}).then(displayMessage, utilsService.onHttpError);
}
}
function getStatusIcon(status) {
let icon = 'time';
if (parseInt(status) === -1) {
icon = 'remove';
} else if (parseInt(status) === 1) {
icon = 'ok';
}
return icon;
}
function showHideDialog(actionType) {
$scope.$evalAsync(() => {
$scope.isDialogVisible[actionType] = !$scope.isDialogVisible[actionType];
});
}
function showDeclineInstallation() {
if (!$scope.isDeclineInstallationDisabled) {
$scope.$evalAsync(() => {
$scope.isInstallationDeclined[idPackage] = !$scope.isInstallationDeclined[idPackage];
});
}
}
function getAcceptanceClass(acceptanceStatus) {
let cssClass = 'warning';
if (parseInt(acceptanceStatus) === -1) {
cssClass = 'danger';
} else if (parseInt(acceptanceStatus) === 1) {
cssClass = 'success';
}
return cssClass;
}
function showCustomerAcceptance(acceptance) {
return acceptance !== 0;
}
function getCustomerAcceptanceDescription(customerAcceptance) {
let acceptanceStatus = 'WAITING';
if (parseInt(customerAcceptance) === -1) {
acceptanceStatus = 'DECLINED';
} else if (parseInt(customerAcceptance) === 1) {
acceptanceStatus = 'ACCEPTED';
}
return $translate.instant('orders.messages.CUSTOMER_INSTALLATION_' + acceptanceStatus);
}
function removeAcceptanceDocument(idDocument) {
const params = $.param({
idOrder,
idPackage,
idDocument
});
$http({
method: 'POST',
data: params,
url: 'orders/api/removeOrderDocument'
}).then(displayMessage, utilsService.onHttpError);
}
}
})();

View File

@@ -0,0 +1,96 @@
(function () {
global.dashModule
.controller('procurementCtrl', ['$scope', '$', '$http', '$translate', 'Upload', 'utilsService', 'ordersUtilsService', procurementCtrl])
.directive('procurement', [procurementDirective]);
function procurementDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/procurementTemplate'
};
}
function procurementCtrl($scope, $, $http, $translate, Upload, utilsService, ordersUtilsService) {
const step = $scope.$parent.step;
const idOrder = step.idOrder;
$scope.getSuppliersByPackageOrder = getSuppliersByPackageOrder;
$scope.uploadFile = uploadFile;
$scope.removeOrderDocument = removeOrderDocument;
$scope.isDialogVisible = {};
$scope.showHideDialog = showHideDialog;
$scope.selectPackage = selectPackage;
$scope.selectedPackage = {};
function selectPackage(packageObj, idSupplier){
$scope.selectedPackage[idSupplier] = packageObj;
}
function getSuppliersByPackageOrder() {
const params = $.param({
idOrder,
documentType: 'configuration'
});
$http({
method: 'POST',
data: params,
url: 'orders/api/getSuppliersByPackageOrder'
}).then(setProductEstimations, utilsService.onHttpError);
}
function setProductEstimations(response) {
if (response.data) {
$scope.suppliersData = response.data;
$.each($scope.suppliersData, (name, details) => {
details.documents.forEach(docDetails => {
$scope.isDialogVisible[docDetails.idDocument] = false;
});
});
}
}
function uploadFile(file, idSupplier) {
Upload.upload({
url: 'orders/api/uploadConfigurationDocument',
method: 'POST',
file: file,
data: {
idPackage : $scope.selectedPackage[idSupplier] && $scope.selectedPackage[idSupplier].idPackage || 0,
idOrder,
idSupplier
}
}).then(displayMessage, utilsService.onHttpError);
}
function displayMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
getSuppliersByPackageOrder();
ordersUtilsService.getOrderInfo();
});
}
}
function removeOrderDocument(document) {
const params = $.param({
idOrder,
idPackage: document.idPackage,
idDocument: document.idDocument
});
$http({
method: 'POST',
data: params,
url: 'orders/api/removeOrderDocument'
}).then(displayMessage, utilsService.onHttpError);
}
function showHideDialog(idDocument) {
$scope.$evalAsync(() => {
$scope.isDialogVisible[idDocument] = !$scope.isDialogVisible[idDocument];
});
}
}
})();

View File

@@ -0,0 +1,147 @@
(function () {
global.dashModule
.controller('scheduleMeetingCtrl', ['$scope', '$', '$http', '$translate', 'utilsService', scheduleMeetingCtrl])
.directive('scheduleMeeting', [scheduleMeetingDirective]);
function scheduleMeetingDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/scheduleMeetingTemplate'
};
}
function scheduleMeetingCtrl($scope, $, $http, $translate, utilsService) {
$scope.updateScheduledDates = updateScheduledDates;
$scope.getScheduledDates = getScheduledDates;
$scope.addNewSchedule = addNewSchedule;
$scope.getIcon = getIcon;
$scope.canNotEditDate = canNotEditDate;
$scope.changeScheduleStatus = changeScheduleStatus;
$scope.parentStep = $scope.$parent.step;
const stepInfo = {
isNextButtonDisabled: true,
idOrder: $scope.$parent.step.idOrder,
idPackage: $scope.$parent.step.idPackage,
idProcess: $scope.$parent.step.idProcess
};
utilsService.executeRegisteredFunction('isNextBtnDisabled', stepInfo);
function getScheduledDates(step) {
const params = $.param({
idOrder: step.idOrder,
idPackage: step.idPackage,
idProcessStep: step.idProcessStep || 0
});
$http({
method: 'POST',
url: 'orders/api/getScheduledDates',
data: params
}).then((response) => {
setScheduleDates(response, step);
}, utilsService.onHttpError);
}
function setScheduleDates(response, step) {
if (response.data && response.data.length) {
step.scheduledDates = response.data;
} else {
addNewSchedule(step);
}
checkIfDateConfirmed(step);
}
function addNewSchedule(step) {
if (!step.scheduledDates) {
step.scheduledDates = [];
}
step.scheduledDates.push((() => {
return {
idSchedule: 0,
isDateConfirmed : 0,
scheduledDate: '',
idPackage: step.idPackage,
idProcessStep: step.idProcessStep
};
})());
}
function updateScheduledDates(newDate, data) {
const params = $.param({
idOrder: data.step.idOrder,
idPackage: data.step.idPackage,
idProcess: data.step.idProcess,
idProcessStep: data.step.idProcessStep || 0,
idSchedule: data.scheduleDate.idSchedule,
newDate: newDate,
});
$http({
method: 'POST',
url: 'orders/api/updateScheduledDates',
data: params
}).then((response) => {
showConfirmationMessage(response, data.step);
}, utilsService.onHttpError);
}
function showConfirmationMessage(response, step) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const key = messageObj.key ? $translate.instant('orders.messages.' + messageObj.key) : '';
let translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
translatedMessage = key !== '' ? key + ': ' + translatedMessage : translatedMessage;
utilsService.displayMessage(messageObj.code, translatedMessage);
if (messageObj.code === 'success') {
getScheduledDates(step);
}
});
}
}
function getIcon(status){
const statusesIcons = {
pending: 'time',
accepted: 'ok',
declined: 'ban-circle'
};
return statusesIcons[status];
}
function canNotEditDate(scheduleDate){
return parseInt(scheduleDate.isDateConfirmed) !== 0;
}
function changeScheduleStatus(scheduleDate, status, step){
const params = $.param({
idSchedule : scheduleDate.idSchedule,
idOrder: step.idOrder,
idPackage: step.idPackage,
actionCode: step.actionCode,
status
});
$http({
method: 'POST',
url: 'orders/api/updateScheduleDateStatus',
data: params
}).then((response) => {
showConfirmationMessage(response, step);
}, utilsService.onHttpError);
}
function checkIfDateConfirmed(step){
let isConfirmed = false;
step.scheduledDates.forEach((date) => {
if(date.isDateConfirmed && parseInt(date.isDateConfirmed) === 1){
isConfirmed = true;
}
});
stepInfo.isNextButtonDisabled = !isConfirmed;
utilsService.executeRegisteredFunction('isNextBtnDisabled', stepInfo);
}
}
})();

View File

@@ -0,0 +1,178 @@
(function () {
global.dashModule
.controller('validateQuestionnaireCtrl', ['$scope', '$', '$http', '$translate', 'Upload', 'utilsService', validateQuestionnaireCtrl])
.directive('validateQuestionnaire', [validateQuestionnaireDirective]);
function validateQuestionnaireDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/validateQuestionnaireTemplate'
};
}
function validateQuestionnaireCtrl($scope, $, $http, $translate, Upload, utilsService) {
$scope.customerDocuments = [];
$scope.getDocumentsAndQuestionnaireComments = getDocumentsAndQuestionnaireComments;
$scope.getValidationStatus = getValidationStatus;
$scope.validateQuestionaire = validateQuestionaire;
$scope.uploadFile = uploadFile;
$scope.needsUplaod = needsUplaod;
$scope.isQuestionaireInvalid = {};
$scope.isValidationDialogVisible = {
validated : {},
invalid : {}
};
$scope.showHideValidationDialog = showHideValidationDialog;
$scope.showInvalidTextbox = showInvalidTextbox;
$scope.waitingResponseFromCustomer = {};
$scope.getInvalidReasonsHeader = getInvalidReasonsHeader;
$scope.questionnaireCommentsExist = false;
const step = $scope.$parent.step;
const idOrder = step.idOrder;
const idProcessStep = step.idProcessStep;
const stepInfo = {
idOrder,
idProcess: step.idProcess
};
function getDocumentsAndQuestionnaireComments() {
getCustomerDocuments();
getQuestionnaireComments();
}
function getCustomerDocuments() {
const params = $.param({
idOrder,
documentType: 'orderQuestionaire'
});
$http({
method: 'POST',
data: params,
url: 'v2/orders/api/getOrderDocumentsPerType'
}).then(setCustomerDocuments, utilsService.onHttpError);
}
function showHideValidationDialog(fctParams) {
if(!$scope.waitingResponseFromCustomer[fctParams.idDocument]) {
$scope.$evalAsync(() => {
$scope.isValidationDialogVisible[fctParams.validationStatus][fctParams.idDocument] = !$scope.isValidationDialogVisible[fctParams.validationStatus][fctParams.idDocument];
});
}
}
function checkIfAllValid() {
let allValid = true;
Object.keys($scope.customerDocuments).forEach(key => {
const packageDocuments = $scope.customerDocuments[key];
packageDocuments.forEach((doc) => {
if (doc.validation !== 'validated') {
allValid = false;
}
$scope.waitingResponseFromCustomer[doc.idDocument] = doc.validation !== 'not-validated';
});
});
stepInfo.isNextButtonDisabled = !allValid;
utilsService.executeRegisteredFunction('isNextBtnDisabled', stepInfo);
}
function setCustomerDocuments(response) {
if (response.data && response.data.documents) {
$scope.customerDocuments = response.data.documents;
checkIfAllValid();
}
}
function getValidationStatus(status, documentValidation) {
return status === documentValidation;
}
function validateQuestionaire(fctParams) {
const params = $.param({
idOrder,
idPackage: fctParams.idPackage,
idDocument: fctParams.idDocument,
idProcessStep,
validationStatus: fctParams.validationStatus,
invalidQuestionaireReason: $scope.invalidQuestionaireReason
});
if (!$scope.waitingResponseFromCustomer[fctParams.idDocument]) {
$http({
method: 'POST',
data: params,
url: 'orders/api/validateQuestionaire'
}).then(displayMessage, utilsService.onHttpError);
}
}
function displayMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
if (messageObj.code === 'success') {
$scope.invalidQuestionaireReason = '';
$scope.isQuestionaireInvalid = {};
getDocumentsAndQuestionnaireComments();
}
if (messageObj.message === 'REASON_EMPTY') {
$('#invalid-questionaire-comment').focus();
}
});
}
}
function needsUplaod(validation) {
return validation === 'invalid';
}
function uploadFile(file, idDocument, idPackage) {
Upload.upload({
url: 'orders/api/reUploadQuestionaire',
method: 'POST',
file: file,
data: {
idPackage,
idOrder,
idDocument
}
}).then(displayMessage, utilsService.onHttpError);
}
function showInvalidTextbox(idDocument) {
$scope.isQuestionaireInvalid[idDocument] = (!$scope.isQuestionaireInvalid[idDocument] && !$scope.waitingResponseFromCustomer[idDocument]);
}
function getQuestionnaireComments() {
const params = $.param({
idOrder,
idProcessStep,
commentType: 'invalidQuestionnaireComment'
});
$http({
method: 'POST',
url: 'v2/orders/api/getCommentsByType',
data: params
}).then(setQuestionnaireComments, utilsService.onHttpError);
}
function setQuestionnaireComments(response) {
if (typeof response.data !== 'undefined') {
if (response.data.messages) {
displayMessage(response);
}
$scope.invalidQuestionaireComments = response.data;
$scope.questionnaireCommentsExist = $scope.invalidQuestionaireComments.length > 0;
}
}
function getInvalidReasonsHeader() {
return $translate.instant('orders.tables.extra.INVALID_REASONS');
}
}
})();

View File

@@ -0,0 +1,376 @@
(function () {
global.dashModule
.controller('installationSchedulerCtrl', ['$scope', '$', '$http', '$translate', '$timeout', 'Upload', 'utilsService', 'ordersUtilsService', installationSchedulerCtrl])
.directive('installationScheduler', [installationSchedulerDirective]);
function installationSchedulerDirective() {
return {
restrict: 'E'
};
}
function installationSchedulerCtrl($scope, $, $http, $translate, $timeout, Upload, utilsService, ordersUtilsService) {
const idOrder = global.getParameterByName('idOrder');
const idPackage = $scope.$parent.orderPackage.idPackage;
const stepsIdsForInstallation = {
firstStepEnabled: 5,
lastStepEnabled: 6
};
$scope.idPackage = idPackage;
$scope.idOrder = idOrder;
$scope.getInstallationDetails = getInstallationDetails;
$scope.installationDates = [];
$scope.earliestInstallationDate = () => {
return ordersUtilsService.getEarliestInstallationDate(idOrder);
};
$scope.saveInstallationForPackage = saveInstallationForPackage;
$scope.installCompany = {};
$scope.multipleInstallCompanies = false;
$scope.updateInstallationDate = updateInstallationDate;
$scope.getIcon = getIcon;
$scope.shouldShowAddNewDate = shouldShowAddNewDate;
$scope.showAddNewDate = true;
$scope.isRemoveBtnVisible = isRemoveBtnVisible;
$scope.isDateProposedByMe = isDateProposedByMe;
$scope.removeMyDate = removeMyDate;
$scope.isAcceptDialogVisible = {};
$scope.isDeclineDialogVisible = {};
$scope.isRemoveDialogVisible = {};
$scope.showHideAcceptDialog = showHideAcceptDialog;
$scope.showHideDeclineDialog = showHideDeclineDialog;
$scope.showHideRemoveDialog = showHideRemoveDialog;
$scope.isInstallationInOrder = true;
$scope.isInstallationSet = false;
$scope.canUserAcceptOrDecline = canUserAcceptOrDecline;
$scope.userButtonAction = userButtonAction;
$scope.isMyInstallationCompany = false;
$scope.isInstallationSchedulingDisabled = () => {
const schedulingDisabled = ordersUtilsService.isComponentDisabled(idOrder, 'installationScheduling') || $scope.earliestInstallationDate() === '-';
$scope.optionClass = schedulingDisabled ? 'installation-company-disabled' : '';
return schedulingDisabled;
};
$scope.isInstallCompanySelectedAndScheduleDisabled = () => {
return $scope.isInstallationSchedulingDisabled() || !$scope.isInstallationSet;
};
utilsService.registerFunction('setMinDateAvailable', setMinDateAvailable);
$scope.installationDocuments = {};
$scope.uploadFile = uploadFile;
$scope.removeInstallDocument = removeInstallDocument;
$scope.isDialogVisible = {};
$scope.showHideDialog = showHideDialog;
$scope.showHideInstallationDialog = showHideInstallationDialog;
$scope.isInstallationDialogVisible = {};
$scope.isChangeInstallationAvailable = false;
$scope.activateChangeInstallation = activateChangeInstallation;
$scope.showHideChangingInstallationDialog = showHideChangingInstallationDialog;
$scope.isChangingInstallationDialogVisible = false;
$scope.showDateDetails = showDateDetails;
function getInstallationInformations() {
getInstallCompaniesForPackage();
getConfirmationInstallationDates();
getInstallationDocuments();
checkIfDateAlreadyAccepted();
utilsService.registerFunction('getConfirmationInstallationDates', getConfirmationInstallationDates);
}
function getInstallationDetails() {
getInstallationInformations();
ordersUtilsService.checkIfIsNextStepWanted(idOrder, 'installationScheduling', stepsIdsForInstallation);
ordersUtilsService.getEarliestInstallationDateFromDb(idOrder);
}
function setMinDateAvailable(paramData) {
$('#installation-date-propose-' + paramData.idPackage).datepicker('option', 'minDate', new Date(paramData.minDate));
}
function getConfirmationInstallationDates() {
const params = $.param({
idOrder,
idPackage
});
$http({
method: 'POST',
url: 'orders/api/getInstallationDates',
data: params
}).then(setInstallationDates, utilsService.onHttpError);
}
function setInstallationDates(response) {
if (response.data && Object.keys(response.data).length) {
$scope.confirmationDates = response.data;
$scope.showAddNewDate = false;
} else {
$scope.confirmationDates = {};
$scope.showAddNewDate = true;
}
}
function getInstallCompaniesForPackage() {
const params = $.param({
idOrder,
idPackage
});
$http({
method: 'POST',
data: params,
url: 'orders/api/getInstallCompaniesForPackage'
}).then(setInstallationCompanies, utilsService.onHttpError);
}
function setInstallationCompanies(response) {
if (typeof response.data !== 'undefined') {
const availableInstallationCompanies = response.data.available ? response.data.available : [];
const selectedInstallationCompany = response.data.selected ? response.data.selected : [];
$scope.isMyInstallationCompany = response.data.isMyInstallationCompany;
if (availableInstallationCompanies.length === 0 && selectedInstallationCompany.length === 0) {
$scope.isInstallationInOrder = false;
} else if (availableInstallationCompanies.length > 0) {
if (availableInstallationCompanies.length === 1) {
$scope.multipleInstallCompanies = false;
$scope.installationCompany = availableInstallationCompanies[0];
$scope.isInstallationSet = true;
} else {
$scope.multipleInstallCompanies = true;
if (selectedInstallationCompany.length > 0) {
$scope.installationCompany = selectedInstallationCompany[0];
$scope.isInstallationSet = true;
}
$scope.installCompanies = availableInstallationCompanies;
}
}
$scope.isChangeInstallationAvailable = $scope.multipleInstallCompanies && $scope.isInstallationSet;
}
}
function getInstallationDocuments() {
const params = $.param({
idOrder,
idPackage,
documentType: 'installationProtocol'
});
$http({
method: 'POST',
url: 'orders/api/getOrderDocumentsPerType',
data: params
}).then(setInstallationDocuments, utilsService.onHttpError);
}
function setInstallationDocuments(response) {
if (typeof response.data !== 'undefined') {
$scope.installationDocuments = response.data;
}
}
function saveInstallationForPackage(idInstallation) {
const params = $.param({
idOrder,
idPackage,
idInstallation
});
$http({
method: 'POST',
data: params,
url: 'orders/api/saveInstallationCompany'
}).then(displayMessage, utilsService.onHttpError);
}
function checkIfDateAlreadyAccepted() {
const params = $.param({
idOrder,
idPackage
});
$http({
method: 'POST',
url: 'orders/api/checkIfDateAlreadyAccepted',
data: params
}).then(setInstallationAlreadyAccepted, utilsService.onHttpError);
}
function setInstallationAlreadyAccepted(response) {
if (typeof response !== 'undefined') {
$scope.isDateAlreadyAccepted = response.data;
}
}
function displayMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
let translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
if ('key' in messageObj) {
translatedMessage += ' ' + messageObj.key;
}
utilsService.displayMessage(messageObj.code, translatedMessage);
if (messageObj.code === 'success') {
$scope.installationDate = '';
getInstallationInformations();
}
});
}
}
function updateInstallationDate(installationDate, status = 'proposed') {
if (Date.parse(installationDate)) {
const params = $.param({
idOrder,
idPackage,
installationDate,
status
});
$http({
method: 'POST',
url: 'orders/api/updateInstallationDate',
data: params
}).then(displayMessage, utilsService.onHttpError);
} else {
const translatedMessage = $translate.instant('orders.messages.WRONG_DATE_FORMAT');
utilsService.displayMessage('error', translatedMessage);
}
}
function getIcon(status) {
const statusesIcons = {
proposed: 'time',
accepted: 'ok',
canceled: 'remove-circle',
declined: 'ban-circle',
invalid: 'remove-circle'
};
return statusesIcons[status];
}
function shouldShowAddNewDate() {
$scope.$evalAsync(() => {
$scope.showAddNewDate = !$scope.showAddNewDate;
});
}
function isDateProposedByMe(installationDate) {
return $scope.confirmationDates[installationDate].lastStatus === 'proposed' &&
$scope.confirmationDates[installationDate].isProposedByMe === true;
}
function removeMyDate(installationDate) {
const params = $.param({
idOrder,
idPackage,
installationDate
});
$http({
method: 'POST',
data: params,
url: 'orders/api/removeMyDate'
}).then(displayMessage, utilsService.onHttpError);
}
function showHideAcceptDialog(confirmationDate) {
checkIfDateAlreadyAccepted();
$scope.isAcceptDialogVisible[confirmationDate] = !$scope.isAcceptDialogVisible[confirmationDate];
}
function showHideDeclineDialog(confirmationDate) {
$scope.$evalAsync(() => {
$scope.isDeclineDialogVisible[confirmationDate] = !$scope.isDeclineDialogVisible[confirmationDate];
});
}
function showHideRemoveDialog(confirmationDate) {
$scope.$evalAsync(() => {
$scope.isRemoveDialogVisible[confirmationDate] = !$scope.isRemoveDialogVisible[confirmationDate];
});
}
function userButtonAction(data) {
if (data.userStatus && data.confirmationDate) {
updateInstallationDate(data.confirmationDate, data.userStatus);
}
}
function canUserAcceptOrDecline(confirmationDate, dateInfo, lastStatus) {
let additionalCondition = false;
if (dateInfo.lastStatus === 'proposed') {
$scope.offsetClass = 'col-md-offset-1';
} else {
$scope.offsetClass = 'col-md-offset-3';
}
if (lastStatus === 'declined') {
additionalCondition = dateInfo.lastStatus === 'canceled' && dateInfo.isProposedByMe;
}
return !$scope.isInstallationSchedulingDisabled() &&
((dateInfo.lastStatus === 'proposed' && !dateInfo.isProposedByMe) ||
(dateInfo.lastStatus === lastStatus && dateInfo.isProposedByMe) ||
additionalCondition);
}
function isRemoveBtnVisible(confirmationDate) {
return !$scope.isInstallationSchedulingDisabled() && isDateProposedByMe(confirmationDate);
}
function uploadFile(file) {
const idSupplier = $scope.installationCompany && $scope.installationCompany.idSupplier ? $scope.installationCompany.idSupplier : 0;
Upload.upload({
url: 'orders/api/uploadInstallationDocument',
method: 'POST',
file: file,
data: {
idPackage,
idOrder,
idSupplier,
fileType: 'installationProtocol'
}
}).then(displayMessage, utilsService.onHttpError);
}
function showHideDialog(idDocument) {
$scope.$evalAsync(() => {
$scope.isDialogVisible[idDocument] = !$scope.isDialogVisible[idDocument];
});
}
function showHideInstallationDialog(idInstallationCompany) {
$scope.$evalAsync(() => {
$scope.isInstallationDialogVisible[idInstallationCompany] = !$scope.isInstallationDialogVisible[idInstallationCompany];
});
}
function removeInstallDocument(idDocument) {
const params = $.param({
idOrder,
idPackage,
idDocument
});
$http({
method: 'POST',
data: params,
url: 'orders/api/removeOrderDocument'
}).then(displayMessage, utilsService.onHttpError);
}
function activateChangeInstallation() {
$scope.isChangeInstallationAvailable = !$scope.isChangeInstallationAvailable;
}
function showHideChangingInstallationDialog() {
$scope.$evalAsync(() => {
$scope.isChangingInstallationDialogVisible = !$scope.isChangingInstallationDialogVisible;
});
}
function showDateDetails(installationDate) {
installationDate.isInfoVisible = !installationDate.isInfoVisible;
}
}
})();

View File

@@ -0,0 +1,18 @@
(function () {
global.dashModule
.controller('ordersDetailsCtrl', ['$scope', 'utilsService', 'ordersUtilsService', ordersDetailsCtrl])
.directive('ordersDetails', [ordersDetailsDirective]);
function ordersDetailsDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/ordersDetailsTemplate'
};
}
function ordersDetailsCtrl($scope, utilsService, ordersUtilsService) {
$scope.getStatusIcon = utilsService.getStatusIcon;
$scope.hasAgreement = ordersUtilsService.hasAgreement;
$scope.calculatePrice = ordersUtilsService.calculatePrice;
}
})();

View File

@@ -0,0 +1,164 @@
(function () {
global.dashModule.service('ordersUtilsService', ['$', '$http', '$translate', 'utilsService', ordersUtilsService]);
function ordersUtilsService($, $http, $translate, utilsService) {
let maxDeliveryDate = '';
const earliestInstallationDate = {};
const isNextStepTheOneWanted = {};
const callbackMethods = {};
return {
hasExtraAction,
calculatePrice,
hasAgreement,
setMaximumDeliveryDate,
getEarliestInstallationDateFromDb,
getEarliestInstallationDate,
checkIfIsNextStepWanted,
isComponentDisabled,
registerOrderFunction,
getOrderInfo
};
function hasExtraAction(step) {
return step.stepType === 'extraAction' && step.status === 'in-progress';
}
function calculatePrice(values, units) {
let total = 0;
values.forEach((val) => {
total += parseFloat(val);
});
return units ? total * units : 0;
}
function hasAgreement(packagePayPeriod, servicesContractPeriod) {
return parseInt(packagePayPeriod) > 0 || parseInt(servicesContractPeriod) > 0;
}
function setMaximumDeliveryDate(idOrder, idPackage, earliestIntallationDate) {
const params = $.param({
idOrder,
idPackage,
maxDeliveryDate: earliestIntallationDate
});
if (!maxDeliveryDate) {
maxDeliveryDate = '-';
}
if (earliestIntallationDate && earliestIntallationDate !== '-') {
maxDeliveryDate = earliestIntallationDate;
$http({
method: 'POST',
url: 'orders/api/setEarliestInstallationDateInDb',
data: params
}).then(getMaximumDeliveryDate, utilsService.onHttpError);
}
}
function getMaximumDeliveryDate(response) {
if (typeof response.data !== 'undefined' && Object.keys(response.data).length) {
getEarliestInstallationDateFromDb(response.data.idOrder, response.data.idPackage);
displayMessage(response);
if('callConfirmationInstallationDatesFct' in response.data && response.data.callConfirmationInstallationDatesFct) {
utilsService.executeRegisteredFunction('getConfirmationInstallationDates');
}
}
}
function getEarliestInstallationDateFromDb(idOrder, idPackage) {
const params = $.param({
idOrder,
idPackage,
maxDeliveryDate: maxDeliveryDate[idPackage]
});
$http({
method: 'POST',
url: 'orders/api/getEarliestInstallationDate',
data: params
}).then(setEarliestInstallationDate, utilsService.onHttpError);
}
function setEarliestInstallationDate(response) {
if (typeof response.data !== 'undefined') {
if (response.data.messages) {
displayMessage(response);
}
if (response.data.earliestInstallationDate) {
const paramData = {
idPackage: response.data.idPackage,
minDate: response.data.earliestInstallationDate
};
earliestInstallationDate[response.data.idOrder] = response.data.earliestInstallationDate;
utilsService.executeRegisteredFunction('setMinDateAvailable', paramData);
}
}
}
function getEarliestInstallationDate(idOrder) {
return earliestInstallationDate[idOrder] || '-';
}
function checkIfIsNextStepWanted(idOrder, usedForDirective, stepIds) {
const params = $.param({
idOrder,
stepIds: JSON.stringify(stepIds)
});
$http({
method: 'POST',
url: 'orders/api/checkIfIsNextStepWanted',
data: params
}).then((response) => {
isNextStepWanted(response, idOrder, usedForDirective);
}, utilsService.onHttpError);
}
function isNextStepWanted(response, idOrder, usedForDirective) {
if(typeof response.data !== 'undefined') {
if(!isNextStepTheOneWanted[usedForDirective]) {
isNextStepTheOneWanted[usedForDirective] = {};
}
isNextStepTheOneWanted[usedForDirective][idOrder] = response.data;
}
}
function isComponentDisabled(idOrder, usedForDirective) {
if(isNextStepTheOneWanted[usedForDirective] && isNextStepTheOneWanted[usedForDirective][idOrder]) {
return isNextStepTheOneWanted[usedForDirective][idOrder];
}
return false;
}
function registerOrderFunction(key, showOrderInfo) {
callbackMethods[key] = showOrderInfo;
}
function getOrderInfo() {
const idOrder = global.getParameterByName('idOrder') || 0;
const params = $.param({
idOrder
});
$http({
method: 'POST',
url: 'orders/api/getOrderInfo',
data: params
}).then(callbackMethods.showOrderInfo, utilsService.onHttpError);
}
function displayMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
let translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
const messageKey = 'key' in messageObj ? ' ' + messageObj.key : '';
utilsService.displayMessage(messageObj.code, translatedMessage + messageKey);
});
}
}
}
})();

View File

@@ -0,0 +1,196 @@
(function () {
global.dashModule
.controller('ordersController', ['$scope', '$rootScope', '$http', '$compile', '$translate', '$', 'dataTableHelper', 'utilsService', 'ORDER_STATUSES_ICONS', 'ORDER_STATUSES', ordersController])
.directive('orders', [ordersDirective]);
function ordersDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/ordersTemplate'
};
}
function ordersController($scope, $rootScope, $http, $compile, $translate, $, dataTableHelper, utilsService, ORDER_STATUSES_ICONS, ORDER_STATUSES) {
const translationPath = 'orders.tables.headers.';
$scope.subModule = global.getParameterByName('subModule') || 'ongoing_orders';
$scope.setSubModule = setSubModule;
$scope.isSubmoduleVisible = isSubmoduleVisible;
$scope.getOngoingOrders = getOngoingOrders;
$scope.getOrdersHistory = getOrdersHistory;
$scope.brokers = [];
addUrlListener();
function addUrlListener() {
window.addEventListener('popstate', function (e) {
$scope.$evalAsync($scope => {
$scope.subModule = e.state ? e.state.subModule : 'ongoing_orders';
});
}, false);
}
function setSubModule($event) {
$scope.subModule = $event.currentTarget.attributes.subModule.value;
history.pushState({
subModule: $scope.subModule
}, null, '?subModule=' + $scope.subModule);
}
function isSubmoduleVisible(subModule) {
return subModule === $scope.subModule;
}
function getOngoingOrders() {
$http({
method: 'POST',
url: 'orders/api/getOngoingOrdersHeaders',
}).then(showOngoingOrders, utilsService.onHttpError);
}
function showOngoingOrders(response) {
if (response.data.brokers && response.data.brokers.length > 0) {
$scope.brokers = response.data.brokers;
}
if (response.data.headers.length > 0) {
const params = {
selector: '#ongoing-orders',
url: 'orders/api/getOngoingOrders',
hasDetails: true,
extraTableOptions: {
responsive: false,
order: [
[1, 'asc']
]
}
};
dataTableHelper.generateColumns(response.data.headers, translationPath, dataTableHelper.showTable, params, formatOrderColumn)
.then((table) => {
addDetailsEvent(table, params.selector);
addAssignBrokerDirectives();
});
}
}
function addAssignBrokerDirectives() {
$('#ongoing-orders tbody').off('click', '.assign-icon');
$('#ongoing-orders tbody').on('click', '.assign-icon', function () {
const assignSelector = $(this).parent().find('.assign-broker');
if (assignSelector.length) {
assignSelector.remove();
} else {
const parent = $(this).parent();
const idOrder = parent.attr('id-order');
const directiveHtml = '<assign-broker id="assign-broker-' + idOrder + '" class="assign-broker" ng-controller="assignBrokerCtrl"></assign-broker>';
const scope = $rootScope.$new();
scope.brokers = $scope.brokers;
scope.idOrder = idOrder;
scope.onUpdate = getOngoingOrders;
const comp = $compile($(directiveHtml))(scope);
parent.append(comp);
}
});
}
function getOrdersHistory() {
$http({
method: 'POST',
url: 'orders/api/getOrdersHistoryHeaders',
}).then(showOrdersHistory, utilsService.onHttpError);
}
function showOrdersHistory(response) {
if (response.data.length > 0) {
const params = {
selector: '#orders-history',
url: 'orders/api/getOrdersHistory',
hasDetails: true,
extraTableOptions: {
responsive: false,
order: [
[1, 'asc']
]
}
};
dataTableHelper.generateColumns(response.data, translationPath, dataTableHelper.showTable, params, formatOrderColumn)
.then((table) => {
addDetailsEvent(table, params.selector);
});
}
}
function addDetailsEvent(table, containerSelector) {
$(containerSelector + ' tbody').off('click', 'td.info-control');
$(containerSelector + ' tbody').on('click', 'td.info-control', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
row.child.hide();
tr.removeClass('shown');
} else {
const directiveHtml = '<orders-details ng-controller="ordersDetailsCtrl"></orders-details>';
const scope = $rootScope.$new();
scope.data = row.data();
const layerSelector = 'details-layer-' + scope.data.id;
row.child('<div id="' + layerSelector + '"></div>').show();
const comp = $compile($(directiveHtml))(scope);
$('#' + layerSelector).append(comp);
tr.addClass('shown');
}
});
}
function formatOrderColumn(value, translations) {
const columnObj = {
data: value,
title: translations[translationPath + value]
};
const renders = getOrderRenders();
columnObj.visible = isColumnVisible(value);
if (typeof renders[value] !== 'undefined') {
columnObj.render = renders[value];
}
return columnObj;
}
function isColumnVisible(value) {
const notVisibleFields = [
'id',
'idCustomer',
'idCommercialLead',
'idCommercialLeadUser',
'idCustomerInstance',
'deliveryAddress',
'customerPhone',
'customerMail',
'commercialLeadPhone',
'commercialLeadMail'
];
return notVisibleFields.indexOf(value) === -1;
}
function getOrderRenders() {
return {
orderNumber: ordersNumberRenderer,
status: ordersStatusRenderer,
orderItems: orderItemsRender,
step: orderStepRender,
assignedTo: assignedToRender
};
function ordersNumberRenderer(data, type, row) {
return '<a href="orders?subModule=orders_steps&idOrder=' + row.id + '&orderNumber=' + row.orderNumber + '">' + data + '</a>';
}
function ordersStatusRenderer(data) {
const status = ORDER_STATUSES[data] || data;
return '<div class="order-status-' + data + '"><span class="' + ORDER_STATUSES_ICONS[data] + '"></span> ' + status + '</div>';
}
function orderItemsRender(data, type, row) {
let html = '';
row.packages.forEach((pacakgeObj) => {
html += '<div class="order-item">';
html += pacakgeObj.units + ' x ' + pacakgeObj.packageName;
html += typeof pacakgeObj.shortDesc !== 'undefined' ? ' ( ' + pacakgeObj.shortDesc + ' )' : '';
html += ' <span class="order-status-' + pacakgeObj.status + ' ' + ORDER_STATUSES_ICONS[pacakgeObj.status] + '"></span>';
html += '</div>';
});
return html;
}
function orderStepRender(data) {
return data.replace(/,/g, '<br/>');
}
function assignedToRender(data, type, row) {
const newData = data === '' ? $translate.instant('orders.tables.extra.NOT_ASSIGNED') : data;
let html = '<div class="assign-broker-layer" id-order="' + row.id + '">';
html += '<div class="assigned-broker">' + newData + '</div>';
html += '<div class="assign-icon glyphicon glyphicon-pencil"></div>';
html += '</div>';
return html;
}
}
}
})();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,303 @@
(function () {
global.dashModule
.controller('setDeliveryDatesCtrl', ['$scope', '$', '$http', '$translate', 'utilsService', 'ordersUtilsService', setDeliveryDatesCtrl])
.directive('setDeliveryDates', [setDeliveryDatesDirective]);
function setDeliveryDatesDirective() {
return {
restrict: 'E'
};
}
function setDeliveryDatesCtrl($scope, $, $http, $translate, utilsService, ordersUtilsService) {
let areEstimatedDatesSet = false;
let areConfirmedDatesSet = false;
const stepIdsForDeliveryDates = {
firstStepEnabled: 5,
lastStepEnabled: 6
};
$scope.isDatePickerOpen = {
estimatedDate: {},
confirmedDate: {}
};
const idOrder = global.getParameterByName('idOrder');
const process = $scope.$parent.process;
const idPackage = process.idPackage;
const idProcess = process.idProcess;
const stepInfo = {
idOrder,
idPackage,
idProcess
};
$scope.idPackage = idPackage;
$scope.getEstimationsAndEarliestInstallDate = getEstimationsAndEarliestInstallDate;
$scope.updateSupplierEstimation = updateSupplierEstimation;
$scope.getEstimationIcon = getEstimationIcon;
$scope.getEstimatedOrConfirmedMaxDate = getEstimatedOrConfirmedMaxDate;
$scope.updateTracking = updateTracking;
$scope.addTracking = addTracking;
$scope.supplierEstimations = [];
$scope.shouldShowAddNewTracking = shouldShowAddNewTracking;
$scope.showAddNewTracking = {};
$scope.removeTracking = removeTracking;
$scope.isRemoveDialogVisible = {};
$scope.showHideRemoveDialog = showHideRemoveDialog;
$scope.isTrackingEmpty = isTrackingEmpty;
$scope.removeSupplierEstimation = removeSupplierEstimation;
$scope.areProductsInOrder = true;
$scope.openDatePicker = openDatePicker;
$scope.isDateEditable = isDateEditable;
$scope.isRemoveDatesDialogVisible = {
'estimated': {},
'confirmed': {}
};
$scope.showHideRemoveDatesDialog = showHideRemoveDatesDialog;
$scope.earliestInstallationDate = () => {
return ordersUtilsService.getEarliestInstallationDate(idOrder);
};
$scope.isSetDeliveryDatesDisabled = () => {
return ordersUtilsService.isComponentDisabled(idOrder, 'setDeliveryDates');
};
function getEstimationsAndEarliestInstallDate() {
getSupplierEstimations();
ordersUtilsService.checkIfIsNextStepWanted(idOrder, 'setDeliveryDates', stepIdsForDeliveryDates);
ordersUtilsService.getEarliestInstallationDateFromDb(idOrder, idPackage);
utilsService.registerFunction('getSupplierEstimations', getSupplierEstimations);
}
function getSupplierEstimations(onInit = false) {
const params = $.param({
idOrder
});
$http({
method: 'POST',
data: params,
url: 'orders/api/getSupplierEstimations'
}).then((response) => {
setSuppliersEstimations(response, onInit);
}, utilsService.onHttpError);
}
function setSuppliersEstimations(response, onInit = false) {
areEstimatedDatesSet = false;
areConfirmedDatesSet = false;
if (response.data) {
$scope.supplierEstimations = response.data;
if ($scope.supplierEstimations.length === 0) {
$scope.areProductsInOrder = false;
}
$scope.supplierEstimations.forEach(supplierEstimation => {
$scope.showAddNewTracking[supplierEstimation.idSupplier] = !supplierEstimation.trackings.length;
});
}
if (!onInit) {
areEstimatedDatesSet = checkEstimatedDateSet($scope.supplierEstimations);
areConfirmedDatesSet = checkConfirmedDateSet($scope.supplierEstimations);
if (areConfirmedDatesSet) {
const maxConfDate = getEstimatedOrConfirmedMaxDate('confirmedDate');
ordersUtilsService.setMaximumDeliveryDate(idOrder, 0, maxConfDate);
} else if (areEstimatedDatesSet) {
const maxEstimatedDate = getEstimatedOrConfirmedMaxDate('estimatedDate');
const maxConfDate = getEstimatedOrConfirmedMaxDate('confirmedDate');
const maxDate = maxConfDate !== '-' ? maxConfDate > maxEstimatedDate ? maxConfDate : maxEstimatedDate : maxEstimatedDate;
ordersUtilsService.setMaximumDeliveryDate(idOrder, 0, maxDate);
}
}
utilsService.executeRegisteredFunction('isNextBtnDisabled', stepInfo);
}
function checkEstimatedDateSet(supplierEstimations) {
return supplierEstimations.every(supplierEstimation => {
return supplierEstimation.estimatedDate !== null;
});
}
function checkConfirmedDateSet(supplierEstimations) {
return supplierEstimations.every(supplierEstimation => {
return supplierEstimation.confirmedDate !== null;
});
}
function addTracking(idSupplier, trackingNumber, trackingUrl) {
const params = $.param({
idOrder,
idSupplier,
trackingNumber,
trackingUrl
});
$http({
method: 'POST',
data: params,
url: 'orders/api/addTracking'
}).then(displayUpdateMessage, utilsService.onHttpError);
}
function updateTracking(trackingInfo) {
const params = $.param({
idTracking: trackingInfo.idTracking,
trackingNumber: trackingInfo.trackingNumber,
trackingUrl: trackingInfo.trackingUrl
});
$http({
method: 'POST',
data: params,
url: 'orders/api/updateTracking'
}).then(displayUpdateMessage, utilsService.onHttpError);
}
function removeSupplierEstimation(fctParams) {
const params = $.param({
idOrder,
type: fctParams.type,
idSupplier: fctParams.idSupplier
});
if(areEstimatedDatesSet) {
if(!areConfirmedDatesSet && fctParams.type === 'estimation') {
ordersUtilsService.setMaximumDeliveryDate(idOrder, 0, 'remove');
}
} else if(!areEstimatedDatesSet && areConfirmedDatesSet){
ordersUtilsService.setMaximumDeliveryDate(idOrder, 0, 'remove');
} else if(areEstimatedDatesSet || areConfirmedDatesSet) {
const maxEstimatedDate = getEstimatedOrConfirmedMaxDate('estimatedDate');
const maxConfDate = getEstimatedOrConfirmedMaxDate('confirmedDate');
const maxDate = maxConfDate !== '-' ? maxConfDate > maxEstimatedDate ? maxConfDate : maxEstimatedDate : maxEstimatedDate;
ordersUtilsService.setMaximumDeliveryDate(idOrder, 0, maxDate);
}
$http({
method: 'POST',
data: params,
url: 'orders/api/removeSupplierEstimation'
}).then(displayUpdateMessage, utilsService.onHttpError);
}
function updateSupplierEstimation(date, supplierEstimation) {
if (Date.parse(date)) {
const params = $.param({
idOrder,
idSupplier: supplierEstimation.idSupplier,
estimatedDate: supplierEstimation.estimatedDate,
confirmedDate: supplierEstimation.confirmedDate
});
if (supplierEstimation.confirmedDate && areEstimatedDatesSet) {
const maxEstimatedDate = getEstimatedOrConfirmedMaxDate('estimatedDate');
const maxConfDate = getEstimatedOrConfirmedMaxDate('confirmedDate');
let maxDate = maxEstimatedDate;
if(maxConfDate !== '-') {
if(maxConfDate > maxEstimatedDate) {
maxDate = maxConfDate;
}
}
ordersUtilsService.setMaximumDeliveryDate(idOrder, 0, maxDate);
}
$http({
method: 'POST',
data: params,
url: 'orders/api/updateSupplierEstimation'
}).then(displayUpdateMessage, utilsService.onHttpError);
} else {
const translatedMessage = $translate.instant('orders.messages.WRONG_DATE_FORMAT');
utilsService.displayMessage('error', translatedMessage);
}
}
function displayUpdateMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
const messageKey = 'key' in messageObj ? messageObj.key : '';
utilsService.displayMessage(messageObj.code, translatedMessage + messageKey);
if (response.data.messages[0].code === 'success') {
getSupplierEstimations();
if ('idProduct' in response.data) {
$scope.isDatePickerOpen['estimatedDate'][response.data.idProduct] = false;
$scope.isDatePickerOpen['confirmedDate'][response.data.idProduct] = false;
}
}
});
}
}
function getEstimationIcon(confirmedDate) {
return confirmedDate ? 'glyphicon-ok' : 'glyphicon-time';
}
function getEstimatedOrConfirmedMaxDate(key) {
let maxDate = '2000-01-01';
let d1;
let d2;
const maxTempDate = $scope.supplierEstimations.length > 0 ?
$scope.supplierEstimations.reduce((a, b) => {
d1 = new Date(a[key]);
d2 = new Date(b[key]);
return d1 < d2 ? b : a;
}) : maxDate;
d1 = new Date(maxTempDate[key]);
d2 = new Date(maxDate);
maxDate = d1 > d2 ? maxTempDate[key] : maxDate;
return maxDate !== '2000-01-01' ? maxDate : '-';
}
function shouldShowAddNewTracking(idSupplier) {
$scope.$evalAsync(() => {
$scope.showAddNewTracking[idSupplier] = !$scope.showAddNewTracking[idSupplier];
});
}
function showHideRemoveDialog(idTracking) {
$scope.$evalAsync(() => {
$scope.isRemoveDialogVisible[idTracking] = !$scope.isRemoveDialogVisible[idTracking];
});
}
function removeTracking(trackingInfo) {
const params = $.param({
idTracking: trackingInfo.idTracking
});
$http({
method: 'POST',
url: 'orders/api/removeTracking',
data: params
}).then(displayUpdateMessage, utilsService.onHttpError);
}
function isTrackingEmpty(trackingData) {
return trackingData.length === 0;
}
function openDatePicker(dateType, idSupplier) {
if (!(idSupplier in $scope.isDatePickerOpen[dateType])) {
$scope.isDatePickerOpen[dateType][idSupplier] = false;
}
$scope.isDatePickerOpen[dateType][idSupplier] = !$scope.isDatePickerOpen[dateType][idSupplier];
}
function isDateEditable(dateType, supplierEstimation) {
return $scope.isDatePickerOpen[dateType][supplierEstimation.idSupplier] || !supplierEstimation[dateType];
}
function showHideRemoveDatesDialog(type, supplierEstimation) {
$scope.$evalAsync(() => {
$scope.isRemoveDatesDialogVisible[type][supplierEstimation.idSupplier] = !$scope.isRemoveDatesDialogVisible[type][supplierEstimation.idSupplier];
});
}
}
})();

View File

@@ -0,0 +1,35 @@
(function () {
global.dashModule
.controller('suppliersProcurementViewCtrl', ['$scope', '$', '$http', '$rootScope', '$compile', 'utilsService', 'ordersUtilsService', suppliersProcurementViewCtrl])
.directive('suppliersProcurementView', [suppliersProcurementViewDirective]);
function suppliersProcurementViewDirective() {
return {
restrict: 'E',
templateUrl: 'orders/html/suppliersProcurementViewTemplate'
};
}
function suppliersProcurementViewCtrl($scope, $, $http, $rootScope, $compile, utilsService, ordersUtilsService) {
$scope.hasExtraAction = ordersUtilsService.hasExtraAction;
$scope.getOrderSteps = getOrderSteps;
function getOrderSteps() {
const idOrder = global.getParameterByName('idOrder') || 0;
const params = $.param({
idOrder
});
$http({
method: 'POST',
url: 'orders/api/getOrderSteps',
data: params
}).then(showOrderSteps, utilsService.onHttpError);
}
function showOrderSteps(response) {
if (typeof response.data === 'object') {
$scope.processSteps = response.data;
}
}
}
})();

View File

@@ -0,0 +1,21 @@
(function () {
global.dashModule
.directive('supportMail', ['utilsService', 'ordersUtilsService', supportMailDirective]);
function supportMailDirective(utilsService, ordersUtilsService) {
return {
restrict: 'A',
templateUrl: 'orders/html/supportMailTemplate',
scope: {
ordersDetails: '<',
packages: '<',
supportMailText: '='
},
link: function (scope) {
scope.calculatePrice = ordersUtilsService.calculatePrice;
scope.getStatusIcon = utilsService.getStatusIcon;
scope.hasAgreement = ordersUtilsService.hasAgreement;
}
};
}
})();

View File

@@ -0,0 +1,80 @@
(function () {
global.dashModule
.controller('uploadDocumentsForOrderPackageCtrl', ['$scope', '$', '$http', '$translate', 'utilsService', 'Upload', uploadDocumentsForOrderPackageCtrl])
.directive('uploadDocumentsForOrderPackage', [uploadDocumentsForOrderPackageDirective]);
function uploadDocumentsForOrderPackageDirective() {
return {
restrict: 'E'
};
}
function uploadDocumentsForOrderPackageCtrl($scope, $, $http, $translate, utilsService, Upload) {
$scope.getDocumentTypes = getDocumentTypes;
$scope.setDocumentTypes = setDocumentTypes;
$scope.uploadFile = uploadFile;
$scope.selectFileType = selectFileType;
$scope.selectPackage = selectPackage;
$scope.documentTypes = [];
$scope.fileName = '';
$scope.selectedFileType = {};
$scope.selectedPackage = {};
$scope.isOrderOngoingOrCompleted = isOrderOngoingOrCompleted;
function getDocumentTypes() {
$http({
url: 'documents/api/getDocumentTypes',
method: 'POST',
data: $.param({
withoutTemplates: true
})
}).then(setDocumentTypes, utilsService.onHttpError);
}
function setDocumentTypes(response){
if(response.data && response.data.length){
$scope.documentTypes = response.data.filter((documentType) => {
return documentType.isSpecialType !== 1;
});
}
}
function uploadFile(file) {
Upload.upload({
url: 'orders/api/uploadOrderDocument',
method: 'POST',
file: file,
data: {
idOrder: global.getParameterByName('idOrder') || 0,
idPackage: $scope.selectedPackage.idPackage || 0,
idDocumentType: $scope.selectedFileType.idDocumentType || 0,
fileName : $scope.fileName
}
}).then(displayMessage, utilsService.onHttpError);
}
function displayMessage(response) {
if (typeof response.data.messages !== 'undefined') {
response.data.messages.forEach((messageObj) => {
const translatedMessage = $translate.instant('orders.messages.' + messageObj.message);
utilsService.displayMessage(messageObj.code, translatedMessage);
if(messageObj.code === 'success'){
$scope.fileName = '';
}
});
}
}
function selectFileType(docType){
$scope.selectedFileType = docType;
}
function selectPackage(packageObj){
$scope.selectedPackage = packageObj;
}
function isOrderOngoingOrCompleted() {
return ['in-progress', 'production'].includes($scope.$parent.$parent.$parent.ordersInfo.status);
}
}
})();