1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Fixes for tests (#3184)

* fix typo

* php-cs traits

* CS fixer pass

* Password protect User routes

* Implement checks to prevent editing a deleted record

* Clean up payment flows

* Fixes for tests
This commit is contained in:
David Bomba 2019-12-31 08:59:12 +11:00 committed by GitHub
parent 167b503fa1
commit f712b789ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
470 changed files with 5777 additions and 7249 deletions

View File

@ -51,8 +51,6 @@ class CreateTestData extends Command
parent::__construct();
$this->invoice_repo = $invoice_repo;
}
/**
@ -72,13 +70,11 @@ class CreateTestData extends Command
$this->createSmallAccount();
$this->createMediumAccount();
$this->createLargeAccount();
}
private function createSmallAccount()
{
$this->info('Creating Small Account and Company');
$account = factory(\App\Models\Account::class)->create();
@ -91,8 +87,7 @@ class CreateTestData extends Command
$user = User::whereEmail('small@example.com')->first();
if(!$user)
{
if (!$user) {
$user = factory(\App\Models\User::class)->create([
// 'account_id' => $account->id,
'email' => 'small@example.com',
@ -123,13 +118,12 @@ class CreateTestData extends Command
$this->info('Creating '.$this->count. ' clients');
for($x=0; $x<$this->count; $x++) {
for ($x=0; $x<$this->count; $x++) {
$z = $x+1;
$this->info("Creating client # ".$z);
$this->createClient($company, $user);
$this->createClient($company, $user);
}
}
private function createMediumAccount()
@ -146,8 +140,7 @@ class CreateTestData extends Command
$user = User::whereEmail('medium@example.com')->first();
if(!$user)
{
if (!$user) {
$user = factory(\App\Models\User::class)->create([
// 'account_id' => $account->id,
'email' => 'medium@example.com',
@ -179,18 +172,17 @@ class CreateTestData extends Command
$this->info('Creating '.$this->count. ' clients');
for($x=0; $x<$this->count; $x++) {
for ($x=0; $x<$this->count; $x++) {
$z = $x+1;
$this->info("Creating client # ".$z);
$this->createClient($company, $user);
$this->createClient($company, $user);
}
}
private function createLargeAccount()
{
$this->info('Creating Large Account and Company');
$this->info('Creating Large Account and Company');
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
@ -202,8 +194,7 @@ class CreateTestData extends Command
$user = User::whereEmail('large@example.com')->first();
if(!$user)
{
if (!$user) {
$user = factory(\App\Models\User::class)->create([
// 'account_id' => $account->id,
'email' => 'large@example.com',
@ -235,13 +226,12 @@ class CreateTestData extends Command
$this->info('Creating '.$this->count. ' clients');
for($x=0; $x<$this->count; $x++) {
for ($x=0; $x<$this->count; $x++) {
$z = $x+1;
$this->info("Creating client # ".$z);
$this->createClient($company, $user);
$this->createClient($company, $user);
}
}
private function createClient($company, $user)
@ -252,25 +242,24 @@ class CreateTestData extends Command
]);
factory(\App\Models\ClientContact::class,1)->create([
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1
]);
factory(\App\Models\ClientContact::class,rand(1,5))->create([
factory(\App\Models\ClientContact::class, rand(1, 5))->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id
]);
$y = $this->count * rand(1,5);
$y = $this->count * rand(1, 5);
$this->info("Creating {$y} invoices & quotes");
for($x=0; $x<$y; $x++){
for ($x=0; $x<$y; $x++) {
$this->createInvoice($client);
$this->createQuote($client);
}
@ -280,27 +269,24 @@ class CreateTestData extends Command
{
$faker = \Faker\Factory::create();
$invoice = InvoiceFactory::create($client->company->id,$client->user->id);//stub the company and user_id
$invoice = InvoiceFactory::create($client->company->id, $client->user->id);//stub the company and user_id
$invoice->client_id = $client->id;
$invoice->date = $faker->date();
$invoice->line_items = $this->buildLineItems();
$invoice->uses_inclusive_taxes = false;
if(rand(0,1))
{
if (rand(0, 1)) {
$invoice->tax_name1 = 'GST';
$invoice->tax_rate1 = 10.00;
}
if(rand(0,1))
{
if (rand(0, 1)) {
$invoice->tax_name2 = 'VAT';
$invoice->tax_rate2 = 17.50;
}
if(rand(0,1))
{
if (rand(0, 1)) {
$invoice->tax_name3 = 'CA Sales Tax';
$invoice->tax_rate3 = 5;
}
@ -314,31 +300,30 @@ class CreateTestData extends Command
$invoice->save();
event(new CreateInvoiceInvitation($invoice));
event(new CreateInvoiceInvitation($invoice));
UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance, $invoice->company);
UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance, $invoice->company);
$this->invoice_repo->markSent($invoice);
$this->invoice_repo->markSent($invoice);
CreateInvoiceInvitations::dispatch($invoice, $invoice->company);
CreateInvoiceInvitations::dispatch($invoice, $invoice->company);
if(rand(0, 1)) {
if (rand(0, 1)) {
$payment = PaymentFactory::create($client->company->id, $client->user->id);
$payment->date = now();
$payment->client_id = $client->id;
$payment->amount = $invoice->balance;
$payment->transaction_reference = rand(0, 500);
$payment->type_id = PaymentType::CREDIT_CARD_OTHER;
$payment->status_id = Payment::STATUS_COMPLETED;
$payment->save();
$payment = PaymentFactory::create($client->company->id, $client->user->id);
$payment->date = now();
$payment->client_id = $client->id;
$payment->amount = $invoice->balance;
$payment->transaction_reference = rand(0,500);
$payment->type_id = PaymentType::CREDIT_CARD_OTHER;
$payment->status_id = Payment::STATUS_COMPLETED;
$payment->save();
$payment->invoices()->save($invoice);
$payment->invoices()->save($invoice);
event(new PaymentWasCreated($payment, $payment->company));
event(new PaymentWasCreated($payment, $payment->company));
UpdateInvoicePayment::dispatchNow($payment, $payment->company);
}
UpdateInvoicePayment::dispatchNow($payment, $payment->company);
}
}
@ -346,27 +331,24 @@ class CreateTestData extends Command
{
$faker = \Faker\Factory::create();
$quote = QuoteFactory::create($client->company->id,$client->user->id);//stub the company and user_id
$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id
$quote->client_id = $client->id;
$quote->date = $faker->date();
$quote->line_items = $this->buildLineItems();
$quote->uses_inclusive_taxes = false;
if(rand(0,1))
{
if (rand(0, 1)) {
$quote->tax_name1 = 'GST';
$quote->tax_rate1 = 10.00;
}
if(rand(0,1))
{
if (rand(0, 1)) {
$quote->tax_name2 = 'VAT';
$quote->tax_rate2 = 17.50;
}
if(rand(0,1))
{
if (rand(0, 1)) {
$quote->tax_name3 = 'CA Sales Tax';
$quote->tax_rate3 = 5;
}
@ -380,9 +362,7 @@ class CreateTestData extends Command
$quote->save();
CreateQuoteInvitations::dispatch($quote, $quote->company);
CreateQuoteInvitations::dispatch($quote, $quote->company);
}
private function buildLineItems()
@ -393,20 +373,17 @@ class CreateTestData extends Command
$item->quantity = 1;
$item->cost =10;
if(rand(0, 1))
{
if (rand(0, 1)) {
$item->tax_name1 = 'GST';
$item->tax_rate1 = 10.00;
}
if(rand(0, 1))
{
if (rand(0, 1)) {
$item->tax_name1 = 'VAT';
$item->tax_rate1 = 17.50;
}
if(rand(0, 1))
{
if (rand(0, 1)) {
$item->tax_name1 = 'Sales Tax';
$item->tax_rate1 = 5;
}
@ -414,12 +391,11 @@ class CreateTestData extends Command
$line_items[] = $item;
return $line_items;
}
private function warmCache()
{
/* Warm up the cache !*/
/* Warm up the cache !*/
$cached_tables = config('ninja.cached_tables');
foreach ($cached_tables as $name => $class) {

View File

@ -64,7 +64,7 @@ class SendTestEmails extends Command
$user = User::whereEmail('user@example.com')->first();
$client = Client::all()->first();
if(!$user){
if (!$user) {
$user = factory(\App\Models\User::class)->create([
'confirmation_code' => '123',
'email' => 'admin@business.com',
@ -73,12 +73,11 @@ class SendTestEmails extends Command
]);
}
if(!$client) {
$client = ClientFactory::create($user->company()->id, $user->id);
$client->save();
if (!$client) {
$client = ClientFactory::create($user->company()->id, $user->id);
$client->save();
factory(\App\Models\ClientContact::class,1)->create([
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
@ -87,7 +86,7 @@ class SendTestEmails extends Command
'email' => 'exy@example.com',
]);
factory(\App\Models\ClientContact::class,1)->create([
factory(\App\Models\ClientContact::class, 1)->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
@ -96,14 +95,13 @@ class SendTestEmails extends Command
]);
}
$cc_emails = [config('ninja.testvars.test_email')];
$bcc_emails = [config('ninja.testvars.test_email')];
$cc_emails = [config('ninja.testvars.test_email')];
$bcc_emails = [config('ninja.testvars.test_email')];
Mail::to(config('ninja.testvars.test_email'),'Mr Test')
Mail::to(config('ninja.testvars.test_email'), 'Mr Test')
->cc($cc_emails)
->bcc($bcc_emails)
//->replyTo(also_available_if_needed)
->send(new TemplateEmail($message, $template, $user, $client));
}
}

View File

@ -38,8 +38,6 @@ class Kernel extends ConsoleKernel
// ->hourly();
$schedule->job(new RecurringInvoicesCron)->hourly();
}
/**

View File

@ -16,50 +16,48 @@ namespace App\DataMapper;
*/
class BaseSettings
{
public function __construct($obj)
{
foreach ($obj as $key => $value) {
$obj->{$key} = $value;
}
}
public static function setCasts($obj, $casts)
{
foreach ($casts as $key => $value) {
$obj->{$key} = self::castAttribute($key, $obj->{$key});
}
public function __construct($obj)
{
foreach($obj as $key => $value)
$obj->{$key} = $value;
}
public static function setCasts($obj, $casts)
{
foreach ($casts as $key => $value)
$obj->{$key} = self::castAttribute($key, $obj->{$key});
return $obj;
}
return $obj;
}
public static function castAttribute($key, $value)
{
switch ($key) {
case 'int':
case 'integer':
return (int) $value;
case 'real':
case 'float':
case 'double':
return (float) $value;
case 'string':
return is_null($value) ? '' : (string) $value;
case 'bool':
case 'boolean':
return (bool)($value);
case 'object':
return json_decode($value);
case 'array':
case 'json':
return json_decode($value, true);
default:
return $value;
}
}
public static function castAttribute($key, $value)
{
switch ($key)
{
case 'int':
case 'integer':
return (int) $value;
case 'real':
case 'float':
case 'double':
return (float) $value;
case 'string':
return is_null($value) ? '' : (string) $value;
case 'bool':
case 'boolean':
return (bool)($value);
case 'object':
return json_decode($value);
case 'array':
case 'json':
return json_decode($value, true);
default:
return $value;
}
}
public static function castSingleAttribute($key, $data)
{
}
}
public static function castSingleAttribute($key, $data)
{
}
}

View File

@ -20,88 +20,82 @@ use App\Utils\TranslationHelper;
* ClientSettings
*
* Client settings are built as a superset of Company Settings
*
*
* If no client settings is specified, the default company setting is used.
*
*
* Client settings are passed down to the entity level where they can be further customized and then saved
* into the settings column of the entity, so there is no need to create additional entity level settings handlers.
*
*
*/
class ClientSettings extends BaseSettings
{
/**
* Settings which which are unique to client settings
*/
public $industry_id;
public $size_id;
public static $casts = [
'industry_id' => 'string',
'size_id' => 'string',
];
/**
* Cast object values and return entire class
* prevents missing properties from not being returned
* and always ensure an up to date class is returned
*
* @return \stdClass
/**
* Settings which which are unique to client settings
*/
public function __construct($obj)
{
parent::__construct($obj);
}
public $industry_id;
public $size_id;
/**
*
* Default Client Settings scaffold
*
* @return \stdClass
*
public static $casts = [
'industry_id' => 'string',
'size_id' => 'string',
];
/**
* Cast object values and return entire class
* prevents missing properties from not being returned
* and always ensure an up to date class is returned
*
* @return \stdClass
*/
public static function defaults() : \stdClass
{
public function __construct($obj)
{
parent::__construct($obj);
}
$data = (object)[
'entity' => (string)Client::class,
'industry_id' => '',
'size_id' => '',
];
/**
*
* Default Client Settings scaffold
*
* @return \stdClass
*
*/
public static function defaults() : \stdClass
{
$data = (object)[
'entity' => (string)Client::class,
'industry_id' => '',
'size_id' => '',
];
return self::setCasts($data, self::$casts);
}
return self::setCasts($data, self::$casts);
}
/**
* Merges settings from Company to Client
*
* @param \stdClass $company_settings
* @param \stdClass $client_settings
* @return \stdClass of merged settings
*/
public static function buildClientSettings($company_settings, $client_settings)
{
if(!$client_settings)
return $company_settings;
foreach($company_settings as $key => $value)
{
/* pseudo code
if the property exists and is a string BUT has no length, treat it as TRUE
*/
if( ( (property_exists($client_settings, $key) && is_string($client_settings->{$key}) && (iconv_strlen($client_settings->{$key}) <1)))
|| !isset($client_settings->{$key})
&& property_exists($company_settings, $key)) {
$client_settings->{$key} = $company_settings->{$key};
}
}
return $client_settings;
}
/**
* Merges settings from Company to Client
*
* @param \stdClass $company_settings
* @param \stdClass $client_settings
* @return \stdClass of merged settings
*/
public static function buildClientSettings($company_settings, $client_settings)
{
if (!$client_settings) {
return $company_settings;
}
foreach ($company_settings as $key => $value) {
/* pseudo code
if the property exists and is a string BUT has no length, treat it as TRUE
*/
if (((property_exists($client_settings, $key) && is_string($client_settings->{$key}) && (iconv_strlen($client_settings->{$key}) <1)))
|| !isset($client_settings->{$key})
&& property_exists($company_settings, $key)) {
$client_settings->{$key} = $company_settings->{$key};
}
}
return $client_settings;
}
}

View File

