Hello, I'm configuring a payment module to install in perfex, and I need to capture some data from custom fields in the staff's registration to load when the staff is placed as a sales agent.
The code is as follows:
`$repass_1['payee_code'] = $this->get_invoice_customfields($data['invoice']->sale_agent, 'staff', 'staff_payee_code_repass');
(int)$repass_1['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->sale_agent, 'staff', 'staff_percentage_repass');
// Dinamico 2
$repass_12['payee_code'] = $this->get_invoice_customfields($data['invoice']->sale_agent, 'staff', 'staff_payee_code_repass_2');
(int)$repass_12['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->sale_agent, 'staff', 'staff_percentage_repass_2');
// Dinamico 3
$repass_13['payee_code'] = $this->get_invoice_customfields($data['invoice']->sale_agent, 'staff', 'staff_payee_code_repass_3');
(int)$repass_13['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->sale_agent, 'staff', 'staff_percentage_repass_3');
//
$repass_2['payee_code'] = $this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_payee_code_repass_2');
(int)$repass_2['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_percentage_repass_2');
//
$repass_3['payee_code'] = $this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_payee_code_repass_3');
(int)$repass_3['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_percentage_repass_3');
//
$repass_4['payee_code'] = $this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_payee_code_repass_4');
(int)$repass_4['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_percentage_repass_4');
//
$repass_5['payee_code'] = $this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_payee_code_repass_5');
(int)$repass_5['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_percentage_repass_5');
//
$repass_6['payee_code'] = $this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_payee_code_repass_6');
(int)$repass_6['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_percentage_repass_6');
//
$repass_7['payee_code'] = $this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_payee_code_repass_7');
(int)$repass_7['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_percentage_repass_7');
//
$repass_10['payee_code'] = $this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_payee_code_repass_10');
(int)$repass_10['percentage'] = (int)$this->get_invoice_customfields($data['invoice']->clientid, 'customers', 'customers_percentage_repass_10');
$repasses_array = [
$repass_1,
$repass_12,
$repass_13,
$repass_2,
$repass_3,
$repass_4,
$repass_5,
$repass_6,
$repass_7,
$repass_10
];
$repasses = [];
for ($x = 0; $x <= 9; $x++) {
if (!empty($repasses_array[$x]['payee_code'])) {
$repasses[$x]['payee_code'] = $repasses_array[$x]['payee_code'];
$repasses[$x]['percentage'] = $repasses_array[$x]['percentage'];
}
}`
public function get_invoice_customfields($id, $fieldto, $slug)
{
$ci = &get_instance();
// Consulta para obter o campo personalizado baseado no slug e no fieldto
$customfield = $ci->db->query("
SELECT id
FROM `tblcustomfields`
WHERE `fieldto` = ? AND `slug` = ?", [$fieldto, $slug])->row();
if ($customfield) {
// Consulta para obter o valor do campo personalizado para o registro especĂfico
$customfieldvalue = $ci->db->query("
SELECT value
FROM `tblcustomfieldsvalues`
WHERE `fieldto` = ? AND `relid` = ? AND `fieldid` = ?", [$fieldto, $id, $customfield->id])->row();
if ($customfieldvalue) {
return $customfieldvalue->value;
}
}
return NULL;
}