mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 16:34:35 -04: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->tax_rate3 = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$invoice->custom_value1 = $faker->date;
|
||||||
|
$invoice->custom_value2 = rand(0,1) ? 'yes' : 'no';
|
||||||
|
|
||||||
$invoice->save();
|
$invoice->save();
|
||||||
|
|
||||||
$invoice_calc = new InvoiceSum($invoice);
|
$invoice_calc = new InvoiceSum($invoice);
|
||||||
|
@ -38,8 +38,6 @@ class UpdateInvoiceRequest extends Request
|
|||||||
|
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
\Log::error(print_r($this->all(),1));
|
|
||||||
|
|
||||||
$rules = [];
|
$rules = [];
|
||||||
|
|
||||||
if($this->input('documents') && is_array($this->input('documents'))) {
|
if($this->input('documents') && is_array($this->input('documents'))) {
|
||||||
|
@ -86,6 +86,7 @@ class AccountTransformer extends EntityTransformer
|
|||||||
'current_version' => (string)config('ninja.app_version'),
|
'current_version' => (string)config('ninja.app_version'),
|
||||||
'updated_at' => (int)$account->updated_at,
|
'updated_at' => (int)$account->updated_at,
|
||||||
'archived_at' => (int)$account->deleted_at,
|
'archived_at' => (int)$account->deleted_at,
|
||||||
|
'report_errors' => (bool)$account->report_errors,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ trait MakesInvoiceHtml
|
|||||||
|
|
||||||
$labels = $entity->makeLabels();
|
$labels = $entity->makeLabels();
|
||||||
$values = $entity->makeValues($contact);
|
$values = $entity->makeValues($contact);
|
||||||
|
|
||||||
$designer->build();
|
$designer->build();
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
@ -83,6 +83,47 @@ trait MakesInvoiceValues
|
|||||||
return '';
|
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
|
public function makeLabels($contact = null) :array
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
|
@ -10,16 +10,19 @@ $factory->define(App\Models\Company::class, function (Faker $faker) {
|
|||||||
'ip' => $faker->ipv4,
|
'ip' => $faker->ipv4,
|
||||||
'db' => config('database.default'),
|
'db' => config('database.default'),
|
||||||
'settings' => CompanySettings::defaults(),
|
'settings' => CompanySettings::defaults(),
|
||||||
'custom_fields' => (object) ['invoice1' => '1', 'invoice2' => '2', 'client1'=>'3'],
|
'custom_fields' => (object) [
|
||||||
|
'invoice1' => '1|date',
|
||||||
// 'address1' => $faker->secondaryAddress,
|
'invoice2' => '2|switch',
|
||||||
// 'address2' => $faker->address,
|
'invoice3' => '3|',
|
||||||
// 'city' => $faker->city,
|
'invoice4' => '4',
|
||||||
// 'state' => $faker->state,
|
'client1'=>'1',
|
||||||
// 'postal_code' => $faker->postcode,
|
'client2'=>'2',
|
||||||
// 'country_id' => 4,
|
'client3'=>'3|date',
|
||||||
// 'phone' => $faker->phoneNumber,
|
'client4'=>'4|switch',
|
||||||
// 'email' => $faker->safeEmail,
|
'company1'=>'1|date',
|
||||||
// 'logo' => 'https://www.invoiceninja.com/wp-content/themes/invoice-ninja/images/logo.png',
|
'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_rate2' => 17.5,
|
||||||
//'tax_name3' => 'THIRDTAX',
|
//'tax_name3' => 'THIRDTAX',
|
||||||
//'tax_rate3' => 5,
|
//'tax_rate3' => 5,
|
||||||
// 'custom_value1' => $faker->numberBetween(1,4),
|
'custom_value1' => $faker->date,
|
||||||
// 'custom_value2' => $faker->numberBetween(1,4),
|
'custom_value2' => rand(0,1) ? 'yes' : 'no',
|
||||||
// 'custom_value3' => $faker->numberBetween(1,4),
|
// 'custom_value3' => $faker->numberBetween(1,4),
|
||||||
// 'custom_value4' => $faker->numberBetween(1,4),
|
// 'custom_value4' => $faker->numberBetween(1,4),
|
||||||
'is_deleted' => false,
|
'is_deleted' => false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user