Merge branch 'master' into title-subheading
This commit is contained in:
		| @@ -3,6 +3,7 @@ | ||||
| namespace App\Models\Document; | ||||
|  | ||||
| use App\Abstracts\Model; | ||||
| use App\Interfaces\Utility\DocumentNumber; | ||||
| use App\Models\Common\Media as MediaModel; | ||||
| use App\Models\Setting\Tax; | ||||
| use App\Scopes\Document as Scope; | ||||
| @@ -30,8 +31,6 @@ class Document extends Model | ||||
|  | ||||
|     protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid', 'received_at', 'status_label', 'sent_at', 'reconciled', 'contact_location']; | ||||
|  | ||||
|     protected $dates = ['deleted_at', 'issued_at', 'due_at']; | ||||
|  | ||||
|     protected $fillable = [ | ||||
|         'company_id', | ||||
|         'type', | ||||
| @@ -69,8 +68,11 @@ class Document extends Model | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $casts = [ | ||||
|         'amount' => 'double', | ||||
|         'issued_at'     => 'datetime', | ||||
|         'due_at'        => 'datetime', | ||||
|         'amount'        => 'double', | ||||
|         'currency_rate' => 'double', | ||||
|         'deleted_at'    => 'datetime', | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
| @@ -218,7 +220,10 @@ class Document extends Model | ||||
|  | ||||
|     public function scopeInvoiceRecurring(Builder $query): Builder | ||||
|     { | ||||
|         return $query->where($this->qualifyColumn('type'), '=', self::INVOICE_RECURRING_TYPE); | ||||
|         return $query->where($this->qualifyColumn('type'), '=', self::INVOICE_RECURRING_TYPE) | ||||
|                     ->whereHas('recurring', function (Builder $query) { | ||||
|                         $query->whereNull('deleted_at'); | ||||
|                     }); | ||||
|     } | ||||
|  | ||||
|     public function scopeBill(Builder $query): Builder | ||||
| @@ -228,7 +233,10 @@ class Document extends Model | ||||
|  | ||||
|     public function scopeBillRecurring(Builder $query): Builder | ||||
|     { | ||||
|         return $query->where($this->qualifyColumn('type'), '=', self::BILL_RECURRING_TYPE); | ||||
|         return $query->where($this->qualifyColumn('type'), '=', self::BILL_RECURRING_TYPE) | ||||
|                     ->whereHas('recurring', function (Builder $query) { | ||||
|                         $query->whereNull('deleted_at'); | ||||
|                     }); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -246,7 +254,7 @@ class Document extends Model | ||||
|         } | ||||
|  | ||||
|         $this->status          = 'draft'; | ||||
|         $this->document_number = $this->getNextDocumentNumber($type); | ||||
|         $this->document_number = app(DocumentNumber::class)->getNextNumber($type, $src->contact); | ||||
|     } | ||||
|  | ||||
|     public function getSentAtAttribute(string $value = null) | ||||
| @@ -323,7 +331,7 @@ class Document extends Model | ||||
|  | ||||
|         $code = $this->currency_code; | ||||
|         $rate = $this->currency_rate; | ||||
|         $precision = config('money.' . $code . '.precision'); | ||||
|         $precision = config('money.currencies.' . $code . '.precision'); | ||||
|  | ||||
|         if ($this->transactions->count()) { | ||||
|             foreach ($this->transactions as $transaction) { | ||||
| @@ -355,7 +363,7 @@ class Document extends Model | ||||
|  | ||||
|         $code = $this->currency_code; | ||||
|         $rate = $this->currency_rate; | ||||
|         $precision = config('money.' . $code . '.precision'); | ||||
|         $precision = config('money.currencies.' . $code . '.precision'); | ||||
|  | ||||
|         if ($this->transactions->count()) { | ||||
|             foreach ($this->transactions as $transaction) { | ||||
| @@ -385,7 +393,7 @@ class Document extends Model | ||||
|      */ | ||||
|     public function getAmountDueAttribute() | ||||
|     { | ||||
|         $precision = config('money.' . $this->currency_code . '.precision'); | ||||
|         $precision = config('money.currencies.' . $this->currency_code . '.precision'); | ||||
|  | ||||
|         return round($this->amount - $this->paid, $precision); | ||||
|     } | ||||
| @@ -465,7 +473,7 @@ class Document extends Model | ||||
|             $location[] = $this->contact_state; | ||||
|         } | ||||
|  | ||||
|         if ($this->contact_country && in_array($this->contact_country, trans('countries'))) { | ||||
|         if ($this->contact_country && array_key_exists($this->contact_country, trans('countries'))) { | ||||
|             $location[] = trans('countries.' . $this->contact_country); | ||||
|         } | ||||
|  | ||||
| @@ -532,17 +540,29 @@ class Document extends Model | ||||
|  | ||||
|         if ($this->status != 'paid' && (empty($this->transactions->count()) || (! empty($this->transactions->count()) && $this->paid != $this->amount))) { | ||||
|             try { | ||||
|                 $actions[] = [ | ||||
|                     'type' => 'button', | ||||
|                     'title' => trans('invoices.add_payment'), | ||||
|                     'icon' => 'paid', | ||||
|                     'url' => route('modals.documents.document.transactions.create', $this->id), | ||||
|                     'permission' => 'read-' . $group . '-' . $permission_prefix, | ||||
|                     'attributes' => [ | ||||
|                         'id' => 'index-line-actions-payment-' . $this->type . '-' . $this->id, | ||||
|                         '@click' => 'onAddPayment("' . route('modals.documents.document.transactions.create', $this->id) . '")', | ||||
|                     ], | ||||
|                 ]; | ||||
|                 if ($this->totals->count()) { | ||||
|                     $actions[] = [ | ||||
|                         'type' => 'button', | ||||
|                         'title' => trans('invoices.add_payment'), | ||||
|                         'icon' => 'paid', | ||||
|                         'url' => route('modals.documents.document.transactions.create', $this->id), | ||||
|                         'permission' => 'read-' . $group . '-' . $permission_prefix, | ||||
|                         'attributes' => [ | ||||
|                             'id' => 'index-line-actions-payment-' . $this->type . '-' . $this->id, | ||||
|                             '@click' => 'onAddPayment("' . route('modals.documents.document.transactions.create', $this->id) . '")', | ||||
|                         ], | ||||
|                     ]; | ||||
|                 } else { | ||||
|                     $actions[] = [ | ||||
|                         'type' => 'button', | ||||
|                         'title' => trans('invoices.messages.totals_required', ['type' => $this->type]), | ||||
|                         'icon' => 'paid', | ||||
|                         'permission' => 'read-' . $group . '-' . $permission_prefix, | ||||
|                         'attributes' => [ | ||||
|                             "disabled" => "disabled", | ||||
|                         ], | ||||
|                     ]; | ||||
|                 } | ||||
|             } catch (\Exception $e) {} | ||||
|         } | ||||
|  | ||||
| @@ -613,10 +633,10 @@ class Document extends Model | ||||
|                 'type' => 'divider', | ||||
|             ]; | ||||
|  | ||||
|             if ($this->status != 'cancelled') { | ||||
|             if (! in_array($this->status, ['cancelled', 'draft'])) { | ||||
|                 try { | ||||
|                     $actions[] = [ | ||||
|                         'title' => trans('general.cancel'), | ||||
|                         'title' => trans('documents.actions.cancel'), | ||||
|                         'icon' => 'cancel', | ||||
|                         'url' => route($prefix . '.cancelled', $this->id), | ||||
|                         'permission' => 'update-' . $group . '-' . $permission_prefix, | ||||
|   | ||||
| @@ -15,6 +15,13 @@ class DocumentItem extends Model | ||||
|  | ||||
|     protected $table = 'document_items'; | ||||
|  | ||||
|     /** | ||||
|      * The relationships that should always be loaded. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $with = ['taxes']; | ||||
|  | ||||
|     protected $appends = ['discount']; | ||||
|  | ||||
|     protected $fillable = [ | ||||
| @@ -40,9 +47,10 @@ class DocumentItem extends Model | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $casts = [ | ||||
|         'price' => 'double', | ||||
|         'total' => 'double', | ||||
|         'tax' => 'double', | ||||
|         'price'         => 'double', | ||||
|         'total'         => 'double', | ||||
|         'tax'           => 'double', | ||||
|         'deleted_at'    => 'datetime', | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -16,15 +16,6 @@ class DocumentItemTax extends Model | ||||
|  | ||||
|     protected $fillable = ['company_id', 'type', 'document_id', 'document_item_id', 'tax_id', 'name', 'amount', 'created_from', 'created_by']; | ||||
|  | ||||
|     /** | ||||
|      * The attributes that should be cast. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $casts = [ | ||||
|         'amount' => 'double', | ||||
|     ]; | ||||
|  | ||||
|     public function document() | ||||
|     { | ||||
|         return $this->belongsTo('App\Models\Document\Document')->withoutGlobalScope('App\Scopes\Document'); | ||||
|   | ||||
| @@ -18,15 +18,6 @@ class DocumentTotal extends Model | ||||
|  | ||||
|     protected $fillable = ['company_id', 'type', 'document_id', 'code', 'name', 'amount', 'sort_order', 'created_from', 'created_by']; | ||||
|  | ||||
|     /** | ||||
|      * The attributes that should be cast. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $casts = [ | ||||
|         'amount' => 'double', | ||||
|     ]; | ||||
|  | ||||
|     public function document() | ||||
|     { | ||||
|         return $this->belongsTo('App\Models\Document\Document')->withoutGlobalScope('App\Scopes\Document'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user