Commit ba93008bf5c0bf08857ce84ba6243e5fb3bb5515

Authored by Eric Fernandez
1 parent e919068324
Exists in master

resolve como funcion

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