
insert into vendors."TendorStatus" ("Status") values
('VendorAccepted'),
('VendorRejected'),
('PartialAccepted');


create table "PharmacyProductType"(
				"PharmacyProductTypeId" serial primary key,
				"TypeName" text,
				"Active" boolean,
				"CreatedBy" int references "Account"("AccountId"),
				"CreatedDate" timestamp without time zone,
				"ModifiedBy" int references "Account"("AccountId"),
				"ModifiedDate" timestamp without time zone
);


alter  table "PharmacyProductType" add column "IsGeneralItem" boolean default false;

create table "PharmacyProductSubType"(
				"PharmacyProductSubTypeId" serial primary key,
				"PharmacyProductTypeId" int references "PharmacyProductType"("PharmacyProductTypeId"),
				"SubTypeName" text,
				"Active" boolean,
				"CreatedBy" int references "Account"("AccountId"),
				"CreatedDate" timestamp without time zone,
				"ModifiedBy" int references "Account"("AccountId"),
				"ModifiedDate" timestamp without time zone
);

alter table "PharmacyProduct" add column "StorageTypeId" int references "LookupValue"("LookupValueId"),
add column "PharmacyProductTypeId" int references "PharmacyProductType"("PharmacyProductTypeId"),
add column "PharmacyProductSubTypeId" int references "PharmacyProductSubType"("PharmacyProductSubTypeId");



alter table "PharmacyProduct" 
 add column "OnlyConsumable" boolean default false;


alter table vendors."TenderRequestSupplierDetail" add column if not exists "VendorQuantity" int;

create table if not exists vendors."IncomingQuotationHeader"(
				"IncomingQuotationHeaderId" bigserial primary key,
				"TenderRequestSupplierHeaderId" bigint references vendors."TenderRequestSupplierHeader"("TenderRequestSupplierHeaderId"),
				"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId"),
				"DeliveryDate" date,
				"RaisedBy" int references "Account"("AccountId"),
				"RaisedDate" timestamp without time zone,
				"ApprovedBy" int references "Account"("AccountId"),
				"ApprovedDate" timestamp without time zone
);

create table if not exists vendors."IncomingQuotationDetail"(
					"IncomingQuotationDetailId" bigserial primary key,
					"IncomingQuotationHeaderId" bigint references vendors."IncomingQuotationHeader"("IncomingQuotationHeaderId"),
					"TenderRequestSupplierDetailId" bigint references vendors."TenderRequestSupplierDetail"("TenderRequestSupplierDetailId")
);


alter table vendors."PharmacyProductRequest" drop column if exists "PharmacyStockId", drop column if exists "RolStocksId";

alter table vendors."PharmacyProductRequest" add column if not exists "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");


alter table vendors."PharmacyProductApproval" drop column if exists "PharmacyStockId";

alter table vendors."PharmacyProductApproval" add column if not exists "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId");

alter table "Supplier" add column if not exists "DeliverDays" int ;


alter table vendors."PharmacyProductApproval" add column if not exists "Quantity" int;

create table vendors."PurchaseOrderHeader"(
					"PurchaseOrderHeaderId" bigserial primary key,
					"PONumber" varchar(250),
					"PORaiseDate" timestamp without time zone,
					"EstimatedDeliveryDate" date,
					"CreatedBy" int references "Account"("AccountId"),
					"CreatedDate" timestamp without time zone,
					"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId"),
					"TotalAmount" numeric,
					"TotalTax" numeric,
				    "TotalNetAmount" numeric,
				    "SupplierId" int references "Supplier"("SupplierId"),
				    "PharmacyWareHouseId" int references "PharmacyWareHouse"("PharmacyWareHouseId")
);

create table vendors."PurchaseOrderDetail"(
				"PurchaseOrderDetailId" bigserial primary key,
				"PurchaseOrderHeaderId" bigint references vendors."PurchaseOrderHeader"("PurchaseOrderHeaderId"),
				"PharmacyProductApprovalId" bigint references vendors."PharmacyProductApproval"("PharmacyProductApprovalId"),
				"Quantity" int ,
				"Amount" numeric,
				"TaxAmount" numeric,
				"NetAmount" numeric
);
                                

alter table "PharmacyPurchaseHeader" add column "PurchaseOrderHeaderId" bigint references vendors."PurchaseOrderHeader"("PurchaseOrderHeaderId");
alter table "PharmacyPurchaseDetail" add column "PurchaseOrderDetailId" bigint references vendors."PurchaseOrderDetail"("PurchaseOrderDetailId");


insert into vendors."TendorStatus"("Status") values
('Partial PO'),
('Completed') ;

alter table vendors."PurchaseOrderDetail" add column if not exists "IsAddedByGrn" bool default false;

------------latest--------

insert into vendors."TendorStatus" ("Status") values ('Awaits Approval');

alter table vendors."PharmacyProductRequest" 
add column if not exists "ApprovalGivenBy" int references "Account"("AccountId"),
add column if not exists "ApprovalGivenDate" timestamp without time zone;

--- 20 07 23
drop table if exists vendors."TenderRequestSupplierDetail" ;

drop table if exists vendors."TenderRequestSupplierHeader" ;

drop table if exists vendors."IncomingQuotationDetail" ;

drop table if exists vendors."IncomingQuotationHeader" ;