(function() {
    'use strict';
    angular.module('Monitour.pages.payment').controller('PaymentCtrl', PaymentCtrl);

    /** @ngInject */
    function PaymentCtrl($scope, baConfig, $filter, colorHelper, $http, $localStorage, $state, SweetAlert, $translate, $stateParams, PaymentService, InvoiceService) {
        var vm = this;
        var id = $stateParams.id;

        // Initialize vm.invoice and vm.details
        vm.invoice = null;
        vm.details = null;

        // Get the invoice by its ID
        InvoiceService.GetById(id).then(function(response) {
            vm.invoice = response.data[0];
            console.log(vm.invoice);

            // Once invoice is received, get the payment details using vm.invoice.id
            var paymentId = vm.invoice.id;
            PaymentService.GetById(paymentId).then(function(response) {
                vm.payment = response.data[0];
                console.log(vm.payment);
            }, function(error) {
                // Handle error in getting payment details
                $scope.error = 'unable to get the payment details';
            });

        }, function(error) {
            // Handle error in getting invoice details
            $scope.error = 'unable to get the invoice details';
        });


        
    }
})();
