Commit 2c9f5ae3693362f9c06b6439fbcf98bc992137df

Authored by Nicolás Guarnieri
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master(efernandez)

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