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