diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 9bba61a97f2b..f35b2cb4fec9 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -112,6 +112,7 @@ class ActivityController extends BaseController 'purchase_order' => $activity->purchase_order ? $activity->purchase_order : '', 'subscription' => $activity->subscription ? $activity->subscription : '', 'vendor_contact' => $activity->vendor_contact ? $activity->vendor_contact : '', + 'recurring_expense' => $activity->recurring_expense ? $activity->recurring_expense : '', ]; return array_merge($arr, $activity->toArray()); diff --git a/app/Http/Controllers/SubscriptionController.php b/app/Http/Controllers/SubscriptionController.php index 6fb0fa9146e4..6880f4573aea 100644 --- a/app/Http/Controllers/SubscriptionController.php +++ b/app/Http/Controllers/SubscriptionController.php @@ -15,6 +15,7 @@ namespace App\Http\Controllers; use App\Events\Subscription\SubscriptionWasCreated; use App\Events\Subscription\SubscriptionWasUpdated; use App\Factory\SubscriptionFactory; +use App\Filters\SubscriptionFilters; use App\Http\Requests\Subscription\CreateSubscriptionRequest; use App\Http\Requests\Subscription\DestroySubscriptionRequest; use App\Http\Requests\Subscription\EditSubscriptionRequest; diff --git a/app/Import/Transformer/Freshbooks/InvoiceTransformer.php b/app/Import/Transformer/Freshbooks/InvoiceTransformer.php index d974e91626ac..316779875761 100644 --- a/app/Import/Transformer/Freshbooks/InvoiceTransformer.php +++ b/app/Import/Transformer/Freshbooks/InvoiceTransformer.php @@ -61,9 +61,9 @@ class InvoiceTransformer extends BaseTransformer 'discount' => $this->getFreshbookQuantityFloat($record, 'Discount Percentage'), 'is_amount_discount' => false, 'tax_name1' => $this->getString($record, 'Tax 1 Type'), - 'tax_rate1' => $this->getFreshbookQuantityFloat($record, 'Tax 1 Amount'), + 'tax_rate1' => $this->calcTaxRate($record, 'Tax 1 Amount'), 'tax_name2' => $this->getString($record, 'Tax 2 Type'), - 'tax_rate2' => $this->getFreshbookQuantityFloat($record, 'Tax 2 Amount'), + 'tax_rate2' => $this->calcTaxRate($record, 'Tax 2 Amount'), ]; $transformed['amount'] += $this->getFreshbookQuantityFloat($record, 'Line Total'); } @@ -79,6 +79,27 @@ class InvoiceTransformer extends BaseTransformer return $transformed; } + //Line Subtotal + public function calcTaxRate($record, $field) + { + if(isset($record['Line Subtotal']) && $record['Line Subtotal'] > 0) + return ($record[$field] / $record['Line Subtotal']) * 100; + + $tax_amount1 = isset($record['Tax 1 Amount']) ? $record['Tax 1 Amount'] : 0; + + $tax_amount2 = isset($record['Tax 2 Amount']) ? $record['Tax 2 Amount'] : 0; + + $line_total = isset($record['Line Total']) ? $record['Line Total'] : 0; + + $subtotal = $line_total - $tax_amount2 - $tax_amount1; + + if($subtotal > 0) + return $record[$field] / $subtotal * 100; + + return 0; + + } + /** @return float */ public function getFreshbookQuantityFloat($data, $field) { diff --git a/app/Models/Activity.php b/app/Models/Activity.php index daa84260a6a2..9633382388fa 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -214,21 +214,33 @@ class Activity extends StaticModel 'backup', ]; + /** + * @return mixed + */ public function getHashedIdAttribute() { return $this->encodePrimaryKey($this->id); } + /** + * @return mixed + */ public function getEntityType() { return self::class; } + /** + * @return mixed + */ public function backup() { return $this->hasOne(Backup::class); } + /** + * @return mixed + */ public function history() { return $this->hasOne(Backup::class); @@ -266,6 +278,9 @@ class Activity extends StaticModel return $this->belongsTo(Invoice::class)->withTrashed(); } + /** + * @return mixed + */ public function vendor() { return $this->belongsTo(Vendor::class)->withTrashed(); @@ -279,6 +294,9 @@ class Activity extends StaticModel return $this->belongsTo(RecurringInvoice::class)->withTrashed(); } + /** + * @return mixed + */ public function credit() { return $this->belongsTo(Credit::class)->withTrashed(); @@ -308,31 +326,57 @@ class Activity extends StaticModel return $this->belongsTo(Payment::class)->withTrashed(); } + /** + * @return mixed + */ public function expense() { return $this->belongsTo(Expense::class)->withTrashed(); } + /** + * @return mixed + */ + public function recurring_expense() + { + return $this->belongsTo(RecurringExpense::class)->withTrashed(); + } + + /** + * @return mixed + */ public function purchase_order() { return $this->belongsTo(PurchaseOrder::class)->withTrashed(); } + /** + * @return mixed + */ public function vendor_contact() { return $this->belongsTo(VendorContact::class)->withTrashed(); } + /** + * @return mixed + */ public function task() { return $this->belongsTo(Task::class)->withTrashed(); } + /** + * @return mixed + */ public function company() { return $this->belongsTo(Company::class); } + /** + * @return mixed + */ public function resolveRouteBinding($value, $field = null) { if (is_numeric($value)) {