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