use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.
the class BonEnginServiceImpl method getPage.
/**
* Search by Pompiste, Chauffeur, code, engin and date
*
* @param pageable
* @param search
* @return
*/
@Override
public Page<BonEngin> getPage(Pageable pageable, String search) {
log.info("Service- BonEnginServiceImpl Calling bonEnginList with params :" + pageable + ", " + search);
try {
if (search.isEmpty()) {
log.debug("fetching bonEngins page");
return bonEnginRepo.findAll(pageable);
} else {
log.debug("Searching by :" + search);
// creating example by pompiste / chauffeur / code bon / code engin
BonEngin bonEngin = new BonEngin();
bonEngin.setCode(search);
bonEngin.setCompteurAbsoluKm(null);
bonEngin.setCompteurKm(null);
bonEngin.setCompteurH(null);
bonEngin.setCompteurAbsoluH(null);
bonEngin.setConsommationH(null);
bonEngin.setConsommationKm(null);
bonEngin.setQuantite(null);
bonEngin.setCarburant(null);
bonEngin.setCompteurPompe(null);
bonEngin.setCompteurHenPanne(null);
bonEngin.setCompteurKmenPanne(null);
bonEngin.setNbrHeures(null);
bonEngin.setNbrKm(null);
bonEngin.setConsommationPrevu(null);
bonEngin.setChargeHoraire(null);
Employe employe = new Employe();
employe.setNom(search);
Engin engin = new Engin();
engin.setCode(search);
engin.setNumeroSerie(search);
engin.setNumeroSerie(null);
engin.setConsommationMoyenne(null);
engin.setObjectif(null);
Chantier chantier = new Chantier();
chantier.setStock(null);
chantier.setNom(search);
bonEngin.setChantierGazoil(chantier);
bonEngin.setPompiste(employe);
bonEngin.setChauffeur(employe);
bonEngin.setEngin(engin);
try {
bonEngin.setDate(LocalDate.parse(search, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
} catch (Exception e) {
log.debug("Cannot search by date : keyword doesn't match date pattern");
}
// creating matcher
ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
Example<BonEngin> example = Example.of(bonEngin, matcher);
log.debug("getting search results");
return bonEnginRepo.findAll(example, pageable);
}
} catch (Exception e) {
log.debug("Failed retrieving list of bons");
throw new OperationFailedException("Operation échouée", e);
}
}
use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.
the class BonEnginServiceImpl method delete.
@Override
public void delete(Long id) {
log.info("Service= BonEnginServiceImpl - calling methode delete");
try {
BonEngin bonEngin = bonEnginRepo.getOne(id);
log.info("Suppression du dernier bon");
Long idChantier = bonEngin.getChantierTravail().getId();
Long idGasoil = bonEngin.getChantierGazoil().getId();
stockManagerService.deleteStock(idGasoil, idChantier, id, TypeBon.BE);
alerteRepo.deleteAllByBonEngin_Id(id);
bonEnginRepo.deleteById(id);
miseAjourBonsService.doMiseAjour(bonEngin);
alerteRepo.findAllByIdBonEngin(bonEngin.getId()).forEach(alerteRepo::delete);
} catch (Exception e) {
throw new OperationFailedException("Probleme lors de la suppression du bon, ce bon ne peut pas être supprimer", e);
}
}
use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.
the class BonEnginServiceImpl method hasErrors.
/* ------------------------------------------------------------------------------ */
/* ------------ TRAITEMENT WITHOUT CALLING REPO -------------------------------- */
/* ---------------------------------------------------------------------------- */
/**
* @param bon the current BonEngin
* @return boolean value
* 0 if one of (quantity or meter) hasn't a logic value
* 1 else ( if compteur and quantité are logic )
*/
@Override
public boolean hasErrors(BonEngin bon) {
calculAbsoluService.fillBon(bon);
BonEngin lastBonEngin = persistService.getLastBonEngin(bon.getEngin(), bon.getDate());
if (lastBonEngin != null)
return !(checkService.hasLogicQuantite(bon) && checkService.hasLogicCompteur(bon, lastBonEngin) && checkService.hasLogicDate(bon, lastBonEngin) && checkService.hasLogicDateAndCompteur(bon, lastBonEngin));
else
return !checkService.hasLogicQuantite(bon);
}
use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.
the class BonEnginController method addGet.
@GetMapping("/add")
public String addGet(Model model) {
model.addAttribute("bonEngin", new BonEngin());
model.addAttribute("chantiers", chantierService.getList());
model.addAttribute("engins", enginService.getList());
model.addAttribute("employes", employeService.getList());
model.addAttribute("carburants", Carburant.values());
return "saisi/engins/add";
}
use of me.kadarh.mecaworks.domain.bons.BonEngin in project mecaworks by KadarH.
the class DataFakerO method loadBonEngin.
private void loadBonEngin(int n) {
for (int i = 0; i < n; i++) {
BonEngin bonEngin = new BonEngin();
bonEngin.setDate(LocalDate.of(2018, LocalDate.now().getMonth().getValue(), new Random().nextInt(28) + 1));
bonEngin.setCode("code " + i);
bonEngin.setCompteurHenPanne(i % 2 == 0);
bonEngin.setCompteurH((long) i);
bonEngin.setCompteurKmenPanne(i % 2 == 1);
bonEngin.setCompteurKm((long) i);
bonEngin.setQuantite(200 + i * 10);
bonEngin.setPlein(true);
bonEngin.setConsommationKm(i * 100f);
bonEngin.setConsommationH(i * 1500f);
bonEngin.setCompteurAbsoluH(i + 502L);
bonEngin.setCompteurAbsoluKm(i + 600L);
bonEngin.setNbrHeures(i + 2L);
bonEngin.setNbrKm(i + 4L);
bonEngin.setEngin(enginRepo.getOne(i / 26 + 1L));
bonEngin.setChargeHoraire(bonEngin.getNbrHeures() * bonEngin.getEngin().getPrixLocationJournalier() / bonEngin.getEngin().getObjectif());
bonEngin.setConsommationPrevu(bonEngin.getEngin().getConsommationMoyenne().longValue() * bonEngin.getNbrHeures());
bonEngin.setPompiste(employeRepo.getOne(i / 100 + 1L));
bonEngin.setChauffeur(employeRepo.getOne(i / 50 + 2L));
bonEngin.setChantierGazoil(chantierRepo.getOne(i / 100 + 1L));
bonEngin.setChantierTravail(chantierRepo.getOne(i / 100 + 1L));
bonEnginRepo.save(bonEngin);
}
}
Aggregations