@ -21,442 +21,435 @@ use App\Models\Company;
class CompanySettings extends BaseSettings
{
/*Group settings based on functionality*/
/*Group settings based on functionality*/
/*Invoice*/
public $auto_archive_invoice = false;
public $lock_sent_invoices = false;
/*Invoice*/
public $auto_archive_invoice = false;
public $lock_sent_invoices = false;
public $enable_client_portal_tasks = false;
public $enable_client_portal_password = false;
public $enable_client_portal = true; //implemented
public $enable_client_portal_dashboard = true; //implemented
public $signature_on_pdf = false;
public $document_email_attachment = false;
public $send_portal_password = false;
public $enable_client_portal_tasks = false;
public $enable_client_portal_password = false;
public $enable_client_portal = true; //implemented
public $enable_client_portal_dashboard = true; //implemented
public $signature_on_pdf = false;
public $document_email_attachment = false;
public $send_portal_password = false;
public $timezone_id = '';
public $date_format_id = '';
public $military_time = false;
public $timezone_id = '';
public $date_format_id = '';
public $military_time = false;
public $language_id = '';
public $show_currency_code = false;
public $language_id = '';
public $show_currency_code = false;
public $company_gateway_ids = '';
public $company_gateway_ids = '';
public $currency_id = '1';
public $currency_id = '1';
public $custom_value1 = '';
public $custom_value2 = '';
public $custom_value3 = '';
public $custom_value4 = '';
public $custom_value1 = '';
public $custom_value2 = '';
public $custom_value3 = '';
public $custom_value4 = '';
public $default_task_rate = 0;
public $default_task_rate = 0;
public $payment_terms = 1;
public $send_reminders = false;
public $payment_terms = 1;
public $send_reminders = false;
public $custom_message_dashboard = '';
public $custom_message_unpaid_invoice = '';
public $custom_message_paid_invoice = '';
public $custom_message_unapproved_quote = '';
public $auto_archive_quote = false;
public $auto_convert_quote = true;
public $auto_email_invoice = true;
public $custom_message_dashboard = '';
public $custom_message_unpaid_invoice = '';
public $custom_message_paid_invoice = '';
public $custom_message_unapproved_quote = '';
public $auto_archive_quote = false;
public $auto_convert_quote = true;
public $auto_email_invoice = true;
public $inclusive_taxes = false;
public $quote_footer = '';
public $inclusive_taxes = false;
public $quote_footer = '';
public $translations;
public $translations;
public $counter_number_applied = 'when_saved'; // when_saved , when_sent , when_paid
public $quote_number_applied = 'when_saved'; // when_saved , when_sent
/* Counters */
public $invoice_number_pattern = '';
public $invoice_number_counter = 1;
public $counter_number_applied = 'when_saved'; // when_saved , when_sent , when_paid
public $quote_number_applied = 'when_saved'; // when_saved , when_sent
/* Counters */
public $invoice_number_pattern = '';
public $invoice_number_counter = 1;
public $quote_number_pattern = '';
public $quote_number_counter = 1;
public $quote_number_pattern = '';
public $quote_number_counter = 1;
public $client_number_pattern = '';
public $client_number_counter = 1;
public $client_number_pattern = '';
public $client_number_counter = 1;
public $credit_number_pattern = '';
public $credit_number_counter = 1;
public $credit_number_pattern = '';
public $credit_number_counter = 1;
public $task_number_pattern = '';
public $task_number_counter = 1;
public $task_number_pattern = '';
public $task_number_counter = 1;
public $expense_number_pattern = '';
public $expense_number_counter = 1;
public $expense_number_pattern = '';
public $expense_number_counter = 1;
public $vendor_number_pattern = '';
public $vendor_number_counter = 1;
public $vendor_number_pattern = '';
public $vendor_number_counter = 1;
public $ticket_number_pattern = '';
public $ticket_number_counter = 1;
public $ticket_number_pattern = '';
public $ticket_number_counter = 1;
public $payment_number_pattern = '';
public $payment_number_counter = 1;
public $payment_number_pattern = '';
public $payment_number_counter = 1;
public $shared_invoice_quote_counter = false;
public $recurring_number_prefix = 'R';
public $reset_counter_frequency_id = '0';
public $reset_counter_date = '';
public $counter_padding = 4;
public $shared_invoice_quote_counter = false;
public $recurring_number_prefix = 'R';
public $reset_counter_frequency_id = '0';
public $reset_counter_date = '';
public $counter_padding = 4;
public $design = 'views/pdf/design1.blade.php';
public $design = 'views/pdf/design1.blade.php';
public $invoice_terms = '';
public $quote_terms = '';
public $invoice_taxes = 0;
public $enabled_item_tax_rates = 0;
public $invoice_design_id = '1';
public $quote_design_id = '1';
public $invoice_footer = '';
public $invoice_labels = '';
public $tax_name1 = '';
public $tax_rate1 = 0;
public $tax_name2 = '';
public $tax_rate2 = 0;
public $tax_name3 = '';
public $tax_rate3 = 0;
public $payment_type_id = '1';
public $invoice_fields = '';
public $invoice_terms = '';
public $quote_terms = '';
public $invoice_taxes = 0;
public $enabled_item_tax_rates = 0;
public $invoice_design_id = '1';
public $quote_design_id = '1';
public $invoice_footer = '';
public $invoice_labels = '';
public $tax_name1 = '';
public $tax_rate1 = 0;
public $tax_name2 = '';
public $tax_rate2 = 0;
public $tax_name3 = '';
public $tax_rate3 = 0;
public $payment_type_id = '1';
public $invoice_fields = '';
public $show_accept_invoice_terms = false;
public $show_accept_quote_terms = false;
public $require_invoice_signature = false;
public $require_quote_signature = false;
public $show_accept_invoice_terms = false;
public $show_accept_quote_terms = false;
public $require_invoice_signature = false;
public $require_quote_signature = false;
//email settings
public $email_sending_method = 'default'; //enum 'default','gmail'
public $gmail_sending_user_id = '0';
public $reply_to_email = '';
public $bcc_email = '';
public $pdf_email_attachment = false;
public $ubl_email_attachment = false;
//email settings
public $email_sending_method = 'default'; //enum 'default','gmail'
public $gmail_sending_user_id = '0';
public $reply_to_email = '';
public $bcc_email = '';
public $pdf_email_attachment = false;
public $ubl_email_attachment = false;
public $email_style = 'plain'; //plain, light, dark, custom
public $email_style_custom = ''; //the template itself
public $email_subject_invoice = '';
public $email_subject_quote = '';
public $email_subject_payment = '';
public $email_subject_statement = '';
public $email_template_invoice = '';
public $email_template_quote = '';
public $email_template_payment = '';
public $email_template_statement = '';
public $email_subject_reminder1 = '';
public $email_subject_reminder2 = '';
public $email_subject_reminder3 = '';
public $email_subject_reminder_endless = '';
public $email_template_reminder1 = '';
public $email_template_reminder2 = '';
public $email_template_reminder3 = '';
public $email_template_reminder_endless = '';
public $email_signature = '';
public $enable_email_markup = true;
public $email_style = 'plain'; //plain, light, dark, custom
public $email_style_custom = ''; //the template itself
public $email_subject_invoice = '';
public $email_subject_quote = '';
public $email_subject_payment = '';
public $email_subject_statement = '';
public $email_template_invoice = '';
public $email_template_quote = '';
public $email_template_payment = '';
public $email_template_statement = '';
public $email_subject_reminder1 = '';
public $email_subject_reminder2 = '';
public $email_subject_reminder3 = '';
public $email_subject_reminder_endless = '';
public $email_template_reminder1 = '';
public $email_template_reminder2 = '';
public $email_template_reminder3 = '';
public $email_template_reminder_endless = '';
public $email_signature = '';
public $enable_email_markup = true;
public $email_subject_custom1 = '';
public $email_subject_custom2 = '';
public $email_subject_custom3 = '';
public $email_subject_custom1 = '';
public $email_subject_custom2 = '';
public $email_subject_custom3 = '';
public $email_template_custom1 = '';
public $email_template_custom2 = '';
public $email_template_custom3 = '';
public $email_template_custom1 = '';
public $email_template_custom2 = '';
public $email_template_custom3 = '';
public $enable_reminder1 = false;
public $enable_reminder2 = false;
public $enable_reminder3 = false;
public $enable_reminder1 = false;
public $enable_reminder2 = false;
public $enable_reminder3 = false;
public $num_days_reminder1 = 0;
public $num_days_reminder2 = 0;
public $num_days_reminder3 = 0;
public $num_days_reminder1 = 0;
public $num_days_reminder2 = 0;
public $num_days_reminder3 = 0;
public $schedule_reminder1 = ''; // (enum: after_invoice_date, before_due_date, after_due_date)
public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date)
public $schedule_reminder3 = ''; // (enum: after_invoice_date, before_due_date, after_due_date)
public $schedule_reminder1 = ''; // (enum: after_invoice_date, before_due_date, after_due_date)
public $schedule_reminder2 = ''; // (enum: after_invoice_date, before_due_date, after_due_date)
public $schedule_reminder3 = ''; // (enum: after_invoice_date, before_due_date, after_due_date)
public $reminder_send_time = 32400; //number of seconds from UTC +0 to send reminders
public $reminder_send_time = 32400; //number of seconds from UTC +0 to send reminders
public $late_fee_amount1 = 0;
public $late_fee_amount2 = 0;
public $late_fee_amount3 = 0;
public $late_fee_amount1 = 0;
public $late_fee_amount2 = 0;
public $late_fee_amount3 = 0;
public $endless_reminder_frequency_id = '0';
public $endless_reminder_frequency_id = '0';
public $client_online_payment_notification = true;
public $client_manual_payment_notification = true;
public $client_online_payment_notification = true;
public $client_manual_payment_notification = true;
/* Company Meta data that we can use to build sub companies*/
/* Company Meta data that we can use to build sub companies*/
public $name = '';
public $company_logo = '';
public $website = '';
public $address1 = '';
public $address2 = '';
public $city = '';
public $state = '';
public $postal_code = '';
public $phone = '';
public $email = '';
public $country_id;
public $vat_number = '';
public $id_number = '';
public $name = '';
public $company_logo = '';
public $website = '';
public $address1 = '';
public $address2 = '';
public $city = '';
public $state = '';
public $postal_code = '';
public $phone = '';
public $email = '';
public $country_id;
public $vat_number = '';
public $id_number = '';
public $page_size = 'A4';
public $font_size = 9;
public $page_size = 'A4';
public $font_size = 9;
public $primary_font = 'Roboto';
public $secondary_font = 'Roboto';
public $hide_paid_to_date = false;
public $embed_documents = false;
public $embed_documents = false;
public $all_pages_header = true;
public $all_pages_footer = true;
public static $casts = [
'auto_email_invoice' => 'bool',
'reminder_send_time' => 'int',
'email_sending_method' => 'string',
'gmail_sending_user_id' => 'string',
'currency_id' => 'string',
'counter_number_applied' => 'string',
'quote_number_applied' => 'string',
'email_subject_custom1' => 'string',
'email_subject_custom2' => 'string',
'email_subject_custom3' => 'string',
'email_template_custom1' => 'string',
'email_template_custom2' => 'string',
'email_template_custom3' => 'string',
'enable_reminder1' => 'bool',
'enable_reminder2' => 'bool',
'enable_reminder3' => 'bool',
'num_days_reminder1' => 'int',
'num_days_reminder2' => 'int',
'num_days_reminder3' => 'int',
'schedule_reminder1' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'schedule_reminder2' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'schedule_reminder3' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'late_fee_amount1' => 'float',
'late_fee_amount2' => 'float',
'late_fee_amount3' => 'float',
'endless_reminder_frequency_id' => 'integer',
'client_online_payment_notification' => 'bool',
'client_manual_payment_notification' => 'bool',
'document_email_attachment' => 'bool',
'enable_client_portal_password' => 'bool',
'enable_email_markup' => 'bool',
'enable_client_portal_dashboard' => 'bool',
'enable_client_portal' => 'bool',
'email_template_statement' => 'string',
'email_subject_statement' => 'string',
'signature_on_pdf' => 'bool',
'send_portal_password' => 'bool',
'quote_footer' => 'string',
'page_size' => 'string',
'font_size' => 'int',
'primary_font' => 'string',
'secondary_font' => 'string',
'hide_paid_to_date' => 'bool',
'embed_documents' => 'bool',
'all_pages_header' => 'bool',
'all_pages_footer' => 'bool',
'task_number_pattern' => 'string',
'task_number_counter' => 'int',
'expense_number_pattern' => 'string',
'expense_number_counter' => 'int',
'vendor_number_pattern' => 'string',
'vendor_number_counter' => 'int',
'ticket_number_pattern' => 'string',
'ticket_number_counter' => 'int',
'payment_number_pattern' => 'string',
'payment_number_counter' => 'int',
'reply_to_email' => 'string',
'bcc_email' => 'string',
'pdf_email_attachment' => 'bool',
'ubl_email_attachment' => 'bool',
'email_style' => 'string',
'email_style_custom' => 'string',
'company_gateway_ids' => 'string',
'address1' => 'string',
'address2' => 'string',
'city' => 'string',
'company_logo' => 'string',
'country_id' => 'string',
'client_number_pattern' => 'string',
'client_number_counter' => 'integer',
'credit_number_pattern' => 'string',
'credit_number_counter' => 'integer',
'currency_id' => 'string',
'custom_value1' => 'string',
'custom_value2' => 'string',
'custom_value3' => 'string',
'custom_value4' => 'string',
'custom_message_dashboard' => 'string',
'custom_message_unpaid_invoice' => 'string',
'custom_message_paid_invoice' => 'string',
'custom_message_unapproved_quote' => 'string',
'default_task_rate' => 'float',
'email_signature' => 'string',
'email_subject_invoice' => 'string',
'email_subject_quote' => 'string',
'email_subject_payment' => 'string',
'email_template_invoice' => 'string',
'email_template_quote' => 'string',
'email_template_payment' => 'string',
'email_subject_reminder1' => 'string',
'email_subject_reminder2' => 'string',
'email_subject_reminder3' => 'string',
'email_subject_reminder_endless' => 'string',
'email_template_reminder1' => 'string',
'email_template_reminder2' => 'string',
'email_template_reminder3' => 'string',
'email_template_reminder_endless' => 'string',
'enable_client_portal_password' => 'bool',
'inclusive_taxes' => 'bool',
'invoice_number_pattern' => 'string',
'invoice_number_counter' => 'integer',
'invoice_design_id' => 'string',
'invoice_fields' => 'string',
'invoice_taxes' => 'int',
'enabled_item_tax_rates' => 'int',
'invoice_footer' => 'string',
'invoice_labels' => 'string',
'invoice_terms' => 'string',
'name' => 'string',
'payment_terms' => 'integer',
'payment_type_id' => 'string',
'phone' => 'string',
'postal_code' => 'string',
'quote_design_id' => 'string',
'quote_number_pattern' => 'string',
'quote_number_counter' => 'integer',
'quote_terms' => 'string',
'recurring_number_prefix' => 'string',
'reset_counter_frequency_id' => 'integer',
'reset_counter_date' => 'string',
'require_invoice_signature' => 'bool',
'require_quote_signature' => 'bool',
'state' => 'string',
'email' => 'string',
'vat_number' => 'string',
'id_number' => 'string',
'tax_name1' => 'string',
'tax_name2' => 'string',
'tax_name3' => 'string',
'tax_rate1' => 'float',
'tax_rate2' => 'float',
'tax_rate3' => 'float',
'show_accept_quote_terms' => 'bool',
'show_accept_invoice_terms' => 'bool',
'timezone_id' => 'string',
'date_format_id' => 'string',
'military_time' => 'bool',
'language_id' => 'string',
'show_currency_code' => 'bool',
'send_reminders' => 'bool',
'enable_client_portal_tasks' => 'bool',
'lock_sent_invoices' => 'bool',
'auto_archive_invoice' => 'bool',
'auto_archive_quote' => 'bool',
'auto_convert_quote' => 'bool',
'shared_invoice_quote_counter' => 'bool',
'counter_padding' => 'integer',
'design' => 'string',
'website' => 'string',
];
public static $casts = [
'auto_email_invoice' => 'bool',
'reminder_send_time' => 'int',
'email_sending_method' => 'string',
'gmail_sending_user_id' => 'string',
'currency_id' => 'string',
'counter_number_applied' => 'string',
'quote_number_applied' => 'string',
'email_subject_custom1' => 'string',
'email_subject_custom2' => 'string',
'email_subject_custom3' => 'string',
'email_template_custom1' => 'string',
'email_template_custom2' => 'string',
'email_template_custom3' => 'string',
'enable_reminder1' => 'bool',
'enable_reminder2' => 'bool',
'enable_reminder3' => 'bool',
'num_days_reminder1' => 'int',
'num_days_reminder2' => 'int',
'num_days_reminder3' => 'int',
'schedule_reminder1' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'schedule_reminder2' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'schedule_reminder3' => 'string', // (enum: after_invoice_date, before_due_date, after_due_date)
'late_fee_amount1' => 'float',
'late_fee_amount2' => 'float',
'late_fee_amount3' => 'float',
'endless_reminder_frequency_id' => 'integer',
'client_online_payment_notification' => 'bool',
'client_manual_payment_notification' => 'bool',
'document_email_attachment' => 'bool',
'enable_client_portal_password' => 'bool',
'enable_email_markup' => 'bool',
'enable_client_portal_dashboard' => 'bool',
'enable_client_portal' => 'bool',
'email_template_statement' => 'string',
'email_subject_statement' => 'string',
'signature_on_pdf' => 'bool',
'send_portal_password' => 'bool',
'quote_footer' => 'string',
'page_size' => 'string',
'font_size' => 'int',
'primary_font' => 'string',
'secondary_font' => 'string',
'hide_paid_to_date' => 'bool',
'embed_documents' => 'bool',
'all_pages_header' => 'bool',
'all_pages_footer' => 'bool',
'task_number_pattern' => 'string',
'task_number_counter' => 'int',
'expense_number_pattern' => 'string',
'expense_number_counter' => 'int',
'vendor_number_pattern' => 'string',
'vendor_number_counter' => 'int',
'ticket_number_pattern' => 'string',
'ticket_number_counter' => 'int',
'payment_number_pattern' => 'string',
'payment_number_counter' => 'int',
'reply_to_email' => 'string',
'bcc_email' => 'string',
'pdf_email_attachment' => 'bool',
'ubl_email_attachment' => 'bool',
'email_style' => 'string',
'email_style_custom' => 'string',
'company_gateway_ids' => 'string',
'address1' => 'string',
'address2' => 'string',
'city' => 'string',
'company_logo' => 'string',
'country_id' => 'string',
'client_number_pattern' => 'string',
'client_number_counter' => 'integer',
'credit_number_pattern' => 'string',
'credit_number_counter' => 'integer',
'currency_id' => 'string',
'custom_value1' => 'string',
'custom_value2' => 'string',
'custom_value3' => 'string',
'custom_value4' => 'string',
'custom_message_dashboard' => 'string',
'custom_message_unpaid_invoice' => 'string',
'custom_message_paid_invoice' => 'string',
'custom_message_unapproved_quote' => 'string',
'default_task_rate' => 'float',
'email_signature' => 'string',
'email_subject_invoice' => 'string',
'email_subject_quote' => 'string',
'email_subject_payment' => 'string',
'email_template_invoice' => 'string',
'email_template_quote' => 'string',
'email_template_payment' => 'string',
'email_subject_reminder1' => 'string',
'email_subject_reminder2' => 'string',
'email_subject_reminder3' => 'string',
'email_subject_reminder_endless' => 'string',
'email_template_reminder1' => 'string',
'email_template_reminder2' => 'string',
'email_template_reminder3' => 'string',
'email_template_reminder_endless' => 'string',
'enable_client_portal_password' => 'bool',
'inclusive_taxes' => 'bool',
'invoice_number_pattern' => 'string',
'invoice_number_counter' => 'integer',
'invoice_design_id' => 'string',
'invoice_fields' => 'string',
'invoice_taxes' => 'int',
'enabled_item_tax_rates' => 'int',
'invoice_footer' => 'string',
'invoice_labels' => 'string',
'invoice_terms' => 'string',
'name' => 'string',
'payment_terms' => 'integer',
'payment_type_id' => 'string',
'phone' => 'string',
'postal_code' => 'string',
'quote_design_id' => 'string',
'quote_number_pattern' => 'string',
'quote_number_counter' => 'integer',
'quote_terms' => 'string',
'recurring_number_prefix' => 'string',
'reset_counter_frequency_id' => 'integer',
'reset_counter_date' => 'string',
'require_invoice_signature' => 'bool',
'require_quote_signature' => 'bool',
'state' => 'string',
'email' => 'string',
'vat_number' => 'string',
'id_number' => 'string',
'tax_name1' => 'string',
'tax_name2' => 'string',
'tax_name3' => 'string',
'tax_rate1' => 'float',
'tax_rate2' => 'float',
'tax_rate3' => 'float',
'show_accept_quote_terms' => 'bool',
'show_accept_invoice_terms' => 'bool',
'timezone_id' => 'string',
'date_format_id' => 'string',
'military_time' => 'bool',
'language_id' => 'string',
'show_currency_code' => 'bool',
'send_reminders' => 'bool',
'enable_client_portal_tasks' => 'bool',
'lock_sent_invoices' => 'bool',
'auto_archive_invoice' => 'bool',
'auto_archive_quote' => 'bool',
'auto_convert_quote' => 'bool',
'shared_invoice_quote_counter' => 'bool',
'counter_padding' => 'integer',
'design' => 'string',
'website' => 'string',
];
/**
* Array of variables which
* cannot be modified client side
*/
public static $protected_fields = [
// 'credit_number_counter',
// 'invoice_number_counter',
// 'quote_number_counter',
];
/**
* Cast object values and return entire class
* prevents missing properties from not being returned
* and always ensure an up to date class is returned
*
* @return \stdClass
/**
* Array of variables which
* cannot be modified client side
*/
public function __construct($obj)
{
// parent::__construct($obj);
}
public static $protected_fields = [
// 'credit_number_counter',
// 'invoice_number_counter',
// 'quote_number_counter',
];
/**
* Provides class defaults on init
* @return object
*/
public static function defaults() : \stdClass
{
$config = json_decode(config('ninja.settings'));
$data = (object)get_class_vars(CompanySettings::class);
unset($data->casts);
unset($data->protected_fields);
/**
* Cast object values and return entire class
* prevents missing properties from not being returned
* and always ensure an up to date class is returned
*
* @return \stdClass
*/
public function __construct($obj)
{
// parent::__construct($obj);
}
$data->timezone_id = (string)config('ninja.i18n.timezone_id');
$data->currency_id = (string)config('ninja.i18n.currency_id');
$data->language_id = (string)config('ninja.i18n.language_id');
$data->payment_terms = (int)config('ninja.i18n.payment_terms');
$data->military_time = (bool)config('ninja.i18n.military_time');
$data->date_format_id = (string)config('ninja.i18n.date_format_id');
$data->country_id = (string)config('ninja.i18n.country_id');
$data->translations = (object) [];
// $data->email_subject_invoice = EmailTemplateDefaults::emailInvoiceSubject();
// $data->email_template_invoice = EmailTemplateDefaults:: emailInvoiceTemplate();
// $data->email_subject_quote = EmailTemplateDefaults::emailQuoteSubject();
// $data->email_subject_payment = EmailTemplateDefaults::emailPaymentSubject();
// $data->email_subject_statement = EmailTemplateDefaults::emailStatementSubject();
// $data->email_template_quote = EmailTemplateDefaults::emailQuoteTemplate();
// $data->email_template_payment = EmailTemplateDefaults::emailPaymentTemplate();
// $data->email_template_statement = EmailTemplateDefaults::emailStatementTemplate();
// $data->email_subject_reminder1 = EmailTemplateDefaults::emailReminder1Subject();
// $data->email_subject_reminder2 = EmailTemplateDefaults::emailReminder2Subject();
// $data->email_subject_reminder3 = EmailTemplateDefaults::emailReminder3Subject();
// $data->email_subject_reminder_endless = EmailTemplateDefaults::emailReminderEndlessSubject();
// $data->email_template_reminder1 = EmailTemplateDefaults::emailReminder1Template();
// $data->email_template_reminder2 = EmailTemplateDefaults::emailReminder2Template();
// $data->email_template_reminder3 = EmailTemplateDefaults::emailReminder3Template();
// $data->email_template_reminder_endless = EmailTemplateDefaults::emailReminderEndlessTemplate();
return self::setCasts($data, self::$casts);
/**
* Provides class defaults on init
* @return object
*/
public static function defaults() : \stdClass
{
$config = json_decode(config('ninja.settings'));
$data = (object)get_class_vars(CompanySettings::class);
unset($data->casts);
unset($data->protected_fields);
}
$data->timezone_id = (string)config('ninja.i18n.timezone_id');
$data->currency_id = (string)config('ninja.i18n.currency_id');
$data->language_id = (string)config('ninja.i18n.language_id');
$data->payment_terms = (int)config('ninja.i18n.payment_terms');
$data->military_time = (bool)config('ninja.i18n.military_time');
$data->date_format_id = (string)config('ninja.i18n.date_format_id');
$data->country_id = (string)config('ninja.i18n.country_id');
$data->translations = (object) [];
// $data->email_subject_invoice = EmailTemplateDefaults::emailInvoiceSubject();
// $data->email_template_invoice = EmailTemplateDefaults:: emailInvoiceTemplate();
// $data->email_subject_quote = EmailTemplateDefaults::emailQuoteSubject();
// $data->email_subject_payment = EmailTemplateDefaults::emailPaymentSubject();
// $data->email_subject_statement = EmailTemplateDefaults::emailStatementSubject();
// $data->email_template_quote = EmailTemplateDefaults::emailQuoteTemplate();
// $data->email_template_payment = EmailTemplateDefaults::emailPaymentTemplate();
// $data->email_template_statement = EmailTemplateDefaults::emailStatementTemplate();
// $data->email_subject_reminder1 = EmailTemplateDefaults::emailReminder1Subject();
// $data->email_subject_reminder2 = EmailTemplateDefaults::emailReminder2Subject();
// $data->email_subject_reminder3 = EmailTemplateDefaults::emailReminder3Subject();
// $data->email_subject_reminder_endless = EmailTemplateDefaults::emailReminderEndlessSubject();
// $data->email_template_reminder1 = EmailTemplateDefaults::emailReminder1Template();
// $data->email_template_reminder2 = EmailTemplateDefaults::emailReminder2Template();
// $data->email_template_reminder3 = EmailTemplateDefaults::emailReminder3Template();
// $data->email_template_reminder_endless = EmailTemplateDefaults::emailReminderEndlessTemplate();
return self::setCasts($data, self::$casts);
}
/**
* In case we update the settings object in the future we
* need to provide a fallback catch on old settings objects which will
* set new properties to the object prior to being returned.
*
* @param object $data The settings object to be checked
*/
public static function setProperties($settings) :\stdClass
{
/**
* In case we update the settings object in the future we
* need to provide a fallback catch on old settings objects which will
* set new properties to the object prior to being returned.
*
* @param object $data The settings object to be checked
*/
public static function setProperties($settings) :\stdClass
{
$company_settings = (object)get_class_vars(CompanySettings::class);
$company_settings = (object)get_class_vars(CompanySettings::class);
foreach($company_settings as $key => $value)
{
if(!property_exists($settings, $key))
$settings->{$key} = self::castAttribute($key, $company_settings->{$key});
}
return $settings;
}
foreach ($company_settings as $key => $value) {
if (!property_exists($settings, $key)) {
$settings->{$key} = self::castAttribute($key, $company_settings->{$key});
}
}
return $settings;
}
}

