diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index a8cd0623cc..1ade12baee 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -451,6 +451,9 @@ class CreateTestData extends Command $invoice->tax_rate3 = 5; } + $invoice->custom_value1 = $faker->date; + $invoice->custom_value2 = rand(0,1) ? 'yes' : 'no'; + $invoice->save(); $invoice_calc = new InvoiceSum($invoice); diff --git a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php index c697a4d1ee..3b87761650 100644 --- a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php @@ -38,8 +38,6 @@ class UpdateInvoiceRequest extends Request public function rules() { - \Log::error(print_r($this->all(),1)); - $rules = []; if($this->input('documents') && is_array($this->input('documents'))) { diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index bbce6931fb..0c2a11abc1 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -86,6 +86,7 @@ class AccountTransformer extends EntityTransformer 'current_version' => (string)config('ninja.app_version'), 'updated_at' => (int)$account->updated_at, 'archived_at' => (int)$account->deleted_at, + 'report_errors' => (bool)$account->report_errors, ]; } diff --git a/app/Utils/Traits/MakesInvoiceHtml.php b/app/Utils/Traits/MakesInvoiceHtml.php index 22c38f5c3c..a5642a6f0c 100644 --- a/app/Utils/Traits/MakesInvoiceHtml.php +++ b/app/Utils/Traits/MakesInvoiceHtml.php @@ -44,7 +44,7 @@ trait MakesInvoiceHtml $labels = $entity->makeLabels(); $values = $entity->makeValues($contact); - + $designer->build(); $data = []; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index 0e1c63e616..77f692f362 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -83,6 +83,47 @@ trait MakesInvoiceValues return ''; } + private function findCustomType($field) + { + $custom_fields = $this->company->custom_fields; + + if ($custom_fields && property_exists($custom_fields, $field)) { + $custom_field = $custom_fields->{$field}; + $custom_field_parts = explode("|", $custom_field); + + return $custom_field_parts[1]; + } + + return ''; + } + + /** + * This method produces the key /value pairs for + * custom fields + * + * We need to explode the field name and search for the | + * we split on the pipe, the first value is the field name + * and the second is the field _type_ + * + * We transform the $value depending the $field type + * + * @param string $field The full field name + * @param string $value The custom value + * @return array The key value pair + */ + private function makeCustomFieldKeyValuePair($field, $value) + { + if($this->findCustomType($field) == 'date') + $value = $this->formatDate($value, $this->client->date_format()); + elseif($this->findCustomType($field) == 'switch') + $value = ctrans('texts.'.$value); + + if(!$value) + $value = ''; + + return ['value' => $value, 'field' => $this->makeCustomField($field)]; + } + public function makeLabels($contact = null) :array { $data = []; diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php index f96054f399..6678eeb68e 100644 --- a/database/factories/CompanyFactory.php +++ b/database/factories/CompanyFactory.php @@ -10,16 +10,19 @@ $factory->define(App\Models\Company::class, function (Faker $faker) { 'ip' => $faker->ipv4, 'db' => config('database.default'), 'settings' => CompanySettings::defaults(), - 'custom_fields' => (object) ['invoice1' => '1', 'invoice2' => '2', 'client1'=>'3'], - - // 'address1' => $faker->secondaryAddress, - // 'address2' => $faker->address, - // 'city' => $faker->city, - // 'state' => $faker->state, - // 'postal_code' => $faker->postcode, - // 'country_id' => 4, - // 'phone' => $faker->phoneNumber, - // 'email' => $faker->safeEmail, - // 'logo' => 'https://www.invoiceninja.com/wp-content/themes/invoice-ninja/images/logo.png', + 'custom_fields' => (object) [ + 'invoice1' => '1|date', + 'invoice2' => '2|switch', + 'invoice3' => '3|', + 'invoice4' => '4', + 'client1'=>'1', + 'client2'=>'2', + 'client3'=>'3|date', + 'client4'=>'4|switch', + 'company1'=>'1|date', + 'company2'=>'2|switch', + 'company3'=>'3', + 'company4'=>'4', + ], ]; }); diff --git a/database/factories/InvoiceFactory.php b/database/factories/InvoiceFactory.php index 31b5199b9b..4569014ba7 100644 --- a/database/factories/InvoiceFactory.php +++ b/database/factories/InvoiceFactory.php @@ -17,8 +17,8 @@ $factory->define(App\Models\Invoice::class, function (Faker $faker) { 'tax_rate2' => 17.5, //'tax_name3' => 'THIRDTAX', //'tax_rate3' => 5, - // 'custom_value1' => $faker->numberBetween(1,4), - // 'custom_value2' => $faker->numberBetween(1,4), + 'custom_value1' => $faker->date, + 'custom_value2' => rand(0,1) ? 'yes' : 'no', // 'custom_value3' => $faker->numberBetween(1,4), // 'custom_value4' => $faker->numberBetween(1,4), 'is_deleted' => false,