IDEMPIERE-217 Allocate Payment to Charge

Credits:
Adaxa (Paul Bowden) / development
David Peñuela / integration
Edwin Ang / testings
This commit is contained in:
Carlos Ruiz 2012-08-22 22:27:33 -05:00
parent 85b4deb4db
commit 56fff1e1b8
7 changed files with 279 additions and 23 deletions

View File

@ -0,0 +1,63 @@
-- Aug 21, 2012
-- IDEMPIERE-217 Allocate Payment to Charge
UPDATE AD_Column SET AD_Val_Rule_ID=52032,Updated=TO_DATE('2011-07-05 11:35:47','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3050;
INSERT INTO AD_Val_Rule (AD_Client_ID,AD_Org_ID,AD_Val_Rule_ID,Code,Created,CreatedBy,EntityType,IsActive,Name,Type,Updated,UpdatedBy) VALUES (0,0,52103,'(C_Charge.C_Charge_ID IN (
SELECT c.C_Charge_ID
FROM C_Charge c
JOIN C_ChargeType ct ON (ct.C_ChargeType_ID = c.C_ChargeType_ID)
JOIN C_ChargeType_Doctype ctd ON (ctd.C_ChargeType_ID = ct.C_ChargeType_ID)
JOIN C_DocType dt ON (dt.C_DocType_ID =ctd.C_DocType_ID AND dt.AD_Client_ID= ctd.AD_Client_ID AND dt.DocBaseType= ''CMA'')
) OR
(SELECT COUNT(*) FROM C_ChargeType_DocType WHERE AD_Client_ID=@AD_Client_ID@) = 0)',TO_DATE('2011-07-05 11:37:30','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','C_Charge_ID by DocType Allocation','S',TO_DATE('2011-07-05 11:37:30','YYYY-MM-DD HH24:MI:SS'),100);
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,AD_Val_Rule_ID,ColumnName,Created,CreatedBy,Description,EntityType,FieldLength,Help,IsActive,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,61804,968,0,19,390,52103,'C_Charge_ID',TO_DATE('2011-07-05 11:38:51','YYYY-MM-DD HH24:MI:SS'),100,'Additional document charges','D',22,'The Charge indicates a type of Charge (Handling, Shipping, Restocking)','Y','Y','N','N','N','N','N','N','N','N','N','N','N','Charge',0,TO_DATE('2011-07-05 11:38:51','YYYY-MM-DD HH24:MI:SS'),100,0);
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=61804 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID);
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,EntityType,Help,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,Updated,UpdatedBy) VALUES (0,61804,61876,0,349,TO_DATE('2011-07-05 11:39:36','YYYY-MM-DD HH24:MI:SS'),100,'Additional document charges',22,'D','The Charge indicates a type of Charge (Handling, Shipping, Restocking)','Y','Y','Y','N','N','N','N','N','Charge',TO_DATE('2011-07-05 11:39:36','YYYY-MM-DD HH24:MI:SS'),100);
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=61876 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID);
UPDATE AD_Field SET SeqNo=90,IsDisplayed='Y' WHERE AD_Field_ID=61876;
UPDATE AD_Field SET SeqNo=100,IsDisplayed='Y' WHERE AD_Field_ID=4368;
UPDATE AD_Field SET SeqNo=110,IsDisplayed='Y' WHERE AD_Field_ID=4387;
UPDATE AD_Field SET SeqNo=120,IsDisplayed='Y' WHERE AD_Field_ID=4375;
UPDATE AD_Field SET SeqNo=130,IsDisplayed='Y' WHERE AD_Field_ID=4380;
UPDATE AD_Field SET SeqNo=140,IsDisplayed='Y' WHERE AD_Field_ID=8931;
UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_DATE('2011-07-05 11:40:14','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=61876;
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53137,0,TO_DATE('2011-07-05 11:41:29','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','Charge to apply difference amount to.','I',TO_DATE('2011-07-05 11:41:29','YYYY-MM-DD HH24:MI:SS'),100,'ChargeDifference');
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53137 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID);
ALTER TABLE C_AllocationLine ADD C_Charge_ID NUMBER(10) DEFAULT NULL ;
UPDATE AD_System
SET LastMigrationScriptApplied='886_IDEMPIERE-217.sql'
WHERE LastMigrationScriptApplied<'886_IDEMPIERE-217.sql'
OR LastMigrationScriptApplied IS NULL
;

View File

