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