Fix for saving invoice client with id/public_id

This commit is contained in:
Hillel Coren 2016-04-21 13:01:36 +03:00
parent cf75a2c2d2
commit b27505f63c
5 changed files with 17 additions and 12 deletions

View File

@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
'App\Console\Commands\RemoveOrphanedDocuments',
'App\Console\Commands\ResetData',
'App\Console\Commands\CheckData',
'App\Console\Commands\PruneData',
'App\Console\Commands\SendRenewalInvoices',
'App\Console\Commands\ChargeRenewalInvoices',
'App\Console\Commands\SendReminders',

View File

@ -33,17 +33,17 @@ class InvoiceService extends BaseService
public function save($data, $checkSubPermissions = false)
{
if (isset($data['client'])) {
$can_save_client = !$checkSubPermissions;
if(!$can_save_client){
if(empty($data['client']['public_id']) || $data['client']['public_id']=='-1'){
$can_save_client = Client::canCreate();
}
else{
$can_save_client = Client::wherePublicId($data['client']['public_id'])->first()->canEdit();
$canSaveClient = !$checkSubPermissions;
if( ! $canSaveClient){
$clientPublicId = array_get($data, 'client.public_id') ?: array_get($data, 'client.id');
if (empty($clientPublicId) || $clientPublicId == '-1') {
$canSaveClient = Client::canCreate();
} else {
$canSaveClient = Client::scope($clientPublicId)->first()->canEdit();
}
}
if($can_save_client){
if ($canSaveClient) {
$client = $this->clientRepo->save($data['client']);
$data['client_id'] = $client->id;
}

View File

@ -63,10 +63,11 @@ class AddPageSize extends Migration
$table->boolean('is_early_access');
});
Schema::dropIfExists('expense_categories');
Schema::table('expenses', function ($table) {
$table->dropForeign('expenses_expense_category_id_foreign');
$table->dropColumn('expense_category_id');
});
Schema::dropIfExists('expense_categories');
}
}

File diff suppressed because one or more lines are too long

View File

@ -710,7 +710,7 @@ function calculateAmounts(invoice) {
total += roundToTwo(invoice.custom_value2);
}
invoice.total_amount = roundToTwo(total) - (roundToTwo(invoice.amount) - roundToTwo(invoice.balance));
invoice.total_amount = roundToTwo(roundToTwo(total) - (roundToTwo(invoice.amount) - roundToTwo(invoice.balance)));
invoice.discount_amount = discount;
invoice.tax_amount1 = taxAmount1;
invoice.tax_amount2 = taxAmount2;