| Server IP : 188.114.96.2 / Your IP : 104.23.243.200 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/git/sms.edl.codes.solutions/application/models/ |
Upload File : |
<?php
/*********************
*********************
Wallet Model
Creation 22 august 2019
Aernout Guillaume
http://Codes.Solutions
*********************
*********************/
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Wallet_model extends CI_Model {
function __construct() {
parent::__construct(array('no_cache'=>1));
//$this->_ci =& get_instance();
$this->load->model('crud_model');
$this->load->database();
}
function payment_total($studentID){
$query = $this->db->get_where('wallet',array('Student_ID'=>$studentID));
$data = $query->result_array();
$total = "0";
foreach ($data as $row) {
if($row['Status'] != "2" && $row['Status'] != "3"){
$total = $total + $row['Payment_amount'];
}
}
return $total;
}
function payment_last($studentID){
$this->db->order_by("ID", "DESC");
$query = $this->db->get_where('wallet',array('Student_ID'=>$studentID));
$data = $query->result_array();
foreach ($data as $row) {
return date("d-m-Y", strtotime($row['Date']));
}
}
function get_discount($studentID){
//$this->db->order_by("student_id", "DESC");
$query = $this->db->get_where('discount',array('student_id'=>$studentID));
$data = $query->result_array();
$total = "0";
foreach ($data as $row) {
$total = $total + $row['Discount_amount'];
}
return $total;
}
function is_vat_course($courseID){
$query = $this->db->get_where('course_new',array('ID'=>$courseID));
$data = $query->result_array();
foreach ($data as $row) {
if($row['CourseVat'] == "yes"){
return true;
}
}
return false;
}
function is_factured_course($courseID){
$query = $this->db->get_where('course_new',array('ID'=>$courseID));
$data = $query->result_array();
foreach ($data as $row) {
if($row['CourseFactured'] == "1"){
return true;
}
}
return false;
}
function get_invoices(){
$this->db->order_by('ID', 'ASC');
$query = $this->db->get('invoices');
return $query->result_array();
}
function get_invoice($id){
$query = $this->db->get_where('invoices',array('ID'=>$id));
$query = $query->result_array();
foreach ($query as $row) {
return $row;
}
}
function get_credit_note($invoice_id){
$query = $this->db->get_where('credit_note',array('Invoice_ID'=>$invoice_id));
$query = $query->result_array();
if(empty($query)){
return false;
}
else{
//return $query;
foreach ($query as $note) {
return array(
'Credit_Note_ID' => $note['ID'],
'Credit_Note_Date' => $note['Date'],
'Credit_Note_Comment' => $note['Comment']
);
}
}
}
function get_invoice_wallet($wallet_id){
$query = $this->db->get_where('invoices',array('Wallet_ID'=>$wallet_id));
//return $this->db->last_query();
$array = $query->result_array();
foreach ($array as $row) {
return $row['ID'];
}
}
function get_wallet_invoice($invoice_id){
$query = $this->db->get_where('invoices',array('ID'=>$invoice_id));
//return $this->db->last_query();
$array = $query->result_array();
foreach ($array as $row) {
return $row['Wallet_ID'];
}
}
function wallet_balance($studentID){
$course_list = $this->crud_model->get_students_course($studentID);
$discount = $this->get_discount($studentID);
$vat = "21"; // set vat in db
$grandTotal = "0";
// abandon du modèle par heure réel
// Backup du code sur Wallet_model.save
//foreach ($lesson_list as $lesson) {
foreach ($course_list as $course) {
$total = "0";
$coursePrice = $this->crud_model->get_course_price($course);
$courseContract = $this->crud_model->get_course_contract($course);
if($this->is_factured_course($course)){
$total = $coursePrice * $courseContract;
//vat check
if($this->is_vat_course($course)){
$vatPrice = (($total / 100)*$vat);
$total = $vatPrice + $total;
}
$grandTotal = round(($grandTotal + $total),0);
}
}
//discount check
if($discount > 0){
//$discountPrice = (($total * $discount)/100); abandon du pourcentage
$grandTotal = $grandTotal - $discount;
}
return round(($this->payment_total($studentID) - $grandTotal),2); // arrondi au centime
}
function check_if_factured($id){
$query = $this->db->get_where('invoices', array('Wallet_ID' => $id));
$res = $query->result_array();
foreach ($res as $row){
return $row['Status'];
}
return false;
}
function get_transaction_user($id){
$query = $this->db->get_where('wallet', array('ID' => $id));
$res = $query->result_array();
foreach ($res as $row){
return $row['Student_ID'];
}
}
function get_transaction_status($id){
$query = $this->db->get_where('wallet', array('ID' => $id));
$res = $query->result_array();
foreach ($res as $row){
if($row['Status'] == NULL){
return "0";
}
return $row['Status'];
}
}
function get_transactions(){
$query= $this->db->get('wallet');
$res = $query->result_array();
return $res;
}
function get_invoice_price($id){
$query = $this->db->get_where('wallet',array('ID'=>$id));
$data = $query->result_array();
foreach ($data as $row) {
return $row['Payment_amount'];
}
return "0";
}
}
?>