Commit 2b4f7165e7cb403443dd04e7a4ba918288115691
1 parent
62463245e4
Exists in
master
24092020 1900
Showing
15 changed files
with
372 additions
and
197 deletions
Show diff stats
app/build.gradle
... | ... | @@ -28,6 +28,7 @@ android { |
28 | 28 | } |
29 | 29 | } |
30 | 30 | compileOptions { |
31 | + coreLibraryDesugaringEnabled true | |
31 | 32 | sourceCompatibility JavaVersion.VERSION_1_8 |
32 | 33 | targetCompatibility JavaVersion.VERSION_1_8 |
33 | 34 | |
... | ... | @@ -54,7 +55,7 @@ dependencies { |
54 | 55 | testImplementation 'junit:junit:4.13' |
55 | 56 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' |
56 | 57 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' |
57 | - | |
58 | + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10' | |
58 | 59 | |
59 | 60 | //Room |
60 | 61 | implementation 'androidx.room:room-ktx:2.2.5' |
app/src/main/java/com/focasoftware/deboinventariov20/DB/DAO/ArticulosDAO.kt
... | ... | @@ -51,19 +51,22 @@ interface InvHeadDAO { |
51 | 51 | suspend fun deleteAllArticulos() |
52 | 52 | |
53 | 53 | @Query("DELETE FROM $TABLA_INV_H WHERE INV_NUM=:inven") |
54 | - suspend fun deleteinvHead(inven: Long) | |
54 | + suspend fun deleteinvHead(inven: Int) | |
55 | 55 | |
56 | 56 | @Query("SELECT * FROM $TABLA_INV_H ORDER BY INV_FEI") |
57 | 57 | suspend fun fetchAllInvHead(): List<InvHead> |
58 | 58 | |
59 | 59 | @Query("SELECT INV_LUG FROM $TABLA_INV_H WHERE INV_NUM=:inven") |
60 | - suspend fun fetchAreaInvH (inven: Long): Boolean | |
60 | + suspend fun fetchAreaInvH (inven: Int): Boolean | |
61 | 61 | |
62 | 62 | @Query("SELECT INV_PRODCONT FROM $TABLA_INV_H WHERE INV_NUM=:inven") |
63 | - suspend fun consultaCantidadInvH (inven: Long): Int | |
63 | + suspend fun consultaCantidadInvH (inven: Int): Int | |
64 | 64 | |
65 | 65 | @Query("UPDATE $TABLA_INV_H SET INV_PRODCONT=:cant WHERE INV_NUM=:inven") |
66 | - suspend fun updateInvBody(inven: Long,cant: Int) | |
66 | + suspend fun updateInvBody(inven: Int,cant: Int) | |
67 | + | |
68 | + @Query("SELECT INV_PRODCONT FROM $TABLA_INV_H WHERE INV_NUM=:inven") | |
69 | + suspend fun foundInvHead (inven: Int): InvHead | |
67 | 70 | } |
68 | 71 | |
69 | 72 | @Dao |
... | ... | @@ -75,19 +78,19 @@ interface InvBodyDAO { |
75 | 78 | suspend fun deleteAllInvBody() |
76 | 79 | |
77 | 80 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:inven") |
78 | - suspend fun deleteInvBody(inven: Long) | |
81 | + suspend fun deleteInvBody(inven: Int) | |
79 | 82 | |
80 | - @Query("UPDATE $TABLA_INV_B SET CANT=:cant WHERE SEC=:sec AND COD=:cod") | |
81 | - suspend fun UpdateInvBody(cant: Float, sec: Long, cod: Long) | |
83 | + @Query("UPDATE $TABLA_INV_B SET CANT=:cant , INV_FEF=:actFechaHora WHERE SEC=:sec AND COD=:cod") | |
84 | + suspend fun updateInvBody(cant: Float, sec: Long, cod: Long, actFechaHora:String) | |
82 | 85 | |
83 | 86 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:inven ORDER BY INV_FEI DESC") |
84 | 87 | suspend fun fetchAllInvBody(inven: Int): List<InvBody> |
85 | 88 | |
86 | 89 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:numInventario AND SEC=:sector AND COD=:codigo") |
87 | - suspend fun fetchArtInInvBody(sector: Long, codigo: Long, numInventario: Long): InvBody | |
90 | + suspend fun fetchArtInInvBody(sector: Long, codigo: Long, numInventario: Int): InvBody | |
88 | 91 | |
89 | 92 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:numInventario AND SEC=:sector AND COD=:codigo") |
90 | - suspend fun deleteItemFromInvBody(sector: Long, codigo: Long, numInventario: Long): Int | |
93 | + suspend fun deleteItemFromInvBody(sector: Long, codigo: Long, numInventario: Int): Int | |
91 | 94 | } |
92 | 95 | |
93 | 96 | @Dao |
app/src/main/java/com/focasoftware/deboinventariov20/Model/ProductosApi.kt
... | ... | @@ -1,11 +0,0 @@ |
1 | -package com.focasoftware.deboinventariov20.Model | |
2 | - | |
3 | -import retrofit2.Response | |
4 | -import retrofit2.http.GET | |
5 | - | |
6 | -interface ProductosApi { | |
7 | - | |
8 | - @GET("articulos/articulosCodBarra") | |
9 | - suspend fun getProductos(): Response<List<Productos>> | |
10 | - | |
11 | -} | |
12 | 0 | \ No newline at end of file |
app/src/main/java/com/focasoftware/deboinventariov20/Model/ProductosService.kt
... | ... | @@ -1,52 +0,0 @@ |
1 | -package com.focasoftware.deboinventariov20.Model | |
2 | - | |
3 | -import com.focasoftware.deboinventariov20.UI.actualizacionMaestros.BASE_URL | |
4 | -import okhttp3.OkHttpClient | |
5 | -import okhttp3.logging.HttpLoggingInterceptor | |
6 | -import retrofit2.Retrofit | |
7 | -import retrofit2.converter.gson.GsonConverterFactory | |
8 | -import java.net.SocketTimeoutException | |
9 | -import java.util.concurrent.TimeUnit | |
10 | - | |
11 | -object ProductosService { | |
12 | - private val TIME_OUT: Long | |
13 | - get() { | |
14 | - return 15 | |
15 | - } | |
16 | - private val interceptor = run { | |
17 | - val httpLoggingInterceptor = HttpLoggingInterceptor() | |
18 | - httpLoggingInterceptor.apply { | |
19 | - httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY | |
20 | - } | |
21 | - } | |
22 | - private val okHttpClient = OkHttpClient.Builder() | |
23 | - .addNetworkInterceptor(interceptor) // same for .addInterceptor(...) | |
24 | - .connectTimeout(TIME_OUT, TimeUnit.SECONDS) //Backend is really slow | |
25 | - .writeTimeout(TIME_OUT, TimeUnit.SECONDS) | |
26 | - .readTimeout(TIME_OUT, TimeUnit.SECONDS) | |
27 | - .build() | |
28 | - fun getProductosService(): ProductosApi { | |
29 | - return Retrofit.Builder() | |
30 | - .client(okHttpClient) | |
31 | - .baseUrl(BASE_URL) | |
32 | - .addConverterFactory(GsonConverterFactory.create()) | |
33 | - .build() | |
34 | - .create(ProductosApi::class.java) | |
35 | - } | |
36 | -} | |
37 | -//fun prubaConexion(){ | |
38 | -// for (retries in 0..2) { | |
39 | -// try { | |
40 | -// val client: HttpClient = createHttpClientWithDefaultSocketFactory(null, null) | |
41 | -// val response: HttpResponse = client.execute(get) | |
42 | -// val statusCode: Int = response.getStatusLine().getStatusCode() | |
43 | -// return if (statusCode != 200) { | |
44 | -// throw IllegalStateException("GET Request on '" + get.getURI().toString().toString() + "' resulted in " + statusCode) | |
45 | -// } else { | |
46 | -// response.getEntity() | |
47 | -// } | |
48 | -// } catch (e: SocketTimeoutException) { | |
49 | -// // connection timed out...let's try again | |
50 | -// } | |
51 | -// } | |
52 | -//} | |
53 | 0 | \ No newline at end of file |
app/src/main/java/com/focasoftware/deboinventariov20/Model/Tablas.kt
... | ... | @@ -36,6 +36,16 @@ data class Productos(@SerializedName("CODSEC") var sector: String?, |
36 | 36 | @SerializedName( "UNIVEN") var balanza: Int?, |
37 | 37 | @SerializedName("DEPSN") var depSn: Boolean?, |
38 | 38 | @SerializedName("FOTO") var imagen: String?) |
39 | + | |
40 | +data class InvToSend ( var fechaInicio: String?, | |
41 | + var fechaFinal: String?, | |
42 | + var lugar: Int?, | |
43 | + var sector: String?, | |
44 | + var codigo: String?, | |
45 | + var descripcion: String?, | |
46 | + var cantTomada: String?, | |
47 | + var fechaInicioArt: String?, | |
48 | + var fechaFinArt: String?) | |
39 | 49 | //@Entity(tableName = TABLA_ART) |
40 | 50 | //data class Articles(@ColumnInfo(name = "SEC") var sector: String?, |
41 | 51 | // @ColumnInfo(name = "COD") var codigo: String?, |
app/src/main/java/com/focasoftware/deboinventariov20/Model/WebService.kt
... | ... | @@ -0,0 +1,71 @@ |
1 | +package com.focasoftware.deboinventariov20.Model | |
2 | + | |
3 | +import com.focasoftware.deboinventariov20.UI.actualizacionMaestros.BASE_URL | |
4 | +import okhttp3.OkHttpClient | |
5 | +import okhttp3.logging.HttpLoggingInterceptor | |
6 | +import retrofit2.Retrofit | |
7 | +import retrofit2.converter.gson.GsonConverterFactory | |
8 | +import java.util.concurrent.TimeUnit | |
9 | + | |
10 | +object WebService { | |
11 | + private var instance: WebService? = null | |
12 | + private var retrofit:Retrofit? =null | |
13 | + private val TIME_OUT: Long | |
14 | + get() { | |
15 | + return 15 | |
16 | + } | |
17 | + private val interceptor = run { | |
18 | + val httpLoggingInterceptor = HttpLoggingInterceptor() | |
19 | + httpLoggingInterceptor.apply { | |
20 | + httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY | |
21 | + } | |
22 | + } | |
23 | + private val okHttpClient = OkHttpClient.Builder() | |
24 | + .addNetworkInterceptor(interceptor) | |
25 | + .connectTimeout(TIME_OUT, TimeUnit.SECONDS) | |
26 | + .writeTimeout(TIME_OUT, TimeUnit.SECONDS) | |
27 | + .readTimeout(TIME_OUT, TimeUnit.SECONDS) | |
28 | + .build() | |
29 | + | |
30 | + private fun WebService() { | |
31 | + retrofit = Retrofit.Builder() | |
32 | + .client(okHttpClient) | |
33 | + .baseUrl(BASE_URL) | |
34 | + .addConverterFactory(GsonConverterFactory.create()) | |
35 | + .build() | |
36 | + } | |
37 | + | |
38 | + @Synchronized | |
39 | + fun getInstance(): WebService? { | |
40 | + if (instance == null) { | |
41 | + instance = WebService | |
42 | + } | |
43 | + return instance | |
44 | + } | |
45 | + | |
46 | + fun <S> createService(serviceClass: Class<S>): S { | |
47 | + return retrofit!!.create(serviceClass) | |
48 | + } | |
49 | + | |
50 | +// fun <S> createService(serviceClass: Class<S>): S { | |
51 | +// return retrofit!!.create(serviceClass) | |
52 | +// } | |
53 | + | |
54 | +// fun getProductosService(): EndPoints { | |
55 | +// return Retrofit.Builder() | |
56 | +// .client(okHttpClient) | |
57 | +// .baseUrl(BASE_URL) | |
58 | +// .addConverterFactory(GsonConverterFactory.create()) | |
59 | +// .build() | |
60 | +// .create(EndPoints::class.java) | |
61 | +// } | |
62 | + | |
63 | +// fun getProductosService(): ProductosApi { | |
64 | +// return Retrofit.Builder() | |
65 | +// .client(okHttpClient) | |
66 | +// .baseUrl(BASE_URL) | |
67 | +// .addConverterFactory(GsonConverterFactory.create()) | |
68 | +// .build() | |
69 | +// .create(ProductosApi::class.java) | |
70 | +// } | |
71 | +} |
app/src/main/java/com/focasoftware/deboinventariov20/Model/WebServiceApi.kt
... | ... | @@ -0,0 +1,18 @@ |
1 | +package com.focasoftware.deboinventariov20.Model | |
2 | + | |
3 | +import retrofit2.Call | |
4 | +import retrofit2.Response | |
5 | +import retrofit2.http.Body | |
6 | +import retrofit2.http.GET | |
7 | +import retrofit2.http.POST | |
8 | + | |
9 | + | |
10 | +interface WebServiceApi { | |
11 | + | |
12 | + @GET("articulos/articulosCodBarra") | |
13 | + fun getProductos(): Call<List<Productos>> | |
14 | + | |
15 | + | |
16 | + @POST("articulos/articulosCodBarra") | |
17 | + fun inventarioToSend(@Body invToSend: List<InvToSend>?): Call<Void?>? | |
18 | +} | |
0 | 19 | \ No newline at end of file |
app/src/main/java/com/focasoftware/deboinventariov20/UI/SplashActivity.kt
app/src/main/java/com/focasoftware/deboinventariov20/UI/Utils/Utils.kt
... | ... | @@ -11,6 +11,8 @@ import kotlinx.coroutines.GlobalScope |
11 | 11 | import kotlinx.coroutines.async |
12 | 12 | import java.io.IOException |
13 | 13 | import java.net.UnknownHostException |
14 | +import java.time.LocalDateTime | |
15 | +import java.time.format.DateTimeFormatter | |
14 | 16 | |
15 | 17 | fun modificarCantidadEnCabecera(inventarioActual: Int, b: Boolean, context: Context) { |
16 | 18 | GlobalScope.async(Dispatchers.IO) { |
... | ... | @@ -138,4 +140,11 @@ class serverNoConf : DialogFragment() { |
138 | 140 | return builder.create() |
139 | 141 | } ?: throw IllegalStateException("Activity cannot be null") |
140 | 142 | } |
141 | -} | |
142 | 143 | \ No newline at end of file |
144 | +} | |
145 | +fun ObtenerFechaActual(): String { | |
146 | + //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | |
147 | + val current = LocalDateTime.now() | |
148 | + val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss") | |
149 | + val dFechaHora = current.format(formatter) | |
150 | + return dFechaHora.toString() | |
151 | + } | |
143 | 152 | \ No newline at end of file |
app/src/main/java/com/focasoftware/deboinventariov20/UI/actualizacionMaestros/ActuaMaestrosFragment.kt
... | ... | @@ -5,25 +5,30 @@ import android.view.LayoutInflater |
5 | 5 | import android.view.View |
6 | 6 | import android.view.ViewGroup |
7 | 7 | import android.widget.Button |
8 | -import android.widget.Toast | |
9 | 8 | import androidx.fragment.app.Fragment |
9 | +import androidx.lifecycle.lifecycleScope | |
10 | 10 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
11 | 11 | import com.focasoftware.deboinventariov20.Model.Articles |
12 | -import com.focasoftware.deboinventariov20.Model.ProductosService | |
12 | +import com.focasoftware.deboinventariov20.Model.Productos | |
13 | 13 | import com.focasoftware.deboinventariov20.Model.ServeInv |
14 | +import com.focasoftware.deboinventariov20.Model.WebService.getInstance | |
15 | +import com.focasoftware.deboinventariov20.Model.WebServiceApi | |
14 | 16 | import com.focasoftware.deboinventariov20.R |
15 | 17 | import com.focasoftware.deboinventariov20.UI.Utils.noServerConf |
16 | 18 | import com.focasoftware.deboinventariov20.UI.Utils.serverNoConf |
17 | -import com.focasoftware.deboinventariov20.UI.Utils.serverValido | |
18 | 19 | import kotlinx.android.synthetic.main.fragment_actua_maestros.* |
19 | 20 | import kotlinx.coroutines.* |
20 | 21 | import kotlinx.coroutines.Dispatchers.IO |
21 | 22 | import kotlinx.coroutines.Dispatchers.Main |
23 | +import retrofit2.Call | |
24 | +import retrofit2.Callback | |
25 | +import retrofit2.Response | |
22 | 26 | import java.net.SocketTimeoutException |
23 | 27 | |
24 | 28 | |
25 | 29 | var BASE_URL = "" |
26 | -var serverPre:ServeInv?=null | |
30 | +var serverPre: ServeInv? = null | |
31 | + | |
27 | 32 | class ActuaMaestrosFragment : Fragment() { |
28 | 33 | |
29 | 34 | override fun onCreate(savedInstanceState: Bundle?) { |
... | ... | @@ -31,9 +36,9 @@ class ActuaMaestrosFragment : Fragment() { |
31 | 36 | |
32 | 37 | GlobalScope.launch(Main) { |
33 | 38 | |
34 | - serverPre = fetchServerPreOne() | |
35 | - if (serverPre!=null) { | |
36 | - btnConfirmarAct.isEnabled=true | |
39 | + serverPre = fetchServerPreOne() | |
40 | + if (serverPre != null) { | |
41 | + btnConfirmarAct.isEnabled = true | |
37 | 42 | if (serverPre!!.direccion.isNullOrEmpty()) { |
38 | 43 | val modalDialog = noServerConf() |
39 | 44 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
... | ... | @@ -41,11 +46,11 @@ class ActuaMaestrosFragment : Fragment() { |
41 | 46 | BASE_URL = serverPre!!.direccion.toString() + ":" + serverPre!!.puerto.toString() + "/" |
42 | 47 | tvServerConectado.text = "Conectado al servidor: ${serverPre!!.descripcion}" |
43 | 48 | } |
44 | - }else{ | |
49 | + } else { | |
45 | 50 | val modalDialog = serverNoConf() |
46 | 51 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
47 | 52 | |
48 | - btnConfirmarAct.isEnabled=false | |
53 | + btnConfirmarAct.isEnabled = false | |
49 | 54 | |
50 | 55 | } |
51 | 56 | } |
... | ... | @@ -67,25 +72,20 @@ class ActuaMaestrosFragment : Fragment() { |
67 | 72 | bConfirmarAct.setOnClickListener { |
68 | 73 | loading_view.visibility = View.VISIBLE |
69 | 74 | countriesList.text = "Obteniendo artรญculos del servidor, aguarde por favor." |
70 | - GlobalScope.launch(Main) { | |
71 | - obtenerArticulos() | |
72 | - } | |
75 | + obtenerArticulos() | |
73 | 76 | } |
74 | 77 | return v |
75 | 78 | } |
76 | 79 | |
77 | - private suspend fun obtenerArticulos() { | |
78 | - | |
79 | - val productosService = ProductosService.getProductosService() | |
80 | + private fun obtenerArticulos() { | |
81 | + val call = getInstance() | |
82 | + ?.createService(WebServiceApi::class.java) | |
83 | + ?.getProductos() | |
80 | 84 | var index: Long = 1 |
81 | - withContext(IO) { | |
82 | - val job = CoroutineScope(IO).launch { | |
83 | - // TODO: BORRO TODO LOS ARTICULOS DE LA BASE PARA CARGARLOS DE NUEVO | |
84 | - AppDb.getAppDb(requireActivity())!!.ArticulosDAO()!!.deleteAllArticulos() | |
85 | - try { | |
86 | - val response = productosService.getProductos() | |
87 | - if (response.isSuccessful) { | |
88 | - | |
85 | + call!!.enqueue(object : Callback<List<Productos>> { | |
86 | + override fun onResponse(call: Call<List<Productos>>, response: Response<List<Productos>>) { | |
87 | + if (response.code() == 200) { | |
88 | + try { | |
89 | 89 | for (pro in response.body()!!) { |
90 | 90 | val artiAcargar = Articles( |
91 | 91 | pro.sector, |
... | ... | @@ -103,36 +103,76 @@ class ActuaMaestrosFragment : Fragment() { |
103 | 103 | pro.imagen |
104 | 104 | ) |
105 | 105 | index += index |
106 | - AppDb.getAppDb(requireActivity())!!.ArticulosDAO()!!.insertArticulos(artiAcargar) | |
106 | + insertarProducto(artiAcargar) | |
107 | 107 | } |
108 | - withContext(Main) { | |
109 | - countriesList.visibility = View.VISIBLE | |
110 | - countriesList.text = "ยกDatos Importados Correctamente!" | |
111 | - loading_view.visibility = View.GONE | |
112 | - } | |
113 | - } else if (!response.isSuccessful) { | |
114 | - withContext(Main) { | |
115 | - countriesList.visibility = View.VISIBLE | |
116 | - countriesList.text = "ยกSin servicio. No se puede conectar a la api o al servidor configurado en el BackEnd!" | |
117 | - loading_view.visibility = View.GONE | |
118 | - } | |
119 | - } | |
120 | - } catch (e: SocketTimeoutException) { | |
121 | - withContext(Main) { | |
108 | + countriesList.visibility = View.VISIBLE | |
109 | + countriesList.text = "ยกDatos Importados Correctamente!" | |
110 | + loading_view.visibility = View.GONE | |
111 | + } catch (e: SocketTimeoutException) { | |
122 | 112 | countriesList.visibility = View.VISIBLE |
123 | 113 | countriesList.text = "ยกSin conexiรณn al Servidor!" |
124 | 114 | loading_view.visibility = View.GONE |
125 | 115 | } |
126 | 116 | } |
127 | 117 | } |
128 | -// if (job == null) { | |
129 | -// withContext(Main) { | |
130 | -// countriesList.visibility = View.VISIBLE | |
131 | -// countriesList.text = "No se puedo realizar la conexiรณn al Servidor" | |
132 | -// loading_view.visibility = View.GONE | |
118 | + | |
119 | + override fun onFailure(call: Call<List<Productos>>, t: Throwable) { | |
120 | + countriesList.visibility = View.VISIBLE | |
121 | + countriesList.text = (t.message + "." + t.cause) | |
122 | + loading_view.visibility = View.GONE | |
123 | + } | |
124 | + }) | |
125 | + | |
126 | + | |
127 | +// var index: Long = 1 | |
128 | +// withContext(IO) { | |
129 | +// val job = CoroutineScope(IO).launch { | |
130 | +// // TODO: BORRO TODO LOS ARTICULOS DE LA BASE PARA CARGARLOS DE NUEVO | |
131 | +// AppDb.getAppDb(requireActivity())!!.ArticulosDAO()!!.deleteAllArticulos() | |
132 | +// try { | |
133 | +// val response = productosService.getProductos() | |
134 | +// if (response.isSuccessful) { | |
135 | +// | |
136 | +// for (pro in response.body()!!) { | |
137 | +// val artiAcargar = Articles( | |
138 | +// pro.sector, | |
139 | +// pro.codigo, | |
140 | +// pro.descripcion, | |
141 | +// pro.codBar, | |
142 | +// pro.codOrigen, | |
143 | +// pro.precio, | |
144 | +// pro.costo, | |
145 | +// pro.exiVenta, | |
146 | +// pro.exiDeposito, | |
147 | +// pro.de, | |
148 | +// pro.balanza, | |
149 | +// pro.depSn, | |
150 | +// pro.imagen | |
151 | +// ) | |
152 | +// index += index | |
153 | +// AppDb.getAppDb(requireActivity())!!.ArticulosDAO()!!.insertArticulos(artiAcargar) | |
154 | +// } | |
155 | +// withContext(Main) { | |
156 | +// countriesList.visibility = View.VISIBLE | |
157 | +// countriesList.text = "ยกDatos Importados Correctamente!" | |
158 | +// loading_view.visibility = View.GONE | |
159 | +// } | |
160 | +// } else if (!response.isSuccessful) { | |
161 | +// withContext(Main) { | |
162 | +// countriesList.visibility = View.VISIBLE | |
163 | +// countriesList.text = "ยกSin servicio. No se puede conectar a la api o al servidor configurado en el BackEnd!" | |
164 | +// loading_view.visibility = View.GONE | |
165 | +// } | |
166 | +// } | |
167 | +// } catch (e: SocketTimeoutException) { | |
168 | +// withContext(Main) { | |
169 | +// countriesList.visibility = View.VISIBLE | |
170 | +// countriesList.text = "ยกSin conexiรณn al Servidor!" | |
171 | +// loading_view.visibility = View.GONE | |
172 | +// } | |
133 | 173 | // } |
134 | 174 | // } |
135 | - } | |
175 | +// } | |
136 | 176 | |
137 | 177 | |
138 | 178 | // withContext(Dispatchers.Main) { |
... | ... | @@ -166,6 +206,14 @@ class ActuaMaestrosFragment : Fragment() { |
166 | 206 | // }) |
167 | 207 | } |
168 | 208 | |
209 | + fun insertarProducto(aCargar: Articles) { | |
210 | + lifecycleScope.launch { | |
211 | + withContext(IO) { | |
212 | + AppDb.getAppDb(requireActivity())!!.ArticulosDAO()!!.insertArticulos(aCargar) | |
213 | + } | |
214 | + } | |
215 | + } | |
216 | + | |
169 | 217 | fun mostrarArticulos() { |
170 | 218 | val Job = GlobalScope.launch { |
171 | 219 | var listArticulos: List<Articles>? = null |
... | ... | @@ -181,9 +229,8 @@ class ActuaMaestrosFragment : Fragment() { |
181 | 229 | countriesList?.text = temp |
182 | 230 | } |
183 | 231 | } |
184 | -// for (professor in listArticulos!!) { | |
185 | -// editT.text= professor.id.toString() | |
186 | -// } | |
187 | 232 | } |
188 | 233 | } |
189 | 234 | |
235 | + | |
236 | + |
app/src/main/java/com/focasoftware/deboinventariov20/UI/descripCorigenFragment/CodigoOriFragment.kt
... | ... | @@ -27,8 +27,8 @@ import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
27 | 27 | import com.focasoftware.deboinventariov20.Model.Articles |
28 | 28 | import com.focasoftware.deboinventariov20.Model.InvBody |
29 | 29 | import com.focasoftware.deboinventariov20.R |
30 | +import com.focasoftware.deboinventariov20.UI.Utils.ObtenerFechaActual | |
30 | 31 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera |
31 | -import com.focasoftware.deboinventariov20.UI.inventario.InventarioFragment | |
32 | 32 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* |
33 | 33 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.btnAceptar |
34 | 34 | import kotlinx.android.synthetic.main.login_dialog.view.* |
... | ... | @@ -138,8 +138,8 @@ class CodigoOriFragment : Fragment() { |
138 | 138 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, |
139 | 139 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza, |
140 | 140 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.depSn, |
141 | - InventarioFragment().ObtenerFechaActual(), | |
142 | - InventarioFragment().ObtenerFechaActual()) | |
141 | + ObtenerFechaActual(), | |
142 | + ObtenerFechaActual()) | |
143 | 143 | InsertarArtEnDB(body)// TODO: MANDO A CARGAR A LA BASE DE DATOS |
144 | 144 | modificarCantidadEnCabecera(numeroInventario, true, requireActivity()) |
145 | 145 | // VolverAinventario() |
... | ... | @@ -250,7 +250,7 @@ class CodigoOriFragment : Fragment() { |
250 | 250 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
251 | 251 | var busqueda: InvBody? = null |
252 | 252 | return GlobalScope.async(Dispatchers.IO) { |
253 | - busqueda = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.fetchArtInInvBody(sector.toLong(), codigo.toLong(), numInventario.toLong()) | |
253 | + busqueda = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.fetchArtInInvBody(sector.toLong(), codigo.toLong(), numInventario.toInt()) | |
254 | 254 | return@async busqueda |
255 | 255 | }.await() |
256 | 256 | } |
... | ... | @@ -260,7 +260,7 @@ class CodigoOriFragment : Fragment() { |
260 | 260 | withContext(Dispatchers.IO) { |
261 | 261 | val activity: FragmentActivity? = activity |
262 | 262 | if (activity != null && isAdded) { |
263 | - AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.UpdateInvBody(cantidad, sector.toLong(), codigo.toLong()) | |
263 | + AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.updateInvBody(cantidad, sector.toLong(), codigo.toLong(), ObtenerFechaActual()) | |
264 | 264 | } |
265 | 265 | } |
266 | 266 | } |
app/src/main/java/com/focasoftware/deboinventariov20/UI/descripcionFragment/DescripcionFragment.kt
... | ... | @@ -27,8 +27,8 @@ import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
27 | 27 | import com.focasoftware.deboinventariov20.Model.Articles |
28 | 28 | import com.focasoftware.deboinventariov20.Model.InvBody |
29 | 29 | import com.focasoftware.deboinventariov20.R |
30 | +import com.focasoftware.deboinventariov20.UI.Utils.ObtenerFechaActual | |
30 | 31 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera |
31 | -import com.focasoftware.deboinventariov20.UI.inventario.InventarioFragment | |
32 | 32 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* |
33 | 33 | import kotlinx.android.synthetic.main.login_dialog.view.* |
34 | 34 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar |
... | ... | @@ -138,8 +138,8 @@ class DescripcionFragment : Fragment() { |
138 | 138 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, |
139 | 139 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza, |
140 | 140 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.depSn, |
141 | - InventarioFragment().ObtenerFechaActual(), | |
142 | - InventarioFragment().ObtenerFechaActual() | |
141 | + ObtenerFechaActual(), | |
142 | + ObtenerFechaActual() | |
143 | 143 | ) |
144 | 144 | InsertarArtEnDB(body)// TODO: MANDO A CARGAR A LA BASE DE DATOS |
145 | 145 | modificarCantidadEnCabecera(numeroInventario, true, requireActivity()) |
... | ... | @@ -264,7 +264,7 @@ class DescripcionFragment : Fragment() { |
264 | 264 | withContext(Dispatchers.IO) { |
265 | 265 | val activity: FragmentActivity? = activity |
266 | 266 | if (activity != null && isAdded) { |
267 | - AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.UpdateInvBody(cantidad, sector.toLong(), codigo.toLong()) | |
267 | + AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.updateInvBody(cantidad, sector.toLong(), codigo.toLong(),ObtenerFechaActual()) | |
268 | 268 | } |
269 | 269 | } |
270 | 270 | } |
app/src/main/java/com/focasoftware/deboinventariov20/UI/inventario/InventarioFragment.kt
... | ... | @@ -2,7 +2,6 @@ package com.focasoftware.deboinventariov20.UI.inventario |
2 | 2 | |
3 | 3 | import android.annotation.SuppressLint |
4 | 4 | import android.app.AlertDialog |
5 | -import android.app.Dialog | |
6 | 5 | import android.content.Context |
7 | 6 | import android.content.Context.INPUT_METHOD_SERVICE |
8 | 7 | import android.content.DialogInterface |
... | ... | @@ -23,7 +22,6 @@ import androidx.core.content.ContextCompat |
23 | 22 | import androidx.core.os.bundleOf |
24 | 23 | import androidx.fragment.app.Fragment |
25 | 24 | import androidx.lifecycle.ViewModel |
26 | -import androidx.lifecycle.ViewModelProvider | |
27 | 25 | import androidx.lifecycle.ViewModelProviders |
28 | 26 | import androidx.lifecycle.lifecycleScope |
29 | 27 | import androidx.navigation.NavController |
... | ... | @@ -32,11 +30,10 @@ import androidx.recyclerview.widget.ItemTouchHelper |
32 | 30 | import androidx.recyclerview.widget.LinearLayoutManager |
33 | 31 | import androidx.recyclerview.widget.RecyclerView |
34 | 32 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
35 | -import com.focasoftware.deboinventariov20.Model.Articles | |
36 | -import com.focasoftware.deboinventariov20.Model.InvBody | |
37 | -import com.focasoftware.deboinventariov20.Model.InvHead | |
33 | +import com.focasoftware.deboinventariov20.Model.* | |
38 | 34 | import com.focasoftware.deboinventariov20.R |
39 | 35 | import com.focasoftware.deboinventariov20.UI.Utils.NoEncontradoSimple |
36 | +import com.focasoftware.deboinventariov20.UI.Utils.ObtenerFechaActual | |
40 | 37 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera |
41 | 38 | import com.focasoftware.deboinventariov20.UI.inventario.viewModel.InventarioViewModel |
42 | 39 | import kotlinx.android.synthetic.main.fragment_inventario.* |
... | ... | @@ -45,8 +42,9 @@ import kotlinx.android.synthetic.main.login_dialog.view.* |
45 | 42 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar |
46 | 43 | import kotlinx.coroutines.* |
47 | 44 | import kotlinx.coroutines.Dispatchers.IO |
48 | -import java.time.LocalDateTime | |
49 | -import java.time.format.DateTimeFormatter | |
45 | +import retrofit2.Call | |
46 | +import retrofit2.Callback | |
47 | +import retrofit2.Response | |
50 | 48 | import java.util.* |
51 | 49 | |
52 | 50 | class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickListener { |
... | ... | @@ -99,20 +97,32 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
99 | 97 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) |
100 | 98 | rcInventarios = v.findViewById(R.id.rcInventarios) |
101 | 99 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) |
100 | + val descArea: String = if (!SerchArea()) "Ventas" else "Deposito" | |
102 | 101 | |
103 | 102 | if ((inventarioViewModel as InventarioViewModel).InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO |
104 | 103 | GlobalScope.launch(Dispatchers.Main) { |
105 | 104 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO |
106 | 105 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = AppDb.getAppDb(requireActivity())?.InvHeadDAO()?.findLastInv()?.plus(1) ?: 1 |
107 | 106 | //TODO: CREAMOS EL INVENTARIO EN LA CABECERA DEL INVENTARIO |
108 | - invHead = InvHead((inventarioViewModel as InventarioViewModel).InventarioNuevo, if (!SerchArea()) "Ventas" else "Deposito", 1, ObtenerFechaActual(), ObtenerFechaActual(), 0L, SerchArea(), AjusteProductos(), ProdNoCont()) | |
107 | + invHead = InvHead( | |
108 | + (inventarioViewModel as InventarioViewModel).InventarioNuevo, | |
109 | + if (!SerchArea()) "Ventas" else "Deposito", | |
110 | + 1, | |
111 | + ObtenerFechaActual(), | |
112 | + ObtenerFechaActual(), | |
113 | + 0L, | |
114 | + SerchArea(), | |
115 | + AjusteProductos(), | |
116 | + ProdNoCont() | |
117 | + ) | |
109 | 118 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.insertInvHead(invHead) |
110 | - tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo}" | |
119 | + | |
120 | + tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo} "+descArea | |
111 | 121 | } |
112 | 122 | } else {// TODO (SI VENGO DE FRAGMENT DESCRIPCION) |
113 | 123 | listArticulos.clear() |
114 | - CargarDeBdInventario((inventarioViewModel as InventarioViewModel).InventarioNuevo) | |
115 | - tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo}" | |
124 | + cargarDeBdInventario((inventarioViewModel as InventarioViewModel).InventarioNuevo) | |
125 | + tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo} "+ descArea | |
116 | 126 | } |
117 | 127 | |
118 | 128 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> |
... | ... | @@ -147,9 +157,11 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
147 | 157 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
148 | 158 | // fCant += 1F |
149 | 159 | //TODO ACTUALIZO LA CANTIDAD EN LA BD |
150 | - updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), | |
160 | + updateCantidad( | |
161 | + listArticulos[indiceDelArtEncontrado].sector.toString(), | |
151 | 162 | listArticulos[indiceDelArtEncontrado].codigo.toString(), |
152 | - listArticulos[indiceDelArtEncontrado].cantTomada + 1) | |
163 | + listArticulos[indiceDelArtEncontrado].cantTomada + 1 | |
164 | + ) | |
153 | 165 | //TODO ACTUALIZO LA CANTIDAD EN EL RV |
154 | 166 | listArticulos[indiceDelArtEncontrado].cantTomada = listArticulos[indiceDelArtEncontrado].cantTomada + 1 |
155 | 167 | viewAdapter.notifyDataSetChanged() |
... | ... | @@ -160,7 +172,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
160 | 172 | } else if (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD |
161 | 173 | //TODO BUSCO EN BASE DE DATOS |
162 | 174 | val artEncontrado = buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
163 | - ContinuarCargaCB(artEncontrado)//TODO SE MANDA CERO POR QUE ES UN ARTICULO ESCANEADO NUEVO PARA QUE SEA COMPATIBLE | |
175 | + continuarCargaCB(artEncontrado)//TODO SE MANDA CERO POR QUE ES UN ARTICULO ESCANEADO NUEVO PARA QUE SEA COMPATIBLE | |
164 | 176 | } |
165 | 177 | tCodigoBarras.focusable = View.FOCUSABLE |
166 | 178 | tCodigoBarras.setText("") |
... | ... | @@ -204,7 +216,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
204 | 216 | // (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD |
205 | 217 | GlobalScope.launch(Dispatchers.Main) { |
206 | 218 | val artEncontrado = buscarDescEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
207 | - ContinuarCargaDesc(artEncontrado as ArrayList<Articles>) | |
219 | + continuarCargaDesc(artEncontrado as ArrayList<Articles>) | |
208 | 220 | } |
209 | 221 | |
210 | 222 | iBusquedaPor = 0 |
... | ... | @@ -290,14 +302,14 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
290 | 302 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
291 | 303 | // } |
292 | 304 | // } else if (indiceDelArtEncontrado == -1) { |
293 | - // no lo encontro en el RV, lo va a buscar en al BD | |
305 | + // no lo encontro en el RV, lo va a buscar en al BD | |
294 | 306 | |
295 | - GlobalScope.launch(Dispatchers.Main) { | |
296 | - //TODO BUSCO EN BASE DE DATOS | |
297 | - val artEncontrado = buscarCodiogoOriEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | |
298 | - ContinuarCargaCodigoOri(artEncontrado ) | |
299 | - } | |
300 | - iBusquedaPor = 0 | |
307 | + GlobalScope.launch(Dispatchers.Main) { | |
308 | + //TODO BUSCO EN BASE DE DATOS | |
309 | + val artEncontrado = buscarCodiogoOriEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | |
310 | + continuarCargaCodigoOri(artEncontrado) | |
311 | + } | |
312 | + iBusquedaPor = 0 | |
301 | 313 | // } |
302 | 314 | // } |
303 | 315 | return@setOnKeyListener true |
... | ... | @@ -320,7 +332,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
320 | 332 | btnBorrarInv.setOnClickListener { |
321 | 333 | AlertDialog.Builder(requireContext()).setTitle("Eliminaciรณn de Inventarios").setMessage("ยฟConfirma que desea eliminar el inventario?") |
322 | 334 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> |
323 | - BorrarInvActual() | |
335 | + borrarInvActual() | |
324 | 336 | Toast.makeText(requireContext(), "El inventario $(inventarioViewModel as InventarioViewModel).InventarioNuevo fue Borrado", Toast.LENGTH_LONG).show() |
325 | 337 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
326 | 338 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 |
... | ... | @@ -333,7 +345,8 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
333 | 345 | btnExportarInv.setOnClickListener { |
334 | 346 | AlertDialog.Builder(requireContext()).setTitle(R.string.sTituloExportar).setMessage(R.string.sMensajeExportar) |
335 | 347 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> |
336 | - BorrarInvActual() | |
348 | + exportarInventario(InventarioNuevo) | |
349 | + borrarInvActual() | |
337 | 350 | Toast.makeText(requireContext(), "El inventario $(inventarioViewModel as InventarioViewModel).InventarioNuevo fue Exportado al Servidor", Toast.LENGTH_LONG).show() |
338 | 351 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
339 | 352 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 |
... | ... | @@ -372,20 +385,81 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
372 | 385 | } |
373 | 386 | } |
374 | 387 | |
375 | - private fun BorrarInvActual() { | |
388 | + private fun exportarInventario(inventario: Int) { | |
389 | + GlobalScope.launch(Dispatchers.Main) { | |
390 | + val aEnviar: MutableList<InvToSend>?=null | |
391 | + val datosCabecera = foundInvHeadDB(inventario) | |
392 | + val datosCuerpo=foundInvBodyBD(inventario) | |
393 | + | |
394 | + for (cuerpo in datosCuerpo){ | |
395 | + val temp=InvToSend( | |
396 | + datosCabecera.fechaInicio, | |
397 | + datosCabecera.fechaFinal, | |
398 | + if (datosCabecera.lugar!!) 1 else 0, | |
399 | + cuerpo.sector, | |
400 | + cuerpo.codigo, | |
401 | + cuerpo.descripcion, | |
402 | + cuerpo.cantTomada, | |
403 | + cuerpo.fechaInicio, | |
404 | + cuerpo.fechaFinal) | |
405 | + aEnviar!!.add (temp) | |
406 | + } | |
407 | + exportarInventario(aEnviar!!) | |
408 | + } | |
409 | + | |
410 | + | |
411 | + } | |
412 | + private fun exportarInventario(aEnviar:List<InvToSend> ){ | |
413 | + | |
414 | + val call: Call<Void?>? = WebService | |
415 | + .getInstance() | |
416 | + ?.createService(WebServiceApi::class.java) | |
417 | + ?.inventarioToSend(aEnviar) | |
418 | + | |
419 | + call!!.enqueue(object : Callback<Void?> { | |
420 | + override fun onResponse(call: Call<Void?>?, response: Response<Void?>) { | |
421 | + if (response.code() == 201) { | |
422 | + } | |
423 | + if (response.code() == 409) { | |
424 | + } | |
425 | + } | |
426 | + | |
427 | + override fun onFailure(call: Call<Void?>?, t: Throwable?) {} | |
428 | + }) | |
429 | + | |
430 | + } | |
431 | + | |
432 | + private suspend fun foundInvHeadDB(inv: Int): InvHead { | |
433 | + var busqueda: InvHead | |
434 | + return GlobalScope.async(IO) { | |
435 | + busqueda = AppDb.getAppDb(requireContext())!!.InvHeadDAO()!!.foundInvHead(inv) | |
436 | + return@async busqueda | |
437 | + }.await() | |
438 | + } | |
439 | + | |
440 | + private suspend fun foundInvBodyBD(inv: Int): List<InvBody> { | |
441 | + var busqueda: List<InvBody> | |
442 | + return GlobalScope.async(IO) { | |
443 | + busqueda = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.fetchAllInvBody(inv) | |
444 | + return@async busqueda | |
445 | + }.await() | |
446 | + } | |
447 | + | |
448 | + private fun borrarInvActual() { | |
376 | 449 | lifecycleScope.launch { |
377 | 450 | withContext(Dispatchers.IO) { |
378 | - AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.deleteinvHead((inventarioViewModel as InventarioViewModel).InventarioNuevo.toLong()) | |
379 | - AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.deleteInvBody((inventarioViewModel as InventarioViewModel).InventarioNuevo.toLong()) | |
451 | + AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.deleteinvHead((inventarioViewModel as InventarioViewModel).InventarioNuevo) | |
452 | + AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.deleteInvBody((inventarioViewModel as InventarioViewModel).InventarioNuevo) | |
380 | 453 | } |
381 | 454 | } |
382 | 455 | } |
383 | 456 | |
384 | - private fun CargarDeBdInventario(ultimoInv: Int) { | |
457 | + private fun cargarDeBdInventario(ultimoInv: Int) { | |
385 | 458 | GlobalScope.launch(Dispatchers.Main) { |
386 | 459 | val invbody = cargarInventario(ultimoInv) |
387 | 460 | for ((i, _) in invbody!!.withIndex()) { |
388 | - val art = Articles(invbody[i].sector, | |
461 | + val art = Articles( | |
462 | + invbody[i].sector, | |
389 | 463 | invbody[i].codigo, |
390 | 464 | invbody[i].descripcion, |
391 | 465 | invbody[i].codBar, |
... | ... | @@ -403,7 +477,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
403 | 477 | } |
404 | 478 | } |
405 | 479 | |
406 | - private fun ContinuarCargaCodigoOri(artAcargar:List<Articles>) { | |
480 | + private fun continuarCargaCodigoOri(artAcargar: List<Articles>) { | |
407 | 481 | |
408 | 482 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD |
409 | 483 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
... | ... | @@ -424,7 +498,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
424 | 498 | etCodigoBarras.selectAll() |
425 | 499 | } |
426 | 500 | |
427 | - private fun ContinuarCargaDesc(artAcargar: ArrayList<Articles>) { | |
501 | + private fun continuarCargaDesc(artAcargar: ArrayList<Articles>) { | |
428 | 502 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS |
429 | 503 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV |
430 | 504 | |
... | ... | @@ -505,7 +579,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
505 | 579 | etCodigoBarras.selectAll() |
506 | 580 | } |
507 | 581 | |
508 | - private fun ContinuarCargaCB(artAcargar: Articles?) { | |
582 | + private fun continuarCargaCB(artAcargar: Articles?) { | |
509 | 583 | |
510 | 584 | if (artAcargar != null) {// TODO: Si lo encuentra en la BD |
511 | 585 | if (swSumaUno!!.isChecked) {//TODO: SI ESTA +1, PONE CANTIDAD 1 |
... | ... | @@ -515,7 +589,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
515 | 589 | cargarRecicler(artAcargar, fCant) |
516 | 590 | } else {//TODO: SI NO ESTA +1 PREGUNTA CANTIDAD |
517 | 591 | |
518 | - DialogingresarCantidad(requireContext(), artAcargar) | |
592 | + dialogingresarCantidad(requireContext(), artAcargar) | |
519 | 593 | |
520 | 594 | } |
521 | 595 | } else {// TODO si no lo encuentra en la BD |
... | ... | @@ -527,7 +601,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
527 | 601 | etCodigoBarras.selectAll() |
528 | 602 | } |
529 | 603 | |
530 | - fun DialogingresarCantidad(cnxt: Context, artAcargar: Articles?): Float { | |
604 | + fun dialogingresarCantidad(cnxt: Context, artAcargar: Articles?): Float { | |
531 | 605 | var cantidad = 0F |
532 | 606 | val mDialogView = LayoutInflater.from(cnxt).inflate(R.layout.ingresar_cantidad, null) |
533 | 607 | val mBuilder = AlertDialog.Builder(cnxt).setView(mDialogView).setCancelable(false) |
... | ... | @@ -603,9 +677,11 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
603 | 677 | if (mDialogView.tvResultado.text.isNotEmpty() || !mDialogView.tvResultado.text.isBlank()) { |
604 | 678 | mAlertDialog.dismiss() |
605 | 679 | listArticulos[indiceDelArtEncontrado].cantTomada = String.format("%.2f", mDialogView.tvResultado.text.toString().toFloat()).toFloat() |
606 | - updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), | |
680 | + updateCantidad( | |
681 | + listArticulos[indiceDelArtEncontrado].sector.toString(), | |
607 | 682 | listArticulos[indiceDelArtEncontrado].codigo.toString(), |
608 | - String.format("%.2f", mDialogView.tvResultado.text.toString().toFloat()).toFloat()) | |
683 | + String.format("%.2f", mDialogView.tvResultado.text.toString().toFloat()).toFloat() | |
684 | + ) | |
609 | 685 | |
610 | 686 | viewAdapter.notifyDataSetChanged() |
611 | 687 | } else if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { |
... | ... | @@ -627,7 +703,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
627 | 703 | suspend fun buscarCodiogoOriEnBD(CodOri: String): List<Articles> { |
628 | 704 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
629 | 705 | var busqueda: List<Articles> |
630 | - return GlobalScope.async(Dispatchers.IO) { | |
706 | + return GlobalScope.async(IO) { | |
631 | 707 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodOri(CodOri, SerchAreaInventario()) |
632 | 708 | return@async busqueda |
633 | 709 | }.await() |
... | ... | @@ -645,7 +721,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
645 | 721 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { |
646 | 722 | //TODO BUSQUEDA POR DESCRIPCION |
647 | 723 | var busqueda: List<Articles>? = null |
648 | - return GlobalScope.async(Dispatchers.IO) { | |
724 | + return GlobalScope.async(IO) { | |
649 | 725 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, SerchAreaInventario()) |
650 | 726 | return@async busqueda |
651 | 727 | }.await() |
... | ... | @@ -655,7 +731,7 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
655 | 731 | //TODO BUSQUEDA POR DESCRIPCION |
656 | 732 | var result: Int |
657 | 733 | return GlobalScope.async(IO) { |
658 | - result = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.deleteItemFromInvBody(sector.toLong(), codigo.toLong(), inventario.toLong()) | |
734 | + result = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.deleteItemFromInvBody(sector.toLong(), codigo.toLong(), inventario.toInt()) | |
659 | 735 | return@async result |
660 | 736 | }.await() |
661 | 737 | } |
... | ... | @@ -708,7 +784,8 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
708 | 784 | } |
709 | 785 | |
710 | 786 | private fun cargarArtEnBd(articulos: Articles, cant: String) { |
711 | - val body = InvBody((inventarioViewModel as InventarioViewModel).InventarioNuevo,// TODO PREPARO PARA MANDAR A CARGAR EN LA BD | |
787 | + val body = InvBody( | |
788 | + (inventarioViewModel as InventarioViewModel).InventarioNuevo,// TODO PREPARO PARA MANDAR A CARGAR EN LA BD | |
712 | 789 | articulos.sector, |
713 | 790 | articulos.codigo, |
714 | 791 | articulos.descripcion, |
... | ... | @@ -720,14 +797,23 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
720 | 797 | articulos.balanza, |
721 | 798 | articulos.depSn, |
722 | 799 | ObtenerFechaActual(), |
723 | - ObtenerFechaActual()) | |
800 | + ObtenerFechaActual() | |
801 | + ) | |
724 | 802 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS |
725 | 803 | } |
726 | 804 | |
727 | 805 | fun cargarRecicler(articulos: Articles, cant: Float) { |
728 | 806 | //TODO CARGO EN LE RV |
729 | - val item = ItemsRecycler(if (articulos.sector.toString().toInt()<9) "0${articulos.sector.toString()}" else articulos.sector.toString() | |
730 | - , articulos.codigo, articulos.descripcion, cant, articulos.codBar, articulos.codOrigen, articulos.balanza.toString(), articulos.de.toString()) | |
807 | + val item = ItemsRecycler( | |
808 | + if (articulos.sector.toString().toInt() < 9) "0${articulos.sector.toString()}" else articulos.sector.toString(), | |
809 | + articulos.codigo, | |
810 | + articulos.descripcion, | |
811 | + cant, | |
812 | + articulos.codBar, | |
813 | + articulos.codOrigen, | |
814 | + articulos.balanza.toString(), | |
815 | + articulos.de.toString() | |
816 | + ) | |
731 | 817 | listArticulos.add(item) |
732 | 818 | |
733 | 819 | viewAdapter = ProductosListAdapter(requireContext(), listArticulos, this) |
... | ... | @@ -745,7 +831,11 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
745 | 831 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { |
746 | 832 | |
747 | 833 | GlobalScope.launch(Dispatchers.Main) { |
748 | - borrarArticulo(listArticulos[viewHolder.adapterPosition].sector.toString(), listArticulos[viewHolder.adapterPosition].codigo.toString(), (inventarioViewModel as InventarioViewModel).InventarioNuevo.toString()) | |
834 | + borrarArticulo( | |
835 | + listArticulos[viewHolder.adapterPosition].sector.toString(), | |
836 | + listArticulos[viewHolder.adapterPosition].codigo.toString(), | |
837 | + (inventarioViewModel as InventarioViewModel).InventarioNuevo.toString() | |
838 | + ) | |
749 | 839 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) |
750 | 840 | viewAdapter.notifyDataSetChanged() |
751 | 841 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, false, requireContext()) |
... | ... | @@ -796,19 +886,11 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
796 | 886 | |
797 | 887 | suspend fun SerchAreaInventario(): Boolean { |
798 | 888 | return GlobalScope.async(IO) { |
799 | - return@async AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.fetchAreaInvH((inventarioViewModel as InventarioViewModel).InventarioNuevo.toLong()) | |
889 | + return@async AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.fetchAreaInvH((inventarioViewModel as InventarioViewModel).InventarioNuevo) | |
800 | 890 | }.await() |
801 | 891 | |
802 | 892 | } |
803 | 893 | |
804 | - fun ObtenerFechaActual(): String? { | |
805 | - //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | |
806 | - val current = LocalDateTime.now() | |
807 | - val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss") | |
808 | - val dFechaHora = current.format(formatter) | |
809 | - return dFechaHora.toString() | |
810 | - } | |
811 | - | |
812 | 894 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { |
813 | 895 | lifecycleScope.launch { |
814 | 896 | withContext(Dispatchers.IO) { |
... | ... | @@ -819,14 +901,14 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
819 | 901 | |
820 | 902 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { |
821 | 903 | lifecycleScope.launch { |
822 | - withContext(Dispatchers.IO) { | |
823 | - AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.UpdateInvBody(cantidad, sector.toLong(), codigo.toLong()) | |
904 | + withContext(IO) { | |
905 | + AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.updateInvBody(cantidad, sector.toLong(), codigo.toLong(), ObtenerFechaActual()) | |
824 | 906 | } |
825 | 907 | } |
826 | 908 | } |
827 | 909 | |
828 | 910 | suspend fun cargarInventario(inventario: Int): List<InvBody>? { |
829 | - return GlobalScope.async(Dispatchers.IO) { | |
911 | + return GlobalScope.async(IO) { | |
830 | 912 | return@async AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inventario) |
831 | 913 | }.await() |
832 | 914 | } |
... | ... | @@ -844,16 +926,13 @@ class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickList |
844 | 926 | } |
845 | 927 | |
846 | 928 | private val textWatcher = object : TextWatcher { |
847 | - override fun afterTextChanged(s: Editable?) { | |
848 | - } | |
849 | - | |
850 | - override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { | |
851 | - } | |
929 | + override fun afterTextChanged(s: Editable?) {} | |
930 | + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} | |
852 | 931 | |
853 | 932 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { |
854 | 933 | if(mDialogView.rbSumar.isChecked){ |
855 | 934 | // mDialogView.tvNuevaCantidad.isEnabled=false |
856 | - mDialogView.tvResultado.text=String.format("%.2f", mDialogView.tvNuevaCantidad.text.toString().toFloat()+ mDialogView.tvCantInicial.text.toString().toFloat()) | |
935 | + mDialogView.tvResultado.text=String.format("%.2f", mDialogView.tvNuevaCantidad.text.toString().toFloat() + mDialogView.tvCantInicial.text.toString().toFloat()) | |
857 | 936 | } |
858 | 937 | if(mDialogView.rbRestar.isChecked) { |
859 | 938 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
app/src/main/java/com/focasoftware/deboinventariov20/UI/inventario/ProductosListAdapter.kt
... | ... | @@ -21,7 +21,8 @@ class ProductosListAdapter(private val context: Context,private val productos: A |
21 | 21 | interface OnImageDotsClickListener { |
22 | 22 | fun onImageDotsClick(sector: String?,codigo: String?) |
23 | 23 | fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) |
24 | -} | |
24 | + | |
25 | + } | |
25 | 26 | |
26 | 27 | override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = ItemsViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false)) |
27 | 28 |
app/src/main/res/layout-xlarge/item_codigo_origen.xml
... | ... | @@ -45,14 +45,13 @@ |
45 | 45 | android:layout_width="wrap_content" |
46 | 46 | android:layout_height="match_parent" |
47 | 47 | android:layout_marginStart="5dp" |
48 | - android:layout_marginTop="10dp" | |
49 | 48 | android:text="9999" |
50 | 49 | android:textAppearance="@style/TextAppearance.AppCompat.Large" |
51 | 50 | android:textColorHint="@android:color/black" |
52 | 51 | android:textSize="@dimen/SubTitulos10" |
53 | 52 | android:textStyle="bold" |
54 | - app:layout_constraintStart_toEndOf="@+id/textView2" | |
55 | - app:layout_constraintTop_toBottomOf="@+id/tvDescripcion" /> | |
53 | + app:layout_constraintBaseline_toBaselineOf="@+id/textView2" | |
54 | + app:layout_constraintStart_toEndOf="@+id/textView2" /> | |
56 | 55 | |
57 | 56 | <TextView |
58 | 57 | android:id="@+id/tvCodigo" |