Uname:Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64

403WebShell
403Webshell
Server IP : 188.114.96.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/BO/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/nicolasj/www/sms.formationlangues.be/application/controllers/BO/Accounting.php
<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Accounting extends NS_Controller
{
    public function __construct()
    {
        parent::__construct(array('no_cache' => 1));

        if ($this->session->userdata('admin_login') != 1) {
            $this->error('restricted admin');
        }
        $this->load->helper('generator');
        $this->load->model('crud_model');
        $this->load->model('security_model');
        $this->load->model('wallet_model');
        $this->load->model('payment_model');
        $this->load->model('profile_model');
        $this->load->model('email_model');
        $this->load->model('accounting_model');
        $this->load->database();
    }
    ////////////////////////
    // Fonction controller
    ////////////////////////
    public function index()
    {
        if ($this->session->userdata('userID') != 18) {
            //  header("Location: https://google.com");
            //  exit();
        }
        $this->load->helper('url');
        //  $this->load->library('../controllers/BO/Overview');
        $param = $this->uri->segment(3);
        //var_dump($param);


        if ($param == "manage") {
            $data['manage'] = $this->uri->segment(4);
        }
        if ($param == "require") {
            $data['require'] = $this->uri->segment(4);
        }
        $data['society'] = $this->crud_model->get_courses_society();
        $data['invoice_list'] = $this->wallet_model->get_invoices();
        $data['page_name'] = 'accounting_wallet_student';
        $data['page_title'] = get_phrase('Student_wallet_operation');
        $data['course_list'] = $this->crud_model->get_courses();
        $data['student_list'] = $this->crud_model->mix_student_group();//$this->crud_model->get_student_list();
        $data['transaction'] = $this->wallet_model->get_transactions();
        $this->load->view('backend/index', $data);

        //  var_dump($data);
    }

    public function refresh()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $student_list = $this->crud_model->get_student_list();
        $data = array();

        foreach ($student_list as $student) {

            $balance = $this->wallet_model->wallet_balance($student['student_id']);
            $total = $this->wallet_model->payment_total($student['student_id']);
            if ((float)$balance == $balance && (float)$balance == 0 && $total != 0) {
                $class = "btn-success";
            } elseif ((float)$balance == $balance && (float)$balance > 0  && $total != 0) {
                $class = "btn-success";
            } elseif ((float)$balance == $balance && (float)$balance < 0) {
                $class = "btn-danger";
            } else {
                $class = "btn-info";
            }

            $subData = array(
              'id' => $student['student_id'],
              'class' => $class,
              'name' => $this->crud_model->get_student_name($student['student_id']),
              'last' => $this->wallet_model->payment_last($student['student_id']),
              'total' => $total,
              'balance' => $balance
            );
            array_push($data, $subData);
        }
        echo json_encode($data);
    }

    public function fetch_group()
    {
        $course = $this->input->post('course');
        //echo $course;
        echo json_encode($this->crud_model->get_students_n($course));
    }

    public function fetch_linked()
    {
        $this->db->order_by("Date", "asc");
        $this->db->where('Linked_ID !=', "");
        $this->db->distinct('Linked_ID');
        $r = $this->db->get('wallet')->result_array();

        $r_clean = array();
        foreach ($r as $key => $v) {
            //var_dump(array_column($r_clean,"Linked_ID"));
            if (!in_array($v['Linked_ID'], array_column($r_clean, "Linked_ID"))) {
                array_push($r_clean, $v);
            }
        }

        echo json_encode(($r_clean));
    }
    public function get_linked()
    {
        $id = $this->input->post('id');
        if ($id == "") {
            return;
        }

        $this->db->where('Linked_ID', $id);
        $r = $this->db->get('wallet')->result_array();

        $course_list;
        $course_array = array();

        foreach ($r as $key => $row) {

            $courses = json_decode($row['Courses_id'], true);
            foreach ($courses as $k => $course) {
                $name = $course;

                if ($name != "" && in_array($k, $course_array) == false) {
                    $course_list = $course_list. "<span>".$name."</span>";
                    array_push($course_array, $k);
                }

            }
            $r[$key]['Student'] = $this->crud_model->get_student_name($row['Student_ID']);
            $r[$key]['Course_list'] =  $course_list;
        }
        echo json_encode($r);
    }

    public function refresh_invoices()
    {
        $transactions = $this->wallet_model->get_invoices();

        $invoicesArray = array();
        foreach ($transactions as $transaction) {
            $address = $tansaction['Add_L1'].",<br>".$transaction['Add_L2'].",<br>".$transaction['Add_PC'].$transaction['Add_Location'];
            $amount = $this->wallet_model->get_invoice_price($transaction['Wallet_ID']);
            $token = $this->security_model->generateToken($transaction['ID']);

            $invoiceArray = array(
              'id' => $transaction['ID'],
              'Student_id' => $transaction['Customer_ID'],
              'Student_name' => $this->crud_model->get_student_name($transaction['Customer_ID']),
              'Society' => $this->crud_model->get_society_name($transaction['Society_ID']),
              'Customer_name' => $transaction['Customer_Name'],
              'Invoice_date' => $transaction['Invoice_Date'],
              'Payment_date' => $transaction['Payment_Date'],
              'Address' => $address,
              'Amount' => $amount,
              'Product' => $transaction['Product'],
              'Comment' => $transaction['Comment'],
              'Token' => $token,
              'Status' => $transaction['Status']
            );

            if (($this->wallet_model->get_credit_note($transaction['ID'])) != false) {
                $creditNoteArray = $this->wallet_model->get_credit_note($transaction['ID']);
                $invoiceArray = array_merge($invoiceArray, $creditNoteArray);
            }

            array_push($invoicesArray, $invoiceArray);
        }
        echo json_encode($invoicesArray);
    }

    public function cancel_invoice()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');

        $this->db->set(array('Status' => '3','Comment' => 'invoice aborted on :'.date('Y-m-d')));
        $this->db->where('ID', $id);
        $this->db->update('invoices');

        $sql = array(
          'Invoice_ID' => $id,
          'Comment' => 'credit note for #'.$id
        );

        $this->db->insert('credit_note', $this->crud_model->cleanArray($sql));
        echo $this->db->insert_id();
    }
    public function regenerate_invoice()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');

        $wallet_id = $this->wallet_model->get_wallet_invoice($id);
        $status = $this->wallet_model->get_transaction_status($wallet_id);

        $this->db->set(array('Status' => $status,'Comment' => 'invoice regenerated on :'.date('Y-m-d')));
        $this->db->where('ID', $id);
        $this->db->update('invoices');

        $this->db->where('Invoice_ID', $id);
        if ($this->db->delete('credit_note')) {
            echo "1";
        } else {
            echo "error";
        }

    }
    public function require_suggest($id_param)
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        if (!isset($id_param)) {
            $id = $this->input->post('id');
            $origin = $this->input->post('origin');
        } else {
            $id = $id_param;
        }
        $query = $this->db->get_where('wallet', array('Student_ID' => $id,'Status' => '2'));
        $query2 = $this->db->get_where('invoices_preview', array('Customer_ID' => $id));

        if ($query->num_rows() > 0) {
            $query = $query->result_array();
            $idSql = $query[0]['ID'];
            $amount = $query[0]['Payment_amount'];
            $date = $query[0]['Date'];

            $hash = $this->payment_model->hash_request($idSql, $id, abs($amount), $date);
            $link = "https://".base_url()."Payment/index/".$idSql."/".$hash."/";

            $invoice = $this->crud_model->get_user_invoice($id);

            $data = array(
              'id' => $id,
              'student_name' => $this->crud_model->get_student_name($id),
              'society' => $invoice['Society_ID'],
              'amount' => abs($amount),
              'name' => $invoice['Customer_Name'],
              'link' => $link,
              'add_l1' => $invoice['Add_L1'],
              'add_l2' => $invoice['Add_L2'],
              'postcode' => $invoice['Add_PC'],
              'location' => $invoice['Add_Location'],
              'country' => $invoice['Add_Country'],
              'require_date' => $date,
              'invoice_date' => $invoice['Invoice_Date'],
              'payment_date' => $invoice['Payment_Date'],
              'product' => $invoice['Product']
            );
        } elseif ($query2->num_rows() > 0) {
            $invoice_prev = $query2->result_array();
            //var_dump($invoice_prev);
            $data = array(
              'id' => $id,
              'student_name' => $this->crud_model->get_student_name($id),
              'society' => $invoice_prev[0]['Society_ID'],
              'amount' =>  $invoice_prev[0]['Amount'],
              'name' => $invoice_prev[0]['Customer_Name'],
              'link' => 'n/a',
              'add_l1' => $invoice_prev[0]['Add_L1'],
              'add_l2' => $invoice_prev[0]['Add_L2'],
              'postcode' => $invoice_prev[0]['Add_PC'],
              'location' => $invoice_prev[0]['Add_Location'],
              'country' => $invoice_prev[0]['Add_Country'],
              'require_date' => $invoice_prev[0]['Invoice_Date'],
              'invoice_date' => $invoice_prev[0]['Invoice_Date'],
              'payment_date' => $invoice_prev[0]['Payment_Date'],
              'product' => $invoice_prev[0]['Product']
            );
        } else {
            $society = $this->payment_model->detect_society($id);
            $product = $this->payment_model->detect_course($id);
            $userData = $this->crud_model->get_student_info($id);
            $address = $this->crud_model->get_user_address($userData[0]['residential_address_id']);
            $amount =  $this->wallet_model->wallet_balance($id);

            $parent = $this->crud_model->get_child_parent($id);
            $debug = $name;

            if ($parent == "0" || $parent == null) {
                $name = $this->crud_model->get_student_name($id);
            } else {
                $name = $this->crud_model->get_parent_name($parent);
            }

            $data = array(
              'debug' => $debug,
              'id' => $id,
              'student_name' => $this->crud_model->get_student_name($id),
              'name' => $name,
              'society' => $society,
              'amount' => abs($amount),
              'link' => 'n/a',
              'add_l1' => $address[0]['line_1'],
              'add_l2' => $address[0]['line_2'],
              'postcode' => $address[0]['postcode'],
              'location' => $address[0]['location'],
              'country' => $address[0]['country'],
              'product' => $product
            );
        }
        if (!isset($id_param)) {
            echo json_encode($data);
        } else {
            return $data;
        }
    }

    public function invoice_suggest()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $transactionId = $this->input->post('id');
        $id = $this->wallet_model->get_transaction_user($transactionId);

        $query = $this->db->get_where('wallet', array('Student_ID' => $id));
        $query = $query->result_array();

        $idSql = $query[0]['ID'];
        $amount = $query[0]['Payment_amount'];
        $date = $query[0]['Date'];
        $society =  $query[0]['Society_ID'];

        if ($society == 0) {
            $society = $this->payment_model->detect_society($id);
        }

        $product = $this->payment_model->detect_course($id);

        $userData = $this->crud_model->get_student_info($id);
        $address = $this->crud_model->get_user_address($userData[0]['residential_address_id']);


        $name = $this->crud_model->get_parent_name($id);
        if ($name == " " || $name == "") {
            $name = $this->crud_model->get_student_name($id);
        }

        $dueDate = strtotime("+7 day");

        $data = array(
          'id' => $id,
          'student_name' => $this->crud_model->get_student_name($id),
          'society' => $society,
          'amount' => abs($amount),
          'name' => $name,
          'add_l1' => $address[0]['line_1'],
          'add_l2' => $address[0]['line_2'],
          'postcode' => $address[0]['postcode'],
          'location' => $address[0]['location'],
          'country' => $address[0]['country'],
          'product' => $product,
          'require_date' => $date,
          'invoice_date' => date('Y-m-d'),
          'payment_date' => date('Y-m-d', $dueDate)
        );

        echo json_encode($data);
    }


    public function send_request()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');
        $link = $this->input->post('link');

        $email = $name = $lang = "";

        $parent = $this->crud_model->get_child_parent($id);
        //echo $parent;
        //check if parents
        if ($parent != "0") {
            $email = $this->crud_model->get_user_email($parent);
            $name = $this->crud_model->get_parent_name($parent);
            $lang = $this->crud_model->get_user_lang($parent);
        } else {
            $email = $this->crud_model->get_user_email($id);
            $name = $this->crud_model->get_student_name($id);
            $lang = $this->crud_model->get_user_lang($id);
        }

        if ($lang == "0") {
            $lang = "1";
        }

        $isoLang = $this->profile_model->intToIso($lang);

        try {
            //echo "$isoLang $link $name $email";
            echo $this->email_model->invoice_request_email($isoLang, $link, $name, $email, $id);
            //echo "1";
        } catch (Exception $e) {
            echo "error :".$e->getMessage();
        }

    }

    public function send_request_group()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');
        $message = $this->input->post('message');
        $link = $this->input->post('link');

        $email = $name = $lang = "";

        $parent = $this->crud_model->get_child_parent($id);
        //echo $parent;
        //check if parents
        if ($parent != "0") {
            $email = $this->crud_model->get_user_email($parent);
            $name = $this->crud_model->get_parent_name($parent);
            $lang = $this->crud_model->get_user_lang($parent);
        } else {
            $email = $this->crud_model->get_user_email($id);
            $name = $this->crud_model->get_student_name($id);
            $lang = $this->crud_model->get_user_lang($id);
        }

        if ($lang == "0") {
            $lang = "1";
        }

        $isoLang = $this->profile_model->intToIso($lang);

        try {
            //echo "$isoLang $link $name $email";
            echo $this->email_model->invoice_request_email_custom($isoLang, $link, $name, $email, $message, $id);
            //echo "1";
        } catch (Exception $e) {
            //  echo "error :".$e->getMessage();
        }

    }

    public function require()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post([
            'id','society', 'amount', 'payment_date', 'payment_expiration', 'invoice_date',
            'due_date', 'customer_name', 'customer_add_l1', 'customer_add_l2', 'customer_add_country',
            'customer_add_code', 'customer_add_city', 'customer_product', 'payment_expiration'
        ]);
        $idSql = "";

        $sql = array(
          'Student_ID' => $data['id'],
          'Payment_amount' => abs($data['amount']),
          'Method_ID' => '3',
          'Status' => '2',
          'Date' => $this->format_date($data['payment_date']),
          'Comment' => 'payment request for '.$this->crud_model->get_student_name($data['id']),
          'Society_id' => $data['society'],
          'Payment_expiration' => $this->format_date($data['payment_expiration'])
        );
        $query = $this->db->get_where('wallet', array('Student_ID' => $data['id'],'Status' => '2')); //avoid duplicate request
        if ($query->num_rows() == 0) {
            $this->db->insert('wallet', $this->crud_model->cleanArray($sql));
            $idSql = $this->db->insert_id();

            $sqlInvoice = array(
              "Wallet_ID" => "$idSql",
              "Customer_ID" => $data['id'],
              "Society_ID" => $data['society'],
              "Customer_Name" => $data['customer_name'],
              "Invoice_Date" => $this->format_date($data['invoice_date']),
              "Payment_Date" => $this->format_date($data['due_date']),
              "Add_L1" => $data['customer_add_l1'],
              "Add_L2" => $data['customer_add_l2'],
              "Add_PC" => $data['customer_add_code'],
              "Add_Country" => $data['customer_add_country'],
              "Add_Location" => $data['customer_add_city'],
              "Product" => $data['customer_product'],
              "Status" => "2"
            );
            //var_dump($sqlInvoice);
            $this->db->insert('invoices', $this->crud_model->cleanArray($sqlInvoice));

        }

        $hash = $this->payment_model->hash_request($idSql, $data['id'], abs($data['amount']), $this->format_date($data['payment_date']));//$this->format_date($data['payment_date']));
        echo "https://".base_url()."Payment/index/".$idSql."/".$hash."/";

    }

    public function preview()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('id','society','amount','payment_date','invoice_date','due_date','customer_name','customer_add_l1','customer_add_l2','customer_add_country','customer_add_code','customer_add_city','customer_product'));
        $idSql = "";

        $this->db->where('CUSTOMER_ID', $data['id']);
        $q = $this->db->get('invoices_preview');

        $sqlInvoice = array(
          "Customer_ID" => $data['id'],
          "Society_ID" => $data['society'],
          "Amount" => $data['amount'],
          "Customer_Name" => $data['customer_name'],
          "Invoice_Date" => $this->format_date($data['invoice_date']),
          "Payment_Date" => $this->format_date($data['due_date']),
          "Add_L1" => $data['customer_add_l1'],
          "Add_L2" => $data['customer_add_l2'],
          "Add_PC" => $data['customer_add_code'],
          "Add_Country" => $data['customer_add_country'],
          "Add_Location" => $data['customer_add_city'],
          "Product" => $data['customer_product'],
        );

        if ($q->num_rows() > 0) {
            $this->db->set($sqlInvoice);
            $this->db->where('Customer_ID', $data['id']);
            $this->db->update('invoices_preview');
            echo "1";
        } else {
            $this->db->insert('invoices_preview', $this->crud_model->cleanArray($sqlInvoice));
            echo $this->db->insert_id();
        }
    }

    public function remove_payment()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');

        //check if associated to invoice
        if ($this->wallet_model->verify_linked($id)) {
            echo "first remove transaction from invoice";
            return;
        }

        //echo "..";
        //return;
        //check if liked
        $this->db->where('ID', $id);
        $r = $this->db->get('wallet')->result_array()[0];

        if ($r['Linked'] == 1) {
            $rep = $r['Linked_repartition'];

            if ($rep != '0') {

                $this->db->where('Linked_ID', $r['Linked_ID']);
                $linked = $this->db->get('wallet')->result_array();
                $nb_linked = count($linked) - 1;

                if ($nb_linked > 0) {
                    $rep_n = $rep / $nb_linked;
                    foreach ($linked as $key => $l) {
                        if ($r['ID'] != $l['ID']) {

                            $target_rep = ($rep_n + $l['Linked_repartition']);
                            if ($target_rep > 100) {
                                //preven for group
                                $target_rep = 100;
                            }
                            $this->db->set('Linked_repartition', $target_rep);
                            $this->db->where('ID', $l['ID']);
                            $this->db->update('wallet');
                        }
                    }
                } else {
                    //one occurence: to delete
                }
            }
        }

        $this->db->where('ID', $id);
        if ($this->db->delete('wallet')) {

            $this->db->set('Status', '3');
            $this->db->where('Wallet_ID', $id);
            $this->db->update('invoices');

            echo "1";
        } else {
            echo "-1";
        }
    }

    public function profile()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');
        $query = $this->db->get_where('wallet', array('Student_ID' => $id));
        $history = $query->result_array();

        foreach ($history as $key => $tran) {
            $unser =  unserialize($tran['Linked_users']);
            $arrayUser = array();
            foreach ($unser as $key => $user) {
                $array = [
                  "id" => $user,
                  "name" => $this->crud_model->get_name($user)
                ];
                array_push($arrayUser, $array);
            }
            $history[$key]['Linked_users'] = $arrayUser;
        }
        $query2 = $this->db->get_where('discount', array('Student_ID' => $id));
        $discount = $query2->result_array();
        $courses = $this->crud_model->get_students_course($id);
        $courses_info = array();

        foreach ($courses as $course) {
            $course_data = $this->crud_model->get_course_info($course);

            $course_info = array(
              'Course_ID' => $course,
              'Course_Name' => $this->crud_model->get_course_name($course),
              'Course_Info' => "[ ".$this->crud_model->get_course_start($course)." - ".$this->crud_model->get_course_end($course)." ]",
              'Course_Price' => round($course_data[0]['CoursePrice'] * $course_data[0]['CourseContract']),
              'Course_Comment' => $course_data[0]['CourseDescription'],
              'Course_Factured' => $course_data[0]['CourseFactured']
            );
            array_push($courses_info, $course_info);
        }

        $profile = [
            'student' => $id,
            'total' => $this->wallet_model->payment_total($id),
            'balance' => $this->wallet_model->wallet_balance($id),
            'history' => $history,
            'course' => $courses_info,
            'discount' => $discount
        ];
        echo json_encode($profile);
    }

    public function get_token()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');
        echo $this->security_model->generateToken($id);
    }

    public function add_payment()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('student','amount','type','date','comment','ref','linked_repartition','linked_courses','linked_users'));

        $j_rep = null;
        if (is_array($data['linked_repartition'])) {
            $j_rep = $data['linked_repartition'];
        } else {
            try {
                $j_rep = json_decode($data['linked_repartition'], true);
            } catch (Exception $e) {}
        }

        if ($data['linked_repartition'] == "{}" || $data['linked_repartition'] == '{"":"0"}' || empty($j_rep)) {
            $this->db->insert('wallet', [
                'Payment_ID' => $data['ref'],
                'Student_ID' => $data['student'],
                'Payment_amount' => $data['amount'],
                'Method_ID' => $data['type'],
                'Status' => '1',
                'Date' => date("Y-m-d", strtotime($data['date'])),
                'Comment' => $data['comment'],
                'Courses_id' => $data['linked_courses'],
                'Payment_expiration' => ''
            ]);
            $id = $this->db->insert_id();
            echo $id;
        } else {
            $uniqueId = $this->security_model->randString('6');
            foreach ($j_rep as $user => $rep) {
                $this->db->insert('wallet', [
                    'Payment_ID' => $data['ref'],
                    'Student_ID' => $user,
                    'Payment_amount' => $data['amount'],
                    'Method_ID' => $data['type'],
                    'Status' => '1',
                    'Date' => date("Y-m-d", strtotime($data['date'])),
                    'Comment' => $data['comment'],
                    'Courses_id' => $data['linked_courses'],
                    'Payment_expiration' => '',
                    'Linked' => '1',
                    'Linked_repartition' => $rep,
                    'Linked_ID' => $uniqueId
                ]);
                $id = $this->db->insert_id();
            }
            echo $id;
        }
    }

    public function add_invoice()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('id','society','amount','date','invoice_date','invoice_due','l1','l2','coun','code','loca','invoice_name','invoice_product'));

        if ($this->wallet_model->check_if_factured($data['id']) != '2' && $this->wallet_model->check_if_factured($data['id']) != '1') {

            $sqlInvoice = array(
              "Wallet_ID" => $data['id'],
              "Customer_ID" => $this->wallet_model->get_transaction_user($data['id']),
              "Society_ID" => $data['society'],
              "Customer_Name" => $data['invoice_name'],
              "Invoice_Date" => $this->format_date($data['invoice_date']),
              "Payment_Date" => $this->format_date($data['invoice_due']),
              "Add_L1" => $data['l1'],
              "Add_L2" => $data['l2'],
              "Add_PC" => $data['code'],
              "Add_Country" => $data['coun'],
              "Add_Location" => $data['loca'],
              "Product" => $data['invoice_product'],
              "Status" => '1'
            );
            //var_dump($sqlInvoice);
            $this->db->insert('invoices', $this->crud_model->cleanArray($sqlInvoice));
            echo $this->db->insert_id();

        } elseif ($this->wallet_model->check_if_factured($data['id']) == '2') {
            echo "invoice already generated : payment pending";
        } elseif ($this->wallet_model->check_if_factured($data['id']) == '1') {
            echo "invoice already generated : payment done";
        } else {
            echo "out of range";
        }
    }

    public function add_discount()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $data = $this->input->post(array('student','amount','date','comment','ref'));

        $sql = array(
          'Discount_ID' => $data['ref'],
          'Student_ID' => $data['student'],
          'Discount_amount' => $data['amount'],
          'Date' => date("Y-m-d", strtotime($data['date'])),
          'Comment' => $data['comment']
        );
        $this->db->insert('discount', $this->crud_model->cleanArray($sql));
        $id = $this->db->insert_id();
        echo $id;
        //echo $data['date'];
    }
    public function remove_require()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');

        $sql = array(
          "Comment" => "invoice aborted on :".date("Y-m-d"),
          "Status" => "3"
        );

        $this->db->set($sql);
        $this->db->where('Student_ID', $id);

        if ($this->db->update('wallet')) {
            //mark first wallet

            $this->db->set($sql);
            $this->db->where('Customer_ID', $id);
            $this->db->update('invoices');

            echo "1";
        } else {
            echo "-1";
        }
    }

    public function remove_discount()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');
        $this->db->where('ID', $id);
        if ($this->db->delete('discount')) {
            echo "1";
        } else {
            echo "-1";
        }
    }

    public function facture_course()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');

        $sql = array(
          'CourseFactured' => '1'
         );

        $this->db->set($sql);
        $this->db->where('ID', $id);
        $this->db->update('course_new');
        echo "1";
    }
    public function un_facture_course()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');

        $sql = array(
          'CourseFactured' => '0'
         );

        $this->db->set($sql);
        $this->db->where('ID', $id);
        $this->db->update('course_new');
        echo "1";
    }

    public function notify_invoice()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');//invoice id
        $type = $this->input->post('type');

        $wallet_id = $this->wallet_model->get_wallet_invoice($id);
        $token = $this->security_model->generateToken($id);

        $userId = $this->wallet_model->get_transaction_user($wallet_id);
        //  echo "==>$userId";
        $email = $name = $lang = "";

        $parent = $this->crud_model->get_child_parent($userId);

        if ($parent != "0") {
            $email = $this->crud_model->get_user_email($parent);
            $name = $this->crud_model->get_parent_name($parent);
            $lang = $this->crud_model->get_user_lang($parent);
        } else {
            $email = $this->crud_model->get_user_email($userId);
            $name = $this->crud_model->get_student_name($userId);
            $lang = $this->crud_model->get_user_lang($userId);
        }

        if ($lang == "0") {
            $lang = "1";
        }

        $isoLang = $this->profile_model->intToIso($lang);

        //echo "$isoLang,$token,$id,$name,$email";
        try {
            if ($type == "invoice") {
                $this->email_model->invoice_email($isoLang, $token, $id, $name, $email, $userId);
                echo "1";
            } elseif ($type == "credit_note") {
                $this->email_model->credit_note_email($isoLang, $token, $id, $name, $email, $userId);
                echo "1";
            }
        } catch (Exception $e) {
            echo "mail error :".$e->getMessage();
        }
    }

    public function format_date($dateOriginal)
    {
        $dateArray = date_parse($dateOriginal);
        $date = $dateArray['year']."-". str_pad($dateArray['month'], 2, '0', STR_PAD_LEFT)."-".str_pad($dateArray['day'], 2, '0', STR_PAD_LEFT);
        return $date;
    }

    public function require_multiple_course()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');//119
        $student_list = $this->db->get_where('course_student_new', array('course_id' => $id))->result_array();

        $students = array();
        $jsonTable = array();
        foreach ($student_list as $student) {
            if (!in_array($student['student_id'], $students)) {
                array_push($students, $student['student_id']);

                $json = $this->require_suggest($student['student_id']);
                //var_dump($json);
                array_push($jsonTable, $json);
            }
        }
        //var_dump($students);
        echo json_encode($jsonTable);
    }
    public function require_single_course()
    {
        $this->continueIfAllowed(array('allowed' => array('admin')));
        $id = $this->input->post('id');//119

        foreach ($student_list as $student) {
            if (!in_array($student['student_id'], $students)) {
                array_push($students, $student['student_id']);

                $json = $this->require_suggest($student['student_id']);
                //var_dump($json);
                array_push($jsonTable, $json);
            }
        }
        //var_dump($students);
        echo json_encode($jsonTable);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit