Commit a64c4d9fcacfbf82091f83ec6608b40ed1cef930

Authored by Pablo Marco del Pont
Exists in master

Merge branch 'master' into 'master'

agrego resolve de modal nota pedido

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