Skip to content
Merged
16 changes: 14 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application

android:usesCleartextTraffic="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -25,7 +30,14 @@
android:roundIcon="@mipmap/icone_app_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
tools:targetApi="31">
tools:targetApi="31"
>
<activity
android:name=".ui.AtualizarNome"
android:exported="false" />
<!-- <activity-->
<!-- android:name=".ui.Chatbot"-->
<!-- android:exported="false" />-->
<activity
android:name=".ui.Conversa"
android:exported="false" />
Expand Down Expand Up @@ -94,4 +106,4 @@
android:resource="@array/preloaded_fonts" />
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.projetosaveit.adapter
import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import java.util.Date
Expand All @@ -19,13 +20,13 @@ import com.example.projetosaveit.R
import com.example.projetosaveit.adapter.recycleView.Produto
import com.example.projetosaveit.api.repository.EstoqueRepository
import com.example.projetosaveit.api.repository.LoteRepository
import com.example.projetosaveit.api.repository.ProdutoRepository
import com.example.projetosaveit.api.repository.VitrineRepository
import com.example.projetosaveit.model.EstoqueDTO
import com.example.projetosaveit.model.ProdutoInfoDTO
import com.example.projetosaveit.model.VitrineDTO
import com.example.projetosaveit.model.VitrineInsertDTO
import com.example.projetosaveit.ui.TelaEstoque
import com.example.projetosaveit.util.NotificaoUtils
import com.google.android.material.appbar.MaterialToolbar
import okhttp3.ResponseBody
import java.text.SimpleDateFormat
Expand All @@ -38,7 +39,7 @@ class AdapterProduto : RecyclerView.Adapter<AdapterProduto.ViewHolder>() {
var listProdutos = listOf<Produto>()
var repository : LoteRepository = LoteRepository()
var repositoryVitrine : VitrineRepository = VitrineRepository()
var produtoRepository : ProdutoRepository = ProdutoRepository()
var repositoryEstoque : EstoqueRepository = EstoqueRepository()

override fun onCreateViewHolder(
parent: ViewGroup,
Expand Down Expand Up @@ -85,44 +86,59 @@ class AdapterProduto : RecyclerView.Adapter<AdapterProduto.ViewHolder>() {
cancelBtn.setOnClickListener { dialog.dismiss() }
saveBtn.setOnClickListener {
val quantidade = editQuantidade.text.toString().toInt()
val vitrineInsert : VitrineInsertDTO = VitrineInsertDTO("", produto.batchId, quantidade, Date())
val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.getDefault())
val currentDate = sdf.format(Date())

val vitrineInsert = VitrineInsertDTO("", produto.batchId, quantidade, currentDate)

repositoryVitrine.postVitrine(vitrineInsert).enqueue(object : retrofit2.Callback<ResponseBody> {
override fun onResponse(
call: retrofit2.Call<ResponseBody>,
response: retrofit2.Response<ResponseBody>
) {
if (response.isSuccessful) {
Toast.makeText(holder.itemView.context, "Produto adicionado à vitrine com sucesso!", Toast.LENGTH_LONG).show()
val updates = mapOf("quatity" to produto.quantity.toInt() - quantidade)
repository.patchProdutoId(produto.id, updates).enqueue(object : retrofit2.Callback<ResponseBody> {

val apenasNumero = produto.quantity.filter { it.isDigit() }
val quantidadeAtual = apenasNumero.toInt()

NotificaoUtils.notificarProdutoAdicionado(
holder.itemView.context,
produto.name
)

var estoque : EstoqueDTO = EstoqueDTO(0, 0, quantidadeAtual - quantidade, produto.batchId, produto.id, 0, "", currentDate)
repositoryEstoque.postEstoque(estoque).enqueue(object : retrofit2.Callback<ResponseBody> {
override fun onResponse(
call: retrofit2.Call<ResponseBody>,
response: retrofit2.Response<ResponseBody>
) {
if (response.isSuccessful) {
var estoque : EstoqueDTO = EstoqueDTO(0, 0, produto.quantity.toInt() - quantidade, produto.batchId, produto.id, 0, "", LocalDateTime.now())
produtoRepository.postProduto(estoque).enqueue(object : retrofit2.Callback<ResponseBody> {
override fun onResponse(
call: retrofit2.Call<ResponseBody>,
response: retrofit2.Response<ResponseBody>
) {
if (response.isSuccessful) {
Toast.makeText(holder.itemView.context, "O estoque foi atualizado junto com inserção na vitrine", Toast.LENGTH_LONG).show()
}
}

override fun onFailure(call: retrofit2.Call<ResponseBody>, t: Throwable) {
Toast.makeText(holder.itemView.context, "Erro ao atualizar estoque: ${t.message}", Toast.LENGTH_LONG).show()
}
})
Toast.makeText(holder.itemView.context, "O estoque foi atualizado junto com inserção na vitrine", Toast.LENGTH_LONG).show()
}else {
val errorBodyString = try {
response.errorBody()?.string()
} catch (e: Exception) {
"Erro desconhecido ao ler o corpo de erro"
}

Log.e("API_ERROR", "Erro na API: $errorBodyString")
Toast.makeText(context, errorBodyString ?: "Erro desconhecido", Toast.LENGTH_LONG).show()
}
}

override fun onFailure(call: retrofit2.Call<ResponseBody>, t: Throwable) {
Toast.makeText(holder.itemView.context, "Erro ao atualizar estoque: ${t.message}", Toast.LENGTH_LONG).show()
}
})
}else {
val errorBodyString = try {
response.errorBody()?.string()
} catch (e: Exception) {
"Erro desconhecido ao ler o corpo de erro"
}

Log.e("API_ERROR", "Erro na API: $errorBodyString")
Toast.makeText(context, errorBodyString ?: "Erro desconhecido", Toast.LENGTH_LONG).show()
}
}

Expand All @@ -140,7 +156,7 @@ class AdapterProduto : RecyclerView.Adapter<AdapterProduto.ViewHolder>() {
}

else -> {
repository.getProdutoId(produto.id).enqueue(object : retrofit2.Callback<ProdutoInfoDTO> {
repository.getProdutoId(produto.batchId).enqueue(object : retrofit2.Callback<ProdutoInfoDTO> {
override fun onResponse(
call: retrofit2.Call<ProdutoInfoDTO>,
response: retrofit2.Response<ProdutoInfoDTO>
Expand Down Expand Up @@ -174,6 +190,7 @@ class AdapterProduto : RecyclerView.Adapter<AdapterProduto.ViewHolder>() {
bundle.putString("quantidadeMostrada", produto?.batchResponseDTO?.quantity.toString())
bundle.putString("marcaProduto", produto?.productResponseDTO?.brand)
bundle.putString("skuProduto", produto?.batchResponseDTO?.batchCode)
bundle.putLong("idProduto", produto?.productResponseDTO?.id!!)

val intent : Intent = Intent(holder.itemView.context, TelaEstoque::class.java)
intent.putExtras(bundle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AdapterVitrine() : RecyclerView.Adapter<AdapterVitrine.ViewHolder>() {
val intent = Intent(context, ProdutoVitrine::class.java)

val bundle : Bundle = Bundle()
bundle.putLong("idEmpresa", response.body()?.enterpriseId ?: 0L)
bundle.putLong("idVitrine", itemVitrine.id)
bundle.putString("nomeVitrine", itemVitrine.name)
bundle.putString("imagemVitrine", itemVitrine.image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.example.projetosaveit.adapter.recycleView

import java.util.Date

class Produto(
data class Produto(
var name : String,
var quantity : String,
var expirationDate : Date,
var image : String,
var batchId : Long,
var id : Long
) {}
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ package com.example.projetosaveit.api.network
import com.example.projetosaveit.adapter.recycleView.Produto
import com.example.projetosaveit.adapter.recycleView.Vitrine
import com.example.projetosaveit.model.ChatDTO
import com.example.projetosaveit.model.ChatRequest
import com.example.projetosaveit.model.ChatResponse
import com.example.projetosaveit.model.EmpresaDTO
import com.example.projetosaveit.model.EmpresaInsertDTO
import com.example.projetosaveit.model.EstoqueDTO
import com.example.projetosaveit.model.EstoqueInsertDTO
import com.example.projetosaveit.model.FuncionarioDTO
import com.example.projetosaveit.model.FuncionarioInsertDTO
import com.example.projetosaveit.model.HistoricoResponse
import com.example.projetosaveit.model.ImagemDTO
import com.example.projetosaveit.model.IniciarChatRequest
import com.example.projetosaveit.model.IniciarChatResponse
import com.example.projetosaveit.model.LoteDTO
import com.example.projetosaveit.model.LoteInsertDTO
import com.example.projetosaveit.model.ProdutoInfoDTO
import com.example.projetosaveit.model.RelatorioDTO
import com.example.projetosaveit.model.RelatorioProdutoDTO
import com.example.projetosaveit.model.VitrineDTO
import com.example.projetosaveit.model.VitrineInsertDTO
import okhttp3.ResponseBody
Expand All @@ -30,8 +35,18 @@ interface ApiService {

// API de SQL

@POST("api/product/inserir")
fun postProduto(@Body estoque : EstoqueDTO) : Call<ResponseBody>
@GET("api/stock/relatorioProdutoPorProduto/{enterpriseId}/{productId}")
fun getRelatorioProduto(@Path("enterpriseId") enterpriseId: Long, @Path("productId") productId: Long
): Call<List<RelatorioProdutoDTO>>

@GET("api/stock/relatorioProduto/{enterpriseId}")
fun getRelatorioProdutos(@Path("enterpriseId") idEmpresa : Long): Call<List<RelatorioDTO>>

@POST("/api/stock/inserir")
fun postEstoque(@Body estoque : EstoqueDTO) : Call<ResponseBody>

@GET("/api/batch/selecionarSku/{sku}")
fun getBatchSku(@Path("sku") sku : String) : Call<LoteDTO>

@GET("api/batch/listarProdutosLote/{enterpriseId}")
fun getProdutos(@Path("enterpriseId") idEmpresa : Long): Call<List<Produto>>
Expand Down Expand Up @@ -81,34 +96,41 @@ interface ApiService {
@GET("api/employee/buscarPorEmail/{email}")
fun getFuncionarioEmail(@Path("email") email : String): Call<FuncionarioDTO>

@GET("api/stock/relatorioProduto/{enterpriseId}")
fun getRelatorioProdutos(@Path("enterpriseId") idEmpresa : Long): Call<List<RelatorioDTO>>
@GET("api/showcase/novos")
fun getVitrinesNovas(
@Query("ultimoCheck") ultimoCheck: String
): Call<List<VitrineDTO>>

@GET("api/batch/selecionarSku/{sku}")
fun getBatchSku(@Path("sku") sku : String): Call<LoteDTO>
// API de Mongo/WebSocket

@POST("api/stock/inserir")
fun postEstoque(@Body estoque : EstoqueInsertDTO) : Call<ResponseBody>

// API de Mongo

@GET("chats/enterprise/{enterpriseId}")
@GET("chats/empresa/{enterpriseId}")
fun getChatsEmpresa(
@Path("enterpriseId") idEmpresa: Long
): Call<List<ChatDTO>>

@GET("chats/ultimamensagem")
@GET("chats/ultimaMensagemDoChat")
fun getChatUltimaMensagem(
@Query("chatId") idChat: Long, @Query("enterpriseId") idEmpresa: Long
): Call<ChatDTO>

@GET("chats/outraempresa")
@GET("chats/buscarOutraEmpresa")
fun getChatOutraEmpresa(
@Query("chatId") idChat: Long, @Query("enterpriseId") idEmpresa: Long
): Call<ChatDTO>

@GET("chats/buscarchatweb")
@GET("chats/buscarChatWebSocket")
fun getChatsHistorico(
@Query("chatId") idChat: Long
): Call<List<ChatDTO>>

// API de Chatbot

@POST("iniciar_chat")
fun iniciarChat(@Body request: IniciarChatRequest): Call<IniciarChatResponse>

@POST("executar_fluxo")
fun enviarMensagem(@Body request: ChatRequest): Call<ChatResponse>

@GET("obter_historico")
fun obterHistorico(@Query("session_id") sessionId: String): Call<HistoricoResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import okhttp3.OkHttpClient

object RetrofitClientSql {

private const val BASE_URL = "https://apisaveit.onrender.com/"
private const val BASE_URL = "https://apisaveit.onrender.com"
private const val API_TOKEN = "essentiasaveit-193812-paoea-oei"

private val client = OkHttpClient.Builder()
Expand All @@ -28,4 +28,4 @@ object RetrofitClientSql {
val instance: ApiService by lazy {
retrofit.create(ApiService::class.java)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.example.projetosaveit.api.network.RetrofitClientSql
import com.example.projetosaveit.model.EstoqueDTO
import com.example.projetosaveit.model.EstoqueInsertDTO
import com.example.projetosaveit.model.RelatorioDTO
import com.example.projetosaveit.model.RelatorioProdutoDTO
import okhttp3.Response
import okhttp3.ResponseBody
import retrofit2.Call
Expand All @@ -15,7 +16,11 @@ class EstoqueRepository {
return RetrofitClientSql.instance.getRelatorioProdutos(enterpriseId)
}

fun postEstoque(estoque: EstoqueInsertDTO) : Call<ResponseBody> {
fun postEstoque(estoque: EstoqueDTO) : Call<ResponseBody> {
return RetrofitClientSql.instance.postEstoque(estoque)
}

fun getRelatorioProduto(enterpriseId : Long, productId : Long) : Call<List<RelatorioProdutoDTO>> {
return RetrofitClientSql.instance.getRelatorioProduto(enterpriseId, productId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ import retrofit2.Response


class ProdutoRepository {
fun postProduto(estoque : EstoqueDTO) : Call<ResponseBody> {
return RetrofitClientSql.instance.postProduto(estoque)
}
// por enquanto nada...
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ class VitrineRepository {
fun getVitrineEmpresa(enterpriseId : Long) = RetrofitClientSql.instance.getVitrinesEmpresa(enterpriseId)

fun postVitrine(showcase : VitrineInsertDTO) = RetrofitClientSql.instance.postVitrine(showcase)

fun getVitrineNovas(ultimoCheck: String) = RetrofitClientSql.instance.getVitrinesNovas(ultimoCheck)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class EstoqueDTO (
var productId : Long,
var discardQuantity : Int,
var discardReason : String,
var createdAt : LocalDateTime
var createdAt : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.projetosaveit.model

data class RelatorioProdutoDTO(
val totalOutput: Int,
val mouthInput: Int
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ class VitrineDTO(
var name: String,
var description: String,
var image: String,
var price: Double,
var productId: Long,
var loteId: Long,
var tipoPeso: String,
var quantidadeGeral: Int,
var empresa: String,
var localizacao: String,
var validade: String
var validade: String,
var enterpriseId: Long
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class VitrineInsertDTO(
var description : String,
var batchId : Long,
var quantityShowcase : Int,
var entranceDate : Date
var entranceDate : String
) {
}
Loading
Loading