View File

@ -21,33 +21,30 @@ use App\Models\User;
class DefaultSettings extends BaseSettings
{
/**
* @var int
/**
* @var int
*/
public static $per_page = 25;
public static $per_page = 25;
/**
* @return \stdClass
*
* //todo user specific settings / preferences.
/**
* @return \stdClass
*
* //todo user specific settings / preferences.
*/
public static function userSettings() : \stdClass
{
return (object)[
class_basename(User::class) => self::userSettingsObject(),
];
}
public static function userSettings() : \stdClass
{
return (object)[
class_basename(User::class) => self::userSettingsObject(),
];
}
/**
* @return \stdClass
/**
* @return \stdClass
*/
private static function userSettingsObject() : \stdClass
{
return (object)[
'per_page' => self::$per_page,
];
}
}
private static function userSettingsObject() : \stdClass
{
return (object)[
'per_page' => self::$per_page,
];
}
}

View File

@ -108,5 +108,3 @@ class EmailTemplateDefaults
return str_replace(":", "$", ctrans('texts.'.$string));
}
}

View File

@ -13,29 +13,29 @@ namespace App\DataMapper;
class FeesAndLimits
{
public $min_limit = -1; //equivalent to null
public $min_limit = -1; //equivalent to null
public $max_limit = -1; //equivalent to null
public $max_limit = -1; //equivalent to null
public $fee_amount = 0;
public $fee_amount = 0;
public $fee_percent = 0;
public $fee_percent = 0;
public $fee_tax_name1 = '';
public $fee_tax_name1 = '';
public $fee_tax_name2 = '';
public $fee_tax_name2 = '';
public $fee_tax_name3 = '';
public $fee_tax_name3 = '';
public $fee_tax_rate1 = 0;
public $fee_tax_rate1 = 0;
public $fee_tax_rate2 = 0;
public $fee_tax_rate2 = 0;
public $fee_tax_rate3 = 0;
public $fee_tax_rate3 = 0;
public $fee_cap = 0;
public $fee_cap = 0;
public $adjust_fee_percent = false;
public $adjust_fee_percent = false;
//public $gateway_type_id = 1;

View File

@ -13,7 +13,6 @@ namespace App\DataMapper;
class InvoiceItem
{
public $quantity = 0;
public $cost = 0;

View File

@ -13,13 +13,13 @@ namespace App\DataMapper;
class PaymentMethodMeta
{
public $exp_month;
public $exp_month;
public $exp_year;
public $exp_year;
public $brand;
public $brand;
public $last4;
public $last4;
public $type;
}
public $type;
}

View File

@ -13,17 +13,15 @@ namespace App\DataMapper;
class PaymentTransaction
{
public $transaction_id;
public $transaction_id;
public $gateway_response;
public $gateway_response;
public $account_gateway_id;
public $account_gateway_id;
public $type_id;
public $type_id;
public $status; // prepayment|payment|response|completed
public $status; // prepayment|payment|response|completed
public $invoices;
}
public $invoices;
}

View File

@ -19,6 +19,7 @@ use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
/**
* Class ClientWasArchived.
*/

View File

