delete from ccmanager where pid in (601);

/* STORE ITEMS 2019 FIRST DAY OF MONTH */
/* ORDERS PID = 1*/
insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select r.code_center,k.code_categ,c.calday,100,1000,1,601
from centers r, categs k, calendar c
where r.pid=601 and k.pid = 601
and date_format(c.calday,'%d') = '01'
and c.calday >= '2019-01-01' and c.calday <= '2019-12-31';

update ccmanager set rab_number = 4500 where code_categ = '101' and pid = 601;
update ccmanager set rab_number = 2900 where code_categ = '102' and pid = 601;
update ccmanager set rab_number = 1300 where code_categ = '103' and pid = 601;

update ccmanager set rab_qty = rab_qty * 2, rab_number = rab_number * 2 where code_categ = '102' and pid = 601;
update ccmanager set rab_qty = rab_qty * 3, rab_number = rab_number * 3 where code_categ = '103' and pid = 601;

/* DELIVERED PID = 2 */
insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select r.code_center,r.code_categ,DATE_ADD(r.rab_date, INTERVAL 4 DAY),r.rab_qty/2,r.rab_number/2,2,r.pid
from ccmanager r
where r.pid = 601 and r.mid = 1 and r.rab_date < '2019-12-01';

insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select r.code_center,r.code_categ,DATE_ADD(r.rab_date, INTERVAL 14 DAY),r.rab_qty/2,r.rab_number/2,2,r.pid
from ccmanager r
where r.pid = 601 and r.mid = 1 and r.rab_date < '2019-12-01';


/* SALES FORECAST PID = 4 */
insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select r.code_center,r.code_categ,DATE_ADD(r.rab_date, INTERVAL 4 DAY),r.rab_qty/10,r.rab_number/10,4,r.pid
from ccmanager r
where r.pid = 601 and r.mid = 1;

insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select r.code_center,r.code_categ,DATE_ADD(r.rab_date, INTERVAL 9 DAY),r.rab_qty/4,r.rab_number/4,4,r.pid
from ccmanager r
where r.pid = 601 and r.mid = 1;

insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select r.code_center,r.code_categ,DATE_ADD(r.rab_date, INTERVAL 11 DAY),r.rab_qty/5,r.rab_number/5,4,r.pid
from ccmanager r
where r.pid = 601 and r.mid = 1;

insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select r.code_center,r.code_categ,'2019-01-12',r.rab_qty/15,r.rab_number/15,4,r.pid
from ccmanager r
where r.pid = 601 and r.mid = 1 AND r.rab_date = '2019-01-01';

insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select r.code_center,r.code_categ,'2019-12-12',r.rab_qty/20,r.rab_number/20,4,r.pid
from ccmanager r
where r.pid = 601 and r.mid = 1 AND r.rab_date = '2019-01-01';

update ccmanager set rab_number = rab_number * 1.2 where code_categ = '101' and pid = 601 and mid = 4;
update ccmanager set rab_number = rab_number * 1.3 where code_categ = '102' and pid = 601 and mid = 4;
update ccmanager set rab_number = rab_number * 1.4 where code_categ = '103' and pid = 601 and mid = 4;

/* UPDATE FOR COUNTRIES */
/* UPDATE FOR ITALY */
update ccmanager set rab_qty = rab_qty * 5, rab_number = rab_number * 5 where code_center = '1001' and pid = 601;
/* UPDATE FOR FRANCE */
update ccmanager set rab_qty = rab_qty * 6, rab_number = rab_number * 6 where code_center = '2001' and pid = 601;
/* UPDATE FOR SPAIN */
update ccmanager set rab_qty = rab_qty * 4, rab_number = rab_number * 4 where code_center = '4001' and pid = 601;
/* UPDATE FOR GERMANY */
update ccmanager set rab_qty = rab_qty * 10, rab_number = rab_number * 10 where code_center = '5001' and pid = 601;

/* UNIT COST UPDATE */

update ccmanager set rab_uc = (rab_number / rab_qty) where pid = 601;