Example #1
2
 /**
  * @param Layout $default_layout
  */
 public function __construct(Layout $default_layout)
 {
     $this->pdf = new \TCPDF('P', 'pt', 'A4', true, 'UTF-8');
     $this->pdf->SetTitle($default_layout->getReportTitle());
     $this->pdf->SetCreator('Thinreports Generator');
     $this->pdf->SetAutoPageBreak(false);
     $this->pdf->SetMargins(0, 0, 0, true);
     $this->pdf->SetCellPadding(0);
     $this->pdf->SetCellMargins(0, 0, 0, 0);
     $this->pdf->SetPrintHeader(false);
     $this->pdf->SetPrintFooter(false);
     $this->default_layout = $default_layout;
     $this->default_page_format = $this->buildPageFormat($default_layout);
 }
Example #2
2
function student_kolizijapdf()
{
    global $userid;
    require_once 'lib/tcpdf/tcpdf.php';
    $semestar = intval($_REQUEST['semestar']);
    if ($semestar == 1) {
        $tekst_semestar = "zimskom";
    } else {
        $tekst_semestar = "ljetnjem";
    }
    // Prikupljam podatke iz baze
    // Za koju godinu se prijavljuje?
    $q1 = myquery("select id, naziv from akademska_godina where aktuelna=1");
    $q2 = myquery("select id, naziv from akademska_godina where id>" . mysql_result($q1, 0, 0) . " order by id limit 1");
    if (mysql_num_rows($q2) < 1) {
        //	nicemessage("U ovom trenutku nije aktiviran upis u sljedeću akademsku godinu.");
        //	return;
        // Pretpostavljamo da se upisuje u aktuelnu?
        $zagodinu = mysql_result($q1, 0, 0);
        $agnaziv = mysql_result($q1, 0, 1);
        $q3 = myquery("select id from akademska_godina where id<{$zagodinu} order by id desc limit 1");
        $proslagodina = mysql_result($q3, 0, 0);
    } else {
        $proslagodina = mysql_result($q1, 0, 0);
        $zagodinu = mysql_result($q2, 0, 0);
        $agnaziv = mysql_result($q2, 0, 1);
    }
    // Koji je odsjek?
    $q4 = myquery("select s.id, s.naziv, i.naziv, ss.semestar from studij as s, student_studij as ss, institucija as i where ss.student={$userid} and ss.studij=s.id and s.institucija=i.id and ss.akademska_godina={$proslagodina} order by semestar desc limit 1");
    if (mysql_num_rows($q4) < 1) {
        // Očito da su aktuelna i prošla godina loše određene
        $q4 = myquery("select s.id, s.naziv, i.naziv, ss.semestar, ss.akademska_godina from studij as s, student_studij as ss, institucija as i where ss.student={$userid} and ss.studij=s.id and s.institucija=i.id order by akademska_godina desc, semestar desc limit 1");
        if (mysql_num_rows($q4) < 1) {
            biguglyerror("Nikada niste bili nas student!");
            return;
        }
        $proslagodina = mysql_result($q4, 0, 4);
        if (mysql_num_rows($q2) < 1) {
            biguglyerror("Nije kreirana nova akademska godina u koju se upisujete.");
            print "Kontaktirajte administratora.";
            return;
        }
        $q2 = myquery("select id, naziv from akademska_godina where id>{$proslagodina} order by id limit 1");
        $zagodinu = mysql_result($q2, 0, 0);
        $agnaziv = mysql_result($q2, 0, 1);
    }
    $studij = mysql_result($q4, 0, 0);
    $studij_naziv = mysql_result($q4, 0, 1);
    $institucija_naziv = mysql_result($q4, 0, 2);
    $godina_studija = ceil(mysql_result($q4, 0, 3) / 2);
    // Da li je student popunio ugovor za drugi odsjek?
    $tekst_mijenja = "";
    $q7 = myquery("select s.id, s.naziv, i.naziv from studij as s, ugovoroucenju as uou, institucija as i where uou.student={$userid} and uou.studij=s.id and s.institucija=i.id and uou.akademska_godina={$zagodinu}");
    if (mysql_num_rows($q7) > 1 && $studij != mysql_result($q7, 0, 0)) {
        $institucija_naziv = mysql_result($q7, 0, 2);
        $tekst_mijenja = "predao sam zahtjev za promjenu studija na " . mysql_result($q7, 0, 1) . ". S tim u vezi, ";
    }
    // Zapis u tabeli kolizija
    $predmeti_kolizija = $predmeti_ects = array();
    $q10 = myquery("select p.id, p.naziv, p.ects from kolizija as k, predmet as p where k.student={$userid} and k.akademska_godina={$zagodinu} and k.semestar={$semestar} and k.predmet=p.id");
    if (mysql_num_rows($q10) < 1) {
        biguglyerror("Vi niste popunili Zahtjev za koliziju za {$agnaziv} godinu!");
        print "Ako je ovo greska, kontaktirajte administratora.";
        return;
    }
    while ($r10 = mysql_fetch_row($q10)) {
        $predmeti_kolizija[$r10[0]] = $r10[1];
        $predmeti_ects[$r10[0]] = $r10[2];
    }
    if ($semestar == 1) {
        $s2 = 1;
    } else {
        $s2 = 0;
    }
    // Predmeti koje nije polozio
    $predmeti_prenos = array();
    $q20 = myquery("select p.id, p.naziv, p.ects from student_predmet as sp, ponudakursa as pk, predmet as p where sp.student={$userid} and sp.predmet=pk.id and pk.predmet=p.id and pk.akademska_godina={$proslagodina} and pk.semestar MOD 2={$s2} and pk.semestar<{$godina_studija}*2+1 and (select count(*) from konacna_ocjena as ko where ko.student={$userid} and ko.predmet=p.id and ko.ocjena != 5)=0");
    while ($r20 = mysql_fetch_row($q20)) {
        if (array_key_exists($r20[0], $predmeti_kolizija)) {
            continue;
        }
        $predmeti_prenos[$r20[0]] = $r20[1];
        $predmeti_ects[$r20[0]] = $r20[2];
    }
    // Podaci o studentu
    $q30 = myquery("select ime, prezime, brindexa, spol from osoba where id={$userid}");
    $ime = mysql_result($q30, 0, 0);
    $prezime = mysql_result($q30, 0, 1);
    $brindexa = mysql_result($q30, 0, 2);
    $spol = mysql_result($q30, 0, 3);
    if ($spol == "") {
        $spol = spol(mysql_result($q30, 0, 0));
    }
    if ($spol == "M") {
        $student = "student";
        $polozio = "položio";
    } else {
        $student = "studentica";
        $polozio = "položila";
    }
    ?>
<html>
<head>
<title>Zahtjev za koliziju</title>
</head>
<body>
<p>Univerzitet u Sarajevu<br>
Elektrotehnički fakultet Sarajevo<br>
<?php 
    echo $institucija_naziv;
    ?>
</p>

<p>&nbsp;</p>

<p>Student: <?php 
    echo "{$ime} {$prezime} ({$brindexa})";
    ?>
</p>

<p>&nbsp;</p>

<p><b>Predmet: ZAHTJEV ZA KOLIZIJU</b></p>

<p>&nbsp;</p>

<p>Ja, <?php 
    echo "{$ime} {$prezime}";
    ?>
, <?php 
    echo $student;
    ?>
 studija <?php 
    echo $studij_naziv;
    ?>
, <?php 
    echo $godina_studija;
    ?>
. godina, broj indexa <?php 
    echo $brindexa;
    ?>
, <?php 
    echo $tekst_mijenja;
    ?>
 molim Vas da mi u skladu sa Zakonom o visokom obrazovanju Kantona Sarajevo, u <?php 
    echo $tekst_semestar;
    ?>
 semestru akademske <?php 
    echo $agnaziv;
    ?>
 godine odobrite slušanje sljedećih predmeta sa <?php 
    echo $godina_studija + 1;
    ?>
. godine studija u koliziji:</p>

<ul>
<?php 
    foreach ($predmeti_kolizija as $id => $predmet) {
        print "<li>{$predmet} (" . $predmeti_ects[$id] . " ECTS)</li>\n";
    }
    ?>
</ul>

<p>&nbsp;</p>

<p>Obzirom da sa <?php 
    echo $godina_studija;
    ?>
. godine studija nisam <?php 
    echo $polozio;
    ?>
 sljedeće predmete:</p>

<ul>
<?php 
    foreach ($predmeti_prenos as $id => $predmet) {
        print "<li>{$predmet} (" . $predmeti_ects[$id] . " ECTS)</li>\n";
    }
    ?>
</ul>

te da se jedan predmet prenosi, nije prekoračen maksimalan broj od 30 ECTS kredita po semestru.</p>

<p>&nbsp;</p>

<p>U nadi da ćete udovoljiti mom zahtjevu,</p>

<p>&nbsp;</p>

<table border="0"><tr><td width="100%">&nbsp;</td><td align="right"><p>&nbsp;</p><p>_____________________________________</p></td></tr>
<tr><td width="100%">&nbsp;</td><td align="center"><?php 
    echo "{$ime} {$prezime}";
    ?>
</td></tr></table>
</body>
</html>
<?php 
    return;
    $q5 = myquery("select uu.id, s.id, s.naziv, s.naziv_en, uu.semestar, s.tipstudija from ugovoroucenju as uu, studij as s where uu.student={$userid} and uu.akademska_godina={$zagodinu} and uu.studij=s.id order by semestar desc limit 1");
    if (mysql_num_rows($q5) < 1) {
        niceerror("Nije kreiran ugovor o učenju za studenta.");
        return;
    }
    $ugovorid = mysql_result($q5, 0, 0);
    $studij = mysql_result($q5, 0, 1);
    $studijbos = mysql_result($q5, 0, 2);
    $studijbos = substr($studijbos, 0, strpos($studijbos, "(") - 1);
    $studijeng = mysql_result($q5, 0, 3);
    $sem2 = mysql_result($q5, 0, 4);
    $tipstudija = mysql_result($q5, 0, 5);
    $sem1 = $sem2 - 1;
    $godina = $sem2 / 2;
    // Ostali podaci o osobi
    $q10 = myquery("select ime, prezime, brindexa from osoba where id={$userid}");
    $imeprezime = mysql_result($q10, 0, 0) . " " . mysql_result($q10, 0, 1);
    $brindexa = mysql_result($q10, 0, 2);
    // Najnoviji plan za odabrani studij
    $q6 = myquery("select godina_vazenja from plan_studija where studij={$studij} order by godina_vazenja desc limit 1");
    if (mysql_num_rows($q6) < 1) {
        niceerror("Nepostojeći studij");
        return;
    }
    $najnoviji_plan = mysql_result($q6, 0, 0);
    // Da li je ponovac?
    $q20 = myquery("select semestar from student_studij where student={$userid} and studij={$studij} and akademska_godina={$proslagodina} order by semestar desc limit 1");
    if ($sem1 > mysql_result($q20, 0, 0)) {
        $ponovac = 0;
    } else {
        $ponovac = 1;
    }
    // Odredjujemo da li ima prenesenih predmeta
    // TODO: ovo sada ne radi za izborne predmete
    $q20 = myquery("select p.sifra, p.naziv, p.ects, ps.semestar from predmet as p, plan_studija as ps where ps.godina_vazenja={$najnoviji_plan} and ps.studij={$studij} and (ps.semestar=" . ($sem1 - 1) . " or ps.semestar=" . ($sem1 - 2) . ") and ps.obavezan=1 and ps.predmet=p.id and (select count(*) from konacna_ocjena as ko where ko.student={$userid} and ko.predmet=p.id)=0");
    if (mysql_num_rows($q20) > 1) {
        niceerror("Nemate uslove za upis {$godina}. godine studija");
        print "Sačekajte da prikupite uslov ili popunite Ugovor za prethodnu godinu studija.";
        return;
    }
    if (mysql_num_rows($q20) == 1) {
        $ima_preneseni = 1;
        $preneseni_sifra = mysql_result($q20, 0, 0);
        $preneseni_naziv = mysql_result($q20, 0, 1);
        $preneseni_ects = mysql_result($q20, 0, 2);
        $preneseni_semestar = mysql_result($q20, 0, 3);
    } else {
        $ima_preneseni = 0;
    }
    // Privremeni hack za master
    if ($tipstudija == 3) {
        $mscfile = "-msc";
    } else {
        if ($tipstudija == 2) {
            $mscfile = "";
        }
    }
    // Ako čovjek upisuje prvu godinu nečeka (mastera), broj indexa je netačan!
    if ($godina == 1) {
        $brindexa = "";
    }
    // ----- Pravljenje PDF dokumenta
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    $pdf->SetCreator("Zamger");
    $pdf->SetTitle('Domestic Learning Agreement / Ugovor o ucenju');
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    //set margins
    $pdf->SetMargins(0, 0, 0);
    //set auto page breaks
    $pdf->SetAutoPageBreak(false);
    //set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    //$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO*2.083333);
    $pdf->setJPEGQuality(100);
    //set some language-dependent strings
    $pdf->setLanguageArray($l);
    // ---------------------------------------------------------
    // set font
    $pdf->SetFont('freesans', 'B', 9);
    $pdf->SetHeaderData("", 0, "", "");
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    // add a page
    $pdf->AddPage();
    //	$pdf->Image("images/content/150dpi/ETF-Domestic-contract-PGS-ALL-0.png",210,297,0,0,'','','',true,150);
    $pdf->Image("images/content/150dpi/domestic-contract{$mscfile}-0.png", 0, 0, 210, 0, '', '', '', true, 150);
    $pdf->SetXY(175, 34);
    $pdf->Cell(23, 0, $agnaziv, 0, 0, 'C');
    $pdf->SetXY(175, 42);
    $pdf->Cell(23, 0, $godina . ".", 0, 0, 'C');
    $pdf->SetXY(175, 50);
    $pdf->Cell(23, 0, $sem1 . ". & " . $sem2, 0, 0, 'C');
    $pdf->SetXY(70, 48);
    $pdf->Cell(100, 0, $studijeng, 0, 0);
    $pdf->SetXY(70, 52);
    $pdf->Cell(100, 0, $studijbos, 0, 0);
    $pdf->SetXY(70, 62);
    $pdf->Cell(100, 0, $imeprezime);
    $pdf->SetXY(70, 69);
    $pdf->Cell(100, 0, $brindexa);
    // PRVI SEMESTAR
    $pdf->AddPage();
    $pdf->Image("images/content/150dpi/domestic-contract{$mscfile}-1.png", 0, 0, 210);
    $pdf->SetXY(175, 34);
    $pdf->Cell(23, 0, $agnaziv, 0, 0, 'C');
    $pdf->SetXY(175, 42);
    $pdf->Cell(23, 0, $godina . ".", 0, 0, 'C');
    $pdf->SetXY(175, 50);
    $pdf->Cell(23, 0, $sem1 . ".", 0, 0, 'C');
    $pdf->SetXY(70, 48);
    $pdf->Cell(100, 0, $studijeng, 0, 0);
    $pdf->SetXY(70, 52);
    $pdf->Cell(100, 0, $studijbos, 0, 0);
    $pdf->SetXY(70, 62);
    $pdf->Cell(100, 0, $imeprezime);
    $pdf->SetXY(70, 69);
    $pdf->Cell(100, 0, $brindexa);
    // Spisak obaveznih predmeta na neparnom semestru
    // Ako je ponovac, ne prikazujemo predmete koje je polozio
    if ($ponovac == 1) {
        $q100 = myquery("select p.sifra, p.naziv, p.ects from predmet as p, plan_studija as ps where ps.godina_vazenja={$najnoviji_plan} and ps.studij={$studij} and ps.semestar={$sem1} and ps.obavezan=1 and ps.predmet=p.id and (select count(*) from konacna_ocjena as ko where ko.student={$userid} and ko.predmet=p.id)=0");
    } else {
        // Ako nije, trebamo prikazati one koje je položio u koliziji
        $q100 = myquery("select p.sifra, p.naziv, p.ects from predmet as p, plan_studija as ps where ps.godina_vazenja={$najnoviji_plan} and ps.studij={$studij} and ps.semestar={$sem1} and ps.obavezan=1 and ps.predmet=p.id");
    }
    $ykoord = 95;
    $ects = 0;
    while ($r100 = mysql_fetch_row($q100)) {
        $pdf->SetXY(13, $ykoord);
        $pdf->Cell(100, 0, $r100[0]);
        $pdf->SetXY(50, $ykoord);
        $pdf->Cell(100, 0, $r100[1]);
        $e = "{$r100['2']}";
        if (!strchr($e, ".")) {
            $e .= ".0";
        }
        $pdf->SetXY(170, $ykoord);
        $pdf->Cell(100, 0, $e);
        $ykoord += 4;
        $ects += $r100[2];
    }
    // Da li je prenesen predmet na neparnom semestru?
    if ($ima_preneseni && $preneseni_semestar % 2 == 1) {
        $pdf->SetXY(13, $ykoord);
        $pdf->Cell(100, 0, $preneseni_sifra);
        $pdf->SetXY(50, $ykoord);
        $pdf->Cell(100, 0, $preneseni_naziv);
        $e = "{$preneseni_ects}";
        if (!strchr($e, ".")) {
            $e .= ".0";
        }
        $pdf->SetXY(170, $ykoord);
        $pdf->Cell(100, 0, $e);
        $ykoord += 4;
        $ects += $preneseni_ects;
    }
    // Spisak izbornih predmeta
    if ($ponovac == 1) {
        $q110 = myquery("select p.sifra, p.naziv, p.ects from predmet as p, ugovoroucenju_izborni as uoui, ugovoroucenju as uu where uoui.ugovoroucenju=uu.id and uu.student={$userid} and uu.akademska_godina={$zagodinu} and uoui.predmet=p.id and uu.semestar={$sem1} and (select count(*) from konacna_ocjena as ko where ko.student={$userid} and ko.predmet=p.id)=0");
    } else {
        $q110 = myquery("select p.sifra, p.naziv, p.ects from predmet as p, ugovoroucenju_izborni as uoui, ugovoroucenju as uu where uoui.ugovoroucenju=uu.id and uu.student={$userid} and uu.akademska_godina={$zagodinu} and uoui.predmet=p.id and uu.semestar={$sem1}");
    }
    $ykoord = 123;
    while ($r110 = mysql_fetch_row($q110)) {
        $pdf->SetXY(13, $ykoord);
        $pdf->Cell(100, 0, $r110[0]);
        $pdf->SetXY(50, $ykoord);
        $pdf->Cell(100, 0, $r110[1]);
        $e = "{$r110['2']}";
        if (!strchr($e, ".")) {
            $e .= ".0";
        }
        $pdf->SetXY(170, $ykoord);
        $pdf->Cell(100, 0, $e);
        $ykoord += 4;
        $ects += $r110[2];
    }
    // Suma ects
    if (!strchr($ects, ".")) {
        $ects .= ".0";
    }
    $pdf->SetXY(170, 135);
    $pdf->Cell(100, 0, $ects);
    // DRUGI SEMESTAR
    $pdf->AddPage();
    $pdf->Image("images/content/150dpi/domestic-contract{$mscfile}-2.png", 0, 0, 210);
    $pdf->SetXY(175, 34);
    $pdf->Cell(23, 0, $agnaziv, 0, 0, 'C');
    $pdf->SetXY(175, 42);
    $pdf->Cell(23, 0, $godina . ".", 0, 0, 'C');
    $pdf->SetXY(175, 50);
    $pdf->Cell(23, 0, $sem2 . ".", 0, 0, 'C');
    $pdf->SetXY(70, 48);
    $pdf->Cell(100, 0, $studijeng, 0, 0);
    $pdf->SetXY(70, 52);
    $pdf->Cell(100, 0, $studijbos, 0, 0);
    $pdf->SetXY(70, 62);
    $pdf->Cell(100, 0, $imeprezime);
    $pdf->SetXY(70, 69);
    $pdf->Cell(100, 0, $brindexa);
    // Spisak obaveznih predmeta na parnom semestru
    if ($ponovac == 1) {
        $q100 = myquery("select p.sifra, p.naziv, p.ects from predmet as p, plan_studija as ps where ps.godina_vazenja={$najnoviji_plan} and ps.studij={$studij} and ps.semestar={$sem2} and ps.obavezan=1 and ps.predmet=p.id and (select count(*) from konacna_ocjena as ko where ko.student={$userid} and ko.predmet=p.id)=0");
    } else {
        $q100 = myquery("select p.sifra, p.naziv, p.ects from predmet as p, plan_studija as ps where ps.godina_vazenja={$najnoviji_plan} and ps.studij={$studij} and ps.semestar={$sem2} and ps.obavezan=1 and ps.predmet=p.id");
    }
    $ykoord = 95;
    $ects = 0;
    while ($r100 = mysql_fetch_row($q100)) {
        $pdf->SetXY(13, $ykoord);
        $pdf->Cell(100, 0, $r100[0]);
        $pdf->SetXY(50, $ykoord);
        $pdf->Cell(100, 0, $r100[1]);
        $e = "{$r100['2']}";
        if (!strchr($e, ".")) {
            $e .= ".0";
        }
        $pdf->SetXY(170, $ykoord);
        $pdf->Cell(100, 0, $e);
        $ykoord += 4;
        $ects += $r100[2];
    }
    // Da li je prenesen predmet na parnom semestru?
    if ($ima_preneseni && $preneseni_semestar % 2 == 0) {
        $pdf->SetXY(13, $ykoord);
        $pdf->Cell(100, 0, $preneseni_sifra);
        $pdf->SetXY(50, $ykoord);
        $pdf->Cell(100, 0, $preneseni_naziv);
        $e = "{$preneseni_ects}";
        if (!strchr($e, ".")) {
            $e .= ".0";
        }
        $pdf->SetXY(170, $ykoord);
        $pdf->Cell(100, 0, $e);
        $ykoord += 4;
        $ects += $preneseni_ects;
    }
    // Spisak izbornih predmeta
    if ($ponovac == 1) {
        $q110 = myquery("select p.sifra, p.naziv, p.ects from predmet as p, ugovoroucenju_izborni as uoui, ugovoroucenju as uu where uoui.ugovoroucenju=uu.id and uu.student={$userid} and uu.akademska_godina={$zagodinu} and uoui.predmet=p.id and uu.semestar={$sem2} and (select count(*) from konacna_ocjena as ko where ko.student={$userid} and ko.predmet=p.id)=0");
    } else {
        $q110 = myquery("select p.sifra, p.naziv, p.ects from predmet as p, ugovoroucenju_izborni as uoui, ugovoroucenju as uu where uoui.ugovoroucenju=uu.id and uu.student={$userid} and uu.akademska_godina={$zagodinu} and uoui.predmet=p.id and uu.semestar={$sem2}");
    }
    $ykoord = 123;
    while ($r110 = mysql_fetch_row($q110)) {
        $pdf->SetXY(13, $ykoord);
        $pdf->Cell(100, 0, $r110[0]);
        $pdf->SetXY(50, $ykoord);
        $pdf->Cell(100, 0, $r110[1]);
        $e = "{$r110['2']}";
        if (!strchr($e, ".")) {
            $e .= ".0";
        }
        $pdf->SetXY(170, $ykoord);
        $pdf->Cell(100, 0, $e);
        $ykoord += 4;
        $ects += $r110[2];
    }
    // Suma ects
    if (!strchr($ects, ".")) {
        $ects .= ".0";
    }
    $pdf->SetXY(170, 135);
    $pdf->Cell(100, 0, $ects);
    // ---------------------------------------------------------
    //Close and output PDF document
    $pdf->Output('ugovor_o_ucenju.pdf', 'I');
    //============================================================+
    // END OF FILE
    //============================================================+
}
Example #3
1
function izvjestaj_prijemni_brzi_unos()
{
    require_once 'lib/tcpdf/tcpdf.php';
    $termin = intval($_REQUEST['termin']);
    $osoba = intval($_REQUEST['osoba']);
    $q10 = myquery("select ime, prezime, imeoca, jmbg from osoba where id={$osoba}");
    if (mysql_num_rows($q10) < 1) {
        biguglyerror("Nepostojeća osoba");
        zamgerlog("nepostojeca osoba {$osoba}", 3);
        return;
    }
    $ime = mysql_result($q10, 0, 0);
    $prezime = mysql_result($q10, 0, 1);
    $imeoca = mysql_result($q10, 0, 2);
    $jmbg = mysql_result($q10, 0, 3);
    $q20 = myquery("select sifra, jezik from prijemni_obrazac where osoba={$osoba} and prijemni_termin={$termin}");
    if (mysql_num_rows($q20) < 1) {
        biguglyerror("Ne postoji obrazac za ovu osobu");
        zamgerlog("za osobu u{$osoba} ne postoji obrazac na terminu {$termin}", 3);
        return;
    }
    $sifra = mysql_result($q20, 0, 0);
    $jezik = mysql_result($q20, 0, 1);
    $datum = date("d. m. Y.");
    $vrijeme = date("h:i");
    // ----- Pravljenje PDF dokumenta
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    $pdf->SetCreator("Zamger");
    $pdf->SetTitle('Sifra kandidata i pregled vaznijih datuma');
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    //set margins
    $pdf->SetMargins(0, 0, 0);
    //set auto page breaks
    $pdf->SetAutoPageBreak(false);
    //set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    //$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO*2.083333);
    $pdf->setJPEGQuality(100);
    //set some language-dependent strings
    $pdf->setLanguageArray($l);
    // ---------------------------------------------------------
    // set font
    $pdf->SetFont('freesans', '', 48);
    $pdf->SetHeaderData("", 0, "", "");
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    // add a page
    $pdf->AddPage();
    //	$pdf->Image("images/content/150dpi/ETF-Domestic-contract-PGS-ALL-0.png",210,297,0,0,'','','',true,150);
    if ($jezik == "en") {
        $pdf->Image("images/content/150dpi/obrazac_sa_sifrom_en.png", 0, 0, 210, 0, '', '', '', true, 150);
        $en_offset = 7;
    } else {
        $pdf->Image("images/content/150dpi/obrazac_sa_sifrom.png", 0, 0, 210, 0, '', '', '', true, 150);
        $en_offset = 0;
    }
    $pdf->SetXY(130, 15);
    $pdf->Cell(23, 0, $sifra, 0, 0, 'C');
    $pdf->SetFont('freesans', '', 16);
    $pdf->SetXY(80, 62 + $en_offset);
    $pdf->Cell(23, 0, "{$ime} ({$imeoca}) {$prezime}");
    $pdf->SetXY(80, 73 + $en_offset);
    $pdf->Cell(23, 0, $jmbg);
    $pdf->SetFont('freesans', '', 14);
    $pdf->SetXY(40, 113 + $en_offset);
    $pdf->Cell(23, 0, $datum);
    $pdf->SetXY(130, 113 + $en_offset);
    $pdf->Cell(23, 0, $vrijeme);
    // ---------------------------------------------------------
    //Close and output PDF document
    $pdf->Output('obrazac_sa_sifrom.pdf', 'I');
    //============================================================+
    // END OF FILE
    //============================================================+
}
Example #4
0
 /**
  * @param Layout|null $default_layout
  */
 public function __construct(Layout $default_layout = null)
 {
     $this->pdf = new \TCPDF('P', 'pt', 'A4', true, 'UTF-8');
     $this->pdf->SetCreator('Thinreports Generator');
     $this->pdf->SetAutoPageBreak(false);
     $this->pdf->SetMargins(0, 0, 0, true);
     $this->pdf->SetCellPadding(0);
     $this->pdf->SetCellMargins(0, 0, 0, 0);
     $this->pdf->SetPrintHeader(false);
     $this->pdf->SetPrintFooter(false);
     if ($default_layout !== null) {
         $this->pdf->SetTitle($default_layout->getReportTitle());
         $this->registerPageFormat($default_layout);
     }
     $this->initDrawer();
 }
