app.controller('DeclineQuotationCtrl', function($scope, $http, $routeParams) { // Initialize $scope.init = function() { $scope.declineReasons = []; // $scope.competitor = null; $scope.declineReason = null; $scope.competitorReason = null; // Get the decline reasons var req = { method: 'GET', url: '/decline_reason/get', } $http(req).then(function(response) { // If status true send to the dashboard page if (response.data.status) { // OK $scope.declineReasons = response.data.data; } // Failed? Give an error message else { // Wrong data swal("Helaas", "Het afwijsformulier kon niet geladen worden.", "error"); } }); } $scope.init(); // The quotation is declined $scope.decline = function(declineOkFunction) { // Data check if ($routeParams.hash) { var hash = $routeParams.hash; } else if ($scope.hash) { var hash = $scope.hash; } if (hash) { // Check the data if ($scope.declineData.main_reason && $scope.declineData.main_reason.id) { var req = { method: 'POST', url: '/quotation/decline/' + hash, data: { reason: JSON.stringify($scope.declineData), } } $http(req).then(function(response) { // If status true send to the dashboard page if (response.data.status) { // OK. Hide the modal $('#declineModal').modal('hide'); swal("Offerte afgewezen", "Dank voor uw bericht.", "success"); // $scope.rawQuotation.header.status = 'Geweigerd'; if (typeof declineOkFunction === 'function') { declineOkFunction(); } } // Failed? Give an error message else { // Wrong data swal("Helaas", "Het afwijzen is mislukt.", "error"); } }); } else { $scope.declineMsg = 'Gelieve een reden op te geven.'; } } else { swal('Fout', 'Er is een technische fout:\nHet offerte ID is niet bekend.','error'); } } })