Search in sources :

Example 1 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class StockTakingOperation method fullfillDetails.

/**
 * Takes the supplied list of refurbishIds, validates their existence in the supplied Stock or all if none supplied.
 *
 * @param inFile  a XLS File containing the refurbishIds in the first sheet, first column.
 * @param stockId the stock, may be null
 * @return a FileJacket with the Result as XLS Report.
 */
@Override
public FileJacket fullfillDetails(FileJacket inFile, Integer stockId) {
    SubMonitor m = monitorFactory.newSubMonitor("Inventur vervollständigen", 100);
    m.start();
    m.message("Datei einlesen");
    ReaderResult read = xlsToList(inFile);
    m.worked(3);
    m.setWorkRemaining(read.getRefurbisIds().size() * 2 + 10);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    DossierEao dossierEao = new DossierEao(redTapeEm);
    List<Object[]> result = new ArrayList<>();
    Set<StockUnit> found = new HashSet<>();
    String stockTaking = "erfasst";
    for (String refurbishId : read.getRefurbisIds()) {
        m.worked(1, "vervollständige " + refurbishId);
        UniqueUnit uu = uniqueUnitEao.findByIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbishId);
        StockUnit stu = (uu == null ? null : stockUnitEao.findByUniqueUnitId(uu.getId()));
        if (stu != null)
            found.add(stu);
        if (uu == null) {
            result.add(new Object[] { stockTaking, "Fehler: Gerät exitiert nicht !", refurbishId, null, null, null, null, null, null, null, null, null, null, null });
        } else {
            String partNo = uu.getProduct().getPartNo();
            String contractorPartNo = uu.getProduct().getAdditionalPartNo(uu.getContractor());
            String name = ProductFormater.toName(uu.getProduct());
            if (stu == null) {
                result.add(new Object[] { stockTaking, "Nicht im Lager", refurbishId, partNo, uu.getSerial(), name, uu.getContractor(), null, uu.getSalesChannel(), null, null, null, contractorPartNo, null });
            } else {
                // jetzt schauen was mit st ist
                String stock = (stu.getStock() == null ? stu.getTransaction().toSimpleLine() : stu.getStock().getName());
                if (stu.getLogicTransaction() == null) {
                    result.add(new Object[] { stockTaking, "verfügbar", refurbishId, partNo, uu.getSerial(), name, uu.getContractor(), stock, uu.getSalesChannel(), null, null, null, contractorPartNo, null });
                } else {
                    Dossier dos = dossierEao.findById(stu.getLogicTransaction().getDossierId());
                    result.add(new Object[] { stockTaking, dos.isClosed() ? "abgeschlossen" : "in transfer", refurbishId, partNo, uu.getSerial(), name, uu.getContractor(), stock, uu.getSalesChannel(), dos.getCrucialDirective().getName(), dos.getCustomerId(), dos.getIdentifier(), contractorPartNo, customerService.asUiCustomer(dos.getCustomerId()).toNameCompanyLine() });
                }
            }
        }
    }
    stockTaking = "nicht erfasst";
    m.message("lade fehlende Geräte");
    List<StockUnit> openUnits = (stockId == null ? stockUnitEao.findAll() : stockUnitEao.findByStockId(stockId));
    m.worked(8);
    openUnits.removeAll(found);
    m.setWorkRemaining(openUnits.size());
    for (StockUnit stu : openUnits) {
        m.worked(1, "vervollständige " + stu.getRefurbishId());
        UniqueUnit uu = uniqueUnitEao.findById(stu.getUniqueUnitId());
        String partNo = uu.getProduct().getPartNo();
        String contractorPartNo = uu.getProduct().getAdditionalPartNo(uu.getContractor());
        String name = ProductFormater.toName(uu.getProduct());
        // jetzt schauen was mit st ist
        String stock = (stu.getStock() == null ? stu.getTransaction().toString() : stu.getStock().getName());
        if (stu.getLogicTransaction() == null) {
            result.add(new Object[] { stockTaking, "verfügbar", uu.getRefurbishId(), partNo, uu.getSerial(), name, uu.getContractor(), stock, uu.getSalesChannel(), null, null, null, contractorPartNo, null });
        } else {
            Dossier dos = dossierEao.findById(stu.getLogicTransaction().getDossierId());
            result.add(new Object[] { stockTaking, dos.isClosed() ? "abgeschlossen" : "in transfer", uu.getRefurbishId(), partNo, uu.getSerial(), name, uu.getContractor(), stock, uu.getSalesChannel(), dos.getCrucialDirective().getName(), dos.getCustomerId(), dos.getIdentifier(), contractorPartNo, customerService.asUiCustomer(dos.getCustomerId()).toNameCompanyLine() });
        }
    }
    for (String error : read.getErrors()) {
        result.add(new Object[] { "Lesefehler", error, null, null, null, null, null, null, null, null, null, null, null, null });
    }
    m.message("Erzeuge Tabelle");
    CSheet sheet = new CSheet("Inventur");
    STable table = new STable();
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, BLACK, WHITE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("Inventur", 12)).add(new STableColumn("Status", 10)).add(new STableColumn("SopoNr", 10)).add(new STableColumn("ArtikelNr", 16));
    table.add(new STableColumn("Seriennummer", 30)).add(new STableColumn("Name", 50)).add(new STableColumn("Contractor", 14)).add(new STableColumn("Lager", 25));
    table.add(new STableColumn("Verkaufskanal", 16)).add(new STableColumn("Directive", 20)).add(new STableColumn("Kid", 8)).add(new STableColumn("VorgangsId", 10));
    table.add(new STableColumn("LieferantenPartNo", 16)).add(new STableColumn("Kunde", 40));
    table.setModel(new STableModelList(result));
    sheet.addBelow(table);
    CCalcDocument document = new TempCalcDocument();
    document.add(sheet);
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(document);
    m.finish();
    return new FileJacket("Inventur", ".xls", file);
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) File(java.io.File)

