unit uGlobalVar;

interface

uses uRegModel, System.Classes, SysUtils, Vcl.Graphics,
     uGlobalTypes, System.Generics.Collections,
     {$IFNDEF EAPI}
     uUserSettingsStore, uUserSettingsLegacy, uUserSettings.KVAdapter,
     {$ENDIF}
     SysTem.SyncObjs, udmResourceStrings;

const
  ID_PRODUCT                        = 'PT300';
  PROGRAM_VERSION                   = '4.250.00.10';

  HH_HELP_CONTEXT                   = $F;

  SOCKET_TIMEOUT                    = 1000;

  APP_YEAR                          = '2025';

  OPERATION_DOVOLENA                = 3996;

  BOOLEAN_VAL_TRUE                  = '1';
  BOOLEAN_VAL_FALSE                 = '0';

  OPERATION_GROUP_REZIE             = 2;
  OPERATION_GROUP_OSTATNI           = 3;

  tyto_znaky_ne_1 = ['\', '?', ':', '"', '<', '>', '|', '''', '*', '+'];

  OPERATION_ODCHOD = 3999;
  OPERATION_PRICHOD = 3997;

  LANGUAGELIST : TArray<String> = ['NTV','DEU','ENU','SKY'];

  POPUP_DATUM_POLOZEK = 20;

  POHYB_NEDEFINOVAN = 0;
  POHYB_PRIJEM = 1;
  POHYB_VYDEJ = 2;
  POHYB_PREVOD = 3;

  BAR_PREFIX_OPERATION      = 'A';
  BAR_PREFIX_ORDER          = 'B';
  BAR_PREFIX_CUSTOMER       = 'C';
  BAR_PREFIX_WORKER         = 'D';
  BAR_PREFIX_PAUSAL         = 'E';
  BAR_PREFIX_SERVICE        = 'F';
  BAR_PREFIX_MATERIAL       = 'G';
  BAR_PREFIX_COUNT          = 'H';
  BAR_PREFIX_NARADI         = 'I';
  BAR_PREFIX_POHYB          = 'J';
  BAR_PREFIX_FORMA          = 'K';
  BAR_PREFIX_MATERIAL_POHYB = 'M';
  BAR_PREFIX_SKLAD_POZICE   = 'P';
  BAR_PREFIX_ORDER_UNIQUE_OPERATION = 'Q';

var
{$IFNDEF EAPI}
  GlobalUserSettings                    : TUserSettingsLegacy;
  GlobalUserSettingsStore               : TUserSettingsStore;
{$ENDIF}
  GlobalUserId                          : Integer;


  GL_EXPORT_OBJEDNAVKY_POVOLENO     : boolean;
  GL_EXPORT_OBJEDNAVKY_SOUBOR       : string;
  GL_CZPLAST                        : Boolean;

  STORNO_FLAG                       : boolean; //pro stornovani vypoctu
  URL                               : PChar;
  LOGING                            : Boolean;

  DEBUG_TIME                        : TDateTime;
  LICID                             : TRegData;
  LICID_CHECKED                     : Boolean;
  LICID_DATA, LICID_CNT             : TStream;
  LICENCE_FROM_DB                   : Boolean;

  EASY_VERSION                      : Boolean;
  START_VERSION                     : boolean;
  URL_ACTIVATE_SUD                  : String;
  iniFileOverride                   : string;

  USE_STAVY_DOKLADU                 : boolean;

  FILTRY_USE_REGV                   : boolean;
  NEWSQLLIKE                        : boolean;

  FILTER_REPLACE_COMMA              : boolean;

  LIMIT_ZAZNAMU_COMBO_POCET         : Integer;

  URL_BASE                          : string;

  URL_SERIAL_STATUS                 : PChar;
  URL_SERIAL                        : PChar;
  URL_MESSAGE                       : PChar;
  URL_MESSAGE_PORTAL                : PChar;
  URL_GENERATOR                     : PChar;
  URL_LICENCE                       : PChar;

  ODDELOVAC                         : String[1];
  NEAKTUALIZOVAT_POCET_ZOBRAZ_ZAZNAMU : Boolean;
  LIMIT_ZAZNAMU                     : Boolean;
  LIMIT_ZAZNAMU_POCET               : Integer;
  LOGED_USER                        : String;
  LOGED_USER_ID                     : Integer;
  LOGED_USE_WORKERID                : Integer;

  presunSloupce                     : boolean;

  SERVICE_SERVER                    : String;
  SERVICE_PORT                      : Integer;

  USER_VYCHOZI_JAZYK                : string;

  SKLAD_POZICE_USE_PREFIX           : boolean;

  DASHBOARD_ADVANCED_PAGE           : boolean;

  OPERATION_PROPUSTKA               : integer;
  OPERATION_NEMOC                   : integer;
  OPERATION_OCR                     : integer;
  OPERATION_SLUZEBNI_CESTA_KOD      : string;
  DASHBOARD_OPERACE_CNC_PORUCHA,
  DASHBOARD_OPERACE_CNC_SERVIS,
  DASHBOARD_OPERACE_CNC_SERIZOVANI  : string;
  LOGED_USER_OPERACE_TOP5_DAYS      : Integer;

  NOVY_C_ORDER_GRID                 : Boolean;
  constUnits                        : TStringList;

  FormatStr                         : TFormatSettings;

  CIZI_MENA                         : boolean;
  KURZ                              : extended;
  CIZI_MENA_ZKRATKA                 : string;
  DEFAULT_MENA                      : string;
  LOKAL_MENA_ZKRATKA                : string;

  KURZY_ZKRATKY                     : array of string;
  KURZY_HODNOTY                     : array of extended;

  ID_PASIVNI                        : string;

  MONITORING_AGENDA_ACTIVE          : Boolean;

  COLOR_EDIT_FIELDS                 : Integer;
  COLOR_CAPTIONS                    : Integer;
  COLOR_MEMO_FIELDS                 : Integer;
  COLOR_COMBOBOX_FIELDS             : Integer;
  COLOR_DATETIME_PICKER             : Integer;
  COLOR_BUTTON                      : Integer;

  STYLE_EDIT_FIELDS                 : TFontStyles;
  STYLE_CAPTIONS                    : TFontStyles;
  STYLE_DBGRID                      : TFontStyles;
  STYLE_MEMO_FIELDS                 : TFontStyles;
  STYLE_COMBOBOX_FIELDS             : TFontStyles;
  STYLE_DATETIME_PICKER             : TFontStyles;
  STYLE_BUTTON                      : TFontStyles;
  STYLE_CHECKBOX                    : TFontStyles;
  STYLE_RADIOBUTTON                 : TFontStyles;


  FORMAT_HODIN : integer;

  OPERATION_WC_PAUZA: String;
  OPERATION_INT_CODE: boolean;

  //ticket #2831 ///////////////////////////////////////////////////////////////
  FRMAIL_PRINT        : boolean=false;
  FRMAIL_ADDRESS      : STRING;
  FRMAIL_FROM         : STRING;
  FRMAIL_SMTPHOST     : string;
  FRMAIL_LOGIN        : string;
  FRMAIL_PASS         : string;
  FRMAIL_SUBJECT      : string;
  FRMAIL_CONFREAD     : boolean;
  FRMAIL_SHOWDIALOG   : boolean;
  FRMAIL_SMTPPORT     : integer;
  FRMAIL_TYPE         : string;
  FRMAIL_NAME         : string;
  FRMAIL_USENATIVEAPP : boolean;
  //////////////////////////////////////////////////////////////////////////////

  FREXPORT_DIR        : string;   //2848
  FREXPORT_SAVESTYLE  : integer;  //2848

  PODPIS: string;
  GLOBAL_PODPIS : string;
  SPISMARK: string;

  LOGED_USER_EMAIL                  : String;
  LOGED_USER_PHONE                  : String;

  LOGED_USER_REALNAME               : String;

  CONECTION_DRIVERNAME              : String;
  CONECTION_DATABASE                : String;
  CONECTION_IP                      : String;
  CONECTION_LOGIN                   : String;
  CONECTION_PASSWORD                : String;
  CONECTION_PORT                    : Integer;
  CONNECTION_ADO_DRIVERNAME         : String;
  CODEPAGE                          : String;

  OCR_BAR_ID : string; //Podvrhnuty kod operace "Osetrovani Clena Rodiny"

  PLAC_VOLNO_BAR_ID : string; // kod operace placene volno - Alcomex

  DOCH_BREAK_ROUND    : boolean;  //zaokrouhlovani prestavky

  OPERATION_PRESTAVKA : string;   //bar_id prestavky

  ROUND_DOCHAZKA_HODNOTY: integer;

    Sklad_Use_Akt_Dat    : boolean;   // použít
  Sklad_Fin_Akt_Dat    : TDate;     // omezit do

  USE_SKLADOVE_POZICE : boolean;

  SKLAD_MATERIAL_PRODEJNI_CENA_MARZE : integer;

  MASKA_INVENTURA : TMaska;

  MENA_ZKRATKA : string;

  LICENCE_NAME                      : String;
  LICENCE_ADRESS                    : String;
  LICENCE_COPYRIGHT                 : String;

  LOGO_FIRMY: string;

  POUZIVAT_FASTREPORTS : boolean; //2821

  USER_PRINT_REPORT_EDIT_ORIGINAL: boolean;

  LOGED_USER_PRV_ARRAY              : array[1..32] of Int64;

  GDPR_AKTIVNI: Boolean;
  LOGED_USER_GDPR_GROUP             : Integer;

  POHODA                            : Boolean;

  IMPORT_MONEY_ADRESAR: String;
  IMPORT_MONEY_PODMINKA_KODY: array of string;
  MONEY_VYCHOZI_STAV_ID: Integer;
  defaultColumnsCaptionList : TDictionary<string,TAgColumn>;

  EFEKTIVITA_ORDER_WORK : Boolean;

  MASKA_ZAKAZEK, MASKA_ZAKAZEK_DEFAULT, MASKA_SKLAD_MATERIAL: TMaska;
  ORDER_MASK                        : Integer;
  MASKA_VYKRES : TMaska;
  MASKA_VYROBNI_PRIKAZ : TMaska;
  MASKA_PRIJEMKY: TMaska;
  MASKA_VYDEJKY: TMaska;
  MASKA_SERIOVA_CISLA : TMaska;
  MASKA_ZAKAZNICI : TMaska;

  USER_OV_CISELNARADA : Integer;
  USER_OP_CISELNARADA : Integer;
  USER_DL_CISELNARADA : Integer;
  USER_PRIJEMKY_CISELNARADA : Integer;
  USER_VYDEJKY_CISELNARADA : Integer;

  ZALOHA_SOUBOR: String;
  ZALOHA_ODESLANI: Boolean;

  UPDATE_NEW_SERVERS : boolean;

  SKLAD_MATERIAL_VRATKA_POHYB : integer;

  URL_INTRANET : string;

  POPUP_DATUMY: string;

  NEWCOLUMNSELECTOR : boolean;

  NEW_PREPOCET_STAVU : Boolean;

  cas_DEF_SKLAD_PCT : integer;
  cas_DEF_SKLAD_PCT_MONTAZ : integer;
  cas_DEF_SKLAD_PCT_SPRAVA : integer;

  VYKLADNOVAT_MAT_S_PEVNA_CENA      : integer;
  OBJEDNAVKY_PREBIRAT_CENU : Integer;


  UUID          : Array[0..31] of AnsiChar;
  ZAK_BEZ_MARZE : Integer;

  ORDEREDITOWNCALCSCRIPT : string;

  ORDER_PODZAKAZKA_SUFIX_FROM_DEFAULT : Boolean;

  SHOW_COMPONENTS_NAME : Boolean;

  ORDER_UKON1_POPIS,ORDER_UKON2_POPIS,ORDER_UKON3_POPIS,ORDER_UKON4_POPIS,ORDER_UKON5_POPIS,ORDER_UKON6_POPIS,ORDER_UKON7_POPIS,ORDER_UKON8_POPIS,ORDER_UKON9_POPIS,ORDER_UKON10_POPIS,ORDER_UKON11_POPIS,ORDER_UKON12_POPIS,ORDER_UKON13_POPIS,ORDER_UKON14_POPIS,ORDER_UKON15_POPIS: string;

  ORD_ONLY_WORK_DAY_LEFT : boolean; //2719

  ZMENA_STAVU_ID: integer;

  DEFAULT_ORDER_TYP                 : Integer;
  idStavuSkupinyAktivni : string;

  NOVA_UKOL_MZDA: Boolean;

  WORKER_MZDA_DEFAULT : Extended;

  USER_RIGHTS_SPECIAL : Boolean;

  ORDERWORK_NEW_PORADI_ENABLED : Boolean;

  ORDER_WORK_OPERATION_FIX : boolean;

  EASY_VERSION_SHOWMODULE : Boolean;

  NoCalculatedQryOrder : boolean;

  LOGED_ACCES                       : Integer;
  LASER_AUTOCHECK                   : Boolean;
  COM_PORT                          : String;
  COM_STOP_BITS                     : Integer;
  COM_DATA_BITS                     : Integer;

  DASHBOARD_PANEL1, DASHBOARD_PANEL2, DASHBOARD_PANEL3, DASHBOARD_PANEL4, DASHBOARD_PANEL5, DASHBOARD_PANEL6 : string;
  DASHBOARD_EX1, DASHBOARD_EX2, DASHBOARD_EX3, DASHBOARD_EX4 : string;
  DASHBOARD_EX1_CAPTION, DASHBOARD_EX2_CAPTION, DASHBOARD_EX3_CAPTION, DASHBOARD_EX4_CAPTION : string;

  PRIJEMKY_NAZEV_DOPLN_FIRMOU : Boolean;

  FAKTURA_FIRMA                     : String;

  ORDER_ROZDEL_DEFSKUPINASTAVU      : string;

  ORDER_PREVOD_CHECK_MJ : boolean;

  OBJEDNAVKY_NESESKUPOVAT_MATERIAL : Boolean;

  Sklad_Auto_Posun_Dat : boolean;
  Autoposun_O_opcet_dni : integer;  // posunout o počet dní
  Kontrola_Min_Bez_Auto_Pusunu : integer; //pokud není posun, tak kontrola konce

  SKLAD_MATERIAL_MORE_CODES : boolean;

  DODACI_LIST_VYTVORIT_VYDEJKU : boolean;

  UNIVERZAL_LIST_DX : Boolean;

  VYHODNOCENI_ZAKAZEK_ENABLED : boolean;

  OBJPRIJATE_PREDVYPLNIT_CENU_POTVRZENOU : Boolean;


  TMPPID : string;
  //2024-02-21 PP #14837
  SKLAD_VICE_SKLADU_HIDE: boolean;
  //2024-09-10 PP #15460
  READDATA_VYBER_DATUM_CAS: boolean;
  //2024-12-16 PP #16914
  CISLO_OBJEDNAVKY_AKTUALNI_STAV: boolean;
  fCS : TCriticalSection;

  SCM_ZAPISOVAT_POZNAMKU : Boolean;

  CALCUTATING : integer;

  ORDER_DEFAULT_STAV : string;

  BGS_NO_CHECK : boolean;

  Print_Directory_Suffix            : String;

  TESS                              : Boolean;
  KOVOMAX                           : Boolean;
  TRIDIC                            : Boolean;

  USE_UNICODE                       : Boolean;

  LicenceURLs : TLicenceURL;

  //2025-10-07 PP #18763
  GRIDY_RADKY_RUZNE_BARVY: boolean;

  WORKER_KOEFICIENT_DEFAULT : Extended;
  DEFAULTNI_MARZE : double;
  SKLAD_DEF_UNIT : integer;

  //EMISTR_USER_SETTINGS_StoreImpl  : TUserSettingsStore;
  //EMISTR_USER_SETTINGS_Store      : IUserSettings;
  //EMISTR_USER_SETTINGS            : TUserSettingsLegacy;
  OBJPRIJATE_MNOZSTVI_NA_DL : integer;

 //2025-11-28 PP #19244
  CALENDAR_STATE        : string;


const
  FIntervalTyp: array [0..2] of string = ('Za časové období', 'Za výrobu (odpracovaný čas a měrné jednotky)', 'Kombinace za časové období a za výrobu');
  FIntervalTypSufix: array [0..2] of string = ('', '', ' (který nastane dříve)');
  FObdobiTyp: array [0..2] of string = ('den', 'měsíc', 'rok');

type
  TDateRange =
    (dr_undefined, dr_yesterday, dr_today, dr_last7days, dr_actualWeek, dr_lastWeek,
     dr_last14days, dr_last30days, dr_actualMonth, dr_lastMonth, dr_last90days,
     dr_actualQuarter, dr_lastQuarter, dr_last365days, dr_actualYear, dr_lastYear);

type
  TCharSet = set of Ansichar;

const
  TxtDateRange : array [TDateRange] of String = (
    '',
    message1798,
    message1799,
    message1800,
    message1801,
    message1802,
    message1803,
    message1804,
    message1805,
    message1806,
    message1807,
    message1808,
    message1809,
    message1810,
    message1811,
    message1812);

type TPolozkyDataSetKind = (dstSQL,dstAurelius,dstMemory);

const cFieldDeprecated = 'deprecated';

implementation

procedure LoadUserSettings(const AUserId: Integer);
begin
  GlobalUserId := AUserId;
  //FreeAndNil(GlobalUserSettings);
  //GlobalUserSettings := TUserSettingsLegacy.Create;
  //TUserSettingsKVAdapter.Load(GlobalUserSettingsStore, GlobalUserId, GlobalUserSettings);
end;

procedure SaveUserSettings;
begin
  //if Assigned(GlobalUserSettings) then
  //  TUserSettingsKVAdapter.Save(GlobalUserSettingsStore, GlobalUserId, GlobalUserSettings);
end;

initialization
  fCS := TCriticalSection.Create;

end.
