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