function prepareStockStatusReport($conn)
{
    $lan = $_POST['lan'];
    if ($lan == 'en-GB') {
        $MonthList = array('1' => 'January', '2' => 'February', '3' => 'March', '4' => 'April', '5' => 'May', '6' => 'June', '7' => 'July', '8' => 'August', '9' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');
    } else {
        $MonthList = array('1' => 'Janvier', '2' => 'F�vrier', '3' => 'Mars', '4' => 'Avril', '5' => 'Mai', '6' => 'Juin', '7' => 'Juillet', '8' => 'Ao�t', '9' => 'Septembre', '10' => 'Octobre', '11' => 'Novembre', '12' => 'D�cembre');
    }
    require_once 'tcpdf/tcpdf.php';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    $pdf->SetFont('dejavusans', '', 12);
    $pdf->AddPage();
    ini_set('magic_quotes_gpc', 'off');
    $html = htmlentities($_POST['html'], ENT_QUOTES, "UTF-8");
    $html = html_entity_decode($html, ENT_QUOTES, "UTF-8");
    $alavel = htmlentities($_POST['alavel'], ENT_QUOTES, "UTF-8");
    $alavel = html_entity_decode($alavel, ENT_QUOTES, "UTF-8");
    $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/stock_status.svg';
    if (file_exists($filePath)) {
        unlink($filePath);
    }
    $file = fopen($filePath, "w");
    fwrite($file, $html);
    fclose($file);
    $pdf->ImageSVG($file = 'pdfslice/stock_status.svg', $x = 8, $y = 20, $w = 180, $h = '', $link = '', $align = 'left', $palign = 'center', $border = 0, $fitonpage = false);
    $html2 = <<<EOF
    <!-- EXAMPLE OF CSS STYLE -->
    <style>
    </style>
    <body>
        <div id="barchartlegend">
            {$alavel}
        </div>
    </body>
EOF;
    echo $html2;
    $pdf->writeHTMLCell($w = 150, $h = 30, $x = 15, $y = 0, $html2, $border = 0, $ln = 0, $fill = false, $reseth = true, $align = 'C', $autopadding = true);
    $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/StockStatusChart.pdf';
    if (file_exists($filePath)) {
        unlink($filePath);
    }
    $pdf->Output('pdfslice/StockStatusChart.pdf', 'F');
}
function prepareFundingStatusReport($conn)
{
    require_once 'tcpdf/tcpdf.php';
    //$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf = new TCPDF('L', PDF_UNIT, 'Letter', true, 'UTF-8', false);
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    $pdf->SetFont('dejavusans', '', 7);
    $pdf->AddPage($orientation = L, $format = 'Letter', $keepmargins = true, $tocpage = false);
    ini_set('magic_quotes_gpc', 'off');
    $html = htmlentities($_POST['html'], ENT_QUOTES, "UTF-8");
    $html = html_entity_decode($html, ENT_QUOTES, "UTF-8");
    $alavel = htmlentities($_POST['alavel'], ENT_QUOTES, "UTF-8");
    $alavel = html_entity_decode($alavel, ENT_QUOTES, "UTF-8");
    $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/funding_status.svg';
    if (file_exists($filePath)) {
        unlink($filePath);
    }
    $file = fopen($filePath, "w");
    fwrite($file, $html);
    fclose($file);
    $pdf->ImageSVG($file = 'pdfslice/funding_status.svg', $x = 3, $y = 20, $w = 1291, $h = 400, $link = '', $align = '', $palign = 'center', $border = 0, $fitonpage = false);
    $html2 = <<<EOF
    <!-- EXAMPLE OF CSS STYLE -->
    <style>
    </style>
    <body>
        <div id="barchartlegend">
            {$alavel}
        </div>
    </body>
EOF;
    echo $html2;
    $pdf->writeHTMLCell($w = 150, $h = 30, $x = 15, $y = 130, $html2, $border = 0, $ln = 0, $fill = false, $reseth = true, $align = 'middle', $autopadding = true);
    $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/FundingStatusChart.pdf';
    if (file_exists($filePath)) {
        unlink($filePath);
    }
    $pdf->Output('pdfslice/FundingStatusChart.pdf', 'F');
}
 public function postAdicionar()
 {
     $pdf = new TCPDF();
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('GestBiblio - Sistema de Gestão de Bibliotecas');
     $pdf->SetTitle('Comprovante de Imprestimo');
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     $pdf->AddPage();
     $html = '';
     $pdf->Text(90, 140, 'This is a test');
     $filename = storage_path() . '/test.pdf';
     $pdf->output($filename, 'F');
     return Response::view($filename);
 }
Example #8
0
 /**
  * [พิมพ์ post]
  * @param  [type] $id [description]
  * @return [type]     [description]
  */
 public function printPost($id)
 {
     if (Session::get('c3') == 1) {
         $sql = ' select c.*, concat(n.pname,n.fname," ",n.lname) as fullname from c_blog_posts c left join n_datageneral n on n.cid=c.created_by';
         $sql .= ' where postID =' . e($id) . ' ';
         $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
         $pdf->SetPrintHeader(false);
         $pdf->SetPrintFooter(false);
         // set header and footer fonts
         $pdf->setHeaderFont(array('angsanaupc', '', PDF_FONT_SIZE_MAIN));
         $pdf->setFooterFont(array('angsanaupc', '', PDF_FONT_SIZE_DATA));
         // set default monospaced font
         $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
         // set margins
         $pdf->SetMargins(15, 15, 15);
         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
         $pdf->AddPage();
         $pdf->SetFont('angsanaupc', 'B', 16, '', true);
         $pdf->SetXY(15, 15);
         $pdf->MultiCell(180, 0, 'ใบประสานงานขอรถ', 0, 'C', 0, 1, '', '', true);
         $data = DB::select($sql);
         $pdf->SetFont('angsanaupc', '', 14, '', true);
         $tbl = '<br /><br /><table style="width: 100%; padding:2px;" cellspacing="0">';
         foreach ($data as $key => $value) {
             $tbl = $tbl . '<tr>
                   <td style="border: 0px solid #000000; text-align:left"> เรื่อง ' . $value->postTitle . '</td>
               </tr>';
             $tbl = $tbl . '<tr>
                   <td style="border: 0px solid #000000; text-align:left"> สร้างโดย ' . $value->fullname . ' วันที่ ' . date("d-m", strtotime($value->postDate)) . '-' . (date("Y", strtotime($value->postDate)) + 543) . ' เวลา ' . date("H:i:s", strtotime($value->postDate)) . '</td>
               </tr>';
             $tbl = $tbl . '<tr>
                   <td style="border: 0px solid #000000; text-align:left"> ' . $value->postDesc . '</td>
               </tr>';
         }
         $tbl = $tbl . '</table>';
         $pdf->writeHTML($tbl, true, false, false, false, '');
         $filename = storage_path() . '/report_post.pdf';
         $contents = $pdf->output($filename, 'I');
         $headers = array('Content-Type' => 'application/pdf');
         return Response::make($contents, 200, $headers);
     } else {
         return Redirect::to('contact');
     }
 }
 /**
  * Sets up a new PDF object with the necessary settings
  *
  * @return  FPDF            A new PDF object
  */
 protected function initialize_pdf()
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/elisreports/lib/tcpdf/tcpdf.php';
     $newpdf = new TCPDF('L', 'in', 'letter');
     //prevent the library from automatically outputting
     //header or footer bars
     $newpdf->SetPrintHeader(false);
     $newpdf->SetPrintFooter(false);
     $newpdf->setMargins(self::marginx, self::marginy);
     $newpdf->SetFont('freesans', '', 9);
     $newpdf->AddPage();
     $newpdf->SetFont('freesans', '', 16);
     $newpdf->MultiCell(0, 0.2, $this->report->title, 0, 'C');
     $newpdf->Ln(0.2);
     $newpdf->SetFont('freesans', '', 8);
     $newpdf->SetFillColor(225, 225, 225);
     return $newpdf;
 }
