All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eevolution.process.ProcessingInvoiceSelection Maven / Gradle / Ivy

There is a newer version: 3.9.4.001
Show newest version
/******************************************************************************
 * Product: ADempiere ERP & CRM Smart Business Solution                       *
 * Copyright (C) 2003-2016 e-Evolution Consultants. All Rights Reserved.      *
 * Copyright (C) 2003-2016 Victor Pèrez Juárez 								  *
 * This program is free software; you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program is distributed in the hope   *
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.           *
 * See the GNU General Public License for more details.                       *
 * You should have received a copy of the GNU General Public License along    *
 * with this program; if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 * For the text or an alternative of this public license, you may reach us    *
 * Contributor(s): Victor Pérez Juúrez  ([email protected])		  *
 * Sponsors: e-Evolution Consultants (http://www.e-evolution.com/)            *
 *****************************************************************************/

package org.eevolution.process;

import org.compiere.model.MInvoice;
import org.eevolution.model.MWMInOutBound;
import org.eevolution.model.MWMInOutBoundLine;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Generated Process for (Invoice Selection)
 *
 * @author ADempiere (generated)
 * @author eEvolution author Victor Perez 
 * @version Release 3.8.2
 */
public class ProcessingInvoiceSelection extends ProcessingInvoiceSelectionAbstract {

    @Override
    protected void prepare() {
        super.prepare();
    }

    @Override
    protected String doIt() throws Exception {
        List invoices = (List) getInstancesForSelection(get_TrxName());
        if (getRecord_ID() > 0 && getSelectionKeys().size() > 0 && getTable_ID() == MWMInOutBound.Table_ID) {
            createInboundLineFrom(invoices);
        } else if (getRecord_ID() == 0 && getSelectionKeys().size() > 0) {
            UpdatingInvoiceProperties(invoices);
        }
        return "";
    }

    /**
     * Updating Invoice Properties
     * @param invoices
     */
    private void UpdatingInvoiceProperties(List invoices) {
        invoices.stream().filter(invoice -> invoice != null)
                .forEach(invoice -> {
                    int columns = invoice.get_ColumnCount();
                    for (int index = 0; index < columns; index++) {
                        String columnName = invoice.get_ColumnName(index);
                        Optional.ofNullable(getSelection(invoice.get_ID(), getPrefixAliasForTableSelection() + columnName))
                                .ifPresent(value -> invoice.set_ValueOfColumn(columnName, value));
                    }
                    invoice.saveEx();
                });


    }

    /**
     * Create inboud lines from invoice
     * @param invoices
     */
    private void createInboundLineFrom(List invoices) {
        MWMInOutBound inOutBound = (MWMInOutBound) getInstance(get_TrxName());
        AtomicInteger lineNo = new AtomicInteger(10);
        invoices.stream()
                .filter(invoice -> invoice != null)
                .flatMap(invoice -> Arrays.stream(invoice.getLines(true)))
                .forEach(invoiceLine -> {
                    MWMInOutBoundLine outBoundLine = MWMInOutBoundLine.getByInvoiceLine(invoiceLine);
                    if (outBoundLine == null) {
                        outBoundLine = new MWMInOutBoundLine(inOutBound, invoiceLine);
                        outBoundLine.setLine(lineNo.get());
                        outBoundLine.saveEx();
                        lineNo.updateAndGet(line -> line + 10);
                    }
                });

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy