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