mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2026-03-03 00:47:02 +00:00
Merge branch 'v5-develop' of https://github.com/turbo124/invoiceninja into v5-develop
This commit is contained in:
@@ -527,11 +527,27 @@ class DesignController extends BaseController
|
||||
|
||||
$ids = request()->input('ids');
|
||||
|
||||
$designs = Design::withTrashed()->company()->whereIn('id', $this->transformKeys($ids));
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
|
||||
if($action == 'clone') {
|
||||
$design = Design::withTrashed()
|
||||
->whereIn('id', $this->transformKeys($ids))
|
||||
->where(function ($q){
|
||||
$q->where('company_id', auth()->user()->company()->id)
|
||||
->orWhereNull('company_id');
|
||||
})->first();
|
||||
|
||||
if($design){
|
||||
$this->design_repo->clone($design, $user);
|
||||
}
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
$designs = Design::withTrashed()->company()->whereIn('id', $this->transformKeys($ids));
|
||||
|
||||
$designs->each(function ($design, $key) use ($action, $user) {
|
||||
if ($user->can('edit', $design)) {
|
||||
$this->design_repo->{$action}($design);
|
||||
|
||||
@@ -88,6 +88,9 @@ class ValidInvoicesRules implements Rule
|
||||
} elseif ($inv->status_id == Invoice::STATUS_DRAFT && floatval($invoice['amount']) > floatval($inv->amount)) {
|
||||
$this->error_msg = 'Amount cannot be greater than invoice balance';
|
||||
return false;
|
||||
} elseif($invoice['amount'] < 0 && $inv->amount >= 0) {
|
||||
$this->error_msg = 'Amount cannot be negative';
|
||||
return false;
|
||||
} elseif (floatval($invoice['amount']) > floatval($inv->balance)) {
|
||||
$this->error_msg = ctrans('texts.amount_greater_than_balance_v5');
|
||||
return false;
|
||||
|
||||
@@ -75,5 +75,17 @@ class DesignRepository extends BaseRepository
|
||||
|
||||
}
|
||||
|
||||
public function clone($design, $user)
|
||||
{
|
||||
|
||||
$new_design = $design->replicate();
|
||||
$new_design->company_id = $user->company()->id;
|
||||
$new_design->user_id = $user->id;
|
||||
$new_design->name = $new_design->name.' clone '.date('Y-m-d H:i:s');
|
||||
$new_design->save();
|
||||
|
||||
return $new_design;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -219,6 +219,10 @@
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/beganovich/php-ansible"
|
||||
},
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/turbo124/snappdf"
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../admin-api"
|
||||
|
||||
1574
composer.lock
generated
1574
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,7 @@ class JsonDesignServiceTest extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->markTestSkipped('Skipping JsonDesignServiceTest');
|
||||
// Load test design
|
||||
$jsonPath = base_path('tests/Feature/Design/stubs/test_design_1.json');
|
||||
$this->testDesign = json_decode(file_get_contents($jsonPath), true);
|
||||
|
||||
@@ -45,6 +45,36 @@ class DesignApiTest extends TestCase
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testCloneDesign()
|
||||
{
|
||||
|
||||
$design = Design::find(2);
|
||||
|
||||
$this->assertNotNull($design);
|
||||
|
||||
$data = [
|
||||
'ids' => [$design->hashed_id],
|
||||
'action' => 'clone',
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/designs/bulk', $data);
|
||||
|
||||
|
||||
$response->assertStatus(204);
|
||||
|
||||
|
||||
$d = Design::query()->latest()->first();
|
||||
|
||||
|
||||
$this->assertEquals($this->user->id, $d->user_id);
|
||||
$this->assertEquals($this->company->id, $d->company_id);
|
||||
$this->assertEquals($design->name.' clone '.date('Y-m-d H:i:s'), $d->name);
|
||||
// $dsd = Design::all()->pluck('name')->toArray();
|
||||
}
|
||||
|
||||
public function testSelectiveDefaultDesignUpdatesInvoice()
|
||||
{
|
||||
$settings = ClientSettings::defaults();
|
||||
|
||||
Reference in New Issue
Block a user