Commit 6afee148bf69329527eac1187c99e689e988501a

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

Merge branch 'master' into 'develop'

Master(efernandez)

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