Ignore:
Timestamp:
Feb 17, 2021, 9:27:32 PM (3 years ago)
Author:
chronos
Message:
  • Added: Documents section accessible from users panel.
  • Added: Contract model moved to separate module Contract.
  • Added: New action to generate PDF from Contract.
  • Fixed: Allow users to download files only by hash instead of direct id.
  • Added: Support for SHA1 as allowed mysql function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Customer/Customer.php

    r899 r901  
    3737        'SupportActivity' => array('Type' => 'TSupportActivityListCustomer', 'Caption' => 'Zákaznická podpora', 'Default' => ''),
    3838        'Consumption' => array('Type' => 'TCustomerStockSerialNumber', 'Caption' => 'Spotřeba zařízení', 'Default' => ''),
     39        'Contract' => array('Type' => 'TContract', 'Caption' => 'Smlouva', 'Default' => '', 'Null' => true),
    3940        'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true),
    4041        'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true),
     
    196197      ),
    197198    ));
     199    $this->System->FormManager->RegisterFormType('TCustomerListContract', array(
     200      'Type' => 'ManyToOne',
     201      'Table' => 'Member',
     202      'Id' => 'Id',
     203      'Ref' => 'Contract',
     204      'Filter' => '1',
     205    ));
     206
     207    $this->System->RegisterPage(['user', 'dokumenty'], 'PageCustomerDocuments');
    198208
    199209    ModuleIS::Cast(Core::Cast($this->System)->GetModule('IS'))->RegisterDashboardItem('Customer',
     
    211221    $Output .= ' platících:'.$DbRow['0'].'<br/>';
    212222
     223    return $Output;
     224  }
     225}
     226
     227class PageCustomerDocuments extends Page
     228{
     229  function __construct(System $System)
     230  {
     231    parent::__construct($System);
     232    $this->FullTitle = 'Dokumenty klienta';
     233    $this->ShortTitle = 'Dokumenty';
     234    $this->ParentClass = 'PageUser';
     235  }
     236
     237  function Show(): string
     238  {
     239    $Output = '<br/><div><strong>Dostupné dokumenty:</strong></div><br/>';
     240
     241    $User = &ModuleUser::Cast($this->System->GetModule('User'))->User;
     242
     243    // Determine which customer should be displayed
     244    if (array_key_exists('i', $_GET))
     245    {
     246      if (!$User->CheckPermission('Finance', 'Manage')) return 'Nemáte oprávnění';
     247      $CustomerId = $_GET['i'];
     248    } else
     249    {
     250      if (!$User->CheckPermission('Customer', 'DisplayCustomerDocuments')) return 'Nemáte oprávnění';
     251      $UserId = ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'];
     252      $DbResult = $this->Database->query('SELECT `Customer` FROM `UserCustomerRel` WHERE `User`='.$UserId.' LIMIT 1');
     253      if ($DbResult->num_rows > 0)
     254      {
     255        $CustomerUserRel = $DbResult->fetch_assoc();
     256        $CustomerId = $CustomerUserRel['Customer'];
     257      } else return $this->SystemMessage('Chyba', 'Nejste zákazníkem');
     258    }
     259
     260    // Load customer info
     261    $DbResult = $this->Database->query('SELECT * FROM `Member` WHERE `Id`='.$CustomerId);
     262    if ($DbResult->num_rows == 1)
     263    {
     264      $Customer = $DbResult->fetch_assoc();
     265    } else return $this->SystemMessage('Položka nenalezena', 'Zákazník nenalezen');
     266
     267    if ($Customer['Contract'] != '')
     268    {
     269      $DbResult = $this->Database->query('SELECT Contract.*, File.Hash AS FileHash, DocumentLineCode.Name AS BillCodeText FROM Contract '.
     270        'LEFT JOIN File ON File.Id=Contract.File '.
     271        'LEFT JOIN DocumentLineCode ON DocumentLineCode.Id=Contract.BillCode '.
     272        'WHERE (Contract.Id='.$Customer['Contract'].')');
     273      if ($DbResult->num_rows > 0)
     274      {
     275        $Contract = $DbResult->fetch_assoc();
     276        if ($Contract['File'] > 0) $Output .= 'Smlouva: <a href="'.$this->System->Link('/file?h='.$Contract['FileHash']).'">'.$Contract['BillCodeText'].'</a><br/>';
     277          else $Output .= 'Smlouva: '.$Contract['BillCodeText'].'<br/>';
     278        $Output .= 'Všeobecné smluvní podmínky: <a href="http://www.zdechov.net/docs/V%C5%A1eobecn%C3%A9%20smluvn%C3%AD%20podm%C3%ADnky.pdf">PDF</a><br/>';
     279      }
     280    }
    213281    return $Output;
    214282  }
Note: See TracChangeset for help on using the changeset viewer.