@ -0,0 +1,64 @@
-- Aug 21, 2012
-- IDEMPIERE-217 Allocate Payment to Charge
UPDATE AD_Column SET AD_Val_Rule_ID=52032,Updated=TO_TIMESTAMP('2011-07-05 11:35:47','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3050;
INSERT INTO AD_Val_Rule (AD_Client_ID,AD_Org_ID,AD_Val_Rule_ID,Code,Created,CreatedBy,EntityType,IsActive,Name,Type,Updated,UpdatedBy) VALUES (0,0,52103,'(C_Charge.C_Charge_ID IN (
SELECT c.C_Charge_ID
FROM C_Charge c
JOIN C_ChargeType ct ON (ct.C_ChargeType_ID = c.C_ChargeType_ID)
JOIN C_ChargeType_Doctype ctd ON (ctd.C_ChargeType_ID = ct.C_ChargeType_ID)
JOIN C_DocType dt ON (dt.C_DocType_ID =ctd.C_DocType_ID AND dt.AD_Client_ID= ctd.AD_Client_ID AND dt.DocBaseType= ''CMA'')
) OR
(SELECT COUNT(*) FROM C_ChargeType_DocType WHERE AD_Client_ID=@AD_Client_ID@) = 0)',TO_TIMESTAMP('2011-07-05 11:37:30','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','C_Charge_ID by DocType Allocation','S',TO_TIMESTAMP('2011-07-05 11:37:30','YYYY-MM-DD HH24:MI:SS'),100);
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,AD_Val_Rule_ID,ColumnName, Created,CreatedBy,Description,EntityType,FieldLength,Help,IsActive,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted, IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy, Version) VALUES (0,61804,968,0,19,390,52103,'C_Charge_ID',TO_TIMESTAMP('2011-07-05 11:38:51','YYYY-MM-DD HH24:MI:SS'),100, 'Additional document charges','D',22,'The Charge indicates a type of Charge (Handling, Shipping, Restocking)', 'Y','Y','N','N','N','N','N','N','N','N','N','N','N','Charge',0,TO_TIMESTAMP('2011-07-05 11:38:51','YYYY-MM-DD HH24:MI:SS'),100,0);
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated, UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated, t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=61804 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID);
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength, EntityType,Help,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,Updated, UpdatedBy) VALUES (0,61804,61876,0,349,TO_TIMESTAMP('2011-07-05 11:39:36','YYYY-MM-DD HH24:MI:SS'),100,'Additional document charges', 22,'D','The Charge indicates a type of Charge (Handling, Shipping, Restocking)','Y','Y','Y','N','N','N','N','N','Charge', TO_TIMESTAMP('2011-07-05 11:39:36','YYYY-MM-DD HH24:MI:SS'),100);
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby, Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created, t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=61876 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID);
UPDATE AD_Field SET SeqNo=90,IsDisplayed='Y' WHERE AD_Field_ID=61876;
UPDATE AD_Field SET SeqNo=100,IsDisplayed='Y' WHERE AD_Field_ID=4368;
UPDATE AD_Field SET SeqNo=110,IsDisplayed='Y' WHERE AD_Field_ID=4387;
UPDATE AD_Field SET SeqNo=120,IsDisplayed='Y' WHERE AD_Field_ID=4375;
UPDATE AD_Field SET SeqNo=130,IsDisplayed='Y' WHERE AD_Field_ID=4380;
UPDATE AD_Field SET SeqNo=140,IsDisplayed='Y' WHERE AD_Field_ID=8931;
UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_TIMESTAMP('2011-07-05 11:40:14','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=61876;
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53137,0,TO_TIMESTAMP('2011-07-05 11:41:29','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','Charge to apply difference amount to.','I',TO_TIMESTAMP('2011-07-05 11:41:29','YYYY-MM-DD HH24:MI:SS'),100,'ChargeDifference');
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53137 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID);
ALTER TABLE C_AllocationLine ADD C_Charge_ID NUMERIC(10) DEFAULT NULL ;
UPDATE AD_System
SET LastMigrationScriptApplied='886_IDEMPIERE-217.sql'
WHERE LastMigrationScriptApplied<'886_IDEMPIERE-217.sql'
OR LastMigrationScriptApplied IS NULL
;

View File

