Commit 10d0868ed80f1628f49d64b9cf674dc9f6285387
1 parent
8f56b4b215
Exists in
master
27022020 0031
Showing
3 changed files
with
26 additions
and
45 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 | 16 | ||
| 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | buildTypes { | 20 | buildTypes { |
| 21 | release { | 21 | release { |
| 22 | minifyEnabled false | 22 | minifyEnabled false |
| 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
| 26 | compileOptions { | 26 | compileOptions { |
| 27 | sourceCompatibility JavaVersion.VERSION_1_8 | 27 | sourceCompatibility JavaVersion.VERSION_1_8 |
| 28 | targetCompatibility JavaVersion.VERSION_1_8 | 28 | targetCompatibility JavaVersion.VERSION_1_8 |
| 29 | } | 29 | } |
| 30 | kotlinOptions { | 30 | kotlinOptions { |
| 31 | jvmTarget = '1.8' | 31 | jvmTarget = '1.8' |
| 32 | } | 32 | } |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | dependencies { | 35 | dependencies { |
| 36 | implementation fileTree(dir: "libs", include: ["*.jar"]) | 36 | implementation fileTree(dir: "libs", include: ["*.jar"]) |
| 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" |
| 38 | implementation 'androidx.core:core-ktx:1.3.1' | 38 | implementation 'androidx.core:core-ktx:1.3.1' |
| 39 | implementation 'androidx.appcompat:appcompat:1.2.0' | 39 | implementation 'androidx.appcompat:appcompat:1.2.0' |
| 40 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' | 40 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' |
| 41 | implementation 'com.google.android.material:material:1.2.0' | 41 | implementation 'com.google.android.material:material:1.2.0' |
| 42 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | 42 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' |
| 43 | implementation 'androidx.navigation:navigation-fragment:2.3.0' | 43 | implementation 'androidx.navigation:navigation-fragment:2.3.0' |
| 44 | implementation 'androidx.navigation:navigation-ui:2.3.0' | 44 | implementation 'androidx.navigation:navigation-ui:2.3.0' |
| 45 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' | 45 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' |
| 46 | implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0' | 46 | implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0' |
| 47 | implementation 'androidx.navigation:navigation-ui-ktx:2.3.0' | 47 | implementation 'androidx.navigation:navigation-ui-ktx:2.3.0' |
| 48 | implementation 'androidx.recyclerview:recyclerview:1.1.0' | 48 | implementation 'androidx.recyclerview:recyclerview:1.1.0' |
| 49 | testImplementation 'junit:junit:4.13' | 49 | testImplementation 'junit:junit:4.13' |
| 50 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' | 50 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' |
| 51 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | 51 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' |
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | //Room | 54 | //Room |
| 55 | implementation 'androidx.room:room-ktx:2.2.5' | 55 | implementation 'androidx.room:room-ktx:2.2.5' |
| 56 | implementation "androidx.room:room-runtime:2.2.5" | 56 | implementation "androidx.room:room-runtime:2.2.5" |
| 57 | kapt "androidx.room:room-compiler:2.2.5" | 57 | kapt "androidx.room:room-compiler:2.2.5" |
| 58 | 58 | ||
| 59 | //Retrofit | 59 | //Retrofit |
| 60 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' | 60 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' |
| 61 | implementation 'com.google.code.gson:gson:2.8.6' | 61 | implementation 'com.google.code.gson:gson:2.8.6' |
| 62 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' | 62 | implementation 'com.squareup.retrofit2:converter-gson:2.9.0' |
| 63 | implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1' | 63 | implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1' |
| 64 | 64 | ||
| 65 | //Gson library | 65 | //Gson library |
| 66 | implementation "com.google.code.gson:gson:2.8.6" | 66 | implementation "com.google.code.gson:gson:2.8.6" |
| 67 | annotationProcessor 'androidx.room:room-compiler:2.2.5' | 67 | annotationProcessor 'androidx.room:room-compiler:2.2.5' |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | implementation 'com.afollestad.material-dialogs:bottomsheets:3.2.1' | ||
| 71 | implementation 'com.afollestad.material-dialogs:core:3.3.0' | 70 | implementation 'com.afollestad.material-dialogs:core:3.3.0' |
| 72 | implementation 'com.afollestad.material-dialogs:input:3.3.0' | 71 | implementation 'com.afollestad.material-dialogs:input:3.3.0' |
| 73 | } | 72 | } |
app/src/main/java/com/focasoftware/deboinventariov20/ui/dialogos/DialogNoEncontrado.kt
| 1 | package com.focasoftware.deboinventariov20.ui.dialogos | 1 | package com.focasoftware.deboinventariov20.ui.dialogos |
| 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.DialogInterface | ||
| 6 | import android.os.Bundle | 5 | import android.os.Bundle |
| 7 | import android.view.LayoutInflater | ||
| 8 | import androidx.fragment.app.DialogFragment | 6 | import androidx.fragment.app.DialogFragment |
| 9 | import com.focasoftware.deboinventariov20.R | ||
| 10 | import kotlinx.android.synthetic.main.ingresar_cantidad.* | ||
| 11 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* | ||
| 12 | 7 | ||
| 13 | class DialogNoEncontrado : DialogFragment() { | 8 | class DialogNoEncontrado : DialogFragment() { |
| 14 | |||
| 15 | fun newInstance(title: String, s: String): DialogNoEncontrado? { | ||
| 16 | val dialog = DialogNoEncontrado() | ||
| 17 | |||
| 18 | val args = Bundle() | ||
| 19 | args.putString("title", title) | ||
| 20 | args.putString("s", s) | ||
| 21 | dialog.arguments = args | ||
| 22 | return dialog | ||
| 23 | } | ||
| 24 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 9 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
| 25 | return activity?.let { | 10 | return activity?.let { |
| 26 | val args = requireArguments() | 11 | val title = "Busqueda de Productos" |
| 27 | 12 | val content = "Producto no encotrado." | |
| 28 | |||
| 29 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 13 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
| 30 | val inflater = requireActivity().layoutInflater; | 14 | builder.setTitle(title).setMessage(content).setPositiveButton(android.R.string.ok) { _, _ -> |
| 31 | 15 | //Todo OK click | |
| 32 | builder.setView(inflater.inflate(R.layout.ingresar_cantidad, null)) | 16 | } |
| 33 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, id ->}) | 17 | return builder.create() |
| 34 | |||
| 35 | |||
| 36 | builder.create() | ||
| 37 | } ?: throw IllegalStateException("Activity cannot be null") | 18 | } ?: throw IllegalStateException("Activity cannot be null") |
| 38 | } | 19 | } |
| 39 | |||
| 40 | } | 20 | } |
| 41 | |||
| 42 | 21 |
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.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.Drawable | 8 | import android.graphics.drawable.Drawable |
| 9 | import android.os.Bundle | 9 | import android.os.Bundle |
| 10 | import android.view.KeyEvent | 10 | import android.view.KeyEvent |
| 11 | import android.view.LayoutInflater | 11 | import android.view.LayoutInflater |
| 12 | import android.view.View | 12 | import android.view.View |
| 13 | import android.view.ViewGroup | 13 | import android.view.ViewGroup |
| 14 | import android.widget.EditText | 14 | import android.widget.EditText |
| 15 | import android.widget.TextView | 15 | import android.widget.TextView |
| 16 | import android.widget.Toast | 16 | import android.widget.Toast |
| 17 | import androidx.core.content.ContextCompat | 17 | import androidx.core.content.ContextCompat |
| 18 | import androidx.core.os.bundleOf | 18 | import androidx.core.os.bundleOf |
| 19 | import androidx.fragment.app.Fragment | 19 | import androidx.fragment.app.Fragment |
| 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.afollestad.materialdialogs.MaterialDialog | 26 | import com.afollestad.materialdialogs.MaterialDialog |
| 27 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 27 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
| 28 | import com.focasoftware.deboinventariov20.Model.Articles | 28 | import com.focasoftware.deboinventariov20.Model.Articles |
| 29 | import com.focasoftware.deboinventariov20.Model.InvBody | 29 | import com.focasoftware.deboinventariov20.Model.InvBody |
| 30 | import com.focasoftware.deboinventariov20.Model.InvHead | 30 | import com.focasoftware.deboinventariov20.Model.InvHead |
| 31 | import com.focasoftware.deboinventariov20.R | 31 | import com.focasoftware.deboinventariov20.R |
| 32 | import com.focasoftware.deboinventariov20.ui.dialogos.DialogNoEncontrado | ||
| 32 | import kotlinx.android.synthetic.main.fragment_inventario.* | 33 | import kotlinx.android.synthetic.main.fragment_inventario.* |
| 33 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* | 34 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* |
| 34 | import kotlinx.android.synthetic.main.login_dialog.view.* | 35 | import kotlinx.android.synthetic.main.login_dialog.view.* |
| 35 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar | 36 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar |
| 36 | import kotlinx.coroutines.* | 37 | import kotlinx.coroutines.* |
| 37 | import java.time.LocalDateTime | 38 | import java.time.LocalDateTime |
| 38 | import java.time.format.DateTimeFormatter | 39 | import java.time.format.DateTimeFormatter |
| 39 | import java.util.* | 40 | import java.util.* |
| 40 | 41 | ||
| 41 | 42 | ||
| 42 | class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickListener { | 43 | class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickListener { |
| 43 | 44 | ||
| 44 | private lateinit var sharedPreferences: SharedPreferences | 45 | private lateinit var sharedPreferences: SharedPreferences |
| 45 | private var iArea: Int = 0 | 46 | private var iArea: Int = 0 |
| 46 | private lateinit var invHead: InvHead | 47 | private lateinit var invHead: InvHead |
| 47 | private lateinit var rcInventarios: RecyclerView | 48 | private lateinit var rcInventarios: RecyclerView |
| 48 | private lateinit var viewAdapter: RecyclerView.Adapter<*> | 49 | private lateinit var viewAdapter: RecyclerView.Adapter<*> |
| 49 | private lateinit var viewManager: RecyclerView.LayoutManager | 50 | private lateinit var viewManager: RecyclerView.LayoutManager |
| 50 | private lateinit var sChangeUpper: String | 51 | private lateinit var sChangeUpper: String |
| 51 | private var listArticulos = ArrayList<ItemsRecycler>() | 52 | private var listArticulos = ArrayList<ItemsRecycler>() |
| 52 | private lateinit var navController: NavController | 53 | private lateinit var navController: NavController |
| 53 | private var InventarioNuevo: Int = 0 | 54 | private var InventarioNuevo: Int = 0 |
| 54 | private var iEstado = 0 | 55 | private var iEstado = 0 |
| 55 | private var iBusquedaPor = 0 | 56 | private var iBusquedaPor = 0 |
| 56 | private var fCant = 0F | 57 | private var fCant = 0F |
| 57 | private var bFirst = false | 58 | private var bFirst = false |
| 58 | private lateinit var deleteIcon: Drawable | 59 | private lateinit var deleteIcon: Drawable |
| 59 | 60 | ||
| 60 | override fun onCreate(savedInstanceState: Bundle?) { | 61 | override fun onCreate(savedInstanceState: Bundle?) { |
| 61 | super.onCreate(savedInstanceState) | 62 | super.onCreate(savedInstanceState) |
| 62 | 63 | ||
| 63 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 64 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
| 64 | if (sharedPreferences.contains("Inventario")) if (sharedPreferences.getString("Inventario", "").toString() != "-1") { | 65 | if (sharedPreferences.contains("Inventario")) if (sharedPreferences.getString("Inventario", "").toString() != "-1") { |
| 65 | InventarioNuevo = sharedPreferences.getString("Inventario", "").toString().toInt() | 66 | InventarioNuevo = sharedPreferences.getString("Inventario", "").toString().toInt() |
| 66 | val editor = sharedPreferences.edit() | 67 | val editor = sharedPreferences.edit() |
| 67 | editor?.putString("Inventario", "-1") | 68 | editor?.putString("Inventario", "-1") |
| 68 | editor?.apply() | 69 | editor?.apply() |
| 69 | editor.commit() | 70 | editor.commit() |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | } | 73 | } |
| 73 | 74 | ||
| 74 | 75 | ||
| 75 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 76 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
| 76 | val v = inflater.inflate(R.layout.fragment_inventario, container, false) | 77 | val v = inflater.inflate(R.layout.fragment_inventario, container, false) |
| 77 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 78 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
| 78 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) | 79 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) |
| 79 | rcInventarios = v.findViewById(R.id.rcInventarios) | 80 | rcInventarios = v.findViewById(R.id.rcInventarios) |
| 80 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) | 81 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) |
| 81 | 82 | ||
| 82 | if (InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO | 83 | if (InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO |
| 83 | GlobalScope.launch(Dispatchers.Main) { | 84 | GlobalScope.launch(Dispatchers.Main) { |
| 84 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO | 85 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO |
| 85 | InventarioNuevo = AppDb.getAppDb(requireActivity())?.InvHeadDAO()?.findLastInv()?.plus(1) ?: 1 | 86 | InventarioNuevo = AppDb.getAppDb(requireActivity())?.InvHeadDAO()?.findLastInv()?.plus(1) ?: 1 |
| 86 | SerchArea() | 87 | SerchArea() |
| 87 | val descripInv: String = if (iArea == 0) "Ventas" else "Deposito" | 88 | val descripInv: String = if (iArea == 0) "Ventas" else "Deposito" |
| 88 | //TODO: CREAMOS EL INVENTARIO EN LA CABECERA DEL INVENTARIO | 89 | //TODO: CREAMOS EL INVENTARIO EN LA CABECERA DEL INVENTARIO |
| 89 | invHead = InvHead(InventarioNuevo, descripInv, 1, ObtenerFechaActual(), ObtenerFechaActual(), 0L, iArea, AjusteProductos(), ProdNoCont()) | 90 | invHead = InvHead(InventarioNuevo, descripInv, 1, ObtenerFechaActual(), ObtenerFechaActual(), 0L, iArea, AjusteProductos(), ProdNoCont()) |
| 90 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.insertInvHead(invHead) | 91 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.insertInvHead(invHead) |
| 91 | tvTitulo.text = "Inventario Dinamico" + " N° $InventarioNuevo" | 92 | tvTitulo.text = "Inventario Dinamico" + " N° $InventarioNuevo" |
| 92 | } | 93 | } |
| 93 | } else {// TODO (SI VENGO DE FRAGMENT DESCRIPCION) | 94 | } else {// TODO (SI VENGO DE FRAGMENT DESCRIPCION) |
| 94 | listArticulos.clear() | 95 | listArticulos.clear() |
| 95 | CargarDeBdInventario(InventarioNuevo) | 96 | CargarDeBdInventario(InventarioNuevo) |
| 96 | tvTitulo.text = "Inventario Dinamico" + " N° $InventarioNuevo" | 97 | tvTitulo.text = "Inventario Dinamico" + " N° $InventarioNuevo" |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 99 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> | 100 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> |
| 100 | if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_UP) { | 101 | if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_UP) { |
| 101 | sChangeUpper = tCodigoBarras.text.toString() | 102 | sChangeUpper = tCodigoBarras.text.toString() |
| 102 | 103 | ||
| 103 | var indiceDelArtEncontrado = 0 | 104 | var indiceDelArtEncontrado = 0 |
| 104 | 105 | ||
| 105 | //TODO COMIENZA LA BUSQUEDA POR CODIGO DE BARRAS | 106 | //TODO COMIENZA LA BUSQUEDA POR CODIGO DE BARRAS |
| 106 | when (iBusquedaPor) { | 107 | when (iBusquedaPor) { |
| 107 | 0 -> { | 108 | 0 -> { |
| 108 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 0)//TODO Si encuentra el articulo en el RV devuelve el indice | 109 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 0)//TODO Si encuentra el articulo en el RV devuelve el indice |
| 109 | //TODO Si no lo encuentra devuelve -1 | 110 | //TODO Si no lo encuentra devuelve -1 |
| 110 | if (indiceDelArtEncontrado != -1) { | 111 | if (indiceDelArtEncontrado != -1) { |
| 111 | if (swSumaUno!!.isChecked) { | 112 | if (swSumaUno!!.isChecked) { |
| 112 | fCant = 0F | 113 | fCant = 0F |
| 113 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 114 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 114 | fCant += 1F | 115 | fCant += 1F |
| 115 | //TODO ACTUALIZO LA CANTIDAD EN LA BD | 116 | //TODO ACTUALIZO LA CANTIDAD EN LA BD |
| 116 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 117 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
| 117 | //TODO ACTUALIZO LA CANTIDAD EN EL RV | 118 | //TODO ACTUALIZO LA CANTIDAD EN EL RV |
| 118 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 119 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 119 | viewAdapter.notifyDataSetChanged() | 120 | viewAdapter.notifyDataSetChanged() |
| 120 | } else { | 121 | } else { |
| 121 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 122 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
| 122 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[indiceDelArtEncontrado].descripcion}', se encuentra cargado.") | 123 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[indiceDelArtEncontrado].descripcion}', se encuentra cargado.") |
| 123 | .setCancelable(false) | 124 | .setCancelable(false) |
| 124 | mDialogView.tvCantInicial.text = listArticulos[indiceDelArtEncontrado].cantTomada.toString() | 125 | mDialogView.tvCantInicial.text = listArticulos[indiceDelArtEncontrado].cantTomada.toString() |
| 125 | val mAlertDialog = mBuilder.show() | 126 | val mAlertDialog = mBuilder.show() |
| 126 | mDialogView.rbSumar.setOnClickListener { | 127 | mDialogView.rbSumar.setOnClickListener { |
| 127 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 128 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 128 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 129 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 129 | } | 130 | } |
| 130 | } | 131 | } |
| 131 | mDialogView.rbRestar.setOnClickListener { | 132 | mDialogView.rbRestar.setOnClickListener { |
| 132 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 133 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 133 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 134 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
| 134 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 135 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 135 | } | 136 | } |
| 136 | } | 137 | } |
| 137 | } | 138 | } |
| 138 | mDialogView.rbMdodificar.setOnClickListener { | 139 | mDialogView.rbMdodificar.setOnClickListener { |
| 139 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 140 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 140 | mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 141 | mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 141 | } | 142 | } |
| 142 | } | 143 | } |
| 143 | mDialogView.btnAceptar.setOnClickListener { | 144 | mDialogView.btnAceptar.setOnClickListener { |
| 144 | mAlertDialog.dismiss() | 145 | mAlertDialog.dismiss() |
| 145 | val name = mDialogView.tvgenerico4.text.toString().toFloat() | 146 | val name = mDialogView.tvgenerico4.text.toString().toFloat() |
| 146 | fCant = 0F | 147 | fCant = 0F |
| 147 | fCant = name | 148 | fCant = name |
| 148 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 149 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 149 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 150 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
| 150 | viewAdapter.notifyDataSetChanged() | 151 | viewAdapter.notifyDataSetChanged() |
| 151 | } | 152 | } |
| 152 | mDialogView.dialogCancelBtn.setOnClickListener { | 153 | mDialogView.dialogCancelBtn.setOnClickListener { |
| 153 | mAlertDialog.dismiss() | 154 | mAlertDialog.dismiss() |
| 154 | } | 155 | } |
| 155 | } | 156 | } |
| 156 | 157 | ||
| 157 | } else if (indiceDelArtEncontrado == -1) {// no lo encontro en el RV, lo va a buscar en al BD | 158 | } else if (indiceDelArtEncontrado == -1) {// no lo encontro en el RV, lo va a buscar en al BD |
| 158 | 159 | ||
| 159 | GlobalScope.launch(Dispatchers.Main) { | 160 | GlobalScope.launch(Dispatchers.Main) { |
| 160 | //TODO BUSCO EN BASE DE DATOS | 161 | //TODO BUSCO EN BASE DE DATOS |
| 161 | val artEncontrado = buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 162 | val artEncontrado = buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
| 162 | ContinuarCargaCB(artEncontrado)//TODO SE MANDA CERO POR QUE ES UN ARTICULO ESCANEADO NUEVO PARA QUE SEA COMPATIBLE | 163 | ContinuarCargaCB(artEncontrado)//TODO SE MANDA CERO POR QUE ES UN ARTICULO ESCANEADO NUEVO PARA QUE SEA COMPATIBLE |
| 163 | } | 164 | } |
| 164 | } | 165 | } |
| 165 | 166 | ||
| 166 | tCodigoBarras.focusable = View.FOCUSABLE | 167 | tCodigoBarras.focusable = View.FOCUSABLE |
| 167 | tCodigoBarras.setText("") | 168 | tCodigoBarras.setText("") |
| 168 | tCodigoBarras.selectAll() | 169 | tCodigoBarras.selectAll() |
| 169 | return@setOnKeyListener true | 170 | return@setOnKeyListener true |
| 170 | 171 | ||
| 171 | 172 | ||
| 172 | } | 173 | } |
| 173 | 1 -> {//TODO: BUSQUEDA POR DESCRIPCION************************************************************************** | 174 | 1 -> {//TODO: BUSQUEDA POR DESCRIPCION************************************************************************** |
| 174 | // | 175 | // |
| 175 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 1) //TODO :Si encuentra el articulo en el RV devuelve el indice | 176 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 1) //TODO :Si encuentra el articulo en el RV devuelve el indice |
| 176 | // //TODO Si no lo encuentra devuelve -1 | 177 | // //TODO Si no lo encuentra devuelve -1 |
| 177 | // if (indiceDelArtEncontrado != -1) { | 178 | // if (indiceDelArtEncontrado != -1) { |
| 178 | //// if (swSumaUno!!.isChecked) { | 179 | //// if (swSumaUno!!.isChecked) { |
| 179 | //// fCant = 0F | 180 | //// fCant = 0F |
| 180 | //// fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 181 | //// fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 181 | //// fCant += 1F | 182 | //// fCant += 1F |
| 182 | //// listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 183 | //// listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 183 | //// viewAdapter.notifyDataSetChanged() | 184 | //// viewAdapter.notifyDataSetChanged() |
| 184 | //// } else { | 185 | //// } else { |
| 185 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 186 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 186 | // MaterialDialog(requireContext()).show { | 187 | // MaterialDialog(requireContext()).show { |
| 187 | // title(R.string.sTituloNueva) | 188 | // title(R.string.sTituloNueva) |
| 188 | // message(R.string.sCantidadNueva) | 189 | // message(R.string.sCantidadNueva) |
| 189 | // input { materialDialog, charSequence -> | 190 | // input { materialDialog, charSequence -> |
| 190 | // fCant = 0F | 191 | // fCant = 0F |
| 191 | // fCant = charSequence.toString().toFloat() | 192 | // fCant = charSequence.toString().toFloat() |
| 192 | // } | 193 | // } |
| 193 | // positiveButton(R.string.btnOk) { | 194 | // positiveButton(R.string.btnOk) { |
| 194 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 195 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 195 | // viewAdapter.notifyDataSetChanged() | 196 | // viewAdapter.notifyDataSetChanged() |
| 196 | // dismiss() | 197 | // dismiss() |
| 197 | // } | 198 | // } |
| 198 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 199 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
| 199 | //// } | 200 | //// } |
| 200 | // | 201 | // |
| 201 | // } else if | 202 | // } else if |
| 202 | // (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD | 203 | // (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD |
| 203 | GlobalScope.launch(Dispatchers.Main) { | 204 | GlobalScope.launch(Dispatchers.Main) { |
| 204 | val artEncontrado = buscarDescEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 205 | val artEncontrado = buscarDescEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
| 205 | ContinuarCargaDesc(artEncontrado as ArrayList<Articles>) | 206 | ContinuarCargaDesc(artEncontrado as ArrayList<Articles>) |
| 206 | } | 207 | } |
| 207 | // } | 208 | // } |
| 208 | tCodigoBarras.focusable = View.FOCUSABLE | 209 | |
| 209 | tCodigoBarras.setText("") | ||
| 210 | tCodigoBarras.selectAll() | ||
| 211 | return@setOnKeyListener true | 210 | return@setOnKeyListener true |
| 212 | } | 211 | } |
| 213 | 2 -> {//TODO: BUSQUEDA POR CODIGO DE ORIGEN************************************************************************** | 212 | 2 -> {//TODO: BUSQUEDA POR CODIGO DE ORIGEN************************************************************************** |
| 214 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 3)//TODO Si encuentra el articulo en el RV devuelve el indice | 213 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 3)//TODO Si encuentra el articulo en el RV devuelve el indice |
| 215 | //TODO Si no lo encuentra devuelve -1 | 214 | //TODO Si no lo encuentra devuelve -1 |
| 216 | if (indiceDelArtEncontrado != -1) { | 215 | if (indiceDelArtEncontrado != -1) { |
| 217 | if (swSumaUno!!.isChecked) { | 216 | if (swSumaUno!!.isChecked) { |
| 218 | fCant = 0F | 217 | fCant = 0F |
| 219 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 218 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 220 | fCant += 1F | 219 | fCant += 1F |
| 221 | //TODO ACTUALIZO LA CANTIDAD EN LA BD | 220 | //TODO ACTUALIZO LA CANTIDAD EN LA BD |
| 222 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 221 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
| 223 | //TODO ACTUALIZO LA CANTIDAD EN EL RV | 222 | //TODO ACTUALIZO LA CANTIDAD EN EL RV |
| 224 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 223 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 225 | viewAdapter.notifyDataSetChanged() | 224 | viewAdapter.notifyDataSetChanged() |
| 226 | } else { | 225 | } else { |
| 227 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 226 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
| 228 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[indiceDelArtEncontrado].descripcion}', se encuentra cargado.") | 227 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[indiceDelArtEncontrado].descripcion}', se encuentra cargado.") |
| 229 | .setCancelable(false) | 228 | .setCancelable(false) |
| 230 | mDialogView.tvCantInicial.text = listArticulos[indiceDelArtEncontrado].cantTomada.toString() | 229 | mDialogView.tvCantInicial.text = listArticulos[indiceDelArtEncontrado].cantTomada.toString() |
| 231 | val mAlertDialog = mBuilder.show() | 230 | val mAlertDialog = mBuilder.show() |
| 232 | mDialogView.rbSumar.setOnClickListener { | 231 | mDialogView.rbSumar.setOnClickListener { |
| 233 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 232 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 234 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 233 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 235 | } | 234 | } |
| 236 | } | 235 | } |
| 237 | mDialogView.rbRestar.setOnClickListener { | 236 | mDialogView.rbRestar.setOnClickListener { |
| 238 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 237 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 239 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 238 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
| 240 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 239 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 241 | } | 240 | } |
| 242 | } | 241 | } |
| 243 | } | 242 | } |
| 244 | mDialogView.rbMdodificar.setOnClickListener { | 243 | mDialogView.rbMdodificar.setOnClickListener { |
| 245 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 244 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 246 | mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 245 | mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 247 | } | 246 | } |
| 248 | } | 247 | } |
| 249 | mDialogView.btnAceptar.setOnClickListener { | 248 | mDialogView.btnAceptar.setOnClickListener { |
| 250 | mAlertDialog.dismiss() | 249 | mAlertDialog.dismiss() |
| 251 | val name = mDialogView.tvgenerico4.text.toString().toFloat() | 250 | val name = mDialogView.tvgenerico4.text.toString().toFloat() |
| 252 | fCant = 0F | 251 | fCant = 0F |
| 253 | fCant = name | 252 | fCant = name |
| 254 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 253 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 255 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 254 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
| 256 | viewAdapter.notifyDataSetChanged() | 255 | viewAdapter.notifyDataSetChanged() |
| 257 | } | 256 | } |
| 258 | mDialogView.dialogCancelBtn.setOnClickListener { | 257 | mDialogView.dialogCancelBtn.setOnClickListener { |
| 259 | mAlertDialog.dismiss() | 258 | mAlertDialog.dismiss() |
| 260 | } | 259 | } |
| 261 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 260 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
| 262 | // val type = InputType.TYPE_CLASS_NUMBER | 261 | // val type = InputType.TYPE_CLASS_NUMBER |
| 263 | // MaterialDialog(requireContext()).show { | 262 | // MaterialDialog(requireContext()).show { |
| 264 | // | 263 | // |
| 265 | // title(text = "Producto '$sChangeUpper', se encuentra cargado.") | 264 | // title(text = "Producto '$sChangeUpper', se encuentra cargado.") |
| 266 | // message(R.string.sCantidadNueva) | 265 | // message(R.string.sCantidadNueva) |
| 267 | // input(waitForPositiveButton = false, hint = "99.99", inputType = type) { materialDialog, charSequence -> | 266 | // input(waitForPositiveButton = false, hint = "99.99", inputType = type) { materialDialog, charSequence -> |
| 268 | // fCant = 0F | 267 | // fCant = 0F |
| 269 | // fCant = charSequence.toString().toFloat() | 268 | // fCant = charSequence.toString().toFloat() |
| 270 | // } | 269 | // } |
| 271 | // positiveButton(R.string.btnOk) { | 270 | // positiveButton(R.string.btnOk) { |
| 272 | // //TODO ACTUALIZO CANTIADAD EN BD | 271 | // //TODO ACTUALIZO CANTIADAD EN BD |
| 273 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 272 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
| 274 | // //TODO ACTUALIZO CANTIDAD EN RV | 273 | // //TODO ACTUALIZO CANTIDAD EN RV |
| 275 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 274 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
| 276 | // viewAdapter.notifyDataSetChanged() | 275 | // viewAdapter.notifyDataSetChanged() |
| 277 | // dismiss() | 276 | // dismiss() |
| 278 | // } | 277 | // } |
| 279 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 278 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
| 280 | } | 279 | } |
| 281 | |||
| 282 | } else if (indiceDelArtEncontrado == -1) {// no lo encontro en el RV, lo va a buscar en al BD | 280 | } else if (indiceDelArtEncontrado == -1) {// no lo encontro en el RV, lo va a buscar en al BD |
| 283 | 281 | ||
| 284 | GlobalScope.launch(Dispatchers.Main) { | 282 | GlobalScope.launch(Dispatchers.Main) { |
| 285 | //TODO BUSCO EN BASE DE DATOS | 283 | //TODO BUSCO EN BASE DE DATOS |
| 286 | listArticulos[indiceDelArtEncontrado].cantTomada | 284 | listArticulos[indiceDelArtEncontrado].cantTomada |
| 287 | val artEncontrado = buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 285 | val artEncontrado = buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
| 288 | ContinuarCargaCB(artEncontrado) | 286 | ContinuarCargaCB(artEncontrado) |
| 289 | } | 287 | } |
| 290 | } | 288 | } |
| 291 | |||
| 292 | tCodigoBarras.focusable = View.FOCUSABLE | ||
| 293 | tCodigoBarras.setText("") | ||
| 294 | tCodigoBarras.selectAll() | ||
| 295 | return@setOnKeyListener true | 289 | return@setOnKeyListener true |
| 296 | |||
| 297 | |||
| 298 | } | 290 | } |
| 299 | } | 291 | } |
| 300 | } | 292 | } |
| 301 | return@setOnKeyListener false | 293 | return@setOnKeyListener false |
| 302 | } | 294 | } |
| 303 | return v | 295 | return v |
| 304 | } | 296 | } |
| 305 | 297 | ||
| 306 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 298 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
| 307 | super.onViewCreated(view, savedInstanceState) | 299 | super.onViewCreated(view, savedInstanceState) |
| 308 | navController = Navigation.findNavController(view) | 300 | navController = Navigation.findNavController(view) |
| 309 | etCodigoBarras.requestFocus() | 301 | etCodigoBarras.requestFocus() |
| 310 | 302 | ||
| 311 | btnBorrarInv.setOnClickListener { | 303 | btnBorrarInv.setOnClickListener { |
| 312 | MaterialDialog(requireContext()).show { | 304 | MaterialDialog(requireContext()).show { |
| 313 | title(R.string.sTituloBorrarInv) | 305 | title(R.string.sTituloBorrarInv) |
| 314 | message(R.string.sMensajeBorrarInv) | 306 | message(R.string.sMensajeBorrarInv) |
| 315 | positiveButton(R.string.btnOk) { | 307 | positiveButton(R.string.btnOk) { |
| 316 | BorrarInvActual() | 308 | BorrarInvActual() |
| 317 | Toast.makeText(requireContext(), "El inventario $InventarioNuevo fue Borrado", Toast.LENGTH_LONG).show() | 309 | Toast.makeText(requireContext(), "El inventario $InventarioNuevo fue Borrado", Toast.LENGTH_LONG).show() |
| 318 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) | 310 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
| 319 | InventarioNuevo = 0 | 311 | InventarioNuevo = 0 |
| 320 | dismiss() | 312 | dismiss() |
| 321 | } | 313 | } |
| 322 | negativeButton { | 314 | negativeButton { |
| 323 | dismiss() | 315 | dismiss() |
| 324 | } | 316 | } |
| 325 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 317 | }.cancelOnTouchOutside(false).cornerRadius(10F) |
| 326 | } | 318 | } |
| 327 | 319 | ||
| 328 | btnExportarInv.setOnClickListener { | 320 | btnExportarInv.setOnClickListener { |
| 329 | MaterialDialog(requireContext()).show { | 321 | MaterialDialog(requireContext()).show { |
| 330 | title(R.string.sTituloExportar) | 322 | title(R.string.sTituloExportar) |
| 331 | message(R.string.sMensajeExportar) | 323 | message(R.string.sMensajeExportar) |
| 332 | positiveButton(R.string.btnOk) { | 324 | positiveButton(R.string.btnOk) { |
| 333 | BorrarInvActual() | 325 | BorrarInvActual() |
| 334 | Toast.makeText(requireContext(), "El inventario $InventarioNuevo fue Exportado al Servidor", Toast.LENGTH_LONG).show() | 326 | Toast.makeText(requireContext(), "El inventario $InventarioNuevo fue Exportado al Servidor", Toast.LENGTH_LONG).show() |
| 335 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) | 327 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
| 336 | InventarioNuevo = 0 | 328 | InventarioNuevo = 0 |
| 337 | dismiss() | 329 | dismiss() |
| 338 | } | 330 | } |
| 339 | negativeButton { | 331 | negativeButton { |
| 340 | dismiss() | 332 | dismiss() |
| 341 | } | 333 | } |
| 342 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 334 | }.cancelOnTouchOutside(false).cornerRadius(10F) |
| 343 | } | 335 | } |
| 344 | ivCamara.setOnClickListener { | 336 | ivCamara.setOnClickListener { |
| 345 | if (!bFirst) { | 337 | if (!bFirst) { |
| 346 | iEstado = 1 | 338 | iEstado = 1 |
| 347 | bFirst = true | 339 | bFirst = true |
| 348 | } | 340 | } |
| 349 | 341 | ||
| 350 | when (iEstado) { | 342 | when (iEstado) { |
| 351 | 0 -> { | 343 | 0 -> { |
| 352 | ivCamara.setImageResource(R.drawable.codbar) | 344 | ivCamara.setImageResource(R.drawable.codbar) |
| 353 | etCodigoBarras.hint = "Busqueda por C. Barras" | 345 | etCodigoBarras.hint = "Busqueda por C. Barras" |
| 354 | swSumaUno.visibility = View.VISIBLE | 346 | swSumaUno.visibility = View.VISIBLE |
| 355 | iBusquedaPor = 0 | 347 | iBusquedaPor = 0 |
| 356 | iEstado = 1 | 348 | iEstado = 1 |
| 357 | } | 349 | } |
| 358 | 1 -> { | 350 | 1 -> { |
| 359 | ivCamara.setImageResource(R.drawable.desc) | 351 | ivCamara.setImageResource(R.drawable.desc) |
| 360 | etCodigoBarras.hint = "Busqueda por Descripción" | 352 | etCodigoBarras.hint = "Busqueda por Descripción" |
| 361 | swSumaUno.visibility = View.GONE | 353 | swSumaUno.visibility = View.GONE |
| 362 | iBusquedaPor = 1 | 354 | iBusquedaPor = 1 |
| 363 | iEstado = 2 | 355 | iEstado = 2 |
| 364 | } | 356 | } |
| 365 | 2 -> { | 357 | 2 -> { |
| 366 | ivCamara.setImageResource(R.drawable.cod_origen) | 358 | ivCamara.setImageResource(R.drawable.cod_origen) |
| 367 | etCodigoBarras.hint = "Busqueda por C. Origen" | 359 | etCodigoBarras.hint = "Busqueda por C. Origen" |
| 368 | swSumaUno.visibility = View.GONE | 360 | swSumaUno.visibility = View.GONE |
| 369 | iBusquedaPor = 2 | 361 | iBusquedaPor = 2 |
| 370 | iEstado = 0 | 362 | iEstado = 0 |
| 371 | } | 363 | } |
| 372 | } | 364 | } |
| 373 | } | 365 | } |
| 374 | } | 366 | } |
| 375 | 367 | ||
| 376 | private fun BorrarInvActual() { | 368 | private fun BorrarInvActual() { |
| 377 | lifecycleScope.launch { | 369 | lifecycleScope.launch { |
| 378 | withContext(Dispatchers.IO) { | 370 | withContext(Dispatchers.IO) { |
| 379 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.deleteinvHead(InventarioNuevo) | 371 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.deleteinvHead(InventarioNuevo) |
| 380 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.deleteInvBody(InventarioNuevo) | 372 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.deleteInvBody(InventarioNuevo) |
| 381 | } | 373 | } |
| 382 | } | 374 | } |
| 383 | } | 375 | } |
| 384 | 376 | ||
| 385 | private fun CargarDeBdInventario(ultimoInv: Int) { | 377 | private fun CargarDeBdInventario(ultimoInv: Int) { |
| 386 | GlobalScope.launch(Dispatchers.Main) { | 378 | GlobalScope.launch(Dispatchers.Main) { |
| 387 | val invbody = cargarInventario(ultimoInv) | 379 | val invbody = cargarInventario(ultimoInv) |
| 388 | for ((i, item) in invbody!!.withIndex()) { | 380 | for ((i, item) in invbody!!.withIndex()) { |
| 389 | val art = Articles(invbody[i].sector, | 381 | val art = Articles(invbody[i].sector, |
| 390 | invbody[i].codigo, | 382 | invbody[i].codigo, |
| 391 | invbody[i].descripcion, | 383 | invbody[i].descripcion, |
| 392 | invbody[i].codBar, | 384 | invbody[i].codBar, |
| 393 | invbody[i].codOrigen, | 385 | invbody[i].codOrigen, |
| 394 | invbody[i].precio, | 386 | invbody[i].precio, |
| 395 | invbody[i].costo, | 387 | invbody[i].costo, |
| 396 | "", | 388 | "", |
| 397 | "", | 389 | "", |
| 398 | "", | 390 | "", |
| 399 | invbody[i].balanza, | 391 | invbody[i].balanza, |
| 400 | invbody[i].depSn, | 392 | invbody[i].depSn, |
| 401 | invbody[i].costo) | 393 | invbody[i].costo) |
| 402 | cargarRecicler(art, invbody[i].cantTomada!!.toFloat()) | 394 | cargarRecicler(art, invbody[i].cantTomada!!.toFloat()) |
| 403 | } | 395 | } |
| 404 | } | 396 | } |
| 405 | 397 | ||
| 406 | } | 398 | } |
| 407 | 399 | ||
| 408 | private fun ContinuarCargaDesc(artAcargar: ArrayList<Articles>) { | 400 | private fun ContinuarCargaDesc(artAcargar: ArrayList<Articles>) { |
| 409 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS | 401 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS |
| 410 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV | 402 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV |
| 411 | 403 | ||
| 412 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD | 404 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD |
| 413 | // if (swSumaUno!!.isChecked) {// TODO: SI ESTA +1, PONE CANTIDAD 1 | 405 | // if (swSumaUno!!.isChecked) {// TODO: SI ESTA +1, PONE CANTIDAD 1 |
| 414 | if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV | 406 | if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV |
| 415 | fCant = 0F | 407 | fCant = 0F |
| 416 | fCant += 1F | 408 | fCant += 1F |
| 417 | // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV | 409 | // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV |
| 418 | val acargarPorDesc = Articles(artAcargar[0].sector, | 410 | val acargarPorDesc = Articles(artAcargar[0].sector, |
| 419 | artAcargar[0].codigo, | 411 | artAcargar[0].codigo, |
| 420 | artAcargar[0].descripcion, | 412 | artAcargar[0].descripcion, |
| 421 | artAcargar[0].codBar, | 413 | artAcargar[0].codBar, |
| 422 | artAcargar[0].codOrigen, | 414 | artAcargar[0].codOrigen, |
| 423 | artAcargar[0].precio, | 415 | artAcargar[0].precio, |
| 424 | artAcargar[0].costo, | 416 | artAcargar[0].costo, |
| 425 | "", | 417 | "", |
| 426 | "", | 418 | "", |
| 427 | "", | 419 | "", |
| 428 | artAcargar[0].balanza, | 420 | artAcargar[0].balanza, |
| 429 | artAcargar[0].depSn, | 421 | artAcargar[0].depSn, |
| 430 | "") | 422 | "") |
| 431 | // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD | 423 | // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD |
| 432 | cargarArtEnBd(acargarPorDesc, fCant) | 424 | cargarArtEnBd(acargarPorDesc, fCant) |
| 433 | cargarRecicler(acargarPorDesc, fCant) | 425 | cargarRecicler(acargarPorDesc, fCant) |
| 434 | } else { | 426 | } else { |
| 435 | var bundle = Bundle() | 427 | var bundle = Bundle() |
| 436 | bundle = bundleOf("ArrayDesc" to artAcargar) | 428 | bundle = bundleOf("ArrayDesc" to artAcargar) |
| 437 | bundle.putInt("numeroInv", InventarioNuevo) | 429 | bundle.putInt("numeroInv", InventarioNuevo) |
| 438 | navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) | 430 | navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) |
| 439 | } | 431 | } |
| 440 | // } else {//SI NO ESTA +1 | 432 | // } else {//SI NO ESTA +1 |
| 441 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV | 433 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV |
| 442 | // fCant = listArticulos[0].cantTomada | 434 | // fCant = listArticulos[0].cantTomada |
| 443 | // MaterialDialog(requireContext()).show { | 435 | // MaterialDialog(requireContext()).show { |
| 444 | // title(R.string.sTituloNueva) | 436 | // title(R.string.sTituloNueva) |
| 445 | // message(R.string.sCantidadNueva) | 437 | // message(R.string.sCantidadNueva) |
| 446 | // input { materialDialog, charSequence -> | 438 | // input { materialDialog, charSequence -> |
| 447 | // fCant = 0F | 439 | // fCant = 0F |
| 448 | // fCant = charSequence.toString().toFloat() | 440 | // fCant = charSequence.toString().toFloat() |
| 449 | // } | 441 | // } |
| 450 | // positiveButton(R.string.btnOk) { | 442 | // positiveButton(R.string.btnOk) { |
| 451 | // listArticulos[0].cantTomada = fCant | 443 | // listArticulos[0].cantTomada = fCant |
| 452 | // viewAdapter.notifyDataSetChanged() | 444 | // viewAdapter.notifyDataSetChanged() |
| 453 | // dismiss() | 445 | // dismiss() |
| 454 | // } | 446 | // } |
| 455 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 447 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
| 456 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV | 448 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV |
| 457 | // val acargarPorDesc = Articles(artAcargar[0].sector, | 449 | // val acargarPorDesc = Articles(artAcargar[0].sector, |
| 458 | // artAcargar[0].codigo, | 450 | // artAcargar[0].codigo, |
| 459 | // artAcargar[0].descripcion, | 451 | // artAcargar[0].descripcion, |
| 460 | // artAcargar[0].codBar, | 452 | // artAcargar[0].codBar, |
| 461 | // artAcargar[0].cod_origen, | 453 | // artAcargar[0].cod_origen, |
| 462 | // artAcargar[0].precio, | 454 | // artAcargar[0].precio, |
| 463 | // artAcargar[0].costo, | 455 | // artAcargar[0].costo, |
| 464 | // artAcargar[0].balanza, | 456 | // artAcargar[0].balanza, |
| 465 | // artAcargar[0].depSn, | 457 | // artAcargar[0].depSn, |
| 466 | // "") | 458 | // "") |
| 467 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD | 459 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD |
| 468 | // cargarArtEnBd(acargarPorDesc, fCant) | 460 | // cargarArtEnBd(acargarPorDesc, fCant) |
| 469 | // cargarRecicler(acargarPorDesc, fCant) | 461 | // cargarRecicler(acargarPorDesc, fCant) |
| 470 | // } else { | 462 | // } else { |
| 471 | // var bundle = Bundle() | 463 | // var bundle = Bundle() |
| 472 | // bundle = bundleOf("ArrayDesc" to artAcargar) | 464 | // bundle = bundleOf("ArrayDesc" to artAcargar) |
| 473 | // bundle.putInt("numeroInv", InventarioNuevo) | 465 | // bundle.putInt("numeroInv", InventarioNuevo) |
| 474 | // navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) | 466 | // navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) |
| 475 | // } | 467 | // } |
| 476 | // } | 468 | // } |
| 477 | } else {//TODO si no lo encuentra en la BD | 469 | } else {//TODO si no lo encuentra en la BD |
| 478 | MaterialDialog(requireContext()).show { | 470 | val modalDialog = DialogNoEncontrado() |
| 479 | title(text = "El articulo ${etCodigoBarras.text}") | 471 | |
| 480 | message(R.string.sMensaje) | 472 | modalDialog.show(requireActivity().supportFragmentManager, "confirmDialog") |
| 481 | positiveButton(R.string.btnOk) { | 473 | |
| 482 | dismiss() | 474 | // MaterialDialog(requireContext()).show { |
| 483 | } | 475 | // val t=etCodigoBarras.text |
| 484 | }.cornerRadius(10F) | 476 | // title(text = "El articulo ${etCodigoBarras.text.toString()}") |
| 477 | // message(R.string.sMensaje) | ||
| 478 | // positiveButton(R.string.btnOk) { | ||
| 479 | // dismiss() | ||
| 480 | // } | ||
| 481 | // }.cornerRadius(10F) | ||
| 485 | } | 482 | } |
| 483 | etCodigoBarras.focusable = View.FOCUSABLE | ||
| 484 | etCodigoBarras.setText("") | ||
| 485 | etCodigoBarras.selectAll() | ||
| 486 | } | 486 | } |
| 487 | 487 | ||
| 488 | private fun ContinuarCargaCB(artAcargar: Articles?) { | 488 | private fun ContinuarCargaCB(artAcargar: Articles?) { |
| 489 | 489 | ||
| 490 | if (artAcargar != null) {// TODO: Si lo encuentra en la BD | 490 | if (artAcargar != null) {// TODO: Si lo encuentra en la BD |
| 491 | if (swSumaUno!!.isChecked) {//TODO: SI ESTA +1, PONE CANTIDAD 1 | 491 | if (swSumaUno!!.isChecked) {//TODO: SI ESTA +1, PONE CANTIDAD 1 |
| 492 | fCant = 0F | 492 | fCant = 0F |
| 493 | fCant += 1F | 493 | fCant += 1F |
| 494 | cargarArtEnBd(artAcargar, fCant) | 494 | cargarArtEnBd(artAcargar, fCant) |
| 495 | cargarRecicler(artAcargar, fCant) | 495 | cargarRecicler(artAcargar, fCant) |
| 496 | } else {//SI NO ESTA +1 PREGUNTA CANTIDAD | 496 | } else {//SI NO ESTA +1 PREGUNTA CANTIDAD |
| 497 | 497 | ||
| 498 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.ingresar_cantidad, null) | 498 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.ingresar_cantidad, null) |
| 499 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(false) | 499 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(false) |
| 500 | mDialogView.tvTitulo.text="Producto '${artAcargar.descripcion.toString()}'." | 500 | mDialogView.tvTitulo.text="Producto '${artAcargar.descripcion.toString()}'." |
| 501 | val mAlertDialog = mBuilder.show() | 501 | val mAlertDialog = mBuilder.show() |
| 502 | mDialogView.btnAceptar.setOnClickListener { | 502 | mDialogView.btnAceptar.setOnClickListener { |
| 503 | mAlertDialog.dismiss() | 503 | mAlertDialog.dismiss() |
| 504 | fCant = 0F | 504 | fCant = 0F |
| 505 | fCant = mDialogView.etCantidad.text.toString().toFloat() | 505 | fCant = mDialogView.etCantidad.text.toString().toFloat() |
| 506 | cargarArtEnBd(artAcargar, fCant) | 506 | cargarArtEnBd(artAcargar, fCant) |
| 507 | cargarRecicler(artAcargar, fCant) | 507 | cargarRecicler(artAcargar, fCant) |
| 508 | } | 508 | } |
| 509 | } | 509 | } |
| 510 | } else {// TODO si no lo encuentra en la BD | 510 | } else {// TODO si no lo encuentra en la BD |
| 511 | 511 | ||
| 512 | MaterialDialog(requireContext()).show { | 512 | MaterialDialog(requireContext()).show { |
| 513 | title(text = "El producto: $sChangeUpper") | 513 | title(text = "El producto: $sChangeUpper") |
| 514 | message(text = "¡No fue encontrado!") | 514 | message(text = "¡No fue encontrado!") |
| 515 | positiveButton(R.string.btnOk) {} | 515 | positiveButton(R.string.btnOk) {} |
| 516 | dismiss() | 516 | dismiss() |
| 517 | } | 517 | } |
| 518 | } | 518 | } |
| 519 | etCodigoBarras.focusable = View.FOCUSABLE | ||
| 520 | etCodigoBarras.setText("") | ||
| 521 | etCodigoBarras.selectAll() | ||
| 519 | } | 522 | } |
| 520 | 523 | ||
| 521 | suspend fun buscarCBEnBD(CodigoBarras: String): Articles? { | 524 | suspend fun buscarCBEnBD(CodigoBarras: String): Articles? { |
| 522 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 525 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
| 523 | var busqueda: Articles? = null | 526 | var busqueda: Articles? = null |
| 524 | return GlobalScope.async(Dispatchers.IO) { | 527 | return GlobalScope.async(Dispatchers.IO) { |
| 525 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBar(CodigoBarras, iArea) | 528 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBar(CodigoBarras, iArea) |
| 526 | return@async busqueda | 529 | return@async busqueda |
| 527 | }.await() | 530 | }.await() |
| 528 | } | 531 | } |
| 529 | 532 | ||
| 530 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { | 533 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { |
| 531 | //TODO BUSQUEDA POR DESCRIPCION | 534 | //TODO BUSQUEDA POR DESCRIPCION |
| 532 | var busqueda: List<Articles>? = null | 535 | var busqueda: List<Articles>? = null |
| 533 | return GlobalScope.async(Dispatchers.IO) { | 536 | return GlobalScope.async(Dispatchers.IO) { |
| 534 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, iArea) | 537 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, iArea) |
| 535 | return@async busqueda | 538 | return@async busqueda |
| 536 | }.await() | 539 | }.await() |
| 537 | } | 540 | } |
| 538 | 541 | ||
| 539 | suspend fun borrarArticulo(sector: String, codigo: String, inventario: String): Int? { | 542 | suspend fun borrarArticulo(sector: String, codigo: String, inventario: String): Int? { |
| 540 | //TODO BUSQUEDA POR DESCRIPCION | 543 | //TODO BUSQUEDA POR DESCRIPCION |
| 541 | var result: Int | 544 | var result: Int |
| 542 | return GlobalScope.async(Dispatchers.IO) { | 545 | return GlobalScope.async(Dispatchers.IO) { |
| 543 | result = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.deleteItemFromInvBody(sector, codigo, inventario) | 546 | result = AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.deleteItemFromInvBody(sector, codigo, inventario) |
| 544 | return@async result | 547 | return@async result |
| 545 | }.await() | 548 | }.await() |
| 546 | } | 549 | } |
| 547 | 550 | ||
| 548 | private fun buscoArtEnRv(codigoBarras: String, sTipoBusqueda: Int): Int { | 551 | private fun buscoArtEnRv(codigoBarras: String, sTipoBusqueda: Int): Int { |
| 549 | var indice = 0 | 552 | var indice = 0 |
| 550 | var bEncontrado = false | 553 | var bEncontrado = false |
| 551 | if (sTipoBusqueda == 0) {//TODO BUSQUEDA POR CODIGO DE BARRAS | 554 | if (sTipoBusqueda == 0) {//TODO BUSQUEDA POR CODIGO DE BARRAS |
| 552 | for (item in listArticulos) { | 555 | for (item in listArticulos) { |
| 553 | if (item.codigoBarras!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 556 | if (item.codigoBarras!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
| 554 | bEncontrado = true | 557 | bEncontrado = true |
| 555 | break | 558 | break |
| 556 | } | 559 | } |
| 557 | indice += 1 | 560 | indice += 1 |
| 558 | } | 561 | } |
| 559 | } else if (sTipoBusqueda == 1) {//TODO BUSQUEDA POR DESCRIPCION | 562 | } else if (sTipoBusqueda == 1) {//TODO BUSQUEDA POR DESCRIPCION |
| 560 | for (item in listArticulos) { | 563 | for (item in listArticulos) { |
| 561 | if (item.descripcion!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 564 | if (item.descripcion!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
| 562 | bEncontrado = true | 565 | bEncontrado = true |
| 563 | break | 566 | break |
| 564 | } | 567 | } |
| 565 | indice += 1 | 568 | indice += 1 |
| 566 | } | 569 | } |
| 567 | } else if (sTipoBusqueda == 2) {//TODO BUSQUEDA POR CODIGO DE ORIGEN | 570 | } else if (sTipoBusqueda == 2) {//TODO BUSQUEDA POR CODIGO DE ORIGEN |
| 568 | for (item in listArticulos) { | 571 | for (item in listArticulos) { |
| 569 | if (item.codigoOrigen!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 572 | if (item.codigoOrigen!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
| 570 | bEncontrado = true | 573 | bEncontrado = true |
| 571 | break | 574 | break |
| 572 | } | 575 | } |
| 573 | indice += 1 | 576 | indice += 1 |
| 574 | } | 577 | } |
| 575 | } | 578 | } |
| 576 | return if (bEncontrado) indice | 579 | return if (bEncontrado) indice |
| 577 | else -1 | 580 | else -1 |
| 578 | } | 581 | } |
| 579 | 582 | ||
| 580 | private fun cargarArtEnBd(articulos: Articles, cant: Float) { | 583 | private fun cargarArtEnBd(articulos: Articles, cant: Float) { |
| 581 | val body = InvBody(InventarioNuevo,// TODO PREPARO PARA MANDAR A CARGAR EN LA BD | 584 | val body = InvBody(InventarioNuevo,// TODO PREPARO PARA MANDAR A CARGAR EN LA BD |
| 582 | articulos.sector, | 585 | articulos.sector, |
| 583 | articulos.codigo, | 586 | articulos.codigo, |
| 584 | articulos.descripcion, | 587 | articulos.descripcion, |
| 585 | cant.toString(), | 588 | cant.toString(), |
| 586 | articulos.codBar, | 589 | articulos.codBar, |
| 587 | articulos.codOrigen, | 590 | articulos.codOrigen, |
| 588 | articulos.precio, | 591 | articulos.precio, |
| 589 | articulos.precio, | 592 | articulos.precio, |
| 590 | articulos.balanza, | 593 | articulos.balanza, |
| 591 | articulos.depSn, | 594 | articulos.depSn, |
| 592 | ObtenerFechaActual(), | 595 | ObtenerFechaActual(), |
| 593 | ObtenerFechaActual()) | 596 | ObtenerFechaActual()) |
| 594 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS | 597 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS |
| 595 | } | 598 | } |
| 596 | 599 | ||
| 597 | fun cargarRecicler(articulos: Articles, cant: Float) { | 600 | fun cargarRecicler(articulos: Articles, cant: Float) { |
| 598 | //TODO CARGO EN LE RV | 601 | //TODO CARGO EN LE RV |
| 599 | val item = ItemsRecycler(articulos.sector, articulos.codigo, articulos.descripcion, cant, articulos.codBar, articulos.codOrigen) | 602 | val item = ItemsRecycler(articulos.sector, articulos.codigo, articulos.descripcion, cant, articulos.codBar, articulos.codOrigen) |
| 600 | listArticulos.add(item) | 603 | listArticulos.add(item) |
| 601 | 604 | ||
| 602 | viewAdapter = ProductosListAdapter(requireContext(), listArticulos, this) | 605 | viewAdapter = ProductosListAdapter(requireContext(), listArticulos, this) |
| 603 | viewManager = LinearLayoutManager(requireContext()) | 606 | viewManager = LinearLayoutManager(requireContext()) |
| 604 | deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! | 607 | deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! |
| 605 | rcInventarios.apply { | 608 | rcInventarios.apply { |
| 606 | adapter = viewAdapter | 609 | adapter = viewAdapter |
| 607 | layoutManager = viewManager | 610 | layoutManager = viewManager |
| 608 | } | 611 | } |
| 609 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { | 612 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { |
| 610 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { | 613 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { |
| 611 | return false | 614 | return false |
| 612 | } | 615 | } |
| 613 | 616 | ||
| 614 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | 617 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { |
| 615 | 618 | ||
| 616 | GlobalScope.launch(Dispatchers.Main) { | 619 | GlobalScope.launch(Dispatchers.Main) { |
| 617 | borrarArticulo(listArticulos[viewHolder.adapterPosition].sector.toString(), listArticulos[viewHolder.adapterPosition].codigo.toString(), InventarioNuevo.toString()) | 620 | borrarArticulo(listArticulos[viewHolder.adapterPosition].sector.toString(), listArticulos[viewHolder.adapterPosition].codigo.toString(), InventarioNuevo.toString()) |
| 618 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) | 621 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) |
| 619 | viewAdapter.notifyDataSetChanged() | 622 | viewAdapter.notifyDataSetChanged() |
| 620 | } | 623 | } |
| 621 | } | 624 | } |
| 622 | 625 | ||
| 623 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { | 626 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { |
| 624 | val itemView = viewHolder.itemView | 627 | val itemView = viewHolder.itemView |
| 625 | val iconMargin = (itemView.height - deleteIcon.intrinsicHeight) / 2 | 628 | val iconMargin = (itemView.height - deleteIcon.intrinsicHeight) / 2 |
| 626 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) | 629 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) |
| 627 | 630 | ||
| 628 | if (dX > 0) { | 631 | if (dX > 0) { |
| 629 | 632 | ||
| 630 | if (dX < c.width / 2) c.drawColor(Color.GREEN) | 633 | if (dX < c.width / 2) c.drawColor(Color.GREEN) |
| 631 | else c.drawColor(Color.RED) | 634 | else c.drawColor(Color.RED) |
| 632 | deleteIcon.setBounds(itemView.left + iconMargin, itemView.top + iconMargin, itemView.left + iconMargin + deleteIcon.intrinsicWidth, itemView.bottom - iconMargin) | 635 | deleteIcon.setBounds(itemView.left + iconMargin, itemView.top + iconMargin, itemView.left + iconMargin + deleteIcon.intrinsicWidth, itemView.bottom - iconMargin) |
| 633 | } else { | 636 | } else { |
| 634 | } | 637 | } |
| 635 | 638 | ||
| 636 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 639 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
| 637 | deleteIcon.draw(c) | 640 | deleteIcon.draw(c) |
| 638 | } | 641 | } |
| 639 | } | 642 | } |
| 640 | 643 | ||
| 641 | val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback) | 644 | val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback) |
| 642 | itemTouchHelper.attachToRecyclerView(rcInventarios) | 645 | itemTouchHelper.attachToRecyclerView(rcInventarios) |
| 643 | } | 646 | } |
| 644 | 647 | ||
| 645 | private fun ProdNoCont(): Int? { | 648 | private fun ProdNoCont(): Int? { |
| 646 | var mostrarStock = 0 | 649 | var mostrarStock = 0 |
| 647 | if (sharedPreferences.contains("cbMostrarStock")) if (sharedPreferences.getString("cbMostrarStock", "").toString() == "1") mostrarStock = 1 | 650 | if (sharedPreferences.contains("cbMostrarStock")) if (sharedPreferences.getString("cbMostrarStock", "").toString() == "1") mostrarStock = 1 |
| 648 | return mostrarStock | 651 | return mostrarStock |
| 649 | } | 652 | } |
| 650 | 653 | ||
| 651 | private fun AjusteProductos(): Int? { | 654 | private fun AjusteProductos(): Int? { |
| 652 | var prodInclu = 0 | 655 | var prodInclu = 0 |
| 653 | if (sharedPreferences.contains("rbProInclu")) if (sharedPreferences.getString("rbProInclu", "").toString() == "1") prodInclu = 1 | 656 | if (sharedPreferences.contains("rbProInclu")) if (sharedPreferences.getString("rbProInclu", "").toString() == "1") prodInclu = 1 |
| 654 | 657 | ||
| 655 | if (sharedPreferences.contains("rbProNoInclu")) if (sharedPreferences.getString("rbProNoInclu", "").toString() == "0") prodInclu = 0 | 658 | if (sharedPreferences.contains("rbProNoInclu")) if (sharedPreferences.getString("rbProNoInclu", "").toString() == "0") prodInclu = 0 |
| 656 | return prodInclu | 659 | return prodInclu |
| 657 | } | 660 | } |
| 658 | 661 | ||
| 659 | private fun SerchArea() { | 662 | private fun SerchArea() { |
| 660 | 663 | ||
| 661 | if (sharedPreferences.contains("rbVentas")) if (sharedPreferences.getString("rbVentas", "").toString() == "1") iArea = 0 | 664 | if (sharedPreferences.contains("rbVentas")) if (sharedPreferences.getString("rbVentas", "").toString() == "1") iArea = 0 |
| 662 | if (sharedPreferences.contains("rbDeposito")) if (sharedPreferences.getString("rbDeposito", "").toString() == "1") iArea = 1 | 665 | if (sharedPreferences.contains("rbDeposito")) if (sharedPreferences.getString("rbDeposito", "").toString() == "1") iArea = 1 |
| 663 | } | 666 | } |
| 664 | 667 | ||
| 665 | fun ObtenerFechaActual(): String? { | 668 | fun ObtenerFechaActual(): String? { |
| 666 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | 669 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD |
| 667 | val current = LocalDateTime.now() | 670 | val current = LocalDateTime.now() |
| 668 | val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss") | 671 | val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss") |
| 669 | val dFechaHora = current.format(formatter) | 672 | val dFechaHora = current.format(formatter) |
| 670 | return dFechaHora.toString() | 673 | return dFechaHora.toString() |
| 671 | } | 674 | } |
| 672 | 675 | ||
| 673 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { | 676 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { |
| 674 | lifecycleScope.launch { | 677 | lifecycleScope.launch { |
| 675 | withContext(Dispatchers.IO) { | 678 | withContext(Dispatchers.IO) { |
| 676 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) | 679 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) |
| 677 | } | 680 | } |
| 678 | } | 681 | } |
| 679 | } | 682 | } |
| 680 | 683 | ||
| 681 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { | 684 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { |
| 682 | lifecycleScope.launch { | 685 | lifecycleScope.launch { |
| 683 | withContext(Dispatchers.IO) { | 686 | withContext(Dispatchers.IO) { |
| 684 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.UpdateInvBody(cantidad, sector, codigo) | 687 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.UpdateInvBody(cantidad, sector, codigo) |
| 685 | } | 688 | } |
| 686 | } | 689 | } |
| 687 | } | 690 | } |
| 688 | 691 | ||
| 689 | suspend fun cargarInventario(inventario: Int): List<InvBody>? { | 692 | suspend fun cargarInventario(inventario: Int): List<InvBody>? { |
| 690 | return GlobalScope.async(Dispatchers.IO) { | 693 | return GlobalScope.async(Dispatchers.IO) { |
| 691 | return@async AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inventario) | 694 | return@async AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inventario) |
| 692 | }.await() | 695 | }.await() |
| 693 | } | 696 | } |
| 694 | 697 | ||
| 695 | override fun onImageDotsClick(sector: String?, codigo: String?) { | 698 | override fun onImageDotsClick(sector: String?, codigo: String?) { |
| 696 | val bundle = Bundle() | 699 | val bundle = Bundle() |
| 697 | bundle.putString("sector", sector) | 700 | bundle.putString("sector", sector) |
| 698 | bundle.putString("codigo", codigo) | 701 | bundle.putString("codigo", codigo) |
| 699 | bundle.putInt("numeroInv", InventarioNuevo) | 702 | bundle.putInt("numeroInv", InventarioNuevo) |
| 700 | navController.navigate(R.id.action_inventarioFragment_to_detalleArtFragment, bundle) | 703 | navController.navigate(R.id.action_inventarioFragment_to_detalleArtFragment, bundle) |
| 701 | } | 704 | } |
| 702 | 705 | ||
| 703 | override fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) { | 706 | override fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) { |
| 704 | 707 | ||
| 705 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 708 | val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
| 706 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[position.toInt()].descripcion}'.").setCancelable(false) | 709 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[position.toInt()].descripcion}'.").setCancelable(false) |
| 707 | mDialogView.tvCantInicial.text = cantidad | 710 | mDialogView.tvCantInicial.text = cantidad |
| 708 | val mAlertDialog = mBuilder.show() | 711 | val mAlertDialog = mBuilder.show() |
| 709 | mDialogView.rbSumar.setOnClickListener { | 712 | mDialogView.rbSumar.setOnClickListener { |
| 710 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 713 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 711 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 714 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 712 | } | 715 | } |
| 713 | } | 716 | } |
| 714 | mDialogView.rbRestar.setOnClickListener { | 717 | mDialogView.rbRestar.setOnClickListener { |
| 715 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 718 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 716 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 719 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
| 717 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 720 | mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 718 | } | 721 | } |
| 719 | } | 722 | } |
| 720 | } | 723 | } |
| 721 | mDialogView.rbMdodificar.setOnClickListener { | 724 | mDialogView.rbMdodificar.setOnClickListener { |
| 722 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 725 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
| 723 | mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 726 | mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
| 724 | } | 727 | } |
| 725 | } | 728 | } |
| 726 | mDialogView.btnAceptar.setOnClickListener { | 729 | mDialogView.btnAceptar.setOnClickListener { |
| 727 | mAlertDialog.dismiss() | 730 | mAlertDialog.dismiss() |
| 728 | val name = mDialogView.tvgenerico4.text.toString().toFloat() | 731 | val name = mDialogView.tvgenerico4.text.toString().toFloat() |
| 729 | fCant = 0F | 732 | fCant = 0F |
| 730 | fCant = name | 733 | fCant = name |
| 731 | listArticulos[position.toInt()].cantTomada = fCant | 734 | listArticulos[position.toInt()].cantTomada = fCant |
| 732 | updateCantidad(listArticulos[position.toInt()].sector.toString(), listArticulos[position.toInt()].codigo.toString(), fCant) | 735 | updateCantidad(listArticulos[position.toInt()].sector.toString(), listArticulos[position.toInt()].codigo.toString(), fCant) |
| 733 | viewAdapter.notifyDataSetChanged() | 736 | viewAdapter.notifyDataSetChanged() |
| 734 | } | 737 | } |
| 735 | mDialogView.dialogCancelBtn.setOnClickListener { | 738 | mDialogView.dialogCancelBtn.setOnClickListener { |
| 736 | mAlertDialog.dismiss() | 739 | mAlertDialog.dismiss() |
| 737 | } | 740 | } |
| 738 | } | 741 | } |
| 739 | 742 | ||
| 740 | } | 743 | } |
| 741 | 744 | ||
| 742 | 745 | ||
| 743 | 746 | ||
| 744 | 747 |