Commit 71682e427865e9b41d088004fca7aba6b1359d30
Exists in
master
and in
1 other branch
Merge branch 'master' into 'develop'
Master(benjamin) See merge request !130
Showing
2 changed files
Show diff stats
index.html
| 1 | <html ng-app="focaCrearNotaPedido"> | 1 | <html ng-app="focaCrearNotaPedido"> |
| 2 | <head> | 2 | <head> |
| 3 | <meta charset="UTF-8"/> | 3 | <meta charset="UTF-8"/> |
| 4 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | 4 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
| 5 | 5 | ||
| 6 | <!--CSS--> | 6 | <!--CSS--> |
| 7 | <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/> | 7 | <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/> |
| 8 | <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet"/> | 8 | <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet"/> |
| 9 | <link href="node_modules/ladda/dist/ladda-themeless.min.css" rel="stylesheet"> | 9 | <link href="node_modules/ladda/dist/ladda-themeless.min.css" rel="stylesheet"> |
| 10 | 10 | ||
| 11 | <!--VENDOR JS--> | 11 | <!--VENDOR JS--> |
| 12 | <script src="node_modules/jquery/dist/jquery.min.js"></script> | 12 | <script src="node_modules/jquery/dist/jquery.min.js"></script> |
| 13 | <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> | 13 | <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> |
| 14 | <script src="node_modules/angular/angular.min.js"></script> | 14 | <script src="node_modules/angular/angular.min.js"></script> |
| 15 | <script src="node_modules/angular-route/angular-route.min.js"></script> | 15 | <script src="node_modules/angular-route/angular-route.min.js"></script> |
| 16 | <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script> | 16 | <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script> |
| 17 | <script src="node_modules/ladda/dist/spin.min.js"></script> | 17 | <script src="node_modules/ladda/dist/spin.min.js"></script> |
| 18 | <script src="node_modules/ladda/dist/ladda.min.js"></script> | 18 | <script src="node_modules/ladda/dist/ladda.min.js"></script> |
| 19 | <script src="node_modules/angular-ladda/dist/angular-ladda.min.js"></script> | 19 | <script src="node_modules/angular-ladda/dist/angular-ladda.min.js"></script> |
| 20 | <script src="vendor/cordovaGeolocationModule.min.js"></script> | 20 | <script src="vendor/cordovaGeolocationModule.min.js"></script> |
| 21 | 21 | ||
| 22 | <script src="node_modules/foca-directivas/dist/foca-directivas.min.js"></script> | 22 | <script src="node_modules/foca-directivas/dist/foca-directivas.min.js"></script> |
| 23 | <script src="node_modules/foca-botonera-facturador/dist/foca-botonera-facturador.min.js"></script> | 23 | <script src="node_modules/foca-botonera-facturador/dist/foca-botonera-facturador.min.js"></script> |
| 24 | <script src="node_modules/foca-modal-vendedores/dist/foca-modal-vendedores.min.js"></script> | 24 | <script src="node_modules/foca-modal-vendedores/dist/foca-modal-vendedores.min.js"></script> |
| 25 | <script src="node_modules/foca-modal-busqueda-productos/dist/foca-busqueda-productos.min.js"></script> | 25 | <script src="node_modules/foca-modal-busqueda-productos/dist/foca-busqueda-productos.min.js"></script> |
| 26 | <script src="node_modules/foca-modal-proveedor/dist/foca-modal-proveedor.min.js"></script> | 26 | <script src="node_modules/foca-modal-proveedor/dist/foca-modal-proveedor.min.js"></script> |
| 27 | <script src="node_modules/foca-busqueda-cliente/dist/foca-busqueda-cliente.min.js"></script> | 27 | <script src="node_modules/foca-busqueda-cliente/dist/foca-busqueda-cliente.min.js"></script> |
| 28 | <script src="node_modules/foca-modal-precio-condiciones/dist/foca-modal-precio-condiciones.min.js"></script> | 28 | <script src="node_modules/foca-modal-precio-condiciones/dist/foca-modal-precio-condiciones.min.js"></script> |
| 29 | <script src="node_modules/foca-modal-flete/dist/foca-modal-flete.min.js"></script> | 29 | <script src="node_modules/foca-modal-flete/dist/foca-modal-flete.min.js"></script> |
| 30 | <script src="node_modules/foca-modal/dist/foca-modal.min.js"></script> | 30 | <script src="node_modules/foca-modal/dist/foca-modal.min.js"></script> |
| 31 | <script src="node_modules/foca-modal-domicilio/dist/foca-modal-domicilios.min.js"></script> | 31 | <script src="node_modules/foca-modal-domicilio/dist/foca-modal-domicilio.min.js"></script> |
| 32 | <script src="node_modules/foca-modal-moneda/dist/foca-modal-moneda.min.js"></script> | 32 | <script src="node_modules/foca-modal-moneda/dist/foca-modal-moneda.min.js"></script> |
| 33 | <script src="node_modules/foca-modal-cotizacion/dist/foca-modal-cotizacion.min.js"></script> | 33 | <script src="node_modules/foca-modal-cotizacion/dist/foca-modal-cotizacion.min.js"></script> |
| 34 | <script src="node_modules/foca-seguimiento/dist/foca-seguimiento.min.js"></script> | 34 | <script src="node_modules/foca-seguimiento/dist/foca-seguimiento.min.js"></script> |
| 35 | 35 | ||
| 36 | <script src="src/js/app.js"></script> | 36 | <script src="src/js/app.js"></script> |
| 37 | <script src="src/js/controller.js"></script> | 37 | <script src="src/js/controller.js"></script> |
| 38 | <script src="src/js/service.js"></script> | 38 | <script src="src/js/service.js"></script> |
| 39 | <script src="src/js/businessService.js"></script> | 39 | <script src="src/js/businessService.js"></script> |
| 40 | <script src="src/js/route.js"></script> | 40 | <script src="src/js/route.js"></script> |
| 41 | 41 | ||
| 42 | <script src="src/etc/develop.js"></script> | 42 | <script src="src/etc/develop.js"></script> |
| 43 | </head> | 43 | </head> |
| 44 | <body> | 44 | <body> |
| 45 | <div ng-view class="container-fluid"></div> | 45 | <div ng-view class="container-fluid"></div> |
| 46 | </body> | 46 | </body> |
| 47 | </html> | 47 | </html> |
| 48 | 48 |
src/js/controller.js
| 1 | angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido').controller('notaPedidoCtrl', |
| 2 | [ | 2 | [ |
| 3 | '$scope', | 3 | '$scope', |
| 4 | '$uibModal', | 4 | '$uibModal', |
| 5 | '$location', | 5 | '$location', |
| 6 | '$filter', | 6 | '$filter', |
| 7 | '$timeout', | 7 | '$timeout', |
| 8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
| 9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
| 10 | 'focaModalService', | 10 | 'focaModalService', |
| 11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
| 12 | '$rootScope', | 12 | '$rootScope', |
| 13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
| 14 | 'APP', | 14 | 'APP', |
| 15 | 'focaLoginService', | 15 | 'focaLoginService', |
| 16 | '$localStorage', | 16 | '$localStorage', |
| 17 | function ( | 17 | function ( |
| 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, | 18 | $scope, $uibModal, $location, $filter, $timeout, crearNotaPedidoService, |
| 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, | 19 | focaBotoneraLateralService, focaModalService, notaPedidoBusinessService, |
| 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) { | 20 | $rootScope, focaSeguimientoService, APP, focaLoginService, $localStorage) { |
| 21 | config(); | 21 | config(); |
| 22 | var cotizacionPArgentino = {}; | 22 | var cotizacionPArgentino = {}; |
| 23 | 23 | ||
| 24 | function config() { | 24 | function config() { |
| 25 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA | 25 | // PARAMETROS INICIALES PARA FUNCIONAMIENTO DEL PROGRAMA |
| 26 | $scope.tmpCantidad = Number; | 26 | $scope.tmpCantidad = Number; |
| 27 | $scope.tmpPrecio = Number; | 27 | $scope.tmpPrecio = Number; |
| 28 | $scope.notaPedido = {}; | 28 | $scope.notaPedido = {}; |
| 29 | $scope.isNumber = angular.isNumber; | 29 | $scope.isNumber = angular.isNumber; |
| 30 | $scope.datepickerAbierto = false; | 30 | $scope.datepickerAbierto = false; |
| 31 | $scope.show = false; | 31 | $scope.show = false; |
| 32 | $scope.cargando = true; | 32 | $scope.cargando = true; |
| 33 | $scope.cabeceras = []; | 33 | $scope.cabeceras = []; |
| 34 | $scope.botonera = crearNotaPedidoService.getBotonera(); | 34 | $scope.botonera = crearNotaPedidoService.getBotonera(); |
| 35 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); | 35 | $scope.puntoVenta = $filter('rellenarDigitos')(0, 4); |
| 36 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); | 36 | $scope.comprobante = $filter('rellenarDigitos')(0, 8); |
| 37 | $scope.dateOptions = { | 37 | $scope.dateOptions = { |
| 38 | maxDate: new Date(), | 38 | maxDate: new Date(), |
| 39 | minDate: new Date(2010, 0, 1) | 39 | minDate: new Date(2010, 0, 1) |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | //SETEO BOTONERA LATERAL | 42 | //SETEO BOTONERA LATERAL |
| 43 | $timeout(function () { | 43 | $timeout(function () { |
| 44 | focaBotoneraLateralService.showSalir(false); | 44 | focaBotoneraLateralService.showSalir(false); |
| 45 | focaBotoneraLateralService.showPausar(true); | 45 | focaBotoneraLateralService.showPausar(true); |
| 46 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); | 46 | focaBotoneraLateralService.showGuardar(true, $scope.crearNotaPedido); |
| 47 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 47 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 48 | }); | 48 | }); |
| 49 | 49 | ||
| 50 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR | 50 | // SETEA BOTONERA DE FACTURADOR TENIENDO EN CUENTA SI ESTA SETEADO EL VENDEDOR |
| 51 | if (APP === 'distribuidor') { | 51 | if (APP === 'distribuidor') { |
| 52 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; | 52 | $scope.idVendedor = focaLoginService.getLoginData().vendedorCobrador; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | crearNotaPedidoService.getParametros().then(function (res) { | 55 | crearNotaPedidoService.getParametros().then(function (res) { |
| 56 | var parametros = JSON.parse(res.data[0].jsonText); | 56 | var parametros = JSON.parse(res.data[0].jsonText); |
| 57 | if ($localStorage.notaPedido) { | 57 | if ($localStorage.notaPedido) { |
| 58 | $timeout(function () { getLSNotaPedido(); }); | 58 | $timeout(function () { getLSNotaPedido(); }); |
| 59 | } else { | 59 | } else { |
| 60 | for (var property in parametros) { | 60 | for (var property in parametros) { |
| 61 | $scope.notaPedido[property] = parametros[property]; | 61 | $scope.notaPedido[property] = parametros[property]; |
| 62 | $scope.inicial[property] = parametros[property]; | 62 | $scope.inicial[property] = parametros[property]; |
| 63 | } | 63 | } |
| 64 | setearNotaPedido($scope.notaPedido); | 64 | setearNotaPedido($scope.notaPedido); |
| 65 | } | 65 | } |
| 66 | }); | 66 | }); |
| 67 | 67 | ||
| 68 | init(); | 68 | init(); |
| 69 | 69 | ||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | function init() { | 72 | function init() { |
| 73 | $scope.$broadcast('cleanCabecera'); | 73 | $scope.$broadcast('cleanCabecera'); |
| 74 | 74 | ||
| 75 | $scope.notaPedido = { | 75 | $scope.notaPedido = { |
| 76 | id: 0, | 76 | id: 0, |
| 77 | cliente: {}, | 77 | cliente: {}, |
| 78 | proveedor: {}, | 78 | proveedor: {}, |
| 79 | domicilio: { dom: '' }, | 79 | domicilio: { dom: '' }, |
| 80 | vendedor: {}, | 80 | vendedor: {}, |
| 81 | fechaCarga: new Date(), | 81 | fechaCarga: new Date(), |
| 82 | cotizacion: {}, | 82 | cotizacion: {}, |
| 83 | articulosNotaPedido: [], | 83 | articulosNotaPedido: [], |
| 84 | notaPedidoPlazo: [], | 84 | notaPedidoPlazo: [], |
| 85 | notaPedidoPuntoDescarga: [] | 85 | notaPedidoPuntoDescarga: [] |
| 86 | 86 | ||
| 87 | }; | 87 | }; |
| 88 | $scope.idLista = undefined; | 88 | $scope.idLista = undefined; |
| 89 | 89 | ||
| 90 | crearNotaPedidoService.getNumeroNotaPedido().then( | 90 | crearNotaPedidoService.getNumeroNotaPedido().then( |
| 91 | function (res) { | 91 | function (res) { |
| 92 | $scope.puntoVenta = $filter('rellenarDigitos')( | 92 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 93 | res.data.sucursal, 4 | 93 | res.data.sucursal, 4 |
| 94 | ); | 94 | ); |
| 95 | 95 | ||
| 96 | $scope.comprobante = $filter('rellenarDigitos')( | 96 | $scope.comprobante = $filter('rellenarDigitos')( |
| 97 | res.data.numeroNotaPedido, 8 | 97 | res.data.numeroNotaPedido, 8 |
| 98 | ); | 98 | ); |
| 99 | }, | 99 | }, |
| 100 | function (err) { | 100 | function (err) { |
| 101 | focaModalService.alert('La terminal no esta configurada correctamente'); | 101 | focaModalService.alert('La terminal no esta configurada correctamente'); |
| 102 | console.info(err); | 102 | console.info(err); |
| 103 | } | 103 | } |
| 104 | ); | 104 | ); |
| 105 | 105 | ||
| 106 | if (APP === 'distribuidor') { | 106 | if (APP === 'distribuidor') { |
| 107 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( | 107 | crearNotaPedidoService.getVendedorById($scope.idVendedor).then( |
| 108 | function (res) { | 108 | function (res) { |
| 109 | var vendedor = res.data; | 109 | var vendedor = res.data; |
| 110 | $scope.$broadcast('addCabecera', { | 110 | $scope.$broadcast('addCabecera', { |
| 111 | label: 'Vendedor:', | 111 | label: 'Vendedor:', |
| 112 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 112 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 113 | vendedor.NOM | 113 | vendedor.NOM |
| 114 | }); | 114 | }); |
| 115 | 115 | ||
| 116 | $scope.notaPedido.vendedor = vendedor; | 116 | $scope.notaPedido.vendedor = vendedor; |
| 117 | $scope.inicial.vendedor = $scope.notaPedido.vendedor; | 117 | $scope.inicial.vendedor = $scope.notaPedido.vendedor; |
| 118 | } | 118 | } |
| 119 | ); | 119 | ); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | $scope.inicial = angular.copy($scope.notaPedido); | 122 | $scope.inicial = angular.copy($scope.notaPedido); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | $scope.$watch('notaPedido', function (newValue) { | 125 | $scope.$watch('notaPedido', function (newValue) { |
| 126 | focaBotoneraLateralService.setPausarData({ | 126 | focaBotoneraLateralService.setPausarData({ |
| 127 | label: 'notaPedido', | 127 | label: 'notaPedido', |
| 128 | val: newValue | 128 | val: newValue |
| 129 | }); | 129 | }); |
| 130 | }, true); | 130 | }, true); |
| 131 | 131 | ||
| 132 | $scope.$watch('NotaPedido', function (newValue) { | 132 | $scope.$watch('NotaPedido', function (newValue) { |
| 133 | focaBotoneraLateralService.setPausarData({ | 133 | focaBotoneraLateralService.setPausarData({ |
| 134 | label: 'notaPedido', | 134 | label: 'notaPedido', |
| 135 | val: newValue | 135 | val: newValue |
| 136 | }); | 136 | }); |
| 137 | focaBotoneraLateralService.setRutasPausadas({ | 137 | focaBotoneraLateralService.setRutasPausadas({ |
| 138 | label: 'rutas', | 138 | label: 'rutas', |
| 139 | val: 'venta-nota-pedido/crear' | 139 | val: 'venta-nota-pedido/crear' |
| 140 | }); | 140 | }); |
| 141 | }, true); | 141 | }, true); |
| 142 | 142 | ||
| 143 | $scope.crearNotaPedido = function () { | 143 | $scope.crearNotaPedido = function () { |
| 144 | if (!$scope.notaPedido.cliente.COD) { | 144 | if (!$scope.notaPedido.cliente.COD) { |
| 145 | focaModalService.alert('Ingrese Cliente'); | 145 | focaModalService.alert('Ingrese Cliente'); |
| 146 | return; | 146 | return; |
| 147 | } | 147 | } |
| 148 | if (!$scope.notaPedido.vendedor.id) { | 148 | |
| 149 | focaModalService.alert('Este cliente no tiene vendedor asignado'); | 149 | // Se crearon comentarios en las restricciones de vendedor para las bases |
| 150 | return; | 150 | // de datos que no poseen vendedor asignado a los clientes despues |
| 151 | } else if ($scope.notaPedido.idRemito === -1) { | 151 | // descomentar en (crear-nota-pedido, modal-nota-pedido, crear-remito y modal-remito) |
| 152 | // if (!$scope.notaPedido.vendedor.id) { | ||
| 153 | // focaModalService.alert('Este cliente no tiene vendedor asignado'); | ||
| 154 | // return; | ||
| 155 | if ($scope.notaPedido.idRemito === -1) { | ||
| 152 | focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); | 156 | focaBotoneraLateralService.alert('No se puede modificar esta nota de pedido'); |
| 153 | return; | 157 | return; |
| 154 | } else if (!$scope.notaPedido.proveedor.COD) { | 158 | } else if (!$scope.notaPedido.proveedor.COD) { |
| 155 | focaModalService.alert('Ingrese Proveedor'); | 159 | focaModalService.alert('Ingrese Proveedor'); |
| 156 | return; | 160 | return; |
| 157 | } else if (!$scope.notaPedido.cotizacion.ID) { | 161 | } else if (!$scope.notaPedido.cotizacion.ID) { |
| 158 | focaModalService.alert('Ingrese Cotización'); | 162 | focaModalService.alert('Ingrese Cotización'); |
| 159 | return; | 163 | return; |
| 160 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { | 164 | } else if (!$scope.notaPedido.cotizacion.moneda.ID) { |
| 161 | focaModalService.alert('Ingrese Moneda'); | 165 | focaModalService.alert('Ingrese Moneda'); |
| 162 | return; | 166 | return; |
| 163 | } else if (!$scope.notaPedido.notaPedidoPlazo) { | 167 | } else if (!$scope.notaPedido.notaPedidoPlazo) { |
| 164 | focaModalService.alert('Ingrese Precios y Condiciones'); | 168 | focaModalService.alert('Ingrese Precios y Condiciones'); |
| 165 | return; | 169 | return; |
| 166 | } else if ( | 170 | } else if ( |
| 167 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) { | 171 | $scope.notaPedido.flete === undefined || $scope.notaPedido.flete === null) { |
| 168 | focaModalService.alert('Ingrese Flete'); | 172 | focaModalService.alert('Ingrese Flete'); |
| 169 | return; | 173 | return; |
| 170 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto | 174 | } else if (!$scope.notaPedido.domicilioStamp) {//TODO validar domicilio correcto |
| 171 | focaModalService.alert('Ingrese Domicilio'); | 175 | focaModalService.alert('Ingrese Domicilio'); |
| 172 | return; | 176 | return; |
| 173 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { | 177 | } else if ($scope.notaPedido.articulosNotaPedido.length === 0) { |
| 174 | focaModalService.alert('Debe cargar al menos un articulo'); | 178 | focaModalService.alert('Debe cargar al menos un articulo'); |
| 175 | return; | 179 | return; |
| 176 | } | 180 | } |
| 177 | 181 | ||
| 178 | focaBotoneraLateralService.startGuardar(); | 182 | focaBotoneraLateralService.startGuardar(); |
| 179 | $scope.saveLoading = true; | 183 | $scope.saveLoading = true; |
| 180 | var notaPedido = { | 184 | var notaPedido = { |
| 181 | id: $scope.notaPedido.id, | 185 | id: $scope.notaPedido.id, |
| 182 | fechaCarga: new Date($scope.notaPedido.fechaCarga) | 186 | fechaCarga: new Date($scope.notaPedido.fechaCarga) |
| 183 | .toISOString().slice(0, 19).replace('T', ' '), | 187 | .toISOString().slice(0, 19).replace('T', ' '), |
| 184 | idVendedor: $scope.notaPedido.vendedor.id, | 188 | // idVendedor: $scope.notaPedido.vendedor.id, |
| 185 | idCliente: $scope.notaPedido.cliente.COD, | 189 | idCliente: $scope.notaPedido.cliente.COD, |
| 186 | nombreCliente: $scope.notaPedido.cliente.NOM, | 190 | nombreCliente: $scope.notaPedido.cliente.NOM, |
| 187 | cuitCliente: $scope.notaPedido.cliente.CUIT, | 191 | cuitCliente: $scope.notaPedido.cliente.CUIT, |
| 188 | idProveedor: $scope.notaPedido.proveedor.COD, | 192 | idProveedor: $scope.notaPedido.proveedor.COD, |
| 189 | idDomicilio: $scope.notaPedido.domicilio.id, | 193 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 190 | idCotizacion: $scope.notaPedido.cotizacion.ID, | 194 | idCotizacion: $scope.notaPedido.cotizacion.ID, |
| 191 | idListaPrecio: $scope.idLista, | 195 | idListaPrecio: $scope.idLista, |
| 192 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 196 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 193 | flete: $scope.notaPedido.flete, | 197 | flete: $scope.notaPedido.flete, |
| 194 | fob: $scope.notaPedido.fob, | 198 | fob: $scope.notaPedido.fob, |
| 195 | bomba: $scope.notaPedido.bomba, | 199 | bomba: $scope.notaPedido.bomba, |
| 196 | kilometros: $scope.notaPedido.kilometros, | 200 | kilometros: $scope.notaPedido.kilometros, |
| 197 | domicilioStamp: $scope.notaPedido.domicilioStamp, | 201 | domicilioStamp: $scope.notaPedido.domicilioStamp, |
| 198 | observaciones: $scope.notaPedido.observaciones, | 202 | observaciones: $scope.notaPedido.observaciones, |
| 199 | estado: 0, | 203 | estado: 0, |
| 200 | total: $scope.getTotal() | 204 | total: $scope.getTotal() |
| 201 | }; | 205 | }; |
| 202 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( | 206 | crearNotaPedidoService.crearNotaPedido(notaPedido).then( |
| 203 | function (data) { | 207 | function (data) { |
| 204 | // Al guardar los datos de la nota de pedido logueamos la | 208 | // Al guardar los datos de la nota de pedido logueamos la |
| 205 | // actividad para su seguimiento. | 209 | // actividad para su seguimiento. |
| 206 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? | 210 | //TODO: GUARDAR POSISIONAMIENTO AL EDITAR? |
| 207 | focaSeguimientoService.guardarPosicion( | 211 | focaSeguimientoService.guardarPosicion( |
| 208 | 'Nota de pedido', | 212 | 'Nota de pedido', |
| 209 | data.data.id, | 213 | data.data.id, |
| 210 | '' | 214 | '' |
| 211 | ); | 215 | ); |
| 212 | notaPedidoBusinessService.addArticulos( | 216 | notaPedidoBusinessService.addArticulos( |
| 213 | $scope.notaPedido.articulosNotaPedido, | 217 | $scope.notaPedido.articulosNotaPedido, |
| 214 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); | 218 | data.data.id, $scope.notaPedido.cotizacion.VENDEDOR); |
| 215 | 219 | ||
| 216 | if ($scope.notaPedido.notaPedidoPuntoDescarga.length > 0) { | 220 | if ($scope.notaPedido.notaPedidoPuntoDescarga.length > 0) { |
| 217 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, | 221 | notaPedidoBusinessService.addPuntosDescarga(data.data.id, |
| 218 | $scope.notaPedido.notaPedidoPuntoDescarga); | 222 | $scope.notaPedido.notaPedidoPuntoDescarga); |
| 219 | } | 223 | } |
| 220 | 224 | ||
| 221 | var rutaJson = JSON.parse($localStorage.rutas); | 225 | var rutaJson; |
| 222 | 226 | if ($localStorage.rutas) { | |
| 223 | removeItemFromArr( rutaJson, 'venta-nota-pedido/crear' ); | 227 | rutaJson = JSON.parse($localStorage.rutas); |
| 224 | $localStorage.rutas = JSON.stringify(rutaJson); | 228 | removeItemFromArr(rutaJson, 'venta-nota-pedido/crear'); |
| 225 | 229 | $localStorage.rutas = JSON.stringify(rutaJson); | |
| 226 | var plazos = $scope.notaPedido.notaPedidoPlazo; | 230 | } |
| 227 | var plazosACrear = []; | 231 | |
| 228 | plazos.forEach(function (plazo) { | 232 | var plazos = $scope.notaPedido.notaPedidoPlazo; |
| 229 | plazosACrear.push({ | 233 | var plazosACrear = []; |
| 230 | idNotaPedido: data.data.id, | 234 | plazos.forEach(function (plazo) { |
| 231 | dias: plazo.dias | 235 | plazosACrear.push({ |
| 236 | idNotaPedido: data.data.id, | ||
| 237 | dias: plazo.dias | ||
| 238 | }); | ||
| 232 | }); | 239 | }); |
| 233 | }); | ||
| 234 | 240 | ||
| 235 | if (plazosACrear.length) { | 241 | if (plazosACrear.length) { |
| 236 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); | 242 | crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear); |
| 237 | } | 243 | } |
| 238 | 244 | ||
| 239 | notaPedidoBusinessService.addEstado(data.data.id, | 245 | notaPedidoBusinessService.addEstado(data.data.id); |
| 240 | $scope.notaPedido.vendedor.id); | ||
| 241 | 246 | ||
| 242 | focaBotoneraLateralService.endGuardar(true); | 247 | focaBotoneraLateralService.endGuardar(true); |
| 243 | $scope.saveLoading = false; | 248 | $scope.saveLoading = false; |
| 244 | 249 | ||
| 245 | config(); | 250 | config(); |
| 246 | }, function (error) { | 251 | }, function (error) { |
| 247 | focaModalService.alert('Hubo un error al crear la nota de pedido'); | 252 | focaModalService.alert('Hubo un error al crear la nota de pedido'); |
| 248 | focaBotoneraLateralService.endGuardar(); | 253 | focaBotoneraLateralService.endGuardar(); |
| 249 | $scope.saveLoading = false; | 254 | $scope.saveLoading = false; |
| 250 | console.info(error); | 255 | console.info(error); |
| 251 | }); | 256 | }); |
| 252 | }; | 257 | }; |
| 253 | 258 | ||
| 254 | $scope.seleccionarNotaPedido = function () { | 259 | $scope.seleccionarNotaPedido = function () { |
| 255 | var modalInstance = $uibModal.open( | 260 | var modalInstance = $uibModal.open( |
| 256 | { | 261 | { |
| 257 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 262 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
| 258 | templateUrl: 'foca-modal-nota-pedido.html', | 263 | templateUrl: 'foca-modal-nota-pedido.html', |
| 259 | controller: 'focaModalNotaPedidoController', | 264 | controller: 'focaModalNotaPedidoController', |
| 260 | size: 'lg', | 265 | size: 'lg', |
| 261 | resolve: { | 266 | resolve: { |
| 262 | usadoPor: function () { return 'notaPedido'; }, | 267 | usadoPor: function () { return 'notaPedido'; }, |
| 263 | idVendedor: function () { | 268 | idVendedor: function () { |
| 264 | if (APP === 'distribuidor') | 269 | if (APP === 'distribuidor') |
| 265 | return $scope.notaPedido.vendedor.id; | 270 | return $scope.notaPedido.vendedor.id; |
| 266 | else | 271 | else |
| 267 | return null; | 272 | return null; |
| 268 | } | 273 | } |
| 269 | } | 274 | } |
| 270 | } | 275 | } |
| 271 | ); | 276 | ); |
| 272 | modalInstance.result.then(function (notaPedido) { | 277 | modalInstance.result.then(function (notaPedido) { |
| 273 | 278 | ||
| 274 | notaPedido.articulosNotaPedido.forEach(function (articulo) { | 279 | notaPedido.articulosNotaPedido.forEach(function (articulo) { |
| 275 | articulo.precio = | 280 | articulo.precio = |
| 276 | (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); | 281 | (articulo.precio / notaPedido.cotizacion.VENDEDOR).toFixed(4); |
| 277 | }); | 282 | }); |
| 278 | 283 | ||
| 279 | setearNotaPedido(notaPedido); | 284 | setearNotaPedido(notaPedido); |
| 280 | }); | 285 | }); |
| 281 | }; | 286 | }; |
| 282 | 287 | ||
| 283 | $scope.seleccionarProductos = function () { | 288 | $scope.seleccionarProductos = function () { |
| 284 | if ($scope.idLista === undefined) { | 289 | if ($scope.idLista === undefined) { |
| 285 | focaModalService.alert('Primero seleccione una lista de precio y condición'); | 290 | focaModalService.alert('Primero seleccione una lista de precio y condición'); |
| 286 | return; | 291 | return; |
| 287 | } else if (!validarNotaRemitada()) { | 292 | } else if (!validarNotaRemitada()) { |
| 288 | return; | 293 | return; |
| 289 | } | 294 | } |
| 290 | 295 | ||
| 291 | var modalInstance = $uibModal.open( | 296 | var modalInstance = $uibModal.open( |
| 292 | { | 297 | { |
| 293 | ariaLabelledBy: 'Busqueda de Productos', | 298 | ariaLabelledBy: 'Busqueda de Productos', |
| 294 | templateUrl: 'modal-busqueda-productos.html', | 299 | templateUrl: 'modal-busqueda-productos.html', |
| 295 | controller: 'modalBusquedaProductosCtrl', | 300 | controller: 'modalBusquedaProductosCtrl', |
| 296 | resolve: { | 301 | resolve: { |
| 297 | parametroProducto: { | 302 | parametroProducto: { |
| 298 | idLista: $scope.idLista, | 303 | idLista: $scope.idLista, |
| 299 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, | 304 | cotizacion: $scope.notaPedido.cotizacion.VENDEDOR, |
| 300 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO | 305 | simbolo: $scope.notaPedido.cotizacion.moneda.SIMBOLO |
| 301 | } | 306 | } |
| 302 | }, | 307 | }, |
| 303 | size: 'lg' | 308 | size: 'lg' |
| 304 | } | 309 | } |
| 305 | ); | 310 | ); |
| 306 | modalInstance.result.then( | 311 | modalInstance.result.then( |
| 307 | function (producto) { | 312 | function (producto) { |
| 308 | var newArt = | 313 | var newArt = |
| 309 | { | 314 | { |
| 310 | id: 0, | 315 | id: 0, |
| 311 | codigo: producto.codigo, | 316 | codigo: producto.codigo, |
| 312 | sector: producto.sector, | 317 | sector: producto.sector, |
| 313 | sectorCodigo: producto.sector + '-' + producto.codigo, | 318 | sectorCodigo: producto.sector + '-' + producto.codigo, |
| 314 | descripcion: producto.descripcionLarga, | 319 | descripcion: producto.descripcionLarga, |
| 315 | item: $scope.notaPedido.articulosNotaPedido.length + 1, | 320 | item: $scope.notaPedido.articulosNotaPedido.length + 1, |
| 316 | nombre: producto.descripcion, | 321 | nombre: producto.descripcion, |
| 317 | precio: parseFloat(producto.precio.toFixed(4)), | 322 | precio: parseFloat(producto.precio.toFixed(4)), |
| 318 | costoUnitario: producto.costo, | 323 | costoUnitario: producto.costo, |
| 319 | editCantidad: false, | 324 | editCantidad: false, |
| 320 | editPrecio: false, | 325 | editPrecio: false, |
| 321 | rubro: producto.CodRub, | 326 | rubro: producto.CodRub, |
| 322 | ivaUnitario: producto.IMPIVA, | 327 | ivaUnitario: producto.IMPIVA, |
| 323 | impuestoInternoUnitario: producto.ImpInt, | 328 | impuestoInternoUnitario: producto.ImpInt, |
| 324 | impuestoInterno1Unitario: producto.ImpInt2, | 329 | impuestoInterno1Unitario: producto.ImpInt2, |
| 325 | impuestoInterno2Unitario: producto.ImpInt3, | 330 | impuestoInterno2Unitario: producto.ImpInt3, |
| 326 | precioLista: producto.precio, | 331 | precioLista: producto.precio, |
| 327 | combustible: 1, | 332 | combustible: 1, |
| 328 | facturado: 0, | 333 | facturado: 0, |
| 329 | idArticulo: producto.id, | 334 | idArticulo: producto.id, |
| 330 | tasaIva: producto.tasaIVA | 335 | tasaIva: producto.tasaIVA |
| 331 | }; | 336 | }; |
| 332 | 337 | ||
| 333 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; | 338 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; |
| 334 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; | 339 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; |
| 335 | 340 | ||
| 336 | $scope.articuloACargar = newArt; | 341 | $scope.articuloACargar = newArt; |
| 337 | $scope.cargando = false; | 342 | $scope.cargando = false; |
| 338 | }, function () { | 343 | }, function () { |
| 339 | // funcion ejecutada cuando se cancela el modal | 344 | // funcion ejecutada cuando se cancela el modal |
| 340 | } | 345 | } |
| 341 | ); | 346 | ); |
| 342 | }; | 347 | }; |
| 343 | 348 | ||
| 344 | $scope.seleccionarPuntosDeDescarga = function () { | 349 | $scope.seleccionarPuntosDeDescarga = function () { |
| 345 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 350 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
| 346 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 351 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
| 347 | return; | 352 | return; |
| 348 | } else { | 353 | } else { |
| 349 | var modalInstance = $uibModal.open( | 354 | var modalInstance = $uibModal.open( |
| 350 | { | 355 | { |
| 351 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 356 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
| 352 | templateUrl: 'modal-punto-descarga.html', | 357 | templateUrl: 'modal-punto-descarga.html', |
| 353 | controller: 'focaModalPuntoDescargaController', | 358 | controller: 'focaModalPuntoDescargaController', |
| 354 | size: 'lg', | 359 | size: 'lg', |
| 355 | resolve: { | 360 | resolve: { |
| 356 | filters: { | 361 | filters: { |
| 357 | idDomicilio: $scope.notaPedido.domicilio.id, | 362 | idDomicilio: $scope.notaPedido.domicilio.id, |
| 358 | idCliente: $scope.notaPedido.cliente.COD, | 363 | idCliente: $scope.notaPedido.cliente.COD, |
| 359 | articulos: $scope.notaPedido.articulosNotaPedido, | 364 | articulos: $scope.notaPedido.articulosNotaPedido, |
| 360 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, | 365 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, |
| 361 | domicilio: $scope.notaPedido.domicilio | 366 | domicilio: $scope.notaPedido.domicilio |
| 362 | } | 367 | } |
| 363 | } | 368 | } |
| 364 | } | 369 | } |
| 365 | ); | 370 | ); |
| 366 | modalInstance.result.then( | 371 | modalInstance.result.then( |
| 367 | function (puntoDescarga) { | 372 | function (puntoDescarga) { |
| 368 | 373 | ||
| 369 | puntoDescarga.forEach(function (punto) { | 374 | puntoDescarga.forEach(function (punto) { |
| 370 | $scope.notaPedido.notaPedidoPuntoDescarga.push( | 375 | $scope.notaPedido.notaPedidoPuntoDescarga.push( |
| 371 | { | 376 | { |
| 372 | puntoDescarga: punto | 377 | puntoDescarga: punto |
| 373 | } | 378 | } |
| 374 | ); | 379 | ); |
| 375 | }); | 380 | }); |
| 376 | 381 | ||
| 377 | $scope.$broadcast('addCabecera', { | 382 | $scope.$broadcast('addCabecera', { |
| 378 | label: 'Puntos de descarga:', | 383 | label: 'Puntos de descarga:', |
| 379 | valor: getCabeceraPuntoDescarga(puntoDescarga) | 384 | valor: getCabeceraPuntoDescarga(puntoDescarga) |
| 380 | }); | 385 | }); |
| 381 | }, function () { | 386 | }, function () { |
| 382 | $scope.abrirModalDomicilios($scope.notaPedido.cliente); | 387 | $scope.abrirModalDomicilios($scope.notaPedido.cliente); |
| 383 | } | 388 | } |
| 384 | ); | 389 | ); |
| 385 | } | 390 | } |
| 386 | }; | 391 | }; |
| 387 | 392 | ||
| 388 | $scope.seleccionarDomicilioDeEntrega = function () { | 393 | $scope.seleccionarDomicilioDeEntrega = function () { |
| 389 | if (!$scope.notaPedido.cliente.COD) { | 394 | if (!$scope.notaPedido.cliente.COD) { |
| 390 | focaModalService.alert('Seleccione un Cliente'); | 395 | focaModalService.alert('Seleccione un Cliente'); |
| 391 | return; | 396 | return; |
| 392 | } else { | 397 | } else { |
| 393 | $scope.abrirModalDomicilios($scope.notaPedido.cliente); | 398 | $scope.abrirModalDomicilios($scope.notaPedido.cliente); |
| 394 | } | 399 | } |
| 395 | }; | 400 | }; |
| 396 | $scope.seleccionarProveedor = function () { | 401 | $scope.seleccionarProveedor = function () { |
| 397 | $scope.abrirModalProveedores(function () { | 402 | $scope.abrirModalProveedores(function () { |
| 398 | if (validarNotaRemitada()) { | 403 | if (validarNotaRemitada()) { |
| 399 | var modalInstance = $uibModal.open( | 404 | var modalInstance = $uibModal.open( |
| 400 | { | 405 | { |
| 401 | ariaLabelledBy: 'Busqueda de Flete', | 406 | ariaLabelledBy: 'Busqueda de Flete', |
| 402 | templateUrl: 'modal-flete.html', | 407 | templateUrl: 'modal-flete.html', |
| 403 | controller: 'focaModalFleteController', | 408 | controller: 'focaModalFleteController', |
| 404 | size: 'lg', | 409 | size: 'lg', |
| 405 | resolve: { | 410 | resolve: { |
| 406 | parametrosFlete: | 411 | parametrosFlete: |
| 407 | function () { | 412 | function () { |
| 408 | return { | 413 | return { |
| 409 | flete: $scope.notaPedido.fob ? 'FOB' : | 414 | flete: $scope.notaPedido.fob ? 'FOB' : |
| 410 | ($scope.notaPedido.flete ? '1' : | 415 | ($scope.notaPedido.flete ? '1' : |
| 411 | ($scope.notaPedido.flete === undefined ? | 416 | ($scope.notaPedido.flete === undefined ? |
| 412 | null : '0')), | 417 | null : '0')), |
| 413 | bomba: $scope.notaPedido.bomba ? '1' : | 418 | bomba: $scope.notaPedido.bomba ? '1' : |
| 414 | ($scope.notaPedido.bomba === undefined ? | 419 | ($scope.notaPedido.bomba === undefined ? |
| 415 | null : '0'), | 420 | null : '0'), |
| 416 | kilometros: $scope.notaPedido.kilometros | 421 | kilometros: $scope.notaPedido.kilometros |
| 417 | }; | 422 | }; |
| 418 | } | 423 | } |
| 419 | } | 424 | } |
| 420 | } | 425 | } |
| 421 | ); | 426 | ); |
| 422 | modalInstance.result.then( | 427 | modalInstance.result.then( |
| 423 | function (datos) { | 428 | function (datos) { |
| 424 | $scope.notaPedido.flete = datos.flete; | 429 | $scope.notaPedido.flete = datos.flete; |
| 425 | $scope.notaPedido.fob = datos.FOB; | 430 | $scope.notaPedido.fob = datos.FOB; |
| 426 | $scope.notaPedido.bomba = datos.bomba; | 431 | $scope.notaPedido.bomba = datos.bomba; |
| 427 | $scope.notaPedido.kilometros = datos.kilometros; | 432 | $scope.notaPedido.kilometros = datos.kilometros; |
| 428 | $scope.$broadcast('addCabecera', { | 433 | $scope.$broadcast('addCabecera', { |
| 429 | label: 'Flete:', | 434 | label: 'Flete:', |
| 430 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 435 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
| 431 | }); | 436 | }); |
| 432 | if (datos.flete) { | 437 | if (datos.flete) { |
| 433 | $scope.$broadcast('addCabecera', { | 438 | $scope.$broadcast('addCabecera', { |
| 434 | label: 'Bomba:', | 439 | label: 'Bomba:', |
| 435 | valor: datos.bomba ? 'Si' : 'No' | 440 | valor: datos.bomba ? 'Si' : 'No' |
| 436 | }); | 441 | }); |
| 437 | $scope.$broadcast('addCabecera', { | 442 | $scope.$broadcast('addCabecera', { |
| 438 | label: 'Kilometros:', | 443 | label: 'Kilometros:', |
| 439 | valor: datos.kilometros | 444 | valor: datos.kilometros |
| 440 | }); | 445 | }); |
| 441 | } else { | 446 | } else { |
| 442 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 447 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 443 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 448 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 444 | $scope.notaPedido.bomba = false; | 449 | $scope.notaPedido.bomba = false; |
| 445 | $scope.notaPedido.kilometros = null; | 450 | $scope.notaPedido.kilometros = null; |
| 446 | } | 451 | } |
| 447 | 452 | ||
| 448 | $filter('filter')($scope.botonera, | 453 | $filter('filter')($scope.botonera, |
| 449 | { label: 'Proveedor' })[0].checked = true; | 454 | { label: 'Proveedor' })[0].checked = true; |
| 450 | }, function () { | 455 | }, function () { |
| 451 | $scope.seleccionarTransportista(); | 456 | $scope.seleccionarTransportista(); |
| 452 | } | 457 | } |
| 453 | ); | 458 | ); |
| 454 | } | 459 | } |
| 455 | }); | 460 | }); |
| 456 | }; | 461 | }; |
| 457 | 462 | ||
| 458 | $scope.seleccionarVendedor = function (callback, ocultarVendedor) { | 463 | $scope.seleccionarVendedor = function (callback, ocultarVendedor) { |
| 459 | if (APP === 'distribuidor' || ocultarVendedor) { | 464 | if (APP === 'distribuidor' || ocultarVendedor) { |
| 460 | callback(); | 465 | callback(); |
| 461 | return; | 466 | return; |
| 462 | } | 467 | } |
| 463 | 468 | ||
| 464 | if (validarNotaRemitada()) { | 469 | if (validarNotaRemitada()) { |
| 465 | var parametrosModal = { | 470 | var parametrosModal = { |
| 466 | titulo: 'Búsqueda vendedores', | 471 | titulo: 'Búsqueda vendedores', |
| 467 | query: '/vendedor', | 472 | query: '/vendedor', |
| 468 | columnas: [ | 473 | columnas: [ |
| 469 | { | 474 | { |
| 470 | propiedad: 'NUM', | 475 | propiedad: 'NUM', |
| 471 | nombre: 'Código', | 476 | nombre: 'Código', |
| 472 | filtro: { | 477 | filtro: { |
| 473 | nombre: 'rellenarDigitos', | 478 | nombre: 'rellenarDigitos', |
| 474 | parametro: 3 | 479 | parametro: 3 |
| 475 | } | 480 | } |
| 476 | }, | 481 | }, |
| 477 | { | 482 | { |
| 478 | propiedad: 'NOM', | 483 | propiedad: 'NOM', |
| 479 | nombre: 'Nombre' | 484 | nombre: 'Nombre' |
| 480 | } | 485 | } |
| 481 | ], | 486 | ], |
| 482 | size: 'md' | 487 | size: 'md' |
| 483 | }; | 488 | }; |
| 484 | focaModalService.modal(parametrosModal).then( | 489 | focaModalService.modal(parametrosModal).then( |
| 485 | function (vendedor) { | 490 | function (vendedor) { |
| 486 | $scope.$broadcast('addCabecera', { | 491 | $scope.$broadcast('addCabecera', { |
| 487 | label: 'Vendedor:', | 492 | label: 'Vendedor:', |
| 488 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 493 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
| 489 | vendedor.NOM | 494 | vendedor.NOM |
| 490 | }); | 495 | }); |
| 491 | $scope.notaPedido.vendedor = vendedor; | 496 | $scope.notaPedido.vendedor = vendedor; |
| 492 | deleteCliente(); | 497 | deleteCliente(); |
| 493 | callback(); | 498 | callback(); |
| 494 | }, function () { } | 499 | }, function () { } |
| 495 | ); | 500 | ); |
| 496 | } | 501 | } |
| 497 | }; | 502 | }; |
| 498 | 503 | ||
| 499 | $scope.seleccionarCliente = function () { | 504 | $scope.seleccionarCliente = function () { |
| 500 | if (validarNotaRemitada()) { | 505 | if (validarNotaRemitada()) { |
| 501 | 506 | ||
| 502 | var modalInstance = $uibModal.open( | 507 | var modalInstance = $uibModal.open( |
| 503 | { | 508 | { |
| 504 | ariaLabelledBy: 'Busqueda de Cliente', | 509 | ariaLabelledBy: 'Busqueda de Cliente', |
| 505 | templateUrl: 'foca-busqueda-cliente-modal.html', | 510 | templateUrl: 'foca-busqueda-cliente-modal.html', |
| 506 | controller: 'focaBusquedaClienteModalController', | 511 | controller: 'focaBusquedaClienteModalController', |
| 507 | resolve: { | 512 | resolve: { |
| 508 | parametros: function () { | 513 | parametros: function () { |
| 509 | return { | 514 | return { |
| 510 | vendedor: $scope.idVendedor, | 515 | // vendedor: $scope.idVendedor, |
| 511 | cobrador: null, | 516 | cobrador: null, |
| 512 | searchText: $scope.notaPedido.cliente ? | 517 | searchText: $scope.notaPedido.cliente ? |
| 513 | $scope.notaPedido.cliente.NOM : '' | 518 | $scope.notaPedido.cliente.NOM : '' |
| 514 | }; | 519 | }; |
| 515 | } | 520 | } |
| 516 | }, | 521 | }, |
| 522 | backdrop: false, | ||
| 517 | size: 'lg' | 523 | size: 'lg' |
| 518 | } | 524 | } |
| 519 | ); | 525 | ); |
| 520 | modalInstance.result.then( | 526 | modalInstance.result.then( |
| 521 | function (cliente) { | 527 | function (cliente) { |
| 522 | 528 | ||
| 523 | if ($scope.notaPedido.precioCondicion !== undefined) { | 529 | if ($scope.notaPedido.precioCondicion !== undefined) { |
| 524 | focaModalService | 530 | focaModalService |
| 525 | .alert('Debe agregar lista de precio de cliente actual') | 531 | .alert('Debe agregar lista de precio de cliente actual') |
| 526 | .then(function () { | 532 | .then(function () { |
| 527 | $scope.notaPedido.precioCondicion = undefined; | 533 | $scope.notaPedido.precioCondicion = undefined; |
| 528 | $scope.$broadcast('removeCabecera', | 534 | $scope.$broadcast('removeCabecera', |
| 529 | 'Precios y Condiciones:'); | 535 | 'Precios y Condiciones:'); |
| 530 | $filter('filter')($scope.botonera, | 536 | $filter('filter')($scope.botonera, |
| 531 | { label: 'Precios y Condiciones' })[0].checked = false; | 537 | { label: 'Precios y Condiciones' })[0].checked = false; |
| 532 | }) | 538 | }) |
| 533 | .catch(function () { | 539 | .catch(function () { |
| 534 | }); | 540 | }); |
| 535 | } | 541 | } |
| 536 | 542 | ||
| 537 | if (angular.equals({}, cliente.vendedor)) { | 543 | // if (angular.equals({}, cliente.vendedor)) { |
| 538 | 544 | ||
| 539 | focaModalService | 545 | // focaModalService |
| 540 | .alert('El cliente seleccionado no tiene tiene ' + | 546 | // .alert('El cliente seleccionado no tiene tiene ' + |
| 541 | 'vendedor asignado.') | 547 | // 'vendedor asignado.') |
| 542 | .then($scope.seleccionarCliente); | 548 | // .then($scope.seleccionarCliente); |
| 543 | 549 | ||
| 544 | return; | 550 | // return; |
| 545 | } | 551 | // } |
| 546 | 552 | ||
| 547 | $scope.abrirModalDomicilios(cliente); | 553 | $scope.abrirModalDomicilios(cliente); |
| 548 | }, function () { } | 554 | }, function () { } |
| 549 | ); | 555 | ); |
| 550 | } | 556 | } |
| 551 | }; | 557 | }; |
| 552 | 558 | ||
| 553 | $scope.abrirModalProveedores = function (callback) { | 559 | $scope.abrirModalProveedores = function (callback) { |
| 554 | if (validarNotaRemitada()) { | 560 | if (validarNotaRemitada()) { |
| 555 | var parametrosModal = { | 561 | var parametrosModal = { |
| 556 | titulo: 'Búsqueda de Proveedor', | 562 | titulo: 'Búsqueda de Proveedor', |
| 557 | query: '/proveedor', | 563 | query: '/proveedor', |
| 558 | columnas: [ | 564 | columnas: [ |
| 559 | { | 565 | { |
| 560 | nombre: 'Código', | 566 | nombre: 'Código', |
| 561 | propiedad: 'COD', | 567 | propiedad: 'COD', |
| 562 | filtro: { | 568 | filtro: { |
| 563 | nombre: 'rellenarDigitos', | 569 | nombre: 'rellenarDigitos', |
| 564 | parametro: 5 | 570 | parametro: 5 |
| 565 | } | 571 | } |
| 566 | }, | 572 | }, |
| 567 | { | 573 | { |
| 568 | nombre: 'Nombre', | 574 | nombre: 'Nombre', |
| 569 | propiedad: 'NOM' | 575 | propiedad: 'NOM' |
| 570 | }, | 576 | }, |
| 571 | { | 577 | { |
| 572 | nombre: 'CUIT', | 578 | nombre: 'CUIT', |
| 573 | propiedad: 'CUIT' | 579 | propiedad: 'CUIT' |
| 574 | } | 580 | } |
| 575 | ], | 581 | ], |
| 576 | tipo: 'POST', | 582 | tipo: 'POST', |
| 577 | json: { razonCuitCod: '' } | 583 | json: { razonCuitCod: '' } |
| 578 | }; | 584 | }; |
| 579 | focaModalService.modal(parametrosModal).then( | 585 | focaModalService.modal(parametrosModal).then( |
| 580 | function (proveedor) { | 586 | function (proveedor) { |
| 581 | $scope.notaPedido.proveedor = proveedor; | 587 | $scope.notaPedido.proveedor = proveedor; |
| 582 | $scope.$broadcast('addCabecera', { | 588 | $scope.$broadcast('addCabecera', { |
| 583 | label: 'Proveedor:', | 589 | label: 'Proveedor:', |
| 584 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 590 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
| 585 | proveedor.NOM | 591 | proveedor.NOM |
| 586 | }); | 592 | }); |
| 587 | callback(); | 593 | callback(); |
| 588 | }, function () { | 594 | }, function () { |
| 589 | 595 | ||
| 590 | } | 596 | } |
| 591 | ); | 597 | ); |
| 592 | } | 598 | } |
| 593 | }; | 599 | }; |
| 594 | 600 | ||
| 595 | $scope.abrirModalDomicilios = function (cliente) { | 601 | $scope.abrirModalDomicilios = function (cliente) { |
| 596 | var modalInstanceDomicilio = $uibModal.open( | 602 | var modalInstanceDomicilio = $uibModal.open( |
| 597 | { | 603 | { |
| 598 | ariaLabelledBy: 'Busqueda de Domicilios', | 604 | ariaLabelledBy: 'Busqueda de Domicilios', |
| 599 | templateUrl: 'modal-domicilio.html', | 605 | templateUrl: 'modal-domicilio.html', |
| 600 | controller: 'focaModalDomicilioController', | 606 | controller: 'focaModalDomicilioController', |
| 601 | resolve: { | 607 | resolve: { |
| 602 | idCliente: function () { return cliente.COD; }, | 608 | idCliente: function () { return cliente.COD; }, |
| 603 | esNuevo: function () { return cliente.esNuevo; } | 609 | esNuevo: function () { return cliente.esNuevo; } |
| 604 | }, | 610 | }, |
| 611 | backdrop: false, | ||
| 605 | size: 'lg', | 612 | size: 'lg', |
| 606 | } | 613 | } |
| 607 | ); | 614 | ); |
| 608 | modalInstanceDomicilio.result.then( | 615 | modalInstanceDomicilio.result.then( |
| 609 | function (domicilio) { | 616 | function (domicilio) { |
| 610 | 617 | ||
| 611 | $scope.notaPedido.domicilio = domicilio; | 618 | $scope.notaPedido.domicilio = domicilio; |
| 612 | $scope.notaPedido.cliente = cliente; | 619 | $scope.notaPedido.cliente = cliente; |
| 613 | $scope.notaPedido.vendedor = cliente.vendedor; | 620 | // $scope.notaPedido.vendedor = cliente.vendedor; |
| 614 | 621 | ||
| 615 | $scope.$broadcast('addCabecera', { | 622 | // $scope.$broadcast('addCabecera', { |
| 616 | label: 'Vendedor:', | 623 | // label: 'Vendedor:', |
| 617 | valor: $filter('rellenarDigitos') | 624 | // valor: $filter('rellenarDigitos') |
| 618 | ($scope.notaPedido.vendedor.NUM, 3) + | 625 | // ($scope.notaPedido.vendedor.NUM, 3) + |
| 619 | ' - ' + $scope.notaPedido.vendedor.NOM | 626 | // ' - ' + $scope.notaPedido.vendedor.NOM |
| 620 | }); | 627 | // }); |
| 621 | 628 | ||
| 622 | var domicilioStamp = | 629 | var domicilioStamp = |
| 623 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 630 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
| 624 | domicilio.Localidad + ', ' + domicilio.Provincia; | 631 | domicilio.Localidad + ', ' + domicilio.Provincia; |
| 625 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 632 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
| 626 | 633 | ||
| 627 | $scope.$broadcast('addCabecera', { | 634 | $scope.$broadcast('addCabecera', { |
| 628 | label: 'Cliente:', | 635 | label: 'Cliente:', |
| 629 | valor: $filter('rellenarDigitos')(cliente.COD, 5) + | 636 | valor: $filter('rellenarDigitos')(cliente.COD, 5) + |
| 630 | ' - ' + cliente.NOM | 637 | ' - ' + cliente.NOM |
| 631 | }); | 638 | }); |
| 632 | 639 | ||
| 633 | $scope.$broadcast('addCabecera', { | 640 | $scope.$broadcast('addCabecera', { |
| 634 | label: 'Domicilio:', | 641 | label: 'Domicilio:', |
| 635 | valor: domicilioStamp | 642 | valor: domicilioStamp |
| 636 | }); | 643 | }); |
| 637 | 644 | ||
| 638 | if (domicilio.verPuntos) { | 645 | if (domicilio.verPuntos) { |
| 639 | delete $scope.notaPedido.domicilio.verPuntos; | 646 | delete $scope.notaPedido.domicilio.verPuntos; |
| 640 | $scope.seleccionarPuntosDeDescarga(); | 647 | $scope.seleccionarPuntosDeDescarga(); |
| 641 | } | 648 | } |
| 642 | 649 | ||
| 643 | // Seteo checked en botonera | 650 | // Seteo checked en botonera |
| 644 | $filter('filter')($scope.botonera, | 651 | $filter('filter')($scope.botonera, |
| 645 | { label: 'Cliente' })[0].checked = true; | 652 | { label: 'Cliente' })[0].checked = true; |
| 646 | $filter('filter')($scope.botonera, | 653 | $filter('filter')($scope.botonera, |
| 647 | { label: 'Domicilio de Entrega' })[0].checked = true; | 654 | { label: 'Domicilio de Entrega' })[0].checked = true; |
| 648 | 655 | ||
| 649 | }, function () { | 656 | }, function () { |
| 650 | $scope.seleccionarCliente(true); | 657 | $scope.seleccionarCliente(true); |
| 651 | return; | 658 | return; |
| 652 | } | 659 | } |
| 653 | ); | 660 | ); |
| 654 | }; | 661 | }; |
| 655 | 662 | ||
| 656 | $scope.getTotal = function () { | 663 | $scope.getTotal = function () { |
| 657 | var total = 0; | 664 | var total = 0; |
| 658 | if ($scope.notaPedido.articulosNotaPedido) { | 665 | if ($scope.notaPedido.articulosNotaPedido) { |
| 659 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; | 666 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; |
| 660 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 667 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
| 661 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 668 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
| 662 | } | 669 | } |
| 663 | } | 670 | } |
| 664 | return parseFloat(total.toFixed(2)); | 671 | return parseFloat(total.toFixed(2)); |
| 665 | }; | 672 | }; |
| 666 | 673 | ||
| 667 | $scope.getSubTotal = function () { | 674 | $scope.getSubTotal = function () { |
| 668 | if ($scope.articuloACargar) { | 675 | if ($scope.articuloACargar) { |
| 669 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 676 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
| 670 | } | 677 | } |
| 671 | }; | 678 | }; |
| 672 | 679 | ||
| 673 | $scope.seleccionarPreciosYCondiciones = function () { | 680 | $scope.seleccionarPreciosYCondiciones = function () { |
| 674 | 681 | ||
| 675 | if (!validarNotaRemitada()) return; | 682 | if (!validarNotaRemitada()) return; |
| 676 | 683 | ||
| 677 | if (!$scope.notaPedido.cliente.COD) { | 684 | if (!$scope.notaPedido.cliente.COD) { |
| 678 | focaModalService.alert('Primero seleccione un cliente'); | 685 | focaModalService.alert('Primero seleccione un cliente'); |
| 679 | return; | 686 | return; |
| 680 | } else { | 687 | } else { |
| 681 | abrirModal(); | 688 | abrirModal(); |
| 682 | } | 689 | } |
| 683 | 690 | ||
| 684 | function abrirModal() { | 691 | function abrirModal() { |
| 685 | var parametros = { | 692 | var parametros = { |
| 686 | idCliente: $scope.notaPedido.cliente.COD, | 693 | idCliente: $scope.notaPedido.cliente.COD, |
| 687 | idListaPrecio: $scope.notaPedido.cliente.MOD, | 694 | idListaPrecio: $scope.notaPedido.cliente.MOD, |
| 688 | notaPedido: $scope.notaPedido | 695 | notaPedido: $scope.notaPedido |
| 689 | }; | 696 | }; |
| 690 | var modalInstance = $uibModal.open( | 697 | var modalInstance = $uibModal.open( |
| 691 | { | 698 | { |
| 692 | ariaLabelledBy: 'Busqueda de Precio Condición', | 699 | ariaLabelledBy: 'Busqueda de Precio Condición', |
| 693 | templateUrl: 'modal-precio-condicion.html', | 700 | templateUrl: 'modal-precio-condicion.html', |
| 694 | controller: 'focaModalPrecioCondicionController', | 701 | controller: 'focaModalPrecioCondicionController', |
| 695 | size: 'lg', | 702 | size: 'lg', |
| 696 | resolve: { | 703 | resolve: { |
| 697 | parametros: function () { return parametros; }, | 704 | parametros: function () { return parametros; }, |
| 698 | } | 705 | } |
| 699 | } | 706 | } |
| 700 | ); | 707 | ); |
| 701 | 708 | ||
| 702 | modalInstance.result.then(function (precioCondicion) { | 709 | modalInstance.result.then(function (precioCondicion) { |
| 703 | var cabecera = ''; | 710 | var cabecera = ''; |
| 704 | var plazosConcat = ''; | 711 | var plazosConcat = ''; |
| 705 | if (!Array.isArray(precioCondicion)) { | 712 | if (!Array.isArray(precioCondicion)) { |
| 706 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; | 713 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; |
| 707 | $scope.notaPedido.precioCondicion = precioCondicion; | 714 | $scope.notaPedido.precioCondicion = precioCondicion; |
| 708 | $scope.notaPedido.cliente.MOD = precioCondicion.listaPrecio.ID; | 715 | $scope.notaPedido.cliente.MOD = precioCondicion.listaPrecio.ID; |
| 709 | $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? | 716 | $scope.idLista = parseInt(precioCondicion.listaPrecio.ID) ? |
| 710 | parseInt(precioCondicion.listaPrecio.ID) : -1; | 717 | parseInt(precioCondicion.listaPrecio.ID) : -1; |
| 711 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { | 718 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { |
| 712 | plazosConcat += precioCondicion.plazoPago[i].dias + ', '; | 719 | plazosConcat += precioCondicion.plazoPago[i].dias + ', '; |
| 713 | } | 720 | } |
| 714 | plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); | 721 | plazosConcat = plazosConcat.substring(0, plazosConcat.length - 2); |
| 715 | cabecera = $filter('rellenarDigitos')($scope.idLista, 4) + | 722 | cabecera = $filter('rellenarDigitos')($scope.idLista, 4) + |
| 716 | ' - ' + precioCondicion.listaPrecio.DES + | 723 | ' - ' + precioCondicion.listaPrecio.DES + |
| 717 | ' ' + plazosConcat.trim(); | 724 | ' ' + plazosConcat.trim(); |
| 718 | } else { //Cuando se ingresan los plazos manualmente | 725 | } else { //Cuando se ingresan los plazos manualmente |
| 719 | //-1, el modal productos busca todos los productos | 726 | //-1, el modal productos busca todos los productos |
| 720 | $scope.idLista = -1; | 727 | $scope.idLista = -1; |
| 721 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; | 728 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; |
| 722 | for (var j = 0; j < precioCondicion.length; j++) { | 729 | for (var j = 0; j < precioCondicion.length; j++) { |
| 723 | plazosConcat += precioCondicion[j].dias + ' '; | 730 | plazosConcat += precioCondicion[j].dias + ' '; |
| 724 | } | 731 | } |
| 725 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 732 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
| 726 | } | 733 | } |
| 727 | $scope.cabeceras.push({ | 734 | $scope.cabeceras.push({ |
| 728 | label: 'Precios y Condiciones:', | 735 | label: 'Precios y Condiciones:', |
| 729 | valor: $scope.idLista + ' - ' + precioCondicion.listaPrecio.DES + ' ' + | 736 | valor: $scope.idLista + ' - ' + precioCondicion.listaPrecio.DES + ' ' + |
| 730 | notaPedidoBusinessService.plazoToString(precioCondicion.plazoPago) | 737 | notaPedidoBusinessService.plazoToString(precioCondicion.plazoPago) |
| 731 | }); | 738 | }); |
| 732 | 739 | ||
| 733 | $filter('filter')($scope.botonera, | 740 | $filter('filter')($scope.botonera, |
| 734 | { label: 'Precios y Condiciones' })[0].checked = true; | 741 | { label: 'Precios y Condiciones' })[0].checked = true; |
| 735 | 742 | ||
| 736 | addArrayCabecera($scope.cabeceras); | 743 | addArrayCabecera($scope.cabeceras); |
| 737 | 744 | ||
| 738 | }) | 745 | }) |
| 739 | .catch(function (e) { | 746 | .catch(function (e) { |
| 740 | console.log(e); | 747 | console.log(e); |
| 741 | }); | 748 | }); |
| 742 | 749 | ||
| 743 | } | 750 | } |
| 744 | }; | 751 | }; |
| 745 | 752 | ||
| 746 | $scope.seleccionarMoneda = function () { | 753 | $scope.seleccionarMoneda = function () { |
| 747 | if (validarNotaRemitada()) { | 754 | if (validarNotaRemitada()) { |
| 748 | var parametrosModal = { | 755 | var parametrosModal = { |
| 749 | titulo: 'Búsqueda de monedas', | 756 | titulo: 'Búsqueda de monedas', |
| 750 | query: '/moneda', | 757 | query: '/moneda', |
| 751 | columnas: [ | 758 | columnas: [ |
| 752 | { | 759 | { |
| 753 | propiedad: 'DETALLE', | 760 | propiedad: 'DETALLE', |
| 754 | nombre: 'Nombre' | 761 | nombre: 'Nombre' |
| 755 | }, | 762 | }, |
| 756 | { | 763 | { |
| 757 | propiedad: 'SIMBOLO', | 764 | propiedad: 'SIMBOLO', |
| 758 | nombre: 'Símbolo' | 765 | nombre: 'Símbolo' |
| 759 | } | 766 | } |
| 760 | ], | 767 | ], |
| 761 | size: 'md' | 768 | size: 'md' |
| 762 | }; | 769 | }; |
| 763 | focaModalService.modal(parametrosModal).then( | 770 | focaModalService.modal(parametrosModal).then( |
| 764 | function (moneda) { | 771 | function (moneda) { |
| 765 | 772 | ||
| 766 | if (moneda.ID !== 1) { | 773 | if (moneda.ID !== 1) { |
| 767 | $scope.abrirModalCotizacion(moneda); | 774 | $scope.abrirModalCotizacion(moneda); |
| 768 | return; | 775 | return; |
| 769 | } | 776 | } |
| 770 | 777 | ||
| 771 | crearNotaPedidoService.getCotizacionByIdMoneda(1) | 778 | crearNotaPedidoService.getCotizacionByIdMoneda(1) |
| 772 | .then(function (res) { | 779 | .then(function (res) { |
| 773 | 780 | ||
| 774 | cotizacionPArgentino = res.data[0].cotizaciones[0]; | 781 | cotizacionPArgentino = res.data[0].cotizaciones[0]; |
| 775 | cotizacionPArgentino.moneda = moneda; | 782 | cotizacionPArgentino.moneda = moneda; |
| 776 | 783 | ||
| 777 | actualizarCabeceraMoneda(cotizacionPArgentino); | 784 | actualizarCabeceraMoneda(cotizacionPArgentino); |
| 778 | $filter('filter')($scope.botonera, | 785 | $filter('filter')($scope.botonera, |
| 779 | { label: 'Moneda' })[0].checked = true; | 786 | { label: 'Moneda' })[0].checked = true; |
| 780 | $scope.notaPedido.cotizacion = cotizacionPArgentino; | 787 | $scope.notaPedido.cotizacion = cotizacionPArgentino; |
| 781 | }); | 788 | }); |
| 782 | } | 789 | } |
| 783 | ); | 790 | ); |
| 784 | } | 791 | } |
| 785 | }; | 792 | }; |
| 786 | 793 | ||
| 787 | $scope.seleccionarObservaciones = function () { | 794 | $scope.seleccionarObservaciones = function () { |
| 788 | var observacion = { | 795 | var observacion = { |
| 789 | titulo: 'Ingrese Observaciones', | 796 | titulo: 'Ingrese Observaciones', |
| 790 | value: $scope.notaPedido.observaciones, | 797 | value: $scope.notaPedido.observaciones, |
| 791 | maxlength: 155, | 798 | maxlength: 155, |
| 792 | textarea: true | 799 | textarea: true |
| 793 | }; | 800 | }; |
| 794 | 801 | ||
| 795 | focaModalService | 802 | focaModalService |
| 796 | .prompt(observacion) | 803 | .prompt(observacion) |
| 797 | .then(function (observaciones) { | 804 | .then(function (observaciones) { |
| 798 | $scope.notaPedido.observaciones = observaciones; | 805 | $scope.notaPedido.observaciones = observaciones; |
| 799 | }); | 806 | }); |
| 800 | }; | 807 | }; |
| 801 | 808 | ||
| 802 | $scope.abrirModalCotizacion = function (moneda) { | 809 | $scope.abrirModalCotizacion = function (moneda) { |
| 803 | var modalInstance = $uibModal.open( | 810 | var modalInstance = $uibModal.open( |
| 804 | { | 811 | { |
| 805 | ariaLabelledBy: 'Busqueda de Cotización', | 812 | ariaLabelledBy: 'Busqueda de Cotización', |
| 806 | templateUrl: 'modal-cotizacion.html', | 813 | templateUrl: 'modal-cotizacion.html', |
| 807 | controller: 'focaModalCotizacionController', | 814 | controller: 'focaModalCotizacionController', |
| 808 | size: 'lg', | 815 | size: 'lg', |
| 809 | resolve: { | 816 | resolve: { |
| 810 | idMoneda: function () { | 817 | idMoneda: function () { |
| 811 | return moneda.ID; | 818 | return moneda.ID; |
| 812 | } | 819 | } |
| 813 | } | 820 | } |
| 814 | } | 821 | } |
| 815 | ); | 822 | ); |
| 816 | modalInstance.result.then( | 823 | modalInstance.result.then( |
| 817 | function (cotizacion) { | 824 | function (cotizacion) { |
| 818 | 825 | ||
| 819 | cotizacion.moneda = moneda; | 826 | cotizacion.moneda = moneda; |
| 820 | actualizarCabeceraMoneda(cotizacion); | 827 | actualizarCabeceraMoneda(cotizacion); |
| 821 | 828 | ||
| 822 | $scope.notaPedido.cotizacion = cotizacion; | 829 | $scope.notaPedido.cotizacion = cotizacion; |
| 823 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 830 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; |
| 824 | }, function () { | 831 | }, function () { |
| 825 | 832 | ||
| 826 | } | 833 | } |
| 827 | ); | 834 | ); |
| 828 | }; | 835 | }; |
| 829 | 836 | ||
| 830 | function actualizarCabeceraMoneda(cotizacion) { | 837 | function actualizarCabeceraMoneda(cotizacion) { |
| 831 | 838 | ||
| 832 | $scope.notaPedido.articulosNotaPedido.forEach(function (art) { | 839 | $scope.notaPedido.articulosNotaPedido.forEach(function (art) { |
| 833 | art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); | 840 | art.precio = (art.precio * $scope.notaPedido.cotizacion.VENDEDOR).toFixed(4); |
| 834 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); | 841 | art.precio = (art.precio / cotizacion.VENDEDOR).toFixed(4); |
| 835 | }); | 842 | }); |
| 836 | 843 | ||
| 837 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { | 844 | if (cotizacion.moneda.DETALLE === 'PESOS ARGENTINOS') { |
| 838 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 845 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
| 839 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 846 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
| 840 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 847 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
| 841 | } else { | 848 | } else { |
| 842 | $scope.$broadcast('addCabecera', { | 849 | $scope.$broadcast('addCabecera', { |
| 843 | label: 'Moneda:', | 850 | label: 'Moneda:', |
| 844 | valor: cotizacion.moneda.DETALLE | 851 | valor: cotizacion.moneda.DETALLE |
| 845 | }); | 852 | }); |
| 846 | $scope.$broadcast('addCabecera', { | 853 | $scope.$broadcast('addCabecera', { |
| 847 | label: 'Fecha cotizacion:', | 854 | label: 'Fecha cotizacion:', |
| 848 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 855 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
| 849 | }); | 856 | }); |
| 850 | $scope.$broadcast('addCabecera', { | 857 | $scope.$broadcast('addCabecera', { |
| 851 | label: 'Cotizacion:', | 858 | label: 'Cotizacion:', |
| 852 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 859 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
| 853 | }); | 860 | }); |
| 854 | } | 861 | } |
| 855 | } | 862 | } |
| 856 | 863 | ||
| 857 | $scope.agregarATabla = function (key) { | 864 | $scope.agregarATabla = function (key) { |
| 858 | if (key === 13) { | 865 | if (key === 13) { |
| 859 | if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { | 866 | if (!$scope.articuloACargar.cantidad || !$scope.articuloACargar.precio) { |
| 860 | focaModalService.alert('El valor debe ser al menos 1'); | 867 | focaModalService.alert('El valor debe ser al menos 1'); |
| 861 | return; | 868 | return; |
| 862 | } | 869 | } |
| 863 | delete $scope.articuloACargar.sectorCodigo; | 870 | delete $scope.articuloACargar.sectorCodigo; |
| 864 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); | 871 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); |
| 865 | $scope.cargando = true; | 872 | $scope.cargando = true; |
| 866 | } | 873 | } |
| 867 | }; | 874 | }; |
| 868 | 875 | ||
| 869 | $scope.quitarArticulo = function (key) { | 876 | $scope.quitarArticulo = function (key) { |
| 870 | if (validarNotaRemitada()) { | 877 | if (validarNotaRemitada()) { |
| 871 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | 878 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); |
| 872 | } | 879 | } |
| 873 | }; | 880 | }; |
| 874 | 881 | ||
| 875 | $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { | 882 | $scope.editarArticulo = function (key, articulo, tmpCantidad, tmpPrecio) { |
| 876 | if (key === 13) { | 883 | if (key === 13) { |
| 877 | if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { | 884 | if (!articulo.cantidad || !articulo.precio || !tmpCantidad || !tmpPrecio) { |
| 878 | focaModalService.alert('Los valores deben ser al menos 1'); | 885 | focaModalService.alert('Los valores deben ser al menos 1'); |
| 879 | return; | 886 | return; |
| 880 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { | 887 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { |
| 881 | focaModalService.alert('Los valores no pueden ser negativos'); | 888 | focaModalService.alert('Los valores no pueden ser negativos'); |
| 882 | return; | 889 | return; |
| 883 | } | 890 | } |
| 884 | articulo.cantidad = tmpCantidad; | 891 | articulo.cantidad = tmpCantidad; |
| 885 | articulo.precio = tmpPrecio; | 892 | articulo.precio = tmpPrecio; |
| 886 | $scope.getTotal(); | 893 | $scope.getTotal(); |
| 887 | articulo.editCantidad = articulo.editPrecio = false; | 894 | articulo.editCantidad = articulo.editPrecio = false; |
| 888 | } | 895 | } |
| 889 | }; | 896 | }; |
| 890 | 897 | ||
| 891 | $scope.cancelarEditar = function (articulo) { | 898 | $scope.cancelarEditar = function (articulo) { |
| 892 | $scope.tmpCantidad = articulo.cantidad; | 899 | $scope.tmpCantidad = articulo.cantidad; |
| 893 | $scope.tmpPrecio = articulo.precio; | 900 | $scope.tmpPrecio = articulo.precio; |
| 894 | articulo.editCantidad = articulo.editPrecio = false; | 901 | articulo.editCantidad = articulo.editPrecio = false; |
| 895 | }; | 902 | }; |
| 896 | 903 | ||
| 897 | $scope.cambioEdit = function (articulo, propiedad) { | 904 | $scope.cambioEdit = function (articulo, propiedad) { |
| 898 | if (propiedad === 'cantidad') { | 905 | if (propiedad === 'cantidad') { |
| 899 | articulo.editCantidad = true; | 906 | articulo.editCantidad = true; |
| 900 | } else if (propiedad === 'precio') { | 907 | } else if (propiedad === 'precio') { |
| 901 | articulo.editPrecio = true; | 908 | articulo.editPrecio = true; |
| 902 | } | 909 | } |
| 903 | }; | 910 | }; |
| 904 | 911 | ||
| 905 | $scope.resetFilter = function () { | 912 | $scope.resetFilter = function () { |
| 906 | $scope.articuloACargar = {}; | 913 | $scope.articuloACargar = {}; |
| 907 | $scope.cargando = true; | 914 | $scope.cargando = true; |
| 908 | }; | 915 | }; |
| 909 | //Recibe aviso si el teclado está en uso | 916 | //Recibe aviso si el teclado está en uso |
| 910 | $rootScope.$on('usarTeclado', function (event, data) { | 917 | $rootScope.$on('usarTeclado', function (event, data) { |
| 911 | if (data) { | 918 | if (data) { |
| 912 | $scope.mostrarTeclado = true; | 919 | $scope.mostrarTeclado = true; |
| 913 | return; | 920 | return; |
| 914 | } | 921 | } |
| 915 | $scope.mostrarTeclado = false; | 922 | $scope.mostrarTeclado = false; |
| 916 | }); | 923 | }); |
| 917 | 924 | ||
| 918 | $scope.selectFocus = function ($event) { | 925 | $scope.selectFocus = function ($event) { |
| 919 | // Si el teclado esta en uso no selecciona el valor | 926 | // Si el teclado esta en uso no selecciona el valor |
| 920 | if ($scope.mostrarTeclado) { | 927 | if ($scope.mostrarTeclado) { |
| 921 | return; | 928 | return; |
| 922 | } | 929 | } |
| 923 | $event.target.select(); | 930 | $event.target.select(); |
| 924 | }; | 931 | }; |
| 925 | 932 | ||
| 926 | $scope.salir = function () { | 933 | $scope.salir = function () { |
| 927 | $location.path('/'); | 934 | $location.path('/'); |
| 928 | }; | 935 | }; |
| 929 | 936 | ||
| 930 | $scope.parsearATexto = function (articulo) { | 937 | $scope.parsearATexto = function (articulo) { |
| 931 | articulo.cantidad = parseFloat(articulo.cantidad); | 938 | articulo.cantidad = parseFloat(articulo.cantidad); |
| 932 | articulo.precio = parseFloat(articulo.precio); | 939 | articulo.precio = parseFloat(articulo.precio); |
| 933 | }; | 940 | }; |
| 934 | 941 | ||
| 935 | // TODO: quitar watch usar función de articulos pedido cuando se haga | 942 | // TODO: quitar watch usar función de articulos pedido cuando se haga |
| 936 | $scope.$watch('notaPedido.articulosNotaPedido', function () { | 943 | $scope.$watch('notaPedido.articulosNotaPedido', function () { |
| 937 | if ($scope.notaPedido.articulosNotaPedido.length) { | 944 | if ($scope.notaPedido.articulosNotaPedido.length) { |
| 938 | $filter('filter')($scope.botonera, | 945 | $filter('filter')($scope.botonera, |
| 939 | { label: 'Productos' })[0].checked = true; | 946 | { label: 'Productos' })[0].checked = true; |
| 940 | } else { | 947 | } else { |
| 941 | $filter('filter')($scope.botonera, | 948 | $filter('filter')($scope.botonera, |
| 942 | { label: 'Productos' })[0].checked = false; | 949 | { label: 'Productos' })[0].checked = false; |
| 943 | } | 950 | } |
| 944 | }, true); | 951 | }, true); |
| 945 | 952 | ||
| 946 | function setearNotaPedido(notaPedido) { | 953 | function setearNotaPedido(notaPedido) { |
| 947 | //añado cabeceras | 954 | //añado cabeceras |
| 948 | $scope.notaPedido = notaPedido; | 955 | $scope.notaPedido = notaPedido; |
| 949 | if (!$scope.notaPedido.domicilio) { | 956 | if (!$scope.notaPedido.domicilio) { |
| 950 | $scope.notaPedido.domicilio = { | 957 | $scope.notaPedido.domicilio = { |
| 951 | id: $scope.notaPedido.idDomicilio | 958 | id: $scope.notaPedido.idDomicilio |
| 952 | }; | 959 | }; |
| 953 | } | 960 | } |
| 954 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 961 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
| 955 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 962 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
| 956 | $scope.$broadcast('cleanCabecera'); | 963 | $scope.$broadcast('cleanCabecera'); |
| 957 | 964 | ||
| 958 | $scope.cabeceras = []; | 965 | $scope.cabeceras = []; |
| 959 | 966 | ||
| 960 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 967 | if (notaPedido.cotizacion.moneda.codigo !== 'PES') { |
| 961 | $scope.cabeceras.push({ | 968 | $scope.cabeceras.push({ |
| 962 | label: 'Moneda:', | 969 | label: 'Moneda:', |
| 963 | valor: notaPedido.cotizacion.moneda.DETALLE | 970 | valor: notaPedido.cotizacion.moneda.DETALLE |
| 964 | }); | 971 | }); |
| 965 | $scope.cabeceras.push({ | 972 | $scope.cabeceras.push({ |
| 966 | label: 'Fecha cotizacion:', | 973 | label: 'Fecha cotizacion:', |
| 967 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 974 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
| 968 | 'dd/MM/yyyy') | 975 | 'dd/MM/yyyy') |
| 969 | }); | 976 | }); |
| 970 | $scope.cabeceras.push({ | 977 | $scope.cabeceras.push({ |
| 971 | label: 'Cotizacion:', | 978 | label: 'Cotizacion:', |
| 972 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 979 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
| 973 | '2') | 980 | '2') |
| 974 | }); | 981 | }); |
| 975 | } | 982 | } |
| 976 | 983 | ||
| 977 | if (notaPedido.cotizacion.moneda) { | 984 | if (notaPedido.cotizacion.moneda) { |
| 978 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; | 985 | $filter('filter')($scope.botonera, { label: 'Moneda' })[0].checked = true; |
| 979 | } | 986 | } |
| 980 | 987 | ||
| 981 | if (notaPedido.vendedor.NUM) { | 988 | // if (notaPedido.vendedor.NUM) { |
| 982 | $scope.cabeceras.push({ | 989 | // $scope.cabeceras.push({ |
| 983 | label: 'Vendedor:', | 990 | // label: 'Vendedor:', |
| 984 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 991 | // valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
| 985 | ' - ' + notaPedido.vendedor.NOM | 992 | // ' - ' + notaPedido.vendedor.NOM |
| 986 | }); | 993 | // }); |
| 987 | } | 994 | // } |
| 988 | 995 | ||
| 989 | if (notaPedido.cliente.COD) { | 996 | if (notaPedido.cliente.COD) { |
| 990 | $scope.cabeceras.push({ | 997 | $scope.cabeceras.push({ |
| 991 | label: 'Cliente:', | 998 | label: 'Cliente:', |
| 992 | valor: notaPedido.cliente.NOM | 999 | valor: notaPedido.cliente.NOM |
| 993 | }); | 1000 | }); |
| 994 | $scope.cabeceras.push({ | 1001 | $scope.cabeceras.push({ |
| 995 | label: 'Domicilio:', | 1002 | label: 'Domicilio:', |
| 996 | valor: notaPedido.domicilioStamp | 1003 | valor: notaPedido.domicilioStamp |
| 997 | }); | 1004 | }); |
| 998 | 1005 | ||
| 999 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; | 1006 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = true; |
| 1000 | } | 1007 | } |
| 1001 | 1008 | ||
| 1002 | if (notaPedido.proveedor.COD) { | 1009 | if (notaPedido.proveedor.COD) { |
| 1003 | $scope.cabeceras.push({ | 1010 | $scope.cabeceras.push({ |
| 1004 | label: 'Proveedor:', | 1011 | label: 'Proveedor:', |
| 1005 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 1012 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
| 1006 | ' - ' + notaPedido.proveedor.NOM | 1013 | ' - ' + notaPedido.proveedor.NOM |
| 1007 | }); | 1014 | }); |
| 1008 | 1015 | ||
| 1009 | $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; | 1016 | $filter('filter')($scope.botonera, { label: 'Proveedor' })[0].checked = true; |
| 1010 | } | 1017 | } |
| 1011 | 1018 | ||
| 1012 | if (notaPedido.notaPedidoPlazo.length) { | 1019 | if (notaPedido.notaPedidoPlazo.length) { |
| 1013 | valorPrecioCondicion(); | 1020 | valorPrecioCondicion(); |
| 1014 | $filter('filter')($scope.botonera, | 1021 | $filter('filter')($scope.botonera, |
| 1015 | { label: 'Precios y condiciones' })[0].checked = true; | 1022 | { label: 'Precios y condiciones' })[0].checked = true; |
| 1016 | } | 1023 | } |
| 1017 | 1024 | ||
| 1018 | if (notaPedido.flete !== undefined) { | 1025 | if (notaPedido.flete !== undefined) { |
| 1019 | $scope.cabeceras.push({ | 1026 | $scope.cabeceras.push({ |
| 1020 | label: 'Flete:', | 1027 | label: 'Flete:', |
| 1021 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 1028 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
| 1022 | notaPedido.flete === 1 ? 'Si' : 'No') | 1029 | notaPedido.flete === 1 ? 'Si' : 'No') |
| 1023 | }); | 1030 | }); |
| 1024 | } | 1031 | } |
| 1025 | 1032 | ||
| 1026 | function valorPrecioCondicion() { | 1033 | function valorPrecioCondicion() { |
| 1027 | if (notaPedido.idListaPrecio > 0) { | 1034 | if (notaPedido.idListaPrecio > 0) { |
| 1028 | crearNotaPedidoService | 1035 | crearNotaPedidoService |
| 1029 | .getPrecioCondicionById(parseInt(notaPedido.idListaPrecio)) | 1036 | .getPrecioCondicionById(parseInt(notaPedido.idListaPrecio)) |
| 1030 | .then(function (res) { | 1037 | .then(function (res) { |
| 1031 | $scope.cabeceras.push({ | 1038 | $scope.cabeceras.push({ |
| 1032 | label: 'Precios y Condiciones:', | 1039 | label: 'Precios y Condiciones:', |
| 1033 | valor: parseInt(res.data[0].ID) + ' - ' + | 1040 | valor: parseInt(res.data[0].ID) + ' - ' + |
| 1034 | res.data[0].DES + ' ' + | 1041 | res.data[0].DES + ' ' + |
| 1035 | notaPedidoBusinessService | 1042 | notaPedidoBusinessService |
| 1036 | .plazoToString(notaPedido.notaPedidoPlazo) | 1043 | .plazoToString(notaPedido.notaPedidoPlazo) |
| 1037 | }); | 1044 | }); |
| 1038 | addArrayCabecera($scope.cabeceras); | 1045 | addArrayCabecera($scope.cabeceras); |
| 1039 | }); | 1046 | }); |
| 1040 | } | 1047 | } |
| 1041 | $scope.idLista = parseInt(notaPedido.idListaPrecio); | 1048 | $scope.idLista = parseInt(notaPedido.idListaPrecio); |
| 1042 | } | 1049 | } |
| 1043 | 1050 | ||
| 1044 | if (notaPedido.flete === 1) { | 1051 | if (notaPedido.flete === 1) { |
| 1045 | var cabeceraBomba = { | 1052 | var cabeceraBomba = { |
| 1046 | label: 'Bomba:', | 1053 | label: 'Bomba:', |
| 1047 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 1054 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
| 1048 | }; | 1055 | }; |
| 1049 | if (notaPedido.kilometros) { | 1056 | if (notaPedido.kilometros) { |
| 1050 | var cabeceraKilometros = { | 1057 | var cabeceraKilometros = { |
| 1051 | label: 'Kilometros:', | 1058 | label: 'Kilometros:', |
| 1052 | valor: notaPedido.kilometros | 1059 | valor: notaPedido.kilometros |
| 1053 | }; | 1060 | }; |
| 1054 | $scope.cabeceras.push(cabeceraKilometros); | 1061 | $scope.cabeceras.push(cabeceraKilometros); |
| 1055 | } | 1062 | } |
| 1056 | $scope.cabeceras.push(cabeceraBomba); | 1063 | $scope.cabeceras.push(cabeceraBomba); |
| 1057 | } | 1064 | } |
| 1058 | 1065 | ||
| 1059 | if (notaPedido.idPrecioCondicion > 0) { | 1066 | if (notaPedido.idPrecioCondicion > 0) { |
| 1060 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 1067 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
| 1061 | } else if (notaPedido.idPrecioCondicion) { | 1068 | } else if (notaPedido.idPrecioCondicion) { |
| 1062 | $scope.idLista = -1; | 1069 | $scope.idLista = -1; |
| 1063 | } | 1070 | } |
| 1064 | 1071 | ||
| 1065 | $scope.puntoVenta = $filter('rellenarDigitos')( | 1072 | $scope.puntoVenta = $filter('rellenarDigitos')( |
| 1066 | notaPedido.sucursal, 4 | 1073 | notaPedido.sucursal, 4 |
| 1067 | ); | 1074 | ); |
| 1068 | 1075 | ||
| 1069 | $scope.comprobante = $filter('rellenarDigitos')( | 1076 | $scope.comprobante = $filter('rellenarDigitos')( |
| 1070 | notaPedido.numeroNotaPedido, 8 | 1077 | notaPedido.numeroNotaPedido, 8 |
| 1071 | ); | 1078 | ); |
| 1072 | 1079 | ||
| 1073 | if (notaPedido.notaPedidoPuntoDescarga.length) { | 1080 | if (notaPedido.notaPedidoPuntoDescarga.length) { |
| 1074 | var puntos = []; | 1081 | var puntos = []; |
| 1075 | notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) { | 1082 | notaPedido.notaPedidoPuntoDescarga.forEach(function (notaPedidoPuntoDescarga) { |
| 1076 | puntos.push(notaPedidoPuntoDescarga.puntoDescarga); | 1083 | puntos.push(notaPedidoPuntoDescarga.puntoDescarga); |
| 1077 | }); | 1084 | }); |
| 1078 | $scope.cabeceras.push({ | 1085 | $scope.cabeceras.push({ |
| 1079 | label: 'Puntos de descarga: ', | 1086 | label: 'Puntos de descarga: ', |
| 1080 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) | 1087 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) |
| 1081 | }); | 1088 | }); |
| 1082 | } | 1089 | } |
| 1083 | 1090 | ||
| 1084 | addArrayCabecera($scope.cabeceras); | 1091 | addArrayCabecera($scope.cabeceras); |
| 1085 | } | 1092 | } |
| 1086 | 1093 | ||
| 1087 | function getCabeceraPuntoDescarga(puntoDescarga) { | 1094 | function getCabeceraPuntoDescarga(puntoDescarga) { |
| 1088 | var puntosStamp = ''; | 1095 | var puntosStamp = ''; |
| 1089 | puntoDescarga.forEach(function (punto, idx, arr) { | 1096 | puntoDescarga.forEach(function (punto, idx, arr) { |
| 1090 | puntosStamp += punto.descripcion; | 1097 | puntosStamp += punto.descripcion; |
| 1091 | if ((idx + 1) !== arr.length) puntosStamp += ', '; | 1098 | if ((idx + 1) !== arr.length) puntosStamp += ', '; |
| 1092 | }); | 1099 | }); |
| 1093 | return puntosStamp; | 1100 | return puntosStamp; |
| 1094 | } | 1101 | } |
| 1095 | 1102 | ||
| 1096 | function addArrayCabecera(array) { | 1103 | function addArrayCabecera(array) { |
| 1097 | for (var i = 0; i < array.length; i++) { | 1104 | for (var i = 0; i < array.length; i++) { |
| 1098 | $scope.$broadcast('addCabecera', { | 1105 | $scope.$broadcast('addCabecera', { |
| 1099 | label: array[i].label, | 1106 | label: array[i].label, |
| 1100 | valor: array[i].valor | 1107 | valor: array[i].valor |
| 1101 | }); | 1108 | }); |
| 1102 | } | 1109 | } |
| 1103 | } | 1110 | } |
| 1104 | 1111 | ||
| 1105 | function validarNotaRemitada() { | 1112 | function validarNotaRemitada() { |
| 1106 | if (!$scope.notaPedido.idRemito) { | 1113 | if (!$scope.notaPedido.idRemito) { |
| 1107 | return true; | 1114 | return true; |
| 1108 | } else { | 1115 | } else { |
| 1109 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 1116 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
| 1110 | return false; | 1117 | return false; |
| 1111 | } | 1118 | } |
| 1112 | } | 1119 | } |
| 1113 | 1120 | ||
| 1114 | function removeItemFromArr ( arr, item ) { | 1121 | function removeItemFromArr(arr, item) { |
| 1115 | var i = arr.indexOf( item ); | 1122 | var i = arr.indexOf(item); |
| 1116 | 1123 | ||
| 1117 | if ( i !== -1 ) { | 1124 | if (i !== -1) { |
| 1118 | arr.splice( i, 1 ); | 1125 | arr.splice(i, 1); |
| 1119 | } | 1126 | } |
| 1120 | } | 1127 | } |
| 1121 | 1128 | ||
| 1122 | function salir() { | 1129 | function salir() { |
| 1123 | var confirmacion = false; | 1130 | var confirmacion = false; |
| 1124 | 1131 | ||
| 1125 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { | 1132 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { |
| 1126 | confirmacion = true; | 1133 | confirmacion = true; |
| 1127 | } | 1134 | } |
| 1128 | 1135 | ||
| 1129 | if (confirmacion) { | 1136 | if (confirmacion) { |
| 1130 | focaModalService.confirm( | 1137 | focaModalService.confirm( |
| 1131 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 1138 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 1132 | ).then(function (data) { | 1139 | ).then(function (data) { |
| 1133 | if (data) { | 1140 | if (data) { |
| 1134 | $location.path('/'); | 1141 | $location.path('/'); |
| 1135 | var rutaJson = JSON.parse($localStorage.rutas); | 1142 | var rutaJson = JSON.parse($localStorage.rutas); |
| 1136 | removeItemFromArr( rutaJson, 'venta-nota-pedido/crear' ); | 1143 | removeItemFromArr(rutaJson, 'venta-nota-pedido/crear'); |
| 1137 | $localStorage.rutas = JSON.stringify(rutaJson); | 1144 | $localStorage.rutas = JSON.stringify(rutaJson); |
| 1138 | } | 1145 | } |
| 1139 | }); | 1146 | }); |
| 1140 | } else { | 1147 | } else { |
| 1141 | $location.path('/'); | 1148 | $location.path('/'); |
| 1142 | } | 1149 | } |
| 1143 | } | 1150 | } |
| 1144 | 1151 | ||
| 1145 | function getLSNotaPedido() { | 1152 | function getLSNotaPedido() { |
| 1146 | var notaPedido = JSON.parse($localStorage.notaPedido || null); | 1153 | var notaPedido = JSON.parse($localStorage.notaPedido || null); |
| 1147 | if (notaPedido) { | 1154 | if (notaPedido) { |
| 1148 | delete $localStorage.notaPedido; | 1155 | delete $localStorage.notaPedido; |
| 1149 | setearNotaPedido(notaPedido); | 1156 | setearNotaPedido(notaPedido); |
| 1150 | } | 1157 | } |
| 1151 | } | 1158 | } |
| 1152 | 1159 | ||
| 1153 | function deleteCliente() { | 1160 | function deleteCliente() { |
| 1154 | $scope.notaPedido.domicilioStamp = ''; | 1161 | $scope.notaPedido.domicilioStamp = ''; |
| 1155 | $scope.notaPedido.notaPedidoPuntoDescarga = []; | 1162 | $scope.notaPedido.notaPedidoPuntoDescarga = []; |
| 1156 | $scope.notaPedido.domicilio = { dom: '' }; | 1163 | $scope.notaPedido.domicilio = { dom: '' }; |
| 1157 | $scope.notaPedido.cliente = {}; | 1164 | $scope.notaPedido.cliente = {}; |
| 1158 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 1165 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
| 1159 | $scope.$broadcast('removeCabecera', 'Domicilio:'); | 1166 | $scope.$broadcast('removeCabecera', 'Domicilio:'); |
| 1160 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); | 1167 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); |
| 1161 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false; | 1168 | $filter('filter')($scope.botonera, { label: 'Cliente' })[0].checked = false; |
| 1162 | } | 1169 | } |
| 1163 | } | 1170 | } |