where('settings','buttontext')->get(); $buttonData=$data[0]->value; include_once("generateQRcode/phpqrcode/qrlib.php"); if(isset($_POST["submit"])) { $id=$_GET['id']; function get_client_id() { $id=$_GET['id']; return $id; } include_once("generateQRcode/TCPDF-main/tcpdf.php"); class myPDF extends TCPDF { public $globalcheckdue = 0; public $qrheigh = 0; public function Header() { // $this->setRTL(true); $this->SetPrintHeader(false); } public function Footer() { $this->SetPrintFooter(false); } function table_client() { $CompanyName = Capsule::table('tblconfiguration')->where('setting','CompanyName')->get(); $system_CompanyName = $CompanyName[0]->value; $this->SetFont('aealarabiya','B',13); $this->SetXY(155,2); $this->Write(-5,$system_CompanyName); $LogoURL = Capsule::table('tblconfiguration')->where('setting','LogoURL')->get(); foreach ($LogoURL as $value){ $finalLogoURL = $value->value; } $LogoURLPath = parse_url($finalLogoURL, PHP_URL_PATH); $AbsoluteFilePath = $LogoURLPath; $pathinfo = pathinfo($AbsoluteFilePath); $fileextension = $pathinfo['extension']; if($fileextension !== "svg") { $this->Image($AbsoluteFilePath,10,-4,20,20); }else{ $this->ImageSVG($AbsoluteFilePath,10,-4,20,20); } $headertext = Capsule::table('tblIqr_setting')->where('settings','headertext')->get(); $headertextvalue=$headertext[0]->value; if(!empty($headertextvalue)) { $this->SetTextColor(255,0,0); $this->SetXY(10,12); $this->MultiCell(0, 0, $headertextvalue, 0, 'C', false, 1); } $id=get_client_id(); $get= Capsule::table("tblinvoices")->where("id",$id)->get(); $user_id= $get[0]->userid; $clientdetails= Capsule::table("tblclients")->where("id",$user_id)->get(); $this->SetTextColor(0,0,0); $this->setFillColor(230,230,230); $this->SetY(25); $client='العميل'; $details='بيانات'; $this->Cell(190,12,"Client Details / $client $details",1,1,'C',true); $this->Cell(95,8,'Name / الاسم',1,0,'L',0); $this->Cell(95,8,$clientdetails[0]->firstname." ".$clientdetails[0]->lastname,1,1,'L',0); $this->Cell(95,8,'Company Name / الشركة',1,0,'L',0); $this->Cell(95,8,$clientdetails[0]->companyname,1,1,'L',0); $email='الالكتروني'; $email1='البريد'; $this->Cell(95,8,"Email /$email $email1 ",1,0,'L',0); $this->Cell(95,8,$clientdetails[0]->email,1,1,'L',0); $this->Cell(95,8,'Address / العنوان',1,0,'L',0); $this->Cell(95,8,$clientdetails[0]->address1,1,1,'L',0); $countryu='والمدينة'; $country1='الدولة'; $this->Cell(95,8,"City / State / Country / Pincode /$countryu $country1 ",1,0,'L',0); $this->Cell(95,8,$clientdetails[0]->city.' / '.$clientdetails[0]->state.' / '.$clientdetails[0]->country.' / '.$clientdetails[0]->postcode,1,1,'L',0); $phoneno='الهاتف'; $phoneno1='رقم'; $this->Cell(95,8,"Phone Number / $phoneno $phoneno1 ",1,0,'L',0); $this->Cell(95,8,$clientdetails[0]->phonenumber,1,1,'L',0); $this->Ln(); return $this; } function table_invoice() { $id=get_client_id(); $get= Capsule::table("tblinvoices")->where("id",$id)->get(); $tax_rate1=$get[0]->taxrate; $tax_rate2=$get[0]->taxrate2; $user_id= $get[0]->userid; $command = 'GetInvoices'; $postData = array( 'userid' => $user_id, ); $results = localAPI($command, $postData); $currency_code=$results['invoices']['invoice'][0]['currencycode']; $clientdetails= Capsule::table("tblclients")->where("id",$user_id)->get(); $country=$clientdetails[0]->country; $state=$clientdetails[0]->state; if($tax_rate1>0) { $get= Capsule::table("tblinvoices")->where("id",$id)->get(); $tax_price1=$get[0]->tax; $tax_details1= Capsule::table("tbltax")->where("level",1)->where("state",$state)->where("Country",$country)->where("taxrate",$tax_rate1)->count(); if($tax_details1>0) { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("state",$state)->where("Country",$country)->where("taxrate",$tax_rate1)->get(); $tax_name1=$tax_details1[0]->name; }else { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country",$country)->where("taxrate",$tax_rate1)->count(); if($tax_details1>0) { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country",$country)->where("taxrate",$tax_rate1)->get(); $tax_name1=$tax_details1[0]->name; }else { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country"," ")->where("taxrate",$tax_rate1)->count(); if($tax_details1>0) { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country"," ")->where("taxrate",$tax_rate1)->get(); $tax_name1=$tax_details1[0]->name; } } } } $getdescription= Capsule::table("tblinvoiceitems")->where("invoiceid",$id)->get(); $Invoice ='تفاصيل'; $details =' الفاتورة'; $this->SetLeftMargin(10); $this->SetY(87); $width_fourth_cell = array(190); $this->Cell($width_fourth_cell[0],12,"Invoice Details /$details $Invoice",1,1,C,true); $invoice1='الفاتورة'; $urdu_id='رقم'; $this->Cell(95,8,"Invoiceid / $invoice1 $urdu_id ",1,0,'L',0); $this->Cell(95,8,$get[0]->id,1,1,'L',0); $date='الفاتورة'; $date1='تاريخ'; $this->Cell(95,8,"Date /$date $date1 ",1,0,'L',0); $this->Cell(95,8,$get[0]->date,1,1,'L',0); $due='الاستحقاق'; $date='تاريخ'; $this->Cell(95,8,"DueDate /$due $date ",1,0,'L',0); $this->Cell(95,8,$get[0]->duedate,1,1,'L',0); return $this; } function description() { $id=get_client_id(); $get= Capsule::table("tblinvoices")->where("id",$id)->get(); $user_id= $get[0]->userid; $command = 'GetInvoices'; $postData = array( 'userid' => $user_id, ); $results = localAPI($command, $postData); $currency_code=$results['invoices']['invoice'][0]['currencycode']; $status = $get[0]->status; $getdescription= Capsule::table("tblinvoiceitems")->where("invoiceid",$id)->get(); $this->SetLeftMargin(10); $table_topmargin=125; $this->SetY( $table_topmargin); $this->setFillColor(230,230,230); $items='أغراض'; $invoice='الفاتورة'; $this->Cell(146,12,"Invoice Items /$invoice $items ",1,0,'C',true); $this->Cell(44,12,'Amount / مقدار',1,1,'L',true); $values = ""; foreach ($getdescription as $value) { $values.= ''.$value->description.' '.$value->amount.' '.$currency_code.' '; } $tbl = << $values EOD; $this->setFillColor(255,255,255); $this->writeHTML($tbl); $get= Capsule::table("tblinvoices")->where("id",$id)->get(); $tax_rate1=$get[0]->taxrate; if($tax_rate1>0) { $tax_price1=$get[0]->tax; $this->Cell(146,$column_height, 'Vat Tax / الضريبة',1,0,'L',0); $this->Cell(44,$column_height, $tax_price1." ".$currency_code,1,1,'L',0); } $sub="الاجمالي"; $this->Cell(146,$column_height,"Sub total/ $sub ",1,0,'L',0); $this->Cell(44,$column_height,$get[0]->subtotal." ".$currency_code,1,1,'L',0); $total="الاجمالي"; $invoicetot="بالضريبة"; $this->Cell(146,$column_height,"Total / $invoicetot $total ",1,0,'L',0); $this->Cell(44,$column_height,$get[0]->total." ".$currency_code,1,1,'L',0); if($status == "Paid") { $this->Cell(146,$column_height,'Status / الحالة',1,0,'L',0); $this->SetTextColor(0,100,0); $this->Cell(44,$column_height,$status.' / مدفوعة',1,1,'L',0); }else { $un="غير"; $paid="مدفوعة"; $this->Cell(146,$column_height,'Status / الحالة',1,0,'L',0); $this->SetTextColor(139, 128, 0); $this->Cell(44,$column_height,$status." / $un $paid ",1,1,'L',0); } $this->globalcheckdue = $this->getY(); return $this; } function make_QR() { $id=get_client_id(); $table_topmargin=125; $get= Capsule::table("tblinvoices")->where("id",$id)->get(); $tax_rate1=$get[0]->taxrate; $user_id= $get[0]->userid; $getdescription= Capsule::table("tblinvoiceitems")->where("invoiceid",$id)->get(); $description_fields=count($getdescription); $CompanyName = Capsule::table('tblconfiguration')->where('setting','CompanyName')->get(); $system_CompanyName = $CompanyName[0]->value; $id=get_client_id(); $get= Capsule::table("tblinvoices")->where("id",$id)->get(); $tax_rate1=$get[0]->taxrate; $tax_rate2=$get[0]->taxrate2; $user_id= $get[0]->userid; $command = 'GetInvoices'; $postData = array( 'userid' => $user_id, ); $results = localAPI($command, $postData); $currency_code=$results[invoices][invoice][0][currencycode]; $clientdetails= Capsule::table("tblclients")->where("id",$user_id)->get(); $country=$clientdetails[0]->country; $state=$clientdetails[0]->state; if($tax_rate1>0) { $get= Capsule::table("tblinvoices")->where("id",$id)->get(); $tax_price1=$get[0]->tax; $tax_details1= Capsule::table("tbltax")->where("level",1)->where("state",$state)->where("Country",$country)->where("taxrate",$tax_rate1)->count(); if($tax_details1>0) { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("state",$state)->where("Country",$country)->where("taxrate",$tax_rate1)->get(); $tax_name1=$tax_details1[0]->name; }else { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country",$country)->where("taxrate",$tax_rate1)->count(); if($tax_details1>0) { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country",$country)->where("taxrate",$tax_rate1)->get(); $tax_name1=$tax_details1[0]->name; }else { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country","")->where("taxrate",$tax_rate1)->count(); if($tax_details1>0) { $tax_details1= Capsule::table("tbltax")->where("level",1)->where("Country","")->where("taxrate",$tax_rate1)->get(); $tax_name1=$tax_details1[0]->name; } } } } $TaxCode = Capsule::table('tblconfiguration')->where('setting','TaxCode')->get(); $system_TaxCode = $TaxCode[0]->value; $vat_registration_number = $system_TaxCode; $invoice_datetimez = $get[0]->created_at; $invoice_amount = $get[0]->total; $invoice_tax_amount = $tax_price1; $result = chr(1) . chr( strlen($system_CompanyName) ) . $system_CompanyName; $result.= chr(2) . chr( strlen($vat_registration_number) ) . $vat_registration_number; $result.= chr(3) . chr( strlen($invoice_datetimez) ) . $invoice_datetimez; $result.= chr(4) . chr( strlen($invoice_amount) ) . $invoice_amount; $result.= chr(5) . chr( strlen($invoice_tax_amount) ) . $invoice_tax_amount; $response = base64_encode($result); $fileName = '005_file_'.$response.'.png'; $urlRelativeFilePath = ''.__DIR__.'/generateQRcode/temp/'.$fileName; $pngAbsoluteFilePath = ''.__DIR__.'/generateQRcode/temp/'.$fileName; if (!file_exists($urlRelativeFilePath)) { QRcode::png($response, $urlRelativeFilePath); } $dummy_y = 0; if($this->globalcheckdue > 0) { $distance_x = $this->globalcheckdue+5; } $this->Image($pngAbsoluteFilePath,158,$distance_x,45,45,'png'); $this->qrheigh = $this->getImageRBY(); return $this; } function add_text() { $data=Capsule::table('tblIqr_setting')->where('settings','footertext')->get(); $footertext=$data[0]->value; $this->SetTextColor(0,0,0); if(!empty($footertext)) { if($this->qrheigh > 0) { $distance_x = $this->qrheigh-40; $terms="والشروط"; $conditions="الأحكام"; $this->SetFont('freeserif','B',12); $this->SetXY(10,$distance_x); $this->Write(0, "Terms and Conditions / $terms $conditions "); $this->Ln(); $this->setRTL(true); $distance_x = $distance_x+7; $this->SetFont('aealarabiya',10); $this->SetXY(-96, $distance_x); $this->MultiCell(90,2,$footertext); $this->Ln(); } } return $this; } } $pdf = new myPDF('P','mm',"A4"); $pdf->AddPage(); $pdf->table_client()->table_invoice()->description()->make_QR()->add_text(); $pdf->Output("QR_INVOICE_".$id."_".date("M-d-Y-h-i-s-A")."_doc.pdf"); exit(); } ?>