Added InvoiceJob
This commit is contained in:
@@ -108,7 +108,13 @@ XINON GmbH";
|
||||
return false;
|
||||
}
|
||||
|
||||
$pdf_filename = $pdf->getFullPath();
|
||||
$pdf_filename = false;
|
||||
try {
|
||||
$pdf_filename = $pdf->getFullPath();
|
||||
} catch(\Exception $e) {
|
||||
$this->log->error("File for Invoice ".$this->id." not found");
|
||||
}
|
||||
|
||||
if(!$pdf_filename || !file_exists($pdf_filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,17 @@ class InvoiceController extends mfBaseController {
|
||||
$this->layout()->set("invoices", $billings);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
// get Jobs
|
||||
$now = new DateTime("now");
|
||||
$pdf_jobs = InvoiceJobModel::search(["task" => "make-invoice-pdf", "to_date>=" => $now->format("Y-m-d")]);
|
||||
$email_jobs = InvoiceJobModel::search(["task" => "send-invoice-email", "to_date>=" => $now->format("Y-m-d")]);
|
||||
|
||||
$this->layout()->set("pdf_jobs", $pdf_jobs);
|
||||
$this->layout()->set("email_jobs", $email_jobs);
|
||||
|
||||
|
||||
// sum listing
|
||||
|
||||
$sum_price = InvoiceModel::getSumPrice($filter);
|
||||
$sum_price_gross = InvoiceModel::getSumGrossPrice($filter);
|
||||
$sum_price_sepa = InvoiceModel::getSumPrice(array_merge($filter, ["billing_type" => "sepa"]));
|
||||
@@ -202,6 +213,45 @@ class InvoiceController extends mfBaseController {
|
||||
}
|
||||
|
||||
|
||||
protected function createJob() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get());exit;
|
||||
|
||||
$task = $r->task;
|
||||
if($task != "make-invoice-pdf" && $task != "send-invoice-email") {
|
||||
$this->layout()->setFlash("Ungültiger Task", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
if(!$r->from_date || !$r->to_date) {
|
||||
$this->layout()->setFlash("Start- und Endddatum werden benötigt", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
try {
|
||||
$from_date = DateTime::createFromFormat("d.m.Y", $r->from_date, new DateTimeZone("Europe/Vienna"));
|
||||
$from_date->setTime(0,0,0);
|
||||
|
||||
$to_date = DateTime::createFromFormat("d.m.Y", $r->to_date, new DateTimeZone("Europe/Vienna"));
|
||||
$to_date->setTime(23,59,59);
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Von- oder Bisdatum ungültig", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
$job = InvoiceJobModel::create([
|
||||
"task" => $task,
|
||||
"from_date" => $from_date->format("Y-m-d"),
|
||||
"to_date" => $to_date->format("Y-m-d"),
|
||||
]);
|
||||
if(!$job->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Task erfolgreich gespeichert", "success");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
protected function runInvoicingAction() {
|
||||
if(!$this->me->can("Billing")) {
|
||||
@@ -784,9 +834,13 @@ class InvoiceController extends mfBaseController {
|
||||
exit;
|
||||
}
|
||||
|
||||
public function createPDFs() {
|
||||
public function createPDFs($limit = false) {
|
||||
$invoice_path_base = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
|
||||
$created = 0;
|
||||
foreach(InvoiceModel::getAll() as $invoice) {
|
||||
if($limit && $created >= $limit) {
|
||||
return $created;
|
||||
}
|
||||
if(InvoiceFileModel::getFirst(["invoice_id" => $invoice->id])) {
|
||||
continue;
|
||||
}
|
||||
@@ -803,11 +857,11 @@ class InvoiceController extends mfBaseController {
|
||||
if(!$ifile) {
|
||||
echo "Could not create PDF for ".$invoice->invoice_number."\n";
|
||||
}
|
||||
|
||||
echo ".";
|
||||
$created++;
|
||||
//echo ".";
|
||||
}
|
||||
echo "\n";
|
||||
return true;
|
||||
//echo "\n";
|
||||
return $created;
|
||||
}
|
||||
|
||||
protected function sendInvoicesAction() {
|
||||
@@ -831,28 +885,40 @@ class InvoiceController extends mfBaseController {
|
||||
/*
|
||||
* Gutschriften auch an Xinon
|
||||
*/
|
||||
public function _sendEmailInvoices() {
|
||||
public function _sendEmailInvoices($limit = false) {
|
||||
$sent = 0;
|
||||
$defer = 0;
|
||||
foreach(InvoiceModel::search(["billing_delivery" => "email", "date_delivered" => false]) as $invoice) {
|
||||
if($limit && $sent >= $limit) {
|
||||
return ["sent" => $sent, "defer" => $defer];
|
||||
}
|
||||
$pdf = $invoice->pdf;
|
||||
|
||||
if(!$pdf || !$pdf->name) {
|
||||
echo "PDF für ".$invoice->invoice_number." noch nicht generiert\n";
|
||||
//echo "PDF für ".$invoice->invoice_number." noch nicht generiert\n";
|
||||
$defer++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$pdf_file = $pdf->getFullPath();
|
||||
$pdf_file = false;
|
||||
try {
|
||||
$pdf_file = $pdf->getFullPath();
|
||||
} catch (Exception $e) {
|
||||
$this->log->error("File for Invoice ".$invoice->id." not found");
|
||||
}
|
||||
|
||||
if(!file_exists($pdf_file)) {
|
||||
echo "Datei ".$pdf->filename." nicht gefunden\n";
|
||||
//echo "Datei ".$pdf->filename." nicht gefunden\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if($invoice->total == 0) {
|
||||
echo "Skipping ".$invoice->invoice_number." because total is zero\n";
|
||||
//echo "Skipping ".$invoice->invoice_number." because total is zero\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$invoice->sendByEmail()) {
|
||||
echo "Error sending ".$invoice->invoice_number." to ".$invoice->email."\n";
|
||||
$this->log->warning("Error sending ".$invoice->invoice_number." to ".$invoice->email);
|
||||
continue;
|
||||
}
|
||||
$invoice->date_delivered = date("U");
|
||||
@@ -863,11 +929,11 @@ class InvoiceController extends mfBaseController {
|
||||
$invoice->sendByEmail("billing@xinon.at");
|
||||
}
|
||||
|
||||
$sent++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
return ["sent" => $sent, "defer" => $defer];
|
||||
}
|
||||
|
||||
public function printInvoices() {
|
||||
|
||||
Reference in New Issue
Block a user