bills import/export
This commit is contained in:
parent
45c02d5502
commit
1383dd4758
@ -9,7 +9,7 @@ class BillHistories extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::usingSearchString(request('search'));
|
||||
$model = Model::with(['bill'])->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('bill_id', (array) $this->ids);
|
||||
@ -18,10 +18,17 @@ class BillHistories extends Export
|
||||
return $model->get();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->bill_number = $model->bill->bill_number;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_id',
|
||||
'bill_number',
|
||||
'status',
|
||||
'notify',
|
||||
'description',
|
||||
|
@ -9,7 +9,7 @@ class BillItemTaxes extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::usingSearchString(request('search'));
|
||||
$model = Model::with(['bill', 'item', 'tax'])->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('bill_id', (array) $this->ids);
|
||||
@ -18,13 +18,21 @@ class BillItemTaxes extends Export
|
||||
return $model->get();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->bill_number = $model->bill->bill_number;
|
||||
$model->item_name = $model->item->name;
|
||||
$model->tax_rate = $model->tax->rate;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_id',
|
||||
'bill_item_id',
|
||||
'tax_id',
|
||||
'name',
|
||||
'bill_number',
|
||||
'item_name',
|
||||
'tax_rate',
|
||||
'amount',
|
||||
];
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ class BillItems extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::usingSearchString(request('search'));
|
||||
$model = Model::with(['bill', 'item'])->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('bill_id', (array) $this->ids);
|
||||
@ -18,12 +18,19 @@ class BillItems extends Export
|
||||
return $model->get();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->bill_number = $model->bill->bill_number;
|
||||
$model->item_name = $model->item->name;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_id',
|
||||
'item_id',
|
||||
'name',
|
||||
'bill_number',
|
||||
'item_name',
|
||||
'quantity',
|
||||
'price',
|
||||
'total',
|
||||
|
@ -9,7 +9,7 @@ class BillTotals extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::usingSearchString(request('search'));
|
||||
$model = Model::with(['bill'])->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('bill_id', (array) $this->ids);
|
||||
@ -18,11 +18,17 @@ class BillTotals extends Export
|
||||
return $model->get();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->bill_number = $model->bill->bill_number;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_id',
|
||||
'bill_number',
|
||||
'code',
|
||||
'name',
|
||||
'amount',
|
||||
|
@ -9,7 +9,7 @@ class BillTransactions extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::type('expense')->isDocument()->usingSearchString(request('search'));
|
||||
$model = Model::with(['account', 'category', 'contact', 'bill'])->type('expense')->isDocument()->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('document_id', (array) $this->ids);
|
||||
@ -18,17 +18,27 @@ class BillTransactions extends Export
|
||||
return $model->get();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->bill_number = $model->bill->bill_number;
|
||||
$model->account_name = $model->account->name;
|
||||
$model->category_name = $model->category->name;
|
||||
$model->contact_email = $model->contact->email;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'bill_number',
|
||||
'paid_at',
|
||||
'amount',
|
||||
'currency_code',
|
||||
'currency_rate',
|
||||
'account_id',
|
||||
'document_id',
|
||||
'contact_id',
|
||||
'category_id',
|
||||
'account_name',
|
||||
'contact_email',
|
||||
'category_name',
|
||||
'description',
|
||||
'payment_method',
|
||||
'reference',
|
||||
|
@ -9,7 +9,7 @@ class Bills extends Export
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
$model = Model::usingSearchString(request('search'));
|
||||
$model = Model::with(['category'])->usingSearchString(request('search'));
|
||||
|
||||
if (!empty($this->ids)) {
|
||||
$model->whereIn('id', (array) $this->ids);
|
||||
@ -18,6 +18,13 @@ class Bills extends Export
|
||||
return $model->get();
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->category_name = $model->category->name;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
@ -29,8 +36,7 @@ class Bills extends Export
|
||||
'amount',
|
||||
'currency_code',
|
||||
'currency_rate',
|
||||
'category_id',
|
||||
'contact_id',
|
||||
'category_name',
|
||||
'contact_name',
|
||||
'contact_email',
|
||||
'contact_tax_number',
|
||||
|
34
app/Http/Requests/Purchase/BillItemTax.php
Normal file
34
app/Http/Requests/Purchase/BillItemTax.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Purchase;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
|
||||
class BillItemTax extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'bill_id' => 'required|integer',
|
||||
'bill_item_id' => 'required|integer',
|
||||
'tax_id' => 'required|integer',
|
||||
'name' => 'required|string',
|
||||
'amount' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
@ -3,13 +3,19 @@
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Purchase\BillHistory as Model;
|
||||
use App\Http\Requests\Purchase\BillHistory as Request;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillHistory as Model;
|
||||
|
||||
class BillHistories extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after 3.2 release
|
||||
if ($row['bill_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
@ -17,6 +23,8 @@ class BillHistories extends Import
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['bill_id'] = Bill::number($row['bill_number'])->pluck('id')->first();
|
||||
|
||||
$row['notify'] = (int) $row['notify'];
|
||||
|
||||
return $row;
|
||||
@ -24,6 +32,11 @@ class BillHistories extends Import
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,53 @@
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Http\Requests\Purchase\BillItemTax as Request;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillItem;
|
||||
use App\Models\Purchase\BillItemTax as Model;
|
||||
|
||||
class BillItemTaxes extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after 3.2 release
|
||||
if ($row['bill_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['bill_id'] = Bill::number($row['bill_number'])->pluck('id')->first();
|
||||
|
||||
if (empty($row['invoice_item_id']) && !empty($row['item_name'])) {
|
||||
$item_id = Item::name($row['item_name'])->pluck('id')->first();
|
||||
$row['invoice_item_id'] = BillItem::where('item_id', $item_id)->pluck('id')->first();
|
||||
}
|
||||
|
||||
$row['tax_id'] = $this->getTaxId($row);
|
||||
|
||||
if (empty($row['name']) && !empty($row['item_name'])) {
|
||||
$row['name'] = $row['item_name'];
|
||||
}
|
||||
|
||||
$row['amount'] = (double) $row['amount'];
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,9 @@
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Purchase\BillItem as Model;
|
||||
use App\Http\Requests\Purchase\BillItem as Request;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillItem as Model;
|
||||
|
||||
class BillItems extends Import
|
||||
{
|
||||
@ -13,8 +14,31 @@ class BillItems extends Import
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['bill_id'] = Bill::number($row['bill_number'])->pluck('id')->first();
|
||||
|
||||
if (empty($row['item_id']) && !empty($row['item_name'])) {
|
||||
$row['item_id'] = $this->getItemIdFromName($row);
|
||||
|
||||
$row['name'] = $row['item_name'];
|
||||
}
|
||||
|
||||
$row['tax'] = (double) $row['tax'];
|
||||
$row['tax_id'] = 0;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,9 @@
|
||||
namespace App\Imports\Purchases\Sheets;
|
||||
|
||||
use App\Abstracts\Import;
|
||||
use App\Models\Purchase\BillTotal as Model;
|
||||
use App\Http\Requests\Purchase\BillTotal as Request;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillTotal as Model;
|
||||
|
||||
class BillTotals extends Import
|
||||
{
|
||||
@ -13,8 +14,22 @@ class BillTotals extends Import
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['bill_id'] = Bill::number($row['bill_number'])->pluck('id')->first();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
unset($rules['bill_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,20 @@ class BillTransactions extends Import
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['type'] = 'expense';
|
||||
$row['account_id'] = $this->getAccountId($row);
|
||||
$row['category_id'] = $this->getCategoryId($row, 'expense');
|
||||
$row['contact_id'] = $this->getContactId($row, 'vendor');
|
||||
$row['document_id'] = $this->getDocumentId($row);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
$rules = (new Request())->rules();
|
||||
|
||||
$rules['bill_number'] = 'required|string';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,16 @@ class Bills extends Import
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$row = parent::map($row);
|
||||
|
||||
$row['category_id'] = $this->getCategoryId($row, 'expense');
|
||||
$row['contact_id'] = $this->getContactId($row, 'vendor');
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return (new Request())->rules();
|
||||
|
@ -11,6 +11,11 @@ class InvoiceHistories extends Import
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// @todo remove after 3.2 release
|
||||
if ($row['invoice_number'] == $this->empty_field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ use App\Models\Common\Item;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceItem;
|
||||
use App\Models\Sale\InvoiceItemTax as Model;
|
||||
use App\Models\Setting\Tax;
|
||||
|
||||
class InvoiceItemTaxes extends Import
|
||||
{
|
||||
@ -19,8 +18,6 @@ class InvoiceItemTaxes extends Import
|
||||
return null;
|
||||
}
|
||||
|
||||
$row['invoice_id'] = Invoice::number($row['invoice_number'])->pluck('id')->first();
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
|
@ -50,14 +50,14 @@ trait Import
|
||||
|
||||
$type = !empty($type) ? $type : (!empty($row['type']) ? (($row['type'] == 'income') ? 'customer' : 'vendor') : 'customer');
|
||||
|
||||
if (empty($id) && !empty($row['contact_name'])) {
|
||||
$id = $this->getContactIdFromName($row, $type);
|
||||
}
|
||||
|
||||
if (empty($row['contact_id']) && !empty($row['contact_email'])) {
|
||||
$id = $this->getContactIdFromEmail($row, $type);
|
||||
}
|
||||
|
||||
if (empty($id) && !empty($row['contact_name'])) {
|
||||
$id = $this->getContactIdFromName($row, $type);
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
@ -116,9 +116,9 @@ trait Import
|
||||
'currency_code' => $row['currency_code'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'name' => $row['currency_code'],
|
||||
'number' => Account::max('number') + 1,
|
||||
'opening_balance' => 0,
|
||||
'name' => !empty($row['account_name']) ? $row['account_name'] : $row['currency_code'],
|
||||
'number' => !empty($row['account_number']) ? $row['account_number'] : Account::max('number') + 1,
|
||||
'opening_balance' => !empty($row['opening_balance']) ? $row['opening_balance'] : 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
@ -129,9 +129,9 @@ trait Import
|
||||
'name' => $row['account_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'number' => Account::max('number') + 1,
|
||||
'currency_code' => setting('default.currency'),
|
||||
'opening_balance' => 0,
|
||||
'number' => !empty($row['account_number']) ? $row['account_number'] : Account::max('number') + 1,
|
||||
'currency_code' => !empty($row['currency_code']) ? $row['currency_code'] : setting('default.currency'),
|
||||
'opening_balance' => !empty($row['opening_balance']) ? $row['opening_balance'] : 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
@ -142,9 +142,9 @@ trait Import
|
||||
'number' => $row['account_number'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'name' => $row['account_number'],
|
||||
'currency_code' => setting('default.currency'),
|
||||
'opening_balance' => 0,
|
||||
'name' => !empty($row['account_name']) ? $row['account_name'] : $row['account_number'],
|
||||
'currency_code' => !empty($row['currency_code']) ? $row['currency_code'] : setting('default.currency'),
|
||||
'opening_balance' => !empty($row['opening_balance']) ? $row['opening_balance'] : 0,
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
@ -156,7 +156,7 @@ trait Import
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'color' => '#' . dechex(rand(0x000000, 0xFFFFFF)),
|
||||
'color' => !empty($row['category_color']) ? $row['category_color'] : '#' . dechex(rand(0x000000, 0xFFFFFF)),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
@ -168,8 +168,8 @@ trait Import
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'name' => $row['contact_email'],
|
||||
'currency_code' => setting('default.currency'),
|
||||
'name' => !empty($row['contact_name']) ? $row['contact_name'] : $row['contact_email'],
|
||||
'currency_code' => !empty($row['contact_currency']) ? $row['contact_currency'] : setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
@ -181,7 +181,7 @@ trait Import
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'currency_code' => setting('default.currency'),
|
||||
'currency_code' => !empty($row['contact_currency']) ? $row['contact_currency'] : setting('default.currency'),
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
@ -192,8 +192,8 @@ trait Import
|
||||
'name' => $row['item_name'],
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'sale_price' => $row['price'],
|
||||
'purchase_price' => $row['price'],
|
||||
'sale_price' => !empty($row['sale_price']) ? $row['sale_price'] : $row['price'],
|
||||
'purchase_price' => !empty($row['purchase_price']) ? $row['purchase_price'] : $row['price'],
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
@ -205,7 +205,7 @@ trait Import
|
||||
], [
|
||||
'company_id' => session('company_id'),
|
||||
'type' => $type,
|
||||
'name' => $row['tax_rate'],
|
||||
'name' => !empty($row['tax_name']) ? $row['tax_name'] : $row['tax_rate'],
|
||||
'enabled' => 1,
|
||||
])->id;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user