Commit 018abb2254b968233dc253c51af22dc17e8d187f

Authored by Nicolás Guarnieri
Exists in master

Merge branch 'master' into 'master'

agrego resolve para modal de remito

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