From 98dd01e1d5aca3ef15ba0315839bbc156f947450 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 27 Sep 2023 20:36:08 +1000 Subject: [PATCH] Stubbing mock data for templates --- app/Http/Controllers/PreviewController.php | 21 ++++--- app/Services/Template/MockTrait.php | 22 +++++++ app/Services/Template/TemplateMock.php | 69 ++++++++++++++++++++++ app/Services/Template/TemplateService.php | 48 +++++++++------ 4 files changed, 133 insertions(+), 27 deletions(-) create mode 100644 app/Services/Template/MockTrait.php create mode 100644 app/Services/Template/TemplateMock.php diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 9dfcd7db9c..9535f31c47 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -16,6 +16,7 @@ use App\Utils\Ninja; use App\Models\Quote; use App\Models\Client; use App\Models\Credit; +use App\Models\Vendor; use App\Models\Invoice; use App\Models\Payment; use App\Models\Project; @@ -24,6 +25,7 @@ use App\Libraries\MultiDB; use App\Factory\QuoteFactory; use App\Jobs\Util\PreviewPdf; use App\Models\ClientContact; +use App\Models\PurchaseOrder; use App\Services\Pdf\PdfMock; use App\Factory\CreditFactory; use App\Factory\InvoiceFactory; @@ -51,7 +53,6 @@ use App\Http\Requests\Preview\DesignPreviewRequest; use App\Services\PdfMaker\Design as PdfDesignModel; use App\Services\PdfMaker\Design as PdfMakerDesign; use App\Http\Requests\Preview\PreviewInvoiceRequest; -use App\Models\PurchaseOrder; class PreviewController extends BaseController { @@ -358,17 +359,19 @@ class PreviewController extends BaseController /** @var \App\Models\Company $company */ $company = $user->company(); - // $template = request()->input('design'); $design_object = json_decode(json_encode(request()->input('design')),1); + $client_id = Invoice::whereHas('payments')->company()->where('is_deleted', 0)->orderBy('id','desc')->first()->client_id; + $vendor_id = PurchaseOrder::query()->company()->where('is_deleted', 0)->orderBy('id', 'desc')->first()->vendor_id; + $data = [ - 'invoices' => Invoice::whereHas('payments')->with('client','payments')->company()->orderBy('id','desc')->take(4)->get(), - 'quotes' => Quote::query()->company()->with('client')->orderBy('id','desc')->take(4)->get(), - 'credits' => Credit::query()->company()->with('client')->orderBy('id','desc')->take(4)->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(), - 'tasks' => Task::query()->with('client','invoice')->company()->orderBy('id','desc')->take(2)->get(), - 'projects' => Project::query()->with('tasks','client')->company()->orderBy('id','desc')->take(2)->get(), + 'invoices' => Invoice::whereHas('payments')->company()->with('client','payments')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(), + 'quotes' => Quote::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(), + 'credits' => Credit::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(), + 'payments' => Payment::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(), + 'purchase_orders' => PurchaseOrder::query()->company()->with('vendor')->where('vendor_id', $vendor_id)->orderBy('id','desc')->take(5)->get(), + 'tasks' => Task::query()->company()->with('client','invoice')->where('client_id', $client_id)->orderBy('id','desc')->take(2)->get(), + 'projects' => Project::query()->company()->with('tasks','client')->where('client_id', $client_id)->orderBy('id','desc')->take(2)->get(), ]; $ts = (new TemplateService()); diff --git a/app/Services/Template/MockTrait.php b/app/Services/Template/MockTrait.php new file mode 100644 index 0000000000..32926a46a6 --- /dev/null +++ b/app/Services/Template/MockTrait.php @@ -0,0 +1,22 @@ +Default company invoice terms<\/p>", "public_notes": "", "private_notes": "", "uses_inclusive_taxes": false, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "total_taxes": 0, "is_amount_discount": true, "footer": "

Default invoice footer<\/p>", "partial": 0, "partial_due_date": "", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "has_tasks": false, "has_expenses": false, "custom_surcharge1": 0, "custom_surcharge2": 0, "custom_surcharge3": 0, "custom_surcharge4": 0, "exchange_rate": 1, "custom_surcharge_tax1": false, "custom_surcharge_tax2": false, "custom_surcharge_tax3": false, "custom_surcharge_tax4": false, "line_items": [{ "_id": "1d9727b4-bc32-4c62-a291-3b595e638a3b", "quantity": 0, "cost": 33, "product_key": "t1", "product_cost": 0, "notes": "task 1 description", "discount": 0, "is_amount_discount": true, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 0, "gross_line_total": 0, "date": "", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "type_id": "2", "tax_id": "2", "task_id": "Volej0WbjN", "tax_amount": 0, "expense_id": "" }, { "_id": "37e6f099-d7c9-47ad-aaf3-2de38942959c", "quantity": 5, "cost": 123, "product_key": "t2", "product_cost": 0, "notes": "task 2 description", "discount": 0, "is_amount_discount": true, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 615, "gross_line_total": 615, "date": "", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "type_id": "2", "tax_id": "2", "task_id": "O5xe7pwa7r", "tax_amount": 0, "expense_id": "" }, { "_id": "d109e819-e839-4eeb-9c24-cd91cbfed7b5", "quantity": 5, "cost": 33, "product_key": "t3", "product_cost": 0, "notes": "task 3 description", "discount": 0, "is_amount_discount": true, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 165, "gross_line_total": 165, "date": "", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "type_id": "2", "tax_id": "2", "task_id": "QK9b6B7bEv", "tax_amount": 0, "expense_id": "" }, { "_id": "ac64e02b-219c-4a18-9a7c-191dd5b8f21f", "quantity": 5, "cost": 67, "product_key": "t4", "product_cost": 0, "notes": "task 4 description", "discount": 0, "is_amount_discount": true, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 335, "gross_line_total": 335, "date": "", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "type_id": "2", "tax_id": "2", "task_id": "qM7e5Rxa2v", "tax_amount": 0, "expense_id": "" }, { "_id": "7b6dcee1-7b07-49b7-bcfa-2129ef844f07", "quantity": 5, "cost": 4, "product_key": "t5", "product_cost": 0, "notes": "task 5 description", "discount": 0, "is_amount_discount": true, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 20, "gross_line_total": 20, "date": "", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "type_id": "2", "tax_id": "2", "task_id": "KGRb4z2eBL", "tax_amount": 0, "expense_id": "" }, { "_id": "a8ef31c5-49ac-43f7-a40e-0e311b940589", "quantity": 5, "cost": 11, "product_key": "t6", "product_cost": 0, "notes": "task 6 description", "discount": 0, "is_amount_discount": true, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 55, "gross_line_total": 55, "date": "", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "type_id": "2", "tax_id": "2", "task_id": "GELe3yrb69", "tax_amount": 0, "expense_id": "" }], "entity_type": "invoice", "reminder1_sent": "", "reminder2_sent": "", "reminder3_sent": "", "reminder_last_sent": "", "paid_to_date": 444, "subscription_id": "", "auto_bill_enabled": false, "tax_info": {}, "client": { "id": "QJ0dN6dLOv", "user_id": "wMvbmOeYAl", "assigned_user_id": "", "name": "Paucek and Sons", "website": "http:\/\/www.wiegand.com\/sit-repellendus-enim-porro-aut-voluptas-voluptates.html", "private_notes": "In nihil non voluptas voluptatibus molestiae et. Nihil labore eligendi omnis id. Et cumque reiciendis blanditiis fugiat.", "balance": 19958.86, "group_settings_id": "", "paid_to_date": 18895.75, "payment_balance": 0, "credit_balance": 548.03, "last_login": 0, "size_id": "", "public_notes": "", "client_hash": "ngQe8O6SInYp1D0SKacHE8f6nzr3Gc1UkkoyGMKI", "address1": "873", "address2": "220 Hand Glen", "phone": "", "city": "Lake Kallie", "state": "Ohio", "postal_code": "77890", "country_id": "535", "industry_id": "", "custom_value1": "1974-10-02 21:56:55", "custom_value2": "Aqua", "custom_value3": "modi", "custom_value4": "xhomenick@hotmail.com", "shipping_address1": "89064", "shipping_address2": "87854 Meda Junction", "shipping_city": "South Aryanna", "shipping_state": "Connecticut", "shipping_postal_code": "52527-1873", "shipping_country_id": "4", "is_deleted": false, "vat_number": "881403416", "id_number": "MU19IWUA7340242407223765691CMM", "updated_at": 1695803284, "archived_at": 0, "created_at": 1695796650, "display_name": "Paucek and Sons", "number": "0005", "has_valid_vat_number": false, "is_tax_exempt": false, "routing_id": "", "tax_info": {}, "contacts": [{ "id": "yMYerkEaOB", "first_name": "Bret", "last_name": "Beatty", "email": "user@example.com", "created_at": 1695796650, "updated_at": 1695796650, "archived_at": 0, "is_primary": true, "is_locked": false, "phone": "1-985-403-1242", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "contact_key": "juMXBqyvDashDUvoYXsdcbZV2SRrFf0BOUFjsc6G", "send_email": true, "last_login": 0, "password": "**********", "link": "http:\/\/ninja.test:8000\/client\/key_login\/juMXBqyvDashDUvoYXsdcbZV2SRrFf0BOUFjsc6G" }, { "id": "gl9av2maG1", "first_name": "Sandra", "last_name": "Daniel", "email": "linnie.aufderhar@example.net", "created_at": 1695796650, "updated_at": 1695796650, "archived_at": 0, "is_primary": false, "is_locked": false, "phone": "+17319151379", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "contact_key": "sm53aNvvsGUmLXFku0RLPUrP0zLj3rzBcTaGMjHd", "send_email": true, "last_login": 0, "password": "**********", "link": "http:\/\/ninja.test:8000\/client\/key_login\/sm53aNvvsGUmLXFku0RLPUrP0zLj3rzBcTaGMjHd" }, { "id": "7LDdwpRe1Y", "first_name": "Leone", "last_name": "Bode", "email": "ipollich@example.org", "created_at": 1695796650, "updated_at": 1695796650, "archived_at": 0, "is_primary": false, "is_locked": false, "phone": "(424) 789-3412", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "contact_key": "gDUwiOqRehgCHWbbctW8qgKiLmma3xvsZi10a5Ma", "send_email": true, "last_login": 0, "password": "**********", "link": "http:\/\/ninja.test:8000\/client\/key_login\/gDUwiOqRehgCHWbbctW8qgKiLmma3xvsZi10a5Ma" }], "documents": { "data": [] }, "gateway_tokens": { "data": [] } }, "payments": [{ "id": "oBDbDxbl2E", "user_id": "wMvbmOeYAl", "assigned_user_id": "", "amount": 0, "refunded": 0, "applied": 0, "transaction_reference": "Manual entry", "transaction_id": "", "date": "2023-09-26", "is_manual": true, "created_at": 1695798370, "updated_at": 1695798370, "archived_at": 0, "is_deleted": false, "type_id": "", "invitation_id": "", "private_notes": "", "number": "0001", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "client_id": "QJ0dN6dLOv", "client_contact_id": "", "company_gateway_id": "", "gateway_type_id": "", "status_id": "4", "project_id": "", "vendor_id": "", "currency_id": "1", "exchange_rate": 1, "exchange_currency_id": "", "paymentables": [{ "id": "xYRdG7dDzO", "invoice_id": "mxkazm8eJ0", "amount": 0, "refunded": 0, "created_at": 1695798370, "updated_at": 1695798370, "archived_at": 0 }], "documents": { "data": [] }, "type": { "name": "" } }, { "id": "K4oeEva0By", "user_id": "wMvbmOeYAl", "assigned_user_id": "", "amount": 444, "refunded": 0, "applied": 444, "transaction_reference": "", "transaction_id": "", "date": "2023-09-27", "is_manual": true, "created_at": 1695799116, "updated_at": 1695799116, "archived_at": 0, "is_deleted": false, "type_id": "", "invitation_id": "", "private_notes": "", "number": "0002", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "client_id": "QJ0dN6dLOv", "client_contact_id": "", "company_gateway_id": "", "gateway_type_id": "", "status_id": "4", "project_id": "", "vendor_id": "", "currency_id": "1", "exchange_rate": 1, "exchange_currency_id": "", "paymentables": [{ "id": "1YQdJ2dOGp", "invoice_id": "mxkazm8eJ0", "amount": 444, "refunded": 0, "created_at": 1695799116, "updated_at": 1695799116, "archived_at": 0 }], "documents": { "data": [] }, "type": { "name": "" } }], "credits": [] }, { "id": "7N1aMj3bWm", "user_id": "wMvbmOeYAl", "project_id": "", "assigned_user_id": "", "amount": 9199.58, "balance": 0, "client_id": "QJ0dN6dLOv", "vendor_id": "", "status_id": "4", "design_id": "Wpmbk5ezJn", "recurring_id": "", "created_at": 1695799468, "updated_at": 1695803284, "archived_at": 0, "is_deleted": false, "number": "0027", "discount": 0, "po_number": "", "date": "2023-09-27", "last_sent_date": "", "next_send_date": "", "due_date": "", "terms": "

Default company quote terms<\/p>", "public_notes": "", "private_notes": "", "uses_inclusive_taxes": false, "tax_name1": "GST", "tax_rate1": 10, "tax_name2": "VAT", "tax_rate2": 17.5, "tax_name3": "", "tax_rate3": 0, "total_taxes": 2269.58, "is_amount_discount": true, "footer": "Default invoice footer", "partial": 0, "partial_due_date": "", "custom_value1": "1991-04-30", "custom_value2": "yes", "custom_value3": "", "custom_value4": "", "has_tasks": false, "has_expenses": false, "custom_surcharge1": 0, "custom_surcharge2": 0, "custom_surcharge3": 0, "custom_surcharge4": 0, "exchange_rate": 1, "custom_surcharge_tax1": false, "custom_surcharge_tax2": false, "custom_surcharge_tax3": false, "custom_surcharge_tax4": false, "line_items": [{ "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "Sales Tax", "tax_rate1": 5, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 727.65, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 34.65, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "f8b4d3e2-4460-4403-a2c2-2f4e0f0aa93b" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "Sales Tax", "tax_rate1": 5, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 727.65, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 34.65, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "9d1d7614-3286-4405-95e1-583b63a9243d" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 693, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 0, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "85886668-4ae6-4fe6-95fe-f7bfdd59e409" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "Sales Tax", "tax_rate1": 5, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 727.65, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 34.65, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "e6b7e129-2821-4e89-b378-dc8f46a00c00" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "Sales Tax", "tax_rate1": 5, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 727.65, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 34.65, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "a0eaa41c-4dce-4500-aa5d-fbae0906e42a" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "VAT", "tax_rate1": 17.5, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 814.28, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 121.28, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "ba7b8380-07a4-4898-9968-3f995e51b9a2" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "Sales Tax", "tax_rate1": 5, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 727.65, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 34.65, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "fe9d54c1-bd41-42df-b53d-8934088a3120" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "Sales Tax", "tax_rate1": 5, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 727.65, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 34.65, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "65c01100-0261-4f0c-9d19-9152d95c111b" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "", "tax_rate1": 0, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 693, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 0, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "5e325b00-904b-47bc-8a53-8bae8bbe10ff" }, { "quantity": 1, "cost": 693, "product_key": "Sed.", "notes": "Est sequi.", "discount": 0, "is_amount_discount": true, "tax_name1": "Sales Tax", "tax_rate1": 5, "tax_name2": "", "tax_rate2": 0, "tax_name3": "", "tax_rate3": 0, "sort_id": "0", "line_total": 693, "gross_line_total": 727.65, "custom_value1": "https:\/\/picsum.photos\/200", "custom_value2": "56", "custom_value3": "Dolores porro quia.", "custom_value4": "Perferendis itaque.", "type_id": "1", "product_cost": 0, "tax_amount": 34.65, "date": "", "tax_id": "1", "task_id": "", "expense_id": "", "_id": "483cdc42-a0c8-42db-974a-33edc91fdf30" }], "entity_type": "invoice", "reminder1_sent": "", "reminder2_sent": "", "reminder3_sent": "", "reminder_last_sent": "", "paid_to_date": 9199.58, "subscription_id": "", "auto_bill_enabled": false, "tax_info": {}, "client": { "id": "QJ0dN6dLOv", "user_id": "wMvbmOeYAl", "assigned_user_id": "", "name": "Paucek and Sons", "website": "http:\/\/www.wiegand.com\/sit-repellendus-enim-porro-aut-voluptas-voluptates.html", "private_notes": "In nihil non voluptas voluptatibus molestiae et. Nihil labore eligendi omnis id. Et cumque reiciendis blanditiis fugiat.", "balance": 19958.86, "group_settings_id": "", "paid_to_date": 18895.75, "payment_balance": 0, "credit_balance": 548.03, "last_login": 0, "size_id": "", "public_notes": "", "client_hash": "ngQe8O6SInYp1D0SKacHE8f6nzr3Gc1UkkoyGMKI", "address1": "873", "address2": "220 Hand Glen", "phone": "", "city": "Lake Kallie", "state": "Ohio", "postal_code": "77890", "country_id": "535", "industry_id": "", "custom_value1": "1974-10-02 21:56:55", "custom_value2": "Aqua", "custom_value3": "modi", "custom_value4": "xhomenick@hotmail.com", "shipping_address1": "89064", "shipping_address2": "87854 Meda Junction", "shipping_city": "South Aryanna", "shipping_state": "Connecticut", "shipping_postal_code": "52527-1873", "shipping_country_id": "4", "is_deleted": false, "vat_number": "881403416", "id_number": "MU19IWUA7340242407223765691CMM", "updated_at": 1695803284, "archived_at": 0, "created_at": 1695796650, "display_name": "Paucek and Sons", "number": "0005", "has_valid_vat_number": false, "is_tax_exempt": false, "routing_id": "", "tax_info": {}, "contacts": [{ "id": "yMYerkEaOB", "first_name": "Bret", "last_name": "Beatty", "email": "user@example.com", "created_at": 1695796650, "updated_at": 1695796650, "archived_at": 0, "is_primary": true, "is_locked": false, "phone": "1-985-403-1242", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "contact_key": "juMXBqyvDashDUvoYXsdcbZV2SRrFf0BOUFjsc6G", "send_email": true, "last_login": 0, "password": "**********", "link": "http:\/\/ninja.test:8000\/client\/key_login\/juMXBqyvDashDUvoYXsdcbZV2SRrFf0BOUFjsc6G" }, { "id": "gl9av2maG1", "first_name": "Sandra", "last_name": "Daniel", "email": "linnie.aufderhar@example.net", "created_at": 1695796650, "updated_at": 1695796650, "archived_at": 0, "is_primary": false, "is_locked": false, "phone": "+17319151379", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "contact_key": "sm53aNvvsGUmLXFku0RLPUrP0zLj3rzBcTaGMjHd", "send_email": true, "last_login": 0, "password": "**********", "link": "http:\/\/ninja.test:8000\/client\/key_login\/sm53aNvvsGUmLXFku0RLPUrP0zLj3rzBcTaGMjHd" }, { "id": "7LDdwpRe1Y", "first_name": "Leone", "last_name": "Bode", "email": "ipollich@example.org", "created_at": 1695796650, "updated_at": 1695796650, "archived_at": 0, "is_primary": false, "is_locked": false, "phone": "(424) 789-3412", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "contact_key": "gDUwiOqRehgCHWbbctW8qgKiLmma3xvsZi10a5Ma", "send_email": true, "last_login": 0, "password": "**********", "link": "http:\/\/ninja.test:8000\/client\/key_login\/gDUwiOqRehgCHWbbctW8qgKiLmma3xvsZi10a5Ma" }], "documents": { "data": [] }, "gateway_tokens": { "data": [] } }, "payments": [{ "id": "l4zbqx2apr", "user_id": "wMvbmOeYAl", "assigned_user_id": "", "amount": 9199.58, "refunded": 0, "applied": 9199.58, "transaction_reference": "Manual entry", "transaction_id": "", "date": "2023-09-26", "is_manual": true, "created_at": 1695803284, "updated_at": 1695803284, "archived_at": 0, "is_deleted": false, "type_id": "", "invitation_id": "", "private_notes": "", "number": "0007", "custom_value1": "", "custom_value2": "", "custom_value3": "", "custom_value4": "", "client_id": "QJ0dN6dLOv", "client_contact_id": "", "company_gateway_id": "", "gateway_type_id": "", "status_id": "4", "project_id": "", "vendor_id": "", "currency_id": "1", "exchange_rate": 1, "exchange_currency_id": "", "paymentables": [{ "id": "OpnelY5aKB", "invoice_id": "7N1aMj3bWm", "amount": 9199.58, "refunded": 0, "created_at": 1695803284, "updated_at": 1695803284, "archived_at": 0 }], "documents": { "data": [] }, "type": { "name": "" } }], "credits": [] }]'; + +} \ No newline at end of file diff --git a/app/Services/Template/TemplateMock.php b/app/Services/Template/TemplateMock.php new file mode 100644 index 0000000000..67989e8193 --- /dev/null +++ b/app/Services/Template/TemplateMock.php @@ -0,0 +1,69 @@ +company = $company; + + $variables = collect(['invoices', 'quotes', 'credits', 'payments', 'purchase_orders'])->map(function ($type) { + $this->createVariables($type); + })->toArray(); + + $variables = array_merge($variables, [ + 'invoices' => $this->createTemplate('invoices'), + 'quotes' => $this->createTemplate('quotes'), + 'credits' => $this->createTemplate('credits'), + 'tasks' => $this->createTemplate('tasks'), + 'projects' => $this->createTemplate('projects'), + 'payments' => $this->createTemplate('payments'), + 'purchase_orders' => $this->createTemplate('purchase_orders'), + ]); + + return $variables; + } + + /** + * ['entity_type','design','settings_type','settings'] + * + * @param string $type + * @return array + */ + private function createVariables(string $type): array + { + $data = [ + 'entity_type' => rtrim($type,"s"), + 'design' => '', + 'settings_type' => 'company', + 'settings' => $this->company->settings, + ]; + + $mock = (new PdfMock($data, $this->company))->build(); + + return [$type => $mock->getStubVariables()]; + } + + private function createTemplate(string $type): array + { + + } +} \ No newline at end of file diff --git a/app/Services/Template/TemplateService.php b/app/Services/Template/TemplateService.php index e49e1eee07..14aec7d1fa 100644 --- a/app/Services/Template/TemplateService.php +++ b/app/Services/Template/TemplateService.php @@ -43,6 +43,8 @@ class TemplateService private string $compiled_html = ''; + private array $data = []; + public function __construct(public ?Design $template = null) { $this->template = $template; @@ -78,30 +80,43 @@ class TemplateService public function build(array $data): self { $this->compose() - ->parseNinjaBlocks($data) + ->processData($data) + ->parseNinjaBlocks() ->parseVariables($data); return $this; } + public function mock(): self + { + + return $this; + } + public function getHtml(): string { return $this->compiled_html; } + + private function processData($data): self + { + + $this->data = $this->preProcessDataBlocks($data); + + nlog(json_encode($this->data)); + + return $this; + } + /** * Parses all Ninja tags in the document - * - * @param array $data * * @return self */ - private function parseNinjaBlocks(array $data): self + private function parseNinjaBlocks(): self { - $data = $this->preProcessDataBlocks($data); $replacements = []; - // nlog($data); - $contents = $this->document->getElementsByTagName('ninja'); foreach ($contents as $content) { @@ -109,9 +124,7 @@ class TemplateService $template = $content->ownerDocument->saveHTML($content); $template = $this->twig->createTemplate(html_entity_decode($template)); - $template = $template->render($data); - - // nlog($template); + $template = $template->render($this->data); $f = $this->document->createDocumentFragment(); $f->appendXML($template); @@ -196,7 +209,7 @@ class TemplateService * @return self */ public function setTemplate(array $partials): self - {nlog($partials); + { $html = ''; $html .= $partials['design']['includes']; @@ -262,28 +275,27 @@ class TemplateService })->toArray(); } - private function processInvoices($invoices): array + public function processInvoices($invoices): array { $it = new InvoiceTransformer(); - $it->setDefaultIncludes(['client','payments']); + $it->setDefaultIncludes(['client','payments', 'credits']); $manager = new Manager(); - $manager->parseIncludes(['client','payments','payments.type']); + $manager->parseIncludes(['client','payments','payments.type','credits']); $resource = new \League\Fractal\Resource\Collection($invoices, $it, null); $invoices = $manager->createData($resource)->toArray(); - // nlog($invoices); - foreach($invoices['data'] as $key => $invoice) { $invoices['data'][$key]['client'] = $invoice['client']['data'] ?? []; $invoices['data'][$key]['client']['contacts'] = $invoice['client']['data']['contacts']['data'] ?? []; $invoices['data'][$key]['payments'] = $invoice['payments']['data'] ?? []; + $invoices['data'][$key]['credits'] = $invoice['credits']['data'] ?? []; if($invoice['payments']['data'] ?? false) { foreach($invoice['payments']['data'] as $keyx => $payment) { - $invoices['data'][$key]['payments'][$keyx]['paymentables']= $payment['paymentables']['data'] ?? []; - $invoices['data'][$key]['payments'][$keyx]['type']= $payment['type']['data'] ?? []; + $invoices['data'][$key]['payments'][$keyx]['paymentables'] = $payment['paymentables']['data'] ?? []; + $invoices['data'][$key]['payments'][$keyx]['type'] = $payment['type']['data'] ?? []; } }