Payment Term Functionality Completed. Extra Translations Pending.
This commit is contained in:
parent
538dd29ddf
commit
006046975a
|
|
@ -166,10 +166,17 @@
|
|||
</div>
|
||||
|
||||
<div class="row">
|
||||
<span class="label">{{ __('admin::app.sales.invoices.order-date') }} </span>
|
||||
<span class="label">{{ __('admin::app.sales.invoices.order-date') }} -</span>
|
||||
<span class="value">{{ $invoice->created_at->format('d-m-Y') }}</span>
|
||||
</div>
|
||||
|
||||
@if ($invoice->hasPaymentTerm())
|
||||
<div class="row">
|
||||
<span class="label">{{ __('admin::app.admin.system.payment-terms') }} -</span>
|
||||
<span class="value">{{ $invoice->getFormattedPaymentTerm() }}</span>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="table address">
|
||||
<table>
|
||||
<thead>
|
||||
|
|
|
|||
|
|
@ -4,11 +4,24 @@ namespace Webkul\Sales\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\Invoice as InvoiceContract;
|
||||
use Webkul\Sales\Traits\PaymentTerm;
|
||||
|
||||
class Invoice extends Model implements InvoiceContract
|
||||
{
|
||||
use PaymentTerm;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var string[]|bool
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Invoice status.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $statusLabel = [
|
||||
'pending' => 'Pending',
|
||||
'paid' => 'Paid',
|
||||
|
|
@ -16,7 +29,7 @@ class Invoice extends Model implements InvoiceContract
|
|||
];
|
||||
|
||||
/**
|
||||
* Returns the status label from status code
|
||||
* Returns the status label from status code.
|
||||
*/
|
||||
public function getStatusLabelAttribute()
|
||||
{
|
||||
|
|
@ -63,4 +76,4 @@ class Invoice extends Model implements InvoiceContract
|
|||
return $this->belongsTo(OrderAddressProxy::modelClass(), 'order_address_id')
|
||||
->where('address_type', OrderAddress::ADDRESS_TYPE_BILLING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Webkul\Sales\Contracts\Invoice;
|
||||
use Webkul\Sales\Generators\InvoiceSequencer;
|
||||
|
|
@ -12,28 +12,28 @@ use Webkul\Sales\Generators\InvoiceSequencer;
|
|||
class InvoiceRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* OrderRepository object
|
||||
* Order repository instance.
|
||||
*
|
||||
* @var \Webkul\Sales\Repositories\OrderRepository
|
||||
*/
|
||||
protected $orderRepository;
|
||||
|
||||
/**
|
||||
* OrderItemRepository object
|
||||
* Order's item repository instance.
|
||||
*
|
||||
* @var \Webkul\Sales\Repositories\OrderItemRepository
|
||||
*/
|
||||
protected $orderItemRepository;
|
||||
|
||||
/**
|
||||
* InvoiceItemRepository object
|
||||
* Invoice's item repository instance.
|
||||
*
|
||||
* @var \Webkul\Sales\Repositories\InvoiceItemRepository
|
||||
*/
|
||||
protected $invoiceItemRepository;
|
||||
|
||||
/**
|
||||
* DownloadableLinkPurchasedRepository object
|
||||
* Downloadable link purchased repository instance.
|
||||
*
|
||||
* @var \Webkul\Sales\Repositories\DownloadableLinkPurchasedRepository
|
||||
*/
|
||||
|
|
@ -54,8 +54,7 @@ class InvoiceRepository extends Repository
|
|||
InvoiceItemRepository $invoiceItemRepository,
|
||||
DownloadableLinkPurchasedRepository $downloadableLinkPurchasedRepository,
|
||||
App $app
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->orderRepository = $orderRepository;
|
||||
|
||||
$this->orderItemRepository = $orderItemRepository;
|
||||
|
|
@ -70,17 +69,18 @@ class InvoiceRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Specify Model class name
|
||||
* Specify model class name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
function model()
|
||||
public function model()
|
||||
{
|
||||
return Invoice::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create invoice.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $invoiceState
|
||||
* @param string $orderState
|
||||
|
|
@ -135,10 +135,10 @@ class InvoiceRepository extends Repository
|
|||
'base_price' => $orderItem->base_price,
|
||||
'total' => $orderItem->price * $qty,
|
||||
'base_total' => $orderItem->base_price * $qty,
|
||||
'tax_amount' => ( ($orderItem->tax_amount / $orderItem->qty_ordered) * $qty ),
|
||||
'base_tax_amount' => ( ($orderItem->base_tax_amount / $orderItem->qty_ordered) * $qty ),
|
||||
'discount_amount' => ( ($orderItem->discount_amount / $orderItem->qty_ordered) * $qty ),
|
||||
'base_discount_amount' => ( ($orderItem->base_discount_amount / $orderItem->qty_ordered) * $qty ),
|
||||
'tax_amount' => (($orderItem->tax_amount / $orderItem->qty_ordered) * $qty),
|
||||
'base_tax_amount' => (($orderItem->base_tax_amount / $orderItem->qty_ordered) * $qty),
|
||||
'discount_amount' => (($orderItem->discount_amount / $orderItem->qty_ordered) * $qty),
|
||||
'base_discount_amount' => (($orderItem->base_discount_amount / $orderItem->qty_ordered) * $qty),
|
||||
'product_id' => $orderItem->product_id,
|
||||
'product_type' => $orderItem->product_type,
|
||||
'additional' => $orderItem->additional,
|
||||
|
|
@ -147,8 +147,8 @@ class InvoiceRepository extends Repository
|
|||
if ($orderItem->getTypeInstance()->isComposite()) {
|
||||
foreach ($orderItem->children as $childOrderItem) {
|
||||
$finalQty = $childOrderItem->qty_ordered
|
||||
? ($childOrderItem->qty_ordered / $orderItem->qty_ordered) * $qty
|
||||
: $orderItem->qty_ordered;
|
||||
? ($childOrderItem->qty_ordered / $orderItem->qty_ordered) * $qty
|
||||
: $orderItem->qty_ordered;
|
||||
|
||||
$this->invoiceItemRepository->create([
|
||||
'invoice_id' => $invoice->id,
|
||||
|
|
@ -170,7 +170,8 @@ class InvoiceRepository extends Repository
|
|||
'additional' => $childOrderItem->additional,
|
||||
]);
|
||||
|
||||
if ($childOrderItem->product
|
||||
if (
|
||||
$childOrderItem->product
|
||||
&& ! $childOrderItem->getTypeInstance()->isStockable()
|
||||
&& $childOrderItem->getTypeInstance()->showQuantityBox()
|
||||
) {
|
||||
|
|
@ -184,7 +185,8 @@ class InvoiceRepository extends Repository
|
|||
|
||||
$this->orderItemRepository->collectTotals($childOrderItem);
|
||||
}
|
||||
} elseif ($orderItem->product
|
||||
} elseif (
|
||||
$orderItem->product
|
||||
&& ! $orderItem->getTypeInstance()->isStockable()
|
||||
&& $orderItem->getTypeInstance()->showQuantityBox()
|
||||
) {
|
||||
|
|
@ -234,8 +236,10 @@ class InvoiceRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \Webkul\Sales\Contracts\Invoice $invoice
|
||||
* @return \Webkul\Sales\Contracts\Invoice
|
||||
* Collect totals.
|
||||
*
|
||||
* @param \Webkul\Sales\Models\Invoice $invoice
|
||||
* @return \Webkul\Sales\Models\Invoice
|
||||
*/
|
||||
public function collectTotals($invoice)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Traits;
|
||||
|
||||
trait PaymentTerm
|
||||
{
|
||||
/**
|
||||
* Wether the core config have payment term or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPaymentTerm()
|
||||
{
|
||||
return $this->getPaymentTerm()
|
||||
? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get payment term from the core config in days.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPaymentTerm()
|
||||
{
|
||||
static $dueDuration = 0;
|
||||
|
||||
if ($dueDuration) {
|
||||
return $dueDuration;
|
||||
}
|
||||
|
||||
return $dueDuration = (int) core()->getConfigData('sales.invoice_setttings.payment_terms.due_duration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatted payment terms for invoice. Handled singular and plural case also.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormattedPaymentTerm()
|
||||
{
|
||||
$dueDuration = $this->getPaymentTerm();
|
||||
|
||||
if ($dueDuration > 1) {
|
||||
return __('admin::app.admin.system.due-duration-days', ['due-duration' => $dueDuration]);
|
||||
}
|
||||
|
||||
return $dueDuration
|
||||
? __('admin::app.admin.system.due-duration-day', ['due-duration' => $dueDuration])
|
||||
: __('admin::app.admin.system.due-duration-day', ['due-duration' => 0]);
|
||||
}
|
||||
}
|
||||
|
|
@ -173,6 +173,13 @@
|
|||
<span class="value">{{ core()->formatDate($invoice->order->created_at, 'd-m-Y') }}</span>
|
||||
</div>
|
||||
|
||||
@if ($invoice->hasPaymentTerm())
|
||||
<div class="row">
|
||||
<span class="label">{{ __('shop::app.customer.account.order.view.payment-terms') }} -</span>
|
||||
<span class="value">{{ $invoice->getFormattedPaymentTerm() }}</span>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="table address">
|
||||
<table>
|
||||
<thead>
|
||||
|
|
|
|||
Loading…
Reference in New Issue