Example 2 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class SalesListingProducerOperation method generateAllSalesListing.

@Override
public FileJacket generateAllSalesListing() {
    SubMonitor m = monitorFactory.newSubMonitor("All List", 5);
    m.message("loading Units");
    m.start();
    List<StockUnit> stockUnits = new StockUnitEao(stockEm).findByNoLogicTransaction();
    List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uuEm).findByIds(toUniqueUnitIds(stockUnits));
    m.worked(3, "preparing Units");
    List<Object[]> retailers = new ArrayList<>(stockUnits.size());
    List<Object[]> customers = new ArrayList<>(stockUnits.size());
    for (Map.Entry<UniqueUnit, StockUnit> entry : toSortedMap(uniqueUnits, stockUnits, new UniqueUnitComparator()).entrySet()) {
        UniqueUnit uu = entry.getKey();
        StockUnit su = entry.getValue();
        Product p = uu.getProduct();
        Date firstPriced = null;
        for (PriceHistory priceHistory : uu.getPriceHistory()) {
            if (firstPriced == null || firstPriced.after(priceHistory.getDate()))
                firstPriced = priceHistory.getDate();
        }
        String source = "Automatisch";
        if (p != null && p.getFlags().contains(Product.Flag.PRICE_FIXED))
            source = "Manuell (Artikel)";
        else if (uu.getFlags().contains(UniqueUnit.Flag.PRICE_FIXED))
            source = "Manuell (Gerät)";
        Object[] row = { uu.getRefurbishId(), (p == null ? null : p.getPartNo()), (p == null ? null : p.getGroup().getNote()), (p == null ? null : p.getTradeName().getName()), (p == null ? null : p.getName()), (p == null ? null : p.getDescription()), uu.getWarranty().getName(), uu.getWarrentyValid(), UniqueUnitFormater.toSingleLineAccessories(uu), uu.getCondition().getNote(), UniqueUnitFormater.toSingleLineComment(uu), uu.getPrice(PriceType.RETAILER), uu.getPrice(PriceType.CUSTOMER), (!uu.hasPrice(PriceType.CUSTOMER) ? null : TwoDigits.roundedApply(uu.getPrice(PriceType.CUSTOMER), GlobalConfig.DEFAULT_TAX.getTax(), 0)), (su.getStock() == null ? su.getTransaction() : su.getStock().getName()), uu.getMfgDate(), uu.getInputDate(), firstPriced, source };
        if (uu.getSalesChannel() == SalesChannel.CUSTOMER && uu.hasPrice(PriceType.CUSTOMER))
            customers.add(row);
        else if (uu.getSalesChannel() == SalesChannel.RETAILER && (uu.hasPrice(PriceType.CUSTOMER) || uu.hasPrice(PriceType.RETAILER)))
            retailers.add(row);
    }
    m.worked(1, "creating File, Endkundengeräte: " + customers.size() + ", Händlergeräte: " + retailers.size());
    STable consumerTable = new STable();
    consumerTable.setTableFormat(new CFormat(CENTER, TOP, new CBorder(Color.GRAY, CBorder.LineStyle.THIN), true));
    consumerTable.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.LIGHT_GRAY, CENTER, MIDDLE));
    consumerTable.setRowHeight(1000);
    consumerTable.add(new STableColumn("SopoNr", 12));
    consumerTable.add(new STableColumn("ArtikelNr", 15));
    consumerTable.add(new STableColumn("Warengruppe", 18));
    consumerTable.add(new STableColumn("Hersteller", 15));
    consumerTable.add(new STableColumn("Bezeichnung", 30));
    consumerTable.add(new STableColumn("Beschreibung", 60, LFT));
    consumerTable.add(new STableColumn("Garantie", 18, LFT));
    consumerTable.add(new STableColumn("Garantie bis", 18, new CFormat(Representation.SHORT_DATE)));
    consumerTable.add(new STableColumn("Zubehör", 30, LFT));
    consumerTable.add(new STableColumn("optische Bewertung", 25));
    consumerTable.add(new STableColumn("Bemerkung", 50, LFT));
    consumerTable.add(new STableColumn("Händler", 15, EURO));
    consumerTable.add(new STableColumn("Endkunde", 15, EURO));
    consumerTable.add(new STableColumn("E.inc.Mwst", 15, EURO));
    consumerTable.add(new STableColumn("Lager", 18));
    consumerTable.add(new STableColumn("Mfg Datum", 18, new CFormat(Representation.SHORT_DATE)));
    consumerTable.add(new STableColumn("Aufnahme Datum", 18, new CFormat(Representation.SHORT_DATE)));
    consumerTable.add(new STableColumn("Erstmalig Bepreist", 18, new CFormat(Representation.SHORT_DATE)));
    consumerTable.add(new STableColumn("Preis Quelle", 18));
    consumerTable.setModel(new STableModelList(customers));
    STable retailerTable = new STable(consumerTable);
    retailerTable.setModel(new STableModelList(retailers));
    CCalcDocument cdoc = new TempCalcDocument();
    cdoc.add(new CSheet("Endkunde", consumerTable));
    cdoc.add(new CSheet("Händler", retailerTable));
    FileJacket fj = new FileJacket("All", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc));
    m.finish();
    return fj;
}
Also used : Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) PriceHistory(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceHistory) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)

