From 37c361282e59509d485eba6f81653a93e375969b Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 10 Jul 2024 12:56:19 +0200 Subject: [PATCH] WIP Invoice Email delivery --- Layout/default/Invoice/Index.php | 2 +- application/Invoice/InvoiceController.php | 53 ++++++++++++++++++++++- scripts/invoice/send-invoice-emails.php | 20 --------- 3 files changed, 53 insertions(+), 22 deletions(-) delete mode 100644 scripts/invoice/send-invoice-emails.php diff --git a/Layout/default/Invoice/Index.php b/Layout/default/Invoice/Index.php index c828fd04d..3b3160f62 100644 --- a/Layout/default/Invoice/Index.php +++ b/Layout/default/Invoice/Index.php @@ -79,7 +79,7 @@ $pagination_entity_name = "Rechnungen";

Rechnungsversand

-
"> + ">
diff --git a/application/Invoice/InvoiceController.php b/application/Invoice/InvoiceController.php index 3810813f9..c1aa27c84 100644 --- a/application/Invoice/InvoiceController.php +++ b/application/Invoice/InvoiceController.php @@ -713,7 +713,58 @@ class InvoiceController extends mfBaseController { } } - public function printInvoicesAction() { + protected function sendInvoices() { + $r = $this->request; + $type = $r->type; + + if($type == "email") { + return $this->sendEmailInvoices(); + } + if($type == "paper") { + return $this->printInvoices(); + } + + $this->redirect("Invoice"); + } + + public function sendEmailInvoices() { + $r = $this->request; + $start = $r->delivery_start_date; + $end = $r->delivery_end_date; + + try { + $start_date = DateTime::createFromFormat("d.m.Y", $start, new DateTimeZone("Europe/Vienna")); + $start_date->setTime(0,0,0); + + $end_date = DateTime::createFromFormat("d.m.Y", $end, new DateTimeZone("Europe/Vienna")); + $end_date->setTime(23,59,59); + } catch(Exception $e) { + $this->layout()->setFlash("Von- oder Bisdatum ungültig", "error"); + $this->redirect("Invoice"); + } + + if(!InvoiceModel::count(["billing_delivery" => "email", "date_delivered" => false, "invoice_date>=" => $start_date->getTimestamp(), "invoice_date<=" => $end_date->getTimestamp()])) { + $this->layout()->setFlash("Keine Rechnungen im angegebenen Zeitraum gefunden", "error"); + $this->redirect("Invoice"); + } + + foreach(InvoiceModel::search(["billing_delivery" => "email", "date_delivered" => false, "invoice_date>=" => $start_date->getTimestamp(), "invoice_date<=" => $end_date->getTimestamp()]) as $invoice) { + var_dump($invoice);exit; + + $pdf = $invoice->pdf; + if(!file_exists($pdf_file)) { + $this->layout()->setFlash("Datei ".$pdf->filename." nicht gefunden", "error"); + return false; + } + + + } + + + } + + public function printInvoices() { + return false; $start = $this->request->delivery_start_date; $end = $this->request->delivery_end_date; diff --git a/scripts/invoice/send-invoice-emails.php b/scripts/invoice/send-invoice-emails.php deleted file mode 100644 index 8e79498d4..000000000 --- a/scripts/invoice/send-invoice-emails.php +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/php -id); -define("INTERNAL_USER_USERNAME", $me->username); - -$ic = new InvoiceController(false); -$ic->createPDFs();