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