Adding Date field in Invoice Items

I’m trying to add a date field before quantity field in the invoice item. But when I try to save the date gets saved as

I made changes to this invoices/view/partial_invoice_table.php http://pastie.org/10918548

and invoices/models/mdl_items.php http://pastie.org/10918550

I wonder if the values are really getting passed. Hope someone can point me in the right direction.

Thanks to your initial posting, I was able to get the dates to save to the DB and not allow the Unix Epoch Date (1/1/1970 GMT, or as I now see it in the USA, 12/31/1969 -8:00 GMT) be saved into the DB and then later displayed, instead of leaving the field empty.

I followed your steps, because I also wanted a date-per-item. My field/column is item_service_date.

I am new to PHP, so do not know if this is the best way to solve this issue, but here are my steps after your steps above.

I added the column to the ip_invoice_items table:

ALTER TABLE invoice.ip_invoice_items
ADD COLUMN item_service_date DATE NULL AFTER item_product_id;

I just started using IP at v1.4.10. (Your code samples have differences, like lang whereas v1.4.10 uses trans)

Then I followed the class-path starting in mdl_items.php
class Mdl_Items extends Response_Model

Which led to application/core/ Response_Model.php
class Response_Model extends Form_Validation_Model

Which led to application/core/ Form_Validation_Model.php
class Form_Validation_Model extends MY_Model

Ending up in application/core/ MY_Model.php where I made the following 3 additions:

  1. At the top of the file
    public $date_created_field;
    public $date_modified_field;
    public $service_date_field;

Inside the save() function, there are two place to add code. Firstly, for inserting and secondly for updating.

2)


if ($this->service_date_field) {
$service_date = NULL;
if (is_array($db_array)) {
if($db_array[$this->service_date_field]) {
$service_date = date(‘Y-m-d’, strtotime($db_array[$this->service_date_field]));
}
$db_array[$this->service_date_field] = $service_date;
} else {
if ($db_array->{$this->service_date_field}) {
$service_date = date(‘Y-m-d’, strtotime($db_array->{$this->service_date_field}));
}
$db_array->{$this->service_date_field} = $service_date;
}
}
$this->db->insert($this->table, $db_array);

3)


if ($this->service_date_field) {
$service_date = NULL;
if (is_array($db_array)) {
if($db_array[$this->service_date_field]) {
$service_date = date(‘Y-m-d’, strtotime($db_array[$this->service_date_field]));
}
$db_array[$this->service_date_field] = $service_date;
} else {
if ($db_array->{$this->service_date_field}) {
$service_date = date(‘Y-m-d’, strtotime($db_array->{$this->service_date_field}));
}
$db_array->{$this->service_date_field} = $service_date;
}
}
$this->db->where($this->primary_key, $id);
$this->db->update($this->table, $db_array);

Oops! There was a fourth addition:

At the top of application/modules/invoices/models/ mdl_items.php

public $primary_key = ‘ip_invoice_items.item_id’;
public $date_created_field = ‘item_date_added’;
public $service_date_field = ‘item_service_date’;

I have just installed version 1.4.10 and tried the above and ended up with blank screens. Bit confusing between the 2 post so maybe I did something wrong. Is there any help for this where all the steps are based on the current version? Or if someone can help me get it going I would be happy to write something up from the view of a first time user. Also on the approach suggested would this be overwritten when updating to a new version?
Thanks.