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