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