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