442 lines
16 KiB
JavaScript
442 lines
16 KiB
JavaScript
supersamApp.controller('OrderPaymentController', [
|
|||
|
|
'$scope',
|
||
|
|
'$http',
|
||
|
|
'$timeout',
|
||
|
|
'$filter',
|
||
|
|
'config',
|
||
|
|
'$interval',
|
||
|
|
function($scope,
|
||
|
|
$http,
|
||
|
|
$timeout,
|
||
|
|
$filter,
|
||
|
|
config,
|
||
|
|
$interval) {
|
||
|
|
var orderPaymentApp;
|
||
|
|
orderPaymentApp = (function() {
|
||
|
|
class orderPaymentApp {
|
||
|
|
constructor() {
|
||
|
|
this.openDateFromDatepicker = this.openDateFromDatepicker.bind(this);
|
||
|
|
this.openDateToDatepicker = this.openDateToDatepicker.bind(this);
|
||
|
|
this.processSearchResponse = this.processSearchResponse.bind(this);
|
||
|
|
this.searchOrders = this.searchOrders.bind(this);
|
||
|
|
this.adminDeleteOrder = this.adminDeleteOrder.bind(this);
|
||
|
|
this.openElplatPaymentHistoryModal = this.openElplatPaymentHistoryModal.bind(this);
|
||
|
|
this.adminShowElplatPaymentHistory = this.adminShowElplatPaymentHistory.bind(this);
|
||
|
|
this.makeElplatRefund = this.makeElplatRefund.bind(this);
|
||
|
|
this.openCloudPaymentsPaymentHistoryModal = this.openCloudPaymentsPaymentHistoryModal.bind(this);
|
||
|
|
this.adminShowCloudPaymentsPaymentHistory = this.adminShowCloudPaymentsPaymentHistory.bind(this);
|
||
|
|
this.makeCloudPaymentsRefund = this.makeCloudPaymentsRefund.bind(this);
|
||
|
|
this.getPaymentGatewayLabel = this.getPaymentGatewayLabel.bind(this);
|
||
|
|
$scope.utilities.showContentOnLoad();
|
||
|
|
$timeout(() => {
|
||
|
|
return angular.element("#orderPaymentSearch").focus();
|
||
|
|
});
|
||
|
|
this.dateFrom = new Date();
|
||
|
|
this.dateFrom.setDate(this.dateFrom.getDate() - 7);
|
||
|
|
this.dateTo = new Date(); //+7 days
|
||
|
|
config.sortFields = {
|
||
|
|
ordersList: {
|
||
|
|
field: 'expiry_date',
|
||
|
|
direction: 'desc'
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
openDateFromDatepicker() {
|
||
|
|
return this.dateFromDatepicker.opened = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
openDateToDatepicker() {
|
||
|
|
return this.dateToDatepicker.opened = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
processSearchResponse(data) {
|
||
|
|
this.errors = [];
|
||
|
|
this.ordersList = data.ordersList;
|
||
|
|
this.totalOrders = data.totalOrders;
|
||
|
|
this.paidCount = data.paidCount;
|
||
|
|
this.paidTotal = data.paidTotal;
|
||
|
|
this.unpaidCount = data.unpaidCount;
|
||
|
|
this.unpaidTotal = data.unpaidTotal;
|
||
|
|
this.pagination.totalItems = data.totalOrders;
|
||
|
|
this.pagination.totalPages = this.pagination.numPerPage < 1 ? 1 : Math.ceil(this.pagination.totalItems / this.pagination.numPerPage);
|
||
|
|
this.pagination.totalPages = Math.max(this.pagination.totalPages || 0, 1);
|
||
|
|
return $timeout(() => {
|
||
|
|
$('[data-toggle="tooltip"]').tooltip();
|
||
|
|
return angular.element("body").scrollTo('#table-order-payment-head', 50, {
|
||
|
|
offset: {
|
||
|
|
top: -300
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
searchOrders() {
|
||
|
|
var dataToSend;
|
||
|
|
this.search = angular.copy(this.search.trim());
|
||
|
|
$timeout(() => {
|
||
|
|
return angular.element("#orderPaymentSearch").val(this.search);
|
||
|
|
});
|
||
|
|
if (!this.isSubmitting) {
|
||
|
|
this.isSubmitting = true;
|
||
|
|
$timeout(() => {
|
||
|
|
return $('[data-toggle="tooltip"]').tooltip('dispose');
|
||
|
|
});
|
||
|
|
dataToSend = {
|
||
|
|
action: "searchOrders",
|
||
|
|
search: this.search,
|
||
|
|
paymentStatus: this.paymentStatus,
|
||
|
|
paymentGateway: this.paymentGateway,
|
||
|
|
currentPage: this.pagination.currentPage,
|
||
|
|
numPerPage: this.pagination.numPerPage,
|
||
|
|
sortFields: config.sortFields.ordersList,
|
||
|
|
dateFrom: this.dateFrom,
|
||
|
|
dateTo: this.dateTo
|
||
|
|
};
|
||
|
|
return $http.post(config.urls.orderPayment, dataToSend).then((response) => {
|
||
|
|
var data;
|
||
|
|
data = response.data;
|
||
|
|
this.isSubmitting = false;
|
||
|
|
this.usedSearch = angular.copy(this.search);
|
||
|
|
if (data) {
|
||
|
|
if (data.status && (data.status === "success")) {
|
||
|
|
return this.processSearchResponse(data);
|
||
|
|
} else {
|
||
|
|
if (data.errors && data.errors.length) {
|
||
|
|
return this.errors = data.errors;
|
||
|
|
} else {
|
||
|
|
return toastr.error(config.global_labels.defaultErrorMessage.value);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch((response) => {
|
||
|
|
if (response.data && response.data.errors) {
|
||
|
|
this.errors = response.data.errors;
|
||
|
|
} else {
|
||
|
|
toastr.error(config.global_labels.defaultErrorMessage.value);
|
||
|
|
}
|
||
|
|
this.usedSearch = angular.copy(this.search);
|
||
|
|
return this.isSubmitting = false;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
adminDeleteOrder(adminDeleteOrder) {
|
||
|
|
var dataToSend;
|
||
|
|
if (!this.isDeleteOrderSubmitting) {
|
||
|
|
if (confirm("Вы уверены, что хотите удалить данный счет?")) {
|
||
|
|
this.isDeleteOrderSubmitting = true;
|
||
|
|
dataToSend = {
|
||
|
|
id: adminDeleteOrder.id,
|
||
|
|
search: this.search,
|
||
|
|
paymentStatus: this.paymentStatus,
|
||
|
|
paymentGateway: this.paymentGateway,
|
||
|
|
currentPage: this.pagination.currentPage,
|
||
|
|
numPerPage: this.pagination.numPerPage,
|
||
|
|
sortFields: config.sortFields.ordersList
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.urls.orderPaymentAdminDeleteOrder,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 30000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
this.isDeleteOrderSubmitting = false;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status && (data.status === "success")) {
|
||
|
|
this.processSearchResponse(data);
|
||
|
|
return toastr.success("Счет был успешно удалён");
|
||
|
|
} else {
|
||
|
|
if (data.warning) {
|
||
|
|
toastr.warning(data.warning);
|
||
|
|
}
|
||
|
|
if (data.error) {
|
||
|
|
return toastr.warning(data.error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
this.isDeleteOrderSubmitting = false;
|
||
|
|
return toastr.error(config.global_labels.defaultErrorMessage.value);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
openElplatPaymentHistoryModal() {
|
||
|
|
return $timeout(() => {
|
||
|
|
return angular.element("#elplatPaymentHistoryModal").modal("show");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
adminShowElplatPaymentHistory(orderId, order_num, showElplatHistoryModalOnSuccess = true) {
|
||
|
|
var dataToSend;
|
||
|
|
dataToSend = {
|
||
|
|
id: orderId
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.urls.getElplatPaymentHistory,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 30000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status && (data.status === "success")) {
|
||
|
|
this.elplatPaymentModalData = {
|
||
|
|
orderId: orderId,
|
||
|
|
order_num: order_num,
|
||
|
|
history: data.history,
|
||
|
|
refundDescription: data.refundDescription,
|
||
|
|
refundAmount: data.refundAmount
|
||
|
|
};
|
||
|
|
if (showElplatHistoryModalOnSuccess) {
|
||
|
|
return this.openElplatPaymentHistoryModal();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (data.warning) {
|
||
|
|
toastr.warning(data.warning);
|
||
|
|
}
|
||
|
|
if (data.error) {
|
||
|
|
return toastr.warning(data.error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
return toastr.error(config.global_labels.defaultErrorMessage.value);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
makeElplatRefund() {
|
||
|
|
var dataToSend;
|
||
|
|
if (!this.isMakingElplatRefundInProgress) {
|
||
|
|
if (confirm("Вы уверены, что хотите вернуть средства по данному счету?")) {
|
||
|
|
this.isMakingElplatRefundInProgress = true;
|
||
|
|
dataToSend = {
|
||
|
|
id: this.elplatPaymentModalData.orderId,
|
||
|
|
refundDescription: this.elplatPaymentModalData.refundDescription,
|
||
|
|
refundAmount: this.elplatPaymentModalData.refundAmount
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.urls.makeElplatRefund,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 30000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
this.isMakingElplatRefundInProgress = false;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status && (data.status === "success")) {
|
||
|
|
toastr.success("Возврат средств был произведен успешно.");
|
||
|
|
return this.adminShowElplatPaymentHistory(this.elplatPaymentModalData.orderId, "", false);
|
||
|
|
} else {
|
||
|
|
if (data.warning) {
|
||
|
|
toastr.warning(data.warning);
|
||
|
|
}
|
||
|
|
if (data.error) {
|
||
|
|
return toastr.warning(data.error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
this.isMakingElplatRefundInProgress = false;
|
||
|
|
return toastr.error(config.global_labels.defaultErrorMessage.value);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
openCloudPaymentsPaymentHistoryModal() {
|
||
|
|
$timeout(() => {
|
||
|
|
return angular.element("#cloudPaymentsPaymentHistoryModal").modal("show");
|
||
|
|
});
|
||
|
|
return angular.element("#cloudPaymentsPaymentHistoryModal").on("hidden.bs.modal", () => {
|
||
|
|
if ($scope.orderPayment.cloudPaymentsPaymentModalDataPromise) {
|
||
|
|
$interval.cancel($scope.orderPayment.cloudPaymentsPaymentModalDataPromise);
|
||
|
|
return $scope.orderPayment.cloudPaymentsPaymentModalDataPromise = null;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
adminShowCloudPaymentsPaymentHistory(orderId, order_num, showCloudPaymentsHistoryModalOnSuccess = true) {
|
||
|
|
var dataToSend;
|
||
|
|
dataToSend = {
|
||
|
|
id: orderId
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.urls.getCloudPaymentsPaymentHistory,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 30000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status && (data.status === "success")) {
|
||
|
|
this.cloudPaymentsPaymentModalData = {
|
||
|
|
orderId: orderId,
|
||
|
|
order_num: order_num,
|
||
|
|
history: data.history,
|
||
|
|
refundAmount: data.refundAmount
|
||
|
|
};
|
||
|
|
if (showCloudPaymentsHistoryModalOnSuccess) {
|
||
|
|
return this.openCloudPaymentsPaymentHistoryModal();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (data.warning) {
|
||
|
|
toastr.warning(data.warning);
|
||
|
|
}
|
||
|
|
if (data.error) {
|
||
|
|
return toastr.warning(data.error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
return toastr.error(config.global_labels.defaultErrorMessage.value);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
makeCloudPaymentsRefund() {
|
||
|
|
var dataToSend;
|
||
|
|
if (!this.isMakingCloudPaymentsRefundInProgress) {
|
||
|
|
if (confirm("Вы уверены, что хотите вернуть средства по данному счету?")) {
|
||
|
|
this.isMakingCloudPaymentsRefundInProgress = true;
|
||
|
|
dataToSend = {
|
||
|
|
id: this.cloudPaymentsPaymentModalData.orderId,
|
||
|
|
refundAmount: this.cloudPaymentsPaymentModalData.refundAmount
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.urls.makeCloudPaymentsRefund,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 30000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
this.isMakingCloudPaymentsRefundInProgress = false;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status && (data.status === "success")) {
|
||
|
|
toastr.success("Возврат средств был произведен успешно.");
|
||
|
|
this.adminShowCloudPaymentsPaymentHistory(this.cloudPaymentsPaymentModalData.orderId, "", false);
|
||
|
|
return this.cloudPaymentsPaymentModalDataPromise = $interval(() => {
|
||
|
|
return this.adminShowCloudPaymentsPaymentHistory(this.cloudPaymentsPaymentModalData.orderId, "", false);
|
||
|
|
}, 2000);
|
||
|
|
} else {
|
||
|
|
if (data.warning) {
|
||
|
|
toastr.warning(data.warning);
|
||
|
|
}
|
||
|
|
if (data.error) {
|
||
|
|
return toastr.warning(data.error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
this.isMakingCloudPaymentsRefundInProgress = false;
|
||
|
|
return toastr.error(config.global_labels.defaultErrorMessage.value);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
getPaymentGatewayLabel(paymentGateway) {
|
||
|
|
var result;
|
||
|
|
result = "";
|
||
|
|
if (paymentGateway && (paymentGateway.length > 0)) {
|
||
|
|
switch (paymentGateway) {
|
||
|
|
case "Elplat":
|
||
|
|
return result = "СБП";
|
||
|
|
case "CloudPayments":
|
||
|
|
return result = "РНКБ";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.isSubmitting = false;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.isDeleteOrderSubmitting = false;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.errors = [];
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.search = "";
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.paymentStatus = "";
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.paymentGateway = "";
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.usedSearch = null;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.ordersList = [];
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.elplatPaymentModalData = {};
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.isMakingElplatRefundInProgress = false;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.cloudPaymentsPaymentModalData = {};
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.isMakingCloudPaymentsRefundInProgress = false;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.cloudPaymentsPaymentModalDataPromise = null;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.dateFromDatepicker = {
|
||
|
|
opened: false
|
||
|
|
};
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.dateFromDatepickerOptions = {
|
||
|
|
formatYear: 'yyyy',
|
||
|
|
startingDay: 1,
|
||
|
|
showWeeks: false
|
||
|
|
};
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.dateToDatepicker = {
|
||
|
|
opened: false
|
||
|
|
};
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.dateToDatepickerOptions = {
|
||
|
|
formatYear: 'yyyy',
|
||
|
|
startingDay: 1,
|
||
|
|
showWeeks: false
|
||
|
|
};
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.pagination = {
|
||
|
|
currentPage: 1,
|
||
|
|
numPerPage: 25,
|
||
|
|
totalItems: 0,
|
||
|
|
onWatchChange: (newValue,
|
||
|
|
oldValue) => {
|
||
|
|
if (newValue !== oldValue) {
|
||
|
|
return $scope.orderPayment.searchOrders();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
setPage: (page) => {
|
||
|
|
if (page !== $scope.orderPayment.pagination.currentPage) {
|
||
|
|
$scope.orderPayment.pagination.currentPage = page;
|
||
|
|
}
|
||
|
|
$scope.orderPayment.pagination.totalPages = 0;
|
||
|
|
$scope.orderPayment.ordersList = [];
|
||
|
|
return $scope.orderPayment.searchOrders();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
return orderPaymentApp;
|
||
|
|
|
||
|
|
}).call(this);
|
||
|
|
$scope.config = config;
|
||
|
|
$scope.utilities = new UtilitiesClass(config,
|
||
|
|
$filter,
|
||
|
|
$timeout);
|
||
|
|
$scope.orderPayment = new orderPaymentApp();
|
||
|
|
$scope.orderPayment.searchOrders();
|
||
|
|
$scope.$watch("orderPayment.pagination.currentPage",
|
||
|
|
$scope.orderPayment.pagination.onWatchChange);
|
||
|
|
$scope.$watch("config.sortFields.ordersList.field",
|
||
|
|
$scope.orderPayment.pagination.onWatchChange);
|
||
|
|
return $scope.$watch("config.sortFields.ordersList.direction",
|
||
|
|
$scope.orderPayment.pagination.onWatchChange);
|
||
|
|
}
|
||
|
|
]);
|