Commit 1ec4e9a4af5e8f921c09083878aad840b02e6371

Authored by Jose Pinto
1 parent 71d49b9116
Exists in master

precios y condiciones relacion con cliente

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