Merge pull request #3006 from CihanSenturk/import/export-improvements
Import/export improvements
This commit is contained in:
commit
1f42081b98
@ -20,6 +20,7 @@ class Transactions extends Export implements WithColumnFormatting
|
|||||||
$model->contact_email = $model->contact->email;
|
$model->contact_email = $model->contact->email;
|
||||||
$model->category_name = $model->category->name;
|
$model->category_name = $model->category->name;
|
||||||
$model->invoice_bill_number = $model->document->document_number ?? 0;
|
$model->invoice_bill_number = $model->document->document_number ?? 0;
|
||||||
|
$model->parent_number = Model::isRecurring()->find($model->parent_id)?->number;
|
||||||
|
|
||||||
return parent::map($model);
|
return parent::map($model);
|
||||||
}
|
}
|
||||||
@ -41,6 +42,7 @@ class Transactions extends Export implements WithColumnFormatting
|
|||||||
'payment_method',
|
'payment_method',
|
||||||
'reference',
|
'reference',
|
||||||
'reconciled',
|
'reconciled',
|
||||||
|
'parent_number',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ class Bills extends Export implements WithColumnFormatting
|
|||||||
$model->bill_number = $model->document_number;
|
$model->bill_number = $model->document_number;
|
||||||
$model->billed_at = $model->issued_at;
|
$model->billed_at = $model->issued_at;
|
||||||
$model->contact_country = $country;
|
$model->contact_country = $country;
|
||||||
|
$model->parent_number = Model::billRecurring()->find($model->parent_id)?->document_number ?? null;
|
||||||
|
|
||||||
return parent::map($model);
|
return parent::map($model);
|
||||||
}
|
}
|
||||||
@ -52,6 +53,7 @@ class Bills extends Export implements WithColumnFormatting
|
|||||||
'contact_zip_code',
|
'contact_zip_code',
|
||||||
'contact_city',
|
'contact_city',
|
||||||
'notes',
|
'notes',
|
||||||
|
'parent_number',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ class Invoices extends Export implements WithColumnFormatting
|
|||||||
$model->invoice_number = $model->document_number;
|
$model->invoice_number = $model->document_number;
|
||||||
$model->invoiced_at = $model->issued_at;
|
$model->invoiced_at = $model->issued_at;
|
||||||
$model->contact_country = $country;
|
$model->contact_country = $country;
|
||||||
|
$model->parent_number = Model::invoiceRecurring()->find($model->parent_id)?->document_number;
|
||||||
|
|
||||||
return parent::map($model);
|
return parent::map($model);
|
||||||
}
|
}
|
||||||
@ -53,6 +54,7 @@ class Invoices extends Export implements WithColumnFormatting
|
|||||||
'contact_city',
|
'contact_city',
|
||||||
'notes',
|
'notes',
|
||||||
'footer',
|
'footer',
|
||||||
|
'parent_number',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ class Transactions extends Import
|
|||||||
$row['category_id'] = $this->getCategoryId($row);
|
$row['category_id'] = $this->getCategoryId($row);
|
||||||
$row['contact_id'] = $this->getContactId($row);
|
$row['contact_id'] = $this->getContactId($row);
|
||||||
$row['document_id'] = $this->getDocumentId($row);
|
$row['document_id'] = $this->getDocumentId($row);
|
||||||
|
$row['parent_id'] = $this->getParentId($row);
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ class Bills extends Import
|
|||||||
$row['currency_code'] = $this->getCurrencyCode($row);
|
$row['currency_code'] = $this->getCurrencyCode($row);
|
||||||
$row['type'] = Model::BILL_TYPE;
|
$row['type'] = Model::BILL_TYPE;
|
||||||
$row['contact_country'] = !empty($country) ? $country : null;
|
$row['contact_country'] = !empty($country) ? $country : null;
|
||||||
|
$row['parent_id'] = $this->getParentId($row);
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ class Invoices extends Import
|
|||||||
$row['currency_code'] = $this->getCurrencyCode($row);
|
$row['currency_code'] = $this->getCurrencyCode($row);
|
||||||
$row['type'] = Model::INVOICE_TYPE;
|
$row['type'] = Model::INVOICE_TYPE;
|
||||||
$row['contact_country'] = !empty($country) ? $country : null;
|
$row['contact_country'] = !empty($country) ? $country : null;
|
||||||
|
$row['parent_id'] = $this->getParentId($row);
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,11 @@ class Transaction extends Model
|
|||||||
return $this->belongsTo('App\Models\Auth\User', 'contact_id', 'id');
|
return $this->belongsTo('App\Models\Auth\User', 'contact_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeNumber(Builder $query, string $number): Builder
|
||||||
|
{
|
||||||
|
return $query->where('number', '=', $number);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeType(Builder $query, $types): Builder
|
public function scopeType(Builder $query, $types): Builder
|
||||||
{
|
{
|
||||||
if (empty($types)) {
|
if (empty($types)) {
|
||||||
|
@ -13,6 +13,10 @@ class Recurring extends Model
|
|||||||
public const ACTIVE_STATUS = 'active';
|
public const ACTIVE_STATUS = 'active';
|
||||||
public const END_STATUS = 'ended';
|
public const END_STATUS = 'ended';
|
||||||
public const COMPLETE_STATUS = 'completed';
|
public const COMPLETE_STATUS = 'completed';
|
||||||
|
public const INVOICE_RECURRING_TYPE = 'invoice-recurring';
|
||||||
|
public const BILL_RECURRING_TYPE = 'bill-recurring';
|
||||||
|
public const INCOME_RECURRING_TYPE = 'income-recurring';
|
||||||
|
public const EXPENSE_RECURRING_TYPE = 'expense-recurring';
|
||||||
|
|
||||||
protected $table = 'recurring';
|
protected $table = 'recurring';
|
||||||
|
|
||||||
@ -55,6 +59,21 @@ class Recurring extends Model
|
|||||||
return $this->morphTo()->isRecurring();
|
return $this->morphTo()->isRecurring();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function documents()
|
||||||
|
{
|
||||||
|
return $this->morphedByMany('App\Models\Document\Document', 'recurable');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invoices()
|
||||||
|
{
|
||||||
|
return $this->documents()->where('type', self::INVOICE_RECURRING_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bills()
|
||||||
|
{
|
||||||
|
return $this->documents()->where('type', self::BILL_RECURRING_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeActive(Builder $query): Builder
|
public function scopeActive(Builder $query): Builder
|
||||||
{
|
{
|
||||||
return $query->where($this->qualifyColumn('status'), '=', static::ACTIVE_STATUS);
|
return $query->where($this->qualifyColumn('status'), '=', static::ACTIVE_STATUS);
|
||||||
@ -69,4 +88,49 @@ class Recurring extends Model
|
|||||||
{
|
{
|
||||||
return $query->where($this->qualifyColumn('status'), '=', static::COMPLETE_STATUS);
|
return $query->where($this->qualifyColumn('status'), '=', static::COMPLETE_STATUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeDocument(Builder $query, $type): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('recurable_type'), '=', 'App\\Models\\Document\\Document')
|
||||||
|
->whereHas('recurable', function (Builder $query) use ($type) {
|
||||||
|
$query->where('type', $type);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeInvoice(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('recurable_type'), '=', 'App\\Models\\Document\\Document')
|
||||||
|
->whereHas('recurable', function (Builder $query) {
|
||||||
|
$query->where('type', self::INVOICE_RECURRING_TYPE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeBill(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('recurable_type'), '=', 'App\\Models\\Document\\Document')
|
||||||
|
->whereHas('recurable', function (Builder $query) {
|
||||||
|
$query->where('type', self::BILL_RECURRING_TYPE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeTransaction(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('recurable_type'), '=', 'App\\Models\\Banking\\Transaction');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeExpenseTransaction(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('recurable_type'), '=', 'App\\Models\\Banking\\Transaction')
|
||||||
|
->whereHas('recurable', function (Builder $query) {
|
||||||
|
$query->where('type', self::EXPENSE_RECURRING_TYPE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeIncomeTransaction(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('recurable_type'), '=', 'App\\Models\\Banking\\Transaction')
|
||||||
|
->whereHas('recurable', function (Builder $query) {
|
||||||
|
$query->where('type', self::INCOME_RECURRING_TYPE);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,24 @@ class DocumentHistory extends Model
|
|||||||
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE);
|
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeInvoiceRecurring(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_RECURRING_TYPE)
|
||||||
|
->whereHas('document.recurring', function (Builder $query) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeBill(Builder $query)
|
public function scopeBill(Builder $query)
|
||||||
{
|
{
|
||||||
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE);
|
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeBillRecurring(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_RECURRING_TYPE)
|
||||||
|
->whereHas('document.recurring', function (Builder $query) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,11 +100,27 @@ class DocumentItem extends Model
|
|||||||
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE);
|
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeInvoiceRecurring(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_RECURRING_TYPE)
|
||||||
|
->whereHas('document.recurring', function (Builder $query) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeBill(Builder $query)
|
public function scopeBill(Builder $query)
|
||||||
{
|
{
|
||||||
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE);
|
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeBillRecurring(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_RECURRING_TYPE)
|
||||||
|
->whereHas('document.recurring', function (Builder $query) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function getDiscountAttribute(): string
|
public function getDiscountAttribute(): string
|
||||||
{
|
{
|
||||||
if (setting('localisation.percent_position', 'after') === 'after') {
|
if (setting('localisation.percent_position', 'after') === 'after') {
|
||||||
|
@ -41,11 +41,27 @@ class DocumentItemTax extends Model
|
|||||||
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE);
|
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeInvoiceRecurring(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_RECURRING_TYPE)
|
||||||
|
->whereHas('document.recurring', function (Builder $query) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeBill(Builder $query)
|
public function scopeBill(Builder $query)
|
||||||
{
|
{
|
||||||
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE);
|
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeBillRecurring(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_RECURRING_TYPE)
|
||||||
|
->whereHas('document.recurring', function (Builder $query) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function onCloned($src)
|
public function onCloned($src)
|
||||||
{
|
{
|
||||||
$document_item = DocumentItem::find($this->document_item_id);
|
$document_item = DocumentItem::find($this->document_item_id);
|
||||||
|
@ -33,11 +33,27 @@ class DocumentTotal extends Model
|
|||||||
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE);
|
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeInvoiceRecurring(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_RECURRING_TYPE)
|
||||||
|
->whereHas('document.recurring', function (Builder $query) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeBill(Builder $query)
|
public function scopeBill(Builder $query)
|
||||||
{
|
{
|
||||||
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE);
|
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeBillRecurring(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where($this->qualifyColumn('type'), '=', Document::BILL_RECURRING_TYPE)
|
||||||
|
->whereHas('document.recurring', function (Builder $query) {
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeCode($query, $code)
|
public function scopeCode($query, $code)
|
||||||
{
|
{
|
||||||
return $query->where('code', '=', $code);
|
return $query->where('code', '=', $code);
|
||||||
|
@ -16,6 +16,7 @@ use App\Jobs\Setting\CreateCurrency;
|
|||||||
use App\Jobs\Setting\CreateTax;
|
use App\Jobs\Setting\CreateTax;
|
||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
|
use App\Models\Banking\Transaction;
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
use App\Models\Common\Item;
|
use App\Models\Common\Item;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
@ -149,6 +150,21 @@ trait Import
|
|||||||
return is_null($id) ? $id : (int) $id;
|
return is_null($id) ? $id : (int) $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParentId($row)
|
||||||
|
{
|
||||||
|
$id = isset($row['parent_id']) ? $row['parent_id'] : null;
|
||||||
|
|
||||||
|
if (empty($id) && isset($row['document_number']) && !empty($row['parent_number'])) {
|
||||||
|
$id = Document::number($row['parent_number'])->pluck('id')->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($id) && isset($row['number']) && !empty($row['parent_number'])) {
|
||||||
|
$id = Transaction::number($row['parent_number'])->pluck('id')->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_null($id) ? $id : (int) $id;
|
||||||
|
}
|
||||||
|
|
||||||
public function getItemId($row, $type = null)
|
public function getItemId($row, $type = null)
|
||||||
{
|
{
|
||||||
$id = isset($row['item_id']) ? $row['item_id'] : null;
|
$id = isset($row['item_id']) ? $row['item_id'] : null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user