Commit 73063b851f790b0d7047d5173ce23c90944512d4

Authored by Pablo Marco del Pont
Exists in master

Merge branch 'master' into 'master'

Master

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