<?php

        try{

        #GET LIBRARY
        require('fpdf.php');
        #GET LIBRARY

        $pdf     = new Fpdf();
        header('content-type:image/jpeg');

//                 $core_id                = $request->core_id;
//                 $final_action           = $request->final_action;
//                 $date                   = $request->date;
//                 $membership_number      = $request->membership_number;
//                 $loan_agreement_number  = $request->loan_agreement_number;
//                 $amount                 = $request->amount;
//                 $amount_from_word       = $request->amount_from_word;
//
//                 $member_1_name          = $request->member_1_name;
//                 $member_1_nic           = $request->member_1_nic;
//                 $member_1_address       = $request->member_1_address;
//
//                 $guarantor_1_name       = $request->guarantor_name;
//                 $guarantor_1_nic        = $request->guarantor_nic;
//                 $guarantor_1_address    = $request->guarantor_address;
//
//                 $k_2                    = $request->k_2;
//                 $k_3                    = $request->k_3;
//                 $k_4                    = $request->k_4;
//                 $k_5                    = $request->k_5;
//
//                 $k_6                    = $request->k_6;
//                 $k_7                    = $request->k_7;
//                 $k_8                    = $request->k_8;
//
//                 $saving_data            = DB::table('savings')->where('id',$core_id)->first();
//                 $borrower_data          = DB::table('borrowers')->where('id',$saving_data->borrower_id)->first();
//
//                 $borrower_address       = $borrower_data->borrower_address;
//                 $borrower_nic           = $borrower_data->borrower_nic;
//                 $borrower_name          = $borrower_data->borrower_name;


        for($a = 1; $a<4; $a++)
        {
                $source               = $_SERVER['DOCUMENT_ROOT']."/assets/kprint/la/image_".$a."_sinhala.jpg";

                $image                = imagecreatefromjpeg($source);

                $font                 = $_SERVER['DOCUMENT_ROOT']."/assets/kprint/font/OpenSans-Regular.ttf";
                $color                = imagecolorallocate($image,0,0,0);

                $data_all             = DB::table('savings')->where('id',$core_id)->first();

                switch($a)
                {
                    case 1:

                        $data_1         = $membership_number;
                        $data_2         = $loan_agreement_number;

                        imagettftext($image,37,0,2270,280,$color,$font,$data_1);
                        imagettftext($image,37,0,2270,380,$color,$font,$data_2);

                    break;
                   case 2:

                        $data_1             = $borrower_name;//"data 1 page 2";
                        $data_2             = $borrower_nic;//"data 2 page 2";
                        $data_3             = $borrower_address;//"data 3 page 2";

                        $data_4             = $member_1_name;//"data 4 page 2";
                        $data_5             = $member_1_nic;//"data 5 page 2";
                        $data_6             = $member_1_address;//"data 6 page 2";

                        $data_7             = $loan_agreement_number;//"data 7 page 2";
                        $data_8             = $date;//"data 8 page 2";
                        $data_9             = $membership_number;//"data 9 page 2";

                        $data_10            = $guarantor_1_name;//"data 10 page 2";
                        $data_11            = $guarantor_1_nic;//"data 11 page 2";
                        $data_12            = $guarantor_1_address;//"data 12 page 2";

                        $data_13            = $amount;//"data 13 page 2";
                        $data_14            = $k_2;//"data 14 page 2";
                        $data_15            = $k_3;//"data 15 page 2";
                        $data_16            = $k_4;//"data 16 page 2";
                        $data_17            = $k_5;//"data 17 page 2";
                        $data_18            = $k_6;//"data 18 page 2";
                        $data_19            = $k_7;//"data 19 page 2";
                        $data_20            = $k_8;//"data 20 page 2";

                        imagettftext($image,37,0,420,1800,$color,$font,$data_1); // 700 -> plus 1100
                        imagettftext($image,37,0,420,1940,$color,$font,$data_2);
                        imagettftext($image,37,0,420,2100,$color,$font,$data_3);
//
                        imagettftext($image,37,0,420,2530,$color,$font,$data_4);
                        imagettftext($image,37,0,420,2680,$color,$font,$data_5);
                        imagettftext($image,37,0,420,2820,$color,$font,$data_6);
//
                        imagettftext($image,37,0,2020,1100+520,$color,$font,$data_7);
                        imagettftext($image,37,0,2020,1100+650,$color,$font,$data_8);
                        imagettftext($image,37,0,2020,1100+780,$color,$font,$data_9);
//
                        imagettftext($image,37,0,1610,2530,$color,$font,$data_10);
                        imagettftext($image,37,0,1610,2680,$color,$font,$data_11);
                        imagettftext($image,37,0,1610,2820,$color,$font,$data_12);
//
                        imagettftext($image,33,0,1000,3270,$color,$font,$data_13);
                        imagettftext($image,33,0,1000,3370,$color,$font,$data_14);
                        imagettftext($image,33,0,1000,3480,$color,$font,$data_15);
                        imagettftext($image,33,0,1000,3610,$color,$font,$data_16);
//
                        imagettftext($image,33,0,2260,3270,$color,$font,$data_17);
                        imagettftext($image,33,0,2260,3370,$color,$font,$data_18);
                        imagettftext($image,33,0,2260,3480,$color,$font,$data_19);
                        imagettftext($image,33,0,2260,3610,$color,$font,$data_20);


                    break;
                   case 3:
                       // imagettftext($image,42,0,400,440,$color,$font,"Image 3");
                    break;


                }



                imagejpeg($image,$_SERVER['DOCUMENT_ROOT'].'/assets/kprint/update/la_agreement_'.$a.$core_id.'.jpg', 50);

                $pdf->AddPage();
                $pdf->Image($_SERVER['DOCUMENT_ROOT'].'/assets/kprint/update/la_agreement_'.$a.$core_id.'.jpg',10,10,189);

        }

        $pdf->Output();
        exit;


        }
        catch(Exception $e)
        {
            echo $e;
        }



?>