Guest User

Untitled

a guest
Jan 5th, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.94 KB | None | 0 0
  1. <?php
  2.     use WHMCS\Database\Capsule;
  3.     $data=Capsule::table('tblIqr_setting')->where('settings','buttontext')->get();
  4.     $buttonData=$data[0]->value;
  5.     include_once("generateQRcode/phpqrcode/qrlib.php");
  6.     if(isset($_POST["submit"]))
  7.     {
  8.  
  9.         $id=$_GET['id'];
  10.         function get_client_id()
  11.         {
  12.              $id=$_GET['id'];
  13.              return $id;
  14.         }
  15.         include_once("generateQRcode/TCPDF-main/tcpdf.php");
  16.         class myPDF extends TCPDF
  17.         {
  18.             public $globalcheckdue = 0;
  19.             public $qrheigh = 0;
  20.  
  21.  
  22.             public function Header()
  23.             {
  24.            
  25.              // $this->setRTL(true);
  26.              $this->SetPrintHeader(false);
  27.            
  28.             }
  29.             public function Footer()
  30.             {
  31.            
  32.              $this->SetPrintFooter(false);
  33.            
  34.             }
  35.             function table_client()
  36.             {  
  37.                 $CompanyName  = Capsule::table('tblconfiguration')->where('setting','CompanyName')->get();
  38.                 $system_CompanyName = $CompanyName[0]->value;
  39.                 $this->SetFont('aealarabiya','B',13);
  40.                 $this->SetXY(155,2);
  41.                 $this->Write(-5,$system_CompanyName);
  42.                 $LogoURL  = Capsule::table('tblconfiguration')->where('setting','LogoURL')->get();
  43.                 foreach ($LogoURL as  $value){
  44.                         $finalLogoURL = $value->value;
  45.                  }
  46.                 $LogoURLPath = parse_url($finalLogoURL, PHP_URL_PATH);
  47.                 $AbsoluteFilePath = $LogoURLPath;
  48.                
  49.                 $pathinfo = pathinfo($AbsoluteFilePath);
  50.                
  51.                 $fileextension = $pathinfo['extension'];
  52.                
  53.                
  54.                 if($fileextension !== "svg")
  55.                 {
  56.                     $this->Image($AbsoluteFilePath,10,-4,20,20);
  57.  
  58.                 }else{
  59.                     $this->ImageSVG($AbsoluteFilePath,10,-4,20,20);    
  60.                 }
  61.                 $headertext  = Capsule::table('tblIqr_setting')->where('settings','headertext')->get();
  62.                 $headertextvalue=$headertext[0]->value;
  63.                 if(!empty($headertextvalue))
  64.                 {  
  65.                     $this->SetTextColor(255,0,0);
  66.                     $this->SetXY(10,12);
  67.                     $this->MultiCell(0, 0, $headertextvalue, 0, 'C', false, 1);
  68.                 }
  69.                 $id=get_client_id();
  70.                 $get= Capsule::table("tblinvoices")->where("id",$id)->get();
  71.                 $user_id= $get[0]->userid;
  72.                 $clientdetails= Capsule::table("tblclients")->where("id",$user_id)->get();
  73.                 $this->SetTextColor(0,0,0);
  74.                 $this->setFillColor(230,230,230);
  75.                 $this->SetY(25);
  76.                 $client='العميل';
  77.                
  78.                 $details='بيانات';
  79.                 $this->Cell(190,12,"Client Details / $client $details",1,1,'C',true);  
  80.                 $this->Cell(95,8,'Name / الاسم',1,0,'L',0);
  81.                 $this->Cell(95,8,$clientdetails[0]->firstname." ".$clientdetails[0]->lastname,1,1,'L',0);
  82.                 $this->Cell(95,8,'Company Name / الشركة',1,0,'L',0);
  83.                 $this->Cell(95,8,$clientdetails[0]->companyname,1,1,'L',0);
  84.                 $email='الالكتروني';
  85.                 $email1='البريد';
  86.                 $this->Cell(95,8,"Email /$email $email1 ",1,0,'L',0);
  87.                 $this->Cell(95,8,$clientdetails[0]->email,1,1,'L',0);
  88.                 $this->Cell(95,8,'Address / العنوان',1,0,'L',0);
  89.                 $this->Cell(95,8,$clientdetails[0]->address1,1,1,'L',0);
  90.                 $countryu='والمدينة';
  91.                 $country1='الدولة';
  92.                 $this->Cell(95,8,"City / State / Country / Pincode /$countryu $country1  ",1,0,'L',0);
  93.                 $this->Cell(95,8,$clientdetails[0]->city.' / '.$clientdetails[0]->state.' / '.$clientdetails[0]->country.' / '.$clientdetails[0]->postcode,1,1,'L',0);
  94.                $phoneno='الهاتف';
  95.                $phoneno1='رقم';
  96.                 $this->Cell(95,8,"Phone Number / $phoneno $phoneno1 ",1,0,'L',0);
  97.                 $this->Cell(95,8,$clientdetails[0]->phonenumber,1,1,'L',0);
  98.                 $this->Ln();
  99.                 return $this;
  100.             }
  101.             function table_invoice()
  102.             {  
  103.                 $id=get_client_id();
  104.                 $get= Capsule::table("tblinvoices")->where("id",$id)->get();
  105.                 $tax_rate1=$get[0]->taxrate;
  106.                 $tax_rate2=$get[0]->taxrate2;
  107.                 $user_id= $get[0]->userid;
  108.                     $command = 'GetInvoices';
  109.                     $postData = array(
  110.                     'userid' => $user_id,
  111.                    
  112.                     );
  113.                    
  114.                 $results = localAPI($command, $postData);
  115.                    
  116.                 $currency_code=$results['invoices']['invoice'][0]['currencycode'];          
  117.                 $clientdetails= Capsule::table("tblclients")->where("id",$user_id)->get();
  118.                 $country=$clientdetails[0]->country;
  119.                 $state=$clientdetails[0]->state;
  120.                 if($tax_rate1>0)
  121.                 {
  122.                     $get= Capsule::table("tblinvoices")->where("id",$id)->get();
  123.                     $tax_price1=$get[0]->tax;
  124.                     $tax_details1= Capsule::table("tbltax")->where("level",1)->where("state",$state)->where("Country",$country)->where("taxrate",$tax_rate1)->count();
  125.                     if($tax_details1>0)
  126.                     {                    
  127.                         $tax_details1= Capsule::table("tbltax")->where("level",1)->where("state",$state)->where("Country",$country)->where("taxrate",$tax_rate1)->get();
  128.                             $tax_name1=$tax_details1[0]->name;                          
  129.                     }else
  130.                     {
  131.                         $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country",$country)->where("taxrate",$tax_rate1)->count();
  132.                         if($tax_details1>0)
  133.                         {
  134.                             $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country",$country)->where("taxrate",$tax_rate1)->get();
  135.                             $tax_name1=$tax_details1[0]->name;
  136.                          
  137.                         }else
  138.                         {
  139.                             $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country"," ")->where("taxrate",$tax_rate1)->count();
  140.                             if($tax_details1>0)
  141.                             {
  142.                                 $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country"," ")->where("taxrate",$tax_rate1)->get();
  143.                                $tax_name1=$tax_details1[0]->name;
  144.                                                            
  145.                             }
  146.                         }
  147.                     }
  148.                 }                          
  149.                
  150.             $getdescription= Capsule::table("tblinvoiceitems")->where("invoiceid",$id)->get();        
  151.             $Invoice ='تفاصيل';
  152.            
  153.             $details =' الفاتورة';
  154.            
  155.                 $this->SetLeftMargin(10);
  156.                 $this->SetY(87);
  157.                 $width_fourth_cell = array(190);
  158.                 $this->Cell($width_fourth_cell[0],12,"Invoice Details  /$details $Invoice",1,1,C,true);  
  159.                 $invoice1='الفاتورة';
  160.                 $urdu_id='رقم';
  161.                 $this->Cell(95,8,"Invoiceid  / $invoice1 $urdu_id ",1,0,'L',0);
  162.                 $this->Cell(95,8,$get[0]->id,1,1,'L',0);
  163.                 $date='الفاتورة';
  164.                 $date1='تاريخ';
  165.                 $this->Cell(95,8,"Date  /$date $date1 ",1,0,'L',0);
  166.                 $this->Cell(95,8,$get[0]->date,1,1,'L',0);
  167.                 $due='الاستحقاق';
  168.                 $date='تاريخ';
  169.                 $this->Cell(95,8,"DueDate  /$due $date  ",1,0,'L',0);
  170.                 $this->Cell(95,8,$get[0]->duedate,1,1,'L',0);
  171.                
  172.                 return $this;
  173.             }
  174.             function description()
  175.             {
  176.                 $id=get_client_id();
  177.                 $get= Capsule::table("tblinvoices")->where("id",$id)->get();
  178.                 $user_id= $get[0]->userid;
  179.                 $command = 'GetInvoices';
  180.                     $postData = array(
  181.                     'userid' => $user_id,
  182.                    
  183.                     );
  184.                    
  185.                 $results = localAPI($command, $postData);
  186.                 $currency_code=$results['invoices']['invoice'][0]['currencycode'];
  187.                 $status = $get[0]->status;
  188.                 $getdescription= Capsule::table("tblinvoiceitems")->where("invoiceid",$id)->get();  
  189.                 $this->SetLeftMargin(10);
  190.                
  191.                 $table_topmargin=125;
  192.                 $this->SetY(  $table_topmargin);
  193.                 $this->setFillColor(230,230,230);
  194.                 $items='أغراض';
  195.                 $invoice='الفاتورة';
  196.                  $this->Cell(146,12,"Invoice  Items  /$invoice $items ",1,0,'C',true);
  197.                  $this->Cell(44,12,'Amount / مقدار',1,1,'L',true);
  198.  
  199.  
  200.                 $values = "";
  201.                 foreach ($getdescription as   $value)
  202.                 {
  203.                     $values.= '<tr><td width="414">'.$value->description.'</td>
  204.  
  205.  
  206.                            <td width="124">'.$value->amount.'&nbsp;'.$currency_code.'</td>
  207.                    </tr>';
  208.                 }      
  209.                 $tbl = <<<EOD
  210.                 <table border="1">
  211.  
  212.                
  213.                 $values
  214.  
  215.                
  216.                 </table>
  217.                 EOD;
  218.                 $this->setFillColor(255,255,255);
  219.  
  220.                 $this->writeHTML($tbl);
  221.                 $get= Capsule::table("tblinvoices")->where("id",$id)->get();
  222.                 $tax_rate1=$get[0]->taxrate;  
  223.  
  224.                 if($tax_rate1>0)
  225.                 {
  226.                     $tax_price1=$get[0]->tax;
  227.                     $this->Cell(146,$column_height, 'Vat Tax  / الضريبة',1,0,'L',0);
  228.                     $this->Cell(44,$column_height, $tax_price1." ".$currency_code,1,1,'L',0);
  229.                 }
  230.                     $sub="الاجمالي";
  231.                     $this->Cell(146,$column_height,"Sub total/ $sub ",1,0,'L',0);
  232.                     $this->Cell(44,$column_height,$get[0]->subtotal." ".$currency_code,1,1,'L',0);
  233.                     $total="الاجمالي";
  234.                     $invoicetot="بالضريبة";
  235.                     $this->Cell(146,$column_height,"Total  / $invoicetot $total ",1,0,'L',0);
  236.                     $this->Cell(44,$column_height,$get[0]->total." ".$currency_code,1,1,'L',0);
  237.              
  238.                 if($status == "Paid")
  239.                 {  
  240.                      $this->Cell(146,$column_height,'Status / الحالة',1,0,'L',0);
  241.                     $this->SetTextColor(0,100,0);
  242.                     $this->Cell(44,$column_height,$status.' / مدفوعة',1,1,'L',0);
  243.                 }else
  244.                 {
  245.                    $un="غير";
  246.                    $paid="مدفوعة";
  247.                    
  248.                     $this->Cell(146,$column_height,'Status / الحالة',1,0,'L',0);
  249.                     $this->SetTextColor(139, 128, 0);
  250.                     $this->Cell(44,$column_height,$status." / $un $paid  ",1,1,'L',0);
  251.                 }
  252.                 $this->globalcheckdue = $this->getY();
  253.                 return $this;
  254.             }
  255.            
  256.             function make_QR()
  257.             {
  258.                 $id=get_client_id();
  259.                 $table_topmargin=125;
  260.                 $get= Capsule::table("tblinvoices")->where("id",$id)->get();
  261.                 $tax_rate1=$get[0]->taxrate;
  262.                 $user_id= $get[0]->userid;
  263.                 $getdescription= Capsule::table("tblinvoiceitems")->where("invoiceid",$id)->get();  
  264.                 $description_fields=count($getdescription);
  265.  
  266.                 $CompanyName  = Capsule::table('tblconfiguration')->where('setting','CompanyName')->get();
  267.                 $system_CompanyName = $CompanyName[0]->value;
  268.                 $id=get_client_id();
  269.                 $get= Capsule::table("tblinvoices")->where("id",$id)->get();
  270.                 $tax_rate1=$get[0]->taxrate;
  271.                 $tax_rate2=$get[0]->taxrate2;
  272.                 $user_id= $get[0]->userid;
  273.  
  274.                 $command = 'GetInvoices';
  275.                 $postData = array(
  276.                 'userid' => $user_id,
  277.  
  278.                 );
  279.                 $results = localAPI($command, $postData);
  280.                
  281.                 $currency_code=$results[invoices][invoice][0][currencycode];
  282.                 $clientdetails= Capsule::table("tblclients")->where("id",$user_id)->get();
  283.                 $country=$clientdetails[0]->country;
  284.                 $state=$clientdetails[0]->state;
  285.                 if($tax_rate1>0)
  286.                 {
  287.                     $get= Capsule::table("tblinvoices")->where("id",$id)->get();
  288.                     $tax_price1=$get[0]->tax;
  289.                         $tax_details1= Capsule::table("tbltax")->where("level",1)->where("state",$state)->where("Country",$country)->where("taxrate",$tax_rate1)->count();
  290.                     if($tax_details1>0)
  291.                     {
  292.                         $tax_details1= Capsule::table("tbltax")->where("level",1)->where("state",$state)->where("Country",$country)->where("taxrate",$tax_rate1)->get();
  293.                             $tax_name1=$tax_details1[0]->name;
  294.                            
  295.                     }else
  296.                     {
  297.                         $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country",$country)->where("taxrate",$tax_rate1)->count();
  298.  
  299.                         if($tax_details1>0)
  300.                         {
  301.                            $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country",$country)->where("taxrate",$tax_rate1)->get();
  302.                             $tax_name1=$tax_details1[0]->name;
  303.                          
  304.                         }else
  305.                         {
  306.                             $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country","")->where("taxrate",$tax_rate1)->count();
  307.                             if($tax_details1>0)
  308.                             {
  309.                                 $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country","")->where("taxrate",$tax_rate1)->get();
  310.                                 $tax_name1=$tax_details1[0]->name;
  311.                                                                
  312.                             }
  313.                         }
  314.                     }
  315.                 }
  316.                 $TaxCode  = Capsule::table('tblconfiguration')->where('setting','TaxCode')->get();
  317.                 $system_TaxCode = $TaxCode[0]->value;
  318.                 $vat_registration_number = $system_TaxCode;
  319.                 $invoice_datetimez = $get[0]->created_at;
  320.                 $invoice_amount = $get[0]->total;
  321.                 $invoice_tax_amount = $tax_price1;
  322.                 $result = chr(1) . chr( strlen($system_CompanyName) ) .  $system_CompanyName;
  323.                 $result.= chr(2) . chr( strlen($vat_registration_number) ) . $vat_registration_number;
  324.                 $result.= chr(3) . chr( strlen($invoice_datetimez) ) . $invoice_datetimez;
  325.                 $result.= chr(4) . chr( strlen($invoice_amount) ) . $invoice_amount;
  326.                 $result.= chr(5) . chr( strlen($invoice_tax_amount) ) . $invoice_tax_amount;
  327.                 $response = base64_encode($result);
  328.                 $fileName = '005_file_'.$response.'.png';
  329.                 $urlRelativeFilePath = ''.__DIR__.'/generateQRcode/temp/'.$fileName;
  330.                 $pngAbsoluteFilePath = ''.__DIR__.'/generateQRcode/temp/'.$fileName;
  331.  
  332.                 if (!file_exists($urlRelativeFilePath))
  333.                 {
  334.                     QRcode::png($response, $urlRelativeFilePath);
  335.                 }  
  336.                 $dummy_y = 0;
  337.                 if($this->globalcheckdue > 0)
  338.                 {
  339.                     $distance_x = $this->globalcheckdue+5;
  340.                 }
  341.  
  342.                 $this->Image($pngAbsoluteFilePath,158,$distance_x,45,45,'png');
  343.                 $this->qrheigh = $this->getImageRBY();
  344.                 return $this;
  345.             }
  346.             function add_text()
  347.             {
  348.                 $data=Capsule::table('tblIqr_setting')->where('settings','footertext')->get();
  349.                 $footertext=$data[0]->value;
  350.                 $this->SetTextColor(0,0,0);
  351.                 if(!empty($footertext))
  352.                 {
  353.                     if($this->qrheigh > 0)
  354.                     {                        
  355.                         $distance_x = $this->qrheigh-40;
  356.                         $terms="والشروط";
  357.                         $conditions="الأحكام";
  358.                         $this->SetFont('freeserif','B',12);
  359.                         $this->SetXY(10,$distance_x);
  360.                         $this->Write(0, "Terms and Conditions  / $terms $conditions ");
  361.                         $this->Ln();
  362.                         $this->setRTL(true);
  363.                         $distance_x = $distance_x+7;
  364.                         $this->SetFont('aealarabiya',10);
  365.                         $this->SetXY(-96, $distance_x);
  366.                         $this->MultiCell(90,2,$footertext);
  367.                         $this->Ln();  
  368.                     }
  369.                 }
  370.                 return $this;
  371.             }
  372.         }
  373.         $pdf = new myPDF('P','mm',"A4");
  374.         $pdf->AddPage();
  375.         $pdf->table_client()->table_invoice()->description()->make_QR()->add_text();
  376.         $pdf->Output("QR_INVOICE_".$id."_".date("M-d-Y-h-i-s-A")."_doc.pdf");
  377.         exit();
  378.     }
  379. ?>
  380. <style>
  381. table { width: 100%; }
  382. table th, table td { width: 25%; }
  383.  
  384. </style>
Add Comment
Please, Sign In to add comment