function generateShipmentReport($conn)
{
    global $gTEXT;
    require_once 'tcpdf/tcpdf.php';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    $pdf->AddPage();
    $pdf->SetFillColor(255, 255, 255);
    //=====================================================National Inventory Table=======================================================
    /*	$months = $_POST['MonthNumber']; 
        $monthIndex = date("n");
        $yearIndex = date("Y");
        settype($yearIndex, "integer");    
        if ($monthIndex == 1){
    		$monthIndex = 12;				
    		$yearIndex = $yearIndex - 1;				
    	}else{
    	    $monthIndex = $monthIndex - 1;
    	}
        $months = $months - 1;  
          	   
        $currentYearMonth = $yearIndex."-0".$monthIndex."-"."01";    
        $currentYearMonth = date('Y-m-d', strtotime($currentYearMonth));
    	$lastYearMonth = date("Y-m-d", strtotime(date("Y-m-d", strtotime($currentYearMonth)) . "-".$months." month"));  
        */
    $StartMonthId = $_POST['StartMonthId'];
    $StartYearId = $_POST['StartYearId'];
    $EndMonthId = $_POST['EndMonthId'];
    $EndYearId = $_POST['EndYearId'];
    if ($_POST['MonthNumber'] != 0) {
        $months = $_POST['MonthNumber'];
        $monthIndex = date("m");
        $yearIndex = date("Y");
        settype($yearIndex, "integer");
        $startDate = $yearIndex . "-" . $monthIndex . "-" . "01";
        $startDate = date('Y-m-d', strtotime($startDate));
        $months--;
        $endDate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($startDate)) . "+" . $months . " month"));
    } else {
        $startDate = $StartYearId . "-" . $StartMonthId . "-" . "01";
        $startDate = date('Y-m-d', strtotime($startDate));
        $d = cal_days_in_month(CAL_GREGORIAN, $EndMonthId, $EndYearId);
        $endDate = $EndYearId . "-" . $EndMonthId . "-" . $d;
        $endDate = date('Y-m-d', strtotime($endDate));
    }
    $CountryId = $_POST['ACountryId'];
    $AFundingSourceId = $_POST['AFundingSourceId'];
    $ASStatusId = $_POST['ASStatusId'];
    $ItemGroup = $_POST['ItemGroup'];
    $OwnerTypeId = $_POST['OwnerType'];
    if ($AFundingSourceId) {
        $AFundingSourceId = " AND a.FundingSourceId = '" . $AFundingSourceId . "' ";
    }
    if ($ASStatusId) {
        $ASStatusId = " AND a.ShipmentStatusId = '" . $ASStatusId . "' ";
    }
    if ($ItemGroup) {
        $ItemGroup = " AND e.ItemGroupId = '" . $ItemGroup . "' ";
    }
    if ($OwnerTypeId) {
        $OwnerTypeId = " AND f.OwnerTypeId = '" . $OwnerTypeId . "' ";
    }
    $sLimit = "";
    if (isset($_POST['iDisplayStart'])) {
        $sLimit = " LIMIT " . mysql_real_escape_string($_POST['iDisplayStart']) . ", " . mysql_real_escape_string($_POST['iDisplayLength']);
    }
    $sOrder = "";
    if (isset($_POST['iSortCol_0'])) {
        $sOrder = " ORDER BY  ";
        for ($i = 0; $i < mysql_real_escape_string($_POST['iSortingCols']); $i++) {
            $sOrder .= fnColumnToField_agencyShipment(mysql_real_escape_string($_POST['iSortCol_' . $i])) . "" . mysql_real_escape_string($_POST['sSortDir_' . $i]) . ", ";
        }
        $sOrder = substr_replace($sOrder, "", -2);
    }
    $sWhere = "";
    if ($_POST['sSearch'] != "") {
        $sWhere = "  AND (a.ItemNo LIKE '%" . mysql_real_escape_string($_POST['sSearch']) . "%'  OR " . " e.ItemName LIKE '%" . mysql_real_escape_string($_POST['sSearch']) . "%' OR " . " c.ShipmentStatusDesc LIKE '%" . mysql_real_escape_string($_POST['sSearch']) . "%')  ";
    }
    $sql = "SELECT SQL_CALC_FOUND_ROWS AgencyShipmentId, a.FundingSourceId, d.FundingSourceName, a.ShipmentStatusId, c.ShipmentStatusDesc, a.CountryId, \n            b.CountryName, a.ItemNo, e.ItemName, a.ShipmentDate, a.Qty, a.OwnerTypeId, f.OwnerTypeName \n\t\t\tFROM t_agencyshipment as a\n            INNER JOIN t_country b ON a.CountryId = b.CountryId\n            INNER JOIN t_shipmentstatus c ON a.ShipmentStatusId = c.ShipmentStatusId\n            INNER JOIN t_fundingsource d ON a.FundingSourceId= d.FundingSourceId\n            INNER JOIN t_itemlist e ON a.ItemNo = e.ItemNo\n            INNER JOIN t_owner_type f ON a.OwnerTypeId = f.OwnerTypeId \n            WHERE CAST(a.ShipmentDate AS DATETIME) BETWEEN CAST('{$startDate}' AS DATETIME) AND CAST('{$endDate}' AS DATETIME) \n            AND (a.CountryId = " . $CountryId . " OR " . $CountryId . " = 0) \n            " . $AFundingSourceId . " " . $ASStatusId . " " . $ItemGroup . " " . $OwnerTypeId . "\n\t\t\t{$sWhere} {$sOrder} {$sLimit} ";
    $result = mysql_query($sql, $conn);
    $total = mysql_num_rows($result);
    $i = 0;
    $f = 0;
    $GrandtotalQty = 0;
    $SubtotalQty = 0;
    $OldCountry = ' ';
    $NewCountry = ' ';
    $serial = 1;
    $tblHTML = '';
    if ($total > 0) {
        /* $data=array();
           $f=0; 
           $tblHTML='';
           $tempGroupId='';*/
        while ($rec = mysql_fetch_array($result)) {
            $ItemName = trim(preg_replace('/\\s+/', ' ', addslashes($rec['ItemName'])));
            $date = strtotime($rec['ShipmentDate']);
            $newdate = date('d/m/Y', $date);
            if ($OldCountry == ' ') {
                $OldCountry = addslashes($rec['CountryName']);
            }
            $NewCountry = addslashes($rec['CountryName']);
            if ($OldCountry != $NewCountry) {
                $tblHTML .= '<tr >
                       <td style="background-color:#FE9929;border-radius:2px;align:center; font-size:12px;"colspan="5">Sub Total</td>
                       <td style="background-color:#FE9929;border-radius:2px;text-align:right; font-size:12px;">' . number_format($SubtotalQty) . '</td>
    				</tr>';
                $tblHTML .= '<tr >
                     <td style="background-color:#DAEF62;border-radius:2px;align:center; font-size:12px;"colspan="6">' . $NewCountry . '</td>
                     
                     </tr>';
                $tempGroupId = $rec['CountryName'];
                $OldCountry = $NewCountry;
                $SubtotalQty = $rec['Qty'];
            } else {
                $SubtotalQty += $rec['Qty'];
            }
            if ($tempGroupId != $rec['CountryName']) {
                $tblHTML .= '<tr >
	                     <td style="background-color:#DAEF62;border-radius:2px;  align:center; font-size:12px;" colspan="6">' . $rec['CountryName'] . '</td>
	                   </tr>';
                $tempGroupId = $rec['CountryName'];
            }
            $tblHTML .= '<tr>
                             <td style="text-align: center;">' . $serial++ . '</td>
                             <td style="text-align:left;">' . $ItemName . '</td>
                	         <td style="text-align:left;">' . addslashes($rec['FundingSourceName']) . '</td>
                             <td style="text-align:left;">' . addslashes($rec['ShipmentStatusDesc']) . '</td>
                	         <td style="text-align:right;">' . $newdate . '</td>
                	         <td style="text-align:right;">' . number_format(addslashes($rec['Qty'])) . '</td>
        	           </tr>';
            $GrandtotalQty += $rec['Qty'];
            $tblHTML .= '';
            if ($total == $i + 1) {
                $tblHTML .= '<tr >
                       <td style="background-color:#FE9929;border-radius:2px;  align:center; font-size:12px;" colspan="5">Sub Total</td>
                       <td style="background-color:#FE9929;border-radius:2px;  text-align:right; font-size:12px;" ">' . number_format($SubtotalQty) . '</td>
                	</tr>';
                $tblHTML .= '<tr >
                       <td style="background-color:#FE9929;border-radius:2px;  align:center; font-size:12px;" colspan="5">Sub Total</td>
                       <td style="background-color:#FE9929;border-radius:2px;  text-align:right; font-size:12px;" ">' . number_format($SubtotalQty) . '</td>
                	</tr>';
                $tblHTML .= '<tr >
                       <td style="background-color:#50ABED;border-radius:2px;  align:center; font-size:12px;" colspan="5">Grand Total</td>
                       <td style="background-color:#50ABED;border-radius:2px;  text-align:right; font-size:12px;" ">' . number_format($GrandtotalQty) . '</td>
                	</tr>';
                $tblHTML .= '<tr >
                       <td style="background-color:#50ABED;border-radius:2px;  align:center; font-size:12px;" colspan="5">Grand Total</td>
                       <td style="background-color:#50ABED;border-radius:2px;  text-align:right; font-size:12px;" ">' . number_format($GrandtotalQty) . '</td>
                	</tr>';
            }
            $i++;
        }
        //$months = $_POST['MonthNumber'];
        $months = $_POST['MonthNumber'];
        $CountryName = $_POST['CountryName'];
        $FundingSourceName = $_POST['FundingSourceName'];
        $ItemGroupName = $_POST['ItemGroupName'];
        $ASStatusName = $_POST['ASStatusName'];
        $OwnerTypeName = $_POST['OwnerTypeName'];
        $html = '
        <!-- EXAMPLE OF CSS STYLE -->
        <style>
        p {
          line-height: 0.5px;
        }
        
        </style>
            <body>
                <p style="text-align:center;"><h4 ><b>' . $gTEXT['Shipment Reports'] . '  of ' . $CountryName . ' ' . $gTEXT['from'] . ' ' . date('M,Y', strtotime($startDate)) . ' ' . $gTEXT['to'] . ' ' . date('M,Y', strtotime($endDate)) . '</b></h4></p>
                <p style="text-align:center;"><h5><b>' . $FundingSourceName . ' - ' . $ASStatusName . ' - ' . $ItemGroupName . ' - ' . $OwnerTypeName . '</b><h5></p>
            </body>';
        $pdf->SetFont('dejavusans', '', 10);
        $pdf->writeHTMLCell(0, 0, 8, 10, $html, '', 0, 0, false, 'C', true);
        //date('M,Y', strtotime($StartYearMonth)), date('M,Y', strtotime($EndYearMonth))
        $html = '
            <!-- EXAMPLE OF CSS STYLE -->
            <style>
             td{
                 height: 6px;
                 line-height:3px;
             }
             th{
                height:20;
                font-size:10px;
            }
            </style>
            <body>
            <table width="600px" border="0.5" style="margin:0 auto;">
                <tr>
            		<th width="30" align="center"><b>SL#</b></th>
                    <th width="250" align="left"><b>' . $gTEXT['Product Name'] . '</b></th>
                    <th width="100" align="left"><b>' . $gTEXT['Funding Source'] . '</b></th>
            		<th width="90" align="left"><b>' . $gTEXT['Shipment Status'] . '</b></th>
                    <th width="100" align="right"><b>' . $gTEXT['Shipment Date'] . '</b></th>
                    <th width="90" align="right"><b>' . $gTEXT['Quantity'] . '</b></th>                    
         	    </tr>' . $tblHTML . '</table></body>';
        //echo $tblHTML;
        $pdf->SetFont('dejavusans', '', 7);
        $pdf->writeHTMLCell(0, 0, 10, 40, $html, '', 1, 1, false, 'L', true);
        $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/ShipmentReport.pdf';
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $pdf->Output('pdfslice/ShipmentReport.pdf', 'F');
        echo 'ShipmentReport.pdf';
    } else {
        echo 'Processing Error';
    }
}
Example #11
0
function genPDF($proj, $local = false)
{
    // create new PDF document
    $size = array(8.5, 11);
    $pdf = new TCPDF("l", "in", $size, true, "UTF-8", false);
    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor("EMu Mover");
    $pdf->SetTitle("Project Title");
    $pdf->SetSubject("Project");
    $pdf->SetKeywords("EMu, Project");
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetMargins(0.5, 0.5, 0.5, false);
    setSpacing($pdf);
    // set font
    $pdf->SetFont("helvetica", "", 10);
    // add a page
    $pdf->AddPage();
    $pdf->SetAutoPageBreak(TRUE, 0);
    $html = "";
    $css = file_get_contents("report.css");
    $style = "<style type=\"text/css\">\n{$css}\n</style>";
    $w = $pdf->getPageWidth();
    $h = $pdf->getPageHeight();
    $m = $pdf->getMargins();
    $pdf->setCellPaddings(0.05, 0.1, 0.05, 0);
    $pdf->setCellHeightRatio(0.4);
    $w -= $m['left'] + $m['right'];
    $h -= $m['top'] + $m['bottom'];
    $sixth = $w / 6;
    $sixth = floor($sixth * 100.0) / 100.0;
    $objs = generatePDFcells($proj);
    addHeaderRow($pdf);
    //Get row heights
    $heights = array();
    foreach ($objs as $k1 => $obj) {
        $c = 0;
        $lh = 0;
        $y = $pdf->GetY();
        foreach ($obj as $k2 => $cell) {
            $cellWidth = $sixth;
            $x = $pdf->GetX();
            if ($c == 1) {
                $cellWidth = 3 * $sixth;
            }
            $pdf->writeHTMLcell($cellWidth, 0, $x, $y, $style . $cell, 0, 0, 0, 1, '', 1);
            $c++;
            $tlh = $pdf->getLastH();
            //$objs[$k1][$k2] .= "<p>$tlh</p>";
            if ($tlh > $lh) {
                $lh = $tlh;
            }
        }
        $heights[$k1] = $lh;
        $pdf->deletePage($pdf->getPage());
        $pdf->AddPage();
    }
    addIntro($pdf, $proj);
    $y = $pdf->GetY();
    addHeaderRow($pdf);
    //Now actually create the PDF
    foreach ($objs as $k1 => $obj) {
        $y = $pdf->GetY();
        if (isset($heights[$k1])) {
            if ($y + $heights[$k1] >= $h) {
                $pdf->AddPage();
                addHeaderRow($pdf);
            }
        }
        $c = 0;
        $lh = 0;
        $y = $pdf->GetY();
        foreach ($obj as $k2 => $cell) {
            $cellWidth = $sixth;
            $x = $pdf->GetX();
            if ($c == 1) {
                $cellWidth = 3 * $sixth;
            }
            $pdf->writeHTMLcell($cellWidth, $heights[$k1], $x, $y, $style . $cell, 'LTRB', 0, 0, 1, '', 1);
            $c++;
        }
        $pdf->SetY($y + $heights[$k1]);
    }
    if ($proj) {
        $info = getProjectInfo($proj);
        if ($local) {
            $fname = $info['title'] . ".pdf";
            $pdfpath = sys_get_temp_dir() . "/" . $info['title'] . "--" . date("Y-m-d") . ".pdf";
            $pdf->Output($pdfpath, "F");
            return $pdfpath;
        } else {
            header("Content-type: application/pdf");
            $val = $pdf->Output($info['title'] . "-" . date("Y-m-d") . ".pdf", "I");
            print $val;
        }
        return true;
        exit;
    } else {
        print "{$style}";
        var_dump($objs);
        return false;
    }
}
function generateFacilityInventoryReport($conn)
{
    global $gTEXT;
    require_once 'tcpdf/tcpdf.php';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    $pdf->setFontSubsetting(false);
    $pdf->AddPage();
    $pdf->SetFillColor(255, 255, 255);
    //=====================================================Facility Inventory Table=======================================================
    $MonthId = $_REQUEST['MonthId'];
    $YearId = $_REQUEST['YearId'];
    $mosTypeId = $_REQUEST['MosTypeId'];
    $countryId = $_REQUEST['CountryId'];
    $fLevelId = $_REQUEST['FLevelId'];
    $FacilityId = $_REQUEST['FacilityId'];
    $ItemGroupId = $_REQUEST['ItemGroupId'];
    $regionId = $_REQUEST['RegionId'];
    $districtId = $_REQUEST['DistrictId'];
    $ownerTypeId = $_REQUEST['OwnerTypeId'];
    $region = $_REQUEST['Region'];
    $district = $_REQUEST['District'];
    $ownerType = $_REQUEST['OwnerType'];
    $year = $_REQUEST['Year'];
    $CountryName = $_REQUEST['CountryName'];
    $monthName = $_REQUEST['MonthName'];
    $ItemGroupName = $_REQUEST['ItemGroupName'];
    $FacilityName = $_REQUEST['FacilityName'];
    $lan = $_REQUEST['lan'];
    if ($lan == 'en-GB') {
        $SITETITLE = SITETITLEENG;
    } else {
        $SITETITLE = SITETITLEFRN;
    }
    $column_name = array();
    $sQuery1 = "SELECT\n\t\t\t    MosTypeId\n\t\t\t    , MosTypeName\n\t\t\t    , ColorCode\n\t\t\tFROM\n\t\t\t    t_mostype_facility\n\t\t\tWHERE CountryId = {$countryId} AND FLevelId = {$fLevelId}  AND (MosTypeId = {$mosTypeId} OR {$mosTypeId} = 0)\n\t\t\tORDER BY MosTypeId;";
    $rResult1 = mysql_query($sQuery1);
    $output1 = array();
    $col = '';
    while ($row1 = mysql_fetch_array($rResult1)) {
        $output1[] = $row1;
        array_push($column_name, $row1['MosTypeName']);
    }
    $col .= '<tr><th width="180" align="left"><b>' . $gTEXT['Product Name'] . '</b></th>';
    $col .= '<th width="60" align="left"><b>' . $gTEXT['Closing Balance'] . '</b></th>';
    $col .= '<th width="45" align="left"><b>' . $gTEXT['AMC'] . '</b></th>';
    $col .= '<th width="40" align="left"><b>' . $gTEXT['MOS'] . '</b></th>';
    $f = 0;
    for ($f = 0; $f < count($output1); $f++) {
        $col .= '<th width="70" align="right"><b>' . $column_name[$f] . '</b></th>';
    }
    $col .= '</tr>';
    /*
    	$sQuery = "SELECT p.MosTypeId, ItemName, MOS FROM (SELECT
    				    a.ItemNo
    				    , b.ItemName
    				    , a.MOS
    				,(SELECT MosTypeId FROM t_mostype_facility x WHERE CountryId = $countryId AND FLevelId = $fLevelId  AND (MosTypeId = $mosTypeId OR $mosTypeId = 0) AND a.MOS >= x.MinMos AND a.MOS < x.MaxMos) MosTypeId
    				FROM t_cfm_stockstatus a, t_itemlist b,  t_cfm_masterstockstatus c
    				WHERE a.itemno = b.itemno AND a.MOS IS NOT NULL AND a.MonthId = " . $_REQUEST['MonthId'] . " AND a.Year = '" . $_REQUEST['YearId'] . "' AND a.CountryId = " . $_REQUEST['CountryId'] . " AND a.FacilityId = " . $_REQUEST['FacilityId'] . " AND a.ItemGroupId = " . $_REQUEST['ItemGroupId'] . " AND a.CFMStockId = c.CFMStockId" . " AND c.StatusId = 5 " . ") p
    				WHERE (p.MosTypeId = $mosTypeId OR $mosTypeId = 0) 
    				ORDER BY ItemName";
    */
    if ($ownerTypeId == 1 || $ownerTypeId == 2) {
        $sQuery = "SELECT p.MosTypeId, ItemName, MOS ,ClStock,AMC FROM (SELECT\n\t\t\t\t    a.ItemNo, b.ItemName, a.MOS ,a.ClStock,a.AMC\n\t\t\t\t,(SELECT MosTypeId FROM t_mostype_facility x WHERE CountryId = {$countryId} \n                AND FLevelId = {$fLevelId}  AND (MosTypeId = {$mosTypeId} OR {$mosTypeId} = 0) \n                AND a.MOS >= x.MinMos AND a.MOS < x.MaxMos ) MosTypeId\n\t\t\t\tFROM t_cfm_stockstatus a, t_itemlist b,  t_cfm_masterstockstatus c, t_facility g\n\t\t\t\tWHERE a.itemno = b.itemno AND a.MOS IS NOT NULL AND a.MonthId = " . $MonthId . " \n                AND a.Year = '" . $YearId . "' AND a.CountryId = " . $countryId . " \n                AND a.FacilityId = " . $FacilityId . " AND a.ItemGroupId = " . $ItemGroupId . "\n                AND a.CFMStockId = c.CFMStockId" . " AND c.StatusId = 5 " . "\n                AND a.FacilityId=g.FacilityId \n                AND g.OwnerTypeId = {$ownerTypeId} \n                AND  (g.RegionId = {$regionId} OR {$regionId} = 0)\n                AND (g.DistrictId = {$districtId} OR {$districtId} = 0)\n                 ) p\n                \n\t\t\t\tWHERE (p.MosTypeId = {$mosTypeId} OR {$mosTypeId} = 0) \n\t\t\t\tORDER BY ItemName";
    } else {
        $sQuery = "SELECT p.MosTypeId, ItemName, MOS ,ClStock,AMC FROM (SELECT\n\t\t\t\t    a.ItemNo, b.ItemName, a.MOS ,a.ClStock,a.AMC\n\t\t\t\t,(SELECT MosTypeId FROM t_mostype_facility x WHERE CountryId = {$countryId} \n                AND FLevelId = {$fLevelId}  AND (MosTypeId = {$mosTypeId} OR {$mosTypeId} = 0) \n                AND a.MOS >= x.MinMos AND a.MOS < x.MaxMos ) MosTypeId\n\t\t\t\tFROM t_cfm_stockstatus a, t_itemlist b,  t_cfm_masterstockstatus c, t_facility g\n\t\t\t\tWHERE a.itemno = b.itemno AND a.MOS IS NOT NULL AND a.MonthId = " . $MonthId . " \n                AND a.Year = '" . $YearId . "' AND a.CountryId = " . $countryId . " \n                AND a.FacilityId = " . $FacilityId . " AND a.ItemGroupId = " . $ItemGroupId . "\n                AND a.CFMStockId = c.CFMStockId" . " AND c.StatusId = 5 " . "\n                AND a.FacilityId=g.FacilityId\n                AND g.AgentType = {$ownerTypeId} \n                AND  (g.RegionId = {$regionId} OR {$regionId} = 0)\n                AND (g.DistrictId = {$districtId} OR {$districtId} = 0) ) p\n                \n\t\t\t\tWHERE (p.MosTypeId = {$mosTypeId} OR {$mosTypeId} = 0) \n\t\t\t\tORDER BY ItemName";
    }
    //echo $sQuery;
    mysql_query("SET character_set_results=utf8");
    $rResult = mysql_query($sQuery);
    $aData = array();
    $total = mysql_num_rows($rResult);
    if ($total > 0) {
        while ($row = mysql_fetch_array($rResult)) {
            $tmpRow = array();
            /*	foreach ($output1 as $rowMosType) {
            			if ($rowMosType['MosTypeId'] == $row['MosTypeId']) {
            				//$tmpRow[] = '<span class="glyphicon glyphicon-ok-circle" style="color:' . $rowMosType['ColorCode'] . ';font-size:2em;"></span>';
            				$tmpRow[] = '<i class="fa fa-check-circle fa-lg" style="color:' . $rowMosType['ColorCode'] . ';font-size:2.5em;"></i>';
            
            			} else
            				$tmpRow[] = '';
            		}
            		array_unshift($tmpRow, $row['ItemName'], number_format($row['MOS'], 1));
            		$aData[] = $tmpRow;*/
            $col .= '<tr style="page-break-inside:avoid;">
			           <td>' . $row['ItemName'] . '</td>
					   <td>' . $row['ClStock'] . '</td>
					   <td>' . $row['AMC'] . '</td>
			         <td> ' . number_format($row['MOS'], 1) . '</td>  ';
            foreach ($output1 as $rowMosType) {
                if ($rowMosType['MosTypeId'] == $row['MosTypeId']) {
                    /*$tmpRow[] = '<i class="fa fa-check-circle fa-lg" style="color:' . $rowMosType['ColorCode'] . ';font-size:2.5em;"></i>';
                    		$col.= '<td><span class="fa fa-check-circle fa-lg" style="color:' . $rowMosType['ColorCode'] . ';font-size:2.5em;text-align:center;"></span></td>';
                    		*/
                    $tmpRow[] = $rowMosType['ColorCode'];
                    $col .= '<td style="background-color:' . $rowMosType['ColorCode'] . '"></td>';
                } else {
                    $col .= '<td> </td>';
                }
            }
            array_unshift($tmpRow, $row['ItemName'], number_format($row['MOS'], 1));
            $aData[] = $tmpRow;
            $col .= ' </tr>';
        }
        $ItemGroupName = $_REQUEST['ItemGroupName'];
        $FacilityName = $_REQUEST['FacilityName'];
        $html_head = '
            <!-- EXAMPLE OF CSS STYLE -->
            <style>
            p {
              line-height: 0.1px;
            }
            </style>
                <body>
					<p><h3 style="text-align:center;"><b>' . $SITETITLE . '</b></h3></p></br>
                    <p><h4 style="text-align:center;"><b>' . $ItemGroupName . ' ' . $gTEXT['Facility Inventory Control Report of '] . '  ' . $CountryName . ' ' . $gTEXT['on'] . ' ' . $monthName . ',' . $year . '</b></h4></p></br>
					<p><h4 style="text-align:center;"><b>' . $gTEXT['Region'] . ': ' . $region . ', ' . $gTEXT['District'] . ': ' . $district . ', ' . $gTEXT['Report By'] . ': ' . $ownerType . '</b></h4></p></br>
                    <p style="text-align:center;"><h4><b>' . $gTEXT['Facility Name'] . ': ' . $FacilityName . '</b><h4></p></br>
                </body>';
        $pdf->SetFont('dejavusans', '', 10);
        $pdf->writeHTMLCell(0, 0, 6, 10, $html_head, '', 0, 0, false, 'C', true);
        $html = '<head>
			  <link rel="stylesheet" href="' . $jBaseUrl . 'templates/protostar/css/template.css" type="text/css" /> 
			  
			 <link href="' . $jBaseUrl . 'templates/protostar/endless/bootstrap/css/bootstrap.min.css" rel="stylesheet">
			 <link href="' . $jBaseUrl . 'templates/protostar/endless/css/font-awesome.min.css" rel="stylesheet">
			 <link href="' . $jBaseUrl . 'templates/protostar/endless/css/pace.css" rel="stylesheet">	
			 <link href="' . $jBaseUrl . 'templates/protostar/endless/css/colorbox/colorbox.css" rel="stylesheet">
			 <link href="' . $jBaseUrl . 'templates/protostar/endless/css/morris.css" rel="stylesheet"/> 	
             <link href="' . $jBaseUrl . 'templates/protostar/endless/css/endless.min.css" rel="stylesheet"> 
	        <link href="' . $jBaseUrl . 'templates/protostar/endless/css/endless-skin.css" rel="stylesheet">
	
	    	<link href="' . $jBaseUrl . 'templates/protostar/endless/bootstrap/css/font-halflings.css" rel="stylesheet">
	    	
			<link href="' . $jBaseUrl . 'administrator/components/com_jcode/source/css/custom.css" rel="stylesheet"/>
			</head>
            <!-- EXAMPLE OF CSS STYLE -->
            <style>
             td{
                 height: 6px;
                 line-height:3px;
             }
             th{
             height: 20;
            }
            </style>
            <body>
            <table width="600px" border="0.5" style="margin:0 auto;">' . $col . '</table></body>';
        $pdf->SetFont('dejavusans', '', 7);
        $pdf->writeHTMLCell(0, 0, 5, 45, $html, '', 1, 1, false, 'L', true);
        $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/FacilityInventoryReport.pdf';
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $pdf->Output('pdfslice/FacilityInventoryReport.pdf', 'F');
        echo 'FacilityInventoryReport.pdf';
    } else {
        echo 'Processing Error';
    }
}
function generateFacilityReport($conn)
{
    global $gTEXT;
    require_once 'tcpdf/tcpdf.php';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    $pdf->setFontSubsetting(false);
    $pdf->AddPage();
    $pdf->SetFillColor(255, 255, 255);
    $monthId = $_POST['MonthId'];
    $year = $_POST['Year'];
    $country = $_POST['CountryId'];
    // $itemGroupId=$_POST['ItemGroupId'];
    $CountryName = $_POST['CountryName'];
    $MonthName = $_POST['MonthName'];
    $ItemGroupName = $_POST['ItemGroupName'];
    $regionId = $_POST['RegionId'];
    $RegionName = $_POST['RegionName'];
    $districtId = $_POST['DistrictId'];
    $DistrictName = $_POST['DistrictName'];
    $ownerTypeId = $_POST['OwnerTypeId'];
    $OwnerTypeName = $_POST['OwnerTypeName'];
    $condition = "";
    if ($regionId) {
        $condition .= " and  x.RegionId = {$regionId} ";
    }
    if ($districtId) {
        $condition .= " and x.DistrictId = {$districtId} ";
    }
    if ($ownerTypeId) {
        $condition .= " and  x.OwnerTypeId = {$ownerTypeId} ";
    }
    $aColumns = array('SL', 'FacilityCode', 'FacilityName', 'bEntered', 'CreatedDt', 'bSubmitted', 'LastSubmittedDt', 'bAccepted', 'AcceptedDt', 'bPublished', 'PublishedDt');
    $sIndexColumn = "FacilityId";
    $sTable = "t_cfm_masterstockstatus";
    $sLimit = "limit 300";
    if (isset($_POST['iDisplayStart']) && $_POST['iDisplayLength'] != '-1') {
        $sLimit = "LIMIT " . intval($_POST['iDisplayStart']) . ", " . intval($_POST['iDisplayLength']);
    }
    $sOrder = "";
    if (isset($_POST['iSortCol_0'])) {
        $sOrder = "ORDER BY  ";
        for ($i = 0; $i < intval($_POST['iSortingCols']); $i++) {
            if ($_POST['bSortable_' . intval($_POST['iSortCol_' . $i])] == "true") {
                $sOrder .= "`" . $aColumns[intval($_POST['iSortCol_' . $i])] . "` " . ($_POST['sSortDir_' . $i] === 'asc' ? 'asc' : 'desc') . ", ";
            }
        }
        $sOrder = substr_replace($sOrder, "", -2);
        if ($sOrder == "ORDER BY") {
            $sOrder = "";
        }
    }
    /*$sWhere="";
    	for ($i = 0; $i < count($aColumns); $i++) {
    		
    		if (isset($_POST['bSearchable_' . $i]) && $_POST['bSearchable_' . $i] == "true" && $_POST['sSearch'] != '') {
    			
    			if ($sWhere == "") {
    				$sWhere = "WHERE ";
    			} else {
    				$sWhere .= " OR ";
    			}
    			$sWhere .= "`" . $aColumns[$i] . "` LIKE '%" . mysql_real_escape_string($_POST['sSearch']) . "%' ";
    		}
    	}*/
    $sWhere = "";
    if ($_POST['sSearch'] != "") {
        $sWhere = " WHERE (b.FacilityCode LIKE '%" . mysql_real_escape_string($_POST['sSearch']) . "%'\n        OR " . " b.FacilityName LIKE '%" . mysql_real_escape_string($_POST['sSearch']) . "%' )";
    }
    safe_query("SET @rank=0;");
    $serial = "@rank:=@rank+1 AS SL";
    $sQuery = "SELECT SQL_CALC_FOUND_ROWS " . $serial . ", b.FacilityId, b.FacilityCode, b.FacilityName,\n\t\t\t\tIFNULL( a.FacilityId,0) bEntered,\t\t\t\t\n\t\t\t\tDATE_FORMAT(a.CreatedDt, '%d-%b-%Y %h:%i %p') CreatedDt,\t\n\t\t\t\tIF(c.StatusId = '2', '1', '0') bSubmitted,\n\t\t\t\tDATE_FORMAT(a.LastSubmittedDt, '%d-%b-%Y %h:%i %p')  LastSubmittedDt,\n\t\t\t\tIF(c.StatusId = '3', '1', '0') bAccepted,\n\t\t\t\tDATE_FORMAT(a.AcceptedDt, '%d-%b-%Y %h:%i %p')  AcceptedDt,\n\t\t\t\tIF(c.StatusId = '5', '1', '0') bPublished,\n\t\t\t\tDATE_FORMAT(a.PublishedDt, '%d-%b-%Y %h:%i %p')  PublishedDt\n\t\t\t\tFROM  t_cfm_masterstockstatus a \n\t\t\t\tRIGHT JOIN (SELECT x.FacilityId, x.FacilityCode, x.FacilityName \n\t\t\t\tFROM t_facility x \n\t\t\t\tWHERE x.CountryId = {$country}  {$condition}) b\n\t\t\t\tON a.FacilityId = b.FacilityId AND  MonthId = {$monthId} \n\t\t\t\tAND Year = '{$year}' AND a.CountryId = {$country} \n\t\t\t\tLEFT JOIN t_status c ON a.StatusId = c.StatusId \n\t\t\t\t{$sWhere}\n\t\t\t\t{$sOrder};";
    mysql_query("SET character_set_results=utf8");
    $r = safe_query($sQuery);
    $total = mysql_num_rows($r);
    $h = 1;
    $col = '';
    $i = 1;
    if ($total > 0) {
        $h = 1;
        while ($rec = mysql_fetch_array($r)) {
            $narr = array();
            for ($i = 0; $i < count($aColumns); $i++) {
                if ($aColumns[$i] == "bEntered") {
                    $narr[] = $rec[$aColumns[$i]] == "0" ? '<span class="label label-danger"> No </span>' : '<span class="label label-success"> Yes </span>';
                } else {
                    if ($aColumns[$i] == "bSubmitted") {
                        $narr[] = $rec[$aColumns[$i]] == "0" ? '<span class="label label-danger"> No </span>' : '<span class="label label-success"> Yes </span>';
                    } else {
                        if ($aColumns[$i] == "bAccepted") {
                            $narr[] = $rec[$aColumns[$i]] == "0" ? '<span class="label label-danger">  No  </span>' : '<span class="label label-success">  Yes  </span>';
                            if ($rec[$aColumns[$i]] == "1") {
                                $narr[5] = '<span class="label label-success">  Yes  </span>';
                            }
                        } else {
                            if ($aColumns[$i] == "bPublished") {
                                $narr[] = $rec[$aColumns[$i]] == "0" ? '<span class="label label-danger">  No  </span>' : '<span class="label label-success">  Yes  </span>';
                                if ($rec[$aColumns[$i]] == "1") {
                                    $narr[5] = '<span class="label label-success">  Yes  </span>';
                                    $narr[7] = '<span class="label label-success">  Yes  </span>';
                                }
                            } else {
                                if ($aColumns[$i] != ' ') {
                                    $narr[] = $rec[$aColumns[$i]];
                                }
                            }
                        }
                    }
                }
            }
            $col .= '<tr style="page-break-inside:avoid;">';
            for ($i = 0; $i < count($narr); $i++) {
                $col .= '<td>' . $narr[$i] . '</td>';
            }
            $col .= '</tr>';
        }
        //echo $col;
        $lan = $_POST['lan'];
        if ($lan == 'en-GB') {
            $SITETITLE = SITETITLEENG;
        } else {
            $SITETITLE = SITETITLEFRN;
        }
        $html = '<style>
    </style>
    <head></head>
    <body>
		 <h3 style="text-align:center;"><b>' . $SITETITLE . '</b></h3>
        <h4 style="text-align:center;"><b>' . $ItemGroupName . ' ' . $gTEXT['Facility Reporting Status of'] . ' ' . $CountryName . ' ' . $gTEXT['on'] . ' ' . $MonthName . ',' . $year . '</b></h4>
        <h4>' . $gTEXT['Region'] . ': ' . $RegionName . ', ' . $gTEXT['District'] . ': ' . $DistrictName . ', ' . $gTEXT['Owner Type'] . ': ' . $OwnerTypeName . '</h4>
    </body>';
        $pdf->SetFont('dejavusans', '', 10);
        $pdf->writeHTMLCell(0, 0, 10, 10, $html, '', 0, 0, false, 'C', true);
        $html = '
    <!-- EXAMPLE OF CSS STYLE -->
    <style>
     td{
         height: 6px;
         line-height:3px;
     }
     th{
     height: 20;
    }
    </style>
    <body>    
    <table width="600px" border="0.5" style="margin:0 auto;">
    <tr style="page-break-inside:avoid;">
            <th width="25px" align="center"><b>SL</b></th>
            <th width="60px" align="left"><b>' . $gTEXT['Facility Code'] . '</b></th>
            <th width="70px" align="left"><b>' . $gTEXT['Facility Name'] . '</b></th>
            <th width="60px" align="center"><b>' . $gTEXT['Entered'] . '</b></th>
            <th width="65px" align="left"><b>' . $gTEXT['Entry Date'] . '</b></th>
            <th width="60px" align="center"><b>' . $gTEXT['Submitted'] . '</b></th>
            <th width="65px" align="right"><b>' . $gTEXT['Submitted Date'] . '</b></th>
            <th width="60px" align="center"><b>' . $gTEXT['Accepted'] . '</b></th>
            <th width="65px" align="left"><b>' . $gTEXT['Accepted Date'] . '</b></th>
            <th width="60px" align="center"><b>' . $gTEXT['Published'] . '</b></th>
            <th width="60px" align="right"><b>' . $gTEXT['Published Date'] . '</b></th>
         </tr>' . $col . '</table></body>';
        //echo $html;
        $pdf->SetFont('dejavusans', '', 7);
        $pdf->writeHTMLCell(0, 0, 10, 45, $html, '', 1, 1, false, 'L', true);
        $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/FacilityReportingStatus.pdf';
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $pdf->Output('pdfslice/FacilityReportingStatus.pdf', 'F');
        echo trim('FacilityReportingStatus.pdf');
    } else {
        echo 'Processing Error';
    }
}
Example #14
0
<?php

