Commit f1107299d84fc63b090ecf0e186f51822e5b9c86

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'master'

Master

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