/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.triz.trizservice.modeles.object;

import com.triz.trizservice.modeles.ServiceIncrementation;
import com.triz.trizservice.service.TransactionService;
import java.util.Date;

/**
 *
 * @author HP
 */
public class GenerateIDObject {

    public static String genererIdGroups(TransactionService service) {

        System.out.println("genererIdGroups");
        String id = "";
        ServiceIncrementation incr = service.getIncrementation();
        if (incr == null) {
            incr = new ServiceIncrementation();
            incr.setDateMois(new Date());
        }

        if (incr.getIncrGroups() == null) {
            incr.setIncrGroups(0);
        }

        int nbrStockGroups = incr.getIncrGroups() + 1;
        incr.setIncrGroups(nbrStockGroups);
        id = "" + nbrStockGroups;
        service.save(incr);
        while (id.length() < 5) {
            id = "0" + id;
        }

        id = "90" + id;
        System.out.println("Id :" + id);
        return id;
    }
}
