if not(exists(select * from systable where UCase(table_name)=UCase('pos_sale')))
then
  create table "pos_sale"
  (
    "id" integer not null,
	"location_code" varchar(10),
	"date_start" datetime,
	"date_end" datetime,
	"pos_terminal_code" integer,
	"currency_code" varchar(3),
	"destination_syscode" varchar(5),
    primary key ("id")
  );
end if;

go

if not(exists(select * from systable where UCase(table_name)=UCase('pos_sale_item')))
then
  create table "pos_sale_item"
  (
    "id" integer not null default autoincrement,
	"pos_sale_id" integer,
	"navision_item_no" varchar(13),
	"regime_syscode" varchar(1),
	"lot_no" varchar(30),
	"qty" numeric(12,3),
	"amount" numeric(12,4),
    primary key ("id")
  );
end if;

go


if not(exists(select * from systable where UCase(table_name)=UCase('pos_sale_payment')))
then
  create table "pos_sale_payment"
  (
    "id" integer not null default autoincrement,
	"pos_sale_id" integer,
	"payment_type_syscode" varchar(15),
	"currency_code" varchar(3),
	"amount" numeric(12,4),
	"amount_bgn" numeric(12,4),
    primary key ("id")
  );
end if;

go

