Changeset 951


Ignore:
Timestamp:
Jul 12, 2023, 9:02:24 PM (18 months ago)
Author:
chronos
Message:
  • Modified: Improved client contract generation.
  • Fixed: SQL query logging into file.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Core.php

    r922 r951  
    131131      if (isset($this->Config['Web']['LogSQLQuery']))
    132132        $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery'];
     133      if (isset($this->Config['Web']['MeasureQueryDuration']))
     134        $this->Database->MeasureDuration = $this->Config['Web']['MeasureQueryDuration'];
    133135    } catch (Exception $E)
    134136    {
  • trunk/Modules/Contract/Contract.php

    r940 r951  
    2121  function DoStart(): void
    2222  {
    23     $this->DirectoryId = $this->System->Config['Contract']['DirectoryId'];
     23    $this->DirectoryId = Core::Cast($this->System)->Config['Contract']['DirectoryId'];
    2424    $this->System->RegisterPage(['smlouvy', 'generovat'], 'PageContractGenerate');
    25     $this->System->FormManager->RegisterClass('Contract', array(
     25    Core::Cast($this->System)->FormManager->RegisterClass('Contract', array(
    2626      'Title' => 'Smlouvy',
    2727      'Table' => 'Contract',
     
    4242      )
    4343    ));
    44     $this->System->FormManager->RegisterFormType('TContract', array(
     44    Core::Cast($this->System)->FormManager->RegisterFormType('TContract', array(
    4545      'Type' => 'Reference',
    4646      'Table' => 'Contract',
     
    129129    $this->FontSize = 10;
    130130
    131     $DbResult = $this->Database->select('Subject', '*', '`Id`='.$this->System->Config['Finance']['MainSubjectId']);
     131    $DbResult = $this->Database->select('Subject', '*', '`Id`='.Core::Cast($this->System)->Config['Finance']['MainSubjectId']);
    132132    if ($DbResult->num_rows > 0)
    133133    {
     
    159159    } else die('Customer not found.');
    160160
     161    $PrefixMultiplier = new PrefixMultiplier();
     162    $ServiceType = '';
     163    $Price = 0;
     164    $MaxSpeed = '';
     165    $MinSpeed = '';
    161166    $DbResult = $this->Database->query('SELECT * FROM ServiceCustomerRel '.
    162167      'LEFT JOIN Service ON Service.Id=ServiceCustomerRel.Service '.
    163168      'WHERE `ServiceCustomerRel`.`Customer`='.$Customer['Id'].' ');
    164169    if ($DbResult->num_rows > 0)
    165     {
    166       $Service = $DbResult->fetch_assoc();
    167     } else die('Service not found.');
    168     $ServiceType = $Service['Name'];
    169     $Price = $Service['Price'];
     170    {   
     171      while ($Service = $DbResult->fetch_assoc())
     172      {
     173        if ($ServiceType != '') $ServiceType .= ', ';
     174        $ServiceType .= $Service['Name'];
     175        $Price += $Service['Price'];
     176        if ($Service['InternetSpeedMax'] != 0)
     177          $MaxSpeed = $PrefixMultiplier->Add($Service['InternetSpeedMax'], 'bit/s');
     178        if ($Service['InternetSpeedMin'] != 0)
     179          $MinSpeed = $PrefixMultiplier->Add($Service['InternetSpeedMin'], 'bit/s');
     180      }
     181    }
    170182
    171183    $DbResult = $this->Database->query('SELECT NetworkInterface.LocalIP, NetworkInterface.MAC FROM NetworkDevice '.
     
    175187    {
    176188      $NetworkInterface = $DbResult->fetch_assoc();
    177     } else die('NetworkDevice not found.');
    178 
    179     $PrefixMultiplier = new PrefixMultiplier();
    180     $MaxSpeed = $PrefixMultiplier->Add($Service['InternetSpeedMax'], 'bit/s');
    181     $MinSpeed = $PrefixMultiplier->Add($Service['InternetSpeedMin'], 'bit/s');
    182     $IpAddress = $NetworkInterface['LocalIP'];
    183     $MacAddress = $NetworkInterface['MAC'];
    184 
    185     $DbResult = $this->Database->query('SELECT * FROM NetworkSubnet '.
     189      $IpAddress = $NetworkInterface['LocalIP'];
     190      $MacAddress = $NetworkInterface['MAC'];
     191
     192      $DbResult = $this->Database->query('SELECT * FROM NetworkSubnet '.
    186193      'WHERE CompareNetworkPrefix(INET_ATON("'.$IpAddress.'"), INET_ATON(`AddressRange`), `Mask`)');
    187     if ($DbResult->num_rows > 0)
    188     {
    189       $Subnet = $DbResult->fetch_assoc();
    190       $DefaultGateway = $Subnet['Gateway'];
    191       $NetworkAddressIPv4 = new NetworkAddressIPv4();
    192       $NetworkAddressIPv4->Prefix = $Subnet['Mask'];
    193       $NetworkAddressIPv4->Address = $NetworkAddressIPv4->GetNetMask();
    194       $NetMask = $NetworkAddressIPv4->AddressToString();
    195     } else die('Subnet not found.');
    196 
    197     $Interface = 'Ethernet';
    198     $PrimaryDNS = '10.145.64.8';
     194      if ($DbResult->num_rows > 0)
     195      {
     196        $Subnet = $DbResult->fetch_assoc();
     197        $DefaultGateway = $Subnet['Gateway'];
     198        $NetworkAddressIPv4 = new NetworkAddressIPv4();
     199        $NetworkAddressIPv4->Prefix = $Subnet['Mask'];
     200        $NetworkAddressIPv4->Address = $NetworkAddressIPv4->GetNetMask();
     201        $NetMask = $NetworkAddressIPv4->AddressToString();
     202      } else die('Subnet not found.');
     203      $Interface = 'Ethernet';
     204      $PrimaryDNS = '10.145.64.8';
     205    } else
     206    {
     207      $IpAddress = '';
     208      $MacAddress = '';
     209      $DefaultGateway = '';
     210      $NetMask = '';
     211      $Interface = '';
     212      $PrimaryDNS = '';
     213    }
    199214
    200215    $VarSymbol = $Subject['Id'];
    201216    $DbResult = $this->Database->query('SELECT FinanceBankAccount.*, CONCAT(FinanceBankAccount.Number, "/", FinanceBank.Code) AS NumberFull FROM FinanceBankAccount '.
    202217      'JOIN FinanceBank ON FinanceBank.Id=FinanceBankAccount.Bank '.
    203       'WHERE (FinanceBankAccount.`Subject`='.$this->System->Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
     218      'WHERE (FinanceBankAccount.`Subject`='.Core::Cast($this->System)->Config['Finance']['MainSubjectId'].') AND (FinanceBankAccount.`Use`=1)');
    204219    if ($DbResult->num_rows > 0)
    205220    {
     
    216231    $BankAccount = $SupplierBankAccount['NumberFull'];
    217232
    218     $DbResult = $this->Database->select('Member', '*', '`Subject`='.$this->System->Config['Finance']['MainSubjectId']);
     233    $DbResult = $this->Database->select('Member', '*', '`Subject`='.Core::Cast($this->System)->Config['Finance']['MainSubjectId']);
    219234    if ($DbResult->num_rows > 0)
    220235    {
     
    224239    $DbResult = $this->Database->query('SELECT Contact.Value AS Phone FROM User '.
    225240      'LEFT JOIN Contact ON Contact.User=User.ID AND Contact.Category=1 '.
    226       'WHERE User.Id='.$SupplierMember['ResponsibleUser']);
     241      'WHERE User.Id='.$SupplierMember['ResponsibleUser'].' ORDER BY `Contact`.`Receive` DESC');
    227242    if ($DbResult->num_rows > 0)
    228243    {
     
    233248    $DbResult = $this->Database->query('SELECT Contact.Value AS Phone FROM User '.
    234249      'LEFT JOIN Contact ON Contact.User=User.ID AND Contact.Category=1 '.
    235       'WHERE User.Id='.$Customer['ResponsibleUser']);
     250      'WHERE User.Id='.$Customer['ResponsibleUser'].' ORDER BY `Contact`.`Receive` DESC');
    236251    if ($DbResult->num_rows > 0)
    237252    {
     
    243258    $DbResult = $this->Database->query('SELECT Email, Contact.Value AS ContactEmail FROM User '.
    244259      'LEFT JOIN Contact ON Contact.User=User.ID AND Contact.Category=4 '.
    245       'WHERE User.Id='.$Customer['ResponsibleUser']);
     260      'WHERE User.Id='.$Customer['ResponsibleUser'].' ORDER BY `Contact`.`Receive` DESC');
    246261    if ($DbResult->num_rows > 0)
    247262    {
     
    260275    $SupplierPsc = $Supplier['AddressPSC'];
    261276    $SupplierIC = $Supplier['IC'];
    262     $SupplierDIC = 'neplátce DPH';
    263 
    264     $Web = '<a href="https://www.zdechov.net/">www.zdechov.net</a>';
     277    if ($Supplier['PayVAT'] == 1) $SupplierDIC = 'plátce DPH';
     278      else $SupplierDIC = 'neplátce DPH';
     279
     280    $Web = '<a href="'.$Supplier['WWW'].'">'.$this->SimplifiedLink($Supplier['WWW']).'</a>';
    265281
    266282    $CustomerName = $Subject['Name'];
     
    302318      '<strong>II. Poskytované služby:</strong><br/>'.
    303319      '<table width="100%" border="1">'.
    304       '<tr><td width="50%">Zvolený typ (tarif) služby:</td><td>'.NotBlank($ServiceType).'</td></tr>'.
     320      '<tr><td width="50%">Zvolené služby:</td><td>'.NotBlank($ServiceType).'</td></tr>'.
    305321      '</table>'.
    306322      '<br/>'.
     
    316332      'Poplatky a pravidelné platby budou na základě této smlouvy hrazeny Odběratelem na bankovní účet Poskytovatele bankovním převodem, nebo složenkou, v uvedené výši a s uvedenou frekvencí. Jako VS bude uvedeno přidělené číslo. V případě prodlení s platbou mohou být uplatněny sankce, či služba pozastavena, nebo zrušena (dle Ceníku a Všeobecných smluvních podmínek).<br/>'.
    317333      '<table width="100%">'.
    318       '<tr><td width="25%">Cena služby:</td><td width="25%">'.NotBlank($Price).' Kč</td><td width="25%">Číslo účtu:</td><td width="25%">'.NotBlank($BankAccount).'</td></tr>'.
     334      '<tr><td width="25%">Cena služeb:</td><td width="25%">'.NotBlank($Price).' Kč</td><td width="25%">Číslo účtu:</td><td width="25%">'.NotBlank($BankAccount).'</td></tr>'.
    319335      '<tr><td>Pronájem zařízení:</td><td>0 Kč</td><td>Variabilní symbol:</td><td>'.NotBlank($VarSymbol).'</td></tr>'.
    320336      '<tr><td>Frekvence platby:</td><td>'.NotBlank($PaymentPeriod).'</td><td></td><td></td></tr>'.
     
    337353      '</body></html>';
    338354    return $Output;
     355  }
     356
     357  function SimplifiedLink(string $Link): string
     358  {
     359    if (substr($Link, 0, 8) == 'https://') $Link = substr($Link, 8);
     360    if (substr($Link, 0, 7) == 'http://') $Link = substr($Link, 7);
     361    return $Link;
    339362  }
    340363}
  • trunk/Modules/Subject/Subject.php

    r914 r951  
    4444        'BankAccounts' => array('Type' => 'TFinanceBankAccountListSubject', 'Caption' => 'Bankovní účty', 'Default' => ''),
    4545        'Contracts' => array('Type' => 'TContractListSubject', 'Caption' => 'Smlouvy', 'Default' => ''),
     46        'Contacts' => array('Type' => 'TContactListSubject', 'Caption' => 'Kontakty', 'Default' => ''),
    4647      ),
    4748    ));
     
    5657      'Type' => 'ManyToOne',
    5758      'Table' => 'Contract',
     59      'Id' => 'Id',
     60      'Ref' => 'Subject',
     61      'Filter' => '1',
     62    ));
     63    $this->System->FormManager->RegisterFormType('TContactListSubject', array(
     64      'Type' => 'ManyToOne',
     65      'Table' => 'Contact',
    5866      'Id' => 'Id',
    5967      'Ref' => 'Subject',
  • trunk/Modules/User/User.php

    r916 r951  
    5050    Core::Cast($this->System)->RegisterPage(['user'], 'PageUser');
    5151    Core::Cast($this->System)->RegisterPageBarItem('Top', 'User', array($this, 'TopBarCallback'));
    52     $this->System->FormManager->RegisterClass('UserLogin', array(
     52    Core::Cast($this->System)->FormManager->RegisterClass('UserLogin', array(
    5353      'Title' => 'Přihlášení uživatele',
    5454      'SubmitText' => 'Přihlásit',
     
    6060      ),
    6161    ));
    62     $this->System->FormManager->RegisterClass('UserOptions', array(
     62    Core::Cast($this->System)->FormManager->RegisterClass('UserOptions', array(
    6363      'Title' => 'Základní nastavení',
    6464      'Table' => 'User',
     
    7272      ),
    7373    ));
    74     $this->System->FormManager->RegisterClass('UserRegister', array(
     74    Core::Cast($this->System)->FormManager->RegisterClass('UserRegister', array(
    7575      'Title' => 'Registrace uživatele',
    7676      'SubmitText' => 'Registrovat',
     
    8484      ),
    8585    ));
    86     $this->System->FormManager->RegisterClass('PasswordRecovery', array(
     86    Core::Cast($this->System)->FormManager->RegisterClass('PasswordRecovery', array(
    8787      'Title' => 'Obnova hesla',
    8888      'SubmitText' => 'Obnovit',
     
    9393      ),
    9494    ));
    95     $this->System->FormManager->RegisterClass('APIToken', array(
     95    Core::Cast($this->System)->FormManager->RegisterClass('APIToken', array(
    9696      'Title' => 'Přístupový token',
    9797      'Table' => 'APIToken',
     
    101101      ),
    102102    ));
    103     $this->System->FormManager->RegisterClass('User', array(
     103    Core::Cast($this->System)->FormManager->RegisterClass('User', array(
    104104      'Title' => 'Uživatelé',
    105105      'Table' => 'User',
     
    120120      ),
    121121    ));
    122     $this->System->FormManager->RegisterClass('PermissionUserAssignment', array(
     122    Core::Cast($this->System)->FormManager->RegisterClass('PermissionUserAssignment', array(
    123123      'Title' => 'Oprávnění uživatelů',
    124124      'Table' => 'PermissionUserAssignment',
     
    129129      ),
    130130    ));
    131     $this->System->FormManager->RegisterClass('PermissionGroup', array(
     131    Core::Cast($this->System)->FormManager->RegisterClass('PermissionGroup', array(
    132132      'Title' => 'Skupiny oprávnění',
    133133      'Table' => 'PermissionGroup',
     
    138138      ),
    139139    ));
    140     $this->System->FormManager->RegisterClass('PermissionGroupAssignment', array(
     140    Core::Cast($this->System)->FormManager->RegisterClass('PermissionGroupAssignment', array(
    141141      'Title' => 'Přiřazení skupin oprávnění',
    142142      'Table' => 'PermissionGroupAssignment',
     
    147147      ),
    148148    ));
    149     $this->System->FormManager->RegisterClass('PermissionOperation', array(
     149    Core::Cast($this->System)->FormManager->RegisterClass('PermissionOperation', array(
    150150      'Title' => 'Operace oprávnění',
    151151      'Table' => 'PermissionOperation',
     
    158158      ),
    159159    ));
    160     $this->System->FormManager->RegisterFormType('TUser', array(
     160    Core::Cast($this->System)->FormManager->RegisterFormType('TUser', array(
    161161      'Type' => 'Reference',
    162162      'Table' => 'User',
     
    165165      'Filter' => '1',
    166166    ));
    167     $this->System->FormManager->RegisterFormType('TPermissionGroup', array(
     167    Core::Cast($this->System)->FormManager->RegisterFormType('TPermissionGroup', array(
    168168      'Type' => 'Reference',
    169169      'Table' => 'PermissionGroup',
     
    172172      'Filter' => '1',
    173173    ));
    174     $this->System->FormManager->RegisterFormType('TPermissionGroupAssignment', array(
     174    Core::Cast($this->System)->FormManager->RegisterFormType('TPermissionGroupAssignment', array(
    175175      'Type' => 'Reference',
    176176      'Table' => 'PermissionGroupAssignment',
     
    179179      'Filter' => '1',
    180180    ));
    181     $this->System->FormManager->RegisterFormType('TPermissionOperation', array(
     181    Core::Cast($this->System)->FormManager->RegisterFormType('TPermissionOperation', array(
    182182      'Type' => 'Reference',
    183183      'Table' => 'PermissionOperation',
  • trunk/Packages/Common/Database.php

    r929 r951  
    4343  public bool $ShowSQLQuery;
    4444  public bool $LogSQLQuery;
     45  public bool $MeasureDuration;
    4546  public string $LogFile;
    4647  public string $Database;
     
    5657    $this->ShowSQLQuery = false;
    5758    $this->LogSQLQuery = false;
     59    $this->MeasureDuration = false;
    5860    $this->LogFile = dirname(__FILE__).'/../../Query.log';
    5961    $this->Database = '';
     
    9395  {
    9496    if (!$this->Connected()) throw new Exception(T('Not connected to database'));
    95     if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float();
     97    $Duration = '';
     98    if ($this->MeasureDuration)
     99    {
     100      $QueryStartTime = microtime_float();
     101    }
    96102    $this->LastQuery = $Query;
    97     if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
    98     {
    99       $Time = round(microtime_float() - $QueryStartTime, 4);
    100       $Duration = ' ; '.$Time. ' s';
    101     }
    102     if (($this->LogSQLQuery == true) and ($Time != 0))
    103       file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    104     if ($this->ShowSQLQuery == true)
    105       echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; '.
    106       'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
    107103    $Result = new DatabaseResult();
    108104    $Statement = $this->PDO->query($Query);
     
    119115        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
    120116        throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query);
     117    }
     118    if ($this->MeasureDuration)
     119    {
     120      $Time = round(microtime_float() - $QueryStartTime, 4);
     121      $Duration = ' ; '.$Time. ' s';
     122    }
     123    if ($this->ShowSQLQuery == true)
     124    {
     125       echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; '.
     126      'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
     127    }
     128    if ($this->LogSQLQuery == true)
     129    {
     130      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    121131    }
    122132    return $Result;
Note: See TracChangeset for help on using the changeset viewer.