mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-21 20:19:23 +01:00
Add newStock calculation forgot in previous versions
This commit is contained in:
parent
70ac8b3d1e
commit
e1cfc2a375
2 changed files with 23 additions and 1 deletions
|
@ -50,8 +50,14 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|||
PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(context.getApplicationContext());
|
||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||
List<Prescription> prescriptionList = prescriptionsDAO.getAllMedics();
|
||||
Prescription firstPrescription = null ;
|
||||
Prescription firstPrescription = null;
|
||||
Prescription currentPrescription;
|
||||
|
||||
for (int i=0 ; i < prescriptionList.size(); i++ ) {
|
||||
currentPrescription = prescriptionList.get(i);
|
||||
currentPrescription.newStock();
|
||||
prescriptionsDAO.update(currentPrescription);
|
||||
}
|
||||
// Sorting list by dateEndOfStock
|
||||
Utils.sortPrescriptionList(prescriptionList);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -129,6 +133,7 @@ public class Prescription implements Serializable {
|
|||
public void setGeneric_type(Integer generic_type) {
|
||||
this.generic_type = generic_type;
|
||||
}
|
||||
|
||||
public Date getDateEndOfStock() {
|
||||
int numberDayOfTake;
|
||||
if (this.getTake() > 0) {
|
||||
|
@ -144,6 +149,17 @@ public class Prescription implements Serializable {
|
|||
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public void newStock() {
|
||||
Date lastUpdate = new Date(getLast_update());
|
||||
|
||||
int numberOfDays = UtilDate.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