Commit f27334259584b7d89507ac8c2b16f2d701082db1

Authored by Luigi

Merge remote-tracking branch 'upstream/develop'

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 }, 300 numeroRemito: parseInt($scope.comprobante),
301 notaPedido: $scope.notaPedido 301 sucursal: parseInt($scope.puntoVenta)
302 }; 302 },
303 303 notaPedido: $scope.notaPedido
304 };
305
304 crearRemitoService.crearRemito(save).then( 306 crearRemitoService.crearRemito(save).then(
305 function(data) { 307 function(data) {
306 308
307 focaBotoneraLateralService.endGuardar(true); 309 focaBotoneraLateralService.endGuardar(true);
308 $scope.saveLoading = false; 310 $scope.saveLoading = false;
309 311
310 remitoBusinessService.addArticulos($scope.remito.articulosRemito, 312 remitoBusinessService.addArticulos($scope.remito.articulosRemito,
311 $scope.remito.id, $scope.remito.cotizacion.VENDEDOR); 313 $scope.remito.id, $scope.remito.cotizacion.VENDEDOR);
312 314
313 // TODO: updatear plazos 315 if(data.status === 500) {
316 focaModalService.alert(data.data);
317 return;
318 }
319
320 // TODO: updatear plazos
314 if ($scope.remito.id === 0) { 321 if ($scope.remito.id === 0) {
315 322
316 $scope.remito.id = data.data.id; 323 $scope.remito.id = data.data.id;
317 $scope.remito.numeroRemito = data.data.numero; 324 $scope.remito.numeroRemito = data.data.numero;
318 var plazos = $scope.remito.remitoPlazo; 325 var plazos = $scope.remito.remitoPlazo;
319 326
320 for(var j = 0; j < plazos.length; j++) { 327 for(var j = 0; j < plazos.length; j++) {
321 var json = { 328 var json = {
322 idRemito: $scope.remito.id, 329 idRemito: $scope.remito.id,
323 dias: plazos[j].dias 330 dias: plazos[j].dias
324 }; 331 };
325 crearRemitoService.crearPlazosParaRemito(json); 332 crearRemitoService.crearPlazosParaRemito(json);
326 } 333 }
327 } 334 }
328 335
329 abrirModalMail($scope.remito.id, 336 abrirModalMail($scope.remito.id,
330 $scope.remito.cliente, 337 $scope.remito.cliente,
331 $filter('comprobante')([ 338 $filter('comprobante')([
332 $scope.puntoVenta, 339 $scope.puntoVenta,
333 $scope.remito.numeroRemito 340 $scope.remito.numeroRemito
334 ]) 341 ])
335 ); 342 );
336 343
337 init(); 344 init();
338 345
339 }, function(error) { 346 }, function(error) {
340 focaModalService.alert('Hubo un error al crear el remito'); 347 focaModalService.alert('Hubo un error al crear el remito');
341 focaBotoneraLateralService.endGuardar(); 348 focaBotoneraLateralService.endGuardar();
342 $scope.saveLoading = false; 349 $scope.saveLoading = false;
343 console.info(error); 350 console.info(error);
344 } 351 }
345 ); 352 );
346 }; 353 };
347 354
348 $scope.seleccionarProductos = function() { 355 $scope.seleccionarProductos = function() {
349 if ($scope.idLista === undefined) { 356 if ($scope.idLista === undefined) {
350 focaModalService.alert( 357 focaModalService.alert(
351 'Primero seleccione una lista de precio y condicion'); 358 'Primero seleccione una lista de precio y condicion');
352 return; 359 return;
353 } 360 }
354 var modalInstance = $uibModal.open( 361 var modalInstance = $uibModal.open(
355 { 362 {
356 ariaLabelledBy: 'Busqueda de Productos', 363 ariaLabelledBy: 'Busqueda de Productos',
357 templateUrl: 'modal-busqueda-productos.html', 364 templateUrl: 'modal-busqueda-productos.html',
358 controller: 'modalBusquedaProductosCtrl', 365 controller: 'modalBusquedaProductosCtrl',
359 resolve: { 366 resolve: {
360 parametroProducto: { 367 parametroProducto: {
361 idLista: $scope.idLista, 368 idLista: $scope.idLista,
362 cotizacion: $scope.remito.cotizacion.VENDEDOR, 369 cotizacion: $scope.remito.cotizacion.VENDEDOR,
363 simbolo: $scope.remito.cotizacion.moneda.SIMBOLO 370 simbolo: $scope.remito.cotizacion.moneda.SIMBOLO
364 } 371 }
365 }, 372 },
366 size: 'lg' 373 size: 'lg'
367 } 374 }
368 ); 375 );
369 modalInstance.result.then( 376 modalInstance.result.then(
370 function(producto) { 377 function(producto) {
371 var newArt = 378 var newArt =
372 { 379 {
373 id: 0, 380 id: 0,
374 idRemito: 0, 381 idRemito: 0,
375 codigo: producto.codigo, 382 codigo: producto.codigo,
376 sector: producto.sector, 383 sector: producto.sector,
377 sectorCodigo: producto.sector + '-' + producto.codigo, 384 sectorCodigo: producto.sector + '-' + producto.codigo,
378 descripcion: producto.descripcion, 385 descripcion: producto.descripcion,
379 item: $scope.remito.articulosRemito.length + 1, 386 item: $scope.remito.articulosRemito.length + 1,
380 nombre: producto.descripcion, 387 nombre: producto.descripcion,
381 precio: parseFloat(producto.precio.toFixed(4)), 388 precio: parseFloat(producto.precio.toFixed(4)),
382 costoUnitario: producto.costo, 389 costoUnitario: producto.costo,
383 editCantidad: false, 390 editCantidad: false,
384 editPrecio: false, 391 editPrecio: false,
385 rubro: producto.CodRub, 392 rubro: producto.CodRub,
386 exentoUnitario: producto.precio, 393 exentoUnitario: producto.precio,
387 ivaUnitario: producto.IMPIVA, 394 ivaUnitario: producto.IMPIVA,
388 impuestoInternoUnitario: producto.ImpInt, 395 impuestoInternoUnitario: producto.ImpInt,
389 impuestoInterno1Unitario: producto.ImpInt2, 396 impuestoInterno1Unitario: producto.ImpInt2,
390 impuestoInterno2Unitario: producto.ImpInt3, 397 impuestoInterno2Unitario: producto.ImpInt3,
391 precioLista: producto.precio, 398 precioLista: producto.precio,
392 combustible: 1, 399 combustible: 1,
393 facturado: 0 400 facturado: 0
394 }; 401 };
395 $scope.articuloACargar = newArt; 402 $scope.articuloACargar = newArt;
396 $scope.cargando = false; 403 $scope.cargando = false;
397 }, function() { 404 }, function() {
398 // funcion ejecutada cuando se cancela el modal 405 // funcion ejecutada cuando se cancela el modal
399 } 406 }
400 ); 407 );
401 }; 408 };
402 409
403 $scope.seleccionarPuntosDeDescarga = function() { 410 $scope.seleccionarPuntosDeDescarga = function() {
404 if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) { 411 if (!$scope.remito.cliente.COD || !$scope.remito.domicilio.id) {
405 focaModalService.alert('Primero seleccione un cliente y un domicilio'); 412 focaModalService.alert('Primero seleccione un cliente y un domicilio');
406 return; 413 return;
407 } else { 414 } else {
408 var modalInstance = $uibModal.open( 415 var modalInstance = $uibModal.open(
409 { 416 {
410 ariaLabelledBy: 'Búsqueda de Puntos de descarga', 417 ariaLabelledBy: 'Búsqueda de Puntos de descarga',
411 templateUrl: 'modal-punto-descarga.html', 418 templateUrl: 'modal-punto-descarga.html',
412 controller: 'focaModalPuntoDescargaController', 419 controller: 'focaModalPuntoDescargaController',
413 size: 'lg', 420 size: 'lg',
414 resolve: { 421 resolve: {
415 filters: { 422 filters: {
416 idDomicilio: $scope.remito.domicilio.id, 423 idDomicilio: $scope.remito.domicilio.id,
417 idCliente: $scope.remito.cliente.COD, 424 idCliente: $scope.remito.cliente.COD,
418 articulos: $scope.remito.articulosRemito, 425 articulos: $scope.remito.articulosRemito,
419 puntosDescarga: $scope.remito.domicilio.puntosDescarga 426 puntosDescarga: $scope.remito.domicilio.puntosDescarga
420 } 427 }
421 } 428 }
422 } 429 }
423 ); 430 );
424 modalInstance.result.then( 431 modalInstance.result.then(
425 function(puntosDescarga) { 432 function(puntosDescarga) {
426 $scope.remito.puntosDescarga = puntosDescarga; 433 $scope.remito.puntosDescarga = puntosDescarga;
427 434
428 //AGREGO PUNTOS DE DESCARGA A CABECERA 435 //AGREGO PUNTOS DE DESCARGA A CABECERA
429 var puntosStamp = ''; 436 var puntosStamp = '';
430 puntosDescarga.forEach(function(punto, idx, arr) { 437 puntosDescarga.forEach(function(punto, idx, arr) {
431 puntosStamp += punto.descripcion; 438 puntosStamp += punto.descripcion;
432 if ((idx + 1) !== arr.length) puntosStamp += ', '; 439 if ((idx + 1) !== arr.length) puntosStamp += ', ';
433 }); 440 });
434 441
435 $scope.$broadcast('addCabecera', { 442 $scope.$broadcast('addCabecera', {
436 label: 'Puntos de descarga:', 443 label: 'Puntos de descarga:',
437 valor: puntosStamp 444 valor: puntosStamp
438 }); 445 });
439 }, function() { 446 }, function() {
440 $scope.abrirModalDomicilios($scope.cliente); 447 $scope.abrirModalDomicilios($scope.cliente);
441 } 448 }
442 ); 449 );
443 } 450 }
444 }; 451 };
445 452
446 $scope.seleccionarVendedor = function(callback, ocultarVendedor) { 453 $scope.seleccionarVendedor = function(callback, ocultarVendedor) {
447 if (ocultarVendedor) { 454 if (ocultarVendedor) {
448 callback(); 455 callback();
449 return; 456 return;
450 } 457 }
451 458
452 if (varlidarRemitoFacturado()) { 459 if (varlidarRemitoFacturado()) {
453 var parametrosModal = { 460 var parametrosModal = {
454 titulo: 'Búsqueda vendedores', 461 titulo: 'Búsqueda vendedores',
455 query: '/vendedor', 462 query: '/vendedor',
456 columnas: [ 463 columnas: [
457 { 464 {
458 propiedad: 'NUM', 465 propiedad: 'NUM',
459 nombre: 'Código', 466 nombre: 'Código',
460 filtro: { 467 filtro: {
461 nombre: 'rellenarDigitos', 468 nombre: 'rellenarDigitos',
462 parametro: 3 469 parametro: 3
463 } 470 }
464 }, 471 },
465 { 472 {
466 propiedad: 'NOM', 473 propiedad: 'NOM',
467 nombre: 'Nombre' 474 nombre: 'Nombre'
468 } 475 }
469 ], 476 ],
470 size: 'md' 477 size: 'md'
471 }; 478 };
472 focaModalService.modal(parametrosModal).then( 479 focaModalService.modal(parametrosModal).then(
473 function(vendedor) { 480 function(vendedor) {
474 $scope.$broadcast('addCabecera',{ 481 $scope.$broadcast('addCabecera',{
475 label: 'Vendedor:', 482 label: 'Vendedor:',
476 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 483 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
477 vendedor.NOM 484 vendedor.NOM
478 }); 485 });
479 $scope.remito.idVendedor = vendedor.id; 486 $scope.remito.idVendedor = vendedor.id;
480 $scope.remito.vendedor = vendedor; 487 $scope.remito.vendedor = vendedor;
481 deleteCliente(); 488 deleteCliente();
482 callback(); 489 callback();
483 }, function() { 490 }, function() {
484 491
485 } 492 }
486 ); 493 );
487 } 494 }
488 }; 495 };
489 496
490 $scope.seleccionarCliente = function(ocultarVendedor) { 497 $scope.seleccionarCliente = function(ocultarVendedor) {
491 498
492 $scope.seleccionarVendedor(function() { 499 $scope.seleccionarVendedor(function() {
493 if (varlidarRemitoFacturado()) { 500 if (varlidarRemitoFacturado()) {
494 var modalInstance = $uibModal.open( 501 var modalInstance = $uibModal.open(
495 { 502 {
496 ariaLabelledBy: 'Busqueda de Cliente', 503 ariaLabelledBy: 'Busqueda de Cliente',
497 templateUrl: 'foca-busqueda-cliente-modal.html', 504 templateUrl: 'foca-busqueda-cliente-modal.html',
498 controller: 'focaBusquedaClienteModalController', 505 controller: 'focaBusquedaClienteModalController',
499 resolve: { 506 resolve: {
500 vendedor: function() { return $scope.remito.vendedor; }, 507 vendedor: function() { return $scope.remito.vendedor; },
501 cobrador: function() { return null; } 508 cobrador: function() { return null; }
502 }, 509 },
503 size: 'lg' 510 size: 'lg'
504 } 511 }
505 ); 512 );
506 modalInstance.result.then( 513 modalInstance.result.then(
507 function(cliente) { 514 function(cliente) {
508 $scope.abrirModalDomicilios(cliente); 515 $scope.abrirModalDomicilios(cliente);
509 $scope.cliente = cliente; 516 $scope.cliente = cliente;
510 }, function() { 517 }, function() {
511 $scope.seleccionarCliente(); 518 $scope.seleccionarCliente();
512 } 519 }
513 ); 520 );
514 } 521 }
515 }, ocultarVendedor); 522 }, ocultarVendedor);
516 }; 523 };
517 524
518 $scope.seleccionarProveedor = function(callback) { 525 $scope.seleccionarProveedor = function(callback) {
519 if (varlidarRemitoFacturado()) { 526 if (varlidarRemitoFacturado()) {
520 var parametrosModal = { 527 var parametrosModal = {
521 titulo: 'Búsqueda de Proveedor', 528 titulo: 'Búsqueda de Proveedor',
522 query: '/proveedor', 529 query: '/proveedor',
523 columnas: [ 530 columnas: [
524 { 531 {
525 nombre: 'Código', 532 nombre: 'Código',
526 propiedad: 'COD', 533 propiedad: 'COD',
527 filtro: { 534 filtro: {
528 nombre: 'rellenarDigitos', 535 nombre: 'rellenarDigitos',
529 parametro: 5 536 parametro: 5
530 } 537 }
531 }, 538 },
532 { 539 {
533 nombre: 'Nombre', 540 nombre: 'Nombre',
534 propiedad: 'NOM' 541 propiedad: 'NOM'
535 }, 542 },
536 { 543 {
537 nombre: 'CUIT', 544 nombre: 'CUIT',
538 propiedad: 'CUIT' 545 propiedad: 'CUIT'
539 } 546 }
540 ], 547 ],
541 tipo: 'POST', 548 tipo: 'POST',
542 json: {razonCuitCod: ''} 549 json: {razonCuitCod: ''}
543 }; 550 };
544 focaModalService.modal(parametrosModal).then( 551 focaModalService.modal(parametrosModal).then(
545 function(proveedor) { 552 function(proveedor) {
546 $scope.remito.proveedor = proveedor; 553 $scope.remito.proveedor = proveedor;
547 $scope.remito.idProveedor = proveedor.COD; 554 $scope.remito.idProveedor = proveedor.COD;
548 $scope.$broadcast('addCabecera',{ 555 $scope.$broadcast('addCabecera',{
549 label: 'Proveedor:', 556 label: 'Proveedor:',
550 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 557 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
551 proveedor.NOM 558 proveedor.NOM
552 }); 559 });
553 callback(); 560 callback();
554 }, function() { } 561 }, function() { }
555 ); 562 );
556 } 563 }
557 }; 564 };
558 565
559 $scope.abrirModalDomicilios = function(cliente) { 566 $scope.abrirModalDomicilios = function(cliente) {
560 var modalInstanceDomicilio = $uibModal.open( 567 var modalInstanceDomicilio = $uibModal.open(
561 { 568 {
562 ariaLabelledBy: 'Busqueda de Domicilios', 569 ariaLabelledBy: 'Busqueda de Domicilios',
563 templateUrl: 'modal-domicilio.html', 570 templateUrl: 'modal-domicilio.html',
564 controller: 'focaModalDomicilioController', 571 controller: 'focaModalDomicilioController',
565 size: 'lg', 572 size: 'lg',
566 resolve: { 573 resolve: {
567 idCliente: function() { return cliente.cod; }, 574 idCliente: function() { return cliente.cod; },
568 esNuevo: function() { return cliente.esNuevo; } 575 esNuevo: function() { return cliente.esNuevo; }
569 } 576 }
570 } 577 }
571 ); 578 );
572 modalInstanceDomicilio.result.then( 579 modalInstanceDomicilio.result.then(
573 function(domicilio) { 580 function(domicilio) {
574 $scope.remito.domicilio = domicilio; 581 $scope.remito.domicilio = domicilio;
575 $scope.remito.cliente = { 582 $scope.remito.cliente = {
576 COD: cliente.cod, 583 COD: cliente.cod,
577 CUIT: cliente.cuit, 584 CUIT: cliente.cuit,
578 NOM: cliente.nom, 585 NOM: cliente.nom,
579 MAIL: cliente.mail, 586 MAIL: cliente.mail,
580 MOD: cliente.mod 587 MOD: cliente.mod
581 }; 588 };
582 589
583 var domicilioStamp = 590 var domicilioStamp =
584 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 591 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
585 domicilio.Localidad + ', ' + domicilio.Provincia; 592 domicilio.Localidad + ', ' + domicilio.Provincia;
586 $scope.remito.domicilioStamp = domicilioStamp; 593 $scope.remito.domicilioStamp = domicilioStamp;
587 $scope.$broadcast('addCabecera',{ 594 $scope.$broadcast('addCabecera',{
588 label: 'Cliente:', 595 label: 'Cliente:',
589 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom 596 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
590 }); 597 });
591 $scope.$broadcast('addCabecera',{ 598 $scope.$broadcast('addCabecera',{
592 label: 'Domicilio:', 599 label: 'Domicilio:',
593 valor: domicilioStamp 600 valor: domicilioStamp
594 }); 601 });
595 602
596 if (domicilio.verPuntos) { 603 if (domicilio.verPuntos) {
597 delete $scope.remito.domicilio.verPuntos; 604 delete $scope.remito.domicilio.verPuntos;
598 $scope.seleccionarPuntosDeDescarga(); 605 $scope.seleccionarPuntosDeDescarga();
599 } else { 606 } else {
600 crearRemitoService 607 crearRemitoService
601 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 608 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
602 .then(function(res) { 609 .then(function(res) {
603 if (res.data.length) $scope.seleccionarPuntosDeDescarga(); 610 if (res.data.length) $scope.seleccionarPuntosDeDescarga();
604 }); 611 });
605 } 612 }
606 }, function() { 613 }, function() {
607 $scope.seleccionarCliente(true); 614 $scope.seleccionarCliente(true);
608 return; 615 return;
609 } 616 }
610 ); 617 );
611 }; 618 };
612 619
613 $scope.getTotal = function() { 620 $scope.getTotal = function() {
614 var total = 0; 621 var total = 0;
615 var arrayTempArticulos = $scope.articulosFiltro(); 622 var arrayTempArticulos = $scope.articulosFiltro();
616 for(var i = 0; i < arrayTempArticulos.length; i++) { 623 for(var i = 0; i < arrayTempArticulos.length; i++) {
617 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 624 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
618 } 625 }
619 return parseFloat(total.toFixed(2)); 626 return parseFloat(total.toFixed(2));
620 }; 627 };
621 628
622 $scope.getSubTotal = function() { 629 $scope.getSubTotal = function() {
623 if ($scope.articuloACargar) { 630 if ($scope.articuloACargar) {
624 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 631 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
625 } 632 }
626 }; 633 };
627 634
628 $scope.seleccionarPreciosYCondiciones = function() { 635 $scope.seleccionarPreciosYCondiciones = function() {
629 if (!$scope.remito.cliente.COD) { 636 if (!$scope.remito.cliente.COD) {
630 focaModalService.alert('Primero seleccione un cliente'); 637 focaModalService.alert('Primero seleccione un cliente');
631 return; 638 return;
632 } 639 }
633 if (varlidarRemitoFacturado()) { 640 if (varlidarRemitoFacturado()) {
634 var modalInstance = $uibModal.open( 641 var modalInstance = $uibModal.open(
635 { 642 {
636 ariaLabelledBy: 'Busqueda de Precio Condición', 643 ariaLabelledBy: 'Busqueda de Precio Condición',
637 templateUrl: 'modal-precio-condicion.html', 644 templateUrl: 'modal-precio-condicion.html',
638 controller: 'focaModalPrecioCondicionController', 645 controller: 'focaModalPrecioCondicionController',
639 size: 'lg', 646 size: 'lg',
640 resolve: { 647 resolve: {
641 idListaPrecio: function() { 648 idListaPrecio: function() {
642 return $scope.remito.cliente.MOD || null; 649 return $scope.remito.cliente.MOD || null;
643 } 650 }
644 } 651 }
645 } 652 }
646 ); 653 );
647 modalInstance.result.then( 654 modalInstance.result.then(
648 function(precioCondicion) { 655 function(precioCondicion) {
649 var cabecera = ''; 656 var cabecera = '';
650 var plazosConcat = ''; 657 var plazosConcat = '';
651 if (!Array.isArray(precioCondicion)) { 658 if (!Array.isArray(precioCondicion)) {
652 $scope.remito.idPrecioCondicion = precioCondicion.id; 659 $scope.remito.idPrecioCondicion = precioCondicion.id;
653 $scope.remito.remitoPlazo = precioCondicion.plazoPago; 660 $scope.remito.remitoPlazo = precioCondicion.plazoPago;
654 $scope.idLista = precioCondicion.idListaPrecio; 661 $scope.idLista = precioCondicion.idListaPrecio;
655 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 662 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
656 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 663 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
657 } 664 }
658 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 665 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
659 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 666 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
660 } else { //Cuando se ingresan los plazos manualmente 667 } else { //Cuando se ingresan los plazos manualmente
661 $scope.remito.idPrecioCondicion = 0; 668 $scope.remito.idPrecioCondicion = 0;
662 //-1, el modal productos busca todos los productos 669 //-1, el modal productos busca todos los productos
663 $scope.idLista = -1; 670 $scope.idLista = -1;
664 $scope.remito.remitoPlazo = precioCondicion; 671 $scope.remito.remitoPlazo = precioCondicion;
665 for(var j = 0; j < precioCondicion.length; j++) { 672 for(var j = 0; j < precioCondicion.length; j++) {
666 plazosConcat += precioCondicion[j].dias + ' '; 673 plazosConcat += precioCondicion[j].dias + ' ';
667 } 674 }
668 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 675 cabecera = 'Ingreso manual ' + plazosConcat.trim();
669 } 676 }
670 $scope.remito.articulosRemito = []; 677 $scope.remito.articulosRemito = [];
671 $scope.$broadcast('addCabecera',{ 678 $scope.$broadcast('addCabecera',{
672 label: 'Precios y condiciones:', 679 label: 'Precios y condiciones:',
673 valor: cabecera 680 valor: cabecera
674 }); 681 });
675 $scope.remito.precioCondicion = precioCondicion; 682 $scope.remito.precioCondicion = precioCondicion;
676 }, function() { 683 }, function() {
677 684
678 } 685 }
679 ); 686 );
680 } 687 }
681 }; 688 };
682 689
683 $scope.seleccionarTransportista = function() { 690 $scope.seleccionarTransportista = function() {
684 $scope.seleccionarProveedor(function() { 691 $scope.seleccionarProveedor(function() {
685 if (varlidarRemitoFacturado()) { 692 if (varlidarRemitoFacturado()) {
686 var modalInstance = $uibModal.open( 693 var modalInstance = $uibModal.open(
687 { 694 {
688 ariaLabelledBy: 'Busqueda de Flete', 695 ariaLabelledBy: 'Busqueda de Flete',
689 templateUrl: 'modal-flete.html', 696 templateUrl: 'modal-flete.html',
690 controller: 'focaModalFleteController', 697 controller: 'focaModalFleteController',
691 size: 'lg', 698 size: 'lg',
692 resolve: { 699 resolve: {
693 parametrosFlete: 700 parametrosFlete:
694 function() { 701 function() {
695 return { 702 return {
696 flete: $scope.remito.flete ? '1' : 703 flete: $scope.remito.flete ? '1' :
697 ($scope.remito.fob ? 'FOB' : 704 ($scope.remito.fob ? 'FOB' :
698 ($scope.remito.flete === undefined ? 705 ($scope.remito.flete === undefined ?
699 null : '0')), 706 null : '0')),
700 bomba: $scope.remito.bomba ? '1' : 707 bomba: $scope.remito.bomba ? '1' :
701 ($scope.remito.bomba === undefined ? 708 ($scope.remito.bomba === undefined ?
702 null : '0'), 709 null : '0'),
703 kilometros: $scope.remito.kilometros 710 kilometros: $scope.remito.kilometros
704 }; 711 };
705 } 712 }
706 } 713 }
707 } 714 }
708 ); 715 );
709 modalInstance.result.then( 716 modalInstance.result.then(
710 function(datos) { 717 function(datos) {
711 $scope.remito.flete = datos.flete; 718 $scope.remito.flete = datos.flete;
712 $scope.remito.fob = datos.FOB; 719 $scope.remito.fob = datos.FOB;
713 $scope.remito.bomba = datos.bomba; 720 $scope.remito.bomba = datos.bomba;
714 $scope.remito.kilometros = datos.kilometros; 721 $scope.remito.kilometros = datos.kilometros;
715 722
716 $scope.$broadcast('addCabecera',{ 723 $scope.$broadcast('addCabecera',{
717 label: 'Flete:', 724 label: 'Flete:',
718 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 725 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
719 }); 726 });
720 if (datos.flete) { 727 if (datos.flete) {
721 $scope.$broadcast('addCabecera',{ 728 $scope.$broadcast('addCabecera',{
722 label: 'Bomba:', 729 label: 'Bomba:',
723 valor: datos.bomba ? 'Si' : 'No' 730 valor: datos.bomba ? 'Si' : 'No'
724 }); 731 });
725 $scope.$broadcast('addCabecera',{ 732 $scope.$broadcast('addCabecera',{
726 label: 'Kilometros:', 733 label: 'Kilometros:',
727 valor: datos.kilometros 734 valor: datos.kilometros
728 }); 735 });
729 } else { 736 } else {
730 $scope.$broadcast('removeCabecera', 'Bomba:'); 737 $scope.$broadcast('removeCabecera', 'Bomba:');
731 $scope.$broadcast('removeCabecera', 'Kilometros:'); 738 $scope.$broadcast('removeCabecera', 'Kilometros:');
732 $scope.remito.bomba = false; 739 $scope.remito.bomba = false;
733 $scope.remito.kilometros = null; 740 $scope.remito.kilometros = null;
734 } 741 }
735 }, function() { 742 }, function() {
736 $scope.seleccionarTransportista(); 743 $scope.seleccionarTransportista();
737 } 744 }
738 ); 745 );
739 } 746 }
740 }); 747 });
741 }; 748 };
742 749
743 $scope.seleccionarMoneda = function() { 750 $scope.seleccionarMoneda = function() {
744 if (varlidarRemitoFacturado()) { 751 if (varlidarRemitoFacturado()) {
745 var parametrosModal = { 752 var parametrosModal = {
746 titulo: 'Búsqueda de monedas', 753 titulo: 'Búsqueda de monedas',
747 query: '/moneda', 754 query: '/moneda',
748 columnas: [ 755 columnas: [
749 { 756 {
750 propiedad: 'DETALLE', 757 propiedad: 'DETALLE',
751 nombre: 'Nombre' 758 nombre: 'Nombre'
752 }, 759 },
753 { 760 {
754 propiedad: 'SIMBOLO', 761 propiedad: 'SIMBOLO',
755 nombre: 'Símbolo' 762 nombre: 'Símbolo'
756 } 763 }
757 ], 764 ],
758 size: 'md' 765 size: 'md'
759 }; 766 };
760 focaModalService.modal(parametrosModal).then( 767 focaModalService.modal(parametrosModal).then(
761 function(moneda) { 768 function(moneda) {
762 $scope.abrirModalCotizacion(moneda); 769 $scope.abrirModalCotizacion(moneda);
763 }, function() { 770 }, function() {
764 771
765 } 772 }
766 ); 773 );
767 } 774 }
768 }; 775 };
769 776
770 $scope.seleccionarObservaciones = function() { 777 $scope.seleccionarObservaciones = function() {
771 focaModalService 778 focaModalService
772 .prompt({ 779 .prompt({
773 titulo: 'Observaciones', 780 titulo: 'Observaciones',
774 value: $scope.remito.observaciones, 781 value: $scope.remito.observaciones,
775 textarea: true, 782 textarea: true,
776 readonly: true 783 readonly: true
777 }) 784 })
778 .then(function(observaciones) { 785 .then(function(observaciones) {
779 $scope.remito.observaciones = observaciones; 786 $scope.remito.observaciones = observaciones;
780 }); 787 });
781 }; 788 };
782 789
783 $scope.abrirModalCotizacion = function(moneda) { 790 $scope.abrirModalCotizacion = function(moneda) {
784 var modalInstance = $uibModal.open( 791 var modalInstance = $uibModal.open(
785 { 792 {
786 ariaLabelledBy: 'Busqueda de Cotización', 793 ariaLabelledBy: 'Busqueda de Cotización',
787 templateUrl: 'modal-cotizacion.html', 794 templateUrl: 'modal-cotizacion.html',
788 controller: 'focaModalCotizacionController', 795 controller: 'focaModalCotizacionController',
789 size: 'lg', 796 size: 'lg',
790 resolve: {idMoneda: function() {return moneda.ID;}} 797 resolve: {idMoneda: function() {return moneda.ID;}}
791 } 798 }
792 ); 799 );
793 modalInstance.result.then( 800 modalInstance.result.then(
794 function(cotizacion) { 801 function(cotizacion) {
795 var articulosTablaTemp = $scope.remito.articulosRemito; 802 var articulosTablaTemp = $scope.remito.articulosRemito;
796 for(var i = 0; i < articulosTablaTemp.length; i++) { 803 for(var i = 0; i < articulosTablaTemp.length; i++) {
797 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 804 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
798 $scope.remito.cotizacion.VENDEDOR; 805 $scope.remito.cotizacion.VENDEDOR;
799 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 806 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
800 cotizacion.VENDEDOR; 807 cotizacion.VENDEDOR;
801 } 808 }
802 $scope.remito.articulosRemito = articulosTablaTemp; 809 $scope.remito.articulosRemito = articulosTablaTemp;
803 $scope.remito.cotizacion = cotizacion; 810 $scope.remito.cotizacion = cotizacion;
804 $scope.remito.cotizacion.moneda = moneda; 811 $scope.remito.cotizacion.moneda = moneda;
805 if (moneda.DETALLE === 'PESOS ARGENTINOS') { 812 if (moneda.DETALLE === 'PESOS ARGENTINOS') {
806 $scope.$broadcast('removeCabecera', 'Moneda:'); 813 $scope.$broadcast('removeCabecera', 'Moneda:');
807 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 814 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
808 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 815 $scope.$broadcast('removeCabecera', 'Cotizacion:');
809 } else { 816 } else {
810 $scope.$broadcast('addCabecera',{ 817 $scope.$broadcast('addCabecera',{
811 label: 'Moneda:', 818 label: 'Moneda:',
812 valor: moneda.DETALLE 819 valor: moneda.DETALLE
813 }); 820 });
814 $scope.$broadcast('addCabecera',{ 821 $scope.$broadcast('addCabecera',{
815 label: 'Fecha cotizacion:', 822 label: 'Fecha cotizacion:',
816 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 823 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
817 }); 824 });
818 $scope.$broadcast('addCabecera',{ 825 $scope.$broadcast('addCabecera',{
819 label: 'Cotizacion:', 826 label: 'Cotizacion:',
820 valor: $filter('number')(cotizacion.VENDEDOR, '2') 827 valor: $filter('number')(cotizacion.VENDEDOR, '2')
821 }); 828 });
822 } 829 }
823 }, function() { 830 }, function() {
824 831
825 } 832 }
826 ); 833 );
827 }; 834 };
828 835
829 $scope.agregarATabla = function(key) { 836 $scope.agregarATabla = function(key) {
830 if (key === 13) { 837 if (key === 13) {
831 if ($scope.articuloACargar.cantidad === undefined || 838 if ($scope.articuloACargar.cantidad === undefined ||
832 $scope.articuloACargar.cantidad === 0 || 839 $scope.articuloACargar.cantidad === 0 ||
833 $scope.articuloACargar.cantidad === null ) { 840 $scope.articuloACargar.cantidad === null ) {
834 focaModalService.alert('El valor debe ser al menos 1'); 841 focaModalService.alert('El valor debe ser al menos 1');
835 return; 842 return;
836 } 843 }
837 delete $scope.articuloACargar.sectorCodigo; 844 delete $scope.articuloACargar.sectorCodigo;
838 $scope.remito.articulosRemito.push($scope.articuloACargar); 845 $scope.remito.articulosRemito.push($scope.articuloACargar);
839 $scope.cargando = true; 846 $scope.cargando = true;
840 } 847 }
841 }; 848 };
842 849
843 $scope.quitarArticulo = function(articulo) { 850 $scope.quitarArticulo = function(articulo) {
844 articulo.idRemito = -1; 851 articulo.idRemito = -1;
845 }; 852 };
846 853
847 $scope.articulosFiltro = function() { 854 $scope.articulosFiltro = function() {
848 855
849 var result = $scope.remito.articulosRemito.filter(function(articulo) { 856 var result = $scope.remito.articulosRemito.filter(function(articulo) {
850 return articulo.idRemito >= 0; 857 return articulo.idRemito >= 0;
851 }); 858 });
852 return result; 859 return result;
853 }; 860 };
854 861
855 $scope.editarArticulo = function(key, articulo) { 862 $scope.editarArticulo = function(key, articulo) {
856 if (key === 13) { 863 if (key === 13) {
857 if (!articulo.cantidad || !articulo.precio) { 864 if (!articulo.cantidad || !articulo.precio) {
858 focaModalService.alert('Los valores deben ser al menos 1'); 865 focaModalService.alert('Los valores deben ser al menos 1');
859 return; 866 return;
860 } else if (articulo.cantidad < 0 || articulo.precio < 0) { 867 } else if (articulo.cantidad < 0 || articulo.precio < 0) {
861 focaModalService.alert('Los valores no pueden ser negativos'); 868 focaModalService.alert('Los valores no pueden ser negativos');
862 return; 869 return;
863 } 870 }
864 articulo.editCantidad = articulo.editPrecio = false; 871 articulo.editCantidad = articulo.editPrecio = false;
865 } 872 }
866 }; 873 };
867 874
868 $scope.cambioEdit = function(articulo, propiedad) { 875 $scope.cambioEdit = function(articulo, propiedad) {
869 if (propiedad === 'cantidad') { 876 if (propiedad === 'cantidad') {
870 articulo.editCantidad = true; 877 articulo.editCantidad = true;
871 } else if (propiedad === 'precio') { 878 } else if (propiedad === 'precio') {
872 articulo.editPrecio = true; 879 articulo.editPrecio = true;
873 } 880 }
874 }; 881 };
875 882
876 $scope.resetFilter = function() { 883 $scope.resetFilter = function() {
877 $scope.articuloACargar = {}; 884 $scope.articuloACargar = {};
878 $scope.cargando = true; 885 $scope.cargando = true;
879 }; 886 };
880 //Recibe aviso si el teclado está en uso 887 //Recibe aviso si el teclado está en uso
881 $rootScope.$on('usarTeclado', function(event, data) { 888 $rootScope.$on('usarTeclado', function(event, data) {
882 if (data) { 889 if (data) {
883 $scope.mostrarTeclado = true; 890 $scope.mostrarTeclado = true;
884 return; 891 return;
885 } 892 }
886 $scope.mostrarTeclado = false; 893 $scope.mostrarTeclado = false;
887 }); 894 });
888 895
889 $scope.selectFocus = function($event) { 896 $scope.selectFocus = function($event) {
890 // Si el teclado esta en uso no selecciona el valor 897 // Si el teclado esta en uso no selecciona el valor
891 if ($scope.mostrarTeclado) { 898 if ($scope.mostrarTeclado) {
892 return; 899 return;
893 } 900 }
894 $event.target.select(); 901 $event.target.select();
895 }; 902 };
896 903
897 function addArrayCabecera(array) { 904 function addArrayCabecera(array) {
898 for (var i = 0; i < array.length; i++) { 905 for (var i = 0; i < array.length; i++) {
899 $scope.$broadcast('addCabecera',{ 906 $scope.$broadcast('addCabecera',{
900 label: array[i].label, 907 label: array[i].label,
901 valor: array[i].valor 908 valor: array[i].valor
902 }); 909 });
903 } 910 }
904 } 911 }
905 912
906 function rellenar(relleno, longitud) { 913 function rellenar(relleno, longitud) {
907 relleno = '' + relleno; 914 relleno = '' + relleno;
908 while (relleno.length < longitud) { 915 while (relleno.length < longitud) {
909 relleno = '0' + relleno; 916 relleno = '0' + relleno;
910 } 917 }
911 return relleno; 918 return relleno;
912 } 919 }
913 920
914 function varlidarRemitoFacturado() { 921 function varlidarRemitoFacturado() {
915 if ($scope.remito.estado !== 5) { 922 if ($scope.remito.estado !== 5) {
916 return true; 923 return true;
917 } else { 924 } else {
918 focaModalService.alert('No se puede editar un remito facturado'); 925 focaModalService.alert('No se puede editar un remito facturado');
919 return false(); 926 return false();
920 } 927 }
921 } 928 }
922 929
923 function salir() { 930 function salir() {
924 var confirmacion = false; 931 var confirmacion = false;
925 932
926 if (!angular.equals($scope.remito, $scope.inicial)) { 933 if (!angular.equals($scope.remito, $scope.inicial)) {
927 confirmacion = true; 934 confirmacion = true;
928 } 935 }
929 936
930 if (confirmacion) { 937 if (confirmacion) {
931 focaModalService.confirm( 938 focaModalService.confirm(
932 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 939 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
933 ).then(function(data) { 940 ).then(function(data) {
934 if (data) { 941 if (data) {
935 $location.path('/'); 942 $location.path('/');
936 } 943 }
937 }); 944 });
938 } else { 945 } else {
939 $location.path('/'); 946 $location.path('/');
940 } 947 }
941 } 948 }
942 949
943 function enableObservaciones(val) { 950 function enableObservaciones(val) {
944 var boton = $scope.botonera.filter(function(botonObs) { 951 var boton = $scope.botonera.filter(function(botonObs) {
945 return botonObs.label === 'Observaciones'; 952 return botonObs.label === 'Observaciones';
946 }); 953 });
947 boton[0].disable = !val; 954 boton[0].disable = !val;
948 } 955 }
949 956
950 function setearRemito(remito) { 957 function setearRemito(remito) {
951 //añado cabeceras 958 //añado cabeceras
952 $scope.$broadcast('removeCabecera', 'Moneda:'); 959 $scope.$broadcast('removeCabecera', 'Moneda:');
953 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 960 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
954 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 961 $scope.$broadcast('removeCabecera', 'Cotizacion:');
955 962
956 var cabeceras = []; 963 var cabeceras = [];
957 964
958 if (remito.cotizacion.moneda.CODIGO_AFIP != 'PES') { 965 if (remito.cotizacion.moneda.CODIGO_AFIP !== 'PES') {
959 cabeceras.push({ 966 cabeceras.push({
960 label: 'Moneda:', 967 label: 'Moneda:',
961 valor: remito.cotizacion.moneda.DETALLE 968 valor: remito.cotizacion.moneda.DETALLE
962 }); 969 });
963 cabeceras.push({ 970 cabeceras.push({
964 label: 'Fecha cotizacion:', 971 label: 'Fecha cotizacion:',
965 valor: $filter('date')(remito.cotizacion.FECHA, 972 valor: $filter('date')(remito.cotizacion.FECHA,
966 'dd/MM/yyyy') 973 'dd/MM/yyyy')
967 }); 974 });
968 cabeceras.push({ 975 cabeceras.push({
969 label: 'Cotizacion:', 976 label: 'Cotizacion:',
970 valor: $filter('number')(remito.cotizacion.VENDEDOR, 977 valor: $filter('number')(remito.cotizacion.VENDEDOR,
971 '2') 978 '2')
972 }); 979 });
973 } 980 }
974 if (remito.cliente.COD) { 981 if (remito.cliente.COD) {
975 cabeceras.push({ 982 cabeceras.push({
976 label: 'Cliente:', 983 label: 'Cliente:',
977 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + 984 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
978 remito.cliente.NOM 985 remito.cliente.NOM
979 }); 986 });
980 cabeceras.push({ 987 cabeceras.push({
981 label: 'Domicilio:', 988 label: 'Domicilio:',
982 valor: remito.domicilioStamp 989 valor: remito.domicilioStamp
983 }); 990 });
984 } 991 }
985 if (remito.vendedor.NUM) { 992 if (remito.vendedor.NUM) {
986 cabeceras.push({ 993 cabeceras.push({
987 label: 'Vendedor:', 994 label: 'Vendedor:',
988 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + 995 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
989 ' - ' + remito.vendedor.NOM 996 ' - ' + remito.vendedor.NOM
990 }); 997 });
991 } 998 }
992 if (remito.proveedor.COD) { 999 if (remito.proveedor.COD) {
993 cabeceras.push({ 1000 cabeceras.push({
994 label: 'Proveedor:', 1001 label: 'Proveedor:',
995 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + 1002 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
996 ' - ' + remito.proveedor.NOM 1003 ' - ' + remito.proveedor.NOM
997 }); 1004 });
998 } 1005 }
999 if (remito.flete !== undefined && remito.fob !== undefined) { 1006 if (remito.flete !== undefined && remito.fob !== undefined) {
1000 cabeceras.push({ 1007 cabeceras.push({
1001 label: 'Flete:', 1008 label: 'Flete:',
1002 valor: remito.fob ? 'FOB' : ( 1009 valor: remito.fob ? 'FOB' : (
1003 remito.flete ? 'Si' : 'No') 1010 remito.flete ? 'Si' : 'No')
1004 }); 1011 });
1005 } 1012 }
1006 if (remito.remitoPlazo) { 1013 if (remito.remitoPlazo) {
1007 cabeceras.push({ 1014 cabeceras.push({
1008 label: 'Precio condicion:', 1015 label: 'Precio condicion:',
1009 valor: valorPrecioCondicion() + ' ' + 1016 valor: valorPrecioCondicion() + ' ' +
1010 remitoBusinessService.plazoToString(remito.remitoPlazo) 1017 remitoBusinessService.plazoToString(remito.remitoPlazo)
1011 }); 1018 });
1012 } 1019 }
1013 function valorPrecioCondicion() { 1020 function valorPrecioCondicion() {
1014 if (remito.idPrecioCondicion > 0) { 1021 if (remito.idPrecioCondicion > 0) {
1015 return remito.precioCondicion.nombre; 1022 return remito.precioCondicion.nombre;
1016 } else { 1023 } else {
1017 return 'Ingreso Manual'; 1024 return 'Ingreso Manual';
1018 } 1025 }
1019 } 1026 }
1020 if (remito.flete === 1) { 1027 if (remito.flete === 1) {
1021 var cabeceraBomba = { 1028 var cabeceraBomba = {
1022 label: 'Bomba', 1029 label: 'Bomba',
1023 valor: remito.bomba === 1 ? 'Si' : 'No' 1030 valor: remito.bomba === 1 ? 'Si' : 'No'
1024 }; 1031 };
1025 if (remito.kilometros) { 1032 if (remito.kilometros) {
1026 var cabeceraKilometros = { 1033 var cabeceraKilometros = {
1027 label: 'Kilometros', 1034 label: 'Kilometros',
1028 valor: remito.kilometros 1035 valor: remito.kilometros
1029 }; 1036 };
1030 cabeceras.push(cabeceraKilometros); 1037 cabeceras.push(cabeceraKilometros);
1031 } 1038 }
1032 cabeceras.push(cabeceraBomba); 1039 cabeceras.push(cabeceraBomba);
1033 } 1040 }
1034 $scope.remito.articulosRemito = remito.articulosRemito; 1041 $scope.remito.articulosRemito = remito.articulosRemito;
1035 1042
1036 if (remito.idPrecioCondicion > 0) { 1043 if (remito.idPrecioCondicion > 0) {
1037 $scope.idLista = remito.precioCondicion.idListaPrecio; 1044 $scope.idLista = remito.precioCondicion.idListaPrecio;
1038 } else { 1045 } else {
1039 $scope.idLista = -1; 1046 $scope.idLista = -1;
1040 } 1047 }
1041 $scope.puntoVenta = rellenar(remito.sucursal, 4); 1048 $scope.puntoVenta = rellenar(remito.sucursal, 4);
1042 $scope.comprobante = rellenar(remito.numeroRemito, 8); 1049 $scope.comprobante = rellenar(remito.numeroRemito, 8);
1043 $scope.remito = remito; 1050 $scope.remito = remito;
1044 addArrayCabecera(cabeceras); 1051 addArrayCabecera(cabeceras);
1045 } 1052 }
1046 1053
1047 function getLSRemito() { 1054 function getLSRemito() {
1048 var remito = JSON.parse($localStorage.remito || null); 1055 var remito = JSON.parse($localStorage.remito || null);
1049 if (remito) { 1056 if (remito) {
1050 setearRemito(remito); 1057 setearRemito(remito);
1051 delete $localStorage.remito; 1058 delete $localStorage.remito;
1052 } 1059 }
1053 } 1060 }
1054 1061
1055 function deleteCliente() { 1062 function deleteCliente() {
1056 delete $scope.remito.domicilioStamp; 1063 delete $scope.remito.domicilioStamp;
1057 delete $scope.remito.puntosDescarga; 1064 delete $scope.remito.puntosDescarga;
1058 $scope.remito.domicilio = {dom: ''}; 1065 $scope.remito.domicilio = {dom: ''};
1059 $scope.remito.cliente = {}; 1066 $scope.remito.cliente = {};
1060 $scope.$broadcast('removeCabecera', 'Cliente:'); 1067 $scope.$broadcast('removeCabecera', 'Cliente:');
1061 $scope.$broadcast('removeCabecera', 'Domicilio:'); 1068 $scope.$broadcast('removeCabecera', 'Domicilio:');
1062 $scope.$broadcast('removeCabecera', 'Puntos de descarga:'); 1069 $scope.$broadcast('removeCabecera', 'Puntos de descarga:');
1063 } 1070 }
1064 1071
1065 function abrirModalMail(id, cliente, numeroRemito) { 1072 function abrirModalMail(id, cliente, numeroRemito) {
1066 focaModalService.mail( 1073 focaModalService.mail(
1067 { 1074 {
1068 titulo: 'Comprobante de remito Nº ' + numeroRemito, 1075 titulo: 'Comprobante de remito Nº ' + numeroRemito,
1069 descarga: { 1076 descarga: {
1070 nombre: numeroRemito + '.pdf', 1077 nombre: numeroRemito + '.pdf',
1071 url: '/remito/comprobante', 1078 url: '/remito/comprobante',
1072 }, 1079 },
1073 envio: { 1080 envio: {
1074 mailCliente: cliente.MAIL, 1081 mailCliente: cliente.MAIL,
1075 url: '/remito/mail', 1082 url: '/remito/mail',
1076 }, 1083 },
1077 options: { 1084 options: {
1078 idRemito: id 1085 idRemito: id
1079 } 1086 }
1080 } 1087 }
1081 ) 1088 )
1082 .then(function(res) { 1089 .then(function(res) {
1083 if (res === false) { 1090 if (res === false) {
1084 abrirModalMail(id); 1091 abrirModalMail(id);
1085 focaModalService.alert('Descarga o envíe su remito ' + 1092 focaModalService.alert('Descarga o envíe su remito ' +
1086 'antes de cerrar esta ventana'); 1093 'antes de cerrar esta ventana');
1087 } 1094 }
1088 }); 1095 });
1089 } 1096 }
1090 } 1097 }
1091 ]); 1098 ]);
1092 1099