@ -40,9 +40,7 @@ class ContactLoggedIn
*/
public function __construct(ClientContact $client_contact)
{
$this->client_contact = $client_contact;
}
/**

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class ExpenseWasArchived.
*/
class ExpenseWasArchived
class ExpenseWasArchived
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class ExpenseWasCreated.
*/
class ExpenseWasCreated
class ExpenseWasCreated
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class ExpenseWasRestored.
*/
class ExpenseWasRestored
class ExpenseWasRestored
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class ExpenseWasUpdated.
*/
class ExpenseWasUpdated
class ExpenseWasUpdated
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasArchived.
*/
class InvoiceWasArchived
class InvoiceWasArchived
{
use SerializesModels;

View File

@ -18,7 +18,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasCreated.
*/
class InvoiceWasCreated
class InvoiceWasCreated
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasDeleted.
*/
class InvoiceWasDeleted
class InvoiceWasDeleted
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasEmailed.
*/
class InvoiceWasEmailed
class InvoiceWasEmailed
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasEmailedAndFailed.
*/
class InvoiceWasEmailedAndFailed
class InvoiceWasEmailedAndFailed
{
use SerializesModels;

View File

@ -18,7 +18,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasMarkedSent.
*/
class InvoiceWasMarkedSent
class InvoiceWasMarkedSent
{
use SerializesModels;

View File

@ -18,7 +18,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasPaid.
*/
class InvoiceWasPaid
class InvoiceWasPaid
{
use SerializesModels;

View File

@ -11,13 +11,14 @@
namespace App\Events\Invoice;
use App\Models\Company;
use App\Models\Invoice;
use Illuminate\Queue\SerializesModels;
/**
* Class InvoiceWasUpdated.
*/
class InvoiceWasUpdated
class InvoiceWasUpdated
{
use SerializesModels;
@ -26,13 +27,15 @@ class InvoiceWasUpdated
*/
public $invoice;
public $company;
/**
* Create a new event instance.
*
* @param Invoice $invoice
*/
public function __construct(Invoice $invoice)
public function __construct(Invoice $invoice, Company $company)
{
$this->invoice = $invoice;
$this->company = $company;
}
}

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class PaymentCompleted.
*/
class PaymentCompleted
class PaymentCompleted
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class PaymentFailed.
*/
class PaymentFailed
class PaymentFailed
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class PaymentWasArchived.
*/
class PaymentWasArchived
class PaymentWasArchived
{
use SerializesModels;

View File

@ -18,7 +18,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class PaymentWasCreated.
*/
class PaymentWasCreated
class PaymentWasCreated
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class PaymentWasDeleted.
*/
class PaymentWasDeleted
class PaymentWasDeleted
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class PaymentWasRefunded.
*/
class PaymentWasRefunded
class PaymentWasRefunded
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class PaymentWasRestored.
*/
class PaymentWasRestored
class PaymentWasRestored
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class PaymentWasVoided.
*/
class PaymentWasVoided
class PaymentWasVoided
{
use SerializesModels;

View File

@ -14,7 +14,7 @@ namespace App\Events\Product;
use App\Models\Product;
use Illuminate\Queue\SerializesModels;
class ProductWasDeleted
class ProductWasDeleted
{
use SerializesModels;

View File

@ -16,7 +16,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class QuoteWasCreated.
*/
class QuoteWasCreated
class QuoteWasCreated
{
use SerializesModels;
public $quote;

View File

@ -16,7 +16,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class QuoteWasDeleted.
*/
class QuoteWasDeleted
class QuoteWasDeleted
{
use SerializesModels;
public $quote;

View File

@ -16,7 +16,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class QuoteWasEmailed.
*/
class QuoteWasEmailed
class QuoteWasEmailed
{
use SerializesModels;
public $quote;

View File

@ -16,7 +16,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class QuoteWasRestored.
*/
class QuoteWasRestored
class QuoteWasRestored
{
use SerializesModels;
public $quote;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class TaskWasArchived.
*/
class TaskWasArchived
class TaskWasArchived
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class TaskWasCreated.
*/
class TaskWasCreated
class TaskWasCreated
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class TaskWasDeleted.
*/
class TaskWasDeleted
class TaskWasDeleted
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class TaskWasRestored.
*/
class TaskWasRestored
class TaskWasRestored
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class TaskWasUpdated.
*/
class TaskWasUpdated
class TaskWasUpdated
{
use SerializesModels;

View File

@ -39,9 +39,7 @@ class UserLoggedIn
*/
public function __construct($user)
{
$this->user = $user;
}
/**

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class VendorWasArchived.
*/
class VendorWasArchived
class VendorWasArchived
{
// vendor
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class VendorWasCreated.
*/
class VendorWasCreated
class VendorWasCreated
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class VendorWasDeleted.
*/
class VendorWasDeleted
class VendorWasDeleted
{
use SerializesModels;

View File

@ -17,7 +17,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class VendorWasRestored.
*/
class VendorWasRestored
class VendorWasRestored
{
use SerializesModels;

View File

@ -70,47 +70,32 @@ class Handler extends ExceptionHandler
public function render($request, Exception $exception)
{
if ($exception instanceof ModelNotFoundException && $request->expectsJson())
{
return response()->json(['message'=>'Record not found'],400);
}
else if($exception instanceof ThrottleRequestsException && $request->expectsJson())
{
return response()->json(['message'=>'Too many requests'],429);
}
else if($exception instanceof FatalThrowableError && $request->expectsJson())
{
if ($exception instanceof ModelNotFoundException && $request->expectsJson()) {
return response()->json(['message'=>'Record not found'], 400);
} elseif ($exception instanceof ThrottleRequestsException && $request->expectsJson()) {
return response()->json(['message'=>'Too many requests'], 429);
} elseif ($exception instanceof FatalThrowableError && $request->expectsJson()) {
return response()->json(['message'=>'Fatal error'], 500);
}
else if($exception instanceof AuthorizationException)
{
return response()->json(['message'=>'You are not authorized to view or perform this action'],401);
}
else if ($exception instanceof \Illuminate\Session\TokenMismatchException)
{
} elseif ($exception instanceof AuthorizationException) {
return response()->json(['message'=>'You are not authorized to view or perform this action'], 401);
} elseif ($exception instanceof \Illuminate\Session\TokenMismatchException) {
return redirect()
->back()
->withInput($request->except('password', 'password_confirmation', '_token'))
->with([
'message' => ctrans('texts.token_expired'),
'message-type' => 'danger']);
}
else if ($exception instanceof NotFoundHttpException && $request->expectsJson()) {
return response()->json(['message'=>'Route does not exist'],404);
}
else if($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()){
return response()->json(['message'=>'Method not support for this route'],404);
}
else if ($exception instanceof ValidationException && $request->expectsJson()) {
} elseif ($exception instanceof NotFoundHttpException && $request->expectsJson()) {
return response()->json(['message'=>'Route does not exist'], 404);
} elseif ($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()) {
return response()->json(['message'=>'Method not support for this route'], 404);
} elseif ($exception instanceof ValidationException && $request->expectsJson()) {
return response()->json(['message' => 'The given data was invalid.', 'errors' => $exception->validator->getMessageBag()], 422);
}
else if ($exception instanceof RelationNotFoundException && $request->expectsJson()) {
} elseif ($exception instanceof RelationNotFoundException && $request->expectsJson()) {
return response()->json(['message' => $exception->getMessage()], 400);
}
return parent::render($request, $exception);
}

View File

@ -15,15 +15,15 @@ use App\Models\ClientContact;
class ClientContactFactory
{
public static function create(int $company_id, int $user_id) :ClientContact
{
$client_contact = new ClientContact;
public static function create(int $company_id, int $user_id) :ClientContact
{
$client_contact = new ClientContact;
$client_contact->first_name = "";
$client_contact->user_id = $user_id;
$client_contact->company_id = $company_id;
$client_contact->contact_key = \Illuminate\Support\Str::random(40);
$client_contact->id = 0;
return $client_contact;
}
return $client_contact;
}
}

View File

@ -17,24 +17,24 @@ use Illuminate\Support\Str;
class ClientFactory
{
public static function create(int $company_id, int $user_id) :Client
{
$client = new Client;
$client->company_id = $company_id;
$client->user_id = $user_id;
$client->name = '';
$client->website = '';
$client->private_notes = '';
$client->balance = 0;
$client->paid_to_date = 0;
$client->country_id = 4;
$client->is_deleted = 0;
$client->client_hash = Str::random(40);
$client->settings = ClientSettings::defaults();
$client_contact = ClientContactFactory::create($company_id, $user_id);
public static function create(int $company_id, int $user_id) :Client
{
$client = new Client;
$client->company_id = $company_id;
$client->user_id = $user_id;
$client->name = '';
$client->website = '';
$client->private_notes = '';
$client->balance = 0;
$client->paid_to_date = 0;
$client->country_id = 4;
$client->is_deleted = 0;
$client->client_hash = Str::random(40);
$client->settings = ClientSettings::defaults();
$client_contact = ClientContactFactory::create($company_id, $user_id);
$client->contacts->add($client_contact);
return $client;
}
return $client;
}
}

View File

@ -15,20 +15,19 @@ use App\Models\Invoice;
class CloneInvoiceFactory
{
public static function create(Invoice $invoice, $user_id) : ?Invoice
{
$clone_invoice = $invoice->replicate();
$clone_invoice->status_id = Invoice::STATUS_DRAFT;
$clone_invoice->number = NULL;
$clone_invoice->date = null;
$clone_invoice->due_date = null;
$clone_invoice->partial_due_date = null;
$clone_invoice->user_id = $user_id;
$clone_invoice->balance = $invoice->amount;
$clone_invoice->line_items = $invoice->line_items;
$clone_invoice->backup = null;
return $clone_invoice;
}
}
public static function create(Invoice $invoice, $user_id) : ?Invoice
{
$clone_invoice = $invoice->replicate();
$clone_invoice->status_id = Invoice::STATUS_DRAFT;
$clone_invoice->number = null;
$clone_invoice->date = null;
$clone_invoice->due_date = null;
$clone_invoice->partial_due_date = null;
$clone_invoice->user_id = $user_id;
$clone_invoice->balance = $invoice->amount;
$clone_invoice->line_items = $invoice->line_items;
$clone_invoice->backup = null;
return $clone_invoice;
}
}

View File

@ -16,45 +16,43 @@ use App\Models\Quote;
class CloneInvoiceToQuoteFactory
{
public static function create(Invoice $invoice, $user_id) : ?Quote
{
public static function create(Invoice $invoice, $user_id) : ?Quote
{
$quote = new Quote();
$quote->client_id = $invoice->client_id;
$quote->user_id = $user_id;
$quote->company_id = $invoice->company_id;
$quote->discount = $invoice->discount;
$quote->is_amount_discount = $invoice->is_amount_discount;
$quote->po_number = $invoice->po_number;
$quote->is_deleted = false;
$quote->backup = null;
$quote->footer = $invoice->footer;
$quote->public_notes = $invoice->public_notes;
$quote->private_notes = $invoice->private_notes;
$quote->terms = $invoice->terms;
$quote->tax_name1 = $invoice->tax_name1;
$quote->tax_rate1 = $invoice->tax_rate1;
$quote->tax_name2 = $invoice->tax_name2;
$quote->tax_rate2 = $invoice->tax_rate2;
$quote->custom_value1 = $invoice->custom_value1;
$quote->custom_value2 = $invoice->custom_value2;
$quote->custom_value3 = $invoice->custom_value3;
$quote->custom_value4 = $invoice->custom_value4;
$quote->amount = $invoice->amount;
$quote->balance = $invoice->balance;
$quote->partial = $invoice->partial;
$quote->partial_due_date = $invoice->partial_due_date;
$quote->last_viewed = $invoice->last_viewed;
$quote = new Quote();
$quote->client_id = $invoice->client_id;
$quote->user_id = $user_id;
$quote->company_id = $invoice->company_id;
$quote->discount = $invoice->discount;
$quote->is_amount_discount = $invoice->is_amount_discount;
$quote->po_number = $invoice->po_number;
$quote->is_deleted = false;
$quote->backup = null;
$quote->footer = $invoice->footer;
$quote->public_notes = $invoice->public_notes;
$quote->private_notes = $invoice->private_notes;
$quote->terms = $invoice->terms;
$quote->tax_name1 = $invoice->tax_name1;
$quote->tax_rate1 = $invoice->tax_rate1;
$quote->tax_name2 = $invoice->tax_name2;
$quote->tax_rate2 = $invoice->tax_rate2;
$quote->custom_value1 = $invoice->custom_value1;
$quote->custom_value2 = $invoice->custom_value2;
$quote->custom_value3 = $invoice->custom_value3;
$quote->custom_value4 = $invoice->custom_value4;
$quote->amount = $invoice->amount;
$quote->balance = $invoice->balance;
$quote->partial = $invoice->partial;
$quote->partial_due_date = $invoice->partial_due_date;
$quote->last_viewed = $invoice->last_viewed;
$quote->status_id = Quote::STATUS_DRAFT;
$quote->number = '';
$quote->date = null;
$quote->due_date = null;
$quote->partial_due_date = null;
$quote->balance = $invoice->amount;
$quote->line_items = $invoice->line_items;
$quote->status_id = Quote::STATUS_DRAFT;
$quote->number = '';
$quote->date = null;
$quote->due_date = null;
$quote->partial_due_date = null;
$quote->balance = $invoice->amount;
$quote->line_items = $invoice->line_items;
return $quote;
}
}
return $quote;
}
}

View File

@ -17,14 +17,14 @@ use App\Utils\Traits\MakesHash;
class CompanyFactory
{
use MakesHash;
use MakesHash;
/**
* @param int $account_id
* @return Company
*/
public function create(int $account_id) :Company
{
{
$company = new Company;
// $company->name = '';
$company->account_id = $account_id;

View File

@ -15,15 +15,12 @@ use App\Models\CompanyGateway;
class CompanyGatewayFactory
{
public static function create(int $company_id, int $user_id) :CompanyGateway
{
public static function create(int $company_id, int $user_id) :CompanyGateway
{
$company_gateway = new CompanyGateway;
$company_gateway->company_id = $company_id;
$company_gateway->user_id = $user_id;
return $company_gateway;
}
}
}

View File

@ -15,17 +15,17 @@ use App\Models\CompanyLedger;
class CompanyLedgerFactory
{
public static function create(int $company_id, int $user_id) :CompanyLedger
{
$company_ledger = new CompanyLedger;
$company_ledger->company_id = $company_id;
$company_ledger->user_id = $user_id;
$company_ledger->adjustment = 0;
$company_ledger->balance = 0;
$company_ledger->notes = '';
$company_ledger->hash = '';
$company_ledger->client_id = 0;
public static function create(int $company_id, int $user_id) :CompanyLedger
{
$company_ledger = new CompanyLedger;
$company_ledger->company_id = $company_id;
$company_ledger->user_id = $user_id;
$company_ledger->adjustment = 0;
$company_ledger->balance = 0;
$company_ledger->notes = '';
$company_ledger->hash = '';
$company_ledger->client_id = 0;
return $company_ledger;
}
return $company_ledger;
}
}

View File

@ -15,16 +15,13 @@ use App\Models\CompanyUser;
class CompanyUserFactory
{
public static function create($user_id, $company_id, $account_id) :CompanyUser
{
public static function create($user_id, $company_id, $account_id) :CompanyUser
{
$company_user = new CompanyUser;
$company_user->user_id = $user_id;
$company_user->company_id = $company_id;
$company_user->account_id = $account_id;
return $company_user;
}
}
}

View File

@ -15,10 +15,8 @@ use App\Models\GroupSetting;
class GroupSettingFactory
{
public static function create(int $company_id, int $user_id) :GroupSetting
{
public static function create(int $company_id, int $user_id) :GroupSetting
{
$gs = new GroupSetting;
$gs->name = '';
$gs->company_id = $company_id;
@ -26,6 +24,5 @@ class GroupSettingFactory
$gs->settings = '{}';
return $gs;
}
}
}

View File

@ -18,39 +18,39 @@ use Illuminate\Support\Facades\Log;
class InvoiceFactory
{
public static function create(int $company_id, int $user_id) :Invoice
{
$invoice = new Invoice();
$invoice->status_id = Invoice::STATUS_DRAFT;
$invoice->number = null;
$invoice->discount = 0;
$invoice->is_amount_discount = true;
$invoice->po_number = '';
$invoice->footer = '';
$invoice->terms = '';
$invoice->public_notes = '';
$invoice->private_notes = '';
$invoice->date = null;
$invoice->due_date = null;
$invoice->partial_due_date = null;
$invoice->is_deleted = false;
$invoice->line_items = json_encode([]);
$invoice->backup = json_encode([]);
$invoice->tax_name1 = '';
$invoice->tax_rate1 = 0;
$invoice->tax_name2 = '';
$invoice->tax_rate2 = 0;
$invoice->custom_value1 = 0;
$invoice->custom_value2 = 0;
$invoice->custom_value3 = 0;
$invoice->custom_value4 = 0;
$invoice->amount = 0;
$invoice->balance = 0;
$invoice->partial = 0;
$invoice->user_id = $user_id;
$invoice->company_id = $company_id;
$invoice->recurring_id = null;
return $invoice;
}
public static function create(int $company_id, int $user_id) :Invoice
{
$invoice = new Invoice();
$invoice->status_id = Invoice::STATUS_DRAFT;
$invoice->number = null;
$invoice->discount = 0;
$invoice->is_amount_discount = true;
$invoice->po_number = '';
$invoice->footer = '';
$invoice->terms = '';
$invoice->public_notes = '';
$invoice->private_notes = '';
$invoice->date = null;
$invoice->due_date = null;
$invoice->partial_due_date = null;
$invoice->is_deleted = false;
$invoice->line_items = json_encode([]);
$invoice->backup = json_encode([]);
$invoice->tax_name1 = '';
$invoice->tax_rate1 = 0;
$invoice->tax_name2 = '';
$invoice->tax_rate2 = 0;
$invoice->custom_value1 = 0;
$invoice->custom_value2 = 0;
$invoice->custom_value3 = 0;
$invoice->custom_value4 = 0;
$invoice->amount = 0;
$invoice->balance = 0;
$invoice->partial = 0;
$invoice->user_id = $user_id;
$invoice->company_id = $company_id;
$invoice->recurring_id = null;
return $invoice;
}
}

View File

@ -16,27 +16,23 @@ use Illuminate\Support\Str;
class InvoiceInvitationFactory
{
public static function create(int $company_id, int $user_id) :InvoiceInvitation
{
$ii = new InvoiceInvitation;
$ii->company_id = $company_id;
$ii->user_id = $user_id;
$ii->client_contact_id = null;
$ii->invoice_id = null;
$ii->key = Str::random(config('ninja.key_length'));
$ii->transaction_reference = null;
$ii->message_id = null;
$ii->email_error = '';
$ii->signature_base64 = '';
$ii->signature_date = null;
$ii->sent_date = null;
$ii->viewed_date = null;
$ii->opened_date = null;
public static function create(int $company_id, int $user_id) :InvoiceInvitation
{
$ii = new InvoiceInvitation;
$ii->company_id = $company_id;
$ii->user_id = $user_id;
$ii->client_contact_id = null;
$ii->invoice_id = null;
$ii->key = Str::random(config('ninja.key_length'));
$ii->transaction_reference = null;
$ii->message_id = null;
$ii->email_error = '';
$ii->signature_base64 = '';
$ii->signature_date = null;
$ii->sent_date = null;
$ii->viewed_date = null;
$ii->opened_date = null;
return $ii;
}
return $ii;
}
}

View File

@ -12,70 +12,67 @@
namespace App\Factory;
use Illuminate\Support\Carbon;
//use Faker\Generator as Faker;
class InvoiceItemFactory
{
public static function create() :\stdClass
{
$item = new \stdClass;
$item->quantity = 0;
$item->cost = 0;
$item->product_key = '';
$item->notes = '';
$item->discount = 0;
$item->is_amount_discount = true;
$item->tax_name1 = '';
$item->tax_rate1 = 0;
$item->tax_name2 = '';
$item->tax_rate2 = 0;
$item->tax_name3 = '';
$item->tax_rate3 = 0;
$item->sort_id = 0;
$item->line_total = 0;
$item->date = Carbon::now();
$item->custom_value1 = NULL;
$item->custom_value2 = NULL;
$item->custom_value3 = NULL;
$item->custom_value4 = NULL;
public static function create() :\stdClass
{
$item = new \stdClass;
$item->quantity = 0;
$item->cost = 0;
$item->product_key = '';
$item->notes = '';
$item->discount = 0;
$item->is_amount_discount = true;
$item->tax_name1 = '';
$item->tax_rate1 = 0;
$item->tax_name2 = '';
$item->tax_rate2 = 0;
$item->tax_name3 = '';
$item->tax_rate3 = 0;
$item->sort_id = 0;
$item->line_total = 0;
$item->date = Carbon::now();
$item->custom_value1 = null;
$item->custom_value2 = null;
$item->custom_value3 = null;
$item->custom_value4 = null;
return $item;
return $item;
}
}
/**
* Generates an array of dummy data for invoice items
* @param int $items Number of line items to create
* @return array array of objects
*/
public static function generate(int $items = 1) :array
{
$faker = \Faker\Factory::create();
/**
* Generates an array of dummy data for invoice items
* @param int $items Number of line items to create
* @return array array of objects
*/
public static function generate(int $items = 1) :array
{
$faker = \Faker\Factory::create();
$data = [];
for($x=0; $x<$items; $x++)
{
$item = self::create();
$item->quantity = $faker->numberBetween(1,10);
$item->cost = $faker->randomFloat(2, 1, 1000);
$item->line_total = $item->quantity * $item->cost;
$item->is_amount_discount = true;
$item->discount = $faker->numberBetween(1,10);
$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->tax_name1 = 'GST';
$item->tax_rate1 = '10.00';
$data[] = $item;
}
return $data;
}
$data = [];
for ($x=0; $x<$items; $x++) {
$item = self::create();
$item->quantity = $faker->numberBetween(1, 10);
$item->cost = $faker->randomFloat(2, 1, 1000);
$item->line_total = $item->quantity * $item->cost;
$item->is_amount_discount = true;
$item->discount = $faker->numberBetween(1, 10);
$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->tax_name1 = 'GST';
$item->tax_rate1 = '10.00';
$data[] = $item;
}
return $data;
}
}

View File

@ -18,44 +18,42 @@ use App\Models\RecurringInvoice;
class InvoiceToRecurringInvoiceFactory
{
public static function create(Invoice $invoice) :RecurringInvoice
{
$recurring_invoice = new RecurringInvoice;
public static function create(Invoice $invoice) :RecurringInvoice
{
$recurring_invoice = new RecurringInvoice;
$recurring_invoice->status_id = RecurringInvoice::STATUS_DRAFT;
$recurring_invoice->discount = $invoice->discount;
$recurring_invoice->number = '';
$recurring_invoice->is_amount_discount = $invoice->is_amount_discount;
$recurring_invoice->po_number = $invoice->po_number;
$recurring_invoice->footer = $invoice->footer;
$recurring_invoice->terms = $invoice->terms;
$recurring_invoice->public_notes = $invoice->public_notes;
$recurring_invoice->private_notes = $invoice->private_notes;
$recurring_invoice->date = date_create()->format($invoice->client->date_format());
$recurring_invoice->due_date = $invoice->due_date; //todo calculate based on terms
$recurring_invoice->is_deleted = $invoice->is_deleted;
$recurring_invoice->line_items = $invoice->line_items;
$recurring_invoice->tax_name1 = $invoice->tax_name1;
$recurring_invoice->tax_rate1 = $invoice->tax_rate1;
$recurring_invoice->tax_name2 = $invoice->tax_name2;
$recurring_invoice->tax_rate2 = $invoice->tax_rate2;
$recurring_invoice->custom_value1 = $invoice->custom_value1;
$recurring_invoice->custom_value2 = $invoice->custom_value2;
$recurring_invoice->custom_value3 = $invoice->custom_value3;
$recurring_invoice->custom_value4 = $invoice->custom_value4;
$recurring_invoice->amount = $invoice->amount;
$recurring_invoice->balance = $invoice->balance;
$recurring_invoice->user_id = $invoice->user_id;
$recurring_invoice->client_id = $invoice->client_id;
$recurring_invoice->company_id = $invoice->company_id;
$recurring_invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$recurring_invoice->start_date = null;
$recurring_invoice->last_sent_date = null;
$recurring_invoice->next_send_date = null;
$recurring_invoice->remaining_cycles = 0;
return $recurring_invoice;
}
$recurring_invoice->status_id = RecurringInvoice::STATUS_DRAFT;
$recurring_invoice->discount = $invoice->discount;
$recurring_invoice->number = '';
$recurring_invoice->is_amount_discount = $invoice->is_amount_discount;
$recurring_invoice->po_number = $invoice->po_number;
$recurring_invoice->footer = $invoice->footer;
$recurring_invoice->terms = $invoice->terms;
$recurring_invoice->public_notes = $invoice->public_notes;
$recurring_invoice->private_notes = $invoice->private_notes;
$recurring_invoice->date = date_create()->format($invoice->client->date_format());
$recurring_invoice->due_date = $invoice->due_date; //todo calculate based on terms
$recurring_invoice->is_deleted = $invoice->is_deleted;
$recurring_invoice->line_items = $invoice->line_items;
$recurring_invoice->tax_name1 = $invoice->tax_name1;
$recurring_invoice->tax_rate1 = $invoice->tax_rate1;
$recurring_invoice->tax_name2 = $invoice->tax_name2;
$recurring_invoice->tax_rate2 = $invoice->tax_rate2;
$recurring_invoice->custom_value1 = $invoice->custom_value1;
$recurring_invoice->custom_value2 = $invoice->custom_value2;
$recurring_invoice->custom_value3 = $invoice->custom_value3;
$recurring_invoice->custom_value4 = $invoice->custom_value4;
$recurring_invoice->amount = $invoice->amount;
$recurring_invoice->balance = $invoice->balance;
$recurring_invoice->user_id = $invoice->user_id;
$recurring_invoice->client_id = $invoice->client_id;
$recurring_invoice->company_id = $invoice->company_id;
$recurring_invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$recurring_invoice->start_date = null;
$recurring_invoice->last_sent_date = null;
$recurring_invoice->next_send_date = null;
$recurring_invoice->remaining_cycles = 0;
return $recurring_invoice;
}
}

View File

@ -19,27 +19,24 @@ use Illuminate\Support\Facades\Log;
class PaymentFactory
{
public static function create(int $company_id, int $user_id) :Payment
{
$payment = new Payment;
$payment->company_id = $company_id;
$payment->user_id = $user_id;
$payment->client_id = 0;
$payment->client_contact_id = null;
$payment->invitation_id = null;
$payment->company_gateway_id = null;
$payment->type_id = null;
$payment->is_deleted = false;
$payment->amount = 0;
$payment->date = Carbon::now()->format('Y-m-d');
$payment->transaction_reference = null;
$payment->payer_id = null;
$payment->status_id = Payment::STATUS_PENDING;
return $payment;
}
public static function create(int $company_id, int $user_id) :Payment
{
$payment = new Payment;
$payment->company_id = $company_id;
$payment->user_id = $user_id;
$payment->client_id = 0;
$payment->client_contact_id = null;
$payment->invitation_id = null;
$payment->company_gateway_id = null;
$payment->type_id = null;
$payment->is_deleted = false;
$payment->amount = 0;
$payment->date = Carbon::now()->format('Y-m-d');
$payment->transaction_reference = null;
$payment->payer_id = null;
$payment->status_id = Payment::STATUS_PENDING;
return $payment;
}
}

View File

@ -15,29 +15,27 @@ use App\Models\Product;
class ProductFactory
{
public static function create(int $company_id, int $user_id) :Product
{
$product = new Product;
$product->company_id = $company_id;
$product->user_id = $user_id;
public static function create(int $company_id, int $user_id) :Product
{
$product = new Product;
$product->company_id = $company_id;
$product->user_id = $user_id;
$product->product_key = '';
$product->notes = '';
$product->cost = 0;
$product->price = 0;
$product->quantity = 1;
$product->tax_name1 = '';
$product->tax_rate1 = 0;
$product->tax_name2 = '';
$product->tax_rate2 = 0;
$product->custom_value1 = '';
$product->custom_value2 = '';
$product->custom_value3 = '';
$product->custom_value4 = '';
$product->is_deleted = 0;
$product->product_key = '';
$product->notes = '';
$product->cost = 0;
$product->price = 0;
$product->quantity = 1;
$product->tax_name1 = '';
$product->tax_rate1 = 0;
$product->tax_name2 = '';
$product->tax_rate2 = 0;
$product->custom_value1 = '';
$product->custom_value2 = '';
$product->custom_value3 = '';
$product->custom_value4 = '';
$product->is_deleted = 0;
return $product;
}
return $product;
}
}

View File

@ -18,38 +18,38 @@ use Illuminate\Support\Facades\Log;
class QuoteFactory
{
public static function create(int $company_id, int $user_id) :Quote
{
$quote = new Quote();
$quote->status_id = Quote::STATUS_DRAFT;
$quote->number = null;
$quote->discount = 0;
$quote->is_amount_discount = true;
$quote->po_number = '';
$quote->footer = '';
$quote->terms = '';
$quote->public_notes = '';
$quote->private_notes = '';
$quote->date = null;
$quote->due_date = null;
$quote->partial_due_date = null;
$quote->is_deleted = false;
$quote->line_items = json_encode([]);
$quote->backup = json_encode([]);
$quote->tax_name1 = '';
$quote->tax_rate1 = 0;
$quote->tax_name2 = '';
$quote->tax_rate2 = 0;
$quote->custom_value1 = 0;
$quote->custom_value2 = 0;
$quote->custom_value3 = 0;
$quote->custom_value4 = 0;
$quote->amount = 0;
$quote->balance = 0;
$quote->partial = 0;
$quote->user_id = $user_id;
$quote->company_id = $company_id;
return $quote;
}
public static function create(int $company_id, int $user_id) :Quote
{
$quote = new Quote();
$quote->status_id = Quote::STATUS_DRAFT;
$quote->number = null;
$quote->discount = 0;
$quote->is_amount_discount = true;
$quote->po_number = '';
$quote->footer = '';
$quote->terms = '';
$quote->public_notes = '';
$quote->private_notes = '';
$quote->date = null;
$quote->due_date = null;
$quote->partial_due_date = null;
$quote->is_deleted = false;
$quote->line_items = json_encode([]);
$quote->backup = json_encode([]);
$quote->tax_name1 = '';
$quote->tax_rate1 = 0;
$quote->tax_name2 = '';
$quote->tax_rate2 = 0;
$quote->custom_value1 = 0;
$quote->custom_value2 = 0;
$quote->custom_value3 = 0;
$quote->custom_value4 = 0;
$quote->amount = 0;
$quote->balance = 0;
$quote->partial = 0;
$quote->user_id = $user_id;
$quote->company_id = $company_id;
return $quote;
}
}

View File

@ -16,27 +16,23 @@ use Illuminate\Support\Str;
class QuoteInvitationFactory
{
public static function create(int $company_id, int $user_id) :QuoteInvitation
{
$qi = new QuoteInvitation;
$qi->company_id = $company_id;
$qi->user_id = $user_id;
$qi->client_contact_id = null;
$qi->quote_id = null;
$qi->key = Str::random(config('ninja.key_length'));
$qi->transaction_reference = null;
$qi->message_id = null;
$qi->email_error = '';
$qi->signature_base64 = '';
$qi->signature_date = null;
$qi->sent_date = null;
$qi->viewed_date = null;
$qi->opened_date = null;
public static function create(int $company_id, int $user_id) :QuoteInvitation
{
$qi = new QuoteInvitation;
$qi->company_id = $company_id;
$qi->user_id = $user_id;
$qi->client_contact_id = null;
$qi->quote_id = null;
$qi->key = Str::random(config('ninja.key_length'));
$qi->transaction_reference = null;
$qi->message_id = null;
$qi->email_error = '';
$qi->signature_base64 = '';
$qi->signature_date = null;
$qi->sent_date = null;
$qi->viewed_date = null;
$qi->opened_date = null;
return $qi;
}
return $qi;
}
}

View File

@ -17,44 +17,43 @@ use App\Models\RecurringInvoice;
class RecurringInvoiceFactory
{
public static function create(int $company_id, int $user_id) :RecurringInvoice
{
$invoice = new RecurringInvoice();
$invoice->status_id = RecurringInvoice::STATUS_DRAFT;
$invoice->discount = 0;
$invoice->is_amount_discount = true;
$invoice->po_number = '';
$invoice->number = '';
$invoice->footer = '';
$invoice->terms = '';
$invoice->public_notes = '';
$invoice->private_notes = '';
$invoice->date = null;
$invoice->due_date = null;
$invoice->partial_due_date = null;
$invoice->is_deleted = false;
$invoice->line_items = json_encode([]);
$invoice->backup = json_encode([]);
$invoice->tax_name1 = '';
$invoice->tax_rate1 = 0;
$invoice->tax_name2 = '';
$invoice->tax_rate2 = 0;
$invoice->custom_value1 = 0;
$invoice->custom_value2 = 0;
$invoice->custom_value3 = 0;
$invoice->custom_value4 = 0;
$invoice->amount = 0;
$invoice->balance = 0;
$invoice->partial = 0;
$invoice->user_id = $user_id;
$invoice->company_id = $company_id;
$invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$invoice->start_date = null;
$invoice->last_sent_date = null;
$invoice->next_send_date = null;
$invoice->remaining_cycles = 0;
return $invoice;
}
public static function create(int $company_id, int $user_id) :RecurringInvoice
{
$invoice = new RecurringInvoice();
$invoice->status_id = RecurringInvoice::STATUS_DRAFT;
$invoice->discount = 0;
$invoice->is_amount_discount = true;
$invoice->po_number = '';
$invoice->number = '';
$invoice->footer = '';
$invoice->terms = '';
$invoice->public_notes = '';
$invoice->private_notes = '';
$invoice->date = null;
$invoice->due_date = null;
$invoice->partial_due_date = null;
$invoice->is_deleted = false;
$invoice->line_items = json_encode([]);
$invoice->backup = json_encode([]);
$invoice->tax_name1 = '';
$invoice->tax_rate1 = 0;
$invoice->tax_name2 = '';
$invoice->tax_rate2 = 0;
$invoice->custom_value1 = 0;
$invoice->custom_value2 = 0;
$invoice->custom_value3 = 0;
$invoice->custom_value4 = 0;
$invoice->amount = 0;
$invoice->balance = 0;
$invoice->partial = 0;
$invoice->user_id = $user_id;
$invoice->company_id = $company_id;
$invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$invoice->start_date = null;
$invoice->last_sent_date = null;
$invoice->next_send_date = null;
$invoice->remaining_cycles = 0;
return $invoice;
}
}

View File

@ -18,38 +18,36 @@ use App\Models\RecurringInvoice;
class recurring_invoiceToInvoiceFactory
{
public static function create(RecurringInvoice $recurring_invoice) :Invoice
{
$invoice = new Invoice();
$invoice->status_id = Invoice::STATUS_DRAFT;
$invoice->discount = $recurring_invoice->discount;
$invoice->is_amount_discount = $recurring_invoice->is_amount_discount;
$invoice->po_number = $recurring_invoice->po_number;
$invoice->footer = $recurring_invoice->footer;
$invoice->terms = $recurring_invoice->terms;
$invoice->public_notes = $recurring_invoice->public_notes;
$invoice->private_notes = $recurring_invoice->private_notes;
$invoice->date = date_create()->format($client->date_format());
$invoice->due_date = $recurring_invoice->due_date; //todo calculate based on terms
$invoice->is_deleted = $recurring_invoice->is_deleted;
$invoice->line_items = $recurring_invoice->line_items;
$invoice->backup = json_encode([]);
$invoice->tax_name1 = $recurring_invoice->tax_name1;
$invoice->tax_rate1 = $recurring_invoice->tax_rate1;
$invoice->tax_name2 = $recurring_invoice->tax_name2;
$invoice->tax_rate2 = $recurring_invoice->tax_rate2;
$invoice->custom_value1 = $recurring_invoice->custom_value1;
$invoice->custom_value2 = $recurring_invoice->custom_value2;
$invoice->custom_value3 = $recurring_invoice->custom_value3;
$invoice->custom_value4 = $recurring_invoice->custom_value4;
$invoice->amount = $recurring_invoice->amount;
$invoice->balance = $recurring_invoice->balance;
$invoice->user_id = $recurring_invoice->user_id;
$invoice->company_id = $recurring_invoice->company_id;
$invoice->recurring_id = $recurring_invoice->id;
return $invoice;
}
public static function create(RecurringInvoice $recurring_invoice) :Invoice
{
$invoice = new Invoice();
$invoice->status_id = Invoice::STATUS_DRAFT;
$invoice->discount = $recurring_invoice->discount;
$invoice->is_amount_discount = $recurring_invoice->is_amount_discount;
$invoice->po_number = $recurring_invoice->po_number;
$invoice->footer = $recurring_invoice->footer;
$invoice->terms = $recurring_invoice->terms;
$invoice->public_notes = $recurring_invoice->public_notes;
$invoice->private_notes = $recurring_invoice->private_notes;
$invoice->date = date_create()->format($client->date_format());
$invoice->due_date = $recurring_invoice->due_date; //todo calculate based on terms
$invoice->is_deleted = $recurring_invoice->is_deleted;
$invoice->line_items = $recurring_invoice->line_items;
$invoice->backup = json_encode([]);
$invoice->tax_name1 = $recurring_invoice->tax_name1;
$invoice->tax_rate1 = $recurring_invoice->tax_rate1;
$invoice->tax_name2 = $recurring_invoice->tax_name2;
$invoice->tax_rate2 = $recurring_invoice->tax_rate2;
$invoice->custom_value1 = $recurring_invoice->custom_value1;
$invoice->custom_value2 = $recurring_invoice->custom_value2;
$invoice->custom_value3 = $recurring_invoice->custom_value3;
$invoice->custom_value4 = $recurring_invoice->custom_value4;
$invoice->amount = $recurring_invoice->amount;
$invoice->balance = $recurring_invoice->balance;
$invoice->user_id = $recurring_invoice->user_id;
$invoice->company_id = $recurring_invoice->company_id;
$invoice->recurring_id = $recurring_invoice->id;
return $invoice;
}
}

View File

@ -17,43 +17,42 @@ use App\Models\RecurringQuote;
class RecurringQuoteFactory
{
public static function create(int $company_id, int $user_id) :RecurringQuote
{
$quote = new RecurringQuote();
$quote->status_id = RecurringQuote::STATUS_DRAFT;
$quote->discount = 0;
$quote->is_amount_discount = true;
$quote->po_number = '';
$quote->footer = '';
$quote->terms = '';
$quote->public_notes = '';
$quote->private_notes = '';
$quote->date = null;
$quote->due_date = null;
$quote->partial_due_date = null;
$quote->is_deleted = false;
$quote->line_items = json_encode([]);
$quote->backup = json_encode([]);
$quote->tax_name1 = '';
$quote->tax_rate1 = 0;
$quote->tax_name2 = '';
$quote->tax_rate2 = 0;
$quote->custom_value1 = 0;
$quote->custom_value2 = 0;
$quote->custom_value3 = 0;
$quote->custom_value4 = 0;
$quote->amount = 0;
$quote->balance = 0;
$quote->partial = 0;
$quote->user_id = $user_id;
$quote->company_id = $company_id;
$quote->frequency_id = RecurringQuote::FREQUENCY_MONTHLY;
$quote->start_date = null;
$quote->last_sent_date = null;
$quote->next_send_date = null;
$quote->remaining_cycles = 0;
return $quote;
}
public static function create(int $company_id, int $user_id) :RecurringQuote
{
$quote = new RecurringQuote();
$quote->status_id = RecurringQuote::STATUS_DRAFT;
$quote->discount = 0;
$quote->is_amount_discount = true;
$quote->po_number = '';
$quote->footer = '';
$quote->terms = '';
$quote->public_notes = '';
$quote->private_notes = '';
$quote->date = null;
$quote->due_date = null;
$quote->partial_due_date = null;
$quote->is_deleted = false;
$quote->line_items = json_encode([]);
$quote->backup = json_encode([]);
$quote->tax_name1 = '';
$quote->tax_rate1 = 0;
$quote->tax_name2 = '';
$quote->tax_rate2 = 0;
$quote->custom_value1 = 0;
$quote->custom_value2 = 0;
$quote->custom_value3 = 0;
$quote->custom_value4 = 0;
$quote->amount = 0;
$quote->balance = 0;
$quote->partial = 0;
$quote->user_id = $user_id;
$quote->company_id = $company_id;
$quote->frequency_id = RecurringQuote::FREQUENCY_MONTHLY;
$quote->start_date = null;
$quote->last_sent_date = null;
$quote->next_send_date = null;
$quote->remaining_cycles = 0;
return $quote;
}
}

View File

@ -15,17 +15,15 @@ use App\Models\TaxRate;
class TaxRateFactory
{
public static function create($company_id, $user_id) :TaxRate
{
$tax_rate = new TaxRate;
public static function create($company_id, $user_id) :TaxRate
{
$tax_rate = new TaxRate;
$tax_rate->name = '';
$tax_rate->rate = '';
$tax_rate->company_id = $company_id;
$tax_rate->user_id = $user_id;
$tax_rate->name = '';
$tax_rate->rate = '';
$tax_rate->company_id = $company_id;
$tax_rate->user_id = $user_id;
return $tax_rate;
}
}
return $tax_rate;
}
}

View File

@ -15,19 +15,19 @@ use App\Models\User;
class UserFactory
{
public static function create() :User
{
$user = new User;
public static function create() :User
{
$user = new User;
$user->first_name = '';
$user->last_name = '';
$user->phone = '';
$user->email = '';
$user->last_login = now();
$user->failed_logins = 0;
$user->signature = '';
$user->theme_id = 0;
return $user;
}
}
$user->first_name = '';
$user->last_name = '';
$user->phone = '';
$user->email = '';
$user->last_login = now();
$user->failed_logins = 0;
$user->signature = '';
$user->theme_id = 0;
return $user;
}
}

View File

@ -25,9 +25,9 @@ class ClientFilters extends QueryFilters
/**
* Filter by balance
*
* @param string $balance
* @return Illuminate\Database\Query\Builder
*
* @param string $balance
* @return Illuminate\Database\Query\Builder
*/
public function balance(string $balance): Builder
{
@ -38,7 +38,7 @@ class ClientFilters extends QueryFilters
/**
* Filter between balances
*
*
* @param string balance
* @return Illuminate\Database\Query\Builder
*/
@ -51,41 +51,43 @@ class ClientFilters extends QueryFilters
/**
* Filter based on search text
*
*
* @param string query filter
* @return Illuminate\Database\Query\Builder
* @deprecated
*
*
*/
public function filter(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
return $this->builder->where(function ($query) use ($filter) {
$query->where('clients.name', 'like', '%'.$filter.'%')
$query->where('clients.name', 'like', '%'.$filter.'%')
->orWhere('clients.id_number', 'like', '%'.$filter.'%')
->orWhere('client_contacts.first_name', 'like', '%'.$filter.'%')
->orWhere('client_contacts.last_name', 'like', '%'.$filter.'%')
->orWhere('client_contacts.email', 'like', '%'.$filter.'%')
->orWhere('clients.custom_value1', 'like' , '%'.$filter.'%')
->orWhere('clients.custom_value2', 'like' , '%'.$filter.'%')
->orWhere('clients.custom_value3', 'like' , '%'.$filter.'%')
->orWhere('clients.custom_value4', 'like' , '%'.$filter.'%');
});
->orWhere('clients.custom_value1', 'like', '%'.$filter.'%')
->orWhere('clients.custom_value2', 'like', '%'.$filter.'%')
->orWhere('clients.custom_value3', 'like', '%'.$filter.'%')
->orWhere('clients.custom_value4', 'like', '%'.$filter.'%');
});
}
/**
* Filters the list based on the status
* archived, active, deleted
*
*
* @param string filter
* @return Illuminate\Database\Query\Builder
*/
public function status(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
$table = 'clients';
$filters = explode(',', $filter);
@ -115,7 +117,7 @@ class ClientFilters extends QueryFilters
/**
* Sorts the list based on $sort
*
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Query\Builder
*/
@ -127,7 +129,7 @@ class ClientFilters extends QueryFilters
/**
* Returns the base query
*
*
* @param int company_id
* @return Illuminate\Database\Query\Builder
* @deprecated
@ -181,16 +183,14 @@ class ClientFilters extends QueryFilters
/**
* Filters the query by the users company ID
*
*
* @param $company_id The company Id
* @return Illuminate\Database\Query\Builder
*/
public function entityFilter()
public function entityFilter()
{
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->company();
}
}
}

View File

@ -33,7 +33,7 @@ class InvoiceFilters extends QueryFilters
* - unpaid
* - overdue
* - reversed
*
*
* @param string client_status The invoice status as seen by the client
* @return Illuminate\Database\Query\Builder
*
@ -41,67 +41,74 @@ class InvoiceFilters extends QueryFilters
public function client_status(string $value = '') :Builder
{
if(strlen($value) == 0)
if (strlen($value) == 0) {
return $this->builder;
}
$status_parameters = explode(",", $value);
if (in_array('all', $status_parameters))
if (in_array('all', $status_parameters)) {
return $this->builder;
}
if(in_array('paid', $status_parameters))
if (in_array('paid', $status_parameters)) {
$this->builder->where('status_id', Invoice::STATUS_PAID);
}
if(in_array('unpaid', $status_parameters))
if (in_array('unpaid', $status_parameters)) {
$this->builder->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]);
//->where('due_date', '>', Carbon::now())
//->orWhere('partial_due_date', '>', Carbon::now());
}
//->where('due_date', '>', Carbon::now())
//->orWhere('partial_due_date', '>', Carbon::now());
if(in_array('overdue', $status_parameters))
if (in_array('overdue', $status_parameters)) {
$this->builder->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('due_date', '<', Carbon::now())
->orWhere('partial_due_date', '<', Carbon::now());
}
return $this->builder;
}
/**
* Filter based on search text
*
*
* @param string query filter
* @return Illuminate\Database\Query\Builder
* @deprecated
*
*
*/
public function filter(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
return $this->builder->where(function ($query) use ($filter) {
$query->where('invoices.number', 'like', '%'.$filter.'%')
$query->where('invoices.number', 'like', '%'.$filter.'%')
->orWhere('invoices.po_number', 'like', '%'.$filter.'%')
->orWhere('invoices.date', 'like', '%'.$filter.'%')
->orWhere('invoices.amount', 'like', '%'.$filter.'%')
->orWhere('invoices.balance', 'like', '%'.$filter.'%')
->orWhere('invoices.custom_value1', 'like', '%'.$filter.'%')
->orWhere('invoices.custom_value2', 'like' , '%'.$filter.'%')
->orWhere('invoices.custom_value3', 'like' , '%'.$filter.'%')
->orWhere('invoices.custom_value4', 'like' , '%'.$filter.'%');
});
->orWhere('invoices.custom_value2', 'like', '%'.$filter.'%')
->orWhere('invoices.custom_value3', 'like', '%'.$filter.'%')
->orWhere('invoices.custom_value4', 'like', '%'.$filter.'%');
});
}
/**
* Filters the list based on the status
* archived, active, deleted - legacy from V1
*
*
* @param string filter
* @return Illuminate\Database\Query\Builder
*/
public function status(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
$table = 'invoices';
$filters = explode(',', $filter);
@ -131,7 +138,7 @@ class InvoiceFilters extends QueryFilters
/**
* Sorts the list based on $sort
*
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Query\Builder
*/
@ -143,14 +150,13 @@ class InvoiceFilters extends QueryFilters
/**
* Returns the base query
*
*
* @param int company_id
* @return Illuminate\Database\Query\Builder
* @deprecated
*/
public function baseQuery(int $company_id, User $user) : Builder
{
}
/**
@ -158,37 +164,31 @@ class InvoiceFilters extends QueryFilters
*
* We need to ensure we are using the correct company ID
* as we could be hitting this from either the client or company auth guard
*
*
* @param $company_id The company Id
* @return Illuminate\Database\Query\Builder
*/
public function entityFilter()
{
if(auth('contact')->user())
if (auth('contact')->user()) {
return $this->contactViewFilter();
else
} else {
return $this->builder->company();
}
// return $this->builder->whereCompanyId(auth()->user()->company()->id);
}
/**
* We need additional filters when showing invoices for the
* client portal. Need to automatically exclude drafts and cancelled invoices
*
*
* @return Illuminate\Database\Query\Builder
*/
private function contactViewFilter() : Builder
{
return $this->builder
->whereCompanyId(auth('contact')->user()->company->id)
->whereNotIn('status_id', [Invoice::STATUS_DRAFT, Invoice::STATUS_CANCELLED]);
}
}
}

View File

@ -24,38 +24,40 @@ class PaymentFilters extends QueryFilters
/**
* Filter based on search text
*
*
* @param string query filter
* @return Illuminate\Database\Query\Builder
* @deprecated
*
*
*/
public function filter(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
return $this->builder->where(function ($query) use ($filter) {
$query->where('payments.amount', 'like', '%'.$filter.'%')
$query->where('payments.amount', 'like', '%'.$filter.'%')
->orWhere('payments.date', 'like', '%'.$filter.'%')
->orWhere('payments.custom_value1', 'like', '%'.$filter.'%')
->orWhere('payments.custom_value2', 'like' , '%'.$filter.'%')
->orWhere('payments.custom_value3', 'like' , '%'.$filter.'%')
->orWhere('payments.custom_value4', 'like' , '%'.$filter.'%');
});
->orWhere('payments.custom_value2', 'like', '%'.$filter.'%')
->orWhere('payments.custom_value3', 'like', '%'.$filter.'%')
->orWhere('payments.custom_value4', 'like', '%'.$filter.'%');
});
}
/**
* Filters the list based on the status
* archived, active, deleted
*
*
* @param string filter
* @return Illuminate\Database\Query\Builder
*/
public function status(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
$table = 'payments';
$filters = explode(',', $filter);
@ -85,7 +87,7 @@ class PaymentFilters extends QueryFilters
/**
* Sorts the list based on $sort
*
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Query\Builder
*/
@ -97,29 +99,28 @@ class PaymentFilters extends QueryFilters
/**
* Returns the base query
*
*
* @param int company_id
* @return Illuminate\Database\Query\Builder
* @deprecated
*/
public function baseQuery(int $company_id, User $user) : Builder
{
}
/**
* Filters the query by the users company ID
*
*
* @param $company_id The company Id
* @return Illuminate\Database\Query\Builder
*/
public function entityFilter()
public function entityFilter()
{
if(auth('contact')->user())
if (auth('contact')->user()) {
return $this->contactViewFilter();
else
} else {
return $this->builder->company();
}
}
@ -127,15 +128,13 @@ class PaymentFilters extends QueryFilters
/**
* We need additional filters when showing invoices for the
* client portal. Need to automatically exclude drafts and cancelled invoices
*
*
* @return Illuminate\Database\Query\Builder
*/
private function contactViewFilter() : Builder
{
return $this->builder
->whereCompanyId(auth('contact')->user()->company->id)
->whereIsDeleted(false);
}
}

View File

@ -23,38 +23,40 @@ class ProductFilters extends QueryFilters
/**
* Filter based on search text
*
*
* @param string query filter
* @return Illuminate\Database\Query\Builder
* @deprecated
*
*
*/
public function filter(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
return $this->builder->where(function ($query) use ($filter) {
$query->where('products.product_key', 'like', '%'.$filter.'%')
$query->where('products.product_key', 'like', '%'.$filter.'%')
->orWhere('products.notes', 'like', '%'.$filter.'%')
->orWhere('products.custom_value1', 'like' , '%'.$filter.'%')
->orWhere('products.custom_value2', 'like' , '%'.$filter.'%')
->orWhere('products.custom_value3', 'like' , '%'.$filter.'%')
->orWhere('products.custom_value4', 'like' , '%'.$filter.'%');
});
->orWhere('products.custom_value1', 'like', '%'.$filter.'%')
->orWhere('products.custom_value2', 'like', '%'.$filter.'%')
->orWhere('products.custom_value3', 'like', '%'.$filter.'%')
->orWhere('products.custom_value4', 'like', '%'.$filter.'%');
});
}
/**
* Filters the list based on the status
* archived, active, deleted
*
*
* @param string filter
* @return Illuminate\Database\Query\Builder
*/
public function status(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
$table = 'products';
$filters = explode(',', $filter);
@ -84,7 +86,7 @@ class ProductFilters extends QueryFilters
/**
* Sorts the list based on $sort
*
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Query\Builder
*/
@ -96,27 +98,23 @@ class ProductFilters extends QueryFilters
/**
* Returns the base query
*
*
* @param int company_id
* @return Illuminate\Database\Query\Builder
* @deprecated
*/
public function baseQuery(int $company_id, User $user) : Builder
{
}
/**
* Filters the query by the users company ID
*
*
* @param $company_id The company Id
* @return Illuminate\Database\Query\Builder
*/
public function entityFilter()
public function entityFilter()
{
return $this->builder->company();
return $this->builder->company();
}
}
}

View File

@ -59,9 +59,7 @@ abstract class QueryFilters
*/
public function __construct(Request $request)
{
$this->request = $request;
}
/**
@ -100,20 +98,17 @@ abstract class QueryFilters
*/
public function filters()
{
return $this->request->all();
}
/**
* Explodes the value by delimiter
*
*
* @param string $value
* @return stdClass
* @return stdClass
*/
public function split($value) : stdClass
{
$exploded_array = explode(":", $value);
$parts = new stdClass;
@ -122,18 +117,16 @@ abstract class QueryFilters
$parts->operator = $this->operatorConvertor($exploded_array[1]);
return $parts;
}
/**
* String to operator convertor
*
*
* @param string $value
* @return string
*/
private function operatorConvertor(string $operator) : string
{
switch ($operator) {
case 'lt':
return '<';
@ -159,15 +152,16 @@ abstract class QueryFilters
/**
* Filters the query by the contact's client_id.
*
*
* -Can only be used on contact routes
*
*
* @param $client_id The client Id
* @param Illuminate\Database\Query\Builder
*/
public function clientFilter()
{
if(auth('contact')->user())
if (auth('contact')->user()) {
return $this->builder->whereClientId(auth('contact')->user()->client->id);
}
}
}
}

View File

@ -23,36 +23,38 @@ class QuoteFilters extends QueryFilters
/**
* Filter based on search text
*
*
* @param string query filter
* @return Illuminate\Database\Query\Builder
* @deprecated
*
*
*/
public function filter(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
return $this->builder->where(function ($query) use ($filter) {
$query->where('quotes.custom_value1', 'like', '%'.$filter.'%')
->orWhere('quotes.custom_value2', 'like' , '%'.$filter.'%')
->orWhere('quotes.custom_value3', 'like' , '%'.$filter.'%')
->orWhere('quotes.custom_value4', 'like' , '%'.$filter.'%');
});
$query->where('quotes.custom_value1', 'like', '%'.$filter.'%')
->orWhere('quotes.custom_value2', 'like', '%'.$filter.'%')
->orWhere('quotes.custom_value3', 'like', '%'.$filter.'%')
->orWhere('quotes.custom_value4', 'like', '%'.$filter.'%');
});
}
/**
* Filters the list based on the status
* archived, active, deleted
*
*
* @param string filter
* @return Illuminate\Database\Query\Builder
*/
public function status(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
$table = 'quotes';
$filters = explode(',', $filter);
@ -82,7 +84,7 @@ class QuoteFilters extends QueryFilters
/**
* Sorts the list based on $sort
*
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Query\Builder
*/
@ -94,27 +96,23 @@ class QuoteFilters extends QueryFilters
/**
* Returns the base query
*
*
* @param int company_id
* @return Illuminate\Database\Query\Builder
* @deprecated
*/
public function baseQuery(int $company_id, User $user) : Builder
{
}
/**
* Filters the query by the users company ID
*
*
* @param $company_id The company Id
* @return Illuminate\Database\Query\Builder
*/
public function entityFilter()
public function entityFilter()
{
return $this->builder->company();
return $this->builder->company();
}
}
}

