Fixed filename extension in Invoice Email
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
@@ -34,6 +34,65 @@ 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 = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user