added export and improved import
This commit is contained in:
@ -37,7 +37,7 @@ class Items extends Controller
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
return redirect('common/items');
|
||||
return redirect()->route('items.index');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +76,7 @@ class Items extends Controller
|
||||
|
||||
flash($message)->success();
|
||||
|
||||
return redirect('common/items');
|
||||
return redirect()->route('items.index');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +94,7 @@ class Items extends Controller
|
||||
|
||||
flash($message)->success();
|
||||
|
||||
return redirect('common/items/' . $clone->id . '/edit');
|
||||
return redirect()->route('items.edit', $item->id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,20 +106,26 @@ class Items extends Controller
|
||||
*/
|
||||
public function import(ImportFile $import)
|
||||
{
|
||||
$rows = $import->all();
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) {
|
||||
if ($sheet->getTitle() != 'items') {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
// Loop through all rows
|
||||
$sheet->each(function ($row) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
|
||||
Item::create($data);
|
||||
}
|
||||
Item::create($data);
|
||||
});
|
||||
});
|
||||
|
||||
$message = trans('messages.success.imported', ['type' => trans_choice('general.items', 2)]);
|
||||
|
||||
flash($message)->success();
|
||||
|
||||
return redirect('common/items');
|
||||
return redirect()->route('items.index');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,7 +167,7 @@ class Items extends Controller
|
||||
|
||||
flash($message)->success();
|
||||
|
||||
return redirect('common/items');
|
||||
return redirect()->route('items.index');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +196,23 @@ class Items extends Controller
|
||||
flash($message)->warning();
|
||||
}
|
||||
|
||||
return redirect('common/items');
|
||||
return redirect()->route('items.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('items', function($excel) {
|
||||
$excel->sheet('items', function($sheet) {
|
||||
$sheet->fromModel(Item::filter(request()->input())->get()->makeHidden([
|
||||
'id', 'company_id', 'item_id', 'created_at', 'updated_at', 'deleted_at'
|
||||
]));
|
||||
});
|
||||
})->download('xlsx');
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
|
@ -291,14 +291,44 @@ class Bills extends Controller
|
||||
*/
|
||||
public function import(ImportFile $import)
|
||||
{
|
||||
$rows = $import->all();
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) {
|
||||
$class = '\App\Models\Expense\\' . str_singular(studly_case($sheet->getTitle()));
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
if (!class_exists($class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bill::create($data);
|
||||
}
|
||||
$sheet->each(function ($row) use ($sheet, $class) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
|
||||
switch ($sheet->getTitle()) {
|
||||
case 'bills':
|
||||
if (empty($data['vendor_email'])) {
|
||||
$data['vendor_email'] = '';
|
||||
}
|
||||
break;
|
||||
case 'bill_items':
|
||||
if (empty($data['tax_id'])) {
|
||||
$data['tax_id'] = '0';
|
||||
}
|
||||
break;
|
||||
case 'bill_histories':
|
||||
if (empty($data['notify'])) {
|
||||
$data['notify'] = '0';
|
||||
}
|
||||
break;
|
||||
case 'bill_totals':
|
||||
if (empty($data['amount'])) {
|
||||
$data['amount'] = '0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$class::create($data);
|
||||
});
|
||||
});
|
||||
|
||||
$message = trans('messages.success.imported', ['type' => trans_choice('general.bills', 2)]);
|
||||
|
||||
@ -490,6 +520,35 @@ class Bills extends Controller
|
||||
return redirect('expenses/bills');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('bills', function($excel) {
|
||||
$bills = Bill::with(['items', 'payments', 'totals'])->filter(request()->input())->get();
|
||||
|
||||
$excel->sheet('invoices', function($sheet) use ($bills) {
|
||||
$sheet->fromModel($bills->makeHidden([
|
||||
'company_id', 'parent_id', 'created_at', 'updated_at', 'deleted_at', 'attachment', 'discount', 'items', 'payments', 'totals', 'media'
|
||||
]));
|
||||
});
|
||||
|
||||
$tables = ['items', 'histories', 'payments', 'totals'];
|
||||
foreach ($tables as $table) {
|
||||
$excel->sheet('bill_' . $table, function($sheet) use ($bills, $table) {
|
||||
$bills->each(function ($bill) use ($sheet, $table) {
|
||||
$sheet->fromModel($bill->$table->makeHidden([
|
||||
'id', 'company_id', 'created_at', 'updated_at', 'deleted_at'
|
||||
]));
|
||||
});
|
||||
});
|
||||
}
|
||||
})->download('xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the bill as received.
|
||||
*
|
||||
|
@ -133,14 +133,20 @@ class Payments extends Controller
|
||||
*/
|
||||
public function import(ImportFile $import)
|
||||
{
|
||||
$rows = $import->all();
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) {
|
||||
if ($sheet->getTitle() != 'payments') {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
// Loop through all rows
|
||||
$sheet->each(function ($row) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
|
||||
Payment::create($data);
|
||||
}
|
||||
Payment::create($data);
|
||||
});
|
||||
});
|
||||
|
||||
$message = trans('messages.success.imported', ['type' => trans_choice('general.payments', 2)]);
|
||||
|
||||
@ -231,4 +237,20 @@ class Payments extends Controller
|
||||
|
||||
return redirect('expenses/payments');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('payments', function($excel) {
|
||||
$excel->sheet('payments', function($sheet) {
|
||||
$sheet->fromModel(Payment::filter(request()->input())->get()->makeHidden([
|
||||
'id', 'company_id', 'parent_id', 'created_at', 'updated_at', 'deleted_at'
|
||||
]));
|
||||
});
|
||||
})->download('xlsx');
|
||||
}
|
||||
}
|
||||
|
@ -171,19 +171,25 @@ class Vendors extends Controller
|
||||
*/
|
||||
public function import(ImportFile $import)
|
||||
{
|
||||
$rows = $import->all();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data = $row->toArray();
|
||||
|
||||
if (empty($data['email'])) {
|
||||
$data['email'] = '';
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) {
|
||||
if ($sheet->getTitle() != 'vendors') {
|
||||
return;
|
||||
}
|
||||
|
||||
$data['company_id'] = session('company_id');
|
||||
// Loop through all rows
|
||||
$sheet->each(function ($row) {
|
||||
$data = $row->toArray();
|
||||
|
||||
Vendor::create($data);
|
||||
}
|
||||
if (empty($data['email'])) {
|
||||
$data['email'] = '';
|
||||
}
|
||||
|
||||
$data['company_id'] = session('company_id');
|
||||
|
||||
Vendor::create($data);
|
||||
});
|
||||
});
|
||||
|
||||
$message = trans('messages.success.imported', ['type' => trans_choice('general.vendors', 2)]);
|
||||
|
||||
@ -265,6 +271,22 @@ class Vendors extends Controller
|
||||
return redirect('expenses/vendors');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('vendors', function($excel) {
|
||||
$excel->sheet('vendors', function($sheet) {
|
||||
$sheet->fromModel(Vendor::filter(request()->input())->get()->makeHidden([
|
||||
'id', 'company_id', 'created_at', 'updated_at', 'deleted_at'
|
||||
]));
|
||||
});
|
||||
})->download('xlsx');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
$vendor_id = request('vendor_id');
|
||||
|
@ -191,19 +191,25 @@ class Customers extends Controller
|
||||
*/
|
||||
public function import(ImportFile $import)
|
||||
{
|
||||
$rows = $import->all();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data = $row->toArray();
|
||||
|
||||
if (empty($data['email'])) {
|
||||
$data['email'] = '';
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) {
|
||||
if ($sheet->getTitle() != 'customers') {
|
||||
return;
|
||||
}
|
||||
|
||||
$data['company_id'] = session('company_id');
|
||||
// Loop through all rows
|
||||
$sheet->each(function ($row) {
|
||||
$data = $row->toArray();
|
||||
|
||||
Customer::create($data);
|
||||
}
|
||||
if (empty($data['email'])) {
|
||||
$data['email'] = '';
|
||||
}
|
||||
|
||||
$data['company_id'] = session('company_id');
|
||||
|
||||
Customer::create($data);
|
||||
});
|
||||
});
|
||||
|
||||
$message = trans('messages.success.imported', ['type' => trans_choice('general.customers', 2)]);
|
||||
|
||||
@ -301,6 +307,22 @@ class Customers extends Controller
|
||||
return redirect('incomes/customers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('customers', function($excel) {
|
||||
$excel->sheet('customers', function($sheet) {
|
||||
$sheet->fromModel(Customer::filter(request()->input())->get()->makeHidden([
|
||||
'id', 'company_id', 'created_at', 'updated_at', 'deleted_at'
|
||||
]));
|
||||
});
|
||||
})->download('xlsx');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
$customer_id = request('customer_id');
|
||||
|
@ -312,14 +312,44 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function import(ImportFile $import)
|
||||
{
|
||||
$rows = $import->all();
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) {
|
||||
$class = '\App\Models\Income\\' . str_singular(studly_case($sheet->getTitle()));
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
if (!class_exists($class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Invoice::create($data);
|
||||
}
|
||||
$sheet->each(function ($row) use ($sheet, $class) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
|
||||
switch ($sheet->getTitle()) {
|
||||
case 'invoices':
|
||||
if (empty($data['customer_email'])) {
|
||||
$data['customer_email'] = '';
|
||||
}
|
||||
break;
|
||||
case 'invoice_items':
|
||||
if (empty($data['tax_id'])) {
|
||||
$data['tax_id'] = '0';
|
||||
}
|
||||
break;
|
||||
case 'invoice_histories':
|
||||
if (empty($data['notify'])) {
|
||||
$data['notify'] = '0';
|
||||
}
|
||||
break;
|
||||
case 'invoice_totals':
|
||||
if (empty($data['amount'])) {
|
||||
$data['amount'] = '0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$class::create($data);
|
||||
});
|
||||
});
|
||||
|
||||
$message = trans('messages.success.imported', ['type' => trans_choice('general.invoices', 2)]);
|
||||
|
||||
@ -511,6 +541,35 @@ class Invoices extends Controller
|
||||
return redirect('incomes/invoices');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('invoices', function($excel) {
|
||||
$invoices = Invoice::with(['items', 'payments', 'totals'])->filter(request()->input())->get();
|
||||
|
||||
$excel->sheet('invoices', function($sheet) use ($invoices) {
|
||||
$sheet->fromModel($invoices->makeHidden([
|
||||
'company_id', 'parent_id', 'created_at', 'updated_at', 'deleted_at', 'attachment', 'discount', 'items', 'payments', 'totals', 'media'
|
||||
]));
|
||||
});
|
||||
|
||||
$tables = ['items', 'histories', 'payments', 'totals'];
|
||||
foreach ($tables as $table) {
|
||||
$excel->sheet('invoice_' . $table, function($sheet) use ($invoices, $table) {
|
||||
$invoices->each(function ($bill) use ($sheet, $table) {
|
||||
$sheet->fromModel($bill->$table->makeHidden([
|
||||
'id', 'company_id', 'created_at', 'updated_at', 'deleted_at'
|
||||
]));
|
||||
});
|
||||
});
|
||||
}
|
||||
})->download('xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the invoice as sent.
|
||||
*
|
||||
|
@ -135,14 +135,20 @@ class Revenues extends Controller
|
||||
*/
|
||||
public function import(ImportFile $import)
|
||||
{
|
||||
$rows = $import->all();
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) {
|
||||
if ($sheet->getTitle() != 'revenues') {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
// Loop through all rows
|
||||
$sheet->each(function ($row) {
|
||||
$data = $row->toArray();
|
||||
$data['company_id'] = session('company_id');
|
||||
|
||||
Revenue::create($data);
|
||||
}
|
||||
Revenue::create($data);
|
||||
});
|
||||
});
|
||||
|
||||
$message = trans('messages.success.imported', ['type' => trans_choice('general.revenues', 2)]);
|
||||
|
||||
@ -233,4 +239,20 @@ class Revenues extends Controller
|
||||
|
||||
return redirect('incomes/revenues');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('revenues', function($excel) {
|
||||
$excel->sheet('revenues', function($sheet) {
|
||||
$sheet->fromModel(Revenue::filter(request()->input())->get()->makeHidden([
|
||||
'id', 'company_id', 'parent_id', 'created_at', 'updated_at', 'deleted_at'
|
||||
]));
|
||||
});
|
||||
})->download('xlsx');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user