View File

@ -23,36 +23,38 @@ class RecurringInvoiceFilters extends QueryFilters
/**
* Filter based on search text
*
*
* @param string query filter
* @return Illuminate\Database\Query\Builder
* @deprecated
*
*
*/
public function filter(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
return $this->builder->where(function ($query) use ($filter) {
$query->where('recurring_invoices.custom_value1', 'like', '%'.$filter.'%')
->orWhere('recurring_invoices.custom_value2', 'like' , '%'.$filter.'%')
->orWhere('recurring_invoices.custom_value3', 'like' , '%'.$filter.'%')
->orWhere('recurring_invoices.custom_value4', 'like' , '%'.$filter.'%');
});
$query->where('recurring_invoices.custom_value1', 'like', '%'.$filter.'%')
->orWhere('recurring_invoices.custom_value2', 'like', '%'.$filter.'%')
->orWhere('recurring_invoices.custom_value3', 'like', '%'.$filter.'%')
->orWhere('recurring_invoices.custom_value4', 'like', '%'.$filter.'%');
});
}
/**
* Filters the list based on the status
* archived, active, deleted
*
*
* @param string filter
* @return Illuminate\Database\Query\Builder
*/
public function status(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
$table = 'recurring_';
$filters = explode(',', $filter);
@ -82,7 +84,7 @@ class RecurringInvoiceFilters extends QueryFilters
/**
* Sorts the list based on $sort
*
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Query\Builder
*/
@ -94,27 +96,23 @@ class RecurringInvoiceFilters extends QueryFilters
/**
* Returns the base query
*
*
* @param int company_id
* @return Illuminate\Database\Query\Builder
* @deprecated
*/
public function baseQuery(int $company_id, User $user) : Builder
{
}
/**
* Filters the query by the users company ID
*
*
* @param $company_id The company Id
* @return Illuminate\Database\Query\Builder
*/
public function entityFilter()
public function entityFilter()
{
return $this->builder->company();
return $this->builder->company();
}
}
}

