1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Merge pull request #4672 from turbo124/v5-develop

Changes to schema for expenses, drop redundant columns from company
This commit is contained in:
David Bomba 2021-01-13 07:21:35 +11:00 committed by GitHub
commit 8bd6f41bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 62 additions and 41 deletions

View File

@ -64,10 +64,10 @@ class InvoiceItemFactory
$item->discount = $faker->numberBetween(1, 10);
$item->notes = $faker->realText(50);
$item->product_key = $faker->word();
$item->custom_value1 = $faker->realText(10);
$item->custom_value2 = $faker->realText(10);
$item->custom_value3 = $faker->realText(10);
$item->custom_value4 = $faker->realText(10);
// $item->custom_value1 = $faker->realText(10);
// $item->custom_value2 = $faker->realText(10);
// $item->custom_value3 = $faker->realText(10);
// $item->custom_value4 = $faker->realText(10);
$item->tax_name1 = 'GST';
$item->tax_rate1 = 10.00;
$item->type_id = "1";
@ -98,10 +98,10 @@ class InvoiceItemFactory
$item->discount = 0;
$item->notes = $faker->realText(20);
$item->product_key = $faker->word();
$item->custom_value1 = $faker->realText(10);
$item->custom_value2 = $faker->realText(10);
$item->custom_value3 = $faker->realText(10);
$item->custom_value4 = $faker->realText(10);
// $item->custom_value1 = $faker->realText(10);
// $item->custom_value2 = $faker->realText(10);
// $item->custom_value3 = $faker->realText(10);
// $item->custom_value4 = $faker->realText(10);
$item->tax_name1 = '';
$item->tax_rate1 = 0;
$item->type_id = "1";

View File

@ -214,7 +214,7 @@ class PaymentController extends Controller
$payment_method_id = $request->input('payment_method_id');
$invoice_totals = $payable_invoices->sum('amount');
$first_invoice = $invoices->first();
$credit_totals = $first_invoice->client->getSetting('use_credits_payment') == 'off' ? 0 : $first_invoice->client->service()->getCreditBalance();
$credit_totals = $first_invoice->client->getSetting('use_credits_payment') == 'always' ? $first_invoice->client->service()->getCreditBalance() : 0;
$starting_invoice_amount = $first_invoice->amount;
if ($gateway) {

View File

@ -128,7 +128,11 @@ class EmailController extends BaseController
'body' => $body
];
EmailEntity::dispatchNow($invitation, $invitation->company, $template, $data);
$entity_obj->service()->markSent()->save();
//@TODO why is this dispatchNow instead of just dispatch?
//update - changing to dispatch and see if something breaks.
EmailEntity::dispatch($invitation, $invitation->company, $template, $data)->delay(now()->addSeconds(5));
}
});

View File

@ -38,12 +38,9 @@ class StoreExpenseRequest extends Request
if (isset($this->number)) {
$rules['number'] = Rule::unique('expenses')->where('company_id', auth()->user()->company()->id);
}
// $rules['number'] = 'unique:expenses,number,'.$this->id.',id,company_id,'.auth()->user()->company()->id;
// $rules['contacts.*.email'] = 'nullable|distinct';
//$rules['number'] = new UniqueExpenseNumberRule($this->all());
$rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.auth()->user()->company()->id;
if(!empty($this->client_id))
$rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.auth()->user()->company()->id;
return $this->globalRules($rules);
}

View File

@ -36,7 +36,7 @@ class UpdateExpenseRequest extends Request
/* Ensure we have a client name, and that all emails are unique*/
$rules['country_id'] = 'integer|nullable';
//$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id;
$rules['contacts.*.email'] = 'nullable|distinct';
if (isset($this->number)) {

View File

@ -108,7 +108,6 @@ class CreateEntityPdf implements ShouldQueue
$entity_design_id = 'credit_design_id';
}
$file_path = $path.$this->entity->number.'.pdf';
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
@ -145,10 +144,6 @@ class CreateEntityPdf implements ShouldQueue
->design($template)
->build();
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
//nlog("make dir => {$path}");
//Storage::makeDirectory($path, 0775);
$pdf = null;
try {

View File

@ -110,15 +110,11 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
)
);
} catch (\Exception $e) {
// $this->failed($e);
$this->entityEmailFailed($e->getMessage());
$this->logMailError($e->getMessage(), $this->entity->client);
}
// if (count(Mail::failures()) == 0) {
// $this->entityEmailSucceeded();
// }
/* Mark entity sent */
$this->entity->service()->markSent()->save();
}

View File

@ -83,7 +83,6 @@ class Company extends BaseModel
'default_task_is_date_based',
'enable_product_discount',
'expense_inclusive_taxes',
'expense_amount_is_pretax',
];
protected $hidden = [

View File

@ -55,7 +55,7 @@ class Expense extends BaseModel
'tax_amount2',
'tax_amount3',
'uses_inclusive_taxes',
'amount_is_pretax',
'calculate_tax_by_amount',
];
protected $casts = [

View File

@ -91,6 +91,7 @@ class RecurringInvoice extends BaseModel
'remaining_cycles',
'auto_bill',
'auto_bill_enabled',
'design_id',
];
protected $casts = [

View File

@ -140,11 +140,6 @@ class AuthorizeCreditCard
}
private function handleResponse($data, $request)
{
$response = $data['response'];
@ -205,7 +200,12 @@ class AuthorizeCreditCard
'data' => $this->formatGatewayResponse($data, $vars),
];
SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_AUTHORIZE, $this->authorize->client);
SystemLogger::dispatch(
$logger_message,
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_SUCCESS,
SystemLog::TYPE_AUTHORIZE,
$this->authorize->client);
return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]);
}

