<commit_before>/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
miAppHome.controller('DistribucionController', function ($scope, localStorageService, $rootScope, _productoService, NgTableParams, ngDialog, toaster, $timeout, facturaProductoService, $state, $stateParams, distribucionService) {

    $scope.alerts = [];
    $scope.modalDistribuir = {
        tierra: null,
        bebelandia: null,
        libertador: null
    };
    $scope.wrapper = {
        "stockTierra": {
            "idStock": null,
            "cantidad": null,
            "idProducto": null,
            "estado": true,
            "usuarioCreacion": null,
            "usuarioModificacion": null,
            "fechaCreacion": null,
            "fechaModificacion": null,
            "idSucursal": null
        },
        "stockBebelandia": {
            "idStock": null,
            "cantidad": null,
            "idProducto": null,
            "estado": true,
            "usuarioCreacion": null,
            "usuarioModificacion": null,
            "fechaCreacion": null,
            "fechaModificacion": null,
            "idSucursal": null
        },
        "stockLibertador": {
            "idStock": null,
            "cantidad": null,
            "idProducto": null,
            "estado": true,
            "usuarioCreacion": null,
            "usuarioModificacion": null,
            "fechaCreacion": null,
            "fechaModificacion": null,
            "idSucursal": null
        }};

    $scope.detallesFacturaProductoDistribucion = function () {
        var idFacturaProducto = parseInt($stateParams.idFactura);
        $detail = facturaProductoService.detail(idFacturaProducto);
        $detail.then(function (datos) {
            if (datos.status === 200) {
                $scope.detalle = datos.data;
            }
        });
    };

    $scope.listaTierra = function () {
        $tierra = distribucionService.getAll(1);
        $tierra.then(function (datos) {
            var data = datos.data;
            $scope.tierraStock = datos.data;
            $scope.tableTierraStock = new NgTableParams({
                page: 1,
                count: 11
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.tierraStock;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.listaBebelandia = function () {
        $tierra = distribucionService.getAll(2);
        $tierra.then(function (datos) {
            var data = datos.data;
            $scope.bebelandiaStock = datos.data;
            $scope.tableBebelandiaStock = new NgTableParams({
                page: 1,
                count: 11
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.bebelandiaStock;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.listaLibertador = function () {
        $tierra = distribucionService.getAll(3);
        $tierra.then(function (datos) {
            var data = datos.data;
            $scope.libertadorStock = datos.data;
            $scope.tableLibertadorStock = new NgTableParams({
                page: 1,
                count: 11
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.libertadorStock;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.listaFacturaTierra = function () {
        var idFactura = $stateParams.idFactura;
        $facturaTierra = distribucionService.getStockTierra(idFactura);
        $facturaTierra.then(function (datos) {
            $scope.facturaTierra = datos.data;
            var data = datos;
            $scope.tableFacturaTierra = new NgTableParams({
                page: 1,
                count: 8
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.facturaTierra;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.listaFacturaBebelandia = function () {
        var idFactura = $stateParams.idFactura;
        $facturaBebelandia = distribucionService.getStockBebelandia(idFactura);
        $facturaBebelandia.then(function (datos) {
            var data = datos.data;
            $scope.facturaBebelandia = datos.data;
            $scope.tableFacturaBebelandia = new NgTableParams({
                page: 1,
                count: 10
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.facturaBebelandia;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.listaFacturaLibertador = function () {
        var idFactura = $stateParams.idFactura;
        $facturaLibertador = distribucionService.getStockLibertador(idFactura);
        $facturaLibertador.then(function (datos) {
            var data = datos.data;
            $scope.facturaLibertador = datos.data;
            $scope.tableFacturaLibertador = new NgTableParams({
                page: 1,
                count: 10
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.facturaLibertador;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.distribuirModal = function (producto) {
        $rootScope.modalProducto = producto;
        ngDialog.open({
            template: 'views/distribucion/modal-distribuir-stock.html',<commit_msg>metodos para paginacion de stock por sucursal<commit_after>/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
miAppHome.controller('DistribucionController', function (
        $scope,
        $http,
        BaseURL,
        cookieService,
        $rootScope,
        _productoService,
        NgTableParams,
        ngDialog,
        toaster,
        $timeout,
        facturaProductoService,
        $state,
        $stateParams,
        distribucionService) {

    $scope.alerts = [];
    $scope.modalDistribuir = {
        tierra: null,
        bebelandia: null,
        libertador: null
    };
    $scope.wrapper = {
        "stockTierra": {
            "idStock": null,
            "cantidad": null,
            "idProducto": null,
            "estado": true,
            "usuarioCreacion": null,
            "usuarioModificacion": null,
            "fechaCreacion": null,
            "fechaModificacion": null,
            "idSucursal": null
        },
        "stockBebelandia": {
            "idStock": null,
            "cantidad": null,
            "idProducto": null,
            "estado": true,
            "usuarioCreacion": null,
            "usuarioModificacion": null,
            "fechaCreacion": null,
            "fechaModificacion": null,
            "idSucursal": null
        },
        "stockLibertador": {
            "idStock": null,
            "cantidad": null,
            "idProducto": null,
            "estado": true,
            "usuarioCreacion": null,
            "usuarioModificacion": null,
            "fechaCreacion": null,
            "fechaModificacion": null,
            "idSucursal": null
        }};

    $scope.detallesFacturaProductoDistribucion = function () {
        var idFacturaProducto = parseInt($stateParams.idFactura);
        $detail = facturaProductoService.detail(idFacturaProducto);
        $detail.then(function (datos) {
            if (datos.status === 200) {
                $scope.detalle = datos.data;
            }
        });
    };

    $scope.listaTierraDEPRECATED = function () {
        $tierra = distribucionService.getAll(1);
        $tierra.then(function (datos) {
            var data = datos.data;
            $scope.tierraStock = datos.data;
            $scope.tableTierraStock = new NgTableParams({
                page: 1,
                count: 12
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.tierraStock;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };
    $scope.listaTierra = function () {
        var token = cookieService.get('token');
        token.then(function (data) {
            $scope.tableTierraStock = new NgTableParams({
                page: 1,
                count: 12
            }, {
                getData: function (params) {
                    return $http({
                        url: BaseURL + "stock/list/paged",
                        method: 'get',
                        headers: {
                            'Authorization': 'Bearer ' + data,
                            'Content-type': 'application/json'
                        },
                        params: {
                            idStock: 1,
                            page: params.page() - 1,
                            size: params.count()
                        }
                    }).then(function successCallback(response) {
                        params.total(response.data.totalElements);
                        return response.data.content;
                    }, function errorCallback(response) {
                    });
                }
            });
        });
    };

    $scope.listaBebelandia = function () {
        var token = cookieService.get('token');
        token.then(function (data) {
            $scope.tableBebelandiaStock = new NgTableParams({
                page: 1,
                count: 12
            }, {
                getData: function (params) {
                    return $http({
                        url: BaseURL + "stock/list/paged",
                        method: 'get',
                        headers: {
                            'Authorization': 'Bearer ' + data,
                            'Content-type': 'application/json'
                        },
                        params: {
                            idStock: 2,
                            page: params.page() - 1,
                            size: params.count()
                        }
                    }).then(function successCallback(response) {
                        params.total(response.data.totalElements);
                        return response.data.content;
                    }, function errorCallback(response) {
                    });
                }
            });
        });
    };

    $scope.listaLibertador = function () {
        var token = cookieService.get('token');
        token.then(function (data) {
            $scope.tableLibertadorStock = new NgTableParams({
                page: 1,
                count: 12
            }, {
                getData: function (params) {
                    return $http({
                        url: BaseURL + "stock/list/paged",
                        method: 'get',
                        headers: {
                            'Authorization': 'Bearer ' + data,
                            'Content-type': 'application/json'
                        },
                        params: {
                            idStock: 3,
                            page: params.page() - 1,
                            size: params.count()
                        }
                    }).then(function successCallback(response) {
                        params.total(response.data.totalElements);
                        return response.data.content;
                    }, function errorCallback(response) {
                    });
                }
            });
        });
    };

    $scope.listaFacturaTierra = function () {
        var idFactura = $stateParams.idFactura;
        $facturaTierra = distribucionService.getStockTierra(idFactura);
        $facturaTierra.then(function (datos) {
            $scope.facturaTierra = datos.data;
            var data = datos;
            $scope.tableFacturaTierra = new NgTableParams({
                page: 1,
                count: 13
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.facturaTierra;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.listaFacturaBebelandia = function () {
        var idFactura = $stateParams.idFactura;
        $facturaBebelandia = distribucionService.getStockBebelandia(idFactura);
        $facturaBebelandia.then(function (datos) {
            var data = datos.data;
            $scope.facturaBebelandia = datos.data;
            $scope.tableFacturaBebelandia = new NgTableParams({
                page: 1,
                count: 13
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.facturaBebelandia;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.listaFacturaLibertador = function () {
        var idFactura = $stateParams.idFactura;
        $facturaLibertador = distribucionService.getStockLibertador(idFactura);
        $facturaLibertador.then(function (datos) {
            var data = datos.data;
            $scope.facturaLibertador = datos.data;
            $scope.tableFacturaLibertador = new NgTableParams({
                page: 1,
                count: 13
            }, {
                total: data.length,
                getData: function (params) {
                    data = $scope.facturaLibertador;
                    params.total(data.length);
                    if (params.total() <= ((params.page() - 1) * params.count())) {
                        params.page(1);
                    }
                    return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                }});
        });
    };

    $scope.distribuirModal = function (producto) {
        $rootScope.modalProducto = producto;
        ngDialog.open({
            template: 'views/distribucion/modal-distribuir-stock.html',
{'fraction_non_alphanumeric': 0.11695555688838241, 'fraction_numerical': 0.00503808552749955, 'mean_word_length': 1.3135840155404468, 'pattern_counts': {'":': 60, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6266656', 'n_tokens_mistral': 4609, 'n_tokens_neox': 4338, 'n_words': 798}