Commit 57e2a704571876454f76626c7d5bfbcd92c14db1

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

See merge request !39
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() { 445 $scope.seleccionarVendedor = function() {
446 if(varlidarRemitoFacturado()) { 446 if(varlidarRemitoFacturado()) {
447 var parametrosModal = { 447 var parametrosModal = {
448 titulo: 'Búsqueda vendedores', 448 titulo: 'Búsqueda vendedores',
449 query: '/vendedor', 449 query: '/vendedor',
450 columnas: [ 450 columnas: [
451 { 451 {
452 propiedad: 'NUM', 452 propiedad: 'NUM',
453 nombre: 'Código', 453 nombre: 'Código',
454 filtro: { 454 filtro: {
455 nombre: 'rellenarDigitos', 455 nombre: 'rellenarDigitos',
456 parametro: 3 456 parametro: 3
457 } 457 }
458 }, 458 },
459 { 459 {
460 propiedad: 'NOM', 460 propiedad: 'NOM',
461 nombre: 'Nombre' 461 nombre: 'Nombre'
462 } 462 }
463 ], 463 ],
464 size: 'md' 464 size: 'md'
465 }; 465 };
466 focaModalService.modal(parametrosModal).then( 466 focaModalService.modal(parametrosModal).then(
467 function(vendedor) { 467 function(vendedor) {
468 $scope.$broadcast('addCabecera',{ 468 $scope.$broadcast('addCabecera',{
469 label: 'Vendedor:', 469 label: 'Vendedor:',
470 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' + 470 valor: $filter('rellenarDigitos')(vendedor.NUM, 3) + ' - ' +
471 vendedor.NOM 471 vendedor.NOM
472 }); 472 });
473 $scope.remito.idVendedor = vendedor.id; 473 $scope.remito.idVendedor = vendedor.id;
474 $scope.remito.vendedor = vendedor; 474 $scope.remito.vendedor = vendedor;
475 }, function() { 475 }, function() {
476 476
477 } 477 }
478 ); 478 );
479 } 479 }
480 }; 480 };
481 481
482 $scope.seleccionarProveedor = function() { 482 $scope.seleccionarProveedor = function() {
483 if(varlidarRemitoFacturado()) { 483 if(varlidarRemitoFacturado()) {
484 var parametrosModal = { 484 var parametrosModal = {
485 titulo: 'Búsqueda de Proveedor', 485 titulo: 'Búsqueda de Proveedor',
486 query: '/proveedor', 486 query: '/proveedor',
487 columnas: [ 487 columnas: [
488 { 488 {
489 nombre: 'Código', 489 nombre: 'Código',
490 propiedad: 'COD', 490 propiedad: 'COD',
491 filtro: { 491 filtro: {
492 nombre: 'rellenarDigitos', 492 nombre: 'rellenarDigitos',
493 parametro: 5 493 parametro: 5
494 } 494 }
495 }, 495 },
496 { 496 {
497 nombre: 'Nombre', 497 nombre: 'Nombre',
498 propiedad: 'NOM' 498 propiedad: 'NOM'
499 }, 499 },
500 { 500 {
501 nombre: 'CUIT', 501 nombre: 'CUIT',
502 propiedad: 'CUIT' 502 propiedad: 'CUIT'
503 } 503 }
504 ], 504 ],
505 tipo: 'POST', 505 tipo: 'POST',
506 json: {razonCuitCod: ''} 506 json: {razonCuitCod: ''}
507 }; 507 };
508 focaModalService.modal(parametrosModal).then( 508 focaModalService.modal(parametrosModal).then(
509 function(proveedor) { 509 function(proveedor) {
510 $scope.remito.proveedor = proveedor; 510 $scope.remito.proveedor = proveedor;
511 $scope.remito.idProveedor = proveedor.COD; 511 $scope.remito.idProveedor = proveedor.COD;
512 512
513 $scope.$broadcast('addCabecera',{ 513 $scope.$broadcast('addCabecera',{
514 label: 'Proveedor:', 514 label: 'Proveedor:',
515 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' + 515 valor: $filter('rellenarDigitos')(proveedor.COD, 5) + ' - ' +
516 proveedor.NOM 516 proveedor.NOM
517 }); 517 });
518 }, function() { 518 }, function() {
519 519
520 } 520 }
521 ); 521 );
522 } 522 }
523 }; 523 };
524 524
525 $scope.seleccionarCliente = function() { 525 $scope.seleccionarCliente = function() {
526 if (!$scope.remito.vendedor) { 526 if (!$scope.remito.vendedor) {
527 focaModalService.alert('Primero seleccione un vendedor'); 527 focaModalService.alert('Primero seleccione un vendedor');
528 return; 528 return;
529 } 529 }
530 530
531 if (varlidarRemitoFacturado()) { 531 if (varlidarRemitoFacturado()) {
532 var modalInstance = $uibModal.open( 532 var modalInstance = $uibModal.open(
533 { 533 {
534 ariaLabelledBy: 'Busqueda de Cliente', 534 ariaLabelledBy: 'Busqueda de Cliente',
535 templateUrl: 'foca-busqueda-cliente-modal.html', 535 templateUrl: 'foca-busqueda-cliente-modal.html',
536 controller: 'focaBusquedaClienteModalController', 536 controller: 'focaBusquedaClienteModalController',
537 resolve: { 537 resolve: {
538 vendedor: function() { return $scope.remito.vendedor; } 538 vendedor: function() { return $scope.remito.vendedor; }
539 }, 539 },
540 size: 'lg' 540 size: 'lg'
541 } 541 }
542 ); 542 );
543 modalInstance.result.then( 543 modalInstance.result.then(
544 function(cliente) { 544 function(cliente) {
545 $scope.abrirModalDomicilios(cliente); 545 $scope.abrirModalDomicilios(cliente);
546 $scope.cliente = cliente; 546 $scope.cliente = cliente;
547 }, function() { 547 }, function() {
548 548
549 } 549 }
550 ); 550 );
551 } 551 }
552 }; 552 };
553 553
554 $scope.abrirModalDomicilios = function(cliente) { 554 $scope.abrirModalDomicilios = function(cliente) {
555 var modalInstanceDomicilio = $uibModal.open( 555 var modalInstanceDomicilio = $uibModal.open(
556 { 556 {
557 ariaLabelledBy: 'Busqueda de Domicilios', 557 ariaLabelledBy: 'Busqueda de Domicilios',
558 templateUrl: 'modal-domicilio.html', 558 templateUrl: 'modal-domicilio.html',
559 controller: 'focaModalDomicilioController', 559 controller: 'focaModalDomicilioController',
560 size: 'lg', 560 size: 'lg',
561 resolve: { 561 resolve: {
562 idCliente: function() { return cliente.cod; }, 562 idCliente: function() { return cliente.cod; },
563 esNuevo: function() { return cliente.esNuevo; } 563 esNuevo: function() { return cliente.esNuevo; }
564 } 564 }
565 } 565 }
566 ); 566 );
567 modalInstanceDomicilio.result.then( 567 modalInstanceDomicilio.result.then(
568 function(domicilio) { 568 function(domicilio) {
569 $scope.remito.domicilio = domicilio; 569 $scope.remito.domicilio = domicilio;
570 $scope.remito.cliente = { 570 $scope.remito.cliente = {
571 COD: cliente.cod, 571 COD: cliente.cod,
572 CUIT: cliente.cuit, 572 CUIT: cliente.cuit,
573 NOM: cliente.nom, 573 NOM: cliente.nom,
574 MAIL: cliente.mail 574 MAIL: cliente.mail
575 }; 575 };
576 576
577 577
578 var domicilioStamp = 578 var domicilioStamp =
579 domicilio.Calle + ' ' + domicilio.Numero + ', ' + 579 domicilio.Calle + ' ' + domicilio.Numero + ', ' +
580 domicilio.Localidad + ', ' + domicilio.Provincia; 580 domicilio.Localidad + ', ' + domicilio.Provincia;
581 $scope.remito.domicilioStamp = domicilioStamp; 581 $scope.remito.domicilioStamp = domicilioStamp;
582 582
583 $scope.$broadcast('addCabecera',{ 583 $scope.$broadcast('addCabecera',{
584 label: 'Cliente:', 584 label: 'Cliente:',
585 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom 585 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + cliente.nom
586 }); 586 });
587 $scope.$broadcast('addCabecera',{ 587 $scope.$broadcast('addCabecera',{
588 label: 'Domicilio:', 588 label: 'Domicilio:',
589 valor: domicilioStamp 589 valor: domicilioStamp
590 }); 590 });
591 591
592 if(domicilio.verPuntos) { 592 if(domicilio.verPuntos) {
593 delete $scope.remito.domicilio.verPuntos; 593 delete $scope.remito.domicilio.verPuntos;
594 $scope.seleccionarPuntosDeDescarga(); 594 $scope.seleccionarPuntosDeDescarga();
595 }else { 595 }else {
596 crearRemitoService 596 crearRemitoService
597 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod) 597 .getPuntosDescargaByClienDom(domicilio.id, cliente.cod)
598 .then(function(res) { 598 .then(function(res) {
599 if(res.data.length) $scope.seleccionarPuntosDeDescarga(); 599 if(res.data.length) $scope.seleccionarPuntosDeDescarga();
600 }); 600 });
601 } 601 }
602 }, function() { 602 }, function() {
603 $scope.seleccionarCliente(); 603 $scope.seleccionarCliente();
604 return; 604 return;
605 } 605 }
606 ); 606 );
607 }; 607 };
608 608
609 $scope.mostrarFichaCliente = function() { 609 $scope.mostrarFichaCliente = function() {
610 $uibModal.open( 610 $uibModal.open(
611 { 611 {
612 ariaLabelledBy: 'Datos del Cliente', 612 ariaLabelledBy: 'Datos del Cliente',
613 templateUrl: 'foca-crear-remito-ficha-cliente.html', 613 templateUrl: 'foca-crear-remito-ficha-cliente.html',
614 controller: 'focaCrearRemitoFichaClienteController', 614 controller: 'focaCrearRemitoFichaClienteController',
615 size: 'lg' 615 size: 'lg'
616 } 616 }
617 ); 617 );
618 }; 618 };
619 619
620 $scope.getTotal = function() { 620 $scope.getTotal = function() {
621 var total = 0; 621 var total = 0;
622 var arrayTempArticulos = $scope.remito.articulosRemito; 622 var arrayTempArticulos = $scope.remito.articulosRemito;
623 for(var i = 0; i < arrayTempArticulos.length; i++) { 623 for(var i = 0; i < arrayTempArticulos.length; i++) {
624 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad; 624 total += arrayTempArticulos[i].precio * arrayTempArticulos[i].cantidad;
625 } 625 }
626 return parseFloat(total.toFixed(2)); 626 return parseFloat(total.toFixed(2));
627 }; 627 };
628 628
629 $scope.getSubTotal = function() { 629 $scope.getSubTotal = function() {
630 if($scope.articuloACargar) { 630 if($scope.articuloACargar) {
631 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad; 631 return $scope.articuloACargar.precio * $scope.articuloACargar.cantidad;
632 } 632 }
633 }; 633 };
634 634
635 $scope.seleccionarPreciosYCondiciones = function() { 635 $scope.seleccionarPreciosYCondiciones = function() {
636 if(varlidarRemitoFacturado()) { 636 if(varlidarRemitoFacturado()) {
637 var modalInstance = $uibModal.open( 637 var modalInstance = $uibModal.open(
638 { 638 {
639 ariaLabelledBy: 'Busqueda de Precio Condición', 639 ariaLabelledBy: 'Busqueda de Precio Condición',
640 templateUrl: 'modal-precio-condicion.html', 640 templateUrl: 'modal-precio-condicion.html',
641 controller: 'focaModalPrecioCondicionController', 641 controller: 'focaModalPrecioCondicionController',
642 size: 'lg' 642 size: 'lg'
643 } 643 }
644 ); 644 );
645 modalInstance.result.then( 645 modalInstance.result.then(
646 function(precioCondicion) { 646 function(precioCondicion) {
647 var cabecera = ''; 647 var cabecera = '';
648 var plazosConcat = ''; 648 var plazosConcat = '';
649 if(!Array.isArray(precioCondicion)) { 649 if(!Array.isArray(precioCondicion)) {
650 $scope.remito.idPrecioCondicion = precioCondicion.id; 650 $scope.remito.idPrecioCondicion = precioCondicion.id;
651 $scope.remito.remitoPlazo = precioCondicion.plazoPago; 651 $scope.remito.remitoPlazo = precioCondicion.plazoPago;
652 $scope.idLista = precioCondicion.idListaPrecio; 652 $scope.idLista = precioCondicion.idListaPrecio;
653 for(var i = 0; i < precioCondicion.plazoPago.length; i++) { 653 for(var i = 0; i < precioCondicion.plazoPago.length; i++) {
654 plazosConcat += precioCondicion.plazoPago[i].dias + ' '; 654 plazosConcat += precioCondicion.plazoPago[i].dias + ' ';
655 } 655 }
656 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) + 656 cabecera = $filter('rellenarDigitos')(precioCondicion.id, 4) +
657 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim(); 657 ' - ' + precioCondicion.nombre + ' ' + plazosConcat.trim();
658 }else { //Cuando se ingresan los plazos manualmente 658 }else { //Cuando se ingresan los plazos manualmente
659 $scope.remito.idPrecioCondicion = 0; 659 $scope.remito.idPrecioCondicion = 0;
660 //-1, el modal productos busca todos los productos 660 //-1, el modal productos busca todos los productos
661 $scope.idLista = -1; 661 $scope.idLista = -1;
662 $scope.remito.remitoPlazo = precioCondicion; 662 $scope.remito.remitoPlazo = precioCondicion;
663 for(var j = 0; j < precioCondicion.length; j++) { 663 for(var j = 0; j < precioCondicion.length; j++) {
664 plazosConcat += precioCondicion[j].dias + ' '; 664 plazosConcat += precioCondicion[j].dias + ' ';
665 } 665 }
666 cabecera = 'Ingreso manual ' + plazosConcat.trim(); 666 cabecera = 'Ingreso manual ' + plazosConcat.trim();
667 } 667 }
668 $scope.remito.articulosRemito = []; 668 $scope.remito.articulosRemito = [];
669 $scope.$broadcast('addCabecera',{ 669 $scope.$broadcast('addCabecera',{
670 label: 'Precios y condiciones:', 670 label: 'Precios y condiciones:',
671 valor: cabecera 671 valor: cabecera
672 }); 672 });
673 673
674 $scope.remito.precioCondicion = precioCondicion; 674 $scope.remito.precioCondicion = precioCondicion;
675 }, function() { 675 }, function() {
676 676
677 } 677 }
678 ); 678 );
679 } 679 }
680 }; 680 };
681 681
682 $scope.seleccionarFlete = function() { 682 $scope.seleccionarFlete = function() {
683 if(varlidarRemitoFacturado()) { 683 if(varlidarRemitoFacturado()) {
684 var modalInstance = $uibModal.open( 684 var modalInstance = $uibModal.open(
685 { 685 {
686 ariaLabelledBy: 'Busqueda de Flete', 686 ariaLabelledBy: 'Busqueda de Flete',
687 templateUrl: 'modal-flete.html', 687 templateUrl: 'modal-flete.html',
688 controller: 'focaModalFleteController', 688 controller: 'focaModalFleteController',
689 size: 'lg', 689 size: 'lg',
690 resolve: { 690 resolve: {
691 parametrosFlete: 691 parametrosFlete:
692 function() { 692 function() {
693 return { 693 return {
694 flete: $scope.remito.flete ? '1' : 694 flete: $scope.remito.flete ? '1' :
695 ($scope.remito.fob ? 'FOB' : 695 ($scope.remito.fob ? 'FOB' :
696 ($scope.remito.flete === undefined ? null : '0')), 696 ($scope.remito.flete === undefined ? null : '0')),
697 bomba: $scope.remito.bomba ? '1' : 697 bomba: $scope.remito.bomba ? '1' :
698 ($scope.remito.bomba === undefined ? null : '0'), 698 ($scope.remito.bomba === undefined ? null : '0'),
699 kilometros: $scope.remito.kilometros 699 kilometros: $scope.remito.kilometros
700 }; 700 };
701 } 701 }
702 } 702 }
703 } 703 }
704 ); 704 );
705 modalInstance.result.then( 705 modalInstance.result.then(
706 function(datos) { 706 function(datos) {
707 $scope.remito.flete = datos.flete; 707 $scope.remito.flete = datos.flete;
708 $scope.remito.fob = datos.FOB; 708 $scope.remito.fob = datos.FOB;
709 $scope.remito.bomba = datos.bomba; 709 $scope.remito.bomba = datos.bomba;
710 $scope.remito.kilometros = datos.kilometros; 710 $scope.remito.kilometros = datos.kilometros;
711 711
712 $scope.$broadcast('addCabecera',{ 712 $scope.$broadcast('addCabecera',{
713 label: 'Flete:', 713 label: 'Flete:',
714 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No') 714 valor: datos.flete ? 'Si' : ($scope.remito.fob ? 'FOB' : 'No')
715 }); 715 });
716 if(datos.flete) { 716 if(datos.flete) {
717 $scope.$broadcast('addCabecera',{ 717 $scope.$broadcast('addCabecera',{
718 label: 'Bomba:', 718 label: 'Bomba:',
719 valor: datos.bomba ? 'Si' : 'No' 719 valor: datos.bomba ? 'Si' : 'No'
720 }); 720 });
721 $scope.$broadcast('addCabecera',{ 721 $scope.$broadcast('addCabecera',{
722 label: 'Kilometros:', 722 label: 'Kilometros:',
723 valor: datos.kilometros 723 valor: datos.kilometros
724 }); 724 });
725 }else { 725 }else {
726 $scope.$broadcast('removeCabecera', 'Bomba:'); 726 $scope.$broadcast('removeCabecera', 'Bomba:');
727 $scope.$broadcast('removeCabecera', 'Kilometros:'); 727 $scope.$broadcast('removeCabecera', 'Kilometros:');
728 $scope.remito.fob = false; 728 $scope.remito.fob = false;
729 $scope.remito.bomba = false; 729 $scope.remito.bomba = false;
730 $scope.remito.kilometros = null; 730 $scope.remito.kilometros = null;
731 } 731 }
732 }, function() { 732 }, function() {
733 733
734 } 734 }
735 ); 735 );
736 } 736 }
737 }; 737 };
738 738
739 $scope.seleccionarMoneda = function() { 739 $scope.seleccionarMoneda = function() {
740 if(varlidarRemitoFacturado()) { 740 if(varlidarRemitoFacturado()) {
741 var parametrosModal = { 741 var parametrosModal = {
742 titulo: 'Búsqueda de monedas', 742 titulo: 'Búsqueda de monedas',
743 query: '/moneda', 743 query: '/moneda',
744 columnas: [ 744 columnas: [
745 { 745 {
746 propiedad: 'DETALLE', 746 propiedad: 'DETALLE',
747 nombre: 'Nombre' 747 nombre: 'Nombre'
748 }, 748 },
749 { 749 {
750 propiedad: 'SIMBOLO', 750 propiedad: 'SIMBOLO',
751 nombre: 'Símbolo' 751 nombre: 'Símbolo'
752 } 752 }
753 ], 753 ],
754 size: 'md' 754 size: 'md'
755 }; 755 };
756 focaModalService.modal(parametrosModal).then( 756 focaModalService.modal(parametrosModal).then(
757 function(moneda) { 757 function(moneda) {
758 $scope.abrirModalCotizacion(moneda); 758 $scope.abrirModalCotizacion(moneda);
759 }, function() { 759 }, function() {
760 760
761 } 761 }
762 ); 762 );
763 } 763 }
764 }; 764 };
765 765
766 $scope.seleccionarObservaciones = function() { 766 $scope.seleccionarObservaciones = function() {
767 focaModalService 767 focaModalService
768 .prompt('Observaciones', $scope.remito.observaciones, true, true) 768 .prompt({
769 titulo: 'Observaciones',
770 value: $scope.remito.observaciones,
771 textarea: true,
772 readonly: true
773 })
769 .then(function(observaciones) { 774 .then(function(observaciones) {
770 $scope.remito.observaciones = observaciones; 775 $scope.remito.observaciones = observaciones;
771 }); 776 });
772 }; 777 };
773 778
774 $scope.abrirModalCotizacion = function(moneda) { 779 $scope.abrirModalCotizacion = function(moneda) {
775 var modalInstance = $uibModal.open( 780 var modalInstance = $uibModal.open(
776 { 781 {
777 ariaLabelledBy: 'Busqueda de Cotización', 782 ariaLabelledBy: 'Busqueda de Cotización',
778 templateUrl: 'modal-cotizacion.html', 783 templateUrl: 'modal-cotizacion.html',
779 controller: 'focaModalCotizacionController', 784 controller: 'focaModalCotizacionController',
780 size: 'lg', 785 size: 'lg',
781 resolve: {idMoneda: function() {return moneda.ID;}} 786 resolve: {idMoneda: function() {return moneda.ID;}}
782 } 787 }
783 ); 788 );
784 modalInstance.result.then( 789 modalInstance.result.then(
785 function(cotizacion) { 790 function(cotizacion) {
786 var articulosTablaTemp = $scope.remito.articulosRemito; 791 var articulosTablaTemp = $scope.remito.articulosRemito;
787 for(var i = 0; i < articulosTablaTemp.length; i++) { 792 for(var i = 0; i < articulosTablaTemp.length; i++) {
788 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio * 793 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
789 $scope.remito.cotizacion.COTIZACION; 794 $scope.remito.cotizacion.COTIZACION;
790 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio / 795 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
791 cotizacion.COTIZACION; 796 cotizacion.COTIZACION;
792 } 797 }
793 $scope.remito.articulosRemito = articulosTablaTemp; 798 $scope.remito.articulosRemito = articulosTablaTemp;
794 $scope.remito.cotizacion.moneda = moneda; 799 $scope.remito.cotizacion.moneda = moneda;
795 $scope.remito.cotizacion = cotizacion; 800 $scope.remito.cotizacion = cotizacion;
796 if(moneda.DETALLE === 'PESOS ARGENTINOS') { 801 if(moneda.DETALLE === 'PESOS ARGENTINOS') {
797 $scope.$broadcast('removeCabecera', 'Moneda:'); 802 $scope.$broadcast('removeCabecera', 'Moneda:');
798 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 803 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
799 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 804 $scope.$broadcast('removeCabecera', 'Cotizacion:');
800 }else { 805 }else {
801 $scope.$broadcast('addCabecera',{ 806 $scope.$broadcast('addCabecera',{
802 label: 'Moneda:', 807 label: 'Moneda:',
803 valor: moneda.DETALLE 808 valor: moneda.DETALLE
804 }); 809 });
805 $scope.$broadcast('addCabecera',{ 810 $scope.$broadcast('addCabecera',{
806 label: 'Fecha cotizacion:', 811 label: 'Fecha cotizacion:',
807 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy') 812 valor: $filter('date')(cotizacion.FECHA, 'dd/MM/yyyy')
808 }); 813 });
809 $scope.$broadcast('addCabecera',{ 814 $scope.$broadcast('addCabecera',{
810 label: 'Cotizacion:', 815 label: 'Cotizacion:',
811 valor: $filter('number')(cotizacion.COTIZACION, '2') 816 valor: $filter('number')(cotizacion.COTIZACION, '2')
812 }); 817 });
813 } 818 }
814 }, function() { 819 }, function() {
815 820
816 } 821 }
817 ); 822 );
818 }; 823 };
819 824
820 $scope.agregarATabla = function(key) { 825 $scope.agregarATabla = function(key) {
821 if(key === 13) { 826 if(key === 13) {
822 if($scope.articuloACargar.cantidad === undefined || 827 if($scope.articuloACargar.cantidad === undefined ||
823 $scope.articuloACargar.cantidad === 0 || 828 $scope.articuloACargar.cantidad === 0 ||
824 $scope.articuloACargar.cantidad === null ) { 829 $scope.articuloACargar.cantidad === null ) {
825 focaModalService.alert('El valor debe ser al menos 1'); 830 focaModalService.alert('El valor debe ser al menos 1');
826 return; 831 return;
827 } 832 }
828 delete $scope.articuloACargar.sectorCodigo; 833 delete $scope.articuloACargar.sectorCodigo;
829 $scope.remito.articulosRemito.push($scope.articuloACargar); 834 $scope.remito.articulosRemito.push($scope.articuloACargar);
830 $scope.cargando = true; 835 $scope.cargando = true;
831 } 836 }
832 }; 837 };
833 838
834 $scope.quitarArticulo = function(key) { 839 $scope.quitarArticulo = function(key) {
835 $scope.remito.articulosRemito.splice(key, 1); 840 $scope.remito.articulosRemito.splice(key, 1);
836 }; 841 };
837 842
838 $scope.editarArticulo = function(key, articulo) { 843 $scope.editarArticulo = function(key, articulo) {
839 if(key === 13) { 844 if(key === 13) {
840 if(articulo.cantidad === null || articulo.cantidad === 0 || 845 if(articulo.cantidad === null || articulo.cantidad === 0 ||
841 articulo.cantidad === undefined) { 846 articulo.cantidad === undefined) {
842 focaModalService.alert('El valor debe ser al menos 1'); 847 focaModalService.alert('El valor debe ser al menos 1');
843 return; 848 return;
844 } 849 }
845 articulo.editCantidad = false; 850 articulo.editCantidad = false;
846 articulo.editPrecio = false; 851 articulo.editPrecio = false;
847 } 852 }
848 }; 853 };
849 854
850 $scope.cambioEdit = function(articulo, propiedad) { 855 $scope.cambioEdit = function(articulo, propiedad) {
851 if(propiedad === 'cantidad') { 856 if(propiedad === 'cantidad') {
852 articulo.editCantidad = true; 857 articulo.editCantidad = true;
853 }else if(propiedad === 'precio') { 858 }else if(propiedad === 'precio') {
854 articulo.editPrecio = true; 859 articulo.editPrecio = true;
855 } 860 }
856 }; 861 };
857 862
858 $scope.limpiarFlete = function() { 863 $scope.limpiarFlete = function() {
859 $scope.remito.fleteNombre = ''; 864 $scope.remito.fleteNombre = '';
860 $scope.remito.chofer = ''; 865 $scope.remito.chofer = '';
861 $scope.remito.vehiculo = ''; 866 $scope.remito.vehiculo = '';
862 $scope.remito.kilometros = ''; 867 $scope.remito.kilometros = '';
863 $scope.remito.costoUnitarioKmFlete = ''; 868 $scope.remito.costoUnitarioKmFlete = '';
864 $scope.choferes = ''; 869 $scope.choferes = '';
865 $scope.vehiculos = ''; 870 $scope.vehiculos = '';
866 }; 871 };
867 872
868 $scope.limpiarPantalla = function() { 873 $scope.limpiarPantalla = function() {
869 $scope.limpiarFlete(); 874 $scope.limpiarFlete();
870 $scope.remito.flete = '0'; 875 $scope.remito.flete = '0';
871 $scope.remito.bomba = '0'; 876 $scope.remito.bomba = '0';
872 $scope.remito.precioCondicion = ''; 877 $scope.remito.precioCondicion = '';
873 $scope.remito.articulosRemito = []; 878 $scope.remito.articulosRemito = [];
874 $scope.remito.vendedor.nombre = ''; 879 $scope.remito.vendedor.nombre = '';
875 $scope.remito.cliente = {nombre: ''}; 880 $scope.remito.cliente = {nombre: ''};
876 $scope.remito.domicilio = {dom: ''}; 881 $scope.remito.domicilio = {dom: ''};
877 $scope.domiciliosCliente = []; 882 $scope.domiciliosCliente = [];
878 }; 883 };
879 884
880 $scope.resetFilter = function() { 885 $scope.resetFilter = function() {
881 $scope.articuloACargar = {}; 886 $scope.articuloACargar = {};
882 $scope.cargando = true; 887 $scope.cargando = true;
883 }; 888 };
884 //Recibe aviso si el teclado está en uso 889 //Recibe aviso si el teclado está en uso
885 $rootScope.$on('usarTeclado', function(event, data) { 890 $rootScope.$on('usarTeclado', function(event, data) {
886 if(data) { 891 if(data) {
887 $scope.mostrarTeclado = true; 892 $scope.mostrarTeclado = true;
888 return; 893 return;
889 } 894 }
890 $scope.mostrarTeclado = false; 895 $scope.mostrarTeclado = false;
891 }); 896 });
892 897
893 $scope.selectFocus = function($event) { 898 $scope.selectFocus = function($event) {
894 // Si el teclado esta en uso no selecciona el valor 899 // Si el teclado esta en uso no selecciona el valor
895 if($scope.mostrarTeclado) { 900 if($scope.mostrarTeclado) {
896 return; 901 return;
897 } 902 }
898 $event.target.select(); 903 $event.target.select();
899 }; 904 };
900 905
901 function addArrayCabecera(array) { 906 function addArrayCabecera(array) {
902 for(var i = 0; i < array.length; i++) { 907 for(var i = 0; i < array.length; i++) {
903 $scope.$broadcast('addCabecera',{ 908 $scope.$broadcast('addCabecera',{
904 label: array[i].label, 909 label: array[i].label,
905 valor: array[i].valor 910 valor: array[i].valor
906 }); 911 });
907 } 912 }
908 } 913 }
909 914
910 function rellenar(relleno, longitud) { 915 function rellenar(relleno, longitud) {
911 relleno = '' + relleno; 916 relleno = '' + relleno;
912 while (relleno.length < longitud) { 917 while (relleno.length < longitud) {
913 relleno = '0' + relleno; 918 relleno = '0' + relleno;
914 } 919 }
915 920
916 return relleno; 921 return relleno;
917 } 922 }
918 923
919 function varlidarRemitoFacturado() { 924 function varlidarRemitoFacturado() {
920 if($scope.remito.estado !== 5) { 925 if($scope.remito.estado !== 5) {
921 return true; 926 return true;
922 }else { 927 }else {
923 focaModalService.alert('No se puede editar un remito facturado'); 928 focaModalService.alert('No se puede editar un remito facturado');
924 return false(); 929 return false();
925 } 930 }
926 } 931 }
927 932
928 function salir() { 933 function salir() {
929 var confirmacion = false; 934 var confirmacion = false;
930 935
931 if (!angular.equals($scope.remito, $scope.inicial)) { 936 if (!angular.equals($scope.remito, $scope.inicial)) {
932 confirmacion = true; 937 confirmacion = true;
933 } 938 }
934 939
935 if (confirmacion) { 940 if (confirmacion) {
936 focaModalService.confirm( 941 focaModalService.confirm(
937 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 942 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
938 ).then(function(data) { 943 ).then(function(data) {
939 if (data) { 944 if (data) {
940 $location.path('/'); 945 $location.path('/');
941 } 946 }
942 }); 947 });
943 } else { 948 } else {
944 $location.path('/'); 949 $location.path('/');
945 } 950 }
946 } 951 }
947 952
948 function enableObservaciones(val) { 953 function enableObservaciones(val) {
949 var boton = $scope.botonera.filter(function(botonObs) { 954 var boton = $scope.botonera.filter(function(botonObs) {
950 return botonObs.label === 'Observaciones'; 955 return botonObs.label === 'Observaciones';
951 }); 956 });
952 957
953 boton[0].disable = !val; 958 boton[0].disable = !val;
954 } 959 }
955 960
956 function setearRemito(remito) { 961 function setearRemito(remito) {
957 //añado cabeceras 962 //añado cabeceras
958 $scope.$broadcast('removeCabecera', 'Moneda:'); 963 $scope.$broadcast('removeCabecera', 'Moneda:');
959 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:'); 964 $scope.$broadcast('removeCabecera', 'Fecha cotizacion:');
960 $scope.$broadcast('removeCabecera', 'Cotizacion:'); 965 $scope.$broadcast('removeCabecera', 'Cotizacion:');
961 966
962 var cabeceras = []; 967 var cabeceras = [];
963 968
964 if (remito.cotizacion.ID) { 969 if (remito.cotizacion.ID) {
965 cabeceras.push({ 970 cabeceras.push({
966 label: 'Moneda:', 971 label: 'Moneda:',
967 valor: remito.cotizacion.moneda.DETALLE 972 valor: remito.cotizacion.moneda.DETALLE
968 }); 973 });
969 cabeceras.push({ 974 cabeceras.push({
970 label: 'Fecha cotizacion:', 975 label: 'Fecha cotizacion:',
971 valor: $filter('date')(remito.cotizacion.FECHA, 976 valor: $filter('date')(remito.cotizacion.FECHA,
972 'dd/MM/yyyy') 977 'dd/MM/yyyy')
973 }); 978 });
974 cabeceras.push({ 979 cabeceras.push({
975 label: 'Cotizacion:', 980 label: 'Cotizacion:',
976 valor: $filter('number')(remito.cotizacion.VENDEDOR, 981 valor: $filter('number')(remito.cotizacion.VENDEDOR,
977 '2') 982 '2')
978 }); 983 });
979 } 984 }
980 if (remito.cliente.COD) { 985 if (remito.cliente.COD) {
981 cabeceras.push({ 986 cabeceras.push({
982 label: 'Cliente:', 987 label: 'Cliente:',
983 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' + 988 valor: $filter('rellenarDigitos')(remito.cliente.COD, 3) + ' - ' +
984 remito.cliente.NOM 989 remito.cliente.NOM
985 }); 990 });
986 cabeceras.push({ 991 cabeceras.push({
987 label: 'Domicilio:', 992 label: 'Domicilio:',
988 valor: remito.domicilioStamp 993 valor: remito.domicilioStamp
989 }); 994 });
990 } 995 }
991 if (remito.vendedor.NUM) { 996 if (remito.vendedor.NUM) {
992 cabeceras.push({ 997 cabeceras.push({
993 label: 'Vendedor:', 998 label: 'Vendedor:',
994 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) + 999 valor: $filter('rellenarDigitos')(remito.vendedor.NUM, 3) +
995 ' - ' + remito.vendedor.NOM 1000 ' - ' + remito.vendedor.NOM
996 }); 1001 });
997 } 1002 }
998 if (remito.proveedor.COD) { 1003 if (remito.proveedor.COD) {
999 cabeceras.push({ 1004 cabeceras.push({
1000 label: 'Proveedor:', 1005 label: 'Proveedor:',
1001 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) + 1006 valor: $filter('rellenarDigitos')(remito.proveedor.COD, 5) +
1002 ' - ' + remito.proveedor.NOM 1007 ' - ' + remito.proveedor.NOM
1003 }); 1008 });
1004 } 1009 }
1005 if (remito.flete !== undefined) { 1010 if (remito.flete !== undefined) {
1006 cabeceras.push({ 1011 cabeceras.push({
1007 label: 'Flete:', 1012 label: 'Flete:',
1008 valor: remito.fob === 1 ? 'FOB' : ( 1013 valor: remito.fob === 1 ? 'FOB' : (
1009 remito.flete === 1 ? 'Si' : 'No') 1014 remito.flete === 1 ? 'Si' : 'No')
1010 }); 1015 });
1011 } 1016 }
1012 if (remito.remitoPlazo) { 1017 if (remito.remitoPlazo) {
1013 cabeceras.push({ 1018 cabeceras.push({
1014 label: 'Precio condicion:', 1019 label: 'Precio condicion:',
1015 valor: valorPrecioCondicion() + ' ' + 1020 valor: valorPrecioCondicion() + ' ' +
1016 remitoBusinessService.plazoToString(remito.remitoPlazo) 1021 remitoBusinessService.plazoToString(remito.remitoPlazo)
1017 }); 1022 });
1018 } 1023 }
1019 1024
1020 function valorPrecioCondicion() { 1025 function valorPrecioCondicion() {
1021 if (remito.idPrecioCondicion > 0) { 1026 if (remito.idPrecioCondicion > 0) {
1022 return remito.precioCondicion.nombre; 1027 return remito.precioCondicion.nombre;
1023 } else { 1028 } else {
1024 return 'Ingreso Manual'; 1029 return 'Ingreso Manual';
1025 } 1030 }
1026 } 1031 }
1027 1032
1028 if (remito.flete === 1) { 1033 if (remito.flete === 1) {
1029 var cabeceraBomba = { 1034 var cabeceraBomba = {
1030 label: 'Bomba', 1035 label: 'Bomba',
1031 valor: remito.bomba === 1 ? 'Si' : 'No' 1036 valor: remito.bomba === 1 ? 'Si' : 'No'
1032 }; 1037 };
1033 if (remito.kilometros) { 1038 if (remito.kilometros) {
1034 var cabeceraKilometros = { 1039 var cabeceraKilometros = {
1035 label: 'Kilometros', 1040 label: 'Kilometros',
1036 valor: remito.kilometros 1041 valor: remito.kilometros
1037 }; 1042 };
1038 cabeceras.push(cabeceraKilometros); 1043 cabeceras.push(cabeceraKilometros);
1039 } 1044 }
1040 cabeceras.push(cabeceraBomba); 1045 cabeceras.push(cabeceraBomba);
1041 } 1046 }
1042 $scope.remito.articulosRemito = remito.articulosRemito; 1047 $scope.remito.articulosRemito = remito.articulosRemito;
1043 remitoBusinessService.calcularArticulos($scope.remito.articulosRemito, 1048 remitoBusinessService.calcularArticulos($scope.remito.articulosRemito,
1044 remito.cotizacion.VENDEDOR); 1049 remito.cotizacion.VENDEDOR);
1045 if (remito.idPrecioCondicion > 0) { 1050 if (remito.idPrecioCondicion > 0) {
1046 $scope.idLista = remito.precioCondicion.idListaPrecio; 1051 $scope.idLista = remito.precioCondicion.idListaPrecio;
1047 } else { 1052 } else {
1048 $scope.idLista = -1; 1053 $scope.idLista = -1;
1049 } 1054 }
1050 $scope.puntoVenta = rellenar(remito.sucursal, 4); 1055 $scope.puntoVenta = rellenar(remito.sucursal, 4);
1051 $scope.comprobante = rellenar(remito.numeroRemito, 8); 1056 $scope.comprobante = rellenar(remito.numeroRemito, 8);
1052 $scope.remito = remito; 1057 $scope.remito = remito;
1053 addArrayCabecera(cabeceras); 1058 addArrayCabecera(cabeceras);
1054 } 1059 }
1055 1060
1056 function getLSRemito() { 1061 function getLSRemito() {
1057 var remito = JSON.parse($localStorage.remito || null); 1062 var remito = JSON.parse($localStorage.remito || null);
1058 if (remito) { 1063 if (remito) {
1059 console.log('remito', remito);
1060 setearRemito(remito); 1064 setearRemito(remito);
1061 delete $localStorage.remito; 1065 delete $localStorage.remito;
1062 } 1066 }
1063 } 1067 }
1064 } 1068 }
1065 ]); 1069 ]);