Commit 4e751b19035f4fe0b06d03010eb934cf3e9bcd29
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !33
Showing
4 changed files
Show diff stats
src/js/controller.js
1 | angular.module('focaCrearRemito') .controller('remitoController', | 1 | angular.module('focaCrearRemito') .controller('remitoController', |
2 | [ | 2 | [ |
3 | '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', | 3 | '$scope', '$uibModal', '$location', '$filter', 'crearRemitoService', '$timeout', |
4 | 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', | 4 | 'focaModalService', 'remitoBusinessService', '$rootScope', 'focaBotoneraLateralService', |
5 | '$window', | ||
6 | function( | 5 | function( |
7 | $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, | 6 | $scope, $uibModal, $location, $filter, crearRemitoService, $timeout, focaModalService, |
8 | remitoBusinessService, $rootScope, focaBotoneraLateralService, $window) | 7 | remitoBusinessService, $rootScope, focaBotoneraLateralService) |
9 | { | 8 | { |
10 | config(); | 9 | config(); |
11 | 10 | ||
12 | function config() { | 11 | function config() { |
13 | $scope.botonera = crearRemitoService.getBotonera(); | 12 | $scope.botonera = crearRemitoService.getBotonera(); |
14 | $scope.isNumber = angular.isNumber; | 13 | $scope.isNumber = angular.isNumber; |
15 | $scope.datepickerAbierto = false; | 14 | $scope.datepickerAbierto = false; |
16 | $scope.show = false; | 15 | $scope.show = false; |
17 | $scope.cargando = true; | 16 | $scope.cargando = true; |
18 | $scope.now = new Date(); | 17 | $scope.now = new Date(); |
19 | $scope.puntoVenta = rellenar(0, 4); | 18 | $scope.puntoVenta = rellenar(0, 4); |
20 | $scope.comprobante = rellenar(0, 8); | 19 | $scope.comprobante = rellenar(0, 8); |
21 | $scope.dateOptions = { | 20 | $scope.dateOptions = { |
22 | maxDate: new Date(), | 21 | maxDate: new Date(), |
23 | minDate: new Date(2010, 0, 1) | 22 | minDate: new Date(2010, 0, 1) |
24 | }; | 23 | }; |
25 | 24 | ||
26 | var monedaPorDefecto; | 25 | var monedaPorDefecto; |
27 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' | 26 | //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]' |
28 | crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { | 27 | crearRemitoService.getCotizacionByIdMoneda(1).then(function(res) { |
29 | monedaPorDefecto = res.data[0]; | 28 | monedaPorDefecto = res.data[0]; |
30 | 29 | ||
31 | $scope.remito.moneda = monedaPorDefecto; | 30 | $scope.remito.moneda = monedaPorDefecto; |
32 | $scope.inicial.remito.moneda = $scope.remito.moneda; | 31 | $scope.inicial.remito.moneda = $scope.remito.moneda; |
33 | 32 | ||
34 | $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0]; | 33 | $scope.remito.cotizacion = monedaPorDefecto.cotizaciones[0]; |
35 | $scope.inicial.remito.cotizacion = $scope.remito.cotizacion; | 34 | $scope.inicial.remito.cotizacion = $scope.remito.cotizacion; |
36 | }); | 35 | }); |
37 | 36 | ||
38 | //SETEO BOTONERA LATERAL | 37 | //SETEO BOTONERA LATERAL |
39 | $timeout(function() { | 38 | $timeout(function() { |
40 | focaBotoneraLateralService.showSalir(false); | 39 | focaBotoneraLateralService.showSalir(false); |
41 | focaBotoneraLateralService.showPausar(true); | 40 | focaBotoneraLateralService.showPausar(true); |
42 | focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); | 41 | focaBotoneraLateralService.showGuardar(true, $scope.crearRemito); |
43 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 42 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
44 | }); | 43 | }); |
45 | 44 | ||
46 | init(); | 45 | init(); |
47 | } | 46 | } |
48 | 47 | ||
49 | function init() { | 48 | function init() { |
50 | $scope.$broadcast('cleanCabecera'); | 49 | $scope.$broadcast('cleanCabecera'); |
51 | 50 | ||
52 | $scope.remito = { | 51 | $scope.remito = { |
53 | id: 0, | 52 | id: 0, |
54 | estado: 0, | 53 | estado: 0, |
55 | vendedor: {}, | 54 | vendedor: {}, |
56 | cliente: {}, | 55 | cliente: {}, |
57 | proveedor: {}, | 56 | proveedor: {}, |
58 | domicilio: {dom: ''}, | 57 | domicilio: {dom: ''}, |
59 | moneda: {}, | 58 | moneda: {}, |
60 | cotizacion: {} | 59 | cotizacion: {} |
61 | }; | 60 | }; |
62 | 61 | ||
63 | $scope.notaPedido = { | 62 | $scope.notaPedido = { |
64 | id: 0 | 63 | id: 0 |
65 | }; | 64 | }; |
66 | 65 | ||
67 | $scope.articulosTabla = []; | 66 | $scope.articulosTabla = []; |
68 | $scope.idLista = undefined; | 67 | $scope.idLista = undefined; |
69 | 68 | ||
70 | crearRemitoService.getNumeroRemito().then( | 69 | crearRemitoService.getNumeroRemito().then( |
71 | function(res) { | 70 | function(res) { |
72 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); | 71 | $scope.puntoVenta = rellenar(res.data.sucursal, 4); |
73 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); | 72 | $scope.comprobante = rellenar(res.data.numeroRemito, 8); |
74 | }, | 73 | }, |
75 | function(err) { | 74 | function(err) { |
76 | focaModalService.alert('La terminal no esta configurada correctamente'); | 75 | focaModalService.alert('La terminal no esta configurada correctamente'); |
77 | console.info(err); | 76 | console.info(err); |
78 | } | 77 | } |
79 | ); | 78 | ); |
80 | 79 | ||
81 | $scope.inicial = { | 80 | $scope.inicial = { |
82 | remito: angular.copy($scope.remito), | 81 | remito: angular.copy($scope.remito), |
83 | notaPedido: angular.copy($scope.notaPedido), | 82 | notaPedido: angular.copy($scope.notaPedido), |
84 | articulosTabla: angular.copy($scope.articulosTabla), | 83 | articulosTabla: angular.copy($scope.articulosTabla), |
85 | idLista: angular.copy($scope.idLista) | 84 | idLista: angular.copy($scope.idLista) |
86 | }; | 85 | }; |
87 | } | 86 | } |
88 | 87 | ||
89 | $scope.seleccionarNotaPedido = function() { | 88 | $scope.seleccionarNotaPedido = function() { |
90 | if(varlidarRemitoFacturado()) { | 89 | if(varlidarRemitoFacturado()) { |
91 | var modalInstance = $uibModal.open( | 90 | var modalInstance = $uibModal.open( |
92 | { | 91 | { |
93 | ariaLabelledBy: 'Busqueda de Nota de Pedido', | 92 | ariaLabelledBy: 'Busqueda de Nota de Pedido', |
94 | templateUrl: 'foca-modal-nota-pedido.html', | 93 | templateUrl: 'foca-modal-nota-pedido.html', |
95 | controller: 'focaModalNotaPedidoController', | 94 | controller: 'focaModalNotaPedidoController', |
96 | size: 'lg', | 95 | size: 'lg', |
97 | resolve: { | 96 | resolve: { |
98 | usadoPor: function() { return 'remito'; }, | 97 | usadoPor: function() { return 'remito'; }, |
99 | idVendedor: function() { return null; } | 98 | idVendedor: function() { return null; } |
100 | } | 99 | } |
101 | } | 100 | } |
102 | ); | 101 | ); |
103 | modalInstance.result.then( | 102 | modalInstance.result.then( |
104 | function(notaPedido) { | 103 | function(notaPedido) { |
105 | //añado cabeceras | 104 | //añado cabeceras |
106 | $scope.notaPedido.id = notaPedido.id; | 105 | $scope.notaPedido.id = notaPedido.id; |
107 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 106 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
108 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 107 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
109 | var cabeceras = [ | 108 | var cabeceras = [ |
110 | { | 109 | { |
111 | label: 'Moneda:', | 110 | label: 'Moneda:', |
112 | valor: notaPedido.cotizacion.moneda.DETALLE | 111 | valor: notaPedido.cotizacion.moneda.DETALLE |
113 | }, | 112 | }, |
114 | { | 113 | { |
115 | label: 'Fecha cotizacion:', | 114 | label: 'Fecha cotizacion:', |
116 | valor: $filter('date')(notaPedido.cotizacion.FECHA, | 115 | valor: $filter('date')(notaPedido.cotizacion.FECHA, |
117 | 'dd/MM/yyyy') | 116 | 'dd/MM/yyyy') |
118 | }, | 117 | }, |
119 | { | 118 | { |
120 | label: 'Cotizacion:', | 119 | label: 'Cotizacion:', |
121 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, | 120 | valor: $filter('number')(notaPedido.cotizacion.VENDEDOR, |
122 | '2') | 121 | '2') |
123 | }, | 122 | }, |
124 | { | 123 | { |
125 | label: 'Cliente:', | 124 | label: 'Cliente:', |
126 | valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + | 125 | valor: $filter('rellenarDigitos')(notaPedido.cliente.COD, 3) + |
127 | ' - ' + notaPedido.cliente.NOM | 126 | ' - ' + notaPedido.cliente.NOM |
128 | }, | 127 | }, |
129 | { | 128 | { |
130 | label: 'Domicilio:', | 129 | label: 'Domicilio:', |
131 | valor: notaPedido.domicilioStamp | 130 | valor: notaPedido.domicilioStamp |
132 | }, | 131 | }, |
133 | { | 132 | { |
134 | label: 'Vendedor:', | 133 | label: 'Vendedor:', |
135 | valor: $filter('rellenarDigitos')( | 134 | valor: $filter('rellenarDigitos')( |
136 | notaPedido.vendedor.NUM, 3 | 135 | notaPedido.vendedor.NUM, 3 |
137 | ) + ' - ' + notaPedido.vendedor.NOM | 136 | ) + ' - ' + notaPedido.vendedor.NOM |
138 | }, | 137 | }, |
139 | { | 138 | { |
140 | label: 'Proveedor:', | 139 | label: 'Proveedor:', |
141 | valor: $filter('rellenarDigitos') | 140 | valor: $filter('rellenarDigitos') |
142 | (notaPedido.proveedor.COD, 5) + ' - ' + | 141 | (notaPedido.proveedor.COD, 5) + ' - ' + |
143 | notaPedido.proveedor.NOM | 142 | notaPedido.proveedor.NOM |
144 | }, | 143 | }, |
145 | { | 144 | { |
146 | label: 'Precio condicion:', | 145 | label: 'Precio condicion:', |
147 | valor: valorPrecioCondicion() + ' ' + | 146 | valor: valorPrecioCondicion() + ' ' + |
148 | remitoBusinessService | 147 | remitoBusinessService |
149 | .plazoToString(notaPedido.notaPedidoPlazo) | 148 | .plazoToString(notaPedido.notaPedidoPlazo) |
150 | }, | 149 | }, |
151 | { | 150 | { |
152 | label: 'Flete:', | 151 | label: 'Flete:', |
153 | valor: notaPedido.fob === 1 ? 'FOB' : ( | 152 | valor: notaPedido.fob === 1 ? 'FOB' : ( |
154 | notaPedido.flete === 1 ? 'Si' : 'No') | 153 | notaPedido.flete === 1 ? 'Si' : 'No') |
155 | } | 154 | } |
156 | ]; | 155 | ]; |
157 | 156 | ||
158 | function valorPrecioCondicion() { | 157 | function valorPrecioCondicion() { |
159 | if(notaPedido.idPrecioCondicion > 0) { | 158 | if(notaPedido.idPrecioCondicion > 0) { |
160 | return notaPedido.precioCondicion.nombre; | 159 | return notaPedido.precioCondicion.nombre; |
161 | }else { | 160 | }else { |
162 | return 'Ingreso Manual'; | 161 | return 'Ingreso Manual'; |
163 | } | 162 | } |
164 | } | 163 | } |
165 | 164 | ||
166 | if(notaPedido.flete === 1) { | 165 | if(notaPedido.flete === 1) { |
167 | var cabeceraBomba = { | 166 | var cabeceraBomba = { |
168 | label: 'Bomba:', | 167 | label: 'Bomba:', |
169 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' | 168 | valor: notaPedido.bomba === 1 ? 'Si' : 'No' |
170 | }; | 169 | }; |
171 | if(notaPedido.kilometros) { | 170 | if(notaPedido.kilometros) { |
172 | var cabeceraKilometros = { | 171 | var cabeceraKilometros = { |
173 | label: 'Kilometros:', | 172 | label: 'Kilometros:', |
174 | valor: notaPedido.kilometros | 173 | valor: notaPedido.kilometros |
175 | }; | 174 | }; |
176 | cabeceras.push(cabeceraKilometros); | 175 | cabeceras.push(cabeceraKilometros); |
177 | } | 176 | } |
178 | cabeceras.push(cabeceraBomba); | 177 | cabeceras.push(cabeceraBomba); |
179 | } | 178 | } |
180 | 179 | ||
181 | for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) { | 180 | for(var i = notaPedido.articulosNotaPedido.length - 1; i >= 0; i--) { |
182 | notaPedido.articulosNotaPedido[i].id = 0; | 181 | notaPedido.articulosNotaPedido[i].id = 0; |
183 | } | 182 | } |
184 | 183 | ||
185 | $scope.articulosTabla = notaPedido.articulosNotaPedido; | 184 | $scope.articulosTabla = notaPedido.articulosNotaPedido; |
186 | remitoBusinessService.calcularArticulos($scope.articulosTabla, | 185 | remitoBusinessService.calcularArticulos($scope.articulosTabla, |
187 | notaPedido.cotizacion.VENDEDOR); | 186 | notaPedido.cotizacion.VENDEDOR); |
188 | 187 | ||
189 | if(notaPedido.idPrecioCondicion > 0) { | 188 | if(notaPedido.idPrecioCondicion > 0) { |
190 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; | 189 | $scope.idLista = notaPedido.precioCondicion.idListaPrecio; |
191 | }else { | 190 | }else { |
192 | $scope.idLista = -1; | 191 | $scope.idLista = -1; |
193 | } | 192 | } |
194 | 193 | ||
195 | delete notaPedido.id; | 194 | delete notaPedido.id; |
196 | $scope.remito = notaPedido; | 195 | $scope.remito = notaPedido; |
197 | $scope.remito.id = 0; | 196 | $scope.remito.id = 0; |
198 | $scope.remito.moneda = notaPedido.cotizacion.moneda; | 197 | $scope.remito.moneda = notaPedido.cotizacion.moneda; |
199 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; | 198 | $scope.plazosPagos = notaPedido.notaPedidoPlazo; |
200 | enableObservaciones(notaPedido.observaciones ? true : false); | 199 | enableObservaciones(notaPedido.observaciones ? true : false); |
201 | addArrayCabecera(cabeceras); | 200 | addArrayCabecera(cabeceras); |
202 | 201 | ||
203 | }, function() { | 202 | }, function() { |
204 | // funcion ejecutada cuando se cancela el modal | 203 | // funcion ejecutada cuando se cancela el modal |
205 | } | 204 | } |
206 | ); | 205 | ); |
207 | } | 206 | } |
208 | }; | 207 | }; |
209 | 208 | ||
210 | $scope.seleccionarRemito = function() { | 209 | $scope.seleccionarRemito = function() { |
211 | var modalInstance = $uibModal.open( | 210 | var modalInstance = $uibModal.open( |
212 | { | 211 | { |
213 | ariaLabelledBy: 'Busqueda de Remito', | 212 | ariaLabelledBy: 'Busqueda de Remito', |
214 | templateUrl: 'foca-modal-remito.html', | 213 | templateUrl: 'foca-modal-remito.html', |
215 | controller: 'focaModalRemitoController', | 214 | controller: 'focaModalRemitoController', |
216 | size: 'lg', | 215 | size: 'lg', |
217 | resolve: {usadoPor: function() {return 'remito';}} | 216 | resolve: {usadoPor: function() {return 'remito';}} |
218 | } | 217 | } |
219 | ); | 218 | ); |
220 | modalInstance.result.then( | 219 | modalInstance.result.then( |
221 | function(remito) { | 220 | function(remito) { |
222 | //añado cabeceras | 221 | //añado cabeceras |
223 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 222 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
224 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 223 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
225 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 224 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
226 | var cabeceras = [ | 225 | var cabeceras = [ |
227 | { | 226 | { |
228 | label: 'Moneda:', | 227 | label: 'Moneda:', |
229 | valor: remito.cotizacion.moneda.DETALLE | 228 | valor: remito.cotizacion.moneda.DETALLE |
230 | }, | 229 | }, |
231 | { | 230 | { |
232 | label: 'Fecha cotizacion:', | 231 | label: 'Fecha cotizacion:', |
233 | valor: $filter('date')(remito.cotizacion.FECHA, | 232 | valor: $filter('date')(remito.cotizacion.FECHA, |
234 | 'dd/MM/yyyy') | 233 | 'dd/MM/yyyy') |
235 | }, | 234 | }, |
236 | { | 235 | { |
237 | label: 'Cotizacion:', | 236 | label: 'Cotizacion:', |
238 | valor: $filter('number')(remito.cotizacion.VENDEDOR, | 237 | valor: $filter('number')(remito.cotizacion.VENDEDOR, |
239 | '2') | 238 | '2') |
240 | }, | 239 | }, |
241 | { | 240 | { |
242 | label: 'Cliente:', | 241 | label: 'Cliente:', |
243 | valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + | 242 | valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + |
244 | remito.cliente.NOM | 243 | remito.cliente.NOM |
245 | }, | 244 | }, |
246 | { | 245 | { |
247 | label: 'Domicilio:', | 246 | label: 'Domicilio:', |
248 | valor: remito.domicilioStamp | 247 | valor: remito.domicilioStamp |
249 | }, | 248 | }, |
250 | { | 249 | { |
251 | label: 'Vendedor:', | 250 | label: 'Vendedor:', |
252 | valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + | 251 | valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + |
253 | ' - ' + remito.vendedor.NOM | 252 | ' - ' + remito.vendedor.NOM |
254 | }, | 253 | }, |
255 | { | 254 | { |
256 | label: 'Proveedor:', | 255 | label: 'Proveedor:', |
257 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + | 256 | valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + |
258 | ' - ' + remito.proveedor.NOM | 257 | ' - ' + remito.proveedor.NOM |
259 | }, | 258 | }, |
260 | { | 259 | { |
261 | label: 'Flete:', | 260 | label: 'Flete:', |
262 | valor: remito.fob === 1 ? 'FOB' : ( | 261 | valor: remito.fob === 1 ? 'FOB' : ( |
263 | remito.flete === 1 ? 'Si' : 'No') | 262 | remito.flete === 1 ? 'Si' : 'No') |
264 | }, | 263 | }, |
265 | { | 264 | { |
266 | label: 'Precio condicion:', | 265 | label: 'Precio condicion:', |
267 | valor: valorPrecioCondicion() + ' ' + | 266 | valor: valorPrecioCondicion() + ' ' + |
268 | remitoBusinessService.plazoToString(remito.remitoPlazo) | 267 | remitoBusinessService.plazoToString(remito.remitoPlazo) |
269 | } | 268 | } |
270 | ]; | 269 | ]; |
271 | function valorPrecioCondicion() { | 270 | function valorPrecioCondicion() { |
272 | if(remito.idPrecioCondicion > 0) { | 271 | if(remito.idPrecioCondicion > 0) { |
273 | return remito.precioCondicion.nombre; | 272 | return remito.precioCondicion.nombre; |
274 | }else { | 273 | }else { |
275 | return 'Ingreso Manual'; | 274 | return 'Ingreso Manual'; |
276 | } | 275 | } |
277 | } | 276 | } |
278 | 277 | ||
279 | if(remito.flete === 1) { | 278 | if(remito.flete === 1) { |
280 | var cabeceraBomba = { | 279 | var cabeceraBomba = { |
281 | label: 'Bomba', | 280 | label: 'Bomba', |
282 | valor: remito.bomba === 1 ? 'Si' : 'No' | 281 | valor: remito.bomba === 1 ? 'Si' : 'No' |
283 | }; | 282 | }; |
284 | if(remito.kilometros) { | 283 | if(remito.kilometros) { |
285 | var cabeceraKilometros = { | 284 | var cabeceraKilometros = { |
286 | label: 'Kilometros', | 285 | label: 'Kilometros', |
287 | valor: remito.kilometros | 286 | valor: remito.kilometros |
288 | }; | 287 | }; |
289 | cabeceras.push(cabeceraKilometros); | 288 | cabeceras.push(cabeceraKilometros); |
290 | } | 289 | } |
291 | cabeceras.push(cabeceraBomba); | 290 | cabeceras.push(cabeceraBomba); |
292 | } | 291 | } |
293 | $scope.articulosTabla = remito.articulosRemito; | 292 | $scope.articulosTabla = remito.articulosRemito; |
294 | remitoBusinessService.calcularArticulos($scope.articulosTabla, | 293 | remitoBusinessService.calcularArticulos($scope.articulosTabla, |
295 | remito.cotizacion.VENDEDOR); | 294 | remito.cotizacion.VENDEDOR); |
296 | if(remito.idPrecioCondicion > 0) { | 295 | if(remito.idPrecioCondicion > 0) { |
297 | $scope.idLista = remito.precioCondicion.idListaPrecio; | 296 | $scope.idLista = remito.precioCondicion.idListaPrecio; |
298 | }else { | 297 | }else { |
299 | $scope.idLista = -1; | 298 | $scope.idLista = -1; |
300 | } | 299 | } |
301 | $scope.puntoVenta = rellenar(remito.sucursal, 4); | 300 | $scope.puntoVenta = rellenar(remito.sucursal, 4); |
302 | $scope.comprobante = rellenar(remito.numeroRemito, 8); | 301 | $scope.comprobante = rellenar(remito.numeroRemito, 8); |
303 | $scope.remito = remito; | 302 | $scope.remito = remito; |
304 | $scope.remito.moneda = remito.cotizacion.moneda; | 303 | $scope.remito.moneda = remito.cotizacion.moneda; |
305 | $scope.plazosPagos = remito.remitoPlazo; | 304 | $scope.plazosPagos = remito.remitoPlazo; |
306 | addArrayCabecera(cabeceras); | 305 | addArrayCabecera(cabeceras); |
307 | }, function() { | 306 | }, function() { |
308 | // funcion ejecutada cuando se cancela el modal | 307 | // funcion ejecutada cuando se cancela el modal |
309 | } | 308 | } |
310 | ); | 309 | ); |
311 | }; | 310 | }; |
312 | 311 | ||
313 | //validacion por domicilio y por plazo pago | 312 | //validacion por domicilio y por plazo pago |
314 | $scope.crearRemito = function() { | 313 | $scope.crearRemito = function() { |
315 | if(!$scope.remito.vendedor) { | 314 | if(!$scope.remito.vendedor) { |
316 | focaModalService.alert('Ingrese Vendedor'); | 315 | focaModalService.alert('Ingrese Vendedor'); |
317 | return; | 316 | return; |
318 | }else if(!$scope.remito.cliente) { | 317 | }else if(!$scope.remito.cliente) { |
319 | focaModalService.alert('Ingrese Cliente'); | 318 | focaModalService.alert('Ingrese Cliente'); |
320 | return; | 319 | return; |
321 | }else if(!$scope.remito.proveedor) { | 320 | }else if(!$scope.remito.proveedor) { |
322 | focaModalService.alert('Ingrese Proveedor'); | 321 | focaModalService.alert('Ingrese Proveedor'); |
323 | return; | 322 | return; |
324 | }else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) { | 323 | }else if(!$scope.remito.moneda.id && !$scope.remito.moneda.ID) { |
325 | focaModalService.alert('Ingrese Moneda'); | 324 | focaModalService.alert('Ingrese Moneda'); |
326 | return; | 325 | return; |
327 | }else if(!$scope.remito.cotizacion.ID) { | 326 | }else if(!$scope.remito.cotizacion.ID) { |
328 | focaModalService.alert('Ingrese Cotización'); | 327 | focaModalService.alert('Ingrese Cotización'); |
329 | return; | 328 | return; |
330 | }else if( | 329 | }else if( |
331 | $scope.remito.flete === undefined || $scope.remito.flete === null) | 330 | $scope.remito.flete === undefined || $scope.remito.flete === null) |
332 | { | 331 | { |
333 | focaModalService.alert('Ingrese Flete'); | 332 | focaModalService.alert('Ingrese Flete'); |
334 | return; | 333 | return; |
335 | }else if($scope.articulosTabla.length === 0) { | 334 | }else if($scope.articulosTabla.length === 0) { |
336 | focaModalService.alert('Debe cargar al menos un articulo'); | 335 | focaModalService.alert('Debe cargar al menos un articulo'); |
337 | return; | 336 | return; |
338 | } | 337 | } |
339 | focaBotoneraLateralService.startGuardar(); | 338 | focaBotoneraLateralService.startGuardar(); |
340 | $scope.saveLoading = true; | 339 | $scope.saveLoading = true; |
341 | var save = { | 340 | var save = { |
342 | remito: { | 341 | remito: { |
343 | id: $scope.remito.id, | 342 | id: $scope.remito.id, |
344 | fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), | 343 | fechaRemito: $scope.now.toISOString().slice(0, 19).replace('T', ' '), |
345 | idCliente: $scope.remito.cliente.COD, | 344 | idCliente: $scope.remito.cliente.COD, |
346 | nombreCliente: $scope.remito.cliente.NOM, | 345 | nombreCliente: $scope.remito.cliente.NOM, |
347 | cuitCliente: $scope.remito.cliente.CUIT, | 346 | cuitCliente: $scope.remito.cliente.CUIT, |
348 | responsabilidadIvaCliente: 0,//TODO, | 347 | responsabilidadIvaCliente: 0,//TODO, |
349 | descuento: 0,//TODO, | 348 | descuento: 0,//TODO, |
350 | importeNeto: 0,//TODO | 349 | importeNeto: 0,//TODO |
351 | importeExento: 0,//TODO | 350 | importeExento: 0,//TODO |
352 | importeIva: 0,//TODO | 351 | importeIva: 0,//TODO |
353 | importeIvaServicios: 0,//TODO | 352 | importeIvaServicios: 0,//TODO |
354 | importeImpuestoInterno: 0,//TODO | 353 | importeImpuestoInterno: 0,//TODO |
355 | importeImpuestoInterno1: 0,//TODO | 354 | importeImpuestoInterno1: 0,//TODO |
356 | importeImpuestoInterno2: 0,//TODO | 355 | importeImpuestoInterno2: 0,//TODO |
357 | percepcion: 0,//TODO | 356 | percepcion: 0,//TODO |
358 | percepcionIva: 0,//TODO | 357 | percepcionIva: 0,//TODO |
359 | redondeo: 0,//TODO | 358 | redondeo: 0,//TODO |
360 | total: $scope.getTotal(), | 359 | total: $scope.getTotal(), |
361 | numeroNotaPedido: $scope.remito.numeroNotaPedido, | 360 | numeroNotaPedido: $scope.remito.numeroNotaPedido, |
362 | anulado: false, | 361 | anulado: false, |
363 | planilla: 0,//TODO | 362 | planilla: 0,//TODO |
364 | lugar: 0,//TODO | 363 | lugar: 0,//TODO |
365 | cuentaMadre: 0,// | 364 | cuentaMadre: 0,// |
366 | cuentaContable: 0,//TODO | 365 | cuentaContable: 0,//TODO |
367 | asiento: 0,//TODO | 366 | asiento: 0,//TODO |
368 | e_hd: '',//TODO | 367 | e_hd: '',//TODO |
369 | c_hd: '', | 368 | c_hd: '', |
370 | numeroLiquidoProducto: 0,//TODO | 369 | numeroLiquidoProducto: 0,//TODO |
371 | idVendedor: $scope.remito.idVendedor, | 370 | idVendedor: $scope.remito.idVendedor, |
372 | idProveedor: $scope.remito.idProveedor, | 371 | idProveedor: $scope.remito.idProveedor, |
373 | idDomicilio: $scope.remito.idDomicilio, | 372 | idDomicilio: $scope.remito.idDomicilio, |
374 | idCotizacion: $scope.remito.cotizacion.ID, | 373 | idCotizacion: $scope.remito.cotizacion.ID, |
375 | idPrecioCondicion: $scope.remito.idPrecioCondicion, | 374 | idPrecioCondicion: $scope.remito.idPrecioCondicion, |
376 | flete: $scope.remito.flete, | 375 | flete: $scope.remito.flete, |
377 | fob: $scope.remito.fob, | 376 | fob: $scope.remito.fob, |
378 | bomba: $scope.remito.bomba, | 377 | bomba: $scope.remito.bomba, |
379 | kilometros: $scope.remito.kilometros, | 378 | kilometros: $scope.remito.kilometros, |
380 | domicilioStamp: $scope.remito.domicilioStamp, | 379 | domicilioStamp: $scope.remito.domicilioStamp, |
381 | estado: 0,//TODO | 380 | estado: 0,//TODO |
382 | destinoVenta: 0,//TODO | 381 | destinoVenta: 0,//TODO |
383 | operacionTipo: 0//TODO | 382 | operacionTipo: 0//TODO |
384 | }, | 383 | }, |
385 | notaPedido: $scope.notaPedido | 384 | notaPedido: $scope.notaPedido |
386 | }; | 385 | }; |
387 | 386 | ||
388 | crearRemitoService.crearRemito(save).then( | 387 | crearRemitoService.crearRemito(save).then( |
389 | function(data) { | 388 | function(data) { |
390 | remitoBusinessService.addArticulos($scope.articulosTabla, | 389 | remitoBusinessService.addArticulos($scope.articulosTabla, |
391 | data.data.id, $scope.remito.cotizacion.COTIZACION); | 390 | data.data.id, $scope.remito.cotizacion.COTIZACION); |
392 | 391 | ||
393 | focaBotoneraLateralService.endGuardar(true); | 392 | focaBotoneraLateralService.endGuardar(true); |
394 | $scope.saveLoading = false; | 393 | $scope.saveLoading = false; |
395 | //TODO: updatear plazos | 394 | //TODO: updatear plazos |
396 | if($scope.remito.id === 0) { | 395 | if($scope.remito.id === 0) { |
397 | var plazos = $scope.plazosPagos; | 396 | var plazos = $scope.plazosPagos; |
398 | 397 | ||
399 | for(var j = 0; j < plazos.length; j++) { | 398 | for(var j = 0; j < plazos.length; j++) { |
400 | var json = { | 399 | var json = { |
401 | idRemito: data.data.id, | 400 | idRemito: data.data.id, |
402 | dias: plazos[j].dias | 401 | dias: plazos[j].dias |
403 | }; | 402 | }; |
404 | crearRemitoService.crearPlazosParaRemito(json); | 403 | crearRemitoService.crearPlazosParaRemito(json); |
405 | } | 404 | } |
406 | } | 405 | } |
407 | crearRemitoService.imprimirRemitoByIdRemito(data.data.id).then( | 406 | $uibModal.open({ |
408 | function(res) { | 407 | templateUrl: 'remito-comprobante.html', |
409 | 408 | controller: 'focaRemitoComprobanteController', | |
410 | var printWindow = $window.open('', '', 'height=1000,width=800'); | 409 | resolve: { |
411 | printWindow.document.write(res.data); | 410 | parametros: { |
412 | printWindow.document.close(); | 411 | remito: $scope.remito |
413 | printWindow.print(); | 412 | } |
414 | |||
415 | } | 413 | } |
416 | ); | 414 | }); |
417 | init(); | 415 | init(); |
418 | }, function(error) { | 416 | }, function(error) { |
419 | focaModalService.alert('Hubo un error al crear el remito'); | 417 | focaModalService.alert('Hubo un error al crear el remito'); |
420 | focaBotoneraLateralService.endGuardar(); | 418 | focaBotoneraLateralService.endGuardar(); |
421 | $scope.saveLoading = false; | 419 | $scope.saveLoading = false; |
422 | console.info(error); | 420 | console.info(error); |
423 | } | 421 | } |
424 | ); | 422 | ); |
425 | }; | 423 | }; |
426 | 424 | ||
427 | $scope.seleccionarProductos = function() { | 425 | $scope.seleccionarProductos = function() { |
428 | if($scope.idLista === undefined) { | 426 | if($scope.idLista === undefined) { |
429 | focaModalService.alert( | 427 | focaModalService.alert( |
430 | 'Primero seleccione una lista de precio y condicion'); | 428 | 'Primero seleccione una lista de precio y condicion'); |
431 | return; | 429 | return; |
432 | } | 430 | } |
433 | var modalInstance = $uibModal.open( | 431 | var modalInstance = $uibModal.open( |
434 | { | 432 | { |
435 | ariaLabelledBy: 'Busqueda de Productos', | 433 | ariaLabelledBy: 'Busqueda de Productos', |
436 | templateUrl: 'modal-busqueda-productos.html', | 434 | templateUrl: 'modal-busqueda-productos.html', |
437 | controller: 'modalBusquedaProductosCtrl', | 435 | controller: 'modalBusquedaProductosCtrl', |
438 | resolve: { | 436 | resolve: { |
439 | parametroProducto: { | 437 | parametroProducto: { |
440 | idLista: $scope.idLista, | 438 | idLista: $scope.idLista, |
441 | cotizacion: $scope.remito.cotizacion.COTIZACION, | 439 | cotizacion: $scope.remito.cotizacion.COTIZACION, |
442 | simbolo: $scope.remito.moneda.simbolo | 440 | simbolo: $scope.remito.moneda.simbolo |
443 | } | 441 | } |
444 | }, | 442 | }, |
445 | size: 'lg' | 443 | size: 'lg' |
446 | } | 444 | } |
447 | ); | 445 | ); |
448 | modalInstance.result.then( | 446 | modalInstance.result.then( |
449 | function(producto) { | 447 | function(producto) { |
450 | var newArt = | 448 | var newArt = |
451 | { | 449 | { |
452 | id: 0, | 450 | id: 0, |
453 | codigo: producto.codigo, | 451 | codigo: producto.codigo, |
454 | sector: producto.sector, | 452 | sector: producto.sector, |
455 | sectorCodigo: producto.sector + '-' + producto.codigo, | 453 | sectorCodigo: producto.sector + '-' + producto.codigo, |
456 | descripcion: producto.descripcion, | 454 | descripcion: producto.descripcion, |
457 | item: $scope.articulosTabla.length + 1, | 455 | item: $scope.articulosTabla.length + 1, |
458 | nombre: producto.descripcion, | 456 | nombre: producto.descripcion, |
459 | precio: parseFloat(producto.precio.toFixed(4)), | 457 | precio: parseFloat(producto.precio.toFixed(4)), |
460 | costoUnitario: producto.costo, | 458 | costoUnitario: producto.costo, |
461 | editCantidad: false, | 459 | editCantidad: false, |
462 | editPrecio: false, | 460 | editPrecio: false, |
463 | rubro: producto.CodRub, | 461 | rubro: producto.CodRub, |
464 | exentoUnitario: producto.precio, | 462 | exentoUnitario: producto.precio, |
465 | ivaUnitario: producto.IMPIVA, | 463 | ivaUnitario: producto.IMPIVA, |
466 | impuestoInternoUnitario: producto.ImpInt, | 464 | impuestoInternoUnitario: producto.ImpInt, |
467 | impuestoInterno1Unitario: producto.ImpInt2, | 465 | impuestoInterno1Unitario: producto.ImpInt2, |
468 | impuestoInterno2Unitario: producto.ImpInt3, | 466 | impuestoInterno2Unitario: producto.ImpInt3, |
469 | precioLista: producto.precio, | 467 | precioLista: producto.precio, |
470 | combustible: 1, | 468 | combustible: 1, |
471 | facturado: 0 | 469 | facturado: 0 |
472 | }; | 470 | }; |
473 | $scope.articuloACargar = newArt; | 471 | $scope.articuloACargar = newArt; |
474 | $scope.cargando = false; | 472 | $scope.cargando = false; |
475 | }, function() { | 473 | }, function() { |
476 | // funcion ejecutada cuando se cancela el modal | 474 | // funcion ejecutada cuando se cancela el modal |
477 | } | 475 | } |
478 | ); | 476 | ); |
479 | }; | 477 | }; |
480 | 478 | ||
481 | $scope.seleccionarPuntosDeDescarga = function() { | 479 | $scope.seleccionarPuntosDeDescarga = function() { |
482 | if(!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { | 480 | if(!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { |
483 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); | 481 | focaModalService.alert('Primero seleccione un cliente y un domicilio'); |
484 | return; | 482 | return; |
485 | }else { | 483 | }else { |
486 | var modalInstance = $uibModal.open( | 484 | var modalInstance = $uibModal.open( |
487 | { | 485 | { |
488 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', | 486 | ariaLabelledBy: 'Búsqueda de Puntos de descarga', |
489 | templateUrl: 'modal-punto-descarga.html', | 487 | templateUrl: 'modal-punto-descarga.html', |
490 | controller: 'focaModalPuntoDescargaController', | 488 | controller: 'focaModalPuntoDescargaController', |
491 | size: 'lg', | 489 | size: 'lg', |
492 | resolve: { | 490 | resolve: { |
493 | filters: { | 491 | filters: { |
494 | idDomicilio: $scope.remito.domicilio.id, | 492 | idDomicilio: $scope.remito.domicilio.id, |
495 | idCliente: $scope.remito.cliente.COD, | 493 | idCliente: $scope.remito.cliente.COD, |
496 | articulos: $scope.articulosTabla, | 494 | articulos: $scope.articulosTabla, |
497 | puntosDescarga: $scope.remito.domicilio.puntosDescarga | 495 | puntosDescarga: $scope.remito.domicilio.puntosDescarga |
498 | } | 496 | } |
499 | } | 497 | } |
500 | } | 498 | } |
501 | ); | 499 | ); |
502 | modalInstance.result.then( | 500 | modalInstance.result.then( |
503 | function(puntosDescarga) { | 501 | function(puntosDescarga) { |
504 | $scope.remito.puntosDescarga = puntosDescarga; | 502 | $scope.remito.puntosDescarga = puntosDescarga; |
505 | 503 | ||
506 | //AGREGO PUNTOS DE DESCARGA A CABECERA | 504 | //AGREGO PUNTOS DE DESCARGA A CABECERA |
507 | var puntosStamp = ''; | 505 | var puntosStamp = ''; |
508 | puntosDescarga.forEach(function(punto, idx, arr) { | 506 | puntosDescarga.forEach(function(punto, idx, arr) { |
509 | puntosStamp += punto.descripcion; | 507 | puntosStamp += punto.descripcion; |
510 | if((idx + 1) !== arr.length) puntosStamp += ', '; | 508 | if((idx + 1) !== arr.length) puntosStamp += ', '; |
511 | }); | 509 | }); |
512 | 510 | ||
513 | $scope.$broadcast('addCabecera', { | 511 | $scope.$broadcast('addCabecera', { |
514 | label: 'Puntos de descarga:', | 512 | label: 'Puntos de descarga:', |
515 | valor: puntosStamp | 513 | valor: puntosStamp |
516 | }); | 514 | }); |
517 | }, function() { | 515 | }, function() { |
518 | $scope.abrirModalDomicilios($scope.cliente); | 516 | $scope.abrirModalDomicilios($scope.cliente); |
519 | } | 517 | } |
520 | ); | 518 | ); |
521 | } | 519 | } |
522 | }; | 520 | }; |
523 | 521 | ||
524 | $scope.seleccionarVendedor = function() { | 522 | $scope.seleccionarVendedor = function() { |
525 | if(varlidarRemitoFacturado()) { | 523 | if(varlidarRemitoFacturado()) { |
526 | var parametrosModal = { | 524 | var parametrosModal = { |
527 | titulo: 'Búsqueda vendedores', | 525 | titulo: 'Búsqueda vendedores', |
528 | query: '/vendedor', | 526 | query: '/vendedor', |
529 | columnas: [ | 527 | columnas: [ |
530 | { | 528 | { |
531 | propiedad: 'NUM', | 529 | propiedad: 'NUM', |
532 | nombre: 'Código', | 530 | nombre: 'Código', |
533 | filtro: { | 531 | filtro: { |
534 | nombre: 'rellenarDigitos', | 532 | nombre: 'rellenarDigitos', |
535 | parametro: 3 | 533 | parametro: 3 |
536 | } | 534 | } |
537 | }, | 535 | }, |
538 | { | 536 | { |
539 | propiedad: 'NOM', | 537 | propiedad: 'NOM', |
540 | nombre: 'Nombre' | 538 | nombre: 'Nombre' |
541 | } | 539 | } |
542 | ], | 540 | ], |
543 | size: 'md' | 541 | size: 'md' |
544 | }; | 542 | }; |
545 | focaModalService.modal(parametrosModal).then( | 543 | focaModalService.modal(parametrosModal).then( |
546 | function(vendedor) { | 544 | function(vendedor) { |
547 | $scope.$broadcast('addCabecera',{ | 545 | $scope.$broadcast('addCabecera',{ |
548 | label: 'Vendedor:', | 546 | label: 'Vendedor:', |
549 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + | 547 | valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + |
550 | vendedor.NOM | 548 | vendedor.NOM |
551 | }); | 549 | }); |
552 | $scope.remito.idVendedor = vendedor.id; | 550 | $scope.remito.idVendedor = vendedor.id; |
553 | $scope.vendedor = vendedor; | 551 | $scope.vendedor = vendedor; |
554 | }, function() { | 552 | }, function() { |
555 | 553 | ||
556 | } | 554 | } |
557 | ); | 555 | ); |
558 | } | 556 | } |
559 | }; | 557 | }; |
560 | 558 | ||
561 | $scope.seleccionarProveedor = function() { | 559 | $scope.seleccionarProveedor = function() { |
562 | if(varlidarRemitoFacturado()) { | 560 | if(varlidarRemitoFacturado()) { |
563 | var parametrosModal = { | 561 | var parametrosModal = { |
564 | titulo: 'Búsqueda de Proveedor', | 562 | titulo: 'Búsqueda de Proveedor', |
565 | query: '/proveedor', | 563 | query: '/proveedor', |
566 | columnas: [ | 564 | columnas: [ |
567 | { | 565 | { |
568 | nombre: 'Código', | 566 | nombre: 'Código', |
569 | propiedad: 'COD', | 567 | propiedad: 'COD', |
570 | filtro: { | 568 | filtro: { |
571 | nombre: 'rellenarDigitos', | 569 | nombre: 'rellenarDigitos', |
572 | parametro: 5 | 570 | parametro: 5 |
573 | } | 571 | } |
574 | }, | 572 | }, |
575 | { | 573 | { |
576 | nombre: 'Nombre', | 574 | nombre: 'Nombre', |
577 | propiedad: 'NOM' | 575 | propiedad: 'NOM' |
578 | }, | 576 | }, |
579 | { | 577 | { |
580 | nombre: 'CUIT', | 578 | nombre: 'CUIT', |
581 | propiedad: 'CUIT' | 579 | propiedad: 'CUIT' |
582 | } | 580 | } |
583 | ], | 581 | ], |
584 | tipo: 'POST', | 582 | tipo: 'POST', |
585 | json: {razonCuitCod: ''} | 583 | json: {razonCuitCod: ''} |
586 | }; | 584 | }; |
587 | focaModalService.modal(parametrosModal).then( | 585 | focaModalService.modal(parametrosModal).then( |
588 | function(proveedor) { | 586 | function(proveedor) { |
589 | $scope.remito.idProveedor = proveedor.COD; | 587 | $scope.remito.idProveedor = proveedor.COD; |
590 | $scope.$broadcast('addCabecera',{ | 588 | $scope.$broadcast('addCabecera',{ |
591 | label: 'Proveedor:', | 589 | label: 'Proveedor:', |
592 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + | 590 | valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + |
593 | proveedor.NOM | 591 | proveedor.NOM |
594 | }); | 592 | }); |
595 | }, function() { | 593 | }, function() { |
596 | 594 | ||
597 | } | 595 | } |
598 | ); | 596 | ); |
599 | } | 597 | } |
600 | }; | 598 | }; |
601 | 599 | ||
602 | $scope.seleccionarCliente = function() { | 600 | $scope.seleccionarCliente = function() { |
603 | if(!$scope.vendedor) { | 601 | if(!$scope.vendedor) { |
604 | focaModalService.alert('Primero seleccione un vendedor'); | 602 | focaModalService.alert('Primero seleccione un vendedor'); |
605 | return; | 603 | return; |
606 | } | 604 | } |
607 | 605 | ||
608 | if(varlidarRemitoFacturado()) { | 606 | if(varlidarRemitoFacturado()) { |
609 | var modalInstance = $uibModal.open( | 607 | var modalInstance = $uibModal.open( |
610 | { | 608 | { |
611 | ariaLabelledBy: 'Busqueda de Cliente', | 609 | ariaLabelledBy: 'Busqueda de Cliente', |
612 | templateUrl: 'foca-busqueda-cliente-modal.html', | 610 | templateUrl: 'foca-busqueda-cliente-modal.html', |
613 | controller: 'focaBusquedaClienteModalController', | 611 | controller: 'focaBusquedaClienteModalController', |
614 | resolve: { | 612 | resolve: { |
615 | vendedor: function() { return $scope.vendedor; } | 613 | vendedor: function() { return $scope.vendedor; } |
616 | }, | 614 | }, |
617 | size: 'lg' | 615 | size: 'lg' |
618 | } | 616 | } |
619 | ); | 617 | ); |
620 | modalInstance.result.then( | 618 | modalInstance.result.then( |
621 | function(cliente) { | 619 | function(cliente) { |
622 | $scope.abrirModalDomicilios(cliente); | 620 | $scope.abrirModalDomicilios(cliente); |
623 | $scope.cliente = cliente; | 621 | $scope.cliente = cliente; |
624 | }, function() { | 622 | }, function() { |
625 | 623 | ||
626 | } | 624 | } |
627 | ); | 625 | ); |
628 | } | 626 | } |
629 | }; | 627 | }; |
630 | 628 | ||
631 | $scope.abrirModalDomicilios = function(cliente) { | 629 | $scope.abrirModalDomicilios = function(cliente) { |
632 | var modalInstanceDomicilio = $uibModal.open( | 630 | var modalInstanceDomicilio = $uibModal.open( |
633 | { | 631 | { |
634 | ariaLabelledBy: 'Busqueda de Domicilios', | 632 | ariaLabelledBy: 'Busqueda de Domicilios', |
635 | templateUrl: 'modal-domicilio.html', | 633 | templateUrl: 'modal-domicilio.html', |
636 | controller: 'focaModalDomicilioController', | 634 | controller: 'focaModalDomicilioController', |
637 | size: 'lg', | 635 | size: 'lg', |
638 | resolve: { | 636 | resolve: { |
639 | idCliente: function() { return cliente.cod; }, | 637 | idCliente: function() { return cliente.cod; }, |
640 | esNuevo: function() { return cliente.esNuevo; } | 638 | esNuevo: function() { return cliente.esNuevo; } |
641 | } | 639 | } |
642 | } | 640 | } |
643 | ); | 641 | ); |
644 | modalInstanceDomicilio.result.then( | 642 | modalInstanceDomicilio.result.then( |
645 | function(domicilio) { | 643 | function(domicilio) { |
646 | $scope.remito.domicilio = domicilio; | 644 | $scope.remito.domicilio = domicilio; |
647 | $scope.remito.cliente = { | 645 | $scope.remito.cliente = { |
648 | COD: cliente.cod, | 646 | COD: cliente.cod, |
649 | CUIT: cliente.cuit, | 647 | CUIT: cliente.cuit, |
650 | NOM: cliente.nom | 648 | NOM: cliente.nom, |
649 | MAIL: cliente.mail | ||
651 | }; | 650 | }; |
652 | 651 | ||
653 | 652 | ||
654 | var domicilioStamp = | 653 | var domicilioStamp = |
655 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + | 654 | domicilio.Calle + ' ' + domicilio.Numero + ', ' + |
656 | domicilio.Localidad + ', ' + domicilio.Provincia; | 655 | domicilio.Localidad + ', ' + domicilio.Provincia; |
657 | $scope.remito.domicilioStamp = domicilioStamp; | 656 | $scope.remito.domicilioStamp = domicilioStamp; |
658 | 657 | ||
659 | $scope.$broadcast('addCabecera',{ | 658 | $scope.$broadcast('addCabecera',{ |
660 | label: 'Cliente:', | 659 | label: 'Cliente:', |
661 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom | 660 | valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom |
662 | }); | 661 | }); |
663 | $scope.$broadcast('addCabecera',{ | 662 | $scope.$broadcast('addCabecera',{ |
664 | label: 'Domicilio:', | 663 | label: 'Domicilio:', |
665 | valor: domicilioStamp | 664 | valor: domicilioStamp |
666 | }); | 665 | }); |
667 | 666 | ||
668 | if(domicilio.verPuntos) { | 667 | if(domicilio.verPuntos) { |
669 | delete $scope.remito.domicilio.verPuntos; | 668 | delete $scope.remito.domicilio.verPuntos; |
670 | $scope.seleccionarPuntosDeDescarga(); | 669 | $scope.seleccionarPuntosDeDescarga(); |
671 | }else { | 670 | }else { |
672 | crearRemitoService | 671 | crearRemitoService |
673 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) | 672 | .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) |
674 | .then(function(res) { | 673 | .then(function(res) { |
675 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); | 674 | if(res.data.length) $scope.seleccionarPuntosDeDescarga(); |
676 | }); | 675 | }); |
677 | } | 676 | } |
678 | }, function() { | 677 | }, function() { |
679 | $scope.seleccionarCliente(); | 678 | $scope.seleccionarCliente(); |
680 | return; | 679 | return; |
681 | } | 680 | } |
682 | ); | 681 | ); |
683 | }; | 682 | }; |
684 | 683 | ||
685 | $scope.mostrarFichaCliente = function() { | 684 | $scope.mostrarFichaCliente = function() { |
686 | $uibModal.open( | 685 | $uibModal.open( |
687 | { | 686 | { |
688 | ariaLabelledBy: 'Datos del Cliente', | 687 | ariaLabelledBy: 'Datos del Cliente', |
689 | templateUrl: 'foca-crear-remito-ficha-cliente.html', | 688 | templateUrl: 'foca-crear-remito-ficha-cliente.html', |
690 | controller: 'focaCrearRemitoFichaClienteController', | 689 | controller: 'focaCrearRemitoFichaClienteController', |
691 | size: 'lg' | 690 | size: 'lg' |
692 | } | 691 | } |
693 | ); | 692 | ); |
694 | }; | 693 | }; |
695 | 694 | ||
696 | $scope.getTotal = function() { | 695 | $scope.getTotal = function() { |
697 | var total = 0; | 696 | var total = 0; |
698 | var arrayTempArticulos = $scope.articulosTabla; | 697 | var arrayTempArticulos = $scope.articulosTabla; |
699 | for(var i = 0; i < arrayTempArticulos.length; i++) { | 698 | for(var i = 0; i < arrayTempArticulos.length; i++) { |
700 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; | 699 | total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; |
701 | } | 700 | } |
702 | return parseFloat(total.toFixed(2)); | 701 | return parseFloat(total.toFixed(2)); |
703 | }; | 702 | }; |
704 | 703 | ||
705 | $scope.getSubTotal = function() { | 704 | $scope.getSubTotal = function() { |
706 | if($scope.articuloACargar) { | 705 | if($scope.articuloACargar) { |
707 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; | 706 | return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; |
708 | } | 707 | } |
709 | }; | 708 | }; |
710 | 709 | ||
711 | $scope.seleccionarPreciosYCondiciones = function() { | 710 | $scope.seleccionarPreciosYCondiciones = function() { |
712 | if(varlidarRemitoFacturado()) { | 711 | if(varlidarRemitoFacturado()) { |
713 | var modalInstance = $uibModal.open( | 712 | var modalInstance = $uibModal.open( |
714 | { | 713 | { |
715 | ariaLabelledBy: 'Busqueda de Precio Condición', | 714 | ariaLabelledBy: 'Busqueda de Precio Condición', |
716 | templateUrl: 'modal-precio-condicion.html', | 715 | templateUrl: 'modal-precio-condicion.html', |
717 | controller: 'focaModalPrecioCondicionController', | 716 | controller: 'focaModalPrecioCondicionController', |
718 | size: 'lg' | 717 | size: 'lg' |
719 | } | 718 | } |
720 | ); | 719 | ); |
721 | modalInstance.result.then( | 720 | modalInstance.result.then( |
722 | function(precioCondicion) { | 721 | function(precioCondicion) { |
723 | var cabecera = ''; | 722 | var cabecera = ''; |
724 | var plazosConcat = ''; | 723 | var plazosConcat = ''; |
725 | if(!Array.isArray(precioCondicion)) { | 724 | if(!Array.isArray(precioCondicion)) { |
726 | $scope.remito.idPrecioCondicion = precioCondicion.id; | 725 | $scope.remito.idPrecioCondicion = precioCondicion.id; |
727 | $scope.plazosPagos = precioCondicion.plazoPago; | 726 | $scope.plazosPagos = precioCondicion.plazoPago; |
728 | $scope.idLista = precioCondicion.idListaPrecio; | 727 | $scope.idLista = precioCondicion.idListaPrecio; |
729 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { | 728 | for(var i = 0; i < precioCondicion.plazoPago.length; i++) { |
730 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; | 729 | plazosConcat += precioCondicion.plazoPago[i].dias + ' '; |
731 | } | 730 | } |
732 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + | 731 | cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + |
733 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); | 732 | ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); |
734 | }else { //Cuando se ingresan los plazos manualmente | 733 | }else { //Cuando se ingresan los plazos manualmente |
735 | $scope.remito.idPrecioCondicion = 0; | 734 | $scope.remito.idPrecioCondicion = 0; |
736 | //-1, el modal productos busca todos los productos | 735 | //-1, el modal productos busca todos los productos |
737 | $scope.idLista = -1; | 736 | $scope.idLista = -1; |
738 | $scope.plazosPagos = precioCondicion; | 737 | $scope.plazosPagos = precioCondicion; |
739 | for(var j = 0; j < precioCondicion.length; j++) { | 738 | for(var j = 0; j < precioCondicion.length; j++) { |
740 | plazosConcat += precioCondicion[j].dias + ' '; | 739 | plazosConcat += precioCondicion[j].dias + ' '; |
741 | } | 740 | } |
742 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); | 741 | cabecera = 'Ingreso manual ' + plazosConcat.trim(); |
743 | } | 742 | } |
744 | $scope.articulosTabla = []; | 743 | $scope.articulosTabla = []; |
745 | $scope.$broadcast('addCabecera',{ | 744 | $scope.$broadcast('addCabecera',{ |
746 | label: 'Precios y condiciones:', | 745 | label: 'Precios y condiciones:', |
747 | valor: cabecera | 746 | valor: cabecera |
748 | }); | 747 | }); |
749 | }, function() { | 748 | }, function() { |
750 | 749 | ||
751 | } | 750 | } |
752 | ); | 751 | ); |
753 | } | 752 | } |
754 | }; | 753 | }; |
755 | 754 | ||
756 | $scope.seleccionarFlete = function() { | 755 | $scope.seleccionarFlete = function() { |
757 | if(varlidarRemitoFacturado()) { | 756 | if(varlidarRemitoFacturado()) { |
758 | var modalInstance = $uibModal.open( | 757 | var modalInstance = $uibModal.open( |
759 | { | 758 | { |
760 | ariaLabelledBy: 'Busqueda de Flete', | 759 | ariaLabelledBy: 'Busqueda de Flete', |
761 | templateUrl: 'modal-flete.html', | 760 | templateUrl: 'modal-flete.html', |
762 | controller: 'focaModalFleteController', | 761 | controller: 'focaModalFleteController', |
763 | size: 'lg', | 762 | size: 'lg', |
764 | resolve: { | 763 | resolve: { |
765 | parametrosFlete: | 764 | parametrosFlete: |
766 | function() { | 765 | function() { |
767 | return { | 766 | return { |
768 | flete: $scope.remito.flete ? '1' : | 767 | flete: $scope.remito.flete ? '1' : |
769 | ($scope.remito.fob ? 'FOB' : | 768 | ($scope.remito.fob ? 'FOB' : |
770 | ($scope.remito.flete === undefined ? null : '0')), | 769 | ($scope.remito.flete === undefined ? null : '0')), |
771 | bomba: $scope.remito.bomba ? '1' : | 770 | bomba: $scope.remito.bomba ? '1' : |
772 | ($scope.remito.bomba === undefined ? null : '0'), | 771 | ($scope.remito.bomba === undefined ? null : '0'), |
773 | kilometros: $scope.remito.kilometros | 772 | kilometros: $scope.remito.kilometros |
774 | }; | 773 | }; |
775 | } | 774 | } |
776 | } | 775 | } |
777 | } | 776 | } |
778 | ); | 777 | ); |
779 | modalInstance.result.then( | 778 | modalInstance.result.then( |
780 | function(datos) { | 779 | function(datos) { |
781 | $scope.remito.flete = datos.flete; | 780 | $scope.remito.flete = datos.flete; |
782 | $scope.remito.fob = datos.FOB; | 781 | $scope.remito.fob = datos.FOB; |
783 | $scope.remito.bomba = datos.bomba; | 782 | $scope.remito.bomba = datos.bomba; |
784 | $scope.remito.kilometros = datos.kilometros; | 783 | $scope.remito.kilometros = datos.kilometros; |
785 | 784 | ||
786 | $scope.$broadcast('addCabecera',{ | 785 | $scope.$broadcast('addCabecera',{ |
787 | label: 'Flete:', | 786 | label: 'Flete:', |
788 | valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') | 787 | valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') |
789 | }); | 788 | }); |
790 | if(datos.flete) { | 789 | if(datos.flete) { |
791 | $scope.$broadcast('addCabecera',{ | 790 | $scope.$broadcast('addCabecera',{ |
792 | label: 'Bomba:', | 791 | label: 'Bomba:', |
793 | valor: datos.bomba ? 'Si' : 'No' | 792 | valor: datos.bomba ? 'Si' : 'No' |
794 | }); | 793 | }); |
795 | $scope.$broadcast('addCabecera',{ | 794 | $scope.$broadcast('addCabecera',{ |
796 | label: 'Kilometros:', | 795 | label: 'Kilometros:', |
797 | valor: datos.kilometros | 796 | valor: datos.kilometros |
798 | }); | 797 | }); |
799 | }else { | 798 | }else { |
800 | $scope.$broadcast('removeCabecera', 'Bomba:'); | 799 | $scope.$broadcast('removeCabecera', 'Bomba:'); |
801 | $scope.$broadcast('removeCabecera', 'Kilometros:'); | 800 | $scope.$broadcast('removeCabecera', 'Kilometros:'); |
802 | $scope.remito.fob = false; | 801 | $scope.remito.fob = false; |
803 | $scope.remito.bomba = false; | 802 | $scope.remito.bomba = false; |
804 | $scope.remito.kilometros = null; | 803 | $scope.remito.kilometros = null; |
805 | } | 804 | } |
806 | }, function() { | 805 | }, function() { |
807 | 806 | ||
808 | } | 807 | } |
809 | ); | 808 | ); |
810 | } | 809 | } |
811 | }; | 810 | }; |
812 | 811 | ||
813 | $scope.seleccionarMoneda = function() { | 812 | $scope.seleccionarMoneda = function() { |
814 | if(varlidarRemitoFacturado()) { | 813 | if(varlidarRemitoFacturado()) { |
815 | var parametrosModal = { | 814 | var parametrosModal = { |
816 | titulo: 'Búsqueda de monedas', | 815 | titulo: 'Búsqueda de monedas', |
817 | query: '/moneda', | 816 | query: '/moneda', |
818 | columnas: [ | 817 | columnas: [ |
819 | { | 818 | { |
820 | propiedad: 'DETALLE', | 819 | propiedad: 'DETALLE', |
821 | nombre: 'Nombre' | 820 | nombre: 'Nombre' |
822 | }, | 821 | }, |
823 | { | 822 | { |
824 | propiedad: 'SIMBOLO', | 823 | propiedad: 'SIMBOLO', |
825 | nombre: 'Símbolo' | 824 | nombre: 'Símbolo' |
826 | } | 825 | } |
827 | ], | 826 | ], |
828 | size: 'md' | 827 | size: 'md' |
829 | }; | 828 | }; |
830 | focaModalService.modal(parametrosModal).then( | 829 | focaModalService.modal(parametrosModal).then( |
831 | function(moneda) { | 830 | function(moneda) { |
832 | $scope.abrirModalCotizacion(moneda); | 831 | $scope.abrirModalCotizacion(moneda); |
833 | }, function() { | 832 | }, function() { |
834 | 833 | ||
835 | } | 834 | } |
836 | ); | 835 | ); |
837 | } | 836 | } |
838 | }; | 837 | }; |
839 | 838 | ||
840 | $scope.seleccionarObservaciones = function() { | 839 | $scope.seleccionarObservaciones = function() { |
841 | focaModalService | 840 | focaModalService |
842 | .prompt('Ingrese observaciones', $scope.remito.observaciones, true) | 841 | .prompt('Ingrese observaciones', $scope.remito.observaciones, true) |
843 | .then(function(observaciones) { | 842 | .then(function(observaciones) { |
844 | $scope.remito.observaciones = observaciones; | 843 | $scope.remito.observaciones = observaciones; |
845 | }); | 844 | }); |
846 | }; | 845 | }; |
847 | 846 | ||
848 | $scope.abrirModalCotizacion = function(moneda) { | 847 | $scope.abrirModalCotizacion = function(moneda) { |
849 | var modalInstance = $uibModal.open( | 848 | var modalInstance = $uibModal.open( |
850 | { | 849 | { |
851 | ariaLabelledBy: 'Busqueda de Cotización', | 850 | ariaLabelledBy: 'Busqueda de Cotización', |
852 | templateUrl: 'modal-cotizacion.html', | 851 | templateUrl: 'modal-cotizacion.html', |
853 | controller: 'focaModalCotizacionController', | 852 | controller: 'focaModalCotizacionController', |
854 | size: 'lg', | 853 | size: 'lg', |
855 | resolve: {idMoneda: function() {return moneda.ID;}} | 854 | resolve: {idMoneda: function() {return moneda.ID;}} |
856 | } | 855 | } |
857 | ); | 856 | ); |
858 | modalInstance.result.then( | 857 | modalInstance.result.then( |
859 | function(cotizacion) { | 858 | function(cotizacion) { |
860 | var articulosTablaTemp = $scope.articulosTabla; | 859 | var articulosTablaTemp = $scope.articulosTabla; |
861 | for(var i = 0; i < articulosTablaTemp.length; i++) { | 860 | for(var i = 0; i < articulosTablaTemp.length; i++) { |
862 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * | 861 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * |
863 | $scope.remito.cotizacion.COTIZACION; | 862 | $scope.remito.cotizacion.COTIZACION; |
864 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / | 863 | articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / |
865 | cotizacion.COTIZACION; | 864 | cotizacion.COTIZACION; |
866 | } | 865 | } |
867 | $scope.articulosTabla = articulosTablaTemp; | 866 | $scope.articulosTabla = articulosTablaTemp; |
868 | $scope.remito.moneda = moneda; | 867 | $scope.remito.moneda = moneda; |
869 | $scope.remito.cotizacion = cotizacion; | 868 | $scope.remito.cotizacion = cotizacion; |
870 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { | 869 | if(moneda.DETALLE === 'PESOS ARGENTINOS') { |
871 | $scope.$broadcast('removeCabecera', 'Moneda:'); | 870 | $scope.$broadcast('removeCabecera', 'Moneda:'); |
872 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); | 871 | $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); |
873 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); | 872 | $scope.$broadcast('removeCabecera', 'Cotizacion:'); |
874 | }else { | 873 | }else { |
875 | $scope.$broadcast('addCabecera',{ | 874 | $scope.$broadcast('addCabecera',{ |
876 | label: 'Moneda:', | 875 | label: 'Moneda:', |
877 | valor: moneda.DETALLE | 876 | valor: moneda.DETALLE |
878 | }); | 877 | }); |
879 | $scope.$broadcast('addCabecera',{ | 878 | $scope.$broadcast('addCabecera',{ |
880 | label: 'Fecha cotizacion:', | 879 | label: 'Fecha cotizacion:', |
881 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') | 880 | valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') |
882 | }); | 881 | }); |
883 | $scope.$broadcast('addCabecera',{ | 882 | $scope.$broadcast('addCabecera',{ |
884 | label: 'Cotizacion:', | 883 | label: 'Cotizacion:', |
885 | valor: $filter('number')(cotizacion.COTIZACION, '2') | 884 | valor: $filter('number')(cotizacion.COTIZACION, '2') |
886 | }); | 885 | }); |
887 | } | 886 | } |
888 | }, function() { | 887 | }, function() { |
889 | 888 | ||
890 | } | 889 | } |
891 | ); | 890 | ); |
892 | }; | 891 | }; |
893 | 892 | ||
894 | $scope.agregarATabla = function(key) { | 893 | $scope.agregarATabla = function(key) { |
895 | if(key === 13) { | 894 | if(key === 13) { |
896 | if($scope.articuloACargar.cantidad === undefined || | 895 | if($scope.articuloACargar.cantidad === undefined || |
897 | $scope.articuloACargar.cantidad === 0 || | 896 | $scope.articuloACargar.cantidad === 0 || |
898 | $scope.articuloACargar.cantidad === null ) { | 897 | $scope.articuloACargar.cantidad === null ) { |
899 | focaModalService.alert('El valor debe ser al menos 1'); | 898 | focaModalService.alert('El valor debe ser al menos 1'); |
900 | return; | 899 | return; |
901 | } | 900 | } |
902 | delete $scope.articuloACargar.sectorCodigo; | 901 | delete $scope.articuloACargar.sectorCodigo; |
903 | $scope.articulosTabla.push($scope.articuloACargar); | 902 | $scope.articulosTabla.push($scope.articuloACargar); |
904 | $scope.cargando = true; | 903 | $scope.cargando = true; |
905 | } | 904 | } |
906 | }; | 905 | }; |
907 | 906 | ||
908 | $scope.quitarArticulo = function(key) { | 907 | $scope.quitarArticulo = function(key) { |
909 | $scope.articulosTabla.splice(key, 1); | 908 | $scope.articulosTabla.splice(key, 1); |
910 | }; | 909 | }; |
911 | 910 | ||
912 | $scope.editarArticulo = function(key, articulo) { | 911 | $scope.editarArticulo = function(key, articulo) { |
913 | if(key === 13) { | 912 | if(key === 13) { |
914 | if(articulo.cantidad === null || articulo.cantidad === 0 || | 913 | if(articulo.cantidad === null || articulo.cantidad === 0 || |
915 | articulo.cantidad === undefined) { | 914 | articulo.cantidad === undefined) { |
916 | focaModalService.alert('El valor debe ser al menos 1'); | 915 | focaModalService.alert('El valor debe ser al menos 1'); |
917 | return; | 916 | return; |
918 | } | 917 | } |
919 | articulo.editCantidad = false; | 918 | articulo.editCantidad = false; |
920 | articulo.editPrecio = false; | 919 | articulo.editPrecio = false; |
921 | } | 920 | } |
922 | }; | 921 | }; |
923 | 922 | ||
924 | $scope.cambioEdit = function(articulo, propiedad) { | 923 | $scope.cambioEdit = function(articulo, propiedad) { |
925 | if(propiedad === 'cantidad') { | 924 | if(propiedad === 'cantidad') { |
926 | articulo.editCantidad = true; | 925 | articulo.editCantidad = true; |
927 | }else if(propiedad === 'precio') { | 926 | }else if(propiedad === 'precio') { |
928 | articulo.editPrecio = true; | 927 | articulo.editPrecio = true; |
929 | } | 928 | } |
930 | }; | 929 | }; |
931 | 930 | ||
932 | $scope.limpiarFlete = function() { | 931 | $scope.limpiarFlete = function() { |
933 | $scope.remito.fleteNombre = ''; | 932 | $scope.remito.fleteNombre = ''; |
934 | $scope.remito.chofer = ''; | 933 | $scope.remito.chofer = ''; |
935 | $scope.remito.vehiculo = ''; | 934 | $scope.remito.vehiculo = ''; |
936 | $scope.remito.kilometros = ''; | 935 | $scope.remito.kilometros = ''; |
937 | $scope.remito.costoUnitarioKmFlete = ''; | 936 | $scope.remito.costoUnitarioKmFlete = ''; |
938 | $scope.choferes = ''; | 937 | $scope.choferes = ''; |
939 | $scope.vehiculos = ''; | 938 | $scope.vehiculos = ''; |
940 | }; | 939 | }; |
941 | 940 | ||
942 | $scope.limpiarPantalla = function() { | 941 | $scope.limpiarPantalla = function() { |
943 | $scope.limpiarFlete(); | 942 | $scope.limpiarFlete(); |
944 | $scope.remito.flete = '0'; | 943 | $scope.remito.flete = '0'; |
945 | $scope.remito.bomba = '0'; | 944 | $scope.remito.bomba = '0'; |
946 | $scope.remito.precioCondicion = ''; | 945 | $scope.remito.precioCondicion = ''; |
947 | $scope.articulosTabla = []; | 946 | $scope.articulosTabla = []; |
948 | $scope.remito.vendedor.nombre = ''; | 947 | $scope.remito.vendedor.nombre = ''; |
949 | $scope.remito.cliente = {nombre: ''}; | 948 | $scope.remito.cliente = {nombre: ''}; |
950 | $scope.remito.domicilio = {dom: ''}; | 949 | $scope.remito.domicilio = {dom: ''}; |
951 | $scope.domiciliosCliente = []; | 950 | $scope.domiciliosCliente = []; |
952 | }; | 951 | }; |
953 | 952 | ||
954 | $scope.resetFilter = function() { | 953 | $scope.resetFilter = function() { |
955 | $scope.articuloACargar = {}; | 954 | $scope.articuloACargar = {}; |
956 | $scope.cargando = true; | 955 | $scope.cargando = true; |
957 | }; | 956 | }; |
958 | //Recibe aviso si el teclado está en uso | 957 | //Recibe aviso si el teclado está en uso |
959 | $rootScope.$on('usarTeclado', function(event, data) { | 958 | $rootScope.$on('usarTeclado', function(event, data) { |
960 | if(data) { | 959 | if(data) { |
961 | $scope.mostrarTeclado = true; | 960 | $scope.mostrarTeclado = true; |
962 | return; | 961 | return; |
963 | } | 962 | } |
964 | $scope.mostrarTeclado = false; | 963 | $scope.mostrarTeclado = false; |
965 | }); | 964 | }); |
966 | 965 | ||
967 | $scope.selectFocus = function($event) { | 966 | $scope.selectFocus = function($event) { |
968 | // Si el teclado esta en uso no selecciona el valor | 967 | // Si el teclado esta en uso no selecciona el valor |
969 | if($scope.mostrarTeclado) { | 968 | if($scope.mostrarTeclado) { |
970 | return; | 969 | return; |
971 | } | 970 | } |
972 | $event.target.select(); | 971 | $event.target.select(); |
973 | }; | 972 | }; |
974 | 973 | ||
975 | function addArrayCabecera(array) { | 974 | function addArrayCabecera(array) { |
976 | for(var i = 0; i < array.length; i++) { | 975 | for(var i = 0; i < array.length; i++) { |
977 | $scope.$broadcast('addCabecera',{ | 976 | $scope.$broadcast('addCabecera',{ |
978 | label: array[i].label, | 977 | label: array[i].label, |
979 | valor: array[i].valor | 978 | valor: array[i].valor |
980 | }); | 979 | }); |
981 | } | 980 | } |
982 | } | 981 | } |
983 | 982 | ||
984 | function rellenar(relleno, longitud) { | 983 | function rellenar(relleno, longitud) { |
985 | relleno = '' + relleno; | 984 | relleno = '' + relleno; |
986 | while (relleno.length < longitud) { | 985 | while (relleno.length < longitud) { |
987 | relleno = '0' + relleno; | 986 | relleno = '0' + relleno; |
988 | } | 987 | } |
989 | 988 | ||
990 | return relleno; | 989 | return relleno; |
991 | } | 990 | } |
992 | 991 | ||
993 | function varlidarRemitoFacturado() { | 992 | function varlidarRemitoFacturado() { |
994 | if($scope.remito.estado !== 5) { | 993 | if($scope.remito.estado !== 5) { |
995 | return true; | 994 | return true; |
996 | }else { | 995 | }else { |
997 | focaModalService.alert('No se puede editar un remito facturado'); | 996 | focaModalService.alert('No se puede editar un remito facturado'); |
998 | return false(); | 997 | return false(); |
999 | } | 998 | } |
1000 | } | 999 | } |
1001 | 1000 | ||
1002 | function salir() { | 1001 | function salir() { |
1003 | var confirmacion = false; | 1002 | var confirmacion = false; |
1004 | 1003 | ||
1005 | angular.forEach($scope.inicial, function(valor, key) { | 1004 | angular.forEach($scope.inicial, function(valor, key) { |
1006 | if (!angular.equals($scope[key], $scope.inicial[key])) { | 1005 | if (!angular.equals($scope[key], $scope.inicial[key])) { |
1007 | confirmacion = true; | 1006 | confirmacion = true; |
1008 | } | 1007 | } |
1009 | }); | 1008 | }); |
1010 | 1009 | ||
1011 | if (confirmacion) { | 1010 | if (confirmacion) { |
1012 | focaModalService.confirm( | 1011 | focaModalService.confirm( |
1013 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 1012 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
1014 | ).then(function(data) { | 1013 | ).then(function(data) { |
1015 | if (data) { | 1014 | if (data) { |
1016 | $location.path('/'); | 1015 | $location.path('/'); |
1017 | } | 1016 | } |
1018 | }); | 1017 | }); |
1019 | } else { | 1018 | } else { |
1020 | $location.path('/'); | 1019 | $location.path('/'); |
1021 | } | 1020 | } |
1022 | } | 1021 | } |
1023 | 1022 | ||
1024 | function enableObservaciones(val) { | 1023 | function enableObservaciones(val) { |
1025 | var boton = $scope.botonera.filter(function(botonObs) { | 1024 | var boton = $scope.botonera.filter(function(botonObs) { |
1026 | return botonObs.label === 'Observaciones'; | 1025 | return botonObs.label === 'Observaciones'; |
1027 | }); | 1026 | }); |
1028 | 1027 | ||
1029 | boton[0].disable = !val; | 1028 | boton[0].disable = !val; |
1030 | } | 1029 | } |
1031 | } | 1030 | } |
1032 | ]); | 1031 | ]); |
src/js/controllerComprobante.js
File was created | 1 | angular.module('focaCrearRemito') | |
2 | .controller('focaRemitoComprobanteController', [ | ||
3 | '$scope', | ||
4 | '$uibModalInstance', | ||
5 | 'crearRemitoService', | ||
6 | '$window', | ||
7 | 'parametros', | ||
8 | function($scope, $uibModalInstance, crearRemitoService, $window, parametros) { | ||
9 | |||
10 | $scope.correoEnviado = false; | ||
11 | $scope.correoNoEnviado = false; | ||
12 | $scope.esperando = false; | ||
13 | $scope.remito = parametros.remito; | ||
14 | |||
15 | crearRemitoService.imprimirRemitoByIdRemito($scope.remito.id).then( | ||
16 | function(res) { | ||
17 | $scope.htmlComprobante = res.data; | ||
18 | }); | ||
19 | |||
20 | $scope.aceptar = function() { | ||
21 | $uibModalInstance.close(); | ||
22 | }; | ||
23 | |||
24 | $scope.imprimir = function () { | ||
25 | |||
26 | var printWindow = $window.open('', '', 'height=1000,width=800'); | ||
27 | printWindow.document.write($scope.htmlComprobante); | ||
28 | printWindow.document.close(); | ||
29 | printWindow.print(); | ||
30 | }; | ||
31 | |||
32 | $scope.enviarCorreo = function(key) { | ||
33 | if(key !== 13) return; | ||
34 | $scope.esperando = true; | ||
35 | var options = { | ||
36 | para: $scope.remito.cliente.MAIL, | ||
37 | titulo: 'Recibo Mail', | ||
38 | texto: '', | ||
39 | html: $scope.htmlComprobante | ||
40 | }; | ||
41 | |||
42 | crearRemitoService.enviarCorreo(options).then(function() { | ||
43 | $scope.correoEnviado = true; | ||
44 | $scope.esperando = false; | ||
45 | }, function() { | ||
46 | $scope.esperando = false; | ||
47 | $scope.correoNoEnviado = true; | ||
48 | }); | ||
49 | }; | ||
50 | } | ||
51 | ]); | ||
52 |
src/js/service.js
1 | angular.module('focaCrearRemito') | 1 | angular.module('focaCrearRemito') |
2 | .service('crearRemitoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .service('crearRemitoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
3 | var route = API_ENDPOINT.URL; | 3 | var route = API_ENDPOINT.URL; |
4 | return { | 4 | return { |
5 | crearRemito: function(remito) { | 5 | crearRemito: function(remito) { |
6 | // TODO: Cambiar para usar el servicio /remito | 6 | // TODO: Cambiar para usar el servicio /remito |
7 | return $http.post(route + '/remito', remito); | 7 | return $http.post(route + '/remito', remito); |
8 | }, | 8 | }, |
9 | obtenerRemito: function() { | 9 | obtenerRemito: function() { |
10 | return $http.get(route +'/nota-pedido'); | 10 | return $http.get(route +'/nota-pedido'); |
11 | }, | 11 | }, |
12 | setRemito: function(remito) { | 12 | setRemito: function(remito) { |
13 | this.remito = remito; | 13 | this.remito = remito; |
14 | }, | 14 | }, |
15 | clearRemito: function() { | 15 | clearRemito: function() { |
16 | this.remito = undefined; | 16 | this.remito = undefined; |
17 | }, | 17 | }, |
18 | getRemito: function() { | 18 | getRemito: function() { |
19 | return this.remito; | 19 | return this.remito; |
20 | }, | 20 | }, |
21 | getArticulosByIdRemito: function(id) { | 21 | getArticulosByIdRemito: function(id) { |
22 | return $http.get(route+'/articulos/nota-pedido/'+id); | 22 | return $http.get(route+'/articulos/nota-pedido/'+id); |
23 | }, | 23 | }, |
24 | crearArticulosParaRemito: function(articuloRemito) { | 24 | crearArticulosParaRemito: function(articuloRemito) { |
25 | return $http.post(route + '/articulos/remito', | 25 | return $http.post(route + '/articulos/remito', |
26 | {articuloRemito: articuloRemito}); | 26 | {articuloRemito: articuloRemito}); |
27 | }, | 27 | }, |
28 | getDomiciliosByIdRemito: function(id) { | 28 | getDomiciliosByIdRemito: function(id) { |
29 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); | 29 | return $http.get(route +'/nota-pedido/'+id+'/domicilios'); |
30 | }, | 30 | }, |
31 | getDomiciliosByIdCliente: function(id) { | 31 | getDomiciliosByIdCliente: function(id) { |
32 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) | 32 | var idTipoEntrega = 2;//Solo traigo los domicilios que tienen tipo 2 (tipo entrega) |
33 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); | 33 | return $http.get(route + '/domicilio/tipo/' + idTipoEntrega + '/cliente/' + id ); |
34 | }, | 34 | }, |
35 | getPrecioCondicion: function() { | 35 | getPrecioCondicion: function() { |
36 | return $http.get(route + '/precio-condicion'); | 36 | return $http.get(route + '/precio-condicion'); |
37 | }, | 37 | }, |
38 | getPrecioCondicionById: function(id) { | 38 | getPrecioCondicionById: function(id) { |
39 | return $http.get(route + '/precio-condicion/' + id); | 39 | return $http.get(route + '/precio-condicion/' + id); |
40 | }, | 40 | }, |
41 | getPlazoPagoByPrecioCondicion: function(id) { | 41 | getPlazoPagoByPrecioCondicion: function(id) { |
42 | return $http.get(route + '/plazo-pago/precio-condicion/'+ id); | 42 | return $http.get(route + '/plazo-pago/precio-condicion/'+ id); |
43 | }, | 43 | }, |
44 | crearFlete: function(flete) { | 44 | crearFlete: function(flete) { |
45 | return $http.post(route + '/flete', {flete : flete}); | 45 | return $http.post(route + '/flete', {flete : flete}); |
46 | }, | 46 | }, |
47 | crearPlazosParaRemito: function(plazos) { | 47 | crearPlazosParaRemito: function(plazos) { |
48 | return $http.post(route + '/plazo-pago/remito', plazos); | 48 | return $http.post(route + '/plazo-pago/remito', plazos); |
49 | }, | 49 | }, |
50 | getCotizacionByIdMoneda: function(id) { | 50 | getCotizacionByIdMoneda: function(id) { |
51 | return $http.get(route + '/moneda/' + id); | 51 | return $http.get(route + '/moneda/' + id); |
52 | }, | 52 | }, |
53 | crearEstadoParaRemito: function(estado) { | 53 | crearEstadoParaRemito: function(estado) { |
54 | return $http.post(route + '/estado', {estado: estado}); | 54 | return $http.post(route + '/estado', {estado: estado}); |
55 | }, | 55 | }, |
56 | getNumeroRemito: function() { | 56 | getNumeroRemito: function() { |
57 | return $http.get(route + '/remito/numero-siguiente'); | 57 | return $http.get(route + '/remito/numero-siguiente'); |
58 | }, | 58 | }, |
59 | imprimirRemitoByIdRemito: function(idRemito, original) { | 59 | imprimirRemitoByIdRemito: function(idRemito, original) { |
60 | var tipo = original ? '/original' : ''; | 60 | var tipo = original ? '/original' : ''; |
61 | return $http.get(route + '/remito/comprobante/' + idRemito + tipo); | 61 | return $http.get(route + '/remito/comprobante/' + idRemito + tipo); |
62 | }, | 62 | }, |
63 | getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { | 63 | getPuntosDescargaByClienDom: function(idDomicilio, idCliente) { |
64 | return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + | 64 | return $http.get(API_ENDPOINT.URL + '/punto-descarga/' + |
65 | idDomicilio + '/' + idCliente); | 65 | idDomicilio + '/' + idCliente); |
66 | }, | 66 | }, |
67 | enviarCorreo: function(options) { | ||
68 | return $http.post(API_ENDPOINT.URL + '/mail/enviar', options); | ||
69 | }, | ||
67 | getBotonera: function() { | 70 | getBotonera: function() { |
68 | return [ | 71 | return [ |
69 | { | 72 | { |
70 | label: 'Nota pedido', | 73 | label: 'Nota pedido', |
71 | image: 'notaDePedido.png' | 74 | image: 'notaDePedido.png' |
72 | }, | 75 | }, |
73 | { | 76 | { |
74 | label: 'Vendedor', | 77 | label: 'Vendedor', |
75 | image: 'vendedor.png' | 78 | image: 'vendedor.png' |
76 | }, | 79 | }, |
77 | { | 80 | { |
78 | label: 'Cliente', | 81 | label: 'Cliente', |
79 | image: 'cliente.png' | 82 | image: 'cliente.png' |
80 | }, | 83 | }, |
81 | { | 84 | { |
82 | label: 'Proveedor', | 85 | label: 'Proveedor', |
83 | image: 'proveedor.png' | 86 | image: 'proveedor.png' |
84 | }, | 87 | }, |
85 | { | 88 | { |
86 | label: 'Moneda', | 89 | label: 'Moneda', |
87 | image: 'moneda.png' | 90 | image: 'moneda.png' |
88 | }, | 91 | }, |
89 | { | 92 | { |
90 | label: 'Precios y condiciones', | 93 | label: 'Precios y condiciones', |
91 | image: 'precios-condiciones.png' | 94 | image: 'precios-condiciones.png' |
92 | }, | 95 | }, |
93 | { | 96 | { |
94 | label: 'Flete', | 97 | label: 'Flete', |
95 | image: 'flete.png' | 98 | image: 'flete.png' |
96 | }, | 99 | }, |
97 | { | 100 | { |
98 | label: 'Productos', | 101 | label: 'Productos', |
99 | image: 'productos.png' | 102 | image: 'productos.png' |
100 | }, | 103 | }, |
101 | { | 104 | { |
102 | label: 'Observaciones', | 105 | label: 'Observaciones', |
103 | image: 'productos.png', | 106 | image: 'productos.png', |
104 | disable: true | 107 | disable: true |
105 | } | 108 | } |
106 | ]; | 109 | ]; |
107 | } | 110 | } |
108 | }; | 111 | }; |
109 | }]); | 112 | }]); |
110 | 113 |
src/views/remito-comprobante.html
File was created | 1 | <div class="modal-header"> | |
2 | <h5>Comprobante de remito Nº | ||
3 | <span | ||
4 | ng-bind="[remito.numeroRemito, remito.sucursal] | comprobante"> | ||
5 | </span> | ||
6 | </h5> | ||
7 | </div> | ||
8 | <div class="modal-body"> | ||
9 | <div class="col-12"> | ||
10 | <label | ||
11 | class="col-12 bg-success text-white" | ||
12 | ng-show="correoEnviado">Correo enviado con éxito</label> | ||
13 | <label | ||
14 | class="col-12 bg-danger text-white" | ||
15 | ng-show="correoNoEnviado">Hubo un error al enviar el correo</label> | ||
16 | <label>Enviar correo a </label> | ||
17 | <input | ||
18 | class="form-control" | ||
19 | ng-model="remito.cliente.MAIL" | ||
20 | ng-click="enviarCorreo($event.keyCode)"/> | ||
21 | </div> | ||
22 | </div> | ||
23 | <div class="modal-footer"> | ||
24 | <button | ||
25 | type="button" | ||
26 | class="btn btn-info" | ||
27 | ng-click="imprimir()" | ||
28 | ladda="esperando" | ||
29 | >Imprimir</button> | ||
30 | <button | ||
31 | type="button" | ||
32 | class="btn btn-primary" | ||
33 | ng-click="aceptar()" | ||
34 | ladda="esperando" | ||
35 | >Aceptar</button> | ||
36 | <button | ||
37 | type="button" | ||
38 | class="btn btn-primary" | ||
39 | ng-click="enviarCorreo(13)" | ||
40 | ladda="esperando" | ||
41 | >Enviar</button> | ||
42 | </div> | ||
43 |