diff --git a/src/js/controller.js b/src/js/controller.js index fd160ea..0c3d7ea 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,10 +1,11 @@ angular.module('focaCrearFactura').controller('facturaController', [ '$scope', '$uibModal', '$location', '$filter', 'crearFacturaService', '$timeout', 'focaModalService', 'crearRemitoService', '$rootScope', 'focaBotoneraLateralService', - '$localStorage', 'APP', + '$localStorage', 'APP', 'focaLoginService', function ( $scope, $uibModal, $location, $filter, crearFacturaService, $timeout, focaModalService, - crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP) { + crearRemitoService, $rootScope, focaBotoneraLateralService, $localStorage, APP, loginServ) + { config(); @@ -88,6 +89,33 @@ angular.module('focaCrearFactura').controller('facturaController', [ ); $scope.inicial = angular.copy($scope.factura); + + if (APP == 'facturador') { + crearFacturaService + .getVendedorPlayaById(loginServ.getLoginData().vendedorPlaya) + .then(function (res) { + + validarPlanillaVendedor(res.data) + .then(function () { + + $scope.$broadcast('addCabecera', { + label: 'Vendedor:', + valor: $filter('rellenarDigitos')(res.data.CodVen, 3) + + ' - ' + + res.data.NomVen + }); + + $scope.factura.vendedor = res.data; + + getProductosByPlanilla(res.data.NplVen); + }) + .catch(function (err) { + console.log(err); + focaModalService.alert('Ocurrió un error al intentar recuperar' + + 'el vendedor logeado'); + }); + }) + } } $scope.$watch('factura', function (newValue) { @@ -643,7 +671,7 @@ angular.module('focaCrearFactura').controller('facturaController', [ return new Promise(function (resolve, reject) { crearFacturaService - .validarPlanillaVendedor(vendedor.CodVen.trim()) + .validarPlanillaVendedor(vendedor.CodVen.toString().trim()) .then(function (res) { if (!res.data.length) { @@ -657,7 +685,10 @@ angular.module('focaCrearFactura').controller('facturaController', [ } }) - .catch(reject); + .catch(function (err) { + console.log(err) + reject(); + }); }); } diff --git a/src/js/service.js b/src/js/service.js index 6dd06df..f7e4cbc 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -1,6 +1,6 @@ angular.module('focaCrearFactura') - .service('crearFacturaService', ['$http', 'API_ENDPOINT', - function ($http, API_ENDPOINT) { + .service('crearFacturaService', ['$http', 'API_ENDPOINT', 'APP', + function ($http, API_ENDPOINT, APP) { var route = API_ENDPOINT.URL; return { guardarFactura: function (factura) { @@ -22,14 +22,18 @@ angular.module('focaCrearFactura') return $http.post(route + '/turnos/depacho-sin-uso', parametros); }, getResumenCuenta: function (idCliente) { - return $http.get(API_ENDPOINT + '/cliente/resumen-cuenta/' + idCliente); + return $http.get(route + '/cliente/resumen-cuenta/' + idCliente); + }, + getVendedorPlayaById: function (id) { + return $http.get(route + '/vendedor-playa/' + id); }, getBotonera: function () { - return [ - { - label: 'Vendedor', - image: 'vendedor.png' - }, + var vendedor = { + label: 'Vendedor', + image: 'vendedor.png' + }; + + var botones = [ { label: 'Cliente', image: 'cliente.png' @@ -43,6 +47,12 @@ angular.module('focaCrearFactura') image: 'botonObservaciones.png' } ]; + + if (APP != 'facturador') { + botones.unshift(vendedor); + } + + return botones; } }; }