$footer = "ważna do <b>" . file_get_contents("config/data.txt") . "</b>";
require_once 'lib/tcpdf.php';
$pdf = new TCPDF("P", "mm", "A4");
$pdf->SetCreator("Legitk(s)i");
$pdf->SetFontSubsetting(false);
$pdf->SetPrintFooter(false);
$pdf->SetPrintHeader(false);
$pdf->SetAutoPageBreak(TRUE, 0);
/* SIZE CONFIG - in mm */
$leftMargin = 5;
$topMargin = 5;
$cellsPerPage = 10;
$cellWidth = 80;
$cellHeight = 50;
//$cellWidth=85; $cellHeight=54; //<-- -1mm for border (A4 is 297mm heigh)
$cellWidth = 78;
$cellHeight = 49;
$handle = fopen("config/ludzie.txt", "r");
if ($handle) {
    $i = -1;
    while (($line = fgets($handle)) !== false) {
        $i = ($i + 1) % $cellsPerPage;
        if ($i == 0) {
            //page change
            $x = $leftMargin;
            $y = $topMargin;
            $pdf->AddPage();
        }
        if ($i % 2 == 0) {
 function project_details($customer_file_id)
 {
     $this->load->library('Pdf');
     $this->load->model(array('payment_schedule_customer_model', 'receipt_model', 'discount_model'));
     $this->db->select('contact.name as customer_name,project.name as project_name,availability_chart_unit.unit_name as unit_name,' . 'customer_file.purchase_cost,customer_file.area,customer_file.rate');
     $this->db->from('customer_file');
     $this->db->join('contact', 'customer_file.customer_id=contact.id');
     $this->db->join('project', 'project.id=customer_file.project_id');
     $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id');
     $this->db->where('customer_file.id', $customer_file_id);
     $project_details = $this->db->get()->first_row();
     //        print_r($project_details);exit(0);
     $land_cost = $this->db->select('cost')->where(array('customer_file_id' => $customer_file_id, 'cost_head_id' => '14'))->get('customer_file_unit_costing')->first_row();
     $this->db->select('company.name,company.address,project.project_type');
     $this->db->from('company');
     $this->db->join('project', 'project.company_id=company.id');
     $this->db->join('customer_file', 'customer_file.project_id=project.id');
     $this->db->where('customer_file.id', $customer_file_id);
     $company_details = $this->db->get()->first_row();
     $crm_settings = $this->db->get('crm_settings')->first_row();
     $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetTitle('Receipt');
     //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255));
     $pdf->SetPrintFooter(false);
     $pdf->setPrintHeader(false);
     //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     //$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
         require_once dirname(__FILE__) . '/lang/eng.php';
         $pdf->setLanguageArray($l);
     }
     $pdf->setFontSubsetting(true);
     $pdf->SetFont('dejavusans', '', 8, '', true);
     $pdf->AddPage();
     $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true);
     $pdf->writeHTMLCell(211, 12, '0', 15, '<p style="text-align:center;">' . $company_details->address . '</p>', 0, 1, 0, true, '', true);
     $pdf->writeHTMLCell(211, 8, '0', 20, '<p style="text-align:center;">' . 'www.olivebuilder.com' . '</p>', 0, 1, 0, true, '', true);
     $style = array('width' => 0.1, 'color' => array(0, 0, 0));
     $pdf->Line(0, 25, 220, 25, $style);
     $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;"> WWF Report </h2>', 0, 1, 0, true, '', true);
     $style = array('width' => 0.1, 'color' => array(0, 0, 0));
     $pdf->Line(0, 35, 220, 35, $style);
     $html = '<br /><br />';
     $html .= '<table cellpadding="5" ><tr><td width="448"><strong> Customer Name : </strong>' . $project_details->customer_name . '</td>';
     $html .= '<td><strong> Date :</strong> ' . date('m-d-Y') . '</td></tr>';
     $html .= '<tr><td><strong> Project  :</strong> ' . $project_details->project_name . '</td>';
     if ($company_details->project_type == 1) {
         $html .= '<td><strong> Flat No :</strong> ' . $project_details->unit_name . '</td></tr>';
     } else {
         $html .= '<td><strong> Villa No :</strong> ' . $project_details->unit_name . '</td></tr>';
     }
     $html .= '<tr><td></td><td><td/></tr></table><br /><br />';
     $html .= '<table  cellpadding="5" align="center" border="1"><tr><td width="35%"><strong> Construction Cost :</strong> ' . ($project_details->purchase_cost - $land_cost->cost) . '</td>';
     $html .= '<td width="35%"><strong> Land Cost :</strong> ' . round($land_cost->cost) . '</td>';
     $html .= '<td width="35%"><strong> Purchase Cost :</strong> ' . round($project_details->purchase_cost) . '</td></tr></table><br />';
     $html .= '<br /><br />';
     $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
     $pdf->Output('receipt.pdf', 'I');
 }
Example #16
0
 public function tax_continuous_type4($id = null, $year = null)
 {
     if (Session::get('level') != '') {
         $y = Input::get('y3');
         if ($y != '') {
             $year = $y;
             $id = 'all';
         }
         $pdf = new TCPDF();
         $pdf->SetPrintHeader(false);
         $pdf->SetPrintFooter(false);
         $n = DB::select('select * from s_general_data');
         foreach ($n as $k) {
             $name = $k->name;
             $address = $k->address;
             $address2 = $k->address2;
             $tax_id2 = $k->tax_id2;
             $director = $k->director;
         }
         $sql = ' select concat(n.pname,"",n.fname," ",n.lname) as name, s.cid, s.tax_id,sum(s.salary+s.r_other) as salary, sum(s.r_c) as r_c, sum(s.special_m+s.pts+s.pts2) as special, sum(s.tax) as tax ,sum(s.kbk) as kbk from s_salary_ocsc_detail s left join n_datageneral n on n.cid=s.cid left join n_position_salary p on p.cid=n.cid where  s.cid=5350400051484  and  year(s.order_date)=' . $year . ' group by s.cid order by n.datainfoID asc ';
         $result = DB::select($sql);
         foreach ($result as $key) {
             $pdf->AddPage('P', 'A4');
             $pdf->SetFont('freeserif', 'B', 11, '', true);
             $pdf->MultiCell(185, 5, 'เลขที่ งป. ........................./ ' . ($year == 'null' ? $this->yearThai() : $year + 543), 0, 'R', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 16, '', true);
             $pdf->SetY(25);
             $pdf->SetX(18);
             $pdf->MultiCell(177, 5, 'หนังสือรับรองการหักภาษี ณ ที่จ่าย', 0, 'C', 0, 1, '', '', true);
             $pdf->SetY(34);
             $pdf->SetX(18);
             $pdf->MultiCell(177, 5, 'ตามมาตรา 50 ทวิ แห่งประมวลรัษฎากร', 0, 'C', 0, 1, '', '', true);
             //===== แนวตั้ง =====//
             $linever1 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(18, 190, 18, 50, $linever1);
             $linever2 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(80, 190, 80, 50, $linever2);
             $linever3 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(110, 190, 110, 50, $linever3);
             $linever4 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(135, 190, 135, 50, $linever4);
             $linever5 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(165, 190, 165, 50, $linever5);
             $linever6 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(195, 190, 195, 50, $linever6);
             //===== แนวนอน =====//
             $linetop = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(18, 50, 195, 50, $linetop);
             $linetop2 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(80, 63, 195, 63, $linetop2);
             $linetop3 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(18, 120, 80, 120, $linetop3);
             $linetop4 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(80, 180, 195, 180, $linetop4);
             $linetop5 = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(0, 0, 0));
             $pdf->Line(18, 190, 195, 190, $linetop5);
             //======= text in box 1 ========//
             $pdf->SetFont('freeserif', '', 13, '', true);
             $pdf->SetY(52);
             $pdf->SetX(19);
             $pdf->MultiCell(62, 5, 'ชื่อและที่อยู่ของผู้มีหน้าที่หักภาษี ณ ที่จ่าย บุคคลคณะบุคคล นิติบุคคล ส่วนราชการ องค์การ รัฐวิสาหกิจ ฯลฯ ', 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 13, '', true);
             $pdf->SetY(82);
             $pdf->SetX(19);
             $pdf->MultiCell(62, 5, $address2, 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 13, '', true);
             $pdf->SetY(105);
             $pdf->SetX(19);
             $pdf->MultiCell(40, 5, $tax_id2, 0, 'L', 0, 1, '', '', true);
             //======= text in box 2 ========//
             $pdf->SetFont('freeserif', '', 13, '', true);
             $pdf->SetY(122);
             $pdf->SetX(19);
             $pdf->MultiCell(62, 5, 'ชื่อและที่อยู่ของผู้ถูกหักภาษี ณ ที่จ่าย', 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 12, '', true);
             $pdf->SetY(137);
             $pdf->SetX(21);
             $pdf->MultiCell(59, 5, $key->name, 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', '', 13, '', true);
             $pdf->SetY(145);
             $pdf->SetX(19);
             $pdf->MultiCell(62, 5, $address, 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 13, '', true);
             $pdf->SetY(165);
             $pdf->SetX(19);
             $pdf->MultiCell(62, 5, 'เลขประจำตัวผู้เสียภาษีของผู้ถูกหักภาษี ณ ที่จ่าย', 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', '', 12, '', true);
             $pdf->SetY(178);
             $pdf->SetX(22);
             $pdf->MultiCell(62, 5, $key->cid, 0, 'L', 0, 1, '', '', true);
             //======= text in box 3 header content ========//
             $pdf->SetFont('freeserif', 'B', 13, '', true);
             $pdf->SetY(54);
             $pdf->SetX(83);
             $pdf->MultiCell(32, 5, 'เงินได้ที่จ่าย', 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 13, '', true);
             $pdf->SetY(54);
             $pdf->SetX(111);
             $pdf->MultiCell(32, 5, 'ปีภาษีที่จ่าย', 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 13, '', true);
             $pdf->SetY(54);
             $pdf->SetX(138);
             $pdf->MultiCell(32, 5, 'จำนวนเงิน', 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 13, '', true);
             $pdf->SetY(54);
             $pdf->SetX(167);
             $pdf->MultiCell(32, 5, 'ภาษีที่หักไว้', 0, 'L', 0, 1, '', '', true);
             //============= text in content ================//
             $pdf->SetFont('freeserif', '', 12, '', true);
             //-----col 1
             $pdf->SetY(70);
             $pdf->SetX(80);
             $pdf->MultiCell(30, 5, 'เงินเดือน ค่าจ้าง บำนาญ เบี้ยเลี้ยง โบนัส ตามมาตรา 40(1)', 0, 'L', 0, 1, '', '', true);
             $pdf->SetY(95);
             $pdf->SetX(80);
             $pdf->MultiCell(31, 5, 'เงินประจำตำแหน่ง', 0, 'L', 0, 1, '', '', true);
             $pdf->SetY(104);
             $pdf->SetX(80);
             $pdf->MultiCell(27, 5, 'เงินค่าตอบแทนพิเศษ พตส ค่าครองชีพ', 0, 'L', 0, 1, '', '', true);
             //-----col 2
             $pdf->SetY(70);
             $pdf->SetX(116);
             $pdf->MultiCell(31, 5, $year == 'null' ? $this->yearThai() : $year + 543, 0, 'L', 0, 1, '', '', true);
             //-----col 3
             $pdf->SetY(70);
             $pdf->SetX(135);
             $pdf->MultiCell(30, 5, number_format($key->salary, 2), 0, 'R', 0, 1, '', '', true);
             $pdf->SetY(95);
             $pdf->SetX(135);
             $pdf->MultiCell(30, 5, number_format($key->r_c, 2), 0, 'R', 0, 1, '', '', true);
             $pdf->SetY(104);
             $pdf->SetX(135);
             $pdf->MultiCell(30, 5, number_format($key->special, 2), 0, 'R', 0, 1, '', '', true);
             //-----col 4
             $pdf->SetY(70);
             $pdf->SetX(165);
             $pdf->MultiCell(30, 5, number_format($key->tax, 2), 0, 'R', 0, 1, '', '', true);
             //============= text in box 4 footer sum ============//
             $pdf->SetFont('freeserif', 'B', 13, '', true);
             $pdf->SetY(182);
             $pdf->SetX(89);
             $pdf->MultiCell(32, 5, 'รวม', 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', '', 12, '', true);
             $pdf->SetY(182);
             $pdf->SetX(135);
             $pdf->MultiCell(30, 5, number_format($key->salary + $key->special + $key->r_c, 2), 0, 'R', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', '', 12, '', true);
             $pdf->SetY(182);
             $pdf->SetX(165);
             $pdf->MultiCell(30, 5, number_format($key->tax, 2), 0, 'R', 0, 1, '', '', true);
             //============= text footer ================//
             $pdf->SetFont('freeserif', '', 12, '', true);
             $pdf->SetY(195);
             $pdf->SetX(22);
             $pdf->MultiCell(32, 5, 'ผู้จ่ายเงิน', 0, 'L', 0, 1, '', '', true);
             $pdf->SetY(195);
             $pdf->SetX(39);
             $pdf->MultiCell(5, 5, '', 1, 'L', 0, 1, '', '', true);
             $pdf->SetY(195);
             $pdf->SetX(44);
             $pdf->MultiCell(30, 5, '(1) หัก ณ ที่จ่าย', 0, 'L', 0, 1, '', '', true);
             $pdf->SetY(195);
             $pdf->SetX(73);
             $pdf->MultiCell(5, 5, '', 1, 'L', 0, 1, '', '', true);
             $pdf->SetY(195);
             $pdf->SetX(78);
             $pdf->MultiCell(35, 5, '(2) ออกให้ตลอดไป', 0, 'L', 0, 1, '', '', true);
             $pdf->SetY(195);
             $pdf->SetX(112);
             $pdf->MultiCell(5, 5, '', 1, 'L', 0, 1, '', '', true);
             $pdf->SetY(195);
             $pdf->SetX(117);
             $pdf->MultiCell(35, 5, '(3) ออกให้ครั้งเดียว', 0, 'L', 0, 1, '', '', true);
             $pdf->SetY(205);
             $pdf->SetX(39);
             $pdf->MultiCell(5, 5, ' /', 1, 'L', 0, 1, '', '', true);
             $pdf->SetY(205);
             $pdf->SetX(44);
             $pdf->MultiCell(100, 5, '(4) เงินสบทบกองทุนประกันสังคม ' . '  ' . number_format($key->kbk, 2) . ' บาท', 0, 'L', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', 'B', 12, '', true);
             $pdf->SetY(220);
             $pdf->SetX(18);
             $pdf->MultiCell(177, 5, 'ข้าพเจ้าขอรับรองว่า ข้อความและตัวเลขดังกล่าวข้างต้นนี้ถูกต้องตามความเป็นจริงทุกประการ', 0, 'R', 0, 1, '', '', true);
             $pdf->SetFont('freeserif', '', 12, '', true);
             $pdf->SetY(235);
             $pdf->SetX(32);
             $pdf->MultiCell(170, 5, 'ลงชื่อ...........................................................ผู้มีหน้าที่หักภาษี ณ ที่จ่าย', 0, 'C', 0, 1, '', '', true);
             $pdf->SetY(245);
             $pdf->SetX(32);
             $pdf->MultiCell(140, 5, $director, 0, 'C', 0, 1, '', '', true);
             $pdf->SetY(255);
             $pdf->SetX(32);
             $pdf->MultiCell(140, 5, 'ทันตแพทย์เชี่ยวชาญ ปฎิบัติราชการแทน', 0, 'C', 0, 1, '', '', true);
             $pdf->SetY(265);
             $pdf->SetX(32);
             $pdf->MultiCell(140, 5, 'ผู้อำนวยการโรงพยาบาลโนนไทย', 0, 'C', 0, 1, '', '', true);
         }
         $filename = storage_path() . '/report_tax_continuous_emp4.pdf';
         // Response::download($filename);
         $contents = $pdf->output($filename, 'I');
         $headers = array('Content-Type' => 'application/pdf');
         return Response::make($contents, 200, $headers);
     } else {
         return View::make('login.index');
     }
 }
 function final_bill($customer_file_id)
 {
     $this->load->library('form_validation');
     $this->form_validation->set_rules('due_date', 'Due Date', 'trim|required');
     if ($this->form_validation->run() == FALSE) {
         $data['customer_file_id'] = $customer_file_id;
         $this->load->view('customer_file/final_bill', $data);
     } else {
         $due_date = $this->input->post('due_date');
         $due_date_db = date('Y-m-d', strtotime($due_date));
         $show_payment = $this->input->post('show_payment');
         $show_tax = $this->input->post('show_tax');
         $show_dpc = $this->input->post('show_dpc');
         $show_discount = $this->input->post('show_discount');
         $this->load->library('Pdf');
         $this->load->model(array('payment_schedule_customer_model', 'receipt_model', 'discount_model'));
         $this->db->select('contact.name as customer_name,project.name as project_name,availability_chart_unit.unit_name as unit_name,' . 'customer_file.purchase_cost,customer_file.area,customer_file.rate');
         $this->db->from('customer_file');
         $this->db->join('contact', 'customer_file.customer_id=contact.id');
         $this->db->join('project', 'project.id=customer_file.project_id');
         $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id');
         $this->db->where('customer_file.id', $customer_file_id);
         $project_details = $this->db->get()->first_row();
         $land_cost = $this->db->select('cost')->where(array('customer_file_id' => $customer_file_id, 'cost_head_id' => '14'))->get('customer_file_unit_costing')->first_row();
         $this->db->select('company.name,project.project_type');
         $this->db->from('company');
         $this->db->join('project', 'project.company_id=company.id');
         $this->db->join('customer_file', 'customer_file.project_id=project.id');
         $this->db->where('customer_file.id', $customer_file_id);
         $company_details = $this->db->get()->first_row();
         $this->db->select('receipt_split_up.amount as splitup_amount,payment_schedule_customer.installment_name,' . 'payment_schedule_customer.dpc_interest,payment_schedule_customer.dpc_grace_period,' . 'payment_schedule_customer.due_date,payment_schedule_customer.due_amount,receipt.date_payment,' . 'receipt.receipt_number');
         $this->db->from('receipt_split_up');
         $this->db->join('receipt', 'receipt.id=receipt_split_up.receipt_id');
         $this->db->join('payment_schedule_customer', 'payment_schedule_customer.id=receipt_split_up.installment_id');
         $this->db->where('payment_schedule_customer.customer_file_id', $customer_file_id);
         $this->db->where('receipt_split_up.amount >', 0);
         $paid_amout_details = $this->db->get()->result();
         $actual_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_actual($customer_file_id);
         $additional_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_additional($customer_file_id);
         $receipts = $this->receipt_model->list_cleared_receipt_customer_file($customer_file_id);
         if ($show_discount == 1) {
             $discounts = $this->discount_model->list_discount_customer_file($customer_file_id);
             $htmldis = '</br /><br /></br /><br /><h3 style="padding: 10px;  text-align:center"><u>Discount </u></h3>';
             $htmldis .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">';
             $htmldis .= '<tr><td width="40"><b>No.</b></td><td width="110"><b>Date</b></td><td width="110"><b>Amount</b></td><td width="377"><b>Remarks</b></td></tr>';
             $nd = 1;
             $total_discount = 0;
             foreach ($discounts as $discount) {
                 $total_discount += $discount->amount;
                 $htmldis .= '<tr><td>' . $nd . '</td><td>' . date('d-m-Y', strtotime($discount->date)) . '</td>' . '<td>' . number_format($discount->amount) . '</td><td>' . $discount->remarks . '</td></tr>';
                 $nd++;
             }
             $htmldis .= '<tr><td></td><td></td><td>' . number_format($total_discount) . '</td><td></td></tr>';
             $htmldis .= '</table></br /><br />';
             $htmldis .= '<table>';
             $htmldis .= '<tr>';
             $htmldis .= '<td><strong>Total Discount : </strong>' . number_format($total_discount) . '</td>';
             $htmldis .= '</tr>';
             $htmldis .= '</table><br /><br />';
         }
         $this->db->select('tax_type.name,tax_master.id');
         $this->db->from('tax_type');
         $this->db->join('tax_master', 'tax_master.tax_type_id=tax_type.id');
         $this->db->join('customer_file_tax', 'customer_file_tax.tax_id=tax_master.id');
         $this->db->where('customer_file_tax.customer_file_id', $customer_file_id);
         $customer_tax = $this->db->get()->result();
         $crm_settings = $this->db->get('crm_settings')->first_row();
         $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
         $pdf->SetCreator(PDF_CREATOR);
         $pdf->SetTitle('Receipt');
         //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255));
         $pdf->SetPrintFooter(false);
         $pdf->setPrintHeader(false);
         //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
         //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
         $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
         $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
         //$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
         //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
         $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
         if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
             require_once dirname(__FILE__) . '/lang/eng.php';
             $pdf->setLanguageArray($l);
         }
         $pdf->setFontSubsetting(true);
         $pdf->SetFont('dejavusans', '', 8, '', true);
         $pdf->AddPage();
         $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true);
         $style = array('width' => 0.1, 'color' => array(0, 0, 0));
         $pdf->Line(0, 25, 220, 25, $style);
         $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Final Bill </h2>', 0, 1, 0, true, '', true);
         $style = array('width' => 0.1, 'color' => array(0, 0, 0));
         $pdf->Line(0, 35, 220, 35, $style);
         $html = '<br /><br />';
         $html .= '<table cellpadding="5" ><tr><td width="448"><strong> Customer Name : </strong>' . $project_details->customer_name . '</td>';
         $html .= '<td><strong> Date :</strong> ' . $due_date . '</td></tr>';
         $html .= '<tr><td><strong> Project  :</strong> ' . $project_details->project_name . '</td>';
         if ($company_details->project_type == 1) {
             $html .= '<td><strong> Flat No :</strong> ' . $project_details->unit_name . '</td></tr>';
         } else {
             $html .= '<td><strong> Villa No :</strong> ' . $project_details->unit_name . '</td></tr>';
         }
         $html .= '<br /><br /><br />';
         foreach ($actual_payment_schedule as $schedule) {
             $total_due_amount += $schedule->due_amount;
             $ttax = 0;
             $ttax_bal = 0;
             foreach ($customer_tax as $cs2) {
                 $tax_amount = 0;
                 $tax_amount_bal = 0;
                 if ($schedule->status == 1) {
                     if ($schedule->due_amount - $schedule->amount_paid == 0) {
                         $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                         $this->db->from('receipt_split_up_tax');
                         $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                         $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                         $applicale_tax = $this->db->get()->first_row();
                         if ($applicale_tax->tax_amount) {
                             $ttax += $applicale_tax->tax_amount;
                             $total_tax[$cs2->id] += $applicale_tax->tax_amount;
                         } else {
                         }
                     } elseif ($schedule->amount_paid == 0) {
                         $this->db->select('tax_slab.tax_percentage as tax_percentage');
                         $this->db->from('tax_slab');
                         $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                         $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $due_date_db, 'to_date >=' => $due_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type));
                         $applicale_tax = $this->db->get()->first_row();
                         if (!empty($applicale_tax->tax_percentage)) {
                             $tax_amount = $schedule->due_amount / 100 * $applicale_tax->tax_percentage;
                             $ttax += $tax_amount;
                         }
                         if (!empty($tax_amount)) {
                             $total_tax[$cs2->id] += $tax_amount;
                         } else {
                         }
                     } else {
                         $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                         $this->db->from('receipt_split_up_tax');
                         $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                         $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                         $applicale_tax_paid = $this->db->get()->first_row();
                         $this->db->select('tax_slab.tax_percentage as tax_percentage');
                         $this->db->from('tax_slab');
                         $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                         $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $due_date_db, 'to_date >=' => $due_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type));
                         $tax_percentage_balance = $this->db->get()->first_row();
                         $tax_amount_balance = ($schedule->due_amount - $schedule->amount_paid) / 100 * $tax_percentage_balance->tax_percentage;
                         $applicale_tax_amount = $applicale_tax_paid->tax_amount + $tax_amount_balance;
                         $ttax += $applicale_tax_amount;
                         $total_tax[$cs2->id] += $applicale_tax_amount;
                     }
                 }
             }
             $total_due_tax_amount += $schedule->due_amount + $ttax;
             $n++;
         }
         foreach ($customer_tax as $cs3) {
             $tt_tax += $total_tax[$cs3->id];
         }
         $total_due_tax_amount;
         ////////////////////////////////////////////////////////////////////////////////////////////////
         $total_due_tax_amount2 = 0;
         if (!empty($additional_payment_schedule)) {
             $html2 .= '<h4 style="padding: 10px;"><strong>Additional Cost</strong></h4>';
             $html2 .= '<table border="1" cellpadding="5" cellspacing="0" width="100%">';
             $html2 .= '<thead>';
             $html2 .= '<tr>';
             $html2 .= '<th>No.</th>';
             $html2 .= '<th>Name</th>';
             $html2 .= '<th data-toggle="tooltip" data-placement="top" title="Principle Amount Due">Due Amount</th>       ';
             foreach ($customer_tax as $cs) {
                 $html2 .= '<th>' . $cs->name . '</th>   ';
             }
             $html2 .= ' <th>Total </th>';
             $html2 .= '</tr>';
             $html2 .= '</thead>';
             $html2 .= '<tbody>';
             $total_due_amount2 = 0;
             $total_balance2 = 0;
             $total_tax = array();
             foreach ($customer_tax as $cs20) {
                 $total_tax2[$cs20->id] = 0;
             }
             $total_paid1 = 0;
             $n = 1;
             foreach ($additional_payment_schedule as $schedule_additional) {
                 $total_due_amount2 += $schedule_additional->due_amount;
                 $html2 .= '<tr >';
                 $html2 .= '<td>' . $n . '</td>';
                 $html2 .= '<td>' . $schedule_additional->installment_name . '</td>';
                 $html2 .= ' <td>' . number_format($schedule_additional->due_amount) . '</td>';
                 $ttax = 0;
                 foreach ($customer_tax as $cs2) {
                     $tax_amount = 0;
                     $html2 .= '<td>';
                     $this->db->select('tax_slab.tax_percentage as tax_percentage');
                     $this->db->from('tax_slab');
                     $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                     $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => date('Y-m-d'), 'to_date >=' => date('Y-m-d'), 'tax_slab_cost_head.cost_head_id' => $schedule_additional->payment_type));
                     $applicale_tax = $this->db->get()->first_row();
                     if (!empty($applicale_tax->tax_percentage)) {
                         $tax_amount = $schedule_additional->due_amount / 100 * $applicale_tax->tax_percentage;
                         $ttax += $tax_amount;
                     }
                     if (!empty($tax_amount)) {
                         $html2 .= '<span>' . number_format($tax_amount) . '</span>';
                         $total_tax2[$cs2->id] += $tax_amount;
                     } else {
                         $html2 .= '<span>0</span>';
                     }
                     $html2 .= '</td>';
                 }
                 $html2 .= '<td>';
                 $html2 .= '<span data-toggle="modal" data-target="#total_splitup">';
                 $html2 .= '<span>' . number_format($schedule_additional->due_amount + $ttax) . '</span>';
                 $total_due_tax_amount2 += $schedule_additional->due_amount + $ttax;
                 $html2 .= '</span>';
                 $html2 .= '</td>';
                 $html2 .= '</tr>';
                 $n++;
             }
             $html2 .= '</tbody>';
             $html2 .= '<tfoot>';
             $html2 .= '<tr style="font-weight: bolder">';
             $html2 .= '<td colspan="2"></td>        ';
             $html2 .= '<td>' . number_format($total_due_amount2) . '</td>';
             foreach ($customer_tax as $cs7) {
                 $html2 .= '<td>' . number_format($total_tax2[$cs7->id]) . '</td>';
             }
             $html2 .= '<td>' . number_format($total_due_tax_amount2) . '</td>';
             $html2 .= '<td></td>';
             $html2 .= '</tr>';
             $html2 .= '</tfoot>';
             $html2 .= '</table>';
         }
         //////////////////////////////////////////////////////////////////////////
         if (empty($total_due_tax_amount2)) {
             $total_due_tax_amount2 = 0;
         }
         if (empty($tt_tax2)) {
             $tt_tax2 = 0;
         }
         if (empty($total_due_amount2)) {
             $total_due_amount2 = 0;
         }
         $total_amt22 = 0;
         foreach ($receipts as $receipt22) {
             $total_amt22 += $receipt22->amount_paid;
         }
         $html .= '<table  cellpadding="8" align="Left" border="1"><tr>';
         $html .= '<td><strong>Total Cost</strong><br /><br />' . ' Total Agreement Value : ' . number_format($total_due_amount) . '<br /><br />' . ' Taxes : ' . number_format($tt_tax) . '<br /><br />' . ' Additional Charges : ' . number_format($total_due_tax_amount2) . '<br />' . '</td>';
         $html .= '<td> <strong>Rs. ' . number_format($total_due_amount + $tt_tax + $total_due_tax_amount2) . '</strong></td>';
         $html .= '</tr>';
         $html .= '<tr>';
         $html .= '<td><strong>Total Receipts </strong></td>';
         $html .= '<td><strong>Rs. ' . number_format($total_amt22) . '</strong></td>';
         $html .= '</tr>';
         $html .= '</table><br /><br /><br />';
         if ($show_discount == 1) {
             $html .= '<strong>Gross Balance : </strong> Rs.' . number_format($total_due_amount + $tt_tax + $total_due_tax_amount2 - $total_amt22);
             $html .= '<br /><br /><strong>Discount : </strong> Rs.' . number_format($total_discount);
             $html .= '<br /><br /><strong>Net Balance : </strong> Rs.' . number_format($total_due_amount + $tt_tax + $total_due_tax_amount2 - ($total_amt22 + $total_discount));
         } else {
             $html .= '<strong>Net Balance : </strong> Rs.' . number_format($total_due_amount + $tt_tax + $total_due_tax_amount2 - $total_amt22);
         }
         $html .= '<br /><br /><br />';
         $html .= '<strong>For ' . $company_details->name . ' </strong>';
         $html .= '<br /><br /><br />';
         $html .= '<strong>Authorised Signature</strong>';
         $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
         $pdf->AddPage();
         $html = '';
         $this->db->select("cost_head.name as cost_head,SUM(`customer_file_unit_costing`.`cost`) as cost," . "cost_head.is_auto_calculate,cost_head.is_included");
         $this->db->from('customer_file_unit_costing');
         $this->db->join('cost_head', 'customer_file_unit_costing.cost_head_id=cost_head.id');
         $this->db->where('customer_file_unit_costing.customer_file_id', $customer_file_id);
         $this->db->group_by('cost_head.id');
         $unit_costs = $this->db->get()->result();
         $html .= '<strong>Total Agreement Value</strong><br /></br />';
         $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">';
         $ttcst = 0;
         foreach ($unit_costs as $cost) {
             $html .= '<tr>';
             $html .= '<td>' . $cost->cost_head . '</td>';
             if ($cost->is_auto_calculate) {
                 $inc = 0;
                 foreach ($unit_costs as $cost2) {
                     if ($cost2->is_included) {
                         $inc += $cost2->cost;
                     }
                 }
                 $html .= '<td>' . number_format($cost->cost - $inc) . '</td>';
                 $ttcst += $cost->cost - $inc;
             } else {
                 $html .= '<td>' . number_format($cost->cost) . '</td>';
                 $ttcst += $cost->cost;
             }
             $html .= '</tr>';
         }
         $html .= '<tr>';
         $html .= '<td></td>';
         $html .= '<td><strong> Rs. ' . number_format($ttcst) . '</strong></td>';
         $html .= '</tr>';
         $html .= '</table><br /><br /><br /><br />';
         $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
         $pdf->writeHTMLCell(0, 0, '', '', $html2, 0, 1, 0, true, '', true);
         if (!empty($receipts) && $show_payment == 1) {
             $pdf->AddPage();
             $html = '';
             $html .= '<table cellpadding="5" border="0" cellspacing="0" width="100%" nobr="true">';
             $html .= '<tr><td colspan="7" style="text-align:center;" ><u><strong>Payments Received as on Date</strong></u></td></tr>';
             $html .= '<tr><td  border="1"><b>No.</b></td><td border="1"><b>Date</b></td><td border="1"><b>Payment Type</b></td><td border="1"><b>Inv No</b></td><td border="1"><b>Principle Amount</b></td>';
             $html .= '<td border="1"><b>Total Tax</b></td><td border="1"><b>Total Amount</b></td></tr>';
             $total_pri = 0;
             $total_tx = 0;
             $total_amt = 0;
             foreach ($receipts as $b => $receipt) {
                 $total_pri += $receipt->principle_amount;
                 $total_tx += $receipt->amount_paid - $receipt->principle_amount;
                 $total_amt += $receipt->amount_paid;
                 $html .= '<tr>';
                 $html .= '<td border="1">' . ($b + 1) . '</td>';
                 $html .= '<td border="1">' . $receipt->date_payment . '</td>';
                 $html .= '<td border="1">' . $receipt->payment_type . '</td>';
                 $html .= '<td border="1">' . $receipt->receipt_number . '</td>';
                 $html .= '<td border="1">' . number_format($receipt->principle_amount) . '</td>';
                 $html .= '<td border="1">' . number_format($receipt->amount_paid - $receipt->principle_amount) . '</td>';
                 $html .= '<td border="1">' . number_format($receipt->amount_paid) . '</td>';
                 $html .= '</tr>';
             }
             $html .= '<tr style="font-weight: bolder">';
             $html .= ' <td colspan="4" border="1"></td>';
             $html .= ' <td border="1">' . $total_pri . '</td>';
             $html .= '  <td border="1">' . $total_tx . '</td>';
             $html .= '  <td border="1">' . $total_amt . '</td>';
             $html .= '  </tr>';
             $html .= ' </table><br /><br />';
             $html .= '<table>';
             $html .= '<tr>';
             $html .= '<td><strong>Total Due : </strong>' . number_format($total_due_tax_amount2 + $total_due_tax_amount) . '</td>';
             $html .= '<td><strong>Amount Received : </strong>' . number_format($total_amt) . '</td>';
             if ($total_due_tax_amount2 + $total_due_tax_amount - $total_amt <= 0) {
                 $html .= '<td><strong>Balance Due : </strong>' . number_format('0', 2) . '</td>';
             } else {
                 $html .= '<td><strong>Balance Due : </strong>' . number_format($total_due_tax_amount2 + $total_due_tax_amount - $total_amt) . '</td>';
             }
             $html .= '</tr>';
             $html .= '</table><br /><br />';
             if ($total_due_tax_amount2 + $total_due_tax_amount - $total_amt <= 0) {
                 $html .= '<table>';
                 $html .= '<tr>';
                 $html .= '<td><strong>Advance Payment : </strong>' . number_format($total_amt - ($total_due_tax_amount2 + $total_due_tax_amount)) . '</td>';
                 $html .= '</tr>';
                 $html .= '</table>';
             }
             $html .= '<br /><br /><br /><br />';
             $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
         }
         //detailed tax report
         if ($show_tax == 1) {
             if (!empty($customer_tax)) {
                 foreach ($customer_tax as $tx_det) {
                     $html = '';
                     $html .= '<strong>' . $tx_det->name . ' on Collected Amount</strong><br /></br />';
                     $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">';
                     $html .= '<tr>';
                     $html .= '<td><b>No.</b></td>';
                     $html .= '<td><b>Inv No</b></td>';
                     $html .= '<td> <b>Date</b></td>';
                     $html .= '<td><b>Amount</b></td>';
                     $html .= '<td><b>' . $tx_det->name . ' %</b></td>';
                     $html .= '<td><b>' . $tx_det->name . '</b></td>';
                     $html .= '</tr>';
                     $count = 1;
                     $tot_principle_amount = 0;
                     $tot_tax_amount = 0;
                     foreach ($receipts as $b => $rcpt) {
                         $this->db->select('SUM(`receipt_split_up_tax`.`tax_amount`) as tax_amount');
                         $this->db->from('receipt');
                         $this->db->join('receipt_split_up', 'receipt_split_up.receipt_id=receipt.id');
                         $this->db->join('receipt_split_up_tax', 'receipt_split_up_tax.receipt_split_up_id=receipt_split_up.id');
                         $this->db->join('tax_master', 'tax_master.id=receipt_split_up_tax.tax_id');
                         $this->db->join('tax_type', 'tax_type.id=tax_master.tax_type_id');
                         $this->db->where('tax_type.id', $tx_det->id);
                         $this->db->where('receipt.id', $rcpt->id);
                         $tax_data = $this->db->get()->first_row();
                         $html .= '<tr>';
                         $html .= '<td>' . $count . '</td>';
                         $html .= '<td>' . $rcpt->receipt_number . '</td>';
                         $html .= '<td>' . $rcpt->date_payment . '</td>';
                         $html .= '<td>' . number_format($rcpt->principle_amount) . '</td>';
                         $html .= '<td>' . $tax_data->tax_amount / $rcpt->principle_amount * 100 . '</td>';
                         $html .= '<td>' . number_format($tax_data->tax_amount) . '</td>';
                         $html .= '</tr>';
                         $count++;
                         $tot_principle_amount += $rcpt->principle_amount;
                         $tot_tax_amount += $tax_data->tax_amount;
                     }
                     $html .= '<tr>';
                     $html .= '<td colspan="3"></td>';
                     $html .= '<td><strong>' . number_format($tot_principle_amount) . '</strong></td>';
                     $html .= '<td></td>';
                     $html .= '<td><strong>' . number_format($tot_tax_amount) . '</strong></td>';
                     $html .= '</tr>';
                     $html .= '</table><br /><br /><br /><br />';
                     if (!empty($actual_payment_schedule)) {
                         $html .= '<strong>' . $tx_det->name . ' on  Balance Due Amount - Actual Due</strong><br /></br />';
                         $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">';
                         $html .= '<tr>';
                         $html .= '<td><b>No.</b></td>';
                         $html .= '<td><b>Inst Name </b></td>';
                         $html .= '<td> <b>Due Date</b></td>';
                         $html .= '<td><b>Due Amt </b></td>';
                         $html .= '<td><b>Due Amt Paid </b></td>';
                         $html .= '<td><b>Due Amt Balance </b></td>';
                         $html .= '<td><b>' . $tx_det->name . ' %</b></td>';
                         $html .= '<td><b>' . $tx_det->name . '</b></td>';
                         $html .= '</tr>';
                         $count = 1;
                         $total_due_amount_actual = 0;
                         $total_amount_paid_actual = 0;
                         $total_balance_actual = 0;
                         $total_tax_amount_actual = 0;
                         foreach ($actual_payment_schedule as $schedule) {
                             if ($schedule->status == 1) {
                                 if ($schedule->due_amount - $schedule->amount_paid != 0) {
                                     $balance_amount = $schedule->due_amount - $schedule->amount_paid;
                                     $this->db->select('tax_slab.tax_percentage as tax_percentage');
                                     $this->db->from('customer_file_tax');
                                     $this->db->join('tax_master', 'tax_master.id=customer_file_tax.tax_id');
                                     $this->db->join('tax_slab', 'tax_slab.tax_master_id=tax_master.id');
                                     $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                                     $this->db->where('tax_slab.tax_type_id', $tx_det->id);
                                     $this->db->where('customer_file_tax.customer_file_id', $customer_file_id);
                                     $this->db->where('tax_slab.from_date <=', $due_date_db);
                                     $this->db->where('tax_slab.to_date >=', $due_date_db);
                                     $this->db->where('tax_slab_cost_head.cost_head_id', $schedule->payment_type);
                                     $applicale_tax = $this->db->get()->first_row();
                                     if (!empty($applicale_tax->tax_percentage)) {
                                         $tax_amount = $balance_amount / 100 * $applicale_tax->tax_percentage;
                                         $ttax += $tax_amount;
                                     }
                                     $html .= '<tr>';
                                     $html .= '<td>' . $count . '</td>';
                                     $html .= '<td>' . $schedule->installment_name . '</td>';
                                     $html .= '<td>' . $schedule->due_date . '</td>';
                                     $html .= '<td>' . number_format($schedule->due_amount) . '</td>';
                                     $html .= '<td>' . number_format($schedule->amount_paid) . '</td>';
                                     $html .= '<td>' . number_format($schedule->due_amount - $schedule->amount_paid) . '</td>';
                                     $html .= '<td>' . number_format($applicale_tax->tax_percentage, 2) . ' %</td>';
                                     $html .= '<td>' . number_format($tax_amount) . '</td>';
                                     $html .= '</tr>';
                                     $total_due_amount_actual += $schedule->due_amount;
                                     $total_amount_paid_actual += $schedule->amount_paid;
                                     $total_balance_actual += $schedule->due_amount - $schedule->amount_paid;
                                     $total_tax_amount_actual += $tax_amount;
                                 }
                             }
                             $count++;
                         }
                         $html .= '<tr>';
                         $html .= '<td colspan="3"></td>';
                         $html .= '<td><strong>' . number_format($total_due_amount_actual) . '</strong></td>';
                         $html .= '<td><strong>' . number_format($total_amount_paid_actual) . ' </strong></td>';
                         $html .= '<td><strong>' . number_format($total_balance_actual) . '</strong></td>';
                         $html .= '<td><strong> </strong></td>';
                         $html .= '<td><strong>' . number_format($total_tax_amount_actual) . ' </strong></td>';
                         $html .= '</tr>';
                         $html .= '</table><br /><br /><br /><br />';
                     }
                     if (!empty($additional_payment_schedule)) {
                         $html .= '<strong>' . $tx_det->name . ' on  Balance Due Amount - Additional Due</strong><br /></br />';
                         $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true">';
                         $html .= '<tr>';
                         $html .= '<td><b>No.</b></td>';
                         $html .= '<td><b>Inst Name </b></td>';
                         $html .= '<td><b> Due Date</b></td>';
                         $html .= '<td><b>Due Amt </b></td>';
                         $html .= '<td><b>Due Amt Paid </b></td>';
                         $html .= '<td><b>Due Amt Balance </b></td>';
                         $html .= '<td><b>' . $tx_det->name . ' %</b></td>';
                         $html .= '<td><b>' . $tx_det->name . '</b></td>';
                         $html .= '</tr>';
                         $count = 1;
                         $total_due_amount_additional = 0;
                         $total_amount_paid_additional = 0;
                         $total_balance_additional = 0;
                         $total_tax_amount_additional = 0;
                         foreach ($additional_payment_schedule as $schedule_additional) {
                             $balance_amount = 0;
                             if ($schedule_additional->status == 1) {
                                 if ($schedule_additional->due_amount - $schedule_additional->amount_paid != 0) {
                                     $balance_amount = $schedule_additional->due_amount - $schedule_additional->amount_paid;
                                     $this->db->select('tax_slab.tax_percentage as tax_percentage');
                                     $this->db->from('customer_file_tax');
                                     $this->db->join('tax_master', 'tax_master.id=customer_file_tax.tax_id');
                                     $this->db->join('tax_slab', 'tax_slab.tax_master_id=tax_master.id');
                                     $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                                     $this->db->where('tax_slab.tax_type_id', $tx_det->id);
                                     $this->db->where('customer_file_tax.customer_file_id', $customer_file_id);
                                     $this->db->where('tax_slab.from_date <=', $due_date_db);
                                     $this->db->where('tax_slab.to_date >=', $due_date_db);
                                     $this->db->where('tax_slab_cost_head.cost_head_id', $schedule_additional->payment_type);
                                     $applicale_tax_additional = $this->db->get()->first_row();
                                     if (!empty($applicale_tax_additional->tax_percentage)) {
                                         $tax_amount_additional = $balance_amount / 100 * $applicale_tax_additional->tax_percentage;
                                         $ttax += $tax_amount;
                                     }
                                     $html .= '<tr>';
                                     $html .= '<td>' . $count . '</td>';
                                     $html .= '<td> ' . $schedule_additional->installment_name . '</td>';
                                     $html .= '<td>' . $schedule_additional->due_date . '</td>';
                                     $html .= '<td>' . number_format($schedule_additional->due_amount) . '</td>';
                                     $html .= '<td>' . number_format($schedule_additional->amount_paid) . '</td>';
                                     $html .= '<td>' . number_format($schedule_additional->due_amount - $schedule_additional->amount_paid) . '</td>';
                                     $html .= '<td>' . number_format($applicale_tax_additional->tax_percentage, 2) . ' %</td>';
                                     $html .= '<td>' . number_format($tax_amount_additional) . '</td>';
                                     $html .= '</tr>';
                                     $total_due_amount_additional += $schedule_additional->due_amount;
                                     $total_amount_paid_additional += $schedule_additional->amount_paid;
                                     $total_balance_additional += $schedule_additional->due_amount - $schedule_additional->amount_paid;
                                     $total_tax_amount_additional += $tax_amount;
                                 }
                             }
                             $count++;
                         }
                         $html .= '<tr>';
                         $html .= '<td colspan="3"></td>';
                         $html .= '<td><strong>' . number_format($total_due_amount_additional) . '</strong></td>';
                         $html .= '<td><strong>' . number_format($total_amount_paid_additional) . ' </strong></td>';
                         $html .= '<td><strong>' . number_format($total_balance_additional) . '</strong></td>';
                         $html .= '<td><strong> </strong></td>';
                         $html .= '<td><strong>' . number_format($total_tax_amount_additional) . ' </strong></td>';
                         $html .= '</tr>';
                         $html .= '</table><br /><br /><br /><br />';
                     }
                     $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
                 }
             }
         }
         if ($show_dpc == 1) {
             $pdf->AddPage();
             $html = '';
             $html .= '<h3 style="padding: 10px;  text-align:center"><u>DPC Due on Collected Amount</u></h3>';
             $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>';
             $html .= '<th width="28"><b>No.</b></th>';
             $html .= '<th width="104"><b>Installment Name</b></th>';
             $html .= '<th width="58"><b>Due Date</b></th>';
             $html .= '<th width="65"><b>Due Amount</b></th>';
             $html .= '<th width="65"><b>Paid Amt </b></th>';
             $html .= '<th width="58"><b>Pay Date </b></th>';
             $html .= '<th width="45"><b>Inv No</b></th>';
             $html .= '<th width="58"><b>Gr Period</b></th>';
             $html .= '<th width="53"><b>Delayed Days</b></th>';
             $html .= '<th width="44"><b>DPC % </b></th>';
             $html .= '<th width="58"><b>DPC Due </b></th>';
             $html .= '</tr>';
             $html .= '</thead><tbody>';
             $total_dpc = 0;
             foreach ($paid_amout_details as $schedule) {
                 $datetime1 = date_create($schedule->due_date);
                 $datetime2 = date_create($schedule->date_payment);
                 $interval = date_diff($datetime1, $datetime2);
                 $delayed_days = $interval->format('%R%a');
                 if ($delayed_days <= 0) {
                     $delayed_days = 0;
                 } else {
                     $delayed_days = str_replace('+', '', $delayed_days);
                 }
                 if ($delayed_days < $schedule->dpc_grace_period) {
                     $dday = 0;
                 } else {
                     if ($crm_settings->include_grace_period == 0) {
                         $dday = $delayed_days - $schedule->dpc_grace_period;
                     } else {
                         $dday = $delayed_days;
                     }
                 }
                 $dpc = $schedule->splitup_amount * $schedule->dpc_interest / 100;
                 $dpc = $dpc / 365 * $dday;
                 $total_dpc += $dpc;
                 $html .= '<tr>';
                 $html .= '<td width="28">' . $n . '</td>';
                 $html .= '<td width="104">' . $schedule->installment_name . '</td>';
                 $html .= '<td width="58">' . date('d-m-y', strtotime($schedule->due_date)) . '</td>';
                 $html .= '<td width="65">' . number_format($schedule->due_amount) . '</td>';
                 $html .= '<td width="65">' . number_format($schedule->splitup_amount) . '</td>';
                 $html .= '<td width="58">' . date('d-m-y', strtotime($schedule->date_payment)) . '</td>';
                 $html .= '<td width="45">' . $schedule->receipt_number . '</td>';
                 $html .= '<td width="58">' . $schedule->dpc_grace_period . '</td>';
                 $html .= '<td width="53">' . $delayed_days . '</td>';
                 $html .= '<td width="44">' . number_format($schedule->dpc_interest) . '</td>';
                 $html .= ' <td  width="58">';
                 $html .= '<span>' . number_format($dpc) . '</span>';
                 $html .= '</td>';
                 $html .= '</tr>';
                 $n++;
             }
             $html .= '</tbody>';
             $html .= '<tfoot>';
             $html .= '<tr style="font-weight: bolder">';
             $html .= '<td  width="578" colspan="10"></td>';
             $html .= '<td  width="58">' . number_format($total_dpc) . '</td>';
             $html .= '</tr>';
             $html .= '</tfoot>';
             $html .= '</table><br /><br />';
             $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
             $pdf->AddPage();
             $html = '';
             $html .= '<h3 style="padding: 10px;  text-align:center"><u>DPC Due on Balance Amount </u></h3>';
             $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>';
             $html .= '<th width="30"><b>No.</b></th>';
             $html .= '<th width="124"><b>Installment Name</b></th>';
             $html .= '<th width="65"><b>Due Date</b></th>';
             $html .= '<th width="70"><b>Due Amount</b></th>';
             $html .= '<th width="82"><b>Due Amount Balance</b></th>';
             $html .= '<th width="65"><b>Gr Period</b></th>';
             $html .= '<th width="65"><b>Delayed Days</b></th>';
             $html .= '<th width="65"><b>DPC % </b></th>';
             $html .= '<th width="70"><b>DPC Due </b></th>';
             $html .= '</tr>';
             $html .= '</thead><tbody>';
             $total_dpc_bal = 0;
             foreach ($actual_payment_schedule as $schedule) {
                 $balance_amt = $schedule->due_amount - $schedule->amount_paid;
                 if ($balance_amt > 0) {
                     $datetime1 = date_create($schedule->due_date);
                     $datetime2 = date_create($due_date_db);
                     $interval = date_diff($datetime1, $datetime2);
                     $delayed_days = $interval->format('%R%a');
                     if ($delayed_days <= 0) {
                         $delayed_days = 0;
                     } else {
                         $delayed_days = str_replace('+', '', $delayed_days);
                     }
                     if ($delayed_days < $schedule->dpc_grace_period) {
                         $dday = 0;
                     } else {
                         if ($crm_settings->include_grace_period == 0) {
                             $dday = $delayed_days - $schedule->dpc_grace_period;
                         } else {
                             $dday = $delayed_days;
                         }
                     }
                     $dpc = $balance_amt * $schedule->dpc_interest / 100;
                     $dpc = $dpc / 365 * $dday;
                     $total_dpc_bal += $dpc;
                     $html .= '<tr>';
                     $html .= '<td width="30">' . $n . '</td>';
                     $html .= '<td width="124">' . $schedule->installment_name . '</td>';
                     $html .= '<td width="65">' . date('d-m-y', strtotime($schedule->due_date)) . '</td>';
                     $html .= '<td width="70">' . number_format($schedule->due_amount) . '</td>';
                     $html .= '<td width="82">' . number_format($balance_amt) . '</td>';
                     $html .= '<td width="65">' . $schedule->dpc_grace_period . '</td>';
                     $html .= '<td width="65">' . $delayed_days . '</td>';
                     $html .= '<td width="65">' . number_format($schedule->dpc_interest) . '</td>';
                     $html .= ' <td  width="70">';
                     $html .= '<span>' . number_format($dpc) . '</span>';
                     $html .= '</td>';
                     $html .= '</tr>';
                     $n++;
                 }
             }
             $html .= '</tbody>';
             $html .= '<tfoot>';
             $html .= '<tr style="font-weight: bolder">';
             $html .= '<td  width="566" colspan="9"></td>';
             $html .= '<td  width="70">' . number_format($total_dpc_bal) . '</td>';
             $html .= '</tr>';
             $html .= '</tfoot>';
             $html .= '</table><br /><br />';
             $html .= '<table>';
             $html .= '<tr>';
             $html .= '<td><strong>Total DPC : </strong>' . number_format($total_dpc_bal + $total_dpc) . '</td>';
             $html .= '</tr>';
             $html .= '</table><br /><br />';
             $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
         }
         if ($show_discount == 1) {
             $pdf->writeHTMLCell(0, 0, '', '', $htmldis, 0, 1, 0, true, '', true);
         }
         //echo $html;
         //exit();
         $pdf->Output('receipt.pdf', 'I');
     }
 }
