[Vtigercrm-developers] V6 Creating an Invoice from a potentials Bug With Solution

Daniel Thompson developingdanny at gmail.com
Tue Sep 17 14:55:09 UTC 2013


Hi,

I've noticed something rather odd and a bit lazy.

When creating an Invoice from a potential it seems to default the related
to on both types i.e. Organization and Contact in the invoice edit view
even though it's a UI type 10 and only one can be selected.

This also saves the record and creates void data entry and can corrupt
further reporting.

it seems that in modules/Potentials/models/Record.php

function getCreateInvoiceUrl() {
$invoiceModuleModel = Vtiger_Module_Model::getInstance('Invoice');
return
'index.php?module='.$invoiceModuleModel->getName().'&view='.$invoiceModuleModel->getEditViewName().'&account_id='.$this->get('related_to').'&contact_id='.$this->get('related_to');
}

As you can see it defaults both of the above to whatever was saved
originally :S

However I've created a dummy function within the class to check this. The
below i think still can be improved and future proofed by checking the
vtiger_fieldmodulerel, vtiger_field and gather the appropriate data to
perform a sql look up. A rough example below of what i've created in a few
mins.

function getCreateInvoiceUrl() {
$invoiceModuleModel = Vtiger_Module_Model::getInstance('Invoice');
 return
'index.php?module='.$invoiceModuleModel->getName().'&view='.$invoiceModuleModel->getEditViewName().$this->checkRelatedTo();
}
 function checkRelatedTo()
{
global $adb;
 $sql = "SELECT
             (case when vtiger_account.accountid != '' then 'account_id'
 when vtiger_contactdetails.contactid != '' then 'contact_id'
when vtiger account.accountid = '' AND vtiger contactdetails.contactid = ''
then '' end)
as Type
FROM vtiger_potential
LEFT JOIN vtiger_account
ON vtiger_potential.related_to=vtiger_account.accountid
LEFT JOIN vtiger_contactdetails
ON vtiger_potential.related_to=vtiger_contactdetails.contactid
WHERE related_to=?";
$result = $adb->pquery($sql,array($this->get('related_to')));
$type = $adb->query_result($result,0,'type');
 if(!empty($type))
{
return '&'.$type.'='.$this->get('related_to');
}
 return;
}

Thoughts welcome...

Regards,

Danny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20130917/ec41ff1e/attachment.html>


More information about the vtigercrm-developers mailing list