app.controller("conferenciasController", function ($scope, $modal, $rootScope, localizacaoFactory, notificationFactory) {

    $scope.selectedConferenciaErro = null;
    $scope.emExecucao = false;

    $scope.selConf = function (row) {

        if (row == null)
            return;
        $scope.selectedConferenciaErro = row;
        
    };

    $scope.deleteErrosConferencias = function (id,lst) {
        

        var successCallback = function (data, status, headers, config) {
            notificationFactory.success(data);
            selectedConferenciaErro = null;
            for (i=0; i<lst.length; i++)
            {
                if (lst[i].Id==id)
                {
                    lst.splice(i, 1);
                    break;
                }
            }
        };

        var errorCallback = function (data, status, headers, config) {
            notificationFactory.error(data);
        };

        localizacaoFactory.deleteErrosConferencias(id).success(successCallback).error(errorCallback);
    };

    $scope.corrigirLocal = function (erro, lst) {


        var successCallback = function (data, status, headers, config) {
            //$scope.emExecucao = false;
            notificationFactory.success(data);
            selectedConferenciaErro = null;
            for (i = 0; i < lst.length; i++) {
                if (lst[i].Id == erro.Id) {
                    lst.splice(i, 1);
                    break;
                }
            }
        };

        var errorCallback = function (data, status, headers, config) {
            notificationFactory.error(data);
            //$scope.emExecucao = false;
        };

        var inv={
            FK_Edificio: erro.FK_Edificio,
            FK_Piso: erro.FK_Piso,
            FK_Sala: erro.FK_Sala,
            Pk_Inventario: erro.FK_Inventario,
            IdErro: erro.Id
        };

        $scope.emExecucao = true;
        localizacaoFactory.updateLocal(inv).success(successCallback).error(errorCallback);
    };

});



