Commit 8d995460306534cb613241eb73df4c6a0ef366b8

Authored by Nicolás Guarnieri
Exists in master and in 2 other branches develop, lab

Merge branch 'master' into 'master'

Master

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