Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions

:
#)McoPost. Copyright © 2012 tourapp.com. All rights reserved. GPL3 Open Source Software License.
  
  package com.tourapp.tour.acctrec.screen.mco;
  
  import java.util.*;
  
McoPost - Post the MCOs.
 
 public class McoPost extends BaseArTrxPostScreen
 {
     protected int m_iTrxStatusEntered = 0;
    
Default constructor.
 
     public McoPost()
     {
         super();
     }
    
Constructor.

Parameters:
record The main record for this screen.
itsLocation The location of this component within the parent.
parentScreen The parent screen.
fieldConverter The field this screen field is linked to.
iDisplayFieldDesc Do I display the field desc?
properties Addition properties to pass to the screen.
 
     public McoPost(Record recordScreenLocation itsLocationBasePanel parentScreenConverter fieldConverterint iDisplayFieldDescMap<String,Objectproperties)
     {
         this();
         this.init(recorditsLocationparentScreenfieldConverteriDisplayFieldDescproperties);
     }
    
Initialize class fields.
 
     public void init(Record recordScreenLocation itsLocationBasePanel parentScreenConverter fieldConverterint iDisplayFieldDescMap<String,Objectproperties)
     {
         super.init(recorditsLocationparentScreenfieldConverteriDisplayFieldDescproperties);
     }
    
Get the screen display title.
 
     public String getTitle()
     {
         return "Post the MCOs";
     }
    
Override this to open the main file.

You should pass this record owner to the new main file (ie., new MyNewTable(thisRecordOwner)).

Returns:
The new record.
 
     public Record openMainRecord()
     {
         return new Mco(this);
     }
    
Override this to open the other files in the query.
 
     public void openOtherRecords()
     {
         super.openOtherRecords();
         
         new McoBatchDist(this);
         
         new ArTrx(this);
         new ArControl(this);
         
         new TrxStatus(this);
         new TransactionType(this);
     }
    
Add the screen fields. Override this to create (and return) the screen record for this recordowner.

Returns:
The screen record.
    public Record addScreenRecord()
    {
        return new CashBatchScreenRecord(this);
    }
    
Add all the screen listeners.
    public void addListeners()
    {
        super.addListeners();
        
        
        McoBatchDist recMcoBatchDist = (McoBatchDist)this.getRecord(.);
        recMcoBatchDist.addListener(new SubFileFilter(this.getRecord(.)));
        recMcoBatchDist.addListener(new SubCountHandler(this.getScreenRecord().getField(.), .falsetrue));
        
        Mco recMco = (Mco)this.getRecord(.);
        
        Booking recBooking = (Booking)((ReferenceField)recMco.getField(.)).getReferenceRecord(this);
        recMco.getField(.).addListener(new ReadSecondaryHandler(recBookingnulltruetruetrue));     // Update record
        ArTrx recArTrx = (ArTrx)this.getRecord(.);
        recBooking.addArDetail(recArTrxnullfalse);
        
        recMco.close();
        try   {   // Recount totals
            while (recMco.hasNext())
            {
                recMco.next();
            }
        } catch (DBException ex)    {
            ex.printStackTrace();
        }
    }
    
Set up all the screen fields.
    public void setupSFields()
    {
        new SCannedBox(this.getNextLocation(..), thisnull.null"Post""Post""Post"null);
    }
    
Get the batch detail record.
    public Record getDetailRecord()
    {
        return this.getMainRecord();
    }
    
Return the distribution detail record.

Returns:
The dist record.
    public Record getDistRecord()
    {
        return this.getRecord(.);
    }
    
Get the base trx record.

Returns:
The record.
    public BaseTrx getBaseTrx()
    {
        return (BaseTrx)this.getRecord(.);
    }
    
Is the batch header record valid?

Returns:
true if valid (if false, set the last error).
    public boolean checkValidHeader()
    {
        // Don't call inherited as there is no batch header on MCOs
        BaseApplication application = (BaseApplication)this.getTask().getApplication();
        BaseField fldDefAccountID = this.getRecord(.).getField(.);
        if (fldDefAccountID.isNull())
        {
            this.displayError(application.getResources(.true).getString("No default account set in control file"));
            return false;
        }
        return true;    // Success
    }
    
Make sure this batch detail trx is valid.

Returns:
True if batch is okay.
    public boolean checkValidDetail()
    {
        return super.checkValidDetail();
    }
    
(Optionally) update this detail transaction.

Returns:
true if success.
    public boolean updateDetailTrx()
    {
        Record recDetail = this.getDetailRecord();
        try {
            recDetail.edit();
            recDetail.getField(.).setValue();
        } catch (DBException ex)    {
            ex.printStackTrace();
            return false;
        }
        return super.updateDetailTrx();
    }
    
Setup and post this base transaction.

Parameters:
recBaseTrx The base transaction to post.
recTransactionType The transaction type for the TRX posting.
Returns:
true If successful.
    public boolean postBaseTrx(BaseTrx recBaseTrxTransactionType recTransactionType)
    {
        // Step 2b - Post the transaction side of the distribution.
        Record recDetail = this.getDetailRecord();
        try {
            recDetail.writeAndRefresh();
        } catch (DBException ex)    {
            ex.printStackTrace();
            return false;
        }
        double dAmount = recDetail.getField(.).getValue();
        boolean bSuccess = recBaseTrx.onPostTrxDist(fldDrAccountIDdAmount.);
        return bSuccess;
    }
    
Post the distribution detail.

Parameters:
recBaseTrx The base transaction to post.
recTransactionType The transaction type for the DIST posting.
Returns:
true If successful.
    public boolean postDistTrx(BaseTrx recBaseTrxTransactionType recTransactionType)
    {
        
        Record recBatchDetail = this.getDetailRecord();
        double dLocalTotal = recBatchDetail.getField(.).getValue();
        String strComment = recBatchDetail.getField(.).toString();
        
        return this.postDistTrx(recBaseTrxdLocalTotalstrCommentfldDefAccountID);
    }
    
Remove this batch detail transaction and the distribution.

Returns:
true if successful.
    public boolean removeDetailTrx()
    {
        // Step 3 - Delete the batch (if not recurring)
        Record recBankTrxBatchDetail = this.getDetailRecord();
        Record recBankTrxBatchDist = this.getDistRecord();
        recBankTrxBatchDist.close();
        try   {
            while (recBankTrxBatchDist.hasNext())
            {
                recBankTrxBatchDist.next();
                recBankTrxBatchDist.edit();
                recBankTrxBatchDist.remove();
            }
            // Don't remove the detail trx as it is not in a batch.
        } catch (DBException ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }
    
Delete the batch header.
    public boolean removeTrxHeader()
    {
        String strSuccess = "Posted successfully";
        strSuccess = this.getTask().getApplication().getResources(.true).getString(strSuccess);
        this.getTask().setStatusText(this.getTask().getString(strSuccess));
        return true;    // Not required for Mcos
    }
New to GrepCode? Check out our FAQ X