Padding out data

This commit is contained in:
David Bomba 2023-09-27 18:10:22 +10:00
parent 1677482a11
commit 99e9723fea
7 changed files with 188 additions and 94 deletions

View File

@ -11,51 +11,52 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\DataMapper\ClientRegistrationFields; use stdClass;
use App\DataMapper\CompanySettings;
use App\DataMapper\FeesAndLimits;
use App\Events\Invoice\InvoiceWasCreated;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
use App\Factory\GroupSettingFactory;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory;
use App\Factory\RecurringInvoiceFactory;
use App\Factory\SubscriptionFactory;
use App\Helpers\Invoice\InvoiceSum;
use App\Jobs\Company\CreateCompanyTaskStatuses;
use App\Libraries\MultiDB;
use App\Models\Account;
use App\Models\BankIntegration;
use App\Models\BankTransaction;
use App\Models\BankTransactionRule;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\CompanyToken;
use App\Models\Country;
use App\Models\Credit;
use App\Models\Expense;
use App\Models\Product;
use App\Models\Project;
use App\Models\Quote;
use App\Models\RecurringInvoice;
use App\Models\Task;
use App\Models\TaxRate;
use App\Models\User;
use App\Models\Vendor;
use App\Models\VendorContact;
use App\Repositories\InvoiceRepository;
use App\Utils\Ninja;
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesHash;
use Carbon\Carbon; use Carbon\Carbon;
use Faker\Factory; use Faker\Factory;
use App\Models\Task;
use App\Models\User;
use App\Utils\Ninja;
use App\Models\Quote;
use App\Models\Client;
use App\Models\Credit;
use App\Models\Vendor;
use App\Models\Account;
use App\Models\Company;
use App\Models\Country;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Product;
use App\Models\Project;
use App\Models\TaxRate;
use App\Libraries\MultiDB;
use App\Models\CompanyToken;
use App\Models\ClientContact;
use App\Models\VendorContact;
use App\Models\CompanyGateway;
use App\Factory\InvoiceFactory;
use App\Models\BankIntegration;
use App\Models\BankTransaction;
use App\Utils\Traits\MakesHash;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache; use App\Models\RecurringInvoice;
use App\DataMapper\FeesAndLimits;
use App\DataMapper\CompanySettings;
use App\Factory\InvoiceItemFactory;
use App\Helpers\Invoice\InvoiceSum;
use App\Models\BankTransactionRule;
use App\Factory\GroupSettingFactory;
use App\Factory\SubscriptionFactory;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Cache;
use App\Utils\Traits\GeneratesCounter;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use stdClass; use App\Repositories\InvoiceRepository;
use App\Factory\RecurringInvoiceFactory;
use App\Events\Invoice\InvoiceWasCreated;
use App\DataMapper\ClientRegistrationFields;
use App\Jobs\Company\CreateCompanyTaskStatuses;
use App\Events\RecurringInvoice\RecurringInvoiceWasCreated;
class CreateSingleAccount extends Command class CreateSingleAccount extends Command
{ {
@ -303,6 +304,60 @@ class CreateSingleAccount extends Command
$this->createGateways($company, $user); $this->createGateways($company, $user);
$this->createSubsData($company, $user); $this->createSubsData($company, $user);
$repo = new \App\Repositories\TaskRepository();
Task::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\ExpenseRepository();
Expense::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\VendorRepository(new \App\Repositories\VendorContactRepository());
Vendor::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\ClientRepository(new \App\Repositories\ClientContactRepository());
Client::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\RecurringInvoiceRepository();
RecurringInvoice::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\InvoiceRepository();
Invoice::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\QuoteRepository();
Quote::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
$repo = new \App\Repositories\CreditRepository();
Credit::query()->cursor()->each(function ($t) use ($repo) {
$repo->save([], $t);
});
Project::query()->cursor()->each(function ($p) {
if(!isset($p->number)) {
$p->number = $this->getNextProjectNumber($p);
$p->save();
}
});
} }
private function createSubsData($company, $user) private function createSubsData($company, $user)

View File

