mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Implement Custom Values (#3619)
* Add report errors to account transformer * Implement resolving custom values
This commit is contained in:
parent
20bf35c054
commit
4c0bba7814
@ -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);
|
||||
|
@ -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'))) {
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ trait MakesInvoiceHtml
|
||||
|
||||
$labels = $entity->makeLabels();
|
||||
$values = $entity->makeValues($contact);
|
||||
|
||||
|
||||
$designer->build();
|
||||
|
||||
$data = [];
|
||||
|
@ -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 = [];
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
});
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user