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