Attachment system some file

This commit is contained in:
cuneytsenturk
2017-12-28 17:20:16 +03:00
parent 411de05efd
commit 97afc50cfa
16 changed files with 420 additions and 84 deletions

View File

@ -128,16 +128,17 @@ class Bills extends Controller
$request['amount'] = 0;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'bills');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$bill = Bill::create($request->input());
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'revenues');
$invoice->attachMedia($media, 'attachment');
}
$taxes = [];
$tax_total = 0;
$sub_total = 0;
@ -357,13 +358,6 @@ class Bills extends Controller
$request['amount'] = 0;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'bills');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$taxes = [];
$tax_total = 0;
$sub_total = 0;
@ -460,6 +454,13 @@ class Bills extends Controller
$bill->update($request->input());
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'bills');
$bill->syncMedia($media, 'attachment');
}
// Added bill total total
$bill_total = [
'company_id' => $request['company_id'],
@ -594,15 +595,15 @@ class Bills extends Controller
$request['currency_code'] = $currency->code;
$request['currency_rate'] = $currency->rate;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'revenues');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$bill = Bill::find($request['bill_id']);
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'payments');
$bill->attachMedia($media, 'attachment');
}
$total_amount = $bill->amount;
$amount = (double) $request['amount'];

View File

@ -77,13 +77,14 @@ class Payments extends Controller
$request['currency_code'] = $currency->code;
$request['currency_rate'] = $currency->rate;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'payments');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$payment = Payment::create($request->input());
Payment::create($request->input());
// Upload attachment
$media = $this->getMedia($request->file('attachment'), 'payments');
if ($media) {
$payment->attachMedia($media, 'attachment');
}
$message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]);
@ -175,14 +176,15 @@ class Payments extends Controller
$request['currency_code'] = $currency->code;
$request['currency_rate'] = $currency->rate;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'payments');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$payment->update($request->input());
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'payments');
$payment->syncMedia($media, 'attachment');
}
$message = trans('messages.success.updated', ['type' => trans_choice('general.payments', 1)]);
flash($message)->success();

View File

@ -137,16 +137,17 @@ class Invoices extends Controller
$request['amount'] = 0;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'invoices');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$invoice = Invoice::create($request->input());
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'revenues');
$invoice->attachMedia($media, 'attachment');
}
$taxes = [];
$tax_total = 0;
$sub_total = 0;
@ -349,13 +350,6 @@ class Invoices extends Controller
$request['currency_code'] = $currency->code;
$request['currency_rate'] = $currency->rate;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'invoices');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$taxes = [];
$tax_total = 0;
$sub_total = 0;
@ -418,6 +412,13 @@ class Invoices extends Controller
$invoice->update($request->input());
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'invoices');
$invoice->syncMedia($media, 'attachment');
}
// Delete previous invoice totals
InvoiceTotal::where('invoice_id', $invoice->id)->delete();
@ -624,13 +625,6 @@ class Invoices extends Controller
$request['currency_code'] = $currency->code;
$request['currency_rate'] = $currency->rate;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'invoices');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$invoice = Invoice::find($request['invoice_id']);
$total_amount = $invoice->amount;
@ -669,6 +663,13 @@ class Invoices extends Controller
$invoice_payment = InvoicePayment::create($request->input());
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'invoices');
$invoice_payment->attachMedia($media, 'attachment');
}
$request['status_code'] = $invoice->invoice_status_code;
$request['notify'] = 0;

View File

@ -79,13 +79,14 @@ class Revenues extends Controller
$request['currency_code'] = $currency->code;
$request['currency_rate'] = $currency->rate;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'revenues');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$revenue = Revenue::create($request->input());
Revenue::create($request->input());
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'revenues');
$revenue->syncMedia($media, 'attachment');
}
$message = trans('messages.success.added', ['type' => trans_choice('general.revenues', 1)]);
@ -177,14 +178,15 @@ class Revenues extends Controller
$request['currency_code'] = $currency->code;
$request['currency_rate'] = $currency->rate;
// Upload attachment
$attachment_path = $this->getUploadedFilePath($request->file('attachment'), 'revenues');
if ($attachment_path) {
$request['attachment'] = $attachment_path;
}
$revenue->update($request->input());
// Upload attachment
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'revenues');
$revenue->syncMedia($media, 'attachment');
}
$message = trans('messages.success.updated', ['type' => trans_choice('general.revenues', 1)]);
flash($message)->success();

View File

@ -53,13 +53,14 @@ class Items extends Controller
*/
public function store(Request $request)
{
// Upload picture
$picture_path = $this->getUploadedFilePath($request->file('picture'), 'items');
if ($picture_path) {
$request['picture'] = $picture_path;
}
$item = Item::create($request->input());
Item::create($request->input());
// Upload picture
if ($media) {
$media = $this->getMedia($request->file('picture'), 'items');
$item->attachMedia($media, 'picture');
}
$message = trans('messages.success.added', ['type' => trans_choice('general.items', 1)]);
@ -137,14 +138,15 @@ class Items extends Controller
*/
public function update(Item $item, Request $request)
{
// Upload picture
$picture_path = $this->getUploadedFilePath($request->file('picture'), 'items');
if ($picture_path) {
$request['picture'] = $picture_path;
}
$item->update($request->input());
// Upload picture
if ($media) {
$media = $this->getMedia($request->file('picture'), 'items');
$item->syncMedia($media, 'picture');
}
$message = trans('messages.success.updated', ['type' => trans_choice('general.items', 1)]);
flash($message)->success();

View File

@ -8,13 +8,21 @@ use App\Traits\DateTime;
use App\Traits\Incomes;
use Bkwld\Cloner\Cloneable;
use Sofa\Eloquence\Eloquence;
use Plank\Mediable\Mediable;
class Invoice extends Model
{
use Cloneable, Currencies, DateTime, Eloquence, Incomes;
use Cloneable, Currencies, DateTime, Eloquence, Incomes, Mediable;
protected $table = 'invoices';
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['attachment'];
protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];
/**
@ -130,4 +138,18 @@ class Invoice 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')->first();
}
}

View File

@ -44,7 +44,7 @@ class FormServiceProvider extends ServiceProvider
]);
Form::component('fileGroup', 'partials.form.file_group', [
'name', 'text', 'attributes' => [], 'col' => 'col-md-6',
'name', 'text', 'attributes' => [], 'value' => null, 'col' => 'col-md-6',
]);
Form::component('deleteButton', 'partials.form.delete_button', [

View File

@ -2,6 +2,8 @@
namespace App\Traits;
use MediaUploader;
trait Uploads
{
@ -27,4 +29,17 @@ trait Uploads
return $path;
}
}
public function getMedia($file, $folder, $company_id = null)
{
if (!$company_id) {
$company_id = session('company_id');
}
$path = config('filesystems.disks.uploads.root') . '/' . $company_id . '/' . $folder;
config(['filesystems.disks.uploads.root' => $path]);
return MediaUploader::fromSource($file)->upload();
}
}