diff --git a/app/Models/Expense/Bill.php b/app/Models/Expense/Bill.php index ca4dd2be7..8a4eb4d76 100644 --- a/app/Models/Expense/Bill.php +++ b/app/Models/Expense/Bill.php @@ -7,10 +7,11 @@ use App\Traits\Currencies; use App\Traits\DateTime; use Bkwld\Cloner\Cloneable; use Sofa\Eloquence\Eloquence; +use Plank\Mediable\Mediable; class Bill extends Model { - use Cloneable, Currencies, DateTime, Eloquence; + use Cloneable, Currencies, DateTime, Eloquence, Mediable; protected $table = 'bills'; @@ -128,4 +129,18 @@ class Bill extends Model { $this->attributes['currency_rate'] = (double) $value; } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Expense/BillPayment.php b/app/Models/Expense/BillPayment.php index 4397bddf6..b0f9c6dca 100644 --- a/app/Models/Expense/BillPayment.php +++ b/app/Models/Expense/BillPayment.php @@ -5,10 +5,11 @@ namespace App\Models\Expense; use App\Models\Model; use App\Traits\Currencies; use App\Traits\DateTime; +use Plank\Mediable\Mediable; class BillPayment extends Model { - use Currencies, DateTime; + use Currencies, DateTime, Mediable; protected $table = 'bill_payments'; @@ -78,4 +79,18 @@ class BillPayment extends Model { return $query->sum('amount'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Expense/Payment.php b/app/Models/Expense/Payment.php index ae3e230c8..f10133066 100644 --- a/app/Models/Expense/Payment.php +++ b/app/Models/Expense/Payment.php @@ -7,10 +7,11 @@ use App\Traits\Currencies; use App\Traits\DateTime; use Bkwld\Cloner\Cloneable; use Sofa\Eloquence\Eloquence; +use Plank\Mediable\Mediable; class Payment extends Model { - use Cloneable, Currencies, DateTime, Eloquence; + use Cloneable, Currencies, DateTime, Eloquence, Mediable; protected $table = 'payments'; @@ -91,4 +92,18 @@ class Payment extends Model { return $query->orderBy('paid_at', 'desc'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Income/InvoicePayment.php b/app/Models/Income/InvoicePayment.php index 615b65a90..ed7977ffd 100644 --- a/app/Models/Income/InvoicePayment.php +++ b/app/Models/Income/InvoicePayment.php @@ -5,10 +5,11 @@ namespace App\Models\Income; use App\Models\Model; use App\Traits\Currencies; use App\Traits\DateTime; +use Plank\Mediable\Mediable; class InvoicePayment extends Model { - use Currencies, DateTime; + use Currencies, DateTime, Mediable; protected $table = 'invoice_payments'; @@ -78,4 +79,18 @@ class InvoicePayment extends Model { return $query->sum('amount'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/app/Models/Income/Revenue.php b/app/Models/Income/Revenue.php index 60c4f8b89..221c54632 100644 --- a/app/Models/Income/Revenue.php +++ b/app/Models/Income/Revenue.php @@ -7,10 +7,11 @@ use App\Traits\Currencies; use App\Traits\DateTime; use Bkwld\Cloner\Cloneable; use Sofa\Eloquence\Eloquence; +use Plank\Mediable\Mediable; class Revenue extends Model { - use Cloneable, Currencies, DateTime, Eloquence; + use Cloneable, Currencies, DateTime, Eloquence, Mediable; protected $table = 'revenues'; @@ -97,4 +98,18 @@ class Revenue extends Model { return $query->orderBy('paid_at', 'desc'); } + + /** + * Get the current balance. + * + * @return string + */ + public function getAttachmentAttribute() + { + if (!$this->hasMedia('attachment')) { + return false; + } + + return $this->getMedia('attachment')->last(); + } } diff --git a/resources/views/expenses/bills/edit.blade.php b/resources/views/expenses/bills/edit.blade.php index d0dc1ebb0..5c87e0524 100644 --- a/resources/views/expenses/bills/edit.blade.php +++ b/resources/views/expenses/bills/edit.blade.php @@ -204,9 +204,32 @@ $('#attachment').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'attachment; ?>' + @if($bill->attachment) + placeholder : 'attachment->basename; ?>' + @endif }); + @if($bill->attachment) + attachment_html = ''; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {{ $bill->attachment->basename }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $bill->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $bill->attachment->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::close() !!}'; + attachment_html += ''; + + $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $bill->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif + var autocomplete_path = "{{ url('items/items/autocomplete') }}"; $(document).on('click', '.form-control.typeahead', function() { diff --git a/resources/views/expenses/bills/show.blade.php b/resources/views/expenses/bills/show.blade.php index a32104653..46508b6e2 100644 --- a/resources/views/expenses/bills/show.blade.php +++ b/resources/views/expenses/bills/show.blade.php @@ -167,6 +167,26 @@ @endpermission + + @if($bill->attachment) + + + + {{ $bill->attachment->basename }} + + + {!! Form::open([ + 'id' => 'attachment-' . $bill->attachment->id, + 'method' => 'DELETE', + 'url' => [url('uploads/' . $bill->attachment->id)], + 'style' => 'display:inline' + ]) !!} + + + + {!! Form::close() !!} + + @endif @@ -403,6 +423,11 @@ $('#email-modal').modal('show'); }); + @if($bill->attachment) + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $bill->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif }); function addPayment() { diff --git a/resources/views/expenses/payments/edit.blade.php b/resources/views/expenses/payments/edit.blade.php index b86844a92..92f723f77 100644 --- a/resources/views/expenses/payments/edit.blade.php +++ b/resources/views/expenses/payments/edit.blade.php @@ -92,9 +92,32 @@ $('#attachment').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'attachment) ? $payment->attachment : trans('general.form.no_file_selected'); ?>' + @if($payment->attachment) + placeholder : 'attachment->basename; ?>' + @endif }); + @if($payment->attachment) + attachment_html = ''; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {{ $payment->attachment->basename }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $payment->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $payment->attachment->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::close() !!}'; + attachment_html += ''; + + $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $payment->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $payment->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif + $(document).on('change', '#account_id', function (e) { $.ajax({ url: '{{ url("settings/currencies/currency") }}', diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index e87f6c95c..7834e0cf8 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -216,7 +216,6 @@ attachment_html += ' '; attachment_html += ' '; attachment_html += ' {!! Form::open(['id' => 'attachment-' . $invoice->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline']) !!}'; - attachment_html += ' {{ Form::hidden('id', $invoice->id) }}'; attachment_html += ' '; attachment_html += ' '; attachment_html += ' '; @@ -224,6 +223,10 @@ attachment_html += ''; $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $invoice->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $invoice->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); @endif var autocomplete_path = "{{ url('items/items/autocomplete') }}"; diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index e0d324c4a..fdbd4e8f7 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -192,7 +192,6 @@ 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline' ]) !!} - {{ Form::hidden('id', $invoice->id) }} diff --git a/resources/views/incomes/revenues/edit.blade.php b/resources/views/incomes/revenues/edit.blade.php index e49e88645..c25a3d437 100644 --- a/resources/views/incomes/revenues/edit.blade.php +++ b/resources/views/incomes/revenues/edit.blade.php @@ -92,9 +92,32 @@ $('#attachment').fancyfile({ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', - placeholder : 'attachment; ?>' + @if($revenue->attachment) + placeholder : 'attachment->basename; ?>' + @endif }); + @if($revenue->attachment) + attachment_html = ''; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {{ $revenue->attachment->basename }}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::open(['id' => 'attachment-' . $revenue->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $revenue->attachment->id)], 'style' => 'display:inline']) !!}'; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' '; + attachment_html += ' {!! Form::close() !!}'; + attachment_html += ''; + + $('.fancy-file .fake-file').append(attachment_html); + + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $revenue->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $revenue->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif + $(document).on('change', '#account_id', function (e) { $.ajax({ url: '{{ url("settings/currencies/currency") }}',