Commit c3549f34ca115cbb2f47ecef87ef246154db1e01

Authored by Eric Fernandez
Exists in master and in 2 other branches develop, lab

Merge branch 'master' into 'develop'

Master

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