Search in sources :

Example 11 with BonEngin

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);
    }
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) me.kadarh.mecaworks.service.impl.bons.bonEngin(me.kadarh.mecaworks.service.impl.bons.bonEngin) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 12 with BonEngin

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);
    }
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 13 with BonEngin

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);
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin)

Example 14 with BonEngin

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";
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin)

Example 15 with BonEngin

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);
    }
}
Also used : BonEngin(me.kadarh.mecaworks.domain.bons.BonEngin) Random(java.util.Random)

Aggregations

BonEngin (me.kadarh.mecaworks.domain.bons.BonEngin)21 OperationFailedException (me.kadarh.mecaworks.service.exceptions.OperationFailedException)8 LocalDate (java.time.LocalDate)6 BonLivraison (me.kadarh.mecaworks.domain.bons.BonLivraison)6 ChronoUnit (java.time.temporal.ChronoUnit)5 Collectors (java.util.stream.Collectors)5 Slf4j (lombok.extern.slf4j.Slf4j)5 BonFournisseur (me.kadarh.mecaworks.domain.bons.BonFournisseur)5 Chantier (me.kadarh.mecaworks.domain.others.Chantier)5 BonEnginRepo (me.kadarh.mecaworks.repo.bons.BonEnginRepo)5 BonFournisseurRepo (me.kadarh.mecaworks.repo.bons.BonFournisseurRepo)5 BonLivraisonRepo (me.kadarh.mecaworks.repo.bons.BonLivraisonRepo)5 Service (org.springframework.stereotype.Service)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Month (java.time.Month)4 java.util (java.util)4 ArrayList (java.util.ArrayList)4 Engin (me.kadarh.mecaworks.domain.others.Engin)4 Stock (me.kadarh.mecaworks.domain.others.Stock)4 ChantierBatch (me.kadarh.mecaworks.domain.user.ChantierBatch)4