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