delete from ccmanager where pid=1005;
delete from ccmanager_id where pid=1005;

delete from centers where pid=1005;
delete from centers_groups where pid=1005;

delete from categs where pid=1005;
delete from categs_groups where pid=1005;

delete from ccprojects where pid=1005;

set names utf8;

INSERT INTO `ccprojects` (`pid`, `desc_project`, `logopic`, `geochart_region`, `geochart_resolution`, `septh`, `sepdc`, `totdc`, `totdcqty`, `umqtyuc`, `stockrep`, `invoiceon`, `project_short`, `project_html`) VALUES
(1005,	'Demo Air Systems',	'ac.png',	'0',	NULL,	'.',	',',	2,	2,	1,	1,	1,	'Demo Air Systems',	'<p><span>A demo project for the hypothetical company </span><strong>Demo Air Systems</strong><span>. Rabio structure is organized to control the delivered and sold quantities of the demo company and provice easy Store Management.</span></p>');

INSERT INTO `ccmanager_id` (`pid`, `mid`, `desc_manager`, `budget`, `expenses`, `rep_column`, `desc_rep`, `desc_rep_stock`, `delta_col`, `delta_pm`, `delta_calc`, `delta_perc`, `menu_order`) VALUES
(1005,	1,	'Delivered',	1,	0,	'A',	'A.Delivered',	'Delivered',	0,	'',	'',	0,	1),
(1005,	2,	'Sold',	0,	1,	'B',	'B.Sold',	'Sold',	0,	'',	'',	0,	2),
(1005,	3,	'B-A',	0,	0,	'C',	'Profit B-A',	'Stock',	1,	'M',	'2,1',	1,	0);


INSERT INTO `centers_groups` (`pid`, `code_center_group`, `desc_center_group`) VALUES
(1005,	'1000',	'DEMO AIR SYSTEMS COMPANY'),
(1005,	'2000',	'WHOLESALE'),
(1005,	'3000',	'RETAIL');

INSERT INTO `centers` (`pid`, `code_center`, `desc_center`, `umc`, `comm_center`, `code_center_group`, `isgroup`) VALUES
(1005,	'1001',	'AIR SYSTEMS STORE',	'--',	'',	'1000',	'GRP0'),
(1005,	'2001',	'EM WORKS COMPANY',	'--',	'',	'2000',	'GRP0'),
(1005,	'2002',	'AC WORKS COMPANY',	'--',	'',	'2000',	'GRP0'),
(1005,	'3999',	'RETAIL CUSTOMER',	'--',	'',	'3000',	'GRP0');

INSERT INTO `categs_groups` (`pid`, `code_categ_group`, `desc_categ_group`) VALUES
(1005,	'10000',	'LG'),
(1005,	'20000',	'MIDEA'),
(1005,	'30000',	'INVENTOR'),
(1005,	'40000',	'SANYO');

INSERT INTO `categs` (`pid`, `code_categ`, `desc_categ`, `um`, `comm_categ`, `code_categ_group`, `isgroup`) VALUES
(1005,	'LG-009K',	'LG AC 9000 BTU',	'PC',	'',	'10000',	'GRP0'),
(1005,	'LG-012K',	'LG AC 12000 BTU',	'PC',	'',	'10000',	'GRP0'),
(1005,	'LG-018K',	'LG AC 18000 BTU',	'PC',	'',	'10000',	'GRP0'),
(1005,	'MIDEA-00001',	'MIDEA AC 9000 BTU',	'PC',	'',	'20000',	'GRP0'),
(1005,	'MIDEA-00002',	'MIDEA AC 12000 BTU',	'PC',	'',	'20000',	'GRP0'),
(1005,	'MIDEA-00003',	'MIDEA AC 18000 BTU',	'PC',	'',	'20000',	'GRP0'),
(1005,	'INVENTOR-AC',	'INVENTOR AC SYSTEM',	'PC',	'',	'30000',	'GRP0'),
(1005,	'SANYO-AC9',	'SANYO AC 9000 BTU',	'PC',	'',	'40000',	'GRP0'),
(1005,	'SANYO-AC12',	'SANYO AC 12000 BTU',	'PC',	'',	'40000',	'GRP0'),
(1005,	'SANYO-AC18',	'SANYO AC 18000 BTU',	'PC',	'',	'40000',	'GRP0'),
(1005,	'SANYO-AC24',	'SANYO AC 24000 BTU',	'PC',	'',	'40000',	'GRP0');

/* DELIVERED */
insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select a.code_center,a.code_categ,c.calday,a.qty*0.1,a.budget*0.1,1,a.pid
from ademo a, calendar c
where a.pid=1005
and c.calday >= '2020-01-01' and c.calday <= '2020-10-31'
and date_format(c.calday,'%d') = '01';


/* SENT 2001 */
insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select '2001',a.code_categ,c.calday,a.qty*0.05,(a.budget*0.05)*1.15,2,a.pid
from ademo a, calendar c
where a.pid=1005
and c.calday >= '2020-05-01' and c.calday <= '2020-08-31'
and date_format(c.calday,'%d') in ('05');

/* SENT 2002 */
insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select '2002',a.code_categ,c.calday,a.qty*0.05,(a.budget*0.05)*1.15,2,a.pid
from ademo a, calendar c
where a.pid=1005
and c.calday >= '2020-04-01' and c.calday <= '2020-09-30'
and date_format(c.calday,'%d') in ('10');


update calendar  set rand_number = FLOOR(RAND()*(5-1)+1);

/* SENT 2002 */
insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select '3999',a.code_categ,c.calday,c.rand_number,(a.budget/a.qty)*c.rand_number,2,a.pid
from ademo a, calendar c
where a.pid=1005
and date_format(c.calday,'%Y') in ('2020')
and date_format(c.calday,'%m') in ('03','04','09','10')
and date_format(c.calday,'%d') in ('7','12','18');



insert into ccmanager (code_center,code_categ,rab_date,rab_qty,rab_number,mid,pid)
select '3999',a.code_categ,c.calday,c.rand_number,((a.budget/a.qty)*1.25)*c.rand_number,2,a.pid
from ademo a, calendar c
where a.pid=1005
and date_format(c.calday,'%Y') in ('2020')
and date_format(c.calday,'%m') in ('05','06','07','08')
and date_format(c.calday,'%d') in ('5','9','12','18');

update ccmanager set invoice = null where pid = 1005;