Commit 1e642e9f73c067c864c9b906aed1ba5818d14cbb

Authored by Jose Pinto
1 parent be760b98e6
Exists in master

fix modal puntos descarga

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