View File

@ -23,36 +23,38 @@ class RecurringQuoteFilters extends QueryFilters
/**
* Filter based on search text
*
*
* @param string query filter
* @return Illuminate\Database\Query\Builder
* @deprecated
*
*
*/
public function filter(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
return $this->builder->where(function ($query) use ($filter) {
$query->where('recurring_quotes.custom_value1', 'like', '%'.$filter.'%')
->orWhere('recurring_quotes.custom_value2', 'like' , '%'.$filter.'%')
->orWhere('recurring_quotes.custom_value3', 'like' , '%'.$filter.'%')
->orWhere('recurring_quotes.custom_value4', 'like' , '%'.$filter.'%');
});
$query->where('recurring_quotes.custom_value1', 'like', '%'.$filter.'%')
->orWhere('recurring_quotes.custom_value2', 'like', '%'.$filter.'%')
->orWhere('recurring_quotes.custom_value3', 'like', '%'.$filter.'%')
->orWhere('recurring_quotes.custom_value4', 'like', '%'.$filter.'%');
});
}
/**
* Filters the list based on the status
* archived, active, deleted
*
*
* @param string filter
* @return Illuminate\Database\Query\Builder
*/
public function status(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
$table = 'recurring_';
$filters = explode(',', $filter);
@ -82,7 +84,7 @@ class RecurringQuoteFilters extends QueryFilters
/**
* Sorts the list based on $sort
*
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Query\Builder
*/
@ -94,27 +96,23 @@ class RecurringQuoteFilters extends QueryFilters
/**
* Returns the base query
*
*
* @param int company_id
* @return Illuminate\Database\Query\Builder
* @deprecated
*/
public function baseQuery(int $company_id, User $user) : Builder
{
}
/**
* Filters the query by the users company ID
*
*
* @param $company_id The company Id
* @return Illuminate\Database\Query\Builder
*/
public function entityFilter()
public function entityFilter()
{
return $this->builder->company();
return $this->builder->company();
}
}
}

View File

@ -23,36 +23,38 @@ class UserFilters extends QueryFilters
/**
* Filter based on search text
*
*
* @param string query filter
* @return Illuminate\Database\Query\Builder
* @deprecated
*
*
*/
public function filter(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
return $this->builder->where(function ($query) use ($filter) {
$query->where('users.first_name', 'like', '%'.$filter.'%')
->orWhere('users.last_name', 'like' , '%'.$filter.'%')
->orWhere('users.email', 'like' , '%'.$filter.'%')
->orWhere('users.signature', 'like' , '%'.$filter.'%');
});
$query->where('users.first_name', 'like', '%'.$filter.'%')
->orWhere('users.last_name', 'like', '%'.$filter.'%')
->orWhere('users.email', 'like', '%'.$filter.'%')
->orWhere('users.signature', 'like', '%'.$filter.'%');
});
}
/**
* Filters the list based on the status
* archived, active, deleted
*
*
* @param string filter
* @return Illuminate\Database\Query\Builder
*/
public function status(string $filter = '') : Builder
{
if(strlen($filter) == 0)
if (strlen($filter) == 0) {
return $this->builder;
}
$table = 'users';
$filters = explode(',', $filter);
@ -82,7 +84,7 @@ class UserFilters extends QueryFilters
/**
* Sorts the list based on $sort
*
*
* @param string sort formatted as column|asc
* @return Illuminate\Database\Query\Builder
*/
@ -94,31 +96,27 @@ class UserFilters extends QueryFilters
/**
* Returns the base query
*
*
* @param int company_id
* @return Illuminate\Database\Query\Builder
* @deprecated
*/
public function baseQuery(int $company_id, User $user) : Builder
{
}
/**
* Filters the query by the users company ID
*
*
* @param $company_id The company Id
* @return Illuminate\Database\Query\Builder
*/
public function entityFilter()
public function entityFilter()
{
//return $this->builder->user_companies()->whereCompanyId(auth()->user()->company()->id);
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->whereHas('company_users', function($q)
{
return $this->builder->whereHas('company_users', function ($q) {
$q->where('company_id', '=', auth()->user()->company()->id);
});
}
}
}

View File

@ -16,17 +16,12 @@ namespace App\Helpers\Invoice;
*/
trait Balancer
{
public function balance($total, $invoice)
{
if(isset($this->invoice->id) && $this->invoice->id >= 1)
{
public function balance($total, $invoice)
{
if (isset($this->invoice->id) && $this->invoice->id >= 1) {
return round($total - ($this->invoice->amount - $this->invoice->balance), 2);
}
}
return $total;
}
}
}

View File

@ -16,23 +16,21 @@ namespace App\Helpers\Invoice;
*/
trait CustomValuer
{
public function valuer($custom_value)
{
if(isset($custom_value) && is_numeric($custom_value))
return $custom_value;
public function valuer($custom_value)
{
if (isset($custom_value) && is_numeric($custom_value)) {
return $custom_value;
}
return 0;
}
}
public function valuerTax($custom_value, $has_custom_invoice_taxes)
{
if(isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes === true)
return round($custom_value * ($this->invoice->tax_rate1/100) ,2) + round($custom_value * ($this->invoice->tax_rate2/100) ,2) + round($custom_value * ($this->invoice->tax_rate3/100) ,2);
return 0;
}
public function valuerTax($custom_value, $has_custom_invoice_taxes)
{
if (isset($custom_value) && is_numeric($custom_value) && $has_custom_invoice_taxes === true) {
return round($custom_value * ($this->invoice->tax_rate1/100), 2) + round($custom_value * ($this->invoice->tax_rate2/100), 2) + round($custom_value * ($this->invoice->tax_rate3/100), 2);
}
return 0;
}
}

View File

@ -16,18 +16,13 @@ namespace App\Helpers\Invoice;
*/
trait Discounter
{
public function discount($amount)
{
if ($this->invoice->is_amount_discount == true) {
return $this->invoice->discount;
}
public function discount($amount)
{
if($this->invoice->is_amount_discount == true){
return $this->invoice->discount;
}
return round($amount * ($this->invoice->discount / 100), 2);
}
return round($amount * ($this->invoice->discount / 100), 2);
}
}

View File

@ -21,275 +21,261 @@ use Illuminate\Support\Collection;
class InvoiceItemSum
{
use NumberFormatter;
use Discounter;
use Taxer;
use NumberFormatter;
use Discounter;
use Taxer;
protected $invoice;
protected $invoice;
private $items;
private $items;
private $line_total;
private $line_total;
private $currency;
private $currency;
private $total_taxes;
private $total_taxes;
private $item;
private $item;
private $line_items;
private $line_items;
private $sub_total;
private $sub_total;
private $total_discount;
private $total_discount;
private $tax_collection;
private $tax_collection;
public function __construct($invoice)
{
$this->tax_collection = collect([]);
public function __construct($invoice)
{
$this->invoice = $invoice;
$this->tax_collection = collect([]);
$this->currency = $this->invoice->client->currency();
$this->invoice = $invoice;
$this->line_items = [];
}
$this->currency = $this->invoice->client->currency();
public function process()
{
if (!$this->invoice->line_items || !isset($this->invoice->line_items) || count($this->invoice->line_items) == 0) {
$this->items = [];
return $this;
}
$this->line_items = [];
}
$this->calcLineItems();
public function process()
{
return $this;
}
if(!$this->invoice->line_items || !isset($this->invoice->line_items) || count($this->invoice->line_items) == 0){
$this->items = [];
return $this;
}
private function calcLineItems()
{
foreach ($this->invoice->line_items as $this->item) {
$this->cleanLineItem()
->sumLineItem()
->setDiscount()
->calcTaxes()
->push();
}
$this->calcLineItems();
return $this;
}
return $this;
}
private function push()
{
$this->sub_total += $this->getLineTotal();
private function calcLineItems()
{
foreach($this->invoice->line_items as $this->item)
{
$this->cleanLineItem()
->sumLineItem()
->setDiscount()
->calcTaxes()
->push();
}
$this->line_items[] = $this->item;
return $this;
}
return $this;
}
private function push()
{
private function sumLineItem()
{
$this->setLineTotal($this->formatValue($this->item->cost, $this->currency->precision) * $this->formatValue($this->item->quantity, $this->currency->precision));
return $this;
}
$this->sub_total += $this->getLineTotal();
private function setDiscount()
{
if ($this->invoice->is_amount_discount) {
$this->setLineTotal($this->getLineTotal() - $this->formatValue($this->item->discount, $this->currency->precision));
} else {
$this->setLineTotal($this->getLineTotal() - $this->formatValue(round($this->item->line_total * ($this->item->discount / 100), 2), $this->currency->precision));
}
$this->line_items[] = $this->item;
$this->item->is_amount_discount = $this->invoice->is_amount_discount;
return $this;
}
return $this;
}
private function sumLineItem()
{
$this->setLineTotal($this->formatValue($this->item->cost, $this->currency->precision) * $this->formatValue($this->item->quantity, $this->currency->precision));
return $this;
}
private function calcTaxes()
{
$item_tax = 0;
private function setDiscount()
{
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/100));
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
if($this->invoice->is_amount_discount)
{
$this->setLineTotal($this->getLineTotal() - $this->formatValue($this->item->discount, $this->currency->precision));
}
else
{
$this->setLineTotal($this->getLineTotal() - $this->formatValue(round($this->item->line_total * ($this->item->discount / 100),2), $this->currency->precision));
}
$item_tax += $item_tax_rate1_total;
$this->item->is_amount_discount = $this->invoice->is_amount_discount;
return $this;
if ($item_tax_rate1_total > 0) {
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
}
}
$item_tax_rate2_total = $this->calcAmountLineTax($this->item->tax_rate2, $amount);
private function calcTaxes()
{
$item_tax += $item_tax_rate2_total;
$item_tax = 0;
if ($item_tax_rate2_total > 0) {
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
}
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/100));
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
$item_tax_rate3_total = $this->calcAmountLineTax($this->item->tax_rate3, $amount);
$item_tax += $item_tax_rate1_total;
$item_tax += $item_tax_rate3_total;
if($item_tax_rate1_total > 0)
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
$item_tax_rate2_total = $this->calcAmountLineTax($this->item->tax_rate2, $amount);
$item_tax += $item_tax_rate2_total;
if($item_tax_rate2_total > 0)
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
$item_tax_rate3_total = $this->calcAmountLineTax($this->item->tax_rate3, $amount);
$item_tax += $item_tax_rate3_total;
if($item_tax_rate3_total > 0)
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
if ($item_tax_rate3_total > 0) {
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
}
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
return $this;
}
return $this;
}
private function groupTax($tax_name, $tax_rate, $tax_total)
{
$group_tax = [];
private function groupTax($tax_name, $tax_rate, $tax_total)
{
$group_tax = [];
$key = str_replace(" ", "", $tax_name.$tax_rate);
$key = str_replace(" ", "", $tax_name.$tax_rate);
$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name . ' ' . $tax_rate.'%'];
$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name . ' ' . $tax_rate.'%'];
$this->tax_collection->push(collect($group_tax));
}
$this->tax_collection->push(collect($group_tax));
}
public function getTotalTaxes()
{
return $this->total_taxes;
}
public function getTotalTaxes()
{
return $this->total_taxes;
}
public function setTotalTaxes($total)
{
$this->total_taxes = $total;
public function setTotalTaxes($total)
{
$this->total_taxes = $total;
return $this;
}
return $this;
}
public function setLineTotal($total)
{
$this->item->line_total = $total;
public function setLineTotal($total)
{
$this->item->line_total = $total;
return $this;
}
return $this;
}
public function getLineTotal()
{
return $this->item->line_total;
}
public function getLineTotal()
{
return $this->item->line_total;
}
public function getLineItems()
{
return $this->line_items;
}
public function getLineItems()
{
return $this->line_items;
}
public function getGroupedTaxes()
{
return $this->tax_collection;
}
public function getGroupedTaxes()
{
return $this->tax_collection;
}
public function setGroupedTaxes($group_taxes)
{
$this->tax_collection = $group_taxes;
public function setGroupedTaxes($group_taxes)
{
$this->tax_collection = $group_taxes;
return $this;
}
return $this;
}
public function getSubTotal()
{
return $this->sub_total;
}
public function getSubTotal()
{
return $this->sub_total;
}
public function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
public function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
/**
* Invoice Amount Discount
*
* The problem, when calculating invoice level discounts,
* the tax collected changes.
*
* We need to synthetically reduce the line_total amounts
* and recalculate the taxes and then pass back
* the updated map
*/
public function calcTaxesWithAmountDiscount()
{
$this->setGroupedTaxes(collect([]));
/**
* Invoice Amount Discount
*
* The problem, when calculating invoice level discounts,
* the tax collected changes.
*
* We need to synthetically reduce the line_total amounts
* and recalculate the taxes and then pass back
* the updated map
*/
public function calcTaxesWithAmountDiscount()
{
$this->setGroupedTaxes(collect([]));
$item_tax = 0;
$item_tax = 0;
foreach($this->line_items as $this->item)
{
foreach ($this->line_items as $this->item) {
if ($this->item->line_total == 0) {
continue;
}
if($this->item->line_total == 0)
continue;
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/$this->sub_total));
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/$this->sub_total));
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
$item_tax += $item_tax_rate1_total;
$item_tax += $item_tax_rate1_total;
if ($item_tax_rate1_total > 0) {
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
}
$item_tax_rate2_total = $this->calcAmountLineTax($this->item->tax_rate2, $amount);
if($item_tax_rate1_total > 0)
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
$item_tax_rate2_total = $this->calcAmountLineTax($this->item->tax_rate2, $amount);
$item_tax += $item_tax_rate2_total;
$item_tax += $item_tax_rate2_total;
if ($item_tax_rate2_total > 0) {
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
}
if($item_tax_rate2_total > 0)
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
$item_tax_rate3_total = $this->calcAmountLineTax($this->item->tax_rate3, $amount);
$item_tax_rate3_total = $this->calcAmountLineTax($this->item->tax_rate3, $amount);
$item_tax += $item_tax_rate3_total;
$item_tax += $item_tax_rate3_total;
if ($item_tax_rate3_total > 0) {
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
}
}
if($item_tax_rate3_total > 0)
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
$this->setTotalTaxes($item_tax);
}
/**
* Sets default values for the line_items
* @return $this
*/
private function cleanLineItem()
{
$invoice_item = (object)get_class_vars(InvoiceItem::class);
unset($invoice_item->casts);
foreach ($invoice_item as $key => $value) {
if (!property_exists($this->item, $key) || !isset($this->item->{$key})) {
$this->item->{$key} = $value;
$this->item->{$key} = BaseSettings::castAttribute(InvoiceItem::$casts[$key], $value);
}
}
}
$this->setTotalTaxes($item_tax);
}
/**
* Sets default values for the line_items
* @return $this
*/
private function cleanLineItem()
{
$invoice_item = (object)get_class_vars(InvoiceItem::class);
unset($invoice_item->casts);
foreach($invoice_item as $key => $value)
{
if(!property_exists($this->item, $key) || !isset($this->item->{$key})){
$this->item->{$key} = $value;
$this->item->{$key} = BaseSettings::castAttribute(InvoiceItem::$casts[$key], $value);
}
}
return $this;
}
}
return $this;
}
}

