Merge branch 'fronkdev' into 'master'

Fixed filename extension in Invoice Email

See merge request fronk/thetool!464
This commit is contained in:
Frank Schubert
2024-07-10 13:23:00 +00:00
2 changed files with 61 additions and 2 deletions

View File

@@ -152,7 +152,7 @@ XINON GmbH";
$email->setFrom($from, $from_name);
$email->setTo($to);
$email->setHeader("X-".MFAPPNAME."-Iid", $this->id);
$email->addAttachment($pdf_filename, null, $pdf->name, "application/pdf");
$email->addAttachment($pdf_filename, null, $pdf->filename, "application/pdf");
$email->send();
$this->log->info(__METHOD__.": Sending Invoice ".$this->invoice_number." to $to");
}

View File

@@ -33,7 +33,66 @@ class InvoiceFileModel {
return $model;
}
public static function createFromInvoice(Invoice $invoice) {
$log = mfLoghandler::singleton();
$invoice_path_base = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
$invoice_date = new DateTime("@".$invoice->invoice_date);
$year = $invoice_date->format("Y");
$invoice_subfolder = TT_INVOICE_SAVE_SUBFOLDER."/$year";
$invoice_path = "$invoice_path_base/$year";
if(!file_exists($invoice_path)) {
mkdir($invoice_path, 0777, true);
}
// create PDF
$tmp_filename = $invoice->createPdf();
if(!$tmp_filename) {
$log->debug("Error creating PDF file");
return false;
}
$new_filename = $invoice->invoice_number.".pdf";
// move pdf to correct folder
if(!rename($tmp_filename, "$invoice_path/$new_filename")) {
$log->debug("Error moving created PDF file");
return false;
}
// create File
$file = FileModel::create([
"name" => $invoice->invoice_number,
"filename" => $new_filename,
"subfolder" => $invoice_subfolder,
"store_filename" => $new_filename,
"orig_filename" => $new_filename,
]);
if(!$file->save()) {
echo "Error saving PDF file", "error";
return false;
}
// create InvoiceFile
$ifile = InvoiceFileModel::create([
"invoice_id" => $invoice->id,
"file_id" => $file->id,
"name" => $new_filename,
"description" => ""
]);
if(!$ifile->save()) {
echo "Error saving PDF Invoice file", "error";
return false;
}
return $ifile;
}
public static function getAll() {
$items = [];