@ -41,7 +41,12 @@ public class DocLine_Allocation extends DocLine
m_C_CashLine_ID = line.getC_CashLine_ID();
m_C_Invoice_ID = line.getC_Invoice_ID();
m_C_Order_ID = line.getC_Order_ID();
//
// adaxa-pb
Object obj = line.get_Value("C_Charge_ID");
if ( obj != null )
m_C_Charge_ID = (Integer) line.get_Value("C_Charge_ID");
else m_C_Charge_ID = 0;
// end adaxa-pb
setAmount(line.getAmount());
m_DiscountAmt = line.getDiscountAmt();
m_WriteOffAmt = line.getWriteOffAmt();
@ -52,6 +57,7 @@ public class DocLine_Allocation extends DocLine
private int m_C_Payment_ID;
private int m_C_CashLine_ID;
private int m_C_Order_ID;
private int m_C_Charge_ID; // adaxa-pb
private BigDecimal m_DiscountAmt;
private BigDecimal m_WriteOffAmt;
private BigDecimal m_OverUnderAmt;
@ -140,4 +146,11 @@ public class DocLine_Allocation extends DocLine
{
return m_C_Payment_ID;
}
/** adaxa-pb
* @return Returns the C_Charge_ID.
*/
public int getC_Charge_ID ()
{
return m_C_Charge_ID;
}
} // DocLine_Allocation

View File

