-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_code_generator.php
38 lines (31 loc) · 1.1 KB
/
client_code_generator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
class ClientCodeGenerator {
private $oApp;
private $oPeopleDB;
public function __construct( SEEDAppSessionAccount $oApp ){
$this->oApp = $oApp;
$this->oPeopleDB = new PeopleDB($this->oApp);
}
public function getClientCode(int $client_key){
$kfr = $this->oPeopleDB->GetKFR("C", $client_key);
if($code = $kfr->Value("code")){
return $code;
}
$code = strtoupper(substr($kfr->Value("P_last_name"),0,3))
.strtoupper(substr($kfr->Value("P_first_name") ,0,3));
$existingCodes = $this->oPeopleDB->GetList("C", "code LIKE '".$code."%'");
if(count($existingCodes) > 0){
$code .= (count($existingCodes)+1);
}
$kfr->SetValue("code", $code);
$kfr->PutDBRow();
return $code;
}
public function regenerateCode(int $client_key){
$kfr = $this->oPeopleDB->GetKFR("C", $client_key);
$kfr->SetValue("code", "");
$kfr->PutDBRow();
return $this->getClientCode($client_key);
}
}
?>