Commit 6add83e49cc223fdec13719ed6195f4c39e9ed71

Authored by Jose Pinto
1 parent 68cc05f26b
Exists in master

ok modal vendedor

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