From d0a5bfb74eb0929f7d7f140c7797502776f64438 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 27 Jun 2022 15:55:20 +0200 Subject: [PATCH] Add newStock method --- .../foucry/pilldroid/models/Prescription.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java index 709bad1..ab9bd0d 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java @@ -1,5 +1,9 @@ package net.foucry.pilldroid.models; +import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday; + +import android.util.Log; + import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.PrimaryKey; @@ -12,6 +16,7 @@ import java.util.Date; @Entity(tableName = "prescriptions") public class Prescription implements Serializable { + private static final String TAG = Prescription.class.getName();; @PrimaryKey @NonNull private String cis; private String cip13; @@ -144,6 +149,18 @@ public class Prescription implements Serializable { return calendar.getTime(); } + + public void newStock() { + Log.d(TAG, "current drug = " + this); + + Date lastUpdate = new Date(getLast_update()); + int numberOfDays = nbOfDaysBetweenDateAndToday(lastUpdate); + if (numberOfDays > 0) { + double takeDuringPeriod = this.take * numberOfDays; + setStock((float) (getStock() - takeDuringPeriod)); + setLast_update(new Date().getTime()); + } + } }