fixed #712
This commit is contained in:
parent
4632eb0856
commit
a844b7a721
@ -161,7 +161,7 @@ class Bills extends Controller
|
||||
{
|
||||
$success = true;
|
||||
|
||||
$allowed_sheets = ['bills', 'bill_items', 'bill_histories', 'bill_payments', 'bill_totals'];
|
||||
$allowed_sheets = ['bills', 'bill_items', 'bill_item_taxes', 'bill_histories', 'bill_payments', 'bill_totals'];
|
||||
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) use (&$success, $allowed_sheets) {
|
||||
@ -245,7 +245,7 @@ class Bills extends Controller
|
||||
*/
|
||||
public function destroy(Bill $bill)
|
||||
{
|
||||
$this->deleteRelationships($bill, ['items', 'itemTaxes', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$this->deleteRelationships($bill, ['items', 'item_taxes', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$bill->delete();
|
||||
|
||||
$message = trans('messages.success.deleted', ['type' => trans_choice('general.bills', 1)]);
|
||||
@ -263,15 +263,15 @@ class Bills extends Controller
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('bills', function ($excel) {
|
||||
$bills = Bill::with(['items', 'histories', 'payments', 'totals'])->filter(request()->input())->get();
|
||||
$bills = Bill::with(['items', 'item_taxes', 'histories', 'payments', 'totals'])->filter(request()->input())->get();
|
||||
|
||||
$excel->sheet('bills', function ($sheet) use ($bills) {
|
||||
$sheet->fromModel($bills->makeHidden([
|
||||
'company_id', 'parent_id', 'created_at', 'updated_at', 'deleted_at', 'attachment', 'discount', 'items', 'histories', 'payments', 'totals', 'media', 'paid'
|
||||
'company_id', 'parent_id', 'created_at', 'updated_at', 'deleted_at', 'attachment', 'discount', 'items', 'item_taxes', 'histories', 'payments', 'totals', 'media', 'paid', 'amount_without_tax'
|
||||
]));
|
||||
});
|
||||
|
||||
$tables = ['items', 'histories', 'payments', 'totals'];
|
||||
$tables = ['items', 'item_taxes', 'histories', 'payments', 'totals'];
|
||||
foreach ($tables as $table) {
|
||||
$excel->sheet('bill_' . $table, function ($sheet) use ($bills, $table) {
|
||||
$hidden_fields = ['id', 'company_id', 'created_at', 'updated_at', 'deleted_at', 'title'];
|
||||
|
@ -173,7 +173,7 @@ class Invoices extends Controller
|
||||
{
|
||||
$success = true;
|
||||
|
||||
$allowed_sheets = ['invoices', 'invoice_items', 'invoice_histories', 'invoice_payments', 'invoice_totals'];
|
||||
$allowed_sheets = ['invoices', 'invoice_items', 'invoice_item_taxes', 'invoice_histories', 'invoice_payments', 'invoice_totals'];
|
||||
|
||||
// Loop through all sheets
|
||||
$import->each(function ($sheet) use (&$success, $allowed_sheets) {
|
||||
@ -257,7 +257,7 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function destroy(Invoice $invoice)
|
||||
{
|
||||
$this->deleteRelationships($invoice, ['items', 'itemTaxes', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$this->deleteRelationships($invoice, ['items', 'item_taxes', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$invoice->delete();
|
||||
|
||||
$message = trans('messages.success.deleted', ['type' => trans_choice('general.invoices', 1)]);
|
||||
@ -275,15 +275,15 @@ class Invoices extends Controller
|
||||
public function export()
|
||||
{
|
||||
\Excel::create('invoices', function ($excel) {
|
||||
$invoices = Invoice::with(['items', 'histories', 'payments', 'totals'])->filter(request()->input())->get();
|
||||
$invoices = Invoice::with(['items', 'item_taxes', 'histories', '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', 'histories', 'payments', 'totals', 'media', 'paid'
|
||||
'company_id', 'parent_id', 'created_at', 'updated_at', 'deleted_at', 'attachment', 'discount', 'items', 'item_taxes', 'histories', 'payments', 'totals', 'media', 'paid', 'amount_without_tax'
|
||||
]));
|
||||
});
|
||||
|
||||
$tables = ['items', 'histories', 'payments', 'totals'];
|
||||
$tables = ['items', 'item_taxes', 'histories', 'payments', 'totals'];
|
||||
foreach ($tables as $table) {
|
||||
$excel->sheet('invoice_' . $table, function ($sheet) use ($invoices, $table) {
|
||||
$hidden_fields = ['id', 'company_id', 'created_at', 'updated_at', 'deleted_at', 'title'];
|
||||
|
@ -176,7 +176,6 @@ class CreateBillItem
|
||||
'quantity' => (double) $this->data['quantity'],
|
||||
'price' => (double) $this->data['price'],
|
||||
'tax' => $item_tax_total,
|
||||
'tax_id' => 0,
|
||||
'total' => $item_amount,
|
||||
]);
|
||||
|
||||
|
@ -203,7 +203,6 @@ class CreateInvoiceItem
|
||||
'quantity' => (double) $this->data['quantity'],
|
||||
'price' => (double) $this->data['price'],
|
||||
'tax' => $item_tax_total,
|
||||
'tax_id' => 0,
|
||||
'total' => $item_amount,
|
||||
]);
|
||||
|
||||
|
58
app/Listeners/Updates/V13/Version139.php
Normal file
58
app/Listeners/Updates/V13/Version139.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Updates\V13;
|
||||
|
||||
use App\Events\UpdateFinished;
|
||||
use App\Listeners\Updates\Listener;
|
||||
use App\Models\Income\InvoiceItem;
|
||||
use App\Models\Income\InvoiceItemTax;
|
||||
use App\Models\Setting\Tax;
|
||||
use Artisan;
|
||||
|
||||
class Version139 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '1.3.9';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(UpdateFinished $event)
|
||||
{
|
||||
// Check if should listen
|
||||
if (!$this->check($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->copyOldInvoiceItemTaxes();
|
||||
|
||||
// Update database
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
}
|
||||
|
||||
protected function copyOldInvoiceItemTaxes()
|
||||
{
|
||||
$invoice_items = InvoiceItem::where('company_id', '<>', '0')->where('tax_id', '<>', '0')->get();
|
||||
|
||||
foreach ($invoice_items as $invoice_item) {
|
||||
$tax = Tax::where('company_id', $invoice_item->company_id)->where('id', $invoice_item->tax_id)->first();
|
||||
|
||||
if (empty($tax)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
InvoiceItemTax::create([
|
||||
'company_id' => $invoice_item->company_id,
|
||||
'invoice_id' => $invoice_item->invoice_id,
|
||||
'invoice_item_id' => $invoice_item->id,
|
||||
'tax_id' => $invoice_item->tax_id,
|
||||
'name' => $tax->name,
|
||||
'amount' => $invoice_item->tax,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
@ -83,7 +83,7 @@ class Bill extends Model
|
||||
return $this->hasMany('App\Models\Expense\BillItem');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
public function item_taxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillItemTax');
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class BillItem extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax', 'tax_id'];
|
||||
protected $fillable = ['company_id', 'bill_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax'];
|
||||
|
||||
public function bill()
|
||||
{
|
||||
@ -29,16 +29,11 @@ class BillItem extends Model
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
public function taxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillItemTax', 'bill_item_id', 'id');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert price to double.
|
||||
*
|
||||
@ -71,23 +66,4 @@ class BillItem extends Model
|
||||
{
|
||||
$this->attributes['tax'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function getTaxIdAttribute($value)
|
||||
{
|
||||
$tax_ids = [];
|
||||
|
||||
if (!empty($value)) {
|
||||
$tax_ids[] = $value;
|
||||
|
||||
return $tax_ids;
|
||||
}
|
||||
|
||||
return $this->itemTaxes->pluck('tax_id');
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,6 @@ class BillItemTax extends Model
|
||||
return $this->belongsTo('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
|
@ -86,7 +86,7 @@ class Invoice extends Model
|
||||
return $this->hasMany('App\Models\Income\InvoiceItem');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
public function item_taxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItemTax');
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class InvoiceItem extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax', 'tax_id'];
|
||||
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax'];
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
@ -29,16 +29,11 @@ class InvoiceItem extends Model
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
public function taxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItemTax', 'invoice_item_id', 'id');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert price to double.
|
||||
*
|
||||
@ -71,23 +66,4 @@ class InvoiceItem extends Model
|
||||
{
|
||||
$this->attributes['tax'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function getTaxIdAttribute($value)
|
||||
{
|
||||
$tax_ids = [];
|
||||
|
||||
if (!empty($value)) {
|
||||
$tax_ids[] = $value;
|
||||
|
||||
return $tax_ids;
|
||||
}
|
||||
|
||||
return $this->itemTaxes->pluck('tax_id');
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,6 @@ class InvoiceItemTax extends Model
|
||||
return $this->belongsTo('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
|
@ -32,6 +32,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
'App\Listeners\Updates\V13\Version132',
|
||||
'App\Listeners\Updates\V13\Version135',
|
||||
'App\Listeners\Updates\V13\Version138',
|
||||
'App\Listeners\Updates\V13\Version139',
|
||||
],
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\Auth\Login',
|
||||
|
40
database/migrations/2019_01_07_000000_drop_tax_id_column.php
Normal file
40
database/migrations/2019_01_07_000000_drop_tax_id_column.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class DropTaxIdColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('bill_items', function (Blueprint $table) {
|
||||
$table->dropColumn('tax_id');
|
||||
});
|
||||
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->dropColumn('tax_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('bill_items', function (Blueprint $table) {
|
||||
$table->integer('tax_id')->default(0);
|
||||
});
|
||||
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->integer('tax_id')->default(0);
|
||||
});
|
||||
}
|
||||
}
|
@ -35,7 +35,7 @@
|
||||
@stack('taxes_td_start')
|
||||
<td {{ $errors->has('item.' . $item_row . '.tax_id') ? 'class="has-error"' : '' }}>
|
||||
@stack('tax_id_input_start')
|
||||
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, (empty($item) || empty($item->tax_id)) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
|
||||
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, (empty($item) || empty($item->taxes)) ? setting('general.default_tax') : $item->taxes->pluck('tax_id'), ['id'=> 'item-tax-' . $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
|
||||
{!! $errors->first('item.' . $item_row . '.tax_id', '<p class="help-block">:message</p>') !!}
|
||||
@stack('tax_id_input_end')
|
||||
</td>
|
||||
|
@ -35,7 +35,7 @@
|
||||
@stack('taxes_td_start')
|
||||
<td {{ $errors->has('item.' . $item_row . '.tax_id') ? 'class="has-error"' : '' }}>
|
||||
@stack('tax_id_input_start')
|
||||
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, (empty($item) || empty($item->tax_id)) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
|
||||
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, (empty($item) || empty($item->taxes)) ? setting('general.default_tax') : $item->taxes->pluck('tax_id'), ['id'=> 'item-tax-' . $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
|
||||
{!! $errors->first('item.' . $item_row . '.tax_id', '<p class="help-block">:message</p>') !!}
|
||||
@stack('tax_id_input_end')
|
||||
</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user