WIP Invoice Email delivery

This commit is contained in:
Frank Schubert
2024-07-10 12:56:19 +02:00
parent 4ca5c849ae
commit 37c361282e
3 changed files with 53 additions and 22 deletions

View File

@@ -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;