Added generating/downloading Print Invoices
This commit is contained in:
@@ -66,28 +66,28 @@ $pagination_entity_name = "Rechnungen";
|
|||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<h4>Rechnungsversand</h4>
|
<h4>Rechnungsversand</h4>
|
||||||
<form method="post" action="<?=self::getUrl("Invoice","sendInvoices")?>">
|
<form method="post" action="<?=self::getUrl("Invoice","sendInvoices")?>">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<label class="form-label" for="delivery_start_date">Rechungsdatum von</label>
|
<label class="form-label" for="delivery_start_date">Rechungsdatum von</label>
|
||||||
<input type="text" class="form-control" name="delivery_start_date" id="delivery_start_date" value="" />
|
<input type="text" class="form-control" name="delivery_start_date" id="delivery_start_date" value="" />
|
||||||
</div>
|
|
||||||
<div class="col-6">
|
|
||||||
<label class="form-label" for="delivery_end_date">Rechungsdatum bis</label>
|
|
||||||
<input type="text" class="form-control" name="delivery_end_date" id="delivery_end_date" value="" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row mt-2">
|
<div class="col-6">
|
||||||
<div class="col-12">
|
<label class="form-label" for="delivery_end_date">Rechungsdatum bis</label>
|
||||||
<button name="type" value="paper" class="btn btn-lg btn-purple"><i class="far fa-fw fa-print"></i> Rechnungen für Postversand drucken</button>
|
<input type="text" class="form-control" name="delivery_end_date" id="delivery_end_date" value="" />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
</div>
|
<div class="row mt-2">
|
||||||
|
<div class="col-12">
|
||||||
|
<button name="type" value="paper" class="btn btn-lg btn-purple"><i class="far fa-fw fa-print"></i> Rechnungen für Postversand drucken</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ $this->setReturnValue(['filename' => $invoice->invoice_number . ".pdf"]);
|
|||||||
<td style="text-align: right; padding-right: 8pt;"><?=number_format($zone->call_count, 0, ",",".")?></td>
|
<td style="text-align: right; padding-right: 8pt;"><?=number_format($zone->call_count, 0, ",",".")?></td>
|
||||||
<td style="text-align: right"><?=self::getHumanReadableInterval($zone->duration)?></td>
|
<td style="text-align: right"><?=self::getHumanReadableInterval($zone->duration)?></td>
|
||||||
<td style="text-align: right"><?=number_format($zone->price_total, 4, ",",".")?> €</td>
|
<td style="text-align: right"><?=number_format($zone->price_total, 4, ",",".")?> €</td>
|
||||||
<td style="text-align: right; padding-right: 4pt;"><?=$zone->price_total_gross?> €</td>
|
<td style="text-align: right; padding-right: 4pt;"><?=number_format($zone->price_total_gross, 4, ",",".")?> €</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php $v++; ?>
|
<?php $v++; ?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
@@ -670,7 +670,7 @@ class InvoiceController extends mfBaseController {
|
|||||||
|
|
||||||
public function createPDFs() {
|
public function createPDFs() {
|
||||||
$invoice_path_base = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
|
$invoice_path_base = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
|
||||||
foreach(InvoiceModel::getAll() as $invoice) {
|
foreach(InvoiceModel::search(["billing_delivery" => "paper"]) as $invoice) {
|
||||||
if(InvoiceFileModel::getFirst(["invoice_id" => $invoice->id])) {
|
if(InvoiceFileModel::getFirst(["invoice_id" => $invoice->id])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -751,7 +751,6 @@ class InvoiceController extends mfBaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function printInvoices() {
|
public function printInvoices() {
|
||||||
return false;
|
|
||||||
$start = $this->request->delivery_start_date;
|
$start = $this->request->delivery_start_date;
|
||||||
$end = $this->request->delivery_end_date;
|
$end = $this->request->delivery_end_date;
|
||||||
|
|
||||||
@@ -774,28 +773,62 @@ class InvoiceController extends mfBaseController {
|
|||||||
$pdf_files = [];
|
$pdf_files = [];
|
||||||
|
|
||||||
foreach(InvoiceModel::search(["billing_delivery" => "paper", "invoice_date>=" => $start_date->getTimestamp(), "invoice_date<=" => $end_date->getTimestamp()]) as $invoice) {
|
foreach(InvoiceModel::search(["billing_delivery" => "paper", "invoice_date>=" => $start_date->getTimestamp(), "invoice_date<=" => $end_date->getTimestamp()]) as $invoice) {
|
||||||
$filename = $invoice->createPdf();
|
$pdf = $invoice->pdf;
|
||||||
if(!$filename) {
|
|
||||||
$this->layout()->setFlash("Fehler beim PDF erstellen (".$invoice->invoice_number.")", "error");
|
if(!$pdf || !$pdf->name) {
|
||||||
$this->redirect("Invoice");
|
die("PDF für ".$invoice->invoice_number." noch nicht generiert\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$pdf_files[] = $filename;
|
$pdf_file = $pdf->getFullPath();
|
||||||
|
if(!file_exists($pdf_file)) {
|
||||||
|
die("Datei ".$pdf->filename." nicht gefunden\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdf_files[] = $pdf_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//var_dump($pdf_files);exit;
|
||||||
if(!count($pdf_files)) {
|
if(!count($pdf_files)) {
|
||||||
$this->layout()->setFlash("Fehler beim PDF erstellen: Keine PDFs zum zusammenführen", "error");
|
$this->layout()->setFlash("Fehler beim PDF erstellen: Keine PDFs zum zusammenführen", "error");
|
||||||
$this->redirect("Invoice");
|
$this->redirect("Invoice");
|
||||||
}
|
}
|
||||||
|
|
||||||
$output_path = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
|
$output_path = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
|
||||||
$output_filename = "invoices-print-".date("Y-m-d-H-i-s").".pdf";
|
$output_filename = "print-invoices-".date("Y-m-d_H-i-s").".pdf";
|
||||||
$output_filepath = "$output_path/$output_filename";
|
$output_filepath = "$output_path/$output_filename";
|
||||||
|
//var_dump($pdf_files);exit;
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
|
$first = true;
|
||||||
|
$tmp_file1 = "$output_filepath.tmp1";
|
||||||
|
$tmp_file2 = "$output_filepath.tmp2";
|
||||||
|
$tmp_file = "";
|
||||||
foreach($pdf_files as $file) {
|
foreach($pdf_files as $file) {
|
||||||
$pdf_unite_cmd = PDFUNITE_BIN_PATH." '$file' '$output_filepath'";
|
if($i % 2 == 1) {
|
||||||
|
$tmp_file = $tmp_file1;
|
||||||
|
$src_file = $tmp_file2;
|
||||||
|
} else {
|
||||||
|
$tmp_file = $tmp_file2;
|
||||||
|
$src_file = $tmp_file1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($first) {
|
||||||
|
$pdf_unite_cmd = PDFUNITE_BIN_PATH." '$file' '$tmp_file'";
|
||||||
|
$first = false;
|
||||||
|
} else {
|
||||||
|
$pdf_unite_cmd = PDFUNITE_BIN_PATH." '$src_file' '$file' '$tmp_file'";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//echo "$pdf_unite_cmd\n<br />";
|
||||||
shell_exec($pdf_unite_cmd);
|
shell_exec($pdf_unite_cmd);
|
||||||
|
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
|
//exit;
|
||||||
|
rename($tmp_file, $output_filepath);
|
||||||
|
|
||||||
|
//exit;
|
||||||
|
|
||||||
if(!file_exists($output_filepath)) {
|
if(!file_exists($output_filepath)) {
|
||||||
$this->layout()->setFlash("Fehler beim PDFs zusammenführen: Ausgabedatei nicht gefunden", "error");
|
$this->layout()->setFlash("Fehler beim PDFs zusammenführen: Ausgabedatei nicht gefunden", "error");
|
||||||
|
|||||||
Reference in New Issue
Block a user