Skip to content

Fix attribute datetime formatting - #2319

Merged
daN4cat merged 3 commits into
masterfrom
fix-attribute-datetime
Jun 15, 2019
Merged

daN4cat merged 3 commits into
masterfrom
fix-attribute-datetime

Conversation

@jekkos

@jekkos jekkos commented Jan 25, 2019

Copy link
Copy Markdown
Member

Fix for attribute datetime formatting. Did a quick test on items listing and attribute datetime columns are formatted according to what a users specifies as date / time format. Might also need to check sales and receivings and eventually reports.

@jekkos
jekkos force-pushed the fix-attribute-datetime branch from 7624027 to a1b642b Compare January 25, 2019 08:10
@jekkos jekkos changed the title Fix attribute datetime Fix attribute datetime formatting Jan 25, 2019
@odiea

odiea commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

Something is not correct here. Same database is being used.
Before
2019-01-25 06_24_18-window
After
2019-01-25 06_26_16-window

@odiea

odiea commented Jan 25, 2019

Copy link
Copy Markdown
Collaborator

Ignore the right hand edit columns. I moved them to the left.

@jekkos

jekkos commented Jan 27, 2019 •

Copy link
Copy Markdown
Member Author

Ok thanks for testing, will need to check some other scenarios but couldn't wait to put it out here.

@odiea

odiea commented Jan 28, 2019 •

Copy link
Copy Markdown
Collaborator

I also receive the following error when adding an item into the Register.
A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' GROUP_CONCAT(DATE_FORMAT(attribute_datetime, '%m/%d/%Y :%i:%S ') SEPARATOR ', '' at line 1

