Search in sources :

Example 6 with Stock

use of me.kadarh.mecaworks.domain.others.Stock in project mecaworks by KadarH.

the class BonLivraisonServiceImpl method insertStock_Livraison.

public void insertStock_Livraison(BonLivraison bonLivraison) {
    // sortie Livraison
    Stock stock = new Stock();
    Chantier chantier = bonLivraison.getChantierDepart();
    stock.setChantier(chantier);
    stock.setDate(bonLivraison.getDate());
    stock.setSortieL(bonLivraison.getQuantite());
    stock.setQuantite(stock.getSortieL());
    stock.setId_Bon(bonLivraison.getId());
    stock.setTypeBon(TypeBon.BL);
    if (stockService.getLastStock(chantier) != null)
        stock.setStockC(stockService.getLastStock(chantier).getStockC() - bonLivraison.getQuantite());
    else
        stock.setStockC(chantier.getStock() - bonLivraison.getQuantite());
    // Entréé livraison
    Stock stock2 = new Stock();
    Chantier chantier1 = bonLivraison.getChantierArrivee();
    stock2.setChantier(chantier1);
    stock2.setDate(bonLivraison.getDate());
    stock2.setEntreeL(bonLivraison.getQuantite());
    stock2.setQuantite(stock2.getEntreeL());
    stock2.setId_Bon(bonLivraison.getId());
    stock2.setTypeBon(TypeBon.BL);
    if (stockService.getLastStock(chantier1) != null)
        stock2.setStockC(stockService.getLastStock(chantier1).getStockC() + bonLivraison.getQuantite());
    else
        stock2.setStockC(chantier1.getStock() + bonLivraison.getQuantite());
    stockService.add(stock);
    stockService.add(stock2);
    stockManagerService.addStockUpdate(bonLivraison.getChantierArrivee().getId(), bonLivraison.getChantierDepart().getId(), stock2, TypeBon.BL);
}
Also used : Chantier(me.kadarh.mecaworks.domain.others.Chantier) Stock(me.kadarh.mecaworks.domain.others.Stock)

Example 7 with Stock

use of me.kadarh.mecaworks.domain.others.Stock in project mecaworks by KadarH.

the class DashbordChantierServiceImpl method getDashbordChantier.

@Override
public DashbordChantier getDashbordChantier(Long idc, int mois, int annee) {
    Long stock_c;
    Long ecartPlus;
    Long ecartMoins;
    LocalDate dateMaj;
    Optional<Stock> stock = stockRepo.findLastStockReel(idc);
    List<Quantite> quantites = new ArrayList<>();
    LocalDate d = LocalDate.of(annee, mois, 1);
    for (int i = 12, month, yeaar; i >= 0; i--) {
        month = d.minusMonths(i).getMonthValue();
        yeaar = d.minusMonths(i).getYear();
        quantites.add(userCalculService.getMonthsWithQuantities(chantierService.get(idc), month, yeaar));
    }
    if (stock.isPresent()) {
        ecartPlus = stock.get().getEcart_plus().longValue();
        ecartMoins = stock.get().getEcart_moins().longValue();
        dateMaj = stock.get().getDate();
    } else {
        ecartPlus = 0L;
        ecartMoins = 0L;
        dateMaj = LocalDate.now();
    }
    return new DashbordChantier(userCalculService.getListDaysQuantities(chantierService.get(idc), mois, annee), quantites, userCalculService.getListChantierStockDays(chantierService.get(idc), mois, annee), chantierService.get(idc).getStock().longValue(), ecartPlus, ecartMoins, dateMaj, chantierService.get(idc));
}
Also used : Quantite(me.kadarh.mecaworks.domain.user.Quantite) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) Stock(me.kadarh.mecaworks.domain.others.Stock) DashbordChantier(me.kadarh.mecaworks.domain.user.DashbordChantier)

Example 8 with Stock

use of me.kadarh.mecaworks.domain.others.Stock in project mecaworks by KadarH.

the class UserCalculService method getListChantierStockDays.

public List<Stock> getListChantierStockDays(Chantier chantier, int month, int year) {
    LocalDate from = LocalDate.of(year, Month.of(month).getValue(), 1);
    LocalDate to = LocalDate.of(year, Month.of(month).plus(1).getValue(), 1);
    if (from.getMonth().getValue() == 12)
        to = LocalDate.of(year + 1, Month.of(month).plus(1).getValue(), 1);
    List<Stock> list = new ArrayList<>();
    List<Stock> stocks = stockRepo.findAllByChantier(chantier.getId(), from, to);
    Stock stock;
    Long stock1;
    long days = ChronoUnit.DAYS.between(from, to);
    for (int i = 0; i < days; i++) {
        stock = new Stock();
        LocalDate localDate = LocalDate.of(year, month, i + 1);
        OptionalLong id_s = stocks.stream().filter(be -> be.getDate().equals(localDate)).mapToLong(Stock::getId).max();
        if (id_s.isPresent())
            stock1 = stockRepo.getOne(id_s.getAsLong()).getStockC().longValue();
        else
            stock1 = 100000L;
        stock.setStockC(stock1.intValue());
        stock.setChantier(chantier);
        stock.setDate(LocalDate.of(year, month, i + 1));
        list.add(stock);
    }
    for (int i = 1; i < list.size(); i++) {
        if (list.get(i).getStockC() == 100000L)
            list.get(i).setStockC(list.get(i - 1).getStockC());
    }
    return list;
}
Also used : LocalDate(java.time.LocalDate) Stock(me.kadarh.mecaworks.domain.others.Stock)

Aggregations

Stock (me.kadarh.mecaworks.domain.others.Stock)8 Chantier (me.kadarh.mecaworks.domain.others.Chantier)3 LocalDate (java.time.LocalDate)2 NoSuchElementException (java.util.NoSuchElementException)2 OperationFailedException (me.kadarh.mecaworks.service.exceptions.OperationFailedException)2 ResourceNotFoundException (me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException)2 ArrayList (java.util.ArrayList)1 DashbordChantier (me.kadarh.mecaworks.domain.user.DashbordChantier)1 Quantite (me.kadarh.mecaworks.domain.user.Quantite)1