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