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
| 1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
| 2 | apply plugin: 'kotlin-android' | 2 | apply plugin: 'kotlin-android' |
| 3 | apply plugin: 'kotlin-android-extensions' | 3 | apply plugin: 'kotlin-android-extensions' |
| 4 | apply plugin: 'kotlin-kapt' | 4 | apply plugin: 'kotlin-kapt' |
| 5 | 5 | ||
| 6 | android { | 6 | android { |
| 7 | compileSdkVersion 30 | 7 | compileSdkVersion 30 |
| 8 | buildToolsVersion "29.0.3" | 8 | buildToolsVersion "29.0.3" |
| 9 | 9 | ||
| 10 | defaultConfig { | 10 | defaultConfig { |
| 11 | applicationId "com.focasoftware.deboinventariov20" | 11 | applicationId "com.focasoftware.deboinventariov20" |
| 12 | minSdkVersion 26 | 12 | minSdkVersion 26 |
| 13 | targetSdkVersion 30 | 13 | targetSdkVersion 30 |
| 14 | versionCode 1 | 14 | versionCode 1 |
| 15 | versionName "1.0" | 15 | versionName "1.0" |
| 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 17 | javaCompileOptions { | 17 | javaCompileOptions { |
| 18 | annotationProcessorOptions { | 18 | annotationProcessorOptions { |
| 19 | arguments = ["room.incremental":"true"] | 19 | arguments = ["room.incremental":"true"] |
| 20 | } | 20 | } |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | buildTypes { | 24 | buildTypes { |
| 25 | release { | 25 | release { |
| 26 | minifyEnabled false | 26 | minifyEnabled false |
| 27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 28 | } | 28 | } |
| 29 | } | 29 | } |
| 30 | compileOptions { | 30 | compileOptions { |
| 31 | coreLibraryDesugaringEnabled true | ||
| 31 | sourceCompatibility JavaVersion.VERSION_1_8 | 32 | sourceCompatibility JavaVersion.VERSION_1_8 |
| 32 | targetCompatibility JavaVersion.VERSION_1_8 | 33 | targetCompatibility JavaVersion.VERSION_1_8 |
| 33 | 34 | ||
| 34 | } | 35 | } |
| 35 | kotlinOptions { | 36 | kotlinOptions { |
| 36 | jvmTarget = '1.8' | 37 | jvmTarget = '1.8' |
| 37 | } | 38 | } |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 40 | dependencies { | 41 | dependencies { |
| 41 | implementation fileTree(dir: "libs", include: ["*.jar"]) | 42 | implementation fileTree(dir: "libs", include: ["*.jar"]) |
| 42 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | 43 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" |
| 43 | implementation 'androidx.core:core-ktx:1.3.1' | 44 | implementation 'androidx.core:core-ktx:1.3.1' |
| 44 | implementation 'androidx.appcompat:appcompat:1.2.0' | 45 | implementation 'androidx.appcompat:appcompat:1.2.0' |
| 45 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' | 46 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' |
| 46 | implementation 'com.google.android.material:material:1.2.1' | 47 | implementation 'com.google.android.material:material:1.2.1' |
| 47 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1' | 48 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1' |
| 48 | implementation 'androidx.navigation:navigation-fragment:2.3.0' | 49 | implementation 'androidx.navigation:navigation-fragment:2.3.0' |
| 49 | implementation 'androidx.navigation:navigation-ui:2.3.0' | 50 | implementation 'androidx.navigation:navigation-ui:2.3.0' |
| 50 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' | 51 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' |
| 51 | implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0' | 52 | implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0' |
| 52 | implementation 'androidx.navigation:navigation-ui-ktx:2.3.0' | 53 | implementation 'androidx.navigation:navigation-ui-ktx:2.3.0' |
| 53 | implementation 'androidx.recyclerview:recyclerview:1.1.0' | 54 | implementation 'androidx.recyclerview:recyclerview:1.1.0' |
| 54 | testImplementation 'junit:junit:4.13' | 55 | testImplementation 'junit:junit:4.13' |
| 55 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' | 56 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' |
| 56 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | 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 | //Room | 60 | //Room |
| 60 | implementation 'androidx.room:room-ktx:2.2.5' | 61 | implementation 'androidx.room:room-ktx:2.2.5' |
| 61 | implementation "androidx.room:room-runtime:2.2.5" | 62 | implementation "androidx.room:room-runtime:2.2.5" |
| 62 | debugImplementation 'com.idescout.sql:sqlscout-server:4.1' | 63 | debugImplementation 'com.idescout.sql:sqlscout-server:4.1' |
| 63 | kapt "androidx.room:room-compiler:2.2.5" | 64 | kapt "androidx.room:room-compiler:2.2.5" |
| 64 | // annotationProcessor 'androidx.room:room-compiler:2.2.5' | 65 | // annotationProcessor 'androidx.room:room-compiler:2.2.5' |
| 65 | 66 | ||
| 66 | //Retrofit | 67 | //Retrofit |
| 67 | implementation 'com.google.code.gson:gson:2.8.6' | 68 | implementation 'com.google.code.gson:gson:2.8.6' |
| 68 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' | 69 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' |
| 69 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' | 70 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' |
| 70 | implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1' | 71 | implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1' |
| 71 | 72 | ||
| 72 | //Gson library | 73 | //Gson library |
| 73 | implementation "com.google.code.gson:gson:2.8.6" | 74 | implementation "com.google.code.gson:gson:2.8.6" |
| 74 | 75 | ||
| 75 | // ViewModel and LiveData | 76 | // ViewModel and LiveData |
| 76 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' | 77 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' |
| 77 | kapt 'androidx.lifecycle:lifecycle-common-java8:2.2.0' | 78 | kapt 'androidx.lifecycle:lifecycle-common-java8:2.2.0' |
| 78 | releaseImplementation 'com.idescout.sql:sqlscout-server-noop:4.1' | 79 | releaseImplementation 'com.idescout.sql:sqlscout-server-noop:4.1' |
| 79 | } | 80 | } |
app/src/main/java/com/focasoftware/deboinventariov20/DB/DAO/ArticulosDAO.kt
| 1 | package com.focasoftware.deboinventariov20.DB.DAO | 1 | package com.focasoftware.deboinventariov20.DB.DAO |
| 2 | 2 | ||
| 3 | import androidx.room.Dao | 3 | import androidx.room.Dao |
| 4 | import androidx.room.Insert | 4 | import androidx.room.Insert |
| 5 | import androidx.room.OnConflictStrategy | 5 | import androidx.room.OnConflictStrategy |
| 6 | import androidx.room.Query | 6 | import androidx.room.Query |
| 7 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_ART | 7 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_ART |
| 8 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_B | 8 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_B |
| 9 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_H | 9 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_H |
| 10 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_SERV_INV | 10 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_SERV_INV |
| 11 | import com.focasoftware.deboinventariov20.Model.Articles | 11 | import com.focasoftware.deboinventariov20.Model.Articles |
| 12 | import com.focasoftware.deboinventariov20.Model.InvBody | 12 | import com.focasoftware.deboinventariov20.Model.InvBody |
| 13 | import com.focasoftware.deboinventariov20.Model.InvHead | 13 | import com.focasoftware.deboinventariov20.Model.InvHead |
| 14 | import com.focasoftware.deboinventariov20.Model.ServeInv | 14 | import com.focasoftware.deboinventariov20.Model.ServeInv |
| 15 | 15 | ||
| 16 | @Dao | 16 | @Dao |
| 17 | interface ArticulosDAO { | 17 | interface ArticulosDAO { |
| 18 | 18 | ||
| 19 | // TABLA ARTICULOS | 19 | // TABLA ARTICULOS |
| 20 | @Insert(onConflict = OnConflictStrategy.REPLACE) | 20 | @Insert(onConflict = OnConflictStrategy.REPLACE) |
| 21 | suspend fun insertArticulos(articulos: Articles?) | 21 | suspend fun insertArticulos(articulos: Articles?) |
| 22 | 22 | ||
| 23 | @Query("SELECT * FROM $TABLA_ART ORDER BY DETART DESC") | 23 | @Query("SELECT * FROM $TABLA_ART ORDER BY DETART DESC") |
| 24 | suspend fun findAllArticulos(): List<Articles> | 24 | suspend fun findAllArticulos(): List<Articles> |
| 25 | 25 | ||
| 26 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND DETART LIKE '%' || :description || '%' GROUP BY DETART ORDER BY DETART") | 26 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND DETART LIKE '%' || :description || '%' GROUP BY DETART ORDER BY DETART") |
| 27 | suspend fun findArticuloByDesc(description: String?, dep: Boolean): List<Articles> | 27 | suspend fun findArticuloByDesc(description: String?, dep: Boolean): List<Articles> |
| 28 | 28 | ||
| 29 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND TRIM(CODBAR) = :codBarra") | 29 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND TRIM(CODBAR) = :codBarra") |
| 30 | suspend fun findArticuloByCodBar(codBarra: String, dep: Boolean): Articles | 30 | suspend fun findArticuloByCodBar(codBarra: String, dep: Boolean): Articles |
| 31 | 31 | ||
| 32 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND TRIM(COO) LIKE :CodOrigen") | 32 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND TRIM(COO) LIKE :CodOrigen") |
| 33 | suspend fun findArticuloByCodOri(CodOrigen: String?, dep: Boolean): List<Articles> | 33 | suspend fun findArticuloByCodOri(CodOrigen: String?, dep: Boolean): List<Articles> |
| 34 | 34 | ||
| 35 | @Query("DELETE FROM $TABLA_ART") | 35 | @Query("DELETE FROM $TABLA_ART") |
| 36 | suspend fun deleteAllArticulos() | 36 | suspend fun deleteAllArticulos() |
| 37 | 37 | ||
| 38 | @Query("SELECT * FROM $TABLA_ART WHERE CODSEC=:sector AND CODART=:codigo") | 38 | @Query("SELECT * FROM $TABLA_ART WHERE CODSEC=:sector AND CODART=:codigo") |
| 39 | suspend fun fetchArticuloByCodSec(sector: String?, codigo: String?): Articles? | 39 | suspend fun fetchArticuloByCodSec(sector: String?, codigo: String?): Articles? |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | @Dao | 42 | @Dao |
| 43 | interface InvHeadDAO { | 43 | interface InvHeadDAO { |
| 44 | @Insert() | 44 | @Insert() |
| 45 | suspend fun insertInvHead(invHead: InvHead?) | 45 | suspend fun insertInvHead(invHead: InvHead?) |
| 46 | 46 | ||
| 47 | @Query("SELECT INV_NUM FROM $TABLA_INV_H ORDER BY INV_NUM DESC") | 47 | @Query("SELECT INV_NUM FROM $TABLA_INV_H ORDER BY INV_NUM DESC") |
| 48 | suspend fun findLastInv(): Int | 48 | suspend fun findLastInv(): Int |
| 49 | 49 | ||
| 50 | @Query("DELETE FROM $TABLA_INV_H") | 50 | @Query("DELETE FROM $TABLA_INV_H") |
| 51 | suspend fun deleteAllArticulos() | 51 | suspend fun deleteAllArticulos() |
| 52 | 52 | ||
| 53 | @Query("DELETE FROM $TABLA_INV_H WHERE INV_NUM=:inven") | 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 | @Query("SELECT * FROM $TABLA_INV_H ORDER BY INV_FEI") | 56 | @Query("SELECT * FROM $TABLA_INV_H ORDER BY INV_FEI") |
| 57 | suspend fun fetchAllInvHead(): List<InvHead> | 57 | suspend fun fetchAllInvHead(): List<InvHead> |
| 58 | 58 | ||
| 59 | @Query("SELECT INV_LUG FROM $TABLA_INV_H WHERE INV_NUM=:inven") | 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 | @Query("SELECT INV_PRODCONT FROM $TABLA_INV_H WHERE INV_NUM=:inven") | 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 | @Query("UPDATE $TABLA_INV_H SET INV_PRODCONT=:cant WHERE INV_NUM=:inven") | 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 | @Dao | 72 | @Dao |
| 70 | interface InvBodyDAO { | 73 | interface InvBodyDAO { |
| 71 | @Insert() | 74 | @Insert() |
| 72 | suspend fun insertInvBody(invBody: InvBody?) | 75 | suspend fun insertInvBody(invBody: InvBody?) |
| 73 | 76 | ||
| 74 | @Query("DELETE FROM $TABLA_INV_B") | 77 | @Query("DELETE FROM $TABLA_INV_B") |
| 75 | suspend fun deleteAllInvBody() | 78 | suspend fun deleteAllInvBody() |
| 76 | 79 | ||
| 77 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:inven") | 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") | 83 | @Query("UPDATE $TABLA_INV_B SET CANT=:cant , INV_FEF=:actFechaHora WHERE SEC=:sec AND COD=:cod") |
| 81 | suspend fun UpdateInvBody(cant: Float, sec: Long, cod: Long) | 84 | suspend fun updateInvBody(cant: Float, sec: Long, cod: Long, actFechaHora:String) |
| 82 | 85 | ||
| 83 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:inven ORDER BY INV_FEI DESC") | 86 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:inven ORDER BY INV_FEI DESC") |
| 84 | suspend fun fetchAllInvBody(inven: Int): List<InvBody> | 87 | suspend fun fetchAllInvBody(inven: Int): List<InvBody> |
| 85 | 88 | ||
| 86 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:numInventario AND SEC=:sector AND COD=:codigo") | 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 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:numInventario AND SEC=:sector AND COD=:codigo") | 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 | @Dao | 96 | @Dao |
| 94 | interface ServeInvDao { | 97 | interface ServeInvDao { |
| 95 | @Insert(onConflict = OnConflictStrategy.REPLACE) | 98 | @Insert(onConflict = OnConflictStrategy.REPLACE) |
| 96 | fun insertServer(servidor: ServeInv) | 99 | fun insertServer(servidor: ServeInv) |
| 97 | 100 | ||
| 98 | @Query("SELECT * FROM $TABLA_SERV_INV ORDER BY SER_NUM") | 101 | @Query("SELECT * FROM $TABLA_SERV_INV ORDER BY SER_NUM") |
| 99 | suspend fun fetchAllServers(): List<ServeInv> | 102 | suspend fun fetchAllServers(): List<ServeInv> |
| 100 | 103 | ||
| 101 | @Query("DELETE FROM $TABLA_SERV_INV WHERE SER_DESC LIKE :description AND SER_DIR LIKE :dir") | 104 | @Query("DELETE FROM $TABLA_SERV_INV WHERE SER_DESC LIKE :description AND SER_DIR LIKE :dir") |
| 102 | suspend fun deleteServer(description: String, dir: String) | 105 | suspend fun deleteServer(description: String, dir: String) |
| 103 | 106 | ||
| 104 | @Query("SELECT SER_NUM FROM $TABLA_SERV_INV ORDER BY SER_NUM DESC") | 107 | @Query("SELECT SER_NUM FROM $TABLA_SERV_INV ORDER BY SER_NUM DESC") |
| 105 | suspend fun findLastServer(): Int | 108 | suspend fun findLastServer(): Int |
| 106 | 109 | ||
| 107 | @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=0") | 110 | @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=0") |
| 108 | suspend fun UpdateServerPreInZero() | 111 | suspend fun UpdateServerPreInZero() |
| 109 | 112 | ||
| 110 | @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=1 WHERE SER_NUM = :numero") | 113 | @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=1 WHERE SER_NUM = :numero") |
| 111 | suspend fun UpdateServerPre(numero: Int) | 114 | suspend fun UpdateServerPre(numero: Int) |
| 112 | 115 | ||
| 113 | @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_PRE= 1") | 116 | @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_PRE= 1") |
| 114 | suspend fun fetchServerPreOne(): ServeInv | 117 | suspend fun fetchServerPreOne(): ServeInv |
| 115 | 118 | ||
| 116 | @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_NUM = :numero") | 119 | @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_NUM = :numero") |
| 117 | suspend fun fetchServer(numero: Int): ServeInv | 120 | suspend fun fetchServer(numero: Int): ServeInv |
| 118 | } | 121 | } |
app/src/main/java/com/focasoftware/deboinventariov20/Model/ProductosApi.kt
| 1 | package com.focasoftware.deboinventariov20.Model | File was deleted | |
| 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 | } |
app/src/main/java/com/focasoftware/deboinventariov20/Model/ProductosService.kt
| 1 | package com.focasoftware.deboinventariov20.Model | File was deleted | |
| 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 | //} |
app/src/main/java/com/focasoftware/deboinventariov20/Model/Tablas.kt
| 1 | package com.focasoftware.deboinventariov20.Model | 1 | package com.focasoftware.deboinventariov20.Model |
| 2 | 2 | ||
| 3 | import androidx.room.ColumnInfo | 3 | import androidx.room.ColumnInfo |
| 4 | import androidx.room.Entity | 4 | import androidx.room.Entity |
| 5 | import androidx.room.PrimaryKey | 5 | import androidx.room.PrimaryKey |
| 6 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_ART | 6 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_ART |
| 7 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_B | 7 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_B |
| 8 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_H | 8 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_H |
| 9 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_SERV_INV | 9 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_SERV_INV |
| 10 | import com.google.gson.annotations.SerializedName | 10 | import com.google.gson.annotations.SerializedName |
| 11 | import java.io.Serializable | 11 | import java.io.Serializable |
| 12 | 12 | ||
| 13 | //data class Productos(@SerializedName("SEC") var sector: String?, | 13 | //data class Productos(@SerializedName("SEC") var sector: String?, |
| 14 | // @SerializedName("COD") var codigo: String?, | 14 | // @SerializedName("COD") var codigo: String?, |
| 15 | // @SerializedName("DESC") var descripcion: String?, | 15 | // @SerializedName("DESC") var descripcion: String?, |
| 16 | // @SerializedName("CB") var codBar: String?, | 16 | // @SerializedName("CB") var codBar: String?, |
| 17 | // @SerializedName("CBC") var codOrigen: String?, | 17 | // @SerializedName("CBC") var codOrigen: String?, |
| 18 | // @SerializedName("PRE_VTA") var precio: String?, | 18 | // @SerializedName("PRE_VTA") var precio: String?, |
| 19 | // @SerializedName("PRE_COS") var costo: String?, | 19 | // @SerializedName("PRE_COS") var costo: String?, |
| 20 | // @SerializedName( "EV") var exiVenta: String?, | 20 | // @SerializedName( "EV") var exiVenta: String?, |
| 21 | // @SerializedName( "ED") var exiDeposito: String?, | 21 | // @SerializedName( "ED") var exiDeposito: String?, |
| 22 | // @SerializedName( "DE") var de: String?, | 22 | // @SerializedName( "DE") var de: String?, |
| 23 | // @SerializedName( "BAL") var balanza: Int?, | 23 | // @SerializedName( "BAL") var balanza: Int?, |
| 24 | // @SerializedName("DEPSN") var depSn: Int?, | 24 | // @SerializedName("DEPSN") var depSn: Int?, |
| 25 | // @SerializedName("FOTO") var imagen: String?) | 25 | // @SerializedName("FOTO") var imagen: String?) |
| 26 | data class Productos(@SerializedName("CODSEC") var sector: String?, | 26 | data class Productos(@SerializedName("CODSEC") var sector: String?, |
| 27 | @SerializedName("CODART") var codigo: String?, | 27 | @SerializedName("CODART") var codigo: String?, |
| 28 | @SerializedName("DETART") var descripcion: String?, | 28 | @SerializedName("DETART") var descripcion: String?, |
| 29 | @SerializedName("CODBAR") var codBar: String?, | 29 | @SerializedName("CODBAR") var codBar: String?, |
| 30 | @SerializedName("COO") var codOrigen: String?, | 30 | @SerializedName("COO") var codOrigen: String?, |
| 31 | @SerializedName("PREVEN") var precio: String?, | 31 | @SerializedName("PREVEN") var precio: String?, |
| 32 | @SerializedName("COSTO") var costo: String?, | 32 | @SerializedName("COSTO") var costo: String?, |
| 33 | @SerializedName( "EXIVTA") var exiVenta: String?, | 33 | @SerializedName( "EXIVTA") var exiVenta: String?, |
| 34 | @SerializedName( "EXIDEP") var exiDeposito: String?, | 34 | @SerializedName( "EXIDEP") var exiDeposito: String?, |
| 35 | @SerializedName( "DVE") var de: String?, | 35 | @SerializedName( "DVE") var de: String?, |
| 36 | @SerializedName( "UNIVEN") var balanza: Int?, | 36 | @SerializedName( "UNIVEN") var balanza: Int?, |
| 37 | @SerializedName("DEPSN") var depSn: Boolean?, | 37 | @SerializedName("DEPSN") var depSn: Boolean?, |
| 38 | @SerializedName("FOTO") var imagen: String?) | 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 | //@Entity(tableName = TABLA_ART) | 49 | //@Entity(tableName = TABLA_ART) |
| 40 | //data class Articles(@ColumnInfo(name = "SEC") var sector: String?, | 50 | //data class Articles(@ColumnInfo(name = "SEC") var sector: String?, |
| 41 | // @ColumnInfo(name = "COD") var codigo: String?, | 51 | // @ColumnInfo(name = "COD") var codigo: String?, |
| 42 | // @ColumnInfo(name = "DES") var descripcion: String?, | 52 | // @ColumnInfo(name = "DES") var descripcion: String?, |
| 43 | // @ColumnInfo(name = "CB") var codBar: String?, | 53 | // @ColumnInfo(name = "CB") var codBar: String?, |
| 44 | // @ColumnInfo(name = "CBC") var codOrigen: String?, | 54 | // @ColumnInfo(name = "CBC") var codOrigen: String?, |
| 45 | // @ColumnInfo(name = "PRE_VTA") var precio: String?, | 55 | // @ColumnInfo(name = "PRE_VTA") var precio: String?, |
| 46 | // @ColumnInfo(name = "PRE_COS") var costo: String?, | 56 | // @ColumnInfo(name = "PRE_COS") var costo: String?, |
| 47 | // @ColumnInfo(name = "EV") var exiVenta: String?, | 57 | // @ColumnInfo(name = "EV") var exiVenta: String?, |
| 48 | // @ColumnInfo(name = "ED") var exiDeposito: String?, | 58 | // @ColumnInfo(name = "ED") var exiDeposito: String?, |
| 49 | // @ColumnInfo(name = "DE") var de: String?, | 59 | // @ColumnInfo(name = "DE") var de: String?, |
| 50 | // @ColumnInfo(name = "BAL") var balanza: Int?, | 60 | // @ColumnInfo(name = "BAL") var balanza: Int?, |
| 51 | // @ColumnInfo(name = "DEPSN") var depSn: Int?, | 61 | // @ColumnInfo(name = "DEPSN") var depSn: Int?, |
| 52 | // @ColumnInfo(name = "FOTO") var imagen: String?) : Serializable { | 62 | // @ColumnInfo(name = "FOTO") var imagen: String?) : Serializable { |
| 53 | // @PrimaryKey(autoGenerate = true) | 63 | // @PrimaryKey(autoGenerate = true) |
| 54 | // @ColumnInfo(name = "id") | 64 | // @ColumnInfo(name = "id") |
| 55 | // var id: Long = 0 | 65 | // var id: Long = 0 |
| 56 | //} | 66 | //} |
| 57 | @Entity(tableName = TABLA_ART) | 67 | @Entity(tableName = TABLA_ART) |
| 58 | data class Articles(@ColumnInfo(name = "CODSEC") var sector: String?, | 68 | data class Articles(@ColumnInfo(name = "CODSEC") var sector: String?, |
| 59 | @ColumnInfo(name = "CODART") var codigo: String?, | 69 | @ColumnInfo(name = "CODART") var codigo: String?, |
| 60 | @ColumnInfo(name = "DETART") var descripcion: String?, | 70 | @ColumnInfo(name = "DETART") var descripcion: String?, |
| 61 | @ColumnInfo(name = "CODBAR") var codBar: String?, | 71 | @ColumnInfo(name = "CODBAR") var codBar: String?, |
| 62 | @ColumnInfo(name = "COO") var codOrigen: String?, | 72 | @ColumnInfo(name = "COO") var codOrigen: String?, |
| 63 | @ColumnInfo(name = "PREVEN") var precio: String?, | 73 | @ColumnInfo(name = "PREVEN") var precio: String?, |
| 64 | @ColumnInfo(name = "COSTO") var costo: String?, | 74 | @ColumnInfo(name = "COSTO") var costo: String?, |
| 65 | @ColumnInfo(name = "EXIVTA") var exiVenta: String?, | 75 | @ColumnInfo(name = "EXIVTA") var exiVenta: String?, |
| 66 | @ColumnInfo(name = "EXIDEP") var exiDeposito: String?, | 76 | @ColumnInfo(name = "EXIDEP") var exiDeposito: String?, |
| 67 | @ColumnInfo(name = "DVE") var de: String?, | 77 | @ColumnInfo(name = "DVE") var de: String?, |
| 68 | @ColumnInfo(name = "UNIVEN") var balanza: Int?, | 78 | @ColumnInfo(name = "UNIVEN") var balanza: Int?, |
| 69 | @ColumnInfo(name = "DEPSN") var depSn: Boolean?, | 79 | @ColumnInfo(name = "DEPSN") var depSn: Boolean?, |
| 70 | @ColumnInfo(name = "FOTO") var imagen: String?) : Serializable { | 80 | @ColumnInfo(name = "FOTO") var imagen: String?) : Serializable { |
| 71 | @PrimaryKey(autoGenerate = true) | 81 | @PrimaryKey(autoGenerate = true) |
| 72 | @ColumnInfo(name = "id") | 82 | @ColumnInfo(name = "id") |
| 73 | var id: Long = 0 | 83 | var id: Long = 0 |
| 74 | } | 84 | } |
| 75 | 85 | ||
| 76 | @Entity(tableName = TABLA_INV_H) | 86 | @Entity(tableName = TABLA_INV_H) |
| 77 | data class InvHead(@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "INV_NUM") var invNum: Int, | 87 | data class InvHead(@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "INV_NUM") var invNum: Int, |
| 78 | @ColumnInfo(name = "INV_DESC") var descripcion: String?, | 88 | @ColumnInfo(name = "INV_DESC") var descripcion: String?, |
| 79 | @ColumnInfo(name = "ESTADO") var estado: Int?, | 89 | @ColumnInfo(name = "ESTADO") var estado: Int?, |
| 80 | @ColumnInfo(name = "INV_FEI") var fechaInicio: String?, | 90 | @ColumnInfo(name = "INV_FEI") var fechaInicio: String?, |
| 81 | @ColumnInfo(name = "INV_FEF") var fechaFinal: String?, | 91 | @ColumnInfo(name = "INV_FEF") var fechaFinal: String?, |
| 82 | // productos contados en el inventario | 92 | // productos contados en el inventario |
| 83 | @ColumnInfo(name = "INV_PRODCONT") var prodContados: Long?, | 93 | @ColumnInfo(name = "INV_PRODCONT") var prodContados: Long?, |
| 84 | @ColumnInfo(name = "INV_LUG") var lugar: Boolean?, | 94 | @ColumnInfo(name = "INV_LUG") var lugar: Boolean?, |
| 85 | // Solo se ajustan los productos incluidos en el conteo=0 | 95 | // Solo se ajustan los productos incluidos en el conteo=0 |
| 86 | // Ajusta productos no incluidos en el conteo con stock en cero=1 | 96 | // Ajusta productos no incluidos en el conteo con stock en cero=1 |
| 87 | @ColumnInfo(name = "PRO_NO_CONTA") var stDesc: Int?, | 97 | @ColumnInfo(name = "PRO_NO_CONTA") var stDesc: Int?, |
| 88 | // Mostror stock en el sistema al momento de la descarga del maestro. | 98 | // Mostror stock en el sistema al momento de la descarga del maestro. |
| 89 | @ColumnInfo(name = "MOSTRAR_STOCK") var proNoCont: Int?) | 99 | @ColumnInfo(name = "MOSTRAR_STOCK") var proNoCont: Int?) |
| 90 | 100 | ||
| 91 | 101 | ||
| 92 | @Entity(tableName = TABLA_INV_B) | 102 | @Entity(tableName = TABLA_INV_B) |
| 93 | data class InvBody(@ColumnInfo(name = "INV_NUM") var invNum: Int, | 103 | data class InvBody(@ColumnInfo(name = "INV_NUM") var invNum: Int, |
| 94 | @ColumnInfo(name = "SEC") var sector: String?, | 104 | @ColumnInfo(name = "SEC") var sector: String?, |
| 95 | @ColumnInfo(name = "COD") var codigo: String?, | 105 | @ColumnInfo(name = "COD") var codigo: String?, |
| 96 | @ColumnInfo(name = "DES") var descripcion: String?, | 106 | @ColumnInfo(name = "DES") var descripcion: String?, |
| 97 | @ColumnInfo(name = "CANT") var cantTomada: String?, | 107 | @ColumnInfo(name = "CANT") var cantTomada: String?, |
| 98 | @ColumnInfo(name = "CB") var codBar: String?, | 108 | @ColumnInfo(name = "CB") var codBar: String?, |
| 99 | @ColumnInfo(name = "CBC") var codOrigen: String?, | 109 | @ColumnInfo(name = "CBC") var codOrigen: String?, |
| 100 | @ColumnInfo(name = "PRE_VTA") var precio: String?, | 110 | @ColumnInfo(name = "PRE_VTA") var precio: String?, |
| 101 | @ColumnInfo(name = "PRE_COS") var costo: String?, | 111 | @ColumnInfo(name = "PRE_COS") var costo: String?, |
| 102 | @ColumnInfo(name = "BAL") var balanza: Int?, | 112 | @ColumnInfo(name = "BAL") var balanza: Int?, |
| 103 | @ColumnInfo(name = "DSN") var depSn: Boolean?, | 113 | @ColumnInfo(name = "DSN") var depSn: Boolean?, |
| 104 | @ColumnInfo(name = "INV_FEI") var fechaInicio: String?, | 114 | @ColumnInfo(name = "INV_FEI") var fechaInicio: String?, |
| 105 | @ColumnInfo(name = "INV_FEF") var fechaFinal: String?) : Serializable { | 115 | @ColumnInfo(name = "INV_FEF") var fechaFinal: String?) : Serializable { |
| 106 | @PrimaryKey(autoGenerate = true) | 116 | @PrimaryKey(autoGenerate = true) |
| 107 | @ColumnInfo(name = "id") | 117 | @ColumnInfo(name = "id") |
| 108 | var id: Long = 0 | 118 | var id: Long = 0 |
| 109 | } | 119 | } |
| 110 | 120 | ||
| 111 | @Entity(tableName = TABLA_SERV_INV) | 121 | @Entity(tableName = TABLA_SERV_INV) |
| 112 | data class ServeInv( | 122 | data class ServeInv( |
| 113 | @ColumnInfo(name = "SER_DESC") var descripcion: String?, | 123 | @ColumnInfo(name = "SER_DESC") var descripcion: String?, |
| 114 | @ColumnInfo(name = "SER_DIR") var direccion: String?, | 124 | @ColumnInfo(name = "SER_DIR") var direccion: String?, |
| 115 | @ColumnInfo(name = "SER_PUERTO") var puerto: String?, | 125 | @ColumnInfo(name = "SER_PUERTO") var puerto: String?, |
| 116 | @ColumnInfo(name = "SER_PRE") var predeterminado: Int?): | 126 | @ColumnInfo(name = "SER_PRE") var predeterminado: Int?): |
| 117 | Serializable { @PrimaryKey(autoGenerate = true) | 127 | Serializable { @PrimaryKey(autoGenerate = true) |
| 118 | @ColumnInfo(name = "SER_NUM") | 128 | @ColumnInfo(name = "SER_NUM") |
| 119 | var servNum: Int=0 | 129 | var servNum: Int=0 |
| 120 | } | 130 | } |
| 121 | 131 | ||
| 122 | 132 | ||
| 123 | 133 |
app/src/main/java/com/focasoftware/deboinventariov20/Model/WebService.kt
| File was created | 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 | } | ||
| 72 |
app/src/main/java/com/focasoftware/deboinventariov20/Model/WebServiceApi.kt
| File was created | 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 | } |
app/src/main/java/com/focasoftware/deboinventariov20/UI/SplashActivity.kt
| 1 | package com.focasoftware.deboinventariov20.UI | 1 | package com.focasoftware.deboinventariov20.UI |
| 2 | 2 | ||
| 3 | import android.app.Activity | 3 | import android.app.Activity |
| 4 | import android.content.Intent | 4 | import android.content.Intent |
| 5 | import android.os.Bundle | 5 | import android.os.Bundle |
| 6 | import com.focasoftware.deboinventariov20.R | 6 | import com.focasoftware.deboinventariov20.R |
| 7 | 7 | ||
| 8 | class SplashActivity : Activity() { | 8 | class SplashActivity : Activity() { |
| 9 | 9 | ||
| 10 | override fun onCreate(savedInstanceState: Bundle?) { | 10 | override fun onCreate(savedInstanceState: Bundle?) { |
| 11 | super.onCreate(savedInstanceState) | 11 | super.onCreate(savedInstanceState) |
| 12 | setContentView(R.layout.activity_splash) | 12 | setContentView(R.layout.activity_splash) |
| 13 | //window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | 13 | //window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 14 | 14 | ||
| 15 | val bac = object : Thread(){ | 15 | val bac = object : Thread(){ |
| 16 | override fun run(){ | 16 | override fun run(){ |
| 17 | try { | 17 | try { |
| 18 | Thread.sleep(3000) | 18 | Thread.sleep(3) |
| 19 | val intent = Intent(baseContext, MainActivity:: class.java) | 19 | val intent = Intent(baseContext, MainActivity:: class.java) |
| 20 | startActivity(intent) | 20 | startActivity(intent) |
| 21 | finish() | 21 | finish() |
| 22 | } catch (e : Exception){ | 22 | } catch (e : Exception){ |
| 23 | e.printStackTrace() | 23 | e.printStackTrace() |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | bac.start() | 27 | bac.start() |
| 28 | } | 28 | } |
| 29 | } | 29 | } |
| 30 | 30 |
app/src/main/java/com/focasoftware/deboinventariov20/UI/Utils/Utils.kt
| 1 | package com.focasoftware.deboinventariov20.UI.Utils | 1 | package com.focasoftware.deboinventariov20.UI.Utils |
| 2 | 2 | ||
| 3 | import android.app.AlertDialog | 3 | import android.app.AlertDialog |
| 4 | import android.app.Dialog | 4 | import android.app.Dialog |
| 5 | import android.content.Context | 5 | import android.content.Context |
| 6 | import android.os.Bundle | 6 | import android.os.Bundle |
| 7 | import androidx.fragment.app.DialogFragment | 7 | import androidx.fragment.app.DialogFragment |
| 8 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 8 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
| 9 | import kotlinx.coroutines.Dispatchers | 9 | import kotlinx.coroutines.Dispatchers |
| 10 | import kotlinx.coroutines.GlobalScope | 10 | import kotlinx.coroutines.GlobalScope |
| 11 | import kotlinx.coroutines.async | 11 | import kotlinx.coroutines.async |
| 12 | import java.io.IOException | 12 | import java.io.IOException |
| 13 | import java.net.UnknownHostException | 13 | import java.net.UnknownHostException |
| 14 | import java.time.LocalDateTime | ||
| 15 | import java.time.format.DateTimeFormatter | ||
| 14 | 16 | ||
| 15 | fun modificarCantidadEnCabecera(inventarioActual: Int, b: Boolean, context: Context) { | 17 | fun modificarCantidadEnCabecera(inventarioActual: Int, b: Boolean, context: Context) { |
| 16 | GlobalScope.async(Dispatchers.IO) { | 18 | GlobalScope.async(Dispatchers.IO) { |
| 17 | var cantProductos = 0 | 19 | var cantProductos = 0 |
| 18 | cantProductos = | 20 | cantProductos = |
| 19 | AppDb.getAppDb(context)!!.InvHeadDAO()!!.consultaCantidadInvH(inventarioActual.toLong()) | 21 | AppDb.getAppDb(context)!!.InvHeadDAO()!!.consultaCantidadInvH(inventarioActual.toLong()) |
| 20 | if (b) { | 22 | if (b) { |
| 21 | AppDb.getAppDb(context)!!.InvHeadDAO()!! | 23 | AppDb.getAppDb(context)!!.InvHeadDAO()!! |
| 22 | .updateInvBody(inventarioActual.toLong(), cantProductos + 1) | 24 | .updateInvBody(inventarioActual.toLong(), cantProductos + 1) |
| 23 | } else { | 25 | } else { |
| 24 | AppDb.getAppDb(context)!!.InvHeadDAO()!! | 26 | AppDb.getAppDb(context)!!.InvHeadDAO()!! |
| 25 | .updateInvBody(inventarioActual.toLong(), cantProductos - 1) | 27 | .updateInvBody(inventarioActual.toLong(), cantProductos - 1) |
| 26 | } | 28 | } |
| 27 | } | 29 | } |
| 28 | } | 30 | } |
| 29 | 31 | ||
| 30 | open class AlertDialogBorrarInv : DialogFragment() { | 32 | open class AlertDialogBorrarInv : DialogFragment() { |
| 31 | 33 | ||
| 32 | interface OnBorrarInvClickListener { | 34 | interface OnBorrarInvClickListener { |
| 33 | fun onPositiveClick() | 35 | fun onPositiveClick() |
| 34 | fun onCancelClick() | 36 | fun onCancelClick() |
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 39 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
| 38 | return activity?.let { | 40 | return activity?.let { |
| 39 | val title = "Borrar Inventario" | 41 | val title = "Borrar Inventario" |
| 40 | val content = "¿Seguro que desea Borrar el inventario?" | 42 | val content = "¿Seguro que desea Borrar el inventario?" |
| 41 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 43 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
| 42 | builder.setTitle(title).setMessage(content) | 44 | builder.setTitle(title).setMessage(content) |
| 43 | 45 | ||
| 44 | .setPositiveButton(android.R.string.ok) { _, _ -> | 46 | .setPositiveButton(android.R.string.ok) { _, _ -> |
| 45 | val listener = activity as OnBorrarInvClickListener? | 47 | val listener = activity as OnBorrarInvClickListener? |
| 46 | listener!!.onPositiveClick() | 48 | listener!!.onPositiveClick() |
| 47 | } | 49 | } |
| 48 | .setNegativeButton(android.R.string.cancel) { _, _ -> | 50 | .setNegativeButton(android.R.string.cancel) { _, _ -> |
| 49 | val listener = activity as OnBorrarInvClickListener? | 51 | val listener = activity as OnBorrarInvClickListener? |
| 50 | listener!!.onCancelClick() | 52 | listener!!.onCancelClick() |
| 51 | } | 53 | } |
| 52 | return builder.create() | 54 | return builder.create() |
| 53 | } ?: throw IllegalStateException("Activity cannot be null") | 55 | } ?: throw IllegalStateException("Activity cannot be null") |
| 54 | } | 56 | } |
| 55 | } | 57 | } |
| 56 | 58 | ||
| 57 | class NoEncontradoSimple : DialogFragment() { | 59 | class NoEncontradoSimple : DialogFragment() { |
| 58 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 60 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
| 59 | return activity?.let { | 61 | return activity?.let { |
| 60 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 62 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
| 61 | builder.show() | 63 | builder.show() |
| 62 | val title = "" | 64 | val title = "" |
| 63 | val content = "¡El producto buscado NO fue encontrado!" | 65 | val content = "¡El producto buscado NO fue encontrado!" |
| 64 | 66 | ||
| 65 | builder.setTitle(title).setMessage(content) | 67 | builder.setTitle(title).setMessage(content) |
| 66 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 68 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
| 67 | return builder.create() | 69 | return builder.create() |
| 68 | } ?: throw IllegalStateException("Activity cannot be null") | 70 | } ?: throw IllegalStateException("Activity cannot be null") |
| 69 | } | 71 | } |
| 70 | } | 72 | } |
| 71 | 73 | ||
| 72 | class noServerConf : DialogFragment() { | 74 | class noServerConf : DialogFragment() { |
| 73 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 75 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
| 74 | return activity?.let { | 76 | return activity?.let { |
| 75 | val title = "" | 77 | val title = "" |
| 76 | val content = "¡Antes de importar debe configurar un servidor!" | 78 | val content = "¡Antes de importar debe configurar un servidor!" |
| 77 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 79 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
| 78 | builder.setTitle(title).setMessage(content) | 80 | builder.setTitle(title).setMessage(content) |
| 79 | .setPositiveButton(android.R.string.ok) { _, _ -> | 81 | .setPositiveButton(android.R.string.ok) { _, _ -> |
| 80 | activity?.onBackPressed() | 82 | activity?.onBackPressed() |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | return builder.create() | 85 | return builder.create() |
| 84 | } ?: throw IllegalStateException("Activity cannot be null") | 86 | } ?: throw IllegalStateException("Activity cannot be null") |
| 85 | } | 87 | } |
| 86 | } | 88 | } |
| 87 | 89 | ||
| 88 | fun isConnectedToThisServer(host: String): Boolean { | 90 | fun isConnectedToThisServer(host: String): Boolean { |
| 89 | 91 | ||
| 90 | val runtime = Runtime.getRuntime() | 92 | val runtime = Runtime.getRuntime() |
| 91 | try { | 93 | try { |
| 92 | val ipProcess = runtime.exec("/system/bin/ping -c 1 $host") | 94 | val ipProcess = runtime.exec("/system/bin/ping -c 1 $host") |
| 93 | val exitValue = ipProcess.waitFor() | 95 | val exitValue = ipProcess.waitFor() |
| 94 | ipProcess.destroy() | 96 | ipProcess.destroy() |
| 95 | return exitValue == 0 | 97 | return exitValue == 0 |
| 96 | } catch (e: UnknownHostException) { | 98 | } catch (e: UnknownHostException) { |
| 97 | e.printStackTrace() | 99 | e.printStackTrace() |
| 98 | } catch (e: IOException) { | 100 | } catch (e: IOException) { |
| 99 | e.printStackTrace() | 101 | e.printStackTrace() |
| 100 | } catch (e: InterruptedException) { | 102 | } catch (e: InterruptedException) { |
| 101 | e.printStackTrace() | 103 | e.printStackTrace() |
| 102 | } | 104 | } |
| 103 | 105 | ||
| 104 | return false | 106 | return false |
| 105 | } | 107 | } |
| 106 | class serverValido : DialogFragment() { | 108 | class serverValido : DialogFragment() { |
| 107 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 109 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
| 108 | return activity?.let { | 110 | return activity?.let { |
| 109 | val title = "" | 111 | val title = "" |
| 110 | val content = "¡La IP del servidor es correcta!" | 112 | val content = "¡La IP del servidor es correcta!" |
| 111 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 113 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
| 112 | builder.setTitle(title).setMessage(content) | 114 | builder.setTitle(title).setMessage(content) |
| 113 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 115 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
| 114 | return builder.create() | 116 | return builder.create() |
| 115 | } ?: throw IllegalStateException("Activity cannot be null") | 117 | } ?: throw IllegalStateException("Activity cannot be null") |
| 116 | } | 118 | } |
| 117 | } | 119 | } |
| 118 | class serverNoValido : DialogFragment() { | 120 | class serverNoValido : DialogFragment() { |
| 119 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 121 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
| 120 | return activity?.let { | 122 | return activity?.let { |
| 121 | val title = "" | 123 | val title = "" |
| 122 | val content = "¡La IP del servidor es Incorrecta! Verfique en la carga de Servidores." | 124 | val content = "¡La IP del servidor es Incorrecta! Verfique en la carga de Servidores." |
| 123 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 125 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
| 124 | builder.setTitle(title).setMessage(content) | 126 | builder.setTitle(title).setMessage(content) |
| 125 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 127 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
| 126 | return builder.create() | 128 | return builder.create() |
| 127 | } ?: throw IllegalStateException("Activity cannot be null") | 129 | } ?: throw IllegalStateException("Activity cannot be null") |
| 128 | } | 130 | } |
| 129 | } | 131 | } |
| 130 | class serverNoConf : DialogFragment() { | 132 | class serverNoConf : DialogFragment() { |
| 131 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 133 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
| 132 | return activity?.let { | 134 | return activity?.let { |
| 133 | val title = "Servidor no Valido" | 135 | val title = "Servidor no Valido" |
| 134 | val content = "!Debe configurar el Servidor en Configuraciones¡" | 136 | val content = "!Debe configurar el Servidor en Configuraciones¡" |
| 135 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 137 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
| 136 | builder.setTitle(title).setMessage(content) | 138 | builder.setTitle(title).setMessage(content) |
| 137 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 139 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
| 138 | return builder.create() | 140 | return builder.create() |
| 139 | } ?: throw IllegalStateException("Activity cannot be null") | 141 | } ?: throw IllegalStateException("Activity cannot be null") |
| 140 | } | 142 | } |
| 141 | } | ||
| 143 | } | ||
| 144 | fun ObtenerFechaActual(): String { | ||
| 145 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | ||
| 146 | val current = LocalDateTime.now() | ||
| 147 | val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss") | ||
| 148 | val dFechaHora = current.format(formatter) | ||
| 149 | return dFechaHora.toString() |
app/src/main/java/com/focasoftware/deboinventariov20/UI/actualizacionMaestros/ActuaMaestrosFragment.kt
| 1 | package com.focasoftware.deboinventariov20.UI.actualizacionMaestros | 1 | package com.focasoftware.deboinventariov20.UI.actualizacionMaestros |
| 2 | 2 | ||
| 3 | import android.os.Bundle | 3 | import android.os.Bundle |
| 4 | import android.view.LayoutInflater | 4 | import android.view.LayoutInflater |
| 5 | import android.view.View | 5 | import android.view.View |
| 6 | import android.view.ViewGroup | 6 | import android.view.ViewGroup |
| 7 | import android.widget.Button | 7 | import android.widget.Button |
| 8 | import android.widget.Toast | ||
| 9 | import androidx.fragment.app.Fragment | 8 | import androidx.fragment.app.Fragment |
| 9 | import androidx.lifecycle.lifecycleScope | ||
| 10 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 10 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
| 11 | import com.focasoftware.deboinventariov20.Model.Articles | 11 | import com.focasoftware.deboinventariov20.Model.Articles |
| 12 | import com.focasoftware.deboinventariov20.Model.ProductosService | 12 | import com.focasoftware.deboinventariov20.Model.Productos |
| 13 | import com.focasoftware.deboinventariov20.Model.ServeInv | 13 | import com.focasoftware.deboinventariov20.Model.ServeInv |
| 14 | import com.focasoftware.deboinventariov20.Model.WebService.getInstance | ||
| 15 | import com.focasoftware.deboinventariov20.Model.WebServiceApi | ||
| 14 | import com.focasoftware.deboinventariov20.R | 16 | import com.focasoftware.deboinventariov20.R |
| 15 | import com.focasoftware.deboinventariov20.UI.Utils.noServerConf | 17 | import com.focasoftware.deboinventariov20.UI.Utils.noServerConf |
| 16 | import com.focasoftware.deboinventariov20.UI.Utils.serverNoConf | 18 | import com.focasoftware.deboinventariov20.UI.Utils.serverNoConf |
| 17 | import com.focasoftware.deboinventariov20.UI.Utils.serverValido | ||
| 18 | import kotlinx.android.synthetic.main.fragment_actua_maestros.* | 19 | import kotlinx.android.synthetic.main.fragment_actua_maestros.* |
| 19 | import kotlinx.coroutines.* | 20 | import kotlinx.coroutines.* |
| 20 | import kotlinx.coroutines.Dispatchers.IO | 21 | import kotlinx.coroutines.Dispatchers.IO |
| 21 | import kotlinx.coroutines.Dispatchers.Main | 22 | import kotlinx.coroutines.Dispatchers.Main |
| 23 | import retrofit2.Call | ||
| 24 | import retrofit2.Callback | ||
| 25 | import retrofit2.Response | ||
| 22 | import java.net.SocketTimeoutException | 26 | import java.net.SocketTimeoutException |
| 23 | 27 | ||
| 24 | 28 | ||
| 25 | var BASE_URL = "" | 29 | var BASE_URL = "" |
| 26 | var serverPre:ServeInv?=null | 30 | var serverPre: ServeInv? = null |
| 31 | |||
| 27 | class ActuaMaestrosFragment : Fragment() { | 32 | class ActuaMaestrosFragment : Fragment() { |
| 28 | 33 | ||
| 29 | override fun onCreate(savedInstanceState: Bundle?) { | 34 | override fun onCreate(savedInstanceState: Bundle?) { |
| 30 | super.onCreate(savedInstanceState) | 35 | super.onCreate(savedInstanceState) |
| 31 | 36 | ||
| 32 | GlobalScope.launch(Main) { | 37 | GlobalScope.launch(Main) { |
| 33 | 38 | ||
| 34 | serverPre = fetchServerPreOne() | 39 | serverPre = fetchServerPreOne() |
| 35 | if (serverPre!=null) { | 40 | if (serverPre != null) { |
| 36 | btnConfirmarAct.isEnabled=true | 41 | btnConfirmarAct.isEnabled = true |
| 37 | if (serverPre!!.direccion.isNullOrEmpty()) { | 42 | if (serverPre!!.direccion.isNullOrEmpty()) { |
| 38 | val modalDialog = noServerConf() | 43 | val modalDialog = noServerConf() |
| 39 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") | 44 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
| 40 | } else { | 45 | } else { |
| 41 | BASE_URL = serverPre!!.direccion.toString() + ":" + serverPre!!.puerto.toString() + "/" | 46 | BASE_URL = serverPre!!.direccion.toString() + ":" + serverPre!!.puerto.toString() + "/" |
| 42 | tvServerConectado.text = "Conectado al servidor: ${serverPre!!.descripcion}" | 47 | tvServerConectado.text = "Conectado al servidor: ${serverPre!!.descripcion}" |
| 43 | } | 48 | } |
| 44 | }else{ | 49 | } else { |
| 45 | val modalDialog = serverNoConf() | 50 | val modalDialog = serverNoConf() |
| 46 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") | 51 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
| 47 | 52 | ||
| 48 | btnConfirmarAct.isEnabled=false | 53 | btnConfirmarAct.isEnabled = false |
| 49 | 54 | ||
| 50 | } | 55 | } |
| 51 | } | 56 | } |
| 52 | 57 | ||
| 53 | // mostrarArticulos() | 58 | // mostrarArticulos() |
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | private suspend fun fetchServerPreOne(): ServeInv? { | 61 | private suspend fun fetchServerPreOne(): ServeInv? { |
| 57 | return GlobalScope.async(IO) { | 62 | return GlobalScope.async(IO) { |
| 58 | return@async AppDb.getAppDb(requireActivity())!!.ServeInvDao()!!.fetchServerPreOne() | 63 | return@async AppDb.getAppDb(requireActivity())!!.ServeInvDao()!!.fetchServerPreOne() |
| 59 | }.await() | 64 | }.await() |
| 60 | } | 65 | } |
| 61 | 66 | ||
| 62 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 67 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
| 63 | // Inflate the layout for this fragment | 68 | // Inflate the layout for this fragment |
| 64 | val v = inflater.inflate(R.layout.fragment_actua_maestros, container, false) | 69 | val v = inflater.inflate(R.layout.fragment_actua_maestros, container, false) |
| 65 | val bConfirmarAct = v.findViewById<Button>(R.id.btnConfirmarAct) | 70 | val bConfirmarAct = v.findViewById<Button>(R.id.btnConfirmarAct) |
| 66 | 71 | ||
| 67 | bConfirmarAct.setOnClickListener { | 72 | bConfirmarAct.setOnClickListener { |
| 68 | loading_view.visibility = View.VISIBLE | 73 | loading_view.visibility = View.VISIBLE |
| 69 | countriesList.text = "Obteniendo artículos del servidor, aguarde por favor." | 74 | countriesList.text = "Obteniendo artículos del servidor, aguarde por favor." |
| 70 | GlobalScope.launch(Main) { | 75 | obtenerArticulos() |
| 71 | obtenerArticulos() | ||
| 72 | } | ||
| 73 | } | 76 | } |
| 74 | return v | 77 | return v |
| 75 | } | 78 | } |
| 76 | 79 | ||
| 77 | private suspend fun obtenerArticulos() { | 80 | private fun obtenerArticulos() { |
| 78 | 81 | val call = getInstance() | |
| 79 | val productosService = ProductosService.getProductosService() | 82 | ?.createService(WebServiceApi::class.java) |
| 83 | ?.getProductos() | ||
| 80 | var index: Long = 1 | 84 | var index: Long = 1 |
| 81 | withContext(IO) { | 85 | call!!.enqueue(object : Callback<List<Productos>> { |
| 82 | val job = CoroutineScope(IO).launch { | 86 | override fun onResponse(call: Call<List<Productos>>, response: Response<List<Productos>>) { |
| 83 | // TODO: BORRO TODO LOS ARTICULOS DE LA BASE PARA CARGARLOS DE NUEVO | 87 | if (response.code() == 200) { |
| 84 | AppDb.getAppDb(requireActivity())!!.ArticulosDAO()!!.deleteAllArticulos() | 88 | try { |
| 85 | try { | ||
| 86 | val response = productosService.getProductos() | ||
| 87 | if (response.isSuccessful) { | ||
| 88 | |||
| 89 | for (pro in response.body()!!) { | 89 | for (pro in response.body()!!) { |
| 90 | val artiAcargar = Articles( | 90 | val artiAcargar = Articles( |
| 91 | pro.sector, | 91 | pro.sector, |
| 92 | pro.codigo, | 92 | pro.codigo, |
| 93 | pro.descripcion, | 93 | pro.descripcion, |
| 94 | pro.codBar, | 94 | pro.codBar, |
| 95 | pro.codOrigen, | 95 | pro.codOrigen, |
| 96 | pro.precio, | 96 | pro.precio, |
| 97 | pro.costo, | 97 | pro.costo, |
| 98 | pro.exiVenta, | 98 | pro.exiVenta, |
| 99 | pro.exiDeposito, | 99 | pro.exiDeposito, |
| 100 | pro.de, | 100 | pro.de, |
| 101 | pro.balanza, | 101 | pro.balanza, |
| 102 | pro.depSn, | 102 | pro.depSn, |
| 103 | pro.imagen | 103 | pro.imagen |
| 104 | ) | 104 | ) |
| 105 | index += index | 105 | index += index |
| 106 | AppDb.getAppDb(requireActivity())!!.ArticulosDAO()!!.insertArticulos(artiAcargar) | 106 | insertarProducto(artiAcargar) |
| 107 | } | 107 | } |
| 108 | withContext(Main) { | 108 | countriesList.visibility = View.VISIBLE |
| 109 | countriesList.visibility = View.VISIBLE | 109 | countriesList.text = "¡Datos Importados Correctamente!" |
| 110 | countriesList.text = "¡Datos Importados Correctamente!" | 110 | loading_view.visibility = View.GONE |
| 111 | loading_view.visibility = View.GONE | 111 | } catch (e: SocketTimeoutException) { |
| 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) { | ||
| 122 | countriesList.visibility = View.VISIBLE | 112 | countriesList.visibility = View.VISIBLE |
| 123 | countriesList.text = "¡Sin conexión al Servidor!" | 113 | countriesList.text = "¡Sin conexión al Servidor!" |
| 124 | loading_view.visibility = View.GONE | 114 | loading_view.visibility = View.GONE |
| 125 | } | 115 | } |
| 126 | } | 116 | } |
| 127 | } | 117 | } |
| 128 | // if (job == null) { | 118 | |
| 129 | // withContext(Main) { | 119 | override fun onFailure(call: Call<List<Productos>>, t: Throwable) { |
| 130 | // countriesList.visibility = View.VISIBLE | 120 | countriesList.visibility = View.VISIBLE |
| 131 | // countriesList.text = "No se puedo realizar la conexión al Servidor" | 121 | countriesList.text = (t.message + "." + t.cause) |
| 132 | // loading_view.visibility = View.GONE | 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 | // withContext(Dispatchers.Main) { | 178 | // withContext(Dispatchers.Main) { |
| 139 | // if (response.isSuccessful) { | 179 | // if (response.isSuccessful) { |
| 140 | // val call = WebService | 180 | // val call = WebService |
| 141 | // .instance | 181 | // .instance |
| 142 | // ?.createService(WebServiceApi::class.java) | 182 | // ?.createService(WebServiceApi::class.java) |
| 143 | // ?.articulos | 183 | // ?.articulos |
| 144 | // call?.enqueue(object : Callback<List<productos?>?> { | 184 | // call?.enqueue(object : Callback<List<productos?>?> { |
| 145 | // override fun onResponse( | 185 | // override fun onResponse( |
| 146 | // call: Call<List<productos?>?>, | 186 | // call: Call<List<productos?>?>, |
| 147 | // response: Response<List<productos?>?> | 187 | // response: Response<List<productos?>?> |
| 148 | // ) { | 188 | // ) { |
| 149 | // if (response.code() == 200) { | 189 | // if (response.code() == 200) { |
| 150 | // for (i in response.body()!!.indices) { | 190 | // for (i in response.body()!!.indices) { |
| 151 | // //AppDb.getAppDb(requireActivity())!!.ArticulosDAO()?.insertArticulos(response.body()!![i]) | 191 | // //AppDb.getAppDb(requireActivity())!!.ArticulosDAO()?.insertArticulos(response.body()!![i]) |
| 152 | // cargarArticulos(2, 500, "sfas", "66666","2,2", "2,2", false, false, "") | 192 | // cargarArticulos(2, 500, "sfas", "66666","2,2", "2,2", false, false, "") |
| 153 | //// Log.d( | 193 | //// Log.d( |
| 154 | //// "TAG1", "Nombre Curso: " + response.body()!![i]?.sector | 194 | //// "TAG1", "Nombre Curso: " + response.body()!![i]?.sector |
| 155 | //// + "Codigo Profesor: " + response.body()!![i]?.descripcion | 195 | //// + "Codigo Profesor: " + response.body()!![i]?.descripcion |
| 156 | //// ) | 196 | //// ) |
| 157 | // mostrarArticulos() | 197 | // mostrarArticulos() |
| 158 | // } | 198 | // } |
| 159 | // } else if (response.code() == 404) { | 199 | // } else if (response.code() == 404) { |
| 160 | // Log.d("TAG1", "No hay cursos") | 200 | // Log.d("TAG1", "No hay cursos") |
| 161 | // } | 201 | // } |
| 162 | // | 202 | // |
| 163 | // } | 203 | // } |
| 164 | // | 204 | // |
| 165 | // override fun onFailure(call: Call<List<productos?>?>, t: Throwable) {} | 205 | // override fun onFailure(call: Call<List<productos?>?>, t: Throwable) {} |
| 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 | fun mostrarArticulos() { | 217 | fun mostrarArticulos() { |
| 170 | val Job = GlobalScope.launch { | 218 | val Job = GlobalScope.launch { |
| 171 | var listArticulos: List<Articles>? = null | 219 | var listArticulos: List<Articles>? = null |
app/src/main/java/com/focasoftware/deboinventariov20/UI/descripCorigenFragment/CodigoOriFragment.kt
| 1 | package com.focasoftware.deboinventariov20.UI.descripCorigenFragment | 1 | package com.focasoftware.deboinventariov20.UI.descripCorigenFragment |
| 2 | 2 | ||
| 3 | import android.app.AlertDialog | 3 | import android.app.AlertDialog |
| 4 | import android.content.Context | 4 | import android.content.Context |
| 5 | import android.content.SharedPreferences | 5 | import android.content.SharedPreferences |
| 6 | import android.graphics.Canvas | 6 | import android.graphics.Canvas |
| 7 | import android.graphics.Color | 7 | import android.graphics.Color |
| 8 | import android.graphics.drawable.ColorDrawable | 8 | import android.graphics.drawable.ColorDrawable |
| 9 | import android.os.Bundle | 9 | import android.os.Bundle |
| 10 | import android.text.Editable | 10 | import android.text.Editable |
| 11 | import android.text.InputType | 11 | import android.text.InputType |
| 12 | import android.text.TextWatcher | 12 | import android.text.TextWatcher |
| 13 | import androidx.fragment.app.Fragment | 13 | import androidx.fragment.app.Fragment |
| 14 | import android.view.LayoutInflater | 14 | import android.view.LayoutInflater |
| 15 | import android.view.View | 15 | import android.view.View |
| 16 | import android.view.ViewGroup | 16 | import android.view.ViewGroup |
| 17 | import android.view.WindowManager | 17 | import android.view.WindowManager |
| 18 | import android.view.inputmethod.InputMethodManager | 18 | import android.view.inputmethod.InputMethodManager |
| 19 | import androidx.fragment.app.FragmentActivity | 19 | import androidx.fragment.app.FragmentActivity |
| 20 | import androidx.lifecycle.lifecycleScope | 20 | import androidx.lifecycle.lifecycleScope |
| 21 | import androidx.navigation.NavController | 21 | import androidx.navigation.NavController |
| 22 | import androidx.navigation.Navigation | 22 | import androidx.navigation.Navigation |
| 23 | import androidx.recyclerview.widget.ItemTouchHelper | 23 | import androidx.recyclerview.widget.ItemTouchHelper |
| 24 | import androidx.recyclerview.widget.LinearLayoutManager | 24 | import androidx.recyclerview.widget.LinearLayoutManager |
| 25 | import androidx.recyclerview.widget.RecyclerView | 25 | import androidx.recyclerview.widget.RecyclerView |
| 26 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 26 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
| 27 | import com.focasoftware.deboinventariov20.Model.Articles | 27 | import com.focasoftware.deboinventariov20.Model.Articles |
| 28 | import com.focasoftware.deboinventariov20.Model.InvBody | 28 | import com.focasoftware.deboinventariov20.Model.InvBody |
| 29 | import com.focasoftware.deboinventariov20.R | 29 | import com.focasoftware.deboinventariov20.R |
| 30 | import com.focasoftware.deboinventariov20.UI.Utils.ObtenerFechaActual | ||
| 30 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera | 31 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera |
| 31 | import com.focasoftware.deboinventariov20.UI.inventario.InventarioFragment | ||
| 32 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* | 32 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* |
| 33 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.btnAceptar | 33 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.btnAceptar |
| 34 | import kotlinx.android.synthetic.main.login_dialog.view.* | 34 | import kotlinx.android.synthetic.main.login_dialog.view.* |
| 35 | import kotlinx.coroutines.* | 35 | import kotlinx.coroutines.* |
| 36 | 36 | ||
| 37 | // | 37 | // |
| 38 | class CodigoOriFragment : Fragment() { | 38 | class CodigoOriFragment : Fragment() { |
| 39 | 39 | ||
| 40 | private lateinit var artAcargar2: List<Articles> | 40 | private lateinit var artAcargar2: List<Articles> |
| 41 | private var listArticulos: List<Articles>? = null | 41 | private var listArticulos: List<Articles>? = null |
| 42 | lateinit var viewAdapter2: RecyclerView.Adapter<*> | 42 | lateinit var viewAdapter2: RecyclerView.Adapter<*> |
| 43 | private lateinit var viewManager2: RecyclerView.LayoutManager | 43 | private lateinit var viewManager2: RecyclerView.LayoutManager |
| 44 | private lateinit var rcCodigoOri: RecyclerView | 44 | private lateinit var rcCodigoOri: RecyclerView |
| 45 | private var swipeBackground: ColorDrawable = ColorDrawable(Color.YELLOW) | 45 | private var swipeBackground: ColorDrawable = ColorDrawable(Color.YELLOW) |
| 46 | private var cantidad = 0F | 46 | private var cantidad = 0F |
| 47 | private var numeroInventario = 0 | 47 | private var numeroInventario = 0 |
| 48 | lateinit var navController: NavController | 48 | lateinit var navController: NavController |
| 49 | lateinit var sharedPreferences: SharedPreferences | 49 | lateinit var sharedPreferences: SharedPreferences |
| 50 | private var artCargadoEnBD: InvBody? = null | 50 | private var artCargadoEnBD: InvBody? = null |
| 51 | lateinit var mDialogViewM: View | 51 | lateinit var mDialogViewM: View |
| 52 | 52 | ||
| 53 | override fun onCreate(savedInstanceState: Bundle?) { | 53 | override fun onCreate(savedInstanceState: Bundle?) { |
| 54 | super.onCreate(savedInstanceState) | 54 | super.onCreate(savedInstanceState) |
| 55 | 55 | ||
| 56 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 56 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
| 57 | arguments.apply { | 57 | arguments.apply { |
| 58 | artAcargar2 = requireArguments().getSerializable("ArrayDesc") as List<Articles> | 58 | artAcargar2 = requireArguments().getSerializable("ArrayDesc") as List<Articles> |
| 59 | numeroInventario = requireArguments().getInt("numeroInv") | 59 | numeroInventario = requireArguments().getInt("numeroInv") |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | } | 62 | } |
| 63 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 63 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
| 64 | super.onViewCreated(view, savedInstanceState) | 64 | super.onViewCreated(view, savedInstanceState) |
| 65 | navController = Navigation.findNavController(view) | 65 | navController = Navigation.findNavController(view) |
| 66 | showSoftKeyboard(view) | 66 | showSoftKeyboard(view) |
| 67 | } | 67 | } |
| 68 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 68 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
| 69 | val v = inflater.inflate(R.layout.fragment_codigo_ori, container, false) | 69 | val v = inflater.inflate(R.layout.fragment_codigo_ori, container, false) |
| 70 | rcCodigoOri = v.findViewById(R.id.rcCodigoOri) | 70 | rcCodigoOri = v.findViewById(R.id.rcCodigoOri) |
| 71 | 71 | ||
| 72 | IngresarRecicler(artAcargar2) | 72 | IngresarRecicler(artAcargar2) |
| 73 | showSoftKeyboard(v) | 73 | showSoftKeyboard(v) |
| 74 | // btnSalir.setOnClickListener { | 74 | // btnSalir.setOnClickListener { |
| 75 | // activity?.onBackPressed(); | 75 | // activity?.onBackPressed(); |
| 76 | //// VolverAinventario() | 76 | //// VolverAinventario() |
| 77 | // } | 77 | // } |
| 78 | return v | 78 | return v |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | private fun showSoftKeyboard(view: View) { | 81 | private fun showSoftKeyboard(view: View) { |
| 82 | if (view.requestFocus()) { | 82 | if (view.requestFocus()) { |
| 83 | val imm = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | 83 | val imm = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager |
| 84 | imm.showSoftInput(view, InputMethodManager.HIDE_IMPLICIT_ONLY) | 84 | imm.showSoftInput(view, InputMethodManager.HIDE_IMPLICIT_ONLY) |
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | fun IngresarRecicler(articulos: List<Articles>) { | 88 | fun IngresarRecicler(articulos: List<Articles>) { |
| 89 | 89 | ||
| 90 | viewAdapter2 = CodigoOrigenAdapter(requireContext(),articulos) | 90 | viewAdapter2 = CodigoOrigenAdapter(requireContext(),articulos) |
| 91 | viewManager2 = LinearLayoutManager(requireContext()) | 91 | viewManager2 = LinearLayoutManager(requireContext()) |
| 92 | 92 | ||
| 93 | rcCodigoOri.apply { | 93 | rcCodigoOri.apply { |
| 94 | adapter = viewAdapter2 | 94 | adapter = viewAdapter2 |
| 95 | layoutManager = viewManager2 | 95 | layoutManager = viewManager2 |
| 96 | } | 96 | } |
| 97 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) { | 97 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) { |
| 98 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { | 98 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { |
| 99 | return false | 99 | return false |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, position: Int) { | 102 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, position: Int) { |
| 103 | 103 | ||
| 104 | GlobalScope.launch(Dispatchers.Main) { | 104 | GlobalScope.launch(Dispatchers.Main) { |
| 105 | //TODO BUSCO EN BASE DE DATOS | 105 | //TODO BUSCO EN BASE DE DATOS |
| 106 | artCargadoEnBD = buscarCodigoDeboEnBD((viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)?.sector.toString(), | 106 | artCargadoEnBD = buscarCodigoDeboEnBD((viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)?.sector.toString(), |
| 107 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)?.codigo.toString(), | 107 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)?.codigo.toString(), |
| 108 | numeroInventario.toString()) | 108 | numeroInventario.toString()) |
| 109 | if (artCargadoEnBD == null) { | 109 | if (artCargadoEnBD == null) { |
| 110 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.ingresar_cantidad, null) | 110 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.ingresar_cantidad, null) |
| 111 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(false) | 111 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(false) |
| 112 | //TODO: DEPENDIENDO DEL TIPO DE ARTICULO PERMITER INGRESAR DECIMALES O NO | 112 | //TODO: DEPENDIENDO DEL TIPO DE ARTICULO PERMITER INGRESAR DECIMALES O NO |
| 113 | if ((viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza==1 || (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza==3 || (viewAdapter2 as CodigoOrigenAdapter).items2?.get( | 113 | if ((viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza==1 || (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza==3 || (viewAdapter2 as CodigoOrigenAdapter).items2?.get( |
| 114 | viewHolder.layoutPosition)!!.balanza==7) | 114 | viewHolder.layoutPosition)!!.balanza==7) |
| 115 | mDialogView.etCantidad.inputType= InputType.TYPE_CLASS_NUMBER | 115 | mDialogView.etCantidad.inputType= InputType.TYPE_CLASS_NUMBER |
| 116 | 116 | ||
| 117 | mDialogView.tvTitulo.text = "${(viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.descripcion}" | 117 | mDialogView.tvTitulo.text = "${(viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.descripcion}" |
| 118 | val mAlertDialog = mBuilder.show() | 118 | val mAlertDialog = mBuilder.show() |
| 119 | mDialogView.etCantidad.requestFocus() | 119 | mDialogView.etCantidad.requestFocus() |
| 120 | mAlertDialog.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 120 | mAlertDialog.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
| 121 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 121 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
| 122 | mDialogView.btnAceptar.setOnClickListener { | 122 | mDialogView.btnAceptar.setOnClickListener { |
| 123 | if (mDialogView.etCantidad.text.isNullOrEmpty()) { | 123 | if (mDialogView.etCantidad.text.isNullOrEmpty()) { |
| 124 | mDialogView.etCantidad.error = "No vacio" | 124 | mDialogView.etCantidad.error = "No vacio" |
| 125 | mDialogView.etCantidad.requestFocus() | 125 | mDialogView.etCantidad.requestFocus() |
| 126 | mDialogView.etCantidad.hint = "Ingrese un valor" | 126 | mDialogView.etCantidad.hint = "Ingrese un valor" |
| 127 | } else if (!mDialogView.etCantidad.text.isNullOrEmpty()) { | 127 | } else if (!mDialogView.etCantidad.text.isNullOrEmpty()) { |
| 128 | cantidad = mDialogView.etCantidad.text.toString().toFloat() | 128 | cantidad = mDialogView.etCantidad.text.toString().toFloat() |
| 129 | val body = InvBody(numeroInventario, | 129 | val body = InvBody(numeroInventario, |
| 130 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.sector, | 130 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.sector, |
| 131 | // TODO: PREPARO PARA MANDAR A CARGAR EN LA BD | 131 | // TODO: PREPARO PARA MANDAR A CARGAR EN LA BD |
| 132 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.codigo, | 132 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.codigo, |
| 133 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.descripcion, | 133 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.descripcion, |
| 134 | cantidad.toString(), | 134 | cantidad.toString(), |
| 135 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.codBar, | 135 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.codBar, |
| 136 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.codOrigen, | 136 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.codOrigen, |
| 137 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, | 137 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, |
| 138 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, | 138 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, |
| 139 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza, | 139 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza, |
| 140 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.depSn, | 140 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.depSn, |
| 141 | InventarioFragment().ObtenerFechaActual(), | 141 | ObtenerFechaActual(), |
| 142 | InventarioFragment().ObtenerFechaActual()) | 142 | ObtenerFechaActual()) |
| 143 | InsertarArtEnDB(body)// TODO: MANDO A CARGAR A LA BASE DE DATOS | 143 | InsertarArtEnDB(body)// TODO: MANDO A CARGAR A LA BASE DE DATOS |
| 144 | modificarCantidadEnCabecera(numeroInventario, true, requireActivity()) | 144 | modificarCantidadEnCabecera(numeroInventario, true, requireActivity()) |
| 145 | // VolverAinventario() | 145 | // VolverAinventario() |
| 146 | activity?.onBackPressed() | 146 | activity?.onBackPressed() |
| 147 | mAlertDialog.dismiss() | 147 | mAlertDialog.dismiss() |
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| 150 | } else if (artCargadoEnBD != null) { | 150 | } else if (artCargadoEnBD != null) { |
| 151 | 151 | ||
| 152 | mDialogViewM = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 152 | mDialogViewM = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
| 153 | val mBuilder = AlertDialog.Builder(context).setView(mDialogViewM).setCancelable(false) | 153 | val mBuilder = AlertDialog.Builder(context).setView(mDialogViewM).setCancelable(false) |
| 154 | if (artCargadoEnBD!!.balanza.toString().contains("1") || artCargadoEnBD!!.balanza.toString().contains("3") || artCargadoEnBD!!.balanza.toString().contains("7")) mDialogViewM.tvNuevaCantidad.inputType= InputType.TYPE_CLASS_NUMBER | 154 | if (artCargadoEnBD!!.balanza.toString().contains("1") || artCargadoEnBD!!.balanza.toString().contains("3") || artCargadoEnBD!!.balanza.toString().contains("7")) mDialogViewM.tvNuevaCantidad.inputType= InputType.TYPE_CLASS_NUMBER |
| 155 | mDialogViewM.tvTitulo2.text="${artCargadoEnBD!!.descripcion}" | 155 | mDialogViewM.tvTitulo2.text="${artCargadoEnBD!!.descripcion}" |
| 156 | mDialogViewM.tvCantInicial.text =String.format("%.2f", artCargadoEnBD!!.cantTomada.toString().toFloat()) | 156 | mDialogViewM.tvCantInicial.text =String.format("%.2f", artCargadoEnBD!!.cantTomada.toString().toFloat()) |
| 157 | 157 | ||
| 158 | val mAlertDialog = mBuilder.show() | 158 | val mAlertDialog = mBuilder.show() |
| 159 | mDialogViewM.tvNuevaCantidad.requestFocus() | 159 | mDialogViewM.tvNuevaCantidad.requestFocus() |
| 160 | mDialogViewM.tvNuevaCantidad.addTextChangedListener(textWatcher) | 160 | mDialogViewM.tvNuevaCantidad.addTextChangedListener(textWatcher) |
| 161 | 161 | ||
| 162 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 162 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
| 163 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 163 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
| 164 | 164 | ||
| 165 | mDialogViewM.rbSumar.setOnClickListener { | 165 | mDialogViewM.rbSumar.setOnClickListener { |
| 166 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 166 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 167 | mDialogViewM.tvResultado.text = String.format("%.2f", (mDialogViewM.tvCantInicial.text.toString().toFloat() + mDialogViewM.tvNuevaCantidad.text.toString().toFloat())) | 167 | mDialogViewM.tvResultado.text = String.format("%.2f", (mDialogViewM.tvCantInicial.text.toString().toFloat() + mDialogViewM.tvNuevaCantidad.text.toString().toFloat())) |
| 168 | // mDialogView.tvNuevaCantidad.isEnabled=false | 168 | // mDialogView.tvNuevaCantidad.isEnabled=false |
| 169 | } | 169 | } |
| 170 | } | 170 | } |
| 171 | mDialogViewM.rbRestar.setOnClickListener { | 171 | mDialogViewM.rbRestar.setOnClickListener { |
| 172 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 172 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 173 | if (mDialogViewM.tvCantInicial.text.toString().toFloat() >= mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) { | 173 | if (mDialogViewM.tvCantInicial.text.toString().toFloat() >= mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) { |
| 174 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvCantInicial.text.toString().toFloat() - mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) | 174 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvCantInicial.text.toString().toFloat() - mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) |
| 175 | // mDialogView.tvNuevaCantidad.isEnabled = false | 175 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 176 | }else{ | 176 | }else{ |
| 177 | mDialogViewM.tvResultado.text="" | 177 | mDialogViewM.tvResultado.text="" |
| 178 | mDialogViewM.tvResultado.error = "Operación No Valida" | 178 | mDialogViewM.tvResultado.error = "Operación No Valida" |
| 179 | mDialogViewM.tvResultado.requestFocus() | 179 | mDialogViewM.tvResultado.requestFocus() |
| 180 | mDialogViewM.tvResultado.hint = "Error" | 180 | mDialogViewM.tvResultado.hint = "Error" |
| 181 | } | 181 | } |
| 182 | } | 182 | } |
| 183 | } | 183 | } |
| 184 | mDialogViewM.rbMdodificar.setOnClickListener { | 184 | mDialogViewM.rbMdodificar.setOnClickListener { |
| 185 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 185 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 186 | mDialogViewM.tvResultado.text = String.format("%.2f", (mDialogViewM.tvNuevaCantidad.text.toString().toFloat())) | 186 | mDialogViewM.tvResultado.text = String.format("%.2f", (mDialogViewM.tvNuevaCantidad.text.toString().toFloat())) |
| 187 | // mDialogView.tvNuevaCantidad.isEnabled = false | 187 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 188 | } | 188 | } |
| 189 | } | 189 | } |
| 190 | mDialogViewM.btnAceptar.setOnClickListener { | 190 | mDialogViewM.btnAceptar.setOnClickListener { |
| 191 | if (mDialogViewM.tvNuevaCantidad.text.isNotEmpty() || !mDialogViewM.tvNuevaCantidad.text.isBlank()) { | 191 | if (mDialogViewM.tvNuevaCantidad.text.isNotEmpty() || !mDialogViewM.tvNuevaCantidad.text.isBlank()) { |
| 192 | if (mDialogViewM.tvResultado.text.isNotEmpty() || !mDialogViewM.tvResultado.text.isBlank()) { | 192 | if (mDialogViewM.tvResultado.text.isNotEmpty() || !mDialogViewM.tvResultado.text.isBlank()) { |
| 193 | 193 | ||
| 194 | updateCantidad((viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.sector.toString(), | 194 | updateCantidad((viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.sector.toString(), |
| 195 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.codigo.toString(), | 195 | (viewAdapter2 as CodigoOrigenAdapter).items2?.get(viewHolder.layoutPosition)!!.codigo.toString(), |
| 196 | mDialogViewM.tvResultado.text.toString().toFloat()) | 196 | mDialogViewM.tvResultado.text.toString().toFloat()) |
| 197 | // VolverAinventario() | 197 | // VolverAinventario() |
| 198 | activity?.onBackPressed(); | 198 | activity?.onBackPressed(); |
| 199 | mAlertDialog.dismiss() | 199 | mAlertDialog.dismiss() |
| 200 | } else if (mDialogViewM.tvNuevaCantidad.text.isNotEmpty() || mDialogViewM.tvNuevaCantidad.text.isBlank()) { | 200 | } else if (mDialogViewM.tvNuevaCantidad.text.isNotEmpty() || mDialogViewM.tvNuevaCantidad.text.isBlank()) { |
| 201 | mDialogViewM.tvResultado.error = "Operación Requerida" | 201 | mDialogViewM.tvResultado.error = "Operación Requerida" |
| 202 | mDialogViewM.tvResultado.requestFocus() | 202 | mDialogViewM.tvResultado.requestFocus() |
| 203 | mDialogViewM.tvResultado.hint = "Seleccione Operación" | 203 | mDialogViewM.tvResultado.hint = "Seleccione Operación" |
| 204 | } | 204 | } |
| 205 | } else if (mDialogViewM.tvNuevaCantidad.text.isEmpty() || mDialogViewM.tvNuevaCantidad.text.isBlank()) { | 205 | } else if (mDialogViewM.tvNuevaCantidad.text.isEmpty() || mDialogViewM.tvNuevaCantidad.text.isBlank()) { |
| 206 | mDialogViewM.tvNuevaCantidad.error = "Completar" | 206 | mDialogViewM.tvNuevaCantidad.error = "Completar" |
| 207 | mDialogViewM.tvNuevaCantidad.requestFocus() | 207 | mDialogViewM.tvNuevaCantidad.requestFocus() |
| 208 | mDialogViewM.tvNuevaCantidad.hint = "Ingrese un valor" | 208 | mDialogViewM.tvNuevaCantidad.hint = "Ingrese un valor" |
| 209 | } | 209 | } |
| 210 | } | 210 | } |
| 211 | mDialogViewM.dialogCancelBtn.setOnClickListener { | 211 | mDialogViewM.dialogCancelBtn.setOnClickListener { |
| 212 | activity?.onBackPressed(); | 212 | activity?.onBackPressed(); |
| 213 | mAlertDialog.dismiss() | 213 | mAlertDialog.dismiss() |
| 214 | } | 214 | } |
| 215 | } | 215 | } |
| 216 | } | 216 | } |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { | 219 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { |
| 220 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 220 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
| 221 | val itemView = viewHolder.itemView | 221 | val itemView = viewHolder.itemView |
| 222 | 222 | ||
| 223 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) | 223 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) |
| 224 | 224 | ||
| 225 | if (dX > 0) { | 225 | if (dX > 0) { |
| 226 | 226 | ||
| 227 | c.drawColor(Color.RED) | 227 | c.drawColor(Color.RED) |
| 228 | } else if (dX < 0) { | 228 | } else if (dX < 0) { |
| 229 | // swipeBackground.setBounds(itemView.right+dX.toInt(),itemView.top,itemView.right,itemView.bottom) | 229 | // swipeBackground.setBounds(itemView.right+dX.toInt(),itemView.top,itemView.right,itemView.bottom) |
| 230 | c.drawColor(Color.YELLOW) | 230 | c.drawColor(Color.YELLOW) |
| 231 | } | 231 | } |
| 232 | swipeBackground.draw(c) | 232 | swipeBackground.draw(c) |
| 233 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 233 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
| 234 | } | 234 | } |
| 235 | } | 235 | } |
| 236 | val itemTouchHelper2 = ItemTouchHelper(itemTouchHelperCallback) | 236 | val itemTouchHelper2 = ItemTouchHelper(itemTouchHelperCallback) |
| 237 | itemTouchHelper2.attachToRecyclerView(rcCodigoOri) | 237 | itemTouchHelper2.attachToRecyclerView(rcCodigoOri) |
| 238 | 238 | ||
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { | 241 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { |
| 242 | lifecycleScope.launch { | 242 | lifecycleScope.launch { |
| 243 | withContext(Dispatchers.IO) { | 243 | withContext(Dispatchers.IO) { |
| 244 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) | 244 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) |
| 245 | } | 245 | } |
| 246 | } | 246 | } |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | suspend fun buscarCodigoDeboEnBD(sector: String, codigo: String, numInventario: String): InvBody? { | 249 | suspend fun buscarCodigoDeboEnBD(sector: String, codigo: String, numInventario: String): InvBody? { |
| 250 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 250 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
| 251 | var busqueda: InvBody? = null | 251 | var busqueda: InvBody? = null |
| 252 | return GlobalScope.async(Dispatchers.IO) { | 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 | return@async busqueda | 254 | return@async busqueda |
| 255 | }.await() | 255 | }.await() |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { | 258 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { |
| 259 | lifecycleScope.launch { | 259 | lifecycleScope.launch { |
| 260 | withContext(Dispatchers.IO) { | 260 | withContext(Dispatchers.IO) { |
| 261 | val activity: FragmentActivity? = activity | 261 | val activity: FragmentActivity? = activity |
| 262 | if (activity != null && isAdded) { | 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 | } |
| 267 | } | 267 | } |
| 268 | private val textWatcher = object : TextWatcher { | 268 | private val textWatcher = object : TextWatcher { |
| 269 | override fun afterTextChanged(s: Editable?) { | 269 | override fun afterTextChanged(s: Editable?) { |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { | 272 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { | 275 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { |
| 276 | if (mDialogViewM.rbSumar.isChecked) { | 276 | if (mDialogViewM.rbSumar.isChecked) { |
| 277 | // mDialogView.tvNuevaCantidad.isEnabled=false | 277 | // mDialogView.tvNuevaCantidad.isEnabled=false |
| 278 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvNuevaCantidad.text.toString().toFloat() + mDialogViewM.tvCantInicial.text.toString().toFloat()) | 278 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvNuevaCantidad.text.toString().toFloat() + mDialogViewM.tvCantInicial.text.toString().toFloat()) |
| 279 | } | 279 | } |
| 280 | if (mDialogViewM.rbRestar.isChecked) { | 280 | if (mDialogViewM.rbRestar.isChecked) { |
| 281 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 281 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 282 | if (mDialogViewM.tvCantInicial.text.toString().toFloat() >= mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) { | 282 | if (mDialogViewM.tvCantInicial.text.toString().toFloat() >= mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) { |
| 283 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvCantInicial.text.toString().toFloat() - mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) | 283 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvCantInicial.text.toString().toFloat() - mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) |
| 284 | // mDialogView.tvNuevaCantidad.isEnabled = false | 284 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 285 | } else { | 285 | } else { |
| 286 | mDialogViewM.tvResultado.text = "" | 286 | mDialogViewM.tvResultado.text = "" |
| 287 | mDialogViewM.tvResultado.error = "Operación No Valida" | 287 | mDialogViewM.tvResultado.error = "Operación No Valida" |
| 288 | mDialogViewM.tvResultado.requestFocus() | 288 | mDialogViewM.tvResultado.requestFocus() |
| 289 | mDialogViewM.tvResultado.hint = "Error" | 289 | mDialogViewM.tvResultado.hint = "Error" |
| 290 | } | 290 | } |
| 291 | } | 291 | } |
| 292 | } | 292 | } |
| 293 | if (mDialogViewM.rbMdodificar.isChecked) { | 293 | if (mDialogViewM.rbMdodificar.isChecked) { |
| 294 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 294 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 295 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) | 295 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) |
| 296 | // mDialogView.tvNuevaCantidad.isEnabled = false | 296 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 297 | } | 297 | } |
| 298 | } | 298 | } |
| 299 | } | 299 | } |
| 300 | } | 300 | } |
app/src/main/java/com/focasoftware/deboinventariov20/UI/descripcionFragment/DescripcionFragment.kt
| 1 | package com.focasoftware.deboinventariov20.UI.descripcionFragment | 1 | package com.focasoftware.deboinventariov20.UI.descripcionFragment |
| 2 | 2 | ||
| 3 | import android.app.AlertDialog | 3 | import android.app.AlertDialog |
| 4 | import android.content.Context | 4 | import android.content.Context |
| 5 | import android.content.SharedPreferences | 5 | import android.content.SharedPreferences |
| 6 | import android.graphics.Canvas | 6 | import android.graphics.Canvas |
| 7 | import android.graphics.Color | 7 | import android.graphics.Color |
| 8 | import android.graphics.drawable.ColorDrawable | 8 | import android.graphics.drawable.ColorDrawable |
| 9 | import android.os.Bundle | 9 | import android.os.Bundle |
| 10 | import android.text.Editable | 10 | import android.text.Editable |
| 11 | import android.text.InputType | 11 | import android.text.InputType |
| 12 | import android.text.TextWatcher | 12 | import android.text.TextWatcher |
| 13 | import android.view.LayoutInflater | 13 | import android.view.LayoutInflater |
| 14 | import android.view.View | 14 | import android.view.View |
| 15 | import android.view.ViewGroup | 15 | import android.view.ViewGroup |
| 16 | import android.view.WindowManager | 16 | import android.view.WindowManager |
| 17 | import android.view.inputmethod.InputMethodManager | 17 | import android.view.inputmethod.InputMethodManager |
| 18 | import androidx.fragment.app.Fragment | 18 | import androidx.fragment.app.Fragment |
| 19 | import androidx.fragment.app.FragmentActivity | 19 | import androidx.fragment.app.FragmentActivity |
| 20 | import androidx.lifecycle.lifecycleScope | 20 | import androidx.lifecycle.lifecycleScope |
| 21 | import androidx.navigation.NavController | 21 | import androidx.navigation.NavController |
| 22 | import androidx.navigation.Navigation | 22 | import androidx.navigation.Navigation |
| 23 | import androidx.recyclerview.widget.ItemTouchHelper | 23 | import androidx.recyclerview.widget.ItemTouchHelper |
| 24 | import androidx.recyclerview.widget.LinearLayoutManager | 24 | import androidx.recyclerview.widget.LinearLayoutManager |
| 25 | import androidx.recyclerview.widget.RecyclerView | 25 | import androidx.recyclerview.widget.RecyclerView |
| 26 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 26 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
| 27 | import com.focasoftware.deboinventariov20.Model.Articles | 27 | import com.focasoftware.deboinventariov20.Model.Articles |
| 28 | import com.focasoftware.deboinventariov20.Model.InvBody | 28 | import com.focasoftware.deboinventariov20.Model.InvBody |
| 29 | import com.focasoftware.deboinventariov20.R | 29 | import com.focasoftware.deboinventariov20.R |
| 30 | import com.focasoftware.deboinventariov20.UI.Utils.ObtenerFechaActual | ||
| 30 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera | 31 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera |
| 31 | import com.focasoftware.deboinventariov20.UI.inventario.InventarioFragment | ||
| 32 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* | 32 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* |
| 33 | import kotlinx.android.synthetic.main.login_dialog.view.* | 33 | import kotlinx.android.synthetic.main.login_dialog.view.* |
| 34 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar | 34 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar |
| 35 | import kotlinx.coroutines.* | 35 | import kotlinx.coroutines.* |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | class DescripcionFragment : Fragment() { | 38 | class DescripcionFragment : Fragment() { |
| 39 | private var artAcargar2: List<Articles>? = null | 39 | private var artAcargar2: List<Articles>? = null |
| 40 | private var listArticulos2: List<Articles>? = null | 40 | private var listArticulos2: List<Articles>? = null |
| 41 | lateinit var viewAdapter2: RecyclerView.Adapter<*> | 41 | lateinit var viewAdapter2: RecyclerView.Adapter<*> |
| 42 | private lateinit var viewManager2: RecyclerView.LayoutManager | 42 | private lateinit var viewManager2: RecyclerView.LayoutManager |
| 43 | private lateinit var rcDescripcion: RecyclerView | 43 | private lateinit var rcDescripcion: RecyclerView |
| 44 | private var swipeBackground: ColorDrawable = ColorDrawable(Color.YELLOW) | 44 | private var swipeBackground: ColorDrawable = ColorDrawable(Color.YELLOW) |
| 45 | private var cantidad = 0F | 45 | private var cantidad = 0F |
| 46 | private var numeroInventario = 0 | 46 | private var numeroInventario = 0 |
| 47 | lateinit var navController: NavController | 47 | lateinit var navController: NavController |
| 48 | lateinit var sharedPreferences: SharedPreferences | 48 | lateinit var sharedPreferences: SharedPreferences |
| 49 | private var artCargadoEnBD: InvBody? = null | 49 | private var artCargadoEnBD: InvBody? = null |
| 50 | lateinit var mDialogViewM: View | 50 | lateinit var mDialogViewM: View |
| 51 | 51 | ||
| 52 | override fun onCreate(savedInstanceState: Bundle?) { | 52 | override fun onCreate(savedInstanceState: Bundle?) { |
| 53 | super.onCreate(savedInstanceState) | 53 | super.onCreate(savedInstanceState) |
| 54 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 54 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
| 55 | arguments.apply { | 55 | arguments.apply { |
| 56 | artAcargar2 = requireArguments().getSerializable("ArrayDesc") as List<Articles> | 56 | artAcargar2 = requireArguments().getSerializable("ArrayDesc") as List<Articles> |
| 57 | numeroInventario = requireArguments().getInt("numeroInv") | 57 | numeroInventario = requireArguments().getInt("numeroInv") |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 62 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
| 63 | super.onViewCreated(view, savedInstanceState) | 63 | super.onViewCreated(view, savedInstanceState) |
| 64 | navController = Navigation.findNavController(view) | 64 | navController = Navigation.findNavController(view) |
| 65 | showSoftKeyboard(view) | 65 | showSoftKeyboard(view) |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 68 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
| 69 | val v = inflater.inflate(R.layout.fragment_descripcion, container, false) | 69 | val v = inflater.inflate(R.layout.fragment_descripcion, container, false) |
| 70 | rcDescripcion = v.findViewById(R.id.rcDescripcion) | 70 | rcDescripcion = v.findViewById(R.id.rcDescripcion) |
| 71 | IngresarRecicler(artAcargar2) | 71 | IngresarRecicler(artAcargar2) |
| 72 | showSoftKeyboard(v) | 72 | showSoftKeyboard(v) |
| 73 | 73 | ||
| 74 | return v | 74 | return v |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | private fun showSoftKeyboard(view: View) { | 77 | private fun showSoftKeyboard(view: View) { |
| 78 | if (view.requestFocus()) { | 78 | if (view.requestFocus()) { |
| 79 | val imm = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | 79 | val imm = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager |
| 80 | imm.showSoftInput(view, InputMethodManager.HIDE_IMPLICIT_ONLY) | 80 | imm.showSoftInput(view, InputMethodManager.HIDE_IMPLICIT_ONLY) |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | fun IngresarRecicler(articulos: List<Articles>?) { | 84 | fun IngresarRecicler(articulos: List<Articles>?) { |
| 85 | 85 | ||
| 86 | viewAdapter2 = DescripcionListAdapter(articulos) | 86 | viewAdapter2 = DescripcionListAdapter(articulos) |
| 87 | viewManager2 = LinearLayoutManager(requireContext()) | 87 | viewManager2 = LinearLayoutManager(requireContext()) |
| 88 | 88 | ||
| 89 | rcDescripcion.apply { | 89 | rcDescripcion.apply { |
| 90 | adapter = viewAdapter2 | 90 | adapter = viewAdapter2 |
| 91 | layoutManager = viewManager2 | 91 | layoutManager = viewManager2 |
| 92 | } | 92 | } |
| 93 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) { | 93 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) { |
| 94 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { | 94 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { |
| 95 | return false | 95 | return false |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, position: Int) { | 98 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, position: Int) { |
| 99 | 99 | ||
| 100 | GlobalScope.launch(Dispatchers.Main) { | 100 | GlobalScope.launch(Dispatchers.Main) { |
| 101 | //TODO BUSCO EN BASE DE DATOS | 101 | //TODO BUSCO EN BASE DE DATOS |
| 102 | artCargadoEnBD = buscarCodigoDeboEnBD( | 102 | artCargadoEnBD = buscarCodigoDeboEnBD( |
| 103 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)?.sector.toString(), | 103 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)?.sector.toString(), |
| 104 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)?.codigo.toString(), numeroInventario.toString() | 104 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)?.codigo.toString(), numeroInventario.toString() |
| 105 | ) | 105 | ) |
| 106 | if (artCargadoEnBD == null) { | 106 | if (artCargadoEnBD == null) { |
| 107 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.ingresar_cantidad, null) | 107 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.ingresar_cantidad, null) |
| 108 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(false) | 108 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(false) |
| 109 | //TODO: DEPENDIENDO DEL TIPO DE ARTICULO PERMITER INGRESAR DECIMALES O NO | 109 | //TODO: DEPENDIENDO DEL TIPO DE ARTICULO PERMITER INGRESAR DECIMALES O NO |
| 110 | if ((viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza == 1 || (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza == 3 || (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza == 7) | 110 | if ((viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza == 1 || (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza == 3 || (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza == 7) |
| 111 | mDialogView.etCantidad.inputType = InputType.TYPE_CLASS_NUMBER | 111 | mDialogView.etCantidad.inputType = InputType.TYPE_CLASS_NUMBER |
| 112 | 112 | ||
| 113 | mDialogView.tvTitulo.text = "${(viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.descripcion}" | 113 | mDialogView.tvTitulo.text = "${(viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.descripcion}" |
| 114 | val mAlertDialog = mBuilder.show() | 114 | val mAlertDialog = mBuilder.show() |
| 115 | 115 | ||
| 116 | mDialogView.etCantidad.requestFocus() | 116 | mDialogView.etCantidad.requestFocus() |
| 117 | mAlertDialog.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 117 | mAlertDialog.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
| 118 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 118 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
| 119 | 119 | ||
| 120 | mDialogView.btnAceptar.setOnClickListener { | 120 | mDialogView.btnAceptar.setOnClickListener { |
| 121 | if (mDialogView.etCantidad.text.isNullOrEmpty()) { | 121 | if (mDialogView.etCantidad.text.isNullOrEmpty()) { |
| 122 | mDialogView.etCantidad.error = "No vacio" | 122 | mDialogView.etCantidad.error = "No vacio" |
| 123 | mDialogView.etCantidad.requestFocus() | 123 | mDialogView.etCantidad.requestFocus() |
| 124 | mDialogView.etCantidad.hint = "Ingrese un valor" | 124 | mDialogView.etCantidad.hint = "Ingrese un valor" |
| 125 | } else if (!mDialogView.etCantidad.text.isNullOrEmpty()) { | 125 | } else if (!mDialogView.etCantidad.text.isNullOrEmpty()) { |
| 126 | 126 | ||
| 127 | cantidad = String.format("%.2f",mDialogView.etCantidad.text.toString().toFloat()).toFloat() | 127 | cantidad = String.format("%.2f",mDialogView.etCantidad.text.toString().toFloat()).toFloat() |
| 128 | val body = InvBody( | 128 | val body = InvBody( |
| 129 | numeroInventario, | 129 | numeroInventario, |
| 130 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.sector, | 130 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.sector, |
| 131 | // TODO: PREPARO PARA MANDAR A CARGAR EN LA BD | 131 | // TODO: PREPARO PARA MANDAR A CARGAR EN LA BD |
| 132 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.codigo, | 132 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.codigo, |
| 133 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.descripcion, | 133 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.descripcion, |
| 134 | cantidad.toString(), | 134 | cantidad.toString(), |
| 135 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.codBar, | 135 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.codBar, |
| 136 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.codOrigen, | 136 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.codOrigen, |
| 137 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, | 137 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, |
| 138 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, | 138 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.precio, |
| 139 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza, | 139 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.balanza, |
| 140 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.depSn, | 140 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.depSn, |
| 141 | InventarioFragment().ObtenerFechaActual(), | 141 | ObtenerFechaActual(), |
| 142 | InventarioFragment().ObtenerFechaActual() | 142 | ObtenerFechaActual() |
| 143 | ) | 143 | ) |
| 144 | InsertarArtEnDB(body)// TODO: MANDO A CARGAR A LA BASE DE DATOS | 144 | InsertarArtEnDB(body)// TODO: MANDO A CARGAR A LA BASE DE DATOS |
| 145 | modificarCantidadEnCabecera(numeroInventario, true, requireActivity()) | 145 | modificarCantidadEnCabecera(numeroInventario, true, requireActivity()) |
| 146 | // VolverAinventario() | 146 | // VolverAinventario() |
| 147 | activity?.onBackPressed() | 147 | activity?.onBackPressed() |
| 148 | mAlertDialog.dismiss() | 148 | mAlertDialog.dismiss() |
| 149 | } | 149 | } |
| 150 | } | 150 | } |
| 151 | } else if (artCargadoEnBD != null) { | 151 | } else if (artCargadoEnBD != null) { |
| 152 | 152 | ||
| 153 | mDialogViewM = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 153 | mDialogViewM = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
| 154 | val mBuilder = AlertDialog.Builder(context).setView(mDialogViewM).setCancelable(false) | 154 | val mBuilder = AlertDialog.Builder(context).setView(mDialogViewM).setCancelable(false) |
| 155 | if (artCargadoEnBD!!.balanza.toString().contains("1") || artCargadoEnBD!!.balanza.toString().contains("3") || artCargadoEnBD!!.balanza.toString().contains("7") | 155 | if (artCargadoEnBD!!.balanza.toString().contains("1") || artCargadoEnBD!!.balanza.toString().contains("3") || artCargadoEnBD!!.balanza.toString().contains("7") |
| 156 | ) mDialogViewM.tvNuevaCantidad.inputType = InputType.TYPE_CLASS_NUMBER | 156 | ) mDialogViewM.tvNuevaCantidad.inputType = InputType.TYPE_CLASS_NUMBER |
| 157 | mDialogViewM.tvTitulo2.text="${artCargadoEnBD!!.descripcion}" | 157 | mDialogViewM.tvTitulo2.text="${artCargadoEnBD!!.descripcion}" |
| 158 | mDialogViewM.tvCantInicial.text = String.format("%.2f", artCargadoEnBD!!.cantTomada.toString().toFloat()) | 158 | mDialogViewM.tvCantInicial.text = String.format("%.2f", artCargadoEnBD!!.cantTomada.toString().toFloat()) |
| 159 | 159 | ||
| 160 | val mAlertDialog = mBuilder.show() | 160 | val mAlertDialog = mBuilder.show() |
| 161 | mDialogViewM.tvNuevaCantidad.requestFocus() | 161 | mDialogViewM.tvNuevaCantidad.requestFocus() |
| 162 | 162 | ||
| 163 | 163 | ||
| 164 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 164 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
| 165 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 165 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
| 166 | 166 | ||
| 167 | mDialogViewM.tvNuevaCantidad.addTextChangedListener(textWatcher) | 167 | mDialogViewM.tvNuevaCantidad.addTextChangedListener(textWatcher) |
| 168 | 168 | ||
| 169 | mDialogViewM.rbSumar.setOnClickListener { | 169 | mDialogViewM.rbSumar.setOnClickListener { |
| 170 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 170 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 171 | mDialogViewM.tvResultado.text = String.format("%.2f", (mDialogViewM.tvCantInicial.text.toString().toFloat() + mDialogViewM.tvNuevaCantidad.text.toString().toFloat())) | 171 | mDialogViewM.tvResultado.text = String.format("%.2f", (mDialogViewM.tvCantInicial.text.toString().toFloat() + mDialogViewM.tvNuevaCantidad.text.toString().toFloat())) |
| 172 | // mDialogViewM.tvNuevaCantidad.isEnabled = false | 172 | // mDialogViewM.tvNuevaCantidad.isEnabled = false |
| 173 | } | 173 | } |
| 174 | } | 174 | } |
| 175 | mDialogViewM.rbRestar.setOnClickListener { | 175 | mDialogViewM.rbRestar.setOnClickListener { |
| 176 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 176 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 177 | if (mDialogViewM.tvCantInicial.text.toString().toFloat() >= mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) { | 177 | if (mDialogViewM.tvCantInicial.text.toString().toFloat() >= mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) { |
| 178 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvCantInicial.text.toString().toFloat() - mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) | 178 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvCantInicial.text.toString().toFloat() - mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) |
| 179 | // mDialogViewM.tvNuevaCantidad.isEnabled = false | 179 | // mDialogViewM.tvNuevaCantidad.isEnabled = false |
| 180 | } else { | 180 | } else { |
| 181 | mDialogViewM.tvResultado.text = "" | 181 | mDialogViewM.tvResultado.text = "" |
| 182 | mDialogViewM.tvResultado.error = "Operación No Valida" | 182 | mDialogViewM.tvResultado.error = "Operación No Valida" |
| 183 | mDialogViewM.tvResultado.requestFocus() | 183 | mDialogViewM.tvResultado.requestFocus() |
| 184 | mDialogViewM.tvResultado.hint = "Error" | 184 | mDialogViewM.tvResultado.hint = "Error" |
| 185 | } | 185 | } |
| 186 | } | 186 | } |
| 187 | } | 187 | } |
| 188 | mDialogViewM.rbMdodificar.setOnClickListener { | 188 | mDialogViewM.rbMdodificar.setOnClickListener { |
| 189 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 189 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 190 | mDialogViewM.tvResultado.text = String.format("%.2f", (mDialogViewM.tvNuevaCantidad.text.toString().toFloat())) | 190 | mDialogViewM.tvResultado.text = String.format("%.2f", (mDialogViewM.tvNuevaCantidad.text.toString().toFloat())) |
| 191 | // mDialogViewM.tvNuevaCantidad.isEnabled = false | 191 | // mDialogViewM.tvNuevaCantidad.isEnabled = false |
| 192 | } | 192 | } |
| 193 | } | 193 | } |
| 194 | mDialogViewM.btnAceptar.setOnClickListener { | 194 | mDialogViewM.btnAceptar.setOnClickListener { |
| 195 | if (mDialogViewM.tvNuevaCantidad.text.isNotEmpty() || !mDialogViewM.tvNuevaCantidad.text.isBlank()) { | 195 | if (mDialogViewM.tvNuevaCantidad.text.isNotEmpty() || !mDialogViewM.tvNuevaCantidad.text.isBlank()) { |
| 196 | if (mDialogViewM.tvResultado.text.isNotEmpty() || !mDialogViewM.tvResultado.text.isBlank()) { | 196 | if (mDialogViewM.tvResultado.text.isNotEmpty() || !mDialogViewM.tvResultado.text.isBlank()) { |
| 197 | 197 | ||
| 198 | updateCantidad( | 198 | updateCantidad( |
| 199 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.sector.toString(), | 199 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.sector.toString(), |
| 200 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.codigo.toString(), | 200 | (viewAdapter2 as DescripcionListAdapter).items2?.get(viewHolder.layoutPosition)!!.codigo.toString(), |
| 201 | mDialogViewM.tvResultado.text.toString().toFloat() | 201 | mDialogViewM.tvResultado.text.toString().toFloat() |
| 202 | ) | 202 | ) |
| 203 | activity?.onBackPressed() | 203 | activity?.onBackPressed() |
| 204 | mAlertDialog.dismiss() | 204 | mAlertDialog.dismiss() |
| 205 | } else if (mDialogViewM.tvNuevaCantidad.text.isNotEmpty() || mDialogViewM.tvNuevaCantidad.text.isBlank()) { | 205 | } else if (mDialogViewM.tvNuevaCantidad.text.isNotEmpty() || mDialogViewM.tvNuevaCantidad.text.isBlank()) { |
| 206 | mDialogViewM.tvResultado.error = "Operación Requerida" | 206 | mDialogViewM.tvResultado.error = "Operación Requerida" |
| 207 | mDialogViewM.tvResultado.requestFocus() | 207 | mDialogViewM.tvResultado.requestFocus() |
| 208 | mDialogViewM.tvResultado.hint = "Seleccione Operación" | 208 | mDialogViewM.tvResultado.hint = "Seleccione Operación" |
| 209 | } | 209 | } |
| 210 | } else if (mDialogViewM.tvNuevaCantidad.text.isEmpty() || mDialogViewM.tvNuevaCantidad.text.isBlank()) { | 210 | } else if (mDialogViewM.tvNuevaCantidad.text.isEmpty() || mDialogViewM.tvNuevaCantidad.text.isBlank()) { |
| 211 | mDialogViewM.tvNuevaCantidad.error = "Completar" | 211 | mDialogViewM.tvNuevaCantidad.error = "Completar" |
| 212 | mDialogViewM.tvNuevaCantidad.requestFocus() | 212 | mDialogViewM.tvNuevaCantidad.requestFocus() |
| 213 | mDialogViewM.tvNuevaCantidad.hint = "Ingrese un valor" | 213 | mDialogViewM.tvNuevaCantidad.hint = "Ingrese un valor" |
| 214 | } | 214 | } |
| 215 | } | 215 | } |
| 216 | mDialogViewM.dialogCancelBtn.setOnClickListener { | 216 | mDialogViewM.dialogCancelBtn.setOnClickListener { |
| 217 | activity?.onBackPressed() | 217 | activity?.onBackPressed() |
| 218 | mAlertDialog.dismiss() | 218 | mAlertDialog.dismiss() |
| 219 | } | 219 | } |
| 220 | } | 220 | } |
| 221 | } | 221 | } |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { | 224 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { |
| 225 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 225 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
| 226 | val itemView = viewHolder.itemView | 226 | val itemView = viewHolder.itemView |
| 227 | 227 | ||
| 228 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) | 228 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) |
| 229 | 229 | ||
| 230 | if (dX > 0) { | 230 | if (dX > 0) { |
| 231 | 231 | ||
| 232 | c.drawColor(Color.RED) | 232 | c.drawColor(Color.RED) |
| 233 | } else if (dX < 0) { | 233 | } else if (dX < 0) { |
| 234 | // swipeBackground.setBounds(itemView.right+dX.toInt(),itemView.top,itemView.right,itemView.bottom) | 234 | // swipeBackground.setBounds(itemView.right+dX.toInt(),itemView.top,itemView.right,itemView.bottom) |
| 235 | c.drawColor(Color.YELLOW) | 235 | c.drawColor(Color.YELLOW) |
| 236 | } | 236 | } |
| 237 | swipeBackground.draw(c) | 237 | swipeBackground.draw(c) |
| 238 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 238 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
| 239 | } | 239 | } |
| 240 | } | 240 | } |
| 241 | val itemTouchHelper2 = ItemTouchHelper(itemTouchHelperCallback) | 241 | val itemTouchHelper2 = ItemTouchHelper(itemTouchHelperCallback) |
| 242 | itemTouchHelper2.attachToRecyclerView(rcDescripcion) | 242 | itemTouchHelper2.attachToRecyclerView(rcDescripcion) |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { | 245 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { |
| 246 | lifecycleScope.launch { | 246 | lifecycleScope.launch { |
| 247 | withContext(Dispatchers.IO) { | 247 | withContext(Dispatchers.IO) { |
| 248 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) | 248 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) |
| 249 | } | 249 | } |
| 250 | } | 250 | } |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | suspend fun buscarCodigoDeboEnBD(sector: String, codigo: String, numInventario: String): InvBody? { | 253 | suspend fun buscarCodigoDeboEnBD(sector: String, codigo: String, numInventario: String): InvBody? { |
| 254 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 254 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
| 255 | var busqueda: InvBody? = null | 255 | var busqueda: InvBody? = null |
| 256 | return GlobalScope.async(Dispatchers.IO) { | 256 | return GlobalScope.async(Dispatchers.IO) { |
| 257 | busqueda = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.fetchArtInInvBody(sector.toLong(), codigo.toLong(), numInventario.toLong()) | 257 | busqueda = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.fetchArtInInvBody(sector.toLong(), codigo.toLong(), numInventario.toLong()) |
| 258 | return@async busqueda | 258 | return@async busqueda |
| 259 | }.await() | 259 | }.await() |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { | 262 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { |
| 263 | lifecycleScope.launch { | 263 | lifecycleScope.launch { |
| 264 | withContext(Dispatchers.IO) { | 264 | withContext(Dispatchers.IO) { |
| 265 | val activity: FragmentActivity? = activity | 265 | val activity: FragmentActivity? = activity |
| 266 | if (activity != null && isAdded) { | 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 | } |
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | private val textWatcher = object : TextWatcher { | 273 | private val textWatcher = object : TextWatcher { |
| 274 | override fun afterTextChanged(s: Editable?) { | 274 | override fun afterTextChanged(s: Editable?) { |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { | 277 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { | 280 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { |
| 281 | if (mDialogViewM.rbSumar.isChecked) { | 281 | if (mDialogViewM.rbSumar.isChecked) { |
| 282 | // mDialogView.tvNuevaCantidad.isEnabled=false | 282 | // mDialogView.tvNuevaCantidad.isEnabled=false |
| 283 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvNuevaCantidad.text.toString().toFloat() + mDialogViewM.tvCantInicial.text.toString().toFloat()) | 283 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvNuevaCantidad.text.toString().toFloat() + mDialogViewM.tvCantInicial.text.toString().toFloat()) |
| 284 | } | 284 | } |
| 285 | if (mDialogViewM.rbRestar.isChecked) { | 285 | if (mDialogViewM.rbRestar.isChecked) { |
| 286 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 286 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 287 | if (mDialogViewM.tvCantInicial.text.toString().toFloat() >= mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) { | 287 | if (mDialogViewM.tvCantInicial.text.toString().toFloat() >= mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) { |
| 288 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvCantInicial.text.toString().toFloat() - mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) | 288 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvCantInicial.text.toString().toFloat() - mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) |
| 289 | // mDialogView.tvNuevaCantidad.isEnabled = false | 289 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 290 | } else { | 290 | } else { |
| 291 | mDialogViewM.tvResultado.text = "" | 291 | mDialogViewM.tvResultado.text = "" |
| 292 | mDialogViewM.tvResultado.error = "Operación No Valida" | 292 | mDialogViewM.tvResultado.error = "Operación No Valida" |
| 293 | mDialogViewM.tvResultado.requestFocus() | 293 | mDialogViewM.tvResultado.requestFocus() |
| 294 | mDialogViewM.tvResultado.hint = "Error" | 294 | mDialogViewM.tvResultado.hint = "Error" |
| 295 | } | 295 | } |
| 296 | } | 296 | } |
| 297 | } | 297 | } |
| 298 | if (mDialogViewM.rbMdodificar.isChecked) { | 298 | if (mDialogViewM.rbMdodificar.isChecked) { |
| 299 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { | 299 | if (!mDialogViewM.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 300 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) | 300 | mDialogViewM.tvResultado.text = String.format("%.2f", mDialogViewM.tvNuevaCantidad.text.toString().toFloat()) |
| 301 | // mDialogView.tvNuevaCantidad.isEnabled = false | 301 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 302 | } | 302 | } |
| 303 | } | 303 | } |
| 304 | } | 304 | } |
| 305 | } | 305 | } |
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | 308 |
app/src/main/java/com/focasoftware/deboinventariov20/UI/inventario/InventarioFragment.kt
| 1 | package com.focasoftware.deboinventariov20.UI.inventario | 1 | package com.focasoftware.deboinventariov20.UI.inventario |
| 2 | 2 | ||
| 3 | import android.annotation.SuppressLint | 3 | import android.annotation.SuppressLint |
| 4 | import android.app.AlertDialog | 4 | import android.app.AlertDialog |
| 5 | import android.app.Dialog | ||
| 6 | import android.content.Context | 5 | import android.content.Context |
| 7 | import android.content.Context.INPUT_METHOD_SERVICE | 6 | import android.content.Context.INPUT_METHOD_SERVICE |
| 8 | import android.content.DialogInterface | 7 | import android.content.DialogInterface |
| 9 | import android.content.SharedPreferences | 8 | import android.content.SharedPreferences |
| 10 | import android.graphics.Canvas | 9 | import android.graphics.Canvas |
| 11 | import android.graphics.Color | 10 | import android.graphics.Color |
| 12 | import android.graphics.drawable.Drawable | 11 | import android.graphics.drawable.Drawable |
| 13 | import android.os.Bundle | 12 | import android.os.Bundle |
| 14 | import android.text.Editable | 13 | import android.text.Editable |
| 15 | import android.text.InputType.TYPE_CLASS_NUMBER | 14 | import android.text.InputType.TYPE_CLASS_NUMBER |
| 16 | import android.text.TextWatcher | 15 | import android.text.TextWatcher |
| 17 | import android.view.* | 16 | import android.view.* |
| 18 | import android.view.inputmethod.InputMethodManager | 17 | import android.view.inputmethod.InputMethodManager |
| 19 | import android.widget.EditText | 18 | import android.widget.EditText |
| 20 | import android.widget.TextView | 19 | import android.widget.TextView |
| 21 | import android.widget.Toast | 20 | import android.widget.Toast |
| 22 | import androidx.core.content.ContextCompat | 21 | import androidx.core.content.ContextCompat |
| 23 | import androidx.core.os.bundleOf | 22 | import androidx.core.os.bundleOf |
| 24 | import androidx.fragment.app.Fragment | 23 | import androidx.fragment.app.Fragment |
| 25 | import androidx.lifecycle.ViewModel | 24 | import androidx.lifecycle.ViewModel |
| 26 | import androidx.lifecycle.ViewModelProvider | ||
| 27 | import androidx.lifecycle.ViewModelProviders | 25 | import androidx.lifecycle.ViewModelProviders |
| 28 | import androidx.lifecycle.lifecycleScope | 26 | import androidx.lifecycle.lifecycleScope |
| 29 | import androidx.navigation.NavController | 27 | import androidx.navigation.NavController |
| 30 | import androidx.navigation.Navigation | 28 | import androidx.navigation.Navigation |
| 31 | import androidx.recyclerview.widget.ItemTouchHelper | 29 | import androidx.recyclerview.widget.ItemTouchHelper |
| 32 | import androidx.recyclerview.widget.LinearLayoutManager | 30 | import androidx.recyclerview.widget.LinearLayoutManager |
| 33 | import androidx.recyclerview.widget.RecyclerView | 31 | import androidx.recyclerview.widget.RecyclerView |
| 34 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 32 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
| 35 | import com.focasoftware.deboinventariov20.Model.Articles | 33 | import com.focasoftware.deboinventariov20.Model.* |
| 36 | import com.focasoftware.deboinventariov20.Model.InvBody | ||
| 37 | import com.focasoftware.deboinventariov20.Model.InvHead | ||
| 38 | import com.focasoftware.deboinventariov20.R | 34 | import com.focasoftware.deboinventariov20.R |
| 39 | import com.focasoftware.deboinventariov20.UI.Utils.NoEncontradoSimple | 35 | import com.focasoftware.deboinventariov20.UI.Utils.NoEncontradoSimple |
| 36 | import com.focasoftware.deboinventariov20.UI.Utils.ObtenerFechaActual | ||
| 40 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera | 37 | import com.focasoftware.deboinventariov20.UI.Utils.modificarCantidadEnCabecera |
| 41 | import com.focasoftware.deboinventariov20.UI.inventario.viewModel.InventarioViewModel | 38 | import com.focasoftware.deboinventariov20.UI.inventario.viewModel.InventarioViewModel |
| 42 | import kotlinx.android.synthetic.main.fragment_inventario.* | 39 | import kotlinx.android.synthetic.main.fragment_inventario.* |
| 43 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* | 40 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* |
| 44 | import kotlinx.android.synthetic.main.login_dialog.view.* | 41 | import kotlinx.android.synthetic.main.login_dialog.view.* |
| 45 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar | 42 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar |
| 46 | import kotlinx.coroutines.* | 43 | import kotlinx.coroutines.* |
| 47 | import kotlinx.coroutines.Dispatchers.IO | 44 | import kotlinx.coroutines.Dispatchers.IO |
| 48 | import java.time.LocalDateTime | 45 | import retrofit2.Call |
| 49 | import java.time.format.DateTimeFormatter | 46 | import retrofit2.Callback |
| 47 | import retrofit2.Response | ||
| 50 | import java.util.* | 48 | import java.util.* |
| 51 | 49 | ||
| 52 | class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickListener { | 50 | class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickListener { |
| 53 | 51 | ||
| 54 | private lateinit var sharedPreferences: SharedPreferences | 52 | private lateinit var sharedPreferences: SharedPreferences |
| 55 | private var iArea: Boolean = false | 53 | private var iArea: Boolean = false |
| 56 | private lateinit var invHead: InvHead | 54 | private lateinit var invHead: InvHead |
| 57 | private lateinit var rcInventarios: RecyclerView | 55 | private lateinit var rcInventarios: RecyclerView |
| 58 | private lateinit var viewAdapter: RecyclerView.Adapter<*> | 56 | private lateinit var viewAdapter: RecyclerView.Adapter<*> |
| 59 | private lateinit var viewManager: RecyclerView.LayoutManager | 57 | private lateinit var viewManager: RecyclerView.LayoutManager |
| 60 | private lateinit var sChangeUpper: String | 58 | private lateinit var sChangeUpper: String |
| 61 | private var listArticulos = ArrayList<ItemsRecycler>() | 59 | private var listArticulos = ArrayList<ItemsRecycler>() |
| 62 | private lateinit var navController: NavController | 60 | private lateinit var navController: NavController |
| 63 | var InventarioNuevo: Int = 0 | 61 | var InventarioNuevo: Int = 0 |
| 64 | private var iEstado = 0 | 62 | private var iEstado = 0 |
| 65 | private var iBusquedaPor = 0 | 63 | private var iBusquedaPor = 0 |
| 66 | private var fCant = 0F | 64 | private var fCant = 0F |
| 67 | private var bFirst = false | 65 | private var bFirst = false |
| 68 | private lateinit var deleteIcon: Drawable | 66 | private lateinit var deleteIcon: Drawable |
| 69 | lateinit var mDialogView: View | 67 | lateinit var mDialogView: View |
| 70 | lateinit var inventarioViewModel: ViewModel | 68 | lateinit var inventarioViewModel: ViewModel |
| 71 | 69 | ||
| 72 | @SuppressLint("MissingPermission") | 70 | @SuppressLint("MissingPermission") |
| 73 | override fun onCreate(savedInstanceState: Bundle?) { | 71 | override fun onCreate(savedInstanceState: Bundle?) { |
| 74 | super.onCreate(savedInstanceState) | 72 | super.onCreate(savedInstanceState) |
| 75 | inventarioViewModel= ViewModelProviders.of(this).get(InventarioViewModel::class.java) | 73 | inventarioViewModel= ViewModelProviders.of(this).get(InventarioViewModel::class.java) |
| 76 | 74 | ||
| 77 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 75 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
| 78 | if (sharedPreferences.contains("Inventario")) if (sharedPreferences.getString("Inventario", "").toString() != "-1") { | 76 | if (sharedPreferences.contains("Inventario")) if (sharedPreferences.getString("Inventario", "").toString() != "-1") { |
| 79 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = sharedPreferences.getString("Inventario", "").toString().toInt() | 77 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = sharedPreferences.getString("Inventario", "").toString().toInt() |
| 80 | val editor = sharedPreferences.edit() | 78 | val editor = sharedPreferences.edit() |
| 81 | editor?.putString("Inventario", "-1") | 79 | editor?.putString("Inventario", "-1") |
| 82 | editor?.apply() | 80 | editor?.apply() |
| 83 | editor.commit() | 81 | editor.commit() |
| 84 | } | 82 | } |
| 85 | // val c = Calendar.getInstance() | 83 | // val c = Calendar.getInstance() |
| 86 | // c[2009, 9, 9, 12, 0] = 0 | 84 | // c[2009, 9, 9, 12, 0] = 0 |
| 87 | // val am: AlarmManager = requireActivity().getSystemService(Context.ALARM_SERVICE) as AlarmManager | 85 | // val am: AlarmManager = requireActivity().getSystemService(Context.ALARM_SERVICE) as AlarmManager |
| 88 | // am.setTime(c.timeInMillis) | 86 | // am.setTime(c.timeInMillis) |
| 89 | } | 87 | } |
| 90 | // private fun setupTimeZone(timeZoneName: String) { | 88 | // private fun setupTimeZone(timeZoneName: String) { |
| 91 | // val am = requireContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager | 89 | // val am = requireContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager |
| 92 | // am.setTimeZone("Europe/Madrid") | 90 | // am.setTimeZone("Europe/Madrid") |
| 93 | // } | 91 | // } |
| 94 | 92 | ||
| 95 | 93 | ||
| 96 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 94 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
| 97 | val v = inflater.inflate(R.layout.fragment_inventario, container, false) | 95 | val v = inflater.inflate(R.layout.fragment_inventario, container, false) |
| 98 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 96 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
| 99 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) | 97 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) |
| 100 | rcInventarios = v.findViewById(R.id.rcInventarios) | 98 | rcInventarios = v.findViewById(R.id.rcInventarios) |
| 101 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) | 99 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) |
| 100 | val descArea: String = if (!SerchArea()) "Ventas" else "Deposito" | ||
| 102 | 101 | ||
| 103 | if ((inventarioViewModel as InventarioViewModel).InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO | 102 | if ((inventarioViewModel as InventarioViewModel).InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO |
| 104 | GlobalScope.launch(Dispatchers.Main) { | 103 | GlobalScope.launch(Dispatchers.Main) { |
| 105 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO | 104 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO |
| 106 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = AppDb.getAppDb(requireActivity())?.InvHeadDAO()?.findLastInv()?.plus(1) ?: 1 | 105 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = AppDb.getAppDb(requireActivity())?.InvHeadDAO()?.findLastInv()?.plus(1) ?: 1 |
| 107 | //TODO: CREAMOS EL INVENTARIO EN LA CABECERA DEL INVENTARIO | 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 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.insertInvHead(invHead) | 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 | } else {// TODO (SI VENGO DE FRAGMENT DESCRIPCION) | 122 | } else {// TODO (SI VENGO DE FRAGMENT DESCRIPCION) |
| 113 | listArticulos.clear() | 123 | listArticulos.clear() |
| 114 | CargarDeBdInventario((inventarioViewModel as InventarioViewModel).InventarioNuevo) | 124 | cargarDeBdInventario((inventarioViewModel as InventarioViewModel).InventarioNuevo) |
| 115 | tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo}" | 125 | tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo} "+ descArea |
| 116 | } | 126 | } |
| 117 | 127 | ||
| 118 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> | 128 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> |
| 119 | if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_UP) { | 129 | if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_UP) { |
| 120 | sChangeUpper = tCodigoBarras.text.toString() | 130 | sChangeUpper = tCodigoBarras.text.toString() |
| 121 | var indiceDelArtEncontrado = 0 | 131 | var indiceDelArtEncontrado = 0 |
| 122 | 132 | ||
| 123 | if (tCodigoBarras.text.isNullOrBlank() ) { | 133 | if (tCodigoBarras.text.isNullOrBlank() ) { |
| 124 | tCodigoBarras.error = "No puede estar vacio" | 134 | tCodigoBarras.error = "No puede estar vacio" |
| 125 | tCodigoBarras.requestFocus() | 135 | tCodigoBarras.requestFocus() |
| 126 | tCodigoBarras.hint = "No puede estar vacio" | 136 | tCodigoBarras.hint = "No puede estar vacio" |
| 127 | }else if (tCodigoBarras.text.toString().length<4 && iEstado==2) { | 137 | }else if (tCodigoBarras.text.toString().length<4 && iEstado==2) { |
| 128 | tCodigoBarras.error = "Minimo 4 caracteres" | 138 | tCodigoBarras.error = "Minimo 4 caracteres" |
| 129 | tCodigoBarras.requestFocus() | 139 | tCodigoBarras.requestFocus() |
| 130 | tCodigoBarras.hint = "4 Minimo" | 140 | tCodigoBarras.hint = "4 Minimo" |
| 131 | 141 | ||
| 132 | } else { | 142 | } else { |
| 133 | 143 | ||
| 134 | //TODO COMIENZA LA BUSQUEDA POR CODIGO DE BARRAS | 144 | //TODO COMIENZA LA BUSQUEDA POR CODIGO DE BARRAS |
| 135 | when (iBusquedaPor) { | 145 | when (iBusquedaPor) { |
| 136 | 0 -> { | 146 | 0 -> { |
| 137 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER | 147 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
| 138 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 148 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
| 139 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 149 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
| 140 | 150 | ||
| 141 | GlobalScope.launch(Dispatchers.Main) { | 151 | GlobalScope.launch(Dispatchers.Main) { |
| 142 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 0)//TODO Si encuentra el articulo en el RV devuelve el indice | 152 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 0)//TODO Si encuentra el articulo en el RV devuelve el indice |
| 143 | //TODO (Si no lo encuentra devuelve -1) | 153 | //TODO (Si no lo encuentra devuelve -1) |
| 144 | if (indiceDelArtEncontrado != -1) { | 154 | if (indiceDelArtEncontrado != -1) { |
| 145 | if (swSumaUno!!.isChecked) { | 155 | if (swSumaUno!!.isChecked) { |
| 146 | // fCant = 0F | 156 | // fCant = 0F |
| 147 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 157 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 148 | // fCant += 1F | 158 | // fCant += 1F |
| 149 | //TODO ACTUALIZO LA CANTIDAD EN LA BD | 159 | //TODO ACTUALIZO LA CANTIDAD EN LA BD |
| 150 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), | 160 | updateCantidad( |
| 161 | listArticulos[indiceDelArtEncontrado].sector.toString(), | ||
| 151 | listArticulos[indiceDelArtEncontrado].codigo.toString(), | 162 | listArticulos[indiceDelArtEncontrado].codigo.toString(), |
| 152 | listArticulos[indiceDelArtEncontrado].cantTomada + 1) | 163 | listArticulos[indiceDelArtEncontrado].cantTomada + 1 |
| 164 | ) | ||
| 153 | //TODO ACTUALIZO LA CANTIDAD EN EL RV | 165 | //TODO ACTUALIZO LA CANTIDAD EN EL RV |
| 154 | listArticulos[indiceDelArtEncontrado].cantTomada = listArticulos[indiceDelArtEncontrado].cantTomada + 1 | 166 | listArticulos[indiceDelArtEncontrado].cantTomada = listArticulos[indiceDelArtEncontrado].cantTomada + 1 |
| 155 | viewAdapter.notifyDataSetChanged() | 167 | viewAdapter.notifyDataSetChanged() |
| 156 | } else { | 168 | } else { |
| 157 | dialogoSumaResta(requireContext(), indiceDelArtEncontrado, listArticulos[indiceDelArtEncontrado].univta, false) | 169 | dialogoSumaResta(requireContext(), indiceDelArtEncontrado, listArticulos[indiceDelArtEncontrado].univta, false) |
| 158 | } | 170 | } |
| 159 | 171 | ||
| 160 | } else if (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD | 172 | } else if (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD |
| 161 | //TODO BUSCO EN BASE DE DATOS | 173 | //TODO BUSCO EN BASE DE DATOS |
| 162 | val artEncontrado = buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 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 | tCodigoBarras.focusable = View.FOCUSABLE | 177 | tCodigoBarras.focusable = View.FOCUSABLE |
| 166 | tCodigoBarras.setText("") | 178 | tCodigoBarras.setText("") |
| 167 | tCodigoBarras.selectAll() | 179 | tCodigoBarras.selectAll() |
| 168 | } | 180 | } |
| 169 | return@setOnKeyListener true | 181 | return@setOnKeyListener true |
| 170 | 182 | ||
| 171 | 183 | ||
| 172 | } | 184 | } |
| 173 | 1 -> {//TODO: BUSQUEDA POR DESCRIPCION************************************************************************** | 185 | 1 -> {//TODO: BUSQUEDA POR DESCRIPCION************************************************************************** |
| 174 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER | 186 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
| 175 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 187 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
| 176 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 188 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
| 177 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 1) //TODO :Si encuentra el articulo en el RV devuelve el indice | 189 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 1) //TODO :Si encuentra el articulo en el RV devuelve el indice |
| 178 | // //TODO Si no lo encuentra devuelve -1 | 190 | // //TODO Si no lo encuentra devuelve -1 |
| 179 | // if (indiceDelArtEncontrado != -1) { | 191 | // if (indiceDelArtEncontrado != -1) { |
| 180 | //// if (swSumaUno!!.isChecked) { | 192 | //// if (swSumaUno!!.isChecked) { |
| 181 | //// fCant = 0F | 193 | //// fCant = 0F |
| 182 | //// fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 194 | //// fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 183 | //// fCant += 1F | 195 | //// fCant += 1F |
| 184 | //// listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 196 | //// listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 185 | //// viewAdapter.notifyDataSetChanged() | 197 | //// viewAdapter.notifyDataSetChanged() |
| 186 | //// } else { | 198 | //// } else { |
| 187 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 199 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 188 | // MaterialDialog(requireContext()).show { | 200 | // MaterialDialog(requireContext()).show { |
| 189 | // title(R.string.sTituloNueva) | 201 | // title(R.string.sTituloNueva) |
| 190 | // message(R.string.sCantidadNueva) | 202 | // message(R.string.sCantidadNueva) |
| 191 | // input { materialDialog, charSequence -> | 203 | // input { materialDialog, charSequence -> |
| 192 | // fCant = 0F | 204 | // fCant = 0F |
| 193 | // fCant = charSequence.toString().toFloat() | 205 | // fCant = charSequence.toString().toFloat() |
| 194 | // } | 206 | // } |
| 195 | // positiveButton(R.string.btnOk) { | 207 | // positiveButton(R.string.btnOk) { |
| 196 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 208 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 197 | // viewAdapter.notifyDataSetChanged() | 209 | // viewAdapter.notifyDataSetChanged() |
| 198 | // dismiss() | 210 | // dismiss() |
| 199 | // } | 211 | // } |
| 200 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 212 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
| 201 | //// } | 213 | //// } |
| 202 | // | 214 | // |
| 203 | // } else if | 215 | // } else if |
| 204 | // (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD | 216 | // (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD |
| 205 | GlobalScope.launch(Dispatchers.Main) { | 217 | GlobalScope.launch(Dispatchers.Main) { |
| 206 | val artEncontrado = buscarDescEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 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 | iBusquedaPor = 0 | 222 | iBusquedaPor = 0 |
| 211 | // } | 223 | // } |
| 212 | 224 | ||
| 213 | return@setOnKeyListener true | 225 | return@setOnKeyListener true |
| 214 | } | 226 | } |
| 215 | 2 -> {//TODO: BUSQUEDA POR CODIGO DE ORIGEN************************************************************************** | 227 | 2 -> {//TODO: BUSQUEDA POR CODIGO DE ORIGEN************************************************************************** |
| 216 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 228 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
| 217 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 229 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
| 218 | 230 | ||
| 219 | // GlobalScope.launch(Dispatchers.Main) { | 231 | // GlobalScope.launch(Dispatchers.Main) { |
| 220 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 2)//TODO Si encuentra el articulo en el RV devuelve el indice | 232 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 2)//TODO Si encuentra el articulo en el RV devuelve el indice |
| 221 | //// //TODO Si no lo encuentra devuelve -1 | 233 | //// //TODO Si no lo encuentra devuelve -1 |
| 222 | // if (indiceDelArtEncontrado != -1) { | 234 | // if (indiceDelArtEncontrado != -1) { |
| 223 | // if (swSumaUno!!.isChecked) { | 235 | // if (swSumaUno!!.isChecked) { |
| 224 | // fCant = 0F | 236 | // fCant = 0F |
| 225 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 237 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 226 | // fCant += 1F | 238 | // fCant += 1F |
| 227 | // //TODO ACTUALIZO LA CANTIDAD EN LA BD | 239 | // //TODO ACTUALIZO LA CANTIDAD EN LA BD |
| 228 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 240 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
| 229 | // //TODO ACTUALIZO LA CANTIDAD EN EL RV | 241 | // //TODO ACTUALIZO LA CANTIDAD EN EL RV |
| 230 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 242 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 231 | // viewAdapter.notifyDataSetChanged() | 243 | // viewAdapter.notifyDataSetChanged() |
| 232 | // } else { | 244 | // } else { |
| 233 | // dialogoSumaResta(requireContext(), indiceDelArtEncontrado, listArticulos[indiceDelArtEncontrado].univta, false) | 245 | // dialogoSumaResta(requireContext(), indiceDelArtEncontrado, listArticulos[indiceDelArtEncontrado].univta, false) |
| 234 | // } | 246 | // } |
| 235 | // } else { | 247 | // } else { |
| 236 | // val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 248 | // val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
| 237 | // val mBuilder = | 249 | // val mBuilder = |
| 238 | // AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[indiceDelArtEncontrado].descripcion}', se encuentra cargado.") | 250 | // AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[indiceDelArtEncontrado].descripcion}', se encuentra cargado.") |
| 239 | // .setCancelable(false) | 251 | // .setCancelable(false) |
| 240 | // mDialogView.tvCantInicial.text = listArticulos[indiceDelArtEncontrado].cantTomada.toString() | 252 | // mDialogView.tvCantInicial.text = listArticulos[indiceDelArtEncontrado].cantTomada.toString() |
| 241 | // val mAlertDialog = mBuilder.show() | 253 | // val mAlertDialog = mBuilder.show() |
| 242 | // mDialogView.rbSumar.setOnClickListener { | 254 | // mDialogView.rbSumar.setOnClickListener { |
| 243 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 255 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 244 | // mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 256 | // mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 245 | // } | 257 | // } |
| 246 | // } | 258 | // } |
| 247 | // mDialogView.rbRestar.setOnClickListener { | 259 | // mDialogView.rbRestar.setOnClickListener { |
| 248 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 260 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 249 | // if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 261 | // if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
| 250 | // mDialogView.tvgenerico4.text = | 262 | // mDialogView.tvgenerico4.text = |
| 251 | // (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 263 | // (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 252 | // } | 264 | // } |
| 253 | // } | 265 | // } |
| 254 | // } | 266 | // } |
| 255 | // mDialogView.rbMdodificar.setOnClickListener { | 267 | // mDialogView.rbMdodificar.setOnClickListener { |
| 256 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 268 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 257 | // mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 269 | // mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 258 | // } | 270 | // } |
| 259 | // } | 271 | // } |
| 260 | // mDialogView.btnAceptar.setOnClickListener { | 272 | // mDialogView.btnAceptar.setOnClickListener { |
| 261 | // mAlertDialog.dismiss() | 273 | // mAlertDialog.dismiss() |
| 262 | // val name = mDialogView.tvgenerico4.text.toString().toFloat() | 274 | // val name = mDialogView.tvgenerico4.text.toString().toFloat() |
| 263 | // fCant = 0F | 275 | // fCant = 0F |
| 264 | // fCant = name | 276 | // fCant = name |
| 265 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 277 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 266 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 278 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
| 267 | // viewAdapter.notifyDataSetChanged() | 279 | // viewAdapter.notifyDataSetChanged() |
| 268 | // } | 280 | // } |
| 269 | // mDialogView.dialogCancelBtn.setOnClickListener { | 281 | // mDialogView.dialogCancelBtn.setOnClickListener { |
| 270 | // mAlertDialog.dismiss() | 282 | // mAlertDialog.dismiss() |
| 271 | // } | 283 | // } |
| 272 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 284 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 273 | // val type = InputType.TYPE_CLASS_NUMBER | 285 | // val type = InputType.TYPE_CLASS_NUMBER |
| 274 | // MaterialDialog(requireContext()).show { | 286 | // MaterialDialog(requireContext()).show { |
| 275 | // | 287 | // |
| 276 | // title(text = "Producto '$sChangeUpper', se encuentra cargado.") | 288 | // title(text = "Producto '$sChangeUpper', se encuentra cargado.") |
| 277 | // message(R.string.sCantidadNueva) | 289 | // message(R.string.sCantidadNueva) |
| 278 | // input(waitForPositiveButton = false, hint = "99.99", inputType = type) { materialDialog, charSequence -> | 290 | // input(waitForPositiveButton = false, hint = "99.99", inputType = type) { materialDialog, charSequence -> |
| 279 | // fCant = 0F | 291 | // fCant = 0F |
| 280 | // fCant = charSequence.toString().toFloat() | 292 | // fCant = charSequence.toString().toFloat() |
| 281 | // } | 293 | // } |
| 282 | // positiveButton(R.string.btnOk) { | 294 | // positiveButton(R.string.btnOk) { |
| 283 | // //TODO ACTUALIZO CANTIADAD EN BD | 295 | // //TODO ACTUALIZO CANTIADAD EN BD |
| 284 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 296 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
| 285 | // //TODO ACTUALIZO CANTIDAD EN RV | 297 | // //TODO ACTUALIZO CANTIDAD EN RV |
| 286 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 298 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 287 | // viewAdapter.notifyDataSetChanged() | 299 | // viewAdapter.notifyDataSetChanged() |
| 288 | // dismiss() | 300 | // dismiss() |
| 289 | // } | 301 | // } |
| 290 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 302 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
| 291 | // } | 303 | // } |
| 292 | // } else if (indiceDelArtEncontrado == -1) { | 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) { | 307 | GlobalScope.launch(Dispatchers.Main) { |
| 296 | //TODO BUSCO EN BASE DE DATOS | 308 | //TODO BUSCO EN BASE DE DATOS |
| 297 | val artEncontrado = buscarCodiogoOriEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 309 | val artEncontrado = buscarCodiogoOriEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
| 298 | ContinuarCargaCodigoOri(artEncontrado ) | 310 | continuarCargaCodigoOri(artEncontrado) |
| 299 | } | 311 | } |
| 300 | iBusquedaPor = 0 | 312 | iBusquedaPor = 0 |
| 301 | // } | 313 | // } |
| 302 | // } | 314 | // } |
| 303 | return@setOnKeyListener true | 315 | return@setOnKeyListener true |
| 304 | } | 316 | } |
| 305 | } | 317 | } |
| 306 | } | 318 | } |
| 307 | } | 319 | } |
| 308 | return@setOnKeyListener false | 320 | return@setOnKeyListener false |
| 309 | } | 321 | } |
| 310 | return v | 322 | return v |
| 311 | } | 323 | } |
| 312 | 324 | ||
| 313 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 325 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
| 314 | super.onViewCreated(view, savedInstanceState) | 326 | super.onViewCreated(view, savedInstanceState) |
| 315 | navController = Navigation.findNavController(view) | 327 | navController = Navigation.findNavController(view) |
| 316 | etCodigoBarras.requestFocus() | 328 | etCodigoBarras.requestFocus() |
| 317 | // val modalDialog = NoEncontradoSimple() | 329 | // val modalDialog = NoEncontradoSimple() |
| 318 | // modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") | 330 | // modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
| 319 | 331 | ||
| 320 | btnBorrarInv.setOnClickListener { | 332 | btnBorrarInv.setOnClickListener { |
| 321 | AlertDialog.Builder(requireContext()).setTitle("Eliminación de Inventarios").setMessage("¿Confirma que desea eliminar el inventario?") | 333 | AlertDialog.Builder(requireContext()).setTitle("Eliminación de Inventarios").setMessage("¿Confirma que desea eliminar el inventario?") |
| 322 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> | 334 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> |
| 323 | BorrarInvActual() | 335 | borrarInvActual() |
| 324 | Toast.makeText(requireContext(), "El inventario $(inventarioViewModel as InventarioViewModel).InventarioNuevo fue Borrado", Toast.LENGTH_LONG).show() | 336 | Toast.makeText(requireContext(), "El inventario $(inventarioViewModel as InventarioViewModel).InventarioNuevo fue Borrado", Toast.LENGTH_LONG).show() |
| 325 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) | 337 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
| 326 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 | 338 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 |
| 327 | 339 | ||
| 328 | }).setNegativeButton(R.string.btnCancelar, DialogInterface.OnClickListener { dialog, which -> | 340 | }).setNegativeButton(R.string.btnCancelar, DialogInterface.OnClickListener { dialog, which -> |
| 329 | //botón cancel pulsado | 341 | //botón cancel pulsado |
| 330 | }).show() | 342 | }).show() |
| 331 | } | 343 | } |
| 332 | 344 | ||
| 333 | btnExportarInv.setOnClickListener { | 345 | btnExportarInv.setOnClickListener { |
| 334 | AlertDialog.Builder(requireContext()).setTitle(R.string.sTituloExportar).setMessage(R.string.sMensajeExportar) | 346 | AlertDialog.Builder(requireContext()).setTitle(R.string.sTituloExportar).setMessage(R.string.sMensajeExportar) |
| 335 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> | 347 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> |
| 336 | BorrarInvActual() | 348 | exportarInventario(InventarioNuevo) |
| 349 | borrarInvActual() | ||
| 337 | Toast.makeText(requireContext(), "El inventario $(inventarioViewModel as InventarioViewModel).InventarioNuevo fue Exportado al Servidor", Toast.LENGTH_LONG).show() | 350 | Toast.makeText(requireContext(), "El inventario $(inventarioViewModel as InventarioViewModel).InventarioNuevo fue Exportado al Servidor", Toast.LENGTH_LONG).show() |
| 338 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) | 351 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
| 339 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 | 352 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 |
| 340 | 353 | ||
| 341 | }).setNegativeButton(R.string.btnCancelar, DialogInterface.OnClickListener { dialog, which -> }).show() | 354 | }).setNegativeButton(R.string.btnCancelar, DialogInterface.OnClickListener { dialog, which -> }).show() |
| 342 | } | 355 | } |
| 343 | ivCamara.setOnClickListener { | 356 | ivCamara.setOnClickListener { |
| 344 | if (!bFirst) { | 357 | if (!bFirst) { |
| 345 | iEstado = 1 | 358 | iEstado = 1 |
| 346 | bFirst = true | 359 | bFirst = true |
| 347 | } | 360 | } |
| 348 | 361 | ||
| 349 | when (iEstado) { | 362 | when (iEstado) { |
| 350 | 0 -> { | 363 | 0 -> { |
| 351 | ivCamara.setImageResource(R.drawable.codbar) | 364 | ivCamara.setImageResource(R.drawable.codbar) |
| 352 | etCodigoBarras.hint = "Busqueda por Código de Barras" | 365 | etCodigoBarras.hint = "Busqueda por Código de Barras" |
| 353 | swSumaUno.visibility = View.VISIBLE | 366 | swSumaUno.visibility = View.VISIBLE |
| 354 | iBusquedaPor = 0 | 367 | iBusquedaPor = 0 |
| 355 | iEstado = 1 | 368 | iEstado = 1 |
| 356 | } | 369 | } |
| 357 | 1 -> { | 370 | 1 -> { |
| 358 | ivCamara.setImageResource(R.drawable.desc) | 371 | ivCamara.setImageResource(R.drawable.desc) |
| 359 | etCodigoBarras.hint = "Busqueda por Descripción" | 372 | etCodigoBarras.hint = "Busqueda por Descripción" |
| 360 | swSumaUno.visibility = View.GONE | 373 | swSumaUno.visibility = View.GONE |
| 361 | iBusquedaPor = 1 | 374 | iBusquedaPor = 1 |
| 362 | iEstado = 2 | 375 | iEstado = 2 |
| 363 | } | 376 | } |
| 364 | 2 -> { | 377 | 2 -> { |
| 365 | ivCamara.setImageResource(R.drawable.cod_origen) | 378 | ivCamara.setImageResource(R.drawable.cod_origen) |
| 366 | etCodigoBarras.hint = "Busqueda por Código de Origen" | 379 | etCodigoBarras.hint = "Busqueda por Código de Origen" |
| 367 | swSumaUno.visibility = View.GONE | 380 | swSumaUno.visibility = View.GONE |
| 368 | iBusquedaPor = 2 | 381 | iBusquedaPor = 2 |
| 369 | iEstado = 0 | 382 | iEstado = 0 |
| 370 | } | 383 | } |
| 371 | } | 384 | } |
| 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 | lifecycleScope.launch { | 449 | lifecycleScope.launch { |
| 377 | withContext(Dispatchers.IO) { | 450 | withContext(Dispatchers.IO) { |
| 378 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.deleteinvHead((inventarioViewModel as InventarioViewModel).InventarioNuevo.toLong()) | 451 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.deleteinvHead((inventarioViewModel as InventarioViewModel).InventarioNuevo) |
| 379 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.deleteInvBody((inventarioViewModel as InventarioViewModel).InventarioNuevo.toLong()) | 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 | GlobalScope.launch(Dispatchers.Main) { | 458 | GlobalScope.launch(Dispatchers.Main) { |
| 386 | val invbody = cargarInventario(ultimoInv) | 459 | val invbody = cargarInventario(ultimoInv) |
| 387 | for ((i, _) in invbody!!.withIndex()) { | 460 | for ((i, _) in invbody!!.withIndex()) { |
| 388 | val art = Articles(invbody[i].sector, | 461 | val art = Articles( |
| 462 | invbody[i].sector, | ||
| 389 | invbody[i].codigo, | 463 | invbody[i].codigo, |
| 390 | invbody[i].descripcion, | 464 | invbody[i].descripcion, |
| 391 | invbody[i].codBar, | 465 | invbody[i].codBar, |
| 392 | invbody[i].codOrigen, | 466 | invbody[i].codOrigen, |
| 393 | invbody[i].precio, | 467 | invbody[i].precio, |
| 394 | invbody[i].costo, | 468 | invbody[i].costo, |
| 395 | "", | 469 | "", |
| 396 | "", | 470 | "", |
| 397 | "", | 471 | "", |
| 398 | invbody[i].balanza, | 472 | invbody[i].balanza, |
| 399 | invbody[i].depSn, | 473 | invbody[i].depSn, |
| 400 | invbody[i].costo) | 474 | invbody[i].costo) |
| 401 | cargarRecicler(art, invbody[i].cantTomada!!.toFloat()) | 475 | cargarRecicler(art, invbody[i].cantTomada!!.toFloat()) |
| 402 | } | 476 | } |
| 403 | } | 477 | } |
| 404 | } | 478 | } |
| 405 | 479 | ||
| 406 | private fun ContinuarCargaCodigoOri(artAcargar:List<Articles>) { | 480 | private fun continuarCargaCodigoOri(artAcargar: List<Articles>) { |
| 407 | 481 | ||
| 408 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD | 482 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD |
| 409 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER | 483 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
| 410 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 484 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
| 411 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 485 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
| 412 | 486 | ||
| 413 | var bundle = Bundle() | 487 | var bundle = Bundle() |
| 414 | bundle = bundleOf("ArrayDesc" to artAcargar) | 488 | bundle = bundleOf("ArrayDesc" to artAcargar) |
| 415 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) | 489 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) |
| 416 | navController.navigate(R.id.action_inventarioFragment_to_codigoOriFragment, bundle) | 490 | navController.navigate(R.id.action_inventarioFragment_to_codigoOriFragment, bundle) |
| 417 | 491 | ||
| 418 | } else {//TODO si no lo encuentra en la BD | 492 | } else {//TODO si no lo encuentra en la BD |
| 419 | val modalDialog = NoEncontradoSimple() | 493 | val modalDialog = NoEncontradoSimple() |
| 420 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") | 494 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
| 421 | } | 495 | } |
| 422 | etCodigoBarras.focusable = View.FOCUSABLE | 496 | etCodigoBarras.focusable = View.FOCUSABLE |
| 423 | etCodigoBarras.setText("") | 497 | etCodigoBarras.setText("") |
| 424 | etCodigoBarras.selectAll() | 498 | etCodigoBarras.selectAll() |
| 425 | } | 499 | } |
| 426 | 500 | ||
| 427 | private fun ContinuarCargaDesc(artAcargar: ArrayList<Articles>) { | 501 | private fun continuarCargaDesc(artAcargar: ArrayList<Articles>) { |
| 428 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS | 502 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS |
| 429 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV | 503 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV |
| 430 | 504 | ||
| 431 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD | 505 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD |
| 432 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV | 506 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV |
| 433 | // fCant = 0F | 507 | // fCant = 0F |
| 434 | // fCant += 1F | 508 | // fCant += 1F |
| 435 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV | 509 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV |
| 436 | // val acargarPorDesc = Articles(artAcargar[0].sector, | 510 | // val acargarPorDesc = Articles(artAcargar[0].sector, |
| 437 | // artAcargar[0].codigo, | 511 | // artAcargar[0].codigo, |
| 438 | // artAcargar[0].descripcion, | 512 | // artAcargar[0].descripcion, |
| 439 | // artAcargar[0].codBar, | 513 | // artAcargar[0].codBar, |
| 440 | // artAcargar[0].codOrigen, | 514 | // artAcargar[0].codOrigen, |
| 441 | // artAcargar[0].precio, | 515 | // artAcargar[0].precio, |
| 442 | // artAcargar[0].costo, | 516 | // artAcargar[0].costo, |
| 443 | // "", | 517 | // "", |
| 444 | // "", | 518 | // "", |
| 445 | // "", | 519 | // "", |
| 446 | // artAcargar[0].balanza, | 520 | // artAcargar[0].balanza, |
| 447 | // artAcargar[0].depSn, | 521 | // artAcargar[0].depSn, |
| 448 | // "") | 522 | // "") |
| 449 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD | 523 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD |
| 450 | // cargarArtEnBd(acargarPorDesc, fCant) | 524 | // cargarArtEnBd(acargarPorDesc, fCant) |
| 451 | // cargarRecicler(acargarPorDesc, fCant) | 525 | // cargarRecicler(acargarPorDesc, fCant) |
| 452 | // } else { | 526 | // } else { |
| 453 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER | 527 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
| 454 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 528 | val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
| 455 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 529 | imm!!.hideSoftInputFromWindow(requireActivity().currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
| 456 | var bundle = Bundle() | 530 | var bundle = Bundle() |
| 457 | bundle = bundleOf("ArrayDesc" to artAcargar) | 531 | bundle = bundleOf("ArrayDesc" to artAcargar) |
| 458 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) | 532 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) |
| 459 | navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) | 533 | navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) |
| 460 | //navController.backStack.removeLast() | 534 | //navController.backStack.removeLast() |
| 461 | // } | 535 | // } |
| 462 | // } else {//SI NO ESTA +1 | 536 | // } else {//SI NO ESTA +1 |
| 463 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV | 537 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV |
| 464 | // fCant = listArticulos[0].cantTomada | 538 | // fCant = listArticulos[0].cantTomada |
| 465 | // MaterialDialog(requireContext()).show { | 539 | // MaterialDialog(requireContext()).show { |
| 466 | // title(R.string.sTituloNueva) | 540 | // title(R.string.sTituloNueva) |
| 467 | // message(R.string.sCantidadNueva) | 541 | // message(R.string.sCantidadNueva) |
| 468 | // input { materialDialog, charSequence -> | 542 | // input { materialDialog, charSequence -> |
| 469 | // fCant = 0F | 543 | // fCant = 0F |
| 470 | // fCant = charSequence.toString().toFloat() | 544 | // fCant = charSequence.toString().toFloat() |
| 471 | // } | 545 | // } |
| 472 | // positiveButton(R.string.btnOk) { | 546 | // positiveButton(R.string.btnOk) { |
| 473 | // listArticulos[0].cantTomada = fCant | 547 | // listArticulos[0].cantTomada = fCant |
| 474 | // viewAdapter.notifyDataSetChanged() | 548 | // viewAdapter.notifyDataSetChanged() |
| 475 | // dismiss() | 549 | // dismiss() |
| 476 | // } | 550 | // } |
| 477 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 551 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
| 478 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV | 552 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV |
| 479 | // val acargarPorDesc = Articles(artAcargar[0].sector, | 553 | // val acargarPorDesc = Articles(artAcargar[0].sector, |
| 480 | // artAcargar[0].codigo, | 554 | // artAcargar[0].codigo, |
| 481 | // artAcargar[0].descripcion, | 555 | // artAcargar[0].descripcion, |
| 482 | // artAcargar[0].codBar, | 556 | // artAcargar[0].codBar, |
| 483 | // artAcargar[0].cod_origen, | 557 | // artAcargar[0].cod_origen, |
| 484 | // artAcargar[0].precio, | 558 | // artAcargar[0].precio, |
| 485 | // artAcargar[0].costo, | 559 | // artAcargar[0].costo, |
| 486 | // artAcargar[0].balanza, | 560 | // artAcargar[0].balanza, |
| 487 | // artAcargar[0].depSn, | 561 | // artAcargar[0].depSn, |
| 488 | // "") | 562 | // "") |
| 489 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD | 563 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD |
| 490 | // cargarArtEnBd(acargarPorDesc, fCant) | 564 | // cargarArtEnBd(acargarPorDesc, fCant) |
| 491 | // cargarRecicler(acargarPorDesc, fCant) | 565 | // cargarRecicler(acargarPorDesc, fCant) |
| 492 | // } else { | 566 | // } else { |
| 493 | // var bundle = Bundle() | 567 | // var bundle = Bundle() |
| 494 | // bundle = bundleOf("ArrayDesc" to artAcargar) | 568 | // bundle = bundleOf("ArrayDesc" to artAcargar) |
| 495 | // bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) | 569 | // bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) |
| 496 | // navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) | 570 | // navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) |
| 497 | // } | 571 | // } |
| 498 | // } | 572 | // } |
| 499 | } else {//TODO si no lo encuentra en la BD | 573 | } else {//TODO si no lo encuentra en la BD |
| 500 | val modalDialog = NoEncontradoSimple() | 574 | val modalDialog = NoEncontradoSimple() |
| 501 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") | 575 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
| 502 | } | 576 | } |
| 503 | etCodigoBarras.focusable = View.FOCUSABLE | 577 | etCodigoBarras.focusable = View.FOCUSABLE |
| 504 | etCodigoBarras.setText("") | 578 | etCodigoBarras.setText("") |
| 505 | etCodigoBarras.selectAll() | 579 | etCodigoBarras.selectAll() |
| 506 | } | 580 | } |
| 507 | 581 | ||
| 508 | private fun ContinuarCargaCB(artAcargar: Articles?) { | 582 | private fun continuarCargaCB(artAcargar: Articles?) { |
| 509 | 583 | ||
| 510 | if (artAcargar != null) {// TODO: Si lo encuentra en la BD | 584 | if (artAcargar != null) {// TODO: Si lo encuentra en la BD |
| 511 | if (swSumaUno!!.isChecked) {//TODO: SI ESTA +1, PONE CANTIDAD 1 | 585 | if (swSumaUno!!.isChecked) {//TODO: SI ESTA +1, PONE CANTIDAD 1 |
| 512 | fCant = 0F | 586 | fCant = 0F |
| 513 | fCant += 1F | 587 | fCant += 1F |
| 514 | cargarArtEnBd(artAcargar, String.format("%.3f", fCant)) | 588 | cargarArtEnBd(artAcargar, String.format("%.3f", fCant)) |
| 515 | cargarRecicler(artAcargar, fCant) | 589 | cargarRecicler(artAcargar, fCant) |
| 516 | } else {//TODO: SI NO ESTA +1 PREGUNTA CANTIDAD | 590 | } else {//TODO: SI NO ESTA +1 PREGUNTA CANTIDAD |
| 517 | 591 | ||
| 518 | DialogingresarCantidad(requireContext(), artAcargar) | 592 | dialogingresarCantidad(requireContext(), artAcargar) |
| 519 | 593 | ||
| 520 | } | 594 | } |
| 521 | } else {// TODO si no lo encuentra en la BD | 595 | } else {// TODO si no lo encuentra en la BD |
| 522 | val modalDialog = NoEncontradoSimple() | 596 | val modalDialog = NoEncontradoSimple() |
| 523 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") | 597 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
| 524 | } | 598 | } |
| 525 | etCodigoBarras.focusable = View.FOCUSABLE | 599 | etCodigoBarras.focusable = View.FOCUSABLE |
| 526 | etCodigoBarras.setText("") | 600 | etCodigoBarras.setText("") |
| 527 | etCodigoBarras.selectAll() | 601 | etCodigoBarras.selectAll() |
| 528 | } | 602 | } |
| 529 | 603 | ||
| 530 | fun DialogingresarCantidad(cnxt: Context, artAcargar: Articles?): Float { | 604 | fun dialogingresarCantidad(cnxt: Context, artAcargar: Articles?): Float { |
| 531 | var cantidad = 0F | 605 | var cantidad = 0F |
| 532 | val mDialogView = LayoutInflater.from(cnxt).inflate(R.layout.ingresar_cantidad, null) | 606 | val mDialogView = LayoutInflater.from(cnxt).inflate(R.layout.ingresar_cantidad, null) |
| 533 | val mBuilder = AlertDialog.Builder(cnxt).setView(mDialogView).setCancelable(false) | 607 | val mBuilder = AlertDialog.Builder(cnxt).setView(mDialogView).setCancelable(false) |
| 534 | if (artAcargar!!.balanza!!.toInt() == 1 || artAcargar.balanza!!.toInt() == 3 || artAcargar.balanza!!.toInt() == 7) mDialogView.etCantidad.inputType = TYPE_CLASS_NUMBER | 608 | if (artAcargar!!.balanza!!.toInt() == 1 || artAcargar.balanza!!.toInt() == 3 || artAcargar.balanza!!.toInt() == 7) mDialogView.etCantidad.inputType = TYPE_CLASS_NUMBER |
| 535 | mDialogView.tvTitulo.text = artAcargar.descripcion.toString() | 609 | mDialogView.tvTitulo.text = artAcargar.descripcion.toString() |
| 536 | val mAlertDialog = mBuilder.show() | 610 | val mAlertDialog = mBuilder.show() |
| 537 | 611 | ||
| 538 | mDialogView.etCantidad.requestFocus() | 612 | mDialogView.etCantidad.requestFocus() |
| 539 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 613 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
| 540 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 614 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
| 541 | 615 | ||
| 542 | mDialogView.btnAceptar.setOnClickListener { | 616 | mDialogView.btnAceptar.setOnClickListener { |
| 543 | if (mDialogView.etCantidad.text.isNullOrEmpty()) { | 617 | if (mDialogView.etCantidad.text.isNullOrEmpty()) { |
| 544 | mDialogView.etCantidad.error = "No vacio" | 618 | mDialogView.etCantidad.error = "No vacio" |
| 545 | mDialogView.etCantidad.requestFocus() | 619 | mDialogView.etCantidad.requestFocus() |
| 546 | mDialogView.etCantidad.hint = "Ingrese un valor" | 620 | mDialogView.etCantidad.hint = "Ingrese un valor" |
| 547 | } else if (!mDialogView.etCantidad.text.isNullOrEmpty()) { | 621 | } else if (!mDialogView.etCantidad.text.isNullOrEmpty()) { |
| 548 | mAlertDialog.dismiss() | 622 | mAlertDialog.dismiss() |
| 549 | cantidad = mDialogView.etCantidad.text.toString().toFloat() | 623 | cantidad = mDialogView.etCantidad.text.toString().toFloat() |
| 550 | cargarArtEnBd(artAcargar, String.format("%.2f", cantidad)) | 624 | cargarArtEnBd(artAcargar, String.format("%.2f", cantidad)) |
| 551 | cargarRecicler(artAcargar, cantidad) | 625 | cargarRecicler(artAcargar, cantidad) |
| 552 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, true, requireContext()) | 626 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, true, requireContext()) |
| 553 | } | 627 | } |
| 554 | } | 628 | } |
| 555 | return cantidad | 629 | return cantidad |
| 556 | } | 630 | } |
| 557 | 631 | ||
| 558 | fun dialogoSumaResta(context: Context, indiceDelArtEncontrado: Int, univta: String, cancelable: Boolean) { | 632 | fun dialogoSumaResta(context: Context, indiceDelArtEncontrado: Int, univta: String, cancelable: Boolean) { |
| 559 | 633 | ||
| 560 | mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 634 | mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
| 561 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(cancelable) | 635 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(cancelable) |
| 562 | // TODO: SI PERMITE QUE INGRESE DECIMALES | 636 | // TODO: SI PERMITE QUE INGRESE DECIMALES |
| 563 | if (univta.contains("1") || univta.contains("3") || univta.contains("7")) mDialogView.tvNuevaCantidad.inputType = TYPE_CLASS_NUMBER | 637 | if (univta.contains("1") || univta.contains("3") || univta.contains("7")) mDialogView.tvNuevaCantidad.inputType = TYPE_CLASS_NUMBER |
| 564 | mDialogView.tvTitulo2.text="${listArticulos[indiceDelArtEncontrado].descripcion}" | 638 | mDialogView.tvTitulo2.text="${listArticulos[indiceDelArtEncontrado].descripcion}" |
| 565 | mDialogView.tvCantInicial.text = String.format("%.2f", listArticulos[indiceDelArtEncontrado].cantTomada) | 639 | mDialogView.tvCantInicial.text = String.format("%.2f", listArticulos[indiceDelArtEncontrado].cantTomada) |
| 566 | val mAlertDialog = mBuilder.show() | 640 | val mAlertDialog = mBuilder.show() |
| 567 | mDialogView.tvNuevaCantidad.requestFocus() | 641 | mDialogView.tvNuevaCantidad.requestFocus() |
| 568 | 642 | ||
| 569 | 643 | ||
| 570 | 644 | ||
| 571 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 645 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
| 572 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 646 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
| 573 | 647 | ||
| 574 | mDialogView.tvNuevaCantidad.addTextChangedListener(textWatcher) | 648 | mDialogView.tvNuevaCantidad.addTextChangedListener(textWatcher) |
| 575 | 649 | ||
| 576 | mDialogView.rbSumar.setOnClickListener { | 650 | mDialogView.rbSumar.setOnClickListener { |
| 577 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 651 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 578 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()) | 652 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()) |
| 579 | // mDialogView.tvNuevaCantidad.isEnabled = false | 653 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 580 | } | 654 | } |
| 581 | } | 655 | } |
| 582 | mDialogView.rbRestar.setOnClickListener { | 656 | mDialogView.rbRestar.setOnClickListener { |
| 583 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 657 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 584 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 658 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
| 585 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()) | 659 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()) |
| 586 | // mDialogView.tvNuevaCantidad.isEnabled = false | 660 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 587 | } else { | 661 | } else { |
| 588 | mDialogView.tvResultado.text = "" | 662 | mDialogView.tvResultado.text = "" |
| 589 | mDialogView.tvResultado.error = "Operación No Valida" | 663 | mDialogView.tvResultado.error = "Operación No Valida" |
| 590 | mDialogView.tvResultado.requestFocus() | 664 | mDialogView.tvResultado.requestFocus() |
| 591 | mDialogView.tvResultado.hint = "Error" | 665 | mDialogView.tvResultado.hint = "Error" |
| 592 | } | 666 | } |
| 593 | } | 667 | } |
| 594 | } | 668 | } |
| 595 | mDialogView.rbMdodificar.setOnClickListener { | 669 | mDialogView.rbMdodificar.setOnClickListener { |
| 596 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 670 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 597 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvNuevaCantidad.text.toString().toFloat()) | 671 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvNuevaCantidad.text.toString().toFloat()) |
| 598 | // mDialogView.tvNuevaCantidad.isEnabled = false | 672 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 599 | } | 673 | } |
| 600 | } | 674 | } |
| 601 | mDialogView.btnAceptar.setOnClickListener { | 675 | mDialogView.btnAceptar.setOnClickListener { |
| 602 | if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || !mDialogView.tvNuevaCantidad.text.isBlank()) { | 676 | if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || !mDialogView.tvNuevaCantidad.text.isBlank()) { |
| 603 | if (mDialogView.tvResultado.text.isNotEmpty() || !mDialogView.tvResultado.text.isBlank()) { | 677 | if (mDialogView.tvResultado.text.isNotEmpty() || !mDialogView.tvResultado.text.isBlank()) { |
| 604 | mAlertDialog.dismiss() | 678 | mAlertDialog.dismiss() |
| 605 | listArticulos[indiceDelArtEncontrado].cantTomada = String.format("%.2f", mDialogView.tvResultado.text.toString().toFloat()).toFloat() | 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 | listArticulos[indiceDelArtEncontrado].codigo.toString(), | 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 | viewAdapter.notifyDataSetChanged() | 686 | viewAdapter.notifyDataSetChanged() |
| 611 | } else if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { | 687 | } else if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { |
| 612 | mDialogView.tvResultado.error = "Operación Requerida" | 688 | mDialogView.tvResultado.error = "Operación Requerida" |
| 613 | mDialogView.tvResultado.requestFocus() | 689 | mDialogView.tvResultado.requestFocus() |
| 614 | mDialogView.tvResultado.hint = "Seleccione Operación" | 690 | mDialogView.tvResultado.hint = "Seleccione Operación" |
| 615 | } | 691 | } |
| 616 | } else if (mDialogView.tvNuevaCantidad.text.isEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { | 692 | } else if (mDialogView.tvNuevaCantidad.text.isEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { |
| 617 | mDialogView.tvNuevaCantidad.error = "Completar" | 693 | mDialogView.tvNuevaCantidad.error = "Completar" |
| 618 | mDialogView.tvNuevaCantidad.requestFocus() | 694 | mDialogView.tvNuevaCantidad.requestFocus() |
| 619 | mDialogView.tvNuevaCantidad.hint = "Ingrese un valor" | 695 | mDialogView.tvNuevaCantidad.hint = "Ingrese un valor" |
| 620 | } | 696 | } |
| 621 | } | 697 | } |
| 622 | mDialogView.dialogCancelBtn.setOnClickListener { | 698 | mDialogView.dialogCancelBtn.setOnClickListener { |
| 623 | mAlertDialog.dismiss() | 699 | mAlertDialog.dismiss() |
| 624 | } | 700 | } |
| 625 | } | 701 | } |
| 626 | 702 | ||
| 627 | suspend fun buscarCodiogoOriEnBD(CodOri: String): List<Articles> { | 703 | suspend fun buscarCodiogoOriEnBD(CodOri: String): List<Articles> { |
| 628 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 704 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
| 629 | var busqueda: List<Articles> | 705 | var busqueda: List<Articles> |
| 630 | return GlobalScope.async(Dispatchers.IO) { | 706 | return GlobalScope.async(IO) { |
| 631 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodOri(CodOri, SerchAreaInventario()) | 707 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodOri(CodOri, SerchAreaInventario()) |
| 632 | return@async busqueda | 708 | return@async busqueda |
| 633 | }.await() | 709 | }.await() |
| 634 | } | 710 | } |
| 635 | 711 | ||
| 636 | suspend fun buscarCBEnBD(CodigoBarras: String): Articles? { | 712 | suspend fun buscarCBEnBD(CodigoBarras: String): Articles? { |
| 637 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 713 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
| 638 | var busqueda: Articles? = null | 714 | var busqueda: Articles? = null |
| 639 | return GlobalScope.async(IO) { | 715 | return GlobalScope.async(IO) { |
| 640 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBar(CodigoBarras, SerchAreaInventario()) | 716 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBar(CodigoBarras, SerchAreaInventario()) |
| 641 | return@async busqueda | 717 | return@async busqueda |
| 642 | }.await() | 718 | }.await() |
| 643 | } | 719 | } |
| 644 | 720 | ||
| 645 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { | 721 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { |
| 646 | //TODO BUSQUEDA POR DESCRIPCION | 722 | //TODO BUSQUEDA POR DESCRIPCION |
| 647 | var busqueda: List<Articles>? = null | 723 | var busqueda: List<Articles>? = null |
| 648 | return GlobalScope.async(Dispatchers.IO) { | 724 | return GlobalScope.async(IO) { |
| 649 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, SerchAreaInventario()) | 725 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, SerchAreaInventario()) |
| 650 | return@async busqueda | 726 | return@async busqueda |
| 651 | }.await() | 727 | }.await() |
| 652 | } | 728 | } |
| 653 | 729 | ||
| 654 | suspend fun borrarArticulo(sector: String, codigo: String, inventario: String): Int? { | 730 | suspend fun borrarArticulo(sector: String, codigo: String, inventario: String): Int? { |
| 655 | //TODO BUSQUEDA POR DESCRIPCION | 731 | //TODO BUSQUEDA POR DESCRIPCION |
| 656 | var result: Int | 732 | var result: Int |
| 657 | return GlobalScope.async(IO) { | 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 | return@async result | 735 | return@async result |
| 660 | }.await() | 736 | }.await() |
| 661 | } | 737 | } |
| 662 | 738 | ||
| 663 | private suspend fun buscoArtEnRv(codigoBarras: String, sTipoBusqueda: Int): Int { | 739 | private suspend fun buscoArtEnRv(codigoBarras: String, sTipoBusqueda: Int): Int { |
| 664 | return GlobalScope.async(IO) { | 740 | return GlobalScope.async(IO) { |
| 665 | var indice = 0 | 741 | var indice = 0 |
| 666 | var bEncontrado = false | 742 | var bEncontrado = false |
| 667 | if (sTipoBusqueda == 0) {//TODO BUSQUEDA POR CODIGO DE BARRAS | 743 | if (sTipoBusqueda == 0) {//TODO BUSQUEDA POR CODIGO DE BARRAS |
| 668 | // TODO CAMBIO DE CB A CODIGO DEBO | 744 | // TODO CAMBIO DE CB A CODIGO DEBO |
| 669 | val any = cambioCBporCodigoDebo(codigoBarras) | 745 | val any = cambioCBporCodigoDebo(codigoBarras) |
| 670 | if (any != null) { | 746 | if (any != null) { |
| 671 | for (item in listArticulos) { | 747 | for (item in listArticulos) { |
| 672 | if (item.sector!!.toInt() == any.sector!!.toInt() && item.codigo!!.toInt() == any.codigo!!.toInt()) { | 748 | if (item.sector!!.toInt() == any.sector!!.toInt() && item.codigo!!.toInt() == any.codigo!!.toInt()) { |
| 673 | bEncontrado = true | 749 | bEncontrado = true |
| 674 | break | 750 | break |
| 675 | } | 751 | } |
| 676 | indice += 1 | 752 | indice += 1 |
| 677 | } | 753 | } |
| 678 | } | 754 | } |
| 679 | 755 | ||
| 680 | } else if (sTipoBusqueda == 1) {//TODO BUSQUEDA POR DESCRIPCION | 756 | } else if (sTipoBusqueda == 1) {//TODO BUSQUEDA POR DESCRIPCION |
| 681 | for (item in listArticulos) { | 757 | for (item in listArticulos) { |
| 682 | if (item.descripcion!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 758 | if (item.descripcion!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
| 683 | bEncontrado = true | 759 | bEncontrado = true |
| 684 | break | 760 | break |
| 685 | } | 761 | } |
| 686 | indice += 1 | 762 | indice += 1 |
| 687 | } | 763 | } |
| 688 | } else if (sTipoBusqueda == 2) {//TODO BUSQUEDA POR CODIGO DE ORIGEN | 764 | } else if (sTipoBusqueda == 2) {//TODO BUSQUEDA POR CODIGO DE ORIGEN |
| 689 | for (item in listArticulos) { | 765 | for (item in listArticulos) { |
| 690 | if (item.codigoOrigen!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 766 | if (item.codigoOrigen!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
| 691 | bEncontrado = true | 767 | bEncontrado = true |
| 692 | break | 768 | break |
| 693 | } | 769 | } |
| 694 | indice += 1 | 770 | indice += 1 |
| 695 | } | 771 | } |
| 696 | } | 772 | } |
| 697 | return@async if (bEncontrado) indice else -1 | 773 | return@async if (bEncontrado) indice else -1 |
| 698 | }.await() | 774 | }.await() |
| 699 | } | 775 | } |
| 700 | 776 | ||
| 701 | suspend fun cambioCBporCodigoDebo(codigoBarras: String): Articles? { | 777 | suspend fun cambioCBporCodigoDebo(codigoBarras: String): Articles? { |
| 702 | //TODO BUSQUEDA POR DESCRIPCION | 778 | //TODO BUSQUEDA POR DESCRIPCION |
| 703 | var busqueda: Articles? = null | 779 | var busqueda: Articles? = null |
| 704 | return GlobalScope.async(IO) { | 780 | return GlobalScope.async(IO) { |
| 705 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBar(codigoBarras, SerchAreaInventario()) | 781 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBar(codigoBarras, SerchAreaInventario()) |
| 706 | return@async busqueda | 782 | return@async busqueda |
| 707 | }.await() | 783 | }.await() |
| 708 | } | 784 | } |
| 709 | 785 | ||
| 710 | private fun cargarArtEnBd(articulos: Articles, cant: String) { | 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 | articulos.sector, | 789 | articulos.sector, |
| 713 | articulos.codigo, | 790 | articulos.codigo, |
| 714 | articulos.descripcion, | 791 | articulos.descripcion, |
| 715 | cant, | 792 | cant, |
| 716 | articulos.codBar, | 793 | articulos.codBar, |
| 717 | articulos.codOrigen, | 794 | articulos.codOrigen, |
| 718 | articulos.precio, | 795 | articulos.precio, |
| 719 | articulos.precio, | 796 | articulos.precio, |
| 720 | articulos.balanza, | 797 | articulos.balanza, |
| 721 | articulos.depSn, | 798 | articulos.depSn, |
| 722 | ObtenerFechaActual(), | 799 | ObtenerFechaActual(), |
| 723 | ObtenerFechaActual()) | 800 | ObtenerFechaActual() |
| 801 | ) | ||
| 724 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS | 802 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS |
| 725 | } | 803 | } |
| 726 | 804 | ||
| 727 | fun cargarRecicler(articulos: Articles, cant: Float) { | 805 | fun cargarRecicler(articulos: Articles, cant: Float) { |
| 728 | //TODO CARGO EN LE RV | 806 | //TODO CARGO EN LE RV |
| 729 | val item = ItemsRecycler(if (articulos.sector.toString().toInt()<9) "0${articulos.sector.toString()}" else articulos.sector.toString() | 807 | val item = ItemsRecycler( |
| 730 | , articulos.codigo, articulos.descripcion, cant, articulos.codBar, articulos.codOrigen, articulos.balanza.toString(), articulos.de.toString()) | 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 | listArticulos.add(item) | 817 | listArticulos.add(item) |
| 732 | 818 | ||
| 733 | viewAdapter = ProductosListAdapter(requireContext(), listArticulos, this) | 819 | viewAdapter = ProductosListAdapter(requireContext(), listArticulos, this) |
| 734 | viewManager = LinearLayoutManager(requireContext()) | 820 | viewManager = LinearLayoutManager(requireContext()) |
| 735 | deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! | 821 | deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! |
| 736 | rcInventarios.apply { | 822 | rcInventarios.apply { |
| 737 | adapter = viewAdapter | 823 | adapter = viewAdapter |
| 738 | layoutManager = viewManager | 824 | layoutManager = viewManager |
| 739 | } | 825 | } |
| 740 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { | 826 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { |
| 741 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { | 827 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { |
| 742 | return false | 828 | return false |
| 743 | } | 829 | } |
| 744 | 830 | ||
| 745 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | 831 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { |
| 746 | 832 | ||
| 747 | GlobalScope.launch(Dispatchers.Main) { | 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 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) | 839 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) |
| 750 | viewAdapter.notifyDataSetChanged() | 840 | viewAdapter.notifyDataSetChanged() |
| 751 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, false, requireContext()) | 841 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, false, requireContext()) |
| 752 | } | 842 | } |
| 753 | } | 843 | } |
| 754 | 844 | ||
| 755 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { | 845 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { |
| 756 | val itemView = viewHolder.itemView | 846 | val itemView = viewHolder.itemView |
| 757 | val iconMargin = (itemView.height - deleteIcon.intrinsicHeight) / 2 | 847 | val iconMargin = (itemView.height - deleteIcon.intrinsicHeight) / 2 |
| 758 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) | 848 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) |
| 759 | 849 | ||
| 760 | if (dX > 0) { | 850 | if (dX > 0) { |
| 761 | 851 | ||
| 762 | if (dX < c.width / 2) c.drawColor(Color.GREEN) | 852 | if (dX < c.width / 2) c.drawColor(Color.GREEN) |
| 763 | else c.drawColor(Color.RED) | 853 | else c.drawColor(Color.RED) |
| 764 | deleteIcon.setBounds(itemView.left + iconMargin, itemView.top + iconMargin, itemView.left + iconMargin + deleteIcon.intrinsicWidth, itemView.bottom - iconMargin) | 854 | deleteIcon.setBounds(itemView.left + iconMargin, itemView.top + iconMargin, itemView.left + iconMargin + deleteIcon.intrinsicWidth, itemView.bottom - iconMargin) |
| 765 | } else { | 855 | } else { |
| 766 | } | 856 | } |
| 767 | 857 | ||
| 768 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 858 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
| 769 | deleteIcon.draw(c) | 859 | deleteIcon.draw(c) |
| 770 | } | 860 | } |
| 771 | } | 861 | } |
| 772 | 862 | ||
| 773 | val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback) | 863 | val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback) |
| 774 | itemTouchHelper.attachToRecyclerView(rcInventarios) | 864 | itemTouchHelper.attachToRecyclerView(rcInventarios) |
| 775 | } | 865 | } |
| 776 | 866 | ||
| 777 | private fun ProdNoCont(): Int? { | 867 | private fun ProdNoCont(): Int? { |
| 778 | var mostrarStock = 0 | 868 | var mostrarStock = 0 |
| 779 | if (sharedPreferences.contains("cbMostrarStock")) if (sharedPreferences.getString("cbMostrarStock", "").toString() == "1") mostrarStock = 1 | 869 | if (sharedPreferences.contains("cbMostrarStock")) if (sharedPreferences.getString("cbMostrarStock", "").toString() == "1") mostrarStock = 1 |
| 780 | return mostrarStock | 870 | return mostrarStock |
| 781 | } | 871 | } |
| 782 | 872 | ||
| 783 | private fun AjusteProductos(): Int? { | 873 | private fun AjusteProductos(): Int? { |
| 784 | var prodInclu = 0 | 874 | var prodInclu = 0 |
| 785 | if (sharedPreferences.contains("rbProInclu")) if (sharedPreferences.getString("rbProInclu", "").toString() == "1") prodInclu = 1 | 875 | if (sharedPreferences.contains("rbProInclu")) if (sharedPreferences.getString("rbProInclu", "").toString() == "1") prodInclu = 1 |
| 786 | 876 | ||
| 787 | if (sharedPreferences.contains("rbProNoInclu")) if (sharedPreferences.getString("rbProNoInclu", "").toString() == "0") prodInclu = 0 | 877 | if (sharedPreferences.contains("rbProNoInclu")) if (sharedPreferences.getString("rbProNoInclu", "").toString() == "0") prodInclu = 0 |
| 788 | return prodInclu | 878 | return prodInclu |
| 789 | } | 879 | } |
| 790 | 880 | ||
| 791 | private fun SerchArea(): Boolean { | 881 | private fun SerchArea(): Boolean { |
| 792 | if (sharedPreferences.contains("rbVentas")) if (sharedPreferences.getString("rbVentas", "").toString() == "1") iArea =false | 882 | if (sharedPreferences.contains("rbVentas")) if (sharedPreferences.getString("rbVentas", "").toString() == "1") iArea =false |
| 793 | if (sharedPreferences.contains("rbDeposito")) if (sharedPreferences.getString("rbDeposito", "").toString() == "1") iArea = true | 883 | if (sharedPreferences.contains("rbDeposito")) if (sharedPreferences.getString("rbDeposito", "").toString() == "1") iArea = true |
| 794 | return iArea | 884 | return iArea |
| 795 | } | 885 | } |
| 796 | 886 | ||
| 797 | suspend fun SerchAreaInventario(): Boolean { | 887 | suspend fun SerchAreaInventario(): Boolean { |
| 798 | return GlobalScope.async(IO) { | 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 | }.await() | 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 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { | 894 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { |
| 813 | lifecycleScope.launch { | 895 | lifecycleScope.launch { |
| 814 | withContext(Dispatchers.IO) { | 896 | withContext(Dispatchers.IO) { |
| 815 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) | 897 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) |
| 816 | } | 898 | } |
| 817 | } | 899 | } |
| 818 | } | 900 | } |
| 819 | 901 | ||
| 820 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { | 902 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { |
| 821 | lifecycleScope.launch { | 903 | lifecycleScope.launch { |
| 822 | withContext(Dispatchers.IO) { | 904 | withContext(IO) { |
| 823 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.UpdateInvBody(cantidad, sector.toLong(), codigo.toLong()) | 905 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.updateInvBody(cantidad, sector.toLong(), codigo.toLong(), ObtenerFechaActual()) |
| 824 | } | 906 | } |
| 825 | } | 907 | } |
| 826 | } | 908 | } |
| 827 | 909 | ||
| 828 | suspend fun cargarInventario(inventario: Int): List<InvBody>? { | 910 | suspend fun cargarInventario(inventario: Int): List<InvBody>? { |
| 829 | return GlobalScope.async(Dispatchers.IO) { | 911 | return GlobalScope.async(IO) { |
| 830 | return@async AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inventario) | 912 | return@async AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inventario) |
| 831 | }.await() | 913 | }.await() |
| 832 | } | 914 | } |
| 833 | 915 | ||
| 834 | override fun onImageDotsClick(sector: String?, codigo: String?) { | 916 | override fun onImageDotsClick(sector: String?, codigo: String?) { |
| 835 | val bundle = Bundle() | 917 | val bundle = Bundle() |
| 836 | bundle.putString("sector", sector!!.toInt().toString()) | 918 | bundle.putString("sector", sector!!.toInt().toString()) |
| 837 | bundle.putString("codigo", codigo) | 919 | bundle.putString("codigo", codigo) |
| 838 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) | 920 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) |
| 839 | navController.navigate(R.id.action_inventarioFragment_to_detalleArtFragment, bundle) | 921 | navController.navigate(R.id.action_inventarioFragment_to_detalleArtFragment, bundle) |
| 840 | } | 922 | } |
| 841 | 923 | ||
| 842 | override fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) { | 924 | override fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) { |
| 843 | dialogoSumaResta(requireContext(), position.toInt(), listArticulos[position.toInt()].univta, true) | 925 | dialogoSumaResta(requireContext(), position.toInt(), listArticulos[position.toInt()].univta, true) |
| 844 | } | 926 | } |
| 845 | 927 | ||
| 846 | private val textWatcher = object : TextWatcher { | 928 | private val textWatcher = object : TextWatcher { |
| 847 | override fun afterTextChanged(s: Editable?) { | 929 | override fun afterTextChanged(s: Editable?) {} |
| 848 | } | 930 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} |
| 849 | |||
| 850 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { | ||
| 851 | } | ||
| 852 | 931 | ||
| 853 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { | 932 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { |
| 854 | if(mDialogView.rbSumar.isChecked){ | 933 | if(mDialogView.rbSumar.isChecked){ |
| 855 | // mDialogView.tvNuevaCantidad.isEnabled=false | 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 | if(mDialogView.rbRestar.isChecked) { | 937 | if(mDialogView.rbRestar.isChecked) { |
| 859 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 938 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 860 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 939 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
| 861 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()) | 940 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()) |
| 862 | // mDialogView.tvNuevaCantidad.isEnabled = false | 941 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 863 | } else { | 942 | } else { |
| 864 | mDialogView.tvResultado.text = "" | 943 | mDialogView.tvResultado.text = "" |
| 865 | mDialogView.tvResultado.error = "Operación No Valida" | 944 | mDialogView.tvResultado.error = "Operación No Valida" |
| 866 | mDialogView.tvResultado.requestFocus() | 945 | mDialogView.tvResultado.requestFocus() |
| 867 | mDialogView.tvResultado.hint = "Error" | 946 | mDialogView.tvResultado.hint = "Error" |
| 868 | } | 947 | } |
| 869 | } | 948 | } |
| 870 | } | 949 | } |
| 871 | if(mDialogView.rbMdodificar.isChecked) { | 950 | if(mDialogView.rbMdodificar.isChecked) { |
| 872 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 951 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 873 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvNuevaCantidad.text.toString().toFloat()) | 952 | mDialogView.tvResultado.text = String.format("%.2f", mDialogView.tvNuevaCantidad.text.toString().toFloat()) |
| 874 | // mDialogView.tvNuevaCantidad.isEnabled = false | 953 | // mDialogView.tvNuevaCantidad.isEnabled = false |
| 875 | } | 954 | } |
| 876 | } | 955 | } |
| 877 | 956 | ||
| 878 | } | 957 | } |
| 879 | } | 958 | } |
| 880 | } | 959 | } |
app/src/main/java/com/focasoftware/deboinventariov20/UI/inventario/ProductosListAdapter.kt
| 1 | package com.focasoftware.deboinventariov20.UI.inventario | 1 | package com.focasoftware.deboinventariov20.UI.inventario |
| 2 | 2 | ||
| 3 | import android.content.Context | 3 | import android.content.Context |
| 4 | import android.view.LayoutInflater | 4 | import android.view.LayoutInflater |
| 5 | import android.view.View | 5 | import android.view.View |
| 6 | import android.view.ViewGroup | 6 | import android.view.ViewGroup |
| 7 | import androidx.recyclerview.widget.RecyclerView | 7 | import androidx.recyclerview.widget.RecyclerView |
| 8 | import com.focasoftware.deboinventariov20.R | 8 | import com.focasoftware.deboinventariov20.R |
| 9 | import com.focasoftware.deboinventariov20.UI.Utils.BaseViewHolder | 9 | import com.focasoftware.deboinventariov20.UI.Utils.BaseViewHolder |
| 10 | import kotlinx.android.synthetic.main.item.view.* | 10 | import kotlinx.android.synthetic.main.item.view.* |
| 11 | import java.io.IOException | 11 | import java.io.IOException |
| 12 | import java.net.UnknownHostException | 12 | import java.net.UnknownHostException |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | class ProductosListAdapter(private val context: Context,private val productos: ArrayList<ItemsRecycler>, private val itemImageClickListener: OnImageDotsClickListener) : | 15 | class ProductosListAdapter(private val context: Context,private val productos: ArrayList<ItemsRecycler>, private val itemImageClickListener: OnImageDotsClickListener) : |
| 16 | RecyclerView.Adapter<BaseViewHolder<*>>() { | 16 | RecyclerView.Adapter<BaseViewHolder<*>>() { |
| 17 | 17 | ||
| 18 | private var removePosition: Int = 0 | 18 | private var removePosition: Int = 0 |
| 19 | private var removedItem: ItemsRecycler? = null | 19 | private var removedItem: ItemsRecycler? = null |
| 20 | 20 | ||
| 21 | interface OnImageDotsClickListener { | 21 | interface OnImageDotsClickListener { |
| 22 | fun onImageDotsClick(sector: String?,codigo: String?) | 22 | fun onImageDotsClick(sector: String?,codigo: String?) |
| 23 | fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) | 23 | fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) |
| 24 | } | 24 | |
| 25 | } | ||
| 25 | 26 | ||
| 26 | override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = ItemsViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false)) | 27 | override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = ItemsViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false)) |
| 27 | 28 | ||
| 28 | override fun getItemCount() = productos.size | 29 | override fun getItemCount() = productos.size |
| 29 | 30 | ||
| 30 | override fun onBindViewHolder(holder: BaseViewHolder<*>, position: Int) { | 31 | override fun onBindViewHolder(holder: BaseViewHolder<*>, position: Int) { |
| 31 | when (holder) { | 32 | when (holder) { |
| 32 | is ItemsViewHolder -> { holder.bind(productos[position], position) } | 33 | is ItemsViewHolder -> { holder.bind(productos[position], position) } |
| 33 | 34 | ||
| 34 | } | 35 | } |
| 35 | } | 36 | } |
| 36 | inner class ItemsViewHolder (itemView: View) : BaseViewHolder<ItemsRecycler>(itemView) { | 37 | inner class ItemsViewHolder (itemView: View) : BaseViewHolder<ItemsRecycler>(itemView) { |
| 37 | override fun bind(item: ItemsRecycler, position: Int) { | 38 | override fun bind(item: ItemsRecycler, position: Int) { |
| 38 | itemView.ivDots.setOnClickListener {itemImageClickListener.onImageDotsClick(item.sector,item.codigo) } | 39 | itemView.ivDots.setOnClickListener {itemImageClickListener.onImageDotsClick(item.sector,item.codigo) } |
| 39 | itemView.ivPen.setOnClickListener {itemImageClickListener.onImagePenClick(item.sector,item.codigo,item.cantTomada.toString(),adapterPosition.toString()) } | 40 | itemView.ivPen.setOnClickListener {itemImageClickListener.onImagePenClick(item.sector,item.codigo,item.cantTomada.toString(),adapterPosition.toString()) } |
| 40 | 41 | ||
| 41 | // itemView.tvSector.text=item.sector | 42 | // itemView.tvSector.text=item.sector |
| 42 | // itemView.tvCodigo.text=item.codigo | 43 | // itemView.tvCodigo.text=item.codigo |
| 43 | itemView.tvDescripcion.text=item.descripcion | 44 | itemView.tvDescripcion.text=item.descripcion |
| 44 | itemView.tvCantidad.text=item.cantTomada.toString() | 45 | itemView.tvCantidad.text=item.cantTomada.toString() |
| 45 | // itemView.tvCodigoBarras.text=item.sector | 46 | // itemView.tvCodigoBarras.text=item.sector |
| 46 | // itemView.tvCodigoOrigen.text=item.sector | 47 | // itemView.tvCodigoOrigen.text=item.sector |
| 47 | itemView.ivPen.setImageResource(R.drawable.pen) | 48 | itemView.ivPen.setImageResource(R.drawable.pen) |
| 48 | itemView.ivDots.setImageResource(R.drawable.more) | 49 | itemView.ivDots.setImageResource(R.drawable.more) |
| 49 | } | 50 | } |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | fun removeItem(viewHolder: RecyclerView.ViewHolder) { | 53 | fun removeItem(viewHolder: RecyclerView.ViewHolder) { |
| 53 | removePosition = viewHolder.adapterPosition | 54 | removePosition = viewHolder.adapterPosition |
| 54 | removedItem = productos[viewHolder.adapterPosition] | 55 | removedItem = productos[viewHolder.adapterPosition] |
| 55 | 56 | ||
| 56 | productos.removeAt(viewHolder.adapterPosition) | 57 | productos.removeAt(viewHolder.adapterPosition) |
| 57 | notifyItemRemoved(viewHolder.adapterPosition) | 58 | notifyItemRemoved(viewHolder.adapterPosition) |
| 58 | } | 59 | } |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | 62 |
app/src/main/res/layout-xlarge/item_codigo_origen.xml
| 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | xmlns:app="http://schemas.android.com/apk/res-auto" | 3 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 4 | android:layout_width="match_parent" | 4 | android:layout_width="match_parent" |
| 5 | android:layout_height="wrap_content" | 5 | android:layout_height="wrap_content" |
| 6 | android:layout_margin="5dp" | 6 | android:layout_margin="5dp" |
| 7 | app:cardCornerRadius="15dp" | 7 | app:cardCornerRadius="15dp" |
| 8 | app:cardElevation="10dp" | 8 | app:cardElevation="10dp" |
| 9 | app:cardPreventCornerOverlap="false" | 9 | app:cardPreventCornerOverlap="false" |
| 10 | app:contentPadding="5dp"> | 10 | app:contentPadding="5dp"> |
| 11 | 11 | ||
| 12 | <androidx.constraintlayout.widget.ConstraintLayout | 12 | <androidx.constraintlayout.widget.ConstraintLayout |
| 13 | android:layout_width="match_parent" | 13 | android:layout_width="match_parent" |
| 14 | android:layout_height="wrap_content"> | 14 | android:layout_height="wrap_content"> |
| 15 | 15 | ||
| 16 | <TextView | 16 | <TextView |
| 17 | android:id="@+id/tvDescripcion" | 17 | android:id="@+id/tvDescripcion" |
| 18 | android:layout_width="0dp" | 18 | android:layout_width="0dp" |
| 19 | android:layout_height="wrap_content" | 19 | android:layout_height="wrap_content" |
| 20 | android:layout_marginStart="5dp" | 20 | android:layout_marginStart="5dp" |
| 21 | android:maxLines="2" | 21 | android:maxLines="2" |
| 22 | android:text="abcdefghijklmnñopqrstuvwxyz0123456789abcdefghijklmnñopqrstuvwxyz" | 22 | android:text="abcdefghijklmnñopqrstuvwxyz0123456789abcdefghijklmnñopqrstuvwxyz" |
| 23 | android:textAppearance="@style/TextAppearance.AppCompat.Large" | 23 | android:textAppearance="@style/TextAppearance.AppCompat.Large" |
| 24 | android:textSize="@dimen/SubTitulos10" | 24 | android:textSize="@dimen/SubTitulos10" |
| 25 | android:textStyle="bold" | 25 | android:textStyle="bold" |
| 26 | app:layout_constraintEnd_toEndOf="parent" | 26 | app:layout_constraintEnd_toEndOf="parent" |
| 27 | app:layout_constraintStart_toStartOf="parent" | 27 | app:layout_constraintStart_toStartOf="parent" |
| 28 | app:layout_constraintTop_toTopOf="parent" /> | 28 | app:layout_constraintTop_toTopOf="parent" /> |
| 29 | 29 | ||
| 30 | <TextView | 30 | <TextView |
| 31 | android:id="@+id/textView2" | 31 | android:id="@+id/textView2" |
| 32 | android:layout_width="wrap_content" | 32 | android:layout_width="wrap_content" |
| 33 | android:layout_height="wrap_content" | 33 | android:layout_height="wrap_content" |
| 34 | android:layout_marginStart="5dp" | 34 | android:layout_marginStart="5dp" |
| 35 | android:layout_marginTop="10dp" | 35 | android:layout_marginTop="10dp" |
| 36 | android:text="Código DEBO:" | 36 | android:text="Código DEBO:" |
| 37 | android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Large" | 37 | android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Large" |
| 38 | android:textSize="@dimen/nav_header_vertical_spacing10" | 38 | android:textSize="@dimen/nav_header_vertical_spacing10" |
| 39 | app:layout_constraintStart_toStartOf="parent" | 39 | app:layout_constraintStart_toStartOf="parent" |
| 40 | app:layout_constraintTop_toBottomOf="@+id/tvDescripcion" /> | 40 | app:layout_constraintTop_toBottomOf="@+id/tvDescripcion" /> |
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | <TextView | 43 | <TextView |
| 44 | android:id="@+id/tvSector" | 44 | android:id="@+id/tvSector" |
| 45 | android:layout_width="wrap_content" | 45 | android:layout_width="wrap_content" |
| 46 | android:layout_height="match_parent" | 46 | android:layout_height="match_parent" |
| 47 | android:layout_marginStart="5dp" | 47 | android:layout_marginStart="5dp" |
| 48 | android:layout_marginTop="10dp" | ||
| 49 | android:text="9999" | 48 | android:text="9999" |
| 50 | android:textAppearance="@style/TextAppearance.AppCompat.Large" | 49 | android:textAppearance="@style/TextAppearance.AppCompat.Large" |
| 51 | android:textColorHint="@android:color/black" | 50 | android:textColorHint="@android:color/black" |
| 52 | android:textSize="@dimen/SubTitulos10" | 51 | android:textSize="@dimen/SubTitulos10" |
| 53 | android:textStyle="bold" | 52 | android:textStyle="bold" |
| 54 | app:layout_constraintStart_toEndOf="@+id/textView2" | 53 | app:layout_constraintBaseline_toBaselineOf="@+id/textView2" |
| 55 | app:layout_constraintTop_toBottomOf="@+id/tvDescripcion" /> | 54 | app:layout_constraintStart_toEndOf="@+id/textView2" /> |
| 56 | 55 | ||
| 57 | <TextView | 56 | <TextView |
| 58 | android:id="@+id/tvCodigo" | 57 | android:id="@+id/tvCodigo" |
| 59 | android:layout_width="wrap_content" | 58 | android:layout_width="wrap_content" |
| 60 | android:layout_height="match_parent" | 59 | android:layout_height="match_parent" |
| 61 | android:text="99999999" | 60 | android:text="99999999" |
| 62 | android:textAppearance="@style/TextAppearance.AppCompat.Large" | 61 | android:textAppearance="@style/TextAppearance.AppCompat.Large" |
| 63 | android:textColorHint="@android:color/black" | 62 | android:textColorHint="@android:color/black" |
| 64 | android:textSize="@dimen/SubTitulos10" | 63 | android:textSize="@dimen/SubTitulos10" |
| 65 | android:textStyle="bold" | 64 | android:textStyle="bold" |
| 66 | app:layout_constraintBaseline_toBaselineOf="@+id/tvSector" | 65 | app:layout_constraintBaseline_toBaselineOf="@+id/tvSector" |
| 67 | app:layout_constraintHorizontal_chainStyle="packed" | 66 | app:layout_constraintHorizontal_chainStyle="packed" |
| 68 | app:layout_constraintStart_toEndOf="@+id/tvSector" /> | 67 | app:layout_constraintStart_toEndOf="@+id/tvSector" /> |
| 69 | 68 | ||
| 70 | 69 | ||
| 71 | <TextView | 70 | <TextView |
| 72 | android:id="@+id/tvCantidad" | 71 | android:id="@+id/tvCantidad" |
| 73 | android:layout_width="wrap_content" | 72 | android:layout_width="wrap_content" |
| 74 | android:layout_height="match_parent" | 73 | android:layout_height="match_parent" |
| 75 | android:layout_marginStart="10dp" | 74 | android:layout_marginStart="10dp" |
| 76 | android:text="Código Origen:" | 75 | android:text="Código Origen:" |
| 77 | android:textAppearance="@style/TextAppearance.AppCompat.Large" | 76 | android:textAppearance="@style/TextAppearance.AppCompat.Large" |
| 78 | android:textSize="@dimen/textCantidadDesc10" | 77 | android:textSize="@dimen/textCantidadDesc10" |
| 79 | app:layout_constraintBaseline_toBaselineOf="@+id/tvCodigo" | 78 | app:layout_constraintBaseline_toBaselineOf="@+id/tvCodigo" |
| 80 | app:layout_constraintStart_toEndOf="@+id/tvCodigo" /> | 79 | app:layout_constraintStart_toEndOf="@+id/tvCodigo" /> |
| 81 | 80 | ||
| 82 | <TextView | 81 | <TextView |
| 83 | android:id="@+id/tvCodigoOrigen" | 82 | android:id="@+id/tvCodigoOrigen" |
| 84 | android:layout_width="wrap_content" | 83 | android:layout_width="wrap_content" |
| 85 | android:layout_height="match_parent" | 84 | android:layout_height="match_parent" |
| 86 | android:layout_marginStart="5dp" | 85 | android:layout_marginStart="5dp" |
| 87 | android:layout_marginTop="10dp" | 86 | android:layout_marginTop="10dp" |
| 88 | android:maxLines="2" | 87 | android:maxLines="2" |
| 89 | android:text="987654" | 88 | android:text="987654" |
| 90 | android:textAppearance="@style/TextAppearance.AppCompat.Large" | 89 | android:textAppearance="@style/TextAppearance.AppCompat.Large" |
| 91 | android:textSize="@dimen/SubTitulos10" | 90 | android:textSize="@dimen/SubTitulos10" |
| 92 | android:textStyle="bold" | 91 | android:textStyle="bold" |
| 93 | android:visibility="visible" | 92 | android:visibility="visible" |
| 94 | app:layout_constraintBaseline_toBaselineOf="@+id/tvCantidad" | 93 | app:layout_constraintBaseline_toBaselineOf="@+id/tvCantidad" |
| 95 | app:layout_constraintStart_toEndOf="@+id/tvCantidad" /> | 94 | app:layout_constraintStart_toEndOf="@+id/tvCantidad" /> |
| 96 | 95 | ||
| 97 | 96 | ||
| 98 | </androidx.constraintlayout.widget.ConstraintLayout> | 97 | </androidx.constraintlayout.widget.ConstraintLayout> |
| 99 | 98 | ||
| 100 | </androidx.cardview.widget.CardView> | 99 | </androidx.cardview.widget.CardView> |