<?php
//----------------------------------------------------------------------
// src/Logging/Activity/EInvoicingInboundInvoiceNoteLog.php
//----------------------------------------------------------------------
namespace App\Logging\Activity;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\EInvoicing\EInvoicingInboundInvoiceNote;
use App\Logging\Tools;
use App\Services\LogTools;
/**
* Activity log handler for the free-text notes of the received invoices.
*
* Plan.io Task #4683
*/
class EInvoicingInboundInvoiceNoteLog
{
public function __construct(ManagerRegistry $doctrine, LogTools $logTools, Tools $tools)
{
$this->em = $doctrine->getManager();
$this->logTools = $logTools;
$this->tools = $tools;
}
public function logCreation(EInvoicingInboundInvoiceNote $note)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($note);
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($note, $loggingData);
//----------------------------------------------------------------------
$args["action"] = "einvoicing_inbound_invoice_note_add";
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
public function logChanges(EInvoicingInboundInvoiceNote $note, $changes)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($note);
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($note, $loggingData);
//----------------------------------------------------------------------
$action = "einvoicing_inbound_invoice_note_edit";
$basicChanges = array(
"info",
);
// See what changed and log (members first)
foreach ($changes as $key => $change)
{
$name = $this->logTools->camelToSnakeCase($key);
$args["action"] = $action."_".$name;
$before = $change[0];
$after = $change[1];
if (in_array($key, $basicChanges))
{
$pendingLogArgs[] = $this->tools->handleBasicChanges($args, $before, $after);
continue;
}
}
return $pendingLogArgs;
}
public function logRemoval(EInvoicingInboundInvoiceNote $note)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($note);
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($note, $loggingData);
//----------------------------------------------------------------------
$args["action"] = "einvoicing_inbound_invoice_note_delete";
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
private function initArgs(EInvoicingInboundInvoiceNote $note, $loggingData)
{
$society = $note->getSociety();
$societyGroup = $note->getSocietyGroup();
$args = array(
"object_id" => $note->getId(),
"object_bundle" => "EInvoicing",
"object_entity" => "EInvoicingInboundInvoiceNote",
"object_display" => $note->display(),
"society_group" => $societyGroup,
"society" => $society,
"info" => $loggingData['info'],
"special_author" => $loggingData['special_author'],
);
return $args;
}
}