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