20-02-2026
This commit is contained in:
parent
a8b395e20d
commit
a00c42e770
252 changed files with 28785 additions and 8907 deletions
|
|
@ -7,37 +7,77 @@ use App\Models\File;
|
|||
use App\User;
|
||||
use Storage;
|
||||
|
||||
class ContractPDFRepository extends BaseRepository {
|
||||
|
||||
|
||||
|
||||
|
||||
class ContractPDFRepository extends BaseRepository
|
||||
{
|
||||
protected $disk;
|
||||
|
||||
protected $dir;
|
||||
|
||||
protected $user_id;
|
||||
|
||||
protected $identifier;
|
||||
|
||||
public function __construct(User $model){
|
||||
protected $locale;
|
||||
|
||||
protected $contract_date;
|
||||
|
||||
public function __construct(User $model)
|
||||
{
|
||||
|
||||
$this->model = $model;
|
||||
// Benutzersprache aus Account ermitteln (mit Fallback auf de)
|
||||
$this->locale = $model->account && $model->account->language
|
||||
? $model->account->language
|
||||
: 'de';
|
||||
}
|
||||
|
||||
public function _set($name, $value){
|
||||
public function _set($name, $value)
|
||||
{
|
||||
$this->{$name} = $value;
|
||||
}
|
||||
|
||||
private function convert($str){
|
||||
$search = array('Ő', 'ő', 'Ű', 'ű');
|
||||
$replace = array('Ö', 'ö', 'Ü', 'ü');
|
||||
private function convert($str)
|
||||
{
|
||||
$search = ['Ő', 'ő', 'Ű', 'ű'];
|
||||
$replace = ['Ö', 'ö', 'Ü', 'ü'];
|
||||
$str = str_replace($search, $replace, $str);
|
||||
return iconv('UTF-8', 'windows-1252//IGNORE', $str);
|
||||
|
||||
return iconv('UTF-8', 'windows-1252//IGNORE', $str);
|
||||
}
|
||||
|
||||
public function createContractPDF() {
|
||||
public function createContractPDF()
|
||||
{
|
||||
|
||||
$pdf = new ContractPDF();
|
||||
if (! Storage::disk($this->disk)->exists($this->dir)) {
|
||||
Storage::disk($this->disk)->makeDirectory($this->dir); // creates directory
|
||||
}
|
||||
|
||||
$pdf->AddPage('P', array(210, 297));
|
||||
// Lösche alle alten Vertrags-Einträge für diesen User
|
||||
File::where('user_id', $this->model->id)
|
||||
->where('identifier', $this->identifier)
|
||||
->delete();
|
||||
|
||||
// 1. IMMER deutsches Original erstellen
|
||||
$this->createContractPDFForLocale('de');
|
||||
|
||||
// 2. Wenn Benutzersprache != DE, lokalisierte Version erstellen
|
||||
if ($this->locale && $this->locale !== 'de') {
|
||||
$this->createContractPDFForLocale($this->locale);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen Beratervertrag in der angegebenen Sprache
|
||||
*/
|
||||
private function createContractPDFForLocale(string $locale)
|
||||
{
|
||||
|
||||
$pdf = new ContractPDF;
|
||||
$pdf->setLocale($locale);
|
||||
|
||||
$pdf->AddPage('P', [210, 297]);
|
||||
$pdf->SetFont('Helvetica', '', 11);
|
||||
$pdf->SetDrawColor(160, 160, 160);
|
||||
|
||||
|
|
@ -48,22 +88,21 @@ class ContractPDFRepository extends BaseRepository {
|
|||
$pdf->SetXY($x1, $y);
|
||||
$pdf->Write(0, $this->convert($this->model->account->m_account));
|
||||
$pdf->SetXY($x2, $y);
|
||||
$pdf->Write(0, now()->format("d.m.Y"));
|
||||
$contractDate = $this->contract_date ?? now();
|
||||
$pdf->Write(0, $contractDate->format('d.m.Y'));
|
||||
|
||||
$y += $nl;
|
||||
$pdf->SetXY($x1, $y);
|
||||
$pdf->Write(0, $this->convert($this->model->account->company));
|
||||
$pdf->SetXY($x2, $y);
|
||||
$pre = $this->model->account->pre_phone_id != "" ? $this->convert($this->model->account->pre_phone->phone)." " : "";
|
||||
$pre = $this->model->account->pre_phone_id != '' ? $this->convert($this->model->account->pre_phone->phone).' ' : '';
|
||||
$pdf->Write(0, $pre.$this->convert($this->model->account->phone));
|
||||
|
||||
|
||||
|
||||
$y += $nl;
|
||||
$pdf->SetXY($x1, $y);
|
||||
$pdf->Write(0, $this->convert($this->model->account->m_first_name));
|
||||
$pdf->SetXY($x2, $y);
|
||||
$pre = $this->model->account->pre_mobil_id != "" ? $this->convert($this->model->account->pre_mobil->phone)." " : "";
|
||||
$pre = $this->model->account->pre_mobil_id != '' ? $this->convert($this->model->account->pre_mobil->phone).' ' : '';
|
||||
$pdf->Write(0, $pre.$this->convert($this->model->account->mobil));
|
||||
|
||||
$y += $nl;
|
||||
|
|
@ -80,14 +119,14 @@ class ContractPDFRepository extends BaseRepository {
|
|||
|
||||
$y += $nl;
|
||||
$pdf->SetXY($x1, $y);
|
||||
$pdf->Write(0, $this->convert($this->model->account->zipcode)." ".$this->convert($this->model->account->city));
|
||||
$pdf->Write(0, $this->convert($this->model->account->zipcode).' '.$this->convert($this->model->account->city));
|
||||
|
||||
$y += $nl;
|
||||
$pdf->SetXY($x1, $y);
|
||||
$pre = $this->model->account->country_id ? $this->convert($this->model->account->country->de)." " : "";
|
||||
$pre = $this->model->account->country_id ? $this->convert($this->model->account->country->de).' ' : '';
|
||||
$pdf->Write(0, $pre);
|
||||
|
||||
if($this->model->m_sponsor && $this->model->user_sponsor->account){
|
||||
if ($this->model->m_sponsor && $this->model->user_sponsor->account) {
|
||||
$y += 48;
|
||||
$pdf->SetXY($x1, $y);
|
||||
$pdf->Write(0, $this->convert($this->model->user_sponsor->account->company));
|
||||
|
|
@ -96,49 +135,44 @@ class ContractPDFRepository extends BaseRepository {
|
|||
|
||||
$y += $nl;
|
||||
$pdf->SetXY($x1, $y);
|
||||
$pdf->Write(0, $this->convert($this->model->user_sponsor->account->m_first_name)." ".$this->convert($this->model->user_sponsor->account->m_last_name));
|
||||
$pdf->Write(0, $this->convert($this->model->user_sponsor->account->m_first_name).' '.$this->convert($this->model->user_sponsor->account->m_last_name));
|
||||
|
||||
$website = $this->model->user_sponsor->shop()->count() ? $this->model->user_sponsor->shop->getSubdomain(false) : "www.mivita.care";
|
||||
|
||||
}else{
|
||||
$website = "www.mivita.care";
|
||||
$website = $this->model->user_sponsor->shop()->count() ? $this->model->user_sponsor->shop->getSubdomain(false) : 'www.mivita.care';
|
||||
} else {
|
||||
$website = 'www.mivita.care';
|
||||
}
|
||||
|
||||
$pdf->AddPage('P', array(210, 297));
|
||||
$pdf->AddPage('P', [210, 297]);
|
||||
$pdf->SetFont('Helvetica', '', 10);
|
||||
$pdf->SetDrawColor(160, 160, 160);
|
||||
$pdf->SetXY(52, 56);
|
||||
$pdf->Write(0, $website);
|
||||
|
||||
|
||||
$pdf->SetXY($x1, 65);
|
||||
$pdf->Write(0, $this->convert($this->model->account->m_first_name)." ".$this->convert($this->model->account->m_last_name));
|
||||
$pdf->SetXY($x2, 65);
|
||||
$pdf->Write(0, $this->convert($this->model->account->m_account));
|
||||
$pdf->Write(0, $website.' (ID: '.$this->convert($this->model->account->m_account).')');
|
||||
|
||||
$pdf->AddPage('P', array(210, 297));
|
||||
$pdf->SetXY($x1, 80);
|
||||
$pdf->Write(0, $this->convert($this->model->account->m_first_name));
|
||||
$pdf->SetXY($x2, 80);
|
||||
$pdf->Write(0, $this->convert($this->model->account->m_last_name));
|
||||
|
||||
$pdf->AddPage('P', [210, 297]);
|
||||
|
||||
// Dateiname mit übersetztem Vertragsnamen
|
||||
$contractName = __('pdf.contract_filename', [], $locale);
|
||||
$filename = "MIVITA_{$contractName}.pdf";
|
||||
|
||||
if(!Storage::disk($this->disk)->exists( $this->dir )){
|
||||
Storage::disk($this->disk)->makeDirectory($this->dir); //creates directory
|
||||
}
|
||||
$filename = "MIVITA_Beratervertrag.pdf";
|
||||
Storage::disk($this->disk)->put($this->dir.$filename, $pdf->Output('S'));
|
||||
$size = Storage::disk($this->disk)->size($this->dir.$filename);
|
||||
$size = Storage::disk($this->disk)->size($this->dir.$filename);
|
||||
$mine = Storage::disk($this->disk)->mimeType($this->dir.$filename);
|
||||
|
||||
// Erstelle Datenbank-Eintrag für diesen Vertrag
|
||||
File::create([
|
||||
'user_id' => $this->model->id,
|
||||
'identifier' => $this->identifier,
|
||||
'filename' => $filename,
|
||||
'dir' => $this->dir,
|
||||
'original_name' => $filename,
|
||||
'ext' => "pdf",
|
||||
'ext' => 'pdf',
|
||||
'mine' => $mine,
|
||||
'size' => $size
|
||||
'size' => $size,
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue