
alter table "PharmacyProduct" add column "Suppliers" text;
-------------

alter table "PharmacyProductDetail" add column "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");

alter table "PharmacyProductRack" add column "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");

--------------------------


----ImpQuery


with cts as(
select distinct count(ps."PharmacyProductId" ) over(partition by ps."PharmacyWareHouseId") as "Count",ps."PharmacyWareHouseId",ps."PharmacyProductId" from "PharmacyStock" ps
)  
 
insert into "PharmacyProductDetail" ( "ROQ", "ROL", "PharmacyProductId", "CreatedBy", "CreatedDate",  "PharmacyWareHouseId")
select  coalesce(pp."MinQuantity",100) as "ROQ", coalesce(pp."RolQuantity",100)  as "ROL",
 c."PharmacyProductId",pp."CreatedBy",now() as "CreatedDate",c."PharmacyWareHouseId"
 from "PharmacyProduct" pp
 join cts c on c."PharmacyProductId" = pp."PharmacyProductId" 

----Done---

create table "ProductRaiseStatus"(
			 "ProductRaiseStatusId" serial primary key,
			 "Status" varchar(250)
);

insert into "ProductRaiseStatus" ("Status") values
('Raised'),
('Rejected'),
('Completed');
--------

create table "ProductGroupForTender"(
				"ProductGroupForTenderId" serial primary key,
				"PharmacyProductId" int REFERENCES "PharmacyProduct"("PharmacyProductId"),
				"ProductRaiseStatusId" int references "ProductRaiseStatus"("ProductRaiseStatusId"),
				"PharmacyDepartmentId" int REFERENCES "PharmacyDepartment"("PharmacyDepartmentId"),
				"RetailPharmacyId" int REFERENCES "RetailPharmacy"("RetailPharmacyId"),
				"PharmacyWareHouseId" int  REFERENCES "PharmacyWareHouse"("PharmacyWareHouseId"),
				"Active" bool default true,
				"CreatedBy" int REFERENCES "Account"("AccountId"),
				"CreatedDate" timestamp without time zone				
);