details: /erp/devel/pi/rev/56962e6875b1
changeset: 10807:56962e6875b1
user: Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date: Fri Feb 18 20:26:29 2011 +0100
summary: Adds module script AlertsForWrongInvoices
diffstat:
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices.class
| 0
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoicesData.class
| 0
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices.java
| 75 +
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices_data.xsql
| 132 +++
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoicesData.java
| 414 ++++++++++
5 files changed, 621 insertions(+), 0 deletions(-)
diffs (truncated from 637 to 300 lines):
diff -r c64b22623f73 -r 56962e6875b1
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices.class
Binary file
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices.class
has changed
diff -r c64b22623f73 -r 56962e6875b1
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoicesData.class
Binary file
modules/org.openbravo.advpaymentmngt/build/classes/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoicesData.class
has changed
diff -r c64b22623f73 -r 56962e6875b1
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++
b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices.java
Fri Feb 18 20:26:29 2011 +0100
@@ -0,0 +1,75 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ *************************************************************************
+ */
+package org.openbravo.advpaymentmngt.modulescript;
+
+import javax.servlet.ServletException;
+
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.modulescript.ModuleScript;
+
+public class AlertsForWrongInvoices extends ModuleScript {
+
+ @Override
+ // Inserting Alerts for invoices which needs to be recalculated/processed
+ public void execute() {
+ try {
+ ConnectionProvider cp = getConnectionProvider();
+ AlertsForWrongInvoicesData[] data =
AlertsForWrongInvoicesData.select(cp);
+ for (AlertsForWrongInvoicesData wrongInvoice : data) {
+ createAlert(cp, wrongInvoice);
+ }
+ } catch (Exception e) {
+ handleError(e);
+ }
+ }
+
+ private void createAlert(ConnectionProvider cp, AlertsForWrongInvoicesData
wrongInvoice)
+ throws ServletException {
+ final String SALES_INVOICE_WINDOW = "167";
+ final String PURCHASE_INVOICE_WINDOW = "183";
+ final String SALES_INVOICE_TAB = "263";
+ final String PURCHASE_INVOICE_TAB = "290";
+ String ALERT_RULE = "Wrong purchase invoice. Wrong amount in payment plan
detail";
+ final String ALERT_RULE_SQL = "select distinct
ad_column_identifier('c_invoice', fin_payment_schedule.c_invoice_id, 'en_US')
as record_id, fin_payment_schedule.c_invoice_id as referencekey_id, 0 as
ad_role_id, null as ad_user_id, 'Posted refund payment. Please ensure that it
is unposted before applying the module version upgrade.' as description, 'Y' as
isActive, fin_payment_schedule.ad_org_id, fin_payment_schedule.ad_client_id,
now() as created, 0 as createdBy, now() as updated, 0 as updatedBy from
fin_payment_schedule, fin_payment_scheduledetail where
fin_payment_schedule.fin_payment_schedule_id =
fin_payment_scheduledetail.fin_payment_schedule_invoice group by
fin_payment_schedule.ad_org_id, fin_payment_schedule.ad_client_id,
fin_payment_schedule.fin_payment_schedule_id,
fin_payment_schedule.c_invoice_id, fin_payment_schedule.amount having
fin_payment_schedule.amount <> sum(fin_payment_scheduledetail.amount) order by
1";
+ String WindowInvoiceId = PURCHASE_INVOICE_TAB;
+ String strTabId = PURCHASE_INVOICE_TAB;
+ if ("Y".equals(wrongInvoice.issotrx)) {
+ strTabId = SALES_INVOICE_TAB;
+ WindowInvoiceId = SALES_INVOICE_WINDOW;
+ ALERT_RULE = "Wrong sales invoice. Wrong amount in payment plan detail";
+ }
+ String strName = "Invoice: '" + wrongInvoice.invoice
+ + "' needs to be reactivated and processed again due to wrong payment
info.";
+ String oldAlertRuleId = AlertsForWrongInvoicesData.getAlertRuleId(cp,
ALERT_RULE, wrongInvoice.adClientId);
+ if (!AlertsForWrongInvoicesData.existsAlert(cp, oldAlertRuleId,
wrongInvoice.cInvoiceId)) {
+ if (!AlertsForWrongInvoicesData.existsAlertRule(cp, ALERT_RULE)) {
+ AlertsForWrongInvoicesData.insertAlertRule(cp, wrongInvoice.adClientId,
+ ALERT_RULE, strTabId, ALERT_RULE_SQL);
+ AlertsForWrongInvoicesData[] roles =
AlertsForWrongInvoicesData.getRoleId(cp, WindowInvoiceId,
wrongInvoice.adClientId);
+ for(AlertsForWrongInvoicesData role : roles){
+ AlertsForWrongInvoicesData.insertAlertRecipient(cp,
wrongInvoice.adClientId, wrongInvoice.adOrgId,
AlertsForWrongInvoicesData.getAlertRuleId(cp, ALERT_RULE,
wrongInvoice.adClientId),
+ role.adRoleId);
+ }
+ }
+ String alertRuleId = AlertsForWrongInvoicesData.getAlertRuleId(cp,
ALERT_RULE, wrongInvoice.adClientId);
+ AlertsForWrongInvoicesData.insertAlert(cp, wrongInvoice.adClientId,
wrongInvoice.adOrgId, strName, alertRuleId,
+ wrongInvoice.invoice, wrongInvoice.cInvoiceId);
+ }
+ }
+}
diff -r c64b22623f73 -r 56962e6875b1
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices_data.xsql
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++
b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoices_data.xsql
Fri Feb 18 20:26:29 2011 +0100
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+
************************************************************************************
+ * Copyright (C) 2011 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at
http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+
************************************************************************************
+-->
+<SqlClass name="AlertsForWrongInvoicesData"
package="org.openbravo.advpaymentmngt.modulescript">
+ <SqlClassComment></SqlClassComment>
+ <SqlMethod name="select" type="preparedStatement" return="multiple">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql>
+ <![CDATA[
+ select distinct fin_payment_schedule.ad_client_id,
ad_column_identifier('c_invoice', fin_payment_schedule.c_invoice_id, 'en_US')
as invoice,
+ fin_payment_schedule.c_invoice_id, fin_payment_schedule.ad_org_id,
c_invoice.issotrx, '' as ad_role_id
+ from c_invoice, fin_payment_schedule, fin_payment_scheduledetail
+ where c_invoice.c_invoice_id = fin_payment_schedule.c_invoice_id
+ and fin_payment_schedule.fin_payment_schedule_id =
fin_payment_scheduledetail.fin_payment_schedule_invoice
+ group by fin_payment_schedule.ad_client_id,
fin_payment_schedule.ad_org_id, c_invoice.issotrx,
fin_payment_schedule.fin_payment_schedule_id,
fin_payment_schedule.c_invoice_id, fin_payment_schedule.amount
+ having fin_payment_schedule.amount <>
sum(fin_payment_scheduledetail.amount)
+ order by 1, 2
+ ]]>
+ </Sql>
+ </SqlMethod>
+ <SqlMethod name="existsAlertRule" type="preparedStatement" return="boolean">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT COUNT(*) AS EXISTING
+ FROM AD_ALERTRULE
+ WHERE NAME = ?
+ AND ISACTIVE = 'Y'
+ ]]>
+ </Sql>
+ <Parameter name="alertRule"/>
+ </SqlMethod>
+ <SqlMethod name="existsAlert" type="preparedStatement" return="boolean">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT COUNT(*) AS EXISTING
+ FROM AD_ALERT
+ WHERE AD_ALERTRULE_ID = ?
+ AND REFERENCEKEY_ID = ?
+ AND ISFIXED = 'N'
+ ]]>
+ </Sql>
+ <Parameter name="alertRule"/>
+ <Parameter name="invoice"/>
+ </SqlMethod>
+ <SqlMethod name="getAlertRuleId" type="preparedStatement" return="string">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT MAX(ad_alertrule_id) AS name
+ FROM AD_ALERTRULE
+ WHERE NAME LIKE ?
+ AND ISACTIVE = 'Y'
+ AND AD_CLIENT_ID = ?
+ ]]></Sql>
+ <Parameter name="name"/>
+ <Parameter name="client"/>
+ </SqlMethod>
+ <SqlMethod name="getRoleId" type="preparedStatement" return="multiple">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ SELECT distinct ad_role_id
+ FROM ad_window_access
+ WHERE ad_window_id = ?
+ AND AD_CLIENT_ID = ?
+ AND ISACTIVE = 'Y'
+ ]]></Sql>
+ <Parameter name="window"/>
+ <Parameter name="clientId"/>
+ </SqlMethod>
+ <SqlMethod name="insertAlertRule" type="preparedStatement" return="rowcount">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ INSERT INTO AD_ALERTRULE (
+ AD_ALERTRULE_ID, AD_CLIENT_ID, AD_ORG_ID,ISACTIVE,
+ CREATED, CREATEDBY, UPDATED, UPDATEDBY,
+ NAME, AD_TAB_ID, FILTERCLAUSE, TYPE,
+ SQL
+ ) VALUES (
+ get_uuid(), ?, '0', 'Y',
+ now(), '100', now(), '100',
+ ?, ?, '', 'D',
+ ?
+ )
+ ]]></Sql>
+ <Parameter name="clientId"/>
+ <Parameter name="name"/>
+ <Parameter name="tabId"/>
+ <Parameter name="sql"/>
+ </SqlMethod>
+ <SqlMethod name="insertAlert" type="preparedStatement" return="rowcount">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ INSERT INTO AD_Alert (
+ AD_Alert_ID, AD_Client_ID, AD_Org_ID, IsActive,
+ Created, CreatedBy, Updated, UpdatedBy,
+ Description, AD_AlertRule_ID, Record_Id, Referencekey_ID
+ ) VALUES (
+ get_uuid(), ?, ?, 'Y',
+ NOW(), '0', NOW(), '0',
+ ?, ?, ?, ?)
+ ]]>
+ </Sql>
+ <Parameter name="client"/>
+ <Parameter name="org"/>
+ <Parameter name="description" />
+ <Parameter name="adAlertRuleId" />
+ <Parameter name="recordId" />
+ <Parameter name="referencekey_id" />
+ </SqlMethod>
+ <SqlMethod name="insertAlertRecipient" type="preparedStatement"
return="rowcount">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ INSERT INTO ad_alertrecipient(
+ ad_user_id, ad_client_id, ad_org_id, isactive, created, createdby,
+ updated, updatedby, ad_alertrecipient_id, ad_alertrule_id,
ad_role_id,
+ sendemail)
+ VALUES (null, ?, ?, 'Y', now(), '100',
+ now(), '100', get_uuid(), ?, ?,
+ 'N')
+ ]]>
+ </Sql>
+ <Parameter name="client"/>
+ <Parameter name="org"/>
+ <Parameter name="adAlertRuleId" />
+ <Parameter name="role" />
+ </SqlMethod>
+</SqlClass>
diff -r c64b22623f73 -r 56962e6875b1
modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoicesData.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++
b/modules/org.openbravo.advpaymentmngt/src-util/modulescript/src/src/org/openbravo/advpaymentmngt/modulescript/AlertsForWrongInvoicesData.java
Fri Feb 18 20:26:29 2011 +0100
@@ -0,0 +1,414 @@
+//Sqlc generated V1.O00-1
+package org.openbravo.advpaymentmngt.modulescript;
+
+import java.sql.*;
+
+import org.apache.log4j.Logger;
+
+import javax.servlet.ServletException;
+
+import org.openbravo.data.FieldProvider;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.data.UtilSql;
+import java.util.*;
+
+class AlertsForWrongInvoicesData implements FieldProvider {
+static Logger log4j = Logger.getLogger(AlertsForWrongInvoicesData.class);
+ private String InitRecordNumber="0";
+ public String adClientId;
+ public String invoice;
+ public String cInvoiceId;
+ public String adOrgId;
+ public String issotrx;
+ public String adRoleId;
+
+ public String getInitRecordNumber() {
+ return InitRecordNumber;
+ }
+
+ public String getField(String fieldName) {
+ if (fieldName.equalsIgnoreCase("ad_client_id") ||
fieldName.equals("adClientId"))
+ return adClientId;
+ else if (fieldName.equalsIgnoreCase("invoice"))
+ return invoice;
+ else if (fieldName.equalsIgnoreCase("c_invoice_id") ||
fieldName.equals("cInvoiceId"))
+ return cInvoiceId;
+ else if (fieldName.equalsIgnoreCase("ad_org_id") ||
fieldName.equals("adOrgId"))
+ return adOrgId;
+ else if (fieldName.equalsIgnoreCase("issotrx"))
+ return issotrx;
+ else if (fieldName.equalsIgnoreCase("ad_role_id") ||
fieldName.equals("adRoleId"))
+ return adRoleId;
+ else {
+ log4j.debug("Field does not exist: " + fieldName);
+ return null;
+ }
+ }
+
+ public static AlertsForWrongInvoicesData[] select(ConnectionProvider
connectionProvider) throws ServletException {
+ return select(connectionProvider, 0, 0);
+ }
+
+ public static AlertsForWrongInvoicesData[] select(ConnectionProvider
connectionProvider, int firstRegister, int numberRegisters) throws
ServletException {
+ String strSql = "";
+ strSql = strSql +
+ " select distinct fin_payment_schedule.ad_client_id,
ad_column_identifier('c_invoice', fin_payment_schedule.c_invoice_id, 'en_US')
as invoice, " +
+ " fin_payment_schedule.c_invoice_id,
fin_payment_schedule.ad_org_id, c_invoice.issotrx, '' as ad_role_id" +
+ " from c_invoice, fin_payment_schedule, fin_payment_scheduledetail"
+
+ " where c_invoice.c_invoice_id = fin_payment_schedule.c_invoice_id
" +
+ " and fin_payment_schedule.fin_payment_schedule_id =
fin_payment_scheduledetail.fin_payment_schedule_invoice" +
+ " group by fin_payment_schedule.ad_client_id,
fin_payment_schedule.ad_org_id, c_invoice.issotrx,
fin_payment_schedule.fin_payment_schedule_id,
fin_payment_schedule.c_invoice_id, fin_payment_schedule.amount" +
+ " having fin_payment_schedule.amount <>
sum(fin_payment_scheduledetail.amount)" +
+ " order by 1, 2";
+
+ ResultSet result;
+ Vector<java.lang.Object> vector = new Vector<java.lang.Object>(0);
+ PreparedStatement st = null;
+
+ try {
+ st = connectionProvider.getPreparedStatement(strSql);
+
+ result = st.executeQuery();
+ long countRecord = 0;
+ long countRecordSkip = 1;
+ boolean continueResult = true;
+ while(countRecordSkip < firstRegister && continueResult) {
+ continueResult = result.next();
+ countRecordSkip++;
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits