Commit 4ce8665740b26fc8cc053cbb0d22b2ab2cf33721

Authored by Luigi
1 parent 40bff8f951
Exists in master

edición en Flete

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