Commit 77c44c008b5c6054c460a785548bc4badd29b473

Authored by Eric Fernandez
1 parent 26316adfa7
Exists in master

guarda bien los datos

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