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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.