getType(), [
CreditHistory::TYPE_DEBIT,
CreditHistory::TYPE_PAYMENT,
]);
}
public function isTypeCredit(CreditHistory $creditHistory): bool
{
return in_array($creditHistory->getType(), [
CreditHistory::TYPE_CREDIT,
CreditHistory::TYPE_INITIAL_CREDIT,
CreditHistory::TYPE_REFUND
]);
}
public function getAmount(CreditHistory $creditHistory, bool $format = false): string
{
if ($format) {
return number_format($creditHistory->getAmount(), 2) . ' €';
} else {
return $creditHistory->getAmount();
}
}
/**
* Retourne le libellé du CreditHistory informant de son type et
* éventuellement de la date de sa commande associée.
*
*/
public function getStrWording(CreditHistory $creditHistory): string
{
$str = '';
$type = $creditHistory->getType();
if (CreditHistory::TYPE_INITIAL_CREDIT == $type) {
$str = 'Crédit initial';
} elseif (CreditHistory::TYPE_CREDIT == $type) {
$str = 'Crédit';
} elseif (CreditHistory::TYPE_PAYMENT == $type) {
$str = 'Paiement';
} elseif (CreditHistory::TYPE_REFUND == $type) {
$str = 'Remboursement';
} elseif (CreditHistory::TYPE_DEBIT == $type) {
$str = 'Débit';
}
if (CreditHistory::TYPE_PAYMENT == $type || CreditHistory::TYPE_REFUND == $type) {
$order = $creditHistory->getOrderObject();
if ($order && $order->distribution) {
$str .= '
Commande : ' . date('d/m/Y', strtotime($order->distribution->date));
} else {
$str .= '
Commande supprimée';
}
}
return $str;
}
/**
* Retourne les informations à ajouter au commentaire du CreditHistorique
* (libellé, montant, client, action) au format HTML.
*
*/
public function getStrComment(CreditHistory $creditHistory): string
{
$str = '';
if (strlen($creditHistory->getComment())) {
$str .= '
';
}
$str .= $this->getStrWording($creditHistory);
$order = $creditHistory->getOrderObject();
if ($order) {
$str .= '
Montant de la commande : ' . $order->getAmountWithTax(Order::AMOUNT_TOTAL, true);
}
$user = $creditHistory->getUserObject();
if ($user) {
$str .= '
Client : ' . Html::encode($user->getName() . ' CreditHistorySolver.php' . $user->getLastname());
}
$userAction = $creditHistory->getUserActionObject();
if ($userAction) {
$str .= '
Action : ' . Html::encode($userAction->getName() . ' CreditHistorySolver.php' . $userAction->getLastname());
}
return $str;
}
public function getDate(CreditHistory $creditHistory, bool $format = false): string
{
$date = $creditHistory->getDate();
if ($format) {
return date('d/m/Y à H:i:s', strtotime($date));
} else {
return $date;
}
}
public function getStrMeanPayment(CreditHistory $creditHistory): string
{
return MeanPayment::getStrBy($creditHistory->getMeanPayment());
}
// strUserAction
public function getStrUserAction(CreditHistory $creditHistory): string
{
$userAction = $creditHistory->getUserActionObject();
if ($userAction) {
return $userAction->getName() . ' CreditHistorySolver.php' . $userAction->getlastname();
} else {
return 'Système';
}
}
}