Commit f65cd6121da32b9167aca39d441274099d2a73b3
1 parent
880347544e
Exists in
master
22102020 0743
Showing
5 changed files
with
52 additions
and
18 deletions
Show diff stats
app/src/main/java/com/focasoftware/deboinventariov20/DB/DAO/ArticulosDAO.kt
1 | package com.focasoftware.deboinventariov20.DB.DAO | 1 | package com.focasoftware.deboinventariov20.DB.DAO |
2 | 2 | ||
3 | import androidx.room.Dao | 3 | import androidx.room.Dao |
4 | import androidx.room.Insert | 4 | import androidx.room.Insert |
5 | import androidx.room.OnConflictStrategy | 5 | import androidx.room.OnConflictStrategy |
6 | import androidx.room.Query | 6 | import androidx.room.Query |
7 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_ART | 7 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_ART |
8 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_B | 8 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_B |
9 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_H | 9 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_H |
10 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_SEC_B | 10 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_SEC_B |
11 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_SEC_H | 11 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_INV_SEC_H |
12 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_SERV_INV | 12 | import com.focasoftware.deboinventariov20.DB.Constans.Constans.Companion.TABLA_SERV_INV |
13 | import com.focasoftware.deboinventariov20.Model.* | 13 | import com.focasoftware.deboinventariov20.Model.* |
14 | 14 | ||
15 | @Dao | 15 | @Dao |
16 | interface ArticulosDAO { | 16 | interface ArticulosDAO { |
17 | 17 | ||
18 | // TABLA ARTICULOS | 18 | // TABLA ARTICULOS |
19 | @Insert(onConflict = OnConflictStrategy.REPLACE) | 19 | @Insert(onConflict = OnConflictStrategy.REPLACE) |
20 | suspend fun insertArticulos(articulos: Articles?) | 20 | suspend fun insertArticulos(articulos: Articles?) |
21 | 21 | ||
22 | @Query("SELECT * FROM $TABLA_ART ORDER BY DETART DESC") | 22 | @Query("SELECT * FROM $TABLA_ART ORDER BY DETART DESC") |
23 | suspend fun findAllArticulos(): List<Articles> | 23 | suspend fun findAllArticulos(): List<Articles> |
24 | 24 | ||
25 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND DETART LIKE '%' || :description || '%' GROUP BY DETART ORDER BY DETART") | 25 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND DETART LIKE '%' || :description || '%' GROUP BY DETART ORDER BY DETART") |
26 | suspend fun findArticuloByDesc(description: String?, dep: Boolean): List<Articles> | 26 | suspend fun findArticuloByDesc(description: String?, dep: Boolean): List<Articles> |
27 | 27 | ||
28 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND TRIM(CODBAR) = :codBarra") | 28 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND TRIM(CODBAR) = :codBarra") |
29 | suspend fun findArticuloByCodBar(codBarra: String, dep: Boolean): Articles | 29 | suspend fun findArticuloByCodBar(codBarra: String, dep: Boolean): Articles |
30 | 30 | ||
31 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND TRIM(COO) LIKE :CodOrigen") | 31 | @Query("SELECT * FROM $TABLA_ART WHERE DEPSN=:dep AND TRIM(COO) LIKE :CodOrigen") |
32 | suspend fun findArticuloByCodOri(CodOrigen: String?, dep: Boolean): List<Articles> | 32 | suspend fun findArticuloByCodOri(CodOrigen: String?, dep: Boolean): List<Articles> |
33 | 33 | ||
34 | @Query("DELETE FROM $TABLA_ART") | 34 | @Query("DELETE FROM $TABLA_ART") |
35 | suspend fun deleteAllArticulos() | 35 | suspend fun deleteAllArticulos() |
36 | 36 | ||
37 | @Query("SELECT * FROM $TABLA_ART WHERE CODSEC=:sector AND CODART=:codigo") | 37 | @Query("SELECT * FROM $TABLA_ART WHERE CODSEC=:sector AND CODART=:codigo") |
38 | suspend fun fetchArticuloByCodSec(sector: String?, codigo: String?): Articles? | 38 | suspend fun fetchArticuloByCodSec(sector: String?, codigo: String?): Articles? |
39 | |||
40 | |||
41 | @Query("SELECT * FROM $TABLA_ART WHERE TRIM(CODBAR) = :codBarra") | ||
42 | suspend fun findArticuloByCodBarNoArea(codBarra: String): Articles | ||
43 | |||
44 | @Query("SELECT * FROM $TABLA_ART WHERE TRIM(COO) LIKE :CodOrigen") | ||
45 | suspend fun findArticuloByCodOriNoArea(CodOrigen: String?): List<Articles> | ||
46 | |||
47 | @Query("SELECT * FROM $TABLA_ART WHERE DETART LIKE '%' || :description || '%' GROUP BY DETART ORDER BY DETART") | ||
48 | suspend fun findArticuloByDescNoArea(description: String?): List<Articles> | ||
39 | } | 49 | } |
40 | 50 | ||
41 | @Dao | 51 | @Dao |
42 | interface InvHeadDAO { | 52 | interface InvHeadDAO { |
43 | @Insert() | 53 | @Insert() |
44 | suspend fun insertInvHead(invHead: InvHead?) | 54 | suspend fun insertInvHead(invHead: InvHead?) |
45 | 55 | ||
46 | @Query("SELECT INV_NUM FROM $TABLA_INV_H ORDER BY INV_NUM DESC") | 56 | @Query("SELECT INV_NUM FROM $TABLA_INV_H ORDER BY INV_NUM DESC") |
47 | suspend fun findLastInv(): Int | 57 | suspend fun findLastInv(): Int |
48 | 58 | ||
49 | @Query("DELETE FROM $TABLA_INV_H") | 59 | @Query("DELETE FROM $TABLA_INV_H") |
50 | suspend fun deleteAllArticulos() | 60 | suspend fun deleteAllArticulos() |
51 | 61 | ||
52 | @Query("DELETE FROM $TABLA_INV_H WHERE INV_NUM=:inven") | 62 | @Query("DELETE FROM $TABLA_INV_H WHERE INV_NUM=:inven") |
53 | suspend fun deleteinvHead(inven: Int) | 63 | suspend fun deleteinvHead(inven: Int) |
54 | 64 | ||
55 | @Query("SELECT * FROM $TABLA_INV_H ORDER BY INV_FEI") | 65 | @Query("SELECT * FROM $TABLA_INV_H ORDER BY INV_FEI") |
56 | suspend fun fetchAllInvHead(): List<InvHead> | 66 | suspend fun fetchAllInvHead(): List<InvHead> |
57 | 67 | ||
58 | @Query("SELECT INV_LUG FROM $TABLA_INV_H WHERE INV_NUM=:inven") | 68 | @Query("SELECT INV_LUG FROM $TABLA_INV_H WHERE INV_NUM=:inven") |
59 | suspend fun fetchAreaInvH (inven: Int): Boolean | 69 | suspend fun fetchAreaInvH (inven: Int): Boolean |
60 | 70 | ||
61 | @Query("SELECT INV_PRODCONT FROM $TABLA_INV_H WHERE INV_NUM=:inven") | 71 | @Query("SELECT INV_PRODCONT FROM $TABLA_INV_H WHERE INV_NUM=:inven") |
62 | suspend fun consultaCantidadInvH (inven: Int): Int | 72 | suspend fun consultaCantidadInvH (inven: Int): Int |
63 | 73 | ||
64 | @Query("UPDATE $TABLA_INV_H SET INV_PRODCONT=:cant WHERE INV_NUM=:inven") | 74 | @Query("UPDATE $TABLA_INV_H SET INV_PRODCONT=:cant WHERE INV_NUM=:inven") |
65 | suspend fun updateInvCantHead(inven: Int,cant: Int) | 75 | suspend fun updateInvCantHead(inven: Int,cant: Int) |
66 | 76 | ||
67 | @Query("SELECT * FROM $TABLA_INV_H WHERE INV_NUM=:inven") | 77 | @Query("SELECT * FROM $TABLA_INV_H WHERE INV_NUM=:inven") |
68 | suspend fun foundInvHead (inven: Int): InvHead | 78 | suspend fun foundInvHead (inven: Int): InvHead |
69 | } | 79 | } |
70 | 80 | ||
71 | @Dao | 81 | @Dao |
72 | interface InvBodyDAO { | 82 | interface InvBodyDAO { |
73 | @Insert() | 83 | @Insert() |
74 | suspend fun insertInvBody(invBody: InvBody?) | 84 | suspend fun insertInvBody(invBody: InvBody?) |
75 | 85 | ||
76 | @Query("DELETE FROM $TABLA_INV_B") | 86 | @Query("DELETE FROM $TABLA_INV_B") |
77 | suspend fun deleteAllInvBody() | 87 | suspend fun deleteAllInvBody() |
78 | 88 | ||
79 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:inven") | 89 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:inven") |
80 | suspend fun deleteInvBody(inven: Int) | 90 | suspend fun deleteInvBody(inven: Int) |
81 | 91 | ||
82 | @Query("UPDATE $TABLA_INV_B SET CANT=:cant , INV_FEF=:actFechaHora WHERE SEC=:sec AND COD=:cod") | 92 | @Query("UPDATE $TABLA_INV_B SET CANT=:cant , INV_FEF=:actFechaHora WHERE SEC=:sec AND COD=:cod") |
83 | suspend fun updateInvBody(cant: Float, sec: Long, cod: Long, actFechaHora:String) | 93 | suspend fun updateInvBody(cant: Float, sec: Long, cod: Long, actFechaHora:String) |
84 | 94 | ||
85 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:inven ORDER BY INV_FEI DESC") | 95 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:inven ORDER BY INV_FEI DESC") |
86 | suspend fun fetchAllInvBody(inven: Int): List<InvBody> | 96 | suspend fun fetchAllInvBody(inven: Int): List<InvBody> |
87 | 97 | ||
88 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:numInventario AND SEC=:sector AND COD=:codigo") | 98 | @Query("SELECT * FROM $TABLA_INV_B WHERE INV_NUM =:numInventario AND SEC=:sector AND COD=:codigo") |
89 | suspend fun fetchArtInInvBody(sector: Long, codigo: Long, numInventario: Int): InvBody | 99 | suspend fun fetchArtInInvBody(sector: Long, codigo: Long, numInventario: Int): InvBody |
90 | 100 | ||
91 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:numInventario AND SEC=:sector AND COD=:codigo") | 101 | @Query("DELETE FROM $TABLA_INV_B WHERE INV_NUM =:numInventario AND SEC=:sector AND COD=:codigo") |
92 | suspend fun deleteItemFromInvBody(sector: Long, codigo: Long, numInventario: Int): Int | 102 | suspend fun deleteItemFromInvBody(sector: Long, codigo: Long, numInventario: Int): Int |
93 | } | 103 | } |
94 | 104 | ||
95 | @Dao | 105 | @Dao |
96 | interface ServeInvDao { | 106 | interface ServeInvDao { |
97 | @Insert(onConflict = OnConflictStrategy.REPLACE) | 107 | @Insert(onConflict = OnConflictStrategy.REPLACE) |
98 | fun insertServer(servidor: ServeInv) | 108 | fun insertServer(servidor: ServeInv) |
99 | 109 | ||
100 | @Query("SELECT * FROM $TABLA_SERV_INV ORDER BY SER_NUM") | 110 | @Query("SELECT * FROM $TABLA_SERV_INV ORDER BY SER_NUM") |
101 | suspend fun fetchAllServers(): List<ServeInv> | 111 | suspend fun fetchAllServers(): List<ServeInv> |
102 | 112 | ||
103 | @Query("DELETE FROM $TABLA_SERV_INV WHERE SER_DESC LIKE :description AND SER_DIR LIKE :dir") | 113 | @Query("DELETE FROM $TABLA_SERV_INV WHERE SER_DESC LIKE :description AND SER_DIR LIKE :dir") |
104 | suspend fun deleteServer(description: String, dir: String) | 114 | suspend fun deleteServer(description: String, dir: String) |
105 | 115 | ||
106 | @Query("SELECT SER_NUM FROM $TABLA_SERV_INV ORDER BY SER_NUM DESC") | 116 | @Query("SELECT SER_NUM FROM $TABLA_SERV_INV ORDER BY SER_NUM DESC") |
107 | suspend fun findLastServer(): Int | 117 | suspend fun findLastServer(): Int |
108 | 118 | ||
109 | @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=0") | 119 | @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=0") |
110 | suspend fun UpdateServerPreInZero() | 120 | suspend fun UpdateServerPreInZero() |
111 | 121 | ||
112 | @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=1 WHERE SER_NUM = :numero") | 122 | @Query("UPDATE $TABLA_SERV_INV SET SER_PRE=1 WHERE SER_NUM = :numero") |
113 | suspend fun UpdateServerPre(numero: Int) | 123 | suspend fun UpdateServerPre(numero: Int) |
114 | 124 | ||
115 | @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_PRE= 1") | 125 | @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_PRE= 1") |
116 | suspend fun fetchServerPreOne(): ServeInv | 126 | suspend fun fetchServerPreOne(): ServeInv |
117 | 127 | ||
118 | @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_NUM = :numero") | 128 | @Query("SELECT * FROM $TABLA_SERV_INV WHERE SER_NUM = :numero") |
119 | suspend fun fetchServer(numero: Int): ServeInv | 129 | suspend fun fetchServer(numero: Int): ServeInv |
120 | } | 130 | } |
121 | 131 | ||
122 | 132 | ||
123 | 133 | ||
124 | @Dao | 134 | @Dao |
125 | interface InvHeadSecDAO { | 135 | interface InvHeadSecDAO { |
126 | @Insert(onConflict = OnConflictStrategy.REPLACE) | 136 | @Insert(onConflict = OnConflictStrategy.REPLACE) |
127 | fun insertInvHeadSec(Inventario: InvHeadSec) | 137 | fun insertInvHeadSec(Inventario: InvHeadSec) |
128 | 138 | ||
129 | @Query("DELETE FROM $TABLA_INV_SEC_H WHERE INV_NUM = :inven") | 139 | @Query("DELETE FROM $TABLA_INV_SEC_H WHERE INV_NUM = :inven") |
130 | suspend fun deleteAllInvHeadSec(inven: Int) | 140 | suspend fun deleteAllInvHeadSec(inven: Int) |
131 | 141 | ||
132 | @Query("SELECT * FROM $TABLA_INV_SEC_H ORDER BY INV_NUM") | 142 | @Query("SELECT * FROM $TABLA_INV_SEC_H ORDER BY INV_NUM") |
133 | suspend fun fetchAllInvSecHead(): List<InvHeadSec> | 143 | suspend fun fetchAllInvSecHead(): List<InvHeadSec> |
134 | 144 | ||
135 | @Query("UPDATE $TABLA_INV_SEC_H SET CONT=:cant WHERE INV_NUM=:inven") | 145 | @Query("UPDATE $TABLA_INV_SEC_H SET CONT=:cant WHERE INV_NUM=:inven") |
136 | suspend fun updateCantArtInvSecHead(inven: Int,cant: Int) | 146 | suspend fun updateCantArtInvSecHead(inven: Int,cant: Int) |
137 | 147 | ||
138 | @Query("DELETE FROM $TABLA_INV_SEC_H WHERE INV_NUM=:inven") | 148 | @Query("DELETE FROM $TABLA_INV_SEC_H WHERE INV_NUM=:inven") |
139 | suspend fun deleteinvSecHead(inven: String) | 149 | suspend fun deleteinvSecHead(inven: String) |
140 | 150 | ||
141 | @Query("SELECT * FROM $TABLA_INV_SEC_H WHERE INV_NUM=:inven") | 151 | @Query("SELECT * FROM $TABLA_INV_SEC_H WHERE INV_NUM=:inven") |
142 | suspend fun foundInvSecHead (inven: String): InvHeadSec | 152 | suspend fun foundInvSecHead (inven: String): InvHeadSec |
143 | 153 | ||
144 | @Query("UPDATE $TABLA_INV_SEC_H SET FET=:fecha, FEC=:fecha WHERE INV_NUM=:inven") | 154 | @Query("UPDATE $TABLA_INV_SEC_H SET FET=:fecha, FEC=:fecha WHERE INV_NUM=:inven") |
145 | suspend fun updateFETinvSecHead(inven: String, fecha:String) | 155 | suspend fun updateFETinvSecHead(inven: String, fecha:String) |
146 | 156 | ||
147 | @Query("UPDATE $TABLA_INV_SEC_H SET FEC=:fecha WHERE INV_NUM=:inven") | 157 | @Query("UPDATE $TABLA_INV_SEC_H SET FEC=:fecha WHERE INV_NUM=:inven") |
148 | suspend fun updateFECinvSecHead(inven: String, fecha:String) | 158 | suspend fun updateFECinvSecHead(inven: String, fecha:String) |
149 | } | 159 | } |
150 | 160 | ||
151 | @Dao | 161 | @Dao |
152 | interface InvBodySecDAO { | 162 | interface InvBodySecDAO { |
153 | @Insert() | 163 | @Insert() |
154 | suspend fun insertInvBodySec(invBody: InvBodySec?) | 164 | suspend fun insertInvBodySec(invBody: InvBodySec?) |
155 | 165 | ||
156 | @Query("DELETE FROM $TABLA_INV_SEC_B WHERE INV = :inven") | 166 | @Query("DELETE FROM $TABLA_INV_SEC_B WHERE INV = :inven") |
157 | suspend fun deleteAllInvBodySec(inven: Int) | 167 | suspend fun deleteAllInvBodySec(inven: Int) |
158 | 168 | ||
159 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven GROUP BY SEC, ART") | 169 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven GROUP BY SEC, ART") |
160 | suspend fun buscarInvSecBody(inven: Int): List<InvBodySec> | 170 | suspend fun buscarInvSecBody(inven: Int): List<InvBodySec> |
161 | 171 | ||
162 | @Query("UPDATE $TABLA_INV_SEC_B SET CON=:cant , FECTOM=:actFechaHora WHERE INV =:inven AND SEC=:sec AND ART=:cod") | 172 | @Query("UPDATE $TABLA_INV_SEC_B SET CON=:cant , FECTOM=:actFechaHora WHERE INV =:inven AND SEC=:sec AND ART=:cod") |
163 | suspend fun updateInvSecBody(inven: String, cant: Float, sec: Long, cod: Long, actFechaHora:String) | 173 | suspend fun updateInvSecBody(inven: String, cant: Float, sec: Long, cod: Long, actFechaHora:String) |
164 | 174 | ||
165 | @Query("DELETE FROM $TABLA_INV_SEC_B WHERE INV =:inven") | 175 | @Query("DELETE FROM $TABLA_INV_SEC_B WHERE INV =:inven") |
166 | suspend fun deleteInvSecBody(inven: String) | 176 | suspend fun deleteInvSecBody(inven: String) |
167 | 177 | ||
168 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven GROUP BY SEC, ART") | 178 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven GROUP BY SEC, ART") |
169 | suspend fun fetchInvSecBody(inven: String): List<InvBodySec> | 179 | suspend fun fetchInvSecBody(inven: String): List<InvBodySec> |
170 | 180 | ||
171 | @Query("UPDATE $TABLA_INV_SEC_B SET FECTOM=:fecha, FECTOMFIN=:fecha WHERE INV =:inven") | 181 | @Query("UPDATE $TABLA_INV_SEC_B SET FECTOM=:fecha, FECTOMFIN=:fecha WHERE INV =:inven") |
172 | suspend fun updateFECTOMyFECTOMFINinvSecBody(inven: String, fecha:String) | 182 | suspend fun updateFECTOMyFECTOMFINinvSecBody(inven: String, fecha:String) |
173 | 183 | ||
174 | @Query("UPDATE $TABLA_INV_SEC_B SET CON=:cant ,FECTOMFIN=:actFechaHora WHERE INV =:inven AND SEC=:sec AND ART=:cod") | 184 | @Query("UPDATE $TABLA_INV_SEC_B SET CON=:cant ,FECTOMFIN=:actFechaHora WHERE INV =:inven AND SEC=:sec AND ART=:cod") |
175 | suspend fun updateFECTOMFINinvSecBody(inven: String, cant: Float, sec: Long, cod: Long, actFechaHora:String) | 185 | suspend fun updateFECTOMFINinvSecBody(inven: String, cant: Float, sec: Long, cod: Long, actFechaHora:String) |
176 | 186 | ||
177 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven ") | 187 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven ") |
178 | suspend fun verificoExisteInvSec(inven: Int): List<InvBodySec> | 188 | suspend fun verificoExisteInvSec(inven: Int): List<InvBodySec> |
179 | 189 | ||
180 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven AND SEC=:sec AND ART=:cod") | 190 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven AND SEC=:sec AND ART=:cod") |
181 | suspend fun fetchArticuloByCodSec(inven: String, sec: String, cod: String):InvBodySec | 191 | suspend fun fetchArticuloByCodSec(inven: String, sec: String, cod: String):InvBodySec |
182 | 192 | ||
183 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven GROUP BY SEC, ART") | 193 | @Query("SELECT * FROM $TABLA_INV_SEC_B WHERE INV =:inven GROUP BY SEC, ART") |
184 | suspend fun fetchInvSecBodyGroup(inven: String): List<InvBodySec> | 194 | suspend fun fetchInvSecBodyGroup(inven: String): List<InvBodySec> |
185 | 195 | ||
186 | 196 | ||
187 | } | 197 | } |
188 | 198 |
app/src/main/java/com/focasoftware/deboinventariov20/UI/Utils/Utils.kt
1 | package com.focasoftware.deboinventariov20.UI.Utils | 1 | package com.focasoftware.deboinventariov20.UI.Utils |
2 | 2 | ||
3 | import android.app.Activity | 3 | import android.app.Activity |
4 | import android.app.AlertDialog | 4 | import android.app.AlertDialog |
5 | import android.app.Dialog | 5 | import android.app.Dialog |
6 | import android.content.Context | 6 | import android.content.Context |
7 | import android.content.Intent | 7 | import android.content.Intent |
8 | import android.os.Bundle | 8 | import android.os.Bundle |
9 | import android.provider.Settings | 9 | import android.provider.Settings |
10 | import android.view.LayoutInflater | 10 | import android.view.LayoutInflater |
11 | import android.view.View | 11 | import android.view.View |
12 | import android.view.WindowManager | 12 | import android.view.WindowManager |
13 | import android.view.inputmethod.InputMethodManager | 13 | import android.view.inputmethod.InputMethodManager |
14 | import androidx.core.content.ContextCompat.getSystemService | 14 | import androidx.core.content.ContextCompat.getSystemService |
15 | import androidx.fragment.app.DialogFragment | 15 | import androidx.fragment.app.DialogFragment |
16 | import androidx.fragment.app.FragmentActivity | 16 | import androidx.fragment.app.FragmentActivity |
17 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 17 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
18 | import com.focasoftware.deboinventariov20.Model.ServeInv | 18 | import com.focasoftware.deboinventariov20.Model.ServeInv |
19 | import com.focasoftware.deboinventariov20.R | 19 | import com.focasoftware.deboinventariov20.R |
20 | import com.focasoftware.deboinventariov20.UI.inventario.InventarioFragment | 20 | import com.focasoftware.deboinventariov20.UI.inventario.InventarioFragment |
21 | import kotlinx.android.synthetic.main.fragment_inventario.* | 21 | import kotlinx.android.synthetic.main.fragment_inventario.* |
22 | import kotlinx.android.synthetic.main.solicitar_fecha.view.* | 22 | import kotlinx.android.synthetic.main.solicitar_fecha.view.* |
23 | import kotlinx.coroutines.Dispatchers | 23 | import kotlinx.coroutines.Dispatchers |
24 | import kotlinx.coroutines.GlobalScope | 24 | import kotlinx.coroutines.GlobalScope |
25 | import kotlinx.coroutines.async | 25 | import kotlinx.coroutines.async |
26 | import java.io.IOException | 26 | import java.io.IOException |
27 | import java.net.UnknownHostException | 27 | import java.net.UnknownHostException |
28 | import java.time.LocalDateTime | 28 | import java.time.LocalDateTime |
29 | import java.time.format.DateTimeFormatter | 29 | import java.time.format.DateTimeFormatter |
30 | 30 | ||
31 | 31 | ||
32 | private var serverPre: ServeInv? = null | 32 | private var serverPre: ServeInv? = null |
33 | 33 | ||
34 | fun modificarCantidadEnCabecera(inventarioActual: Int, b: Boolean, context: Context) { | 34 | fun modificarCantidadEnCabecera(inventarioActual: Int, b: Boolean, context: Context) { |
35 | GlobalScope.async(Dispatchers.IO) { | 35 | GlobalScope.async(Dispatchers.IO) { |
36 | var cantProductos = 0 | 36 | var cantProductos = 0 |
37 | cantProductos = | 37 | cantProductos = |
38 | AppDb.getAppDb(context)!!.InvHeadDAO()!!.consultaCantidadInvH(inventarioActual) | 38 | AppDb.getAppDb(context)!!.InvHeadDAO()!!.consultaCantidadInvH(inventarioActual) |
39 | if (b) { | 39 | if (b) { |
40 | AppDb.getAppDb(context)!!.InvHeadDAO()!! | 40 | AppDb.getAppDb(context)!!.InvHeadDAO()!! |
41 | .updateInvCantHead(inventarioActual, cantProductos + 1) | 41 | .updateInvCantHead(inventarioActual, cantProductos + 1) |
42 | } else { | 42 | } else { |
43 | AppDb.getAppDb(context)!!.InvHeadDAO()!! | 43 | AppDb.getAppDb(context)!!.InvHeadDAO()!! |
44 | .updateInvCantHead(inventarioActual, cantProductos - 1) | 44 | .updateInvCantHead(inventarioActual, cantProductos - 1) |
45 | } | 45 | } |
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | open class AlertDialogBorrarInv : DialogFragment() { | 49 | open class AlertDialogBorrarInv : DialogFragment() { |
50 | 50 | ||
51 | interface OnBorrarInvClickListener { | 51 | interface OnBorrarInvClickListener { |
52 | fun onPositiveClick() | 52 | fun onPositiveClick() |
53 | fun onCancelClick() | 53 | fun onCancelClick() |
54 | } | 54 | } |
55 | 55 | ||
56 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 56 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
57 | return activity?.let { | 57 | return activity?.let { |
58 | val title = "Borrar Inventario" | 58 | val title = "Borrar Inventario" |
59 | val content = "¿Seguro que desea Borrar el inventario?" | 59 | val content = "¿Seguro que desea Borrar el inventario?" |
60 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 60 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
61 | builder.setTitle(title).setMessage(content) | 61 | builder.setTitle(title).setMessage(content) |
62 | 62 | ||
63 | .setPositiveButton(android.R.string.ok) { _, _ -> | 63 | .setPositiveButton(android.R.string.ok) { _, _ -> |
64 | val listener = activity as OnBorrarInvClickListener? | 64 | val listener = activity as OnBorrarInvClickListener? |
65 | listener!!.onPositiveClick() | 65 | listener!!.onPositiveClick() |
66 | } | 66 | } |
67 | .setNegativeButton(android.R.string.cancel) { _, _ -> | 67 | .setNegativeButton(android.R.string.cancel) { _, _ -> |
68 | val listener = activity as OnBorrarInvClickListener? | 68 | val listener = activity as OnBorrarInvClickListener? |
69 | listener!!.onCancelClick() | 69 | listener!!.onCancelClick() |
70 | } | 70 | } |
71 | return builder.create() | 71 | return builder.create() |
72 | } ?: throw IllegalStateException("Activity cannot be null") | 72 | } ?: throw IllegalStateException("Activity cannot be null") |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | class NoEncontradoSimple : DialogFragment() { | 76 | class NoEncontradoSimple : DialogFragment() { |
77 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 77 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
78 | return activity?.let { | 78 | return activity?.let { |
79 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 79 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
80 | .setCancelable(true) | 80 | .setCancelable(true) |
81 | 81 | ||
82 | builder.show() | 82 | builder.show() |
83 | val title = "" | 83 | val title = "" |
84 | val content = "¡El producto buscado NO fue encontrado!" | 84 | val content = "¡El producto buscado NO fue encontrado!" |
85 | 85 | ||
86 | builder.setTitle(title).setMessage(content) | 86 | builder.setTitle(title).setMessage(content) |
87 | .setPositiveButton(android.R.string.ok) { _, _ -> | 87 | .setPositiveButton(android.R.string.ok) { _, _ -> |
88 | 88 | ||
89 | } | 89 | } |
90 | return builder.create() | 90 | return builder.create() |
91 | } ?: throw IllegalStateException("Activity cannot be null") | 91 | } ?: throw IllegalStateException("Activity cannot be null") |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | class NoServerConf : DialogFragment() { | 95 | class NoServerConf : DialogFragment() { |
96 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 96 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
97 | return activity?.let { | 97 | return activity?.let { |
98 | val title = "" | 98 | val title = "" |
99 | val content = "¡Antes de importar debe configurar un servidor!" | 99 | val content = "¡Antes de importar debe configurar un servidor!" |
100 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 100 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
101 | builder.setTitle(title).setMessage(content) | 101 | builder.setTitle(title).setMessage(content) |
102 | .setPositiveButton(android.R.string.ok) { _, _ -> | 102 | .setPositiveButton(android.R.string.ok) { _, _ -> |
103 | activity?.onBackPressed() | 103 | activity?.onBackPressed() |
104 | } | 104 | } |
105 | 105 | ||
106 | return builder.create() | 106 | return builder.create() |
107 | } ?: throw IllegalStateException("Activity cannot be null") | 107 | } ?: throw IllegalStateException("Activity cannot be null") |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | fun isConnectedToThisServer(host: String): Boolean { | 111 | fun isConnectedToThisServer(host: String): Boolean { |
112 | 112 | ||
113 | val runtime = Runtime.getRuntime() | 113 | val runtime = Runtime.getRuntime() |
114 | try { | 114 | try { |
115 | val ipProcess = runtime.exec("/system/bin/ping -c 1 $host") | 115 | val ipProcess = runtime.exec("/system/bin/ping -c 1 $host") |
116 | val exitValue = ipProcess.waitFor() | 116 | val exitValue = ipProcess.waitFor() |
117 | ipProcess.destroy() | 117 | ipProcess.destroy() |
118 | return exitValue == 0 | 118 | return exitValue == 0 |
119 | } catch (e: UnknownHostException) { | 119 | } catch (e: UnknownHostException) { |
120 | e.printStackTrace() | 120 | e.printStackTrace() |
121 | } catch (e: IOException) { | 121 | } catch (e: IOException) { |
122 | e.printStackTrace() | 122 | e.printStackTrace() |
123 | } catch (e: InterruptedException) { | 123 | } catch (e: InterruptedException) { |
124 | e.printStackTrace() | 124 | e.printStackTrace() |
125 | } | 125 | } |
126 | 126 | ||
127 | return false | 127 | return false |
128 | } | 128 | } |
129 | 129 | ||
130 | class ServerValido : DialogFragment() { | 130 | class ServerValido : DialogFragment() { |
131 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 131 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
132 | return activity?.let { | 132 | return activity?.let { |
133 | val title = "" | 133 | val title = "" |
134 | val content = "¡La IP del servidor es correcta!" | 134 | val content = "¡La IP del servidor es correcta!" |
135 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 135 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
136 | builder.setTitle(title).setMessage(content) | 136 | builder.setTitle(title).setMessage(content) |
137 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 137 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
138 | return builder.create() | 138 | return builder.create() |
139 | } ?: throw IllegalStateException("Activity cannot be null") | 139 | } ?: throw IllegalStateException("Activity cannot be null") |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | class ServerNoValido : DialogFragment() { | 143 | class ServerNoValido : DialogFragment() { |
144 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 144 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
145 | return activity?.let { | 145 | return activity?.let { |
146 | val title = "" | 146 | val title = "" |
147 | val content = "¡La IP del servidor es Incorrecta! Verfique en la carga de Servidores." | 147 | val content = "¡La IP del servidor es Incorrecta! Verfique en la carga de Servidores." |
148 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 148 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
149 | builder.setTitle(title).setMessage(content) | 149 | builder.setTitle(title).setMessage(content) |
150 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 150 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
151 | return builder.create() | 151 | return builder.create() |
152 | } ?: throw IllegalStateException("Activity cannot be null") | 152 | } ?: throw IllegalStateException("Activity cannot be null") |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | class ServerNoConf : DialogFragment() { | 156 | class ServerNoConf : DialogFragment() { |
157 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 157 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
158 | return activity?.let { | 158 | return activity?.let { |
159 | val title = "Servidor no Valido" | 159 | val title = "Servidor no Valido" |
160 | val content = "!Debe configurar el Servidor en Configuraciones¡" | 160 | val content = "!Debe configurar el Servidor en Configuraciones¡" |
161 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 161 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
162 | builder.setTitle(title).setMessage(content) | 162 | builder.setTitle(title).setMessage(content) |
163 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 163 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
164 | return builder.create() | 164 | return builder.create() |
165 | } ?: throw IllegalStateException("Activity cannot be null") | 165 | } ?: throw IllegalStateException("Activity cannot be null") |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | class ExportacionExitosa : DialogFragment() { | 169 | class ExportacionExitosa : DialogFragment() { |
170 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 170 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
171 | return activity?.let { | 171 | return activity?.let { |
172 | val title = "Exportación de Inventarios" | 172 | val title = "Exportación de Inventarios" |
173 | val content = "!La exportacion del inventario se realizo exitosamente¡" | 173 | val content = "!La exportacion del inventario se realizo exitosamente¡" |
174 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 174 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
175 | builder.setTitle(title).setMessage(content) | 175 | builder.setTitle(title).setMessage(content) |
176 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 176 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
177 | return builder.create() | 177 | return builder.create() |
178 | } ?: throw IllegalStateException("Activity cannot be null") | 178 | } ?: throw IllegalStateException("Activity cannot be null") |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | class ExportacionFracasada : DialogFragment() { | 182 | class ExportacionFracasada : DialogFragment() { |
183 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 183 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
184 | return activity?.let { | 184 | return activity?.let { |
185 | val title = "Exportación de Inventarios" | 185 | val title = "Exportación de Inventarios" |
186 | val content = "!No se pudo realizar la expotación¡" | 186 | val content = "!No se pudo realizar la expotación¡" |
187 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 187 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
188 | builder.setTitle(title).setMessage(content) | 188 | builder.setTitle(title).setMessage(content) |
189 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 189 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
190 | return builder.create() | 190 | return builder.create() |
191 | } ?: throw IllegalStateException("Activity cannot be null") | 191 | } ?: throw IllegalStateException("Activity cannot be null") |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | fun obtenerFechaActualFormatoFoca(): String { | 195 | fun obtenerFechaActualFormatoFoca(): String { |
196 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | 196 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD |
197 | val current = LocalDateTime.now() | 197 | val current = LocalDateTime.now() |
198 | val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") | 198 | val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") |
199 | val dFechaHora = current.format(formatter) | 199 | val dFechaHora = current.format(formatter) |
200 | return dFechaHora.toString() | 200 | return dFechaHora.toString() |
201 | } | 201 | } |
202 | fun obtenerFechaActual(): String { | 202 | fun obtenerFechaActual(): String { |
203 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | 203 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD |
204 | val current = LocalDateTime.now() | 204 | val current = LocalDateTime.now() |
205 | val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss") | 205 | val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss") |
206 | val dFechaHora = current.format(formatter) | 206 | val dFechaHora = current.format(formatter) |
207 | return dFechaHora.toString() | 207 | return dFechaHora.toString() |
208 | } | 208 | } |
209 | fun obtenerHoraActual(): String { | 209 | fun obtenerHoraActual(): String { |
210 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | 210 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD |
211 | val current = LocalDateTime.now() | 211 | val current = LocalDateTime.now() |
212 | val formatter = DateTimeFormatter.ofPattern("HHmmss") | 212 | val formatter = DateTimeFormatter.ofPattern("HHmmss") |
213 | val dFechaHora = current.format(formatter) | 213 | val dFechaHora = current.format(formatter) |
214 | return dFechaHora.toString() | 214 | return dFechaHora.toString() |
215 | } | 215 | } |
216 | 216 | ||
217 | fun obtenerDiaActual(): String { | 217 | fun obtenerDiaActual(): String { |
218 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD | 218 | //TODO OBTENGO FECHA Y HORA ACTUAL PARA LA CABECERA DEL INVENTARIO Y PARA CADA ITEM QUE SE INSERTA EN LA BD |
219 | val current = LocalDateTime.now() | 219 | val current = LocalDateTime.now() |
220 | val formatter = DateTimeFormatter.ofPattern("ddMMyyyy") | 220 | val formatter = DateTimeFormatter.ofPattern("ddMMyyyy") |
221 | val dFechaHora = current.format(formatter) | 221 | val dFechaHora = current.format(formatter) |
222 | return dFechaHora.toString() | 222 | return dFechaHora.toString() |
223 | } | 223 | } |
224 | class SelAreaInventarioVentas : DialogFragment() { | 224 | class SelAreaInventarioVentas : DialogFragment() { |
225 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 225 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
226 | return activity?.let { | 226 | return activity?.let { |
227 | val title = "Inventarios de Ventas" | 227 | val title = "Inventarios de Ventas" |
228 | val content = "!En busqueda de articulos no estaran disponibles los articulos de DEPOSITO¡" | 228 | val content = "!En busqueda de articulos estaran disponibles los articulos de VENTAS y DEPOSITO¡" |
229 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 229 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
230 | builder.setTitle(title).setMessage(content) | 230 | builder.setTitle(title).setMessage(content) |
231 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 231 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
232 | return builder.create() | 232 | return builder.create() |
233 | } ?: throw IllegalStateException("Activity cannot be null") | 233 | } ?: throw IllegalStateException("Activity cannot be null") |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | class SelAreaInventarioDeposito : DialogFragment() { | 237 | class SelAreaInventarioDeposito : DialogFragment() { |
238 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 238 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
239 | return activity?.let { | 239 | return activity?.let { |
240 | val title = "Inventarios de Depositos" | 240 | val title = "Inventarios de Depositos" |
241 | val content = "!En busqueda de articulos no estaran disponibles los articulos de VENTAS¡" | 241 | val content = "!En busqueda de articulos estaran disponibles los articulos de DEPOSITO¡" |
242 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 242 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
243 | builder.setTitle(title).setMessage(content) | 243 | builder.setTitle(title).setMessage(content) |
244 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 244 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
245 | return builder.create() | 245 | return builder.create() |
246 | } ?: throw IllegalStateException("Activity cannot be null") | 246 | } ?: throw IllegalStateException("Activity cannot be null") |
247 | } | 247 | } |
248 | } | 248 | } |
249 | 249 | ||
250 | fun dialogoHoraServer(reqActivity: FragmentActivity, context: Context, fechaHoraDispositivo: String, fechaHoraServer: String) { | 250 | fun dialogoHoraServer(reqActivity: FragmentActivity, context: Context, fechaHoraDispositivo: String, fechaHoraServer: String) { |
251 | val mDialogView: View = LayoutInflater.from(context).inflate(R.layout.solicitar_fecha, null) | 251 | val mDialogView: View = LayoutInflater.from(context).inflate(R.layout.solicitar_fecha, null) |
252 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(false) | 252 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(false) |
253 | 253 | ||
254 | 254 | ||
255 | mDialogView.tvHoraDispositivo.text = fechaHoraDispositivo | 255 | mDialogView.tvHoraDispositivo.text = fechaHoraDispositivo |
256 | mDialogView.tvHoraServidor.text = fechaHoraServer | 256 | mDialogView.tvHoraServidor.text = fechaHoraServer |
257 | val mAlertDialog = mBuilder.show() | 257 | val mAlertDialog = mBuilder.show() |
258 | 258 | ||
259 | // mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 259 | // mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
260 | // mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 260 | // mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
261 | // | 261 | // |
262 | // val imm = reqActivity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager? | 262 | // val imm = reqActivity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager? |
263 | // imm!!.hideSoftInputFromWindow(reqActivity.currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 263 | // imm!!.hideSoftInputFromWindow(reqActivity.currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
264 | 264 | ||
265 | mDialogView.btnCambiarHora.setOnClickListener { | 265 | mDialogView.btnCambiarHora.setOnClickListener { |
266 | context.startActivity(Intent(Settings.ACTION_DATE_SETTINGS)) | 266 | context.startActivity(Intent(Settings.ACTION_DATE_SETTINGS)) |
267 | mAlertDialog.dismiss() | 267 | mAlertDialog.dismiss() |
268 | } | 268 | } |
269 | 269 | ||
270 | mDialogView.btnSalir.setOnClickListener { | 270 | mDialogView.btnSalir.setOnClickListener { |
271 | mAlertDialog.dismiss() | 271 | mAlertDialog.dismiss() |
272 | } | 272 | } |
273 | } | 273 | } |
274 | 274 | ||
275 | class InvSecImp : DialogFragment() { | 275 | class InvSecImp : DialogFragment() { |
276 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | 276 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { |
277 | return activity?.let { | 277 | return activity?.let { |
278 | val title = "Inventarios de Sectorizados" | 278 | val title = "Inventarios de Sectorizados" |
279 | val content = "!Inventario importado correctamente¡" | 279 | val content = "!Inventario importado correctamente¡" |
280 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) | 280 | val builder: AlertDialog.Builder = AlertDialog.Builder(requireActivity()) |
281 | builder.setTitle(title).setMessage(content) | 281 | builder.setTitle(title).setMessage(content) |
282 | .setPositiveButton(android.R.string.ok) { _, _ -> } | 282 | .setPositiveButton(android.R.string.ok) { _, _ -> } |
283 | return builder.create() | 283 | return builder.create() |
284 | } ?: throw IllegalStateException("Activity cannot be null") | 284 | } ?: throw IllegalStateException("Activity cannot be null") |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | suspend fun fetchServerPreOne(reqActivity: FragmentActivity): ServeInv? { | 288 | suspend fun fetchServerPreOne(reqActivity: FragmentActivity): ServeInv? { |
289 | return GlobalScope.async(Dispatchers.IO) { | 289 | return GlobalScope.async(Dispatchers.IO) { |
290 | return@async AppDb.getAppDb(reqActivity)!!.ServeInvDao()!!.fetchServerPreOne() | 290 | return@async AppDb.getAppDb(reqActivity)!!.ServeInvDao()!!.fetchServerPreOne() |
291 | }.await() | 291 | }.await() |
292 | } | 292 | } |
293 | 293 | ||
294 | //fun hideSoftKeyboard(reqActivity: FragmentActivity) { | 294 | //fun hideSoftKeyboard(reqActivity: FragmentActivity) { |
295 | // val imm = reqActivity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager? | 295 | // val imm = reqActivity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager? |
296 | // imm!!.hideSoftInputFromWindow(reqActivity.currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 296 | // imm!!.hideSoftInputFromWindow(reqActivity.currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
297 | // | 297 | // |
298 | // | 298 | // |
299 | //} | 299 | //} |
300 | fun Context.hideSoftKeyboard(view: View) { | 300 | fun Context.hideSoftKeyboard(view: View) { |
301 | val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager | 301 | val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager |
302 | inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) } | 302 | inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) } |
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.Context.INPUT_METHOD_SERVICE | 5 | import android.content.Context.INPUT_METHOD_SERVICE |
6 | import android.content.DialogInterface | 6 | import android.content.DialogInterface |
7 | import android.content.SharedPreferences | 7 | import android.content.SharedPreferences |
8 | import android.graphics.Canvas | 8 | import android.graphics.Canvas |
9 | import android.graphics.Color | 9 | import android.graphics.Color |
10 | import android.graphics.drawable.Drawable | 10 | import android.graphics.drawable.Drawable |
11 | import android.os.Bundle | 11 | import android.os.Bundle |
12 | import android.system.ErrnoException | 12 | import android.system.ErrnoException |
13 | import android.text.Editable | 13 | import android.text.Editable |
14 | import android.text.InputType.TYPE_CLASS_NUMBER | 14 | import android.text.InputType.TYPE_CLASS_NUMBER |
15 | import android.text.TextWatcher | 15 | import android.text.TextWatcher |
16 | import android.view.* | 16 | import android.view.* |
17 | import android.view.inputmethod.InputMethodManager | 17 | import android.view.inputmethod.InputMethodManager |
18 | import android.widget.EditText | 18 | import android.widget.EditText |
19 | import android.widget.TextView | 19 | import android.widget.TextView |
20 | import android.widget.Toast | 20 | import android.widget.Toast |
21 | import androidx.core.content.ContextCompat | 21 | import androidx.core.content.ContextCompat |
22 | import androidx.core.os.bundleOf | 22 | import androidx.core.os.bundleOf |
23 | import androidx.fragment.app.Fragment | 23 | import androidx.fragment.app.Fragment |
24 | import androidx.lifecycle.ViewModel | 24 | import androidx.lifecycle.ViewModel |
25 | import androidx.lifecycle.ViewModelProviders | 25 | import androidx.lifecycle.ViewModelProviders |
26 | import androidx.lifecycle.lifecycleScope | 26 | import androidx.lifecycle.lifecycleScope |
27 | import androidx.navigation.NavController | 27 | import androidx.navigation.NavController |
28 | import androidx.navigation.Navigation | 28 | import androidx.navigation.Navigation |
29 | import androidx.recyclerview.widget.ItemTouchHelper | 29 | import androidx.recyclerview.widget.ItemTouchHelper |
30 | import androidx.recyclerview.widget.LinearLayoutManager | 30 | import androidx.recyclerview.widget.LinearLayoutManager |
31 | import androidx.recyclerview.widget.RecyclerView | 31 | import androidx.recyclerview.widget.RecyclerView |
32 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb | 32 | import com.focasoftware.deboinventariov20.DB.DataBase.AppDb |
33 | import com.focasoftware.deboinventariov20.Model.* | 33 | import com.focasoftware.deboinventariov20.Model.* |
34 | import com.focasoftware.deboinventariov20.R | 34 | import com.focasoftware.deboinventariov20.R |
35 | import com.focasoftware.deboinventariov20.UI.MainActivity | 35 | import com.focasoftware.deboinventariov20.UI.MainActivity |
36 | import com.focasoftware.deboinventariov20.UI.Utils.* | 36 | import com.focasoftware.deboinventariov20.UI.Utils.* |
37 | import com.focasoftware.deboinventariov20.UI.inventario.viewModel.InventarioViewModel | 37 | import com.focasoftware.deboinventariov20.UI.inventario.viewModel.InventarioViewModel |
38 | import kotlinx.android.synthetic.main.fragment_inventario.* | 38 | import kotlinx.android.synthetic.main.fragment_inventario.* |
39 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* | 39 | import kotlinx.android.synthetic.main.ingresar_cantidad.view.* |
40 | import kotlinx.android.synthetic.main.login_dialog.view.* | 40 | import kotlinx.android.synthetic.main.login_dialog.view.* |
41 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar | 41 | import kotlinx.android.synthetic.main.login_dialog.view.btnAceptar |
42 | import kotlinx.coroutines.* | 42 | import kotlinx.coroutines.* |
43 | import kotlinx.coroutines.Dispatchers.IO | 43 | import kotlinx.coroutines.Dispatchers.IO |
44 | import kotlinx.coroutines.Dispatchers.Main | 44 | import kotlinx.coroutines.Dispatchers.Main |
45 | import okhttp3.internal.http2.ErrorCode | 45 | import okhttp3.internal.http2.ErrorCode |
46 | import retrofit2.Call | 46 | import retrofit2.Call |
47 | import retrofit2.Callback | 47 | import retrofit2.Callback |
48 | import retrofit2.Response | 48 | import retrofit2.Response |
49 | import java.io.IOException | 49 | import java.io.IOException |
50 | import java.net.SocketTimeoutException | 50 | import java.net.SocketTimeoutException |
51 | import java.util.* | 51 | import java.util.* |
52 | import kotlin.collections.ArrayList | 52 | import kotlin.collections.ArrayList |
53 | 53 | ||
54 | private lateinit var sharedPreferences: SharedPreferences | 54 | private lateinit var sharedPreferences: SharedPreferences |
55 | private var iArea: Boolean = false | 55 | private var iArea: Boolean = false |
56 | private lateinit var invHead: InvHead | 56 | private lateinit var invHead: InvHead |
57 | private lateinit var viewAdapter: RecyclerView.Adapter<*> | 57 | private lateinit var viewAdapter: RecyclerView.Adapter<*> |
58 | private lateinit var viewManager: RecyclerView.LayoutManager | 58 | private lateinit var viewManager: RecyclerView.LayoutManager |
59 | private lateinit var sChangeUpper: String | 59 | private lateinit var sChangeUpper: String |
60 | private var listArticulos = ArrayList<ItemsRecycler>() | 60 | private var listArticulos = ArrayList<ItemsRecycler>() |
61 | private lateinit var navController: NavController | 61 | private lateinit var navController: NavController |
62 | private var iEstado = 0 | 62 | private var iEstado = 0 |
63 | private var iBusquedaPor = 0 | 63 | private var iBusquedaPor = 0 |
64 | private var fCant = 0F | 64 | private var fCant = 0F |
65 | private var bFirst = false | 65 | private var bFirst = false |
66 | private lateinit var deleteIcon: Drawable | 66 | private lateinit var deleteIcon: Drawable |
67 | lateinit var inventarioViewModel: ViewModel | 67 | lateinit var inventarioViewModel: ViewModel |
68 | private var codBarBalanza = "" | 68 | private var codBarBalanza = "" |
69 | private var cantEnteraBalanza = 0 | 69 | private var cantEnteraBalanza = 0 |
70 | private var cantDecimalBalanza = 0 | 70 | private var cantDecimalBalanza = 0 |
71 | private var EsBalanza = false | 71 | private var EsBalanza = false |
72 | 72 | ||
73 | class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickListener { | 73 | class InventarioFragment : Fragment(), ProductosListAdapter.OnImageDotsClickListener { |
74 | lateinit var mDialogView: View | 74 | lateinit var mDialogView: View |
75 | private lateinit var rcInventarios: RecyclerView | 75 | private lateinit var rcInventarios: RecyclerView |
76 | private val job: Job = Job() | 76 | private val job: Job = Job() |
77 | private val fragmentScopeInvFrag = CoroutineScope(IO + job) | 77 | private val fragmentScopeInvFrag = CoroutineScope(IO + job) |
78 | private var serverBajada: ServeInv? = null | 78 | private var serverBajada: ServeInv? = null |
79 | 79 | ||
80 | override fun onDestroy() { | 80 | override fun onDestroy() { |
81 | super.onDestroy() | 81 | super.onDestroy() |
82 | fragmentScopeInvFrag.cancel() | 82 | fragmentScopeInvFrag.cancel() |
83 | } | 83 | } |
84 | 84 | ||
85 | override fun onCreate(savedInstanceState: Bundle?) { | 85 | override fun onCreate(savedInstanceState: Bundle?) { |
86 | super.onCreate(savedInstanceState) | 86 | super.onCreate(savedInstanceState) |
87 | listArticulos.clear() | 87 | listArticulos.clear() |
88 | inventarioViewModel = ViewModelProviders.of(this).get(InventarioViewModel::class.java) | 88 | inventarioViewModel = ViewModelProviders.of(this).get(InventarioViewModel::class.java) |
89 | 89 | ||
90 | sharedPreferences = (activity as MainActivity).getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) | 90 | sharedPreferences = (activity as MainActivity).getSharedPreferences("SP_INFO", Context.MODE_PRIVATE) |
91 | if (sharedPreferences.contains("Inventario")) if (sharedPreferences.getString("Inventario", "").toString() != "-1") { | 91 | if (sharedPreferences.contains("Inventario")) if (sharedPreferences.getString("Inventario", "").toString() != "-1") { |
92 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = sharedPreferences.getString("Inventario", "").toString().toInt() | 92 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = sharedPreferences.getString("Inventario", "").toString().toInt() |
93 | val editor = sharedPreferences.edit() | 93 | val editor = sharedPreferences.edit() |
94 | editor?.putString("Inventario", "-1") | 94 | editor?.putString("Inventario", "-1") |
95 | editor?.apply() | 95 | editor?.apply() |
96 | editor.commit() | 96 | editor.commit() |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | 100 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
101 | val v = inflater.inflate(R.layout.fragment_inventario, container, false) | 101 | val v = inflater.inflate(R.layout.fragment_inventario, container, false) |
102 | 102 | ||
103 | 103 | ||
104 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) | 104 | val tCodigoBarras = v.findViewById<EditText>(R.id.etCodigoBarras) |
105 | rcInventarios = v.findViewById(R.id.rcInventarios) | 105 | rcInventarios = v.findViewById(R.id.rcInventarios) |
106 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) | 106 | val tvTitulo = v.findViewById<TextView>(R.id.tvTitulo) |
107 | val descArea: String = if (!SerchArea()) "Ventas" else "Deposito" | 107 | val descArea: String = if (!SerchArea()) "Ventas" else "Deposito" |
108 | 108 | ||
109 | if ((inventarioViewModel as InventarioViewModel).InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO | 109 | if ((inventarioViewModel as InventarioViewModel).InventarioNuevo == 0) {// TODO: SI INVETNARIO NUEVO |
110 | GlobalScope.launch(Dispatchers.Main) { | 110 | GlobalScope.launch(Dispatchers.Main) { |
111 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO | 111 | //TODO: BUSCO EL ULTIMO INVENTARIO EN LA BD PARA PODER CREAR EL PROXIMO |
112 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = AppDb.getAppDb((activity as MainActivity))?.InvHeadDAO()?.findLastInv()?.plus(1) ?: 1 | 112 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = AppDb.getAppDb((activity as MainActivity))?.InvHeadDAO()?.findLastInv()?.plus(1) ?: 1 |
113 | //TODO: CREAMOS EL INVENTARIO EN LA CABECERA DEL INVENTARIO | 113 | //TODO: CREAMOS EL INVENTARIO EN LA CABECERA DEL INVENTARIO |
114 | invHead = InvHead( | 114 | invHead = InvHead( |
115 | (inventarioViewModel as InventarioViewModel).InventarioNuevo, | 115 | (inventarioViewModel as InventarioViewModel).InventarioNuevo, |
116 | if (!SerchArea()) "Ventas" else "Deposito", | 116 | if (!SerchArea()) "Ventas" else "Deposito", |
117 | 1, | 117 | 1, |
118 | obtenerFechaActual(), | 118 | obtenerFechaActual(), |
119 | obtenerFechaActual(), | 119 | obtenerFechaActual(), |
120 | 0L, | 120 | 0L, |
121 | SerchArea(), | 121 | SerchArea(), |
122 | AjusteProductos(), | 122 | AjusteProductos(), |
123 | ProdNoCont() | 123 | ProdNoCont() |
124 | ) | 124 | ) |
125 | AppDb.getAppDb((activity as MainActivity))!!.InvHeadDAO()!!.insertInvHead(invHead) | 125 | AppDb.getAppDb((activity as MainActivity))!!.InvHeadDAO()!!.insertInvHead(invHead) |
126 | 126 | ||
127 | tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo} " + descArea | 127 | tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo} " + descArea |
128 | } | 128 | } |
129 | } else {// TODO (SI VENGO DE FRAGMENT DESCRIPCION) | 129 | } else {// TODO (SI VENGO DE FRAGMENT DESCRIPCION) |
130 | listArticulos.clear() | 130 | listArticulos.clear() |
131 | cargarDeBdInventario((inventarioViewModel as InventarioViewModel).InventarioNuevo) | 131 | GlobalScope.launch(Main) { |
132 | tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo} " + descArea | 132 | val depositoVentas = if (SerchAreaInventario()) "Deposito" else "Ventas" |
133 | } | 133 | tvTitulo.text = "Inventario " + " # ${(inventarioViewModel as InventarioViewModel).InventarioNuevo} " + depositoVentas |
134 | 134 | ||
135 | cargarDeBdInventario((inventarioViewModel as InventarioViewModel).InventarioNuevo) | ||
136 | } | ||
137 | } | ||
135 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> | 138 | tCodigoBarras.setOnKeyListener { _, keyCode, keyEvent -> |
136 | if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_UP) { | 139 | if (keyCode == KeyEvent.KEYCODE_ENTER && keyEvent.action == KeyEvent.ACTION_UP) { |
137 | sChangeUpper = tCodigoBarras.text.toString() | 140 | sChangeUpper = tCodigoBarras.text.toString() |
138 | 141 | ||
139 | // val esnumero = try { | 142 | // val esnumero = try { |
140 | // val retorno = java.lang.Double.valueOf(sChangeUpper) | 143 | // val retorno = java.lang.Double.valueOf(sChangeUpper) |
141 | // true | 144 | // true |
142 | // } catch (e: NumberFormatException) { | 145 | // } catch (e: NumberFormatException) { |
143 | // //retorno = 0.0 | 146 | // //retorno = 0.0 |
144 | // false | 147 | // false |
145 | // } | 148 | // } |
146 | // if (esnumero){} | 149 | // if (esnumero){} |
147 | var indiceDelArtEncontrado = 0 | 150 | var indiceDelArtEncontrado = 0 |
148 | 151 | ||
149 | if (tCodigoBarras.text.isNullOrBlank()) { | 152 | if (tCodigoBarras.text.isNullOrBlank()) { |
150 | tCodigoBarras.error = "No puede estar vacio" | 153 | tCodigoBarras.error = "No puede estar vacio" |
151 | tCodigoBarras.requestFocus() | 154 | tCodigoBarras.requestFocus() |
152 | tCodigoBarras.hint = "No puede estar vacio" | 155 | tCodigoBarras.hint = "No puede estar vacio" |
153 | } else if (tCodigoBarras.text.toString().length < 4 && iEstado == 2) { | 156 | } else if (tCodigoBarras.text.toString().length < 4 && iEstado == 2) { |
154 | tCodigoBarras.error = "Minimo 4 caracteres" | 157 | tCodigoBarras.error = "Minimo 4 caracteres" |
155 | tCodigoBarras.requestFocus() | 158 | tCodigoBarras.requestFocus() |
156 | tCodigoBarras.hint = "4 Minimo" | 159 | tCodigoBarras.hint = "4 Minimo" |
157 | 160 | ||
158 | } else { | 161 | } else { |
159 | tCodigoBarras.hint = "" | 162 | tCodigoBarras.hint = "" |
160 | //TODO COMIENZA LA BUSQUEDA POR CODIGO DE BARRAS | 163 | //TODO COMIENZA LA BUSQUEDA POR CODIGO DE BARRAS |
161 | when (iBusquedaPor) { | 164 | when (iBusquedaPor) { |
162 | 0 -> { | 165 | 0 -> { |
163 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER | 166 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
164 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 167 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
165 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 168 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
166 | 169 | ||
167 | if (sharedPreferences.contains("cbHabiLectura")) { | 170 | if (sharedPreferences.contains("cbHabiLectura")) { |
168 | if (sharedPreferences.getString("cbHabiLectura", "").toString() == "1") { | 171 | if (sharedPreferences.getString("cbHabiLectura", "").toString() == "1") { |
169 | if (sChangeUpper.length == 13) | 172 | if (sChangeUpper.length == 13) |
170 | if (sChangeUpper.substring(0, 2) == "20" && sChangeUpper.substring(12, 13) == "2") { | 173 | if (sChangeUpper.substring(0, 2) == "20" && sChangeUpper.substring(12, 13) == "2") { |
171 | EsBalanza=true | 174 | EsBalanza=true |
172 | codBarBalanza = sChangeUpper.substring(2,7).toString() | 175 | codBarBalanza = sChangeUpper.substring(2,7).toString() |
173 | cantEnteraBalanza = sChangeUpper.substring(7, 9).toInt() | 176 | cantEnteraBalanza = sChangeUpper.substring(7, 9).toInt() |
174 | cantDecimalBalanza = sChangeUpper.substring(9, 12).toInt() | 177 | cantDecimalBalanza = sChangeUpper.substring(9, 12).toInt() |
175 | } | 178 | } |
176 | } | 179 | } |
177 | } | 180 | } |
178 | GlobalScope.launch(Main) { | 181 | GlobalScope.launch(Main) { |
179 | if (EsBalanza) sChangeUpper=codBarBalanza | 182 | if (EsBalanza) sChangeUpper=codBarBalanza |
180 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 0)//TODO Si encuentra el articulo en el RV devuelve el indice | 183 | indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 0)//TODO Si encuentra el articulo en el RV devuelve el indice |
181 | //TODO (Si no lo encuentra devuelve -1) | 184 | //TODO (Si no lo encuentra devuelve -1) |
182 | if (indiceDelArtEncontrado != -1) { | 185 | if (indiceDelArtEncontrado != -1) { |
183 | if (EsBalanza) { | 186 | if (EsBalanza) { |
184 | // //TODO SI ES BALANZA NO HAGO NADA | 187 | // //TODO SI ES BALANZA NO HAGO NADA |
185 | 188 | ||
186 | }else{ | 189 | }else{ |
187 | if (swSumaUno!!.isChecked) { | 190 | if (swSumaUno!!.isChecked) { |
188 | //TODO ACTUALIZO LA CANTIDAD EN LA BD | 191 | //TODO ACTUALIZO LA CANTIDAD EN LA BD |
189 | updateCantidad( | 192 | updateCantidad( |
190 | listArticulos[indiceDelArtEncontrado].sector.toString(), | 193 | listArticulos[indiceDelArtEncontrado].sector.toString(), |
191 | listArticulos[indiceDelArtEncontrado].codigo.toString(), | 194 | listArticulos[indiceDelArtEncontrado].codigo.toString(), |
192 | listArticulos[indiceDelArtEncontrado].cantTomada + 1 | 195 | listArticulos[indiceDelArtEncontrado].cantTomada + 1 |
193 | ) | 196 | ) |
194 | //TODO ACTUALIZO LA CANTIDAD EN EL RV | 197 | //TODO ACTUALIZO LA CANTIDAD EN EL RV |
195 | listArticulos[indiceDelArtEncontrado].cantTomada = listArticulos[indiceDelArtEncontrado].cantTomada + 1 | 198 | listArticulos[indiceDelArtEncontrado].cantTomada = listArticulos[indiceDelArtEncontrado].cantTomada + 1 |
196 | viewAdapter.notifyDataSetChanged() | 199 | viewAdapter.notifyDataSetChanged() |
197 | 200 | ||
198 | } else { | 201 | } else { |
199 | dialogoSumaResta(requireContext(), indiceDelArtEncontrado, listArticulos[indiceDelArtEncontrado].univta, false) | 202 | dialogoSumaResta(requireContext(), indiceDelArtEncontrado, listArticulos[indiceDelArtEncontrado].univta, false) |
200 | } | 203 | } |
201 | } | 204 | } |
202 | } else if (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD | 205 | } else if (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD |
203 | //TODO BUSCO EN BASE DE DATOS | 206 | //TODO BUSCO EN BASE DE DATOS |
204 | val artEncontrado:Articles? = if (EsBalanza) { | 207 | val artEncontrado:Articles? = if (EsBalanza) { |
205 | buscarCBEnBD(codBarBalanza) | 208 | if (iArea){ buscarCBEnBD(codBarBalanza) |
209 | }else{ findArticuloByCodBarNoArea(codBarBalanza) } | ||
210 | |||
206 | }else{ | 211 | }else{ |
207 | buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 212 | if (iArea){ buscarCBEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) } |
213 | else{ findArticuloByCodBarNoArea(sChangeUpper.toUpperCase(Locale.ROOT)) } | ||
208 | } | 214 | } |
209 | continuarCargaCB(artEncontrado)//TODO SE MANDA CERO POR QUE ES UN ARTICULO ESCANEADO NUEVO PARA QUE SEA COMPATIBLE | 215 | continuarCargaCB(artEncontrado)//TODO SE MANDA CERO POR QUE ES UN ARTICULO ESCANEADO NUEVO PARA QUE SEA COMPATIBLE |
210 | } | 216 | } |
211 | etCodigoBarras.requestFocus() | 217 | etCodigoBarras.requestFocus() |
212 | tCodigoBarras.setText("") | 218 | tCodigoBarras.setText("") |
213 | tCodigoBarras.selectAll() | 219 | tCodigoBarras.selectAll() |
214 | } | 220 | } |
215 | return@setOnKeyListener true | 221 | return@setOnKeyListener true |
216 | 222 | ||
217 | } | 223 | } |
218 | 1 -> {//TODO: BUSQUEDA POR DESCRIPCION************************************************************************** | 224 | 1 -> {//TODO: BUSQUEDA POR DESCRIPCION************************************************************************** |
219 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER | 225 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
220 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 226 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
221 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 227 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
222 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 1) //TODO :Si encuentra el articulo en el RV devuelve el indice | 228 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 1) //TODO :Si encuentra el articulo en el RV devuelve el indice |
223 | // //TODO Si no lo encuentra devuelve -1 | 229 | // //TODO Si no lo encuentra devuelve -1 |
224 | // if (indiceDelArtEncontrado != -1) { | 230 | // if (indiceDelArtEncontrado != -1) { |
225 | //// if (swSumaUno!!.isChecked) { | 231 | //// if (swSumaUno!!.isChecked) { |
226 | //// fCant = 0F | 232 | //// fCant = 0F |
227 | //// fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 233 | //// fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
228 | //// fCant += 1F | 234 | //// fCant += 1F |
229 | //// listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 235 | //// listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
230 | //// viewAdapter.notifyDataSetChanged() | 236 | //// viewAdapter.notifyDataSetChanged() |
231 | //// } else { | 237 | //// } else { |
232 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 238 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
233 | // MaterialDialog(requireContext()).show { | 239 | // MaterialDialog(requireContext()).show { |
234 | // title(R.string.sTituloNueva) | 240 | // title(R.string.sTituloNueva) |
235 | // message(R.string.sCantidadNueva) | 241 | // message(R.string.sCantidadNueva) |
236 | // input { materialDialog, charSequence -> | 242 | // input { materialDialog, charSequence -> |
237 | // fCant = 0F | 243 | // fCant = 0F |
238 | // fCant = charSequence.toString().toFloat() | 244 | // fCant = charSequence.toString().toFloat() |
239 | // } | 245 | // } |
240 | // positiveButton(R.string.btnOk) { | 246 | // positiveButton(R.string.btnOk) { |
241 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 247 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
242 | // viewAdapter.notifyDataSetChanged() | 248 | // viewAdapter.notifyDataSetChanged() |
243 | // dismiss() | 249 | // dismiss() |
244 | // } | 250 | // } |
245 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 251 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
246 | //// } | 252 | //// } |
247 | // | 253 | // |
248 | // } else if | 254 | // } else if |
249 | // (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD | 255 | // (indiceDelArtEncontrado == -1) {// TODO: no lo encontro en el RV, lo va a buscar en al BD |
250 | GlobalScope.launch(Main) { | 256 | GlobalScope.launch(Main) { |
251 | val artEncontrado = buscarDescEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 257 | if (iArea){val artEncontrado = buscarDescEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
252 | continuarCargaDesc(artEncontrado as ArrayList<Articles>) | 258 | continuarCargaDesc(artEncontrado as ArrayList<Articles>)} |
259 | else{val artEncontrado = findArticuloByDescNoArea(sChangeUpper.toUpperCase(Locale.ROOT)) | ||
260 | continuarCargaDesc(artEncontrado as ArrayList<Articles>)} | ||
253 | } | 261 | } |
254 | 262 | ||
255 | ivCamara.setImageResource(R.drawable.codbar) | 263 | ivCamara.setImageResource(R.drawable.codbar) |
256 | etCodigoBarras.hint = "Busqueda por Código de Barras" | 264 | etCodigoBarras.hint = "Busqueda por Código de Barras" |
257 | swSumaUno.visibility = View.VISIBLE | 265 | swSumaUno.visibility = View.VISIBLE |
258 | iBusquedaPor = 0 | 266 | iBusquedaPor = 0 |
259 | iEstado = 0 | 267 | iEstado = 0 |
260 | bFirst = false | 268 | bFirst = false |
261 | // } | 269 | // } |
262 | 270 | ||
263 | return@setOnKeyListener true | 271 | return@setOnKeyListener true |
264 | } | 272 | } |
265 | 2 -> {//TODO: BUSQUEDA POR CODIGO DE ORIGEN************************************************************************** | 273 | 2 -> {//TODO: BUSQUEDA POR CODIGO DE ORIGEN************************************************************************** |
266 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 274 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
267 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 275 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
268 | 276 | ||
269 | // GlobalScope.launch(Dispatchers.Main) { | 277 | // GlobalScope.launch(Dispatchers.Main) { |
270 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 2)//TODO Si encuentra el articulo en el RV devuelve el indice | 278 | // indiceDelArtEncontrado = buscoArtEnRv(sChangeUpper.toUpperCase(Locale.ROOT), 2)//TODO Si encuentra el articulo en el RV devuelve el indice |
271 | //// //TODO Si no lo encuentra devuelve -1 | 279 | //// //TODO Si no lo encuentra devuelve -1 |
272 | // if (indiceDelArtEncontrado != -1) { | 280 | // if (indiceDelArtEncontrado != -1) { |
273 | // if (swSumaUno!!.isChecked) { | 281 | // if (swSumaUno!!.isChecked) { |
274 | // fCant = 0F | 282 | // fCant = 0F |
275 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 283 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
276 | // fCant += 1F | 284 | // fCant += 1F |
277 | // //TODO ACTUALIZO LA CANTIDAD EN LA BD | 285 | // //TODO ACTUALIZO LA CANTIDAD EN LA BD |
278 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 286 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
279 | // //TODO ACTUALIZO LA CANTIDAD EN EL RV | 287 | // //TODO ACTUALIZO LA CANTIDAD EN EL RV |
280 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 288 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
281 | // viewAdapter.notifyDataSetChanged() | 289 | // viewAdapter.notifyDataSetChanged() |
282 | // } else { | 290 | // } else { |
283 | // dialogoSumaResta(requireContext(), indiceDelArtEncontrado, listArticulos[indiceDelArtEncontrado].univta, false) | 291 | // dialogoSumaResta(requireContext(), indiceDelArtEncontrado, listArticulos[indiceDelArtEncontrado].univta, false) |
284 | // } | 292 | // } |
285 | // } else { | 293 | // } else { |
286 | // val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 294 | // val mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
287 | // val mBuilder = | 295 | // val mBuilder = |
288 | // AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[indiceDelArtEncontrado].descripcion}', se encuentra cargado.") | 296 | // AlertDialog.Builder(context).setView(mDialogView).setTitle("Producto '${listArticulos[indiceDelArtEncontrado].descripcion}', se encuentra cargado.") |
289 | // .setCancelable(false) | 297 | // .setCancelable(false) |
290 | // mDialogView.tvCantInicial.text = listArticulos[indiceDelArtEncontrado].cantTomada.toString() | 298 | // mDialogView.tvCantInicial.text = listArticulos[indiceDelArtEncontrado].cantTomada.toString() |
291 | // val mAlertDialog = mBuilder.show() | 299 | // val mAlertDialog = mBuilder.show() |
292 | // mDialogView.rbSumar.setOnClickListener { | 300 | // mDialogView.rbSumar.setOnClickListener { |
293 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 301 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
294 | // mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 302 | // mDialogView.tvgenerico4.text = (mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
295 | // } | 303 | // } |
296 | // } | 304 | // } |
297 | // mDialogView.rbRestar.setOnClickListener { | 305 | // mDialogView.rbRestar.setOnClickListener { |
298 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 306 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
299 | // if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 307 | // if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
300 | // mDialogView.tvgenerico4.text = | 308 | // mDialogView.tvgenerico4.text = |
301 | // (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 309 | // (mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
302 | // } | 310 | // } |
303 | // } | 311 | // } |
304 | // } | 312 | // } |
305 | // mDialogView.rbMdodificar.setOnClickListener { | 313 | // mDialogView.rbMdodificar.setOnClickListener { |
306 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 314 | // if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
307 | // mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() | 315 | // mDialogView.tvgenerico4.text = (mDialogView.tvNuevaCantidad.text.toString().toFloat()).toString() |
308 | // } | 316 | // } |
309 | // } | 317 | // } |
310 | // mDialogView.btnAceptar.setOnClickListener { | 318 | // mDialogView.btnAceptar.setOnClickListener { |
311 | // mAlertDialog.dismiss() | 319 | // mAlertDialog.dismiss() |
312 | // val name = mDialogView.tvgenerico4.text.toString().toFloat() | 320 | // val name = mDialogView.tvgenerico4.text.toString().toFloat() |
313 | // fCant = 0F | 321 | // fCant = 0F |
314 | // fCant = name | 322 | // fCant = name |
315 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 323 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
316 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 324 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
317 | // viewAdapter.notifyDataSetChanged() | 325 | // viewAdapter.notifyDataSetChanged() |
318 | // } | 326 | // } |
319 | // mDialogView.dialogCancelBtn.setOnClickListener { | 327 | // mDialogView.dialogCancelBtn.setOnClickListener { |
320 | // mAlertDialog.dismiss() | 328 | // mAlertDialog.dismiss() |
321 | // } | 329 | // } |
322 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada | 330 | // fCant = listArticulos[indiceDelArtEncontrado].cantTomada |
323 | // val type = InputType.TYPE_CLASS_NUMBER | 331 | // val type = InputType.TYPE_CLASS_NUMBER |
324 | // MaterialDialog(requireContext()).show { | 332 | // MaterialDialog(requireContext()).show { |
325 | // | 333 | // |
326 | // title(text = "Producto '$sChangeUpper', se encuentra cargado.") | 334 | // title(text = "Producto '$sChangeUpper', se encuentra cargado.") |
327 | // message(R.string.sCantidadNueva) | 335 | // message(R.string.sCantidadNueva) |
328 | // input(waitForPositiveButton = false, hint = "99.99", inputType = type) { materialDialog, charSequence -> | 336 | // input(waitForPositiveButton = false, hint = "99.99", inputType = type) { materialDialog, charSequence -> |
329 | // fCant = 0F | 337 | // fCant = 0F |
330 | // fCant = charSequence.toString().toFloat() | 338 | // fCant = charSequence.toString().toFloat() |
331 | // } | 339 | // } |
332 | // positiveButton(R.string.btnOk) { | 340 | // positiveButton(R.string.btnOk) { |
333 | // //TODO ACTUALIZO CANTIADAD EN BD | 341 | // //TODO ACTUALIZO CANTIADAD EN BD |
334 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) | 342 | // updateCantidad(listArticulos[indiceDelArtEncontrado].sector.toString(), listArticulos[indiceDelArtEncontrado].codigo.toString(), fCant) |
335 | // //TODO ACTUALIZO CANTIDAD EN RV | 343 | // //TODO ACTUALIZO CANTIDAD EN RV |
336 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant | 344 | // listArticulos[indiceDelArtEncontrado].cantTomada = fCant |
337 | // viewAdapter.notifyDataSetChanged() | 345 | // viewAdapter.notifyDataSetChanged() |
338 | // dismiss() | 346 | // dismiss() |
339 | // } | 347 | // } |
340 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 348 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
341 | // } | 349 | // } |
342 | // } else if (indiceDelArtEncontrado == -1) { | 350 | // } else if (indiceDelArtEncontrado == -1) { |
343 | // no lo encontro en el RV, lo va a buscar en al BD | 351 | // no lo encontro en el RV, lo va a buscar en al BD |
344 | 352 | ||
345 | GlobalScope.launch(Dispatchers.Main) { | 353 | GlobalScope.launch(Main) { |
346 | //TODO BUSCO EN BASE DE DATOS | 354 | //TODO BUSCO EN BASE DE DATOS |
347 | val artEncontrado = buscarCodiogoOriEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) | 355 | if (iArea){ val artEncontrado = buscarCodiogoOriEnBD(sChangeUpper.toUpperCase(Locale.ROOT)) |
348 | continuarCargaCodigoOri(artEncontrado) | 356 | continuarCargaCodigoOri(artEncontrado) } |
357 | else{ val artEncontrado = findArticuloByCodOriNoArea(sChangeUpper.toUpperCase(Locale.ROOT)) | ||
358 | continuarCargaCodigoOri(artEncontrado) } | ||
349 | } | 359 | } |
350 | ivCamara.setImageResource(R.drawable.codbar) | 360 | ivCamara.setImageResource(R.drawable.codbar) |
351 | etCodigoBarras.hint = "Busqueda por Código de Barras" | 361 | etCodigoBarras.hint = "Busqueda por Código de Barras" |
352 | swSumaUno.visibility = View.VISIBLE | 362 | swSumaUno.visibility = View.VISIBLE |
353 | iBusquedaPor = 0 | 363 | iBusquedaPor = 0 |
354 | iEstado = 0 | 364 | iEstado = 0 |
355 | bFirst = false | 365 | bFirst = false |
356 | 366 | ||
357 | // } | 367 | // } |
358 | // } | 368 | // } |
359 | return@setOnKeyListener true | 369 | return@setOnKeyListener true |
360 | } | 370 | } |
361 | } | 371 | } |
362 | } | 372 | } |
363 | } | 373 | } |
364 | return@setOnKeyListener false | 374 | return@setOnKeyListener false |
365 | } | 375 | } |
366 | return v | 376 | return v |
367 | } | 377 | } |
368 | 378 | ||
369 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | 379 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
370 | super.onViewCreated(view, savedInstanceState) | 380 | super.onViewCreated(view, savedInstanceState) |
371 | navController = Navigation.findNavController(view) | 381 | navController = Navigation.findNavController(view) |
372 | etCodigoBarras.requestFocus() | 382 | etCodigoBarras.requestFocus() |
373 | // val modalDialog = NoEncontradoSimple() | 383 | // val modalDialog = NoEncontradoSimple() |
374 | // modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 384 | // modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
375 | 385 | ||
376 | btnBorrarInv.setOnClickListener { | 386 | btnBorrarInv.setOnClickListener { |
377 | AlertDialog.Builder(requireContext()).setTitle("Eliminación de Inventarios").setMessage("¿Confirma que desea eliminar el inventario?") | 387 | AlertDialog.Builder(requireContext()).setTitle("Eliminación de Inventarios").setMessage("¿Confirma que desea eliminar el inventario?") |
378 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> | 388 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> |
379 | borrarInvActualCabecera() | 389 | borrarInvActualCabecera() |
380 | borrarInvActualCuerpo() | 390 | borrarInvActualCuerpo() |
381 | Toast.makeText(requireContext(), "El inventario fue Borrado", Toast.LENGTH_LONG).show() | 391 | Toast.makeText(requireContext(), "El inventario fue Borrado", Toast.LENGTH_LONG).show() |
382 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) | 392 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
383 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 | 393 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 |
384 | 394 | ||
385 | }).setNegativeButton(R.string.btnCancelar, DialogInterface.OnClickListener { dialog, which -> | 395 | }).setNegativeButton(R.string.btnCancelar, DialogInterface.OnClickListener { dialog, which -> |
386 | //botón cancel pulsado | 396 | //botón cancel pulsado |
387 | }).show() | 397 | }).show() |
388 | } | 398 | } |
389 | 399 | ||
390 | btnExportarInv.setOnClickListener { | 400 | btnExportarInv.setOnClickListener { |
391 | AlertDialog.Builder(requireContext()).setTitle(R.string.sTituloExportar).setMessage(R.string.sMensajeExportar) | 401 | AlertDialog.Builder(requireContext()).setTitle(R.string.sTituloExportar).setMessage(R.string.sMensajeExportar) |
392 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> | 402 | .setPositiveButton(R.string.btnOk, DialogInterface.OnClickListener { dialog, which -> |
393 | preparaInvParaExportar((inventarioViewModel as InventarioViewModel).InventarioNuevo) | 403 | preparaInvParaExportar((inventarioViewModel as InventarioViewModel).InventarioNuevo) |
394 | }).setNegativeButton(R.string.btnCancelar, DialogInterface.OnClickListener { dialog, which -> }).show() | 404 | }).setNegativeButton(R.string.btnCancelar, DialogInterface.OnClickListener { dialog, which -> }).show() |
395 | } | 405 | } |
396 | ivCamara.setOnClickListener { | 406 | ivCamara.setOnClickListener { |
397 | if (!bFirst) { | 407 | if (!bFirst) { |
398 | iEstado = 1 | 408 | iEstado = 1 |
399 | bFirst = true | 409 | bFirst = true |
400 | } | 410 | } |
401 | 411 | ||
402 | when (iEstado) { | 412 | when (iEstado) { |
403 | 0 -> { | 413 | 0 -> { |
404 | ivCamara.setImageResource(R.drawable.codbar) | 414 | ivCamara.setImageResource(R.drawable.codbar) |
405 | etCodigoBarras.hint = "Busqueda por Código de Barras" | 415 | etCodigoBarras.hint = "Busqueda por Código de Barras" |
406 | swSumaUno.visibility = View.VISIBLE | 416 | swSumaUno.visibility = View.VISIBLE |
407 | iBusquedaPor = 0 | 417 | iBusquedaPor = 0 |
408 | iEstado = 1 | 418 | iEstado = 1 |
409 | } | 419 | } |
410 | 1 -> { | 420 | 1 -> { |
411 | ivCamara.setImageResource(R.drawable.desc) | 421 | ivCamara.setImageResource(R.drawable.desc) |
412 | etCodigoBarras.hint = "Busqueda por Descripción" | 422 | etCodigoBarras.hint = "Busqueda por Descripción" |
413 | swSumaUno.visibility = View.GONE | 423 | swSumaUno.visibility = View.GONE |
414 | iBusquedaPor = 1 | 424 | iBusquedaPor = 1 |
415 | iEstado = 2 | 425 | iEstado = 2 |
416 | } | 426 | } |
417 | 2 -> { | 427 | 2 -> { |
418 | ivCamara.setImageResource(R.drawable.cod_origen) | 428 | ivCamara.setImageResource(R.drawable.cod_origen) |
419 | etCodigoBarras.hint = "Busqueda por Código de Origen" | 429 | etCodigoBarras.hint = "Busqueda por Código de Origen" |
420 | swSumaUno.visibility = View.GONE | 430 | swSumaUno.visibility = View.GONE |
421 | iBusquedaPor = 2 | 431 | iBusquedaPor = 2 |
422 | iEstado = 0 | 432 | iEstado = 0 |
423 | } | 433 | } |
424 | } | 434 | } |
425 | } | 435 | } |
426 | } | 436 | } |
427 | 437 | ||
428 | private fun preparaInvParaExportar(inventario: Int) { | 438 | private fun preparaInvParaExportar(inventario: Int) { |
429 | 439 | ||
430 | var fecInicio: String | 440 | var fecInicio: String |
431 | var lug: Int | 441 | var lug: Int |
432 | var itomInvC: ItomInvC | 442 | var itomInvC: ItomInvC |
433 | // lifecycleScope.launch(Main) { | 443 | // lifecycleScope.launch(Main) { |
434 | fragmentScopeInvFrag.launch(Main) { | 444 | fragmentScopeInvFrag.launch(Main) { |
435 | 445 | ||
436 | val datosCabecera = foundInvHeadDB(inventario) | 446 | val datosCabecera = foundInvHeadDB(inventario) |
437 | val datosCuerpo = foundInvBodyBD(inventario) | 447 | val datosCuerpo = foundInvBodyBD(inventario) |
438 | fecInicio = datosCabecera.fechaInicio.toString() | 448 | fecInicio = datosCabecera.fechaInicio.toString() |
439 | var fecActual: String = "${obtenerFechaActual()}" | 449 | var fecActual: String = "${obtenerFechaActual()}" |
440 | fecActual = "$fecActual" | 450 | fecActual = "$fecActual" |
441 | lug = if (datosCabecera.lugar!!) 1 else 0 | 451 | lug = if (datosCabecera.lugar!!) 1 else 0 |
442 | itomInvC = ItomInvC(fecInicio, fecActual, lug) | 452 | itomInvC = ItomInvC(fecInicio, fecActual, lug) |
443 | serverBajada = AppDb.getAppDb((activity as MainActivity))!!.ServeInvDao()!!.fetchServerPreOne() | 453 | serverBajada = AppDb.getAppDb((activity as MainActivity))!!.ServeInvDao()!!.fetchServerPreOne() |
444 | exportarInventarioHead(itomInvC, datosCuerpo) | 454 | exportarInventarioHead(itomInvC, datosCuerpo) |
445 | } | 455 | } |
446 | } | 456 | } |
447 | 457 | ||
448 | private fun exportarInventarioHead(aEnviar: ItomInvC, datosCuerpo: List<InvBody>) { | 458 | private fun exportarInventarioHead(aEnviar: ItomInvC, datosCuerpo: List<InvBody>) { |
449 | var exporto = false | ||
450 | if (serverBajada != null) { | 459 | if (serverBajada != null) { |
451 | 460 | ||
452 | if (serverBajada!!.direccion.isNullOrEmpty()) { | 461 | if (serverBajada!!.direccion.isNullOrEmpty()) { |
453 | val modalDialog = NoServerConf() | 462 | val modalDialog = NoServerConf() |
454 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 463 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
455 | } else { | 464 | } else { |
456 | BASE_URL = serverBajada!!.direccion.toString() + ":" + serverBajada!!.puertoSubida.toString() + "/" | 465 | BASE_URL = serverBajada!!.direccion.toString() + ":" + serverBajada!!.puertoSubida.toString() + "/" |
457 | try { | 466 | try { |
458 | ItomInv.request.insertarItominvc(aEnviar) | 467 | ItomInv.request.insertarItominvc(aEnviar) |
459 | .enqueue(object : Callback<DefaultResponse> { | 468 | .enqueue(object : Callback<DefaultResponse> { |
460 | override fun onResponse(call: Call<DefaultResponse>, response: Response<DefaultResponse>) { | 469 | override fun onResponse(call: Call<DefaultResponse>, response: Response<DefaultResponse>) { |
461 | fragmentScopeInvFrag.launch(Main) { | 470 | fragmentScopeInvFrag.launch(Main) { |
462 | loading_view.visibility=View.VISIBLE | 471 | loading_view.visibility=View.VISIBLE |
463 | if(exportarInventarioBody(datosCuerpo)) { | 472 | if(exportarInventarioBody(datosCuerpo)) { |
464 | borrarInvActualCabecera() | 473 | borrarInvActualCabecera() |
465 | borrarInvActualCuerpo() | 474 | borrarInvActualCuerpo() |
466 | loading_view.visibility = View.INVISIBLE | 475 | loading_view.visibility = View.INVISIBLE |
467 | 476 | ||
468 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) | 477 | navController.navigate(R.id.action_inventarioFragment_to_mainFragment2) |
469 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 | 478 | (inventarioViewModel as InventarioViewModel).InventarioNuevo = 0 |
470 | 479 | ||
471 | val modalDialog = ExportacionExitosa() | 480 | val modalDialog = ExportacionExitosa() |
472 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 481 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
473 | }else { | 482 | }else { |
474 | loading_view.visibility = View.INVISIBLE | 483 | loading_view.visibility = View.INVISIBLE |
475 | val modalDialog = ExportacionFracasada() | 484 | val modalDialog = ExportacionFracasada() |
476 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 485 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
477 | } | 486 | } |
478 | } | 487 | } |
479 | } | 488 | } |
480 | 489 | ||
481 | override fun onFailure(call: Call<DefaultResponse>, t: Throwable) { | 490 | override fun onFailure(call: Call<DefaultResponse>, t: Throwable) { |
482 | val modalDialog = ExportacionFracasada() | 491 | val modalDialog = ExportacionFracasada() |
483 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 492 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
484 | } | 493 | } |
485 | }) | 494 | }) |
486 | 495 | ||
487 | } catch (e: RuntimeException) { | 496 | } catch (e: RuntimeException) { |
488 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() | 497 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() |
489 | } catch (e: Error) { | 498 | } catch (e: Error) { |
490 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() | 499 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() |
491 | } catch (e: ErrnoException) { | 500 | } catch (e: ErrnoException) { |
492 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() | 501 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() |
493 | } catch (e: InternalError) { | 502 | } catch (e: InternalError) { |
494 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() | 503 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() |
495 | } catch (e: IOException) { | 504 | } catch (e: IOException) { |
496 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() | 505 | Toast.makeText(context, "Error ${e.message}", Toast.LENGTH_LONG).show() |
497 | } catch (e: SocketTimeoutException) { | 506 | } catch (e: SocketTimeoutException) { |
498 | Toast.makeText(requireContext(), e.message, Toast.LENGTH_SHORT).show() | 507 | Toast.makeText(requireContext(), e.message, Toast.LENGTH_SHORT).show() |
499 | } | 508 | } |
500 | } | 509 | } |
501 | } else { | 510 | } else { |
502 | val modalDialog = ServerNoConf() | 511 | val modalDialog = ServerNoConf() |
503 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 512 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
504 | } | 513 | } |
505 | } | 514 | } |
506 | 515 | ||
507 | private fun exportarInventarioBody(datosCuerpo: List<InvBody>):Boolean { | 516 | private fun exportarInventarioBody(datosCuerpo: List<InvBody>):Boolean { |
508 | 517 | ||
509 | |||
510 | for (cuerpo in datosCuerpo) { | 518 | for (cuerpo in datosCuerpo) { |
511 | val aEnviar: ItomInvD = ItomInvD( | 519 | val aEnviar: ItomInvD = ItomInvD( |
512 | cuerpo.sector.toString(), | 520 | cuerpo.sector.toString(), |
513 | cuerpo.codigo.toString(), | 521 | cuerpo.codigo.toString(), |
514 | cuerpo.descripcion.toString(), | 522 | cuerpo.descripcion.toString(), |
515 | cuerpo.cantTomada.toString(), | 523 | cuerpo.cantTomada.toString(), |
516 | cuerpo.fechaInicio.toString(), | 524 | cuerpo.fechaInicio.toString(), |
517 | cuerpo.fechaFinal.toString() | 525 | cuerpo.fechaFinal.toString() |
518 | ) | 526 | ) |
519 | 527 | ||
520 | ItomInv.request.insertarItominvd(aEnviar) | 528 | ItomInv.request.insertarItominvd(aEnviar) |
521 | .enqueue(object : Callback<Void?> { | 529 | .enqueue(object : Callback<Void?> { |
522 | override fun onResponse(call: Call<Void?>, response: Response<Void?>) {} | 530 | override fun onResponse(call: Call<Void?>, response: Response<Void?>) {} |
523 | override fun onFailure(call: Call<Void?>, t: Throwable) {} | 531 | override fun onFailure(call: Call<Void?>, t: Throwable) {} |
524 | // val call: Call<Void?>? = WebService.instance | 532 | // val call: Call<Void?>? = WebService.instance |
525 | // ?.createService(WebServiceApi::class.java) | 533 | // ?.createService(WebServiceApi::class.java) |
526 | // ?.insertarItominvd(aEnviar) | 534 | // ?.insertarItominvd(aEnviar) |
527 | // call?.enqueue(object : Callback<Void?> { | 535 | // call?.enqueue(object : Callback<Void?> { |
528 | // override fun onResponse(call: Call<Void?>, response: Response<Void?>) { | 536 | // override fun onResponse(call: Call<Void?>, response: Response<Void?>) { |
529 | // if (response.code() == 200) { } | 537 | // if (response.code() == 200) { } |
530 | // if (response.code() == 400) { } | 538 | // if (response.code() == 400) { } |
531 | // } | 539 | // } |
532 | // override fun onFailure(call: Call<Void?>?, t: Throwable?) {} | 540 | // override fun onFailure(call: Call<Void?>?, t: Throwable?) {} |
533 | }) | 541 | }) |
534 | 542 | ||
535 | } | 543 | } |
536 | return true | 544 | return true |
537 | } | 545 | } |
538 | 546 | ||
539 | private suspend fun foundInvHeadDB(inv: Int): InvHead { | 547 | private suspend fun foundInvHeadDB(inv: Int): InvHead { |
540 | var busqueda: InvHead | 548 | var busqueda: InvHead |
541 | return GlobalScope.async(IO) { | 549 | return GlobalScope.async(IO) { |
542 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.InvHeadDAO()!!.foundInvHead(inv) | 550 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.InvHeadDAO()!!.foundInvHead(inv) |
543 | return@async busqueda | 551 | return@async busqueda |
544 | }.await() | 552 | }.await() |
545 | } | 553 | } |
546 | 554 | ||
547 | private suspend fun foundInvBodyBD(inv: Int): List<InvBody> { | 555 | private suspend fun foundInvBodyBD(inv: Int): List<InvBody> { |
548 | var busqueda: List<InvBody> | 556 | var busqueda: List<InvBody> |
549 | return GlobalScope.async(IO) { | 557 | return GlobalScope.async(IO) { |
550 | busqueda = AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inv) | 558 | busqueda = AppDb.getAppDb(requireActivity())!!.InvBodyDAO()!!.fetchAllInvBody(inv) |
551 | return@async busqueda | 559 | return@async busqueda |
552 | }.await() | 560 | }.await() |
553 | } | 561 | } |
554 | 562 | ||
555 | private fun borrarInvActualCabecera() { | 563 | private fun borrarInvActualCabecera() { |
556 | GlobalScope.launch(IO) { | 564 | GlobalScope.launch(IO) { |
557 | AppDb.getAppDb(requireContext())!!.InvHeadDAO()!!.deleteinvHead((inventarioViewModel as InventarioViewModel).InventarioNuevo) | 565 | AppDb.getAppDb(requireContext())!!.InvHeadDAO()!!.deleteinvHead((inventarioViewModel as InventarioViewModel).InventarioNuevo) |
558 | } | 566 | } |
559 | } | 567 | } |
560 | 568 | ||
561 | private fun borrarInvActualCuerpo() { | 569 | private fun borrarInvActualCuerpo() { |
562 | GlobalScope.launch(IO) { | 570 | GlobalScope.launch(IO) { |
563 | AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.deleteInvBody((inventarioViewModel as InventarioViewModel).InventarioNuevo) | 571 | AppDb.getAppDb(requireContext())!!.InvBodyDAO()!!.deleteInvBody((inventarioViewModel as InventarioViewModel).InventarioNuevo) |
564 | } | 572 | } |
565 | } | 573 | } |
566 | 574 | ||
567 | private fun cargarDeBdInventario(ultimoInv: Int) { | 575 | private fun cargarDeBdInventario(ultimoInv: Int) { |
568 | GlobalScope.launch(Main) { | 576 | GlobalScope.launch(Main) { |
569 | val invbody = cargarInventario(ultimoInv) | 577 | val invbody = cargarInventario(ultimoInv) |
570 | for ((i, _) in invbody!!.withIndex()) { | 578 | for ((i, _) in invbody!!.withIndex()) { |
571 | val art = Articles( | 579 | val art = Articles( |
572 | invbody[i].sector, | 580 | invbody[i].sector, |
573 | invbody[i].codigo, | 581 | invbody[i].codigo, |
574 | invbody[i].descripcion, | 582 | invbody[i].descripcion, |
575 | invbody[i].codBar, | 583 | invbody[i].codBar, |
576 | invbody[i].codOrigen, | 584 | invbody[i].codOrigen, |
577 | invbody[i].precio, | 585 | invbody[i].precio, |
578 | invbody[i].costo, | 586 | invbody[i].costo, |
579 | "", | 587 | "", |
580 | "", | 588 | "", |
581 | "", | 589 | "", |
582 | invbody[i].balanza, | 590 | invbody[i].balanza, |
583 | invbody[i].depSn, | 591 | invbody[i].depSn, |
584 | invbody[i].costo | 592 | invbody[i].costo |
585 | ) | 593 | ) |
586 | cargarRecicler(art, invbody[i].cantTomada!!.toFloat()) | 594 | cargarRecicler(art, invbody[i].cantTomada!!.toFloat()) |
587 | } | 595 | } |
588 | } | 596 | } |
589 | } | 597 | } |
590 | 598 | ||
591 | private fun continuarCargaCodigoOri(artAcargar: List<Articles>) { | 599 | private fun continuarCargaCodigoOri(artAcargar: List<Articles>) { |
592 | 600 | ||
593 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD | 601 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD |
594 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER | 602 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
595 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 603 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
596 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 604 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
597 | 605 | ||
598 | var bundle = Bundle() | 606 | var bundle = Bundle() |
599 | bundle = bundleOf("ArrayDesc" to artAcargar) | 607 | bundle = bundleOf("ArrayDesc" to artAcargar) |
600 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) | 608 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) |
601 | navController.navigate(R.id.action_inventarioFragment_to_codigoOriFragment, bundle) | 609 | navController.navigate(R.id.action_inventarioFragment_to_codigoOriFragment, bundle) |
602 | 610 | ||
603 | } else {//TODO si no lo encuentra en la BD | 611 | } else {//TODO si no lo encuentra en la BD |
604 | val modalDialog = NoEncontradoSimple() | 612 | val modalDialog = NoEncontradoSimple() |
605 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 613 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
606 | } | 614 | } |
607 | // etCodigoBarras.focusable = View.FOCUSABLE | 615 | // etCodigoBarras.focusable = View.FOCUSABLE |
608 | etCodigoBarras.requestFocus() | 616 | etCodigoBarras.requestFocus() |
609 | etCodigoBarras.setText("") | 617 | etCodigoBarras.setText("") |
610 | etCodigoBarras.selectAll() | 618 | etCodigoBarras.selectAll() |
611 | } | 619 | } |
612 | 620 | ||
613 | private fun continuarCargaDesc(artAcargar: ArrayList<Articles>) { | 621 | private fun continuarCargaDesc(artAcargar: ArrayList<Articles>) { |
614 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS | 622 | //TODO DESPUES DE INGRESAR LA DESCRIPCION Y DE BUSCAR LOS CAINCIDENCIAS EN LA BASE SE VA A MOSTRAR LAS MISMAS |
615 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV | 623 | //TODO SI LA CANTIDAD ENCONTRADA ES UNO, LO CARGO DIRECTAMENTE EN EL RV |
616 | 624 | ||
617 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD | 625 | if (artAcargar.isNotEmpty() || !artAcargar.isNullOrEmpty()) {// TODO: Si lo encuentra en la BD |
618 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV | 626 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV |
619 | // fCant = 0F | 627 | // fCant = 0F |
620 | // fCant += 1F | 628 | // fCant += 1F |
621 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV | 629 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV |
622 | // val acargarPorDesc = Articles(artAcargar[0].sector, | 630 | // val acargarPorDesc = Articles(artAcargar[0].sector, |
623 | // artAcargar[0].codigo, | 631 | // artAcargar[0].codigo, |
624 | // artAcargar[0].descripcion, | 632 | // artAcargar[0].descripcion, |
625 | // artAcargar[0].codBar, | 633 | // artAcargar[0].codBar, |
626 | // artAcargar[0].codOrigen, | 634 | // artAcargar[0].codOrigen, |
627 | // artAcargar[0].precio, | 635 | // artAcargar[0].precio, |
628 | // artAcargar[0].costo, | 636 | // artAcargar[0].costo, |
629 | // "", | 637 | // "", |
630 | // "", | 638 | // "", |
631 | // "", | 639 | // "", |
632 | // artAcargar[0].balanza, | 640 | // artAcargar[0].balanza, |
633 | // artAcargar[0].depSn, | 641 | // artAcargar[0].depSn, |
634 | // "") | 642 | // "") |
635 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD | 643 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD |
636 | // cargarArtEnBd(acargarPorDesc, fCant) | 644 | // cargarArtEnBd(acargarPorDesc, fCant) |
637 | // cargarRecicler(acargarPorDesc, fCant) | 645 | // cargarRecicler(acargarPorDesc, fCant) |
638 | // } else { | 646 | // } else { |
639 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER | 647 | // TODO: ESCONDE EL TECLADO VIRTUAL AL PRESIONAR ENTER |
640 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | 648 | val imm = (activity as MainActivity).getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? |
641 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) | 649 | imm!!.hideSoftInputFromWindow((activity as MainActivity).currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
642 | var bundle = Bundle() | 650 | var bundle = Bundle() |
643 | bundle = bundleOf("ArrayDesc" to artAcargar) | 651 | bundle = bundleOf("ArrayDesc" to artAcargar) |
644 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) | 652 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) |
645 | navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) | 653 | navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) |
646 | //navController.backStack.removeLast() | 654 | //navController.backStack.removeLast() |
647 | // } | 655 | // } |
648 | // } else {//SI NO ESTA +1 | 656 | // } else {//SI NO ESTA +1 |
649 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV | 657 | // if (artAcargar.size == 1) { // TODO: SI EN EL ARRAY SOLO HAY UN ITEM LO METE DIRECTAMENTE AL RV |
650 | // fCant = listArticulos[0].cantTomada | 658 | // fCant = listArticulos[0].cantTomada |
651 | // MaterialDialog(requireContext()).show { | 659 | // MaterialDialog(requireContext()).show { |
652 | // title(R.string.sTituloNueva) | 660 | // title(R.string.sTituloNueva) |
653 | // message(R.string.sCantidadNueva) | 661 | // message(R.string.sCantidadNueva) |
654 | // input { materialDialog, charSequence -> | 662 | // input { materialDialog, charSequence -> |
655 | // fCant = 0F | 663 | // fCant = 0F |
656 | // fCant = charSequence.toString().toFloat() | 664 | // fCant = charSequence.toString().toFloat() |
657 | // } | 665 | // } |
658 | // positiveButton(R.string.btnOk) { | 666 | // positiveButton(R.string.btnOk) { |
659 | // listArticulos[0].cantTomada = fCant | 667 | // listArticulos[0].cantTomada = fCant |
660 | // viewAdapter.notifyDataSetChanged() | 668 | // viewAdapter.notifyDataSetChanged() |
661 | // dismiss() | 669 | // dismiss() |
662 | // } | 670 | // } |
663 | // }.cancelOnTouchOutside(false).cornerRadius(10F) | 671 | // }.cancelOnTouchOutside(false).cornerRadius(10F) |
664 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV | 672 | // // TODO PASO DEL ARRAY A UN ITEM PARA QUE LO CARGUE EN EL RV |
665 | // val acargarPorDesc = Articles(artAcargar[0].sector, | 673 | // val acargarPorDesc = Articles(artAcargar[0].sector, |
666 | // artAcargar[0].codigo, | 674 | // artAcargar[0].codigo, |
667 | // artAcargar[0].descripcion, | 675 | // artAcargar[0].descripcion, |
668 | // artAcargar[0].codBar, | 676 | // artAcargar[0].codBar, |
669 | // artAcargar[0].cod_origen, | 677 | // artAcargar[0].cod_origen, |
670 | // artAcargar[0].precio, | 678 | // artAcargar[0].precio, |
671 | // artAcargar[0].costo, | 679 | // artAcargar[0].costo, |
672 | // artAcargar[0].balanza, | 680 | // artAcargar[0].balanza, |
673 | // artAcargar[0].depSn, | 681 | // artAcargar[0].depSn, |
674 | // "") | 682 | // "") |
675 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD | 683 | // // TODO LO ENVIO A CARGAR EN EL RV Y EN LA BD |
676 | // cargarArtEnBd(acargarPorDesc, fCant) | 684 | // cargarArtEnBd(acargarPorDesc, fCant) |
677 | // cargarRecicler(acargarPorDesc, fCant) | 685 | // cargarRecicler(acargarPorDesc, fCant) |
678 | // } else { | 686 | // } else { |
679 | // var bundle = Bundle() | 687 | // var bundle = Bundle() |
680 | // bundle = bundleOf("ArrayDesc" to artAcargar) | 688 | // bundle = bundleOf("ArrayDesc" to artAcargar) |
681 | // bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) | 689 | // bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) |
682 | // navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) | 690 | // navController.navigate(R.id.action_inventarioFragment_to_descripcionFragment, bundle) |
683 | // } | 691 | // } |
684 | // } | 692 | // } |
685 | } else {//TODO si no lo encuentra en la BD | 693 | } else {//TODO si no lo encuentra en la BD |
686 | val modalDialog = NoEncontradoSimple() | 694 | val modalDialog = NoEncontradoSimple() |
687 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 695 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
688 | } | 696 | } |
689 | // etCodigoBarras.focusable = View.FOCUSABLE | 697 | // etCodigoBarras.focusable = View.FOCUSABLE |
690 | etCodigoBarras.requestFocus() | 698 | etCodigoBarras.requestFocus() |
691 | etCodigoBarras.setText("") | 699 | etCodigoBarras.setText("") |
692 | etCodigoBarras.selectAll() | 700 | etCodigoBarras.selectAll() |
693 | } | 701 | } |
694 | 702 | ||
695 | private fun continuarCargaCB(artAcargar: Articles?) { | 703 | private fun continuarCargaCB(artAcargar: Articles?) { |
696 | 704 | ||
697 | if (artAcargar != null) { // TODO: Si lo encuentra en la BD | 705 | if (artAcargar != null) { // TODO: Si lo encuentra en la BD |
698 | if (EsBalanza) { | 706 | if (EsBalanza) { |
699 | cargarArtEnBd(artAcargar, ("$cantEnteraBalanza.$cantDecimalBalanza")) | 707 | cargarArtEnBd(artAcargar, ("$cantEnteraBalanza.$cantDecimalBalanza")) |
700 | cargarRecicler(artAcargar, ("$cantEnteraBalanza.$cantDecimalBalanza").toFloat()) | 708 | cargarRecicler(artAcargar, ("$cantEnteraBalanza.$cantDecimalBalanza").toFloat()) |
701 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, true, requireContext()) | 709 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, true, requireContext()) |
702 | EsBalanza=false | 710 | EsBalanza=false |
703 | }else{ | 711 | }else{ |
704 | if (swSumaUno!!.isChecked) {//TODO: SI ESTA +1, PONE CANTIDAD 1 | 712 | if (swSumaUno!!.isChecked) {//TODO: SI ESTA +1, PONE CANTIDAD 1 |
705 | fCant = 0F | 713 | fCant = 0F |
706 | fCant += 1F | 714 | fCant += 1F |
707 | 715 | ||
708 | cargarArtEnBd(artAcargar, (Math.round(fCant * 100.0) / 100.0).toFloat().toString()) | 716 | cargarArtEnBd(artAcargar, (Math.round(fCant * 100.0) / 100.0).toFloat().toString()) |
709 | cargarRecicler(artAcargar, (Math.round(fCant * 100.0) / 100.0).toFloat()) | 717 | cargarRecicler(artAcargar, (Math.round(fCant * 100.0) / 100.0).toFloat()) |
710 | } else {//TODO: SI NO ESTA +1 PREGUNTA CANTIDAD | 718 | } else {//TODO: SI NO ESTA +1 PREGUNTA CANTIDAD |
711 | dialogingresarCantidad(requireContext(), artAcargar) | 719 | dialogingresarCantidad(requireContext(), artAcargar) |
712 | } | 720 | } |
713 | } | 721 | } |
714 | } else {// TODO si no lo encuentra en la BD | 722 | } else {// TODO si no lo encuentra en la BD |
715 | val modalDialog = NoEncontradoSimple() | 723 | val modalDialog = NoEncontradoSimple() |
716 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") | 724 | modalDialog.show((activity as MainActivity).supportFragmentManager, "confirmDialog") |
717 | } | 725 | } |
718 | etCodigoBarras.requestFocus() | 726 | etCodigoBarras.requestFocus() |
719 | etCodigoBarras.setText("") | 727 | etCodigoBarras.setText("") |
720 | etCodigoBarras.selectAll() | 728 | etCodigoBarras.selectAll() |
721 | } | 729 | } |
722 | 730 | ||
723 | fun dialogingresarCantidad(cnxt: Context, artAcargar: Articles?): Float { | 731 | fun dialogingresarCantidad(cnxt: Context, artAcargar: Articles?): Float { |
724 | var cantidad = 0F | 732 | var cantidad = 0F |
725 | val mDialogView = LayoutInflater.from(cnxt).inflate(R.layout.ingresar_cantidad, null) | 733 | val mDialogView = LayoutInflater.from(cnxt).inflate(R.layout.ingresar_cantidad, null) |
726 | val mBuilder = AlertDialog.Builder(cnxt).setView(mDialogView).setCancelable(false) | 734 | val mBuilder = AlertDialog.Builder(cnxt).setView(mDialogView).setCancelable(false) |
727 | if (artAcargar!!.balanza!!.toInt() == 1 || artAcargar.balanza!!.toInt() == 3 || artAcargar.balanza!!.toInt() == 7) mDialogView.etCantidad.inputType = TYPE_CLASS_NUMBER | 735 | if (artAcargar!!.balanza!!.toInt() == 1 || artAcargar.balanza!!.toInt() == 3 || artAcargar.balanza!!.toInt() == 7) mDialogView.etCantidad.inputType = TYPE_CLASS_NUMBER |
728 | mDialogView.tvTitulo.text = artAcargar.descripcion.toString() | 736 | mDialogView.tvTitulo.text = artAcargar.descripcion.toString() |
729 | val mAlertDialog = mBuilder.show() | 737 | val mAlertDialog = mBuilder.show() |
730 | 738 | ||
731 | mDialogView.etCantidad.requestFocus() | 739 | mDialogView.etCantidad.requestFocus() |
732 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 740 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
733 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 741 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
734 | 742 | ||
735 | mDialogView.btnAceptar.setOnClickListener { | 743 | mDialogView.btnAceptar.setOnClickListener { |
736 | if (mDialogView.etCantidad.text.isNullOrEmpty()) { | 744 | if (mDialogView.etCantidad.text.isNullOrEmpty()) { |
737 | mDialogView.etCantidad.error = "No vacio" | 745 | mDialogView.etCantidad.error = "No vacio" |
738 | mDialogView.etCantidad.requestFocus() | 746 | mDialogView.etCantidad.requestFocus() |
739 | mDialogView.etCantidad.hint = "Ingrese un valor" | 747 | mDialogView.etCantidad.hint = "Ingrese un valor" |
740 | } else if (!mDialogView.etCantidad.text.isNullOrEmpty()) { | 748 | } else if (!mDialogView.etCantidad.text.isNullOrEmpty()) { |
741 | mAlertDialog.dismiss() | 749 | mAlertDialog.dismiss() |
742 | cantidad = (Math.round(mDialogView.etCantidad.text.toString().toFloat() * 100.0) / 100.0).toFloat() | 750 | cantidad = (Math.round(mDialogView.etCantidad.text.toString().toFloat() * 100.0) / 100.0).toFloat() |
743 | cargarArtEnBd(artAcargar, cantidad.toString()) | 751 | cargarArtEnBd(artAcargar, cantidad.toString()) |
744 | cargarRecicler(artAcargar, cantidad) | 752 | cargarRecicler(artAcargar, cantidad) |
745 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, true, requireContext()) | 753 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, true, requireContext()) |
746 | } | 754 | } |
747 | } | 755 | } |
748 | return cantidad | 756 | return cantidad |
749 | } | 757 | } |
750 | 758 | ||
751 | fun dialogoSumaResta(context: Context, indiceDelArtEncontrado: Int, univta: String, cancelable: Boolean) { | 759 | fun dialogoSumaResta(context: Context, indiceDelArtEncontrado: Int, univta: String, cancelable: Boolean) { |
752 | var cantidadTemp: Float | 760 | var cantidadTemp: Float |
753 | mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) | 761 | mDialogView = LayoutInflater.from(context).inflate(R.layout.login_dialog, null) |
754 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(cancelable) | 762 | val mBuilder = AlertDialog.Builder(context).setView(mDialogView).setCancelable(cancelable) |
755 | // TODO: SI PERMITE QUE INGRESE DECIMALES | 763 | // TODO: SI PERMITE QUE INGRESE DECIMALES |
756 | if (univta.contains("1") || univta.contains("3") || univta.contains("7")) mDialogView.tvNuevaCantidad.inputType = TYPE_CLASS_NUMBER | 764 | if (univta.contains("1") || univta.contains("3") || univta.contains("7")) mDialogView.tvNuevaCantidad.inputType = TYPE_CLASS_NUMBER |
757 | mDialogView.tvTitulo2.text = "${listArticulos[indiceDelArtEncontrado].descripcion}" | 765 | mDialogView.tvTitulo2.text = "${listArticulos[indiceDelArtEncontrado].descripcion}" |
758 | cantidadTemp = (Math.round(listArticulos[indiceDelArtEncontrado].cantTomada * 100.0) / 100.0).toFloat() | 766 | cantidadTemp = (Math.round(listArticulos[indiceDelArtEncontrado].cantTomada * 100.0) / 100.0).toFloat() |
759 | mDialogView.tvCantInicial.text = cantidadTemp.toString() | 767 | mDialogView.tvCantInicial.text = cantidadTemp.toString() |
760 | val mAlertDialog = mBuilder.show() | 768 | val mAlertDialog = mBuilder.show() |
761 | mDialogView.tvNuevaCantidad.requestFocus() | 769 | mDialogView.tvNuevaCantidad.requestFocus() |
762 | 770 | ||
763 | 771 | ||
764 | 772 | ||
765 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) | 773 | mAlertDialog?.window!!.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) |
766 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) | 774 | mAlertDialog.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
767 | 775 | ||
768 | mDialogView.tvNuevaCantidad.addTextChangedListener(textWatcher) | 776 | mDialogView.tvNuevaCantidad.addTextChangedListener(textWatcher) |
769 | 777 | ||
770 | mDialogView.rbSumar.setOnClickListener { | 778 | mDialogView.rbSumar.setOnClickListener { |
771 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 779 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
772 | cantidadTemp = mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat() | 780 | cantidadTemp = mDialogView.tvCantInicial.text.toString().toFloat() + mDialogView.tvNuevaCantidad.text.toString().toFloat() |
773 | mDialogView.tvResultado.text = (Math.round(cantidadTemp * 100.0) / 100.0).toString() | 781 | mDialogView.tvResultado.text = (Math.round(cantidadTemp * 100.0) / 100.0).toString() |
774 | } | 782 | } |
775 | } | 783 | } |
776 | mDialogView.rbRestar.setOnClickListener { | 784 | mDialogView.rbRestar.setOnClickListener { |
777 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 785 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
778 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 786 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
779 | cantidadTemp = mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat() | 787 | cantidadTemp = mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat() |
780 | mDialogView.tvResultado.text = (Math.round(cantidadTemp * 100.0) / 100.0).toString() | 788 | mDialogView.tvResultado.text = (Math.round(cantidadTemp * 100.0) / 100.0).toString() |
781 | // mDialogView.tvNuevaCantidad.isEnabled = false | 789 | // mDialogView.tvNuevaCantidad.isEnabled = false |
782 | } else { | 790 | } else { |
783 | mDialogView.tvResultado.text = "" | 791 | mDialogView.tvResultado.text = "" |
784 | mDialogView.tvResultado.error = "Operación No Valida" | 792 | mDialogView.tvResultado.error = "Operación No Valida" |
785 | mDialogView.tvResultado.requestFocus() | 793 | mDialogView.tvResultado.requestFocus() |
786 | mDialogView.tvResultado.hint = "Error" | 794 | mDialogView.tvResultado.hint = "Error" |
787 | } | 795 | } |
788 | } | 796 | } |
789 | } | 797 | } |
790 | mDialogView.rbMdodificar.setOnClickListener { | 798 | mDialogView.rbMdodificar.setOnClickListener { |
791 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 799 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
792 | mDialogView.tvResultado.text = (Math.round(mDialogView.tvNuevaCantidad.text.toString().toFloat() * 100.0) / 100.0).toString() | 800 | mDialogView.tvResultado.text = (Math.round(mDialogView.tvNuevaCantidad.text.toString().toFloat() * 100.0) / 100.0).toString() |
793 | } | 801 | } |
794 | } | 802 | } |
795 | mDialogView.btnAceptar.setOnClickListener { | 803 | mDialogView.btnAceptar.setOnClickListener { |
796 | if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || !mDialogView.tvNuevaCantidad.text.isBlank()) { | 804 | if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || !mDialogView.tvNuevaCantidad.text.isBlank()) { |
797 | if (mDialogView.tvResultado.text.isNotEmpty() || !mDialogView.tvResultado.text.isBlank()) { | 805 | if (mDialogView.tvResultado.text.isNotEmpty() || !mDialogView.tvResultado.text.isBlank()) { |
798 | mAlertDialog.dismiss() | 806 | mAlertDialog.dismiss() |
799 | listArticulos[indiceDelArtEncontrado].cantTomada = (Math.round(mDialogView.tvResultado.text.toString().toFloat() * 100.0) / 100.0).toFloat() | 807 | listArticulos[indiceDelArtEncontrado].cantTomada = (Math.round(mDialogView.tvResultado.text.toString().toFloat() * 100.0) / 100.0).toFloat() |
800 | updateCantidad( | 808 | updateCantidad( |
801 | listArticulos[indiceDelArtEncontrado].sector.toString(), | 809 | listArticulos[indiceDelArtEncontrado].sector.toString(), |
802 | listArticulos[indiceDelArtEncontrado].codigo.toString(), | 810 | listArticulos[indiceDelArtEncontrado].codigo.toString(), |
803 | (Math.round(mDialogView.tvResultado.text.toString().toFloat() * 100.0) / 100.0).toFloat() | 811 | (Math.round(mDialogView.tvResultado.text.toString().toFloat() * 100.0) / 100.0).toFloat() |
804 | ) | 812 | ) |
805 | 813 | ||
806 | viewAdapter.notifyDataSetChanged() | 814 | viewAdapter.notifyDataSetChanged() |
807 | } else if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { | 815 | } else if (mDialogView.tvNuevaCantidad.text.isNotEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { |
808 | mDialogView.tvResultado.error = "Operación Requerida" | 816 | mDialogView.tvResultado.error = "Operación Requerida" |
809 | mDialogView.tvResultado.requestFocus() | 817 | mDialogView.tvResultado.requestFocus() |
810 | mDialogView.tvResultado.hint = "Seleccione Operación" | 818 | mDialogView.tvResultado.hint = "Seleccione Operación" |
811 | } | 819 | } |
812 | } else if (mDialogView.tvNuevaCantidad.text.isEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { | 820 | } else if (mDialogView.tvNuevaCantidad.text.isEmpty() || mDialogView.tvNuevaCantidad.text.isBlank()) { |
813 | mDialogView.tvNuevaCantidad.error = "Completar" | 821 | mDialogView.tvNuevaCantidad.error = "Completar" |
814 | mDialogView.tvNuevaCantidad.requestFocus() | 822 | mDialogView.tvNuevaCantidad.requestFocus() |
815 | mDialogView.tvNuevaCantidad.hint = "Ingrese un valor" | 823 | mDialogView.tvNuevaCantidad.hint = "Ingrese un valor" |
816 | } | 824 | } |
817 | } | 825 | } |
818 | mDialogView.dialogCancelBtn.setOnClickListener { | 826 | mDialogView.dialogCancelBtn.setOnClickListener { |
819 | mAlertDialog.dismiss() | 827 | mAlertDialog.dismiss() |
820 | } | 828 | } |
821 | } | 829 | } |
822 | 830 | ||
823 | suspend fun buscarCodiogoOriEnBD(CodOri: String): List<Articles> { | 831 | suspend fun buscarCodiogoOriEnBD(CodOri: String): List<Articles> { |
824 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 832 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
825 | var busqueda: List<Articles> | 833 | var busqueda: List<Articles> |
826 | return GlobalScope.async(IO) { | 834 | return GlobalScope.async(IO) { |
827 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByCodOri(CodOri, SerchAreaInventario()) | 835 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByCodOri(CodOri, SerchAreaInventario()) |
828 | return@async busqueda | 836 | return@async busqueda |
829 | }.await() | 837 | }.await() |
830 | } | 838 | } |
831 | 839 | ||
840 | suspend fun findArticuloByCodOriNoArea(CodOri: String): List<Articles> { | ||
841 | //TODO BUSQUEDA POR CODIGO DE BARRAS | ||
842 | var busqueda: List<Articles> | ||
843 | return GlobalScope.async(IO) { | ||
844 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByCodOriNoArea(CodOri) | ||
845 | return@async busqueda | ||
846 | }.await() | ||
847 | } | ||
832 | suspend fun buscarCBEnBD(CodigoBarras: String): Articles? { | 848 | suspend fun buscarCBEnBD(CodigoBarras: String): Articles? { |
833 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 849 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
834 | var busqueda: Articles? = null | 850 | var busqueda: Articles? = null |
835 | return GlobalScope.async(IO) { | 851 | return GlobalScope.async(IO) { |
836 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByCodBar(CodigoBarras, SerchAreaInventario()) | 852 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByCodBar(CodigoBarras, SerchAreaInventario()) |
837 | return@async busqueda | 853 | return@async busqueda |
838 | }.await() | 854 | }.await() |
839 | } | 855 | } |
840 | 856 | ||
841 | suspend fun buscarCodigoDeboEnBD(sector: String?, codigo: String?): Articles? { | 857 | suspend fun findArticuloByCodBarNoArea(codigoBarras: String): Articles? { |
842 | //TODO BUSQUEDA POR CODIGO DE BARRAS | 858 | //TODO BUSQUEDA POR CODIGO DE BARRAS |
843 | var busqueda: Articles? | 859 | var busqueda: Articles? |
844 | return GlobalScope.async(IO) { | 860 | return GlobalScope.async(IO) { |
845 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.fetchArticuloByCodSec(sector, codigo) | 861 | busqueda = AppDb.getAppDb(requireContext())!!.ArticulosDAO()!!.findArticuloByCodBarNoArea(codigoBarras) |
846 | return@async busqueda | 862 | return@async busqueda |
847 | }.await() | 863 | }.await() |
848 | } | 864 | } |
849 | 865 | ||
850 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { | 866 | suspend fun buscarDescEnBD(descripcion: String): List<Articles>? { |
851 | //TODO BUSQUEDA POR DESCRIPCION | 867 | //TODO BUSQUEDA POR DESCRIPCION |
852 | var busqueda: List<Articles>? = null | 868 | var busqueda: List<Articles>? = null |
853 | return GlobalScope.async(IO) { | 869 | return GlobalScope.async(IO) { |
854 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, SerchAreaInventario()) | 870 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByDesc(descripcion, SerchAreaInventario()) |
855 | return@async busqueda | 871 | return@async busqueda |
856 | }.await() | 872 | }.await() |
857 | } | 873 | } |
858 | 874 | ||
875 | suspend fun findArticuloByDescNoArea(descripcion: String): List<Articles>? { | ||
876 | //TODO BUSQUEDA POR DESCRIPCION | ||
877 | var busqueda: List<Articles>? = null | ||
878 | return GlobalScope.async(IO) { | ||
879 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByDescNoArea(descripcion) | ||
880 | return@async busqueda | ||
881 | }.await() | ||
882 | } | ||
859 | suspend fun borrarArticulo(sector: String, codigo: String, inventario: String): Int? { | 883 | suspend fun borrarArticulo(sector: String, codigo: String, inventario: String): Int? { |
860 | //TODO BUSQUEDA POR DESCRIPCION | 884 | //TODO BUSQUEDA POR DESCRIPCION |
861 | var result: Int | 885 | var result: Int |
862 | return GlobalScope.async(IO) { | 886 | return GlobalScope.async(IO) { |
863 | result = AppDb.getAppDb((activity as MainActivity))!!.InvBodyDAO()!!.deleteItemFromInvBody(sector.toLong(), codigo.toLong(), inventario.toInt()) | 887 | result = AppDb.getAppDb((activity as MainActivity))!!.InvBodyDAO()!!.deleteItemFromInvBody(sector.toLong(), codigo.toLong(), inventario.toInt()) |
864 | return@async result | 888 | return@async result |
865 | }.await() | 889 | }.await() |
866 | } | 890 | } |
867 | 891 | ||
868 | private suspend fun buscoArtEnRv(codigoBarras: String, sTipoBusqueda: Int): Int { | 892 | private suspend fun buscoArtEnRv(codigoBarras: String, sTipoBusqueda: Int): Int { |
869 | return GlobalScope.async(IO) { | 893 | return GlobalScope.async(IO) { |
870 | var indice = 0 | 894 | var indice = 0 |
871 | var bEncontrado = false | 895 | var bEncontrado = false |
872 | if (sTipoBusqueda == 0) {//TODO BUSQUEDA POR CODIGO DE BARRAS | 896 | if (sTipoBusqueda == 0) {//TODO BUSQUEDA POR CODIGO DE BARRAS |
873 | // TODO CAMBIO DE CB A CODIGO DEBO | 897 | // TODO CAMBIO DE CB A CODIGO DEBO |
874 | val any = cambioCBporCodigoDebo(codigoBarras) | 898 | val any = cambioCBporCodigoDebo(codigoBarras) |
875 | if (any != null) { | 899 | if (any != null) { |
876 | for (item in listArticulos) { | 900 | for (item in listArticulos) { |
877 | if (item.sector!!.toInt() == any.sector!!.toInt() && item.codigo!!.toInt() == any.codigo!!.toInt()) { | 901 | if (item.sector!!.toInt() == any.sector!!.toInt() && item.codigo!!.toInt() == any.codigo!!.toInt()) { |
878 | bEncontrado = true | 902 | bEncontrado = true |
879 | break | 903 | break |
880 | } | 904 | } |
881 | indice += 1 | 905 | indice += 1 |
882 | } | 906 | } |
883 | } | 907 | } |
884 | 908 | ||
885 | 909 | ||
886 | } else if (sTipoBusqueda == 1) {//TODO BUSQUEDA POR DESCRIPCION | 910 | } else if (sTipoBusqueda == 1) {//TODO BUSQUEDA POR DESCRIPCION |
887 | for (item in listArticulos) { | 911 | for (item in listArticulos) { |
888 | if (item.descripcion!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 912 | if (item.descripcion!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
889 | bEncontrado = true | 913 | bEncontrado = true |
890 | break | 914 | break |
891 | } | 915 | } |
892 | indice += 1 | 916 | indice += 1 |
893 | } | 917 | } |
894 | } else if (sTipoBusqueda == 2) {//TODO BUSQUEDA POR CODIGO DE ORIGEN | 918 | } else if (sTipoBusqueda == 2) {//TODO BUSQUEDA POR CODIGO DE ORIGEN |
895 | for (item in listArticulos) { | 919 | for (item in listArticulos) { |
896 | if (item.codigoOrigen!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { | 920 | if (item.codigoOrigen!!.toUpperCase(Locale.ROOT).contains(codigoBarras)) { |
897 | bEncontrado = true | 921 | bEncontrado = true |
898 | break | 922 | break |
899 | } | 923 | } |
900 | indice += 1 | 924 | indice += 1 |
901 | } | 925 | } |
902 | } | 926 | } |
903 | return@async if (bEncontrado) indice else -1 | 927 | return@async if (bEncontrado) indice else -1 |
904 | }.await() | 928 | }.await() |
905 | } | 929 | } |
906 | 930 | ||
907 | suspend fun cambioCBporCodigoDebo(codigoBarras: String): Articles? { | 931 | suspend fun cambioCBporCodigoDebo(codigoBarras: String): Articles? { |
908 | //TODO BUSQUEDA POR DESCRIPCION | 932 | //TODO BUSQUEDA POR DESCRIPCION |
909 | var busqueda: Articles? = null | 933 | var busqueda: Articles? = null |
910 | return GlobalScope.async(IO) { | 934 | return GlobalScope.async(IO) { |
911 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByCodBar(codigoBarras, SerchAreaInventario()) | 935 | busqueda = AppDb.getAppDb((activity as MainActivity))!!.ArticulosDAO()!!.findArticuloByCodBar(codigoBarras, SerchAreaInventario()) |
912 | return@async busqueda | 936 | return@async busqueda |
913 | }.await() | 937 | }.await() |
914 | } | 938 | } |
915 | 939 | ||
916 | private fun cargarArtEnBd(articulos: Articles, cant: String) { | 940 | private fun cargarArtEnBd(articulos: Articles, cant: String) { |
917 | val body = InvBody( | 941 | val body = InvBody( |
918 | (inventarioViewModel as InventarioViewModel).InventarioNuevo,// TODO PREPARO PARA MANDAR A CARGAR EN LA BD | 942 | (inventarioViewModel as InventarioViewModel).InventarioNuevo,// TODO PREPARO PARA MANDAR A CARGAR EN LA BD |
919 | articulos.sector, | 943 | articulos.sector, |
920 | articulos.codigo, | 944 | articulos.codigo, |
921 | articulos.descripcion, | 945 | articulos.descripcion, |
922 | cant, | 946 | cant, |
923 | articulos.codBar, | 947 | articulos.codBar, |
924 | articulos.codOrigen, | 948 | articulos.codOrigen, |
925 | articulos.precio, | 949 | articulos.precio, |
926 | articulos.precio, | 950 | articulos.precio, |
927 | articulos.balanza, | 951 | articulos.balanza, |
928 | articulos.depSn, | 952 | articulos.depSn, |
929 | obtenerFechaActual(), | 953 | obtenerFechaActual(), |
930 | obtenerFechaActual() | 954 | obtenerFechaActual() |
931 | ) | 955 | ) |
932 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS | 956 | InsertarArtEnDB(body)// TODO MANDO A CARGAR A LA BASE DE DATOS |
933 | } | 957 | } |
934 | 958 | ||
935 | fun cargarRecicler(articulos: Articles, cant: Float) { | 959 | fun cargarRecicler(articulos: Articles, cant: Float) { |
936 | //TODO CARGO EN LE RV | 960 | //TODO CARGO EN LE RV |
937 | val item = ItemsRecycler( | 961 | val item = ItemsRecycler( |
938 | if (articulos.sector.toString().toInt() < 9) "0${articulos.sector.toString()}" else articulos.sector.toString(), | 962 | if (articulos.sector.toString().toInt() < 9) "0${articulos.sector.toString()}" else articulos.sector.toString(), |
939 | articulos.codigo, | 963 | articulos.codigo, |
940 | articulos.descripcion, | 964 | articulos.descripcion, |
941 | cant, | 965 | cant, |
942 | articulos.codBar, | 966 | articulos.codBar, |
943 | articulos.codOrigen, | 967 | articulos.codOrigen, |
944 | articulos.balanza.toString(), | 968 | articulos.balanza.toString(), |
945 | articulos.de.toString() | 969 | articulos.de.toString() |
946 | ) | 970 | ) |
947 | listArticulos.add(item) | 971 | listArticulos.add(item) |
948 | 972 | ||
949 | viewAdapter = ProductosListAdapter(requireContext(), listArticulos, this) | 973 | viewAdapter = ProductosListAdapter(requireContext(), listArticulos, this) |
950 | viewManager = LinearLayoutManager(requireContext()) | 974 | viewManager = LinearLayoutManager(requireContext()) |
951 | deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! | 975 | deleteIcon = ContextCompat.getDrawable(requireContext(), R.drawable.borrar)!! |
952 | rcInventarios.apply { | 976 | rcInventarios.apply { |
953 | adapter = viewAdapter | 977 | adapter = viewAdapter |
954 | layoutManager = viewManager | 978 | layoutManager = viewManager |
955 | } | 979 | } |
956 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { | 980 | val itemTouchHelperCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) { |
957 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { | 981 | override fun onMove(p0: RecyclerView, p1: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { |
958 | return false | 982 | return false |
959 | } | 983 | } |
960 | 984 | ||
961 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | 985 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { |
962 | 986 | ||
963 | GlobalScope.launch(Dispatchers.Main) { | 987 | GlobalScope.launch(Dispatchers.Main) { |
964 | borrarArticulo( | 988 | borrarArticulo( |
965 | listArticulos[viewHolder.adapterPosition].sector.toString(), | 989 | listArticulos[viewHolder.adapterPosition].sector.toString(), |
966 | listArticulos[viewHolder.adapterPosition].codigo.toString(), | 990 | listArticulos[viewHolder.adapterPosition].codigo.toString(), |
967 | (inventarioViewModel as InventarioViewModel).InventarioNuevo.toString() | 991 | (inventarioViewModel as InventarioViewModel).InventarioNuevo.toString() |
968 | ) | 992 | ) |
969 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) | 993 | (viewAdapter as ProductosListAdapter).removeItem(viewHolder) |
970 | viewAdapter.notifyDataSetChanged() | 994 | viewAdapter.notifyDataSetChanged() |
971 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, false, requireContext()) | 995 | modificarCantidadEnCabecera((inventarioViewModel as InventarioViewModel).InventarioNuevo, false, requireContext()) |
972 | } | 996 | } |
973 | } | 997 | } |
974 | 998 | ||
975 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { | 999 | override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { |
976 | val itemView = viewHolder.itemView | 1000 | val itemView = viewHolder.itemView |
977 | val iconMargin = (itemView.height - deleteIcon.intrinsicHeight) / 2 | 1001 | val iconMargin = (itemView.height - deleteIcon.intrinsicHeight) / 2 |
978 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) | 1002 | c.clipRect(0f, itemView.top.toFloat(), dX, itemView.bottom.toFloat()) |
979 | 1003 | ||
980 | if (dX > 0) { | 1004 | if (dX > 0) { |
981 | 1005 | ||
982 | if (dX < c.width / 2) c.drawColor(Color.GREEN) | 1006 | if (dX < c.width / 2) c.drawColor(Color.GREEN) |
983 | else c.drawColor(Color.RED) | 1007 | else c.drawColor(Color.RED) |
984 | deleteIcon.setBounds(itemView.left + iconMargin, itemView.top + iconMargin, itemView.left + iconMargin + deleteIcon.intrinsicWidth, itemView.bottom - iconMargin) | 1008 | deleteIcon.setBounds(itemView.left + iconMargin, itemView.top + iconMargin, itemView.left + iconMargin + deleteIcon.intrinsicWidth, itemView.bottom - iconMargin) |
985 | } else { | 1009 | } else { |
986 | } | 1010 | } |
987 | 1011 | ||
988 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) | 1012 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) |
989 | deleteIcon.draw(c) | 1013 | deleteIcon.draw(c) |
990 | } | 1014 | } |
991 | } | 1015 | } |
992 | 1016 | ||
993 | val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback) | 1017 | val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback) |
994 | itemTouchHelper.attachToRecyclerView(rcInventarios) | 1018 | itemTouchHelper.attachToRecyclerView(rcInventarios) |
995 | } | 1019 | } |
996 | 1020 | ||
997 | private fun ProdNoCont(): Int? { | 1021 | private fun ProdNoCont(): Int? { |
998 | var mostrarStock = 0 | 1022 | var mostrarStock = 0 |
999 | if (sharedPreferences.contains("cbMostrarStock")) if (sharedPreferences.getString("cbMostrarStock", "").toString() == "1") mostrarStock = 1 | 1023 | if (sharedPreferences.contains("cbMostrarStock")) if (sharedPreferences.getString("cbMostrarStock", "").toString() == "1") mostrarStock = 1 |
1000 | return mostrarStock | 1024 | return mostrarStock |
1001 | } | 1025 | } |
1002 | 1026 | ||
1003 | private fun AjusteProductos(): Int? { | 1027 | private fun AjusteProductos(): Int? { |
1004 | var prodInclu = 0 | 1028 | var prodInclu = 0 |
1005 | if (sharedPreferences.contains("rbProInclu")) if (sharedPreferences.getString("rbProInclu", "").toString() == "1") prodInclu = 1 | 1029 | if (sharedPreferences.contains("rbProInclu")) if (sharedPreferences.getString("rbProInclu", "").toString() == "1") prodInclu = 1 |
1006 | 1030 | ||
1007 | if (sharedPreferences.contains("rbProNoInclu")) if (sharedPreferences.getString("rbProNoInclu", "").toString() == "0") prodInclu = 0 | 1031 | if (sharedPreferences.contains("rbProNoInclu")) if (sharedPreferences.getString("rbProNoInclu", "").toString() == "0") prodInclu = 0 |
1008 | return prodInclu | 1032 | return prodInclu |
1009 | } | 1033 | } |
1010 | 1034 | ||
1011 | private fun SerchArea(): Boolean { | 1035 | private fun SerchArea(): Boolean { |
1012 | if (sharedPreferences.contains("rbVentas")) if (sharedPreferences.getString("rbVentas", "").toString() == "1") iArea = false | 1036 | if (sharedPreferences.contains("rbVentas")) if (sharedPreferences.getString("rbVentas", "").toString() == "1") iArea = false |
1013 | if (sharedPreferences.contains("rbDeposito")) if (sharedPreferences.getString("rbDeposito", "").toString() == "1") iArea = true | 1037 | if (sharedPreferences.contains("rbDeposito")) if (sharedPreferences.getString("rbDeposito", "").toString() == "1") iArea = true |
1014 | return iArea | 1038 | return iArea |
1015 | } | 1039 | } |
1016 | 1040 | ||
1017 | private suspend fun SerchAreaInventario(): Boolean { | 1041 | private suspend fun SerchAreaInventario(): Boolean { |
1018 | return GlobalScope.async(IO) { | 1042 | return GlobalScope.async(IO) { |
1019 | return@async AppDb.getAppDb((activity as MainActivity))!!.InvHeadDAO()!!.fetchAreaInvH((inventarioViewModel as InventarioViewModel).InventarioNuevo) | 1043 | return@async AppDb.getAppDb((activity as MainActivity))!!.InvHeadDAO()!!.fetchAreaInvH((inventarioViewModel as InventarioViewModel).InventarioNuevo) |
1020 | }.await() | 1044 | }.await() |
1021 | 1045 | ||
1022 | } | 1046 | } |
1023 | 1047 | ||
1024 | private fun InsertarArtEnDB(cuarpoInventario: InvBody) { | 1048 | private fun InsertarArtEnDB(cuarpoInventario: InvBody) { |
1025 | lifecycleScope.launch { | 1049 | lifecycleScope.launch { |
1026 | withContext(Dispatchers.IO) { | 1050 | withContext(IO) { |
1027 | AppDb.getAppDb((activity as MainActivity))!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) | 1051 | AppDb.getAppDb((activity as MainActivity))!!.InvBodyDAO()!!.insertInvBody(cuarpoInventario) |
1028 | } | 1052 | } |
1029 | } | 1053 | } |
1030 | } | 1054 | } |
1031 | 1055 | ||
1032 | private fun updateCantidad(sector: String, codigo: String, cantidad: Float) { | 1056 | private fun updateCantidad(sector: String, codigo: String, cantidad: Float) { |
1033 | lifecycleScope.launch { | 1057 | lifecycleScope.launch { |
1034 | withContext(IO) { | 1058 | withContext(IO) { |
1035 | AppDb.getAppDb((activity as MainActivity))!!.InvBodyDAO()!!.updateInvBody(cantidad, sector.toLong(), codigo.toLong(), obtenerFechaActual()) | 1059 | AppDb.getAppDb((activity as MainActivity))!!.InvBodyDAO()!!.updateInvBody(cantidad, sector.toLong(), codigo.toLong(), obtenerFechaActual()) |
1036 | } | 1060 | } |
1037 | } | 1061 | } |
1038 | } | 1062 | } |
1039 | 1063 | ||
1040 | private suspend fun cargarInventario(inventario: Int): List<InvBody>? { | 1064 | private suspend fun cargarInventario(inventario: Int): List<InvBody>? { |
1041 | return GlobalScope.async(IO) { | 1065 | return GlobalScope.async(IO) { |
1042 | return@async AppDb.getAppDb((activity as MainActivity))!!.InvBodyDAO()!!.fetchAllInvBody(inventario) | 1066 | return@async AppDb.getAppDb((activity as MainActivity))!!.InvBodyDAO()!!.fetchAllInvBody(inventario) |
1043 | }.await() | 1067 | }.await() |
1044 | } | 1068 | } |
1045 | 1069 | ||
1046 | override fun onImageDotsClick(sector: String?, codigo: String?) { | 1070 | override fun onImageDotsClick(sector: String?, codigo: String?) { |
1047 | val bundle = Bundle() | 1071 | val bundle = Bundle() |
1048 | bundle.putString("sector", sector!!.toInt().toString()) | 1072 | bundle.putString("sector", sector!!.toInt().toString()) |
1049 | bundle.putString("codigo", codigo) | 1073 | bundle.putString("codigo", codigo) |
1050 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) | 1074 | bundle.putInt("numeroInv", (inventarioViewModel as InventarioViewModel).InventarioNuevo) |
1051 | navController.navigate(R.id.action_inventarioFragment_to_detalleArtFragment, bundle) | 1075 | navController.navigate(R.id.action_inventarioFragment_to_detalleArtFragment, bundle) |
1052 | } | 1076 | } |
1053 | 1077 | ||
1054 | override fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) { | 1078 | override fun onImagePenClick(sector: String?, codigo: String?, cantidad: String?, position: String) { |
1055 | dialogoSumaResta(requireContext(), position.toInt(), listArticulos[position.toInt()].univta, true) | 1079 | dialogoSumaResta(requireContext(), position.toInt(), listArticulos[position.toInt()].univta, true) |
1056 | } | 1080 | } |
1057 | 1081 | ||
1058 | private val textWatcher = object : TextWatcher { | 1082 | private val textWatcher = object : TextWatcher { |
1059 | override fun afterTextChanged(s: Editable?) { | 1083 | override fun afterTextChanged(s: Editable?) { |
1060 | if (mDialogView.tvNuevaCantidad.text.toString() == "") { | 1084 | if (mDialogView.tvNuevaCantidad.text.toString() == "") { |
1061 | mDialogView.tvResultado.text = "" | 1085 | mDialogView.tvResultado.text = "" |
1062 | } | 1086 | } |
1063 | } | 1087 | } |
1064 | 1088 | ||
1065 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} | 1089 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} |
1066 | 1090 | ||
1067 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { | 1091 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { |
1068 | var cantidadTemp: Float | 1092 | var cantidadTemp: Float |
1069 | if (mDialogView.tvNuevaCantidad.text.toString() != "") { | 1093 | if (mDialogView.tvNuevaCantidad.text.toString() != "") { |
1070 | if (mDialogView.rbSumar.isChecked) { | 1094 | if (mDialogView.rbSumar.isChecked) { |
1071 | cantidadTemp = mDialogView.tvNuevaCantidad.text.toString().toFloat() + mDialogView.tvCantInicial.text.toString().toFloat() | 1095 | cantidadTemp = mDialogView.tvNuevaCantidad.text.toString().toFloat() + mDialogView.tvCantInicial.text.toString().toFloat() |
1072 | mDialogView.tvResultado.text = (Math.round(cantidadTemp * 100.0) / 100.0).toString() | 1096 | mDialogView.tvResultado.text = (Math.round(cantidadTemp * 100.0) / 100.0).toString() |
1073 | } | 1097 | } |
1074 | if (mDialogView.rbRestar.isChecked) { | 1098 | if (mDialogView.rbRestar.isChecked) { |
1075 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 1099 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
1076 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { | 1100 | if (mDialogView.tvCantInicial.text.toString().toFloat() >= mDialogView.tvNuevaCantidad.text.toString().toFloat()) { |
1077 | cantidadTemp = mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat() | 1101 | cantidadTemp = mDialogView.tvCantInicial.text.toString().toFloat() - mDialogView.tvNuevaCantidad.text.toString().toFloat() |
1078 | mDialogView.tvResultado.text = (Math.round(cantidadTemp * 100.0) / 100.0).toString() | 1102 | mDialogView.tvResultado.text = (Math.round(cantidadTemp * 100.0) / 100.0).toString() |
1079 | // mDialogView.tvNuevaCantidad.isEnabled = false | 1103 | // mDialogView.tvNuevaCantidad.isEnabled = false |
1080 | } else { | 1104 | } else { |
1081 | mDialogView.tvResultado.text = "" | 1105 | mDialogView.tvResultado.text = "" |
1082 | mDialogView.tvResultado.error = "Operación No Valida" | 1106 | mDialogView.tvResultado.error = "Operación No Valida" |
1083 | mDialogView.tvResultado.requestFocus() | 1107 | mDialogView.tvResultado.requestFocus() |
1084 | mDialogView.tvResultado.hint = "Error" | 1108 | mDialogView.tvResultado.hint = "Error" |
1085 | } | 1109 | } |
1086 | } | 1110 | } |
1087 | } | 1111 | } |
1088 | if (mDialogView.rbMdodificar.isChecked) { | 1112 | if (mDialogView.rbMdodificar.isChecked) { |
1089 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { | 1113 | if (!mDialogView.tvNuevaCantidad.text.isNullOrEmpty()) { |
1090 | mDialogView.tvResultado.text = (Math.round(mDialogView.tvNuevaCantidad.text.toString().toFloat() * 100.0) / 100.0).toString() | 1114 | mDialogView.tvResultado.text = (Math.round(mDialogView.tvNuevaCantidad.text.toString().toFloat() * 100.0) / 100.0).toString() |
1091 | } | 1115 | } |
1092 | } | 1116 | } |
1093 | } | 1117 | } |
1094 | } | 1118 | } |
1095 | } | 1119 | } |
1096 | } | 1120 | } |
1097 | 1121 | ||
1098 | 1122 | ||
1099 | 1123 | ||
1100 | 1124 | ||
1101 | 1125 | ||
1102 | 1126 | ||
1103 | 1127 | ||
1104 | 1128 | ||
1105 | 1129 | ||
1106 | 1130 | ||
1107 | 1131 | ||
1108 | 1132 | ||
1109 | 1133 | ||
1110 | 1134 |
app/src/main/res/values/strings.xml
1 | <resources> | 1 | <resources> |
2 | 2 | ||
3 | <string name="action_settings">Ayuda</string> | 3 | <string name="action_settings">Ayuda</string> |
4 | <string name="app_name">DEBO Inventarios</string> | 4 | <string name="app_name">DEBO Inventarios</string> |
5 | 5 | ||
6 | <!-- menu--> | 6 | <!-- menu--> |
7 | <string name="menuInicio">Principal</string> | 7 | <string name="menuInicio">Principal</string> |
8 | <string name="menuNueInv">Nuevo Inventario</string> | 8 | <string name="menuNueInv">Nuevo Inventario</string> |
9 | <string name="menuActMae">Importaciones</string> | 9 | <string name="menuActMae">Importaciones</string> |
10 | <string name="menuConf">Configuraciones</string> | 10 | <string name="menuConf">Configuraciones</string> |
11 | <string name="menuSal">Salir</string> | 11 | <string name="menuSal">Salir</string> |
12 | 12 | ||
13 | <!-- Menu header--> | 13 | <!-- Menu header--> |
14 | <string name="menuLeyenda">Debo Inventario</string> | 14 | <string name="menuLeyenda">Debo Inventario</string> |
15 | 15 | ||
16 | <string name="navigation_drawer_open">Open navigation drawer</string> | 16 | <string name="navigation_drawer_open">Open navigation drawer</string> |
17 | <string name="navigation_drawer_close">Close navigation drawer</string> | 17 | <string name="navigation_drawer_close">Close navigation drawer</string> |
18 | 18 | ||
19 | <!-- Pantalla de inicio--> | 19 | <!-- Pantalla de inicio--> |
20 | <string name="bien">Bienvenido</string> | 20 | <string name="bien">Bienvenido</string> |
21 | <string name="debo">DEBO®</string> | 21 | <string name="debo">DEBO®</string> |
22 | <string name="inventario">Inventario</string> | 22 | <string name="inventario">Inventario</string> |
23 | 23 | ||
24 | <!-- inventarios dinamicos--> | 24 | <!-- inventarios dinamicos--> |
25 | <string name="invDinamicoVenta">Inventarios Dinámicos (0) +</string> | 25 | <string name="invDinamicoVenta">Inventarios Dinámicos (0) +</string> |
26 | <string name="invDinamicoCompra">Inventarios Importados(0) +</string> | 26 | <string name="invDinamicoCompra">Inventarios Importados(0) +</string> |
27 | 27 | ||
28 | <!-- ventana emergente--> | 28 | <!-- ventana emergente--> |
29 | <string name="adv">Ingrese la cantidad contada</string> | 29 | <string name="adv">Ingrese la cantidad contada</string> |
30 | <string name="tvFechayHora">Error de fecha y hora</string> | 30 | <string name="tvFechayHora">Error de fecha y hora</string> |
31 | <string name="invVentas">Inventarios Dinámicos de Ventas</string> | 31 | <string name="invVentas">Inventarios Dinámicos de Ventas</string> |
32 | <string name="btnCancela">Cancelar</string> | 32 | <string name="btnCancela">Cancelar</string> |
33 | 33 | ||
34 | 34 | ||
35 | <!-- Fragment Inventario--> | 35 | <!-- Fragment Inventario--> |
36 | <string name="invTitulo">Inventarios Dinámicos</string> | 36 | <string name="invTitulo"> </string> |
37 | <string name="invTituloV">Inventarios de Ventas</string> | 37 | <string name="invTituloV">Inventarios de Ventas</string> |
38 | <string name="invTituloD">Inventarios de Depósitos</string> | 38 | <string name="invTituloD">Inventarios de Depósitos</string> |
39 | <string name="invCodigoBarras">Código Barras:</string> | 39 | <string name="invCodigoBarras">Código Barras:</string> |
40 | <string name="btnExportarInv">Exportar Inventario</string> | 40 | <string name="btnExportarInv">Exportar Inventario</string> |
41 | <string name="btnBorrarInv">Borrar Inventario</string> | 41 | <string name="btnBorrarInv">Borrar Inventario</string> |
42 | <string name="ibBusDesc">Búsqueda por Descripción</string> | 42 | <string name="ibBusDesc">Búsqueda por Descripción</string> |
43 | <string name="ibBusCB">Búsqueda por Código Barras</string> | 43 | <string name="ibBusCB">Búsqueda por Código Barras</string> |
44 | <string name="ibBusCO">Búsqueda por Código de Origen</string> | 44 | <string name="ibBusCO">Búsqueda por Código de Origen</string> |
45 | <string name="switch_1">+ 1</string> | 45 | <string name="switch_1">+ 1</string> |
46 | 46 | ||
47 | <!-- Fragmento Configuraciones--> | 47 | <!-- Fragmento Configuraciones--> |
48 | <string name="tvTituloConf">Configuraciones</string> | 48 | <string name="tvTituloConf">Configuraciones</string> |
49 | <string name="tvSeleccioneServidor">Seleccione un Servidor</string> | 49 | <string name="tvSeleccioneServidor">Seleccione un Servidor</string> |
50 | <string name="btnValidarServidor">Validar</string> | 50 | <string name="btnValidarServidor">Validar</string> |
51 | <string name="btnAgregarServidor">Agregar un nuevo servidor</string> | 51 | <string name="btnAgregarServidor">Agregar un nuevo servidor</string> |
52 | <string name="tvUbicacionCarpetas">Ubicación de las carpetas de uso interno</string> | 52 | <string name="tvUbicacionCarpetas">Ubicación de las carpetas de uso interno</string> |
53 | <string name="tvTituloArea">Area de Inventario</string> | 53 | <string name="tvTituloArea">Area de Inventario</string> |
54 | <string name="rbVentas">Inventarios de Ventas</string> | 54 | <string name="rbVentas">Inventarios de Ventas</string> |
55 | <string name="rbDeposito">Inventarios de Depositos</string> | 55 | <string name="rbDeposito">Inventarios de Depositos</string> |
56 | <string name="tvLosProductos">Para los productos no contabilizados en Inventarios</string> | 56 | <string name="tvLosProductos">Para los productos no contabilizados en Inventarios</string> |
57 | <string name="tvColumnas">Columnas a Visualizar</string> | 57 | <string name="tvColumnas">Columnas a Visualizar</string> |
58 | 58 | ||
59 | <string name="rbProInclu">Solo se ajustan los productos incluidos en el conteo.</string> | 59 | <string name="rbProInclu">Solo se ajustan los productos incluidos en el conteo.</string> |
60 | <string name="rbProNoInclu">Ajustar los productos no incluidos en el conteo con stock en cero.</string> | 60 | <string name="rbProNoInclu">Ajustar los productos no incluidos en el conteo con stock en cero.</string> |
61 | 61 | ||
62 | <string name="cbMostrarStock">Mostror stock en el sistema al momento de la descarga del maestro.</string> | 62 | <string name="cbMostrarStock">Mostror stock en el sistema al momento de la descarga del maestro.</string> |
63 | <string name="cbHabiLectura">Habilitar Lectura de código de barras en balanza.</string> | 63 | <string name="cbHabiLectura">Habilitar Lectura de código de barras en balanza.</string> |
64 | 64 | ||
65 | <string name="tvColumMostrar">Columnas a mostrar en inventario</string> | 65 | <string name="tvColumMostrar">Columnas a mostrar en inventario</string> |
66 | 66 | ||
67 | <string name="rbCodigoDebo">Código DEBO</string> | 67 | <string name="rbCodigoDebo">Código DEBO</string> |
68 | <string name="rbCodigoOrigen">Código Origen</string> | 68 | <string name="rbCodigoOrigen">Código Origen</string> |
69 | <string name="rbCodigoBarras">Código de Barras</string> | 69 | <string name="rbCodigoBarras">Código de Barras</string> |
70 | 70 | ||
71 | <string name="leyendaSpinner">Seleccione Servidor Predeterminado</string> | 71 | <string name="leyendaSpinner">Seleccione Servidor Predeterminado</string> |
72 | 72 | ||
73 | <string name="btnAskTimeServer">Fecha y hora Servidor</string> | 73 | <string name="btnAskTimeServer">Fecha y hora Servidor</string> |
74 | <string name="cbAskTimeServerToStart">Verificar fecha y hora al iniciar.</string> | 74 | <string name="cbAskTimeServerToStart">Verificar fecha y hora al iniciar.</string> |
75 | 75 | ||
76 | <string name="btnGuardar">Guardar Cambios</string> | 76 | <string name="btnGuardar">Guardar Cambios</string> |
77 | <string name="todo"> </string> | 77 | <string name="todo"> </string> |
78 | todo | 78 | todo |
79 | <!-- fragment Actualizacion de Maestros--> | 79 | <!-- fragment Actualizacion de Maestros--> |
80 | <string name="tvActMaestros">Importaciones</string> | 80 | <string name="tvActMaestros">Importaciones</string> |
81 | <string name="tvMedio">Seleccione que tipo de importación desea realizar</string> | 81 | <string name="tvMedio">Seleccione que tipo de importación desea realizar</string> |
82 | <string name="tvSeleccionInventario"> Seleccione el inventario a importar</string> | 82 | <string name="tvSeleccionInventario"> Seleccione el inventario a importar</string> |
83 | 83 | ||
84 | <string name="obPorWifi">Importación de artículos</string> | 84 | <string name="obPorWifi">Importación de artículos</string> |
85 | <string name="obViaArchivo">Importación de inventarios</string> | 85 | <string name="obViaArchivo">Importación de inventarios</string> |
86 | 86 | ||
87 | <string name="btnConfirmarAct">Confirmar Importación</string> | 87 | <string name="btnConfirmarAct">Confirmar Importación</string> |
88 | <string name="btnConfirmarInv">Confirmar Inventarios</string> | 88 | <string name="btnConfirmarInv">Confirmar Inventarios</string> |
89 | 89 | ||
90 | <!-- Fragment Save--> | 90 | <!-- Fragment Save--> |
91 | <string name="tvConfServi">Configuración de Servidores</string> | 91 | <string name="tvConfServi">Configuración de Servidores</string> |
92 | <string name="server">Ingrese la dirección del servidor</string> | 92 | <string name="server">Ingrese la dirección del servidor</string> |
93 | <string name="etNomServer">Ingrese una descripción para la conexión</string> | 93 | <string name="etNomServer">Ingrese una descripción para la conexión</string> |
94 | <string name="btnGuardarConfServ">Guardar Conexión</string> | 94 | <string name="btnGuardarConfServ">Guardar Conexión</string> |
95 | 95 | ||
96 | <!-- Dialog--> | 96 | <!-- Dialog--> |
97 | <string name="sTitulo">Producto Buscado</string> | 97 | <string name="sTitulo">Producto Buscado</string> |
98 | <string name="btnOk">Aceptar</string> | 98 | <string name="btnOk">Aceptar</string> |
99 | <string name="btnSalir">Salir</string> | 99 | <string name="btnSalir">Salir</string> |
100 | <string name="btnCambiarHora">Configura aquí la fecha y hora </string> | 100 | <string name="btnCambiarHora">Configura aquí la fecha y hora </string> |
101 | 101 | ||
102 | <string name="btnConfirmar">Confirmar</string> | 102 | <string name="btnConfirmar">Confirmar</string> |
103 | <string name="btnCancelar">Cancelar</string> | 103 | <string name="btnCancelar">Cancelar</string> |
104 | <string name="sMensaje">¡No se encontro el producto ingresado!</string> | 104 | <string name="sMensaje">¡No se encontro el producto ingresado!</string> |
105 | <string name="sMensajeEncontrado">¡Ingrese nueva cantidad!</string> | 105 | <string name="sMensajeEncontrado">¡Ingrese nueva cantidad!</string> |
106 | <string name="sTituloNueva">Producto ingresado esta cargado</string> | 106 | <string name="sTituloNueva">Producto ingresado esta cargado</string> |
107 | <string name="sCantidadNueva">¡Por favor ingrese la nueva Cantidad!</string> | 107 | <string name="sCantidadNueva">¡Por favor ingrese la nueva Cantidad!</string> |
108 | 108 | ||
109 | <string name="sMensajeExportar">¡Confirma que exporta el Inventario!</string> | 109 | <string name="sMensajeExportar">¡Confirma que exporta el Inventario!</string> |
110 | <string name="sTituloExportar">Exportación de Inventarios</string> | 110 | <string name="sTituloExportar">Exportación de Inventarios</string> |
111 | 111 | ||
112 | <!-- FRAGMENT SERVIDOR--> | 112 | <!-- FRAGMENT SERVIDOR--> |
113 | <string name="tvTitutloServer">Alta de Servidores</string> | 113 | <string name="tvTitutloServer">Alta de Servidores</string> |
114 | <string name="tvNomServer">Descripción para identificar al servidor</string> | 114 | <string name="tvNomServer">Descripción para identificar al servidor</string> |
115 | <string name="tvDirServer">Dirección del servidor</string> | 115 | <string name="tvDirServer">Dirección del servidor</string> |
116 | <string name="btnGuardarServidores">Guardar Servidor</string> | 116 | <string name="btnGuardarServidores">Guardar Servidor</string> |
117 | 117 | ||
118 | <string name="tvSeleccion">Toque sobre la operación que desea realizar</string> | 118 | <string name="tvSeleccion">Toque sobre la operación que desea realizar</string> |
119 | <string name="rbSumar">Sumar</string> | 119 | <string name="rbSumar">Sumar</string> |
120 | <string name="rbRestar">Restar</string> | 120 | <string name="rbRestar">Restar</string> |
121 | <string name="rbModificar">Reemplazar</string> | 121 | <string name="rbModificar">Reemplazar</string> |
122 | <string name="tvTotal">Cantidad Final</string>tvTotal | 122 | <string name="tvTotal">Cantidad Final</string>tvTotal |
123 | <string name="tvResultado">Resultado:</string>tvTotal | 123 | <string name="tvResultado">Resultado:</string>tvTotal |
124 | 124 | ||
125 | <string name="large_text"> | 125 | <string name="large_text"> |
126 | "Material is the metaphor.\n\n" | 126 | "Material is the metaphor.\n\n" |
127 | 127 | ||
128 | "A material metaphor is the unifying theory of a rationalized space and a system of motion." | 128 | "A material metaphor is the unifying theory of a rationalized space and a system of motion." |
129 | "The material is grounded in tactile reality, inspired by the study of paper and ink, yet " | 129 | "The material is grounded in tactile reality, inspired by the study of paper and ink, yet " |
130 | "technologically advanced and open to imagination and magic.\n" | 130 | "technologically advanced and open to imagination and magic.\n" |
131 | "Surfaces and edges of the material provide visual cues that are grounded in reality. The " | 131 | "Surfaces and edges of the material provide visual cues that are grounded in reality. The " |
132 | "use of familiar tactile attributes helps users quickly understand affordances. Yet the " | 132 | "use of familiar tactile attributes helps users quickly understand affordances. Yet the " |
133 | "flexibility of the material creates new affordances that supercede those in the physical " | 133 | "flexibility of the material creates new affordances that supercede those in the physical " |
134 | "world, without breaking the rules of physics.\n" | 134 | "world, without breaking the rules of physics.\n" |
135 | "The fundamentals of light, surface, and movement are key to conveying how objects move, " | 135 | "The fundamentals of light, surface, and movement are key to conveying how objects move, " |
136 | "interact, and exist in space and in relation to each other. Realistic lighting shows " | 136 | "interact, and exist in space and in relation to each other. Realistic lighting shows " |
137 | "seams, divides space, and indicates moving parts.\n\n" | 137 | "seams, divides space, and indicates moving parts.\n\n" |
138 | 138 | ||
139 | "Bold, graphic, intentional.\n\n" | 139 | "Bold, graphic, intentional.\n\n" |
140 | 140 | ||
141 | "The foundational elements of print based design typography, grids, space, scale, color, " | 141 | "The foundational elements of print based design typography, grids, space, scale, color, " |
142 | "and use of imagery guide visual treatments. These elements do far more than please the " | 142 | "and use of imagery guide visual treatments. These elements do far more than please the " |
143 | "eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge " | 143 | "eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge " |
144 | "imagery, large scale typography, and intentional white space create a bold and graphic " | 144 | "imagery, large scale typography, and intentional white space create a bold and graphic " |
145 | "interface that immerse the user in the experience.\n" | 145 | "interface that immerse the user in the experience.\n" |
146 | "An emphasis on user actions makes core functionality immediately apparent and provides " | 146 | "An emphasis on user actions makes core functionality immediately apparent and provides " |
147 | "waypoints for the user.\n\n" | 147 | "waypoints for the user.\n\n" |
148 | 148 | ||
149 | "Motion provides meaning.\n\n" | 149 | "Motion provides meaning.\n\n" |
150 | 150 | ||
151 | "Motion respects and reinforces the user as the prime mover. Primary user actions are " | 151 | "Motion respects and reinforces the user as the prime mover. Primary user actions are " |
152 | "inflection points that initiate motion, transforming the whole design.\n" | 152 | "inflection points that initiate motion, transforming the whole design.\n" |
153 | "All action takes place in a single environment. Objects are presented to the user without " | 153 | "All action takes place in a single environment. Objects are presented to the user without " |
154 | "breaking the continuity of experience even as they transform and reorganize.\n" | 154 | "breaking the continuity of experience even as they transform and reorganize.\n" |
155 | "Motion is meaningful and appropriate, serving to focus attention and maintain continuity. " | 155 | "Motion is meaningful and appropriate, serving to focus attention and maintain continuity. " |
156 | "Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n" | 156 | "Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n" |
157 | 157 | ||
158 | "3D world.\n\n" | 158 | "3D world.\n\n" |
159 | 159 | ||
160 | "The material environment is a 3D space, which means all objects have x, y, and z " | 160 | "The material environment is a 3D space, which means all objects have x, y, and z " |
161 | "dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the " | 161 | "dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the " |
162 | "positive z-axis extending towards the viewer. Every sheet of material occupies a single " | 162 | "positive z-axis extending towards the viewer. Every sheet of material occupies a single " |
163 | "position along the z-axis and has a standard 1dp thickness.\n" | 163 | "position along the z-axis and has a standard 1dp thickness.\n" |
164 | "On the web, the z-axis is used for layering and not for perspective. The 3D world is " | 164 | "On the web, the z-axis is used for layering and not for perspective. The 3D world is " |
165 | "emulated by manipulating the y-axis.\n\n" | 165 | "emulated by manipulating the y-axis.\n\n" |
166 | 166 | ||
167 | "Light and shadow.\n\n" | 167 | "Light and shadow.\n\n" |
168 | 168 | ||
169 | "Within the material environment, virtual lights illuminate the scene. Key lights create " | 169 | "Within the material environment, virtual lights illuminate the scene. Key lights create " |
170 | "directional shadows, while ambient light creates soft shadows from all angles.\n" | 170 | "directional shadows, while ambient light creates soft shadows from all angles.\n" |
171 | "Shadows in the material environment are cast by these two light sources. In Android " | 171 | "Shadows in the material environment are cast by these two light sources. In Android " |
172 | "development, shadows occur when light sources are blocked by sheets of material at " | 172 | "development, shadows occur when light sources are blocked by sheets of material at " |
173 | "various positions along the z-axis. On the web, shadows are depicted by manipulating the " | 173 | "various positions along the z-axis. On the web, shadows are depicted by manipulating the " |
174 | "y-axis only. The following example shows the card with a height of 6dp.\n\n" | 174 | "y-axis only. The following example shows the card with a height of 6dp.\n\n" |
175 | 175 | ||
176 | "Resting elevation.\n\n" | 176 | "Resting elevation.\n\n" |
177 | 177 | ||
178 | "All material objects, regardless of size, have a resting elevation, or default elevation " | 178 | "All material objects, regardless of size, have a resting elevation, or default elevation " |
179 | "that does not change. If an object changes elevation, it should return to its resting " | 179 | "that does not change. If an object changes elevation, it should return to its resting " |
180 | "elevation as soon as possible.\n\n" | 180 | "elevation as soon as possible.\n\n" |
181 | 181 | ||
182 | "Component elevations.\n\n" | 182 | "Component elevations.\n\n" |
183 | 183 | ||
184 | "The resting elevation for a component type is consistent across apps (e.g., FAB elevation " | 184 | "The resting elevation for a component type is consistent across apps (e.g., FAB elevation " |
185 | "does not vary from 6dp in one app to 16dp in another app).\n" | 185 | "does not vary from 6dp in one app to 16dp in another app).\n" |
186 | "Components may have different resting elevations across platforms, depending on the depth " | 186 | "Components may have different resting elevations across platforms, depending on the depth " |
187 | "of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n" | 187 | "of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n" |
188 | 188 | ||
189 | "Responsive elevation and dynamic elevation offsets.\n\n" | 189 | "Responsive elevation and dynamic elevation offsets.\n\n" |
190 | 190 | ||
191 | "Some component types have responsive elevation, meaning they change elevation in response " | 191 | "Some component types have responsive elevation, meaning they change elevation in response " |
192 | "to user input (e.g., normal, focused, and pressed) or system events. These elevation " | 192 | "to user input (e.g., normal, focused, and pressed) or system events. These elevation " |
193 | "changes are consistently implemented using dynamic elevation offsets.\n" | 193 | "changes are consistently implemented using dynamic elevation offsets.\n" |
194 | "Dynamic elevation offsets are the goal elevation that a component moves towards, relative " | 194 | "Dynamic elevation offsets are the goal elevation that a component moves towards, relative " |
195 | "to the component’s resting state. They ensure that elevation changes are consistent " | 195 | "to the component’s resting state. They ensure that elevation changes are consistent " |
196 | "across actions and component types. For example, all components that lift on press have " | 196 | "across actions and component types. For example, all components that lift on press have " |
197 | "the same elevation change relative to their resting elevation.\n" | 197 | "the same elevation change relative to their resting elevation.\n" |
198 | "Once the input event is completed or cancelled, the component will return to its resting " | 198 | "Once the input event is completed or cancelled, the component will return to its resting " |
199 | "elevation.\n\n" | 199 | "elevation.\n\n" |
200 | 200 | ||
201 | "Avoiding elevation interference.\n\n" | 201 | "Avoiding elevation interference.\n\n" |
202 | 202 | ||
203 | "Components with responsive elevations may encounter other components as they move between " | 203 | "Components with responsive elevations may encounter other components as they move between " |
204 | "their resting elevations and dynamic elevation offsets. Because material cannot pass " | 204 | "their resting elevations and dynamic elevation offsets. Because material cannot pass " |
205 | "through other material, components avoid interfering with one another any number of ways, " | 205 | "through other material, components avoid interfering with one another any number of ways, " |
206 | "whether on a per component basis or using the entire app layout.\n" | 206 | "whether on a per component basis or using the entire app layout.\n" |
207 | "On a component level, components can move or be removed before they cause interference. " | 207 | "On a component level, components can move or be removed before they cause interference. " |
208 | "For example, a floating action button (FAB) can disappear or move off screen before a " | 208 | "For example, a floating action button (FAB) can disappear or move off screen before a " |
209 | "user picks up a card, or it can move if a snackbar appears.\n" | 209 | "user picks up a card, or it can move if a snackbar appears.\n" |
210 | "On the layout level, design your app layout to minimize opportunities for interference. " | 210 | "On the layout level, design your app layout to minimize opportunities for interference. " |
211 | "For example, position the FAB to one side of stream of a cards so the FAB won’t interfere " | 211 | "For example, position the FAB to one side of stream of a cards so the FAB won’t interfere " |
212 | "when a user tries to pick up one of cards.\n\n" | 212 | "when a user tries to pick up one of cards.\n\n" |
213 | </string> | 213 | </string> |
214 | <!-- TODO: Remove or change this placeholder text --> | 214 | <!-- TODO: Remove or change this placeholder text --> |
215 | <string name="hello_blank_fragment">Hello blank fragment</string> | 215 | <string name="hello_blank_fragment">Hello blank fragment</string> |
216 | </resources> | 216 | </resources> |