Search in sources :

Example 1 with MSequence

use of org.compiere.model.MSequence in project lar_361 by comitsrl.

the class PosOrderGlobalVoiding method doIt.

// prepare
@Override
protected String doIt() throws Exception {
    log.info("C_Order_ID=" + p_C_Order_ID);
    m_processMsg = new StringBuilder();
    final MOrder order = new MOrder(getCtx(), p_C_Order_ID, get_TrxName());
    int count = 0;
    // Primero recupera las facturas asociadas a la orden
    // (previo a anulación de orden, porque sino se recuperarían también las anuladas)
    final MInvoice[] invoices = order.getInvoices();
    for (int i = 0; i < invoices.length; i++) {
        count++;
        int c_Invoice_ID = invoices[i].getC_Invoice_ID();
        // Recupera y anula la cabecera de cobros/pagos asociada a la factura
        // en caso de tratarse de una factura de venta al contado (cabecera no nula)
        final MLARPaymentHeader header = MLARPaymentHeader.getFromInvoice(getCtx(), c_Invoice_ID, get_TrxName());
        if (header == null)
            continue;
        if (header.processIt(MLARPaymentHeader.ACTION_Void)) {
            header.save(get_TrxName());
            m_processMsg.append("Cabecera de cobros anulada correctamente");
        } else
            m_processMsg.append("Cabecera de corbos: ").append(order.getProcessMsg());
    }
    // e imputaciones de pago.
    if (order.processIt(MOrder.ACTION_Void)) {
        order.save(get_TrxName());
        m_processMsg.append(", @C_Order_ID@ anulada correctamente");
    } else
        m_processMsg.append(", @C_Order_ID@: ").append(order.getProcessMsg());
    // Retrocede la secuencia asociada al tipo de documento de la factura
    for (int i = 0; i < invoices.length; i++) {
        int AD_Sequence_ID = invoices[i].getC_DocType().getDefiniteSequence_ID();
        final MSequence seq = new MSequence(getCtx(), AD_Sequence_ID, invoices[i].get_TrxName());
        seq.setCurrentNext(seq.getCurrentNext() - count);
        if (!seq.save())
            m_processMsg.append(", @AD_Sequence_ID@: Error al guardar");
    }
    return m_processMsg.toString();
}
Also used : MLARPaymentHeader(ar.com.ergio.model.MLARPaymentHeader) MOrder(org.compiere.model.MOrder) MInvoice(org.compiere.model.MInvoice) MSequence(org.compiere.model.MSequence)

Example 2 with MSequence

use of org.compiere.model.MSequence in project lar_361 by comitsrl.

the class InvoiceFiscalDocumentPrintManager method voidDocument.

@Override
protected void voidDocument() {
    // Anula la Factura/NC
    invoice.processIt(DocAction.ACTION_Void);
    invoice.saveEx();
    // Retrocede la secuencia en 1 (igual a lo que hace el proceso
    // PosOrderGlobalVoing)
    int ad_Sequence_ID = invoice.getC_DocType().getDefiniteSequence_ID();
    final MSequence seq = new MSequence(invoice.getCtx(), ad_Sequence_ID, invoice.get_TrxName());
    seq.setCurrentNext(seq.getCurrentNext() - 1);
    seq.saveEx();
}
Also used : FiscalDocumentPrint(ar.com.ergio.model.FiscalDocumentPrint) MSequence(org.compiere.model.MSequence)

Example 3 with MSequence

use of org.compiere.model.MSequence in project adempiere by adempiere.

the class SequenceCheck method checkTableID.

//	checkTableSequences
/**
	 * 	Check Table Sequence ID values
	 *	@param ctx context
	 *	@param sp server process or null
	 */