View File

@ -468,4 +468,16 @@ class BaseDriver extends AbstractPaymentDriver
{
return $this->company_gateway->id;
}
public function logSuccessfulGatewayResponse($response, $gateway_const)
{
SystemLogger::dispatch(
$response,
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_SUCCESS,
$gateway_const,
$this->client,
);
}
}

View File

@ -103,6 +103,8 @@ class CreditCard
if ($server_response->status == 'succeeded') {
$this->stripe->confirmGatewayFee($request);
$this->stripe->logSuccessfulGatewayResponse(['response' => json_decode($request->gateway_response), 'data' => $this->stripe->payment_hash], SystemLog::TYPE_STRIPE);
return $this->processSuccessfulPayment();
}

View File

@ -15,6 +15,7 @@ use App\Jobs\Entity\CreateEntityPdf;
use App\Models\ClientContact;
use App\Models\Invoice;
use App\Services\AbstractService;
use App\Utils\TempFile;
use Illuminate\Support\Facades\Storage;
class GetInvoicePdf extends AbstractService
@ -46,6 +47,12 @@ class GetInvoicePdf extends AbstractService
$file_path = CreateEntityPdf::dispatchNow($invitation);
}
/* Copy from remote disk to local when using cloud file storage. */
if(config('filesystems.default') == 's3')
return TempFile::path(Storage::disk($disk)->url($file_path));
// return Storage::disk($disk)->url($file_path);
return Storage::disk($disk)->path($file_path);
}
}

View File

@ -131,7 +131,7 @@ class CompanyTransformer extends EntityTransformer
'archived_at' => (int) $company->deleted_at,
'created_at' =>(int) $company->created_at,
'slack_webhook_url' => (string) $company->slack_webhook_url,
'google_analytics_url' => (string) $company->google_analytics_key, //@deprecate
'google_analytics_url' => (string) $company->google_analytics_key, //@deprecate 1-2-2021
'google_analytics_key' => (string) $company->google_analytics_key,
'enabled_item_tax_rates' => (int) $company->enabled_item_tax_rates,
'client_can_register' => (bool) $company->client_can_register,
@ -145,13 +145,13 @@ class CompanyTransformer extends EntityTransformer
'auto_start_tasks' => (bool) $company->auto_start_tasks,
'invoice_task_documents' => (bool) $company->invoice_task_documents,
'show_tasks_table' => (bool) $company->show_tasks_table,
'use_credits_payment' => 'always', //todo remove
'use_credits_payment' => 'always', // @deprecate 1-2-2021
'default_task_is_date_based' => (bool)$company->default_task_is_date_based,
'enable_product_discount' => (bool)$company->enable_product_discount,
'calculate_expense_tax_by_amount' =>(bool)$company->calculate_expense_tax_by_amount,
'hide_empty_columns_on_pdf' => false, //@deprecate
'hide_empty_columns_on_pdf' => false, // @deprecate 1-2-2021
'expense_inclusive_taxes' => (bool)$company->expense_inclusive_taxes,
'expense_amount_is_pretax' =>( bool)$company->expense_amount_is_pretax,
'expense_amount_is_pretax' =>(bool)true, //@deprecate 1-2-2021
];
}

View File

@ -95,7 +95,7 @@ class ExpenseTransformer extends EntityTransformer
'tax_amount2' => (float) $expense->tax_amount2,
'tax_amount3' => (float) $expense->tax_amount3,
'uses_inclusive_taxes' => (bool) $expense->uses_inclusive_taxes,
'amount_is_pretax' => (bool) $expense->amount_is_pretax,
'calculate_tax_by_amount' => (bool) $expense->calculate_tax_by_amount,
];
}
}

View File

@ -15,7 +15,7 @@ class TempFile
{
public static function path($url) :string
{
$temp_path = tempnam(sys_get_temp_dir(), basename($url));
$temp_path = @tempnam(sys_get_temp_dir() . '/' . sha1(time()), basename($url));
copy($url, $temp_path);
return $temp_path;

View File

@ -95,6 +95,8 @@ trait MakesDates
private function convertToDateObject($date)
{
return new DateTime($date);
$dt = new DateTime($date);
$dt->setTimezone(new DateTimeZone('UTC'));
return $dt;
}
}

View File

@ -31,11 +31,17 @@ class FixCompanySettingsUrl extends Migration
Schema::table('companies', function (Blueprint $table) {
$table->dropColumn('logo');
$table->dropColumn('expense_amount_is_pretax');
});
Schema::table('tasks', function (Blueprint $table) {
$table->dropColumn('start_time');
});
Schema::table('expenses', function (Blueprint $table) {
$table->dropColumn('amount_is_pretax');
$table->boolean('calculate_tax_by_amount')->default(false);
});
}
/**