Commit d6743975db38b2eac39957a529ef48e957c224d3

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'develop'

Master(efernandez)

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