Name = 'Customer'; $this->Version = '1.0'; $this->Creator = 'Chronos'; $this->License = 'GNU/GPLv3'; $this->Description = 'Customer management'; $this->Dependencies = array(ModuleUser::GetName(), ModuleFinance::GetName()); $this->Models = array(Member::GetClassName(), MemberPayment::GetClassName(), SupportActivity::GetClassName(), ServiceCategory::GetClassName(), Service::GetClassName(), ServiceCustomerRel::GetClassName(), UserCustomerRel::GetClassName(), AddressPlace::GetClassName()); } function DoStart(): void { $this->System->FormManager->RegisterClass('Member', array( 'Title' => 'Zákazníci', 'Table' => 'Member', 'DefaultSortColumn' => 'Name', 'Items' => array( 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''), 'ResponsibleUser' => array('Type' => 'TUser', 'Caption' => 'Zodpovědný uživatel', 'Default' => ''), 'Subject' => array('Type' => 'TSubject', 'Caption' => 'Subjekt', 'Default' => ''), 'AddressPlace' => array('Type' => 'TAddressPlace', 'Caption' => 'Adresní místo', 'Default' => '', 'Null' => true), 'FamilyMemberCount' => array('Type' => 'String', 'Caption' => 'Bydlících osob', 'Default' => '0', 'Suffix' => 'osob'), 'MembershipDate' => array('Type' => 'Date', 'Caption' => 'Datum členství', 'Default' => ''), 'BillingPeriod' => array('Type' => 'TFinanceBillingPeriod', 'Caption' => 'Fakturační období aktuální', 'Default' => ''), 'BillingPeriodLastDate' => array('Type' => 'Date', 'Caption' => 'Datum poslední fakturace', 'Default' => ''), 'Blocked' => array('Type' => 'Boolean', 'Caption' => 'Blokování', 'Default' => '0'), 'PayDay' => array('Type' => 'Integer', 'Caption' => 'Den placení', 'Default' => '1', 'Suffix' => 'den'), 'Devices' => array('Type' => 'TDeviceList', 'Caption' => 'Registrovaná zařízení', 'Default' => ''), 'UserRel' => array('Type' => 'TUserCustomerRelListCustomer', 'Caption' => 'Přiřazení uživatelé', 'Default' => ''), 'ServiceRel' => array('Type' => 'TServiceCustomerRelListCustomer', 'Caption' => 'Placené služby', 'Default' => ''), 'SupportActivity' => array('Type' => 'TSupportActivityListCustomer', 'Caption' => 'Zákaznická podpora', 'Default' => ''), 'Consumption' => array('Type' => 'TCustomerStockSerialNumber', 'Caption' => 'Spotřeba zařízení', 'Default' => ''), 'Contract' => array('Type' => 'TContract', 'Caption' => 'Smlouva', 'Default' => '', 'Null' => true), 'PaymentEmailTime' => array('Type' => 'DateTime', 'Caption' => 'Čas platebního emailu', 'Default' => 'now', 'Null' => true, 'NotInList' => true), 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true, 'NotInList' => true), 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true), 'ChangeReplaceId' => array('Type' => 'TMember', 'Caption' => 'Změna - položka', 'Default' => '0', 'Null' => true, 'NotInList' => true), ), 'ItemActions' => array( array('Caption' => 'Klientská sekce', 'URL' => '/finance/platby/?i=#RowId'), array('Caption' => 'Email s vyúčtováním do fronty', 'URL' => '/finance/sprava/?Operation=SendPaymentEmail&i=#RowId'), ), )); $this->System->FormManager->RegisterClass('MemberPayment', array( 'Title' => 'Placení zákazníků', 'Table' => 'MemberPayment', 'Items' => array( 'Member' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => '', 'ReadOnly' => true), 'MonthlyTotal' => array('Type' => 'Integer', 'Caption' => 'Celkem měsíčně', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true), 'MonthlyInternet' => array('Type' => 'Integer', 'Caption' => 'Internet měsíčně', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true), 'MonthlyConsumption' => array('Type' => 'Integer', 'Caption' => 'Spotřeba měsíčně', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true), 'MonthlyPlus' => array('Type' => 'Integer', 'Caption' => 'Měsíčně plus', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true), 'Cash' => array('Type' => 'Integer', 'Caption' => 'Kredit', 'Default' => '', 'Suffix' => 'Kč', 'ReadOnly' => true), ), 'Actions' => array( array('Caption' => 'Přepočítat', 'URL' => '/finance/sprava/?Operation=Recalculate'), ), )); $this->System->FormManager->RegisterFormType('TMember', array( 'Type' => 'Reference', 'Table' => 'Member', 'Id' => 'Id', 'Name' => 'Name', 'Filter' => '1', )); $this->System->FormManager->RegisterClass('Service', array( 'Title' => 'Služby', 'Table' => 'Service', 'DefaultSortColumn' => 'Name', 'Items' => array( 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''), 'Category' => array('Type' => 'TServiceCategory', 'Caption' => 'Skupina', 'Default' => '', 'Null' => true), 'Price' => array('Type' => 'Integer', 'Caption' => 'Cena', 'Default' => '0', 'Suffix' => 'Kč'), 'VAT' => array('Type' => 'TFinanceVATType', 'Caption' => 'Sazba DPH', 'Default' => '0', 'Suffix' => ''), 'CustomerCount' => array('Type' => 'Integer', 'Caption' => 'Počet zákazníků', 'Default' => '', 'ReadOnly' => true, 'SQL' => '(SELECT COUNT(*) FROM `ServiceCustomerRel` LEFT JOIN `Member` ON `Member`.`Id`=`ServiceCustomerRel`.`Customer` WHERE (`ServiceCustomerRel`.`Service`=#Id) AND (`Member`.`Blocked`=0))'), 'Public' => array('Type' => 'Boolean', 'Caption' => 'Veřejné', 'Default' => ''), 'InternetSpeedMin' => array('Type' => 'Integer', 'Caption' => 'Min. rychlost internetu', 'Default' => '0', 'Suffix' => 'bit/s'), 'InternetSpeedMax' => array('Type' => 'Integer', 'Caption' => 'Max. rychlost internetu', 'Default' => '0', 'Suffix' => 'bit/s'), 'InternetSpeedBonus' => array('Type' => 'Integer', 'Caption' => 'Bonusová rychlost internetu', 'Default' => '0', 'Suffix' => 'bit/s'), 'UploadAsymmetry' => array('Type' => 'Integer', 'Caption' => 'Asymetrie odesílání', 'Default' => '1'), 'Memory' => array('Type' => 'Integer', 'Caption' => 'Paměť', 'Default' => '0', 'Suffix' => 'GB'), 'MemorySwap' => array('Type' => 'Integer', 'Caption' => 'Odkládací oddíl', 'Default' => '0', 'Suffix' => 'GB'), 'Storage' => array('Type' => 'Integer', 'Caption' => 'Úložiště', 'Default' => '0', 'Suffix' => 'GB'), 'CPUCount' => array('Type' => 'Integer', 'Caption' => 'Počet jader', 'Default' => '0', 'Suffix' => ''), 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true, 'NotInList' => true), 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true), 'ChangeReplaceId' => array('Type' => 'TService', 'Caption' => 'Změna - položka', 'Default' => '', 'Null' => true, 'NotInList' => true), 'CustomerRel' => array('Type' => 'TServiceCustomerRelListService', 'Caption' => 'Placení zákazníky', 'Default' => ''), 'TvRel' => array('Type' => 'TServiceTvRelListService', 'Caption' => 'TV kanály', 'Default' => ''), ), )); $this->System->FormManager->RegisterClass('ServiceCategory', array( 'Title' => 'Kategorie služeb', 'Table' => 'ServiceCategory', 'Items' => array( 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''), 'Items' => array('Type' => 'TServiceListServiceCategory', 'Caption' => 'Služby', 'Default' => ''), ), )); $this->System->FormManager->RegisterClass('ServiceCustomerRel', array( 'Title' => 'Služby zákazníka', 'Table' => 'ServiceCustomerRel', 'Items' => array( 'Service' => array('Type' => 'TService', 'Caption' => 'Služba', 'Default' => ''), 'ServicePrice' => array('Type' => 'Integer', 'Caption' => 'Cena', 'Default' => '', 'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => 'SELECT `Service`.`Price` FROM `Service` WHERE `Service`.`Id`=`TX`.`Service`'), 'Customer' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => ''), 'SpeedLimit' => array('Type' => 'TNetworkSpeedLimit', 'Caption' => 'Omezení rychlosti', 'Default' => null, 'Null' => true), 'Devices' => array('Type' => 'TNetworkDeviceListService', 'Caption' => 'Zařízení', 'Default' => ''), 'Subnets' => array('Type' => 'TNetworkSubnetListService', 'Caption' => 'Podsítě', 'Default' => ''), 'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true, 'NotInList' => true), 'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true, 'NotInList' => true), 'ChangeReplaceId' => array('Type' => 'TServiceCustomerRel', 'Caption' => 'Změna - položka', 'Default' => '', 'Null' => true, 'NotInList' => true), ), )); $this->System->FormManager->RegisterClass('AddressPlace', array( 'Title' => 'Adresní místo', 'Table' => 'AddressPlace', 'DefaultSortColumn' => 'HouseNumber', 'DefaultSortOrder' => 1, 'Items' => array( 'Town' => array('Type' => 'String', 'Caption' => 'Město', 'Default' => ''), 'Street' => array('Type' => 'String', 'Caption' => 'Ulice', 'Default' => ''), 'HouseNumber' => array('Type' => 'Integer', 'Caption' => 'Číslo domu', 'Default' => ''), 'HouseNumberType' => array('Type' => 'THouseNumberType', 'Caption' => 'Typ čísla', 'Default' => ''), 'Psc' => array('Type' => 'Integer', 'Caption' => 'PSČ', 'Default' => ''), 'RuianCode' => array('Type' => 'Integer', 'Caption' => 'Kód Ruian', 'Default' => ''), 'Customers' => array('Type' => 'TCustomerListAddressPlace', 'Caption' => 'Zákazníci', 'Default' => '', 'Null' => true, 'NotInList' => true), ), )); $this->System->FormManager->RegisterFormType('TAddressPlace', array( 'Type' => 'Reference', 'Table' => 'AddressPlace', 'Id' => 'Id', 'Name' => 'CONCAT_WS(" ", NULLIF(AddressPlace.Town, ""), REPLACE(REPLACE(AddressPlace.HouseNumberType, "0", ""), 1, "e.v."), NULLIF(AddressPlace.HouseNumber, ""))', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('THouseNumberType', array( 'Type' => 'Enumeration', 'States' => array(0 => 'Popisné', 1 => 'Evidenční'), )); $this->System->FormManager->RegisterFormType('TCustomerListAddressPlace', array( 'Type' => 'ManyToOne', 'Table' => 'Member', 'Id' => 'Id', 'Ref' => 'AddressPlace', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TServiceCategory', array( 'Type' => 'Reference', 'Table' => 'ServiceCategory', 'Id' => 'Id', 'Name' => 'Name', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TService', array( 'Type' => 'Reference', 'Table' => 'Service', 'Id' => 'Id', 'Name' => 'Name', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TServiceCustomerRel', array( 'Type' => 'Reference', 'Table' => 'ServiceCustomerRel', 'Id' => 'Id', 'Name' => 'Id', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TServiceCustomerRelListCustomer', array( 'Type' => 'ManyToOne', 'Table' => 'ServiceCustomerRel', 'Id' => 'Id', 'Ref' => 'Customer', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TNetworkDeviceListService', array( 'Type' => 'ManyToOne', 'Table' => 'NetworkDevice', 'Id' => 'Id', 'Ref' => 'Service', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TNetworkSubnetListService', array( 'Type' => 'ManyToOne', 'Table' => 'NetworkSubnet', 'Id' => 'Id', 'Ref' => 'Service', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TServiceCustomerRelListService', array( 'Type' => 'ManyToOne', 'Table' => 'ServiceCustomerRel', 'Id' => 'Id', 'Ref' => 'Service', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TServiceTvRelListService', array( 'Type' => 'ManyToOne', 'Table' => 'ServiceTvRel', 'Id' => 'Id', 'Ref' => 'Service', 'Filter' => '1', )); $this->System->FormManager->RegisterFormType('TServiceListServiceCategory', array( 'Type' => 'ManyToOne', 'Table' => 'Service', 'Id' => 'Id', 'Ref' => 'Category', 'Filter' => '1', )); $this->System->FormManager->RegisterClass('SupportActivity', array( 'Title' => 'Zákaznická podpora', 'Table' => 'SupportActivity', 'DefaultSortColumn' => 'Time', 'DefaultSortOrder' => 1, 'Items' => array( 'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''), 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''), 'Customer' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => ''), 'User' => array('Type' => 'TUser', 'Caption' => 'Pracovník', 'Default' => ''), ), )); $this->System->FormManager->RegisterFormType('TSupportActivityListCustomer', array( 'Type' => 'ManyToOne', 'Table' => 'SupportActivity', 'Id' => 'Id', 'Ref' => 'Customer', 'Filter' => '1', )); $this->System->FormManager->RegisterClass('UserCustomerRel', array( 'Title' => 'Vztahy uživatel - zákazník', 'Table' => 'UserCustomerRel', 'Items' => array( 'User' => array('Type' => 'TUser', 'Caption' => 'Uživatel', 'Default' => ''), 'Customer' => array('Type' => 'TMember', 'Caption' => 'Zákazník', 'Default' => ''), ), )); $this->System->FormManager->RegisterFormType('TCustomerListContract', array( 'Type' => 'ManyToOne', 'Table' => 'Member', 'Id' => 'Id', 'Ref' => 'Contract', 'Filter' => '1', )); $this->System->RegisterPage(['user', 'dokumenty'], 'PageCustomerDocuments'); ModuleIS::Cast(Core::Cast($this->System)->GetModule('IS'))->RegisterDashboardItem('Customer', array($this, 'ShowDashboardItem')); } function ShowDashboardItem(): string { $DbResult = $this->Database->select('Member', 'COUNT(*)', '1'); $DbRow = $DbResult->fetch_row(); $Output = 'Zákazníků: registrovaných: '.$DbRow['0'].''; $DbResult = $this->Database->select('Member', 'COUNT(*)', '(`Blocked`=0) AND (`BillingPeriod`<>1)'); $DbRow = $DbResult->fetch_row(); $Output .= ' aktivních: '.$DbRow['0'].''; $DbResult = $this->Database->select('Member', 'COUNT(*)', '(`Blocked`=0) AND (`BillingPeriod`<>1) AND '. '((SELECT SUM(Service.Price) FROM ServiceCustomerRel LEFT JOIN Service ON Service.Id=ServiceCustomerRel.Service WHERE ServiceCustomerRel.Customer=Member.Id) <> 0)'); $DbRow = $DbResult->fetch_row(); $Output .= ' platících: '.$DbRow['0'].'
'; return $Output; } } class PageCustomerDocuments extends Page { function __construct(System $System) { parent::__construct($System); $this->Title = 'Dokumenty'; $this->Description = 'Dokumenty klienta'; $this->ParentClass = 'PageUser'; } function Show(): string { $Output = '
Dostupné dokumenty:

'; $User = &ModuleUser::Cast($this->System->GetModule('User'))->User; // Determine which customer should be displayed if (array_key_exists('i', $_GET)) { if (!$User->CheckPermission('Finance', 'Manage')) return 'Nemáte oprávnění'; $CustomerId = $_GET['i']; } else { if (!$User->CheckPermission('Customer', 'DisplayCustomerDocuments')) return 'Nemáte oprávnění'; $UserId = ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id']; $DbResult = $this->Database->query('SELECT `Customer` FROM `UserCustomerRel` WHERE `User`='.$UserId.' LIMIT 1'); if ($DbResult->num_rows > 0) { $CustomerUserRel = $DbResult->fetch_assoc(); $CustomerId = $CustomerUserRel['Customer']; } else return $this->SystemMessage('Chyba', 'Nejste zákazníkem'); } // Load customer info $DbResult = $this->Database->query('SELECT * FROM `Member` WHERE `Id`='.$CustomerId); if ($DbResult->num_rows == 1) { $Customer = $DbResult->fetch_assoc(); } else return $this->SystemMessage('Položka nenalezena', 'Zákazník nenalezen'); if ($Customer['Contract'] != '') { $DbResult = $this->Database->query('SELECT Contract.*, File.Hash AS FileHash, DocumentLineCode.Name AS BillCodeText FROM Contract '. 'LEFT JOIN File ON File.Id=Contract.File '. 'LEFT JOIN DocumentLineCode ON DocumentLineCode.Id=Contract.BillCode '. 'WHERE (Contract.Id='.$Customer['Contract'].')'); if ($DbResult->num_rows > 0) { $Contract = $DbResult->fetch_assoc(); if ($Contract['File'] > 0) $Output .= 'Smlouva: '.$Contract['BillCodeText'].'
'; else $Output .= 'Smlouva: '.$Contract['BillCodeText'].'
'; $Output .= 'Všeobecné smluvní podmínky: PDF
'; } } return $Output; } } class Member extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddString('Name'); $Desc->AddReference('Subject', Subject::GetClassName()); $Desc->AddReference('ResponsibleUser', User::GetClassName()); $Desc->AddInteger('FamilyMemberCount'); $Desc->AddDate('MembershipDate'); $Desc->AddInteger('MemberState'); $Desc->AddInteger('GPS'); $Desc->AddReference('BillingPeriod', FinanceBillingPeriod::GetClassName()); $Desc->AddDate('BillingPeriodLastDate'); $Desc->AddBoolean('Blocked'); $Desc->AddInteger('PayDay'); $Desc->AddDateTime('PaymentEmailTime'); $Desc->AddChangeAction(); return $Desc; } } class MemberPayment extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddReference('Member', Member::GetClassName()); $Desc->AddFloat('MonthlyTotal'); $Desc->AddFloat('MonthlyInternet'); $Desc->AddFloat('MonthlyConsumption'); $Desc->AddFloat('MonthlyPlus'); $Desc->AddFloat('Cash'); return $Desc; } } class Service extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddString('Name'); $Desc->AddReference('Category', ServiceCategory::GetClassName()); $Desc->AddInteger('Price'); $Desc->AddInteger('VAT'); $Desc->AddChangeAction(); $Desc->AddBoolean('Public'); $Desc->AddInteger('InternetSpeedMax'); $Desc->AddInteger('InternetSpeedMin'); $Desc->AddInteger('InternetSpeedBonus'); $Desc->AddInteger('InternetUploadAsymmetry'); $Desc->AddInteger('Memory'); $Desc->AddInteger('MemorySwap'); $Desc->AddInteger('Storage'); $Desc->AddInteger('CPUCount'); return $Desc; } } class ServiceCategory extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddString('Name'); return $Desc; } } class SupportActivity extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddDateTime('Time'); $Desc->AddString('Description'); $Desc->AddReference('Customer', Member::GetClassName()); $Desc->AddReference('User', User::GetClassName()); return $Desc; } } class ServiceCustomerRel extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddReference('Service', Service::GetClassName()); $Desc->AddReference('Customer', Member::GetClassName()); $Desc->AddChangeAction(); $Desc->AddInteger('SpeedLimit'); return $Desc; } } class UserCustomerRel extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddReference('User', User::GetClassName()); $Desc->AddReference('Customer', Member::GetClassName()); return $Desc; } } class AddressPlace extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddString('Town'); $Desc->AddString('Street'); $Desc->AddString('HouseNumber'); $Desc->AddEnum('HouseNumberType', array('Popisné', 'Evidenční')); $Desc->AddString('Psc'); $Desc->AddInteger('RuianCode'); return $Desc; } }