Example 3 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class ImageIdHandlerOperation method exportMissing.

/**
 * Returns a FileJacket of XLS, which contains all Products with missing ImageIds.
 * <p/>
 * Acitve Filters are:
 * <ul>
 * <li>If SalesChannel is supplied, only Products, which have units in the SalesChannel.</li>
 * <li>Only Products, which don't have an image id.</li>
 * <li>Only Products, which have Unit in stock.</li>
 * </ul>
 * <p/>
 * @param salesChannel
 * @return
 */
@Override
public FileJacket exportMissing(SalesChannel salesChannel) {
    SubMonitor m = monitorFactory.newSubMonitor("Fehlende Image Ids exportieren", 100);
    m.message("Loading Missing IDs");
    m.start();
    List<Integer> uniqueUnitIds = new StockUnitEao(stockEm).findByNoLogicTransactionAsUniqueUnitId();
    List<UniqueUnit> uniqueUnits = new UniqueUnitEao(uuEm).findByIds(uniqueUnitIds);
    SortedSet<Product> products = new TreeSet<>();
    for (UniqueUnit uniqueUnit : uniqueUnits) {
        if (uniqueUnit.getProduct() == null)
            continue;
        if (salesChannel != null && uniqueUnit.getSalesChannel() != salesChannel)
            continue;
        if (uniqueUnit.getProduct().getImageId() > 0)
            continue;
        products.add(uniqueUnit.getProduct());
    }
    STable table = new STable();
    table.setHeadlineFormat(new CFormat(BOLD, BLACK, LIGHT_GRAY, CENTER, MIDDLE));
    table.add(new STableColumn("ArtikelNr", 15).setAction(SUtil.getBeanProperty("partNo")));
    table.add(new STableColumn("Warengruppe", 22).setAction(SUtil.getBeanProperty("group.name")));
    table.add(new STableColumn("Hersteller", 16).setAction(SUtil.getBeanProperty("tradeName.name")));
    table.add(new STableColumn("Bezeichnung", 45).setAction(SUtil.getBeanProperty("name")));
    table.add(new STableColumn("Image Id", 10).setAction(SUtil.getNull()));
    table.setModel(new STableModelList(products));
    CCalcDocument doc = new TempCalcDocument("ImageIds");
    doc.add(new CSheet("ImageIds", table));
    FileJacket fj = new FileJacket("MissingImageIds", ".xls", LucidCalc.createWriter(LucidCalc.Backend.XLS).write(doc));
    m.finish();
    return fj;
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) CSheet(eu.ggnet.lucidcalc.CSheet) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) STableColumn(eu.ggnet.lucidcalc.STableColumn) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) STable(eu.ggnet.lucidcalc.STable) STableModelList(eu.ggnet.lucidcalc.STableModelList) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CFormat(eu.ggnet.lucidcalc.CFormat)

