Commit f8700fda2c16165b217aca90b7e441bd291b54ca

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

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