SELECT 
    t.store_code AS original_store_code_task,
    substring(t.store_code from '^[^.]*') AS modified_store_code_task--,
--    s.store_code AS original_store_code_sjreport,
--    substring(s.store_code from '^[^.]*') AS modified_store_code_sjreport
FROM 
    task t
--JOIN 
--    sjreport s ON t.sjreport_id = s.id
WHERE t.store_code LIKE '%.%';  -- Adjust the join condition as necessary



UPDATE sjreport
SET store_code = substring(store_code from '^[^.]*')
WHERE store_code LIKE '%.%';


UPDATE task
SET store_code = substring(store_code from '^[^.]*')
WHERE store_code LIKE '%.%';


select count(*) from sjreport s 

select count(*) from task t 



select count(*) from task s where SUBSTRING(week_start_date FROM 6 FOR 2) not IN ('09', '12');


CREATE TABLE sjreport_backup_20241209 AS TABLE sjreport;

CREATE TABLE task_backup_20241209 AS TABLE task;


DELETE FROM task
WHERE SUBSTRING(week_start_date FROM 6 FOR 2) NOT IN ('09', '12');







INSERT INTO task (    
    name,
    status,
    file_id,
    client_id,
    customer_id,
    user_id,
    created_by,
    updated_by,
    updated_at,
    sites,
    callsheet_id,
    sjreport_id,
    app_user_mobile,
    type,
    day,
    week,
    note,
    price,
    count,
    barcode,
    share,
    store_id,
    approve,
    rep_full_name,
    chain,
    store_name,
    category,
    brand,
    product,
    variant,
    size,
    image_url,
    week_number,
    score,
    week_start_date,
    store_soh,
    system_dros,
    scoring_system,
    last_sold,
    due_date,
    time_spent,
    promo_before_url,
    promo_after_url,
    created_at,
    store_code,
    product_id
)
SELECT    
    name, 
    status, 
    file_id, 
    client_id, 
    customer_id, 
    user_id, 
    created_by, 
    updated_by, 
    updated_at, 
    sites, 
    callsheet_id, 
    sjreport_id, 
    app_user_mobile, 
    type, 
    day, 
    week, 
    note, 
    price, 
    count, 
    barcode, 
    share, 
    store_id, 
    approve, 
    rep_full_name, 
    chain, 
    store_name, 
    category, 
    brand, 
    product, 
    variant, 
    size, 
    image_url, 
    week_number, 
   score, 
   week_start_date, 
   store_soh, 
   system_dros, 
   scoring_system, 
   last_sold, 
   due_date, 
   time_spent, 
   promo_before_url, 
   promo_after_url, 
   created_at, 
   store_code,  
   product_id
FROM task_backup_20241209
WHERE week_start_date >= '2024-11-01' AND week_start_date < '2024-12-01'
AND week_start_date != '2024-11-11';



INSERT INTO sjreport (
    created_at,
    date,
    region,
    cluster,
    geography,
    channel,
    store_name,
    category,
    brand,
    product,
    variant,
    size,
    barcode_ending,
    issue_for_feedback,
    notes,
    article,
    banner,
    last_sold,
    month,
    rsp_value_loss,
    status,
    store_code,
    store_soh,
    system_dros,
    week,
    row,
    file,
    sheetname,
    week_1,
    due_date,
    score,
    rebate,
    oos_place_order,
    seven_day_cover,
    soh_no_sales,
    negative_stock,
    no_sales_100,
    date_viewed,
    name,
    active_count,
    checked_by,
    march,
    fixed,
    not_ranged,
    feedback_due_by,
    instruction,
    barcode,  -- Note: Ensure this column is not duplicated if it exists in both tables
    no_stock,
    issues_reported,
    qc_check,
    insruction,  -- Note: There seems to be a typo; ensure consistency with your schema
    instructions, 
    ranged_and_selling, 
    published_date, 
    undefined, 
    week_start_date, 
    scoring_system
)
SELECT 
   created_at, 
   date, 
   region, 
   cluster, 
   geography, 
   channel, 
   store_name, 
   category, 
   brand, 
   product, 
   variant, 
   size, 
   barcode_ending, 
   issue_for_feedback, 
   notes, 
   article, 
   banner, 
   last_sold, 
   month, 
   rsp_value_loss, 
   status, 
   store_code, 
   store_soh, 
   system_dros, 
   week, 
   row, 
   file, 
   sheetname, 
   week_1, 
   due_date, 
   score, 
   rebate, 
   oos_place_order, 
   seven_day_cover, 
   soh_no_sales, 
   negative_stock, 
   no_sales_100, 
   date_viewed, 
   name,   
   active_count,  
   checked_by,  
   march,  
   fixed,  
   not_ranged,  
   feedback_due_by,  
   instruction,  
   barcode,  -- Ensure this matches your schema
   no_stock,  
   issues_reported,  
   qc_check,  
   insruction,  -- Ensure this matches your schema
   instructions ,  
   ranged_and_selling ,  
   published_date ,  
   undefined ,  
  week_start_date ,  
  scoring_system
FROM sjreport_backup_20241209
WHERE week_start_date >= '2024-11-01' AND week_start_date < '2024-12-01'
AND week_start_date != '2024-11-11';