Example #18
0
function izvjestaj_prijave()
{
    require_once 'lib/tcpdf/tcpdf.php';
    global $userid, $conf_files_path;
    // Poslani parametar
    $ispit_termin = intval($_GET['ispit_termin']);
    $predmet = intval($_GET['predmet']);
    $ag = intval($_GET['ag']);
    $student = intval($_GET['student']);
    $nasa_slova = array("č" => "c", "ć" => "c", "đ" => "d", "š" => "s", "ž" => "z", "Č" => "C", "Ć" => "C", "Đ" => "D", "Š" => "S", "Ž" => "Z");
    // Odredjujemo filename
    if ($ispit_termin > 0) {
        $q5 = myquery("select p.id, p.naziv, UNIX_TIMESTAMP(it.datumvrijeme), i.akademska_godina from predmet as p, ispit as i, ispit_termin as it where it.id={$ispit_termin} and it.ispit=i.id and i.predmet=p.id");
        $predmet = mysql_result($q5, 0, 0);
        $ag = mysql_result($q5, 0, 3);
        $filename = "prijave-" . strtr(mysql_result($q5, 0, 1), $nasa_slova) . "-" . date("d-m-Y", mysql_result($q5, 0, 2)) . ".pdf";
    } else {
        if ($predmet > 0) {
            $q5 = myquery("select naziv from predmet where id={$predmet}");
            $filename = "prijave-" . strtr(mysql_result($q5, 0, 0), $nasa_slova) . ".pdf";
        } else {
            $filename = "prijave.pdf";
        }
    }
    $upit = "SELECT o.id, o.ime, o.prezime, o.brindexa, pk.semestar, s.naziv, p.naziv, ag.naziv, ";
    // slijedi datum
    // Stampaj sve studente na terminu
    if ($ispit_termin > 0) {
        // Uzimamo datum termina
        $upit .= "UNIX_TIMESTAMP(it.datumvrijeme) from osoba as o, ispit_termin as it, student_ispit_termin as sit, student_predmet as sp, ponudakursa as pk, ispit as i, studij as s, predmet as p, akademska_godina as ag where sit.ispit_termin=it.id and sit.student=o.id and it.id={$ispit_termin} and o.id=sp.student and sp.predmet=pk.id and it.ispit=i.id and i.predmet=pk.predmet and i.akademska_godina=pk.akademska_godina and pk.studij=s.id and pk.predmet=p.id and pk.akademska_godina=ag.id order by o.prezime, o.ime";
    } else {
        if ($predmet <= 0 || $ag <= 0) {
            biguglyerror("Neispravni parametri");
            print "Da li je moguće da ste odabrali neispravan ili nepostojeći predmet?";
            return;
            // Stampaj jednog studenta
        } else {
            if ($student > 0) {
                // Uzecemo danasnji datum
                $upit .= "UNIX_TIMESTAMP(NOW()) from osoba as o, ponudakursa as pk, studij as s, predmet as p, akademska_godina as ag, student_predmet as sp where o.id={$student} and sp.student={$student} and sp.predmet=pk.id and pk.predmet={$predmet} and pk.akademska_godina={$ag} and p.id={$predmet} and ag.id={$ag} and pk.studij=s.id";
                // Sve studente koji nemaju ocjenu
            } else {
                if ($_GET['tip'] == "bez_ocjene" || $_GET['tip'] == "uslov") {
                    // Naknadno provjeravamo da li ima uslov
                    // Uzecemo danasnji datum
                    $upit .= "UNIX_TIMESTAMP(NOW()) from osoba as o, ponudakursa as pk, studij as s, predmet as p, akademska_godina as ag, student_predmet as sp where o.id=sp.student and sp.predmet=pk.id and pk.predmet={$predmet} and pk.akademska_godina={$ag} and p.id={$predmet} and ag.id={$ag} and pk.studij=s.id and (select count(*) from konacna_ocjena as ko where ko.student=o.id and ko.predmet={$predmet})=0 order by o.prezime, o.ime";
                    // Sve studente koji imaju ocjenu
                } else {
                    if ($_GET['tip'] == "sa_ocjenom") {
                        // Uzecemo danasnji datum
                        $upit .= "UNIX_TIMESTAMP(NOW()) from osoba as o, ponudakursa as pk, studij as s, predmet as p, akademska_godina as ag, student_predmet as sp where o.id=sp.student and sp.predmet=pk.id and pk.predmet={$predmet} and pk.akademska_godina={$ag} and p.id={$predmet} and ag.id={$ag} and pk.studij=s.id and (select count(*) from konacna_ocjena as ko where ko.student=o.id and ko.predmet={$predmet})>0 order by o.prezime, o.ime";
                        // Sve studente na predmetu
                    } else {
                        if ($_GET['tip'] == "sve") {
                            // Uzecemo danasnji datum
                            $upit .= "UNIX_TIMESTAMP(NOW()) from osoba as o, ponudakursa as pk, studij as s, predmet as p, akademska_godina as ag, student_predmet as sp where o.id=sp.student and sp.predmet=pk.id and pk.predmet={$predmet} and pk.akademska_godina={$ag} and p.id={$predmet} and ag.id={$ag} and pk.studij=s.id order by o.prezime, o.ime";
                            // Ovo se može desiti ako se klikne na prikaz pojedinačnog studenta, a nijedan student nije izabran
                            // (npr. ako nijedan student ne sluša predmet)
                        } else {
                            biguglyerror("Neispravni parametri");
                            print "Da li je moguće da ovaj predmet ne sluša niti jedan student?";
                            return;
                        }
                    }
                }
            }
        }
    }
    // PDF inicijalizacija
    $pdf = new TCPDF('P', 'mm', 'a5', true, 'UTF-8', false);
    $pdf->SetCreator("Zamger");
    $pdf->SetTitle('Printanje prijava');
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(0, 0, 0);
    $pdf->SetAutoPageBreak(false);
    $pdf->setLanguageArray($l);
    $pdf->SetFont('freesans', 'B', 9);
    $pdf->SetHeaderData("", 0, "", "");
    $pdf->SetPrintHeader(false);
    $pdf->setFooterMargin($fm = 0);
    $pdf->SetPrintFooter(false);
    //set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    //$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO*2.083333);
    $pdf->setJPEGQuality(100);
    // Izvršenje upita
    $q10 = myquery($upit);
    while ($r10 = mysql_fetch_row($q10)) {
        $student = $r10[0];
        $imeprezime = $r10[1] . " " . $r10[2];
        $brind = $r10[3];
        $godStudija = intval(($r10[4] + 1) / 2);
        $odsjek = $r10[5];
        $nazivPr = $r10[6];
        $skolskaGod = $r10[7];
        //	$NastavnikSl=$r10[9];
        $datumIspita = date("d. m. Y.", $r10[8]);
        //	$NastavnikPr=$r10[8];
        //	$datumPrijave=$r10[12];
        $datumPrijave = $datumIspita;
        //	$datumPolaganja=$r10[10];
        $datumPolaganja = $datumIspita;
        //	$datumUsmenog=$r10[13];
        $datumUsmenog = $datumIspita;
        //	$datumDrPar=$r10[14];
        // Ispis nastavnika
        $q33 = myquery("select osoba from angazman where predmet={$predmet} and akademska_godina={$ag} and angazman_status=1");
        if (mysql_num_rows($q33) == 1) {
            // Ako imaju dva odgovorna nastavnika, ne znam kojeg da stavim
            $id_nastavnika = mysql_result($q33, 0, 0);
            $nastavnik = tituliraj($id_nastavnika, $sa_akademskim_zvanjem = false);
        } else {
            $nastavnik = "";
        }
        // Da li ima uslov?
        if ($_GET['tip'] == "uslov") {
            // Dva parcijalna ispita
            $q35 = myquery("select count(*) from ispitocjene as io, ispit as i, komponenta as k where io.student={$student} and io.ispit=i.id and i.predmet={$predmet} and i.akademska_godina={$ag} and i.komponenta=k.id and k.tipkomponente=1 and io.ocjena>=k.prolaz");
            $parcijalnih = mysql_result($q35, 0, 0);
            // Integralni ispiti
            $q37 = myquery("select count(*) from ispitocjene as io, ispit as i, komponenta as k where io.student={$student} and io.ispit=i.id and i.predmet={$predmet} and i.akademska_godina={$ag} and i.komponenta=k.id and k.tipkomponente=2 and io.ocjena>=k.prolaz");
            $integralnih = mysql_result($q37, 0, 0);
            if ($integralnih == 1 || $parcijalnih == 2) {
                // FIXME: ovo radi samo za ETF Bologna standard
                kreirajPrijavu($pdf, $imeprezime, $brind, $godStudija, $odsjek, $nazivPr, $skolskaGod, $datumIspita, $nastavnik);
            }
        } else {
            // Da li je student polozio predmet?
            $q40 = myquery("select ocjena, UNIX_TIMESTAMP(datum_u_indeksu), datum_provjeren from konacna_ocjena where student={$student} and predmet={$predmet}");
            if (mysql_num_rows($q40) > 0) {
                $ocjena = mysql_result($q40, 0, 0);
                $datum_provjeren = mysql_result($q40, 0, 2);
                if ($datum_provjeren) {
                    $datumIspita = $datumPrijave = $datumPolaganja = $datumUsmenog = date("d. m. Y.", mysql_result($q40, 0, 1));
                }
            } else {
                $ocjena = 0;
            }
            kreirajPrijavu($pdf, $imeprezime, $brind, $godStudija, $odsjek, $nazivPr, $skolskaGod, $datumIspita, $ocjena, $nastavnik);
            //		print "$pdf, $imeprezime, $brind, $godStudija, $odsjek, $nazivPr, $skolskaGod, $datumIspita ($r10[8]), $ocjena, $nastavnik<br>\n";
        }
    }
    $pdf->Output($filename, 'I');
}
function generateNumberPatientReport($conn)
{
    global $gTEXT;
    require_once 'tcpdf/tcpdf.php';
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    $pdf->AddPage();
    $pdf->SetFillColor(255, 255, 255);
    //=====================================================National Inventory Table=======================================================
    $monthId = $_POST['MonthId'];
    $year = $_POST['YearId'];
    $countryId = $_POST['CountryId'];
    $itemGroupId = $_POST['ItemGroupId'];
    $currentYearMonth = $_POST['YearId'] . "-" . $_POST['MonthId'] . "-" . "01";
    $monthList = array('1' => 'January', '2' => 'February', '3' => 'March', '4' => 'April', '5' => 'May', '6' => 'June', '7' => 'July', '8' => 'August', '9' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');
    $sql = " SELECT ItemName, AMC, ClStock, FORMAT(MOS,1) MOS, Qty StockOnOrder, FORMAT(Qty/AMC,1) StockOnOrderMOS,\n                     (ifnull(FORMAT(MOS,1),0)+ifnull(FORMAT(Qty/AMC,1),0)) TotalMOS,a.ItemNo,TotalPatient\n                     FROM \n        \t\t\t\t(SELECT\n        \t\t\t\t t_cnm_masterstockstatus.CountryId,\n        \t\t\t\t  t_itemlist.ItemNo,\n        \t\t\t\t  t_itemlist.ItemName,\n        \t\t\t\t  SUM(t_cnm_stockstatus.AMC)    AMC,\n        \t\t\t\t  SUM(t_cnm_stockstatus.ClStock)    ClStock,\n        \t\t\t\t  SUM(t_cnm_stockstatus.MOS)    MOS\n        \t\t\t\tFROM t_cnm_stockstatus\n        \t\t\t\t  INNER JOIN t_cnm_masterstockstatus\n        \t\t\t\t    ON (t_cnm_stockstatus.CNMStockId = t_cnm_masterstockstatus.CNMStockId)\n        \t\t\t\t  INNER JOIN t_itemlist\n        \t\t\t\t    ON (t_cnm_stockstatus.ItemNo = t_itemlist.ItemNo)\n        \t\t\t\tWHERE (t_cnm_masterstockstatus.Year = '{$year}'\n        \t\t\t\t       AND t_cnm_masterstockstatus.MonthId ={$monthId}\n        \t\t\t\t       AND t_cnm_masterstockstatus.CountryId = {$countryId}\n        \t\t\t\t       AND t_cnm_masterstockstatus.ItemGroupId ={$itemGroupId}\n        \t\t\t\t       AND t_cnm_masterstockstatus.StatusId = 5)\n        \t\t\t\tGROUP BY t_cnm_masterstockstatus.CountryId, t_itemlist.ItemNo, t_itemlist.ItemName) a \n        \t\t\t\tLEFT JOIN (SELECT\n        \t\t\t\t    CountryId\n        \t\t\t\t    , ItemNo\n        \t\t\t\t    , SUM(Qty) Qty\n        \t\t\t\tFROM\n        \t\t\t\t    t_agencyshipment\n        \t\t\t\tWHERE (ShipmentDate > CAST('{$currentYearMonth}' AS DATETIME)  AND ShipmentStatusId = 3)\n        \t\t\t\tGROUP BY CountryId, ItemNo) b\n        \t\t\t\tON a.CountryId = b.CountryId AND a.ItemNo = b.ItemNo\n        \t\t\t\tLEFT JOIN (SELECT t_cnm_regimenpatient.CountryId,ItemNo,sum(TotalPatient) as TotalPatient\n        \t\t\t\tfrom t_cnm_regimenpatient\n        \t\t\t\tInner Join t_regimenitems ON t_cnm_regimenpatient.RegimenId=t_regimenitems.RegimenId\n        \t\t\t\tGroup By t_cnm_regimenpatient.CountryId,ItemNo) c ON a.CountryId = c.CountryId AND a.ItemNo = c.ItemNo\n        \t\t\t\t\n        \t\t\t\tHAVING MOS>0 OR StockOnOrderMOS>0 \n        \t\t\t\t;";
    $result = mysql_query($sql, $conn);
    $total = mysql_num_rows($result);
    if ($total > 0) {
        $data = array();
        $f = 0;
        $tblHTML = '';
        while ($rec = mysql_fetch_array($result)) {
            $addmonth = number_format($rec['TotalMOS']);
            $currentYearMonth = $year . "-" . $monthId . "-" . "01";
            $lastYearMonth = date("Y-m-d", strtotime(date("Y-m-d", strtotime($currentYearMonth)) . "{$addmonth} month"));
            $temp = explode('-', $lastYearMonth);
            $strMonth = numberToMonth($temp[1]);
            $lastYearMonth = $strMonth . ', ' . $temp[0];
            $data['SL'][$f] = $f;
            $data['ItemName'][$f] = $rec['ItemName'];
            $data['TotalPatient'][$f] = $rec['TotalPatient'] == 0 ? '' : number_format($rec['TotalPatient']);
            $data['ClStock'][$f] = $rec['ClStock'] == 0 ? '' : number_format($rec['ClStock']);
            $data['MOS'][$f] = $rec['MOS'] == 0 ? '' : number_format($rec['MOS'], 1);
            $data['StockOnOrder'][$f] = $rec['StockOnOrder'] == 0 ? '' : number_format($rec['StockOnOrder']);
            $data['StockOnOrderMOS'][$f] = $rec['StockOnOrderMOS'] == 0 ? '' : number_format($rec['StockOnOrderMOS'], 1);
            $data['TotalMOS'][$f] = $rec['TotalMOS'] == 0 ? '' : number_format($rec['TotalMOS'], 1);
            $tblHTML .= '<tr style="page-break-inside:avoid;">
                            <td align="center" width="30" valign="middle">' . ($data['SL'][$f] + 1) . '</td>  
                            <td align="left" width="150" valign="middle">' . $data['ItemName'][$f] . '</td>
                            <td align="right" width="60" valign="middle">' . $data['TotalPatient'][$f] . '</td>
                            <td align="right" width="60" valign="middle">' . $data['ClStock'][$f] . '</td>
                            <td align="right" width="85" valign="middle">' . $data['MOS'][$f] . '</td>
                            <td align="right" width="60" valign="middle">' . $data['StockOnOrder'][$f] . '</td>
                            <td align="right" width="80" valign="middle">' . $data['StockOnOrderMOS'][$f] . '</td>
                            <td align="right" width="60" valign="middle">' . $data['TotalMOS'][$f] . '</td>
                            <td align="right" width="80" valign="middle">' . $lastYearMonth . '</td>
                            
                    </tr>';
            $f++;
        }
        $year = $_POST['YearId'];
        $MonthName = $_POST['MonthName'];
        $CountryName = $_POST['CountryName'];
        $html = '
        <!-- EXAMPLE OF CSS STYLE -->
        <style>
        </style>
        <body>
            <h4 style="text-align:center;"><b>' . $gTEXT['Number of Patients by Product Report of '] . '  ' . $CountryName . ' on ' . $MonthName . ',' . $year . '</b></h4>
        </body>';
        $pdf->SetFont('dejavusans', '', 10);
        $pdf->writeHTMLCell(0, 0, 8, 10, $html, '', 0, 0, false, 'C', true);
        $html = '
            <!-- EXAMPLE OF CSS STYLE -->
            <style>
             td{
                 height: 6px;
                 line-height:3px;
             }
            </style>
            <body>
            <table width="600px" border="0.5" style="margin:0 auto;">
                <tr>
            		<th width="30" align="center"><b>SL#</b></th>
                    <th width="150" align="left"><b>' . $gTEXT['Product Name'] . '</b></th>
                    <th width="60" align="right"><b>' . $gTEXT['Total Patients'] . '</b></th>
            		<th width="60" align="right"><b>' . $gTEXT['Available Stock'] . '</b></th>
                    <th width="85" align="left"><b>' . $gTEXT['MOS(Available)'] . '</b></th>
                    <th width="60" align="right"><b>' . $gTEXT['Stock on Order'] . '</b></th>
            		<th width="80" align="right"><b>' . $gTEXT['MOS(Ordered)'] . '</b></th>
                    <th width="60" align="left"><b>' . $gTEXT['Total MOS'] . '</b></th>
                    <th width="80" align="right"><b>' . $gTEXT['Projected Date'] . '</b></th>
                    
         	    </tr>' . $tblHTML . '</table></body>';
        $pdf->SetFont('dejavusans', '', 7);
        $pdf->writeHTMLCell(0, 0, 10, 40, $html, '', 1, 1, false, 'L', true);
        $filePath = SITEDOCUMENT . 'administrator/components/com_jcode/source/report/pdfslice/NumberPatientReport.pdf';
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $pdf->Output('pdfslice/NumberPatientReport.pdf', 'F');
        echo 'NumberPatientReport.pdf';
    } else {
        echo 'Processing Error';
    }
}
 function index()
 {
     $this->load->model(array('payment_schedule_customer_model', 'receipt_model'));
     $this->load->library('form_validation');
     $this->load->model('project_model');
     $this->load->helper('csv');
     $this->load->helper('download');
     $data['projects'] = $this->db->get('project')->result();
     $this->form_validation->set_rules('project', 'Date', 'trim|required');
     if ($this->form_validation->run() == FALSE) {
         $data['dues'] = array();
         $this->load->view('reports/sales_report', $data);
     } else {
         $dues = array();
         $project_selected = $this->input->post('project');
         $from_date_db = $this->input->post('from_date');
         $from_date_db = date('Y-m-d', strtotime($from_date_db));
         $to_date_db = $this->input->post('to_date');
         $to_date_db = date('Y-m-d', strtotime($to_date_db));
         $due_report = array();
         $this->db->select('customer_file.id,customer_file.purchase_cost,contact.name,' . 'project.name as project,availability_chart_unit.unit_name as unit_name,' . 'contact.phone,contact.phone_2,contact.phone_3,contact.email,contact.email_2,' . 'customer_file.booking_date,customer_file.area,customer_file.rate,' . 'sales_region.name as sales_region, user.full_name as sales_person');
         $this->db->from('customer_file');
         $this->db->join('contact', 'customer_file.customer_id=contact.id');
         $this->db->join('project', 'customer_file.project_id=project.id');
         $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id');
         $this->db->join('sales_region', 'sales_region.id=customer_file.sales_region', 'left');
         $this->db->join('user', 'user.id=customer_file.sales_person', 'left');
         $this->db->where('customer_file.project_id', $project_selected);
         $this->db->where('customer_file.booking_date >=', $from_date_db);
         $this->db->where('customer_file.booking_date <=', $to_date_db);
         $customers = $this->db->get()->result();
         foreach ($customers as $customer) {
             $due_report[$customer->id] = array();
             $due_report[$customer->id]['client_name'] = $customer->name;
             $due_report[$customer->id]['phone'] = implode(array_filter(array($customer->phone, $customer->phone_2, $customer->phone_3)), ', ');
             $due_report[$customer->id]['email'] = implode(array_filter(array($customer->email, $customer->email_2)), ', ');
             $due_report[$customer->id]['project'] = $customer->project . '-' . $customer->unit_name;
             $due_report[$customer->id]['purchase_cost'] = $customer->purchase_cost;
             $due_report[$customer->id]['booking_date'] = $customer->booking_date;
             $due_report[$customer->id]['area'] = $customer->area;
             $due_report[$customer->id]['rate'] = $customer->rate;
             $due_report[$customer->id]['sales_region'] = $customer->sales_region;
             $due_report[$customer->id]['sales_person'] = $customer->sales_person;
             $due_report[$customer->id]['total_tax'] = 0;
             $due_report[$customer->id]['due_amount'] = 0;
             $due_report[$customer->id]['total_pri'] = 0;
             $due_report[$customer->id]['total_tx'] = 0;
             $due_report[$customer->id]['total_amt'] = 0;
             $due_report[$customer->id]['total_units'] = $this->db->where('project_id', $customer->id)->count_all_results('customer_file');
             $customer_file_id = $customer->id;
             $actual_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_actual_active($customer_file_id);
             $additional_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_additional_active($customer_file_id);
             $receipts = $this->receipt_model->list_cleared_receipt_customer_file($customer_file_id);
             $this->db->select('tax_type.name,tax_master.id');
             $this->db->from('tax_type');
             $this->db->join('tax_master', 'tax_master.tax_type_id=tax_type.id');
             $this->db->join('customer_file_tax', 'customer_file_tax.tax_id=tax_master.id');
             $this->db->where('customer_file_tax.customer_file_id', $customer_file_id);
             $customer_tax = $this->db->get()->result();
             $total_due_amount = 0;
             // Actual Due
             foreach ($actual_payment_schedule as $schedule) {
                 $total_due_amount += $schedule->due_amount;
                 $ttax = 0;
                 $ttax_bal = 0;
                 foreach ($customer_tax as $cs2) {
                     $tax_amount = 0;
                     $tax_amount_bal = 0;
                     if ($schedule->status == 1) {
                         if ($schedule->due_amount - $schedule->amount_paid == 0) {
                             $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                             $this->db->from('receipt_split_up_tax');
                             $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                             $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                             $applicale_tax = $this->db->get()->first_row();
                             if ($applicale_tax->tax_amount) {
                                 $ttax += $applicale_tax->tax_amount;
                             }
                         } elseif ($schedule->amount_paid == 0) {
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type));
                             $applicale_tax = $this->db->get()->first_row();
                             if (!empty($applicale_tax->tax_percentage)) {
                                 $tax_amount = $schedule->due_amount / 100 * $applicale_tax->tax_percentage;
                                 $ttax += $tax_amount;
                             }
                         } else {
                             // tax on paid amount start
                             $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                             $this->db->from('receipt_split_up_tax');
                             $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                             $this->db->where(array('receipt_split_up.installment_id' => $schedule->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                             $applicale_tax_paid = $this->db->get()->first_row();
                             // tax on paid amount end
                             //tax on balance amount start
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type));
                             $tax_percentage_balance = $this->db->get()->first_row();
                             //tax on balance amount end
                             $tax_amount_balance = ($schedule->due_amount - $schedule->amount_paid) / 100 * $tax_percentage_balance->tax_percentage;
                             $applicale_tax_amount = $applicale_tax_paid->tax_amount + $tax_amount_balance;
                             $ttax += $applicale_tax_amount;
                         }
                     }
                 }
                 $due_report[$customer->id]['total_tax'] += $ttax;
                 $due_report[$customer->id]['due_amount'] += $schedule->due_amount;
             }
             // Additional Due
             foreach ($additional_payment_schedule as $schedule_additional) {
                 $total_due_amount_additional += $schedule_additional->due_amount;
                 $ttax_additional = 0;
                 $ttax_bal = 0;
                 foreach ($customer_tax as $cs2) {
                     $tax_amount_add = 0;
                     $tax_amount_bal_add = 0;
                     if ($schedule_additional->status == 1) {
                         if ($schedule_additional->due_amount - $schedule_additional->amount_paid == 0) {
                             $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                             $this->db->from('receipt_split_up_tax');
                             $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                             $this->db->where(array('receipt_split_up.installment_id' => $schedule_additional->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                             $applicale_tax_add = $this->db->get()->first_row();
                             if ($applicale_tax_add->tax_amount) {
                                 $ttax_additional += $applicale_tax_add->tax_amount;
                             }
                         } elseif ($schedule_additional->amount_paid == 0) {
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule_additional->payment_type));
                             $applicale_tax_add = $this->db->get()->first_row();
                             if (!empty($applicale_tax_add->tax_percentage)) {
                                 $tax_amount_add = $schedule_additional->due_amount / 100 * $applicale_tax_add->tax_percentage;
                                 $ttax_additional += $tax_amount_add;
                             }
                         } else {
                             // tax on paid amount start
                             $this->db->select('SUM(receipt_split_up_tax.tax_amount) as tax_amount');
                             $this->db->from('receipt_split_up_tax');
                             $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                             $this->db->where(array('receipt_split_up.installment_id' => $schedule_additional->id, 'receipt_split_up_tax.tax_id' => $cs2->id));
                             $applicale_tax_paid_bal = $this->db->get()->first_row();
                             // tax on paid amount end
                             //tax on balance amount start
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $to_date_db, 'to_date >=' => $to_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule_additional->payment_type));
                             $tax_percentage_balance = $this->db->get()->first_row();
                             //tax on balance amount end
                             $tax_amount_balance_add = ($schedule_additional->due_amount - $schedule_additional->amount_paid) / 100 * $tax_percentage_balance->tax_percentage;
                             $applicale_tax_amount_add = $applicale_tax_paid_bal->tax_amount + $tax_amount_balance_add;
                             $ttax_additional += $applicale_tax_amount_add;
                         }
                     }
                 }
                 $due_report[$customer->id]['total_tax_additional'] += $ttax_additional;
                 $due_report[$customer->id]['due_amount_additional'] += $schedule_additional->due_amount;
             }
             //Receipts
             foreach ($receipts as $b => $receipt) {
                 $due_report[$customer->id]['total_pri'] += $receipt->principle_amount;
                 $due_report[$customer->id]['total_tx'] += $receipt->amount_paid - $receipt->principle_amount;
                 $due_report[$customer->id]['total_amt'] += $receipt->amount_paid;
             }
         }
         //print_r($due_report);
         //exit();
         if (isset($_POST['generate_pdf'])) {
             $this->load->library('Pdf');
             $this->db->select('company.name,project.project_type');
             $this->db->from('company');
             $this->db->join('project', 'project.company_id=company.id');
             $this->db->join('customer_file', 'customer_file.project_id=project.id');
             $company_details = $this->db->get()->first_row();
             $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
             $pdf->SetCreator(PDF_CREATOR);
             $pdf->SetTitle('Receipt');
             //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255));
             $pdf->SetPrintFooter(false);
             $pdf->setPrintHeader(false);
             //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
             //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
             $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
             $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
             //$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
             //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
             $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
             $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
             if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
                 require_once dirname(__FILE__) . '/lang/eng.php';
                 $pdf->setLanguageArray($l);
             }
             $pdf->setFontSubsetting(true);
             $pdf->SetFont('dejavusans', '', 7, '', true);
             $pdf->AddPage();
             $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true);
             $style = array('width' => 0.1, 'color' => array(0, 0, 0));
             $pdf->Line(0, 25, 220, 25, $style);
             $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Sales Report</h2>', 0, 1, 0, true, '', true);
             $style = array('width' => 0.1, 'color' => array(0, 0, 0));
             $pdf->Line(0, 35, 220, 35, $style);
             $pdf->writeHTMLCell(50, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($from_date_db)) . ' - ' . date('M Y', strtotime($to_date_db)) . '</strong>', 0, 1, 0, true, '', true);
             $pdf->writeHTMLCell(35, 0, 168, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true);
             $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />';
             $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>';
             $html .= '<th width="30">No.</th>';
             $html .= '<th width="65">Booking Date</th>';
             $html .= '<th width="75">Client Name</th>';
             $html .= '<th width="60">Project</th>';
             $html .= '<th width="40">Rate</th>';
             $html .= '<th width="65">Agreement Value</th>';
             $html .= '<th width="65">Due Amount</th>';
             $html .= '<th width="65">Total Collection</th>';
             $html .= '<th width="65">Balance Due</th>';
             $html .= '<th width="60">Sales Region</th>';
             $html .= '<th width="60">Sales Person</th>';
             $html .= '</tr>';
             $html .= '</thead><tbody>';
             $total_sale_amount = 0;
             $total_due_amount = 0;
             $total_due_amount_additional = 0;
             $total_due_tax = 0;
             $total_due_tax_additional = 0;
             $total_collection = 0;
             $total_balance = 0;
             foreach ($due_report as $due) {
                 $total_sale_amount += $due['purchase_cost'];
                 $total_due_amount += $due['due_amount'];
                 $total_due_amount_additional += $due['due_amount_additional'];
                 $total_due_tax += $due['total_tax'];
                 $total_due_tax_additional += $due['total_tax_additional'];
                 $total_collection += $due['total_amt'];
                 $total_balance += $due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt'];
                 $html .= '<tr>';
                 $html .= '<td width="30">' . ($n + 1) . '</td>';
                 $html .= '<td width="65">' . date('d-m-Y', strtotime($due['booking_date'])) . '</td>';
                 $html .= '<td width="75">' . $due['client_name'] . '</td>';
                 $html .= '<td width="60">' . $due['project'] . '</td>';
                 $html .= ' <td width="40">' . number_format($due['rate']) . '</td>';
                 $html .= ' <td width="65">' . number_format($due['purchase_cost']) . '</td>';
                 $html .= ' <td width="65">' . number_format($due['due_amount_additional'] + $due['total_tax_additional'] + ($due['due_amount'] + $due['total_tax'])) . '</td>';
                 $html .= ' <td width="65">' . number_format($due['total_amt']) . '</td>';
                 $html .= ' <td width="65">' . number_format($due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt']) . '</td>';
                 $html .= '<td width="60">' . $due['sales_region'] . '</td>';
                 $html .= '<td width="60">' . $due['sales_person'] . '</td>';
                 $html .= '</tr>';
                 $n++;
             }
             $html .= '</tbody>';
             $html .= '<tfoot>';
             $html .= '<tr style="font-weight: bolder">';
             $html .= '<td colspan="5"></td>';
             $html .= '<td>' . number_format($purchase_cost) . '</td>';
             $html .= '<td>' . number_format($due_amount + $due_amount_additional + $total_tax + $total_tax_additional) . '</td>';
             $html .= '<td>' . number_format($total_amt_collected) . '</td>';
             $html .= '<td>' . number_format($due_amount + $due_amount_additional + $total_tax + $total_tax_additional - $total_amt_collected) . '</td>';
             $html .= '<td></td>';
             $html .= '<td></td>';
             $html .= '</tr>';
             $html .= '</tfoot>';
             $html .= '</table><br /><br />';
             //echo $html;
             //exit();
             $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
             $pdf->Output('receipt.pdf', 'I');
         } elseif (isset($_POST['generate_csv'])) {
             $csv_array = array();
             $csv_array_line = array();
             $csv_array_line[] = 'No.';
             $csv_array_line[] = 'Date of Booking';
             $csv_array_line[] = 'Client Name';
             $csv_array_line[] = 'Contact Number';
             $csv_array_line[] = 'Email';
             $csv_array_line[] = 'Area';
             $csv_array_line[] = 'Rate';
             $csv_array_line[] = 'Project';
             $csv_array_line[] = 'Sale Value';
             $csv_array_line[] = 'Prin Amt Due';
             $csv_array_line[] = 'Tax Amt Due';
             $csv_array_line[] = 'Additional Due';
             $csv_array_line[] = 'Additional Due Tax';
             $csv_array_line[] = 'Total Due';
             $csv_array_line[] = 'Total Collection';
             $csv_array_line[] = 'Balance Due';
             $csv_array_line[] = 'Sales Region';
             $csv_array_line[] = 'Sales Person';
             $csv_array[] = $csv_array_line;
             foreach ($due_report as $due) {
                 $csv_array_line = array();
                 $csv_array_line[] = $n + 1;
                 $csv_array_line[] = date('d-m-Y', strtotime($due['booking_date']));
                 $csv_array_line[] = $due['client_name'];
                 $csv_array_line[] = $due['phone'];
                 $csv_array_line[] = $due['email'];
                 $csv_array_line[] = $due['area'];
                 $csv_array_line[] = $due['rate'];
                 $csv_array_line[] = $due['project'];
                 $csv_array_line[] = $due['due_amount'] + $due['due_amount_additional'];
                 $csv_array_line[] = $due['due_amount'];
                 $csv_array_line[] = $due['total_tax'];
                 $csv_array_line[] = $due['due_amount_additional'];
                 $csv_array_line[] = $due['total_tax_additional'];
                 $csv_array_line[] = $due['due_amount_additional'] + $due['total_tax_additional'] + ($due['due_amount'] + $due['total_tax']);
                 $csv_array_line[] = $due['total_amt'];
                 $csv_array_line[] = $due['due_amount'] + $due['total_tax'] + $due['due_amount_additional'] + $due['total_tax_additional'] - $due['total_amt'];
                 $csv_array_line[] = $due['sales_region'];
                 $csv_array_line[] = $due['sales_person'];
                 $csv_array[] = $csv_array_line;
             }
             echo array_to_csv($csv_array, 'due_letter.csv');
             exit;
         } else {
             $data['due_report'] = $due_report;
             $data['from_date_selected'] = $this->input->post('from_date');
             $data['to_date_selected'] = $this->input->post('to_date');
             $data['project_selected'] = $this->input->post('project');
             $this->load->view('reports/sales_report', $data);
         }
     }
 }
