Prestashop : invoice number in database stays at 0 - database

PrestaShop version: 1.6.1
Hosting: ionos
PHP version: 5.6
MySQL version: MySQL 5.7
Hi,
I recently saved new settings in orders > invoices tab but did left the invoice number at 0 in order for it to continue being auto incremented. My problem is that since then no invoices are being generated and when I go to my db - in the ps_order_invoice table - I see that all new order invoice has the number 0. When I manually change the invoice number in the db, an invoice is being generated but it's not really a long term solution.
(I did ask on the prestashop forum but it's like a ghost town there, nobody answered).
I tried changing the invoice_start_number in the ps_configuration table to set it at the next number the invoice should be but it didn't change anything. All new invoices are still numbered 0. I also tried deleting the invoice_start_number line so that it would be recreated when I set it from the BO (and somehow solve everything) but didn't change anything either. And I can't set the column "number" as auto increment since there is already the id_order_invoice being auto incremented.
Does anyone have an idea on how to solve this ? Cause I really don't know what files are in charge of this nor what I should change in them.

Related

delleting bulk comment_type="order_note" from woocommerce DB

wocoommerce after each change status on an order sends comments that types are "order_note" in database.
how can i remove all or disable some of it.
they are 36000 rows in my database now.
some of the order status note comments are not important for us.
picture
36000 rows actually is not that big of a deal. WooCommerce has many performance and database structure related imperfections you should keep in mind, this is probably not one of them.
Anyway...
WooCommerce stores it's order notes inside wp_comments table, with the comment type set as order_note.
You can safely delete these rows as you wish. For example if you want to delete order notes from year 2021 and earlier (and keep only those from 2022), you can run this query:
DELETE FROM `wp_comments` WHERE `comment_type` = 'order_note' AND `comment_date` <= '2021-12-31';
If you want to delete order notes for specific order IDs (e.g. for order 12345 and older), you can do it the similar way:
DELETE FROM `wp_comments` WHERE `comment_type` = 'order_note' AND `comment_post_ID` <= 12345;
You can implement this SQL query as a PHP script using $wpdb, e.g. to automatically delete order notes, that had been created last year or earlier:
global $wpdb;
// Delete all order notes created last year and earlier
$delete_before = date( 'Y-m-d', strtotime( 'last year December 31st' ) );
$wpdb->query($wpdb->prepare("DELETE FROM `wp_comments` WHERE `comment_type` = 'order_note' AND `comment_date` <= %s;", $delete_before));
You can implement such script as a function and trigger it automatically, either with wp_schedule_event() or as a standard CRON job.

Update all products (When out of stock) Prestashop

I need to change the available for order when out stock of all products.
I know is for the SQL way, but I don't know the table name, because ps_product_shop not have an option for this. and in the table ps_stock_avaiable only appears the products with the change of the option When out of stock.
Thanks for your time
Well i'm not sure what version of PrestaShop you use, but for 1.6 what you need is in:
"ps_product" table "available_for_order" field, change 1 or 0 to enable and disable for each product, or for all.
You need to execute this sql request which will change the ps_stock_available table and field out_of_stock from '0' to '1':
UPDATE `ps_stock_available` SET `out_of_stock`=1

Trouble Excluding Nodes from Graph

Set-Up
I'm very new to graph databases and neo4j/cypher and I'm having a hard time understanding how to exclude various pieces from my results. Below is an image of my graph. Every node and every relationship has an activeFrom and activeTo property to allow me to view the graph as it existed at any given point in history.
MATCH (:Collective:Company)<-[tree *0..4]-(downline:Collective) RETURN downline
(Any relationship with a date indicates it's already, or scheduled (future date) to expire. No date or future date means it's active.).
Question
My ultimate goal here is to view this same graph, minus all expired nodes and relationships. Right now, I'm trying to build the query that will let me see that and am failing :(
What I'm not understanding is why:
Region5's relationship to Company1 is still active... why isn't company showing up? (shouldn't the 0-length path bring the company back like in the first image?)
Both Office5 and Office27 have expired relationships, so why are they still in the result?
Offices 1, 2, 6, 9, and 11 are active nodes, but have no active relationships, so why are they being returned? (my GUESS here is that my 2nd WHERE clause (branch filter) is filtering out the relationships, but not the nodes they associate, but I'm not sure how to do it differently)
.
MATCH (:Collective:Company)<-[tree *0..4]-(downline:Collective)
WHERE
// -- node(s) are active
downline.activeFrom <= '2015-08-31 23:59:59'
AND (downline.activeTo IS NULL OR downline.activeTo > '2015-08-31 23:59:59')
UNWIND tree AS branch
WITH branch, downline
WHERE
// -- branch is active
branch.activeFrom <= '2015-08-31 23:59:59'
AND (branch.activeTo IS NULL OR branch.activeTo > '2015-08-31 23:59:59')
RETURN downline
Bonus
I've set up a neo4j sandbox with this data for you guys to play with if needed. Please be mature with this, as I don't know how to make it read only. Please don't go deleting data and messing things up for other people. I'm also personally paying for this cloud instance, so please don't abuse the VM/resources :)
You can access it here: (sorry, removed for security purposes now that question has been answered).
Based on your questions, I'm trying to piece together what you require and I understand that you want to return paths that contain all active nodes and relationships. This is because you've asked about Office 27 and Office 5 which are both active nodes, but their single relationship to region 5 is inactive, so you do not want the paths between Office 27->Region 5 and Office 5->Region 5.
Office 2 however, is active, and it has an active relationship to region 4(also active). Region 4 has an inactive relationship to Company 1, so since you don't expect Office 2 in the results, I'm assuming it's because it has the inactive relationship in the entire path?
If this is the case, here's a query that hopefully does what you want-
MATCH p=(:Collective:Company)<-[tree*0..4]-(downline:Collective)
WHERE
ALL(x in relationships(p) WHERE x.activeFrom <= '2015-08-31 23:59:59'
AND (x.activeTo IS NULL OR x.activeTo > '2015-08-31 23:59:59'))
AND ALL(x in nodes(p) WHERE x.activeFrom <= '2015-08-31 23:59:59'
AND (x.activeTo IS NULL OR x.activeTo > '2015-08-31 23:59:59'))
RETURN p
This makes sure that every relationship and every node in a path is active. To bring back Office 2,1, change ALL to ANY and you'll see those back in the results because the path is now partially active.
BTW, you could also set up your graph at http://console.neo4j.org/?init=0 and share it

How to keep track changing items in a stock portfolio?

I have a system where people can pick some stocks and it values their portfolios but I'm having trouble doing this in a efficient way on a daily basis because I'm creating entries for days that don't have any changes(think of it like I'm measuring the values and having version control so I can track changes to the way the portfolio is designed).
Here's a example(each day's portfolio with stock name and weight):
Day1:
ibm = 10%
microsoft = 50%
google = 40%
day5:
ibm = 20%
microsoft = 20%
google = 40%
cisco = 20%
I can measure the value of the portfolio on day1 and understand I need to measure it again on day5(when it changed) but how do I measure day2-4 without recreating day1's entry in the database?
My approach right now(which I don't like) is to create a temp entry in my database for when someone changes the portfolio and then at the end of the day when I calculate the values if there is a temp entry I use that otherwise I create a new entry(for day2-4) using the last days data. The issue is as data often doesn't change I'm creating entries that are basically duplicates. The catch is: my stock data is all daily. I also thought of taking the portfolio and if it hasn't been updated in 3 days to find the returns of the last 3 days for each stock but I wasn't sure if there was a better solution.
Any ideas? I think this is a straight forward problem but I just can't see a efficient way of doing it.
note: in finance terms, its called creating a NAV and most firms do it the inefficient way I'm doing it but its because the process was created like 50 years ago and hasn't changed. I think this problem is very similar to version control but I can't seem to make a solution.
In storage terms is makes most sense to just store:
UserId - StockId1 - 23% - 2012-06-25
UserId - StockId2 - 11% - 2012-06-26
UserId - StockId1 - 20% - 2012-06-30
So you see that stock 1 went down at 30th. Now if you want to know the StockId1 percentage at the 28th you just select:
SELECT *
FROM stocks
WHERE datecolumn<=DATE(2012-06-28)
ORDER BY datecolumn DESC LIMIT 0,1
If it gives nothing back you did not have it, otherwise you get the last position back.
BTW. if you need for example a graph of stock 1 you could left join against a table full of dates. Then you can fill in the gaps easily.
Found this post here for example:
UPDATE mytable
SET number = (#n := COALESCE(number, #n))
ORDER BY date;
SQL QUERY replace NULL value in a row with a value from the previous known value

Magento - get list of items from orders for specific date range

Magento database name convention is not trivial. How to get these fields below for last 7 days?
Last Name
First Name
Address
City
State
Zip
Phone
Email
Amount
Order #
Item #
I could not tell if you were looking for some PHP/Magento code or if you are looking to access the database directly. It might be "better" to create yourself a custom module that fetches this info using the Magento/Zend framework, but since I don't know the code off the top of my head I'll redirect you to the following link which has a very nice SQL query that will pull that info for you (and more).
http://www.magentocommerce.com/wiki/groups/207/fedex_-_shipping_view
You probably just need to add something like this to the end to filter the last 7 days
where so.created_at > NOW() - INTERVAL 7 DAY

Resources