@ -28,6 +28,7 @@ import org.compiere.model.MAcctSchemaElement;
import org.compiere.model.MAllocationHdr;
import org.compiere.model.MAllocationLine;
import org.compiere.model.MCashLine;
import org.compiere.model.MCharge; // adaxa-pb
import org.compiere.model.MConversionRate;
import org.compiere.model.MFactAcct;
import org.compiere.model.MInvoice;
@ -215,8 +216,15 @@ public class Doc_AllocationHdr extends Doc
// No Invoice
if (invoice == null)
{
// adaxa-pb: allocate to charges
// Charge Only
if (line.getC_Invoice_ID() == 0 && line.getC_Payment_ID() == 0 && line.getC_Charge_ID() != 0 )
{
fl = fact.createLine (line, line.getChargeAccount(as, line.getAmtSource()),
getC_Currency_ID(), line.getAmtSource());
}
// Payment Only
if (line.getC_Invoice_ID() == 0 && line.getC_Payment_ID() != 0)
else if (line.getC_Invoice_ID() == 0 && line.getC_Payment_ID() != 0)
{
fl = fact.createLine (line, getPaymentAcct(as, line.getC_Payment_ID()),
getC_Currency_ID(), line.getAmtSource(), null);

View File

@ -116,6 +116,8 @@ public class VAllocation extends Allocation
private JButton allocateButton = new JButton();
private JLabel currencyLabel = new JLabel();
private VLookup currencyPick = null;
private JLabel chargeLabel = new JLabel();
private VLookup chargePick = null;
private JCheckBox multiCurrency = new JCheckBox();
private JLabel allocCurrencyLabel = new JLabel();
private StatusBar statusBar = new StatusBar();
@ -155,6 +157,8 @@ public class VAllocation extends Allocation
paymentInfo.setHorizontalAlignment(SwingConstants.RIGHT);
paymentInfo.setHorizontalTextPosition(SwingConstants.RIGHT);
paymentInfo.setText(".");
chargeLabel.setText(Msg.translate(Env.getCtx(), "C_Charge_ID"));
chargeLabel.setToolTipText(Msg.getMsg(Env.getCtx(), "ChargeDifference", false));
differenceLabel.setText(Msg.getMsg(Env.getCtx(), "Difference"));
differenceField.setBackground(AdempierePLAF.getFieldBackground_Inactive());
differenceField.setEditable(false);
@ -199,6 +203,10 @@ public class VAllocation extends Allocation
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
allocationPanel.add(differenceField, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
allocationPanel.add(chargeLabel, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
allocationPanel.add(chargePick, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
allocationPanel.add(allocateButton, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
allocationPanel.add(allocCurrencyLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
@ -267,6 +275,13 @@ public class VAllocation extends Allocation
// Date set to Login Date
dateField.setValue(Env.getContextAsDate(Env.getCtx(), "#Date"));
dateField.addVetoableChangeListener(this);
// Charge
AD_Column_ID = 61804; // C_AllocationLine.C_Charge_ID
MLookup lookupCharge = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir);
chargePick = new VLookup("C_Charge_ID", false, false, true, lookupCharge);
chargePick.setValue(new Integer(m_C_Charge_ID));
chargePick.addVetoableChangeListener(this);
} // dynInit
/**************************************************************************
@ -307,10 +322,19 @@ public class VAllocation extends Allocation
int row = e.getFirstRow();
int col = e.getColumn();
if (row < 0)
return;
boolean isInvoice = (e.getSource().equals(invoiceTable.getModel()));
boolean isAutoWriteOff = autoWriteOff.isSelected();
String msg = writeOff(row, col, isInvoice, paymentTable, invoiceTable, isAutoWriteOff);
//render row
DefaultTableModel model = (DefaultTableModel) (isInvoice ? invoiceTable.getModel() : paymentTable.getModel());
//model.fireTableRowsUpdated(row, row);
if(msg != null && msg.length() > 0)
ADialog.warn(m_WindowNo, panel, "AllocationWriteOffWarn");
@ -343,7 +367,17 @@ public class VAllocation extends Allocation
loadBPartner();
}
// Charge
else if (name.equals("C_Charge_ID") )
{
if ( value == null )
m_C_Charge_ID = 0;
else
m_C_Charge_ID = ((Integer) value).intValue();
setAllocateButton();
}
// BPartner
if (name.equals("C_BPartner_ID"))
{
@ -361,6 +395,25 @@ public class VAllocation extends Allocation
else if (name.equals("Date") && multiCurrency.isSelected())
loadBPartner();
} // vetoableChange
private void setAllocateButton() {
if (totalDiff.compareTo(new BigDecimal(0.0)) == 0 ^ m_C_Charge_ID > 0 )
{
allocateButton.setEnabled(true);
// chargePick.setValue(m_C_Charge_ID);
}
else
{
allocateButton.setEnabled(false);
}
if ( totalDiff.compareTo(new BigDecimal(0.0)) == 0 )
{
chargePick.setValue(null);
m_C_Charge_ID = 0;
}
}
public void loadBPartner()
{
@ -412,12 +465,10 @@ public class VAllocation extends Allocation
allocCurrencyLabel.setText(currencyPick.getDisplay());
// Difference
totalDiff = totalPay.subtract(totalInv);
differenceField.setText(format.format(totalDiff));
differenceField.setText(format.format(totalDiff));
setAllocateButton();
if (totalDiff.compareTo(new BigDecimal(0.0)) == 0)
allocateButton.setEnabled(true);
else
allocateButton.setEnabled(false);
}
/**************************************************************************

View File

@ -72,12 +72,7 @@ import org.zkoss.zul.Space;
public class WAllocation extends Allocation
implements IFormController, EventListener, WTableModelListener, ValueChangeListener
{
/**
*
*/
private static final long serialVersionUID = 7806119329546820204L;
private CustomForm form = new CustomForm();
/**
@ -128,6 +123,8 @@ public class WAllocation extends Allocation
private Label currencyLabel = new Label();
private WTableDirEditor currencyPick = null;
private Checkbox multiCurrency = new Checkbox();
private Label chargeLabel = new Label();
private WTableDirEditor chargePick = null;
private Label allocCurrencyLabel = new Label();
private StatusBarPanel statusBar = new StatusBarPanel();
private Label dateLabel = new Label();
@ -162,6 +159,7 @@ public class WAllocation extends Allocation
invoicePanel.appendChild(invoiceLayout);
invoiceInfo.setText(".");
paymentInfo.setText(".");
chargeLabel.setText(" " + Msg.translate(Env.getCtx(), "C_Charge_ID"));
differenceLabel.setText(Msg.getMsg(Env.getCtx(), "Difference"));
differenceField.setText("0");
allocateButton.setLabel(Msg.getMsg(Env.getCtx(), "Process"));
@ -213,13 +211,16 @@ public class WAllocation extends Allocation
south.appendChild(southPanel);
southPanel.appendChild(allocationPanel);
allocationPanel.appendChild(allocationLayout);
allocationLayout.setWidth("400px");
allocationLayout.setWidth("600px");
rows = allocationLayout.newRows();
row = rows.newRow();
row.appendChild(differenceLabel.rightAlign());
row.appendChild(allocCurrencyLabel.rightAlign());
row.appendChild(differenceField);
row.appendChild(new Space());
row.appendChild(chargeLabel.rightAlign());
row.appendChild(chargePick.getComponent());
row.appendChild(new Space());
row.appendChild(allocateButton);
paymentPanel.appendChild(paymentLayout);
@ -321,6 +322,14 @@ public class WAllocation extends Allocation
// Date set to Login Date
dateField.setValue(Env.getContextAsDate(Env.getCtx(), "#Date"));
dateField.addValueChangeListener(this);
// Charge
AD_Column_ID = 61804; // C_AllocationLine.C_Charge_ID
MLookup lookupCharge = MLookupFactory.get (Env.getCtx(), form.getWindowNo(), 0, AD_Column_ID, DisplayType.TableDir);
chargePick = new WTableDirEditor("C_Charge_ID", true, false, true, lookupCharge);
chargePick.setValue(new Integer(m_C_Charge_ID));
chargePick.addValueChangeListener(this);
} // dynInit
/**************************************************************************
@ -361,10 +370,19 @@ public class WAllocation extends Allocation
int row = e.getFirstRow();
int col = e.getColumn();
if (row < 0)
return;
boolean isInvoice = (e.getModel().equals(invoiceTable.getModel()));
boolean isAutoWriteOff = autoWriteOff.isSelected();
String msg = writeOff(row, col, isInvoice, paymentTable, invoiceTable, isAutoWriteOff);
//render row
ListModelTable model = isInvoice ? invoiceTable.getModel() : paymentTable.getModel();
model.updateComponent(row);
if(msg != null && msg.length() > 0)
FDialog.warn(form.getWindowNo(), "AllocationWriteOffWarn");
@ -396,6 +414,16 @@ public class WAllocation extends Allocation
loadBPartner();
}
// Charge
else if (name.equals("C_Charge_ID") )
{
if ( value == null )
m_C_Charge_ID = 0;
else
m_C_Charge_ID = ((Integer) value).intValue();
setAllocateButton();
}
// BPartner
if (name.equals("C_BPartner_ID"))
@ -415,6 +443,23 @@ public class WAllocation extends Allocation
loadBPartner();
} // vetoableChange
private void setAllocateButton() {
if (totalDiff.compareTo(new BigDecimal(0.0)) == 0 ^ m_C_Charge_ID > 0 )
{
allocateButton.setEnabled(true);
// chargePick.setValue(m_C_Charge_ID);
}
else
{
allocateButton.setEnabled(false);
}
if ( totalDiff.compareTo(new BigDecimal(0.0)) == 0 )
{
chargePick.setValue(null);
m_C_Charge_ID = 0;
}
}
/**
* Load Business Partner Info
* - Payments
@ -474,12 +519,9 @@ public class WAllocation extends Allocation
allocCurrencyLabel.setText(currencyPick.getDisplay());
// Difference
totalDiff = totalPay.subtract(totalInv);
differenceField.setText(format.format(totalDiff));
if (totalDiff.compareTo(new BigDecimal(0.0)) == 0)
allocateButton.setEnabled(true);
else
allocateButton.setEnabled(false);
differenceField.setText(format.format(totalDiff));
setAllocateButton();
}
/**************************************************************************

View File

@ -49,6 +49,7 @@ public class Allocation
private boolean m_calculating = false;
public int m_C_Currency_ID = 0;
public int m_C_Charge_ID = 0;
public int m_C_BPartner_ID = 0;
private int m_noInvoices = 0;
private int m_noPayments = 0;
@ -523,8 +524,6 @@ public class Allocation
invoice.setValueAt(applied, row, i_applied);
invoice.setValueAt(writeOff, row, i_writeOff);
invoice.setValueAt(overUnder, row, i_overUnder);
invoice.repaint(); // update r/o
}
m_calculating = false;
@ -732,6 +731,22 @@ public class Allocation
unmatchedApplied = unmatchedApplied.subtract(payAmt);
}
// check for charge amount
if ( m_C_Charge_ID > 0 && unmatchedApplied.compareTo(Env.ZERO) != 0 )
{
BigDecimal chargeAmt = totalDiff;
// Allocation Line
MAllocationLine aLine = new MAllocationLine (alloc, chargeAmt.negate(),
Env.ZERO, Env.ZERO, Env.ZERO);
aLine.set_CustomColumn("C_Charge_ID", m_C_Charge_ID);
//aLine.set_CustomColumn("ChargeAmt", chargeAmt);
aLine.setC_BPartner_ID(m_C_BPartner_ID);
if (!aLine.save(trxName))
log.log(Level.SEVERE, "Allocation Line not saved - Charge=" + m_C_Charge_ID);
unmatchedApplied = unmatchedApplied.add(chargeAmt);
}
if ( unmatchedApplied.signum() != 0 )
log.log(Level.SEVERE, "Allocation not balanced -- out by " + unmatchedApplied );