Example #21
0
 function generate_discount_pdf($discount_id)
 {
     $this->load->library('Pdf');
     $this->load->model('discount_model');
     $rec = $this->discount_model->get_discount($discount_id);
     if (!empty($rec->discount_number) && !empty($rec->date_payment)) {
         $discount = $this->discount_model->get_discount_pdf($rec->discount_number, $rec->date_payment);
     } else {
         $discount = $rec;
     }
     $customer_file = $this->discount_model->get_customer_file_discount($discount_id);
     $pdf = new TCPDF('L', PDF_UNIT, 'A5', true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetTitle('Receipt');
     $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255));
     $pdf->SetPrintFooter(false);
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
         require_once dirname(__FILE__) . '/lang/eng.php';
         $pdf->setLanguageArray($l);
     }
     $pdf->setFontSubsetting(true);
     $pdf->SetFont('dejavusans', '', 12, '', true);
     $pdf->AddPage();
     $amt = $this->convert_number($discount->amount_paid);
     $html = '<h1 style="text-align:center">RECEIPT</h1>';
     $html .= '<table><tr><td>Sl No. :<span style="color:red"> ' . $discount->discount_number . '</span></td>';
     $html .= '<td align="right">Date : ' . $discount->date_payment . ' </td></tr></table>';
     $html .= '<p>Received with thanks from Mr/Mrs <span style="font-weight: bold">' . $customer_file->customer_name . '</span> as sum of Rs. ';
     $html .= '<span style="font-weight: bold">' . $amt . '</span> only paid towards the purchase of apartment ';
     $html .= '<span style="font-weight: bold">' . $customer_file->unit_name . '</span> in Project <span style="font-weight: bold">' . $customer_file->project_name . '</span> ';
     if (!empty($discount->cheque_number)) {
         $html .= 'Cheque / DD No. <span style="font-weight: bold">' . $discount->cheque_number . '</span> Date : <span style="font-weight: bold">' . $discount->cheque_date . '<span></p>';
     }
     $html .= '<br /><br /><br /><br />';
     $html .= '<table cellpadding="6"><tr><td style="border:1px solid black; width:200px; font-weight:bold">Rs. ' . number_format($discount->amount_paid, 2) . ' /-</td>';
     $html .= '</tr></table>';
     $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
     $pdf->Output('discount.pdf', 'I');
 }
