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