<div dir="ltr">Hi,<div><br></div><div>I've noticed something rather odd and a bit lazy.</div><div><br></div><div>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.</div>
<div><br></div><div>This also saves the record and creates void data entry and can corrupt further reporting.</div><div><br></div><div>it seems that in modules/Potentials/models/Record.php </div><div><br></div><div><div>function getCreateInvoiceUrl() {</div>
<div><span class="" style="white-space:pre">            </span>$invoiceModuleModel = Vtiger_Module_Model::getInstance('Invoice');</div><div><span class="" style="white-space:pre">         </span>return 'index.php?module='.$invoiceModuleModel->getName().'&view='.$invoiceModuleModel->getEditViewName().'&account_id='.$this->get('related_to').'&contact_id='.$this->get('related_to');</div>
<div><span class="" style="white-space:pre">    </span>}</div></div><div><br></div><div>As you can see it defaults both of the above to whatever was saved originally :S</div><div><br></div><div>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.</div>
<div><br></div><div><div>function getCreateInvoiceUrl() {</div><div><span class="" style="white-space:pre">         </span>$invoiceModuleModel = Vtiger_Module_Model::getInstance('Invoice');</div><div><span class="" style="white-space:pre">         </span></div>
<div><span class="" style="white-space:pre">            </span>return 'index.php?module='.$invoiceModuleModel->getName().'&view='.$invoiceModuleModel->getEditViewName().$this->checkRelatedTo();</div><div>
<span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span></div><div><span class="" style="white-space:pre">   </span>function checkRelatedTo()</div><div><span class="" style="white-space:pre">  </span>{</div>
<div><span class="" style="white-space:pre">            </span>global $adb;</div><div><span class="" style="white-space:pre">               </span></div><div><span class="" style="white-space:pre">           </span>$sql = "SELECT</div><div> <span class="" style="white-space:pre">               </span>            (case when vtiger_account.accountid != '' then 'account_id'</div>
<div><span class="" style="white-space:pre">                                    </span> when vtiger_contactdetails.contactid != '' then 'contact_id'</div><div><span class="" style="white-space:pre">                                      </span>when vtiger account.accountid = '' AND vtiger contactdetails.contactid = '' then '' end)</div>
<div><span class="" style="white-space:pre">                                    </span>as Type</div><div><span class="" style="white-space:pre">                                    </span>FROM vtiger_potential</div><div><span class="" style="white-space:pre">                                      </span>LEFT JOIN vtiger_account</div>
<div><span class="" style="white-space:pre">                                                    </span>ON vtiger_potential.related_to=vtiger_account.accountid</div><div><span class="" style="white-space:pre">                                    </span>LEFT JOIN vtiger_contactdetails</div><div><span class="" style="white-space:pre">                                                    </span>ON vtiger_potential.related_to=vtiger_contactdetails.contactid</div>
<div><span class="" style="white-space:pre">                                    </span>WHERE related_to=?";</div><div><span class="" style="white-space:pre">          </span>$result = $adb->pquery($sql,array($this->get('related_to')));</div>
<div><span class="" style="white-space:pre">            </span>$type = $adb->query_result($result,0,'type');</div><div><span class="" style="white-space:pre">           </span></div><div><span class="" style="white-space:pre">           </span>if(!empty($type))</div>
<div><span class="" style="white-space:pre">            </span>{</div><div><span class="" style="white-space:pre">                  </span>return '&'.$type.'='.$this->get('related_to');</div><div><span class="" style="white-space:pre">              </span>}</div>
<div><span class="" style="white-space:pre">            </span></div><div><span class="" style="white-space:pre">           </span>return;</div><div><span class="" style="white-space:pre">    </span>}</div></div><div><br></div><div>Thoughts welcome...</div>
<div><br></div><div>Regards,</div><div><br></div><div>Danny</div></div>