Beispiel #1
0
  @Override
  public Result processWorkPackage(
      final I_C_Queue_WorkPackage workPackage, final String localTrxName) {
    final ILoggable loggable = getLoggable();
    final IParams params = getParameters();

    //
    // Extract param: SQL code to execute (and normalize it)
    final String sqlRaw = params.getParameterAsString(PARAM_Code);
    Check.assumeNotEmpty(sqlRaw, "Missing parameter: {}", PARAM_Code);
    final String sql = parseSql(sqlRaw, workPackage);
    loggable.addLog("SQL to execute: {0}", sql);

    //
    // Extract param: ReEnqueue
    final boolean isReEnqueue =
        params.hasParameter(PARAM_ReEnqueue)
            ? params.getParameterAsBool(PARAM_ReEnqueue)
            : DEFAULT_ReEnqueue;

    //
    // Execute the SQL update
    final int updateCount = executeSql(sql, localTrxName);
    loggable.addLog("Updated {0} records", updateCount);

    //
    // Re-enqueue the Workpackage if there was something updated and if we are asked to do so
    if (updateCount > 0) {
      if (isReEnqueue) {
        final Properties ctx = InterfaceWrapperHelper.getCtx(workPackage);
        final I_C_Queue_WorkPackage nextWorkpackage =
            Services.get(IWorkPackageQueueFactory.class)
                .getQueueForEnqueuing(ctx, getClass())
                .newBlock()
                .setContext(ctx)
                .newWorkpackage()
                .bindToTrxName(localTrxName)
                //
                // Workpackage Parameters
                .parameters()
                .setParameter(PARAM_Code, sql)
                .end()
                //
                // Build & enqueue
                .build();

        loggable.addLog("New workpackage enqueued: {0}", nextWorkpackage);
      } else {
        loggable.addLog(
            "No new workpackages will be reenqueued because parameter {0} is false",
            PARAM_ReEnqueue);
      }
    } else {
      loggable.addLog(
          "No new workpackages will be reenqueued because there was nothing updated in this run");
    }

    return Result.SUCCESS;
  }
  private boolean addInvoice0(final I_C_Invoice invoice) {
    //
    // Skip not posted invoices, but warn the user
    if (!invoice.isPosted()) {
      loggable.addLog("@Error@: @C_Invoice_ID@ @Posted@=@N@: " + invoiceBL.getSummary(invoice));
      return false;
    }

    //
    // Tax declaration lines (one for each invoice tax record)
    final List<I_C_InvoiceTax> invoiceTaxes = invoiceDAO.retrieveTaxes(invoice);
    final Map<Integer, I_C_TaxDeclarationLine> taxId2taxDeclarationLine =
        new HashMap<>(invoiceTaxes.size());
    for (final I_C_InvoiceTax invoiceTax : invoiceTaxes) {
      final int taxId = invoiceTax.getC_Tax_ID();
      final I_C_TaxDeclarationLine taxDeclarationLine =
          createTaxDeclarationLine(invoice, invoiceTax);
      final I_C_TaxDeclarationLine taxDeclarationLineOld =
          taxId2taxDeclarationLine.put(taxId, taxDeclarationLine);
      Check.assumeNull(
          taxDeclarationLineOld,
          "More than one invoice tax line for {0}, taxId={1}",
          invoice,
          taxId);
    }

    //
    // Tax declaration accounting records
    final List<I_Fact_Acct> factAcctRecords =
        factAcctDAO
            .retrieveQueryForDocument(invoice)
            // fetch only those Fact_Acct records which are about taxes, i.e.
            .addNotEqualsFilter(I_Fact_Acct.COLUMN_C_Tax_ID, null) // C_Tax_ID is set
            .addEqualsFilter(I_Fact_Acct.COLUMN_Line_ID, null) // Line_ID is NOT set
            //
            .create()
            .list();
    for (final I_Fact_Acct factAcctRecord : factAcctRecords) {
      //
      // Link to Tax Declaration Line only if this Fact_Acct is about tax bookings. Which means:
      // * it's document level booking (Line_ID <= 0)
      // * we have a C_TaxDeclarationLine which has the same tax as this booking
      I_C_TaxDeclarationLine taxDeclarationLine = null;
      if (factAcctRecord.getLine_ID() <= 0) {
        final int taxId = factAcctRecord.getC_Tax_ID();
        taxDeclarationLine = taxId2taxDeclarationLine.get(taxId);
      }

      createTaxDeclarationAcct(taxDeclarationLine, factAcctRecord);
    }

    return true;
  }
  private boolean addGLJournalLine0(final I_GL_JournalLine glJournalLine) {
    final List<I_Fact_Acct> factAcctRecords =
        factAcctDAO.retrieveForDocumentLine(
            I_GL_Journal.Table_Name, glJournalLine.getGL_Journal_ID(), glJournalLine);

    //
    // Skip not posted GL Journal Lines, but warn the user
    if (factAcctRecords.isEmpty()) {
      final String summary = journalLineBL.getDocumentNo(glJournalLine);
      loggable.addLog("@Error@: @I_GL_JournalLine_ID@ @Posted@=@N@: " + summary);
      return false;
    }

    final I_C_TaxDeclarationLine taxDeclarationLine = createTaxDeclarationLine(glJournalLine);
    createTaxDeclarationAccts(taxDeclarationLine, factAcctRecords.iterator());

    return true;
  }
Beispiel #4
0
  @Override
  public Result processWorkPackage(
      final I_C_Queue_WorkPackage workpackage, final String localTrxName) {
    final IQueueDAO queueDAO = Services.get(IQueueDAO.class);
    final ILoggable loggable = Services.get(IWorkPackageBL.class).createLoggable(workpackage);

    // maybe the underyling order line was deleted meanwhile, after the order was reactivated. Using
    // retrieveItemsSkipMissing() because we don't need to make a fuss about that.
    final List<Object> models =
        queueDAO.retrieveItemsSkipMissing(workpackage, Object.class, localTrxName);
    loggable.addLog("Retrieved " + models.size() + " items for this work package");

    for (final Object model : models) {
      final String tableName = InterfaceWrapperHelper.getModelTableName(model);

      final IReceiptScheduleProducer producer =
          Services.get(IReceiptScheduleProducerFactory.class).createProducer(tableName, false);
      final List<I_M_ReceiptSchedule> previousSchedules = Collections.emptyList();
      producer.createOrUpdateReceiptSchedules(model, previousSchedules);
    }
    return Result.SUCCESS;
  }