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