Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
add method to fetch inventory row by medical code and lot code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFonzam committed Aug 7, 2024
1 parent e0d6808 commit 1f0e344
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private void validateMedicalInventory(MedicalInventory medInventory) throws OHDa

@Transactional(rollbackFor = OHServiceException.class)
public void validateInventory(MedicalInventory inventory, List<MedicalInventoryRow> inventoryRowSearchList) throws OHServiceException {
LocalDateTime movFrom = inventory.getInventoryDate();
LocalDateTime movFrom = inventory.getLastModifiedDate();
LocalDateTime movTo = TimeTools.getNow();
List<Movement> movements = movBrowserManager.getMovements(null, null, null, null, movFrom, movTo, null, null, null, null);
if (!movements.isEmpty()) {
Expand All @@ -240,19 +240,24 @@ public void validateInventory(MedicalInventory inventory, List<MedicalInventoryR
double theoQty = medicalInventoryRow.getTheoreticQty();
Medical medical = medicalInventoryRow.getMedical();
List<Movement> movs = groupedByMedical.get(medical);
if (!movs.isEmpty()) {
if (movs != null) {
for (Movement mov: movs) {
String lotCodeOfMovement = mov.getLot().getCode();
Lot lot = movStockInsertingManager.getLot(lotCodeOfMovement);
double mainStoreQty = (double)lot.getMainStoreQuantity();
if (lotCodeOfMovement.equals(lotCode)) {
if (mainStoreQty != theoQty) {
medicalInventoryRow.setTheoreticQty(mainStoreQty);
medicalInventoryRow.setRealqty(mainStoreQty);
medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow);
}
} else {
MedicalInventoryRow medInvRow = new MedicalInventoryRow(0, mainStoreQty, mainStoreQty, inventory, medical, lot);
medicalInventoryRowManager.newMedicalInventoryRow(medInvRow);
Integer medicalCode = medical.getCode();
MedicalInventoryRow inventoryRow = medicalInventoryRowManager.getMedicalInventoryRowByMedicalCodeAndLotCode(medicalCode, lotCodeOfMovement);
if (inventoryRow == null) {
MedicalInventoryRow medInvRow = new MedicalInventoryRow(0, mainStoreQty, mainStoreQty, inventory, medical, lot);
medicalInventoryRowManager.newMedicalInventoryRow(medInvRow);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.isf.generaldata.MessageBundle;
import org.isf.medicalinventory.model.MedicalInventoryRow;
import org.isf.medicalinventory.service.MedicalInventoryRowIoOperation;
import org.isf.medicals.model.Medical;
import org.isf.medicalstock.manager.MovStockInsertingManager;
import org.isf.utils.exception.OHDataValidationException;
import org.isf.utils.exception.OHServiceException;
Expand Down Expand Up @@ -154,4 +155,16 @@ private void validateMedicalInventoryRow(MedicalInventoryRow medicalInventoryRow
throw new OHDataValidationException(errors);
}
}

/**
* Return {@link MedicalInventoryRow} for passed param.
*
* @param medicalCode - the medical code.
* @param lotCode - the lot code.
* @return the {@link MedicalInventoryRow} object.
* @throws OHServiceException
*/
public MedicalInventoryRow getMedicalInventoryRowByMedicalCodeAndLotCode(Integer medicalCode, String lotCode) throws OHServiceException {
return ioOperation.getMedicalInventoryRowByMedicalCodeAndLotCode(medicalCode, lotCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@ public List<MedicalInventoryRow> getMedicalInventoryRowByInventoryId(int invento
public Optional<MedicalInventoryRow> getMedicalInventoryRowById(Integer id) throws OHServiceException {
return repository.findById(id);
}

/**
* Return {@link MedicalInventoryRow} for passed param.
*
* @param medicalCode - the medical code.
* @param lotCode - the lot code.
* @return the {@link MedicalInventoryRow} object.
* @throws OHServiceException
*/
public MedicalInventoryRow getMedicalInventoryRowByMedicalCodeAndLotCode(Integer medicalCode, String lotCode) throws OHServiceException {
return repository.findByMedicalCodeAndLotCode(medicalCode, lotCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public interface MedicalInventoryRowIoOperationRepository extends JpaRepository<

@Query(value = "select medinvrow from MedicalInventoryRow medinvrow where medinvrow.inventory.id = :inventoryId")
List<MedicalInventoryRow> findByInventoryId(@Param("inventoryId") int inventoryId);

@Query(value = "select medinvrow from MedicalInventoryRow medinvrow where medinvrow.medical.code = :medicalCode and medinvrow.lot.code = :lotCode")
MedicalInventoryRow findByMedicalCodeAndLotCode(@Param("medicalCode") int medicalCode, @Param("lotCode") String lotCode);
}

0 comments on commit 1f0e344

Please sign in to comment.