diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 1ec499bf3c67..38fb9db080d6 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -448,7 +448,7 @@ class CreateTestData extends Command { $faker = \Faker\Factory::create(); - $invoice = InvoiceFactory::create($client->company->id, $client->user->id);//stub the company and user_id + $invoice = InvoiceFactory::create($client->company->id, $client->user->id, $client->getMergedSettings(), $client);//stub the company and user_id $invoice->client_id = $client->id; // $invoice->date = $faker->date(); $dateable = Carbon::now()->subDays(rand(0,90)); diff --git a/app/Console/Commands/SendTestEmails.php b/app/Console/Commands/SendTestEmails.php index 2d9b6d38fc15..2c1b6d1e9b0b 100644 --- a/app/Console/Commands/SendTestEmails.php +++ b/app/Console/Commands/SendTestEmails.php @@ -131,7 +131,7 @@ class SendTestEmails extends Command ]); } - $invoice = InvoiceFactory::create($company->id, $user->id); + $invoice = InvoiceFactory::create($company->id, $user->id, $client->getMergedSettings(), $client); $invoice->client_id = $client->id; $invoice->setRelation('client', $client); $invoice->save(); diff --git a/app/Factory/CreditFactory.php b/app/Factory/CreditFactory.php index aee479df9c2a..cb2886403b3c 100644 --- a/app/Factory/CreditFactory.php +++ b/app/Factory/CreditFactory.php @@ -16,7 +16,7 @@ use App\Models\Credit; class CreditFactory { - public static function create(int $company_id, int $user_id, object $settings, Client $client) :Credit + public static function create(int $company_id, int $user_id, object $settings= null, Client $client = null) :Credit { $credit = new Credit(); $credit->status_id = Credit::STATUS_DRAFT; @@ -24,9 +24,9 @@ class CreditFactory $credit->discount = 0; $credit->is_amount_discount = true; $credit->po_number = ''; - $credit->footer = strlen($settings->credit_footer) > 0 ? $settings->credit_footer : ''; - $credit->terms = strlen($settings->credit_terms) > 0 ? $settings->credit_terms : ''; - $credit->public_notes = strlen($client->public_notes) > 0 ? $client->public_notes : ''; + $credit->footer = isset($settings) && strlen($settings->credit_footer) > 0 ? $settings->credit_footer : ''; + $credit->terms = isset($settings) && strlen($settings->credit_terms) > 0 ? $settings->credit_terms : ''; + $credit->public_notes = isset($client) && strlen($client->public_notes) > 0 ? $client->public_notes : ''; $credit->private_notes = ''; $credit->date = null; $credit->due_date = null; diff --git a/app/Factory/InvoiceFactory.php b/app/Factory/InvoiceFactory.php index bf2ec8d69ca9..a4fbd744d2c5 100644 --- a/app/Factory/InvoiceFactory.php +++ b/app/Factory/InvoiceFactory.php @@ -19,7 +19,7 @@ use Illuminate\Support\Facades\Log; class InvoiceFactory { - public static function create(int $company_id, int $user_id, object $settings, Client $client) :Invoice + public static function create(int $company_id, int $user_id, object $settings = null, Client $client = null) :Invoice { $invoice = new Invoice(); $invoice->status_id = Invoice::STATUS_DRAFT; @@ -27,9 +27,9 @@ class InvoiceFactory $invoice->discount = 0; $invoice->is_amount_discount = true; $invoice->po_number = ''; - $invoice->footer = strlen($settings->invoice_footer) > 0 ? $settings->invoice_footer : ''; - $invoice->terms = strlen($settings->invoice_terms) > 0 ? $settings->invoice_terms : ''; - $invoice->public_notes = strlen($client->public_notes) > 0 ? $client->public_notes : ''; + $invoice->footer = isset($settings) && strlen($settings->invoice_footer) > 0 ? $settings->invoice_footer : ''; + $invoice->terms = isset($settings) && strlen($settings->invoice_terms) > 0 ? $settings->invoice_terms : ''; + $invoice->public_notes = isset($settings) && strlen($client->public_notes) > 0 ? $client->public_notes : ''; $invoice->private_notes = ''; $invoice->date = null; $invoice->due_date = null; diff --git a/app/Factory/QuoteFactory.php b/app/Factory/QuoteFactory.php index b2f3affd031e..e3e9d2715904 100644 --- a/app/Factory/QuoteFactory.php +++ b/app/Factory/QuoteFactory.php @@ -19,7 +19,7 @@ use Illuminate\Support\Facades\Log; class QuoteFactory { - public static function create(int $company_id, int $user_id, object $settings, Client $client) :Quote + public static function create(int $company_id, int $user_id, object $settings = null, Client $client = null) :Quote { $quote = new Quote(); $quote->status_id = Quote::STATUS_DRAFT; @@ -27,9 +27,9 @@ class QuoteFactory $quote->discount = 0; $quote->is_amount_discount = true; $quote->po_number = ''; - $quote->footer = strlen($settings->quote_footer) > 0 ? $settings->quote_footer : ''; - $quote->terms = strlen($settings->quote_terms) > 0 ? $settings->quote_terms : ''; - $quote->public_notes = strlen($client->public_notes) > 0 ? $client->public_notes : ''; + $quote->footer = isset($settings) && strlen($settings->quote_footer) > 0 ? $settings->quote_footer : ''; + $quote->terms = isset($settings) && strlen($settings->quote_terms) > 0 ? $settings->quote_terms : ''; + $quote->public_notes = isset($client) && strlen($client->public_notes) > 0 ? $client->public_notes : ''; $quote->private_notes = ''; $quote->date = null; $quote->due_date = null; diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 5a39e14dd807..0917c487e7ec 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -158,7 +158,8 @@ class InvoiceController extends BaseController { * */ public function create(CreateInvoiceRequest $request) { - $invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id); + + $invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id, $client->getMergedSettings(), $client); return $this->itemResponse($invoice); } diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index c439faae9748..1d9e5dd6eafb 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -45,7 +45,7 @@ class MarkPaid extends AbstractService $payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id); $payment->amount = $this->invoice->balance; - $payment->number = $this->getNextPaymentNumber($payment->client); + $payment->number = $this->getNextPaymentNumber($this->invoice->client); $payment->status_id = Payment::STATUS_COMPLETED; $payment->client_id = $this->invoice->client_id; $payment->transaction_reference = ctrans('texts.manual_entry'); diff --git a/tests/Feature/CompanyGatewayApiTest.php b/tests/Feature/CompanyGatewayApiTest.php index 6eef98f3f22f..2bf004d196a9 100644 --- a/tests/Feature/CompanyGatewayApiTest.php +++ b/tests/Feature/CompanyGatewayApiTest.php @@ -187,7 +187,7 @@ class CompanyGatewayApiTest extends TestCase ])->post('/api/v1/company_gateways', $data); - $response->assertStatus(302); + $response->assertStatus(200); } diff --git a/tests/Unit/Migration/ImportTest.php b/tests/Unit/Migration/ImportTest.php index f39c95059a49..79878c7d9acc 100644 --- a/tests/Unit/Migration/ImportTest.php +++ b/tests/Unit/Migration/ImportTest.php @@ -42,12 +42,13 @@ class ImportTest extends TestCase $this->makeTestData(); $migration_file = base_path() . '/tests/Unit/Migration/migration.json'; +// \Log::error($migration_file); +// $handle = fopen($migration_file, "r"); +// $migration_file = fread($handle, filesize($migration_file)); +// fclose($handle); - $handle = fopen($migration_file, "r"); - $migration_file = fread($handle, filesize($migration_file)); - fclose($handle); + $this->migration_array = json_decode(file_get_contents($migration_file),1); - $this->migration_array = json_decode($migration_file,1); } public function testImportClassExists() @@ -102,7 +103,7 @@ class ImportTest extends TestCase public function testInvoicesImporting() { - $this->makeTestData(); + //$this->makeTestData(); $this->invoice->forceDelete(); $this->quote->forceDelete(); diff --git a/tests/Unit/Migration/migration.json b/tests/Unit/Migration/migration.json index a60329d58bd8..1b656eb65b4f 100644 --- a/tests/Unit/Migration/migration.json +++ b/tests/Unit/Migration/migration.json @@ -17155,12 +17155,12 @@ "max_limit": 65317, "fee_amount": "0.00", "fee_percent": "0.000", - "tax_name1": null, - "tax_rate1": null, - "tax_name2": null, - "tax_rate2": null, - "tax_name3": "", - "tax_rate3": 0 + "fee_tax_name1": null, + "fee_tax_rate1": null, + "fee_tax_name2": null, + "fee_tax_rate2": null, + "fee_tax_name3": "", + "fee_tax_rate3": 0 } ], "custom_value1": "", @@ -17224,12 +17224,12 @@ "max_limit": 53254, "fee_amount": "0.00", "fee_percent": "0.000", - "tax_name1": null, - "tax_rate1": null, - "tax_name2": null, - "tax_rate2": null, - "tax_name3": "", - "tax_rate3": 0 + "fee_tax_name1": null, + "fee_tax_rate1": null, + "fee_tax_name2": null, + "fee_tax_rate2": null, + "fee_tax_name3": "", + "fee_tax_rate3": 0 } ], "custom_value1": "", @@ -17265,12 +17265,12 @@ "max_limit": 72857, "fee_amount": "0.00", "fee_percent": "0.000", - "tax_name1": null, - "tax_rate1": null, - "tax_name2": null, - "tax_rate2": null, - "tax_name3": "", - "tax_rate3": 0 + "fee_tax_name1": null, + "fee_tax_rate1": null, + "fee_tax_name2": null, + "fee_tax_rate2": null, + "fee_tax_name3": "", + "fee_tax_rate3": 0 } ], "custom_value1": "", @@ -17306,12 +17306,12 @@ "max_limit": 71349, "fee_amount": "0.00", "fee_percent": "0.000", - "tax_name1": null, - "tax_rate1": null, - "tax_name2": null, - "tax_rate2": null, - "tax_name3": "", - "tax_rate3": 0 + "fee_tax_name1": null, + "fee_tax_rate1": null, + "fee_tax_name2": null, + "fee_tax_rate2": null, + "fee_tax_name3": "", + "fee_tax_rate3": 0 } ], "custom_value1": "", @@ -17347,12 +17347,12 @@ "max_limit": 74365, "fee_amount": "0.00", "fee_percent": "0.000", - "tax_name1": null, - "tax_rate1": null, - "tax_name2": null, - "tax_rate2": null, - "tax_name3": "", - "tax_rate3": 0 + "fee_tax_name1": null, + "fee_tax_rate1": null, + "fee_tax_name2": null, + "fee_tax_rate2": null, + "fee_tax_name3": "", + "fee_tax_rate3": 0 } ], "custom_value1": "",