Example #22
0
/**
 * Creates the PDF version (downloadable) of the whole feedback produced by the teacher/tutor
 *
 * @param unknown $draft            
 * @param unknown $student            
 * @param unknown $context            
 * @param unknown $cmid            
 * @return boolean
 */
function emarking_create_response_pdf($draft, $student, $context, $cmid)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/pdflib.php';
    $fs = get_file_storage();
    if (!($submission = $DB->get_record('emarking_submission', array('id' => $draft->submissionid)))) {
        return false;
    }
    if (!($pages = $DB->get_records('emarking_page', array('submission' => $submission->id), 'page ASC'))) {
        return false;
    }
    if (!($emarking = $DB->get_record('emarking', array('id' => $submission->emarking)))) {
        return false;
    }
    $numpages = count($pages);
    $sqlcomments = "SELECT ec.id,\n\t\t\tec.posx,\n\t\t\tec.posy,\n\t\t\tec.rawtext,\n\t\t\tec.pageno,\n\t\t\tgrm.maxscore,\n\t\t\tec.levelid,\n\t\t\tec.width,\n\t\t\tec.colour,\n\t\t\tec.textformat,\n\t\t\tgrl.score AS score,\n\t\t\tgrl.definition AS leveldesc,\n\t\t\tgrc.id AS criterionid,\n\t\t\tgrc.description AS criteriondesc,\n\t\t\tu.id AS markerid, CONCAT(u.firstname,' ',u.lastname) AS markername\n\t\t\tFROM {emarking_comment} ec\n\t\t\tINNER JOIN {emarking_page} ep ON (ec.draft = :draft AND ec.page = ep.id)\n\t\t\tLEFT JOIN {user} u ON (ec.markerid = u.id)\n\t\t\tLEFT JOIN {gradingform_rubric_levels} grl ON (ec.levelid = grl.id)\n\t\t\tLEFT JOIN {gradingform_rubric_criteria} grc ON (grl.criterionid = grc.id)\n\t\t\tLEFT JOIN (\n\t\t\tSELECT grl.criterionid, max(score) AS maxscore\n\t\t\tFROM {gradingform_rubric_levels} grl\n\t\t\tGROUP BY grl.criterionid\n\t\t\t) AS grm ON (grc.id = grm.criterionid)\n\t\t\tWHERE ec.pageno > 0\n\t\t\tORDER BY ec.pageno";
    $params = array('draft' => $draft->id);
    $comments = $DB->get_records_sql($sqlcomments, $params);
    $commentsperpage = array();
    foreach ($comments as $comment) {
        if (!isset($commentsperpage[$comment->pageno])) {
            $commentsperpage[$comment->pageno] = array();
        }
        $commentsperpage[$comment->pageno][] = $comment;
    }
    // Parameters for PDF generation.
    $iconsize = 5;
    $tempdir = emarking_get_temp_dir_path($emarking->id);
    if (!file_exists($tempdir)) {
        emarking_initialize_directory($tempdir, true);
    }
    // Create new PDF document.
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // Set document information.
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor($student->firstname . ' ' . $student->lastname);
    $pdf->SetTitle($emarking->name);
    $pdf->SetSubject('Exam feedback');
    $pdf->SetKeywords('feedback, emarking');
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    // Set default header data.
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 036', PDF_HEADER_STRING);
    // Set header and footer fonts.
    $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    // Set default monospaced font.
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // Set margins.
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    // Set auto page breaks.
    $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
    // Set image scale factor.
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    // Set some language-dependent strings (optional).
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    // Set font.
    $pdf->SetFont('times', '', 16);
    foreach ($pages as $page) {
        // Add a page.
        $pdf->AddPage();
        // Get the current page break margin.
        $bmargin = $pdf->getBreakMargin();
        // Get current auto-page-break mode.
        $autopagebreak = $pdf->getAutoPageBreak();
        // Disable auto-page-break.
        $pdf->SetAutoPageBreak(false, 0);
        // Set bacground image.
        $pngfile = $fs->get_file_by_id($page->file);
        $imgfile = emarking_get_path_from_hash($tempdir, $pngfile->get_pathnamehash());
        $pdf->Image($imgfile, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
        // Restore auto-page-break status.
        // Set the starting point for the page content.
        $pdf->setPageMark();
        $dimensions = $pdf->getPageDimensions();
        if (isset($commentsperpage[$page->page])) {
            foreach ($commentsperpage[$page->page] as $comment) {
                $content = $comment->rawtext;
                $posx = (int) ((double) $comment->posx * 210);
                $posy = (int) ((double) $comment->posy * 297);
                if ($comment->textformat == 1) {
                    // Text annotation.
                    $pdf->Annotation($posx, $posy, 6, 6, $content, array('Subtype' => 'Text', 'StateModel' => 'Review', 'State' => 'None', 'Name' => 'Comment', 'NM' => 'Comment' . $comment->id, 'T' => $comment->markername, 'Subj' => 'example', 'C' => array(0, 0, 255)));
                    $pdf->Bookmark(get_string('comment', 'mod_emarking') . ' ' . $comment->id, 0, $posy);
                } else {
                    if ($comment->textformat == 2) {
                        $feedback = strlen($comment->rawtext) > 0 ? "\n" . get_string('comment', 'mod_emarking') . ': ' . $comment->rawtext : '';
                        $content = $comment->criteriondesc . ': ' . round($comment->score, 1) . '/' . round($comment->maxscore, 1) . "\n" . $comment->leveldesc . $feedback;
                        // Text annotation.
                        $pdf->Annotation($posx, $posy, 6, 6, $content, array('Subtype' => 'Text', 'StateModel' => 'Review', 'State' => 'None', 'Name' => 'Comment', 'NM' => 'Mark' . $comment->id, 'T' => $comment->markername, 'Subj' => 'grade', 'C' => array(255, 255, 0)));
                        $pdf->Bookmark($comment->criteriondesc, 0, $posy);
                    } else {
                        if ($comment->textformat == 3) {
                            $pdf->Image($CFG->dirroot . "/mod/emarking/img/check.gif", $posx, $posy, $iconsize, $iconsize, '', '', '', false, 300, '', false, false, 0);
                        } else {
                            if ($comment->textformat == 4) {
                                $pdf->Image($CFG->dirroot . "/mod/emarking/img/crossed.gif", $posx, $posy, $iconsize, $iconsize, '', '', '', false, 300, '', false, false, 0);
                            }
                        }
                    }
                }
            }
        }
    }
    $pdffilename = 'response_' . $emarking->id . '_' . $draft->id . '.pdf';
    $pathname = $tempdir . '/' . $pdffilename;
    if (@file_exists($pathname)) {
        unlink($pathname);
    }
    // Close and output PDF document.
    $pdf->Output($pathname, 'F');
    // Copiar archivo desde temp a Area.
    $filerecord = array('contextid' => $context->id, 'component' => 'mod_emarking', 'filearea' => 'response', 'itemid' => $draft->id, 'filepath' => '/', 'filename' => $pdffilename, 'timecreated' => time(), 'timemodified' => time(), 'userid' => $student->id, 'author' => $student->firstname . ' ' . $student->lastname, 'license' => 'allrightsreserved');
    // Si el archivo ya existía entonces lo borramos.
    if ($fs->file_exists($context->id, 'mod_emarking', 'response', $draft->id, '/', $pdffilename)) {
        $previousfile = $fs->get_file($context->id, 'mod_emarking', 'response', $draft->id, '/', $pdffilename);
        $previousfile->delete();
    }
    $fileinfo = $fs->create_file_from_pathname($filerecord, $pathname);
    return true;
}
 function receipt_wise_collection()
 {
     $this->load->model(array('payment_schedule_customer_model', 'receipt_model'));
     $this->load->library('form_validation');
     $this->load->model('project_model');
     $this->load->helper(array('csv', 'download'));
     $this->form_validation->set_rules('project', 'Project', 'trim|required');
     $data['projects'] = $this->db->get('project')->result();
     $data['tax_types'] = $this->db->get('tax_type')->result();
     if ($this->form_validation->run() == FALSE) {
         $data['collections'] = array();
         $this->load->view('reports/receipt_wise_collection', $data);
     } else {
         $tax_types = $this->db->get('tax_type')->result();
         $project_selected = $this->input->post('project');
         $date_from = $this->input->post('date_from');
         $date_from = date('Y-m-d', strtotime($date_from));
         $date_to = $this->input->post('date_to');
         $date_to = date('Y-m-d', strtotime($date_to));
         $this->load->model(array('payment_schedule_customer_model', 'receipt_model'));
         $this->db->select('company.name,project.project_type,project.name as project');
         $this->db->from('company');
         $this->db->join('project', 'project.company_id=company.id');
         $this->db->join('customer_file', 'customer_file.project_id=project.id');
         $this->db->where('project.id', $project_selected);
         $company_details = $this->db->get()->first_row();
         $this->db->select('contact.name as customer_name,project.name as project,SUM(`receipt`.`principle_amount`) as principle_amount,' . 'SUM(`receipt`.`amount_paid`) as amount_paid,receipt.customer_file_id as customer_file_id,' . 'receipt.receipt_number,receipt.date_payment,receipt.id as receipt_number');
         $this->db->from('receipt');
         $this->db->join('customer_file', 'customer_file.id=receipt.customer_file_id');
         $this->db->join('project', 'project.id=customer_file.project_id');
         $this->db->join('contact', 'contact.id=customer_file.customer_id');
         $this->db->where('customer_file.project_id', $project_selected);
         $this->db->where('receipt.date_payment >=', $date_from);
         $this->db->where('receipt.date_payment <=', $date_to);
         $this->db->order_by('receipt.date_payment', 'desc');
         $this->db->group_by('receipt.id');
         $collection_report = $this->db->get()->result();
         if (isset($_POST['generate_pdf'])) {
             $this->load->library('Pdf');
             $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
             $pdf->SetCreator(PDF_CREATOR);
             $pdf->SetTitle('Receipt');
             //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255));
             $pdf->SetPrintFooter(false);
             $pdf->setPrintHeader(false);
             //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
             //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
             $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
             $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
             //$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
             //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
             $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
             $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
             if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
                 require_once dirname(__FILE__) . '/lang/eng.php';
                 $pdf->setLanguageArray($l);
             }
             $pdf->setFontSubsetting(true);
             $pdf->SetFont('dejavusans', '', 7, '', true);
             $pdf->AddPage();
             $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true);
             $style = array('width' => 0.1, 'color' => array(0, 0, 0));
             $pdf->Line(0, 25, 220, 25, $style);
             $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Receipt Wise Collection Report - ' . $company_details->project . '</h2>', 0, 1, 0, true, '', true);
             $style = array('width' => 0.1, 'color' => array(0, 0, 0));
             $pdf->Line(0, 35, 220, 35, $style);
             $pdf->writeHTMLCell(58, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($date_from)) . ' to ' . date('M Y', strtotime($date_to)) . '</strong>', 0, 1, 0, true, '', true);
             $pdf->writeHTMLCell(35, 0, 161, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true);
             $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />';
             $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>';
             $html .= '<th width="30">No.</th>';
             $html .= '<th width="90">Customer Name</th>';
             $html .= '<th width="70">Date</th>';
             $html .= '<th width="75">Principal Amount Paid</th>';
             foreach ($tax_types as $tax_type) {
                 $html .= '<th width="75">' . $tax_type->name . '</th>';
             }
             $html .= '<th width="75">Total Tax</th>';
             $html .= '<th width="74">Total Paid</th>';
             $html .= '</tr>';
             $html .= '</thead><tbody>';
             $total_due_percentage = 0;
             $total_due_amount = 0;
             $total_due_tax_amount = 0;
             $total_balance = 0;
             $total_tax = array();
             foreach ($customer_tax as $cs5) {
                 $total_tax[$cs5->id] = 0;
             }
             $total_paid = 0;
             $n = 1;
             $total_principle_amount = 0;
             $txts = array();
             foreach ($collection_report as $collection) {
                 $total_tax_row = 0;
                 $total_principle_amount += $collection->principle_amount;
                 $html .= '<tr>';
                 $html .= '<td width="30">' . $n . '</td>';
                 $html .= '<td width="90">' . $collection->customer_name . '</td>';
                 $html .= '<td width="70">' . date('d-m-Y', strtotime($collection->date_payment)) . '</td>';
                 $html .= '<td width="75">' . number_format($collection->principle_amount) . '</td>';
                 foreach ($tax_types as $tax_type) {
                     $this->db->select("SUM(`tax_amount`) as tax");
                     $this->db->from('receipt_split_up_tax');
                     $this->db->join('tax_master', 'tax_master.id=receipt_split_up_tax.tax_id');
                     $this->db->join('tax_type', 'tax_type.id=tax_master.tax_type_id');
                     $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                     $this->db->join('receipt', 'receipt.id=receipt_split_up.receipt_id');
                     $this->db->where('receipt.id', $collection->receipt_number);
                     $this->db->where('tax_type.id', $tax_type->id);
                     @($txs = $this->db->get()->first_row());
                     if (!$txs->tax) {
                         $txs = 0;
                     } else {
                         $txs = $txs->tax;
                     }
                     $txts[$tax_type->id] += $txs;
                     $total_tax_row += $txs;
                     $html .= '<td width="75">' . number_format($txs) . '</td>';
                 }
                 $html .= ' <td width="75">' . number_format($total_tax_row) . '</td>';
                 $html .= ' <td width="74">' . number_format($collection->amount_paid) . '</td>';
                 $html .= '</tr>';
                 $n++;
             }
             $html .= '</tbody>';
             $html .= '<tfoot>';
             $html .= '<tr style="font-weight: bolder">';
             $html .= '<td colspan="3"></td>';
             $html .= '<td>' . number_format($total_principle_amount) . '</td>';
             $tt_tax = 0;
             $ttottax = 0;
             foreach ($tax_types as $tax_type) {
                 $html .= '<td>' . number_format($txts[$tax_type->id]) . '</td>';
                 $ttottax += $txts[$tax_type->id];
             }
             $html .= '<td>' . number_format($ttottax) . '</td>';
             $html .= '<td>' . number_format($ttottax + $total_principle_amount) . '</td>';
             $html .= '</tr>';
             $html .= '</tfoot>';
             $html .= '</table><br /><br />';
             //echo $html;
             //exit();
             $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
             $pdf->Output('receipt.pdf', 'I');
         } elseif (isset($_POST['generate_csv'])) {
             $csv_array = array();
             $csv_array_line = array();
             $csv_array_line[] = 'No.';
             $csv_array_line[] = 'Customer Name';
             $csv_array_line[] = 'Project';
             $csv_array_line[] = 'Receipt Number';
             $csv_array_line[] = 'Date';
             $csv_array_line[] = 'Principal Amount Paid';
             foreach ($tax_types as $tax_type) {
                 $csv_array_line[] = $tax_type->name;
             }
             $csv_array_line[] = 'Total Tax';
             $csv_array_line[] = 'Total Paid';
             $csv_array[] = $csv_array_line;
             $csv_array_line = array();
             $n = 1;
             foreach ($collection_report as $collection) {
                 $csv_array_line = array();
                 $csv_array_line[] = $n;
                 $csv_array_line[] = $collection->customer_name;
                 $csv_array_line[] = $collection->project;
                 $csv_array_line[] = $collection->receipt_number;
                 $csv_array_line[] = date('d-m-Y', strtotime($collection->date_payment));
                 $csv_array_line[] = $collection->principle_amount;
                 $total_tax_row = 0;
                 foreach ($tax_types as $tax_type) {
                     $this->db->select("SUM(`tax_amount`) as tax");
                     $this->db->from('receipt_split_up_tax');
                     $this->db->join('tax_master', 'tax_master.id=receipt_split_up_tax.tax_id');
                     $this->db->join('tax_type', 'tax_type.id=tax_master.tax_type_id');
                     $this->db->join('receipt_split_up', 'receipt_split_up.id=receipt_split_up_tax.receipt_split_up_id');
                     $this->db->join('receipt', 'receipt.id=receipt_split_up.receipt_id');
                     $this->db->where('receipt.id', $collection->receipt_number);
                     $this->db->where('tax_type.id', $tax_type->id);
                     @($txs = $this->db->get()->first_row());
                     if (!$txs->tax) {
                         $txs = 0;
                     } else {
                         $txs = $txs->tax;
                     }
                     $txts[$tax_type->id] += $txs;
                     $total_tax_row += $txs;
                     $csv_array_line[] = $txs;
                 }
                 $csv_array_line[] = $total_tax_row;
                 $csv_array_line[] = $collection->amount_paid;
                 $csv_array[] = $csv_array_line;
                 $n = $n + 1;
             }
             echo array_to_csv($csv_array, 'receipt_wise_collection_report.csv');
             exit;
         } else {
             $data['collection_report'] = $collection_report;
             $data['date_from_selected'] = $this->input->post('date_from');
             $data['date_to_selected'] = $this->input->post('date_to');
             $data['project_selected'] = $this->input->post('project');
             $this->load->view('reports/receipt_wise_collection', $data);
         }
     }
 }
 function generatePDF($action = 'return', $view)
 {
     if (!in_array($action, ['return', 'dump'])) {
         throw $this->exception('Please provide action as result or dump');
     }
     $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('xEpan ERP');
     // $pdf->SetTitle($this['type']. ' '. $this['document_no']);
     // $pdf->SetSubject($this['type']. ' '. $this['document_no']);
     // $pdf->SetKeywords($this['type']. ' '. $this['document_no']);
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set font
     $pdf->SetFont('dejavusans', '', 10);
     //remove header or footer hr lines
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     // add a page
     $pdf->AddPage();
     $html = $view->getHTML();
     // echo $html;
     // exit;
     // output the HTML content
     $pdf->writeHTML($html, false, false, true, false, '');
     // set default form properties
     $pdf->setFormDefaultProp(array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 200), 'strokeColor' => array(255, 128, 128)));
     // reset pointer to the last page
     $pdf->lastPage();
     //Close and output PDF document
     switch ($action) {
         case 'return':
             return $pdf->Output(null, 'S');
             break;
         case 'dump':
             return $pdf->Output(null, 'I');
             exit;
             break;
     }
 }
 function customer_aging_report()
 {
     $this->load->model(array('payment_schedule_customer_model', 'receipt_model', 'project_model'));
     $this->load->library('form_validation');
     $this->load->helper(array('csv', 'download'));
     $data['projects'] = $this->db->get('project')->result();
     $this->form_validation->set_rules('due_date', 'Date', 'trim|required');
     if ($this->form_validation->run() == FALSE) {
         $data['dues'] = array();
         $this->load->view('reports/customer_wise_aging', $data);
     } else {
         $dues = array();
         $project_selected = $this->input->post('project');
         $with_tax_selected = $this->input->post('with_tax');
         $due_date_db = $this->input->post('due_date');
         $due_date_selected = $due_date_db;
         $due_date_db = date('Y-m-d', strtotime($due_date_db));
         $due_report = array();
         $this->db->select('customer_file.id,customer_file.purchase_cost,contact.name,project.name as project,availability_chart_unit.unit_name as unit_name');
         $this->db->from('customer_file');
         $this->db->join('contact', 'customer_file.customer_id=contact.id');
         $this->db->join('project', 'customer_file.project_id=project.id');
         $this->db->join('availability_chart_unit', 'availability_chart_unit.id=customer_file.unit_id');
         $this->db->where('customer_file.project_id', $project_selected);
         $this->db->where('customer_file.approval_status', 1);
         $customers = $this->db->get()->result();
         foreach ($customers as $customer) {
             $due_report[$customer->id] = array();
             $due_report[$customer->id]['client_name'] = $customer->name;
             $due_report[$customer->id]['project'] = $customer->project . '-' . $customer->unit_name;
             $due_report[$customer->id]['purchase_cost'] = $customer->purchase_cost;
             $due_report[$customer->id]['total_tax'] = 0;
             $due_report[$customer->id]['due_amount'][1] = 0;
             $due_report[$customer->id]['due_amount'][2] = 0;
             $due_report[$customer->id]['due_amount'][3] = 0;
             $due_report[$customer->id]['due_amount'][4] = 0;
             $due_report[$customer->id]['due_amount'][5] = 0;
             $due_report[$customer->id]['due_amount'][6] = 0;
             $due_report[$customer->id]['due_amount'][7] = 0;
             $due_report[$customer->id]['total_due_amount'] = 0;
             $due_report[$customer->id]['total_pri'] = 0;
             $due_report[$customer->id]['total_tx'] = 0;
             $due_report[$customer->id]['total_amt'] = 0;
             $due_report[$customer->id]['total_units'] = $this->db->where('project_id', $customer->id)->count_all_results('customer_file');
             $customer_file_id = $customer->id;
             $actual_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_actual_active($customer_file_id);
             $additional_payment_schedule = $this->payment_schedule_customer_model->list_schedule_customer_file_additional_active($customer_file_id);
             $receipts = $this->receipt_model->list_cleared_receipt_customer_file($customer_file_id);
             $this->db->select('tax_type.name,tax_master.id');
             $this->db->from('tax_type');
             $this->db->join('tax_master', 'tax_master.tax_type_id=tax_type.id');
             $this->db->join('customer_file_tax', 'customer_file_tax.tax_id=tax_master.id');
             $this->db->where('customer_file_tax.customer_file_id', $customer_file_id);
             $customer_tax = $this->db->get()->result();
             $total_due_amount = 0;
             // Actual Due
             foreach ($actual_payment_schedule as $schedule) {
                 $total_due_amount += $schedule->due_amount;
                 $ttax = 0;
                 $ttax_bal = 0;
                 $date1 = strtotime($schedule->due_date);
                 // or your date as well
                 $date2 = strtotime($due_date_db);
                 $datediff = $date2 - $date1;
                 $delay = floor($datediff / (60 * 60 * 24));
                 //echo $schedule->due_date . ' - ' . $due_date_db . ' - ' . $delay . '<br />';
                 $tax_amount_tot = 0;
                 if ($with_tax_selected == 1) {
                     foreach ($customer_tax as $cs2) {
                         $tax_amount = 0;
                         $tax_amount_bal = 0;
                         if ($schedule->due_amount - $schedule->amount_paid != 0) {
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $due_date_db, 'to_date >=' => $due_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type));
                             $applicale_tax = $this->db->get()->first_row();
                             if (!empty($applicale_tax->tax_percentage)) {
                                 $tax_amount = ($schedule->due_amount - $schedule->amount_paid) / 100 * $applicale_tax->tax_percentage;
                                 $tax_amount_tot += $tax_amount;
                             }
                         }
                     }
                 } else {
                     $tax_amount = 0;
                 }
                 $due_report[$customer->id]['total_due_amount'] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot;
                 if ($delay < 90) {
                     $due_report[$customer->id]['due_amount'][1] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 90 and $delay < 180) {
                     $due_report[$customer->id]['due_amount'][2] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 180 and $delay < 270) {
                     $due_report[$customer->id]['due_amount'][3] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 270 and $delay < 365) {
                     $due_report[$customer->id]['due_amount'][4] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 365 and $delay < 540) {
                     $due_report[$customer->id]['due_amount'][5] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 540 and $delay < 720) {
                     $due_report[$customer->id]['due_amount'][6] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot;
                 }
                 if ($delay > 720) {
                     $due_report[$customer->id]['due_amount'][7] += $schedule->due_amount - $schedule->amount_paid + $tax_amount_tot;
                 }
             }
             // Additional Due
             foreach ($additional_payment_schedule as $schedule_additional) {
                 $total_due_amount += $schedule_additional->due_amount;
                 $ttax = 0;
                 $ttax_bal = 0;
                 $date1 = strtotime($schedule_additional->due_date);
                 // or your date as well
                 $date2 = strtotime($due_date_db);
                 $datediff = $date2 - $date1;
                 $delay = floor($datediff / (60 * 60 * 24));
                 $tax_amount_tot = 0;
                 if ($with_tax_selected == 1) {
                     foreach ($customer_tax as $cs2) {
                         $tax_amount = 0;
                         $tax_amount_bal = 0;
                         if ($schedule_additional->due_amount - $schedule_additional->amount_paid != 0) {
                             $this->db->select('tax_slab.tax_percentage as tax_percentage');
                             $this->db->from('tax_slab');
                             $this->db->join('tax_slab_cost_head', 'tax_slab.id=tax_slab_cost_head.tax_slab_id');
                             $this->db->where(array('tax_master_id' => $cs2->id, 'from_date <=' => $due_date_db, 'to_date >=' => $due_date_db, 'tax_slab_cost_head.cost_head_id' => $schedule->payment_type));
                             $applicale_tax = $this->db->get()->first_row();
                             if (!empty($applicale_tax->tax_percentage)) {
                                 $tax_amount = ($schedule_additional->due_amount - $schedule_additional->amount_paid) / 100 * $applicale_tax->tax_percentage;
                                 $tax_amount_tot += $tax_amount;
                             }
                         }
                     }
                 } else {
                     $tax_amount = 0;
                 }
                 //echo $schedule_additional->due_date . ' - ' . $due_date_db . ' - ' . $delay . '<br />';
                 if ($delay < 90) {
                     $due_report[$customer->id]['due_amount'][1] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 90 and $delay < 180) {
                     $due_report[$customer->id]['due_amount'][2] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 180 and $delay < 270) {
                     $due_report[$customer->id]['due_amount'][3] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 270 and $delay < 365) {
                     $due_report[$customer->id]['due_amount'][4] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 365 and $delay < 540) {
                     $due_report[$customer->id]['due_amount'][5] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot;
                 }
                 if ($delay >= 540 and $delay < 720) {
                     $due_report[$customer->id]['due_amount'][6] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot;
                 }
                 if ($delay > 720) {
                     $due_report[$customer->id]['due_amount'][7] += $schedule_additional->due_amount - $schedule_additional->amount_paid + $tax_amount_tot;
                 }
             }
             //Receipts
             foreach ($receipts as $b => $receipt) {
                 $due_report[$customer->id]['total_pri'] += $receipt->principle_amount;
                 $due_report[$customer->id]['total_tx'] += $receipt->amount_paid - $receipt->principle_amount;
                 $due_report[$customer->id]['total_amt'] += $receipt->amount_paid;
             }
         }
         //print_r($due_report);
         //exit();
         if (isset($_POST['generate_pdf'])) {
             $this->load->library('Pdf');
             $this->db->select('company.name,project.project_type');
             $this->db->from('company');
             $this->db->join('project', 'project.company_id=company.id');
             $this->db->join('customer_file', 'customer_file.project_id=project.id');
             $company_details = $this->db->get()->first_row();
             $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
             $pdf->SetCreator(PDF_CREATOR);
             $pdf->SetTitle('Receipt');
             //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '', array(0, 64, 255), array(255, 255, 255));
             $pdf->SetPrintFooter(false);
             $pdf->setPrintHeader(false);
             //$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
             //$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
             $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
             $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
             //$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
             //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
             $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
             $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
             if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
                 require_once dirname(__FILE__) . '/lang/eng.php';
                 $pdf->setLanguageArray($l);
             }
             $pdf->setFontSubsetting(true);
             $pdf->SetFont('dejavusans', '', 7, '', true);
             $pdf->AddPage();
             $pdf->writeHTMLCell(211, 17, '0', 10, '<h2 style="text-align:center;">' . $company_details->name . '</h2>', 0, 1, 0, true, '', true);
             $style = array('width' => 0.1, 'color' => array(0, 0, 0));
             $pdf->Line(0, 25, 220, 25, $style);
             if ($with_tax_selected == 1) {
                 $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Customer Wise Aging Report - With Tax</h2>', 0, 1, 0, true, '', true);
             } else {
                 $pdf->writeHTMLCell(0, 0, '', '', '<h2 style="text-align:center;">Customer Wise Aging Report - without Tax</h2>', 0, 1, 0, true, '', true);
             }
             $style = array('width' => 0.1, 'color' => array(0, 0, 0));
             $pdf->Line(0, 35, 220, 35, $style);
             $pdf->writeHTMLCell(35, 0, 10, 40, '<strong style="text-align:center;">Period : ' . date('M Y', strtotime($due_date_db)) . '</strong>', 0, 1, 0, true, '', true);
             $pdf->writeHTMLCell(35, 0, 168, 40, '<strong style="text-align:center;">Date : ' . date('d-m-Y') . '</strong>', 0, 1, 0, true, '', true);
             $html .= '<tr><td></td><td><td/></tr></table><br /><br /><br /><br />';
             $html .= '<table  border="1" cellpadding="5" cellspacing = "0" width = "100%" nobr="true"><thead><tr>';
             $html .= '<th width="25">No.</th>';
             $html .= '<th width="75">Client Name</th>';
             $html .= '<th width="60">0-3 Month</th>';
             $html .= '<th width="60">3-6 Month</th>';
             $html .= '<th width="60">6-9 Month</th>';
             $html .= '<th width="60">9-12 Month</th>';
             $html .= '<th width="60">1-1.5 Yrs</th>';
             $html .= '<th width="60">1.5-2 Yrs</th>';
             $html .= '<th width="60">Above 2 Yrs</th>';
             $html .= '<th width="60">Total</th>';
             $html .= '<th width="60">Tools</th>';
             $html .= '</tr>';
             $html .= '</thead><tbody>';
             $total_sale_amount = 0;
             $total_due_amount = 0;
             $total_due_amount_additional = 0;
             $total_due_tax = 0;
             $total_due_tax_additional = 0;
             $total_collection = 0;
             $total_balance = 0;
             foreach ($due_report as $due) {
                 $dues = $due['due_amount'];
                 $html .= '<tr>';
                 $html .= '<td width="25">' . ($n + 1) . '</td>';
                 $html .= '<td width="75">' . $due['client_name'] . '</td>';
                 foreach ($dues as $d => $du) {
                     $html .= '<td width="60">' . number_format($du) . '</td>';
                 }
                 $html .= '<td width="60">' . number_format($due['total_due_amount']) . '</td>';
                 $html .= '<td width="60"></td>';
                 $html .= '</tr>';
                 $n++;
             }
             $html .= '</tbody>';
             $html .= '</table><br /><br />';
             //echo $html;
             //exit();
             $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
             $pdf->Output('receipt.pdf', 'I');
         } elseif (isset($_POST['generate_csv'])) {
             $csv_array = array();
             $csv_array_line = array();
             $csv_array_line[] = 'No.';
             $csv_array_line[] = 'Client Name';
             $csv_array_line[] = '0-3 Month';
             $csv_array_line[] = '3-6 Month';
             $csv_array_line[] = '6-9 Month';
             $csv_array_line[] = '9-12 Month';
             $csv_array_line[] = '1-1.5 Yrs';
             $csv_array_line[] = '1.5-2 Yrs';
             $csv_array_line[] = 'Above 2 Yrs';
             $csv_array_line[] = 'Total';
             $csv_array[] = $csv_array_line;
             $csv_array_line = array();
             $n = 1;
             foreach ($due_report as $due) {
                 $total_due = 0;
                 $dues = $due['due_amount'];
                 $csv_array_line = array();
                 $csv_array_line[] = $n;
                 $csv_array_line[] = $due['client_name'];
                 foreach ($dues as $d => $du) {
                     $total_due += $du;
                     $csv_array_line[] = $du;
                 }
                 $csv_array_line[] = $due['total_due_amount'];
                 $csv_array[] = $csv_array_line;
                 $n = $n + 1;
             }
             echo array_to_csv($csv_array, 'interaction_report.csv');
             exit;
         } else {
             $data['due_report'] = $due_report;
             $data['with_tax_selected'] = $with_tax_selected;
             $data['project_selected'] = $project_selected;
             $data['due_date_selected'] = $due_date_selected;
             $this->load->view('reports/customer_wise_aging', $data);
         }
     }
 }
