Add newStock method

This commit is contained in:
jacques 2022-06-27 15:55:20 +02:00
parent ef7ee0fc76
commit d0a5bfb74e

View file

@ -1,5 +1,9 @@
package net.foucry.pilldroid.models; package net.foucry.pilldroid.models;
import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
@ -12,6 +16,7 @@ import java.util.Date;
@Entity(tableName = "prescriptions") @Entity(tableName = "prescriptions")
public class Prescription implements Serializable { public class Prescription implements Serializable {
private static final String TAG = Prescription.class.getName();;
@PrimaryKey @PrimaryKey
@NonNull private String cis; @NonNull private String cis;
private String cip13; private String cip13;
@ -144,6 +149,18 @@ public class Prescription implements Serializable {
return calendar.getTime(); 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());
}
}
} }