Delete an existing journal voucher (soft delete)

@param int $input Voucher id

@return JSON encoded string
A string as follows:
In case of success: {"success" : form.defaultSuccessDeleteMessage}
421198
public function deleteJournalVoucher($input, $openTransaction = true, $databaseConnectionName = null, $organizationId = null, $loggedUserId = null)
  {
    if(empty($organizationId))
    {
      $organizationId = $this->AuthenticationManager->getCurrentUserOrganizationId();
    }

    if(empty($loggedUserId))
    {
      $loggedUserId = $this->AuthenticationManager->getLoggedUserId();
    }

    $this->beginTransaction($openTransaction, $databaseConnectionName);

    try
    {
      $currentSettingConfiguration = $this->SettingManager->getCurrentSettingConfiguration($organizationId, $databaseConnectionName);
      $JournalVoucher = $this->JournalVoucher->byId($input['id'], $databaseConnectionName);
      $Period = $this->Period->byId($JournalVoucher->period_id, $databaseConnectionName);

      if($Period->is_closed)
      {
        return json_encode(array('success' => false, 'info' => $this->Lang->get('decima-accounting::journal-management.closedPeriodValidationMessage4', array('period' => $this->Lang->get('decima-accounting::period-management.' . $Period->month)))));
      }

      $Journal = $this->Journal->create(array('journalized_id' => $input['id'], 'journalized_type' => $this->JournalVoucher->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));

      $this->Journal->attachDetail($Journal->id, array('note' => $this->Lang->get('decima-accounting::journal-management.journalVoucherDeletedJournal', array('number' => $JournalVoucher->number)), $Journal));

      $this->JournalEntry->byJournalVoucherId($input['id'], $databaseConnectionName)->each(function($JournalEntry) use ($JournalVoucher, $Journal)
      {
        $this->JournalEntry->delete(array($JournalEntry->id));
      });

      $this->JournalVoucher->delete(array($input['id']));

      $journalVouchers = array();

      if($currentSettingConfiguration['voucher_numeration_type'] == 'P')
      {
        $this->JournalVoucher->subsequentByPeriodByNumberAndByOrganization($JournalVoucher->period_id, $JournalVoucher->number, $organizationId, $databaseConnectionName)->each(function($SubsequentJournalVoucher) use (&$journalVouchers, $loggedUserId, $organizationId)
        {
          $journalVouchers[] = $SubsequentJournalVoucher->id;
          $Journal = $this->Journal->create(array('journalized_id' => $SubsequentJournalVoucher->id, 'journalized_type' => $this->JournalVoucher->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
          $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-purchase::purch-order-management.correlative'), 'field_lang_key' => 'decima-purchase::purch-order-management.correlative', 'old_value' => $SubsequentJournalVoucher->number, 'new_value' => $SubsequentJournalVoucher->number - 1), $Journal);
        });
      }
      else
      {
        $this->JournalVoucher->subsequentByPeriodByVoucherTypeByNumberAndByOrganization($JournalVoucher->period_id, $JournalVoucher->voucher_type_id, $JournalVoucher->number, $organizationId, $databaseConnectionName)->each(function($SubsequentJournalVoucher) use (&$journalVouchers, $loggedUserId, $organizationId)
        {
          $journalVouchers[] = $SubsequentJournalVoucher->id;
          $Journal = $this->Journal->create(array('journalized_id' => $SubsequentJournalVoucher->id, 'journalized_type' => $this->JournalVoucher->getTable(), 'user_id' => $loggedUserId, 'organization_id' => $organizationId));
          $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-purchase::purch-order-management.correlative'), 'field_lang_key' => 'decima-purchase::purch-order-management.correlative', 'old_value' => $SubsequentJournalVoucher->number, 'new_value' => $SubsequentJournalVoucher->number - 1), $Journal);
        });
      }

      if(!empty($journalVouchers))
      {
        $this->JournalVoucher->subtractOneNumber($journalVouchers, $databaseConnectionName);
      }

      $this->commit($openTransaction);
    }
    catch (\Exception $e)
    {
      $this->rollBack($openTransaction);

      throw $e;
    }
    catch (\Throwable $e)
    {
      $this->rollBack($openTransaction);

      throw $e;
    }
    // });

    return json_encode(array('success' => $this->Lang->get('decima-accounting::journal-management.successDeletedVoucherMessage')));
  }
843444
private function fromFlattenedSerializationRecipientToSerialization($input)
    {
        $recipient = [];
        foreach (['header', 'encrypted_key'] as $key) {
            if (array_key_exists($key, $input)) {
                $recipient[$key] = $input[$key];
            }
        }
        $recipients = [
            'ciphertext' => $input['ciphertext'],
            'recipients' => [$recipient],
        ];
        foreach (['protected', 'unprotected', 'iv', 'aad', 'tag'] as $key) {
            if (array_key_exists($key, $input)) {
                $recipients[$key] = $input[$key];
            }
        }

        $this->log(LogLevel::INFO, 'JWE in Flattened JSON Serialization mode loaded.');

        return $recipients;
    }
912576
protected function _unserialize($input)
	{
		$data = @unserialize($input);

		if (is_array($data))
		{
			foreach ($data as $key => $val)
			{
				if (is_string($val))
				{
					$data[$key] = str_replace('{{slash}}', '\\', $val);
				}
			}

			return $data;
		}

		elseif ($data === false)
		{
			is_string($input) and $data = array($input);
		}

		return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
	}
835327
private function filterEmptyInput($input)
    {
        foreach ($input as $key => $value)
        {
            if (empty($value))
            {
                unset($input[$key]);
            }
        }

        return $input;
    }
1040556
public function convert( $input ) {

        $result = new SearchResult(
            array(
                'time'       => 0,
                'maxScore'   => 0,
                'totalCount' => $input['SearchCount'],
            )
        );

        $contentService = $this->repository->getContentService();

        foreach ( $input['SearchResult'] as $doc )
        {
            $contentObject = $contentService->loadContent( $doc->ContentObjectID );
            $searchHit = new SearchAndFilterHit(
                array(
                    'score'         => 0,
                    'valueObject'   => $contentObject,
                    'objectStates'  => $this->loadContentObjectStates( $contentObject->contentInfo )
                )
            );
            $result->searchHits[] = $searchHit;
        }
        return $result;
    }
9947
protected function cleanString($input)
	{
		return htmlentities(
			$input,
			$this->parent->getConfig('htmlentities_flags', ENT_QUOTES),
			$this->parent->getConfig('htmlentities_encoding', 'UTF-8'),
			$this->parent->getConfig('htmlentities_double_encode', false)
		);
	}
2467
protected function recursivelyRemoveEmptyReplacements(array $input)
    {
        foreach ($input as &$value) {
            if (is_array($value)) {
                $value = $this->recursivelyRemoveEmptyReplacements($value);
            }
        }

        return array_filter($input, function ($value) {
            if (is_string($value)) {
                return ! starts_with($value, ':');
            }

            return true;
        });
    }
405878
protected function clean_input( array $input ) {
		foreach ( $input as $key => $value ) {
			if ( is_array( $value ) ) {
				$input[ $key ] = $this->clean_input( $value );
			}

			if ( $value instanceof UploadedFile ) {
				unset( $input[ $key ] );
			}
		}

		return $input;
	}
562421
public function update(array $input)
  {
    unset($input['_token']);
    $input = eloquent_array_filter_for_update($input);
    // $input['date'] = $this->Carbon->createFromFormat($this->Lang->get('form.phpShortDateFormat'), $input['date'])->format('Y-m-d');

    $this->DB->transaction(function() use (&$input)
    {
      $VoucherType = $this->VoucherType->byId($input['id']);
      $unchangedVoucherTypeValues = $VoucherType->toArray();

      $this->VoucherType->update($input, $VoucherType);

      $diff = 0;

      foreach ($input as $key => $value)
      {
        if($unchangedVoucherTypeValues[$key] != $value)
        {
          $diff++;

          if($diff == 1)
          {
            $Journal = $this->Journal->create(array('journalized_id' => $VoucherType->id, 'journalized_type' => $this->VoucherType->getTable(), 'user_id' => $this->AuthenticationManager->getLoggedUserId(), 'organization_id' => $this->AuthenticationManager->getCurrentUserOrganizationId()));
          }

          if($key == 'name')
          {
            $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-accounting::voucher-type-management.name'), 'field_lang_key' => 'decima-accounting::voucher-type-management.name', 'old_value' => $this->Lang->get($unchangedVoucherTypeValues[$key]), 'new_value' => $this->Lang->get($value)), $Journal);
          }
          else
          {
            $this->Journal->attachDetail($Journal->id, array('field' => $this->Lang->get('decima-accounting::voucher-type-management.' . camel_case($key)), 'field_lang_key' => 'decima-accounting::voucher-type-management.' . camel_case($key), 'old_value' => $unchangedVoucherTypeValues[$key], 'new_value' => $value), $Journal);
          }
        }
      }
    });

    return json_encode(array('success' => $this->Lang->get('form.defaultSuccessUpdateMessage')));
  }
54904
public function delete(array $input)
    {
        if(isset($input[$this->id_field_name]) && ! empty($input[$this->id_field_name]))
        {
            try
            {
                $this->r->delete($input[$this->id_field_name]);
            }
            catch(ModelNotFoundException $e)
            {
                $this->errors = new MessageBag(array("model" => "Element does not exists."));
                throw new NotFoundException();
            }
            catch(PermissionException $e)
            {
                $this->errors = new MessageBag(array("model" => "Cannot delete this item, please check that the item is not already associated to any other element, in that case remove the association first."));
                throw new PermissionException();
            }
        }
        else
        {
            $this->errors = new MessageBag(array("model" => "Id not given"));
            throw new NotFoundException();
        }
    }
745490
public static function jsonDecode($input)
    {
        $object = json_decode($input);

        if ($object === null && $input !== 'null') {
            throw new DomainException('Null result with non-null input');
        }

        return $object;
    }
359808
protected function _toJson($input)
    {
        $json = json_encode($input);

        if (JSON_ERROR_NONE !== json_last_error())
        {
            throw new InvalidArgumentException(
                'Error encoding JSON data: ' . json_last_error_msg()
            );
        }

        return $json;
    }
1180386
public function inject($input)
    {
        Version::warn(__METHOD__ . ' is deprecated');
        $replace = array();
        foreach ($this->data as $key => $val) {
            $replace['{' . $key . '}'] = $val;
        }

        return strtr($input, $replace);
    }
538279
private static function processWebhook($input)
    {
        self::$receivedWebhook = $input;
        parse_str($input, $result);
        if ($result && isset($result['type'])) {
            self::dispatchWebhookEvent($result['type'], $result['data']);
            return $result;
        }

        return false;
    }
621615
public static function jsonDecode($input)
    {
        $obj = json_decode($input);
        if (function_exists('json_last_error') && $errno = json_last_error()) {
            JWT::_handleJsonError($errno);
        } else if ($obj === null && $input !== 'null') {
            throw new \DomainException('Null result with non-null input');
        }
        return $obj;
    }
232487
protected function cleanObject($input)
	{
		// add to the cleaned list
		$this->parent->isClean($input);

		foreach ($value as $k => $v)
		{
			$value->{$k} = $this->clean($v);
		}
		return $input;
	}
1167006
public static function linkXHTMLSafe($input)
    {
        $regex = 'href="([^"]*(&(amp;){0})[^"]*)*?"';

        return preg_replace_callback(
            "#$regex#i",
            function ($m) {
                $rx = '&(?!amp;)';

                return preg_replace('#' . $rx . '#', '&amp;', $m[0]);
            },
            $input
        );
    }