private static void checkTableID(Properties ctx, SvrProcess sp, // #284
boolean onlyADSequence) {
    int IDRangeEnd = DB.getSQLValue(null, "SELECT IDRangeEnd FROM AD_System");
    if (IDRangeEnd <= 0)
        IDRangeEnd = DB.getSQLValue(null, "SELECT MIN(IDRangeStart)-1 FROM AD_Replication");
    s_log.info("IDRangeEnd = " + IDRangeEnd);
    //
    String sql = "SELECT * FROM AD_Sequence " + "WHERE IsTableID='Y' ";
    if (onlyADSequence) {
        // HARDCODED: AD_Sequence  #284
        sql += " AND AD_Sequence_ID = 16 ";
    }
    sql += "ORDER BY Name";
    int counter = 0;
    PreparedStatement pstmt = null;
    String trxName = null;
    if (sp != null)
        trxName = sp.get_TrxName();
    try {
        pstmt = DB.prepareStatement(sql, trxName);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            MSequence seq = new MSequence(ctx, rs, trxName);
            int old = seq.getCurrentNext();
            int oldSys = seq.getCurrentNextSys();
            if (seq.validateTableIDValue()) {
                if (seq.getCurrentNext() != old) {
                    String msg = seq.getName() + " ID  " + old + " -> " + seq.getCurrentNext();
                    if (sp != null)
                        sp.addLog(0, null, null, msg);
                    else
                        s_log.fine(msg);
                }
                if (seq.getCurrentNextSys() != oldSys) {
                    String msg = seq.getName() + " Sys " + oldSys + " -> " + seq.getCurrentNextSys();
                    if (sp != null)
                        sp.addLog(0, null, null, msg);
                    else
                        s_log.fine(msg);
                }
                if (seq.save())
                    counter++;
                else
                    s_log.severe("Not updated: " + seq);
            }
        //	else if (CLogMgt.isLevel(6)) 
        //		log.fine("checkTableID - skipped " + tableName);
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        s_log.log(Level.SEVERE, sql, e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    s_log.fine("#" + counter);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MSequence(org.compiere.model.MSequence)

Example 4 with MSequence

use of org.compiere.model.MSequence in project adempiere by adempiere.

the class CreateDocType method createDocType.

//  createGLCategory
/**
	 *  Create Document Types with Sequence
	 *  @param Name name
	 *  @param PrintName print name
	 *  @param DocBaseType document base type
	 *  @param DocSubTypeSO sales order sub type
	 *  @param C_DocTypeShipment_ID shipment doc
	 *  @param C_DocTypeInvoice_ID invoice doc
	 *  @param StartNo start doc no
	 *  @param GL_Category_ID gl category
	 *  @return C_DocType_ID doc type or 0 for error
	 */
private int createDocType(String Name, String PrintName, String DocBaseType, String DocSubTypeSO, int C_DocTypeShipment_ID, int C_DocTypeInvoice_ID, int StartNo, int GL_Category_ID) {
    log.fine("In createDocType");
    log.fine("docBaseType: " + DocBaseType);
    log.fine("GL_Category_ID: " + GL_Category_ID);
    MSequence sequence = null;
    if (StartNo != 0) {
        sequence = new MSequence(Env.getCtx(), getAD_Client_ID(), Name, StartNo, trxname);
        if (!sequence.save()) {
            log.log(Level.SEVERE, "Sequence NOT created - " + Name);
            return 0;
        }
    }
    //MDocType dt = new MDocType (Env.getCtx(), DocBaseType, Name, trxname);
    MDocType dt = new MDocType(Env.getCtx(), 0, trxname);
    dt.setAD_Org_ID(0);
    dt.set_CustomColumn("DocBaseType", (Object) DocBaseType);
    dt.setName(Name);
    dt.setPrintName(Name);
    if (DocSubTypeSO != null)
        dt.setDocSubTypeSO(DocSubTypeSO);
    if (C_DocTypeShipment_ID != 0)
        dt.setC_DocTypeShipment_ID(C_DocTypeShipment_ID);
    if (C_DocTypeInvoice_ID != 0)
        dt.setC_DocTypeInvoice_ID(C_DocTypeInvoice_ID);
    if (GL_Category_ID != 0)
        dt.setGL_Category_ID(GL_Category_ID);
    if (sequence == null)
        dt.setIsDocNoControlled(false);
    else {
        dt.setIsDocNoControlled(true);
        dt.setDocNoSequence_ID(sequence.getAD_Sequence_ID());
    }
    dt.setIsSOTrx(false);
    if (!dt.save()) {
        log.log(Level.SEVERE, "DocType NOT created - " + Name);
        return 0;
    }
    //
    return dt.getC_DocType_ID();
}
Also used : MDocType(org.compiere.model.MDocType) MSequence(org.compiere.model.MSequence)

Example 5 with MSequence

use of org.compiere.model.MSequence in project lar_361 by comitsrl.

the class LAR_Validator method changeVoidDocumentNo.

/**
 * Change DocumentNo in order to avoid modified sequence for given document
 */
// TODO - Improve and add this behavior to ADempiere and make it configurable (ideal)
private String changeVoidDocumentNo(final PO po) {
    final Properties ctx = po.getCtx();
    PO revPo = null;
    MSequence seq = null;
    // Corrije el nro de documento de la factura anulada y su reversa asociada
    if (po.get_TableName().equals(MInvoice.Table_Name)) {
        final MInvoice invoice = (MInvoice) po;
        // Si no se tiene la referencia a la reversión, no se procesa
        if (invoice.getReversal_ID() == 0)
            return null;
        revPo = new MInvoice(ctx, invoice.getReversal_ID(), invoice.get_TrxName());
        final MInvoice revInvoice = (MInvoice) revPo;
        log.info("Change DocumentNo of " + revInvoice);
        // Intenta recuperar la secuencia "definitiva". Si no tiene, intenta
        // recupera la secuencia "normal". Si no tiene, no sea hace nada debido
        // a que le documento NO tiene secuencia configurada
        int ad_Sequence_ID = invoice.getC_DocType().getDefiniteSequence_ID();
        if (ad_Sequence_ID == 0)
            ad_Sequence_ID = invoice.getC_DocType().getDocNoSequence_ID();
        if (ad_Sequence_ID != 0)
            seq = new MSequence(ctx, ad_Sequence_ID, invoice.get_TrxName());
        // Redefine los nros de documento y las descripciones de las facturas
        String revDocumentNo = "Rev-" + invoice.getDocumentNo() + "-" + invoice.getC_Invoice_ID();
        String voidDocumentNo = "Anu-" + invoice.getDocumentNo() + "-" + invoice.getC_Invoice_ID();
        revInvoice.setDocumentNo(revDocumentNo);
        revInvoice.setDescription("(" + voidDocumentNo + "<-)");
        invoice.setDocumentNo(voidDocumentNo);
        invoice.setDescription("(" + revDocumentNo + "<-)");
        // Si la secuencia es automática, retrocede la numeración
        if (seq != null && seq.isAutoSequence())
            seq.setCurrentNext(seq.getCurrentNext() - 1);
    }
    // Corrije el nro de documento del remito anulado y su reverso asociado
    if (po.get_TableName().equals(MInOut.Table_Name)) {
        final MInOut shipment = (MInOut) po;
        // Si no se tiene la referencia a la reversión, no se procesa
        if (shipment.getReversal_ID() == 0)
            return null;
        revPo = new MInOut(ctx, shipment.getReversal_ID(), shipment.get_TrxName());
        final MInOut revShipment = (MInOut) revPo;
        log.info("Change DocumentNo of " + revShipment);
        // Intenta recuperar la secuencia "definitiva". En caso que sea nula,
        // recupera la secuencia "normal"
        int AD_Sequence_ID = shipment.getC_DocType().getDefiniteSequence_ID();
        if (AD_Sequence_ID == 0)
            AD_Sequence_ID = shipment.getC_DocType().getDocNoSequence_ID();
        if (AD_Sequence_ID != 0)
            seq = new MSequence(ctx, AD_Sequence_ID, shipment.get_TrxName());
        String revDocumentNo = "Rev-" + shipment.getDocumentNo() + "-" + shipment.getM_InOut_ID();
        String voidDocumentNo = "Anu-" + shipment.getDocumentNo() + "-" + shipment.getM_InOut_ID();
        revShipment.setDocumentNo(revDocumentNo);
        revShipment.setDescription("(" + voidDocumentNo + "<-)");
        shipment.setDocumentNo(voidDocumentNo);
        shipment.setDescription("(" + revDocumentNo + "<-)");
        // Si encontró una secuencia, y la misma es automática, retrocede la numeración
        if (seq != null && seq.isAutoSequence())
            seq.setCurrentNext(seq.getCurrentNext() - 1);
    }
    // (siempre y cuando hayan cambiado y no sean nulos)
    if (revPo != null && !revPo.save())
        return "Error al guardar el documento inverso";
    if (po.is_Changed() && !po.save())
        return "Error al guardar el documento anulado";
    if (seq != null && seq.is_Changed() && !seq.save())
        return "Error al guardar la secuencia";
    return null;
}
Also used : MInOut(org.compiere.model.MInOut) MInvoice(org.compiere.model.MInvoice) Properties(java.util.Properties) MSequence(org.compiere.model.MSequence) PO(org.compiere.model.PO)

Aggregations

MSequence (org.compiere.model.MSequence)6 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 MInvoice (org.compiere.model.MInvoice)2 FiscalDocumentPrint (ar.com.ergio.model.FiscalDocumentPrint)1 MLARPaymentHeader (ar.com.ergio.model.MLARPaymentHeader)1 BigDecimal (java.math.BigDecimal)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 MDocType (org.compiere.model.MDocType)1 MInOut (org.compiere.model.MInOut)1 MOrder (org.compiere.model.MOrder)1 PO (org.compiere.model.PO)1 AdempiereUserError (org.compiere.util.AdempiereUserError)1 MLCODIANFormat (org.globalqss.model.MLCODIANFormat)1 X_LCO_DIAN_SendSchedule (org.globalqss.model.X_LCO_DIAN_SendSchedule)1 X_LCO_DIAN_SendScheduleLine (org.globalqss.model.X_LCO_DIAN_SendScheduleLine)1 X_LCO_DIAN_XML_Header (org.globalqss.model.X_LCO_DIAN_XML_Header)1