mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Support custom product fields
This commit is contained in:
parent
bcb044a776
commit
d89690ebe4
@ -204,9 +204,10 @@ if (! defined('APP_NAME')) {
|
||||
define('FREQUENCY_TWO_WEEKS', 2);
|
||||
define('FREQUENCY_FOUR_WEEKS', 3);
|
||||
define('FREQUENCY_MONTHLY', 4);
|
||||
define('FREQUENCY_THREE_MONTHS', 5);
|
||||
define('FREQUENCY_SIX_MONTHS', 6);
|
||||
define('FREQUENCY_ANNUALLY', 7);
|
||||
define('FREQUENCY_TWO_MONTHS', 5);
|
||||
define('FREQUENCY_THREE_MONTHS', 6);
|
||||
define('FREQUENCY_SIX_MONTHS', 7);
|
||||
define('FREQUENCY_ANNUALLY', 8);
|
||||
|
||||
define('SESSION_TIMEZONE', 'timezone');
|
||||
define('SESSION_CURRENCY', 'currency');
|
||||
@ -392,6 +393,12 @@ if (! defined('APP_NAME')) {
|
||||
define('REMINDER2', 'reminder2');
|
||||
define('REMINDER3', 'reminder3');
|
||||
|
||||
define('RESET_FREQUENCY_DAILY', 1);
|
||||
define('RESET_FREQUENCY_WEEKLY', 2);
|
||||
define('RESET_FREQUENCY_MONTHLY', 3);
|
||||
define('RESET_FREQUENCY_QUATERLY', 4);
|
||||
define('RESET_FREQUENCY_YEARLY', 5);
|
||||
|
||||
define('REMINDER_DIRECTION_AFTER', 1);
|
||||
define('REMINDER_DIRECTION_BEFORE', 2);
|
||||
|
||||
|
@ -140,8 +140,7 @@ class ProductController extends BaseController
|
||||
$product->product_key = trim(Input::get('product_key'));
|
||||
$product->notes = trim(Input::get('notes'));
|
||||
$product->cost = trim(Input::get('cost'));
|
||||
$product->default_tax_rate_id = Input::get('default_tax_rate_id');
|
||||
|
||||
$product->fill(Input::all());
|
||||
$product->save();
|
||||
|
||||
$message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product');
|
||||
|
@ -16,6 +16,13 @@ class Frequency extends Eloquent
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public static function selectOptions()
|
||||
{
|
||||
$data = [];
|
||||
|
@ -31,6 +31,8 @@ class Product extends EntityModel
|
||||
'cost',
|
||||
'qty',
|
||||
'default_tax_rate_id',
|
||||
'custom_value1',
|
||||
'custom_value2',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -632,6 +632,8 @@ class InvoiceRepository extends BaseRepository
|
||||
if ($product && (Auth::user()->can('edit', $product))) {
|
||||
$product->notes = ($task || $expense) ? '' : $item['notes'];
|
||||
$product->cost = $expense ? 0 : $item['cost'];
|
||||
$product->custom_value1 = isset($item['custom_value1']) ? $item['custom_value1'] : null;
|
||||
$product->custom_value2 = isset($item['custom_value2']) ? $item['custom_value2'] : null;
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddCustomProductFields extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('products', function ($table) {
|
||||
$table->string('custom_value1')->nullable();
|
||||
$table->string('custom_value2')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('account_gateway_settings', function ($table) {
|
||||
$table->decimal('fee_amount', 13, 2)->nullable();
|
||||
$table->decimal('fee_percent', 13, 3)->nullable();
|
||||
$table->string('fee_tax_name1')->nullable();
|
||||
$table->string('fee_tax_name2')->nullable();
|
||||
$table->decimal('fee_tax_rate1', 13, 3)->nullable();
|
||||
$table->decimal('fee_tax_rate2', 13, 3)->nullable();
|
||||
});
|
||||
|
||||
Schema::table('invoice_items', function ($table) {
|
||||
$table->smallInteger('invoice_item_type_id')->default(1);
|
||||
});
|
||||
|
||||
Schema::table('accounts', function ($table) {
|
||||
$table->smallInteger('reset_counter_frequency_id')->nullable();
|
||||
});
|
||||
|
||||
DB::table('currencies')->where('code', '=', 'HKR')->update(['code' => 'HRK']);
|
||||
|
||||
// Add 'Two Months' frequency option
|
||||
if (DB::table('frequencies')->count() == 7) {
|
||||
DB::table('frequencies')->where('id', '=', 5)->update(['name' => 'Two months']);
|
||||
DB::table('frequencies')->where('id', '=', 6)->update(['name' => 'Three months']);
|
||||
DB::table('frequencies')->where('id', '=', 7)->update(['name' => 'Six months']);
|
||||
DB::table('frequencies')->insert(['name' => 'Yearly']);
|
||||
DB::statement('update invoices set frequency_id = frequency_id + 1 where frequency_id >= 5');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('products', function ($table) {
|
||||
$table->dropColumn('custom_value1');
|
||||
$table->dropColumn('custom_value2');
|
||||
});
|
||||
|
||||
Schema::table('account_gateway_settings', function ($table) {
|
||||
$table->dropColumn('fee_amount');
|
||||
$table->dropColumn('fee_percent');
|
||||
$table->dropColumn('fee_tax_rate1');
|
||||
$table->dropColumn('fee_tax_name1');
|
||||
$table->dropColumn('fee_tax_rate2');
|
||||
$table->dropColumn('fee_tax_name2');
|
||||
});
|
||||
|
||||
Schema::table('invoice_items', function ($table) {
|
||||
$table->dropColumn('invoice_item_type_id');
|
||||
});
|
||||
|
||||
Schema::table('accounts', function ($table) {
|
||||
$table->dropColumn('reset_counter_frequency_id');
|
||||
});
|
||||
|
||||
DB::table('currencies')->where('code', '=', 'HRK')->update(['code' => 'HKR']);
|
||||
}
|
||||
}
|
@ -24,14 +24,6 @@ class ConstantsSeeder extends Seeder
|
||||
Theme::create(['name' => 'united']);
|
||||
Theme::create(['name' => 'yeti']);
|
||||
|
||||
Frequency::create(['name' => 'Weekly']);
|
||||
Frequency::create(['name' => 'Two weeks']);
|
||||
Frequency::create(['name' => 'Four weeks']);
|
||||
Frequency::create(['name' => 'Monthly']);
|
||||
Frequency::create(['name' => 'Three months']);
|
||||
Frequency::create(['name' => 'Six months']);
|
||||
Frequency::create(['name' => 'Annually']);
|
||||
|
||||
Size::create(['name' => '1 - 3']);
|
||||
Size::create(['name' => '4 - 10']);
|
||||
Size::create(['name' => '11 - 50']);
|
||||
|
@ -52,7 +52,7 @@ class CurrenciesSeeder extends Seeder
|
||||
['name' => 'Aruban Florin', 'code' => 'AWG', 'symbol' => 'Afl. ', 'precision' => '2', 'thousand_separator' => ' ', 'decimal_separator' => '.'],
|
||||
['name' => 'Turkish Lira', 'code' => 'TRY', 'symbol' => 'TL ', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
|
||||
['name' => 'Romanian New Leu', 'code' => 'RON', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
|
||||
['name' => 'Croatian Kuna', 'code' => 'HKR', 'symbol' => 'kn', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
|
||||
['name' => 'Croatian Kuna', 'code' => 'HRK', 'symbol' => 'kn', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
|
||||
['name' => 'Saudi Riyal', 'code' => 'SAR', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
|
||||
['name' => 'Japanese Yen', 'code' => 'JPY', 'symbol' => '¥', 'precision' => '0', 'thousand_separator' => ',', 'decimal_separator' => '.'],
|
||||
['name' => 'Maldivian Rufiyaa', 'code' => 'MVR', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
|
||||
|
@ -28,5 +28,6 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call('PaymentTypesSeeder');
|
||||
$this->call('LanguageSeeder');
|
||||
$this->call('IndustrySeeder');
|
||||
$this->call('FrequencySeeder');
|
||||
}
|
||||
}
|
||||
|
31
database/seeds/FrequencySeeder.php
Normal file
31
database/seeds/FrequencySeeder.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Frequency;
|
||||
|
||||
class FrequencySeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Eloquent::unguard();
|
||||
|
||||
$frequencies = [
|
||||
['name' => 'Weekly'],
|
||||
['name' => 'Two weeks'],
|
||||
['name' => 'Four weeks'],
|
||||
['name' => 'Monthly'],
|
||||
['name' => 'Two months'],
|
||||
['name' => 'Three months'],
|
||||
['name' => 'Six months'],
|
||||
['name' => 'Annually'],
|
||||
];
|
||||
|
||||
foreach ($frequencies as $frequency) {
|
||||
$record = Frequency::whereName($frequency['name'])->first();
|
||||
if ($record) {
|
||||
//$record->save();
|
||||
} else {
|
||||
Frequency::create($frequency);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,8 @@ class UpdateSeeder extends Seeder
|
||||
$this->call('PaymentTypesSeeder');
|
||||
$this->call('LanguageSeeder');
|
||||
$this->call('IndustrySeeder');
|
||||
|
||||
$this->call('FrequencySeeder');
|
||||
|
||||
Cache::flush();
|
||||
}
|
||||
}
|
||||
|
@ -2374,6 +2374,11 @@ $LANG = array(
|
||||
'month_year' => 'MONTH/YEAR',
|
||||
'valid_thru' => 'Valid\nthru',
|
||||
|
||||
'product_fields' => 'Product Fields',
|
||||
'custom_product_fields_help' => 'Add a field when creating a product or invoice and display the label and value on the PDF.',
|
||||
'freq_two_months' => 'Two months',
|
||||
'freq_yearly' => 'Annually',
|
||||
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
@ -174,7 +174,7 @@
|
||||
<a href="#invoice_fields" aria-controls="invoice_fields" role="tab" data-toggle="tab">{{ trans('texts.invoice_fields') }}</a>
|
||||
</li>
|
||||
<li role="presentation">
|
||||
<a href="#invoice_item_fields" aria-controls="invoice_item_fields" role="tab" data-toggle="tab">{{ trans('texts.invoice_item_fields') }}</a>
|
||||
<a href="#product_fields" aria-controls="product_fields" role="tab" data-toggle="tab">{{ trans('texts.product_fields') }}</a>
|
||||
</li>
|
||||
<li role="presentation">
|
||||
<a href="#invoice_charges" aria-controls="invoice_charges" role="tab" data-toggle="tab">{{ trans('texts.invoice_charges') }}</a>
|
||||
@ -220,14 +220,14 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="invoice_item_fields">
|
||||
<div role="tabpanel" class="tab-pane" id="product_fields">
|
||||
<div class="panel-body">
|
||||
|
||||
{!! Former::text('custom_invoice_item_label1')
|
||||
->label(trans('texts.field_label')) !!}
|
||||
{!! Former::text('custom_invoice_item_label2')
|
||||
->label(trans('texts.field_label'))
|
||||
->help(trans('texts.custom_invoice_item_fields_help')) !!}
|
||||
->help(trans('texts.custom_product_fields_help')) !!}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
@ -21,6 +21,16 @@
|
||||
|
||||
{!! Former::text('product_key')->label('texts.product') !!}
|
||||
{!! Former::textarea('notes')->rows(6) !!}
|
||||
|
||||
@if ($account->hasFeature(FEATURE_INVOICE_SETTINGS))
|
||||
@if ($account->custom_invoice_item_label1)
|
||||
{!! Former::text('custom_value1')->label($account->custom_invoice_item_label1) !!}
|
||||
@endif
|
||||
@if ($account->custom_invoice_item_label2)
|
||||
{!! Former::text('custom_value2')->label($account->custom_invoice_item_label2) !!}
|
||||
@endif
|
||||
@endif
|
||||
|
||||
{!! Former::text('cost') !!}
|
||||
|
||||
@if ($account->invoice_item_taxes)
|
||||
|
@ -921,6 +921,16 @@ ko.bindingHandlers.productTypeahead = {
|
||||
$select.val('0 ' + datum.default_tax_rate.rate + ' ' + datum.default_tax_rate.name).trigger('change');
|
||||
}
|
||||
@endif
|
||||
@if (Auth::user()->isPro() && $account->custom_invoice_item_label1)
|
||||
if (datum.custom_value1) {
|
||||
model.custom_value1(datum.custom_value1);
|
||||
}
|
||||
@endif
|
||||
@if (Auth::user()->isPro() && $account->custom_invoice_item_label2)
|
||||
if (datum.custom_value2) {
|
||||
model.custom_value2(datum.custom_value2);
|
||||
}
|
||||
@endif
|
||||
@endif
|
||||
onItemChange();
|
||||
}).on('typeahead:change', function(element, datum, name) {
|
||||
|
Loading…
Reference in New Issue
Block a user