You need to sign in to do that
Don't have an account?

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
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
**
* 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);
}
}
}