Hide/Show Action(Print as PDF) based on the status

Hi, I would like to hide/show “Print as PDF” based on the status(two options, Paid and Cancelled) in Invoice, here is what I did.
I created a view.detail.php in custom/modules/AOS_Invoices/views

<?php
require_once('modules/AOS_Invoices/views/view.detail.php');
class CustomAOS_InvoicesViewDetail extends AOS_InvoicesViewDetail {

  public function display(){
     if($this->bean->status == 'Cancelled') {
            unset($this->dv->defs['templateMeta']['form']['buttons'][4]);
        }
    
        $this->dv->process();
    
        echo $this->dv->display();
  }
}

It doesn’t hide/show “Print as PDF” button, unless I run the Quick Repair and Rebuild every time after I changed the status of an invoice.

Can someone help me with this?

Thank you very much

You can add conditions directly for buttons in detailviewdefs. For reference check “customCode” of buttons at modules/Calls/metdata/detailviewdefs.php

1 Like

You Can Hide/Show “Print as PDF” Button using Logic Hook so you don’t need to do Repair/Rebuild every time when status Change. Follow the below steps,

Create Logic Hook for Invoice Detail View

File Path : custom/Extension/application/Ext/LogicHooks/InvoiceLogicHook.php

File Path : custom/include/InvoiceLogicHook/InvoiceLogicHook.php

File Path : custom/include/InvoiceLogicHook/js/InvoiceLogicHook.js

After creating above 3 files, you need to repair and rebuild your CRM only one time because we have Hide and Show print as pdf option from invoice module detail view by using a logic hook.

I hope it helps you. if you face any issue please let me know.
Thank
Urvi Solanki

1 Like

It works!!

Thank you very much

You Welcome :blush:
In future, if you need any help you can connect me any time
Thanks
Urvi