mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-19 05:48:02 -04:00
Merge pull request #2319 from opensourcepos/fix-attribute-datetime
Fix attribute datetime formatting
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
define('GROUP', 'GROUP');
|
||||
define('DROPDOWN', 'DROPDOWN');
|
||||
define('DECIMAL', 'DECIMAL');
|
||||
define('DATETIME', 'DATETIME');
|
||||
define('DATE', 'DATE');
|
||||
define('TEXT', 'TEXT');
|
||||
|
||||
const DEFINITION_TYPES = [GROUP, DROPDOWN, DECIMAL, TEXT, DATETIME];
|
||||
const DEFINITION_TYPES = [GROUP, DROPDOWN, DECIMAL, TEXT, DATE];
|
||||
|
||||
/**
|
||||
* Attribute class
|
||||
@@ -105,9 +105,9 @@ class Attribute extends CI_Model
|
||||
*/
|
||||
public function search($search, $rows = 0, $limit_from = 0, $sort = 'definition.definition_name', $order = 'asc')
|
||||
{
|
||||
$this->db->select('definition_group.definition_name AS definition_group, definition.*');
|
||||
$this->db->select('parent_definition.definition_name AS definition_group, definition.*');
|
||||
$this->db->from('attribute_definitions AS definition');
|
||||
$this->db->join('attribute_definitions AS definition_group', 'definition_group.definition_id = definition.definition_fk', 'left');
|
||||
$this->db->join('attribute_definitions AS parent_definition', 'parent_definition.definition_id = definition.definition_fk', 'left');
|
||||
|
||||
$this->db->group_start();
|
||||
$this->db->like('definition.definition_name', $search);
|
||||
@@ -270,11 +270,11 @@ class Attribute extends CI_Model
|
||||
$this->db->where('definition_id',$definition);
|
||||
$success = TRUE;
|
||||
|
||||
if($to === DATETIME)
|
||||
if($to === DATE)
|
||||
{
|
||||
foreach($this->db->get()->result_array() as $row)
|
||||
{
|
||||
if(valid_datetime($row['attribute_value']) === FALSE)
|
||||
if(valid_date($row['attribute_value']) === FALSE)
|
||||
{
|
||||
log_message('ERROR', 'item_id: ' . $row['item_id'] . ' with attribute_value: ' . $row['attribute_value'] . ' cannot be converted to datetime');
|
||||
$success = FALSE;
|
||||
@@ -303,9 +303,9 @@ class Attribute extends CI_Model
|
||||
//From TEXT to DATETIME
|
||||
if($from_type === TEXT)
|
||||
{
|
||||
if($to_type === DATETIME || $to_type === DECIMAL)
|
||||
if($to_type === DATE || $to_type === DECIMAL)
|
||||
{
|
||||
$field = ($to_type === DATETIME ? 'attribute_datetime' : 'attribute_decimal');
|
||||
$field = ($to_type === DATETIME ? 'attribute_date' : 'attribute_decimal');
|
||||
|
||||
if($this->check_data_validity($definition_id, $from_type, $to_type))
|
||||
{
|
||||
@@ -452,7 +452,9 @@ class Attribute extends CI_Model
|
||||
|
||||
public function get_link_values($item_id, $sale_receiving_fk, $id, $definition_flags)
|
||||
{
|
||||
$this->db->select('GROUP_CONCAT(attribute_value SEPARATOR ", ") AS attribute_values, GROUP_CONCAT(attribute_datetime SEPARATOR ", ") AS attribute_datetimevalues');
|
||||
$format = $this->db->escape(dateformat_mysql());
|
||||
$this->db->select("GROUP_CONCAT(attribute_value SEPARATOR ', ') AS attribute_values");
|
||||
$this->db->select("GROUP_CONCAT(DATE_FORMAT(attribute_date, $format) SEPARATOR ', ') AS attribute_dtvalues");
|
||||
$this->db->from('attribute_links');
|
||||
$this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id');
|
||||
$this->db->join('attribute_definitions', 'attribute_definitions.definition_id = attribute_links.definition_id');
|
||||
@@ -471,23 +473,7 @@ class Attribute extends CI_Model
|
||||
$this->db->where('item_id', (int) $item_id);
|
||||
$this->db->where('definition_flags & ', $definition_flags);
|
||||
|
||||
$results = $this->db->get();
|
||||
|
||||
if ($results->num_rows() > 0)
|
||||
{
|
||||
$row_object = $results->row_object();
|
||||
|
||||
$datetime_values = explode(', ', $row_object->attribute_datetimevalues);
|
||||
$attribute_values = array();
|
||||
|
||||
foreach (array_filter($datetime_values) as $datetime_value)
|
||||
{
|
||||
$attribute_values[] = to_datetime(strtotime($datetime_value));
|
||||
}
|
||||
|
||||
return implode(',', $attribute_values) . $row_object->attribute_values;
|
||||
}
|
||||
return "";
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
public function get_attribute_value($item_id, $definition_id)
|
||||
@@ -541,38 +527,29 @@ class Attribute extends CI_Model
|
||||
{
|
||||
if($definition_type == TEXT || $definition_type == DROPDOWN)
|
||||
{
|
||||
$attribute_id_check = $this->value_exists($attribute_value);
|
||||
if(empty($attribute_id_check))
|
||||
$attribute_id = $this->value_exists($attribute_value);
|
||||
|
||||
if(empty($attribute_id))
|
||||
{
|
||||
$this->db->insert('attribute_values', array('attribute_value' => $attribute_value));
|
||||
$attribute_id = $this->db->insert_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
$attribute_id = $attribute_id_check;
|
||||
}
|
||||
}
|
||||
else if($definition_type == DECIMAL)
|
||||
{
|
||||
$this->db->insert('attribute_values', array('attribute_decimal' => $attribute_value));
|
||||
$attribute_id = $this->db->insert_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->insert('attribute_values', array('attribute_datetime' => date('Y-m-d H:i:s', strtotime($attribute_value))));
|
||||
$attribute_id = $this->db->insert_id();
|
||||
$this->db->insert('attribute_values', array('attribute_date' => date('Y-m-d', strtotime($attribute_value))));
|
||||
}
|
||||
|
||||
$attribute_id = $attribute_id ? $attribute_id : $this->db->insert_id();
|
||||
|
||||
$this->db->insert('attribute_links', array(
|
||||
'attribute_id' => empty($attribute_id) ? NULL : $attribute_id,
|
||||
'item_id' => empty($item_id) ? NULL : $item_id,
|
||||
'definition_id' => $definition_id));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->where('attribute_id', $attribute_id);
|
||||
$this->db->update('attribute_values', array('attribute_value' => $attribute_value));
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
|
||||
@@ -192,7 +192,9 @@ class Item extends CI_Model
|
||||
|
||||
if ($attributes_enabled)
|
||||
{
|
||||
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\':\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
|
||||
$format = $this->db->escape(dateformat_mysql());
|
||||
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\'_\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
|
||||
$this->db->select("GROUP_CONCAT(DISTINCT CONCAT_WS('_', definition_id, DATE_FORMAT(attribute_date, $format)) SEPARATOR '|') AS attribute_dtvalues");
|
||||
$this->db->join('attribute_links', 'attribute_links.item_id = items.item_id AND attribute_links.receiving_id IS NULL AND attribute_links.sale_id IS NULL AND definition_id IN (' . implode(',', $filters['definition_ids']) . ')', 'left');
|
||||
$this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id', 'left');
|
||||
}
|
||||
@@ -279,6 +281,7 @@ class Item extends CI_Model
|
||||
{
|
||||
$this->db->select('items.*');
|
||||
$this->db->select('GROUP_CONCAT(attribute_value SEPARATOR \'|\') AS attribute_values');
|
||||
$this->db->select('GROUP_CONCAT(attribute_date SEPARATOR \'|\') AS attribute_dtvalues');
|
||||
$this->db->select('suppliers.company_name');
|
||||
$this->db->from('items');
|
||||
$this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left');
|
||||
@@ -376,8 +379,8 @@ class Item extends CI_Model
|
||||
{
|
||||
$this->db->select('items.*');
|
||||
$this->db->select('company_name');
|
||||
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\':\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
|
||||
$this->db->select('items.category');
|
||||
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\'_\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
|
||||
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\'_\', definition_id, attribute_date) ORDER BY definition_id SEPARATOR \'|\') AS attribute_dtvalues');
|
||||
$this->db->select('quantity');
|
||||
$this->db->from('items');
|
||||
$this->db->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left');
|
||||
|
||||
@@ -102,7 +102,9 @@ class Detailed_receivings extends Report
|
||||
$this->db->join('items', 'receivings_items_temp.item_id = items.item_id');
|
||||
if (count($inputs['definition_ids']) > 0)
|
||||
{
|
||||
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\':\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
|
||||
$format = $this->db->escape(dateformat_mysql());
|
||||
$this->db->select("GROUP_CONCAT(DISTINCT CONCAT_WS('_', definition_id, attribute_value) ORDER BY definition_id SEPARATOR '|') AS attribute_values");
|
||||
$this->db->select("GROUP_CONCAT(DISTINCT CONCAT_WS('_', definition_id, DATE_FORMAT(attribute_date, $format)) SEPARATOR '|') AS attribute_dtvalues");
|
||||
$this->db->join('attribute_links', 'attribute_links.item_id = items.item_id AND attribute_links.receiving_id = receivings_items_temp.receiving_id AND definition_id IN (' . implode(',', $inputs['definition_ids']) . ')', 'left');
|
||||
$this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id', 'left');
|
||||
$this->db->group_by('receivings_items_temp.receiving_id, receivings_items_temp.item_id');
|
||||
|
||||
@@ -148,7 +148,9 @@ class Detailed_sales extends Report
|
||||
$this->db->from('sales_items_temp');
|
||||
if (count($inputs['definition_ids']) > 0)
|
||||
{
|
||||
$this->db->select('GROUP_CONCAT(DISTINCT CONCAT_WS(\':\', definition_id, attribute_value) ORDER BY definition_id SEPARATOR \'|\') AS attribute_values');
|
||||
$format = $this->db->escape(dateformat_mysql());
|
||||
$this->db->select("GROUP_CONCAT(DISTINCT CONCAT_WS('_', definition_id, attribute_value) ORDER BY definition_id SEPARATOR '|') AS attribute_values");
|
||||
$this->db->select("GROUP_CONCAT(DISTINCT CONCAT_WS('_', definition_id, DATE_FORMAT(attribute_date, $format)) SEPARATOR '|') AS attribute_dtvalues");
|
||||
$this->db->join('attribute_links', 'attribute_links.item_id = sales_items_temp.item_id AND attribute_links.sale_id = sales_items_temp.sale_id AND definition_id IN (' . implode(',', $inputs['definition_ids']) . ')', 'left');
|
||||
$this->db->join('attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id', 'left');
|
||||
$this->db->group_by('sales_items_temp.sale_id, sales_items_temp.item_id');
|
||||
|
||||
54
application/models/tokens/Token.php
Normal file
54
application/models/tokens/Token.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once(APPPATH . 'models/tokens/Token.php');
|
||||
require_once(APPPATH . 'models/tokens/Token_customer.php');
|
||||
require_once(APPPATH . 'models/tokens/Token_invoice_count.php');
|
||||
require_once(APPPATH . 'models/tokens/Token_invoice_sequence.php');
|
||||
require_once(APPPATH . 'models/tokens/Token_quote_sequence.php');
|
||||
require_once(APPPATH . 'models/tokens/Token_work_order_sequence.php');
|
||||
require_once(APPPATH . 'models/tokens/Token_suspended_invoice_count.php');
|
||||
require_once(APPPATH . 'models/tokens/Token_year_invoice_count.php');
|
||||
|
||||
/**
|
||||
* Token class
|
||||
*/
|
||||
|
||||
abstract class Token
|
||||
{
|
||||
protected $CI;
|
||||
|
||||
protected $value = '';
|
||||
|
||||
public function __construct($value = '')
|
||||
{
|
||||
$this->CI =& get_instance();
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
static function get_tokens()
|
||||
{
|
||||
return array(new Token_customer(), new Token_invoice_count(), new Token_invoice_sequence(),
|
||||
new Token_quote_sequence(), new Token_suspended_invoice_count(), new Token_quote_sequence(),
|
||||
new Token_work_order_sequence(), new Token_year_invoice_count());
|
||||
}
|
||||
|
||||
abstract public function token_id();
|
||||
|
||||
abstract public function get_value();
|
||||
|
||||
function matches($token_id)
|
||||
{
|
||||
return token_id() == $token_id;
|
||||
}
|
||||
|
||||
function replace($text)
|
||||
{
|
||||
if(strstr($text, $this->token_id()))
|
||||
{
|
||||
return str_replace($this->token_id(), $this->get_value(), $text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
40
application/models/tokens/Token_customer.php
Normal file
40
application/models/tokens/Token_customer.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Token_customer class
|
||||
*/
|
||||
|
||||
class Token_customer extends Token
|
||||
{
|
||||
|
||||
private $customer_info;
|
||||
|
||||
public function __construct($customer_info = '')
|
||||
{
|
||||
parent::__construct();
|
||||
$this->customer_info = $customer_info;
|
||||
$this->CI->load->library('sale_lib');
|
||||
}
|
||||
|
||||
public function token_id()
|
||||
{
|
||||
return 'CU';
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
// substitute customer info
|
||||
$customer_id = $this->CI->sale_lib->get_customer();
|
||||
if($customer_id != -1 && empty($this->customer_info))
|
||||
{
|
||||
$customer_info = $this->CI->Customer->get_info($customer_id);
|
||||
if($customer_info != '')
|
||||
{
|
||||
return trim($customer_info->first_name . ' ' . $customer_info->last_name);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
?>
|
||||
26
application/models/tokens/Token_invoice_count.php
Normal file
26
application/models/tokens/Token_invoice_count.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Token_invoice_count class
|
||||
*/
|
||||
|
||||
class Token_invoice_count extends Token
|
||||
{
|
||||
public function __construct($value = '')
|
||||
{
|
||||
parent::__construct($value);
|
||||
|
||||
$this->CI->load->model('Sale');
|
||||
}
|
||||
|
||||
public function token_id()
|
||||
{
|
||||
return 'CO';
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
return empty($value) ? $this->CI->Sale->get_invoice_count() : $value;
|
||||
}
|
||||
}
|
||||
?>
|
||||
25
application/models/tokens/Token_invoice_sequence.php
Normal file
25
application/models/tokens/Token_invoice_sequence.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Token_invoice_sequence class
|
||||
*/
|
||||
|
||||
class Token_invoice_sequence extends Token
|
||||
{
|
||||
|
||||
public function __construct($value = '')
|
||||
{
|
||||
parent::__construct($value);
|
||||
}
|
||||
|
||||
public function token_id()
|
||||
{
|
||||
return 'ISEQ';
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
return $this->CI->Appconfig->acquire_save_next_invoice_sequence();
|
||||
}
|
||||
}
|
||||
?>
|
||||
19
application/models/tokens/Token_quote_sequence.php
Normal file
19
application/models/tokens/Token_quote_sequence.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Token_quote_sequence class
|
||||
*/
|
||||
|
||||
class Token_quote_sequence extends Token
|
||||
{
|
||||
public function token_id()
|
||||
{
|
||||
return 'QSEQ';
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
return $this->CI->Appconfig->acquire_save_next_quote_sequence();
|
||||
}
|
||||
}
|
||||
?>
|
||||
26
application/models/tokens/Token_suspended_invoice_count.php
Normal file
26
application/models/tokens/Token_suspended_invoice_count.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Token_suspended_invoice_count class
|
||||
*/
|
||||
|
||||
class Token_suspended_invoice_count extends Token
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->CI->load->model('Sale');
|
||||
}
|
||||
|
||||
public function token_id()
|
||||
{
|
||||
return 'SCO';
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
return $this->CI->Sale->get_suspended_invoice_count();
|
||||
}
|
||||
}
|
||||
?>
|
||||
19
application/models/tokens/Token_work_order_sequence.php
Normal file
19
application/models/tokens/Token_work_order_sequence.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Token_work_order_sequence class
|
||||
*/
|
||||
|
||||
class Token_work_order_sequence extends Token
|
||||
{
|
||||
public function token_id()
|
||||
{
|
||||
return 'WSEQ';
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
return $this->CI->Appconfig->acquire_save_next_work_order_sequence();
|
||||
}
|
||||
}
|
||||
?>
|
||||
26
application/models/tokens/Token_year_invoice_count.php
Normal file
26
application/models/tokens/Token_year_invoice_count.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Token_year_invoice_count class
|
||||
*/
|
||||
|
||||
class Token_year_invoice_count extends Token
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->CI->load->model('Sale');
|
||||
}
|
||||
|
||||
public function token_id()
|
||||
{
|
||||
return 'YCO';
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
return $this->CI->Sale->get_invoice_number_for_year();
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user