Commit d28f1da104aaa022e5299424d1b72ecf4a408731

Authored by Luigi
Exists in master

Merge branch 'master' into 'develop'

Master(efernandez)

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