@ -362,16 +362,15 @@ class PreviewController extends BaseController
$design_object = json_decode(json_encode(request()->input('design')),1); $design_object = json_decode(json_encode(request()->input('design')),1);
$data = [ $data = [
'invoices' => Invoice::whereHas('payments')->with('client','payments')->company()->orderBy('id','desc')->take(5)->get(), 'invoices' => Invoice::whereHas('payments')->with('client','payments')->company()->orderBy('id','desc')->take(4)->get(),
'quotes' => Quote::query()->company()->with('client')->orderBy('id','desc')->take(5)->get(), 'quotes' => Quote::query()->company()->with('client')->orderBy('id','desc')->take(4)->get(),
'credits' => Credit::query()->company()->with('client')->orderBy('id','desc')->take(5)->get(), 'credits' => Credit::query()->company()->with('client')->orderBy('id','desc')->take(4)->get(),
'payments' => Payment::query()->company()->with('client')->orderBy('id','desc')->take(5)->get(), 'payments' => Payment::query()->company()->with('client')->orderBy('id','desc')->take(4)->get(),
'purchase_orders' => PurchaseOrder::query()->with('vendor')->company()->orderBy('id','desc')->take(5)->get(), 'purchase_orders' => PurchaseOrder::query()->with('vendor')->company()->orderBy('id','desc')->take(5)->get(),
'tasks' => Task::query()->with('client','invoice')->company()->orderBy('id','desc')->take(5)->get(), 'tasks' => Task::query()->with('client','invoice')->company()->orderBy('id','desc')->take(2)->get(),
'projects' => Project::query()->with('tasks','client')->company()->orderBy('id','desc')->take(5)->get(), 'projects' => Project::query()->with('tasks','client')->company()->orderBy('id','desc')->take(2)->get(),
]; ];
nlog($design_object);
$ts = (new TemplateService()); $ts = (new TemplateService());
$ts->setTemplate($design_object) $ts->setTemplate($design_object)
->build($data); ->build($data);
@ -407,6 +406,11 @@ class PreviewController extends BaseController
} }
private function stubTemplateData()
{
}
private function blankEntity() private function blankEntity()
{ {

View File

@ -17,7 +17,7 @@ use App\Utils\Traits\GeneratesCounter;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
/** /**
* TaskRepository. * App\Repositories\TaskRepository.
*/ */
class TaskRepository extends BaseRepository class TaskRepository extends BaseRepository
{ {

View File

@ -100,7 +100,7 @@ class TemplateService
$data = $this->preProcessDataBlocks($data); $data = $this->preProcessDataBlocks($data);
$replacements = []; $replacements = [];
nlog($data); // nlog($data);
$contents = $this->document->getElementsByTagName('ninja'); $contents = $this->document->getElementsByTagName('ninja');
@ -310,12 +310,15 @@ class TemplateService
return $resources['data']; return $resources['data'];
} }
/**
* Pushes credits through the appropriate transformer
* and builds any required relationships
*
* @param mixed $credits
* @return array
*/
private function processCredits($credits): array private function processCredits($credits): array
{ {
$it = new CreditTransformer(); $it = new CreditTransformer();
@ -335,7 +338,13 @@ class TemplateService
} }
/**
* Pushes payments through the appropriate transformer
*
* @param mixed $payments
* @return array
*/
private function processPayments($payments): array private function processPayments($payments): array
{ {
$it = new PaymentTransformer(); $it = new PaymentTransformer();

View File

@ -14,6 +14,7 @@ namespace App\Transformers;
use App\Models\Activity; use App\Models\Activity;
use App\Models\Backup; use App\Models\Backup;
use App\Models\Client; use App\Models\Client;
use App\Models\Credit;
use App\Models\Document; use App\Models\Document;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\InvoiceInvitation; use App\Models\InvoiceInvitation;
@ -63,6 +64,13 @@ class InvoiceTransformer extends EntityTransformer
return $this->includeCollection($invoice->payments, $transformer, Payment::class); return $this->includeCollection($invoice->payments, $transformer, Payment::class);
} }
public function includeCredits(Invoice $invoice)
{
$transformer = new CreditTransformer($this->serializer);
return $this->includeCollection($invoice->credits, $transformer, Credit::class);
}
/* /*
public function includeExpenses(Invoice $invoice) public function includeExpenses(Invoice $invoice)
{ {

View File

@ -12,6 +12,7 @@
namespace App\Transformers; namespace App\Transformers;
use App\Models\Client; use App\Models\Client;
use App\Models\Credit;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Models\Document; use App\Models\Document;
@ -34,6 +35,7 @@ class PaymentTransformer extends EntityTransformer
'client', 'client',
'invoices', 'invoices',
'type', 'type',
'credits',
]; ];
public function __construct($serializer = null) public function __construct($serializer = null)
@ -50,6 +52,13 @@ class PaymentTransformer extends EntityTransformer
return $this->includeCollection($payment->invoices, $transformer, Invoice::class); return $this->includeCollection($payment->invoices, $transformer, Invoice::class);
} }
public function includeCredits(Payment $payment)
{
$transformer = new CreditTransformer($this->serializer);
return $this->includeCollection($payment->credits, $transformer, Credit::class);
}
public function includeClient(Payment $payment) public function includeClient(Payment $payment)
{ {
$transformer = new ClientTransformer($this->serializer); $transformer = new ClientTransformer($this->serializer);

87
composer.lock generated
View File

@ -485,16 +485,16 @@
}, },
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
"version": "3.281.13", "version": "3.281.14",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/aws/aws-sdk-php.git", "url": "https://github.com/aws/aws-sdk-php.git",
"reference": "5547757d891495713aa7d5770bf04124d48a6ab5" "reference": "4b5b8aab08ef0add75f086bc03c7651799d187db"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/5547757d891495713aa7d5770bf04124d48a6ab5", "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/4b5b8aab08ef0add75f086bc03c7651799d187db",
"reference": "5547757d891495713aa7d5770bf04124d48a6ab5", "reference": "4b5b8aab08ef0add75f086bc03c7651799d187db",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -574,9 +574,9 @@
"support": { "support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues", "issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.281.13" "source": "https://github.com/aws/aws-sdk-php/tree/3.281.14"
}, },
"time": "2023-09-25T18:07:38+00:00" "time": "2023-09-26T18:15:48+00:00"
}, },
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@ -1353,16 +1353,16 @@
}, },
{ {
"name": "doctrine/dbal", "name": "doctrine/dbal",
"version": "3.6.7", "version": "3.7.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/dbal.git", "url": "https://github.com/doctrine/dbal.git",
"reference": "8e0e268052b4a8974cb00215bb2892787021614f" "reference": "00d03067f07482f025d41ab55e4ba0db5eca2cdf"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/8e0e268052b4a8974cb00215bb2892787021614f", "url": "https://api.github.com/repos/doctrine/dbal/zipball/00d03067f07482f025d41ab55e4ba0db5eca2cdf",
"reference": "8e0e268052b4a8974cb00215bb2892787021614f", "reference": "00d03067f07482f025d41ab55e4ba0db5eca2cdf",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1378,9 +1378,9 @@
"doctrine/coding-standard": "12.0.0", "doctrine/coding-standard": "12.0.0",
"fig/log-test": "^1", "fig/log-test": "^1",
"jetbrains/phpstorm-stubs": "2023.1", "jetbrains/phpstorm-stubs": "2023.1",
"phpstan/phpstan": "1.10.34", "phpstan/phpstan": "1.10.35",
"phpstan/phpstan-strict-rules": "^1.5", "phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "9.6.12", "phpunit/phpunit": "9.6.13",
"psalm/plugin-phpunit": "0.18.4", "psalm/plugin-phpunit": "0.18.4",
"slevomat/coding-standard": "8.13.1", "slevomat/coding-standard": "8.13.1",
"squizlabs/php_codesniffer": "3.7.2", "squizlabs/php_codesniffer": "3.7.2",
@ -1446,7 +1446,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/doctrine/dbal/issues", "issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.6.7" "source": "https://github.com/doctrine/dbal/tree/3.7.0"
}, },
"funding": [ "funding": [
{ {
@ -1462,7 +1462,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-09-19T20:15:41+00:00" "time": "2023-09-26T20:56:55+00:00"
}, },
{ {
"name": "doctrine/deprecations", "name": "doctrine/deprecations",
@ -4287,16 +4287,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v10.24.0", "version": "v10.25.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "bcebd0a4c015d5c38aeec299d355a42451dd3726" "reference": "cd0a440f43eaaad247d6f6575d3782c156ec913c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/bcebd0a4c015d5c38aeec299d355a42451dd3726", "url": "https://api.github.com/repos/laravel/framework/zipball/cd0a440f43eaaad247d6f6575d3782c156ec913c",
"reference": "bcebd0a4c015d5c38aeec299d355a42451dd3726", "reference": "cd0a440f43eaaad247d6f6575d3782c156ec913c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4314,7 +4314,7 @@
"ext-tokenizer": "*", "ext-tokenizer": "*",
"fruitcake/php-cors": "^1.2", "fruitcake/php-cors": "^1.2",
"guzzlehttp/uri-template": "^1.0", "guzzlehttp/uri-template": "^1.0",
"laravel/prompts": "^0.1", "laravel/prompts": "^0.1.9",
"laravel/serializable-closure": "^1.3", "laravel/serializable-closure": "^1.3",
"league/commonmark": "^2.2.1", "league/commonmark": "^2.2.1",
"league/flysystem": "^3.8.0", "league/flysystem": "^3.8.0",
@ -4396,7 +4396,7 @@
"league/flysystem-read-only": "^3.3", "league/flysystem-read-only": "^3.3",
"league/flysystem-sftp-v3": "^3.0", "league/flysystem-sftp-v3": "^3.0",
"mockery/mockery": "^1.5.1", "mockery/mockery": "^1.5.1",
"orchestra/testbench-core": "^8.10", "orchestra/testbench-core": "^8.12",
"pda/pheanstalk": "^4.0", "pda/pheanstalk": "^4.0",
"phpstan/phpstan": "^1.4.7", "phpstan/phpstan": "^1.4.7",
"phpunit/phpunit": "^10.0.7", "phpunit/phpunit": "^10.0.7",
@ -4483,20 +4483,20 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2023-09-19T15:25:04+00:00" "time": "2023-09-27T01:29:32+00:00"
}, },
{ {
"name": "laravel/prompts", "name": "laravel/prompts",
"version": "v0.1.8", "version": "v0.1.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/prompts.git", "url": "https://github.com/laravel/prompts.git",
"reference": "68dcc65babf92e1fb43cba0b3f78fc3d8002709c" "reference": "b603410e7af1040aa2d29e0a2cdca570bb63e827"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/prompts/zipball/68dcc65babf92e1fb43cba0b3f78fc3d8002709c", "url": "https://api.github.com/repos/laravel/prompts/zipball/b603410e7af1040aa2d29e0a2cdca570bb63e827",
"reference": "68dcc65babf92e1fb43cba0b3f78fc3d8002709c", "reference": "b603410e7af1040aa2d29e0a2cdca570bb63e827",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4505,6 +4505,10 @@
"php": "^8.1", "php": "^8.1",
"symfony/console": "^6.2" "symfony/console": "^6.2"
}, },
"conflict": {
"illuminate/console": ">=10.17.0 <10.25.0",
"laravel/framework": ">=10.17.0 <10.25.0"
},
"require-dev": { "require-dev": {
"mockery/mockery": "^1.5", "mockery/mockery": "^1.5",
"pestphp/pest": "^2.3", "pestphp/pest": "^2.3",
@ -4515,6 +4519,11 @@
"ext-pcntl": "Required for the spinner to be animated." "ext-pcntl": "Required for the spinner to be animated."
}, },
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-main": "0.1.x-dev"
}
},
"autoload": { "autoload": {
"files": [ "files": [
"src/helpers.php" "src/helpers.php"
@ -4529,9 +4538,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/laravel/prompts/issues", "issues": "https://github.com/laravel/prompts/issues",
"source": "https://github.com/laravel/prompts/tree/v0.1.8" "source": "https://github.com/laravel/prompts/tree/v0.1.9"
}, },
"time": "2023-09-19T15:33:56+00:00" "time": "2023-09-26T13:14:20+00:00"
}, },
{ {
"name": "laravel/serializable-closure", "name": "laravel/serializable-closure",
@ -8127,16 +8136,16 @@
}, },
{ {
"name": "phpstan/phpdoc-parser", "name": "phpstan/phpdoc-parser",
"version": "1.24.1", "version": "1.24.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git", "url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01" "reference": "bcad8d995980440892759db0c32acae7c8e79442"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442",
"reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", "reference": "bcad8d995980440892759db0c32acae7c8e79442",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -8168,9 +8177,9 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types", "description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": { "support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues", "issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.1" "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2"
}, },
"time": "2023-09-18T12:18:02+00:00" "time": "2023-09-26T12:28:12+00:00"
}, },
{ {
"name": "pragmarx/google2fa", "name": "pragmarx/google2fa",
@ -15172,16 +15181,16 @@
}, },
{ {
"name": "friendsofphp/php-cs-fixer", "name": "friendsofphp/php-cs-fixer",
"version": "v3.28.0", "version": "v3.30.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
"reference": "113e09fea3d2306319ffaa2423fe3de768b28cff" "reference": "95c64693b2f149966a2bc05a7a4981b0343ea52f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/113e09fea3d2306319ffaa2423fe3de768b28cff", "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/95c64693b2f149966a2bc05a7a4981b0343ea52f",
"reference": "113e09fea3d2306319ffaa2423fe3de768b28cff", "reference": "95c64693b2f149966a2bc05a7a4981b0343ea52f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -15255,7 +15264,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
"source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.28.0" "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.30.0"
}, },
"funding": [ "funding": [
{ {
@ -15263,7 +15272,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-09-22T20:43:40+00:00" "time": "2023-09-26T22:10:43+00:00"
}, },
{ {
"name": "hamcrest/hamcrest-php", "name": "hamcrest/hamcrest-php",