Create not working for new developed expenses module


#1

First,
i would like to thank the developers for the work and time they have put into InvoicePlane to make it an incredible product!
Second, I already have Invoice Plane 1.5 installed. As known, the older version of Invoice Plane doesn’t have an “Expenses Module”.
I added the "Expenses " module;however, I’m stuck.
The “Create” functionality is not working. More Precisely, when i try to save, the expenses is not being created.
Note that I am aware that the date needs to be changed to sql format.
To cover this scenario, I added “Allow Null” for the fields in the Expenses table in mysql.
So, back to issue, any any to why the expense is not being saved in the table?
here is my code.
Any help is very appreciated!

Model: mdl_expenses.php

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

/*
 * InvoicePlane
 *
 * @author		InvoicePlane Developers & Contributors
 * @copyright	Copyright (c) 2012 - 2018 InvoicePlane.com
 * @license		https://invoiceplane.com/license.txt
 * @link		https://invoiceplane.com
 */

/**
 * Class Mdl_expenses
 */
class Mdl_Expenses extends Response_Model
{
    public $table = 'ip_expenses';
    public $primary_key = 'ip_expenses.expense_id';
    public $validation_rules = 'validation_rules';

    public function default_select()
    {
        $this->db->select("
            SQL_CALC_FOUND_ROWS
            ip_expenses.expense_id,
            ip_expenses.expense_title,
            ip_expenses.expense_description,
            ip_expenses.expense_date,
            ip_expenses.expense_amount
            ", false);
    }

    public function default_order_by()
    {
        $this->db->order_by('ip_expenses.expense_date DESC');
    }

    public function validation_rules()
    {
         return array(
        'expense_title' => array(
                'field' => 'expense_title',
                'label' => trans('expense_title')
            ),
            'expense_description' => array(
                'field' => 'expense_description',
                'label' => trans('expense_description')
            ),
            'expense_date' => array(
                'field' => 'expense_date',
                'label' => trans('expense_date')
            ),
            'expense_amount' => array(
                'field' => 'expense_amount',
                'label' => trans('expense_amount')
            )
     );
    }

}

Controller: Expenses.php

<?php
 if (!defined('BASEPATH'))
    exit('No direct script access allowed');
 /*
 * InvoicePlane
 * 
 * A free and open source web based invoicing system
 *
 * @package		InvoicePlane
 * @author		Kovah (www.kovah.de)
 * @copyright	Copyright (c) 2012 - 2015 InvoicePlane.com
 * @license		https://invoiceplane.com/license.txt
 * @link		https://invoiceplane.com
 * 
 */
 class Expenses extends Admin_Controller
{
    
        public function __construct()
    {
        parent::__construct();
         $this->load->model('mdl_expenses');
    }
    
   
     public function index($page = 0)
    {
       
       $this->mdl_expenses->paginate(site_url('expenses/index'), $page);
        $expenses = $this->mdl_expenses->result();

        $this->layout->set(
            array(
                'expenses' => $expenses,
                'filter_display' => true,
                'filter_placeholder' => trans('filter_expenses'),
                'filter_method' => 'filter_expenses'
            )
        );

        $this->layout->buffer('content', 'expenses/index');
        $this->layout->render();
    }
    
    
    
    public function form($id = null)
    {
       
      if ($this->input->post('btn_cancel')) {
            redirect('expenses');
        }
        
         if ($this->mdl_expenses->run_validation()) {
           $this->mdl_expenses->save($id);

            redirect('expenses');
        }
        
        

        $this->layout->buffer('content', 'expenses/form');
        $this->layout->render();
    }
 }

View : form.php

<div id="content" class="table-content">
    </div>
<form method="post" class="form-horizontal">

    <input type="hidden" name="<?php echo $this->config->item('csrf_token_name'); ?>"
           value="<?php echo $this->security->get_csrf_hash() ?>">


    <div id="headerbar">
        <h1 class="headerbar-title"><?php _trans('Expense Form') ?></h1>
        <?php $this->layout->load_view('layout/header_buttons'); ?>
    </div>

    <div id="content">

        <?php $this->layout->load_view('layout/alerts'); ?>
		
		  <div class="form-group">
            <div class="col-xs-12 col-sm-2 text-right text-left-xs">
                <label for="expense_title" class="control-label"><?php _trans('Title'); ?></label>
            </div>
            <div class="col-xs-12 col-sm-6">
                <input type="text" name="expense_title" id="expense_title" class="form-control"
                       value="<?php echo $this->mdl_expenses->form_value('expense_title'); ?>">
            </div>
        </div>
            <div class="form-group">
            <div class="col-xs-12 col-sm-2 text-right text-left-xs">
                <label for="expense_date" class="control-label"><?php _trans('Date'); ?></label>
            </div>
            <div class="col-xs-12 col-sm-6">
                <input type="text" name="expense_date" id="expense_date" class="form-control datepicker"
                       value="<?php echo $this->mdl_expenses->form_value('expense_date'); ?>">
            </div>
        </div>
	
        <div class="form-group">
            <div class="col-xs-12 col-sm-2 text-right text-left-xs">
                <label for="expense_amount" class="control-label"><?php _trans('Amount'); ?></label>
            </div>
            <div class="col-xs-12 col-sm-6">
                <input type="text" name="expense_amount" id="expense_amount" class="form-control"
                       value="<?php echo format_amount($this->mdl_expenses->form_value('expense_amount')); ?>">
            </div>
        </div>

        <div class="form-group">
            <div class="col-xs-12 col-sm-2 text-right text-left-xs">
                <label for="expense_description" class="control-label"><?php _trans('Description'); ?></label>
            </div>
            <div class="col-xs-12 col-sm-6">
                <textarea name="expense_description" id="expense_description"
                          class="form-control"><?php echo $this->mdl_expenses->form_value('expense_description', true); ?></textarea>
            </div>

        </div>

           </div>

</form>

#2

Hi Alice,
I edited your post to make it more clear and formatted the code.

Please add details about what is happening. Error messages, server logs, browser logs, and so on. Can’t help you otherwise.


#3

Hi Kovah,
Your help is deeply appreciated.
I edited the first post and made the issue clearer that the expense is not being saved.
There are no logs.
Does there seem to be any issue with the code though?


#4

Hi Kovah,
Any updates on the above??


#5

Have no time to test your code. Try to debug your code with Xdebug (search on Google) or manually like

public function form($id = null)
{
    if ($this->input->post('btn_cancel')) {
        redirect('expenses');
    }

    var_dump($this->mdl_expenses->run_validation()); exit;
    ...