Commit d60eae7d0b1c4be1ca69d245878efacb0249cc9d
1 parent
c8fab9ae77
Exists in
master
21052020 0205
Showing
7 changed files
with
90 additions
and
76 deletions
Show diff stats
.idea/vcs.xml
File was created | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <project version="4"> | ||
3 | <component name="VcsDirectoryMappings"> | ||
4 | <mapping directory="$PROJECT_DIR$" vcs="Git" /> | ||
5 | </component> | ||
6 | </project> |
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.* | 3 | import androidx.room.* |
4 | import com.focasoftware.deboinventario.ui.actualizacionMaestros.Constans.Companion.TABLA_ART | 4 | import com.focasoftware.deboinventario.ui.actualizacionMaestros.Constans.Companion.TABLA_ART |
5 | import com.focasoftware.deboinventario.ui.actualizacionMaestros.Constans.Companion.TABLA_INV_B | 5 | import com.focasoftware.deboinventario.ui.actualizacionMaestros.Constans.Companion.TABLA_INV_B |
6 | import com.focasoftware.deboinventario.ui.actualizacionMaestros.Constans.Companion.TABLA_INV_H | 6 | import com.focasoftware.deboinventario.ui.actualizacionMaestros.Constans.Companion.TABLA_INV_H |
7 | import com.focasoftware.deboinventariov20.Model.* | 7 | import com.focasoftware.deboinventariov20.Model.* |
8 | 8 | ||
9 | @Dao | 9 | @Dao |
10 | interface ArticulosDAO { | 10 | interface ArticulosDAO { |
11 | 11 | ||
12 | // TABLA ARTICULOS | 12 | // TABLA ARTICULOS |
13 | @Insert(onConflict = OnConflictStrategy.REPLACE) | 13 | @Insert(onConflict = OnConflictStrategy.REPLACE) |
14 | suspend fun insertArticulos(articulos: Articles?) | 14 | suspend fun insertArticulos(articulos: Articles?) |
15 | 15 | ||
16 | @Query("SELECT * FROM $TABLA_ART ORDER BY DES DESC") | 16 | @Query("SELECT * FROM $TABLA_ART ORDER BY DES DESC") |
17 | suspend fun findAllArticulos(): List<Articles> | 17 | suspend fun findAllArticulos(): List<Articles> |
18 | 18 | ||
19 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND DES LIKE '%' || :description || '%'") | 19 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND DES LIKE '%' || :description || '%' GROUP BY DES ORDER BY SEC, COD") |
20 | suspend fun findArticuloByDesc(description: String?, dep: Int): List<Articles> | 20 | suspend fun findArticuloByDesc(description: String?, dep: Int): List<Articles> |
21 | 21 | ||
22 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND CB LIKE :codBarra") | 22 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND CB LIKE :codBarra") |
23 | suspend fun findArticuloByCodBar(codBarra: String?, dep: Int): Articles? | 23 | suspend fun findArticuloByCodBar(codBarra: String?, dep: Int): Articles? |
24 | 24 | ||
25 | @Query("DELETE FROM $TABLA_ART") | 25 | @Query("DELETE FROM $TABLA_ART") |
26 | suspend fun deleteAllArticulos() | 26 | suspend fun deleteAllArticulos() |
27 | } | 27 | } |
28 | 28 | ||
29 | @Dao | 29 | @Dao |
30 | interface InvHeadDAO { | 30 | interface InvHeadDAO { |
31 | @Insert() | 31 | @Insert() |
32 | suspend fun insertInvHead(invHead: InvHead?) | 32 | suspend fun insertInvHead(invHead: InvHead?) |
33 | 33 | ||
34 | @Query("SELECT INV_NUM FROM $TABLA_INV_H ORDER BY INV_NUM DESC") | 34 | @Query("SELECT INV_NUM FROM $TABLA_INV_H ORDER BY INV_NUM DESC") |
35 | suspend fun findLastInv(): Int | 35 | suspend fun findLastInv(): Int |
36 | 36 | ||
37 | @Query("DELETE FROM $TABLA_INV_H") | 37 | @Query("DELETE FROM $TABLA_INV_H") |
38 | suspend fun deleteAllArticulos() | 38 | suspend fun deleteAllArticulos() |
39 | 39 | ||
40 | @Query("DELETE FROM $TABLA_INV_H WHERE INV_NUM=:inven") | 40 | @Query("DELETE FROM $TABLA_INV_H WHERE INV_NUM=:inven") |
41 | suspend fun deleteinvHead(inven: Int) | 41 | suspend fun deleteinvHead(inven: Int) |
42 | 42 | ||
43 | @Query("SELECT * FROM $TABLA_INV_H ORDER BY INV_FEI") | 43 | @Query("SELECT * FROM $TABLA_INV_H ORDER BY INV_FEI") |
44 | suspend fun fetchAllInvHead(): List<InvHead> | 44 | suspend fun fetchAllInvHead(): List<InvHead> |
45 | } | 45 | } |
46 | 46 | ||
47 | @Dao | 47 | @Dao |
48 | interface InvBodyDAO { | 48 | interface InvBodyDAO { |
49 | @Insert() | 49 | @Insert() |
50 | suspend fun insertInvBody(invBody: InvBody?) | 50 | suspend fun insertInvBody(invBody: InvBody?) |
51 | 51 | ||
52 | @Query("DELETE FROM $TABLA_INV_B") | 52 | @Query("DELETE FROM $TABLA_INV_B") |
53 | suspend fun deleteAllInvBody() | 53 | suspend fun deleteAllInvBody() |
54 | 54 | ||
55 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:inven") | 55 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:inven") |
56 | suspend fun deleteInvBody(inven: Int) | 56 | suspend fun deleteInvBody(inven: Int) |
57 | 57 | ||
58 | @Query("UPDATE $TABLA_INV_B SET CANT=:cant WHERE SEC=:sec AND COD=:cod") | 58 | @Query("UPDATE $TABLA_INV_B SET CANT=:cant WHERE SEC=:sec AND COD=:cod") |
59 | suspend fun UpdateInvBody(cant: Float, sec: String, cod: String) | 59 | suspend fun UpdateInvBody(cant: Float, sec: String, cod: String) |
60 | 60 | ||
61 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:inven ORDER BY INV_FEI DESC") | 61 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:inven ORDER BY INV_FEI DESC") |
62 | suspend fun fetchAllInvBody(inven:Int): List<InvBody> | 62 | suspend fun fetchAllInvBody(inven:Int): List<InvBody> |
63 | } | 63 | } |
64 | @Dao | 64 | @Dao |
65 | interface ServeInvDao { | 65 | interface ServeInvDao { |
66 | @Insert(onConflict = OnConflictStrategy.REPLACE) | 66 | @Insert(onConflict = OnConflictStrategy.REPLACE) |
67 | fun insertServer(servidor: ServeInv) | 67 | fun insertServer(servidor: ServeInv) |
68 | 68 | ||
69 | @Query("SELECT SER_NUM,SER_DESC, SER_DIR FROM ServeInv") | 69 | @Query("SELECT SER_NUM,SER_DESC, SER_DIR FROM ServeInv") |
70 | suspend fun findAllServers(): List<ServeInv> | 70 | suspend fun findAllServers(): List<ServeInv> |
71 | } | 71 | } |
app/src/main/java/com/focasoftware/deboinventariov20/ui/inventario/DescripcionFragment.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.content.SharedPreferences | 4 | import android.content.SharedPreferences |
5 | import android.graphics.Canvas | 5 | import android.graphics.Canvas |
6 | import android.graphics.Color | 6 | import android.graphics.Color |
7 | import android.graphics.drawable.ColorDrawable | 7 | import android.graphics.drawable.ColorDrawable |
8 | import android.os.Bundle | 8 | import android.os.Bundle |
9 | import android.view.LayoutInflater | 9 | import android.view.LayoutInflater |
10 | import android.view.View | 10 | import android.view.View |
11 | import android.view.ViewGroup | 11 | import android.view.ViewGroup |
12 | import android.widget.Button | 12 | import android.widget.Button |
13 | import androidx.fragment.app.Fragment | 13 | import androidx.fragment.app.Fragment |
14 | import androidx.lifecycle.lifecycleScope | 14 | import androidx.lifecycle.lifecycleScope |
15 | import androidx.navigation.NavController | 15 | import androidx.navigation.NavController |
16 | import androidx.navigation.Navigation | 16 | import androidx.navigation.Navigation |
17 | import androidx.recyclerview.widget.ItemTouchHelper | 17 | import androidx.recyclerview.widget.ItemTouchHelper |
18 | import androidx.recyclerview.widget.LinearLayoutManager | 18 | import androidx.recyclerview.widget.LinearLayoutManager |
19 | import androidx.recyclerview.widget.RecyclerView | 19 | import androidx.recyclerview.widget.RecyclerView |
20 | import com.afollestad.materialdialogs.MaterialDialog | 20 | import com.afollestad.materialdialogs.MaterialDialog |
21 | import com.afollestad.materialdialogs.input.input | 21 | import com.afollestad.materialdialogs.input.input |
22 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 22 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
23 | import com.focasoftware.deboinventariov20.Model.Articles | 23 | import com.focasoftware.deboinventariov20.Model.Articles |
24 | import com.focasoftware.deboinventariov20.Model.InvBody | 24 | import com.focasoftware.deboinventariov20.Model.InvBody |
25 | import com.focasoftware.deboinventariov20.R | 25 | import com.focasoftware.deboinventariov20.R |
26 | import kotlinx.coroutines.Dispatchers | 26 | import kotlinx.coroutines.Dispatchers |
27 | import kotlinx.coroutines.launch | 27 | import kotlinx.coroutines.launch |
28 | import kotlinx.coroutines.withContext | 28 | import kotlinx.coroutines.withContext |
29 | 29 | ||
30 | class DescripcionFragment : Fragment() { | 30 | class DescripcionFragment : Fragment() { |
31 | private var artAcargar2: List<Articles>? = null | 31 | private var artAcargar2: List<Articles>? = null |
32 | private var listArticulos2: List<Articles>? = null | 32 | private var listArticulos2: List<Articles>? = null |
33 | lateinit var viewAdapter2: RecyclerView.Adapter<*> | 33 | lateinit var viewAdapter2: RecyclerView.Adapter<*> |
34 | private lateinit var viewManager2: RecyclerView.LayoutManager | 34 | private lateinit var viewManager2: RecyclerView.LayoutManager |
35 | private lateinit var rcDescripcion: RecyclerView | 35 | private lateinit var rcDescripcion: RecyclerView |
36 | private var swipeBackground: ColorDrawable = ColorDrawable(Color.YELLOW) | 36 | private var swipeBackground: ColorDrawable = ColorDrawable(Color.YELLOW) |
37 | private var cantidad = 0F | 37 | private var cantidad = 0F |
38 | private var numeroInventario = 0 | 38 | private var numeroInventario = 0 |
39 | lateinit var navController: NavController | 39 | lateinit var navController: NavController |
40 | lateinit var sharedPreferences: SharedPreferences | 40 | lateinit var sharedPreferences: SharedPreferences |
41 | 41 | ||
42 | override fun onCreate(savedInstanceState: Bundle?) { | 42 | override fun onCreate(savedInstanceState: Bundle?) { |
43 | super.onCreate(savedInstanceState) | 43 | super.onCreate(savedInstanceState) |
44 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 44 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
45 | arguments.apply { | 45 | arguments.apply { |
46 | artAcargar2 = requireArguments().getSerializable("ArrayDesc") as List<Articles> | 46 | artAcargar2 = requireArguments().getSerializable("ArrayDesc") as List<Articles> |
47 | numeroInventario = requireArguments().getInt("numeroInv") | 47 | numeroInventario = requireArguments().getInt("numeroInv") |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 51 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
52 | super.onViewCreated(view, savedInstanceState) | 52 | super.onViewCreated(view, savedInstanceState) |
53 | navController = Navigation.findNavController(view) | 53 | navController = Navigation.findNavController(view) |
54 | } | 54 | } |
55 | 55 | ||
56 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 56 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
57 | // Inflate the layout for this fragment | 57 | // Inflate the layout for this fragment |
58 | val v = inflater.inflate(R.layout.fragment_descripcion, container, false) | 58 | val v = inflater.inflate(R.layout.fragment_descripcion, container, false) |
59 | rcDescripcion = v.findViewById(R.id.rcDescripcion) | 59 | rcDescripcion = v.findViewById(R.id.rcDescripcion) |
60 | val btnSalir = v.findViewById<Button>(R.id.btnSalir) | 60 | val btnSalir = v.findViewById<Button>(R.id.btnSalir) |
61 | 61 | ||
62 | IngresarRecicler(artAcargar2) | 62 | IngresarRecicler(artAcargar2) |
63 | 63 | ||
64 | btnSalir.setOnClickListener { | 64 | btnSalir.setOnClickListener { |
65 | requireActivity().onBackPressed() | 65 | VolverAinventario() |
66 | } | 66 | } |
67 | return v | 67 | return v |
68 | } | 68 | } |
69 | 69 | ||
70 | fun IngresarRecicler(articulos: List<Articles>?) { | 70 | fun IngresarRecicler(articulos: List<Articles>?) { |
71 | 71 | ||
72 | viewAdapter2 = DescripcionListAdapter(articulos) | 72 | viewAdapter2 = DescripcionListAdapter(articulos) |
73 | viewManager2 = LinearLayoutManager(requireContext()) | 73 | viewManager2 = LinearLayoutManager(requireContext()) |
74 | 74 | ||
75 | rcDescripcion.apply { | 75 | rcDescripcion.apply { |
76 | adapter = viewAdapter2 | 76 | adapter = viewAdapter2 |
77 | layoutManager = viewManager2 | 77 | layoutManager = viewManager2 |
78 | } | 78 | } |
79 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) { | 79 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) { |
80 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { | 80 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { |
81 | return false | 81 | return false |
82 | } | 82 | } |
83 | 83 | ||
84 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, position: Int) { | 84 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, position: Int) { |
85 | MaterialDialog(requireContext()).show { | 85 | MaterialDialog(requireContext()).show { |
86 | title(R.string.sTitulo) | 86 | title(R.string.sTitulo) |
87 | message(R.string.sMensajeEncontrado) | 87 | message(R.string.sMensajeEncontrado) |
88 | input { materialDialog, charSequence -> | 88 | input { materialDialog, charSequence -> |
89 | cantidad = 0F | 89 | cantidad = 0F |
90 | cantidad = charSequence.toString().toFloat() | 90 | cantidad = charSequence.toString().toFloat() |
91 | } | 91 | } |
92 | // .input("Cantidad",1,,1,0,InputType.TYPE_CLASS_NUMBER,0,waitForPositiveButton = true,false,positiveButton ()) | 92 | // .input("Cantidad",1,,1,0,InputType.TYPE_CLASS_NUMBER,0,waitForPositiveButton = true,false,positiveButton ()) |
93 | positiveButton(R.string.btnOk) { | 93 | positiveButton(R.string.btnOk) { |
94 | dismiss() | 94 | dismiss() |
95 | var indice = 0 | 95 | var indice = 0 |
96 | indice=viewHolder.layoutPosition | 96 | indice=viewHolder.layoutPosition |
97 | 97 | ||
98 | val body = InvBody(numeroInventario, | 98 | val body = InvBody(numeroInventario, |
99 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.sector, | 99 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.sector, |
100 | // TODO PREPARO PARA MANDAR A CARGAR EN LA BD | 100 | // TODO PREPARO PARA MANDAR A CARGAR EN LA BD |
101 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.codigo, | 101 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.codigo, |
102 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.descripcion, | 102 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.descripcion, |
103 | cantidad.toString(), | 103 | cantidad.toString(), |
104 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.codBar, | 104 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.codBar, |
105 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.codOrigen, | 105 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.codOrigen, |
106 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.precio, | 106 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.precio, |
107 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.precio, | 107 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.precio, |
108 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.balanza, | 108 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.balanza, |
109 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.depSn, | 109 | (viewAdapter2 as DescripcionListAdapter).items2?.get(indice)!!.depSn, |
110 | InventarioFragment().ObtenerFechaActual(), | 110 | InventarioFragment().ObtenerFechaActual(), |
111 | InventarioFragment().ObtenerFechaActual()) | 111 | InventarioFragment().ObtenerFechaActual()) |
112 | InsertarArtEnDB(body)// TODO: MANDO A CARGAR A LA BASE DE DATOS | 112 | InsertarArtEnDB(body)// TODO: MANDO A CARGAR A LA BASE DE DATOS |
113 | val editor = sharedPreferences.edit() | 113 | VolverAinventario() |
114 | editor?.putString("Inventario", numeroInventario.toString()) | ||
115 | editor?.apply() | ||
116 | editor.commit() | ||
117 | navController.navigate(R.id.action_descripcionFragment_to_inventarioFragment) | ||
118 | } | 114 | } |
119 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 115 | }.cancelOnTouchOutside(false).cornerRadius(10F) |
120 | } | 116 | } |
121 | 117 | ||
122 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { | 118 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { |
123 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 119 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
124 | val itemView = viewHolder.itemView | 120 | val itemView = viewHolder.itemView |
125 | 121 | ||
126 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) | 122 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) |
127 | 123 | ||
128 | if (dX > 0) { | 124 | if (dX > 0) { |
129 | 125 | ||
130 | c.drawColor(Color.RED) | 126 | c.drawColor(Color.RED) |
131 | } else if (dX < 0) { | 127 | } else if (dX < 0) { |
132 | // swipeBackground.setBounds(itemView.right+dX.toInt(),itemView.top,itemView.right,itemView.bottom) | 128 | // swipeBackground.setBounds(itemView.right+dX.toInt(),itemView.top,itemView.right,itemView.bottom) |
133 | c.drawColor(Color.YELLOW) | 129 | c.drawColor(Color.YELLOW) |
134 | } | 130 | } |
135 | swipeBackground.draw(c) | 131 | swipeBackground.draw(c) |
136 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 132 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
137 | } | 133 | } |
138 | } | 134 | } |
139 | val itemTouchHelper2 = ItemTouchHelper(itemTouchHelperCallback) | 135 | val itemTouchHelper2 = ItemTouchHelper(itemTouchHelperCallback) |
140 | itemTouchHelper2.attachToRecyclerView(rcDescripcion) | 136 | itemTouchHelper2.attachToRecyclerView(rcDescripcion) |
141 | 137 | ||
142 | } | 138 | } |
143 | 139 | ||
144 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { | 140 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { |
145 | lifecycleScope.launch { | 141 | lifecycleScope.launch { |
146 | withContext(Dispatchers.IO) { | 142 | withContext(Dispatchers.IO) { |
147 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) | 143 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) |
148 | } | 144 | } |
149 | } | 145 | } |
150 | } | 146 | } |
147 | fun VolverAinventario(){ | ||
148 | |||
149 | val editor = sharedPreferences.edit() | ||
150 | editor?.putString("Inventario", numeroInventario.toString()) | ||
151 | editor?.apply() | ||
152 | editor.commit() | ||
153 | navController.navigate(R.id.action_descripcionFragment_to_inventarioFragment) |
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.content.Context | 3 | import android.content.Context |
4 | import android.content.SharedPreferences | 4 | import android.content.SharedPreferences |
5 | import android.graphics.Canvas | 5 | import android.graphics.Canvas |
6 | import android.graphics.Color | 6 | import android.graphics.Color |
7 | import android.graphics.drawable.Drawable | 7 | import android.graphics.drawable.Drawable |
8 | import android.os.Bundle | 8 | import android.os.Bundle |
9 | import android.view.KeyEvent | 9 | import android.view.KeyEvent |
10 | import android.view.LayoutInflater | 10 | import android.view.LayoutInflater |
11 | import android.view.View | 11 | import android.view.View |
12 | import android.view.ViewGroup | 12 | import android.view.ViewGroup |
13 | import android.widget.* | 13 | import android.widget.EditText |
14 | import android.widget.TextView | ||
15 | import android.widget.Toast | ||
16 | import android.widget.ToggleButton | ||
14 | import androidx.core.content.ContextCompat | 17 | import androidx.core.content.ContextCompat |
15 | import androidx.core.os.bundleOf | 18 | import androidx.core.os.bundleOf |
16 | import androidx.fragment.app.Fragment | 19 | import androidx.fragment.app.Fragment |
17 | import androidx.lifecycle.lifecycleScope | 20 | import androidx.lifecycle.lifecycleScope |
18 | import androidx.navigation.NavController | 21 | import androidx.navigation.NavController |
19 | import androidx.navigation.Navigation | 22 | import androidx.navigation.Navigation |
20 | import androidx.recyclerview.widget.ItemTouchHelper | 23 | import androidx.recyclerview.widget.ItemTouchHelper |
21 | import androidx.recyclerview.widget.LinearLayoutManager | 24 | import androidx.recyclerview.widget.LinearLayoutManager |
22 | import androidx.recyclerview.widget.RecyclerView | 25 | import androidx.recyclerview.widget.RecyclerView |
23 | import com.afollestad.materialdialogs.MaterialDialog | 26 | import com.afollestad.materialdialogs.MaterialDialog |
24 | import com.afollestad.materialdialogs.input.input | 27 | import com.afollestad.materialdialogs.input.input |
25 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 28 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
26 | import com.focasoftware.deboinventariov20.Model.Articles | 29 | import com.focasoftware.deboinventariov20.Model.Articles |
27 | import com.focasoftware.deboinventariov20.Model.InvBody | 30 | import com.focasoftware.deboinventariov20.Model.InvBody |
28 | import com.focasoftware.deboinventariov20.Model.InvHead | 31 | import com.focasoftware.deboinventariov20.Model.InvHead |
29 | import com.focasoftware.deboinventariov20.R | 32 | import com.focasoftware.deboinventariov20.R |
30 | import kotlinx.android.synthetic.main.fragment_inventario.* | 33 | import kotlinx.android.synthetic.main.fragment_inventario.* |
31 | import kotlinx.coroutines.* | 34 | import kotlinx.coroutines.* |
32 | import java.time.LocalDateTime | 35 | import java.time.LocalDateTime |
33 | import java.time.format.DateTimeFormatter | 36 | import java.time.format.DateTimeFormatter |
34 | import java.util.* | 37 | import java.util.* |
35 | 38 | ||
36 | 39 | ||
37 | class InventarioFragment : Fragment() { | 40 | class InventarioFragment : Fragment() { |
38 | 41 | ||
39 | private lateinit var sharedPreferences: SharedPreferences | 42 | private lateinit var sharedPreferences: SharedPreferences |
40 | private var iArea: Int = 0 | 43 | private var iArea: Int = 0 |
41 | private lateinit var invHead: InvHead | 44 | private lateinit var invHead: InvHead |
42 | private lateinit var rcInventarios: RecyclerView | 45 | private lateinit var rcInventarios: RecyclerView |
43 | lateinit var viewAdapter: RecyclerView.Adapter<*> | 46 | lateinit var viewAdapter: RecyclerView.Adapter<*> |
44 | private lateinit var viewManager: RecyclerView.LayoutManager | 47 | private lateinit var viewManager: RecyclerView.LayoutManager |
45 | private lateinit var sChangeUpper: String | 48 | private lateinit var sChangeUpper: String |
46 | private var listArticulos = ArrayList<ItemsRecycler>() | 49 | private var listArticulos = ArrayList<ItemsRecycler>() |
47 | lateinit var navController: NavController | 50 | lateinit var navController: NavController |
48 | var InventarioNuevo: Int = 0 | 51 | var InventarioNuevo: Int = 0 |
49 | var fCant = 0F | 52 | var fCant = 0F |
50 | private lateinit var deleteIcon: Drawable | 53 | private lateinit var deleteIcon: Drawable |
51 | // private var editTT: EditText? = null | 54 | // private var editTT: EditText? = null |
52 | // private var dialogoModificacion: DialogPersoComplexCantidadModificacion? = null | 55 | // private var dialogoModificacion: DialogPersoComplexCantidadModificacion? = null |
53 | 56 | ||
54 | override fun onCreate(savedInstanceState: Bundle?) { | 57 | override fun onCreate(savedInstanceState: Bundle?) { |
55 | super.onCreate(savedInstanceState) | 58 | super.onCreate(savedInstanceState) |
56 | 59 | ||
57 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 60 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
58 | if (sharedPreferences.contains("Inventario")) if (sharedPreferences.getString("Inventario", "").toString() != "-1") { | 61 | if (sharedPreferences.contains("Inventario")) if (sharedPreferences.getString("Inventario", "").toString() != "-1") { |
59 | InventarioNuevo = sharedPreferences.getString("Inventario", "").toString().toInt() | 62 | InventarioNuevo = sharedPreferences.getString("Inventario", "").toString().toInt() |
60 | val editor = sharedPreferences.edit() | 63 | val editor = sharedPreferences.edit() |
61 | editor?.putString("Inventario", "-1") | 64 | editor?.putString("Inventario", "-1") |
62 | editor?.apply() | 65 | editor?.apply() |
63 | editor.commit() | 66 | editor.commit() |
64 | } | 67 | } |
65 | } | 68 | } |
66 | 69 | ||
67 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 70 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
68 | val v = inflater.inflate(R.layout.fragment_inventario, container, false) | 71 | val v = inflater.inflate(R.layout.fragment_inventario, container, false) |
69 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 72 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
70 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) | 73 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) |
71 | rcInventarios = v.findViewById(R.id.rcInventarios) | 74 | rcInventarios = v.findViewById(R.id.rcInventarios) |
72 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) | 75 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) |
73 | val toggleButton = v.findViewById<ToggleButton>(R.id.toggleButton) | 76 | val toggleButton = v.findViewById<ToggleButton>(R.id.toggleButton) |
74 | 77 | ||
75 | 78 | ||
76 | if (InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO | 79 | if (InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO |
77 | GlobalScope.launch(Dispatchers.Main) { | 80 | GlobalScope.launch(Dispatchers.Main) { |
78 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO | 81 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO |
79 | InventarioNuevo = AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.findLastInv() + 1 | 82 | InventarioNuevo = AppDb.getAppDb(requireActivity())?.InvHeadDAO()?.findLastInv()?.plus(1) ?: 1 |
80 | SerchArea() | 83 | SerchArea() |
81 | val descripInv: String = if (iArea == 0) "Inventario Ventas" else "Inventario Deposito" | 84 | val descripInv: String = if (iArea == 0) "Ventas" else "Deposito" |
82 | //TODO: CREAMOS EL INVENTARIO EN LA CABECERA DEL INVENTARIO | 85 | //TODO: CREAMOS EL INVENTARIO EN LA CABECERA DEL INVENTARIO |
83 | invHead = InvHead(InventarioNuevo, descripInv, 1, ObtenerFechaActual(), ObtenerFechaActual(), 0L, iArea, AjusteProductos(), ProdNoCont()) | 86 | invHead = InvHead(InventarioNuevo, descripInv, 1, ObtenerFechaActual(), ObtenerFechaActual(), 0L, iArea, AjusteProductos(), ProdNoCont()) |
84 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.insertInvHead(invHead) | 87 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.insertInvHead(invHead) |
85 | tvTitulo.text = "Inventario Dinamico" + " Nยฐ $InventarioNuevo" | 88 | tvTitulo.text = "Inventario Dinamico" + " Nยฐ $InventarioNuevo" |
86 | } | 89 | } |
87 | } else {// TODO: SI VENGO DE FRAGMENT DESCRIPCION | 90 | } else {// TODO: SI VENGO DE FRAGMENT DESCRIPCION |
88 | CargarDeBdInventario(InventarioNuevo) | 91 | CargarDeBdInventario(InventarioNuevo) |
89 | tvTitulo.text = "Inventario Dinamico" + " Nยฐ $InventarioNuevo" | 92 | tvTitulo.text = "Inventario Dinamico" + " Nยฐ $InventarioNuevo" |
90 | } | 93 | } |
91 | 94 | ||
92 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> | 95 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> |
93 | if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_UP) { | 96 | if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_UP) { |
94 | sChangeUpper = tCodigoBarras.text.toString() | 97 | sChangeUpper = tCodigoBarras.text.toString() |
95 | 98 | ||
96 | var indiceDelArtEncontrado = 0 | 99 | var indiceDelArtEncontrado = 0 |
97 | 100 | ||
98 | //TODO COMIENZA LA BUSQUEDA POR CODIGO DE BARRAS | 101 | //TODO COMIENZA LA BUSQUEDA POR CODIGO DE BARRAS |
99 | if (toggleButton.isChecked) { | 102 | if (toggleButton.isChecked) { |
100 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 0)//TODO Si encuentra el articulo en el RV devuelve el indice | 103 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 0)//TODO Si encuentra el articulo en el RV devuelve el indice |
101 | //TODO Si no lo encuentra devuelve -1 | 104 | //TODO Si no lo encuentra devuelve -1 |
102 | if (indiceDelArtEncontrado != -1) { | 105 | if (indiceDelArtEncontrado != -1) { |
103 | if (swSumaUno!!.isChecked) { | 106 | if (swSumaUno!!.isChecked) { |
104 | fCant = 0F | 107 | fCant = 0F |
105 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 108 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
106 | fCant += 1F | 109 | fCant += 1F |
107 | //TODO ACTUALIZO LA CANTIDAD EN LA BD | 110 | //TODO ACTUALIZO LA CANTIDAD EN LA BD |
108 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 111 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
109 | //TODO ACTUALIZO LA CANTIDAD EN EL RV | 112 | //TODO ACTUALIZO LA CANTIDAD EN EL RV |
110 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 113 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
111 | viewAdapter.notifyDataSetChanged() | 114 | viewAdapter.notifyDataSetChanged() |
112 | } else { | 115 | } else { |
113 | // val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 116 | // val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
114 | // val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setTitle("Login Form").setCancelable(false) | 117 | // val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setTitle("Login Form").setCancelable(false) |
115 | // val mAlertDialog = mBuilder.show() | 118 | // val mAlertDialog = mBuilder.show() |
116 | // mDialogView.dialogLoginBtn.setOnClickListener { | 119 | // mDialogView.dialogLoginBtn.setOnClickListener { |
117 | // mAlertDialog.dismiss() | 120 | // mAlertDialog.dismiss() |
118 | // //get text from EditTexts of custom layout | 121 | // //get text from EditTexts of custom layout |
119 | // val name = mDialogView.dialogNameEt.text.toString() | 122 | // val name = mDialogView.dialogNameEt.text.toString() |
120 | // val email = mDialogView.dialogEmailEt.text.toString() | 123 | // val email = mDialogView.dialogEmailEt.text.toString() |
121 | // val password = mDialogView.dialogPasswEt.text.toString() | 124 | // val password = mDialogView.dialogPasswEt.text.toString() |
122 | // fCant = 0F | 125 | // fCant = 0F |
123 | // fCant = name.toFloat() | 126 | // fCant = name.toFloat() |
124 | // } | 127 | // } |
125 | // mDialogView.dialogCancelBtn.setOnClickListener { | 128 | // mDialogView.dialogCancelBtn.setOnClickListener { |
126 | // mAlertDialog.dismiss() | 129 | // mAlertDialog.dismiss() |
127 | // } | 130 | // } |
128 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 131 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
129 | MaterialDialog(requireContext()).show { | 132 | MaterialDialog(requireContext()).show { |
130 | title(R.string.sTituloNueva) | 133 | title(R.string.sTituloNueva) |
131 | message(R.string.sCantidadNueva) | 134 | message(R.string.sCantidadNueva) |
132 | input { materialDialog, charSequence -> | 135 | input { materialDialog, charSequence -> |
133 | fCant = 0F | 136 | fCant = 0F |
134 | fCant = charSequence.toString().toFloat() | 137 | fCant = charSequence.toString().toFloat() |
135 | } | 138 | } |
136 | positiveButton(R.string.btnOk) { | 139 | positiveButton(R.string.btnOk) { |
137 | //TODO ACTUALIZO CANTIADAD EN BD | 140 | //TODO ACTUALIZO CANTIADAD EN BD |
138 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 141 | updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
139 | //TODO ACTUALIZO CANTIDAD EN RV | 142 | //TODO ACTUALIZO CANTIDAD EN RV |
140 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 143 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
141 | viewAdapter.notifyDataSetChanged() | 144 | viewAdapter.notifyDataSetChanged() |
142 | dismiss() | 145 | dismiss() |
143 | } | 146 | } |
144 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 147 | }.cancelOnTouchOutside(false).cornerRadius(10F) |
145 | } | 148 | } |
146 | 149 | ||
147 | } else if (indiceDelArtEncontrado == -1) {// no lo encontro en el RV, lo va a buscar en al BD | 150 | } else if (indiceDelArtEncontrado == -1) {// no lo encontro en el RV, lo va a buscar en al BD |
148 | 151 | ||
149 | GlobalScope.launch(Dispatchers.Main) { | 152 | GlobalScope.launch(Dispatchers.Main) { |
150 | //TODO BUSCO EN BASE DE DATOS | 153 | //TODO BUSCO EN BASE DE DATOS |
151 | val artEncontrado = buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 154 | val artEncontrado = buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
152 | ContinuarCargaCB(artEncontrado) | 155 | ContinuarCargaCB(artEncontrado) |
153 | } | 156 | } |
154 | } | 157 | } |
155 | 158 | ||
156 | tCodigoBarras.focusable = View.FOCUSABLE | 159 | tCodigoBarras.focusable = View.FOCUSABLE |
157 | tCodigoBarras.setText("") | 160 | tCodigoBarras.setText("") |
158 | tCodigoBarras.selectAll() | 161 | tCodigoBarras.selectAll() |
159 | return@setOnKeyListener true | 162 | return@setOnKeyListener true |
160 | 163 | ||
161 | 164 | ||
162 | } else {//TODO BUSQUEDA POR DESCRIPCION************************************************************************** | 165 | } else {//TODO: BUSQUEDA POR DESCRIPCION************************************************************************** |
163 | 166 | // | |
164 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 1) //TODO :Si encuentra el articulo en el RV devuelve el indice | 167 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 1) //TODO :Si encuentra el articulo en el RV devuelve el indice |
165 | //TODO Si no lo encuentra devuelve -1 | 168 | // //TODO Si no lo encuentra devuelve -1 |
166 | if (indiceDelArtEncontrado != -1) { | 169 | // if (indiceDelArtEncontrado != -1) { |
167 | // if (swSumaUno!!.isChecked) { | 170 | //// if (swSumaUno!!.isChecked) { |
168 | // fCant = 0F | 171 | //// fCant = 0F |
169 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 172 | //// fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
170 | // fCant += 1F | 173 | //// fCant += 1F |
171 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 174 | //// listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
172 | // viewAdapter.notifyDataSetChanged() | 175 | //// viewAdapter.notifyDataSetChanged() |
173 | // } else { | 176 | //// } else { |
174 | fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 177 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
175 | MaterialDialog(requireContext()).show { | 178 | // MaterialDialog(requireContext()).show { |
176 | title(R.string.sTituloNueva) | 179 | // title(R.string.sTituloNueva) |
177 | message(R.string.sCantidadNueva) | 180 | // message(R.string.sCantidadNueva) |
178 | input { materialDialog, charSequence -> | 181 | // input { materialDialog, charSequence -> |
179 | fCant = 0F | 182 | // fCant = 0F |
180 | fCant = charSequence.toString().toFloat() | 183 | // fCant = charSequence.toString().toFloat() |
181 | } | 184 | // } |
182 | positiveButton(R.string.btnOk) { | 185 | // positiveButton(R.string.btnOk) { |
183 | listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 186 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
184 | viewAdapter.notifyDataSetChanged() | 187 | // viewAdapter.notifyDataSetChanged() |
185 | dismiss() | 188 | // dismiss() |
186 | } | 189 | // } |
187 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 190 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
188 | // } | 191 | //// } |
189 | 192 | // | |
190 | } else if (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD | 193 | // } else if |
194 | // (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD | ||
191 | GlobalScope.launch(Dispatchers.Main) { | 195 | GlobalScope.launch(Dispatchers.Main) { |
192 | val artEncontrado = buscarDescEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 196 | val artEncontrado = buscarDescEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
193 | ContinuarCargaDesc(artEncontrado as ArrayList<Articles>) | 197 | ContinuarCargaDesc(artEncontrado as ArrayList<Articles>) |
194 | } | 198 | } |
195 | } | 199 | // } |
196 | tCodigoBarras.focusable = View.FOCUSABLE | 200 | tCodigoBarras.focusable = View.FOCUSABLE |
197 | tCodigoBarras.setText("") | 201 | tCodigoBarras.setText("") |
198 | tCodigoBarras.selectAll() | 202 | tCodigoBarras.selectAll() |
199 | return@setOnKeyListener true | 203 | return@setOnKeyListener true |
200 | } | 204 | } |
201 | } | 205 | } |
202 | return@setOnKeyListener false | 206 | return@setOnKeyListener false |
203 | } | 207 | } |
204 | return v | 208 | return v |
205 | } | 209 | } |
206 | 210 | ||
207 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 211 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
208 | super.onViewCreated(view, savedInstanceState) | 212 | super.onViewCreated(view, savedInstanceState) |
209 | navController = Navigation.findNavController(view) | 213 | navController = Navigation.findNavController(view) |
210 | etCodigoBarras.requestFocus() | 214 | etCodigoBarras.requestFocus() |
211 | 215 | ||
212 | btnBorrarInv.setOnClickListener { | 216 | btnBorrarInv.setOnClickListener { |
213 | MaterialDialog(requireContext()).show { | 217 | MaterialDialog(requireContext()).show { |
214 | title(R.string.sTituloBorrarInv) | 218 | title(R.string.sTituloBorrarInv) |
215 | message(R.string.sMensajeBorrarInv) | 219 | message(R.string.sMensajeBorrarInv) |
216 | positiveButton(R.string.btnOk) { | 220 | positiveButton(R.string.btnOk) { |
217 | BorrarInvActual() | 221 | BorrarInvActual() |
218 | Toast.makeText(requireContext(), "El inventario $InventarioNuevo fue Borrado", Toast.LENGTH_LONG).show() | 222 | Toast.makeText(requireContext(), "El inventario $InventarioNuevo fue Borrado", Toast.LENGTH_LONG).show() |
219 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) | 223 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
220 | InventarioNuevo = 0 | 224 | InventarioNuevo = 0 |
221 | dismiss() | 225 | dismiss() |
222 | } | 226 | } |
223 | negativeButton { | 227 | negativeButton { |
224 | dismiss() | 228 | dismiss() |
225 | } | 229 | } |
226 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 230 | }.cancelOnTouchOutside(false).cornerRadius(10F) |
227 | } | 231 | } |
228 | 232 | ||
229 | btnExportarInv.setOnClickListener { | 233 | btnExportarInv.setOnClickListener { |
230 | MaterialDialog(requireContext()).show { | 234 | MaterialDialog(requireContext()).show { |
231 | title(R.string.sTituloExportar) | 235 | title(R.string.sTituloExportar) |
232 | message(R.string.sMensajeExportar) | 236 | message(R.string.sMensajeExportar) |
233 | positiveButton(R.string.btnOk) { | 237 | positiveButton(R.string.btnOk) { |
234 | BorrarInvActual() | 238 | BorrarInvActual() |
235 | Toast.makeText(requireContext(), "El inventario $InventarioNuevo fue Exportado al Servidor", Toast.LENGTH_LONG).show() | 239 | Toast.makeText(requireContext(), "El inventario $InventarioNuevo fue Exportado al Servidor", Toast.LENGTH_LONG).show() |
236 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) | 240 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
237 | InventarioNuevo = 0 | 241 | InventarioNuevo = 0 |
238 | dismiss() | 242 | dismiss() |
239 | } | 243 | } |
240 | negativeButton { | 244 | negativeButton { |
241 | dismiss() | 245 | dismiss() |
242 | } | 246 | } |
243 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 247 | }.cancelOnTouchOutside(false).cornerRadius(10F) |
244 | } | 248 | } |
245 | } | 249 | } |
246 | 250 | ||
247 | private fun BorrarInvActual() { | 251 | private fun BorrarInvActual() { |
248 | lifecycleScope.launch { | 252 | lifecycleScope.launch { |
249 | withContext(Dispatchers.IO) { | 253 | withContext(Dispatchers.IO) { |
250 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.deleteinvHead(InventarioNuevo) | 254 | AppDb.getAppDb(requireActivity())!!.InvHeadDAO()!!.deleteinvHead(InventarioNuevo) |
251 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.deleteInvBody(InventarioNuevo) | 255 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.deleteInvBody(InventarioNuevo) |
252 | } | 256 | } |
253 | } | 257 | } |
254 | } | 258 | } |
255 | 259 | ||
256 | private fun CargarDeBdInventario(ultimoInv: Int) { | 260 | private fun CargarDeBdInventario(ultimoInv: Int) { |
257 | GlobalScope.launch(Dispatchers.Main) { | 261 | GlobalScope.launch(Dispatchers.Main) { |
258 | val invbody = cargarInventario(ultimoInv) | 262 | val invbody = cargarInventario(ultimoInv) |
259 | for ((i, item) in invbody!!.withIndex()) { | 263 | for ((i, item) in invbody!!.withIndex()) { |
260 | val art = Articles(invbody[i].sector, | 264 | val art = Articles(invbody[i].sector, |
261 | invbody[i].codigo, | 265 | invbody[i].codigo, |
262 | invbody[i].descripcion, | 266 | invbody[i].descripcion, |
263 | invbody[i].codBar, | 267 | invbody[i].codBar, |
264 | invbody[i].codOrigen, | 268 | invbody[i].codOrigen, |
265 | invbody[i].precio, | 269 | invbody[i].precio, |
266 | invbody[i].costo, | 270 | invbody[i].costo, |
267 | invbody[i].balanza, | 271 | invbody[i].balanza, |
268 | invbody[i].depSn, | 272 | invbody[i].depSn, |
269 | invbody[i].costo) | 273 | invbody[i].costo) |
270 | cargarRecicler(art, invbody[i].cantTomada!!.toFloat()) | 274 | cargarRecicler(art, invbody[i].cantTomada!!.toFloat()) |
271 | } | 275 | } |
272 | } | 276 | } |
273 | 277 | ||
274 | } | 278 | } |
275 | 279 | ||
276 | private fun ContinuarCargaDesc(artAcargar: ArrayList<Articles>) { | 280 | private fun ContinuarCargaDesc(artAcargar: ArrayList<Articles>) { |
277 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS | 281 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS |
278 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV | 282 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV |
279 | 283 | ||
280 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD | 284 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD |
281 | // if (swSumaUno!!.isChecked) {// TODO: SI ESTA +1, PONE CANTIDAD 1 | 285 | // if (swSumaUno!!.isChecked) {// TODO: SI ESTA +1, PONE CANTIDAD 1 |
282 | if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV | 286 | if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV |
283 | fCant = 0F | 287 | fCant = 0F |
284 | fCant += 1F | 288 | fCant += 1F |
285 | // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV | 289 | // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV |
286 | val acargarPorDesc = Articles(artAcargar[0].sector, | 290 | val acargarPorDesc = Articles(artAcargar[0].sector, |
287 | artAcargar[0].codigo, | 291 | artAcargar[0].codigo, |
288 | artAcargar[0].descripcion, | 292 | artAcargar[0].descripcion, |
289 | artAcargar[0].codBar, | 293 | artAcargar[0].codBar, |
290 | artAcargar[0].codOrigen, | 294 | artAcargar[0].codOrigen, |
291 | artAcargar[0].precio, | 295 | artAcargar[0].precio, |
292 | artAcargar[0].costo, | 296 | artAcargar[0].costo, |
293 | artAcargar[0].balanza, | 297 | artAcargar[0].balanza, |
294 | artAcargar[0].depSn, | 298 | artAcargar[0].depSn, |
295 | "") | 299 | "") |
296 | // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD | 300 | // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD |
297 | cargarArtEnBd(acargarPorDesc, fCant) | 301 | cargarArtEnBd(acargarPorDesc, fCant) |
298 | cargarRecicler(acargarPorDesc, fCant) | 302 | cargarRecicler(acargarPorDesc, fCant) |
299 | } else { | 303 | } else { |
300 | var bundle = Bundle() | 304 | var bundle = Bundle() |
301 | bundle = bundleOf("ArrayDesc" to artAcargar) | 305 | bundle = bundleOf("ArrayDesc" to artAcargar) |
302 | bundle.putInt("numeroInv", InventarioNuevo) | 306 | bundle.putInt("numeroInv", InventarioNuevo) |
303 | navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) | 307 | navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) |
304 | } | 308 | } |
305 | // } else {//SI NO ESTA +1 | 309 | // } else {//SI NO ESTA +1 |
306 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV | 310 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV |
307 | // fCant = listArticulos[0].cantTomada | 311 | // fCant = listArticulos[0].cantTomada |
308 | // MaterialDialog(requireContext()).show { | 312 | // MaterialDialog(requireContext()).show { |
309 | // title(R.string.sTituloNueva) | 313 | // title(R.string.sTituloNueva) |
310 | // message(R.string.sCantidadNueva) | 314 | // message(R.string.sCantidadNueva) |
311 | // input { materialDialog, charSequence -> | 315 | // input { materialDialog, charSequence -> |
312 | // fCant = 0F | 316 | // fCant = 0F |
313 | // fCant = charSequence.toString().toFloat() | 317 | // fCant = charSequence.toString().toFloat() |
314 | // } | 318 | // } |
315 | // positiveButton(R.string.btnOk) { | 319 | // positiveButton(R.string.btnOk) { |
316 | // listArticulos[0].cantTomada = fCant | 320 | // listArticulos[0].cantTomada = fCant |
317 | // viewAdapter.notifyDataSetChanged() | 321 | // viewAdapter.notifyDataSetChanged() |
318 | // dismiss() | 322 | // dismiss() |
319 | // } | 323 | // } |
320 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 324 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
321 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV | 325 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV |
322 | // val acargarPorDesc = Articles(artAcargar[0].sector, | 326 | // val acargarPorDesc = Articles(artAcargar[0].sector, |
323 | // artAcargar[0].codigo, | 327 | // artAcargar[0].codigo, |
324 | // artAcargar[0].descripcion, | 328 | // artAcargar[0].descripcion, |
325 | // artAcargar[0].codBar, | 329 | // artAcargar[0].codBar, |
326 | // artAcargar[0].codOrigen, | 330 | // artAcargar[0].codOrigen, |
327 | // artAcargar[0].precio, | 331 | // artAcargar[0].precio, |
328 | // artAcargar[0].costo, | 332 | // artAcargar[0].costo, |
329 | // artAcargar[0].balanza, | 333 | // artAcargar[0].balanza, |
330 | // artAcargar[0].depSn, | 334 | // artAcargar[0].depSn, |
331 | // "") | 335 | // "") |
332 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD | 336 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD |
333 | // cargarArtEnBd(acargarPorDesc, fCant) | 337 | // cargarArtEnBd(acargarPorDesc, fCant) |
334 | // cargarRecicler(acargarPorDesc, fCant) | 338 | // cargarRecicler(acargarPorDesc, fCant) |
335 | // } else { | 339 | // } else { |
336 | // var bundle = Bundle() | 340 | // var bundle = Bundle() |
337 | // bundle = bundleOf("ArrayDesc" to artAcargar) | 341 | // bundle = bundleOf("ArrayDesc" to artAcargar) |
338 | // bundle.putInt("numeroInv", InventarioNuevo) | 342 | // bundle.putInt("numeroInv", InventarioNuevo) |
339 | // navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) | 343 | // navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) |
340 | // } | 344 | // } |
341 | // } | 345 | // } |
342 | } else {//TODO si no lo encuentra en la BD | 346 | } else {//TODO si no lo encuentra en la BD |
343 | MaterialDialog(requireContext()).show { | 347 | MaterialDialog(requireContext()).show { |
344 | title(R.string.sTitulo) | 348 | title(R.string.sTitulo) |
345 | message(R.string.sMensaje) | 349 | message(R.string.sMensaje) |
346 | positiveButton(R.string.btnOk) { | 350 | positiveButton(R.string.btnOk) { |
347 | dismiss() | 351 | dismiss() |
348 | } | 352 | } |
349 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 353 | }.cornerRadius(10F) |
350 | } | 354 | } |
351 | 355 | ||
352 | } | 356 | } |
353 | 357 | ||
354 | private fun ContinuarCargaCB(artAcargar: Articles?) { | 358 | private fun ContinuarCargaCB(artAcargar: Articles?) { |
355 | 359 | ||
356 | if (artAcargar != null) {//Si lo encuentra en la BD | 360 | if (artAcargar != null) {//Si lo encuentra en la BD |
357 | 361 | ||
358 | if (swSumaUno!!.isChecked) {// SI ESTA +1, PONE CANTIDAD 1 | 362 | if (swSumaUno!!.isChecked) {// SI ESTA +1, PONE CANTIDAD 1 |
359 | fCant = 0F | 363 | fCant = 0F |
360 | fCant += 1F | 364 | fCant += 1F |
361 | cargarArtEnBd(artAcargar, fCant) | 365 | cargarArtEnBd(artAcargar, fCant) |
362 | cargarRecicler(artAcargar, fCant) | 366 | cargarRecicler(artAcargar, fCant) |
363 | } else {//SI NO ESTA +1 PREGUNTA CANTIDAD | 367 | } else {//SI NO ESTA +1 PREGUNTA CANTIDAD |
364 | MaterialDialog(requireContext()).show { | 368 | MaterialDialog(requireContext()).show { |
365 | title(R.string.sTitulo) | 369 | title(R.string.sTitulo) |
366 | message(R.string.sMensajeEncontrado) | 370 | message(R.string.sMensajeEncontrado) |
367 | input { materialDialog, charSequence -> | 371 | input { materialDialog, charSequence -> |
368 | fCant = 0F | 372 | fCant = 0F |
369 | fCant = charSequence.toString().toFloat() | 373 | fCant = charSequence.toString().toFloat() |
370 | } | 374 | } |
371 | // .input("Cantidad",1,,1,0,InputType.TYPE_CLASS_NUMBER,0,waitForPositiveButton = true,false,positiveButton ()) | 375 | // .input("Cantidad",1,,1,0,InputType.TYPE_CLASS_NUMBER,0,waitForPositiveButton = true,false,positiveButton ()) |
372 | positiveButton(R.string.btnOk) { | 376 | positiveButton(R.string.btnOk) { |
373 | dismiss() | 377 | dismiss() |
374 | cargarArtEnBd(artAcargar, fCant) | 378 | cargarArtEnBd(artAcargar, fCant) |
375 | cargarRecicler(artAcargar, fCant) | 379 | cargarRecicler(artAcargar, fCant) |
376 | 380 | ||
377 | } | 381 | } |
378 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 382 | }.cancelOnTouchOutside(false).cornerRadius(10F) |
379 | } | 383 | } |
380 | } else {// TODO si no lo encuentra en la BD | 384 | } else {// TODO si no lo encuentra en la BD |
381 | MaterialDialog(requireContext()).show { | 385 | MaterialDialog(requireContext()).show { |
382 | title(R.string.sTitulo) | 386 | title(R.string.sTitulo) |
383 | message(R.string.sMensaje) | 387 | message(R.string.sMensaje) |
384 | positiveButton(R.string.btnOk) { | 388 | positiveButton(R.string.btnOk) { |
385 | // if (this.swSumaUno.isChecked) { | 389 | // if (this.swSumaUno.isChecked) { |
386 | // swSumaUno.isChecked=false | 390 | // swSumaUno.isChecked=false |
387 | // } | 391 | // } |
388 | dismiss() | 392 | dismiss() |
389 | } | 393 | } |
390 | }.cancelOnTouchOutside(false).cornerRadius(10F) | 394 | }.cornerRadius(10F) |
391 | } | 395 | } |
392 | } | 396 | } |
393 | 397 | ||
394 | suspend fun buscarCBEnBD(CodigoBarras: String): Articles? { | 398 | suspend fun buscarCBEnBD(CodigoBarras: String): Articles? { |
395 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 399 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
396 | var busqueda: Articles? = null | 400 | var busqueda: Articles? = null |
397 | return GlobalScope.async(Dispatchers.IO) { | 401 | return GlobalScope.async(Dispatchers.IO) { |
398 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBar(CodigoBarras, iArea) | 402 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBar(CodigoBarras, iArea) |
399 | return@async busqueda | 403 | return@async busqueda |
400 | }.await() | 404 | }.await() |
401 | } | 405 | } |
402 | 406 | ||
403 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { | 407 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { |
404 | //TODO BUSQUEDA POR DESCRIPCION | 408 | //TODO BUSQUEDA POR DESCRIPCION |
405 | var busqueda: List<Articles>? = null | 409 | var busqueda: List<Articles>? = null |
406 | return GlobalScope.async(Dispatchers.IO) { | 410 | return GlobalScope.async(Dispatchers.IO) { |
407 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, iArea) | 411 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, iArea) |
408 | return@async busqueda | 412 | return@async busqueda |
409 | }.await() | 413 | }.await() |
410 | } | 414 | } |
411 | 415 | ||
412 | private fun buscoArtEnRv(codigoBarras: String, sTipoBusqueda: Int): Int { | 416 | private fun buscoArtEnRv(codigoBarras: String, sTipoBusqueda: Int): Int { |
413 | var indice = 0 | 417 | var indice = 0 |
414 | var bEncontrado = false | 418 | var bEncontrado = false |
415 | if (sTipoBusqueda == 0) {//TODO BUSQUEDA POR CODIGO DE BARRAS | 419 | if (sTipoBusqueda == 0) {//TODO BUSQUEDA POR CODIGO DE BARRAS |
416 | for (item in listArticulos) { | 420 | for (item in listArticulos) { |
417 | if (item.codigoBarras!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 421 | if (item.codigoBarras!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
418 | bEncontrado = true | 422 | bEncontrado = true |
419 | break | 423 | break |
420 | } | 424 | } |
421 | indice += 1 | 425 | indice += 1 |
422 | } | 426 | } |
423 | } else {//TODO BUSQUEDA POR DESCRIPCION | 427 | } else {//TODO BUSQUEDA POR DESCRIPCION |
424 | for (item in listArticulos) { | 428 | for (item in listArticulos) { |
425 | if (item.descripcion!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 429 | if (item.descripcion!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
426 | bEncontrado = true | 430 | bEncontrado = true |
427 | break | 431 | break |
428 | } | 432 | } |
429 | indice += 1 | 433 | indice += 1 |
430 | } | 434 | } |
431 | } | 435 | } |
432 | return if (bEncontrado) indice | 436 | return if (bEncontrado) indice |
433 | else -1 | 437 | else -1 |
434 | } | 438 | } |
435 | 439 | ||
436 | private fun cargarArtEnBd(articulos: Articles, cant: Float) { | 440 | private fun cargarArtEnBd(articulos: Articles, cant: Float) { |
437 | val body = InvBody(InventarioNuevo,// TODO PREPARO PARA MANDAR A CARGAR EN LA BD | 441 | val body = InvBody(InventarioNuevo,// TODO PREPARO PARA MANDAR A CARGAR EN LA BD |
438 | articulos.sector, | 442 | articulos.sector, |
439 | articulos.codigo, | 443 | articulos.codigo, |
440 | articulos.descripcion, | 444 | articulos.descripcion, |
441 | cant.toString(), | 445 | cant.toString(), |
442 | articulos.codBar, | 446 | articulos.codBar, |
443 | articulos.codOrigen, | 447 | articulos.codOrigen, |
444 | articulos.precio, | 448 | articulos.precio, |
445 | articulos.precio, | 449 | articulos.precio, |
446 | articulos.balanza, | 450 | articulos.balanza, |
447 | articulos.depSn, | 451 | articulos.depSn, |
448 | ObtenerFechaActual(), | 452 | ObtenerFechaActual(), |
449 | ObtenerFechaActual()) | 453 | ObtenerFechaActual()) |
450 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS | 454 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS |
451 | } | 455 | } |
452 | 456 | ||
453 | fun cargarRecicler(articulos: Articles, cant: Float) { | 457 | fun cargarRecicler(articulos: Articles, cant: Float) { |
454 | 458 | ||
455 | //TODO CARGO EN LE RV | 459 | //TODO CARGO EN LE RV |
456 | val item = ItemsRecycler(articulos.sector, articulos.codigo, articulos.descripcion, cant, articulos.codBar) | 460 | val item = ItemsRecycler(articulos.sector, articulos.codigo, articulos.descripcion, cant, articulos.codBar) |
457 | listArticulos.add(item) | 461 | listArticulos.add(item) |
458 | 462 | ||
459 | viewAdapter = ProductosListAdapter(listArticulos) | 463 | viewAdapter = ProductosListAdapter(listArticulos) |
460 | viewManager =LinearLayoutManager(requireContext()) | 464 | viewManager = LinearLayoutManager(requireContext()) |
461 | deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! | 465 | deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! |
462 | rcInventarios.apply { | 466 | rcInventarios.apply { |
463 | adapter = viewAdapter | 467 | adapter = viewAdapter |
464 | layoutManager = viewManager | 468 | layoutManager = viewManager |
465 | } | 469 | } |
466 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { | 470 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { |
467 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { | 471 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { |
468 | return false | 472 | return false |
469 | } | 473 | } |
470 | 474 | ||
471 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | 475 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { |
472 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) | 476 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) |
473 | viewAdapter.notifyDataSetChanged() | 477 | viewAdapter.notifyDataSetChanged() |
474 | } | 478 | } |
475 | 479 | ||
476 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { | 480 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { |
477 | val itemView = viewHolder.itemView | 481 | val itemView = viewHolder.itemView |
478 | val iconMargin = (itemView.height - deleteIcon.intrinsicHeight) / 2 | 482 | val iconMargin = (itemView.height - deleteIcon.intrinsicHeight) / 2 |
479 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) | 483 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) |
480 | 484 | ||
481 | if (dX > 0) { | 485 | if (dX > 0) { |
482 | 486 | ||
483 | if (dX < c.width / 2) c.drawColor(Color.GREEN) | 487 | if (dX < c.width / 2) c.drawColor(Color.GREEN) |
484 | else c.drawColor(Color.RED) | 488 | else c.drawColor(Color.RED) |
485 | deleteIcon.setBounds(itemView.left + iconMargin, itemView.top + iconMargin, itemView.left + iconMargin + deleteIcon.intrinsicWidth, itemView.bottom-iconMargin) | 489 | deleteIcon.setBounds(itemView.left + iconMargin, itemView.top + iconMargin, itemView.left + iconMargin + deleteIcon.intrinsicWidth, itemView.bottom - iconMargin) |
486 | } else { | 490 | } else { |
487 | 491 | ||
488 | } | 492 | } |
489 | 493 | ||
490 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 494 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
491 | deleteIcon.draw(c) | 495 | deleteIcon.draw(c) |
492 | } | 496 | } |
493 | } | 497 | } |
494 | 498 | ||
495 | val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback) | 499 | val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback) |
496 | itemTouchHelper.attachToRecyclerView(rcInventarios) | 500 | itemTouchHelper.attachToRecyclerView(rcInventarios) |
497 | } | 501 | } |
498 | 502 | ||
499 | private fun ProdNoCont(): Int? { | 503 | private fun ProdNoCont(): Int? { |
500 | var mostrarStock = 0 | 504 | var mostrarStock = 0 |
501 | if (sharedPreferences.contains("cbMostrarStock")) if (sharedPreferences.getString("cbMostrarStock", "").toString() == "1") mostrarStock = 1 | 505 | if (sharedPreferences.contains("cbMostrarStock")) if (sharedPreferences.getString("cbMostrarStock", "").toString() == "1") mostrarStock = 1 |
502 | return mostrarStock | 506 | return mostrarStock |
503 | } | 507 | } |
504 | 508 | ||
505 | private fun AjusteProductos(): Int? { | 509 | private fun AjusteProductos(): Int? { |
506 | var prodInclu = 0 | 510 | var prodInclu = 0 |
507 | if (sharedPreferences.contains("rbProInclu")) if (sharedPreferences.getString("rbProInclu", "").toString() == "1") prodInclu = 1 | 511 | if (sharedPreferences.contains("rbProInclu")) if (sharedPreferences.getString("rbProInclu", "").toString() == "1") prodInclu = 1 |
508 | 512 | ||
509 | if (sharedPreferences.contains("rbProNoInclu")) if (sharedPreferences.getString("rbProNoInclu", "").toString() == "0") prodInclu = 0 | 513 | if (sharedPreferences.contains("rbProNoInclu")) if (sharedPreferences.getString("rbProNoInclu", "").toString() == "0") prodInclu = 0 |
510 | return prodInclu | 514 | return prodInclu |
511 | } | 515 | } |
512 | 516 | ||
513 | private fun SerchArea() { | 517 | private fun SerchArea() { |
514 | 518 | ||
515 | if (sharedPreferences.contains("rbVentas")) if (sharedPreferences.getString("rbVentas", "").toString() == "1") iArea = 0 | 519 | if (sharedPreferences.contains("rbVentas")) if (sharedPreferences.getString("rbVentas", "").toString() == "1") iArea = 0 |
516 | if (sharedPreferences.contains("rbDeposito")) if (sharedPreferences.getString("rbDeposito", "").toString() == "1") iArea = 1 | 520 | if (sharedPreferences.contains("rbDeposito")) if (sharedPreferences.getString("rbDeposito", "").toString() == "1") iArea = 1 |
517 | } | 521 | } |
518 | 522 | ||
519 | fun ObtenerFechaActual(): String? { | 523 | fun ObtenerFechaActual(): String? { |
520 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | 524 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD |
521 | val current = LocalDateTime.now() | 525 | val current = LocalDateTime.now() |
522 | val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") | 526 | val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm:ss") |
523 | val dFechaHora = current.format(formatter) | 527 | val dFechaHora = current.format(formatter) |
524 | return dFechaHora.toString() | 528 | return dFechaHora.toString() |
525 | } | 529 | } |
526 | 530 | ||
527 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { | 531 | fun InsertarArtEnDB(cuarpoInventario: InvBody) { |
528 | lifecycleScope.launch { | 532 | lifecycleScope.launch { |
529 | withContext(Dispatchers.IO) { | 533 | withContext(Dispatchers.IO) { |
530 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) | 534 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) |
531 | } | 535 | } |
532 | } | 536 | } |
533 | } | 537 | } |
534 | 538 | ||
535 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { | 539 | fun updateCantidad(sector: String, codigo: String, cantidad: Float) { |
536 | lifecycleScope.launch { | 540 | lifecycleScope.launch { |
537 | withContext(Dispatchers.IO) { | 541 | withContext(Dispatchers.IO) { |
538 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.UpdateInvBody(cantidad, sector, codigo) | 542 | AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.UpdateInvBody(cantidad, sector, codigo) |
539 | } | 543 | } |
540 | } | 544 | } |
541 | } | 545 | } |
542 | 546 | ||
543 | suspend fun cargarInventario(inventario: Int): List<InvBody>? { | 547 | suspend fun cargarInventario(inventario: Int): List<InvBody>? { |
544 | // var inventarios: List<InvBody>? = null | 548 | // var inventarios: List<InvBody>? = null |
545 | return GlobalScope.async(Dispatchers.IO) { | 549 | return GlobalScope.async(Dispatchers.IO) { |
546 | return@async AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inventario) | 550 | return@async AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inventario) |
547 | }.await() | 551 | }.await() |
548 | } | 552 | } |
549 | } | 553 | } |
550 | 554 | ||
551 | 555 | ||
552 | 556 | ||
553 | 557 | ||
554 | 558 | ||
555 | 559 | ||
556 | 560 | ||
557 | 561 | ||
558 | 562 | ||
559 | 563 | ||
560 | 564 | ||
561 | 565 | ||
562 | 566 |
app/src/main/java/com/focasoftware/deboinventariov20/ui/main/MainFragment.kt
1 | package com.focasoftware.deboinventariov20.ui.main | 1 | package com.focasoftware.deboinventariov20.ui.main |
2 | 2 | ||
3 | import android.content.Context | 3 | import android.content.Context |
4 | import android.content.SharedPreferences | 4 | import android.content.SharedPreferences |
5 | import android.os.Bundle | 5 | import android.os.Bundle |
6 | import android.view.LayoutInflater | 6 | import android.view.LayoutInflater |
7 | import android.view.View | 7 | import android.view.View |
8 | import android.view.ViewGroup | 8 | import android.view.ViewGroup |
9 | import androidx.core.view.get | ||
10 | import androidx.fragment.app.Fragment | 9 | import androidx.fragment.app.Fragment |
11 | import androidx.navigation.NavController | 10 | import androidx.navigation.NavController |
12 | import androidx.navigation.Navigation | 11 | import androidx.navigation.Navigation |
13 | import androidx.recyclerview.widget.LinearLayoutManager | 12 | import androidx.recyclerview.widget.LinearLayoutManager |
14 | import androidx.recyclerview.widget.RecyclerView | 13 | import androidx.recyclerview.widget.RecyclerView |
15 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 14 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
16 | import com.focasoftware.deboinventariov20.Model.InvHead | 15 | import com.focasoftware.deboinventariov20.Model.InvHead |
17 | import com.focasoftware.deboinventariov20.R | 16 | import com.focasoftware.deboinventariov20.R |
18 | import kotlinx.coroutines.Dispatchers | 17 | import kotlinx.coroutines.Dispatchers |
19 | import kotlinx.coroutines.GlobalScope | 18 | import kotlinx.coroutines.GlobalScope |
20 | import kotlinx.coroutines.async | 19 | import kotlinx.coroutines.async |
21 | import kotlinx.coroutines.launch | 20 | import kotlinx.coroutines.launch |
22 | import java.util.* | 21 | import java.util.* |
23 | 22 | ||
24 | class MainFragment : Fragment(), InventarioListAdapter.OnItemClickListener { | 23 | class MainFragment : Fragment(), InventarioListAdapter.OnItemClickListener { |
25 | private lateinit var inventarios: List<InvHead> | 24 | private lateinit var inventarios: List<InvHead> |
26 | private lateinit var rcInventario: RecyclerView | 25 | private lateinit var rcInventario: RecyclerView |
27 | private lateinit var viewAdapter: RecyclerView.Adapter<*> | 26 | private lateinit var viewAdapter: RecyclerView.Adapter<*> |
28 | private lateinit var viewManager: RecyclerView.LayoutManager | 27 | private lateinit var viewManager: RecyclerView.LayoutManager |
29 | private var listIvn = ArrayList<ItemInventario>() | 28 | private var listIvn = ArrayList<ItemInventario>() |
30 | private lateinit var navController: NavController | 29 | private lateinit var navController: NavController |
31 | private lateinit var sharedPreferences: SharedPreferences | 30 | private lateinit var sharedPreferences: SharedPreferences |
32 | 31 | ||
33 | override fun onCreate(savedInstanceState: Bundle?) { | 32 | override fun onCreate(savedInstanceState: Bundle?) { |
34 | super.onCreate(savedInstanceState) | 33 | super.onCreate(savedInstanceState) |
35 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 34 | sharedPreferences = requireActivity().getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
36 | 35 | ||
37 | 36 | ||
38 | } | 37 | } |
39 | 38 | ||
40 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 39 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
41 | val v = inflater.inflate(R.layout.fragment_main, container, false) | 40 | val v = inflater.inflate(R.layout.fragment_main, container, false) |
42 | GlobalScope.launch(Dispatchers.Main) { | 41 | GlobalScope.launch(Dispatchers.Main) { |
43 | inventarios = buscarEnBDInvHead() | 42 | inventarios = buscarEnBDInvHead() |
44 | for ((i, item) in inventarios.withIndex()) { | 43 | for ((i, item) in inventarios.withIndex()) { |
45 | val inv = InvHead(inventarios[i].invNum, | 44 | val inv = InvHead(inventarios[i].invNum, |
46 | inventarios[i].descripcion, | 45 | inventarios[i].descripcion, |
47 | inventarios[i].estado, | 46 | inventarios[i].estado, |
48 | inventarios[i].fechaInicio, | 47 | inventarios[i].fechaInicio, |
49 | inventarios[i].fechaFinal, | 48 | inventarios[i].fechaFinal, |
50 | inventarios[i].prodContados, | 49 | inventarios[i].prodContados, |
51 | inventarios[i].lugar, | 50 | inventarios[i].lugar, |
52 | inventarios[i].stDesc, | 51 | inventarios[i].stDesc, |
53 | inventarios[i].proNoCont) | 52 | inventarios[i].proNoCont) |
54 | cargarRecicler(inv) | 53 | cargarRecicler(inv) |
55 | } | 54 | } |
56 | } | 55 | } |
57 | rcInventario = v.findViewById(R.id.rcInventario) | 56 | rcInventario = v.findViewById(R.id.rcInventario) |
58 | return v | 57 | return v |
59 | } | 58 | } |
60 | 59 | ||
61 | suspend fun buscarEnBDInvHead(): List<InvHead> { | 60 | suspend fun buscarEnBDInvHead(): List<InvHead> { |
62 | //TODO BUSQUEDA POR DESCRIPCION | 61 | //TODO BUSQUEDA POR DESCRIPCION |
63 | var busqueda: List<InvHead> | 62 | var busqueda: List<InvHead> |
64 | return GlobalScope.async(Dispatchers.IO) { | 63 | return GlobalScope.async(Dispatchers.IO) { |
65 | busqueda = AppDb.getAppDb(requireContext())!!.InvHeadDAO()!!.fetchAllInvHead() | 64 | busqueda = AppDb.getAppDb(requireContext())!!.InvHeadDAO()!!.fetchAllInvHead() |
66 | return@async busqueda | 65 | return@async busqueda |
67 | }.await() | 66 | }.await() |
68 | } | 67 | } |
69 | 68 | ||
70 | fun cargarRecicler(inv: InvHead) { | 69 | fun cargarRecicler(inv: InvHead) { |
71 | var numero="" | ||
72 | //TODO CARGO EN LE RV | 70 | //TODO CARGO EN LE RV |
73 | if (inv.invNum.toLong()<10) numero="0${inv.invNum.toLong()}" else numero=inv.invNum.toString() | 71 | |
74 | val item = ItemInventario("Inventeario: ${numero} ${inv.descripcion} Fecha:${inv.fechaFinal} ") | 72 | val number = if (inv.invNum.toLong()<10) "0${inv.invNum.toLong()}" else inv.invNum.toString() |
73 | val item = ItemInventario("Nยฐ $number ${inv.descripcion}. Fecha: ${inv.fechaFinal}") | ||
75 | //(articulos.sector, articulos.codigo, articulos.descripcion, cant, articulos.codBar) | 74 | //(articulos.sector, articulos.codigo, articulos.descripcion, cant, articulos.codBar) |
76 | listIvn.add(item) | 75 | listIvn.add(item) |
77 | 76 | ||
78 | viewAdapter = InventarioListAdapter(listIvn, this) | 77 | viewAdapter = InventarioListAdapter(listIvn, this) |
79 | viewManager = LinearLayoutManager(requireContext()) | 78 | viewManager = LinearLayoutManager(requireContext()) |
80 | 79 | ||
81 | rcInventario.apply { | 80 | rcInventario.apply { |
82 | adapter = viewAdapter | 81 | adapter = viewAdapter |
83 | layoutManager = viewManager | 82 | layoutManager = viewManager |
84 | } | 83 | } |
85 | } | 84 | } |
86 | 85 | ||
87 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 86 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
88 | super.onViewCreated(view, savedInstanceState) | 87 | super.onViewCreated(view, savedInstanceState) |
89 | navController = Navigation.findNavController(view) | 88 | navController = Navigation.findNavController(view) |
90 | } | 89 | } |
91 | 90 | ||
92 | override fun OnItemClick(position: Int) { | 91 | override fun OnItemClick(position: Int) { |
93 | val editor = sharedPreferences.edit() | 92 | val editor = sharedPreferences.edit() |
94 | var invSel:String = listIvn[position].inventario.toString() | 93 | var invSel:String = listIvn[position].inventario.toString() |
95 | invSel=invSel.substring(13, 15) | 94 | invSel=invSel.substring(13, 15) |
96 | editor?.putString("Inventario", invSel) | 95 | editor?.putString("Inventario", invSel) |
97 | editor?.apply() | 96 | editor?.apply() |
98 | editor.commit() | 97 | editor.commit() |
99 | navController.navigate(R.id.action_mainFragment2_to_inventarioFragment) | 98 | navController.navigate(R.id.action_mainFragment2_to_inventarioFragment) |
100 | 99 | ||
101 | } | 100 | } |
102 | } | 101 | } |
103 | 102 |
app/src/main/res/layout/fragment_servidores.xml
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <androidx.constraintlayout.widget.ConstraintLayout 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 | xmlns:tools="http://schemas.android.com/tools" | 4 | xmlns:tools="http://schemas.android.com/tools" |
5 | android:layout_width="match_parent" | 5 | android:layout_width="match_parent" |
6 | android:layout_height="match_parent" | 6 | android:layout_height="match_parent" |
7 | tools:context=".ui.servidores.ServidoresFragment"> | 7 | tools:context=".ui.servidores.ServidoresFragment"> |
8 | 8 | ||
9 | 9 | ||
10 | <androidx.appcompat.widget.AppCompatTextView | 10 | <androidx.appcompat.widget.AppCompatTextView |
11 | android:id="@+id/tvTitutloServer" | 11 | android:id="@+id/tvTitutloServer" |
12 | android:layout_width="match_parent" | 12 | android:layout_width="match_parent" |
13 | android:layout_height="90dp" | 13 | android:layout_height="90dp" |
14 | android:layout_marginStart="8dp" | 14 | android:layout_marginStart="8dp" |
15 | android:layout_marginTop="15dp" | 15 | android:layout_marginTop="15dp" |
16 | android:layout_marginEnd="8dp" | 16 | android:layout_marginEnd="8dp" |
17 | android:autoSizeMaxTextSize="100sp" | 17 | android:autoSizeMaxTextSize="100sp" |
18 | android:autoSizeMinTextSize="20sp" | 18 | android:autoSizeMinTextSize="20sp" |
19 | android:autoSizeStepGranularity="5sp" | 19 | android:autoSizeStepGranularity="5sp" |
20 | android:autoSizeTextType="uniform" | 20 | android:autoSizeTextType="uniform" |
21 | android:gravity="center" | 21 | android:gravity="center" |
22 | android:lines="1" | 22 | android:lines="1" |
23 | android:text="@string/tvTitutloServer" | 23 | android:text="@string/tvTitutloServer" |
24 | android:textColor="@color/colorAccent" | 24 | android:textColor="@color/colorAccent" |
25 | app:fontFamily="sans-serif-condensed" | 25 | app:fontFamily="sans-serif-condensed" |
26 | app:layout_constraintBottom_toTopOf="@id/guideline2" | 26 | app:layout_constraintBottom_toTopOf="@id/guideline2" |
27 | app:layout_constraintEnd_toEndOf="parent" | 27 | app:layout_constraintEnd_toEndOf="parent" |
28 | app:layout_constraintStart_toStartOf="parent" | 28 | app:layout_constraintStart_toStartOf="parent" |
29 | app:layout_constraintTop_toTopOf="parent" /> | 29 | app:layout_constraintTop_toTopOf="parent" /> |
30 | 30 | ||
31 | <TextView | 31 | <TextView |
32 | android:id="@+id/tvDirServer" | 32 | android:id="@+id/tvDirServer" |
33 | android:layout_width="match_parent" | 33 | android:layout_width="match_parent" |
34 | android:layout_height="wrap_content" | 34 | android:layout_height="wrap_content" |
35 | android:layout_marginStart="8dp" | 35 | android:layout_marginStart="8dp" |
36 | android:layout_marginEnd="8dp" | 36 | android:layout_marginEnd="8dp" |
37 | android:gravity="center" | 37 | android:gravity="center" |
38 | android:lines="1" | 38 | android:lines="1" |
39 | android:text="@string/tvDirServer" | 39 | android:text="@string/tvDirServer" |
40 | android:textColor="@android:color/black" | 40 | android:textColor="@android:color/black" |
41 | android:textSize="@dimen/TitulosMedios" | 41 | android:textSize="@dimen/TitulosMedios" |
42 | android:textStyle="bold|italic" | 42 | android:textStyle="bold|italic" |
43 | app:fontFamily="sans-serif-condensed" | 43 | app:fontFamily="sans-serif-condensed" |
44 | app:layout_constraintBottom_toTopOf="@+id/etDireccionServidor" | 44 | app:layout_constraintBottom_toTopOf="@+id/etDireccionServidor" |
45 | app:layout_constraintEnd_toEndOf="parent" | 45 | app:layout_constraintEnd_toEndOf="parent" |
46 | app:layout_constraintStart_toStartOf="parent" | 46 | app:layout_constraintStart_toStartOf="parent" |
47 | app:layout_constraintTop_toBottomOf="@id/guideline3" | 47 | app:layout_constraintTop_toBottomOf="@id/guideline3" |
48 | app:layout_constraintVertical_bias="0.451" /> | 48 | app:layout_constraintVertical_bias="0.451" /> |
49 | 49 | ||
50 | <TextView | 50 | <TextView |
51 | android:id="@+id/tvNomServer" | 51 | android:id="@+id/tvNomServer" |
52 | android:layout_width="match_parent" | 52 | android:layout_width="match_parent" |
53 | android:layout_height="wrap_content" | 53 | android:layout_height="wrap_content" |
54 | android:layout_marginStart="8dp" | 54 | android:layout_marginStart="8dp" |
55 | android:layout_marginEnd="8dp" | 55 | android:layout_marginEnd="8dp" |
56 | android:layout_marginTop="15dp" | 56 | android:layout_marginTop="15dp" |
57 | android:gravity="center" | 57 | android:gravity="center" |
58 | android:lines="2" | 58 | android:lines="2" |
59 | android:text="@string/tvNomServer" | 59 | android:text="@string/tvNomServer" |
60 | android:textColor="@android:color/black" | 60 | android:textColor="@android:color/black" |
61 | android:textSize="@dimen/TitulosMedios" | 61 | android:textSize="@dimen/TitulosMedios" |
62 | android:textStyle="bold|italic" | 62 | android:textStyle="bold|italic" |
63 | app:fontFamily="sans-serif-condensed" | 63 | app:fontFamily="sans-serif-condensed" |
64 | app:layout_constraintBottom_toTopOf="@+id/etNombreServidor" | 64 | app:layout_constraintBottom_toTopOf="@+id/etNombreServidor" |
65 | app:layout_constraintEnd_toEndOf="parent" | 65 | app:layout_constraintEnd_toEndOf="parent" |
66 | app:layout_constraintStart_toStartOf="parent" | 66 | app:layout_constraintStart_toStartOf="parent" |
67 | app:layout_constraintTop_toBottomOf="@id/guideline2" /> | 67 | app:layout_constraintTop_toBottomOf="@id/guideline2" /> |
68 | 68 | ||
69 | <EditText | 69 | <EditText |
70 | android:id="@+id/etNombreServidor" | 70 | android:id="@+id/etNombreServidor" |
71 | android:layout_width="match_parent" | 71 | android:layout_width="match_parent" |
72 | android:layout_height="wrap_content" | 72 | android:layout_height="wrap_content" |
73 | android:autofillHints="" | 73 | android:autofillHints="" |
74 | android:clickable="true" | 74 | android:clickable="true" |
75 | android:ems="10" | 75 | android:ems="10" |
76 | android:focusable="true" | 76 | android:focusable="true" |
77 | android:inputType="text" | 77 | android:inputType="text" |
78 | android:lines="1" | 78 | android:lines="1" |
79 | android:text="" | 79 | android:hint="Servidor Local" |
80 | android:textSize="15sp" | 80 | android:textSize="15sp" |
81 | app:layout_constraintBottom_toTopOf="@id/guideline3" | 81 | app:layout_constraintBottom_toTopOf="@id/guideline3" |
82 | app:layout_constraintEnd_toEndOf="parent" | 82 | app:layout_constraintEnd_toEndOf="parent" |
83 | app:layout_constraintHorizontal_bias="0.0" | 83 | app:layout_constraintHorizontal_bias="0.0" |
84 | app:layout_constraintStart_toStartOf="parent" | 84 | app:layout_constraintStart_toStartOf="parent" |
85 | app:layout_constraintTop_toBottomOf="@+id/tvNomServer" /> | 85 | app:layout_constraintTop_toBottomOf="@+id/tvNomServer" /> |
86 | 86 | ||
87 | <EditText | 87 | <EditText |
88 | android:id="@+id/etDireccionServidor" | 88 | android:id="@+id/etDireccionServidor" |
89 | android:layout_width="0dp" | 89 | android:layout_width="0dp" |
90 | android:layout_height="wrap_content" | 90 | android:layout_height="wrap_content" |
91 | android:layout_marginStart="8dp" | 91 | android:layout_marginStart="8dp" |
92 | android:layout_marginEnd="8dp" | 92 | android:layout_marginEnd="8dp" |
93 | android:clickable="true" | 93 | android:clickable="true" |
94 | android:ems="10" | 94 | android:ems="10" |
95 | android:focusable="true" | 95 | android:focusable="true" |
96 | android:inputType="text" | 96 | android:inputType="text" |
97 | android:lines="1" | 97 | android:lines="1" |
98 | android:text="" | 98 | |
99 | android:hint="192.168.10.1:9090" | ||
99 | android:textSize="15sp" | 100 | android:textSize="15sp" |
100 | app:layout_constraintBottom_toTopOf="@id/guideline4" | 101 | app:layout_constraintBottom_toTopOf="@id/guideline4" |
101 | app:layout_constraintEnd_toEndOf="parent" | 102 | app:layout_constraintEnd_toEndOf="parent" |
102 | app:layout_constraintStart_toStartOf="parent" | 103 | app:layout_constraintStart_toStartOf="parent" |
103 | app:layout_constraintTop_toTopOf="@+id/tvDirServer" /> | 104 | app:layout_constraintTop_toTopOf="@+id/tvDirServer" /> |
104 | 105 | ||
105 | <androidx.recyclerview.widget.RecyclerView | 106 | <androidx.recyclerview.widget.RecyclerView |
106 | android:id="@+id/rvServidores" | 107 | android:id="@+id/rvServidores" |
107 | android:layout_width="match_parent" | 108 | android:layout_width="match_parent" |
108 | android:layout_height="0dp" | 109 | android:layout_height="0dp" |
109 | android:background="@android:color/darker_gray" | 110 | android:background="@android:color/darker_gray" |
110 | app:layout_constraintBottom_toBottomOf="@+id/guideline5" | 111 | app:layout_constraintBottom_toBottomOf="@+id/guideline5" |
111 | app:layout_constraintEnd_toEndOf="parent" | 112 | app:layout_constraintEnd_toEndOf="parent" |
112 | app:layout_constraintStart_toStartOf="parent" | 113 | app:layout_constraintStart_toStartOf="parent" |
113 | app:layout_constraintTop_toBottomOf="@+id/guideline4" | 114 | app:layout_constraintTop_toBottomOf="@+id/guideline4" |
114 | tools:listitem="@layout/item_servidores" /> | 115 | tools:listitem="@layout/item_servidores" /> |
115 | 116 | ||
116 | <Button | 117 | <Button |
117 | android:id="@+id/btnGuardarServidores" | 118 | android:id="@+id/btnGuardarServidores" |
118 | android:layout_width="0dp" | 119 | android:layout_width="0dp" |
119 | android:layout_height="wrap_content" | 120 | android:layout_height="wrap_content" |
120 | android:text="@string/btnGuardarServidores" | 121 | android:text="@string/btnGuardarServidores" |
121 | app:layout_constraintBottom_toBottomOf="@+id/guideline6" | 122 | app:layout_constraintBottom_toBottomOf="@+id/guideline6" |
122 | app:layout_constraintEnd_toEndOf="parent" | 123 | app:layout_constraintEnd_toEndOf="parent" |
123 | app:layout_constraintStart_toStartOf="parent" /> | 124 | app:layout_constraintStart_toStartOf="parent" /> |
124 | 125 | ||
125 | 126 | ||
126 | <androidx.constraintlayout.widget.Guideline | 127 | <androidx.constraintlayout.widget.Guideline |
127 | android:id="@+id/guideline2" | 128 | android:id="@+id/guideline2" |
128 | android:layout_width="wrap_content" | 129 | android:layout_width="wrap_content" |
129 | android:layout_height="wrap_content" | 130 | android:layout_height="wrap_content" |
130 | android:orientation="horizontal" | 131 | android:orientation="horizontal" |
131 | app:layout_constraintGuide_percent="0.15" /> | 132 | app:layout_constraintGuide_percent="0.15" /> |
132 | 133 | ||
133 | <androidx.constraintlayout.widget.Guideline | 134 | <androidx.constraintlayout.widget.Guideline |
134 | android:id="@+id/guideline3" | 135 | android:id="@+id/guideline3" |
135 | android:layout_width="wrap_content" | 136 | android:layout_width="wrap_content" |
136 | android:layout_height="wrap_content" | 137 | android:layout_height="wrap_content" |
137 | android:orientation="horizontal" | 138 | android:orientation="horizontal" |
138 | app:layout_constraintGuide_percent="0.25" /> | 139 | app:layout_constraintGuide_percent="0.25" /> |
139 | 140 | ||
140 | <androidx.constraintlayout.widget.Guideline | 141 | <androidx.constraintlayout.widget.Guideline |
141 | android:id="@+id/guideline4" | 142 | android:id="@+id/guideline4" |
142 | android:layout_width="wrap_content" | 143 | android:layout_width="wrap_content" |
143 | android:layout_height="wrap_content" | 144 | android:layout_height="wrap_content" |
144 | android:orientation="horizontal" | 145 | android:orientation="horizontal" |
145 | app:layout_constraintGuide_percent="0.5" /> | 146 | app:layout_constraintGuide_percent="0.5" /> |
146 | 147 | ||
147 | <androidx.constraintlayout.widget.Guideline | 148 | <androidx.constraintlayout.widget.Guideline |
148 | android:id="@+id/guideline5" | 149 | android:id="@+id/guideline5" |
149 | android:layout_width="wrap_content" | 150 | android:layout_width="wrap_content" |
150 | android:layout_height="wrap_content" | 151 | android:layout_height="wrap_content" |
151 | android:orientation="horizontal" | 152 | android:orientation="horizontal" |
152 | app:layout_constraintGuide_percent="0.80" /> | 153 | app:layout_constraintGuide_percent="0.80" /> |
153 | 154 | ||
154 | <androidx.constraintlayout.widget.Guideline | 155 | <androidx.constraintlayout.widget.Guideline |
155 | android:id="@+id/guideline6" | 156 | android:id="@+id/guideline6" |
156 | android:layout_width="wrap_content" | 157 | android:layout_width="wrap_content" |
157 | android:layout_height="wrap_content" | 158 | android:layout_height="wrap_content" |
158 | android:orientation="horizontal" | 159 | android:orientation="horizontal" |
159 | app:layout_constraintGuide_percent="0.88" /> | 160 | app:layout_constraintGuide_percent="0.88" /> |
160 | </androidx.constraintlayout.widget.ConstraintLayout> | 161 | </androidx.constraintlayout.widget.ConstraintLayout> |
161 | 162 |
app/src/main/res/layout/login_dialog.xml
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <androidx.constraintlayout.widget.ConstraintLayout 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:orientation="vertical" | 6 | android:orientation="vertical" |
7 | android:padding="10dp"> | 7 | android:padding="10dp"> |
8 | 8 | ||
9 | <TextView | 9 | <TextView |
10 | android:id="@+id/dialogNameEt" | 10 | android:id="@+id/dialogNameEt" |
11 | android:layout_width="wrap_content" | 11 | android:layout_width="wrap_content" |
12 | android:layout_height="wrap_content" | 12 | android:layout_height="wrap_content" |
13 | android:layout_margin="5dp" | 13 | android:layout_margin="5dp" |
14 | android:text="La cantidad actual es:" | 14 | android:text="La cantidad actual es:" |
15 | android:textSize="20sp" | 15 | android:textSize="20sp" |
16 | app:layout_constraintEnd_toStartOf="@id/tvCantInicial" | 16 | app:layout_constraintEnd_toStartOf="@id/tvCantInicial" |
17 | app:layout_constraintHorizontal_bias="0.0" | 17 | app:layout_constraintHorizontal_bias="0.0" |
18 | app:layout_constraintHorizontal_chainStyle="packed" | 18 | app:layout_constraintHorizontal_chainStyle="packed" |
19 | app:layout_constraintStart_toStartOf="parent" | 19 | app:layout_constraintStart_toStartOf="parent" |
20 | app:layout_constraintTop_toTopOf="parent" /> | 20 | app:layout_constraintTop_toTopOf="parent" /> |
21 | 21 | ||
22 | <TextView | 22 | <TextView |
23 | android:id="@+id/tvCantInicial" | 23 | android:id="@+id/tvCantInicial" |
24 | android:layout_width="wrap_content" | 24 | android:layout_width="wrap_content" |
25 | android:layout_height="wrap_content" | 25 | android:layout_height="wrap_content" |
26 | android:layout_margin="5dp" | 26 | android:layout_margin="5dp" |
27 | android:text="20" | 27 | android:text="20" |
28 | android:textSize="20sp" | 28 | android:textSize="20sp" |
29 | app:layout_constraintBaseline_toBaselineOf="@+id/dialogNameEt" | 29 | app:layout_constraintBaseline_toBaselineOf="@+id/dialogNameEt" |
30 | app:layout_constraintEnd_toEndOf="parent" | 30 | app:layout_constraintEnd_toEndOf="parent" |
31 | app:layout_constraintHorizontal_chainStyle="packed" | 31 | app:layout_constraintHorizontal_chainStyle="packed" |
32 | app:layout_constraintStart_toEndOf="@id/dialogNameEt" /> | 32 | app:layout_constraintStart_toEndOf="@id/dialogNameEt" /> |
33 | 33 | ||
34 | <TextView | 34 | <TextView |
35 | android:id="@+id/tvgenerico" | 35 | android:id="@+id/tvgenerico" |
36 | android:layout_width="wrap_content" | 36 | android:layout_width="wrap_content" |
37 | android:layout_height="wrap_content" | 37 | android:layout_height="wrap_content" |
38 | android:layout_margin="5dp" | 38 | android:layout_margin="5dp" |
39 | android:text="Ingrese la nueva cantidad:" | 39 | android:text="Ingrese la nueva cantidad:" |
40 | android:textSize="20sp" | 40 | android:textSize="20sp" |
41 | app:layout_constraintStart_toStartOf="parent" | 41 | app:layout_constraintStart_toStartOf="parent" |
42 | app:layout_constraintTop_toBottomOf="@+id/tvCantInicial" /> | 42 | app:layout_constraintTop_toBottomOf="@+id/tvCantInicial" /> |
43 | 43 | ||
44 | <EditText | 44 | <EditText |
45 | android:id="@+id/tvNuevaCantidad" | 45 | android:id="@+id/tvNuevaCantidad" |
46 | android:layout_width="0dp" | 46 | android:layout_width="0dp" |
47 | android:layout_height="wrap_content" | 47 | android:layout_height="wrap_content" |
48 | android:hint="Nueva Cacntidad" | 48 | android:hint="Nueva Cacntidad" |
49 | android:inputType="numberDecimal" | 49 | android:inputType="numberDecimal" |
50 | app:layout_constraintBaseline_toBaselineOf="@+id/tvgenerico" | 50 | app:layout_constraintBaseline_toBaselineOf="@+id/tvgenerico" |
51 | app:layout_constraintEnd_toEndOf="parent" | 51 | app:layout_constraintEnd_toEndOf="parent" |
52 | app:layout_constraintStart_toEndOf="@id/tvgenerico" /> | 52 | app:layout_constraintStart_toEndOf="@id/tvgenerico" /> |
53 | 53 | ||
54 | <TextView | 54 | <TextView |
55 | android:id="@+id/tvgenerico2" | 55 | android:id="@+id/tvgenerico2" |
56 | android:layout_width="wrap_content" | 56 | android:layout_width="wrap_content" |
57 | android:layout_height="wrap_content" | 57 | android:layout_height="wrap_content" |
58 | android:layout_margin="5dp" | 58 | android:layout_margin="5dp" |
59 | android:visibility="gone" | ||
59 | android:gravity="center" | 60 | android:gravity="center" |
60 | android:text="@string/tvSeleccion" | 61 | android:text="@string/tvSeleccion" |
61 | android:textSize="20sp" | 62 | android:textSize="20sp" |
62 | app:layout_constraintStart_toStartOf="parent" | 63 | app:layout_constraintStart_toStartOf="parent" |
63 | app:layout_constraintTop_toBottomOf="@+id/tvgenerico" /> | 64 | app:layout_constraintTop_toBottomOf="@+id/tvgenerico" /> |
64 | 65 | ||
65 | <RadioGroup | 66 | <RadioGroup |
66 | android:id="@+id/rgFechaHora" | 67 | android:id="@+id/rgFechaHora" |
67 | android:layout_width="wrap_content" | 68 | android:layout_width="wrap_content" |
68 | android:layout_height="wrap_content" | 69 | android:layout_height="wrap_content" |
69 | android:layout_margin="5dp" | 70 | android:layout_margin="5dp" |
70 | android:gravity="start" | 71 | android:gravity="start" |
71 | android:orientation="vertical" | 72 | android:orientation="horizontal" |
72 | app:layout_constraintEnd_toEndOf="parent" | 73 | app:layout_constraintEnd_toEndOf="parent" |
73 | app:layout_constraintHorizontal_bias="0.0" | 74 | app:layout_constraintHorizontal_bias="0.0" |
74 | app:layout_constraintStart_toStartOf="parent" | 75 | app:layout_constraintStart_toStartOf="parent" |
75 | app:layout_constraintTop_toBottomOf="@+id/tvgenerico2"> | 76 | app:layout_constraintTop_toBottomOf="@+id/tvgenerico2"> |
76 | 77 | ||
77 | |||
78 | <RadioButton | 78 | <RadioButton |
79 | android:id="@+id/rbMdodificar" | 79 | android:id="@+id/rbSumar" |
80 | android:layout_width="wrap_content" | 80 | android:layout_width="wrap_content" |
81 | android:layout_height="wrap_content" | 81 | android:layout_height="wrap_content" |
82 | android:layout_margin="5dp" | 82 | android:layout_margin="5dp" |
83 | android:checked="false" | 83 | android:checked="true" |
84 | android:padding="5dp" | 84 | android:padding="5dp" |
85 | android:text="@string/rbModificar" | 85 | android:text="@string/rbSumar" |
86 | android:textSize="@dimen/text_size2" /> | 86 | android:textSize="@dimen/text_size2" /> |
87 | 87 | ||
88 | <RadioButton | 88 | <RadioButton |
89 | android:id="@+id/rbSumar" | 89 | android:id="@+id/rbRestar" |
90 | android:layout_width="wrap_content" | 90 | android:layout_width="wrap_content" |
91 | android:layout_height="wrap_content" | 91 | android:layout_height="wrap_content" |
92 | android:layout_margin="5dp" | 92 | android:layout_margin="5dp" |
93 | android:checked="false" | 93 | android:checked="false" |
94 | android:padding="5dp" | 94 | android:padding="5dp" |
95 | android:text="@string/rbSumar" | 95 | android:text="@string/rbRestar" |
96 | android:textSize="@dimen/text_size2" /> | 96 | android:textSize="@dimen/text_size2" /> |
97 | 97 | ||
98 | <RadioButton | 98 | <RadioButton |
99 | android:id="@+id/rbRestar" | 99 | android:id="@+id/rbMdodificar" |
100 | android:layout_width="wrap_content" | 100 | android:layout_width="wrap_content" |
101 | android:layout_height="wrap_content" | 101 | android:layout_height="wrap_content" |
102 | android:layout_margin="5dp" | 102 | android:layout_margin="5dp" |
103 | android:checked="false" | 103 | android:checked="false" |
104 | android:padding="5dp" | 104 | android:padding="5dp" |
105 | android:text="@string/rbRestar" | 105 | android:text="@string/rbModificar" |
106 | android:textSize="@dimen/text_size2" /> | 106 | android:textSize="@dimen/text_size2" /> |
107 | </RadioGroup> | 107 | </RadioGroup> |
108 | 108 | ||
109 | <TextView | 109 | <TextView |
110 | android:id="@+id/tvgenerico3" | 110 | android:id="@+id/tvgenerico3" |
111 | android:layout_width="wrap_content" | 111 | android:layout_width="wrap_content" |
112 | android:layout_height="wrap_content" | 112 | android:layout_height="wrap_content" |
113 | android:layout_margin="5dp" | 113 | android:layout_margin="5dp" |
114 | android:gravity="center" | 114 | android:gravity="center" |
115 | android:text="@string/tvResultado" | 115 | android:text="@string/tvResultado" |
116 | android:textSize="20sp" | 116 | android:textSize="20sp" |
117 | app:layout_constraintEnd_toEndOf="parent" | 117 | app:layout_constraintEnd_toEndOf="parent" |
118 | app:layout_constraintHorizontal_bias="0.0" | 118 | app:layout_constraintHorizontal_bias="0.0" |
119 | app:layout_constraintStart_toStartOf="parent" | 119 | app:layout_constraintStart_toStartOf="parent" |
120 | app:layout_constraintTop_toBottomOf="@+id/rgFechaHora" /> | 120 | app:layout_constraintTop_toBottomOf="@+id/rgFechaHora" /> |
121 | 121 | ||
122 | <TextView | 122 | <TextView |
123 | android:id="@+id/tvgenerico4" | 123 | android:id="@+id/tvgenerico4" |
124 | android:layout_width="wrap_content" | 124 | android:layout_width="wrap_content" |
125 | android:layout_height="wrap_content" | 125 | android:layout_height="wrap_content" |
126 | android:layout_margin="5dp" | 126 | android:layout_margin="5dp" |
127 | android:gravity="center" | 127 | android:gravity="center" |
128 | android:text="50" | 128 | android:text="50" |
129 | android:textSize="20sp" | 129 | android:textSize="20sp" |
130 | app:layout_constraintEnd_toEndOf="parent" | 130 | app:layout_constraintEnd_toEndOf="parent" |
131 | app:layout_constraintHorizontal_bias="0.0" | 131 | app:layout_constraintHorizontal_bias="0.0" |
132 | app:layout_constraintStart_toEndOf="@+id/tvgenerico3" | 132 | app:layout_constraintStart_toEndOf="@+id/tvgenerico3" |
133 | app:layout_constraintTop_toBottomOf="@+id/rgFechaHora" /> | 133 | app:layout_constraintTop_toBottomOf="@+id/rgFechaHora" /> |
134 | 134 | ||
135 | <LinearLayout | 135 | <LinearLayout |
136 | android:layout_width="match_parent" | 136 | android:layout_width="match_parent" |
137 | android:layout_height="wrap_content" | 137 | android:layout_height="wrap_content" |
138 | android:orientation="horizontal" | 138 | android:orientation="horizontal" |
139 | android:gravity="center" | 139 | android:gravity="center" |
140 | app:layout_constraintStart_toStartOf="parent" | 140 | app:layout_constraintStart_toStartOf="parent" |
141 | app:layout_constraintEnd_toEndOf="parent" | 141 | app:layout_constraintEnd_toEndOf="parent" |
142 | app:layout_constraintTop_toBottomOf="@+id/tvgenerico4"> | 142 | app:layout_constraintTop_toBottomOf="@+id/tvgenerico4"> |
143 | 143 | ||
144 | <Button | 144 | <Button |
145 | android:id="@+id/dialogLoginBtn" | 145 | android:id="@+id/dialogLoginBtn" |
146 | style="@style/Base.Widget.AppCompat.Button.Colored" | 146 | style="@style/Base.Widget.AppCompat.Button.Colored" |
147 | android:layout_width="wrap_content" | 147 | android:layout_width="wrap_content" |
148 | android:padding="20dp" | 148 | android:padding="20dp" |
149 | android:layout_margin="5dp" | 149 | android:layout_margin="5dp" |
150 | android:layout_height="wrap_content" | 150 | android:layout_height="wrap_content" |
151 | android:text="@string/btnOk" /> | 151 | android:text="@string/btnOk" /> |
152 | 152 | ||
153 | <Button | 153 | <Button |
154 | android:id="@+id/dialogCancelBtn" | 154 | android:id="@+id/dialogCancelBtn" |
155 | style="@style/Base.Widget.AppCompat.Button.Colored" | 155 | style="@style/Base.Widget.AppCompat.Button.Colored" |
156 | android:padding="20dp" | 156 | android:padding="20dp" |
157 | android:layout_margin="5dp" | 157 | android:layout_margin="5dp" |
158 | android:layout_width="wrap_content" | 158 | android:layout_width="wrap_content" |
159 | android:layout_height="wrap_content" | 159 | android:layout_height="wrap_content" |
160 | android:text="@string/btnCancelar" /> | 160 | android:text="@string/btnCancelar" /> |
161 | </LinearLayout> | 161 | </LinearLayout> |
162 | 162 |