Example 4 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class PersistenceValidatorOperation method validateDatabase.

/**
 * This Method Validate all Databases.
 * It's validate:
 * - RedTape
 * - UniqueUnit
 * - Sopo
 * - Stock
 * <p/>
 * @return a Filejacket where a xls from the JExcel api is, that contains all Errors.
 */
@Override
public Optional<FileJacket> validateDatabase() {
    List<Vm> vms = new ArrayList<>();
    UniqueUnitEao uuEao = new UniqueUnitEao(uuEm);
    DossierEao dossierEao = new DossierEao(redTapeEm);
    LogicTransactionEao logicEao = new LogicTransactionEao(stockEm);
    StockUnitEao stockUnitEao = new StockUnitEao(stockEm);
    int uuMax = uuEao.count();
    int dossierMax = dossierEao.count();
    int logicMax = logicEao.count();
    int stockUnitMax = stockUnitEao.count();
    SubMonitor m = monitorFactory.newSubMonitor("DatenbankValidation", 100);
    // All Listen
    List<Dossier> dossiers;
    List<UniqueUnit> uniqueUnits;
    List<LogicTransaction> logicTransactions;
    List<StockUnit> stockUnits;
    m.message("Hole alle Unique Units. " + uuMax);
    uniqueUnits = uuEao.findAll();
    m.worked(10, "Hole Alle Dossiers. " + dossierMax);
    dossiers = dossierEao.findAll();
    m.worked(10, "Hole Alle LogicTransaction. " + logicMax);
    logicTransactions = logicEao.findAll();
    m.worked(10, "Hole Alle StockUnit. " + stockUnitMax);
    stockUnits = stockUnitEao.findAll();
    m.worked(10, "Validieren.");
    validateRedTape(vms, dossiers, convertUnitListToMap(uniqueUnits), m.newChild(10));
    validateUniqueUnit(vms, uniqueUnits, m.newChild(10));
    validateLogicTransaction(vms, logicTransactions, dossiers, m.newChild(10));
    // TODO: split:
    // 1. Sopo Validation <-> RedTape
    // 2. Sopo Only.
    m.finish();
    return createFileJacket(vms);
}
Also used : SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 5 with StockUnitEao

use of eu.ggnet.dwoss.stock.ee.eao.StockUnitEao in project dwoss by gg-net.

the class LogicTransactionEmo method optionalRemoveUnits.

/**
 * Removes StockUnits identified by UniqueUnitIds from a LogicTransaction, if it exists.
 *
 * @param dossierId     the dossierId of the LogicTransaction
 * @param uniqueUnitIds the uniqueUnitIds
 * @return the LogicTransaction after the removal, always returns a list.
 */
// TODO: Test
public List<StockUnit> optionalRemoveUnits(long dossierId, Collection<Integer> uniqueUnitIds) {
    if (uniqueUnitIds == null)
        throw new NullPointerException("uniqueUnitIds must not be null");
    // Null is possible
    LogicTransaction logicTransaction = new LogicTransactionEao(em).findByDossierId(dossierId);
    if (logicTransaction == null)
        return new ArrayList<>();
    List<StockUnit> stockUnits = new ArrayList<>();
    for (Integer uniqueUnitId : uniqueUnitIds) {
        // check stockunit if not in LogicTransaction.
        StockUnit unit = new StockUnitEao(em).findByUniqueUnitId(uniqueUnitId);
        if (unit == null)
            continue;
        if (unit.getLogicTransaction() == null)
            throw new IllegalStateException(unit + " is not on a LogicTransaction, shoud be on " + logicTransaction);
        if (!logicTransaction.equals(unit.getLogicTransaction()))
            throw new IllegalStateException(unit + " is on a different LogicTransaction than " + logicTransaction);
        logicTransaction.remove(unit);
        stockUnits.add(unit);
    }
    return stockUnits;
}
Also used : StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Aggregations

StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)29 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)25 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)19 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)16 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)9 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)6 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)6 StockTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo)5 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)5 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)4 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)4 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)4 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)3 ProductSpecEao (eu.ggnet.dwoss.spec.ee.eao.ProductSpecEao)3 FileJacket (eu.ggnet.dwoss.util.FileJacket)3 Test (org.junit.Test)3 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)2 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)2 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)2 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)2