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