Changeset 786


Ignore:
Timestamp:
Jan 11, 2016, 12:06:08 AM (9 years ago)
Author:
chronos
Message:
  • Modified: Now billing period for invoice generation is calculated as aligned to year boundary and if period is not complete then only valid months are used.
  • Removed: ToDo list and list of task and bugs is available in Trac web system.
  • Modified: BillingPeriodNext was replaced by more general ChangeAction in Member table.
  • Added: Log new monthly finance recalculation report to log table.
Location:
trunk
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/FormClasses.php

    r765 r786  
    3030      'Shortcut' => array('Type' => 'String', 'Caption' => 'Kód', 'Default' => ''),
    3131      'Sequence' => array('Type' => 'TDocumentLineSequenceListLine', 'Caption' => 'Čísleníky', 'Default' => ''),
    32         'Codes' => array('Type' => 'TDocumentLineCodeList', 'Caption' => 'Kódy', 'Default' => ''),
     32      'Codes' => array('Type' => 'TDocumentLineCodeList', 'Caption' => 'Kódy', 'Default' => ''),
     33      'Operations' => array('Type' => 'TFinanceOperationGroupListDocumentLine', 'Caption' => 'Skupiny finančních operací', 'Default' => ''),
     34      'Invoices' => array('Type' => 'TFinanceInvoiceGroupListDocumentLine', 'Caption' => 'Skupiny faktur', 'Default' => ''),
    3335    ),
    3436  ),
     
    4244      'NextNumber' => array('Type' => 'Integer', 'Caption' => 'Další číslo', 'Default' => '1'),
    4345      'YearPrefix' => array('Type' => 'Boolean', 'Caption' => 'Rok jako přípona', 'Default' => '1'),
    44       'Operations' => array('Type' => 'TFinanceOperationListDocumentLine', 'Caption' => 'Finanční operace', 'Default' => ''),
    45       'Invoices' => array('Type' => 'TFinanceInvoiceListDocumentLine', 'Caption' => 'Faktury', 'Default' => ''),
    4646    ),
    4747  ),
     
    461461    'Filter' => '1',
    462462  ),
    463   'TFinanceOperationListDocumentLine' => array(
    464     'Type' => 'ManyToOne',
    465     'Table' => 'FinanceOperation',
     463  'TFinanceOperationGroupListDocumentLine' => array(
     464    'Type' => 'ManyToOne',
     465    'Table' => 'FinanceOperationGroup',
    466466    'Id' => 'Id',
    467467    'Ref' => 'DocumentLine',
    468468    'Filter' => '1',
    469469  ),
    470   'TFinanceInvoiceListDocumentLine' => array(
    471     'Type' => 'ManyToOne',
    472     'Table' => 'FinanceInvoice',
     470  'TFinanceInvoiceGroupListDocumentLine' => array(
     471    'Type' => 'ManyToOne',
     472    'Table' => 'FinanceInvoiceGroup',
    473473    'Id' => 'Id',
    474474    'Ref' => 'DocumentLine',
  • trunk/Application/UpdateTrace.php

    r785 r786  
    17931793{
    17941794  $Manager->Execute('DROP TABLE `NetworkInterfaceStat`');
     1795}
     1796
     1797function UpdateTo786($Manager)
     1798{
     1799  $Manager->Execute('ALTER TABLE `Member` DROP FOREIGN KEY Member_ibfk_28;');
     1800  $Manager->Execute('ALTER TABLE `Member` DROP `BillingPeriodNext`;');
     1801  $Manager->Execute('ALTER TABLE `Member` ADD `Action` ENUM( "add", "modify", "remove" ) NULL');
     1802  $Manager->Execute('ALTER TABLE `Member` ADD `ChangeTime` DATETIME NULL');
     1803  $Manager->Execute('ALTER TABLE `Member` ADD `ReplaceId` `ChangeReplaceId` INT(11) NULL DEFAULT NULL;');
     1804  $Manager->Execute('ALTER TABLE `Member` ADD FOREIGN KEY (`ChangeReplaceId`) REFERENCES `Member`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
    17951805}
    17961806
     
    18761886      768 => array('Revision' => 770, 'Function' => 'UpdateTo770'),
    18771887      770 => array('Revision' => 785, 'Function' => 'UpdateTo785'),
     1888      775 => array('Revision' => 786, 'Function' => 'UpdateTo786'),
    18781889    ));
    18791890  }
  • trunk/Modules/Customer/Customer.php

    r765 r786  
    2727        'MembershipDate' => array('Type' => 'Date', 'Caption' => 'Datum členství', 'Default' => ''),
    2828        'BillingPeriod' => array('Type' => 'TFinanceBillingPeriod', 'Caption' => 'Fakturační období aktuální', 'Default' => ''),
    29         'BillingPeriodNext' => array('Type' => 'TFinanceBillingPeriod', 'Caption' => 'Fakturační období příští', 'Default' => ''),
    3029        'BillingPeriodLastDate' => array('Type' => 'Date', 'Caption' => 'Datum poslední fakturace', 'Default' => ''),
    3130        'Blocked' => array('Type' => 'Boolean', 'Caption' => 'Blokování', 'Default' => '0'),
     
    3635        'SupportActivity' => array('Type' => 'TSupportActivityListCustomer', 'Caption' => 'Zákaznická podpora', 'Default' => ''),
    3736        'Consumption' => array('Type' => 'TCustomerStockSerialNumber', 'Caption' => 'Spotřeba zařízení', 'Default' => ''),
     37        'ChangeAction' => array('Type' => 'TActionEnum', 'Caption' => 'Změna - akce', 'Default' => '', 'Null' => true),
     38        'ChangeTime' => array('Type' => 'DateTime', 'Caption' => 'Změna - čas', 'Default' => '', 'Null' => true),
     39        'ChangeReplaceId' => array('Type' => 'TMember', 'Caption' => 'Změna - položka', 'Default' => '0', 'Null' => true),
    3840      ),
    3941      'ItemActions' => array(
  • trunk/Modules/Finance/Finance.php

    r781 r786  
    159159      $Monthly = round($Monthly);
    160160
    161       if($Member['BillingPeriodNext'] == 1)
     161      if($Member['BillingPeriod'] == 1)
    162162      {
    163163        // Inactive payer
  • trunk/Modules/Finance/Manage.php

    r773 r786  
    3939  }
    4040
     41  /* Get first day and last day of given billing period. Periods are aligned with year start/end. */
    4142  function GetBillingPeriod($Period)
    4243  {
     44    $Time = time();
     45    $Year = date('Y', $Time);
     46
    4347    $MonthCount = $this->System->Modules['Finance']->BillingPeriods[$Period]['MonthCount'];
    44     $PeriodFrom = mktime(0, 0, 0, date('n'), 1, date('Y'));
    45     $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y'));
     48    if($MonthCount <= 0) return(array('From' => NULL, 'To' => NULL, 'MonthCount' => 0));
     49    $MonthCurrent = date('n', $Time);
     50
     51    /* Get start and end of aligned period */
     52    $MonthFrom = floor(($MonthCurrent - 1) / $MonthCount) + 1;
     53    $MonthTo = $MonthFrom + $MonthCount - 1;
     54
     55    /* Use period from current month to end month so months before current month are cut out */
     56    $MonthCount = $MonthTo - $MonthCurrent + 1;
     57    $MonthFrom = $MonthCurrent;
     58
     59    /* Get first and last day of period */
     60    $PeriodFrom = mktime(0, 0, 0, $MonthFrom, 1, $Year);
     61    $PeriodTo = mktime(0, 0, 0, $MonthTo, date('t', mktime(0, 0, 0, $MonthTo, 1, $Year)), $Year);
     62
    4663    return(array('From' => $PeriodFrom, 'To' => $PeriodTo, 'MonthCount' => $MonthCount));
    4764  }
     
    5976      'FROM `MemberPayment` JOIN `Member` ON `Member`.`Id`=`MemberPayment`.`Member` JOIN `Subject` '.
    6077      'ON `Subject`.`Id`=`Member`.`Subject` LEFT JOIN `FinanceBillingPeriod` ON '.
    61       '`FinanceBillingPeriod`.`Id`=`Member`.`BillingPeriodNext` WHERE (`Member`.`Blocked` = 0)'.
    62       'AND (`Member`.`BillingPeriodNext` > 1) AND (`MemberPayment`.`MonthlyTotal` != 0)';
     78      '`FinanceBillingPeriod`.`Id`=`Member`.`BillingPeriod` WHERE (`Member`.`Blocked` = 0)'.
     79      'AND (`Member`.`BillingPeriod` > 1) AND (`MemberPayment`.`MonthlyTotal` != 0)';
    6380
    6481    $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$SQL.') AS T');
     
    133150    $Output = '';
    134151
    135     // Generuj účetní položky
     152    // Produce accounting items
    136153    $DbResult = $this->Database->query('SELECT `Member`.*, `MemberPayment`.`MonthlyTotal` AS `MonthlyTotal`, '.
    137154      'UNIX_TIMESTAMP(`Member`.`BillingPeriodLastDate`) AS `BillingPeriodLastUnixTime`, `Subject`.`Name` AS `SubjectName`,'.
     
    142159    {
    143160      $Output .= $Member['SubjectName'].': ';
    144       $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']);
    145       if($Period['From'] > $Member['BillingPeriodLastUnixTime'])
    146       {
    147         $this->Database->update('Member', 'Id='.$Member['Id'],
    148           array('BillingPeriod' => $Member['BillingPeriodNext']));
    149         $Member['BillingPeriod'] = $Member['BillingPeriodNext'];
    150       }
    151161      $Period = $this->GetBillingPeriod($Member['BillingPeriod']);
     162
     163      /* Check if need to produce new invoice for customer */
    152164      if(($Period['MonthCount'] > 0) and ($Member['Blocked'] == 0) and
    153165        ($Period['From'] > $Member['BillingPeriodLastUnixTime']))
     
    170182        // TODO: In case of negative invoice it is not sufficient to reverse invoicing direction
    171183        // Other subject should invoice only positive items. Negative items should be somehow removed.
    172         if($MonthlyTotal >= 0) {
     184        if($MonthlyTotal >= 0)
     185        {
    173186          $InvoiceGroupId = INVOICE_GROUP_OUT;
    174187        } else {
     
    178191        // Load invoice group
    179192        $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($InvoiceGroupId, 'FinanceInvoiceGroup');
    180         foreach($InvoiceItems as $Index => $Item) {
     193        foreach($InvoiceItems as $Index => $Item)
     194        {
    181195          $InvoiceItems[$Index]['Price'] = $Item['Price'] * $FinanceGroup['ValueSign'];
    182196        }
     
    191205
    192206          $Output .= $this->SendPaymentEmail($Member['Id']);
    193         } else $Output .= '<br />';
    194         $this->Database->update('Member', 'Id='.$Member['Id'],
     207        }
     208        /* Update last billing day */
     209        $this->Database->update('Member', '`Id`='.$Member['Id'],
    195210          array('BillingPeriodLastDate' => TimeToMysqlDateTime($Period['To'])));
    196       } else $Output .= '<br />';
     211      }
     212      $Output .= '<br />';
    197213    }
    198214    return($Output);
     
    233249  function ProcessTableUpdates()
    234250  {
     251    // Update customers
     252    $Output = 'Měním zákazníky...<br>';
     253    $this->TableUpdateChanges('Member');
     254
    235255    // Update finance charge
    236256    $Output = 'Měním aktuální parametry sítě...<br>';
     
    288308    if($MonthCurrent != $MonthLast)
    289309    {
    290       $Output .= 'Odečítám měsíční poplatek...<br />';
     310      $Output .= 'Odečítám pravidelný poplatek...<br />';
    291311      $Output .= $this->ProduceInvoices();
    292312
     
    302322
    303323      $Finance->RecalculateMemberPayment();
    304       //CreateMonthlyOverallBill();
    305       //$Finance->RecalculateUsersFinance();
    306324
    307325      // Restart traffic shaping
     
    309327      //flush();
    310328      //$this->GenerateBills();
     329      $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'ProcessMonthlyPayment', $Output);
    311330    }
    312331    return($Output);
     
    332351    $MainSubject = $DbResult->fetch_assoc();
    333352
    334     $Period = $this->GetBillingPeriod($Member['BillingPeriodNext']);
     353    $Period = $this->GetBillingPeriod($Member['BillingPeriod']);
    335354
    336355    $DbResult = $this->Database->query('SELECT `FinanceBankAccount`.*, '.
     
    382401      $Output = '';
    383402    } else $Output = 'Uživatel '.$User['Name'].' nemá email.';
     403    return $Output;
    384404  }
    385405
  • trunk/Modules/Portal/Portal.php

    r738 r786  
    4040        'DIC' => array('Type' => 'String', 'Caption' => 'DIČ', 'Default' => ''),
    4141        'FamilyMemberCount' => array('Type' => 'Integer', 'Caption' => 'Počet osob v domácnosti', 'Default' => '', 'Suffix' => 'osob'),
    42         'BillingPeriodNext' => array('Type' => 'TFinanceBillingPeriod', 'Caption' => 'Požadované fakturované období', 'Default' => ''),
    4342      ),
    4443    ));
     
    196195          $CustomerUserRel = $DbResult->fetch_assoc();
    197196          $DbResult = $this->Database->query('SELECT Member.Id, '.
    198             'Member.FamilyMemberCount, Member.BillingPeriodNext, Subject.Name, Subject.AddressStreet, '.
     197            'Member.FamilyMemberCount, Subject.Name, Subject.AddressStreet, '.
    199198            'Subject.AddressTown, Subject.AddressPSC, Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
    200199           'ON Subject.Id = Member.Subject WHERE Member.Id='.$CustomerUserRel['Customer']);
     
    215214        if($Form->Values['FamilyMemberCount'] < 0)
    216215          $Form->Values['FamilyMemberCount'] = 0;
    217         if($Form->Values['BillingPeriodNext'] < 2)
    218           $Form->Values['BillingPeriodNext'] = 2;
    219216
    220217        $DbResult = $this->Database->update('Member', 'Id='.$this->System->User->User['Member'],
    221            array('FamilyMemberCount' => $Form->Values['FamilyMemberCount'],
    222            'BillingPeriodNext' => $Form->Values['BillingPeriodNext']));
     218           array('FamilyMemberCount' => $Form->Values['FamilyMemberCount']));
    223219        $DbResult = $this->Database->query('SELECT Subject FROM Member WHERE Id='.$this->System->User->User['Member']);
    224220        $Member = $DbResult->fetch_assoc();
     
    231227        $this->System->ModuleManager->Modules['Log']->NewRecord('Member+Subject', 'Nastavení člena/subjektu změněno',
    232228          $Form->Values['Name']);
    233         $DbResult = $this->Database->query('SELECT Member.Id, Member.FamilyMemberCount, Member.BillingPeriodNext, '.
     229        $DbResult = $this->Database->query('SELECT Member.Id, Member.FamilyMemberCount, '.
    234230          'Subject.Name, Subject.AddressStreet, Subject.AddressTown, Subject.AddressPSC, '.
    235231          'Subject.AddressCountry, Subject.IC, Subject.DIC FROM Member JOIN Subject '.
  • trunk/Modules/SpeedTest/results.php

    r738 r786  
    123123<br /><br />
    124124<h2><a class="start_test" href="<?php echo $config->{'general'}->{'base_url'}; ?>/download.php">Test Again</a></h2>
    125 </center>
    126125<div id="speedtest_credits">
    127126    Powered by <a title="Brandon Checketts Fancy Speed Test" href="http://www.brandonchecketts.com/speedtest/" target="_new">Fancy Speed Test</a>
Note: See TracChangeset for help on using the changeset viewer.