?
Current Path : /home1/savoy/public_html/savoyglobal.net/sec/application/models/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/sec/application/models/franchiseemodel.php |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Franchiseemodel extends CI_Model { function __construct() { // Call the Model constructor parent::__construct(); // $this->load->model('hrmodel'); $this->load->model('accountingmodel'); } function search_franchisee() { $data = array(); $this->db->select('*'); $this->db->from('franchisee'); $this->db->join('master', 'master_id=franchisee_id'); $this->db->order_by('franchisee_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function insert_franchisee($postdata) { $data = array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues = array( 'franchisee_id' => $masterid, 'franchisee_name' => $postdata['franchisee_name'], 'franchisee_code' => $postdata['franchisee_code'], 'franchisee_address' => $postdata['franchisee_address'], 'franchisee_contact_no' => $postdata['franchisee_contact_no'], 'franchisee_email' => $postdata['franchisee_email'], 'franchisee_website' => $postdata['franchisee_website'], 'franchisee_remarks' => $postdata['franchisee_remarks'], ); $this->db->insert('franchisee', $tblValues); $i = 1; while (isset($postdata['course_id' . $i])) { if ($postdata['course_id' . $i] != "") { $tblValues = array( 'franchisee_id' => $masterid, 'course_id' => $postdata['course_id' . $i], 'franchisee_course_royalty' => $postdata['franchisee_course_royalty' . $i], 'franchisee_course_remarks' => $postdata['franchisee_course_remarks' . $i], ); $this->db->insert('franchisee_course', $tblValues); } $i++; } $i = 1; while (isset($postdata['franchisee_contact_person_name' . $i])) { if ($postdata['franchisee_contact_person_name' . $i] != "") { $tblValues = array( 'franchisee_id' => $masterid, 'franchisee_contact_person_name' => $postdata['franchisee_contact_person_name' . $i], 'franchisee_contact_no' => $postdata['franchisee_contact_no' . $i], 'franchisee_contact_email' => $postdata['franchisee_contact_email' . $i], 'franchisee_contact_address' => $postdata['franchisee_contact_address' . $i] ); $this->db->insert('franchisee_contact', $tblValues); } $i++; } $parent = $this->mastermodel->get_account_settings('franchisee', 'finance_sub_account_settings'); if ($parent) { $chart_type_id = $this->mastermodel->get_single_field_value('finance_chart_master', 'chart_type_id', 'chart_master_id', $parent); if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $postdata['franchisee_code']) == 0) { $tblValues = array( 'chart_account_code' => $postdata['franchisee_code'], 'chart_account_name' => $postdata['franchisee_name'], 'chart_type_id' => $chart_type_id, 'parent' => $parent, 'inactive' => 0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues = array( 'chart_account_name' => $postdata['franchisee_name'], 'chart_type_id' => $chart_type_id, 'parent' => $parent, 'inactive' => 0); $this->db->where('chart_account_code', $postdata['franchisee_code']); $this->db->update('finance_chart_master', $tblValues); } } $data['resfunction'] = 'search_franchisee'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_franchisee($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'franchisee_name' => $postdata['franchisee_name'], 'franchisee_address' => $postdata['franchisee_address'], 'franchisee_contact_no' => $postdata['franchisee_contact_no'], 'franchisee_email' => $postdata['franchisee_email'], 'franchisee_website' => $postdata['franchisee_website'], 'franchisee_remarks' => $postdata['franchisee_remarks'], ); $this->db->where('franchisee_id', $postdata['franchisee_id']); $this->db->update('franchisee', $tblValues); $this->db->where('franchisee_id', $postdata['franchisee_id']); $this->db->delete('franchisee_course'); $i = 1; while (isset($postdata['course_id' . $i])) { if ($postdata['course_id' . $i] != '') { $tblValues = array( 'franchisee_id' => $postdata['franchisee_id'], 'course_id' => $postdata['course_id' . $i], 'franchisee_course_royalty' => $postdata['franchisee_course_royalty' . $i], 'franchisee_course_remarks' => $postdata['franchisee_course_remarks' . $i], ); $this->db->insert('franchisee_course', $tblValues); } $i++; } $this->db->where('franchisee_id', $postdata['franchisee_id']); $this->db->delete('franchisee_contact'); $i = 1; while (isset($postdata['franchisee_contact_person_name' . $i])) { if ($postdata['franchisee_contact_person_name' . $i] != '') { $tblValues = array( 'franchisee_id' => $postdata['franchisee_id'], 'franchisee_contact_person_name' => $postdata['franchisee_contact_person_name' . $i], 'franchisee_contact_no' => $postdata['franchisee_contact_no' . $i], 'franchisee_contact_email' => $postdata['franchisee_contact_email' . $i], 'franchisee_contact_address' => $postdata['franchisee_contact_address' . $i] ); $this->db->insert('franchisee_contact', $tblValues); } $i++; } $parent = $this->mastermodel->get_account_settings('franchisee', 'finance_sub_account_settings'); if ($parent) { $chart_type_id = $this->mastermodel->get_single_field_value('finance_chart_master', 'chart_type_id', 'chart_master_id', $parent); if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $postdata['franchisee_code']) == 0) { $tblValues = array('chart_account_code' => $postdata['franchisee_code'], 'chart_account_name' => $postdata['franchisee_name'], 'chart_type_id' => $chart_type_id, 'parent' => $parent, 'inactive' => 0); $this->db->insert('finance_chart_master', $tblValues); } else { $tblValues = array( 'chart_account_name' => $postdata['franchisee_name'], 'chart_type_id' => $chart_type_id, 'parent' => $parent, 'inactive' => 0); $this->db->where('chart_account_code', $postdata['franchisee_code']); $this->db->update('finance_chart_master', $tblValues); } } $data['resfunction'] = 'search_franchisee'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function search_franchisee_fee($pagenum) { $data = array(); $this->db->select('*'); $this->db->from('batch'); $this->db->join('course', 'course.course_id=batch.course_id'); $this->db->join('franchisee_course', 'franchisee_course.course_id=course.course_id'); //$this->db->where('close', '0'); $this->db->order_by('batch_id', 'desc'); $data['results'] = $this->db->get(); return $data; } function get_batch_student_details($batch_id, $course_id) { $data = array(); $this->db->select('*,student_batch.student_batch_id as student_batch_id ,student_batch.student_id as student_id,student_batch.current_batch_id as batch_id'); $this->db->from('student_batch'); $this->db->join('student', 'student.student_id=student_batch.student_id'); // $this->db->join('student_cancellation', 'student_cancellation.student_batch_id=student_batch.student_batch_id', 'left'); $this->db->where('course_id', $course_id); $this->db->where('current_batch_id', $batch_id); // $this->db->where('date' <=date("Y-m-d")); // $this->db->having('cancellation_id is null'); $this->db->order_by('date'); $Q = $this->db->get(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_franchisee_batch_details($id) { $data = array(); $this->db->select('*'); $this->db->from('franchisee_fee'); $this->db->join('franchisee', 'franchisee.franchisee_id=franchisee_fee.franchisee_id', 'left'); $this->db->where('franchisee_fee_id', $id); $data = $this->db->get(); return $data->row(); } function insert_franchisee_fee($postdata) { $data = array(); $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $tblValues = array('franchisee_fee_id' => $masterid, 'franchisee_fee_batch_id' => $postdata['franchisee_fee_batch_id'], 'franchisee_fee_amount' => $postdata['franchisee_fee_amount'], 'franchisee_fee_payment_mode' => $postdata['franchisee_fee_payment_mode'], 'franchisee_receipt_no' => $postdata['franchisee_receipt_no'], 'franchisee_fee_payment_remarks' => $postdata['franchisee_fee_payment_remarks'], 'franchisee_fee_date' => $this->mastermodel->convertdateformat($postdata['franchisee_fee_date']), 'franchisee_id' => $postdata['franchisee_id'] ); $this->db->insert('franchisee_fee', $tblValues); $data['resfunction'] = 'search_franchisee_fee'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } function update_franchisee_fee($postdata) { $data = array(); $this->db->trans_begin(); $tblValues = array( 'franchisee_fee_amount' => $postdata['franchisee_fee_amount'], 'franchisee_fee_payment_mode' => $postdata['franchisee_fee_payment_mode'], 'franchisee_receipt_no' => $postdata['franchisee_receipt_no'], 'franchisee_fee_payment_remarks' => $postdata['franchisee_fee_payment_remarks'], 'franchisee_fee_date' => $this->mastermodel->convertdateformat($postdata['franchisee_fee_date']), 'franchisee_id' => $postdata['franchisee_id'] ); $this->db->where('franchisee_fee_id', $postdata['franchisee_fee_id']); $this->db->update('franchisee_fee', $tblValues); $data['resfunction'] = 'search_franchisee_fee'; if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Updating Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Updated Successfully'; return $data; } } function get_student_batch($id) { $data = array(); $this->db->select('*'); // $this->db->join('student_batch', 'student_batch.current_batch_id=batch.batch_id', 'left'); $this->db->join('student', 'student.student_id=student_batch.student_id'); $this->db->where('current_batch_id', $id); $this->db->order_by('student.student_id', 'asc'); $Q = $this->db->get('student_batch'); // echo $this->db->last_query(); if ($Q->num_rows() > 0) { foreach ($Q->result_array() as $row) { $data[] = $row; } } $Q->free_result(); return $data; } function get_franchisee_details_for_edit($id) { $data = array(); $this->db->select('*'); $this->db->from('batch'); $this->db->join('franchisee_fee', 'franchisee_fee.franchisee_fee_batch_id=batch.batch_id'); $this->db->join('franchisee', 'franchisee.franchisee_id=franchisee_fee.franchisee_id'); $this->db->where('batch.batch_id', $id); $this->db->order_by('batch.batch_id', 'asc'); $data = $this->db->get(); return $data->result(); } function get_all_deatils_for_pdf_franchisee($id) { $data = array(); $this->db->select('*'); $this->db->from('franchisee_fee'); $this->db->join('batch', 'batch.batch_id=franchisee_fee.franchisee_fee_batch_id'); $this->db->join('course', 'course.course_id=batch.course_id', 'left'); $this->db->join('franchisee', 'franchisee.franchisee_id=franchisee_fee.franchisee_id'); $this->db->join('finance_journal_refs', 'finance_journal_refs.journal_id=franchisee_fee.journal_id', 'left'); $this->db->where('franchisee_fee.franchisee_fee_id', $id); $this->db->order_by('franchisee_fee.franchisee_fee_id', 'desc'); $data = $this->db->get(); // var_dump($data->row_array()); // die(); // echo $this->db->last_query(); return $data->result(); } function get_franchisee_details($id) { $this->db->select('*, franchisee.franchisee_id as franchisee_name_id'); $this->db->from('batch'); $this->db->join('course', 'course.course_id = batch.course_id'); $this->db->join('franchisee_course', 'franchisee_course.course_id=course.course_id'); $this->db->join('franchisee', 'franchisee.franchisee_id=franchisee_course.franchisee_id'); $this->db->where('batch.batch_id', $id); $Q = $this->db->get(); // echo $this->db->last_query(); $row = $Q->row(); return $row; } function get_paid_royaly($batch_id) { $data = $this->db->query("select SUM(franchisee_fee_amount) as franchisee_fee_amount from franchisee_fee where franchisee_fee_batch_id ='" . $batch_id . "'"); $result = $data->row(); if ($result) { return $result->franchisee_fee_amount; } else { return 0; } } function get_total_royalty($batch_id) { // echo "select SUM(amount_paid) as course_fee from // fee_paid_details join fee ON fee.fee_id = fee_paid_details.fee_id join student_batch ON student_batch.student_batch_id = fee.student_batch_id where fee_type = 'course' and current_batch_id ='" . $batch_id . "'"; $data = $this->db->query("select SUM(amount_paid) as course_fee from fee_paid_details join fee ON fee.fee_id = fee_paid_details.fee_id join student_batch ON student_batch.student_batch_id = fee.student_batch_id where fee_type = 'course' and current_batch_id ='" . $batch_id . "'"); $result = $data->row(); if ($result) { return $result->course_fee; } else { return 0; } } function get_paid_fee_details($batch_id, $student_id) { $data = array(); $this->db->select('*'); $this->db->from('fee'); $this->db->join('fee_paid_details', 'fee_paid_details.fee_id=fee.fee_id'); $this->db->join('student_batch', 'student_batch.student_batch_id=fee.student_batch_id'); $this->db->where('current_batch_id', $batch_id); $this->db->where('student_batch.student_id', $student_id); $res = $this->db->get(); $crs = 0; if ($res->num_rows() > 0) { foreach ($res->result_array() as $row) { if ($row['fee_type'] == 'course') { $crs+=$row['amount_paid']; } } } // $data = array('course_paid_fee' => $crs, 'reg_fee_paid' => $reg, 'extra_fee_paid' => $extra, 'books_fee_paid' => $books); return $crs; } function set_payment_voucher_fee_settings($postdata) { $data = array(); // $course = $this->mastermodel->get_single_joined_value('course_name', 'course', 'batch', 'course_id', 'course_id', 'batch_id', $postdata['batch_id']); // $student = $this->mastermodel->get_data_srow('student', $postdata['student_id'], 'student_id'); $fisc_year_id = $this->accountingmodel->getfiscalyearid(); $default_currency = $this->accountingmodel->getcurrency(); $data['resfunction'] = 'search_franchisee_fee'; if ($fisc_year_id != 0 && $default_currency != 0) { $this->db->trans_begin(); $masterid = $this->mastermodel->insertmasterdata(); $account = explode("~", $postdata['bankacc_id']); $account_to_id = $account[0]; $account_to_code = $account[1]; $account_to_name = $account[2]; $description = $postdata['description']; $transaction_id = $postdata['transaction_id']; $payment_type = $postdata['payment_type_id']; $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type); $tblValues = array( 'journal_id' => $masterid, 'journal_date' => $this->mastermodel->convertdateformat($postdata['journal_date']), 'description' => $description, 'reference' => $reference, 'currency_id' => $default_currency, 'payment_type_id' => $postdata['payment_type_id'], 'transaction_id' => $postdata['transaction_id'], 'posted' => '1' ); $this->db->insert('finance_journal_refs', $tblValues); if ($postdata['payment_type_id'] == 2) { $tblValues = array( 'journal_id' => $masterid, 'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']), 'cheque_no ' => $postdata['cheque_no'], 'chart_account_code' => $account_to_code, 'cheque_info' => $postdata['cheque_info'] ); $this->db->insert('finance_cheque_info', $tblValues); } else if ($postdata['payment_type_id'] == 3) { $tblValues = array( 'journal_id' => $masterid, 'wire_info' => $postdata['wire_info'], ); $this->db->insert('finance_wire_info', $tblValues); } else if ($postdata['payment_type_id'] == 4) { $tblValues = array( 'journal_id' => $masterid, 'card_info' => $postdata['card_info'], ); $this->db->insert('finance_card_info', $tblValues); } $total_amount = 0; if ($postdata['payment_to_id'] != "") { $chart_account = explode("~", $postdata['payment_to_id']); $chart_account_id = $chart_account[0]; $chart_account_code = $chart_account[1]; $chart_account_name = $chart_account[2]; $total_amount = $postdata['amount']; $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $chart_account_code, 'debit' => $total_amount, 'credit' => 0, 'description' => $description, 'fiscal_year_id' => $fisc_year_id, ); $this->db->insert('finance_journal', $tblValues); } $tblValues = array( 'journal_id' => $masterid, 'chart_account_code' => $account_to_code, 'debit' => 0, 'credit' => $total_amount, 'description' => $description, 'fiscal_year_id' => $fisc_year_id ); $this->db->insert('finance_journal', $tblValues); $tblValues = array( 'journal_id' => $masterid, 'param_id' => $postdata['franchisee_fee_id'], 'refs_type' => 'Franchisee Fee Payment', 'param_table' => 'franchisee_fee' ); $this->db->insert('finance_refs', $tblValues); $tblValues = array( 'journal_id' => $masterid ); $this->db->where('franchisee_fee_id', $postdata['franchisee_fee_id']); $this->db->update('franchisee_fee', $tblValues); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $data['res'] = 0; $data['msg'] = 'Error On Adding Record'; return $data; } else { $this->db->trans_commit(); $data['res'] = 1; $data['msg'] = 'Record Added Successfully'; return $data; } } else { $data['res'] = 0; if ($fisc_year_id == 0) $data['msg'] = 'Fiscal Year Not Set.'; else if ($default_currency == 0) $data['msg'] = 'Default Currency Not Set.'; else $data['msg'] = 'Fiscal Year and Default Currency Not Set.'; return $data; } } } ?>