Commit 49f31e0f404f21e06d14c9ac11a525ce36e6a74d

Authored by Eric
1 parent f97fdee1d1
Exists in master

seteo remito de pausar después de traer moneda por defecto

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