function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Olivia FordeOlivia Forde 

Help with code

Hi
I have the following piece of code in an Apex Class
 
    public class LineItem {
        public String productCode {get; set;}
        public String productName {get; set;}
        public Decimal quantity {get; set;}
        public Decimal unitPrice {get; set;}
        public Decimal ListEX {get; set;}
        public Decimal ListSubtotal {get; set;}
        public Decimal VAT {get; set;}
        public Decimal subTotal {get; set;}
        public Decimal totalWithVAT {get; set;}
        
        
        public LineItem(String productCode, String productName, Decimal quantity, Decimal unitPrice, Decimal VAT , Decimal ListEX, Decimal ListSubtotal) {
            this.productCode = productCode;
            this.productName = productName;
            this.quantity = quantity;
            this.unitPrice = unitPrice;
            this.ListEX = ListEX ;
            this.ListSubtotal = ListSubtotal ;
            if ( VAT == null ) {
                this.VAT = 0.0;
            } else {
                this.VAT = VAT;
            }
            this.subTotal = (this.quantity * this.unitPrice).setScale(2);
            this.totalWithVAT = (this.quantity * (this.unitPrice + this.VAT)).setScale(2);
        }

I want to change how subTotal is calculated , I want to use a new field instead of unitPrice - how do I do that 
JD68JD68
Hi Olivia, not sure I understand the question.  When you say you want to use a new field - are you talking about a custom field, or a paramter that's passed in to the function?  Perhaps if you can explain in more detail what you're trying to achieve.  Thanks, JD
Olivia FordeOlivia Forde
Hi It's a custom field I want to use Sent from my Samsung device
John Davies 14John Davies 14
OK so currently your code is not using any Salesforce data objects, it's passing in all the values it needs as parameters.  So I'm not sure how the custom field fits in.  More information is needed if you want this one solved!
Olivia FordeOlivia Forde
Here is the full class - all references to ListEXVAT, and ListSubtotal are mine and may not be correct.
**
 * Extension for the Receipt PDF
 *
 */
public class Receipt {
    public Receipt.LineItem lineItem {get; set;}
    public List <Receipt.LineItem> lineItems {get; set;}
    public Decimal total {get; set;}
    public Decimal vatTotal {get; set;}
    public Decimal totalWithVAT {get; set;}
    public String timestamp {get; set;}
    public Decimal ListExVAT{get; set;}
    
    // Translation Strings
    public String trnReceipt {get; set;}
    public String trnTo {get; set;}
    public String trnFrom {get; set;}
    public String trnAddress1 {get; set;}
    public String trnAddress2 {get; set;}
    public String trnAddress3 {get; set;}
    public String trnAddress4 {get; set;}
    public String trnAddress5 {get; set;}
    public String trnAddress6 {get; set;}
    public String trnSummary {get; set;}
    public String trnTotalAmount {get; set;}
    public String trnInvoiceID {get; set;}
    public String trnPhoneNumber {get; set;}
    public String trnDate {get; set;}
    public String trnShippingInformation {get; set;}
    public String trnShipTo {get; set;}
    public String trnBillTo {get; set;}
    public String trnDetails {get; set;}
    public String trnProductID {get; set;}
    public String trnProduct {get; set;}
    public String trnQuantity {get; set;}
    public String trnPrice {get; set;}
    public String trnNETPrice {get; set;}
    public String trnVAT {get; set;}
    public String trnSubTotal {get; set;}
    public String trnDiscount {get; set;}
    public String trnNET {get; set;}
    public String trnTotal {get; set;}
    public String trnThankYou {get; set;}
    public String trnRegs {get; set;}
    public String trnListexVAT {get; set;}
    
    
    public Receipt(ApexPages.StandardController OpportunityController) {
        this.lineItems = new List <Receipt.LineItem>();
        this.total = 0.0;
        this.vatTotal = 0.0;
        this.totalWithVAT = 0.0;
        this.ListExVAT = 0.0;
        for (OpportunityLineItem oppLineItem : [SELECT Id, PricebookEntry.Product2.ProductCode, 
        PricebookEntry.Product2.Name, Quantity, UnitPrice, VAT_Value__c,List_Price_Ex_VAT__c, Line_EX_VAT_Subtotal__c
        FROM OpportunityLineItem WHERE OpportunityId = :OpportunityController.getId()]) {
            this.lineItem = new Receipt.LineItem(
                oppLineItem.PricebookEntry.Product2.ProductCode,
                oppLineItem.PricebookEntry.Product2.Name,
                oppLineItem.quantity,
                oppLineItem.unitPrice,
                oppLineItem.VAT_Value__c,
                oppLineItem.List_Price_Ex_VAT__c,
                oppLineItem.Line_EX_VAT_Subtotal__c
            );  
            this.total += this.lineItem.subTotal;
            this.vatTotal += this.lineItem.VAT;
            this.totalWithVAT += this.lineItem.totalWithVAT;
            this.lineItems.add( this.lineItem );
        }
        Opportunity thisOp = [SELECT Id, Business_Unit__c FROM Opportunity WHERE Id = :OpportunityController.getId()];
        if ( thisOp.Business_Unit__c == 'ES' ) {
            this.setES();
        } else if ( thisOp.Business_Unit__c == 'PT' ) {
            this.setPT();
        } else {
            // Default to English Language
            this.setEnglish();
        }
        this.timestamp = Datetime.now().format('d/M/y');
    }
    
    
    
    public class LineItem {
        public String productCode {get; set;}
        public String productName {get; set;}
        public Decimal quantity {get; set;}
        public Decimal unitPrice {get; set;}
        public Decimal ListEX {get; set;}
        public Decimal ListSubtotal {get; set;}
        public Decimal VAT {get; set;}
        public Decimal subTotal {get; set;}
        public Decimal totalWithVAT {get; set;}
        
        
        public LineItem(String productCode, String productName, Decimal quantity, Decimal unitPrice, Decimal VAT , Decimal ListEX, Decimal ListSubtotal) {
            this.productCode = productCode;
            this.productName = productName;
            this.quantity = quantity;
            this.unitPrice = unitPrice;
            this.ListEX = ListEX ;
            this.ListSubtotal = ListSubtotal ;
            if ( VAT == null ) {
                this.VAT = 0.0;
            } else {
                this.VAT = VAT;
            }
            this.subTotal = (this.quantity * this.ListEX ).setScale(2);
            this.totalWithVAT = (this.quantity * (this.unitPrice + this.VAT)).setScale(2);
        }
    } 
}
Olivia FordeOlivia Forde
Any help guys ? I am trying to pass a new paramenter but cannot get it to work