Commit 8ae2f47312b8d83002a768c0ae14560a5769f5fa
Exists in
master
Merge branch 'develop' of http://git.focasoftware.com/npm/foca-crear-nota-pedido
Showing
1 changed file
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', | 1 | angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl', |
2 | [ | 2 | [ |
3 | '$scope', | 3 | '$scope', |
4 | '$uibModal', | 4 | '$uibModal', |
5 | '$location', | 5 | '$location', |
6 | '$filter', | 6 | '$filter', |
7 | '$timeout', | 7 | '$timeout', |
8 | 'crearNotaPedidoService', | 8 | 'crearNotaPedidoService', |
9 | 'focaBotoneraLateralService', | 9 | 'focaBotoneraLateralService', |
10 | 'focaModalService', | 10 | 'focaModalService', |
11 | 'notaPedidoBusinessService', | 11 | 'notaPedidoBusinessService', |
12 | '$rootScope', | 12 | '$rootScope', |
13 | 'focaSeguimientoService', | 13 | 'focaSeguimientoService', |
14 | 'APP', | 14 | 'APP', |
15 | 'focaLoginService', | 15 | 'focaLoginService', |
16 | '$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 | ivaUnitario: producto.IMPIVA, | 300 | ivaUnitario: producto.IMPIVA, |
298 | impuestoInternoUnitario: producto.ImpInt, | 301 | impuestoInternoUnitario: producto.ImpInt, |
299 | impuestoInterno1Unitario: producto.ImpInt2, | 302 | impuestoInterno1Unitario: producto.ImpInt2, |
300 | impuestoInterno2Unitario: producto.ImpInt3, | 303 | impuestoInterno2Unitario: producto.ImpInt3, |
301 | precioLista: producto.precio, | 304 | precioLista: producto.precio, |
302 | combustible: 1, | 305 | combustible: 1, |
303 | facturado: 0, | 306 | facturado: 0, |
304 | idArticulo: producto.id, | 307 | idArticulo: producto.id, |
305 | tasaIva: producto.tasaIVA | 308 | tasaIva: producto.tasaIVA |
306 | }; | 309 | }; |
307 | 310 | ||
308 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; | 311 | newArt.exentoUnitario = newArt.ivaUnitario ? 0 : producto.neto; |
309 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; | 312 | newArt.netoUnitario = newArt.ivaUnitario ? producto.neto : 0; |
310 | 313 | ||
311 | $scope.articuloACargar = newArt; | 314 | $scope.articuloACargar = newArt; |
312 | $scope.cargando = false; | 315 | $scope.cargando = false; |
313 | }, function() { | 316 | }, function() { |
314 | // funcion ejecutada cuando se cancela el modal | 317 | // funcion ejecutada cuando se cancela el modal |
315 | } | 318 | } |
316 | ); | 319 | ); |
317 | }; | 320 | }; |
318 | 321 | ||
319 | $scope.seleccionarPuntosDeDescarga = function() { | 322 | $scope.seleccionarPuntosDeDescarga = function() { |
320 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { | 323 | if (!$scope.notaPedido.cliente.COD || !$scope.notaPedido.domicilio.id) { |
321 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 324 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
322 | return; | 325 | return; |
323 | } else { | 326 | } else { |
324 | var modalInstance = $uibModal.open( | 327 | var modalInstance = $uibModal.open( |
325 | { | 328 | { |
326 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 329 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
327 | templateUrl: 'modal-punto-descarga.html', | 330 | templateUrl: 'modal-punto-descarga.html', |
328 | controller: 'focaModalPuntoDescargaController', | 331 | controller: 'focaModalPuntoDescargaController', |
329 | size: 'lg', | 332 | size: 'lg', |
330 | resolve: { | 333 | resolve: { |
331 | filters: { | 334 | filters: { |
332 | idDomicilio: $scope.notaPedido.domicilio.id, | 335 | idDomicilio: $scope.notaPedido.domicilio.id, |
333 | idCliente: $scope.notaPedido.cliente.COD, | 336 | idCliente: $scope.notaPedido.cliente.COD, |
334 | articulos: $scope.notaPedido.articulosNotaPedido, | 337 | articulos: $scope.notaPedido.articulosNotaPedido, |
335 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, | 338 | puntoDescarga: $scope.notaPedido.notaPedidoPuntoDescarga, |
336 | domicilio: $scope.notaPedido.domicilio | 339 | domicilio: $scope.notaPedido.domicilio |
337 | } | 340 | } |
338 | } | 341 | } |
339 | } | 342 | } |
340 | ); | 343 | ); |
341 | modalInstance.result.then( | 344 | modalInstance.result.then( |
342 | function(puntoDescarga) { | 345 | function(puntoDescarga) { |
343 | $scope.notaPedido.notaPedidoPuntoDescarga = puntoDescarga; | 346 | $scope.notaPedido.notaPedidoPuntoDescarga = puntoDescarga; |
344 | 347 | ||
345 | $scope.$broadcast('addCabecera', { | 348 | $scope.$broadcast('addCabecera', { |
346 | label: 'Puntos de descarga:', | 349 | label: 'Puntos de descarga:', |
347 | valor: getCabeceraPuntoDescarga(puntoDescarga) | 350 | valor: getCabeceraPuntoDescarga(puntoDescarga) |
348 | }); | 351 | }); |
349 | }, function() { | 352 | }, function() { |
350 | $scope.abrirModalDomicilios($scope.cliente); | 353 | $scope.abrirModalDomicilios($scope.cliente); |
351 | } | 354 | } |
352 | ); | 355 | ); |
353 | } | 356 | } |
354 | }; | 357 | }; |
355 | 358 | ||
356 | $scope.seleccionarProveedor = function() { | 359 | $scope.seleccionarProveedor = function() { |
357 | $scope.abrirModalProveedores(function() { | 360 | $scope.abrirModalProveedores(function() { |
358 | if (validarNotaRemitada()) { | 361 | if (validarNotaRemitada()) { |
359 | var modalInstance = $uibModal.open( | 362 | var modalInstance = $uibModal.open( |
360 | { | 363 | { |
361 | ariaLabelledBy: 'Busqueda de Flete', | 364 | ariaLabelledBy: 'Busqueda de Flete', |
362 | templateUrl: 'modal-flete.html', | 365 | templateUrl: 'modal-flete.html', |
363 | controller: 'focaModalFleteController', | 366 | controller: 'focaModalFleteController', |
364 | size: 'lg', | 367 | size: 'lg', |
365 | resolve: { | 368 | resolve: { |
366 | parametrosFlete: | 369 | parametrosFlete: |
367 | function() { | 370 | function() { |
368 | return { | 371 | return { |
369 | flete: $scope.notaPedido.fob ? 'FOB' : | 372 | flete: $scope.notaPedido.fob ? 'FOB' : |
370 | ( $scope.notaPedido.flete ? '1' : | 373 | ( $scope.notaPedido.flete ? '1' : |
371 | ($scope.notaPedido.flete === undefined ? | 374 | ($scope.notaPedido.flete === undefined ? |
372 | null : '0')), | 375 | null : '0')), |
373 | bomba: $scope.notaPedido.bomba ? '1' : | 376 | bomba: $scope.notaPedido.bomba ? '1' : |
374 | ($scope.notaPedido.bomba === undefined ? | 377 | ($scope.notaPedido.bomba === undefined ? |
375 | null : '0'), | 378 | null : '0'), |
376 | kilometros: $scope.notaPedido.kilometros | 379 | kilometros: $scope.notaPedido.kilometros |
377 | }; | 380 | }; |
378 | } | 381 | } |
379 | } | 382 | } |
380 | } | 383 | } |
381 | ); | 384 | ); |
382 | modalInstance.result.then( | 385 | modalInstance.result.then( |
383 | function(datos) { | 386 | function(datos) { |
384 | $scope.notaPedido.flete = datos.flete; | 387 | $scope.notaPedido.flete = datos.flete; |
385 | $scope.notaPedido.fob = datos.FOB; | 388 | $scope.notaPedido.fob = datos.FOB; |
386 | $scope.notaPedido.bomba = datos.bomba; | 389 | $scope.notaPedido.bomba = datos.bomba; |
387 | $scope.notaPedido.kilometros = datos.kilometros; | 390 | $scope.notaPedido.kilometros = datos.kilometros; |
388 | $scope.$broadcast('addCabecera', { | 391 | $scope.$broadcast('addCabecera', { |
389 | label: 'Flete:', | 392 | label: 'Flete:', |
390 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') | 393 | valor: datos.FOB ? 'FOB' : (datos.flete ? 'Si' : 'No') |
391 | }); | 394 | }); |
392 | if (datos.flete) { | 395 | if (datos.flete) { |
393 | $scope.$broadcast('addCabecera', { | 396 | $scope.$broadcast('addCabecera', { |
394 | label: 'Bomba:', | 397 | label: 'Bomba:', |
395 | valor: datos.bomba ? 'Si' : 'No' | 398 | valor: datos.bomba ? 'Si' : 'No' |
396 | }); | 399 | }); |
397 | $scope.$broadcast('addCabecera', { | 400 | $scope.$broadcast('addCabecera', { |
398 | label: 'Kilometros:', | 401 | label: 'Kilometros:', |
399 | valor: datos.kilometros | 402 | valor: datos.kilometros |
400 | }); | 403 | }); |
401 | } else { | 404 | } else { |
402 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 405 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
403 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 406 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
404 | $scope.notaPedido.bomba = false; | 407 | $scope.notaPedido.bomba = false; |
405 | $scope.notaPedido.kilometros = null; | 408 | $scope.notaPedido.kilometros = null; |
406 | } | 409 | } |
407 | }, function() { | 410 | }, function() { |
408 | $scope.seleccionarTransportista(); | 411 | $scope.seleccionarTransportista(); |
409 | } | 412 | } |
410 | ); | 413 | ); |
411 | } | 414 | } |
412 | }); | 415 | }); |
413 | }; | 416 | }; |
414 | 417 | ||
415 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { | 418 | $scope.seleccionarVendedor = function(callback, ocultarVendedor) { |
416 | if (APP === 'distribuidor' || ocultarVendedor) { | 419 | if (APP === 'distribuidor' || ocultarVendedor) { |
417 | callback(); | 420 | callback(); |
418 | return; | 421 | return; |
419 | } | 422 | } |
420 | 423 | ||
421 | if (validarNotaRemitada()) { | 424 | if (validarNotaRemitada()) { |
422 | var parametrosModal = { | 425 | var parametrosModal = { |
423 | titulo: 'Búsqueda vendedores', | 426 | titulo: 'Búsqueda vendedores', |
424 | query: '/vendedor', | 427 | query: '/vendedor', |
425 | columnas: [ | 428 | columnas: [ |
426 | { | 429 | { |
427 | propiedad: 'NUM', | 430 | propiedad: 'NUM', |
428 | nombre: 'Código', | 431 | nombre: 'Código', |
429 | filtro: { | 432 | filtro: { |
430 | nombre: 'rellenarDigitos', | 433 | nombre: 'rellenarDigitos', |
431 | parametro: 3 | 434 | parametro: 3 |
432 | } | 435 | } |
433 | }, | 436 | }, |
434 | { | 437 | { |
435 | propiedad: 'NOM', | 438 | propiedad: 'NOM', |
436 | nombre: 'Nombre' | 439 | nombre: 'Nombre' |
437 | } | 440 | } |
438 | ], | 441 | ], |
439 | size: 'md' | 442 | size: 'md' |
440 | }; | 443 | }; |
441 | focaModalService.modal(parametrosModal).then( | 444 | focaModalService.modal(parametrosModal).then( |
442 | function(vendedor) { | 445 | function(vendedor) { |
443 | $scope.$broadcast('addCabecera', { | 446 | $scope.$broadcast('addCabecera', { |
444 | label: 'Vendedor:', | 447 | label: 'Vendedor:', |
445 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 448 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
446 | vendedor.NOM | 449 | vendedor.NOM |
447 | }); | 450 | }); |
448 | $scope.notaPedido.vendedor = vendedor; | 451 | $scope.notaPedido.vendedor = vendedor; |
449 | deleteCliente(); | 452 | deleteCliente(); |
450 | callback(); | 453 | callback(); |
451 | }, function() {} | 454 | }, function() {} |
452 | ); | 455 | ); |
453 | } | 456 | } |
454 | }; | 457 | }; |
455 | 458 | ||
456 | $scope.seleccionarCliente = function(ocultarVendedor) { | 459 | $scope.seleccionarCliente = function(ocultarVendedor) { |
457 | $scope.seleccionarVendedor(function() { | 460 | $scope.seleccionarVendedor(function() { |
458 | if (validarNotaRemitada()) { | 461 | if (validarNotaRemitada()) { |
459 | var modalInstance = $uibModal.open( | 462 | var modalInstance = $uibModal.open( |
460 | { | 463 | { |
461 | ariaLabelledBy: 'Busqueda de Cliente', | 464 | ariaLabelledBy: 'Busqueda de Cliente', |
462 | templateUrl: 'foca-busqueda-cliente-modal.html', | 465 | templateUrl: 'foca-busqueda-cliente-modal.html', |
463 | controller: 'focaBusquedaClienteModalController', | 466 | controller: 'focaBusquedaClienteModalController', |
464 | resolve: { | 467 | resolve: { |
465 | vendedor: function() { return $scope.notaPedido.vendedor; }, | 468 | vendedor: function() { return $scope.notaPedido.vendedor; }, |
466 | cobrador: function() { return null; } | 469 | cobrador: function() { return null; } |
467 | }, | 470 | }, |
468 | size: 'lg' | 471 | size: 'lg' |
469 | } | 472 | } |
470 | ); | 473 | ); |
471 | modalInstance.result.then( | 474 | modalInstance.result.then( |
472 | function(cliente) { | 475 | function(cliente) { |
473 | $scope.abrirModalDomicilios(cliente); | 476 | $scope.abrirModalDomicilios(cliente); |
474 | $scope.cliente = cliente; | 477 | $scope.cliente = cliente; |
475 | }, function() { | 478 | }, function() { |
476 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); | 479 | if (APP !== 'distribuidor') $scope.seleccionarCliente(); |
477 | } | 480 | } |
478 | ); | 481 | ); |
479 | } | 482 | } |
480 | }, ocultarVendedor); | 483 | }, ocultarVendedor); |
481 | }; | 484 | }; |
482 | 485 | ||
483 | $scope.abrirModalProveedores = function(callback) { | 486 | $scope.abrirModalProveedores = function(callback) { |
484 | if (validarNotaRemitada()) { | 487 | if (validarNotaRemitada()) { |
485 | var parametrosModal = { | 488 | var parametrosModal = { |
486 | titulo: 'Búsqueda de Proveedor', | 489 | titulo: 'Búsqueda de Proveedor', |
487 | query: '/proveedor', | 490 | query: '/proveedor', |
488 | columnas: [ | 491 | columnas: [ |
489 | { | 492 | { |
490 | nombre: 'Código', | 493 | nombre: 'Código', |
491 | propiedad: 'COD', | 494 | propiedad: 'COD', |
492 | filtro: { | 495 | filtro: { |
493 | nombre: 'rellenarDigitos', | 496 | nombre: 'rellenarDigitos', |
494 | parametro: 5 | 497 | parametro: 5 |
495 | } | 498 | } |
496 | }, | 499 | }, |
497 | { | 500 | { |
498 | nombre: 'Nombre', | 501 | nombre: 'Nombre', |
499 | propiedad: 'NOM' | 502 | propiedad: 'NOM' |
500 | }, | 503 | }, |
501 | { | 504 | { |
502 | nombre: 'CUIT', | 505 | nombre: 'CUIT', |
503 | propiedad: 'CUIT' | 506 | propiedad: 'CUIT' |
504 | } | 507 | } |
505 | ], | 508 | ], |
506 | tipo: 'POST', | 509 | tipo: 'POST', |
507 | json: {razonCuitCod: ''} | 510 | json: {razonCuitCod: ''} |
508 | }; | 511 | }; |
509 | focaModalService.modal(parametrosModal).then( | 512 | focaModalService.modal(parametrosModal).then( |
510 | function(proveedor) { | 513 | function(proveedor) { |
511 | $scope.notaPedido.proveedor = proveedor; | 514 | $scope.notaPedido.proveedor = proveedor; |
512 | $scope.$broadcast('addCabecera', { | 515 | $scope.$broadcast('addCabecera', { |
513 | label: 'Proveedor:', | 516 | label: 'Proveedor:', |
514 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 517 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
515 | proveedor.NOM | 518 | proveedor.NOM |
516 | }); | 519 | }); |
517 | callback(); | 520 | callback(); |
518 | }, function() { | 521 | }, function() { |
519 | 522 | ||
520 | } | 523 | } |
521 | ); | 524 | ); |
522 | } | 525 | } |
523 | }; | 526 | }; |
524 | 527 | ||
525 | $scope.abrirModalDomicilios = function(cliente) { | 528 | $scope.abrirModalDomicilios = function(cliente) { |
526 | var modalInstanceDomicilio = $uibModal.open( | 529 | var modalInstanceDomicilio = $uibModal.open( |
527 | { | 530 | { |
528 | ariaLabelledBy: 'Busqueda de Domicilios', | 531 | ariaLabelledBy: 'Busqueda de Domicilios', |
529 | templateUrl: 'modal-domicilio.html', | 532 | templateUrl: 'modal-domicilio.html', |
530 | controller: 'focaModalDomicilioController', | 533 | controller: 'focaModalDomicilioController', |
531 | resolve: { | 534 | resolve: { |
532 | idCliente: function() { return cliente.cod; }, | 535 | idCliente: function() { return cliente.cod; }, |
533 | esNuevo: function() { return cliente.esNuevo; } | 536 | esNuevo: function() { return cliente.esNuevo; } |
534 | }, | 537 | }, |
535 | size: 'lg', | 538 | size: 'lg', |
536 | } | 539 | } |
537 | ); | 540 | ); |
538 | modalInstanceDomicilio.result.then( | 541 | modalInstanceDomicilio.result.then( |
539 | function(domicilio) { | 542 | function(domicilio) { |
540 | $scope.notaPedido.domicilio = domicilio; | 543 | $scope.notaPedido.domicilio = domicilio; |
541 | $scope.notaPedido.cliente = { | 544 | $scope.notaPedido.cliente = { |
542 | COD: cliente.cod, | 545 | COD: cliente.cod, |
543 | CUIT: cliente.cuit, | 546 | CUIT: cliente.cuit, |
544 | NOM: cliente.nom, | 547 | NOM: cliente.nom, |
545 | MOD: cliente.mod | 548 | MOD: cliente.mod |
546 | }; | 549 | }; |
547 | var domicilioStamp = | 550 | var domicilioStamp = |
548 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 551 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
549 | domicilio.Localidad + ', ' + domicilio.Provincia; | 552 | domicilio.Localidad + ', ' + domicilio.Provincia; |
550 | $scope.notaPedido.domicilioStamp = domicilioStamp; | 553 | $scope.notaPedido.domicilioStamp = domicilioStamp; |
551 | 554 | ||
552 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntoDescarga; | 555 | $scope.notaPedido.notaPedidoPuntoDescarga = domicilio.puntoDescarga; |
553 | 556 | ||
554 | $scope.$broadcast('addCabecera', { | 557 | $scope.$broadcast('addCabecera', { |
555 | label: 'Cliente:', | 558 | label: 'Cliente:', |
556 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom | 559 | valor: $filter('rellenarDigitos')(cliente.cod, 5) + ' - ' + cliente.nom |
557 | }); | 560 | }); |
558 | $scope.$broadcast('addCabecera', { | 561 | $scope.$broadcast('addCabecera', { |
559 | label: 'Domicilio:', | 562 | label: 'Domicilio:', |
560 | valor: domicilioStamp | 563 | valor: domicilioStamp |
561 | }); | 564 | }); |
562 | if (domicilio.verPuntos) { | 565 | if (domicilio.verPuntos) { |
563 | delete $scope.notaPedido.domicilio.verPuntos; | 566 | delete $scope.notaPedido.domicilio.verPuntos; |
564 | $scope.seleccionarPuntosDeDescarga(); | 567 | $scope.seleccionarPuntosDeDescarga(); |
565 | } else { | 568 | } else { |
566 | crearNotaPedidoService | 569 | crearNotaPedidoService |
567 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 570 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
568 | .then(function(res) { | 571 | .then(function(res) { |
569 | if (res.data.length) $scope.seleccionarPuntosDeDescarga(); | 572 | if (res.data.length) $scope.seleccionarPuntosDeDescarga(); |
570 | }); | 573 | }); |
571 | } | 574 | } |
572 | }, function() { | 575 | }, function() { |
573 | $scope.seleccionarCliente(true); | 576 | $scope.seleccionarCliente(true); |
574 | return; | 577 | return; |
575 | } | 578 | } |
576 | ); | 579 | ); |
577 | }; | 580 | }; |
578 | 581 | ||
579 | $scope.getTotal = function() { | 582 | $scope.getTotal = function() { |
580 | var total = 0; | 583 | var total = 0; |
581 | if ($scope.notaPedido.articulosNotaPedido) { | 584 | if ($scope.notaPedido.articulosNotaPedido) { |
582 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; | 585 | var arrayTempArticulos = $scope.notaPedido.articulosNotaPedido; |
583 | for (var i = 0; i < arrayTempArticulos.length; i++) { | 586 | for (var i = 0; i < arrayTempArticulos.length; i++) { |
584 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 587 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
585 | } | 588 | } |
586 | } | 589 | } |
587 | return parseFloat(total.toFixed(2)); | 590 | return parseFloat(total.toFixed(2)); |
588 | }; | 591 | }; |
589 | 592 | ||
590 | $scope.getSubTotal = function() { | 593 | $scope.getSubTotal = function() { |
591 | if ($scope.articuloACargar) { | 594 | if ($scope.articuloACargar) { |
592 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 595 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
593 | } | 596 | } |
594 | }; | 597 | }; |
595 | 598 | ||
596 | $scope.seleccionarPreciosYCondiciones = function() { | 599 | $scope.seleccionarPreciosYCondiciones = function() { |
597 | if (!$scope.notaPedido.cliente.COD) { | 600 | if (!$scope.notaPedido.cliente.COD) { |
598 | focaModalService.alert('Primero seleccione un cliente'); | 601 | focaModalService.alert('Primero seleccione un cliente'); |
599 | return; | 602 | return; |
600 | } | 603 | } |
601 | if ($scope.notaPedido.articulosNotaPedido.length !== 0) { | 604 | if ($scope.notaPedido.articulosNotaPedido.length !== 0) { |
602 | focaModalService.confirm('Se perderan los productos ingresados').then(function(data) { | 605 | focaModalService.confirm('Se perderan los productos ingresados').then(function(data) { |
603 | if (data) { | 606 | if (data) { |
604 | abrirModal(); | 607 | abrirModal(); |
605 | } | 608 | } |
606 | }); | 609 | }); |
607 | } else if (validarNotaRemitada()) { | 610 | } else if (validarNotaRemitada()) { |
608 | abrirModal(); | 611 | abrirModal(); |
609 | } | 612 | } |
610 | function abrirModal() { | 613 | function abrirModal() { |
611 | var modalInstance = $uibModal.open( | 614 | var modalInstance = $uibModal.open( |
612 | { | 615 | { |
613 | ariaLabelledBy: 'Busqueda de Precio Condición', | 616 | ariaLabelledBy: 'Busqueda de Precio Condición', |
614 | templateUrl: 'modal-precio-condicion.html', | 617 | templateUrl: 'modal-precio-condicion.html', |
615 | controller: 'focaModalPrecioCondicionController', | 618 | controller: 'focaModalPrecioCondicionController', |
616 | size: 'lg', | 619 | size: 'lg', |
617 | resolve: { | 620 | resolve: { |
618 | idListaPrecio: function() { | 621 | idListaPrecio: function() { |
619 | return $scope.notaPedido.cliente.MOD || null; | 622 | return $scope.notaPedido.cliente.MOD || null; |
620 | } | 623 | } |
621 | } | 624 | } |
622 | } | 625 | } |
623 | ); | 626 | ); |
624 | 627 | ||
625 | modalInstance.result.then( | 628 | modalInstance.result.then( |
626 | function(precioCondicion) { | 629 | function(precioCondicion) { |
627 | var cabecera = ''; | 630 | var cabecera = ''; |
628 | var plazosConcat = ''; | 631 | var plazosConcat = ''; |
629 | if (!Array.isArray(precioCondicion)) { | 632 | if (!Array.isArray(precioCondicion)) { |
630 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; | 633 | $scope.notaPedido.notaPedidoPlazo = precioCondicion.plazoPago; |
631 | $scope.notaPedido.precioCondicion = precioCondicion; | 634 | $scope.notaPedido.precioCondicion = precioCondicion; |
632 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; | 635 | $scope.notaPedido.idPrecioCondicion = precioCondicion.id; |
633 | $scope.idLista = precioCondicion.idListaPrecio; | 636 | $scope.idLista = precioCondicion.idListaPrecio; |
634 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { | 637 | for (var i = 0; i < precioCondicion.plazoPago.length; i++) { |
635 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 638 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
636 | } | 639 | } |
637 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 640 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
638 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 641 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
639 | } else { //Cuando se ingresan los plazos manualmente | 642 | } else { //Cuando se ingresan los plazos manualmente |
640 | $scope.notaPedido.idPrecioCondicion = 0; | 643 | $scope.notaPedido.idPrecioCondicion = 0; |
641 | //-1, el modal productos busca todos los productos | 644 | //-1, el modal productos busca todos los productos |
642 | $scope.idLista = -1; | 645 | $scope.idLista = -1; |
643 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; | 646 | $scope.notaPedido.notaPedidoPlazo = precioCondicion; |
644 | for (var j = 0; j < precioCondicion.length; j++) { | 647 | for (var j = 0; j < precioCondicion.length; j++) { |
645 | plazosConcat += precioCondicion[j].dias + ' '; | 648 | plazosConcat += precioCondicion[j].dias + ' '; |
646 | } | 649 | } |
647 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 650 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
648 | } | 651 | } |
649 | $scope.notaPedido.articulosNotaPedido = []; | 652 | $scope.notaPedido.articulosNotaPedido = []; |
650 | $scope.$broadcast('addCabecera', { | 653 | $scope.$broadcast('addCabecera', { |
651 | label: 'Precios y condiciones:', | 654 | label: 'Precios y condiciones:', |
652 | valor: cabecera | 655 | valor: cabecera |
653 | }); | 656 | }); |
654 | }, function() { | 657 | }, function() { |
655 | 658 | ||
656 | } | 659 | } |
657 | ); | 660 | ); |
658 | } | 661 | } |
659 | }; | 662 | }; |
660 | 663 | ||
661 | $scope.seleccionarMoneda = function() { | 664 | $scope.seleccionarMoneda = function() { |
662 | if (validarNotaRemitada()) { | 665 | if (validarNotaRemitada()) { |
663 | var parametrosModal = { | 666 | var parametrosModal = { |
664 | titulo: 'Búsqueda de monedas', | 667 | titulo: 'Búsqueda de monedas', |
665 | query: '/moneda', | 668 | query: '/moneda', |
666 | columnas: [ | 669 | columnas: [ |
667 | { | 670 | { |
668 | propiedad: 'DETALLE', | 671 | propiedad: 'DETALLE', |
669 | nombre: 'Nombre' | 672 | nombre: 'Nombre' |
670 | }, | 673 | }, |
671 | { | 674 | { |
672 | propiedad: 'SIMBOLO', | 675 | propiedad: 'SIMBOLO', |
673 | nombre: 'Símbolo' | 676 | nombre: 'Símbolo' |
674 | } | 677 | } |
675 | ], | 678 | ], |
676 | size: 'md' | 679 | size: 'md' |
677 | }; | 680 | }; |
678 | focaModalService.modal(parametrosModal).then( | 681 | focaModalService.modal(parametrosModal).then( |
679 | function(moneda) { | 682 | function(moneda) { |
680 | $scope.abrirModalCotizacion(moneda); | 683 | $scope.abrirModalCotizacion(moneda); |
681 | }, function() { | 684 | }, function() { |
682 | 685 | ||
683 | } | 686 | } |
684 | ); | 687 | ); |
685 | } | 688 | } |
686 | }; | 689 | }; |
687 | 690 | ||
688 | $scope.seleccionarObservaciones = function() { | 691 | $scope.seleccionarObservaciones = function() { |
689 | var observacion = { | 692 | var observacion = { |
690 | titulo: 'Ingrese Observaciones', | 693 | titulo: 'Ingrese Observaciones', |
691 | value: $scope.notaPedido.observaciones, | 694 | value: $scope.notaPedido.observaciones, |
692 | maxlength: 155, | 695 | maxlength: 155, |
693 | textarea: true | 696 | textarea: true |
694 | }; | 697 | }; |
695 | 698 | ||
696 | focaModalService | 699 | focaModalService |
697 | .prompt(observacion) | 700 | .prompt(observacion) |
698 | .then(function(observaciones) { | 701 | .then(function(observaciones) { |
699 | $scope.notaPedido.observaciones = observaciones; | 702 | $scope.notaPedido.observaciones = observaciones; |
700 | }); | 703 | }); |
701 | }; | 704 | }; |
702 | 705 | ||
703 | $scope.abrirModalCotizacion = function(moneda) { | 706 | $scope.abrirModalCotizacion = function(moneda) { |
704 | var modalInstance = $uibModal.open( | 707 | var modalInstance = $uibModal.open( |
705 | { | 708 | { |
706 | ariaLabelledBy: 'Busqueda de Cotización', | 709 | ariaLabelledBy: 'Busqueda de Cotización', |
707 | templateUrl: 'modal-cotizacion.html', | 710 | templateUrl: 'modal-cotizacion.html', |
708 | controller: 'focaModalCotizacionController', | 711 | controller: 'focaModalCotizacionController', |
709 | size: 'lg', | 712 | size: 'lg', |
710 | resolve: { | 713 | resolve: { |
711 | idMoneda: function() { | 714 | idMoneda: function() { |
712 | return moneda.ID; | 715 | return moneda.ID; |
713 | } | 716 | } |
714 | } | 717 | } |
715 | } | 718 | } |
716 | ); | 719 | ); |
717 | modalInstance.result.then( | 720 | modalInstance.result.then( |
718 | function(cotizacion) { | 721 | function(cotizacion) { |
719 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; | 722 | var articulosTablaTemp = $scope.notaPedido.articulosNotaPedido || []; |
720 | for (var i = 0; i < articulosTablaTemp.length; i++) { | 723 | for (var i = 0; i < articulosTablaTemp.length; i++) { |
721 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 724 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
722 | $scope.notaPedido.cotizacion.VENDEDOR; | 725 | $scope.notaPedido.cotizacion.VENDEDOR; |
723 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 726 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
724 | cotizacion.VENDEDOR; | 727 | cotizacion.VENDEDOR; |
725 | } | 728 | } |
726 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; | 729 | $scope.notaPedido.articulosNotaPedido = articulosTablaTemp; |
727 | $scope.notaPedido.cotizacion = cotizacion; | 730 | $scope.notaPedido.cotizacion = cotizacion; |
728 | $scope.notaPedido.cotizacion.moneda = moneda; | 731 | $scope.notaPedido.cotizacion.moneda = moneda; |
729 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { | 732 | if (moneda.DETALLE === 'PESOS ARGENTINOS') { |
730 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 733 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
731 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 734 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
732 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 735 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
733 | } else { | 736 | } else { |
734 | $scope.$broadcast('addCabecera', { | 737 | $scope.$broadcast('addCabecera', { |
735 | label: 'Moneda:', | 738 | label: 'Moneda:', |
736 | valor: moneda.DETALLE | 739 | valor: moneda.DETALLE |
737 | }); | 740 | }); |
738 | $scope.$broadcast('addCabecera', { | 741 | $scope.$broadcast('addCabecera', { |
739 | label: 'Fecha cotizacion:', | 742 | label: 'Fecha cotizacion:', |
740 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 743 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
741 | }); | 744 | }); |
742 | $scope.$broadcast('addCabecera', { | 745 | $scope.$broadcast('addCabecera', { |
743 | label: 'Cotizacion:', | 746 | label: 'Cotizacion:', |
744 | valor: $filter('number')(cotizacion.VENDEDOR, '2') | 747 | valor: $filter('number')(cotizacion.VENDEDOR, '2') |
745 | }); | 748 | }); |
746 | } | 749 | } |
747 | }, function() { | 750 | }, function() { |
748 | 751 | ||
749 | } | 752 | } |
750 | ); | 753 | ); |
751 | }; | 754 | }; |
752 | 755 | ||
753 | $scope.agregarATabla = function(key) { | 756 | $scope.agregarATabla = function(key) { |
754 | if (key === 13) { | 757 | if (key === 13) { |
755 | if ($scope.articuloACargar.cantidad === undefined || | 758 | if ($scope.articuloACargar.cantidad === undefined || |
756 | $scope.articuloACargar.cantidad === 0 || | 759 | $scope.articuloACargar.cantidad === 0 || |
757 | $scope.articuloACargar.cantidad === null ) { | 760 | $scope.articuloACargar.cantidad === null ) { |
758 | focaModalService.alert('El valor debe ser al menos 1'); | 761 | focaModalService.alert('El valor debe ser al menos 1'); |
759 | return; | 762 | return; |
760 | } | 763 | } |
761 | delete $scope.articuloACargar.sectorCodigo; | 764 | delete $scope.articuloACargar.sectorCodigo; |
762 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); | 765 | $scope.notaPedido.articulosNotaPedido.push($scope.articuloACargar); |
763 | $scope.cargando = true; | 766 | $scope.cargando = true; |
764 | } | 767 | } |
765 | }; | 768 | }; |
766 | 769 | ||
767 | $scope.quitarArticulo = function(key) { | 770 | $scope.quitarArticulo = function(key) { |
768 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); | 771 | $scope.notaPedido.articulosNotaPedido.splice(key, 1); |
769 | }; | 772 | }; |
770 | 773 | ||
771 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { | 774 | $scope.editarArticulo = function(key, articulo, tmpCantidad, tmpPrecio) { |
772 | if (key === 13) { | 775 | if (key === 13) { |
773 | if (!articulo.cantidad || !articulo.precio) { | 776 | if (!articulo.cantidad || !articulo.precio) { |
774 | focaModalService.alert('Los valores deben ser al menos 1'); | 777 | focaModalService.alert('Los valores deben ser al menos 1'); |
775 | return; | 778 | return; |
776 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { | 779 | } else if (articulo.cantidad < 0 || articulo.precio < 0) { |
777 | focaModalService.alert('Los valores no pueden ser negativos'); | 780 | focaModalService.alert('Los valores no pueden ser negativos'); |
778 | return; | 781 | return; |
779 | } | 782 | } |
780 | articulo.cantidad = tmpCantidad; | 783 | articulo.cantidad = tmpCantidad; |
781 | articulo.precio = tmpPrecio; | 784 | articulo.precio = tmpPrecio; |
782 | $scope.getTotal(); | 785 | $scope.getTotal(); |
783 | articulo.editCantidad = articulo.editPrecio = false; | 786 | articulo.editCantidad = articulo.editPrecio = false; |
784 | } | 787 | } |
785 | }; | 788 | }; |
786 | 789 | ||
787 | $scope.cancelarEditar = function(articulo) { | 790 | $scope.cancelarEditar = function(articulo) { |
788 | $scope.tmpCantidad = articulo.cantidad; | 791 | $scope.tmpCantidad = articulo.cantidad; |
789 | $scope.tmpPrecio = articulo.precio; | 792 | $scope.tmpPrecio = articulo.precio; |
790 | articulo.editCantidad = articulo.editPrecio = false; | 793 | articulo.editCantidad = articulo.editPrecio = false; |
791 | }; | 794 | }; |
792 | 795 | ||
793 | $scope.cambioEdit = function(articulo, propiedad) { | 796 | $scope.cambioEdit = function(articulo, propiedad) { |
794 | if (propiedad === 'cantidad') { | 797 | if (propiedad === 'cantidad') { |
795 | articulo.editCantidad = true; | 798 | articulo.editCantidad = true; |
796 | } else if (propiedad === 'precio') { | 799 | } else if (propiedad === 'precio') { |
797 | articulo.editPrecio = true; | 800 | articulo.editPrecio = true; |
798 | } | 801 | } |
799 | }; | 802 | }; |
800 | 803 | ||
801 | $scope.resetFilter = function() { | 804 | $scope.resetFilter = function() { |
802 | $scope.articuloACargar = {}; | 805 | $scope.articuloACargar = {}; |
803 | $scope.cargando = true; | 806 | $scope.cargando = true; |
804 | }; | 807 | }; |
805 | //Recibe aviso si el teclado está en uso | 808 | //Recibe aviso si el teclado está en uso |
806 | $rootScope.$on('usarTeclado', function(event, data) { | 809 | $rootScope.$on('usarTeclado', function(event, data) { |
807 | if (data) { | 810 | if (data) { |
808 | $scope.mostrarTeclado = true; | 811 | $scope.mostrarTeclado = true; |
809 | return; | 812 | return; |
810 | } | 813 | } |
811 | $scope.mostrarTeclado = false; | 814 | $scope.mostrarTeclado = false; |
812 | }); | 815 | }); |
813 | 816 | ||
814 | $scope.selectFocus = function($event) { | 817 | $scope.selectFocus = function($event) { |
815 | // Si el teclado esta en uso no selecciona el valor | 818 | // Si el teclado esta en uso no selecciona el valor |
816 | if ($scope.mostrarTeclado) { | 819 | if ($scope.mostrarTeclado) { |
817 | return; | 820 | return; |
818 | } | 821 | } |
819 | $event.target.select(); | 822 | $event.target.select(); |
820 | }; | 823 | }; |
821 | 824 | ||
822 | $scope.salir = function() { | 825 | $scope.salir = function() { |
823 | $location.path('/'); | 826 | $location.path('/'); |
824 | }; | 827 | }; |
825 | 828 | ||
826 | $scope.parsearATexto = function(articulo) { | 829 | $scope.parsearATexto = function(articulo) { |
827 | articulo.cantidad = parseFloat(articulo.cantidad); | 830 | articulo.cantidad = parseFloat(articulo.cantidad); |
828 | articulo.precio = parseFloat(articulo.precio); | 831 | articulo.precio = parseFloat(articulo.precio); |
829 | }; | 832 | }; |
830 | 833 | ||
831 | function setearNotaPedido(notaPedido) { | 834 | function setearNotaPedido(notaPedido) { |
832 | //añado cabeceras | 835 | //añado cabeceras |
833 | $scope.notaPedido = notaPedido; | 836 | $scope.notaPedido = notaPedido; |
834 | if (!$scope.notaPedido.domicilio) { | 837 | if (!$scope.notaPedido.domicilio) { |
835 | $scope.notaPedido.domicilio = { | 838 | $scope.notaPedido.domicilio = { |
836 | id: $scope.notaPedido.idDomicilio | 839 | id: $scope.notaPedido.idDomicilio |
837 | }; | 840 | }; |
838 | } | 841 | } |
839 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 842 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
840 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 843 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
841 | $scope.$broadcast('cleanCabecera'); | 844 | $scope.$broadcast('cleanCabecera'); |
842 | 845 | ||
843 | var cabeceras = []; | 846 | var cabeceras = []; |
844 | 847 | ||
845 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { | 848 | if (notaPedido.cotizacion.moneda.CODIGO_AFIP !== 'PES') { |
846 | cabeceras.push({ | 849 | cabeceras.push({ |
847 | label: 'Moneda:', | 850 | label: 'Moneda:', |
848 | valor: notaPedido.cotizacion.moneda.DETALLE | 851 | valor: notaPedido.cotizacion.moneda.DETALLE |
849 | }); | 852 | }); |
850 | cabeceras.push({ | 853 | cabeceras.push({ |
851 | label: 'Fecha cotizacion:', | 854 | label: 'Fecha cotizacion:', |
852 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 855 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
853 | 'dd/MM/yyyy') | 856 | 'dd/MM/yyyy') |
854 | }); | 857 | }); |
855 | cabeceras.push({ | 858 | cabeceras.push({ |
856 | label: 'Cotizacion:', | 859 | label: 'Cotizacion:', |
857 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 860 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
858 | '2') | 861 | '2') |
859 | }); | 862 | }); |
860 | } | 863 | } |
861 | 864 | ||
862 | if (notaPedido.vendedor.NUM) { | 865 | if (notaPedido.vendedor.NUM) { |
863 | cabeceras.push({ | 866 | cabeceras.push({ |
864 | label: 'Vendedor:', | 867 | label: 'Vendedor:', |
865 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + | 868 | valor: $filter('rellenarDigitos')(notaPedido.vendedor.NUM, 3) + |
866 | ' - ' + notaPedido.vendedor.NOM | 869 | ' - ' + notaPedido.vendedor.NOM |
867 | }); | 870 | }); |
868 | } | 871 | } |
869 | 872 | ||
870 | if (notaPedido.cliente.COD) { | 873 | if (notaPedido.cliente.COD) { |
871 | cabeceras.push({ | 874 | cabeceras.push({ |
872 | label: 'Cliente:', | 875 | label: 'Cliente:', |
873 | valor: notaPedido.cliente.NOM | 876 | valor: notaPedido.cliente.NOM |
874 | }); | 877 | }); |
875 | cabeceras.push({ | 878 | cabeceras.push({ |
876 | label: 'Domicilio:', | 879 | label: 'Domicilio:', |
877 | valor: notaPedido.domicilioStamp | 880 | valor: notaPedido.domicilioStamp |
878 | }); | 881 | }); |
879 | } | 882 | } |
880 | 883 | ||
881 | if (notaPedido.proveedor.COD) { | 884 | if (notaPedido.proveedor.COD) { |
882 | cabeceras.push({ | 885 | cabeceras.push({ |
883 | label: 'Proveedor:', | 886 | label: 'Proveedor:', |
884 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + | 887 | valor: $filter('rellenarDigitos')(notaPedido.proveedor.COD, 5) + |
885 | ' - ' + notaPedido.proveedor.NOM | 888 | ' - ' + notaPedido.proveedor.NOM |
886 | }); | 889 | }); |
887 | } | 890 | } |
888 | 891 | ||
889 | if (notaPedido.notaPedidoPlazo.length) { | 892 | if (notaPedido.notaPedidoPlazo.length) { |
890 | cabeceras.push({ | 893 | cabeceras.push({ |
891 | label: 'Precios y condiciones:', | 894 | label: 'Precios y condiciones:', |
892 | valor: valorPrecioCondicion() + ' ' + | 895 | valor: valorPrecioCondicion() + ' ' + |
893 | notaPedidoBusinessService | 896 | notaPedidoBusinessService |
894 | .plazoToString(notaPedido.notaPedidoPlazo) | 897 | .plazoToString(notaPedido.notaPedidoPlazo) |
895 | }); | 898 | }); |
896 | } | 899 | } |
897 | 900 | ||
898 | if (notaPedido.flete !== undefined) { | 901 | if (notaPedido.flete !== undefined) { |
899 | cabeceras.push({ | 902 | cabeceras.push({ |
900 | label: 'Flete:', | 903 | label: 'Flete:', |
901 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 904 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
902 | notaPedido.flete === 1 ? 'Si' : 'No') | 905 | notaPedido.flete === 1 ? 'Si' : 'No') |
903 | }); | 906 | }); |
904 | } | 907 | } |
905 | 908 | ||
906 | function valorPrecioCondicion() { | 909 | function valorPrecioCondicion() { |
907 | if (notaPedido.idPrecioCondicion > 0) { | 910 | if (notaPedido.idPrecioCondicion > 0) { |
908 | return notaPedido.precioCondicion.nombre; | 911 | return notaPedido.precioCondicion.nombre; |
909 | } else { | 912 | } else { |
910 | return 'Ingreso Manual'; | 913 | return 'Ingreso Manual'; |
911 | } | 914 | } |
912 | } | 915 | } |
913 | 916 | ||
914 | if (notaPedido.flete === 1) { | 917 | if (notaPedido.flete === 1) { |
915 | var cabeceraBomba = { | 918 | var cabeceraBomba = { |
916 | label: 'Bomba:', | 919 | label: 'Bomba:', |
917 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 920 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
918 | }; | 921 | }; |
919 | if (notaPedido.kilometros) { | 922 | if (notaPedido.kilometros) { |
920 | var cabeceraKilometros = { | 923 | var cabeceraKilometros = { |
921 | label: 'Kilometros:', | 924 | label: 'Kilometros:', |
922 | valor: notaPedido.kilometros | 925 | valor: notaPedido.kilometros |
923 | }; | 926 | }; |
924 | cabeceras.push(cabeceraKilometros); | 927 | cabeceras.push(cabeceraKilometros); |
925 | } | 928 | } |
926 | cabeceras.push(cabeceraBomba); | 929 | cabeceras.push(cabeceraBomba); |
927 | } | 930 | } |
928 | 931 | ||
929 | if (notaPedido.idPrecioCondicion > 0) { | 932 | if (notaPedido.idPrecioCondicion > 0) { |
930 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 933 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
931 | } else { | 934 | } else { |
932 | $scope.idLista = -1; | 935 | $scope.idLista = -1; |
933 | } | 936 | } |
934 | 937 | ||
935 | $scope.puntoVenta = $filter('rellenarDigitos')( | 938 | $scope.puntoVenta = $filter('rellenarDigitos')( |
936 | notaPedido.sucursal, 4 | 939 | notaPedido.sucursal, 4 |
937 | ); | 940 | ); |
938 | 941 | ||
939 | $scope.comprobante = $filter('rellenarDigitos')( | 942 | $scope.comprobante = $filter('rellenarDigitos')( |
940 | notaPedido.numeroNotaPedido, 8 | 943 | notaPedido.numeroNotaPedido, 8 |
941 | ); | 944 | ); |
942 | 945 | ||
943 | if (notaPedido.notaPedidoPuntoDescarga) { | 946 | if (notaPedido.notaPedidoPuntoDescarga) { |
944 | var puntos = []; | 947 | var puntos = []; |
945 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga, idx, arr) { | 948 | notaPedido.notaPedidoPuntoDescarga.forEach(function(notaPedidoPuntoDescarga, idx, arr) { |
946 | puntos.push(notaPedidoPuntoDescarga.puntoDescarga); | 949 | puntos.push(notaPedidoPuntoDescarga.puntoDescarga); |
947 | }); | 950 | }); |
948 | cabeceras.push({ | 951 | cabeceras.push({ |
949 | label: 'Puntos de descarga: ', | 952 | label: 'Puntos de descarga: ', |
950 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) | 953 | valor: $filter('rellenarDigitos')(getCabeceraPuntoDescarga(puntos)) |
951 | }); | 954 | }); |
952 | } | 955 | } |
953 | 956 | ||
954 | addArrayCabecera(cabeceras); | 957 | addArrayCabecera(cabeceras); |
955 | } | 958 | } |
956 | 959 | ||
957 | function getCabeceraPuntoDescarga(puntoDescarga){ | 960 | function getCabeceraPuntoDescarga(puntoDescarga){ |
958 | var puntosStamp = ''; | 961 | var puntosStamp = ''; |
959 | puntoDescarga.forEach(function(punto, idx, arr) { | 962 | puntoDescarga.forEach(function(punto, idx, arr) { |
960 | puntosStamp += punto.descripcion; | 963 | puntosStamp += punto.descripcion; |
961 | if ((idx + 1) !== arr.length) puntosStamp += ', '; | 964 | if ((idx + 1) !== arr.length) puntosStamp += ', '; |
962 | }); | 965 | }); |
963 | return puntosStamp; | 966 | return puntosStamp; |
964 | } | 967 | } |
965 | 968 | ||
966 | function addArrayCabecera(array) { | 969 | function addArrayCabecera(array) { |
967 | for (var i = 0; i < array.length; i++) { | 970 | for (var i = 0; i < array.length; i++) { |
968 | $scope.$broadcast('addCabecera', { | 971 | $scope.$broadcast('addCabecera', { |
969 | label: array[i].label, | 972 | label: array[i].label, |
970 | valor: array[i].valor | 973 | valor: array[i].valor |
971 | }); | 974 | }); |
972 | } | 975 | } |
973 | } | 976 | } |
974 | 977 | ||
975 | function validarNotaRemitada() { | 978 | function validarNotaRemitada() { |
976 | if (!$scope.notaPedido.idRemito) { | 979 | if (!$scope.notaPedido.idRemito) { |
977 | return true; | 980 | return true; |
978 | } else { | 981 | } else { |
979 | focaModalService.alert('No se puede editar una nota de pedido remitada'); | 982 | focaModalService.alert('No se puede editar una nota de pedido remitada'); |
980 | return false; | 983 | return false; |
981 | } | 984 | } |
982 | } | 985 | } |
983 | 986 | ||
984 | function salir() { | 987 | function salir() { |
985 | var confirmacion = false; | 988 | var confirmacion = false; |
986 | 989 | ||
987 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { | 990 | if (!angular.equals($scope.notaPedido, $scope.inicial)) { |
988 | confirmacion = true; | 991 | confirmacion = true; |
989 | } | 992 | } |
990 | 993 | ||
991 | if (confirmacion) { | 994 | if (confirmacion) { |
992 | focaModalService.confirm( | 995 | focaModalService.confirm( |
993 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 996 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
994 | ).then(function(data) { | 997 | ).then(function(data) { |
995 | if (data) { | 998 | if (data) { |
996 | $location.path('/'); | 999 | $location.path('/'); |
997 | } | 1000 | } |
998 | }); | 1001 | }); |
999 | } else { | 1002 | } else { |
1000 | $location.path('/'); | 1003 | $location.path('/'); |
1001 | } | 1004 | } |
1002 | } | 1005 | } |
1003 | 1006 | ||
1004 | function getLSNotaPedido() { | 1007 | function getLSNotaPedido() { |
1005 | var notaPedido = JSON.parse($localStorage.notaPedido || null); | 1008 | var notaPedido = JSON.parse($localStorage.notaPedido || null); |
1006 | if (notaPedido) { | 1009 | if (notaPedido) { |
1007 | delete $localStorage.notaPedido; | 1010 | delete $localStorage.notaPedido; |
1008 | setearNotaPedido(notaPedido); | 1011 | setearNotaPedido(notaPedido); |
1009 | } | 1012 | } |
1010 | } | 1013 | } |
1011 | 1014 | ||
1012 | function deleteCliente() { | 1015 | function deleteCliente() { |
1013 | delete $scope.notaPedido.domicilioStamp; | 1016 | delete $scope.notaPedido.domicilioStamp; |
1014 | delete $scope.notaPedido.notaPedidoPuntoDescarga; | 1017 | delete $scope.notaPedido.notaPedidoPuntoDescarga; |
1015 | $scope.notaPedido.domicilio = {dom: ''}; | 1018 | $scope.notaPedido.domicilio = {dom: ''}; |
1016 | $scope.notaPedido.cliente = {}; | 1019 | $scope.notaPedido.cliente = {}; |
1017 | $scope.$broadcast('removeCabecera', 'Cliente:'); | 1020 | $scope.$broadcast('removeCabecera', 'Cliente:'); |
1018 | $scope.$broadcast('removeCabecera', 'Domicilio:'); | 1021 | $scope.$broadcast('removeCabecera', 'Domicilio:'); |
1019 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); | 1022 | $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); |