View File

@ -19,255 +19,243 @@ use Illuminate\Support\Collection;
class InvoiceItemSumInclusive
{
use NumberFormatter;
use Discounter;
use Taxer;
use NumberFormatter;
use Discounter;
use Taxer;
protected $invoice;
protected $invoice;
private $items;
private $items;
private $line_total;
private $line_total;
private $currency;
private $currency;
private $total_taxes;
private $total_taxes;
private $item;
private $item;
private $line_items;
private $line_items;
private $sub_total;
private $sub_total;
private $total_discount;
private $total_discount;
private $tax_collection;
private $tax_collection;
public function __construct($invoice)
{
public function __construct($invoice)
{
$this->tax_collection = collect([]);
$this->invoice = $invoice;
$this->currency = $this->invoice->client->currency();
$this->line_items = [];
}
public function process()
{
if (!$this->invoice->line_items || count($this->invoice->line_items) == 0) {
$this->items = [];
return $this;
}
$this->calcLineItems();
return $this;
}
private function calcLineItems()
{
foreach ($this->invoice->line_items as $this->item) {
$this->sumLineItem()
->setDiscount()
->calcTaxes()
->push();
}
return $this;
}
private function push()
{
$this->sub_total += $this->getLineTotal();
$this->line_items[] = $this->item;
return $this;
}
$this->tax_collection = collect([]);
private function sumLineItem()
{
$this->setLineTotal($this->formatValue($this->item->cost, $this->currency->precision) * $this->formatValue($this->item->quantity, $this->currency->precision));
$this->invoice = $invoice;
return $this;
}
$this->currency = $this->invoice->client->currency();
private function setDiscount()
{
if ($this->invoice->is_amount_discount) {
$this->setLineTotal($this->getLineTotal() - $this->formatValue($this->item->discount, $this->currency->precision));
} else {
$this->setLineTotal($this->getLineTotal() - $this->formatValue(($this->item->line_total * ($this->item->discount / 100)), $this->currency->precision));
}
$this->line_items = [];
}
$this->item->is_amount_discount = $this->invoice->is_amount_discount;
public function process()
{
return $this;
}
if(!$this->invoice->line_items || count($this->invoice->line_items) == 0){
$this->items = [];
return $this;
}
/**
* Taxes effect the line totals and item costs. we decrement both on
* application of inclusive tax rates.
*
*/
private function calcTaxes()
{
$item_tax = 0;
$this->calcLineItems();
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/100));
return $this;
}
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
private function calcLineItems()
{
foreach($this->invoice->line_items as $this->item)
{
$this->sumLineItem()
->setDiscount()
->calcTaxes()
->push();
}
$item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision);
return $this;
}
private function push()
{
$this->sub_total += $this->getLineTotal();
$this->line_items[] = $this->item;
return $this;
}
private function sumLineItem()
{
$this->setLineTotal($this->formatValue($this->item->cost, $this->currency->precision) * $this->formatValue($this->item->quantity, $this->currency->precision));
return $this;
}
private function setDiscount()
{
if($this->invoice->is_amount_discount)
{
$this->setLineTotal($this->getLineTotal() - $this->formatValue($this->item->discount, $this->currency->precision));
}
else
{
$this->setLineTotal($this->getLineTotal() - $this->formatValue(($this->item->line_total * ($this->item->discount / 100)), $this->currency->precision));
}
$this->item->is_amount_discount = $this->invoice->is_amount_discount;
return $this;
if ($item_tax_rate1_total > 0) {
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
}
}
$item_tax_rate2_total = $this->calcInclusiveLineTax($this->item->tax_rate2, $amount);
/**
* Taxes effect the line totals and item costs. we decrement both on
* application of inclusive tax rates.
*
*/
private function calcTaxes()
{
$item_tax += $this->formatValue($item_tax_rate2_total, $this->currency->precision);
$item_tax = 0;
if ($item_tax_rate2_total > 0) {
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
}
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/100));
$item_tax_rate3_total = $this->calcInclusiveLineTax($this->item->tax_rate3, $amount);
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
$item_tax += $this->formatValue($item_tax_rate3_total, $this->currency->precision);
$item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision);
if ($item_tax_rate3_total > 0) {
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
}
if($item_tax_rate1_total > 0)
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
$item_tax_rate2_total = $this->calcInclusiveLineTax($this->item->tax_rate2, $amount);
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
$item_tax += $this->formatValue($item_tax_rate2_total, $this->currency->precision);
return $this;
}
if($item_tax_rate2_total > 0)
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
private function groupTax($tax_name, $tax_rate, $tax_total)
{
$group_tax = [];
$item_tax_rate3_total = $this->calcInclusiveLineTax($this->item->tax_rate3, $amount);
$key = str_replace(" ", "", $tax_name.$tax_rate);
$item_tax += $this->formatValue($item_tax_rate3_total, $this->currency->precision);
$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name . ' ' . $tax_rate.'%'];
if($item_tax_rate3_total > 0)
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
$this->tax_collection->push(collect($group_tax));
}
$this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision));
public function getTotalTaxes()
{
return $this->total_taxes;
}
return $this;
}
public function setTotalTaxes($total)
{
$this->total_taxes = $total;
private function groupTax($tax_name, $tax_rate, $tax_total)
{
$group_tax = [];
return $this;
}
$key = str_replace(" ", "", $tax_name.$tax_rate);
public function setLineTotal($total)
{
$this->item->line_total = $total;
$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name . ' ' . $tax_rate.'%'];
return $this;
}
$this->tax_collection->push(collect($group_tax));
}
public function getLineTotal()
{
return $this->item->line_total;
}
public function getTotalTaxes()
{
return $this->total_taxes;
}
public function getLineItems()
{
return $this->line_items;
}
public function setTotalTaxes($total)
{
$this->total_taxes = $total;
public function getGroupedTaxes()
{
return $this->tax_collection;
}
return $this;
}
public function setGroupedTaxes($group_taxes)
{
$this->tax_collection = $group_taxes;
public function setLineTotal($total)
{
$this->item->line_total = $total;
return $this;
}
return $this;
}
public function getSubTotal()
{
return $this->sub_total;
}
public function getLineTotal()
{
return $this->item->line_total;
}
public function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
public function getLineItems()
{
return $this->line_items;
}
/**
* Invoice Amount Discount
*
* The problem, when calculating invoice level discounts,
* the tax collected changes.
*
* We need to synthetically reduce the line_total amounts
* and recalculate the taxes and then pass back
* the updated map
*/
public function calcTaxesWithAmountDiscount()
{
$this->setGroupedTaxes(collect([]));
public function getGroupedTaxes()
{
return $this->tax_collection;
}
$item_tax = 0;
public function setGroupedTaxes($group_taxes)
{
$this->tax_collection = $group_taxes;
foreach ($this->line_items as $this->item) {
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/$this->sub_total));
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
return $this;
}
$item_tax += $item_tax_rate1_total;
public function getSubTotal()
{
return $this->sub_total;
}
if ($item_tax_rate1_total > 0) {
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
}
$item_tax_rate2_total = $this->calcInclusiveLineTax($this->item->tax_rate2, $amount);
public function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
$item_tax += $item_tax_rate2_total;
/**
* Invoice Amount Discount
*
* The problem, when calculating invoice level discounts,
* the tax collected changes.
*
* We need to synthetically reduce the line_total amounts
* and recalculate the taxes and then pass back
* the updated map
*/
public function calcTaxesWithAmountDiscount()
{
$this->setGroupedTaxes(collect([]));
if ($item_tax_rate2_total > 0) {
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
}
$item_tax = 0;
$item_tax_rate3_total = $this->calcInclusiveLineTax($this->item->tax_rate3, $amount);
foreach($this->line_items as $this->item)
{
$item_tax += $item_tax_rate3_total;
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount/$this->sub_total));
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
if ($item_tax_rate3_total > 0) {
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
}
}
$item_tax += $item_tax_rate1_total;
if($item_tax_rate1_total > 0)
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
$item_tax_rate2_total = $this->calcInclusiveLineTax($this->item->tax_rate2, $amount);
$item_tax += $item_tax_rate2_total;
if($item_tax_rate2_total > 0)
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
$item_tax_rate3_total = $this->calcInclusiveLineTax($this->item->tax_rate3, $amount);
$item_tax += $item_tax_rate3_total;
if($item_tax_rate3_total > 0)
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
}
$this->setTotalTaxes($item_tax);
}
}
$this->setTotalTaxes($item_tax);
}
}

View File

