Commit c266c16b6ad60da9e721caef0654b6050fbd2c7a

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

quito modal proveedor

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