From 13a00fc8971841a6d0e17d0b345752210f059ae3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 00:27:41 +1100 Subject: [PATCH 1/9] Redundant code cleanup --- app/Repositories/BaseRepository.php | 37 ------------------- app/Repositories/ClientRepository.php | 12 +----- app/Repositories/CompanyRepository.php | 10 ----- app/Repositories/CreditRepository.php | 9 ----- app/Repositories/DesignRepository.php | 22 +---------- app/Repositories/DocumentRepository.php | 9 ----- app/Repositories/ExpenseRepository.php | 13 ------- app/Repositories/GroupSettingRepository.php | 12 ------ app/Repositories/InvoiceRepository.php | 15 ++------ .../Migration/PaymentMigrationRepository.php | 5 --- app/Repositories/PaymentRepository.php | 9 ----- app/Repositories/ProductRepository.php | 5 --- app/Repositories/ProjectRepository.php | 9 ----- app/Repositories/QuoteRepository.php | 5 --- .../RecurringInvoiceRepository.php | 4 -- app/Repositories/RecurringQuoteRepository.php | 10 +---- app/Repositories/TaskRepository.php | 13 ------- app/Repositories/TokenRepository.php | 10 +---- app/Repositories/UserRepository.php | 13 +------ app/Repositories/VendorRepository.php | 25 +++---------- app/Services/Credit/CreateInvitations.php | 2 +- psalm.xml | 5 +++ 22 files changed, 22 insertions(+), 232 deletions(-) diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 553b869e51a1..54ec44405f52 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -34,24 +34,6 @@ class BaseRepository use MakesHash; use SavesDocuments; - /** - * @return null - */ - public function getClassName() - { - return null; - } - - /** - * @return mixed - */ - private function getInstance() - { - $className = $this->getClassName(); - - return new $className(); - } - /** * @param $entity * @param $type @@ -153,25 +135,6 @@ class BaseRepository return count($entities); } - /** - * @param $ids - * - * @return mixed - */ - public function findByPublicIds($ids) - { - return $this->getInstance()->scope($ids)->get(); - } - - /** - * @param $ids - * - * @return mixed - */ - public function findByPublicIdsWithTrashed($ids) - { - return $this->getInstance()->scope($ids)->withTrashed()->get(); - } public function getInvitation($invitation, $resource) { diff --git a/app/Repositories/ClientRepository.php b/app/Repositories/ClientRepository.php index 806fa4ba553e..e4924f387f7e 100644 --- a/app/Repositories/ClientRepository.php +++ b/app/Repositories/ClientRepository.php @@ -39,17 +39,7 @@ class ClientRepository extends BaseRepository { $this->contact_repo = $contact_repo; } - - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Client::class; - } - + /** * Saves the client and its contacts. * diff --git a/app/Repositories/CompanyRepository.php b/app/Repositories/CompanyRepository.php index 296e3fba29a7..b68df6b6e342 100644 --- a/app/Repositories/CompanyRepository.php +++ b/app/Repositories/CompanyRepository.php @@ -23,16 +23,6 @@ class CompanyRepository extends BaseRepository { } - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Company::class; - } - /** * Saves the client and its contacts. * diff --git a/app/Repositories/CreditRepository.php b/app/Repositories/CreditRepository.php index dd2963a316a1..5092fc8881ab 100644 --- a/app/Repositories/CreditRepository.php +++ b/app/Repositories/CreditRepository.php @@ -30,15 +30,6 @@ class CreditRepository extends BaseRepository { } - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Credit::class; - } /** * Saves the client and its contacts. diff --git a/app/Repositories/DesignRepository.php b/app/Repositories/DesignRepository.php index 353774e999d0..97a53dd8734e 100644 --- a/app/Repositories/DesignRepository.php +++ b/app/Repositories/DesignRepository.php @@ -11,30 +11,10 @@ namespace App\Repositories; -use App\Libraries\MultiDB; -use App\Models\Activity; -use App\Models\Backup; -use App\Models\Client; -use App\Models\Design; -use App\Models\Invoice; -use App\Models\User; -use App\Utils\Traits\MakesInvoiceHtml; -use Illuminate\Support\Facades\Log; - /** - * Class for activity repository. + * Class for DesignRepository . */ class DesignRepository extends BaseRepository { - use MakesInvoiceHtml; - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Design::class; - } } diff --git a/app/Repositories/DocumentRepository.php b/app/Repositories/DocumentRepository.php index 595fcc732dab..1c60366f618f 100644 --- a/app/Repositories/DocumentRepository.php +++ b/app/Repositories/DocumentRepository.php @@ -19,15 +19,6 @@ use App\Utils\Ninja; */ class DocumentRepository extends BaseRepository { - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Document::class; - } public function delete($document) { diff --git a/app/Repositories/ExpenseRepository.php b/app/Repositories/ExpenseRepository.php index 0044514ffbdd..310a9315aad5 100644 --- a/app/Repositories/ExpenseRepository.php +++ b/app/Repositories/ExpenseRepository.php @@ -24,19 +24,6 @@ class ExpenseRepository extends BaseRepository { use GeneratesCounter; - public function __construct() - { - } - - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Expense::class; - } /** * Saves the expense and its contacts. diff --git a/app/Repositories/GroupSettingRepository.php b/app/Repositories/GroupSettingRepository.php index fd0ebb4d9ce9..d1aac1dda4d9 100644 --- a/app/Repositories/GroupSettingRepository.php +++ b/app/Repositories/GroupSettingRepository.php @@ -12,21 +12,9 @@ namespace App\Repositories; use App\Models\GroupSetting; -use App\Utils\Traits\MakesHash; class GroupSettingRepository extends BaseRepository { - use MakesHash; - - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return GroupSetting::class; - } public function save($data, GroupSetting $group_setting) :?GroupSetting { diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index a6d00636803e..8a286902917b 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -27,23 +27,14 @@ class InvoiceRepository extends BaseRepository { use MakesHash; - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Invoice::class; - } /** * Saves the invoices. * - * @param array. $data The invoice data - * @param InvoiceSum|Invoice $invoice The invoice + * @param array $data The invoice data + * @param Invoice $invoice The invoice * - * @return Invoice|InvoiceSum|null Returns the invoice object + * @return Invoice|null Returns the invoice object */ public function save($data, Invoice $invoice):?Invoice { diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 632c5ef47932..197e4eaac9ce 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -48,11 +48,6 @@ class PaymentMigrationRepository extends BaseRepository $this->activity_repo = new ActivityRepository(); } - public function getClassName() - { - return Payment::class; - } - /** * Saves and updates a payment. //todo refactor to handle refunds and payments. * diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index b83851a1ea39..de63f2472b25 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -41,15 +41,6 @@ class PaymentRepository extends BaseRepository $this->credit_repo = $credit_repo; } - /** - * @return string - */ - - public function getClassName() - { - return Payment::class; - } - /** * Saves and updates a payment. //todo refactor to handle refunds and payments. * diff --git a/app/Repositories/ProductRepository.php b/app/Repositories/ProductRepository.php index 350c7ebc39da..c5c8a1e7c0af 100644 --- a/app/Repositories/ProductRepository.php +++ b/app/Repositories/ProductRepository.php @@ -19,11 +19,6 @@ class ProductRepository extends BaseRepository { use SavesDocuments; - public function getClassName() - { - return Product::class; - } - /** * @param array $data * @param Product $product diff --git a/app/Repositories/ProjectRepository.php b/app/Repositories/ProjectRepository.php index b1010bf71d65..136ecadf9e55 100644 --- a/app/Repositories/ProjectRepository.php +++ b/app/Repositories/ProjectRepository.php @@ -19,13 +19,4 @@ use App\Models\Project; class ProjectRepository extends BaseRepository { - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Project::class; - } } diff --git a/app/Repositories/QuoteRepository.php b/app/Repositories/QuoteRepository.php index e0e70424fd6a..33aa4e34e554 100644 --- a/app/Repositories/QuoteRepository.php +++ b/app/Repositories/QuoteRepository.php @@ -27,12 +27,7 @@ use Illuminate\Http\Request; */ class QuoteRepository extends BaseRepository { - use MakesHash; - public function getClassName() - { - return Quote::class; - } public function save($data, Quote $quote) : ?Quote { diff --git a/app/Repositories/RecurringInvoiceRepository.php b/app/Repositories/RecurringInvoiceRepository.php index 7ef4d778ab36..9658caaaa533 100644 --- a/app/Repositories/RecurringInvoiceRepository.php +++ b/app/Repositories/RecurringInvoiceRepository.php @@ -20,10 +20,6 @@ use Illuminate\Http\Request; */ class RecurringInvoiceRepository extends BaseRepository { - public function getClassName() - { - return RecurringInvoice::class; - } public function save($data, RecurringInvoice $invoice) : ?RecurringInvoice { diff --git a/app/Repositories/RecurringQuoteRepository.php b/app/Repositories/RecurringQuoteRepository.php index 65e218e28dbe..a0894e8f3a9d 100644 --- a/app/Repositories/RecurringQuoteRepository.php +++ b/app/Repositories/RecurringQuoteRepository.php @@ -20,10 +20,7 @@ use Illuminate\Http\Request; */ class RecurringQuoteRepository extends BaseRepository { - public function getClassName() - { - return RecurringQuote::class; - } + public function save(Request $request, RecurringQuote $quote) : ?RecurringQuote { @@ -31,13 +28,10 @@ class RecurringQuoteRepository extends BaseRepository $quote->save(); - $quote_calc = new InvoiceSum($quote, $quote->settings); + $quote_calc = new InvoiceSum($quote); $quote = $quote_calc->build()->getQuote(); - //fire events here that cascading from the saving of an Quote - //ie. client balance update... - return $quote; } } diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 639567c25686..75f0e7817570 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -23,19 +23,6 @@ class TaskRepository extends BaseRepository { use GeneratesCounter; - public function __construct() - { - } - - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Task::class; - } /** * Saves the task and its contacts. diff --git a/app/Repositories/TokenRepository.php b/app/Repositories/TokenRepository.php index 39a559f376b1..aef6e1e20f44 100644 --- a/app/Repositories/TokenRepository.php +++ b/app/Repositories/TokenRepository.php @@ -15,15 +15,7 @@ use App\Models\CompanyToken; class TokenRepository extends BaseRepository { - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return CompanyToken::class; - } + /** * Saves the companytoken. diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index dfa0c531a117..6a55bd1aa5a6 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -27,24 +27,15 @@ class UserRepository extends BaseRepository { use MakesHash; - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return User::class; - } /** * Saves the user and its contacts. * * @param array $data The data - * @param \App\Models\user $user The user + * @param \App\Models\User $user The user * * @param bool $unset_company_user - * @return user|\App\Models\user|null user Object + * @return \App\Models\User user Object */ public function save(array $data, User $user, $unset_company_user = false) { diff --git a/app/Repositories/VendorRepository.php b/app/Repositories/VendorRepository.php index 165478c7e5ff..9b15eb5a3f5f 100644 --- a/app/Repositories/VendorRepository.php +++ b/app/Repositories/VendorRepository.php @@ -13,7 +13,7 @@ namespace App\Repositories; use App\Factory\VendorFactory; use App\Models\Vendor; -use App\Repositories\VSendorContactRepository; +use App\Repositories\VendorContactRepository; use App\Utils\Traits\GeneratesCounter; use Illuminate\Http\Request; @@ -23,37 +23,24 @@ use Illuminate\Http\Request; class VendorRepository extends BaseRepository { use GeneratesCounter; - /** - * @var vendorContactRepository - */ + protected $contact_repo; /** - * vendorController constructor. - * @param vendorContactRepository $contact_repo + * VendorContactRepository constructor. */ public function __construct(VendorContactRepository $contact_repo) { $this->contact_repo = $contact_repo; } - /** - * Gets the class name. - * - * @return string The class name. - */ - public function getClassName() - { - return Vendor::class; - } - /** * Saves the vendor and its contacts. * * @param array $data The data - * @param \App\Models\vendor $vendor The vendor + * @param \App\Models\Vendor $vendor The vendor * - * @return vendor|\App\Models\vendor|null vendor Object + * @return vendor|\App\Models\Vendor|null Vendor Object * @throws \Laracasts\Presenter\Exceptions\PresenterException */ public function save(array $data, Vendor $vendor) : ?Vendor @@ -70,7 +57,7 @@ class VendorRepository extends BaseRepository $vendor->save(); if (isset($data['contacts'])) { - $contacts = $this->contact_repo->save($data, $vendor); + $this->contact_repo->save($data, $vendor); } if (empty($data['name'])) { diff --git a/app/Services/Credit/CreateInvitations.php b/app/Services/Credit/CreateInvitations.php index 4a742effd293..45c7b1bff7a2 100644 --- a/app/Services/Credit/CreateInvitations.php +++ b/app/Services/Credit/CreateInvitations.php @@ -40,7 +40,7 @@ class CreateInvitations extends AbstractService $ii->credit_id = $this->credit->id; $ii->client_contact_id = $contact->id; $ii->save(); - } elseif ($invitation && ! $contact->send_email) { + } elseif (! $contact->send_email) { $invitation->delete(); } }); diff --git a/psalm.xml b/psalm.xml index 73bb3b38d930..ba56482e2e13 100644 --- a/psalm.xml +++ b/psalm.xml @@ -61,6 +61,11 @@ + + + + + From d762c5e842682bb808cbe354f86c5856e462b0d9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 00:34:24 +1100 Subject: [PATCH 2/9] Psalm code cleanup --- app/Repositories/CompanyRepository.php | 2 +- app/Repositories/DocumentRepository.php | 6 +++--- app/Repositories/ExpenseRepository.php | 8 ++++---- app/Repositories/InvoiceRepository.php | 8 +++----- app/Repositories/Migration/InvoiceMigrationRepository.php | 2 +- psalm.xml | 5 +++++ 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/Repositories/CompanyRepository.php b/app/Repositories/CompanyRepository.php index b68df6b6e342..70941a8a0ae0 100644 --- a/app/Repositories/CompanyRepository.php +++ b/app/Repositories/CompanyRepository.php @@ -28,7 +28,7 @@ class CompanyRepository extends BaseRepository * * @param array $data The data * @param Company $company - * @return Client|Company|null Company Object + * @return Company|null Company Object */ public function save(array $data, Company $company) : ?Company { diff --git a/app/Repositories/DocumentRepository.php b/app/Repositories/DocumentRepository.php index 1c60366f618f..b9521dc954cd 100644 --- a/app/Repositories/DocumentRepository.php +++ b/app/Repositories/DocumentRepository.php @@ -34,8 +34,8 @@ class DocumentRepository extends BaseRepository $document->restore(); - if (class_exists($className)) { - event(new $className($document, $document->company, Ninja::eventVars())); - } + // if (class_exists($className)) { + // event(new $className($document, $document->company, Ninja::eventVars())); + // } } } diff --git a/app/Repositories/ExpenseRepository.php b/app/Repositories/ExpenseRepository.php index 310a9315aad5..da7f7f80c916 100644 --- a/app/Repositories/ExpenseRepository.php +++ b/app/Repositories/ExpenseRepository.php @@ -28,10 +28,10 @@ class ExpenseRepository extends BaseRepository /** * Saves the expense and its contacts. * - * @param array $data The data - * @param \App\Models\expense $expense The expense + * @param array $data The data + * @param \App\Models\Expense $expense The expense * - * @return expense|null expense Object + * @return \App\Models\Expense|Null expense Object */ public function save(array $data, Expense $expense) : ?Expense { @@ -50,7 +50,7 @@ class ExpenseRepository extends BaseRepository * Store expenses in bulk. * * @param array $expense - * @return expense|null + * @return \App\Models\Expense|null */ public function create($expense): ?Expense { diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 8a286902917b..a80e2e5e6da3 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -66,18 +66,16 @@ class InvoiceRepository extends BaseRepository * ie. invoice can be deleted from a business logic perspective. * * @param Invoice $invoice - * @return void $invoice + * @return Invoice $invoice */ - public function delete($invoice) + public function delete($invoice) :Invoice { if ($invoice->is_deleted) { - return; + return $invoice; } $invoice->service()->markDeleted()->handleCancellation()->save(); - - $invoice = parent::delete($invoice); return $invoice; diff --git a/app/Repositories/Migration/InvoiceMigrationRepository.php b/app/Repositories/Migration/InvoiceMigrationRepository.php index 9230c9a80bfd..1b28ec5c52f5 100644 --- a/app/Repositories/Migration/InvoiceMigrationRepository.php +++ b/app/Repositories/Migration/InvoiceMigrationRepository.php @@ -100,7 +100,7 @@ class InvoiceMigrationRepository extends BaseRepository $invitations = collect($data['invitations']); /* Get array of Keys which have been removed from the invitations array and soft delete each invitation */ - $model->invitations->pluck('key')->diff($invitations->pluck('key'))->each(function ($invitation) { + $model->invitations->pluck('key')->diff($invitations->pluck('key'))->each(function ($invitation) use($resource){ $this->getInvitation($invitation, $resource)->delete(); }); diff --git a/psalm.xml b/psalm.xml index ba56482e2e13..2c1858a64e00 100644 --- a/psalm.xml +++ b/psalm.xml @@ -66,6 +66,11 @@ + + + + + From f98e7d15da7e0a62f429a70efc85b89e20a862a6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 00:57:48 +1100 Subject: [PATCH 3/9] fixes for updating products --- app/Jobs/Product/UpdateOrCreateProduct.php | 16 +++++++++++----- app/Repositories/BaseRepository.php | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Product/UpdateOrCreateProduct.php b/app/Jobs/Product/UpdateOrCreateProduct.php index 7f45f30c532d..8fc2cd654fd6 100644 --- a/app/Jobs/Product/UpdateOrCreateProduct.php +++ b/app/Jobs/Product/UpdateOrCreateProduct.php @@ -18,7 +18,6 @@ use App\Models\Product; use App\Repositories\InvoiceRepository; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Database\Capsule\Eloquent; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; @@ -27,11 +26,11 @@ class UpdateOrCreateProduct implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - private $products; + public $products; - private $invoice; + public $invoice; - private $company; + public $company; /** * Create a new job instance. @@ -59,7 +58,14 @@ class UpdateOrCreateProduct implements ShouldQueue { MultiDB::setDB($this->company->db); - foreach ($this->products as $item) { + //only update / create products - not tasks or gateway fees + $updateable_products = collect($this->products)->filter(function ($item) { + + return $item->type_id == 1; + + }); + + foreach ($updateable_products as $item) { if (empty($item->product_key)) { continue; } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 54ec44405f52..381bc754dffa 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -270,7 +270,7 @@ class BaseRepository $model = $model->service()->applyNumber()->save(); if ($model->company->update_products !== false) { - UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company); + UpdateOrCreateProduct::dispatchNow($model->line_items, $model, $model->company); } if ($class->name == Invoice::class) { From bbf240be2d85e4fbbf5e1ad4643737a88d2fbfb9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 07:19:59 +1100 Subject: [PATCH 4/9] New fields for company gateway --- app/Models/CompanyGateway.php | 8 +++-- app/Repositories/InvoiceRepository.php | 2 +- .../CompanyGatewayTransformer.php | 13 +++++-- ...200345_company_gateway_fields_refactor.php | 36 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2020_11_03_200345_company_gateway_fields_refactor.php diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 0de3bd5f226e..eae78caf1769 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -38,8 +38,12 @@ class CompanyGateway extends BaseModel 'gateway_key', 'accepted_credit_cards', 'require_cvv', - 'show_billing_address', - 'show_shipping_address', + 'require_billing_address', + 'require_shipping_address', + 'require_client_name', + 'require_zip', + 'require_client_phone', + 'require_contact_name', 'update_details', 'config', 'fees_and_limits', diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index a80e2e5e6da3..12a22121e484 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -76,7 +76,7 @@ class InvoiceRepository extends BaseRepository $invoice->service()->markDeleted()->handleCancellation()->save(); - $invoice = parent::delete($invoice); + parent::delete($invoice); return $invoice; } diff --git a/app/Transformers/CompanyGatewayTransformer.php b/app/Transformers/CompanyGatewayTransformer.php index 160391b735cc..fdfde7cce99f 100644 --- a/app/Transformers/CompanyGatewayTransformer.php +++ b/app/Transformers/CompanyGatewayTransformer.php @@ -49,8 +49,8 @@ class CompanyGatewayTransformer extends EntityTransformer 'gateway_key' => (string) $company_gateway->gateway_key ?: '', 'accepted_credit_cards' => (int) $company_gateway->accepted_credit_cards, 'require_cvv' => (bool) $company_gateway->require_cvv, - 'show_billing_address' => (bool) $company_gateway->show_billing_address, - 'show_shipping_address' => (bool) $company_gateway->show_shipping_address, + 'show_billing_address' => (bool) $company_gateway->show_billing_address, //@deprecated + 'show_shipping_address' => (bool) $company_gateway->show_shipping_address, //@deprecated 'update_details' => (bool) $company_gateway->update_details, 'config' => (string) $company_gateway->getConfigTransformed(), 'fees_and_limits' => $company_gateway->fees_and_limits ?: new stdClass, @@ -75,3 +75,12 @@ class CompanyGatewayTransformer extends EntityTransformer return $this->includeItem($company_gateway->gateway, $transformer, Gateway::class); } } + + + $table->renameColumn('show_billing_address', 'require_billing_address'); + $table->renameColumn('show_shipping_address', 'require_billing_address'); + $table->boolean('require_client_name')->default(false); + $table->boolean('require_zip')->default(false); + $table->boolean('require_client_phone')->default(false); + $table->boolean('require_contact_name')->default(false); + $table->boolean('require_contact_email')->default(false); \ No newline at end of file diff --git a/database/migrations/2020_11_03_200345_company_gateway_fields_refactor.php b/database/migrations/2020_11_03_200345_company_gateway_fields_refactor.php new file mode 100644 index 000000000000..18ac62d41d48 --- /dev/null +++ b/database/migrations/2020_11_03_200345_company_gateway_fields_refactor.php @@ -0,0 +1,36 @@ +renameColumn('show_billing_address', 'require_billing_address'); + $table->renameColumn('show_shipping_address', 'require_shipping_address'); + $table->boolean('require_client_name')->default(false); + $table->boolean('require_zip')->default(false); + $table->boolean('require_client_phone')->default(false); + $table->boolean('require_contact_name')->default(false); + $table->boolean('require_contact_email')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} From 64b703513d72447861e52152b59f73d725cf16be Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 08:26:28 +1100 Subject: [PATCH 5/9] Refactor company gateway schema for required fields --- app/Console/Commands/CreateSingleAccount.php | 20 +++++++++---------- .../OpenAPI/CompanyGatewaySchema.php | 4 ++-- app/Repositories/BaseRepository.php | 2 +- .../CompanyGatewayTransformer.php | 16 +++++++-------- database/seeders/RandomDataSeeder.php | 20 +++++++++---------- .../Feature/CompanyGatewayResolutionTest.php | 2 +- tests/Feature/CompanyGatewayTest.php | 6 +++--- tests/MockAccountData.php | 8 ++++---- tests/Unit/Migration/migration.json | 4 ++-- 9 files changed, 40 insertions(+), 42 deletions(-) diff --git a/app/Console/Commands/CreateSingleAccount.php b/app/Console/Commands/CreateSingleAccount.php index ecdcc40ea558..ba83e7ecba92 100644 --- a/app/Console/Commands/CreateSingleAccount.php +++ b/app/Console/Commands/CreateSingleAccount.php @@ -516,8 +516,8 @@ class CreateSingleAccount extends Command $cg->user_id = $user->id; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->save(); @@ -527,8 +527,8 @@ class CreateSingleAccount extends Command // $cg->user_id = $user->id; // $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; // $cg->require_cvv = true; - // $cg->show_billing_address = true; - // $cg->show_shipping_address = true; + // $cg->require_billing_address = true; + // $cg->require_shipping_address = true; // $cg->update_details = true; // $cg->config = encrypt(config('ninja.testvars.stripe')); // $cg->save(); @@ -540,8 +540,8 @@ class CreateSingleAccount extends Command $cg->user_id = $user->id; $cg->gateway_key = '38f2c48af60c7dd69e04248cbb24c36e'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.paypal')); $cg->save(); @@ -553,8 +553,8 @@ class CreateSingleAccount extends Command $cg->user_id = $user->id; $cg->gateway_key = '3758e7f7c6f4cecf0f4f348b9a00f456'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.checkout')); $cg->save(); @@ -566,8 +566,8 @@ class CreateSingleAccount extends Command $cg->user_id = $user->id; $cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.authorize')); $cg->save(); diff --git a/app/Http/Controllers/OpenAPI/CompanyGatewaySchema.php b/app/Http/Controllers/OpenAPI/CompanyGatewaySchema.php index a5009d01b461..ed483fd0585b 100644 --- a/app/Http/Controllers/OpenAPI/CompanyGatewaySchema.php +++ b/app/Http/Controllers/OpenAPI/CompanyGatewaySchema.php @@ -7,8 +7,8 @@ * @OA\Property(property="company_id", type="string", example="2", description="______"), * @OA\Property(property="gateway_key", type="string", example="2", description="______"), * @OA\Property(property="accepted_credit_cards", type="integer", example="32", description="Bitmask representation of cards"), - * @OA\Property(property="show_billing_address", type="boolean", example=true, description="______"), - * @OA\Property(property="show_shipping_address", type="boolean", example=true, description="______"), + * @OA\Property(property="require_billing_address", type="boolean", example=true, description="______"), + * @OA\Property(property="require_shipping_address", type="boolean", example=true, description="______"), * @OA\Property(property="config", type="string", example="dfadsfdsafsafd", description="The configuration map for the gateway"), * @OA\Property(property="update_details", type="boolean", example=true, description="______"), * @OA\Property( diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 381bc754dffa..54ec44405f52 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -270,7 +270,7 @@ class BaseRepository $model = $model->service()->applyNumber()->save(); if ($model->company->update_products !== false) { - UpdateOrCreateProduct::dispatchNow($model->line_items, $model, $model->company); + UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company); } if ($class->name == Invoice::class) { diff --git a/app/Transformers/CompanyGatewayTransformer.php b/app/Transformers/CompanyGatewayTransformer.php index fdfde7cce99f..6cc59b8b98f1 100644 --- a/app/Transformers/CompanyGatewayTransformer.php +++ b/app/Transformers/CompanyGatewayTransformer.php @@ -49,6 +49,13 @@ class CompanyGatewayTransformer extends EntityTransformer 'gateway_key' => (string) $company_gateway->gateway_key ?: '', 'accepted_credit_cards' => (int) $company_gateway->accepted_credit_cards, 'require_cvv' => (bool) $company_gateway->require_cvv, + 'require_billing_address' => (bool) $company_gateway->require_billing_address, + 'require_shipping_address' => (bool) $company_gateway->require_shipping_address, + 'require_client_name' => (bool) $company_gateway->require_client_name, + 'require_zip' => (bool) $company_gateway->require_zip, + 'require_client_phone' => (bool) $company_gateway->require_client_phone, + 'require_contact_name' => (bool) $company_gateway->require_contact_name, + 'require_contact_email' => (bool) $company_gateway->require_contact_email, 'show_billing_address' => (bool) $company_gateway->show_billing_address, //@deprecated 'show_shipping_address' => (bool) $company_gateway->show_shipping_address, //@deprecated 'update_details' => (bool) $company_gateway->update_details, @@ -75,12 +82,3 @@ class CompanyGatewayTransformer extends EntityTransformer return $this->includeItem($company_gateway->gateway, $transformer, Gateway::class); } } - - - $table->renameColumn('show_billing_address', 'require_billing_address'); - $table->renameColumn('show_shipping_address', 'require_billing_address'); - $table->boolean('require_client_name')->default(false); - $table->boolean('require_zip')->default(false); - $table->boolean('require_client_phone')->default(false); - $table->boolean('require_contact_name')->default(false); - $table->boolean('require_contact_email')->default(false); \ No newline at end of file diff --git a/database/seeders/RandomDataSeeder.php b/database/seeders/RandomDataSeeder.php index d2b75f333c52..d2e549129a2d 100644 --- a/database/seeders/RandomDataSeeder.php +++ b/database/seeders/RandomDataSeeder.php @@ -315,8 +315,8 @@ class RandomDataSeeder extends Seeder $cg->user_id = $user->id; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->save(); @@ -326,8 +326,8 @@ class RandomDataSeeder extends Seeder $cg->user_id = $user->id; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->save(); @@ -339,8 +339,8 @@ class RandomDataSeeder extends Seeder $cg->user_id = $user->id; $cg->gateway_key = '38f2c48af60c7dd69e04248cbb24c36e'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.paypal')); $cg->save(); @@ -352,8 +352,8 @@ class RandomDataSeeder extends Seeder $cg->user_id = $user->id; $cg->gateway_key = '3758e7f7c6f4cecf0f4f348b9a00f456'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.checkout')); $cg->save(); @@ -365,8 +365,8 @@ class RandomDataSeeder extends Seeder $cg->user_id = $user->id; $cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.authorize')); $cg->save(); diff --git a/tests/Feature/CompanyGatewayResolutionTest.php b/tests/Feature/CompanyGatewayResolutionTest.php index 8de3d96a7f9c..f23aa02caa02 100644 --- a/tests/Feature/CompanyGatewayResolutionTest.php +++ b/tests/Feature/CompanyGatewayResolutionTest.php @@ -101,7 +101,7 @@ class CompanyGatewayResolutionTest extends TestCase $this->cg->user_id = $this->user->id; $this->cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $this->cg->require_cvv = true; - $this->cg->show_billing_address = true; + $this->cg->require_billing_address = true; $this->cg->show_shipping_address = true; $this->cg->update_details = true; $this->cg->config = encrypt(json_encode($json_config)); diff --git a/tests/Feature/CompanyGatewayTest.php b/tests/Feature/CompanyGatewayTest.php index 8dc1499fc17a..5f83dc9e26fd 100644 --- a/tests/Feature/CompanyGatewayTest.php +++ b/tests/Feature/CompanyGatewayTest.php @@ -63,7 +63,7 @@ class CompanyGatewayTest extends TestCase $cg->user_id = $this->user->id; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; - $cg->show_billing_address = true; + $cg->require_billing_address = true; $cg->show_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); @@ -133,7 +133,7 @@ class CompanyGatewayTest extends TestCase $cg->user_id = $this->user->id; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; - $cg->show_billing_address = true; + $cg->require_billing_address = true; $cg->show_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); @@ -170,7 +170,7 @@ class CompanyGatewayTest extends TestCase $cg->user_id = $this->user->id; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; - $cg->show_billing_address = true; + $cg->require_billing_address = true; $cg->show_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index 6d6461e1e7d3..5dfeae55c8cb 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -539,8 +539,8 @@ trait MockAccountData $cg->user_id = $this->user->id; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->fees_and_limits = $data; @@ -551,8 +551,8 @@ trait MockAccountData $cg->user_id = $this->user->id; $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; - $cg->show_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_billing_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->fees_and_limits = $data; $cg->config = encrypt(config('ninja.testvars.stripe')); diff --git a/tests/Unit/Migration/migration.json b/tests/Unit/Migration/migration.json index 1307746a43b5..d73df558201f 100644 --- a/tests/Unit/Migration/migration.json +++ b/tests/Unit/Migration/migration.json @@ -65637,7 +65637,7 @@ "gateway_key": "16dc1d3c8a865425421f64463faaf768", "accepted_credit_cards": 0, "require_cvv": 1, - "show_billing_address": null, + "require_billing_address": null, "show_shipping_address": 0, "update_details": null, "config": "{\"apiKey\":\"345345345\",\"publishableKey\":\"5435345\",\"plaidClientId\":\"\",\"plaidSecret\":\"\",\"plaidPublicKey\":\"\",\"enableAlipay\":false,\"enableSofort\":false,\"enableSepa\":false,\"enableBitcoin\":false,\"enableApplePay\":false,\"enableAch\":false}", @@ -65666,7 +65666,7 @@ "gateway_key": "16dc1d3c8a865425421f64463faaf768", "accepted_credit_cards": 0, "require_cvv": 1, - "show_billing_address": null, + "require_billing_address": null, "show_shipping_address": 0, "update_details": null, "config": "{\"apiKey\":\"345345345\",\"publishableKey\":\"5435345\",\"plaidClientId\":\"\",\"plaidSecret\":\"\",\"plaidPublicKey\":\"\",\"enableAlipay\":false,\"enableSofort\":false,\"enableSepa\":false,\"enableBitcoin\":false,\"enableApplePay\":false,\"enableAch\":false}", From 4d58188da4c603086e1675fa1aee9ac3475f8332 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 08:29:53 +1100 Subject: [PATCH 6/9] Refactor company gateway schema for required fields --- tests/Feature/CompanyGatewayResolutionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/CompanyGatewayResolutionTest.php b/tests/Feature/CompanyGatewayResolutionTest.php index f23aa02caa02..b06d7eebc638 100644 --- a/tests/Feature/CompanyGatewayResolutionTest.php +++ b/tests/Feature/CompanyGatewayResolutionTest.php @@ -102,7 +102,7 @@ class CompanyGatewayResolutionTest extends TestCase $this->cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $this->cg->require_cvv = true; $this->cg->require_billing_address = true; - $this->cg->show_shipping_address = true; + $this->cg->require_shipping_address = true; $this->cg->update_details = true; $this->cg->config = encrypt(json_encode($json_config)); $this->cg->fees_and_limits = $data; From 3d674836077e02cf7fb701c168338dd3c515ed3e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 09:19:31 +1100 Subject: [PATCH 7/9] Fixes for tests --- tests/Feature/CompanyGatewayTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Feature/CompanyGatewayTest.php b/tests/Feature/CompanyGatewayTest.php index 5f83dc9e26fd..9d2159985c25 100644 --- a/tests/Feature/CompanyGatewayTest.php +++ b/tests/Feature/CompanyGatewayTest.php @@ -64,7 +64,7 @@ class CompanyGatewayTest extends TestCase $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; $cg->require_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->fees_and_limits = $data; @@ -134,7 +134,7 @@ class CompanyGatewayTest extends TestCase $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; $cg->require_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->fees_and_limits = $data; @@ -171,7 +171,7 @@ class CompanyGatewayTest extends TestCase $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23'; $cg->require_cvv = true; $cg->require_billing_address = true; - $cg->show_shipping_address = true; + $cg->require_shipping_address = true; $cg->update_details = true; $cg->config = encrypt(config('ninja.testvars.stripe')); $cg->fees_and_limits = $data; From a3acc6a01988fdcd32d9db6449a6a4ee646144cf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 09:47:06 +1100 Subject: [PATCH 8/9] Update or Create product --- app/Jobs/Product/UpdateOrCreateProduct.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/Product/UpdateOrCreateProduct.php b/app/Jobs/Product/UpdateOrCreateProduct.php index 8fc2cd654fd6..210046f6fced 100644 --- a/app/Jobs/Product/UpdateOrCreateProduct.php +++ b/app/Jobs/Product/UpdateOrCreateProduct.php @@ -57,7 +57,7 @@ class UpdateOrCreateProduct implements ShouldQueue public function handle() { MultiDB::setDB($this->company->db); - + //only update / create products - not tasks or gateway fees $updateable_products = collect($this->products)->filter(function ($item) { From 870a41a93eb7d2a724a173f0d80654a6ec2ac672 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Nov 2020 10:56:29 +1100 Subject: [PATCH 9/9] Fix for removing company logo from storage --- app/Http/Controllers/CompanyController.php | 4 ++++ app/Models/Credit.php | 1 + app/Utils/Traits/Uploadable.php | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index c703fe983b8f..f6668b6048f9 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -408,6 +408,10 @@ class CompanyController extends BaseController */ public function update(UpdateCompanyRequest $request, Company $company) { + + if($request->hasFile('company_logo') || !array_key_exists('company_logo', $request->input('settings'))) + $this->removeLogo($company); + $company = $this->company_repo->save($request->all(), $company); $company->saveSettings($request->input('settings'), $company); diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 63050b2a7b65..cd11e9ea578c 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -26,6 +26,7 @@ use App\Utils\Traits\MakesInvoiceValues; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Storage; use Laracasts\Presenter\PresentableTrait; class Credit extends BaseModel diff --git a/app/Utils/Traits/Uploadable.php b/app/Utils/Traits/Uploadable.php index b802bb5e10d6..d11f53f5396c 100644 --- a/app/Utils/Traits/Uploadable.php +++ b/app/Utils/Traits/Uploadable.php @@ -11,13 +11,33 @@ namespace App\Utils\Traits; +use App\Jobs\Util\UnlinkFile; use App\Jobs\Util\UploadAvatar; +use Illuminate\Support\Facades\Storage; /** * Class Uploadable. */ trait Uploadable { + + public function removeLogo($company) + { + $company_logo = $company->settings->company_logo; + +info("company logo to be deleted = {$company_logo}"); + + $file_name = basename($company_logo); + + $storage_path = $company->company_key . '/' . $file_name; + + if (Storage::exists($storage_path)) { + UnlinkFile::dispatchNow(config('filesystems.default'), $storage_path); + } + + + } + public function uploadLogo($file, $company, $entity) { if ($file) {