How to add a redundancy check in Quote module for "Convert to Invoice" option

Hello All,

I need to know how we can show a popup saying “Invoice is already existed” in the quote module if an invoice is already generated before for the same quote.

I need to add an upgrade safe popup for the same.

Please help

Hi @jyotip,

I don’t want sound pessimistic but I think that popup will require a lot of work to be completed. Basically you will need to modify the entire process to do the validations you want to include. I might require javascript … and don’t know what else. Not saying is impossible BTW.

What I propose is to create a before_save logic hook and do all the validation there. If a invoice exists then you redirect the page before it saves. That way you will always make sure no second invoice is created for your quotes.

Thanks,

BrozTechnologies

HI @BrozTechnologies,

Thanks for your reply.

I tried before_save logic hook but it is not showing popup when I click on the Save button.

Can you help me with the code please

<?php

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class check_invoice_before_save_class
{
    function check_invoice_before_save_method($bean, $event, $arguments)
    {

        global $timedate,$db;
  

       $sql = "SELECT * FROM aos_invoices WHERE quote_number = '$bean->quote_number' AND deleted = 0";
       $result = $db->query($sql);
       $row = $db->fetchByAssoc($result);
     

       if($result->num_rows != 0) {
        
        SugarApplication::appendErrorMessage('record cannot be saved !!!'.$errorMsg);
        $params = array(
        'module'=> 'AOS_Quotes',
        'action'=>'DetailView', 
            'record' => $bean->id
        );
        SugarApplication::redirect('index.php?' . http_build_query($params).'&return_module=AOS_Quotes&return_action=DetailView&offset=1');
    }
    }
}

?>

This is not allowing even if I create a new fresh record. I want to stop creating a new invoice if it is already there.

Did you solve this process? I am looking for simimilar solution.