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
Mayuri NehulMayuri Nehul 

how to add formula logic in lwc

Hi All,
I have used a formula for calculating no. of working days excluding weekends that is working fine but actually, I want to add half-day logic in it like when both dates are the same then show options for half-day and full-day. I am not able to add half-day logic in the formula so I have used one checkbox field, created one process when both dates are the same then the checkbox value should be true, and added that logic in Apex trigger where I have handles my overall logic. Actually, I want to handle this all logic in LWC because I need to check for a full day as well if both dates are the same for that I have used the radio button. Can anyone please help me to resolve this 
my formula:
(IF(AND((5 - (CASE(MOD( fromDate__c- DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) < (CASE(MOD( toDate__c - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)) ),
((( toDate__c - fromDate__c) + 1) < 7)),
((CASE(MOD( toDate__c - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)) - (5 - (CASE(MOD( fromDate__c - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)))),
(((FLOOR((( toDate__c - fromDate__c ) - (CASE(MOD( fromDate__c - DATE(1900, 1, 6), 7), 0, 0, 1, 6, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0))) / 7)) * 5) +
(CASE(MOD( fromDate__c - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) +
(CASE(MOD( toDate__c - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)))))

--lwc.js
import { LightningElement,api,track,wire } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import Id from '@salesforce/user/Id';

export default class CreateRbtn extends NavigationMixin(LightningElement) 
{
    userId = Id;
    @track Leave_Request__c;
    @track cardTitle;
    Date1;
    Date2;
    rbValue = '';  //radio button value
    
    _wiredResult;
    handleSuccess(event) {
        console.log('onsuccess event recordEditForm',event.detail.id)
    }
    handleSubmit(event){
        var isVal = true;
        this.template.querySelectorAll('lightning-input-field').forEach(element => {
            isVal = isVal && element.reportValidity();
        });
        if (isVal) {
            this.template.querySelectorAll('lightning-record-edit-form').forEach(element => {element.submit();  });
            this.dispatchEvent(
            new ShowToastEvent({
                title: 'Success',
                message: 'Leave record successfully created',
                variant: 'success',
                }),
            );
            // Navigate to the Leave request list view
    
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Leave_Request__c',
                actionName: 'list'
            },
            state: {
                
                filterName: 'Recent' 
            }
        });
        
    }
    
    
        
        else {
            this.dispatchEvent(
            new ShowToastEvent({
                title: 'Error creating record',
                message: 'Please enter all the required fields',
                variant: 'error',
                }),
            );
        }
    }
    
    showRadioBtn = false;
    
    get options() {
        return [
            { label: 'Half day', value: '0.5' },
            { label: 'Full day', value: '1' },
        ];
    }
    
    handleChange(event){
        if(event.target.dataset.id === 'Date1'){
        this.Date1 = event.target.value;
        }else if(event.target.dataset.id === 'Date2'){
        this.Date2 = event.target.value;
        }
        
        if(this.Date1 == this.Date2){
            this.showRadioBtn = true;
          }else{
            this.showRadioBtn = false;
          }
      
    //added custom validation on 27/06/21     
       if(this.Date1>this.Date2)    
       {
           alert('To date should not be less than from date');
        }  
    
    }
    handleRbtn(event){
        this.rbValue = event.target.value;
        // alert(this.rbValue);
        
    }
}

Thanks in advance

Mayuri