Example #26
0
 function generatePDF($action = 'return')
 {
     if (!in_array($action, ['return', 'dump'])) {
         throw $this->exception('Please provide action as result or dump');
     }
     $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('xEpan ERP');
     $pdf->SetTitle($this['type'] . ' ' . $this['document_no']);
     $pdf->SetSubject($this['type'] . ' ' . $this['document_no']);
     $pdf->SetKeywords($this['type'] . ' ' . $this['document_no']);
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set font
     $pdf->SetFont('dejavusans', '', 10);
     //remove header or footer hr lines
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     // add a page
     $pdf->AddPage();
     if ($org = $this->ref('contact_id')->get('organization')) {
         $this['contact'] = $org;
         $this['contact_id'] = '';
     }
     // getting layouts from config
     $layout_m = $this->add('xepan\\base\\Model_ConfigJsonModel', ['fields' => ['master' => 'xepan\\base\\RichText', 'detail' => 'xepan\\base\\RichText'], 'config_key' => strtoupper($this['type']) . '_LAYOUT', 'application' => 'commerce']);
     $layout_m->tryLoadAny();
     $info_config = $layout_m['master'];
     $info_layout = $this->add('GiTemplate');
     $info_layout->loadTemplateFromString($info_config);
     $detail_config = $layout_m['detail'];
     $detail_layout = $this->add('GiTemplate');
     $detail_layout->loadTemplateFromString($detail_config);
     $new = $this->add('xepan\\commerce\\Model_QSP_Master');
     $new->addHook('afterLoad', function ($m) {
         $m['round_amount'] = abs($m['round_amount']);
     });
     $new->load($this->id);
     $view = $this->app->add('xepan\\commerce\\View_QSP', ['qsp_model' => $new, 'master_template' => $info_layout, 'detail_template' => $detail_layout, 'action' => 'pdf']);
     // $view = $this->owner->add('xepan\commerce\View_QSP',['qsp_model'=>$this]);
     if ($bar_code = $this->getBarCode()) {
         $barcodeobj = new \TCPDFBarcode($bar_code, 'C128');
         // $barcode_html = $barcodeobj->getBarcodePNG(2, 30, 'black');
         $barcode_html = $barcodeobj->getBarcodePngData(1, 20, array(0, 128, 0));
         $info_layout->trySetHtml('dispatch_barcode', '<img src="data:image/png;base64, ' . base64_encode($barcode_html) . '"/>');
     }
     $html = $view->getHTML();
     // echo "string".$html;
     // echo $html;
     // exit;
     // output the HTML content
     $pdf->writeHTML($html, false, false, true, false, '');
     // set default form properties
     $pdf->setFormDefaultProp(array('lineWidth' => 1, 'borderStyle' => 'solid', 'fillColor' => array(255, 255, 200), 'strokeColor' => array(255, 128, 128)));
     // reset pointer to the last page
     $pdf->lastPage();
     //Close and output PDF document
     switch ($action) {
         case 'return':
             return $pdf->Output(null, 'S');
             break;
         case 'dump':
             return $pdf->Output(null, 'I');
             exit;
             break;
     }
 }
Example #27
0
 public function salary_ocsc_ktb()
 {
     if (Session::get('level') != '') {
         $n = DB::select('select * from s_general_data');
         foreach ($n as $k) {
             $name = $k->name;
             $address = $k->address;
             $tax_id = $k->tax_id;
         }
         $sql = ' select s.bank_acc, concat(n.pname,"",n.fname," ",n.lname) as name';
         $sql .= ' , s.salary, s.r_c, s.special, s.son, s.r_pt, s.r_other, s.kbk, s.tax';
         $sql .= ' , s.cas, s.save_p, s.houseLoan, s.save_h, s.p_other, s.shop, s.rice';
         $sql .= ' , s.water, s.elec, s.pt, s.bank_o, s.fund_p';
         $sql .= ' from s_salary_ocsc_detail s';
         $sql .= ' left join n_datageneral n on n.cid=s.cid';
         $sql .= ' where  month(s.order_date)=' . $this->max_month() . ' and year(s.order_date)=' . $this->max_year();
         $sql .= ' order by n.datainfoID asc';
         $result = DB::select($sql);
         $pdf = new TCPDF();
         $pdf->SetPrintHeader(true);
         $pdf->SetPrintFooter(true);
         $pdf->SetHeaderData('', '', 'รายการนำฝากเงินเดือน ลูกจ้างประจำ/ข้าราชการ ' . $name, '  เข้าบัญชีธนาคารกรุงไทย    ประจำเดือน  ' . $this->get_monthyearThai($this->max_month(), $this->max_year()));
         $pdf->setHeaderFont(array('freeserif', '', 12));
         $pdf->setFooterFont(array('freeserif', '', PDF_FONT_SIZE_DATA));
         // set default monospaced font
         $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
         // set margins
         $pdf->SetMargins(10, PDF_MARGIN_TOP, 10);
         $pdf->SetHeaderMargin(10);
         $pdf->SetFooterMargin(10);
         $pdf->SetFont('freeserif', '', 12, '', true);
         $pdf->AddPage('P', 'A4');
         $tbl = ' <style> ';
         $tbl .= '  table.table-report tr td { border-bottom:1px dashed #000; height:35px; line-height: 35px; } ';
         $tbl .= '  table.table-report tr th { border-bottom:2px solid #000; border-top:2px solid #000; height:35px; line-height: 25px; }';
         $tbl .= ' .text-bold { font-weight: bold; } hr { border:2px solid #000; }';
         $tbl .= ' table.table-sum tr td { font-weight: bold; font-size: 14px; }';
         $tbl .= ' table.table-textthai { font-weight: bold; font-size: 14px; border-bottom:2px solid #000; } ';
         $tbl .= ' </style> ';
         $tbl .= ' <table class="table-report"> ';
         $tbl .= '<tr>';
         $tbl .= '<th>เลขที่บัญชี</th> <th>ชื่อ-นามสกุล</th> <th align="right">จำนวนเงิน</th>';
         $tbl .= '</tr>';
         $r = 0;
         $salary_sum = 0;
         foreach ($result as $key) {
             $r++;
             $tbl .= ' <tr>';
             $tbl .= ' <td class="text-bold" width="120">';
             $tbl .= $key->bank_acc;
             $tbl .= ' </td>';
             $tbl .= ' <td  width="210" align="left">';
             $tbl .= $key->name;
             $tbl .= ' </td>';
             $tbl .= ' <td width="210" align="right" >';
             $tbl .= number_format($key->salary + $key->r_c + $key->son + $key->r_other - ($key->kbk + $key->tax + $key->cas + $key->save_p + $key->houseLoan) - ($key->save_h + $key->p_other + $key->shop + $key->rice + $key->water + $key->elec + $key->pt + $key->bank_o + $key->fund_p), 2);
             $tbl .= ' </td>';
             $tbl .= ' </tr>';
             $salary_sum = $salary_sum + ($key->salary + $key->r_c + $key->son + $key->r_other - ($key->kbk + $key->tax + $key->cas + $key->save_p + $key->houseLoan) - ($key->save_h + $key->p_other + $key->shop + $key->rice + $key->water + $key->elec + $key->pt + $key->bank_o + $key->fund_p));
         }
         $tbl .= '</table>';
         $tbl .= ' <br /><br />';
         $tbl .= ' <table class="table-sum">';
         $tbl .= ' <tr>';
         $tbl .= ' <td width="70">รวม:</td><td>' . $r . '  ราย</td> <td width="200" align="right">รวมเป็นเงิน</td><td align="right">' . number_format($salary_sum, 2) . '</td>';
         $tbl .= ' </tr>';
         $tbl .= ' </table>';
         $tbl .= ' <br /><br />';
         $tbl .= ' <table class="table-textthai">';
         $tbl .= ' <tr>';
         $tbl .= ' <td width="540" align="right">' . $this->ThaiBahtConversion($salary_sum) . '</td>';
         $tbl .= ' </tr>';
         $tbl .= ' </table>';
         $tbl .= ' <br /><br />';
         $tbl .= ' <table class="">';
         $tbl .= ' <tr>';
         $tbl .= ' <td width="240" height="30" align="left">ลงชื่อผู้นำส่ง.........................................</td> <td width="240" align="left">ลงชื่อผู้รับ.........................................</td>';
         $tbl .= ' </tr>';
         $tbl .= ' <tr>';
         $tbl .= ' <td width="240" align="left">วันที่.................................................</td> <td width="240" align="left">วันที่...............................................</td>';
         $tbl .= ' </tr>';
         $tbl .= ' </table>';
         $pdf->writeHTML($tbl, true, false, false, false, '');
         $filename = storage_path() . '/report_salary_ocsc_ktb.pdf';
         // Response::download($filename);
         $contents = $pdf->output($filename, 'I');
         $headers = array('Content-Type' => 'application/pdf');
         return Response::make($contents, 200, $headers);
     } else {
         return View::make('login.index');
     }
 }
Example #28
0
 protected function renderPDFIntoFile($template, $filename)
 {
     require_once DIR_SYSTEM . 'tcpdf/config/lang/eng.php';
     require_once DIR_SYSTEM . 'tcpdf/tcpdf.php';
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     //set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     //set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     //set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     //set some language-dependent strings
     $pdf->setLanguageArray($l);
     // ---------------------------------------------------------
     // set font
     $pdf->SetFont('dejavusans', '', 10);
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     // add a page
     $pdf->AddPage();
     $tablecontent = $this->fetch($template);
     // output the HTML content
     $pdf->writeHTML($tablecontent, true, false, true, false, '');
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     // reset pointer to the last page
     $pdf->lastPage();
     // ---------------------------------------------------------
     //Close and output PDF document
     $pdf->Output('invoice' . $filename . '.pdf', 'F');
     //============================================================+
     // END OF FILE
     //============================================================+
 }
Example #29
0
$foto = "profile.jpg";
$cknama = $this->db->get_where('view_member', array('kode' => $kode))->result();
foreach ($cknama as $row) {
    $nama = $row->nama;
    $tgl = date('d-m-Y', strtotime($row->tgl_lahir));
    $tempat = $row->tempat_lahir;
    $jns = strtoupper($row->nama_tipe);
}
$ckhasil = $this->db->get_where('tbl_status_izajah', array('id' => $status))->result();
foreach ($ckhasil as $key) {
    $hasil = $key->status;
}
$obj_pdf->SetTitle($toko);
$obj_pdf->SetHeaderData("", "", "", "");
$obj_pdf->SetPrintHeader(FALSE);
$obj_pdf->SetPrintFooter(FALSE);
$obj_pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', 9));
$obj_pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('helvetica');
$obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(10, 34, 10);
$obj_pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);
$obj_pdf->SetFont('helvetica', '', 10);
$obj_pdf->setFontSubsetting(FALSE);
$obj_pdf->SetDisplayMode('fullpage', 'SinglePage', 'UseNone');
$obj_pdf->AddPage();
$obj_pdf->SetFont("helvetica", '', 20);
$obj_pdf->Ln(107);
$obj_pdf->MultiCell(180, 10, $no, 0, 'C', 0, 1, '', '', true, 0, false, true, 10, 'B');
$obj_pdf->Ln(30);
Example #30
0
/**
 * Creates the PDF version (downloadable) of the whole feedback produced by the teacher/tutor
 *
 * @param unknown $draft            
 * @param unknown $student            
 * @param unknown $context            
 * @param unknown $cmid            
 * @return boolean
 */
function emarking_create_response_pdf($draft, $student, $context, $cmid)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/pdflib.php';
    $fs = get_file_storage();
    if (!($submission = $DB->get_record('emarking_submission', array('id' => $draft->submissionid)))) {
        return false;
    }
    if (!($pages = $DB->get_records('emarking_page', array('submission' => $submission->id, 'student' => $student->id), 'page ASC'))) {
        return false;
    }
    if (!($emarking = $DB->get_record('emarking', array('id' => $submission->emarking)))) {
        return false;
    }
    $numpages = count($pages);
    $sqlcomments = "SELECT ec.id,\n\t\t\tec.posx,\n\t\t\tec.posy,\n\t\t\tec.rawtext,\n\t\t\tec.pageno,\n\t\t\tgrm.maxscore,\n\t\t\tec.levelid,\n\t\t\tec.width,\n\t\t\tec.colour,\n\t\t\tec.textformat,\n\t\t\tgrl.score AS score,\n\t\t\tgrl.definition AS leveldesc,\n\t\t\tgrc.id AS criterionid,\n\t\t\tgrc.description AS criteriondesc,\n\t\t\tu.id AS markerid, CONCAT(u.firstname,' ',u.lastname) AS markername\n\t\t\tFROM {emarking_comment} AS ec\n\t\t\tINNER JOIN {emarking_page} AS ep ON (ec.draft = :draft AND ec.page = ep.id)\n\t\t\tLEFT JOIN {user} AS u ON (ec.markerid = u.id)\n\t\t\tLEFT JOIN {gradingform_rubric_levels} AS grl ON (ec.levelid = grl.id)\n\t\t\tLEFT JOIN {gradingform_rubric_criteria} AS grc ON (grl.criterionid = grc.id)\n\t\t\tLEFT JOIN (\n\t\t\tSELECT grl.criterionid, max(score) AS maxscore\n\t\t\tFROM {gradingform_rubric_levels} AS grl\n\t\t\tGROUP BY grl.criterionid\n\t\t\t) AS grm ON (grc.id = grm.criterionid)\n\t\t\tWHERE ec.pageno > 0\n\t\t\tORDER BY ec.pageno";
    $params = array('draft' => $draft->id);
    $comments = $DB->get_records_sql($sqlcomments, $params);
    $commentsperpage = array();
    foreach ($comments as $comment) {
        if (!isset($commentsperpage[$comment->pageno])) {
            $commentsperpage[$comment->pageno] = array();
        }
        $commentsperpage[$comment->pageno][] = $comment;
    }
    // Parameters for PDF generation
    $iconsize = 5;
    $tempdir = emarking_get_temp_dir_path($emarking->id);
    if (!file_exists($tempdir)) {
        mkdir($tempdir);
    }
    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    // set document information
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor($student->firstname . ' ' . $student->lastname);
    $pdf->SetTitle($emarking->name);
    $pdf->SetSubject('Exam feedback');
    $pdf->SetKeywords('feedback, emarking');
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    // set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 036', PDF_HEADER_STRING);
    // set header and footer fonts
    $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    // set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    // set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    // set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    // set some language-dependent strings (optional)
    if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
        require_once dirname(__FILE__) . '/lang/eng.php';
        $pdf->setLanguageArray($l);
    }
    // ---------------------------------------------------------
    // set font
    $pdf->SetFont('times', '', 16);
    foreach ($pages as $page) {
        // add a page
        $pdf->AddPage();
        // get the current page break margin
        $bMargin = $pdf->getBreakMargin();
        // get current auto-page-break mode
        $auto_page_break = $pdf->getAutoPageBreak();
        // disable auto-page-break
        $pdf->SetAutoPageBreak(false, 0);
        // set bacground image
        $pngfile = $fs->get_file_by_id($page->file);
        $img_file = emarking_get_path_from_hash($tempdir, $pngfile->get_pathnamehash());
        $pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
        // restore auto-page-break status
        // $pdf->SetAutoPageBreak($auto_page_break, $bMargin);
        // set the starting point for the page content
        $pdf->setPageMark();
        $dimensions = $pdf->getPageDimensions();
        if (isset($commentsperpage[$page->page])) {
            foreach ($commentsperpage[$page->page] as $comment) {
                $content = $comment->rawtext;
                $posx = (int) ((double) $comment->posx * $dimensions['w']);
                $posy = (int) ((double) $comment->posy * $dimensions['h']);
                if ($comment->textformat == 1) {
                    // text annotation
                    $pdf->Annotation($posx, $posy, 6, 6, $content, array('Subtype' => 'Text', 'StateModel' => 'Review', 'State' => 'None', 'Name' => 'Comment', 'NM' => 'Comment' . $comment->id, 'T' => $comment->markername, 'Subj' => 'example', 'C' => array(0, 0, 255)));
                } elseif ($comment->textformat == 2) {
                    $content = $comment->criteriondesc . ': ' . round($comment->score, 1) . '/' . round($comment->maxscore, 1) . "\n" . $comment->leveldesc . "\n" . get_string('comment', 'mod_emarking') . ': ' . $content;
                    // text annotation
                    $pdf->Annotation($posx, $posy, 6, 6, $content, array('Subtype' => 'Text', 'StateModel' => 'Review', 'State' => 'None', 'Name' => 'Comment', 'NM' => 'Mark' . $comment->id, 'T' => $comment->markername, 'Subj' => 'grade', 'C' => array(255, 255, 0)));
                } elseif ($comment->textformat == 3) {
                    $pdf->Image($CFG->dirroot . "/mod/emarking/img/check.gif", $posx, $posy, $iconsize, $iconsize, '', '', '', false, 300, '', false, false, 0);
                } elseif ($comment->textformat == 4) {
                    $pdf->Image($CFG->dirroot . "/mod/emarking/img/crossed.gif", $posx, $posy, $iconsize, $iconsize, '', '', '', false, 300, '', false, false, 0);
                }
            }
        }
    }
    // ---------------------------------------------------------
    // COGIDO PARA IMPRIMIR RÚBRICA
    if ($emarking->downloadrubricpdf) {
        $cm = new StdClass();
        $rubricdesc = $DB->get_recordset_sql("SELECT\n\t\td.name AS rubricname,\n\t\ta.id AS criterionid,\n\t\ta.description ,\n\t\tb.definition,\n\t\tb.id AS levelid,\n\t\tb.score,\n\t\tIFNULL(E.id,0) AS commentid,\n\t\tIFNULL(E.pageno,0) AS commentpage,\n\t\tE.rawtext AS commenttext,\n\t\tE.markerid AS markerid,\n\t\tIFNULL(E.textformat,2) AS commentformat,\n\t\tIFNULL(E.bonus,0) AS bonus,\n\t\tIFNULL(er.id,0) AS regradeid,\n\t\tIFNULL(er.motive,0) AS motive,\n\t\ter.comment AS regradecomment,\n\t\tIFNULL(er.markercomment, '') AS regrademarkercomment,\n\t\tIFNULL(er.accepted,0) AS regradeaccepted\n\t\tFROM {course_modules} AS c\n\t\tINNER JOIN {context} AS mc ON (c.id = :coursemodule AND c.id = mc.instanceid)\n\t\tINNER JOIN {grading_areas} AS ar ON (mc.id = ar.contextid)\n\t\tINNER JOIN {grading_definitions} AS d ON (ar.id = d.areaid)\n\t\tINNER JOIN {gradingform_rubric_criteria} AS a ON (d.id = a.definitionid)\n\t\tINNER JOIN {gradingform_rubric_levels} AS b ON (a.id = b.criterionid)\n\t\tLEFT JOIN (\n\t\tSELECT ec.*, d.id AS draftid\n\t\tFROM {emarking_comment} AS ec\n\t\tINNER JOIN {emarking_draft} AS d ON (d.id = :draft AND ec.draft = d.id)\n\t\t) AS E ON (E.levelid = b.id)\n\t\tLEFT JOIN {emarking_regrade} AS er ON (er.criterion = a.id AND er.draft = E.draftid)\n\t\tORDER BY a.sortorder ASC, b.score ASC", array('coursemodule' => $cmid, 'draft' => $draft->id));
        $table = new html_table();
        $data = array();
        foreach ($rubricdesc as $rd) {
            if (!isset($data[$rd->criterionid])) {
                $data[$rd->criterionid] = array($rd->description, $rd->definition . " (" . round($rd->score, 2) . " ptos. )");
            } else {
                array_push($data[$rd->criterionid], $rd->definition . " (" . round($rd->score, 2) . " ptos. )");
            }
        }
        $table->data = $data;
        // add extra page with rubrics
        $pdf->AddPage();
        $pdf->Write(0, 'Rúbrica', '', 0, 'L', true, 0, false, false, 0);
        $pdf->SetFont('helvetica', '', 8);
        $tbl = html_writer::table($table);
        $pdf->writeHTML($tbl, true, false, false, false, '');
    }
    // ---------------------------------------------------------
    $pdffilename = 'response_' . $emarking->id . '_' . $draft->id . '.pdf';
    $pathname = $tempdir . '/' . $pdffilename;
    if (@file_exists($pathname)) {
        unlink($pathname);
    }
    // Close and output PDF document
    $pdf->Output($pathname, 'F');
    // Copiar archivo desde temp a �rea
    $file_record = array('contextid' => $context->id, 'component' => 'mod_emarking', 'filearea' => 'response', 'itemid' => $student->id, 'filepath' => '/', 'filename' => $pdffilename, 'timecreated' => time(), 'timemodified' => time(), 'userid' => $student->id, 'author' => $student->firstname . ' ' . $student->lastname, 'license' => 'allrightsreserved');
    // Si el archivo ya existía entonces lo borramos
    if ($fs->file_exists($context->id, 'mod_emarking', 'response', $student->id, '/', $pdffilename)) {
        $previousfile = $fs->get_file($context->id, 'mod_emarking', 'response', $student->id, '/', $pdffilename);
        $previousfile->delete();
    }
    $fileinfo = $fs->create_file_from_pathname($file_record, $pathname);
    return true;
}