Commit 63111b1f6921ab73e54bb685652b960ce5d671d5

Authored by Benjamin Rodriguez
1 parent 9d07c5e47c
Exists in master and in 1 other branch develop

bloqueo backdrop de modal clientes

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