@php
// --- FUNÇÕES DE LÓGICA DO PEDIDO ---
// Array de tradução de Status
$statusTranslations = [
"TYPED" => "Aberto",
"CLOSED" => "Fechado",
"AWAITING_PAYMENT" => "Aguardando Pgto",
"PROCESSING" => "Em Processamento",
"AWAITING_ANALYSIS" => "Em Análise",
"AWAITING_NF" => "Aguardando NF",
"NF_ISSUED" => "NF Emitida",
"TRANSPORT" => "Em Transporte",
"DELIVERED" => "Entregue",
"DELETED" => "Deletado"
];
// Array de tradução para Níveis de Usuário no Histórico
$historyUserLevels = [
"ManagerSalesConsultant" => "Gerente",
"SalesConsultant" => "Consultora",
"ADM" => "Sistema",
"ProcessOrders" => "Proc.Pedidos",
"Integration" => "Sistema",
];
function getTranslatedPaymentMethod($order) {
return match ($order->payment_method) {
'CREDIT_CARD' => 'Cartão de Crédito',
'PIX' => 'PIX',
'BILLET' => 'Boleto',
default => '',
};
}
function getTotalItemsQuantity($order) {
return $order->itens->sum('pivot.quantity');
}
function getTotalAmountWithoutDiscount($order) {
return $order->itens->sum(function ($item) {
return $item->pivot->quantity * $item->pivot->unitary_value;
});
}
function getTotalDiscountValue($order, $totalWithoutDiscount) {
return $totalWithoutDiscount - $order->amount_total;
}
function getFinalPayableAmount($order) {
return $order->amount_total + $order->shipping_value;
}
function isProductInExceptionList($productCode) {
$exceptionProducts = [
'005324',
'005328',
'005327',
'005325',
'005326',
'008333',
'008334'
];
return in_array($productCode, $exceptionProducts);
}
// function getTotalIncentiveAmount($order) {
// return $order->itens->reduce(function ($carry, $item) {
// $shouldAddIncentive = (
// $item->pivot->unitary_value > 0 &&
// !$item->pivot->special_discount &&
// $item->amount_incentive > 0 &&
// $item->local_presentation == 0
// ) || isProductInExceptionList($item->product->code);
// if ($shouldAddIncentive) {
// return $carry + ($item->pivot->quantity * $item->pivot->unitary_value);
// }
// return $carry;
// }, 0);
// }
function getItemDiscountInfo($item, $order) {
$discountPercentage = 0;
if ($item->pivot->special_discount) {
$discountPercentage = $item->pivot->special_discount_value;
} elseif ($item->discount_type == 'NO_DISCOUNT' || $item->discount_type == 'PERCENT') {
$discountPercentage = $item->discount_value;
} elseif ($order->sales_consultant->class == 'S') {
$discountPercentage = 51;
} else {
$discountPercentage = $order->campaign_benchmarking_range->discount ?? 0;
}
$finalUnitaryValue = $item->pivot->unitary_value * (1 - ($discountPercentage / 100));
$finalUnitaryValue = $finalUnitaryValue < 0 ? 0 : $finalUnitaryValue;
return (object)[
'discount_percentage' => $discountPercentage,
'final_unitary_value' => $finalUnitaryValue,
'final_total_value' => $finalUnitaryValue * $item->pivot->quantity,
];
}
// --- PRÉ-CÁLCULO DE VALORES PARA EVITAR REPETIÇÃO ---
$totalAmountWithoutDiscount = getTotalAmountWithoutDiscount($order);
@endphp
Pedido #{{ $order->id }}
Itens do Pedido
| # |
Cód. |
Produto |
Qtd |
V. Catál. |
V. Total |
Desc. |
V. Unit. |
V. Final |
@foreach($order->itens as $item)
@php $itemInfo = getItemDiscountInfo($item, $order); @endphp
| {{ $loop->iteration }} |
{{ $item->product->code }} |
{{ $item->product->name }}
@if($item->is_showroom)
SHOWROOM
@endif
|
{{ $item->pivot->quantity }} |
R$ {{ number_format($item->catalog_value, 2, ',', '.') }} |
R$ {{ number_format($item->pivot->unitary_value * $item->pivot->quantity, 2, ',', '.') }} |
{{ $itemInfo->discount_percentage }}% |
R$ {{ number_format($itemInfo->final_unitary_value, 2, ',', '.') }} |
R$ {{ number_format($itemInfo->final_total_value, 2, ',', '.') }} |
@endforeach
@if($order->itensScore->isNotEmpty())
Produtos de Pontuação
| # |
Cód. |
Produto |
Qtd |
Pontos |
@foreach($order->itensScore as $item)
| {{ $loop->iteration }} |
{{ $item->product->code }} |
{{ $item->product->name }} |
{{ $item->pivot->quantity }} |
{{ $item->value_score * $item->pivot->quantity }} |
@endforeach
@endif
| Subtotal: |
R$ {{ number_format($totalAmountWithoutDiscount, 2, ',', '.') }} |
| Valor Incentivo: |
R$ {{ number_format($order['value_incentive'], 2, ',', '.') }} |
| Desconto: |
R$ {{ number_format(getTotalDiscountValue($order, $totalAmountWithoutDiscount), 2, ',', '.') }} |
| Frete: |
R$ {{ number_format($order->shipping_value, 2, ',', '.') }} |
@if($order->discount_super_class_turbo > 0)
| Bônus Super Class: |
R$ {{ number_format($order->discount_super_class_turbo, 2, ',', '.') }} |
@endif
| Valor a Pagar: |
R$ {{ number_format(getFinalPayableAmount($order), 2, ',', '.') }} |