Commit 24f968602697b3835e7c6925cdabac389b329c84

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

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