Inventory decreases by 1 even if order was cancelled - configuration

Which configuration should I change in order to increase the inventory of a product back to what it was if the order was cancelled?
Thanks,

Login to the admin and change System>Config>Catalog>Inventory>Stock Options>Set Items' Status to be In Stock When Order is Cancelled = Yes. That should do it for you.

Related

How Can I extract order details for every first customer order with mysql

I'm tying to extract from my Prestashop 1.6 the following info for every first customer order:
ID customer
sex
age
order date
total amount spent
product category
Newsletter subscription yes or not
using VAT yes or not
Using coupon yes or not
payment method
device or OS (it is the device the customer was connected from)
Is here anyone who can help me?
Thank you very much!

MYSQL - How to group by with condition

Here's an example of the tables and outputs I want
I want to group by by no reg with condition, status = 0 but if in table activity there is no status = 0 then that will be selected is with biggest id
You may only need this query.
Select no_reg, location from activities where status = 0
Check the result and run another query.
if (result == null){ //for example run the query below
Select no_reg, location from activities desc limit 1
}
From the image what you want is activities of the equipment i believe
for example if you want to check the equipment A1 Malaysia should be list or one with biggest status will be listed i believe
if thats what you want here it is
SELECT no_reg,MAX(status) FROM activities a,equipment e on e.no_reg=a.no_reg where e.no_reg='A1' group by a.no_reg
i believe this is the solution you are expecting

FIFO in MySQL db

I'm using Mysql (not MSSQL) database and bumped onto a problem I seem to be unable to solve. I would very much appreciate your help finding a solution.
I'd like to create a view using two tables, as described below:
1. product_in
product_code
received_time
received_amount
2. product_out
product_code
delivery_time
delivered_amount
The “view” should provide the following:
product_code
received_time
received_amount
of_which_delivered
My problem is that product_out is to be administered to the first incoming data (FIFO: first in first out), but since the amount delivered is either more or less than the received amount, I do not know how to calculate the “of_which_delivered”.
So far, I managed to put into order the incoming data, and sum up the outgoing (delivered) goods using SUM.
SELECT
sn,
product_code,
received_time,
received_amount,
delivered_amount
FROM
( SELECT
received_time,
received_amount,
#rend2 := If( #rend1 = product_code, #rend2 + 1, 1) as sn,
#rend1 := product_code AS product
FROM
product_in,
( SELECT #rend1 := 0, #rend2 := 0 ) AS tt
ORDER BY
product_code,
received_time ) AS k
LEFT JOIN
( SELECT
product_code AS prdct,
SUM(delivered_amount) AS delivered_amount
FROM
product_out
GROUP BY
product_code ) AS b
ON aru = product_code
I have not succeded in creating the loop that would make it possible to analyze if the output amount is more, or less than the received amount on a given day, and if more, then the difference be added to the received amount of another day.
To be more precise, here is an example:
Product Date Qty
nr.1 Sep 2 500
nr.1 Sep 3 300
nr1. Sep 4 200 on the 4th.
900 pcs were delivered out on the 5th.
In this case we should see the following in the view:
Product Action Date Qty
nr.1 received Sep 2 500 (delivered all 500)
nr.1 received Sep 3 300 (delivered all 300)
nr.1 received Sep 4 200 (only 100 delivered)
I would be very grateful to anyone who could help me find a solution!
Sorry no query adjustment for you, but... having worked with accounting systems in the past, your database structure appears short on a better handling of the in/out FIFO method (or even LIFO). What the underlying accounting system had was a inventory table for all receipts (abbreviated)
Table: ItemTrans
ItemTransID (auto-increment ID for any transaction)
ItemID (item id of the inventory item)
Status (status, such as In, Our or Inventory Adjustment)
Date (date of the activity)
Qty (quantity)
QtyUsed (running total column as inventory was used up)
As items were sold or adjustments. the Sales Details table would show which ItemTrans record the quantities were used for. So, if you had inventory on hand as you have in your sample, the sales order detail line would show the 900. The inventory used table would show which specific ItemTransID the quantities were allocated from and how many from said block, thus showing what your intended activity of release of actual product was at the time of sale.
This way, you don't have to recreate what inventory was what at a given point in time. Just query the sales order details and which items they were pulled from to get the data and how many from each block of receipt it went against.
This simplifies the process of generating the COGS (cost of goods sold) as would be reported to the General Ledger from a Sub-journal such as Accounts Receivable (Sales Orders) activity.
Do you have the ability to introduce such adjustments to your database structures?

Is there a better way to determine the most trusted users in a bookstore database?

I'm building a web portal for a bookstore.
I want to allow users to mark other users as "trusted" or "not-trusted".
I want to figure out who are our stores most trusted users by ordering on their overall trust level.
Here's an example to illustrate how this trust level is calculated:
We are going to calculate Bob's trust level...
Bob has been marked as "trusted" by 100 other users, and marked as "not trusted" by 20 users. Bob's trust level = 100 - 20 = 80.
I have the following table:
Judges(judgerLoginName: VARCHAR(45), judgedLoginName VARCHAR(45), trustLevel SMALLINT)
Now, currently I have a trustLevel of 0 representing "not-trusted" and 1 representing "trusted".
So, I'm thinking about changing all the 0's to -1's, so I could do a simple:
SELECT judgedLoginName, SUM(trustLevel)
FROM Judges
GROUP BY judgedLoginName,
ORDER BY SUM(trustLevel) DESC
However, I would like to know if there was an equally simple means to subtract countOfNotTrusted from countOfTrusted. What do you suggest? I'm quite new to database development and would appreciate any guidance.
SELECT judgedLoginName, SUM(IF(trustLevel = 0, -1, 1))
FROM Judges
GROUP BY judgedLoginName,
ORDER BY 2 DESC
Check if your trust level is 0, then the value that is added is -1
Added the order by 2 to order by the second column if you need to
SELECT judgedLoginName, -COUNT(*)+2*SUM(trustLevel)
FROM Judges
GROUP BY judgedLoginName,
ORDER BY 2 DESC
gives all users a value of -1 and adds the trusted ones +2, resulting in +1 for them.

Comparing multiple rows of data in sql

Howzit guys!
I have to compare multiple rows of data with each other and i would really appreciate your help
I have a table in sql called Technicians. this table contains information about a technician such as, [Tech_id, Name, Surname, Tel, Cell, Status, Last_Available_time].
There are 3 status types: 'Available', 'Semi Available' and 'unavailable'
*Semi available meaning that a technician has jobs assigned to him but of mostly low priority. Last_available_time is set to datetime*
I need to get the technician with a status of 'available' and the longest last_available_time
I'm still a student.
My sql code:
select * from Technician
where (_Status='Available')
Just get the first record, ordered by their available date:
SELECT TOP 1 *
FROM Technician
WHERE _status = 'Available'
ORDER BY Last_Available_Time
That will give one available technician, with the oldest available time.