mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-21 20:19:23 +01:00
Add newStock method
This commit is contained in:
parent
ef7ee0fc76
commit
d0a5bfb74e
1 changed files with 17 additions and 0 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue