function index() { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $this->load->library('pagination'); $this->load->model(array('customer_file_model')); $this->load->helper('form'); $config['base_url'] = site_url('sales/approval_management/index'); $this->db->from('customer_file'); $this->db->join('contact', 'customer_file.customer_id=contact.id'); $this->db->join('project', 'customer_file.project_id=project.id'); $this->db->join('availability_chart_unit', 'customer_file.unit_id=availability_chart_unit.id'); $this->db->where('customer_file.approval_status', 0); if (isset($usr_accs[1])) { if ($usr_accs[1] != 1) { $this->db->where('customer_file.customer_care', $user_id); } } else { $this->db->where('customer_file.customer_care', $user_id); } $config['total_rows'] = $this->db->count_all_results(); $config['uri_segment'] = 4; $config['per_page'] = 20; $config['full_tag_open'] = '<ul class="pagination pull-right">'; $config['full_tag_close'] = '</ul>'; $this->pagination->initialize($config); $data['customer_files'] = $this->customer_file_model->list_customer_file_not_approved($config['per_page'], $this->uri->segment(4)); $this->load->view('sales/approval_management', $data); }
function search_customer_file_pages($num, $offset) { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $search_query = $this->input->get('search_query'); $this->db->select('customer_file.id as customer_file_id,' . 'customer_file.schedule_edit_status as schedule_edit_status,' . 'customer_file.file_number as file_number,' . 'project.name as project,' . 'availability_chart_unit.unit_name as unit,' . 'contact.name as customer'); $this->db->from('customer_file'); $this->db->join('project', 'customer_file.project_id=project.id'); $this->db->join('availability_chart_unit', 'customer_file.unit_id=availability_chart_unit.id'); $this->db->join('contact', 'customer_file.customer_id=contact.id'); if (!empty($search_query)) { $this->db->like('contact.name', $search_query); $this->db->or_like('project.name', $search_query); $this->db->or_like('availability_chart_unit.unit_name', $search_query); $this->db->or_like('CONCAT(project.name,\'-\',availability_chart_unit.unit_name)', $search_query); } if (isset($usr_accs[1])) { if ($usr_accs[1] != 1) { $this->db->where('customer_file.customer_care', $user_id); } } else { $this->db->where('customer_file.customer_care', $user_id); } $this->db->limit($num, $offset); return $this->db->get()->result(); }
function search_lead_pages($num, $offset) { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $search_query = $this->input->get('search_query'); $lead_id = $this->input->get('lead_id'); $this->db->select('lead.status,lead.id,project.name as project,contact.name as customer,customer_rating.name as customer_rating'); $this->db->from('lead'); $this->db->join('contact', 'lead.contact_id=contact.id'); $this->db->join('project', 'project.id=lead.interested_project', 'left'); $this->db->join('customer_rating', 'customer_rating.id=lead.rating', 'left'); if (!empty($search_query)) { $this->db->like('contact.name', $search_query); $this->db->or_like('project.name', $search_query); } if (!empty($lead_id)) { $this->db->where('lead.id', $lead_id); } if (isset($usr_accs[1])) { if ($usr_accs[1] != 1) { $this->db->where('lead.customer_care', $user_id); } } else { $this->db->where('lead.customer_care', $user_id); } $this->db->limit($num, $offset); return $this->db->get()->result(); }
function date_based() { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $this->load->model(array('payment_schedule_detail_model', 'project_model')); $this->load->helper('form'); $this->load->library('form_validation'); $project = $this->input->post('project'); $date_from = $this->input->post('date_from'); $date_to = $this->input->post('date_to'); $this->form_validation->set_rules('project', 'project', 'required'); $this->form_validation->set_rules('date_from', 'From Date', 'required'); $this->form_validation->set_rules('date_to', 'To Date', 'required'); if ($this->form_validation->run() == FALSE) { $data['projects'] = $this->project_model->list_project(); $data['installments'] = array(); $this->load->view('due_management/date_based_due_management', $data); } else { if ($_POST['search']) { $data['projects'] = $this->project_model->list_project(); $data['selected_poject'] = $project; $data['selected_date_from'] = $date_from; $data['selected_date_to'] = $date_to; $data['installments'] = $this->payment_schedule_detail_model->search_date_based_schedules($project, $date_from, $date_to); $this->load->view('due_management/date_based_due_management', $data); } } }
function index() { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $this->load->library('pagination'); $this->load->model(array('customer_file_model')); $this->load->helper('form'); $search_query = $this->input->get('search_query'); $status = $this->input->get('status'); $customer_file_id = $this->input->get('customer_file_id'); $config['base_url'] = site_url('customer_file/index?search_query=' . $search_query . '&status=' . $status); $query = "SELECT COUNT(`customer_file`.`id`) as counts "; $query .= "FROM (`customer_file`) JOIN `project` ON `customer_file`.`project_id`=`project`.`id`"; $query .= "JOIN `availability_chart_unit` ON `customer_file`.`unit_id`=`availability_chart_unit`.`id` "; $query .= "JOIN `contact` ON `customer_file`.`customer_id`=`contact`.`id` "; $query .= " WHERE 1=1 "; if (!empty($search_query)) { $query .= "AND (`contact`.`name` LIKE '%" . $search_query . "%' "; $query .= "OR `project`.`name` LIKE '%" . $search_query . "%' "; $query .= "OR `availability_chart_unit`.`unit_name` LIKE '%" . $search_query . "%' "; $query .= "OR CONCAT(project.name,'-',availability_chart_unit.unit_name) LIKE '%" . $search_query . "%' ) "; } if (!empty($status)) { $query .= " AND `customer_file`.`approval_status` = '" . $status . "'"; } if (!empty($customer_file_id)) { $query .= " AND `customer_file`.`id` = '" . $customer_file_id . "'"; } if (isset($usr_accs[1])) { if ($usr_accs[1] != 1) { $query .= " AND `customer_file`.`customer_care` = '" . $user_id . "'"; } } else { $query .= " AND `customer_file`.`customer_care` = '" . $user_id . "'"; } $config['total_rows'] = $this->db->query($query)->first_row()->counts; $config['page_query_string'] = TRUE; $config['uri_segment'] = 3; $config['per_page'] = 5; $config['full_tag_open'] = '<ul class="pagination pull-right">'; $config['full_tag_close'] = '</ul>'; $this->pagination->initialize($config); if (!empty($search_query) || !empty($customer_file_id) || !empty($status)) { $data['customer_files'] = $this->customer_file_model->search_customer_file_pages($config['per_page'], $this->input->get("per_page")); } else { $data['customer_files'] = $this->customer_file_model->list_customer_file_pages($config['per_page'], $this->input->get("per_page")); } $data['status'] = $status; $data['search_query'] = $search_query; $this->load->view('customer_file/list_customer_files', $data); }
function index() { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $this->load->library('pagination'); $this->load->model(array('interaction_model')); $this->load->helper('form'); $status = $this->input->get('status'); $date_from = $this->input->get('date_from'); if (!empty($date_from)) { $date_from = date('Y-m-d', strtotime($date_from)); } $date_to = $this->input->get('date_to'); if (!empty($date_to)) { $date_to = date('Y-m-d', strtotime($date_to)); } $config['base_url'] = site_url('customer_interactions/index?status=' . $status . '&date_from=' . $date_from . '&date_from=' . $date_from); $this->db->from('interaction'); if (!empty($status)) { $this->db->where('interaction.status', $status); } if (!empty($date_from) && !empty($date_to)) { $this->db->where('interaction.date >=', $date_from); $this->db->where('interaction.date <=', $date_to); } if (isset($usr_accs[1])) { if ($usr_accs[1] != 1) { $this->db->where('interaction.assigned_to', $user_id); } } else { $this->db->where('interaction.assigned_to', $user_id); } $config['total_rows'] = $this->db->count_all_results(); // total number of interactions $config['page_query_string'] = TRUE; $config['uri_segment'] = 3; $config['per_page'] = 5; $config['full_tag_open'] = '<ul class="pagination pull-right">'; $config['full_tag_close'] = '</ul>'; $this->pagination->initialize($config); ###### Separate methods for search and general listing ###### if (!empty($status) || !empty($date_from) || !empty($date_to)) { $data['interactions'] = $this->interaction_model->search_customer_interaction_pages($config['per_page'], $this->input->get("per_page")); } else { $data['interactions'] = $this->interaction_model->list_open_customer_interaction(); } $this->load->view('customer_interactions/list_interactions', $data); }
function index() { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $this->load->library('pagination'); $this->load->model(array('customer_file_model')); $this->load->helper('form'); $search_query = $this->input->get('search_query'); $config['base_url'] = site_url('customer_file/index?search_query=' . $search_query); $this->db->from('customer_file'); $this->db->join('contact', 'customer_file.customer_id=contact.id'); $this->db->join('project', 'customer_file.project_id=project.id'); $this->db->join('availability_chart_unit', 'customer_file.unit_id=availability_chart_unit.id'); if (!empty($search_query)) { $this->db->like('contact.name', $search_query); $this->db->or_like('project.name', $search_query); $this->db->or_like('availability_chart_unit.unit_name', $search_query); $this->db->or_like('CONCAT(project.name,\'-\',availability_chart_unit.unit_name)', $search_query); } if (isset($usr_accs[1])) { if ($usr_accs[1] != 1) { $this->db->where('customer_file.customer_care', $user_id); } } else { $this->db->where('customer_file.customer_care', $user_id); } $config['total_rows'] = $this->db->count_all_results(); $config['page_query_string'] = TRUE; $config['uri_segment'] = 3; $config['per_page'] = 5; $config['full_tag_open'] = '<ul class="pagination pull-right">'; $config['full_tag_close'] = '</ul>'; $this->pagination->initialize($config); if (!empty($search_query)) { $data['customer_files'] = $this->customer_file_model->search_customer_file_pages($config['per_page'], $this->input->get("per_page")); } else { $data['customer_files'] = $this->customer_file_model->list_customer_file_pages($config['per_page'], $this->input->get("per_page")); } $this->load->view('customer_file/list_customer_files', $data); }
function index() { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $this->load->library('pagination'); $this->load->model(array('lead_model')); $this->load->helper('form'); $search_query = $this->input->get('search_query'); $lead_id = $this->input->get('lead_id'); $config['base_url'] = site_url('sales/lead_management/index?search_query=' . $search_query); $this->db->from('lead'); $this->db->join('contact', 'lead.contact_id=contact.id'); if (!empty($search_query)) { $this->db->like('contact.name', $search_query); } if (!empty($lead_id)) { $this->db->where('lead.id', $lead_id); } if (isset($usr_accs[1])) { if ($usr_accs[1] != 1) { $this->db->where('lead.lead_owner', $user_id); } } else { $this->db->where('lead.lead_owner', $user_id); } $config['total_rows'] = $this->db->count_all_results(); $config['page_query_string'] = TRUE; $config['uri_segment'] = 3; $config['per_page'] = 5; $config['full_tag_open'] = '<ul class="pagination pull-right">'; $config['full_tag_close'] = '</ul>'; $this->pagination->initialize($config); if (!empty($search_query) || !empty($lead_id)) { $data['leads'] = $this->lead_model->search_lead_pages($config['per_page'], $this->input->get("per_page")); } else { $data['leads'] = $this->lead_model->list_lead_pages($config['per_page'], $this->input->get("per_page")); } $this->load->view('sales/lead_management/list_leads', $data); }
<?php $usr_accs = get_user_access(); ?> <div class="left side-menu"> <div class="sidebar-inner slimscrollleft"> <!-- Search form --> <form role="search" class="navbar-form"> <div class="form-group"> <input type="text" placeholder="Search" class="form-control"> <button type="submit" class="btn search-button"><i class="fa fa-search"></i></button> </div> </form> <div class="clearfix"></div> <!--- Profile --> <div class="profile-info"> <?php if (!$this->session->userdata('USER_PIC')) { ?> <div class="col-xs-4"> <a href="<?php echo site_url('profile'); ?> " class="rounded-image profile-image"> <img src="<?php echo base_url(); ?> profile_picture/<?php echo $this->session->userdata('USER_PIC'); ?> ">
function BodyScope(&$lexer) { global $KEY_TO_TABLE_TYPE; $dummy = NULL; $this->descendants = array(); parent::Scope($lexer, $dummy); if (strlen($lexer->post) > 0) { // parent::Scope swallows all tags, leaving only (possibly) some trailing text $this->addChild(new PlainText($lexer, $this)); } $this->global_vars = array(); foreach ($KEY_TO_TABLE_TYPE as $key => $table_type) { // e.g. 'res_id' => RESOURCE if (array_key_exists($key, $_REQUEST)) { $this->global_vars["{$table_type}-ID"] = $_REQUEST[$key]; } } $this->global_vars['this-url'] = preg_replace('/&chop&.*/', '', $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']); $this->global_vars['ref-url'] = preg_replace('/&chop&.*/', '', @$_SERVER['HTTP_REFERER']); if (get_user_id()) { $this->global_vars["logged-in-user-id"] = get_user_id(); $this->global_vars["logged-in-user-name"] = get_user_name(); $this->global_vars["logged-in-user-username"] = get_user_username(); $access = get_user_access(); if ($access) { $this->global_vars["logged-in-user-access"] = get_user_access(); //$this->global_vars["logged-in-is-administrator"] = is_administrator(); //$this->global_vars["logged-in-is-editor"] = is_editor(); $levels = get_access_levels(); foreach ($levels as $accesslevel => $enabled) { $this->global_vars["logged-in-is-" . $accesslevel] = $enabled; } } } }
function search_customer_interaction_pages($num, $offset) { $usr_accs = get_user_access(); $user_id = $this->session->userdata('USER_ID'); $status = $this->input->get('status'); $date_from = $this->input->get('date_from'); if (!empty($date_from)) { $date_from = date('Y-m-d', strtotime($date_from)); } $date_to = $this->input->get('date_to'); if (!empty($date_to)) { $date_to = date('Y-m-d', strtotime($date_to)); } $this->db->select('contact.name,interaction_subject.name as subject,interaction_action.name as action,' . 'interaction.id,interaction.customer_file_id,user.full_name as interaction_owner,' . 'interaction.date,interaction.time,interaction.pre_details,interaction.status,interaction.priority,' . 'interaction.result,interaction.post_details,interaction.type'); $this->db->from('interaction'); $this->db->join('contact', 'interaction.contact_id=contact.id'); $this->db->join('user', 'user.id=interaction.assigned_to'); $this->db->join('interaction_subject', 'interaction_subject.id=interaction.subject', 'left'); $this->db->join('interaction_action', 'interaction_action.id=interaction.action', 'left'); if (!empty($status)) { $this->db->where('interaction.status', $status); } if (!empty($date_from) && !empty($date_to)) { $this->db->where('interaction.date >=', $date_from); $this->db->where('interaction.date <=', $date_to); } if (isset($usr_accs[1])) { if ($usr_accs[1] != 1) { $this->db->where('interaction.assigned_to', $user_id); } } else { $this->db->where('interaction.assigned_to', $user_id); } $this->db->where('interaction.customer_file_id !=', 0); $this->db->limit($num, $offset); return $this->db->get()->result(); }
function create_customer_file($customer_id) { $this->db->trans_begin(); ####################### customer file - start ####################### $project = $this->input->post('project'); $purchase_cost = $this->input->post('purchase_cost'); $booking_date = $this->input->get('booking_date'); $unit_id = $this->input->post('unit'); $finance_mode = $this->input->post('finance_mode'); if ($finance_mode == 2) { $bank = NULL; $branch = $branch_code_bank = $loan_acc_no = $loan_amount = $loan_percentage = $loan_status = $loan_balance = 0; } else { $bank = $this->input->post('bank'); if (empty($bank)) { $bank = NULL; } $branch = $this->input->post('branch'); $branch_code_bank = $this->input->post('branch_code_bank'); $loan_acc_no = $this->input->post('loan_acc_no'); $loan_amount = $this->input->post('loan_amount'); $loan_percentage = $this->input->post('loan_percentage'); $loan_status = $this->input->post('loan_status'); $loan_balance = $this->input->post('loan_balance'); } $booking_date = date('Y-m-d', strtotime($this->input->post('booking_date'))); $booking_date_actual = date('Y-m-d', strtotime($this->input->post('booking_date_actual'))); $agreement_date = date('Y-m-d', strtotime($this->input->post('agreement_date'))); $starting_date = date('Y-m-d', strtotime($this->input->post('starting_date'))); $crm_settings = $this->db->get('crm_settings')->first_row(); $max_no_approvals = $crm_settings->max_no_approvals; $usr_accs = get_user_access(); $max_no_approvals_user = $usr_accs['4']; if ($max_no_approvals == $max_no_approvals_user) { $approval_status = 1; } else { $approval_status = 0; } $data = array('customer_id' => $customer_id, 'project_id' => $project, 'unit_id' => $unit_id, 'type' => $this->input->post('type'), 'file_number' => $this->input->post('file_number'), 'booking_date' => $booking_date, 'booking_date_actual' => $booking_date_actual, 'area' => $this->input->post('area'), 'rate' => $this->input->post('rate'), 'purchase_cost' => $purchase_cost, 'agreement_date' => $agreement_date, 'agreement_status' => $this->input->post('agreement_status'), 'finance_mode' => $finance_mode, 'bank' => $bank, 'branch' => $branch, 'branch_code_bank' => $branch_code_bank, 'loan_acc_no' => $loan_acc_no, 'loan_amount' => $loan_amount, 'loan_percentage' => $loan_percentage, 'loan_status' => $loan_status, 'loan_balance' => $loan_balance, 'starting_date' => $starting_date, 'payment_schedule_type' => $this->input->post('payment_schedule_type'), 'tenure' => $this->input->post('tenure'), 'billing_day' => $this->input->post('billing_day'), 'payment_interval' => $this->input->post('payment_interval'), 'grace_period' => $this->input->post('grace_period'), 'sales_region' => $this->input->post('sales_region'), 'sales_person' => $this->input->post('sales_person'), 'customer_care' => $this->input->post('customer_care'), 'account' => $this->input->post('account'), 'amount_booking' => $this->input->post('amount_booking'), 'amount_possession' => $this->input->post('amount_possession'), 'dpc_interest' => $this->input->post('dpc_interest'), 'approval_status' => $approval_status, 'created_by' => $this->session->userdata('USER_ID')); $this->db->insert('customer_file', $data); $customer_file_id = $this->db->insert_id(); ####################### customer file - end ####################### # # # ####################### change status of unit -start ####################### $this->db->where(array('id' => $unit_id, 'project_id' => $project))->update('availability_chart_unit', array('status' => '1')); ####################### change status of unit -end ####################### # # # ####################### tax applicable to customer - start ####################### $tax = $this->input->post('tax'); if (!empty($tax)) { $data_tax = array(); foreach ($tax as $tx) { $data_tax[] = array('customer_file_id' => $customer_file_id, 'tax_id' => $tx); } $this->db->insert_batch('customer_file_tax', $data_tax); } ####################### tax applicable to customer - end ####################### # # # ####################### cost heads of customer - start ####################### $cost = $this->input->post('cost'); $data_cost = array(); foreach ($cost as $c => $ct) { $data_cost[] = array('customer_file_id' => $customer_file_id, 'cost_head_id' => $c, 'cost' => $ct); } $this->db->insert_batch('customer_file_unit_costing', $data_cost); ####################### cost heads of customer - end ####################### # # # ####################### tpayment schedule - start ####################### $payment_schedule_type = $this->input->post('payment_schedule_type'); $installment_name = $this->input->post('installment_name'); if (!empty($installment_name)) { if ($payment_schedule_type == 1) { $data = array(); foreach ($installment_name as $index => $value) { $due_percentage = $this->input->post('due_percentage'); $due_percentage = $due_percentage[$index]; $installment_type = $this->input->post('installment_type'); $installment_type = $installment_type[$index]; $payment_type = $this->input->post('payment_type'); $payment_type = $payment_type[$index]; $due_date = $this->input->post('due_date'); $due_date = $due_date[$index]; $actual_due_date = $this->input->post('actual_due_date'); $actual_due_date = $actual_due_date[$index]; $dpc_grace_period = $this->input->post('dpc_grace_period'); $dpc_grace_period = $actual_due_date[$index]; $dpc_interest = $this->input->post('dpc_interest'); $dpc_interest = $actual_due_date[$index]; $due_amount = $this->input->post('due_amount'); $due_amount = $due_amount[$index]; $display_order = $this->input->post('display_order'); $display_order = $display_order[$index]; $status = $this->input->post('status'); $status = $status[$index]; if ($due_percentage) { $due_percentage = $due_percentage; } else { $due_percentage = 0; } $data[] = array('project_id' => $project, 'payment_schedule_id' => $this->input->post('payment_schedule_format'), 'installment_type' => $installment_type, 'installment_id' => $index, 'installment_name' => $value, 'payment_type' => $payment_type, 'actual_due_date' => date('Y-m-d', strtotime($actual_due_date)), 'due_date' => date('Y-m-d', strtotime($due_date)), 'due_amount' => $due_amount, 'due_percentage' => $due_percentage, 'customer_file_id' => $customer_file_id, 'amount_paid' => 0, 'dpc_interest' => $dpc_interest, 'dpc_grace_period' => $dpc_grace_period, 'display_order' => $display_order, 'status' => $status); } $this->db->insert_batch('payment_schedule_customer', $data); } else { $data = array(); foreach ($installment_name as $index => $value) { $due_percentage = $this->input->post('due_percentage'); $due_percentage = $due_percentage[$index]; $installment_type = $this->input->post('installment_type'); $installment_type = $installment_type[$index]; $payment_type = $this->input->post('payment_type'); $payment_type = $payment_type[$index]; $due_date = $this->input->post('due_date'); $due_date = $due_date[$index]; $actual_due_date = $this->input->post('actual_due_date'); $actual_due_date = $actual_due_date[$index]; $dpc_grace_period = $this->input->post('dpc_grace_period'); $dpc_grace_period = $actual_due_date[$index]; $dpc_interest = $this->input->post('dpc_interest'); $dpc_interest = $actual_due_date[$index]; $due_amount = $this->input->post('due_amount'); $due_amount = $due_amount[$index]; $display_order = $this->input->post('display_order'); $display_order = $display_order[$index]; $status = $this->input->post('status'); $status = $status[$index]; if ($due_percentage) { $due_percentage = $due_percentage; } else { $due_percentage = 0; } $data[] = array('project_id' => $project, 'payment_schedule_id' => NULL, 'installment_type' => $installment_type, 'installment_id' => NULL, 'installment_name' => $value, 'payment_type' => $payment_type, 'actual_due_date' => date('Y-m-d', strtotime($actual_due_date)), 'due_date' => date('Y-m-d', strtotime($due_date)), 'due_amount' => $due_amount, 'due_percentage' => $due_percentage, 'customer_file_id' => $customer_file_id, 'amount_paid' => 0, 'dpc_interest' => $dpc_interest, 'dpc_grace_period' => $dpc_grace_period, 'display_order' => $display_order, 'status' => $status); } $this->db->insert_batch('payment_schedule_customer', $data); } } else { if ($payment_schedule_type == 1) { //progress based $payment_schedule_format = $this->input->post('payment_schedule_format'); $this->db->select('payment_schedule.name as payment_schedule,payment_schedule_detail.*'); $this->db->from('payment_schedule_detail'); $this->db->join('payment_schedule', 'payment_schedule.id=payment_schedule_detail.payment_schedule_id'); $this->db->where('payment_schedule_detail.payment_schedule_id', $payment_schedule_format); $this->db->order_by('payment_schedule_detail.payment_type', 'desc'); $this->db->order_by('payment_schedule_detail.display_order', 'asc'); $payment_schedule = $this->db->get()->result(); $data = array(); foreach ($payment_schedule as $ps) { $due_percentage_in = round($ps->due_percentage); if (empty($due_percentage_in) && !empty($ps->due_amount)) { $installment_amout = $ps->due_amount; $due_percentage = $installment_amout / ($purchase_cost - $tinc) * 100; } elseif (!empty($ps->due_percentage)) { if (!empty($ps->payment_schedule_relation_id)) { $relation = $this->db->where('id', $ps->payment_schedule_relation_id)->get('payment_schedule_relation')->first_row(); $due_amount = $this->db->select('SUM(`due_amount`) as due_amount')->where(array('payment_schedule_relation_id' => $ps->payment_schedule_relation_id, 'payment_schedule_id' => $ps->payment_schedule_id))->get('payment_schedule_detail')->first_row(); $installment_amout = $purchase_cost / 100 * $relation->due_percentage; $due_percentage = ($installment_amout - $due_amount->due_amount) / $purchase_cost * 100; $installment_amout = $purchase_cost / 100 * $due_percentage; } else { $installment_amout = $purchase_cost / 100 * $ps->due_percentage; $due_percentage = $ps->due_percentage; } } else { $installment_amout = $purchase_cost / 100 * $ps->due_percentage; } $due_date = $ps->due_date; if (strtotime($booking_date) > strtotime($due_date)) { $due_date = $booking_date; } $data[] = array('project_id' => $project, 'payment_schedule_id' => $ps->payment_schedule_id, 'installment_type' => $ps->installment_type, 'installment_id' => $ps->id, 'installment_name' => $ps->name, 'payment_type' => $ps->payment_type, 'actual_due_date' => $ps->due_date, 'due_date' => $due_date, 'due_amount' => $installment_amout, 'due_percentage' => $due_percentage, 'customer_file_id' => $customer_file_id, 'display_order' => $ps->display_order, 'amount_paid' => 0, 'dpc_interest' => $ps->dpc_interest, 'dpc_grace_period' => $ps->dpc_grace_period, 'status' => $ps->status); } $this->db->insert_batch('payment_schedule_customer', $data); } else { //date based $frequency = $this->input->post('frequency'); if ($frequency == 1) { $payment_interval = 1; } else { $payment_interval = $this->input->post('frequency'); } $tenure = $this->input->post('tenure'); $billing_day = $this->input->post('billing_day'); $starting_date = $this->input->post('starting_date'); $grace_period = $this->input->post('grace_period'); $dpc_interest = $this->input->post('dpc_interest'); $starting_date = date('Y-m-d', strtotime($starting_date)); $amount_booking = $this->input->post('amount_booking'); $amount_possession = $this->input->post('amount_possession'); $percentahe_booking = $amount_booking / $purchase_cost * 100; $percentahe_possession = $amount_possession / $purchase_cost * 100; $installment_amout = ($purchase_cost - ($amount_booking + $amount_possession)) / $tenure; $due_percentage = $installment_amout / $purchase_cost * 100; $grace_period = $this->input->post('grace_period'); $dpc_interest = $this->input->post('dpc_interest'); $data = array(); $data[] = array('project_id' => $project, 'payment_schedule_id' => NULL, 'installment_id' => NULL, 'installment_type' => 1, 'installment_name' => 'On Booking', 'payment_type' => 13, 'due_date' => $starting_date, 'due_amount' => $amount_booking, 'due_percentage' => $percentahe_booking, 'customer_file_id' => $customer_file_id, 'amount_paid' => 0, 'dpc_interest' => $dpc_interest, 'dpc_grace_period' => $grace_period, 'display_order' => 1, 'status' => 1); for ($i = 1; $i <= $tenure; $i++) { $time = strtotime($starting_date); $starting_date = date("Y-m-d", strtotime("+1 month", $time)); $data[] = array('project_id' => $project, 'payment_schedule_id' => NULL, 'installment_id' => NULL, 'installment_type' => 1, 'installment_name' => 'On ' . date('M', strtotime($starting_date)) . ' ' . $billing_day, 'payment_type' => 13, 'due_date' => $starting_date, 'due_amount' => $installment_amout, 'due_percentage' => $due_percentage, 'customer_file_id' => $customer_file_id, 'amount_paid' => 0, 'display_order' => $i + 1, 'status' => 1); } $time = strtotime($starting_date); $starting_date = date("Y-m-d", strtotime("+1 month", $time)); $data[] = array('project_id' => $project, 'payment_schedule_id' => NULL, 'installment_id' => NULL, 'installment_type' => 1, 'installment_name' => 'On Possession', 'payment_type' => 13, 'due_date' => $starting_date, 'due_amount' => $amount_possession, 'due_percentage' => $percentahe_possession, 'customer_file_id' => $customer_file_id, 'amount_paid' => 0, 'display_order' => $i + 1, 'status' => 1); $this->db->insert_batch('payment_schedule_customer', $data); } } ####################### tpayment schedule - start ####################### $this->reprocess_payment_schedule($customer_file_id); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); return FALSE; } else { $this->db->trans_commit(); return $customer_file_id; } }