PreorderBilling
This commit is contained in:
@@ -10,6 +10,9 @@ class PreorderBillingInvoice extends mfBaseModel {
|
||||
private $pdf;
|
||||
private $csv;
|
||||
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
|
||||
public static function getNextInvoiceNumber($netowner_id) {
|
||||
$last_invoice_num = self::getLastInvoiceNumber($netowner_id);
|
||||
@@ -135,7 +138,87 @@ RML Infrastruktur GmbH";
|
||||
return (new QRCode)->render($epc);
|
||||
}
|
||||
|
||||
public function sendByEmail($to_email = false) {
|
||||
if(!$this->id) return false;
|
||||
|
||||
// get pdf file
|
||||
$ifile = PreorderBillingInvoiceFile::createFromInvoice($this);
|
||||
if(!$ifile) {
|
||||
$this->layout()->setFlash("Fehler beim PDF erstellen");
|
||||
$this->redirect("PreorderBillingInvoice");
|
||||
}
|
||||
$pdf = $ifile->file;
|
||||
|
||||
$pdf_filename = false;
|
||||
try {
|
||||
$pdf_filename = $pdf->getFullPath();
|
||||
} catch(\Exception $e) {
|
||||
$this->log->error("PDF-File for Invoice ".$this->id." not found");
|
||||
}
|
||||
if(!$pdf_filename || !file_exists($pdf_filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get csv file
|
||||
$csv_filename = false;
|
||||
$csv = $this->getProperty("csv");
|
||||
if($csv) {
|
||||
try {
|
||||
$csv_filename = $csv->getFullPath();
|
||||
} catch (\Exception $e) {
|
||||
$this->log->error("CSV-File for Invoice " . $this->id . " not found");
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Emailtemplates/preorder-invoice/rml/invoice-email");
|
||||
|
||||
$pdf_vars = [
|
||||
"invoice" => $this
|
||||
];
|
||||
|
||||
foreach($pdf_vars as $name => $val) {
|
||||
$tpl->set($name, $val);
|
||||
}
|
||||
|
||||
$body = $tpl->render();
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
if($to_email) {
|
||||
$to = $to_email;
|
||||
} else {
|
||||
$to = trim($this->email);
|
||||
}
|
||||
|
||||
if(!$to) {
|
||||
$this->log->error(__METHOD__.": Invoice ".$this->invoice_number." missing email");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn(__METHOD__.": Invoice ".$this->invoice_number." could not be sent. Values missing. (subject: '$subject', from: '$from_name', from_email: '$from', to: '$to')");
|
||||
return false;
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-".MFAPPNAME."-Iid", $this->id);
|
||||
$email->addAttachment($pdf_filename, null, $pdf->filename, "application/pdf");
|
||||
if($csv_filename) {
|
||||
$email->addAttachment($csv_filename, null, $csv->filename, "text/csv");
|
||||
}
|
||||
$email->send();
|
||||
$this->log->info(__METHOD__.": Sending Preorder Invoice ".$this->invoice_number." to $to");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -147,7 +230,7 @@ RML Infrastruktur GmbH";
|
||||
}
|
||||
|
||||
if($name == "pdf") {
|
||||
$ifile = PreorderBillingInvoiceFile::getFirst(["invoice_id" => $this->id]);
|
||||
$ifile = PreorderBillingInvoiceFile::getFirst(["invoice_id" => $this->id, "name" => "%.pdf"]);
|
||||
if(!$ifile) return null;
|
||||
|
||||
$file = $ifile->file;
|
||||
@@ -481,6 +564,16 @@ RML Infrastruktur GmbH";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("date_delivered", $filter)) {
|
||||
$date_delivered = $filter['date_delivered'];
|
||||
if($date_delivered === null || $date_delivered === false) {
|
||||
$where .= " AND (PreorderBillingInvoice.date_delivered IS NULL OR PreorderBillingInvoice.date_delivered=0)";
|
||||
} elseif($date_delivered === true) {
|
||||
$where .= " AND (PreorderBillingInvoice.date_delivered IS NOT NULL AND PreorderBillingInvoice.date_delivered > 0)";
|
||||
} elseif(is_numeric($date_delivered)) {
|
||||
$where .= " AND PreorderBillingInvoice.date_delivered=$date_delivered";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
|
||||
Reference in New Issue
Block a user