fixed adding months to product

This commit is contained in:
leca 2024-10-17 20:37:21 +03:00
parent 4e11a7b4b9
commit b1b987e5f6
5 changed files with 6 additions and 11 deletions

View File

@ -79,7 +79,5 @@ fun calculateProductFreshness(dateOfProduction: Long, dateOfExpiry: Long): Doubl
val productLifeSpan = dateOfExpiry - dateOfProduction; val productLifeSpan = dateOfExpiry - dateOfProduction;
val lifeSpanLeft: Long = dateOfExpiry - Date().time / 1000 val lifeSpanLeft: Long = dateOfExpiry - Date().time / 1000
Log.d("QWERTYUIOP", "ProductLifeSpan: ${productLifeSpan}, Lifespan left: ${lifeSpanLeft}, percent: ${lifeSpanLeft / productLifeSpan.toDouble()}")
return lifeSpanLeft / productLifeSpan.toDouble() return lifeSpanLeft / productLifeSpan.toDouble()
} }

View File

@ -167,14 +167,10 @@ class AddProductActivity : AppCompatActivity() {
} }
val c = Calendar.getInstance() val c = Calendar.getInstance()
c.timeInMillis = dateOfProduction * 1000
// val dateOfProductionSplit = dateOfProduction.split(".")
c.set(Calendar.YEAR, Date(dateOfProduction).year)
c.set(Calendar.MONTH, Date(dateOfProduction).month)
c.set(Calendar.DAY_OF_MONTH, Date(dateOfProduction).day)
c.add(Calendar.MONTH, shelfLifeMonths) c.add(Calendar.MONTH, shelfLifeMonths)
dateOfExpiry = SimpleDateFormat("dd.MM.yyyy").parse("${c.get(Calendar.YEAR)}.${c.get(Calendar.MONTH)}.${c.get(Calendar.DAY_OF_MONTH)}").time / 1000 dateOfExpiry = c.timeInMillis / 1000
} }
fun findAndDisplayAbstractProductByBarcode(barcode: String) { fun findAndDisplayAbstractProductByBarcode(barcode: String) {

View File

@ -26,6 +26,7 @@ import org.foxarmy.barcodescannerforemployees.dataclasses.AbstractProduct
import org.foxarmy.barcodescannerforemployees.dataclasses.Product import org.foxarmy.barcodescannerforemployees.dataclasses.Product
import java.io.File import java.io.File
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -100,7 +101,7 @@ class ProductView: LinearLayout {
productNetWeightTextView.text = linkedAbstractProduct.netWeight.toString() productNetWeightTextView.text = linkedAbstractProduct.netWeight.toString()
productAmountTextView.text = product.amount.toString() productAmountTextView.text = product.amount.toString()
productCategoryView.text = DBStorageController(activity).getCategoryNameById(DBStorageController(activity).readableDatabase, linkedAbstractProduct.category) productCategoryView.text = DBStorageController(activity).getCategoryNameById(DBStorageController(activity).readableDatabase, linkedAbstractProduct.category)
productLifeSpan.text = "${Date(product.dateOfProduction*1000)}-${Date(product.dateOfExpiry*1000)}" productLifeSpan.text = "${SimpleDateFormat("dd.MM.yyyy").format(Date(product.dateOfProduction*1000))}-${SimpleDateFormat("dd.MM.yyyy").format(Date(product.dateOfExpiry*1000))}"
productFreshnessTextView.text = productFreshnessTextView.text =
if (product.freshness == Double.NEGATIVE_INFINITY || product.freshness == Double.POSITIVE_INFINITY) { if (product.freshness == Double.NEGATIVE_INFINITY || product.freshness == Double.POSITIVE_INFINITY) {
"Expired" "Expired"

View File

@ -2,7 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="190dp" xmlns:tools="http://schemas.android.com/tools" android:layout_width="190dp"
android:layout_height="wrap_content" app:barrierMargin="1dp" android:clickable="false" android:layout_height="330dp" app:barrierMargin="1dp" android:clickable="false"
android:outlineProvider="background" android:background="@drawable/outline"> android:outlineProvider="background" android:background="@drawable/outline">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout

View File

@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical"
android:layout_width="190dp" android:layout_width="190dp"
android:layout_height="wrap_content"> android:layout_height="345dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"