Commit 26fae65a55810e6ea8a3b1f2c5a2811bcf1af958

Authored by Eric Fernandez
1 parent 3d1721f582
Exists in master

linea innecesaria

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