Commit 0d3a25224f4d7e27e61e7da0f58a57a47b6380e2

Authored by Eric Fernandez
1 parent 44ab0493f0
Exists in master

numero comprobante correcto

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