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