<?php namespace App\Controllers;
require __DIR__ . '/fp/fpdf.php';
// require __DIR__ . '/fp/writeHTML.php';

//require __DIR__.'/fp/exfpdf.php';
use FPDF;


class Proforma extends FPDF {
    public function createProforma($app, $fileName) {

        $this->AliasNbPages();
        $this->AddPage();
        $this->SetFont('Times', '', 14);
        $image = 'public/images/logo.png';
        $this->Image($image, 0, 0, 0);
        $this->SetY(50);
        $this->SetX(90);
        $this->SetX(-30);
        $this->Cell(85, 8, $app['date'], 0, 1);
        //$this->SetX(0);
        $this->Cell(85, 4, '', 0, 1);
        $this->Cell(85, 4, '', 0, 1);
        $this->Cell(85, 8, 'Dear ' . $app['name'] . ',', 0, 1);
        $this->SetFont('Times', 'BU', 14);
        $this->Cell(85, 8, 'SUBJECT: INVITATION TO ATTEND A TRAINING COURSE', 0, 1);

        $this->SetFont('Times', 'B', 14);
         $this->Rect($this->GetX(),$this->GetY(),0,0);
        $this->Write(5, 'Soaring Skills Training Institute ', 0, 1);

        $this->SetFont('Times', '', 14);
        $this->Write(5,  'is happy to invite you to participate in a ', 0, 1);

        $this->SetFont('Times', 'B', 14);
        $this->Rect($this->GetX(),$this->GetY(),0,0);
        $this->Write(5, '' . $app['duration'] . ' ' . $app['durationIn'] . ' training course on ' . $app['courseName'] . '', 0, 1);

        $this->SetFont('Times', '', 14);
        $this->Write(5, 'to be held from ', 0, 1);

        $this->SetFont('Times', 'B', 14);
        $this->Rect($this->GetX(),$this->GetY(),0,0);
        $this->Write(5, '' . $app['startDate'] . ' to ' . $app['endDate'] . ' at Soaring Skills Training Institute, Nairobi Kenya ', 'L');
        $this->Cell(120, 8, '', 0, 1);

        $this->SetFont('Times', 'B', 14);
        $this->Cell(120, 8, 'Minimum Requirements:', 0, 1);
        $this->SetFont('Times', '', 14);
        $this->Write(5, 'All facilitation and materials will be offered in English. The participant should be sufficiently proficient in English', 0,1);
        $this->Cell(120, 8, '', 0, 1);
        $this->SetFont('Times', 'B', 14);
        $this->Cell(120, 8, 'Training  Venue and Catering:', 0, 1);
        $this->SetFont('Times', '', 14);
        $this->Write(5, 'The training will be held at Soaring Skills Training Institute in Nairobi Kenya. Accommodation will be catered for by the participant.', 0, 1);

        $this->Cell(120, 8, '', 0, 1);
        $this->SetFont('Times', 'B', '14');
        $this->Cell(160 ,8, 'Total Participation Fee', 0, 1);

         $totalAccommodationFee = 0;
        if ($app['accomodation'] == 'Yes' ) {
            $durationType = $app['durationIn'];
            $duration = $app['duration'] + 1;
            $accommodationFee = 100;
            $weeklyAccommodationFee = 5 * $accommodationFee;
            $monthlyAccommodationFee = $weeklyAccommodationFee * 4;
            $yearlyAccommodationFee = $monthlyAccommodationFee * 12;
            if ($durationType == 'Days') {
                $totalAccommodationFee = $duration * $accommodationFee;
            } else if ($durationType == 'Weeks') {
                $totalAccommodationFee = $weeklyAccommodationFee * $duration;
            } else if ($durationType == 'Months') {
                $totalAccommodationFee = $monthlyAccommodationFee * $duration;
            } else if ($durationType == 'Years') {
                $totalAccommodationFee = $yearlyAccommodationFee * $duration;
            }
        }

        if ($app['airport'] == 'Yes') {
            $totalAirportFee = 100;
        } else
            $totalAirportFee = 0;

            $totalFees = $app['fees'];
        $totalFees += $totalAccommodationFee + $totalAirportFee;


        $this->Cell(160, 8, 'USD ' . $totalFees . ' (Total Participation fee for ' . $app['duration'] . ' days)  ', 0, 1);

        // Last Edit


        $this->SetFont('Times', 'B', 14);
        $this->Cell(120, 8, 'Enquire:', 0, 1);
        $this->SetFont('Times', '', 14);
        $this->Cell(160, 9, 'For any enquiry regarding this course contact us on training@soaringskillsinstitute.com', 0, 1);
        $this->SetFont('Times', 'B', 14);
        $this->Cell(120, 8, 'Payment:', 0, 1);
        $this->SetFont('Times', '', 14);
        $this->Cell(160, 10, 'Payment should be made to Soaring Skills Training Institute bank account before the course begins. ', 0, 1);
        $this->Cell(160, 8, 'Yours Sincerely,', 0, 1);
        $this->Cell(160, 8, 'Signed', 0, 1);
        $this->SetFont('Times', 'BI', 14);
        $this->Cell(120, 8, 'A.M:', 0, 1);
        // $this->SetY(173);
        $this->Cell(160, 8, 'Amos Mwangi', 0, 1);
        $this->Cell(160, 8, 'Training Director', 0, 1);

        $this->SetFont('Times', '', 14);
        $this->Cell(160, 8, 'Soaring Skills Training Institute', 0, 1);
        $this->Cell(160, 8, 'Phone:+254 746 038 012', 0, 1);
        $this->Cell(160, 8, 'Email Address: training@soaringskillsinstitute.com', 0, 1);
        $this->Cell(160, 8, 'Nairobi, Kenya', 0, 1);


        /* Data loading */
        // $data = $this->LoadData('data.txt');
        $this->SetFont('Arial', '', 14);
        $this->AddPage();
        $image = 'public/images/logo.png';
        $this->Image($image, 0, 0, 0);

        $this->SetY(40);
        $this->SetX(90);
        //invoice contents
        $this->SetFont('Arial', 'B', 14);
        $this->SetX(30);
        $this->Cell(85, 8, 'Taxpayer PIN: P051741687Z', 0, 1);
        $this->SetX(30);
        $this->Cell(85, 8, 'Organisation. Registration No: CPR/2014/147006', 0, 1);
        $this->SetX(30);
        $this->Cell(85, 8, 'INVOICE No: SSA-' . $app['invoiceId'] . '', 0, 1);
        $this->SetX(30);
        $this->Cell(85, 8, 'Personal Data', 0, 1);
        $this->SetFont('Arial', '', 14);

        //Numbers are right-aligned so we give 'R' after new line parameter

        $this->Cell(85, 8, 'Name:', 1, 0);
        $this->Cell(85, 8, '' . $app['name'] . '', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'Invoice No.:', 1, 0);
        $this->Cell(85, 8, '' . $app['invoiceId'] . '', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'Organization:', 1, 0);
        $this->Cell(85, 8, '' . $app['org'] . '', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'Email:', 1, 0);
        $this->Cell(85, 8, $app['email'] . '', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'Date:', 1, 0);
        $this->Cell(85, 8, $app['startDate'] . ' -' . $app['endDate'] . '', 1, 1, 'L');//end of line

        // $this->Cell(85 ,7,'Registrant No:',1,0);
        // $this->Cell(85 ,7,''.$app['userId'].'',1,1,'R');//end of line

        $this->Cell(85, 8, 'Country:', 1, 0);
        $this->Cell(85, 8, '' . $app['country'] . '', 1, 1, 'L');//end of line

        // $this->Cell(85, 8, 'Class Type:', 1, 0);
        // $this->Cell(85, 8, '' . $app['classType'] . '', 1, 1, 'L');//end of line

        $this->Cell(85, 16, 'Course Description:', 1, 0);
        $this->MultiCell(85, 8, '' .  ucwords(strtolower($app['courseName'])) . '', 1, 1);//end of line


         // $this->Ln(12, 0);
        // Course Cost Table Begins here


        $this->Cell(85, 8, 'Course Total Cost: (Total Amount in USD)', 0, 1);
        $this->SetFont('Arial', '', 14);

        //Numbers are right-aligned so we give 'R' after new line parameter

        $this->Cell(85, 8, 'Course fees:', 1, 0);
        $this->Cell(85, 8, 'USD ' . $app['fees'] . '', 1, 1, 'L');//end of line

         $totalAccommodationFee = 0;
        if ($app['accomodation'] == 'Yes' ) {
            $durationType = $app['durationIn'];
            $duration = $app['duration'] + 1;
            $accommodationFee = 100;
            $weeklyAccommodationFee = 5 * $accommodationFee;
            $monthlyAccommodationFee = $weeklyAccommodationFee * 4;
            $yearlyAccommodationFee = $monthlyAccommodationFee * 12;
            if ($durationType == 'Days') {
                $totalAccommodationFee = $duration * $accommodationFee;
            } else if ($durationType == 'Weeks') {
                $totalAccommodationFee = $weeklyAccommodationFee * $duration;
            } else if ($durationType == 'Months') {
                $totalAccommodationFee = $monthlyAccommodationFee * $duration;
            } else if ($durationType == 'Years') {
                $totalAccommodationFee = $yearlyAccommodationFee * $duration;
            }
        }

        $this->Cell(85, 8, 'Accomodation:', 1, 0);
        $this->Cell(85, 8, 'USD: ' . $totalAccommodationFee . '', 1, 1, 'L');//end of line

        if ($app['airport'] == 'Yes') {
            $totalAirportFee = 100;
        } else
            $totalAirportFee = 0;
        $this->Cell(85, 8, 'Airport Pick Up', 1, 0);
        $this->Cell(85, 8, 'USD: ' . $totalAirportFee . '', 1, 1, 'L');//end of line

        $totalFees = $app['fees'];
        $totalFees += $totalAccommodationFee + $totalAirportFee;

        $this->Cell(85, 8, 'Total Amount', 1, 0);
        $this->Cell(85, 8, 'USD: ' . $totalFees . '', 1, 1, 'L'); //end of line 

        // $this->Cell(85, 7, 'Total Amount (Kshs)', 1,0);
        // $this->Cell(85, 7, ''. $totalFees * 104 . '', 1,1, 'R');


        // $this->Ln(12, 0);


        // Cost table ends

        // Bank Details Table begins


       $this->SetX(30);
        $this->Cell(85, 8, 'Mode of Payment: Bank transfer', 0, 1, 'L');
        $this->SetFont('Arial', '', 14);

        //Numbers are right-aligned so we give 'R' after new line parameter

        $this->Cell(85, 8, 'Name of Bank::', 1, 0);
        $this->Cell(85, 8, 'KCB Bank Kenya Ltd', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'Branch:', 1, 0);
        $this->Cell(85, 8, 'Garden Mortgage Centre', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'SWIFT Code:', 1, 0);
        $this->Cell(85, 8, 'KCBLKENX', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'Bank Code:', 1, 0);
        $this->Cell(85, 8, '01290', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'Account Name:', 1, 0);
        $this->Cell(85, 8, 'Soaring Skills Training Institute Ltd', 1, 1, 'L');//end of line

        $this->Cell(85, 8, 'USD Account No:', 1, 0);
        $this->Cell(85, 8, '1319823289', 1, 1, 'L');

        // $this->Cell(85, 8, 'KSH Account No:', 1, 0);
        // $this->Cell(85, 8, '-', 1, 1, 'L');

        $this->Ln(15, 0);
        // Bank Details Table begins

        // End of page two


        // Page three

        // $this->SetFont('Arial','',14);
        $this->AddPage();
        $image = 'public/images/logo.png';
        $this->Image($image, 0, 0, 0);

        $this->SetY(45);
        $this->SetX(90);
        // Begin with regular font
        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, 'Terms and Conditions:', 0, 1);

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '1. Definitions and Application', 0, 1);
        $this->Ln();

        $this->SetFont('Arial', '', 9);
        $this->Write(5, 'If any legislation is compulsorily applicable to any business undertaken, these Terms and Conditions shall, as regards such business, be read as subject to such legislation and nothing in these Terms and Conditions shall be construed as a surrender by ', 0, 1);
         $this->Rect($this->GetX(),$this->GetY(),0,0);
        $this->SetFont('Arial','B',9);
        $this->Write(5,"Soaring Skills Training Institute", 0, 1);

        $this->SetFont('Arial', '', 9);
        $this->Write(5, '  of any of its rights or immunities or as an increase of any of its responsibilities or liabilities under such legislation and if any part of these Terms and Conditions be repugnant to such legislation to any extent such part shall as regards such business be overridden to that extent and no further.', 0, 1);
        $this->Ln();

        $this->SetY(85);
        $this->SetX(10);

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '2. Pricing:', 0,1);

        $this->SetFont('Arial', '', 9);
        $this->Write(5, 'Training Fee shall be charged at individual or group rates which includes facilitation and cost of workshop materials. All prices quoted are exclusive of VAT which will be added to all sums due under invoice.', 0, 1);

        $this->SetY(100);
        $this->SetX(10);

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '3. Training confirmation:', 0, 1);

        $this->SetFont('Arial', 'B', 9);
        $this->Write(5, 'Soaring Skills Training Institute Limited', 0, 1);

        $this->SetFont('Arial', '', 9);
        $this->Write(5, ' shall accept the client registration once the  training fee, as invoiced, have been paid in full.', 0, 1);

        $this->SetY(110);
        $this->SetX(10);
        $this->Ln();

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '4. Terms of Payment:', 0, 1);

        $this->SetFont('Arial', '', 9);
        $this->Write(5, 'Unless otherwise agreed between the two parties, the payment of the fee for the training program, as seen on our website, has to be paid 14 days before the training date to the following account details:', 0, 1);
        $this->Ln();
        $this->Ln();

        $this->SetY(130);
        $this->SetX(10);

        $this->SetFont('Arial', 'B', 9);
         $this->Write(5, '      Soaring Skills Training Institute  Limited
            Account Number:USD: 1319823289
            BANK: KCB Bank Kenya Ltd, Garden Mortgage Centre
            SWIFT Code:
            KCBLKENX
            Bank Code:01290', 0, 1);
         $this->Ln();

        $this->SetY(165);
        $this->SetX(10);

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '5. Validity of Offer:', 0, 1);

        // $this->SetY(160);
        $this->SetX(10);

        $this->SetFont('Arial', '', 9);
        $this->Write(5, 'Thirty days (30) from date of issue.', 0, 1);

        $this->SetY(175);
        $this->SetX(10);

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '6. Force Majeure:', 0, 1);

         $this->SetX(10);

        $this->SetFont('Arial', '', 9);
        $this->Write(5, 'Neither party will be liable for performance delays, nor for non performance due to causes beyond their reasonable control.', 0, 1);
        $this->SetY(185);
        $this->SetX(10);

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '7. Confidentiality:', 0, 1);

        $this->SetFont('Arial','', 9);
        $this->SetX(10);
        $this->Write(5, 'Confidential information includes without limitation, pricing, software and hardware products, product plans, marketing and sales information, business plans, customer and supplier data, financial and technical information, know how, trade secrets, and other information, whether such information is in written, oral, electronic, web based, or other form. These may not be divulged to any third party without prior written consent from',0, 1);

        $this->Rect($this->GetX(),$this->GetY(),0,0);

        $this->SetFont('Arial', 'B', 9);
        $this->Write(5, ' Soaring Skills Training Institute Limited.', 0, 0);

        $this->setFont('Arial', '', 9);
        $this->Write(5, ' The Client shall exercise the same degree of care as that used to protect their own confidential information but no less than reasonable care.',0, 1);
        $this->SetY(215);
        $this->SetX(10);

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '8. Jurisdiction and Law:', 0, 1);

        $this->SetFont('Arial','', 9);
        $this->SetX(10);
        $this->Write(5, 'These Terms and Conditions and any act or contract to which they apply shall be governed by the Laws of Kenya and any dispute arising out of any act or contract to which these Terms and Conditions apply shall be subject to the exclusive jurisdiction of the Courts of Kenya.',0, 1);

        $this->SetY(235);
        $this->SetX(10);

        $this->SetFont('Arial', 'B', 9);
        $this->Cell(85, 5, '9. Further Information:', 0, 1);

        $this->SetFont('Arial','', 9);
        $this->SetX(10);
        $this->Write(5, 'Please contact us in case you need clarification or further information.
Tel: +254 746 038 012
Email: training@soaringskillsinstitute.com', 1, 0);



        //$this->Output();
        $filename = "public/images/apps/invoice.pdf"; //.$fileName;
        $this->Output($filename, 'F');


    }

    // Page footer

    function Footer() {
        // Position at 1.5 cm from bottom
        $this->SetY(-15);
        // Arial italic 8
        $this->SetFont('Arial', 'I', 14);
        // Page number

        //$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
        $image = 'public/images/footer.png';
        $this->Image($image, 0, 271, 0, 0);
    }


    public function createInvoice() {

        $this->AliasNbPages();
        $this->AddPage();
        $this->SetFont('Times', '', 14);
        //for($i=1;$i<=40;$i++)
        //  $this->Cell(0,10,'Printing line number '.$i,0,1);

        $image = 'public/unify/img/logo.png';
        $this->Image($image, 85, 12, 50);
        $this->SetY(50);
        $this->SetX(90);
        $this->SetFont('Times', 'U', 14);
        $this->Cell(85, 4, 'www.soaringskillsinstitute.com ', 0, 1);
        $this->SetX(85);
        $this->Cell(85, 4, 'email:training@soaringskillsinstitute.com ', 0, 1);
        $this->SetX(93);
        $this->SetFont('Times', '', 14);
        $this->Cell(85, 4, 'Phone:+254 746 038 012  ', 0, 1);
        $this->SetX(914);
        $this->SetFont('Times', 'U', 14);
        $this->Cell(85, 4, 'INVOICE ', 0, 1);

        $this->SetFont('Times', '', 14);
        $this->SetX(-60);
        $this->Cell(85, 8, 'INVOICE DATE: June 29, 2020', 0, 1);
        $this->SetX(-60);
        $this->Cell(85, 8, 'INVOICE No: '.$app['invoiceId'], 0, 1);
        //$this->SetX(0);
        $this->Cell(85, 4, '', 0, 1);
        $this->Cell(85, 4, '', 0, 1);
        $this->Cell(85, 8, 'Bill To:', 0, 1);
        $this->SetFont('Times', '', 10);
        $this->Cell(85, 8, 'Name(s)', 0, 1);
        $this->Cell(85, 8, 'Phone: +254 746 038 012  ', 0, 1);
        $html = "<table><tr><th>DECRIPTION</th><th>PARTICIPANTS</th><th>RATE (Kshs)</th><th>TOTAL(Kshs)</th></tr>";
        $html .= "<tr><td></td><td></td><td></td><td></td></tr>";
        $html .= "<i>itali</i>";


        $this->WriteHTML($html);

        $header = array('DECRIPTION', 'PARTICIPANTS', 'RATE (Kshs)', 'TOTAL(Kshs)');

        //set font for apache_request_headers
        $this->SetFillColor(192,192,192);
    $this->SetTextColor(0);
    $this->SetDrawColor(0,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
        $w = array(60, 35, 40, 45);
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
    $this->Ln();
        $firstRow = array('Training Course on Strategic Development  hfhfhfhfhfhfhf', '1', '80 000', '80 000');




        $this->SetFillColor(255,255,255);
        $this->SetFont('','');
        $w = array(60, 35, 40, 45);
        for($i=0;$i<count($firstRow);$i++)
                $this->Cell($w[$i],7,$firstRow[$i],1,0,'C',true);





        $sectRow = array('Net Total', '', '', '80 000');
        $thirdRow = array('TOTAL AMOUNT', '', '', '80 000');



        $this->Output();

    }


}

?>
