Commit a7ee896113754ff77c3a8407eec6572a5e7a4c24

Authored by Marcelo Puebla
1 parent 628295ece3
Exists in master

Arreglo en cabecera de remito.

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