Is it bad practice to calculate within the insert query? I am trying to do a web application for time sheets.
I have three options to calculate the value of hours (AFAIK):

In the form
In the backend
In the query

Is it smart or bad practice to do this calculation in the SQL query?
with list as (select code_id,code_ppu from code)

insert into hr values
(default,'JD','20-0001','PM','testing',1.25,
(select code_ppu from list where code_id='PM'),
(select 1.25 * code_ppu from list where code_id='PM')),
 
(default,'JD','20-0001','COPY','testing',2.25,
(select code_ppu from list where code_id='COPY'),
(select 2.25 * code_ppu from list where code_id='COPY'));

db fiddle https://www.db-fiddle.com/f/f8nZn5LQfbmKxAdxX2fdej/50
INSERT INTO hr (hr_sign, hr_job, hr_code, hr_subject, hr_qty, hr_ppu, hr_sum)
SELECT 'JD',
       '20-0001',
       code_id,
       'testing',
       CASE code_id WHEN 'PM' THEN 1.25
                    WHEN 'COPY' THEN 2.25
                    END, 
       code_ppu, 
       code_ppu * CASE code_id WHEN 'PM' THEN 1.25
                               WHEN 'COPY' THEN 2.25
                               END
FROM code
WHERE code_id IN ('PM','COPY');

PS. It is safe to store the relation between code_id and according coefficient (set into hr_qty and used during hr_sum calculation) in separate table and use this table in data source instead of CASEs.


Is it smart or bad practice to do this calculation in the SQL query?

Calculations is a norma. But shown subqueries usage - hardly...


How do I transfer them as parameters?

For example, something like (not tested)
INSERT INTO hr (hr_sign, hr_job, hr_code, hr_subject, hr_qty, hr_ppu, hr_sum)
WITH 
cte1 AS ( SELECT one_row
          FROM REGEXP_SPLIT_TO_TABLE(@packed_csv, ',') AS parameters(one_row) ),
cte2 AS ( SELECT SPLIT_PART(one_row, ':', 1) AS code_id,
                 SPLIT_PART(one_row, ':', 2)::DECIMAL AS multiplier 
          FROM cte1 )
SELECT 'JD',
       '20-0001',
       code.code_id,
       'testing',
       cte2.multiplier, 
       code.code_ppu, 
       code.code_ppu * cte2.multiplier
FROM code
JOIN cte2 ON code.code_id = cte2.code_id;

where @packed_csv is a string like 'PM:1.25,COPY:2.25',