| Server IP : 188.114.97.2 / Your IP : 104.23.197.230 Web Server : Apache/2.4.59 (Debian) System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : edlftp ( 1002) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/nicolasj/www/sms.formationlangues.be/application/controllers/ |
Upload File : |
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class PdfGenerator extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('crud_model');
$this->load->model('profile_model');
$this->load->model('security_model');
$this->load->model('invoice_model');
$this->load->model('wallet_model');
$this->load->model('accounting_model');
}
public function index()
{
$token = $this->input->post('token');
$id = 54;
$invoice = $this->wallet_model->get_invoice($id);
$address = $invoice['Add_L1']." , ". $invoice['Add_L2']."<br>". $invoice['Add_Location']." , ". $invoice['Add_Location'];
$data = [
'invoice_id' => preg_replace('/[^0-9]/', '', $invoice['Invoice_ID']),
'name' =>$invoice['Customer_Name'],
'date' => $invoice['Invoice_Date'],
'due' => $invoice['Payment_Date'],
'address' => $address,
'tva' => $invoice['VAT'],
'comment' => $invoice['Public_Comment'],
'products' => $invoice['Product'],
'amount' => $invoice['Payment_amount'],
'state' => $invoice['Status'],
'email' => $this->crud_model->get_user_email($invoice['Customer_ID'])
];
$this->load->view('pdf/credit_note/Propulse/fr', $data);
}
public function one_3()
{
$r = (array) json_decode($this->input->post('data'));
$data = array(
'ref' => $r['ref'],
'name' => $r['s_name'],
'dob' => $r['s_dob'],
'start' => $r['course_start'],
'end' => $r['course_end'],
'days' => $r['course_lessons'],
'price' => $r['course_price'],
'total' => $r['period_course_total'],
'parent' => $r['p_name'],
'address' => $r['p_address'],
'r' => (object)$r,
);
$this->load->library('pdf');
$this->pdf->load_view('pdf/one/propulse/fr_3', $data);
$this->pdf->render();
$this->pdf->stream($data['ref']."_cadre2.pdf");
}
public function one_2()
{
$r = (array)json_decode($this->input->post('data'));
$pdf_name = $r['ref'];
$this->load->library('pdf');
$this->pdf->load_view('pdf/one/propulse/fr_2');
$this->pdf->render();
$this->pdf->stream($pdf_name.".pdf");
}
public function one_1()
{
$r = (array)json_decode($this->input->post('data'));
$data = array(
'ref' => $r['ref'],
'name' => $r['s_name'],
'dob' => $r['s_dob'],
'start' => $r['course_start'],
'end' => $r['course_end'],
'days' => $r['course_lessons'],
'price' => $r['course_price'],
'total' => $r['period_course_total'],
'parent' => $r['p_name'],
'address' => $r['p_address'],
);
$this->load->library('pdf');
$this->pdf->load_view('pdf/one/propulse/fr_1', $data);
$this->pdf->render();
$this->pdf->stream($data['ref']."_1.pdf");
}
public function invoice($id=null, $token=null)
{
if($id == null && $token == null) {
$token = $this->input->post('token');
$id = $this->input->post('id');
}
if($this->security_model->generateToken($id) !== $token) {
echo "error : token corrupt";
return;
}
$invoice = $this->wallet_model->get_invoice($id);
$address = $invoice['Add_L1']." , ". $invoice['Add_L2']."<br>". $invoice['Add_PC']." , ". $invoice['Add_Location'];
$customer = $this->get_customer((int) $invoice['Customer_ID']);
$data = array(
'invoice_id' => preg_replace('/[^0-9]/', '', $invoice['Invoice_ID']),
'name' => $invoice['Customer_Name'],
'date' => $invoice['Invoice_Date'],
'due' => $invoice['Payment_Date'],
'address' => $address,
'tva' => $invoice['VAT'],
'comment' => $invoice['Public_Comment'],
'products' => $invoice['Product'],
'amount' => ($invoice['Payment_amount'] - $invoice['Discount_Amount']),
'real_amount' => $invoice['Payment_amount'],
'discounts' => $invoice['Discount'],
'discount_total' => $invoice['Discount_Amount'],
'discount_note' => $invoice['Discount_Note'],
'state' => $invoice['Status'],
'com_structured' => $this->invoice_model->generate_invoice_strutured_com(
(int) preg_replace('/[^0-9]/', '', $invoice['Invoice_ID']),
(int) substr($invoice['Invoice_Date'], 0, 4)
),
'email' => $this->profile_model->get_user_master_email((int) $invoice['Customer_ID']),
'phone_number' => $customer->user->phone
);
$tr = json_decode($invoice['Transaction_ID'], true)['transactions'];
foreach ($tr as $t) {
$paid = $paid + $this->wallet_model->get_transaction_amount($t);
$date = $this->wallet_model->get_transaction_date($t);
$method = $this->wallet_model->get_transaction_method($t);
}
if ($paid >= $data['amount']) {
$data['state'] = 1;
}
if ($paid > 0) {
$data['paid'] = $paid;
$data['paid_date'] = $date;
$data['paid_method'] = $method;
}
$data['transactions'] = $tr;
$langInt = $this->crud_model->get_user_lang($invoice['Customer_ID']);
$lang = $this->profile_model->intToIso($langInt);
$society = $this->crud_model->get_society_name($invoice['Society_ID']);
$this->load->library('pdf');
if(!isset($lang)|| $lang == "") {
$lang = "en";
}
$this->load->view('pdf/invoice/'.$society.'/fr', $data);
return;
}
public function credit_note($id=null, $token=null)
{
if($id == null && $token == null) {
$token = $this->input->post('token');
$id = $this->input->post('id');
}
if($this->security_model->generateToken($id) !== $token) {
echo "error : token corrupt";
return;
}
$credit_note = $this->wallet_model->get_credit_note_bis($id)[0];
$address = $credit_note['Add_L1']." , ". $credit_note['Add_L2']."<br>". $credit_note['Add_PC']." , ". $credit_note['Add_Location'];
$data = array(
'credit_note_id' => preg_replace('/[^0-9]/', '', $credit_note['Credit_Note_ID']),
'name' => $credit_note['Customer_Name'],
'date' => $credit_note['Creation_Date'],
'due' => $credit_note['Payment_Date'],
'address' => $address,
'tva' => $credit_note['VAT'],
'comment' => $credit_note['Public_Comment'],
'products' => $credit_note['Product'],
'amount' => ($credit_note['Payment_amount'] - $credit_note['Discount_Amount']),
'real_amount' => $credit_note['Payment_amount'],
'discounts' => $credit_note['Discount'],
'discount_total' => $credit_note['Discount_Amount'],
'discount_note' => $credit_note['Discount_Note'],
'com_structured' => $this->invoice_model->generate_creditnote_strutured_com(
(int) preg_replace('/[^0-9]/', '', $credit_note['Credit_Note_ID']),
(int) substr($credit_note['Creation_Date'], 0, 4)
),
'state' => $credit_note['Status'],
'email' => $this->profile_model->get_user_master_email($credit_note['Customer_ID'])
);
$tr = json_decode($credit_note['Transaction_ID'], true)['transactions'];
$paid = 0.0;
$date = null;
$method = null;
foreach ($tr as $t) {
$paid = $paid + $this->wallet_model->get_transaction_amount($t);
$date = $this->wallet_model->get_transaction_date($t);
$method = $this->wallet_model->get_transaction_method($t);
}
if($paid >= $data['amount']) {
$data['state'] = 1;
}
if($paid>0) {
$data['paid'] = $paid;
$data['paid_date'] = $date;
$data['paid_method'] = $method;
}
$data['transactions'] = $tr;
$langInt = $this->crud_model->get_user_lang($credit_note['Customer_ID']);
$lang = $this->profile_model->intToIso($langInt);
$society = $this->crud_model->get_society_name($credit_note['Society_ID']);
$this->load->library('pdf');
if(!isset($lang)|| $lang == "") {
$lang = "en";
}
return $this->load->view('pdf/credit_note/'.$society.'/fr', $data);
}
public function display_invoice()
{
$url = explode('/', $_SERVER[REQUEST_URI]);
$token = $url[4];
$id = $url[3];
$this->invoice($id, $token);
return;
}
public function display_credit_note()
{
$url = explode('/', $_SERVER[REQUEST_URI]);
$token = $url[4];
$id = $url[3];
$this->credit_note($id, $token);
return;
}
private function get_customer(int $customer_id) : stdClass
{
$this->load->model(['student_model', 'parent_model']);
$customer = $this->student_model->get_entry($customer_id, true);
if (!empty($customer->parent_id)) {
$customer = $this->parent_model->get_entry($customer->parent_id, true);
}
return $customer;
}
}