From ff6c53703cd8abc6c3158ae5806cc01da62cf874 Mon Sep 17 00:00:00 2001 From: s421507 Date: Wed, 15 Jul 2020 05:34:02 +0200 Subject: [PATCH] Wniosek o nadanie odznaczenia - lista odznaczen --- .idea/workspace.xml | 13 +- app/Common/PDF.php | 132 ++++++++++++++++++ .../documentApplicationController.php | 8 +- .../Controllers/documentOverlayController.php | 9 +- 4 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 app/Common/PDF.php diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3acd8b8..aa7f111 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,10 @@ + - - - - - - @@ -279,6 +274,10 @@ + + + + diff --git a/app/Common/PDF.php b/app/Common/PDF.php new file mode 100644 index 0000000..9fc79c4 --- /dev/null +++ b/app/Common/PDF.php @@ -0,0 +1,132 @@ +CurrentFont['cw']; + if($w==0) + $w=$this->w-$this->rMargin-$this->x; + $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; + $s=str_replace("\r",'',$txt); + $nb=strlen($s); + if($nb>0 && $s[$nb-1]=="\n") + $nb--; + $b=0; + if($border) + { + if($border==1) + { + $border='LTRB'; + $b='LRT'; + $b2='LR'; + } + else + { + $b2=''; + if(is_int(strpos($border,'L'))) + $b2.='L'; + if(is_int(strpos($border,'R'))) + $b2.='R'; + $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; + } + } + $sep=-1; + $i=0; + $j=0; + $l=0; + $ns=0; + $nl=1; + while($i<$nb) + { + //Get next character + $c=$s[$i]; + if($c=="\n") + { + //Explicit line break + if($this->ws>0) + { + $this->ws=0; + $this->_out('0 Tw'); + } + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $i++; + $sep=-1; + $j=$i; + $l=0; + $ns=0; + $nl++; + if($border && $nl==2) + $b=$b2; + if($maxline && $nl>$maxline) + return substr($s,$i); + continue; + } + if($c==' ') + { + $sep=$i; + $ls=$l; + $ns++; + } + $l+=$cw[$c]; + if($l>$wmax) + { + //Automatic line break + if($sep==-1) + { + if($i==$j) + $i++; + if($this->ws>0) + { + $this->ws=0; + $this->_out('0 Tw'); + } + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + } + else + { + if($align=='J') + { + $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; + $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); + } + $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); + $i=$sep+1; + } + $sep=-1; + $j=$i; + $l=0; + $ns=0; + $nl++; + if($border && $nl==2) + $b=$b2; + if($maxline && $nl>$maxline) + { + if($this->ws>0) + { + $this->ws=0; + $this->_out('0 Tw'); + } + return substr($s,$i); + } + } + else + $i++; + } + //Last chunk + if($this->ws>0) + { + $this->ws=0; + $this->_out('0 Tw'); + } + if($border && is_int(strpos($border,'B'))) + $b.='B'; + $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); + $this->x=$this->lMargin; + return ''; + } +} diff --git a/app/Http/Controllers/documentApplicationController.php b/app/Http/Controllers/documentApplicationController.php index 2cef25e..0e730cb 100644 --- a/app/Http/Controllers/documentApplicationController.php +++ b/app/Http/Controllers/documentApplicationController.php @@ -44,9 +44,15 @@ class documentApplicationController extends Controller ->select('users.id','users.name', 'users.surname', 'users.PESEL', 'users.fireStationID','users.phoneNumber', 'users.email', 'ranks.rank', 'unitFunctions.unitFunction', 'users.number') ->first(); + $awardedDecorations = DB::table('decorationsFirefighters')->where("decorationsFirefighters.firefighterID", '=', $request->fireFighterID) + ->whereNull('decorationsFirefighters.deleted_at') + ->leftJoin('decorations', 'decorationsFirefighters.decorationID', '=', 'decorations.id') + ->select('decorationName', 'dateOfAward', 'firefighterID', 'decorations.id AS decorationsId', 'decorationsFirefighters.id AS decorationsFirefightersID') + ->get(); + $fireStation = DB::table('fireStations')->where("id", '=', $userData->fireStationID)->first(); - $test->wniosekNadaniePDF($userData, $request->decoration, $fireStation); + $test->wniosekNadaniePDF($userData, $request->decoration, $fireStation, $awardedDecorations); } } diff --git a/app/Http/Controllers/documentOverlayController.php b/app/Http/Controllers/documentOverlayController.php index cd4e5b1..1df2363 100644 --- a/app/Http/Controllers/documentOverlayController.php +++ b/app/Http/Controllers/documentOverlayController.php @@ -10,7 +10,7 @@ use App\Common\Helpers; class documentOverlayController extends Controller { - public function wniosekNadaniePDF($userData, $decoration, $fireStation){ + public function wniosekNadaniePDF($userData, $decoration, $fireStation, $awardedDecorations){ // initiate FPDI $pdf = new Fpdi(); // set the source file @@ -71,6 +71,13 @@ class documentOverlayController extends Controller #Funkcja $pdf->SetXY(35, 113); $pdf->Cell(20,10, $fireStation->postOffice, 0, 0, 'C'); + + $txt = ""; + foreach($awardedDecorations as $awardedDecoration){ + $txt = $txt." ".$awardedDecoration->decorationName."\n"; + } + $pdf->SetXY(18, 132); + $pdf->MultiCell(86,4, $txt, 1, 'l', 0); } }