Exemple #1
0
 public Get_ID()
 {
     usuarios = new UsuariosModel();
     sucursal = new SucursalModel();
     corte    = new CorteModel();
     local    = new Repository_Local();
 }
 // Borrar Corte
 public void CorteModel(CorteModel corte)
 {
     try
     {
         BD_local.Delete(corte);
     }
     catch (Exception ex)
     {
         StatusMessage = $"Error al insertar{ex.Message}";
     }
 }
        // Ingresar Sucursal En BD Local

        public void CreateCorte(CorteModel newCorte)
        {
            try
            {
                BD_local.Insert(newCorte);
                StatusMessage = $"Registro Ingresado exitosamente ID:{newCorte.id_corte}";
            }
            catch (Exception ex)
            {
                StatusMessage = $"Error al insertar{ex.Message}";
            }
        }
        //Obtener Numero De Corte
        public async Task <IEnumerable <CorteModel> > numero_corte(CorteModel id_sucursal)
        {
            HttpClient cliente   = getCliente();
            string     json      = JsonConvert.SerializeObject(id_sucursal);
            var        contenido = new StringContent(json, Encoding.UTF8, "application/json");
            var        resultado = await cliente.PostAsync($"{URL}/Corte/get_ncorte", contenido);

            if (resultado.IsSuccessStatusCode)
            {
                string log = await resultado.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <IEnumerable <CorteModel> >(log));
            }
            else
            {
                return(Enumerable.Empty <CorteModel>());
            }
        }
        // Cerrar Session
        public async Task <dynamic> Finalizar_Corte(CorteModel fincorte)
        {
            HttpClient client = getCliente();
            string     json   = JsonConvert.SerializeObject(fincorte);

            try
            {
                var contenido = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage respuesta = await client.PostAsync($"{URL}/Corte/Finalizar_corte", contenido);
            }
            catch (HttpRequestException ex)
            {
                await App.Current.MainPage.DisplayAlert("ERROR", $"{ex.Message}", "OK");

                System.Diagnostics.Debug.WriteLine(ex);
            }
            return("");
        }
        // Ingresar Corte Al Sistema
        public async void Iniciar_Corte()
        {
            CorteModel datos   = new CorteModel();
            Get_ID     ids     = new Get_ID();
            Get_NCorte num     = new Get_NCorte();
            int        n_corte = await num.get_ncorte();

            int    id_usuario  = ids.get_usuario();
            int    id_sucursal = ids.get_sucursal();
            string nombre      = ids.get_nombreusuario();
            //await App.Current.MainPage.DisplayAlert("Corte","ID Usuario: " + id_usuario.ToString()+ "\n"+ "ID Sucursal: " + id_sucursal.ToString() + "\n" + "Nombre: " + nombre , "OK");
            var corte_save = await bdapi.Iniciar_Corte(new CorteModel {
                usuario          = id_usuario,
                sucursal         = id_sucursal,
                efectivo_final   = 0.00,
                efectivo_inicial = 0.00,
                // Estado 1 Para indicar que se inicio
                estado = 1,
                turno  = n_corte + 1
            });

            corte = new ObservableCollection <CorteModel>(corte_save);
            foreach (CorteModel info in corte)
            {
                datos.id_corte         = info.id_corte;
                datos.fecha_hora       = info.fecha_hora;
                datos.efectivo_final   = info.efectivo_final;
                datos.efectivo_inicial = info.efectivo_inicial;
                datos.estado           = info.estado;
                datos.sucursal         = info.sucursal;
                datos.usuario          = info.usuario;
                datos.turno            = info.turno;
            }
            bdlocal.CreateCorte(datos);
            //int num_corte = await num.get_ncorte();
            //await App.Current.MainPage.DisplayAlert("Corte","Numero De Turno: " + num_corte, "OK");
        }