@ -21,88 +21,85 @@ use Illuminate\Support\Collection;
class InvoiceSum
{
use Taxer;
use Balancer;
use CustomValuer;
use Discounter;
use Taxer;
use Balancer;
use CustomValuer;
use Discounter;
use NumberFormatter;
use NumberFormatter;
protected $invoice;
protected $invoice;
public $tax_map;
public $tax_map;
public $invoice_item;
public $invoice_item;
public $total_taxes;
public $total_taxes;
private $total;
private $total;
private $total_discount;
private $total_discount;
private $total_custom_values;
private $total_custom_values;
private $total_tax_map;
private $total_tax_map;
private $sub_total;
/**
* Constructs the object with Invoice and Settings object
*
* @param \App\Models\Invoice $invoice The invoice
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
private $sub_total;
/**
* Constructs the object with Invoice and Settings object
*
* @param \App\Models\Invoice $invoice The invoice
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
$this->tax_map = new Collection;
$this->tax_map = new Collection;
}
}
public function build()
{
$this->calculateLineItems()
->calculateDiscount()
->calculateCustomValues()
->calculateInvoiceTaxes()
->setTaxMap()
->calculateTotals()
->calculateBalance()
->calculatePartial();
public function build()
{
return $this;
}
$this->calculateLineItems()
->calculateDiscount()
->calculateCustomValues()
->calculateInvoiceTaxes()
->setTaxMap()
->calculateTotals()
->calculateBalance()
->calculatePartial();
private function calculateLineItems()
{
$this->invoice_items = new InvoiceItemSum($this->invoice);
$this->invoice_items->process();
$this->invoice->line_items = $this->invoice_items->getLineItems();
$this->total = $this->invoice_items->getSubTotal();
$this->setSubTotal($this->invoice_items->getSubTotal());
return $this;
}
return $this;
}
private function calculateLineItems()
{
$this->invoice_items = new InvoiceItemSum($this->invoice);
$this->invoice_items->process();
$this->invoice->line_items = $this->invoice_items->getLineItems();
$this->total = $this->invoice_items->getSubTotal();
$this->setSubTotal($this->invoice_items->getSubTotal());
private function calculateDiscount()
{
$this->total_discount = $this->discount($this->invoice_items->getSubTotal());
return $this;
}
$this->total -= $this->total_discount;
private function calculateDiscount()
{
$this->total_discount = $this->discount($this->invoice_items->getSubTotal());
return $this;
}
$this->total -= $this->total_discount;
return $this;
}
private function calculateCustomValues()
{
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1);
private function calculateCustomValues()
{
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_taxes4);
@ -111,145 +108,142 @@ class InvoiceSum
$this->total += $this->total_custom_values;
return $this;
}
}
private function calculateInvoiceTaxes()
{
if($this->invoice->tax_rate1 > 0){
$tax = $this->taxer($this->total, $this->invoice->tax_rate1);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1 . ' ' . $this->invoice->tax_rate1.'%', 'total' => $tax];
private function calculateInvoiceTaxes()
{
if ($this->invoice->tax_rate1 > 0) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate1);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1 . ' ' . $this->invoice->tax_rate1.'%', 'total' => $tax];
}
if($this->invoice->tax_rate2 > 0){
$tax = $this->taxer($this->total, $this->invoice->tax_rate2);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2. ' ' . $this->invoice->tax_rate2.'%', 'total' => $tax];
if ($this->invoice->tax_rate2 > 0) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate2);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2. ' ' . $this->invoice->tax_rate2.'%', 'total' => $tax];
}
if($this->invoice->tax_rate3 > 0){
$tax = $this->taxer($this->total, $this->invoice->tax_rate3);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3 . ' ' . $this->invoice->tax_rate3.'%', 'total' => $tax];
if ($this->invoice->tax_rate3 > 0) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate3);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3 . ' ' . $this->invoice->tax_rate3.'%', 'total' => $tax];
}
return $this;
}
}
/**
* Calculates the balance.
*
* @return self The balance.
*/
private function calculateBalance()
{
//$this->invoice->balance = $this->balance($this->getTotal(), $this->invoice);
$this->setCalculatedAttributes();
/**
* Calculates the balance.
*
* @return self The balance.
*/
private function calculateBalance()
{
//$this->invoice->balance = $this->balance($this->getTotal(), $this->invoice);
$this->setCalculatedAttributes();
return $this;
}
return $this;
}
private function calculatePartial()
{
if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) {
private function calculatePartial()
{
if (!isset($this->invoice->id) && isset($this->invoice->partial)) {
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
}
return $this;
}
}
private function calculateTotals()
{
$this->total += $this->total_taxes;
private function calculateTotals()
{
$this->total += $this->total_taxes;
return $this;
}
}
public function getInvoice()
{
//Build invoice values here and return Invoice
$this->setCalculatedAttributes();
$this->invoice->save();
return $this->invoice;
}
public function getInvoice()
{
//Build invoice values here and return Invoice
$this->setCalculatedAttributes();
$this->invoice->save();
return $this->invoice;
}
/**
* Build $this->invoice variables after
* calculations have been performed.
*/
private function setCalculatedAttributes()
{
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
if($this->invoice->amount != $this->invoice->balance)
{
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
/**
* Build $this->invoice variables after
* calculations have been performed.
*/
private function setCalculatedAttributes()
{
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
if ($this->invoice->amount != $this->invoice->balance) {
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
}
else
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
} else {
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
}
/* Set new calculated total */
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
/* Set new calculated total */
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
$this->invoice->total_taxes = $this->getTotalTaxes();
$this->invoice->total_taxes = $this->getTotalTaxes();
return $this;
}
return $this;
}
public function getSubTotal()
{
return $this->sub_total;
}
public function getSubTotal()
{
return $this->sub_total;
}
public function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
public function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
public function getTotalDiscount()
{
return $this->total_discount;
}
public function getTotalDiscount()
{
return $this->total_discount;
}
public function getTotalTaxes()
{
return $this->total_taxes;
}
public function getTotalTaxes()
{
return $this->total_taxes;
}
public function getTotalTaxMap()
{
return $this->total_tax_map;
}
public function getTotalTaxMap()
{
return $this->total_tax_map;
}
public function getTotal()
{
return $this->total;
}
public function getTotal()
{
return $this->total;
}
public function setTaxMap()
{
if($this->invoice->is_amount_discount == true)
$this->invoice_items->calcTaxesWithAmountDiscount();
public function setTaxMap()
{
if ($this->invoice->is_amount_discount == true) {
$this->invoice_items->calcTaxesWithAmountDiscount();
}
$this->tax_map = collect();
$this->tax_map = collect();
$keys = $this->invoice_items->getGroupedTaxes()->pluck('key')->unique();
$values = $this->invoice_items->getGroupedTaxes();
foreach($keys as $key)
{
$tax_name = $values->filter(function ($value, $k) use($key){
foreach ($keys as $key) {
$tax_name = $values->filter(function ($value, $k) use ($key) {
return $value['key'] == $key;
})->pluck('tax_name')->first();
$total_line_tax = $values->filter(function ($value, $k) use($key){
$total_line_tax = $values->filter(function ($value, $k) use ($key) {
return $value['key'] == $key;
})->sum('total');
@ -261,21 +255,20 @@ class InvoiceSum
}
return $this;
}
}
public function getTaxMap()
{
return $this->tax_map;
}
public function getTaxMap()
{
return $this->tax_map;
}
public function getBalance()
{
return $this->invoice->balance;
}
public function getBalance()
{
return $this->invoice->balance;
}
public function getItemTotalTaxes()
{
return $this->getTotalTaxes();
}
}
public function getItemTotalTaxes()
{
return $this->getTotalTaxes();
}
}

View File

@ -22,88 +22,86 @@ use Illuminate\Support\Collection;
class InvoiceSumInclusive
{
use Taxer;
use Balancer;
use CustomValuer;
use Discounter;
use Taxer;
use Balancer;
use CustomValuer;
use Discounter;
use NumberFormatter;
use NumberFormatter;
protected $invoice;
protected $invoice;
public $tax_map;
public $tax_map;
public $invoice_item;
public $invoice_item;
public $total_taxes;
public $total_taxes;
private $total;
private $total;
private $total_discount;
private $total_discount;
private $total_custom_values;
private $total_custom_values;
private $total_tax_map;
private $total_tax_map;
private $sub_total;
/**
* Constructs the object with Invoice and Settings object
*
* @param \App\Models\Invoice $invoice The invoice
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
private $sub_total;
/**
* Constructs the object with Invoice and Settings object
*
* @param \App\Models\Invoice $invoice The invoice
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
$this->tax_map = new Collection;
$this->tax_map = new Collection;
}
}
public function build()
{
$this->calculateLineItems()
->calculateDiscount()
->calculateCustomValues()
->calculateInvoiceTaxes()
->setTaxMap()
public function build()
{
$this->calculateLineItems()
->calculateDiscount()
->calculateCustomValues()
->calculateInvoiceTaxes()
->setTaxMap()
// ->calculateTotals()
->calculateBalance()
->calculatePartial();
->calculateBalance()
->calculatePartial();
return $this;
}
return $this;
}
private function calculateLineItems()
{
$this->invoice_items = new InvoiceItemSumInclusive($this->invoice);
$this->invoice_items->process();
$this->invoice->line_items = $this->invoice_items->getLineItems();
$this->total = $this->invoice_items->getSubTotal();
$this->setSubTotal($this->invoice_items->getSubTotal());
private function calculateLineItems()
{
$this->invoice_items = new InvoiceItemSumInclusive($this->invoice);
$this->invoice_items->process();
$this->invoice->line_items = $this->invoice_items->getLineItems();
$this->total = $this->invoice_items->getSubTotal();
$this->setSubTotal($this->invoice_items->getSubTotal());
return $this;
}
return $this;
}
private function calculateDiscount()
{
$this->total_discount = $this->discount($this->invoice_items->getSubTotal());
private function calculateDiscount()
{
$this->total_discount = $this->discount($this->invoice_items->getSubTotal());
$this->total -= $this->total_discount;
$this->total -= $this->total_discount;
return $this;
}
return $this;
}
private function calculateCustomValues()
{
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1);
private function calculateCustomValues()
{
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3);
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3);
$this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_taxes4);
@ -112,156 +110,154 @@ class InvoiceSumInclusive
$this->total += $this->total_custom_values;
return $this;
}
}
private function calculateInvoiceTaxes()
{
$amount = $this->total;
private function calculateInvoiceTaxes()
{
$amount = $this->total;
if($this->invoice->discount > 0 && $this->invoice->is_amount_discount)
$amount = $this->formatValue(($this->sub_total - $this->invoice->discount),2);
if ($this->invoice->discount > 0 && $this->invoice->is_amount_discount) {
$amount = $this->formatValue(($this->sub_total - $this->invoice->discount), 2);
}
if($this->invoice->discount > 0 && !$this->invoice->is_amount_discount)
$amount = $this->formatValue(($this->sub_total - ($this->sub_total * ($this->invoice->discount/100))),2);
if ($this->invoice->discount > 0 && !$this->invoice->is_amount_discount) {
$amount = $this->formatValue(($this->sub_total - ($this->sub_total * ($this->invoice->discount/100))), 2);
}
if($this->invoice->tax_rate1 > 0){
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate1, $amount);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1 . ' ' . $this->invoice->tax_rate1.'%', 'total' => $tax];
if ($this->invoice->tax_rate1 > 0) {
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate1, $amount);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name1 . ' ' . $this->invoice->tax_rate1.'%', 'total' => $tax];
}
if($this->invoice->tax_rate2 > 0){
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate2, $amount);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2. ' ' . $this->invoice->tax_rate2.'%', 'total' => $tax];
if ($this->invoice->tax_rate2 > 0) {
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate2, $amount);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name2. ' ' . $this->invoice->tax_rate2.'%', 'total' => $tax];
}
if($this->invoice->tax_rate3 > 0){
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate3, $amount);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3 . ' ' . $this->invoice->tax_rate3.'%', 'total' => $tax];
if ($this->invoice->tax_rate3 > 0) {
$tax = $this->calcInclusiveLineTax($this->invoice->tax_rate3, $amount);
$this->total_taxes += $tax;
$this->total_tax_map[] = ['name' => $this->invoice->tax_name3 . ' ' . $this->invoice->tax_rate3.'%', 'total' => $tax];
}
return $this;
}
}
/**
* Calculates the balance.
*
* @return self The balance.
*/
private function calculateBalance()
{
//$this->invoice->balance = $this->balance($this->getTotal(), $this->invoice);
$this->setCalculatedAttributes();
/**
* Calculates the balance.
*
* @return self The balance.
*/
private function calculateBalance()
{
//$this->invoice->balance = $this->balance($this->getTotal(), $this->invoice);
$this->setCalculatedAttributes();
return $this;
}
return $this;
}
private function calculatePartial()
{
if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) {
private function calculatePartial()
{
if (!isset($this->invoice->id) && isset($this->invoice->partial)) {
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
}
return $this;
}
}
private function calculateTotals()
{
$this->total += $this->total_taxes;
private function calculateTotals()
{
$this->total += $this->total_taxes;
return $this;
}
}
public function getInvoice()
{
//Build invoice values here and return Invoice
$this->setCalculatedAttributes();
$this->invoice->save();
return $this->invoice;
}
public function getInvoice()
{
//Build invoice values here and return Invoice
$this->setCalculatedAttributes();
$this->invoice->save();
return $this->invoice;
}
/**
* Build $this->invoice variables after
* calculations have been performed.
*/
private function setCalculatedAttributes()
{
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
if($this->invoice->amount != $this->invoice->balance)
{
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
/**
* Build $this->invoice variables after
* calculations have been performed.
*/
private function setCalculatedAttributes()
{
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
if ($this->invoice->amount != $this->invoice->balance) {
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
}
else
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision) - $paid_to_date;
} else {
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
}
/* Set new calculated total */
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
/* Set new calculated total */
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
$this->invoice->total_taxes = $this->getTotalTaxes();
$this->invoice->total_taxes = $this->getTotalTaxes();
return $this;
}
return $this;
}
public function getSubTotal()
{
return $this->sub_total;
}
public function getSubTotal()
{
return $this->sub_total;
}
public function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
public function setSubTotal($value)
{
$this->sub_total = $value;
return $this;
}
public function getTotalDiscount()
{
return $this->total_discount;
}
public function getTotalDiscount()
{
return $this->total_discount;
}
public function getTotalTaxes()
{
return $this->total_taxes;
}
public function getTotalTaxes()
{
return $this->total_taxes;
}
public function getTotalTaxMap()
{
return $this->total_tax_map;
}
public function getTotalTaxMap()
{
return $this->total_tax_map;
}
public function getTotal()
{
return $this->total;
}
public function getTotal()
{
return $this->total;
}
public function setTaxMap()
{
if($this->invoice->is_amount_discount == true)
$this->invoice_items->calcTaxesWithAmountDiscount();
public function setTaxMap()
{
if ($this->invoice->is_amount_discount == true) {
$this->invoice_items->calcTaxesWithAmountDiscount();
}
$this->tax_map = collect();
$this->tax_map = collect();
$keys = $this->invoice_items->getGroupedTaxes()->pluck('key')->unique();
$values = $this->invoice_items->getGroupedTaxes();
foreach($keys as $key)
{
$tax_name = $values->filter(function ($value, $k) use($key){
foreach ($keys as $key) {
$tax_name = $values->filter(function ($value, $k) use ($key) {
return $value['key'] == $key;
})->pluck('tax_name')->first();
$total_line_tax = $values->filter(function ($value, $k) use($key){
$total_line_tax = $values->filter(function ($value, $k) use ($key) {
return $value['key'] == $key;
})->sum('total');
@ -273,23 +269,20 @@ class InvoiceSumInclusive
}
return $this;
}
}
public function getTaxMap()
{
return $this->tax_map;
}
public function getTaxMap()
{
return $this->tax_map;
}
public function getBalance()
{
return $this->invoice->balance;
}
public function getBalance()
{
return $this->invoice->balance;
}
public function getItemTotalTaxes()
{
return $this->getTotalTaxes();
}
}
public function getItemTotalTaxes()
{
return $this->getTotalTaxes();
}
}

View File

@ -16,21 +16,18 @@ namespace App\Helpers\Invoice;
*/
trait Taxer
{
public function taxer($amount, $tax_rate)
{
return round($amount * (($tax_rate ? $tax_rate : 0) / 100), 2);
}
public function taxer($amount, $tax_rate)
{
return round($amount * (($tax_rate ? $tax_rate : 0) / 100), 2);
}
public function calcAmountLineTax($tax_rate, $amount)
{
return $this->formatValue(($amount * $tax_rate/100), 2);
}
public function calcInclusiveLineTax($tax_rate, $amount)
{
return $this->formatValue($amount - ($amount / (1 + ($tax_rate/100))), 2);
}
public function calcAmountLineTax($tax_rate, $amount)
{
return $this->formatValue(($amount * $tax_rate/100), 2);
}
public function calcInclusiveLineTax($tax_rate, $amount)
{
return $this->formatValue($amount - ($amount / (1 + ($tax_rate/100))), 2);
}
}

View File

@ -66,4 +66,4 @@ class GmailTransport extends Transport
return $this->numberOfRecipients($message);
}
}
}

View File

@ -24,13 +24,12 @@ use Laravel\Socialite\Facades\Socialite;
*/
class GmailTransportConfig
{
public function test()
{
/********************* We may need to fetch a new token on behalf of the client ******************************/
$query = [
'email' => 'david@invoiceninja.com',
];
/********************* We may need to fetch a new token on behalf of the client ******************************/
$query = [
'email' => 'david@invoiceninja.com',
];
$user = MultiDB::hasUser($query);
// $oauth_user = Socialite::driver('google')->stateless()->userFromToken($user->oauth_user_token);
@ -38,25 +37,12 @@ class GmailTransportConfig
// $user->oauth_user_token = $oauth_user->refreshToken;
// $user->save();
Config::set('mail.driver', 'gmail');
Config::set('services.gmail.token', $user->oauth_user_token);
(new MailServiceProvider(app()))->register();
Config::set('mail.driver', 'gmail');
Config::set('services.gmail.token', $user->oauth_user_token);
(new MailServiceProvider(app()))->register();
Mail::to('david@romulus.com.au')
->send(new SupportMessageSent('a cool message'));
Mail::to('david@romulus.com.au')
->send(new SupportMessageSent('a cool message'));
}
}

View File

@ -15,5 +15,4 @@ class GmailTransportManager extends TransportManager
return new GmailTransport($mail, $token);
}
}
}

View File

@ -16,14 +16,13 @@ use Illuminate\Support\Facades\Cache;
* falls back on defaults if no string exists
*
* //Cache::forever($custom_company_translated_string, 'mogly');
*
*
* @param string translation string key
* @return string
*/
function ctrans(string $string, $replace = [], $locale = null) : string
{
//todo pass through the cached version of the custom strings here else return trans();
//todo pass through the cached version of the custom strings here else return trans();
return trans($string, $replace, $locale);
}
}

View File

@ -43,8 +43,7 @@ class AccountController extends BaseController
*/
public function index()
{
// return view('signup.index');
// return view('signup.index');
}
/**
@ -113,7 +112,7 @@ class AccountController extends BaseController
* property="privacy_policy",
* description="The user accepted the privacy policy",
* type="boolean",
* ),
* ),
* @OA\Property(
* property="password",
* example="1234567",
@ -138,7 +137,7 @@ class AccountController extends BaseController
* ),
* @OA\Response(
* response="default",
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
@ -146,13 +145,11 @@ class AccountController extends BaseController
*/
public function store(CreateAccountRequest $request)
{
$account = CreateAccount::dispatchNow($request->all());
$ct = CompanyUser::whereUserId(auth()->user()->id);
return $this->listResponse($ct);
}
/**

View File

@ -11,14 +11,12 @@
namespace App\Http\Controllers;
use App\Models\Activity;
use App\Transformers\ActivityTransformer;
use Illuminate\Http\Request;
class ActivityController extends BaseController
{
protected $entity_type = Activity::class;
protected $entity_transformer = ActivityTransformer::class;
@ -66,7 +64,7 @@ class ActivityController extends BaseController
* ),
* @OA\Response(
* response="default",
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
@ -83,5 +81,4 @@ class ActivityController extends BaseController
return $this->listResponse($activities);
}
}
}

View File

@ -41,13 +41,14 @@ class ContactForgotPasswordController extends Controller
$this->middleware('guest:contact');
}
/**
* Show the reset email form.
*
* @return \Illuminate\Http\Response
*/
public function showLinkRequestForm(){
return view('portal.default.auth.passwords.email',[
/**
* Show the reset email form.
*
* @return \Illuminate\Http\Response
*/
public function showLinkRequestForm()
{
return view('portal.default.auth.passwords.email', [
'title' => 'Client Password Reset',
'passwordEmailRoute' => 'client.password.email'
]);
@ -60,6 +61,6 @@ class ContactForgotPasswordController extends Controller
public function broker()
{
return Password::broker('contacts');
return Password::broker('contacts');
}
}

View File

@ -20,7 +20,6 @@ use Route;
class ContactLoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/client/dashboard';
@ -32,9 +31,7 @@ class ContactLoginController extends Controller
public function showLoginForm()
{
return view('portal.default.auth.login');
return view('portal.default.auth.login');
}
@ -63,20 +60,19 @@ class ContactLoginController extends Controller
public function authenticated(Request $request, ClientContact $client)
{
Auth::guard('contact')->login($client, true);
if(session()->get('url.intended'))
if (session()->get('url.intended')) {
return redirect(session()->get('url.intended'));
}
return redirect(route('client.dashboard'));
}
public function logout()
{
Auth::guard('contact')->logout();
return redirect('/client/login');
}
}
}

View File

@ -72,6 +72,6 @@ class ContactResetPasswordController extends Controller
public function broker()
{
return Password::broker('contacts');
return Password::broker('contacts');
}
}

View File

@ -44,7 +44,7 @@ class ForgotPasswordController extends Controller
/**
* Password Reset
*
*
*
* @OA\Post(
* path="/api/v1/reset_password",
* operationId="reset_password",
@ -93,7 +93,7 @@ class ForgotPasswordController extends Controller
* ),
* @OA\Response(
* response="default",
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
@ -115,5 +115,4 @@ class ForgotPasswordController extends Controller
? response()->json(['message' => 'Reset link sent to your email.', 'status' => true], 201)
: response()->json(['message' => 'Email not found', 'status' => false], 401);
}
}

View File

@ -40,16 +40,16 @@ class LoginController extends BaseController
|
*/
/**
* @OA\Tag(
* name="login",
* description="Authentication",
* @OA\ExternalDocumentation(
* description="Find out more",
* url="http://docs.invoiceninja.com"
* )
* )
*/
/**
* @OA\Tag(
* name="login",
* description="Authentication",
* @OA\ExternalDocumentation(
* description="Find out more",
* url="http://docs.invoiceninja.com"
* )
* )
*/
use AuthenticatesUsers;
use UserSessionAttributes;
@ -72,9 +72,7 @@ class LoginController extends BaseController
*/
public function __construct()
{
parent::__construct();
}
/**
@ -97,7 +95,7 @@ class LoginController extends BaseController
*
* @return Response|User Process user login.
*
*
*
* @OA\Post(
* path="/api/v1/login",
* operationId="postLogin",
@ -146,7 +144,7 @@ class LoginController extends BaseController
* ),
* @OA\Response(
* response="default",
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
@ -170,17 +168,13 @@ class LoginController extends BaseController
}
if ($this->attemptLogin($request)) {
$user = $this->guard()->user();
$user->setCompany($user->company_user->account->default_company);
$ct = CompanyUser::whereUserId($user->id);
return $this->listResponse($ct);
}
else {
} else {
$this->incrementLoginAttempts($request);
return response()
@ -188,15 +182,14 @@ class LoginController extends BaseController
->header('X-App-Version', config('ninja.app_version'))
->header('X-Api-Version', config('ninja.api_version'));
}
}
/**
* Refreshes the data feed with the current Company User
*
*
* @return CompanyUser Refresh Feed.
*
*
*
* @OA\Post(
* path="/api/v1/refresh",
* operationId="refresh",
@ -224,7 +217,7 @@ class LoginController extends BaseController
* ),
* @OA\Response(
* response="default",
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
@ -233,8 +226,8 @@ class LoginController extends BaseController
*/
public function refresh(Request $request)
{
$ct = CompanyUser::whereUserId(auth()->user()->id);
return $this->listResponse($ct);
$ct = CompanyUser::whereUserId(auth()->user()->id);
return $this->listResponse($ct);
}
/**
@ -242,28 +235,27 @@ class LoginController extends BaseController
*
* @return void
*/
public function redirectToProvider(string $provider)
public function redirectToProvider(string $provider)
{
//'https://www.googleapis.com/auth/gmail.send','email','profile','openid'
//
if(request()->has('code'))
if (request()->has('code')) {
return $this->handleProviderCallback($provider);
else
} else {
return Socialite::driver($provider)->scopes('https://www.googleapis.com/auth/gmail.send')->redirect();
}
}
public function redirectToProviderAndCreate(string $provider)
{
$redirect_url = config('services.' . $provider . '.redirect') . '/create';
if(request()->has('code'))
if (request()->has('code')) {
return $this->handleProviderCallbackAndCreate($provider);
else
} else {
return Socialite::driver($provider)->scopes('https://www.googleapis.com/auth/gmail.send')->redirectUrl($redirect_url)->redirect();
}
}
@ -278,23 +270,20 @@ class LoginController extends BaseController
->user();
/* Handle existing users who attempt to create another account with existing OAuth credentials */
if($user = OAuth::handleAuth($socialite_user, $provider))
{
if ($user = OAuth::handleAuth($socialite_user, $provider)) {
$user->oauth_user_token = $socialite_user->refreshToken;
$user->save();
Auth::login($user, true);
return redirect($this->redirectTo);
}
else if(MultiDB::checkUserEmailExists($socialite_user->getEmail()))
{
} elseif (MultiDB::checkUserEmailExists($socialite_user->getEmail())) {
Session::flash('error', 'User exists in system, but not with this authentication method'); //todo add translations
return view('auth.login');
}
}
/** 3. Automagically creating a new account here. */
else {
//todo
//todo
$name = OAuth::splitName($socialite_user->getName());
$new_account = [
@ -317,17 +306,15 @@ class LoginController extends BaseController
return redirect($this->redirectTo)->withCookie($cookie);
}
}
/**
* We use this function when OAUTHING via the web interface
*
* @return redirect
*
* @return redirect
*/
public function handleProviderCallback(string $provider)
public function handleProviderCallback(string $provider)
{
$redirect_url = config('services.' . $provider . '.redirect');
$socialite_user = Socialite::driver($provider)
@ -335,23 +322,20 @@ class LoginController extends BaseController
->stateless()
->user();
if($user = OAuth::handleAuth($socialite_user, $provider))
{
if ($user = OAuth::handleAuth($socialite_user, $provider)) {
$user->oauth_user_token = $socialite_user->token;
$user->save();
Auth::login($user, true);
return redirect($this->redirectTo);
}
else if(MultiDB::checkUserEmailExists($socialite_user->getEmail()))
{
} elseif (MultiDB::checkUserEmailExists($socialite_user->getEmail())) {
Session::flash('error', 'User exists in system, but not with this authentication method'); //todo add translations
return view('auth.login');
}
}
/** 3. Automagically creating a new account here. */
else {
//todo
//todo
$name = OAuth::splitName($socialite_user->getName());
$new_account = [
@ -372,25 +356,22 @@ class LoginController extends BaseController
return redirect($this->redirectTo)->withCookie($cookie);
}
}
/**
* A client side authentication has taken place.
* A client side authentication has taken place.
* We now digest the token and confirm authentication with
* the authentication server, the correct user object
* is returned to us here and we send back the correct
* user object payload - or error.
*
* This can be extended to a create route also - need to pass a ?create query parameter and
* This can be extended to a create route also - need to pass a ?create query parameter and
* then process the signup
*
*
* return User $user
*/
public function oauthApiLogin()
{
$user = false;
$oauth = new OAuth();
@ -400,12 +381,9 @@ class LoginController extends BaseController
if ($user) {
$ct = CompanyUser::whereUserId($user);
return $this->listResponse($ct);
// return $this->itemResponse($user);
}
else
// return $this->itemResponse($user);
} else {
return $this->errorResponse(['message' => 'Invalid credentials'], 401);
}
}
}

Some files were not shown because too many files have changed in this diff Show More