Changeset 866


Ignore:
Timestamp:
Dec 23, 2019, 1:08:17 AM (5 years ago)
Author:
chronos
Message:
  • Added: Allow to manually regenerate PDF files for invoices and finance operations.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r865 r866  
    11<?php
    22
    3 $Revision = 865; // Subversion revision
     3$Revision = 866; // Subversion revision
    44$DatabaseRevision = 862; // SQL structure revision
    55$ReleaseTime = strtotime('2019-12-23');
  • trunk/Modules/Finance/Finance.php

    r844 r866  
    8282    return(round($Spotreba * 0.72 * $this->kWh));
    8383  }
    84  
     84
    8585  function CreateFinanceYear($Year)
    8686  {
    8787    $StartTime = mktime(0, 0, 0, 1, 1, $Year);
    8888    $EndTime = mktime(0, 0, 0, 12, 31, $Year);
    89     $this->Database->insert('FinanceYear', array('Year' => $Year, 
     89    $this->Database->insert('FinanceYear', array('Year' => $Year,
    9090          'DateStart' => TimeToMysqlDate($StartTime), 'DateEnd' => TimeToMysqlDate($EndTime), 'Closed' => 0));
    9191        $YearId = $this->Database->insert_id;
     
    9595    while($DbRow = $DbResult->fetch_assoc())
    9696    {
    97           $this->Database->insert('DocumentLineSequence', array('FinanceYear' => $YearId, 
     97          $this->Database->insert('DocumentLineSequence', array('FinanceYear' => $YearId,
    9898            'NextNumber' => 1, 'YearPrefix' => 1, 'DocumentLine' => $DbRow['Id']));
    9999        }
    100100  }
    101  
     101
    102102  function GetFinanceYear($Year)
    103103  {
     
    111111          {
    112112                $this->CreateFinanceYear($Year);
    113         $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year);           
     113        $DbResult = $this->Database->select('FinanceYear', '*', '`Year`='.$Year);
    114114          } else throw new Exception('Rok '.$Year.' nenalezen');
    115115        }
    116116    $FinanceYear = $DbResult->fetch_assoc();
    117     if($FinanceYear['Closed'] == 1) 
     117    if($FinanceYear['Closed'] == 1)
    118118      throw new Exception('Rok '.$FinanceYear['Year'].' je již uzavřen. Nelze do něj přidávat položky.');
    119     return $FinanceYear;         
     119    return $FinanceYear;
    120120  }
    121121
     
    273273      'AfterInsert' => array($this, 'AfterInsertFinanceOperation'),
    274274      'BeforeModify' => array($this, 'BeforeModifyFinanceOperation'),
     275      'ItemActions' => array(
     276        array('Caption' => 'Přegenerovat doklad', 'URL' => '/finance/sprava/?Operation=RegenerateOperation&i=#RowId'),
     277      ),
    275278    ));
    276279
     
    377380      'AfterInsert' => array($this, 'AfterInsertFinanceInvoice'),
    378381      'BeforeModify' => array($this, 'BeforeModifyFinanceInvoice'),
     382      'ItemActions' => array(
     383        array('Caption' => 'Přegenerovat doklad', 'URL' => '/finance/sprava/?Operation=RegenerateInvoice&i=#RowId'),
     384      ),
    379385    ));
    380386    $this->System->FormManager->RegisterClass('FinanceInvoiceIn', $this->System->FormManager->Classes['FinanceInvoice']);
  • trunk/Modules/Finance/Manage.php

    r833 r866  
    2828      case 'GenerateBills':
    2929        $Output = $this->GenerateBills();
     30        break;
     31      case 'RegenerateInvoice':
     32        $Output = $this->GenerateInvoice('AND (Id='.$_GET['i'].')');
     33        break;
     34      case 'RegenerateOperation':
     35        $Output = $this->GenerateOperation('AND (Id='.$_GET['i'].')');
    3036        break;
    3137      default:
     
    406412  }
    407413
    408   function GenerateBills()
    409   {
    410     $Output = '';
    411 
    412     // FinanceInvoice
     414  function GenerateInvoice($Where)
     415  {
     416    $Output = '';
    413417    $DbResult = $this->Database->query('SELECT * FROM `FinanceInvoice` WHERE (`BillCode` <> "") '.
    414       'AND (`Value` != 0) AND (`File` IS NULL) AND (`Generate` = 1)');
     418      'AND (`Value` != 0) AND (`Generate` = 1)'.$Where);
    415419    while($Row = $DbResult->fetch_assoc())
    416420    {
    417       $DbResult2 = $this->Database->insert('File', array('Name' => '', 'Size' => 0,
    418         'Directory' => $this->System->Modules['Finance']->DirectoryId, 'Time' => 'NOW()'));
    419       $FileId = $this->Database->insert_id;
     421      if ($Row['File'] == null)
     422      {
     423        $DbResult2 = $this->Database->insert('File', array('Name' => '', 'Size' => 0,
     424          'Directory' => $this->System->Modules['Finance']->DirectoryId, 'Time' => 'NOW()'));
     425        $FileId = $this->Database->insert_id;
     426      } else $FileId = $Row['File'];
    420427      $FileName = 'doklad-'.$FileId.'.pdf';
    421428      $Bill = new BillInvoice($this->System);
     
    425432      $FullFileName = $this->System->Modules['File']->GetDir($this->System->Modules['Finance']->DirectoryId).$FileName;
    426433      $Bill->SaveToFile($FullFileName);
    427       if(file_exists($FullFileName))
     434      if (file_exists($FullFileName))
    428435      {
    429436        $this->Database->update('File', 'Id='.$FileId, array('Name' => $FileName, 'Size' => filesize($FullFileName)));
    430437        $this->Database->update('FinanceInvoice', 'Id='.$Row['Id'], array('File' => $FileId));
    431         $Output .= '.';
     438        $Output .= 'Faktura '.$Row['Id'].' vygenerována do souboru '.$FileName.'<br/>'."\n";
    432439      } else $Output .= 'Soubor "'.$FullFileName.'" se nepodařilo uložit.';
    433440    }
    434 
    435     // FinanceOperations
     441    return $Output;
     442  }
     443
     444  function GenerateOperation($Where)
     445  {
     446    $Output = '';
    436447    $DbResult = $this->Database->query('SELECT * FROM `FinanceOperation` WHERE (`BillCode` <> "") '.
    437         'AND (`Value` != 0) AND (`File` IS NULL) AND (`Generate` = 1)');
     448        'AND (`Value` != 0) AND (`Generate` = 1)'.$Where);
    438449    while($Row = $DbResult->fetch_assoc())
    439450    {
    440       $DbResult2 = $this->Database->insert('File', array('Name' => '', 'Size' => 0,
     451      if ($Row['File'] == null)
     452      {
     453        $DbResult2 = $this->Database->insert('File', array('Name' => '', 'Size' => 0,
    441454          'Directory' => $this->System->Modules['Finance']->DirectoryId, 'Time' => 'NOW()'));
    442       $FileId = $this->Database->insert_id;
     455        $FileId = $this->Database->insert_id;
     456      } else $FileId = $Row['File'];
    443457      $FileName = 'doklad2-'.$FileId.'.pdf';
    444458      $Bill = new BillOperation($this->System);
     
    452466        $this->Database->update('File', 'Id='.$FileId, array('Name' => $FileName, 'Size' => filesize($FullFileName)));
    453467        $this->Database->update('FinanceOperation', 'Id='.$Row['Id'], array('File' => $FileId));
    454         $Output .= '.';
     468        $Output .= 'Doklad pro platbu '.$Row['Id'].' vygenerován do souboru '.$FileName.'<br/>'."\n";
    455469      } else $Output .= 'Soubor "'.$FullFileName.'" se nepodařilo uložit.';
    456470    }
     471    return $Output;
     472  }
     473
     474  function GenerateBills()
     475  {
     476    $Output = '';
     477    // Generate PDF files for new invoices and operations
     478    $Output .= $this->GenerateInvoice(' AND (`File` IS NULL)');
     479    $Output .= $this->GenerateOperation(' AND (`File` IS NULL)');
    457480    return($Output);
    458481  }
Note: See TracChangeset for help on using the changeset viewer.