From 4c5c43c390441570dabef699c931f7cdbaf16b3e Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 13 Jun 2019 14:32:34 +1000 Subject: [PATCH] Fixed order processing, broken after upgrade to Laravel 5.8 --- .../External/Accounting/Quickbooks.php | 21 ++++++++++++++++++- app/Console/Commands/QuickAccounts.php | 6 ------ app/Models/Account.php | 3 +++ app/Models/AdslPlan.php | 2 +- app/Models/Base/ServiceType.php | 4 ---- app/Models/PlanVoip.php | 2 +- app/Models/Service.php | 6 ++++-- app/Models/Service/Adsl.php | 6 ++++++ app/Models/Service/Domain.php | 6 ++++++ app/Models/Service/Host.php | 6 ++++++ app/Models/Service/SSL.php | 7 +++++++ app/Models/Service/Voip.php | 6 ++++++ app/Traits/NextKey.php | 9 +++++++- 13 files changed, 68 insertions(+), 16 deletions(-) diff --git a/app/Classes/External/Accounting/Quickbooks.php b/app/Classes/External/Accounting/Quickbooks.php index 5ea034b..66443a4 100644 --- a/app/Classes/External/Accounting/Quickbooks.php +++ b/app/Classes/External/Accounting/Quickbooks.php @@ -7,7 +7,6 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cache; use QuickBooksOnline\API\Data\IPPCustomer; -use QuickBooksOnline\API\Facades\Customer; use App\User; use App\Classes\External\Accounting as Base; @@ -36,6 +35,26 @@ class Quickbooks extends Base }); } + public function getInvoice(int $id,$refresh=FALSE) + { + if ($refresh) + Cache::forget(__METHOD__.$id); + + return Cache::remember(__METHOD__.$id,86400,function() use ($id) { + return $this->api->getDataService()->Query(sprintf("SELECT * FROM Invoice where id = '%s'",$id)); + }); + } + + public function getInvoices($refresh=FALSE): Collection + { + if ($refresh) + Cache::forget(__METHOD__); + + return Cache::remember(__METHOD__,86400,function() { + return collect($this->api->getDataService()->Query('SELECT * FROM Invoice')); + }); + } + public function updateCustomer(IPPCustomer $r,array $args) { $r->sparse = TRUE; diff --git a/app/Console/Commands/QuickAccounts.php b/app/Console/Commands/QuickAccounts.php index 9593af4..ed3b083 100644 --- a/app/Console/Commands/QuickAccounts.php +++ b/app/Console/Commands/QuickAccounts.php @@ -4,8 +4,6 @@ namespace App\Console\Commands; use App\User; use Illuminate\Console\Command; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Log; use App\Classes\External\Accounting\Quickbooks; use App\Models\Account; @@ -47,10 +45,6 @@ class QuickAccounts extends Command */ public function handle() { - DB::listen(function($query) { - Log::debug('- SQL',['sql'=>$query->sql,'binding'=>$query->bindings]); - }); - foreach (Integrations::active()->type('ACCOUNTING')->get() as $into) { switch ($into->name) diff --git a/app/Models/Account.php b/app/Models/Account.php index d26d05d..633eeeb 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -9,6 +9,9 @@ use App\Traits\NextKey; class Account extends Model { use NextKey; + + const RECORD_ID = 'account'; + public $incrementing = FALSE; protected $table = 'ab_account'; diff --git a/app/Models/AdslPlan.php b/app/Models/AdslPlan.php index ce61022..71fdb57 100644 --- a/app/Models/AdslPlan.php +++ b/app/Models/AdslPlan.php @@ -21,7 +21,7 @@ class AdslPlan extends Model ], ]; - protected $order_model = ServiceAdsl::class; + protected $order_model = Service\Adsl::class; public function product() { diff --git a/app/Models/Base/ServiceType.php b/app/Models/Base/ServiceType.php index 6519241..0fd2060 100644 --- a/app/Models/Base/ServiceType.php +++ b/app/Models/Base/ServiceType.php @@ -4,12 +4,8 @@ namespace App\Models\Base; use Illuminate\Database\Eloquent\Model; -use App\Traits\NextKey; - abstract class ServiceType extends Model { - use NextKey; - public $timestamps = FALSE; public $dateFormat = 'U'; diff --git a/app/Models/PlanVoip.php b/app/Models/PlanVoip.php index 31cb7eb..216b5f4 100644 --- a/app/Models/PlanVoip.php +++ b/app/Models/PlanVoip.php @@ -31,5 +31,5 @@ class PlanVoip extends Model ], ]; - protected $order_model = ServiceVoip::class; + protected $order_model = Service\Voip::class; } \ No newline at end of file diff --git a/app/Models/Service.php b/app/Models/Service.php index ca7441d..ac66350 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -10,9 +10,11 @@ class Service extends Model { use NextKey; - public $incrementing = FALSE; + const RECORD_ID = 'service'; + const CREATED_AT = 'date_orig'; const UPDATED_AT = 'date_last'; + public $incrementing = FALSE; protected $table = 'ab_service'; protected $with = ['product.descriptions','account.language']; @@ -86,7 +88,7 @@ class Service extends Model * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function orderedby() + public function orderby() { return $this->belongsTo(Account::class); } diff --git a/app/Models/Service/Adsl.php b/app/Models/Service/Adsl.php index 61ff7f0..9ad4cf6 100644 --- a/app/Models/Service/Adsl.php +++ b/app/Models/Service/Adsl.php @@ -2,8 +2,14 @@ namespace App\Models\Service; +use App\Traits\NextKey; + class Adsl extends \App\Models\Base\ServiceType { + use NextKey; + + const RECORD_ID = 'service__adsl'; + // @todo column service_id can be removed. protected $table = 'ab_service__adsl'; diff --git a/app/Models/Service/Domain.php b/app/Models/Service/Domain.php index b45d508..05d00f5 100644 --- a/app/Models/Service/Domain.php +++ b/app/Models/Service/Domain.php @@ -2,8 +2,14 @@ namespace App\Models\Service; +use App\Traits\NextKey; + class Domain extends \App\Models\Base\ServiceType { + use NextKey; + + const RECORD_ID = 'service__domain'; + protected $table = 'ab_service__domain'; public function tld() diff --git a/app/Models/Service/Host.php b/app/Models/Service/Host.php index b7b5fe7..2f0ada6 100644 --- a/app/Models/Service/Host.php +++ b/app/Models/Service/Host.php @@ -2,8 +2,14 @@ namespace App\Models\Service; +use App\Traits\NextKey; + class Host extends \App\Models\Base\ServiceType { + use NextKey; + + const RECORD_ID = 'service__hosting'; + protected $table = 'ab_service__hosting'; public function getNameAttribute() diff --git a/app/Models/Service/SSL.php b/app/Models/Service/SSL.php index 451018c..aa53b08 100644 --- a/app/Models/Service/SSL.php +++ b/app/Models/Service/SSL.php @@ -2,9 +2,16 @@ namespace App\Models\Service; +use App\Traits\NextKey; + class SSL extends \App\Models\Base\ServiceType { + use NextKey; + + const RECORD_ID = 'service__ssl'; + protected $table = 'ab_service__ssl'; + protected $_o = NULL; public function tld() diff --git a/app/Models/Service/Voip.php b/app/Models/Service/Voip.php index 2ba0937..12c697e 100644 --- a/app/Models/Service/Voip.php +++ b/app/Models/Service/Voip.php @@ -2,8 +2,14 @@ namespace App\Models\Service; +use App\Traits\NextKey; + class Voip extends \App\Models\Base\ServiceType { + use NextKey; + + const RECORD_ID = 'service__adsl'; + protected $table = 'ab_service__voip'; public function getFullNameAttribute() diff --git a/app/Traits/NextKey.php b/app/Traits/NextKey.php index fe3ca51..7133159 100644 --- a/app/Traits/NextKey.php +++ b/app/Traits/NextKey.php @@ -7,7 +7,7 @@ */ namespace App\Traits; -use App\Models\Module; +use App\Models\{Module,Record}; trait NextKey { @@ -27,6 +27,13 @@ trait NextKey throw new \Exception('Missing record_id const for '.get_class($model)); $mo = Module::where('name',$model::RECORD_ID)->firstOrFail(); + + if (! $mo->record) { + $mo->record = new Record; + $mo->record->module_id = $mo->id; + $mo->record->site_id = 1; // @todo + } + $mo->record->id = $model->id; $mo->record->save(); }