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