Changeset 498 for trunk/finance/bills.php
- Timestamp:
- Mar 3, 2013, 6:02:17 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/finance/bills.php
r486 r498 4 4 { 5 5 var $SpecificSymbol = 1; // počítačová sít 6 var $FileFolder = 'doklady';7 var $FileNamePrefix = 'doklad-';8 6 9 function Generate Bill($BillId)7 function GenerateHTML() 10 8 { 11 global $SpecificSymbol, $Config; 12 13 $DbResult = $this->Database->select('FinanceBills', '*', '`Id`='.$BillId); 14 $Bill = $DbResult->fetch_assoc(); 15 16 $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Bill['Subject']); 17 $Subject = $DbResult->fetch_assoc(); 18 19 $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Config['Finance']['MainSubjectId']); 20 $MainSubject = $DbResult->fetch_assoc(); 21 22 $DbResult = $this->Database->select('FinanceBankAccount', '*', '(`Subject`='. 23 $Config['Finance']['MainSubjectId'].') AND (`Use`=1)'); 24 $MainSubjectAccount = $DbResult->fetch_assoc(); 25 26 $Dodavka = array(); 27 $DbResult = $this->Database->select('FinanceBillsItems', '*', 'Bill='.$BillId); 28 while($Item = $DbResult->fetch_assoc()) 29 { 30 $Dodavka[$Item['Id']] = $Item; 31 } 32 33 $PaymentType = array('převodem', 'hotově'); 34 $BooleanText = array('Ne', 'Ano'); 35 36 switch($Bill['Type']) 37 { 38 case 'invoice': 39 $Output = '<table width="100%"><tr><td colspan="2">'. 40 '<font size="6"><div align="center">Faktura - daňový doklad</font></div>'. 41 '<hr></td></tr>'. 42 '<tr><td valign="top" width="50%"><strong>Dodavatel:</strong><br>'. 43 $MainSubject['Name'].'<br>'. 44 $MainSubject['AddressStreet'].'<br>'. 45 $MainSubject['AddressPSC'].' '.$MainSubject['AddressTown'].'<br>'. 46 'IČ: '.$MainSubject['IC'].'<br>'. 47 'DIČ: '.$MainSubject['DIC'].'<br>'. 48 'Účet: '.$MainSubjectAccount['Number'].'<br>'. 49 'Plátce DPH: '.$BooleanText[$MainSubject['PayVAT']].'<br>'. 50 '</td><td valign="top">'. 51 '<strong>Odběratel:</strong><br>'. 52 $Subject['Name'].'<br>'. 53 $Subject['AddressStreet'].'<br>'. 54 $Subject['AddressPSC'].' '.$Subject['AddressTown'].'<br>'; 55 if($Subject['IC'] != 0) $Output .= 'IČ: '.$Subject['IC'].'<br>'; 56 if($Subject['DIC'] != '') $Output .= 'DIČ: '.$Subject['DIC'].'<br>'; 57 $Output .= 58 '</td></tr>'. 59 '<tr><td colspan="2"><hr></td></tr>'. 60 '<tr><td width="50%" valign="top">'. 61 '<strong>Platební podmínky:</strong><br>'. 62 'Číslo dokladu: '.$Bill['BillCode'].'<br>'. 63 'Variabilní symbol: '.$Subject['Id'].'<br>'. 64 'Specifický symbol: '.$this->SpecificSymbol.'<br>'. 65 'Konstantní symbol:<br>'. 66 'Způsob úhrady: '.$PaymentType[$Bill['Cash']]. 67 '</td><td valign="top">'. 68 '<br>'. 69 'Datum vystavení: '.HumanDate($Bill['TimeCreate']).'<br>'. 70 'Datum zdanitel. plnění: '.HumanDate($Bill['TimeCreate']).'<br>'. 71 'Datum splatnosti: '.HumanDate($Bill['TimeDue']).'<br>'; 72 if(($Bill['PeriodFrom'] != '') and ($Bill['PeriodTo'] != '')) 73 $Output .= 'Fakturované období: '.HumanDate($Bill['PeriodFrom']).' - '.HumanDate($Bill['PeriodTo']).'<br>'; 74 $Output .= '</td></tr>'. 75 '<tr><td colspan="2">'. 76 '<hr>'. 77 '<br>'. 78 '<table border="0" width="100%">'. 79 '<tr><th align="left">Dodávka</th><th align="right">Množství</th><th align="right">Cena/MJ</th><th align="right">Celkem</th></tr>'. 80 '<tr><td colspan="4"><hr></td></tr>'; 81 82 $Total = 0; 83 foreach($Dodavka as $Polozka) 84 { 85 $Output .= '<tr><td>'.$Polozka['Description'].'</td><td align="right">'.$Polozka['Quantity'].'</td><td align="right">'.$Polozka['Price'].' Kč</td><td align="right">'.($Polozka['Quantity'] * $Polozka['Price']).' Kč</td></tr>'; 86 $Total += ($Polozka['Quantity'] * $Polozka['Price']); 87 } 88 $Output .= '<tr><th colspan="3" align="left">Celkem</th><th align="right">'.$Total.' Kč</th></tr>'; 89 $Output .= '</table>'. 90 '</td></tr>'. 91 '<tr><td colspan="2"><hr></td></tr>'. 92 '</table>'; 93 break; 94 case 'income': 95 $Output = '<table width="100%" border="1" cellspacing="0" cellpadding="3"><tr><td width="50%">'. 96 '<strong>Firma:</strong><br>'. 97 $MainSubject['Name'].'<br>'. 98 $MainSubject['AddressStreet'].'<br>'. 99 $MainSubject['AddressPSC'].' '.$MainSubject['AddressTown'].'<br>'. 100 'IČ: '.$MainSubject['IC'].'<br>'. 101 'DIČ: '.$MainSubject['DIC'].'<br>'. 102 'Účet: '.$MainSubjectAccount['Number'].'<br>'. 103 'Plátce DPH: '.$BooleanText[$MainSubject['PayVAT']]. 104 '</td><td width="50%" valign="top">'. 105 '<font size="5"><strong>PŘÍJMOVÝ POKLADNÍ DOKLAD</strong></font><br><br>'. 106 'Číslo dokladu: '.$Bill['BillCode'].'<br>'. 107 'Datum vystavení: '.HumanDate($Bill['TimeCreate']).'<br>'. 108 '</td></tr>'. 109 '<tr><td colspan="2"><strong>Přijato od:</strong><br>'. 110 $Subject['Name'].'<br>'. 111 $Subject['AddressStreet'].'<br>'. 112 $Subject['AddressPSC'].' '.$Subject['AddressTown'].'<br>'; 113 if($Subject['IC'] != 0) $Output .= 'IČ: '.$Subject['IC'].'<br>'; 114 if($Subject['DIC'] != '') $Output .= 'DIČ: '.$Subject['DIC'].'<br>'; 115 $Total = 0; 116 $Description = ''; 117 foreach($Dodavka as $Polozka) 118 { 119 $Description .= $Polozka['Description'].'<br>'; 120 $Total += ($Polozka['Quantity'] * $Polozka['Price']); 121 } 122 $Output .= '</td></tr>'. 123 '<tr><td colspan="2"><strong>Částka:</strong> '.$Total.' Kč<br><br>'. 124 '</td></tr>'. 125 '<tr><td colspan="2"><strong>Účel platby:</strong><br>'.$Description.'</td></tr>'. 126 '<tr><td><br><br>Podpis příjemce:</td><td><br><br>Podpis pokladníka:</td></tr>'; 127 $Output .= '</table>'; 128 break; 129 } 130 return($Output); 9 return(''); 131 10 } 132 11 133 function CreateBill($SubjectId, $Items, $TimeCreate, $TimeDue, $BillCode = '', $Type = 'invoice', 134 $PeriodFrom, $PeriodTo) 135 { 136 $this->Database->insert('FinanceBills', array('TimeCreate' => TimeToMysqlDateTime($TimeCreate), 137 'Subject' => $SubjectId, 'TimeDue' => TimeToMysqlDateTime($TimeDue), 138 'BillCode' => $BillCode, 'Type' => $Type, 'PeriodFrom' => TimeToMysqlDate($PeriodFrom), 139 'PeriodTo' => TimeToMysqlDate($PeriodTo))); 140 $BillId = $this->Database->insert_id; 141 foreach($Items as $Item) 142 { 143 $this->Database->insert('FinanceBillsItems', array('Bill' => $BillId, 144 'Description' => $Item['Description'], 'Price' => $Item['Price'], 'Quantity' => $Item['Quantity'])); 145 } 146 //Header('Content-Type: application/pdf'); 147 $PdfData = $this->HtmlToPdf($this->GenerateBill($BillId)); 148 //echo($PdfData); 149 file_put_contents($this->FileFolder.'/'.$this->FileNamePrefix.$BillId.'.pdf', $PdfData); 150 //$this->Database->query('UPDATE finance_bills SET pdf = 0x'.bin2hex($PdfData).' WHERE id='.$BillId); 151 return($BillId); 152 } 153 154 function CreateIncomeBill($SubjectId, $Description, $Price, $BillCode) 155 { 156 $this->Database->insert('FinanceBills', array('TimeCreate' => TimeToMysqlDateTime(time()), 'Subject' => $SubjectId, 'BillCode' => $BillCode, 'Type' => 'income')); 157 $BillId = $this->Database->insert_id; 158 $this->Database->insert('FinanceBillsItems', array('Bill' => $BillId, 'Description' => $Description, 'Price' => $Price, 'Quantity' => 1)); 159 //Header('Content-Type: application/pdf'); 160 $PdfData = $this->HtmlToPdf($this->GenerateBill($BillId)); 161 //echo($PdfData); 162 file_put_contents($this->FileFolder.'/'.$this->FileNamePrefix.$BillId.'.pdf', $PdfData); 163 //$this->Database->query('UPDATE finance_bills SET pdf = 0x'.bin2hex($PdfData).' WHERE id='.$BillId); 164 return($BillId); 165 } 166 167 function RegeneratePDF($BillId) 12 function SaveToFile($FileName) 168 13 { 169 14 global $Database; 170 15 171 $PdfData = $this->HtmlToPdf($this->GenerateBill($BillId)); 172 //echo($this->FileFolder.'/'.$this->FileNamePrefix.$BillId.'.pdf'); 173 echo(file_put_contents($this->FileFolder.'/'.$this->FileNamePrefix.$BillId.'.pdf', $PdfData)); 174 //$this->Database->query('UPDATE finance_bills SET pdf = 0x'.bin2hex($PdfData).' WHERE id='.$BillId); 175 } 176 177 function ShowStoredBill($BillId) 178 { 179 global $Database; 180 181 //$DbResult = $this->Database->select('finance_bills', 'pdf', 'id='.$BillId); 182 //if($DbResult->num_rows == 1) 183 //{ 184 // $DbRow = $DbResult->fetch_array(); 185 $FileName = $this->FileFolder.'/'.$this->FileNamePrefix.$BillId.'.pdf'; 186 if(file_exists($FileName)) 187 { 188 Header('Content-Type: application/pdf'); 189 Header('Content-Disposition: attachment; filename="'.$this->FileNamePrefix.$BillId.'.pdf"'); 190 echo(file_get_contents($FileName)); 191 } else echo('Faktura nenalezena'); 192 } 193 194 function ShowGeneratedBill($BillId) 195 { 196 global $Database; 197 198 Header('Content-Type: application/pdf'); 199 Header('Content-Disposition: attachment; filename="'.$this->FileNamePrefix.$BillId.'.pdf"'); 200 echo($this->HtmlToPdf($this->GenerateBill($BillId))); 201 } 202 203 function HasPDFFile($BillId) 204 { 205 return(file_exists($this->FileFolder.'/'.$this->FileNamePrefix.$BillId.'.pdf')); 16 $PdfData = $this->HtmlToPdf($this->GenerateHTML()); 17 file_put_contents($FileName, $PdfData); 206 18 } 207 19 208 20 function HtmlToPdf($HtmlCode) 209 21 { 210 $Output = shell_exec('echo "'.addslashes(FromUTF8($HtmlCode)).'"|htmldoc --no-numbered --webpage --no-embedfonts --charset 8859-2 -t pdf -'); 22 $Output = shell_exec('echo "'.addslashes(FromUTF8($HtmlCode)). 23 '"|htmldoc --no-numbered --webpage --no-embedfonts --charset 8859-2 -t pdf -'); 211 24 return($Output); 212 25 } 26 } 213 27 214 function ShowPage() 28 class BillInvoice extends Bill 29 { 30 var $InvoiceId; 31 32 function GenerateHTML() 215 33 { 216 global $Database; 217 if(array_key_exists('subject', $_GET)) 34 global $SpecificSymbol, $Config; 35 36 $DbResult = $this->Database->select('FinanceInvoice', '*', '`Id`='.$this->InvoiceId); 37 $Invoice = $DbResult->fetch_assoc(); 38 39 $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Invoice['Subject']); 40 $Subject = $DbResult->fetch_assoc(); 41 42 $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Config['Finance']['MainSubjectId']); 43 $MainSubject = $DbResult->fetch_assoc(); 44 45 $DbResult = $this->Database->select('FinanceBankAccount', '*', '(`Subject`='. 46 $Config['Finance']['MainSubjectId'].') AND (`Use`=1)'); 47 $MainSubjectAccount = $DbResult->fetch_assoc(); 48 49 $Dodavka = array(); 50 $DbResult = $this->Database->select('FinanceInvoiceItem', '*', 'FinanceInvoice='.$this->InvoiceId); 51 while($Item = $DbResult->fetch_assoc()) 218 52 { 53 $InvoiceItems[$Item['Id']] = $Item; 54 } 55 56 $PaymentType = array('převodem', 'hotově'); 57 $BooleanText = array('Ne', 'Ano'); 58 59 $Output = '<table width="100%"><tr><td colspan="2">'. 60 '<font size="6"><div align="center">Faktura - daňový doklad</font></div>'. 61 '<hr></td></tr>'. 62 '<tr><td valign="top" width="50%"><strong>Dodavatel:</strong><br>'. 63 $MainSubject['Name'].'<br>'. 64 $MainSubject['AddressStreet'].'<br>'. 65 $MainSubject['AddressPSC'].' '.$MainSubject['AddressTown'].'<br>'. 66 'IČ: '.$MainSubject['IC'].'<br>'. 67 'DIČ: '.$MainSubject['DIC'].'<br>'. 68 'Účet: '.$MainSubjectAccount['Number'].'<br>'. 69 'Plátce DPH: '.$BooleanText[$MainSubject['PayVAT']].'<br>'. 70 '</td><td valign="top">'. 71 '<strong>Odběratel:</strong><br>'. 72 $Subject['Name'].'<br>'. 73 $Subject['AddressStreet'].'<br>'. 74 $Subject['AddressPSC'].' '.$Subject['AddressTown'].'<br>'; 75 if($Subject['IC'] != 0) $Output .= 'IČ: '.$Subject['IC'].'<br>'; 76 if($Subject['DIC'] != '') $Output .= 'DIČ: '.$Subject['DIC'].'<br>'; 77 $Output .= 78 '</td></tr>'. 79 '<tr><td colspan="2"><hr></td></tr>'. 80 '<tr><td width="50%" valign="top">'. 81 '<strong>Platební podmínky:</strong><br>'. 82 'Číslo dokladu: '.$Invoice['BillCode'].'<br>'. 83 'Variabilní symbol: '.$Subject['Id'].'<br>'. 84 'Specifický symbol: '.$this->SpecificSymbol.'<br>'. 85 'Konstantní symbol:<br>'. 86 'Způsob úhrady: '.$PaymentType[$Invoice['Cash']]. 87 '</td><td valign="top">'. 88 '<br>'. 89 'Datum vystavení: '.HumanDate($Invoice['TimeCreation']).'<br>'. 90 'Datum zdanitel. plnění: '.HumanDate($Invoice['TimeCreation']).'<br>'. 91 'Datum splatnosti: '.HumanDate($Invoice['TimeDue']).'<br>'; 92 if(($Invoice['PeriodFrom'] != '') and ($Invoice['PeriodTo'] != '')) 93 $Output .= 'Fakturované období: '.HumanDate($Invoice['PeriodFrom']).' - '. 94 HumanDate($Invoice['PeriodTo']).'<br>'; 95 $Output .= '</td></tr>'. 96 '<tr><td colspan="2">'. 97 '<hr>'. 98 '<br>'. 99 '<table border="0" width="100%">'. 100 '<tr><th align="left">Dodávka</th><th align="right">Množství</th><th align="right">Cena/MJ</th><th align="right">Celkem</th></tr>'. 101 '<tr><td colspan="4"><hr></td></tr>'; 102 103 $Total = 0; 104 foreach($InvoiceItems as $Item) 105 { 106 $Output .= '<tr><td>'.$Item['Description'].'</td><td align="right">'. 107 $Item['Quantity'].'</td><td align="right">'.$Item['Price']. 108 ' Kč</td><td align="right">'.($Item['Quantity'] * $Item['Price']).' Kč</td></tr>'; 109 $Total += ($Item['Quantity'] * $Item['Price']); 110 } 111 $Output .= '<tr><th colspan="3" align="left">Celkem</th><th align="right">'.$Total.' Kč</th></tr>'; 112 $Output .= '</table>'. 113 '</td></tr>'. 114 '<tr><td colspan="2"><hr></td></tr>'. 115 '</table>'; 116 117 return($Output); 118 } 119 } 120 121 class BillOperation extends Bill 122 { 123 var $OperationId; 219 124 220 $DbResult = $this->Database->select('FinanceBills', '*', 'Subject='.$_GET['subject']); 221 while($Item = $DbResult->fetch_array()) 222 { 223 echo('<a href="?bill='.$Item['Id'].'">faktura '.$Item['Id'].'</a> <a href="?billpdf='.$Item['Id'].'">Uložené PDF</a> <a href="?billpdf2='.$Item['Id'].'">Generované PDF</a> <a href="?regenerate='.$Item['Id'].'">Přegenerovat</a><br>'); 224 } 225 } else 226 if(array_key_exists('billpdf', $_GET)) 227 { 228 $this->ShowStoredBill($_GET['billpdf']); 229 } else 230 if(array_key_exists('billpdf2', $_GET)) 231 { 232 $this->ShowGeneratedBill($_GET['billpdf2']); 233 } else 234 if(array_key_exists('regenerate', $_GET)) 235 { 236 $this->RegeneratePDF($_GET['regenerate']); 237 } else 238 if(array_key_exists('bill', $_GET)) 239 { 240 echo($this->GenerateBill($_GET['bill'])); 241 } else 242 if(array_key_exists('generate', $_GET)) 243 { 244 $this->CreateBill(1, array(array('Description' => 'Poplatek za připojení k síti', 'Price' => 1000, 'Quantity' => 1)), time(), time()); 245 } else 246 { 247 ShowHeader('Doklady', 'Doklady'); 248 echo('Faktury:<br />'); 249 $DbResult = $this->Database->select('Subject', '*', '1 ORDER BY Name'); 250 while($Subject = $DbResult->fetch_assoc()) 251 { 252 echo('<a href="?user='.$Subject['Id'].'">'.$Subject['Name'].'</a><br />'); 253 } 254 ShowFooter(); 255 } 125 function GenerateHTML() 126 { 127 $DbResult = $this->Database->select('FinanceOperation', '*', '`Id`='.$this->OperationId); 128 $Operation = $DbResult->fetch_assoc(); 129 130 $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Operation['Subject']); 131 $Subject = $DbResult->fetch_assoc(); 132 133 $DbResult = $this->Database->select('Subject', '*', '`Id`='.$Config['Finance']['MainSubjectId']); 134 $MainSubject = $DbResult->fetch_assoc(); 135 136 $DbResult = $this->Database->select('FinanceBankAccount', '*', '(`Subject`='. 137 $Config['Finance']['MainSubjectId'].') AND (`Use`=1)'); 138 $MainSubjectAccount = $DbResult->fetch_assoc(); 139 140 //$Dodavka = array(); 141 //$DbResult = $this->Database->select('FinanceInvoiceItem', '*', 'FinanceInvoice='.$BillId); 142 //while($Item = $DbResult->fetch_assoc()) 143 //{ 144 // $InvoiceItems[$Item['Id']] = $Item; 145 //} 146 147 $Output = '<table width="100%" border="1" cellspacing="0" cellpadding="3"><tr><td width="50%">'. 148 '<strong>Firma:</strong><br>'. 149 $MainSubject['Name'].'<br>'. 150 $MainSubject['AddressStreet'].'<br>'. 151 $MainSubject['AddressPSC'].' '.$MainSubject['AddressTown'].'<br>'. 152 'IČ: '.$MainSubject['IC'].'<br>'. 153 'DIČ: '.$MainSubject['DIC'].'<br>'. 154 'Účet: '.$MainSubjectAccount['Number'].'<br>'. 155 'Plátce DPH: '.$BooleanText[$MainSubject['PayVAT']]. 156 '</td><td width="50%" valign="top">'. 157 '<font size="5"><strong>PŘÍJMOVÝ POKLADNÍ DOKLAD</strong></font><br><br>'. 158 'Číslo dokladu: '.$Bill['BillCode'].'<br>'. 159 'Datum vystavení: '.HumanDate($Bill['TimeCreate']).'<br>'. 160 '</td></tr>'. 161 '<tr><td colspan="2"><strong>Přijato od:</strong><br>'. 162 $Subject['Name'].'<br>'. 163 $Subject['AddressStreet'].'<br>'. 164 $Subject['AddressPSC'].' '.$Subject['AddressTown'].'<br>'; 165 if($Subject['IC'] != 0) $Output .= 'IČ: '.$Subject['IC'].'<br>'; 166 if($Subject['DIC'] != '') $Output .= 'DIČ: '.$Subject['DIC'].'<br>'; 167 $Total = 0; 168 $Description = ''; 169 //foreach($Dodavka as $Polozka) 170 //{ 171 // $Description .= $Polozka['Description'].'<br>'; 172 // $Total += ($Polozka['Quantity'] * $Polozka['Price']); 173 //} 174 $Output .= '</td></tr>'. 175 '<tr><td colspan="2"><strong>Částka:</strong> '.$Total.' Kč<br><br>'. 176 '</td></tr>'. 177 '<tr><td colspan="2"><strong>Účel platby:</strong><br>'.$Description.'</td></tr>'. 178 '<tr><td><br><br>Podpis příjemce:</td><td><br><br>Podpis pokladníka:</td></tr>'; 179 $Output .= '</table>'; 180 return($Output); 256 181 } 257 182 }
Note:
See TracChangeset
for help on using the changeset viewer.