SELECT GROUP_CONCAT(attribute_value SEPARATOR, GROUP_CONCAT(DATE_FORMAT(attribute_datetime, '%m/%d/%Y :%i:%S ') SEPARATOR ', ') AS attribute_datetimevalues FROM ospos_attribute_links JOIN ospos_attribute_values ON ospos_attribute_values.attribute_id = ospos_attribute_links.attribute_id JOIN ospos_attribute_definitions ON ospos_attribute_definitions.definition_id = ospos_attribute_links.definition_id WHERE definition_type <> 'GROUP' AND deleted = 0 AND sale_id IS NULL AND receiving_id IS NULL AND item_id = 1 AND definition_flags & 2

Filename: C:/wamp64/www/newdate/vendor/codeigniter/framework/system/database/DB_driver.php

Line Number: 691

@odiea

odiea commented Jan 30, 2019

Copy link
Copy Markdown
Collaborator

It's getting better. The Items table needs more work. If I just use the Datetime attribute it does not show on the table until another attribute is selected which may be why the table does not refresh after selecting the Datetime attribute.

@daN4cat

daN4cat commented Feb 16, 2019

Copy link
Copy Markdown
Collaborator

what's the status of this?

@jekkos

jekkos commented Feb 18, 2019

Copy link
Copy Markdown
Member Author

Still have some pending changes here that I need to test further. Also wonder whether we should keep the time in the datetime type. @objecttothis do you actually use it that way or would a regular datepicker suffice?

@daN4cat daN4cat added this to the 3.3.0 milestone Feb 18, 2019
@objecttothis

Copy link
Copy Markdown
Member

Still have some pending changes here that I need to test further. Also wonder whether we should keep the time in the datetime type. @objecttothis do you actually use it that way or would a regular datepicker suffice?

@jekkos For our use, we don't need a full timestamp it as we are dealing with the publication date. So then would you change the database structure to have the attribute_datetime be a DATE in MySQL instead of DATETIME? Also, does it make sense then to refactor our code and the name of the column to be DATE and attribute_date respectively? Let me know what you end of deciding on just storing the date and I will adjust the regex accordingly. The only scenario in which I could forsee the need for a full DATETIME is if we expanded attributes in the future to include Inventory attributes. In that case it could be useful to have a datetime which tells us the hour and minute an item was received, quantity was changed, report was run, etc.

Alternately we could just keep the database as is for future compatibility and ignore the hour, minute and second on the software end. MySQL will accept YYYY-MM-DD in a datetime without the time portion. It just stores zeros in the time portion.

@jekkos

jekkos commented Feb 20, 2019 •

Copy link
Copy Markdown
Member Author

As discusses in other issues, usage of this type of attribute is rather limited as an expiry date should be linked to invntory and not to the item class itself. So for now I might just make this a date instead backed by a MySQL datetime field.

Still have some testing to do here but that won't be before beginning next week, as i'll be off to London for a couple of days ...

@@ -395,16 +381,13 @@ public function save_value($attribute_value, $definition_id, $item_id = FALSE, $
{
$this->db->trans_start();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@objecttothis this it the fix I was talking abouit. You will need to add in another case for decimals then.

@daN4cat

daN4cat commented Apr 28, 2019

Copy link
Copy Markdown
Collaborator

@jekkos what happened to this?

@jekkos

jekkos commented May 2, 2019

Copy link
Copy Markdown
Member Author

Yes I have to find the time to look into this, it's still on my list. I hope somewhere next week.

Comment thread application/helpers/locale_helper.php Outdated
'B' => '',
'g' => '%l',
'G' => '%k',
'h' => '',

@UncleBong UncleBong May 5, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fill-in this lacking associative-array 'h'=>'%H'
in mysql_db -> ospos_app_config -> time_format = 'h:i:s A'

if (sizeof($exploded_value) > 1)
{
$indexed_values[$exploded_value[0]] = $exploded_value[1];
}

@UncleBong UncleBong May 5, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it works tiny fix/change on a special case if DATETIME attribute_value occur
special case for DATETIME attribute_value only. eg: from this '2120/12/31 11' turns to --> '12/31/2120'

$dt_value = to_datetime(strtotime(explode(' ', $exploded_value[1])[0]), FALSE, 'm/d/Y');
$exploded_value[1] = preg_match('/[0-2][0-1][0-9][0-9]/[0-1][0-9]/[0-3][0-9]/i', $exploded_value[1])? $dt_value : $exploded_value[1];
$indexed_values[$exploded_value[0]] = isset($exploded_value[1]) ? $exploded_value[1] : '-';

@UncleBong UncleBong May 5, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i change a little in function to_datetime() at locale_helper.php

function to_datetime($datetime, $flag = TRUE, $dt_format="")
{
$config = get_instance()->config;
if($flag == TRUE) return date($config->item('dateformat') . ' ' . $config->item('timeformat'), $datetime);

 if(!empty($dt_format)) return date($dt_format, $datetime);
 return date($config->item('dateformat'), $datetime);

}

@UncleBong UncleBong May 6, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appreciated sir @jekkos seems working i just put this little fix code it runs on me!
this is just for sample! i used all types of attributes in one records to test
image

in sales register&receiving when i add items i've notice that in table field 'Item Name' w/ lots of attribute values have been setup particularly on this field was bloated with long description
before:
image

after: i add some tooltip on this table field & view the attribute_values there everytime we hover it
image
correct me if i wrong sir i put some little modifications "views/sales/register.php" and i add some little helper functions

@UncleBong UncleBong May 6, 2019 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jekkos these are code functions that i add&modify! i just print screen it
for clear reference!. :)

at tabular_helper.php
image

image

at locale_helper.php
image

at register.php & receiving.php
image

and lastly dont forget to add this!
image

thanks godbless us

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I like the tooltip idea, but it might be good to use it only when the content is too long.

@jekkos jekkos mentioned this pull request May 6, 2019
@daN4cat

daN4cat commented May 6, 2019

Copy link
Copy Markdown
Collaborator

@jekkos please give a kick to this so we can wrap up and release 3.3.0 soon.

@objecttothis

objecttothis commented May 28, 2019 •

Copy link
Copy Markdown
Member

@jekkos it appears that @UncleBong has proposed the changes that you will need to make this work. Once you get the time, could you implement them so that we can do the code reviews and get this into the master?

@daN4cat

daN4cat commented May 30, 2019 •

Copy link
Copy Markdown
Collaborator

Yep, we need to get to an end of this release. It's been a very long time since we started it, and it doesn't look like we are getting near to close it.

@jekkos

jekkos commented May 30, 2019

Copy link
Copy Markdown
Member Author

Ok ill try to give a kick this weekend

@daN4cat

daN4cat commented Jun 2, 2019

Copy link
Copy Markdown
Collaborator

@jekkos managed to get it done?

I really want to close this 3.3.0!

@jekkos

jekkos commented Jun 4, 2019

Copy link
Copy Markdown
Member Author

I did give a kick but wasn't hard enough yet.. converted datetime to be a date but there's some bugs (values not showing after a call to search()). Quite a busy week so hope to pick it up later again.

@jekkos
jekkos force-pushed the fix-attribute-datetime branch from 954e6ec to 4fc0652 Compare June 4, 2019 22:27
@jekkos
jekkos force-pushed the fix-attribute-datetime branch from 4fc0652 to 0ae6470 Compare June 4, 2019 22:47
@jekkos

jekkos commented Jun 4, 2019

Copy link
Copy Markdown
Member Author

Ok had another look and I found no more issues for now, dates are showing and refreshing as it should in items listing now + fixed another bug in the attribute form.

@daN4cat

daN4cat commented Jun 5, 2019

Copy link
Copy Markdown
Collaborator

@objecttothis @UncleBong do you have time to review and test the latest code from @jekkos and see if we are fine now?

@objecttothis

Copy link
Copy Markdown
Member

@objecttothis @UncleBong do you have time to review and test the latest code from @jekkos and see if we are fine now?

I'll install the branch and test it.

@objecttothis

Copy link
Copy Markdown
Member

@daN4cat I went to bintray but there doesn't seem to be any builds for this pull request. If there is another way for me to download a build and test it, please let me know.

@jekkos

jekkos commented Jun 5, 2019

Copy link
Copy Markdown
Member Author

Ok ic, account is rate limited again, alas

@daN4cat

daN4cat commented Jun 5, 2019

Copy link
Copy Markdown
Collaborator

Probably you need to clean up from old builds?

@objecttothis

objecttothis commented Jun 5, 2019 •

Copy link
Copy Markdown
Member

Ok ic, account is rate limited again, alas

That explains why I'm getting "There are no files yet for this package. You can browse files after they are published by the package owner. Check back soon."

Is there a way to keep fewer builds in the account so that we don't hit the size limit?

@jekkos

jekkos commented Jun 5, 2019

Copy link
Copy Markdown
Member Author

I removed all the builds and mailed back to jfrog, hope they respond soon.

@jekkos jekkos closed this Jun 5, 2019
@jekkos jekkos reopened this Jun 5, 2019
@jekkos

jekkos commented Jun 5, 2019

Copy link
Copy Markdown
Member Author

Ok rate limitation was removed, I'm rerunning the build now.

@objecttothis

Copy link
Copy Markdown
Member

Ok rate limitation was removed, I'm rerunning the build now.

I'll see if I can download and test it later tonight.

@odiea

odiea commented Jun 5, 2019

Copy link
Copy Markdown
Collaborator

Nothing was showing in bintray so I had to download it from the master.
It is better now. I had to remove the old date attribute and add date back and it shows fine in the Register with only 1 Date showing.
Items table still loads very slowly with attributes .
When I add an Item id at the register I get the following error.
A Database Error Occurred
Error Number: 1054
Unknown column 'company_name' in 'field list'
SELECT item_id, name, pack_name, company_name, name, cost_price FROM ospos_items WHERE deleted = 0 AND item_type IN(0, 2) AND name LIKE '%1%' ESCAPE '!' ORDER BY name ASC
Filename: C:/wamp64/www/datetime/vendor/codeigniter/framework/system/database/DB_driver.php

@odiea

odiea commented Jun 5, 2019

Copy link
Copy Markdown
Collaborator

Please ignore the db error. I changed the db and it the register works without errors.

@jekkos

jekkos commented Jun 5, 2019 •

Copy link
Copy Markdown
Member Author

@odiea how many items do you have in the items table? I might give the performance another look then and try on a dataset of my own first to see how it compares. I mean you could easily benchmark attributes by deselecting the items flag in the definition. It will omit the JOIN in the query and run it as before. Curious if that is where the perf hit is coming from.

Real quick would be using chrome inspector or the like to see the page load speed with attributes enabled/disabled.

@jekkos

jekkos commented Jun 5, 2019 •

Copy link
Copy Markdown
Member Author

And indeed bintray is still disabled.. quite annoying that their software doesnt remove the limitation after wiping the account, so I'll have to wait for their reply again.

@odiea

odiea commented Jun 5, 2019 •

Copy link
Copy Markdown
Collaborator

I only have 188 items and with the attributes enabled in Items it take 3.6 seconds to show the table. With no attributes in items table it shows almost immediately. 246ms with no attributes in the Items table.

@objecttothis

Copy link
Copy Markdown
Member

I have over 14800 items in my database, but I can't test until bintray gets re-enabled. It's too bad JFrog is a little slow to re-enable the account. @jekkos you said that the rate-limit had been exceeded. Do you mean storage size limit or rate-limit as in number of downloads, or bandwidth used? I ask because if this keep happening we might want to consider alternate solutions to reduce the risk.

@UncleBong UncleBong left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We forgot this function valid_date()

function valid_date($date)
{
return preg_match('/^(([0-9]{2,4})(\/|-)([0-1][0-9])(\/|-)([0-3][0-9])|([0-1][0-9])(\/|-)([0-3][0-9])(\/|-)([0-9]{2,4}))?$/', $date);
}

seems ok sir for now! but for me in the future use its better to stick to valid DATETIME format cuz in this function we can choose either DATE or DATETIME format if we refactor this function nicely! And also what if, if we change the app_config to another 'dateformat' type that we rely on?

sample valid dates: 2001-01-01, 2001/01/01, 12-31-2001, 12/31/2001 01:01:01.

correct me if i wrong SIR i think this will give a future little headache to us

@jekkos

jekkos commented Jun 7, 2019

Copy link
Copy Markdown
Member Author

@UncleBong if you change dateformat then formatting in items table should follow along. After some discussion with @objecttothis we found that the usecase for datetime might be rather limited, that's why I changed it. Where exactly do I need the valid_date method?

@odiea thanks for the quick benchmark. I'll have to look further into this and possibly look into optimizing the query in that case (will run an explain first to see what is causing the slowness)

@objecttothis you're right about bintray. We should maybe set something up that deletes the oldest file once we upload a new build, so that we don't go over this limit again. Or other option would be to use the weblate VPS for this (but will need to check how much download volume these builds account for first).

@UncleBong

Copy link
Copy Markdown

@UncleBong if you change dateformat then formatting in items table should follow along. After some discussion with @objecttothis we found that the usecase for datetime might be rather limited, that's why I changed it. Where exactly do I need the valid_date method?

@odiea thanks for the quick benchmark. I'll have to look further into this and possibly look into optimizing the query in that case (will run an explain first to see what is causing the slowness)

@objecttothis you're right about bintray. We should maybe set something up that deletes the oldest file once we upload a new build, so that we don't go over this limit again. Or other option would be to use the weblate VPS for this (but will need to check how much download volume these builds account for first).

ok sir @jekkos ic thanks nothing to worry! we can use valid_datetime format if we use to_datetime method instead of to_date method but it seems ok to us ready to merge :)

@@ -192,7 +192,9 @@ public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = 'i

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

little refactor/fix to enable to search items particular fields in attribute_values

$attributes_enabled = count($filters['definition_ids']) > 0;

if(!empty($search))
{
$this->db->group_start();
$this->db->like('name', $search);
$this->db->or_like('item_number', $search);
$this->db->or_like('items.item_id', $search);
$this->db->or_like('company_name', $search);
$this->db->or_like('items.category', $search);

  //if ($filters['search_custom'] && $attributes_enabled)
if($attributes_enabled)
{
	$this->db->or_like('attribute_values.attribute_value', $search);
}

$this->db->group_end();
}

if($attributes_enabled)
{
//$format = $this->db->escape(dateformat_mysql(TRUE));
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 AS 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 AS attribute_values', 'attribute_values.attribute_id = attribute_links.attribute_id', 'left');
}

@objecttothis

Copy link
Copy Markdown
Member

@jekkos let's definitely setup bintray to delete the oldest build when a new build goes up. Do you think you could reach out to JFrog again? Bintray still isn't up.

@jekkos

jekkos commented Jun 10, 2019

Copy link
Copy Markdown
Member Author

OK I see, I have sent them two messages but no response yet.

@daN4cat

daN4cat commented Jun 15, 2019

Copy link
Copy Markdown
Collaborator

Might not be a popular decision but I'm going to merge this to master and if any issue we take it as collective pain and fix it.

As stated a couple of times, I want 3.3.0 to be released end of the month, 6 months later than initially intended (end of 2018).

Past this point we need to agree on a different approach because any release takes half or a whole year.
I can't even remember when we released last version!

@daN4cat
daN4cat merged commit 01dfd02 into master Jun 15, 2019
@daN4cat

daN4cat commented Jun 15, 2019

Copy link
Copy Markdown
Collaborator

Pushed the button and done.

Now let's all test and fix any issue!

daN4cat added a commit that referenced this pull request Jun 15, 2019
@jekkos
jekkos deleted the fix-attribute-datetime branch July 4, 2019 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants